1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00
vcmi/test/map/CMapEditManagerTest.cpp

169 lines
5.9 KiB
C++
Raw Normal View History

/*
* CMapEditManagerTest.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 "../lib/filesystem/ResourceID.h"
#include "../lib/mapping/CMapService.h"
#include "../lib/mapping/CMap.h"
#include "../lib/JsonNode.h"
#include "../lib/mapping/CMapEditManager.h"
#include "../lib/int3.h"
#include "../lib/CRandomGenerator.h"
#include "../lib/VCMI_Lib.h"
2017-06-14 10:56:35 +02:00
TEST(MapManager, DrawTerrain_Type)
{
try
{
auto map = make_unique<CMap>();
2015-08-11 21:50:08 +02:00
map->width = 52;
map->height = 52;
map->initTerrain();
auto editManager = map->getEditManager();
editManager->clearTerrain();
// 1x1 Blow up
editManager->getTerrainSelection().select(int3(5, 5, 0));
editManager->drawTerrain(Terrain("grass"));
static const int3 squareCheck[] = { int3(5,5,0), int3(5,4,0), int3(4,4,0), int3(4,5,0) };
for(int i = 0; i < ARRAY_COUNT(squareCheck); ++i)
{
EXPECT_EQ(map->getTile(squareCheck[i]).terType, Terrain("grass"));
}
// Concat to square
editManager->getTerrainSelection().select(int3(6, 5, 0));
editManager->drawTerrain(Terrain("grass"));
EXPECT_EQ(map->getTile(int3(6, 4, 0)).terType, Terrain("grass"));
editManager->getTerrainSelection().select(int3(6, 5, 0));
editManager->drawTerrain(Terrain("lava"));
EXPECT_EQ(map->getTile(int3(4, 4, 0)).terType, Terrain("grass"));
EXPECT_EQ(map->getTile(int3(7, 4, 0)).terType, Terrain("lava"));
// Special case water,rock
editManager->getTerrainSelection().selectRange(MapRect(int3(10, 10, 0), 10, 5));
editManager->drawTerrain(Terrain("grass"));
editManager->getTerrainSelection().selectRange(MapRect(int3(15, 17, 0), 10, 5));
editManager->drawTerrain(Terrain("grass"));
editManager->getTerrainSelection().select(int3(21, 16, 0));
editManager->drawTerrain(Terrain("grass"));
EXPECT_EQ(map->getTile(int3(20, 15, 0)).terType, Terrain("grass"));
// Special case non water,rock
static const int3 diagonalCheck[] = { int3(31,42,0), int3(32,42,0), int3(32,43,0), int3(33,43,0), int3(33,44,0),
int3(34,44,0), int3(34,45,0), int3(35,45,0), int3(35,46,0), int3(36,46,0),
int3(36,47,0), int3(37,47,0)};
for(int i = 0; i < ARRAY_COUNT(diagonalCheck); ++i)
{
editManager->getTerrainSelection().select(diagonalCheck[i]);
}
editManager->drawTerrain(Terrain("grass"));
EXPECT_EQ(map->getTile(int3(35, 44, 0)).terType, Terrain("water"));
// Rock case
editManager->getTerrainSelection().selectRange(MapRect(int3(1, 1, 1), 15, 15));
editManager->drawTerrain(Terrain("subterra"));
std::vector<int3> vec({ int3(6, 6, 1), int3(7, 6, 1), int3(8, 6, 1), int3(5, 7, 1), int3(6, 7, 1), int3(7, 7, 1),
int3(8, 7, 1), int3(4, 8, 1), int3(5, 8, 1), int3(6, 8, 1)});
editManager->getTerrainSelection().setSelection(vec);
editManager->drawTerrain(Terrain("rock"));
EXPECT_TRUE(!map->getTile(int3(5, 6, 1)).terType.isPassable() || !map->getTile(int3(7, 8, 1)).terType.isPassable());
2015-08-11 21:50:08 +02:00
//todo: add checks here and enable, also use smaller size
#if 0
// next check
auto map2 = make_unique<CMap>();
map2->width = 128;
map2->height = 128;
map2->initTerrain();
auto editManager2 = map2->getEditManager();
editManager2->getTerrainSelection().selectRange(MapRect(int3(0, 0, 1), 128, 128));
editManager2->drawTerrain(CTerrainType("subterra"));
std::vector<int3> selection({ int3(95, 43, 1), int3(95, 44, 1), int3(94, 45, 1), int3(95, 45, 1), int3(96, 45, 1),
int3(93, 46, 1), int3(94, 46, 1), int3(95, 46, 1), int3(96, 46, 1), int3(97, 46, 1),
int3(98, 46, 1), int3(99, 46, 1)});
editManager2->getTerrainSelection().setSelection(selection);
editManager2->drawTerrain(CTerrainType("rock"));
2015-08-11 21:50:08 +02:00
#endif // 0
}
catch(const std::exception & e)
{
FAIL()<<e.what();
2015-08-11 21:50:08 +02:00
throw;
}
}
TEST(MapManager, DrawTerrain_View)
{
try
{
2017-06-04 21:42:48 +02:00
const ResourceID testMap("test/TerrainViewTest", EResType::MAP);
// Load maps and json config
Spells configuration version 2 (effect-based) * Indirect spell effects loading * Json serializer improvements * spell->canBeCastAt do not allow useless cast for any spell * Added proxy caster class for spell-created obstacles * Handle damage from spell-created obstacles inside mechanics * Experimental GameState integration/regression tests * Ignore mod settings and load only "vcmi" mod when running tests * fixed https://bugs.vcmi.eu/view.php?id=2765 (with tests) * Huge improvements of BattleAI regarding spell casts * AI can cast almost any combat spell except TELEPORT, SACRIFICE and obstacle placement spells. * Possible fix for https://bugs.vcmi.eu/view.php?id=1811 * CStack factored out to several classes * [Battle] Allowed RETURN_AFTER_STRIKE effect on server side to be optional * [Battle] Allowed BattleAction have multiple destinations * [Spells] Converted limit|immunity to target condition * [Spells] Use partial configuration reload for backward compatibility handling * [Tests] Started tests for CUnitState * Partial fixes of fire shield effect * [Battle] Do HP calculations in 64 bits * [BattleAI] Use threading for spell cast evaluation * [BattleAI] Made AI be able to evaluate modified turn order (on hypothetical battle state) * Implemented https://bugs.vcmi.eu/view.php?id=2811 * plug rare freeze when hypnotized unit shots vertically * Correctly apply ONLY_MELEE_FIGHT / ONLY_DISTANCE_FIGHT for unit damage, attack & defense * [BattleAI] Try to not waste a cast if battle is actually won already * Extended JsonSerializeFormat API * fixed https://bugs.vcmi.eu/view.php?id=2847 * Any unit effect can be now chained (not only damage like Chain Lightning) ** only damage effect for now actually uses "chainFactor" * Possible quick fix for https://bugs.vcmi.eu/view.php?id=2860
2017-07-20 06:08:49 +02:00
CMapService mapService;
const auto originalMap = mapService.loadMap(testMap);
auto map = mapService.loadMap(testMap);
// Validate edit manager
auto editManager = map->getEditManager();
CRandomGenerator gen;
const JsonNode viewNode(ResourceID("test/terrainViewMappings", EResType::TEXT));
const auto & mappingsNode = viewNode["mappings"].Vector();
for (const auto & node : mappingsNode)
{
// Get terrain group and id
const auto & patternStr = node["pattern"].String();
std::vector<std::string> patternParts;
boost::split(patternParts, patternStr, boost::is_any_of("."));
if(patternParts.size() != 2) throw std::runtime_error("A pattern should consist of two parts, the group and the id. Continue with next pattern.");
const auto & groupStr = patternParts[0];
const auto & id = patternParts[1];
// Get mapping range
const auto & pattern = VLC->terviewh->getTerrainViewPatternById(groupStr, id);
const auto & mapping = (*pattern).mapping;
const auto & positionsNode = node["pos"].Vector();
for (const auto & posNode : positionsNode)
{
const auto & posVector = posNode.Vector();
if(posVector.size() != 3) throw std::runtime_error("A position should consist of three values x,y,z. Continue with next position.");
int3 pos((si32)posVector[0].Float(), (si32)posVector[1].Float(), (si32)posVector[2].Float());
const auto & originalTile = originalMap->getTile(pos);
editManager->getTerrainSelection().selectRange(MapRect(pos, 1, 1));
editManager->drawTerrain(originalTile.terType, &gen);
const auto & tile = map->getTile(pos);
bool isInRange = false;
for(const auto & range : mapping)
{
if(tile.terView >= range.first && tile.terView <= range.second)
{
isInRange = true;
break;
}
}
EXPECT_TRUE(isInRange);
2016-08-11 10:06:06 +02:00
if(!isInRange)
FAIL()<<("No or invalid pattern found for current position.");
}
}
}
catch(const std::exception & e)
{
FAIL()<<e.what();
2015-08-11 21:50:08 +02:00
throw;
}
}