339 break; |
339 break; |
340 } |
340 } |
341 |
341 |
342 /* Determine extra costs */ |
342 /* Determine extra costs */ |
343 |
343 |
344 /* Ordinary track with signals */ |
344 /* Check for signals */ |
345 if (IsTileType(tile, MP_RAILWAY) && (_map5[tile] & 0xC0) == 0x40) { |
345 if (IsTileType(tile, MP_RAILWAY) && (_map5[tile] & 0xC0) == 0x40) { |
|
346 /* Ordinary track with signals */ |
346 if ((_map2[tile] & _signal_along_trackdir[trackdir]) == 0) { |
347 if ((_map2[tile] & _signal_along_trackdir[trackdir]) == 0) { |
347 /* Signal facing us is red */ |
348 /* Signal facing us is red */ |
348 if (!(current->user_data[NPF_NODE_FLAGS] & NPF_FLAG_SEEN_SIGNAL)) { |
349 if (!NPFGetFlag(current, NPF_FLAG_SEEN_SIGNAL)) { |
349 /* Penalize the first signal we |
350 /* Penalize the first signal we |
350 * encounter, if it is red */ |
351 * encounter, if it is red */ |
351 cost += _patches.npf_rail_firstred_penalty; |
352 cost += _patches.npf_rail_firstred_penalty; |
352 } |
353 } |
|
354 /* Record the state of this signal */ |
|
355 NPFSetFlag(current, NPF_FLAG_LAST_SIGNAL_RED, true); |
|
356 } else { |
|
357 /* Record the state of this signal */ |
|
358 NPFSetFlag(current, NPF_FLAG_LAST_SIGNAL_RED, false); |
353 } |
359 } |
354 current->user_data[NPF_NODE_FLAGS] |= NPF_FLAG_SEEN_SIGNAL; |
360 NPFSetFlag(current, NPF_FLAG_SEEN_SIGNAL, true); |
355 } |
361 } |
|
362 |
|
363 /* Penalise the tile if it is a target tile and the last signal was |
|
364 * red */ |
|
365 if (as->EndNodeCheck(as, current) && NPFGetFlag(current, NPF_FLAG_LAST_SIGNAL_RED)) |
|
366 cost += _patches.npf_rail_lastred_penalty; |
356 |
367 |
357 /* Check for slope */ |
368 /* Check for slope */ |
358 cost += NPFSlopeCost(current); |
369 cost += NPFSlopeCost(current); |
359 |
370 |
360 /* Check for turns */ |
371 /* Check for turns */ |
383 #endif |
394 #endif |
384 return cost; |
395 return cost; |
385 } |
396 } |
386 |
397 |
387 /* Will find any depot */ |
398 /* Will find any depot */ |
388 int32 NPFFindDepot(AyStar* as, OpenListNode *current) { |
399 int32 NPFFindDepot(AyStar* as, AyStarNode *node) { |
389 TileIndex tile = current->path.node.tile; |
400 TileIndex tile = node->tile; |
390 if (IsTileDepotType(tile, as->user_data[NPF_TYPE])) |
401 if (IsTileDepotType(tile, as->user_data[NPF_TYPE])) |
391 return AYSTAR_FOUND_END_NODE; |
402 return AYSTAR_FOUND_END_NODE; |
392 else |
403 else |
393 return AYSTAR_DONE; |
404 return AYSTAR_DONE; |
394 } |
405 } |
395 |
406 |
396 /* Will find a station identified using the NPFFindStationOrTileData */ |
407 /* Will find a station identified using the NPFFindStationOrTileData */ |
397 int32 NPFFindStationOrTile(AyStar* as, OpenListNode *current) { |
408 int32 NPFFindStationOrTile(AyStar* as, AyStarNode *node) { |
|
409 |
|
410 /* See if we checked this before */ |
|
411 if (NPFGetFlag(node, NPF_FLAG_TARGET_CHECKED)) |
|
412 return NPFGetFlag(node, NPF_FLAG_IS_TARGET); |
|
413 /* We're gonna check this now and store the result, let's mark that */ |
|
414 NPFSetFlag(node, NPF_FLAG_TARGET_CHECKED, true); |
|
415 |
398 /* If GetNeighbours said we could get here, we assume the station type |
416 /* If GetNeighbours said we could get here, we assume the station type |
399 * is correct */ |
417 * is correct */ |
400 NPFFindStationOrTileData* fstd = (NPFFindStationOrTileData*)as->user_target; |
418 NPFFindStationOrTileData* fstd = (NPFFindStationOrTileData*)as->user_target; |
401 TileIndex tile = current->path.node.tile; |
419 TileIndex tile = node->tile; |
402 if ( (fstd->station_index == -1 && tile == fstd->dest_coords) || /* We've found the tile, or */ |
420 if ( |
|
421 (fstd->station_index == -1 && tile == fstd->dest_coords) || /* We've found the tile, or */ |
403 (IsTileType(tile, MP_STATION) && _map2[tile] == fstd->station_index) /* the station */ |
422 (IsTileType(tile, MP_STATION) && _map2[tile] == fstd->station_index) /* the station */ |
404 ) |
423 ) { |
405 return AYSTAR_FOUND_END_NODE; |
424 NPFSetFlag(node, NPF_FLAG_TARGET_CHECKED, true); |
406 else |
425 return AYSTAR_FOUND_END_NODE; |
|
426 } else { |
|
427 NPFSetFlag(node, NPF_FLAG_TARGET_CHECKED, false); |
407 return AYSTAR_DONE; |
428 return AYSTAR_DONE; |
|
429 } |
408 } |
430 } |
409 |
431 |
410 /* To be called when current contains the (shortest route to) the target node. |
432 /* To be called when current contains the (shortest route to) the target node. |
411 * Will fill the contents of the NPFFoundTargetData using |
433 * Will fill the contents of the NPFFoundTargetData using |
412 * AyStarNode[NPF_TRACKDIR_CHOICE]. |
434 * AyStarNode[NPF_TRACKDIR_CHOICE]. |
420 } |
442 } |
421 |
443 |
422 /* Will just follow the results of GetTileTrackStatus concerning where we can |
444 /* Will just follow the results of GetTileTrackStatus concerning where we can |
423 * go and where not. Uses AyStar.user_data[NPF_TYPE] as the transport type and |
445 * go and where not. Uses AyStar.user_data[NPF_TYPE] as the transport type and |
424 * an argument to GetTileTrackStatus. Will skip tunnels, meaning that the |
446 * an argument to GetTileTrackStatus. Will skip tunnels, meaning that the |
425 * entry and exit are neighbours. Will fill AyStarNode.user_data[NPF_TRACKDIR_CHOICE] with an |
447 * entry and exit are neighbours. Will fill |
426 * appropriate value, and copy AyStarNode.user_data[NPF_NODE_FLAGS] from the |
448 * AyStarNode.user_data[NPF_TRACKDIR_CHOICE] with an appropriate value, and |
427 * parent */ |
449 * copy AyStarNode.user_data[NPF_NODE_FLAGS] from the parent */ |
428 void NPFFollowTrack(AyStar* aystar, OpenListNode* current) { |
450 void NPFFollowTrack(AyStar* aystar, OpenListNode* current) { |
429 byte src_trackdir = current->path.node.direction; |
451 byte src_trackdir = current->path.node.direction; |
430 TileIndex src_tile = current->path.node.tile; |
452 TileIndex src_tile = current->path.node.tile; |
431 byte src_exitdir = _trackdir_to_exitdir[src_trackdir]; |
453 byte src_exitdir = _trackdir_to_exitdir[src_trackdir]; |
432 FindLengthOfTunnelResult flotr; |
454 FindLengthOfTunnelResult flotr; |
579 start1->user_data[NPF_TRACKDIR_CHOICE] = 0xff; |
601 start1->user_data[NPF_TRACKDIR_CHOICE] = 0xff; |
580 start1->user_data[NPF_NODE_FLAGS] = 0; |
602 start1->user_data[NPF_NODE_FLAGS] = 0; |
581 _npf_aystar.addstart(&_npf_aystar, start1); |
603 _npf_aystar.addstart(&_npf_aystar, start1); |
582 if (start2) { |
604 if (start2) { |
583 start2->user_data[NPF_TRACKDIR_CHOICE] = 0xff; |
605 start2->user_data[NPF_TRACKDIR_CHOICE] = 0xff; |
584 start2->user_data[NPF_NODE_FLAGS] = NPF_FLAG_REVERSE; |
606 start2->user_data[NPF_NODE_FLAGS] = 0; |
|
607 NPFSetFlag(start2, NPF_FLAG_REVERSE, true); |
585 _npf_aystar.addstart(&_npf_aystar, start2); |
608 _npf_aystar.addstart(&_npf_aystar, start2); |
586 } |
609 } |
587 |
610 |
588 /* Initialize result */ |
611 /* Initialize result */ |
589 result.best_bird_dist = (uint)-1; |
612 result.best_bird_dist = (uint)-1; |