|
Odamex
Setting the Standard in Multiplayer Doom
|
00001 // Emacs style mode select -*- C++ -*- 00002 //----------------------------------------------------------------------------- 00003 // 00004 // $Id: actor.h 1828 2010-08-31 03:42:35Z mike $ 00005 // 00006 // Copyright (C) 1993-1996 by id Software, Inc. 00007 // Copyright (C) 2006-2010 by The Odamex Team. 00008 // 00009 // This program is free software; you can redistribute it and/or 00010 // modify it under the terms of the GNU General Public License 00011 // as published by the Free Software Foundation; either version 2 00012 // of the License, or (at your option) any later version. 00013 // 00014 // This program is distributed in the hope that it will be useful, 00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 // GNU General Public License for more details. 00018 // 00019 // DESCRIPTION: 00020 // Map Objects, MObj, definition and handling. 00021 // 00022 //----------------------------------------------------------------------------- 00023 00024 00025 #ifndef __ACTOR_H__ 00026 #define __ACTOR_H__ 00027 00028 // Basics. 00029 #include "tables.h" 00030 #include "m_fixed.h" 00031 00032 // We need the thinker_t stuff. 00033 #include "dthinker.h" 00034 00035 // We need the WAD data structure for Map things, 00036 // from the THINGS lump. 00037 #include "doomdata.h" 00038 00039 // States are tied to finite states are 00040 // tied to animation frames. 00041 // Needs precompiled tables/data structures. 00042 #include "info.h" 00043 00044 #include "szp.h" 00045 00046 // STL 00047 #include <vector> 00048 #include <map> 00049 00050 // 00051 // NOTES: AActor 00052 // 00053 // Actors are used to tell the refresh where to draw an image, 00054 // tell the world simulation when objects are contacted, 00055 // and tell the sound driver how to position a sound. 00056 // 00057 // The refresh uses the next and prev links to follow 00058 // lists of things in sectors as they are being drawn. 00059 // The sprite, frame, and angle elements determine which patch_t 00060 // is used to draw the sprite if it is visible. 00061 // The sprite and frame values are almost always set 00062 // from state_t structures. 00063 // The statescr.exe utility generates the states.h and states.c 00064 // files that contain the sprite/frame numbers from the 00065 // statescr.txt source file. 00066 // The xyz origin point represents a point at the bottom middle 00067 // of the sprite (between the feet of a biped). 00068 // This is the default origin position for patch_ts grabbed 00069 // with lumpy.exe. 00070 // A walking creature will have its z equal to the floor 00071 // it is standing on. 00072 // 00073 // The sound code uses the x,y, and subsector fields 00074 // to do stereo positioning of any sound effited by the AActor. 00075 // 00076 // The play simulation uses the blocklinks, x,y,z, radius, height 00077 // to determine when AActors are touching each other, 00078 // touching lines in the map, or hit by trace lines (gunshots, 00079 // lines of sight, etc). 00080 // The AActor->flags element has various bit flags 00081 // used by the simulation. 00082 // 00083 // Every actor is linked into a single sector 00084 // based on its origin coordinates. 00085 // The subsector_t is found with R_PointInSubsector(x,y), 00086 // and the sector_t can be found with subsector->sector. 00087 // The sector links are only used by the rendering code, 00088 // the play simulation does not care about them at all. 00089 // 00090 // Any actor that needs to be acted upon by something else 00091 // in the play world (block movement, be shot, etc) will also 00092 // need to be linked into the blockmap. 00093 // If the thing has the MF_NOBLOCK flag set, it will not use 00094 // the block links. It can still interact with other things, 00095 // but only as the instigator (missiles will run into other 00096 // things, but nothing can run into a missile). 00097 // Each block in the grid is 128*128 units, and knows about 00098 // every line_t that it contains a piece of, and every 00099 // interactable actor that has its origin contained. 00100 // 00101 // A valid actor is an actor that has the proper subsector_t 00102 // filled in for its xy coordinates and is linked into the 00103 // sector from which the subsector was made, or has the 00104 // MF_NOSECTOR flag set (the subsector_t needs to be valid 00105 // even if MF_NOSECTOR is set), and is linked into a blockmap 00106 // block or has the MF_NOBLOCKMAP flag set. 00107 // Links should only be modified by the P_[Un]SetThingPosition() 00108 // functions. 00109 // Do not change the MF_NO* flags while a thing is valid. 00110 // 00111 // Any questions? 00112 // 00113 00114 // 00115 // Misc. mobj flags 00116 // 00117 typedef enum 00118 { 00119 // --- mobj.flags --- 00120 00121 MF_SPECIAL = 0x00000001, // call P_SpecialThing when touched 00122 MF_SOLID = 0x00000002, 00123 MF_SHOOTABLE = 0x00000004, 00124 MF_NOSECTOR = 0x00000008, // don't use the sector links 00125 // (invisible but touchable) 00126 MF_NOBLOCKMAP = 0x00000010, // don't use the blocklinks 00127 // (inert but displayable) 00128 MF_AMBUSH = 0x00000020, // not activated by sound; deaf monster 00129 MF_JUSTHIT = 0x00000040, // try to attack right back 00130 MF_JUSTATTACKED = 0x00000080, // take at least one step before attacking 00131 MF_SPAWNCEILING = 0x00000100, // hang from ceiling instead of floor 00132 MF_NOGRAVITY = 0x00000200, // don't apply gravity every tic 00133 00134 // movement flags 00135 MF_DROPOFF = 0x00000400, // allow jumps from high places 00136 MF_PICKUP = 0x00000800, // for players to pick up items 00137 MF_NOCLIP = 0x00001000, // player cheat 00138 MF_SLIDE = 0x00002000, // keep info about sliding along walls 00139 MF_FLOAT = 0x00004000, // allow moves to any height, no gravity 00140 MF_TELEPORT = 0x00008000, // don't cross lines or look at heights 00141 MF_MISSILE = 0x00010000, // don't hit same species, explode on block 00142 00143 MF_DROPPED = 0x00020000, // dropped by a demon, not level spawned 00144 MF_SHADOW = 0x00040000, // actor is hard for monsters to see 00145 MF_NOBLOOD = 0x00080000, // don't bleed when shot (use puff) 00146 MF_CORPSE = 0x00100000, // don't stop moving halfway off a step 00147 MF_INFLOAT = 0x00200000, // floating to a height for a move, don't 00148 // auto float to target's height 00149 00150 MF_COUNTKILL = 0x00400000, // count towards intermission kill total 00151 MF_COUNTITEM = 0x00800000, // count towards intermission item total 00152 00153 MF_SKULLFLY = 0x01000000, // skull in flight 00154 MF_NOTDMATCH = 0x02000000, // don't spawn in death match (key cards) 00155 00156 // Player sprites in multiplayer modes are modified 00157 // using an internal color lookup table for re-indexing. 00158 // If 0x4 0x8 or 0xc, use a translation table for player colormaps 00159 MF_TRANSLATION = 0xc000000, 00160 00161 MF_UNMORPHED = 0x10000000, // [RH] Actor is the unmorphed version of something else 00162 MF_FALLING = 0x20000000, 00163 MF_SPECTATOR = 0x40000000, // GhostlyDeath -- thing is/was a spectator and can't be seen! 00164 MF_ICECORPSE = 0x80000000, // a frozen corpse (for blasting) [RH] was 0x800000 00165 00166 // --- mobj.flags2 --- 00167 00168 MF2_LOGRAV = 0x00000001, // alternate gravity setting 00169 MF2_WINDTHRUST = 0x00000002, // gets pushed around by the wind 00170 // specials 00171 MF2_FLOORBOUNCE = 0x00000004, // bounces off the floor 00172 MF2_BLASTED = 0x00000008, // missile will pass through ghosts 00173 MF2_FLY = 0x00000010, // fly mode is active 00174 MF2_FLOORCLIP = 0x00000020, // if feet are allowed to be clipped 00175 MF2_SPAWNFLOAT = 0x00000040, // spawn random float z 00176 MF2_NOTELEPORT = 0x00000080, // does not teleport 00177 MF2_RIP = 0x00000100, // missile rips through solid 00178 // targets 00179 MF2_PUSHABLE = 0x00000200, // can be pushed by other moving 00180 // mobjs 00181 MF2_SLIDE = 0x00000400, // slides against walls 00182 MF2_ONMOBJ = 0x00000800, // mobj is resting on top of another 00183 // mobj 00184 MF2_PASSMOBJ = 0x00001000, // Enable z block checking. If on, 00185 // this flag will allow the mobj to 00186 // pass over/under other mobjs. 00187 MF2_CANNOTPUSH = 0x00002000, // cannot push other pushable mobjs 00188 MF2_THRUGHOST = 0x00004000, // missile will pass through ghosts [RH] was 8 00189 MF2_BOSS = 0x00008000, // mobj is a major boss 00190 MF2_FIREDAMAGE = 0x00010000, // does fire damage 00191 MF2_NODMGTHRUST = 0x00020000, // does not thrust target when damaging 00192 MF2_TELESTOMP = 0x00040000, // mobj can stomp another 00193 MF2_FLOATBOB = 0x00080000, // use float bobbing z movement 00194 MF2_DONTDRAW = 0x00100000, // don't generate a vissprite 00195 MF2_IMPACT = 0x00200000, // an MF_MISSILE mobj can activate SPAC_IMPACT 00196 MF2_PUSHWALL = 0x00400000, // mobj can push walls 00197 MF2_MCROSS = 0x00800000, // can activate monster cross lines 00198 MF2_PCROSS = 0x01000000, // can activate projectile cross lines 00199 MF2_CANTLEAVEFLOORPIC = 0x02000000, // stay within a certain floor type 00200 MF2_NONSHOOTABLE = 0x04000000, // mobj is totally non-shootable, 00201 // but still considered solid 00202 MF2_INVULNERABLE = 0x08000000, // mobj is invulnerable 00203 MF2_DORMANT = 0x10000000, // thing is dormant 00204 MF2_ICEDAMAGE = 0x20000000, // does ice damage 00205 MF2_SEEKERMISSILE = 0x40000000, // is a seeker (for reflection) 00206 MF2_REFLECTIVE = 0x80000000 // reflects missiles 00207 00208 } mobjflag_t; 00209 00210 #define MF_TRANSSHIFT 0x1A 00211 00212 #define TRANSLUC25 (FRACUNIT/4) 00213 #define TRANSLUC33 (FRACUNIT/3) 00214 #define TRANSLUC50 (FRACUNIT/2) 00215 #define TRANSLUC66 ((FRACUNIT*2)/3) 00216 #define TRANSLUC75 ((FRACUNIT*3)/4) 00217 00218 // Map Object definition. 00219 class AActor : public DThinker 00220 { 00221 DECLARE_SERIAL (AActor, DThinker) 00222 typedef szp<AActor> AActorPtr; 00223 AActorPtr self; 00224 00225 class AActorPtrCounted 00226 { 00227 AActorPtr ptr; 00228 00229 public: 00230 00231 AActorPtrCounted() {} 00232 00233 AActorPtr &operator= (AActorPtr other) 00234 { 00235 if(ptr) 00236 ptr->refCount--; 00237 if(other) 00238 other->refCount++; 00239 ptr = other; 00240 return ptr; 00241 } 00242 00243 AActorPtr &operator= (AActorPtrCounted other) 00244 { 00245 if(ptr) 00246 ptr->refCount--; 00247 if(other) 00248 other->refCount++; 00249 ptr = other.ptr; 00250 return ptr; 00251 } 00252 00253 ~AActorPtrCounted() 00254 { 00255 if(ptr) 00256 ptr->refCount--; 00257 } 00258 00259 operator AActorPtr() 00260 { 00261 return ptr; 00262 } 00263 operator AActor*() 00264 { 00265 return ptr; 00266 } 00267 00268 AActor &operator *() 00269 { 00270 return *ptr; 00271 } 00272 AActor *operator ->() 00273 { 00274 return ptr; 00275 } 00276 }; 00277 00278 public: 00279 AActor (); 00280 AActor (const AActor &other); 00281 AActor &operator= (const AActor &other); 00282 AActor (fixed_t x, fixed_t y, fixed_t z, mobjtype_t type); 00283 void Destroy (); 00284 ~AActor (); 00285 00286 virtual void RunThink (); 00287 00288 // Info for drawing: position. 00289 fixed_t x; 00290 fixed_t y; 00291 fixed_t z; 00292 00293 AActor *snext, **sprev; // links in sector (if needed) 00294 00295 //More drawing info: to determine current sprite. 00296 angle_t angle; // orientation 00297 spritenum_t sprite; // used to find patch_t and flip value 00298 int frame; // might be ORed with FF_FULLBRIGHT 00299 fixed_t pitch, roll; 00300 00301 DWORD effects; // [RH] see p_effect.h 00302 00303 // Interaction info, by BLOCKMAP. 00304 // Links in blocks (if needed). 00305 AActor *bnext, **bprev; 00306 struct subsector_s *subsector; 00307 00308 // The closest interval over all contacted Sectors. 00309 fixed_t floorz; 00310 fixed_t ceilingz; 00311 00312 // For movement checking. 00313 fixed_t radius; 00314 fixed_t height; 00315 00316 // Momentums, used to update position. 00317 fixed_t momx; 00318 fixed_t momy; 00319 fixed_t momz; 00320 00321 // If == validcount, already checked. 00322 int validcount; 00323 00324 mobjtype_t type; 00325 mobjinfo_t* info; // &mobjinfo[mobj->type] 00326 int tics; // state tic counter 00327 state_t *state; 00328 int flags; 00329 int flags2; // Heretic flags 00330 int special1; // Special info 00331 int special2; // Special info 00332 int health; 00333 00334 // Movement direction, movement generation (zig-zagging). 00335 byte movedir; // 0-7 00336 int movecount; // when 0, select a new dir 00337 char visdir; 00338 00339 // Thing being chased/attacked (or NULL), 00340 // also the originator for missiles. 00341 AActorPtr target; 00342 AActorPtr lastenemy; // Last known enemy -- killogh 2/15/98 00343 00344 // Reaction time: if non 0, don't attack yet. 00345 // Used by player to freeze a bit after teleporting. 00346 int reactiontime; 00347 00348 // If >0, the target will be chased 00349 // no matter what (even if shot) 00350 int threshold; 00351 00352 // Additional info record for player avatars only. 00353 // Only valid if type == MT_PLAYER 00354 player_s* player; 00355 00356 // Player number last looked for. 00357 unsigned int lastlook; 00358 00359 // For nightmare respawn. 00360 mapthing2_t spawnpoint; 00361 00362 // Thing being chased/attacked for tracers. 00363 AActorPtr tracer; 00364 byte special; // special 00365 byte args[5]; // special arguments 00366 00367 AActor *inext, *iprev; // Links to other mobjs in same bucket 00368 00369 // denis - playerids of players to whom this object has been sent 00370 std::vector<size_t> players_aware; 00371 00372 AActorPtr goal; // Monster's goal if not chasing anything 00373 byte *translation; // Translation table (or NULL) 00374 fixed_t translucency; // 65536=fully opaque, 0=fully invisible 00375 byte waterlevel; // 0=none, 1=feet, 2=waist, 3=eyes 00376 00377 fixed_t onground; // NES - Fixes infinite jumping bug like a charm. 00378 00379 // a linked list of sectors where this object appears 00380 struct msecnode_s *touching_sectorlist; // phares 3/14/98 00381 00382 short deadtic; // tics after player's death 00383 int oldframe; 00384 00385 unsigned char rndindex; // denis - because everything should have a random number generator, for prediction 00386 00387 // ThingIDs 00388 static void ClearTIDHashes (); 00389 void AddToHash (); 00390 void RemoveFromHash (); 00391 AActor *FindByTID (int tid) const; 00392 static AActor *FindByTID (const AActor *first, int tid); 00393 AActor *FindGoal (int tid, int kind) const; 00394 static AActor *FindGoal (const AActor *first, int tid, int kind); 00395 00396 int netid; // every object has its own netid 00397 short tid; // thing identifier 00398 00399 private: 00400 static AActor *TIDHash[128]; 00401 static inline int TIDHASH (int key) { return key & 127; } 00402 00403 public: 00404 void LinkToWorld (); 00405 void UnlinkFromWorld (); 00406 void SetOrigin (fixed_t x, fixed_t y, fixed_t z); 00407 00408 AActorPtr ptr(){ return AActorPtr(self); } 00409 }; 00410 00411 #endif 00412 00413 00414