1 /* state.h: Definitions for embodying the state of a game in progress. 2 * 3 * Copyright (C) 2001-2006 by Brian Raiter, under the GNU General Public 4 * License. No warranty. See COPYING for details. 5 */ 6 7 #ifndef _state_h_ 8 #define _state_h_ 9 10 #include "defs.h" 11 12 /* The tiles that make up Chip's universe. 13 */ 14 enum 15 { 16 Nothing = 0, 17 18 Empty = 0x01, 19 20 Slide_North = 0x02, 21 Slide_West = 0x03, 22 Slide_South = 0x04, 23 Slide_East = 0x05, 24 Slide_Random = 0x06, 25 Ice = 0x07, 26 IceWall_Northwest = 0x08, 27 IceWall_Northeast = 0x09, 28 IceWall_Southwest = 0x0A, 29 IceWall_Southeast = 0x0B, 30 Gravel = 0x0C, 31 Dirt = 0x0D, 32 Water = 0x0E, 33 Fire = 0x0F, 34 Bomb = 0x10, 35 Beartrap = 0x11, 36 Burglar = 0x12, 37 HintButton = 0x13, 38 39 Button_Blue = 0x14, 40 Button_Green = 0x15, 41 Button_Red = 0x16, 42 Button_Brown = 0x17, 43 Teleport = 0x18, 44 45 Wall = 0x19, 46 Wall_North = 0x1A, 47 Wall_West = 0x1B, 48 Wall_South = 0x1C, 49 Wall_East = 0x1D, 50 Wall_Southeast = 0x1E, 51 HiddenWall_Perm = 0x1F, 52 HiddenWall_Temp = 0x20, 53 BlueWall_Real = 0x21, 54 BlueWall_Fake = 0x22, 55 SwitchWall_Open = 0x23, 56 SwitchWall_Closed = 0x24, 57 PopupWall = 0x25, 58 59 CloneMachine = 0x26, 60 61 Door_Red = 0x27, 62 Door_Blue = 0x28, 63 Door_Yellow = 0x29, 64 Door_Green = 0x2A, 65 Socket = 0x2B, 66 Exit = 0x2C, 67 68 ICChip = 0x2D, 69 Key_Red = 0x2E, 70 Key_Blue = 0x2F, 71 Key_Yellow = 0x30, 72 Key_Green = 0x31, 73 Boots_Ice = 0x32, 74 Boots_Slide = 0x33, 75 Boots_Fire = 0x34, 76 Boots_Water = 0x35, 77 78 Block_Static = 0x36, 79 80 Drowned_Chip = 0x37, 81 Burned_Chip = 0x38, 82 Bombed_Chip = 0x39, 83 Exited_Chip = 0x3A, 84 Exit_Extra_1 = 0x3B, 85 Exit_Extra_2 = 0x3C, 86 87 Overlay_Buffer = 0x3D, 88 89 Floor_Reserved2 = 0x3E, 90 Floor_Reserved1 = 0x3F, 91 92 Chip = 0x40, 93 94 Block = 0x44, 95 96 Tank = 0x48, 97 Ball = 0x4C, 98 Glider = 0x50, 99 Fireball = 0x54, 100 Walker = 0x58, 101 Blob = 0x5C, 102 Teeth = 0x60, 103 Bug = 0x64, 104 Paramecium = 0x68, 105 106 Swimming_Chip = 0x6C, 107 Pushing_Chip = 0x70, 108 109 Entity_Reserved2 = 0x74, 110 Entity_Reserved1 = 0x78, 111 112 Water_Splash = 0x7C, 113 Bomb_Explosion = 0x7D, 114 Entity_Explosion = 0x7E, 115 Animation_Reserved1 = 0x7F 116 }; 117 118 /* Macros to assist in identifying tile taxons. 119 */ 120 #define isslide(f) ((f) >= Slide_North && (f) <= Slide_Random) 121 #define isice(f) ((f) >= Ice && (f) <= IceWall_Southeast) 122 #define isdoor(f) ((f) >= Door_Red && (f) <= Door_Green) 123 #define iskey(f) ((f) >= Key_Red && (f) <= Key_Green) 124 #define isboots(f) ((f) >= Boots_Ice && (f) <= Boots_Water) 125 #define ismsspecial(f) ((f) >= Drowned_Chip && (f) <= Overlay_Buffer) 126 #define isfloor(f) ((f) <= Floor_Reserved1) 127 #define iscreature(f) ((f) >= Chip && (f) < Water_Splash) 128 #define isanimation(f) ((f) >= Water_Splash && (f) <= Animation_Reserved1) 129 130 /* Macro for getting the tile ID of a creature with a specific direction. 131 */ 132 #define crtile(id, dir) ((id) | diridx(dir)) 133 134 /* Macros for decomposing a creature tile into ID and direction. 135 */ 136 #define creatureid(id) ((id) & ~3) 137 #define creaturedirid(id) (idxdir((id) & 3)) 138 139 /* 140 * Substructures of the game state 141 */ 142 143 /* Two x,y-coordinates give the locations of a button and what it is 144 * connected to. 145 */ 146 typedef struct xyconn { 147 short from; /* location of the button */ 148 short to; /* location of the trap/cloner */ 149 } xyconn; 150 151 /* A tile on the map. 152 */ 153 typedef struct maptile { 154 unsigned char id; /* identity of the tile */ 155 unsigned char state; /* internal state flags */ 156 } maptile; 157 158 /* A location on the map. 159 */ 160 typedef struct mapcell { 161 maptile top; /* the upper tile */ 162 maptile bot; /* the lower tile */ 163 } mapcell; 164 165 /* A creature. 166 */ 167 #if 0 168 typedef struct creature { 169 signed int pos : 11; /* creature's location */ 170 signed int dir : 5; /* current direction of creature */ 171 signed int id : 8; /* type of creature */ 172 signed int state : 8; /* internal state value */ 173 signed int hidden: 1; /* TRUE if creature is invisible */ 174 signed int moving: 5; /* positional offset of creature */ 175 signed int frame : 5; /* explicit animation index */ 176 signed int tdir : 5; /* internal state value */ 177 } creature; 178 #else 179 typedef struct creature { 180 short pos; /* creature's location */ 181 unsigned char id; /* type of creature */ 182 unsigned char dir; /* current direction of creature */ 183 signed char moving; /* positional offset of creature */ 184 signed char frame; /* explicit animation index */ 185 unsigned char hidden; /* TRUE if creature is invisible */ 186 unsigned char state; /* internal state value */ 187 unsigned char tdir; /* internal state value */ 188 } creature; 189 #endif 190 191 /* 192 * The game state structure proper. 193 */ 194 195 /* Ideally, everything that the gameplay module, the display module, 196 * and both logic modules need to know about a game in progress is 197 * in here. 198 */ 199 typedef struct gamestate { 200 gamesetup *game; /* the level specification */ 201 int ruleset; /* the ruleset for the game */ 202 int replay; /* playback move index */ 203 int timelimit; /* maximum time permitted */ 204 int currenttime; /* the current tick count */ 205 int timeoffset; /* offset for displayed time */ 206 short currentinput; /* the current keystroke */ 207 short chipsneeded; /* no. of chips still needed */ 208 short xviewpos; /* the visible part of the */ 209 short yviewpos; /* map (ie, where Chip is) */ 210 short keys[4]; /* keys collected */ 211 short boots[4]; /* boots collected */ 212 short statusflags; /* flags (see below) */ 213 short lastmove; /* most recent move */ 214 unsigned char initrndslidedir; /* initial random-slide dir */ 215 signed char stepping; /* initial timer offset 0-7 */ 216 unsigned long soundeffects; /* the latest sound effects */ 217 actlist moves; /* the list of moves */ 218 prng mainprng; /* the main PRNG */ 219 creature *creatures; /* the creature list */ 220 short trapcount; /* number of trap buttons */ 221 short clonercount; /* number of cloner buttons */ 222 short crlistcount; /* number of creatures */ 223 xyconn traps[256]; /* list of trap wirings */ 224 xyconn cloners[256]; /* list of cloner wirings */ 225 short crlist[256]; /* list of creatures */ 226 char hinttext[256]; /* text of the hint */ 227 mapcell map[CXGRID * CYGRID]; /* the game's map */ 228 unsigned char localstateinfo[256]; /* rule-specific state data */ 229 } gamestate; 230 231 /* General status flags. 232 */ 233 #define SF_NOSAVING 0x0001 /* solution won't be saved */ 234 #define SF_INVALID 0x0002 /* level is not playable */ 235 #define SF_BADTILES 0x0004 /* map has undefined tiles */ 236 #define SF_SHOWHINT 0x0008 /* display the hint text */ 237 #define SF_NOANIMATION 0x0010 /* suppress tile animation */ 238 #define SF_SHUTTERED 0x0020 /* hide map view */ 239 240 /* Macros for the keys and boots. 241 */ 242 #define redkeys(st) ((st)->keys[0]) 243 #define bluekeys(st) ((st)->keys[1]) 244 #define yellowkeys(st) ((st)->keys[2]) 245 #define greenkeys(st) ((st)->keys[3]) 246 #define iceboots(st) ((st)->boots[0]) 247 #define slideboots(st) ((st)->boots[1]) 248 #define fireboots(st) ((st)->boots[2]) 249 #define waterboots(st) ((st)->boots[3]) 250 251 #endif 252