diff --git a/binaries/data/mods/public/gui/gamesetup/gamesetup.js b/binaries/data/mods/public/gui/gamesetup/gamesetup.js
index 0a55bf8d33..95f3c4af5e 100644
--- a/binaries/data/mods/public/gui/gamesetup/gamesetup.js
+++ b/binaries/data/mods/public/gui/gamesetup/gamesetup.js
@@ -1,8 +1,8 @@
////////////////////////////////////////////////////////////////////////////////////////////////
// Constants
// TODO: Move some of these into common location (other scripts may need)
-const MAP_SIZES_TEXT = ["Small", "Medium", "Large", "Huge"];
-const MAP_SIZES_DATA = [16, 20, 24, 32];
+const MAP_SIZES_TEXT = ["Tiny (2 player)", "Small (3 player)", "Medium (4 player)", "Normal (6 player)", "Large (8 player)", "Very Large", "Giant"];
+const MAP_SIZES_DATA = [8, 12, 16, 20, 24, 28, 32];
// Max number of players for any map
const MAX_PLAYERS = 8;
@@ -28,7 +28,7 @@ var g_GameAttributes = {
map: "",
mapPath: "",
settings: {
- Size: 16,
+ Size: 12,
Seed: 0,
BaseTerrain: "grass1_spring",
BaseHeight: 0,
@@ -165,7 +165,7 @@ function initMain()
if (!g_IsInGuiUpdate)
updateGameAttributes();
};
- mapSize.selected = 0;
+ mapSize.selected = 1;
getGUIObjectByName("revealMap").onPress = function()
{ // Update attributes so other players can see change
@@ -613,6 +613,7 @@ function selectMap(name)
g_GameAttributes.settings.RevealMap = getSetting(mapSettings, g_GameAttributes.settings, "RevealMap");
g_GameAttributes.settings.LockTeams = getSetting(mapSettings, g_GameAttributes.settings, "LockTeams");
g_GameAttributes.settings.GameType = getSetting(mapSettings, g_GameAttributes.settings, "GameType");
+ g_GameAttributes.settings.CircularMap = mapSettings.CircularMap;
// Reset player assignments on map change
if (!g_IsNetworked)
diff --git a/binaries/data/mods/public/gui/gamesetup/gamesetup.xml b/binaries/data/mods/public/gui/gamesetup/gamesetup.xml
index 9548ca34a5..3eaf10bb70 100644
--- a/binaries/data/mods/public/gui/gamesetup/gamesetup.xml
+++ b/binaries/data/mods/public/gui/gamesetup/gamesetup.xml
@@ -134,15 +134,15 @@
diff --git a/binaries/data/mods/public/maps/random/cantabrian_highlands.js b/binaries/data/mods/public/maps/random/cantabrian_highlands.js
index f244aff785..889a3f5f15 100644
--- a/binaries/data/mods/public/maps/random/cantabrian_highlands.js
+++ b/binaries/data/mods/public/maps/random/cantabrian_highlands.js
@@ -19,7 +19,8 @@ const oTreeLarge = "gaia/flora_tree_oak";
const oBerryBush = "gaia/flora_bush_berry";
const oSheep = "gaia/fauna_sheep";
const oDeer = "gaia/fauna_deer";
-const oMine = "gaia/geology_stone_temperate";
+const oStone = "gaia/geology_stone_greek";
+const oMetal = "gaia/geology_metal_greek";
// decorative props
const aGrass = "actor|props/flora/grass_temp_field.xml";
@@ -41,6 +42,7 @@ InitMap();
var numPlayers = getNumPlayers();
var mapSize = getMapSize();
+var mapArea = mapSize*mapSize;
// create tile classes
@@ -50,6 +52,7 @@ var clForest = createTileClass();
var clWater = createTileClass();
var clDirt = createTileClass();
var clRock = createTileClass();
+var clMetal = createTileClass();
var clFood = createTileClass();
var clBaseResource = createTileClass();
var clSettlement = createTileClass();
@@ -101,7 +104,7 @@ for (var i=1; i<=numPlayers; i++)
// create the ramp
var rampAngle = playerAngle[i] + PI + (2*randFloat()-1)*PI/8;
- var rampDist = radius - 1;
+ var rampDist = radius;
var rampX = round(fx + rampDist * cos(rampAngle));
var rampY = round(fy + rampDist * sin(rampAngle));
placer = new ClumpPlacer(100, 0.9, 0.5, 0, rampX, rampY);
@@ -148,7 +151,8 @@ for (var i=1; i<=numPlayers; i++)
var mX = round(fx + mDist * cos(mAngle));
var mY = round(fy + mDist * sin(mAngle));
group = new SimpleGroup(
- [new SimpleObject(oMine, 4,4, 0,2)],
+ [new SimpleObject(oStone, 2,2, 0,3),
+ new SimpleObject(oMetal, 2,2, 0,3)],
true, clBaseResource, mX, mY
);
createObjectGroup(group, 0);
@@ -177,7 +181,7 @@ for (var i=1; i<=numPlayers; i++)
// create lakes
log("Creating lakes...");
-placer = new ClumpPlacer(140, 0.8, 0.1, 0);
+placer = new ClumpPlacer(mapArea * 0.009, 0.8, 0.1, 0);
terrainPainter = new LayeredPainter(
[tShoreBlend, tShore, tWater], // terrains
[1,1] // widths
@@ -198,12 +202,12 @@ createAreas(
placer,
painter,
avoidClasses(clWater, 2, clPlayer, 0),
- mapSize*mapSize/1000
+ mapArea/1000
);
// create hills
log("Creating hills...");
-placer = new ClumpPlacer(30, 0.2, 0.1, 0);
+placer = new ClumpPlacer(mapArea * 0.0015, 0.2, 0.1, 0);
terrainPainter = new LayeredPainter(
[tCliff, [tGrass,tGrass,tGrassDirt75]], // terrains
[3] // widths
@@ -218,7 +222,7 @@ createAreas(
// create forests
log("Creating forests...");
-placer = new ClumpPlacer(32, 0.1, 0.1, 0);
+placer = new ClumpPlacer(mapArea * 0.002, 0.1, 0.1, 0);
painter = new LayeredPainter(
[[tGrassForest, tGrass, pForest], [tGrassForest, pForest]], // terrains
[2] // widths
@@ -233,7 +237,7 @@ createAreas(
// create dirt patches
log("Creating dirt patches...");
var sizes = [8,14,20];
-for (i=0; i y ? x : y;
}
-function min(x, y) {
+function min(x, y)
+{
return x < y ? x : y;
}
-function println(x) {
+function println(x)
+{
print(x);
print("\n");
}
@@ -111,46 +126,73 @@ function chooseRand()
function createAreas(centeredPlacer, painter, constraint, num, retryFactor)
{
if (retryFactor === undefined)
+ {
retryFactor = 10;
+ }
var maxFail = num * retryFactor;
var good = 0;
var bad = 0;
- var ret = [];
+ var result = [];
+ var halfSize = getMapSize()/2;
+
while(good < num && bad <= maxFail)
{
- centeredPlacer.x = randInt(getMapSize());
- centeredPlacer.y = randInt(getMapSize());
- var r = g_Map.createArea(centeredPlacer, painter, constraint);
- if (r !== undefined)
+ if (isCircularMap())
+ { // Polar coordinates
+ var r = halfSize * Math.sqrt(randFloat()); // uniform distribution
+ var theta = randFloat(0, 2 * PI);
+ centeredPlacer.x = Math.floor(r * Math.cos(theta)) + halfSize;
+ centeredPlacer.y = Math.floor(r * Math.sin(theta)) + halfSize;
+ }
+ else
+ { // Rectangular coordinates
+ centeredPlacer.x = randInt(getMapSize());
+ centeredPlacer.y = randInt(getMapSize());
+ }
+
+ var area = g_Map.createArea(centeredPlacer, painter, constraint);
+ if (area !== undefined)
{
good++;
- ret.push(r);
+ result.push(area);
}
else
{
bad++;
}
}
-
- return ret;
+ return good;
}
function createObjectGroups(placer, player, constraint, num, retryFactor)
{
if (retryFactor === undefined)
+ {
retryFactor = 10;
+ }
var maxFail = num * retryFactor;
var good = 0;
var bad = 0;
+ var halfSize = getMapSize()/2;
while(good < num && bad <= maxFail)
{
- placer.x = randInt(getMapSize());
- placer.y = randInt(getMapSize());
- var r = createObjectGroup(placer, player, constraint);
+ if (isCircularMap())
+ { // Polar coordinates
+ var r = halfSize * Math.sqrt(randFloat()); // uniform distribution
+ var theta = randFloat(0, 2 * PI);
+ placer.x = Math.floor(r * Math.cos(theta)) + halfSize;
+ placer.y = Math.floor(r * Math.sin(theta)) + halfSize;
+ }
+ else
+ { // Rectangular coordinates
+ placer.x = randInt(getMapSize());
+ placer.y = randInt(getMapSize());
+ }
- if (r !== undefined)
+ var result = createObjectGroup(placer, player, constraint);
+ if (result !== undefined)
{
good++;
}
@@ -169,7 +211,9 @@ function createTerrain(terrain)
var terrainList = [];
for (var i = 0; i < terrain.length; ++i)
+ {
terrainList.push(createTerrain(terrain[i]));
+ }
return new RandomTerrain(terrainList);
}
@@ -213,6 +257,11 @@ function placeTerrain(x, y, terrain)
}
+function isCircularMap()
+{
+ return (g_MapSettings.CircularMap ? true : false);
+}
+
/////////////////////////////////////////////////////////////////////////////////////////////
// Access global map variable
/////////////////////////////////////////////////////////////////////////////////////////////
@@ -225,13 +274,12 @@ function createTileClass()
function getTileClass(id)
{
// Check for valid class id
- if (id < 1 || id > g_Map.tileClasses.length)
+ if (!g_Map.validClass(id))
{
- //error("Invalid tile class id: "+id);
- return null;
+ return undefined;
}
- return g_Map.tileClasses[id - 1];
+ return g_Map.tileClasses[id];
}
function createArea(placer, painter, constraint)
@@ -285,7 +333,9 @@ function addToClass(x, y, id)
var tileClass = getTileClass(id);
if (tileClass !== null)
+ {
tileClass.add(x, y);
+ }
}
// Create a painter for the given class
diff --git a/binaries/data/mods/public/maps/random/rmgen/map.js b/binaries/data/mods/public/maps/random/rmgen/map.js
index 1f89c9ade8..1bfcab80f6 100644
--- a/binaries/data/mods/public/maps/random/rmgen/map.js
+++ b/binaries/data/mods/public/maps/random/rmgen/map.js
@@ -216,9 +216,10 @@ Map.prototype.createObjectGroup = function(placer, player, constraint)
Map.prototype.createTileClass = function()
{
- this.tileClasses.push(new TileClass(this.size));
+ var newID = this.tileClasses.length;
+ this.tileClasses.push(new TileClass(this.size, newID));
- return this.tileClasses.length;
+ return newID;
};
// Get height taking into account terrain curvature
diff --git a/binaries/data/mods/public/maps/random/rmgen/mapgen.js b/binaries/data/mods/public/maps/random/rmgen/mapgen.js
index 0e4415d582..b666f37641 100644
--- a/binaries/data/mods/public/maps/random/rmgen/mapgen.js
+++ b/binaries/data/mods/public/maps/random/rmgen/mapgen.js
@@ -2,21 +2,21 @@ var g_Map;
var g_Environment = {
SkySet: "default",
- SunColour: {r: 1.5, g: 1.5, b: 1.5},
+ SunColour: {r: 1.5, g: 1.5, b: 1.5, a: 0},
SunElevation: 0.785398,
SunRotation: 5.49779,
- TerrainAmbientColour: {r: 0.313726, g: 0.376471, b: 0.521569},
- UnitsAmbientColour: {r: 0.501961, g: 0.501961, b: 0.501961},
+ TerrainAmbientColour: {r: 0.313726, g: 0.376471, b: 0.521569, a: 0},
+ UnitsAmbientColour: {r: 0.501961, g: 0.501961, b: 0.501961, a: 0},
Water: {
WaterBody: {
Type: "default",
- Colour: {r: 0.3, g: 0.35, b: 0.7},
+ Colour: {r: 0.3, g: 0.35, b: 0.7, a: 0},
Height: 5,
Shininess: 150,
Waviness: 8,
Murkiness: 0.45,
- Tint: {r: 0.28, g: 0.3, b: 0.59},
- ReflectionTint: {r: 0.28, g: 0.3, b: 0.59},
+ Tint: {r: 0.28, g: 0.3, b: 0.59, a: 0},
+ ReflectionTint: {r: 0.28, g: 0.3, b: 0.59, a: 0},
ReflectionTintStrength: 0.0
}
}
diff --git a/binaries/data/mods/public/maps/random/rmgen/placer.js b/binaries/data/mods/public/maps/random/rmgen/placer.js
index dd13ce71c6..dc490c6bff 100644
--- a/binaries/data/mods/public/maps/random/rmgen/placer.js
+++ b/binaries/data/mods/public/maps/random/rmgen/placer.js
@@ -70,8 +70,6 @@ ClumpPlacer.prototype.place = function(constraint)
var S = v1;
noise[i] = P*t*t*t + Q*t*t + R*t + S;
- if (noise[i] > 4294967296)
- warn("noise["+i+"] is beyond max_uint32 bounds");
}
var failed = 0;
@@ -249,7 +247,7 @@ SimpleObject.prototype.place = function(cx, cy, player, avoidSelf, constraint)
function SimpleGroup(elements, avoidSelf, tileClass, x, y)
{
this.elements = elements;
- this.tileClass = (tileClass !== undefined ? getTileClass(tileClass) : null);
+ this.tileClass = (tileClass !== undefined ? getTileClass(tileClass) : undefined);
this.avoidSelf = (avoidSelf !== undefined ? avoidSelf : false);
this.x = (x !== undefined ? x : -1);
this.y = (y !== undefined ? y : -1);
@@ -280,7 +278,7 @@ SimpleGroup.prototype.place = function(player, constraint)
{
g_Map.addObjects(resultObjs[i]);
- if (this.tileClass !== null)
+ if (this.tileClass !== undefined)
{ // Round object position to integer
this.tileClass.add(Math.floor(resultObjs[i].x), Math.floor(resultObjs[i].y));
}
diff --git a/binaries/data/mods/public/maps/random/rmgen/tileclass.js b/binaries/data/mods/public/maps/random/rmgen/tileclass.js
index bcf9471f2c..3b0121ae3f 100644
--- a/binaries/data/mods/public/maps/random/rmgen/tileclass.js
+++ b/binaries/data/mods/public/maps/random/rmgen/tileclass.js
@@ -62,8 +62,9 @@ RangeOp.prototype.get = function(start, end)
// TileClass
//////////////////////////////////////////////////////////////////////
-function TileClass(size)
+function TileClass(size, id)
{
+ this.id = id;
this.size = size;
this.inclusionCount = new Array(size);
this.rangeCount = new Array(size);
diff --git a/binaries/data/mods/public/maps/scenarios/Miletus.xml b/binaries/data/mods/public/maps/scenarios/Miletus.xml
index a7d706e603..d5a89ece8f 100644
--- a/binaries/data/mods/public/maps/scenarios/Miletus.xml
+++ b/binaries/data/mods/public/maps/scenarios/Miletus.xml
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
-oid sha256:c7b11ee5339e95fac77dfb7cf63298c740cde50bc1ba587990add008b8604096
+oid sha256:d95130d87d4e5e6ac445211f33b30c7093eaa2947db3ae6da5b991d3a5fedc82
size 195886
diff --git a/source/graphics/MapGenerator.cpp b/source/graphics/MapGenerator.cpp
index 84331af206..eab1315fc7 100644
--- a/source/graphics/MapGenerator.cpp
+++ b/source/graphics/MapGenerator.cpp
@@ -21,32 +21,24 @@
#include "lib/timer.h"
#include "ps/CLogger.h"
-#include
+
// TODO: what's a good default? perhaps based on map size
#define RMS_RUNTIME_SIZE 96 * 1024 * 1024
-boost::rand48 g_MapGenRNG;
-
CMapGenerator::CMapGenerator() : m_ScriptInterface("RMS", "MapGenerator", ScriptInterface::CreateRuntime(RMS_RUNTIME_SIZE))
{
m_ScriptInterface.SetCallbackData(static_cast (this));
// Replace RNG with a seeded deterministic function
- m_ScriptInterface.ReplaceNondeterministicFunctions(g_MapGenRNG);
+ m_ScriptInterface.ReplaceNondeterministicFunctions(m_MapGenRNG);
// functions for RMS
m_ScriptInterface.RegisterFunction("LoadLibrary");
m_ScriptInterface.RegisterFunction("ExportMap");
}
-CMapGenerator::~CMapGenerator()
-{
- // Clean up rooted objects before destroying their script context
- m_MapData = CScriptValRooted();
-}
-
bool CMapGenerator::GenerateMap(const VfsPath& scriptFile, const CScriptValRooted& settings)
{
TIMER(L"GenerateMap");
@@ -54,12 +46,12 @@ bool CMapGenerator::GenerateMap(const VfsPath& scriptFile, const CScriptValRoote
// Init RNG seed
uint32 seed;
if (!m_ScriptInterface.GetProperty(settings.get(), "Seed", seed))
- { // No seed specfified
+ { // No seed specified
LOGWARNING(L"GenerateMap: No seed value specified - using 0");
seed = 0;
}
- g_MapGenRNG.seed(seed);
+ m_MapGenRNG.seed(seed);
// Copy settings to script context
if (!m_ScriptInterface.SetProperty(m_ScriptInterface.GetGlobalObject(), "g_MapSettings", settings))
diff --git a/source/graphics/MapGenerator.h b/source/graphics/MapGenerator.h
index 87773cb4be..a441e47581 100644
--- a/source/graphics/MapGenerator.h
+++ b/source/graphics/MapGenerator.h
@@ -22,6 +22,7 @@
#include "ps/FileIo.h"
#include "scriptinterface/ScriptInterface.h"
+#include
class CMapGenerator
{
@@ -30,9 +31,6 @@ public:
// constructor
CMapGenerator();
- // destructor
- ~CMapGenerator();
-
// return success of map generation
bool GenerateMap(const VfsPath& scriptFile, const CScriptValRooted& settings);
@@ -53,6 +51,7 @@ private:
ScriptInterface m_ScriptInterface;
CScriptValRooted m_MapData;
std::set m_LoadedLibraries;
+ boost::rand48 m_MapGenRNG;
};
#endif //INCLUDED_MAPGENERATOR
diff --git a/source/graphics/MapReader.cpp b/source/graphics/MapReader.cpp
index ba1065d15c..aea1eea116 100644
--- a/source/graphics/MapReader.cpp
+++ b/source/graphics/MapReader.cpp
@@ -53,7 +53,6 @@ CMapReader::CMapReader()
cur_terrain_tex = 0; // important - resets generator state
}
-
// LoadMap: try to load the map from given file; reinitialise the scene to new data if successful
void CMapReader::LoadMap(const VfsPath& pathname, CTerrain *pTerrain_,
WaterManager* pWaterMan_, SkyManager* pSkyMan_,
@@ -1218,11 +1217,20 @@ int CMapReader::ParseEnvironment()
GET_ENVIRONMENT_PROPERTY(envObj.get(), SkySet, skySet)
pSkyMan->SetSkySet(skySet);
- GET_ENVIRONMENT_PROPERTY(envObj.get(), SunColour, m_LightEnv.m_SunColor)
+ CColor sunColor;
+ GET_ENVIRONMENT_PROPERTY(envObj.get(), SunColour, sunColor)
+ m_LightEnv.m_SunColor = RGBColor(sunColor.r, sunColor.g, sunColor.b);
+
GET_ENVIRONMENT_PROPERTY(envObj.get(), SunElevation, m_LightEnv.m_Elevation)
GET_ENVIRONMENT_PROPERTY(envObj.get(), SunRotation, m_LightEnv.m_Rotation)
- GET_ENVIRONMENT_PROPERTY(envObj.get(), TerrainAmbientColour, m_LightEnv.m_TerrainAmbientColor)
- GET_ENVIRONMENT_PROPERTY(envObj.get(), UnitsAmbientColour, m_LightEnv.m_UnitsAmbientColor)
+
+ CColor terrainAmbientColor;
+ GET_ENVIRONMENT_PROPERTY(envObj.get(), TerrainAmbientColour, terrainAmbientColor)
+ m_LightEnv.m_TerrainAmbientColor = RGBColor(terrainAmbientColor.r, terrainAmbientColor.g, terrainAmbientColor.b);
+
+ CColor unitsAmbientColor;
+ GET_ENVIRONMENT_PROPERTY(envObj.get(), UnitsAmbientColour, unitsAmbientColor)
+ m_LightEnv.m_UnitsAmbientColor = RGBColor(unitsAmbientColor.r, unitsAmbientColor.g, unitsAmbientColor.b);
// Water properties
CScriptValRooted waterObj;
@@ -1246,22 +1254,12 @@ int CMapReader::ParseEnvironment()
// TODO: Water type not implemented
//GET_ENVIRONMENT_PROPERTY(waterBodyObj.get(), Type, waterType)
- RGBColor waterColour;
- GET_ENVIRONMENT_PROPERTY(waterBodyObj.get(), Colour, waterColour)
- pWaterMan->m_WaterColor = CColor(waterColour.X, waterColour.Y, waterColour.Z, 1.0f);
-
+ GET_ENVIRONMENT_PROPERTY(waterBodyObj.get(), Colour, pWaterMan->m_WaterColor)
GET_ENVIRONMENT_PROPERTY(waterBodyObj.get(), Shininess, pWaterMan->m_Shininess)
GET_ENVIRONMENT_PROPERTY(waterBodyObj.get(), Waviness, pWaterMan->m_Waviness)
GET_ENVIRONMENT_PROPERTY(waterBodyObj.get(), Murkiness, pWaterMan->m_Murkiness)
-
- RGBColor waterTint;
- GET_ENVIRONMENT_PROPERTY(waterBodyObj.get(), Tint, waterTint)
- pWaterMan->m_WaterTint = CColor(waterTint.X, waterTint.Y, waterTint.Z, 1.0f);
-
- RGBColor reflectTint;
- GET_ENVIRONMENT_PROPERTY(waterBodyObj.get(), ReflectionTint, reflectTint)
- pWaterMan->m_ReflectionTint = CColor(reflectTint.X, reflectTint.Y, reflectTint.Z, 1.0f);
-
+ GET_ENVIRONMENT_PROPERTY(waterBodyObj.get(), Tint, pWaterMan->m_WaterTint)
+ GET_ENVIRONMENT_PROPERTY(waterBodyObj.get(), ReflectionTint, pWaterMan->m_ReflectionTint)
GET_ENVIRONMENT_PROPERTY(waterBodyObj.get(), ReflectionTintStrength, pWaterMan->m_ReflectionTintStrength)
}
diff --git a/source/ps/GameSetup/GameSetup.cpp b/source/ps/GameSetup/GameSetup.cpp
index 937b7e2ca6..926926767a 100644
--- a/source/ps/GameSetup/GameSetup.cpp
+++ b/source/ps/GameSetup/GameSetup.cpp
@@ -954,10 +954,10 @@ static bool Autostart(const CmdLineArgs& args)
{
/*
* Handle various command-line options, for quick testing of various features:
- * -autostart=mapname -- single-player
+ * -autostart=mapname -- single-player
* -autostart=mapname -autostart-playername=Player -autostart-host -autostart-players=2 -- multiplayer host, wait for 2 players
* -autostart=mapname -autostart-playername=Player -autostart-client -autostart-ip=127.0.0.1 -- multiplayer client, connect to 127.0.0.1
- * -autostart=scriptname -autostart-random
+ * -autostart=scriptname -autostart-random=104 -- random map, seed 104 (default is 0, for random choose -1)
*/
CStr autoStartName = args.Get("autostart");
@@ -978,18 +978,34 @@ static bool Autostart(const CmdLineArgs& args)
// Set different attributes for random or scenario game
if (args.Has("autostart-random"))
{
+ CStr seedArg = args.Get("autostart-random");
+
+ // Default seed is 0
+ uint32 seed = 0;
+ if (!seedArg.empty())
+ {
+ if (seedArg.compare("-1") == 0)
+ { // Random seed value
+ seed = rand();
+ }
+ else
+ {
+ seed = seedArg.ToULong();
+ }
+ }
+
scriptInterface.SetProperty(attrs.get(), "script", std::string(autoStartName), false); // RMS name
scriptInterface.SetProperty(attrs.get(), "mapType", std::string("random"), false);
// For random map, there are special settings
// TODO: Get these from command line - using defaults for now
- scriptInterface.SetProperty(settings.get(), "Size", 16); // Random map size (in patches)
- scriptInterface.SetProperty(settings.get(), "Seed", 0); // Random seed
+ scriptInterface.SetProperty(settings.get(), "Size", 12); // Random map size (in patches)
+ scriptInterface.SetProperty(settings.get(), "Seed", seed); // Random seed
scriptInterface.SetProperty(settings.get(), "BaseTerrain", std::string("grass1_spring")); // Base terrain texture
scriptInterface.SetProperty(settings.get(), "BaseHeight", 0); // Base terrain height
// Define players
- // TODO: Get these from command line - using defaults for now
+ // TODO: Get these from command line? - using defaults for now
size_t numPlayers = 2;
for (size_t i = 0; i < numPlayers; ++i)
{
diff --git a/source/scriptinterface/ScriptConversions.cpp b/source/scriptinterface/ScriptConversions.cpp
index 4840319d3e..f69f1d1e4b 100644
--- a/source/scriptinterface/ScriptConversions.cpp
+++ b/source/scriptinterface/ScriptConversions.cpp
@@ -19,7 +19,6 @@
#include "ScriptInterface.h"
-#include "graphics/Color.h"
#include "graphics/Entity.h"
#include "graphics/MapIO.h"
#include "ps/utf16string.h"
@@ -164,23 +163,6 @@ template<> bool ScriptInterface::FromJSVal(JSContext* cx, jsval v, Entit
return true;
}
-template<> bool ScriptInterface::FromJSVal(JSContext* cx, jsval v, RGBColor& out)
-{
- JSObject* obj;
- if (!JS_ValueToObject(cx, v, &obj) || obj == NULL)
- FAIL("Argument must be an object");
-
- jsval r, g, b;
- if (!JS_GetProperty(cx, obj, "r", &r) || !FromJSVal(cx, r, out.X))
- FAIL("Failed to read RGBColor.r property");
- if (!JS_GetProperty(cx, obj, "g", &g) || !FromJSVal(cx, g, out.Y))
- FAIL("Failed to read RGBColor.g property");
- if (!JS_GetProperty(cx, obj, "b", &b) || !FromJSVal(cx, b, out.Z))
- FAIL("Failed to read RGBColor.b property");
-
- return true;
-}
-
template<> bool ScriptInterface::FromJSVal(JSContext* cx, jsval v, CMapIO::STileDesc& out)
{
JSObject* obj;
diff --git a/source/simulation2/scripting/EngineScriptConversions.cpp b/source/simulation2/scripting/EngineScriptConversions.cpp
index 59bf1c6606..d5b11292b5 100644
--- a/source/simulation2/scripting/EngineScriptConversions.cpp
+++ b/source/simulation2/scripting/EngineScriptConversions.cpp
@@ -35,6 +35,8 @@
#include "js/jstypedarray.h"
#undef signbit
+#define FAIL(msg) STMT(JS_ReportError(cx, msg); return false)
+
template<> jsval ScriptInterface::ToJSVal(JSContext* cx, IComponent* const& val)
{
if (val == NULL)
@@ -89,21 +91,21 @@ template<> jsval ScriptInterface::ToJSVal(JSContext* cx, cons
template<> bool ScriptInterface::FromJSVal(JSContext* cx, jsval v, CColor& out)
{
if (!JSVAL_IS_OBJECT(v))
- return false; // TODO: report type error
+ FAIL("jsval not an object");
+
JSObject* obj = JSVAL_TO_OBJECT(v);
jsval r, g, b, a;
- if (!JS_GetProperty(cx, obj, "r", &r)) return false; // TODO: report type errors
- if (!JS_GetProperty(cx, obj, "g", &g)) return false;
- if (!JS_GetProperty(cx, obj, "b", &b)) return false;
- if (!JS_GetProperty(cx, obj, "a", &a)) return false;
+ if (!JS_GetProperty(cx, obj, "r", &r) || !FromJSVal(cx, r, out.r))
+ FAIL("Failed to get property CColor.r");
+ if (!JS_GetProperty(cx, obj, "g", &g) || !FromJSVal(cx, g, out.g))
+ FAIL("Failed to get property CColor.g");
+ if (!JS_GetProperty(cx, obj, "b", &b) || !FromJSVal(cx, b, out.b))
+ FAIL("Failed to get property CColor.b");
+ if (!JS_GetProperty(cx, obj, "a", &a) || !FromJSVal(cx, a, out.a))
+ FAIL("Failed to get property CColor.a");
// TODO: this probably has GC bugs if a getter returns an unrooted value
- if (!FromJSVal(cx, r, out.r)) return false;
- if (!FromJSVal(cx, g, out.g)) return false;
- if (!FromJSVal(cx, b, out.b)) return false;
- if (!FromJSVal(cx, a, out.a)) return false;
-
return true;
}