2010-09-13 18:04:41 +01:00
|
|
|
// Cyphesis Online RPG Server and AI Engine
|
|
|
|
|
// Copyright (C) 2009 Alistair Riddoch
|
|
|
|
|
//
|
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
|
// the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
//
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
|
// along with this program; if not, write to the Free Software Foundation,
|
|
|
|
|
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
|
|
|
|
|
|
2011-02-15 09:30:46 +00:00
|
|
|
#ifdef NDEBUG
|
|
|
|
|
#undef NDEBUG
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef DEBUG
|
|
|
|
|
#define DEBUG
|
|
|
|
|
#endif
|
|
|
|
|
|
2011-01-06 20:55:27 +00:00
|
|
|
#include "rulesets/TerrainModTranslator.h"
|
2014-08-26 21:05:18 +02:00
|
|
|
#include "stubs/common/stubCustom.h"
|
|
|
|
|
#include "stubs/modules/stubLocation.h"
|
2010-09-13 18:04:41 +01:00
|
|
|
|
2010-11-08 19:03:20 +00:00
|
|
|
#include <wfmath/quaternion.h>
|
2010-09-14 01:33:08 +01:00
|
|
|
|
2010-09-13 18:04:41 +01:00
|
|
|
#include <cassert>
|
|
|
|
|
|
2010-09-14 17:25:42 +01:00
|
|
|
using Atlas::Message::Element;
|
|
|
|
|
using Atlas::Message::ListType;
|
2010-09-14 01:33:08 +01:00
|
|
|
using Atlas::Message::MapType;
|
|
|
|
|
|
2011-01-06 19:01:37 +00:00
|
|
|
class TestTerrainModTranslator : public TerrainModTranslator
|
2010-09-13 18:04:41 +01:00
|
|
|
{
|
|
|
|
|
public:
|
2011-01-06 19:01:37 +00:00
|
|
|
TestTerrainModTranslator() : TerrainModTranslator() { }
|
2010-09-13 18:04:41 +01:00
|
|
|
|
2011-10-03 22:12:45 +01:00
|
|
|
static float test_parsePosition(const WFMath::Point<3> & pos,
|
|
|
|
|
const MapType& modElement)
|
2010-09-14 01:33:08 +01:00
|
|
|
{
|
2010-11-03 15:04:17 +00:00
|
|
|
return parsePosition(pos, modElement);
|
2010-09-14 01:33:08 +01:00
|
|
|
}
|
2010-09-13 18:04:41 +01:00
|
|
|
};
|
|
|
|
|
|
2010-11-08 18:49:37 +00:00
|
|
|
static int test_reparse()
|
|
|
|
|
{
|
2010-11-10 16:11:21 +00:00
|
|
|
// Call parseData with polygon shape and valid points
|
2010-11-08 18:49:37 +00:00
|
|
|
{
|
2011-01-06 19:01:37 +00:00
|
|
|
TerrainModTranslator * titm = new TerrainModTranslator;
|
2010-11-08 19:03:20 +00:00
|
|
|
WFMath::Point<3> pos(0,0,-1);
|
|
|
|
|
WFMath::Quaternion orientation;
|
2010-11-08 18:49:37 +00:00
|
|
|
bool ret;
|
|
|
|
|
|
|
|
|
|
MapType mod;
|
|
|
|
|
MapType shape_desc;
|
|
|
|
|
shape_desc["type"] = "polygon";
|
|
|
|
|
shape_desc["points"] = ListType(3, ListType(2, 1.));
|
|
|
|
|
mod["shape"] = shape_desc;
|
2010-11-11 12:00:31 +00:00
|
|
|
mod["type"] = "levelmod";
|
2010-11-10 16:11:21 +00:00
|
|
|
ret = titm->parseData(pos, orientation, mod);
|
2010-11-08 18:49:37 +00:00
|
|
|
assert(ret);
|
|
|
|
|
Mercator::TerrainMod * tm1 = titm->getModifier();
|
|
|
|
|
assert(tm1 != 0);
|
|
|
|
|
|
|
|
|
|
// Re-parse the same data. Should update the mod in place.
|
2010-11-10 16:11:21 +00:00
|
|
|
ret = titm->parseData(pos, orientation, mod);
|
2010-11-08 18:49:37 +00:00
|
|
|
assert(ret);
|
|
|
|
|
Mercator::TerrainMod * tm2 = titm->getModifier();
|
|
|
|
|
assert(tm2 != 0);
|
2010-11-11 13:32:44 +00:00
|
|
|
assert(tm2 == tm1);
|
2010-11-08 18:49:37 +00:00
|
|
|
|
|
|
|
|
// Change it to 2D ball shape. This requires a new mod.
|
|
|
|
|
shape_desc["type"] = "ball";
|
|
|
|
|
shape_desc["radius"] = 1.f;
|
|
|
|
|
shape_desc["position"] = ListType(2, 1.);
|
|
|
|
|
mod["shape"] = shape_desc;
|
2010-11-11 12:00:31 +00:00
|
|
|
mod["type"] = "levelmod";
|
2010-11-10 16:11:21 +00:00
|
|
|
ret = titm->parseData(pos, orientation, mod);
|
2010-11-08 18:49:37 +00:00
|
|
|
assert(ret);
|
|
|
|
|
Mercator::TerrainMod * tm3 = titm->getModifier();
|
|
|
|
|
assert(tm3 != 0);
|
2010-11-11 13:32:44 +00:00
|
|
|
assert(tm3 != tm1);
|
2010-11-08 18:49:37 +00:00
|
|
|
|
2010-11-11 20:15:05 +00:00
|
|
|
// Change it to an adjustmod. This requires a new mod
|
|
|
|
|
mod["type"] = "adjustmod";
|
|
|
|
|
ret = titm->parseData(pos, orientation, mod);
|
|
|
|
|
assert(ret);
|
|
|
|
|
Mercator::TerrainMod * tm4 = titm->getModifier();
|
|
|
|
|
assert(tm4 != 0);
|
|
|
|
|
assert(tm4 != tm1);
|
|
|
|
|
|
2010-11-08 18:49:37 +00:00
|
|
|
delete titm;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-13 18:04:41 +01:00
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
{
|
2011-01-06 19:01:37 +00:00
|
|
|
TerrainModTranslator * titm = new TestTerrainModTranslator;
|
2010-09-13 18:04:41 +01:00
|
|
|
delete titm;
|
|
|
|
|
}
|
2010-09-14 01:33:08 +01:00
|
|
|
|
|
|
|
|
// Call parsePosition with empty height data
|
|
|
|
|
{
|
2010-11-08 19:03:20 +00:00
|
|
|
WFMath::Point<3> pos(0,0,-1);
|
2010-09-14 01:33:08 +01:00
|
|
|
|
|
|
|
|
MapType data;
|
2011-01-06 19:01:37 +00:00
|
|
|
float z = TestTerrainModTranslator::test_parsePosition(pos, data);
|
2010-11-04 16:18:18 +00:00
|
|
|
assert(z < 0);
|
2010-09-14 01:33:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Call parsePosition with int height data
|
|
|
|
|
{
|
2010-11-08 19:03:20 +00:00
|
|
|
WFMath::Point<3> pos(0,0,-1);
|
2010-09-14 01:33:08 +01:00
|
|
|
|
|
|
|
|
MapType data;
|
|
|
|
|
data["height"] = 1;
|
2011-01-06 19:01:37 +00:00
|
|
|
float z = TestTerrainModTranslator::test_parsePosition(pos, data);
|
2010-11-04 16:18:18 +00:00
|
|
|
assert(z > 0);
|
2010-09-14 01:33:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Call parsePosition with float height data
|
|
|
|
|
{
|
2010-11-08 19:03:20 +00:00
|
|
|
WFMath::Point<3> pos(0,0,-1);
|
2010-09-14 01:33:08 +01:00
|
|
|
|
|
|
|
|
MapType data;
|
|
|
|
|
data["height"] = 1.;
|
2011-01-06 19:01:37 +00:00
|
|
|
float z = TestTerrainModTranslator::test_parsePosition(pos, data);
|
2010-11-04 16:18:18 +00:00
|
|
|
assert(z > 0);
|
2010-09-14 01:33:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Call parsePosition with bad (string) height data
|
|
|
|
|
{
|
2010-11-08 19:03:20 +00:00
|
|
|
WFMath::Point<3> pos(0,0,-1);
|
2010-09-14 01:33:08 +01:00
|
|
|
|
|
|
|
|
MapType data;
|
|
|
|
|
data["height"] = "1.";
|
2011-01-06 19:01:37 +00:00
|
|
|
float z = TestTerrainModTranslator::test_parsePosition(pos, data);
|
2010-11-04 16:18:18 +00:00
|
|
|
assert(z < 0);
|
2010-09-14 01:33:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Call parsePosition with int heightoffset data
|
|
|
|
|
{
|
2010-11-08 19:03:20 +00:00
|
|
|
WFMath::Point<3> pos(0,0,-1);
|
2010-09-14 01:33:08 +01:00
|
|
|
|
|
|
|
|
MapType data;
|
2010-09-14 02:20:59 +01:00
|
|
|
data["heightoffset"] = 2;
|
2011-01-06 19:01:37 +00:00
|
|
|
float z = TestTerrainModTranslator::test_parsePosition(pos, data);
|
2010-11-04 16:18:18 +00:00
|
|
|
assert(z > 0);
|
2010-09-14 01:33:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Call parsePosition with float heightoffset data
|
|
|
|
|
{
|
2010-11-08 19:03:20 +00:00
|
|
|
WFMath::Point<3> pos(0,0,-1);
|
2010-09-14 01:33:08 +01:00
|
|
|
|
|
|
|
|
MapType data;
|
2010-09-14 02:20:59 +01:00
|
|
|
data["heightoffset"] = 2.;
|
2011-01-06 19:01:37 +00:00
|
|
|
float z = TestTerrainModTranslator::test_parsePosition(pos, data);
|
2010-11-04 16:18:18 +00:00
|
|
|
assert(z > 0);
|
2010-09-14 01:33:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Call parsePosition with bad (string) heightoffset data
|
|
|
|
|
{
|
2010-11-08 19:03:20 +00:00
|
|
|
WFMath::Point<3> pos(0,0,-1);
|
2010-09-14 01:33:08 +01:00
|
|
|
|
|
|
|
|
MapType data;
|
|
|
|
|
data["heightoffset"] = "1.";
|
2011-01-06 19:01:37 +00:00
|
|
|
float z = TestTerrainModTranslator::test_parsePosition(pos, data);
|
2010-11-04 16:18:18 +00:00
|
|
|
assert(z < 0);
|
2010-09-14 01:33:08 +01:00
|
|
|
}
|
|
|
|
|
|
2010-09-14 17:25:42 +01:00
|
|
|
////////////////////// Concrete classes ///////////////////////////
|
2010-09-14 02:34:39 +01:00
|
|
|
|
|
|
|
|
{
|
2011-01-06 19:01:37 +00:00
|
|
|
TerrainModTranslator * titm = new TerrainModTranslator;
|
2010-09-14 02:34:39 +01:00
|
|
|
delete titm;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2011-01-06 19:01:37 +00:00
|
|
|
TerrainModTranslator * titm = new TerrainModTranslator;
|
2010-09-14 02:34:39 +01:00
|
|
|
assert(titm->getModifier() == 0);
|
|
|
|
|
delete titm;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-10 16:11:21 +00:00
|
|
|
// Call parseData with empty map
|
2010-09-14 02:34:39 +01:00
|
|
|
{
|
2011-01-06 19:01:37 +00:00
|
|
|
TerrainModTranslator * titm = new TerrainModTranslator;
|
2010-11-08 19:03:20 +00:00
|
|
|
WFMath::Point<3> pos(0,0,-1);
|
|
|
|
|
WFMath::Quaternion orientation;
|
2010-09-14 02:34:39 +01:00
|
|
|
|
|
|
|
|
MapType data;
|
2010-11-10 16:11:21 +00:00
|
|
|
bool ret = titm->parseData(pos, orientation, data);
|
2010-09-14 17:25:42 +01:00
|
|
|
assert(!ret);
|
|
|
|
|
|
|
|
|
|
delete titm;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-10 16:11:21 +00:00
|
|
|
// Call parseData with unknown shape
|
2010-09-14 17:25:42 +01:00
|
|
|
{
|
2011-01-06 19:01:37 +00:00
|
|
|
TerrainModTranslator * titm = new TerrainModTranslator;
|
2010-11-08 19:03:20 +00:00
|
|
|
WFMath::Point<3> pos(0,0,-1);
|
|
|
|
|
WFMath::Quaternion orientation;
|
2010-09-14 17:25:42 +01:00
|
|
|
|
|
|
|
|
MapType mod;
|
|
|
|
|
MapType shape_desc;
|
|
|
|
|
shape_desc["type"] = "unknown_shape";
|
|
|
|
|
mod["shape"] = shape_desc;
|
2010-11-10 16:11:21 +00:00
|
|
|
bool ret = titm->parseData(pos, orientation, mod);
|
2010-09-14 17:25:42 +01:00
|
|
|
assert(!ret);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
delete titm;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-10 16:11:21 +00:00
|
|
|
// Call parseData with ball shape
|
2010-09-14 17:25:42 +01:00
|
|
|
{
|
2011-01-06 19:01:37 +00:00
|
|
|
TerrainModTranslator * titm = new TerrainModTranslator;
|
2010-11-08 19:03:20 +00:00
|
|
|
WFMath::Point<3> pos(0,0,-1);
|
|
|
|
|
WFMath::Quaternion orientation;
|
2010-09-14 17:25:42 +01:00
|
|
|
|
|
|
|
|
MapType mod;
|
|
|
|
|
MapType shape_desc;
|
|
|
|
|
shape_desc["type"] = "ball";
|
|
|
|
|
mod["shape"] = shape_desc;
|
2010-11-10 16:11:21 +00:00
|
|
|
bool ret = titm->parseData(pos, orientation, mod);
|
2010-09-14 17:25:42 +01:00
|
|
|
assert(!ret);
|
|
|
|
|
|
|
|
|
|
delete titm;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-10 16:11:21 +00:00
|
|
|
// Call parseData with ball shape and valid ball params
|
2010-09-14 21:47:31 +01:00
|
|
|
{
|
2011-01-06 19:01:37 +00:00
|
|
|
TerrainModTranslator * titm = new TerrainModTranslator;
|
2010-11-08 19:03:20 +00:00
|
|
|
WFMath::Point<3> pos(0,0,-1);
|
|
|
|
|
WFMath::Quaternion orientation;
|
2010-09-14 21:47:31 +01:00
|
|
|
|
|
|
|
|
MapType mod;
|
|
|
|
|
MapType shape_desc;
|
|
|
|
|
shape_desc["type"] = "ball";
|
|
|
|
|
shape_desc["radius"] = 1.f;
|
2010-11-02 11:08:57 +00:00
|
|
|
shape_desc["position"] = ListType(2, 1.);
|
2010-09-14 21:47:31 +01:00
|
|
|
mod["shape"] = shape_desc;
|
2010-11-11 12:00:31 +00:00
|
|
|
mod["type"] = "levelmod";
|
2010-11-10 16:11:21 +00:00
|
|
|
bool ret = titm->parseData(pos, orientation, mod);
|
2010-09-14 21:47:31 +01:00
|
|
|
assert(ret);
|
|
|
|
|
assert(titm->getModifier() != 0);
|
|
|
|
|
|
|
|
|
|
delete titm;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-10 16:11:21 +00:00
|
|
|
// Call parseData with ball shape and valid ball and orientation
|
2010-11-08 22:31:49 +00:00
|
|
|
{
|
2011-01-06 19:01:37 +00:00
|
|
|
TerrainModTranslator * titm = new TerrainModTranslator;
|
2010-11-08 22:31:49 +00:00
|
|
|
WFMath::Point<3> pos(0,0,-1);
|
|
|
|
|
WFMath::Quaternion orientation(0,0,0,1);
|
|
|
|
|
|
|
|
|
|
MapType mod;
|
|
|
|
|
MapType shape_desc;
|
|
|
|
|
shape_desc["type"] = "ball";
|
|
|
|
|
shape_desc["radius"] = 1.f;
|
|
|
|
|
shape_desc["position"] = ListType(2, 1.);
|
|
|
|
|
mod["shape"] = shape_desc;
|
2010-11-11 12:00:31 +00:00
|
|
|
mod["type"] = "levelmod";
|
2010-11-10 16:11:21 +00:00
|
|
|
bool ret = titm->parseData(pos, orientation, mod);
|
2010-11-08 22:31:49 +00:00
|
|
|
assert(ret);
|
|
|
|
|
assert(titm->getModifier() != 0);
|
|
|
|
|
|
|
|
|
|
delete titm;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-10 16:11:21 +00:00
|
|
|
// Call parseData with polygon shape and valid polygon params
|
2010-11-08 22:24:16 +00:00
|
|
|
{
|
2011-01-06 19:01:37 +00:00
|
|
|
TerrainModTranslator * titm = new TerrainModTranslator;
|
2010-11-08 22:24:16 +00:00
|
|
|
WFMath::Point<3> pos(0,0,-1);
|
|
|
|
|
WFMath::Quaternion orientation;
|
|
|
|
|
|
|
|
|
|
MapType mod;
|
|
|
|
|
MapType shape_desc;
|
|
|
|
|
shape_desc["type"] = "polygon";
|
|
|
|
|
shape_desc["points"] = ListType(3, ListType(2, 1.));
|
|
|
|
|
mod["shape"] = shape_desc;
|
2010-11-11 12:00:31 +00:00
|
|
|
mod["type"] = "levelmod";
|
2010-11-10 16:11:21 +00:00
|
|
|
bool ret = titm->parseData(pos, orientation, mod);
|
2010-11-08 22:24:16 +00:00
|
|
|
assert(ret);
|
|
|
|
|
assert(titm->getModifier() != 0);
|
|
|
|
|
|
|
|
|
|
delete titm;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-10 16:11:21 +00:00
|
|
|
// Call parseData with rotbox shape and valid rotbox params
|
2010-11-08 22:24:16 +00:00
|
|
|
{
|
2011-01-06 19:01:37 +00:00
|
|
|
TerrainModTranslator * titm = new TerrainModTranslator;
|
2010-11-08 22:24:16 +00:00
|
|
|
WFMath::Point<3> pos(0,0,-1);
|
|
|
|
|
WFMath::Quaternion orientation;
|
|
|
|
|
|
|
|
|
|
MapType mod;
|
|
|
|
|
MapType shape_desc;
|
|
|
|
|
shape_desc["type"] = "rotbox";
|
|
|
|
|
shape_desc["point"] = ListType(2, 1.);
|
|
|
|
|
shape_desc["size"] = ListType(2, 1.);
|
|
|
|
|
mod["shape"] = shape_desc;
|
2010-11-11 12:00:31 +00:00
|
|
|
mod["type"] = "levelmod";
|
2010-11-10 16:11:21 +00:00
|
|
|
bool ret = titm->parseData(pos, orientation, mod);
|
2010-11-08 22:24:16 +00:00
|
|
|
assert(ret);
|
|
|
|
|
assert(titm->getModifier() != 0);
|
|
|
|
|
|
|
|
|
|
delete titm;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-10 16:11:21 +00:00
|
|
|
// Call parseData with ball shape and invalid ball params
|
2010-09-14 21:47:31 +01:00
|
|
|
{
|
2011-01-06 19:01:37 +00:00
|
|
|
TerrainModTranslator * titm = new TerrainModTranslator;
|
2010-11-08 19:03:20 +00:00
|
|
|
WFMath::Point<3> pos(0,0,-1);
|
|
|
|
|
WFMath::Quaternion orientation;
|
2010-09-14 21:47:31 +01:00
|
|
|
|
|
|
|
|
MapType mod;
|
|
|
|
|
MapType shape_desc;
|
|
|
|
|
shape_desc["type"] = "ball";
|
|
|
|
|
shape_desc["radius"] = 1.f;
|
|
|
|
|
shape_desc["position"] = ListType(3, "1");
|
|
|
|
|
mod["shape"] = shape_desc;
|
2010-11-11 12:00:31 +00:00
|
|
|
mod["type"] = "levelmod";
|
2010-11-10 16:11:21 +00:00
|
|
|
bool ret = titm->parseData(pos, orientation, mod);
|
2010-09-14 21:47:31 +01:00
|
|
|
assert(!ret);
|
|
|
|
|
assert(titm->getModifier() == 0);
|
|
|
|
|
|
|
|
|
|
delete titm;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-08 18:49:37 +00:00
|
|
|
return test_reparse();
|
2010-09-13 18:04:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// stubs
|
|
|
|
|
|
|
|
|
|
#include "common/log.h"
|
|
|
|
|
|
|
|
|
|
void log(LogLevel lvl, const std::string & msg)
|
|
|
|
|
{
|
|
|
|
|
}
|