Skip to content

Commit

Permalink
Some buildable and Lua changes
Browse files Browse the repository at this point in the history
- Changed how the lua function `trigger:onbuild()` behaved
    - Individual buildables now controllable by lua.
    - `trigger:onbuild()` no longer returns a player object, instead returns what's being built.
    - Now Detpacks can be controlled even by their fuse time, (example - detpack for fuse time 10 is accepted, but any other is declined)

- Added detpack methods for lua
    - `detpack:GetFuseTime()` - Gets the fuse time of the detpack.
    - `detpack:GetDetonateTime()` Returns the exact game time it'll detonate on.
    - `detpack:LastFiveSeconds()` Retruns a boolean value, true if only five seconds are remaining for the detpack to explode.
  • Loading branch information
YoYo178 authored and squeek502 committed Dec 14, 2022
1 parent 4d8fb70 commit 1ec8571
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 14 deletions.
3 changes: 2 additions & 1 deletion dlls/ff/ff_detpack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,8 @@ CFFDetpack *CFFDetpack::Create( const Vector &vecOrigin, const QAngle &vecAngles
pObject->VPhysicsInitNormal( SOLID_VPHYSICS, pObject->GetSolidFlags(), true );

// Spawn the object
pObject->Spawn( );
//pObject->Spawn();
// commented out for better nobuild functions, will be spawned ONLY IF it's allowed to, from ff_player.cpp

return pObject;
}
Expand Down
3 changes: 2 additions & 1 deletion dlls/ff/ff_dispenser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,8 @@ CFFDispenser *CFFDispenser::Create( const Vector &vecOrigin, const QAngle &vecAn
//pObject->VPhysicsInitNormal( SOLID_VPHYSICS, pObject->GetSolidFlags(), true );

// Spawn the object
pObject->Spawn();
//pObject->Spawn();
// commented out for better nobuild functions, will be spawned ONLY IF it's allowed to, from ff_player.cpp

return pObject;
}
Expand Down
3 changes: 3 additions & 0 deletions dlls/ff/ff_lualib_buildables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,8 @@ void CFFLuaLib::InitBuildables(lua_State* L)

// Detpack
class_<CFFDetpack, CFFBuildableObject>("Detpack")
.def("GetFuseTime", &CFFDetpack::GetFuseTime)
.def("GetDetonateTime", &CFFDetpack::GetDetonateTime)
.def("LastFiveSeconds", &CFFDetpack::LastFiveSeconds)
];
};
3 changes: 2 additions & 1 deletion dlls/ff/ff_mancannon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ CFFManCannon *CFFManCannon::Create( const Vector& vecOrigin, const QAngle& vecAn

pObject->m_hOwner.GetForModify() = pentOwner;
pObject->VPhysicsInitNormal( SOLID_VPHYSICS, pObject->GetSolidFlags(), true );
pObject->Spawn();
//pObject->Spawn();
// commented out for better nobuild functions, will be spawned ONLY IF it's allowed to, from ff_player.cpp

return pObject;
}
Expand Down
91 changes: 83 additions & 8 deletions dlls/ff/ff_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3222,8 +3222,11 @@ void CFFPlayer::PreBuildGenericThink( void )
m_vecBuildOrigin = GetAbsOrigin();

// See if player is in a no build area first

// TODO: need to check where the SG is being built, NOT where player is? - AfterShock
if( IsInNoBuild() && ( (m_iWantBuild == FF_BUILD_DISPENSER) || (m_iWantBuild == FF_BUILD_SENTRYGUN) || (m_iWantBuild == FF_BUILD_MANCANNON) ) )
// Status: Complete

/*if( IsInNoBuild() && ( (m_iWantBuild == FF_BUILD_DISPENSER) || (m_iWantBuild == FF_BUILD_SENTRYGUN) || (m_iWantBuild == FF_BUILD_MANCANNON) ) )
{
Omnibot::Notify_Build_CantBuild(this, m_iWantBuild);
Expand All @@ -3236,7 +3239,7 @@ void CFFPlayer::PreBuildGenericThink( void )
ClientPrint( this, HUD_PRINTCENTER, "#FF_BUILDERROR_NOBUILD" );
return;
}
}*/

/*
DevMsg( "[Building] Not currently building so lets try to build a: %s" );
Expand Down Expand Up @@ -3349,7 +3352,7 @@ void CFFPlayer::PreBuildGenericThink( void )

// Changed to building straight on ground (Bug #0000191: Engy "imagines" SG placement, then lifts SG, then back to imagined position.)
CFFDispenser *pDispenser = CFFDispenser::Create( hBuildInfo.GetBuildOrigin(), hBuildInfo.GetBuildAngles(), this );

// Set custom text
pDispenser->SetText( m_szCustomDispenserText );

Expand All @@ -3359,6 +3362,24 @@ void CFFPlayer::PreBuildGenericThink( void )
pDispenser->SetGroundOrigin( hBuildInfo.GetBuildOrigin() );
pDispenser->SetGroundAngles( hBuildInfo.GetBuildAngles() );

// Send info to "trigger:onbuild()" lua function after setting buildable info, see if it's allowed
if( IsInNoBuild( pDispenser ) ) {
pDispenser->Cancel();
pDispenser->Remove(); // prevent leaving model in any case
pDispenser = NULL; // not sure if this is needed, added it anyway
// Re-initialize
m_iCurBuild = FF_BUILD_NONE;
m_iWantBuild = FF_BUILD_NONE;
m_bBuilding = false;
m_bStaticBuilding = false;

ClientPrint( this, HUD_PRINTCENTER, "#FF_BUILDERROR_NOBUILD" );

return;
} else {
pDispenser->Spawn();
}

// Set network var
m_hDispenser = pDispenser;

Expand Down Expand Up @@ -3403,13 +3424,31 @@ void CFFPlayer::PreBuildGenericThink( void )

// Changed to building straight on ground (Bug #0000191: Engy "imagines" SG placement, then lifts SG, then back to imagined position.)
CFFSentryGun *pSentryGun = CFFSentryGun::Create( hBuildInfo.GetBuildOrigin(), hBuildInfo.GetBuildAngles(), this );

pSentryGun->SetLocation(g_pGameRules->GetChatLocation(true, this));

// Mirv: Store future ground location + orientation
pSentryGun->SetGroundOrigin( hBuildInfo.GetBuildOrigin() );
pSentryGun->SetGroundAngles( hBuildInfo.GetBuildAngles() );

// Send info to "trigger:onbuild()" lua function after setting buildable info, see if it's allowed
if( IsInNoBuild( pSentryGun ) ) {
pSentryGun->Cancel();
pSentryGun->Remove(); // prevent leaving model in any case
pSentryGun = NULL; // not sure if this is needed, added it anyway
// Re-initialize
m_iCurBuild = FF_BUILD_NONE;
m_iWantBuild = FF_BUILD_NONE;
m_bBuilding = false;
m_bStaticBuilding = false;

ClientPrint( this, HUD_PRINTCENTER, "#FF_BUILDERROR_NOBUILD" );

return;
} else {
pSentryGun->Spawn();
}

// Set network var
m_hSentryGun = pSentryGun;

Expand All @@ -3431,15 +3470,33 @@ void CFFPlayer::PreBuildGenericThink( void )
// Changed to building straight on ground (Bug #0000191: Engy "imagines" SG placement, then lifts SG, then back to imagined position.)
CFFDetpack *pDetpack = CFFDetpack::Create( hBuildInfo.GetBuildOrigin(), hBuildInfo.GetBuildAngles(), this );

pDetpack->SetLocation(g_pGameRules->GetChatLocation(true, this));

// Set the fuse time
pDetpack->m_iFuseTime = m_iDetpackTime;

pDetpack->SetLocation(g_pGameRules->GetChatLocation(true, this));

// Mirv: Store future ground location + orientation
pDetpack->SetGroundOrigin( hBuildInfo.GetBuildOrigin() );
pDetpack->SetGroundAngles( hBuildInfo.GetBuildAngles() );

// Send info to "trigger:onbuild()" lua function after setting buildable info, see if it's allowed
if( IsInNoBuild( pDetpack ) ) {
pDetpack->Cancel();
pDetpack->Remove(); // prevent leaving model in any case
pDetpack = NULL; // not sure if this is needed, added it anyway
// Re-initialize
m_iCurBuild = FF_BUILD_NONE;
m_iWantBuild = FF_BUILD_NONE;
m_bBuilding = false;
m_bStaticBuilding = false;

ClientPrint( this, HUD_PRINTCENTER, "#FF_BUILDERROR_NOBUILD" );

return;
} else {
pDetpack->Spawn();
}

// Set network var
m_hDetpack = pDetpack;

Expand All @@ -3458,6 +3515,24 @@ void CFFPlayer::PreBuildGenericThink( void )
pManCannon->SetGroundOrigin( hBuildInfo.GetBuildOrigin() );
pManCannon->SetGroundAngles( hBuildInfo.GetBuildAngles() );

// Send info to "trigger:onbuild()" lua function after setting buildable info, see if it's allowed
if( IsInNoBuild( pManCannon ) ) {
pManCannon->Cancel();
pManCannon->Remove(); // prevent leaving model in any case
pManCannon = NULL; // not sure if this is needed, added it anyway
// Re-initialize
m_iCurBuild = FF_BUILD_NONE;
m_iWantBuild = FF_BUILD_NONE;
m_bBuilding = false;
m_bStaticBuilding = false;

ClientPrint( this, HUD_PRINTCENTER, "#FF_BUILDERROR_NOBUILD" );

return;
} else {
pManCannon->Spawn();
}

m_hManCannon = pManCannon;
m_flBuildTime = gpGlobals->curtime + 3.5f; // 3.5 seconds to build?

Expand Down Expand Up @@ -6868,7 +6943,7 @@ bool CFFPlayer::HasItem(const char* itemname) const
}

//-----------------------------------------------------------------------------
bool CFFPlayer::IsInNoBuild()
bool CFFPlayer::IsInNoBuild( CBaseEntity *pEntity )
{
Vector vecForward;
EyeVectors(&vecForward);
Expand All @@ -6884,7 +6959,7 @@ bool CFFPlayer::IsInNoBuild()
}
#endif

return !FFScriptRunPredicates( (CBaseEntity*)this, "onbuild", true, vecOrigin, 40.0f );
return !FFScriptRunPredicates( pEntity, "onbuild", true, vecOrigin, 40.0f );
}


Expand Down
2 changes: 1 addition & 1 deletion dlls/ff/ff_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ class CFFPlayer : public CBasePlayer, public IFFPlayerAnimStateHelpers
// <-- Mirv: Damage & force stuff

bool HasItem(const char* szItemName) const;
bool IsInNoBuild();
bool IsInNoBuild( CBaseEntity *pEntity );
bool IsUnderWater() const { return (GetWaterLevel() == WL_Eyes); }
bool IsWaistDeepInWater() const { return (GetWaterLevel() == WL_Waist); }
bool IsFeetDeepInWater() const { return (GetWaterLevel() == WL_Feet); }
Expand Down
3 changes: 2 additions & 1 deletion dlls/ff/ff_sentrygun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1773,7 +1773,8 @@ CFFSentryGun *CFFSentryGun::Create( const Vector &vecOrigin, const QAngle &vecAn
//pObject->VPhysicsInitNormal( SOLID_VPHYSICS, pObject->GetSolidFlags(), true );

// Spawn the object
pObject->Spawn();
//pObject->Spawn();
// commented out for better nobuild functions, will be spawned ONLY IF it's allowed to, from ff_player.cpp

return pObject;
}
Expand Down
18 changes: 17 additions & 1 deletion game_shared/ff/ff_buildableobjects_shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,22 @@ class CFFDetpack : public CFFBuildableObject
int m_iFuseTime;
float m_flDetonateTime;
bool m_bFiveSeconds;

int GetFuseTime()
{
return m_iFuseTime;
}

int GetDetonateTime()
{
return m_flDetonateTime;
}

bool LastFiveSeconds()
{
return m_bFiveSeconds;
}

#endif

};
Expand Down Expand Up @@ -1065,4 +1081,4 @@ inline CFFManCannon *FF_ToManCannon( CBaseEntity *pEntity )
return static_cast< CFFManCannon * >( pEntity );
}

#endif // FF_BUILDABLEOBJECTS_SHARED_H
#endif // FF_BUILDABLEOBJECTS_SHARED_H

0 comments on commit 1ec8571

Please sign in to comment.