public int GetConstructionTime(int upgLevel, LogicLevel level, int ignoreBuildingCnt)
        {
            if (this.GetVillage2Housing() < 1)
            {
                return(this.m_constructionTimes[upgLevel]);
            }

            return(LogicDataTables.GetGlobals().GetTroopHousingBuildTimeVillage2(level, ignoreBuildingCnt));
        }
        public int GetBuildCost(int index, LogicLevel level)
        {
            if (this.GetVillage2Housing() <= 0)
            {
                if (this.m_buildingClass.IsWorker())
                {
                    return(LogicDataTables.GetGlobals().GetWorkerCost(level));
                }

                return(this.m_buildCost[index]);
            }

            return(LogicDataTables.GetGlobals().GetTroopHousingBuildCostVillage2(level));
        }
        public void CalculateHousingSpaceCap()
        {
            this.m_maxHousingSpace = 0;

            if (this.GetInstanceID() > 0)
            {
                this.m_table.GetItemAt(this.GetInstanceID() - 1); // Thx supercell for the crappy code.
            }

            LogicDataTable buildingTable  = LogicDataTables.GetTable(LogicDataType.BUILDING);
            int            dataTableCount = this.m_table.GetItemCount();

            if (dataTableCount > 0)
            {
                int unitHousingCostMultiplierForTotal         = LogicDataTables.GetGlobals().GetUnitHousingCostMultiplierForTotal();
                int spellHousingCostMultiplierForTotal        = LogicDataTables.GetGlobals().GetSpellHousingCostMultiplierForTotal();
                int heroHousingCostMultiplierForTotal         = LogicDataTables.GetGlobals().GetHeroHousingCostMultiplierForTotal();
                int allianceUnitHousingCostMultiplierForTotal = LogicDataTables.GetGlobals().GetAllianceUnitHousingCostMultiplierForTotal();

                int idx = 0;

                do
                {
                    LogicBuildingData buildingData = (LogicBuildingData)buildingTable.GetItemAt(idx);
                    int count = this.m_buildingCaps[idx];

                    if (count > 0)
                    {
                        int multiplier  = unitHousingCostMultiplierForTotal;
                        int maxUpgLevel = buildingData.GetMaxUpgradeLevelForTownHallLevel(this.GetInstanceID());

                        if (maxUpgLevel >= 0)
                        {
                            int housingSpace = buildingData.GetUnitStorageCapacity(maxUpgLevel);

                            if (!buildingData.IsAllianceCastle())
                            {
                                if (buildingData.IsForgesMiniSpells() || buildingData.IsForgesSpells())
                                {
                                    multiplier = spellHousingCostMultiplierForTotal;
                                }
                                else if (buildingData.IsHeroBarrack())
                                {
                                    housingSpace = buildingData.GetHeroData().GetHousingSpace();
                                    multiplier   = heroHousingCostMultiplierForTotal;
                                }
                            }
                            else
                            {
                                multiplier = allianceUnitHousingCostMultiplierForTotal;
                            }

                            if (housingSpace > 0)
                            {
                                this.m_maxHousingSpace += multiplier * count * housingSpace / 100;
                            }
                        }
                    }
                } while (++idx != dataTableCount);
            }
        }
        public int GetTrainingTime(int index, LogicLevel level, int additionalBarrackCount)
        {
            int trainingTime = this.m_trainingTime[index];

            if (LogicDataTables.GetGlobals().UseNewTraining() &&
                this.GetVillageType() != 1 &&
                this.GetCombatItemType() == LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER)
            {
                if (level != null)
                {
                    LogicGameObjectManager gameObjectManager = level.GetGameObjectManagerAt(0);

                    switch (this.m_unitType)
                    {
                    case 1:
                        int barrackCount    = gameObjectManager.GetBarrackCount();
                        int productionLevel = this.GetRequiredProductionHouseLevel();
                        int barrackFound    = 0;

                        for (int i = 0; i < barrackCount; i++)
                        {
                            LogicBuilding barrack = (LogicBuilding)gameObjectManager.GetBarrack(i);

                            if (barrack != null)
                            {
                                if (barrack.GetBuildingData().GetProducesUnitsOfType() == this.GetUnitOfType())
                                {
                                    if (barrack.GetUpgradeLevel() >= productionLevel)
                                    {
                                        if (!barrack.IsConstructing())
                                        {
                                            barrackFound += 1;
                                        }
                                    }
                                }
                            }
                        }

                        if (barrackFound + additionalBarrackCount <= 0)
                        {
                            return(trainingTime);
                        }

                        int[] barrackDivisor = LogicDataTables.GetGlobals().GetBarrackReduceTrainingDevisor();
                        int   divisor        = barrackDivisor[LogicMath.Min(barrackDivisor.Length - 1, barrackFound + additionalBarrackCount - 1)];

                        if (divisor > 0)
                        {
                            return(trainingTime / divisor);
                        }

                        return(trainingTime);

                    case 2:
                        barrackCount    = gameObjectManager.GetDarkBarrackCount();
                        productionLevel = this.GetRequiredProductionHouseLevel();
                        barrackFound    = 0;

                        for (int i = 0; i < barrackCount; i++)
                        {
                            LogicBuilding barrack = (LogicBuilding)gameObjectManager.GetDarkBarrack(i);

                            if (barrack != null)
                            {
                                if (barrack.GetBuildingData().GetProducesUnitsOfType() == this.GetUnitOfType())
                                {
                                    if (barrack.GetUpgradeLevel() >= productionLevel)
                                    {
                                        if (!barrack.IsConstructing())
                                        {
                                            barrackFound += 1;
                                        }
                                    }
                                }
                            }
                        }

                        if (barrackFound + additionalBarrackCount <= 0)
                        {
                            return(trainingTime);
                        }

                        barrackDivisor = LogicDataTables.GetGlobals().GetDarkBarrackReduceTrainingDevisor();
                        divisor        = barrackDivisor[LogicMath.Min(barrackDivisor.Length - 1, barrackFound + additionalBarrackCount - 1)];

                        if (divisor > 0)
                        {
                            return(trainingTime / divisor);
                        }

                        return(trainingTime);

                    default:
                        Debugger.Error("invalid type for unit");
                        break;
                    }
                }
                else
                {
                    Debugger.Error("level was null in getTrainingTime()");
                }
            }

            return(trainingTime);
        }