summaryrefslogtreecommitdiff
path: root/ai/default
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2006-11-05 22:49:34 +0000
committerpeter1138 <peter1138@openttd.org>2006-11-05 22:49:34 +0000
commit6ebac79c45114d1a6027c6f57524427228de6c9a (patch)
tree27a9331871ceead0d4bf5ed3ac92ceefb00bb410 /ai/default
parent7ab311cd693622059de4161b31008fa6d866bba5 (diff)
downloadopenttd-6ebac79c45114d1a6027c6f57524427228de6c9a.tar.xz
(svn r7073) -Feature: Add cargo refit support to both AIs for road vehicles
Diffstat (limited to 'ai/default')
-rw-r--r--ai/default/default.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/ai/default/default.c b/ai/default/default.c
index 35fc85305..496a17a62 100644
--- a/ai/default/default.c
+++ b/ai/default/default.c
@@ -177,14 +177,18 @@ static EngineID AiChooseRoadVehToBuild(CargoID cargo, int32 money, TileIndex til
}
/* Skip vehicles which can't take our cargo type */
- if (rvi->cargo_type != cargo) continue;
+ if (rvi->cargo_type != cargo && !CanRefitTo(i, cargo)) continue;
/* Rate and compare the engine by speed & capacity */
rating = rvi->max_speed * rvi->capacity;
if (rating <= best_veh_rating) continue;
ret = DoCommand(tile, i, 0, 0, CMD_BUILD_ROAD_VEH);
- if (CmdFailed(ret) || ret > money) continue;
+ if (CmdFailed(ret)) continue;
+
+ /* Add the cost of refitting */
+ if (rvi->cargo_type != cargo) ret += GetRefitCost(i);
+ if (ret > money) continue;
best_veh_rating = rating;
best_veh_index = i;
@@ -3184,6 +3188,15 @@ static void AiStateBuildRoadVehicles(Player *p)
loco_id = _new_vehicle_id;
+ if (GetVehicle(loco_id)->cargo_type != p->ai.cargo_type) {
+ /* Cargo type doesn't match, so refit it */
+ if (CmdFailed(DoCommand(tile, loco_id, p->ai.cargo_type, DC_EXEC, CMD_REFIT_ROAD_VEH))) {
+ /* Refit failed... sell the vehicle */
+ DoCommand(tile, loco_id, 0, DC_EXEC, CMD_SELL_ROAD_VEH);
+ return;
+ }
+ }
+
for (i = 0; p->ai.order_list_blocks[i] != 0xFF; i++) {
const AiBuildRec* aib = &p->ai.src + p->ai.order_list_blocks[i];
bool is_pass = (