Merge pull request #5 from intothevoid/master
[KDIS.git] / KDIS / KDIS / PDU / Live_Entity / LE_Detonation_PDU.h
blob8b4136515b0e4d693ed3a2c9f52f157270972a68
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 /********************************************************************
31 class: LE_Detonation_PDU
32 DIS: (6) 1278.1a - 1998
33 created: 23/08/2010
34 author: Karl Jones
36 purpose: Communicates the detonation or impact of munitions.
37 size: 320 bits / 40 octets - Min size
38 *********************************************************************/
40 #pragma once
42 #include "./LE_Header.h"
43 #include "./../../DataTypes/WorldCoordinates.h"
44 #include "./../../DataTypes/RelativeWorldCoordinates.h"
45 #include "./../../DataTypes/LE_Vector.h"
46 #include "./../../DataTypes/LE_EulerAngles.h"
47 #include "./../../DataTypes/MunitionDescriptor.h"
49 namespace KDIS {
50 namespace PDU {
52 class KDIS_EXPORT LE_Detonation_PDU : public LE_Header
54 protected:
56 union
58 struct
60 KUINT8 m_ui8TargetId : 1; // F0 : 0 = Target Entity ID field is not included
61 // 1 = Target Entity ID field is included
62 KUINT8 m_ui8MunitionSiteApp : 1; // F1 : 0 = Site Number and Application Number data are the same as the firing
63 // entity’s and are not included in the Munition ID
64 // 1 = Site Number and Application Number fields are included in the Munition ID
65 KUINT8 m_ui8MunitionId : 1; // F2 : 0 = Munition ID field is not included
66 // 1 = Munition ID field is included
67 KUINT8 m_ui8EventSiteAppId : 1; // F3 : 0 = Site Number and Application Number data are the same as the firing
68 // entity’s and are not included in the Event ID
69 // 1 = Site Number and Application Number fields are included in the Event ID
70 KUINT8 m_ui8WarheadFuse : 1; // F4 : 0 = Warhead and Fuse fields of the Munition Descriptor record are not
71 // included (use munition default)
72 // 1 = Warhead and Fuse fields of the Munition Descriptor record are present
73 KUINT8 m_ui8QuantRate : 1; // F5 : 0 = Quantity and Rate fields of the Munition Descriptor record are not
74 // included
75 // 1 = Quantity and Rate fields of the Munition Descriptor record are included
76 KUINT8 m_ui8LocationTyp : 1; // F6 : 0 = Location in Entity Coordinates field is not included; Location in
77 // Relative World Coordinates field is included
78 // 1 = Location in Entity Coordinates field is included; Location in Relative
79 // World Coordinates field is not included
80 KUINT8 m_ui8Flag2 : 1; // F7 : 0 = Flag Octet 2 is not included
81 // 1 = Flag Octet 2 is included
83 KUINT8 m_ui8Flag;
84 } m_DetonationFlag1Union;
86 union
88 struct
90 KUINT8 m_ui8MunitionOri : 1; // G0 : 0 = Munition Orientation field is not included
91 // 1 = Munition Orientation field is included
92 KUINT8 m_ui8EventNum : 1; // G1 : 0 = Event Number field is not included in Event ID
93 // 1 = Event Number field is included in Event ID
94 KUINT8 m_ui8Unused : 5;
95 KUINT8 m_ui8Reserved : 1;
97 KUINT8 m_ui8Flag;
98 } m_DetonationFlag2Union;
100 KDIS::DATA_TYPE::LE_EntityIdentifier m_TargetID;
102 KDIS::DATA_TYPE::LE_EntityIdentifier m_MunitionID;
104 KDIS::DATA_TYPE::LE_EntityIdentifier m_EventID;
106 KDIS::DATA_TYPE::LE_Vector16_3 m_LocEntCoord;
107 KDIS::DATA_TYPE::RelativeWorldCoordinates m_LocWrldCoord;
109 KDIS::DATA_TYPE::LE_Vector16_3 m_Vel;
111 KDIS::DATA_TYPE::LE_EulerAngles m_Ori;
113 KDIS::DATA_TYPE::MunitionDescriptor m_MunitionDesc;
115 KUINT8 m_ui8DetonationResult;
117 //************************************
118 // FullName: KDIS::PDU::LE_Detonation_PDU::checkFlagsAndPDULength
119 // Description: Checks the site and application values to see if we need to include them during
120 // encoding. The values are set when the set id functions are called however it is
121 // possible that a change may have occurred since, I.E by calling the GetID function
122 // and setting through it.
123 //************************************
124 void checkFlagsAndPDULength();
126 public:
128 static const KUINT16 LE_DETONATION_PDU_SIZE = 40; // Min size, not including optional fields
130 LE_Detonation_PDU();
132 LE_Detonation_PDU( KDataStream & stream ) ;
134 LE_Detonation_PDU( const Header & H, KDataStream & stream ) ;
136 LE_Detonation_PDU( const KDIS::DATA_TYPE::LE_EntityIdentifier & ID );
138 virtual ~LE_Detonation_PDU();
140 //************************************
141 // FullName: KDIS::PDU::LE_Detonation_PDU::SetTargetEntityIDFlag
142 // KDIS::PDU::LE_Detonation_PDU::GetTargetEntityIDFlag
143 // KDIS::PDU::LE_Detonation_PDU::SetMunitionEntityIDFlag
144 // KDIS::PDU::LE_Detonation_PDU::GetMunitionEntityIDFlag
145 // KDIS::PDU::LE_Detonation_PDU::SetMunitionEntityIDSiteAppIncludedFlag
146 // KDIS::PDU::LE_Detonation_PDU::GetMunitionEntityIDSiteAppIncludedFlag
147 // KDIS::PDU::LE_Detonation_PDU::SetEventIDSiteAppIncludedFlag
148 // KDIS::PDU::LE_Detonation_PDU::GetEventIDSiteAppIncludedFlag
149 // KDIS::PDU::LE_Detonation_PDU::SetWarheadFuseFlag
150 // KDIS::PDU::LE_Detonation_PDU::GetWarheadFuseFlag
151 // KDIS::PDU::LE_Detonation_PDU::SetQuantityRateFlag
152 // KDIS::PDU::LE_Detonation_PDU::GetQuantityRateFlag
153 // KDIS::PDU::LE_Detonation_PDU::SetLocationInEntityCoordinatesFlag
154 // KDIS::PDU::LE_Detonation_PDU::GetLocationInEntityCoordinatesFlag
155 // Description: Identifies optional data fields that are being transmitted with
156 // this PDU.
157 // Notes:
158 // TargetEntityIDFlag - If the value is true then the location must be
159 // specified using WorldCoordinates otherwise use RelativeWorldCoordinates.
160 // LocationInEntityCoordinatesFlag - If the value is true the location class is
161 // in WorldCoordinates otherwise the location is in RelativeWorldCoordinates.
162 // Parameter: KBOOL F
163 //************************************
164 void SetTargetEntityIDFlag( KBOOL F );
165 KBOOL GetTargetEntityIDFlag() const;
166 void SetMunitionEntityIDFlag( KBOOL F );
167 KBOOL GetMunitionEntityIDFlag() const;
168 void SetMunitionEntityIDSiteAppIncludedFlag( KBOOL F );
169 KBOOL GetMunitionEntityIDSiteAppIncludedFlag() const;
170 void SetEventIDSiteAppIncludedFlag( KBOOL F );
171 KBOOL GetEventIDSiteAppIncludedFlag() const;
172 void SetWarheadFuseFlag( KBOOL F );
173 KBOOL GetWarheadFuseFlag() const;
174 void SetQuantityRateFlag( KBOOL F );
175 KBOOL GetQuantityRateFlag() const;
176 void SetLocationInEntityCoordinatesFlag( KBOOL F );
177 KBOOL GetLocationInEntityCoordinatesFlag() const;
178 void SetFlag2Flag( KBOOL F );
179 KBOOL GetFlag2Flag() const;
180 void SetMunitionOrientationFlag( KBOOL F );
181 KBOOL GetMunitionOrientationFlag() const;
182 void SetEventNumberIncludedFlag( KBOOL F );
183 KBOOL GetEventNumberIncludedFlag() const;
185 //************************************
186 // FullName: KDIS::PDU::LE_Detonation_PDU::SetTargetEntityID
187 // KDIS::PDU::LE_Detonation_PDU::GetTargetEntityID
188 // Description: Optional field.The intended target. If the intended target is unknown, this field
189 // shall not be included in the PDU.
190 // Note: Setting this value will also cause the relevant flag to be set to true.
191 // Parameter: const LE_EntityIdentifier & ID
192 //************************************
193 void SetTargetEntityID( const KDIS::DATA_TYPE::LE_EntityIdentifier & ID );
194 const KDIS::DATA_TYPE::LE_EntityIdentifier & GetTargetEntityID() const;
195 KDIS::DATA_TYPE::LE_EntityIdentifier & GetTargetEntityID();
197 //************************************
198 // FullName: KDIS::PDU::LE_Detonation_PDU::SetMunitionEntityID
199 // KDIS::PDU::LE_Detonation_PDU::GetMunitionEntityID
200 // Description: Optional field. Identifies the fired munition if tracking data is required.
201 // If tracking data for the munition are not required, this field
202 // shall not be included in the PDU.
203 // If the Site Number and Application Number fields are the same as
204 // those in the Firing Entity ID, they shall not be included;
205 // and the associated Flag field bit will be set to zero.
206 // Note: Setting this value will also cause the relevant flags to be set to true.
207 // Parameter: const LE_EntityIdentifier & ID
208 //************************************
209 void SetMunitionEntityID( const KDIS::DATA_TYPE::LE_EntityIdentifier & ID );
210 const KDIS::DATA_TYPE::LE_EntityIdentifier & GetMunitionEntityID() const;
211 KDIS::DATA_TYPE::LE_EntityIdentifier & GetMunitionEntityID();
213 //************************************
214 // FullName: KDIS::PDU::LE_Detonation_PDU::SetEventID
215 // KDIS::PDU::LE_Detonation_PDU::GetEventID
216 // Description: Optional field. Should contain the same data as in the Event ID field of the
217 // LE Fire PDU that communicated the launch of the munition.
218 // If the detonation is not preceded by a corresponding fire event, then the
219 // Event ID field shall not be included in the current PDU.
220 // If the Site Number and Application Number fields are the same as those in the
221 // Firing Entity ID, they shall not be included.
222 // Note: Setting this value will also cause the relevant flags to be set to true.
223 // A check is automatically made when encoding to see if the site/app fields match the
224 // firing entity and the relevant flags are set accordingly.
225 // Parameter: const LE_EntityIdentifier & ID
226 //************************************
227 void SetEventID( const KDIS::DATA_TYPE::LE_EntityIdentifier & ID );
228 const KDIS::DATA_TYPE::LE_EntityIdentifier & GetEventID() const;
229 KDIS::DATA_TYPE::LE_EntityIdentifier & GetEventID();
231 //************************************
232 // FullName: KDIS::PDU::LE_Detonation_PDU::SetLocation
233 // KDIS::PDU::LE_Detonation_PDU::SetLocationEntityCoordinates
234 // KDIS::PDU::LE_Detonation_PDU::GetLocationEntityCoordinates
235 // KDIS::PDU::LE_Detonation_PDU::SetLocationWorldCoordinates
236 // KDIS::PDU::LE_Detonation_PDU::GetLocationWorldCoordinates
237 // Description: The location of the detonation.
238 // If the Target ID field is included the location will be in EntityCoordinates(LE_Vector16_3),
239 // This information should be used for damage assessment.
240 // If the Target ID field is not included then this field will be in WorldCoordinates.
241 // Note: Setting this value will also cause the relevant flag to be set correctly.
242 // Parameter: const LE_Vector16_3 & L, const RelativeWorldCoordinates & L
243 //************************************
244 void SetLocation( const KDIS::DATA_TYPE::LE_Vector16_3 & L );
245 void SetLocation( const KDIS::DATA_TYPE::RelativeWorldCoordinates & L );
246 void SetLocationEntityCoordinates( const KDIS::DATA_TYPE::LE_Vector16_3 & L );
247 const KDIS::DATA_TYPE::LE_Vector16_3 & GetLocationEntityCoordinates() const;
248 KDIS::DATA_TYPE::LE_Vector16_3 & GetLocationEntityCoordinates();
249 void SetLocationWorldCoordinates( const KDIS::DATA_TYPE::RelativeWorldCoordinates & L );
250 const KDIS::DATA_TYPE::RelativeWorldCoordinates & GetLocationWorldCoordinates() const;
251 KDIS::DATA_TYPE::RelativeWorldCoordinates & GetLocationWorldCoordinates();
253 //************************************
254 // FullName: KDIS::PDU::LE_Detonation_PDU::SetVelocity
255 // KDIS::PDU::LE_Detonation_PDU::GetVelocity
256 // Description: The velocity of the munition immediately before
257 // detonation/impact in decimeters per second.
258 // Parameter: const LE_Vector16_3 & V
259 //************************************
260 void SetVelocity( const KDIS::DATA_TYPE::LE_Vector16_3 & V );
261 const KDIS::DATA_TYPE::LE_Vector16_3 & GetVelocity() const;
262 KDIS::DATA_TYPE::LE_Vector16_3 & GetVelocity();
264 //************************************
265 // FullName: KDIS::PDU::LE_Detonation_PDU::SetMunitionOrientation
266 // KDIS::PDU::LE_Detonation_PDU::GetMunitionOrientation
267 // Description: Optional field. Orientation of the munition in entity based
268 // coordinates at the time of detonation.
269 // Note: Setting this value will also cause the relevant flag to be set to true.
270 // Parameter: const LE_EulerAngles & O
271 //************************************
272 void SetMunitionOrientation( const KDIS::DATA_TYPE::LE_EulerAngles & O );
273 const KDIS::DATA_TYPE::LE_EulerAngles & GetMunitionOrientation() const;
274 KDIS::DATA_TYPE::LE_EulerAngles & GetMunitionOrientation();
276 //************************************
277 // FullName: KDIS::PDU::LE_Detonation_PDU::SetMunitionDescriptor
278 // KDIS::PDU::LE_Detonation_PDU::GetMunitionDescriptor
279 // Description: Describes the type of munition fired, warhead, fuse, quantity,
280 // and rate. The warhead, fuse, quantity, and rate fields of this record
281 // are optional. If you wish to have them included then the relevant flag field must be set:
282 // void SetWarheadFuseFlag( true ) - To include Warhead and fuse fields.
283 // void SetQuantityRateFlag( true ) - To include Quantity and Rate fields.
284 // This field is also known as the BurstDescriptor in older versions of the DIS standard.
285 // Parameter: const MunitionDescriptor & MD
286 //************************************
287 void SetMunitionDescriptor( const KDIS::DATA_TYPE::MunitionDescriptor & MD );
288 const KDIS::DATA_TYPE::MunitionDescriptor & GetMunitionDescriptor() const;
289 KDIS::DATA_TYPE::MunitionDescriptor & GetMunitionDescriptor();
291 //************************************
292 // FullName: KDIS::PDU::LE_Detonation_PDU::SetDetonationResult
293 // KDIS::PDU::LE_Detonation_PDU::GetDetonationResult
294 // Description: Represents the result of the detonation.
295 // Parameter: DetonationResult DR
296 //************************************
297 void SetDetonationResult( KDIS::DATA_TYPE::ENUMS::DetonationResult DR );
298 KDIS::DATA_TYPE::ENUMS::DetonationResult GetDetonationResult() const;
300 //************************************
301 // FullName: KDIS::PDU::LE_Detonation_PDU::GetAsString
302 // Description: Returns a string representation of the PDU
303 //************************************
304 virtual KString GetAsString() const;
306 //************************************
307 // FullName: KDIS::PDU::LE_Detonation_PDU::Decode
308 // Description: Convert From Network Data.
309 // Parameter: KDataStream & stream
310 // Parameter: bool ignoreHeader = false - Decode the header from the stream?
311 //************************************
312 virtual void Decode( KDataStream & stream, bool ignoreHeader = false ) ;
314 //************************************
315 // FullName: KDIS::PDU::LE_Detonation_PDU::Encode
316 // Description: Convert To Network Data.
317 // Parameter: KDataStream & stream
318 //************************************
319 virtual KDataStream Encode() const;
320 virtual void Encode( KDataStream & stream ) const;
322 KBOOL operator == ( const LE_Detonation_PDU & Value ) const;
323 KBOOL operator != ( const LE_Detonation_PDU & Value ) const;
326 } // END namespace PDU
327 } // END namespace KDIS