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