211 int z1 = GetSlopeZ(x1 + dx4, y1 + dy4); |
211 int z1 = GetSlopeZ(x1 + dx4, y1 + dy4); |
212 int z2 = GetSlopeZ(x2 - dx4, y2 - dy4); |
212 int z2 = GetSlopeZ(x2 - dx4, y2 - dy4); |
213 |
213 |
214 if (z2 - z1 > 1) { |
214 if (z2 - z1 > 1) { |
215 /* Slope up */ |
215 /* Slope up */ |
216 return _settings.pf.npf.npf_rail_slope_penalty; |
216 return _settings_game.pf.npf.npf_rail_slope_penalty; |
217 } |
217 } |
218 return 0; |
218 return 0; |
219 /* Should we give a bonus for slope down? Probably not, we |
219 /* Should we give a bonus for slope down? Probably not, we |
220 * could just substract that bonus from the penalty, because |
220 * could just substract that bonus from the penalty, because |
221 * there is only one level of steepness... */ |
221 * there is only one level of steepness... */ |
258 Trackdir trackdir = (Trackdir)current->direction; |
258 Trackdir trackdir = (Trackdir)current->direction; |
259 |
259 |
260 cost = _trackdir_length[trackdir]; // Should be different for diagonal tracks |
260 cost = _trackdir_length[trackdir]; // Should be different for diagonal tracks |
261 |
261 |
262 if (IsBuoyTile(current->tile) && IsDiagonalTrackdir(trackdir)) |
262 if (IsBuoyTile(current->tile) && IsDiagonalTrackdir(trackdir)) |
263 cost += _settings.pf.npf.npf_buoy_penalty; // A small penalty for going over buoys |
263 cost += _settings_game.pf.npf.npf_buoy_penalty; // A small penalty for going over buoys |
264 |
264 |
265 if (current->direction != NextTrackdir((Trackdir)parent->path.node.direction)) |
265 if (current->direction != NextTrackdir((Trackdir)parent->path.node.direction)) |
266 cost += _settings.pf.npf.npf_water_curve_penalty; |
266 cost += _settings_game.pf.npf.npf_water_curve_penalty; |
267 |
267 |
268 /* @todo More penalties? */ |
268 /* @todo More penalties? */ |
269 |
269 |
270 return cost; |
270 return cost; |
271 } |
271 } |
283 break; |
283 break; |
284 |
284 |
285 case MP_ROAD: |
285 case MP_ROAD: |
286 cost = NPF_TILE_LENGTH; |
286 cost = NPF_TILE_LENGTH; |
287 /* Increase the cost for level crossings */ |
287 /* Increase the cost for level crossings */ |
288 if (IsLevelCrossing(tile)) cost += _settings.pf.npf.npf_crossing_penalty; |
288 if (IsLevelCrossing(tile)) cost += _settings_game.pf.npf.npf_crossing_penalty; |
289 break; |
289 break; |
290 |
290 |
291 case MP_STATION: |
291 case MP_STATION: |
292 cost = NPF_TILE_LENGTH; |
292 cost = NPF_TILE_LENGTH; |
293 /* Increase the cost for drive-through road stops */ |
293 /* Increase the cost for drive-through road stops */ |
294 if (IsDriveThroughStopTile(tile)) cost += _settings.pf.npf.npf_road_drive_through_penalty; |
294 if (IsDriveThroughStopTile(tile)) cost += _settings_game.pf.npf.npf_road_drive_through_penalty; |
295 break; |
295 break; |
296 |
296 |
297 default: |
297 default: |
298 break; |
298 break; |
299 } |
299 } |
304 cost += NPFSlopeCost(current); |
304 cost += NPFSlopeCost(current); |
305 |
305 |
306 /* Check for turns. Road vehicles only really drive diagonal, turns are |
306 /* Check for turns. Road vehicles only really drive diagonal, turns are |
307 * represented by non-diagonal tracks */ |
307 * represented by non-diagonal tracks */ |
308 if (!IsDiagonalTrackdir((Trackdir)current->direction)) |
308 if (!IsDiagonalTrackdir((Trackdir)current->direction)) |
309 cost += _settings.pf.npf.npf_road_curve_penalty; |
309 cost += _settings_game.pf.npf.npf_road_curve_penalty; |
310 |
310 |
311 NPFMarkTile(tile); |
311 NPFMarkTile(tile); |
312 DEBUG(npf, 4, "Calculating G for: (%d, %d). Result: %d", TileX(current->tile), TileY(current->tile), cost); |
312 DEBUG(npf, 4, "Calculating G for: (%d, %d). Result: %d", TileX(current->tile), TileY(current->tile), cost); |
313 return cost; |
313 return cost; |
314 } |
314 } |
342 * station tiles that are not our destination this penalty. This would |
342 * station tiles that are not our destination this penalty. This would |
343 * discourage trains to drive through busy stations. But, we can just |
343 * discourage trains to drive through busy stations. But, we can just |
344 * give any station tile a penalty, because every possible route will get |
344 * give any station tile a penalty, because every possible route will get |
345 * this penalty exactly once, on its end tile (if it's a station) and it |
345 * this penalty exactly once, on its end tile (if it's a station) and it |
346 * will therefore not make a difference. */ |
346 * will therefore not make a difference. */ |
347 cost = NPF_TILE_LENGTH + _settings.pf.npf.npf_rail_station_penalty; |
347 cost = NPF_TILE_LENGTH + _settings_game.pf.npf.npf_rail_station_penalty; |
348 break; |
348 break; |
349 |
349 |
350 default: |
350 default: |
351 break; |
351 break; |
352 } |
352 } |
364 |
364 |
365 /* Is this a presignal exit or combo? */ |
365 /* Is this a presignal exit or combo? */ |
366 SignalType sigtype = GetSignalType(tile, TrackdirToTrack(trackdir)); |
366 SignalType sigtype = GetSignalType(tile, TrackdirToTrack(trackdir)); |
367 if (sigtype == SIGTYPE_EXIT || sigtype == SIGTYPE_COMBO) { |
367 if (sigtype == SIGTYPE_EXIT || sigtype == SIGTYPE_COMBO) { |
368 /* Penalise exit and combo signals differently (heavier) */ |
368 /* Penalise exit and combo signals differently (heavier) */ |
369 cost += _settings.pf.npf.npf_rail_firstred_exit_penalty; |
369 cost += _settings_game.pf.npf.npf_rail_firstred_exit_penalty; |
370 } else { |
370 } else { |
371 cost += _settings.pf.npf.npf_rail_firstred_penalty; |
371 cost += _settings_game.pf.npf.npf_rail_firstred_penalty; |
372 } |
372 } |
373 } |
373 } |
374 /* Record the state of this signal */ |
374 /* Record the state of this signal */ |
375 NPFSetFlag(current, NPF_FLAG_LAST_SIGNAL_RED, true); |
375 NPFSetFlag(current, NPF_FLAG_LAST_SIGNAL_RED, true); |
376 } else { |
376 } else { |
384 * red */ |
384 * red */ |
385 /* HACK: We create a new_node here so we can call EndNodeCheck. Ugly as hell |
385 /* HACK: We create a new_node here so we can call EndNodeCheck. Ugly as hell |
386 * of course... */ |
386 * of course... */ |
387 new_node.path.node = *current; |
387 new_node.path.node = *current; |
388 if (as->EndNodeCheck(as, &new_node) == AYSTAR_FOUND_END_NODE && NPFGetFlag(current, NPF_FLAG_LAST_SIGNAL_RED)) |
388 if (as->EndNodeCheck(as, &new_node) == AYSTAR_FOUND_END_NODE && NPFGetFlag(current, NPF_FLAG_LAST_SIGNAL_RED)) |
389 cost += _settings.pf.npf.npf_rail_lastred_penalty; |
389 cost += _settings_game.pf.npf.npf_rail_lastred_penalty; |
390 |
390 |
391 /* Check for slope */ |
391 /* Check for slope */ |
392 cost += NPFSlopeCost(current); |
392 cost += NPFSlopeCost(current); |
393 |
393 |
394 /* Check for turns */ |
394 /* Check for turns */ |
395 if (current->direction != NextTrackdir((Trackdir)parent->path.node.direction)) |
395 if (current->direction != NextTrackdir((Trackdir)parent->path.node.direction)) |
396 cost += _settings.pf.npf.npf_rail_curve_penalty; |
396 cost += _settings_game.pf.npf.npf_rail_curve_penalty; |
397 /*TODO, with realistic acceleration, also the amount of straight track between |
397 /*TODO, with realistic acceleration, also the amount of straight track between |
398 * curves should be taken into account, as this affects the speed limit. */ |
398 * curves should be taken into account, as this affects the speed limit. */ |
399 |
399 |
400 /* Check for reverse in depot */ |
400 /* Check for reverse in depot */ |
401 if (IsRailDepotTile(tile) && as->EndNodeCheck(as, &new_node) != AYSTAR_FOUND_END_NODE) { |
401 if (IsRailDepotTile(tile) && as->EndNodeCheck(as, &new_node) != AYSTAR_FOUND_END_NODE) { |
402 /* Penalise any depot tile that is not the last tile in the path. This |
402 /* Penalise any depot tile that is not the last tile in the path. This |
403 * _should_ penalise every occurence of reversing in a depot (and only |
403 * _should_ penalise every occurence of reversing in a depot (and only |
404 * that) */ |
404 * that) */ |
405 cost += _settings.pf.npf.npf_rail_depot_reverse_penalty; |
405 cost += _settings_game.pf.npf.npf_rail_depot_reverse_penalty; |
406 } |
406 } |
407 |
407 |
408 /* Check for occupied track */ |
408 /* Check for occupied track */ |
409 //TODO |
409 //TODO |
410 |
410 |
632 |
632 |
633 /* Select only trackdirs we can reach from our current trackdir */ |
633 /* Select only trackdirs we can reach from our current trackdir */ |
634 trackdirbits &= TrackdirReachesTrackdirs(src_trackdir); |
634 trackdirbits &= TrackdirReachesTrackdirs(src_trackdir); |
635 |
635 |
636 /* Filter out trackdirs that would make 90 deg turns for trains */ |
636 /* Filter out trackdirs that would make 90 deg turns for trains */ |
637 if (_settings.pf.forbid_90_deg && (type == TRANSPORT_RAIL || type == TRANSPORT_WATER)) trackdirbits &= ~TrackdirCrossesTrackdirs(src_trackdir); |
637 if (_settings_game.pf.forbid_90_deg && (type == TRANSPORT_RAIL || type == TRANSPORT_WATER)) trackdirbits &= ~TrackdirCrossesTrackdirs(src_trackdir); |
638 |
638 |
639 DEBUG(npf, 6, "After filtering: (%d, %d), possible trackdirs: 0x%X", TileX(dst_tile), TileY(dst_tile), trackdirbits); |
639 DEBUG(npf, 6, "After filtering: (%d, %d), possible trackdirs: 0x%X", TileX(dst_tile), TileY(dst_tile), trackdirbits); |
640 |
640 |
641 return trackdirbits; |
641 return trackdirbits; |
642 } |
642 } |
968 _npf_aystar.loops_per_tick = 0; |
968 _npf_aystar.loops_per_tick = 0; |
969 _npf_aystar.max_path_cost = 0; |
969 _npf_aystar.max_path_cost = 0; |
970 //_npf_aystar.max_search_nodes = 0; |
970 //_npf_aystar.max_search_nodes = 0; |
971 /* We will limit the number of nodes for now, until we have a better |
971 /* We will limit the number of nodes for now, until we have a better |
972 * solution to really fix performance */ |
972 * solution to really fix performance */ |
973 _npf_aystar.max_search_nodes = _settings.pf.npf.npf_max_search_nodes; |
973 _npf_aystar.max_search_nodes = _settings_game.pf.npf.npf_max_search_nodes; |
974 } |
974 } |
975 |
975 |
976 void NPFFillWithOrderData(NPFFindStationOrTileData* fstd, Vehicle* v) |
976 void NPFFillWithOrderData(NPFFindStationOrTileData* fstd, Vehicle* v) |
977 { |
977 { |
978 /* Ships don't really reach their stations, but the tile in front. So don't |
978 /* Ships don't really reach their stations, but the tile in front. So don't |