Skip to content

Commit

Permalink
Merge pull request #48 from momentum-mod/doorfix_wip
Browse files Browse the repository at this point in the history
func_door and func_button bhop block fix
  • Loading branch information
Rubén committed Mar 16, 2016
2 parents 06426c6 + 68a0f4b commit 472b47a
Show file tree
Hide file tree
Showing 14 changed files with 340 additions and 134 deletions.
11 changes: 0 additions & 11 deletions mp/src/game/server/buttons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,6 @@
void PlayLockSounds( CBaseEntity *pEdict, locksound_t *pls, int flocked, int fbutton );
string_t MakeButtonSound( int sound ); // get string of button sound number


#define SF_BUTTON_DONTMOVE 1
#define SF_ROTBUTTON_NOTSOLID 1
#define SF_BUTTON_TOGGLE 32 // button stays pushed until reactivated
#define SF_BUTTON_TOUCH_ACTIVATES 256 // Button fires when touched.
#define SF_BUTTON_DAMAGE_ACTIVATES 512 // Button fires when damaged.
#define SF_BUTTON_USE_ACTIVATES 1024 // Button fires when used.
#define SF_BUTTON_LOCKED 2048 // Whether the button is initially locked.
#define SF_BUTTON_SPARK_IF_OFF 4096 // button sparks in OFF state
#define SF_BUTTON_JIGGLE_ON_USE_LOCKED 8192 // whether to jiggle if someone uses us when we're locked

BEGIN_DATADESC( CBaseButton )

DEFINE_KEYFIELD( m_vecMoveDir, FIELD_VECTOR, "movedir" ),
Expand Down
11 changes: 11 additions & 0 deletions mp/src/game/server/buttons.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@
#pragma once
#endif

#include <locksounds.h>

#define SF_BUTTON_DONTMOVE 1
#define SF_ROTBUTTON_NOTSOLID 1
#define SF_BUTTON_TOGGLE 32 // button stays pushed until reactivated
#define SF_BUTTON_TOUCH_ACTIVATES 256 // Button fires when touched.
#define SF_BUTTON_DAMAGE_ACTIVATES 512 // Button fires when damaged.
#define SF_BUTTON_USE_ACTIVATES 1024 // Button fires when used.
#define SF_BUTTON_LOCKED 2048 // Whether the button is initially locked.
#define SF_BUTTON_SPARK_IF_OFF 4096 // button sparks in OFF state
#define SF_BUTTON_JIGGLE_ON_USE_LOCKED 8192 // whether to jiggle if someone uses us when we're locked

class CBaseButton : public CBaseToggle
{
Expand Down
146 changes: 146 additions & 0 deletions mp/src/game/server/momentum/mom_blockfix.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
#include "cbase.h"
#include "mom_blockfix.h"

#include "tier0/memdbgon.h"

void CMOMBhopBlockFixSystem::FindBhopBlocks()
{
SetDefLessFunc(m_mapBlocks);
// ---- func_door ----
CBaseEntity *ent = NULL;
while ((ent = gEntList.FindEntityByClassname(ent, "func_door")) != NULL)
{
CBaseDoor *pEntDoor = static_cast<CBaseDoor *>(ent);

Vector startpos(pEntDoor->m_vecPosition1);
Vector endpos(pEntDoor->m_vecPosition2);

if (startpos.z > endpos.z)
{
FindTeleport(pEntDoor, true);

if (m_mapBlocks.Count() == MAX_BHOPBLOCKS)
break;
}
}
ent = NULL;

// ---- func_button ----
while ((ent = gEntList.FindEntityByClassname(ent, "func_button")) != NULL)
{
CBaseButton *pEntButton = static_cast<CBaseButton *>(ent);
Vector startpos(pEntButton->m_vecPosition1);
Vector endpos(pEntButton->m_vecPosition2);

if (startpos.z > endpos.z && (pEntButton->HasSpawnFlags(SF_BUTTON_TOUCH_ACTIVATES)))
{
FindTeleport(pEntButton, false);

if (m_mapBlocks.Count() == MAX_BHOPBLOCKS)
break;
}
}
}
void CMOMBhopBlockFixSystem::AlterBhopBlock(bhop_block_t block)
{
if (block.m_bIsDoor)
{
// And now the settings begin
CBaseDoor *pDoorEnt = static_cast<CBaseDoor *>(block.m_pBlockEntity); //(block.m_hBlockEntity.Get());

pDoorEnt->m_vecPosition2 = pDoorEnt->m_vecPosition1; // Set the end position to start (not allowed to move)

pDoorEnt->m_flSpeed = 0.0; // set speed to 0 (further not allowed to move)

pDoorEnt->ClearSpawnFlags();
pDoorEnt->AddSpawnFlags(SF_DOOR_PTOUCH); // Player touch affects this

variant_t emptyvarient;
pDoorEnt->AcceptInput("Lock", NULL, NULL, emptyvarient, 0); // Lock the door bhop block

pDoorEnt->m_ls.sLockedSound =
pDoorEnt->m_NoiseMoving; // Plays the sound like normal (makes the player aware they jumped it)
}
else
{ // func_button block

CBaseButton *pEntButton = static_cast<CBaseButton *>(block.m_pBlockEntity); //(block.m_hBlockEntity.Get());
pEntButton->m_vecPosition2 = pEntButton->m_vecPosition1;

pEntButton->m_flSpeed = 0.0f;
pEntButton->ClearSpawnFlags();

pEntButton->AddSpawnFlags(SF_BUTTON_DONTMOVE | SF_BUTTON_TOUCH_ACTIVATES);
}
}

void CMOMBhopBlockFixSystem::PlayerTouch(CBaseEntity *pPlayerEnt, CBaseEntity *pBlock)
{
CMomentumPlayer *pPlayer = static_cast<CMomentumPlayer *>(pPlayerEnt);
float diff = gpGlobals->curtime - pPlayer->GetPunishTime();

if (pPlayer->GetLastBlock() != pBlock->entindex() || diff > BLOCK_COOLDOWN)
{
pPlayer->SetLastBlock(pBlock->entindex());
pPlayer->SetPunishTime(gpGlobals->curtime + BLOCK_TELEPORT);
}
else if (diff > BLOCK_TELEPORT) // We need to teleport the player.
{
int idx = m_mapBlocks.Find(pBlock->entindex());
if (m_mapBlocks.IsValidIndex(idx))
{
CBaseEntity *pEntTeleport = m_mapBlocks.Element(idx).m_pTeleportTrigger;
if (pEntTeleport)
{
pEntTeleport->Touch(pPlayer);
}
}
}
}

void CMOMBhopBlockFixSystem::FindTeleport(CBaseEntity *pBlockEnt, bool isDoor)
{
// Create Vectors for the start, stop, and direction
Vector vecAbsStart, vecAbsEnd, vecDir;

vecDir = Vector(0, 0, -1); // Straight down

// Get the Start/End
vecAbsStart = pBlockEnt->WorldSpaceCenter();
// move vector to top of bhop block
vecAbsStart.z += pBlockEnt->WorldAlignMaxs().z;

// ray is as long as the bhop block is tall
vecAbsEnd = vecAbsStart + (vecDir * (pBlockEnt->WorldAlignMaxs().z - pBlockEnt->WorldAlignMins().z));

// Do the TraceLine, and write our results to our trace_t class, tr.
Ray_t ray;
ray.Init(vecAbsStart, vecAbsEnd);
CTeleportTriggerTraceEnum triggerTraceEnum(&ray, pBlockEnt, isDoor);

enginetrace->EnumerateEntities(ray, true, &triggerTraceEnum);
}
// override of IEntityEnumerator's EnumEntity() for our trigger teleport filter
bool CTeleportTriggerTraceEnum::EnumEntity(IHandleEntity *pHandleEntity)
{
trace_t tr;
// store entity that we found on the trace
CBaseEntity *pEnt = gEntList.GetBaseEntity(pHandleEntity->GetRefEHandle());

// Done to avoid hitting an entity that's both solid & a trigger.
if (pEnt->IsSolid())
return false;

enginetrace->ClipRayToEntity(*m_pRay, MASK_ALL, pHandleEntity, &tr);

if (tr.fraction < 1.0f) // tr.fraction = 1.0 means the trace completed
{
// arguments are initilized in the constructor of CTeleportTriggerTraceEnum
g_MOMBlockFixer->AddBhopBlock(pEntBlock, pEnt, bIsDoor);
return true;
}
return false;
}

static CMOMBhopBlockFixSystem s_MOMBlockFixer("CMOMBhopBlockFixSystem");
CMOMBhopBlockFixSystem *g_MOMBlockFixer = &s_MOMBlockFixer;
73 changes: 73 additions & 0 deletions mp/src/game/server/momentum/mom_blockfix.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#ifndef DOORFIX_H
#define DOORFIX_H
#ifdef _WIN32
#pragma once
#endif

#include "buttons.h"
#include "cbase.h"
#include "doors.h"
#include "mom_player.h"

#define MAX_BHOPBLOCKS 1024
#define BLOCK_TELEPORT 0.11
#define BLOCK_COOLDOWN 1.0

class CMOMBhopBlockFixSystem : CAutoGameSystem
{

public:
CMOMBhopBlockFixSystem(const char *pName) : CAutoGameSystem(pName) {}

virtual void LevelInitPostEntity() { FindBhopBlocks(); }

virtual void LevelShutdownPostEntity() { m_mapBlocks.RemoveAll(); }

bool IsBhopBlock(int entIndex) { return (m_mapBlocks.Find(entIndex) != m_mapBlocks.InvalidIndex()); }

void PlayerTouch(CBaseEntity *pPlayerEnt, CBaseEntity *pBlock);

void FindBhopBlocks();

void FindTeleport(CBaseEntity *pBlockEnt, bool isDoor);

void AddBhopBlock(CBaseEntity *pBlockEnt, CBaseEntity *pTeleportEnt, bool isDoor)
{
bhop_block_t block = bhop_block_t();
block.m_pBlockEntity = pBlockEnt;
block.m_pTeleportTrigger = pTeleportEnt;
block.m_bIsDoor = isDoor;
AlterBhopBlock(block);
m_mapBlocks.Insert(pBlockEnt->entindex(), block);
}

private:
struct bhop_block_t
{
CBaseEntity *m_pBlockEntity; // func_door or func_button
CBaseEntity *m_pTeleportTrigger; // trigger_teleport under it
bool m_bIsDoor;
};
CUtlMap<int, bhop_block_t> m_mapBlocks;
void AlterBhopBlock(bhop_block_t);
};

class CTeleportTriggerTraceEnum : public IEntityEnumerator
{
public:
CTeleportTriggerTraceEnum(Ray_t *pRay, CBaseEntity *block, bool isDoor)
: m_pRay(pRay), pEntBlock(block), bIsDoor(isDoor)
{
}

virtual bool EnumEntity(IHandleEntity *pHandleEntity);

private:
bool bIsDoor;
CBaseEntity *pEntBlock;
Ray_t *m_pRay;
};

extern CMOMBhopBlockFixSystem *g_MOMBlockFixer;

#endif // DOORFIX_H
56 changes: 30 additions & 26 deletions mp/src/game/server/momentum/mom_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,16 @@ PRECACHE_REGISTER(player);

CMomentumPlayer::CMomentumPlayer()
{

m_flPunishTime = -1;
m_iLastBlock = -1;
}

CMomentumPlayer::~CMomentumPlayer()
{

}
CMomentumPlayer::~CMomentumPlayer() {}

void CMomentumPlayer::Precache()
{
// Name of our entity's model
#define ENTITY_MODEL "models/gibs/airboat_broken_engine.mdl"
// Name of our entity's model
#define ENTITY_MODEL "models/gibs/airboat_broken_engine.mdl"
PrecacheModel(ENTITY_MODEL);

BaseClass::Precache();
Expand All @@ -43,32 +41,32 @@ void CMomentumPlayer::Spawn()
SetModel(ENTITY_MODEL);
BaseClass::Spawn();
AddFlag(FL_GODMODE);
//do this here because we can't get a local player in the timer class
// do this here because we can't get a local player in the timer class
ConVarRef gm("mom_gamemode");
switch (gm.GetInt())
{
case MOMGM_BHOP:
case MOMGM_SURF:
case MOMGM_UNKNOWN:
default:
EnableAutoBhop();
break;
case MOMGM_SCROLL:
DisableAutoBhop();
break;
case MOMGM_BHOP:
case MOMGM_SURF:
case MOMGM_UNKNOWN:
default:
EnableAutoBhop();
break;
case MOMGM_SCROLL:
DisableAutoBhop();
break;
}
SetThink(&CMomentumPlayer::CheckForBhop); // Pass a function pointer
SetNextThink(gpGlobals->curtime);
}

void CMomentumPlayer::SurpressLadderChecks(const Vector& pos, const Vector& normal)
void CMomentumPlayer::SurpressLadderChecks(const Vector &pos, const Vector &normal)
{
m_ladderSurpressionTimer.Start(1.0f);
m_lastLadderPos = pos;
m_lastLadderNormal = normal;
}

bool CMomentumPlayer::CanGrabLadder(const Vector& pos, const Vector& normal)
bool CMomentumPlayer::CanGrabLadder(const Vector &pos, const Vector &normal)
{
if (m_ladderSurpressionTimer.GetRemainingTime() <= 0.0f)
{
Expand All @@ -89,7 +87,7 @@ bool CMomentumPlayer::CanGrabLadder(const Vector& pos, const Vector& normal)
return false;
}

CBaseEntity* CMomentumPlayer::EntSelectSpawnPoint()
CBaseEntity *CMomentumPlayer::EntSelectSpawnPoint()
{
CBaseEntity *pStart;
pStart = NULL;
Expand All @@ -112,7 +110,7 @@ CBaseEntity* CMomentumPlayer::EntSelectSpawnPoint()
}
}

bool CMomentumPlayer::SelectSpawnSpot(const char *pEntClassName, CBaseEntity* &pStart)
bool CMomentumPlayer::SelectSpawnSpot(const char *pEntClassName, CBaseEntity *&pStart)
{
#define SF_PLAYER_START_MASTER 1
pStart = gEntList.FindEntityByClassname(pStart, pEntClassName);
Expand Down Expand Up @@ -142,6 +140,15 @@ bool CMomentumPlayer::SelectSpawnSpot(const char *pEntClassName, CBaseEntity* &p

return false;
}

void CMomentumPlayer::Touch(CBaseEntity *pOther)
{
BaseClass::Touch(pOther);

if (g_MOMBlockFixer->IsBhopBlock(pOther->entindex()))
g_MOMBlockFixer->PlayerTouch(this, pOther);
}

void CMomentumPlayer::EnableAutoBhop()
{
m_bAutoBhop = true;
Expand All @@ -152,16 +159,13 @@ void CMomentumPlayer::DisableAutoBhop()
m_bAutoBhop = false;
DevLog("Disabled autobhop\n");
}
bool CMomentumPlayer::HasAutoBhop()
{
return m_bAutoBhop;
}
bool CMomentumPlayer::HasAutoBhop() { return m_bAutoBhop; }
void CMomentumPlayer::CheckForBhop()
{
if (GetGroundEntity() != NULL)
{
m_flTicksOnGround += gpGlobals->interval_per_tick;
//true is player is on ground for less than 4 ticks, false if they are on ground for more
// true is player is on ground for less than 10 ticks, false if they are on ground for more s
m_bDidPlayerBhop = (m_flTicksOnGround < NUM_TICKS_TO_BHOP * gpGlobals->interval_per_tick) != 0;
}
else
Expand Down
Loading

0 comments on commit 472b47a

Please sign in to comment.