Ticket #2243: actorTech.4.diff

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

     
    373373        this.modificationCache[valueName][ent] = {"origValue": curValue};
    374374        var cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager);
    375375        var templateName = cmpTemplateManager.GetCurrentTemplateName(ent);
    376         // Ensure that preview entites have the same properties as the final building
    377         if (templateName.indexOf("preview|") != -1)
    378             templateName = templateName.slice(8);
     376        // Ensure that preview or construction entites have the same properties as the final building
     377        if (templateName.indexOf("preview|") > -1 || templateName.indexOf("construction|") > -1 )
     378            templateName = templateName.slice(templateName.indexOf("|") + 1);
    379379        this.modificationCache[valueName][ent].newValue = GetTechModifiedProperty(this.modifications, cmpTemplateManager.GetTemplate(templateName), valueName, curValue);
    380380    }
    381381   
  • 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"
     
    5758        componentManager.SubscribeToMessageType(MT_Interpolate);
    5859        componentManager.SubscribeToMessageType(MT_RenderSubmit);
    5960        componentManager.SubscribeToMessageType(MT_OwnershipChanged);
     61        componentManager.SubscribeToMessageType(MT_ValueModification);
    6062        componentManager.SubscribeGloballyToMessageType(MT_TerrainChanged);
    6163    }
    6264
     
    6365    DEFAULT_COMPONENT_ALLOCATOR(VisualActor)
    6466
    6567private:
    66     std::wstring m_ActorName;
     68    std::wstring m_BaseActorName, m_ActorName;
     69    bool m_IsFoundationActor;
    6770    CUnit* m_Unit;
    6871
    6972    fixed m_R, m_G, m_B; // shading colour
     
    188191
    189192        m_Seed = GetEntityId();
    190193
    191         if (paramNode.GetChild("Foundation").IsOk() && paramNode.GetChild("FoundationActor").IsOk())
    192             m_ActorName = paramNode.GetChild("FoundationActor").ToString();
     194        m_IsFoundationActor = paramNode.GetChild("Foundation").IsOk() && paramNode.GetChild("FoundationActor").IsOk();
     195        if (m_IsFoundationActor)
     196            m_BaseActorName = m_ActorName = paramNode.GetChild("FoundationActor").ToString();
    193197        else
    194             m_ActorName = paramNode.GetChild("Actor").ToString();
     198            m_BaseActorName = m_ActorName = paramNode.GetChild("Actor").ToString();
    195199
    196200        m_VisibleInAtlasOnly = paramNode.GetChild("VisibleInAtlasOnly").ToBool();
    197201        m_IsActorOnly = paramNode.GetChild("ActorOnly").IsOk();
     
    228232
    229233        serialize.NumberU32_Unbounded("seed", m_Seed);
    230234        // TODO: variation/selection strings
     235        serialize.String("actor", m_ActorName, 0, 256);
    231236
    232237        serialize.NumberFixed_Unbounded("constructionprogress", m_ConstructionProgress);
    233238
     
    240245
    241246        if (serialize.IsDebug())
    242247        {
    243             serialize.String("actor", m_ActorName, 0, 256);
     248            serialize.String("base actor", m_BaseActorName, 0, 256);
    244249        }
    245250
    246251        SerializeCommon(serialize);
     
    254259
    255260        SerializeCommon(deserialize);
    256261
    257         // If we serialized a different seed, reload actor
    258         if (oldSeed != GetActorSeed())
     262        // If we serialized a different seed or different actor, reload actor
     263        if (oldSeed != GetActorSeed() || m_BaseActorName != m_ActorName)
    259264            ReloadActor();
    260265
    261266        fixed repeattime = m_AnimSyncRepeatTime; // save because SelectAnimation overwrites it
     
    313318            m_Unit->GetModel().SetTerrainDirty(msgData.i0, msgData.j0, msgData.i1, msgData.j1);
    314319            break;
    315320        }
     321        case MT_ValueModification:
     322        {
     323            const CMessageValueModification& msgData = static_cast<const CMessageValueModification&> (msg);
     324            if (msgData.component != L"VisualActor")
     325                break;
     326            CmpPtr<ICmpValueModificationManager> cmpValueModificationManager(GetSystemEntity());
     327            std::wstring newActorName;
     328            if (m_IsFoundationActor)
     329                newActorName = cmpValueModificationManager->ApplyModifications(L"VisualActor/FoundationActor", m_BaseActorName, GetEntityId());
     330            else
     331                newActorName = cmpValueModificationManager->ApplyModifications(L"VisualActor/Actor", m_BaseActorName, GetEntityId());
     332            if (newActorName != m_ActorName)
     333            {
     334                m_ActorName = newActorName;
     335                ReloadActor();
     336            }
     337            break;
    316338        }
     339        }
    317340    }
    318341
    319342    virtual CBoundingBoxAligned GetBounds()
     
    519542    if (GetSimContext().HasUnitManager())
    520543    {
    521544        std::set<CStr> selections;
    522         m_Unit = GetSimContext().GetUnitManager().CreateUnit(m_ActorName, GetActorSeed(), selections);
     545        std::wstring actorName = m_ActorName;
     546        if (actorName.find(L".xml") == std::wstring::npos)
     547            actorName += L".xml";
     548        m_Unit = GetSimContext().GetUnitManager().CreateUnit(actorName, GetActorSeed(), selections);
    523549        if (m_Unit)
    524550        {
    525551            CModelAbstract& model = m_Unit->GetModel();
     
    637663        return;
    638664
    639665    std::set<CStr> selections;
    640     CUnit* newUnit = GetSimContext().GetUnitManager().CreateUnit(m_ActorName, GetActorSeed(), selections);
     666    std::wstring actorName = m_ActorName;
     667    if (actorName.find(L".xml") == std::wstring::npos)
     668        actorName += L".xml";
     669    CUnit* newUnit = GetSimContext().GetUnitManager().CreateUnit(actorName, GetActorSeed(), selections);
    641670
    642671    if (!newUnit)
    643672        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};