]> icculus.org git repositories - theoddone33/hhexen.git/blob - base/p_switch.c
Fix stupid wadfile problem
[theoddone33/hhexen.git] / base / p_switch.c
1
2 //**************************************************************************
3 //**
4 //** p_switch.c : Heretic 2 : Raven Software, Corp.
5 //**
6 //** $RCSfile$
7 //** $Revision$
8 //** $Date$
9 //** $Author$
10 //**
11 //**************************************************************************
12
13 #include "h2def.h"
14 #include "p_local.h"
15 #include "soundst.h"
16
17 //==================================================================
18 //
19 //      CHANGE THE TEXTURE OF A WALL SWITCH TO ITS OPPOSITE
20 //
21 //==================================================================
22 switchlist_t alphSwitchList[] =
23 {
24         { "SW_1_UP", "SW_1_DN", SFX_SWITCH1 },
25         { "SW_2_UP", "SW_2_DN", SFX_SWITCH1 },
26         { "VALVE1", "VALVE2", SFX_VALVE_TURN },     // Not in in demo wad - KR
27         { "SW51_OFF", "SW51_ON", SFX_SWITCH2 },     //
28         { "SW52_OFF", "SW52_ON", SFX_SWITCH2 },
29         { "SW53_UP", "SW53_DN", SFX_ROPE_PULL },    //
30         { "PUZZLE5", "PUZZLE9", SFX_SWITCH1 },      //
31         { "PUZZLE6", "PUZZLE10", SFX_SWITCH1 },     //
32         { "PUZZLE7", "PUZZLE11", SFX_SWITCH1 },     //
33         { "PUZZLE8", "PUZZLE12", SFX_SWITCH1 },     //
34         {"\0", "\0", 0}
35 };
36
37 int switchlist[MAXSWITCHES * 2];
38 int numswitches;
39 button_t buttonlist[MAXBUTTONS];
40
41 /*
42 ===============
43 =
44 = P_InitSwitchList
45 =
46 = Only called at game initialization
47 =
48 ===============
49 */
50
51 void P_InitSwitchList(void)
52 {
53         int             i;
54         int             index;
55
56         for (index = 0, i = 0; i < MAXSWITCHES; i++)
57         {
58                 if(!alphSwitchList[i].soundID)
59                 {
60                         numswitches = index/2;
61                         switchlist[index] = -1;
62                         break;
63                 }
64                 switchlist[index++] = R_TextureNumForName(alphSwitchList[i].name1);
65                 switchlist[index++] = R_TextureNumForName(alphSwitchList[i].name2);
66         }
67 }
68
69 //==================================================================
70 //
71 //      Start a button counting down till it turns off.
72 //
73 //==================================================================
74 void P_StartButton(line_t *line,bwhere_e w,int texture,int time)
75 {
76         int             i;
77
78         for (i = 0;i < MAXBUTTONS;i++)
79         {
80                 if (!buttonlist[i].btimer)
81                 {
82                         buttonlist[i].line = line;
83                         buttonlist[i].where = w;
84                         buttonlist[i].btexture = texture;
85                         buttonlist[i].btimer = time;
86                         buttonlist[i].soundorg = (mobj_t *)&line->frontsector->soundorg;
87                         return;
88                 }
89         }
90         I_Error("P_StartButton: no button slots left!");
91 }
92
93 //==================================================================
94 //
95 //      Function that changes wall texture.
96 //      Tell it if switch is ok to use again (1=yes, it's a button).
97 //
98 //==================================================================
99 void P_ChangeSwitchTexture(line_t *line, int useAgain)
100 {
101         int     texTop;
102         int     texMid;
103         int     texBot;
104         int     i;
105
106         texTop = sides[line->sidenum[0]].toptexture;
107         texMid = sides[line->sidenum[0]].midtexture;
108         texBot = sides[line->sidenum[0]].bottomtexture;
109
110         for (i = 0; i < numswitches*2; i++)
111         {
112                 if (switchlist[i] == texTop)
113                 {
114                         S_StartSound((mobj_t *)&line->frontsector->soundorg, 
115                                 alphSwitchList[i/2].soundID);
116                         sides[line->sidenum[0]].toptexture = switchlist[i^1];
117                         if(useAgain)
118                         {
119                                 P_StartButton(line, SWTCH_TOP, switchlist[i], BUTTONTIME);
120                         }
121                         return;
122                 }
123                 else if (switchlist[i] == texMid)
124                 {
125                         S_StartSound((mobj_t *)&line->frontsector->soundorg,
126                                 alphSwitchList[i/2].soundID);
127                         sides[line->sidenum[0]].midtexture = switchlist[i^1];
128                         if(useAgain)
129                         {
130                                 P_StartButton(line, SWTCH_MIDDLE, switchlist[i], BUTTONTIME);
131                         }
132                         return;
133                 }
134                 else if (switchlist[i] == texBot)
135                 {
136                         S_StartSound((mobj_t *)&line->frontsector->soundorg,
137                                 alphSwitchList[i/2].soundID);
138                         sides[line->sidenum[0]].bottomtexture = switchlist[i^1];
139                         if(useAgain)
140                         {
141                                 P_StartButton(line, SWTCH_BOTTOM, switchlist[i], BUTTONTIME);
142                         }
143                         return;
144                 }
145         }
146 }
147