public void SendDisEvent(DetonationPdu detonationPdu)
    {
        DateTime timestamp = DateTime.Now;

        Vector3D geographicalCoordinates = CalculationUtil.ConvertToGeographicalCoordinates(new Vector3D(detonationPdu.LocationInWorldCoordinates.X, detonationPdu.LocationInWorldCoordinates.Y, detonationPdu.LocationInWorldCoordinates.Z));
        string   message = String.Format("Detonation at {0:0.000000}° lat, {1:0.000000}° lon. by entity", geographicalCoordinates.y, geographicalCoordinates.x);

        Treeview_DataModel firingEntity = RecursionUtil.GetTreeviewItemByEntityId(detonationPdu.FiringEntityID.Entity, this.treeviewHandlerScript.TreeView.ItemsSource);

        if (firingEntity == null)
        {
            message += " \"UNK\".";
        }
        else
        {
            message += " \"" + firingEntity.Text + "\".";
        }

        this.treeviewHandlerScript.AddEventToLog(new DisEvent(timestamp, message));
    }
    public void SendDisEvent(FirePdu firePdu)
    {
        DateTime timestamp = DateTime.Now;
        string   message;

        Treeview_DataModel firingEntity = RecursionUtil.GetTreeviewItemByEntityId(firePdu.FiringEntityID.Entity, this.treeviewHandlerScript.TreeView.ItemsSource);

        if (firingEntity == null)
        {
            message = "Entity \"UNK\" fired";
        }
        else
        {
            message = "Entity \"" + firingEntity.Text + "\" fired";
        }

        if (firePdu.TargetEntityID.Entity != 0)
        {
            Treeview_DataModel targetEntity = RecursionUtil.GetTreeviewItemByEntityId(firePdu.TargetEntityID.Entity, this.treeviewHandlerScript.TreeView.ItemsSource);

            if (targetEntity == null)
            {
                message += " upon entity \"UNK\"";
            }
            else
            {
                message += " upon entity \"" + targetEntity.Text + "\"";
            }
        }

        Vector3D geographicalCoordinates = CalculationUtil.ConvertToGeographicalCoordinates(new Vector3D(firePdu.LocationInWorldCoordinates.X, firePdu.LocationInWorldCoordinates.Y, firePdu.LocationInWorldCoordinates.Z));

        message += String.Format(" at {0:0.000000}° lat, {1:0.000000}° lon.", geographicalCoordinates.y, geographicalCoordinates.x);

        this.treeviewHandlerScript.AddEventToLog(new DisEvent(timestamp, message));
    }
    private void ChangeEntityState(EntityStatePdu entityStatePdu)
    {
        int entityID     = entityStatePdu.EntityID.Entity;
        int entityDamage = (entityStatePdu.EntityAppearance & 24) >> 3;

        Vector3D geographicalCoordinates = CalculationUtil.ConvertToGeographicalCoordinates(
            new Vector3D(entityStatePdu.EntityLocation.X, entityStatePdu.EntityLocation.Y, entityStatePdu.EntityLocation.Z));
        Vector3 worldCoordinates = CalculationUtil.ConvertToWorldCoordinates(geographicalCoordinates, entityStatePdu.EntityType.Domain, layerMask_terrain);

        // calculating velocity and setting movement
        Vector3D velocityVec3D = new Vector3D(entityStatePdu.EntityLinearVelocity.X, entityStatePdu.EntityLinearVelocity.Y, entityStatePdu.EntityLinearVelocity.Z);

        if (velocityVec3D.x != 0 || velocityVec3D.y != 0 || velocityVec3D.z != 0)
        {
            Vector3D velocityCoordinates = CalculationUtil.ConvertToGeographicalCoordinates(new Vector3D(
                                                                                                entityStatePdu.EntityLocation.X + entityStatePdu.EntityLinearVelocity.X,
                                                                                                entityStatePdu.EntityLocation.Y + entityStatePdu.EntityLinearVelocity.Y,
                                                                                                entityStatePdu.EntityLocation.Z + entityStatePdu.EntityLinearVelocity.Z));

            Vector3 worldCoordinatesVelocity = CalculationUtil.ConvertToWorldCoordinates(velocityCoordinates, entityStatePdu.EntityType.Domain, layerMask_terrain);

            Vector3 lookAtVector = (new Vector3(worldCoordinatesVelocity.x, 0, worldCoordinatesVelocity.z) -
                                    new Vector3(worldCoordinates.x, 0, worldCoordinates.z)).normalized;

            float distance = Vector3.Distance(
                new Vector3(worldCoordinates.x, 0, worldCoordinates.z),
                new Vector3(worldCoordinatesVelocity.x, 0, worldCoordinatesVelocity.z));

            this.entityHandlerScript.SetEntityMovementAndDamage(entityID, true, lookAtVector, distance, entityDamage, geographicalCoordinates, worldCoordinates, entityStatePdu.EntityType.Domain);
        }
        // else rotate entity based on previous location
        else
        {
            this.entityHandlerScript.SetEntityMovementAndDamage(entityID, false, Vector3.zero, 0, entityDamage, geographicalCoordinates, worldCoordinates, entityStatePdu.EntityType.Domain);
        }
    }