]> icculus.org git repositories - theoddone33/hheretic.git/blob - base/p_switch.c
Minor cleanups
[theoddone33/hheretic.git] / base / p_switch.c
1
2 #include "doomdef.h"
3 #include "p_local.h"
4 #include "soundst.h"
5
6 //==================================================================
7 //
8 //      CHANGE THE TEXTURE OF A WALL SWITCH TO ITS OPPOSITE
9 //
10 //==================================================================
11 switchlist_t alphSwitchList[] =
12 {
13         {"SW1OFF",              "SW1ON",        1},
14         {"SW2OFF",              "SW2ON",        1},
15
16 /*
17         {"SW1CTY",              "SW2CTY",       1},
18         {"SW1ORGRY",    "SW2ORGRY",     1},
19         {"SW1GRSTN",    "SW2GRSTN",     1},
20         {"SW1SNDP",             "SW2SNDP",      1},
21         {"SW1SPINE",    "SW2SPINE",     1},
22         {"SW1SQPEB",    "SW2SQPEB",     1},
23         {"SW1TRST1",    "SW2TRST1",     1},
24         {"SW1CSTL",             "SW2CSTL",      1},
25         {"SW1MOSS",             "SW2MOSS",      1},
26         {"SW1SNDSQ",    "SW2SNDSQ",     1},
27         {"SW1RED",              "SW2RED",       1},
28         {"SW1WOOD",             "SW2WOOD",      1},
29         {"SW1BROWN",    "SW2BROWN",     1},
30
31         {"SW1TRST2",    "SW2TRST2",     2},
32         {"SW1MSC",              "SW2MSC",       2},
33         {"SW1MSC2",             "SW2MSC2",      2},
34         {"SW1GRDMD",    "SW2GRDMD",     2},
35 */
36
37 #if 0
38         {"SW1BRCOM",    "SW2BRCOM",     1},
39         {"SW1BRN1",             "SW2BRN1",      1},
40         {"SW1BRN2",             "SW2BRN2",      1},
41         {"SW1BRNGN",    "SW2BRNGN",     1},
42         {"SW1BROWN",    "SW2BROWN",     1},
43         {"SW1COMM",             "SW2COMM",      1},
44         {"SW1COMP",             "SW2COMP",      1},
45         {"SW1DIRT",             "SW2DIRT",      1},
46         {"SW1EXIT",             "SW2EXIT",      1},
47         {"SW1GRAY",             "SW2GRAY",      1},
48         {"SW1GRAY1",    "SW2GRAY1",     1},
49         {"SW1METAL",    "SW2METAL",     1},
50         {"SW1PIPE",             "SW2PIPE",      1},
51         {"SW1SLAD",             "SW2SLAD",      1},
52         {"SW1STARG",    "SW2STARG",     1},
53         {"SW1STON1",    "SW2STON1",     1},
54         {"SW1STON2",    "SW2STON2",     1},
55         {"SW1STONE",    "SW2STONE",     1},
56         {"SW1STRTN",    "SW2STRTN",     1},
57         
58         {"SW1BLUE",             "SW2BLUE",      2},
59         {"SW1CMT",              "SW2CMT",       2},
60         {"SW1GARG",             "SW2GARG",      2},
61         {"SW1GSTON",    "SW2GSTON",     2},
62         {"SW1HOT",              "SW2HOT",       2},
63         {"SW1LION",             "SW2LION",      2},
64         {"SW1SATYR",    "SW2SATYR",     2},
65         {"SW1SKIN",             "SW2SKIN",      2},
66         {"SW1VINE",             "SW2VINE",      2},
67         {"SW1WOOD",             "SW2WOOD",      2},
68 #endif  
69         {"\0",                  "\0",           0}
70 };
71
72 int                     switchlist[MAXSWITCHES * 2];
73 int                     numswitches;
74 button_t        buttonlist[MAXBUTTONS];
75
76 /*
77 ===============
78 =
79 = P_InitSwitchList
80 =
81 = Only called at game initialization
82 =
83 ===============
84 */
85
86 void P_InitSwitchList(void)
87 {
88         int             i;
89         int             index;
90         int             episode;
91         
92         episode = 1;
93         if (!shareware)
94                 episode = 2;
95                 
96         for (index = 0,i = 0;i < MAXSWITCHES;i++)
97         {
98                 if (!alphSwitchList[i].episode)
99                 {
100                         numswitches = index/2;
101                         switchlist[index] = -1;
102                         break;
103                 }
104                 
105                 if (alphSwitchList[i].episode <= episode)
106                 {
107                         switchlist[index++] = R_TextureNumForName(alphSwitchList[i].name1);
108                         switchlist[index++] = R_TextureNumForName(alphSwitchList[i].name2);
109                 }
110         }
111 }
112
113 //==================================================================
114 //
115 //      Start a button counting down till it turns off.
116 //
117 //==================================================================
118 void P_StartButton(line_t *line,bwhere_e w,int texture,int time)
119 {
120         int             i;
121         
122         for (i = 0;i < MAXBUTTONS;i++)
123                 if (!buttonlist[i].btimer)
124                 {
125                         buttonlist[i].line = line;
126                         buttonlist[i].where = w;
127                         buttonlist[i].btexture = texture;
128                         buttonlist[i].btimer = time;
129                         buttonlist[i].soundorg = (mobj_t *)&line->frontsector->soundorg;
130                         return;
131                 }
132                 
133         I_Error("P_StartButton: no button slots left!");
134 }
135
136 //==================================================================
137 //
138 //      Function that changes wall texture.
139 //      Tell it if switch is ok to use again (1=yes, it's a button).
140 //
141 //==================================================================
142 void P_ChangeSwitchTexture(line_t *line,int useAgain)
143 {
144         int     texTop;
145         int     texMid;
146         int     texBot;
147         int     i;
148         int     sound;
149         
150         if (!useAgain)
151                 line->special = 0;
152
153         texTop = sides[line->sidenum[0]].toptexture;
154         texMid = sides[line->sidenum[0]].midtexture;
155         texBot = sides[line->sidenum[0]].bottomtexture;
156
157         sound = sfx_switch;
158         //if (line->special == 11) // EXIT SWITCH?
159         //      sound = sfx_swtchx;
160         
161         for (i = 0;i < numswitches*2;i++)
162                 if (switchlist[i] == texTop)
163                 {
164                         S_StartSound(buttonlist->soundorg,sound);
165                         sides[line->sidenum[0]].toptexture = switchlist[i^1];
166                         if (useAgain)
167                                 P_StartButton(line,top,switchlist[i],BUTTONTIME);
168                         return;
169                 }
170                 else
171                 if (switchlist[i] == texMid)
172                 {
173                         S_StartSound(buttonlist->soundorg,sound);
174                         sides[line->sidenum[0]].midtexture = switchlist[i^1];
175                         if (useAgain)
176                                 P_StartButton(line, middle,switchlist[i],BUTTONTIME);
177                         return;
178                 }
179                 else
180                 if (switchlist[i] == texBot)
181                 {
182                         S_StartSound(buttonlist->soundorg,sound);
183                         sides[line->sidenum[0]].bottomtexture = switchlist[i^1];
184                         if (useAgain)
185                                 P_StartButton(line, bottom,switchlist[i],BUTTONTIME);
186                         return;
187                 }
188 }
189
190 /*
191 ==============================================================================
192 =
193 = P_UseSpecialLine
194 =
195 = Called when a thing uses a special line
196 = Only the front sides of lines are usable
197 ===============================================================================
198 */
199
200 boolean P_UseSpecialLine ( mobj_t *thing, line_t *line)
201 {               
202         //
203         //      Switches that other things can activate
204         //
205         if (!thing->player)
206         {
207                 if (line->flags & ML_SECRET)
208                         return false;           // never open secret doors
209                 switch(line->special)
210                 {
211                         case 1:         // MANUAL DOOR RAISE
212                         case 32:        // MANUAL BLUE
213                         case 33:        // MANUAL RED
214                         case 34:        // MANUAL YELLOW
215                                 break;
216                         default:
217                                 return false;
218                 }
219         }
220         
221         //
222         // do something
223         //      
224         switch (line->special)
225         {
226                 //===============================================
227                 //      MANUALS
228                 //===============================================
229                 case 1:                 // Vertical Door
230                 case 26:                // Blue Door/Locked
231                 case 27:                // Yellow Door /Locked
232                 case 28:                // Red Door /Locked
233
234                 case 31:                // Manual door open
235                 case 32:                // Blue locked door open
236                 case 33:                // Red locked door open
237                 case 34:                // Yellow locked door open
238                         EV_VerticalDoor (line, thing);
239                         break;
240                 //===============================================
241                 //      SWITCHES
242                 //===============================================
243                 case 7: // Switch_Build_Stairs (8 pixel steps)
244                         if(EV_BuildStairs(line, 8*FRACUNIT))
245                         {
246                                 P_ChangeSwitchTexture(line, 0);
247                         }
248                         break;
249                 case 107: // Switch_Build_Stairs_16 (16 pixel steps)
250                         if(EV_BuildStairs(line, 16*FRACUNIT))
251                         {
252                                 P_ChangeSwitchTexture(line, 0);
253                         }
254                         break;
255                 case 9:                 // Change Donut
256                         if (EV_DoDonut(line))
257                                 P_ChangeSwitchTexture(line,0);
258                         break;
259                 case 11:                // Exit level
260                         G_ExitLevel ();
261                         P_ChangeSwitchTexture(line,0);
262                         break;
263                 case 14:                // Raise Floor 32 and change texture
264                         if (EV_DoPlat(line,raiseAndChange,32))
265                                 P_ChangeSwitchTexture(line,0);
266                         break;
267                 case 15:                // Raise Floor 24 and change texture
268                         if (EV_DoPlat(line,raiseAndChange,24))
269                                 P_ChangeSwitchTexture(line,0);
270                         break;
271                 case 18:                // Raise Floor to next highest floor
272                         if (EV_DoFloor(line, raiseFloorToNearest))
273                                 P_ChangeSwitchTexture(line,0);
274                         break;
275                 case 20:                // Raise Plat next highest floor and change texture
276                         if (EV_DoPlat(line,raiseToNearestAndChange,0))
277                                 P_ChangeSwitchTexture(line,0);
278                         break;
279                 case 21:                // PlatDownWaitUpStay
280                         if (EV_DoPlat(line,downWaitUpStay,0))
281                                 P_ChangeSwitchTexture(line,0);
282                         break;
283                 case 23:                // Lower Floor to Lowest
284                         if (EV_DoFloor(line,lowerFloorToLowest))
285                                 P_ChangeSwitchTexture(line,0);
286                         break;
287                 case 29:                // Raise Door
288                         if (EV_DoDoor(line,normal,VDOORSPEED))
289                                 P_ChangeSwitchTexture(line,0);
290                         break;
291                 case 41:                // Lower Ceiling to Floor
292                         if (EV_DoCeiling(line,lowerToFloor))
293                                 P_ChangeSwitchTexture(line,0);
294                         break;
295                 case 71:                // Turbo Lower Floor
296                         if (EV_DoFloor(line,turboLower))
297                                 P_ChangeSwitchTexture(line,0);
298                         break;
299                 case 49:                // Lower Ceiling And Crush
300                         if (EV_DoCeiling(line,lowerAndCrush))
301                                 P_ChangeSwitchTexture(line,0);
302                         break;
303                 case 50:                // Close Door
304                         if (EV_DoDoor(line,close,VDOORSPEED))
305                                 P_ChangeSwitchTexture(line,0);
306                         break;
307                 case 51:                // Secret EXIT
308                         G_SecretExitLevel ();
309                         P_ChangeSwitchTexture(line,0);
310                         break;
311                 case 55:                // Raise Floor Crush
312                         if (EV_DoFloor(line,raiseFloorCrush))
313                                 P_ChangeSwitchTexture(line,0);
314                         break;
315                 case 101:               // Raise Floor
316                         if (EV_DoFloor(line,raiseFloor))
317                                 P_ChangeSwitchTexture(line,0);
318                         break;
319                 case 102:               // Lower Floor to Surrounding floor height
320                         if (EV_DoFloor(line,lowerFloor))
321                                 P_ChangeSwitchTexture(line,0);
322                         break;
323                 case 103:               // Open Door
324                         if (EV_DoDoor(line,open,VDOORSPEED))
325                                 P_ChangeSwitchTexture(line,0);
326                         break;
327                 //===============================================
328                 //      BUTTONS
329                 //===============================================
330                 case 42:                // Close Door
331                         if (EV_DoDoor(line,close,VDOORSPEED))
332                                 P_ChangeSwitchTexture(line,1);
333                         break;
334                 case 43:                // Lower Ceiling to Floor
335                         if (EV_DoCeiling(line,lowerToFloor))
336                                 P_ChangeSwitchTexture(line,1);
337                         break;
338                 case 45:                // Lower Floor to Surrounding floor height
339                         if (EV_DoFloor(line,lowerFloor))
340                                 P_ChangeSwitchTexture(line,1);
341                         break;
342                 case 60:                // Lower Floor to Lowest
343                         if (EV_DoFloor(line,lowerFloorToLowest))
344                                 P_ChangeSwitchTexture(line,1);
345                         break;
346                 case 61:                // Open Door
347                         if (EV_DoDoor(line,open,VDOORSPEED))
348                                 P_ChangeSwitchTexture(line,1);
349                         break;
350                 case 62:                // PlatDownWaitUpStay
351                         if (EV_DoPlat(line,downWaitUpStay,1))
352                                 P_ChangeSwitchTexture(line,1);
353                         break;
354                 case 63:                // Raise Door
355                         if (EV_DoDoor(line,normal,VDOORSPEED))
356                                 P_ChangeSwitchTexture(line,1);
357                         break;
358                 case 64:                // Raise Floor to ceiling
359                         if (EV_DoFloor(line,raiseFloor))
360                                 P_ChangeSwitchTexture(line,1);
361                         break;
362                 case 66:                // Raise Floor 24 and change texture
363                         if (EV_DoPlat(line,raiseAndChange,24))
364                                 P_ChangeSwitchTexture(line,1);
365                         break;
366                 case 67:                // Raise Floor 32 and change texture
367                         if (EV_DoPlat(line,raiseAndChange,32))
368                                 P_ChangeSwitchTexture(line,1);
369                         break;
370                 case 65:                // Raise Floor Crush
371                         if (EV_DoFloor(line,raiseFloorCrush))
372                                 P_ChangeSwitchTexture(line,1);
373                         break;
374                 case 68:                // Raise Plat to next highest floor and change texture
375                         if (EV_DoPlat(line,raiseToNearestAndChange,0))
376                                 P_ChangeSwitchTexture(line,1);
377                         break;
378                 case 69:                // Raise Floor to next highest floor
379                         if (EV_DoFloor(line, raiseFloorToNearest))
380                                 P_ChangeSwitchTexture(line,1);
381                         break;
382                 case 70:                // Turbo Lower Floor
383                         if (EV_DoFloor(line,turboLower))
384                                 P_ChangeSwitchTexture(line,1);
385                         break;
386         }
387         
388         return true;
389 }
390