private void updateClassificationFor(GameObject target, SoaActor targetActor) { // Loop through all possible classifier modes foreach (PerceptionModality mode in modes) { // Compute slant range in km float slantRange = Mathf.Sqrt( ((transform.position.x - target.transform.position.x) / SimControl.KmToUnity) * ((transform.position.x - target.transform.position.x) / SimControl.KmToUnity) + (thisSoaActor.simAltitude_km - targetActor.simAltitude_km) * (thisSoaActor.simAltitude_km - targetActor.simAltitude_km) + // Recall that altitude is kept track of separately ((transform.position.z - target.transform.position.z) / SimControl.KmToUnity) * ((transform.position.z - target.transform.position.z) / SimControl.KmToUnity) ); // If the game object matches its intended target if (mode.tagString == target.tag) { // Determine whether it was classified if (slantRange <= mode.RangeP1) { // Successful kill, 100% probabiltiy thisSoaActor.setClassified(targetActor.unique_id); } else if (slantRange <= mode.RangeMax) { // Probability of being classified if (UnityEngine.Random.value < (mode.RangeMax - slantRange) / (mode.RangeMax - mode.RangeP1)) { // Target was unlucky and was classified thisSoaActor.setClassified(targetActor.unique_id); } } } } }
bool removeFakeTarget = false; // Not used, but interesting for future // Awake is called before anything else void Awake() { thisSoaActor = gameObject.GetComponent <SoaActor>(); simControlScript = GameObject.FindObjectOfType <SimControl>(); waypointScript = gameObject.GetComponent <SoldierWaypointMotion>(); thisNavAgent = gameObject.GetComponent <NavMeshAgent>(); }
// Awake is called before anything else void Awake() { // Get references to scripts simControlScript = GameObject.FindObjectOfType <SimControl>(); waypointScript = gameObject.GetComponent <SoldierWaypointMotion>(); thisNavAgent = gameObject.GetComponent <NavMeshAgent>(); thisSoaActor = gameObject.GetComponent <SoaActor>(); // To hold source/destination choices during random selection choices = new List <GameObject>(); }
/* * Remove an existing actor from data manager list of actors */ public void removeActor(SoaActor actor) { if (actors.Contains(actor)) { actors.Remove(actor); Debug.Log("Removing actor " + actor.unique_id + " from actor dictionary"); soaActorDictionary.Remove(actor.unique_id); } else { Debug.LogError("TRIED TO REMOVE ACTOR FROM DATA MANAGER THAT DOESN'T EXIST: " + actor.unique_id); } }
public void TrackObjectWithID(int unique_id) { for (int i = 0; i < Platforms.Count; ++i) { GameObject platform = Platforms[i]; SoaActor actor = platform.GetComponent <SoaActor>(); if (actor != null && actor.unique_id == unique_id) { trackedPlatformIndex = i; trackingOn = true; break; } } }
public void logKill(SoaActor killedActor) { lock (soaActor.killDetections) { soaActor.killDetections.Add(new soa.Belief_Actor( killedActor.unique_id, (int)killedActor.affiliation, killedActor.type, false, killedActor.numStorageSlots, killedActor.numCasualtiesStored, killedActor.numSuppliesStored, killedActor.numCiviliansStored, killedActor.isWeaponized, killedActor.hasJammer, killedActor.fuelRemaining_s, killedActor.transform.position.x / SimControl.KmToUnity, killedActor.simAltitude_km, killedActor.transform.position.z / SimControl.KmToUnity)); } }
// Use this for initialization protected void Start() { waypointIndex = 0; currentSpeed = 0; On = false; displayWaypoints = false; actor = gameObject.GetComponent <SoaActor>(); transform.position = new Vector3(transform.position.x, AltitudeOffset, transform.position.z); if (GetComponent <Animation>() != null) { GetComponent <Animation>().wrapMode = WrapMode.Loop; } }
// Cone beam antenna pattern public bool CheckSensorFootprint(GameObject target) { // Re-evaluate boresight if sensor is gimbaled (balloon) if (soaActor.type == (int)SoaActor.ActorType.BALLOON) { // Get the belief dictionary and SPOI Belief Belief_SPOI b = soaActor.Find <Belief_SPOI>(soa.Belief.BeliefType.SPOI, soaActor.unique_id); if (b != null) { // Extract SPOI (x,y,z) in sim coordinates [km] Vector3 spoi_km = new Vector3( b.getPos_x(), b.getPos_y(), b.getPos_z()); // Update the sensor boresight vector boresightUnitVector.x = spoi_km.x - transform.position.x / SimControl.KmToUnity; // [km] boresightUnitVector.y = spoi_km.y - soaActor.simAltitude_km; // [km] boresightUnitVector.z = spoi_km.z - transform.position.z / SimControl.KmToUnity; // [km] boresightUnitVector.Normalize(); } } // Compute relative vector SoaActor targetActor = target.GetComponent <SoaActor>(); Vector3 sensorToTargetUnitVector; sensorToTargetUnitVector.x = (target.transform.position.x - transform.position.x) / SimControl.KmToUnity; // [km] sensorToTargetUnitVector.y = targetActor.simAltitude_km - soaActor.simAltitude_km; // [km] sensorToTargetUnitVector.z = (target.transform.position.z - transform.position.z) / SimControl.KmToUnity; // [km] sensorToTargetUnitVector.Normalize(); // Compute target cone angle relative to boresight double coneAngleDeg = (180.0f / Mathf.PI) * Mathf.Acos( sensorToTargetUnitVector.x * boresightUnitVector.x + sensorToTargetUnitVector.y * boresightUnitVector.y + sensorToTargetUnitVector.z * boresightUnitVector.z); // Check if target is within beamwidthDeg/2 of boresight return(coneAngleDeg <= (beamwidthDeg / 2)); }
/* * Add every new actor to the data manager list of actors */ public void addNewActor(SoaActor actor) { if (!actors.Contains(actor)) { actors.Add(actor); //Debug.Log("Adding actor " + actor.unique_id + " to actor dictionary"); soaActorDictionary[actor.unique_id] = actor; cm.addNewActor(actor.unique_id, actor.getRepository()); addBeliefToDataManager( new Belief_Actor(actor.unique_id, (int)actor.affiliation, actor.type, actor.isAlive, actor.numStorageSlots, actor.numCasualtiesStored, actor.numSuppliesStored, actor.numCiviliansStored, actor.isWeaponized, actor.hasJammer, actor.fuelRemaining_s, actor.transform.position.x / SimControl.KmToUnity, actor.simAltitude_km, actor.transform.position.z / SimControl.KmToUnity), actor.unique_id); } else { Debug.LogError("TRIED TO ADD ACTOR TO DATA MANAGER THAT ALREADY EXISTS: " + actor.unique_id); } }
// Awake is called first before anything else void Awake() { // Initialize databases protectedSitePos = new Dictionary <string, Vector3>(); protectedSiteVirtualCasualties = new Dictionary <string, float>(); protectedSiteTotalCasualties = new Dictionary <string, float>(); // Get and store references simControlScript = GameObject.FindObjectOfType <SimControl>(); thisNavAgent = gameObject.GetComponent <NavMeshAgent>(); thisSoaActor = gameObject.GetComponent <SoaActor>(); // Internal parameters clearPatrolRange = 0.50f; // Unity units transitionProbability = 1.0f; // Initial task currTask = Task.NONE; patrolTarget = null; pursueActorID = 0; // Red unit database redUnitDatabase = new Dictionary <int, RedUnitInfo>(); }
/** * Update the position of the actor vectors. This function is called when in simulation mode * If Sim is in charge of waypoints, get the current target from the motion script and add to * belief map. Otherwise get the waypointBelief from the dictionary and set as navAgent destination. * * TODO create functions for when in client mode and only reading position data */ public virtual void updateActor() { if (!isAlive) { return; } Belief myActor = null; displayTruePosition = true; if (myActor != null && myActor.getId() != unique_id) { Debug.LogError("Update Actor " + unique_id + " has invalid id " + myActor.getId()); return; } if (simulateMotion) { displayActor = true; // Setup waypoint belief if (useExternalWaypoint) { Belief_Waypoint newWaypoint = beliefRepo.Find <Belief_Waypoint>(Belief.BeliefType.WAYPOINT, unique_id); Belief_WaypointPath newPath = beliefRepo.Find <Belief_WaypointPath>(Belief.BeliefType.WAYPOINT_PATH, unique_id); motionScript.On = false; if (wpMotionScript != null) { if (newPath != null && newWaypoint != null) { //If we have a path and a waypoint choose the newest one if (newPath.getBeliefTime() < newWaypoint.getBeliefTime()) { newPath = null; } else { newWaypoint = null; } } if (newPath != null) { wpMotionScript.SetWaypointBelief(newPath); wpMotionScript.On = true; } else if (newWaypoint != null) { wpMotionScript.SetWaypointBelief(newWaypoint); wpMotionScript.On = true; } //SetDesiredAltitude(wpMotionScript.desiredAltitude_km); } else if (newWaypoint != null) { // Received a waypoint in km, transform to Unity coordinates and then use it to set the nav agent's destination if (navAgent != null) { navAgent.SetDestination(SimControl.ConstrainUnityDestinationToBoard( new Vector3( newWaypoint.getPos_x() * SimControl.KmToUnity, transform.position.y, // Nav agent ignores the y coordinate (altitude) newWaypoint.getPos_z() * SimControl.KmToUnity ) )); } // Set the desired altitude separately [km] SetDesiredAltitude(newWaypoint.getPos_y()); } else if (navAgent != null) { // Stay put navAgent.SetDestination(SimControl.ConstrainUnityDestinationToBoard( new Vector3(transform.position.x, transform.position.y, transform.position.z))); } } else if (motionScript != null) { // Convert position coordinates from unity to km before making new belief waypoint Belief_Waypoint newWaypoint = new Belief_Waypoint((ulong)(System.DateTime.UtcNow - epoch).Milliseconds, unique_id, motionScript.targetPosition.x / SimControl.KmToUnity, desiredAltitude_km, motionScript.targetPosition.z / SimControl.KmToUnity); addMyBeliefData(newWaypoint); } else if (wpMotionScript != null) { // Special case for blue balloon // Convert position coordinates from unity to km before making new belief waypoint /* * Belief_Waypoint newWaypoint = new Belief_Waypoint((ulong)(System.DateTime.UtcNow - epoch).Milliseconds, unique_id, * wpMotionScript.targetPosition.x / SimControl.KmToUnity, * desiredAltitude_km, * wpMotionScript.targetPosition.z / SimControl.KmToUnity); * addMyBeliefData(newWaypoint); */ Belief_WaypointPath waypointPath = beliefRepo.Find <Belief_WaypointPath>(Belief.BeliefType.WAYPOINT_PATH, unique_id); if (waypointPath != null) { wpMotionScript.SetWaypointBelief(waypointPath); } } else { // Special case for blue balloon // Convert position coordinates from unity to km before making new belief waypoint Belief_Waypoint newWaypoint = new Belief_Waypoint((ulong)(System.DateTime.UtcNow - epoch).Milliseconds, unique_id, pcMotionScript.targetPosition.x / SimControl.KmToUnity, desiredAltitude_km, pcMotionScript.targetPosition.z / SimControl.KmToUnity); addMyBeliefData(newWaypoint); } // Clear and update classifications foreach (SoaClassifier c in Classifiers) { c.UpdateClassifications(Detections); } // Update each weapon foreach (SoaWeapon w in Weapons) { w.UpdateWeapon(Detections); } // Go through each detected object's Soa Actor, get unique ID, affiliation, and pos. Broadcast belief out to everyone // Send detections to Sim Controller to be logged foreach (GameObject gameObject in Detections) { SoaActor soaActor = gameObject.GetComponent <SoaActor>(); // Actor's position must be converted from Unity to km when generating belief Belief_Actor detectedActor; if (classificationDictionary.ContainsKey(soaActor.unique_id) && classificationDictionary[soaActor.unique_id]) { // Me or one of my peers has classified this actor before, provide actual affiliation, isWeaponized info, and storage detectedActor = new Belief_Actor( soaActor.unique_id, (int)soaActor.affiliation, soaActor.type, soaActor.isAlive, soaActor.numStorageSlots, soaActor.numCasualtiesStored, soaActor.numSuppliesStored, soaActor.numCiviliansStored, soaActor.isWeaponized, soaActor.hasJammer, soaActor.fuelRemaining_s, gameObject.transform.position.x / SimControl.KmToUnity, soaActor.simAltitude_km, gameObject.transform.position.z / SimControl.KmToUnity); } else { // No one that I'm aware of has classified this actor before, hide affiliation, weapon/jamming, and storage detectedActor = new Belief_Actor( soaActor.unique_id, (int)Affiliation.UNCLASSIFIED, soaActor.type, soaActor.isAlive, 0, 0, 0, 0, false, false, soaActor.fuelRemaining_s, gameObject.transform.position.x / SimControl.KmToUnity, soaActor.simAltitude_km, gameObject.transform.position.z / SimControl.KmToUnity); } addMyBeliefData(detectedActor); simControlScript.logDetectedActor(unique_id, detectedActor); } Detections.Clear(); //Evaluate if grid cell changed and log if (prevHexGridCell != null) { currentCell = hexGrid.Map[transform.position]; if (prevHexGridCell != currentCell) { prevHexGridCell = currentCell; simControlScript.logGridCellMove(unique_id, currentCell.X, currentCell.Y); //Debug.LogWarning("Actor " + unique_id + " Moved to cell " + prevHexGridCell.X + " " + prevHexGridCell.Y); } } else { currentCell = hexGrid.Map[transform.position]; prevHexGridCell = currentCell; } List <Belief_Actor> localKillDetections = new List <Belief_Actor>(); lock (killDetections) { localKillDetections.AddRange(killDetections); killDetections.Clear(); } foreach (Belief_Actor belief_actor in localKillDetections) { addMyBeliefData(new Belief_Actor( belief_actor.getId(), (int)belief_actor.getAffiliation(), belief_actor.getType(), false, belief_actor.getNumStorageSlots(), belief_actor.getNumCasualtiesStored(), belief_actor.getNumSuppliesStored(), belief_actor.getNumCiviliansStored(), belief_actor.getIsWeaponized(), belief_actor.getHasJammer(), belief_actor.getFuelRemaining(), belief_actor.getPos_x(), belief_actor.getPos_y(), belief_actor.getPos_z())); } // ??? useGhostModel = false; } }
// Use this for initialization void Start() { // Save reference to my SoaActor thisSoaActor = gameObject.GetComponentInParent <SoaActor>(); }
// Use this for initialization void Start() { thisSoaActor = gameObject.GetComponentInParent <SoaActor>(); }
void Start() { boresightUnitVector = new Vector3(0, -1, 0); // Pointed straight down by default soaActor = gameObject.GetComponentInParent <SoaActor>(); }
// Awake is called first before anything else void Awake() { // Get pointer to SoaActor thisSoaActor = gameObject.GetComponent <SoaActor>(); }
// Use this for initialization void Start() { thisSoaActor = GetComponent <SoaActor>(); }
// Awake is called first before anything else void Awake() { thisSoaActor = gameObject.GetComponent <SoaActor>(); simControlScript = GameObject.FindObjectOfType <SimControl>(); }
// Awake is called first before anything else void Awake() { thisSoaActor = gameObject.GetComponent <SoaActor>(); }