diff --git a/binaries/data/mods/public/simulation/components/RallyPoint.js b/binaries/data/mods/public/simulation/components/RallyPoint.js index 40d45fddf8..6cead15ebd 100644 --- a/binaries/data/mods/public/simulation/components/RallyPoint.js +++ b/binaries/data/mods/public/simulation/components/RallyPoint.js @@ -19,6 +19,29 @@ RallyPoint.prototype.AddPosition = function(x, z) RallyPoint.prototype.GetPositions = function() { + // Update positions for moving target entities + // TODO: If we target an enemy unit we should update its position + // as long as it is outside of FoW and SoD. + for (var i = 0; i < this.pos.length; i++) + { + if (!this.data[i].target) + continue; + + // Get the actual position of the target entity + var cmpPosition = Engine.QueryInterface(this.data[i].target, IID_Position); + if (!cmpPosition) + continue; + + var targetPosition = cmpPosition.GetPosition2D(); + if (!targetPosition) + continue; + + this.pos[i] = {"x": targetPosition.x, "z": targetPosition.y}; + var cmpRallyPointRenderer = Engine.QueryInterface(this.entity, IID_RallyPointRenderer); + if (cmpRallyPointRenderer) + cmpRallyPointRenderer.UpdatePosition(i, targetPosition); + } + return this.pos; }; diff --git a/source/simulation2/components/CCmpRallyPointRenderer.cpp b/source/simulation2/components/CCmpRallyPointRenderer.cpp index e5bbf8d5bd..193d044df4 100644 --- a/source/simulation2/components/CCmpRallyPointRenderer.cpp +++ b/source/simulation2/components/CCmpRallyPointRenderer.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2012 Wildfire Games. +/* Copyright (C) 2014 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -277,6 +277,21 @@ public: } } + virtual void UpdatePosition(u32 rallyPointId, CFixedVector2D pos) + { + if (rallyPointId >= m_RallyPoints.size()) + return; + + m_RallyPoints[rallyPointId] = pos; + + UpdateMarkers(); + + // Compute a new path for the current, and if existing the next rally point + RecomputeRallyPointPath_wrapper(rallyPointId); + if (rallyPointId+1 < m_RallyPoints.size()) + RecomputeRallyPointPath_wrapper(rallyPointId+1); + } + virtual void SetDisplayed(bool displayed) { if (m_Displayed != displayed) @@ -285,7 +300,7 @@ public: // move the markers out of oblivion and back into the real world, or vice-versa UpdateMarkers(); - + // Check for changes to the SoD and update the overlay lines accordingly. We need to do this here because this method // only takes effect when the display flag is active; we need to pick up changes to the SoD that might have occurred // while this rally point was not being displayed. @@ -507,29 +522,27 @@ void CCmpRallyPointRenderer::UpdateMarkers() // set rally point flag selection based on player civilization CmpPtr cmpOwnership(GetEntityHandle()); - if (cmpOwnership) - { - player_id_t ownerId = cmpOwnership->GetOwner(); - if (ownerId != INVALID_PLAYER && (ownerId != previousOwner || m_LastMarkerCount < i)) - { - m_LastOwner = ownerId; - CmpPtr cmpPlayerManager(GetSystemEntity()); - // cmpPlayerManager should not be null as long as this method is called on-demand instead of at Init() time - // (we can't rely on component initialization order in Init()) - if (cmpPlayerManager) - { - CmpPtr cmpPlayer(GetSimContext(), cmpPlayerManager->GetPlayerByID(ownerId)); - if (cmpPlayer) - { - CmpPtr cmpVisualActor(GetSimContext(), m_MarkerEntityIds[i]); - if (cmpVisualActor) - { - cmpVisualActor->SetUnitEntitySelection(CStrW(cmpPlayer->GetCiv()).ToUTF8()); - } - } - } - } - } + if (!cmpOwnership) + continue; + + player_id_t ownerId = cmpOwnership->GetOwner(); + if (ownerId == INVALID_PLAYER || (ownerId == previousOwner && m_LastMarkerCount >= i)) + continue; + + m_LastOwner = ownerId; + CmpPtr cmpPlayerManager(GetSystemEntity()); + // cmpPlayerManager should not be null as long as this method is called on-demand instead of at Init() time + // (we can't rely on component initialization order in Init()) + if (!cmpPlayerManager) + continue; + + CmpPtr cmpPlayer(GetSimContext(), cmpPlayerManager->GetPlayerByID(ownerId)); + if (!cmpPlayer) + continue; + + CmpPtr cmpVisualActor(GetSimContext(), m_MarkerEntityIds[i]); + if (cmpVisualActor) + cmpVisualActor->SetUnitEntitySelection(CStrW(cmpPlayer->GetCiv()).ToUTF8()); } m_LastMarkerCount = m_RallyPoints.size() - 1; } @@ -1011,7 +1024,7 @@ void CCmpRallyPointRenderer::ReduceSegmentsByVisibility(std::vector& size_t baseNodeIdx = 0; size_t curNodeIdx = 1; - + float baseNodeY; entity_pos_t baseNodeX; entity_pos_t baseNodeZ; @@ -1167,10 +1180,9 @@ void CCmpRallyPointRenderer::MergeVisibilitySegments(std::deque