Add a penalty when getting on and off a train

This commit is contained in:
Markus Koch 2024-04-08 18:39:44 +02:00
parent f1868aba04
commit b32feb66a3
3 changed files with 8 additions and 4 deletions

View File

@ -180,10 +180,7 @@ dijkstra_cost dijkstra_get_weight_from_distance(struct dijkstra_node *node_a,
switch (net_type) {
case TRAINLINE:
scale = 5.0;
break;
case ACCESS:
scale = 0.5;
scale = 10.0;
break;
default:
scale = 1.0;

View File

@ -112,6 +112,11 @@ struct dijkstra_node *dijkstra_search_process_queue(struct dijkstra_search *sear
for (l = node->paths; l != NULL; l = l->next) {
path = (struct dijkstra_path*) l->data;
cost = state->cost + path->weight;
if (state->cheapest_path && path->net_meta->type == ACCESS) { // If we just jumped onto an access path
if (state->cheapest_path->net_meta->type != ACCESS) {// and we came from a non-access path (getting on or off)
cost += (DIJKSTRA_ACCESS_PENALTY * 100.0); // add a penalty
}
}
connection = dijkstra_node_get_connection(node, path);

View File

@ -5,6 +5,8 @@
#define DIJKSTRA_SEARCH_MAX_ITERATIONS 5000
#define DIJKSTRA_ACCESS_PENALTY 300.0
struct dijkstra_state {
struct dijkstra_path *cheapest_path;
dijkstra_cost cost;