void BattleState::EnterState(Application &ctrl, SDL_Surface *screen) {
- monstersLayout->CalculatePositions(background->w, background->h, monsterPositions);
for (int i(0); i < 4; ++i) {
heroes[i].Position() = heroesLayout->CalculatePosition(i, background->w, background->h);
heroes[i].SpellMenu() = res->spellMenuPrototype;
smallHeroTags[i] = SmallHeroTag(this, i);
}
+ for (int i(0); i < int(monsters.size()); ++i) {
+ monsters[i].Position() = monstersLayout->CalculatePosition(i, background->w, background->h);
+ }
+
int tagHeight(attackTypeMenu.Height());
int tagWidth(attackTypeMenu.Width() * 2 + attackTypeMenu.Width() / 2);
int xOffset((Width() - 2 * tagWidth) / 2);
for (vector<Monster>::size_type i(0), end(monsters.size()); i < end; ++i) {
if (MonsterPositionOccupied(i)) {
if (monsters[i].GetAnimation().Running()) {
- monsters[i].GetAnimation().DrawCenter(screen, monsterPositions[i] + offset);
+ monsters[i].GetAnimation().DrawCenter(screen, monsters[i].Position() + offset);
} else {
- monsters[i].Sprite()->DrawCenter(screen, monsterPositions[i] + offset);
+ monsters[i].Sprite()->DrawCenter(screen, monsters[i].Position() + offset);
}
}
}
int MaxHeroes() const { return 4; }
int MaxMonsters() const { return monsters.size(); }
- 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; }
bool HeroPositionOccupied(int index) const { return index >= 0 && index < numHeroes; }
AttackTypeMenu attackTypeMenu;
MoveMenu moveMenu;
// TODO: combine all data about heros or monsters
- std::vector<geometry::Point<int> > monsterPositions;
std::vector<Monster> monsters;
std::vector<Order> attackOrder;
Hero heroes[4];
#include "AttackChoice.h"
#include "Stats.h"
+#include "../geometry/Point.h"
#include "../graphics/Animation.h"
#include <SDL.h>
const graphics::Animation *AttackAnimation() const { return attackAnimation; }
const graphics::Animation *SpellAnimation() const { return spellAnimation; }
+ geometry::Point<int> &Position() { return position; }
+ const geometry::Point<int> &Position() const { return position; }
+
// temporary setters until loader is implemented
public:
void SetName(const char *n) { name = n; }
graphics::AnimationRunner animation;
+ geometry::Point<int> position;
+
AttackChoice attackChoice;
Uint16 maxHealth, health;
TargetSelection::TargetSelection(BattleState *battle, bool multiple, bool atEnemy)
: battle(battle)
-, selected(battle ? ((int)battle->MonsterPositions().size() > battle->NumHeroes() ? (int)battle->MonsterPositions().size() : battle->NumHeroes()) : 0, State())
+, selected(battle ? (battle->MaxMonsters() > battle->NumHeroes() ? battle->MaxMonsters() : battle->NumHeroes()) : 0, State())
, selection(-1)
, cursor(0)
, multiple(multiple)
void TargetSelection::MoveRight() {
if (TargetsEnemies()) {
- cursor = (cursor + 1) % battle->MonsterPositions().size();
+ cursor = (cursor + 1) % battle->MaxMonsters();
while (!battle->MonsterPositionOccupied(cursor)) {
- cursor = (cursor + 1) % battle->MonsterPositions().size();
+ cursor = (cursor + 1) % battle->MaxMonsters();
}
} else {
cursor = (cursor + 1) % battle->NumHeroes();
void TargetSelection::MoveLeft() {
if (TargetsEnemies()) {
- cursor = (cursor + battle->MonsterPositions().size() - 1) % battle->MonsterPositions().size();
+ cursor = (cursor + battle->MaxMonsters() - 1) % battle->MaxMonsters();
FindNextEnemy();
} else {
cursor = (cursor + battle->NumHeroes() - 1) % battle->NumHeroes();
void TargetSelection::FindNextEnemy() {
int start(cursor);
while (!battle->MonsterPositionOccupied(cursor)) {
- cursor = (cursor + battle->MonsterPositions().size() - 1) % battle->MonsterPositions().size();
+ cursor = (cursor + battle->MaxMonsters() - 1) % battle->MaxMonsters();
if (cursor == start) break;
}
}
if (ts.IsBad(i)) {
numberAnimation.push_back(NumberAnimation(ts.GetAmount(i), battle->Res().numberAnimationPrototype, battle->Res().bigNumberSprite));
numberPosition.push_back(
- battle->MonsterPositions()[i]);
+ battle->MonsterAt(i).Position());
} else if (ts.IsGood(i)) {
numberAnimation.push_back(NumberAnimation(ts.GetAmount(i), battle->Res().numberAnimationPrototype, battle->Res().greenNumberSprite));
numberPosition.push_back(
- battle->MonsterPositions()[i]);
+ battle->MonsterAt(i).Position());
}
}
} else {
void PerformAttacks::RenderTargetAnimation(SDL_Surface *screen, const geometry::Vector<int> &offset) const {
if (!targetAnimation.Valid() || !targetAnimation.Running()) return;
const TargetSelection &ts(battle->CurrentAttackAttackChoice().Selection());
- for (vector<Point<int> >::size_type i(0), end(ts.TargetsHeroes() ? battle->NumHeroes() : battle->MaxMonsters()); i < end; ++i) {
- if (ts.IsSelected(i)) {
- targetAnimation.DrawCenter(screen, (ts.TargetsHeroes() ? battle->HeroAt(i).Position() : battle->MonsterPositions()[i]) + offset);
+ if (ts.TargetsHeroes()) {
+ for (vector<Point<int> >::size_type i(0), end(battle->NumHeroes()); i < end; ++i) {
+ if (ts.IsSelected(i)) {
+ targetAnimation.DrawCenter(screen, battle->HeroAt(i).Position() + offset);
+ }
+ }
+ } else {
+ for (vector<Point<int> >::size_type i(0), end(battle->MaxMonsters()); i < end; ++i) {
+ if (ts.IsSelected(i)) {
+ targetAnimation.DrawCenter(screen, battle->MonsterAt(i).Position() + offset);
+ }
}
}
}
Vector<int> indicatorOffset(cursorOffset + Vector<int>(cursorIcon->Width() / 8, cursorIcon->Height() / -8));
vector<Point<int> > positions;
if (selection->TargetsEnemies()) {
- for (vector<Point<int> >::const_iterator i(battle->MonsterPositions().begin()), end(battle->MonsterPositions().end()); i != end; ++i) {
- positions.push_back(*i);
+ for (int i(0), end(battle->MaxMonsters()); i < end; ++i) {
+ positions.push_back(battle->MonsterAt(i).Position());
}
} else {
for (int i(0), end(battle->NumHeroes()); i < end; ++i) {