This commit was manufactured by cvs2svn to create tag 'd2x-0_1_2'.
[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 #ifdef HAVE_CONFIG_H
15 #include <conf.h>
16 #endif
17
18 #ifdef RCS
19 static char rcsid[] = "$Id: effects.c,v 1.2 2001-01-31 15:17:50 bradleyb Exp $";
20 #endif
21
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <stdarg.h>
25 #include <string.h>
26
27 #include "gr.h"
28 #include "inferno.h"
29 #include "game.h"
30 #include "vclip.h"
31 #include "effects.h"
32 #include "bm.h"
33 #include "mono.h"
34 #include "u_mem.h"
35 #include "textures.h"
36 #include "cntrlcen.h"
37 #include "error.h"
38
39 int Num_effects;
40 eclip Effects[MAX_EFFECTS];
41
42 void init_special_effects() 
43 {
44         int i;
45
46         for (i=0;i<Num_effects;i++)
47                 Effects[i].time_left = Effects[i].vc.frame_time;
48 }
49
50 void reset_special_effects()
51 {
52         int i;
53
54         for (i=0;i<Num_effects;i++) {
55                 Effects[i].segnum = -1;                                 //clear any active one-shots
56                 Effects[i].flags &= ~(EF_STOPPED|EF_ONE_SHOT);          //restart any stopped effects
57
58                 //reset bitmap, which could have been changed by a crit_clip
59                 if (Effects[i].changing_wall_texture != -1)
60                         Textures[Effects[i].changing_wall_texture] = Effects[i].vc.frames[Effects[i].frame_count];
61
62                 if (Effects[i].changing_object_texture != -1)
63                         ObjBitmaps[Effects[i].changing_object_texture] = Effects[i].vc.frames[Effects[i].frame_count];
64
65         }
66 }
67
68 void do_special_effects()
69 {
70         int i;
71         eclip *ec;
72
73         for (i=0,ec=Effects;i<Num_effects;i++,ec++) {
74
75                 if ((Effects[i].changing_wall_texture == -1) && (Effects[i].changing_object_texture==-1) )
76                         continue;
77
78                 if (ec->flags & EF_STOPPED)
79                         continue;
80
81                 ec->time_left -= FrameTime;
82
83                 while (ec->time_left < 0) {
84
85                         ec->time_left += ec->vc.frame_time;
86                         
87                         ec->frame_count++;
88                         if (ec->frame_count >= ec->vc.num_frames) {
89                                 if (ec->flags & EF_ONE_SHOT) {
90                                         Assert(ec->segnum!=-1);
91                                         Assert(ec->sidenum>=0 && ec->sidenum<6);
92                                         Assert(ec->dest_bm_num!=0 && Segments[ec->segnum].sides[ec->sidenum].tmap_num2!=0);
93                                         Segments[ec->segnum].sides[ec->sidenum].tmap_num2 = ec->dest_bm_num | (Segments[ec->segnum].sides[ec->sidenum].tmap_num2&0xc000);               //replace with destoyed
94                                         ec->flags &= ~EF_ONE_SHOT;
95                                         ec->segnum = -1;                //done with this
96                                 }
97
98                                 ec->frame_count = 0;
99                         }
100                 }
101
102                 if (ec->flags & EF_CRITICAL)
103                         continue;
104
105                 if (ec->crit_clip!=-1 && Control_center_destroyed) {
106                         int n = ec->crit_clip;
107
108                         //*ec->bm_ptr = &GameBitmaps[Effects[n].vc.frames[Effects[n].frame_count].index];
109                         if (ec->changing_wall_texture != -1)
110                                 Textures[ec->changing_wall_texture] = Effects[n].vc.frames[Effects[n].frame_count];
111
112                         if (ec->changing_object_texture != -1)
113                                 ObjBitmaps[ec->changing_object_texture] = Effects[n].vc.frames[Effects[n].frame_count];
114
115                 }
116                 else    {
117                         // *ec->bm_ptr = &GameBitmaps[ec->vc.frames[ec->frame_count].index];
118                         if (ec->changing_wall_texture != -1)
119                                 Textures[ec->changing_wall_texture] = ec->vc.frames[ec->frame_count];
120         
121                         if (ec->changing_object_texture != -1)
122                                 ObjBitmaps[ec->changing_object_texture] = ec->vc.frames[ec->frame_count];
123                 }
124
125         }
126 }
127
128 void restore_effect_bitmap_icons()
129 {
130         int i;
131         
132         for (i=0;i<Num_effects;i++)
133                 if (! (Effects[i].flags & EF_CRITICAL)) {
134                         if (Effects[i].changing_wall_texture != -1)
135                                 Textures[Effects[i].changing_wall_texture] = Effects[i].vc.frames[0];
136         
137                         if (Effects[i].changing_object_texture != -1)
138                                 ObjBitmaps[Effects[i].changing_object_texture] = Effects[i].vc.frames[0];
139                 }
140                         //if (Effects[i].bm_ptr != -1)
141                         //      *Effects[i].bm_ptr = &GameBitmaps[Effects[i].vc.frames[0].index];
142 }
143
144 //stop an effect from animating.  Show first frame.
145 void stop_effect(int effect_num)
146 {
147         eclip *ec = &Effects[effect_num];
148         
149         //Assert(ec->bm_ptr != -1);
150
151         ec->flags |= EF_STOPPED;
152
153         ec->frame_count = 0;
154         //*ec->bm_ptr = &GameBitmaps[ec->vc.frames[0].index];
155
156         if (ec->changing_wall_texture != -1)
157                 Textures[ec->changing_wall_texture] = ec->vc.frames[0];
158         
159         if (ec->changing_object_texture != -1)
160                 ObjBitmaps[ec->changing_object_texture] = ec->vc.frames[0];
161
162 }
163
164 //restart a stopped effect
165 void restart_effect(int effect_num)
166 {
167         Effects[effect_num].flags &= ~EF_STOPPED;
168
169         //Assert(Effects[effect_num].bm_ptr != -1);
170 }
171