Ticket #2243: actorTech.3.diff

File actorTech.3.diff, 9.1 KB (added by sanderd17, 10 years ago)
  • binaries/data/mods/public/simulation/components/TechnologyManager.js

     
    1818    return ret;
    1919};
    2020
     21
     22TechnologyManager.prototype.Deserialize = function(msg)
     23{
     24    for (var i in msg)
     25    {
     26        if (msg.hasOwnProperty(i))
     27            this[i] = msg[i];
     28    }
     29    this.modificationCache = {};
     30    // warn components that were initialized before the technologymanager was initialized
     31    var notifiedComponents = [];
     32    for (var name in this.modifications)
     33    {
     34        // We only need to find one one tech per component for a match
     35        var component = name.split("/")[0];
     36        if (notifiedComponents.indexOf(component) == -1)
     37        {
     38            notifiedComponents.push(component);
     39            this.componentsToNotifyOnUpdate.push(component);
     40        }
     41    }
     42};
     43
    2144TechnologyManager.prototype.Init = function ()
    2245{
    2346    var cmpTechTempMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_TechnologyTemplateManager);
     
    2548    this.researchedTechs = {}; // technologies which have been researched
    2649    this.researchQueued = {};  // technologies which are queued for research
    2750    this.researchStarted = {}; // technologies which are being researched currently (non-queued)
     51    this.componentsToNotifyOnUpdate = [];
    2852   
    2953    // This stores the modifications to unit stats from researched technologies
    3054    // Example data: {"ResourceGatherer/Rates/food.grain": [
     
    5680TechnologyManager.prototype.OnUpdate = function ()
    5781{
    5882    this.UpdateAutoResearch();
     83
     84    for each (var component in this.componentsToNotifyOnUpdate)
     85        Engine.BroadcastMessage(MT_ValueModification, { "component": component });
     86    this.componentsToNotifyOnUpdate = [];
    5987}
    6088
    6189
     
    356384        this.modificationCache[valueName][ent] = {"origValue": curValue};
    357385        var cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager);
    358386        var templateName = cmpTemplateManager.GetCurrentTemplateName(ent);
    359         // Ensure that preview entites have the same properties as the final building
    360         if (templateName.indexOf("preview|") != -1)
    361             templateName = templateName.slice(8);
     387        // Ensure that preview or construction entites have the same properties as the final building
     388        if (templateName.indexOf("preview|") > -1 || templateName.indexOf("construction|") > -1 )
     389            templateName = templateName.slice(templateName.indexOf("|") + 1);
    362390        this.modificationCache[valueName][ent].newValue = GetTechModifiedProperty(this.modifications, cmpTemplateManager.GetTemplate(templateName), valueName, curValue);
    363391    }
    364    
    365392    return this.modificationCache[valueName][ent].newValue;
    366393};
    367394
  • binaries/data/mods/public/simulation/data/technologies/phase_town.json

     
    22    "genericName": "Town Phase",
    33    "requirements": { "any": [{"tech":"phase_town_generic"}, {"tech":"phase_town_athen"}]},
    44    "autoResearch": true,
    5     "modifications": [{"value": "TerritoryInfluence/Radius", "multiply": 1.30}],
     5    "modifications": [{"value": "TerritoryInfluence/Radius", "multiply": 1.30},{"value": "VisualActor/Actor", "replace":"structures/athenians/gymnasion.xml"}],
    66    "affects": ["CivCentre"],
    77    "soundComplete": "interface/alarm/alarm_phase.xml"
    88}
  • source/simulation2/components/CCmpVisualActor.cpp

     
    3030#include "ICmpTemplateManager.h"
    3131#include "ICmpTerrain.h"
    3232#include "ICmpUnitMotion.h"
     33#include "ICmpValueModificationManager.h"
    3334#include "ICmpVision.h"
    3435
    3536#include "graphics/Decal.h"
     
    5657        componentManager.SubscribeToMessageType(MT_Interpolate);
    5758        componentManager.SubscribeToMessageType(MT_RenderSubmit);
    5859        componentManager.SubscribeToMessageType(MT_OwnershipChanged);
     60        componentManager.SubscribeToMessageType(MT_ValueModification);
    5961        componentManager.SubscribeGloballyToMessageType(MT_TerrainChanged);
    6062    }
    6163
     
    6264    DEFAULT_COMPONENT_ALLOCATOR(VisualActor)
    6365
    6466private:
    65     std::wstring m_ActorName;
     67    std::wstring m_OriginalActorName, m_ActorName;
     68    bool m_IsFoundationActor;
    6669    CUnit* m_Unit;
    6770
    6871    fixed m_R, m_G, m_B; // shading colour
     
    181184
    182185        m_Seed = GetEntityId();
    183186
    184         if (paramNode.GetChild("Foundation").IsOk() && paramNode.GetChild("FoundationActor").IsOk())
    185             m_ActorName = paramNode.GetChild("FoundationActor").ToString();
     187        m_IsFoundationActor = paramNode.GetChild("Foundation").IsOk() && paramNode.GetChild("FoundationActor").IsOk();
     188        if (m_IsFoundationActor)
     189            m_OriginalActorName = m_ActorName = paramNode.GetChild("FoundationActor").ToString();
    186190        else
    187             m_ActorName = paramNode.GetChild("Actor").ToString();
     191            m_OriginalActorName = m_ActorName = paramNode.GetChild("Actor").ToString();
    188192
    189193        m_VisibleInAtlasOnly = paramNode.GetChild("VisibleInAtlasOnly").ToBool();
    190194
     
    297301        {
    298302            const CMessageOwnershipChanged& msgData = static_cast<const CMessageOwnershipChanged&> (msg);
    299303            m_Unit->GetModel().SetPlayerID(msgData.to);
     304
     305            // also update the actor for local entities
     306            CmpPtr<ICmpValueModificationManager> cmpValueModificationManager(GetSystemEntity());
     307            std::wstring newActorName;
     308            if (m_IsFoundationActor)
     309                newActorName = cmpValueModificationManager->ApplyModifications(L"VisualActor/FoundationActor", m_OriginalActorName, GetEntityId());
     310            else
     311                newActorName = cmpValueModificationManager->ApplyModifications(L"VisualActor/Actor", m_OriginalActorName, GetEntityId());
     312            if (newActorName != m_ActorName)
     313            {
     314                m_ActorName = newActorName;
     315                ReloadActor();
     316            }
    300317            break;
    301318        }
    302319        case MT_TerrainChanged:
     
    305322            m_Unit->GetModel().SetTerrainDirty(msgData.i0, msgData.j0, msgData.i1, msgData.j1);
    306323            break;
    307324        }
     325        case MT_ValueModification:
     326        {
     327            const CMessageValueModification& msgData = static_cast<const CMessageValueModification&> (msg);
     328            if (msgData.component != L"VisualActor")
     329                break;
     330            CmpPtr<ICmpValueModificationManager> cmpValueModificationManager(GetSystemEntity());
     331            std::wstring newActorName;
     332            if (m_IsFoundationActor)
     333                newActorName = cmpValueModificationManager->ApplyModifications(L"VisualActor/FoundationActor", m_OriginalActorName, GetEntityId());
     334            else
     335                newActorName = cmpValueModificationManager->ApplyModifications(L"VisualActor/Actor", m_OriginalActorName, GetEntityId());
     336            if (newActorName != m_ActorName)
     337            {
     338                m_ActorName = newActorName;
     339                ReloadActor();
     340            }
     341            break;
    308342        }
     343        }
    309344    }
    310345
    311346    virtual CBoundingBoxAligned GetBounds()
     
    511546    if (GetSimContext().HasUnitManager())
    512547    {
    513548        std::set<CStr> selections;
    514         m_Unit = GetSimContext().GetUnitManager().CreateUnit(m_ActorName, GetActorSeed(), selections);
     549        std::wstring actorName = m_ActorName;
     550        if (actorName.find(L".xml") == std::wstring::npos)
     551            actorName += L".xml";
     552        m_Unit = GetSimContext().GetUnitManager().CreateUnit(actorName, GetActorSeed(), selections);
    515553        if (m_Unit)
    516554        {
    517555            CModelAbstract& model = m_Unit->GetModel();
     
    629667        return;
    630668
    631669    std::set<CStr> selections;
    632     CUnit* newUnit = GetSimContext().GetUnitManager().CreateUnit(m_ActorName, GetActorSeed(), selections);
     670    std::wstring actorName = m_ActorName;
     671    if (actorName.find(L".xml") == std::wstring::npos)
     672        actorName += L".xml";
     673    CUnit* newUnit = GetSimContext().GetUnitManager().CreateUnit(actorName, GetActorSeed(), selections);
    633674
    634675    if (!newUnit)
    635676        return;
  • source/simulation2/components/ICmpValueModificationManager.cpp

     
    3939    {
    4040        return m_Script.Call<u32>("ApplyModifications", valueName, currentValue, entity);
    4141    }
     42
     43    virtual std::wstring ApplyModifications(std::wstring valueName, std::wstring currentValue, entity_id_t entity)
     44    {
     45        return m_Script.Call<std::wstring>("ApplyModifications", valueName, currentValue, entity);
     46    }
    4247};
    4348
    4449REGISTER_COMPONENT_SCRIPT_WRAPPER(ValueModificationManagerScripted)
  • source/simulation2/components/ICmpValueModificationManager.h

     
    3232public:
    3333    virtual fixed ApplyModifications(std::wstring valueName, fixed currentValue, entity_id_t entity) = 0;
    3434    virtual u32 ApplyModifications(std::wstring valueName, u32 currentValue, entity_id_t entity) = 0;
     35    virtual std::wstring ApplyModifications(std::wstring valueName, std::wstring currentValue, entity_id_t entity) = 0;
    3536
    3637    DECLARE_INTERFACE_TYPE(ValueModificationManager)
    3738};