1 //----------------------------------------------------------------------------
2 //  EDGE Moving Object Header
3 //----------------------------------------------------------------------------
4 //
5 //  Copyright (c) 1999-2009  The EDGE Team.
6 //
7 //  This program is free software; you can redistribute it and/or
8 //  modify it under the terms of the GNU General Public License
9 //  as published by the Free Software Foundation; either version 2
10 //  of the License, or (at your option) any later version.
11 //
12 //  This program is distributed in the hope that it will be useful,
13 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 //  GNU General Public License for more details.
16 //
17 //----------------------------------------------------------------------------
18 //
19 //  Based on the DOOM source code, released by Id Software under the
20 //  following copyright:
21 //
22 //    Copyright (C) 1993-1996 by id Software, Inc.
23 //
24 //----------------------------------------------------------------------------
25 //
26 // IMPORTANT NOTE: Altering anything within the mobj_t will most likely
27 //                 require changes to p_saveg.c and the save-game object
28 //                 (savegmobj_t); if you experience any problems with
29 //                 savegames, check here!
30 //
31 
32 #ifndef __P_MOBJ_H__
33 #define __P_MOBJ_H__
34 
35 #include "ddf/types.h"
36 #include "m_math.h"
37 
38 // forward decl.
39 class atkdef_c;
40 class mobjtype_c;
41 class image_c;
42 class abstract_shader_c;
43 
44 struct mobj_s;
45 struct player_s;
46 struct rad_script_s;
47 struct region_properties_s;
48 struct state_s;
49 struct subsector_s;
50 struct touch_node_s;
51 
52 #define STOPSPEED   		0.07f
53 #define OOF_SPEED   		20.0f
54 
55 //
56 // NOTES: mobj_t
57 //
58 // mobj_ts are used to tell the refresh where to draw an image,
59 // tell the world simulation when objects are contacted,
60 // and tell the sound driver how to position a sound.
61 //
62 // The refresh uses the next and prev links to follow
63 // lists of things in sectors as they are being drawn.
64 // The sprite, frame, and angle elements determine which patch_t
65 // is used to draw the sprite if it is visible.
66 // The sprite and frame values are allmost always set
67 // from state_t structures.
68 //
69 // The statescr.exe utility generates the states.h and states.c
70 // files that contain the sprite/frame numbers from the
71 // statescr.txt source file.
72 //
73 // The xyz origin point represents a point at the bottom middle
74 // of the sprite (between the feet of a biped).
75 // This is the default origin position for patch_ts grabbed
76 // with lumpy.exe.
77 // A walking creature will have its z equal to the floor
78 // it is standing on.
79 //
80 // The sound code uses the x,y, and subsector fields
81 // to do stereo positioning of any sound effited by the mobj_t.
82 //
83 // The play simulation uses the blocklinks, x,y,z, radius, height
84 // to determine when mobj_ts are touching each other,
85 // touching lines in the map, or hit by trace lines (gunshots,
86 // lines of sight, etc).
87 // The mobj_t->flags element has various bit flags
88 // used by the simulation.
89 //
90 // Every mobj_t is linked into a single sector
91 // based on its origin coordinates.
92 // The subsector_t is found with R_PointInSubsector(x,y),
93 // and the sector_t can be found with subsector->sector.
94 // The sector links are only used by the rendering code,
95 // the play simulation does not care about them at all.
96 //
97 // Any mobj_t that needs to be acted upon by something else
98 // in the play world (block movement, be shot, etc) will also
99 // need to be linked into the blockmap.
100 // If the thing has the MF_NOBLOCK flag set, it will not use
101 // the block links. It can still interact with other things,
102 // but only as the instigator (missiles will run into other
103 // things, but nothing can run into a missile).
104 // Each block in the grid is 128*128 units, and knows about
105 // every line_t that it contains a piece of, and every
106 // interactable mobj_t that has its origin contained.
107 //
108 // A valid mobj_t is a mobj_t that has the proper subsector_t
109 // filled in for its xy coordinates and is linked into the
110 // sector from which the subsector was made, or has the
111 // MF_NOSECTOR flag set (the subsector_t needs to be valid
112 // even if MF_NOSECTOR is set), and is linked into a blockmap
113 // block or has the MF_NOBLOCKMAP flag set.
114 // Links should only be modified by the P_[Un]SetThingPosition()
115 // functions.
116 // Do not change the MF_NO? flags while a thing is valid.
117 //
118 // Any questions?
119 //
120 
121 // Directions
122 typedef enum
123 {
124 	DI_EAST,
125 	DI_NORTHEAST,
126 	DI_NORTH,
127 	DI_NORTHWEST,
128 	DI_WEST,
129 	DI_SOUTHWEST,
130 	DI_SOUTH,
131 	DI_SOUTHEAST,
132 
133 	DI_NODIR,
134 
135 	DI_SLOWTURN,
136 	DI_FASTTURN,
137 	DI_WALKING,
138 	DI_EVASIVE
139 }
140 dirtype_e;
141 
142 typedef struct
143 {
144 	// location on the map.  `z' can take the special values ONFLOORZ
145 	// and ONCEILINGZ.
146 	float x, y, z;
147 
148 	// direction thing faces
149 	angle_t angle;
150 	angle_t vertangle;
151 
152 	// type of thing
153 	const mobjtype_c *info;
154 
155 	// certain flags (mainly MF_AMBUSH).
156 	int flags;
157 
158 	// tag number (from Hexen map format)
159 	int tag;
160 }
161 spawnpoint_t;
162 
163 
164 struct position_c
165 {
166 public:
167 	float x, y, z;
168 };
169 
170 typedef struct dlight_state_s
171 {
172 	float r;  // radius
173 	float target;  // target radius
174 	rgbcol_t color;
175 ///--- const image_c *image;
176 	abstract_shader_c *shader;
177 }
178 dlight_state_t;
179 
180 
181 // Map Object definition.
182 typedef struct mobj_s mobj_t;
183 
184 struct mobj_s : public position_c
185 {
186 	const mobjtype_c *info;
187 
188 	angle_t angle;      // orientation
189 	angle_t vertangle;  // looking up or down
190 
191 	// For movement checking.
192 	float radius;
193 	float height;
194 
195 	// Momentum, used to update position.
196 	vec3_t mom;
197 
198 	// current subsector
199 	struct subsector_s *subsector;
200 
201 	// properties from extrafloor the thing is in
202 	struct region_properties_s *props;
203 
204 	// The closest interval over all contacted Sectors.
205 	float floorz;
206 	float ceilingz;
207 	float dropoffz;
208 
209 	// This is the current speed of the object.
210 	// if fastparm, it is already calculated.
211 	float speed;
212 	int fuse;
213 
214 	// Thing's health level
215 	float health;
216 
217 	// state tic counter
218 	int tics;
219 	int tic_skip;
220 
221 	const struct state_s *state;
222 	const struct state_s *next_state;
223 
224 	// flags (Old and New)
225 	int flags;
226 	int extendedflags;
227 	int hyperflags;
228 
229 	int model_skin;
230 	int model_last_frame;
231 
232 	// tag ID (for special operations)
233 	int tag;
234 
235 	// Movement direction, movement generation (zig-zagging).
236 	dirtype_e movedir;  // 0-7
237 
238 	// when 0, select a new dir
239 	int movecount;
240 
241 	// Reaction time: if non 0, don't attack yet.
242 	// Used by player to freeze a bit after teleporting.
243 	int reactiontime;
244 
245 	// If >0, the target will be chased
246 	// no matter what (even if shot)
247 	int threshold;
248 
249 	// Additional info record for player avatars only.
250 	struct player_s *player;
251 
252 	// Player number last looked for.
253 	int lastlook;
254 
255 	// For respawning.
256 	spawnpoint_t spawnpoint;
257 
258 	float origheight;
259 
260 	// current visibility and target visibility
261 	float visibility;
262 	float vis_target;
263 
264 	// current attack to be made
265 	const atkdef_c *currentattack;
266 
267 	// spread count for Ordered spreaders
268 	int spreadcount;
269 
270 	// If == validcount, already checked.
271 	int validcount;
272 
273 	// -ES- 1999/10/25 Reference Count. DO NOT TOUCH.
274 	// All the following mobj references should be set only
275 	// through P_MobjSetX, where X is the field name. This is useful because
276 	// it sets the pointer to NULL if the mobj is removed, this protects us
277 	// from a crash.
278 	int refcount;
279 
280 	// source of the mobj, used for projectiles (i.e. the shooter)
281 	mobj_t * source;
282 
283 	// target of the mobj
284 	mobj_t * target;
285 
286 	// current spawned fire of the mobj
287 	mobj_t * tracer;
288 
289 	// if exists, we are supporting/helping this object
290 	mobj_t * supportobj;
291 	int side;
292 
293 	// objects that is above and below this one.  If there were several,
294 	// then the closest one (in Z) is chosen.  We are riding the below
295 	// object if the head height == our foot height.  We are being
296 	// ridden if our head == the above object's foot height.
297 	//
298 	mobj_t * above_mo;
299 	mobj_t * below_mo;
300 
301 	// these delta values give what position from the ride_em thing's
302 	// center that we are sitting on.
303 	float ride_dx, ride_dy;
304 
305 	// -AJA- 1999/09/25: Path support.
306 	struct rad_script_s *path_trigger;
307 
308 	// if we're on a ladder, this is the linedef #, otherwise -1.
309 	int on_ladder;
310 
311 	dlight_state_t dlight;
312 
313 	// monster reload support: count the number of shots
314 	int shot_count;
315 
316 	// hash values for TUNNEL missiles
317 	u32_t tunnel_hash[2];
318 
319 	// position interpolation (disabled when lerp_num <= 1)
320 	short lerp_num;
321 	short lerp_pos;
322 
323 	vec3_t lerp_from;
324 
325 	// touch list: sectors this thing is in or touches
326 	struct touch_node_s *touch_sectors;
327 
328 	// linked list (mobjlisthead)
329 	mobj_t *next, *prev;
330 
331 	// Interaction info, by BLOCKMAP.
332 	// Links in blocks (if needed).
333 	mobj_t *bnext, *bprev;
334 
335 	// More list: links in subsector (if needed)
336 	mobj_t *snext, *sprev;
337 
338 	// One more: link in dynamic light blockmap
339 	mobj_t *dlnext, *dlprev;
340 
341 public:
isRemovedmobj_s342 	inline bool isRemoved() const
343 	{
344 		return (state == NULL);
345 	}
346 
347 	void SetTracer(mobj_t *ref);
348 	void SetSource(mobj_t *ref);
349 	void SetTarget(mobj_t *ref);
350 	void SetSupportObj(mobj_t *ref);
351 	void SetAboveMo(mobj_t *ref);
352 	void SetBelowMo(mobj_t *ref);
353 	void SetRealSource(mobj_t *ref);
354 
355 	void ClearStaleRefs();
356 };
357 
358 // Item-in-Respawn-que Structure -ACB- 1998/07/30
359 typedef struct iteminque_s
360 {
361 	spawnpoint_t spawnpoint;
362 	int time;
363 	struct iteminque_s *next;
364 	struct iteminque_s *prev;
365 }
366 iteminque_t;
367 
368 // useful macro for the vertical center of an object
369 #define MO_MIDZ(mo)  ((mo)->z + (mo)->height / 2)
370 
371 #endif  /*__P_MOBJ_H__*/
372 
373 //--- editor settings ---
374 // vi:ts=4:sw=4:noexpandtab
375