]> icculus.org git repositories - btb/d2x.git/blob - main/effects.c
remove rcs tags
[btb/d2x.git] / main / effects.c
1 /*
2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
12 */
13
14 /*
15  *
16  * Special effects, such as rotating fans, electrical walls, and
17  * other cool animations.
18  *
19  */
20
21 #ifdef HAVE_CONFIG_H
22 #include <conf.h>
23 #endif
24
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <stdarg.h>
28 #include <string.h>
29
30 #include "gr.h"
31 #include "inferno.h"
32 #include "game.h"
33 #include "vclip.h"
34 #include "effects.h"
35 #include "bm.h"
36 #include "mono.h"
37 #include "u_mem.h"
38 #include "textures.h"
39 #include "cntrlcen.h"
40 #include "error.h"
41
42 int Num_effects;
43 eclip Effects[MAX_EFFECTS];
44
45 void init_special_effects()
46 {
47         int i;
48
49         for (i=0;i<Num_effects;i++)
50                 Effects[i].time_left = Effects[i].vc.frame_time;
51 }
52
53 void reset_special_effects()
54 {
55         int i;
56
57         for (i=0;i<Num_effects;i++) {
58                 Effects[i].segnum = -1;                                 //clear any active one-shots
59                 Effects[i].flags &= ~(EF_STOPPED|EF_ONE_SHOT);          //restart any stopped effects
60
61                 //reset bitmap, which could have been changed by a crit_clip
62                 if (Effects[i].changing_wall_texture != -1)
63                         Textures[Effects[i].changing_wall_texture] = Effects[i].vc.frames[Effects[i].frame_count];
64
65                 if (Effects[i].changing_object_texture != -1)
66                         ObjBitmaps[Effects[i].changing_object_texture] = Effects[i].vc.frames[Effects[i].frame_count];
67
68         }
69 }
70
71 void do_special_effects()
72 {
73         int i;
74         eclip *ec;
75
76         for (i=0,ec=Effects;i<Num_effects;i++,ec++) {
77
78                 if ((Effects[i].changing_wall_texture == -1) && (Effects[i].changing_object_texture==-1) )
79                         continue;
80
81                 if (ec->flags & EF_STOPPED)
82                         continue;
83
84                 ec->time_left -= FrameTime;
85
86                 while (ec->time_left < 0) {
87
88                         ec->time_left += ec->vc.frame_time;
89                         
90                         ec->frame_count++;
91                         if (ec->frame_count >= ec->vc.num_frames) {
92                                 if (ec->flags & EF_ONE_SHOT) {
93                                         Assert(ec->segnum!=-1);
94                                         Assert(ec->sidenum>=0 && ec->sidenum<6);
95                                         Assert(ec->dest_bm_num!=0 && Segments[ec->segnum].sides[ec->sidenum].tmap_num2!=0);
96                                         Segments[ec->segnum].sides[ec->sidenum].tmap_num2 = ec->dest_bm_num | (Segments[ec->segnum].sides[ec->sidenum].tmap_num2&0xc000);               //replace with destoyed
97                                         ec->flags &= ~EF_ONE_SHOT;
98                                         ec->segnum = -1;                //done with this
99                                 }
100
101                                 ec->frame_count = 0;
102                         }
103                 }
104
105                 if (ec->flags & EF_CRITICAL)
106                         continue;
107
108                 if (ec->crit_clip!=-1 && Control_center_destroyed) {
109                         int n = ec->crit_clip;
110
111                         //*ec->bm_ptr = &GameBitmaps[Effects[n].vc.frames[Effects[n].frame_count].index];
112                         if (ec->changing_wall_texture != -1)
113                                 Textures[ec->changing_wall_texture] = Effects[n].vc.frames[Effects[n].frame_count];
114
115                         if (ec->changing_object_texture != -1)
116                                 ObjBitmaps[ec->changing_object_texture] = Effects[n].vc.frames[Effects[n].frame_count];
117
118                 }
119                 else    {
120                         // *ec->bm_ptr = &GameBitmaps[ec->vc.frames[ec->frame_count].index];
121                         if (ec->changing_wall_texture != -1)
122                                 Textures[ec->changing_wall_texture] = ec->vc.frames[ec->frame_count];
123         
124                         if (ec->changing_object_texture != -1)
125                                 ObjBitmaps[ec->changing_object_texture] = ec->vc.frames[ec->frame_count];
126                 }
127
128         }
129 }
130
131 void restore_effect_bitmap_icons()
132 {
133         int i;
134         
135         for (i=0;i<Num_effects;i++)
136                 if (! (Effects[i].flags & EF_CRITICAL)) {
137                         if (Effects[i].changing_wall_texture != -1)
138                                 Textures[Effects[i].changing_wall_texture] = Effects[i].vc.frames[0];
139         
140                         if (Effects[i].changing_object_texture != -1)
141                                 ObjBitmaps[Effects[i].changing_object_texture] = Effects[i].vc.frames[0];
142                 }
143                         //if (Effects[i].bm_ptr != -1)
144                         //      *Effects[i].bm_ptr = &GameBitmaps[Effects[i].vc.frames[0].index];
145 }
146
147 //stop an effect from animating.  Show first frame.
148 void stop_effect(int effect_num)
149 {
150         eclip *ec = &Effects[effect_num];
151         
152         //Assert(ec->bm_ptr != -1);
153
154         ec->flags |= EF_STOPPED;
155
156         ec->frame_count = 0;
157         //*ec->bm_ptr = &GameBitmaps[ec->vc.frames[0].index];
158
159         if (ec->changing_wall_texture != -1)
160                 Textures[ec->changing_wall_texture] = ec->vc.frames[0];
161         
162         if (ec->changing_object_texture != -1)
163                 ObjBitmaps[ec->changing_object_texture] = ec->vc.frames[0];
164
165 }
166
167 //restart a stopped effect
168 void restart_effect(int effect_num)
169 {
170         Effects[effect_num].flags &= ~EF_STOPPED;
171
172         //Assert(Effects[effect_num].bm_ptr != -1);
173 }
174
175 #ifndef FAST_FILE_IO
176 /*
177  * reads n eclip structs from a CFILE
178  */
179 int eclip_read_n(eclip *ec, int n, CFILE *fp)
180 {
181         int i;
182
183         for (i = 0; i < n; i++) {
184                 vclip_read_n(&ec[i].vc, 1, fp);
185                 ec[i].time_left = cfile_read_fix(fp);
186                 ec[i].frame_count = cfile_read_int(fp);
187                 ec[i].changing_wall_texture = cfile_read_short(fp);
188                 ec[i].changing_object_texture = cfile_read_short(fp);
189                 ec[i].flags = cfile_read_int(fp);
190                 ec[i].crit_clip = cfile_read_int(fp);
191                 ec[i].dest_bm_num = cfile_read_int(fp);
192                 ec[i].dest_vclip = cfile_read_int(fp);
193                 ec[i].dest_eclip = cfile_read_int(fp);
194                 ec[i].dest_size = cfile_read_fix(fp);
195                 ec[i].sound_num = cfile_read_int(fp);
196                 ec[i].segnum = cfile_read_int(fp);
197                 ec[i].sidenum = cfile_read_int(fp);
198         }
199         return i;
200 }
201 #endif