]> icculus.org git repositories - btb/d2x.git/blob - main/effects.c
Rename include/error.h to include/dxxerror.h
[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 "mono.h"
33 #include "u_mem.h"
34 #include "dxxerror.h"
35
36
37 int Num_effects;
38 eclip Effects[MAX_EFFECTS];
39
40 void init_special_effects()
41 {
42         int i;
43
44         for (i=0;i<Num_effects;i++)
45                 Effects[i].time_left = Effects[i].vc.frame_time;
46 }
47
48 void reset_special_effects()
49 {
50         int i;
51
52         for (i=0;i<Num_effects;i++) {
53                 Effects[i].segnum = -1;                                 //clear any active one-shots
54                 Effects[i].flags &= ~(EF_STOPPED|EF_ONE_SHOT);          //restart any stopped effects
55
56                 //reset bitmap, which could have been changed by a crit_clip
57                 if (Effects[i].changing_wall_texture != -1)
58                         Textures[Effects[i].changing_wall_texture] = Effects[i].vc.frames[Effects[i].frame_count];
59
60                 if (Effects[i].changing_object_texture != -1)
61                         ObjBitmaps[Effects[i].changing_object_texture] = Effects[i].vc.frames[Effects[i].frame_count];
62
63         }
64 }
65
66 void do_special_effects()
67 {
68         int i;
69         eclip *ec;
70
71         for (i=0,ec=Effects;i<Num_effects;i++,ec++) {
72
73                 if ((Effects[i].changing_wall_texture == -1) && (Effects[i].changing_object_texture==-1) )
74                         continue;
75
76                 if (ec->flags & EF_STOPPED)
77                         continue;
78
79                 ec->time_left -= FrameTime;
80
81                 while (ec->time_left < 0) {
82
83                         ec->time_left += ec->vc.frame_time;
84                         
85                         ec->frame_count++;
86                         if (ec->frame_count >= ec->vc.num_frames) {
87                                 if (ec->flags & EF_ONE_SHOT) {
88                                         Assert(ec->segnum!=-1);
89                                         Assert(ec->sidenum>=0 && ec->sidenum<6);
90                                         Assert(ec->dest_bm_num!=0 && Segments[ec->segnum].sides[ec->sidenum].tmap_num2!=0);
91                                         Segments[ec->segnum].sides[ec->sidenum].tmap_num2 = ec->dest_bm_num | (Segments[ec->segnum].sides[ec->sidenum].tmap_num2&0xc000);               //replace with destoyed
92                                         ec->flags &= ~EF_ONE_SHOT;
93                                         ec->segnum = -1;                //done with this
94                                 }
95
96                                 ec->frame_count = 0;
97                         }
98                 }
99
100                 if (ec->flags & EF_CRITICAL)
101                         continue;
102
103                 if (ec->crit_clip!=-1 && Control_center_destroyed) {
104                         int n = ec->crit_clip;
105
106                         //*ec->bm_ptr = &GameBitmaps[Effects[n].vc.frames[Effects[n].frame_count].index];
107                         if (ec->changing_wall_texture != -1)
108                                 Textures[ec->changing_wall_texture] = Effects[n].vc.frames[Effects[n].frame_count];
109
110                         if (ec->changing_object_texture != -1)
111                                 ObjBitmaps[ec->changing_object_texture] = Effects[n].vc.frames[Effects[n].frame_count];
112
113                 }
114                 else    {
115                         // *ec->bm_ptr = &GameBitmaps[ec->vc.frames[ec->frame_count].index];
116                         if (ec->changing_wall_texture != -1)
117                                 Textures[ec->changing_wall_texture] = ec->vc.frames[ec->frame_count];
118         
119                         if (ec->changing_object_texture != -1)
120                                 ObjBitmaps[ec->changing_object_texture] = ec->vc.frames[ec->frame_count];
121                 }
122
123         }
124 }
125
126 void restore_effect_bitmap_icons()
127 {
128         int i;
129         
130         for (i=0;i<Num_effects;i++)
131                 if (! (Effects[i].flags & EF_CRITICAL)) {
132                         if (Effects[i].changing_wall_texture != -1)
133                                 Textures[Effects[i].changing_wall_texture] = Effects[i].vc.frames[0];
134         
135                         if (Effects[i].changing_object_texture != -1)
136                                 ObjBitmaps[Effects[i].changing_object_texture] = Effects[i].vc.frames[0];
137                 }
138                         //if (Effects[i].bm_ptr != -1)
139                         //      *Effects[i].bm_ptr = &GameBitmaps[Effects[i].vc.frames[0].index];
140 }
141
142 //stop an effect from animating.  Show first frame.
143 void stop_effect(int effect_num)
144 {
145         eclip *ec = &Effects[effect_num];
146         
147         //Assert(ec->bm_ptr != -1);
148
149         ec->flags |= EF_STOPPED;
150
151         ec->frame_count = 0;
152         //*ec->bm_ptr = &GameBitmaps[ec->vc.frames[0].index];
153
154         if (ec->changing_wall_texture != -1)
155                 Textures[ec->changing_wall_texture] = ec->vc.frames[0];
156         
157         if (ec->changing_object_texture != -1)
158                 ObjBitmaps[ec->changing_object_texture] = ec->vc.frames[0];
159
160 }
161
162 //restart a stopped effect
163 void restart_effect(int effect_num)
164 {
165         Effects[effect_num].flags &= ~EF_STOPPED;
166
167         //Assert(Effects[effect_num].bm_ptr != -1);
168 }
169
170 #ifndef FAST_FILE_IO
171 /*
172  * reads n eclip structs from a CFILE
173  */
174 int eclip_read_n(eclip *ec, int n, CFILE *fp)
175 {
176         int i;
177
178         for (i = 0; i < n; i++) {
179                 vclip_read_n(&ec[i].vc, 1, fp);
180                 ec[i].time_left = cfile_read_fix(fp);
181                 ec[i].frame_count = cfile_read_int(fp);
182                 ec[i].changing_wall_texture = cfile_read_short(fp);
183                 ec[i].changing_object_texture = cfile_read_short(fp);
184                 ec[i].flags = cfile_read_int(fp);
185                 ec[i].crit_clip = cfile_read_int(fp);
186                 ec[i].dest_bm_num = cfile_read_int(fp);
187                 ec[i].dest_vclip = cfile_read_int(fp);
188                 ec[i].dest_eclip = cfile_read_int(fp);
189                 ec[i].dest_size = cfile_read_fix(fp);
190                 ec[i].sound_num = cfile_read_int(fp);
191                 ec[i].segnum = cfile_read_int(fp);
192                 ec[i].sidenum = cfile_read_int(fp);
193         }
194         return i;
195 }
196 #endif