Ticket #3952: simulationVariations.diff

File simulationVariations.diff, 6.3 KB (added by sanderd17, 8 years ago)
  • binaries/data/mods/public/art/actors/structures/hellenes/siege_tower.xml

     
    1717    </variant>
    1818  </group>
    1919  <group>
    20     <variant frequency="100" name="Idle"/>
     20    <variant frequency="1" name="ungarrisoned"/>
    2121    <variant name="garrisoned">
    2222      <props>
    2323        <prop actor="props/special/common/waypoint_flag_0ad.xml" attachpoint="garrisoned"/>
    2424      </props>
    2525    </variant>
     26  </group>
     27  <group>
     28    <variant frequency="1" name="alive"/>
    2629    <variant name="death">
    2730      <props>
    2831        <prop attachpoint="garrisoned"/>
  • binaries/data/mods/public/simulation/components/GarrisonHolder.js

     
    566566
    567567GarrisonHolder.prototype.UpdateGarrisonFlag = function()
    568568{
    569     var cmpVisual = Engine.QueryInterface(this.entity, IID_Visual);
     569    let cmpVisual = Engine.QueryInterface(this.entity, IID_Visual);
    570570    if (!cmpVisual)
    571571        return;
    572     cmpVisual.SelectAnimation("garrisoned", true, 0, "");
    573     // TODO: ought to extend ICmpVisual to let us just select variant
    574     // keywords without changing the animation too
     572    let oldVariant = "garrisoned";
     573    let newVariant = "garrisoned";
    575574    if (this.entities.length)
    576         cmpVisual.SelectAnimation("garrisoned", false, 1.0, "");
     575        oldVariant = "ungarrisoned";
    577576    else
    578         cmpVisual.SelectAnimation("idle", false, 1.0, "");
     577        newVariant = "ungarrisoned";
     578
     579    let selections = cmpVisual.GetVariantSelections();
     580    cmpVisual.SetVariantSelections(selections.map(s => s == oldVariant ? newVariant : s))
    579581};
    580582
    581583/**
  • source/simulation2/components/CCmpVisualActor.cpp

     
    1 /* Copyright (C) 2014 Wildfire Games.
     1/* Copyright (C) 2016 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    3232#include "ICmpValueModificationManager.h"
    3333#include "ICmpVisibility.h"
    3434
     35#include "simulation2/serialization/SerializeTemplates.h"
     36
    3537#include "graphics/Decal.h"
    3638#include "graphics/Frustum.h"
    3739#include "graphics/Model.h"
     
    230232        serialize.NumberFixed_Unbounded("anim sync repeat time", m_AnimSyncRepeatTime);
    231233
    232234        serialize.NumberU32_Unbounded("seed", m_Seed);
    233         // TODO: variation/selection strings
    234235        serialize.String("actor", m_ActorName, 0, 256);
    235236
    236237        // TODO: store actor variables?
     
    246247        }
    247248
    248249        SerializeCommon(serialize);
     250
     251        std::vector<std::string> variantSelections = GetVariantSelections();
     252        SerializeVector<SerializeString>()(serialize, "variantSeletions", variantSelections);
    249253    }
    250254
    251255    virtual void Deserialize(const CParamNode& paramNode, IDeserializer& deserialize)
     
    269273
    270274        SetAnimationSyncRepeat(repeattime);
    271275
     276        std::vector<std::string> variantSelections;
     277        SerializeVector<SerializeString>()(deserialize, "variantSeletions", variantSelections);
     278        SetVariantSelections(variantSelections);
     279
    272280        if (m_Unit)
    273281        {
    274282            CmpPtr<ICmpOwnership> cmpOwnership(GetEntityHandle());
     
    410418        return CVector3D();
    411419    }
    412420
     421    virtual std::vector<std::string> GetVariantSelections()
     422    {
     423        std::vector<std::string> result;
     424        if (!m_Unit)
     425            return result;
     426        std::set<CStr> selections = m_Unit->GetActorSelections();
     427        std::copy(selections.begin(), selections.end(), std::back_inserter(result));
     428        return result;
     429    }
     430
     431    virtual void SetVariantSelections(const std::vector<std::string>& selections)
     432    {
     433        if (!m_Unit)
     434            return;
     435        std::set<CStr> result(selections.begin(), selections.end());
     436        m_Unit->SetActorSelections(result);
     437    }
     438
    413439    virtual void SelectAnimation(const std::string& name, bool once, fixed speed, const std::wstring& soundgroup)
    414440    {
    415441        m_AnimRunThreshold = fixed::Zero();
  • source/simulation2/components/ICmpVisual.cpp

     
    1 /* Copyright (C) 2013 Wildfire Games.
     1/* Copyright (C) 2016 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    2222#include "simulation2/system/InterfaceScripted.h"
    2323
    2424BEGIN_INTERFACE_WRAPPER(Visual)
     25DEFINE_INTERFACE_METHOD_0("GetVariantSelections", std::vector<std::string>, ICmpVisual, GetVariantSelections)
     26DEFINE_INTERFACE_METHOD_1("SetVariantSelections", void, ICmpVisual, SetVariantSelections, std::vector<std::string>)
    2527DEFINE_INTERFACE_METHOD_4("SelectAnimation", void, ICmpVisual, SelectAnimation, std::string, bool, fixed, std::wstring)
    2628DEFINE_INTERFACE_METHOD_1("SelectMovementAnimation", void, ICmpVisual, SelectMovementAnimation, fixed)
    2729DEFINE_INTERFACE_METHOD_1("ResetMoveAnimation", void, ICmpVisual, ResetMoveAnimation, std::string)
  • source/simulation2/components/ICmpVisual.h

     
    1 /* Copyright (C) 2013 Wildfire Games.
     1/* Copyright (C) 2016 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    8080    virtual CUnit* GetUnit() = 0;
    8181
    8282    /**
     83     * Get the variant selections of the actor
     84     */
     85    virtual std::vector<std::string> GetVariantSelections() = 0;
     86
     87    /**
     88     * Set the variant selections of the actor
     89     */
     90    virtual void SetVariantSelections(const std::vector<std::string>& selections) = 0;
     91
     92    /**
    8393     * Start playing the given animation. If there are multiple possible animations then it will
    8494     * pick one at random (not network-synchronised).
    8595     * If @p soundgroup is specified, then the sound will be played at each 'event' point in the