1 #ifndef BLANK_SHARED_CLICONTEXT_HPP_
2 #define BLANK_SHARED_CLICONTEXT_HPP_
15 /// Create context with optional player and entity
16 /// entity defaults to the player's if given
17 /// Associated player or entity can be changed during
18 /// the context's lifetime and will assume the original
19 /// values when reset.
20 explicit CLIContext(Player *p = nullptr, Entity *e = nullptr);
22 /// get a best name for this context
23 std::string Name() const;
25 /// check if this context associates a player
26 bool HasPlayer() const noexcept { return effective_player; }
27 /// get the player responsible for all this
28 /// only valid if HasPlayer() returns true
29 Player &GetPlayer() noexcept { return *effective_player; }
30 const Player &GetPlayer() const noexcept { return *effective_player; }
31 /// change the effective player of this context
32 /// note that this will *not* change the effective entity
33 void SetPlayer(Player &p) noexcept { effective_player = &p; }
35 /// check if this context associates an entity
36 bool HasEntity() const noexcept { return effective_entity; }
37 /// get the entity on which operations should be performed
38 /// only valid if HasPlayer() returns true
39 Entity &GetEntity() noexcept { return *effective_entity; }
40 const Entity &GetEntity() const noexcept { return *effective_entity; }
41 /// change the effective player of this context
42 void SetEntity(Entity &e) noexcept { effective_entity = &e; }
44 /// reset effective player and entity to their original values
45 void Reset() noexcept {
46 effective_player = original_player;
47 effective_player = original_player;
50 /// an error has happened and the player should be notified
51 virtual void Error(const std::string &) = 0;
54 /// use this for output concerning the originator of a command
55 virtual void Message(const std::string &) = 0;
57 /// send a status message to all players
58 /// use this to announce stuff which may be interesting to anyone
59 virtual void Broadcast(const std::string &) = 0;
62 Player *original_player;
63 Player *effective_player;
64 Entity *original_entity;
65 Entity *effective_entity;