Merge pull request #5 from intothevoid/master
[KDIS.git] / KDIS / KDIS / DataTypes / GED_GroundLogisticsVehicle.cpp
blob612eb37a7def05b19ea94f9819d311db745a7e75
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_GroundLogisticsVehicle.h"
32 using namespace KDIS;
33 using namespace DATA_TYPE;
34 using namespace ENUMS;
35 using namespace UTILS;
37 //////////////////////////////////////////////////////////////////////////
38 // Public:
39 //////////////////////////////////////////////////////////////////////////
41 GED_GroundLogisticsVehicle::GED_GroundLogisticsVehicle() :
42 m_ui16EntityID( 0 ),
43 m_i8Spd( 0 )
45 for( KINT8 i = 0; i < 3; ++i )
47 m_i16Offsets[i] = 0;
48 m_i8Ori[i] = 0;
52 //////////////////////////////////////////////////////////////////////////
54 GED_GroundLogisticsVehicle::GED_GroundLogisticsVehicle( KDataStream & stream )
56 Decode( stream );
59 //////////////////////////////////////////////////////////////////////////
61 GED_GroundLogisticsVehicle::GED_GroundLogisticsVehicle( KUINT16 ID, KINT16 XOffset, KINT16 YOffset, KINT16 ZOffset, const EntityAppearance & EA, KINT8 Psi, KINT8 Theta,
62 KINT8 Phi, KINT8 Speed ) :
63 m_ui16EntityID( ID ),
64 m_EA( EA ),
65 m_i8Spd( Speed )
67 m_i16Offsets[0] = XOffset;
68 m_i16Offsets[1] = YOffset;
69 m_i16Offsets[2] = ZOffset;
70 m_i8Ori[0] = Psi;
71 m_i8Ori[1] = Theta;
72 m_i8Ori[2] = Phi;
75 //////////////////////////////////////////////////////////////////////////
77 GED_GroundLogisticsVehicle::~GED_GroundLogisticsVehicle()
81 //////////////////////////////////////////////////////////////////////////
83 GroupedEntityCategory GED_GroundLogisticsVehicle::GetGroupedEntityCategory() const
85 return BasicFixedWingAircraftGEC;
88 //////////////////////////////////////////////////////////////////////////
90 KUINT8 GED_GroundLogisticsVehicle::GetLength() const
92 return GED_GROUND_LOGISTICS_VEHICLE_SIZE;
95 //////////////////////////////////////////////////////////////////////////
97 void GED_GroundLogisticsVehicle::SetEntityID( KUINT16 ID )
99 m_ui16EntityID = ID;
102 //////////////////////////////////////////////////////////////////////////
104 KUINT16 GED_GroundLogisticsVehicle::GetEntityID() const
106 return m_ui16EntityID;
109 //////////////////////////////////////////////////////////////////////////
111 void GED_GroundLogisticsVehicle::SetEntityLocation( KINT16 XOffset, KINT16 YOffset, KINT16 ZOffset )
113 m_i16Offsets[0] = XOffset;
114 m_i16Offsets[1] = YOffset;
115 m_i16Offsets[2] = ZOffset;
118 //////////////////////////////////////////////////////////////////////////
120 void GED_GroundLogisticsVehicle::SetEntityLocation( KINT16 Offsets[3] )
122 for( KUINT8 i = 0; i < 3; ++i )
124 m_i16Offsets[i] = Offsets[i];
128 //////////////////////////////////////////////////////////////////////////
130 void GED_GroundLogisticsVehicle::SetEntityLocationXOffset( KINT16 X )
132 m_i16Offsets[0] = X;
135 //////////////////////////////////////////////////////////////////////////
137 void GED_GroundLogisticsVehicle::SetEntityLocationYOffset( KINT16 Y )
139 m_i16Offsets[1] = Y;
142 //////////////////////////////////////////////////////////////////////////
144 void GED_GroundLogisticsVehicle::SetEntityLocationZOffset( KINT16 Z )
146 m_i16Offsets[2] = Z;
149 //////////////////////////////////////////////////////////////////////////
151 KINT16 GED_GroundLogisticsVehicle::GetEntityLocationXOffset() const
153 return m_i16Offsets[0];
156 //////////////////////////////////////////////////////////////////////////
158 KINT16 GED_GroundLogisticsVehicle::GetEntityLocationYOffset() const
160 return m_i16Offsets[1];
163 //////////////////////////////////////////////////////////////////////////
165 KINT16 GED_GroundLogisticsVehicle::GetEntityLocationZOffset() const
167 return m_i16Offsets[2];
170 //////////////////////////////////////////////////////////////////////////
172 void GED_GroundLogisticsVehicle::SetEntityAppearance( const EntityAppearance & EA )
174 m_EA = EA;
177 //////////////////////////////////////////////////////////////////////////
179 const EntityAppearance & GED_GroundLogisticsVehicle::GetEntityAppearance() const
181 return m_EA;
184 //////////////////////////////////////////////////////////////////////////
186 EntityAppearance & GED_GroundLogisticsVehicle::GetEntityAppearance()
188 return m_EA;
191 //////////////////////////////////////////////////////////////////////////
193 void GED_GroundLogisticsVehicle::SetEntityOrientation( KINT8 Psi, KINT8 Theta, KINT8 Phi )
195 m_i8Ori[0] = Psi;
196 m_i8Ori[1] = Theta;
197 m_i8Ori[2] = Phi;
200 //////////////////////////////////////////////////////////////////////////
202 void GED_GroundLogisticsVehicle::SetEntityOrientation( KINT8 Ori[3] )
204 for( KINT8 i = 0; i < 3; ++i )
206 m_i8Ori[i] = Ori[i];
210 //////////////////////////////////////////////////////////////////////////
212 void GED_GroundLogisticsVehicle::SetEntityOrientationPsi( KINT8 P )
214 m_i8Ori[0] = P;
217 //////////////////////////////////////////////////////////////////////////
219 void GED_GroundLogisticsVehicle::SetEntityOrientationTheta( KINT8 T )
221 m_i8Ori[1] = T;
224 //////////////////////////////////////////////////////////////////////////
226 void GED_GroundLogisticsVehicle::SetEntityOrientationPhi( KINT8 P )
228 m_i8Ori[2] = P;
231 //////////////////////////////////////////////////////////////////////////
233 KINT8 GED_GroundLogisticsVehicle::GetEntityOrientationPsi() const
235 return m_i8Ori[0];
238 //////////////////////////////////////////////////////////////////////////
240 KINT8 GED_GroundLogisticsVehicle::GetEntityOrientationTheta() const
242 return m_i8Ori[1];
245 //////////////////////////////////////////////////////////////////////////
247 KINT8 GED_GroundLogisticsVehicle::GetEntityOrientationPhi() const
249 return m_i8Ori[2];
252 //////////////////////////////////////////////////////////////////////////
254 void GED_GroundLogisticsVehicle::SetSpeed( KINT8 S )
256 m_i8Spd = S;
259 //////////////////////////////////////////////////////////////////////////
261 KINT8 GED_GroundLogisticsVehicle::GetSpeed() const
263 return m_i8Spd;
266 //////////////////////////////////////////////////////////////////////////
268 KString GED_GroundLogisticsVehicle::GetAsString() const
270 KStringStream ss;
272 ss << "GED Basic Fixed Wing Aircraft\n"
273 << "\tEntity ID: " << m_ui16EntityID << "\n"
274 << "\tLocation Offsets(x,y,z): " << m_i16Offsets[0] << " " << m_i16Offsets[1] << " " << m_i16Offsets[2] << "\n"
275 << IndentString( m_EA.GetAsString( EntityType( Platform, Air, 0, 0, 0, 0, 0 ) ), 1 )
276 << "\tOrientation(Psi,Theta,Phi): " << ( KINT16 )m_i8Ori[0] << " " << ( KINT16 )m_i8Ori[1] << " " << ( KINT16 )m_i8Ori[2] << "\n"
277 << "\tSpeed: " << ( KINT16 )m_i8Spd << "\n";
279 return ss.str();
282 //////////////////////////////////////////////////////////////////////////
284 void GED_GroundLogisticsVehicle::Decode( KDataStream & stream )
286 if( stream.GetBufferSize() < GED_GROUND_LOGISTICS_VEHICLE_SIZE )throw KException( __FUNCTION__, NOT_ENOUGH_DATA_IN_BUFFER );
288 stream >> m_ui16EntityID
289 >> m_i16Offsets[0]
290 >> m_i16Offsets[1]
291 >> m_i16Offsets[2]
292 >> KDIS_STREAM m_EA
293 >> m_i8Ori[0]
294 >> m_i8Ori[1]
295 >> m_i8Ori[2]
296 >> m_i8Spd;
299 //////////////////////////////////////////////////////////////////////////
301 KDataStream GED_GroundLogisticsVehicle::Encode() const
303 KDataStream stream;
305 GED_GroundLogisticsVehicle::Encode( stream );
307 return stream;
310 //////////////////////////////////////////////////////////////////////////
312 void GED_GroundLogisticsVehicle::Encode( KDataStream & stream ) const
314 stream << m_ui16EntityID
315 << m_i16Offsets[0]
316 << m_i16Offsets[1]
317 << m_i16Offsets[2]
318 << KDIS_STREAM m_EA
319 << m_i8Ori[0]
320 << m_i8Ori[1]
321 << m_i8Ori[2]
322 << m_i8Spd;
325 //////////////////////////////////////////////////////////////////////////
327 KBOOL GED_GroundLogisticsVehicle::operator == ( const GED_GroundLogisticsVehicle & Value ) const
329 if( m_ui16EntityID != Value.m_ui16EntityID ) return false;
330 if( m_i16Offsets[0] != Value.m_i16Offsets[0] ) return false;
331 if( m_i16Offsets[1] != Value.m_i16Offsets[1] ) return false;
332 if( m_i16Offsets[2] != Value.m_i16Offsets[2] ) return false;
333 if( m_EA != Value.m_EA ) return false;
334 if( m_i8Ori[0] != Value.m_i8Ori[0] ) return false;
335 if( m_i8Ori[1] != Value.m_i8Ori[1] ) return false;
336 if( m_i8Ori[2] != Value.m_i8Ori[2] ) return false;
337 if( m_i8Spd != Value.m_i8Spd ) return false;
338 return true;
341 //////////////////////////////////////////////////////////////////////////
343 KBOOL GED_GroundLogisticsVehicle::operator != ( const GED_GroundLogisticsVehicle & Value ) const
345 return !( *this == Value );
348 //////////////////////////////////////////////////////////////////////////