PGE Engine
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros Pages
lvl_npc.h
1 #ifndef LVL_NPC_H
2 #define LVL_NPC_H
3 
4 #include "lvl_base_object.h"
5 #include <data_configs/obj_npc.h>
7 #include <common_features/npc_animator.h>
8 #include <common_features/event_queue.h>
9 #include <common_features/pointf.h>
10 #include "npc_detectors/lvl_base_detector.h"
11 #include "npc_detectors/lvl_dtc_player_pos.h"
12 #include "npc_detectors/lvl_dtc_contact.h"
13 #include "npc_detectors/lvl_dtc_inarea.h"
14 
15 #include <luabind/luabind.hpp>
16 #include <lua_inclues/lua.hpp>
17 
18 #include <QHash>
19 
20 class LVL_Player;
21 class LVL_Npc : public PGE_Phys_Object
22 {
23 public:
24  LVL_Npc();
25  virtual ~LVL_Npc();
26  void init();
27 
28  LevelNPC getData();
29 
30  LevelNPC data; //Local settings
31  PGE_PointF offset;
32  PGE_Size frameSize;
33  AdvNpcAnimator animator;
34 
35  void setDirection(int dir);
36  int direction();
37  int _direction;
38  float motionSpeed;
39  bool is_scenery;
40  bool is_activity;
41  bool is_shared_animation;
42  bool keep_position_on_despawn;
43 
44  bool animated;
45  long animator_ID;
46 
47  obj_npc *setup;//Global config
48  bool isKilled();
49  bool killed;
50  enum DamageReason{
51  DAMAGE_NOREASON=0,
52  DAMAGE_STOMPED, //on stomping to head
53  DAMAGE_BY_KICK, //caused by contact with throwned NPC's
54  DAMAGE_BY_PLAYER_ATTACK, //Caused by attaking by player
55  //(for example, by sword, by fists, by teeth sting, by blow claws, by whip, etc.)
56  DAMAGE_TAKEN, //is Power up taken
57  DAMAGE_LAVABURN, //Does NPC burn in lava
58  DAMAGE_PITFALL, //Does NPC fell into the pit
59  DAMAGE_CUSTOM_REASON
60  };
61  void doHarm(int damageReason);
62  void harm(int damage=1, int damageReason = DAMAGE_NOREASON);
63 
64  void talkWith();
65 
66  void kill(int damageReason);
67  void unregister();
68 
70  int taskToTransform_t;
71  void transformTo(long id, int type=0);
72  void transformTo_x(long id);
73 
74  void update(float tickTime);
75  void render(double camX, double camY);
76  void setDefaults();
77  void Activate();
78  void deActivate();
79 
80  void updateCollisions();
81  void solveCollision(PGE_Phys_Object *collided);
83  float _heightDelta; //Delta of changing height. Need to protect going through block on character switching
84  bool onCliff();
85  bool cliffDetected;
86 
87  /*****************NPC's and blocks******************/
88  bool onGround();
89  bool _onGround;
90  QHash<int, int > foot_contacts_map;
91  QHash<int, int > foot_sl_contacts_map;
92 
93  QHash<int, PGE_Phys_Object*> contacted_blocks;
94  QHash<int, PGE_Phys_Object*> contacted_bgos;
95  QHash<int, PGE_Phys_Object*> contacted_npc;
96  QHash<int, PGE_Phys_Object*> contacted_players;
97 
98  typedef QHash<int, PGE_Phys_Object*> PlayerColliders;
99  QHash<int, PGE_Phys_Object*> collided_top;
100  QHash<int, PGE_Phys_Object*> collided_left;
101  QHash<int, PGE_Phys_Object*> collided_right;
102  QHash<int, PGE_Phys_Object*> collided_bottom;
103  QHash<int, PGE_Phys_Object*> collided_center;
104  bool disableBlockCollision;
105  bool disableNpcCollision;
106  bool _stucked;
107 
108  bool bumpDown;
109  bool bumpUp;
110  /***************************************************/
111  /*******************Environmept*********************/
112  //QHash<int, obj_player_physics > physics;
113  QHash<int, int > environments_map;
114  //obj_player_physics physics_cur;
115  int environment;
116  int last_environment;
117  /*******************Environmept*********************/
118 
119  bool reSpawnable;
120  bool isActivated;
121  bool deActivatable;
122  bool wasDeactivated;
123  bool offSectionDeactivate;
124  int activationTimeout;
125 
126  /********************Detectors**********************/
127  QList<BasicDetector > detectors_dummy;
128  PlayerPosDetector detector_player_pos;
130  QList<InAreaDetector > detectors_inarea;
131  InAreaDetector * lua_installInAreaDetector(float left, float top, float right, float bottom, luabind::adl::object filters);
132  QList<ContactDetector > detectors_contact;
133  ContactDetector * lua_installContactDetector();
134 
135  QVector<BasicDetector* > detectors;
136 
137  /***************************************************/
138 
139  /*****Warp*Sprite*****/
140  enum WarpingSide{
141  WARP_TOP=1,
142  WARP_LEFT=2,
143  WARP_BOTTOM=3,
144  WARP_RIGHT=4,
145  };
151  void setSpriteWarp(float depth, WarpingSide _direction=WARP_BOTTOM, bool resizedBody=false);
152  void resetSpriteWarp();
153  bool isWarping;
154  int warpDirectO;
155  bool warpResizedBody;
156  float warpSpriteOffset;
157  float warpFrameW;
158  float warpFrameH;
159  /*********************/
160 
161  /***************************************************/
162  void setWarpSpawn(WarpingSide side=WARP_TOP);
163  bool warpSpawing;
164  EventQueue<LVL_Npc> event_queue;
165  /***************************************************/
166 
167  /***********************Generator*******************/
168  bool isGenerator;
169  float generatorTimeLeft;
170  int generatorType;
171  int generatorDirection;
172  void updateGenerator(float tickTime);
173  /***************************************************/
174 
175  /*******************Throwned*by*********************/
176  void resetThrowned();
177  void setThrownedByNpc(long npcID, LVL_Npc *npcObj);
178  void setThrownedByPlayer(long playerID, LVL_Player *npcObj);
179  long thrownedByNpc();
180  LVL_Npc *thrownedByNpcObj();
181  long thrownedByPlayer();
182  LVL_Player *thrownedByPlayerObj();
183  long throwned_by_npc;
184  LVL_Npc *throwned_by_npc_obj;
185  long throwned_by_player;
186  LVL_Player *throwned_by_player_obj;
187  /***************************************************/
188 
189  /*******************Buddies********************/
190  //Allows communication between neighour NPC's of same type.
191  void buildBuddieGroup();
192  void updateBuddies(float tickTime);
193  void buildLeaf(QList<LVL_Npc*> &needtochec, QList<LVL_Npc*> *&list, LVL_Npc *leader);
194  QList<LVL_Npc*> *buddies_list;//Destroys when was killed last NPC in this group
195  bool buddies_updated;
196  LVL_Npc* buddies_leader;
197  /**********************************************/
198 
199  class KillEvent
200  {
201  public:
202  KillEvent();
203  KillEvent(const KillEvent &ke);
204  bool cancel;
205  int reason_code;
206  enum killedBy {
207  self=0,
208  player,
209  otherNPC
210  };
211  int killed_by;
212  LVL_Player* killer_p;
213  LVL_Npc* killer_n;
214  };
215 
216  class HarmEvent
217  {
218  public:
219  HarmEvent();
220  HarmEvent(const HarmEvent &he);
221  bool cancel;
222  int damage;
223  int reason_code;
224  enum killedBy {
225  self=0,
226  player,
227  otherNPC
228  };
229  int killed_by;
230  LVL_Player* killer_p;
231  LVL_Npc* killer_n;
232  };
233  //Additional lua enums
234 
235  //Additional lua events
236  virtual void lua_onActivated() {}
237  virtual void lua_onLoop(float) {}
238  virtual void lua_onInit() {}
239  virtual void lua_onKill(int) {}
240  virtual void lua_onHarm(int, int) {}
241  virtual void lua_onTransform(long) {}
242 
243  //Additional lua functions
244  void lua_setSequenceLeft(luabind::object frames);
245  void lua_setSequenceRight(luabind::object frames);
246  void lua_setSequence(luabind::object frames);
247  void lua_setOnceAnimation(bool en);
248  bool lua_animationIsFinished();
249  int lua_frameDelay();
250  void lua_setFrameDelay(int ms);
251  int lua_activate_neighbours();
252  LVL_Npc *lua_spawnNPC(int npcID, int sp_type, int sp_dir, bool reSpawnable=false);
253 
254  inline bool not_movable() { return data.nomove; }
255  inline void setNot_movable(bool n) { data.nomove=n; }
256  inline long special1() { return data.special_data; }
257  inline void setSpecial1(long s) { data.special_data=s; }
258  inline long special2() { return data.special_data2; }
259  inline void setSpecial2(long s) { data.special_data2=s; }
260  inline bool isBoss() { return data.is_boss; }
261  inline int getID() { return data.id; }
262  inline long getHealth() { return health; }
263  inline void setHealth(int _health) { health=_health; }
264  inline bool getCollideWithBlocks() { return !disableBlockCollision; }
265  inline void setCollideWithBlocks(bool blkcol) { disableBlockCollision=!blkcol; }
266 
267  bool isLuaNPC;
268 
269 
270 
271  int health;
272 
274  void show();
275  void hide();
276 
277  bool isInited();
278 private:
279  bool _isInited;
280 
281 };
282 
283 #endif // LVL_NPC_H
void setWarpSpawn(WarpingSide side=WARP_TOP)
Definition: lvl_npc_spritewarp.cpp:39
QVector< BasicDetector * > detectors
Detects contacted elements.
Definition: lvl_npc.h:135
Definition: lvl_dtc_inarea.h:8
long special_data2
User-data integer #2 used for configuring some NPC-AI's (kept for SMBX64)
Definition: lvl_filedata.h:202
InAreaDetector * lua_installInAreaDetector(float left, float top, float right, float bottom, luabind::adl::object filters)
Is player touches selected relative area;.
Definition: lvl_npc_lua.cpp:127
void unregister()
In-Game destroying of NPC with triggering of specific events.
Definition: lvl_npc_kill.cpp:145
bool nomove
NPC will stay idle and will always keep look to the playable character.
Definition: lvl_filedata.h:209
bool forceCollideCenter
collide with invizible blocks at center
Definition: lvl_npc.h:82
void show()
Definition: lvl_npc.cpp:88
void setSpriteWarp(float depth, WarpingSide _direction=WARP_BOTTOM, bool resizedBody=false)
setSpriteWarp Changes warping state of a sprite
Definition: lvl_npc_spritewarp.cpp:23
Definition: lvl_dtc_contact.h:11
Definition: npc_animator.h:33
Definition: size.h:23
bool is_boss
Enables some boss-specific NPC-AI features (Used by NPC-AI)
Definition: lvl_filedata.h:210
Definition: lvl_npc.h:216
Level specific NPC entry structure. Defines preferences of each NPC.
Definition: lvl_filedata.h:195
QList< BasicDetector > detectors_dummy
dummy detectors made directly from a base class, for a some tests
Definition: lvl_npc.h:127
long special_data
User-data integer #1 used for configuring some NPC-AI's (kept for SMBX64)
Definition: lvl_filedata.h:201
Definition: pointf.h:23
Definition: obj_npc.h:34
QList< InAreaDetector > detectors_inarea
Detects position and direction of nearest player.
Definition: lvl_npc.h:130
Definition: lvl_npc.h:199
Definition: lvl_dtc_player_pos.h:9
PlayerPosDetector * lua_installPlayerPosDetector()
Player position detectors (should have alone copy!)
Definition: lvl_npc_lua.cpp:119
void Activate()
Definition: lvl_npc_activate.cpp:22
Definition: lvl_player.h:39
QHash< int, int > foot_sl_contacts_map
Slipery surfaces.
Definition: lvl_npc.h:91
Definition: lvl_npc.h:21
PGE File Library.
unsigned long id
ID of NPC type defined in the lvl_npc.ini.
Definition: lvl_filedata.h:200
QHash< int, int > foot_contacts_map
staying on ground surfaces
Definition: lvl_npc.h:90
The PGE_Phys_Object class.
Definition: lvl_base_object.h:51
int taskToTransform
Sielent destroying of NPC without triggering of the events.
Definition: lvl_npc.h:69
QList< ContactDetector > detectors_contact
Detects is player(s) are enters into specific area relative to NPC's center.
Definition: lvl_npc.h:132