//init the faction without modifying the faction attributes public void Init(int factionID, FactionManager factionMgr, GameManager gameMgr) { this.ID = factionID; this.FactionMgr = factionMgr; FactionMgr.Init(gameMgr, ID, typeInfo ? typeInfo.GetLimits() : null, this); //init the faction manager component of this faction //depending on the faction type, add extra units/buildings (if there's actually any) to be created for each faction: if (playerControlled == true) //if this faction is player controlled: { if (typeInfo != null) //if this faction has a valid type. { gameMgr.PlacementMgr.AddBuildingRange(typeInfo.GetExtraBuildings()); //add the extra buildings so that this faction can use them. } } else if (IsNPCFaction() == true) //if this is not controlled by the local player but rather NPC. //Init the NPC Faction manager: { InitNPCMgr(gameMgr); } Lost = false; CustomEvents.OnFactionInit(this); }
//init the npc manager: public void InitNPCMgr(GameManager gameMgr) { //make sure there's a npc manager prefab set: if (npcMgr == null) { Debug.LogError("[Faction Slot]: NPC Manager hasn't been set for NPC faction."); return; } npcMgrIns = Object.Instantiate(npcMgr.gameObject).GetComponent <NPCManager>(); //set the faction manager: npcMgrIns.FactionMgr = FactionMgr; //init the npc manager: npcMgrIns.Init(gameMgr); if (typeInfo != null) //if this faction has a valid type. { //set the building center regulator (if there's any): if (typeInfo.GetCenterBuilding() != null) { npcMgrIns.territoryManager_NPC.centerRegulator = npcMgrIns.GetBuildingRegulatorAsset(typeInfo.GetCenterBuilding()); } //set the population building regulator (if there's any): if (typeInfo.GetPopulationBuilding() != null) { npcMgrIns.populationManager_NPC.populationBuilding = npcMgrIns.GetBuildingRegulatorAsset(typeInfo.GetPopulationBuilding()); } //is there extra buildings to add? foreach (Building b in typeInfo.GetExtraBuildings()) { if (b != null) { npcMgrIns.buildingCreator_NPC.independentBuildingRegulators.Add(npcMgrIns.GetBuildingRegulatorAsset(b)); } else { Debug.LogError($"[Game Manager]: Faction " + typeInfo.GetName() + " (Code: " + typeInfo.GetCode() + ") has missing Building fields in the 'Extra Buildings' list."); } } } }