Skip to content

Commit

Permalink
Merged in ez2/feature/initial-surrender-fixes (pull request mapbase-s…
Browse files Browse the repository at this point in the history
…ource#182)

Smarter surrender hints + Minor surrender behavior AI fix

Approved-by: 1upD
  • Loading branch information
Blixibon authored and 1upD committed Sep 9, 2021
2 parents 99564fb + d3fba1d commit 953390a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
9 changes: 6 additions & 3 deletions sp/src/game/server/ez2/ai_behavior_surrender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,6 @@ void CAI_SurrenderBehavior::RunTask( const Task_t *pTask )

if( pHint == NULL )
{
//SetCondition( COND_SURRENDER_ANYWHERE ); // For now, surrender here
//TaskFail("Surrender: Couldn't find hint node\n");

if (vecDest != vec3_invalid)
{
if (GetNavigator()->SetGoal( vecDest ))
Expand All @@ -210,6 +207,12 @@ void CAI_SurrenderBehavior::RunTask( const Task_t *pTask )

m_hMovingToHint.Set( NULL );
}
else
{
//SetCondition( COND_SURRENDER_ANYWHERE ); // For now, surrender here
//TaskFail("Surrender: Couldn't find hint node\n");
GetOuter()->TaskComplete();
}
}
else
{
Expand Down
24 changes: 22 additions & 2 deletions sp/src/game/server/ez2/ez2_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,31 @@ bool SurrenderableCitizenHintTest( CEZ2_Player *pPlayer, CBaseEntity *pActivator
if (pPlayer->GetVisibleEnemies() > 2)
return false;

// Only our current enemy
if (pPlayer->GetEnemy() != pActivator)
return false;

if (pActivator->Classify() == CLASS_PLAYER_ALLY && pActivator->MyNPCPointer()->GetActiveWeapon() == NULL)
{
// Check our enemy memory; Make sure we see them
CAI_Enemies *pEnemies = pPlayer->GetNPCComponent()->GetEnemies();
AI_EnemyInfo_t *pEnemyInfo = pEnemies->Find( pActivator );
if (!pEnemyInfo || (gpGlobals->curtime - pEnemyInfo->timeLastSeen) > 2.0f)
return false;

CNPC_Citizen *pCitizen = dynamic_cast<CNPC_Citizen*>(pActivator);
if (pCitizen && !pCitizen->IsSurrendered() && pCitizen->CanSurrender() && pPlayer->GetAbsOrigin().DistToSqr(pActivator->GetAbsOrigin()) <= Square(192.0f))
return true;
if (pCitizen && !pCitizen->IsSurrendered() && pCitizen->CanSurrender() && !pCitizen->SurrenderAutomatically()
&& pPlayer->GetAbsOrigin().DistToSqr( pActivator->GetAbsOrigin() ) <= Square( 224.0f ))
{
// Make sure they're not about to pick up a weapon
if (pCitizen->IsCurSchedule( SCHED_NEW_WEAPON, false ))
return false;

// Finally, check if the citizen has begged already
float flTimeSpeakBeg = pCitizen->GetTimeSpokeConcept( TLK_BEG );
if (flTimeSpeakBeg != -1 && gpGlobals->curtime - flTimeSpeakBeg >= 2.0f)
return true;
}
}

return false;
Expand Down
1 change: 1 addition & 0 deletions sp/src/game/server/hl2/npc_citizen17.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ class CNPC_Citizen : public CNPC_PlayerCompanion
inline bool IsSurrendered() { return m_SurrenderBehavior.IsSurrendered(); } //{ return GetContextValue( "surrendered" )[0] == '1'; };
inline bool IsSurrenderIdle() { return m_SurrenderBehavior.IsSurrenderIdle(); }
inline bool CanSurrender() { return m_SurrenderBehavior.CanSurrender(); }
inline bool SurrenderAutomatically() { return m_SurrenderBehavior.SurrenderAutomatically(); }
#endif
void MsgWillpower(const tchar* pMsg, int willpower);
int TranslateWillpowerSchedule(int scheduleType);
Expand Down

0 comments on commit 953390a

Please sign in to comment.