Ticket #1958: UnitMotionTech.patch

File UnitMotionTech.patch, 2.2 KB (added by historic_bruno, 11 years ago)

wraitii's patch from http://www.wildfiregames.com/forum/index.php?showtopic=17209&st=60#entry269384

  • source/simulation2/components/CCmpUnitMotion.cpp

     
    2626#include "simulation2/components/ICmpPosition.h"
    2727#include "simulation2/components/ICmpPathfinder.h"
    2828#include "simulation2/components/ICmpRangeManager.h"
     29#include "simulation2/components/ICmpPlayerManager.h"
     30#include "simulation2/components/ICmpTechnologyManager.h"
    2931#include "simulation2/helpers/Geometry.h"
    3032#include "simulation2/helpers/Render.h"
    3133#include "simulation2/MessageTypes.h"
     
    109111        componentManager.SubscribeToMessageType(MT_Update_MotionUnit);
    110112        componentManager.SubscribeToMessageType(MT_RenderSubmit); // for debug overlays
    111113        componentManager.SubscribeToMessageType(MT_PathResult);
     114        componentManager.SubscribeGloballyToMessageType(MT_TechnologyModification);
    112115    }
    113116
    114117    DEFAULT_COMPONENT_ALLOCATOR(UnitMotion)
     
    395398            PathResult(msgData.ticket, msgData.path);
    396399            break;
    397400        }
     401        case MT_TechnologyModification:
     402        {
     403            const CMessageTechnologyModification& msgData = static_cast<const CMessageTechnologyModification&> (msg);
     404            if (msgData.component == L"UnitMotion")
     405            {
     406                CmpPtr<ICmpOwnership> cmpOwnership(GetSimContext(), GetEntityId());
     407                if (cmpOwnership)
     408                {
     409                    player_id_t owner = cmpOwnership->GetOwner();
     410                    if (owner != INVALID_PLAYER && owner == msgData.player)
     411                    {
     412                        CmpPtr<ICmpPlayerManager> cmpPlayerManager(GetSimContext(), SYSTEM_ENTITY);
     413                        entity_id_t playerEnt = cmpPlayerManager->GetPlayerByID(owner);
     414                        CmpPtr<ICmpTechnologyManager> cmpTechnologyManager(GetSimContext(), playerEnt);
     415                        if (playerEnt != INVALID_ENTITY && cmpTechnologyManager)
     416                        {
     417                            m_WalkSpeed = cmpTechnologyManager->ApplyModifications(L"UnitMotion/Walk/Speed", m_WalkSpeed, GetEntityId());
     418                            m_Speed = m_WalkSpeed;
     419                            m_RunSpeed = cmpTechnologyManager->ApplyModifications(L"UnitMotion/Run/Speed", m_RunSpeed, GetEntityId());
     420                        }
     421                    }
     422                }
     423            }
     424            break;
    398425        }
     426
     427        }
    399428    }
    400429
    401430    virtual bool IsMoving()