Fix units falling off the edge of the world.

I guess changes to the map loading sequence caused the TerrainChanged
message to be sent before the map was switched from square to circular
instead of after. The pathfinder didn't notice the switch, so it
continued treating the map as if it were square, allowing units to walk
into the permanent map-corner SOD and vanish, and allowing territories
to expand into the SOD.

Tell the pathfinder explicitly when the map shape changes, so it can
discard its cached data correctly.

This was SVN commit r15277.
This commit is contained in:
Ykkrosh
2014-06-03 22:35:40 +00:00
parent 0900005e5b
commit db39d742f0
6 changed files with 33 additions and 5 deletions
+14
View File
@@ -361,6 +361,20 @@ public:
int32_t i0, j0, i1, j1; // inclusive lower bound, exclusive upper bound, in tiles
};
/**
* Sent when ObstructionManager's view of the shape of the world has changed
* (changing the TILE_OUTOFBOUNDS tiles returned by Rasterise).
*/
class CMessageObstructionMapShapeChanged : public CMessage
{
public:
DEFAULT_MESSAGE_IMPL(ObstructionMapShapeChanged)
CMessageObstructionMapShapeChanged()
{
}
};
/**
* Sent when territory assignments have changed.
*/
+1
View File
@@ -49,6 +49,7 @@ MESSAGE(MotionChanged)
MESSAGE(RangeUpdate)
MESSAGE(TerrainChanged)
MESSAGE(WaterChanged)
MESSAGE(ObstructionMapShapeChanged)
MESSAGE(TerritoriesChanged)
MESSAGE(PathResult)
MESSAGE(ValueModification)
@@ -443,6 +443,9 @@ public:
{
m_PassabilityCircular = enabled;
MakeDirtyAll();
CMessageObstructionMapShapeChanged msg;
GetSimContext().GetComponentManager().BroadcastMessage(msg);
}
virtual void SetDebugOverlay(bool enabled)
@@ -219,6 +219,7 @@ void CCmpPathfinder::HandleMessage(const CMessage& msg, bool UNUSED(global))
}
case MT_TerrainChanged:
case MT_WaterChanged:
case MT_ObstructionMapShapeChanged:
{
// TODO: we ought to only bother updating the dirtied region
m_TerrainDirty = true;
@@ -339,11 +340,6 @@ void CCmpPathfinder::UpdateGrid()
// Since terrain hasn't changed we only need to update the obstruction bits
// and can skip the rest of the data
// TODO: if ObstructionManager::SetPassabilityCircular was called at runtime
// (which should probably never happen, but that's not guaranteed),
// then TILE_OUTOFBOUNDS will change and we can't use this fast path, but
// currently it'll just set obstructionsDirty and we won't notice
for (u16 j = 0; j < m_MapSize; ++j)
{
for (u16 i = 0; i < m_MapSize; ++i)
@@ -175,6 +175,7 @@ public:
componentManager.SubscribeToMessageType(MT_RenderSubmit); // for debug overlays
componentManager.SubscribeToMessageType(MT_TerrainChanged);
componentManager.SubscribeToMessageType(MT_WaterChanged);
componentManager.SubscribeToMessageType(MT_ObstructionMapShapeChanged);
componentManager.SubscribeToMessageType(MT_TurnStart);
}
@@ -323,6 +323,19 @@ CMessage* CMessageWaterChanged::FromJSVal(ScriptInterface& UNUSED(scriptInterfac
////////////////////////////////
jsval CMessageObstructionMapShapeChanged::ToJSVal(ScriptInterface& scriptInterface) const
{
TOJSVAL_SETUP();
return OBJECT_TO_JSVAL(obj);
}
CMessage* CMessageObstructionMapShapeChanged::FromJSVal(ScriptInterface& UNUSED(scriptInterface), jsval UNUSED(val))
{
return new CMessageObstructionMapShapeChanged();
}
////////////////////////////////
jsval CMessageTerritoriesChanged::ToJSVal(ScriptInterface& scriptInterface) const
{
TOJSVAL_SETUP();