Esempio n. 1
0
 public virtual void InitManagers(NPCManager npcMgr, FactionManager factionMgr)
 {
     this.npcMgr     = npcMgr;
     this.factionMgr = factionMgr;
 }
Esempio n. 2
0
        //init the faction slot and update the faction attributes
        public void Init(string name, FactionTypeInfo typeInfo, Color color, bool playerControlled, int population, NPCManager npcMgr, FactionManager factionMgr, int factionID, GameManager gameMgr)
        {
            this.name             = name;
            this.typeInfo         = typeInfo;
            this.color            = color;
            this.PlayerControlled = playerControlled;

            this.npcMgr = this.PlayerControlled ? null : npcMgr;

            Init(factionID, factionMgr, gameMgr);

            UpdateMaxPopulation(population, false);
        }
Esempio n. 3
0
 public override void InitManagers(NPCManager npcMgr, FactionManager factionMgr)
 {
     base.InitManagers(npcMgr, factionMgr);
     terrainMgr = TerrainManager.Instance;
 }
        private NPCUnitCreator unitCreator_NPC; //the NPCUnitCreator instance used to create all instances of the units regulated here.
        #endregion

        #region Initializing/Terminating
        /// <summary>
        /// NPCUnitRegulator constructor.
        /// </summary>
        /// <param name="data">Holds information regarding how the unit type that will be regulated.</param>
        /// <param name="prefab">Actual Unit prefab to regulate.</param>
        /// <param name="gameMgr">GameManager instance of the currently active game.</param>
        /// <param name="npcMgr">NPCManager instance that manages the NPC faction to whome the regulator component belongs.</param>
        /// <param name="unitCreator_NPC">NPCUnitCreator instance of the NPC faction that's responsible for creating units.</param>
        public NPCUnitRegulator(NPCUnitRegulatorData data, Unit prefab, GameManager gameMgr, NPCManager npcMgr, NPCUnitCreator unitCreator_NPC)
            : base(data, prefab, gameMgr, npcMgr)
        {
            this.Data = data;
            Assert.IsNotNull(this.Data,
                             $"[NPCUnitRegulator] Initializing without NPCUnitRegulatorData instance is not allowed!");

            this.unitCreator_NPC = unitCreator_NPC;
            Assert.IsNotNull(this.unitCreator_NPC,
                             $"[NPCUnitRegulator] Initializing without a reference to the NPCBuildingCreator instance is not allowed!");

            Assert.IsNotNull(prefab,
                             $"[NPCUnitRegulator] Initializing without a reference to the unit's prefab is not allowed!");

            //pick the rest random settings from the given info.
            ratio = Data.GetRatio();

            //update the target amount
            UpdateTargetCount();

            //go through all spawned units to see if the units that should be regulated by this instance are created or not:
            foreach (Unit u in this.factionMgr.GetUnits())
            {
                Add(u);
            }

            //go through all spawned task launchers of the faction and track the ones that include tasks to create the regulated unit type.
            foreach (TaskLauncher tl in this.factionMgr.GetTaskLaunchers())
            {
                AddTaskLauncher(tl);
            }

            //start listening to the required delegate events:
            CustomEvents.UnitCreated            += Add;
            CustomEvents.UnitConversionComplete += OnUnitConversionComplete;
            CustomEvents.UnitDead += Remove;

            CustomEvents.TaskLaunched        += OnTaskLaunched;
            CustomEvents.TaskCanceled        += OnTaskCanceled;
            CustomEvents.TaskLauncherAdded   += OnTaskLauncherAdded;
            CustomEvents.TaskLauncherRemoved += OnTaskLauncherRemoved;

            CustomEvents.MaxPopulationUpdated += OnMaxPopulationUpdated;
        }