2017-07-20 06:08:49 +02:00
|
|
|
/*
|
|
|
|
* CGameStateTest.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"
|
|
|
|
|
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 "mock/mock_Services.h"
|
2017-07-20 06:08:49 +02:00
|
|
|
#include "mock/mock_MapService.h"
|
|
|
|
#include "mock/mock_IGameCallback.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 "mock/mock_spells_Problem.h"
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
#include "../../lib/VCMIDirs.h"
|
2024-02-11 23:09:01 +02:00
|
|
|
#include "../../lib/json/JsonUtils.h"
|
2023-06-23 17:02:48 +02:00
|
|
|
#include "../../lib/gameState/CGameState.h"
|
2023-10-23 15:05:38 +02:00
|
|
|
#include "../../lib/networkPacks/PacksForClient.h"
|
|
|
|
#include "../../lib/networkPacks/PacksForClientBattle.h"
|
2023-10-24 00:27:52 +02:00
|
|
|
#include "../../lib/networkPacks/SetStackEffect.h"
|
2017-07-20 06:08:49 +02:00
|
|
|
#include "../../lib/StartInfo.h"
|
2023-02-28 13:29:35 +02:00
|
|
|
#include "../../lib/TerrainHandler.h"
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
#include "../../lib/battle/BattleInfo.h"
|
|
|
|
#include "../../lib/CStack.h"
|
|
|
|
|
2023-08-23 14:07:50 +02:00
|
|
|
#include "../../lib/filesystem/ResourcePath.h"
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
#include "../../lib/mapping/CMap.h"
|
|
|
|
|
|
|
|
#include "../../lib/spells/CSpellHandler.h"
|
|
|
|
#include "../../lib/spells/ISpellMechanics.h"
|
2018-03-02 12:22:51 +02:00
|
|
|
#include "../../lib/spells/AbilityCaster.h"
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
class CGameStateTest : public ::testing::Test, public SpellCastEnvironment, public MapListener
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CGameStateTest()
|
|
|
|
: gameCallback(new GameCallbackMock(this)),
|
|
|
|
mapService("test/MiniTest/", this),
|
|
|
|
map(nullptr)
|
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 SetUp() override
|
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
|
|
|
gameState = std::make_shared<CGameState>();
|
|
|
|
gameCallback->setGameState(gameState.get());
|
2024-01-10 21:30:12 +02:00
|
|
|
gameState->preInit(&services, gameCallback.get());
|
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
|
|
|
void TearDown() override
|
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
|
|
|
gameState.reset();
|
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
|
|
|
bool describeChanges() const override
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void apply(CPackForClient * pack) override
|
|
|
|
{
|
|
|
|
gameState->apply(pack);
|
|
|
|
}
|
|
|
|
|
|
|
|
void apply(BattleLogMessage * pack) override
|
2017-07-20 06:08:49 +02:00
|
|
|
{
|
2018-02-25 18:16:15 +02:00
|
|
|
gameState->apply(pack);
|
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
|
|
|
void apply(BattleStackMoved * pack) override
|
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
|
|
|
gameState->apply(pack);
|
|
|
|
}
|
|
|
|
|
|
|
|
void apply(BattleUnitsChanged * pack) override
|
|
|
|
{
|
|
|
|
gameState->apply(pack);
|
|
|
|
}
|
|
|
|
|
|
|
|
void apply(SetStackEffect * pack) override
|
|
|
|
{
|
|
|
|
gameState->apply(pack);
|
|
|
|
}
|
|
|
|
|
|
|
|
void apply(StacksInjured * pack) override
|
|
|
|
{
|
|
|
|
gameState->apply(pack);
|
|
|
|
}
|
|
|
|
|
|
|
|
void apply(BattleObstaclesChanged * pack) override
|
|
|
|
{
|
|
|
|
gameState->apply(pack);
|
|
|
|
}
|
|
|
|
|
|
|
|
void apply(CatapultAttack * pack) override
|
|
|
|
{
|
|
|
|
gameState->apply(pack);
|
|
|
|
}
|
|
|
|
|
|
|
|
void complain(const std::string & problem) override
|
|
|
|
{
|
|
|
|
FAIL() << "Server-side assertion: " << problem;
|
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
|
|
|
vstd::RNG * getRNG() override
|
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
|
|
|
return &gameState->getRandomGenerator();//todo: mock this
|
2017-07-20 06:08:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const CMap * getMap() const override
|
|
|
|
{
|
|
|
|
return map;
|
|
|
|
}
|
|
|
|
const CGameInfoCallback * getCb() const override
|
|
|
|
{
|
|
|
|
return gameState.get();
|
|
|
|
}
|
|
|
|
|
2024-07-14 09:56:02 +02:00
|
|
|
void createBoat(const int3 & visitablePosition, BoatId type, PlayerColor initiator) override
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-05-07 22:05:23 +02:00
|
|
|
bool moveHero(ObjectInstanceID hid, int3 dst, EMovementMode movementMode) override
|
2017-07-20 06:08:49 +02:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-09-19 22:17:25 +02:00
|
|
|
void genericQuery(Query * request, PlayerColor color, std::function<void(std::optional<int32_t>)> callback) override
|
2017-07-20 06:08:49 +02:00
|
|
|
{
|
|
|
|
//todo:
|
|
|
|
}
|
|
|
|
|
|
|
|
void mapLoaded(CMap * map) override
|
|
|
|
{
|
|
|
|
EXPECT_EQ(this->map, nullptr);
|
|
|
|
this->map = map;
|
|
|
|
}
|
|
|
|
|
|
|
|
void startTestGame()
|
|
|
|
{
|
|
|
|
StartInfo si;
|
|
|
|
si.mapname = "anything";//does not matter, map service mocked
|
|
|
|
si.difficulty = 0;
|
2024-01-26 17:40:31 +02:00
|
|
|
si.mode = EStartMode::NEW_GAME;
|
2017-07-20 06:08:49 +02:00
|
|
|
|
2023-08-23 14:07:50 +02:00
|
|
|
std::unique_ptr<CMapHeader> header = mapService.loadMapHeader(ResourcePath(si.mapname));
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
ASSERT_NE(header.get(), nullptr);
|
|
|
|
|
|
|
|
//FIXME: this has been copied from CPreGame, but should be part of StartInfo
|
|
|
|
for(int i = 0; i < header->players.size(); i++)
|
|
|
|
{
|
|
|
|
const PlayerInfo & pinfo = header->players[i];
|
|
|
|
|
|
|
|
//neither computer nor human can play - no player
|
|
|
|
if (!(pinfo.canHumanPlay || pinfo.canComputerPlay))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
PlayerSettings & pset = si.playerInfos[PlayerColor(i)];
|
|
|
|
pset.color = PlayerColor(i);
|
2018-01-05 19:21:07 +02:00
|
|
|
pset.connectedPlayerIDs.insert(i);
|
2017-07-20 06:08:49 +02:00
|
|
|
pset.name = "Player";
|
|
|
|
|
|
|
|
pset.castle = pinfo.defaultCastle();
|
|
|
|
pset.hero = pinfo.defaultHero();
|
|
|
|
|
2023-09-28 18:43:04 +02:00
|
|
|
if(pset.hero != HeroTypeID::RANDOM && pinfo.hasCustomMainHero())
|
2017-07-20 06:08:49 +02:00
|
|
|
{
|
|
|
|
pset.hero = pinfo.mainCustomHeroId;
|
2023-09-28 00:04:05 +02:00
|
|
|
pset.heroNameTextId = pinfo.mainCustomHeroNameTextId;
|
2023-09-28 18:43:04 +02:00
|
|
|
pset.heroPortrait = HeroTypeID(pinfo.mainCustomHeroPortrait);
|
2017-07-20 06:08:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pset.handicap = PlayerSettings::NO_HANDICAP;
|
|
|
|
}
|
|
|
|
|
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-22 19:02:32 +02:00
|
|
|
Load::ProgressAccumulator progressTracker;
|
|
|
|
gameState->init(&mapService, &si, progressTracker, false);
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
ASSERT_NE(map, nullptr);
|
|
|
|
ASSERT_EQ(map->heroesOnMap.size(), 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void startTestBattle(const CGHeroInstance * attacker, const CGHeroInstance * defender)
|
|
|
|
{
|
|
|
|
const CGHeroInstance * heroes[2] = {attacker, defender};
|
|
|
|
const CArmedInstance * armedInstancies[2] = {attacker, defender};
|
|
|
|
|
|
|
|
int3 tile(4,4,0);
|
|
|
|
|
2022-09-25 09:33:56 +02:00
|
|
|
const auto & t = *gameCallback->getTile(tile);
|
2017-07-20 06:08:49 +02:00
|
|
|
|
2023-02-28 13:29:35 +02:00
|
|
|
auto terrain = t.terType->getId();
|
2023-07-25 21:36:45 +02:00
|
|
|
BattleField terType(0);
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
//send info about battles
|
|
|
|
|
|
|
|
BattleInfo * battle = BattleInfo::setupBattle(tile, terrain, terType, armedInstancies, heroes, false, nullptr);
|
|
|
|
|
|
|
|
BattleStart bs;
|
|
|
|
bs.info = battle;
|
2023-08-25 17:23:15 +02:00
|
|
|
ASSERT_EQ(gameState->currentBattles.size(), 0);
|
2017-07-20 06:08:49 +02:00
|
|
|
gameCallback->sendAndApply(&bs);
|
2023-08-25 17:23:15 +02:00
|
|
|
ASSERT_EQ(gameState->currentBattles.size(), 1);
|
2017-07-20 06:08:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<CGameState> gameState;
|
|
|
|
|
|
|
|
std::shared_ptr<GameCallbackMock> gameCallback;
|
|
|
|
|
|
|
|
MapServiceMock mapService;
|
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
|
|
|
ServicesMock services;
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
CMap * map;
|
|
|
|
};
|
|
|
|
|
|
|
|
//Issue #2765, Ghost Dragons can cast Age on Catapults
|
2024-01-03 02:26:15 +02:00
|
|
|
TEST_F(CGameStateTest, DISABLED_issue2765)
|
2017-07-20 06:08:49 +02:00
|
|
|
{
|
|
|
|
startTestGame();
|
|
|
|
|
|
|
|
CGHeroInstance * attacker = map->heroesOnMap[0];
|
|
|
|
CGHeroInstance * defender = map->heroesOnMap[1];
|
|
|
|
|
|
|
|
ASSERT_NE(attacker->tempOwner, defender->tempOwner);
|
|
|
|
|
|
|
|
{
|
|
|
|
CArtifactInstance * a = new CArtifactInstance();
|
|
|
|
a->artType = const_cast<CArtifact *>(ArtifactID(ArtifactID::BALLISTA).toArtifact());
|
|
|
|
|
|
|
|
NewArtifact na;
|
|
|
|
na.art = a;
|
|
|
|
gameCallback->sendAndApply(&na);
|
|
|
|
|
|
|
|
PutArtifact pack;
|
2023-10-24 16:32:09 +02:00
|
|
|
pack.al = ArtifactLocation(defender->id, ArtifactPosition::MACH1);
|
2017-07-20 06:08:49 +02:00
|
|
|
pack.art = a;
|
|
|
|
gameCallback->sendAndApply(&pack);
|
|
|
|
}
|
|
|
|
|
|
|
|
startTestBattle(attacker, defender);
|
|
|
|
|
|
|
|
{
|
|
|
|
battle::UnitInfo info;
|
2023-08-25 17:23:15 +02:00
|
|
|
info.id = gameState->currentBattles.front()->battleNextUnitId();
|
2017-07-20 06:08:49 +02:00
|
|
|
info.count = 1;
|
|
|
|
info.type = CreatureID(69);
|
|
|
|
info.side = BattleSide::ATTACKER;
|
2024-06-24 03:23:26 +02:00
|
|
|
info.position = gameState->currentBattles.front()->getAvailableHex(info.type, info.side);
|
2017-07-20 06:08:49 +02:00
|
|
|
info.summoned = false;
|
|
|
|
|
|
|
|
BattleUnitsChanged pack;
|
|
|
|
pack.changedStacks.emplace_back(info.id, UnitChanges::EOperation::ADD);
|
|
|
|
info.save(pack.changedStacks.back().data);
|
|
|
|
gameCallback->sendAndApply(&pack);
|
|
|
|
}
|
|
|
|
|
|
|
|
const CStack * att = nullptr;
|
|
|
|
const CStack * def = nullptr;
|
|
|
|
|
2023-08-25 17:23:15 +02:00
|
|
|
for(const CStack * s : gameState->currentBattles.front()->stacks)
|
2017-07-20 06:08:49 +02:00
|
|
|
{
|
2023-04-29 01:36:39 +02:00
|
|
|
if(s->unitType()->getId() == CreatureID::BALLISTA && s->unitSide() == BattleSide::DEFENDER)
|
2017-07-20 06:08:49 +02:00
|
|
|
def = s;
|
2023-04-29 01:36:39 +02:00
|
|
|
else if(s->unitType()->getId() == CreatureID(69) && s->unitSide() == BattleSide::ATTACKER)
|
2017-07-20 06:08:49 +02:00
|
|
|
att = s;
|
|
|
|
}
|
|
|
|
ASSERT_NE(att, nullptr);
|
|
|
|
ASSERT_NE(def, nullptr);
|
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
|
|
|
ASSERT_NE(att, def);
|
|
|
|
|
|
|
|
EXPECT_NE(att->getMyHero(), defender);
|
|
|
|
EXPECT_NE(def->getMyHero(), attacker);
|
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
|
|
|
EXPECT_EQ(att->getMyHero(), attacker) << att->nodeName();
|
|
|
|
EXPECT_EQ(def->getMyHero(), defender) << def->nodeName();
|
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
|
|
|
using namespace ::testing;
|
|
|
|
|
|
|
|
spells::ProblemMock problemMock;
|
|
|
|
// EXPECT_CALL(problemMock, add(_));
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
const CSpell * age = SpellID(SpellID::AGE).toSpell();
|
|
|
|
ASSERT_NE(age, nullptr);
|
2018-03-02 12:22:51 +02:00
|
|
|
|
|
|
|
spells::AbilityCaster caster(att, 3);
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
//here tested ballista, but this applied to all war machines
|
2023-08-25 17:23:15 +02:00
|
|
|
spells::BattleCast cast(gameState->currentBattles.front().get(), &caster, spells::Mode::PASSIVE, age);
|
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
|
|
|
spells::Target target;
|
|
|
|
target.emplace_back(def);
|
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
|
|
|
auto m = age->battleMechanics(&cast);
|
|
|
|
|
2021-02-20 03:57:50 +02:00
|
|
|
EXPECT_FALSE(m->canBeCastAt(target, problemMock));
|
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
|
|
|
|
|
|
|
EXPECT_TRUE(cast.castIfPossible(this, target));//should be possible, but with no effect (change to aimed cast check?)
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
EXPECT_TRUE(def->activeSpells().empty());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2024-01-03 02:26:15 +02:00
|
|
|
TEST_F(CGameStateTest, DISABLED_battleResurrection)
|
2017-07-20 06:08:49 +02:00
|
|
|
{
|
|
|
|
startTestGame();
|
|
|
|
|
|
|
|
CGHeroInstance * attacker = map->heroesOnMap[0];
|
|
|
|
CGHeroInstance * defender = map->heroesOnMap[1];
|
|
|
|
|
|
|
|
ASSERT_NE(attacker->tempOwner, defender->tempOwner);
|
|
|
|
|
|
|
|
attacker->setSecSkillLevel(SecondarySkill::EARTH_MAGIC, 3, true);
|
2018-12-20 23:42:31 +02:00
|
|
|
attacker->addSpellToSpellbook(SpellID::RESURRECTION);
|
2017-07-20 06:08:49 +02:00
|
|
|
attacker->setPrimarySkill(PrimarySkill::SPELL_POWER, 100, true);
|
|
|
|
attacker->setPrimarySkill(PrimarySkill::KNOWLEDGE, 20, true);
|
|
|
|
attacker->mana = attacker->manaLimit();
|
|
|
|
|
|
|
|
{
|
|
|
|
CArtifactInstance * a = new CArtifactInstance();
|
|
|
|
a->artType = const_cast<CArtifact *>(ArtifactID(ArtifactID::SPELLBOOK).toArtifact());
|
|
|
|
|
|
|
|
NewArtifact na;
|
|
|
|
na.art = a;
|
|
|
|
gameCallback->sendAndApply(&na);
|
|
|
|
|
|
|
|
PutArtifact pack;
|
2023-10-24 16:32:09 +02:00
|
|
|
pack.al = ArtifactLocation(attacker->id, ArtifactPosition::SPELLBOOK);
|
2017-07-20 06:08:49 +02:00
|
|
|
pack.art = a;
|
|
|
|
gameCallback->sendAndApply(&pack);
|
|
|
|
}
|
|
|
|
|
|
|
|
startTestBattle(attacker, defender);
|
|
|
|
|
2023-08-25 17:23:15 +02:00
|
|
|
uint32_t unitId = gameState->currentBattles.front()->battleNextUnitId();
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
{
|
|
|
|
battle::UnitInfo info;
|
|
|
|
info.id = unitId;
|
|
|
|
info.count = 10;
|
|
|
|
info.type = CreatureID(13);
|
|
|
|
info.side = BattleSide::ATTACKER;
|
2024-06-24 03:23:26 +02:00
|
|
|
info.position = gameState->currentBattles.front()->getAvailableHex(info.type, info.side);
|
2017-07-20 06:08:49 +02:00
|
|
|
info.summoned = false;
|
|
|
|
|
|
|
|
BattleUnitsChanged pack;
|
|
|
|
pack.changedStacks.emplace_back(info.id, UnitChanges::EOperation::ADD);
|
|
|
|
info.save(pack.changedStacks.back().data);
|
|
|
|
gameCallback->sendAndApply(&pack);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
battle::UnitInfo info;
|
2023-08-25 17:23:15 +02:00
|
|
|
info.id = gameState->currentBattles.front()->battleNextUnitId();
|
2017-07-20 06:08:49 +02:00
|
|
|
info.count = 10;
|
|
|
|
info.type = CreatureID(13);
|
|
|
|
info.side = BattleSide::DEFENDER;
|
2024-06-24 03:23:26 +02:00
|
|
|
info.position = gameState->currentBattles.front()->getAvailableHex(info.type, info.side);
|
2017-07-20 06:08:49 +02:00
|
|
|
info.summoned = false;
|
|
|
|
|
|
|
|
BattleUnitsChanged pack;
|
|
|
|
pack.changedStacks.emplace_back(info.id, UnitChanges::EOperation::ADD);
|
|
|
|
info.save(pack.changedStacks.back().data);
|
|
|
|
gameCallback->sendAndApply(&pack);
|
|
|
|
}
|
|
|
|
|
2023-08-25 17:23:15 +02:00
|
|
|
CStack * unit = gameState->currentBattles.front()->getStack(unitId);
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
ASSERT_NE(unit, nullptr);
|
|
|
|
|
2023-05-01 19:29:53 +02:00
|
|
|
int64_t damage = unit->getMaxHealth() + 1;
|
2017-07-20 06:08:49 +02:00
|
|
|
|
|
|
|
unit->damage(damage);
|
|
|
|
|
|
|
|
EXPECT_EQ(unit->getCount(), 9);
|
|
|
|
|
|
|
|
{
|
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 namespace ::testing;
|
|
|
|
|
|
|
|
spells::ProblemMock problemMock;
|
|
|
|
EXPECT_CALL(problemMock, add(_)).Times(AnyNumber()); //todo: do smth with problems of optional effects
|
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
const CSpell * spell = SpellID(SpellID::RESURRECTION).toSpell();
|
|
|
|
ASSERT_NE(spell, nullptr);
|
|
|
|
|
2023-08-25 17:23:15 +02:00
|
|
|
spells::BattleCast cast(gameState->currentBattles.front().get(), attacker, spells::Mode::HERO, spell);
|
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
|
|
|
|
|
|
|
spells::Target target;
|
|
|
|
target.emplace_back(unit);
|
|
|
|
|
|
|
|
auto m = spell->battleMechanics(&cast);
|
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
|
|
|
EXPECT_TRUE(m->canBeCast(problemMock));
|
2017-07-20 06:08:49 +02:00
|
|
|
|
2021-02-20 03:57:50 +02:00
|
|
|
EXPECT_TRUE(m->canBeCastAt(target, problemMock));
|
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
|
|
|
cast.cast(this, target);
|
|
|
|
//
|
|
|
|
// std::vector<std::string> expLog;
|
|
|
|
//
|
|
|
|
// EXPECT_THAT(problemMock.log, ContainerEq(expLog));
|
2017-07-20 06:08:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
EXPECT_EQ(unit->health.getCount(), 10);
|
|
|
|
EXPECT_EQ(unit->health.getResurrected(), 0);
|
|
|
|
}
|