npf.c
changeset 1617 c3d3caad6d1e
parent 1503 39d0f85977cf
child 1643 420cad9e62e4
equal deleted inserted replaced
1616:ebc6759a6bb8 1617:c3d3caad6d1e
   330 /* Determine the cost of this node, for railway tracks */
   330 /* Determine the cost of this node, for railway tracks */
   331 int32 NPFRailPathCost(AyStar* as, AyStarNode* current, OpenListNode* parent) {
   331 int32 NPFRailPathCost(AyStar* as, AyStarNode* current, OpenListNode* parent) {
   332 	TileIndex tile = current->tile;
   332 	TileIndex tile = current->tile;
   333 	byte trackdir = current->direction;
   333 	byte trackdir = current->direction;
   334 	int32 cost = 0;
   334 	int32 cost = 0;
       
   335 	OpenListNode new_node;
       
   336 
   335 	/* Determine base length */
   337 	/* Determine base length */
   336 	switch (GetTileType(tile)) {
   338 	switch (GetTileType(tile)) {
   337 		case MP_TUNNELBRIDGE:
   339 		case MP_TUNNELBRIDGE:
   338 			if ((_map5[tile] & 0xF0)==0) {
   340 			if ((_map5[tile] & 0xF0)==0) {
   339 				cost = NPFTunnelCost(current);
   341 				cost = NPFTunnelCost(current);
   382 		NPFSetFlag(current, NPF_FLAG_SEEN_SIGNAL, true);
   384 		NPFSetFlag(current, NPF_FLAG_SEEN_SIGNAL, true);
   383 	}
   385 	}
   384 
   386 
   385 	/* Penalise the tile if it is a target tile and the last signal was
   387 	/* Penalise the tile if it is a target tile and the last signal was
   386 	 * red */
   388 	 * red */
   387 	if (as->EndNodeCheck(as, current)==AYSTAR_FOUND_END_NODE && NPFGetFlag(current, NPF_FLAG_LAST_SIGNAL_RED))
   389 	new_node.path.node = *current;
       
   390 	if (as->EndNodeCheck(as, &new_node)==AYSTAR_FOUND_END_NODE && NPFGetFlag(current, NPF_FLAG_LAST_SIGNAL_RED))
   388 		cost += _patches.npf_rail_lastred_penalty;
   391 		cost += _patches.npf_rail_lastred_penalty;
   389 
   392 
   390 	/* Check for slope */
   393 	/* Check for slope */
   391 	cost += NPFSlopeCost(current);
   394 	cost += NPFSlopeCost(current);
   392 
   395 
   407 #endif
   410 #endif
   408 	return cost;
   411 	return cost;
   409 }
   412 }
   410 
   413 
   411 /* Will find any depot */
   414 /* Will find any depot */
   412 int32 NPFFindDepot(AyStar* as, AyStarNode *node) {
   415 int32 NPFFindDepot(AyStar* as, OpenListNode *current) {
   413 	TileIndex tile = node->tile;
   416 	TileIndex tile = current->path.node.tile;
   414 	if (IsTileDepotType(tile, as->user_data[NPF_TYPE]))
   417 	if (IsTileDepotType(tile, as->user_data[NPF_TYPE]))
   415 		return AYSTAR_FOUND_END_NODE;
   418 		return AYSTAR_FOUND_END_NODE;
   416 	else
   419 	else
   417 		return AYSTAR_DONE;
   420 		return AYSTAR_DONE;
   418 }
   421 }
   419 
   422 
   420 /* Will find a station identified using the NPFFindStationOrTileData */
   423 /* Will find a station identified using the NPFFindStationOrTileData */
   421 int32 NPFFindStationOrTile(AyStar* as, AyStarNode *node) {
   424 int32 NPFFindStationOrTile(AyStar* as, OpenListNode *current) {
   422 	NPFFindStationOrTileData* fstd = (NPFFindStationOrTileData*)as->user_target;
   425 	NPFFindStationOrTileData* fstd = (NPFFindStationOrTileData*)as->user_target;
       
   426 	AyStarNode *node = &current->path.node;
   423 	TileIndex tile = node->tile;
   427 	TileIndex tile = node->tile;
   424 
   428 
   425 	/* See if we checked this before */
   429 	/* See if we checked this before */
   426 	if (NPFGetFlag(node, NPF_FLAG_TARGET_CHECKED))
   430 	if (NPFGetFlag(node, NPF_FLAG_TARGET_CHECKED))
   427 		return NPFGetFlag(node, NPF_FLAG_IS_TARGET);
   431 		return NPFGetFlag(node, NPF_FLAG_IS_TARGET);