This Trac instance is not used for development anymore!

We migrated our development workflow to git and Gitea.
To test the future redirection, replace trac by ariadne in the page URL.

Changeset 9909 for ps


Ignore:
Timestamp:
07/24/11 22:04:04 (13 years ago)
Author:
ben
Message:

Fixes rmgen to use GetCivData and handle invalid/unfinished civs.

Location:
ps/trunk/binaries/data/mods/public/maps/random
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • ps/trunk/binaries/data/mods/public/maps/random/new_rms_test.js

    r9096 r9909  
    2424
    2525var playerX = new Array(numPlayers);
    26 var playerY = new Array(numPlayers);
     26var playerZ = new Array(numPlayers);
    2727var playerAngle = new Array(numPlayers);
    2828
     
    3232    playerAngle[i] = startAngle + i*2*PI/numPlayers;
    3333    playerX[i] = 0.5 + 0.39*cos(playerAngle[i]);
    34     playerY[i] = 0.5 + 0.39*sin(playerAngle[i]);
     34    playerZ[i] = 0.5 + 0.39*sin(playerAngle[i]);
    3535}
    3636
     
    3939    log("Creating base for player " + (i + 1) + "...");
    4040   
    41     // get the x and y in tiles
     41    // get the x and z in tiles
    4242    var fx = fractionToTiles(playerX[i]);
    43     var fy = fractionToTiles(playerY[i]);
     43    var fz = fractionToTiles(playerZ[i]);
    4444    var ix = round(fx);
    45     var iy = round(fy);
     45    var iz = round(fz);
    4646
    47     // create the TC and citizens
    48     var civ = getCivCode(i);
    49     var group = new SimpleGroup(
    50         [                           // elements (type, count, distance)
    51             new SimpleObject("structures/"+civ+"_civil_centre", 1,1, 0,0),
    52             new SimpleObject("units/"+civ+"_support_female_citizen", 3,3, 5,5)
    53         ],
    54         true, null, ix, iy
     47    // get civ specific starting entities
     48    var civEntities = getStartingEntities(i);
     49   
     50    // create the TC
     51    var group = new SimpleGroup(    // elements (type, min/max count, min/max distance)
     52        [new SimpleObject(civEntities[0].Template, 1,1, 0,0)],
     53        true, null, ix, iz
    5554    );
    5655    createObjectGroup(group, i+1);
     56   
     57    // create starting units
     58    var uDist = 8;
     59    var uAngle = playerAngle[i] + PI + randFloat(-PI/8, PI/8);
     60    for (var j = 1; j < civEntities.length; ++j)
     61    {
     62        var count = (civEntities[j].Count !== undefined ? civEntities[j].Count : 1);
     63        var ux = round(fx + uDist * cos(uAngle));
     64        var uz = round(fz + uDist * sin(uAngle));
     65        group = new SimpleGroup(    // elements (type, min/max count, min/max distance)
     66            [new SimpleObject(civEntities[j].Template, count,count, 1,ceil(count/2))],
     67            true, null, ux, uz
     68        );
     69        createObjectGroup(group, i+1);
     70        uAngle += PI/4;
     71    }
    5772}
    5873
  • ps/trunk/binaries/data/mods/public/maps/random/rmgen/library.js

    r9435 r9909  
    390390function getStartingEntities(player)
    391391{   
    392     // This is a temporary hack until map generator has a LoadCivData method
    393     var civStartingEntities = {
    394         "celt" : [
    395             {
    396                 "Template": "structures/celt_civil_centre"
    397             },
    398             {
    399                 "Template": "units/celt_support_female_citizen",
    400                 "Count": 4
    401             },
    402             {
    403                 "Template": "units/celt_infantry_spearman_b",
    404                 "Count": 4
    405             },
    406             {
    407                 "Template": "units/celt_cavalry_swordsman_b"
    408             }
    409         ],
    410         "hele" : [
    411             {
    412                 "Template": "structures/hele_civil_centre"
    413             },
    414             {
    415                 "Template": "units/hele_support_female_citizen",
    416                 "Count": 4
    417             },
    418             {
    419                 "Template": "units/hele_infantry_spearman_b",
    420                 "Count": 4
    421             },
    422             {
    423                 "Template": "units/hele_cavalry_swordsman_b"
    424             }
    425         ],
    426         "iber" : [
    427             {
    428                 "Template": "structures/iber_civil_centre"
    429             },
    430             {
    431                 "Template": "units/iber_support_female_citizen",
    432                 "Count": 4
    433             },
    434             {
    435                 "Template": "units/iber_infantry_spearman_b",
    436                 "Count": 4
    437             },
    438             {
    439                 "Template": "units/iber_cavalry_spearman_b"
    440             }
    441         ]
    442     };
    443    
    444     return civStartingEntities[getCivCode(player)];
     392    var civ = getCivCode(player);
     393    if (!g_CivData[civ] || (g_CivData[civ].SelectableInGameSetup !== undefined && !g_CivData[civ].SelectableInGameSetup) || !g_CivData[civ].StartEntities || !g_CivData[civ].StartEntities.length)
     394    {
     395        warn("Invalid or unimplemented civ '"+civ+"' specified, falling back to 'hele'");
     396        civ = "hele";
     397    }
     398   
     399    return g_CivData[civ].StartEntities;
    445400}
    446401
  • ps/trunk/binaries/data/mods/public/maps/random/rmgen/mapgen.js

    r9435 r9909  
    2929};
    3030
     31var g_CivData = {};
     32
    3133/////////////////////////////////////////////////////////////////////////////////////
    3234
     
    3739        // Should never get this far, failed settings would abort prior to loading scripts
    3840        throw("InitMapGen: settings missing");
     41    }
     42   
     43    // Get civ data as array of JSON strings
     44    var data = RMS.GetCivData();
     45    if (!data || !data.length)
     46    {
     47        throw("InitMapGen: error reading civ data");
     48    }
     49    for (var i = 0; i < data.length; ++i)
     50    {
     51        var civData = JSON.parse(data[i]);
     52        g_CivData[civData.Code] = civData;
    3953    }
    4054   
Note: See TracChangeset for help on using the changeset viewer.