1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-12-22 00:27:58 +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

@@ -35,7 +35,7 @@ PlayerColor CGameInfoCallback::getOwner(ObjectInstanceID heroID) const
int CGameInfoCallback::getResource(PlayerColor Player, Res::ERes which) const
{
const PlayerState *p = getPlayer(Player);
const PlayerState *p = getPlayerState(Player);
ERROR_RET_VAL_IF(!p, "No player info!", -1);
ERROR_RET_VAL_IF(p->resources.size() <= which || which < 0, "No such resource!", -1);
return p->resources[which];
@@ -46,7 +46,7 @@ const PlayerSettings * CGameInfoCallback::getPlayerSettings(PlayerColor color) c
return &gs->scenarioOps->getIthPlayersSettings(color);
}
bool CGameInfoCallback::isAllowed( int type, int id )
bool CGameInfoCallback::isAllowed(int32_t type, int32_t id) const
{
switch(type)
{
@@ -61,7 +61,12 @@ bool CGameInfoCallback::isAllowed( int type, int id )
}
}
const PlayerState * CGameInfoCallback::getPlayer(PlayerColor color, bool verbose) const
const Player * CGameInfoCallback::getPlayer(PlayerColor color) const
{
return getPlayerState(color, false);
}
const PlayerState * CGameInfoCallback::getPlayerState(PlayerColor color, bool verbose) const
{
//funtion written from scratch since it's accessed A LOT by AI
@@ -93,7 +98,7 @@ const CTown * CGameInfoCallback::getNativeTown(PlayerColor color) const
{
const PlayerSettings *ps = getPlayerSettings(color);
ERROR_RET_VAL_IF(!ps, "There is no such player!", nullptr);
return VLC->townh->factions[ps->castle]->town;
return (*VLC->townh)[ps->castle]->town;
}
const CGObjectInstance * CGameInfoCallback::getObjByQuestIdentifier(int identifier) const
@@ -177,7 +182,7 @@ const StartInfo * CGameInfoCallback::getStartInfo(bool beforeRandomization) cons
return gs->scenarioOps;
}
int CGameInfoCallback::getSpellCost(const CSpell * sp, const CGHeroInstance * caster) const
int32_t CGameInfoCallback::getSpellCost(const spells::Spell * sp, const CGHeroInstance * caster) const
{
//boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
ERROR_RET_VAL_IF(!canGetFullInfo(caster), "Cannot get info about caster!", -1);
@@ -348,7 +353,7 @@ bool CGameInfoCallback::getHeroInfo(const CGObjectInstance * hero, InfoAboutHero
int maxAIValue = 0;
const CCreature * mostStrong = nullptr;
for(auto creature : VLC->creh->creatures)
for(auto creature : VLC->creh->objects)
{
if((si16)creature->faction == factionIndex && (int)creature->AIValue > maxAIValue)
{
@@ -551,7 +556,7 @@ EBuildingState::EBuildingState CGameInfoCallback::canBuildStructure( const CGTow
if(ID == BuildingID::CAPITOL)
{
const PlayerState *ps = getPlayer(t->tempOwner, false);
const PlayerState *ps = getPlayerState(t->tempOwner, false);
if(ps)
{
for(const CGTownInstance *town : ps->towns)
@@ -583,7 +588,7 @@ EBuildingState::EBuildingState CGameInfoCallback::canBuildStructure( const CGTow
return EBuildingState::CANT_BUILD_TODAY; //building limit
//checking resources
if(!building->resources.canBeAfforded(getPlayer(t->tempOwner)->resources))
if(!building->resources.canBeAfforded(getPlayerState(t->tempOwner)->resources))
return EBuildingState::NO_RESOURCES; //lack of res
return EBuildingState::ALLOWED;
@@ -601,7 +606,7 @@ bool CGameInfoCallback::hasAccess(boost::optional<PlayerColor> playerId) const
EPlayerStatus::EStatus CGameInfoCallback::getPlayerStatus(PlayerColor player, bool verbose) const
{
const PlayerState *ps = gs->getPlayer(player, verbose);
const PlayerState *ps = gs->getPlayerState(player, verbose);
ERROR_VERBOSE_OR_NOT_RET_VAL_IF(!ps, verbose, "No such player!", EPlayerStatus::WRONG);
return ps->status;
@@ -650,7 +655,7 @@ bool CGameInfoCallback::canGetFullInfo(const CGObjectInstance *obj) const
int CGameInfoCallback::getHeroCount( PlayerColor player, bool includeGarrisoned ) const
{
int ret = 0;
const PlayerState *p = gs->getPlayer(player);
const PlayerState *p = gs->getPlayerState(player);
ERROR_RET_VAL_IF(!p, "No such player!", -1);
if(includeGarrisoned)
@@ -789,7 +794,7 @@ std::vector < const CGDwelling * > CPlayerSpecificInfoCallback::getMyDwellings()
{
ASSERT_IF_CALLED_WITH_PLAYER
std::vector < const CGDwelling * > ret;
for(CGDwelling * dw : gs->getPlayer(*player)->dwellings)
for(CGDwelling * dw : gs->getPlayerState(*player)->dwellings)
{
ret.push_back(dw);
}
@@ -799,7 +804,7 @@ std::vector < const CGDwelling * > CPlayerSpecificInfoCallback::getMyDwellings()
std::vector <QuestInfo> CPlayerSpecificInfoCallback::getMyQuests() const
{
std::vector <QuestInfo> ret;
for (auto quest : gs->getPlayer(*player)->quests)
for (auto quest : gs->getPlayerState(*player)->quests)
{
ret.push_back (quest);
}
@@ -816,7 +821,7 @@ int CPlayerSpecificInfoCallback::howManyHeroes(bool includeGarrisoned) const
const CGHeroInstance* CPlayerSpecificInfoCallback::getHeroBySerial(int serialId, bool includeGarrisoned) const
{
ASSERT_IF_CALLED_WITH_PLAYER
const PlayerState *p = getPlayer(*player);
const PlayerState *p = getPlayerState(*player);
ERROR_RET_VAL_IF(!p, "No player info", nullptr);
if (!includeGarrisoned)
@@ -832,7 +837,7 @@ const CGHeroInstance* CPlayerSpecificInfoCallback::getHeroBySerial(int serialId,
const CGTownInstance* CPlayerSpecificInfoCallback::getTownBySerial(int serialId) const
{
ASSERT_IF_CALLED_WITH_PLAYER
const PlayerState *p = getPlayer(*player);
const PlayerState *p = getPlayerState(*player);
ERROR_RET_VAL_IF(!p, "No player info", nullptr);
ERROR_RET_VAL_IF(serialId < 0 || serialId >= p->towns.size(), "No player info", nullptr);
return p->towns[serialId];
@@ -893,13 +898,14 @@ const TeamState * CGameInfoCallback::getPlayerTeam( PlayerColor color ) const
}
}
const CGHeroInstance* CGameInfoCallback::getHeroWithSubid( int subid ) const
const CGHeroInstance * CGameInfoCallback::getHeroWithSubid( int subid ) const
{
for(const CGHeroInstance *h : gs->map->heroesOnMap)
if(h->subID == subid)
return h;
if(subid<0)
return nullptr;
if(subid>= gs->map->allHeroes.size())
return nullptr;
return nullptr;
return gs->map->allHeroes.at(subid).get();
}
PlayerColor CGameInfoCallback::getLocalPlayer() const
@@ -990,25 +996,3 @@ bool CGameInfoCallback::isTeleportEntrancePassable(const CGTeleport * obj, Playe
{
return obj && obj->isEntrance() && !isTeleportChannelImpassable(obj->channel, player);
}
void IGameEventRealizer::showInfoDialog( InfoWindow *iw )
{
commitPackage(iw);
}
void IGameEventRealizer::showInfoDialog(const std::string &msg, PlayerColor player)
{
InfoWindow iw;
iw.player = player;
iw.text << msg;
showInfoDialog(&iw);
}
void IGameEventRealizer::setObjProperty(ObjectInstanceID objid, int prop, si64 val)
{
SetObjectProperty sob;
sob.id = objid;
sob.what = prop;
sob.val = static_cast<ui32>(val);
commitPackage(&sob);
}