Fix formation reshuffling after entity rename

When entities in formations were renamed (e.g., during promotion),
the formation would immediately recalculate all member positions,
and queue movement orders causing visible shuffling.

Changes:
1. Transfer existing offsets movement to the renamed entity
   to maintain current formation structure
2. Schedule offset recalculation for the next tick to allow proper
   reordering after all systems have updated

This preserves formation integrity during renames while allowing
eventual optimal position recalculation.

Fixes #8656
This commit is contained in:
Atrik
2026-01-13 06:15:32 +01:00
committed by Vantha
parent 6cdbdae87c
commit 99e3799883
6 changed files with 98 additions and 18 deletions
@@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -48,6 +48,7 @@
#include <js/experimental/TypedData.h>
#include <string>
#include <vector>
#include <optional>
#define FAIL(msg) STMT(LOGERROR(msg); return false)
#define FAIL_VOID(msg) STMT(ScriptException::Raise(rq, msg); return)
@@ -210,6 +211,30 @@ template<> void Script::ToJSVal<CFixedVector2D>(const ScriptRequest& rq, JS::Mu
ret.setObject(*objVec);
}
template<> bool Script::FromJSVal<std::optional<CFixedVector2D>>(const ScriptRequest& rq, JS::HandleValue v, std::optional<CFixedVector2D>& out)
{
if (v.isNullOrUndefined())
{
out = std::nullopt;
return true;
}
CFixedVector2D vec;
if (!FromJSVal(rq, v, vec))
return false;
out = vec;
return true;
}
template<> void Script::ToJSVal<std::optional<CFixedVector2D>>(const ScriptRequest& rq, JS::MutableHandleValue ret, const std::optional<CFixedVector2D>& val)
{
if (!val.has_value())
ret.setNull();
else
ToJSVal(rq, ret, val.value());
}
template<> void Script::ToJSVal<Grid<u8> >(const ScriptRequest& rq, JS::MutableHandleValue ret, const Grid<u8>& val)
{
u32 length = (u32)(val.m_W * val.m_H);