Example #1
0
	void compile(const char* path, CompileOptions& compileOptions)
	{
		Buffer unitData(getDefaultAllocator());

		UnitCompiler unitCompiler(compileOptions);
		unitCompiler.compileUnit(path);

		compileOptions.write(unitCompiler.getBlob());
	}
Example #2
0
    ICityUnitTacticsPtr makeCityUnitTactics(const Player& player, const City& city, const boost::shared_ptr<UnitInfo>& pUnitInfo)
    {
        const UnitTypes unitType = pUnitInfo->getUnitType();
        const CvUnitInfo& unitInfo = gGlobals.getUnitInfo(pUnitInfo->getUnitType());
        boost::shared_ptr<UnitAnalysis> pUnitAnalysis = player.getAnalysis()->getUnitAnalysis();   

        MakeUnitTacticsVisitor visitor(player, city, pUnitInfo->getUnitType());
        boost::apply_visitor(visitor, pUnitInfo->getInfo());
        ICityUnitTacticsPtr pCityUnitTactics = visitor.getTactic();

        int maxPromotionLevel = 0;
        int freeExperience = ((CvCity*)city.getCvCity())->getProductionExperience(unitType);
        int requiredExperience = 2;
        while (freeExperience > requiredExperience)
        {
            // TODO - handle charismatic
            requiredExperience += 2 * ++maxPromotionLevel + 1;
        }

        if (unitInfo.getDomainType() == DOMAIN_LAND && unitInfo.getCombat() > 0)
        {
            if (!unitInfo.isOnlyDefensive())
            {
                {
                    UnitAnalysis::RemainingLevelsAndPromotions levelsAndPromotions = pUnitAnalysis->getCityAttackPromotions(unitType, maxPromotionLevel);

                    if (levelsAndPromotions.second.empty())
			        {
				        levelsAndPromotions = pUnitAnalysis->getCombatPromotions(unitType, maxPromotionLevel);
			        }

                    UnitData unitData(unitInfo, levelsAndPromotions.second);
                    pCityUnitTactics->addTactic(ICityUnitTacticPtr(new CityAttackUnitTactic(levelsAndPromotions.second)));
                }

                if (unitInfo.getCombatLimit() == 100)
                {
                    UnitAnalysis::RemainingLevelsAndPromotions levelsAndPromotions = pUnitAnalysis->getCombatPromotions(unitType, maxPromotionLevel);

                    UnitData unitData(unitInfo, levelsAndPromotions.second);
                    pCityUnitTactics->addTactic(ICityUnitTacticPtr(new FieldAttackUnitTactic(levelsAndPromotions.second)));
                }

                // todo - refine this check
                if (unitInfo.getCollateralDamage() > 0)
                {
                    UnitAnalysis::RemainingLevelsAndPromotions levelsAndPromotions = pUnitAnalysis->getCityAttackPromotions(unitType, maxPromotionLevel);

                    if (levelsAndPromotions.second.empty())
			        {
                        levelsAndPromotions = pUnitAnalysis->getCollateralPromotions(unitType, maxPromotionLevel);
			        }

                    UnitData unitData(unitInfo, levelsAndPromotions.second);
                    pCityUnitTactics->addTactic(ICityUnitTacticPtr(new CollateralUnitTactic(levelsAndPromotions.second)));
                }
            }

            {
                UnitAnalysis::RemainingLevelsAndPromotions levelsAndPromotions = pUnitAnalysis->getCityDefencePromotions(unitType, maxPromotionLevel);

                if (levelsAndPromotions.second.empty())
			    {
				    levelsAndPromotions = pUnitAnalysis->getCombatPromotions(unitType, maxPromotionLevel);
			    }

                UnitData unitData(unitInfo, levelsAndPromotions.second);
                pCityUnitTactics->addTactic(ICityUnitTacticPtr(new CityDefenceUnitTactic(levelsAndPromotions.second)));
            }

            {
                UnitAnalysis::RemainingLevelsAndPromotions levelsAndPromotions = pUnitAnalysis->getCombatPromotions(unitType, maxPromotionLevel);

                UnitData unitData(unitInfo, levelsAndPromotions.second);
                pCityUnitTactics->addTactic(ICityUnitTacticPtr(new FieldDefenceUnitTactic(levelsAndPromotions.second)));
            }
        }
        else if (unitInfo.getDomainType() == DOMAIN_SEA)
        {
            if (unitInfo.getCombat() > 0 && !unitInfo.isOnlyDefensive())
            {
                UnitAnalysis::RemainingLevelsAndPromotions levelsAndPromotions = pUnitAnalysis->getCombatPromotions(unitType, maxPromotionLevel);

                UnitData unitData(unitInfo, levelsAndPromotions.second);

                if (unitData.combat > 0)
                {
                    pCityUnitTactics->addTactic(ICityUnitTacticPtr(new SeaAttackUnitTactic(levelsAndPromotions.second)));
                }
            }

            if (unitInfo.getCargoSpace() > 0)
            {
                // todo
            }
        }

        return pCityUnitTactics;
    }