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 OBJECT_H 27 #define OBJECT_H 28 29 #ifndef MAP_H 30 /* need treasure_t */ 31 #include "map.h" 32 #endif 33 34 #ifndef MODIFIERS_H 35 /* need modifiers_t */ 36 #include "modifiers.h" 37 #endif 38 39 /* 40 * Different types of objects, including player. 41 * Robots and tanks are players but have an additional type_ext field. 42 * Smart missile, heatseeker and torpedo can be merged into missile. 43 */ 44 #define OBJ_TYPEBIT(type) (1U<<(type)) 45 46 #define OBJ_PLAYER 0 47 #define OBJ_DEBRIS 1 48 #define OBJ_SPARK 2 49 #define OBJ_BALL 3 50 #define OBJ_SHOT 4 51 #define OBJ_SMART_SHOT 5 52 #define OBJ_MINE 6 53 #define OBJ_TORPEDO 7 54 #define OBJ_HEAT_SHOT 8 55 #define OBJ_PULSE 9 56 #define OBJ_ITEM 10 57 #define OBJ_WRECKAGE 11 58 #define OBJ_ASTEROID 12 59 #define OBJ_CANNON_SHOT 13 60 61 #define OBJ_PLAYER_BIT OBJ_TYPEBIT(OBJ_PLAYER) 62 #define OBJ_DEBRIS_BIT OBJ_TYPEBIT(OBJ_DEBRIS) 63 #define OBJ_SPARK_BIT OBJ_TYPEBIT(OBJ_SPARK) 64 #define OBJ_BALL_BIT OBJ_TYPEBIT(OBJ_BALL) 65 #define OBJ_SHOT_BIT OBJ_TYPEBIT(OBJ_SHOT) 66 #define OBJ_SMART_SHOT_BIT OBJ_TYPEBIT(OBJ_SMART_SHOT) 67 #define OBJ_MINE_BIT OBJ_TYPEBIT(OBJ_MINE) 68 #define OBJ_TORPEDO_BIT OBJ_TYPEBIT(OBJ_TORPEDO) 69 #define OBJ_HEAT_SHOT_BIT OBJ_TYPEBIT(OBJ_HEAT_SHOT) 70 #define OBJ_PULSE_BIT OBJ_TYPEBIT(OBJ_PULSE) 71 #define OBJ_ITEM_BIT OBJ_TYPEBIT(OBJ_ITEM) 72 #define OBJ_WRECKAGE_BIT OBJ_TYPEBIT(OBJ_WRECKAGE) 73 #define OBJ_ASTEROID_BIT OBJ_TYPEBIT(OBJ_ASTEROID) 74 #define OBJ_CANNON_SHOT_BIT OBJ_TYPEBIT(OBJ_CANNON_SHOT) 75 76 /* 77 * Possible object status bits. 78 */ 79 #define GRAVITY (1U<<0) 80 #define WARPING (1U<<1) 81 #define WARPED (1U<<2) 82 #define CONFUSED (1U<<3) 83 #define FROMCANNON (1U<<4) /* Object from cannon */ 84 #define RECREATE (1U<<5) /* Recreate ball */ 85 #define THRUSTING (1U<<6) /* Engine is thrusting */ 86 #define OWNERIMMUNE (1U<<7) /* Owner is immune to object */ 87 #define NOEXPLOSION (1U<<8) /* No recreate explosion */ 88 #define COLLISIONSHOVE (1U<<9) /* Collision counts as shove */ 89 #define RANDOM_ITEM (1U<<10) /* Item shows up as random */ 90 91 #define LOCK_NONE 0x00 /* No lock */ 92 #define LOCK_PLAYER 0x01 /* Locked on player */ 93 #define LOCK_VISIBLE 0x02 /* Lock information was on HUD */ 94 /* computed just before frame shown */ 95 /* and client input checked */ 96 #define LOCKBANK_MAX 4 /* Maximum number of locks in bank */ 97 98 /* 99 * Node within a Cell list. 100 */ 101 typedef struct cell_node cell_node_t; 102 struct cell_node { 103 cell_node_t *next; 104 cell_node_t *prev; 105 }; 106 107 108 #define OBJECT_BASE \ 109 short id; /* For shots => id of player */ \ 110 uint16_t team; /* Team of player or cannon */ \ 111 /* Object position pos must only be changed with the proper functions! */ \ 112 clpos_t pos; /* World coordinates */ \ 113 clpos_t prevpos; /* previous position */ \ 114 clpos_t extmove; /* For collision detection */ \ 115 float wall_time; /* bounce/crash time within frame */ \ 116 vector_t vel; /* speed in x,y */ \ 117 vector_t acc; /* acceleration in x,y */ \ 118 float mass; /* mass in unigrams */ \ 119 float life; /* No of ticks left to live */ \ 120 modifiers_t mods; /* Modifiers to this object */ \ 121 uint8_t type; /* one of OBJ_XXX */ \ 122 uint8_t color; /* Color of object */ \ 123 uint8_t collmode; /* collision checking mode */ \ 124 uint8_t missile_dir; /* missile direction */ \ 125 short wormHoleHit; \ 126 short wormHoleDest; \ 127 uint16_t obj_status; /* gravity, etc. */ \ 128 129 /* up to here all object types are the same as all player types. */ 130 131 #define OBJECT_EXTEND \ 132 cell_node_t cell; /* node in cell linked list */ \ 133 short pl_range; /* distance for collision */ \ 134 short pl_radius; /* distance for hit */ \ 135 float fuse; /* ticks until fused */ \ 136 137 /* up to here all object types are the same. */ 138 139 140 /* 141 * Generic object 142 */ 143 typedef struct xp_object object_t; 144 struct xp_object { 145 146 OBJECT_BASE 147 148 OBJECT_EXTEND 149 150 #define OBJ_IND(ind) (Obj[(ind)]) 151 #define OBJ_PTR(ptr) ((object_t *)(ptr)) 152 }; 153 154 /* 155 * Mine object 156 */ 157 typedef struct xp_mineobject mineobject_t; 158 struct xp_mineobject { 159 160 OBJECT_BASE 161 162 OBJECT_EXTEND 163 164 float mine_count; /* Misc snafus */ 165 float mine_ecm_range; /* Range from last ecm center */ 166 float mine_spread_left; /* how much spread time left */ 167 short mine_owner; /* Who's object is this ? */ 168 169 #define MINE_IND(ind) ((mineobject_t *)Obj[(ind)]) 170 #define MINE_PTR(ptr) ((mineobject_t *)(ptr)) 171 }; 172 173 174 #define MISSILE_EXTEND \ 175 float missile_max_speed; /* speed limitation */ \ 176 float missile_turnspeed; /* how fast to turn */ 177 178 179 /* up to here all missiles types are the same. */ 180 181 /* 182 * Generic missile object 183 */ 184 typedef struct xp_missileobject missileobject_t; 185 struct xp_missileobject { 186 187 OBJECT_BASE 188 189 OBJECT_EXTEND 190 191 MISSILE_EXTEND 192 193 #define MISSILE_IND(ind) ((missileobject_t *)Obj[(ind)]) 194 #define MISSILE_PTR(ptr) ((missileobject_t *)(ptr)) 195 }; 196 197 198 /* 199 * Smart missile is a generic missile with extras. 200 */ 201 typedef struct xp_smartobject smartobject_t; 202 struct xp_smartobject { 203 204 OBJECT_BASE 205 206 OBJECT_EXTEND 207 208 MISSILE_EXTEND 209 210 float smart_ecm_range; /* Range from last ecm center*/ 211 float smart_count; /* Misc snafus */ 212 short smart_lock_id; /* snafu */ 213 short smart_relock_id; /* smart re-lock id */ 214 215 #define SMART_IND(ind) ((smartobject_t *)Obj[(ind)]) 216 #define SMART_PTR(ptr) ((smartobject_t *)(ptr)) 217 }; 218 219 220 /* 221 * Torpedo is a generic missile with extras 222 */ 223 typedef struct xp_torpobject torpobject_t; 224 struct xp_torpobject { 225 226 OBJECT_BASE 227 228 OBJECT_EXTEND 229 230 MISSILE_EXTEND 231 232 float torp_spread_left; /* how much spread time left */ 233 float torp_count; /* Misc snafus */ 234 235 #define TORP_IND(ind) ((torpobject_t *)Obj[(ind)]) 236 #define TORP_PTR(ptr) ((torpobject_t *)(ptr)) 237 }; 238 239 240 /* 241 * Heat-seeker is a generic missile with extras 242 */ 243 typedef struct xp_heatobject heatobject_t; 244 struct xp_heatobject { 245 246 OBJECT_BASE 247 248 OBJECT_EXTEND 249 250 MISSILE_EXTEND 251 252 float heat_count; /* Misc snafus */ 253 short heat_lock_id; /* snafu */ 254 255 #define HEAT_IND(ind) ((heatobject_t *)Obj[(ind)]) 256 #define HEAT_PTR(ptr) ((heatobject_t *)(ptr)) 257 }; 258 259 260 /* 261 * The ball object. 262 */ 263 typedef struct xp_ballobject ballobject_t; 264 struct xp_ballobject { 265 266 OBJECT_BASE 267 268 OBJECT_EXTEND 269 270 double ball_loose_ticks; 271 treasure_t *ball_treasure; /* treasure for ball */ 272 short ball_owner; /* Who's object is this ? */ 273 short ball_style; /* What polystyle to use */ 274 275 #define BALL_IND(ind) ((ballobject_t *)Obj[(ind)]) 276 #define BALL_PTR(obj) ((ballobject_t *)(obj)) 277 }; 278 279 280 /* 281 * Object with a wireframe representation. 282 */ 283 typedef struct xp_wireobject wireobject_t; 284 struct xp_wireobject { 285 286 OBJECT_BASE 287 288 OBJECT_EXTEND 289 290 float wire_turnspeed; /* how fast to turn */ 291 292 uint8_t wire_type; /* Type of object */ 293 uint8_t wire_size; /* Size of object */ 294 uint8_t wire_rotation; /* Rotation direction */ 295 296 #define WIRE_IND(ind) ((wireobject_t *)Obj[(ind)]) 297 #define WIRE_PTR(obj) ((wireobject_t *)(obj)) 298 }; 299 300 301 /* 302 * Pulse object used for laser pulses. 303 */ 304 typedef struct xp_pulseobject pulseobject_t; 305 struct xp_pulseobject { 306 307 OBJECT_BASE 308 309 OBJECT_EXTEND 310 311 float pulse_len; /* Length of the pulse */ 312 uint8_t pulse_dir; /* Direction of the pulse */ 313 bool pulse_refl; /* Pulse was reflected ? */ 314 315 #define PULSE_IND(ind) ((pulseobject_t *)Obj[(ind)]) 316 #define PULSE_PTR(obj) ((pulseobject_t *)(obj)) 317 }; 318 319 320 /* 321 * Item object. 322 */ 323 typedef struct xp_itemobject itemobject_t; 324 struct xp_itemobject { 325 326 OBJECT_BASE 327 328 OBJECT_EXTEND 329 330 int item_type; /* One of ITEM_* */ 331 int item_count; /* Misc snafus */ 332 333 #define ITEM_IND(ind) ((itemobject_t *)Obj[(ind)]) 334 #define ITEM_PTR(obj) ((itemobject_t *)(obj)) 335 }; 336 337 338 /* 339 * Any object type should be part of this union. 340 */ 341 typedef union xp_anyobject anyobject_t; 342 union xp_anyobject { 343 object_t obj; 344 ballobject_t ball; 345 mineobject_t mine; 346 missileobject_t missile; 347 smartobject_t smart; 348 torpobject_t torp; 349 heatobject_t heat; 350 wireobject_t wireobj; 351 pulseobject_t pulse; 352 itemobject_t item; 353 }; 354 355 #endif 356