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