X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fbattle%2FBattleState.cpp;h=649470e894dd20e9db70c690a02d39cc938c15ac;hb=8967f42789c619df6e5874f5c6a9ea4b6b6c33db;hp=b7017c98824246b1251d8431d7223ea31e98055b;hpb=2a3e39f2960bd359dfc8df8f439281dec30c633a;p=l2e.git diff --git a/src/battle/BattleState.cpp b/src/battle/BattleState.cpp index b7017c9..649470e 100644 --- a/src/battle/BattleState.cpp +++ b/src/battle/BattleState.cpp @@ -59,6 +59,13 @@ void BattleState::NextHero() { } } +void BattleState::PreviousHero() { + --activeHero; + while (activeHero >= 0 && heroes[activeHero].Health() == 0) { + --activeHero; + } +} + void BattleState::SwapHeroes(int lhs, int rhs) { if (lhs < 0 || lhs >= numHeroes || rhs < 0 || rhs >= numHeroes || lhs == rhs) return; std::swap(heroes[lhs], heroes[rhs]); @@ -75,9 +82,9 @@ void BattleState::EnterState(Application &ctrl, SDL_Surface *screen) { heroesLayout->CalculatePositions(background->w, background->h, heroesPositions); for (int i(0); i < 4; ++i) { heroes[i].SpellMenu() = res->spellMenuPrototype; - LoadSpellMenu(i); + heroes[i].UpdateSpellMenu(); heroes[i].IkariMenu() = res->ikariMenuPrototype; - LoadIkariMenu(i); + heroes[i].UpdateIkariMenu(res); heroTags[i] = HeroTag(this, i); smallHeroTags[i] = SmallHeroTag(this, i); } @@ -103,94 +110,6 @@ void BattleState::EnterState(Application &ctrl, SDL_Surface *screen) { LoadInventory(); } -void BattleState::LoadSpellMenu(vector::size_type index) { - assert(index >= 0 && index < 4); - heroes[index].SpellMenu().Clear(); - heroes[index].SpellMenu().Reserve(HeroAt(index).Spells().size()); - for (vector::const_iterator i(HeroAt(index).Spells().begin()), end(HeroAt(index).Spells().end()); i != end; ++i) { - bool enabled((*i)->CanUseInBattle() && (*i)->Cost() <= HeroAt(index).Mana()); - heroes[index].SpellMenu().Add((*i)->Name(), *i, enabled, 0, (*i)->Cost()); - } -} - -void BattleState::LoadIkariMenu(vector::size_type index) { - assert(index >= 0 && index < 4); - heroes[index].IkariMenu().Clear(); - heroes[index].IkariMenu().Reserve(6); - - if (HeroAt(index).HasWeapon()) { - heroes[index].IkariMenu().Add( - HeroAt(index).Weapon()->Name(), - HeroAt(index).Weapon(), - HeroAt(index).Weapon()->HasIkari() && HeroAt(index).Weapon()->GetIkari()->Cost() <= HeroAt(index).IP(), - res->weaponMenuIcon, - 0, - HeroAt(index).Weapon()->HasIkari() ? HeroAt(index).Weapon()->GetIkari()->Name() : ""); - } else { - heroes[index].IkariMenu().Add(res->noEquipmentText, 0, false, res->weaponMenuIcon); - } - - if (HeroAt(index).HasArmor()) { - heroes[index].IkariMenu().Add( - HeroAt(index).Armor()->Name(), - HeroAt(index).Armor(), - HeroAt(index).Armor()->HasIkari() && HeroAt(index).Armor()->GetIkari()->Cost() <= HeroAt(index).IP(), - res->armorMenuIcon, - 0, - HeroAt(index).Armor()->HasIkari() ? HeroAt(index).Armor()->GetIkari()->Name() : ""); - } else { - heroes[index].IkariMenu().Add(res->noEquipmentText, 0, false, res->armorMenuIcon); - } - - if (HeroAt(index).HasShield()) { - heroes[index].IkariMenu().Add( - HeroAt(index).Shield()->Name(), - HeroAt(index).Shield(), - HeroAt(index).Shield()->HasIkari() && HeroAt(index).Shield()->GetIkari()->Cost() <= HeroAt(index).IP(), - res->shieldMenuIcon, - 0, - HeroAt(index).Shield()->HasIkari() ? HeroAt(index).Shield()->GetIkari()->Name() : ""); - } else { - heroes[index].IkariMenu().Add(res->noEquipmentText, 0, false, res->shieldMenuIcon); - } - - if (HeroAt(index).HasHelmet()) { - heroes[index].IkariMenu().Add( - HeroAt(index).Helmet()->Name(), - HeroAt(index).Helmet(), - HeroAt(index).Helmet()->HasIkari() && HeroAt(index).Helmet()->GetIkari()->Cost() <= HeroAt(index).IP(), - res->helmetMenuIcon, - 0, - HeroAt(index).Helmet()->HasIkari() ? HeroAt(index).Helmet()->GetIkari()->Name() : ""); - } else { - heroes[index].IkariMenu().Add(res->noEquipmentText, 0, false, res->helmetMenuIcon); - } - - if (HeroAt(index).HasRing()) { - heroes[index].IkariMenu().Add( - HeroAt(index).Ring()->Name(), - HeroAt(index).Ring(), - HeroAt(index).Ring()->HasIkari() && HeroAt(index).Ring()->GetIkari()->Cost() <= HeroAt(index).IP(), - res->ringMenuIcon, - 0, - HeroAt(index).Ring()->HasIkari() ? HeroAt(index).Ring()->GetIkari()->Name() : ""); - } else { - heroes[index].IkariMenu().Add(res->noEquipmentText, 0, false, res->ringMenuIcon); - } - - if (HeroAt(index).HasJewel()) { - heroes[index].IkariMenu().Add( - HeroAt(index).Jewel()->Name(), - HeroAt(index).Jewel(), - HeroAt(index).Jewel()->HasIkari() && HeroAt(index).Jewel()->GetIkari()->Cost() <= HeroAt(index).IP(), - res->jewelMenuIcon, - 0, - HeroAt(index).Jewel()->HasIkari() ? HeroAt(index).Jewel()->GetIkari()->Name() : ""); - } else { - heroes[index].IkariMenu().Add(res->noEquipmentText, 0, false, res->jewelMenuIcon); - } -} - void BattleState::LoadInventory() { const Inventory &inv(*res->inventory); itemMenu.Clear(); @@ -271,10 +190,9 @@ void BattleState::CalculateAttackOrder() { } for (vector::size_type i(0), end(monsters.size()); i < end; ++i) { attackOrder.push_back(Order(i, true)); + MonsterAt(i).GetAttackChoice() = AttackChoice(this); } std::sort(attackOrder.begin(), attackOrder.end(), OrderCompare(this)); - - monsterAttacks.resize(monsters.size(), AttackChoice(this)); } void BattleState::NextAttack() { @@ -299,7 +217,7 @@ bool BattleState::AttacksFinished() const { } void BattleState::CalculateDamage() { - AttackChoice &ac(CurrentAttack().isMonster ? monsterAttacks[CurrentAttack().index] : AttackChoiceAt(CurrentAttack().index)); + AttackChoice &ac(CurrentAttack().isMonster ? MonsterAt(CurrentAttack().index).GetAttackChoice() : HeroAt(CurrentAttack().index).GetAttackChoice()); if (ac.GetType() == AttackChoice::DEFEND) return; if (CurrentAttack().isMonster) { @@ -375,7 +293,7 @@ Uint16 BattleState::CalculateDamage(const Stats &attacker, const Stats &defender void BattleState::ApplyDamage() { if (attackCursor < 0) return; - AttackChoice &ac(CurrentAttack().isMonster ? monsterAttacks[CurrentAttack().index] : AttackChoiceAt(CurrentAttack().index)); + AttackChoice &ac(CurrentAttack().isMonster ? MonsterAt(CurrentAttack().index).GetAttackChoice() : HeroAt(CurrentAttack().index).GetAttackChoice()); TargetSelection &ts(ac.Selection()); if (ts.TargetsEnemies()) { for (int i(0); i < MaxMonsters(); ++i) { @@ -400,20 +318,22 @@ void BattleState::ApplyDamage() { AttackChoice &BattleState::CurrentAttackAttackChoice() { if (CurrentAttack().isMonster) { - return monsterAttacks[CurrentAttack().index]; + return MonsterAt(CurrentAttack().index).GetAttackChoice(); } else { - return AttackChoiceAt(CurrentAttack().index); + return HeroAt(CurrentAttack().index).GetAttackChoice(); } } void BattleState::ClearAllAttacks() { attackCursor = -1; activeHero = -1; - for (int i(0); i < numHeroes; ++i) { - heroes[i].GetAttackChoice() = AttackChoice(this); + for (int i(0); i < NumHeroes(); ++i) { + HeroAt(i).GetAttackChoice() = AttackChoice(this); + } + for (int i(0); i < MaxMonsters(); ++i) { + MonsterAt(i).GetAttackChoice() = AttackChoice(this); } attackOrder.clear(); - monsterAttacks.clear(); }