1 /* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
2 
3 
4 #include "System/EventClient.h"
5 #include "System/EventHandler.h"
6 
7 /******************************************************************************/
8 /******************************************************************************/
9 
CEventClient(const std::string & _name,int _order,bool _synced)10 CEventClient::CEventClient(const std::string& _name, int _order, bool _synced)
11 	: name(_name)
12 	, order(_order)
13 	, synced_(_synced)
14 	, autoLinkEvents(false)
15 {
16 	// Note: virtual functions aren't available in the ctor!
17 	//RegisterLinkedEvents(this);
18 }
19 
20 
~CEventClient()21 CEventClient::~CEventClient()
22 {
23 	// No, we can't autobind all clients in the ctor.
24 	// eventHandler.AddClient() calls CEventClient::WantsEvent() that is
25 	// virtual and so not available during the initialization.
26 	eventHandler.RemoveClient(this);
27 }
28 
29 
WantsEvent(const std::string & eventName)30 bool CEventClient::WantsEvent(const std::string& eventName)
31 {
32 	if (!autoLinkEvents)
33 		return false;
34 
35 	assert(!autoLinkedEvents.empty());
36 
37 	if (autoLinkedEvents[eventName]) {
38 		//LOG("\"%s\" autolinks \"%s\"", GetName().c_str(), eventName.c_str());
39 		return true;
40 	}
41 
42 	return false;
43 }
44 
45 
46 /******************************************************************************/
47 /******************************************************************************/
48 //
49 //  Synced
50 //
51 
CommandFallback(const CUnit * unit,const Command & cmd)52 bool CEventClient::CommandFallback(const CUnit* unit, const Command& cmd) { return false; }
AllowCommand(const CUnit * unit,const Command & cmd,bool fromSynced)53 bool CEventClient::AllowCommand(const CUnit* unit, const Command& cmd, bool fromSynced) { return true; }
54 
AllowUnitCreation(const UnitDef * unitDef,const CUnit * builder,const BuildInfo * buildInfo)55 bool CEventClient::AllowUnitCreation(const UnitDef* unitDef, const CUnit* builder, const BuildInfo* buildInfo) { return true; }
AllowUnitTransfer(const CUnit * unit,int newTeam,bool capture)56 bool CEventClient::AllowUnitTransfer(const CUnit* unit, int newTeam, bool capture) { return true; }
AllowUnitBuildStep(const CUnit * builder,const CUnit * unit,float part)57 bool CEventClient::AllowUnitBuildStep(const CUnit* builder, const CUnit* unit, float part) { return true; }
AllowFeatureCreation(const FeatureDef * featureDef,int allyTeamID,const float3 & pos)58 bool CEventClient::AllowFeatureCreation(const FeatureDef* featureDef, int allyTeamID, const float3& pos) { return true; }
AllowFeatureBuildStep(const CUnit * builder,const CFeature * feature,float part)59 bool CEventClient::AllowFeatureBuildStep(const CUnit* builder, const CFeature* feature, float part) { return true; }
AllowResourceLevel(int teamID,const string & type,float level)60 bool CEventClient::AllowResourceLevel(int teamID, const string& type, float level) { return true; }
AllowResourceTransfer(int oldTeam,int newTeam,const string & type,float amount)61 bool CEventClient::AllowResourceTransfer(int oldTeam, int newTeam, const string& type, float amount) { return true; }
AllowDirectUnitControl(int playerID,const CUnit * unit)62 bool CEventClient::AllowDirectUnitControl(int playerID, const CUnit* unit) { return true; }
AllowBuilderHoldFire(const CUnit * unit,int action)63 bool CEventClient::AllowBuilderHoldFire(const CUnit* unit, int action) { return true; }
AllowStartPosition(int playerID,unsigned char readyState,const float3 & clampedPos,const float3 & rawPickPos)64 bool CEventClient::AllowStartPosition(int playerID, unsigned char readyState, const float3& clampedPos, const float3& rawPickPos) { return true; }
65 
TerraformComplete(const CUnit * unit,const CUnit * build)66 bool CEventClient::TerraformComplete(const CUnit* unit, const CUnit* build) { return false; }
MoveCtrlNotify(const CUnit * unit,int data)67 bool CEventClient::MoveCtrlNotify(const CUnit* unit, int data) { return false; }
68 
AllowWeaponTargetCheck(unsigned int attackerID,unsigned int attackerWeaponNum,unsigned int attackerWeaponDefID)69 int CEventClient::AllowWeaponTargetCheck(unsigned int attackerID, unsigned int attackerWeaponNum, unsigned int attackerWeaponDefID) { return -1; }
AllowWeaponTarget(unsigned int attackerID,unsigned int targetID,unsigned int attackerWeaponNum,unsigned int attackerWeaponDefID,float * targetPriority)70 bool CEventClient::AllowWeaponTarget(
71 	unsigned int attackerID,
72 	unsigned int targetID,
73 	unsigned int attackerWeaponNum,
74 	unsigned int attackerWeaponDefID,
75 	float* targetPriority
76 ) { return true; }
AllowWeaponInterceptTarget(const CUnit * interceptorUnit,const CWeapon * interceptorWeapon,const CProjectile * interceptorTarget)77 bool CEventClient::AllowWeaponInterceptTarget(const CUnit* interceptorUnit, const CWeapon* interceptorWeapon, const CProjectile* interceptorTarget) { return true; }
UnitPreDamaged(const CUnit * unit,const CUnit * attacker,float damage,int weaponDefID,int projectileID,bool paralyzer,float * newDamage,float * impulseMult)78 bool CEventClient::UnitPreDamaged(
79 	const CUnit* unit,
80 	const CUnit* attacker,
81 	float damage,
82 	int weaponDefID,
83 	int projectileID,
84 	bool paralyzer,
85 	float* newDamage,
86 	float* impulseMult) { return false; }
FeaturePreDamaged(const CFeature * feature,const CUnit * attacker,float damage,int weaponDefID,int projectileID,float * newDamage,float * impulseMult)87 bool CEventClient::FeaturePreDamaged(
88 	const CFeature* feature,
89 	const CUnit* attacker,
90 	float damage,
91 	int weaponDefID,
92 	int projectileID,
93 	float* newDamage,
94 	float* impulseMult) { return false; }
ShieldPreDamaged(const CProjectile *,const CWeapon *,const CUnit *,bool)95 bool CEventClient::ShieldPreDamaged(const CProjectile*, const CWeapon*, const CUnit*, bool) { return false; }
SyncedActionFallback(const string & line,int playerID)96 bool CEventClient::SyncedActionFallback(const string& line, int playerID) { return false; }
97 
98 /******************************************************************************/
99 /******************************************************************************/
100 //
101 //  Unsynced
102 //
103 
Save(zipFile archive)104 void CEventClient::Save(zipFile archive) {}
105 
Update()106 void CEventClient::Update() {}
UnsyncedHeightMapUpdate(const SRectangle & rect)107 void CEventClient::UnsyncedHeightMapUpdate(const SRectangle& rect) {}
108 
SunChanged(const float3 & sunDir)109 void CEventClient::SunChanged(const float3& sunDir) {}
110 
ViewResize()111 void CEventClient::ViewResize() {}
112 
DefaultCommand(const CUnit * unit,const CFeature * feature,int & cmd)113 bool CEventClient::DefaultCommand(const CUnit* unit, const CFeature* feature, int& cmd) { return false; }
114 
DrawGenesis()115 void CEventClient::DrawGenesis() {}
DrawWorld()116 void CEventClient::DrawWorld() {}
DrawWorldPreUnit()117 void CEventClient::DrawWorldPreUnit() {}
DrawWorldShadow()118 void CEventClient::DrawWorldShadow() {}
DrawWorldReflection()119 void CEventClient::DrawWorldReflection() {}
DrawWorldRefraction()120 void CEventClient::DrawWorldRefraction() {}
DrawScreenEffects()121 void CEventClient::DrawScreenEffects() {}
DrawScreen()122 void CEventClient::DrawScreen() {}
DrawInMiniMap()123 void CEventClient::DrawInMiniMap() {}
DrawInMiniMapBackground()124 void CEventClient::DrawInMiniMapBackground() {}
125 
DrawUnit(const CUnit * unit)126 bool CEventClient::DrawUnit(const CUnit* unit) { return false; }
DrawFeature(const CFeature * feature)127 bool CEventClient::DrawFeature(const CFeature* feature) { return false; }
DrawShield(const CUnit * unit,const CWeapon * weapon)128 bool CEventClient::DrawShield(const CUnit* unit, const CWeapon* weapon) { return false; }
DrawProjectile(const CProjectile * projectile)129 bool CEventClient::DrawProjectile(const CProjectile* projectile) { return false; }
130 
GameProgress(int gameFrame)131 void CEventClient::GameProgress(int gameFrame) {}
132 
DrawLoadScreen()133 void CEventClient::DrawLoadScreen() {}
LoadProgress(const std::string & msg,const bool replace_lastline)134 void CEventClient::LoadProgress(const std::string& msg, const bool replace_lastline) {}
135 
CollectGarbage()136 void CEventClient::CollectGarbage() {}
DbgTimingInfo(DbgTimingInfoType type,const spring_time start,const spring_time end)137 void CEventClient::DbgTimingInfo(DbgTimingInfoType type, const spring_time start, const spring_time end) {}
138 
139 // from LuaUI
KeyPress(int key,bool isRepeat)140 bool CEventClient::KeyPress(int key, bool isRepeat) { return false; }
KeyRelease(int key)141 bool CEventClient::KeyRelease(int key) { return false; }
TextInput(const std::string & utf8)142 bool CEventClient::TextInput(const std::string& utf8) { return false; }
MouseMove(int x,int y,int dx,int dy,int button)143 bool CEventClient::MouseMove(int x, int y, int dx, int dy, int button) { return false; }
MousePress(int x,int y,int button)144 bool CEventClient::MousePress(int x, int y, int button) { return false; }
MouseRelease(int x,int y,int button)145 void CEventClient::MouseRelease(int x, int y, int button) { }
MouseWheel(bool up,float value)146 bool CEventClient::MouseWheel(bool up, float value) { return false; }
JoystickEvent(const std::string & event,int val1,int val2)147 bool CEventClient::JoystickEvent(const std::string& event, int val1, int val2) { return false; }
IsAbove(int x,int y)148 bool CEventClient::IsAbove(int x, int y) { return false; }
GetTooltip(int x,int y)149 std::string CEventClient::GetTooltip(int x, int y) { return ""; }
150 
CommandNotify(const Command & cmd)151 bool CEventClient::CommandNotify(const Command& cmd) { return false; }
152 
AddConsoleLine(const std::string & msg,const std::string & section,int level)153 bool CEventClient::AddConsoleLine(const std::string& msg, const std::string& section, int level) { return false; }
154 
LastMessagePosition(const float3 & pos)155 void CEventClient::LastMessagePosition(const float3& pos) {}
156 
GroupChanged(int groupID)157 bool CEventClient::GroupChanged(int groupID) { return false; }
158 
GameSetup(const std::string & state,bool & ready,const map<int,std::string> & playerStates)159 bool CEventClient::GameSetup(const std::string& state, bool& ready,
160                              const map<int, std::string>& playerStates) { return false; }
161 
WorldTooltip(const CUnit * unit,const CFeature * feature,const float3 * groundPos)162 std::string CEventClient::WorldTooltip(const CUnit* unit,
163                                  const CFeature* feature,
164                                  const float3* groundPos) { return ""; }
165 
MapDrawCmd(int playerID,int type,const float3 * pos0,const float3 * pos1,const std::string * label)166 bool CEventClient::MapDrawCmd(int playerID, int type,
167                         const float3* pos0,
168                         const float3* pos1,
169                         const std::string* label) { return false; }
170 
171 /******************************************************************************/
172 /******************************************************************************/
173