Ticket #3102: t3102_survival_8a.diff
File t3102_survival_8a.diff, 11.5 KB (added by , 8 years ago) |
---|
-
binaries/data/mods/public/globalscripts/random.js
1 /* 2 * Return a random floating point number using Math.random library 3 * 4 * If no parameter given, the returned float is in the interval [0, 1) 5 * If one parameter given, it's maxval, and the returned float is in the interval [0, maxval) 6 * If two parameters are given, they are minval and maxval, and the returned float is in the interval [minval, maxval) 7 */ 8 function randFloat() 9 { 10 if (!arguments.length) 11 return Math.random(); 12 else if (arguments.length == 1) 13 return randFloat() * arguments[0]; 14 else if (arguments.length == 2) 15 return arguments[0] + randFloat() * (arguments[1] - arguments[0]); 16 else 17 { 18 error("randFloat: invalid number of arguments: "+arguments.length); 19 return undefined; 20 } 21 } 22 23 /* 24 * Return a random integer using Math.random library 25 * 26 * If no parameter given, the returned integer is in the interval [0, 1] 27 * If one parameter given, it's maxval, and the returned integer is in the interval [0, maxval) 28 * If two parameters are given, they are minval and maxval, and the returned integer is in the interval [minval, maxval] 29 */ 30 function randInt() 31 { 32 if (!arguments.length) 33 return Math.round(randFloat()); 34 else if (arguments.length == 1) 35 return Math.floor(randFloat(arguments[0])); 36 else if (arguments.length == 2) 37 return Math.floor(randFloat(arguments[0], arguments[1] + 1)); 38 else 39 { 40 error("randInt: invalid number of arguments: "+arguments.length); 41 return undefined; 42 } 43 } -
binaries/data/mods/public/globalscripts/utility.js
28 28 let result = [source[0]]; 29 29 for (let i = 1; i < source.length; ++i) 30 30 { 31 let j = Math.floor(Math.random() * (i+1));31 let j = randInt(i+1); 32 32 result[i] = result[j]; 33 33 result[j] = source[i]; 34 34 } 35 35 return result; 36 36 } 37 38 function pickRandomElement(source) 39 { 40 return source.length ? source[randInt(source.length)] : undefined; 41 } -
binaries/data/mods/public/gui/common/functions_utility.js
3 3 */ 4 4 var g_LastNickNotification = -1; 5 5 6 function getRandom(randomMin, randomMax)7 {8 // Returns a random whole number in a min..max range.9 // NOTE: There should probably be an engine function for this,10 // since we'd need to keep track of random seeds for replays.11 12 var randomNum = randomMin + (randomMax-randomMin)*Math.random(); // num is random, from A to B13 return Math.round(randomNum);14 }15 16 6 // Get list of XML files in pathname with recursion, excepting those starting with _ 17 7 function getXMLFileList(pathname) 18 8 { -
binaries/data/mods/public/gui/common/music.js
132 132 133 133 Music.prototype.getRandomTrack = function(tracks) 134 134 { 135 return tracks[getRandom(0, tracks.length-1)];135 return pickRandomElement(tracks); 136 136 }; 137 137 138 138 Music.prototype.startPlayList = function(tracks, fadeInPeriod, isLooping) -
binaries/data/mods/public/gui/gamesetup/gamesetup.js
1229 1229 { 1230 1230 let victoryScriptsSelected = g_GameAttributes.settings.VictoryScripts; 1231 1231 let gameTypeSelected = g_GameAttributes.settings.GameType; 1232 selectMap(Engine.GetGUIObjectByName("mapSelection").list_data[Math.floor(Math.random() * 1233 (Engine.GetGUIObjectByName("mapSelection").list.length - 1)) + 1]); 1232 selectMap(pickRandomElement(Engine.GetGUIObjectByName("mapSelection").list_data)); 1234 1233 g_GameAttributes.settings.VictoryScripts = victoryScriptsSelected; 1235 1234 g_GameAttributes.settings.GameType = gameTypeSelected; 1236 1235 } … … 1253 1252 let chosenCiv = g_GameAttributes.settings.PlayerData[i].Civ || "random"; 1254 1253 if (chosenCiv == "random") 1255 1254 { 1256 let culture = cultures[Math.floor(Math.random() * cultures.length)];1255 let culture = pickRandomElement(cultures); 1257 1256 let civs = Object.keys(g_CivData).filter(civ => g_CivData[civ].Culture == culture); 1258 chosenCiv = civs[Math.floor(Math.random() * civs.length)];1257 chosenCiv = pickRandomElement(civs); 1259 1258 } 1260 1259 g_GameAttributes.settings.PlayerData[i].Civ = chosenCiv; 1261 1260 … … 1263 1262 if (g_GameAttributes.mapType === "scenario" || !g_GameAttributes.settings.PlayerData[i].AI) 1264 1263 continue; 1265 1264 1266 let chosenName = g_CivData[chosenCiv].AINames[Math.floor(Math.random() * g_CivData[chosenCiv].AINames.length)];1265 let chosenName = pickRandomElement(g_CivData[chosenCiv].AINames); 1267 1266 1268 1267 if (!g_IsNetworked) 1269 1268 chosenName = translate(chosenName); -
binaries/data/mods/public/gui/loading/loading.js
14 14 if (tipTextLoadingArray.length > 0) 15 15 { 16 16 // Set tip text 17 let tipTextFilePath = tipTextLoadingArray[getRandom(0, tipTextLoadingArray.length-1)];17 let tipTextFilePath = pickRandomElement(tipTextLoadingArray); 18 18 let tipText = Engine.TranslateLines(Engine.ReadFile(tipTextFilePath)); 19 19 20 20 if (tipText) … … 63 63 64 64 // Pick a random quote of the day (each line is a separate tip). 65 65 let quoteArray = Engine.ReadFileLines("gui/text/quotes.txt"); 66 Engine.GetGUIObjectByName("quoteText").caption = translate( quoteArray[getRandom(0, quoteArray.length-1)]);66 Engine.GetGUIObjectByName("quoteText").caption = translate(pickRandomElement(quoteArray)); 67 67 } 68 68 69 69 function displayProgress() -
binaries/data/mods/public/maps/random/flood.js
445 445 planetm * scaleByMapSize(13, 200) 446 446 ); 447 447 448 setSkySet( shuffleArray(["cloudless", "cumulus", "overcast"])[0]);448 setSkySet(pickRandomElement(["cloudless", "cumulus", "overcast"])); 449 449 setWaterMurkiness(0.4); 450 450 451 451 ExportMap(); -
binaries/data/mods/public/maps/random/island_stronghold.js
577 577 paintTerrainBasedOnHeight(1, 2, 0, tShore); 578 578 paintTerrainBasedOnHeight(getMapBaseHeight(), 1, 3, tWater); 579 579 580 setSkySet( shuffleArray(["cloudless", "cumulus", "overcast"])[0]);580 setSkySet(pickRandomElement(["cloudless", "cumulus", "overcast"])); 581 581 582 582 setSunRotation(randFloat(0, TWO_PI)); 583 583 setSunElevation(randFloat(PI/5, PI/3)); -
binaries/data/mods/public/maps/random/rmgen/random.js
1 // TODO: rename/change these functions, so the bounds are more clear2 3 /*4 * Return a random floating point number using Math.random library5 *6 * If no parameter given, the returned float is in the interval [0, 1)7 * If two parameters are given, they are minval and maxval, and the returned float is in the interval [minval, maxval)8 */9 function randFloat()10 {11 if (arguments.length == 0)12 {13 return Math.random();14 }15 else if (arguments.length == 2)16 {17 var minVal = arguments[0];18 var maxVal = arguments[1];19 20 return minVal + randFloat() * (maxVal - minVal);21 }22 else23 {24 error("randFloat: invalid number of arguments: "+arguments.length);25 return undefined;26 }27 }28 29 /*30 * Return a random integer using Math.random library31 *32 * If one parameter given, it's maxval, and the returned integer is in the interval [0, maxval)33 * If two parameters are given, they are minval and maxval, and the returned integer is in the interval [minval, maxval]34 */35 function randInt()36 {37 if (arguments.length == 1)38 {39 var maxVal = arguments[0];40 return Math.floor(Math.random() * maxVal);41 }42 else if (arguments.length == 2)43 {44 var minVal = arguments[0];45 var maxVal = arguments[1];46 47 return minVal + randInt(maxVal - minVal + 1);48 }49 else50 {51 error("randInt: invalid number of arguments: "+arguments.length);52 return undefined;53 }54 } -
binaries/data/mods/public/simulation/ai/common-api/utils.js
Property changes on: binaries/data/mods/public/maps/random/rmgen/random.js ___________________________________________________________________ Deleted: svn:eol-style ## -1 +0,0 ## -native \ No newline at end of property
54 54 return endArray; 55 55 }; 56 56 57 /** Picks a random element from an array */58 m.PickRandom = function(list)59 {60 return list.length ? list[Math.floor(Math.random()*list.length)] : undefined;61 };62 63 64 57 /** Utility functions for conversions of maps of different sizes */ 65 58 66 59 /** -
binaries/data/mods/public/simulation/components/UnitAI.js
3115 3115 this.SelectAnimation("walk", false, this.GetWalkSpeed()); 3116 3116 this.MoveRandomly(+this.template.RoamDistance); 3117 3117 // Set a random timer to switch to feeding state 3118 this.StartTimer( RandomInt(+this.template.RoamTimeMin, +this.template.RoamTimeMax));3118 this.StartTimer(randInt(+this.template.RoamTimeMin, +this.template.RoamTimeMax)); 3119 3119 this.SetFacePointAfterMove(false); 3120 3120 }, 3121 3121 … … 3160 3160 // Stop and eat for a while 3161 3161 this.SelectAnimation("feeding"); 3162 3162 this.StopMoving(); 3163 this.StartTimer( RandomInt(+this.template.FeedTimeMin, +this.template.FeedTimeMax));3163 this.StartTimer(randInt(+this.template.FeedTimeMin, +this.template.FeedTimeMax)); 3164 3164 }, 3165 3165 3166 3166 "leave": function() { -
binaries/data/mods/public/simulation/helpers/Random.js
1 /**2 * Returns a random integer from min (inclusive) to max (exclusive)3 */4 function RandomInt(min, max)5 {6 return Math.floor(min + Math.random() * (max-min));7 }8 9 Engine.RegisterGlobal("RandomInt", RandomInt);