]> icculus.org git repositories - theoddone33/hhexen.git/blob - base/p_plats.c
Fix opengl issue and insert mouse grab line in --help
[theoddone33/hhexen.git] / base / p_plats.c
1
2 //**************************************************************************
3 //**
4 //** p_plats.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 plat_t  *activeplats[MAXPLATS];
18
19 //==================================================================
20 //
21 //      Move a plat up and down
22 //
23 //==================================================================
24 void T_PlatRaise(plat_t *plat)
25 {
26         result_e res;
27
28         switch(plat->status)
29         {
30                 case PLAT_UP:
31                         res = T_MovePlane(plat->sector, plat->speed,
32                                         plat->high, plat->crush, 0, 1);
33                         if (res == RES_CRUSHED && (!plat->crush))
34                         {
35                                 plat->count = plat->wait;
36                                 plat->status = PLAT_DOWN;
37                                 SN_StartSequence((mobj_t *)&plat->sector->soundorg, 
38                                         SEQ_PLATFORM+plat->sector->seqType);
39                         }
40                         else
41                         if (res == RES_PASTDEST)
42                         {
43                                 plat->count = plat->wait;
44                                 plat->status = PLAT_WAITING;
45                                 SN_StopSequence((mobj_t *)&plat->sector->soundorg);
46                                 switch(plat->type)
47                                 {
48                                         case PLAT_DOWNWAITUPSTAY:
49                                         case PLAT_DOWNBYVALUEWAITUPSTAY:
50                                                 P_RemoveActivePlat(plat);
51                                                 break;
52                                         default:
53                                                 break;
54                                 }
55                         }
56                         break;
57                 case PLAT_DOWN:
58                         res = T_MovePlane(plat->sector,plat->speed,plat->low,false,0,-1);
59                         if (res == RES_PASTDEST)
60                         {
61                                 plat->count = plat->wait;
62                                 plat->status = PLAT_WAITING;
63                                 switch(plat->type)
64                                 {
65                                         case PLAT_UPWAITDOWNSTAY:
66                                         case PLAT_UPBYVALUEWAITDOWNSTAY:
67                                                 P_RemoveActivePlat(plat);
68                                                 break;
69                                         default:
70                                                 break;
71                                 }
72                                 SN_StopSequence((mobj_t *)&plat->sector->soundorg);
73                         }
74                         break;
75                 case PLAT_WAITING:
76                         if (!--plat->count)
77                         {
78                                 if (plat->sector->floorheight == plat->low)
79                                         plat->status = PLAT_UP;
80                                 else
81                                         plat->status = PLAT_DOWN;
82                                 SN_StartSequence((mobj_t *)&plat->sector->soundorg, 
83                                         SEQ_PLATFORM+plat->sector->seqType);
84                         }
85 //              case PLAT_IN_STASIS:
86 //                      break;
87         }
88 }
89
90 //==================================================================
91 //
92 //      Do Platforms
93 //      "amount" is only used for SOME platforms.
94 //
95 //==================================================================
96 int EV_DoPlat(line_t *line, byte *args, plattype_e type, int amount)
97 {
98         plat_t          *plat;
99         int                     secnum;
100         int                     rtn;
101         sector_t        *sec;
102
103         secnum = -1;
104         rtn = 0;
105
106 /*
107         //
108         //      Activate all <type> plats that are in_stasis
109         //
110         switch(type)
111         {
112                 case PLAT_PERPETUALRAISE:
113                         P_ActivateInStasis(args[0]);
114                         break;
115                 default:
116                         break;
117         }
118 */
119
120         while ((secnum = P_FindSectorFromTag(args[0], secnum)) >= 0)
121         {
122                 sec = &sectors[secnum];
123                 if (sec->specialdata)
124                         continue;
125
126                 //
127                 // Find lowest & highest floors around sector
128                 //
129                 rtn = 1;
130                 plat = Z_Malloc( sizeof(*plat), PU_LEVSPEC, 0);
131                 P_AddThinker(&plat->thinker);
132
133                 plat->type = type;
134                 plat->sector = sec;
135                 plat->sector->specialdata = plat;
136                 plat->thinker.function = T_PlatRaise;
137                 plat->crush = false;
138                 plat->tag = args[0];
139                 plat->speed = args[1]*(FRACUNIT/8);
140                 switch(type)
141                 {
142                         case PLAT_DOWNWAITUPSTAY:
143                                 plat->low = P_FindLowestFloorSurrounding(sec)+8*FRACUNIT;
144                                 if (plat->low > sec->floorheight)
145                                         plat->low = sec->floorheight;
146                                 plat->high = sec->floorheight;
147                                 plat->wait = args[2];
148                                 plat->status = PLAT_DOWN;
149                                 break;
150                         case PLAT_DOWNBYVALUEWAITUPSTAY:
151                                 plat->low = sec->floorheight-args[3]*8*FRACUNIT;
152                                 if (plat->low > sec->floorheight)
153                                         plat->low = sec->floorheight;
154                                 plat->high = sec->floorheight;
155                                 plat->wait = args[2];
156                                 plat->status = PLAT_DOWN;
157                                 break;
158                         case PLAT_UPWAITDOWNSTAY:
159                                 plat->high = P_FindHighestFloorSurrounding(sec);
160                                 if (plat->high < sec->floorheight)
161                                         plat->high = sec->floorheight;
162                                 plat->low = sec->floorheight;
163                                 plat->wait = args[2];
164                                 plat->status = PLAT_UP;
165                                 break;
166                         case PLAT_UPBYVALUEWAITDOWNSTAY:
167                                 plat->high = sec->floorheight+args[3]*8*FRACUNIT;
168                                 if (plat->high < sec->floorheight)
169                                         plat->high = sec->floorheight;
170                                 plat->low = sec->floorheight;
171                                 plat->wait = args[2];
172                                 plat->status = PLAT_UP;
173                                 break;
174                         case PLAT_PERPETUALRAISE:
175                                 plat->low = P_FindLowestFloorSurrounding(sec)+8*FRACUNIT;
176                                 if (plat->low > sec->floorheight)
177                                         plat->low = sec->floorheight;
178                                 plat->high = P_FindHighestFloorSurrounding(sec);
179                                 if (plat->high < sec->floorheight)
180                                         plat->high = sec->floorheight;
181                                 plat->wait = args[2];
182                                 plat->status = P_Random()&1;
183                                 break;
184                 }
185                 P_AddActivePlat(plat);
186                 SN_StartSequence((mobj_t *)&sec->soundorg, SEQ_PLATFORM+sec->seqType);
187         }
188         return rtn;
189 }
190
191 #if 0
192 void P_ActivateInStasis(int tag)
193 {
194         int             i;
195
196         for (i = 0;i < MAXPLATS;i++)
197                 if (activeplats[i] &&
198                         (activeplats[i])->tag == tag &&
199                         (activeplats[i])->status == PLAT_IN_STASIS)
200                 {
201                         (activeplats[i])->status = (activeplats[i])->oldstatus;
202                         (activeplats[i])->thinker.function = T_PlatRaise;
203                 }
204 }
205 #endif
206
207 void EV_StopPlat(line_t *line, byte *args)
208 {
209         int i;
210
211         for(i = 0; i < MAXPLATS; i++)
212         {
213           /* jim WRONG WRONG WRONG ! */
214 /*              if((activeplats[i])->tag = args[0]) */
215                 if((activeplats[i])->tag == args[0])
216                 {
217                         (activeplats[i])->sector->specialdata = NULL;
218                         P_TagFinished((activeplats[i])->sector->tag);
219                         P_RemoveThinker(&(activeplats[i])->thinker);
220                         activeplats[i] = NULL;
221
222                         return;
223                 }
224         }
225
226 /*
227         int             j;
228
229         for (j = 0;j < MAXPLATS;j++)
230         {
231                 if (activeplats[j] && ((activeplats[j])->status != PLAT_IN_STASIS) &&
232                         ((activeplats[j])->tag == args[0]))
233                 {
234                         (activeplats[j])->oldstatus = (activeplats[j])->status;
235                         (activeplats[j])->status = PLAT_IN_STASIS;
236                         (activeplats[j])->thinker.function = NULL;
237                         SN_StopSequence((mobj_t *)&(activeplats[j])->sector->soundorg);
238                 }
239         }
240 */
241 }
242
243 void P_AddActivePlat(plat_t *plat)
244 {
245         int             i;
246         for (i = 0;i < MAXPLATS;i++)
247                 if (activeplats[i] == NULL)
248                 {
249                         activeplats[i] = plat;
250                         return;
251                 }
252         I_Error ("P_AddActivePlat: no more plats!");
253 }
254
255 void P_RemoveActivePlat(plat_t *plat)
256 {
257         int             i;
258         for (i = 0;i < MAXPLATS;i++)
259                 if (plat == activeplats[i])
260                 {
261                         (activeplats[i])->sector->specialdata = NULL;
262                         P_TagFinished(plat->sector->tag);
263                         P_RemoveThinker(&(activeplats[i])->thinker);
264                         activeplats[i] = NULL;
265                         return;
266                 }
267         I_Error ("P_RemoveActivePlat: can't find plat!");
268 }
269