]> git.localhorst.tv Git - l2e.git/blob - src/battle/TargetSelection.h
extracted battle logic into a class
[l2e.git] / src / battle / TargetSelection.h
1 #ifndef BATTLE_TARGETSELECTION_H_
2 #define BATTLE_TARGETSELECTION_H_
3
4 namespace battle {
5         class Battle;
6 }
7 namespace common {
8         class TargetingMode;
9 }
10
11 #include <vector>
12
13
14 namespace battle {
15
16 class TargetSelection {
17
18 public:
19         TargetSelection();
20         explicit TargetSelection(Battle *battle, bool multiple = false, bool atEnemy = true);
21
22 public:
23         bool TargetsMonsters() const { return enemy; }
24         bool TargetsHeroes() const { return !TargetsMonsters(); }
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 ReadMode(const common::TargetingMode &);
35
36         void SelectMonsters();
37         void SelectHeroes();
38         void Select(int index) { selected[index].type = State::SELECTED; selection = index; }
39         void Unselect(int index) { selected[index].type = State::IGNORE; }
40         void UnselectAll() { selected.assign(selected.size(), State()); selection = -1; }
41
42         void Reset();
43         void Resize(int num) { selected.resize(num); }
44
45         void MoveUp();
46         void MoveRight();
47         void MoveDown();
48         void MoveLeft();
49         void Select() { Select(cursor); }
50         void Unselect() { Unselect(cursor); }
51         int Current() const { return cursor; }
52         bool CurrentIsSelected() { return IsSelected(cursor); }
53
54         void SetMiss(int index) { selected[index].type = State::MISS; }
55         void SetFull(int index) { selected[index].type = State::FULL; }
56         void SetGood(int index, int amount) { selected[index].type = State::GOOD; selected[index].number = amount; }
57         void SetBad(int index, int amount) { selected[index].type = State::BAD; selected[index].number = amount; }
58         int GetAmount(int index) const { return selected[index].number; }
59         bool Missed(int index) const { return selected[index].type == State::MISS; }
60         bool IsGood(int index) const { return selected[index].type == State::GOOD; }
61         bool IsBad(int index) const { return selected[index].type == State::BAD; }
62
63 private:
64         void FindNextEnemy();
65
66 private:
67         struct State {
68                 enum Type {
69                         IGNORE,
70                         SELECTED,
71                         MISS,
72                         FULL,
73                         GOOD,
74                         BAD,
75                 } type;
76                 int number;
77                 explicit State(Type type = IGNORE, int num = 0) : type(type), number(num) { }
78         };
79         Battle *battle;
80         std::vector<State> selected;
81         int selection;
82         int cursor;
83         bool multiple;
84         bool enemy;
85
86 };
87
88 }
89
90 #endif