/// <summary> /// Swaps patrol for alert guard /// </summary> public void SwapAgents() { Guards .Zip(GuardsSwap, Tuple.Create) .ToList() .ForEach(t => { var(inPlay, outPlay) = t; Rigidbody outPlayRb = outPlay.GetComponent <Rigidbody>(); Rigidbody inPlayRb = inPlay.GetComponent <Rigidbody>(); outPlayRb.isKinematic = true; inPlayRb.isKinematic = true; //move agents outPlayRb.transform.position = inPlay.transform.position; inPlayRb.transform.position -= new Vector3(0, 100, 0); outPlayRb.isKinematic = false; inPlayRb.isKinematic = false; // stop their movement outPlayRb.velocity = Vector3.zero; inPlayRb.velocity = Vector3.zero; //swap lists Guards.Remove(inPlay); Guards.Add(outPlay); GuardsSwap.Remove(outPlay); GuardsSwap.Add(inPlay); // change Can Move inPlay.GetComponent <AbstractGuard>().CanMove = false; outPlay.GetComponent <AbstractGuard>().CanMove = true; }); }
/// <summary> /// Adds guards to the list of guards property, will only spawn up to the number of exits - 1 /// </summary> /// <param name="numberOfGuards"></param> /// <param name="inputExitCount"></param> /// <param name="inputTrainingScenario"></param> public void SpawnGuardAgent(int numberOfGuards, int inputExitCount, TrainingScenario inputTrainingScenario) { if (TileDict[TileType.GuardTiles].Count < numberOfGuards) { throw new MapCreationException("Number of guards has exceeded the number of spawn places"); } var maxNumOfGuard = MaxNumberOfGuards(numberOfGuards, inputExitCount); var indexes = RandomHelper.GetUniqueRandomList(maxNumOfGuard, TileDict[TileType.GuardTiles].Count); for (var i = 0; i < maxNumOfGuard; i++) { if (inputTrainingScenario != TrainingScenario.SpyEvade) { if (TrainingScenarioWantsPatrol(inputTrainingScenario)) { var instantiatedPatrolPrefab = Instantiate(guardPatrolPrefab, TileDict[TileType.GuardTiles][indexes[i]].Position, Quaternion.identity, transform); Guards.Add(instantiatedPatrolPrefab); GuardObservations.Add(instantiatedPatrolPrefab, new float[6]); } if (TrainingScenarioWantsAlert(inputTrainingScenario)) { var freeTiles = TileDict[TileType.GuardTiles] .Concat(TileDict[TileType.FreeTiles]) .Where(tile => tile.OnPath) .ToList(); var agentIndex = RandomHelper.GetUniqueRandomList(maxNumOfGuard, freeTiles.Count); var instantiatedAlertPrefab = Instantiate(guardAlertPrefab, freeTiles[agentIndex[i]].Position, Quaternion.identity, transform); Guards.Add(instantiatedAlertPrefab); GuardObservations.Add(instantiatedAlertPrefab, new float[6]); } } else { { var instantiatedPatrolPrefab = Instantiate(guardPatrolPrefab, TileDict[TileType.GuardTiles][indexes[i]].Position, Quaternion.identity, transform); Guards.Add(instantiatedPatrolPrefab); GuardObservations.Add(instantiatedPatrolPrefab, new float[6]); GuardsSwap.Add(Instantiate( guardAlertPrefab, TileDict[TileType.GuardTiles][indexes[i]].Position - new Vector3(0, 100, 0), Quaternion.identity, transform ) ); } } } }