]> icculus.org git repositories - btb/d2x.git/blob - main/wall.h
add level component saving functions which use PhysicsFS
[btb/d2x.git] / main / wall.h
1 /* $Id: wall.h,v 1.10 2005-06-22 09:08:21 chris 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  * Header for wall.c
18  *
19  */
20
21 #ifndef _WALL_H
22 #define _WALL_H
23
24 #include "inferno.h"
25 #include "segment.h"
26 #include "object.h"
27 #include "cfile.h"
28
29 //#include "vclip.h"
30
31 #define MAX_WALLS               254 // Maximum number of walls
32 #define MAX_WALL_ANIMS          60  // Maximum different types of doors
33 #define MAX_DOORS               90  // Maximum number of open doors
34
35 // Various wall types.
36 #define WALL_NORMAL             0   // Normal wall
37 #define WALL_BLASTABLE          1   // Removable (by shooting) wall
38 #define WALL_DOOR               2   // Door
39 #define WALL_ILLUSION           3   // Wall that appears to be there, but you can fly thru
40 #define WALL_OPEN               4   // Just an open side. (Trigger)
41 #define WALL_CLOSED             5   // Wall.  Used for transparent walls.
42 #define WALL_OVERLAY            6   // Goes over an actual solid side.  For triggers
43 #define WALL_CLOAKED            7   // Can see it, and see through it
44
45 // Various wall flags.
46 #define WALL_BLASTED            1   // Blasted out wall.
47 #define WALL_DOOR_OPENED        2   // Open door.
48 #define WALL_DOOR_LOCKED        8   // Door is locked.
49 #define WALL_DOOR_AUTO          16  // Door automatically closes after time.
50 #define WALL_ILLUSION_OFF       32  // Illusionary wall is shut off.
51 #define WALL_WALL_SWITCH        64  // This wall is openable by a wall switch.
52 #define WALL_BUDDY_PROOF        128 // Buddy assumes he cannot get through this wall.
53
54 // Wall states
55 #define WALL_DOOR_CLOSED        0       // Door is closed
56 #define WALL_DOOR_OPENING       1       // Door is opening.
57 #define WALL_DOOR_WAITING       2       // Waiting to close
58 #define WALL_DOOR_CLOSING       3       // Door is closing
59 #define WALL_DOOR_OPEN          4       // Door is open, and staying open
60 #define WALL_DOOR_CLOAKING      5       // Wall is going from closed -> open
61 #define WALL_DOOR_DECLOAKING    6       // Wall is going from open -> closed
62
63 //note: a door is considered opened (i.e., it has WALL_OPENED set) when it
64 //is more than half way open.  Thus, it can have any of OPENING, CLOSING,
65 //or WAITING bits set when OPENED is set.
66
67 #define KEY_NONE                1
68 #define KEY_BLUE                2
69 #define KEY_RED                 4
70 #define KEY_GOLD                8
71
72 #define WALL_HPS                100*F1_0    // Normal wall's hp
73 #define WALL_DOOR_INTERVAL      5*F1_0      // How many seconds a door is open
74
75 #define DOOR_OPEN_TIME          i2f(2)      // How long takes to open
76 #define DOOR_WAIT_TIME          i2f(5)      // How long before auto door closes
77
78 #define MAX_CLIP_FRAMES         50
79
80 // WALL_IS_DOORWAY flags.
81 #define WID_FLY_FLAG            1
82 #define WID_RENDER_FLAG         2
83 #define WID_RENDPAST_FLAG       4
84 #define WID_EXTERNAL_FLAG       8
85 #define WID_CLOAKED_FLAG        16
86
87 //  WALL_IS_DOORWAY return values          F/R/RP
88 #define WID_WALL                    2   // 0/1/0        wall
89 #define WID_TRANSPARENT_WALL        6   // 0/1/1        transparent wall
90 #define WID_ILLUSORY_WALL           3   // 1/1/0        illusory wall
91 #define WID_TRANSILLUSORY_WALL      7   // 1/1/1        transparent illusory wall
92 #define WID_NO_WALL                 5   //  1/0/1       no wall, can fly through
93 #define WID_EXTERNAL                8   // 0/0/0/1  don't see it, dont fly through it
94
95 #define MAX_STUCK_OBJECTS   32
96
97 typedef struct stuckobj {
98         short   objnum, wallnum;
99         int     signature;
100 } stuckobj;
101
102 //Start old wall structures
103
104 typedef struct v16_wall {
105         sbyte   type;               // What kind of special wall.
106         sbyte   flags;              // Flags for the wall.
107         fix     hps;                // "Hit points" of the wall.
108         sbyte   trigger;            // Which trigger is associated with the wall.
109         sbyte   clip_num;           // Which animation associated with the wall.
110         sbyte   keys;
111 } __pack__ v16_wall;
112
113 typedef struct v19_wall {
114         int     segnum,sidenum;     // Seg & side for this wall
115         sbyte   type;               // What kind of special wall.
116         sbyte   flags;              // Flags for the wall.
117         fix     hps;                // "Hit points" of the wall.
118         sbyte   trigger;            // Which trigger is associated with the wall.
119         sbyte   clip_num;           // Which animation associated with the wall.
120         sbyte   keys;
121         int linked_wall;            // number of linked wall
122 } __pack__ v19_wall;
123
124 typedef struct v19_door {
125         int     n_parts;            // for linked walls
126         short   seg[2];             // Segment pointer of door.
127         short   side[2];            // Side number of door.
128         short   type[2];            // What kind of door animation.
129         fix     open;               // How long it has been open.
130 } __pack__ v19_door;
131
132 //End old wall structures
133
134 typedef struct wall {
135         int     segnum,sidenum;     // Seg & side for this wall
136         fix     hps;                // "Hit points" of the wall.
137         int     linked_wall;        // number of linked wall
138         ubyte   type;               // What kind of special wall.
139         ubyte   flags;              // Flags for the wall.
140         ubyte   state;              // Opening, closing, etc.
141         sbyte   trigger;            // Which trigger is associated with the wall.
142         sbyte   clip_num;           // Which animation associated with the wall.
143         ubyte   keys;               // which keys are required
144         sbyte   controlling_trigger;// which trigger causes something to happen here.  Not like "trigger" above, which is the trigger on this wall.
145                                 //  Note: This gets stuffed at load time in gamemine.c.  Don't try to use it in the editor.  You will be sorry!
146         sbyte   cloak_value;        // if this wall is cloaked, the fade value
147 } __pack__ wall;
148
149 typedef struct active_door {
150         int     n_parts;            // for linked walls
151         short   front_wallnum[2];   // front wall numbers for this door
152         short   back_wallnum[2];    // back wall numbers for this door
153         fix     time;               // how long been opening, closing, waiting
154 } __pack__ active_door;
155
156 typedef struct cloaking_wall {
157         short       front_wallnum;  // front wall numbers for this door
158         short       back_wallnum;   // back wall numbers for this door
159         fix     front_ls[4];        // front wall saved light values
160         fix     back_ls[4];         // back wall saved light values
161         fix     time;               // how long been cloaking or decloaking
162 } __pack__ cloaking_wall;
163
164 //wall clip flags
165 #define WCF_EXPLODES    1       //door explodes when opening
166 #define WCF_BLASTABLE   2       //this is a blastable wall
167 #define WCF_TMAP1       4       //this uses primary tmap, not tmap2
168 #define WCF_HIDDEN      8       //this uses primary tmap, not tmap2
169
170 typedef struct {
171         fix     play_time;
172         short   num_frames;
173         short   frames[MAX_CLIP_FRAMES];
174         short   open_sound;
175         short   close_sound;
176         short   flags;
177         char    filename[13];
178         char    pad;
179 } __pack__ wclip;
180
181 extern char Wall_names[7][10];
182
183 //#define WALL_IS_DOORWAY(seg,side) wall_is_doorway(seg, side)
184
185 #define WALL_IS_DOORWAY(seg,side) (((seg)->children[(side)] == -1) ? WID_RENDER_FLAG : ((seg)->children[(side)] == -2) ? WID_EXTERNAL_FLAG : ((seg)->sides[(side)].wall_num == -1) ? (WID_FLY_FLAG|WID_RENDPAST_FLAG) : wall_is_doorway((seg), (side)))
186
187 extern wall Walls[MAX_WALLS];           // Master walls array
188 extern int Num_walls;                   // Number of walls
189
190 extern active_door ActiveDoors[MAX_DOORS];  //  Master doors array
191 extern int Num_open_doors;              // Number of open doors
192
193 extern cloaking_wall CloakingWalls[];
194 extern int Num_cloaking_walls;
195
196 extern wclip WallAnims[MAX_WALL_ANIMS];
197 extern int Num_wall_anims;
198
199 extern int walls_bm_num[MAX_WALL_ANIMS];
200
201 // Initializes all walls (i.e. no special walls.)
202 extern void wall_init();
203
204 // Automatically checks if a there is a doorway (i.e. can fly through)
205 extern int wall_is_doorway ( segment *seg, int side );
206
207 // Deteriorate appearance of wall. (Changes bitmap (paste-ons))
208 extern void wall_damage(segment *seg, int side, fix damage);
209
210 // Destroys a blastable wall. (So it is an opening afterwards)
211 extern void wall_destroy(segment *seg, int side);
212
213 void wall_illusion_on(segment *seg, int side);
214
215 void wall_illusion_off(segment *seg, int side);
216
217 // Opens a door, including animation and other processing.
218 void do_door_open(int door_num);
219
220 // Closes a door, including animation and other processing.
221 void do_door_close(int door_num);
222
223 // Opens a door
224 extern void wall_open_door(segment *seg, int side);
225
226 // Closes a door
227 extern void wall_close_door(segment *seg, int side);
228
229 //return codes for wall_hit_process()
230 #define WHP_NOT_SPECIAL     0       //wasn't a quote-wall-unquote
231 #define WHP_NO_KEY          1       //hit door, but didn't have key
232 #define WHP_BLASTABLE       2       //hit blastable wall
233 #define WHP_DOOR            3       //a door (which will now be opening)
234
235 // Determines what happens when a wall is shot
236 //obj is the object that hit...either a weapon or the player himself
237 extern int wall_hit_process(segment *seg, int side, fix damage, int playernum, object *obj );
238
239 // Opens/destroys specified door.
240 extern void wall_toggle(segment *seg, int side);
241
242 // Tidy up Walls array for load/save purposes.
243 extern void reset_walls();
244
245 // Called once per frame..
246 void wall_frame_process();
247
248 extern stuckobj Stuck_objects[MAX_STUCK_OBJECTS];
249
250 //  An object got stuck in a door (like a flare).
251 //  Add global entry.
252 extern void add_stuck_object(object *objp, int segnum, int sidenum);
253 extern void remove_obsolete_stuck_objects(void);
254
255 //set the tmap_num or tmap_num2 field for a wall/door
256 extern void wall_set_tmap_num(segment *seg,int side,segment *csegp,int cside,int anim_num,int frame_num);
257
258 // Remove any flares from a wall
259 void kill_stuck_objects(int wallnum);
260
261 //start wall open <-> closed transitions
262 void start_wall_cloak(segment *seg, int side);
263 void start_wall_decloak(segment *seg, int side);
264
265 extern int wclip_read_n_d1(wclip *wc, int n, CFILE *fp);
266 #ifdef FAST_FILE_IO
267 #define wclip_read_n(wc, n, fp) cfread(wc, sizeof(wclip), n, fp)
268 #define v16_wall_read(w, fp) cfread(w, sizeof(v16_wall), 1, fp)
269 #define v19_wall_read(w, fp) cfread(w, sizeof(v19_wall), 1, fp)
270 #define wall_read(w, fp) cfread(w, sizeof(wall), 1, fp)
271 #define v19_door_read(d, fp) cfread(d, sizeof(v19_door), 1, fp)
272 #define active_door_read(d, fp) cfread(d, sizeof(active_door), 1, fp)
273 #else
274 /*
275  * reads n wclip structs from a CFILE
276  */
277 extern int wclip_read_n(wclip *wc, int n, CFILE *fp);
278
279 /*
280  * reads a v16_wall structure from a CFILE
281  */
282 extern void v16_wall_read(v16_wall *w, CFILE *fp);
283
284 /*
285  * reads a v19_wall structure from a CFILE
286  */
287 extern void v19_wall_read(v19_wall *w, CFILE *fp);
288
289 /*
290  * reads a wall structure from a CFILE
291  */
292 extern void wall_read(wall *w, CFILE *fp);
293
294 /*
295  * reads a v19_door structure from a CFILE
296  */
297 extern void v19_door_read(v19_door *d, CFILE *fp);
298
299 /*
300  * reads an active_door structure from a CFILE
301  */
302 extern void active_door_read(active_door *ad, CFILE *fp);
303 #endif
304
305 extern void wall_write(wall *w, short version, PHYSFS_file *fp);
306
307 #endif