mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-06 14:27:16 +00:00
(svn r2121) -Fix: changed the 2nd param of AyStar_EndNodeCheck back to what it should be
This commit is contained in:
parent
1d0e0b22e4
commit
5a527daac9
@ -50,19 +50,14 @@ static bool IsRoad(TileIndex tile)
|
||||
#define TILES_BETWEEN(a, b, c) (TileX(a) >= TileX(b) && TileX(a) <= TileX(c) && TileY(a) >= TileY(b) && TileY(a) <= TileY(c))
|
||||
|
||||
// Check if the current tile is in our end-area
|
||||
static int32 AyStar_AiPathFinder_EndNodeCheck(AyStar *aystar, AyStarNode *node)
|
||||
static int32 AyStar_AiPathFinder_EndNodeCheck(AyStar *aystar, OpenListNode *current)
|
||||
{
|
||||
Ai_PathFinderInfo *PathFinderInfo = (Ai_PathFinderInfo*)aystar->user_target;
|
||||
// It is not allowed to have a station on the end of a bridge or tunnel ;)
|
||||
if (node->user_data[0] != 0) return AYSTAR_DONE;
|
||||
if (TILES_BETWEEN(node->tile, PathFinderInfo->end_tile_tl, PathFinderInfo->end_tile_br))
|
||||
if (IsTileType(node->tile, MP_CLEAR) || IsTileType(node->tile, MP_TREES))
|
||||
/* XXX: The next line used to be here, but the argument to this function
|
||||
* changed to an AyStarNode* instead of an OpenListNode*, so we don't
|
||||
* have the parent available here anymore. Still, if we can build a
|
||||
* station in anyone direction, we can build it in any direction, right?*/
|
||||
// if (current->path.parent == NULL || TestCanBuildStationHere(node->tile,AiNew_GetDirection(current->path.parent->node.tile, node->tile)))
|
||||
if ( TestCanBuildStationHere(node->tile,0))
|
||||
if (current->path.node.user_data[0] != 0) return AYSTAR_DONE;
|
||||
if (TILES_BETWEEN(current->path.node.tile, PathFinderInfo->end_tile_tl, PathFinderInfo->end_tile_br))
|
||||
if (IsTileType(current->path.node.tile, MP_CLEAR) || IsTileType(current->path.node.tile, MP_TREES))
|
||||
if (current->path.parent == NULL || TestCanBuildStationHere(current->path.node.tile,AiNew_GetDirection(current->path.parent->node.tile, current->path.node.tile)))
|
||||
return AYSTAR_FOUND_END_NODE;
|
||||
|
||||
return AYSTAR_DONE;
|
||||
|
2
aystar.c
2
aystar.c
@ -146,7 +146,7 @@ int AyStarMain_Loop(AyStar *aystar) {
|
||||
if (current == NULL) return AYSTAR_EMPTY_OPENLIST;
|
||||
|
||||
// Check for end node and if found, return that code
|
||||
if (aystar->EndNodeCheck(aystar, ¤t->path.node) == AYSTAR_FOUND_END_NODE) {
|
||||
if (aystar->EndNodeCheck(aystar, current) == AYSTAR_FOUND_END_NODE) {
|
||||
if (aystar->FoundEndNode != NULL)
|
||||
aystar->FoundEndNode(aystar, current);
|
||||
free(current);
|
||||
|
10
aystar.h
10
aystar.h
@ -56,7 +56,15 @@ typedef struct AyStar AyStar;
|
||||
* AYSTAR_FOUND_END_NODE : indicates this is the end tile
|
||||
* AYSTAR_DONE : indicates this is not the end tile (or direction was wrong)
|
||||
*/
|
||||
typedef int32 AyStar_EndNodeCheck(AyStar *aystar, AyStarNode *node);
|
||||
/*
|
||||
* The 2nd parameter should be OpenListNode, and NOT AyStarNode. AyStarNode is
|
||||
* part of OpenListNode and so it could be accessed without any problems.
|
||||
* The good part about OpenListNode is, and how AIs use it, that you can
|
||||
* access the parent of the current node, and so check if you, for example
|
||||
* don't try to enter the file tile with a 90-degree curve. So please, leave
|
||||
* this an OpenListNode, it works just fine -- TrueLight
|
||||
*/
|
||||
typedef int32 AyStar_EndNodeCheck(AyStar *aystar, OpenListNode *current);
|
||||
|
||||
/*
|
||||
* This function is called to calculate the G-value for AyStar Algorithm.
|
||||
|
12
npf.c
12
npf.c
@ -332,6 +332,8 @@ int32 NPFRailPathCost(AyStar* as, AyStarNode* current, OpenListNode* parent) {
|
||||
TileIndex tile = current->tile;
|
||||
byte trackdir = current->direction;
|
||||
int32 cost = 0;
|
||||
OpenListNode new_node;
|
||||
|
||||
/* Determine base length */
|
||||
switch (GetTileType(tile)) {
|
||||
case MP_TUNNELBRIDGE:
|
||||
@ -384,7 +386,8 @@ int32 NPFRailPathCost(AyStar* as, AyStarNode* current, OpenListNode* parent) {
|
||||
|
||||
/* Penalise the tile if it is a target tile and the last signal was
|
||||
* red */
|
||||
if (as->EndNodeCheck(as, current)==AYSTAR_FOUND_END_NODE && NPFGetFlag(current, NPF_FLAG_LAST_SIGNAL_RED))
|
||||
new_node.path.node = *current;
|
||||
if (as->EndNodeCheck(as, &new_node)==AYSTAR_FOUND_END_NODE && NPFGetFlag(current, NPF_FLAG_LAST_SIGNAL_RED))
|
||||
cost += _patches.npf_rail_lastred_penalty;
|
||||
|
||||
/* Check for slope */
|
||||
@ -409,8 +412,8 @@ int32 NPFRailPathCost(AyStar* as, AyStarNode* current, OpenListNode* parent) {
|
||||
}
|
||||
|
||||
/* Will find any depot */
|
||||
int32 NPFFindDepot(AyStar* as, AyStarNode *node) {
|
||||
TileIndex tile = node->tile;
|
||||
int32 NPFFindDepot(AyStar* as, OpenListNode *current) {
|
||||
TileIndex tile = current->path.node.tile;
|
||||
if (IsTileDepotType(tile, as->user_data[NPF_TYPE]))
|
||||
return AYSTAR_FOUND_END_NODE;
|
||||
else
|
||||
@ -418,8 +421,9 @@ int32 NPFFindDepot(AyStar* as, AyStarNode *node) {
|
||||
}
|
||||
|
||||
/* Will find a station identified using the NPFFindStationOrTileData */
|
||||
int32 NPFFindStationOrTile(AyStar* as, AyStarNode *node) {
|
||||
int32 NPFFindStationOrTile(AyStar* as, OpenListNode *current) {
|
||||
NPFFindStationOrTileData* fstd = (NPFFindStationOrTileData*)as->user_target;
|
||||
AyStarNode *node = ¤t->path.node;
|
||||
TileIndex tile = node->tile;
|
||||
|
||||
/* See if we checked this before */
|
||||
|
Loading…
Reference in New Issue
Block a user