private void Start() { this.grid = this.gridObject.GetComponent <GridManagerScript>(); this.startingPosition = transform.position; this.ship = new ShipUnity(transform.gameObject.name, int.Parse(transform.gameObject.name.ElementAt(4).ToString()), -1, -1); transform.parent.gameObject.GetComponent <ShipManager>().InstantiateShip(this.ship); }
void addOccupancyEntry() { double t = GridManagerScript.getTimeOfDay(); samplesAtHour[t] = samplesAtHour[t] + 1; capacityData[t] = capacityData[t] + percentageFilled; }
void Start() { //starting amount of money (in dollars) balance = 500; //arbitrarily set to 500 to make the demo more interesting //TODO: ask a game designer for a good starting amount and incremental value //find the script and hold it in gms (grid manager script) gms = gridManager.GetComponentInChildren <GridManagerScript> (); }
private void Awake() { Instance = this; //Getting all the BattleTileScript foreach (BattleTileScript item in FindObjectsOfType <BattleTileScript>()) { BattleTiles.Add(item); } }
private void Awake() { //Make sure only one instance of GridManager is around if (instance == null) { instance = this; } else if (instance != this) { Destroy(instance); } }
// Use this for initialization void Start() { instance = GetComponent <GridManagerScript>(); // spawn a 5 * 5 grid for (int x = 0; x < 5; x++) { for (int y = 0; y < 5; y++) { tile[x, y] = Instantiate(tilePrefab, new Vector3(x, y, 0), Quaternion.identity); tile[x, y].transform.parent = gameObject.transform; tile[x, y].GetComponent <SpriteRenderer>().sprite = tileSprite[Random.Range(0, tileSprite.Length)]; } } }
public bool InstanitateFieldWithData(List <Ship> ships) { if (ships == null || ships.Count < 1) { return(false); } GridManagerScript field = grid.GetComponent <GridManagerScript>(); field.InstantiateGrid(); foreach (Transform child in transform) { GameObject.Destroy(child.gameObject); } foreach (var item in ships) { GameObject prefab = null; switch (item.Fields.Count) { case 2: prefab = shipSize2; break; case 3: prefab = shipSize3; break; case 4: prefab = shipSize4; break; case 5: prefab = shipSize5; break; } this.InstantiateShip(prefab, field.gameField[item.PosX, item.PosY].Item1, field.gameField[item.PosX, item.PosY].Item2, item.Fields.Count, item.PosX, item.PosY, item.Rotated); } return(true); }
// Use this for initialization void Start() { //starting amount of souls //TODO: game designer souls = 3000; //needed only for creating towers with the keyboard to test out functionalities quickly myCrossbow2 = null; //2d array of booleans (when they're all true, the grid is empty and all cells are available) availableSpots = new bool[9, 6]; gms = gridManager.GetComponentInChildren <GridManagerScript> (); for (int i = 0; i < 9; i++) { for (int j = 0; j < 6; j++) { //initializing all cells to be empty at first availableSpots[i, j] = true; } } }
private void Start() { JSONReadManager.LoadFile("mapFile"); JSONReadManager.LoadFile("personalityFile"); gridInstance = GridManagerScript.instance; playerUnitManager = PlayerUnitManager.instance; enemyUnitManager = EnemyUnitManager.instance; gridInstance.Initialize(); display = GetComponent <StatDisplay>(); display.Initialize(); DisableText(); chat.InitializeChatBox(); chat.ShowAndHide(false); showingChat = false; AddMessageToChat("HOST", "Left click controls Units."); AddMessageToChat("HOST", "Right click deselects Units."); AddMessageToChat("HOST", "Press E to Prepare to Shoot."); AddMessageToChat("HOST", "Left click to shoot enemies."); AddMessageToChat("HOST", "WASD moves camera."); AddMessageToChat("HOST", "Middle Mouse rotates camera."); localTurnOver = false; networkedTurnOver = false; localStartTurn = false; networkedStartTurn = false; if (PersistentData.GetHosting()) { randomSeed = (int)System.DateTime.Now.Ticks; ChampNetManager.SendSeedMessage(randomSeed); InitUnitManagers(randomSeed); } }
// Removes a car from the lot and spawns an avatar void ReleaseCar() { if (currentOccupancy > 0) { GridManagerScript.numberOfVehicles[GridManagerScript.getTimeOfDay()] += 1; --currentOccupancy; percentageFilled = currentOccupancy * 1.0f / capacity * 1.0f; GetComponent <NodeScript>().myManager.SpawnDiffusionAvatar(GetComponent <NodeScript>(), entering: false); addOccupancyEntry(); } if (currentOccupancy < capacity) { // Checks if the lots should be open bool open = currentOccupancy < capacity && !GetComponent <NodeScript>().forceCloseParking; GetComponent <NodeScript>().openParking = open; GetComponent <NodeScript>().goal = open; //GetComponent<NodeScript>().goalDiffusion = open ? 1000000 : 0; GetComponent <NodeScript>().NodeStatus = open ? NodeScript.NODE_STATUS.END : NodeScript.NODE_STATUS.UNSEARCHED; } }
public void AddCar(DiffusionAvatarScript avatar) { if (savedSpaces.Contains(avatar.id)) { savedSpaces.Remove(avatar.id); float stayTime = RandomiseWaitTime(avatar) * timeStep; CalculateRevenue(stayTime); Invoke("ReleaseCar", stayTime); //take measurement addOccupancyEntry(); } // else if (currentOccupancy < capacity) { GridManagerScript.numberOfVehicles[GridManagerScript.getTimeOfDay()] = System.Math.Max(GridManagerScript.numberOfVehicles[GridManagerScript.getTimeOfDay()] - 1, 0); ++currentOccupancy; percentageFilled = currentOccupancy * 1.0f / capacity * 1.0f; // float stayTime = RandomiseWaitTime(avatar) * timeStep; CalculateRevenue(stayTime); Invoke("ReleaseCar", stayTime); //take measurement addOccupancyEntry(); } else { // Checks if the lots should be open bool open = currentOccupancy < capacity && !GetComponent <NodeScript>().forceCloseParking; GetComponent <NodeScript>().openParking = open; GetComponent <NodeScript>().goal = open; //GetComponent<NodeScript>().goalDiffusion = open ? 1000000 : 0; GetComponent <NodeScript>().NodeStatus = open ? NodeScript.NODE_STATUS.END : NodeScript.NODE_STATUS.UNSEARCHED; } //worthless non-nullable check }
// Set the grid manager public void SetManager(GridManagerScript newManager) { myManager = newManager; }
void Update() { //updates static if (myManager.groups.Count != groups.Length) { groups = myManager.groups.Select(x => x.GetComponent <PeakingGroup>()).ToArray(); for (int i = 0; i < myManager.groups.Count; i++) { myManager.groups[i].GetComponent <PeakingGroup>().index = i; } } //updates local if (groups.Length != staticDiffusionBases.Length) { staticDiffusionBases = new float[groups.Length]; diffusions = new float[groups.Length]; goalTests = new float[groups.Length]; redirectionDiffusion = new float[myManager.groups.Count]; redirectionStaticDiffusion = new float[myManager.groups.Count]; } //Next update /* * don't randomly spawn them * instead you should * * * Make it so that you give a number of cars to be spawned * you give a peak time for them to spawn and they spawn * * to achieve this you have to find out at each point (of time) how many cars you are supposed to spawn at each point * * check the z score for each time and make sure the % of cars that has to be spawned have been spawned * * TODO: * pre-compute Z table * and distribute spawn rate for each node * * * * */ //randomly distributes injections //waves peak around mean (rush hour) if (spawner) { //timespeedlow less spawn //timespeedhigh more spawn //double flatRandNum = UnityEngine.Random.Range(0.0f, 1.01f); //double randNum = GridManagerScript.NextGaussianDoubleBoxMuller(0, 1); //calculate random Gausian double (mean is null) timeOfDayE = (float)(GridManagerScript.hours * 1.0f + (Math.Round(GridManagerScript.minutes * 0.1f / 10, 1) % 0.6)); //get the current time double timeOfDay = GridManagerScript.getTimeOfDay(); //get the current time //this is the x value /*foreach (GameObject obj in myManager.groups) * { * * PeakingGroup group = obj.GetComponent<PeakingGroup>(); * double num = GridManagerScript.NormalDistribution(timeOfDay, group.rushHour, group.standartDeviation); * num = timeOfDay <= group.rushHour ? num : 1-num; * * * double randNumGroup = group.rushHour + group.standartDeviation * randNum; //calculate for given mean and deviation //normally distributed * if (randNumGroup < 0) randNumGroup = 24 + randNumGroup; // format for 24h time and check for negatives * // spawn more when nearing peak hour and scale chance by myManager.diffusionAvatarSpawnRate * //normal distributed chance around rush hour mean * * * * if (UnityEngine.Random.Range(0.0f, 0.5f) < num * && UnityEngine.Random.Range(0.0f, 1.0f) < group.spawnRate //injection control over current group * && UnityEngine.Random.Range(0.0f, 1.0f) < myManager.diffusionAvatarSpawnRate) //injection control overall groups * { * * // chance to spawn pre-booked parking space car * if (UnityEngine.Random.Range(0.0f, 1f) < group.reservedSpawnRate) * myManager.SpawnDiffusionAvatar(this, group: group, prebooked: true); * else * myManager.SpawnDiffusionAvatar(this, group: group, prebooked: false); * } * } */ //itteration 2 //check if you need to reset //reset if max spawned is reached already and the NumberOfCarsAtPointX is not the max //TODO if you just do a normal Z table map and spawn like that you'll solve the problem // foreach (GameObject obj in myManager.groups) // { // PeakingGroup group = obj.GetComponent<PeakingGroup>(); // int numberSpawned = group.numberAlreadySpawned; // int numberOfCarsToSpawn = group.spawnNumber; // double percentageOfCarsAtPointX = GridManagerScript.NormalDistribution(timeOfDay, group.rushHour, group.standartDeviation); // int NumberOfCarsAtPointX = (int)Math.Round(numberOfCarsToSpawn * percentageOfCarsAtPointX); // int carsToBeSpawned = NumberOfCarsAtPointX - numberSpawned; // if ( numberSpawned >= numberOfCarsToSpawn && NumberOfCarsAtPointX < numberSpawned) // group.numberAlreadySpawned = 0; // for (int i = 0; i < carsToBeSpawned; i++) // { // // chance to spawn pre-booked parking space car // if (UnityEngine.Random.Range(0.0f, 1f) < group.reservedSpawnRate) // myManager.SpawnDiffusionAvatar(this, group: group, prebooked: true); // else // myManager.SpawnDiffusionAvatar(this, group: group, prebooked: false); // group.numberAlreadySpawned += 1; // } // } //3rd itteration if (timeOfDay != previousTimeOfDay) { previousTimeOfDay = timeOfDay; foreach (GameObject obj in myManager.groups) { PeakingGroup group = obj.GetComponent <PeakingGroup>(); if (groupsSpawnBuckets.ContainsKey(group)) { int numberOfCarsToSpawn = groupsSpawnBuckets[group][timeOfDay]; //get current group spawns int actualCurrentSumForGroup = spawnGroupSums[group]; //compensate for frame rate drops //calculate expected sum at current time //e.g. it's 1545 getSumUpUntilTime calculates spawned until 1544 //predicted number of current cars at 1544 is 500 //actual sum of spawned cars is 490 //frameCompensationForGroup is 500 - 490 = 10 (i.e. need to spawn 10 more cars //to compensate for the frame skipping) //that frameCompensation is then added to the number of cars to spawn //each frame compensates for all previous frames int predictedCurrentSum = getSumUpUntilTime(groupsSpawnBuckets[group], timeOfDay); //for one group //calculate compensation int frameCompensationForGroup = (predictedCurrentSum - actualCurrentSumForGroup) > 0? (predictedCurrentSum - actualCurrentSumForGroup) : 0; for (int i = 0; i < (numberOfCarsToSpawn + frameCompensationForGroup); i++) { spawnGroupSums[group] += 1; // chance to spawn pre-booked parking space car commented out //if (UnityEngine.Random.Range(0.0f, 1f) < group.reservedSpawnRate) // myManager.SpawnDiffusionAvatar(this, group: group, prebooked: true); //else myManager.SpawnDiffusionAvatar(this, group: group, prebooked: false); GridManagerScript.numberOfVehicles[timeOfDay] += 1; } } } } } }
IEnumerator GridLeapSequence(float duration, Vector3 translation, bool moveChars = true) { //Ensure new grid is set and moved to correct position before everything jumpingchars.Clear(); float jumpHeight = 2f; CharacterAnimationStateType jumpAnim = CharacterAnimationStateType.DashUp; Vector3 cameraStartPos = MainCamera.transform.position; CameraInfoClass cic = CameraStage.CameraInfo.Where(r => r.StageIndex == currentGridIndex && !r.used).First(); Vector3 cameraOffsetChange = cic.CameraPosition - CameraManagerScript.Instance.CurrentCameraOffset; float cameraStartOrtho = MainCamera.orthographicSize; float cameraEndOrtho = cic.OrthographicSize; cic.used = true; //DONT FORGET TO ADD CAMERA OFFSET ADJUSTMENT if (moveChars) { chars = System.Array.ConvertAll(BattleManagerScript.Instance.AllCharactersOnField.Where(r => r.IsOnField).ToArray(), item => (CharacterType_Script)item); } else { chars = new CharacterType_Script[0]; } Vector3[] charStartPositions = new Vector3[chars != null ? chars.Length : 0]; Vector3[] charGridPosOffsets = new Vector3[chars != null ? chars.Length : 0]; for (int i = 0; i < (chars != null ? chars.Length : 0); i++) { charStartPositions[i] = chars[i].transform.position; BattleTileScript bts = GridManagerScript.Instance.BattleTiles.Where(r => r.Pos == chars[i].UMS.CurrentTilePos).FirstOrDefault(); if (bts.BattleTileState != BattleTileStateType.Empty || chars[i].UMS.WalkingSide != bts.WalkingSide) { BattleTileScript newGridTile = GridManagerScript.Instance.GetRandomFreeAdjacentTile(chars[i].UMS.CurrentTilePos, 5, false, chars[i].UMS.WalkingSide); Debug.Log(newGridTile.Pos); charGridPosOffsets[i] = GridManagerScript.GetTranslationBetweenTiles(GridManagerScript.Instance.BattleTiles.Where(r => r.Pos == chars[i].UMS.CurrentTilePos).First(), newGridTile); GridManagerScript.Instance.SetBattleTileState(newGridTile.Pos, BattleTileStateType.Occupied); chars[i].CurrentBattleTiles = new List <BattleTileScript>() { newGridTile }; chars[i].UMS.CurrentTilePos = newGridTile.Pos; chars[i].UMS.Pos = new List <Vector2Int>() { newGridTile.Pos }; } else { GridManagerScript.Instance.SetBattleTileState(bts.Pos, BattleTileStateType.Occupied); charGridPosOffsets[i] = Vector3.zero; } chars[i].SetAttackReady(false); if (translation == Vector3.zero && charGridPosOffsets[i] == Vector3.zero) { continue; } jumpingchars.Add(chars[i]); chars[i].SetAnimation(jumpAnim); } float timeRemaining = duration; float progress = 0; float xPos = 0f; float yPos = 0f; bool hasStarted = false; while (timeRemaining != 0 || !hasStarted) { hasStarted = true; timeRemaining = Mathf.Clamp(timeRemaining - Time.deltaTime, 0f, 9999f); progress = 1f - (timeRemaining / (duration != 0f ? duration : 1f)); MainCamera.transform.position = Vector3.Lerp(cameraStartPos, cameraStartPos + translation + cameraOffsetChange, UniversalGameBalancer.Instance.cameraTravelCurve.Evaluate(progress)); MainCamera.orthographicSize = Mathf.Lerp(cameraStartOrtho, cameraEndOrtho, progress); for (int i = 0; i < (jumpingchars != null ? jumpingchars.Count : 0); i++) { xPos = Mathf.Lerp(charStartPositions[i].x, charStartPositions[i].x + translation.x + charGridPosOffsets[i].x, UniversalGameBalancer.Instance.cameraTravelCurve.Evaluate(progress)); yPos = Mathf.Lerp(charStartPositions[i].y, charStartPositions[i].y + translation.y + charGridPosOffsets[i].y, UniversalGameBalancer.Instance.cameraTravelCurve.Evaluate(progress)); yPos += jumpHeight * UniversalGameBalancer.Instance.characterJumpCurve.Evaluate(progress); jumpingchars[i].transform.position = new Vector3(xPos, yPos, jumpingchars[i].transform.position.z); jumpingchars[i].SpineAnim.SetAnimationSpeed(UniversalGameBalancer.Instance.jumpAnimationCurve.Evaluate(progress)); } yield return(null); } CameraManagerScript.Instance.CurrentCameraOffset = cic.CameraPosition; if (chars.Length != 0) { foreach (CharacterType_Script character in BattleManagerScript.Instance.PlayerControlledCharacters) { character.SetAttackReady(true); } } }
IEnumerator MoveCharactersToFitNewGridSequence(float duration) { float jumpHeight = 2f; CharacterAnimationStateType jumpAnim = CharacterAnimationStateType.DashUp; CharacterType_Script[] chars = BattleManagerScript.Instance.PlayerControlledCharacters; List <CharacterType_Script> charsToMove = new List <CharacterType_Script>(); List <Vector3> charStartPositions = new List <Vector3>(); List <Vector3> charGridPosOffsets = new List <Vector3>(); for (int i = 0; i < (chars != null ? chars.Length : 0); i++) { if (GridManagerScript.Instance.BattleTiles.Where(r => r.Pos == chars[i].UMS.CurrentTilePos).FirstOrDefault().BattleTileState == BattleTileStateType.Blocked || GridManagerScript.Instance.BattleTiles.Where(r => r.Pos == chars[i].UMS.CurrentTilePos).FirstOrDefault().WalkingSide != chars[i].UMS.WalkingSide) { BattleTileScript newGridTile = GridManagerScript.Instance.GetRandomFreeAdjacentTile(chars[i].UMS.CurrentTilePos, 5, false, chars[i].UMS.WalkingSide); GridManagerScript.Instance.SetBattleTileState(newGridTile.Pos, BattleTileStateType.Occupied); charsToMove.Add(chars[i]); charStartPositions.Add(chars[i].transform.position); charGridPosOffsets.Add(GridManagerScript.GetTranslationBetweenTiles(GridManagerScript.Instance.BattleTiles.Where(r => r.Pos == chars[i].UMS.CurrentTilePos).First(), newGridTile)); chars[i].CurrentBattleTiles = new List <BattleTileScript>() { newGridTile }; chars[i].UMS.CurrentTilePos = newGridTile.Pos; chars[i].UMS.Pos = new List <Vector2Int>() { newGridTile.Pos }; chars[i].SetAnimation(jumpAnim); } chars[i].SetAttackReady(false); } float timeRemaining = duration; float progress = 0; float xPos = 0f; float yPos = 0f; bool hasStarted = false; while (timeRemaining != 0 || !hasStarted) { hasStarted = true; timeRemaining = Mathf.Clamp(timeRemaining - Time.deltaTime, 0f, 9999f); progress = 1f - (timeRemaining / (duration != 0f ? duration : 1f)); for (int i = 0; i < (charsToMove != null ? charsToMove.Count : 0); i++) { xPos = Mathf.Lerp(charStartPositions[i].x, charStartPositions[i].x + charGridPosOffsets[i].x, UniversalGameBalancer.Instance.cameraTravelCurve.Evaluate(progress)); yPos = Mathf.Lerp(charStartPositions[i].y, charStartPositions[i].y + charGridPosOffsets[i].y, UniversalGameBalancer.Instance.cameraTravelCurve.Evaluate(progress)); yPos += jumpHeight * UniversalGameBalancer.Instance.characterJumpCurve.Evaluate(progress); charsToMove[i].transform.position = new Vector3(xPos, yPos, charsToMove[i].transform.position.z); charsToMove[i].SpineAnim.SetAnimationSpeed(UniversalGameBalancer.Instance.jumpAnimationCurve.Evaluate(progress)); } yield return(null); } if (chars != null) { foreach (CharacterType_Script character in chars) { character.SetAttackReady(true); } } }
void Start() { grid = GridManagerScript.instance; pathRequester = PathRequestManager.instance; }