Labyrinth
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
character.hpp
1 //////////////////////////////
2 //
3 // File: lxs/game/character.hpp
4 // Author: Maciej Kaminski
5 // E-mail: maciej.a.kaminski@gmail.com
6 // Website: maciejkaminski.pl
7 //
8 // File creation date: Feb 27 2013
9 // This file is part of Project Labyrinth
10 // This file is going to be released under terms of GNU GPL in near future
11 //
12 //////////////////////////////
13 
14 #ifndef __LXS_CHARACTER__
15 #define __LXS_CHARACTER__
16 #include "lxs/game/gameobject.hpp"
17 #include <deque>
18 #include <string>
19 #include "swrs/character.hpp"
20 namespace LxS
21 {
22  namespace Game
23  {
24  class Path;
25  class Map;
26  class GameObject;
27  class Action;
28  class AIAgent;
29  class Item;
30  class Sword;
31  class ItemCatalogue;
32 
33  // pedef std::deque<Item* > Inventory;
34  //!@brief Class converging all aspects of playable character
35  //!
36  //!3D object, interactive game object and SW character record sheet
37  class Character: public GameObject, public SWRS::Character
38  {
39  friend class AIAgent;
40  friend class Map;
41  friend class MapWindowOverlay;
42  float alpha,x,y,z;
43  //float t_x,t_y, t_z; // target;
44  typedef std::deque<Action* > ActionQueue;
45  ActionQueue action_queue;
46  ItemCatalogue* inventory;
47  //! the sword currently used by character
48  Sword * sword;
49  //! precomputed moement path
50  Path * movement_path;
51  float time_to_action; //! time until character is allowed to perform new acction. Decreases to 0; if 0, new action is performedxw
52  //! AI entity controling the character
53  class AIAgent * agent;
54  //! animation routine for movement (walking/running) of character
55  void AnimateMove(float dt);
56  std::string dial_file;
57  float GetMovementSpeedMultiplier();
58  bool surprised;
59  public:
60  //! Does character suffer surprise penalty in this turn?
61  bool IsSurprised() {return surprised;}
62  //! Set Surprised tag to true
63  void Surprise();
64  //! Equip character with some stuff
65  void AddItem(const std::string & itemname, int amount=1);
66  //! Equip character with a sword. This sword must be one of items posessed by character. If character has no swords,
67  // this function will have no result - error won't be returned
68  void ArmSword(const std::string & itemname);
69  //!Return pointer to an item posessed by character' SHOULDN'T IT BE CONST?
70  Item* GetItem(const std::string & itemname);
71  //! pick item posessed by character and add it to inventory
72  void PickItem(Item* it);
73  //! eat one of items in your inventory
74  //! \return return false if no such item was in inventory;
75  //! return true if one unit of item successfully consumed;
76  bool ConsumeItem(Item * it);
77  //! only usable constructor
78  Character(Map * p, SWRS::Character *charactersheet);
79  ~Character();
80  virtual void SelectAnimation(std::string seq_name);
81 
82  //! return true if more potion stored than potion drinking actions enqueued
83  bool CanDrinkMore(const std::string & potionname);
84  //! rotate a model (degrees)
85  float GetRotationY(){return alpha;}
86  virtual void SetRotationY(float alpha);
87  //! set current position
88  virtual void SetPosition(float x, float y, float z);
89  //! set vector of movement. character will calculate his path and start moving
90  virtual void SetDirection(float x, float y, float z);
91  virtual void Animate(float dt);
92  virtual void Initialize();
93  //! render character INCLUDING his weapon
94  virtual void Render(Rendermode mode);
95 
96  //! return list of all items posessed by character
97  ItemCatalogue* GetInventory() { return inventory;}
98  //! return pointer to sword object that is currently equipped
99  const Sword * GetSword() { return sword; }
100 
101  virtual bool CollisionDetection(GameObject * cb, float x, float y, float z);
102  //! get time left to execution of current action in queue (makes sense only
103  //! in battle mode)
104  float GetTimeToAction() {return time_to_action;}
105 
106  //! enqueue action using
107  void EnqueueAction(Action * to_perform);
108  //! perform action immediately
109  void PerformAction(Action * to_perform);
110 
111  //! perform attack action immediately
112  void Attack(Action * to_perform);
113  //! perform escape action immediately
114  void Escape(Action * to_perform);
115  //! perform potion action immediately
116  void Potion(Action * to_perform);
117 
118  //! drop currewntly executed action from queue (it is finished or just canceled)
119  void DropCurrentAction();
120  //! remove all actions from action queue
121  void ClearActionQueue();
122  //! attach AI entity
123  void SetAIAgent(char * aia);
124  //! 0=miss; 1=hit; 2=murderoous+strike
125  int MeleeToHitRoll(Character * enemy);
126  //! damage output
127  int MeleeToWoundRoll(bool murderous,Character * enemy);
128 
129  //! is this NPC willing to talk?
130  bool IsWillingToTalk();
131 
132  //! What can NPC tell to this PC?
133  typedef std::vector<std::string> DialogueLines;
134 
135  //! what does the NPC say
136  std::string GetAnswer();
137 
138  //! What can PC say to this NPC right now?
140 
141  //! file containing statements and dialogue reaction
142  void SetDialoguesFile(std::string &dial_file);
143 
144  //! say sentence s to this NPC character
145  void Say(std::string &s);
146  //! \brief get dialogue file configured for this character
147  //! (if any; if none, empty string is returned and no exception is thrown)
148  std::string GetDialogueFile() { return dial_file;}
149  };
150  }
151 }
152 #endif