]> icculus.org git repositories - theoddone33/hheretic.git/blob - base/p_lights.c
Menu fonts working, drawpatch fix
[theoddone33/hheretic.git] / base / p_lights.c
1 #include "doomdef.h"
2 #include "p_local.h"
3
4 //==================================================================
5 //==================================================================
6 //
7 //                                                      BROKEN LIGHT FLASHING
8 //
9 //==================================================================
10 //==================================================================
11
12 //==================================================================
13 //
14 //      T_LightFlash
15 //
16 //      After the map has been loaded, scan each sector for specials
17 //      that spawn thinkers
18 //
19 //==================================================================
20 void T_LightFlash (lightflash_t *flash)
21 {
22         if (--flash->count)
23                 return;
24         
25         if (flash->sector->lightlevel == flash->maxlight)
26         {
27                 flash-> sector->lightlevel = flash->minlight;
28                 flash->count = (P_Random()&flash->mintime)+1;
29         }
30         else
31         {
32                 flash-> sector->lightlevel = flash->maxlight;
33                 flash->count = (P_Random()&flash->maxtime)+1;
34         }
35
36 }
37
38
39 //==================================================================
40 //
41 //      P_SpawnLightFlash
42 //
43 //      After the map has been loaded, scan each sector for specials that spawn thinkers
44 //
45 //==================================================================
46 void P_SpawnLightFlash (sector_t *sector)
47 {
48         lightflash_t    *flash;
49         
50         sector->special = 0;            // nothing special about it during gameplay
51         
52         flash = Z_Malloc ( sizeof(*flash), PU_LEVSPEC, 0);
53         P_AddThinker (&flash->thinker);
54         flash->thinker.function = T_LightFlash;
55         flash->sector = sector;
56         flash->maxlight = sector->lightlevel;
57
58         flash->minlight = P_FindMinSurroundingLight(sector,sector->lightlevel);
59         flash->maxtime = 64;
60         flash->mintime = 7;
61         flash->count = (P_Random()&flash->maxtime)+1;
62 }
63
64 //==================================================================
65 //
66 //                                                      STROBE LIGHT FLASHING
67 //
68 //==================================================================
69
70 //==================================================================
71 //
72 //      T_StrobeFlash
73 //
74 //      After the map has been loaded, scan each sector for specials that spawn thinkers
75 //
76 //==================================================================
77 void T_StrobeFlash (strobe_t *flash)
78 {
79         if (--flash->count)
80                 return;
81         
82         if (flash->sector->lightlevel == flash->minlight)
83         {
84                 flash-> sector->lightlevel = flash->maxlight;
85                 flash->count = flash->brighttime;
86         }
87         else
88         {
89                 flash-> sector->lightlevel = flash->minlight;
90                 flash->count =flash->darktime;
91         }
92
93 }
94
95 //==================================================================
96 //
97 //      P_SpawnLightFlash
98 //
99 //      After the map has been loaded, scan each sector for specials that spawn thinkers
100 //
101 //==================================================================
102 void P_SpawnStrobeFlash (sector_t *sector,int fastOrSlow, int inSync)
103 {
104         strobe_t        *flash;
105         
106         flash = Z_Malloc ( sizeof(*flash), PU_LEVSPEC, 0);
107         P_AddThinker (&flash->thinker);
108         flash->sector = sector;
109         flash->darktime = fastOrSlow;
110         flash->brighttime = STROBEBRIGHT;
111         flash->thinker.function = T_StrobeFlash;
112         flash->maxlight = sector->lightlevel;
113         flash->minlight = P_FindMinSurroundingLight(sector, sector->lightlevel);
114                 
115         if (flash->minlight == flash->maxlight)
116                 flash->minlight = 0;
117         sector->special = 0;            // nothing special about it during gameplay
118
119         if (!inSync)
120                 flash->count = (P_Random()&7)+1;
121         else
122                 flash->count = 1;
123 }
124
125 //==================================================================
126 //
127 //      Start strobing lights (usually from a trigger)
128 //
129 //==================================================================
130 void EV_StartLightStrobing(line_t *line)
131 {
132         int     secnum;
133         sector_t        *sec;
134         
135         secnum = -1;
136         while ((secnum = P_FindSectorFromLineTag(line,secnum)) >= 0)
137         {
138                 sec = &sectors[secnum];
139                 if (sec->specialdata)
140                         continue;
141         
142                 P_SpawnStrobeFlash (sec,SLOWDARK, 0);
143         }
144 }
145
146 //==================================================================
147 //
148 //      TURN LINE'S TAG LIGHTS OFF
149 //
150 //==================================================================
151 void EV_TurnTagLightsOff(line_t *line)
152 {
153         int                     i;
154         int                     j;
155         int                     min;
156         sector_t        *sector;
157         sector_t        *tsec;
158         line_t          *templine;
159         
160         sector = sectors;
161         for (j = 0;j < numsectors; j++, sector++)
162                 if (sector->tag == line->tag)
163                 {
164                         min = sector->lightlevel;
165                         for (i = 0;i < sector->linecount; i++)
166                         {
167                                 templine = sector->lines[i];
168                                 tsec = getNextSector(templine,sector);
169                                 if (!tsec)
170                                         continue;
171                                 if (tsec->lightlevel < min)
172                                         min = tsec->lightlevel;
173                         }
174                         sector->lightlevel = min;
175                 }
176 }
177
178 //==================================================================
179 //
180 //      TURN LINE'S TAG LIGHTS ON
181 //
182 //==================================================================
183 void EV_LightTurnOn(line_t *line, int bright)
184 {
185         int                     i;
186         int                     j;
187         sector_t        *sector;
188         sector_t        *temp;
189         line_t          *templine;
190         
191         sector = sectors;
192         
193         for (i=0;i<numsectors;i++, sector++)
194                 if (sector->tag == line->tag)
195                 {
196                         //
197                         // bright = 0 means to search for highest
198                         // light level surrounding sector
199                         //
200                         if (!bright)
201                         {
202                                 for (j = 0;j < sector->linecount; j++)
203                                 {
204                                         templine = sector->lines[j];
205                                         temp = getNextSector(templine,sector);
206                                         if (!temp)
207                                                 continue;
208                                         if (temp->lightlevel > bright)
209                                                 bright = temp->lightlevel;
210                                 }
211                         }
212                         sector-> lightlevel = bright;
213                 }
214 }
215
216 //==================================================================
217 //
218 //      Spawn glowing light
219 //
220 //==================================================================
221 void T_Glow(glow_t *g)
222 {
223         switch(g->direction)
224         {
225                 case -1:                // DOWN
226                         g->sector->lightlevel -= GLOWSPEED;
227                         if (g->sector->lightlevel <= g->minlight)
228                         {
229                                 g->sector->lightlevel += GLOWSPEED;
230                                 g->direction = 1;
231                         }
232                         break;
233                 case 1:                 // UP
234                         g->sector->lightlevel += GLOWSPEED;
235                         if (g->sector->lightlevel >= g->maxlight)
236                         {
237                                 g->sector->lightlevel -= GLOWSPEED;
238                                 g->direction = -1;
239                         }
240                         break;
241         }
242 }
243
244 void P_SpawnGlowingLight(sector_t *sector)
245 {
246         glow_t  *g;
247         
248         g = Z_Malloc( sizeof(*g), PU_LEVSPEC, 0);
249         P_AddThinker(&g->thinker);
250         g->sector = sector;
251         g->minlight = P_FindMinSurroundingLight(sector,sector->lightlevel);
252         g->maxlight = sector->lightlevel;
253         g->thinker.function = T_Glow;
254         g->direction = -1;
255
256         sector->special = 0;
257 }
258