(svn r3620) - 2cc: Replace use of macro to determine colour map with a function call for drawing of vehicles.
authorpeter1138
Mon, 20 Feb 2006 09:26:07 +0000
changeset 3040 c3473d1fb81f
parent 3039 69cdde904bb5
child 3041 105098f42dfa
(svn r3620) - 2cc: Replace use of macro to determine colour map with a function call for drawing of vehicles.
aircraft_gui.c
roadveh_gui.c
ship_gui.c
train_gui.c
vehicle.c
vehicle.h
vehicle_gui.c
--- a/aircraft_gui.c	Mon Feb 20 01:36:48 2006 +0000
+++ b/aircraft_gui.c	Mon Feb 20 09:26:07 2006 +0000
@@ -65,7 +65,7 @@
 static void DrawAircraftImage(const Vehicle *v, int x, int y, VehicleID selection)
 {
 	int image = GetAircraftImage(v, 6);
-	uint32 ormod = SPRITE_PALETTE(PLAYER_SPRITE_COLOR(v->owner));
+	uint32 ormod = GetVehiclePalette(v);
 	if (v->vehstatus & VS_CRASHED) ormod = PALETTE_CRASH;
 	DrawSprite(image | ormod, x + 25, y + 10);
 	if (v->subtype == 0) DrawSprite(SPR_ROTOR_STOPPED, x + 25, y + 5);
@@ -126,7 +126,7 @@
 					if (sel==0) selected_id = engine_id;
 					if (IS_INT_INSIDE(--pos, -w->vscroll.cap, 0)) {
 						DrawString(x+62, y+7, GetCustomEngineName(engine_id), sel==0 ? 0xC : 0x10);
-						DrawAircraftEngine(x+29, y+10, engine_id, SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player)));
+						DrawAircraftEngine(x+29, y+10, engine_id, GetEnginePalette(engine_id, _local_player));
 						y += 24;
 					}
 					sel--;
@@ -732,7 +732,7 @@
 		if (v != NULL) {
 			WP(w,traindepot_d).sel = v->index;
 			SetWindowDirty(w);
-			SetObjectToPlaceWnd( SPRITE_PALETTE(PLAYER_SPRITE_COLOR(v->owner)) + GetAircraftImage(v, 6), 4, w);
+			SetObjectToPlaceWnd(GetVehiclePalette(v) | GetAircraftImage(v, 6), 4, w);
 		}
 		break;
 
--- a/roadveh_gui.c	Mon Feb 20 01:36:48 2006 +0000
+++ b/roadveh_gui.c	Mon Feb 20 09:26:07 2006 +0000
@@ -65,7 +65,7 @@
 static void DrawRoadVehImage(const Vehicle *v, int x, int y, VehicleID selection)
 {
 	int image = GetRoadVehImage(v, 6);
-	uint32 ormod = SPRITE_PALETTE(PLAYER_SPRITE_COLOR(v->owner));
+	uint32 ormod = GetVehiclePalette(v);
 	if (v->vehstatus & VS_CRASHED) ormod = PALETTE_CRASH;
 	DrawSprite(image | ormod, x + 14, y + 6);
 
@@ -412,7 +412,7 @@
 				if (sel==0) selected_id = engine_id;
 				if (IS_INT_INSIDE(--pos, -w->vscroll.cap, 0)) {
 					DrawString(x+59, y+2, GetCustomEngineName(engine_id), sel==0 ? 0xC : 0x10);
-					DrawRoadVehEngine(x+29, y+6, engine_id, SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player)));
+					DrawRoadVehEngine(x+29, y+6, engine_id, GetEnginePalette(engine_id, _local_player));
 					y += 14;
 				}
 				sel--;
@@ -638,7 +638,7 @@
 		if (v != NULL) {
 			WP(w,traindepot_d).sel = v->index;
 			SetWindowDirty(w);
-			SetObjectToPlaceWnd( SPRITE_PALETTE(PLAYER_SPRITE_COLOR(v->owner)) + GetRoadVehImage(v, 6), 4, w);
+			SetObjectToPlaceWnd(GetVehiclePalette(v) | GetRoadVehImage(v, 6), 4, w);
 		}
 		break;
 
--- a/ship_gui.c	Mon Feb 20 01:36:48 2006 +0000
+++ b/ship_gui.c	Mon Feb 20 09:26:07 2006 +0000
@@ -66,7 +66,7 @@
 static void DrawShipImage(const Vehicle *v, int x, int y, VehicleID selection)
 {
 	int image = GetShipImage(v, 6);
-	uint32 ormod = SPRITE_PALETTE(PLAYER_SPRITE_COLOR(v->owner));
+	uint32 ormod = GetVehiclePalette(v);
 	DrawSprite(image | ormod, x + 32, y + 10);
 
 	if (v->index == selection) {
@@ -354,7 +354,7 @@
 					if (sel==0) selected_id = engine_id;
 					if (IS_INT_INSIDE(--pos, -w->vscroll.cap, 0)) {
 						DrawString(x+75, y+7, GetCustomEngineName(engine_id), sel==0 ? 0xC : 0x10);
-						DrawShipEngine(x+35, y+10, engine_id, SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player)));
+						DrawShipEngine(x+35, y+10, engine_id, GetEnginePalette(engine_id, _local_player));
 						y += 24;
 					}
 					sel--;
@@ -715,8 +715,7 @@
 		if (v != NULL) {
 			WP(w,traindepot_d).sel = v->index;
 			SetWindowDirty(w);
-			SetObjectToPlaceWnd( SPRITE_PALETTE(PLAYER_SPRITE_COLOR(v->owner)) +
-				GetShipImage(v, 6), 4, w);
+			SetObjectToPlaceWnd(GetVehiclePalette(v) | GetShipImage(v, 6), 4, w);
 		}
 		break;
 
--- a/train_gui.c	Mon Feb 20 01:36:48 2006 +0000
+++ b/train_gui.c	Mon Feb 20 09:26:07 2006 +0000
@@ -186,8 +186,7 @@
 
 		if (IS_INT_INSIDE(--*pos, -show_max, 0)) {
 			DrawString(*x + 59, *y + 2, GetCustomEngineName(i), *sel == 0 ? 0xC : 0x10);
-			DrawTrainEngine(*x + 29, *y + 6, i,
-				SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player)));
+			DrawTrainEngine(*x + 29, *y + 6, i, GetEnginePalette(i, _local_player));
 			*y += 14;
 		}
 		--*sel;
@@ -360,7 +359,7 @@
 	do {
 		if (--skip < 0) {
 			int image = GetTrainImage(v, 6);
-			uint32 ormod = SPRITE_PALETTE(PLAYER_SPRITE_COLOR(v->owner));
+			uint32 ormod = GetVehiclePalette(v);
 			int width = v->u.rail.cached_veh_length;
 
 			if (dx + width <= count) {
@@ -581,7 +580,7 @@
 			TrainDepotMoveVehicle(v, sel, gdvp.head);
 		} else if (v != NULL) {
 			WP(w,traindepot_d).sel = v->index;
-			SetObjectToPlaceWnd( SPRITE_PALETTE(PLAYER_SPRITE_COLOR(v->owner)) + GetTrainImage(v, 6), 4, w);
+			SetObjectToPlaceWnd(GetVehiclePalette(v) | GetTrainImage(v, 6), 4, w);
 			SetWindowDirty(w);
 		}
 		break;
--- a/vehicle.c	Mon Feb 20 01:36:48 2006 +0000
+++ b/vehicle.c	Mon Feb 20 09:26:07 2006 +0000
@@ -698,7 +698,7 @@
 	if (v->vehstatus & VS_DISASTER) {
 		MAKE_TRANSPARENT(image);
 	} else if (v->vehstatus & VS_DEFPAL) {
-		image |= (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : SPRITE_PALETTE(PLAYER_SPRITE_COLOR(v->owner));
+		image |= (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
 	}
 
 	AddSortableSpriteToDraw(image, v->x_pos + v->x_offs, v->y_pos + v->y_offs,
@@ -2040,6 +2040,12 @@
 	return unit;
 }
 
+// XXX Temporary stub -- will be expanded
+PalSpriteID GetEngineColourMap(PlayerID player)
+{
+	return SPRITE_PALETTE(PLAYER_SPRITE_COLOR(player));
+}
+
 // Save and load of vehicles
 const SaveLoad _common_veh_desc[] = {
 	SLE_VAR(Vehicle,subtype,					SLE_UINT8),
--- a/vehicle.h	Mon Feb 20 01:36:48 2006 +0000
+++ b/vehicle.h	Mon Feb 20 09:26:07 2006 +0000
@@ -422,6 +422,20 @@
 
 #define INVALID_VEHICLE 0xFFFF
 
+// XXX Temporary interface -- will be expanded
+PalSpriteID GetEngineColourMap(PlayerID player);
+
+static inline PalSpriteID GetEnginePalette(EngineID engine_type, PlayerID player)
+{
+	return GetEngineColourMap(player);
+}
+
+static inline PalSpriteID GetVehiclePalette(const Vehicle *v)
+{
+	return GetEngineColourMap(v->owner);
+}
+
+
 /* A lot of code calls for the invalidation of the status bar, which is widget 5.
  * Best is to have a virtual value for it when it needs to change again */
 #define STATUS_BAR 5
--- a/vehicle_gui.c	Mon Feb 20 01:36:48 2006 +0000
+++ b/vehicle_gui.c	Mon Feb 20 09:26:07 2006 +0000
@@ -486,7 +486,7 @@
 				colour);
 			// show_outdated is true only for left side, which is where we show old replacements
 			DrawTrainEngine(*x + 29, *y + 6, i, (_player_num_engines[i] == 0 && show_outdated) ?
-				PALETTE_CRASH : SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player)));
+				PALETTE_CRASH : GetEnginePalette(i, _local_player));
 			if ( show_outdated ) {
 				SetDParam(0, _player_num_engines[i]);
 				DrawStringRightAligned(213, *y+5, STR_TINY_BLACK, 0);
@@ -670,7 +670,7 @@
 					if (_player_num_engines[engine_id] > 0 || EngineHasReplacementForPlayer(p, engine_id)) {
 						if (IS_INT_INSIDE(--pos, -w->vscroll.cap, 0)) {
 							DrawString(x+59, y+2, GetCustomEngineName(engine_id), sel[0]==0 ? 0xC : 0x10);
-							DrawRoadVehEngine(x+29, y+6, engine_id, _player_num_engines[engine_id] > 0 ? SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player)) : PALETTE_CRASH);
+							DrawRoadVehEngine(x+29, y+6, engine_id, _player_num_engines[engine_id] > 0 ? GetEnginePalette(engine_id, _local_player) : PALETTE_CRASH);
 							SetDParam(0, _player_num_engines[engine_id]);
 							DrawStringRightAligned(213, y+5, STR_TINY_BLACK, 0);
 							y += 14;
@@ -681,7 +681,7 @@
 					if (RoadVehInfo(engine_id)->cargo_type == cargo && HASBIT(e->player_avail, _local_player)) {
 						if (IS_INT_INSIDE(--pos2, -w->vscroll.cap, 0) && RoadVehInfo(engine_id)->cargo_type == cargo) {
 							DrawString(x2+59, y2+2, GetCustomEngineName(engine_id), sel[1]==0 ? 0xC : 0x10);
-							DrawRoadVehEngine(x2+29, y2+6, engine_id, SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player)));
+							DrawRoadVehEngine(x2+29, y2+6, engine_id, GetEnginePalette(engine_id, _local_player));
 							y2 += 14;
 						}
 						sel[1]--;
@@ -705,7 +705,7 @@
 					if (_player_num_engines[engine_id] > 0 || EngineHasReplacementForPlayer(p, engine_id)) {
 						if (IS_INT_INSIDE(--pos, -w->vscroll.cap, 0)) {
 							DrawString(x+75, y+7, GetCustomEngineName(engine_id), sel[0]==0 ? 0xC : 0x10);
-							DrawShipEngine(x+35, y+10, engine_id, _player_num_engines[engine_id] > 0 ? SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player)) : PALETTE_CRASH);
+							DrawShipEngine(x+35, y+10, engine_id, _player_num_engines[engine_id] > 0 ? GetEnginePalette(engine_id, _local_player) : PALETTE_CRASH);
 							SetDParam(0, _player_num_engines[engine_id]);
 							DrawStringRightAligned(213, y+15, STR_TINY_BLACK, 0);
 							y += 24;
@@ -716,7 +716,7 @@
 						if (HASBIT(e->player_avail, _local_player) && ( cargo == ShipVehInfo(engine_id)->cargo_type || refittable & ShipVehInfo(engine_id)->refittable)) {
 							if (IS_INT_INSIDE(--pos2, -w->vscroll.cap, 0)) {
 								DrawString(x2+75, y2+7, GetCustomEngineName(engine_id), sel[1]==0 ? 0xC : 0x10);
-								DrawShipEngine(x2+35, y2+10, engine_id, SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player)));
+								DrawShipEngine(x2+35, y2+10, engine_id, GetEnginePalette(engine_id, _local_player));
 								y2 += 24;
 							}
 							sel[1]--;
@@ -739,7 +739,7 @@
 						if (sel[0] == 0) selected_id[0] = engine_id;
 						if (IS_INT_INSIDE(--pos, -w->vscroll.cap, 0)) {
 							DrawString(x+62, y+7, GetCustomEngineName(engine_id), sel[0]==0 ? 0xC : 0x10);
-							DrawAircraftEngine(x+29, y+10, engine_id, _player_num_engines[engine_id] > 0 ? SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player)) : PALETTE_CRASH);
+							DrawAircraftEngine(x+29, y+10, engine_id, _player_num_engines[engine_id] > 0 ? GetEnginePalette(engine_id, _local_player) : PALETTE_CRASH);
 							SetDParam(0, _player_num_engines[engine_id]);
 							DrawStringRightAligned(213, y+15, STR_TINY_BLACK, 0);
 							y += 24;
@@ -751,7 +751,7 @@
 						if (sel[1] == 0) selected_id[1] = engine_id;
 						if (IS_INT_INSIDE(--pos2, -w->vscroll.cap, 0)) {
 							DrawString(x2+62, y2+7, GetCustomEngineName(engine_id), sel[1]==0 ? 0xC : 0x10);
-							DrawAircraftEngine(x2+29, y2+10, engine_id, SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player)));
+							DrawAircraftEngine(x2+29, y2+10, engine_id, GetEnginePalette(engine_id, _local_player));
 							y2 += 24;
 						}
 						sel[1]--;