Line data Source code
1 : /* Copyright (C) 2026 Wildfire Games.
2 : * This file is part of 0 A.D.
3 : *
4 : * 0 A.D. is free software: you can redistribute it and/or modify
5 : * it under the terms of the GNU General Public License as published by
6 : * the Free Software Foundation, either version 2 of the License, or
7 : * (at your option) any later version.
8 : *
9 : * 0 A.D. is distributed in the hope that it will be useful,
10 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 : * GNU General Public License for more details.
13 : *
14 : * You should have received a copy of the GNU General Public License
15 : * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16 : */
17 :
18 : #include "precompiled.h"
19 :
20 : #include "ICmpUnitMotion.h"
21 :
22 : #include "simulation2/system/InterfaceScripted.h"
23 : #include "simulation2/scripting/ScriptComponent.h"
24 :
25 : BEGIN_INTERFACE_WRAPPER(UnitMotion)
26 60 : DEFINE_INTERFACE_METHOD("MoveToPointRange", ICmpUnitMotion, MoveToPointRange)
27 357 : DEFINE_INTERFACE_METHOD("MoveToTargetRange", ICmpUnitMotion, MoveToTargetRange)
28 0 : DEFINE_INTERFACE_METHOD("MoveToFormationOffset", ICmpUnitMotion, MoveToFormationOffset)
29 : DEFINE_INTERFACE_METHOD("SetMemberOfFormation", ICmpUnitMotion, SetMemberOfFormation)
30 0 : DEFINE_INTERFACE_METHOD("IsTargetRangeReachable", ICmpUnitMotion, IsTargetRangeReachable)
31 : DEFINE_INTERFACE_METHOD("PossiblyAtDestination", ICmpUnitMotion, PossiblyAtDestination)
32 510 : DEFINE_INTERFACE_METHOD("FaceTowardsPoint", ICmpUnitMotion, FaceTowardsPoint)
33 : DEFINE_INTERFACE_METHOD("StopMoving", ICmpUnitMotion, StopMoving)
34 : DEFINE_INTERFACE_METHOD("GetCurrentSpeed", ICmpUnitMotion, GetCurrentSpeed)
35 0 : DEFINE_INTERFACE_METHOD("GetFormationOffset", ICmpUnitMotion, GetFormationOffset)
36 0 : DEFINE_INTERFACE_METHOD("SetCurrentSpeed", ICmpUnitMotion, SetCurrentSpeed)
37 : DEFINE_INTERFACE_METHOD("IsMoveRequested", ICmpUnitMotion, IsMoveRequested)
38 : DEFINE_INTERFACE_METHOD("IsMovingAsFormation", ICmpUnitMotion, IsMovingAsFormation)
39 : DEFINE_INTERFACE_METHOD("GetSpeed", ICmpUnitMotion, GetSpeed)
40 : DEFINE_INTERFACE_METHOD("GetWalkSpeed", ICmpUnitMotion, GetWalkSpeed)
41 : DEFINE_INTERFACE_METHOD("GetRunMultiplier", ICmpUnitMotion, GetRunMultiplier)
42 36 : DEFINE_INTERFACE_METHOD("EstimateFuturePosition", ICmpUnitMotion, EstimateFuturePosition)
43 381 : DEFINE_INTERFACE_METHOD("SetSpeedMultiplier", ICmpUnitMotion, SetSpeedMultiplier)
44 : DEFINE_INTERFACE_METHOD("GetAcceleration", ICmpUnitMotion, GetAcceleration)
45 0 : DEFINE_INTERFACE_METHOD("SetAcceleration", ICmpUnitMotion, SetAcceleration)
46 : DEFINE_INTERFACE_METHOD("GetPassabilityClassName", ICmpUnitMotion, GetPassabilityClassName)
47 0 : DEFINE_INTERFACE_METHOD("SetPassabilityClassName", ICmpUnitMotion, SetPassabilityClassName)
48 : DEFINE_INTERFACE_METHOD("GetUnitClearance", ICmpUnitMotion, GetUnitClearance)
49 : DEFINE_INTERFACE_METHOD("SetFacePointAfterMove", ICmpUnitMotion, SetFacePointAfterMove)
50 : DEFINE_INTERFACE_METHOD("GetFacePointAfterMove", ICmpUnitMotion, GetFacePointAfterMove)
51 : DEFINE_INTERFACE_METHOD("SetDebugOverlay", ICmpUnitMotion, SetDebugOverlay)
52 2177 : END_INTERFACE_WRAPPER(UnitMotion)
53 :
54 : class CCmpUnitMotionScripted : public ICmpUnitMotion
55 : {
56 : public:
57 278 : DEFAULT_SCRIPT_WRAPPER(UnitMotionScripted)
58 :
59 0 : bool MoveToPointRange(entity_pos_t x, entity_pos_t z, entity_pos_t minRange, entity_pos_t maxRange) override
60 : {
61 0 : return m_Script.Call<bool>("MoveToPointRange", x, z, minRange, maxRange);
62 : }
63 :
64 0 : bool MoveToTargetRange(entity_id_t target, entity_pos_t minRange, entity_pos_t maxRange) override
65 : {
66 0 : return m_Script.Call<bool>("MoveToTargetRange", target, minRange, maxRange);
67 : }
68 :
69 0 : void MoveToFormationOffset(entity_id_t target, entity_pos_t x, entity_pos_t z) override
70 : {
71 0 : m_Script.CallVoid("MoveToFormationOffset", target, x, z);
72 0 : }
73 :
74 0 : void SetMemberOfFormation(entity_id_t controller) override
75 : {
76 0 : m_Script.CallVoid("SetMemberOfFormation", controller);
77 0 : }
78 :
79 0 : bool IsTargetRangeReachable(entity_id_t target, entity_pos_t minRange, entity_pos_t maxRange) override
80 : {
81 0 : return m_Script.Call<bool>("IsTargetRangeReachable", target, minRange, maxRange);
82 : }
83 :
84 0 : bool PossiblyAtDestination() const override
85 : {
86 0 : return m_Script.Call<bool>("PossiblyAtDestination");
87 : }
88 :
89 0 : void FaceTowardsPoint(entity_pos_t x, entity_pos_t z) override
90 : {
91 0 : m_Script.CallVoid("FaceTowardsPoint", x, z);
92 0 : }
93 :
94 0 : void StopMoving() override
95 : {
96 0 : m_Script.CallVoid("StopMoving");
97 0 : }
98 :
99 0 : fixed GetCurrentSpeed() const override
100 : {
101 0 : return m_Script.Call<fixed>("GetCurrentSpeed");
102 : }
103 :
104 0 : void SetCurrentSpeed(const fixed& speed) override
105 : {
106 0 : m_Script.CallVoid("SetCurrentSpeed", speed);
107 0 : }
108 :
109 0 : std::optional<CFixedVector2D> GetFormationOffset() const override
110 : {
111 0 : return m_Script.Call<std::optional<CFixedVector2D>>("GetFormationOffset");
112 : }
113 :
114 0 : bool IsMoveRequested() const override
115 : {
116 0 : return m_Script.Call<bool>("IsMoveRequested");
117 : }
118 :
119 0 : bool IsMovingAsFormation() const override
120 : {
121 0 : return m_Script.Call<bool>("IsMovingAsFormation");
122 : }
123 :
124 0 : fixed GetSpeed() const override
125 : {
126 0 : return m_Script.Call<fixed>("GetSpeed");
127 : }
128 :
129 0 : fixed GetWalkSpeed() const override
130 : {
131 0 : return m_Script.Call<fixed>("GetWalkSpeed");
132 : }
133 :
134 0 : fixed GetRunMultiplier() const override
135 : {
136 0 : return m_Script.Call<fixed>("GetRunMultiplier");
137 : }
138 :
139 0 : void SetSpeedMultiplier(fixed multiplier) override
140 : {
141 0 : m_Script.CallVoid("SetSpeedMultiplier", multiplier);
142 0 : }
143 :
144 0 : fixed GetSpeedMultiplier() const override
145 : {
146 0 : return m_Script.Call<fixed>("GetSpeedMultiplier");
147 : }
148 :
149 0 : CFixedVector2D EstimateFuturePosition(const fixed dt) const override
150 : {
151 0 : return m_Script.Call<CFixedVector2D>("EstimateFuturePosition", dt);
152 : }
153 :
154 0 : fixed GetAcceleration() const override
155 : {
156 0 : return m_Script.Call<fixed>("GetAcceleration");
157 : }
158 :
159 0 : void SetAcceleration(fixed acceleration) override
160 : {
161 0 : m_Script.CallVoid("SetAcceleration", acceleration);
162 0 : }
163 :
164 0 : void SetFacePointAfterMove(bool facePointAfterMove) override
165 : {
166 0 : m_Script.CallVoid("SetFacePointAfterMove", facePointAfterMove);
167 0 : }
168 :
169 0 : bool GetFacePointAfterMove() const override
170 : {
171 0 : return m_Script.Call<bool>("GetFacePointAfterMove");
172 : }
173 :
174 0 : pass_class_t GetPassabilityClass() const override
175 : {
176 0 : return m_Script.Call<pass_class_t>("GetPassabilityClass");
177 : }
178 :
179 0 : std::string GetPassabilityClassName() const override
180 : {
181 0 : return m_Script.Call<std::string>("GetPassabilityClassName");
182 : }
183 :
184 0 : void SetPassabilityClassName(const std::string& passClassName) override
185 : {
186 0 : return m_Script.CallVoid("SetPassabilityClassName", passClassName);
187 : }
188 :
189 0 : entity_pos_t GetUnitClearance() const override
190 : {
191 0 : return m_Script.Call<entity_pos_t>("GetUnitClearance");
192 : }
193 :
194 0 : void SetDebugOverlay(bool enabled) override
195 : {
196 0 : m_Script.CallVoid("SetDebugOverlay", enabled);
197 0 : }
198 :
199 : };
200 :
201 274 : REGISTER_COMPONENT_SCRIPT_WRAPPER(UnitMotionScripted)
|