]> git.localhorst.tv Git - l2e.git/blob - src/battle/TargetSelection.h
apply damage indicated by attack selection
[l2e.git] / src / battle / TargetSelection.h
1 /*
2  * TargetSelection.h
3  *
4  *  Created on: Aug 9, 2012
5  *      Author: holy
6  */
7
8 #ifndef BATTLE_TARGETSELECTION_H_
9 #define BATTLE_TARGETSELECTION_H_
10
11 #include <vector>
12
13 namespace battle {
14
15 class BattleState;
16
17 class TargetSelection {
18
19 public:
20         explicit TargetSelection(BattleState *battle = 0, bool multiple = false, bool atEnemy = true);
21
22 public:
23         bool TargetsEnemies() const { return enemy; }
24         bool TargetsHeroes() const { return !TargetsEnemies(); }
25         bool IsSelected(int index) const { return index >= 0 && index < int(selected.size()) && selected[index].type != State::IGNORE; }
26         bool HasSelected() const { return selection >= 0; }
27         int SingleSelection() const { return selection; }
28
29         bool SelectMultiple() const { return multiple; }
30         void SetMultiple() { multiple = true; }
31         bool SelectSingle() const { return !SelectMultiple(); }
32         void SetSingle() { multiple = false; }
33
34         void SelectEnemies();
35         void SelectHeroes();
36         void Select(int index) { selected[index].type = State::SELECTED; selection = index; }
37         void Unselect(int index) { selected[index].type = State::IGNORE; }
38         void UnselectAll() { selected.assign(selected.size(), State()); selection = -1; }
39
40         void Reset();
41         void Resize(int num) { selected.resize(num); }
42
43         void MoveUp();
44         void MoveRight();
45         void MoveDown();
46         void MoveLeft();
47         void Select() { Select(cursor); }
48         void Unselect() { Unselect(cursor); }
49         int Current() const { return cursor; }
50         bool CurrentIsSelected() { return IsSelected(cursor); }
51
52         void SetMiss(int index) { selected[index].type = State::MISS; }
53         void SetFull(int index) { selected[index].type = State::FULL; }
54         void SetGood(int index, int amount) { selected[index].type = State::GOOD; selected[index].number = amount; }
55         void SetBad(int index, int amount) { selected[index].type = State::BAD; selected[index].number = amount; }
56         int GetAmount(int index) const { return selected[index].number; }
57         bool Missed(int index) const { return selected[index].type == State::MISS; }
58         bool IsGood(int index) const { return selected[index].type == State::GOOD; }
59         bool IsBad(int index) const { return selected[index].type == State::BAD; }
60
61 private:
62         void FindNextEnemy();
63
64 private:
65         struct State {
66                 enum Type {
67                         IGNORE,
68                         SELECTED,
69                         MISS,
70                         FULL,
71                         GOOD,
72                         BAD,
73                 } type;
74                 int number;
75                 explicit State(Type type = IGNORE, int num = 0) : type(type), number(num) { }
76         };
77         BattleState *battle;
78         std::vector<State> selected;
79         int selection;
80         int cursor;
81         bool multiple;
82         bool enemy;
83
84 };
85
86 }
87
88 #endif /* BATTLE_TARGETSELECTION_H_ */