//////////////////////////////////////////////////////
    //// FUNCIONS FOR EXTERNAL ACCESS

    public void FocusOnGameObject(Vector3 gameObjectPosition)
    {
        if (gameObjectPosition.y < -5000)
        {
            return;
        }

        Vector3 cameraPosition = this.transform.position;

        this.focusOrigin        = cameraPosition;
        this.focusGameObjectPos = gameObjectPosition;

        // rotatation of camera
        Vector3 lookAtVector = (gameObjectPosition - cameraPosition).normalized;

        if (lookAtVector != Vector3.zero)
        {
            this.transform.rotation = Quaternion.LookRotation(lookAtVector);
        }

        float x = Vector3.Distance(cameraPosition, gameObjectPosition) - focusMinDistance;

        this.focusDestination = CalculationUtil.CalculatePointOnLine(cameraPosition, gameObjectPosition, x);
        this.focusDeltaTime   = 0;
        this.focusing         = true;
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Initialize all properties with the given sensor trigger.  Note that the collider should have the
    /// "Is Trigger" enabled.
    /// </summary>
    /// <param name="sensorTrigger"></param>
    public SensorProperties(SphereCollider sensorTrigger, AiStateMachine stateMachine)
    {
        /*
         * Assertions should be sufficient to notify us if something has not been configured correctly because many of the
         * required components are actually manually added by us rather than instantiated by code and we'll get a meaningful
         * message right when we play the scene.
         * Thus, this is used in favor of all the "null" checks that were found in the lesson videos and that gives a little
         * more clarity to the code.
         */

        Assert.IsNotNull(sensorTrigger, "Missing sensorTrigger; did you forget to drag it onto the AI Entity GameObject in the inspector!");
        // this will only happen if it is false to begin with; nothing happens if changed after
        Assert.IsTrue(sensorTrigger.isTrigger, "Invalid sensorTrigger; make sure to set 'Is Trigger' to true in the inspector!");

        this.sensorTrigger = sensorTrigger;
        this.stateMachine  = stateMachine;

        // pass the parent state machine to the AiSensor script so that it can delegate trigger callbacks to it
        AiSensor script = this.sensorTrigger.GetComponent <AiSensor>();

        Assert.IsNotNull(script, "Missing AiSensor script on the Sensor GameObject!");
        script.ParentStateMachine = stateMachine;

        // Since sensor is a child with a local position and rotation, we need to ensure its position and radius
        // scales correctly when ancestor values change (i.e. compute global or world position and radius)
        // alternate way is to use the new method that computes both values
        this.worldPosition = CalculationUtil.ComputeWorldPosition(this.sensorTrigger);
        this.worldRadius   = CalculationUtil.ComputeWorldRadius(this.sensorTrigger);
    }
Ejemplo n.º 3
0
        public void VeryShortRouteShouldAllowInvalidAltitude()
        {
            var calc = GetCalculator(NoWind, VeryShortTestRoute0());
            var plan = calc.Create();

            var(isValidAlt, _) = CalculationUtil.CruiseAltValid(
                new CrzAltProviderStub(), plan.AllNodes);
            Assert.IsFalse(isValidAlt);
        }
Ejemplo n.º 4
0
    /// <summary>
    /// Calculate the angle we need to turn the AI Entity body towards the target
    /// </summary>
    /// <returns>A positive angle in degrees that is needed to face the target.</returns>
    public float DetermineAngleNeededToTurnTowardsTarget()
    {
        float angle = CalculationUtil.FindSignedAngle(
            this.stateMachine.AiEntityBodyTransform.forward,
            this.stateMachine.NavAgent.steeringTarget - this.stateMachine.AiEntityBodyTransform.position
            );

        return(angle);
    }
Ejemplo n.º 5
0
        //
        //Berechnen Button
        //
        private void button1_Click(object sender, EventArgs e)
        {
            double scope   = CalculationUtil.Scope(Vertices, Edges, pixelMeter);
            double surface = CalculationUtil.Surface(Vertices, pixelMeter);

            if (scope != 0)
            {
                ScopeNumber.Text   = Convert.ToString(scope) + " m";
                SurfaceNumber.Text = Convert.ToString(surface) + " m²";
            }
        }
Ejemplo n.º 6
0
        public IActionResult Create([FromBody] Employees employee)
        {
            Employees objEmployee = employee;

            if (objEmployee != null)
            {
                CalculationUtil.SetDeductionAmounts(objEmployee);
                db.AddEmployee(objEmployee);
            }

            return(Ok(new
            {
                success = true,
                returncode = "200"
            }));
        }
Ejemplo n.º 7
0
    /// <summary>
    /// Actions to take whenever an Audio threat is detected.
    /// </summary>
    /// <param name="audioCollider">The Audio collider that triggered the collision</param>
    private void HandleAudioThreat(Collider audioCollider)
    {
        SphereCollider soundTrigger = (SphereCollider)audioCollider;

        if (soundTrigger == null)
        {
            return;
        }

        // Get the position of the Agent Sensor
        Vector3 agentSensorPosition = zombieStateMachine.Sensor.WorldPosition;

        Vector3 soundPos;
        float   soundRadius;

        CalculationUtil.ConvertSphereColliderToWorldSpace(soundTrigger, out soundPos, out soundRadius);

        // How far inside the sound's radius are we
        float distanceToThreat = (soundPos - agentSensorPosition).magnitude;

        // Calculate a distance factor such that it is 1.0 when at sound radius 0 when at center
        float distanceFactor = (distanceToThreat / soundRadius);

        // Bias the factor based on hearing ability of Agent.
        distanceFactor += distanceFactor * (1.0f - this.zombieStateMachine.Hearing);

        // Too far away
        if (distanceFactor > 1.0f)
        {
            return;
        }

        // if We can hear it and is it closer then what we previously have stored
        if (IsCloserThanLastThreat(zombieStateMachine.ThreatManager.CurrentAudioThreat, distanceToThreat))
        {
            // Most dangerous Audio Threat so far
            zombieStateMachine.ThreatManager.TrackAudioThreat(
                audioCollider,
                soundPos,
                distanceToThreat
                );
        }
    }
    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));
    }
Ejemplo n.º 10
0
    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);
        }
    }
    public void DrawInfoWindow()
    {
        if (this.treeview.SelectedItem.EntityID < 0)
        {
            return;
        }

        Treeview_DataModel selected = this.treeview.SelectedItem;
        float width  = 280;
        float height = 20;
        float left   = Screen.width - width - 10;
        float index  = 54;

        if (!selected.IsUnit && selected.GeographicCoordinates != null)
        {
            index += 22 * 6;
        }
        else if (selected.IsUnit)
        {
            index += 22 * (3 + selected.Children.Count);
        }
        else
        {
            index += 22 * 3;
        }

        if (index < 120)
        {
            index = 120;
        }

        // draw background
        //GUI.Box(new Rect(left - 15, 10, width + 15, index + 30), "");
        GUI.DrawTexture(new Rect(left - 15, 10, width + 15, 28), this.texture_TitleWindow);
        GUI.DrawTexture(new Rect(left - 15, 40, width + 15, index), this.texture_BackgroundWindow);

        if (GUI.Button(new Rect(left + width - 23, 13, 20, height), "×"))
        {
            this.treeview.SelectedItem = null;
        }

        if (selected.IsUnit)
        {
            GUI.Label(new Rect(left + 103, 15, width, height), "UNIT INFO");
            GUI.DrawTexture(new Rect(left - 15, 10, Constants.NatoIconWidth * 1.5f, Constants.NatoIconHeight * 1.5f), selected.NATO_Icon);
        }
        else
        {
            GUI.Label(new Rect(left + 90, 15, width, height), "SYSTEM INFO");
            GUI.DrawTexture(new Rect(left - 15, 10, Constants.NatoIconWidth * 1.5f, Constants.NatoIconHeight * 1.5f), selected.Father.NATO_Icon);
        }

        index = 22;

        GUI.Label(new Rect(left + 110, index += 22, width, height), "Name: " + selected.Text);

        if (!selected.IsUnit && selected.GeographicCoordinates != null)
        {
            if (!selected.Moving)
            {
                GUI.Label(new Rect(left + 110, index += 22, width, height), "Latitude: " + CalculationUtil.ConvertToDegMinSec(selected.GeographicCoordinates.y));
                GUI.Label(new Rect(left + 110, index += 22, width, height), "Longitude: " + CalculationUtil.ConvertToDegMinSec(selected.GeographicCoordinates.x));
            }
            else
            {
                GUI.Label(new Rect(left + 110, index += 22, width, height), "Latitude: " +
                          CalculationUtil.ConvertToDegMinSec(CalculationUtil.Latitude_LeftBottom + selected.GameObject.transform.position.z / CalculationUtil.DMR_map_size));
                GUI.Label(new Rect(left + 110, index += 22, width, height), "Longitude: " +
                          CalculationUtil.ConvertToDegMinSec(CalculationUtil.Longitude_LeftBottom + selected.GameObject.transform.position.x / CalculationUtil.DMR_map_size));
            }

            GUI.Label(new Rect(left + 110, index += 22, width, height), String.Format("Altitude: {0:0.00} m", selected.GeographicCoordinates.z));
            GUI.Label(new Rect(left + 110, index += 22, width, height), "Health: " + ((3 - selected.Health) * 100 / 3) + " %");
            GUI.Label(new Rect(left + 110, index += 22, width, height), "Visible: " + (!selected.IsAggregated).ToString().ToUpper());
            GUI.Label(new Rect(left + 110, index += 22, width, height), "Moving: " + selected.Moving.ToString().ToUpper());

            if (selected.Moving)
            {
                GUI.Label(new Rect(left + 110, index += 22, width, height), String.Format("Speed: {0:0.00} km/h",
                                                                                          CalculationUtil.CalculateSpeedInKmPerH(selected.MovingSpeed, selected.MovingDirection)));
            }
        }
        else if (selected.IsUnit)
        {
            GUI.Label(new Rect(left + 110, index += 22, width, height), "Health: " + selected.Health + " %");
            GUI.Label(new Rect(left + 110, index += 22, width, height), "Num. of systems: " + RecursionUtil.GetNumberOfSystems_Rec(selected));
            GUI.Label(new Rect(left + 110, index += 22, width, height), "Visible: " + (!selected.Father.IsAggregated).ToString().ToUpper());
            index += 15;
            //GUI.Label(new Rect(left + 110, index += 22, width, height), "Subunits: ");

            for (int i = 0; i < selected.Children.Count; i++)
            {
                /*GUI.Label(new Rect(left, index += 22, width, height), "      " + (
                 * i + 1) + ".)  " + selected.Children[i].Text);
                 *
                 */
                /*if (GUI.Button(new Rect(left + 110, index += 22, width, height), "      " + (i + 1) + ".)  " + selected.Children[i].Text, "Label"))
                 *  this.treeview.SelectedItem = selected.Children[i];
                 *
                 * if (selected.Children[i].IsUnit)
                 *  GUI.DrawTexture(new Rect(Screen.width - 40, index-17, 55 * 612 / 792, 55), selected.Children[i].NATO_Icon);
                 */

                if (GUI.Button(new Rect(left + 50, index += 22, width, height), selected.Children[i].Text, "Label"))
                {
                    this.treeview.SelectedItem = selected.Children[i];
                }

                if (selected.Children[i].IsUnit)
                {
                    GUI.DrawTexture(new Rect(left, index - 17, 55 * 612 / 792, 55), selected.Children[i].NATO_Icon);
                }
                else
                {
                    GUI.DrawTexture(new Rect(left, index - 17, 55 * 612 / 792, 55), selected.Children[i].Father.NATO_Icon);
                }
            }
        }
        else
        {
            GUI.Label(new Rect(left + 110, index += 22, width, height), "Health: " + ((3 - selected.Health) * 100 / 3) + " %");
            GUI.Label(new Rect(left + 110, index += 22, width, height), "Visible: " + (!selected.IsAggregated).ToString().ToUpper());
            GUI.Label(new Rect(left + 110, index += 22, width, height), "Moving: " + selected.Moving.ToString().ToUpper());
        }
    }
Ejemplo n.º 12
0
    /// <summary>
    /// Handles the alerted state by continuing to pursue waypoints, etc.
    /// </summary>
    /// <returns>Either the alerted state or any new state if certain conditions were met.</returns>
    private AiStateType HandleDefaultState()
    {
        AiStateType state = GetDefaultStateType();

        if (
            !zombieStateMachine.IsTargetReached &&
            (zombieStateMachine.ThreatManager.DoesAudioThreatExist() || zombieStateMachine.ThreatManager.DoesLightThreatExist())
            )
        {
            // we got close to the target due to light or sound, so now we need to know if we should pursue it or seek to find it
            float angle = CalculationUtil.FindSignedAngle(
                zombieStateMachine.AiEntityBodyTransform.forward,
                zombieStateMachine.ThreatManager.CurrentTarget.Position - zombieStateMachine.AiEntityBodyTransform.position
                );

            if (zombieStateMachine.ThreatManager.DoesAudioThreatExist() && Mathf.Abs(angle) < this.threatAngleThreshold)
            {
                // it's a sound and we are capable of heading to it, so pursue it
                state = AiStateType.Pursuit;
            }
            else if (HasReachedMaxDirectionChangeTime())
            {
                // it's not a sound and we are not capable of turning towards it, so determine which way we should turn
                if (Random.value < zombieStateMachine.Intelligence)
                {
                    SeekTowards(angle); // smartly turn
                }
                else
                {
                    SeekRandomly();          // randomly turn because we are a stupid zombie :)
                }
                ResetDirectionChangeTimer(); // TODO: this does sometimes happen often and it makes the zombie appear as if it is stuck in the alerted state
            }
        }
        else if (
            zombieStateMachine.ThreatManager.IsTargeting(AiTargetType.Waypoint) &&
            !zombieStateMachine.NavAgent.pathPending
            )
        {
            // we were targeting a waypoint and we arrived at it, so determine if we can head to next one or turn towards it
            float angle = zombieStateMachine.ThreatManager.DetermineAngleNeededToTurnTowardsTarget();

            if (Mathf.Abs(angle) < this.turnOnSpotThreshold)
            {
                state = AiStateType.Patrol;
            }
            else if (HasReachedMaxDirectionChangeTime())
            {
                SeekTowards(angle);
                ResetDirectionChangeTimer();
            }
        }
        else if (HasReachedMaxDirectionChangeTime())
        {
            // we didn't find what we were looking for and our clock ran out, so turn randomly and repeat the entire alert process
            // TODO: this does sometimes happen often and it makes the zombie appear as if it is stuck in the alerted state
            SeekRandomly();
            ResetDirectionChangeTimer();
        }

        return(state);
    }
    //////////////////////////////////////////////////////
    //// FUNCIONS FOR EXTERNAL ACCESS

    public void SetEntityMovementAndDamage(int entityID, bool moving, Vector3 moveDirection, float speed, int entityDamage, Vector3D geodeticLocation, Vector3 position, byte entityDomain)
    {
        // find entity in treeview
        Treeview_DataModel treeviewEntity = RecursionUtil.GetTreeviewItemByEntityId(entityID, this.treeviewHandlerScript.TreeView.ItemsSource);
        string             message        = "";
        bool newEntitySpawned             = false;

        if (treeviewEntity == null)
        {
            newEntitySpawned = true;

            Debug.Log("Entity " + entityID + " wasn't found!");
            this.treeviewHandlerScript.AddUnknownEntityToTreeview(entityID);
            treeviewEntity = RecursionUtil.GetTreeviewItemByEntityId(entityID, this.treeviewHandlerScript.TreeView.ItemsSource);
            message        = "New entity";

            treeviewEntity.Health = -1;

            // TODO move to SetEntityMovementAndDamage
            // set airborne
            if (entityDomain == 2)
            {
                treeviewEntity.IsAirborne = true;
            }
        }
        else if (treeviewEntity.GameObject.transform.position.y < -2000)
        {
            newEntitySpawned = true;
            message          = "Known entity";

            if (entityDomain == 2)
            {
                treeviewEntity.IsAirborne = true;
            }
        }

        // update geodetic location
        treeviewEntity.GeographicCoordinates = geodeticLocation;

        // send entity state event
        if (newEntitySpawned)
        {
            DateTime timestamp = DateTime.Now;
            message += String.Format(" \"{0}\" spawned at {1:0.000000}° lat, {2:0.000000}° lon.", treeviewEntity.Text,
                                     treeviewEntity.GeographicCoordinates.y, treeviewEntity.GeographicCoordinates.x);
            this.treeviewHandlerScript.AddEventToLog(new DisEvent(timestamp, message));
        }


        if (!treeviewEntity.IsUnit)
        {
            // set entity position
            // TODO check maybe needs to be deleted to be faster
            if (!CalculationUtil.HaveSameValues(position, treeviewEntity.GameObject.transform.position))
            {
                treeviewEntity.GameObject.transform.position = position;
                RecursionUtil.SetWorldPositionOfParentUnit_Rec(treeviewEntity);
            }

            // set entity rotation
            if (moveDirection != Vector3.zero)
            {
                treeviewEntity.GameObject.transform.rotation = Quaternion.LookRotation(moveDirection);
            }

            if (treeviewEntity.Health != entityDamage)
            {
                // TODO 1 if(treeviewEntity.Health != entityDamage) (set new health && updateHealth)
                // TODO 2 UpdateHealth change to go up
                // update entity damage
                treeviewEntity.Health = entityDamage;

                // TODO confirm that it is working
                //RecursionUtil.UpdateHealth_Rec(this.treeviewHandlerScript.treeview.ItemsSource);
                RecursionUtil.UpdateHealthOfAncestors_Rec(treeviewEntity);
            }
        }

        // set entity movement
        if (!moving)
        {
            treeviewEntity.Moving = false;
        }
        else
        {
            treeviewEntity.Moving          = true;
            treeviewEntity.MovingSpeed     = speed;
            treeviewEntity.MovingDirection = moveDirection;
        }
    }