Ticket #2944: generic_wall_builder_rmgen2015-4-12.patch

File generic_wall_builder_rmgen2015-4-12.patch, 21.6 KB (added by FeXoR, 9 years ago)

Patch for r16533

  • binaries/data/mods/public/maps/random/belgian_uplands.js

     
    2121// Heightmap functionality
    2222//////////
    2323
    24 // Some general heightmap settings
    25 const MIN_HEIGHT = - SEA_LEVEL; // 20, should be set in the libs!
    26 const MAX_HEIGHT = 0xFFFF/HEIGHT_UNITS_PER_METRE - SEA_LEVEL; // A bit smaler than 90, should be set in the libs!
    27 
    2824// Add random heightmap generation functionality
    2925function getRandomReliefmap(minHeight, maxHeight)
    3026{
  • binaries/data/mods/public/maps/random/rmgen/library.js

     
    66const PI = Math.PI;
    77const TWO_PI = 2 * Math.PI;
    88const TERRAIN_SEPARATOR = "|";
    9 const SEA_LEVEL = 20.0;
     9const SEA_LEVEL = 160.0;
    1010const CELL_SIZE = 4;
    1111const HEIGHT_UNITS_PER_METRE = 92;
    1212const MIN_MAP_SIZE = 128;
    1313const MAX_MAP_SIZE = 512;
    1414const FALLBACK_CIV = "athen";
     15// Constants needed for heightmap_manipulation.js
     16const MAX_HEIGHT_RANGE = 0xFFFF / HEIGHT_UNITS_PER_METRE // Engine limit, Roughly 700 meters
     17const MIN_HEIGHT = - SEA_LEVEL;
     18const MAX_HEIGHT = MAX_HEIGHT_RANGE - SEA_LEVEL;
    1519
    1620/////////////////////////////////////////////////////////////////////////////////////////////
    1721//  Utility functions
     
    394398    return g_MapSettings.PlayerData.length - 1;
    395399}
    396400
     401// Takes nothing, returns an array of strings representing all available civilizations
     402function getCivList()
     403{
     404    var raw_civData = RMS.GetCivData();
     405    var civList = [];
     406    for (var i = 0; i < raw_civData.length; ++i)
     407        civList.push(JSON.parse(raw_civData[i]).Code);
     408   
     409    return civList;
     410}
     411
     412// Takes nothing, returns an associative array with civ strings as keys containing all unpacked civ data (Templates need to be unpacked with RMS.GetTemplate() if needed)
     413function getFullCivData()
     414{
     415    var rawCivData = RMS.GetCivData();
     416    var unpackedCivData = {};
     417    for (var i = 0; i < rawCivData.length; i++)
     418    {
     419        var singleCivData = JSON.parse(rawCivData[i]);
     420        unpackedCivData[singleCivData.Code] = singleCivData;
     421    }
     422   
     423    return unpackedCivData;
     424}
     425
     426// Takes a player number (0-7, so Gaia excluded). Returns this players civ string
     427// ToDo: If the player number is to high an error will occur (and the fallback won't be reached)!
    397428function getCivCode(player)
    398429{
    399430    if (g_MapSettings.PlayerData[player+1].Civ)
    400431        return g_MapSettings.PlayerData[player+1].Civ;
    401432
    402     warn("undefined civ specified for player " + (player + 1) + ", falling back to '" + FALLBACK_CIV + "'");
     433    warn("Undefined civ specified for player " + (player + 1) + ", falling back to '" + FALLBACK_CIV + "'");
    403434    return FALLBACK_CIV;
    404435}
    405436
  • binaries/data/mods/public/maps/random/rmgen/mapgen.js

     
    1 var TILE_CENTERED_HEIGHT_MAP = false;
     1var TILE_CENTERED_HEIGHT_MAP = false; // Only touch this if you REALLY KNOW what you are doing!
    22var WATER_LEVEL_CHANGED = false;
    33
    44var g_Map;
  • 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, "gaul" : 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 civData = getFullCivData();
     113var wallScaleByType = {};
     114for (var i = 0; i < civList.length; i++)
     115{
     116    var civ = civList[i];
     117    var wallSets = civData[civ].WallSets;
     118    if (wallSets.hasOwnProperty("Stone"))
     119        wallScaleByType[civ] = wallSets.Stone.Scale; // Wallset Stone still hardcoded
     120}
     121// Non-civ but civ specific wall styles
     122wallScaleByType.rome_siege = 1.5;
    112123for (var style in wallScaleByType)
    113124{
    114125    var civ = style;
     
    161172wallStyles["pers"]["wallFort"] = new WallElement("wallFort", "structures/pers_fortress", PI, 5.6/*5.5*/, 1.9/*1.7*/);
    162173wallStyles["ptol"]["wallFort"] = new WallElement("wallFort", "structures/ptol_fortress", 2*PI/2 /* PI/2 */, 5.1 /* 5.6 */, 1.9 /* 1.9 */);
    163174wallStyles["rome"]["wallFort"] = new WallElement("wallFort", "structures/rome_fortress", PI, 6.3, 2.1);
    164 wallStyles["sele"]["wallFort"] = new WallElement("wallFort", "structures/sele_fortress", 2*PI/2 /* PI/2 */, 5.1 /* 5.6 */, 1.9 /* 1.9 */);
    165175wallStyles["spart"]["wallFort"] = new WallElement("wallFort", "structures/spart_fortress", 2*PI/2 /* PI/2 */, 5.1 /* 5.6 */, 1.9 /* 1.9 */);
    166176// Adjust "rome_siege" style
    167177wallStyles["rome_siege"]["wallFort"] = new WallElement("wallFort", "structures/rome_army_camp", PI, 7.2, 2);
     
    339349    {
    340350        var element = wallStyles[style][wall[i]];
    341351        if (element === undefined && i == 0)
    342             warn("No valid wall element: " + wall[i]);
     352            warn("No valid wall element: style = " + style + ", wall[" + i + "] = " + wall[i] + ", wallStyles[" + style + "][wall[" + i + "]] = " + wallStyles[style][wall[i]] + ", element = " + element + ", wall = " + wall);
    343353        // Indentation
    344354        var placeX = wallX - element.indent * cos(orientation);
    345355        var placeY = wallY - element.indent * sin(orientation);
     
    351361            orientation += element.bending;
    352362            var nextElement = wallStyles[style][wall[i+1]];
    353363            if (nextElement === undefined)
    354                 warn("No valid wall element: " + wall[i+1]);
     364                warn("No valid wall element: style = " + style + ", wall[" + (i+1) + "] = " + wall[i+1] + ", wallStyles[" + style + "][wall[" + (i+1) + "]] = " + wallStyles[style][wall[i+1]] + ", nextElement = " + uneval(nextElement) + ", wall = " + wall);
    355365            var distance = (element.width + nextElement.width)/2;
    356366            // Corrections for elements with indent AND bending
    357367            var indent = element.indent;
     
    624634//  maxBendOff    Optional. How irregular the circle should be. 0 means regular circle, PI/2 means very irregular. Default is 0 (regular circle)
    625635//
    626636//  NOTE: Don't use wall elements with bending like corners!
    627 //  TODO: Perhaps add eccentricity and maxBendOff functionality (untill now an unused argument)
     637//  TODO: Perhaps add eccentricity
     638//  TODO: Check if maxBendOff parameter works in all cases
    628639//  TODO: Perhaps add functionality for spirals
    629640/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    630641function placeCircularWall(centerX, centerY, radius, wallPart, style, playerId, orientation, maxAngle, endWithFirst, maxBendOff)
     
    652663   
    653664    // Check arguments
    654665    if (maxBendOff > PI/2 || maxBendOff < 0)
    655         warn("placeCircularWall maxBendOff sould satisfy 0 < maxBendOff < PI/2 (~1.5) but it is: " + maxBendOff);
     666        warn("placeCircularWall maxBendOff should satisfy 0 < maxBendOff < PI/2 (~1.5) but it is: " + maxBendOff);
    656667    for (var elementIndex = 0; elementIndex < wallPart.length; elementIndex++)
    657668    {
    658669        var bending = wallStyles[style][wallPart[elementIndex]].bending;
  • binaries/data/mods/public/maps/random/schwarzwald.js

     
    131131// Setup paths
    132132var pathSucsessRadius = baseRadius/2;
    133133var pathAngleOff = PI/2;
    134 var pathWidth = 10; // This is not really the path's thickness in tiles but the number of tiles in the clumbs of the path
     134var pathWidth = 10; // This is not really the path's thickness in tiles but the number of tiles in the clumps of the path
    135135
    136136// Setup additional resources
    137137var resourceRadius = 2*mapRadius/3; // 3*mapRadius/8;
     
    232232//
    233233////////////////
    234234
    235 // Some heightmap constants
    236 const MIN_HEIGHT = - SEA_LEVEL; // -20
    237 const MAX_HEIGHT = 0xFFFF/HEIGHT_UNITS_PER_METRE - SEA_LEVEL; // A bit smaller than 90
    238 
    239235// Get the diferrence between minimum and maxumum height
    240236function getMinAndMaxHeight(reliefmap)
    241237{
  • binaries/data/mods/public/maps/random/wall_demo.js

     
    6262var actualX = distToMapBorder;
    6363var actualY = distToMapBorder;
    6464// Wall styles are chosen by strings so the civ strings got by getCivCode() 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", "gaul", "iber", "mace", "maur", "pers", "ptol", "rome", "sele", "spart", "rome_siege", "palisades"];
     65var wallStyleList = getCivList();
     66// Other styles may be available as well...
     67wallStyleList.push("rome_siege");
     68wallStyleList.push("palisades");
     69// Check if all wall styles are present and remove unknown ones
     70for (var i = 0; i < wallStyleList.length; i++)
     71    if (!wallStyles.hasOwnProperty(wallStyleList[i]))
     72        wallStyleList.splice(i, 1);
    6773
    6874
    6975////////////////////////////////////////
     
    7480{
    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
    77     var style = wallStyleList[styleIndex]; // // The wall's style like 'cart', '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)
     83    var style = wallStyleList[styleIndex]; // The wall's style like 'cart', 'iber', 'pers', 'rome', 'romeSiege' or 'palisades'
     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 color 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"],
  • binaries/data/mods/public/simulation/data/civs/athen.json

     
    109109            "Special":"Train heroes and research technology pertaining to heroes."
    110110        }
    111111    ],
     112    "WallSets":
     113    {
     114        "Palisades":
     115        {
     116            "Template": "other/wallset_palisade",
     117            "Scale": 0.55
     118        },
     119        "Stone":
     120        {
     121            "Template": "structures/athen_wallset_stone",
     122            "Scale": 1.5
     123        }
     124    },
    112125    "StartEntities":
    113126    [
    114127        {
  • binaries/data/mods/public/simulation/data/civs/brit.json

     
    8787            "Special": ""
    8888        }
    8989    ],
     90    "WallSets":
     91    {
     92        "Palisades":
     93        {
     94            "Template": "other/wallset_palisade",
     95            "Scale": 0.55
     96        },
     97        "Stone":
     98        {
     99            "Template": "structures/athen_wallset_stone",
     100            "Scale": 1.5
     101        }
     102    },
    90103    "StartEntities":
    91104    [
    92105        {
  • binaries/data/mods/public/simulation/data/civs/cart.json

     
    112112            "Special":"Hire Iberian mercenaries."
    113113        }       
    114114    ],
     115    "WallSets":
     116    {
     117        "Palisades":
     118        {
     119            "Template": "other/wallset_palisade",
     120            "Scale": 0.55
     121        },
     122        "Stone":
     123        {
     124            "Template": "structures/athen_wallset_stone",
     125            "Scale": 1.8
     126        }
     127    },
    115128    "StartEntities":
    116129    [
    117130        {
  • binaries/data/mods/public/simulation/data/civs/gaul.json

     
    8787            "Special": ""
    8888        }
    8989    ],
     90    "WallSets":
     91    {
     92        "Palisades":
     93        {
     94            "Template": "other/wallset_palisade",
     95            "Scale": 0.55
     96        },
     97        "Stone":
     98        {
     99            "Template": "structures/athen_wallset_stone",
     100            "Scale": 1.5
     101        }
     102    },
    90103    "StartEntities":
    91104    [
    92105        {
  • binaries/data/mods/public/simulation/data/civs/iber.json

     
    8585            "Special": "Defensive Aura - Gives all Iberian units and buildings within vision range of the monument a 10-15% attack boost. Build Limit: Only 5 may be built per map."
    8686        }
    8787    ],
     88    "WallSets":
     89    {
     90        "Palisades":
     91        {
     92            "Template": "other/wallset_palisade",
     93            "Scale": 0.55
     94        },
     95        "Stone":
     96        {
     97            "Template": "structures/athen_wallset_stone",
     98            "Scale": 1.5
     99        }
     100    },
    88101    "StartEntities":
    89102    [
    90103        {
  • binaries/data/mods/public/simulation/data/civs/mace.json

     
    114114            "Special":"Constructs and upgrades all Macedonian siege engines."
    115115        }
    116116    ],
     117    "WallSets":
     118    {
     119        "Palisades":
     120        {
     121            "Template": "other/wallset_palisade",
     122            "Scale": 0.55
     123        },
     124        "Stone":
     125        {
     126            "Template": "structures/athen_wallset_stone",
     127            "Scale": 1.5
     128        }
     129    },
    117130    "StartEntities":
    118131    [
    119132        {
  • binaries/data/mods/public/simulation/data/civs/maur.json

     
    9494            "Special":"Contentment: +10% Health and +10% resource gathering rates for all citizens and allied citizens within its range. Can be built anywhere except in enemy territory. Max Built: 10."
    9595        }
    9696    ],
     97    "WallSets":
     98    {
     99        "Palisades":
     100        {
     101            "Template": "other/wallset_palisade",
     102            "Scale": 0.55
     103        },
     104        "Stone":
     105        {
     106            "Template": "structures/athen_wallset_stone",
     107            "Scale": 1.5
     108        }
     109    },
    97110    "StartEntities":
    98111    [
    99112        {
  • binaries/data/mods/public/simulation/data/civs/pers.json

     
    104104            "Special": "Train heroes and Persian Immortals. Gives a slow trickle of all resources as 'Satrapy Tribute.'"
    105105        }
    106106    ],
     107    "WallSets":
     108    {
     109        "Palisades":
     110        {
     111            "Template": "other/wallset_palisade",
     112            "Scale": 0.55
     113        },
     114        "Stone":
     115        {
     116            "Template": "structures/athen_wallset_stone",
     117            "Scale": 1.5
     118        }
     119    },
    107120    "StartEntities":
    108121    [
    109122        {
  • binaries/data/mods/public/simulation/data/civs/ptol.json

     
    113113            "Special":"When built along the shoreline, removes shroud of darkness over all the water, revealing all the coast lines on the map. Limit: 1."
    114114        }
    115115    ],
     116    "WallSets":
     117    {
     118        "Palisades":
     119        {
     120            "Template": "other/wallset_palisade",
     121            "Scale": 0.55
     122        },
     123        "Stone":
     124        {
     125            "Template": "structures/athen_wallset_stone",
     126            "Scale": 1.5
     127        }
     128    },
    116129    "StartEntities":
    117130    [
    118131        {
  • binaries/data/mods/public/simulation/data/civs/rome.json

     
    8989            "Special": "Can be built in neutral and enemy territory to strangle enemy towns."
    9090        }
    9191    ],
     92    "WallSets":
     93    {
     94        "Palisades":
     95        {
     96            "Template": "other/wallset_palisade",
     97            "Scale": 0.55
     98        },
     99        "Stone":
     100        {
     101            "Template": "structures/athen_wallset_stone",
     102            "Scale": 1.5
     103        },
     104        "Siege":
     105        {
     106            "Template": "structures/rome_wallset_siege",
     107            "Scale": 1.5
     108        }
     109    },
    92110    "StartEntities":
    93111    [
    94112        {
  • binaries/data/mods/public/simulation/data/civs/sele.json

     
    114114            "Special":"This is the Seleucid expansion building, similar to Civic Centers for other factions. It is weaker and carries a smaller territory influence, but is cheaper and built faster."
    115115        }
    116116    ],
     117    "WallSets":
     118    {
     119        "Palisades":
     120        {
     121            "Template": "other/wallset_palisade",
     122            "Scale": 0.55
     123        }
     124    },
    117125    "StartEntities":
    118126    [
    119127        {
  • binaries/data/mods/public/simulation/data/civs/spart.json

     
    105105            "Special":"Train heroes and Spartiates and research technologies related to them."
    106106        }
    107107    ],
     108    "WallSets":
     109    {
     110        "Palisades":
     111        {
     112            "Template": "other/wallset_palisade",
     113            "Scale": 0.55
     114        },
     115        "Stone":
     116        {
     117            "Template": "structures/athen_wallset_stone",
     118            "Scale": 1.5
     119        }
     120    },
    108121    "StartEntities":
    109122    [
    110123        {