1 /*********************************************************************
2 Copyright 2013 Karl Jones
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
8 1. Redistributions of source code must retain the above copyright notice, this
9 list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright notice,
11 this list of conditions and the following disclaimer in the documentation
12 and/or other materials provided with the distribution.
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
18 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 For Further Information Please Contact me at
27 http://p.sf.net/kdis/UserGuide
28 *********************************************************************/
30 #include "KDIS/DataTypes/GED_BasicGroundCombatVehicle.hpp"
33 using namespace DATA_TYPE
;
34 using namespace ENUMS
;
35 using namespace UTILS
;
37 //////////////////////////////////////////////////////////////////////////
39 //////////////////////////////////////////////////////////////////////////
41 GED_BasicGroundCombatVehicle::GED_BasicGroundCombatVehicle()
48 for (KINT8 i
= 0; i
< 3; ++i
) {
54 //////////////////////////////////////////////////////////////////////////
56 GED_BasicGroundCombatVehicle::GED_BasicGroundCombatVehicle(
57 KDataStream
& stream
) {
61 //////////////////////////////////////////////////////////////////////////
63 GED_BasicGroundCombatVehicle::GED_BasicGroundCombatVehicle(
64 KUINT16 ID
, KINT16 XOffset
, KINT16 YOffset
, KINT16 ZOffset
,
65 const EntityAppearance
& EA
, KINT8 Psi
, KINT8 Theta
, KINT8 Phi
, KINT8 Speed
,
66 KINT8 TurretAzimuth
, KINT8 GunElevation
, KINT8 TurretSlewRate
,
67 KINT8 GunElevationRate
)
71 m_i8TrrtAz(TurretAzimuth
),
72 m_i8GnElv(GunElevation
),
73 m_i8TrrtSlwRt(TurretSlewRate
),
74 m_i8GnElvRt(GunElevationRate
) {
75 m_i16Offsets
[0] = XOffset
;
76 m_i16Offsets
[1] = YOffset
;
77 m_i16Offsets
[2] = ZOffset
;
83 //////////////////////////////////////////////////////////////////////////
85 GED_BasicGroundCombatVehicle::~GED_BasicGroundCombatVehicle() {}
87 //////////////////////////////////////////////////////////////////////////
89 GroupedEntityCategory
GED_BasicGroundCombatVehicle::GetGroupedEntityCategory()
91 return BasicGroundCombatVehicleGEC
;
94 //////////////////////////////////////////////////////////////////////////
96 KUINT8
GED_BasicGroundCombatVehicle::GetLength() const {
97 return GED_BASIC_GROUND_COMBAT_VEHICLE_SIZE
;
100 //////////////////////////////////////////////////////////////////////////
102 void GED_BasicGroundCombatVehicle::SetEntityID(KUINT16 ID
) {
106 //////////////////////////////////////////////////////////////////////////
108 KUINT16
GED_BasicGroundCombatVehicle::GetEntityID() const {
109 return m_ui16EntityID
;
112 //////////////////////////////////////////////////////////////////////////
114 void GED_BasicGroundCombatVehicle::SetEntityLocation(KINT16 XOffset
,
117 m_i16Offsets
[0] = XOffset
;
118 m_i16Offsets
[1] = YOffset
;
119 m_i16Offsets
[2] = ZOffset
;
122 //////////////////////////////////////////////////////////////////////////
124 void GED_BasicGroundCombatVehicle::SetEntityLocation(KINT16 Offsets
[3]) {
125 for (KUINT8 i
= 0; i
< 3; ++i
) {
126 m_i16Offsets
[i
] = Offsets
[i
];
130 //////////////////////////////////////////////////////////////////////////
132 void GED_BasicGroundCombatVehicle::SetEntityLocationXOffset(KINT16 X
) {
136 //////////////////////////////////////////////////////////////////////////
138 void GED_BasicGroundCombatVehicle::SetEntityLocationYOffset(KINT16 Y
) {
142 //////////////////////////////////////////////////////////////////////////
144 void GED_BasicGroundCombatVehicle::SetEntityLocationZOffset(KINT16 Z
) {
148 //////////////////////////////////////////////////////////////////////////
150 KINT16
GED_BasicGroundCombatVehicle::GetEntityLocationXOffset() const {
151 return m_i16Offsets
[0];
154 //////////////////////////////////////////////////////////////////////////
156 KINT16
GED_BasicGroundCombatVehicle::GetEntityLocationYOffset() const {
157 return m_i16Offsets
[1];
160 //////////////////////////////////////////////////////////////////////////
162 KINT16
GED_BasicGroundCombatVehicle::GetEntityLocationZOffset() const {
163 return m_i16Offsets
[2];
166 //////////////////////////////////////////////////////////////////////////
168 void GED_BasicGroundCombatVehicle::SetEntityAppearance(
169 const EntityAppearance
& EA
) {
173 //////////////////////////////////////////////////////////////////////////
175 const EntityAppearance
& GED_BasicGroundCombatVehicle::GetEntityAppearance()
180 //////////////////////////////////////////////////////////////////////////
182 EntityAppearance
& GED_BasicGroundCombatVehicle::GetEntityAppearance() {
186 //////////////////////////////////////////////////////////////////////////
188 void GED_BasicGroundCombatVehicle::SetEntityOrientation(KINT8 Psi
, KINT8 Theta
,
195 //////////////////////////////////////////////////////////////////////////
197 void GED_BasicGroundCombatVehicle::SetEntityOrientation(KINT8 Ori
[3]) {
198 for (KINT8 i
= 0; i
< 3; ++i
) {
203 //////////////////////////////////////////////////////////////////////////
205 void GED_BasicGroundCombatVehicle::SetEntityOrientationPsi(KINT8 P
) {
209 //////////////////////////////////////////////////////////////////////////
211 void GED_BasicGroundCombatVehicle::SetEntityOrientationTheta(KINT8 T
) {
215 //////////////////////////////////////////////////////////////////////////
217 void GED_BasicGroundCombatVehicle::SetEntityOrientationPhi(KINT8 P
) {
221 //////////////////////////////////////////////////////////////////////////
223 KINT8
GED_BasicGroundCombatVehicle::GetEntityOrientationPsi() const {
227 //////////////////////////////////////////////////////////////////////////
229 KINT8
GED_BasicGroundCombatVehicle::GetEntityOrientationTheta() const {
233 //////////////////////////////////////////////////////////////////////////
235 KINT8
GED_BasicGroundCombatVehicle::GetEntityOrientationPhi() const {
239 //////////////////////////////////////////////////////////////////////////
241 void GED_BasicGroundCombatVehicle::SetSpeed(KINT8 S
) { m_i8Spd
= S
; }
243 //////////////////////////////////////////////////////////////////////////
245 KINT8
GED_BasicGroundCombatVehicle::GetSpeed() const { return m_i8Spd
; }
247 //////////////////////////////////////////////////////////////////////////
249 void GED_BasicGroundCombatVehicle::SetTurretAzimuth(KINT8 T
) { m_i8TrrtAz
= T
; }
251 //////////////////////////////////////////////////////////////////////////
253 KINT8
GED_BasicGroundCombatVehicle::GetTurretAzimuth() const {
257 //////////////////////////////////////////////////////////////////////////
259 void GED_BasicGroundCombatVehicle::SetGunElevation(KINT8 G
) { m_i8GnElv
= G
; }
261 //////////////////////////////////////////////////////////////////////////
263 KINT8
GED_BasicGroundCombatVehicle::GetGunElevation() const {
267 //////////////////////////////////////////////////////////////////////////
269 void GED_BasicGroundCombatVehicle::SetTurretSlewRate(KINT8 T
) {
273 //////////////////////////////////////////////////////////////////////////
275 KINT8
GED_BasicGroundCombatVehicle::GetTurretSlewRate() const {
276 return m_i8TrrtSlwRt
;
279 //////////////////////////////////////////////////////////////////////////
281 void GED_BasicGroundCombatVehicle::SetGunElevationRate(KINT8 G
) {
285 //////////////////////////////////////////////////////////////////////////
287 KINT8
GED_BasicGroundCombatVehicle::GetGunElevationRate() const {
291 //////////////////////////////////////////////////////////////////////////
293 KString
GED_BasicGroundCombatVehicle::GetAsString() const {
296 ss
<< "GED Basic Ground Combat Vehicle\n"
297 << "\tEntity ID: " << m_ui16EntityID
<< "\n"
298 << "\tLocation Offsets(x,y,z): " << m_i16Offsets
[0] << " "
299 << m_i16Offsets
[1] << " " << m_i16Offsets
[2] << "\n"
301 m_EA
.GetAsString(EntityType(Platform
, Land
, 0, 0, 0, 0, 0)), 1)
302 << "\tOrientation(Psi,Theta,Phi): " << (KINT16
)m_i8Ori
[0] << " "
303 << (KINT16
)m_i8Ori
[1] << " " << (KINT16
)m_i8Ori
[2] << "\n"
304 << "\tSpeed: " << (KINT16
)m_i8Spd
<< "m/s\n"
305 << "\tTurret Azimuth: " << (KINT16
)m_i8TrrtAz
<< "\n"
306 << "\tGun Elevation: " << (KINT16
)m_i8GnElv
<< "\n"
307 << "\tTurret Slew Rate: " << (KINT16
)m_i8TrrtSlwRt
<< "\n"
308 << "\tGun Elevation Rate: " << (KINT16
)m_i8GnElvRt
<< "\n";
313 //////////////////////////////////////////////////////////////////////////
315 void GED_BasicGroundCombatVehicle::Decode(KDataStream
& stream
) {
316 if (stream
.GetBufferSize() < GED_BASIC_GROUND_COMBAT_VEHICLE_SIZE
)
317 throw KException(__FUNCTION__
, NOT_ENOUGH_DATA_IN_BUFFER
);
319 stream
>> m_ui16EntityID
>> m_i16Offsets
[0] >> m_i16Offsets
[1] >>
320 m_i16Offsets
[2] >> KDIS_STREAM m_EA
>> m_i8Ori
[0] >> m_i8Ori
[1] >>
321 m_i8Ori
[2] >> m_i8Spd
>> m_i8TrrtAz
>> m_i8GnElv
>> m_i8TrrtSlwRt
>>
325 //////////////////////////////////////////////////////////////////////////
327 KDataStream
GED_BasicGroundCombatVehicle::Encode() const {
330 GED_BasicGroundCombatVehicle::Encode(stream
);
335 //////////////////////////////////////////////////////////////////////////
337 void GED_BasicGroundCombatVehicle::Encode(KDataStream
& stream
) const {
338 stream
<< m_ui16EntityID
<< m_i16Offsets
[0] << m_i16Offsets
[1]
339 << m_i16Offsets
[2] << KDIS_STREAM m_EA
<< m_i8Ori
[0] << m_i8Ori
[1]
340 << m_i8Ori
[2] << m_i8Spd
<< m_i8TrrtAz
<< m_i8GnElv
<< m_i8TrrtSlwRt
344 //////////////////////////////////////////////////////////////////////////
346 KBOOL
GED_BasicGroundCombatVehicle::operator==(
347 const GED_BasicGroundCombatVehicle
& Value
) const {
348 if (m_ui16EntityID
!= Value
.m_ui16EntityID
) return false;
349 if (m_i16Offsets
[0] != Value
.m_i16Offsets
[0]) return false;
350 if (m_i16Offsets
[1] != Value
.m_i16Offsets
[1]) return false;
351 if (m_i16Offsets
[2] != Value
.m_i16Offsets
[2]) return false;
352 if (m_EA
!= Value
.m_EA
) return false;
353 if (m_i8Ori
[0] != Value
.m_i8Ori
[0]) return false;
354 if (m_i8Ori
[1] != Value
.m_i8Ori
[1]) return false;
355 if (m_i8Ori
[2] != Value
.m_i8Ori
[2]) return false;
356 if (m_i8Spd
!= Value
.m_i8Spd
) return false;
357 if (m_i8TrrtAz
!= Value
.m_i8TrrtAz
) return false;
358 if (m_i8GnElv
!= Value
.m_i8GnElv
) return false;
359 if (m_i8TrrtSlwRt
!= Value
.m_i8TrrtSlwRt
) return false;
360 if (m_i8GnElvRt
!= Value
.m_i8GnElvRt
) return false;
364 //////////////////////////////////////////////////////////////////////////
366 KBOOL
GED_BasicGroundCombatVehicle::operator!=(
367 const GED_BasicGroundCombatVehicle
& Value
) const {
368 return !(*this == Value
);
371 //////////////////////////////////////////////////////////////////////////