1 // Emacs style mode select -*- C++ -*-
2 //-----------------------------------------------------------------------------
6 // Copyright (C) 1993-1996 by id Software, Inc.
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.
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
21 // Switches, buttons. Two-state animation. Exits.
23 //-----------------------------------------------------------------------------
26 rcsid[] = "$Id: p_switch.c,v 1.3 1997/01/28 22:08:29 b1 Exp $";
46 // CHANGE THE TEXTURE OF A WALL SWITCH TO ITS OPPOSITE
48 switchlist_t alphSwitchList[] =
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},
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},
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},
99 int switchlist[MAXSWITCHES * 2];
101 button_t buttonlist[MAXBUTTONS];
105 // Only called at game initialization.
107 void P_InitSwitchList(void)
115 if (gamemode == registered)
118 if ( gamemode == commercial )
121 for (index = 0,i = 0;i < MAXSWITCHES;i++)
123 if (!alphSwitchList[i].episode)
125 numswitches = index/2;
126 switchlist[index] = -1;
130 if (alphSwitchList[i].episode <= episode)
132 switchlist[index++] = R_TextureNumForName(alphSwitchList[i].name1);
133 switchlist[index++] = R_TextureNumForName(alphSwitchList[i].name2);
140 // Start a button counting down till it turns off.
151 // See if button is already pressed
152 for (i = 0;i < MAXBUTTONS;i++)
154 if (buttonlist[i].btimer
155 && buttonlist[i].line == line)
164 for (i = 0;i < MAXBUTTONS;i++)
166 if (!buttonlist[i].btimer)
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;
177 I_Error("P_StartButton: no button slots left!");
185 // Function that changes wall texture.
186 // Tell it if switch is ok to use again (1=yes, it's a button).
189 P_ChangeSwitchTexture
202 texTop = sides[line->sidenum[0]].toptexture;
203 texMid = sides[line->sidenum[0]].midtexture;
204 texBot = sides[line->sidenum[0]].bottomtexture;
209 if (line->special == 11)
212 for (i = 0;i < numswitches*2;i++)
214 if (switchlist[i] == texTop)
216 S_StartSound(buttonlist->soundorg,sound);
217 sides[line->sidenum[0]].toptexture = switchlist[i^1];
220 P_StartButton(line,top,switchlist[i],BUTTONTIME);
226 if (switchlist[i] == texMid)
228 S_StartSound(buttonlist->soundorg,sound);
229 sides[line->sidenum[0]].midtexture = switchlist[i^1];
232 P_StartButton(line, middle,switchlist[i],BUTTONTIME);
238 if (switchlist[i] == texBot)
240 S_StartSound(buttonlist->soundorg,sound);
241 sides[line->sidenum[0]].bottomtexture = switchlist[i^1];
244 P_StartButton(line, bottom,switchlist[i],BUTTONTIME);
260 // Called when a thing uses a special line.
261 // Only the front sides of lines are usable.
271 // Use the back sides of VERY SPECIAL lines...
274 switch(line->special)
277 // Sliding door open&close
288 // Switches that other things can activate.
291 // never open secret doors
292 if (line->flags & ML_SECRET)
295 switch(line->special)
297 case 1: // MANUAL DOOR RAISE
298 case 32: // MANUAL BLUE
299 case 33: // MANUAL RED
300 case 34: // MANUAL YELLOW
311 switch (line->special)
314 case 1: // Vertical Door
315 case 26: // Blue Door/Locked
316 case 27: // Yellow Door /Locked
317 case 28: // Red Door /Locked
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
324 case 117: // Blazing door raise
325 case 118: // Blazing door open
326 EV_VerticalDoor (line, thing);
329 //UNUSED - Door Slide Open&Close
331 // EV_SlidingDoor (line, thing);
337 if (EV_BuildStairs(line,build8))
338 P_ChangeSwitchTexture(line,0);
343 if (EV_DoDonut(line))
344 P_ChangeSwitchTexture(line,0);
349 P_ChangeSwitchTexture(line,0);
354 // Raise Floor 32 and change texture
355 if (EV_DoPlat(line,raiseAndChange,32))
356 P_ChangeSwitchTexture(line,0);
360 // Raise Floor 24 and change texture
361 if (EV_DoPlat(line,raiseAndChange,24))
362 P_ChangeSwitchTexture(line,0);
366 // Raise Floor to next highest floor
367 if (EV_DoFloor(line, raiseFloorToNearest))
368 P_ChangeSwitchTexture(line,0);
372 // Raise Plat next highest floor and change texture
373 if (EV_DoPlat(line,raiseToNearestAndChange,0))
374 P_ChangeSwitchTexture(line,0);
378 // PlatDownWaitUpStay
379 if (EV_DoPlat(line,downWaitUpStay,0))
380 P_ChangeSwitchTexture(line,0);
384 // Lower Floor to Lowest
385 if (EV_DoFloor(line,lowerFloorToLowest))
386 P_ChangeSwitchTexture(line,0);
391 if (EV_DoDoor(line,Normal))
392 P_ChangeSwitchTexture(line,0);
396 // Lower Ceiling to Floor
397 if (EV_DoCeiling(line,lowerToFloor))
398 P_ChangeSwitchTexture(line,0);
403 if (EV_DoFloor(line,turboLower))
404 P_ChangeSwitchTexture(line,0);
408 // Ceiling Crush And Raise
409 if (EV_DoCeiling(line,crushAndRaise))
410 P_ChangeSwitchTexture(line,0);
415 if (EV_DoDoor(line,Close))
416 P_ChangeSwitchTexture(line,0);
421 P_ChangeSwitchTexture(line,0);
422 G_SecretExitLevel ();
427 if (EV_DoFloor(line,raiseFloorCrush))
428 P_ChangeSwitchTexture(line,0);
433 if (EV_DoFloor(line,raiseFloor))
434 P_ChangeSwitchTexture(line,0);
438 // Lower Floor to Surrounding floor height
439 if (EV_DoFloor(line,lowerFloor))
440 P_ChangeSwitchTexture(line,0);
445 if (EV_DoDoor(line,Open))
446 P_ChangeSwitchTexture(line,0);
450 // Blazing Door Raise (faster than TURBO!)
451 if (EV_DoDoor (line,BlazeRaise))
452 P_ChangeSwitchTexture(line,0);
456 // Blazing Door Open (faster than TURBO!)
457 if (EV_DoDoor (line,BlazeOpen))
458 P_ChangeSwitchTexture(line,0);
462 // Blazing Door Close (faster than TURBO!)
463 if (EV_DoDoor (line,BlazeClose))
464 P_ChangeSwitchTexture(line,0);
468 // Blazing PlatDownWaitUpStay
469 if (EV_DoPlat(line,blazeDWUS,0))
470 P_ChangeSwitchTexture(line,0);
474 // Build Stairs Turbo 16
475 if (EV_BuildStairs(line,turbo16))
476 P_ChangeSwitchTexture(line,0);
481 if (EV_DoFloor(line,raiseFloorTurbo))
482 P_ChangeSwitchTexture(line,0);
490 // BlzOpenDoor YELLOW
491 if (EV_DoLockedDoor (line,BlazeOpen,thing))
492 P_ChangeSwitchTexture(line,0);
497 if (EV_DoFloor(line,raiseFloor512))
498 P_ChangeSwitchTexture(line,0);
504 if (EV_DoDoor(line,Close))
505 P_ChangeSwitchTexture(line,1);
509 // Lower Ceiling to Floor
510 if (EV_DoCeiling(line,lowerToFloor))
511 P_ChangeSwitchTexture(line,1);
515 // Lower Floor to Surrounding floor height
516 if (EV_DoFloor(line,lowerFloor))
517 P_ChangeSwitchTexture(line,1);
521 // Lower Floor to Lowest
522 if (EV_DoFloor(line,lowerFloorToLowest))
523 P_ChangeSwitchTexture(line,1);
528 if (EV_DoDoor(line,Open))
529 P_ChangeSwitchTexture(line,1);
533 // PlatDownWaitUpStay
534 if (EV_DoPlat(line,downWaitUpStay,1))
535 P_ChangeSwitchTexture(line,1);
540 if (EV_DoDoor(line,Normal))
541 P_ChangeSwitchTexture(line,1);
545 // Raise Floor to ceiling
546 if (EV_DoFloor(line,raiseFloor))
547 P_ChangeSwitchTexture(line,1);
551 // Raise Floor 24 and change texture
552 if (EV_DoPlat(line,raiseAndChange,24))
553 P_ChangeSwitchTexture(line,1);
557 // Raise Floor 32 and change texture
558 if (EV_DoPlat(line,raiseAndChange,32))
559 P_ChangeSwitchTexture(line,1);
564 if (EV_DoFloor(line,raiseFloorCrush))
565 P_ChangeSwitchTexture(line,1);
569 // Raise Plat to next highest floor and change texture
570 if (EV_DoPlat(line,raiseToNearestAndChange,0))
571 P_ChangeSwitchTexture(line,1);
575 // Raise Floor to next highest floor
576 if (EV_DoFloor(line, raiseFloorToNearest))
577 P_ChangeSwitchTexture(line,1);
582 if (EV_DoFloor(line,turboLower))
583 P_ChangeSwitchTexture(line,1);
587 // Blazing Door Raise (faster than TURBO!)
588 if (EV_DoDoor (line,BlazeRaise))
589 P_ChangeSwitchTexture(line,1);
593 // Blazing Door Open (faster than TURBO!)
594 if (EV_DoDoor (line,BlazeOpen))
595 P_ChangeSwitchTexture(line,1);
599 // Blazing Door Close (faster than TURBO!)
600 if (EV_DoDoor (line,BlazeClose))
601 P_ChangeSwitchTexture(line,1);
605 // Blazing PlatDownWaitUpStay
606 if (EV_DoPlat(line,blazeDWUS,0))
607 P_ChangeSwitchTexture(line,1);
612 if (EV_DoFloor(line,raiseFloorTurbo))
613 P_ChangeSwitchTexture(line,1);
621 // BlzOpenDoor YELLOW
622 if (EV_DoLockedDoor (line,BlazeOpen,thing))
623 P_ChangeSwitchTexture(line,1);
628 EV_LightTurnOn(line,255);
629 P_ChangeSwitchTexture(line,1);
634 EV_LightTurnOn(line,35);
635 P_ChangeSwitchTexture(line,1);