97 uint maxx = minx + st->trainst_w - 1; // lowermost corner of station |
99 uint maxx = minx + st->trainst_w - 1; // lowermost corner of station |
98 uint maxy = miny + st->trainst_h - 1; |
100 uint maxy = miny + st->trainst_h - 1; |
99 uint x; |
101 uint x; |
100 uint y; |
102 uint y; |
101 |
103 |
102 // we are going the aim for the x coordinate of the closest corner |
104 /* we are going the aim for the x coordinate of the closest corner |
103 // but if we are between those coordinates, we will aim for our own x coordinate |
105 * but if we are between those coordinates, we will aim for our own x coordinate */ |
104 x = clamp(TileX(tile), minx, maxx); |
106 x = clamp(TileX(tile), minx, maxx); |
105 |
107 |
106 // same for y coordinate, see above comment |
108 /* same for y coordinate, see above comment */ |
107 y = clamp(TileY(tile), miny, maxy); |
109 y = clamp(TileY(tile), miny, maxy); |
108 |
110 |
109 // return the tile of our target coordinates |
111 /* return the tile of our target coordinates */ |
110 return TileXY(x, y); |
112 return TileXY(x, y); |
111 } |
113 } |
112 |
114 |
113 /* Calcs the heuristic to the target station or tile. For train stations, it |
115 /* Calcs the heuristic to the target station or tile. For train stations, it |
114 * takes into account the direction of approach. |
116 * takes into account the direction of approach. |
119 NPFFoundTargetData* ftd = (NPFFoundTargetData*)as->user_path; |
121 NPFFoundTargetData* ftd = (NPFFoundTargetData*)as->user_path; |
120 TileIndex from = current->tile; |
122 TileIndex from = current->tile; |
121 TileIndex to = fstd->dest_coords; |
123 TileIndex to = fstd->dest_coords; |
122 uint dist; |
124 uint dist; |
123 |
125 |
124 // for train-stations, we are going to aim for the closest station tile |
126 /* for train-stations, we are going to aim for the closest station tile */ |
125 if (as->user_data[NPF_TYPE] == TRANSPORT_RAIL && fstd->station_index != INVALID_STATION) |
127 if (as->user_data[NPF_TYPE] == TRANSPORT_RAIL && fstd->station_index != INVALID_STATION) |
126 to = CalcClosestStationTile(fstd->station_index, from); |
128 to = CalcClosestStationTile(fstd->station_index, from); |
127 |
129 |
128 if (as->user_data[NPF_TYPE] == TRANSPORT_ROAD) { |
130 if (as->user_data[NPF_TYPE] == TRANSPORT_ROAD) { |
129 /* Since roads only have diagonal pieces, we use manhattan distance here */ |
131 /* Since roads only have diagonal pieces, we use manhattan distance here */ |
171 /* We just popped out if this tunnel, since were |
173 /* We just popped out if this tunnel, since were |
172 * facing the tunnel exit */ |
174 * facing the tunnel exit */ |
173 FindLengthOfTunnelResult flotr; |
175 FindLengthOfTunnelResult flotr; |
174 flotr = FindLengthOfTunnel(tile, ReverseDiagDir(exitdir)); |
176 flotr = FindLengthOfTunnel(tile, ReverseDiagDir(exitdir)); |
175 return flotr.length * NPF_TILE_LENGTH; |
177 return flotr.length * NPF_TILE_LENGTH; |
176 //TODO: Penalty for tunnels? |
178 /* @todo: Penalty for tunnels? */ |
177 } else { |
179 } else { |
178 /* We are entering the tunnel, the enter tile is just a |
180 /* We are entering the tunnel, the enter tile is just a |
179 * straight track */ |
181 * straight track */ |
180 return NPF_TILE_LENGTH; |
182 return NPF_TILE_LENGTH; |
181 } |
183 } |
242 #endif |
244 #endif |
243 } |
245 } |
244 |
246 |
245 static int32 NPFWaterPathCost(AyStar* as, AyStarNode* current, OpenListNode* parent) |
247 static int32 NPFWaterPathCost(AyStar* as, AyStarNode* current, OpenListNode* parent) |
246 { |
248 { |
247 //TileIndex tile = current->tile; |
249 /* TileIndex tile = current->tile; */ |
248 int32 cost = 0; |
250 int32 cost = 0; |
249 Trackdir trackdir = (Trackdir)current->direction; |
251 Trackdir trackdir = (Trackdir)current->direction; |
250 |
252 |
251 cost = _trackdir_length[trackdir]; /* Should be different for diagonal tracks */ |
253 cost = _trackdir_length[trackdir]; // Should be different for diagonal tracks |
252 |
254 |
253 if (IsBuoyTile(current->tile) && IsDiagonalTrackdir(trackdir)) |
255 if (IsBuoyTile(current->tile) && IsDiagonalTrackdir(trackdir)) |
254 cost += _patches.npf_buoy_penalty; /* A small penalty for going over buoys */ |
256 cost += _patches.npf_buoy_penalty; // A small penalty for going over buoys |
255 |
257 |
256 if (current->direction != NextTrackdir((Trackdir)parent->path.node.direction)) |
258 if (current->direction != NextTrackdir((Trackdir)parent->path.node.direction)) |
257 cost += _patches.npf_water_curve_penalty; |
259 cost += _patches.npf_water_curve_penalty; |
258 |
260 |
259 /* TODO More penalties? */ |
261 /* @todo More penalties? */ |
260 |
262 |
261 return cost; |
263 return cost; |
262 } |
264 } |
263 |
265 |
264 /* Determine the cost of this node, for road tracks */ |
266 /* Determine the cost of this node, for road tracks */ |
383 cost += NPFSlopeCost(current); |
385 cost += NPFSlopeCost(current); |
384 |
386 |
385 /* Check for turns */ |
387 /* Check for turns */ |
386 if (current->direction != NextTrackdir((Trackdir)parent->path.node.direction)) |
388 if (current->direction != NextTrackdir((Trackdir)parent->path.node.direction)) |
387 cost += _patches.npf_rail_curve_penalty; |
389 cost += _patches.npf_rail_curve_penalty; |
388 //TODO, with realistic acceleration, also the amount of straight track between |
390 /*TODO, with realistic acceleration, also the amount of straight track between |
389 // curves should be taken into account, as this affects the speed limit. |
391 * curves should be taken into account, as this affects the speed limit. */ |
390 |
392 |
391 /* Check for reverse in depot */ |
393 /* Check for reverse in depot */ |
392 if (IsTileDepotType(tile, TRANSPORT_RAIL) && as->EndNodeCheck(as, &new_node) != AYSTAR_FOUND_END_NODE) { |
394 if (IsTileDepotType(tile, TRANSPORT_RAIL) && as->EndNodeCheck(as, &new_node) != AYSTAR_FOUND_END_NODE) { |
393 /* Penalise any depot tile that is not the last tile in the path. This |
395 /* Penalise any depot tile that is not the last tile in the path. This |
394 * _should_ penalise every occurence of reversing in a depot (and only |
396 * _should_ penalise every occurence of reversing in a depot (and only |
542 |
544 |
543 DiagDirection exitdir; |
545 DiagDirection exitdir; |
544 /* Find out the exit direction first */ |
546 /* Find out the exit direction first */ |
545 if (IsRoadStopTile(src_tile)) { |
547 if (IsRoadStopTile(src_tile)) { |
546 exitdir = GetRoadStopDir(src_tile); |
548 exitdir = GetRoadStopDir(src_tile); |
547 } else { /* Train or road depot */ |
549 } else { // Train or road depot |
548 exitdir = GetDepotDirection(src_tile, type); |
550 exitdir = GetDepotDirection(src_tile, type); |
549 } |
551 } |
550 |
552 |
551 /* Let's see if were headed the right way into the depot */ |
553 /* Let's see if were headed the right way into the depot */ |
552 if (src_trackdir == DiagdirToDiagTrackdir(ReverseDiagDir(exitdir))) { |
554 if (src_trackdir == DiagdirToDiagTrackdir(ReverseDiagDir(exitdir))) { |
608 if (type != TRANSPORT_WATER && (IsStandardRoadStopTile(dst_tile) || IsTileDepotType(dst_tile, type))){ |
610 if (type != TRANSPORT_WATER && (IsStandardRoadStopTile(dst_tile) || IsTileDepotType(dst_tile, type))){ |
609 /* Road stations and road and train depots return 0 on GTTS, so we have to do this by hand... */ |
611 /* Road stations and road and train depots return 0 on GTTS, so we have to do this by hand... */ |
610 DiagDirection exitdir; |
612 DiagDirection exitdir; |
611 if (IsRoadStopTile(dst_tile)) { |
613 if (IsRoadStopTile(dst_tile)) { |
612 exitdir = GetRoadStopDir(dst_tile); |
614 exitdir = GetRoadStopDir(dst_tile); |
613 } else { /* Road or train depot */ |
615 } else { // Road or train depot |
614 exitdir = GetDepotDirection(dst_tile, type); |
616 exitdir = GetDepotDirection(dst_tile, type); |
615 } |
617 } |
616 /* Find the trackdirs that are available for a depot or station with this |
618 /* Find the trackdirs that are available for a depot or station with this |
617 * orientation. They are only "inwards", since we are reaching this tile |
619 * orientation. They are only "inwards", since we are reaching this tile |
618 * from some other tile. This prevents vehicles driving into depots from |
620 * from some other tile. This prevents vehicles driving into depots from |
638 DEBUG(npf, 5, "Expanded into trackdir: %d, remaining trackdirs: 0x%X", dst_trackdir, trackdirbits); |
640 DEBUG(npf, 5, "Expanded into trackdir: %d, remaining trackdirs: 0x%X", dst_trackdir, trackdirbits); |
639 |
641 |
640 /* Check for oneway signal against us */ |
642 /* Check for oneway signal against us */ |
641 if (IsTileType(dst_tile, MP_RAILWAY) && GetRailTileType(dst_tile) == RAIL_TILE_SIGNALS) { |
643 if (IsTileType(dst_tile, MP_RAILWAY) && GetRailTileType(dst_tile) == RAIL_TILE_SIGNALS) { |
642 if (HasSignalOnTrackdir(dst_tile, ReverseTrackdir(dst_trackdir)) && !HasSignalOnTrackdir(dst_tile, dst_trackdir)) |
644 if (HasSignalOnTrackdir(dst_tile, ReverseTrackdir(dst_trackdir)) && !HasSignalOnTrackdir(dst_tile, dst_trackdir)) |
643 // if one way signal not pointing towards us, stop going in this direction. |
645 /* if one way signal not pointing towards us, stop going in this direction. */ |
644 break; |
646 break; |
645 } |
647 } |
646 { |
648 { |
647 /* We've found ourselves a neighbour :-) */ |
649 /* We've found ourselves a neighbour :-) */ |
648 AyStarNode* neighbour = &aystar->neighbours[i]; |
650 AyStarNode* neighbour = &aystar->neighbours[i]; |