My Project
IGameObject.h
1 #pragma once
2 #include "TileObject.h"
3 #include <vector>
4 namespace ParaEngine
5 {
6  class CAIBase;
7  class CShapeAABB;
8 
15  class IGameObject:public CTileObject
16  {
17  public:
19 
20  IGameObject();
21  virtual ~IGameObject();
22  virtual CBaseObject::_SceneObjectType GetType(){return CBaseObject::GameObject;};
23 
24  public:
26  // implementation of IAttributeFields
27 
29  virtual int GetAttributeClassID(){return ATTRIBUTE_CLASSID_IGameObject;}
31  virtual const char* GetAttributeClassName(){static const char name[] = "IGameObject"; return name;}
33  virtual const char* GetAttributeClassDescription(){static const char desc[] = ""; return desc;}
35  virtual int InstallFields(CAttributeClass* pClass, bool bOverride);
36 
42  virtual bool ResetField(int nFieldID);
43 
50  virtual bool InvokeEditor(int nFieldID, const string& sParameters);
51 
52 
53  ATTRIBUTE_METHOD1(IGameObject, IsModified_s, bool*) {*p1 = cls->IsModified(); return S_OK;}
54  ATTRIBUTE_METHOD1(IGameObject, SetModified_s, bool) {cls->SetModified(p1); return S_OK;}
55  ATTRIBUTE_METHOD(IGameObject, SaveToDB_s) {return cls->SaveToDB()?S_OK:E_FAIL;}
56 
57  ATTRIBUTE_METHOD1(IGameObject, GetOnLoadScript_s, const char**) {*p1 = cls->GetOnLoadScript().c_str(); return S_OK;}
58  ATTRIBUTE_METHOD1(IGameObject, SetOnLoadScript_s, const char*) {cls->SetOnLoadScript(p1); return S_OK;}
59 
60  ATTRIBUTE_METHOD1(IGameObject, IsLoaded_s, bool*) {*p1 = cls->IsLoaded(); return S_OK;}
61  ATTRIBUTE_METHOD1(IGameObject, SetLoaded_s, bool) {cls->SetLoaded(p1); return S_OK;}
62 
63  DEFINE_SCRIPT_EVENT(IGameObject, EnterSentientArea);
64  DEFINE_SCRIPT_EVENT(IGameObject, LeaveSentientArea);
65  DEFINE_SCRIPT_EVENT(IGameObject, Click);
66  DEFINE_SCRIPT_EVENT(IGameObject, Event);
67  DEFINE_SCRIPT_EVENT(IGameObject, Perception);
68  DEFINE_SCRIPT_EVENT(IGameObject, FrameMove);
69  DEFINE_SCRIPT_EVENT(IGameObject, Net_Send);
70  DEFINE_SCRIPT_EVENT(IGameObject, Net_Receive);
71 
72 
73  ATTRIBUTE_METHOD1(IGameObject, IsGlobal_s, bool*) {*p1 = cls->IsGlobal(); return S_OK;}
74  ATTRIBUTE_METHOD1(IGameObject, MakeGlobal_s, bool) {cls->MakeGlobal(p1); return S_OK;}
75 
76  ATTRIBUTE_METHOD1(IGameObject, IsSentient_s, bool*) {*p1 = cls->IsSentient(); return S_OK;}
77  ATTRIBUTE_METHOD1(IGameObject, MakeSentient_s, bool) {cls->MakeSentient(p1); return S_OK;}
78 
79  ATTRIBUTE_METHOD1(IGameObject, IsAlwaysSentient_s, bool*) {*p1 = cls->IsAlwaysSentient(); return S_OK;}
80  ATTRIBUTE_METHOD1(IGameObject, SetAlwaysSentient_s, bool) {cls->SetAlwaysSentient(p1); return S_OK;}
81 
82  ATTRIBUTE_METHOD1(IGameObject, GetSentientRadius_s, float*) {*p1 = cls->GetSentientRadius(); return S_OK;}
83  ATTRIBUTE_METHOD1(IGameObject, SetSentientRadius_s, float) {cls->SetSentientRadius(p1); return S_OK;}
84 
85  ATTRIBUTE_METHOD1(IGameObject, GetPerceptiveRadius_s, float*) {*p1 = cls->GetPerceptiveRadius(); return S_OK;}
86  ATTRIBUTE_METHOD1(IGameObject, SetPerceptiveRadius_s, float) {cls->SetPerceptiveRadius(p1); return S_OK;}
87 
88  ATTRIBUTE_METHOD1(IGameObject, GetGroupID_s, int*) {*p1 = cls->GetGroupID(); return S_OK;}
89  ATTRIBUTE_METHOD1(IGameObject, SetGroupID_s, int) {cls->SetGroupID(p1); return S_OK;}
90 
91  ATTRIBUTE_METHOD1(IGameObject, GetSentientField_s, int*) {*p1 = cls->GetSentientField(); return S_OK;}
92  ATTRIBUTE_METHOD1(IGameObject, SetSentientField_s, int) {cls->SetSentientField(p1, false); return S_OK;}
93 
94  ATTRIBUTE_METHOD1(IGameObject, GetFrameMoveInterval_s, int*) {*p1 = cls->GetFrameMoveInterval(); return S_OK;}
95  ATTRIBUTE_METHOD1(IGameObject, SetFrameMoveInterval_s, int) {cls->SetFrameMoveInterval(p1); return S_OK;}
96 
97  public:
101  virtual bool SaveToDB();
102 
104  virtual void PathFinding(double dTimeDelta);
105 
108  virtual void AnimateBiped( double dTimeDelta, bool bSharpTurning = false /*reserved*/);
109 
110 
112  virtual CAIBase* GetAIModule();
113 
115  // the following must be implemented. The IGameObject will automatically activate
116  // the script. Hence, object which implements these functions need to call the base class
117  // to ensure that the script is also activated.
119 
121  virtual int On_Attached();
123  virtual int On_Detached();
124 
127  virtual int On_EnterSentientArea();
130  virtual int On_LeaveSentientArea();
131 
139  virtual int On_Click(DWORD nMouseKey, DWORD dwParam1, DWORD dwParam2);
140 
142  virtual int On_Event(DWORD nEventType, DWORD dwParam1, DWORD dwParam2);
143 
146  virtual int On_Perception();
149  virtual int On_FrameMove();
153  virtual int On_Net_Send(DWORD dwNetType, DWORD dwParam1, DWORD dwParam2);
157  virtual int On_Net_Receive(DWORD dwNetType, DWORD dwParam1, DWORD dwParam2);
158  public:
160  // the following is implemented.
162 
165  void LoadOnLoadScriptIfNot();
166 
177  void SetOnLoadScript(const string& str);
179  const string& GetOnLoadScript() {return m_sOnLoadScript;};
180 
191  bool IsLoaded() { return m_bIsLoaded; };
196  void SetLoaded(bool bLoaded) { m_bIsLoaded =bLoaded; };
197 
199  virtual bool IsSentient();
205  virtual void MakeSentient(bool bSentient=true);
206 
212  void ForceSentient(bool bSentient=true);
213 
215  float GetSentientRadius();
217  void SetSentientRadius(float fR);
218 
220  float GetPerceptiveRadius();
222  void SetPerceptiveRadius(float fNewRaduis);
223 
226 
228  IGameObject* GetPerceivedObject(int nIndex);
229 
231  float GetDistanceSq2D(IGameObject* pObj);
232 
234  bool IsAlwaysSentient() const;
236  void SetAlwaysSentient(bool bAlways);
237 
240  virtual void UpdateTileContainer();
241 
242  virtual void SetTileContainer(CTerrainTile * pTile);
243 
245  virtual bool IsGlobal(){return m_bIsGlobal;}
246 
248  virtual void MakeGlobal(bool bGlobal);
249 
253  virtual void SetMovableRegion(const CShapeAABB* aabb);
255  virtual const CShapeAABB* GetMovableRegion();
256 
259  void SetGroupID(int nGroup);
261  int GetGroupID();
262 
270  void SetSentientField(DWORD dwFieldOrGroup, bool bIsGroup=false);
272  DWORD GetSentientField();
273 
275  bool IsSentientWith(const IGameObject * pObj);
276 
280  virtual bool IsPersistent();
284  virtual void SetPersistent(bool bPersistent);
285 
287  virtual bool IsModified(){return m_bModified;};
289  virtual void SetModified(bool bModified){m_bModified = bModified;};
290 
292  virtual void SetSpeedScale(float dScale){};
294  virtual float GetSpeedScale(){return 1.0f;};
296  virtual void SetSizeScale(float dScale){};
298  virtual float GetSizeScale(){return 1.0f;};
299 
301  inline int GetSimTag(){return m_nSimTag;}
303  inline void SetSimTag(int nTag){m_nSimTag = nTag;}
305  inline std::vector <std::string>& GetPerceiveList(){return m_PerceivedList;};
306 
307 
310  inline int GetSentientObjCount(){return m_nSentientObjCount;};
311  inline void SetSentientObjCount(int nCount){m_nSentientObjCount = nCount;};
312 
315  void SetFrameMoveInterval(int nFrameMoveInterval) { m_nFrameMoveInterval = nFrameMoveInterval; };
316  int GetFrameMoveInterval() {return m_nFrameMoveInterval; };
317 
318 
319  protected:
320  // this tag is served for simulation.
321  int m_nSimTag;
322  private:
324  bool m_bIsLoaded;
326  bool m_bModified;
328  bool m_bIsGlobal;
332  bool m_bIsPersistent;
334  bool m_bAlwaysSentient;
335 
337  string m_sOnLoadScript;
338 
340  std::vector <std::string> m_PerceivedList;
341 
344  int m_nSentientObjCount;
345 
347  float m_fSentientRadius;
348 
350  float m_fPeceptiveRadius;
353  int m_nGroup;
357  DWORD m_dwSentientField;
358 
362  unsigned int m_nFrameMoveInterval;
363 
364  friend class CSceneObject;
365  };
366 
367 }
float GetDistanceSq2D(IGameObject *pObj)
get the distance square between this object and another game object
Definition: IGameObject.cpp:256
float GetPerceptiveRadius()
get the perceptive radius.
Definition: IGameObject.cpp:222
void SetGroupID(int nGroup)
set the group ID to which this object belongs to.
Definition: IGameObject.cpp:359
virtual const char * GetAttributeClassDescription()
a static string, describing the attribute class object
Definition: IGameObject.h:33
int GetNumOfPerceivedObject()
return the total number of perceived objects.
Definition: IGameObject.cpp:236
void ForceSentient(bool bSentient=true)
Force the object to be sentient or not.
Definition: IGameObject.cpp:284
virtual void MakeGlobal(bool bGlobal)
make the biped global if it is not and vice versa.
Definition: IGameObject.cpp:342
float GetSentientRadius()
get the sentient radius.
Definition: IGameObject.cpp:214
an attribute class is a collection of attribute fields.
Definition: AttributeClass.h:10
virtual bool IsModified()
whether some of the fields are modified.It is up to the implementation class to provide this function...
Definition: IGameObject.h:287
virtual void UpdateTileContainer()
update the tile container according to the current position of the game object.
Definition: IGameObject.cpp:334
void SetLoaded(bool bLoaded)
see IsLoaded()
Definition: IGameObject.h:196
void LoadOnLoadScriptIfNot()
load the on load script if it is not loaded.
Definition: IGameObject.cpp:57
different physics engine has different winding order.
Definition: EventBinding.h:32
virtual void SetSpeedScale(float dScale)
set the animation instance&#39;s speed to dScale times of its original speed
Definition: IGameObject.h:292
virtual bool SaveToDB()
save the current character to database according to the persistent property.
Definition: IGameObject.cpp:480
virtual const char * GetAttributeClassName()
a static string, describing the attribute class object&#39;s name
Definition: IGameObject.h:31
virtual void AnimateBiped(double dTimeDelta, bool bSharpTurning=false)
animate biped according to its current way point lists and speed.
Definition: IGameObject.cpp:324
bool IsAlwaysSentient() const
whether the object is always sentient.
Definition: IGameObject.cpp:273
virtual void SetModified(bool bModified)
set whether any field has been modified.
Definition: IGameObject.h:289
bool IsSentientWith(const IGameObject *pObj)
return true if the current object is sentient to the specified object.
Definition: IGameObject.cpp:381
virtual int On_FrameMove()
called every frame move when this character is sentient.
Definition: IGameObject.cpp:165
void SetSentientField(DWORD dwFieldOrGroup, bool bIsGroup=false)
set the sentient field.
Definition: IGameObject.cpp:369
virtual bool ResetField(int nFieldID)
Reset the field to its initial or default value.
Definition: IGameObject.cpp:391
int GetSentientObjCount()
the number of objects in its sentient area.
Definition: IGameObject.h:310
virtual float GetSpeedScale()
Definition: IGameObject.h:294
virtual float GetSizeScale()
Definition: IGameObject.h:298
void SetAlwaysSentient(bool bAlways)
set whether sentient.
Definition: IGameObject.cpp:278
DWORD GetSentientField()
Definition: IGameObject.cpp:376
virtual void MakeSentient(bool bSentient=true)
set the object to sentient according to whether the object is currently sentient. ...
Definition: IGameObject.cpp:299
virtual int On_Click(DWORD nMouseKey, DWORD dwParam1, DWORD dwParam2)
when the player clicked on this object.
Definition: IGameObject.cpp:112
weak reference ptr use in a class like this: weak_ptr<CRefCounted> p; e.g.
Definition: PERef.h:105
void SetSentientRadius(float fR)
set the sentient radius.
Definition: IGameObject.cpp:218
AABB-related code.
Definition: ShapeAABB.h:11
virtual int On_Detached()
called when this object is detached from the scene
Definition: IGameObject.cpp:82
virtual void SetPersistent(bool bPersistent)
whenever a persistent object is made non-persistent, the SaveToDB() function will actually removed it...
Definition: IGameObject.cpp:453
virtual bool InvokeEditor(int nFieldID, const string &sParameters)
Invoke an (external) editor for a given field.
Definition: IGameObject.cpp:492
this is an interface class for game objects, such as NPC, OPC and players.
Definition: IGameObject.h:15
a tile in the latticed terrain class
Definition: TerrainTile.h:21
virtual void PathFinding(double dTimeDelta)
automatically generate way points according to its perceptions
Definition: IGameObject.cpp:319
bool IsLoaded()
On Load script logic: the onload script is moved from the biped object to the IGameObject.
Definition: IGameObject.h:191
int GetSimTag()
return the tag served for simulation.
Definition: IGameObject.h:301
virtual const CShapeAABB * GetMovableRegion()
get the region within which the object can move.
Definition: IGameObject.cpp:538
virtual bool IsPersistent()
whether the object is persistent in the world.
Definition: IGameObject.cpp:458
The top level scene management class.
Definition: SceneObject.h:58
virtual int On_Attached()
called when this object is attached to the scene.
Definition: IGameObject.cpp:75
void SetOnLoadScript(const string &str)
set the on load script.
Definition: IGameObject.cpp:543
virtual int On_Perception()
when other game objects of a different type entered the perceptive area of this object.
Definition: IGameObject.cpp:146
virtual int GetAttributeClassID()
attribute class ID should be identical, unless one knows how overriding rules work.
Definition: IGameObject.h:29
base class for all AI objects
Definition: AIBase.h:9
Tile Object have position and bounding rect and can usually be attached to quad-tree terrain tile...
Definition: TileObject.h:10
a general event
Definition: EventClasses.h:8
virtual CAIBase * GetAIModule()
Get the AI module that is dynamically associated with this object.
Definition: IGameObject.cpp:329
virtual bool IsGlobal()
is global object
Definition: IGameObject.h:245
virtual int On_Net_Receive(DWORD dwNetType, DWORD dwParam1, DWORD dwParam2)
when the network module receives packages from the network and it is about a certain game object...
Definition: IGameObject.cpp:197
virtual bool IsSentient()
whether the biped is sentient or not
Definition: IGameObject.cpp:209
virtual int On_LeaveSentientArea()
when no other game objects of different type is in the sentient area of this object.
Definition: IGameObject.cpp:100
void SetPerceptiveRadius(float fNewRaduis)
Set the perceptive radius.
Definition: IGameObject.cpp:227
virtual int On_Net_Send(DWORD dwNetType, DWORD dwParam1, DWORD dwParam2)
during the execution of this object, it may send various network commands to the server or client...
Definition: IGameObject.cpp:185
std::vector< std::string > & GetPerceiveList()
get the names of the game objects in the object&#39;s perceptive radius.
Definition: IGameObject.h:305
void SetSimTag(int nTag)
set the tag served for simulation.
Definition: IGameObject.h:303
virtual void SetMovableRegion(const CShapeAABB *aabb)
Set the region within which the object can move.
Definition: IGameObject.cpp:528
virtual int InstallFields(CAttributeClass *pClass, bool bOverride)
this class should be implemented if one wants to add new attribute.
Definition: IGameObject.cpp:557
IGameObject * GetPerceivedObject(int nIndex)
get the perceived object by index.
Definition: IGameObject.cpp:241
virtual void SetSizeScale(float dScale)
set the size of the object to dScale times of its original size.
Definition: IGameObject.h:296
int GetGroupID()
Get the group ID to which this object belongs to.
Definition: IGameObject.cpp:364
void SetFrameMoveInterval(int nFrameMoveInterval)
milliseconds interval, that the on frame move method should be called on a sentient object...
Definition: IGameObject.h:315
virtual int On_EnterSentientArea()
when other game objects of a different type entered the sentient area of this object.
Definition: IGameObject.cpp:87
virtual int On_Event(DWORD nEventType, DWORD dwParam1, DWORD dwParam2)
TODO: Some game defined events, such as user attack, etc.
Definition: IGameObject.cpp:133
const string & GetOnLoadScript()
get the on load script.
Definition: IGameObject.h:179