p_mobj.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. /* Emacs style mode select -*- C++ -*-
  2. *-----------------------------------------------------------------------------
  3. *
  4. *
  5. * PrBoom: a Doom port merged with LxDoom and LSDLDoom
  6. * based on BOOM, a modified and improved DOOM engine
  7. * Copyright (C) 1999 by
  8. * id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman
  9. * Copyright (C) 1999-2000 by
  10. * Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze
  11. * Copyright 2005, 2006 by
  12. * Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License
  16. * as published by the Free Software Foundation; either version 2
  17. * of the License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  27. * 02111-1307, USA.
  28. *
  29. * DESCRIPTION:
  30. * Map Objects, MObj, definition and handling.
  31. *
  32. *-----------------------------------------------------------------------------*/
  33. #ifndef __P_MOBJ__
  34. #define __P_MOBJ__
  35. // Basics.
  36. #include "tables.h"
  37. #include "m_fixed.h"
  38. // We need the thinker_t stuff.
  39. #include "d_think.h"
  40. // We need the WAD data structure for Map things,
  41. // from the THINGS lump.
  42. #include "doomdata.h"
  43. // States are tied to finite states are
  44. // tied to animation frames.
  45. // Needs precompiled tables/data structures.
  46. #include "info.h"
  47. //
  48. // NOTES: mobj_t
  49. //
  50. // mobj_ts are used to tell the refresh where to draw an image,
  51. // tell the world simulation when objects are contacted,
  52. // and tell the sound driver how to position a sound.
  53. //
  54. // The refresh uses the next and prev links to follow
  55. // lists of things in sectors as they are being drawn.
  56. // The sprite, frame, and angle elements determine which patch_t
  57. // is used to draw the sprite if it is visible.
  58. // The sprite and frame values are allmost allways set
  59. // from state_t structures.
  60. // The statescr.exe utility generates the states.h and states.c
  61. // files that contain the sprite/frame numbers from the
  62. // statescr.txt source file.
  63. // The xyz origin point represents a point at the bottom middle
  64. // of the sprite (between the feet of a biped).
  65. // This is the default origin position for patch_ts grabbed
  66. // with lumpy.exe.
  67. // A walking creature will have its z equal to the floor
  68. // it is standing on.
  69. //
  70. // The sound code uses the x,y, and subsector fields
  71. // to do stereo positioning of any sound effited by the mobj_t.
  72. //
  73. // The play simulation uses the blocklinks, x,y,z, radius, height
  74. // to determine when mobj_ts are touching each other,
  75. // touching lines in the map, or hit by trace lines (gunshots,
  76. // lines of sight, etc).
  77. // The mobj_t->flags element has various bit flags
  78. // used by the simulation.
  79. //
  80. // Every mobj_t is linked into a single sector
  81. // based on its origin coordinates.
  82. // The subsector_t is found with R_PointInSubsector(x,y),
  83. // and the sector_t can be found with subsector->sector.
  84. // The sector links are only used by the rendering code,
  85. // the play simulation does not care about them at all.
  86. //
  87. // Any mobj_t that needs to be acted upon by something else
  88. // in the play world (block movement, be shot, etc) will also
  89. // need to be linked into the blockmap.
  90. // If the thing has the MF_NOBLOCK flag set, it will not use
  91. // the block links. It can still interact with other things,
  92. // but only as the instigator (missiles will run into other
  93. // things, but nothing can run into a missile).
  94. // Each block in the grid is 128*128 units, and knows about
  95. // every line_t that it contains a piece of, and every
  96. // interactable mobj_t that has its origin contained.
  97. //
  98. // A valid mobj_t is a mobj_t that has the proper subsector_t
  99. // filled in for its xy coordinates and is linked into the
  100. // sector from which the subsector was made, or has the
  101. // MF_NOSECTOR flag set (the subsector_t needs to be valid
  102. // even if MF_NOSECTOR is set), and is linked into a blockmap
  103. // block or has the MF_NOBLOCKMAP flag set.
  104. // Links should only be modified by the P_[Un]SetThingPosition()
  105. // functions.
  106. // Do not change the MF_NO? flags while a thing is valid.
  107. //
  108. // Any questions?
  109. //
  110. //
  111. // Misc. mobj flags
  112. //
  113. // Call P_SpecialThing when touched.
  114. #define MF_SPECIAL (uint_64_t)(0x0000000000000001)
  115. // Blocks.
  116. #define MF_SOLID (uint_64_t)(0x0000000000000002)
  117. // Can be hit.
  118. #define MF_SHOOTABLE (uint_64_t)(0x0000000000000004)
  119. // Don't use the sector links (invisible but touchable).
  120. #define MF_NOSECTOR (uint_64_t)(0x0000000000000008)
  121. // Don't use the blocklinks (inert but displayable)
  122. #define MF_NOBLOCKMAP (uint_64_t)(0x0000000000000010)
  123. // Not to be activated by sound, deaf monster.
  124. #define MF_AMBUSH (uint_64_t)(0x0000000000000020)
  125. // Will try to attack right back.
  126. #define MF_JUSTHIT (uint_64_t)(0x0000000000000040)
  127. // Will take at least one step before attacking.
  128. #define MF_JUSTATTACKED (uint_64_t)(0x0000000000000080)
  129. // On level spawning (initial position),
  130. // hang from ceiling instead of stand on floor.
  131. #define MF_SPAWNCEILING (uint_64_t)(0x0000000000000100)
  132. // Don't apply gravity (every tic),
  133. // that is, object will float, keeping current height
  134. // or changing it actively.
  135. #define MF_NOGRAVITY (uint_64_t)(0x0000000000000200)
  136. // Movement flags.
  137. // This allows jumps from high places.
  138. #define MF_DROPOFF (uint_64_t)(0x0000000000000400)
  139. // For players, will pick up items.
  140. #define MF_PICKUP (uint_64_t)(0x0000000000000800)
  141. // Player cheat. ???
  142. #define MF_NOCLIP (uint_64_t)(0x0000000000001000)
  143. // Player: keep info about sliding along walls.
  144. #define MF_SLIDE (uint_64_t)(0x0000000000002000)
  145. // Allow moves to any height, no gravity.
  146. // For active floaters, e.g. cacodemons, pain elementals.
  147. #define MF_FLOAT (uint_64_t)(0x0000000000004000)
  148. // Don't cross lines
  149. // ??? or look at heights on teleport.
  150. #define MF_TELEPORT (uint_64_t)(0x0000000000008000)
  151. // Don't hit same species, explode on block.
  152. // Player missiles as well as fireballs of various kinds.
  153. #define MF_MISSILE (uint_64_t)(0x0000000000010000)
  154. // Dropped by a demon, not level spawned.
  155. // E.g. ammo clips dropped by dying former humans.
  156. #define MF_DROPPED (uint_64_t)(0x0000000000020000)
  157. // Use fuzzy draw (shadow demons or spectres),
  158. // temporary player invisibility powerup.
  159. #define MF_SHADOW (uint_64_t)(0x0000000000040000)
  160. // Flag: don't bleed when shot (use puff),
  161. // barrels and shootable furniture shall not bleed.
  162. #define MF_NOBLOOD (uint_64_t)(0x0000000000080000)
  163. // Don't stop moving halfway off a step,
  164. // that is, have dead bodies slide down all the way.
  165. #define MF_CORPSE (uint_64_t)(0x0000000000100000)
  166. // Floating to a height for a move, ???
  167. // don't auto float to target's height.
  168. #define MF_INFLOAT (uint_64_t)(0x0000000000200000)
  169. // On kill, count this enemy object
  170. // towards intermission kill total.
  171. // Happy gathering.
  172. #define MF_COUNTKILL (uint_64_t)(0x0000000000400000)
  173. // On picking up, count this item object
  174. // towards intermission item total.
  175. #define MF_COUNTITEM (uint_64_t)(0x0000000000800000)
  176. // Special handling: skull in flight.
  177. // Neither a cacodemon nor a missile.
  178. #define MF_SKULLFLY (uint_64_t)(0x0000000001000000)
  179. // Don't spawn this object
  180. // in death match mode (e.g. key cards).
  181. #define MF_NOTDMATCH (uint_64_t)(0x0000000002000000)
  182. // Player sprites in multiplayer modes are modified
  183. // using an internal color lookup table for re-indexing.
  184. // If 0x4 0x8 or 0xc,
  185. // use a translation table for player colormaps
  186. #define MF_TRANSLATION (uint_64_t)(0x000000000c000000)
  187. #define MF_TRANSLATION1 (uint_64_t)(0x0000000004000000)
  188. #define MF_TRANSLATION2 (uint_64_t)(0x0000000008000000)
  189. // Hmm ???.
  190. #define MF_TRANSSHIFT 26
  191. #define MF_UNUSED2 (uint_64_t)(0x0000000010000000)
  192. #define MF_UNUSED3 (uint_64_t)(0x0000000020000000)
  193. // Translucent sprite? // phares
  194. #define MF_TRANSLUCENT (uint_64_t)(0x0000000040000000)
  195. // this is free LONGLONG(0x0000000100000000)
  196. // these are greater than an int. That's why the flags below are now uint_64_t
  197. #define MF_TOUCHY LONGLONG(0x0000000100000000)
  198. #define MF_BOUNCES LONGLONG(0x0000000200000000)
  199. #define MF_FRIEND LONGLONG(0x0000000400000000)
  200. // killough 9/15/98: Same, but internal flags, not intended for .deh
  201. // (some degree of opaqueness is good, to avoid compatibility woes)
  202. enum {
  203. MIF_FALLING = 1, // Object is falling
  204. MIF_ARMED = 2, // Object is armed (for MF_TOUCHY objects)
  205. };
  206. // Map Object definition.
  207. //
  208. //
  209. // killough 2/20/98:
  210. //
  211. // WARNING: Special steps must be taken in p_saveg.c if C pointers are added to
  212. // this mobj_s struct, or else savegames will crash when loaded. See p_saveg.c.
  213. // Do not add "struct mobj_s *fooptr" without adding code to p_saveg.c to
  214. // convert the pointers to ordinals and back for savegames. This was the whole
  215. // reason behind monsters going to sleep when loading savegames (the "target"
  216. // pointer was simply nullified after loading, to prevent Doom from crashing),
  217. // and the whole reason behind loadgames crashing on savegames of AV attacks.
  218. //
  219. // killough 9/8/98: changed some fields to shorts,
  220. // for better memory usage (if only for cache).
  221. /* cph 2006/08/28 - move Prev[XYZ] fields to the end of the struct. Add any
  222. * other new fields to the end, and make sure you don't break savegames! */
  223. typedef struct mobj_s
  224. {
  225. // List: thinker links.
  226. thinker_t thinker;
  227. // Info for drawing: position.
  228. fixed_t x;
  229. fixed_t y;
  230. fixed_t z;
  231. // More list: links in sector (if needed)
  232. struct mobj_s* snext;
  233. struct mobj_s** sprev; // killough 8/10/98: change to ptr-to-ptr
  234. //More drawing info: to determine current sprite.
  235. angle_t angle; // orientation
  236. spritenum_t sprite; // used to find patch_t and flip value
  237. int frame; // might be ORed with FF_FULLBRIGHT
  238. // Interaction info, by BLOCKMAP.
  239. // Links in blocks (if needed).
  240. struct mobj_s* bnext;
  241. struct mobj_s** bprev; // killough 8/11/98: change to ptr-to-ptr
  242. struct subsector_s* subsector;
  243. // The closest interval over all contacted Sectors.
  244. fixed_t floorz;
  245. fixed_t ceilingz;
  246. // killough 11/98: the lowest floor over all contacted Sectors.
  247. fixed_t dropoffz;
  248. // For movement checking.
  249. fixed_t radius;
  250. fixed_t height;
  251. // Momentums, used to update position.
  252. fixed_t momx;
  253. fixed_t momy;
  254. fixed_t momz;
  255. // If == validcount, already checked.
  256. int validcount;
  257. mobjtype_t type;
  258. mobjinfo_t* info; // &mobjinfo[mobj->type]
  259. int tics; // state tic counter
  260. state_t* state;
  261. uint_64_t flags;
  262. int intflags; // killough 9/15/98: internal flags
  263. int health;
  264. // Movement direction, movement generation (zig-zagging).
  265. short movedir; // 0-7
  266. short movecount; // when 0, select a new dir
  267. short strafecount; // killough 9/8/98: monster strafing
  268. // Thing being chased/attacked (or NULL),
  269. // also the originator for missiles.
  270. struct mobj_s* target;
  271. // Reaction time: if non 0, don't attack yet.
  272. // Used by player to freeze a bit after teleporting.
  273. short reactiontime;
  274. // If >0, the current target will be chased no
  275. // matter what (even if shot by another object)
  276. short threshold;
  277. // killough 9/9/98: How long a monster pursues a target.
  278. short pursuecount;
  279. short gear; // killough 11/98: used in torque simulation
  280. // Additional info record for player avatars only.
  281. // Only valid if type == MT_PLAYER
  282. struct player_s* player;
  283. // Player number last looked for.
  284. short lastlook;
  285. // For nightmare respawn.
  286. mapthing_t spawnpoint;
  287. // Thing being chased/attacked for tracers.
  288. struct mobj_s* tracer;
  289. // new field: last known enemy -- killough 2/15/98
  290. struct mobj_s* lastenemy;
  291. // killough 8/2/98: friction properties part of sectors,
  292. // not objects -- removed friction properties from here
  293. // e6y: restored friction properties here
  294. // Friction values for the sector the object is in
  295. int friction; // phares 3/17/98
  296. int movefactor;
  297. // a linked list of sectors where this object appears
  298. struct msecnode_s* touching_sectorlist; // phares 3/14/98
  299. fixed_t PrevX;
  300. fixed_t PrevY;
  301. fixed_t PrevZ;
  302. fixed_t pad; // cph - needed so I can get the size unambiguously on amd64
  303. // SEE WARNING ABOVE ABOUT POINTER FIELDS!!!
  304. } mobj_t;
  305. // External declarations (fomerly in p_local.h) -- killough 5/2/98
  306. #define VIEWHEIGHT (41*FRACUNIT)
  307. #define GRAVITY FRACUNIT
  308. #define MAXMOVE (30*FRACUNIT)
  309. #define ONFLOORZ INT_MIN
  310. #define ONCEILINGZ INT_MAX
  311. // Time interval for item respawning.
  312. #define ITEMQUESIZE 128
  313. #define FLOATSPEED (FRACUNIT*4)
  314. #define STOPSPEED (FRACUNIT/16)
  315. // killough 11/98:
  316. // For torque simulation:
  317. #define OVERDRIVE 6
  318. #define MAXGEAR (OVERDRIVE+16)
  319. // killough 11/98:
  320. // Whether an object is "sentient" or not. Used for environmental influences.
  321. #define sentient(mobj) ((mobj)->health > 0 && (mobj)->info->seestate)
  322. extern int iquehead;
  323. extern int iquetail;
  324. void P_RespawnSpecials(void);
  325. mobj_t *P_SpawnMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type);
  326. void P_RemoveMobj(mobj_t *th);
  327. boolean P_SetMobjState(mobj_t *mobj, statenum_t state);
  328. void P_MobjThinker(mobj_t *mobj);
  329. void P_SpawnPuff(fixed_t x, fixed_t y, fixed_t z);
  330. void P_SpawnBlood(fixed_t x, fixed_t y, fixed_t z, int damage);
  331. mobj_t *P_SpawnMissile(mobj_t *source, mobj_t *dest, mobjtype_t type);
  332. void P_SpawnPlayerMissile(mobj_t *source, mobjtype_t type);
  333. boolean P_IsDoomnumAllowed(int doomnum);
  334. void P_SpawnMapThing (const mapthing_t* mthing);
  335. void P_SpawnPlayer(int n, const mapthing_t *mthing);
  336. void P_CheckMissileSpawn(mobj_t*); // killough 8/2/98
  337. void P_ExplodeMissile(mobj_t*); // killough
  338. #endif