changeset 907:7633c1472eda draft

(svn r1393) fix [ 1096026 ]. Autorenew trains should now hopefully work like it did before autoreplace was added DEREF_ENGINE is now used in autoreplace
author bjarni <bjarni@openttd.org>
date Wed, 05 Jan 2005 19:28:10 +0000
parents 4ceb1c5aa4a5
children 1f4eb50fb136
files vehicle.c vehicle_gui.c
diffstat 2 files changed, 15 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/vehicle.c
+++ b/vehicle.c
@@ -1421,7 +1421,7 @@
 	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 @@
 
 	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 @@
 	 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);
 			}
--- a/vehicle_gui.c
+++ b/vehicle_gui.c
@@ -386,7 +386,7 @@
 			}
 		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 @@
 			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 @@
 
 		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 @@
 
 			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 @@
 		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 @@
 
 			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 @@
 
 		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 @@
 
 		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 @@
 		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 @@
 				// 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);