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>(); }
private void OnSimMessageReceived(byte[] payload) { SimControl control = null; try { control = Serializer.Deserialize <SimControl>(payload.AsSpan()); } catch (Exception ex) { Logger.WriteLine(ex.ToString()); } if (control == null) { return; } if (control.Id != Id) { Logger.WriteLine($"Ignoring SimControl message for wrong id: {control.Id} instead of {Id}"); return; } if (control.Action == SimControl.START_SIM) { try { if (!_settingsReceived.Task.IsCompleted) { _settingsReceived.SetResult(control.Settings); } } catch { } // ignore potential race-condition return; } if (control.Action == SimControl.STOP_SIM) { StopAsync(); } }
// Start is called before the first frame update void Start() { Selection = gameObject.transform.Find("Range").gameObject; Selection.SetActive(false); text = gameObject.GetComponent <Text>(); control = GameObject.Find("Hero").GetComponent <SimControl>(); }
// 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>(); }
public Factions(string name, Color FacColor, Vector3 headQuartersloc, GameObject boids, SimControl s, float speed) { this.name = name; this.FacColor = FacColor; this.boids = boids; this.control = s; spe = speed; for (int i = 0; i < 5; i++) { addMember(headQuartersloc + new Vector3(Random.Range(-10, 10), 0, Random.Range(-20, 20)), Random.Range(10, 20)); } }
public async Task Run(SimControl plan) { plan.StartServices(); var deathPool = plan.Cluster.Machines .Select(p => p.Key) .Where(ApplyToMachines) .ToArray(); plan.Cluster.Routes.Select(p => p.Key); plan.Debug(LogType.RuntimeInfo, $"Monkey has plans for {string.Join(", ", deathPool)}"); while (true) { await plan.Delay(DelayBetweenStrikes(plan.Rand)); var candidate = deathPool[plan.Rand.Next(0, deathPool.Length)]; var grace = plan.Rand.Next(0, 5).Sec(); var wipe = plan.Rand.Next(0, 3) == 1; if (wipe) { plan.Debug(LogType.Fault, $"CHAOS MONKEY KILL {candidate}"); await plan.StopServices(s => s.Machine == candidate, grace : grace); plan.WipeStorage(candidate); } else { plan.Debug(LogType.Fault, $"CHAOS MONKEY REBOOT {candidate}"); await plan.StopServices(s => s.Machine == candidate, grace : grace); } await plan.Delay(plan.Rand.Next(2, 10).Sec()); plan.Debug(LogType.Fault, $"CHAOS MONKEY START {candidate}"); plan.StartServices(s => s.Machine == candidate); } }
// 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() { isSelected = false; //Initialize id array for photon idArray[0] = unique_id; // Alive at the beginning isAlive = true; displayPosition = transform.position; displayOrientation = transform.rotation; Sensors = transform.GetComponentsInChildren <SoaSensor>(); // Look at my children and populate list of classifiers Classifiers = transform.GetComponentsInChildren <SoaClassifier>(); // Look at my children and populate list of weapons Weapons = transform.GetComponentsInChildren <SoaWeapon>(); // An actor is weaponized if it has a weapon with at least one enabled mode foreach (SoaWeapon tempWeapon in Weapons) { foreach (WeaponModality tempModality in tempWeapon.modes) { if (tempModality.enabled) { isWeaponized = true; break; } } if (isWeaponized) { break; } } // Determine whether the actor has a jammer that is active jammer = transform.GetComponentInChildren <SoaJammer>(); hasJammer = jammer != null && jammer.isOn; // Get references to my motion and nav scripts motionScript = gameObject.GetComponent <SoldierWaypointMotion>(); wpMotionScript = gameObject.GetComponent <WaypointMotion>(); pcMotionScript = gameObject.GetComponent <PlanarCoordinateMotion>(); navAgent = gameObject.GetComponent <NavMeshAgent>(); hexGrid = GameObject.Find("Grid").GetComponent <SoaHexWorld>(); // Save reference to simControl simControlScript = GameObject.FindObjectOfType <SimControl>(); Debug.Log("SoaActor: Initialized all beliefDictionaries for " + gameObject.name); // Initialize a new classification dictionary classificationDictionary = new Dictionary <int, bool>(); // Initialize initial altitude to be average of min and max altitudes //simAltitude_km = 0.5f * (minAltitude_km + maxAltitude_km); //desiredAltitude_km = simAltitude_km; // Set to alive now, must be last thing done isAlive = true; nma = GetComponent <NavMeshAgent>(); }
// Awake is called before anything else void Awake() { simControlScript = GameObject.FindObjectOfType <SimControl>(); }
private static void Track104() { SimControl sim = GameObject.FindObjectOfType <SimControl>(); sim.omcScript.TrackObjectWithID(104); }
private static void StopTracking() { SimControl sim = GameObject.FindObjectOfType <SimControl>(); sim.omcScript.trackingOn = false; }
private static void NewMenuOption() { SimControl.HideShowNetworkConnectivity(); }
// Awake is called first before anything else void Awake() { thisSoaActor = gameObject.GetComponent <SoaActor>(); simControlScript = GameObject.FindObjectOfType <SimControl>(); }