1
2 //**************************************************************************
3 //**
4 //** p_switch.c : Heretic 2 : Raven Software, Corp.
5 //**
6 //** $RCSfile: p_switch.c,v $
7 //** $Revision: 1.8 $
8 //** $Date: 95/09/05 13:58:59 $
9 //** $Author: cjr $
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 alphSwitchListFull[] =
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 },
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 switchlist_t alphSwitchListDemo[] =
38 {
39 { "SW_1_UP", "SW_1_DN", SFX_SWITCH1 },
40 { "SW_2_UP", "SW_2_DN", SFX_SWITCH1 },
41 { "SW52_OFF", "SW52_ON", SFX_SWITCH2 },
42 {"\0", "\0", 0}
43 };
44
45 switchlist_t *alphSwitchList=alphSwitchListFull;
46
47 int switchlist[MAXSWITCHES * 2];
48 int numswitches;
49 button_t buttonlist[MAXBUTTONS];
50
51 /*
52 ===============
53 =
54 = P_InitSwitchList
55 =
56 = Only called at game initialization
57 =
58 ===============
59 */
60
P_InitSwitchList(void)61 void P_InitSwitchList(void)
62 {
63 int i;
64 int index;
65
66 for (index = 0, i = 0; i < MAXSWITCHES; i++)
67 {
68 if(!alphSwitchList[i].soundID)
69 {
70 numswitches = index/2;
71 switchlist[index] = -1;
72 break;
73 }
74 switchlist[index++] = R_TextureNumForName(alphSwitchList[i].name1);
75 switchlist[index++] = R_TextureNumForName(alphSwitchList[i].name2);
76 }
77 }
78
79 //==================================================================
80 //
81 // Start a button counting down till it turns off.
82 //
83 //==================================================================
P_StartButton(line_t * line,bwhere_e w,int texture,int time)84 void P_StartButton(line_t *line,bwhere_e w,int texture,int time)
85 {
86 int i;
87
88 for (i = 0;i < MAXBUTTONS;i++)
89 {
90 if (!buttonlist[i].btimer)
91 {
92 buttonlist[i].line = line;
93 buttonlist[i].where = w;
94 buttonlist[i].btexture = texture;
95 buttonlist[i].btimer = time;
96 buttonlist[i].soundorg = (mobj_t *)&line->frontsector->soundorg;
97 return;
98 }
99 }
100 I_Error("P_StartButton: no button slots left!");
101 }
102
103 //==================================================================
104 //
105 // Function that changes wall texture.
106 // Tell it if switch is ok to use again (1=yes, it's a button).
107 //
108 //==================================================================
P_ChangeSwitchTexture(line_t * line,int useAgain)109 void P_ChangeSwitchTexture(line_t *line, int useAgain)
110 {
111 int texTop;
112 int texMid;
113 int texBot;
114 int i;
115
116 texTop = sides[line->sidenum[0]].toptexture;
117 texMid = sides[line->sidenum[0]].midtexture;
118 texBot = sides[line->sidenum[0]].bottomtexture;
119
120 for (i = 0; i < numswitches*2; i++)
121 {
122 if (switchlist[i] == texTop)
123 {
124 S_StartSound((mobj_t *)&line->frontsector->soundorg,
125 alphSwitchList[i/2].soundID);
126 sides[line->sidenum[0]].toptexture = switchlist[i^1];
127 if(useAgain)
128 {
129 P_StartButton(line, SWTCH_TOP, switchlist[i], BUTTONTIME);
130 }
131 return;
132 }
133 else if (switchlist[i] == texMid)
134 {
135 S_StartSound((mobj_t *)&line->frontsector->soundorg,
136 alphSwitchList[i/2].soundID);
137 sides[line->sidenum[0]].midtexture = switchlist[i^1];
138 if(useAgain)
139 {
140 P_StartButton(line, SWTCH_MIDDLE, switchlist[i], BUTTONTIME);
141 }
142 return;
143 }
144 else if (switchlist[i] == texBot)
145 {
146 S_StartSound((mobj_t *)&line->frontsector->soundorg,
147 alphSwitchList[i/2].soundID);
148 sides[line->sidenum[0]].bottomtexture = switchlist[i^1];
149 if(useAgain)
150 {
151 P_StartButton(line, SWTCH_BOTTOM, switchlist[i], BUTTONTIME);
152 }
153 return;
154 }
155 }
156 }
157