Skip to content

Commit

Permalink
Refactor|libcommon: Pass sector-plane-impacted arguments via Sector_T…
Browse files Browse the repository at this point in the history
…ouchingMobjsIterator
  • Loading branch information
danij-deng committed Oct 14, 2013
1 parent a20f18b commit 6c4531e
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 33 deletions.
5 changes: 3 additions & 2 deletions doomsday/plugins/common/include/p_map.h
Expand Up @@ -138,9 +138,10 @@ void P_UseLines(player_t *player);

/**
* @param sector The sector to check.
* @param crunch @c true= crush any things in the sector.
* @param crush Hexen: amount of crush damage to apply.
* Other games: apply fixed crush damage if @c > 0.
*/
boolean P_ChangeSector(Sector *sector, boolean crunch);
boolean P_ChangeSector(Sector *sector, int crush);

/**
* This is called by the engine when it needs to change sector heights without
Expand Down
64 changes: 36 additions & 28 deletions doomsday/plugins/common/src/p_map.cpp
Expand Up @@ -99,9 +99,6 @@ static float aimSlope;
// slopes to top and bottom of target
static float topSlope, bottomSlope;

static boolean crushChange;
static boolean noFit;

static coord_t startPos[3]; // start position for trajectory line checks
static coord_t endPos[3]; // end position for trajectory checks

Expand Down Expand Up @@ -2284,9 +2281,9 @@ static boolean P_ThingHeightClip(mobj_t *thing)
if(P_MobjIsCamera(thing)) return false;

bool const onfloor = (thing->origin[VZ] == thing->floorZ);
P_CheckPosition(thing, thing->origin);

thing->floorZ = tmFloorZ;
P_CheckPosition(thing, thing->origin);
thing->floorZ = tmFloorZ;
thing->ceilingZ = tmCeilingZ;
#if !__JHEXEN__
thing->dropOffZ = tmDropoffZ; // $dropoff_fix: remember dropoffs.
Expand All @@ -2301,23 +2298,29 @@ static boolean P_ThingHeightClip(mobj_t *thing)
thing->origin[VZ] = thing->floorZ;
}
#else
// Update view offset of real players $voodoodolls.
if(thing->player && thing->player->plr->mo == thing)
// Update view offset of real players.
if(Mobj_IsPlayer(thing) && !Mobj_IsVoodooDoll(thing))
{
thing->player->viewZ += thing->floorZ - thing->origin[VZ];
}

// Walking monsters rise and fall with the floor.
thing->origin[VZ] = thing->floorZ;

// $dropoff_fix: Possibly upset balance of objects hanging off ledges.
if((thing->intFlags & MIF_FALLING) && thing->gear >= MAXGEAR)
{
thing->gear = 0;
}
#endif
}
else
{
// Don't adjust a floating monster unless forced to.
if(thing->origin[VZ] + thing->height > thing->ceilingZ)
{
thing->origin[VZ] = thing->ceilingZ - thing->height;
}
}

return (thing->ceilingZ - thing->floorZ) >= thing->height;
Expand Down Expand Up @@ -2548,18 +2551,22 @@ void P_SlideMove(mobj_t *mo)
* to adjust the positions of all things that touch the sector.
*
* If anything doesn't fit anymore, true will be returned.
* If crunch is true, they will take damage as they are being crushed.
* If Crunch is false, you should set the sector height back the way it
* If crushDamage is non-zero, they will take damage as they are being crushed.
* If crushDamage is false, you should set the sector height back the way it
* was and call P_ChangeSector again to undo the changes.
*/

/**
* @param thing The thing to check against height changes.
* @param data Unused.
*/
int PIT_ChangeSector(mobj_t *thing, void * /*context*/)
struct pit_changesector_params_t
{
if(!thing->info) return false; // Invalid thing?
int crushDamage; ///< Damage amount;
bool noFit;
};

int PIT_ChangeSector(mobj_t *thing, void *context)
{
pit_changesector_params_t &parm = *static_cast<pit_changesector_params_t *>(context);

DENG_ASSERT(thing->info != 0);

// Don't check things that aren't blocklinked (supposedly immaterial).
if(thing->info->flags & MF_NOBLOCKMAP)
Expand Down Expand Up @@ -2627,15 +2634,11 @@ int PIT_ChangeSector(mobj_t *thing, void * /*context*/)
return false; // Keep checking...
}

noFit = true;
parm.noFit = true;

if(crushChange > 0 && !(mapTime & 3))
if(parm.crushDamage > 0 && !(mapTime & 3))
{
#if __JHEXEN__
P_DamageMobj(thing, NULL, NULL, crushChange, false);
#else
P_DamageMobj(thing, NULL, NULL, 10, false);
#endif
P_DamageMobj(thing, NULL, NULL, parm.crushDamage, false);

#if __JDOOM__ || __JDOOM64__
if(!(thing->flags & MF_NOBLOOD))
Expand All @@ -2658,20 +2661,25 @@ int PIT_ChangeSector(mobj_t *thing, void * /*context*/)
return false; // Keep checking (crush other things)...
}

boolean P_ChangeSector(Sector *sector, boolean crunch)
boolean P_ChangeSector(Sector *sector, int crush)
{
noFit = false;
crushChange = crunch;
pit_changesector_params_t parm;
parm.noFit = false;
#if __JHEXEN__
parm.crushDamage = int(crush);
#else
parm.crushDamage = 10;
#endif

VALIDCOUNT++;
Sector_TouchingMobjsIterator(sector, PIT_ChangeSector, 0);
Sector_TouchingMobjsIterator(sector, PIT_ChangeSector, &parm);

return noFit;
return parm.noFit;
}

void P_HandleSectorHeightChange(int sectorIdx)
{
P_ChangeSector((Sector *)P_ToPtr(DMU_SECTOR, sectorIdx), false);
P_ChangeSector((Sector *)P_ToPtr(DMU_SECTOR, sectorIdx), false /*don't crush*/);
}

#if __JHERETIC__ || __JHEXEN__
Expand Down
2 changes: 1 addition & 1 deletion doomsday/plugins/common/src/p_xgsec.c
Expand Up @@ -2107,7 +2107,7 @@ int C_DECL XSTrav_MimicSector(Sector *sector, boolean ceiling,
// Copy the properties of the target sector.
P_CopySector(sector, from);

P_ChangeSector(sector, false);
P_ChangeSector(sector, false /*don't crush*/);

// Copy type as well.
XS_SetSectorType(sector, P_ToXSector(from)->special);
Expand Down
4 changes: 2 additions & 2 deletions doomsday/plugins/hexen/src/p_waggle.c
Expand Up @@ -84,7 +84,7 @@ void T_FloorWaggle(waggle_t* waggle)
{
// Remove.
P_SetDoublep(waggle->sector, DMU_FLOOR_HEIGHT, waggle->originalHeight);
P_ChangeSector(waggle->sector, true);
P_ChangeSector(waggle->sector, 1 /*crush damage*/);
P_ToXSector(waggle->sector)->specialData = NULL;
P_TagFinished(P_ToXSector(waggle->sector)->tag);
Thinker_Remove(&waggle->thinker);
Expand All @@ -99,7 +99,7 @@ void T_FloorWaggle(waggle_t* waggle)
P_SetDoublep(waggle->sector, DMU_FLOOR_HEIGHT, fh);
P_SetDoublep(waggle->sector, DMU_FLOOR_TARGET_HEIGHT, fh);
P_SetFloatp(waggle->sector, DMU_FLOOR_SPEED, 0);
P_ChangeSector(waggle->sector, true);
P_ChangeSector(waggle->sector, 1 /*crush damage*/);
}

boolean EV_StartFloorWaggle(int tag, int height, int speed, int offset, int timer)
Expand Down

0 comments on commit 6c4531e

Please sign in to comment.