]> icculus.org git repositories - btb/d2x.git/blob - main/switch.h
fix MEM_OVERWRITE caused by not allocating enough mem for rle bitmaps
[btb/d2x.git] / main / switch.h
1 /* $Id: switch.h,v 1.4 2003-10-04 03:14:48 btb Exp $ */
2 /*
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
13 */
14
15 /*
16  *
17  * Triggers and Switches.
18  *
19  * Old Log:
20  * Revision 1.1  1995/05/16  16:03:48  allender
21  * Initial revision
22  *
23  * Revision 2.0  1995/02/27  11:26:52  john
24  * New version 2.0, which has no anonymous unions, builds with
25  * Watcom 10.0, and doesn't require parsing BITMAPS.TBL.
26  *
27  * Revision 1.19  1995/01/12  17:00:36  rob
28  * Fixed a problem with switches and secret levels.
29  *
30  * Revision 1.18  1994/10/06  21:24:40  matt
31  * Added switch for exit to secret level
32  *
33  * Revision 1.17  1994/09/29  17:05:52  matt
34  * Removed unused constant
35  *
36  * Revision 1.16  1994/09/24  17:10:07  yuan
37  * Added Matcen triggers.
38  *
39  * Revision 1.15  1994/08/15  18:06:39  yuan
40  * Added external trigger.
41  *
42  * Revision 1.14  1994/06/16  16:20:52  john
43  * Made player start out in physics mode; Neatend up game loop a bit.
44  *
45  * Revision 1.13  1994/05/30  20:22:08  yuan
46  * New triggers.
47  *
48  * Revision 1.12  1994/05/27  10:32:44  yuan
49  * New dialog boxes (Walls and Triggers) added.
50  *
51  *
52  * Revision 1.11  1994/05/25  18:06:32  yuan
53  * Making new dialog box controls for walls and triggers.
54  *
55  * Revision 1.10  1994/04/28  18:04:40  yuan
56  * Gamesave added.
57  * Trigger problem fixed (seg pointer is replaced by index now.)
58  *
59  * Revision 1.9  1994/04/26  11:19:01  yuan
60  * Make it so a trigger can only be triggered every 5 seconds.
61  *
62  */
63
64 #ifndef _SWITCH_H
65 #define _SWITCH_H
66
67 #include "inferno.h"
68 #include "segment.h"
69
70 #define MAX_TRIGGERS        100
71 #define MAX_WALLS_PER_LINK  10
72
73 // Trigger types
74
75 #define TT_OPEN_DOOR        0   // Open a door
76 #define TT_CLOSE_DOOR       1   // Close a door
77 #define TT_MATCEN           2   // Activate a matcen
78 #define TT_EXIT             3   // End the level
79 #define TT_SECRET_EXIT      4   // Go to secret level
80 #define TT_ILLUSION_OFF     5   // Turn an illusion off
81 #define TT_ILLUSION_ON      6   // Turn an illusion on
82 #define TT_UNLOCK_DOOR      7   // Unlock a door
83 #define TT_LOCK_DOOR        8   // Lock a door
84 #define TT_OPEN_WALL        9   // Makes a wall open
85 #define TT_CLOSE_WALL       10  // Makes a wall closed
86 #define TT_ILLUSORY_WALL    11  // Makes a wall illusory
87 #define TT_LIGHT_OFF        12  // Turn a light off
88 #define TT_LIGHT_ON         13  // Turn s light on
89 #define NUM_TRIGGER_TYPES   14
90
91 // Trigger flags
92
93 //could also use flags for one-shots
94
95 #define TF_NO_MESSAGE       1   // Don't show a message when triggered
96 #define TF_ONE_SHOT         2   // Only trigger once
97 #define TF_DISABLED         4   // Set after one-shot fires
98
99 //old trigger structs
100
101 typedef struct v29_trigger {
102         sbyte   type;
103         short   flags;
104         fix     value;
105         fix     time;
106         sbyte   link_num;
107         short   num_links;
108         short   seg[MAX_WALLS_PER_LINK];
109         short   side[MAX_WALLS_PER_LINK];
110 } __pack__ v29_trigger;
111
112 typedef struct v30_trigger {
113         short   flags;
114         sbyte   num_links;
115         sbyte   pad;                        //keep alignment
116         fix     value;
117         fix     time;
118         short   seg[MAX_WALLS_PER_LINK];
119         short   side[MAX_WALLS_PER_LINK];
120 } __pack__ v30_trigger;
121
122 //flags for V30 & below triggers
123 #define TRIGGER_CONTROL_DOORS      1    // Control Trigger
124 #define TRIGGER_SHIELD_DAMAGE      2    // Shield Damage Trigger
125 #define TRIGGER_ENERGY_DRAIN       4    // Energy Drain Trigger
126 #define TRIGGER_EXIT               8    // End of level Trigger
127 #define TRIGGER_ON                16    // Whether Trigger is active
128 #define TRIGGER_ONE_SHOT          32    // If Trigger can only be triggered once
129 #define TRIGGER_MATCEN            64    // Trigger for materialization centers
130 #define TRIGGER_ILLUSION_OFF     128    // Switch Illusion OFF trigger
131 #define TRIGGER_SECRET_EXIT      256    // Exit to secret level
132 #define TRIGGER_ILLUSION_ON      512    // Switch Illusion ON trigger
133 #define TRIGGER_UNLOCK_DOORS    1024    // Unlocks a door
134 #define TRIGGER_OPEN_WALL       2048    // Makes a wall open
135 #define TRIGGER_CLOSE_WALL      4096    // Makes a wall closed
136 #define TRIGGER_ILLUSORY_WALL   8192    // Makes a wall illusory
137
138 //the trigger really should have both a type & a flags, since most of the
139 //flags bits are exclusive of the others.
140 typedef struct trigger {
141         ubyte   type;       //what this trigger does
142         ubyte   flags;      //currently unused
143         sbyte   num_links;  //how many doors, etc. linked to this
144         sbyte   pad;        //keep alignment
145         fix     value;
146         fix     time;
147         short   seg[MAX_WALLS_PER_LINK];
148         short   side[MAX_WALLS_PER_LINK];
149 } __pack__ trigger;
150
151 extern trigger Triggers[MAX_TRIGGERS];
152
153 extern int Num_triggers;
154
155 extern void trigger_init();
156 extern void check_trigger(segment *seg, short side, short objnum,int shot);
157 extern int check_trigger_sub(int trigger_num, int player_num,int shot);
158 extern void triggers_frame_process();
159
160 #ifdef FAST_FILE_IO
161 #define v29_trigger_read(t, fp) cfread(t, sizeof(v29_trigger), 1, fp)
162 #define v30_trigger_read(t, fp) cfread(t, sizeof(v30_trigger), 1, fp)
163 #define trigger_read(t, fp) cfread(t, sizeof(trigger), 1, fp)
164 #else
165 /*
166  * reads a v29_trigger structure from a CFILE
167  */
168 extern void v29_trigger_read(v29_trigger *t, CFILE *fp);
169
170 /*
171  * reads a v30_trigger structure from a CFILE
172  */
173 extern void v30_trigger_read(v30_trigger *t, CFILE *fp);
174
175 /*
176  * reads a trigger structure from a CFILE
177  */
178 extern void trigger_read(trigger *t, CFILE *fp);
179 #endif
180
181 #endif