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