Esempio n. 1
0
        public void Init(GameManager gameMgr, int ID, IEnumerable <FactionLimit> factionLimits, FactionSlot slot)
        {
            this.gameMgr   = gameMgr;
            this.FactionID = ID;
            this.Slot      = slot;

            this.limits.Clear();
            //add the limits that come with the faction type
            if (factionLimits != null)
            {
                foreach (FactionLimit limit in factionLimits) //go through the faction limits
                {
                    this.limits.Add(new FactionLimit          //and add them to this faction manager instance
                    {
                        code      = limit.code,
                        maxAmount = limit.maxAmount
                    });
                }
            }

            //start listening to events:
            CustomEvents.UnitCreated            += AddUnit;
            CustomEvents.UnitConversionStart    += OnUnitConversionStart;
            CustomEvents.UnitConversionComplete += OnUnitConversionComplete;
            CustomEvents.UnitDead             += RemoveUnit;
            CustomEvents.UnitInstanceUpgraded += RemoveUnit;

            CustomEvents.BuildingPlaced           += AddBuilding;
            CustomEvents.BuildingDestroyed        += RemoveBuilding;
            CustomEvents.BuildingInstanceUpgraded += RemoveBuilding;

            CustomEvents.TaskLauncherAdded   += OnTaskLauncherAdded;
            CustomEvents.TaskLauncherRemoved += OnTaskLauncherRemoved;
        }
Esempio n. 2
0
        //Randomize the order of the faction slots:
        private void RandomizeFactionSlots(int[] indexSeedList)
        {
            //do not randomize? okay. also make sure the index seed list has the same length as the faction slots amount
            if (randomFactionSlots == false || indexSeedList.Length != factions.Count)
            {
                return;
            }

            int i = 0;

            while (i < indexSeedList.Length)                       //this seed list provides the randomized faction slot indexes
            {
                if (i == indexSeedList[i] || i > indexSeedList[i]) //to avoid reswapping faction slots
                {
                    i++;
                    continue;
                }

                FactionSlot tempSlot = factions[i];
                factions[i] = factions[indexSeedList[i]];
                factions[indexSeedList[i]] = tempSlot;

                i++;
            }
        }
Esempio n. 3
0
        private Text populationText = null; //a text that shows the faction's population

        //a method that allows to update the population UI count
        private void UpdatePopulationUI(FactionSlot factionSlot, int value)
        {
            if (factionSlot.PlayerControlled) //only if this is the local player's faction
            {
                populationText.text = factionSlot.GetCurrentPopulation().ToString() + "/" + factionSlot.GetMaxPopulation().ToString();
            }
        }
Esempio n. 4
0
 //called when the maximum population slots are updated
 public void OnMaxPopulationUpdated(FactionSlot factionSlot, int value)
 {
     //if this update belongs to the faction managed by this component:
     if (factionSlot.FactionMgr.FactionID == factionMgr.FactionID)
     {
         UpdateTargetAmount(factionSlot.GetMaxPopulation());
     }
 }
 /// <summary>
 /// Called whenever a faction is eliminated.
 /// </summary>
 /// <param name="factionInfo">The FactionSlot instance of the eliminated faction.</param>
 private void OnFactionEliminated(FactionSlot factionInfo)
 {
     //if this is the current target faction?
     if (factionInfo.FactionMgr == targetFaction)
     {
         CancelAttack(); //cancel the attack
     }
 }
Esempio n. 6
0
 public void OnMaxPopulationUpdated(FactionSlot factionSlot, int value)
 {
     //if this update belongs to the faction managed by this component:
     if (factionSlot.FactionMgr.FactionID == factionMgr.FactionID)
     {
         maxPopulation = factionSlot.GetMaxPopulation();
         CheckFreePopulationSlots(factionSlot.GetFreePopulation());
     }
 }
        /// <summary>
        /// Called whenever a faction has its maximum or current populations slots updated.
        /// </summary>
        /// <param name="factionSlot">The FactionSlot instance that manages the faction whose max or current population is updated.</param>
        /// <param name="value">The value by which the max or current population is updated.</param>
        private void OnPopulationUpdated(FactionSlot factionSlot, int value)
        {
            if (factionSlot.ID != factionMgr.FactionID) //not this NPC faction?
            {
                return;
            }

            if (factionSlot.GetFreePopulation() + pendingPopulationSlots < minFreePopulationSlots) //if the amount of free population slots is too low
            {
                Activate();                                                                        //activate this component so it can push to place population buildings.
            }
        }
        /// <summary>
        /// Called when a NPC faction is done initializing its components.
        /// </summary>
        /// <param name="factionSlot">FactionSlot of the NPC faction.</param>
        private void OnNPCFactionInit(FactionSlot factionSlot)
        {
            if (factionSlot.FactionMgr != factionMgr) //different NPC faction?
            {
                return;
            }

            //go through the spawned building centers and add their territory size to the faction's territory count
            foreach (Building buildingCenter in factionMgr.GetBuildingCenters())
            {
                UpdateCurrentTerritory(Mathf.PI * Mathf.Pow(buildingCenter.BorderComp.Size, 2));
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Called when the default entities of a faction are initialized.
        /// </summary>
        /// <param name="factionSlot">FactionSlot instance of the faction whose default entities are initialized.</param>
        private void OnFactionDefaultEntitiesInit(FactionSlot factionSlot)
        {
            if (factionSlot.FactionMgr == FactionMgr)                                   //if the faction slot is handled by this component
            {
                foreach (NPCComponent comp in GetComponentsInChildren <NPCComponent>()) //go through the NPC components and init them
                {
                    npcCompDic.Add(comp.GetType(), comp);
                    comp.Init(this.gameMgr, this, this.FactionMgr);
                }

                CustomEvents.OnNPCFactionInit(FactionMgr.Slot);
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Called when a NPC faction is done initializing its components.
        /// </summary>
        /// <param name="factionSlot">FactionSlot of the NPC faction.</param>
        private void OnNPCFactionInit(FactionSlot factionSlot)
        {
            if (factionSlot.FactionMgr != factionMgr) //different NPC faction?
            {
                return;
            }

            //go through the spawned building centers and init their registered resources.
            //can't really rely on the custom events for initializing since the Border components and Resource components will get initialiazed before this one.
            foreach (Building buildingCenter in factionMgr.GetBuildingCenters())
            {
                foreach (Resource resource in buildingCenter.BorderComp.GetResourcesInRange())
                {
                    AddBuildingCenterResource(buildingCenter, resource);
                }
            }
        }
Esempio n. 11
0
 //Population Events:
 public static void OnCurrentPopulationUpdated(FactionSlot factionSlot, int value)  //called when the current population of a faction is updated
 {
     CurrentPopulationUpdated(factionSlot, value);
 }
Esempio n. 12
0
 public static void OnNPCFactionInit(FactionSlot factionSlot)
 {
     NPCFactionInit(factionSlot);
 }
Esempio n. 13
0
 public static void OnFactionDefaultEntitiesInit(FactionSlot factionSlot)
 {
     FactionDefaultEntitiesInit(factionSlot);
 }
Esempio n. 14
0
 public static void OnFactionInit(FactionSlot factionSlot)
 {
     FactionInit(factionSlot);
 }
Esempio n. 15
0
 public static void OnFactionWin(FactionSlot factionSlot)
 {
     FactionWin(factionSlot);
 }
Esempio n. 16
0
 //Game events:
 public static void OnFactionEliminated(FactionSlot factionSlot)
 {
     FactionEliminated(factionSlot);
 }
Esempio n. 17
0
 public static void OnMaxPopulationUpdated(FactionSlot factionSlot, int value)
 {
     MaxPopulationUpdated(factionSlot, value);
 }