summaryrefslogtreecommitdiff
path: root/npf.c
diff options
context:
space:
mode:
authormatthijs <matthijs@openttd.org>2005-03-14 16:56:05 +0000
committermatthijs <matthijs@openttd.org>2005-03-14 16:56:05 +0000
commit7d0eff175a74324e0a6524956acb4940f1644260 (patch)
tree6cd018605668c700bf48696607cb4539997cf23c /npf.c
parent6367bda0bf4e6ce08051310223a2bf328c1fed6d (diff)
downloadopenttd-7d0eff175a74324e0a6524956acb4940f1644260.tar.xz
(svn r2007) - Fix: [NPF] Slope penalties did not work correctly with foundations. (HackyKid)
- Fix: [NPF] Stations penalties were not applied correctly, since stations had no base cost. (HackyKid) - Fix: [NPF] Lastred penalty was applied multiple times for every red signal, instead of just the last one. (HackyKid)
Diffstat (limited to 'npf.c')
-rw-r--r--npf.c37
1 files changed, 23 insertions, 14 deletions
diff --git a/npf.c b/npf.c
index d8c66d55a..3e8652a39 100644
--- a/npf.c
+++ b/npf.c
@@ -242,7 +242,18 @@ uint NPFTunnelCost(AyStarNode* current) {
uint NPFSlopeCost(AyStarNode* current) {
TileIndex next = current->tile + TileOffsByDir(_trackdir_to_exitdir[current->direction]);
- if (GetTileZ(next) > GetTileZ(current->tile)) {
+ int x,y;
+ int8 z1,z2;
+
+ x = TileX(current->tile) * 16;
+ y = TileY(current->tile) * 16;
+ z1 = GetSlopeZ(x+8, y+8);
+
+ x = TileX(next) * 16;
+ y = TileY(next) * 16;
+ z2 = GetSlopeZ(x+8, y+8);
+
+ if ((z2 - z1) > 1) {
/* Slope up */
return _patches.npf_rail_slope_penalty;
}
@@ -336,6 +347,16 @@ int32 NPFRailPathCost(AyStar* as, AyStarNode* current, OpenListNode* parent) {
case MP_STREET: /* Railway crossing */
cost = NPF_TILE_LENGTH;
break;
+ case MP_STATION:
+ /* We give a station tile a penalty. Logically we would only
+ * want to give station tiles that are not our destination
+ * this penalty. This would discourage trains to drive through
+ * busy stations. But, we can just give any station tile a
+ * penalty, because every possible route will get this penalty
+ * exactly once, on its end tile (if it's a station) and it
+ * will therefore not make a difference. */
+ cost = NPF_TILE_LENGTH + _patches.npf_rail_station_penalty;
+ break;
default:
break;
}
@@ -363,7 +384,7 @@ 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) && NPFGetFlag(current, NPF_FLAG_LAST_SIGNAL_RED))
+ if (as->EndNodeCheck(as, current)==AYSTAR_FOUND_END_NODE && NPFGetFlag(current, NPF_FLAG_LAST_SIGNAL_RED))
cost += _patches.npf_rail_lastred_penalty;
/* Check for slope */
@@ -378,18 +399,6 @@ int32 NPFRailPathCost(AyStar* as, AyStarNode* current, OpenListNode* parent) {
/* Check for occupied track */
//TODO
- /* Check for station tiles */
- if (IsTileType(tile, MP_STATION)) {
- /* We give a station tile a penalty. Logically we would only
- * want to give station tiles that are not our destination
- * this penalty. This would discourage trains to drive through
- * busy stations. But, we can just give any station tile a
- * penalty, because every possible route will get this penalty
- * exactly once, on its end tile (if it's a station) and it
- * will therefore not make a difference. */
- cost += _patches.npf_rail_station_penalty;
- }
-
#ifdef NPF_MARKROUTE
NPFMarkTile(tile);
#endif