161 |
161 |
162 static EngineID AiChooseRoadVehToBuild(CargoID cargo, int32 money, TileIndex tile) |
162 static EngineID AiChooseRoadVehToBuild(CargoID cargo, int32 money, TileIndex tile) |
163 { |
163 { |
164 EngineID best_veh_index = INVALID_ENGINE; |
164 EngineID best_veh_index = INVALID_ENGINE; |
165 int32 best_veh_cost = 0; |
165 int32 best_veh_cost = 0; |
166 EngineID i = _cargoc.ai_roadveh_start[cargo]; |
166 EngineID i = ROAD_ENGINES_INDEX; |
167 EngineID end = i + _cargoc.ai_roadveh_count[cargo]; |
167 EngineID end = i + NUM_ROAD_ENGINES; |
168 |
168 |
169 for (; i != end; i++) { |
169 for (; i != end; i++) { |
170 const Engine* e = GetEngine(i); |
170 const Engine* e = GetEngine(i); |
171 int32 ret; |
171 int32 ret; |
172 |
172 |
173 if (!HASBIT(e->player_avail, _current_player) || e->reliability < 0x8A3D) { |
173 if (!HASBIT(e->player_avail, _current_player) || e->reliability < 0x8A3D) { |
174 continue; |
174 continue; |
175 } |
175 } |
|
176 |
|
177 /* Skip vehicles which can't take our cargo type */ |
|
178 if (RoadVehInfo(i)->cargo_type != cargo) continue; |
176 |
179 |
177 ret = DoCommand(tile, i, 0, 0, CMD_BUILD_ROAD_VEH); |
180 ret = DoCommand(tile, i, 0, 0, CMD_BUILD_ROAD_VEH); |
178 if (!CmdFailed(ret) && ret <= money && ret >= best_veh_cost) { |
181 if (!CmdFailed(ret) && ret <= money && ret >= best_veh_cost) { |
179 best_veh_cost = ret; |
182 best_veh_cost = ret; |
180 best_veh_index = i; |
183 best_veh_index = i; |