Changeset - r5717:a4b85b33ca8b
[Not reviewed]
master
0 2 0
peter1138 - 18 years ago 2007-01-17 22:19:12
peter1138@openttd.org
(svn r8211) -Codechange: (NewGRF) Implement callback 2D, explicit vehicle colour map
selection.
2 files changed with 30 insertions and 10 deletions:
0 comments (0 inline, 0 general)
src/newgrf_callbacks.h
Show inline comments
 
@@ -45,12 +45,16 @@ enum CallbackID {
 
	 * used as a custom string ID in the 0xD000 range. */
 
	CBID_VEHICLE_ADDITIONAL_TEXT    = 0x23,
 

	
 
	/* Called when building a station to customize the tile layout */
 
	CBID_STATION_TILE_LAYOUT        = 0x24,
 

	
 
	/* Called to determine if a specific colour map should be used for a vehicle
 
	 * instead of the default livery */
 
	CBID_VEHICLE_COLOUR_MAPPING     = 0x2D,
 

	
 
	/* Called when the player (or AI) tries to start or stop a vehicle. Mainly
 
	 * used for preventing a vehicle from leaving the depot. */
 
	CBID_VEHICLE_START_STOP_CHECK   = 0x31,
 

	
 
	/* Called to play a special sound effect */
 
	CBID_VEHICLE_SOUND_EFFECT       = 0x33,
src/vehicle.cpp
Show inline comments
 
@@ -30,12 +30,13 @@
 
#include "industry_map.h"
 
#include "station_map.h"
 
#include "water_map.h"
 
#include "network/network.h"
 
#include "yapf/yapf.h"
 
#include "date.h"
 
#include "newgrf_callbacks.h"
 
#include "newgrf_engine.h"
 
#include "newgrf_sound.h"
 
#include "helpers.hpp"
 

	
 
#define INVALID_COORD (-0x8000)
 
#define GEN_HASH(x, y) ((GB((y), 6, 6) << 6) + GB((x), 7, 6))
 
@@ -2810,17 +2811,31 @@ UnitID GetFreeUnitNumber(byte type)
 
		if (!cache[unit]) break;
 
	}
 

	
 
	return unit;
 
}
 

	
 
static SpriteID GetEngineColourMap(EngineID engine_type, PlayerID player, EngineID parent_engine_type, CargoID cargo_type)
 
static SpriteID GetEngineColourMap(EngineID engine_type, PlayerID player, EngineID parent_engine_type, const Vehicle *v)
 
{
 
	SpriteID map;
 
	SpriteID map = PAL_NONE;
 
	const Player *p = GetPlayer(player);
 
	LiveryScheme scheme = LS_DEFAULT;
 
	CargoID cargo_type = v == NULL ? (CargoID)CT_INVALID : v->cargo_type;
 

	
 
	/* Check if we should use the colour map callback */
 
	if (HASBIT(EngInfo(engine_type)->callbackmask, CBM_COLOUR_REMAP)) {
 
		uint16 callback = GetVehicleCallback(CBID_VEHICLE_COLOUR_MAPPING, 0, 0, engine_type, v);
 
		/* A return value of 0xC000 is stated to "use the default two-color
 
		 * maps" which happens to be the failure action too... */
 
		if (callback != CALLBACK_FAILED && callback != 0xC000) {
 
			map = GB(callback, 0, 14);
 
			/* If bit 14 is set, then the company colours are applied to the
 
			 * map else it's returned as-is. */
 
			if (!HASBIT(callback, 14)) return map;
 
		}
 
	}
 

	
 
	/* The default livery is always available for use, but its in_use flag determines
 
	 * whether any _other_ liveries are in use. */
 
	if (p->livery[LS_DEFAULT].in_use && (_patches.liveries == 2 || (_patches.liveries == 1 && player == _local_player))) {
 
		/* Determine the livery scheme to use */
 
		switch (GetEngine(engine_type)->type) {
 
@@ -2891,36 +2906,37 @@ static SpriteID GetEngineColourMap(Engin
 
		}
 

	
 
		/* Switch back to the default scheme if the resolved scheme is not in use */
 
		if (!p->livery[scheme].in_use) scheme = LS_DEFAULT;
 
	}
 

	
 
	map = HASBIT(EngInfo(engine_type)->misc_flags, EF_USES_2CC) ?
 
		(SPR_2CCMAP_BASE + p->livery[scheme].colour1 + p->livery[scheme].colour2 * 16) :
 
		(PALETTE_RECOLOR_START + p->livery[scheme].colour1);
 
	bool twocc = HASBIT(EngInfo(engine_type)->misc_flags, EF_USES_2CC);
 

	
 
	if (map == PAL_NONE) map = twocc ? (SpriteID)SPR_2CCMAP_BASE : (SpriteID)PALETTE_RECOLOR_START;
 

	
 
	map += p->livery[scheme].colour1;
 
	if (twocc) map += p->livery[scheme].colour2 * 16;
 

	
 
	return map;
 
}
 

	
 
SpriteID GetEnginePalette(EngineID engine_type, PlayerID player)
 
{
 
	return GetEngineColourMap(engine_type, player, INVALID_ENGINE, CT_INVALID);
 
	return GetEngineColourMap(engine_type, player, INVALID_ENGINE, NULL);
 
}
 

	
 
SpriteID GetVehiclePalette(const Vehicle *v)
 
{
 
	if (v->type == VEH_Train) {
 
		return GetEngineColourMap(
 
			(v->u.rail.first_engine != INVALID_ENGINE && (IsArticulatedPart(v) || UsesWagonOverride(v))) ?
 
				v->u.rail.first_engine : v->engine_type,
 
			v->owner,
 
			v->u.rail.first_engine,
 
			v->cargo_type);
 
			v->owner, v->u.rail.first_engine, v);
 
	}
 

	
 
	return GetEngineColourMap(v->engine_type, v->owner, INVALID_ENGINE, v->cargo_type);
 
	return GetEngineColourMap(v->engine_type, v->owner, INVALID_ENGINE, v);
 
}
 

	
 
// Save and load of vehicles
 
extern const SaveLoad _common_veh_desc[] = {
 
	    SLE_VAR(Vehicle, subtype,              SLE_UINT8),
 

	
0 comments (0 inline, 0 general)