-
-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from momentum-mod/doorfix_wip
func_door and func_button bhop block fix
- Loading branch information
Showing
14 changed files
with
340 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.