forked from borzh/botrix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod.cpp
119 lines (98 loc) · 3.34 KB
/
mod.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include "mods/css/event_css.h"
#include "mods/borzh/mod_borzh.h"
#include "mod.h"
#include "server_plugin.h"
#include "type2string.h"
#include "waypoint.h"
//----------------------------------------------------------------------------------------------------------------
TModId CMod::m_iModId;
good::string CMod::sModName;
IMod* CMod::pCurrentMod = NULL;
StringVector CMod::m_aBotNames;
good::vector<StringVector> CMod::m_aModels;
good::vector< good::auto_ptr<CEvent> > CMod::m_aEvents;
bool CMod::m_bMapHas[EEntityTypeTotal-1]; // Health, armor, weapon, ammo.
StringVector CMod::aTeamsNames;
int CMod::iUnassignedTeam = 0;
int CMod::iSpectatorTeam = 1;
bool CMod::bIntelligenceInBotName = true;
//----------------------------------------------------------------------------------------------------------------
void CMod::Load( TModId iModId )
{
m_iModId = iModId;
m_aEvents.clear();
switch ( iModId )
{
case EModId_Borzh:
pCurrentMod = new CModBorzh();
break;
case EModId_HL2DM:
// TODO: move to hl2dm mod.
AddEvent(new CPlayerActivateEvent());
AddEvent(new CPlayerTeamEvent());
AddEvent(new CPlayerSpawnEvent());
AddEvent(new CPlayerHurtEvent());
AddEvent(new CPlayerDeathEvent());
AddEvent(new CPlayerChatEvent());
break;
case EModId_CSS:
AddEvent(new CRoundStartEvent());
AddEvent(new CWeaponFireEvent());
AddEvent(new CBulletImpactEvent());
AddEvent(new CPlayerFootstepEvent());
AddEvent(new CBombDroppedEvent());
AddEvent(new CBombPickupEvent());
break;
}
}
//----------------------------------------------------------------------------------------------------------------
void CMod::AddEvent( CEvent* pEvent )
{
if (CBotrixPlugin::pGameEventManager)
CBotrixPlugin::pGameEventManager->AddListener( CBotrixPlugin::instance, pEvent->GetName().c_str(), true );
if (CBotrixPlugin::pGameEventManager2)
CBotrixPlugin::pGameEventManager2->AddListener( CBotrixPlugin::instance, pEvent->GetName().c_str(), true );
m_aEvents.push_back(pEvent);
}
//----------------------------------------------------------------------------------------------------------------
void CMod::MapLoaded()
{
// TODO: move this to items.
for ( TEntityType iType=0; iType < EEntityTypeTotal-1; ++iType )
{
m_bMapHas[iType] = false;
if ( CItems::GetItems(iType).size() > 0 ) // Has items.
m_bMapHas[iType] = true;
else
{
TWaypointFlags iFlags = CWaypoint::GetFlagsFor(iType);
// Check if map has waypoints of given type.
for ( TWaypointId id=0; id < CWaypoints::Size(); ++id )
if ( FLAG_SOME_SET(CWaypoints::Get(id).iFlags, iFlags) )
{
m_bMapHas[iType] = true;
break;
}
}
}
//DebugAssert(pCurrentMod);
if ( pCurrentMod )
pCurrentMod->MapLoaded();
}
//----------------------------------------------------------------------------------------------------------------
void CMod::ExecuteEvent( void* pEvent, TEventType iType )
{
IEventInterface *pInterface = CEvent::GetEventInterface(pEvent, iType);
if ( pInterface == NULL )
return;
const char* szEventName = pInterface->GetName();
for (good::vector< good::auto_ptr<CEvent> >::iterator it = m_aEvents.begin(); it != m_aEvents.end(); ++it)
{
if ( (*it)->GetName() == szEventName )
{
(*it)->Execute(pInterface);
break;
}
}
delete pInterface;
}