]> git.lizzy.rs Git - plan9front.git/blob - sys/src/games/doom/p_switch.c
games/doom:
[plan9front.git] / sys / src / games / doom / p_switch.c
1 // Emacs style mode select   -*- C++ -*- 
2 //-----------------------------------------------------------------------------
3 //
4 // $Id:$
5 //
6 // Copyright (C) 1993-1996 by id Software, Inc.
7 //
8 // This source is available for distribution and/or modification
9 // only under the terms of the DOOM Source Code License as
10 // published by id Software. All rights reserved.
11 //
12 // The source is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
15 // for more details.
16 //
17 //
18 // $Log:$
19 //
20 // DESCRIPTION:
21 //      Switches, buttons. Two-state animation. Exits.
22 //
23 //-----------------------------------------------------------------------------
24
25 static const char
26 rcsid[] = "$Id: p_switch.c,v 1.3 1997/01/28 22:08:29 b1 Exp $";
27
28
29 #include "i_system.h"
30 #include "doomdef.h"
31 #include "p_local.h"
32
33 #include "g_game.h"
34
35 #include "s_sound.h"
36
37 // Data.
38 #include "sounds.h"
39
40 // State.
41 #include "doomstat.h"
42 #include "r_state.h"
43
44
45 //
46 // CHANGE THE TEXTURE OF A WALL SWITCH TO ITS OPPOSITE
47 //
48 switchlist_t alphSwitchList[] =
49 {
50     // Doom shareware episode 1 switches
51     {"SW1BRCOM",        "SW2BRCOM",     1},
52     {"SW1BRN1", "SW2BRN1",      1},
53     {"SW1BRN2", "SW2BRN2",      1},
54     {"SW1BRNGN",        "SW2BRNGN",     1},
55     {"SW1BROWN",        "SW2BROWN",     1},
56     {"SW1COMM", "SW2COMM",      1},
57     {"SW1COMP", "SW2COMP",      1},
58     {"SW1DIRT", "SW2DIRT",      1},
59     {"SW1EXIT", "SW2EXIT",      1},
60     {"SW1GRAY", "SW2GRAY",      1},
61     {"SW1GRAY1",        "SW2GRAY1",     1},
62     {"SW1METAL",        "SW2METAL",     1},
63     {"SW1PIPE", "SW2PIPE",      1},
64     {"SW1SLAD", "SW2SLAD",      1},
65     {"SW1STARG",        "SW2STARG",     1},
66     {"SW1STON1",        "SW2STON1",     1},
67     {"SW1STON2",        "SW2STON2",     1},
68     {"SW1STONE",        "SW2STONE",     1},
69     {"SW1STRTN",        "SW2STRTN",     1},
70     
71     // Doom registered episodes 2&3 switches
72     {"SW1BLUE", "SW2BLUE",      2},
73     {"SW1CMT",          "SW2CMT",       2},
74     {"SW1GARG", "SW2GARG",      2},
75     {"SW1GSTON",        "SW2GSTON",     2},
76     {"SW1HOT",          "SW2HOT",       2},
77     {"SW1LION", "SW2LION",      2},
78     {"SW1SATYR",        "SW2SATYR",     2},
79     {"SW1SKIN", "SW2SKIN",      2},
80     {"SW1VINE", "SW2VINE",      2},
81     {"SW1WOOD", "SW2WOOD",      2},
82     
83     // Doom II switches
84     {"SW1PANEL",        "SW2PANEL",     3},
85     {"SW1ROCK", "SW2ROCK",      3},
86     {"SW1MET2", "SW2MET2",      3},
87     {"SW1WDMET",        "SW2WDMET",     3},
88     {"SW1BRIK", "SW2BRIK",      3},
89     {"SW1MOD1", "SW2MOD1",      3},
90     {"SW1ZIM",          "SW2ZIM",       3},
91     {"SW1STON6",        "SW2STON6",     3},
92     {"SW1TEK",          "SW2TEK",       3},
93     {"SW1MARB", "SW2MARB",      3},
94     {"SW1SKULL",        "SW2SKULL",     3},
95         
96     {"\0",              "\0",           0}
97 };
98
99 int             switchlist[MAXSWITCHES * 2];
100 int             numswitches;
101 button_t        buttonlist[MAXBUTTONS];
102
103 //
104 // P_InitSwitchList
105 // Only called at game initialization.
106 //
107 void P_InitSwitchList(void)
108 {
109     int         i;
110     int         index;
111     int         episode;
112         
113     episode = 1;
114
115     if (gamemode == registered)
116         episode = 2;
117     else
118         if ( gamemode == commercial )
119             episode = 3;
120                 
121     for (index = 0,i = 0;i < MAXSWITCHES;i++)
122     {
123         if (!alphSwitchList[i].episode)
124         {
125             numswitches = index/2;
126             switchlist[index] = -1;
127             break;
128         }
129                 
130         if (alphSwitchList[i].episode <= episode)
131         {
132             switchlist[index++] = R_TextureNumForName(alphSwitchList[i].name1);
133             switchlist[index++] = R_TextureNumForName(alphSwitchList[i].name2);
134         }
135     }
136 }
137
138
139 //
140 // Start a button counting down till it turns off.
141 //
142 void
143 P_StartButton
144 ( line_t*       line,
145   bwhere_e      w,
146   int           texture,
147   int           time )
148 {
149     int         i;
150     
151     // See if button is already pressed
152     for (i = 0;i < MAXBUTTONS;i++)
153     {
154         if (buttonlist[i].btimer
155             && buttonlist[i].line == line)
156         {
157             
158             return;
159         }
160     }
161     
162
163     
164     for (i = 0;i < MAXBUTTONS;i++)
165     {
166         if (!buttonlist[i].btimer)
167         {
168             buttonlist[i].line = line;
169             buttonlist[i].where = w;
170             buttonlist[i].btexture = texture;
171             buttonlist[i].btimer = time;
172             buttonlist[i].soundorg = (mobj_t *)&line->frontsector->soundorg;
173             return;
174         }
175     }
176     
177     I_Error("P_StartButton: no button slots left!");
178 }
179
180
181
182
183
184 //
185 // Function that changes wall texture.
186 // Tell it if switch is ok to use again (1=yes, it's a button).
187 //
188 void
189 P_ChangeSwitchTexture
190 ( line_t*       line,
191   int           useAgain )
192 {
193     int     texTop;
194     int     texMid;
195     int     texBot;
196     int     i;
197     int     sound;
198         
199     if (!useAgain)
200         line->special = 0;
201
202     texTop = sides[line->sidenum[0]].toptexture;
203     texMid = sides[line->sidenum[0]].midtexture;
204     texBot = sides[line->sidenum[0]].bottomtexture;
205         
206     sound = sfx_swtchn;
207
208     // EXIT SWITCH?
209     if (line->special == 11)                
210         sound = sfx_swtchx;
211         
212     for (i = 0;i < numswitches*2;i++)
213     {
214         if (switchlist[i] == texTop)
215         {
216             S_StartSound(buttonlist->soundorg,sound);
217             sides[line->sidenum[0]].toptexture = switchlist[i^1];
218
219             if (useAgain)
220                 P_StartButton(line,top,switchlist[i],BUTTONTIME);
221
222             return;
223         }
224         else
225         {
226             if (switchlist[i] == texMid)
227             {
228                 S_StartSound(buttonlist->soundorg,sound);
229                 sides[line->sidenum[0]].midtexture = switchlist[i^1];
230
231                 if (useAgain)
232                     P_StartButton(line, middle,switchlist[i],BUTTONTIME);
233
234                 return;
235             }
236             else
237             {
238                 if (switchlist[i] == texBot)
239                 {
240                     S_StartSound(buttonlist->soundorg,sound);
241                     sides[line->sidenum[0]].bottomtexture = switchlist[i^1];
242
243                     if (useAgain)
244                         P_StartButton(line, bottom,switchlist[i],BUTTONTIME);
245
246                     return;
247                 }
248             }
249         }
250     }
251 }
252
253
254
255
256
257
258 //
259 // P_UseSpecialLine
260 // Called when a thing uses a special line.
261 // Only the front sides of lines are usable.
262 //
263 boolean
264 P_UseSpecialLine
265 ( mobj_t*       thing,
266   line_t*       line,
267   int           side )
268 {               
269
270     // Err...
271     // Use the back sides of VERY SPECIAL lines...
272     if (side)
273     {
274         switch(line->special)
275         {
276           case 124:
277             // Sliding door open&close
278             // UNUSED?
279             break;
280
281           default:
282             return false;
283             break;
284         }
285     }
286
287     
288     // Switches that other things can activate.
289     if (!thing->player)
290     {
291         // never open secret doors
292         if (line->flags & ML_SECRET)
293             return false;
294         
295         switch(line->special)
296         {
297           case 1:       // MANUAL DOOR RAISE
298           case 32:      // MANUAL BLUE
299           case 33:      // MANUAL RED
300           case 34:      // MANUAL YELLOW
301             break;
302             
303           default:
304             return false;
305             break;
306         }
307     }
308
309     
310     // do something  
311     switch (line->special)
312     {
313         // MANUALS
314       case 1:           // Vertical Door
315       case 26:          // Blue Door/Locked
316       case 27:          // Yellow Door /Locked
317       case 28:          // Red Door /Locked
318
319       case 31:          // Manual door open
320       case 32:          // Blue locked door open
321       case 33:          // Red locked door open
322       case 34:          // Yellow locked door open
323
324       case 117:         // Blazing door raise
325       case 118:         // Blazing door open
326         EV_VerticalDoor (line, thing);
327         break;
328         
329         //UNUSED - Door Slide Open&Close
330         // case 124:
331         // EV_SlidingDoor (line, thing);
332         // break;
333
334         // SWITCHES
335       case 7:
336         // Build Stairs
337         if (EV_BuildStairs(line,build8))
338             P_ChangeSwitchTexture(line,0);
339         break;
340
341       case 9:
342         // Change Donut
343         if (EV_DoDonut(line))
344             P_ChangeSwitchTexture(line,0);
345         break;
346         
347       case 11:
348         // Exit level
349         P_ChangeSwitchTexture(line,0);
350         G_ExitLevel ();
351         break;
352         
353       case 14:
354         // Raise Floor 32 and change texture
355         if (EV_DoPlat(line,raiseAndChange,32))
356             P_ChangeSwitchTexture(line,0);
357         break;
358         
359       case 15:
360         // Raise Floor 24 and change texture
361         if (EV_DoPlat(line,raiseAndChange,24))
362             P_ChangeSwitchTexture(line,0);
363         break;
364         
365       case 18:
366         // Raise Floor to next highest floor
367         if (EV_DoFloor(line, raiseFloorToNearest))
368             P_ChangeSwitchTexture(line,0);
369         break;
370         
371       case 20:
372         // Raise Plat next highest floor and change texture
373         if (EV_DoPlat(line,raiseToNearestAndChange,0))
374             P_ChangeSwitchTexture(line,0);
375         break;
376         
377       case 21:
378         // PlatDownWaitUpStay
379         if (EV_DoPlat(line,downWaitUpStay,0))
380             P_ChangeSwitchTexture(line,0);
381         break;
382         
383       case 23:
384         // Lower Floor to Lowest
385         if (EV_DoFloor(line,lowerFloorToLowest))
386             P_ChangeSwitchTexture(line,0);
387         break;
388         
389       case 29:
390         // Raise Door
391         if (EV_DoDoor(line,Normal))
392             P_ChangeSwitchTexture(line,0);
393         break;
394         
395       case 41:
396         // Lower Ceiling to Floor
397         if (EV_DoCeiling(line,lowerToFloor))
398             P_ChangeSwitchTexture(line,0);
399         break;
400         
401       case 71:
402         // Turbo Lower Floor
403         if (EV_DoFloor(line,turboLower))
404             P_ChangeSwitchTexture(line,0);
405         break;
406         
407       case 49:
408         // Ceiling Crush And Raise
409         if (EV_DoCeiling(line,crushAndRaise))
410             P_ChangeSwitchTexture(line,0);
411         break;
412         
413       case 50:
414         // Close Door
415         if (EV_DoDoor(line,Close))
416             P_ChangeSwitchTexture(line,0);
417         break;
418         
419       case 51:
420         // Secret EXIT
421         P_ChangeSwitchTexture(line,0);
422         G_SecretExitLevel ();
423         break;
424         
425       case 55:
426         // Raise Floor Crush
427         if (EV_DoFloor(line,raiseFloorCrush))
428             P_ChangeSwitchTexture(line,0);
429         break;
430         
431       case 101:
432         // Raise Floor
433         if (EV_DoFloor(line,raiseFloor))
434             P_ChangeSwitchTexture(line,0);
435         break;
436         
437       case 102:
438         // Lower Floor to Surrounding floor height
439         if (EV_DoFloor(line,lowerFloor))
440             P_ChangeSwitchTexture(line,0);
441         break;
442         
443       case 103:
444         // Open Door
445         if (EV_DoDoor(line,Open))
446             P_ChangeSwitchTexture(line,0);
447         break;
448         
449       case 111:
450         // Blazing Door Raise (faster than TURBO!)
451         if (EV_DoDoor (line,BlazeRaise))
452             P_ChangeSwitchTexture(line,0);
453         break;
454         
455       case 112:
456         // Blazing Door Open (faster than TURBO!)
457         if (EV_DoDoor (line,BlazeOpen))
458             P_ChangeSwitchTexture(line,0);
459         break;
460         
461       case 113:
462         // Blazing Door Close (faster than TURBO!)
463         if (EV_DoDoor (line,BlazeClose))
464             P_ChangeSwitchTexture(line,0);
465         break;
466         
467       case 122:
468         // Blazing PlatDownWaitUpStay
469         if (EV_DoPlat(line,blazeDWUS,0))
470             P_ChangeSwitchTexture(line,0);
471         break;
472         
473       case 127:
474         // Build Stairs Turbo 16
475         if (EV_BuildStairs(line,turbo16))
476             P_ChangeSwitchTexture(line,0);
477         break;
478         
479       case 131:
480         // Raise Floor Turbo
481         if (EV_DoFloor(line,raiseFloorTurbo))
482             P_ChangeSwitchTexture(line,0);
483         break;
484         
485       case 133:
486         // BlzOpenDoor BLUE
487       case 135:
488         // BlzOpenDoor RED
489       case 137:
490         // BlzOpenDoor YELLOW
491         if (EV_DoLockedDoor (line,BlazeOpen,thing))
492             P_ChangeSwitchTexture(line,0);
493         break;
494         
495       case 140:
496         // Raise Floor 512
497         if (EV_DoFloor(line,raiseFloor512))
498             P_ChangeSwitchTexture(line,0);
499         break;
500         
501         // BUTTONS
502       case 42:
503         // Close Door
504         if (EV_DoDoor(line,Close))
505             P_ChangeSwitchTexture(line,1);
506         break;
507         
508       case 43:
509         // Lower Ceiling to Floor
510         if (EV_DoCeiling(line,lowerToFloor))
511             P_ChangeSwitchTexture(line,1);
512         break;
513         
514       case 45:
515         // Lower Floor to Surrounding floor height
516         if (EV_DoFloor(line,lowerFloor))
517             P_ChangeSwitchTexture(line,1);
518         break;
519         
520       case 60:
521         // Lower Floor to Lowest
522         if (EV_DoFloor(line,lowerFloorToLowest))
523             P_ChangeSwitchTexture(line,1);
524         break;
525         
526       case 61:
527         // Open Door
528         if (EV_DoDoor(line,Open))
529             P_ChangeSwitchTexture(line,1);
530         break;
531         
532       case 62:
533         // PlatDownWaitUpStay
534         if (EV_DoPlat(line,downWaitUpStay,1))
535             P_ChangeSwitchTexture(line,1);
536         break;
537         
538       case 63:
539         // Raise Door
540         if (EV_DoDoor(line,Normal))
541             P_ChangeSwitchTexture(line,1);
542         break;
543         
544       case 64:
545         // Raise Floor to ceiling
546         if (EV_DoFloor(line,raiseFloor))
547             P_ChangeSwitchTexture(line,1);
548         break;
549         
550       case 66:
551         // Raise Floor 24 and change texture
552         if (EV_DoPlat(line,raiseAndChange,24))
553             P_ChangeSwitchTexture(line,1);
554         break;
555         
556       case 67:
557         // Raise Floor 32 and change texture
558         if (EV_DoPlat(line,raiseAndChange,32))
559             P_ChangeSwitchTexture(line,1);
560         break;
561         
562       case 65:
563         // Raise Floor Crush
564         if (EV_DoFloor(line,raiseFloorCrush))
565             P_ChangeSwitchTexture(line,1);
566         break;
567         
568       case 68:
569         // Raise Plat to next highest floor and change texture
570         if (EV_DoPlat(line,raiseToNearestAndChange,0))
571             P_ChangeSwitchTexture(line,1);
572         break;
573         
574       case 69:
575         // Raise Floor to next highest floor
576         if (EV_DoFloor(line, raiseFloorToNearest))
577             P_ChangeSwitchTexture(line,1);
578         break;
579         
580       case 70:
581         // Turbo Lower Floor
582         if (EV_DoFloor(line,turboLower))
583             P_ChangeSwitchTexture(line,1);
584         break;
585         
586       case 114:
587         // Blazing Door Raise (faster than TURBO!)
588         if (EV_DoDoor (line,BlazeRaise))
589             P_ChangeSwitchTexture(line,1);
590         break;
591         
592       case 115:
593         // Blazing Door Open (faster than TURBO!)
594         if (EV_DoDoor (line,BlazeOpen))
595             P_ChangeSwitchTexture(line,1);
596         break;
597         
598       case 116:
599         // Blazing Door Close (faster than TURBO!)
600         if (EV_DoDoor (line,BlazeClose))
601             P_ChangeSwitchTexture(line,1);
602         break;
603         
604       case 123:
605         // Blazing PlatDownWaitUpStay
606         if (EV_DoPlat(line,blazeDWUS,0))
607             P_ChangeSwitchTexture(line,1);
608         break;
609         
610       case 132:
611         // Raise Floor Turbo
612         if (EV_DoFloor(line,raiseFloorTurbo))
613             P_ChangeSwitchTexture(line,1);
614         break;
615         
616       case 99:
617         // BlzOpenDoor BLUE
618       case 134:
619         // BlzOpenDoor RED
620       case 136:
621         // BlzOpenDoor YELLOW
622         if (EV_DoLockedDoor (line,BlazeOpen,thing))
623             P_ChangeSwitchTexture(line,1);
624         break;
625         
626       case 138:
627         // Light Turn On
628         EV_LightTurnOn(line,255);
629         P_ChangeSwitchTexture(line,1);
630         break;
631         
632       case 139:
633         // Light Turn Off
634         EV_LightTurnOn(line,35);
635         P_ChangeSwitchTexture(line,1);
636         break;
637                         
638     }
639         
640     return true;
641 }
642