]> git.localhorst.tv Git - l2e.git/blobdiff - src/battle/BattleState.cpp
made battle's heroes into an array
[l2e.git] / src / battle / BattleState.cpp
index b5c91f8ca6b03587bf9605111ed0e6814097e1c9..0f3fad94838f56e88a16bda2b6efbce8a788b624 100644 (file)
@@ -43,14 +43,15 @@ void BattleState::AddMonster(const Monster &m) {
 }
 
 void BattleState::AddHero(const Hero &h) {
-       if (heroes.size() >= heroesLayout->NumPositions()) {
+       if (numHeroes >= 4 || numHeroes >= (int)heroesLayout->NumPositions()) {
                throw std::overflow_error("too many heroes for layout");
        }
-       heroes.push_back(h);
+       heroes[numHeroes] = h;
+       ++numHeroes;
 }
 
-void BattleState::SwapHeroes(std::vector<Hero>::size_type lhs, std::vector<Hero>::size_type rhs) {
-       if (lhs < 0 || lhs >= heroes.size() || rhs < 0 || rhs >= heroes.size() || lhs == rhs) return;
+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]);
 }
 
@@ -63,10 +64,10 @@ void BattleState::Resize(int w, int h) {
 void BattleState::EnterState(Application &ctrl, SDL_Surface *screen) {
        monstersLayout->CalculatePositions(background->w, background->h, monsterPositions);
        heroesLayout->CalculatePositions(background->w, background->h, heroesPositions);
-       for (vector<Hero>::size_type i(0), end(heroes.size()); i < end; ++i) {
-               spellMenus.push_back(res->spellMenuPrototype);
+       for (int i(0); i < 4; ++i) {
+               spellMenus[i] = res->spellMenuPrototype;
                LoadSpellMenu(i);
-               ikariMenus.push_back(res->ikariMenuPrototype);
+               ikariMenus[i] = res->ikariMenuPrototype;
                LoadIkariMenu(i);
                heroTags[i] = HeroTag(this, i);
        }
@@ -208,7 +209,7 @@ void BattleState::PauseState(Application &ctrl, SDL_Surface *screen) {
 
 void BattleState::ClearAllAttacks() {
        activeHero = -1;
-       for (vector<Hero>::size_type i(0), end(heroes.size()); i < end; ++i) {
+       for (int i(0); i < numHeroes; ++i) {
                attackChoices[i] = AttackChoice(this);
        }
 }
@@ -249,7 +250,7 @@ void BattleState::RenderMonsters(SDL_Surface *screen, const Vector<int> &offset)
 }
 
 void BattleState::RenderHeroes(SDL_Surface *screen, const Vector<int> &offset) {
-       for (vector<Hero>::size_type i(0), end(heroes.size()); i < end; ++i) {
+       for (int i(0); i < numHeroes; ++i) {
                heroes[i].Sprite()->DrawCenterBottom(screen, heroesPositions[i] + offset, 0, 1);
        }
 }
@@ -258,7 +259,7 @@ void BattleState::RenderHeroTags(SDL_Surface *screen, const Vector<int> &offset)
        int tagHeight(attackTypeMenu.Height());
        int tagWidth(attackTypeMenu.Width() * 2 + attackTypeMenu.Width() / 2);
 
-       for (vector<Hero>::size_type i(0), end(heroes.size()); i < end; ++i) {
+       for (int i(0); i < numHeroes; ++i) {
                heroTags[i].Render(screen, tagWidth, tagHeight, heroTagPositions[i] + offset, (int)i == activeHero);
        }
 }