1 /* Copyright (C) 1993, 1992 Nathan Sidwell */ 2 /* RCS $Id: common.h,v 4.29 1995/12/14 13:53:27 nathan Exp $ */ 3 /* common header stuff for xmris and xmred 4 * included from xmris.h or xmred.h 5 */ 6 #include "patchlevel.h" 7 #ifndef EXTERN 8 #define EXTERN extern 9 #endif /* EXTERN */ 10 /*{{{ include*/ 11 #include <stddef.h> 12 #include <stdlib.h> 13 #include <stdio.h> 14 #include <assert.h> 15 #include <string.h> 16 #include <errno.h> 17 #include <ctype.h> 18 #include <time.h> 19 #ifndef TRANSPUTER 20 #include <unistd.h> 21 #endif /* TRANSPUTER */ 22 #include <X11/Xlib.h> 23 #include <X11/Xutil.h> 24 #include <X11/keysym.h> 25 #include <X11/Intrinsic.h> 26 /*}}}*/ 27 #include "ansiknr.h" 28 /*{{{ case changing things*/ 29 #ifdef _tolower 30 #define lowercase(a) _tolower(a) 31 #define uppercase(a) _toupper(a) 32 #else 33 #define lowercase(a) tolower(a) 34 #define uppercase(a) toupper(a) 35 #endif /* _tolower */ 36 /*}}}*/ 37 /*{{{ check font*/ 38 #ifndef FONT_NAME 39 #error No default font 40 #endif /* FONT_NAME */ 41 /*}}}*/ 42 /*{{{ defines*/ 43 /*{{{ board sizes*/ 44 #define CELLS_ACROSS 12 /* size of the board */ 45 #define CELLS_DOWN 13 46 #define CELL_WIDTH 32 /* size of the internal cell */ 47 #define CELL_HEIGHT 32 /* monster sprites must be this size */ 48 #define GAP_WIDTH 4 /* spacing of the cells */ 49 #define GAP_HEIGHT 4 50 #define DEN_WIDTH 1 /* extra space round den */ 51 #define DEN_HEIGHT 1 52 #define CELL_STRIDE 16 /* board array is bigger than the board */ 53 #define CELL_TOP 2 /* and the board is offset by this much */ 54 #define CELL_LEFT 2 55 #define BORDER_TOP CELL_HEIGHT /* placing of the board */ 56 #ifndef XMRED 57 #define BORDER_BOTTOM (CELL_HEIGHT + 1) /* on the window */ 58 #else 59 #define BORDER_BOTTOM (-1) 60 #endif 61 #define BORDER_LEFT (-1) 62 #define BORDER_RIGHT (-1) 63 #define BOARD_WIDTH ((CELL_WIDTH + GAP_WIDTH) * CELLS_ACROSS + GAP_WIDTH) 64 #define BOARD_HEIGHT ((CELL_HEIGHT + GAP_HEIGHT) * CELLS_DOWN + GAP_HEIGHT) 65 #define WINDOW_WIDTH (BOARD_WIDTH + BORDER_LEFT + BORDER_RIGHT) 66 #define WINDOW_HEIGHT (BOARD_HEIGHT + BORDER_TOP + BORDER_BOTTOM) 67 #define XTRA_SPACING ((CELL_WIDTH * 3 + GAP_WIDTH * 3) / 4) 68 #define CENTER_X (BORDER_LEFT + BOARD_WIDTH / 2) 69 #define CENTER_Y (BORDER_TOP + BOARD_HEIGHT / 2) 70 /*}}}*/ 71 /*{{{ some defaults*/ 72 #define DEFAULT_PLAYER_X ((CELLS_ACROSS - 1) >> 1) 73 #define DEFAULT_PLAYER_Y (CELLS_DOWN - 1) 74 #define DEFAULT_DEN_X ((CELLS_ACROSS - 1) >> 1) 75 #define DEFAULT_DEN_Y (CELLS_DOWN >> 1) 76 #define DEFAULT_APPLES 6 77 /*}}}*/ 78 /*{{{ garden characters*/ 79 #define GARDEN_PATH 'A' 80 #define GARDEN_APPLE 'a' 81 #define GARDEN_RANDOM '.' 82 #define GARDEN_CHERRY '@' 83 #define GARDEN_NOAPPLE '+' 84 #define GARDEN_PATH_BLANK 0x0 85 #define GARDEN_PATH_CHERRY 0x4 86 #define GARDEN_PATH_DEN 0x8 87 #define GARDEN_PATH_PLAYER 0xc 88 /*}}}*/ 89 /*{{{ default game gender*/ 90 #define GAME_GENDER False 91 /*}}}*/ 92 /*{{{ limits*/ 93 #define BOARD_LIMIT 64 /* maximum number of boards */ 94 #define APPLE_LIMIT 12 /* maximum number of initial apples */ 95 /*}}}*/ 96 #ifndef XMRED 97 /*{{{ key indices*/ 98 #define KEY_THROW 4 99 #define KEY_PAUSE 5 100 #define KEY_QUIT 6 101 #define KEY_ICONIZE 7 102 #define KEY_KEYBOARD 8 103 #define KEYS 9 104 /*}}}*/ 105 #endif /* XMRED */ 106 /*{{{ sprite numbers*/ 107 #define SPRITE_CENTER_BASE 0 108 #define SPRITE_EDGE_BASE 2 109 #ifndef XMRED 110 #define SPRITE_DIGITS 4 111 #else 112 #define SPRITE_PATH 4 113 #endif /* XMRED */ 114 #define SPRITE_DEN 5 115 #ifndef XMRED 116 #define SPRITE_BALL 6 117 #define SPRITE_CHERRY 7 118 #define SPRITE_APPLE 8 119 #define SPRITE_GHOST 14 120 #define SPRITE_DIAMOND 17 121 #define SPRITE_EXTRA 20 122 #define SPRITE_XTRA_SOURCE 22 123 #define SPRITE_MONSTERS 24 124 #define SPRITE_NORMAL 24 125 #define SPRITE_MUNCHER 36 126 #define SPRITE_XTRA 48 127 #define SPRITE_DRONE 60 128 #define SPRITE_PLAYER 72 129 #define SPRITE_PLAYER_PUSH 84 130 #define SPRITE_PLAYER_REST 88 131 #define SPRITE_PLAYER_HAPPY 92 132 #define SPRITE_PLAYER_DEAD 94 133 #define SPRITE_SQUISHED 110 134 #define SPRITE_CHOMP 120 135 #define SPRITE_MRIS 122 136 #define SPRITE_SEAT 130 137 #define SPRITE_GHOSTING 131 138 #define SPRITE_PRIZE_BASE 132 139 #define SPRITES 137 140 #define SPRITE_PRIZES 5 141 #define SPRITE_MUSHROOM 3 142 #else 143 #define SPRITE_CHERRY 6 144 #define SPRITE_BIG_APPLE 7 145 #define SPRITE_BIG_ARROW 9 146 #define SPRITE_SMALL_APPLE 11 147 #define SPRITE_SMALL_ARROW 13 148 #define SPRITE_EXTRA 15 149 #define SPRITE_PLAYER 16 150 #define SPRITE_COLORS 17 151 #define SPRITE_APPLES 20 152 #define SPRITE_APPLE_DROP 25 153 #define SPRITE_INCLUDE 26 154 #define SPRITE_ICON_I 27 155 #define SPRITE_BOARD_I 28 156 #define SPRITE_WARNING 29 157 #define SPRITES 31 158 #endif /* XMRED */ 159 /*}}}*/ 160 /*{{{ color numbers*/ 161 #define COLOR_WHITE 0 162 #define COLOR_BLACK 1 163 #define COLOR_BACKGROUNDS 2 164 #define COLOR_GREEN_BACK 2 165 #define COLOR_GREEN_FORE 3 166 #define COLOR_RED_BACK 4 167 #define COLOR_RED_FORE 5 168 #define COLOR_BLUE_BACK 6 169 #define COLOR_BLUE_FORE 7 170 #define COLOR_BACKGROUND 8 171 #define COLOR_FOREGROUND 9 172 #define COLOR_BORDER 10 173 #define COLOR_CHERRY 11 174 #define COLOR_CHERRY_STALK 12 175 #define COLOR_APPLE_1 13 176 #define COLOR_APPLE_2 14 177 #define COLOR_APPLE_FAINT 15 178 #define COLOR_PLAYER 16 179 #define COLOR_PLAYER_BOBBLE 17 180 #define COLOR_PLAYER_FACE 18 181 #define COLOR_PLAYER_BOOT 19 182 #define COLOR_NORMAL 20 183 #define COLOR_LETTER_GOT 21 184 #ifndef XMRED 185 #define COLOR_LETTER_NOT_GOT 22 186 #define COLOR_BALL 23 187 #define COLOR_DRONE_BACK 24 188 #define COLOR_DRONE_FORE 25 189 #define COLOR_GEM_1 26 190 #define COLOR_GEM_2 27 191 #define COLOR_MUNCH_1 28 192 #define COLOR_MUNCH_2 29 193 #define COLOR_DRONE 30 194 #define COLOR_DRONE_TONGUE 31 195 #define COLOR_XTRA 32 196 #define COLOR_CHOMP 33 197 #define COLOR_CHOMP_LIP 34 198 #define COLOR_CHOMP_TONGUE 35 199 #define COLOR_SEAT 36 200 #define COLOR_CAKE 37 201 #define COLOR_CAKE_ICING 38 202 #define COLOR_CAKE_JAM 39 203 #define COLOR_SPANNER 40 204 #define COLOR_SPANNER_SHADOW 41 205 #define COLOR_BROLLY_1 42 206 #define COLOR_BROLLY_2 43 207 #define COLOR_BROLLY_HANDLE 44 208 #define COLOR_MUSHROOM_STALK 45 209 #define COLOR_MUSHROOM_CAP 46 210 #define COLOR_CLOCK_FACE 47 211 #define COLOR_CLOCK_BELL 48 212 #define COLOR_CLOCK_EDGE 49 213 #define COLOR_DYNAMIC 50 214 #define COLORS 52 215 #else 216 #define COLORS 22 217 #endif /* XMRED */ 218 /*}}}*/ 219 /*{{{ random sizes*/ 220 #define EDGE_WIDTH (CELL_WIDTH + GAP_WIDTH * 2) 221 #define EDGE_HEIGHT (CELL_HEIGHT + GAP_HEIGHT * 2) 222 #define INTERNAL_WIDTH 4 /* size of internal corner */ 223 #define INTERNAL_HEIGHT 4 224 #define EXTERNAL_WIDTH 4 /* size of external corner */ 225 #define EXTERNAL_HEIGHT 4 226 #define XTRA_LETTER_X 8 /* position of lettering on xtra */ 227 #define XTRA_LETTER_Y 10 228 #ifndef XMRED 229 #define DIGIT_HEIGHT (CELL_HEIGHT / 2) 230 #define DIGIT_WIDTH (CELL_WIDTH / 4) 231 #define BALL_WIDTH 7 /* size of ball */ 232 #define BALL_HEIGHT 7 233 #define GHOSTING_WIDTH 40 234 #define GHOSTING_HEIGHT 40 235 #else 236 #define WARNING_WIDTH 12 237 #define WARNING_HEIGHT 24 238 #endif /* XMRED */ 239 /*}}}*/ 240 /*{{{ colour flags*/ 241 #define COLOUR_ZERO 0 /* colour is all zeros */ 242 #define COLOUR_ONE 1 /* colour is all ones */ 243 #define COLOUR_WEIRD 2 /* colour is neither zeros or ones */ 244 /*}}}*/ 245 #define BACKGROUNDS 3 246 #define FILLS 4 247 #ifndef XMRED 248 #define BACKGROUND_WHIZZ -1 249 #define BACKGROUND_NORMAL -2 250 #define BACKGROUND_DRONES BACKGROUNDS 251 #endif /* XMRED */ 252 /*}}}*/ 253 /*{{{ macros*/ 254 #define PIXELX(CX, OX) \ 255 ((CX) * (CELL_WIDTH + GAP_WIDTH) + (OX) + (GAP_WIDTH + BORDER_LEFT)) 256 #define PIXELY(CY, OY) \ 257 ((CY) * (CELL_HEIGHT + GAP_HEIGHT) + (OY) + (GAP_HEIGHT + BORDER_TOP)) 258 /* 259 * The range macro does one test, rather than (straight foward) two, 260 * provided l and u are compile time constants, we win. I suppose 261 * a decent optimizer may even know about this trick, but gcc doesn't, 262 * and that's usually a good indicator of what happens. 263 */ 264 #define INRANGE(x, l, u) \ 265 ((unsigned)(x) - (unsigned)(l) < (unsigned)(u) - (unsigned)(l)) 266 #define ISPATH(c) INRANGE(c, GARDEN_PATH, GARDEN_PATH + 16) 267 #define ISPATHBLANK(c) INRANGE(c, GARDEN_PATH + GARDEN_PATH_BLANK, \ 268 GARDEN_PATH + GARDEN_PATH_BLANK + 4) 269 #define ISPATHCHERRY(c) INRANGE(c, GARDEN_PATH + GARDEN_PATH_CHERRY, \ 270 GARDEN_PATH + GARDEN_PATH_CHERRY + 4) 271 #define ISPATHDEN(c) INRANGE(c, GARDEN_PATH + GARDEN_PATH_DEN, \ 272 GARDEN_PATH + GARDEN_PATH_DEN + 4) 273 #define ISPATHPLAYER(c) INRANGE(c, GARDEN_PATH + GARDEN_PATH_PLAYER, \ 274 GARDEN_PATH + GARDEN_PATH_PLAYER + 4) 275 #define ISAPPLE(c) INRANGE(c, GARDEN_APPLE, GARDEN_APPLE + 16) 276 #define GARDENPATH(c) ((c) - GARDEN_PATH) 277 #define GARDENAPPLE(c) ((c) - GARDEN_APPLE) 278 /*}}}*/ 279 /*{{{ structs*/ 280 /*{{{ typedef struct Data*/ 281 typedef struct Data 282 { 283 Font font; /* font to use */ 284 #ifndef XMRED 285 String dir; /* score directory */ 286 String expire; /* expiration */ 287 String remove; /* removal */ 288 String boards; /* board definitions */ 289 String format; /* new date format */ 290 KeySym keysyms[KEYS]; 291 Boolean random; /* random apples */ 292 Boolean scores; /* high scores only */ 293 Boolean sprites; /* show sprites */ 294 Boolean username; /* use username of user */ 295 Boolean nodynamic; /* don't take advantage of dynamic visuals */ 296 Boolean nodisplay; /* don't open the display, even to get X resources */ 297 #ifndef TRANSPUTER 298 Boolean busywait; /* do busy waiting */ 299 #endif /* TRANSPUTER */ 300 #endif /* XMRED */ 301 Boolean gender; /* he or she? */ 302 int distinct; /* distinct colors allocated */ 303 Boolean help; /* gimme some help */ 304 Boolean swap; /* swap colours? */ 305 Boolean mono; /* force black & white */ 306 Boolean colors; /* color allocation */ 307 Boolean private; /* own colormap */ 308 } DATA; 309 /*}}}*/ 310 /*{{{ typedef struct _CommandOptionDesc*/ 311 typedef struct _CommandOptionDesc 312 { 313 char CONST *option; /* option text */ 314 unsigned optional; /* optional arg? */ 315 Cardinal offset; /* offset */ 316 } CommandOptionDesc; 317 /*}}}*/ 318 /*{{{ typedef struct Coord*/ 319 typedef struct Coord 320 /* general coordinate store */ 321 { 322 int x; 323 int y; 324 } COORD; 325 /*}}}*/ 326 /*{{{ typedef struct Size*/ 327 typedef struct Size 328 /* general size store */ 329 { 330 unsigned x; 331 unsigned y; 332 } SIZE; 333 /*}}}*/ 334 /*{{{ typedef struct Sprite*/ 335 typedef struct Sprite 336 /* sprite definition */ 337 { 338 Pixmap image; /* image pixmap */ 339 Pixmap mask; /* mask pixmap */ 340 SIZE size; /* size of sprite */ 341 } SPRITE; 342 /*}}}*/ 343 /*{{{ typedef struct Board*/ 344 typedef struct Board 345 /* initial board information */ 346 { 347 unsigned fill; /* fill pattern */ 348 unsigned colors; /* background colours: 0-red, 1-green, 2-blue */ 349 unsigned apples; /* initial number of apples */ 350 char map[CELLS_DOWN][CELLS_ACROSS + 1]; /* board lines with nul */ 351 } BOARD; 352 /*}}}*/ 353 /*}}}*/ 354 EXTERN char CONST *myname; /* name of me */ 355 /*{{{ display*/ 356 EXTERN struct 357 { 358 XtAppContext context; /* my context */ 359 Widget toplevel; /* toplevel widget */ 360 #ifndef XMRED 361 Widget form; /* form widget */ 362 Widget garden; /* garden widget */ 363 Window window; /* game window */ 364 #endif /* XMRED */ 365 Display *display; /* server name stuff */ 366 Colormap colormap; /* colormap */ 367 int screen; /* screen */ 368 Visual *visual; /* visual */ 369 int depth; /* screen depth */ 370 Pixel black; /* black pixel index */ 371 Pixel white; /* white pixel index */ 372 Pixel border; /* border pixel index */ 373 Pixel xor; /* black xor white */ 374 #ifndef XMRED 375 unsigned repeat; /* default keyrepeat state */ 376 unsigned mapped; /* is mapped */ 377 Pixmap back; /* background store */ 378 #endif /* XMRED */ 379 Pixmap copy; /* backing store */ 380 Pixmap icon; /* icon */ 381 unsigned background; /* type of background colour */ 382 unsigned foreground; /* type of foreground colour */ 383 unsigned dynamic; /* dynamic colors */ 384 } display; 385 /*}}}*/ 386 /*{{{ font*/ 387 EXTERN struct 388 { 389 unsigned width; /* width of a character */ 390 int ascent; /* max ascent */ 391 int descent; /* max descent */ 392 int center; /* center offset to add */ 393 int digitup; /* digit ascent */ 394 int digitdown;/* digit descent */ 395 } font; 396 /*}}}*/ 397 /*{{{ gc*/ 398 #define GCN(n) gcs[n] 399 #define GC_COPY 0 /* src */ 400 #define GC_CLEAR 1 /* background */ 401 #define GC_SET 2 /* foreground */ 402 #define GC_MASK 3 /* NOT src AND dst */ 403 #define GC_OR 4 /* src OR dst */ 404 #define GC_TEXT 5 /* text drawer */ 405 #define GC_AND 6 /* and */ 406 #define GC_BOARD 7 /* board background */ 407 #define GC_BORDER 8 /* border lines */ 408 #ifndef XMRED 409 #define GC_LOAD 9 /* game load line */ 410 #define GCS 10 411 #else 412 #define GCS 9 413 #endif /* XMRED */ 414 EXTERN GC gcs[GCS]; 415 /*}}}*/ 416 EXTERN DATA data; 417 /*{{{ tables*/ 418 EXTERN SPRITE sprites[SPRITES]; 419 EXTERN SPRITE fills[FILLS]; 420 extern unsigned CONST backgrounds[][2]; 421 EXTERN XColor colors[COLORS]; 422 extern unsigned char CONST **lettering; 423 /*}}}*/ 424