]> git.localhorst.tv Git - l2e.git/blob - src/battle/Battle.h
e7cf8a2a2cd6f986d3201124b9e1cb34d8c6b13d
[l2e.git] / src / battle / Battle.h
1 #ifndef BATTLE_BATTLE_H_
2 #define BATTLE_BATTLE_H_
3
4 namespace battle {
5         class Hero;
6         class Monster;
7         class PartyLayout;
8         class TargetSelection;
9 }
10 namespace common {
11         class Stats;
12 }
13
14 #include "Capsule.h"
15 #include "Hero.h"
16 #include "Monster.h"
17
18 #include <vector>
19 #include <SDL.h>
20
21
22 namespace battle {
23
24 /// This class models a battle between a party of monsters and one
25 /// of heroes.
26 /// See http://luke.redirectme.net/redmine/projects/l2e/wiki/Battle for
27 /// an explanation of how to use this interface.
28 class Battle {
29
30 public:
31         Battle(const PartyLayout *heroesLayout, const PartyLayout *monstersLayout);
32
33 public:
34         void AddHero(const Hero &);
35         void AddMonster(const Monster &);
36         void SetCapsule(const Capsule &);
37
38         int NumHeroes() const;
39         int MaxHeroes() const;
40         int NumMonsters() const;
41         int MaxMonsters() const;
42         bool HasCapsule() const;
43
44         bool HeroPositionOccupied(int index) const;
45         bool HeroAlive(int index) const;
46         bool MonsterPositionOccupied(int index) const;
47         bool MonsterAlive(int index) const;
48         bool CapsuleAlive() const;
49
50         std::vector<Hero>::const_iterator HeroesBegin() const { return heroes.begin(); }
51         std::vector<Hero>::const_iterator HeroesEnd() const { return heroes.end(); }
52         Hero &HeroAt(int index);
53         const Hero &HeroAt(int index) const;
54
55         std::vector<Monster>::const_iterator MonstersBegin() const { return monsters.begin(); }
56         std::vector<Monster>::const_iterator MonstersEnd() const { return monsters.end(); }
57         Monster &MonsterAt(int index);
58         const Monster &MonsterAt(int index) const;
59
60         Capsule &GetCapsule() { return capsule; }
61         const Capsule &GetCapsule() const { return capsule; }
62
63         const PartyLayout &HeroesLayout() const { return *heroesLayout; }
64         const PartyLayout &MonstersLayout() const { return *monstersLayout; }
65
66         void NextHero();
67         bool BeforeFirstHero() const { return activeHero < 0; }
68         void PreviousHero();
69         void SwapHeroes(int lhs, int rhs);
70         Hero &ActiveHero() { return HeroAt(activeHero); }
71         const Hero &ActiveHero() const { return HeroAt(activeHero); }
72         bool IsActiveHero(int index) const { return index == activeHero; }
73         bool HasChosenAttackType() const;
74         bool AttackSelectionDone() const;
75
76         struct Order {
77                 enum Performer {
78                         HERO,
79                         CAPSULE,
80                         MONSTER,
81                 };
82                 Order(Performer by, int index = 0)
83                 : index(index), by(by) { }
84                 AttackChoice &GetAttackChoice(Battle &) const;
85                 common::Stats &GetStats(Battle &) const;
86                 bool IsHero() const { return by == HERO; }
87                 bool IsCapsule() const { return by == CAPSULE; }
88                 bool IsMonster() const { return by == MONSTER; }
89                 int index;
90                 Performer by;
91         };
92
93         void CalculateAttackOrder();
94         void NextAttack();
95         bool AttacksFinished() const;
96         void CalculateDamage();
97         void ApplyDamage();
98         const Order &CurrentAttack() const;
99         AttackChoice &CurrentAttackAttackChoice();
100         void ClearAllAttacks();
101
102         void DecideMonsterAttack(Monster &);
103         void DecideCapsuleAttack();
104         void CalculateDamage(const common::Stats &attackerStats, TargetSelection &targets) const;
105         Uint16 CalculateDamage(const common::Stats &attacker, const common::Stats &defender) const;
106
107         bool Victory() const;
108         bool Defeat() const;
109
110 private:
111         const PartyLayout *heroesLayout;
112         const PartyLayout *monstersLayout;
113         std::vector<Hero> heroes;
114         std::vector<Monster> monsters;
115         Capsule capsule;
116
117         int activeHero;
118
119         std::vector<Order> attackOrder;
120         int attackCursor;
121
122         int expReward;
123         int goldReward;
124
125 };
126
127 }
128
129 #endif