void PerformAttacks::EnterState(Application &c, SDL_Surface *screen) {
ctrl = &c;
+ battle->WriteOrder(order);
}
void PerformAttacks::ExitState(Application &c, SDL_Surface *screen) {
}
void PerformAttacks::ResumeState(Application &ctrl, SDL_Surface *screen) {
- fakeMoveTimer = GraphicsTimers().StartCountdown(850);
+
}
void PerformAttacks::PauseState(Application &ctrl, SDL_Surface *screen) {
void PerformAttacks::HandleEvents(const Input &input) {
- if (fakeMoveTimer.JustHit()) {
- if (monsters) {
- if (titleBarText) {
- titleBarText = 0;
- ++cursor;
- while (cursor < battle->MaxMonsters() && !battle->MonsterPositionOccupied(cursor)) {
- ++cursor;
- }
- if (cursor >= battle->MaxMonsters()) {
- battle->ClearAllAttacks();
- ctrl->PopState();
- }
- } else {
- if (cursor == 0) {
- if (battle->HeroAt(battle->NumHeroes() - 1).AttackAnimation()) {
- battle->HeroAt(battle->NumHeroes() - 1).AttackAnimation()->Stop();
- }
- if (battle->HeroAt(battle->NumHeroes() - 1).SpellAnimation()) {
- battle->HeroAt(battle->NumHeroes() - 1).SpellAnimation()->Stop();
- }
- }
- titleBarText = battle->MonsterAt(cursor).Name();
- }
+ if (titleBarTimer.Running() || (moveAnimation && moveAnimation->Running())) return;
+
+ if (moveAnimation) moveAnimation->Stop();
+ titleBarTimer.Clear();
+
+ ++cursor;
+
+ while (cursor < int(order.size())) {
+ if (order[cursor].isMonster) {
+ if (battle->MonsterAt(order[cursor].index).Health() > 0) break;
} else {
- const AttackChoice &ac(battle->AttackChoiceAt(cursor));
- if (titleBarText) {
- titleBarText = 0;
-
- switch (ac.GetType()) {
- case AttackChoice::SWORD:
- if (battle->HeroAt(cursor).AttackAnimation()) {
- battle->HeroAt(cursor).AttackAnimation()->Start(*this);
- }
- break;
- case AttackChoice::MAGIC:
- if (battle->HeroAt(cursor).SpellAnimation()) {
- battle->HeroAt(cursor).SpellAnimation()->Start(*this);
- }
- break;
- case AttackChoice::DEFEND:
- break;
- case AttackChoice::IKARI:
- if (ac.GetItem()->HasIkari()) {
- if (ac.GetItem()->GetIkari()->IsMagical()) {
- if (battle->HeroAt(cursor).SpellAnimation()) {
- battle->HeroAt(cursor).SpellAnimation()->Start(*this);
- }
- } else {
- if (battle->HeroAt(cursor).AttackAnimation()) {
- battle->HeroAt(cursor).AttackAnimation()->Start(*this);
- }
- }
- }
- break;
- case AttackChoice::ITEM:
- break;
- case AttackChoice::UNDECIDED:
- break;
- }
+ if (battle->HeroAt(order[cursor].index).Health() > 0) break;
+ }
+ ++cursor;
+ }
- ++cursor;
- if (cursor == battle->NumHeroes()) {
- cursor = 0;
- monsters = true;
- }
- } else {
- if (cursor > 0) {
- if (battle->HeroAt(cursor - 1).AttackAnimation()) {
- battle->HeroAt(cursor - 1).AttackAnimation()->Stop();
- }
- if (battle->HeroAt(cursor - 1).SpellAnimation()) {
- battle->HeroAt(cursor - 1).SpellAnimation()->Stop();
+ if (cursor >= int(order.size())) {
+ battle->ClearAllAttacks();
+ ctrl->PopState();
+ return;
+ }
+
+ if (order[cursor].isMonster) {
+ const Monster &monster(battle->MonsterAt(order[cursor].index));
+ titleBarText = monster.Name();
+ moveAnimation = 0;
+ } else {
+ Hero &hero(battle->HeroAt(order[cursor].index));
+ const AttackChoice &ac(battle->AttackChoiceAt(order[cursor].index));
+
+ switch (ac.GetType()) {
+ case AttackChoice::SWORD:
+ titleBarText = hero.HasWeapon() ? hero.Weapon()->Name() : "Melee attack!";
+ moveAnimation = hero.AttackAnimation();
+ break;
+ case AttackChoice::MAGIC:
+ titleBarText = ac.GetSpell()->Name();
+ moveAnimation = hero.SpellAnimation();
+ break;
+ case AttackChoice::DEFEND:
+ titleBarText = "Defends.";
+ moveAnimation = 0;
+ break;
+ case AttackChoice::IKARI:
+ if (ac.GetItem()->HasIkari()) {
+ titleBarText = ac.GetItem()->GetIkari()->Name();
+ if (ac.GetItem()->GetIkari()->IsMagical()) {
+ moveAnimation = hero.SpellAnimation();
+ } else {
+ moveAnimation = hero.AttackAnimation();
}
}
- switch (ac.GetType()) {
- case AttackChoice::SWORD:
- titleBarText = battle->HeroAt(cursor).HasWeapon() ? battle->HeroAt(cursor).Weapon()->Name() : "Gauntlet";
- break;
- case AttackChoice::MAGIC:
- titleBarText = ac.GetSpell()->Name();
- break;
- case AttackChoice::DEFEND:
- titleBarText = "Defends.";
- break;
- case AttackChoice::IKARI:
- titleBarText = ac.GetItem()->HasIkari() ? ac.GetItem()->GetIkari()->Name() : "No Ikari?";
- break;
- case AttackChoice::ITEM:
- titleBarText = ac.GetItem()->Name();
- break;
- case AttackChoice::UNDECIDED:
- titleBarText = "WTF???";
- break;
- }
- }
+ break;
+ case AttackChoice::ITEM:
+ titleBarText = ac.GetItem()->Name();
+ moveAnimation = 0;
+ break;
+ case AttackChoice::UNDECIDED:
+ titleBarText = "UNDECIDED";
+ moveAnimation = 0;
+ break;
}
}
+
+ titleBarTimer = GraphicsTimers().StartCountdown(1500);
+ if (moveAnimation) moveAnimation->Start(*this);
}
}
void PerformAttacks::RenderTitleBar(SDL_Surface *screen, const Vector<int> &offset) {
- if (!titleBarText) return;
+ if (!titleBarText || !titleBarTimer.Running()) return;
int height(battle->Res().titleFrame->BorderHeight() * 2 + battle->Res().titleFont->CharHeight());
battle->Res().titleFrame->Draw(screen, Point<int>(offset.X(), offset.Y()), battle->BackgroundWidth(), height);