p_mobj.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  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 (unsigned int)(0x0000000000000001)
  115. // Blocks.
  116. #define MF_SOLID (unsigned int)(0x0000000000000002)
  117. // Can be hit.
  118. #define MF_SHOOTABLE (unsigned int)(0x0000000000000004)
  119. // Don't use the sector links (invisible but touchable).
  120. #define MF_NOSECTOR (unsigned int)(0x0000000000000008)
  121. // Don't use the blocklinks (inert but displayable)
  122. #define MF_NOBLOCKMAP (unsigned int)(0x0000000000000010)
  123. // Not to be activated by sound, deaf monster.
  124. #define MF_AMBUSH (unsigned int)(0x0000000000000020)
  125. // Will try to attack right back.
  126. #define MF_JUSTHIT (unsigned int)(0x0000000000000040)
  127. // Will take at least one step before attacking.
  128. #define MF_JUSTATTACKED (unsigned int)(0x0000000000000080)
  129. // On level spawning (initial position),
  130. // hang from ceiling instead of stand on floor.
  131. #define MF_SPAWNCEILING (unsigned int)(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 (unsigned int)(0x0000000000000200)
  136. // Movement flags.
  137. // This allows jumps from high places.
  138. #define MF_DROPOFF (unsigned int)(0x0000000000000400)
  139. // For players, will pick up items.
  140. #define MF_PICKUP (unsigned int)(0x0000000000000800)
  141. // Player cheat. ???
  142. #define MF_NOCLIP (unsigned int)(0x0000000000001000)
  143. // Player: keep info about sliding along walls.
  144. #define MF_SLIDE (unsigned int)(0x0000000000002000)
  145. // Allow moves to any height, no gravity.
  146. // For active floaters, e.g. cacodemons, pain elementals.
  147. #define MF_FLOAT (unsigned int)(0x0000000000004000)
  148. // Don't cross lines
  149. // ??? or look at heights on teleport.
  150. #define MF_TELEPORT (unsigned int)(0x0000000000008000)
  151. // Don't hit same species, explode on block.
  152. // Player missiles as well as fireballs of various kinds.
  153. #define MF_MISSILE (unsigned int)(0x0000000000010000)
  154. // Dropped by a demon, not level spawned.
  155. // E.g. ammo clips dropped by dying former humans.
  156. #define MF_DROPPED (unsigned int)(0x0000000000020000)
  157. // Use fuzzy draw (shadow demons or spectres),
  158. // temporary player invisibility powerup.
  159. #define MF_SHADOW (unsigned int)(0x0000000000040000)
  160. // Flag: don't bleed when shot (use puff),
  161. // barrels and shootable furniture shall not bleed.
  162. #define MF_NOBLOOD (unsigned int)(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 (unsigned int)(0x0000000000100000)
  166. // Floating to a height for a move, ???
  167. // don't auto float to target's height.
  168. #define MF_INFLOAT (unsigned int)(0x0000000000200000)
  169. // On kill, count this enemy object
  170. // towards intermission kill total.
  171. // Happy gathering.
  172. #define MF_COUNTKILL (unsigned int)(0x0000000000400000)
  173. // On picking up, count this item object
  174. // towards intermission item total.
  175. #define MF_COUNTITEM (unsigned int)(0x0000000000800000)
  176. // Special handling: skull in flight.
  177. // Neither a cacodemon nor a missile.
  178. #define MF_SKULLFLY (unsigned int)(0x0000000001000000)
  179. // Don't spawn this object
  180. // in death match mode (e.g. key cards).
  181. #define MF_NOTDMATCH (unsigned int)(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 (unsigned int)(0x000000000c000000)
  187. #define MF_TRANSLATION1 (unsigned int)(0x0000000004000000)
  188. #define MF_TRANSLATION2 (unsigned int)(0x0000000008000000)
  189. // Hmm ???.
  190. #define MF_TRANSSHIFT 26
  191. #define MF_UNUSED2 (unsigned int)(0x0000000010000000)
  192. #define MF_UNUSED3 (unsigned int)(0x0000000020000000)
  193. // Translucent sprite? // phares
  194. #define MF_TRANSLUCENT (unsigned int)(0x0000000040000000)
  195. #define MF_FRIEND (unsigned int)(0x0000000080000000)
  196. // killough 9/15/98: Same, but internal flags, not intended for .deh
  197. // (some degree of opaqueness is good, to avoid compatibility woes)
  198. enum {
  199. MIF_FALLING = 1 // Object is falling
  200. };
  201. // Map Object definition.
  202. //
  203. //
  204. // killough 2/20/98:
  205. //
  206. // WARNING: Special steps must be taken in p_saveg.c if C pointers are added to
  207. // this mobj_s struct, or else savegames will crash when loaded. See p_saveg.c.
  208. // Do not add "struct mobj_s *fooptr" without adding code to p_saveg.c to
  209. // convert the pointers to ordinals and back for savegames. This was the whole
  210. // reason behind monsters going to sleep when loading savegames (the "target"
  211. // pointer was simply nullified after loading, to prevent Doom from crashing),
  212. // and the whole reason behind loadgames crashing on savegames of AV attacks.
  213. //
  214. // killough 9/8/98: changed some fields to shorts,
  215. // for better memory usage (if only for cache).
  216. /* cph 2006/08/28 - move Prev[XYZ] fields to the end of the struct. Add any
  217. * other new fields to the end, and make sure you don't break savegames! */
  218. typedef struct mobj_s
  219. {
  220. // List: thinker links.
  221. thinker_t thinker;
  222. // Info for drawing: position.
  223. fixed_t x;
  224. fixed_t y;
  225. fixed_t z;
  226. // More list: links in sector (if needed)
  227. struct mobj_s* snext;
  228. struct mobj_s** sprev; // killough 8/10/98: change to ptr-to-ptr
  229. //More drawing info: to determine current sprite.
  230. angle_t angle; // orientation
  231. unsigned short sprite; // used to find patch_t and flip value
  232. unsigned short frame; // might be ORed with FF_FULLBRIGHT
  233. // Interaction info, by BLOCKMAP.
  234. // Links in blocks (if needed).
  235. struct mobj_s* bnext;
  236. struct mobj_s** bprev; // killough 8/11/98: change to ptr-to-ptr
  237. struct subsector_s* subsector;
  238. // The closest interval over all contacted Sectors.
  239. fixed_t floorz;
  240. fixed_t ceilingz;
  241. // killough 11/98: the lowest floor over all contacted Sectors.
  242. fixed_t dropoffz;
  243. // For movement checking.
  244. fixed_t radius;
  245. fixed_t height;
  246. // Momentums, used to update position.
  247. fixed_t momx;
  248. fixed_t momy;
  249. fixed_t momz;
  250. short health;
  251. unsigned short type;
  252. int tics; // state tic counter
  253. const state_t* state;
  254. unsigned int flags;
  255. // Thing being chased/attacked (or NULL),
  256. // also the originator for missiles.
  257. struct mobj_s* target;
  258. // Movement direction, movement generation (zig-zagging).
  259. unsigned short movedir: 4;
  260. // If >0, the current target will be chased no
  261. // matter what (even if shot by another object)
  262. unsigned short threshold:8;
  263. // killough 9/9/98: How long a monster pursues a target.
  264. unsigned short pursuecount;
  265. short movecount; // when 0, select a new dir
  266. // Reaction time: if non 0, don't attack yet.
  267. // Used by player to freeze a bit after teleporting.
  268. short reactiontime;
  269. // Thing being chased/attacked for tracers.
  270. struct mobj_s* tracer;
  271. // new field: last known enemy -- killough 2/15/98
  272. struct mobj_s* lastenemy;
  273. // phares 3/17/98
  274. // a linked list of sectors where this object appears
  275. struct msecnode_s* touching_sectorlist; // phares 3/14/98
  276. // SEE WARNING ABOVE ABOUT POINTER FIELDS!!!
  277. } mobj_t;
  278. // External declarations (fomerly in p_local.h) -- killough 5/2/98
  279. #define VIEWHEIGHT (41*FRACUNIT)
  280. #define GRAVITY FRACUNIT
  281. #define MAXMOVE (30*FRACUNIT)
  282. #define ONFLOORZ INT_MIN
  283. #define ONCEILINGZ INT_MAX
  284. // Time interval for item respawning.
  285. #define ITEMQUESIZE 32
  286. #define FLOATSPEED (FRACUNIT*4)
  287. #define STOPSPEED (FRACUNIT/16)
  288. // killough 11/98:
  289. // For torque simulation:
  290. #define OVERDRIVE 6
  291. #define MAXGEAR (OVERDRIVE+16)
  292. // killough 11/98:
  293. // Whether an object is "sentient" or not. Used for environmental influences.
  294. #define sentient(mobj) ((mobj)->health > 0 && (mobj)->info->seestate)
  295. void P_RespawnSpecials(void);
  296. mobj_t *P_SpawnMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type);
  297. void P_RemoveMobj(mobj_t *th);
  298. boolean P_SetMobjState(mobj_t *mobj, statenum_t state);
  299. void P_MobjThinker(mobj_t *mobj);
  300. void P_MobjBrainlessThinker(mobj_t* mobj);
  301. void P_SpawnPuff(fixed_t x, fixed_t y, fixed_t z);
  302. void P_SpawnBlood(fixed_t x, fixed_t y, fixed_t z, int damage);
  303. mobj_t *P_SpawnMissile(mobj_t *source, mobj_t *dest, mobjtype_t type);
  304. void P_SpawnPlayerMissile(mobj_t *source, mobjtype_t type);
  305. boolean P_IsDoomnumAllowed(int doomnum);
  306. void P_SpawnMapThing (const mapthing_t* mthing);
  307. void P_SpawnPlayer(int n, const mapthing_t *mthing);
  308. void P_CheckMissileSpawn(mobj_t*); // killough 8/2/98
  309. void P_ExplodeMissile(mobj_t*); // killough
  310. struct player_s* P_MobjIsPlayer(const mobj_t* mobj);
  311. #endif