1 /* $Id: object.h,v 1.4 2003/01/11 01:11:37 btb Exp $ */ 2 /* 3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX 4 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO 5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A 6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS 7 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS 8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE 9 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE 10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS 11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE. 12 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. 13 */ 14 15 #ifndef _OBJECT_H 16 #define _OBJECT_H 17 18 #include "pstypes.h" 19 #include "vecmat.h" 20 #include "segment.h" 21 #include "gameseg.h" 22 #include "aistruct.h" 23 #include "gr.h" 24 #include "piggy.h" 25 26 /* 27 * CONSTANTS 28 */ 29 30 #define MAX_OBJECTS 350 //increased on 01/24/95 for multiplayer. --MK; total number of objects in world 31 32 //Object types 33 #define OBJ_NONE 255 //unused object 34 #define OBJ_WALL 0 //A wall... not really an object, but used for collisions 35 #define OBJ_FIREBALL 1 //a fireball, part of an explosion 36 #define OBJ_ROBOT 2 //an evil enemy 37 #define OBJ_HOSTAGE 3 //a hostage you need to rescue 38 #define OBJ_PLAYER 4 //the player on the console 39 #define OBJ_WEAPON 5 //a laser, missile, etc 40 #define OBJ_CAMERA 6 //a camera to slew around with 41 #define OBJ_POWERUP 7 //a powerup you can pick up 42 #define OBJ_DEBRIS 8 //a piece of robot 43 #define OBJ_CNTRLCEN 9 //the control center 44 #define OBJ_FLARE 10 //a flare 45 #define OBJ_CLUTTER 11 //misc objects 46 #define OBJ_GHOST 12 //what the player turns into when dead 47 #define OBJ_LIGHT 13 //a light source, & not much else 48 #define OBJ_COOP 14 //a cooperative player object. 49 #define OBJ_MARKER 15 //a map marker 50 // WARNING!! If you add a type here, add its name to Object_type_names in object.c 51 #define MAX_OBJECT_TYPES 16 52 53 //Result types 54 #define RESULT_NOTHING 0 //Ignore this collision 55 #define RESULT_CHECK 1 //Check for this collision 56 57 //Control types - what tells this object what do do 58 #define CT_NONE 0 //doesn't move (or change movement) 59 #define CT_AI 1 //driven by AI 60 #define CT_EXPLOSION 2 //explosion sequencer 61 #define CT_FLYING 4 //the player is flying 62 #define CT_SLEW 5 //slewing 63 #define CT_FLYTHROUGH 6 //the flythrough system 64 #define CT_WEAPON 9 //laser, etc. 65 #define CT_REPAIRCEN 10 //under the control of the repair center 66 #define CT_MORPH 11 //this object is being morphed 67 #define CT_DEBRIS 12 //this is a piece of debris 68 #define CT_POWERUP 13 //animating powerup blob 69 #define CT_LIGHT 14 //doesn't actually do anything 70 #define CT_REMOTE 15 //controlled by another net player 71 #define CT_CNTRLCEN 16 //the control center/main reactor 72 73 //Movement types 74 #define MT_NONE 0 //doesn't move 75 #define MT_PHYSICS 1 //moves by physics 76 #define MT_SPINNING 3 //this object doesn't move, just sits and spins 77 78 //Render types 79 #define RT_NONE 0 //does not render 80 #define RT_POLYOBJ 1 //a polygon model 81 #define RT_FIREBALL 2 //a fireball 82 #define RT_LASER 3 //a laser 83 #define RT_HOSTAGE 4 //a hostage 84 #define RT_POWERUP 5 //a powerup 85 #define RT_MORPH 6 //a robot being morphed 86 #define RT_WEAPON_VCLIP 7 //a weapon that renders as a vclip 87 88 //misc object flags 89 #define OF_EXPLODING 1 //this object is exploding 90 #define OF_SHOULD_BE_DEAD 2 //this object should be dead, so next time we can, we should delete this object. 91 #define OF_DESTROYED 4 //this has been killed, and is showing the dead version 92 #define OF_SILENT 8 //this makes no sound when it hits a wall. Added by MK for weapons, if you extend it to other types, do it completely! 93 #define OF_ATTACHED 16 //this object is a fireball attached to another object 94 #define OF_HARMLESS 32 //this object does no damage. Added to make quad lasers do 1.5 damage as normal lasers. 95 #define OF_PLAYER_DROPPED 64 //this object was dropped by the player... 96 97 //Different Weapon ID types... 98 #define WEAPON_ID_LASER 0 99 #define WEAPON_ID_MISSLE 1 100 #define WEAPON_ID_CANNONBALL 2 101 102 //Object Initial shields... 103 #define OBJECT_INITIAL_SHIELDS F1_0/2 104 105 //physics flags 106 #define PF_TURNROLL 0x01 // roll when turning 107 #define PF_LEVELLING 0x02 // level object with closest side 108 #define PF_BOUNCE 0x04 // bounce (not slide) when hit will 109 #define PF_WIGGLE 0x08 // wiggle while flying 110 #define PF_STICK 0x10 // object sticks (stops moving) when hits wall 111 #define PF_PERSISTENT 0x20 // object keeps going even after it hits another object (eg, fusion cannon) 112 #define PF_USES_THRUST 0x40 // this object uses its thrust 113 #define PF_BOUNCED_ONCE 0x80 // Weapon has bounced once. 114 #define PF_FREE_SPINNING 0x100 // Drag does not apply to rotation of this object 115 #define PF_BOUNCES_TWICE 0x200 // This weapon bounces twice, then dies 116 117 #define IMMORTAL_TIME 0x3fffffff // Time assigned to immortal objects, about 32768 seconds, or about 9 hours. 118 #define ONE_FRAME_TIME 0x3ffffffe // Objects with this lifeleft will live for exactly one frame 119 120 extern char Object_type_names[MAX_OBJECT_TYPES][9]; 121 122 // List of objects rendered last frame in order. Created at render time, used by homing missiles in laser.c 123 #define MAX_RENDERED_OBJECTS 50 124 125 /* 126 * STRUCTURES 127 */ 128 129 // A compressed form for sending crucial data about via slow devices, such as modems and buggies. 130 typedef struct shortpos { 131 byte bytemat[9]; 132 short xo,yo,zo; 133 short segment; 134 short velx, vely, velz; 135 } __pack__ shortpos; 136 137 // This is specific to the shortpos extraction routines in gameseg.c. 138 #define RELPOS_PRECISION 10 139 #define MATRIX_PRECISION 9 140 #define MATRIX_MAX 0x7f // This is based on MATRIX_PRECISION, 9 => 0x7f 141 142 //information for physics sim for an object 143 typedef struct physics_info { 144 vms_vector velocity; //velocity vector of this object 145 vms_vector thrust; //constant force applied to this object 146 fix mass; //the mass of this object 147 fix drag; //how fast this slows down 148 fix brakes; //how much brakes applied 149 vms_vector rotvel; //rotational velecity (angles) 150 vms_vector rotthrust; //rotational acceleration 151 fixang turnroll; //rotation caused by turn banking 152 ushort flags; //misc physics flags 153 } __pack__ physics_info; 154 155 //stuctures for different kinds of simulation 156 157 typedef struct laser_info { 158 short parent_type; // The type of the parent of this object 159 short parent_num; // The object's parent's number 160 int parent_signature; // The object's parent's signature... 161 fix creation_time; // Absolute time of creation. 162 short last_hitobj; // For persistent weapons (survive object collision), object it most recently hit. 163 short track_goal; // Object this object is tracking. 164 fix multiplier; // Power if this is a fusion bolt (or other super weapon to be added). 165 } __pack__ laser_info; 166 167 typedef struct explosion_info { 168 fix spawn_time; // when lifeleft is < this, spawn another 169 fix delete_time; // when to delete object 170 short delete_objnum; // and what object to delete 171 short attach_parent; // explosion is attached to this object 172 short prev_attach; // previous explosion in attach list 173 short next_attach; // next explosion in attach list 174 } __pack__ explosion_info; 175 176 typedef struct light_info { 177 fix intensity; //how bright the light is 178 } __pack__ light_info; 179 180 #define PF_SPAT_BY_PLAYER 1 //this powerup was spat by the player 181 182 typedef struct powerup_info { 183 int count; //how many/much we pick up (vulcan cannon only?) 184 fix creation_time; //Absolute time of creation. 185 int flags; //spat by player? 186 } __pack__ powerup_info; 187 188 typedef struct vclip_info { 189 int vclip_num; 190 fix frametime; 191 byte framenum; 192 } __pack__ vclip_info; 193 194 //structures for different kinds of rendering 195 196 typedef struct polyobj_info { 197 int model_num; //which polygon model 198 vms_angvec anim_angles[MAX_SUBMODELS]; //angles for each subobject 199 int subobj_flags; //specify which subobjs to draw 200 int tmap_override; //if this is not -1, map all face to this 201 int alt_textures; //if not -1, use these textures instead 202 } __pack__ polyobj_info; 203 204 typedef struct object { 205 int signature; // Every object ever has a unique signature... 206 ubyte type; // what type of object this is... robot, weapon, hostage, powerup, fireball 207 ubyte id; // which form of object...which powerup, robot, etc. 208 #ifdef WORDS_NEED_ALIGNMENT 209 short pad; 210 #endif 211 short next,prev; // id of next and previous connected object in Objects, -1 = no connection 212 ubyte control_type; // how this object is controlled 213 ubyte movement_type; // how this object moves 214 ubyte render_type; // how this object renders 215 ubyte flags; // misc flags 216 short segnum; // segment number containing object 217 short attached_obj; // number of attached fireball object 218 vms_vector pos; // absolute x,y,z coordinate of center of object 219 vms_matrix orient; // orientation of object in world 220 fix size; // 3d size of object - for collision detection 221 fix shields; // Starts at maximum, when <0, object dies.. 222 vms_vector last_pos; // where object was last frame 223 byte contains_type; // Type of object this object contains (eg, spider contains powerup) 224 byte contains_id; // ID of object this object contains (eg, id = blue type = key) 225 byte contains_count;// number of objects of type:id this object contains 226 byte matcen_creator;// Materialization center that created this object, high bit set if matcen-created 227 fix lifeleft; // how long until goes away, or 7fff if immortal 228 // -- Removed, MK, 10/16/95, using lifeleft instead: int lightlevel; 229 230 231 //movement info, determined by MOVEMENT_TYPE 232 union { 233 physics_info phys_info; //a physics object 234 vms_vector spin_rate; //for spinning objects 235 } __pack__ mtype; 236 237 //control info, determined by CONTROL_TYPE 238 union { 239 laser_info laser_info; 240 explosion_info expl_info; //NOTE: debris uses this also 241 ai_static ai_info; 242 light_info light_info; //why put this here? Didn't know what else to do with it. 243 powerup_info powerup_info; 244 } __pack__ ctype; 245 246 //render info, determined by RENDER_TYPE 247 union { 248 polyobj_info pobj_info; //polygon model 249 vclip_info vclip_info; //vclip 250 251 } __pack__ rtype; 252 253 #ifdef WORDS_NEED_ALIGNMENT 254 short pad2; 255 #endif 256 } __pack__ object; 257 258 typedef struct obj_position { 259 vms_vector pos; // absolute x,y,z coordinate of center of object 260 vms_matrix orient; // orientation of object in world 261 short segnum; // segment number containing object 262 } obj_position; 263 264 typedef struct { 265 int frame; 266 object *viewer; 267 int rear_view; 268 int user; 269 int num_objects; 270 short rendered_objects[MAX_RENDERED_OBJECTS]; 271 } window_rendered_data; 272 273 #define MAX_RENDERED_WINDOWS 3 274 275 extern window_rendered_data Window_rendered_data[MAX_RENDERED_WINDOWS]; 276 277 /* 278 * VARIABLES 279 */ 280 281 extern int Object_next_signature; // The next signature for the next newly created object 282 283 extern ubyte CollisionResult[MAX_OBJECT_TYPES][MAX_OBJECT_TYPES]; 284 // ie CollisionResult[a][b]== what happens to a when it collides with b 285 286 extern object Objects[]; 287 extern int Highest_object_index; //highest objnum 288 289 extern char *robot_names[]; //name of each robot 290 291 extern int Num_robot_types; 292 293 extern object *ConsoleObject; //pointer to the object that is the player 294 extern object *Viewer; //which object we are seeing from 295 extern object *Dead_player_camera; 296 297 extern object Follow; 298 extern int Player_is_dead; // !0 means player is dead! 299 extern int Player_exploded; 300 extern int Death_sequence_aborted; 301 extern int Player_fired_laser_this_frame; 302 303 /* 304 * FUNCTIONS 305 */ 306 307 308 //do whatever setup needs to be done 309 void init_objects(); 310 311 //returns segment number object is in. Searches out from object's current 312 //seg, so this shouldn't be called if the object has "jumped" to a new seg 313 int obj_get_new_seg(object *obj); 314 315 //when an object has moved into a new segment, this function unlinks it 316 //from its old segment, and links it into the new segment 317 void obj_relink(int objnum,int newsegnum); 318 319 //move an object from one segment to another. unlinks & relinks 320 void obj_set_new_seg(int objnum,int newsegnum); 321 322 //links an object into a segment's list of objects. 323 //takes object number and segment number 324 void obj_link(int objnum,int segnum); 325 326 //unlinks an object from a segment's list of objects 327 void obj_unlink(int objnum); 328 329 //initialize a new object. adds to the list for the given segment 330 //returns the object number 331 int obj_create(ubyte type,ubyte id,int segnum,vms_vector *pos, 332 vms_matrix *orient,fix size,ubyte ctype,ubyte mtype,ubyte rtype); 333 334 //make a copy of an object. returs num of new object 335 int obj_create_copy(int objnum, vms_vector *new_pos, int newsegnum); 336 337 //remove object from the world 338 void obj_delete(int objnum); 339 340 //called after load. Takes number of objects, and objects should be 341 //compressed 342 void reset_objects(int n_objs); 343 344 //make object array non-sparse 345 void compress_objects(void); 346 347 //Render an object. Calls one of several routines based on type 348 void render_object(object *obj); 349 350 //Draw a blob-type object, like a fireball 351 void draw_object_blob(object *obj,bitmap_index bitmap); 352 353 //draw an object that is a texture-mapped rod 354 void draw_object_tmap_rod(object *obj,bitmap_index bitmap,int lighted); 355 356 //Deletes all objects that have been marked for death. 357 void obj_delete_all_that_should_be_dead(); 358 359 // Toggles whether or not lock-boxes draw. 360 void object_toggle_lock_targets(); 361 362 //move all objects for the current frame 363 void object_move_all(); // moves all objects 364 365 //set viewer object to next object in array 366 void object_goto_next_viewer(); 367 368 //draw target boxes for nearby robots 369 void object_render_targets(void); 370 371 //move an object for the current frame 372 void object_move_one( object * obj ); 373 374 //make object0 the player, setting all relevant fields 375 void init_player_object(); 376 377 //check if object is in object->segnum. if not, check the adjacent segs. 378 //if not any of these, returns false, else sets obj->segnum & returns true 379 //callers should really use find_vector_intersection() 380 //Note: this function is in gameseg.c 381 extern int update_object_seg(struct object *obj); 382 383 384 // Finds what segment *obj is in, returns segment number. 385 // If not in any segment, returns -1. 386 // Note: This function is defined in gameseg.h, but object.h depends on gameseg.h, and 387 // object.h is where object is defined...get it? 388 extern int find_object_seg(object * obj ); 389 390 //go through all objects and make sure they have the correct segment numbers 391 //used when debugging is on 392 void fix_object_segs(); 393 394 // Drops objects contained in objp. 395 int object_create_egg(object *objp); 396 397 // Interface to object_create_egg, puts count objects of type type, id = id in objp and then drops them. 398 int call_object_create_egg(object *objp, int count, int type, int id); 399 400 extern void dead_player_end(void); 401 402 // Extract information from an object (objp->orient, objp->pos, objp->segnum), stuff in a shortpos structure. 403 // See typedef shortpos. 404 extern void create_shortpos(shortpos *spp, object *objp, int swap_bytes); 405 406 // Extract information from a shortpos, stuff in objp->orient (matrix), objp->pos, objp->segnum 407 extern void extract_shortpos(object *objp, shortpos *spp, int swap_bytes); 408 409 //delete objects, such as weapons & explosions, that shouldn't stay between levels 410 //if clear_all is set, clear even proximity bombs 411 void clear_transient_objects(int clear_all); 412 413 //returns the number of a free object, updating Highest_object_index. 414 //Generally, obj_create() should be called to get an object, since it 415 //fills in important fields and does the linking. 416 //returns -1 if no free objects 417 int obj_allocate(void); 418 419 //frees up an object. Generally, obj_delete() should be called to get 420 //rid of an object. This function deallocates the object entry after 421 //the object has been unlinked 422 void obj_free(int objnum); 423 424 //after calling init_object(), the network code has grabbed specific 425 //object slots without allocating them. Go though the objects & build 426 //the free list, then set the apporpriate globals 427 //Don't call this function if you don't know what you're doing. 428 void special_reset_objects(void); 429 430 //attaches an object, such as a fireball, to another object, such as a robot 431 void obj_attach(object *parent,object *sub); 432 433 extern void create_small_fireball_on_object(object *objp, fix size_scale, int sound_flag); 434 435 //returns object number 436 int drop_marker_object(vms_vector *pos,int segnum,vms_matrix *orient,int marker_num); 437 438 extern void wake_up_rendered_objects(object *gmissp, int window_num); 439 440 extern void AdjustMineSpawn(); 441 442 void reset_player_object(void); 443 444 #endif 445