Ticket #2048: auras_cpp.diff

File auras_cpp.diff, 8.2 KB (added by sanderd17, 11 years ago)
  • binaries/data/mods/public/simulation/components/interfaces/TechnologyManager.js

     
     1Engine.RegisterInterface("TechnologyManager");
  • source/simulation2/TypeList.h

     
    138138INTERFACE(SoundManager)
    139139COMPONENT(SoundManager)
    140140
    141 INTERFACE(TechnologyManager)
    142 COMPONENT(TechnologyManagerScripted)
    143 
    144141INTERFACE(TechnologyTemplateManager)
    145142COMPONENT(TechnologyTemplateManagerScripted)
    146143
  • source/simulation2/components/CCmpTerritoryInfluence.cpp

     
    2222
    2323#include "simulation2/components/ICmpOwnership.h"
    2424#include "simulation2/components/ICmpPlayerManager.h"
    25 #include "simulation2/components/ICmpTechnologyManager.h"
    2625
    2726class CCmpTerritoryInfluence : public ICmpTerritoryInfluence
    2827{
     
    101100
    102101    virtual u32 GetRadius()
    103102    {
    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();
    105107
    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)
    108111        {
    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;
    118113        }
    119 
    120         return newRadius;
     114        return m_Radius;
    121115    }
    122116};
    123117
  • source/simulation2/components/CCmpVision.cpp

     
    2121#include "ICmpVision.h"
    2222
    2323#include "simulation2/MessageTypes.h"
    24 #include "simulation2/components/ICmpOwnership.h"
    25 #include "simulation2/components/ICmpPlayerManager.h"
    26 #include "simulation2/components/ICmpTechnologyManager.h"
    2724
    2825class CCmpVision : public ICmpVision
    2926{
     
    8582            const CMessageTechnologyModification& msgData = static_cast<const CMessageTechnologyModification&> (msg);
    8683            if (msgData.component == L"Vision")
    8784            {
    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)
    9091                {
    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);
    11097                }
    11198            }
    11299            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 modify
    5  * it under the terms of the GNU General Public License as published by
    6  * the Free Software Foundation, either version 2 of the License, or
    7  * (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 of
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12  * GNU General Public License for more details.
    13  *
    14  * You should have received a copy of the GNU General Public License
    15  * 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 ICmpTechnologyManager
    29 {
    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 modify
    5  * it under the terms of the GNU General Public License as published by
    6  * the Free Software Foundation, either version 2 of the License, or
    7  * (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 of
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12  * GNU General Public License for more details.
    13  *
    14  * You should have received a copy of the GNU General Public License
    15  * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
    16  */
    17 
    18 #ifndef INCLUDED_ICMPTECHNOLOGYMANAGER
    19 #define INCLUDED_ICMPTECHNOLOGYMANAGER
    20 
    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 accessing
    28  *  technology modification data, the associated logic is handled in scripts)
    29  */
    30 class ICmpTechnologyManager : public IComponent
    31 {
    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