Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft new CEG impact filters: shield and intercepted #1602

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion rts/Game/GameHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,9 @@ void CGameHelper::Explosion(const CExplosionParams& params) {
damageAOE,
params.gfxMod,
params.owner,
params.hitUnit
params.hitUnit,
params.hitFeature,
params.hitWeapon
);
}

Expand Down
2 changes: 2 additions & 0 deletions rts/Game/GameHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ struct CExplosionParams {
const WeaponDef* weaponDef;

CUnit* owner;

CUnit* hitUnit;
CFeature* hitFeature;
CWeapon* hitWeapon;

float craterAreaOfEffect;
float damageAreaOfEffect; // radius
Expand Down
8 changes: 7 additions & 1 deletion rts/Lua/LuaSyncedCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6697,6 +6697,10 @@ static int SetExplosionParam(lua_State* L, CExplosionParams& params, DamageArray
case hashString("hitFeature"): {
params.hitFeature = ParseFeature(L, __func__, index + 1);
} break;
case hashString("hitWeapon"): {
LOG_L(L_ERROR, "SetExplosionParam(\"hitWeapon\") not implemented");
params.hitWeapon = nullptr;
} break;

case hashString("craterAreaOfEffect"): {
params.craterAreaOfEffect = lua_tofloat(L, index + 1);
Expand Down Expand Up @@ -6784,6 +6788,7 @@ int LuaSyncedCtrl::SpawnExplosion(lua_State* L)
.owner = nullptr,
.hitUnit = nullptr,
.hitFeature = nullptr,
.hitWeapon = nullptr,
.craterAreaOfEffect = 0.0f,
.damageAreaOfEffect = 0.0f,
.edgeEffectiveness = 0.0f,
Expand All @@ -6810,6 +6815,7 @@ int LuaSyncedCtrl::SpawnExplosion(lua_State* L)
params.owner = ParseUnit (L, __func__, 18);
params.hitUnit = ParseUnit (L, __func__, 19);
params.hitFeature = ParseFeature(L, __func__, 20);
params.hitWeapon = nullptr; // not implemented

params.craterAreaOfEffect = luaL_optfloat(L, 8, 0.0f);
params.damageAreaOfEffect = luaL_optfloat(L, 9, 0.0f);
Expand Down Expand Up @@ -6857,7 +6863,7 @@ int LuaSyncedCtrl::SpawnCEG(lua_State* L)
// (Spawn*C*EG implies only custom generators can fire)
const unsigned int cegID = lua_isstring(L, 1)? explGenHandler.LoadCustomGeneratorID(lua_tostring(L, 1)): luaL_checkint(L, 1);

lua_pushboolean(L, explGenHandler.GenExplosion(cegID, pos, dir, damage, radius, dmgMod, nullptr, nullptr));
lua_pushboolean(L, explGenHandler.GenExplosion(cegID, pos, dir, damage, radius, dmgMod, nullptr, nullptr, nullptr, nullptr));
lua_pushnumber(L, cegID);
return 2;
}
Expand Down
13 changes: 12 additions & 1 deletion rts/Sim/MoveTypes/AAirMoveType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,18 @@ static inline void AAMTEmitEngineTrail(CUnit* owner, unsigned int) {
projMemPool.alloc<CSmokeProjectile>(owner, owner->midPos, guRNG.NextVector() * 0.08f, (100.0f + guRNG.NextFloat() * 50.0f), 5.0f, 0.2f, 0.4f);
}
static inline void AAMTEmitCustomTrail(CUnit* owner, unsigned int id) {
explGenHandler.GenExplosion(id, owner->midPos, owner->frontdir, 1.0f, 0.0f, 1.0f, owner, nullptr);
explGenHandler.GenExplosion(
id,
owner->midPos,
owner->frontdir,
1.0f,
0.0f,
1.0f,
owner,
nullptr,
nullptr,
nullptr
);
}


Expand Down
13 changes: 12 additions & 1 deletion rts/Sim/Projectiles/ExpGenSpawner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,18 @@ void CExpGenSpawner::Update()
{
RECOIL_DETAILED_TRACY_ZONE;
if ((deleteMe |= ((delay--) <= 0)))
explosionGenerator->Explosion(pos, dir, damage, 0.0f, 0.0f, owner(), nullptr, true);
explosionGenerator->Explosion(
pos,
dir,
damage,
0.0f,
0.0f,
owner(),
nullptr,
nullptr,
nullptr,
true
);
}


Expand Down
64 changes: 50 additions & 14 deletions rts/Sim/Projectiles/ExplosionGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include "Sim/Projectiles/ProjectileHandler.h"
#include "Sim/Projectiles/ProjectileMemPool.h"

#include "Sim/Weapons/PlasmaRepulser.h"

#include "System/creg/STL_Map.h"
#include "System/FileSystem/ArchiveScanner.h"
#include "System/FileSystem/FileSystemInitializer.h"
Expand Down Expand Up @@ -57,14 +59,16 @@ unsigned int CCustomExplosionGenerator::GetFlagsFromTable(const LuaTable& table)
{
unsigned int flags = 0;

flags |= (CEG_SPWF_GROUND * table.GetBool( "ground", false));
flags |= (CEG_SPWF_WATER * table.GetBool( "water" , false));
flags |= (CEG_SPWF_VOIDGROUND * table.GetBool("voidground", false));
flags |= (CEG_SPWF_VOIDWATER * table.GetBool("voidwater" , false));
flags |= (CEG_SPWF_AIR * table.GetBool( "air", false));
flags |= (CEG_SPWF_UNDERWATER * table.GetBool("underwater", false));
flags |= (CEG_SPWF_UNIT * table.GetBool( "unit", false));
flags |= (CEG_SPWF_NO_UNIT * table.GetBool( "nounit", false));
flags |= (CEG_SPWF_GROUND * table.GetBool( "ground", false));
flags |= (CEG_SPWF_WATER * table.GetBool( "water" , false));
flags |= (CEG_SPWF_VOIDGROUND * table.GetBool( "voidground", false));
flags |= (CEG_SPWF_VOIDWATER * table.GetBool( "voidwater" , false));
flags |= (CEG_SPWF_AIR * table.GetBool( "air", false));
flags |= (CEG_SPWF_UNDERWATER * table.GetBool( "underwater", false));
flags |= (CEG_SPWF_UNIT * table.GetBool( "unit", false));
flags |= (CEG_SPWF_NO_UNIT * table.GetBool( "nounit", false));
flags |= (CEG_SPWF_SHIELD * table.GetBool( "shield", false));
flags |= (CEG_SPWF_INTERCEPTED * table.GetBool("intercepted", false));

return flags;
}
Expand Down Expand Up @@ -361,7 +365,9 @@ bool CExplosionGeneratorHandler::GenExplosion(
float radius,
float gfxMod,
CUnit* owner,
CUnit* hit,
CUnit* hitUnit,
CFeature* hitFeature,
CWeapon* hitWeapon,
bool withMutex
) {
RECOIL_DETAILED_TRACY_ZONE;
Expand All @@ -370,7 +376,18 @@ bool CExplosionGeneratorHandler::GenExplosion(
if (expGen == nullptr)
return false;

return (expGen->Explosion(pos, dir, damage, radius, gfxMod, owner, hit, withMutex));
return expGen->Explosion(
pos,
dir,
damage,
radius,
gfxMod,
owner,
hitUnit,
hitFeature,
hitWeapon,
withMutex
);
}


Expand All @@ -382,7 +399,9 @@ bool CStdExplosionGenerator::Explosion(
float radius,
float gfxMod,
CUnit* owner,
CUnit* hit,
CUnit* hitUnit,
CFeature* hitFeature,
CWeapon* hitWeapon,
bool withMutex
) {
RECOIL_DETAILED_TRACY_ZONE;
Expand Down Expand Up @@ -965,18 +984,24 @@ bool CCustomExplosionGenerator::Explosion(
float radius,
float gfxMod,
CUnit* owner,
CUnit* hit,
CUnit* hitUnit,
CFeature* hitFeature,
CWeapon* hitWeapon,
bool withMutex
) {
RECOIL_DETAILED_TRACY_ZONE;
unsigned int flags = GetFlagsFromHeight(pos.y, CGround::GetHeightReal(pos.x, pos.z));

const bool unitCollision = (hit != nullptr);
const bool unitCollision = (hitUnit != nullptr);
const bool shieldCollision = (dynamic_cast<CPlasmaRepulser*>(hitWeapon) != nullptr);
const bool groundExplosion = ((flags & CEG_SPWF_GROUND) != 0);

flags |= (CEG_SPWF_UNIT * ( unitCollision));
flags |= (CEG_SPWF_NO_UNIT * (1 - unitCollision));

flags |= CEG_SPWF_SHIELD * shieldCollision;
flags |= CEG_SPWF_INTERCEPTED * (hitWeapon && !shieldCollision);

const std::vector<ProjectileSpawnInfo>& spawnInfo = expGenParams.projectiles;
const GroundFlashInfo& groundFlash = expGenParams.groundFlash;

Expand Down Expand Up @@ -1010,7 +1035,18 @@ bool CCustomExplosionGenerator::Explosion(
projMemPool.alloc<CStandardGroundFlash>(pos, groundFlash);

if (expGenParams.useDefaultExplosions)
return (explGenHandler.GenExplosion(CExplosionGeneratorHandler::EXPGEN_ID_STANDARD, pos, dir, damage, radius, gfxMod, owner, hit));
return (explGenHandler.GenExplosion(
CExplosionGeneratorHandler::EXPGEN_ID_STANDARD,
pos,
dir,
damage,
radius,
gfxMod,
owner,
hitUnit,
hitFeature,
hitWeapon
));

return true;
}
Expand Down
36 changes: 24 additions & 12 deletions rts/Sim/Projectiles/ExplosionGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class LuaParser;
class LuaTable;
class float3;
class CUnit;
class CFeature;
class CWeapon;
class IExplosionGenerator;

struct SExpGenSpawnableMemberInfo;
Expand Down Expand Up @@ -66,7 +68,9 @@ class CExplosionGeneratorHandler
float radius,
float gfxMod,
CUnit* owner,
CUnit* hit,
CUnit* hitUnit,
CFeature* hitFeature,
CWeapon* hitWeapon,
bool withMutex = false
);

Expand Down Expand Up @@ -105,7 +109,9 @@ class IExplosionGenerator
float radius,
float gfxMod,
CUnit* owner,
CUnit* hit,
CUnit* hitUnit,
CFeature* hitFeature,
CWeapon* hitWeapon,
bool withMutex = false
) { return false; }

Expand All @@ -132,7 +138,9 @@ class CStdExplosionGenerator: public IExplosionGenerator
float radius,
float gfxMod,
CUnit* owner,
CUnit* hit,
CUnit* hitUnit,
CFeature* hitFeature,
CWeapon* hitWeapon,
bool withMutex
) override;
};
Expand Down Expand Up @@ -179,20 +187,24 @@ class CCustomExplosionGenerator: public IExplosionGenerator
float radius,
float gfxMod,
CUnit* owner,
CUnit* hit,
CUnit* hitUnit,
CFeature* hitFeature,
CWeapon* hitWeapon,
bool withMutex
) override;

// spawn-flags
enum {
CEG_SPWF_WATER = 1 << 0,
CEG_SPWF_GROUND = 1 << 1,
CEG_SPWF_VOIDWATER = 1 << 2,
CEG_SPWF_VOIDGROUND = 1 << 3,
CEG_SPWF_AIR = 1 << 4,
CEG_SPWF_UNDERWATER = 1 << 5, // TODO: UNDERVOIDWATER?
CEG_SPWF_UNIT = 1 << 6, // only execute when the explosion hits a unit
CEG_SPWF_NO_UNIT = 1 << 7, // only execute when the explosion doesn't hit a unit (environment)
CEG_SPWF_WATER = 1 << 0,
CEG_SPWF_GROUND = 1 << 1,
CEG_SPWF_VOIDWATER = 1 << 2,
CEG_SPWF_VOIDGROUND = 1 << 3,
CEG_SPWF_AIR = 1 << 4,
CEG_SPWF_UNDERWATER = 1 << 5, // TODO: UNDERVOIDWATER?
CEG_SPWF_UNIT = 1 << 6, // only execute when the explosion hits a unit
CEG_SPWF_NO_UNIT = 1 << 7, // only execute when the explosion doesn't hit a unit (environment)
CEG_SPWF_SHIELD = 1 << 8, // execute when the explosion hits a shield
CEG_SPWF_INTERCEPTED = 1 << 9, // the weapon projectile was intercepted
};

enum {
Expand Down
27 changes: 25 additions & 2 deletions rts/Sim/Projectiles/PieceProjectile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,18 @@ CPieceProjectile::CPieceProjectile(
cegID = guRNG.NextInt(ud->GetPieceExpGenCount());
cegID = ud->GetPieceExpGenID(cegID);

explGenHandler.GenExplosion(cegID, pos, speed, 100, 0.0f, 0.0f, nullptr, nullptr);
explGenHandler.GenExplosion(
cegID,
pos,
speed,
100.0f,
0.0f,
0.0f,
nullptr,
nullptr,
nullptr,
nullptr
);
}

model = owner->model;
Expand Down Expand Up @@ -151,6 +162,7 @@ void CPieceProjectile::Collision(CUnit* unit, CFeature* feature)
.owner = owner(),
.hitUnit = unit,
.hitFeature = feature,
.hitWeapon = nullptr,
.craterAreaOfEffect = modInfo.debrisDamage * 0.25f,
.damageAreaOfEffect = modInfo.debrisDamage * 0.5f,
.edgeEffectiveness = 0.0f,
Expand Down Expand Up @@ -220,7 +232,18 @@ void CPieceProjectile::Update()

if ((explFlags & PF_NoCEGTrail) == 0) {
// TODO: pass a more sensible ttl to the CEG (age-related?)
explGenHandler.GenExplosion(cegID, pos, speed, 100, 0.0f, 0.0f, nullptr, nullptr);
explGenHandler.GenExplosion(
cegID,
pos,
speed,
100,
0.0f,
0.0f,
nullptr,
nullptr,
nullptr,
nullptr
);
return;
}

Expand Down
2 changes: 2 additions & 0 deletions rts/Sim/Projectiles/Projectile.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

class CUnit;
class CFeature;
class CWeapon;
class CMatrix44f;
struct AtlasedTexture;
class CProjectileDrawer;
Expand All @@ -43,6 +44,7 @@ class CProjectile: public CExpGenSpawnable
virtual void Collision() { Delete(); }
virtual void Collision(CUnit* unit) { Collision(); }
virtual void Collision(CFeature* feature) { Collision(); }
virtual void Collision(CWeapon* weapon) { Collision(); }
//Not inheritable - used for removing a projectile from Lua.
void Delete();
virtual void Update();
Expand Down
13 changes: 12 additions & 1 deletion rts/Sim/Projectiles/WeaponProjectiles/BeamLaserProjectile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,18 @@ void CBeamLaserProjectile::Update()
edgeColEnd[i] *= decay;
}

explGenHandler.GenExplosion(cegID, startPos + ((targetPos - startPos) / ttl), (targetPos - startPos), 0.0f, flaresize, 0.0f, owner(), nullptr);
explGenHandler.GenExplosion(
cegID,
startPos + ((targetPos - startPos) / ttl),
targetPos - startPos,
0.0f,
flaresize,
0.0f,
owner(),
nullptr,
nullptr,
nullptr
);
}

UpdateInterception();
Expand Down
Loading