Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New entity: trigger_bomb_reset #819

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions regamedll/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ set(GAMEDLL_SRCS
"dlls/API/CSPlayerWeapon.cpp"
"dlls/addons/item_airbox.cpp"
"dlls/addons/point_command.cpp"
"dlls/addons/trigger_bomb_reset.cpp"
"dlls/addons/trigger_random.cpp"
"dlls/addons/trigger_setorigin.cpp"
"dlls/wpn_shared/wpn_ak47.cpp"
Expand Down
39 changes: 39 additions & 0 deletions regamedll/dlls/addons/trigger_bomb_reset.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/

#include "precompiled.h"

LINK_ENTITY_TO_CLASS(trigger_bomb_reset, CTriggerBombReset, CCSTriggerBombReset)

void CTriggerBombReset::Spawn()
{
InitTrigger();
SetTouch(&CTriggerBombReset::Touch);
SetUse(&CTriggerBombReset::ToggleUse);
}

void CTriggerBombReset::Touch(CBaseEntity *pOther)
{
CWeaponBox *pWeaponBox = dynamic_cast<CWeaponBox *>(pOther);

if (pWeaponBox && pWeaponBox->m_bIsBomb)
{
// If the bomb touches this trigger, tell it to reset to its last known valid position.
pWeaponBox->ResetToLastValidPlayerHeldC4Position();
}
}
28 changes: 28 additions & 0 deletions regamedll/dlls/addons/trigger_bomb_reset.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/

#pragma once

#include "triggers.h"

class CTriggerBombReset: public CBaseTrigger
{
public:
virtual void Spawn();
virtual void Touch(CBaseEntity *pOther);
};
1 change: 1 addition & 0 deletions regamedll/dlls/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8218,6 +8218,7 @@ CBaseEntity *EXT_FUNC CBasePlayer::__API_HOOK(DropPlayerItem)(const char *pszIte
pWeaponBox->m_bIsBomb = true;
pWeaponBox->SetThink(&CWeaponBox::BombThink);
pWeaponBox->pev->nextthink = gpGlobals->time + 1.0f;
pWeaponBox->SetLastValidHeldC4Position(((CC4 *)pWeapon)->GetLastValidHeldPosition());

if (TheCSBots())
{
Expand Down
18 changes: 18 additions & 0 deletions regamedll/dlls/weapons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2269,6 +2269,24 @@ void CWeaponBox::SetObjectCollisionBox()
pev->absmax = pev->origin + Vector(16, 16, 16);
}

void CWeaponBox::ResetToLastValidPlayerHeldC4Position()
{
if (pev->origin == m_vecLastValidPlayerHeldC4Position)
{
return;
}

Vector const vecResetPos = m_vecLastValidPlayerHeldC4Position + Vector(0.0f, 0.0f, 8.0f);
Vector const angResetAng = Vector(0.0f, RANDOM_FLOAT(0.0f, 360.0f), 0.0f);

// Teleport
pev->velocity = Vector(0.0f, 0.0f, 0.0f);
pev->movetype = MOVETYPE_NONE;
pev->flags |= FL_ONGROUND;
pev->angles = angResetAng;
UTIL_SetOrigin(pev, vecResetPos);
}

char *CArmoury::m_ItemModels[] = {
"models/w_mp5.mdl",
"models/w_tmp.mdl",
Expand Down
12 changes: 12 additions & 0 deletions regamedll/dlls/weapons.h
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,9 @@ class CWeaponBox: public CBaseEntity
void SetModel_OrigFunc(const char *pszModelName);
#endif

void SetLastValidHeldC4Position(const Vector &vecPositon) { m_vecLastValidPlayerHeldC4Position = vecPositon; }
void ResetToLastValidPlayerHeldC4Position();

public:
static TYPEDESCRIPTION m_SaveData[];

Expand All @@ -494,6 +497,9 @@ class CWeaponBox: public CBaseEntity
int m_rgAmmo[MAX_AMMO_SLOTS];
int m_cAmmoTypes;
bool m_bIsBomb;

private:
Vector m_vecLastValidPlayerHeldC4Position;
};


Expand Down Expand Up @@ -846,6 +852,7 @@ class CAWP: public CBasePlayerWeapon

const float C4_MAX_SPEED = 250.0f;
const float C4_ARMING_ON_TIME = 3.0f;
constexpr float WEAPON_C4_UPDATE_LAST_VALID_PLAYER_HELD_POSITION_INTERVAL = 0.2f;

enum c4_e
{
Expand All @@ -865,6 +872,7 @@ class CC4: public CBasePlayerWeapon
virtual int GetItemInfo(ItemInfo *p);
virtual BOOL Deploy();
virtual void Holster(int skiplocal);
virtual void AttachToPlayer(CBasePlayer *pPlayer);
virtual float GetMaxSpeed();
virtual int iItemSlot() { return C4_SLOT; }
virtual void PrimaryAttack();
Expand All @@ -878,13 +886,17 @@ class CC4: public CBasePlayerWeapon
#endif
}

void EXPORT TrackPlayerHeldPosition();
Vector GetLastValidHeldPosition() const { return m_vecLastValidPlayerHeldPosition; }

public:
bool m_bStartedArming;
bool m_bBombPlacedAnimation;
float m_fArmedTime;

private:
bool m_bHasShield;
Vector m_vecLastValidPlayerHeldPosition;
};


Expand Down
30 changes: 30 additions & 0 deletions regamedll/dlls/wpn_shared/wpn_c4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,3 +382,33 @@ float CC4::GetMaxSpeed()

return C4_MAX_SPEED;
}

void CC4::AttachToPlayer(CBasePlayer *pPlayer)
{
CBasePlayerWeapon::AttachToPlayer(pPlayer);

#ifdef REGAMEDLL_ADD
SetThink(&CC4::TrackPlayerHeldPosition);
pev->nextthink = gpGlobals->time + WEAPON_C4_UPDATE_LAST_VALID_PLAYER_HELD_POSITION_INTERVAL;

if (pPlayer->IsPlayer() && pPlayer->IsAlive())
{
entvars_t *pevPlayer = pPlayer->pev;
m_vecLastValidPlayerHeldPosition = pevPlayer->origin + pevPlayer->mins;
}
#endif
}

void CC4::TrackPlayerHeldPosition()
{
pev->nextthink = gpGlobals->time + WEAPON_C4_UPDATE_LAST_VALID_PLAYER_HELD_POSITION_INTERVAL;

// If the bomb is held by an alive player standing on the ground, then we can use this
// position as the last known valid position to respawn the bomb if it gets reset.

if (m_pPlayer && m_pPlayer->IsPlayer() && m_pPlayer->IsAlive() && (m_pPlayer->pev->flags & FL_ONGROUND))
{
entvars_t *pevPlayer = m_pPlayer->pev;
m_vecLastValidPlayerHeldPosition = pevPlayer->origin + pevPlayer->mins;
}
}
4 changes: 4 additions & 0 deletions regamedll/extra/Toolkit/GameDefinitionFile/regamedll-cs.fgd
Original file line number Diff line number Diff line change
Expand Up @@ -2272,6 +2272,10 @@
]
]

@SolidClass base(Trigger) = trigger_bomb_reset : "Trigger bomb reset"
[
]

// Function entities
@SolidClass = func_bomb_target : "Bomb target zone"
[
Expand Down
4 changes: 3 additions & 1 deletion regamedll/msvc/ReGameDLL.vcxproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug Play|Win32">
Expand All @@ -25,6 +25,7 @@
<ItemGroup>
<ClCompile Include="..\dlls\addons\item_airbox.cpp" />
<ClCompile Include="..\dlls\addons\point_command.cpp" />
<ClCompile Include="..\dlls\addons\trigger_bomb_reset.cpp" />
<ClCompile Include="..\dlls\addons\trigger_random.cpp" />
<ClCompile Include="..\dlls\addons\trigger_setorigin.cpp" />
<ClCompile Include="..\dlls\airtank.cpp" />
Expand Down Expand Up @@ -620,6 +621,7 @@
<ClInclude Include="..\dlls\activity.h" />
<ClInclude Include="..\dlls\addons\item_airbox.h" />
<ClInclude Include="..\dlls\addons\point_command.h" />
<ClInclude Include="..\dlls\addons\trigger_bomb_reset.h" />
<ClInclude Include="..\dlls\addons\trigger_random.h" />
<ClInclude Include="..\dlls\addons\trigger_setorigin.h" />
<ClInclude Include="..\dlls\airtank.h" />
Expand Down
12 changes: 9 additions & 3 deletions regamedll/msvc/ReGameDLL.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="engine">
Expand Down Expand Up @@ -552,6 +552,9 @@
<ClCompile Include="..\dlls\addons\point_command.cpp">
<Filter>dlls\addons</Filter>
</ClCompile>
<ClCompile Include="..\dlls\addons\trigger_bomb_reset.cpp">
<Filter>dlls\addons</Filter>
</ClCompile>
<ClCompile Include="..\public\FileSystem.cpp">
<Filter>public</Filter>
</ClCompile>
Expand Down Expand Up @@ -1046,14 +1049,17 @@
<ClInclude Include="..\public\regamedll\API\CSPlayerItem.h">
<Filter>public\regamedll\API</Filter>
</ClInclude>
<ClInclude Include="..\public\utlarray.h">
<Filter>public</Filter>
</ClInclude>
<ClInclude Include="..\dlls\addons\trigger_random.h">
<Filter>dlls\addons</Filter>
</ClInclude>
<ClInclude Include="..\dlls\addons\point_command.h">
<Filter>dlls\addons</Filter>
</ClInclude>
<ClInclude Include="..\public\utlarray.h">
<Filter>public</Filter>
<ClInclude Include="..\dlls\addons\trigger_bomb_reset.h">
<Filter>dlls\addons</Filter>
</ClInclude>
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions regamedll/public/regamedll/API/CSInterfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ class CCSChangeLevel: public CCSTrigger {};
class CCSLadder: public CCSTrigger {};
class CCSTriggerPush: public CCSTrigger {};
class CCSTriggerTeleport: public CCSTrigger {};
class CCSTriggerBombReset: public CCSTrigger {};
class CCSBuyZone: public CCSTrigger {};
class CCSBombTarget: public CCSTrigger {};
class CCSHostageRescue: public CCSTrigger {};
Expand Down
1 change: 1 addition & 0 deletions regamedll/regamedll/dlls.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ using FloatRef = float;
#include "addons/trigger_setorigin.h"
#include "addons/trigger_random.h"
#include "addons/point_command.h"
#include "addons/trigger_bomb_reset.h"

// Tutor
#include "tutor.h"
Expand Down