]> icculus.org git repositories - btb/d2x.git/blob - main/effects.c
Fixed build, some minor cleanups.
[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 #ifdef RCS
16 static char rcsid[] = "$Id: effects.c,v 1.1.1.1 2001-01-19 03:30:00 bradleyb Exp $";
17 #endif
18
19 #include <conf.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <stdarg.h>
23 #include <string.h>
24
25 #include "gr.h"
26 #include "inferno.h"
27 #include "game.h"
28 #include "vclip.h"
29 #include "effects.h"
30 #include "bm.h"
31 #include "mono.h"
32 #include "u_mem.h"
33 #include "textures.h"
34 #include "cntrlcen.h"
35 #include "error.h"
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