summaryrefslogtreecommitdiff
path: root/ai/trolly
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/trolly
parent7ab311cd693622059de4161b31008fa6d866bba5 (diff)
downloadopenttd-6ebac79c45114d1a6027c6f57524427228de6c9a.tar.xz
(svn r7073) -Feature: Add cargo refit support to both AIs for road vehicles
Diffstat (limited to 'ai/trolly')
-rw-r--r--ai/trolly/build.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/ai/trolly/build.c b/ai/trolly/build.c
index 9c73cc0e2..8583c86fe 100644
--- a/ai/trolly/build.c
+++ b/ai/trolly/build.c
@@ -246,7 +246,7 @@ EngineID AiNew_PickVehicle(Player *p)
int32 ret;
/* Skip vehicles which can't take our cargo type */
- if (rvi->cargo_type != p->ainew.cargo) continue;
+ if (rvi->cargo_type != p->ainew.cargo && !CanRefitTo(i, p->ainew.cargo)) continue;
// Is it availiable?
// Also, check if the reliability of the vehicle is above the AI_VEHICLE_MIN_RELIABILTY
@@ -276,6 +276,17 @@ void CcAI(bool success, TileIndex tile, uint32 p1, uint32 p2)
if (success) {
p->ainew.state = AI_STATE_GIVE_ORDERS;
p->ainew.veh_id = _new_vehicle_id;
+
+ if (GetVehicle(p->ainew.veh_id)->cargo_type != p->ainew.cargo) {
+ /* Cargo type doesn't match, so refit it */
+ debug("doing refit");
+ if (CmdFailed(DoCommand(tile, p->ainew.veh_id, p->ainew.cargo, DC_EXEC, CMD_REFIT_ROAD_VEH))) {
+ debug("refit failed, selling");
+ /* Refit failed, so sell the vehicle */
+ DoCommand(tile, p->ainew.veh_id, 0, DC_EXEC, CMD_SELL_ROAD_VEH);
+ p->ainew.state = AI_STATE_NOTHING;
+ }
+ }
} else {
/* XXX this should be handled more gracefully */
p->ainew.state = AI_STATE_NOTHING;