ScummVM API documentation
GameEntity.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22/*
23 * Copyright (C) 2006-2010 - Frictional Games
24 *
25 * This file is part of Penumbra Overture.
26 */
27
28#ifndef GAME_GAME_ENTITY_H
29#define GAME_GAME_ENTITY_H
30
31#include "hpl1/engine/engine.h"
32
33using namespace hpl;
34
35#include "hpl1/penumbra-overture/GameTypes.h"
36#include "hpl1/penumbra-overture/SaveTypes.h"
37
38class cInit;
39class iGameEntity;
40class cInventoryItem;
41
42//-----------------------------------------
43
45 kSerializableClassInit(cGameEntityScript) public : cGameEntityScript() : msScriptFunc("") {}
46
47 int mlNum;
48 tString msScriptFunc;
49};
50
52typedef tGameEntityScriptMap::iterator tGameEntityScriptMapIt;
53
54//-----------------------------------------
55
57typedef tGameEntityVarMap::iterator tGameEntityVarMapIt;
58
59//------------------------------------------
60
61class iGameEntity;
62
63//------------------------------------------
64
66 kSerializableClassInit(cGameEntityAnimation_SaveData) public : bool mbActive;
67 bool mbLoop;
68
69 float mfWeight;
70 float mfFadeStep;
71 float mfTimePos;
72 float mfSpeed;
73};
74//------------------------------------------
75
77 kSerializableClassInit(iGameEntity_SaveData) public : bool mbActive;
78
79 tString msFileName;
80
81 tString msName;
82
83 float mfHealth;
84
85 float mfMaxExamineDist;
86 float mfMaxInteractDist;
87
88 bool mbHasBeenExamined;
89
90 tWString msGameName;
91 tWString msDescription;
92
93 bool mbShowDescritionOnce;
94
95 eGameEntityType mType;
96
97 cMatrixf m_mtxTransform;
98
99 // Engine types
105
106 cEnginePS_SaveData *GetParticleSystem(cParticleSystem3D *apPS);
107 cEngineSound_SaveData *GetSoundEntity(cSoundEntity *apSound);
108
109 // Animations
111
112 // Callbacks
114
115 cContainerList<cGameEntityScript> mlstCallbackScripts;
116
117 // Script variables
119
120 // Creation
121 virtual iGameEntity *CreateEntity() = 0;
122};
123
124//------------------------------------------
125
127 friend class cPlayer;
128
129public:
130 iGameEntity(cInit *apInit, const tString &asName);
131 virtual ~iGameEntity();
132
133 const tString &GetName() { return msName; }
134
135 bool IsActive() { return mbActive; }
136 void SetActive(bool abX);
137 virtual void OnSetActive(bool abX) {}
138
139 virtual bool IsSaved() { return mbIsSaved; }
140
141 virtual void OnWorldLoad() {}
142 virtual void OnPostLoadScripts() {}
143 virtual void OnWorldExit() {}
144 virtual void Update(float afTimeStep) {}
145 virtual void OnDraw() {}
146 virtual void OnPostSceneDraw() {}
147
148 void OnUpdate(float afTimeStep);
149
150 eGameEntityType GetType() { return mType; }
151
152 const tString &GetSubType() { return msSubType; }
153
154 void SetDescription(const tWString &asDesc) { msDescription = asDesc; }
155 const tWString &GetDescription() { return msDescription; }
156
157 void SetShowDescritionOnce(bool abX) { mbShowDescritionOnce = abX; }
158 bool GetShowDescritionOnce() { return mbShowDescritionOnce; }
159
160 bool GetHasBeenExamined() { return mbHasBeenExamined; }
161
162 void SetGameName(const tWString &asName) { msGameName = asName; }
163 const tWString &GetGameName() { return msGameName; }
164
165 iPhysicsBody *GetBody(int alNum) { return mvBodies[alNum]; }
166 int GetBodyNum() { return (int)mvBodies.size(); }
167 void SetBodies(Common::Array<iPhysicsBody *> &avBodies) { mvBodies = avBodies; }
168
169 iPhysicsJoint *GetJoint(int alNum) { return mvJoints[alNum]; }
170 int GetJointNum() { return (int)mvJoints.size(); }
171 void SetJoints(Common::Array<iPhysicsJoint *> &avJoints) { mvJoints = avJoints; }
172
173 int GetLightNum() { return (int)mvLights.size(); }
174 iLight3D *GetLight(int alX) { return mvLights[alX]; }
175 void SetLights(Common::Array<iLight3D *> &avLights) { mvLights = avLights; }
176
177 void SetParticleSystems(Common::Array<cParticleSystem3D *> &avParticleSystems) { mvParticleSystems = avParticleSystems; }
178 void SetBillboards(Common::Array<cBillboard *> &avBillboards) { mvBillboards = avBillboards; }
179 void SetBeams(Common::Array<cBeam *> &avBeams) { mvBeams = avBeams; }
180 void SetSoundEntities(Common::Array<cSoundEntity *> &avSoundEntities) { mvSoundEntities = avSoundEntities; }
181
182 void DestroyLight(iLight3D *apLight);
183 void DestroyParticleSystem(cParticleSystem3D *apPS);
184 void DestroyBillboard(cBillboard *apBillboard);
185 void SetSoundEntity(cSoundEntity *apSound);
186
187 cMeshEntity *GetMeshEntity() { return mpMeshEntity; }
188 void SetMeshEntity(cMeshEntity *apEnity) { mpMeshEntity = apEnity; }
189
190 void PlayerPick();
191 void PlayerInteract();
192 void PlayerExamine();
193
194 virtual void OnPlayerPick() {}
195 virtual void OnPlayerInteract() {}
196 virtual void OnPlayerExamine();
197
198 virtual bool OnUseItem(cInventoryItem *apItem) { return false; }
199
200 virtual void BreakAction() {}
201
202 virtual void OnDamage(float afDamage) {}
203 virtual void OnDeath(float afDamage) {}
204
205 virtual void OnPlayerGravityCollide(iCharacterBody *apCharBody, cCollideData *apCollideData) {}
206
207 bool GetHasInteraction() { return mbHasInteraction; }
208
209 float GetMaxExamineDist() { return mfMaxExamineDist; }
210 void SetMaxExamineDist(float afX) { mfMaxExamineDist = afX; }
211 float GetMaxInteractDist() { return mfMaxInteractDist; }
212 void SetMaxInteractDist(float afX) { mfMaxInteractDist = afX; }
213
214 virtual eCrossHairState GetPickCrossHairState(iPhysicsBody *apBody);
215 virtual float GetPickedDistance();
216
217 void AddCollideScript(eGameCollideScriptType aType, const tString &asFunc, const tString &asEntity);
218 void RemoveCollideScript(eGameCollideScriptType aType, const tString &asFunc);
219 void RemoveCollideScriptWithChildEntity(iGameEntity *apEntity);
220
221 void AddScript(eGameEntityScriptType aType, const tString &asFunc);
222 void RemoveScript(eGameEntityScriptType aType);
223
224 void CreateVar(const tString &asName, int alVal);
225 void SetVar(const tString &asName, int alVal);
226 void AddVar(const tString &asName, int alVal);
227 int GetVar(const tString &asName);
228
229 void Damage(float afDamage, int alStrength);
230 float GetHealth() { return mfHealth; }
231 void SetHealth(float afHealth);
232
233 void SetToughness(int alX) { mlToughness = alX; }
234 int GetToughness() { return mlToughness; }
235
236 bool GetDestroyMe() { return mbDestroyMe; }
237 bool GetBreakMe() { return mbBreakMe; }
238
239 void Break() { mbBreakMe = true; }
240
241 void SetCharBody(iCharacterBody *apCharBody) { mpCharBody = apCharBody; }
242 iCharacterBody *SetCharBody() { return mpCharBody; }
243
244 void SetUpTransMaterials();
245 void SetTransActive(bool abX);
246
247 void SetPauseControllers(bool abX) { mbPauseControllers = abX; }
248 bool GetPauseControllers() { return mbPauseControllers; }
249
250 void SetPauseGravity(bool abX) { mbPauseGravity = abX; }
251 bool GetPauseGravity() { return mbPauseGravity; }
252
253 const cMatrixf &GetOnLoadTransform() { return m_mtxOnLoadTransform; }
254 void SetOnLoadTransform(const cMatrixf &a_mtxPose) { m_mtxOnLoadTransform = a_mtxPose; }
255
256 void SetLastImpulse(const cVector3f &avVec) { mvLastImpulse = avVec; }
257
258 const tString &GetFileName() { return msFileName; }
259
260 cGameEntityScript *GetCallbackScript(eGameEntityScriptType aType) { return mvCallbackScripts[aType]; }
261
262 // Save data stuff
263 void SetSaveData(iGameEntity_SaveData *apData) { mpSaveData = apData; }
264 iGameEntity_SaveData *GetSaveData() { return mpSaveData; }
265
266 virtual iGameEntity_SaveData *CreateSaveData() = 0;
267 virtual void LoadFromSaveData(iGameEntity_SaveData *apSaveData);
268 virtual void SaveToSaveData(iGameEntity_SaveData *apSaveData);
269 virtual void SetupSaveData(iGameEntity_SaveData *apSaveData);
270
271protected:
272 tString GetScriptCommand(eGameEntityScriptType aType);
273
274 void PreloadModel(const tString &asFile);
275
276 cInit *mpInit;
277
278 bool mbActive;
279
280 tString msFileName;
281
282 bool mbIsSaved;
283
284 bool mbDestroyMe;
285 bool mbBreakMe;
286
287 bool mbHasInteraction;
288
289 bool mbHasBeenExamined;
290
291 tString msName;
292
293 tString msSubType;
294
295 float mfHealth;
296 int mlToughness;
297
298 tWString msGameName;
299 tWString msDescription;
300
301 bool mbShowDescritionOnce;
302
303 float mfMaxExamineDist;
304 float mfMaxInteractDist;
305
306 eGameEntityType mType;
307
308 bool mbPauseControllers;
309 bool mbPauseGravity;
310
311 cMatrixf m_mtxOnLoadTransform;
312
313 iGameEntity_SaveData *mpSaveData;
314
317
319 Common::Array<cParticleSystem3D *> mvParticleSystems;
320 Common::Array<cBillboard *> mvBillboards;
322 Common::Array<cSoundEntity *> mvSoundEntities;
323
324 bool mbSaveLights;
325
326 cMeshEntity *mpMeshEntity;
327
328 Common::Array<iMaterial *> mvNormalMaterials;
329 Common::Array<iMaterial *> mvTransMaterials;
330 bool mbTransActive;
331 bool mbTransShadow;
332
333 cVector3f mvLastImpulse;
334
335 Common::Array<cMesh *> mvPreloadedBreakMeshes;
336
337 iCharacterBody *mpCharBody;
338
339 cGameEntityScript *mvCallbackScripts[eGameEntityScriptType_LastEnum];
340 tGameCollideScriptMap m_mapCollideCallbacks;
341
342 tGameEntityVarMap m_mapVars;
343
344 bool mbUpdatingCollisionCallbacks;
345};
346
347#endif // GAME_GAME_ENTITY_H
size_type size() const
Definition: array.h:316
Definition: stablemap.h:43
typename TreeT::BasicIterator iterator
Definition: stablemap.h:48
Definition: str.h:59
Definition: ustr.h:57
Definition: SaveTypes.h:80
Definition: SaveTypes.h:107
Definition: GameEntity.h:65
Definition: GameEntity.h:44
Definition: Init.h:70
Definition: Inventory.h:123
Definition: Player.h:145
Definition: BillBoard.h:78
Definition: CollideData.h:46
Definition: MeshEntity.h:96
Definition: ParticleSystem3D.h:90
Definition: SoundEntity.h:86
Definition: CharacterBody.h:153
Definition: Light3D.h:117
Definition: PhysicsBody.h:117
Definition: PhysicsJoint.h:135
Definition: SerializeClass.h:230
Definition: GameEntity.h:76
Definition: GameEntity.h:126