Line data Source code
1 : /* Copyright (C) 2022 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 1 : BEGIN_INTERFACE_WRAPPER(UnitMotion)
26 : DEFINE_INTERFACE_METHOD("MoveToPointRange", ICmpUnitMotion, MoveToPointRange)
27 : DEFINE_INTERFACE_METHOD("MoveToTargetRange", ICmpUnitMotion, MoveToTargetRange)
28 : DEFINE_INTERFACE_METHOD("MoveToFormationOffset", ICmpUnitMotion, MoveToFormationOffset)
29 : DEFINE_INTERFACE_METHOD("SetMemberOfFormation", ICmpUnitMotion, SetMemberOfFormation)
30 : DEFINE_INTERFACE_METHOD("IsTargetRangeReachable", ICmpUnitMotion, IsTargetRangeReachable)
31 : DEFINE_INTERFACE_METHOD("FaceTowardsPoint", ICmpUnitMotion, FaceTowardsPoint)
32 : DEFINE_INTERFACE_METHOD("StopMoving", ICmpUnitMotion, StopMoving)
33 : DEFINE_INTERFACE_METHOD("GetCurrentSpeed", ICmpUnitMotion, GetCurrentSpeed)
34 : DEFINE_INTERFACE_METHOD("IsMoveRequested", ICmpUnitMotion, IsMoveRequested)
35 : DEFINE_INTERFACE_METHOD("GetSpeed", ICmpUnitMotion, GetSpeed)
36 : DEFINE_INTERFACE_METHOD("GetWalkSpeed", ICmpUnitMotion, GetWalkSpeed)
37 : DEFINE_INTERFACE_METHOD("GetRunMultiplier", ICmpUnitMotion, GetRunMultiplier)
38 : DEFINE_INTERFACE_METHOD("EstimateFuturePosition", ICmpUnitMotion, EstimateFuturePosition)
39 : DEFINE_INTERFACE_METHOD("SetSpeedMultiplier", ICmpUnitMotion, SetSpeedMultiplier)
40 : DEFINE_INTERFACE_METHOD("GetAcceleration", ICmpUnitMotion, GetAcceleration)
41 : DEFINE_INTERFACE_METHOD("SetAcceleration", ICmpUnitMotion, SetAcceleration)
42 : DEFINE_INTERFACE_METHOD("GetPassabilityClassName", ICmpUnitMotion, GetPassabilityClassName)
43 : DEFINE_INTERFACE_METHOD("SetPassabilityClassName", ICmpUnitMotion, SetPassabilityClassName)
44 : DEFINE_INTERFACE_METHOD("GetUnitClearance", ICmpUnitMotion, GetUnitClearance)
45 : DEFINE_INTERFACE_METHOD("SetFacePointAfterMove", ICmpUnitMotion, SetFacePointAfterMove)
46 : DEFINE_INTERFACE_METHOD("GetFacePointAfterMove", ICmpUnitMotion, GetFacePointAfterMove)
47 : DEFINE_INTERFACE_METHOD("SetDebugOverlay", ICmpUnitMotion, SetDebugOverlay)
48 233 : END_INTERFACE_WRAPPER(UnitMotion)
49 :
50 0 : class CCmpUnitMotionScripted : public ICmpUnitMotion
51 : {
52 : public:
53 232 : DEFAULT_SCRIPT_WRAPPER(UnitMotionScripted)
54 :
55 0 : bool MoveToPointRange(entity_pos_t x, entity_pos_t z, entity_pos_t minRange, entity_pos_t maxRange) override
56 : {
57 0 : return m_Script.Call<bool>("MoveToPointRange", x, z, minRange, maxRange);
58 : }
59 :
60 0 : bool MoveToTargetRange(entity_id_t target, entity_pos_t minRange, entity_pos_t maxRange) override
61 : {
62 0 : return m_Script.Call<bool>("MoveToTargetRange", target, minRange, maxRange);
63 : }
64 :
65 0 : void MoveToFormationOffset(entity_id_t target, entity_pos_t x, entity_pos_t z) override
66 : {
67 0 : m_Script.CallVoid("MoveToFormationOffset", target, x, z);
68 0 : }
69 :
70 0 : void SetMemberOfFormation(entity_id_t controller) override
71 : {
72 0 : m_Script.CallVoid("SetMemberOfFormation", controller);
73 0 : }
74 :
75 0 : bool IsTargetRangeReachable(entity_id_t target, entity_pos_t minRange, entity_pos_t maxRange) override
76 : {
77 0 : return m_Script.Call<bool>("IsTargetRangeReachable", target, minRange, maxRange);
78 : }
79 :
80 0 : void FaceTowardsPoint(entity_pos_t x, entity_pos_t z) override
81 : {
82 0 : m_Script.CallVoid("FaceTowardsPoint", x, z);
83 0 : }
84 :
85 0 : void StopMoving() override
86 : {
87 0 : m_Script.CallVoid("StopMoving");
88 0 : }
89 :
90 0 : fixed GetCurrentSpeed() const override
91 : {
92 0 : return m_Script.Call<fixed>("GetCurrentSpeed");
93 : }
94 :
95 0 : bool IsMoveRequested() const override
96 : {
97 0 : return m_Script.Call<bool>("IsMoveRequested");
98 : }
99 :
100 0 : fixed GetSpeed() const override
101 : {
102 0 : return m_Script.Call<fixed>("GetSpeed");
103 : }
104 :
105 0 : fixed GetWalkSpeed() const override
106 : {
107 0 : return m_Script.Call<fixed>("GetWalkSpeed");
108 : }
109 :
110 0 : fixed GetRunMultiplier() const override
111 : {
112 0 : return m_Script.Call<fixed>("GetRunMultiplier");
113 : }
114 :
115 0 : void SetSpeedMultiplier(fixed multiplier) override
116 : {
117 0 : m_Script.CallVoid("SetSpeedMultiplier", multiplier);
118 0 : }
119 :
120 0 : fixed GetSpeedMultiplier() const override
121 : {
122 0 : return m_Script.Call<fixed>("GetSpeedMultiplier");
123 : }
124 :
125 0 : CFixedVector2D EstimateFuturePosition(const fixed dt) const override
126 : {
127 0 : return m_Script.Call<CFixedVector2D>("EstimateFuturePosition", dt);
128 : }
129 :
130 0 : fixed GetAcceleration() const override
131 : {
132 0 : return m_Script.Call<fixed>("GetAcceleration");
133 : }
134 :
135 0 : void SetAcceleration(fixed acceleration) override
136 : {
137 0 : m_Script.CallVoid("SetAcceleration", acceleration);
138 0 : }
139 :
140 0 : void SetFacePointAfterMove(bool facePointAfterMove) override
141 : {
142 0 : m_Script.CallVoid("SetFacePointAfterMove", facePointAfterMove);
143 0 : }
144 :
145 0 : bool GetFacePointAfterMove() const override
146 : {
147 0 : return m_Script.Call<bool>("GetFacePointAfterMove");
148 : }
149 :
150 0 : pass_class_t GetPassabilityClass() const override
151 : {
152 0 : return m_Script.Call<pass_class_t>("GetPassabilityClass");
153 : }
154 :
155 0 : std::string GetPassabilityClassName() const override
156 : {
157 0 : return m_Script.Call<std::string>("GetPassabilityClassName");
158 : }
159 :
160 0 : void SetPassabilityClassName(const std::string& passClassName) override
161 : {
162 0 : return m_Script.CallVoid("SetPassabilityClassName", passClassName);
163 : }
164 :
165 0 : entity_pos_t GetUnitClearance() const override
166 : {
167 0 : return m_Script.Call<entity_pos_t>("GetUnitClearance");
168 : }
169 :
170 0 : void SetDebugOverlay(bool enabled) override
171 : {
172 0 : m_Script.CallVoid("SetDebugOverlay", enabled);
173 0 : }
174 :
175 : };
176 :
177 119 : REGISTER_COMPONENT_SCRIPT_WRAPPER(UnitMotionScripted)
|