summaryrefslogtreecommitdiff
path: root/ai/default
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2006-11-05 21:50:08 +0000
committerpeter1138 <peter1138@openttd.org>2006-11-05 21:50:08 +0000
commit6f290da2008132e35ffad6d17728791084fe3a66 (patch)
treeb5907c51ec768ae9e190925cbdfd9f54ebc304e0 /ai/default
parentfd361b104de0aca6ce3f5f41856502f306f28b14 (diff)
downloadopenttd-6f290da2008132e35ffad6d17728791084fe3a66.tar.xz
(svn r7070) -Codechange: Make the AI choose road vehicles based on a rating (currently max speed * capacity) instead of either the cost or the index of the vheicle.
Diffstat (limited to 'ai/default')
-rw-r--r--ai/default/default.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/ai/default/default.c b/ai/default/default.c
index 379f4516e..35fc85305 100644
--- a/ai/default/default.c
+++ b/ai/default/default.c
@@ -162,12 +162,14 @@ static EngineID AiChooseTrainToBuild(RailType railtype, int32 money, byte flag,
static EngineID AiChooseRoadVehToBuild(CargoID cargo, int32 money, TileIndex tile)
{
EngineID best_veh_index = INVALID_ENGINE;
- int32 best_veh_cost = 0;
+ int32 best_veh_rating = 0;
EngineID i = ROAD_ENGINES_INDEX;
EngineID end = i + NUM_ROAD_ENGINES;
for (; i != end; i++) {
+ const RoadVehicleInfo *rvi = RoadVehInfo(i);
const Engine* e = GetEngine(i);
+ int32 rating;
int32 ret;
if (!HASBIT(e->player_avail, _current_player) || e->reliability < 0x8A3D) {
@@ -175,13 +177,17 @@ static EngineID AiChooseRoadVehToBuild(CargoID cargo, int32 money, TileIndex til
}
/* Skip vehicles which can't take our cargo type */
- if (RoadVehInfo(i)->cargo_type != cargo) continue;
+ if (rvi->cargo_type != 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 && ret >= best_veh_cost) {
- best_veh_cost = ret;
- best_veh_index = i;
- }
+ if (CmdFailed(ret) || ret > money) continue;
+
+ best_veh_rating = rating;
+ best_veh_index = i;
}
return best_veh_index;