Ticket #2048: auras_cpp.diff
File auras_cpp.diff, 8.2 KB (added by , 11 years ago) |
---|
-
binaries/data/mods/public/simulation/components/interfaces/TechnologyManager.js
1 Engine.RegisterInterface("TechnologyManager"); -
source/simulation2/TypeList.h
138 138 INTERFACE(SoundManager) 139 139 COMPONENT(SoundManager) 140 140 141 INTERFACE(TechnologyManager)142 COMPONENT(TechnologyManagerScripted)143 144 141 INTERFACE(TechnologyTemplateManager) 145 142 COMPONENT(TechnologyTemplateManagerScripted) 146 143 -
source/simulation2/components/CCmpTerritoryInfluence.cpp
22 22 23 23 #include "simulation2/components/ICmpOwnership.h" 24 24 #include "simulation2/components/ICmpPlayerManager.h" 25 #include "simulation2/components/ICmpTechnologyManager.h"26 25 27 26 class CCmpTerritoryInfluence : public ICmpTerritoryInfluence 28 27 { … … 101 100 102 101 virtual u32 GetRadius() 103 102 { 104 u32 newRadius = m_Radius; 103 u32 newRadius; 104 entity_id_t ent = GetEntityId(); 105 const char* valueName = "TerritoryInfluence/Radius"; 106 ScriptInterface& scriptInterface = GetSimContext().GetScriptInterface(); 105 107 106 CmpPtr<ICmpOwnership> cmpOwnership(GetSimContext(), GetEntityId()); 107 if (cmpOwnership && cmpOwnership->GetOwner() != INVALID_PLAYER) 108 bool ok = scriptInterface.CallFunction(scriptInterface.GetGlobalObject(), "ApplyTechModificationsToEntity", valueName, m_Radius, ent, newRadius); 109 110 if (ok) 108 111 { 109 CmpPtr<ICmpPlayerManager> cmpPlayerManager(GetSimContext(), SYSTEM_ENTITY); 110 entity_id_t playerEnt = cmpPlayerManager->GetPlayerByID(cmpOwnership->GetOwner()); 111 112 if (playerEnt != INVALID_ENTITY) 113 { 114 CmpPtr<ICmpTechnologyManager> cmpTechnologyManager(GetSimContext(), playerEnt); 115 if (cmpTechnologyManager) 116 newRadius = cmpTechnologyManager->ApplyModifications(L"TerritoryInfluence/Radius", m_Radius, GetEntityId()); 117 } 112 return newRadius; 118 113 } 119 120 return newRadius; 114 return m_Radius; 121 115 } 122 116 }; 123 117 -
source/simulation2/components/CCmpVision.cpp
21 21 #include "ICmpVision.h" 22 22 23 23 #include "simulation2/MessageTypes.h" 24 #include "simulation2/components/ICmpOwnership.h"25 #include "simulation2/components/ICmpPlayerManager.h"26 #include "simulation2/components/ICmpTechnologyManager.h"27 24 28 25 class CCmpVision : public ICmpVision 29 26 { … … 85 82 const CMessageTechnologyModification& msgData = static_cast<const CMessageTechnologyModification&> (msg); 86 83 if (msgData.component == L"Vision") 87 84 { 88 CmpPtr<ICmpOwnership> cmpOwnership(GetSimContext(), GetEntityId()); 89 if (cmpOwnership) 85 ScriptInterface& scriptInterface = GetSimContext().GetScriptInterface(); 86 entity_pos_t newRange; 87 const char* valueName = "Vision/Range"; 88 bool ok = scriptInterface.CallFunction(scriptInterface.GetGlobalObject(), "ApplyTechModificationsToEntity", valueName, m_BaseRange, GetEntityId(), newRange); 89 90 if (ok && newRange != m_Range) 90 91 { 91 player_id_t owner = cmpOwnership->GetOwner(); 92 if (owner != INVALID_PLAYER && owner == msgData.player) 93 { 94 CmpPtr<ICmpPlayerManager> cmpPlayerManager(GetSimContext(), SYSTEM_ENTITY); 95 entity_id_t playerEnt = cmpPlayerManager->GetPlayerByID(owner); 96 CmpPtr<ICmpTechnologyManager> cmpTechnologyManager(GetSimContext(), playerEnt); 97 if (playerEnt != INVALID_ENTITY && cmpTechnologyManager) 98 { 99 entity_pos_t newRange = cmpTechnologyManager->ApplyModifications(L"Vision/Range", m_BaseRange, GetEntityId()); 100 if (newRange != m_Range) 101 { 102 // Update our vision range and broadcast message 103 entity_pos_t oldRange = m_Range; 104 m_Range = newRange; 105 CMessageVisionRangeChanged msg(GetEntityId(), oldRange, newRange); 106 GetSimContext().GetComponentManager().BroadcastMessage(msg); 107 } 108 } 109 } 92 // Update our vision range and broadcast message 93 entity_pos_t oldRange = m_Range; 94 m_Range = newRange; 95 CMessageVisionRangeChanged msg(GetEntityId(), oldRange, newRange); 96 GetSimContext().GetComponentManager().BroadcastMessage(msg); 110 97 } 111 98 } 112 99 break; -
source/simulation2/components/ICmpTechnologyManager.cpp
1 /* Copyright (C) 2012 Wildfire Games.2 * This file is part of 0 A.D.3 *4 * 0 A.D. is free software: you can redistribute it and/or modify5 * it under the terms of the GNU General Public License as published by6 * the Free Software Foundation, either version 2 of the License, or7 * (at your option) any later version.8 *9 * 0 A.D. is distributed in the hope that it will be useful,10 * but WITHOUT ANY WARRANTY; without even the implied warranty of11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12 * GNU General Public License for more details.13 *14 * You should have received a copy of the GNU General Public License15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.16 */17 18 #include "precompiled.h"19 20 #include "ICmpTechnologyManager.h"21 22 #include "simulation2/system/InterfaceScripted.h"23 #include "simulation2/scripting/ScriptComponent.h"24 25 BEGIN_INTERFACE_WRAPPER(TechnologyManager)26 END_INTERFACE_WRAPPER(TechnologyManager)27 28 class CCmpTechnologyManagerScripted : public ICmpTechnologyManager29 {30 public:31 DEFAULT_SCRIPT_WRAPPER(TechnologyManagerScripted)32 33 virtual fixed ApplyModifications(std::wstring valueName, fixed currentValue, entity_id_t entity)34 {35 return m_Script.Call<fixed>("ApplyModifications", valueName, currentValue, entity);36 }37 38 virtual u32 ApplyModifications(std::wstring valueName, u32 currentValue, entity_id_t entity)39 {40 return m_Script.Call<u32>("ApplyModifications", valueName, currentValue, entity);41 }42 };43 44 REGISTER_COMPONENT_SCRIPT_WRAPPER(TechnologyManagerScripted) -
source/simulation2/components/ICmpTechnologyManager.h
1 /* Copyright (C) 2012 Wildfire Games.2 * This file is part of 0 A.D.3 *4 * 0 A.D. is free software: you can redistribute it and/or modify5 * it under the terms of the GNU General Public License as published by6 * the Free Software Foundation, either version 2 of the License, or7 * (at your option) any later version.8 *9 * 0 A.D. is distributed in the hope that it will be useful,10 * but WITHOUT ANY WARRANTY; without even the implied warranty of11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12 * GNU General Public License for more details.13 *14 * You should have received a copy of the GNU General Public License15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.16 */17 18 #ifndef INCLUDED_ICMPTECHNOLOGYMANAGER19 #define INCLUDED_ICMPTECHNOLOGYMANAGER20 21 #include "simulation2/system/Interface.h"22 23 #include "maths/Fixed.h"24 25 /**26 * Technology manager interface.27 * (This interface only includes the functions needed by native code for accessing28 * technology modification data, the associated logic is handled in scripts)29 */30 class ICmpTechnologyManager : public IComponent31 {32 public:33 virtual fixed ApplyModifications(std::wstring valueName, fixed currentValue, entity_id_t entity) = 0;34 virtual u32 ApplyModifications(std::wstring valueName, u32 currentValue, entity_id_t entity) = 0;35 36 DECLARE_INTERFACE_TYPE(TechnologyManager)37 };38 39 #endif // INCLUDED_ICMPTECHNOLOGYMANAGER