summaryrefslogtreecommitdiff
path: root/src/ai
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2008-04-29 21:31:29 +0000
committerpeter1138 <peter1138@openttd.org>2008-04-29 21:31:29 +0000
commita00371c8db9d3b944d901ea0468eb58fe51418a7 (patch)
tree82b8c0d69acb1c38843e4fcf0b11f46a057ef270 /src/ai
parent1d01390fa6d6ca83cd0cb148137d2a81749b380d (diff)
downloadopenttd-a00371c8db9d3b944d901ea0468eb58fe51418a7.tar.xz
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
Diffstat (limited to 'src/ai')
-rw-r--r--src/ai/default/default.cpp33
-rw-r--r--src/ai/trolly/build.cpp9
-rw-r--r--src/ai/trolly/trolly.cpp1
3 files changed, 23 insertions, 20 deletions
diff --git a/src/ai/default/default.cpp b/src/ai/default/default.cpp
index 27a86cd65..3a2d90c94 100644
--- a/src/ai/default/default.cpp
+++ b/src/ai/default/default.cpp
@@ -137,11 +137,11 @@ static EngineID AiChooseTrainToBuild(RailType railtype, Money money, byte flag,
{
EngineID best_veh_index = INVALID_ENGINE;
byte best_veh_score = 0;
- EngineID i;
+ const Engine *e;
- FOR_ALL_ENGINEIDS_OF_TYPE(i, VEH_TRAIN) {
- const RailVehicleInfo *rvi = RailVehInfo(i);
- const Engine* e = GetEngine(i);
+ FOR_ALL_ENGINES_OF_TYPE(e, VEH_TRAIN) {
+ EngineID i = e->index;
+ const RailVehicleInfo *rvi = &e->u.rail;
if (!IsCompatibleRail(rvi->railtype, railtype) ||
rvi->railveh_type == RAILVEH_WAGON ||
@@ -168,11 +168,11 @@ static EngineID AiChooseRoadVehToBuild(CargoID cargo, Money money, TileIndex til
{
EngineID best_veh_index = INVALID_ENGINE;
int32 best_veh_rating = 0;
- EngineID i;
+ const Engine *e;
- FOR_ALL_ENGINEIDS_OF_TYPE(i, VEH_ROAD) {
- const RoadVehicleInfo *rvi = RoadVehInfo(i);
- const Engine* e = GetEngine(i);
+ FOR_ALL_ENGINES_OF_TYPE(e, VEH_ROAD) {
+ EngineID i = e->index;
+ const RoadVehicleInfo *rvi = &e->u.road;
if (!HasBit(e->player_avail, _current_player) || e->reliability < 0x8A3D) {
continue;
@@ -209,16 +209,17 @@ static EngineID AiChooseAircraftToBuild(Money money, byte forbidden)
{
EngineID best_veh_index = INVALID_ENGINE;
Money best_veh_cost = 0;
- EngineID i;
+ const Engine *e;
- FOR_ALL_ENGINEIDS_OF_TYPE(i, VEH_AIRCRAFT) {
- const Engine* e = GetEngine(i);
+ FOR_ALL_ENGINES_OF_TYPE(e, VEH_AIRCRAFT) {
+ EngineID i = e->index;
+ const AircraftVehicleInfo *avi = &e->u.air;
if (!HasBit(e->player_avail, _current_player) || e->reliability < 0x8A3D) {
continue;
}
- if ((AircraftVehInfo(i)->subtype & forbidden) != 0) continue;
+ if ((avi->subtype & forbidden) != 0) continue;
CommandCost ret = DoCommand(0, i, 0, DC_QUERY_COST, CMD_BUILD_AIRCRAFT);
if (CmdSucceeded(ret) && ret.GetCost() <= money && ret.GetCost() >= best_veh_cost) {
@@ -2445,14 +2446,14 @@ static StationID AiGetStationIdByDef(TileIndex tile, int id)
static EngineID AiFindBestWagon(CargoID cargo, RailType railtype)
{
EngineID best_veh_index = INVALID_ENGINE;
- EngineID i;
uint16 best_capacity = 0;
uint16 best_speed = 0;
uint speed;
+ const Engine *e;
- FOR_ALL_ENGINEIDS_OF_TYPE(i, VEH_TRAIN) {
- const RailVehicleInfo *rvi = RailVehInfo(i);
- const Engine* e = GetEngine(i);
+ FOR_ALL_ENGINES_OF_TYPE(e, VEH_TRAIN) {
+ EngineID i = e->index;
+ const RailVehicleInfo *rvi = &e->u.rail;
if (!IsCompatibleRail(rvi->railtype, railtype) ||
rvi->railveh_type != RAILVEH_WAGON ||
diff --git a/src/ai/trolly/build.cpp b/src/ai/trolly/build.cpp
index b46984d0a..eb7154092 100644
--- a/src/ai/trolly/build.cpp
+++ b/src/ai/trolly/build.cpp
@@ -7,6 +7,7 @@
#include "../../command_func.h"
#include "trolly.h"
#include "../../engine_func.h"
+#include "../../engine_base.h"
#include "../../variables.h"
#include "../../bridge.h"
#include "../../vehicle_func.h"
@@ -235,12 +236,12 @@ EngineID AiNew_PickVehicle(Player *p)
} else {
EngineID best_veh_index = INVALID_ENGINE;
int32 best_veh_rating = 0;
- EngineID i;
+ const Engine *e;
/* Loop through all road vehicles */
- FOR_ALL_ENGINEIDS_OF_TYPE(i, VEH_ROAD) {
- const RoadVehicleInfo *rvi = RoadVehInfo(i);
- const Engine* e = GetEngine(i);
+ FOR_ALL_ENGINES_OF_TYPE(e, VEH_ROAD) {
+ EngineID i = e->index;
+ const RoadVehicleInfo *rvi = &e->u.road;
/* Skip vehicles which can't take our cargo type */
if (rvi->cargo_type != _players_ainew[p->index].cargo && !CanRefitTo(i, _players_ainew[p->index].cargo)) continue;
diff --git a/src/ai/trolly/trolly.cpp b/src/ai/trolly/trolly.cpp
index 49133386d..2a369cd03 100644
--- a/src/ai/trolly/trolly.cpp
+++ b/src/ai/trolly/trolly.cpp
@@ -29,6 +29,7 @@
#include "../../industry.h"
#include "../../station_base.h"
#include "../../engine_func.h"
+#include "../../engine_base.h"
#include "../../gui.h"
#include "../../depot_base.h"
#include "../../vehicle_base.h"