// // nazghul - an old-school RPG engine // Copyright (C) 2002, 2003 Gordon McNutt // // This program is free software; you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by the Free // Software Foundation; either version 2 of the License, or (at your option) // any later version. // // This program is distributed in the hope that it will be useful, but WITHOUT // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for // more details. // // You should have received a copy of the GNU General Public License along with // this program; if not, write to the Free Foundation, Inc., 59 Temple Place, // Suite 330, Boston, MA 02111-1307 USA // // Gordon McNutt // gmcnutt@users.sourceforge.net // #ifndef common_h #define common_h #ifdef __cplusplus extern "C" { #endif #include "list.h" #include "debug.h" #include "los.h" #include "dup_constants.h" #include #include #include /* Constants *****************************************************************/ /* Directions */ #define DIRECTION_NONE -1 #define NORTHWEST 0 #define NORTH 1 #define NORTHEAST 2 #define WEST 3 #define HERE 4 #define EAST 5 #define SOUTHWEST 6 #define SOUTH 7 #define SOUTHEAST 8 #define UP 9 #define DOWN 10 #define NUM_DIRECTIONS 11 #define NUM_PLANAR_DIRECTIONS 9 #define NUM_WIND_DIRECTIONS 4 #define IS_LEGAL_DIRECTION(dir) ((dir)>=0 && (dir) (b) ? (a) : (b)) #define min(a,b) ((a) < (b) ? (a) : (b)) #define clamp(v,a,b) ((v) = (v) < (a) ? (a) : ((v) > (b) ? (b) : (v))) #define array_sz(a) (int)(sizeof((a))/sizeof((a)[0])) #define outcast(ptr,type,field) \ ((type*)((char*)(ptr)-(unsigned long)(&((type *)0)->field))) #define CREATE(ptr,type,err) \ (ptr) = (type*)malloc(sizeof(type)); \ if (!(ptr)) \ return (err); \ memset((ptr), 0, sizeof(type)); #define distance(dx,dy) (((dx)>(dy)) ? ((dx)+((dy)>>1)) : ((dy)+ (dx)>>1))) // SAM: The below are used by palette_print(), terrain_map_print(), etc. #define INITIAL_INDENTATION 0 #define INDENTATION_FACTOR 2 #define INDENT fprintf(fp, "%*s", indent, "") /* Enums *********************************************************************/ typedef enum { UI_SIZE_NORMAL = 0, UI_SIZE_SMALL = 1 } ui_size_t; /* Structures ****************************************************************/ /* Global Functions **********************************************************/ char * version_as_string(void); // From nazghul.c extern int commonInit(void); extern char *get_dir_str(int dx, int dy); extern void turnAdvance(int turns); extern int vector_to_dir(int dx, int dy); extern int vector_to_facing(int dx, int dy); extern int vector_to_rotation(int dx, int dy); extern int stringToDirection(char *str); extern int keyToDirection(int key); extern int directionToDx(int dir); extern int directionToDy(int dir); extern char *directionToString(int dir); extern bool isvowel(char c); extern bool point_in_rect(int x, int y, SDL_Rect *rect); extern int directionToOpposite(int dir); #define keyIsDirection(key) ((key) >= KEY_SOUTHWEST && (key) <= KEY_NORTHEAST) /* Global Variables **********************************************************/ extern int Turn; extern int AnimationTicks; extern int Tick; extern int TickMilliseconds; extern bool Quit; extern struct los *LosEngine; extern int ShowAllTerrain; extern int logBase2(int val); #ifdef __cplusplus } #endif #endif