void PerformAttacks::EnterState(Application &c, SDL_Surface *screen) {
ctrl = &c;
- battle->WriteOrder(order);
+ battle->CalculateAttackOrder();
numberAnimation.reserve(battle->MaxMonsters() > battle->NumHeroes() + 1 ? battle->MaxMonsters() : battle->NumHeroes() + 1);
numberPosition.reserve(numberAnimation.size());
}
void PerformAttacks::ExitState(Application &c, SDL_Surface *screen) {
+ battle->ClearAllAttacks();
ctrl = 0;
}
CheckAnimations();
if (HasAnimationsRunning()) return;
ResetAnimation();
- AdvanceCursor();
- if (Finished()) {
- battle->ClearAllAttacks();
+ battle->ApplyDamage();
+ battle->NextAttack();
+ if (battle->AttacksFinished()) {
ctrl->PopState();
return;
}
- if (order[cursor].isMonster) {
- const Monster &monster(battle->MonsterAt(order[cursor].index));
+ battle->CalculateDamage();
+
+ if (battle->CurrentAttack().isMonster) {
+ Monster &monster(battle->MonsterAt(battle->CurrentAttack().index));
titleBarText = monster.Name();
- moveAnimation = 0;
+ moveAnimation = monster.AttackAnimation();
+ targetAnimation = monster.MeleeAnimation();
+ AddNumberAnimations(battle->MonsterAttackChoiceAt(battle->CurrentAttack().index).Selection());
} else {
- Hero &hero(battle->HeroAt(order[cursor].index));
- const AttackChoice &ac(battle->AttackChoiceAt(order[cursor].index));
+ Hero &hero(battle->HeroAt(battle->CurrentAttack().index));
+ const AttackChoice &ac(battle->AttackChoiceAt(battle->CurrentAttack().index));
switch (ac.GetType()) {
case AttackChoice::SWORD:
targetAnimation = hero.MeleeAnimation();
}
moveAnimation = hero.AttackAnimation();
-
- numberAnimation.push_back(NumberAnimation(15, battle->Res().numberAnimationPrototype, battle->Res().bigNumberSprite));
- if (ac.Selection().TargetsEnemies()) {
- numberPosition.push_back(
- battle->MonsterPositions()[ac.Selection().SingleSelection()]);
- } else {
- numberPosition.push_back(
- battle->HeroesPositions()[ac.Selection().SingleSelection()]);
- }
+ AddNumberAnimations(ac.Selection());
break;
case AttackChoice::MAGIC:
titleBarText = ac.GetSpell()->Name();
}
}
+void PerformAttacks::AddNumberAnimations(const TargetSelection &ts) {
+ if (ts.TargetsEnemies()) {
+ for (int i(0); i < battle->MaxMonsters(); ++i) {
+ if (ts.IsBad(i)) {
+ numberAnimation.push_back(NumberAnimation(ts.GetAmount(i), battle->Res().numberAnimationPrototype, battle->Res().bigNumberSprite));
+ numberPosition.push_back(
+ battle->MonsterPositions()[i]);
+ } else if (ts.IsGood(i)) {
+ numberAnimation.push_back(NumberAnimation(ts.GetAmount(i), battle->Res().numberAnimationPrototype, battle->Res().greenNumberSprite));
+ numberPosition.push_back(
+ battle->MonsterPositions()[i]);
+ }
+ }
+ } else {
+ for (int i(0); i < battle->NumHeroes(); ++i) {
+ if (ts.IsBad(i)) {
+ numberAnimation.push_back(NumberAnimation(ts.GetAmount(i), battle->Res().numberAnimationPrototype, battle->Res().bigNumberSprite));
+ numberPosition.push_back(
+ battle->HeroesPositions()[i]);
+ } else if (ts.IsGood(i)) {
+ numberAnimation.push_back(NumberAnimation(ts.GetAmount(i), battle->Res().numberAnimationPrototype, battle->Res().greenNumberSprite));
+ numberPosition.push_back(
+ battle->HeroesPositions()[i]);
+ }
+ }
+ }
+}
+
void PerformAttacks::CheckAnimations() {
if (targetAnimation && targetAnimationTimer.JustHit()) {
targetAnimation->Start(*this);
numberPosition.clear();
}
-void PerformAttacks::AdvanceCursor() {
- ++cursor;
- while (cursor < int(order.size())) {
- if (order[cursor].isMonster) {
- if (battle->MonsterAt(order[cursor].index).Health() > 0) break;
- } else {
- if (battle->HeroAt(order[cursor].index).Health() > 0) break;
- }
- ++cursor;
- }
-}
-
void PerformAttacks::UpdateWorld(float deltaT) {
void PerformAttacks::RenderTargetAnimation(SDL_Surface *screen, const geometry::Vector<int> &offset) const {
if (!targetAnimation || !targetAnimation->Running()) return;
- if (order[cursor].isMonster) return; // no monsters for now
- const TargetSelection &ts(battle->AttackChoiceAt(order[cursor].index).Selection());
+ const TargetSelection &ts(battle->CurrentAttackAttackChoice().Selection());
const vector<Point<int> > &positions(ts.TargetsHeroes() ? battle->HeroesPositions() : battle->MonsterPositions());
for (vector<Point<int> >::size_type i(0), end(positions.size()); i < end; ++i) {
if (ts.IsSelected(i)) {