p_doors.c (8114B)
1 #include "doomdef.h" 2 #include "p_local.h" 3 #include "st_main.h" 4 5 /*================================================================== */ 6 /*================================================================== */ 7 /* */ 8 /* VERTICAL DOORS */ 9 /* */ 10 /*================================================================== */ 11 /*================================================================== */ 12 13 /*================================================================== */ 14 /* */ 15 /* T_VerticalDoor */ 16 /* */ 17 /*================================================================== */ 18 void T_VerticalDoor (vldoor_t *door) // 800104A0 19 { 20 result_e res1; 21 result_e res2; 22 23 switch(door->direction) 24 { 25 case 0: /* WAITING */ 26 if (!--door->topcountdown) 27 { 28 switch(door->type) 29 { 30 case BlazeRaise: 31 door->direction = -1; /* time to go back down */ 32 S_StartSound((mobj_t *)&door->sector->soundorg,80/*sfx_bdcls*/); 33 break; 34 case Normal: 35 door->direction = -1; /* time to go back down */ 36 S_StartSound((mobj_t *)&door->sector->soundorg,18/*sfx_dorcls*/); 37 break; 38 case Close30ThenOpen: 39 door->direction = 1; 40 S_StartSound((mobj_t *)&door->sector->soundorg,17/*sfx_doropn*/); 41 break; 42 //case RaiseIn5Mins: // [D64] moved here? 43 //door->direction = 1; 44 //door->type = Normal; 45 //S_StartSound((mobj_t *)&door->sector->soundorg,17/*sfx_doropn*/); 46 //break; 47 default: 48 break; 49 } 50 } 51 break; 52 #if 1 // [D64] no used 53 case 2: /* INITIAL WAIT */ 54 if (!--door->topcountdown) 55 { 56 switch(door->type) 57 { 58 case RaiseIn5Mins: 59 door->direction = 1; 60 door->type = Normal; 61 S_StartSound((mobj_t *)&door->sector->soundorg,17/*sfx_doropn*/); 62 break; 63 default: 64 break; 65 } 66 } 67 break; 68 #endif // 0 69 case -1: /* DOWN */ 70 res1 = T_MovePlane(door->sector,door->speed, door->initceiling,false,1,-1); 71 res2 = T_MovePlane(door->sector,door->speed, door->initceiling,false,0,1); 72 if ((res1 == pastdest) && (res2 == pastdest)) 73 { 74 switch(door->type) 75 { 76 case BlazeRaise: 77 case BlazeClose: 78 door->sector->specialdata = NULL; 79 P_RemoveThinker(&door->thinker); /* unlink and free */ 80 S_StartSound((mobj_t *)&door->sector->soundorg, 80/*sfx_bdcls*/); 81 break; 82 case Normal: 83 case DoorClose: 84 door->sector->specialdata = NULL; 85 P_RemoveThinker (&door->thinker); /* unlink and free */ 86 break; 87 case Close30ThenOpen: 88 door->direction = 0; 89 door->topcountdown = TICRATE*30; 90 break; 91 default: 92 break; 93 } 94 } 95 else if ((res1 == crushed) || (res2 == crushed)) 96 { 97 switch (door->type) 98 { 99 case BlazeClose: 100 case DoorClose: /* DO NOT GO BACK UP! */ 101 break; 102 103 default: 104 door->direction = 1; 105 S_StartSound((mobj_t *)&door->sector->soundorg, 17/*sfx_doropn*/); 106 break; 107 } 108 } 109 break; 110 case 1: /* UP */ 111 res1 = T_MovePlane(door->sector,door->speed,door->topheight,false,1,1); 112 res2 = T_MovePlane(door->sector,door->speed,door->bottomheight,false,0,-1); 113 if ((res1 == pastdest) && (res2 == pastdest)) 114 { 115 switch(door->type) 116 { 117 case BlazeRaise: 118 case Normal: 119 door->direction = 0; /* wait at top */ 120 door->topcountdown = door->topwait; 121 break; 122 case Close30ThenOpen: 123 case BlazeOpen: 124 case DoorOpen: 125 door->sector->specialdata = NULL; 126 P_RemoveThinker (&door->thinker); /* unlink and free */ 127 break; 128 default: 129 break; 130 } 131 } 132 break; 133 } 134 } 135 136 /*================================================================== */ 137 /* */ 138 /* EV_DoDoor */ 139 /* Move a door up/down and all around! */ 140 /* */ 141 /*================================================================== */ 142 int EV_DoDoor (line_t *line, vldoor_e type) // 80010750 143 { 144 int secnum,rtn; 145 sector_t *sec; 146 vldoor_t *door; 147 148 secnum = -1; 149 rtn = 0; 150 while ((secnum = P_FindSectorFromLineTag(line->tag,secnum)) >= 0) 151 { 152 sec = §ors[secnum]; 153 if (sec->specialdata) 154 continue; 155 156 /* */ 157 /* new door thinker */ 158 /* */ 159 rtn = 1; 160 door = Z_Malloc (sizeof(*door), PU_LEVSPEC, 0); 161 P_AddThinker (&door->thinker); 162 sec->specialdata = door; 163 door->thinker.function = T_VerticalDoor; 164 door->topwait = VDOORWAIT; 165 door->speed = VDOORSPEED; 166 door->sector = sec; 167 door->type = type; 168 door->bottomheight = sec->floorheight; 169 door->initceiling = sec->floorheight; 170 171 switch(type) 172 { 173 case BlazeClose: 174 door->topheight = P_FindLowestCeilingSurrounding(sec); 175 door->topheight -= 4 * FRACUNIT; 176 door->direction = -1; 177 door->speed = VDOORSPEED * 4; 178 S_StartSound((mobj_t *)&door->sector->soundorg, 80/*sfx_bdcls*/); 179 break; 180 case DoorClose: 181 door->topheight = P_FindLowestCeilingSurrounding(sec); 182 door->topheight -= 4*FRACUNIT; 183 door->direction = -1; 184 S_StartSound((mobj_t *)&door->sector->soundorg,18/*sfx_dorcls*/); 185 break; 186 case Close30ThenOpen: 187 door->topheight = sec->ceilingheight; 188 door->direction = -1; 189 S_StartSound((mobj_t *)&door->sector->soundorg,18/*sfx_dorcls*/); 190 break; 191 case BlazeRaise: 192 case BlazeOpen: 193 door->direction = 1; 194 door->topheight = P_FindLowestCeilingSurrounding(sec); 195 door->topheight -= 4 * FRACUNIT; 196 door->speed = VDOORSPEED * 4; 197 if (door->topheight != sec->ceilingheight) 198 S_StartSound((mobj_t *)&door->sector->soundorg, 79/*sfx_bdopn*/); 199 break; 200 case Normal: 201 case DoorOpen: 202 door->direction = 1; 203 door->topheight = P_FindLowestCeilingSurrounding(sec); 204 door->topheight -= 4*FRACUNIT; 205 if (door->topheight != sec->ceilingheight) 206 S_StartSound((mobj_t *)&door->sector->soundorg,17/*sfx_doropn*/); 207 break; 208 default: 209 break; 210 } 211 } 212 return rtn; 213 } 214 215 216 /*================================================================== */ 217 /* */ 218 /* EV_VerticalDoor : open a door manually, no tag value */ 219 /* */ 220 /*================================================================== */ 221 void EV_VerticalDoor (line_t *line, mobj_t *thing) // 80010998 222 { 223 player_t *player; 224 sector_t *sec; 225 vldoor_t *door; 226 int side; 227 228 side = 0; /* only front sides can be used */ 229 230 /* if the sector has an active thinker, use it */ 231 sec = sides[ line->sidenum[side^1]] .sector; 232 if (sec->specialdata) 233 { 234 door = sec->specialdata; 235 switch(SPECIALMASK(line->special)) 236 { 237 case 1: /* ONLY FOR "RAISE" DOORS, NOT "OPEN"s */ 238 case 117: 239 if (door->direction == -1) 240 door->direction = 1; /* go back up */ 241 else 242 { 243 if (!thing->player) 244 return; /* JDC: bad guys never close doors */ 245 door->direction = -1; /* start going down immediately */ 246 } 247 return; 248 } 249 } 250 251 /* for proper sound */ 252 switch(SPECIALMASK(line->special)) 253 { 254 case 117: /* BLAZING DOOR RAISE */ 255 case 118: /* BLAZING DOOR OPEN */ 256 S_StartSound((mobj_t *)&sec->soundorg,79/*sfx_bdopn*/); 257 break; 258 default: /* LOCKED DOOR SOUND */ 259 S_StartSound((mobj_t *)&sec->soundorg,17/*sfx_doropn*/); 260 break; 261 } 262 263 /* */ 264 /* new door thinker */ 265 /* */ 266 door = Z_Malloc (sizeof(*door), PU_LEVSPEC, 0); 267 P_AddThinker (&door->thinker); 268 sec->specialdata = door; 269 door->thinker.function = T_VerticalDoor; 270 door->speed = VDOORSPEED; 271 door->sector = sec; 272 door->direction = 1; 273 door->topwait = VDOORWAIT; 274 275 switch(SPECIALMASK(line->special)) 276 { 277 case 1: 278 door->type = Normal; 279 break; 280 case 31: 281 door->type = DoorOpen; 282 line->special = 0; 283 break; 284 case 117: /* blazing door raise */ 285 door->type = BlazeRaise; 286 door->speed = VDOORSPEED * 4; 287 break; 288 case 118: /* blazing door open */ 289 door->type = BlazeOpen; 290 door->speed = VDOORSPEED * 4; 291 line->special = 0; 292 break; 293 } 294 295 /* */ 296 /* find the top and bottom of the movement range */ 297 /* */ 298 door->topheight = P_FindLowestCeilingSurrounding(sec); 299 door->topheight -= 4*FRACUNIT; 300 door->bottomheight = P_FindLowestFloorSurrounding(sec); 301 door->initceiling = sec->floorheight; 302 303 if(door->bottomheight != sec->floorheight) 304 door->bottomheight += 4*FRACUNIT; 305 }