DOOM64-RE

DOOM 64 Reverse Engineering
Log | Files | Refs | README | LICENSE

p_ceilng.c (8299B)


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