565 // This function finds a good spot for a station |
565 // This function finds a good spot for a station |
566 static void AiNew_State_FindStation(Player *p) |
566 static void AiNew_State_FindStation(Player *p) |
567 { |
567 { |
568 TileIndex tile; |
568 TileIndex tile; |
569 Station *st; |
569 Station *st; |
570 int i, count = 0; |
570 int count = 0; |
|
571 EngineID i; |
571 TileIndex new_tile = 0; |
572 TileIndex new_tile = 0; |
572 byte direction = 0; |
573 byte direction = 0; |
573 Town *town = NULL; |
574 Town *town = NULL; |
574 Industry *industry = NULL; |
575 Industry *industry = NULL; |
575 assert(p->ainew.state == AI_STATE_FIND_STATION); |
576 assert(p->ainew.state == AI_STATE_FIND_STATION); |
604 // If there is enough cargo left in the station, we take that station |
605 // If there is enough cargo left in the station, we take that station |
605 // If that is not possible, and there are more than 2 stations in the city, abort |
606 // If that is not possible, and there are more than 2 stations in the city, abort |
606 i = AiNew_PickVehicle(p); |
607 i = AiNew_PickVehicle(p); |
607 // Euhmz, this should not happen _EVER_ |
608 // Euhmz, this should not happen _EVER_ |
608 // Quit finding a route... |
609 // Quit finding a route... |
609 if (i == -1) { p->ainew.state = AI_STATE_NOTHING; return; } |
610 if (i == INVALID_ENGINE) { |
|
611 p->ainew.state = AI_STATE_NOTHING; |
|
612 return; |
|
613 } |
610 |
614 |
611 FOR_ALL_STATIONS(st) { |
615 FOR_ALL_STATIONS(st) { |
612 if (st->xy != 0) { |
616 if (st->xy != 0) { |
613 if (st->owner == _current_player) { |
617 if (st->owner == _current_player) { |
614 if (p->ainew.tbt == AI_BUS && (FACIL_BUS_STOP & st->facilities) == FACIL_BUS_STOP) { |
618 if (p->ainew.tbt == AI_BUS && (FACIL_BUS_STOP & st->facilities) == FACIL_BUS_STOP) { |
865 // It returns the cost for the vehicles |
869 // It returns the cost for the vehicles |
866 static int AiNew_HowManyVehicles(Player *p) |
870 static int AiNew_HowManyVehicles(Player *p) |
867 { |
871 { |
868 if (p->ainew.tbt == AI_BUS) { |
872 if (p->ainew.tbt == AI_BUS) { |
869 // For bus-routes we look at the time before we are back in the station |
873 // For bus-routes we look at the time before we are back in the station |
870 int i, length, tiles_a_day; |
874 EngineID i; |
|
875 int length, tiles_a_day; |
871 int amount; |
876 int amount; |
872 i = AiNew_PickVehicle(p); |
877 i = AiNew_PickVehicle(p); |
873 if (i == -1) return 0; |
878 if (i == INVALID_ENGINE) return 0; |
874 // Passenger run.. how long is the route? |
879 // Passenger run.. how long is the route? |
875 length = p->ainew.path_info.route_length; |
880 length = p->ainew.path_info.route_length; |
876 // Calculating tiles a day a vehicle moves is not easy.. this is how it must be done! |
881 // Calculating tiles a day a vehicle moves is not easy.. this is how it must be done! |
877 tiles_a_day = RoadVehInfo(i)->max_speed * DAY_TICKS / 256 / 16; |
882 tiles_a_day = RoadVehInfo(i)->max_speed * DAY_TICKS / 256 / 16; |
878 // We want a vehicle in a station once a month at least, so, calculate it! |
883 // We want a vehicle in a station once a month at least, so, calculate it! |
880 amount = length * 2 * 2 / tiles_a_day / 30; |
885 amount = length * 2 * 2 / tiles_a_day / 30; |
881 if (amount == 0) amount = 1; |
886 if (amount == 0) amount = 1; |
882 return amount; |
887 return amount; |
883 } else if (p->ainew.tbt == AI_TRUCK) { |
888 } else if (p->ainew.tbt == AI_TRUCK) { |
884 // For truck-routes we look at the cargo |
889 // For truck-routes we look at the cargo |
885 int i, length, amount, tiles_a_day; |
890 EngineID i; |
|
891 int length, amount, tiles_a_day; |
886 int max_cargo; |
892 int max_cargo; |
887 i = AiNew_PickVehicle(p); |
893 i = AiNew_PickVehicle(p); |
888 if (i == -1) return 0; |
894 if (i == INVALID_ENGINE) return 0; |
889 // Passenger run.. how long is the route? |
895 // Passenger run.. how long is the route? |
890 length = p->ainew.path_info.route_length; |
896 length = p->ainew.path_info.route_length; |
891 // Calculating tiles a day a vehicle moves is not easy.. this is how it must be done! |
897 // Calculating tiles a day a vehicle moves is not easy.. this is how it must be done! |
892 tiles_a_day = RoadVehInfo(i)->max_speed * DAY_TICKS / 256 / 16; |
898 tiles_a_day = RoadVehInfo(i)->max_speed * DAY_TICKS / 256 / 16; |
893 if (p->ainew.from_deliver) |
899 if (p->ainew.from_deliver) |
1179 if (p->ainew.tbt == AI_TRAIN) { |
1185 if (p->ainew.tbt == AI_TRAIN) { |
1180 } else { |
1186 } else { |
1181 p->ainew.veh_id = _new_roadveh_id; |
1187 p->ainew.veh_id = _new_roadveh_id; |
1182 } |
1188 } |
1183 |
1189 |
1184 if (p->ainew.veh_main_id != (VehicleID)-1) { |
1190 if (p->ainew.veh_main_id != INVALID_VEHICLE) { |
1185 AI_DoCommand(0, p->ainew.veh_id + (p->ainew.veh_main_id << 16), 0, DC_EXEC, CMD_CLONE_ORDER); |
1191 AI_DoCommand(0, p->ainew.veh_id + (p->ainew.veh_main_id << 16), 0, DC_EXEC, CMD_CLONE_ORDER); |
1186 |
1192 |
1187 p->ainew.state = AI_STATE_START_VEHICLE; |
1193 p->ainew.state = AI_STATE_START_VEHICLE; |
1188 return; |
1194 return; |
1189 } else { |
1195 } else { |