Ticket #3102: t3102_survival_7a.diff

File t3102_survival_7a.diff, 7.5 KB (added by bb, 8 years ago)

random changes only

  • 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 */
     8function 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 */
     30function 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/gui/common/functions_utility.js

     
    33 */
    44var g_LastNickNotification = -1;
    55
    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 B
    13     return Math.round(randomNum);
    14 }
    15 
    166// Get list of XML files in pathname with recursion, excepting those starting with _
    177function getXMLFileList(pathname)
    188{
  • binaries/data/mods/public/gui/common/music.js

     
    132132
    133133Music.prototype.getRandomTrack = function(tracks)
    134134{
    135     return tracks[getRandom(0, tracks.length-1)];
     135    return shuffleArray(tracks)[0];
    136136};
    137137
    138138Music.prototype.startPlayList = function(tracks, fadeInPeriod, isLooping)
  • binaries/data/mods/public/gui/loading/loading.js

     
    1414    if (tipTextLoadingArray.length > 0)
    1515    {
    1616        // Set tip text
    17         let tipTextFilePath = tipTextLoadingArray[getRandom(0, tipTextLoadingArray.length-1)];
     17        let tipTextFilePath = shuffleArray(tipTextLoadingArray)[0]
    1818        let tipText = Engine.TranslateLines(Engine.ReadFile(tipTextFilePath));
    1919
    2020        if (tipText)
     
    6363
    6464    // Pick a random quote of the day (each line is a separate tip).
    6565    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(shuffleArray(quoteArray)[0]);
    6767}
    6868
    6969function displayProgress()
  • binaries/data/mods/public/maps/random/rmgen/random.js

     
    1 // TODO: rename/change these functions, so the bounds are more clear
    2 
    3 /*
    4  * Return a random floating point number using Math.random library
    5  *
    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     else
    23     {
    24         error("randFloat: invalid number of arguments: "+arguments.length);
    25         return undefined;
    26     }
    27 }
    28 
    29 /*
    30  * Return a random integer using Math.random library
    31  *
    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     else
    50     {
    51         error("randInt: invalid number of arguments: "+arguments.length);
    52         return undefined;
    53     }
    54 }
  • binaries/data/mods/public/simulation/components/UnitAI.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
     
    31153115                this.SelectAnimation("walk", false, this.GetWalkSpeed());
    31163116                this.MoveRandomly(+this.template.RoamDistance);
    31173117                // 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));
    31193119                this.SetFacePointAfterMove(false);
    31203120            },
    31213121
     
    31603160                // Stop and eat for a while
    31613161                this.SelectAnimation("feeding");
    31623162                this.StopMoving();
    3163                 this.StartTimer(RandomInt(+this.template.FeedTimeMin, +this.template.FeedTimeMax));
     3163                this.StartTimer(randInt(+this.template.FeedTimeMin, +this.template.FeedTimeMax));
    31643164            },
    31653165
    31663166            "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);