]> icculus.org git repositories - btb/d2x.git/blob - main/effects.c
fix level number position
[btb/d2x.git] / main / effects.c
1 /* $Id: effects.c,v 1.5 2003-10-10 09:36:34 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  * Special effects, such as rotating fans, electrical walls, and
18  * other cool animations.
19  *
20  * Old Log:
21  * Revision 1.1  1995/05/16  15:24:25  allender
22  * Initial revision
23  *
24  * Revision 2.0  1995/02/27  11:32:49  john
25  * New version 2.0, which has no anonymous unions, builds with
26  * Watcom 10.0, and doesn't require parsing BITMAPS.TBL.
27  *
28  * Revision 1.21  1995/02/13  20:35:06  john
29  * Lintized
30  *
31  * Revision 1.20  1994/12/10  16:44:50  matt
32  * Added debugging code to track down door that turns into rock
33  *
34  * Revision 1.19  1994/12/06  16:27:14  matt
35  * Fixed horrible bug that was referencing segment -1
36  *
37  * Revision 1.18  1994/12/02  23:20:51  matt
38  * Reset bitmaps possibly changed by crit clips
39  *
40  * Revision 1.17  1994/11/14  14:00:19  matt
41  * Fixed stupid bug
42  *
43  * Revision 1.16  1994/11/14  12:42:43  matt
44  * Allow holes in effects list
45  *
46  * Revision 1.15  1994/11/08  21:11:52  matt
47  * Added functions to stop & start effects
48  *
49  * Revision 1.14  1994/10/04  18:59:08  matt
50  * Exploding eclips now play eclip while exploding, then switch to static bm
51  *
52  * Revision 1.13  1994/10/04  15:17:42  matt
53  * Took out references to unused constant
54  *
55  * Revision 1.12  1994/09/29  11:00:01  matt
56  * Made eclips (wall animations) not frame-rate dependent (for now)
57  *
58  * Revision 1.11  1994/09/25  00:40:24  matt
59  * Added the ability to make eclips (monitors, fans) which can be blown up
60  *
61  * Revision 1.10  1994/08/14  23:15:14  matt
62  * Added animating bitmap hostages, and cleaned up vclips a bit
63  *
64  * Revision 1.9  1994/08/05  15:56:04  matt
65  * Cleaned up effects system, and added alternate effects for after mine
66  * destruction.
67  *
68  * Revision 1.8  1994/08/01  23:17:21  matt
69  * Add support for animating textures on robots
70  *
71  * Revision 1.7  1994/05/23  15:10:46  yuan
72  * Make Eclips read directly...
73  * No more need for $EFFECTS list.
74  *
75  * Revision 1.6  1994/04/06  14:42:44  yuan
76  * Adding new powerups.
77  *
78  * Revision 1.5  1994/03/15  16:31:54  yuan
79  * Cleaned up bm-loading code.
80  * (And structures)
81  *
82  * Revision 1.4  1994/03/04  17:09:09  yuan
83  * New door stuff.
84  *
85  * Revision 1.3  1994/01/11  11:18:50  yuan
86  * Fixed frame_count
87  *
88  * Revision 1.2  1994/01/11  10:38:55  yuan
89  * Special effects new implementation
90  *
91  * Revision 1.1  1994/01/10  09:45:29  yuan
92  * Initial revision
93  *
94  *
95  */
96
97 #ifdef HAVE_CONFIG_H
98 #include <conf.h>
99 #endif
100
101 #ifdef RCS
102 static char rcsid[] = "$Id: effects.c,v 1.5 2003-10-10 09:36:34 btb Exp $";
103 #endif
104
105 #include <stdio.h>
106 #include <stdlib.h>
107 #include <stdarg.h>
108 #include <string.h>
109
110 #include "gr.h"
111 #include "inferno.h"
112 #include "game.h"
113 #include "vclip.h"
114 #include "effects.h"
115 #include "bm.h"
116 #include "mono.h"
117 #include "u_mem.h"
118 #include "textures.h"
119 #include "cntrlcen.h"
120 #include "error.h"
121
122 int Num_effects;
123 eclip Effects[MAX_EFFECTS];
124
125 void init_special_effects()
126 {
127         int i;
128
129         for (i=0;i<Num_effects;i++)
130                 Effects[i].time_left = Effects[i].vc.frame_time;
131 }
132
133 void reset_special_effects()
134 {
135         int i;
136
137         for (i=0;i<Num_effects;i++) {
138                 Effects[i].segnum = -1;                                 //clear any active one-shots
139                 Effects[i].flags &= ~(EF_STOPPED|EF_ONE_SHOT);          //restart any stopped effects
140
141                 //reset bitmap, which could have been changed by a crit_clip
142                 if (Effects[i].changing_wall_texture != -1)
143                         Textures[Effects[i].changing_wall_texture] = Effects[i].vc.frames[Effects[i].frame_count];
144
145                 if (Effects[i].changing_object_texture != -1)
146                         ObjBitmaps[Effects[i].changing_object_texture] = Effects[i].vc.frames[Effects[i].frame_count];
147
148         }
149 }
150
151 void do_special_effects()
152 {
153         int i;
154         eclip *ec;
155
156         for (i=0,ec=Effects;i<Num_effects;i++,ec++) {
157
158                 if ((Effects[i].changing_wall_texture == -1) && (Effects[i].changing_object_texture==-1) )
159                         continue;
160
161                 if (ec->flags & EF_STOPPED)
162                         continue;
163
164                 ec->time_left -= FrameTime;
165
166                 while (ec->time_left < 0) {
167
168                         ec->time_left += ec->vc.frame_time;
169                         
170                         ec->frame_count++;
171                         if (ec->frame_count >= ec->vc.num_frames) {
172                                 if (ec->flags & EF_ONE_SHOT) {
173                                         Assert(ec->segnum!=-1);
174                                         Assert(ec->sidenum>=0 && ec->sidenum<6);
175                                         Assert(ec->dest_bm_num!=0 && Segments[ec->segnum].sides[ec->sidenum].tmap_num2!=0);
176                                         Segments[ec->segnum].sides[ec->sidenum].tmap_num2 = ec->dest_bm_num | (Segments[ec->segnum].sides[ec->sidenum].tmap_num2&0xc000);               //replace with destoyed
177                                         ec->flags &= ~EF_ONE_SHOT;
178                                         ec->segnum = -1;                //done with this
179                                 }
180
181                                 ec->frame_count = 0;
182                         }
183                 }
184
185                 if (ec->flags & EF_CRITICAL)
186                         continue;
187
188                 if (ec->crit_clip!=-1 && Control_center_destroyed) {
189                         int n = ec->crit_clip;
190
191                         //*ec->bm_ptr = &GameBitmaps[Effects[n].vc.frames[Effects[n].frame_count].index];
192                         if (ec->changing_wall_texture != -1)
193                                 Textures[ec->changing_wall_texture] = Effects[n].vc.frames[Effects[n].frame_count];
194
195                         if (ec->changing_object_texture != -1)
196                                 ObjBitmaps[ec->changing_object_texture] = Effects[n].vc.frames[Effects[n].frame_count];
197
198                 }
199                 else    {
200                         // *ec->bm_ptr = &GameBitmaps[ec->vc.frames[ec->frame_count].index];
201                         if (ec->changing_wall_texture != -1)
202                                 Textures[ec->changing_wall_texture] = ec->vc.frames[ec->frame_count];
203         
204                         if (ec->changing_object_texture != -1)
205                                 ObjBitmaps[ec->changing_object_texture] = ec->vc.frames[ec->frame_count];
206                 }
207
208         }
209 }
210
211 void restore_effect_bitmap_icons()
212 {
213         int i;
214         
215         for (i=0;i<Num_effects;i++)
216                 if (! (Effects[i].flags & EF_CRITICAL)) {
217                         if (Effects[i].changing_wall_texture != -1)
218                                 Textures[Effects[i].changing_wall_texture] = Effects[i].vc.frames[0];
219         
220                         if (Effects[i].changing_object_texture != -1)
221                                 ObjBitmaps[Effects[i].changing_object_texture] = Effects[i].vc.frames[0];
222                 }
223                         //if (Effects[i].bm_ptr != -1)
224                         //      *Effects[i].bm_ptr = &GameBitmaps[Effects[i].vc.frames[0].index];
225 }
226
227 //stop an effect from animating.  Show first frame.
228 void stop_effect(int effect_num)
229 {
230         eclip *ec = &Effects[effect_num];
231         
232         //Assert(ec->bm_ptr != -1);
233
234         ec->flags |= EF_STOPPED;
235
236         ec->frame_count = 0;
237         //*ec->bm_ptr = &GameBitmaps[ec->vc.frames[0].index];
238
239         if (ec->changing_wall_texture != -1)
240                 Textures[ec->changing_wall_texture] = ec->vc.frames[0];
241         
242         if (ec->changing_object_texture != -1)
243                 ObjBitmaps[ec->changing_object_texture] = ec->vc.frames[0];
244
245 }
246
247 //restart a stopped effect
248 void restart_effect(int effect_num)
249 {
250         Effects[effect_num].flags &= ~EF_STOPPED;
251
252         //Assert(Effects[effect_num].bm_ptr != -1);
253 }
254
255 #ifndef FAST_FILE_IO
256 /*
257  * reads n eclip structs from a CFILE
258  */
259 int eclip_read_n(eclip *ec, int n, CFILE *fp)
260 {
261         int i;
262
263         for (i = 0; i < n; i++) {
264                 vclip_read_n(&ec[i].vc, 1, fp);
265                 ec[i].time_left = cfile_read_fix(fp);
266                 ec[i].frame_count = cfile_read_int(fp);
267                 ec[i].changing_wall_texture = cfile_read_short(fp);
268                 ec[i].changing_object_texture = cfile_read_short(fp);
269                 ec[i].flags = cfile_read_int(fp);
270                 ec[i].crit_clip = cfile_read_int(fp);
271                 ec[i].dest_bm_num = cfile_read_int(fp);
272                 ec[i].dest_vclip = cfile_read_int(fp);
273                 ec[i].dest_eclip = cfile_read_int(fp);
274                 ec[i].dest_size = cfile_read_fix(fp);
275                 ec[i].sound_num = cfile_read_int(fp);
276                 ec[i].segnum = cfile_read_int(fp);
277                 ec[i].sidenum = cfile_read_int(fp);
278         }
279         return i;
280 }
281 #endif