1 /**\file
2  *\section License
3  * License: GPL
4  * Online License Link: http://www.gnu.org/licenses/gpl.html
5  *
6  *\author Copyright © 2003-2017 Jaakko Keränen <jaakko.keranen@iki.fi>
7  *\author Copyright © 2005-2013 Daniel Swanson <danij@dengine.net>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (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  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor,
22  * Boston, MA  02110-1301  USA
23  */
24 
25 /**
26  * p_xgline.h:
27  */
28 
29 // Extended Generalized Line Types
30 #ifndef __XG_LINETYPE_H__
31 #define __XG_LINETYPE_H__
32 
33 #include "doomsday.h"
34 #include <doomsday/world/xgclass.h>
35 
36 #ifdef __cplusplus
37 class MapStateReader;
38 class MapStateWriter;
39 #endif
40 
41 // Line type classes. Add new classes to the end!
42 enum
43 {
44     LTC_NONE, // No action.
45     LTC_CHAIN_SEQUENCE,
46     LTC_PLANE_MOVE,
47     LTC_BUILD_STAIRS,
48     LTC_DAMAGE,
49     LTC_POWER,
50     LTC_LINE_TYPE,
51     LTC_SECTOR_TYPE,
52     LTC_SECTOR_LIGHT,
53     LTC_ACTIVATE,
54     LTC_KEY,
55     LTC_MUSIC, // Change the music to play.
56     LTC_LINE_COUNT, // Line activation count delta.
57     LTC_LEAVE_MAP,
58     LTC_DISABLE_IF_ACTIVE,
59     LTC_ENABLE_IF_ACTIVE,
60     LTC_EXPLODE, // Explodes the activator.
61     LTC_PLANE_MATERIAL,
62     LTC_WALL_MATERIAL,
63     LTC_COMMAND,
64     LTC_SOUND, // Play a sector sound.
65     LTC_MIMIC_SECTOR,
66     LTC_TELEPORT,
67     LTC_LINE_TELEPORT,
68     NUMXGCLASSES
69 };
70 
71 // Line events.
72 #define XLE_CHAIN           0x001
73 #define XLE_CROSS           0x002
74 #define XLE_USE             0x004
75 #define XLE_SHOOT           0x008
76 #define XLE_HIT             0x010
77 #define XLE_TICKER          0x020
78 // These two arn't real line events
79 #define XLE_AUTO            0x040
80 #define XLE_FORCED          0x080
81 
82 // Treated as XLE_CHAIN (class "do" funcs use it to determine when a "real"
83 // activator isn't present.
84 #define XLE_FUNC            0x100
85 
86 // Time conversion.
87 #define FLT2TIC(x)          ( (int) ((x)*35) )
88 #define TIC2FLT(x)          ( (x)/35.0f )
89 
90 // Line type definition flags.
91 #define LTF_ACTIVE          0x00000001 // Active in the beginning of a map.
92 
93 // Activation method. Line is activated if any of the following
94 // situations take place.
95 #define LTF_PLAYER_USE_A    0x00000002 // Player uses.
96 #define LTF_OTHER_USE_A     0x00000004 // Nonplayers can activate with use.
97 #define LTF_PLAYER_SHOOT_A  0x00000008 // Player shoots it.
98 #define LTF_OTHER_SHOOT_A   0x00000010 // Non-player thing shoots it.
99 #define LTF_ANY_CROSS_A     0x00000020 // Any mobj.
100 #define LTF_MONSTER_CROSS_A 0x00000040 // Flagged Countkill.
101 #define LTF_PLAYER_CROSS_A  0x00000080 // Player crosses the line.
102 #define LTF_MISSILE_CROSS_A 0x00000100 // Missile crosses the line.
103 #define LTF_PLAYER_HIT_A    0x00000200 // Player hits the line (walks into).
104 #define LTF_OTHER_HIT_A     0x00000400 // Nonplayer hits the line.
105 #define LTF_MONSTER_HIT_A   0x00000800 // Monster hits the line.
106 #define LTF_MISSILE_HIT_A   0x00001000 // Missile collides with the line.
107 #define LTF_ANY_HIT_A       0x00002000 // Any mobj collides with the line.
108 
109 // Deactivating by colliding with the line.
110 #define LTF_PLAYER_USE_D    0x00004000 // Player uses.
111 #define LTF_OTHER_USE_D     0x00008000 // Nonplayers can activate with use.
112 #define LTF_PLAYER_SHOOT_D  0x00010000 // Player shoots it.
113 #define LTF_OTHER_SHOOT_D   0x00020000 // Non-player thing shoots it.
114 #define LTF_ANY_CROSS_D     0x00040000 // Any mobj.
115 #define LTF_MONSTER_CROSS_D 0x00080000 // Flagged Countkill.
116 #define LTF_PLAYER_CROSS_D  0x00100000 // Player crosses the line.
117 #define LTF_MISSILE_CROSS_D 0x00200000 // Missile crosses the line.
118 #define LTF_PLAYER_HIT_D    0x00400000 // Player hits the line (walks into).
119 #define LTF_OTHER_HIT_D     0x00800000 // Nonplayer hits the line.
120 #define LTF_MONSTER_HIT_D   0x01000000 // Monster hits the line.
121 #define LTF_MISSILE_HIT_D   0x02000000 // Missile collides with the line.
122 #define LTF_ANY_HIT_D       0x04000000 // Any mobj collides with the line.
123 
124 // A+D activation methods. (A and D flags combined.)
125 #define LTF_PLAYER_USE      0x00004002 // Player uses.
126 #define LTF_OTHER_USE       0x00008004 // Non-player uses.
127 #define LTF_PLAYER_SHOOT    0x00010008 // Player shoots it.
128 #define LTF_OTHER_SHOOT     0x00020010 // Non-player thing shoots it.
129 #define LTF_ANY_CROSS       0x00040020 // Any mobj.
130 #define LTF_MONSTER_CROSS   0x00080040 // Flagged Countkill.
131 #define LTF_PLAYER_CROSS    0x00100080 // Player crosses the line.
132 #define LTF_MISSILE_CROSS   0x00200100 // Missile crosses the line.
133 #define LTF_PLAYER_HIT      0x00400200 // Player hits the line (walks into).
134 #define LTF_OTHER_HIT       0x00800400 // Nonplayer hits the line.
135 #define LTF_MONSTER_HIT     0x01000800 // Monster hits the line.
136 #define LTF_MISSILE_HIT     0x02001000 // Missile collides with the line.
137 #define LTF_ANY_HIT         0x04002000 // Any mobj collides with the line.
138 
139 // Special activation methods/requirements.
140 #define LTF_TICKER_A            0x08000000 // Activate on ticker.
141 #define LTF_TICKER_D            0x10000000 // Deactivate on ticker.
142 #define LTF_TICKER              0x18000000 // A+D on ticker.
143 #define LTF_MOBJ_GONE           0x20000000 // a9 specifies mobj type
144 #define LTF_NO_OTHER_USE_SECRET 0x40000000 // Nonplr can't use line if secret
145 #define LTF_ACTIVATOR_TYPE      0x80000000 // a9 specifies mobj type
146 
147 // When to do effect?
148 #define LTF2_WHEN_ACTIVATED     0x00000001
149 #define LTF2_WHEN_DEACTIVATED   0x00000002
150 #define LTF2_WHEN_ACTIVE        0x00000004
151 #define LTF2_WHEN_INACTIVE      0x00000008
152 #define LTF2_WHEN_LAST          0x00000010 // Only do effects when count=1.
153 
154 // Activation requirements.
155 #define LTF2_KEY(n)         (1<<(5+n))
156 #define LTF2_KEY1           0x00000020
157 #define LTF2_KEY2           0x00000040
158 #define LTF2_KEY3           0x00000080
159 #define LTF2_KEY4           0x00000100
160 #define LTF2_KEY5           0x00000200
161 #define LTF2_KEY6           0x00000400
162 #define LTF2_LINE_ACTIVE    0x00000800 // line ref: a4 + a5
163 #define LTF2_LINE_INACTIVE  0x00001000 // line ref: a6 + a7
164 #define LTF2_COLOR          0x00002000 // a8: activator's color.
165 
166 // Continued in flags2.
167 #define LTF2_HEALTH_ABOVE   0x00004000 // a0 (activator health)
168 #define LTF2_HEALTH_BELOW   0x00008000 // a1
169 #define LTF2_POWER_ABOVE    0x00010000 // a2 (activator power)
170 #define LTF2_POWER_BELOW    0x00020000 // a3
171 #define LTF2_SINGLEPLAYER   0x00040000
172 #define LTF2_COOPERATIVE    0x00080000
173 #define LTF2_DEATHMATCH     0x00100000
174 #define LTF2_ANY_MODE       0x001c0000 // Singleplayer, coop and DM combined.
175 #define LTF2_EASY           0x00200000
176 #define LTF2_MED            0x00400000
177 #define LTF2_HARD           0x00800000
178 #define LTF2_ANY_SKILL      0x00e00000 // Easy/med/hard combined.
179 #define LTF2_SKILL_SHIFT    21 // 1<<this == easy
180 
181 // Extra features.
182 #define LTF2_MULTIPLE       0x01000000 // Copy act state to tagged lines
183 #define LTF2_TWOSIDED       0x02000000 // Allow use/shoot from both sides.
184 #define LTF2_GLOBAL_A_MSG   0x04000000 // Actmsg to all players.
185 #define LTF2_GLOBAL_D_MSG   0x08000000 // Deactmsg to all players.
186 #define LTF2_GLOBAL_MSG     0x0c000000 // A+D msg to all players.
187 #define LTF2_GROUP_ACT      0x10000000 // Act all tag-matching lines
188 #define LTF2_GROUP_DEACT    0x20000000 // Deact all tag-matching lines
189 #define LTF2_OVERRIDE_ANY   0x40000000 // Override BOOM's "Any Trigger" line flag
190 
191 #define LTACT_CNT_INFINITE  -1 // Activate infinite number of times.
192 
193 enum // Activation types.
194 {
195     // When on, count to off. Can be activated when off.
196     LTACT_COUNTED_OFF,
197 
198     // When off, count to on. Can be activated when on.
199     LTACT_COUNTED_ON,
200 
201     // Flip between on/off. Can be activated at any time.
202     LTACT_FLIP,
203 
204     // When on, count to off. Can be (de)activated at any time.
205     LTACT_FLIP_COUNTED_OFF,
206 
207     // When off, count to on. Can be (de)activated at any time.
208     LTACT_FLIP_COUNTED_ON,
209 };
210 
211 enum // Wall sections.
212 {
213     LWS_NONE,
214     LWS_MID,
215     LWS_UPPER,
216     LWS_LOWER
217 };
218 
219 enum // Line reference type.
220 {
221     LREF_NONE,
222     LREF_SELF,
223     LREF_TAGGED,
224     LREF_LINE_TAGGED,
225     LREF_ACT_TAGGED,
226     LREF_INDEX,
227     LREF_ALL
228 };
229 
230 enum // Line -> Plane reference type.
231 {
232     LPREF_NONE,
233 
234     LPREF_MY_FLOOR,
235     LPREF_TAGGED_FLOORS,
236     LPREF_LINE_TAGGED_FLOORS,
237     LPREF_ACT_TAGGED_FLOORS,
238     LPREF_INDEX_FLOOR,
239     LPREF_ALL_FLOORS,
240 
241     LPREF_MY_CEILING,
242     LPREF_TAGGED_CEILINGS,
243     LPREF_LINE_TAGGED_CEILINGS,
244     LPREF_ACT_TAGGED_CEILINGS,
245     LPREF_INDEX_CEILING,
246     LPREF_ALL_CEILINGS,
247 
248     LPREF_SPECIAL, // 2nd param of reference treated in a special way.
249     LPREF_BACK_FLOOR,
250     LPREF_BACK_CEILING,
251     LPREF_THING_EXIST_FLOORS,
252     LPREF_THING_EXIST_CEILINGS,
253     LPREF_THING_NOEXIST_FLOORS,
254     LPREF_THING_NOEXIST_CEILINGS,
255 
256     // Line -> Sector references (same as ->Plane, really).
257     LSREF_NONE = LPREF_NONE,
258     LSREF_MY,
259     LSREF_TAGGED,
260     LSREF_LINE_TAGGED,
261     LSREF_ACT_TAGGED,
262     LSREF_INDEX,
263     LSREF_ALL,
264     LSREF_BACK = LPREF_BACK_FLOOR,
265     LSREF_THING_EXIST = LPREF_THING_EXIST_FLOORS,
266     LSREF_THING_NOEXIST = LPREF_THING_NOEXIST_FLOORS
267 };
268 
269 enum // Sector -> Plane reference type.
270 {
271     SPREF_NONE,
272     SPREF_MY_FLOOR,
273     SPREF_MY_CEILING,
274     SPREF_ORIGINAL_FLOOR,
275     SPREF_ORIGINAL_CEILING,
276     SPREF_CURRENT_FLOOR,
277     SPREF_CURRENT_CEILING,
278     SPREF_HIGHEST_FLOOR,
279     SPREF_HIGHEST_CEILING,
280     SPREF_LOWEST_FLOOR,
281     SPREF_LOWEST_CEILING,
282     SPREF_NEXT_HIGHEST_FLOOR,
283     SPREF_NEXT_HIGHEST_CEILING,
284     SPREF_NEXT_LOWEST_FLOOR,
285     SPREF_NEXT_LOWEST_CEILING,
286     SPREF_MIN_BOTTOM_MATERIAL,
287     SPREF_MIN_MID_MATERIAL,
288     SPREF_MIN_TOP_MATERIAL,
289     SPREF_MAX_BOTTOM_MATERIAL,
290     SPREF_MAX_MID_MATERIAL,
291     SPREF_MAX_TOP_MATERIAL,
292     SPREF_SECTOR_TAGGED_FLOOR,
293     SPREF_LINE_TAGGED_FLOOR,
294     SPREF_TAGGED_FLOOR,
295     SPREF_ACT_TAGGED_FLOOR,
296     SPREF_INDEX_FLOOR,
297     SPREF_SECTOR_TAGGED_CEILING,
298     SPREF_LINE_TAGGED_CEILING,
299     SPREF_TAGGED_CEILING,
300     SPREF_ACT_TAGGED_CEILING,
301     SPREF_INDEX_CEILING,
302     SPREF_BACK_FLOOR,
303     SPREF_BACK_CEILING,
304     SPREF_SPECIAL,
305     SPREF_LINE_ACT_TAGGED_FLOOR,
306     SPREF_LINE_ACT_TAGGED_CEILING
307 };
308 
309 enum // Special lightlevel sources.
310 {
311     LIGHTREF_NONE,
312     LIGHTREF_MY,                   // Actline's front sector.
313     LIGHTREF_ORIGINAL,             // Original light level of the sector.
314     LIGHTREF_CURRENT,              // Current light level of the sector.
315     LIGHTREF_HIGHEST,              // Highest surrounding.
316     LIGHTREF_LOWEST,               // Lowest surrounding.
317     LIGHTREF_NEXT_HIGHEST,         // Next highest surrounding.
318     LIGHTREF_NEXT_LOWEST,          // Next lowest surrounding.
319     LIGHTREF_BACK                  // Actline's back sector.
320 };
321 
322 enum // Line.data references
323 {
324     LDREF_NONE, // Not actually used atm
325     LDREF_ID,
326     LDREF_SPECIAL,
327     LDREF_TAG,
328     LDREF_ACTTAG,
329     LDREF_COUNT,
330     LDREF_ANGLE,
331     LDREF_LENGTH,
332     LDREF_TOP_OFFSETX,
333     LDREF_TOP_OFFSETY,
334     LDREF_MIDDLE_OFFSETX,
335     LDREF_MIDDLE_OFFSETY,
336     LDREF_BOTTOM_OFFSETX,
337     LDREF_BOTTOM_OFFSETY
338 };
339 
340 // Chain sequence flags.
341 #define CHSF_DEACTIVATE_WHEN_DONE   0x1
342 #define CHSF_LOOP                   0x2
343 
344 typedef struct {
345     thinker_t       thinker;
346     Line*           line;
347 } xlthinker_t;
348 
349 // State data for each line.
350 typedef struct {
351     linetype_t      info; // Type definition.
352     dd_bool         active;
353     dd_bool         disabled; // If true, skip all processing.
354     int             timer;
355     int             tickerTimer;
356     void*           activator;
357     int             idata;
358     float           fdata;
359     int             chIdx; // Chain sequence index.
360     float           chTimer; // Chain sequence timer.
361 } xgline_t;
362 
363 // The XG line Classes
364 DENG_EXTERN_C struct xgclass_s xgClasses[];
365 
366 // Used as the activator if there is no real activator.
367 DENG_EXTERN_C struct mobj_s *XG_DummyThing();
368 
369 #ifdef __cplusplus
370 extern "C" {
371 #endif
372 
373 // Register the XG classnames for XGdev
374 void XG_Register(void);
375 
376 // Initialize extended lines for the map.
377 void XL_Init(void);
378 
379 // Called when reseting engine state.
380 void XL_Update(void);
381 
382 void XL_Thinker(void *xlThinkerPtr);
383 
384 /**
385  * Looks for line type definition and sets the line type if one is found.
386  */
387 void XL_SetLineType(Line *line, int id);
388 
389 linetype_t *XL_GetType(int id);
390 
391 int XL_LineEvent(int evType, int lineType, Line *line, int sideNum, void *data);
392 
393 void XL_ActivateLine(dd_bool activating, linetype_t *info, Line *line, int sideNum,
394     struct mobj_s *activator, int evType);
395 
396 /// Function pointer to an XG plane traversal function.
397 typedef int (*LineTraverserFunc)(Line *line, dd_bool ceiling/*unused*/, void *context, void *context2, mobj_t *activator);
398 
399 /**
400  * Executes the specified function on all lines that match the reference
401  * 'rtype'.
402  *
403  * @return  @c false if 'func' returns @c false, otherwise
404  *          @c true. Stops checking when false is returned.
405  */
406 int XL_TraverseLines(Line *line, int reftype, int ref, void *context, void *context2,
407                      struct mobj_s *activator, LineTraverserFunc func);
408 
409 /// Function pointer to an XG plane traversal function.
410 typedef int (*PlaneTraverserFunc)(Sector *sector, dd_bool ceiling, void *context, void *context2, mobj_t *activator);
411 
412 /**
413  * Executes the specified function on all planes that match the reference
414  * (reftype).
415  *
416  * @return  @c true iff all callbacks return @c true.
417  */
418 int XL_TraversePlanes(Line *line, int reftype, int ref, void *context, void *context2,
419     dd_bool travSectors, struct mobj_s *activator, PlaneTraverserFunc func);
420 
421 // Return false if the event was processed.
422 int XL_CrossLine(Line *line, int sideNum, struct mobj_s *thing);
423 
424 int XL_UseLine(Line *line, int sideNum, struct mobj_s *thing);
425 
426 int XL_ShootLine(Line *line, int sideNum, struct mobj_s *thing);
427 
428 int XL_HitLine(Line *line, int sideNum, struct mobj_s *thing);
429 
430 int XG_RandomInt(int min, int max);
431 
432 #ifdef __cplusplus
433 void SV_WriteXGLine(Line *li, MapStateWriter *msw);
434 
435 void SV_ReadXGLine(Line *li, MapStateReader *msr);
436 
437 } // extern "C"
438 #endif
439 
440 #endif
441