Index: binaries/data/mods/public/simulation/components/UnitAI.js =================================================================== --- binaries/data/mods/public/simulation/components/UnitAI.js +++ binaries/data/mods/public/simulation/components/UnitAI.js @@ -143,10 +143,6 @@ // as switching states) }, - "MoveStarted": function() { - // ignore spurious movement messages - }, - "ConstructionFinished": function(msg) { // ignore uninteresting construction messages }, @@ -883,12 +879,6 @@ var cmpFormation = Engine.QueryInterface(this.entity, IID_Formation); cmpFormation.SetRearrange(false); }, - - "MoveStarted": function() { - let cmpFormation = Engine.QueryInterface(this.entity, IID_Formation); - cmpFormation.SetRearrange(true); - cmpFormation.MoveMembersIntoFormation(true, true); - } }, "WALKING": { @@ -898,18 +888,15 @@ this.FinishOrder(); return true; } + let cmpFormation = Engine.QueryInterface(this.entity, IID_Formation); + cmpFormation.SetRearrange(true); + cmpFormation.MoveMembersIntoFormation(true, true); }, "leave": function() { this.StopMoving(); }, - "MoveStarted": function(msg) { - var cmpFormation = Engine.QueryInterface(this.entity, IID_Formation); - cmpFormation.SetRearrange(true); - cmpFormation.MoveMembersIntoFormation(true, true); - }, - "MoveCompleted": function(msg) { if (this.FinishOrder()) this.CallMemberFunction("ResetFinishOrder", []); @@ -924,6 +911,9 @@ return true; } this.StartTimer(0, 1000); + let cmpFormation = Engine.QueryInterface(this.entity, IID_Formation); + cmpFormation.SetRearrange(true); + cmpFormation.MoveMembersIntoFormation(true, true); }, "leave": function() { @@ -939,12 +929,6 @@ this.StopTimer(); }, - "MoveStarted": function(msg) { - var cmpFormation = Engine.QueryInterface(this.entity, IID_Formation); - cmpFormation.SetRearrange(true); - cmpFormation.MoveMembersIntoFormation(true, true); - }, - "MoveCompleted": function(msg) { if (this.FinishOrder()) this.CallMemberFunction("ResetFinishOrder", []); @@ -973,6 +957,10 @@ return true; } this.StartTimer(0, 1000); + + let cmpFormation = Engine.QueryInterface(this.entity, IID_Formation); + cmpFormation.SetRearrange(true); + cmpFormation.MoveMembersIntoFormation(true, true); }, "Timer": function(msg) { @@ -986,12 +974,6 @@ delete this.patrolStartPosOrder; }, - "MoveStarted": function(msg) { - let cmpFormation = Engine.QueryInterface(this.entity, IID_Formation); - cmpFormation.SetRearrange(true); - cmpFormation.MoveMembersIntoFormation(true, true); - }, - "MoveCompleted": function() { /** * A-B-A-B-..: @@ -1039,18 +1021,15 @@ this.FinishOrder(); return true; } - }, - - "leave": function() { - this.StopMoving(); - }, - - "MoveStarted": function(msg) { - var cmpFormation = Engine.QueryInterface(this.entity, IID_Formation); + let cmpFormation = Engine.QueryInterface(this.entity, IID_Formation); cmpFormation.SetRearrange(true); cmpFormation.MoveMembersIntoFormation(true, true); }, + "leave": function() { + this.StopMoving(); + }, + "MoveCompleted": function(msg) { this.SetNextState("GARRISONING"); }, @@ -1077,18 +1056,15 @@ this.FinishOrder(); return true; } + let cmpFormation = Engine.QueryInterface(this.entity, IID_Formation); + cmpFormation.SetRearrange(true); + cmpFormation.MoveMembersIntoFormation(true, true); }, "leave": function() { this.StopMoving(); }, - "MoveStarted": function(msg) { - var cmpFormation = Engine.QueryInterface(this.entity, IID_Formation); - cmpFormation.SetRearrange(true); - cmpFormation.MoveMembersIntoFormation(true, false); - }, - "MoveCompleted": function(msg) { if (this.FinishOrder()) @@ -1110,18 +1086,15 @@ this.FinishOrder(); return true; } - }, - - "leave": function() { - this.StopMoving(); - }, - - "MoveStarted": function(msg) { - var cmpFormation = Engine.QueryInterface(this.entity, IID_Formation); + let cmpFormation = Engine.QueryInterface(this.entity, IID_Formation); cmpFormation.SetRearrange(true); cmpFormation.MoveMembersIntoFormation(true, true); }, + "leave": function() { + this.StopMoving(); + }, + "MoveCompleted": function(msg) { var cmpAttack = Engine.QueryInterface(this.entity, IID_Attack); this.CallMemberFunction("Attack", [this.order.data.target, this.order.data.allowCapture, false]); @@ -1484,10 +1457,6 @@ this.RespondToHealableEntities(msg.data.added); }, - "MoveStarted": function() { - this.SelectAnimation("move"); - }, - "MoveCompleted": function() { this.SelectAnimation("idle"); }, @@ -1623,29 +1592,28 @@ this.FinishOrder(); return; } - this.SetHeldPositionOnEntity(this.isGuardOf); - }, - "leave": function(msg) { - this.StopMoving(); - this.ResetSpeedMultiplier(); - this.StopTimer(); - this.SetDefaultAnimationVariant(); - }, - - "MoveStarted": function(msg) { // Adapt the speed to the one of the target if needed let cmpObstructionManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_ObstructionManager); if (cmpObstructionManager.IsInTargetRange(this.entity, this.isGuardOf, 0, 3 * this.guardRange, true)) { - var cmpUnitAI = Engine.QueryInterface(this.isGuardOf, IID_UnitAI); + let cmpUnitAI = Engine.QueryInterface(this.isGuardOf, IID_UnitAI); if (cmpUnitAI) { - var speed = cmpUnitAI.GetWalkSpeed(); + let speed = cmpUnitAI.GetWalkSpeed(); if (speed < this.GetWalkSpeed()) this.SetSpeedMultiplier(speed / this.GetWalkSpeed()); } } + + this.SetHeldPositionOnEntity(this.isGuardOf); + }, + + "leave": function(msg) { + this.StopMoving(); + this.ResetSpeedMultiplier(); + this.StopTimer(); + this.SetDefaultAnimationVariant(); }, "MoveCompleted": function() { @@ -3823,10 +3791,7 @@ UnitAI.prototype.OnMotionChanged = function(msg) { - if (msg.starting && !msg.error) - this.UnitFsm.ProcessMessage(this, {"type": "MoveStarted", "data": msg}); - else if (!msg.starting || msg.error) - this.UnitFsm.ProcessMessage(this, {"type": "MoveCompleted", "data": msg}); + this.UnitFsm.ProcessMessage(this, { "type": "MoveCompleted", "data": msg }); }; UnitAI.prototype.OnGlobalConstructionFinished = function(msg) Index: binaries/data/mods/public/simulation/components/tests/test_UnitAI.js =================================================================== --- binaries/data/mods/public/simulation/components/tests/test_UnitAI.js +++ binaries/data/mods/public/simulation/components/tests/test_UnitAI.js @@ -155,7 +155,6 @@ controllerFormation.SetMembers([unit]); controllerAI.Walk(100, 100, false); - controllerAI.OnMotionChanged({ "starting": true }); TS_ASSERT_EQUALS(controllerAI.fsmStateName, "FORMATIONCONTROLLER.WALKING"); TS_ASSERT_EQUALS(unitAI.fsmStateName, "FORMATIONMEMBER.WALKING"); Index: source/simulation2/MessageTypes.h =================================================================== --- source/simulation2/MessageTypes.h +++ source/simulation2/MessageTypes.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -317,20 +317,17 @@ }; /** - * Sent by CCmpUnitMotion during Update, whenever the motion status has changed - * since the previous update. + * Sent by CCmpUnitMotion during Update if an event happened that might interest other components. */ class CMessageMotionChanged : public CMessage { public: DEFAULT_MESSAGE_IMPL(MotionChanged) - CMessageMotionChanged(bool starting, bool error) : - starting(starting), error(error) + CMessageMotionChanged(bool error) : error(error) { } - bool starting; // whether this is a start or end of movement bool error; // whether we failed to start moving (couldn't find any path) }; Index: source/simulation2/components/CCmpUnitMotion.cpp =================================================================== --- source/simulation2/components/CCmpUnitMotion.cpp +++ source/simulation2/components/CCmpUnitMotion.cpp @@ -546,19 +546,6 @@ || m_PathState == PATHSTATE_FOLLOWING_REQUESTING_SHORT; } - void StartFailed() - { - StopMoving(); - m_State = STATE_IDLE; // don't go through the STOPPING state since we never even started - - CmpPtr cmpObstruction(GetEntityHandle()); - if (cmpObstruction) - cmpObstruction->SetMovingFlag(false); - - CMessageMotionChanged msg(true, true); - GetSimContext().GetComponentManager().PostMessage(GetEntityId(), msg); - } - void MoveFailed() { StopMoving(); @@ -567,19 +554,7 @@ if (cmpObstruction) cmpObstruction->SetMovingFlag(false); - CMessageMotionChanged msg(false, true); - GetSimContext().GetComponentManager().PostMessage(GetEntityId(), msg); - } - - void StartSucceeded() - { - CmpPtr cmpObstruction(GetEntityHandle()); - if (cmpObstruction) - cmpObstruction->SetMovingFlag(true); - - m_Moving = true; - - CMessageMotionChanged msg(true, false); + CMessageMotionChanged msg(true); GetSimContext().GetComponentManager().PostMessage(GetEntityId(), msg); } @@ -594,7 +569,7 @@ // No longer moving, so speed is 0. m_CurSpeed = fixed::Zero(); - CMessageMotionChanged msg(false, false); + CMessageMotionChanged msg(false); GetSimContext().GetComponentManager().PostMessage(GetEntityId(), msg); } @@ -716,7 +691,7 @@ if (!cmpPosition || !cmpPosition->IsInWorld()) { if (m_PathState == PATHSTATE_WAITING_REQUESTING_LONG || m_PathState == PATHSTATE_WAITING_REQUESTING_SHORT) - StartFailed(); + MoveFailed(); else if (m_PathState == PATHSTATE_FOLLOWING_REQUESTING_LONG || m_PathState == PATHSTATE_FOLLOWING_REQUESTING_SHORT) StopMoving(); return; @@ -738,9 +713,6 @@ if (m_LongPath.m_Waypoints.empty()) m_LongPath.m_Waypoints.emplace_back(Waypoint{ m_FinalGoal.x, m_FinalGoal.z }); - if (!HasValidPath()) - StartSucceeded(); - m_PathState = PATHSTATE_FOLLOWING; if (cmpObstruction) @@ -764,12 +736,12 @@ else if (IsFormationMember()) { m_Moving = false; - CMessageMotionChanged msg(true, true); + CMessageMotionChanged msg(true); GetSimContext().GetComponentManager().PostMessage(GetEntityId(), msg); return; } - CMessageMotionChanged msg(false, false); + CMessageMotionChanged msg(false); GetSimContext().GetComponentManager().PostMessage(GetEntityId(), msg); CmpPtr cmpPosition(GetEntityHandle()); @@ -797,10 +769,6 @@ // else we could, so reset our number of tries. m_Tries = 0; - // Now we've got a short path that we can follow - if (!HasValidPath()) - StartSucceeded(); - m_PathState = PATHSTATE_FOLLOWING; if (cmpObstruction) @@ -1047,7 +1015,7 @@ cmpObstruction->SetMovingFlag(false); m_Moving = false; - CMessageMotionChanged msg(false, false); + CMessageMotionChanged msg(false); GetSimContext().GetComponentManager().PostMessage(GetEntityId(), msg); return; } @@ -1326,8 +1294,6 @@ // instead of computing a path. if (TryGoingStraightToTargetEntity(from)) { - if (!HasValidPath()) - StartSucceeded(); m_PathState = PATHSTATE_FOLLOWING; return; } @@ -1335,8 +1301,6 @@ // Same thing applies to non-entity points if (TryGoingStraightToGoalPoint(from)) { - if (!HasValidPath()) - StartSucceeded(); m_PathState = PATHSTATE_FOLLOWING; return; } Index: source/simulation2/scripting/MessageTypeConversions.cpp =================================================================== --- source/simulation2/scripting/MessageTypeConversions.cpp +++ source/simulation2/scripting/MessageTypeConversions.cpp @@ -269,7 +269,6 @@ JS::Value CMessageMotionChanged::ToJSVal(const ScriptInterface& scriptInterface) const { TOJSVAL_SETUP(); - SET_MSG_PROPERTY(starting); SET_MSG_PROPERTY(error); return JS::ObjectValue(*obj); } @@ -277,9 +276,8 @@ CMessage* CMessageMotionChanged::FromJSVal(const ScriptInterface& scriptInterface, JS::HandleValue val) { FROMJSVAL_SETUP(); - GET_MSG_PROPERTY(bool, starting); GET_MSG_PROPERTY(bool, error); - return new CMessageMotionChanged(starting, error); + return new CMessageMotionChanged(error); } ////////////////////////////////