table/sprites.h
changeset 2187 2a51f8925eeb
parent 2186 461a2aff3486
child 2218 abd47ef7d902
equal deleted inserted replaced
2186:461a2aff3486 2187:2a51f8925eeb
     1 /* $Id$ */
     1 /* $Id$ */
     2 
     2 
     3 #ifndef SPRITES_H
     3 #ifndef SPRITES_H
     4 #define SPRITES_H
     4 #define SPRITES_H
     5 
     5 
     6 /* NOTE:
     6 /** @file sprites.h
       
     7 	This file contails all sprite-related enums and defines. These consist mainly of
       
     8   the sprite numbers and a bunch of masks and macros to handle sprites and to get
       
     9   rid of all the magic numbers in the code.
       
    10 
       
    11 @NOTE:
     7 	ALL SPRITE NUMBERS BELOW 5126 are in the main files
    12 	ALL SPRITE NUMBERS BELOW 5126 are in the main files
     8 	SPR_CANALS_BASE is in canalsw.grf
    13 	SPR_CANALS_BASE is in canalsw.grf
     9 	SPR_SLOPES_BASE is in trkfoundw.grf
    14 	SPR_SLOPES_BASE is in trkfoundw.grf
    10 	SPR_OPENTTD_BASE is in openttd.grf
    15 	SPR_OPENTTD_BASE is in openttd.grf
    11 */
    16 
    12 
       
    13 /*
       
    14 	All elements which consist of two elements should
    17 	All elements which consist of two elements should
    15 	have the same name and then suffixes
    18 	have the same name and then suffixes
    16 		_GROUND and _BUILD for building-type sprites
    19 		_GROUND and _BUILD for building-type sprites
    17 		_REAR and _FRONT for transport-type sprites (tiles where vehicles are on)
    20 		_REAR and _FRONT for transport-type sprites (tiles where vehicles are on)
    18 	These sprites are split because of the Z order of the elements
    21 	These sprites are split because of the Z order of the elements
    19 		(like some parts of a bridge are behind the vehicle, while others are before)
    22 		(like some parts of a bridge are behind the vehicle, while others are before)
    20 */
    23 
    21 
    24 
    22 /*
       
    23 	All sprites which are described here are referenced only one to a handful of times
    25 	All sprites which are described here are referenced only one to a handful of times
    24 	throughout the code. When introducing new sprite enums, use meaningful names.
    26 	throughout the code. When introducing new sprite enums, use meaningful names.
    25 	Don't be lazy and typing, and only use abbrevations when their meaning is clear or
    27 	Don't be lazy and typing, and only use abbrevations when their meaning is clear or
    26 	the length of the enum would get out of hand. In that case EXPLAIN THE ABBREVATION
    28 	the length of the enum would get out of hand. In that case EXPLAIN THE ABBREVATION
    27 	IN THIS FILE, and perhaps add some comments in the code where it is used.
    29 	IN THIS FILE, and perhaps add some comments in the code where it is used.
    28 	Now, don't whine about this being too much typing work if the enums are like
    30 	Now, don't whine about this being too much typing work if the enums are like
    29 	30 characters in length. If your editor doen't help you simplifying your work,
    31 	30 characters in length. If your editor doen't help you simplifying your work,
    30 	get a proper editor. If your Operating Systems don't have any decent editors,
    32 	get a proper editor. If your Operating Systems don't have any decent editors,
    31 	get a proper Operating System.
    33 	get a proper Operating System.
       
    34 
       
    35 	@todo Split the "Sprites" enum into smaller chunks and document them
    32 */
    36 */
    33 
    37 
    34 
    38 
    35 enum Sprites {
    39 enum Sprites {
    36 	SPR_SELECT_TILE	 = 752,
    40 	SPR_SELECT_TILE	 = 752,
   867 	SPR_IMG_BRIDGE				= 2594,
   871 	SPR_IMG_BRIDGE				= 2594,
   868 	SPR_IMG_ROAD_TUNNEL		= 2429,
   872 	SPR_IMG_ROAD_TUNNEL		= 2429,
   869 	SPR_IMG_REMOVE				= 714
   873 	SPR_IMG_REMOVE				= 714
   870 };
   874 };
   871 
   875 
   872 /* Cursor sprite numbers */
   876 /** Cursor sprite numbers */
   873 typedef enum CursorSprites {
   877 typedef enum CursorSprites {
   874 	/* Terraform */
   878 	/* Terraform */
   875 	/* Cursors */
   879 	/* Cursors */
   876 	SPR_CURSOR_MOUSE          = 0,
   880 	SPR_CURSOR_MOUSE          = 0,
   877 	SPR_CURSOR_ZZZ            = 1,
   881 	SPR_CURSOR_ZZZ            = 1,
   938 	SPR_CURSOR_BUS_STATION    = 2725,
   942 	SPR_CURSOR_BUS_STATION    = 2725,
   939 	SPR_CURSOR_TRUCK_STATION  = 2726,
   943 	SPR_CURSOR_TRUCK_STATION  = 2726,
   940 	SPR_CURSOR_ROAD_TUNNEL    = 2433,
   944 	SPR_CURSOR_ROAD_TUNNEL    = 2433,
   941 } CursorSprite;
   945 } CursorSprite;
   942 
   946 
   943 // Animation macro in table/animcursors.h (_animcursors[])
   947 /// Animation macro in table/animcursors.h (_animcursors[])
   944 enum AnimCursors {
   948 enum AnimCursors {
   945 	ANIMCURSOR_DEMOLISH     = -1,	//  704 -  707 - demolish dynamite
   949 	ANIMCURSOR_DEMOLISH     = -1,	///<  704 -  707 - demolish dynamite
   946 	ANIMCURSOR_LOWERLAND    = -2,	//  699 -  701 - lower land tool
   950 	ANIMCURSOR_LOWERLAND    = -2,	///<  699 -  701 - lower land tool
   947 	ANIMCURSOR_RAISELAND    = -3,	//  696 -  698 - raise land tool
   951 	ANIMCURSOR_RAISELAND    = -3,	///<  696 -  698 - raise land tool
   948 	ANIMCURSOR_PICKSTATION  = -4,	//  716 -  718 - goto-order icon
   952 	ANIMCURSOR_PICKSTATION  = -4,	///<  716 -  718 - goto-order icon
   949 	ANIMCURSOR_BUILDSIGNALS	= -5,	// 1292 - 1293 - build signal
   953 	ANIMCURSOR_BUILDSIGNALS	= -5,	///< 1292 - 1293 - build signal
   950 };
   954 };
   951 
   955 
   952 enum {
   956 /**
   953 	MAX_SPRITES = 0x3FFF, //the highest number a sprite can have
   957   * Bitmask setup. For the graphics system, 32 bits are used to define
       
   958   * the sprite to be displayed. This variable contains various information:<p>
       
   959 	* <ul><li> SPRITE_WIDTH is the number of bits used for the actual sprite to be displayed.
       
   960   * This always starts at bit 0.</li>
       
   961   * <li> TRANSPARENT_BIT is the bit number which toggles sprite transparency</li>
       
   962   * <li> RECOLOR_BIT toggles the recoloring system</li>
       
   963   * <li> PALETTE_SPRITE_WIDTH and PALETTE_SPRITE_START determine the position and number of
       
   964   * bits used for the recoloring process. For transparency, it must be 0x322.</li>
       
   965   */
       
   966 enum SpriteSetup {
       
   967 	TRANSPARENT_BIT = 31,       ///< toggles transparency in the sprite
       
   968 	RECOLOR_BIT = 15,           ///< toggles recoloring in the sprite
       
   969 	PALETTE_SPRITE_START = 16,  ///< number of the first bit of the sprite containing the recolor palette
       
   970 	PALETTE_SPRITE_WIDTH = 11,  ///< number of bits of the sprite containing the recolor palette
       
   971 	SPRITE_WIDTH = 14,          ///< number of bits for the sprite number
   954 };
   972 };
   955 
   973 
   956 /*
   974 /**
   957 	these numbers change the colors of the palette for a sprite
   975 	these masks change the colors of the palette for a sprite.
   958 	both need to be fed a sprite which contains the "new" colors
   976 	Apart from this bit, a sprite number is needed to define
       
   977   the palette used for recoloring. This palette is stored
       
   978 	in the bits marked by PALETTE_SPRITE_MASK.
       
   979   @note Do not modify this enum. Alter SpriteSetup instead
       
   980   @see SpriteSetup
   959 */
   981 */
   960 enum Modifiers {
   982 enum Modifiers {
   961 	PALETTE_MODIFIER_TRANSPARENT 	= 0x4000,
   983 	///when a sprite is to be displayed transparently, this bit needs to be set.
   962 	PALETTE_MODIFIER_COLOR 				= 0x8000,
   984 	PALETTE_MODIFIER_TRANSPARENT 	= 1 << TRANSPARENT_BIT,
       
   985 	///this bit is set when a recoloring process is in action
       
   986 	PALETTE_MODIFIER_COLOR 				= 1 << RECOLOR_BIT,
   963 };
   987 };
   964 
   988 
       
   989 /** Masks needed for sprite operations.
       
   990   * @note Do not modify this enum. Alter SpriteSetup instead
       
   991   * @see SpriteSetup
       
   992   */
       
   993 enum SpriteMasks {
       
   994 	///Maximum number of sprites that can be loaded at a given time.
       
   995 	MAX_SPRITES = (1 << SPRITE_WIDTH) - 1,
       
   996 	///The mask to for the main sprite
       
   997 	SPRITE_MASK = MAX_SPRITES,
       
   998 	///The mask for the auxiliary sprite (the one that takes care of recoloring)
       
   999 	PALETTE_SPRITE_MASK = ((1 << PALETTE_SPRITE_WIDTH) - 1) << PALETTE_SPRITE_START,
       
  1000 };
       
  1001 
       
  1002 assert_compile( (1 << TRANSPARENT_BIT & SPRITE_MASK) == 0 );
       
  1003 assert_compile( (1 << RECOLOR_BIT & SPRITE_MASK) == 0 );
       
  1004 assert_compile( TRANSPARENT_BIT != RECOLOR_BIT );
       
  1005 assert_compile( (1 << TRANSPARENT_BIT & PALETTE_SPRITE_MASK) == 0);
       
  1006 assert_compile( (1 << RECOLOR_BIT & PALETTE_SPRITE_MASK) == 0 );
       
  1007 assert_compile( (PALETTE_SPRITE_MASK & SPRITE_MASK) == 0 );
       
  1008 assert_compile( SPRITE_WIDTH + PALETTE_SPRITE_WIDTH <= 30 );
       
  1009 
       
  1010 #define PALETTE_RECOLOR_SPRITE(a) (a << PALETTE_SPRITE_START | PALETTE_MODIFIER_COLOR)
   965 enum PaletteSprites {
  1011 enum PaletteSprites {
   966 	//note: these numbers are already the modified once the renderer needs.
  1012 	//note: these numbers are already the modified once the renderer needs.
   967 	//the actual sprite number is the upper 16 bits of the number
  1013 	//the actual sprite number is the upper 16 bits of the number
   968 
  1014 
   969 	//Here a puslating red tile is drawn if you try to build a wrong tunnel or raise/lower land where it is not possible
  1015 	///Here a puslating red tile is drawn if you try to build a wrong tunnel or raise/lower land where it is not possible
   970 	PALETTE_TILE_RED_PULSATING 	= 0x3038000,
  1016 	PALETTE_TILE_RED_PULSATING 	= PALETTE_RECOLOR_SPRITE(0x303),
   971 	//makes a square red. is used when removing rails or other stuff
  1017 	///makes a square red. is used when removing rails or other stuff
   972 	PALETTE_SEL_TILE_RED 				= 0x3048000,
  1018 	PALETTE_SEL_TILE_RED 				= PALETTE_RECOLOR_SPRITE(0x304),
   973 	//This draws a blueish square (catchment areas for example)
  1019 	///This draws a blueish square (catchment areas for example)
   974 	PALETTE_SEL_TILE_BLUE 			= 0x3058000,
  1020 	PALETTE_SEL_TILE_BLUE 			= PALETTE_RECOLOR_SPRITE(0x305),
   975 	//0x306 is a real sprite (the little dot you get when you try to raise/lower a corner of the map
  1021 	//0x306 is a real sprite (the little dot you get when you try to raise/lower a corner of the map
   976 	//here the color switches begin
  1022 	//here the color switches begin
   977 	//use this if you add stuff to the value, so that the resulting color
  1023 	//use this if you add stuff to the value, so that the resulting color
   978 	//is not a fixed value.
  1024 	//is not a fixed value.
   979 	//NOTE THAT THE SWITCH 0x8000 is NOT present in _TO_COLORS yet!
  1025 	//NOTE THAT THE SWITCH 0x8000 is NOT present in _TO_COLORS yet!
   980 	PALETTE_TO_COLORS 					= 0x3070000,
  1026 	PALETTE_TO_COLORS 					= 0x307 << PALETTE_SPRITE_START,
   981 	PALETTE_TO_DARK_BLUE 				= 0x3078000,
  1027 	PALETTE_TO_DARK_BLUE 				= PALETTE_RECOLOR_SPRITE(0x307),
   982 	PALETTE_TO_PALE_GREEN 			= 0x3088000,
  1028 	PALETTE_TO_PALE_GREEN 			= PALETTE_RECOLOR_SPRITE(0x308),
   983 	PALETTE_TO_PINK 						= 0x3098000,
  1029 	PALETTE_TO_PINK 						= PALETTE_RECOLOR_SPRITE(0x309),
   984 	PALETTE_TO_YELLOW 					= 0x30A8000,
  1030 	PALETTE_TO_YELLOW 					= PALETTE_RECOLOR_SPRITE(0x30A),
   985 	PALETTE_TO_RED 							= 0x30B8000,
  1031 	PALETTE_TO_RED 							= PALETTE_RECOLOR_SPRITE(0x30B),
   986 	PALETTE_TO_LIGHT_BLUE 			= 0x30C8000,
  1032 	PALETTE_TO_LIGHT_BLUE 			= PALETTE_RECOLOR_SPRITE(0x30C),
   987 	PALETTE_TO_GREEN 						= 0x30D8000,
  1033 	PALETTE_TO_GREEN 						= PALETTE_RECOLOR_SPRITE(0x30D),
   988 	PALETTE_TO_DARK_GREEN 			= 0x30E8000,
  1034 	PALETTE_TO_DARK_GREEN 			= PALETTE_RECOLOR_SPRITE(0x30E),
   989 	PALETTE_TO_BLUE 						= 0x30F8000,
  1035 	PALETTE_TO_BLUE 						= PALETTE_RECOLOR_SPRITE(0x30F),
   990 	PALETTE_TO_CREAM 						= 0x3108000,
  1036 	PALETTE_TO_CREAM 						= PALETTE_RECOLOR_SPRITE(0x310),
   991 	//maybe don't use as player color because it doesn't display in the graphs?
  1037 	//maybe don't use as player color because it doesn't display in the graphs?
   992 	PALETTE_TO_MAUVE 						= 0x3118000,
  1038 	PALETTE_TO_MAUVE 						= PALETTE_RECOLOR_SPRITE(0x311),
   993 	PALETTE_TO_PURPLE 					= 0x3128000,
  1039 	PALETTE_TO_PURPLE 					= PALETTE_RECOLOR_SPRITE(0x312),
   994 	PALETTE_TO_ORANGE 					= 0x3138000,
  1040 	PALETTE_TO_ORANGE 					= PALETTE_RECOLOR_SPRITE(0x313),
   995 	PALETTE_TO_BROWN 						= 0x3148000,
  1041 	PALETTE_TO_BROWN 						= PALETTE_RECOLOR_SPRITE(0x314),
   996 	PALETTE_TO_GREY 						= 0x3158000,
  1042 	PALETTE_TO_GREY 						= PALETTE_RECOLOR_SPRITE(0x315),
   997 	PALETTE_TO_WHITE 						= 0x3168000,
  1043 	PALETTE_TO_WHITE 						= PALETTE_RECOLOR_SPRITE(0x316),
   998  	//sets color to bare land stuff, for rail and road (and crossings)
  1044  	//sets color to bare land stuff, for rail and road (and crossings)
   999 	PALETTE_TO_BARE_LAND 				= 0x3178000,
  1045 	PALETTE_TO_BARE_LAND 				= PALETTE_RECOLOR_SPRITE(0x317),
  1000 	//XXX is 318-31A really not used?
  1046 	//XXX is 318-31A really not used?
  1001 	//XXX FIXME I dunno yet what this is
  1047 	//XXX FIXME I dunno yet what this is
  1002 	PALETTE_31B 								= 0x31B8000,
  1048 	PALETTE_31B 								= PALETTE_RECOLOR_SPRITE(0x31B),
  1003 	//structure color to something brownish (for the cantilever bridges for example)
  1049 	//structure color to something brownish (for the cantilever bridges for example)
  1004 	PALETTE_TO_STRUCT_BROWN 		= 0x31C8000,
  1050 	PALETTE_TO_STRUCT_BROWN 		= PALETTE_RECOLOR_SPRITE(0x31C),
  1005 	PALETTE_31D 								= 0x31D8000, //XXX FIXME Don't know this either
  1051 	PALETTE_31D 								= PALETTE_RECOLOR_SPRITE(0x31D), //XXX FIXME Don't know this either
  1006 	//sets bridge or structure to red, little concrete one and cantilever use this one for example
  1052 	//sets bridge or structure to red, little concrete one and cantilever use this one for example
  1007 	PALETTE_TO_STRUCT_RED 			= 0x31E8000,
  1053 	PALETTE_TO_STRUCT_RED 			= PALETTE_RECOLOR_SPRITE(0x31E),
  1008 	//XXX 31F
  1054 	//XXX 31F
  1009 	PALETTE_TO_STRUCT_CONCRETE 	= 0x3208000,  //Sets the suspension bridge to concrete, also other strucutures use it
  1055 	PALETTE_TO_STRUCT_CONCRETE 	= PALETTE_RECOLOR_SPRITE(0x320),  //Sets the suspension bridge to concrete, also other strucutures use it
  1010 	PALETTE_TO_STRUCT_YELLOW 		= 0x3218000,    //Sets the bridge color to yellow (suspension and tubular)
  1056 	PALETTE_TO_STRUCT_YELLOW 		= PALETTE_RECOLOR_SPRITE(0x321),    //Sets the bridge color to yellow (suspension and tubular)
  1011 	PALETTE_TO_TRANSPARENT 			= 0x3224000,	//This sets the sprite to transparent
  1057 	PALETTE_TO_TRANSPARENT 			= 0x322 << PALETTE_SPRITE_START | PALETTE_MODIFIER_TRANSPARENT,	//This sets the sprite to transparent
  1012 	//This is used for changing the tubular bridges to the silicon display, or some grayish color
  1058 	//This is used for changing the tubular bridges to the silicon display, or some grayish color
  1013 	PALETTE_TO_STRUCT_GREY 			= 0x3238000,
  1059 	PALETTE_TO_STRUCT_GREY 			= PALETTE_RECOLOR_SPRITE(0x323),
  1014 	PALETTE_CRASH 							= 0x3248000,	//this changes stuff to the "crash color"
  1060 	PALETTE_CRASH 							= PALETTE_RECOLOR_SPRITE(0x324),	//this changes stuff to the "crash color"
  1015 	//XXX another place where structures are colored.
  1061 	//XXX another place where structures are colored.
  1016 	//I'm not sure which colors these are
  1062 	//I'm not sure which colors these are
  1017 	PALETTE_59E 								= 0x59E8000,
  1063 	PALETTE_59E 								= PALETTE_RECOLOR_SPRITE(0x59E),
  1018 	PALETTE_59F 								= 0x59F8000,
  1064 	PALETTE_59F 								= PALETTE_RECOLOR_SPRITE(0x59F),
  1019 
       
  1020 };
  1065 };
  1021 
  1066 #undef PALETTE_RECOLOR_SPRITE
  1022 #define MAKE_TRANSPARENT(img) (img = (img & MAX_SPRITES) | PALETTE_TO_TRANSPARENT)
  1067 
       
  1068 #define MAKE_TRANSPARENT(img) (img = (img & SPRITE_MASK) | PALETTE_TO_TRANSPARENT)
  1023 
  1069 
  1024 #endif /* SPRITES_H */
  1070 #endif /* SPRITES_H */