1 // Emacs style mode select   -*- C++ -*-
2 //-----------------------------------------------------------------------------
3 //
4 // $Id: p_mobj.h 1367 2017-11-01 01:15:56Z wesleyjohnson $
5 //
6 // Copyright (C) 1993-1996 by id Software, Inc.
7 // Portions Copyright (C) 1998-2000 by DooM Legacy Team.
8 //
9 // This program is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU General Public License
11 // as published by the Free Software Foundation; either version 2
12 // of the License, or (at your option) any later version.
13 //
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 // GNU General Public License for more details.
18 //
19 //
20 // $Log: p_mobj.h,v $
21 // Revision 1.10  2004/07/27 08:19:37  exl
22 // New fmod, fs functions, bugfix or 2, patrol nodes
23 //
24 // Revision 1.9  2002/01/21 23:14:28  judgecutor
25 // Frag's Weapon Falling fixes
26 //
27 // Revision 1.8  2001/11/17 22:12:53  hurdler
28 // Ready to work on beta 4 ;)
29 //
30 // Revision 1.7  2001/02/24 13:35:20  bpereira
31 //
32 // Revision 1.6  2001/01/25 22:15:43  bpereira
33 // added heretic support
34 //
35 // Revision 1.5  2000/11/02 17:50:08  stroggonmeth
36 // Big 3Dfloors & FraggleScript commit!!
37 //
38 // Revision 1.4  2000/04/30 10:30:10  bpereira
39 //
40 // Revision 1.3  2000/04/04 00:32:47  stroggonmeth
41 // Initial Boom compatability plus few misc changes all around.
42 //
43 // Revision 1.2  2000/02/27 00:42:10  hurdler
44 // Revision 1.1.1.1  2000/02/22 20:32:32  hurdler
45 // Initial import into CVS (v1.29 pr3)
46 //
47 //
48 // DESCRIPTION:
49 //      Map Objects, MObj, definition and handling.
50 //
51 //-----------------------------------------------------------------------------
52 
53 #ifndef P_MOBJ_H
54 #define P_MOBJ_H
55 
56 #include "doomdef.h"
57   // NUMSKINCOLORS
58 #include "doomtype.h"
59 
60 // We need the WAD data structure for Map things,
61 // from the THINGS lump.
62 #include "doomdata.h"
63   // mapthing_t
64 
65 // States are tied to finite states are
66 //  tied to animation frames.
67 // Needs precompiled tables/data structures.
68 #include "info.h"
69 
70 // Basics.
71 #include "tables.h"
72 #include "m_fixed.h"
73 
74 // We need the thinker_t stuff.
75 #include "d_think.h"
76 
77 
78 
79 //
80 // NOTES: mobj_t
81 //
82 // mobj_ts are used to tell the refresh where to draw an image,
83 // tell the world simulation when objects are contacted,
84 // and tell the sound driver how to position a sound.
85 //
86 // The refresh uses the next and prev links to follow
87 // lists of things in sectors as they are being drawn.
88 // The sprite, frame, and angle elements determine which patch_t
89 // is used to draw the sprite if it is visible.
90 // The sprite and frame values are allmost allways set
91 // from state_t structures.
92 // The statescr.exe utility generates the states.h and states.c
93 // files that contain the sprite/frame numbers from the
94 // statescr.txt source file.
95 // The xyz origin point represents a point at the bottom middle
96 // of the sprite (between the feet of a biped).
97 // This is the default origin position for patch_ts grabbed
98 // with lumpy.exe.
99 // A walking creature will have its z equal to the floor
100 // it is standing on.
101 //
102 // The sound code uses the x,y, and subsector fields
103 // to do stereo positioning of any sound effited by the mobj_t.
104 //
105 // The play simulation uses the blocklinks, x,y,z, radius, height
106 // to determine when mobj_ts are touching each other,
107 // touching lines in the map, or hit by trace lines (gunshots,
108 // lines of sight, etc).
109 // The mobj_t->flags element has various bit flags
110 // used by the simulation.
111 //
112 // Every mobj_t is linked into a single sector
113 // based on its origin coordinates.
114 // The subsector_t is found with R_PointInSubsector(x,y),
115 // and the sector_t can be found with subsector->sector.
116 // The sector links are only used by the rendering code,
117 // the play simulation does not care about them at all.
118 //
119 // Any mobj_t that needs to be acted upon by something else
120 // in the play world (block movement, be shot, etc) will also
121 // need to be linked into the blockmap.
122 // If the thing has the MF_NOBLOCK flag set, it will not use
123 // the block links. It can still interact with other things,
124 // but only as the instigator (missiles will run into other
125 // things, but nothing can run into a missile).
126 // Each block in the grid is 128*128 units, and knows about
127 // every line_t that it contains a piece of, and every
128 // interactable mobj_t that has its origin contained.
129 //
130 // A valid mobj_t is a mobj_t that has the proper subsector_t
131 // filled in for its xy coordinates and is linked into the
132 // sector from which the subsector was made, or has the
133 // MF_NOSECTOR flag set (the subsector_t needs to be valid
134 // even if MF_NOSECTOR is set), and is linked into a blockmap
135 // block or has the MF_NOBLOCKMAP flag set.
136 // Links should only be modified by the P_[Un]SetThingPosition()
137 // functions.
138 // Do not change the MF_NO? flags while a thing is valid.
139 //
140 // Any questions?
141 //
142 
143 //
144 // Misc. mobj flags
145 //
146 typedef enum
147 {
148     // Call P_SpecialThing when touched.
149     MF_SPECIAL          = 0x0001,
150     // Blocks.
151     MF_SOLID            = 0x0002,
152     // Can be hit.
153     MF_SHOOTABLE        = 0x0004,
154     // Don't use the sector links (invisible but touchable).
155     MF_NOSECTOR         = 0x0008,
156     // Don't use the blocklinks (inert but displayable)
157     MF_NOBLOCKMAP       = 0x0010,
158 
159     // Not to be activated by sound, deaf monster.
160     MF_AMBUSH           = 0x0020,
161     // Will try to attack right back.
162     MF_JUSTHIT          = 0x0040,
163     // Will take at least one step before attacking.
164     MF_JUSTATTACKED     = 0x0080,
165     // On level spawning (initial position),
166     //  hang from ceiling instead of stand on floor.
167     MF_SPAWNCEILING     = 0x0100,
168     // Don't apply gravity (every tic),
169     //  that is, object will float, keeping current height
170     //  or changing it actively.
171     MF_NOGRAVITY        = 0x0200,
172 
173     // Movement flags.
174     // This allows jumps from high places.
175     MF_DROPOFF          = 0x0400,
176     // For players, will pick up items.
177     MF_PICKUP           = 0x0800,
178     // Player cheat. ???
179     MF_NOCLIP           = 0x1000,
180     // Player: keep info about sliding along walls.
181     MF_SLIDE            = 0x2000,
182     // Allow moves to any height, no gravity.
183     // For active floaters, e.g. cacodemons, pain elementals.
184     MF_FLOAT            = 0x4000,
185     // Don't cross lines
186     //   ??? or look at heights on teleport.
187     MF_TELEPORT         = 0x8000,
188     // Don't hit same species, explode on block.
189     // Player missiles as well as fireballs of various kinds.
190     MF_MISSILE          = 0x10000,
191     // Dropped by a demon, not level spawned.
192     // E.g. ammo clips dropped by dying former humans.
193     MF_DROPPED          = 0x20000,
194     // DOOM2: Use fuzzy draw (shadow demons or spectres),
195     //  temporary player invisibility powerup.
196     // LEGACY: no more for translucency, but still makes targeting harder
197     MF_SHADOW           = 0x40000,
198     // Flag: don't bleed when shot (use puff),
199     //  barrels and shootable furniture shall not bleed.
200     MF_NOBLOOD          = 0x80000,
201     // Don't stop moving halfway off a step,
202     //  that is, have dead bodies slide down all the way.
203     MF_CORPSE           = 0x100000,
204     // Floating to a height for a move, ???
205     //  don't auto float to target's height.
206     MF_INFLOAT          = 0x200000,
207 
208     // On kill, count this enemy object
209     //  towards intermission kill total.
210     // Happy gathering.
211     MF_COUNTKILL        = 0x400000,
212 
213     // On picking up, count this item object
214     //  towards intermission item total.
215     MF_COUNTITEM        = 0x800000,
216 
217     // Special handling: skull in flight.
218     // Neither a cacodemon nor a missile.
219     MF_SKULLFLY         = 0x1000000,
220 
221     // Don't spawn this object
222     //  in death match mode (e.g. key cards).
223     MF_NOTDMATCH        = 0x2000000,
224 
225     // MBF flags, in the position that MBF originally had them.
226     // This makes it easier to handle them in combination with other flags.
227     MF_TOUCHY           = 0x10000000, // killough 11/98: dies when solids touch it
228     MF_BOUNCES          = 0x20000000, // killough 7/11/98: for beta BFG fireballs
229     MF_FRIEND           = 0x40000000, // killough 7/18/98: friendly monsters
230 
231     MF_TRANSLUCENT      = 0x80000000,  // from boomdeh.txt, previously was FLOORHUGGER
232 } mobjflag_e;
233 
234 
235 typedef enum {
236     MF2_LOGRAV         =     0x00000001,      // alternate gravity setting
237     MF2_WINDTHRUST     =     0x00000002,      // gets pushed around by the wind
238                                               // specials
239     MF2_FLOORBOUNCE    =     0x00000004,      // bounces off the floor
240     MF2_THRUGHOST      =     0x00000008,      // missile will pass through ghosts
241     MF2_FLY            =     0x00000010,      // fly mode is active
242     MF2_FOOTCLIP       =     0x00000020,      // if feet are allowed to be clipped
243     MF2_SPAWNFLOAT     =     0x00000040,      // spawn random float z
244     MF2_NOTELEPORT     =     0x00000080,      // does not teleport
245     MF2_RIP            =     0x00000100,      // missile rips through solid
246                                               // targets
247     MF2_PUSHABLE       =     0x00000200,      // can be pushed by other moving
248                                               // mobjs
249     MF2_SLIDE          =     0x00000400,      // slides against walls
250     MF2_ONMOBJ         =     0x00000800,      // mobj is resting on top of another
251                                               // mobj
252     MF2_PASSMOBJ       =     0x00001000,      // Enable z block checking.  If on,
253                                               // this flag will allow the mobj to
254                                               // pass over/under other mobjs.
255     MF2_CANNOTPUSH     =     0x00002000,      // cannot push other pushable mobjs
256     MF2_FEETARECLIPPED =     0x00004000,      // a mobj's feet are now being cut
257     MF2_BOSS           =     0x00008000,      // mobj is a major boss
258     MF2_FIREDAMAGE     =     0x00010000,      // does fire damage
259     MF2_NODMGTHRUST    =     0x00020000,      // does not thrust target when
260                                               // damaging
261     MF2_TELESTOMP      =     0x00040000,      // mobj can stomp another
262     MF2_FLOATBOB       =     0x00080000,      // use float bobbing z movement
263     MF2_DONTDRAW       =     0x00100000,      // don't generate a vissprite
264 
265     // extra
266     MF2_FLOORHUGGER    =     0x00200000,      // stays on the floor
267 
268     // for chase camera, don't be blocked by things (partial clipping)
269     MF2_NOCLIPTHING    =     0x00400000,
270 } mobjflag2_e;
271 
272 
273 // [WDJ] Original flag positions, for deh, savegame fixes.
274 typedef enum {
275     // Player sprites in multiplayer modes are modified
276     //  using an internal color lookup table for re-indexing.
277     // If 0x4 0x8 or 0xc,
278     //  use a translation table for player colormaps
279     MFO_TRANSLATION2     = 0x0C000000,    // original 2color
280     MFO_TRANSLATION4     = 0x3C000000,    // 4color
281     MFO_TRANSSHIFT       = 26,  // to shift MF_TRANSLATION bits to INT
282 
283     // Earlier Legacy savegames only.
284     // for chase camera, don't be blocked by things (partial clipping)
285     MFO_NOCLIPTHING      = 0x40000000,
286 } old_mobjflag_e;
287 
288 
289 
290 // Translation Flags, and other displaced flags.
291 typedef enum {
292     // Player sprites in multiplayer modes are modified
293     // using an internal color lookup table for re-indexing.
294     // Use a translation table for player colormaps.
295     // Already shifted to indexing position, so MF_TO_SKINMAP has no shift.
296     MFT_TRANSLATION6     = 0x00003F00,    // 6 bit color
297     MFT_TRANSSHIFT       = 8,
298     // If MFT_TRANSSHIFT is changed, defines in r_draw.h must be fixed too.
299 } mobjtflag_e;
300 
301 
302 // Same friendness
303 // Used often in MBF.
304 // True if both FRIEND, or if both not FRIEND.
305 #define SAME_FRIEND(s,t)  ((((s)->flags ^ (t)->flags) & MF_FRIEND) == 0)
306 #define BOTH_FRIEND(s,t)  ((s)->flags & (t)->flags & MF_FRIEND)
307 
308 
309 //
310 //  New mobj extra flags
311 //
312 //added:28-02-98:
313 typedef enum
314 {
315     // The mobj stands on solid floor (not on another mobj or in air)
316     MF_ONGROUND          = 0x0001,
317     // The mobj just hit the floor while falling, this is cleared on next frame
318     // (instant damage in lava/slime sectors to prevent jump cheat..)
319     MF_JUSTHITFLOOR      = 0x0002,
320     // The mobj stands in a sector with water, and touches the surface
321     // this bit is set once and for all at the start of mobjthinker
322     MF_TOUCHWATER        = 0x0004,
323     // The mobj stands in a sector with water, and his waist is BELOW the water surface
324     // (for player, allows swimming up/down)
325     MF_UNDERWATER        = 0x0008,
326     // Set by P_MovePlayer() to disable gravity add in P_MobjThinker() ( for gameplay )
327     MF_SWIMMING          = 0x0010,
328     // used for client prediction code, player can't be blocked in z by walls
329     // it is set temporarely when player follow the spirit
330     MF_NOZCHECKING       = 0x0020,
331     // "Friendly"; the mobj ignores players
332     MF_IGNOREPLAYER	 = 0x0040,
333     // Actor will predict where the player will be
334     MF_PREDICT		 = 0x0080,
335   // MBF
336     // Object is falling.
337     MF_FALLING           = 0x0100,
338     // Object is armed for TOUCHY explode.
339     MF_ARMED             = 0x0200
340 } mobjeflag_e;
341 
342 
343 #if NUMSKINCOLORS > 16
344 #error MF_TRANSLATION can only handle NUMSKINCOLORS <= 16
345 #endif
346 
347 
348 // Map Object definition.
349 typedef struct mobj_s
350 {
351     // List: thinker links.
352     thinker_t           thinker;
353 
354     // Drawing position, and sound position.
355     // Must be identical to xyz_t, replaces use of degenmobj_t.
356     fixed_t             x, y, z;
357 
358     // Momentums, used to update position.
359     fixed_t             momx, momy, momz;
360 
361     // The closest interval over all contacted Sectors (or Things).
362     fixed_t             floorz;
363     fixed_t             ceilingz;
364     fixed_t             dropoffz;  // MBF, dropoff floor
365 
366     // For movement checking.
367     fixed_t             radius;
368     fixed_t             height;
369 
370     //More drawing info: to determine current sprite.
371     angle_t             angle;  // orientation
372     spritenum_t         sprite; // used to find patch_t and flip value
373     uint32_t            frame;  // frame number, plus bits see p_pspr.h
374 
375     // If == validcount, already checked.
376     //int                 validcount;
377 
378     uint32_t            flags;  // mobjflag_e
379     uint32_t            flags2; // heretic mobjflag2_e
380     uint32_t            tflags; // translation, drawing, settings, mobjtflag_e
381     uint32_t            eflags; //added:28-02-98: mobjeflag_e
382     int                 special1;
383     int                 special2;
384     int                 health;
385     int                 tics;   // state tic counter
386 
387     mobjtype_t          type;   // MT_*  (MT_PLAYER, MT_VILE, MT_BFG, etc.)
388 
389   // [WDJ] Better alignment if ptrs are kept together, and int16 are together.
390 
391     mobjinfo_t        * info;   // &mobjinfo[mobj->type]
392     state_t           * state;
393 
394     // More list: links in sector (if needed)
395     struct mobj_s     * snext;
396     struct mobj_s     * sprev;
397 
398     // Interaction info, by BLOCKMAP.
399     // Links in blocks (if needed).
400     struct mobj_s     * bnext;
401     struct mobj_s     * bprev;
402 
403     struct subsector_s* subsector;
404 
405     // a linked list of sectors where this object appears
406     struct msecnode_s * touching_sectorlist;
407 
408     //Fab:02-08-98
409     // Skin overrides 'sprite' when non NULL (currently hack for player
410     // bodies so they 'remember' the skin).
411     // Secondary use is when player die and we play the die sound.
412     // Problem is he has already respawn and want the corpse to
413     // play the sound !!! (yeah it happens :\)
414     void              * skin;
415 
416     // Thing being chased/attacked (or NULL),
417     // also the originator for missiles.
418   union {
419     struct mobj_s     * target;
420     uint32_t            target_id; // used during loading
421   };
422 
423     // Thing being chased/attacked for tracers.
424   union {
425     struct mobj_s     * tracer;
426     uint32_t            tracer_id; // used during loading
427   };
428 
429   union {
430     struct mobj_s     * lastenemy;    // MBF, last known enemy
431     uint32_t            lastenemy_id; // used during loading
432   };
433 
434     // Additional info record for player avatars only.
435     // Only valid if type == MT_PLAYER
436     struct player_s   * player;
437 
438     // For nightmare and itemrespawn respawn.
439     mapthing_t        * spawnpoint;
440 
441     // Nodes
442     struct mobj_s     * nextnode;   // Next node object to chase after touching
443                                     // current target (which must be MT_NODE).
444     struct mobj_s     * targetnode; // Target node to remember when encountering a player
445     int			nodescript; // Script to run when this node is touched
446     int			nodewait;   // How many ticks to wait at this node
447 
448     // Player number last looked for.
449     int8_t              lastlook;
450 
451     // Movement direction, movement generation (zig-zagging).
452     int8_t              movedir;      // 0-7
453     int16_t             movecount;    // when 0, select a new dir
454 
455     // Reaction time: if non 0, don't attack yet.
456     // Used by player to freeze a bit after teleporting.
457     int16_t             reactiontime;
458 
459     // If >0, the target will be chased no matter what (even if shot).
460     int16_t             threshold;
461     int16_t             strafecount;  // MBF, monster strafing
462     int16_t             pursuecount;  // MBF, how long to pursue
463     int16_t             tipcount;     // MBF, torque simulation (gear)
464 
465     //SoM: Friction.
466     int friction;
467     int movefactor;
468 
469     // Support for Frag Weapon Falling
470     // This field valid only for MF_DROPPED ammo and weapn objects
471     int dropped_ammo_count;
472 
473     // WARNING : new field are not automaticely added to save game
474 } mobj_t;
475 
476 
477 // check mobj against water content, before movement code
478 void P_MobjCheckWater (mobj_t* mobj);
479 
480 void P_SpawnMapthing (mapthing_t*  mthing);
481 // [WJD] spawn as playernum
482 void P_SpawnPlayer(mapthing_t * mthing, int playernum );
483 
484 int P_HitFloor(mobj_t *thing);
485 
486 
487 // Extra Mapthing
488 mapthing_t * P_Get_Extra_Mapthing( uint16_t flags );
489 void P_Free_Extra_Mapthing( mapthing_t * mthing );
490 void P_Clear_Extra_Mapthing( void );
491 
492 // Returns an index number for a mapthing, first index is 1
493 // Returns 0 if not found
494 unsigned int P_Extra_Mapthing_Index( mapthing_t * mtp );
495 
496 // Traverse all Extra Mapthing that are in use
497 mapthing_t * P_Traverse_Extra_Mapthing( mapthing_t * prev );
498 
499 // MBF
500 #define  SENTIENT(mo)  (((mo)->health > 0) && ((mo)->info->seestate))
501 
502 // killough 11/98:
503 // For torque simulation:
504 // MBF, PrBoom  TIPSHIFT=OVERDRIVE, MAXTIPCOUNT=MAXGEAR
505 #define TIPSHIFT     6
506 #define MAXTIPCOUNT  22
507 
508 #endif
509