Skip to content

Commit

Permalink
Allow spawning of any CEG from any LUS:
Browse files Browse the repository at this point in the history
- EmitSFX("cegTag") param will emit the CEG with tag="cegTag"
- EmitSFX(SFX.ABSOLUTE & cegID) will emit the CEG with id=cegID
- Added Spring.GetCEGID("cegTag") to return CEG id from tag
  • Loading branch information
ashdnazg committed Feb 20, 2019
1 parent cf4c80d commit 0193643
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 1 deletion.
4 changes: 4 additions & 0 deletions doc/changelog.txt
Expand Up @@ -116,6 +116,10 @@ Lua:
- Added VFS.GetFileAbsolutePath(string vfsFilePath) -> string filePathOnDisk
- Added VFS.GetArchiveContainingFile(string vfsFilePath) -> string archiveName
- add a 6th return value (feature->reclaimTime) to GetFeatureResources.
- Allow spawning of any CEG from any LUS:
EmitSFX("cegTag") param will emit the CEG with tag="cegTag"
EmitSFX(SFX.ABSOLUTE & cegID) will emit the CEG with id=cegID
Added Spring.GetCEGID("cegTag") to return CEG id from tag


AI:
Expand Down
1 change: 1 addition & 0 deletions rts/Lua/LuaConstCOB.cpp
Expand Up @@ -142,6 +142,7 @@ bool LuaConstSFX::PushEntries(lua_State* L)
LuaPushNamedNumber(L, "CEG", SFX_CEG);
LuaPushNamedNumber(L, "FIRE_WEAPON", SFX_FIRE_WEAPON);
LuaPushNamedNumber(L, "DETONATE_WEAPON", SFX_DETONATE_WEAPON);
LuaPushNamedNumber(L, "ABSOLUTE", SFX_ABSOLUTE);

return true;
}
Expand Down
12 changes: 12 additions & 0 deletions rts/Lua/LuaSyncedRead.cpp
Expand Up @@ -45,6 +45,7 @@
#include "Sim/MoveTypes/StaticMoveType.h"
#include "Sim/MoveTypes/MoveDefHandler.h"
#include "Sim/Path/IPathManager.h"
#include "Sim/Projectiles/ExplosionGenerator.h"
#include "Sim/Projectiles/Projectile.h"
#include "Sim/Projectiles/PieceProjectile.h"
#include "Sim/Projectiles/WeaponProjectiles/WeaponProjectile.h"
Expand Down Expand Up @@ -260,6 +261,8 @@ bool LuaSyncedRead::PushEntries(lua_State* L)
REGISTER_LUA_CFUNC(GetUnitRulesParam);
REGISTER_LUA_CFUNC(GetUnitRulesParams);

REGISTER_LUA_CFUNC(GetCEGID);

REGISTER_LUA_CFUNC(GetAllFeatures);
REGISTER_LUA_CFUNC(GetFeatureDefID);
REGISTER_LUA_CFUNC(GetFeatureTeam);
Expand Down Expand Up @@ -3971,6 +3974,15 @@ int LuaSyncedRead::GetUnitDefDimensions(lua_State* L)
}


int LuaSyncedRead::GetCEGID(lua_State* L)
{
const unsigned int cegID = explGenHandler.LoadGeneratorID(std::string(CEG_PREFIX_STRING) + lua_tostring(L, 1));

lua_pushnumber(L, cegID);
return 1;
}


int LuaSyncedRead::GetUnitBlocking(lua_State* L)
{
return (GetSolidObjectBlocking(L, ParseTypedUnit(L, __func__, 1)));
Expand Down
2 changes: 2 additions & 0 deletions rts/Lua/LuaSyncedRead.h
Expand Up @@ -172,6 +172,8 @@ class LuaSyncedRead {
static int GetUnitFeatureSeparation(lua_State* L);
static int GetUnitDefDimensions(lua_State* L);

static int GetCEGID(lua_State* L);

static int GetAllFeatures(lua_State* L);

static int ValidFeatureID(lua_State* L);
Expand Down
1 change: 1 addition & 0 deletions rts/Sim/Units/Scripts/CobDefines.h
Expand Up @@ -18,6 +18,7 @@
#define SFX_CEG 1024
#define SFX_FIRE_WEAPON 2048
#define SFX_DETONATE_WEAPON 4096
#define SFX_ABSOLUTE 16384


// Indices for set/get value
Expand Down
10 changes: 9 additions & 1 deletion rts/Sim/Units/Scripts/LuaUnitScript.cpp
Expand Up @@ -4,6 +4,7 @@

#include "LuaUnitScript.h"

#include "CobDefines.h"
#include "CobInstance.h"
#include "LuaInclude.h"
#include "NullUnitScript.h"
Expand All @@ -13,6 +14,7 @@
#include "Lua/LuaCallInCheck.h"
#include "Lua/LuaHandleSynced.h"
#include "Lua/LuaUtils.h"
#include "Sim/Projectiles/ExplosionGenerator.h"
#include "Sim/Units/UnitHandler.h"
#include "Sim/Units/Unit.h"
#include "Sim/Weapons/PlasmaRepulser.h"
Expand Down Expand Up @@ -1195,7 +1197,13 @@ int CLuaUnitScript::EmitSfx(lua_State* L)

// note: the arguments are reversed compared to the C++ (and COB?) function
const int piece = luaL_checkint(L, 1) - 1;
const int type = luaL_checkint(L, 2);
int type = CExplosionGeneratorHandler::EXPGEN_ID_INVALID;

if (lua_isstring(L, 2)) {
type = explGenHandler.LoadGeneratorID(std::string(CEG_PREFIX_STRING) + lua_tostring(L, 2)) & SFX_ABSOLUTE;
} else {
type = luaL_checkint(L, 2);
}

activeScript->EmitSfx(type, piece);
return 0;
Expand Down
6 changes: 6 additions & 0 deletions rts/Sim/Units/Scripts/UnitScript.cpp
Expand Up @@ -551,6 +551,12 @@ bool CUnitScript::EmitAbsSFX(int sfxType, const float3& absPos, const float3& ab
} break;

default: {
if ((sfxType & SFX_ABSOLUTE) != 0) {
// emit defined explosion-generator (can only be custom, not standard)
// index is made valid by callee, an ID of -1 means CEG failed to load
explGenHandler.GenExplosion(sfxType - SFX_ABSOLUTE, absPos, absDir, unit->cegDamage, 1.0f, 0.0f, unit, nullptr);
return true;
}
if ((sfxType & SFX_CEG) != 0) {
// emit defined explosion-generator (can only be custom, not standard)
// index is made valid by callee, an ID of -1 means CEG failed to load
Expand Down

0 comments on commit 0193643

Please sign in to comment.