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
|
#ifndef EXPLOSION_GRAPHICS_H
#define EXPLOSION_GRAPHICS_H
#include "Rendering/GL/myGL.h"
#include "Sim/Misc/DamageArray.h"
#include "Lua/LuaParser.h"
#include "Sim/Objects/WorldObject.h"
#include <map>
class CUnit;
class CExplosionGenerator;
class CExpGenSpawnable: public CWorldObject
{
public:
CR_DECLARE(CExpGenSpawnable);
CExpGenSpawnable(): CWorldObject(){ GML_EXPGEN_CHECK() };
CExpGenSpawnable(const float3& pos): CWorldObject(pos) { GML_EXPGEN_CHECK() };
virtual ~CExpGenSpawnable() {};
virtual void Init(const float3& pos, CUnit* owner GML_PARG_H) = 0;
};
class ClassAliasList
{
public:
ClassAliasList();
void Load(const LuaTable&);
creg::Class* GetClass(const std::string& name);
std::string FindAlias(const std::string& className);
protected:
std::map<std::string, std::string> aliases;
};
class CExplosionGeneratorHandler
{
public:
CExplosionGeneratorHandler();
CExplosionGenerator* LoadGenerator(const std::string& tag);
const LuaTable& GetTable() { return luaTable; }
ClassAliasList projectileClasses, generatorClasses;
protected:
std::map<std::string, CExplosionGenerator*> generators;
LuaParser luaParser;
LuaTable luaTable;
};
class CExplosionGenerator
{
public:
CR_DECLARE(CExplosionGenerator);
CExplosionGenerator();
virtual ~CExplosionGenerator();
virtual void Explosion(const float3& pos, float damage, float radius, CUnit* owner, float gfxMod, CUnit* hit, const float3& dir) = 0;
virtual void Load(CExplosionGeneratorHandler* loader, const std::string& tag) = 0;
};
class CStdExplosionGenerator: public CExplosionGenerator
{
public:
CR_DECLARE(CStdExplosionGenerator);
CStdExplosionGenerator();
virtual ~CStdExplosionGenerator();
void Explosion(const float3& pos, float damage, float radius, CUnit* owner, float gfxMod, CUnit* hit, const float3& dir);
void Load(CExplosionGeneratorHandler* loader, const std::string& tag);
};
/* Defines the result of an explosion as a series of new projectiles */
class CCustomExplosionGenerator: public CStdExplosionGenerator
{
protected:
CR_DECLARE(CCustomExplosionGenerator);
struct ProjectileSpawnInfo {
ProjectileSpawnInfo() { projectileClass = 0; }
creg::Class* projectileClass;
std::vector<char> code;
int count;// number of projectiles spawned of this type
unsigned int flags;
};
// TODO: Handle ground flashes with more flexibility like the projectiles
struct GroundFlashInfo {
GroundFlashInfo() { ttl = 0; }
float flashSize;
float flashAlpha;
float circleGrowth;
float circleAlpha;
int ttl;
float3 color;
unsigned int flags;
};
struct CEGData {
std::vector<ProjectileSpawnInfo> projectileSpawn;
GroundFlashInfo groundFlash;
bool useDefaultExplosions;
};
std::map<string, CEGData> cachedCEGs;
std::map<string, CEGData>::iterator currentCEG;
void ParseExplosionCode(ProjectileSpawnInfo* psi, int baseOffset, boost::shared_ptr<creg::IType> type, const std::string& script, std::string& code);
void ExecuteExplosionCode (const char* code, float damage, char* instance, int spawnIndex, const float3& dir);
public:
CCustomExplosionGenerator();
~CCustomExplosionGenerator();
static void OutputProjectileClassInfo();
void Load (CExplosionGeneratorHandler* loader, const std::string& tag);// throws content_error/runtime_error on errors
void Explosion(const float3& pos, float damage, float radius, CUnit* owner, float gfxMod, CUnit* hit, const float3& dir);
};
extern CExplosionGeneratorHandler* explGenHandler;
#endif
|