p_ceilng.c (5054B)
1 #include "z_zone.h" 2 #include "doomdef.h" 3 #include "p_local.h" 4 5 #include "s_sound.h" 6 7 8 #include "doomstat.h" 9 #include "r_state.h" 10 11 12 #include "sounds.h" 13 14 15 16 17 18 19 ceiling_t* activeceilings[MAXCEILINGS]; 20 21 22 23 24 25 26 void T_MoveCeiling (ceiling_t* ceiling) 27 { 28 result_e res; 29 30 switch(ceiling->direction) 31 { 32 case 0: 33 34 break; 35 case 1: 36 37 res = T_MovePlane(ceiling->sector, 38 ceiling->speed, 39 ceiling->topheight, 40 false,1,ceiling->direction); 41 42 if (!(leveltime&7)) 43 { 44 switch(ceiling->type) 45 { 46 case silentCrushAndRaise: 47 break; 48 default: 49 S_StartSound((mobj_t *)&ceiling->sector->soundorg, 50 sfx_stnmov); 51 52 break; 53 } 54 } 55 56 if (res == pastdest) 57 { 58 switch(ceiling->type) 59 { 60 case raiseToHighest: 61 P_RemoveActiveCeiling(ceiling); 62 break; 63 64 case silentCrushAndRaise: 65 S_StartSound((mobj_t *)&ceiling->sector->soundorg, 66 sfx_pstop); 67 case fastCrushAndRaise: 68 case crushAndRaise: 69 ceiling->direction = -1; 70 break; 71 72 default: 73 break; 74 } 75 76 } 77 break; 78 79 case -1: 80 81 res = T_MovePlane(ceiling->sector, 82 ceiling->speed, 83 ceiling->bottomheight, 84 ceiling->crush,1,ceiling->direction); 85 86 if (!(leveltime&7)) 87 { 88 switch(ceiling->type) 89 { 90 case silentCrushAndRaise: break; 91 default: 92 S_StartSound((mobj_t *)&ceiling->sector->soundorg, 93 sfx_stnmov); 94 } 95 } 96 97 if (res == pastdest) 98 { 99 switch(ceiling->type) 100 { 101 case silentCrushAndRaise: 102 S_StartSound((mobj_t *)&ceiling->sector->soundorg, 103 sfx_pstop); 104 case crushAndRaise: 105 ceiling->speed = CEILSPEED; 106 case fastCrushAndRaise: 107 ceiling->direction = 1; 108 break; 109 110 case lowerAndCrush: 111 case lowerToFloor: 112 P_RemoveActiveCeiling(ceiling); 113 break; 114 115 default: 116 break; 117 } 118 } 119 else 120 { 121 if (res == crushed) 122 { 123 switch(ceiling->type) 124 { 125 case silentCrushAndRaise: 126 case crushAndRaise: 127 case lowerAndCrush: 128 ceiling->speed = CEILSPEED / 8; 129 break; 130 131 default: 132 break; 133 } 134 } 135 } 136 break; 137 } 138 } 139 140 141 142 143 144 145 int 146 EV_DoCeiling 147 ( line_t* line, 148 ceiling_e type ) 149 { 150 int secnum; 151 int rtn; 152 sector_t* sec; 153 ceiling_t* ceiling; 154 155 secnum = -1; 156 rtn = 0; 157 158 159 switch(type) 160 { 161 case fastCrushAndRaise: 162 case silentCrushAndRaise: 163 case crushAndRaise: 164 P_ActivateInStasisCeiling(line); 165 default: 166 break; 167 } 168 169 while ((secnum = P_FindSectorFromLineTag(line,secnum)) >= 0) 170 { 171 sec = §ors[secnum]; 172 if (sec->specialdata) 173 continue; 174 175 176 rtn = 1; 177 ceiling = Z_Malloc (sizeof(*ceiling), PU_LEVSPEC, 0); 178 P_AddThinker (&ceiling->thinker); 179 sec->specialdata = ceiling; 180 ceiling->thinker.function.acp1 = (actionf_p1)T_MoveCeiling; 181 ceiling->sector = sec; 182 ceiling->crush = false; 183 184 switch(type) 185 { 186 case fastCrushAndRaise: 187 ceiling->crush = true; 188 ceiling->topheight = sec->ceilingheight; 189 ceiling->bottomheight = sec->floorheight + (8*FRACUNIT); 190 ceiling->direction = -1; 191 ceiling->speed = CEILSPEED * 2; 192 break; 193 194 case silentCrushAndRaise: 195 case crushAndRaise: 196 ceiling->crush = true; 197 ceiling->topheight = sec->ceilingheight; 198 case lowerAndCrush: 199 case lowerToFloor: 200 ceiling->bottomheight = sec->floorheight; 201 if (type != lowerToFloor) 202 ceiling->bottomheight += 8*FRACUNIT; 203 ceiling->direction = -1; 204 ceiling->speed = CEILSPEED; 205 break; 206 207 case raiseToHighest: 208 ceiling->topheight = P_FindHighestCeilingSurrounding(sec); 209 ceiling->direction = 1; 210 ceiling->speed = CEILSPEED; 211 break; 212 } 213 214 ceiling->tag = sec->tag; 215 ceiling->type = type; 216 P_AddActiveCeiling(ceiling); 217 } 218 return rtn; 219 } 220 221 222 223 224 225 void P_AddActiveCeiling(ceiling_t* c) 226 { 227 int i; 228 229 for (i = 0; i < MAXCEILINGS;i++) 230 { 231 if (activeceilings[i] == NULL) 232 { 233 activeceilings[i] = c; 234 return; 235 } 236 } 237 } 238 239 240 241 242 243 244 void P_RemoveActiveCeiling(ceiling_t* c) 245 { 246 int i; 247 248 for (i = 0;i < MAXCEILINGS;i++) 249 { 250 if (activeceilings[i] == c) 251 { 252 activeceilings[i]->sector->specialdata = NULL; 253 P_RemoveThinker (&activeceilings[i]->thinker); 254 activeceilings[i] = NULL; 255 break; 256 } 257 } 258 } 259 260 261 262 263 264 265 void P_ActivateInStasisCeiling(line_t* line) 266 { 267 int i; 268 269 for (i = 0;i < MAXCEILINGS;i++) 270 { 271 if (activeceilings[i] 272 && (activeceilings[i]->tag == line->tag) 273 && (activeceilings[i]->direction == 0)) 274 { 275 activeceilings[i]->direction = activeceilings[i]->olddirection; 276 activeceilings[i]->thinker.function.acp1 277 = (actionf_p1)T_MoveCeiling; 278 } 279 } 280 } 281 282 283 284 285 286 287 288 int EV_CeilingCrushStop(line_t *line) 289 { 290 int i; 291 int rtn; 292 293 rtn = 0; 294 for (i = 0;i < MAXCEILINGS;i++) 295 { 296 if (activeceilings[i] 297 && (activeceilings[i]->tag == line->tag) 298 && (activeceilings[i]->direction != 0)) 299 { 300 activeceilings[i]->olddirection = activeceilings[i]->direction; 301 activeceilings[i]->thinker.function.acv = (actionf_v)NULL; 302 activeceilings[i]->direction = 0; 303 rtn = 1; 304 } 305 } 306 307 308 return rtn; 309 }