コード例 #1
0
ファイル: RecoverSkill.cpp プロジェクト: ProjectKidona/game
Trans RecoverSkill::run(BattleScene* bs, const UserOperation* uo)
{
    const int rows = bs->getMapSet()->getHeight();
    const int cols = bs->getMapSet()->getWidth();
    UnitSet* units = bs->getUnitSet();
    Unit* targetUnit;
    RatioRecoveryExp recoverExp(30);

    // 攻撃範囲の取得
    const AttackRegion* reg = this->getAttackRegion();
    MapMatrix* attackMat = reg->createAttackMatrix(uo->targetX, uo->targetY, rows, cols, 1);

    // 攻撃範囲内の位置 && 味方ユニットを探して回復
    for (int ay = 0; ay < rows; ay++){
        for (int ax = 0; ax < cols; ax++){
            targetUnit = units->getUnit(ax, ay);

            if (attackMat->at(ax, ay) == 1 &&
                targetUnit != nullptr &&
                targetUnit->getPartyId() == uo->unit->getPartyId())
            {
                int recover = targetUnit->recover(uo->unit, &recoverExp);

                printf("%d recover\n", recover);
            }
        }
    }

    return Trans::NEXT;
}
コード例 #2
0
bool AttackConfirmState::init(BattleScene* bs)
{
    // Drawableの取得
    mp_playerStatus = bs->getDrawable("attack_confirm_player_status");
    mp_enemyStatus = bs->getDrawable("attack_confirm_enemy_status");
    mp_choice = bs->getDrawable("attack_confirm_choices");
    mp_menuCursor = bs->getDrawable("menu_cursor");

    mp_yesText = bs->getDrawable("yes_text");
    mp_noText = bs->getDrawable("no_text");

    // 表示設定
    mp_menuCursor->setPosition(535, 245);
    mp_menuCursor->setIsVisible(true);
    mp_playerStatus->setIsVisible(true);
    mp_enemyStatus->setIsVisible(true);
    mp_choice->setIsVisible(true);

    mp_yesText->setIsVisible(true);
    mp_noText->setIsVisible(true);
    
    // UnitSetの取得
    UnitSet* units = bs->getUnitSet();

    // ダメージの計算
    //m_damage = units->calcSufferedDamage(m_selectedUnitId, m_targetUnitId);
    m_damage = units->baseDamage(m_selectedUnitId, m_targetUnitId);

    return true;
}
コード例 #3
0
ファイル: Army.hpp プロジェクト: BourotBenjamin/IA_Battle_v2
    //Return the unit with the given ID
    Unit& getUnit(int id)
    {
		auto it = std::find_if(units_.begin(), units_.end(), [id](const std::shared_ptr<Unit>& unit) {
            return unit->getId()==id;
        });
        if(it == units_.end())throw std::invalid_argument("wrong id : unit "+ std::to_string(id)+" not found");
        return *(it->get());
    }
コード例 #4
0
bool CheeseStrategies::StandardPlay::startTech(BWAPI::TechType tech) {
   UnitType techBuildingType = tech.whatResearches();

    if (Broodwar->self()->completedUnitCount(techBuildingType) == 0) {
        return false;
    }

    UnitSet myUnits = BWAPI::Broodwar->self()->getUnits();
    UnitSet::iterator it;

    BWAPI::Unit* techBuilding;

    for (it=myUnits.begin(); it!=myUnits.end(); it++) {
        if ((*it)->getType() == techBuildingType) {
            techBuilding = (*it);
        }
    }

    return techBuilding->research(tech);
}
コード例 #5
0
bool CheeseStrategies::StandardPlay::startUpgrade(BWAPI::UpgradeType upgrade) {
   UnitType upBuildingType = upgrade.whatUpgrades();

    if (Broodwar->self()->completedUnitCount(upBuildingType) == 0) {
        return false;
    }

    UnitSet myUnits = BWAPI::Broodwar->self()->getUnits();
    UnitSet::iterator it;

    BWAPI::Unit* upBuilding;

    for (it=myUnits.begin(); it!=myUnits.end(); it++) {
        if ((*it)->getType() == upBuildingType) {
            upBuilding = (*it);
        }
    }

    return upBuilding->upgrade(upgrade);
}
コード例 #6
0
ファイル: Army.hpp プロジェクト: BourotBenjamin/IA_Battle_v2
 //Return the number of units
 int size()const
 {
     return units_.size();
 }
コード例 #7
0
/// Updates the danger plots values to reflect threats across the map
void CvDangerPlots::UpdateDanger(bool bPretendWarWithAllCivs, bool bIgnoreVisibility)
{
	// danger plots have not been initialized yet, so no need to update
	if(!m_bArrayAllocated)
		return;

	// wipe out values
	int iGridSize = GC.getMap().numPlots();
	CvAssertMsg(iGridSize == m_DangerPlots.size(), "iGridSize does not match number of DangerPlots");
	for(int i = 0; i < iGridSize; i++)
	{
		m_DangerPlots[i].clear();
	}

	//units we know from last turn
	UnitSet previousKnownUnits = m_knownUnits;
	m_knownUnits.clear();

	CvPlayer& thisPlayer = GET_PLAYER(m_ePlayer);
	TeamTypes thisTeam = thisPlayer.getTeam();

	// for each opposing civ
	for(int iPlayer = 0; iPlayer < MAX_PLAYERS; iPlayer++)
	{
		PlayerTypes ePlayer = (PlayerTypes)iPlayer;
		CvPlayer& loopPlayer = GET_PLAYER(ePlayer);
		TeamTypes eTeam = loopPlayer.getTeam();

		if(!loopPlayer.isAlive())
			continue;

		if(eTeam == thisTeam)
			continue;

		if(ShouldIgnorePlayer(ePlayer) && !bPretendWarWithAllCivs)
			continue;

		//for each unit
		int iLoop;
		CvUnit* pLoopUnit = NULL;
		for(pLoopUnit = loopPlayer.firstUnit(&iLoop); pLoopUnit != NULL; pLoopUnit = loopPlayer.nextUnit(&iLoop))
		{
			UpdateDangerSingleUnit(pLoopUnit, bIgnoreVisibility, true);
		}

		// for each city
		CvCity* pLoopCity;
		for(pLoopCity = loopPlayer.firstCity(&iLoop); pLoopCity != NULL; pLoopCity = loopPlayer.nextCity(&iLoop))
		{
			if(ShouldIgnoreCity(pLoopCity, bIgnoreVisibility))
				continue;

#if defined(MOD_EVENTS_CITY_BOMBARD)
			bool bIndirectFireAllowed = false;
			int iRange = pLoopCity->getBombardRange(bIndirectFireAllowed);
#else
			int iRange = GC.getCITY_ATTACK_RANGE();
#endif
			CvPlot* pCityPlot = pLoopCity->plot();
			CvPlot* pLoopPlot = NULL;
			for(int iDX = -(iRange); iDX <= iRange; iDX++)
			{
				for(int iDY = -(iRange); iDY <= iRange; iDY++)
				{
					pLoopPlot = plotXYWithRangeCheck(pCityPlot->getX(), pCityPlot->getY(), iDX, iDY, iRange);
					if(!pLoopPlot || pLoopPlot == pCityPlot)
						continue;

#if defined(MOD_EVENTS_CITY_BOMBARD)
					if (!bIndirectFireAllowed && !pCityPlot->canSeePlot(pLoopPlot, NO_TEAM, iRange, NO_DIRECTION))
						continue;
#endif
					AssignCityDangerValue(pLoopCity, pLoopPlot);
				}
			}
		}
	}

	// now compare the new known units with the previous known units
	for (UnitSet::iterator it = previousKnownUnits.begin(); it != previousKnownUnits.end(); ++it)
	{
		//might have made peace ...
		if (ShouldIgnorePlayer(it->first))
			continue;

		if (m_knownUnits.find(*it) == m_knownUnits.end())
		{
			CvUnit* pVanishedUnit = GET_PLAYER(it->first).getUnit(it->second);

			//it's still there, but moved out of sight - nevertheless count is, a human would do that as well
			//do not add it to the known units though, so next turn we will have forgotten about it
			if (pVanishedUnit)
				UpdateDangerSingleUnit(pVanishedUnit, true, false);
		}
	}

	int iPlotLoop;
	CvPlot* pPlot, *pAdjacentPlot;
	for(iPlotLoop = 0; iPlotLoop < GC.getMap().numPlots(); iPlotLoop++)
	{
		pPlot = GC.getMap().plotByIndexUnchecked(iPlotLoop);

		if(pPlot->isRevealed(thisTeam))
		{
			//remember the plot based damage, but it depends on the unit's promotions also, so we won't apply it directly
			int iPlotDamage = 0;
			if (pPlot->getFeatureType() != NO_FEATURE)
				iPlotDamage += (GC.getFeatureInfo(pPlot->getFeatureType())->getTurnDamage());
			if (pPlot->getTerrainType() != NO_FEATURE)
				iPlotDamage += (GC.getTerrainInfo(pPlot->getTerrainType())->getTurnDamage());

			m_DangerPlots[iPlotLoop].m_bFlatPlotDamage = (iPlotDamage>0);

			ImprovementTypes eImprovement = pPlot->getRevealedImprovementType(thisTeam);
			if(eImprovement != NO_IMPROVEMENT && GC.getImprovementInfo(eImprovement)->GetNearbyEnemyDamage() > 0)
			{
				if(!ShouldIgnoreCitadel(pPlot, bIgnoreVisibility))
				{
					for(int iI = 0; iI < NUM_DIRECTION_TYPES; iI++)
					{
						pAdjacentPlot = plotDirection(pPlot->getX(), pPlot->getY(), ((DirectionTypes)iI));

						if(pAdjacentPlot != NULL)
						{
							m_DangerPlots[iPlotLoop].m_pCitadel = pPlot;
						}
					}
				}
			}
		}
	}

	// testing city danger values
	CvCity* pLoopCity;
	int iLoopCity = 0;
	for(pLoopCity = thisPlayer.firstCity(&iLoopCity); pLoopCity != NULL; pLoopCity = thisPlayer.nextCity(&iLoopCity))
	{
		//adding danger would count each unit multiple times, is biased towards fast units
		//so we pretend they would all attack the city and tally up the damage
		//question is, what about our own defensive units in the area. should we count those as well?
		int iEvalRange = 4;
		int iThreatValue = 0;
		for(int iX = -iEvalRange; iX <= iEvalRange; iX++)
			for(int iY = -iEvalRange; iY <= iEvalRange; iY++)
			{
				CvPlot* pEvalPlot = plotXYWithRangeCheck(pLoopCity->getX(), pLoopCity->getY(), iX, iY, iEvalRange);
				if (pEvalPlot)
				{
					const CvUnit* pEnemy = pEvalPlot->getBestDefender(NO_PLAYER, thisPlayer.GetID(), NULL, true);
					if (pEnemy)
					{
						int iAttackerDamage = 0; //to be ignored
						iThreatValue += TacticalAIHelpers::GetSimulatedDamageFromAttackOnCity(pLoopCity,pEnemy,iAttackerDamage);
					}
				}
			}

		pLoopCity->SetThreatValue(iThreatValue);
	}

	m_bDirty = false;
}