1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-16 10:19:47 +02:00
vcmi/scripting/lua/api/BattleCb.cpp

121 lines
2.3 KiB
C++
Raw Normal View History

/*
* BattleCb.cpp, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#include "StdInc.h"
#include "BattleCb.h"
#include <vcmi/Entity.h>
#include "../LuaStack.h"
#include "../LuaCallWrapper.h"
#include "../../../lib/GameConstants.h"
#include "../../../lib/battle/Unit.h"
#include "../../../lib/BattleFieldHandler.h"
2022-08-15 13:38:17 +02:00
VCMI_LIB_NAMESPACE_BEGIN
namespace scripting
{
namespace api
{
VCMI_REGISTER_CORE_SCRIPT_API(BattleCbProxy, "Battle");
2021-02-16 16:07:30 +02:00
const std::vector<BattleCbProxy::CustomRegType> BattleCbProxy::REGISTER_CUSTOM =
{
{
"getBattlefieldType",
2021-02-16 16:07:30 +02:00
&BattleCbProxy::getBattlefieldType,
false
},
{
"getNextUnitId",
2021-02-16 16:07:30 +02:00
LuaMethodWrapper<BattleCb, decltype(&BattleCb::battleNextUnitId), &BattleCb::battleNextUnitId>::invoke,
false
},
{
"getTacticDistance",
2021-02-16 16:07:30 +02:00
LuaMethodWrapper<BattleCb, decltype(&BattleCb::battleTacticDist), &BattleCb::battleTacticDist>::invoke,
false
},
{
"getTerrainType",
2021-02-16 16:07:30 +02:00
&BattleCbProxy::getTerrainType,
false
},
{
"getUnitById",
2021-02-16 16:07:30 +02:00
LuaMethodWrapper<BattleCb, decltype(&BattleCb::battleGetUnitByID), &BattleCb::battleGetUnitByID>::invoke,
false
},
{
"getUnitByPos",
2021-02-16 16:07:30 +02:00
&BattleCbProxy::getUnitByPos,
false
},
{
"isFinished",
2021-02-16 16:07:30 +02:00
LuaMethodWrapper<BattleCb, decltype(&BattleCb::battleIsFinished), &BattleCb::battleIsFinished>::invoke,
false
}
};
2021-02-16 16:07:30 +02:00
int BattleCbProxy::getBattlefieldType(lua_State * L)
{
2021-02-16 16:07:30 +02:00
LuaStack S(L);
2021-02-16 16:07:30 +02:00
const BattleCb * object;
if(!S.tryGet(1, object))
return S.retVoid();
auto ret = object->battleGetBattlefieldType();
2021-02-16 16:07:30 +02:00
return LuaStack::quickRetStr(L, ret.getInfo()->identifier);
}
2021-02-16 16:07:30 +02:00
int BattleCbProxy::getTerrainType(lua_State * L)
{
LuaStack S(L);
2021-02-16 16:07:30 +02:00
const BattleCb * object;
if(!S.tryGet(1, object))
return S.retVoid();
2023-02-01 21:25:09 +02:00
return LuaStack::quickRetInt(L, object->battleTerrainType().getNum());
}
2021-02-16 16:07:30 +02:00
int BattleCbProxy::getUnitByPos(lua_State * L)
{
LuaStack S(L);
2021-02-16 16:07:30 +02:00
const BattleCb * object;
if(!S.tryGet(1, object))
return S.retVoid();
BattleHex hex;
2021-02-16 16:07:30 +02:00
if(!S.tryGet(2, hex.hex))
return S.retNil();
bool onlyAlive;
2021-02-16 16:07:30 +02:00
if(!S.tryGet(3, onlyAlive))
onlyAlive = true;//same as default value in battleGetUnitByPos
2021-02-16 16:07:30 +02:00
S.clear();
S.push(object->battleGetUnitByPos(hex, onlyAlive));
return 1;
}
}
}
2022-08-15 13:38:17 +02:00
VCMI_LIB_NAMESPACE_END