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
|
|
|
|
|
|
2018-11-03 16:43:33 +01:00
|
|
|
#include "rules/simulation/TerrainModTranslator.h"
|
2018-10-27 13:13:45 +02:00
|
|
|
#include "stubs/common/stubcustom.h"
|
2018-11-03 16:43:33 +01:00
|
|
|
#include "stubs/rules/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;
|
|
|
|
|
|
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
|
|
|
{
|
2018-01-18 21:43:08 +01:00
|
|
|
WFMath::Point<3> pos(0, -1, 0);
|
2010-11-08 19:03:20 +00:00
|
|
|
WFMath::Quaternion orientation;
|
2010-11-08 18:49:37 +00:00
|
|
|
|
|
|
|
|
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";
|
2016-09-19 18:01:01 +02:00
|
|
|
TerrainModTranslator * titm = new TerrainModTranslator(mod);
|
|
|
|
|
Mercator::TerrainMod * tm1 = titm->parseData(pos, orientation);
|
2010-11-08 18:49:37 +00:00
|
|
|
assert(tm1 != 0);
|
|
|
|
|
|
2016-09-19 18:01:01 +02:00
|
|
|
// Re-parse the same data. Should create new instance.
|
|
|
|
|
Mercator::TerrainMod * tm2 = titm->parseData(pos, orientation);
|
2010-11-08 18:49:37 +00:00
|
|
|
assert(tm2 != 0);
|
2016-09-19 18:01:01 +02: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";
|
2016-09-19 18:01:01 +02:00
|
|
|
titm = new TerrainModTranslator(mod);
|
|
|
|
|
Mercator::TerrainMod * tm3 = titm->parseData(pos, orientation);
|
2010-11-08 18:49:37 +00:00
|
|
|
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";
|
2016-09-19 18:01:01 +02:00
|
|
|
titm = new TerrainModTranslator(mod);
|
|
|
|
|
Mercator::TerrainMod * tm4 = titm->parseData(pos, orientation);
|
2010-11-11 20:15:05 +00:00
|
|
|
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()
|
|
|
|
|
{
|
|
|
|
|
{
|
2016-09-19 18:01:01 +02:00
|
|
|
TerrainModTranslator * titm = new TerrainModTranslator(Atlas::Message::MapType());
|
2010-09-13 18:04:41 +01:00
|
|
|
delete titm;
|
|
|
|
|
}
|
2010-09-14 01:33:08 +01:00
|
|
|
|
|
|
|
|
// Call parsePosition with empty height data
|
|
|
|
|
{
|
2018-01-18 21:43:08 +01:00
|
|
|
WFMath::Point<3> pos(0, -1, 0);
|
2010-09-14 01:33:08 +01:00
|
|
|
|
|
|
|
|
MapType data;
|
2016-09-19 18:01:01 +02:00
|
|
|
float z = TerrainModTranslator::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
|
|
|
|
|
{
|
2018-01-18 21:43:08 +01:00
|
|
|
WFMath::Point<3> pos(0, -1, 0);
|
2010-09-14 01:33:08 +01:00
|
|
|
|
|
|
|
|
MapType data;
|
|
|
|
|
data["height"] = 1;
|
2016-09-19 18:01:01 +02:00
|
|
|
float z = TerrainModTranslator::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
|
|
|
|
|
{
|
2018-01-18 21:43:08 +01:00
|
|
|
WFMath::Point<3> pos(0, -1, 0);
|
2010-09-14 01:33:08 +01:00
|
|
|
|
|
|
|
|
MapType data;
|
|
|
|
|
data["height"] = 1.;
|
2016-09-19 18:01:01 +02:00
|
|
|
float z = TerrainModTranslator::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
|
|
|
|
|
{
|
2018-01-18 21:43:08 +01:00
|
|
|
WFMath::Point<3> pos(0, -1, 0);
|
2010-09-14 01:33:08 +01:00
|
|
|
|
|
|
|
|
MapType data;
|
|
|
|
|
data["height"] = "1.";
|
2016-09-19 18:01:01 +02:00
|
|
|
float z = TerrainModTranslator::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
|
|
|
|
|
{
|
2018-01-18 21:43:08 +01:00
|
|
|
WFMath::Point<3> pos(0, -1, 0);
|
2010-09-14 01:33:08 +01:00
|
|
|
|
|
|
|
|
MapType data;
|
2010-09-14 02:20:59 +01:00
|
|
|
data["heightoffset"] = 2;
|
2016-09-19 18:01:01 +02:00
|
|
|
float z = TerrainModTranslator::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
|
|
|
|
|
{
|
2018-01-18 21:43:08 +01:00
|
|
|
WFMath::Point<3> pos(0, -1, 0);
|
2010-09-14 01:33:08 +01:00
|
|
|
|
|
|
|
|
MapType data;
|
2010-09-14 02:20:59 +01:00
|
|
|
data["heightoffset"] = 2.;
|
2016-09-19 18:01:01 +02:00
|
|
|
float z = TerrainModTranslator::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
|
|
|
|
|
{
|
2018-01-18 21:43:08 +01:00
|
|
|
WFMath::Point<3> pos(0, -1, 0);
|
2010-09-14 01:33:08 +01:00
|
|
|
|
|
|
|
|
MapType data;
|
|
|
|
|
data["heightoffset"] = "1.";
|
2016-09-19 18:01:01 +02:00
|
|
|
float z = TerrainModTranslator::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
|
|
|
|
|
|
|
|
{
|
2016-09-19 18:01:01 +02:00
|
|
|
TerrainModTranslator * titm = new TerrainModTranslator(Atlas::Message::MapType());
|
2010-09-14 02:34:39 +01:00
|
|
|
delete titm;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-11-10 16:11:21 +00:00
|
|
|
// Call parseData with empty map
|
2010-09-14 02:34:39 +01:00
|
|
|
{
|
2016-09-19 18:01:01 +02:00
|
|
|
TerrainModTranslator * titm = new TerrainModTranslator(MapType());
|
2018-01-18 21:43:08 +01:00
|
|
|
WFMath::Point<3> pos(0, -1, 0);
|
2010-11-08 19:03:20 +00:00
|
|
|
WFMath::Quaternion orientation;
|
2010-09-14 02:34:39 +01:00
|
|
|
|
2016-09-19 18:01:01 +02:00
|
|
|
Mercator::TerrainMod* ret = titm->parseData(pos, orientation);
|
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
|
|
|
{
|
|
|
|
|
MapType mod;
|
|
|
|
|
MapType shape_desc;
|
|
|
|
|
shape_desc["type"] = "unknown_shape";
|
|
|
|
|
mod["shape"] = shape_desc;
|
2016-09-19 18:01:01 +02:00
|
|
|
|
|
|
|
|
TerrainModTranslator * titm = new TerrainModTranslator(mod);
|
2018-01-18 21:43:08 +01:00
|
|
|
WFMath::Point<3> pos(0, -1, 0);
|
2016-09-19 18:01:01 +02:00
|
|
|
WFMath::Quaternion orientation;
|
|
|
|
|
|
|
|
|
|
Mercator::TerrainMod* ret = titm->parseData(pos, orientation);
|
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
|
|
|
{
|
|
|
|
|
MapType mod;
|
|
|
|
|
MapType shape_desc;
|
|
|
|
|
shape_desc["type"] = "ball";
|
|
|
|
|
mod["shape"] = shape_desc;
|
2016-09-19 18:01:01 +02:00
|
|
|
|
|
|
|
|
TerrainModTranslator * titm = new TerrainModTranslator(mod);
|
2018-01-18 21:43:08 +01:00
|
|
|
WFMath::Point<3> pos(0, -1, 0);
|
2016-09-19 18:01:01 +02:00
|
|
|
WFMath::Quaternion orientation;
|
|
|
|
|
|
|
|
|
|
Mercator::TerrainMod* ret = titm->parseData(pos, orientation);
|
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
|
|
|
{
|
|
|
|
|
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";
|
2016-09-19 18:01:01 +02:00
|
|
|
|
|
|
|
|
TerrainModTranslator * titm = new TerrainModTranslator(mod);
|
2018-01-18 21:43:08 +01:00
|
|
|
WFMath::Point<3> pos(0, -1, 0);
|
2016-09-19 18:01:01 +02:00
|
|
|
WFMath::Quaternion orientation;
|
|
|
|
|
|
|
|
|
|
Mercator::TerrainMod* ret = titm->parseData(pos, orientation);
|
2010-09-14 21:47:31 +01:00
|
|
|
assert(ret);
|
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
|
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";
|
2016-09-19 18:01:01 +02:00
|
|
|
|
|
|
|
|
TerrainModTranslator * titm = new TerrainModTranslator(mod);
|
2018-01-18 21:43:08 +01:00
|
|
|
WFMath::Point<3> pos(0, -1, 0);
|
2016-09-19 18:01:01 +02:00
|
|
|
WFMath::Quaternion orientation(0,0,0,1);
|
|
|
|
|
|
|
|
|
|
Mercator::TerrainMod* ret = titm->parseData(pos, orientation);
|
2010-11-08 22:31:49 +00:00
|
|
|
assert(ret);
|
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
|
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";
|
2016-09-19 18:01:01 +02:00
|
|
|
|
|
|
|
|
TerrainModTranslator * titm = new TerrainModTranslator(mod);
|
2018-01-18 21:43:08 +01:00
|
|
|
WFMath::Point<3> pos(0, -1, 0);
|
2016-09-19 18:01:01 +02:00
|
|
|
WFMath::Quaternion orientation;
|
|
|
|
|
|
|
|
|
|
Mercator::TerrainMod* ret = titm->parseData(pos, orientation);
|
2010-11-08 22:24:16 +00:00
|
|
|
assert(ret);
|
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
|
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";
|
2016-09-19 18:01:01 +02:00
|
|
|
|
|
|
|
|
TerrainModTranslator * titm = new TerrainModTranslator(mod);
|
2018-01-18 21:43:08 +01:00
|
|
|
WFMath::Point<3> pos(0, -1, 0);
|
2016-09-19 18:01:01 +02:00
|
|
|
WFMath::Quaternion orientation;
|
|
|
|
|
|
|
|
|
|
Mercator::TerrainMod* ret = titm->parseData(pos, orientation);
|
2010-11-08 22:24:16 +00:00
|
|
|
assert(ret);
|
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
|
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";
|
2016-09-19 18:01:01 +02:00
|
|
|
|
|
|
|
|
TerrainModTranslator * titm = new TerrainModTranslator(mod);
|
2018-01-18 21:43:08 +01:00
|
|
|
WFMath::Point<3> pos(0, -1, 0);
|
2016-09-19 18:01:01 +02:00
|
|
|
WFMath::Quaternion orientation;
|
|
|
|
|
|
|
|
|
|
Mercator::TerrainMod* ret = titm->parseData(pos, orientation);
|
2010-09-14 21:47:31 +01:00
|
|
|
assert(!ret);
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
}
|