//---------------------------------------------------------- // CONSTRUCTORS //---------------------------------------------------------- public EntityDataManager( string gameType, string marking, LVCGame.UnitForceType force ) { this.lvcUnityAmbassador = LVCUnityAmbassador.GetInstance(); this.lvcClient = lvcUnityAmbassador.GetLVCClient(); // initialise the entity data container which will hold salient details about // the entity state which we want to send in LVC updates entityData = new LVCGame.EntityData(); entityData.id = new LVCGame.EntityID(); entityData.physics = new LVCGame.EntityPhysics(); entityData.properties = new LVCGame.EntityProperties(); entityData.properties.force = force; // assign a unique ID number to this entity entityData.id.instance = lvcUnityAmbassador.GetNextEntityID(); // initialise types and markings entityData.id.gameType = gameType; entityData.id.marking = marking; lvcGameState = LVCGameState.UNINTIALISED; }
private static readonly Color DAMAGE_100 = new Color(0.1F,0.1F,0.1F,1); // 100% damage - charcoal grey #endregion Fields #region Methods //////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////// LVC Game Related Methods ////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////// public void FireWeapon( string lvcMunitionType, UnityEngine.Vector3 origin, UnityEngine.Vector3 velocity, uint quantity, uint rate, LVCGame.WarHeadType warhead, LVCGame.FuseType fuse, long targetId ) { entityDataManager.FireWeapon( lvcMunitionType, origin, velocity, quantity, rate, warhead, fuse, targetId ); }
//------------------------------------------------------------------------------------------ // STANCE //------------------------------------------------------------------------------------------ /** * Set the stance type of the entity * * @param stanceType the stance of the entity */ public void SetStance( LVCGame.StanceType stanceType ) { lock( this ) { this.entityData.properties.stance = stanceType; } }
//------------------------------------------------------------------------------------------ // PRIMARY WEAPON POSTURE //------------------------------------------------------------------------------------------ /** * Set the primary weapon posture of the entity * * @param primaryWeaponPosture the primary weapon posture of the entity */ public void SetPrimaryWeaponPosture( LVCGame.WeaponPostureType primaryWeaponPosture ) { lock( this ) { this.entityData.properties.prWeaponPosture = primaryWeaponPosture; } }
/** * Causes an weapon fire notification to be sent into the LVC Game world. If * Create() has not yet been called, or Destroy() has been called, this will * have no effect. * * @param lvcMunitionType the LVC Game munition type name * @param origin the location from which the munition originated * @param velocity the velocity of the munition * @param quantity (optional) the number of rounds fired in this "burst" (if unspecified, 1 is used) * @param rate (optional) the rate of fire in rounds per minute * @param warhead (optional) the DIS warhead type of the fired munition * @param fuse (optional) the DIS fuse type of the fired munition * @param targetId (optional) the ID of the entity targeted by this munition fire */ public void FireWeapon( string lvcMunitionType, UnityEngine.Vector3 origin, UnityEngine.Vector3 velocity, uint quantity, uint rate, LVCGame.WarHeadType warhead, LVCGame.FuseType fuse, long targetId ) { lock( this ) { if( lvcGameState == LVCGameState.CREATED ) { LVCGame.FireWeaponData fireWeaponData = lvcUnityAmbassador.MakeFireWeaponData( this.entityData.id.instance, lvcMunitionType, origin, velocity, quantity, rate, warhead, fuse, targetId ); this.lvcClient.FireWeapon( ref fireWeaponData ); } } }
//---------------------------------------------------------- // STATIC VARIABLES //---------------------------------------------------------- //---------------------------------------------------------- // INSTANCE VARIABLES //---------------------------------------------------------- //---------------------------------------------------------- // CONSTRUCTORS //---------------------------------------------------------- //---------------------------------------------------------- // INSTANCE METHODS //---------------------------------------------------------- /** * Handle update event data * * @param entityData the LVC update data information * @param gO the Unity GameObject representation of the updated entity */ public abstract void HandleExtra( LVCGame.EntityData entityData, GameObject gO );
/** * Convert an LVC Game Vector3 into a Unity Engine Vector 3, correcting for the swapping * of the Y and Z axes between the coordinate systems * AXIS (+ve): | LVC | UNITY * ------------+-----+------- * NORTH | X | X * EAST | Y | Z * UP | Z | Y * * @param LVCv3 the LVC Game Vector3 to convert * @return the equivalent Unity Engine Vector3, with corrected axes (Y and Z axes swapped) */ public static UnityEngine.Vector3 LVCGameCoords_to_UnityCoords( LVCGame.Vector3 LVCv3 ) { return new UnityEngine.Vector3( (float)LVCv3.x, (float)LVCv3.z, (float)LVCv3.y ); // ^====SWAPPED====^ }
/** * A utility method to convert a latitude/longitude/altitude position representaion * to a local tangent plane representation. Uses the world origin obtained from the * LVC configuration as the primary reference point for the conversion. * * @param lla the latitude/longitude/altitude position to convert. latitude and longitude * are expected to be in radians, altitude is in meters. * @return the local tangent plane coordinates in meters. The axes are as follows: * AXIS (+ve): | LVC * ------------+----- * NORTH | X * EAST | Y * UP | Z */ public static LVCGame.Vector3 llaToLtp( LVCGame.Vector3 lla ) { return LVCGame.LVCCoordinates.llaToLtp( ref v3zero, ref lla ); }
/** * A utility function to create a string using an LVC EntityData struct to display the salient * details of an entity's state * * @param ed the entity data struct to create the string representation from * @return the formatted string */ public static string DisplayFormatted( LVCGame.EntityData ed ) { return "("+ed.id.instance+") "+ed.id.gameType+"["+ed.id.marking+"]"+ DisplayFormatted(ed.physics.position, "")+ DisplayAsDegrees(ed.physics.orientation)+" "+ DisplayAsMs(ed.physics.worldVelocity)+" "+ DisplayAsMs2(ed.physics.worldAcceleration)+" "+ DisplayAsDegreesPerSecond(ed.physics.bodyAngularVelocity)+" "+ ed.properties.stance.ToString(); }
/** * A utility function to create a string using an LVC Vector3 to display the values of the 3 axes * with unit formatting. This is used for logging purposes. * * @param v3 the LVC Vector3 containing the acceleration values for each axis * @param the suffix to display after each value * @return the formatted string */ public static string DisplayFormatted( LVCGame.Vector3 v3, string suffix ) { return "("+v3.x.ToString("f5")+suffix+", "+v3.y.ToString("f5")+suffix+", "+v3.z.ToString("f5")+suffix+")"; }
/** * A utility function to create a string using an LVC Vector3 to display the values of the 3 axes * as metres per second squared (acceleration). This is used for logging purposes. * * @param v3 the LVC Vector3 containing the acceleration values for each axis * @return the formatted string */ public static string DisplayAsMs2( LVCGame.Vector3 v3 ) { return DisplayFormatted( v3,"m/s\u00B2" ); }
/** * A utility function to create a string using an LVC Vector3 to display the values of the 3 axes * as d*m's" (degrees, minutes, seconds). This is used for logging purposes. * * @param v3 the LVC Vector3 containing the acceleration values for each axis * @return the formatted string */ public static string DisplayAsDMS( LVCGame.Vector3 v3 ) { return "("+RadiansToDMS(v3.x, 2)+", "+RadiansToDMS(v3.y, 2)+", "+RadiansToDMS(v3.z,2)+")"; }
/** * A utility function to create a string using an LVC Vector3 to display the values of the 3 axes * as decimal degrees. This is used for logging purposes. * * @param v3 the LVC Vector3 containing the acceleration values for each axis * @return the formatted string */ public static string DisplayAsDegreesPerSecond( LVCGame.Vector3 v3 ) { string suffix = "\u00B0/s"; return "("+Radians2Degrees(v3.x).ToString("f2")+suffix+", "+Radians2Degrees(v3.y).ToString("f2")+suffix+", "+Radians2Degrees(v3.z).ToString("f2")+suffix+")"; }
/** * A utility function to transfer the values from one LVC Vector3 into another LVC Vector3. * * @param source the LVCGame.Vector3 instance which is the source of the values from the source * @param target the LVCGame.Vector3 instance which is to receive the values */ public static void TransferValues( LVCGame.Vector3 source, ref LVCGame.Vector3 target ) { target.x = source.x; target.y = source.y; target.z = source.z; }
/** * A utility function to transfer the values from an LVC Vector3 into a UnityEngine Vector3. * * @param source the LVCGame.Vector3 instance which is the source of values from the source * @param target the UnityEngine.Vector3 instance which is to receive the values */ public static void TransferValues( LVCGame.Vector3 source, ref UnityEngine.Vector3 target ) { target.x = (float)source.x; target.y = (float)source.y; target.z = (float)source.z; }
/** * A utility function to determine if a munition is an air munition from its EntityData. * It will return true if, and only if the entity is... * - a muniotion, *and* * - its (munition) domain is anti-air * Note that the primarty purpose of this method is to determine whether the munition is * a suitable candidate for ground clamping position processing (i.e., clamp the detonation * to the ground). * * @param entityData the LVCGame.EntityData instance * @return true if the entity is an air munition. */ public static bool IsAirMunition( LVCGame.EntityData entityData ) { string[] disEnumParts = entityData.id.lvcType.Split(' '); if( disEnumParts.Length < ((int)DIS_FIELD_INDEX.DOMAIN+1)) return false; int kind = StringToInt( disEnumParts[(int)DIS_FIELD_INDEX.KIND], 0 ); if( kind == (int)DIS_KIND.MUNITION ) { int domain = StringToInt( disEnumParts[(int)DIS_FIELD_INDEX.DOMAIN], ((int)DIS_DOMAIN.OTHER) ); return domain == (int)DIS_MUNITION_DOMAIN.ANTI_AIR; } return false; }
/** * A utility function to determine if an entity is a land entity from its EntityData. * It will return true if, and only if the entity is... * - a lifeform or platform, *and* * - its domain is land * Note that the primarty purpose of this method is to determine whether an entity is * a suitable candidate for ground clamping position processing. * * @param entityData the LVCGame.EntityData instance * @return true if the entity is a land entity. */ public static bool IsLandEntity( LVCGame.EntityData entityData ) { string[] disEnumParts = entityData.id.lvcType.Split(' '); if( disEnumParts.Length < ((int)DIS_FIELD_INDEX.DOMAIN+1)) return false; int kind = StringToInt( disEnumParts[(int)DIS_FIELD_INDEX.KIND], 0 ); if( kind == (int)DIS_KIND.LIFE_FORM || kind == (int)DIS_KIND.PLATFORM ) { int domain = StringToInt( disEnumParts[(int)DIS_FIELD_INDEX.DOMAIN], ((int)DIS_DOMAIN.OTHER) ); return domain == (int)DIS_DOMAIN.LAND; } return false; }
/** * A utility function to create a string using an LVC FireWeaponData struct to display the salient * details * * @param fwd the fire weapon data struct to create the string representation from * @return the formatted string */ public static string DisplayFormatted( LVCGame.FireWeaponData fwd ) { return fwd.descriptor.quantity+" rounds of "+fwd.targeting.munitionType+" from position "+ DisplayFormatted(LVCUtils.llaToLtp(fwd.targeting.position), "")+", velocity "+ DisplayAsMs(fwd.targeting.velocity); }
/** * A utility method to convert a local tangent plane position representaion to a * latitude/longitude/altitude representation. Uses the world origin obtained from the * LVC configuration as the primary reference point for the conversion. * * @param the local tangent plane coordinates in meters. The axes are as follows: * AXIS (+ve): | LVC * ------------+----- * NORTH | X * EAST | Y * UP | Z * @return lla the latitude/longitude/altitude position to convert. latitude and longitude * are in radians, altitude is in meters. */ public static LVCGame.Vector3 ltpToLla( LVCGame.Vector3 ltp ) { return LVCGame.LVCCoordinates.ltpToLla( ref v3zero, ref ltp ); }
/** * A utility function to create a string using an LVC FireWeaponData struct to display the salient * details * * @param fwd the fire weapon data struct to create the string representation from * @return the formatted string */ public static string DisplayFormatted( LVCGame.DetonateMunitionData dmd ) { return dmd.descriptor.quantity+" rounds of "+dmd.targeting.munitionType+" at position "+ DisplayFormatted(LVCUtils.llaToLtp(dmd.targeting.position), ""); }
/** * Convert a LVC Game Vector 3 orientation into a Unity Engine Quaternion, correcting for * the different interpretations of rotation axes between the systems * AXIS (+ve): | LVC | UNITY * ------------+-----+------- * YAW | X | Y * PITCH | Y | Z * ROLL | Z | -X * * @param orientation the LVC Game Vector3 to convert * @return the equivalent Unity Engine Quaternion, with corrected axes */ public static UnityEngine.Quaternion LVCGameOrientation_to_UnityOrientation( LVCGame.Vector3 orientation ) { float yaw = (float)orientation.x; float pitch = (float)orientation.y; float roll = -(float)orientation.z; float cY = Mathf.Cos(yaw / 2); float cP = Mathf.Cos(pitch / 2); float cR = Mathf.Cos(roll / 2); float sY = Mathf.Sin(yaw / 2); float sP = Mathf.Sin(pitch / 2); float sR = Mathf.Sin(roll / 2); float w = (cY*cP*cR) - (sY*sP*sR); float x = (sY*sP*cR) + (cY*cP*sR); float y = (sY*cP*cR) + (cY*sP*sR); float z = (cY*sP*cR) - (sY*cP*sR); UnityEngine.Quaternion result = new UnityEngine.Quaternion(); result.w = w; result.x = z; result.y = y; result.z = x; return result; }
/** * A utility function to create a string using an LVC EntityData struct to display the salient * details of an entity's state * * @param ed the entity data struct to create the string representation from * @return the formatted string */ public static string DisplayFormatted( LVCGame.UTMCoordinate utm ) { return ""+System.Math.Abs(lvcWorldOriginUTM.easting)+(lvcWorldOriginUTM.easting<0?"W":"E")+" " +System.Math.Abs(lvcWorldOriginUTM.northing)+(lvcWorldOriginUTM.northing<0?"S":"N")+" " +lvcWorldOriginUTM.altitude+"m " +"Z"+lvcWorldOriginUTM.zone+" " +lvcWorldOriginUTM.hemisphere; }
/** * Causes an munition detonation notification to be sent into the LVC Game * world. If Create() has not yet been called, or Destroy() has been called, * this will have no effect. * * @param lvcMunitionType the LVC Game munition type name * @param position the location at which the detonation occurs * @param velocity the velocity of the munition - this is the "approach vector" of the munition * as viewed from the detonation location * @param quantity (optional) the number of rounds fired in this "burst" (if unspecified, 1 is used) * @param rate (optional) the rate of fire in rounds per minute * @param warhead (optional) the DIS warhead type of the detonated munition * @param fuse (optional) the DIS fuse type of the detonated munition * @param detonation (optional) the DIS detonation type of the detonated munition * @param targetId (optional) the ID of the entity targeted by this detonated * @param relativePosition (optional) the relative position of the detonation to the target */ public void DetonateMunition( string lvcMunitionType, UnityEngine.Vector3 position, UnityEngine.Vector3 velocity, uint quantity, uint rate, LVCGame.WarHeadType warhead, LVCGame.FuseType fuse, LVCGame.DetonationType detonation, long targetId, UnityEngine.Vector3 relativePosition ) { lock( this ) { if( lvcGameState == LVCGameState.CREATED ) { LVCGame.DetonateMunitionData detonateMunitionData = lvcUnityAmbassador.MakeDetonateMunitionData( this.entityData.id.instance, lvcMunitionType, position, velocity, quantity, rate, warhead, fuse, detonation, targetId, relativePosition ); this.lvcClient.DetonateMunition( ref detonateMunitionData ); } } }
/** * A utility function to obtain the DIS 'country' of an entity from its EntityData * * @param entityData the LVCGame.EntityData instance * @return the DIS country value */ public static int GetDisCountry( LVCGame.EntityData entityData ) { string[] disEnumParts = entityData.id.lvcType.Split(' '); if( disEnumParts.Length < ((int)DIS_FIELD_INDEX.COUNTRY+1)) return 0; return StringToInt( disEnumParts[(int)DIS_FIELD_INDEX.COUNTRY], 0 ); }
//------------------------------------------------------------------------------------------ // UNIT FORCE TYPE //------------------------------------------------------------------------------------------ /** * Set the unit force type of the entity * * @param unitForceType the force of the entity */ public void SetForce( LVCGame.UnitForceType unitForceType ) { lock( this ) { this.entityData.properties.force = unitForceType; } }
/** * A utility function to obtain the DIS 'domain' of an entity from its EntityData * * @param entityData the LVCGame.EntityData instance * @return the DIS domain value */ public static int GetDisDomain( LVCGame.EntityData entityData ) { string[] disEnumParts = entityData.id.lvcType.Split(' '); if( disEnumParts.Length < ((int)DIS_FIELD_INDEX.DOMAIN+1)) return 0; return StringToInt( disEnumParts[(int)DIS_FIELD_INDEX.DOMAIN], ((int)DIS_DOMAIN.OTHER) ); }
//------------------------------------------------------------------------------------------ // SECONDARY WEAPON POSTURE //------------------------------------------------------------------------------------------ /** * Set the secondary weapon posture of the entity * * @param secondaryWeaponPosture the secondary weapon posture of the entity */ public void SetSecondaryWeaponPosture( LVCGame.WeaponPostureType secondaryWeaponPosture ) { lock( this ) { this.entityData.properties.sndWeaponPosture = secondaryWeaponPosture; } }
/** * A utility function to obtain the DIS enumeration of an entity from its EntityData * * @param entityData the LVCGame.EntityData instance * @return the DIS enumeration values as an integer array of 7 values */ public static int[] GetDisEnumeration( LVCGame.EntityData entityData ) { int[] result = new int[7]; string[] disEnumParts = entityData.id.lvcType.Split(' '); for(int i=0;i<disEnumParts.Length;i++) { result[i] = StringToInt( disEnumParts[i], 0 ); } return result; }
/** * A utility function to obtain the DIS 'kind' of an entity from its EntityData * * @param entityData the LVCGame.EntityData instance * @return the DIS kind value */ public static int GetDisKind( LVCGame.EntityData entityData ) { string[] disEnumParts = entityData.id.lvcType.Split(' '); if( disEnumParts.Length < ((int)DIS_FIELD_INDEX.KIND+1)) return 0; return StringToInt( disEnumParts[(int)DIS_FIELD_INDEX.KIND], ((int)DIS_KIND.OTHER) ); }
//---------------------------------------------------------- // STATIC VARIABLES //---------------------------------------------------------- //---------------------------------------------------------- // INSTANCE VARIABLES //---------------------------------------------------------- //---------------------------------------------------------- // CONSTRUCTORS //---------------------------------------------------------- //---------------------------------------------------------- // INSTANCE METHODS //---------------------------------------------------------- /** * Handle fire weapon event data * * @param fireWeaponData the LVC weapon fire data information * @param gO the Unity GameObject representation of the firing entity */ public abstract void HandleFire( LVCGame.FireWeaponData fireWeaponData, GameObject gO );