]> git.localhorst.tv Git - l2e.git/blob - src/battle/states/SelectAttackType.cpp
removed useless comments
[l2e.git] / src / battle / states / SelectAttackType.cpp
1 #include "SelectAttackType.h"
2
3 #include "SelectIkari.h"
4 #include "SelectItem.h"
5 #include "SelectMoveAction.h"
6 #include "SelectSpell.h"
7 #include "SelectTarget.h"
8 #include "../AttackChoice.h"
9 #include "../BattleState.h"
10 #include "../../app/Application.h"
11 #include "../../app/Input.h"
12 #include "../../common/Item.h"
13 #include "../../math/Vector.h"
14
15 #include <stdexcept>
16
17 using app::Application;
18 using app::Input;
19 using common::Item;
20 using math::Vector;
21
22 namespace battle {
23
24 void SelectAttackType::OnEnterState(SDL_Surface *screen) {
25
26 }
27
28 void SelectAttackType::OnExitState(SDL_Surface *screen) {
29
30 }
31
32 void SelectAttackType::OnResumeState(SDL_Surface *screen) {
33         if (battle->ActiveHero().GetAttackChoice().Selection().HasSelected()) {
34                 battle->ActiveHero().GetAttackChoice().SetType(battle->GetAttackTypeMenu().Selected());
35                 battle->NextHero();
36         }
37         if (battle->AttackSelectionDone()) {
38                 // pass through
39                 Ctrl().PopState();
40         }
41 }
42
43 void SelectAttackType::OnPauseState(SDL_Surface *screen) {
44
45 }
46
47
48 void SelectAttackType::OnResize(int width, int height) {
49
50 }
51
52
53 void SelectAttackType::HandleEvents(const Input &input) {
54         if (input.IsDown(Input::PAD_UP)) {
55                 battle->GetAttackTypeMenu().Select(AttackChoice::MAGIC);
56         } else if (input.IsDown(Input::PAD_RIGHT)) {
57                 battle->GetAttackTypeMenu().Select(AttackChoice::DEFEND);
58         } else if (input.IsDown(Input::PAD_DOWN)) {
59                 battle->GetAttackTypeMenu().Select(AttackChoice::IKARI);
60         } else if (input.IsDown(Input::PAD_LEFT)) {
61                 battle->GetAttackTypeMenu().Select(AttackChoice::ITEM);
62         } else {
63                 battle->GetAttackTypeMenu().Select(AttackChoice::SWORD);
64         }
65
66         Hero &hero(battle->ActiveHero());
67         AttackChoice &ac(hero.GetAttackChoice());
68         if (input.JustPressed(Input::ACTION_A)) {
69                 switch (battle->GetAttackTypeMenu().Selected()) {
70                         case AttackChoice::SWORD:
71                                 if (hero.HasWeapon()) {
72                                         if (hero.Weapon()->GetTargetingMode().TargetsAll()) {
73                                                 ac.SetType(AttackChoice::SWORD);
74                                                 battle->NextHero();
75                                                 break;
76                                         } else {
77                                                 ac.Selection().ReadMode(hero.Weapon()->GetTargetingMode());
78                                         }
79                                 } else {
80                                         ac.Selection().SetSingle();
81                                 }
82                                 ac.Selection().Reset();
83                                 Ctrl().PushState(new SelectTarget(battle, this, &ac.Selection(), battle->Res().weaponTargetCursor));
84                                 break;
85                         case AttackChoice::MAGIC:
86                                 if (battle->ActiveHero().CanUseMagic()) {
87                                         Ctrl().PushState(new SelectSpell(battle, this));
88                                 }
89                                 break;
90                         case AttackChoice::DEFEND:
91                                 ac.SetType(AttackChoice::DEFEND);
92                                 battle->NextHero();
93                                 break;
94                         case AttackChoice::IKARI:
95                                 Ctrl().PushState(new SelectIkari(battle, this));
96                                 break;
97                         case AttackChoice::ITEM:
98                                 Ctrl().PushState(new SelectItem(battle, this));
99                                 break;
100                         default:
101                                 throw std::logic_error("selected invalid attack type");
102                 }
103         } else if (input.JustPressed(Input::ACTION_B)) {
104                 ac.Reset();
105                 battle->PreviousHero();
106                 if (battle->BeforeFirstHero()) {
107                         Ctrl().ChangeState(new SelectMoveAction(battle));
108                 } else {
109                         battle->ActiveHero().GetAttackChoice().Reset();
110                 }
111         }
112
113         if (battle->AttackSelectionDone()) {
114                 Ctrl().PopState();
115         }
116 }
117
118 void SelectAttackType::UpdateWorld(Uint32 deltaT) {
119
120 }
121
122 void SelectAttackType::Render(SDL_Surface *screen) {
123         Vector<int> offset(battle->CalculateScreenOffset(screen));
124         battle->RenderBackground(screen, offset);
125         battle->RenderMonsters(screen, offset);
126         battle->RenderHeroTags(screen, offset);
127         RenderMenu(screen, offset);
128 }
129
130 void SelectAttackType::RenderMenu(SDL_Surface *screen, const Vector<int> &offset) {
131         Vector<int> position(
132                         (battle->Width() - battle->GetAttackTypeMenu().Width()) / 2,
133                         battle->Height() - battle->GetAttackTypeMenu().Height() - battle->GetAttackTypeMenu().Height() / 2);
134         battle->GetAttackTypeMenu().Render(screen, position + offset);
135 }
136
137 }