1
0
mirror of https://github.com/vcmi/vcmi.git synced 2026-05-16 09:28:24 +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
+27
View File
@@ -0,0 +1,27 @@
/*
* 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 "Entity.h"
class ArtifactID;
class CreatureID;
class DLL_LINKAGE Artifact : public EntityWithBonuses<ArtifactID>
{
public:
virtual bool isBig() const = 0;
virtual bool isTradable() const = 0;
virtual const std::string & getDescription() const = 0;
virtual const std::string & getEventText() const = 0;
virtual uint32_t getPrice() const = 0;
virtual CreatureID getWarMachine() const = 0;
};
+21
View File
@@ -0,0 +1,21 @@
/*
* ArtifactService.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 "EntityService.h"
class ArtifactID;
class Artifact;
class DLL_LINKAGE ArtifactService : public EntityServiceT<ArtifactID, Artifact>
{
public:
};
+45
View File
@@ -0,0 +1,45 @@
/*
* 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 "Entity.h"
class CreatureID;
class DLL_LINKAGE Creature : public EntityWithBonuses<CreatureID>
{
public:
virtual const std::string & getPluralName() const = 0;
virtual const std::string & getSingularName() const = 0;
virtual uint32_t getMaxHealth() const = 0;
virtual int32_t getAdvMapAmountMin() const = 0;
virtual int32_t getAdvMapAmountMax() const = 0;
virtual int32_t getAIValue() const = 0;
virtual int32_t getFightValue() const = 0;
virtual int32_t getLevel() const = 0;
virtual int32_t getGrowth() const = 0;
virtual int32_t getHorde() const = 0;
virtual int32_t getFactionIndex() const = 0;
virtual int32_t getBaseAttack() const = 0;
virtual int32_t getBaseDefense() const = 0;
virtual int32_t getBaseDamageMin() const = 0;
virtual int32_t getBaseDamageMax() const = 0;
virtual int32_t getBaseHitPoints() const = 0;
virtual int32_t getBaseSpellPoints() const = 0;
virtual int32_t getBaseSpeed() const = 0;
virtual int32_t getBaseShots() const = 0;
virtual int32_t getCost(int32_t resIndex) const = 0;
virtual bool isDoubleWide() const = 0;
};
+21
View File
@@ -0,0 +1,21 @@
/*
* CreatureService.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 "EntityService.h"
class CreatureID;
class Creature;
class DLL_LINKAGE CreatureService : public EntityServiceT<CreatureID, Creature>
{
public:
};
+42
View File
@@ -0,0 +1,42 @@
/*
* Entity.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
class IBonusBearer;
class DLL_LINKAGE Entity
{
public:
using IconRegistar = std::function<void(int32_t index, const std::string & listName, const std::string & imageName)>;
virtual ~Entity() = default;
virtual int32_t getIndex() const = 0;
virtual int32_t getIconIndex() const = 0;
virtual const std::string & getJsonKey() const = 0;
virtual const std::string & getName() const = 0;
virtual void registerIcons(const IconRegistar & cb) const = 0;
};
template <typename IdType>
class DLL_LINKAGE EntityT : public Entity
{
public:
virtual IdType getId() const = 0;
};
template <typename IdType>
class DLL_LINKAGE EntityWithBonuses : public EntityT<IdType>
{
public:
virtual const IBonusBearer * accessBonuses() const = 0;
};
+32
View File
@@ -0,0 +1,32 @@
/*
* EntityService.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
class Entity;
class DLL_LINKAGE EntityService
{
public:
virtual ~EntityService() = default;
virtual const Entity * getBaseByIndex(const int32_t index) const = 0;
virtual void forEachBase(const std::function<void(const Entity * entity, bool & stop)> & cb) const = 0;
};
template <typename IdType, typename EntityType>
class DLL_LINKAGE EntityServiceT : public EntityService
{
public:
virtual const EntityType * getById(const IdType & id) const = 0;
virtual const EntityType * getByIndex(const int32_t index) const = 0;
virtual void forEach(const std::function<void(const EntityType * entity, bool & stop)> & cb) const = 0;
};
+36
View File
@@ -0,0 +1,36 @@
/*
* Environment.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
class Services;
class IGameInfoCallback;
class IBattleInfoCallback;
namespace events
{
class EventBus;
}
class DLL_LINKAGE Environment
{
public:
using BattleCb = ::IBattleInfoCallback;
using GameCb = ::IGameInfoCallback;
virtual ~Environment() = default;
virtual const Services * services() const = 0;
virtual const BattleCb * battle() const = 0;
virtual const GameCb * game() const = 0;
virtual vstd::CLoggerBase * logger() const = 0;
virtual events::EventBus * eventBus() const = 0;
};
+21
View File
@@ -0,0 +1,21 @@
/*
* 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 "Entity.h"
class FactionID;
class DLL_LINKAGE Faction : public EntityT<FactionID>
{
public:
virtual bool hasTown() const = 0;
};
+21
View File
@@ -0,0 +1,21 @@
/*
* FactionService.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 "EntityService.h"
class FactionID;
class Faction;
class DLL_LINKAGE FactionService : public EntityServiceT<FactionID, Faction>
{
public:
};
+22
View File
@@ -0,0 +1,22 @@
/*
* 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 "Entity.h"
class HeroClassID;
class DLL_LINKAGE HeroClass : public EntityT<HeroClassID>
{
public:
};
+21
View File
@@ -0,0 +1,21 @@
/*
* HeroClassService.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 "EntityService.h"
class HeroClassID;
class HeroClass;
class DLL_LINKAGE HeroClassService : public EntityServiceT<HeroClassID, HeroClass>
{
public:
};
+22
View File
@@ -0,0 +1,22 @@
/*
* 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 "Entity.h"
class HeroTypeID;
class DLL_LINKAGE HeroType : public EntityT<HeroTypeID>
{
public:
};
+21
View File
@@ -0,0 +1,21 @@
/*
* HeroTypeService.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 "EntityService.h"
class HeroTypeID;
class HeroType;
class DLL_LINKAGE HeroTypeService : public EntityServiceT<HeroTypeID, HeroType>
{
public:
};
+30
View File
@@ -0,0 +1,30 @@
/*
* Metatype.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
enum class Metatype : uint32_t
{
UNKNOWN = 0,
ARTIFACT,
ARTIFACT_INSTANCE,
CREATURE,
CREATURE_INSTANCE,
FACTION,
HERO_CLASS,
HERO_TYPE,
HERO_INSTANCE,
MAP_OBJECT_GROUP,
MAP_OBJECT_TYPE,
MAP_OBJECT_INSTANCE,
SKILL,
SPELL
};
+30
View File
@@ -0,0 +1,30 @@
/*
* 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
class PlayerColor;
class TeamID;
class IBonusBearer;
class DLL_LINKAGE Player
{
public:
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;
};
+44
View File
@@ -0,0 +1,44 @@
/*
* ServerCallback.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
namespace vstd
{
class RNG;
}
struct CPackForClient;
struct BattleLogMessage;
struct BattleStackMoved;
struct BattleUnitsChanged;
struct SetStackEffect;
struct StacksInjured;
struct BattleObstaclesChanged;
struct CatapultAttack;
class DLL_LINKAGE ServerCallback
{
public:
virtual void complain(const std::string & problem) = 0;
virtual bool describeChanges() const = 0;
virtual vstd::RNG * getRNG() = 0;
virtual void apply(CPackForClient * pack) = 0;
virtual void apply(BattleLogMessage * pack) = 0;
virtual void apply(BattleStackMoved * pack) = 0;
virtual void apply(BattleUnitsChanged * pack) = 0;
virtual void apply(SetStackEffect * pack) = 0;
virtual void apply(StacksInjured * pack) = 0;
virtual void apply(BattleObstaclesChanged * pack) = 0;
virtual void apply(CatapultAttack * pack) = 0;
};
+57
View File
@@ -0,0 +1,57 @@
/*
* 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 "Metatype.h"
class ArtifactService;
class CreatureService;
class FactionService;
class HeroClassService;
class HeroTypeService;
class SkillService;
class JsonNode;
namespace spells
{
class Service;
namespace effects
{
class Registry;
}
}
namespace scripting
{
class Service;
}
class DLL_LINKAGE Services
{
public:
virtual ~Services() = default;
virtual const ArtifactService * artifacts() const = 0;
virtual const CreatureService * creatures() const = 0;
virtual const FactionService * factions() const = 0;
virtual const HeroClassService * heroClasses() const = 0;
virtual const HeroTypeService * heroTypes() const = 0;
virtual const scripting::Service * scripts() const = 0;
virtual const spells::Service * spells() const = 0;
virtual const SkillService * skills() const = 0;
virtual void updateEntity(Metatype metatype, int32_t index, const JsonNode & data) = 0;
virtual const spells::effects::Registry * spellEffects() const = 0;
virtual spells::effects::Registry * spellEffects() = 0;
//TODO: put map object types registry access here
};
+22
View File
@@ -0,0 +1,22 @@
/*
* 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 "Entity.h"
class SecondarySkill;
class DLL_LINKAGE Skill : public EntityT<SecondarySkill>
{
public:
};
+21
View File
@@ -0,0 +1,21 @@
/*
* SkillService.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 "EntityService.h"
class SecondarySkill;
class Skill;
class DLL_LINKAGE SkillService : public EntityServiceT<SecondarySkill, Skill>
{
public:
};
+15
View File
@@ -0,0 +1,15 @@
/*
* Team.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
+13
View File
@@ -0,0 +1,13 @@
/*
* 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 "ObjectVisitEnded.h"
#include "ObjectVisitStarted.h"
+45
View File
@@ -0,0 +1,45 @@
/*
* ApplyDamage.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 "Event.h"
#include "SubscriptionRegistry.h"
struct BattleStackAttacked;
namespace battle
{
class Unit;
}
namespace events
{
class DLL_LINKAGE ApplyDamage : public Event
{
public:
using Sub = SubscriptionRegistry<ApplyDamage>;
using PreHandler = Sub::PreHandler;
using PostHandler = Sub::PostHandler;
using ExecHandler = Sub::ExecHandler;
static Sub * getRegistry();
virtual int64_t getInitalDamage() const = 0;
virtual int64_t getDamage() const = 0;
virtual void setDamage(int64_t value) = 0;
virtual const battle::Unit * getTarget() const = 0;
friend class SubscriptionRegistry<ApplyDamage>;
};
}
+13
View File
@@ -0,0 +1,13 @@
/*
* 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 "ApplyDamage.h"
+29
View File
@@ -0,0 +1,29 @@
/*
* Event.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
namespace events
{
class EventBus;
template <typename T>
class SubscriptionRegistry;
class DLL_LINKAGE Event
{
public:
virtual bool isEnabled() const = 0;
};
}
+44
View File
@@ -0,0 +1,44 @@
/*
* EventBus.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 "SubscriptionRegistry.h"
class Environment;
namespace events
{
class DLL_LINKAGE EventBus : public boost::noncopyable
{
public:
template <typename E>
std::unique_ptr<EventSubscription> subscribeBefore(typename E::PreHandler && cb)
{
auto registry = E::getRegistry();
return registry->subscribeBefore(this, std::move(cb));
}
template <typename E>
std::unique_ptr<EventSubscription> subscribeAfter(typename E::PostHandler && cb)
{
auto registry = E::getRegistry();
return registry->subscribeAfter(this, std::move(cb));
}
template <typename E>
void executeEvent(E & event, const typename E::ExecHandler & execHandler = typename E::ExecHandler()) const
{
auto registry = E::getRegistry();
registry->executeEvent(this, event, execHandler);
}
};
}
+35
View File
@@ -0,0 +1,35 @@
/*
* GameResumed.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 "Event.h"
#include "SubscriptionRegistry.h"
namespace events
{
class DLL_LINKAGE GameResumed : public Event
{
public:
using Sub = SubscriptionRegistry<GameResumed>;
using PreHandler = Sub::PreHandler;
using PostHandler = Sub::PostHandler;
using ExecHandler = Sub::ExecHandler;
static Sub * getRegistry();
static void defaultExecute(const EventBus * bus);
friend class SubscriptionRegistry<GameResumed>;
};
}
+15
View File
@@ -0,0 +1,15 @@
/*
* 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 "GameResumed.h"
#include "PlayerGotTurn.h"
#include "TurnStarted.h"
+40
View File
@@ -0,0 +1,40 @@
/*
* ObjectVisitEnded.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 "Event.h"
#include "SubscriptionRegistry.h"
class PlayerColor;
class ObjectInstanceID;
namespace events
{
class DLL_LINKAGE ObjectVisitEnded : public Event
{
public:
using Sub = SubscriptionRegistry<ObjectVisitEnded>;
using PreHandler = Sub::PreHandler;
using PostHandler = Sub::PostHandler;
using ExecHandler = Sub::ExecHandler;
virtual PlayerColor getPlayer() const = 0;
virtual ObjectInstanceID getHero() const = 0;
static Sub * getRegistry();
static void defaultExecute(const EventBus * bus, const ExecHandler & execHandler,
const PlayerColor & player, const ObjectInstanceID & heroId);
friend class SubscriptionRegistry<ObjectVisitEnded>;
};
}
+43
View File
@@ -0,0 +1,43 @@
/*
* ObjectVisitStarted.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 "Event.h"
#include "SubscriptionRegistry.h"
class PlayerColor;
class ObjectInstanceID;
namespace events
{
class DLL_LINKAGE ObjectVisitStarted : public Event
{
public:
using Sub = SubscriptionRegistry<ObjectVisitStarted>;
using PreHandler = Sub::PreHandler;
using PostHandler = Sub::PostHandler;
using ExecHandler = Sub::ExecHandler;
virtual PlayerColor getPlayer() const = 0;
virtual ObjectInstanceID getHero() const = 0;
virtual ObjectInstanceID getObject() const = 0;
virtual void setEnabled(bool enable) = 0;
static Sub * getRegistry();
static void defaultExecute(const EventBus * bus, const ExecHandler & execHandler,
const PlayerColor & player, const ObjectInstanceID & heroId, const ObjectInstanceID & objId);
friend class SubscriptionRegistry<ObjectVisitStarted>;
};
}
+41
View File
@@ -0,0 +1,41 @@
/*
* PlayerGotTurn.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 "Event.h"
#include "SubscriptionRegistry.h"
class PlayerColor;
namespace events
{
class DLL_LINKAGE PlayerGotTurn : public Event
{
public:
using Sub = SubscriptionRegistry<PlayerGotTurn>;
using PreHandler = Sub::PreHandler;
using PostHandler = Sub::PostHandler;
using ExecHandler = Sub::ExecHandler;
static Sub * getRegistry();
static void defaultExecute(const EventBus * bus, const ExecHandler & execHandler, PlayerColor & player);
virtual PlayerColor getPlayer() const = 0;
virtual void setPlayer(const PlayerColor & value) = 0;
virtual int32_t getPlayerIndex() const = 0;
virtual void setPlayerIndex(int32_t value) = 0;
friend class SubscriptionRegistry<PlayerGotTurn>;
};
}
+166
View File
@@ -0,0 +1,166 @@
/*
* SubscriptionRegistry.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
class Environment;
namespace events
{
class EventBus;
class DLL_LINKAGE EventSubscription : public boost::noncopyable
{
public:
virtual ~EventSubscription() = default;
};
template <typename E>
class SubscriptionRegistry : public boost::noncopyable
{
public:
using PreHandler = std::function<void(E &)>;
using ExecHandler = std::function<void(E &)>;
using PostHandler = std::function<void(const E &)>;
using BusTag = const void *;
std::unique_ptr<EventSubscription> subscribeBefore(BusTag tag, PreHandler && cb)
{
boost::unique_lock<boost::shared_mutex> lock(mutex);
auto storage = std::make_shared<PreHandlerStorage>(std::move(cb));
preHandlers[tag].push_back(storage);
return make_unique<PreSubscription>(tag, storage);
}
std::unique_ptr<EventSubscription> subscribeAfter(BusTag tag, PostHandler && cb)
{
boost::unique_lock<boost::shared_mutex> lock(mutex);
auto storage = std::make_shared<PostHandlerStorage>(std::move(cb));
postHandlers[tag].push_back(storage);
return make_unique<PostSubscription>(tag, storage);
}
void executeEvent(const EventBus * bus, E & event, const ExecHandler & execHandler)
{
boost::shared_lock<boost::shared_mutex> lock(mutex);
{
auto it = preHandlers.find(bus);
if(it != std::end(preHandlers))
{
for(auto & h : it->second)
(*h)(event);
}
}
if(event.isEnabled())
{
if(execHandler)
execHandler(event);
auto it = postHandlers.find(bus);
if(it != std::end(postHandlers))
{
for(auto & h : it->second)
(*h)(event);
}
}
}
private:
template <typename T>
class HandlerStorage
{
public:
explicit HandlerStorage(T && cb_)
: cb(cb_)
{
}
STRONG_INLINE
void operator()(E & event)
{
cb(event);
}
private:
T cb;
};
using PreHandlerStorage = HandlerStorage<PreHandler>;
using PostHandlerStorage = HandlerStorage<PostHandler>;
class PreSubscription : public EventSubscription
{
public:
PreSubscription(BusTag tag_, std::shared_ptr<PreHandlerStorage> cb_)
: cb(cb_),
tag(tag_)
{
}
virtual ~PreSubscription()
{
auto registry = E::getRegistry();
registry->unsubscribe(tag, cb, registry->preHandlers);
}
private:
BusTag tag;
std::shared_ptr<PreHandlerStorage> cb;
};
class PostSubscription : public EventSubscription
{
public:
PostSubscription(BusTag tag_, std::shared_ptr<PostHandlerStorage> cb_)
: cb(cb_),
tag(tag_)
{
}
virtual ~PostSubscription()
{
auto registry = E::getRegistry();
registry->unsubscribe(tag, cb, registry->postHandlers);
}
private:
BusTag tag;
std::shared_ptr<PostHandlerStorage> cb;
};
boost::shared_mutex mutex;
std::map<BusTag, std::vector<std::shared_ptr<PreHandlerStorage>>> preHandlers;
std::map<BusTag, std::vector<std::shared_ptr<PostHandlerStorage>>> postHandlers;
template <typename T>
void unsubscribe(BusTag tag, T what, std::map<BusTag, std::vector<T>> & from)
{
boost::unique_lock<boost::shared_mutex> lock(mutex);
auto it = from.find(tag);
if(it != std::end(from))
{
it->second -= what;
if(it->second.empty())
{
from.erase(tag);
}
}
}
};
}
+33
View File
@@ -0,0 +1,33 @@
/*
* TurnStarted.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 "Event.h"
#include "SubscriptionRegistry.h"
namespace events
{
class DLL_LINKAGE TurnStarted : public Event
{
public:
using Sub = SubscriptionRegistry<TurnStarted>;
using PreHandler = Sub::PreHandler;
using PostHandler = Sub::PostHandler;
using ExecHandler = Sub::ExecHandler;
static Sub * getRegistry();
static void defaultExecute(const EventBus * bus);
friend class SubscriptionRegistry<TurnStarted>;
};
}
+80
View File
@@ -0,0 +1,80 @@
/*
* scripting/Service.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/Environment.h>
class Services;
class JsonNode;
class ServerCallback;
namespace scripting
{
using BattleCb = ::Environment::BattleCb;
using GameCb = ::Environment::GameCb;
class DLL_LINKAGE Context
{
public:
virtual ~Context() = default;
virtual void run(const JsonNode & initialState) = 0;
virtual void run(ServerCallback * server, const JsonNode & initialState) = 0;
virtual JsonNode callGlobal(const std::string & name, const JsonNode & parameters) = 0;
virtual JsonNode callGlobal(ServerCallback * server, const std::string & name, const JsonNode & parameters) = 0;
virtual void setGlobal(const std::string & name, int value) = 0;
virtual void setGlobal(const std::string & name, const std::string & value) = 0;
virtual void setGlobal(const std::string & name, double value) = 0;
virtual void setGlobal(const std::string & name, const JsonNode & value) = 0;
virtual void getGlobal(const std::string & name, int & value) = 0;
virtual void getGlobal(const std::string & name, std::string & value) = 0;
virtual void getGlobal(const std::string & name, double & value) = 0;
virtual void getGlobal(const std::string & name, JsonNode & value) = 0;
virtual JsonNode saveState() = 0;
};
class DLL_LINKAGE Script
{
public:
virtual ~Script() = default;
virtual const std::string & getName() const = 0;
virtual const std::string & getSource() const = 0;
virtual std::shared_ptr<Context> createContext(const Environment * env) const = 0;
};
class DLL_LINKAGE Pool
{
public:
virtual ~Pool() = default;
virtual void serializeState(const bool saving, JsonNode & data) = 0;
virtual std::shared_ptr<Context> getContext(const Script * script) = 0;
};
class DLL_LINKAGE Service
{
public:
virtual ~Service() = default;
virtual void performRegistration(Services * services) const = 0;
virtual void run(std::shared_ptr<Pool> pool) const = 0;
};
}
+68
View File
@@ -0,0 +1,68 @@
/*
* Caster.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
class PlayerColor;
struct MetaString;
class ServerCallback;
namespace battle
{
class Unit;
}
namespace spells
{
class Spell;
class DLL_LINKAGE Caster
{
public:
virtual ~Caster() = default;
virtual int32_t getCasterUnitId() const = 0;
/// returns level on which given spell would be cast by this(0 - none, 1 - basic etc);
/// caster may not know this spell at all
/// optionally returns number of selected school by arg - 0 - air magic, 1 - fire magic, 2 - water magic, 3 - earth magic
virtual int32_t getSpellSchoolLevel(const Spell * spell, int32_t * outSelectedSchool = nullptr) const = 0;
///default spell school level for effect calculation
virtual int32_t getEffectLevel(const Spell * spell) const = 0;
///applying sorcery secondary skill etc
virtual int64_t getSpellBonus(const Spell * spell, int64_t base, const battle::Unit * affectedStack) const = 0;
///only bonus for particular spell
virtual int64_t getSpecificSpellBonus(const Spell * spell, int64_t base) const = 0;
///default spell-power for damage/heal calculation
virtual int32_t getEffectPower(const Spell * spell) const = 0;
///default spell-power for timed effects duration
virtual int32_t getEnchantPower(const Spell * spell) const = 0;
///damage/heal override(ignores spell configuration, effect level and effect power)
virtual int64_t getEffectValue(const Spell * spell) const = 0;
virtual PlayerColor getCasterOwner() const = 0;
///only name substitution
virtual void getCasterName(MetaString & text) const = 0;
///full default text
virtual void getCastDescription(const Spell * spell, const std::vector<const battle::Unit *> & attacked, MetaString & text) const = 0;
virtual void spendMana(ServerCallback * server, const int32_t spellCost) const = 0;
};
}
+69
View File
@@ -0,0 +1,69 @@
/*
* spells/Magic.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
struct MetaString;
namespace battle
{
class Unit;
class Destination;
}
namespace spells
{
class Caster;
class Spell;
class Mechanics;
class BattleCast;
using Destination = ::battle::Destination;
using Target = std::vector<Destination>;
enum class Mode
{
//ACTIVE, //todo: use
HERO, //deprecated
MAGIC_MIRROR,
CREATURE_ACTIVE, //deprecated
ENCHANTER,
SPELL_LIKE_ATTACK,
PASSIVE//f.e. opening battle spells
};
enum class AimType
{
NO_TARGET,
CREATURE,
OBSTACLE,
LOCATION
};
class DLL_LINKAGE Problem
{
public:
typedef int Severity;
enum ESeverity
{
LOWEST = std::numeric_limits<Severity>::min(),
NORMAL = 0,
CRITICAL = std::numeric_limits<Severity>::max()
};
virtual ~Problem() = default;
virtual void add(MetaString && description, Severity severity = CRITICAL) = 0;
virtual void getAll(std::vector<std::string> & target) const = 0;
};
}
+26
View File
@@ -0,0 +1,26 @@
/*
* spells/Service.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 "../EntityService.h"
class SpellID;
namespace spells
{
class Spell;
class DLL_LINKAGE Service : public EntityServiceT<SpellID, Spell>
{
public:
};
}
+56
View File
@@ -0,0 +1,56 @@
/*
* spells/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 "../Entity.h"
class SpellID;
namespace spells
{
struct SchoolInfo;
class Caster;
class DLL_LINKAGE Spell: public EntityT<SpellID>
{
public:
using SchoolCallback = std::function<void(const SchoolInfo &, bool &)>;
///calculate spell damage on stack taking caster`s secondary skills into account
virtual int64_t calculateDamage(const Caster * caster) const = 0;
virtual int32_t getLevel() const = 0;
virtual boost::logic::tribool getPositiveness() const = 0;
virtual bool isAdventure() const = 0;
virtual bool isCombat() const = 0;
virtual bool isCreatureAbility() const = 0;
virtual bool isPositive() const = 0;
virtual bool isNegative() const = 0;
virtual bool isNeutral() const = 0;
virtual bool isDamage() const = 0;
virtual bool isOffensive() const = 0;
virtual bool isSpecial() const = 0;
virtual void forEachSchool(const SchoolCallback & cb) const = 0;
virtual const std::string & getCastSound() const = 0;
virtual int32_t getCost(const int32_t skillLevel) const = 0;
virtual int32_t getBasePower() const = 0;
/**
* Returns spell level power, base power ignored
*/
virtual int32_t getLevelPower(const int32_t skillLevel) const = 0;
virtual const std::string & getLevelDescription(const int32_t skillLevel) const = 0;
};
}
+1
View File
@@ -4,5 +4,6 @@ namespace vstd
{
DLL_LINKAGE std::vector<std::string> split(std::string s, std::string separators);
DLL_LINKAGE std::pair<std::string, std::string> splitStringToPair(std::string input, char separator);
}