game_client.hpp 4.9 KB
Newer Older
louiz’'s avatar
louiz’ committed
1
2
3
4
5
6
7
8
/**
 * Main class inheriting from BaseClient, and linking the game classes
 * together: World, Camera and all GUI things.
 */

#ifndef GAME_CLIENT_HPP_INCLUDED
#define GAME_CLIENT_HPP_INCLUDED

louiz’'s avatar
louiz’ committed
9
#include <game/game.hpp>
louiz’'s avatar
louiz’ committed
10
#include <game/occupant.hpp>
louiz’'s avatar
louiz’ committed
11
12
13
#include <network/client_base.hpp>
#include <gui/screen/screen.hpp>
#include <game/selection.hpp>
louiz’'s avatar
louiz’ committed
14
15
#include <game/turn_handler.hpp>
#include <gui/hud/debug_hud.hpp>
louiz’'s avatar
louiz’ committed
16
#include <gui/hud/hud.hpp>
17
#include <game/sounds_handler.hpp>
louiz’'s avatar
louiz’ committed
18

louiz’'s avatar
louiz’ committed
19
20
#include <memory>

21
22
class Task;

louiz’'s avatar
louiz’ committed
23
class GameClient: public Game, public ClientBase
louiz’'s avatar
louiz’ committed
24
25
26
27
28
29
30
31
32
33
{
public:
  explicit GameClient(const std::shared_ptr<Screen>& screen);
  ~GameClient();
  void run();
  void install_callbacks() override final;
  void on_connection_closed() override final;

  void add_new_occupant(std::unique_ptr<Occupant>&& occupant);

louiz’'s avatar
louiz’ committed
34
  /**
35
36
   * Callbacks set in the WorldCallbacks objects. See over there for
   * comments.
louiz’'s avatar
louiz’ committed
37
   */
38
  void on_entity_created(const Entity*);
39
  void on_entity_deleted(const Entity*);
louiz’'s avatar
louiz’ committed
40
41
  void on_ability_casted(const Entity*, const AbilityType&, const Entity*,
                         const Position&);
42
  void on_impact(const Entity* entity, const Entity* target);
43
  void on_entity_task_changed(const Entity* entity, const Task* task);
louiz’'s avatar
louiz’ committed
44

louiz’'s avatar
louiz’ committed
45
46
47
48
49
  World& get_world();
  Camera& get_camera();
  Screen& get_screen();

  DebugHud& get_debug_hud();
louiz’'s avatar
louiz’ committed
50
  Hud& get_hud();
louiz’'s avatar
louiz’ committed
51
52
53
54

  /**
   * Called whenever we receive a occupant_left message from the server.
   */
louiz’'s avatar
louiz’ committed
55
  void occupant_left_callback(Message*);
56
57
58
59
  /**
   * Seed the world with the value given by the server.
   */
  void handle_seed_message(Message* message);
louiz’'s avatar
louiz’ committed
60
  /**
louiz’'s avatar
louiz’ committed
61
   * When we receive the message from the server telling us that
louiz’'s avatar
louiz’ committed
62
63
   * it is ready to start the game.
   */
louiz’'s avatar
louiz’ committed
64
  void handle_start_message(Message*);
louiz’'s avatar
louiz’ committed
65
  /**
louiz’'s avatar
louiz’ committed
66
67
   * The server tells us that this turn is ready to be executed (the server
   * already executed it, and thus no more action will be added to it)
louiz’'s avatar
louiz’ committed
68
   */
louiz’'s avatar
louiz’ committed
69
  void turn_callback(Message*);
louiz’'s avatar
louiz’ committed
70
71
72
  /**
   * The server gives a path to follow, to one or more entities.
   */
louiz’'s avatar
louiz’ committed
73
  void path_callback(Message*);
louiz’'s avatar
louiz’ committed
74
75
76
77
78
79
80
81
82
83

  /**
   * Handle an user event that may generate a real action, or nothing.
   * The coordinates are the real-world ones.
   * (for example if the user gives on order while no unit is selected, nothing
   * happens).
   * If an action is generated with this event, generate_action() is called.
   */
  // void handle_event(actions::Type type, unsigned int x, unsigned y);

louiz’'s avatar
louiz’ committed
84
85
86
  /**
   * Tick the TurnHandler and the World, if the TurnHandler is not paused.
   */
87
  bool tick();
louiz’'s avatar
louiz’ committed
88
89
90
91
92
93
  /**
   * Update all graphical object states (tiles etc)
   */
  void graphical_tick();

  /**
louiz’'s avatar
louiz’ committed
94
95
96
97
98
   * Send, to the server, a request to move the given entities to the given
   * destination. Queue indicates whether or not this work should be queued.
   */
  bool action_move(const std::vector<EntityId>& ids, const Position& pos,
                   const bool queue);
99
100
  bool action_follow(const std::vector<EntityId>& ids,
                     const EntityId& target_id, const bool queue);
louiz’'s avatar
louiz’ committed
101
102
103
104
  /**
   * Send, to the server, a request to make the list of entities cast the
   * given spell. There are three versions, each for each type of possible
   * target (Position, Entity, nothing).
louiz’'s avatar
louiz’ committed
105
   */
louiz’'s avatar
louiz’ committed
106
107
108
109
110
  bool action_cast(const std::vector<EntityId>& ids, const Position& pos,
                   const AbilityType& type, const bool queue);
  bool action_cast(const std::vector<EntityId>& ids, const EntityId target,
                   const AbilityType& type, const bool queue);
  bool action_cast(const std::vector<EntityId>& ids, const AbilityType& type,
louiz’'s avatar
louiz’ committed
111
                   const bool queue);
louiz’'s avatar
louiz’ committed
112
113
114
115
116
117
118
119
120
121
  /**
   * Give the order to all selected and movable units to move to the given
   * world coordinates with an attack order (will attack all encountered
   * enemy entity in range) OR to attack the entity under the mouse if any.
   */
  void action_attack(const unsigned int x, const unsigned y);
  void select_entity(const Entity*);
  void unselect_entity(const Entity*);
  void clear_selection();
  bool is_entity_selected(const Entity*) const;
louiz’'s avatar
louiz’ committed
122
  Selection& get_selection();
louiz’'s avatar
louiz’ committed
123
124
125
126
127
128
  const Selection& get_selection() const;
  const Selection* get_selection_ptr() const
  {
    return &this->current_selection;
  }
  void add_selection_change_callback(const t_selection_changed_callback);
129
  void set_self_team(const uint16_t team);
130
  uint16_t get_self_team() const;
louiz’'s avatar
louiz’ committed
131
132
133
134
135

private:
  /**
   * Called by the world object when a turn ends and a new one starts
   */
louiz’'s avatar
louiz’ committed
136
  void on_next_turn(TurnNb turn);
louiz’'s avatar
louiz’ committed
137
138
139
  /**
   * Called whenever we receive a new_occupant message from the server.
   */
louiz’'s avatar
louiz’ committed
140
  void new_occupant_callback(Message*);
louiz’'s avatar
louiz’ committed
141
142
143
144
145

  Selection current_selection;
  std::shared_ptr<Screen> screen;
  Camera camera;
  Hud hud;
louiz’'s avatar
louiz’ committed
146
  DebugHud debug_hud;
147
  uint16_t team;
148
  SoundsHandler sounds_handler;
louiz’'s avatar
louiz’ committed
149
150
151
152
153
154
155
156

  GameClient(const GameClient&) = delete;
  GameClient(GameClient&&) = delete;
  GameClient& operator=(const GameClient&) = delete;
  GameClient& operator=(GameClient&&) = delete;
};

#endif /* GAME_CLIENT_HPP_INCLUDED */