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