1 /* 2 * XPilot NG, a multiplayer space war game. 3 * 4 * Copyright (C) 1991-2001 by 5 * 6 * Bj�rn Stabell <bjoern@xpilot.org> 7 * Ken Ronny Schouten <ken@xpilot.org> 8 * Bert Gijsbers <bert@xpilot.org> 9 * Dick Balaska <dick@xpilot.org> 10 * 11 * This program is free software; you can redistribute it and/or modify 12 * it under the terms of the GNU General Public License as published by 13 * the Free Software Foundation; either version 2 of the License, or 14 * (at your option) any later version. 15 * 16 * This program is distributed in the hope that it will be useful, 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * GNU General Public License for more details. 20 * 21 * You should have received a copy of the GNU General Public License 22 * along with this program; if not, write to the Free Software 23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 24 */ 25 26 #ifndef CONST_H 27 #define CONST_H 28 29 #ifndef XPCONFIG_H 30 #include "xpconfig.h" 31 #endif 32 33 #ifndef TYPES_H 34 #include "types.h" 35 #endif 36 37 /* 38 * FLT_MAX is ANSI C standard, but some systems (BSD) use 39 * MAXFLOAT instead. 40 */ 41 #ifndef FLT_MAX 42 # if defined(MAXFLOAT) 43 # define FLT_MAX MAXFLOAT 44 # else 45 # define FLT_MAX 1e30f /* should suffice :-) */ 46 # endif 47 #endif 48 49 /* Not everyone has PI (or M_PI defined). */ 50 #ifndef M_PI 51 # define PI 3.14159265358979323846 52 #else 53 # define PI M_PI 54 #endif 55 56 /* Not everyone has LINE_MAX either, *sigh* */ 57 #ifndef LINE_MAX 58 # define LINE_MAX 2048 59 #endif 60 61 /* No comment. */ 62 #ifndef PATH_MAX 63 # define PATH_MAX 1023 64 #endif 65 66 #define RES 128 67 68 #define BLOCK_SZ 35 69 70 #define TABLE_SIZE RES 71 72 extern double tbl_sin[]; 73 extern double tbl_cos[]; 74 75 #if 0 76 /* The way it was: one table, and always range checking. */ 77 # define tsin(x) (tbl_sin[MOD2(x, TABLE_SIZE)]) 78 # define tcos(x) (tbl_sin[MOD2((x)+TABLE_SIZE/4, TABLE_SIZE)]) 79 #else 80 # if 0 81 /* Range checking: find out where the table size is exceeded. */ 82 # define CHK2(x, m) ((MOD2(x, m) != x) ? (printf("MOD %s:%d:%s\n", __FILE__, __LINE__, #x), MOD2(x, m)) : (x)) 83 # else 84 /* No range checking. */ 85 # define CHK2(x, m) (x) 86 # endif 87 /* New table lookup with optional range checking and no extra calculations. */ 88 # define tsin(x) (tbl_sin[CHK2(x, TABLE_SIZE)]) 89 # define tcos(x) (tbl_cos[CHK2(x, TABLE_SIZE)]) 90 #endif 91 92 #define NELEM(a) ((int)(sizeof(a) / sizeof((a)[0]))) 93 94 #undef ABS 95 #define ABS(x) ( (x)<0 ? -(x) : (x) ) 96 #ifndef MAX 97 # define MIN(x, y) ( (x)>(y) ? (y) : (x) ) 98 # define MAX(x, y) ( (x)>(y) ? (x) : (y) ) 99 #endif 100 #define sqr(x) ( (x)*(x) ) 101 #define DELTA(a, b) (((a) >= (b)) ? ((a) - (b)) : ((b) - (a))) 102 #define LENGTH(x, y) ( hypot( (double) (x), (double) (y) ) ) 103 #define VECTOR_LENGTH(v) ( hypot( (double) (v).x, (double) (v).y ) ) 104 #define QUICK_LENGTH(x,y) ( ABS(x)+ABS(y) ) /*-BA Only approx, but v. quick */ 105 #define LIMIT(val, lo, hi) ( val=(val)>(hi)?(hi):((val)<(lo)?(lo):(val)) ) 106 107 108 #ifndef MOD2 109 # define MOD2(x, m) ( (x) & ((m) - 1) ) 110 #endif /* MOD2 */ 111 112 /* borrowed from autobook */ 113 #define XCALLOC(type, num) \ 114 ((type *) calloc ((num), sizeof(type))) 115 #define XMALLOC(type, num) \ 116 ((type *) malloc ((num) * sizeof(type))) 117 #define XREALLOC(type, p, num) \ 118 ((type *) realloc ((p), (num) * sizeof(type))) 119 #define XFREE(ptr) \ 120 do { \ 121 if (ptr) { free(ptr); ptr = NULL; } \ 122 } while (0) 123 124 /* Use this to remove unused parameter warning. */ 125 #define UNUSED_PARAM(x) x = x 126 127 /* Do NOT change these! */ 128 #define OLD_MAX_CHECKS 26 129 #define MAX_TEAMS 10 130 131 #define EXPIRED_MINE_ID 4096 /* assume no player has this id */ 132 133 #define MAX_CHARS 80 134 #define MSG_LEN 256 135 136 #define NUM_MODBANKS 4 137 138 #define SPEED_LIMIT 65.0 139 #define MAX_PLAYER_TURNSPEED 64.0 140 #define MIN_PLAYER_TURNSPEED 0.0 141 #define MAX_PLAYER_POWER 55.0 142 #define MIN_PLAYER_POWER 5.0 143 #define MAX_PLAYER_TURNRESISTANCE 1.0 144 #define MIN_PLAYER_TURNRESISTANCE 0.0 145 146 #define MAX_STATION_FUEL 500.0 147 #define TARGET_DAMAGE 250.0 148 #define SELF_DESTRUCT_DELAY 150.0 149 150 /* 151 * Size (pixels) of radius for legal HIT! 152 * Was 14 until 4.2. Increased due to 'analytical collision detection' 153 * which inspects a real circle and not just a square anymore. 154 */ 155 #define SHIP_SZ 16 156 157 #define VISIBILITY_DISTANCE 1000.0 158 159 #define BALL_RADIUS 10 160 161 #define MISSILE_LEN 15 162 163 #define TEAM_NOT_SET 0xffff 164 165 #define DEBRIS_TYPES (8 * 4 * 4) 166 167 #undef rand 168 #define rand() please dont use rand. 169 170 /* 171 * The server supports only 4 colors, except for spark/debris, which 172 * may have 8 different colors. 173 */ 174 #define NUM_COLORS 4 175 176 #define BLACK 0 177 #define WHITE 1 178 #define BLUE 2 179 #define RED 3 180 181 /* 182 * Windows deals in Pens, not Colors. So each pen has to have all of its 183 * attributes defined. 184 */ 185 #if defined(_WINDOWS) && !defined(PENS_OF_PLENTY) 186 #define CLOAKCOLOROFS 15 /* colors 16 and 17 are dashed white/blue */ 187 #define MISSILECOLOR 18 /* wide white pen */ 188 #define LASERCOLOR 19 /* wide red pen */ 189 #define LASERTEAMCOLOR 20 /* wide blue pen */ 190 #define FUNKCOLORS 6 /* 6 funky colors here (15-20) */ 191 #endif 192 193 /* 194 * The minimum and maximum playing window sizes supported by the server. 195 */ 196 #define MIN_VIEW_SIZE 384 197 #define MAX_VIEW_SIZE 1024 198 #define DEF_VIEW_SIZE 768 199 200 /* 201 * Spark rand limits. 202 */ 203 #define MIN_SPARK_RAND 0 /* Not display spark */ 204 #define MAX_SPARK_RAND 0x80 /* Always display spark */ 205 #define DEF_SPARK_RAND 0x55 /* 66% */ 206 207 #define UPDATE_SCORE_DELAY (FPS) 208 209 /* 210 * Polygon style flags 211 */ 212 #define STYLE_FILLED (1U << 0) 213 #define STYLE_TEXTURED (1U << 1) 214 #define STYLE_INVISIBLE (1U << 2) 215 #define STYLE_INVISIBLE_RADAR (1U << 3) 216 217 #endif 218