(svn r2432) Use GetEngine() instead of DEREF_ENGINE() or even _engines[]
authortron
Tue, 07 Jun 2005 18:13:49 +0000
changeset 1926 68d60188a22f
parent 1925 e4bbd7fc2353
child 1927 4126e0e3e884
(svn r2432) Use GetEngine() instead of DEREF_ENGINE() or even _engines[]
ai.c
ai_build.c
aircraft_cmd.c
aircraft_gui.c
engine.c
engine.h
engine_gui.c
oldloader.c
roadveh_cmd.c
roadveh_gui.c
ship_cmd.c
ship_gui.c
train_cmd.c
train_gui.c
vehicle.c
vehicle_gui.c
--- a/ai.c	Tue Jun 07 16:44:54 2005 +0000
+++ b/ai.c	Tue Jun 07 18:13:49 2005 +0000
@@ -104,7 +104,7 @@
 
 			/* not reliable? */
 			if ((v->age != 0 &&
-					_engines[v->engine_type].reliability < 35389) ||
+					GetEngine(v->engine_type)->reliability < 35389) ||
 					v->age >= v->max_age) {
 				p->ai.state = AIS_VEH_CHECK_REPLACE_VEHICLE;
 				p->ai.cur_veh = v;
@@ -126,7 +126,7 @@
 
 	for (i = 0; i < NUM_TRAIN_ENGINES; i++) {
 		const RailVehicleInfo *rvi = RailVehInfo(i);
-		Engine *e = DEREF_ENGINE(i);
+		const Engine* e = GetEngine(i);
 
 		if (e->railtype != railtype || rvi->flags & RVI_WAGON
 		    || !HASBIT(e->player_avail, _current_player) || e->reliability < 0x8A3D)
@@ -151,7 +151,8 @@
 
 	int i = _cargoc.ai_roadveh_start[cargo];
 	int end = i + _cargoc.ai_roadveh_count[cargo];
-	Engine *e = &_engines[i];
+	const Engine* e = GetEngine(i);
+
 	do {
 		if (!HASBIT(e->player_avail, _current_player) || e->reliability < 0x8A3D)
 			continue;
@@ -174,7 +175,8 @@
 
 	int i = AIRCRAFT_ENGINES_INDEX;
 	int end = i + NUM_AIRCRAFT_ENGINES;
-	Engine *e = &_engines[i];
+	const Engine* e = GetEngine(i);
+
 	do {
 		if (!HASBIT(e->player_avail, _current_player) || e->reliability < 0x8A3D)
 			continue;
--- a/ai_build.c	Tue Jun 07 16:44:54 2005 +0000
+++ b/ai_build.c	Tue Jun 07 18:13:49 2005 +0000
@@ -221,7 +221,7 @@
         for (i=start+count-1;i>=start;i--) {
         	// Is it availiable?
         	// Also, check if the reliability of the vehicle is above the AI_VEHICLE_MIN_RELIABILTY
-        	if (!HASBIT(_engines[i].player_avail, _current_player) || _engines[i].reliability * 100 < AI_VEHICLE_MIN_RELIABILTY << 16) continue;
+        	if (!HASBIT(GetEngine(i)->player_avail, _current_player) || GetEngine(i)->reliability * 100 < AI_VEHICLE_MIN_RELIABILTY << 16) continue;
         	// Can we build it?
         	ret = DoCommandByTile(0, i, 0, DC_QUERY_COST, CMD_BUILD_ROAD_VEH);
         	if (!CmdFailed(ret)) break;
--- a/aircraft_cmd.c	Tue Jun 07 16:44:54 2005 +0000
+++ b/aircraft_cmd.c	Tue Jun 07 18:13:49 2005 +0000
@@ -256,7 +256,7 @@
 
 		u->subtype = 4;
 
-		e = &_engines[p1];
+		e = GetEngine(p1);
 		v->reliability = e->reliability;
 		v->reliability_spd_dec = e->reliability_spd_dec;
 		v->max_age = e->lifelength * 366;
@@ -1470,7 +1470,7 @@
 				// an exerpt of ServiceAircraft, without the invisibility stuff
 				v->date_of_last_service = _date;
 				v->breakdowns_since_last_service = 0;
-				v->reliability = _engines[v->engine_type].reliability;
+				v->reliability = GetEngine(v->engine_type)->reliability;
 				InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
 			}
 		}
--- a/aircraft_gui.c	Tue Jun 07 16:44:54 2005 +0000
+++ b/aircraft_gui.c	Tue Jun 07 18:13:49 2005 +0000
@@ -24,7 +24,7 @@
 void DrawAircraftPurchaseInfo(int x, int y, EngineID engine_number)
 {
 	const AircraftVehicleInfo *avi = AircraftVehInfo(engine_number);
-	Engine *e = &_engines[engine_number];
+	const Engine* e = GetEngine(engine_number);
 	YearMonthDay ymd;
 	ConvertDayToYMD(&ymd, e->intro_date);
 
@@ -97,7 +97,8 @@
 		{
 			int count = 0;
 			int num = NUM_AIRCRAFT_ENGINES;
-			Engine *e = &_engines[AIRCRAFT_ENGINES_INDEX];
+			const Engine* e = GetEngine(AIRCRAFT_ENGINES_INDEX);
+
 			do {
 				if (HASBIT(e->player_avail, _local_player))
 					count++;
@@ -109,7 +110,7 @@
 
 		{
 			int num = NUM_AIRCRAFT_ENGINES;
-			Engine *e = &_engines[AIRCRAFT_ENGINES_INDEX];
+			const Engine* e = GetEngine(AIRCRAFT_ENGINES_INDEX);
 			int x = 2;
 			int y = 15;
 			int sel = WP(w,buildtrain_d).sel_index;
--- a/engine.c	Tue Jun 07 16:44:54 2005 +0000
+++ b/engine.c	Tue Jun 07 18:13:49 2005 +0000
@@ -839,7 +839,7 @@
 	Engine *e;
 	if (!IsEngineIndex(p1)) return CMD_ERROR;
 
-	e = DEREF_ENGINE(p1);
+	e = GetEngine(p1);
 	if (GetBestPlayer(e->preview_player) != _current_player) return CMD_ERROR;
 
 	if (flags & DC_EXEC)
@@ -1028,7 +1028,7 @@
 {
 	int index;
 	while ((index = SlIterateArray()) != -1) {
-		SlObject(&_engines[index], _engine_desc);
+		SlObject(GetEngine(index), _engine_desc);
 	}
 }
 
@@ -1057,7 +1057,7 @@
 	// check if it's an engine that is in the engine array
 	if (!IsEngineIndex(engine)) return false;
 
-	e = DEREF_ENGINE(engine);
+	e = GetEngine(engine);
 
 	// check if it's an engine of specified type
 	if (e->type != type) return false;
--- a/engine.h	Tue Jun 07 16:44:54 2005 +0000
+++ b/engine.h	Tue Jun 07 18:13:49 2005 +0000
@@ -222,7 +222,7 @@
 };
 VARDEF Engine _engines[TOTAL_NUM_ENGINES];
 #define FOR_ALL_ENGINES(e) for (e = _engines; e != endof(_engines); e++)
-#define DEREF_ENGINE(i) (GetEngine(i))
+
 static inline Engine* GetEngine(uint i)
 {
   assert(i < lengthof(_engines));
--- a/engine_gui.c	Tue Jun 07 16:44:54 2005 +0000
+++ b/engine_gui.c	Tue Jun 07 18:13:49 2005 +0000
@@ -13,7 +13,7 @@
 static StringID GetEngineCategoryName(byte engine)
 {
 	if (engine < NUM_TRAIN_ENGINES) {
-		switch (_engines[engine].railtype) {
+		switch (GetEngine(engine)->railtype) {
 			case 0:
 				return STR_8102_RAILROAD_LOCOMOTIVE;
 			case 1:
--- a/oldloader.c	Tue Jun 07 16:44:54 2005 +0000
+++ b/oldloader.c	Tue Jun 07 18:13:49 2005 +0000
@@ -1339,12 +1339,12 @@
 };
 static bool LoadOldEngine(LoadgameState *ls, int num)
 {
-	if (!LoadChunk(ls, &_engines[num], engine_chunk))
+	if (!LoadChunk(ls, GetEngine(num), engine_chunk))
 		return false;
 
 	/* Make sure wagons are marked as do-not-age */
 	if ((num >= 27 && num < 54) || (num >= 57 && num < 84) || (num >= 89 && num < 116))
-		_engines[num].age = 0xFFFF;
+		GetEngine(num)->age = 0xFFFF;
 
 	return true;
 }
--- a/roadveh_cmd.c	Tue Jun 07 16:44:54 2005 +0000
+++ b/roadveh_cmd.c	Tue Jun 07 18:13:49 2005 +0000
@@ -183,7 +183,7 @@
 		v->max_speed = rvi->max_speed;
 		v->engine_type = (byte)p1;
 
-		e = DEREF_ENGINE(p1);
+		e = GetEngine(p1);
 		v->reliability = e->reliability;
 		v->reliability_spd_dec = e->reliability_spd_dec;
 		v->max_age = e->lifelength * 366;
--- a/roadveh_gui.c	Tue Jun 07 16:44:54 2005 +0000
+++ b/roadveh_gui.c	Tue Jun 07 18:13:49 2005 +0000
@@ -23,7 +23,7 @@
 void DrawRoadVehPurchaseInfo(int x, int y, EngineID engine_number)
 {
 	const RoadVehicleInfo *rvi = RoadVehInfo(engine_number);
-	Engine *e = &_engines[engine_number];
+	const Engine* e = GetEngine(engine_number);
 	YearMonthDay ymd;
 	ConvertDayToYMD(&ymd, e->intro_date);
 
@@ -370,7 +370,8 @@
 	{
 		int count = 0;
 		int num = NUM_ROAD_ENGINES;
-		Engine *e = &_engines[ROAD_ENGINES_INDEX];
+		const Engine* e = GetEngine(ROAD_ENGINES_INDEX);
+
 		do {
 			if (HASBIT(e->player_avail, _local_player))
 				count++;
@@ -382,7 +383,7 @@
 
 	{
 		int num = NUM_ROAD_ENGINES;
-		Engine *e = &_engines[ROAD_ENGINES_INDEX];
+		const Engine* e = GetEngine(ROAD_ENGINES_INDEX);
 		int x = 1;
 		int y = 15;
 		int sel = WP(w,buildtrain_d).sel_index;
--- a/ship_cmd.c	Tue Jun 07 16:44:54 2005 +0000
+++ b/ship_cmd.c	Tue Jun 07 18:13:49 2005 +0000
@@ -912,7 +912,7 @@
 		v->max_speed = svi->max_speed;
 		v->engine_type = (byte)p1;
 
-		e = &_engines[p1];
+		e = GetEngine(p1);
 		v->reliability = e->reliability;
 		v->reliability_spd_dec = e->reliability_spd_dec;
 		v->max_age = e->lifelength * 366;
--- a/ship_gui.c	Tue Jun 07 16:44:54 2005 +0000
+++ b/ship_gui.c	Tue Jun 07 18:13:49 2005 +0000
@@ -44,7 +44,7 @@
 	y += 10;
 
 	/* Design date - Life length */
-	e = &_engines[engine_number];
+	e = GetEngine(engine_number);
 	ConvertDayToYMD(&ymd, e->intro_date);
 	SetDParam(0, ymd.year + 1920);
 	SetDParam(1, e->lifelength);
@@ -326,7 +326,8 @@
 		{
 			int count = 0;
 			int num = NUM_SHIP_ENGINES;
-			Engine *e = &_engines[SHIP_ENGINES_INDEX];
+			const Engine* e = GetEngine(SHIP_ENGINES_INDEX);
+
 			do {
 				if (HASBIT(e->player_avail, _local_player))
 					count++;
@@ -338,7 +339,7 @@
 
 		{
 			int num = NUM_SHIP_ENGINES;
-			Engine *e = &_engines[SHIP_ENGINES_INDEX];
+			const Engine* e = GetEngine(SHIP_ENGINES_INDEX);
 			int x = 2;
 			int y = 15;
 			int sel = WP(w,buildtrain_d).sel_index;
--- a/train_cmd.c	Tue Jun 07 16:44:54 2005 +0000
+++ b/train_cmd.c	Tue Jun 07 18:13:49 2005 +0000
@@ -481,7 +481,7 @@
 			v->value = value;
 //			v->day_counter = 0;
 
-			e = &_engines[engine];
+			e = GetEngine(engine);
 			v->u.rail.railtype = e->railtype;
 
 			v->build_year = _cur_year;
@@ -650,7 +650,7 @@
 			v->dest_tile = 0;
 
 			v->engine_type = (byte)p1;
-			e = DEREF_ENGINE(p1);
+			e = GetEngine(p1);
 
 			v->reliability = e->reliability;
 			v->reliability_spd_dec = e->reliability_spd_dec;
@@ -1693,9 +1693,9 @@
 		int engtype = v->engine_type;
 
 		// no smoke?
-		if (RailVehInfo(engtype)->flags & 2
-		    || _engines[engtype].railtype > 0
-		    || (v->vehstatus&VS_HIDDEN) || (v->u.rail.track & 0xC0) )
+		if (RailVehInfo(engtype)->flags & 2 ||
+				GetEngine(engtype)->railtype > 0 ||
+				(v->vehstatus & VS_HIDDEN) || (v->u.rail.track & 0xC0))
 			continue;
 
 		switch (RailVehInfo(engtype)->engclass) {
@@ -1738,7 +1738,7 @@
 
 	int engtype = v->engine_type;
 
-	switch (_engines[engtype].railtype) {
+	switch (GetEngine(engtype)->railtype) {
 		case 0:
 			SndPlayVehicleFx(sfx[RailVehInfo(engtype)->engclass], v);
 			break;
--- a/train_gui.c	Tue Jun 07 16:44:54 2005 +0000
+++ b/train_gui.c	Tue Jun 07 18:13:49 2005 +0000
@@ -26,7 +26,7 @@
 void DrawTrainEnginePurchaseInfo(int x, int y, EngineID engine_number)
 {
 	const RailVehicleInfo *rvi = RailVehInfo(engine_number);
-	Engine *e = &_engines[engine_number];
+	const Engine* e = GetEngine(engine_number);
 	int multihead = (rvi->flags&RVI_MULTIHEAD?1:0);
 	YearMonthDay ymd;
 	ConvertDayToYMD(&ymd, e->intro_date);
@@ -157,7 +157,7 @@
 	int i;
 
 	for (i = 0; i < NUM_TRAIN_ENGINES; i++) {
-		const Engine *e = DEREF_ENGINE(i);
+		const Engine *e = GetEngine(i);
 		const RailVehicleInfo *rvi = RailVehInfo(i);
 
 		if (e->railtype != railtype || !(rvi->flags & RVI_WAGON) != is_engine ||
@@ -191,7 +191,7 @@
 			int i;
 
 			for (i = 0; i < NUM_TRAIN_ENGINES; i++) {
-				const Engine *e = DEREF_ENGINE(i);
+				const Engine *e = GetEngine(i);
 				if (e->railtype == railtype
 				    && HASBIT(e->player_avail, _local_player))
 					count++;
--- a/vehicle.c	Tue Jun 07 16:44:54 2005 +0000
+++ b/vehicle.c	Tue Jun 07 18:13:49 2005 +0000
@@ -49,7 +49,7 @@
 {
 	v->date_of_last_service = _date;
 	v->breakdowns_since_last_service = 0;
-	v->reliability = _engines[v->engine_type].reliability;
+	v->reliability = GetEngine(v->engine_type)->reliability;
 }
 
 bool VehicleNeedsService(const Vehicle *v)
@@ -61,7 +61,7 @@
 		return false; /* Crashed vehicles don't need service anymore */
 
 	return _patches.servint_ispercent ?
-		(v->reliability < _engines[v->engine_type].reliability * (100 - v->service_interval) / 100) :
+		(v->reliability < GetEngine(v->engine_type)->reliability * (100 - v->service_interval) / 100) :
 		(v->date_of_last_service + v->service_interval < _date);
 }
 
@@ -1358,7 +1358,7 @@
 	if (!IsEngineIndex(new_engine_type)) return CMD_ERROR;
 
 	// check that the new vehicle type is the same as the original one
-	if (v->type != DEREF_ENGINE(new_engine_type)->type) return CMD_ERROR;
+	if (v->type != GetEngine(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;
@@ -1369,7 +1369,7 @@
 	}
 
 	// makes sure that the player can actually buy the new engine. Renewing is still allowed to outdated engines
-	if (!HASBIT(DEREF_ENGINE(new_engine_type)->player_avail, v->owner) && old_engine_type != new_engine_type) return CMD_ERROR;
+	if (!HASBIT(GetEngine(new_engine_type)->player_avail, v->owner) && old_engine_type != new_engine_type) return CMD_ERROR;
 
 	switch (v->type) {
 		case VEH_Train:    build_cost = EstimateTrainCost(RailVehInfo(new_engine_type)); break;
@@ -1438,7 +1438,7 @@
 
 	if (flags & DC_EXEC) {
 		/* We do not really buy a new vehicle, we upgrade the old one */
-		Engine *e = DEREF_ENGINE(new_engine_type);
+		const Engine* e = GetEngine(new_engine_type);
 
 		v->reliability = e->reliability;
 		v->reliability_spd_dec = e->reliability_spd_dec;
@@ -1620,7 +1620,7 @@
 	 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 == DEREF_ENGINE(_autoreplace_array[v->engine_type])->type);
+	assert(v->type == GetEngine(_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);
--- a/vehicle_gui.c	Tue Jun 07 16:44:54 2005 +0000
+++ b/vehicle_gui.c	Tue Jun 07 18:13:49 2005 +0000
@@ -391,7 +391,7 @@
 	byte colour;
 
 	for (i = 0; i < NUM_TRAIN_ENGINES; i++) {
-		const Engine *e = DEREF_ENGINE(i);
+		const Engine *e = GetEngine(i);
 		const RailVehicleInfo *rvi = RailVehInfo(i);
 		const EngineInfo *info = &_engine_info[i];
 
@@ -448,7 +448,7 @@
 			w->widget[13].color = _player_colors[_local_player];	// sets the colour of that art thing
 			w->widget[16].color = _player_colors[_local_player];	// sets the colour of that art thing
 			for (engine_id = 0; engine_id < NUM_TRAIN_ENGINES; engine_id++) {
-				const Engine *e = DEREF_ENGINE(engine_id);
+				const Engine *e = GetEngine(engine_id);
 				const EngineInfo *info = &_engine_info[engine_id];
 
 				if (ENGINE_AVAILABLE && RailVehInfo(engine_id)->power && e->railtype == railtype ) {
@@ -468,7 +468,7 @@
 		}
 		case VEH_Road: {
 			int num = NUM_ROAD_ENGINES;
-			Engine *e = DEREF_ENGINE(ROAD_ENGINES_INDEX);
+			Engine *e = GetEngine(ROAD_ENGINES_INDEX);
 			byte cargo;
 			EngineInfo *info;
 			engine_id = ROAD_ENGINES_INDEX;
@@ -485,7 +485,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 = DEREF_ENGINE(ROAD_ENGINES_INDEX);
+				e = GetEngine(ROAD_ENGINES_INDEX);
 				cargo = RoadVehInfo(selected_id[0])->cargo_type;
 
 				do {
@@ -501,7 +501,7 @@
 
 		case VEH_Ship: {
 			int num = NUM_SHIP_ENGINES;
-			Engine *e = DEREF_ENGINE(SHIP_ENGINES_INDEX);
+			Engine *e = GetEngine(SHIP_ENGINES_INDEX);
 			byte cargo, refittable;
 			EngineInfo *info;
 			engine_id = SHIP_ENGINES_INDEX;
@@ -517,7 +517,7 @@
 
 			if ( selected_id[0] != -1 ) {
 				num = NUM_SHIP_ENGINES;
-				e = DEREF_ENGINE(SHIP_ENGINES_INDEX);
+				e = GetEngine(SHIP_ENGINES_INDEX);
 				engine_id = SHIP_ENGINES_INDEX;
 				cargo = ShipVehInfo(selected_id[0])->cargo_type;
 				refittable = ShipVehInfo(selected_id[0])->refittable;
@@ -538,7 +538,7 @@
 		case VEH_Aircraft:{
 			int num = NUM_AIRCRAFT_ENGINES;
 			byte subtype;
-			Engine *e = DEREF_ENGINE(AIRCRAFT_ENGINES_INDEX);
+			Engine *e = GetEngine(AIRCRAFT_ENGINES_INDEX);
 			EngineInfo *info;
 			engine_id = AIRCRAFT_ENGINES_INDEX;
 
@@ -553,7 +553,7 @@
 
 			if ( selected_id[0] != -1 ) {
 				num = NUM_AIRCRAFT_ENGINES;
-				e = DEREF_ENGINE(AIRCRAFT_ENGINES_INDEX);
+				e = GetEngine(AIRCRAFT_ENGINES_INDEX);
 				subtype = AircraftVehInfo(selected_id[0])->subtype;
 				engine_id = AIRCRAFT_ENGINES_INDEX;
 				do {
@@ -612,7 +612,7 @@
 
 		case VEH_Road: {
 			int num = NUM_ROAD_ENGINES;
-			Engine *e = DEREF_ENGINE(ROAD_ENGINES_INDEX);
+			Engine *e = GetEngine(ROAD_ENGINES_INDEX);
 			int engine_id = ROAD_ENGINES_INDEX;
 			byte cargo;
 			EngineInfo *info;
@@ -648,7 +648,7 @@
 
 		case VEH_Ship: {
 			int num = NUM_SHIP_ENGINES;
-			Engine *e = DEREF_ENGINE(SHIP_ENGINES_INDEX);
+			Engine *e = GetEngine(SHIP_ENGINES_INDEX);
 			int engine_id = SHIP_ENGINES_INDEX;
 			byte cargo, refittable;
 			EngineInfo *info;
@@ -687,7 +687,7 @@
 		case VEH_Aircraft: {
 			if ( selected_id[0] != -1 ) {
 				int num = NUM_AIRCRAFT_ENGINES;
-				Engine *e = DEREF_ENGINE(AIRCRAFT_ENGINES_INDEX);
+				Engine *e = GetEngine(AIRCRAFT_ENGINES_INDEX);
 				int engine_id = AIRCRAFT_ENGINES_INDEX;
 				byte subtype = AircraftVehInfo(selected_id[0])->subtype;
 				EngineInfo *info;
@@ -757,7 +757,7 @@
 							// do not count the vehicles, that contains only 0 in all var
 							if (vehicle->engine_type == 0 && vehicle->spritenum == 0 ) continue;
 
-							if (vehicle->type != DEREF_ENGINE(vehicle->engine_type)->type) continue;
+							if (vehicle->type != GetEngine(vehicle->engine_type)->type) continue;
 
 							_player_num_engines[vehicle->engine_type]++;
 						}
@@ -892,9 +892,9 @@
 				// finds mask for available engines
 				{
 					int engine_avail = 0;
-					if ( !(HASBIT(DEREF_ENGINE(NUM_NORMAL_RAIL_ENGINES + NUM_MONORAIL_ENGINES)->player_avail, _local_player))) {
+					if (!HASBIT(GetEngine(NUM_NORMAL_RAIL_ENGINES + NUM_MONORAIL_ENGINES)->player_avail, _local_player)) {
 						engine_avail = 4;
-						if ( !(HASBIT(DEREF_ENGINE(NUM_NORMAL_RAIL_ENGINES)->player_avail, _local_player)))
+						if (!HASBIT(GetEngine(NUM_NORMAL_RAIL_ENGINES)->player_avail, _local_player))
 							engine_avail = 6;
 					}
 					ShowDropDownMenu(w, _rail_types_list, _railtype_selected_in_replace_gui, 15, engine_avail, 1);