Пример #1
0
Battle::Result Battle::Loader(Army & army1, Army & army2, s32 mapsindex)
{
    const Settings & conf = Settings::Get();

    // pre battle army1
    if(army1.GetCommander())
    {
	if(CONTROL_AI & army1.GetControl())
    	    AI::HeroesPreBattle(*army1.GetCommander());
        else
	    army1.GetCommander()->ActionPreBattle();
    }

    // pre battle army2
    if(army2.GetCommander())
    {
	if(CONTROL_AI & army2.GetControl())
    	    AI::HeroesPreBattle(*army2.GetCommander());
        else
	    army2.GetCommander()->ActionPreBattle();
    }

    if(conf.ExtPocketLowMemory())
        AGG::ICNRegistryEnable(true);

    AGG::ResetMixer();
    bool local = (CONTROL_HUMAN & army1.GetControl()) || (CONTROL_HUMAN & army2.GetControl()) || IS_DEBUG(DBG_BATTLE, DBG_TRACE);

    Arena arena(army1, army2, mapsindex, local);

    DEBUG(DBG_BATTLE, DBG_INFO, "army1 " << army1.String());
    DEBUG(DBG_BATTLE, DBG_INFO, "army2 " << army2.String());

    while(arena.BattleValid())
	arena.Turns();

    const Result & result = arena.GetResult();
    AGG::ResetMixer();

    HeroBase* hero_wins = (result.army1 & RESULT_WINS ? army1.GetCommander() : (result.army2 & RESULT_WINS ? army2.GetCommander() : NULL));
    HeroBase* hero_loss = (result.army1 & RESULT_LOSS ? army1.GetCommander() : (result.army2 & RESULT_LOSS ? army2.GetCommander() : NULL));
    const u8 loss_result =  result.army1 & RESULT_LOSS ? result.army1 : result.army2;

    if(local)
    {
	// fade arena
	arena.FadeArena();

	// dialog summary
	arena.DialogBattleSummary(result);
    }

    // save count troop
    arena.GetForce1().SyncArmyCount();
    arena.GetForce2().SyncArmyCount();

    // after battle army1
    if(army1.GetCommander())
    {
	if(CONTROL_AI & army1.GetControl())
    	    AI::HeroesAfterBattle(*army1.GetCommander());
        else
	    army1.GetCommander()->ActionAfterBattle();
    }

    // after battle army2
    if(army2.GetCommander())
    {
	if(CONTROL_AI & army2.GetControl())
    	    AI::HeroesAfterBattle(*army2.GetCommander());
        else
	    army2.GetCommander()->ActionAfterBattle();
    }

    // pickup artifact
    if(hero_wins && hero_loss &&
	!((RESULT_RETREAT | RESULT_SURRENDER) & loss_result) &&
	Skill::Primary::HEROES == hero_wins->GetType() &&
	Skill::Primary::HEROES == hero_loss->GetType())
	PickupArtifactsAction(*hero_wins, *hero_loss, (CONTROL_HUMAN & hero_wins->GetControl()));

    // eagle eye capability
    if(hero_wins && hero_loss &&
	hero_wins->GetLevelSkill(Skill::Secondary::EAGLEEYE) &&
	Skill::Primary::HEROES == hero_loss->GetType())
	    EagleEyeSkillAction(*hero_wins, arena.GetUsageSpells(), (CONTROL_HUMAN & hero_wins->GetControl()));

    // necromancy capability
    if(hero_wins &&
	hero_wins->GetLevelSkill(Skill::Secondary::NECROMANCY))
	    NecromancySkillAction(*hero_wins, result.killed, (CONTROL_HUMAN & hero_wins->GetControl()));

    DEBUG(DBG_BATTLE, DBG_INFO, "army1 " << army1.String());
    DEBUG(DBG_BATTLE, DBG_INFO, "army2 " << army1.String());

    // update army
    if(army1.GetCommander() && Skill::Primary::HEROES == army1.GetCommander()->GetType())
    {
	// hard reset army
	if(!army1.isValid() || (result.army1 & RESULT_RETREAT)) army1.Reset(false);
    }

    // update army
    if(army2.GetCommander() && Skill::Primary::HEROES == army2.GetCommander()->GetType())
    {
	// hard reset army
        if(!army2.isValid() || (result.army2 & RESULT_RETREAT)) army2.Reset(false);
    }

    if(conf.ExtPocketLowMemory())
    {
        AGG::ICNRegistryEnable(false);
        AGG::ICNRegistryFreeObjects();
    }

    DEBUG(DBG_BATTLE, DBG_INFO, "army1: " << (result.army1 & RESULT_WINS ? "wins" : "loss") << ", army2: " << (result.army2 & RESULT_WINS ? "wins" : "loss"));

    return result;
}
Пример #2
0
Battle::Result Battle::Loader(Army & army1, Army & army2, s32 mapsindex)
{
    // pre battle army1
    if(army1.GetCommander())
    {
	if(army1.GetCommander()->isCaptain())
	    army1.GetCommander()->ActionPreBattle();
	else
	if(army1.isControlAI())
    	    AI::HeroesPreBattle(*army1.GetCommander());
        else
	    army1.GetCommander()->ActionPreBattle();
    }

    // pre battle army2
    if(army2.GetCommander())
    {
	if(army2.GetCommander()->isCaptain())
	    army2.GetCommander()->ActionPreBattle();
	else
	if(army2.isControlAI())
    	    AI::HeroesPreBattle(*army2.GetCommander());
        else
	    army2.GetCommander()->ActionPreBattle();
    }

    AGG::ResetMixer();
    bool local = army1.isControlHuman() || army2.isControlHuman();

#ifdef DEBUG
    if(IS_DEBUG(DBG_BATTLE, DBG_TRACE)) local = true;
#endif

    Arena arena(army1, army2, mapsindex, local);

    DEBUG(DBG_BATTLE, DBG_INFO, "army1 " << army1.String());
    DEBUG(DBG_BATTLE, DBG_INFO, "army2 " << army2.String());

    while(arena.BattleValid())
	arena.Turns();

    const Result & result = arena.GetResult();
    AGG::ResetMixer();

    HeroBase* hero_wins = (result.army1 & RESULT_WINS ? army1.GetCommander() : (result.army2 & RESULT_WINS ? army2.GetCommander() : NULL));
    HeroBase* hero_loss = (result.army1 & RESULT_LOSS ? army1.GetCommander() : (result.army2 & RESULT_LOSS ? army2.GetCommander() : NULL));
    const u32 loss_result =  result.army1 & RESULT_LOSS ? result.army1 : result.army2;

    if(local)
    {
	// fade arena
	arena.FadeArena();

	// dialog summary
	arena.DialogBattleSummary(result);
    }

    // save count troop
    arena.GetForce1().SyncArmyCount();
    arena.GetForce2().SyncArmyCount();

    // after battle army1
    if(army1.GetCommander())
    {
	if(army1.isControlAI())
    	    AI::HeroesAfterBattle(*army1.GetCommander());
        else
	    army1.GetCommander()->ActionAfterBattle();
    }

    // after battle army2
    if(army2.GetCommander())
    {
	if(army2.isControlAI())
    	    AI::HeroesAfterBattle(*army2.GetCommander());
        else
	    army2.GetCommander()->ActionAfterBattle();
    }

    // pickup artifact
    if(hero_wins && hero_loss &&
	!((RESULT_RETREAT | RESULT_SURRENDER) & loss_result) &&
	hero_wins->isHeroes() &&
	hero_loss->isHeroes())
	PickupArtifactsAction(*hero_wins, *hero_loss, hero_wins->isControlHuman());

    // eagle eye capability
    if(hero_wins && hero_loss &&
	hero_wins->GetLevelSkill(Skill::Secondary::EAGLEEYE) &&
	hero_loss->isHeroes())
	    EagleEyeSkillAction(*hero_wins, arena.GetUsageSpells(), hero_wins->isControlHuman());

    // necromancy capability
    if(hero_wins &&
	hero_wins->GetLevelSkill(Skill::Secondary::NECROMANCY))
	    NecromancySkillAction(*hero_wins, result.killed, hero_wins->isControlHuman());

    DEBUG(DBG_BATTLE, DBG_INFO, "army1 " << army1.String());
    DEBUG(DBG_BATTLE, DBG_INFO, "army2 " << army1.String());

    // update army
    if(army1.GetCommander() && army1.GetCommander()->isHeroes())
    {
	// hard reset army
	if(!army1.isValid() || (result.army1 & RESULT_RETREAT)) army1.Reset(false);
    }

    // update army
    if(army2.GetCommander() && army2.GetCommander()->isHeroes())
    {
	// hard reset army
        if(!army2.isValid() || (result.army2 & RESULT_RETREAT)) army2.Reset(false);
    }

    DEBUG(DBG_BATTLE, DBG_INFO, "army1: " << (result.army1 & RESULT_WINS ? "wins" : "loss") << ", army2: " << (result.army2 & RESULT_WINS ? "wins" : "loss"));

    return result;
}