Ticket #2944: generic_wall_builder_rmgen.patch

File generic_wall_builder_rmgen.patch, 8.4 KB (added by FeXoR, 9 years ago)

Patch for r16007

  • binaries/data/mods/public/maps/random/rmgen/library.js

     
    394394    return g_MapSettings.PlayerData.length;
    395395}
    396396
     397// Takes nothing, Returns an array of strings representing all available civilizations
     398function getCivList()
     399{
     400    var raw_civData = RMS.GetCivData();
     401    var civList = [];
     402    for (var i = 0; i < raw_civData.length; ++i)
     403        civList.push(JSON.parse(raw_civData[i]).Code);
     404   
     405    return civList;
     406}
     407
    397408function getCivCode(player)
    398409{
    399410    if (g_MapSettings.PlayerData[player].Civ)
  • binaries/data/mods/public/maps/random/rmgen/misc.js

     
    157157    }
    158158}
    159159
    160 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     160//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    161161// placeCivDefaultEntities
    162162//
    163163//  Creates the default starting player entities depending on the players civ
    164164//  fx&fy: position of player base
    165165//  playerid: id of player
    166166//  angle: angle of main base building, optional, default is BUILDING_ANGlE
    167 //  kwargs: Takes some optional keyword arguments to tweek things
    168 //      'iberWall': may be false, 'walls' (default) or 'towers'. Determines the defensive structures Iberians get as civ bonus
     167//  kwargs: Optional. Takes an associative array with keyword arguments to tweak things:
     168//      Known keys: 'iberWall': may be false, 'walls' (default) or 'towers'. Determines the defensive structures Iberians get as civ bonus
    169169//
    170 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     170//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    171171function placeCivDefaultEntities(fx, fz, playerid, angle, kwargs)
    172172{
    173173    // Unpack kwargs
  • binaries/data/mods/public/maps/random/rmgen/wall_builder.js

     
    107107////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    108108var wallStyles = {};
    109109
    110 // Generic civ dependent wall style definition. "rome_siege" needs some tweek...
    111 var wallScaleByType = {"athen" : 1.5, "brit" : 1.5, "cart" : 1.8, "celt" : 1.5, "gaul" : 1.5, "hele" : 1.5, "iber" : 1.5, "mace" : 1.5, "maur": 1.5, "pers" : 1.5, "ptol" : 1.5, "rome" : 1.5, "sele" : 1.5, "spart" : 1.5, "rome_siege" : 1.5};
     110// Generic civ dependent wall style definition. Some, e.g. "rome_siege" needs tweaking...
     111var civList = getCivList();
     112var wallScaleByType = {};
     113for (var i = 0; i < civList.length; i++)
     114{
     115    if (civList[i] == "cart")
     116        wallScaleByType[civList[i]] = 1.8;
     117    else if (civList[i] == "theb") // Not a full civ
     118        {}
     119    else
     120        wallScaleByType[civList[i]] = 1.5;
     121}
     122// Non-civ but civ specific wall styles
     123wallScaleByType.rome_siege = 1.5;
    112124for (var style in wallScaleByType)
    113125{
    114126    var civ = style;
     
    626638//  maxBendOff    Optional. How irregular the circle should be. 0 means regular circle, PI/2 means very irregular. Default is 0 (regular circle)
    627639//
    628640//  NOTE: Don't use wall elements with bending like corners!
    629 //  TODO: Perhaps add eccentricity and maxBendOff functionality (untill now an unused argument)
     641//  TODO: Perhaps add eccentricity
     642//  TODO: Check if maxBendOff parameter works in all cases
    630643//  TODO: Perhaps add functionality for spirals
    631644/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    632645function placeCircularWall(centerX, centerY, radius, wallPart, style, playerId, orientation, maxAngle, endWithFirst, maxBendOff)
     
    654667   
    655668    // Check arguments
    656669    if (maxBendOff > PI/2 || maxBendOff < 0)
    657         warn("placeCircularWall maxBendOff sould satisfy 0 < maxBendOff < PI/2 (~1.5) but it is: " + maxBendOff);
     670        warn("placeCircularWall maxBendOff should satisfy 0 < maxBendOff < PI/2 (~1.5) but it is: " + maxBendOff);
    658671    for (var elementIndex = 0; elementIndex < wallPart.length; elementIndex++)
    659672    {
    660673        var bending = wallStyles[style][wallPart[elementIndex]].bending;
  • binaries/data/mods/public/maps/random/wall_demo.js

     
    6161var buildableMapSize = mapSize - 2 * distToMapBorder;
    6262var actualX = distToMapBorder;
    6363var actualY = distToMapBorder;
     64
    6465// Wall styles are chosen by strings so the civ strings got by g_MapSettings.PlayerData[playerId - 1].Civ can be used
    65 // Other styles may be present as well but besides the civ styles only 'palisades' includes all wall element types (yet)
    66 const wallStyleList = ["athen", "brit", "cart", "celt", "gaul", "hele", "iber", "mace", "maur", "pers", "ptol", "rome", "sele", "spart", "rome_siege", "palisades"];
     66var wallStyleList = getCivList();
     67// Remove civ "theb" if present (not a full faction)
     68if (wallStyleList.indexOf("theb") != -1)
     69    wallStyleList.splice(wallStyleList.indexOf("theb"), 1);
     70// Other styles may be available as well...
     71wallStyleList.push("rome_siege");
     72wallStyleList.push("palisades");
    6773
    6874
    6975////////////////////////////////////////
     
    7581    var startX = actualX + styleIndex * buildableMapSize/wallStyleList.length; // X coordinate of the first wall element
    7682    var startY = actualY; // Y coordinate of the first wall element
    7783    var style = wallStyleList[styleIndex]; // // The wall's style like 'cart', 'celt', 'hele', 'iber', 'pers', 'rome', 'romeSiege' or 'palisades'
    78     var orientation = styleIndex * PI/64; // Orientation of the first wall element. 0 means 'outside' or 'front' is right (positive X, like object placement)
     84    var orientation = PI/16 * sin(styleIndex * PI/4); // Orientation of the first wall element. 0 means 'outside' or 'front' is right (positive X, like object placement in Atlas)
    7985    // That means the wall will be build towards top (positive Y) if no corners are used
    8086    var playerId = 0; // Owner of the wall (like in placeObject). 0 is Gaia, 1 is Player 1 (default colour blue), ...
    8187    placeWall(startX, startY, wall, style, playerId, orientation); // Actually placing the wall
     
    155161{
    156162    for (var wallIndex = 0; wallIndex < numWallsPerStyle; wallIndex++)
    157163    {
    158         var startX = actualX + (styleIndex * numWallsPerStyle + wallIndex) * distToOtherWalls; // X coordinate the wall will start from
     164        var startX = actualX + (styleIndex * numWallsPerStyle + wallIndex) * buildableMapSize/wallStyleList.length/numWallsPerStyle; // X coordinate the wall will start from
    159165        var startY = actualY; // Y coordinate the wall will start from
    160166        var endX = startX; // X coordinate the wall will end
    161167        var endY = actualY + (wallIndex + 1) * maxWallLength/numWallsPerStyle; // Y coordinate the wall will end
     
    167173        // placeObject(endX, endY, 'other/obelisk', 0, 0*PI); // Place visual marker to see where exsactly the wall ends
    168174    }
    169175}
    170 actualX = distToMapBorder; // Reset actualX
    171 actualY += maxWallLength + distToOtherWalls; // Increase actualY for next wall placement method
    172176
    173177
    174178// Export map data
  • binaries/data/mods/public/maps/random/wall_demo.json

     
    22    "settings" : {
    33        "Name" : "Wall Demo",
    44        "Script" : "wall_demo.js",
    5         "Description" : "A demonstration of wall placement methods/code in random maps. Very large map size is recommended.",
     5        "Description" : "A demonstration of wall placement methods/code in random maps. Giant map size is recommended!",
    66        "BaseTerrain" : ["grass1"],
    77        "BaseHeight" : 0,
    88        "Keywords": ["demo"],