Merge pull request #5 from intothevoid/master
[KDIS.git] / KDIS / KDIS / DataTypes / GED_BasicGroundCombatVehicle.cpp
blob42194abb5e1c15b5da86621e8a5c5ceb994ba2a0
1 /*********************************************************************
2 Copyright 2013 Karl Jones
3 All rights reserved.
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
26 Karljj1@yahoo.com
27 http://p.sf.net/kdis/UserGuide
28 *********************************************************************/
30 #include "./GED_BasicGroundCombatVehicle.h"
32 using namespace KDIS;
33 using namespace DATA_TYPE;
34 using namespace ENUMS;
35 using namespace UTILS;
37 //////////////////////////////////////////////////////////////////////////
38 // Public:
39 //////////////////////////////////////////////////////////////////////////
41 GED_BasicGroundCombatVehicle::GED_BasicGroundCombatVehicle() :
42 m_ui16EntityID( 0 ),
43 m_i8Spd( 0 ),
44 m_i8TrrtAz( 0 ),
45 m_i8GnElv( 0 ),
46 m_i8TrrtSlwRt( 0 ),
47 m_i8GnElvRt( 0 )
49 for( KINT8 i = 0; i < 3; ++i )
51 m_i16Offsets[i] = 0;
52 m_i8Ori[i] = 0;
56 //////////////////////////////////////////////////////////////////////////
58 GED_BasicGroundCombatVehicle::GED_BasicGroundCombatVehicle( KDataStream & stream )
60 Decode( stream );
63 //////////////////////////////////////////////////////////////////////////
65 GED_BasicGroundCombatVehicle::GED_BasicGroundCombatVehicle( KUINT16 ID, KINT16 XOffset, KINT16 YOffset, KINT16 ZOffset, const EntityAppearance & EA,
66 KINT8 Psi, KINT8 Theta, KINT8 Phi, KINT8 Speed, KINT8 TurretAzimuth, KINT8 GunElevation,
67 KINT8 TurretSlewRate, KINT8 GunElevationRate ) :
68 m_ui16EntityID( ID ),
69 m_EA( EA ),
70 m_i8Spd( Speed ),
71 m_i8TrrtAz( TurretAzimuth ),
72 m_i8GnElv( GunElevation ),
73 m_i8TrrtSlwRt( TurretSlewRate ),
74 m_i8GnElvRt( GunElevationRate )
76 m_i16Offsets[0] = XOffset;
77 m_i16Offsets[1] = YOffset;
78 m_i16Offsets[2] = ZOffset;
79 m_i8Ori[0] = Psi;
80 m_i8Ori[1] = Theta;
81 m_i8Ori[2] = Phi;
84 //////////////////////////////////////////////////////////////////////////
86 GED_BasicGroundCombatVehicle::~GED_BasicGroundCombatVehicle()
90 //////////////////////////////////////////////////////////////////////////
92 GroupedEntityCategory GED_BasicGroundCombatVehicle::GetGroupedEntityCategory() const
94 return BasicGroundCombatVehicleGEC;
97 //////////////////////////////////////////////////////////////////////////
99 KUINT8 GED_BasicGroundCombatVehicle::GetLength() const
101 return GED_BASIC_GROUND_COMBAT_VEHICLE_SIZE;
104 //////////////////////////////////////////////////////////////////////////
106 void GED_BasicGroundCombatVehicle::SetEntityID( KUINT16 ID )
108 m_ui16EntityID = ID;
111 //////////////////////////////////////////////////////////////////////////
113 KUINT16 GED_BasicGroundCombatVehicle::GetEntityID() const
115 return m_ui16EntityID;
118 //////////////////////////////////////////////////////////////////////////
120 void GED_BasicGroundCombatVehicle::SetEntityLocation( KINT16 XOffset, KINT16 YOffset, KINT16 ZOffset )
122 m_i16Offsets[0] = XOffset;
123 m_i16Offsets[1] = YOffset;
124 m_i16Offsets[2] = ZOffset;
127 //////////////////////////////////////////////////////////////////////////
129 void GED_BasicGroundCombatVehicle::SetEntityLocation( KINT16 Offsets[3] )
131 for( KUINT8 i = 0; i < 3; ++i )
133 m_i16Offsets[i] = Offsets[i];
137 //////////////////////////////////////////////////////////////////////////
139 void GED_BasicGroundCombatVehicle::SetEntityLocationXOffset( KINT16 X )
141 m_i16Offsets[0] = X;
144 //////////////////////////////////////////////////////////////////////////
146 void GED_BasicGroundCombatVehicle::SetEntityLocationYOffset( KINT16 Y )
148 m_i16Offsets[1] = Y;
151 //////////////////////////////////////////////////////////////////////////
153 void GED_BasicGroundCombatVehicle::SetEntityLocationZOffset( KINT16 Z )
155 m_i16Offsets[2] = Z;
158 //////////////////////////////////////////////////////////////////////////
160 KINT16 GED_BasicGroundCombatVehicle::GetEntityLocationXOffset() const
162 return m_i16Offsets[0];
165 //////////////////////////////////////////////////////////////////////////
167 KINT16 GED_BasicGroundCombatVehicle::GetEntityLocationYOffset() const
169 return m_i16Offsets[1];
172 //////////////////////////////////////////////////////////////////////////
174 KINT16 GED_BasicGroundCombatVehicle::GetEntityLocationZOffset() const
176 return m_i16Offsets[2];
179 //////////////////////////////////////////////////////////////////////////
181 void GED_BasicGroundCombatVehicle::SetEntityAppearance( const EntityAppearance & EA )
183 m_EA = EA;
186 //////////////////////////////////////////////////////////////////////////
188 const EntityAppearance & GED_BasicGroundCombatVehicle::GetEntityAppearance() const
190 return m_EA;
193 //////////////////////////////////////////////////////////////////////////
195 EntityAppearance & GED_BasicGroundCombatVehicle::GetEntityAppearance()
197 return m_EA;
200 //////////////////////////////////////////////////////////////////////////
202 void GED_BasicGroundCombatVehicle::SetEntityOrientation( KINT8 Psi, KINT8 Theta, KINT8 Phi )
204 m_i8Ori[0] = Psi;
205 m_i8Ori[1] = Theta;
206 m_i8Ori[2] = Phi;
209 //////////////////////////////////////////////////////////////////////////
211 void GED_BasicGroundCombatVehicle::SetEntityOrientation( KINT8 Ori[3] )
213 for( KINT8 i = 0; i < 3; ++i )
215 m_i8Ori[i] = Ori[i];
219 //////////////////////////////////////////////////////////////////////////
221 void GED_BasicGroundCombatVehicle::SetEntityOrientationPsi( KINT8 P )
223 m_i8Ori[0] = P;
226 //////////////////////////////////////////////////////////////////////////
228 void GED_BasicGroundCombatVehicle::SetEntityOrientationTheta( KINT8 T )
230 m_i8Ori[1] = T;
233 //////////////////////////////////////////////////////////////////////////
235 void GED_BasicGroundCombatVehicle::SetEntityOrientationPhi( KINT8 P )
237 m_i8Ori[2] = P;
240 //////////////////////////////////////////////////////////////////////////
242 KINT8 GED_BasicGroundCombatVehicle::GetEntityOrientationPsi() const
244 return m_i8Ori[0];
247 //////////////////////////////////////////////////////////////////////////
249 KINT8 GED_BasicGroundCombatVehicle::GetEntityOrientationTheta() const
251 return m_i8Ori[1];
254 //////////////////////////////////////////////////////////////////////////
256 KINT8 GED_BasicGroundCombatVehicle::GetEntityOrientationPhi() const
258 return m_i8Ori[2];
261 //////////////////////////////////////////////////////////////////////////
263 void GED_BasicGroundCombatVehicle::SetSpeed( KINT8 S )
265 m_i8Spd = S;
268 //////////////////////////////////////////////////////////////////////////
270 KINT8 GED_BasicGroundCombatVehicle::GetSpeed() const
272 return m_i8Spd;
275 //////////////////////////////////////////////////////////////////////////
277 void GED_BasicGroundCombatVehicle::SetTurretAzimuth( KINT8 T )
279 m_i8TrrtAz = T;
282 //////////////////////////////////////////////////////////////////////////
284 KINT8 GED_BasicGroundCombatVehicle::GetTurretAzimuth() const
286 return m_i8TrrtAz;
289 //////////////////////////////////////////////////////////////////////////
291 void GED_BasicGroundCombatVehicle::SetGunElevation( KINT8 G )
293 m_i8GnElv = G;
296 //////////////////////////////////////////////////////////////////////////
298 KINT8 GED_BasicGroundCombatVehicle::GetGunElevation() const
300 return m_i8GnElv;
303 //////////////////////////////////////////////////////////////////////////
305 void GED_BasicGroundCombatVehicle::SetTurretSlewRate( KINT8 T )
307 m_i8TrrtSlwRt = T;
310 //////////////////////////////////////////////////////////////////////////
312 KINT8 GED_BasicGroundCombatVehicle::GetTurretSlewRate() const
314 return m_i8TrrtSlwRt;
317 //////////////////////////////////////////////////////////////////////////
319 void GED_BasicGroundCombatVehicle::SetGunElevationRate( KINT8 G )
321 m_i8GnElvRt = G;
324 //////////////////////////////////////////////////////////////////////////
326 KINT8 GED_BasicGroundCombatVehicle::GetGunElevationRate() const
328 return m_i8GnElvRt;
331 //////////////////////////////////////////////////////////////////////////
333 KString GED_BasicGroundCombatVehicle::GetAsString() const
335 KStringStream ss;
337 ss << "GED Basic Ground Combat Vehicle\n"
338 << "\tEntity ID: " << m_ui16EntityID << "\n"
339 << "\tLocation Offsets(x,y,z): " << m_i16Offsets[0] << " " << m_i16Offsets[1] << " " << m_i16Offsets[2] << "\n"
340 << IndentString( m_EA.GetAsString( EntityType( Platform, Land, 0, 0, 0, 0, 0 ) ), 1 )
341 << "\tOrientation(Psi,Theta,Phi): " << ( KINT16 )m_i8Ori[0] << " " << ( KINT16 )m_i8Ori[1] << " " << ( KINT16 )m_i8Ori[2] << "\n"
342 << "\tSpeed: " << ( KINT16 )m_i8Spd << "m/s\n"
343 << "\tTurret Azimuth: " << ( KINT16 )m_i8TrrtAz << "\n"
344 << "\tGun Elevation: " << ( KINT16 )m_i8GnElv << "\n"
345 << "\tTurret Slew Rate: " << ( KINT16 )m_i8TrrtSlwRt << "\n"
346 << "\tGun Elevation Rate: " << ( KINT16 )m_i8GnElvRt << "\n";
348 return ss.str();
351 //////////////////////////////////////////////////////////////////////////
353 void GED_BasicGroundCombatVehicle::Decode( KDataStream & stream )
355 if( stream.GetBufferSize() < GED_BASIC_GROUND_COMBAT_VEHICLE_SIZE )throw KException( __FUNCTION__, NOT_ENOUGH_DATA_IN_BUFFER );
357 stream >> m_ui16EntityID
358 >> m_i16Offsets[0]
359 >> m_i16Offsets[1]
360 >> m_i16Offsets[2]
361 >> KDIS_STREAM m_EA
362 >> m_i8Ori[0]
363 >> m_i8Ori[1]
364 >> m_i8Ori[2]
365 >> m_i8Spd
366 >> m_i8TrrtAz
367 >> m_i8GnElv
368 >> m_i8TrrtSlwRt
369 >> m_i8GnElvRt;
372 //////////////////////////////////////////////////////////////////////////
374 KDataStream GED_BasicGroundCombatVehicle::Encode() const
376 KDataStream stream;
378 GED_BasicGroundCombatVehicle::Encode( stream );
380 return stream;
383 //////////////////////////////////////////////////////////////////////////
385 void GED_BasicGroundCombatVehicle::Encode( KDataStream & stream ) const
387 stream << m_ui16EntityID
388 << m_i16Offsets[0]
389 << m_i16Offsets[1]
390 << m_i16Offsets[2]
391 << KDIS_STREAM m_EA
392 << m_i8Ori[0]
393 << m_i8Ori[1]
394 << m_i8Ori[2]
395 << m_i8Spd
396 << m_i8TrrtAz
397 << m_i8GnElv
398 << m_i8TrrtSlwRt
399 << m_i8GnElvRt;
402 //////////////////////////////////////////////////////////////////////////
404 KBOOL GED_BasicGroundCombatVehicle::operator == ( const GED_BasicGroundCombatVehicle & Value ) const
406 if( m_ui16EntityID != Value.m_ui16EntityID ) return false;
407 if( m_i16Offsets[0] != Value.m_i16Offsets[0] ) return false;
408 if( m_i16Offsets[1] != Value.m_i16Offsets[1] ) return false;
409 if( m_i16Offsets[2] != Value.m_i16Offsets[2] ) return false;
410 if( m_EA != Value.m_EA ) return false;
411 if( m_i8Ori[0] != Value.m_i8Ori[0] ) return false;
412 if( m_i8Ori[1] != Value.m_i8Ori[1] ) return false;
413 if( m_i8Ori[2] != Value.m_i8Ori[2] ) return false;
414 if( m_i8Spd != Value.m_i8Spd ) return false;
415 if( m_i8TrrtAz != Value.m_i8TrrtAz ) return false;
416 if( m_i8GnElv != Value.m_i8GnElv ) return false;
417 if( m_i8TrrtSlwRt != Value.m_i8TrrtSlwRt ) return false;
418 if( m_i8GnElvRt != Value.m_i8GnElvRt ) return false;
419 return true;
422 //////////////////////////////////////////////////////////////////////////
424 KBOOL GED_BasicGroundCombatVehicle::operator != ( const GED_BasicGroundCombatVehicle & Value ) const
426 return !( *this == Value );
429 //////////////////////////////////////////////////////////////////////////