OpenTTD Source 20250428-master-ga5578166bb
RiverBuilder Class Reference

Search path and build river. More...

Inheritance diagram for RiverBuilder:
AyStar

Static Public Member Functions

static void Exec (TileIndex begin, TileIndex end, TileIndex spring, bool main_river)
 Actually build the river between the begin and end tiles using AyStar.
 

Protected Member Functions

AyStarStatus EndNodeCheck (const PathNode &current) const override
 Check whether the end-tile is found.
 
int32_t CalculateG (const AyStarNode &, const PathNode &) const override
 Calculate the G-value for the AyStar algorithm.
 
int32_t CalculateH (const AyStarNode &current, const PathNode &) const override
 Calculate the H-value for the AyStar algorithm.
 
void GetNeighbours (const PathNode &current, std::vector< AyStarNode > &neighbours) const override
 This function requests the tiles around the current tile.
 
void FoundEndNode (const PathNode &current) override
 If the End Node is found, this function is called.
 
 RiverBuilder (TileIndex end, TileIndex spring, bool main_river)
 
- Protected Member Functions inherited from AyStar
void AddStartNode (AyStarNode *start_node, int g)
 Adds a node from where to start an algorithm.
 
AyStarStatus Main ()
 This is the function you call to run AyStar.
 

Private Attributes

TileIndex end
 Destination for the river.
 
TileIndex spring
 The current spring during river generation.
 
bool main_river
 Whether the current river is a big river that others flow into.
 

Detailed Description

Search path and build river.

Definition at line 1202 of file landscape.cpp.

Constructor & Destructor Documentation

◆ RiverBuilder()

RiverBuilder::RiverBuilder ( TileIndex  end,
TileIndex  spring,
bool  main_river 
)
inlineprotected

Definition at line 1265 of file landscape.cpp.

Member Function Documentation

◆ CalculateG()

int32_t RiverBuilder::CalculateG ( const AyStarNode current,
const PathNode parent 
) const
inlineoverrideprotectedvirtual

Calculate the G-value for the AyStar algorithm.

Returns
G value of the node:
  • AYSTAR_INVALID_NODE : indicates an item is not valid (e.g.: unwalkable)
  • Any value >= 0 : the g-value for this tile

Implements AyStar.

Definition at line 1209 of file landscape.cpp.

References _settings_game, GameSettings::game_creation, RandomRange(), and GameCreationSettings::river_route_random.

◆ CalculateH()

int32_t RiverBuilder::CalculateH ( const AyStarNode current,
const PathNode parent 
) const
inlineoverrideprotectedvirtual

Calculate the H-value for the AyStar algorithm.

Mostly, this must return the distance (Manhattan way) between the current point and the end point.

Returns
The h-value for this tile (any value >= 0)

Implements AyStar.

Definition at line 1214 of file landscape.cpp.

References DistanceManhattan(), and end.

◆ EndNodeCheck()

AyStarStatus RiverBuilder::EndNodeCheck ( const PathNode current) const
inlineoverrideprotectedvirtual

Check whether the end-tile is found.

Parameters
currentNode to exam.
Returns
Status of the node:

Implements AyStar.

Definition at line 1204 of file landscape.cpp.

References Done, end, and FoundEndNode.

◆ Exec()

static void RiverBuilder::Exec ( TileIndex  begin,
TileIndex  end,
TileIndex  spring,
bool  main_river 
)
inlinestatic

Actually build the river between the begin and end tiles using AyStar.

Parameters
beginThe begin of the river.
endThe end of the river.
springThe springing point of the river.
main_riverWhether the current river is a big river that others flow into.

Definition at line 1280 of file landscape.cpp.

References AyStar::AddStartNode(), end, INVALID_TRACKDIR, AyStar::Main(), main_river, and spring.

Referenced by FlowRiver().

◆ FoundEndNode()

void RiverBuilder::FoundEndNode ( const PathNode current)
inlineoverrideprotectedvirtual

If the End Node is found, this function is called.

It can do, for example, calculate the route and put that in an array.

Implements AyStar.

Definition at line 1234 of file landscape.cpp.

References _settings_game, DistanceManhattan(), GameSettings::game_creation, IsWaterTile(), GameCreationSettings::land_generator, LG_ORIGINAL, MakeRiverAndModifyDesertZoneAround(), GameCreationSettings::min_river_length, RiverMakeWider(), and spring.

◆ GetNeighbours()

void RiverBuilder::GetNeighbours ( const PathNode current,
std::vector< AyStarNode > &  neighours 
) const
inlineoverrideprotectedvirtual

This function requests the tiles around the current tile.

neighbours is never reset, so if you are not using directions, just leave it alone.

Implements AyStar.

Definition at line 1219 of file landscape.cpp.

References DIAGDIR_BEGIN, DIAGDIR_END, FlowsDown(), INVALID_TRACKDIR, IsValidTile(), and TileOffsByDiagDir().

Field Documentation

◆ end

TileIndex RiverBuilder::end
private

Destination for the river.

Definition at line 1268 of file landscape.cpp.

Referenced by CalculateH(), EndNodeCheck(), and Exec().

◆ main_river

bool RiverBuilder::main_river
private

Whether the current river is a big river that others flow into.

Definition at line 1270 of file landscape.cpp.

Referenced by Exec().

◆ spring

TileIndex RiverBuilder::spring
private

The current spring during river generation.

Definition at line 1269 of file landscape.cpp.

Referenced by Exec(), and FoundEndNode().


The documentation for this class was generated from the following file: