1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-06-15 00:05:02 +02:00

Entities redesign and a few ERM features

* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
This commit is contained in:
AlexVinS
2018-03-17 17:58:30 +03:00
committed by AlexVinS
parent 11bb46780a
commit ecaa9f5d0b
475 changed files with 22491 additions and 7123 deletions

View File

@ -0,0 +1,48 @@
/*
* api/Artifact.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 "Artifact.h"
#include "Registry.h"
#include "../LuaStack.h"
#include "../LuaCallWrapper.h"
#include "../../../lib/HeroBonus.h"
namespace scripting
{
namespace api
{
VCMI_REGISTER_CORE_SCRIPT_API(ArtifactProxy, "Artifact");
const std::vector<ArtifactProxy::RegType> ArtifactProxy::REGISTER = {};
const std::vector<ArtifactProxy::CustomRegType> ArtifactProxy::REGISTER_CUSTOM =
{
{"getIconIndex", LuaMethodWrapper<Artifact, int32_t(Entity:: *)()const, &Entity::getIconIndex>::invoke, false},
{"getIndex", LuaMethodWrapper<Artifact, int32_t(Entity:: *)()const, &Entity::getIndex>::invoke, false},
{"getJsonKey", LuaMethodWrapper<Artifact, const std::string &(Entity:: *)()const, &Entity::getJsonKey>::invoke, false},
{"getName", LuaMethodWrapper<Artifact, const std::string &(Entity:: *)()const, &Entity::getName>::invoke, false},
{"getId", LuaMethodWrapper<Artifact, ArtifactID(EntityT<ArtifactID>::*)()const, &EntityT<ArtifactID>::getId>::invoke, false},
{"accessBonuses", LuaMethodWrapper<Artifact, const IBonusBearer *(EntityWithBonuses<ArtifactID>:: *)()const, &EntityWithBonuses<ArtifactID>::accessBonuses>::invoke, false},
{"getDescription", LuaMethodWrapper<Artifact, const std::string &(Artifact:: *)()const, &Artifact::getDescription>::invoke, false},
{"getEventText", LuaMethodWrapper<Artifact, const std::string &(Artifact:: *)()const, &Artifact::getEventText>::invoke, false},
{"isBig", LuaMethodWrapper<Artifact, bool(Artifact:: *)()const, &Artifact::isBig>::invoke, false},
{"isTradable", LuaMethodWrapper<Artifact, bool(Artifact:: *)()const, &Artifact::isTradable>::invoke, false},
{"getPrice", LuaMethodWrapper<Artifact, uint32_t(Artifact:: *)()const, &Artifact::getPrice>::invoke, false},
};
}
}

View File

@ -0,0 +1,32 @@
/*
* api/Artifact.h, 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
*
*/
#pragma once
#include <vcmi/Artifact.h>
#include "../LuaWrapper.h"
namespace scripting
{
namespace api
{
class ArtifactProxy : public OpaqueWrapper<const Artifact, ArtifactProxy>
{
public:
using Wrapper = OpaqueWrapper<const Artifact, ArtifactProxy>;
static const std::vector<typename Wrapper::RegType> REGISTER;
static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
};
}
}

View File

@ -0,0 +1,101 @@
/*
* 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 "../LuaStack.h"
#include "../LuaCallWrapper.h"
#include "../../../lib/GameConstants.h"
#include "../../../lib/battle/Unit.h"
namespace scripting
{
namespace api
{
VCMI_REGISTER_CORE_SCRIPT_API(BattleCbProxy, "Battle");
const std::vector<BattleCbProxy::RegType> BattleCbProxy::REGISTER =
{
{
"getBattlefieldType",
&BattleCbProxy::getBattlefieldType
},
{
"getNextUnitId",
LuaCallWrapper<const BattleCb>::createFunctor(&BattleCb::battleNextUnitId)
},
{
"getTacticDistance",
LuaCallWrapper<const BattleCb>::createFunctor(&BattleCb::battleTacticDist)
},
{
"getTerrainType",
&BattleCbProxy::getTerrainType
},
{
"getUnitById",
LuaCallWrapper<const BattleCb>::createFunctor(&BattleCb::battleGetUnitByID)
},
{
"getUnitByPos",
&BattleCbProxy::getUnitByPos
},
{
"isFinished",
LuaCallWrapper<const BattleCb>::createFunctor(&BattleCb::battleIsFinished)
}
};
const std::vector<BattleCbProxy::CustomRegType> BattleCbProxy::REGISTER_CUSTOM =
{
};
int BattleCbProxy::getBattlefieldType(lua_State * L, const BattleCb * object)
{
LuaStack S(L);
auto ret = object->battleGetBattlefieldType();
S.push(static_cast<si32>(ret.num));
return 1;
}
int BattleCbProxy::getTerrainType(lua_State * L, const BattleCb * object)
{
LuaStack S(L);
auto ret = object->battleTerrainType();
S.push(static_cast<si32>(ret.num));
return 1;
}
int BattleCbProxy::getUnitByPos(lua_State * L, const BattleCb * object)
{
LuaStack S(L);
BattleHex hex;
if(!S.tryGet(1, hex.hex))
return S.retNil();
bool onlyAlive;
if(!S.tryGet(2, onlyAlive))
onlyAlive = true;//same as default value in battleGetUnitByPos
S.push(object->battleGetUnitByPos(hex, onlyAlive));
return 1;
}
}
}

View File

@ -0,0 +1,37 @@
/*
* BattleCb.h, 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
*
*/
#pragma once
#include <vcmi/scripting/Service.h>
#include "../../../lib/battle/IBattleInfoCallback.h"
#include "../LuaWrapper.h"
namespace scripting
{
namespace api
{
class BattleCbProxy : public OpaqueWrapper<const BattleCb, BattleCbProxy>
{
public:
using Wrapper = OpaqueWrapper<const BattleCb, BattleCbProxy>;
static const std::vector<typename Wrapper::RegType> REGISTER;
static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
static int getBattlefieldType(lua_State * L, const BattleCb * object);
static int getTerrainType(lua_State * L, const BattleCb * object);
static int getUnitByPos(lua_State * L, const BattleCb * object);
};
}
}

View File

@ -0,0 +1,232 @@
/*
* BonusSystem.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 "BonusSystem.h"
#include "../../../lib/HeroBonus.h"
#include "Registry.h"
#include "../LuaStack.h"
#include "../LuaCallWrapper.h"
namespace scripting
{
namespace api
{
VCMI_REGISTER_SCRIPT_API(BonusProxy, "Bonus");
const std::vector<BonusProxy::RegType> BonusProxy::REGISTER =
{
{"getType", &BonusProxy::getType},
{"getSubtype", &BonusProxy::getSubtype},
{"getDuration", &BonusProxy::getDuration},
{"getTurns", &BonusProxy::getTurns},
{"getValueType", &BonusProxy::getValueType},
{"getVal", &BonusProxy::getVal},
{"getSource", &BonusProxy::getSource},
{"getSourceID", &BonusProxy::getSourceID},
{"getEffectRange", &BonusProxy::getEffectRange},
{"getStacking", &BonusProxy::getStacking},
{"getDescription", &BonusProxy::getDescription},
{"toJsonNode", &BonusProxy::toJsonNode}
};
const std::vector<BonusProxy::CustomRegType> BonusProxy::REGISTER_CUSTOM =
{
};
int BonusProxy::getType(lua_State * L, std::shared_ptr<const Bonus> object)
{
return LuaStack::quickRetInt(L, object->type);
}
int BonusProxy::getSubtype(lua_State * L, std::shared_ptr<const Bonus> object)
{
return LuaStack::quickRetInt(L, object->subtype);
}
int BonusProxy::getDuration(lua_State * L, std::shared_ptr<const Bonus> object)
{
return LuaStack::quickRetInt(L, object->duration);
}
int BonusProxy::getTurns(lua_State * L, std::shared_ptr<const Bonus> object)
{
return LuaStack::quickRetInt(L, object->turnsRemain);
}
int BonusProxy::getValueType(lua_State * L, std::shared_ptr<const Bonus> object)
{
return LuaStack::quickRetInt(L, object->valType);
}
int BonusProxy::getVal(lua_State * L, std::shared_ptr<const Bonus> object)
{
return LuaStack::quickRetInt(L, object->val);
}
int BonusProxy::getSource(lua_State * L, std::shared_ptr<const Bonus> object)
{
return LuaStack::quickRetInt(L, object->source);
}
int BonusProxy::getSourceID(lua_State * L, std::shared_ptr<const Bonus> object)
{
return LuaStack::quickRetInt(L, object->sid);
}
int BonusProxy::getEffectRange(lua_State * L, std::shared_ptr<const Bonus> object)
{
return LuaStack::quickRetInt(L, object->effectRange);
}
int BonusProxy::getStacking(lua_State * L, std::shared_ptr<const Bonus> object)
{
return LuaStack::quickRetStr(L, object->stacking);
}
int BonusProxy::getDescription(lua_State * L, std::shared_ptr<const Bonus> object)
{
return LuaStack::quickRetStr(L, object->description);
}
int BonusProxy::toJsonNode(lua_State * L, std::shared_ptr<const Bonus> object)
{
LuaStack S(L);
S.clear();
S.push(object->toJsonNode());
return 1;
}
template <typename T>
static void publishMap(lua_State * L, const T & map)
{
for(auto & p : map)
{
const std::string & name = p.first;
int32_t id = static_cast<int32_t>(p.second);
lua_pushstring(L, name.c_str());
lua_pushinteger(L, id);
lua_rawset(L, -3);
}
}
void BonusProxy::adjustStaticTable(lua_State * L) const
{
publishMap(L, bonusNameMap);
publishMap(L, bonusValueMap);
publishMap(L, bonusSourceMap);
publishMap(L, bonusDurationMap);
}
VCMI_REGISTER_SCRIPT_API(BonusListProxy, "BonusList");
const std::vector<BonusListProxy::RegType> BonusListProxy::REGISTER =
{
};
const std::vector<BonusListProxy::CustomRegType> BonusListProxy::REGISTER_CUSTOM =
{
};
int BonusListProxy::index(lua_State * L)
{
//field = __index(self, key)
LuaStack S(L);
std::shared_ptr<const BonusList> self;
lua_Integer key = -1;
if(S.tryGet(1, self) && S.tryGetInteger(2, key))
{
if((key >= 1) && (key <= self->size()))
{
std::shared_ptr<const Bonus> ret = (*self)[key-1];
S.clear();
S.push(ret);
return 1;
}
}
return S.retNil();
}
void BonusListProxy::adjustMetatable(lua_State * L) const
{
lua_pushstring(L, "__index");
lua_pushcfunction(L, &BonusListProxy::index);
lua_rawset(L, -3);
}
VCMI_REGISTER_SCRIPT_API(BonusBearerProxy, "BonusBearer");
const std::vector<BonusBearerProxy::RegType> BonusBearerProxy::REGISTER =
{
{"getBonuses", &BonusBearerProxy::getBonuses},
};
const std::vector<BonusBearerProxy::CustomRegType> BonusBearerProxy::REGISTER_CUSTOM =
{
};
int BonusBearerProxy::getBonuses(lua_State * L, const IBonusBearer * object)
{
LuaStack S(L);
TConstBonusListPtr ret;
const bool hasSelector = S.isFunction(1);
const bool hasRangeSelector = S.isFunction(2);
if(hasSelector)
{
auto selector = [](const Bonus * b)
{
return false; //TODO: BonusBearerProxy::getBonuses selector
};
if(hasRangeSelector)
{
auto rangeSelector = [](const Bonus * b)
{
return false;//TODO: BonusBearerProxy::getBonuses rangeSelector
};
ret = object->getBonuses(selector, rangeSelector);
}
else
{
ret = object->getBonuses(selector, Selector::all);
}
}
else
{
ret = object->getBonuses(Selector::all, Selector::all);
}
S.clear();
S.push(ret);
return S.retPushed();
}
}
}

View File

@ -0,0 +1,75 @@
/*
* BonusSystem.h, 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
*
*/
#pragma once
#include "../LuaWrapper.h"
class Bonus;
class BonusList;
class IBonusBearer;
namespace scripting
{
namespace api
{
class BonusProxy : public SharedWrapper<const Bonus, BonusProxy>
{
public:
using Wrapper = SharedWrapper<const Bonus, BonusProxy>;
static const std::vector<typename Wrapper::RegType> REGISTER;
static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
static int getType(lua_State * L, std::shared_ptr<const Bonus> object);
static int getSubtype(lua_State * L, std::shared_ptr<const Bonus> object);
static int getDuration(lua_State * L, std::shared_ptr<const Bonus> object);
static int getTurns(lua_State * L, std::shared_ptr<const Bonus> object);
static int getValueType(lua_State * L, std::shared_ptr<const Bonus> object);
static int getVal(lua_State * L, std::shared_ptr<const Bonus> object);
static int getSource(lua_State * L, std::shared_ptr<const Bonus> object);
static int getSourceID(lua_State * L, std::shared_ptr<const Bonus> object);
static int getDescription(lua_State * L, std::shared_ptr<const Bonus> object);
static int getEffectRange(lua_State * L, std::shared_ptr<const Bonus> object);
static int getStacking(lua_State * L, std::shared_ptr<const Bonus> object);
static int toJsonNode(lua_State * L, std::shared_ptr<const Bonus> object);
protected:
virtual void adjustStaticTable(lua_State * L) const override;
};
class BonusListProxy : public SharedWrapper<const BonusList, BonusListProxy>
{
public:
using Wrapper = SharedWrapper<const BonusList, BonusListProxy>;
static const std::vector<typename Wrapper::RegType> REGISTER;
static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
static int index(lua_State * L);
protected:
virtual void adjustMetatable(lua_State * L) const override;
};
class BonusBearerProxy : public OpaqueWrapper<const IBonusBearer, BonusBearerProxy>
{
public:
using Wrapper = OpaqueWrapper<const IBonusBearer, BonusBearerProxy>;
static int getBonuses(lua_State * L, const IBonusBearer * object);
static const std::vector<typename Wrapper::RegType> REGISTER;
static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
};
}
}

View File

@ -0,0 +1,68 @@
/*
* api/Creature.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 "Creature.h"
#include "Registry.h"
#include "../LuaStack.h"
#include "../LuaCallWrapper.h"
#include "../../../lib/HeroBonus.h"
namespace scripting
{
namespace api
{
VCMI_REGISTER_CORE_SCRIPT_API(CreatureProxy, "Creature");
const std::vector<CreatureProxy::RegType> CreatureProxy::REGISTER =
{
{"accessBonuses", LuaCallWrapper<const EntityWithBonuses<CreatureID>>::createFunctor(&EntityWithBonuses<CreatureID>::accessBonuses)},
{"getCost", LuaCallWrapper<const Creature>::createFunctor(&Creature::getCost)},
{"isDoubleWide", LuaCallWrapper<const Creature>::createFunctor(&Creature::isDoubleWide)},
};
const std::vector<CreatureProxy::CustomRegType> CreatureProxy::REGISTER_CUSTOM =
{
{"getIconIndex", LuaMethodWrapper<Creature, int32_t(Entity:: *)()const, &Entity::getIconIndex>::invoke, false},
{"getIndex", LuaMethodWrapper<Creature, int32_t(Entity:: *)()const, &Entity::getIndex>::invoke, false},
{"getJsonKey", LuaMethodWrapper<Creature, const std::string &(Entity:: *)()const, &Entity::getJsonKey>::invoke, false},
{"getName", LuaMethodWrapper<Creature, const std::string &(Entity:: *)()const, &Entity::getName>::invoke, false},
{"accessBonuses", LuaMethodWrapper<Creature, const IBonusBearer *(EntityWithBonuses<CreatureID>:: *)()const, &EntityWithBonuses<CreatureID>::accessBonuses>::invoke, false},
{"getMaxHealth", LuaMethodWrapper<Creature, uint32_t(Creature:: *)()const, &Creature::getMaxHealth>::invoke, false},
{"getPluralName", LuaMethodWrapper<Creature, const std::string &(Creature:: *)()const, &Creature::getPluralName>::invoke, false},
{"getSingularName", LuaMethodWrapper<Creature, const std::string &(Creature:: *)()const, &Creature::getSingularName>::invoke, false},
{"getAdvMapAmountMin", LuaMethodWrapper<Creature, int32_t(Creature:: *)()const, &Creature::getAdvMapAmountMin>::invoke, false},
{"getAdvMapAmountMax", LuaMethodWrapper<Creature, int32_t(Creature:: *)()const, &Creature::getAdvMapAmountMax>::invoke, false},
{"getAIValue", LuaMethodWrapper<Creature, int32_t(Creature:: *)()const, &Creature::getAIValue>::invoke, false},
{"getFightValue", LuaMethodWrapper<Creature, int32_t(Creature:: *)()const, &Creature::getFightValue>::invoke, false},
{"getLevel", LuaMethodWrapper<Creature, int32_t(Creature:: *)()const, &Creature::getLevel>::invoke, false},
{"getGrowth", LuaMethodWrapper<Creature, int32_t(Creature:: *)()const, &Creature::getGrowth>::invoke, false},
{"getHorde", LuaMethodWrapper<Creature, int32_t(Creature:: *)()const, &Creature::getHorde>::invoke, false},
{"getFactionIndex", LuaMethodWrapper<Creature, int32_t(Creature:: *)()const, &Creature::getFactionIndex>::invoke, false},
{"getBaseAttack", LuaMethodWrapper<Creature, int32_t(Creature:: *)()const, &Creature::getBaseAttack>::invoke, false},
{"getBaseDefense", LuaMethodWrapper<Creature, int32_t(Creature:: *)()const, &Creature::getBaseDefense>::invoke, false},
{"getBaseDamageMin", LuaMethodWrapper<Creature, int32_t(Creature:: *)()const, &Creature::getBaseDamageMin>::invoke, false},
{"getBaseDamageMax", LuaMethodWrapper<Creature, int32_t(Creature:: *)()const, &Creature::getBaseDamageMax>::invoke, false},
{"getBaseHitPoints", LuaMethodWrapper<Creature, int32_t(Creature:: *)()const, &Creature::getBaseHitPoints>::invoke, false},
{"getBaseSpellPoints", LuaMethodWrapper<Creature, int32_t(Creature:: *)()const, &Creature::getBaseSpellPoints>::invoke, false},
{"getBaseSpeed", LuaMethodWrapper<Creature, int32_t(Creature:: *)()const, &Creature::getBaseSpeed>::invoke, false},
{"getBaseShots", LuaMethodWrapper<Creature, int32_t(Creature:: *)()const, &Creature::getBaseShots>::invoke, false},
};
}
}

View File

@ -0,0 +1,33 @@
/*
* api/Creature.h, 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
*
*/
#pragma once
#include <vcmi/Creature.h>
#include "../LuaWrapper.h"
namespace scripting
{
namespace api
{
class CreatureProxy : public OpaqueWrapper<const Creature, CreatureProxy>
{
public:
using Wrapper = OpaqueWrapper<const Creature, CreatureProxy>;
static const std::vector<typename Wrapper::RegType> REGISTER;
static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
};
}
}

View File

@ -0,0 +1,38 @@
/*
* api/Faction.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 "Faction.h"
#include "Registry.h"
#include "../LuaStack.h"
#include "../LuaCallWrapper.h"
namespace scripting
{
namespace api
{
VCMI_REGISTER_CORE_SCRIPT_API(FactionProxy, "Faction");
const std::vector<FactionProxy::RegType> FactionProxy::REGISTER = {};
const std::vector<FactionProxy::CustomRegType> FactionProxy::REGISTER_CUSTOM =
{
{"getIconIndex", LuaMethodWrapper<Faction, int32_t(Entity:: *)()const, &Entity::getIconIndex>::invoke, false},
{"getIndex", LuaMethodWrapper<Faction, int32_t(Entity:: *)()const, &Entity::getIndex>::invoke, false},
{"getJsonKey", LuaMethodWrapper<Faction, const std::string &(Entity:: *)()const, &Entity::getJsonKey>::invoke, false},
{"getName", LuaMethodWrapper<Faction, const std::string &(Entity:: *)()const, &Entity::getName>::invoke, false},
{"hasTown", LuaMethodWrapper<Faction, bool(Faction:: *)()const, &Faction::hasTown>::invoke, false},
};
}
}

View File

@ -0,0 +1,31 @@
/*
* api/Faction.h, 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
*
*/
#pragma once
#include <vcmi/Faction.h>
#include "../LuaWrapper.h"
namespace scripting
{
namespace api
{
class FactionProxy : public OpaqueWrapper<const Faction, FactionProxy>
{
public:
using Wrapper = OpaqueWrapper<const Faction, FactionProxy>;
static const std::vector<typename Wrapper::RegType> REGISTER;
static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
};
}
}

View File

@ -0,0 +1,43 @@
/*
* GameCb.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 "GameCb.h"
#include <vcmi/Player.h>
#include "../LuaCallWrapper.h"
#include "../../../lib/mapObjects/CGHeroInstance.h"
namespace scripting
{
namespace api
{
VCMI_REGISTER_CORE_SCRIPT_API(GameCbProxy, "Game");
const std::vector<GameCbProxy::RegType> GameCbProxy::REGISTER = {};
const std::vector<GameCbProxy::CustomRegType> GameCbProxy::REGISTER_CUSTOM =
{
{"getDate", LuaMethodWrapper<GameCb, int32_t(GameCb:: *)(Date::EDateType)const, &GameCb::getDate>::invoke, false},
{"isAllowed", LuaMethodWrapper<GameCb, bool(GameCb:: *)(int32_t, int32_t)const, &GameCb::isAllowed>::invoke, false},
{"getCurrentPlayer", LuaMethodWrapper<GameCb, PlayerColor(GameCb:: *)()const, &GameCb::getLocalPlayer>::invoke, false},
{"getPlayer", LuaMethodWrapper<GameCb, const Player * (GameCb:: *)(PlayerColor)const, &GameCb::getPlayer>::invoke, false},
{"getHero", LuaMethodWrapper<GameCb, const CGHeroInstance *(GameCb:: *)(ObjectInstanceID)const, &GameCb::getHero>::invoke, false},
{"getHeroWithSubid", LuaMethodWrapper<GameCb, const CGHeroInstance *(GameCb:: *)(int)const, &GameCb::getHeroWithSubid>::invoke, false},
{"getObj", LuaMethodWrapper<GameCb, const CGObjectInstance *(GameCb:: *)(ObjectInstanceID, bool)const, &GameCb::getObj>::invoke, false},
};
}
}

View File

@ -0,0 +1,34 @@
/*
* GameCb.h, 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
*
*/
#pragma once
#include <vcmi/scripting/Service.h>
#include "../../../lib/CGameInfoCallback.h"
#include "../LuaWrapper.h"
namespace scripting
{
namespace api
{
class GameCbProxy : public OpaqueWrapper<const GameCb, GameCbProxy>
{
public:
using Wrapper = OpaqueWrapper<const GameCb, GameCbProxy>;
static const std::vector<typename Wrapper::RegType> REGISTER;
static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
};
}
}

View File

@ -0,0 +1,36 @@
/*
* api/HeroClass.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 "HeroClass.h"
#include "Registry.h"
#include "../LuaStack.h"
#include "../LuaCallWrapper.h"
namespace scripting
{
namespace api
{
VCMI_REGISTER_CORE_SCRIPT_API(HeroClassProxy, "HeroClass");
const std::vector<HeroClassProxy::RegType> HeroClassProxy::REGISTER = {};
const std::vector<HeroClassProxy::CustomRegType> HeroClassProxy::REGISTER_CUSTOM =
{
{"getIconIndex", LuaMethodWrapper<HeroClass, int32_t(Entity:: *)()const, &Entity::getIconIndex>::invoke, false},
{"getIndex", LuaMethodWrapper<HeroClass, int32_t(Entity:: *)()const, &Entity::getIndex>::invoke, false},
{"getJsonKey", LuaMethodWrapper<HeroClass, const std::string &(Entity:: *)()const, &Entity::getJsonKey>::invoke, false},
{"getName", LuaMethodWrapper<HeroClass, const std::string &(Entity:: *)()const, &Entity::getName>::invoke, false},
};
}
}

View File

@ -0,0 +1,32 @@
/*
* api/HeroClass.h, 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
*
*/
#pragma once
#include <vcmi/HeroClass.h>
#include "../LuaWrapper.h"
namespace scripting
{
namespace api
{
class HeroClassProxy : public OpaqueWrapper<const HeroClass, HeroClassProxy>
{
public:
using Wrapper = OpaqueWrapper<const HeroClass, HeroClassProxy>;
static const std::vector<typename Wrapper::RegType> REGISTER;
static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
};
}
}

View File

@ -0,0 +1,35 @@
/*
* HeroInstance.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 "HeroInstance.h"
#include "Registry.h"
#include "../LuaStack.h"
#include "../LuaCallWrapper.h"
namespace scripting
{
namespace api
{
VCMI_REGISTER_CORE_SCRIPT_API(HeroInstanceProxy, "HeroInstance");
const std::vector<HeroInstanceProxy::RegType> HeroInstanceProxy::REGISTER = {};
const std::vector<HeroInstanceProxy::CustomRegType> HeroInstanceProxy::REGISTER_CUSTOM =
{
{"getStack", LuaMethodWrapper<CGHeroInstance, const CStackInstance *(CCreatureSet:: *)(SlotID)const, &CCreatureSet::getStackPtr>::invoke, false},
{"getOwner", LuaMethodWrapper<CGHeroInstance, PlayerColor(CGObjectInstance:: *)()const, &CGObjectInstance::getOwner>::invoke, false},
};
}
}

View File

@ -0,0 +1,35 @@
/*
* HeroInstance.h, 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
*
*/
#pragma once
#include <vcmi/HeroClass.h>
#include "../LuaWrapper.h"
#include "../../../lib/mapObjects/CGHeroInstance.h"
namespace scripting
{
namespace api
{
class HeroInstanceProxy : public OpaqueWrapper<const CGHeroInstance, HeroInstanceProxy>
{
public:
using Wrapper = OpaqueWrapper<const CGHeroInstance, HeroInstanceProxy>;
static const std::vector<typename Wrapper::RegType> REGISTER;
static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
};
}
}

View File

@ -0,0 +1,38 @@
/*
* api/HeroType.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 "HeroType.h"
#include "Registry.h"
#include "../LuaStack.h"
#include "../LuaCallWrapper.h"
namespace scripting
{
namespace api
{
VCMI_REGISTER_CORE_SCRIPT_API(HeroTypeProxy, "HeroType");
const std::vector<HeroTypeProxy::RegType> HeroTypeProxy::REGISTER = {};
const std::vector<HeroTypeProxy::CustomRegType> HeroTypeProxy::REGISTER_CUSTOM =
{
{"getIconIndex", LuaMethodWrapper<HeroType, int32_t(Entity:: *)()const, &Entity::getIconIndex>::invoke, false},
{"getIndex", LuaMethodWrapper<HeroType, int32_t(Entity:: *)()const, &Entity::getIndex>::invoke, false},
{"getJsonKey", LuaMethodWrapper<HeroType, const std::string &(Entity:: *)()const, &Entity::getJsonKey>::invoke, false},
{"getName", LuaMethodWrapper<HeroType, const std::string &(Entity:: *)()const, &Entity::getName>::invoke, false},
};
}
}

View File

@ -0,0 +1,32 @@
/*
* api/HeroType.h, 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
*
*/
#pragma once
#include <vcmi/HeroType.h>
#include "../LuaWrapper.h"
namespace scripting
{
namespace api
{
class HeroTypeProxy : public OpaqueWrapper<const HeroType, HeroTypeProxy>
{
public:
using Wrapper = OpaqueWrapper<const HeroType, HeroTypeProxy>;
static const std::vector<typename Wrapper::RegType> REGISTER;
static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
};
}
}

View File

@ -0,0 +1,38 @@
/*
* ObjectInstance.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 "ObjectInstance.h"
#include "Registry.h"
#include "../LuaStack.h"
#include "../LuaCallWrapper.h"
namespace scripting
{
namespace api
{
VCMI_REGISTER_CORE_SCRIPT_API(ObjectInstanceProxy, "ObjectInstance");
const std::vector<ObjectInstanceProxy::RegType> ObjectInstanceProxy::REGISTER = {};
const std::vector<ObjectInstanceProxy::CustomRegType> ObjectInstanceProxy::REGISTER_CUSTOM =
{
{"getOwner", LuaMethodWrapper<CGObjectInstance, PlayerColor(IObjectInterface:: *)()const, &IObjectInterface::getOwner>::invoke, false},
{"getObjGroupIndex", LuaMethodWrapper<CGObjectInstance, int32_t(IObjectInterface:: *)()const, &IObjectInterface::getObjGroupIndex>::invoke, false},
{"getObjTypeIndex", LuaMethodWrapper<CGObjectInstance, int32_t(IObjectInterface:: *)()const, &IObjectInterface::getObjTypeIndex>::invoke, false},
{"getVisitablePosition", LuaMethodWrapper<CGObjectInstance, int3(IObjectInterface:: *)()const, &IObjectInterface::visitablePos>::invoke, false},
{"getPosition", LuaMethodWrapper<CGObjectInstance, int3(IObjectInterface:: *)()const, &IObjectInterface::getPosition>::invoke, false},
};
}
}

View File

@ -0,0 +1,35 @@
/*
* ObjectInstance.h, 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
*
*/
#pragma once
#include <vcmi/HeroClass.h>
#include "../LuaWrapper.h"
#include "../../../lib/mapObjects/CObjectHandler.h"
namespace scripting
{
namespace api
{
class ObjectInstanceProxy : public OpaqueWrapper<const IObjectInterface, ObjectInstanceProxy>
{
public:
using Wrapper = OpaqueWrapper<const IObjectInterface, ObjectInstanceProxy>;
static const std::vector<typename Wrapper::RegType> REGISTER;
static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
};
}
}

View File

@ -0,0 +1,42 @@
/*
* api/Player.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 "Player.h"
#include "Registry.h"
#include "../LuaStack.h"
#include "../LuaCallWrapper.h"
namespace scripting
{
namespace api
{
VCMI_REGISTER_CORE_SCRIPT_API(PlayerProxy, "Player");
const std::vector<PlayerProxy::RegType> PlayerProxy::REGISTER =
{
};
const std::vector<PlayerProxy::CustomRegType> PlayerProxy::REGISTER_CUSTOM =
{
// virtual PlayerColor getColor() const = 0;
// virtual TeamID getTeam() const = 0;
// virtual bool isHuman() const = 0;
// virtual const IBonusBearer * accessBonuses() const = 0;
// virtual int getResourceAmount(int type) const = 0;
};
}
}

View File

@ -0,0 +1,33 @@
/*
* api/Player.h, 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
*
*/
#pragma once
#include <vcmi/Player.h>
#include "../LuaWrapper.h"
namespace scripting
{
namespace api
{
class PlayerProxy : public OpaqueWrapper<const Player, PlayerProxy>
{
public:
using Wrapper = OpaqueWrapper<const Player, PlayerProxy>;
static const std::vector<typename Wrapper::RegType> REGISTER;
static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
};
}
}

View File

@ -0,0 +1,88 @@
/*
* Registry.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 "api/Registry.h"
namespace scripting
{
namespace api
{
Registry::Registry() = default;
Registry * Registry::get()
{
static std::unique_ptr<Registry> Instance = std::unique_ptr<Registry>(new Registry());
return Instance.get();
}
void Registry::add(const std::string & name, std::shared_ptr<Registar> item)
{
data[name] = item;
}
void Registry::addCore(const std::string & name, std::shared_ptr<Registar> item)
{
coreData[name] = item;
}
const Registar * Registry::find(const std::string & name) const
{
auto iter = data.find(name);
if(iter == data.end())
return nullptr;
else
return iter->second.get();
}
TypeRegistry::TypeRegistry()
: nextIndex(0)
{
}
TypeRegistry * TypeRegistry::get()
{
static std::unique_ptr<TypeRegistry> Instance = std::unique_ptr<TypeRegistry>(new TypeRegistry());
return Instance.get();
}
const char * TypeRegistry::getKeyForType(const std::type_info & type)
{
//std::type_index is unique and stable (because all bindings are in vcmiLua shared lib), but there is no way to convert it to Lua value
//there is no guarantee that name is unique, but it is at least somewhat human readable, so we append unique number to name
//TODO: name demangle
std::type_index typeIndex(type);
boost::unique_lock<boost::mutex> lock(mutex);
auto iter = keys.find(typeIndex);
if(iter == std::end(keys))
{
std::string newKey = type.name();
newKey += "_";
newKey += std::to_string(nextIndex++);
keys[typeIndex] = std::move(newKey);
return keys[typeIndex].c_str();
}
else
{
return iter->second.c_str();
}
}
}
}

View File

@ -0,0 +1,110 @@
/*
* Registry.h, 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
*
*/
#pragma once
#include <typeinfo>
#include <typeindex>
#define VCMI_REGISTER_SCRIPT_API(Type, Name) \
namespace\
{\
RegisterAPI<Type> _register ## Type (Name);\
}\
\
#define VCMI_REGISTER_CORE_SCRIPT_API(Type, Name) \
namespace\
{\
RegisterCoreAPI<Type> _register ## Type (Name);\
}\
\
namespace scripting
{
namespace api
{
class TypeRegistry;
class Registar
{
public:
virtual ~Registar() = default;
virtual void pushMetatable(lua_State * L) const = 0;
};
class Registry : public boost::noncopyable
{
public:
using RegistryData = std::map<std::string, std::shared_ptr<Registar>>;
static Registry * get();
const Registar * find(const std::string & name) const;
void add(const std::string & name, std::shared_ptr<Registar> item);
void addCore(const std::string & name, std::shared_ptr<Registar> item);
const RegistryData & getCoreData() const
{
return coreData;
}
private:
RegistryData data;
RegistryData coreData;
Registry();
};
template<typename T>
class RegisterAPI
{
public:
RegisterAPI(const std::string & name)
{
auto r = std::make_shared<T>();
Registry::get()->add(name, r);
}
};
template<typename T>
class RegisterCoreAPI
{
public:
RegisterCoreAPI(const std::string & name)
{
auto r = std::make_shared<T>();
Registry::get()->addCore(name, r);
}
};
class TypeRegistry : public boost::noncopyable
{
public:
template<typename T>
const char * getKey()
{
return getKeyForType(typeid(T));
}
static TypeRegistry * get();
private:
size_t nextIndex;
boost::mutex mutex;
std::map<std::type_index, std::string> keys;
TypeRegistry();
const char * getKeyForType(const std::type_info & type);
};
}
}

View File

@ -0,0 +1,93 @@
/*
* ServerCb.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 "ServerCb.h"
#include "Registry.h"
#include "../LuaStack.h"
#include "../../../lib/NetPacks.h"
namespace scripting
{
namespace api
{
VCMI_REGISTER_CORE_SCRIPT_API(ServerCbProxy, "Server");
const std::vector<ServerCbProxy::RegType> ServerCbProxy::REGISTER =
{
{
"addToBattleLog",
&ServerCbProxy::apply<BattleLogMessage>
},
{
"moveUnit",
&ServerCbProxy::apply<BattleStackMoved>
},
{
"changeUnits",
&ServerCbProxy::apply<BattleUnitsChanged>
},
{
"commitPackage",
&ServerCbProxy::commitPackage
}
};
const std::vector<ServerCbProxy::CustomRegType> ServerCbProxy::REGISTER_CUSTOM =
{
};
int ServerCbProxy::commitPackage(lua_State * L, ServerCallback * object)
{
if(lua_isuserdata(L, 1) != 1)
{
lua_settop(L, 0);
return 0;
}
lua_getfield(L, 1, "toNetpackLight");
lua_insert(L, 1);
int ret = lua_pcall(L, 1, 1, 0);
if(ret != 0 || !lua_islightuserdata(L, 1))
{
lua_settop(L, 0);
return 0;
}
CPackForClient * pack = static_cast<CPackForClient *>(lua_touserdata(L, 1));
object->apply(pack);
lua_settop(L, 0);
return 0;
}
template<typename NetPack>
int ServerCbProxy::apply(lua_State * L, ServerCallback * object)
{
LuaStack S(L);
std::shared_ptr<NetPack> pack;
if(!S.tryGet(1, pack))
return S.retVoid();
object->apply(pack.get());
return S.retVoid();
}
}
}

View File

@ -0,0 +1,37 @@
/*
* ServerCb.h, 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
*
*/
#pragma once
#include <vcmi/ServerCallback.h>
#include "../LuaWrapper.h"
namespace scripting
{
namespace api
{
class ServerCbProxy : public OpaqueWrapper<ServerCallback, ServerCbProxy>
{
public:
using Wrapper = OpaqueWrapper<ServerCallback, ServerCbProxy>;
static int commitPackage(lua_State * L, ServerCallback * object);
static const std::vector<typename Wrapper::RegType> REGISTER;
static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
template<typename NetPack>
static int apply(lua_State * L, ServerCallback * object);
};
}
}

View File

@ -0,0 +1,137 @@
/*
* api/Services.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 "Services.h"
#include <vcmi/Artifact.h>
#include <vcmi/Creature.h>
#include <vcmi/Faction.h>
#include <vcmi/HeroClass.h>
#include <vcmi/HeroType.h>
#include <vcmi/Skill.h>
#include <vcmi/spells/Spell.h>
#include "Registry.h"
#include "../LuaStack.h"
#include "../LuaCallWrapper.h"
namespace scripting
{
namespace api
{
VCMI_REGISTER_CORE_SCRIPT_API(ServicesProxy, "Services");
const std::vector<ServicesProxy::RegType> ServicesProxy::REGISTER =
{
{"artifacts", LuaCallWrapper<const Services>::createFunctor(&Services::artifacts)},
{"creatures", LuaCallWrapper<const Services>::createFunctor(&Services::creatures)},
{"factions", LuaCallWrapper<const Services>::createFunctor(&Services::factions)},
{"heroClasses", LuaCallWrapper<const Services>::createFunctor(&Services::heroClasses)},
{"heroTypes", LuaCallWrapper<const Services>::createFunctor(&Services::heroTypes)},
{"spells", LuaCallWrapper<const Services>::createFunctor(&Services::spells)},
{"skills", LuaCallWrapper<const Services>::createFunctor(&Services::skills)},
};
const std::vector<ServicesProxy::CustomRegType> ServicesProxy::REGISTER_CUSTOM =
{
};
VCMI_REGISTER_CORE_SCRIPT_API(ArtifactServiceProxy, "Artifacts");
const std::vector<ArtifactServiceProxy::RegType> ArtifactServiceProxy::REGISTER =
{
{"getByIndex", LuaCallWrapper<const EntityServiceT<ArtifactID, Artifact>>::createFunctor(&ArtifactService::getByIndex)}
};
const std::vector<ArtifactServiceProxy::CustomRegType> ArtifactServiceProxy::REGISTER_CUSTOM =
{
};
VCMI_REGISTER_CORE_SCRIPT_API(CreatureServiceProxy, "Creatures");
const std::vector<CreatureServiceProxy::RegType> CreatureServiceProxy::REGISTER =
{
{"getByIndex", LuaCallWrapper<const EntityServiceT<CreatureID, Creature>>::createFunctor(&CreatureService::getByIndex)}
};
const std::vector<CreatureServiceProxy::CustomRegType> CreatureServiceProxy::REGISTER_CUSTOM =
{
};
VCMI_REGISTER_CORE_SCRIPT_API(FactionServiceProxy, "Factions");
const std::vector<FactionServiceProxy::RegType> FactionServiceProxy::REGISTER =
{
{"getByIndex", LuaCallWrapper<const EntityServiceT<FactionID, Faction>>::createFunctor(&FactionService::getByIndex)}
};
const std::vector<FactionServiceProxy::CustomRegType> FactionServiceProxy::REGISTER_CUSTOM =
{
};
VCMI_REGISTER_CORE_SCRIPT_API(HeroClassServiceProxy, "HeroClasses");
const std::vector<HeroClassServiceProxy::RegType> HeroClassServiceProxy::REGISTER =
{
{"getByIndex", LuaCallWrapper<const EntityServiceT<HeroClassID, HeroClass>>::createFunctor(&HeroClassService::getByIndex)}
};
const std::vector<HeroClassServiceProxy::CustomRegType> HeroClassServiceProxy::REGISTER_CUSTOM =
{
};
VCMI_REGISTER_CORE_SCRIPT_API(HeroTypeServiceProxy, "HeroTypes");
const std::vector<HeroTypeServiceProxy::RegType> HeroTypeServiceProxy::REGISTER =
{
{"getByIndex", LuaCallWrapper<const EntityServiceT<HeroTypeID, HeroType>>::createFunctor(&HeroTypeService::getByIndex)}
};
const std::vector<HeroTypeServiceProxy::CustomRegType> HeroTypeServiceProxy::REGISTER_CUSTOM =
{
};
VCMI_REGISTER_CORE_SCRIPT_API(SkillServiceProxy, "Skills");
const std::vector<SkillServiceProxy::RegType> SkillServiceProxy::REGISTER =
{
{"getByIndex", LuaCallWrapper<const EntityServiceT<SecondarySkill, Skill>>::createFunctor(&SkillService::getByIndex)}
};
const std::vector<SkillServiceProxy::CustomRegType> SkillServiceProxy::REGISTER_CUSTOM =
{
};
VCMI_REGISTER_CORE_SCRIPT_API(SpellServiceProxy, "Spells");
const std::vector<SpellServiceProxy::RegType> SpellServiceProxy::REGISTER =
{
{"getByIndex", LuaCallWrapper<const EntityServiceT<SpellID, spells::Spell>>::createFunctor(&spells::Service::getByIndex)}
};
const std::vector<SpellServiceProxy::CustomRegType> SpellServiceProxy::REGISTER_CUSTOM =
{
};
}
}

View File

@ -0,0 +1,97 @@
/*
* api/Services.h, 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
*
*/
#pragma once
#include <vcmi/Services.h>
#include <vcmi/ArtifactService.h>
#include <vcmi/CreatureService.h>
#include <vcmi/FactionService.h>
#include <vcmi/HeroClassService.h>
#include <vcmi/HeroTypeService.h>
#include <vcmi/SkillService.h>
#include <vcmi/spells/Service.h>
#include "../LuaWrapper.h"
namespace scripting
{
namespace api
{
class ServicesProxy : public OpaqueWrapper<const Services, ServicesProxy>
{
public:
using Wrapper = OpaqueWrapper<const Services, ServicesProxy>;
static const std::vector<typename Wrapper::RegType> REGISTER;
static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
};
class ArtifactServiceProxy : public OpaqueWrapper<const ArtifactService, ArtifactServiceProxy>
{
public:
using Wrapper = OpaqueWrapper<const ArtifactService, ArtifactServiceProxy>;
static const std::vector<typename Wrapper::RegType> REGISTER;
static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
};
class CreatureServiceProxy : public OpaqueWrapper<const CreatureService, CreatureServiceProxy>
{
public:
using Wrapper = OpaqueWrapper<const CreatureService, CreatureServiceProxy>;
static const std::vector<typename Wrapper::RegType> REGISTER;
static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
};
class FactionServiceProxy : public OpaqueWrapper<const FactionService, FactionServiceProxy>
{
public:
using Wrapper = OpaqueWrapper<const FactionService, FactionServiceProxy>;
static const std::vector<typename Wrapper::RegType> REGISTER;
static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
};
class HeroClassServiceProxy : public OpaqueWrapper<const HeroClassService, HeroClassServiceProxy>
{
public:
using Wrapper = OpaqueWrapper<const HeroClassService, HeroClassServiceProxy>;
static const std::vector<typename Wrapper::RegType> REGISTER;
static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
};
class HeroTypeServiceProxy : public OpaqueWrapper<const HeroTypeService, HeroTypeServiceProxy>
{
public:
using Wrapper = OpaqueWrapper<const HeroTypeService, HeroTypeServiceProxy>;
static const std::vector<typename Wrapper::RegType> REGISTER;
static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
};
class SkillServiceProxy : public OpaqueWrapper<const SkillService, SkillServiceProxy>
{
public:
using Wrapper = OpaqueWrapper<const SkillService, SkillServiceProxy>;
static const std::vector<typename Wrapper::RegType> REGISTER;
static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
};
class SpellServiceProxy : public OpaqueWrapper<const spells::Service, SpellServiceProxy>
{
public:
using Wrapper = OpaqueWrapper<const spells::Service, SpellServiceProxy>;
static const std::vector<typename Wrapper::RegType> REGISTER;
static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
};
}
}

View File

@ -0,0 +1,36 @@
/*
* api/Skill.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 "Skill.h"
#include "Registry.h"
#include "../LuaStack.h"
#include "../LuaCallWrapper.h"
namespace scripting
{
namespace api
{
VCMI_REGISTER_CORE_SCRIPT_API(SkillProxy, "Skill");
const std::vector<SkillProxy::RegType> SkillProxy::REGISTER = {};
const std::vector<SkillProxy::CustomRegType> SkillProxy::REGISTER_CUSTOM =
{
{"getIconIndex", LuaMethodWrapper<Skill, int32_t(Entity:: *)()const, &Entity::getIconIndex>::invoke, false},
{"getIndex", LuaMethodWrapper<Skill, int32_t(Entity:: *)()const, &Entity::getIndex>::invoke, false},
{"getJsonKey", LuaMethodWrapper<Skill, const std::string &(Entity:: *)()const, &Entity::getJsonKey>::invoke, false},
{"getName", LuaMethodWrapper<Skill, const std::string &(Entity:: *)()const, &Entity::getName>::invoke, false},
};
}
}

32
scripting/lua/api/Skill.h Normal file
View File

@ -0,0 +1,32 @@
/*
* api/Skill.h, 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
*
*/
#pragma once
#include <vcmi/Skill.h>
#include "../LuaWrapper.h"
namespace scripting
{
namespace api
{
class SkillProxy : public OpaqueWrapper<const Skill, SkillProxy>
{
public:
using Wrapper = OpaqueWrapper<const Skill, SkillProxy>;
static const std::vector<typename Wrapper::RegType> REGISTER;
static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
};
}
}

View File

@ -0,0 +1,57 @@
/*
* api/Spell.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 "Spell.h"
#include "Registry.h"
#include "../LuaStack.h"
#include "../LuaCallWrapper.h"
namespace scripting
{
namespace api
{
using ::spells::Spell;
VCMI_REGISTER_CORE_SCRIPT_API(SpellProxy, "Spell");
//TODO:calculateDamage,forEachSchool
const std::vector<SpellProxy::RegType> SpellProxy::REGISTER =
{
{"getCost", LuaCallWrapper<const Spell>::createFunctor(&Spell::getCost)},
{"getBasePower", LuaCallWrapper<const Spell>::createFunctor(&Spell::getBasePower)},
{"getLevelPower", LuaCallWrapper<const Spell>::createFunctor(&Spell::getLevelPower)},
{"getLevelDescription", LuaCallWrapper<const Spell>::createFunctor(&Spell::getLevelDescription)},
};
const std::vector<SpellProxy::CustomRegType> SpellProxy::REGISTER_CUSTOM =
{
{"getIconIndex", LuaMethodWrapper<Spell, int32_t(Entity:: *)()const, &Entity::getIconIndex>::invoke, false},
{"getIndex", LuaMethodWrapper<Spell, int32_t(Entity:: *)()const, &Entity::getIndex>::invoke, false},
{"getJsonKey", LuaMethodWrapper<Spell, const std::string &(Entity:: *)()const, &Entity::getJsonKey>::invoke, false},
{"getName", LuaMethodWrapper<Spell, const std::string &(Entity:: *)()const, &Entity::getName>::invoke, false},
{"isAdventure", LuaMethodWrapper<Spell, bool(Spell:: *)()const, &Spell::isAdventure>::invoke, false},
{"isCombat", LuaMethodWrapper<Spell, bool(Spell:: *)()const, &Spell::isCombat>::invoke, false},
{"isCreatureAbility", LuaMethodWrapper<Spell, bool(Spell:: *)()const, &Spell::isCreatureAbility>::invoke, false},
{"isPositive", LuaMethodWrapper<Spell, bool(Spell:: *)()const, &Spell::isPositive>::invoke, false},
{"isNegative", LuaMethodWrapper<Spell, bool(Spell:: *)()const, &Spell::isNegative>::invoke, false},
{"isNeutral", LuaMethodWrapper<Spell, bool(Spell:: *)()const, &Spell::isNeutral>::invoke, false},
{"isDamage", LuaMethodWrapper<Spell, bool(Spell:: *)()const, &Spell::isDamage>::invoke, false},
{"isOffensive", LuaMethodWrapper<Spell, bool(Spell:: *)()const, &Spell::isOffensive>::invoke, false},
{"isSpecial", LuaMethodWrapper<Spell, bool(Spell:: *)()const, &Spell::isSpecial>::invoke, false},
};
}
}

31
scripting/lua/api/Spell.h Normal file
View File

@ -0,0 +1,31 @@
/*
* api/Spell.h, 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
*
*/
#pragma once
#include <vcmi/spells/Spell.h>
#include "../LuaWrapper.h"
namespace scripting
{
namespace api
{
class SpellProxy : public OpaqueWrapper<const ::spells::Spell, SpellProxy>
{
public:
using Wrapper = OpaqueWrapper<const ::spells::Spell, SpellProxy>;
static const std::vector<typename Wrapper::RegType> REGISTER;
static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
};
}
}

View File

@ -0,0 +1,40 @@
/*
* StackInstance.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 "StackInstance.h"
#include "Registry.h"
#include "../LuaStack.h"
#include "../LuaCallWrapper.h"
#include <vcmi/Creature.h>
namespace scripting
{
namespace api
{
VCMI_REGISTER_CORE_SCRIPT_API(StackInstanceProxy, "StackInstance");
const std::vector<StackInstanceProxy::RegType> StackInstanceProxy::REGISTER =
{
};
const std::vector<StackInstanceProxy::CustomRegType> StackInstanceProxy::REGISTER_CUSTOM =
{
{"getType", LuaMethodWrapper<CStackInstance, const Creature *(CStackBasicDescriptor:: *)()const, &CStackBasicDescriptor::getType>::invoke, false},
{"getCount", LuaMethodWrapper<CStackInstance, TQuantity(CStackBasicDescriptor:: *)()const, &CStackBasicDescriptor::getCount>::invoke, false},
};
}
}

View File

@ -0,0 +1,35 @@
/*
* StackInstance.h, 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
*
*/
#pragma once
#include <vcmi/HeroClass.h>
#include "../LuaWrapper.h"
#include "../../../lib/CCreatureSet.h"
namespace scripting
{
namespace api
{
class StackInstanceProxy : public OpaqueWrapper<const CStackInstance, StackInstanceProxy>
{
public:
using Wrapper = OpaqueWrapper<const CStackInstance, StackInstanceProxy>;
static const std::vector<typename Wrapper::RegType> REGISTER;
static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
};
}
}

View File

@ -0,0 +1,63 @@
/*
* UnitProxy.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 "UnitProxy.h"
#include "../../LuaStack.h"
#include "../../LuaCallWrapper.h"
#include "../Registry.h"
namespace scripting
{
namespace api
{
namespace battle
{
VCMI_REGISTER_SCRIPT_API(UnitProxy, "battle.Unit")
const std::vector<UnitProxy::RegType> UnitProxy::REGISTER =
{
{
"getMinDamage",
LuaCallWrapper<const IBonusBearer>::createFunctor(&IBonusBearer::getMinDamage)
},
{
"getMaxDamage",
LuaCallWrapper<const IBonusBearer>::createFunctor(&IBonusBearer::getMaxDamage)
},
{
"getAttack",
LuaCallWrapper<const IBonusBearer>::createFunctor(&IBonusBearer::getAttack)
},
{
"getDefense",
LuaCallWrapper<const IBonusBearer>::createFunctor(&IBonusBearer::getDefense)
},
{
"isAlive",
LuaCallWrapper<const Unit>::createFunctor(&Unit::alive)
},
{
"unitId",
LuaCallWrapper<const IUnitInfo>::createFunctor(&IUnitInfo::unitId)
}
};
const std::vector<UnitProxy::CustomRegType> UnitProxy::REGISTER_CUSTOM =
{
};
}
}
}

View File

@ -0,0 +1,38 @@
/*
* UnitProxy.h, 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
*
*/
#pragma once
#include <vcmi/scripting/Service.h>
#include "../../../../lib/battle/Unit.h"
#include "../../LuaWrapper.h"
namespace scripting
{
namespace api
{
namespace battle
{
using ::battle::IUnitInfo;
using ::battle::Unit;
class UnitProxy : public OpaqueWrapper<const Unit, UnitProxy>
{
public:
using Wrapper = OpaqueWrapper<const Unit, UnitProxy>;
static const std::vector<typename Wrapper::RegType> REGISTER;
static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
};
}
}
}

View File

@ -0,0 +1,47 @@
/*
* AdventureEvents.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 "AdventureEvents.h"
#include "../../LuaStack.h"
#include "../../LuaCallWrapper.h"
#include "../Registry.h"
#include "SubscriptionRegistryProxy.h"
namespace scripting
{
namespace api
{
namespace events
{
VCMI_REGISTER_SCRIPT_API(ObjectVisitStartedProxy, "events.ObjectVisitStarted");
const std::vector<ObjectVisitStartedProxy::RegType> ObjectVisitStartedProxy::REGISTER = {};
const std::vector<ObjectVisitStartedProxy::CustomRegType> ObjectVisitStartedProxy::REGISTER_CUSTOM =
{
{
"subscribeBefore",
&SubscriptionRegistryProxy<ObjectVisitStartedProxy>::subscribeBefore,
true
},
{
"subscribeAfter",
&SubscriptionRegistryProxy<ObjectVisitStartedProxy>::subscribeAfter,
true
},
};
}
}
}

View File

@ -0,0 +1,41 @@
/*
* AdventureEvents.h, 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
*
*/
#pragma once
#include <vcmi/events/AdventureEvents.h>
#include "../../LuaWrapper.h"
#include "EventBusProxy.h"
namespace scripting
{
namespace api
{
namespace events
{
using ::events::ObjectVisitStarted;
class ObjectVisitStartedProxy : public OpaqueWrapper<ObjectVisitStarted, ObjectVisitStartedProxy>
{
public:
using Wrapper = OpaqueWrapper<ObjectVisitStarted, ObjectVisitStartedProxy>;
static const std::vector<typename Wrapper::RegType> REGISTER;
static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
};
}
}
}

View File

@ -0,0 +1,67 @@
/*
* BattleEvents.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 "BattleEvents.h"
#include "../../LuaStack.h"
#include "../../LuaCallWrapper.h"
#include "../Registry.h"
#include "../../../../lib/battle/Unit.h"
#include "SubscriptionRegistryProxy.h"
namespace scripting
{
namespace api
{
namespace events
{
using ::events::ApplyDamage;
VCMI_REGISTER_SCRIPT_API(ApplyDamageProxy, "events.ApplyDamage");
const std::vector<ApplyDamageProxy::RegType> ApplyDamageProxy::REGISTER =
{
{
"getInitalDamage",
LuaCallWrapper<ApplyDamage>::createFunctor(&ApplyDamage::getInitalDamage)
},
{
"getDamage",
LuaCallWrapper<ApplyDamage>::createFunctor(&ApplyDamage::getDamage)
},
{
"setDamage",
LuaCallWrapper<ApplyDamage>::createFunctor(&ApplyDamage::setDamage)
},
{
"getTarget",
LuaCallWrapper<ApplyDamage>::createFunctor(&ApplyDamage::getTarget)
}
};
const std::vector<ApplyDamageProxy::CustomRegType> ApplyDamageProxy::REGISTER_CUSTOM =
{
{
"subscribeBefore",
&SubscriptionRegistryProxy<ApplyDamageProxy>::subscribeBefore,
true
},
{
"subscribeAfter",
&SubscriptionRegistryProxy<ApplyDamageProxy>::subscribeAfter,
true
}
};
}
}
}

View File

@ -0,0 +1,38 @@
/*
* BattleEvents.h, 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
*
*/
#pragma once
#include <vcmi/events/BattleEvents.h>
#include "../../LuaWrapper.h"
#include "EventBusProxy.h"
namespace scripting
{
namespace api
{
namespace events
{
class ApplyDamageProxy : public OpaqueWrapper<::events::ApplyDamage, ApplyDamageProxy>
{
public:
using Wrapper = OpaqueWrapper<::events::ApplyDamage, ApplyDamageProxy>;
static const std::vector<typename Wrapper::RegType> REGISTER;
static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
};
}
}
}

View File

@ -0,0 +1,33 @@
/*
* EventBusProxy.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 "EventBusProxy.h"
#include "../../LuaStack.h"
#include "../../LuaCallWrapper.h"
#include "../Registry.h"
namespace scripting
{
namespace api
{
namespace events
{
//No methods here, just an empty metatable for type safety.
VCMI_REGISTER_CORE_SCRIPT_API(EventBusProxy, "EventBus");
const std::vector<EventBusProxy::RegType> EventBusProxy::REGISTER = {};
const std::vector<EventBusProxy::CustomRegType> EventBusProxy::REGISTER_CUSTOM = {};
}
}
}

View File

@ -0,0 +1,34 @@
/*
* EventBusProxy.h, 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
*
*/
#pragma once
#include <vcmi/events/EventBus.h>
#include "../../LuaWrapper.h"
namespace scripting
{
namespace api
{
namespace events
{
class EventBusProxy : public OpaqueWrapper<::events::EventBus, EventBusProxy>
{
public:
using Wrapper = OpaqueWrapper<::events::EventBus, EventBusProxy>;
static const std::vector<typename Wrapper::RegType> REGISTER;
static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
};
}
}
}

View File

@ -0,0 +1,94 @@
/*
* GenericEvents.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 "GenericEvents.h"
#include "../../LuaStack.h"
#include "../../LuaCallWrapper.h"
#include "../Registry.h"
#include "SubscriptionRegistryProxy.h"
namespace scripting
{
namespace api
{
namespace events
{
using ::events::GameResumed;
using ::events::PlayerGotTurn;
using ::events::TurnStarted;
VCMI_REGISTER_SCRIPT_API(GameResumedProxy, "events.GameResumed");
VCMI_REGISTER_SCRIPT_API(PlayerGotTurnProxy, "events.PlayerGotTurn");
VCMI_REGISTER_SCRIPT_API(TurnStartedProxy, "events.TurnStarted");
const std::vector<GameResumedProxy::RegType> GameResumedProxy::REGISTER = {};
const std::vector<GameResumedProxy::CustomRegType> GameResumedProxy::REGISTER_CUSTOM =
{
{
"subscribeBefore",
&SubscriptionRegistryProxy<GameResumedProxy>::subscribeBefore,
true
},
{
"subscribeAfter",
&SubscriptionRegistryProxy<GameResumedProxy>::subscribeAfter,
true
}
};
const std::vector<PlayerGotTurnProxy::RegType> PlayerGotTurnProxy::REGISTER =
{
{
"getPlayer",
LuaCallWrapper<PlayerGotTurn>::createFunctor(&PlayerGotTurn::getPlayerIndex)
},
{
"setPlayer",
LuaCallWrapper<PlayerGotTurn>::createFunctor(&PlayerGotTurn::setPlayerIndex)
},
};
const std::vector<PlayerGotTurnProxy::CustomRegType> PlayerGotTurnProxy::REGISTER_CUSTOM =
{
{
"subscribeBefore",
&SubscriptionRegistryProxy<PlayerGotTurnProxy>::subscribeBefore,
true
},
{
"subscribeAfter",
&SubscriptionRegistryProxy<PlayerGotTurnProxy>::subscribeAfter,
true
}
};
const std::vector<TurnStartedProxy::RegType> TurnStartedProxy::REGISTER = {};
const std::vector<TurnStartedProxy::CustomRegType> TurnStartedProxy::REGISTER_CUSTOM =
{
{
"subscribeBefore",
&SubscriptionRegistryProxy<TurnStartedProxy>::subscribeBefore,
true
},
{
"subscribeAfter",
&SubscriptionRegistryProxy<TurnStartedProxy>::subscribeAfter,
true
}
};
}
}
}

View File

@ -0,0 +1,54 @@
/*
* GenericEvents.h, 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
*
*/
#pragma once
#include <vcmi/events/GenericEvents.h>
#include "../../LuaWrapper.h"
#include "EventBusProxy.h"
namespace scripting
{
namespace api
{
namespace events
{
class GameResumedProxy : public OpaqueWrapper<::events::GameResumed, GameResumedProxy>
{
public:
using Wrapper = OpaqueWrapper<::events::GameResumed, GameResumedProxy>;
static const std::vector<typename Wrapper::RegType> REGISTER;
static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
};
class PlayerGotTurnProxy : public OpaqueWrapper<::events::PlayerGotTurn, PlayerGotTurnProxy>
{
public:
using Wrapper = OpaqueWrapper<::events::PlayerGotTurn, PlayerGotTurnProxy>;
static const std::vector<typename Wrapper::RegType> REGISTER;
static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
};
class TurnStartedProxy : public OpaqueWrapper<::events::TurnStarted, TurnStartedProxy>
{
public:
using Wrapper = OpaqueWrapper<::events::TurnStarted, TurnStartedProxy>;
static const std::vector<typename Wrapper::RegType> REGISTER;
static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
};
}
}
}

View File

@ -0,0 +1,28 @@
/*
* SubscriptionRegistryProxy.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 "SubscriptionRegistryProxy.h"
#include "../Registry.h"
namespace scripting
{
namespace api
{
namespace events
{
//No methods here, just an empty metatable for type safety.
VCMI_REGISTER_CORE_SCRIPT_API(EventSubscriptionProxy, "EventSubscription");
const std::vector<EventSubscriptionProxy::RegType> EventSubscriptionProxy::REGISTER = {};
const std::vector<EventSubscriptionProxy::CustomRegType> EventSubscriptionProxy::REGISTER_CUSTOM = {};
}
}
}

View File

@ -0,0 +1,131 @@
/*
* SubscriptionRegistryProxy.h, 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
*
*/
#pragma once
#include <vcmi/events/Event.h>
#include <vcmi/events/EventBus.h>
#include <vcmi/events/SubscriptionRegistry.h>
#include "../../LuaWrapper.h"
#include "../../LuaStack.h"
#include "../../LuaReference.h"
namespace scripting
{
namespace api
{
namespace events
{
class EventSubscriptionProxy : public UniqueOpaqueWrapper<::events::EventSubscription, EventSubscriptionProxy>
{
public:
using Wrapper = UniqueOpaqueWrapper<::events::EventSubscription, EventSubscriptionProxy>;
static const std::vector<typename Wrapper::RegType> REGISTER;
static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
};
template <typename EventProxy>
class SubscriptionRegistryProxy
{
public:
using EventType = typename EventProxy::ObjectType;
using RegistryType = ::events::SubscriptionRegistry<EventType>;
static_assert(std::is_base_of<::events::Event, EventType>::value, "Invalid template parameter");
static int subscribeBefore(lua_State * L)
{
LuaStack S(L);
// subscription = subscribeBefore(eventBus, callback)
//TODO: use capture by move from c++14
auto callbackRef = std::make_shared<LuaReference>(L);
::events::EventBus * eventBus = nullptr;
if(!S.tryGet(1, eventBus))
{
S.push("No event bus");
return 1;
}
S.clear();
RegistryType * registry = EventType::getRegistry();
typename EventType::PreHandler callback = [=](EventType & event)
{
LuaStack S(L);
callbackRef->push();
S.push(&event);
if(lua_pcall(L, 1, 0, 0) != 0)
{
std::string msg;
S.tryGet(1, msg);
logMod->error("Script callback error: %s", msg);
}
S.clear();
};
std::unique_ptr<::events::EventSubscription> subscription = registry->subscribeBefore(eventBus, std::move(callback));
S.push(std::move(subscription));
return 1;
}
static int subscribeAfter(lua_State * L)
{
LuaStack S(L);
//TODO: use capture by move from c++14
auto callbackRef = std::make_shared<LuaReference>(L);
::events::EventBus * eventBus = nullptr;
if(!S.tryGet(1, eventBus))
{
S.push("No event bus");
return 1;
}
S.clear();
RegistryType * registry = EventType::getRegistry();
typename EventType::PostHandler callback = [=](const EventType & event)
{
LuaStack S(L);
callbackRef->push();
S.push(const_cast<EventType *>(&event)); //FIXME:
if(lua_pcall(L, 1, 0, 0) != 0)
{
std::string msg;
S.tryGet(1, msg);
logMod->error("Script callback error: %s", msg);
}
S.clear();
};
std::unique_ptr<::events::EventSubscription> subscription = registry->subscribeAfter(eventBus, std::move(callback));
S.push(std::move(subscription));
return 1;
}
};
}
}
}

View File

@ -0,0 +1,63 @@
/*
* api/netpacks/BattleLogMessage.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 "BattleLogMessage.h"
#include "../../LuaStack.h"
#include "../Registry.h"
namespace scripting
{
namespace api
{
namespace netpacks
{
VCMI_REGISTER_SCRIPT_API(BattleLogMessageProxy, "netpacks.BattleLogMessage");
const std::vector<BattleLogMessageProxy::RegType> BattleLogMessageProxy::REGISTER =
{
{
"addText",
&BattleLogMessageProxy::addText
},
{
"toNetpackLight",
&PackForClientProxy<BattleLogMessageProxy>::toNetpackLight
},
};
const std::vector<BattleLogMessageProxy::CustomRegType> BattleLogMessageProxy::REGISTER_CUSTOM =
{
{"new", &Wrapper::constructor, true}
};
int BattleLogMessageProxy::addText(lua_State * L, std::shared_ptr<BattleLogMessage> object)
{
LuaStack S(L);
std::string text;
if(S.tryGet(1, text))
{
if(object->lines.empty())
object->lines.emplace_back();
object->lines.back() << text;
}
return S.retVoid();
}
}
}
}

View File

@ -0,0 +1,35 @@
/*
* api/netpacks/BattleLogMessage.h, 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
*
*/
#pragma once
#include "PackForClient.h"
namespace scripting
{
namespace api
{
namespace netpacks
{
class BattleLogMessageProxy : public SharedWrapper<BattleLogMessage, BattleLogMessageProxy>
{
public:
using Wrapper = SharedWrapper<BattleLogMessage, BattleLogMessageProxy>;
static const std::vector<Wrapper::RegType> REGISTER;
static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
static int addText(lua_State * L, std::shared_ptr<BattleLogMessage> object);
};
}
}
}

View File

@ -0,0 +1,89 @@
/*
* api/netpacks/BattleStackMoved.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 "BattleStackMoved.h"
#include "../../LuaStack.h"
#include "../Registry.h"
namespace scripting
{
namespace api
{
namespace netpacks
{
VCMI_REGISTER_SCRIPT_API(BattleStackMovedProxy, "netpacks.BattleStackMoved");
const std::vector<BattleStackMovedProxy::RegType> BattleStackMovedProxy::REGISTER =
{
{
"addTileToMove",
&BattleStackMovedProxy::addTileToMove
},
{
"setUnitId",
&BattleStackMovedProxy::setUnitId
},
{
"setDistance",
&BattleStackMovedProxy::setDistance
},
{
"setTeleporting",
&BattleStackMovedProxy::setTeleporting
},
{
"toNetpackLight",
&PackForClientProxy<BattleStackMovedProxy>::toNetpackLight
}
};
const std::vector<BattleStackMovedProxy::CustomRegType> BattleStackMovedProxy::REGISTER_CUSTOM =
{
{"new", &Wrapper::constructor, true}
};
int BattleStackMovedProxy::addTileToMove(lua_State * L, std::shared_ptr<BattleStackMoved> object)
{
LuaStack S(L);
lua_Integer hex = 0;
if(!S.tryGetInteger(1, hex))
return S.retVoid();
object->tilesToMove.emplace_back(hex);
return S.retVoid();
}
int BattleStackMovedProxy::setUnitId(lua_State * L, std::shared_ptr<BattleStackMoved> object)
{
LuaStack S(L);
S.tryGet(1, object->stack);
return S.retVoid();
}
int BattleStackMovedProxy::setDistance(lua_State * L, std::shared_ptr<BattleStackMoved> object)
{
LuaStack S(L);
S.tryGet(1, object->distance);
return S.retVoid();
}
int BattleStackMovedProxy::setTeleporting(lua_State * L, std::shared_ptr<BattleStackMoved> object)
{
LuaStack S(L);
S.tryGet(1, object->teleporting);
return S.retVoid();
}
}
}
}

View File

@ -0,0 +1,39 @@
/*
* api/netpacks/BattleStackMoved.h, 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
*
*/
#pragma once
#include "PackForClient.h"
namespace scripting
{
namespace api
{
namespace netpacks
{
class BattleStackMovedProxy : public SharedWrapper<BattleStackMoved, BattleStackMovedProxy>
{
public:
using Wrapper = SharedWrapper<BattleStackMoved, BattleStackMovedProxy>;
static const std::vector<Wrapper::RegType> REGISTER;
static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
static int addTileToMove(lua_State * L, std::shared_ptr<BattleStackMoved> object);
static int setUnitId(lua_State * L, std::shared_ptr<BattleStackMoved> object);
static int setDistance(lua_State * L, std::shared_ptr<BattleStackMoved> object);
static int setTeleporting(lua_State * L, std::shared_ptr<BattleStackMoved> object);
};
}
}
}

View File

@ -0,0 +1,114 @@
/*
* api/netpacks/BattleUnitsChanged.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 "BattleUnitsChanged.h"
#include "../../LuaStack.h"
#include "../Registry.h"
namespace scripting
{
namespace api
{
namespace netpacks
{
VCMI_REGISTER_SCRIPT_API(BattleUnitsChangedProxy, "netpacks.BattleUnitsChanged");
const std::vector<BattleUnitsChangedProxy::RegType> BattleUnitsChangedProxy::REGISTER =
{
{
"toNetpackLight",
&PackForClientProxy<BattleUnitsChangedProxy>::toNetpackLight
},
{
"add",
&BattleUnitsChangedProxy::add
},
{
"update",
&BattleUnitsChangedProxy::update
},
{
"resetState",
&BattleUnitsChangedProxy::resetState
},
{
"remove",
&BattleUnitsChangedProxy::remove
}
};
const std::vector<BattleUnitsChangedProxy::CustomRegType> BattleUnitsChangedProxy::REGISTER_CUSTOM =
{
{"new", &Wrapper::constructor, true}
};
int BattleUnitsChangedProxy::add(lua_State * L, std::shared_ptr<BattleUnitsChanged> object)
{
LuaStack S(L);
uint32_t id;
if(!S.tryGet(1, id))
return S.retVoid();
UnitChanges changes(id, BattleChanges::EOperation::ADD);
if(!S.tryGet(2, changes.data))
return S.retVoid();
if(!S.tryGet(3, changes.healthDelta))
changes.healthDelta = 0;
object->changedStacks.push_back(changes);
return S.retVoid();
}
int BattleUnitsChangedProxy::update(lua_State * L, std::shared_ptr<BattleUnitsChanged> object)
{
LuaStack S(L);
uint32_t id;
if(!S.tryGet(1, id))
return S.retVoid();
UnitChanges changes(id, BattleChanges::EOperation::UPDATE);
if(!S.tryGet(2, changes.data))
return S.retVoid();
if(!S.tryGet(3, changes.healthDelta))
changes.healthDelta = 0;
object->changedStacks.push_back(changes);
return S.retVoid();
}
int BattleUnitsChangedProxy::resetState(lua_State * L, std::shared_ptr<BattleUnitsChanged> object)
{
LuaStack S(L);
return S.retVoid();
}
int BattleUnitsChangedProxy::remove(lua_State * L, std::shared_ptr<BattleUnitsChanged> object)
{
LuaStack S(L);
return S.retVoid();
}
}
}
}

View File

@ -0,0 +1,38 @@
/*
* api/netpacks/BattleUnitsChanged.h, 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
*
*/
#pragma once
#include "PackForClient.h"
namespace scripting
{
namespace api
{
namespace netpacks
{
class BattleUnitsChangedProxy : public SharedWrapper<BattleUnitsChanged, BattleUnitsChangedProxy>
{
public:
using Wrapper = SharedWrapper<BattleUnitsChanged, BattleUnitsChangedProxy>;
static const std::vector<Wrapper::RegType> REGISTER;
static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
static int add(lua_State * L, std::shared_ptr<BattleUnitsChanged> object);
static int update(lua_State * L, std::shared_ptr<BattleUnitsChanged> object);
static int resetState(lua_State * L, std::shared_ptr<BattleUnitsChanged> object);
static int remove(lua_State * L, std::shared_ptr<BattleUnitsChanged> object);
};
}
}
}

View File

@ -0,0 +1,69 @@
/*
* api/netpacks/EntitiesChanged.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 "EntitiesChanged.h"
#include "../../LuaStack.h"
#include "../Registry.h"
namespace scripting
{
namespace api
{
namespace netpacks
{
VCMI_REGISTER_SCRIPT_API(EntitiesChangedProxy, "netpacks.EntitiesChanged");
const std::vector<EntitiesChangedProxy::RegType> EntitiesChangedProxy::REGISTER =
{
{
"update",
&EntitiesChangedProxy::update
},
{
"toNetpackLight",
&PackForClientProxy<EntitiesChangedProxy>::toNetpackLight
},
};
const std::vector<EntitiesChangedProxy::CustomRegType> EntitiesChangedProxy::REGISTER_CUSTOM =
{
{"new", &Wrapper::constructor, true}
};
int EntitiesChangedProxy::update(lua_State * L, std::shared_ptr<EntitiesChanged> object)
{
LuaStack S(L);
EntityChanges changes;
int32_t metaIndex = 0;
if(!S.tryGet(1, metaIndex))
return S.retVoid();
changes.metatype = static_cast<Metatype>(metaIndex);
if(!S.tryGet(2, changes.entityIndex))
return S.retVoid();
if(!S.tryGet(3, changes.data))
return S.retVoid();
object->changes.push_back(changes);
return S.retVoid();
}
}
}
}

View File

@ -0,0 +1,36 @@
/*
* api/netpacks/EntitiesChanged.h 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
*
*/
#pragma once
#include "PackForClient.h"
namespace scripting
{
namespace api
{
namespace netpacks
{
class EntitiesChangedProxy : public SharedWrapper<EntitiesChanged, EntitiesChangedProxy>
{
public:
using Wrapper = SharedWrapper<EntitiesChanged, EntitiesChangedProxy>;
static const std::vector<typename Wrapper::RegType> REGISTER;
static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
static int update(lua_State * L, std::shared_ptr<EntitiesChanged> object);
};
}
}
}

View File

@ -0,0 +1,128 @@
/*
* api/netpacks/InfoWindow.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 "InfoWindow.h"
#include "../../LuaStack.h"
#include "../Registry.h"
using scripting::api::netpacks::InfoWindowProxy;
using scripting::api::RegisterAPI;
VCMI_REGISTER_SCRIPT_API(InfoWindowProxy, "netpacks.InfoWindow")
namespace scripting
{
namespace api
{
namespace netpacks
{
const std::vector<InfoWindowProxy::RegType> InfoWindowProxy::REGISTER =
{
{
"addReplacement",
&InfoWindowProxy::addReplacement
},
{
"addText",
&InfoWindowProxy::addText
},
{
"setPlayer",
&InfoWindowProxy::setPlayer
},
{
"toNetpackLight",
&PackForClientProxy<InfoWindowProxy>::toNetpackLight
},
};
const std::vector<InfoWindowProxy::CustomRegType> InfoWindowProxy::REGISTER_CUSTOM =
{
{"new", &Wrapper::constructor, true}
};
int InfoWindowProxy::addReplacement(lua_State * L, std::shared_ptr<InfoWindow> object)
{
int top = lua_gettop(L);
if(top == 1)
{
if(lua_isstring(L, 1))
{
size_t len = 0;
auto raw = lua_tolstring(L, 1, &len);
std::string text(raw, len);
object->text.addReplacement(text);
}
else if(lua_isnumber(L, 1))
{
object->text.addReplacement(lua_tointeger(L, 1));
}
}
else if(top >= 2)
{
if(lua_isnumber(L, 1) && lua_isnumber(L, 2))
object->text.addReplacement(lua_tointeger(L, 1), lua_tointeger(L, 2));
}
lua_settop(L, 0);
return 0;
}
int InfoWindowProxy::addText(lua_State * L, std::shared_ptr<InfoWindow> object)
{
int top = lua_gettop(L);
if(top == 1)
{
if(lua_isstring(L, 1))
{
size_t len = 0;
auto raw = lua_tolstring(L, 1, &len);
std::string text(raw, len);
object->text << text;
}
else if(lua_isnumber(L, 1))
{
object->text << (lua_tointeger(L, 1));
}
}
if(top >= 2)
{
if(lua_isnumber(L, 1) && lua_isnumber(L, 2))
object->text.addTxt(lua_tointeger(L, 1), lua_tointeger(L, 2));
}
lua_settop(L, 0);
return 0;
}
int InfoWindowProxy::setPlayer(lua_State * L, std::shared_ptr<InfoWindow> object)
{
LuaStack S(L);
PlayerColor value;
if(S.tryGet(1, value))
object->player = value;
return S.retVoid();
}
}
}
}

View File

@ -0,0 +1,36 @@
/*
* api/netpacks/InfoWindow.h, 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
*
*/
#pragma once
#include "PackForClient.h"
namespace scripting
{
namespace api
{
namespace netpacks
{
class InfoWindowProxy : public SharedWrapper<InfoWindow, InfoWindowProxy>
{
public:
using Wrapper = SharedWrapper<InfoWindow, InfoWindowProxy>;
static const std::vector<typename Wrapper::RegType> REGISTER;
static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
static int addReplacement(lua_State * L, std::shared_ptr<InfoWindow> object);
static int addText(lua_State * L, std::shared_ptr<InfoWindow> object);
static int setPlayer(lua_State * L, std::shared_ptr<InfoWindow> object);
};
}
}
}

View File

@ -0,0 +1,39 @@
/*
* api/netpacks/PackForClient.h, 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
*
*/
#pragma once
#include "../../LuaWrapper.h"
#include "../../../../lib/NetPacks.h"
namespace scripting
{
namespace api
{
namespace netpacks
{
template <typename Derived>
class PackForClientProxy
{
public:
static int toNetpackLight(lua_State * L, typename Derived::UDataType object)
{
lua_settop(L, 0);
lua_pushlightuserdata(L, static_cast<CPackForClient *>(object.get()));
return 1;
}
};
}
}
}

View File

@ -0,0 +1,133 @@
/*
* api/netpacks/SetResources.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 "SetResources.h"
#include "../../LuaStack.h"
#include "../Registry.h"
namespace scripting
{
namespace api
{
namespace netpacks
{
VCMI_REGISTER_SCRIPT_API(SetResourcesProxy, "netpacks.SetResources");
const std::vector<SetResourcesProxy::RegType> SetResourcesProxy::REGISTER =
{
{"getAbs",&SetResourcesProxy::getAbs},
{"setAbs",&SetResourcesProxy::setAbs},
{"getPlayer",&SetResourcesProxy::getPlayer},
{"setPlayer",&SetResourcesProxy::setPlayer},
{"setAmount",&SetResourcesProxy::setAmount},
{"getAmount",&SetResourcesProxy::getAmount},
{"clear",&SetResourcesProxy::clear},
{
"toNetpackLight",
&PackForClientProxy<SetResourcesProxy>::toNetpackLight
},
};
const std::vector<SetResourcesProxy::CustomRegType> SetResourcesProxy::REGISTER_CUSTOM =
{
{"new", &Wrapper::constructor, true}
};
int SetResourcesProxy::getAbs(lua_State * L, std::shared_ptr<SetResources> object)
{
return LuaStack::quickRetBool(L, object->abs);
}
int SetResourcesProxy::setAbs(lua_State * L, std::shared_ptr<SetResources> object)
{
LuaStack S(L);
bool value = false;
if(S.tryGet(1, value))
object->abs = value;
return S.retVoid();
}
int SetResourcesProxy::getPlayer(lua_State * L, std::shared_ptr<SetResources> object)
{
LuaStack S(L);
S.clear();
S.push(object->player);
return 1;
}
int SetResourcesProxy::setPlayer(lua_State * L, std::shared_ptr<SetResources> object)
{
LuaStack S(L);
PlayerColor value;
if(S.tryGet(1, value))
object->player = value;
return S.retVoid();
}
int SetResourcesProxy::getAmount(lua_State * L, std::shared_ptr<SetResources> object)
{
LuaStack S(L);
Res::ERes type = Res::ERes::INVALID;
if(!S.tryGet(1, type))
return S.retVoid();
S.clear();
const TQuantity amount = vstd::atOrDefault(object->res, static_cast<size_t>(type), 0);
S.push(amount);
return 1;
}
int SetResourcesProxy::setAmount(lua_State * L, std::shared_ptr<SetResources> object)
{
LuaStack S(L);
Res::ERes type = Res::ERes::INVALID;
if(!S.tryGet(1, type))
return S.retVoid();
int typeIdx = static_cast<int>(type);
if(typeIdx < 0 || typeIdx >= object->res.size())
return S.retVoid();
TQuantity amount = 0;
if(!S.tryGet(2, amount))
return S.retVoid();
object->res.at(typeIdx) = amount;
return S.retVoid();
}
int SetResourcesProxy::clear(lua_State * L, std::shared_ptr<SetResources> object)
{
LuaStack S(L);
object->res.amin(0);
object->res.positive();
return S.retVoid();
}
}
}
}

View File

@ -0,0 +1,41 @@
/*
* api/netpacks/SetResources.h, 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
*
*/
#pragma once
#include "PackForClient.h"
namespace scripting
{
namespace api
{
namespace netpacks
{
class SetResourcesProxy : public SharedWrapper<SetResources, SetResourcesProxy>
{
public:
using Wrapper = SharedWrapper<SetResources, SetResourcesProxy>;
static const std::vector<Wrapper::RegType> REGISTER;
static const std::vector<typename Wrapper::CustomRegType> REGISTER_CUSTOM;
static int getAbs(lua_State * L, std::shared_ptr<SetResources> object);
static int setAbs(lua_State * L, std::shared_ptr<SetResources> object);
static int getPlayer(lua_State * L, std::shared_ptr<SetResources> object);
static int setPlayer(lua_State * L, std::shared_ptr<SetResources> object);
static int getAmount(lua_State * L, std::shared_ptr<SetResources> object);
static int setAmount(lua_State * L, std::shared_ptr<SetResources> object);
static int clear(lua_State * L, std::shared_ptr<SetResources> object);
};
}
}
}