Make T_MarioBlock use its own thinker data structure

This commit is contained in:
MascaraSnake 2020-04-18 02:05:23 +02:00
parent 7e2f95c3f5
commit 0038605979
3 changed files with 67 additions and 41 deletions

View file

@ -941,17 +941,10 @@ void T_StartCrumble(elevator_t *elevator)
//////////////////////////////////////////////////
// Mario hits a block!
//
void T_MarioBlock(levelspecthink_t *block)
void T_MarioBlock(mariothink_t *block)
{
INT32 i;
#define speed vars[1]
#define direction vars[2]
#define floorwasheight vars[3]
#define ceilingwasheight vars[4]
#define distance vars[5]
#define low vars[6]
T_MovePlane
(
block->sector,
@ -972,12 +965,12 @@ void T_MarioBlock(levelspecthink_t *block)
block->direction
);
if (block->sector->ceilingheight >= block->ceilingwasheight + 32*FRACUNIT) // Go back down now..
block->direction = -block->direction;
else if (block->sector->ceilingheight <= block->ceilingwasheight)
if (block->sector->ceilingheight >= block->ceilingstartheight + 32*FRACUNIT) // Go back down now..
block->direction *= -1;
else if (block->sector->ceilingheight <= block->ceilingstartheight)
{
block->sector->ceilingheight = block->ceilingwasheight;
block->sector->floorheight = block->floorwasheight;
block->sector->ceilingheight = block->ceilingstartheight;
block->sector->floorheight = block->floorstartheight;
P_RemoveThinker(&block->thinker);
block->sector->floordata = NULL;
block->sector->ceilingdata = NULL;
@ -986,15 +979,8 @@ void T_MarioBlock(levelspecthink_t *block)
block->direction = 0;
}
for (i = -1; (i = P_FindSectorFromTag((INT16)block->vars[0], i)) >= 0 ;)
for (i = -1; (i = P_FindSectorFromTag(block->tag, i)) >= 0 ;)
P_RecalcPrecipInSector(&sectors[i]);
#undef speed
#undef direction
#undef floorwasheight
#undef ceilingwasheight
#undef distance
#undef low
}
void T_FloatSector(floatthink_t *floater)
@ -2460,11 +2446,11 @@ INT32 EV_StartCrumble(sector_t *sec, ffloor_t *rover, boolean floating,
return 1;
}
INT32 EV_MarioBlock(ffloor_t *rover, sector_t *sector, mobj_t *puncher)
void EV_MarioBlock(ffloor_t *rover, sector_t *sector, mobj_t *puncher)
{
sector_t *roversec = rover->master->frontsector;
fixed_t topheight = *rover->topheight;
levelspecthink_t *block;
mariothink_t *block;
mobj_t *thing;
fixed_t oldx = 0, oldy = 0, oldz = 0;
@ -2472,7 +2458,7 @@ INT32 EV_MarioBlock(ffloor_t *rover, sector_t *sector, mobj_t *puncher)
I_Assert(puncher->player != NULL);
if (roversec->floordata || roversec->ceilingdata)
return 0;
return;
if (!(rover->flags & FF_SOLID))
rover->flags |= (FF_SOLID|FF_RENDERALL|FF_CUTLEVEL);
@ -2480,8 +2466,9 @@ INT32 EV_MarioBlock(ffloor_t *rover, sector_t *sector, mobj_t *puncher)
// Find an item to pop out!
thing = SearchMarioNode(roversec->touching_thinglist);
// Found something!
if (thing)
if (!thing)
S_StartSound(puncher, sfx_mario1); // "Thunk!" sound - puncher is "close enough".
else // Found something!
{
const boolean itsamonitor = (thing->flags & MF_MONITOR) == MF_MONITOR;
// create and initialize new elevator thinker
@ -2494,13 +2481,11 @@ INT32 EV_MarioBlock(ffloor_t *rover, sector_t *sector, mobj_t *puncher)
// Set up the fields
block->sector = roversec;
block->vars[0] = sector->tag; // actionsector
block->vars[1] = 4*FRACUNIT; // speed
block->vars[2] = 1; // Up // direction
block->vars[3] = block->sector->floorheight; // floorwasheight
block->vars[4] = block->sector->ceilingheight; // ceilingwasheight
block->vars[5] = FRACUNIT; // distance
block->vars[6] = 1; // low
block->speed = 4*FRACUNIT;
block->direction = 1;
block->floorstartheight = block->sector->floorheight;
block->ceilingstartheight = block->sector->ceilingheight;
block->tag = (INT16)sector->tag;
if (itsamonitor)
{
@ -2541,8 +2526,4 @@ INT32 EV_MarioBlock(ffloor_t *rover, sector_t *sector, mobj_t *puncher)
P_SetThingPosition(thing);
}
}
else
S_StartSound(puncher, sfx_mario1); // "Thunk!" sound - puncher is "close enough".
return 1;
}

View file

@ -1675,6 +1675,23 @@ static void SaveContinuousFallThinker(const thinker_t *th, const UINT8 type)
WRITEFIXED(save_p, ht->destheight);
}
//
// SaveMarioBlockThinker
//
// Saves a mariothink_t thinker
//
static void SaveMarioBlockThinker(const thinker_t *th, const UINT8 type)
{
const mariothink_t *ht = (const void *)th;
WRITEUINT8(save_p, type);
WRITEUINT32(save_p, SaveSector(ht->sector));
WRITEFIXED(save_p, ht->speed);
WRITEINT32(save_p, ht->direction);
WRITEFIXED(save_p, ht->floorstartheight);
WRITEFIXED(save_p, ht->ceilingstartheight);
WRITEINT16(save_p, ht->tag);
}
//
// SaveFloatThinker
//
@ -2338,7 +2355,7 @@ static void P_NetArchiveThinkers(void)
}
else if (th->function.acp1 == (actionf_p1)T_MarioBlock)
{
SaveSpecialLevelThinker(th, tc_marioblock);
SaveMarioBlockThinker(th, tc_marioblock);
continue;
}
else if (th->function.acp1 == (actionf_p1)T_MarioBlockChecker)
@ -2848,6 +2865,23 @@ static thinker_t* LoadContinuousFallThinker(actionf_p1 thinker)
return &ht->thinker;
}
// LoadMarioBlockThinker
//
// Loads a mariothink_t from a save game
//
static thinker_t* LoadMarioBlockThinker(actionf_p1 thinker)
{
mariothink_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL);
ht->thinker.function.acp1 = thinker;
ht->sector = LoadSector(READUINT32(save_p));
ht->speed = READFIXED(save_p);
ht->direction = READINT32(save_p);
ht->floorstartheight = READFIXED(save_p);
ht->ceilingstartheight = READFIXED(save_p);
ht->tag = READINT16(save_p);
return &ht->thinker;
}
// LoadFloatThinker
//
// Loads a floatthink_t from a save game
@ -3596,7 +3630,7 @@ static void P_NetUnArchiveThinkers(void)
break;
case tc_marioblock:
th = LoadSpecialLevelThinker((actionf_p1)T_MarioBlock, 3);
th = LoadMarioBlockThinker((actionf_p1)T_MarioBlock);
break;
case tc_marioblockchecker:

View file

@ -331,6 +331,17 @@ typedef struct
fixed_t destheight;
} continuousfall_t;
typedef struct
{
thinker_t thinker;
sector_t *sector;
fixed_t speed;
INT32 direction;
fixed_t floorstartheight;
fixed_t ceilingstartheight;
INT16 tag;
} mariothink_t;
typedef struct
{
thinker_t thinker;
@ -391,7 +402,7 @@ INT32 EV_StartCrumble(sector_t *sector, ffloor_t *rover,
void EV_DoContinuousFall(sector_t *sec, sector_t *backsector, fixed_t spd, boolean backwards);
INT32 EV_MarioBlock(ffloor_t *rover, sector_t *sector, mobj_t *puncher);
void EV_MarioBlock(ffloor_t *rover, sector_t *sector, mobj_t *puncher);
void T_MoveFloor(floormove_t *movefloor);
@ -399,7 +410,7 @@ void T_MoveElevator(elevator_t *elevator);
void T_ContinuousFalling(continuousfall_t *faller);
void T_BounceCheese(levelspecthink_t *bouncer);
void T_StartCrumble(elevator_t *elevator);
void T_MarioBlock(levelspecthink_t *block);
void T_MarioBlock(mariothink_t *block);
void T_FloatSector(floatthink_t *floater);
void T_MarioBlockChecker(levelspecthink_t *block);
void T_ThwompSector(levelspecthink_t *thwomp);