summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbjarni <bjarni@openttd.org>2005-01-05 19:28:10 +0000
committerbjarni <bjarni@openttd.org>2005-01-05 19:28:10 +0000
commit1e99155d61e2433eed70446ab7bc6053c86d69a6 (patch)
tree6fd641e2ff719297020a5c4793ca8dbf56135688
parentcc465f0f35eac488eeae6508c38c3f524edf29ed (diff)
downloadopenttd-1e99155d61e2433eed70446ab7bc6053c86d69a6.tar.xz
(svn r1393) fix [ 1096026 ]. Autorenew trains should now hopefully work like it did before autoreplace was added
DEREF_ENGINE is now used in autoreplace
-rw-r--r--vehicle.c8
-rw-r--r--vehicle_gui.c22
2 files changed, 15 insertions, 15 deletions
diff --git a/vehicle.c b/vehicle.c
index 1b79e0a8a..6ea7cfa60 100644
--- a/vehicle.c
+++ b/vehicle.c
@@ -1421,7 +1421,7 @@ int32 CmdReplaceVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2)
if (new_engine_type >= TOTAL_NUM_ENGINES ) return CMD_ERROR;
// check that the new vehicle type is the same as the original one
- if (v->type != _engines[new_engine_type].type) return CMD_ERROR;
+ if (v->type != DEREF_ENGINE(new_engine_type)->type) return CMD_ERROR;
// check that it's the vehicle's owner that requested the replace
if (!CheckOwnership(v->owner)) return CMD_ERROR;
@@ -1465,7 +1465,7 @@ int32 CmdReplaceVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2)
if (flags & DC_EXEC) {
Engine *e;
- e = &_engines[new_engine_type];
+ e = DEREF_ENGINE(new_engine_type);
// TODO make it check if refit is possible before actually doing it
@@ -1606,14 +1606,14 @@ void MaybeReplaceVehicle(Vehicle *v)
the last 8 bit is the engine. The 8 bits in front of the engine is free so it have room for 16 bit engine entries */
new_engine_and_autoreplace_money = ((_patches.autorenew_money / 100000) << 16) + _autoreplace_array[v->engine_type];
- assert(v->type == _engines[ _autoreplace_array[v->engine_type] ].type);
+ assert(v->type == DEREF_ENGINE(_autoreplace_array[v->engine_type])->type);
if ( v->type != VEH_Train ) {
DoCommandP(v->tile, v->index, new_engine_and_autoreplace_money, NULL, CMD_REPLACE_VEHICLE | CMD_SHOW_NO_ERROR);
} else {
// checks if any of the engines in the train are either old or listed for replacement
do {
- if ( v->engine_type != _autoreplace_array[v->engine_type] || (v->age - v->max_age) > (_patches.autorenew_months * 30)) {
+ if ( v->engine_type != _autoreplace_array[v->engine_type] || (_patches.autorenew && (v->age - v->max_age) > (_patches.autorenew_months * 30))) {
new_engine_and_autoreplace_money = (new_engine_and_autoreplace_money & 0xFFFF0000) + _autoreplace_array[v->engine_type]; // sets the new engine replacement type
DoCommandP(v->tile, v->index, new_engine_and_autoreplace_money, NULL, CMD_REPLACE_VEHICLE | CMD_SHOW_NO_ERROR);
}
diff --git a/vehicle_gui.c b/vehicle_gui.c
index 1c6362f47..8a8b69655 100644
--- a/vehicle_gui.c
+++ b/vehicle_gui.c
@@ -386,7 +386,7 @@ static void SetupScrollStuffForReplaceWindow(Window *w)
}
case VEH_Road: {
int num = NUM_ROAD_ENGINES;
- Engine *e = &_engines[ROAD_ENGINES_INDEX];
+ Engine *e = DEREF_ENGINE(ROAD_ENGINES_INDEX);
byte cargo;
EngineInfo *info;
engine_id = ROAD_ENGINES_INDEX;
@@ -403,7 +403,7 @@ static void SetupScrollStuffForReplaceWindow(Window *w)
if ( selected_id[0] != -1 ) { // only draw right array if we have anything in the left one
num = NUM_ROAD_ENGINES;
engine_id = ROAD_ENGINES_INDEX;
- e = &_engines[ROAD_ENGINES_INDEX];
+ e = DEREF_ENGINE(ROAD_ENGINES_INDEX);
cargo = RoadVehInfo(selected_id[0])->cargo_type;
do {
@@ -419,7 +419,7 @@ static void SetupScrollStuffForReplaceWindow(Window *w)
case VEH_Ship: {
int num = NUM_SHIP_ENGINES;
- Engine *e = &_engines[SHIP_ENGINES_INDEX];
+ Engine *e = DEREF_ENGINE(SHIP_ENGINES_INDEX);
byte cargo, refittable;
EngineInfo *info;
engine_id = SHIP_ENGINES_INDEX;
@@ -435,7 +435,7 @@ static void SetupScrollStuffForReplaceWindow(Window *w)
if ( selected_id[0] != -1 ) {
num = NUM_SHIP_ENGINES;
- e = &_engines[SHIP_ENGINES_INDEX];
+ e = DEREF_ENGINE(SHIP_ENGINES_INDEX);
engine_id = SHIP_ENGINES_INDEX;
cargo = ShipVehInfo(selected_id[0])->cargo_type;
refittable = ShipVehInfo(selected_id[0])->refittable;
@@ -456,7 +456,7 @@ static void SetupScrollStuffForReplaceWindow(Window *w)
case VEH_Aircraft:{
int num = NUM_AIRCRAFT_ENGINES;
byte subtype;
- Engine *e = &_engines[AIRCRAFT_ENGINES_INDEX];
+ Engine *e = DEREF_ENGINE(AIRCRAFT_ENGINES_INDEX);
EngineInfo *info;
engine_id = AIRCRAFT_ENGINES_INDEX;
@@ -471,7 +471,7 @@ static void SetupScrollStuffForReplaceWindow(Window *w)
if ( selected_id[0] != -1 ) {
num = NUM_AIRCRAFT_ENGINES;
- e = &_engines[AIRCRAFT_ENGINES_INDEX];
+ e = DEREF_ENGINE(AIRCRAFT_ENGINES_INDEX);
subtype = AircraftVehInfo(selected_id[0])->subtype;
engine_id = AIRCRAFT_ENGINES_INDEX;
do {
@@ -523,7 +523,7 @@ static void DrawEngineArrayInReplaceWindow(Window *w, int x, int y, int x2, int
case VEH_Road: {
int num = NUM_ROAD_ENGINES;
- Engine *e = &_engines[ROAD_ENGINES_INDEX];
+ Engine *e = DEREF_ENGINE(ROAD_ENGINES_INDEX);
int engine_id = ROAD_ENGINES_INDEX;
byte cargo;
EngineInfo *info;
@@ -557,7 +557,7 @@ static void DrawEngineArrayInReplaceWindow(Window *w, int x, int y, int x2, int
case VEH_Ship: {
int num = NUM_SHIP_ENGINES;
- Engine *e = &_engines[SHIP_ENGINES_INDEX];
+ Engine *e = DEREF_ENGINE(SHIP_ENGINES_INDEX);
int engine_id = SHIP_ENGINES_INDEX;
byte cargo, refittable;
EngineInfo *info;
@@ -594,7 +594,7 @@ static void DrawEngineArrayInReplaceWindow(Window *w, int x, int y, int x2, int
case VEH_Aircraft: {
if ( selected_id[0] != -1 ) {
int num = NUM_AIRCRAFT_ENGINES;
- Engine *e = &_engines[AIRCRAFT_ENGINES_INDEX];
+ Engine *e = DEREF_ENGINE(AIRCRAFT_ENGINES_INDEX);
int engine_id = AIRCRAFT_ENGINES_INDEX;
byte subtype = AircraftVehInfo(selected_id[0])->subtype;
EngineInfo *info;
@@ -782,9 +782,9 @@ static void ReplaceVehicleWndProc(Window *w, WindowEvent *e)
// finds mask for available engines
{
int engine_avail = 0;
- if ( !(HASBIT(_engines[NUM_NORMAL_RAIL_ENGINES + NUM_MONORAIL_ENGINES].player_avail, _local_player))) {
+ if ( !(HASBIT(DEREF_ENGINE(NUM_NORMAL_RAIL_ENGINES + NUM_MONORAIL_ENGINES)->player_avail, _local_player))) {
engine_avail = 4;
- if ( !(HASBIT(_engines[NUM_NORMAL_RAIL_ENGINES].player_avail, _local_player)))
+ if ( !(HASBIT(DEREF_ENGINE(NUM_NORMAL_RAIL_ENGINES)->player_avail, _local_player)))
engine_avail = 6;
}
ShowDropDownMenu(w, _rail_types_list, WP(w,replaceveh_d).railtype, 15, engine_avail, 1);