2022-03-07 15:04:11 -08:00
|
|
|
/* Copyright (C) 2022 Wildfire Games.
|
2023-12-02 16:30:12 -08:00
|
|
|
* This file is part of 0 A.D.
|
2010-01-09 11:20:14 -08:00
|
|
|
*
|
2023-12-02 16:30:12 -08:00
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
2010-01-09 11:20:14 -08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
2023-12-02 16:30:12 -08:00
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
2010-01-09 11:20:14 -08:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2023-12-02 16:30:12 -08:00
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
2010-01-09 11:20:14 -08:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "precompiled.h"
|
|
|
|
|
|
|
|
|
|
#include "ICmpUnitMotion.h"
|
|
|
|
|
|
|
|
|
|
#include "simulation2/system/InterfaceScripted.h"
|
2011-06-09 12:44:40 -07:00
|
|
|
#include "simulation2/scripting/ScriptComponent.h"
|
2010-01-09 11:20:14 -08:00
|
|
|
|
|
|
|
|
BEGIN_INTERFACE_WRAPPER(UnitMotion)
|
2021-05-01 01:01:30 -07:00
|
|
|
DEFINE_INTERFACE_METHOD("MoveToPointRange", ICmpUnitMotion, MoveToPointRange)
|
|
|
|
|
DEFINE_INTERFACE_METHOD("MoveToTargetRange", ICmpUnitMotion, MoveToTargetRange)
|
|
|
|
|
DEFINE_INTERFACE_METHOD("MoveToFormationOffset", ICmpUnitMotion, MoveToFormationOffset)
|
2021-06-06 08:25:52 -07:00
|
|
|
DEFINE_INTERFACE_METHOD("SetMemberOfFormation", ICmpUnitMotion, SetMemberOfFormation)
|
2021-05-01 01:01:30 -07:00
|
|
|
DEFINE_INTERFACE_METHOD("IsTargetRangeReachable", ICmpUnitMotion, IsTargetRangeReachable)
|
2025-01-01 02:33:07 -08:00
|
|
|
DEFINE_INTERFACE_METHOD("PossiblyAtDestination", ICmpUnitMotion, PossiblyAtDestination)
|
2021-05-01 01:01:30 -07:00
|
|
|
DEFINE_INTERFACE_METHOD("FaceTowardsPoint", ICmpUnitMotion, FaceTowardsPoint)
|
|
|
|
|
DEFINE_INTERFACE_METHOD("StopMoving", ICmpUnitMotion, StopMoving)
|
|
|
|
|
DEFINE_INTERFACE_METHOD("GetCurrentSpeed", ICmpUnitMotion, GetCurrentSpeed)
|
|
|
|
|
DEFINE_INTERFACE_METHOD("IsMoveRequested", ICmpUnitMotion, IsMoveRequested)
|
|
|
|
|
DEFINE_INTERFACE_METHOD("GetSpeed", ICmpUnitMotion, GetSpeed)
|
|
|
|
|
DEFINE_INTERFACE_METHOD("GetWalkSpeed", ICmpUnitMotion, GetWalkSpeed)
|
|
|
|
|
DEFINE_INTERFACE_METHOD("GetRunMultiplier", ICmpUnitMotion, GetRunMultiplier)
|
|
|
|
|
DEFINE_INTERFACE_METHOD("EstimateFuturePosition", ICmpUnitMotion, EstimateFuturePosition)
|
|
|
|
|
DEFINE_INTERFACE_METHOD("SetSpeedMultiplier", ICmpUnitMotion, SetSpeedMultiplier)
|
2021-10-09 14:31:11 -07:00
|
|
|
DEFINE_INTERFACE_METHOD("GetAcceleration", ICmpUnitMotion, GetAcceleration)
|
|
|
|
|
DEFINE_INTERFACE_METHOD("SetAcceleration", ICmpUnitMotion, SetAcceleration)
|
2021-05-01 01:01:30 -07:00
|
|
|
DEFINE_INTERFACE_METHOD("GetPassabilityClassName", ICmpUnitMotion, GetPassabilityClassName)
|
2022-04-17 04:06:09 -07:00
|
|
|
DEFINE_INTERFACE_METHOD("SetPassabilityClassName", ICmpUnitMotion, SetPassabilityClassName)
|
2021-05-01 01:01:30 -07:00
|
|
|
DEFINE_INTERFACE_METHOD("GetUnitClearance", ICmpUnitMotion, GetUnitClearance)
|
|
|
|
|
DEFINE_INTERFACE_METHOD("SetFacePointAfterMove", ICmpUnitMotion, SetFacePointAfterMove)
|
|
|
|
|
DEFINE_INTERFACE_METHOD("GetFacePointAfterMove", ICmpUnitMotion, GetFacePointAfterMove)
|
|
|
|
|
DEFINE_INTERFACE_METHOD("SetDebugOverlay", ICmpUnitMotion, SetDebugOverlay)
|
2010-01-09 11:20:14 -08:00
|
|
|
END_INTERFACE_WRAPPER(UnitMotion)
|
2011-06-09 12:44:40 -07:00
|
|
|
|
|
|
|
|
class CCmpUnitMotionScripted : public ICmpUnitMotion
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
DEFAULT_SCRIPT_WRAPPER(UnitMotionScripted)
|
|
|
|
|
|
2022-03-07 15:04:11 -08:00
|
|
|
bool MoveToPointRange(entity_pos_t x, entity_pos_t z, entity_pos_t minRange, entity_pos_t maxRange) override
|
2011-06-09 12:44:40 -07:00
|
|
|
{
|
|
|
|
|
return m_Script.Call<bool>("MoveToPointRange", x, z, minRange, maxRange);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-07 15:04:11 -08:00
|
|
|
bool MoveToTargetRange(entity_id_t target, entity_pos_t minRange, entity_pos_t maxRange) override
|
2011-06-09 12:44:40 -07:00
|
|
|
{
|
|
|
|
|
return m_Script.Call<bool>("MoveToTargetRange", target, minRange, maxRange);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-07 15:04:11 -08:00
|
|
|
void MoveToFormationOffset(entity_id_t target, entity_pos_t x, entity_pos_t z) override
|
2011-06-09 12:44:40 -07:00
|
|
|
{
|
|
|
|
|
m_Script.CallVoid("MoveToFormationOffset", target, x, z);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-07 15:04:11 -08:00
|
|
|
void SetMemberOfFormation(entity_id_t controller) override
|
2021-06-06 08:25:52 -07:00
|
|
|
{
|
|
|
|
|
m_Script.CallVoid("SetMemberOfFormation", controller);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-07 15:04:11 -08:00
|
|
|
bool IsTargetRangeReachable(entity_id_t target, entity_pos_t minRange, entity_pos_t maxRange) override
|
2020-08-03 05:02:24 -07:00
|
|
|
{
|
|
|
|
|
return m_Script.Call<bool>("IsTargetRangeReachable", target, minRange, maxRange);
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-01 02:33:07 -08:00
|
|
|
bool PossiblyAtDestination() const override
|
|
|
|
|
{
|
|
|
|
|
return m_Script.Call<bool>("PossiblyAtDestination");
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-07 15:04:11 -08:00
|
|
|
void FaceTowardsPoint(entity_pos_t x, entity_pos_t z) override
|
2011-06-09 12:44:40 -07:00
|
|
|
{
|
|
|
|
|
m_Script.CallVoid("FaceTowardsPoint", x, z);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-07 15:04:11 -08:00
|
|
|
void StopMoving() override
|
2011-06-09 12:44:40 -07:00
|
|
|
{
|
|
|
|
|
m_Script.CallVoid("StopMoving");
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-07 15:04:11 -08:00
|
|
|
fixed GetCurrentSpeed() const override
|
2012-12-06 11:46:13 -08:00
|
|
|
{
|
|
|
|
|
return m_Script.Call<fixed>("GetCurrentSpeed");
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-07 15:04:11 -08:00
|
|
|
bool IsMoveRequested() const override
|
2012-08-31 01:20:36 -07:00
|
|
|
{
|
2019-07-28 03:51:12 -07:00
|
|
|
return m_Script.Call<bool>("IsMoveRequested");
|
2012-08-31 01:20:36 -07:00
|
|
|
}
|
|
|
|
|
|
2022-03-07 15:04:11 -08:00
|
|
|
fixed GetSpeed() const override
|
2011-06-09 12:44:40 -07:00
|
|
|
{
|
2019-04-19 03:04:50 -07:00
|
|
|
return m_Script.Call<fixed>("GetSpeed");
|
2011-06-09 12:44:40 -07:00
|
|
|
}
|
|
|
|
|
|
2022-03-07 15:04:11 -08:00
|
|
|
fixed GetWalkSpeed() const override
|
2011-06-09 12:44:40 -07:00
|
|
|
{
|
2019-04-19 03:04:50 -07:00
|
|
|
return m_Script.Call<fixed>("GetWalkSpeed");
|
2011-06-09 12:44:40 -07:00
|
|
|
}
|
|
|
|
|
|
2022-03-07 15:04:11 -08:00
|
|
|
fixed GetRunMultiplier() const override
|
2019-05-13 09:47:51 -07:00
|
|
|
{
|
|
|
|
|
return m_Script.Call<fixed>("GetRunMultiplier");
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-07 15:04:11 -08:00
|
|
|
void SetSpeedMultiplier(fixed multiplier) override
|
2019-05-13 09:47:51 -07:00
|
|
|
{
|
|
|
|
|
m_Script.CallVoid("SetSpeedMultiplier", multiplier);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-07 15:04:11 -08:00
|
|
|
fixed GetSpeedMultiplier() const override
|
2019-05-13 09:47:51 -07:00
|
|
|
{
|
|
|
|
|
return m_Script.Call<fixed>("GetSpeedMultiplier");
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-07 15:04:11 -08:00
|
|
|
CFixedVector2D EstimateFuturePosition(const fixed dt) const override
|
2021-01-19 07:59:03 -08:00
|
|
|
{
|
|
|
|
|
return m_Script.Call<CFixedVector2D>("EstimateFuturePosition", dt);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-07 15:04:11 -08:00
|
|
|
fixed GetAcceleration() const override
|
2021-10-09 14:31:11 -07:00
|
|
|
{
|
|
|
|
|
return m_Script.Call<fixed>("GetAcceleration");
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-07 15:04:11 -08:00
|
|
|
void SetAcceleration(fixed acceleration) override
|
2021-10-09 14:31:11 -07:00
|
|
|
{
|
|
|
|
|
m_Script.CallVoid("SetAcceleration", acceleration);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-07 15:04:11 -08:00
|
|
|
void SetFacePointAfterMove(bool facePointAfterMove) override
|
2013-09-30 16:52:22 -07:00
|
|
|
{
|
|
|
|
|
m_Script.CallVoid("SetFacePointAfterMove", facePointAfterMove);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-07 15:04:11 -08:00
|
|
|
bool GetFacePointAfterMove() const override
|
2020-07-19 03:42:45 -07:00
|
|
|
{
|
|
|
|
|
return m_Script.Call<bool>("GetFacePointAfterMove");
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-07 15:04:11 -08:00
|
|
|
pass_class_t GetPassabilityClass() const override
|
2011-08-06 01:11:05 -07:00
|
|
|
{
|
New long-range pathfinder.
Based on Philip's work located at
http://git.wildfiregames.com/gitweb/?p=0ad.git;a=shortlog;h=refs/heads/projects/philip/pathfinder
Includes code by wraitii, sanderd17 and kanetaka.
An updated version of docs/pathfinder.pdf describing the changes in
detail will be committed ASAP.
Running update-workspaces is needed after this change.
Fixes #1756.
Fixes #930, #1259, #2908, #2960, #3097
Refs #1200, #1914, #1942, #2568, #2132, #2563
This was SVN commit r16751.
2015-06-12 11:58:24 -07:00
|
|
|
return m_Script.Call<pass_class_t>("GetPassabilityClass");
|
2011-08-06 01:11:05 -07:00
|
|
|
}
|
|
|
|
|
|
2022-03-07 15:04:11 -08:00
|
|
|
std::string GetPassabilityClassName() const override
|
2014-05-18 00:59:43 -07:00
|
|
|
{
|
|
|
|
|
return m_Script.Call<std::string>("GetPassabilityClassName");
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-17 04:06:09 -07:00
|
|
|
void SetPassabilityClassName(const std::string& passClassName) override
|
|
|
|
|
{
|
|
|
|
|
return m_Script.CallVoid("SetPassabilityClassName", passClassName);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-07 15:04:11 -08:00
|
|
|
entity_pos_t GetUnitClearance() const override
|
2011-06-09 12:44:40 -07:00
|
|
|
{
|
2015-07-18 01:37:49 -07:00
|
|
|
return m_Script.Call<entity_pos_t>("GetUnitClearance");
|
2011-06-09 12:44:40 -07:00
|
|
|
}
|
|
|
|
|
|
2022-03-07 15:04:11 -08:00
|
|
|
void SetDebugOverlay(bool enabled) override
|
2011-06-09 12:44:40 -07:00
|
|
|
{
|
|
|
|
|
m_Script.CallVoid("SetDebugOverlay", enabled);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
REGISTER_COMPONENT_SCRIPT_WRAPPER(UnitMotionScripted)
|