Skip to content
Permalink
Browse files

fix #6317

  • Loading branch information...
rtri
rtri committed Nov 2, 2019
1 parent 1ad7ac2 commit 6ba05832597e6091f7c810f76c547dd54a585c13
@@ -1094,11 +1094,17 @@ function gadgetHandler:CommandFallback(unitID, unitDefID, unitTeam,
end


function gadgetHandler:AllowCommand(unitID, unitDefID, unitTeam,
cmdID, cmdParams, cmdOptions, cmdTag, synced)
function gadgetHandler:AllowCommand(
unitID, unitDefID, unitTeam,
cmdID, cmdParams, cmdOptions, cmdTag,
playerID, fromSynced, fromLua
)
for _,g in r_ipairs(self.AllowCommandList) do
if (not g:AllowCommand(unitID, unitDefID, unitTeam,
cmdID, cmdParams, cmdOptions, cmdTag, synced)) then
if (not g:AllowCommand(
unitID, unitDefID, unitTeam,
cmdID, cmdParams, cmdOptions, cmdTag,
playerID, fromSynced, fromLua)
) then
return false
end
end
@@ -1429,9 +1435,17 @@ function gadgetHandler:UnitCmdDone(unitID, unitDefID, unitTeam, cmdID, cmdParams
end
end

function gadgetHandler:UnitCommand(unitID, unitDefID, unitTeam, cmdID, cmdParams, cmdOpts, cmdTag)
function gadgetHandler:UnitCommand(
unitID, unitDefID, unitTeam,
cmdID, cmdParams, cmdOpts, cmdTag,
playerID, fromSynced, fromLua
)
for _,g in r_ipairs(self.UnitCommandList) do
g:UnitCommand(unitID, unitDefID, unitTeam, cmdID, cmdParams, cmdOpts, cmdTag)
g:UnitCommand(
unitID, unitDefID, unitTeam,
cmdID, cmdParams, cmdOpts, cmdTag,
playerID, fromSynced, fromLua
)
end
end

@@ -19,6 +19,9 @@ Lua:
- add Platform.hwConfig
- Script.IsEngineMinVersion now available in all Lua parsing contexts,
most importantly in `defs.lua`
! change {Allow,Unit}Command callin parameters
AllowCommand(..., cmdTag, fromSynced) --> AllowCommand(..., cmdTag, playerID, fromSynced, fromLua)
UnitCommand(..., cmdTag ) --> UnitCommand(..., cmdTag, playerID, fromSynced, fromLua)
! remove Game.mapHumanName
! remove UnitDefs[i].moveDef.{family,type}
- let Spring.SelectUnitArray select enemy units with godmode enabled
@@ -986,8 +989,8 @@ Lua (model rendering):
! gl.UnitShape and gl.FeatureShape now take three extra boolean arguments
and set their relevant GL state internally (so that calling only these
functions is enough to get correctly rendered models; pass in 'false'
for the [new] THIRD argument to get the fixed behavior, omit it or pass
in 'true' [default] to render with your own custom state instead)
for the [new] THIRD argument for the fixed behavior, omit it or pass in
'true' [default] to render with your own custom state instead)
NOTE:
the [new] FOURTH argument should be 'true' if in DrawScreen and 'false'
(default) if in DrawWorld; any transforms for these two functions *MUST*
@@ -110,7 +110,7 @@ bool CSelectedUnitsHandlerAI::GiveCommandNet(Command& c, int playerNum)
if (MayRequireSetMaxSpeedCommand(c))
SetUnitWantedMaxSpeedNet(unit);

unit->commandAI->GiveCommand(c, true);
unit->commandAI->GiveCommand(c, playerNum, true, false);

if (cmdID == CMD_WAIT && playerNum == gu->myPlayerNum)
waitCommandsAI.AcknowledgeCommand(c);
@@ -229,7 +229,7 @@ bool CSelectedUnitsHandlerAI::GiveCommandNet(Command& c, int playerNum)
SetUnitWantedMaxSpeedNet(unit);
}

unit->commandAI->GiveCommand(uc, ret = true);
unit->commandAI->GiveCommand(uc, playerNum, ret = true, false);
}

return ret;
@@ -247,7 +247,7 @@ bool CSelectedUnitsHandlerAI::GiveCommandNet(Command& c, int playerNum)
if (MayRequireSetMaxSpeedCommand(c))
SetUnitWantedMaxSpeedNet(unit);

unit->commandAI->GiveCommand(c, ret = true);
unit->commandAI->GiveCommand(c, playerNum, ret = true, false);
}

if (cmdID != CMD_WAIT)
@@ -331,7 +331,7 @@ void CSelectedUnitsHandlerAI::MakeFormationFrontOrder(Command* c, int playerNum)
if (unit == nullptr)
continue;

unit->commandAI->GiveCommand(*c, false);
unit->commandAI->GiveCommand(*c, playerNum, false, false);
}

return;
@@ -431,7 +431,7 @@ void CSelectedUnitsHandlerAI::MakeFormationFrontOrder(Command* c, int playerNum)
CUnit* unit = unitHandler.GetUnit(mixedUnitIDs[i]);
CCommandAI* cai = unit->commandAI;

cai->GiveCommand(frontMoveCommands[i].second, false);
cai->GiveCommand(frontMoveCommands[i].second, playerNum, false, false);
}

frontMoveCommands.clear();
@@ -565,7 +565,7 @@ bool CSelectedUnitsHandlerAI::SelectAttackNet(const Command& cmd, int playerNum)
if (!commandAI->WillCancelQueued(attackCmd))
continue;

commandAI->GiveCommand(attackCmd, ret = true);
commandAI->GiveCommand(attackCmd, playerNum, ret = true, false);
}
}

@@ -624,7 +624,7 @@ bool CSelectedUnitsHandlerAI::SelectAttackNet(const Command& cmd, int playerNum)
if (queueingCmd && commandAI->WillCancelQueued(attackCmd))
continue;

commandAI->GiveCommand(attackCmd, ret = true);
commandAI->GiveCommand(attackCmd, playerNum, ret = true, false);

SetUnitWantedMaxSpeedNet(unit);
// following commands are always queued
@@ -754,7 +754,7 @@ void CSelectedUnitsHandler::AINetOrder(int unitID, int aiTeamID, int playerID, c
// always pulled from net, synced command by definition
// (fromSynced determines whether CMD_UNLOAD_UNITS uses
// synced or unsynced randomized position sampling, etc)
unit->commandAI->GiveCommand(c, true);
unit->commandAI->GiveCommand(c, playerID, true, false);
}


@@ -930,21 +930,25 @@ void CLuaHandle::UnitIdle(const CUnit* unit)
}


void CLuaHandle::UnitCommand(const CUnit* unit, const Command& command)
void CLuaHandle::UnitCommand(const CUnit* unit, const Command& command, int playerNum, bool fromSynced, bool fromLua)
{
LUA_CALL_IN_CHECK(L);
luaL_checkstack(L, 11, __func__);
luaL_checkstack(L, 1 + 7 + 3, __func__);

const LuaUtils::ScopedDebugTraceBack traceBack(L);

static const LuaHashString cmdStr(__func__);
if (!cmdStr.GetGlobalFunc(L))
return;

LuaUtils::PushUnitAndCommand(L, unit, command);
const int argc = LuaUtils::PushUnitAndCommand(L, unit, command);

lua_pushnumber(L, playerNum);
lua_pushboolean(L, fromSynced);
lua_pushboolean(L, fromLua);

// call the routine
RunCallInTraceback(L, cmdStr, 7, 0, traceBack.GetErrFuncIdx(), false);
RunCallInTraceback(L, cmdStr, argc + 3, 0, traceBack.GetErrFuncIdx(), false);
}


@@ -47,11 +47,11 @@ class CLuaHandle : public CEventClient
void ResetCallinErrors() { callinErrors = 0; }

public:
#define PERMISSIONS_FUNCS(Name, type, dataArg, OVERRIDE) \
void Set ## Name(type _ ## dataArg) { GetLuaContextData(L)->dataArg = _ ## dataArg; } \
type Get ## Name() const OVERRIDE { return GetLuaContextData(L)->dataArg; } \
static void SetHandle ## Name(const lua_State* L, type _ ## dataArg) { GetLuaContextData(L)->dataArg = _ ## dataArg;; } \
static type GetHandle ## Name(const lua_State* L) { return GetLuaContextData(L)->dataArg; }
#define PERMISSIONS_FUNCS(Name, type, val, OVERRIDE) \
void Set ## Name(type _ ## val) { GetLuaContextData(L)->val = _ ## val; } \
type Get ## Name( ) const OVERRIDE { return GetLuaContextData(L)->val ; } \
static void SetHandle ## Name(const lua_State* L, type _ ## val) { GetLuaContextData(L)->val = _ ## val; } \
static type GetHandle ## Name(const lua_State* L ) { return GetLuaContextData(L)->val ; }

PERMISSIONS_FUNCS(FullRead, bool, fullRead, override); // virtual function in CEventClient
PERMISSIONS_FUNCS(FullCtrl, bool, fullCtrl, );
@@ -126,8 +126,8 @@ class CLuaHandle : public CEventClient
void UnitGiven(const CUnit* unit, int oldTeam, int newTeam) override;

void UnitIdle(const CUnit* unit) override;
void UnitCommand(const CUnit* unit, const Command& command) override;
void UnitCmdDone(const CUnit* unit, const Command& command) override;
void UnitCommand(const CUnit* unit, const Command& command, int playerNum, bool fromSynced, bool fromLua) override;
void UnitCmdDone(const CUnit* unit, const Command& command ) override;
void UnitDamaged(
const CUnit* unit,
const CUnit* attacker,
@@ -516,21 +516,23 @@ bool CSyncedLuaHandle::CommandFallback(const CUnit* unit, const Command& cmd)
}


bool CSyncedLuaHandle::AllowCommand(const CUnit* unit, const Command& cmd, bool fromSynced)
bool CSyncedLuaHandle::AllowCommand(const CUnit* unit, const Command& cmd, int playerNum, bool fromSynced, bool fromLua)
{
LUA_CALL_IN_CHECK(L, true);
luaL_checkstack(L, 10, __func__);
luaL_checkstack(L, 7 + 3, __func__);

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

LuaUtils::PushUnitAndCommand(L, unit, cmd);
const int argc = LuaUtils::PushUnitAndCommand(L, unit, cmd);

lua_pushnumber(L, playerNum);
lua_pushboolean(L, fromSynced);
lua_pushboolean(L, fromLua);

// call the function
if (!RunCallIn(L, cmdStr, 8, 1))
if (!RunCallIn(L, cmdStr, argc + 3, 1))
return true;

// get the results
@@ -52,7 +52,7 @@ class CSyncedLuaHandle : public CLuaHandle

public: // call-ins
bool CommandFallback(const CUnit* unit, const Command& cmd) override;
bool AllowCommand(const CUnit* unit, const Command& cmd, bool fromSynced) override;
bool AllowCommand(const CUnit* unit, const Command& cmd, int playerNum, bool fromSynced, bool fromLua) override;

bool AllowUnitCreation(const UnitDef* unitDef, const CUnit* builder, const BuildInfo* buildInfo) override;
bool AllowUnitTransfer(const CUnit* unit, int newTeam, bool capture) override;
@@ -3541,7 +3541,7 @@ int LuaSyncedCtrl::GiveOrderToUnit(lua_State* L)
luaL_error(L, "[%s] recursion not permitted", __func__);

inGiveOrder = true;
unit->commandAI->GiveCommand(cmd);
unit->commandAI->GiveCommand(cmd, -1, true, true);
inGiveOrder = false;

lua_pushboolean(L, true);
@@ -3554,11 +3554,11 @@ int LuaSyncedCtrl::GiveOrderToUnitMap(lua_State* L)
CheckAllowGameChanges(L);

// units
vector<CUnit*> units;
std::vector<CUnit*> units;

ParseUnitMap(L, __func__, 1, units);
const int unitCount = (int)units.size();

if (unitCount <= 0) {
if (units.empty()) {
lua_pushnumber(L, 0);
return 1;
}
@@ -3570,10 +3570,9 @@ int LuaSyncedCtrl::GiveOrderToUnitMap(lua_State* L)

inGiveOrder = true;
int count = 0;
for (int i = 0; i < unitCount; i++) {
CUnit* unit = units[i];
for (CUnit* unit: units) {
if (CanControlUnit(L, unit)) {
unit->commandAI->GiveCommand(cmd);
unit->commandAI->GiveCommand(cmd, -1, true, true);
count++;
}
}
@@ -3589,11 +3588,11 @@ int LuaSyncedCtrl::GiveOrderToUnitArray(lua_State* L)
CheckAllowGameChanges(L);

// units
vector<CUnit*> units;
std::vector<CUnit*> units;

ParseUnitArray(L, __func__, 1, units);
const int unitCount = (int)units.size();

if (unitCount <= 0) {
if (units.empty()) {
lua_pushnumber(L, 0);
return 1;
}
@@ -3606,10 +3605,9 @@ int LuaSyncedCtrl::GiveOrderToUnitArray(lua_State* L)
inGiveOrder = true;

int count = 0;
for (int i = 0; i < unitCount; i++) {
CUnit* unit = units[i];
for (CUnit* unit: units) {
if (CanControlUnit(L, unit)) {
unit->commandAI->GiveCommand(cmd);
unit->commandAI->GiveCommand(cmd, -1, true, true);
count++;
}
}
@@ -3625,17 +3623,13 @@ int LuaSyncedCtrl::GiveOrderArrayToUnitMap(lua_State* L)
{
CheckAllowGameChanges(L);

// units
vector<CUnit*> units;
ParseUnitMap(L, __func__, 1, units);
const int unitCount = (int)units.size();
std::vector<CUnit*> units;
std::vector<Command> commands;

// commands
vector<Command> commands;
ParseUnitMap(L, __func__, 1, units);
LuaUtils::ParseCommandArray(L, __func__, 2, commands);
const int commandCount = (int)commands.size();

if ((unitCount <= 0) || (commandCount <= 0)) {
if (units.empty() || commands.empty()) {
lua_pushnumber(L, 0);
return 1;
}
@@ -3646,11 +3640,10 @@ int LuaSyncedCtrl::GiveOrderArrayToUnitMap(lua_State* L)
inGiveOrder = true;

int count = 0;
for (int u = 0; u < unitCount; u++) {
CUnit* unit = units[u];
for (CUnit* unit: units) {
if (CanControlUnit(L, unit)) {
for (int c = 0; c < commandCount; c++) {
unit->commandAI->GiveCommand(commands[c]);
for (const Command& c: commands) {
unit->commandAI->GiveCommand(c, -1, true, true);
}
count++;
}
@@ -3667,18 +3660,13 @@ int LuaSyncedCtrl::GiveOrderArrayToUnitArray(lua_State* L)
CheckAllowGameChanges(L);

// units
vector<CUnit*> units;
ParseUnitArray(L, __func__, 1, units);
const int unitCount = (int)units.size();
std::vector<CUnit*> units;
std::vector<Command> commands;

// commands
vector<Command> commands;
ParseUnitArray(L, __func__, 1, units);
LuaUtils::ParseCommandArray(L, __func__, 2, commands);
const int commandCount = (int)commands.size();

bool pairwise = luaL_optboolean(L, 3, false);

if ((unitCount <= 0) || (commandCount <= 0)) {
if (units.empty() || commands.empty()) {
lua_pushnumber(L, 0);
return 1;
}
@@ -3689,21 +3677,21 @@ int LuaSyncedCtrl::GiveOrderArrayToUnitArray(lua_State* L)
inGiveOrder = true;

int count = 0;
if (pairwise) {
for (int x = 0; x < std::min(unitCount, commandCount); ++x) {
CUnit* unit = units[x];

if (luaL_optboolean(L, 3, false)) {
// pairwise
for (size_t i = 0, n = std::min(units.size(), commands.size()); i < n; ++i) {
CUnit* unit = units[i];
if (CanControlUnit(L, unit)) {
unit->commandAI->GiveCommand(commands[x]);
unit->commandAI->GiveCommand(commands[i], -1, true, true);
count++;
}
}
}
else {
for (int u = 0; u < unitCount; u++) {
CUnit* unit = units[u];
} else {
for (CUnit* unit: units) {
if (CanControlUnit(L, unit)) {
for (int c = 0; c < commandCount; c++) {
unit->commandAI->GiveCommand(commands[c]);
for (const Command& c: commands) {
unit->commandAI->GiveCommand(c, -1, true, true);
}
count++;
}

0 comments on commit 6ba0583

Please sign in to comment.
You can’t perform that action at this time.