public SupplyNetwork(Army army, LevelV0 level, GamePlayState gamePlayState) { this.gamePlayState = gamePlayState; NetworkNodes = new SortedDictionary<int, SupplyNode>(); NetworkConnections = new Dictionary<int, List<int>>(); // add nodes for all the entry points in our level. // caution is needed when changing, since we are calling a static method // that does a lot of writing to various locations. If this constructor // is ever called twice in one succession, disaster might arise. level.AddBuildingEntryPointsToNetwork(this); int startingPointId = level.Buildings.Single(building => building.isStartingPosition == true).nodeIdsForEntryPoints.First(); this.NetworkNodes[startingPointId].SquadsInNode = army.Squads; // instead of adding new functions to 'initialize' the units in there initial starting building, // we'll reuse the Event Queue, adding 'unit arrived' events. army.Squads.ForEach( squad => { UnityEngine.Object unitResource = Resources.Load(@"Unit"); GameObject unitTest = UnityEngine.Object.Instantiate( unitResource, Vector3.zero, Quaternion.identity) as GameObject; Unit unit = unitTest.GetComponent(typeof(Unit)) as Unit; unit.InitializeOnGameSetup(startingPointId, squad.id,this.gamePlayState); unit.gameObject.SetActive(false); GameObject.Destroy(unitTest); GameObject.Destroy(unit); }); }
// Use this for initialization void Start() { UnityEngine.Object levelV0 = Resources.Load(@"LevelV0"); GameObject levelV0Object = UnityEngine.Object.Instantiate(levelV0, Vector3.zero, Quaternion.identity) as GameObject; this.LevelData = levelV0Object.GetComponent(typeof(LevelV0)) as LevelV0; this.LevelData.Initialize(); this.blueTeamProfile = new Profile("testProfile"); this.redTeamProfile = new Profile("testEnemyTeam"); this.redTeam = new Army(this.redTeamProfile); this.blueTeam = new Army(this.blueTeamProfile); squadIdToSquadInfo = new Dictionary<Guid, Squad>(); this.redTeam.Squads.ForEach( squad => squadIdToSquadInfo[squad.id] = squad ); this.blueTeam.Squads.ForEach( squad => squadIdToSquadInfo[squad.id] = squad ); this.CurrentGameMode = GameMode.BlankState; this.CurrentInputState = InputState.BlankState; this.buildingIdToBuildingInfo = new Dictionary<Guid, Building>(); List<Building> buildings = this.LevelData.Buildings; GamePlayState.supplyLines = new SupplyNetwork(this.blueTeam, this.LevelData, this); foreach(Building building in buildings) { this.buildingIdToBuildingInfo.Add(building.buildingId, building); if(building.isStartingPosition) { // if this building is a starting point for all of our units, then // we need to let our supply network 'know', so that it knows where to // position our units in the initial configuration. GamePlayState.supplyLines.MarkAsStartingPoint(building.nodeIdsForEntryPoints.First()); } } // link up event handlers with the camera. if(Camera.allCameras.Length != 1) { throw new System.ArgumentException("we only expected one active camera"); } Camera activeCamera = Camera.allCameras[0]; TopDownCamera camera = activeCamera.GetComponentsInChildren<TopDownCamera>().First() as TopDownCamera; camera.ActionModeButtonPressed += this.ActionModeButtonPressed; this.Paused += camera.GamePausedHandler; this.UnPaused += camera.GameUnPausedHandler; }