Navigation Menu

Skip to content

Commit

Permalink
fix #6012
Browse files Browse the repository at this point in the history
adding AllowUnitTransport{Load,Unload} callins officially
makes {un}loading no longer the engine's problem to solve
  • Loading branch information
rt committed Jul 16, 2018
1 parent 65e10e8 commit aa20328
Show file tree
Hide file tree
Showing 9 changed files with 249 additions and 125 deletions.
2 changes: 2 additions & 0 deletions cont/base/springcontent/LuaGadgets/callins.lua
Expand Up @@ -102,6 +102,8 @@ CALLIN_LIST = {
"AllowUnitTransfer",
"AllowUnitBuildStep",
"AllowUnitTransport",
"AllowUnitTransportLoad",
"AllowUnitTransportUnload",
"AllowUnitCloak",
"AllowUnitDecloak",
"AllowFeatureBuildStep",
Expand Down
37 changes: 35 additions & 2 deletions cont/base/springcontent/LuaGadgets/gadgets.lua
Expand Up @@ -1138,14 +1138,47 @@ function gadgetHandler:AllowUnitTransport(
transporteeID, transporteeUnitDefID, transporteeTeam
)
for _,g in r_ipairs(self.AllowUnitTransportList) do
if (not g:AllowUnitTransport(transporterID, transporterUnitDefID, transporterTeam,
transporteeID, transporteeUnitDefID, transporteeTeam)) then
if (not g:AllowUnitTransport(
transporterID, transporterUnitDefID, transporterTeam,
transporteeID, transporteeUnitDefID, transporteeTeam
)) then
return false
end
end
return true
end

function gadgetHandler:AllowUnitTransportLoad(
transporterID, transporterUnitDefID, transporterTeam,
transporteeID, transporteeUnitDefID, transporteeTeam
)
for _,g in r_ipairs(self.AllowUnitTransportLoadList) do
if (not g:AllowUnitTransportLoad(
transporterID, transporterUnitDefID, transporterTeam,
transporteeID, transporteeUnitDefID, transporteeTeam
)) then
return false
end
end
return true
end

function gadgetHandler:AllowUnitTransportUnload(
transporterID, transporterUnitDefID, transporterTeam,
transporteeID, transporteeUnitDefID, transporteeTeam
)
for _,g in r_ipairs(self.AllowUnitTransportUnloadList) do
if (not g:AllowUnitTransportUnload(
transporterID, transporterUnitDefID, transporterTeam,
transporteeID, transporteeUnitDefID, transporteeTeam
)) then
return false
end
end
return true
end


function gadgetHandler:AllowUnitCloak(unitID, enemyID)
for _,g in r_ipairs(self.AllowUnitCloakList) do
if (not g:AllowUnitCloak(unitID, enemyID)) then
Expand Down
140 changes: 94 additions & 46 deletions rts/Lua/LuaHandleSynced.cpp
Expand Up @@ -207,9 +207,9 @@ bool CUnsyncedLuaHandle::DrawUnit(const CUnit* unit)
if (!success)
return false;

const bool retval = luaL_optboolean(L, -1, false);
const bool draw = luaL_optboolean(L, -1, false);
lua_pop(L, 1);
return retval;
return draw;
}


Expand All @@ -234,9 +234,9 @@ bool CUnsyncedLuaHandle::DrawFeature(const CFeature* feature)
if (!success)
return false;

const bool retval = luaL_optboolean(L, -1, false);
const bool draw = luaL_optboolean(L, -1, false);
lua_pop(L, 1);
return retval;
return draw;
}


Expand All @@ -263,9 +263,9 @@ bool CUnsyncedLuaHandle::DrawShield(const CUnit* unit, const CWeapon* weapon)
if (!success)
return false;

const bool retval = luaL_optboolean(L, -1, false);
const bool draw = luaL_optboolean(L, -1, false);
lua_pop(L, 1);
return retval;
return draw;
}


Expand All @@ -292,9 +292,9 @@ bool CUnsyncedLuaHandle::DrawProjectile(const CProjectile* projectile)
if (!success)
return false;

const bool retval = luaL_optboolean(L, -1, false);
const bool draw = luaL_optboolean(L, -1, false);
lua_pop(L, 1);
return retval;
return draw;
}


Expand Down Expand Up @@ -475,9 +475,9 @@ bool CSyncedLuaHandle::CommandFallback(const CUnit* unit, const Command& cmd)
if (!RunCallIn(L, cmdStr, 7, 1))
return true;

const bool retval = luaL_optboolean(L, -1, true);
const bool remove = luaL_optboolean(L, -1, true);
lua_pop(L, 1);
return retval; // return 'true' to remove the command
return remove; // return 'true' to remove the command
}


Expand All @@ -499,9 +499,9 @@ bool CSyncedLuaHandle::AllowCommand(const CUnit* unit, const Command& cmd, bool
return true;

// get the results
const bool retval = luaL_optboolean(L, -1, true);
const bool allow = luaL_optboolean(L, -1, true);
lua_pop(L, 1);
return retval;
return allow;
}


Expand Down Expand Up @@ -531,9 +531,9 @@ bool CSyncedLuaHandle::AllowUnitCreation(const UnitDef* unitDef,
return true;

// get the results
const bool retval = luaL_optboolean(L, -1, true);
const bool allow = luaL_optboolean(L, -1, true);
lua_pop(L, 1);
return retval;
return allow;
}


Expand All @@ -558,9 +558,9 @@ bool CSyncedLuaHandle::AllowUnitTransfer(const CUnit* unit, int newTeam, bool ca
return true;

// get the results
const bool retval = luaL_optboolean(L, -1, true);
const bool allow = luaL_optboolean(L, -1, true);
lua_pop(L, 1);
return retval;
return allow;
}


Expand All @@ -585,21 +585,21 @@ bool CSyncedLuaHandle::AllowUnitBuildStep(const CUnit* builder,
return true;

// get the results
const bool retval = luaL_optboolean(L, -1, true);
const bool allow = luaL_optboolean(L, -1, true);
lua_pop(L, 1);
return retval;
return allow;
}


bool CSyncedLuaHandle::AllowUnitTransport(const CUnit* transporter, const CUnit* transportee)
{
LUA_CALL_IN_CHECK(L, true);
luaL_checkstack(L, 8, __func__);
luaL_checkstack(L, 2 + 6, __func__);

static const LuaHashString cmdStr(__func__);

if (!cmdStr.GetGlobalFunc(L))
return true; // the call is not defined
return true;

lua_pushnumber(L, transporter->id);
lua_pushnumber(L, transporter->unitDef->id);
Expand All @@ -608,14 +608,62 @@ bool CSyncedLuaHandle::AllowUnitTransport(const CUnit* transporter, const CUnit*
lua_pushnumber(L, transportee->unitDef->id);
lua_pushnumber(L, transportee->team);

// call the function
if (!RunCallIn(L, cmdStr, 6, 1))
return true;

// get the results
const bool retval = luaL_optboolean(L, -1, true);
const bool allow = luaL_optboolean(L, -1, true);
lua_pop(L, 1);
return allow;
}

bool CSyncedLuaHandle::AllowUnitTransportLoad(const CUnit* transporter, const CUnit* transportee, bool allowed)
{
LUA_CALL_IN_CHECK(L, true);
luaL_checkstack(L, 2 + 6, __func__);

static const LuaHashString cmdStr(__func__);

if (!cmdStr.GetGlobalFunc(L))
return allowed;

lua_pushnumber(L, transporter->id);
lua_pushnumber(L, transporter->unitDef->id);
lua_pushnumber(L, transporter->team);
lua_pushnumber(L, transportee->id);
lua_pushnumber(L, transportee->unitDef->id);
lua_pushnumber(L, transportee->team);

if (!RunCallIn(L, cmdStr, 6, 1))
return true;

const bool allow = luaL_optboolean(L, -1, allowed);
lua_pop(L, 1);
return allow;
}

bool CSyncedLuaHandle::AllowUnitTransportUnload(const CUnit* transporter, const CUnit* transportee, bool allowed)
{
LUA_CALL_IN_CHECK(L, true);
luaL_checkstack(L, 2 + 6, __func__);

static const LuaHashString cmdStr(__func__);

if (!cmdStr.GetGlobalFunc(L))
return allowed;

lua_pushnumber(L, transporter->id);
lua_pushnumber(L, transporter->unitDef->id);
lua_pushnumber(L, transporter->team);
lua_pushnumber(L, transportee->id);
lua_pushnumber(L, transportee->unitDef->id);
lua_pushnumber(L, transportee->team);

if (!RunCallIn(L, cmdStr, 6, 1))
return true;

const bool allow = luaL_optboolean(L, -1, allowed);
lua_pop(L, 1);
return retval;
return allow;
}


Expand All @@ -641,9 +689,9 @@ bool CSyncedLuaHandle::AllowUnitCloak(const CUnit* unit, const CUnit* enemy)
if (!RunCallIn(L, cmdStr, 2, 1))
return true;

const bool retval = luaL_optboolean(L, -1, true);
const bool allow = luaL_optboolean(L, -1, true);
lua_pop(L, 1);
return retval;
return allow;
}

bool CSyncedLuaHandle::AllowUnitDecloak(const CUnit* unit, const CSolidObject* object, const CWeapon* weapon)
Expand Down Expand Up @@ -675,9 +723,9 @@ bool CSyncedLuaHandle::AllowUnitDecloak(const CUnit* unit, const CSolidObject* o

assert(lua_isboolean(L, -1));

const bool retval = lua_toboolean(L, -1);
const bool allow = lua_toboolean(L, -1);
lua_pop(L, 1);
return retval;
return allow;
}


Expand All @@ -701,9 +749,9 @@ bool CSyncedLuaHandle::AllowFeatureCreation(const FeatureDef* featureDef, int te
return true;

// get the results
const bool retval = luaL_optboolean(L, -1, true);
const bool allow = luaL_optboolean(L, -1, true);
lua_pop(L, 1);
return retval;
return allow;
}


Expand All @@ -727,9 +775,9 @@ bool CSyncedLuaHandle::AllowFeatureBuildStep(const CUnit* builder, const CFeatur
return true;

// get the results
const bool retval = luaL_optboolean(L, -1, true);
const bool allow = luaL_optboolean(L, -1, true);
lua_pop(L, 1);
return retval;
return allow;
}


Expand All @@ -751,9 +799,9 @@ bool CSyncedLuaHandle::AllowResourceLevel(int teamID, const string& type, float
return true;

// get the results
const bool retval = luaL_optboolean(L, -1, true);
const bool allow = luaL_optboolean(L, -1, true);
lua_pop(L, 1);
return retval;
return allow;
}


Expand All @@ -776,9 +824,9 @@ bool CSyncedLuaHandle::AllowResourceTransfer(int oldTeam, int newTeam, const cha
return true;

// get the results
const bool retval = luaL_optboolean(L, -1, true);
const bool allow = luaL_optboolean(L, -1, true);
lua_pop(L, 1);
return retval;
return allow;
}


Expand All @@ -801,9 +849,9 @@ bool CSyncedLuaHandle::AllowDirectUnitControl(int playerID, const CUnit* unit)
return true;

// get the results
const bool retval = luaL_optboolean(L, -1, true);
const bool allow = luaL_optboolean(L, -1, true);
lua_pop(L, 1);
return retval;
return allow;
}


Expand All @@ -825,9 +873,9 @@ bool CSyncedLuaHandle::AllowBuilderHoldFire(const CUnit* unit, int action)
return true;

// get the results
const bool retval = luaL_optboolean(L, -1, true);
const bool allow = luaL_optboolean(L, -1, true);
lua_pop(L, 1);
return retval;
return allow;
}


Expand Down Expand Up @@ -856,9 +904,9 @@ bool CSyncedLuaHandle::AllowStartPosition(int playerID, int teamID, unsigned cha
return true;

// get the results
const bool retval = luaL_optboolean(L, -1, true);
const bool allow = luaL_optboolean(L, -1, true);
lua_pop(L, 1);
return retval;
return allow;
}


Expand All @@ -882,9 +930,9 @@ bool CSyncedLuaHandle::MoveCtrlNotify(const CUnit* unit, int data)
return false;

// get the results
const bool retval = luaL_optboolean(L, -1, false);
const bool disable = luaL_optboolean(L, -1, false);
lua_pop(L, 1);
return retval;
return disable;
}


Expand Down Expand Up @@ -914,9 +962,9 @@ bool CSyncedLuaHandle::TerraformComplete(const CUnit* unit, const CUnit* build)
return false;

// get the results
const bool retval = luaL_optboolean(L, -1, false);
const bool stop = luaL_optboolean(L, -1, false);
lua_pop(L, 1);
return retval;
return stop;
}


Expand Down
2 changes: 2 additions & 0 deletions rts/Lua/LuaHandleSynced.h
Expand Up @@ -59,6 +59,8 @@ class CSyncedLuaHandle : public CLuaHandle
bool AllowUnitTransfer(const CUnit* unit, int newTeam, bool capture) override;
bool AllowUnitBuildStep(const CUnit* builder, const CUnit* unit, float part) override;
bool AllowUnitTransport(const CUnit* transporter, const CUnit* transportee) override;
bool AllowUnitTransportLoad(const CUnit* transporter, const CUnit* transportee, bool allowed) override;
bool AllowUnitTransportUnload(const CUnit* transporter, const CUnit* transportee, bool allowed) override;
bool AllowUnitCloak(const CUnit* unit, const CUnit* enemy) override;
bool AllowUnitDecloak(const CUnit* unit, const CSolidObject* object, const CWeapon* weapon) override;
bool AllowFeatureCreation(const FeatureDef* featureDef, int allyTeamID, const float3& pos) override;
Expand Down

0 comments on commit aa20328

Please sign in to comment.