2016-10-28 16:16:46 +02:00
|
|
|
/*
|
|
|
|
* StackWithBonuses.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 "StackWithBonuses.h"
|
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.
2018-03-17 16:58:30 +02:00
|
|
|
|
|
|
|
#include <vcmi/events/EventBus.h>
|
|
|
|
|
2017-03-17 17:48:44 +02:00
|
|
|
#include "../../lib/CStack.h"
|
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.
2018-03-17 16:58:30 +02:00
|
|
|
#include "../../lib/ScriptHandler.h"
|
2023-10-23 12:59:15 +02:00
|
|
|
#include "../../lib/networkPacks/PacksForClientBattle.h"
|
2023-10-24 00:27:52 +02:00
|
|
|
#include "../../lib/networkPacks/SetStackEffect.h"
|
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.
2018-03-17 16:58:30 +02:00
|
|
|
|
2022-09-21 18:31:14 +02:00
|
|
|
#if SCRIPTING_ENABLED
|
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.
2018-03-17 16:58:30 +02:00
|
|
|
using scripting::Pool;
|
2022-09-21 18:31:14 +02:00
|
|
|
#endif
|
2017-03-17 17:48:44 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
void actualizeEffect(TBonusListPtr target, const Bonus & ef)
|
|
|
|
{
|
2021-01-30 14:13:45 +02:00
|
|
|
for(auto & bonus : *target) //TODO: optimize
|
2017-07-20 06:08:49 +02:00
|
|
|
{
|
2023-05-01 00:20:01 +02:00
|
|
|
if(bonus->source == BonusSource::SPELL_EFFECT && bonus->type == ef.type && bonus->subtype == ef.subtype)
|
2017-07-20 06:08:49 +02:00
|
|
|
{
|
2021-01-30 14:13:45 +02:00
|
|
|
if(bonus->turnsRemain < ef.turnsRemain)
|
|
|
|
{
|
|
|
|
bonus.reset(new Bonus(*bonus));
|
|
|
|
|
|
|
|
bonus->turnsRemain = ef.turnsRemain;
|
|
|
|
}
|
2017-07-20 06:08:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-10-28 16:16:46 +02:00
|
|
|
|
2023-04-27 22:41:41 +02:00
|
|
|
StackWithBonuses::StackWithBonuses(const HypotheticBattle * Owner, const battle::CUnitState * Stack)
|
2017-07-20 06:08:49 +02:00
|
|
|
: battle::CUnitState(),
|
2023-04-27 22:41:41 +02:00
|
|
|
origBearer(Stack->getBonusBearer()),
|
2017-07-20 06:08:49 +02:00
|
|
|
owner(Owner),
|
|
|
|
type(Stack->unitType()),
|
|
|
|
baseAmount(Stack->unitBaseAmount()),
|
|
|
|
id(Stack->unitId()),
|
|
|
|
side(Stack->unitSide()),
|
|
|
|
player(Stack->unitOwner()),
|
2023-08-26 12:06:41 +02:00
|
|
|
slot(Stack->unitSlot()),
|
|
|
|
treeVersionLocal(0)
|
2017-07-20 06:08:49 +02:00
|
|
|
{
|
|
|
|
localInit(Owner);
|
|
|
|
|
|
|
|
battle::CUnitState::operator=(*Stack);
|
|
|
|
}
|
|
|
|
|
2023-08-13 12:56:04 +02:00
|
|
|
StackWithBonuses::StackWithBonuses(const HypotheticBattle * Owner, const battle::Unit * Stack)
|
|
|
|
: battle::CUnitState(),
|
|
|
|
origBearer(Stack->getBonusBearer()),
|
|
|
|
owner(Owner),
|
|
|
|
type(Stack->unitType()),
|
|
|
|
baseAmount(Stack->unitBaseAmount()),
|
|
|
|
id(Stack->unitId()),
|
|
|
|
side(Stack->unitSide()),
|
|
|
|
player(Stack->unitOwner()),
|
2023-08-26 12:06:41 +02:00
|
|
|
slot(Stack->unitSlot()),
|
|
|
|
treeVersionLocal(0)
|
2023-08-13 12:56:04 +02:00
|
|
|
{
|
|
|
|
localInit(Owner);
|
|
|
|
|
|
|
|
auto state = Stack->acquireState();
|
|
|
|
battle::CUnitState::operator=(*state);
|
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
StackWithBonuses::StackWithBonuses(const HypotheticBattle * Owner, const battle::UnitInfo & info)
|
|
|
|
: battle::CUnitState(),
|
|
|
|
origBearer(nullptr),
|
|
|
|
owner(Owner),
|
|
|
|
baseAmount(info.count),
|
|
|
|
id(info.id),
|
|
|
|
side(info.side),
|
2023-08-26 12:06:41 +02:00
|
|
|
slot(SlotID::SUMMONED_SLOT_PLACEHOLDER),
|
|
|
|
treeVersionLocal(0)
|
2017-07-20 06:08:49 +02:00
|
|
|
{
|
|
|
|
type = info.type.toCreature();
|
|
|
|
origBearer = type;
|
|
|
|
|
|
|
|
player = Owner->getSidePlayer(side);
|
|
|
|
|
2018-02-23 20:58:05 +02:00
|
|
|
localInit(Owner);
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
position = info.position;
|
|
|
|
summoned = info.summoned;
|
|
|
|
}
|
|
|
|
|
|
|
|
StackWithBonuses::~StackWithBonuses() = default;
|
|
|
|
|
|
|
|
StackWithBonuses & StackWithBonuses::operator=(const battle::CUnitState & other)
|
|
|
|
{
|
|
|
|
battle::CUnitState::operator=(other);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
const CCreature * StackWithBonuses::unitType() const
|
|
|
|
{
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t StackWithBonuses::unitBaseAmount() const
|
|
|
|
{
|
|
|
|
return baseAmount;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t StackWithBonuses::unitId() const
|
|
|
|
{
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2024-08-11 22:22:35 +02:00
|
|
|
BattleSide StackWithBonuses::unitSide() const
|
2017-07-20 06:08:49 +02:00
|
|
|
{
|
|
|
|
return side;
|
|
|
|
}
|
|
|
|
|
|
|
|
PlayerColor StackWithBonuses::unitOwner() const
|
|
|
|
{
|
|
|
|
return player;
|
|
|
|
}
|
|
|
|
|
|
|
|
SlotID StackWithBonuses::unitSlot() const
|
|
|
|
{
|
|
|
|
return slot;
|
|
|
|
}
|
|
|
|
|
2020-10-01 07:55:41 +02:00
|
|
|
TConstBonusListPtr StackWithBonuses::getAllBonuses(const CSelector & selector, const CSelector & limit,
|
2024-08-25 12:44:11 +02:00
|
|
|
const std::string & cachingStr) const
|
2016-10-28 16:16:46 +02:00
|
|
|
{
|
2024-01-17 14:50:00 +02:00
|
|
|
auto ret = std::make_shared<BonusList>();
|
2024-08-25 12:44:11 +02:00
|
|
|
TConstBonusListPtr originalList = origBearer->getAllBonuses(selector, limit, cachingStr);
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
vstd::copy_if(*originalList, std::back_inserter(*ret), [this](const std::shared_ptr<Bonus> & b)
|
|
|
|
{
|
|
|
|
return !vstd::contains(bonusesToRemove, b);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
for(const Bonus & bonus : bonusesToUpdate)
|
|
|
|
{
|
2023-08-08 17:37:42 +02:00
|
|
|
if(selector(&bonus) && (!limit || limit(&bonus)))
|
2017-07-20 06:08:49 +02:00
|
|
|
{
|
2023-05-01 00:20:01 +02:00
|
|
|
if(ret->getFirst(Selector::source(BonusSource::SPELL_EFFECT, bonus.sid).And(Selector::typeSubtype(bonus.type, bonus.subtype))))
|
2017-07-20 06:08:49 +02:00
|
|
|
{
|
|
|
|
actualizeEffect(ret, bonus);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto b = std::make_shared<Bonus>(bonus);
|
|
|
|
ret->push_back(b);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(auto & bonus : bonusesToAdd)
|
2016-10-28 16:16:46 +02:00
|
|
|
{
|
|
|
|
auto b = std::make_shared<Bonus>(bonus);
|
2017-07-20 06:08:49 +02:00
|
|
|
if(selector(b.get()) && (!limit || !limit(b.get())))
|
2016-10-28 16:16:46 +02:00
|
|
|
ret->push_back(b);
|
|
|
|
}
|
|
|
|
//TODO limiters?
|
|
|
|
return ret;
|
|
|
|
}
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
int64_t StackWithBonuses::getTreeVersion() const
|
|
|
|
{
|
2023-08-08 17:37:42 +02:00
|
|
|
auto result = owner->getTreeVersion();
|
|
|
|
|
|
|
|
if(bonusesToAdd.empty() && bonusesToUpdate.empty() && bonusesToRemove.empty())
|
|
|
|
return result;
|
|
|
|
else
|
|
|
|
return result + treeVersionLocal;
|
2017-07-20 06:08:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void StackWithBonuses::addUnitBonus(const std::vector<Bonus> & bonus)
|
|
|
|
{
|
|
|
|
vstd::concatenate(bonusesToAdd, bonus);
|
2023-08-08 17:37:42 +02:00
|
|
|
treeVersionLocal++;
|
2017-07-20 06:08:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void StackWithBonuses::updateUnitBonus(const std::vector<Bonus> & bonus)
|
|
|
|
{
|
|
|
|
//TODO: optimize, actualize to last value
|
|
|
|
|
|
|
|
vstd::concatenate(bonusesToUpdate, bonus);
|
2023-08-08 17:37:42 +02:00
|
|
|
treeVersionLocal++;
|
2017-07-20 06:08:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void StackWithBonuses::removeUnitBonus(const std::vector<Bonus> & bonus)
|
|
|
|
{
|
|
|
|
for(auto & one : bonus)
|
|
|
|
{
|
|
|
|
CSelector selector([&one](const Bonus * b) -> bool
|
|
|
|
{
|
|
|
|
//compare everything but turnsRemain, limiter and propagator
|
|
|
|
return one.duration == b->duration
|
|
|
|
&& one.type == b->type
|
|
|
|
&& one.subtype == b->subtype
|
|
|
|
&& one.source == b->source
|
|
|
|
&& one.val == b->val
|
|
|
|
&& one.sid == b->sid
|
|
|
|
&& one.valType == b->valType
|
|
|
|
&& one.additionalInfo == b->additionalInfo
|
2024-04-07 18:57:49 +02:00
|
|
|
&& one.effectRange == b->effectRange;
|
2017-07-20 06:08:49 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
removeUnitBonus(selector);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StackWithBonuses::removeUnitBonus(const CSelector & selector)
|
|
|
|
{
|
2020-10-01 07:55:41 +02:00
|
|
|
TConstBonusListPtr toRemove = origBearer->getBonuses(selector);
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
for(auto b : *toRemove)
|
|
|
|
bonusesToRemove.insert(b);
|
|
|
|
|
|
|
|
vstd::erase_if(bonusesToAdd, [&](const Bonus & b){return selector(&b);});
|
|
|
|
vstd::erase_if(bonusesToUpdate, [&](const Bonus & b){return selector(&b);});
|
2023-08-08 17:37:42 +02:00
|
|
|
|
|
|
|
treeVersionLocal++;
|
2017-07-20 06:08:49 +02:00
|
|
|
}
|
|
|
|
|
2022-01-27 09:00:27 +02:00
|
|
|
std::string StackWithBonuses::getDescription() const
|
|
|
|
{
|
|
|
|
std::ostringstream oss;
|
2023-09-04 21:21:02 +02:00
|
|
|
oss << unitOwner().toString();
|
2022-01-27 09:00:27 +02:00
|
|
|
oss << " battle stack [" << unitId() << "]: " << getCount() << " of ";
|
|
|
|
if(type)
|
2023-01-02 18:00:51 +02:00
|
|
|
oss << type->getJsonKey();
|
2022-01-27 09:00:27 +02:00
|
|
|
else
|
|
|
|
oss << "[UNDEFINED TYPE]";
|
|
|
|
|
|
|
|
oss << " from slot " << slot;
|
|
|
|
|
|
|
|
return oss.str();
|
|
|
|
}
|
|
|
|
|
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.
2018-03-17 16:58:30 +02:00
|
|
|
void StackWithBonuses::spendMana(ServerCallback * server, const int spellCost) const
|
2017-07-20 06:08:49 +02:00
|
|
|
{
|
|
|
|
//TODO: evaluate cast use
|
|
|
|
}
|
|
|
|
|
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.
2018-03-17 16:58:30 +02:00
|
|
|
HypotheticBattle::HypotheticBattle(const Environment * ENV, Subject realBattle)
|
2017-07-20 06:08:49 +02:00
|
|
|
: BattleProxy(realBattle),
|
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.
2018-03-17 16:58:30 +02:00
|
|
|
env(ENV),
|
2017-07-20 06:08:49 +02:00
|
|
|
bonusTreeVersion(1)
|
|
|
|
{
|
|
|
|
auto activeUnit = realBattle->battleActiveUnit();
|
|
|
|
activeUnitId = activeUnit ? activeUnit->unitId() : -1;
|
|
|
|
|
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.
2018-03-17 16:58:30 +02:00
|
|
|
nextId = 0x00F00000;
|
|
|
|
|
|
|
|
eventBus.reset(new events::EventBus());
|
|
|
|
|
|
|
|
localEnvironment.reset(new HypotheticEnvironment(this, env));
|
|
|
|
serverCallback.reset(new HypotheticServerCallback(this));
|
|
|
|
|
2022-09-21 18:31:14 +02:00
|
|
|
#if SCRIPTING_ENABLED
|
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.
2018-03-17 16:58:30 +02:00
|
|
|
pool.reset(new scripting::PoolImpl(localEnvironment.get(), serverCallback.get()));
|
2022-09-21 18:31:14 +02:00
|
|
|
#endif
|
2017-07-20 06:08:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool HypotheticBattle::unitHasAmmoCart(const battle::Unit * unit) const
|
|
|
|
{
|
|
|
|
//FIXME: check ammocart alive state here
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
PlayerColor HypotheticBattle::unitEffectiveOwner(const battle::Unit * unit) const
|
|
|
|
{
|
|
|
|
return battleGetOwner(unit);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<StackWithBonuses> HypotheticBattle::getForUpdate(uint32_t id)
|
|
|
|
{
|
|
|
|
auto iter = stackStates.find(id);
|
|
|
|
|
|
|
|
if(iter == stackStates.end())
|
|
|
|
{
|
2023-08-13 12:56:04 +02:00
|
|
|
const battle::Unit * s = subject->battleGetUnitByID(id);
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
auto ret = std::make_shared<StackWithBonuses>(this, s);
|
|
|
|
stackStates[id] = ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return iter->second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-18 19:43:11 +02:00
|
|
|
battle::Units HypotheticBattle::getUnitsIf(const battle::UnitFilter & predicate) const
|
2017-07-20 06:08:49 +02:00
|
|
|
{
|
|
|
|
battle::Units proxyed = BattleProxy::getUnitsIf(predicate);
|
|
|
|
|
|
|
|
battle::Units ret;
|
|
|
|
ret.reserve(proxyed.size());
|
|
|
|
|
|
|
|
for(auto unit : proxyed)
|
|
|
|
{
|
|
|
|
//unit was not changed, trust proxyed data
|
|
|
|
if(stackStates.find(unit->unitId()) == stackStates.end())
|
|
|
|
ret.push_back(unit);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(auto id_unit : stackStates)
|
|
|
|
{
|
|
|
|
if(predicate(id_unit.second.get()))
|
|
|
|
ret.push_back(id_unit.second.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-08-31 17:45:52 +02:00
|
|
|
BattleID HypotheticBattle::getBattleID() const
|
|
|
|
{
|
|
|
|
return subject->getBattle()->getBattleID();
|
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
int32_t HypotheticBattle::getActiveStackID() const
|
|
|
|
{
|
|
|
|
return activeUnitId;
|
|
|
|
}
|
|
|
|
|
2023-08-28 16:43:57 +02:00
|
|
|
void HypotheticBattle::nextRound()
|
2017-07-20 06:08:49 +02:00
|
|
|
{
|
|
|
|
//TODO:HypotheticBattle::nextRound
|
|
|
|
for(auto unit : battleAliveUnits())
|
|
|
|
{
|
|
|
|
auto forUpdate = getForUpdate(unit->unitId());
|
|
|
|
//TODO: update Bonus::NTurns effects
|
|
|
|
forUpdate->afterNewRound();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HypotheticBattle::nextTurn(uint32_t unitId)
|
|
|
|
{
|
|
|
|
activeUnitId = unitId;
|
|
|
|
auto unit = getForUpdate(unitId);
|
|
|
|
|
|
|
|
unit->removeUnitBonus(Bonus::UntilGetsTurn);
|
|
|
|
|
|
|
|
unit->afterGetsTurn();
|
|
|
|
}
|
|
|
|
|
|
|
|
void HypotheticBattle::addUnit(uint32_t id, const JsonNode & data)
|
|
|
|
{
|
|
|
|
battle::UnitInfo info;
|
|
|
|
info.load(id, data);
|
2024-01-17 14:50:00 +02:00
|
|
|
auto newUnit = std::make_shared<StackWithBonuses>(this, info);
|
2017-07-20 06:08:49 +02:00
|
|
|
stackStates[newUnit->unitId()] = newUnit;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HypotheticBattle::moveUnit(uint32_t id, BattleHex destination)
|
|
|
|
{
|
|
|
|
std::shared_ptr<StackWithBonuses> changed = getForUpdate(id);
|
|
|
|
changed->position = destination;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HypotheticBattle::setUnitState(uint32_t id, const JsonNode & data, int64_t healthDelta)
|
|
|
|
{
|
|
|
|
std::shared_ptr<StackWithBonuses> changed = getForUpdate(id);
|
|
|
|
|
|
|
|
changed->load(data);
|
|
|
|
|
|
|
|
if(healthDelta < 0)
|
|
|
|
{
|
|
|
|
changed->removeUnitBonus(Bonus::UntilBeingAttacked);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HypotheticBattle::removeUnit(uint32_t id)
|
|
|
|
{
|
|
|
|
std::set<uint32_t> ids;
|
|
|
|
ids.insert(id);
|
|
|
|
|
|
|
|
while(!ids.empty())
|
|
|
|
{
|
|
|
|
auto toRemoveId = *ids.begin();
|
|
|
|
|
|
|
|
auto toRemove = getForUpdate(toRemoveId);
|
|
|
|
|
|
|
|
if(!toRemove->ghost)
|
|
|
|
{
|
|
|
|
toRemove->onRemoved();
|
|
|
|
|
|
|
|
//TODO: emulate detachFromAll() somehow
|
|
|
|
|
|
|
|
//stack may be removed instantly (not being killed first)
|
|
|
|
//handle clone remove also here
|
|
|
|
if(toRemove->cloneID >= 0)
|
|
|
|
{
|
|
|
|
ids.insert(toRemove->cloneID);
|
|
|
|
toRemove->cloneID = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//TODO: cleanup remaining clone links if any
|
|
|
|
// for(auto s : stacks)
|
|
|
|
// {
|
|
|
|
// if(s->cloneID == toRemoveId)
|
|
|
|
// s->cloneID = -1;
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
|
|
|
|
ids.erase(toRemoveId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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.
2018-03-17 16:58:30 +02:00
|
|
|
void HypotheticBattle::updateUnit(uint32_t id, const JsonNode & data)
|
|
|
|
{
|
|
|
|
//TODO:
|
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
void HypotheticBattle::addUnitBonus(uint32_t id, const std::vector<Bonus> & bonus)
|
|
|
|
{
|
|
|
|
getForUpdate(id)->addUnitBonus(bonus);
|
|
|
|
bonusTreeVersion++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HypotheticBattle::updateUnitBonus(uint32_t id, const std::vector<Bonus> & bonus)
|
|
|
|
{
|
|
|
|
getForUpdate(id)->updateUnitBonus(bonus);
|
|
|
|
bonusTreeVersion++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HypotheticBattle::removeUnitBonus(uint32_t id, const std::vector<Bonus> & bonus)
|
|
|
|
{
|
|
|
|
getForUpdate(id)->removeUnitBonus(bonus);
|
|
|
|
bonusTreeVersion++;
|
|
|
|
}
|
|
|
|
|
2023-01-13 00:35:58 +02:00
|
|
|
void HypotheticBattle::setWallState(EWallPart partOfWall, EWallState state)
|
2017-07-20 06:08:49 +02:00
|
|
|
{
|
|
|
|
//TODO:HypotheticBattle::setWallState
|
|
|
|
}
|
|
|
|
|
|
|
|
void HypotheticBattle::addObstacle(const ObstacleChanges & changes)
|
|
|
|
{
|
|
|
|
//TODO:HypotheticBattle::addObstacle
|
|
|
|
}
|
|
|
|
|
2020-02-12 19:12:12 +02:00
|
|
|
void HypotheticBattle::updateObstacle(const ObstacleChanges& changes)
|
|
|
|
{
|
|
|
|
//TODO:HypotheticBattle::updateObstacle
|
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
void HypotheticBattle::removeObstacle(uint32_t id)
|
|
|
|
{
|
|
|
|
//TODO:HypotheticBattle::removeObstacle
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t HypotheticBattle::nextUnitId() const
|
|
|
|
{
|
|
|
|
return nextId++;
|
|
|
|
}
|
|
|
|
|
2023-03-23 17:49:33 +02:00
|
|
|
int64_t HypotheticBattle::getActualDamage(const DamageRange & damage, int32_t attackerCount, vstd::RNG & rng) const
|
2017-07-20 06:08:49 +02:00
|
|
|
{
|
2023-03-23 17:49:33 +02:00
|
|
|
return (damage.min + damage.max) / 2;
|
2017-07-20 06:08:49 +02:00
|
|
|
}
|
|
|
|
|
2024-08-11 22:22:35 +02:00
|
|
|
std::vector<SpellID> HypotheticBattle::getUsedSpells(BattleSide side) const
|
2023-08-28 16:43:57 +02:00
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
int3 HypotheticBattle::getLocation() const
|
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
return int3(-1, -1, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HypotheticBattle::isCreatureBank() const
|
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
int64_t HypotheticBattle::getTreeVersion() const
|
|
|
|
{
|
2023-04-05 02:26:29 +02:00
|
|
|
return getBonusBearer()->getTreeVersion() + bonusTreeVersion;
|
2017-07-20 06:08:49 +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.
2018-03-17 16:58:30 +02:00
|
|
|
|
2022-09-21 18:31:14 +02:00
|
|
|
#if SCRIPTING_ENABLED
|
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.
2018-03-17 16:58:30 +02:00
|
|
|
Pool * HypotheticBattle::getContextPool() const
|
|
|
|
{
|
|
|
|
return pool.get();
|
|
|
|
}
|
2022-09-21 18:31:14 +02:00
|
|
|
#endif
|
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.
2018-03-17 16:58:30 +02:00
|
|
|
|
|
|
|
ServerCallback * HypotheticBattle::getServerCallback()
|
|
|
|
{
|
|
|
|
return serverCallback.get();
|
|
|
|
}
|
|
|
|
|
2024-08-25 14:49:11 +02:00
|
|
|
void HypotheticBattle::makeWait(const battle::Unit * activeStack)
|
|
|
|
{
|
|
|
|
auto unit = getForUpdate(activeStack->unitId());
|
|
|
|
|
|
|
|
resetActiveUnit();
|
|
|
|
unit->waiting = true;
|
|
|
|
unit->waitedThisTurn = true;
|
|
|
|
}
|
|
|
|
|
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.
2018-03-17 16:58:30 +02:00
|
|
|
HypotheticBattle::HypotheticServerCallback::HypotheticServerCallback(HypotheticBattle * owner_)
|
|
|
|
:owner(owner_)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void HypotheticBattle::HypotheticServerCallback::complain(const std::string & problem)
|
|
|
|
{
|
|
|
|
logAi->error(problem);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HypotheticBattle::HypotheticServerCallback::describeChanges() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
vstd::RNG * HypotheticBattle::HypotheticServerCallback::getRNG()
|
|
|
|
{
|
|
|
|
return &rngStub;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HypotheticBattle::HypotheticServerCallback::apply(CPackForClient * pack)
|
|
|
|
{
|
|
|
|
logAi->error("Package of type %s is not allowed in battle evaluation", typeid(pack).name());
|
|
|
|
}
|
|
|
|
|
|
|
|
void HypotheticBattle::HypotheticServerCallback::apply(BattleLogMessage * pack)
|
|
|
|
{
|
|
|
|
pack->applyBattle(owner);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HypotheticBattle::HypotheticServerCallback::apply(BattleStackMoved * pack)
|
|
|
|
{
|
|
|
|
pack->applyBattle(owner);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HypotheticBattle::HypotheticServerCallback::apply(BattleUnitsChanged * pack)
|
|
|
|
{
|
|
|
|
pack->applyBattle(owner);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HypotheticBattle::HypotheticServerCallback::apply(SetStackEffect * pack)
|
|
|
|
{
|
|
|
|
pack->applyBattle(owner);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HypotheticBattle::HypotheticServerCallback::apply(StacksInjured * pack)
|
|
|
|
{
|
|
|
|
pack->applyBattle(owner);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HypotheticBattle::HypotheticServerCallback::apply(BattleObstaclesChanged * pack)
|
|
|
|
{
|
|
|
|
pack->applyBattle(owner);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HypotheticBattle::HypotheticServerCallback::apply(CatapultAttack * pack)
|
|
|
|
{
|
|
|
|
pack->applyBattle(owner);
|
|
|
|
}
|
|
|
|
|
|
|
|
HypotheticBattle::HypotheticEnvironment::HypotheticEnvironment(HypotheticBattle * owner_, const Environment * upperEnvironment)
|
|
|
|
: owner(owner_),
|
|
|
|
env(upperEnvironment)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const Services * HypotheticBattle::HypotheticEnvironment::services() const
|
|
|
|
{
|
|
|
|
return env->services();
|
|
|
|
}
|
|
|
|
|
2023-08-28 16:43:57 +02:00
|
|
|
const Environment::BattleCb * HypotheticBattle::HypotheticEnvironment::battle(const BattleID & battleID) const
|
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.
2018-03-17 16:58:30 +02:00
|
|
|
{
|
2023-08-28 16:43:57 +02:00
|
|
|
assert(battleID == owner->getBattleID());
|
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.
2018-03-17 16:58:30 +02:00
|
|
|
return owner;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Environment::GameCb * HypotheticBattle::HypotheticEnvironment::game() const
|
|
|
|
{
|
|
|
|
return env->game();
|
|
|
|
}
|
|
|
|
|
|
|
|
vstd::CLoggerBase * HypotheticBattle::HypotheticEnvironment::logger() const
|
|
|
|
{
|
|
|
|
return env->logger();
|
|
|
|
}
|
|
|
|
|
|
|
|
events::EventBus * HypotheticBattle::HypotheticEnvironment::eventBus() const
|
|
|
|
{
|
|
|
|
return owner->eventBus.get();
|
|
|
|
}
|
|
|
|
|