mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-06 09:09:40 +02:00
Moved town portal logic to mechanics class
This commit is contained in:
@@ -71,7 +71,8 @@ public:
|
||||
void complain(const std::string & problem) const override;
|
||||
const CMap * getMap() const override;
|
||||
const CGameInfoCallback * getCb() const override;
|
||||
bool moveHero(ObjectInstanceID hid, int3 dst, ui8 teleporting, PlayerColor asker = PlayerColor::NEUTRAL) const override;
|
||||
bool moveHero(ObjectInstanceID hid, int3 dst, bool teleporting) const override;
|
||||
void genericQuery(Query * request, PlayerColor color, std::function<void(const JsonNode &)> callback) const override;
|
||||
private:
|
||||
mutable CGameHandler * gh;
|
||||
};
|
||||
@@ -6516,13 +6517,20 @@ const CGameInfoCallback * ServerSpellCastEnvironment::getCb() const
|
||||
return gh;
|
||||
}
|
||||
|
||||
|
||||
const CMap * ServerSpellCastEnvironment::getMap() const
|
||||
{
|
||||
return gh->gameState()->map;
|
||||
}
|
||||
|
||||
bool ServerSpellCastEnvironment::moveHero(ObjectInstanceID hid, int3 dst, ui8 teleporting, PlayerColor asker) const
|
||||
bool ServerSpellCastEnvironment::moveHero(ObjectInstanceID hid, int3 dst, bool teleporting) const
|
||||
{
|
||||
return gh->moveHero(hid, dst, teleporting, false, asker);
|
||||
return gh->moveHero(hid, dst, teleporting, false);
|
||||
}
|
||||
|
||||
void ServerSpellCastEnvironment::genericQuery(Query * request, PlayerColor color, std::function<void(const JsonNode&)> callback) const
|
||||
{
|
||||
auto query = std::make_shared<CGenericQuery>(&gh->queries, color, callback);
|
||||
request->queryID = query->queryID;
|
||||
gh->queries.addQuery(query);
|
||||
gh->sendAndApply(request);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
#include "CGameHandler.h"
|
||||
#include "../lib/battle/BattleInfo.h"
|
||||
#include "../lib/mapObjects/MiscObjects.h"
|
||||
#include "../lib/spells/ISpellMechanics.h"
|
||||
|
||||
boost::mutex Queries::mx;
|
||||
|
||||
@@ -86,6 +85,7 @@ void CQuery::notifyObjectAboutRemoval(const CObjectVisitQuery &objectVisit) cons
|
||||
|
||||
void CQuery::onExposure(QueryPtr topQuery)
|
||||
{
|
||||
logGlobal->trace("Exposed query with id %d", queryID);
|
||||
owner->popQuery(*this);
|
||||
}
|
||||
|
||||
@@ -472,66 +472,29 @@ void CHeroMovementQuery::onAdding(PlayerColor color)
|
||||
gh->sendAndApply(&pb);
|
||||
}
|
||||
|
||||
CMapObjectSelectQuery::CMapObjectSelectQuery(Queries * Owner):
|
||||
CQuery(Owner)
|
||||
CGenericQuery::CGenericQuery(Queries * Owner, PlayerColor color, std::function<void(const JsonNode &)> Callback):
|
||||
CQuery(Owner), callback(Callback)
|
||||
{
|
||||
|
||||
addPlayer(color);
|
||||
}
|
||||
|
||||
bool CMapObjectSelectQuery::blocksPack(const CPack * pack) const
|
||||
bool CGenericQuery::blocksPack(const CPack * pack) const
|
||||
{
|
||||
return blockAllButReply(pack);
|
||||
}
|
||||
|
||||
bool CMapObjectSelectQuery::endsByPlayerAnswer() const
|
||||
bool CGenericQuery::endsByPlayerAnswer() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void CMapObjectSelectQuery::setReply(const JsonNode & reply)
|
||||
void CGenericQuery::onExposure(QueryPtr topQuery)
|
||||
{
|
||||
//TODO:
|
||||
//do nothing
|
||||
}
|
||||
|
||||
CSpellQuery::CSpellQuery(Queries * Owner, const SpellCastEnvironment * SpellEnv):
|
||||
CQuery(Owner), spellEnv(SpellEnv)
|
||||
void CGenericQuery::setReply(const JsonNode & reply)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
AdventureSpellCastQuery::AdventureSpellCastQuery(Queries * Owner, const SpellCastEnvironment * SpellEnv, const CSpell * Spell, const CGHeroInstance * Caster, const int3 & Position):
|
||||
CSpellQuery(Owner, SpellEnv), spell(Spell), caster(Caster), position(Position), requiresPositions(false)
|
||||
{
|
||||
assert(owner);
|
||||
assert(spellEnv);
|
||||
assert(spell);
|
||||
assert(caster);
|
||||
|
||||
addPlayer(caster->getOwner());
|
||||
}
|
||||
|
||||
bool AdventureSpellCastQuery::blocksPack(const CPack * pack) const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void AdventureSpellCastQuery::onAdded(PlayerColor color)
|
||||
{
|
||||
//TODO: destination select request
|
||||
|
||||
}
|
||||
|
||||
void AdventureSpellCastQuery::onExposure(QueryPtr topQuery)
|
||||
{
|
||||
CQuery::onExposure(topQuery);
|
||||
}
|
||||
|
||||
void AdventureSpellCastQuery::onRemoval(PlayerColor color)
|
||||
{
|
||||
AdventureSpellCastParameters p;
|
||||
p.caster = caster;
|
||||
p.pos = position;
|
||||
|
||||
spell->adventureCast(spellEnv, p);
|
||||
callback(reply);
|
||||
}
|
||||
|
||||
|
||||
@@ -175,39 +175,17 @@ public:
|
||||
CommanderLevelUp clu;
|
||||
};
|
||||
|
||||
class CMapObjectSelectQuery : public CQuery
|
||||
class CGenericQuery : public CQuery
|
||||
{
|
||||
public:
|
||||
CMapObjectSelectQuery(Queries * Owner);
|
||||
CGenericQuery(Queries * Owner, PlayerColor color, std::function<void(const JsonNode &)> Callback);
|
||||
|
||||
bool blocksPack(const CPack * pack) const override;
|
||||
bool endsByPlayerAnswer() const override;
|
||||
void setReply(const JsonNode & reply) override;
|
||||
};
|
||||
|
||||
class CSpellQuery : public CQuery
|
||||
{
|
||||
public:
|
||||
CSpellQuery(Queries * Owner, const SpellCastEnvironment * SpellEnv);
|
||||
protected:
|
||||
const SpellCastEnvironment * spellEnv;
|
||||
};
|
||||
|
||||
class AdventureSpellCastQuery : public CSpellQuery
|
||||
{
|
||||
public:
|
||||
AdventureSpellCastQuery(Queries * Owner, const SpellCastEnvironment * SpellEnv, const CSpell * Spell, const CGHeroInstance * Caster, const int3 & Position);
|
||||
|
||||
bool blocksPack(const CPack * pack) const override;
|
||||
|
||||
void onAdded(PlayerColor color) override;
|
||||
void onExposure(QueryPtr topQuery) override;
|
||||
void onRemoval(PlayerColor color) override;
|
||||
|
||||
const CSpell * spell;
|
||||
const CGHeroInstance * caster;
|
||||
int3 position;
|
||||
bool requiresPositions;
|
||||
void setReply(const JsonNode & reply) override;
|
||||
private:
|
||||
std::function<void(const JsonNode &)> callback;
|
||||
};
|
||||
|
||||
class Queries
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#include "../lib/battle/BattleInfo.h"
|
||||
#include "../lib/battle/BattleAction.h"
|
||||
#include "../lib/serializer/Connection.h"
|
||||
#include "../lib/spells/CSpellHandler.h"
|
||||
#include "../lib/spells/ISpellMechanics.h"
|
||||
|
||||
|
||||
#define PLAYER_OWNS(id) (gh->getPlayerAt(c)==gh->getOwner(id))
|
||||
@@ -286,11 +288,11 @@ bool CastAdvSpell::applyGh(CGameHandler * gh)
|
||||
if(!h)
|
||||
ERROR_AND_RETURN;
|
||||
|
||||
auto query = std::make_shared<AdventureSpellCastQuery>(&gh->queries, gh->spellEnv, s, h, pos);
|
||||
AdventureSpellCastParameters p;
|
||||
p.caster = h;
|
||||
p.pos = pos;
|
||||
|
||||
gh->queries.addQuery(query);
|
||||
gh->queries.popIfTop(query);//if we already can perform cast do it now
|
||||
return true;
|
||||
return s->adventureCast(gh->spellEnv, p);
|
||||
}
|
||||
|
||||
bool PlayerMessage::applyGh( CGameHandler *gh )
|
||||
|
||||
Reference in New Issue
Block a user