]> git.localhorst.tv Git - l2e.git/blob - src/battle/Battle.h
314288c6213dbebd892bd90d85c49558aeddecf1
[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>::iterator HeroesBegin() { return heroes.begin(); }
51         std::vector<Hero>::const_iterator HeroesBegin() const { return heroes.begin(); }
52         std::vector<Hero>::iterator HeroesEnd() { return heroes.end(); }
53         std::vector<Hero>::const_iterator HeroesEnd() const { return heroes.end(); }
54         Hero &HeroAt(int index);
55         const Hero &HeroAt(int index) const;
56
57         std::vector<Monster>::const_iterator MonstersBegin() const { return monsters.begin(); }
58         std::vector<Monster>::const_iterator MonstersEnd() const { return monsters.end(); }
59         Monster &MonsterAt(int index);
60         const Monster &MonsterAt(int index) const;
61
62         Capsule &GetCapsule() { return capsule; }
63         const Capsule &GetCapsule() const { return capsule; }
64
65         const PartyLayout &HeroesLayout() const { return *heroesLayout; }
66         const PartyLayout &MonstersLayout() const { return *monstersLayout; }
67
68         void NextHero();
69         bool BeforeFirstHero() const { return activeHero < 0; }
70         void PreviousHero();
71         void SwapHeroes(int lhs, int rhs);
72         Hero &ActiveHero() { return HeroAt(activeHero); }
73         const Hero &ActiveHero() const { return HeroAt(activeHero); }
74         bool IsActiveHero(int index) const { return index == activeHero; }
75         bool HasChosenAttackType() const;
76         bool AttackSelectionDone() const;
77
78         struct Order {
79                 enum Performer {
80                         HERO,
81                         CAPSULE,
82                         MONSTER,
83                 };
84                 Order(Performer by, int index = 0)
85                 : index(index), by(by) { }
86                 AttackChoice &GetAttackChoice(Battle &) const;
87                 common::Stats &GetStats(Battle &) const;
88                 bool IsHero() const { return by == HERO; }
89                 bool IsCapsule() const { return by == CAPSULE; }
90                 bool IsMonster() const { return by == MONSTER; }
91                 int index;
92                 Performer by;
93         };
94
95         void CalculateAttackOrder();
96         void NextAttack();
97         bool AttacksFinished() const;
98         void CalculateDamage();
99         void ApplyDamage();
100         const Order &CurrentAttack() const;
101         AttackChoice &CurrentAttackAttackChoice();
102         void ClearAllAttacks();
103
104         void DecideMonsterAttack(Monster &);
105         void DecideCapsuleAttack();
106         void CalculateDamage(const common::Stats &attackerStats, TargetSelection &targets) const;
107         Uint16 CalculateDamage(const common::Stats &attacker, const common::Stats &defender) const;
108
109         bool Victory() const;
110         bool Defeat() const;
111
112         int ExpReward() const { return expReward; }
113         int GoldReward() const { return goldReward; }
114
115 private:
116         const PartyLayout *heroesLayout;
117         const PartyLayout *monstersLayout;
118         std::vector<Hero> heroes;
119         std::vector<Monster> monsters;
120         Capsule capsule;
121
122         int activeHero;
123
124         std::vector<Order> attackOrder;
125         int attackCursor;
126
127         int expReward;
128         int goldReward;
129
130 };
131
132 }
133
134 #endif