}
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]);
}
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) {
+ for (int i(0); i < 4; ++i) {
spellMenus[i] = res->spellMenuPrototype;
LoadSpellMenu(i);
ikariMenus[i] = res->ikariMenuPrototype;
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);
}
}
}
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);
}
}
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);
}
}
, res(res)
, attackTypeMenu(res->attackIcons)
, moveMenu(res->moveIcons)
+ , numHeroes(0)
, activeHero(-1)
, ranAway(false) { }
AttackTypeMenu &GetAttackTypeMenu() { return attackTypeMenu; }
MoveMenu &GetMoveMenu() { return moveMenu; }
- bool HasMoreHeroes() const { return activeHero < (int) heroes.size(); }
+ bool HasMoreHeroes() const { return activeHero < numHeroes; }
void NextHero() { ++activeHero; }
bool BeforeFirstHero() const { return activeHero < 0; }
void PreviousHero() { --activeHero; }
Hero &ActiveHero() { return heroes[activeHero]; }
const Hero &ActiveHero() const { return heroes[activeHero]; }
- Hero &HeroAt(std::vector<Hero>::size_type index) { return heroes[index]; }
- const Hero &HeroAt(std::vector<Hero>::size_type index) const { return heroes[index]; }
+ Hero &HeroAt(int index) { return heroes[index]; }
+ const Hero &HeroAt(int index) const { return heroes[index]; }
Monster &MonsterAt(std::vector<Monster>::size_type index) { return monsters[index]; }
const Monster &MonsterAt(std::vector<Monster>::size_type index) const { return monsters[index]; }
- void SwapHeroes(std::vector<Hero>::size_type lhs, std::vector<Hero>::size_type rhs);
+ void SwapHeroes(int lhs, int rhs);
const HeroTag &ActiveHeroTag() const { return heroTags[activeHero]; }
- const HeroTag &HeroTagAt(std::vector<Hero>::size_type index) const { return heroTags[index]; }
- const geometry::Point<int> &HeroTagPositionAt(std::vector<Hero>::size_type index) const { return heroTagPositions[index]; }
+ const HeroTag &HeroTagAt(int index) const { return heroTags[index]; }
+ const geometry::Point<int> &HeroTagPositionAt(int index) const { return heroTagPositions[index]; }
bool HasChosenAttackType() const { return attackChoices[activeHero].GetType() != AttackChoice::UNDECIDED; }
void SetAttackType(AttackChoice::Type t) { attackChoices[activeHero].SetType(t); }
AttackChoice &ActiveHeroAttackChoice() { return attackChoices[activeHero]; }
const AttackChoice &ActiveHeroAttackChoice() const { return attackChoices[activeHero]; }
- const AttackChoice &AttackChoiceAt(std::vector<Hero>::size_type index) const { return attackChoices[index]; }
+ const AttackChoice &AttackChoiceAt(int index) const { return attackChoices[index]; }
TargetSelection &ActiveHeroTargets() { return attackChoices[activeHero].Selection(); }
const TargetSelection &ActiveHeroTargets() const { return attackChoices[activeHero].Selection(); }
- bool AttackSelectionDone() const { return activeHero >= (int) heroes.size(); }
+ bool AttackSelectionDone() const { return activeHero >= numHeroes; }
graphics::Menu<const common::Spell *> &GetSpellMenu() { return spellMenus[activeHero]; }
const graphics::Menu<const common::Spell *> &GetSpellMenu() const { return spellMenus[activeHero]; }
const std::vector<geometry::Point<int> > &MonsterPositions() const { return monsterPositions; }
bool MonsterPositionOccupied(int index) { return index >= 0 && index < int(monsters.size()) && monsters[index].Health() > 0; }
const std::vector<geometry::Point<int> > &HeroesPositions() const { return heroesPositions; }
- bool HeroPositionOccupied(int index) { return index >= 0 && index < int(heroes.size()); }
- std::vector<Hero> &Heroes() { return heroes; }
- const std::vector<Hero> &Heroes() const { return heroes; }
+ bool HeroPositionOccupied(int index) { return index >= 0 && index < numHeroes; }
+ int NumHeroes() const { return numHeroes; }
std::vector<Monster> &Monsters() { return monsters; }
const std::vector<Monster> &Monsters() const { return monsters; }
std::vector<geometry::Point<int> > monsterPositions;
std::vector<geometry::Point<int> > heroesPositions;
std::vector<Monster> monsters;
- std::vector<Hero> heroes;
+ Hero heroes[4];
graphics::Menu<const common::Spell *> spellMenus[4];
graphics::Menu<const common::Item *> itemMenu;
graphics::Menu<const common::Item *> ikariMenus[4];
HeroTag heroTags[4];
geometry::Point<int> heroTagPositions[4];
AttackChoice attackChoices[4];
+ int numHeroes;
int activeHero;
bool ranAway;
TargetSelection::TargetSelection(BattleState *battle, bool multiple, bool atEnemy)
: battle(battle)
-, selected(battle ? (battle->MonsterPositions().size() > battle->Heroes().size() ? battle->MonsterPositions().size() : battle->Heroes().size()) : 0, false)
+, selected(battle ? ((int)battle->MonsterPositions().size() > battle->NumHeroes() ? (int)battle->MonsterPositions().size() : battle->NumHeroes()) : 0, false)
, selection(-1)
, cursor(0)
, multiple(multiple)
cursor = (cursor + 1) % battle->MonsterPositions().size();
}
} else {
- cursor = (cursor + 1) % battle->Heroes().size();
+ cursor = (cursor + 1) % battle->NumHeroes();
}
}
return;
}
int newCursor(cursor + 2 % 4);
- if (newCursor < int(battle->Heroes().size())) {
+ if (newCursor < battle->NumHeroes()) {
cursor = newCursor;
}
}
cursor = (cursor + battle->MonsterPositions().size() - 1) % battle->MonsterPositions().size();
FindNextEnemy();
} else {
- cursor = (cursor + battle->Heroes().size() - 1) % battle->Heroes().size();
+ cursor = (cursor + battle->NumHeroes() - 1) % battle->NumHeroes();
}
}
if (titleBarText) {
titleBarText = 0;
++cursor;
- if (cursor == (int)battle->Heroes().size()) {
+ if (cursor == battle->NumHeroes()) {
cursor = 0;
monsters = true;
}
positions.push_back(*i);
}
} else {
- for (vector<Hero>::size_type i(0), end(battle->Heroes().size()); i < end; ++i) {
+ for (int i(0), end(battle->NumHeroes()); i < end; ++i) {
Vector<int> positionCorrection(cursorIcon->Width() / 2, battle->HeroTagAt(i).HeroSprite()->Height() - cursorIcon->Height() / 2);
// indicator offsets are inverted for heroes
positionCorrection -= cursorOffset;
if (cursor > 0) {
--cursor;
} else {
- cursor = battle->Heroes().size();
+ cursor = battle->NumHeroes();
}
}
Vector<int> cursorOffset(battle->Res().swapCursor->Width() / -8, battle->Res().swapCursor->Height() / 8);
Vector<int> indicatorOffset(0, 0);
vector<Point<int> > positions;
- for (vector<Hero>::size_type i(0), end(battle->Heroes().size()); i < end; ++i) {
+ for (int i(0), end(battle->NumHeroes()); i < end; ++i) {
Vector<int> positionCorrection(battle->Res().swapCursor->Width() / 2, battle->HeroTagAt(i).HeroSprite()->Height() - battle->Res().swapCursor->Height() / 2);
// indicator offsets are inverted for heroes
positionCorrection -= cursorOffset;