diff --git a/source/tools/rmgen/api.cpp b/source/tools/rmgen/api.cpp index fc4e2bc320..fb414c19dc 100644 --- a/source/tools/rmgen/api.cpp +++ b/source/tools/rmgen/api.cpp @@ -23,8 +23,8 @@ JSFunctionSpec globalFunctions[] = { {"getHeight", getHeight, 2}, {"setHeight", setHeight, 3}, {"getMapSize", getMapSize, 0}, - {"randInt", randInt, 1}, - {"randFloat", randFloat, 0}, + {"randInt", randInt, 2}, + {"randFloat", randFloat, 1}, {"placeObject", placeObject, 4}, {"createArea", createArea, 3}, {"createObjectGroup", createObjectGroup, 3}, @@ -38,7 +38,7 @@ JSFunctionSpec globalFunctions[] = { void ValidateArgs(const char* types, JSContext* cx, uintN argc, jsval* argv, const char* function) { int num = strlen(types); if(argc != num) { - JS_ReportError(cx, "%s: expected %d arguments but got %d", function, num, argc); + JS_ReportError(cx, "%s: requires %d arguments but got %d", function, num, argc); } JSObject* obj; for(int i=0; i& retVec) { + // TODO: use a 2D array or hash set instead of a STL set for speed + if(!m->validT(x, y) || !constr->allows(m, x, y)) { return false; } diff --git a/source/tools/rmgen/convert.cpp b/source/tools/rmgen/convert.cpp index 0c2c948355..10e80792db 100644 --- a/source/tools/rmgen/convert.cpp +++ b/source/tools/rmgen/convert.cpp @@ -205,12 +205,15 @@ ObjectGroupPlacer* ParseObjectGroupPlacer(JSContext* cx, jsval val) { elements.resize(array.size()); for(int i=0; i maxCount) { + JS_ReportError(cx, "SimpleObject: minCount must be less than or equal to maxCount"); + } + if(minDistance > maxDistance) { + JS_ReportError(cx, "SimpleObject: minDistance must be less than or equal to maxDistance"); + } } SimpleGroup::Element::~Element() { @@ -20,11 +27,14 @@ SimpleGroup::Element::~Element() { bool SimpleGroup::Element::place(int cx, int cy, Map* m, int player, bool avoidSelf, Constraint* constr, vector& ret) { int failCount = 0; + int count = RandInt(minCount, maxCount); for(int i=0; im->size || y>m->size) { goto bad; diff --git a/source/tools/rmgen/simplegroup.h b/source/tools/rmgen/simplegroup.h index 7e7feeb9e4..b3686f9ac3 100644 --- a/source/tools/rmgen/simplegroup.h +++ b/source/tools/rmgen/simplegroup.h @@ -10,11 +10,12 @@ public: class Element { public: std::string type; - int count; - float distance; + int minCount, maxCount; + float minDistance, maxDistance; Element::Element(); - Element::Element(const std::string& type, int count, float distance); + Element::Element(const std::string& type, int minCount, int maxCount, + float minDistance, float maxDistance); Element::~Element(); bool place(int cx, int cy, class Map* m, int player, bool avoidSelf, diff --git a/source/tools/rmgen/smoothelevationpainter.cpp b/source/tools/rmgen/smoothelevationpainter.cpp index 2d2dabebb3..e80ed0a080 100644 --- a/source/tools/rmgen/smoothelevationpainter.cpp +++ b/source/tools/rmgen/smoothelevationpainter.cpp @@ -28,6 +28,8 @@ bool SmoothElevationPainter::checkInArea(Map* m, Area* a, int x, int y) { } void SmoothElevationPainter::paint(Map* m, Area* a) { + // TODO: Use a 2D array instead of STL maps and sets for speed + map saw; map dist;