ScummVM API documentation
combat_controller.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef ULTIMA4_CONTROLLERS_COMBAT_CONTROLLER_H
23 #define ULTIMA4_CONTROLLERS_COMBAT_CONTROLLER_H
24 
25 #include "ultima/ultima4/map/direction.h"
26 #include "ultima/ultima4/map/map.h"
27 #include "ultima/ultima4/controllers/controller.h"
28 #include "ultima/ultima4/core/observer.h"
29 #include "ultima/ultima4/core/types.h"
30 #include "ultima/ultima4/filesys/savegame.h"
31 #include "ultima/ultima4/game/creature.h"
32 #include "ultima/ultima4/game/game.h"
33 #include "ultima/ultima4/game/object.h"
34 #include "ultima/ultima4/game/player.h"
35 
36 namespace Ultima {
37 namespace Ultima4 {
38 
39 #define AREA_CREATURES 16
40 #define AREA_PLAYERS 8
41 
42 class CombatMap;
43 class Creature;
44 class MoveEvent;
45 class Weapon;
46 
47 typedef enum {
48  CA_ATTACK,
49  CA_CAST_SLEEP,
50  CA_ADVANCE,
51  CA_RANGED,
52  CA_FLEE,
53  CA_TELEPORT
54 } CombatAction;
55 
59 class CombatController : public Controller, public Observer<Party *, PartyEvent &>, public TurnCompleter {
60 protected:
62 public:
64  CombatController(MapId id);
65  virtual ~CombatController();
66 
67  // Accessor Methods
68  bool isCombatController() const override {
69  return true;
70  }
71 
75  void setActive() override;
76 
77  bool isCamping() const;
78  bool isWinOrLose() const;
79  Direction getExitDir() const;
80  byte getFocus() const;
81  CombatMap *getMap() const;
82  Creature *getCreature() const;
83  PartyMemberVector *getParty();
84  PartyMember *getCurrentPlayer();
85 
86  void setExitDir(Direction d);
87  void setCreature(Creature *);
88  void setWinOrLose(bool worl = true);
89  void showCombatMessage(bool show = true);
90 
91  // Methods
95  virtual void init(Creature *m);
96 
100  void initDungeonRoom(int room, Direction from);
101 
106 
110  virtual void begin();
111  virtual void end(bool adjustKarma);
112 
119  void fillCreatureTable(const Creature *creature);
120 
124  int initialNumberOfCreatures(const Creature *creature) const;
125 
129  bool isWon() const;
130 
134  bool isLost() const;
135 
139  void moveCreatures();
140 
144  void placeCreatures();
145 
149  void placePartyMembers();
150 
154  bool setActivePlayer(int player);
155  bool attackHit(Creature *attacker, Creature *defender);
156  virtual void awardLoot();
157 
158  // attack functions
159  void attack(Direction dir = DIR_NONE, int distance = 0);
160  bool attackAt(const Coords &coords, PartyMember *attacker, int dir, int range, int distance);
161  bool rangedAttack(const Coords &coords, Creature *attacker);
162  void rangedMiss(const Coords &coords, Creature *attacker);
163  bool returnWeaponToOwner(const Coords &coords, int distance, int dir, const Weapon *weapon);
164 
168  static void attackFlash(const Coords &coords, MapTile tile, int timeFactor);
169  static void attackFlash(const Coords &coords, const Common::String &tilename, int timeFactor);
170  static void doScreenAnimationsWhilePausing(int timeFactor);
171 
172  void keybinder(KeybindingAction action) override;
173 
174  void finishTurn() override;
175 
179  void movePartyMember(MoveEvent &event);
180  void update(Party *party, PartyEvent &event) override;
181 
182  // Properties
183 protected:
184  CombatMap *_map;
185 
186  PartyMemberVector _party;
187  byte _focus;
188 
189  const Creature *_creatureTable[AREA_CREATURES];
190  Creature *_creature;
191 
192  bool _camping;
193  bool _forceStandardEncounterSize;
194  bool _placePartyOnMap;
195  bool _placeCreaturesOnMap;
196  bool _winOrLose;
197  bool _showMessage;
198  Direction _exitDir;
199 
200 private:
202  const CombatController &operator=(const CombatController &);
203 
204  void init();
205 };
206 
207 extern CombatController *g_combat;
208 
212 class CombatMap : public Map {
213 public:
214  CombatMap();
215  ~CombatMap() override {}
216 
220  CreatureVector getCreatures();
221 
225  PartyMemberVector getPartyMembers();
226 
231  PartyMember *partyMemberAt(Coords coords);
232 
237  Creature *creatureAt(Coords coords);
238 
242  static MapId mapForTile(const Tile *ground, const Tile *transport, Object *obj);
243 
244  // Getters
245  bool isDungeonRoom() const {
246  return _dungeonRoom;
247  }
248  bool isAltarRoom() const {
249  return _altarRoom != VIRT_NONE;
250  }
251  bool isContextual() const {
252  return _contextual;
253  }
254  BaseVirtue getAltarRoom() const {
255  return _altarRoom;
256  }
257 
258  // Setters
259  void setAltarRoom(BaseVirtue ar) {
260  _altarRoom = ar;
261  }
262  void setDungeonRoom(bool d) {
263  _dungeonRoom = d;
264  }
265  void setContextual(bool c) {
266  _contextual = c;
267  }
268 
269  // Properties
270 protected:
271  bool _dungeonRoom;
272  BaseVirtue _altarRoom;
273  bool _contextual;
274 
275 public:
276  Coords creature_start[AREA_CREATURES];
277  Coords player_start[AREA_PLAYERS];
278 };
279 
280 bool isCombatMap(Map *punknown);
281 CombatMap *getCombatMap(Map *punknown = nullptr);
282 
283 } // End of namespace Ultima4
284 } // End of namespace Ultima
285 
286 #endif
Definition: str.h:59
Definition: map.h:134
Definition: movement.h:53
Definition: coords.h:31
Definition: observer.h:37
static void attackFlash(const Coords &coords, MapTile tile, int timeFactor)
Definition: player.h:103
void keybinder(KeybindingAction action) override
Definition: combat_controller.h:212
Definition: controller.h:153
Definition: controller.h:35
Definition: player.h:262
virtual void init(Creature *m)
Definition: detection.h:27
Definition: player.h:285
void movePartyMember(MoveEvent &event)
Definition: combat_controller.h:59
Definition: map_tile.h:34
Definition: creature.h:159
Definition: object.h:42
void initDungeonRoom(int room, Direction from)
Definition: tile.h:65
Definition: weapon.h:34
int initialNumberOfCreatures(const Creature *creature) const
Definition: containers.h:38
void fillCreatureTable(const Creature *creature)