Skip to content
Merged
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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,14 @@ Other sources:

//-------------------------------------------------------------------------------------------------------------------------

Mapbase additionally contains the following features originally created for Team Fortress 2 Classic:

- TF-Style Instructor Hint Background by MaartenS11
- TF-Style Instructor Hint Icons by Wheat (This is asset-based and not reflected in the code)
- env_instructor_hint team and class support by azzy

//-------------------------------------------------------------------------------------------------------------------------

If there is anything missing from this list, please contact Blixibon.

//=========================================================================================================================
Expand Down
68 changes: 63 additions & 5 deletions src/game/client/c_baselesson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
#include "vstdlib/IKeyValuesSystem.h"
#ifdef MAPBASE
#include "usermessages.h"
#ifdef TF_CLIENT_DLL
#include "c_tf_player.h"
#endif
#endif

// memdbgon must be the last include file in a .cpp file!!!
Expand Down Expand Up @@ -448,6 +451,8 @@ void CIconLesson::Init()

m_iIconTargetPos = ICON_TARGET_EYE_POSITION;
m_szHudHint = "";
m_iHintEntSpawnFlags = 0;
m_iHintEntTeam = 0;
#else
m_szCaptionColor = "255,255,255";// Default to white
#endif
Expand Down Expand Up @@ -701,6 +706,36 @@ bool CIconLesson::ShouldDisplay() const
}
}

#ifdef MAPBASE
if ( m_iHintEntSpawnFlags || m_iHintEntTeam )
{
C_BasePlayer *pLocalPlayer = GetGameInstructor().GetLocalPlayer();
if ( pLocalPlayer )
{
#ifdef TF_CLIENT_DLL
C_TFPlayer *pTFPlayer = static_cast<C_TFPlayer*>( pLocalPlayer );
if ( m_iHintEntSpawnFlags )
{
int iClass = pTFPlayer->GetPlayerClass()->GetClassIndex();
int bits = pow(2, iClass);
if ( !(m_iHintEntSpawnFlags & bits) )
{
return false;
}
}
#endif
if ( m_iHintEntTeam )
{
int iTeam = pLocalPlayer->GetTeamNumber();
if ( m_iHintEntTeam != iTeam )
{
return false;
}
}
}
}
#endif

// Ok to display
return true;
}
Expand Down Expand Up @@ -1033,6 +1068,9 @@ Vector CIconLesson::GetIconTargetPosition( C_BaseEntity *pIconTarget )
\
LESSON_VARIABLE_MACRO( ICON_TARGET_POS, m_iIconTargetPos, int ) \
LESSON_VARIABLE_MACRO_STRING( HUD_HINT_AFTER_LEARNED, m_szHudHint, CGameInstructorSymbol ) \
\
LESSON_VARIABLE_MACRO( ENT_SPAWNFLAGS, m_iHintEntSpawnFlags, int ) \
LESSON_VARIABLE_MACRO( ENT_TEAM, m_iHintEntTeam, int ) \


// Create keyvalues name symbol
Expand Down Expand Up @@ -1298,6 +1336,22 @@ void CScriptedIconLesson::Init()
// Initialize from the key value file
InitFromKeys( GetGameInstructor().GetScriptKeys() );

#if defined(MAPBASE) && defined(TF_CLIENT_DLL)
// Enable tf_scan_potential_use_target if this lesson utilizes use_target
extern ConVar tf_scan_potential_use_target;
CGameInstructorSymbol szUseTargetEvent( "use_target" );

CUtlVector< LessonEvent_t > &openEvents = m_OpenEvents;
for ( int i = 0; i < openEvents.Count(); i++ )
{
if ( openEvents[i].szEventName == szUseTargetEvent )
{
tf_scan_potential_use_target.SetValue( 1 );
break;
}
}
#endif

if ( m_iPriority >= LESSON_PRIORITY_MAX )
{
DevWarning( "Priority level not set for lesson: %s\n", GetName() );
Expand Down Expand Up @@ -1606,7 +1660,11 @@ void CScriptedIconLesson::ProcessOpenGameEvents( const CScriptedIconLesson *pRoo
}

MEM_ALLOC_CREDIT();
#ifdef MAPBASE
CScriptedIconLesson *pOpenLesson = CreateLessonCopy();
#else
CScriptedIconLesson *pOpenLesson = new CScriptedIconLesson( GetName(), false, true );
#endif

// Run copy macros on all scriptable variables (see: LESSON_VARIABLE_FACTORY definition)
#define LESSON_VARIABLE_MACRO LESSON_VARIABLE_COPY
Expand Down Expand Up @@ -2657,13 +2715,13 @@ bool CScriptedIconLesson::ProcessElementAction( int iAction, bool bNot, const ch
bool CScriptedIconLesson::ProcessElementAction( int iAction, bool bNot, const char *pchVarName, EHANDLE &hVar, const CGameInstructorSymbol *pchParamName, float fParam, C_BaseEntity *pParam, const char *pchParam )
{
// First try to let the mod act on the action
/*bool bModHandled = false;
bool bModHandled = false;
bool bModReturn = Mod_ProcessElementAction( iAction, bNot, pchVarName, hVar, pchParamName, fParam, pParam, pchParam, bModHandled );

if ( bModHandled )
{
return bModReturn;
}*/
}

C_BaseEntity *pVar = hVar.Get();

Expand Down Expand Up @@ -3619,7 +3677,7 @@ bool CScriptedIconLesson::ProcessElementAction( int iAction, bool bNot, const ch
return true;
}

/*case LESSON_ACTION_GET_POTENTIAL_USE_TARGET:
case LESSON_ACTION_GET_POTENTIAL_USE_TARGET:
{
int iTemp = static_cast<int>( fParam );

Expand Down Expand Up @@ -3670,7 +3728,7 @@ bool CScriptedIconLesson::ProcessElementAction( int iAction, bool bNot, const ch
}

return true;
}*/
}
}

DevWarning( "Invalid lesson action type used with \"%s\" variable type.\n", pchVarName );
Expand Down Expand Up @@ -3891,5 +3949,5 @@ void CScriptedIconLesson::PreReadLessonsFromFile()
CScriptedIconLesson::LessonActionMap.Insert( "get potential use target", LESSON_ACTION_GET_POTENTIAL_USE_TARGET );

// Add mod actions to the map
//Mod_PreReadLessonsFromFile();
Mod_PreReadLessonsFromFile();
}
9 changes: 9 additions & 0 deletions src/game/client/c_baselesson.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ class CIconLesson : public CTextLesson
};

CGameInstructorSymbol m_szHudHint;

int m_iHintEntSpawnFlags;
int m_iHintEntTeam;
#endif
};

Expand Down Expand Up @@ -402,6 +405,10 @@ class CScriptedIconLesson : public CIconLesson

bool ProcessElements( IGameEvent *event, const CUtlVector< LessonElement_t > *pElements );

#ifdef MAPBASE
virtual CScriptedIconLesson *CreateLessonCopy() { return new CScriptedIconLesson( GetName(), false, true ); }
#endif

private:
void InitElementsFromKeys( CUtlVector< LessonElement_t > *pLessonElements, KeyValues *pKey );
void InitElementsFromElements( CUtlVector< LessonElement_t > *pLessonElements, const CUtlVector< LessonElement_t > *pLessonElements2 );
Expand All @@ -428,6 +435,7 @@ class CScriptedIconLesson : public CIconLesson
private:
static CUtlDict< int, int > LessonActionMap;

protected:
EHANDLE m_hLocalPlayer;
float m_fOutput;
CHandle<C_BaseEntity> m_hEntity1;
Expand All @@ -439,6 +447,7 @@ class CScriptedIconLesson : public CIconLesson
float m_fFloat1;
float m_fFloat2;

private:
CUtlVector< CGameInstructorSymbol > m_PrerequisiteNames;
CUtlVector< LessonEvent_t > m_OpenEvents;
CUtlVector< LessonEvent_t > m_CloseEvents;
Expand Down
3 changes: 3 additions & 0 deletions src/game/client/c_baseplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,9 @@ class C_BasePlayer : public C_BaseCombatCharacter, public CGameEventListener
bool IsPoisoned( void ) { return m_Local.m_bPoisoned; }

C_BaseEntity *GetUseEntity();
#ifdef MAPBASE // From Alien Swarm SDK
virtual C_BaseEntity *GetPotentialUseEntity() { return GetUseEntity(); }
#endif

// Vehicles...
IClientVehicle *GetVehicle();
Expand Down
18 changes: 16 additions & 2 deletions src/game/client/c_gameinstructor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,7 @@ void C_GameInstructor::Shutdown()
//=========================================================
void C_GameInstructor::UpdateHiddenByOtherElements()
{
//bool bHidden = Mod_HiddenByOtherElements();
bool bHidden = false;
bool bHidden = Mod_HiddenByOtherElements();

if ( bHidden && !m_bHiddenDueToOtherElements )
StopAllLessons();
Expand Down Expand Up @@ -1276,8 +1275,23 @@ void C_GameInstructor::ReadLessonsFromFile( const char *pchFileName )
continue;
}

#ifdef MAPBASE
const char *pszLessonType = m_pScriptKeys->GetString( "lesson_type", "locator" );
if ( pszLessonType )
{
if (FStrEq( pszLessonType, "locator" ))
{
DefineLesson( new CScriptedIconLesson( m_pScriptKeys->GetName(), false, false ) );
}
else if (!Mod_DefineLessonType( m_pScriptKeys->GetName(), pszLessonType ))
{
Warning( "Lesson \"%s\" has unknown type \"%s\"\n", m_pScriptKeys->GetName(), pszLessonType );
}
}
#else
CScriptedIconLesson *pNewLesson = new CScriptedIconLesson(m_pScriptKeys->GetName(), false, false);
GetGameInstructor().DefineLesson(pNewLesson);
#endif
}

m_pScriptKeys = NULL;
Expand Down
6 changes: 5 additions & 1 deletion src/game/client/c_gameinstructor.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ class C_GameInstructor : public CAutoGameSystemPerFrame, public CGameEventListen

void DefineLesson( CBaseLesson *pLesson );

#ifdef MAPBASE
bool Mod_DefineLessonType( const char *pszLessonName, const char *pszLessonType );
#endif

const CBaseLesson * GetLesson( const char *pchLessonName );
bool IsLessonOfSameTypeOpen( const CBaseLesson *pLesson ) const;

Expand All @@ -60,6 +64,7 @@ class C_GameInstructor : public CAutoGameSystemPerFrame, public CGameEventListen
void PlaySound( const char *pchSoundName );

bool OpenOpportunity( CBaseLesson *pLesson );
void CloseOpportunity( CBaseLesson *pLesson );

void DumpOpenOpportunities( void );

Expand All @@ -83,7 +88,6 @@ class C_GameInstructor : public CAutoGameSystemPerFrame, public CGameEventListen
void StopAllLessons( void );

void CloseAllOpenOpportunities( void );
void CloseOpportunity( CBaseLesson *pLesson );

void InitLessonPrerequisites( void );

Expand Down
89 changes: 89 additions & 0 deletions src/game/client/c_mod_lesson_stubs.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
//========= Copyright © 1996-2008, Valve Corporation, All rights reserved. ============//
//
// Purpose: Stub for custom mod lesson actions.
// This is so that mods can do actions
// Remove this file from the mod's vpc and include your own.
//
//=============================================================================//

#include "cbase.h"

#include "c_gameinstructor.h"
#include "c_baselesson.h"

// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"


extern ConVar gameinstructor_verbose;


enum Mod_LessonAction
{
// Enum starts from end of LessonAction
LESSON_ACTION_MOD_CUSTOM_ACTION_STUB = LESSON_ACTION_MOD_START,

LESSON_ACTION_TOTAL
};


void CScriptedIconLesson::Mod_PreReadLessonsFromFile( void )
{
// Add custom actions to the map
CScriptedIconLesson::LessonActionMap.Insert( "custom action stub", LESSON_ACTION_MOD_CUSTOM_ACTION_STUB );
}


bool CScriptedIconLesson::Mod_ProcessElementAction( int iAction, bool bNot, const char *pchVarName, EHANDLE &hVar, const CGameInstructorSymbol *pchParamName, float fParam, C_BaseEntity *pParam, const char *pchParam, bool &bModHandled )
{
// Assume we're going to handle the action
bModHandled = true;

C_BaseEntity *pVar;
pVar = hVar.Get();

switch ( iAction )
{
case LESSON_ACTION_MOD_CUSTOM_ACTION_STUB:
{
float flStub = 0.0f; //pVar->GetStubValue();

if ( gameinstructor_verbose.GetInt() > 0 && ShouldShowSpew() )
{
ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, "\t[%s]->GetStubValue() ", pchVarName );
ConColorMsg( CBaseLesson::m_rgbaVerboseName, "%.1f ", flStub );
ConColorMsg( CBaseLesson::m_rgbaVerbosePlain, ( bNot ) ? ( ">= [%s] " ) : ( "< [%s] " ), pchParamName->String() );
ConColorMsg( CBaseLesson::m_rgbaVerboseName, "%.1f\n", fParam );
}

return ( flStub ) ? ( flStub >= fParam ) : ( flStub < fParam );
}

default:
// Didn't handle this action
bModHandled = false;
break;
}

return false;
}


bool C_GameInstructor::Mod_HiddenByOtherElements( void )
{
return false;
}


#ifdef MAPBASE
//
// This function allows you to add new lesson types beyond the default icon hints.
// Use this to integrate instructor lessons into another game-specific HUD element.
//
// Note that, due to some technical constraints, your custom type must still derive from CScriptedIconLesson.
//
bool C_GameInstructor::Mod_DefineLessonType( const char *pszLessonName, const char *pszLessonType )
{
return false;
}
#endif
7 changes: 4 additions & 3 deletions src/game/client/client_mapbase.vpc
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
// Project Script
//-----------------------------------------------------------------------------

$Include "$SRCDIR\game\client\client_mapbase_hl2.vpc" [$HL2||$EPISODIC||$HL2MP]
$Include "$SRCDIR\game\client\client_mapbase_tf.vpc" [$TF]

$Configuration
{
$Compiler
Expand All @@ -30,6 +27,7 @@ $Project
$File "c_baselesson.h"
$File "c_gameinstructor.cpp"
$File "c_gameinstructor.h"
$File "c_mod_lesson_stubs.cpp"
$File "hud_locator_target.cpp"
$File "hud_locator_target.h"
$File "c_postprocesscontroller.cpp"
Expand Down Expand Up @@ -81,3 +79,6 @@ $Project
$Lib "raytrace"
}
}

$Include "$SRCDIR\game\client\client_mapbase_hl2.vpc" [$HL2||$EPISODIC||$HL2MP]
$Include "$SRCDIR\game\client\client_mapbase_tf.vpc" [$TF]
Loading
Loading