From 4de9c4c1644873848b31ae3cf66398ded7974cd1 Mon Sep 17 00:00:00 2001 From: wraitii Date: Thu, 10 Jun 2021 13:16:10 +0000 Subject: [PATCH] Fixes for some random maps. - Hellas_biome isn't a RM but as a JSON script it does load, and then silently fails on mapgen. Explicitly fail. - Fix player.js when a valid position cannot exist. - Fix unknown.js when landscape isn't set in the settings. Reported by: vladislavbelov Refs #6180 Differential Revision: https://code.wildfiregames.com/D4147 This was SVN commit r25765. --- .../data/mods/public/maps/random/rmgen-common/player.js | 4 +++- binaries/data/mods/public/maps/random/unknown.js | 3 ++- source/ps/GameSetup/GameSetup.cpp | 6 +++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/binaries/data/mods/public/maps/random/rmgen-common/player.js b/binaries/data/mods/public/maps/random/rmgen-common/player.js index 51598391e6..38d12f50e2 100644 --- a/binaries/data/mods/public/maps/random/rmgen-common/player.js +++ b/binaries/data/mods/public/maps/random/rmgen-common/player.js @@ -689,7 +689,9 @@ function playerPlacementRandom(playerIDs, constraints = undefined) for (let i = 0; i < getNumPlayers(); ++i) { - let position = pickRandom(area.getPoints()); + const position = pickRandom(area.getPoints()); + if (!position) + return undefined; // Minimum distance between initial bases must be a quarter of the map diameter if (locations.some(loc => loc.distanceToSquared(position) < playerMinDistSquared) || diff --git a/binaries/data/mods/public/maps/random/unknown.js b/binaries/data/mods/public/maps/random/unknown.js index a6f3e54f9c..fdb581cdbf 100644 --- a/binaries/data/mods/public/maps/random/unknown.js +++ b/binaries/data/mods/public/maps/random/unknown.js @@ -107,7 +107,8 @@ var g_StartingWalls = true; function createUnknownMap() { - global["unknown" + g_MapSettings.Landscape || pickRandom([...unknownMapFunctions.land, ...unknownMapFunctions.naval])](); + const landscape = g_MapSettings.Landscape || pickRandom([...unknownMapFunctions.land, ...unknownMapFunctions.naval]); + global["unknown" + landscape](); paintUnknownMapBasedOnHeight(); diff --git a/source/ps/GameSetup/GameSetup.cpp b/source/ps/GameSetup/GameSetup.cpp index 3ac6a2af0a..f52a66c22c 100644 --- a/source/ps/GameSetup/GameSetup.cpp +++ b/source/ps/GameSetup/GameSetup.cpp @@ -1231,7 +1231,11 @@ bool Autostart(const CmdLineArgs& args) { // JSON loaded ok - copy script name over to game attributes std::wstring scriptFile; - Script::GetProperty(rq, settings, "Script", scriptFile); + if (!Script::GetProperty(rq, settings, "Script", scriptFile)) + { + LOGERROR("Autostart: random map '%s' data has no 'Script' property.", utf8_from_wstring(scriptPath)); + throw PSERROR_Game_World_MapLoadFailed("Error reading random map script.\nCheck application log for details."); + } Script::SetProperty(rq, attrs, "script", scriptFile); // RMS filename } else