Ticket #2258: undefined_civ_fex.diff

File undefined_civ_fex.diff, 31.4 KB (added by FeXoR, 11 years ago)

SVN .diff including the modified wall_builder.js allongside with the (needed) previous modifications to library.js by sanderd17

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

     
    1111const HEIGHT_UNITS_PER_METRE = 732;
    1212const MIN_MAP_SIZE = 128;
    1313const MAX_MAP_SIZE = 512;
     14const FALLBACK_CIV = "athen";
    1415
    1516/////////////////////////////////////////////////////////////////////////////////////////////
    1617//  Utility functions
     
    395396
    396397function getCivCode(player)
    397398{
    398     return g_MapSettings.PlayerData[player].Civ;
     399    if (g_MapSettings.PlayerData[player].Civ)
     400        return g_MapSettings.PlayerData[player].Civ;
     401
     402    warn("undefined civ specified for player " + (player + 1) + ", falling back to '" + FALLBACK_CIV + "'");
     403    return FALLBACK_CIV;
    399404}
    400405
    401406function areAllies(player1, player2)
     
    470475    var civ = getCivCode(player);
    471476    if (!g_CivData[civ] || !g_CivData[civ].StartEntities || !g_CivData[civ].StartEntities.length)
    472477    {
    473         warn("Invalid or unimplemented civ '"+civ+"' specified, falling back to 'athen'");
    474         civ = "athen";
     478        warn("Invalid or unimplemented civ '"+civ+"' specified, falling back to '" + FALLBACK_CIV + "'");
     479        civ = FALLBACK_CIV;
    475480    }
    476481   
    477482    return g_CivData[civ].StartEntities;
  • data/mods/public/maps/random/rmgen/wall_builder.js

     
    55// To do:
    66// Check if all wall placement methods work with wall elements with entity === undefined (some still might raise errors in that case)
    77// Rename wall elements to fit the entity names so that entity = "structures/" + "civ + "_" + wallElement.type in the common case (as far as possible)
    8 // Perhaps add roman army camp to style palisades and add upgraded/balanced default palisade fortress types matching civ default fortresses strength
     8// Perhaps add Roman army camp to style palisades and add upgraded/balanced default palisade fortress types matching civ default fortresses strength
    99// Perhaps add further wall elements cornerInHalf, cornerOutHalf (banding PI/4) and adjust default fortress types to better fit in the octagonal territory of a civil center
    1010// Perhaps swap angle and width in WallElement class(?) definition
    1111// Adjust argument order to be always the same:
     
    2525//      maxBendOff (angle or other, unused ATM!!!)
    2626//      irregularity
    2727//      maxTrys
    28 // Add tresures to wall style "others"
     28// Add treasures to wall style "others"
    2929// Adjust documentation
    3030// Perhaps rename "endLeft" to "start" and "endRight" to "end"
    3131// ?Use available civ-type wall elements rather than palisades: Remove "endLeft" and "endRight" as default wall elements and adjust default palisade fortress types?
     
    3737//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    3838//  WallElement class definition
    3939//
    40 //  Concept: If placed unrotated the wall's course is towards positive Y (top) with "outside" right (+X) and "inside" left (-X) like unrotated entities has their droppoints right (in rmgen)
    41 //  The coure of the wall will be changed by corners (bending != 0) and so the "inside"/"outside" direction
     40//  Concept: If placed unrotated the wall's course is towards positive Y (top) with "outside" right (+X) and "inside" left (-X) like unrotated entities has their drop-points right (in rmgen)
     41//  The course of the wall will be changed by corners (bending != 0) and so the "inside"/"outside" direction
    4242//
    4343//  type    Descriptive string, example: "wallLong". NOTE: Not really needed. Mainly for custom wall elements and to get the wall element type in code
    4444//  entity  Optional. Template name string of the entity to be placed, example: "structures/cart_wall_long". Default is undefined (No entity placed)
    4545//  angle   Optional. The angle (float) added to place the entity so "outside" is right when the wall element is placed unrotated. Default is 0
    46 //  width   Optional. How far this wall element enlengthens the wall (float), if unrotated the Y space needed. Default is 0
     46//  width   Optional. How far this wall element lengthens the wall (float), if unrotated the Y space needed. Default is 0
    4747//  indent  Optional. The lateral indentation of the entity, drawn "inside" (positive values) or pushed "outside" (negative values). Default is 0
    4848//  bending Optional. How the course of the wall is changed after this element, positive is bending "in"/left/counter clockwise (like entity placement)
    4949//      NOTE: Bending is not supported by all placement functions (see there)
     
    5252{
    5353    this.type = type;
    5454    // Default wall element type documentation:
    55     // Enlengthening straight blocking (mainly left/right symetric) wall elements (Walls and wall fortifications)
     55    // Lengthening straight blocking (mainly left/right symmetric) wall elements (Walls and wall fortifications)
    5656        // "wall"          A blocking straight wall element that mainly lengthens the wall, self-explanatory
    5757        // "wallShort"     self-explanatory
    5858        // "wallLong"      self-explanatory
    59         // "tower"         A blocking straight wall element with damage potential (but for palisades) that slightly lengthens the wall, exsample: wall tower, palisade tower(No attack)
    60         // "wallFort"      A blocking straight wall element with massive damage potential that lengthens the wall, exsample: fortress, palisade fort
    61     // Enlengthening straight non/custom blocking (mainly left/right symetric) wall elements (Gates and entrys)
     59        // "tower"         A blocking straight wall element with damage potential (but for palisades) that slightly lengthens the wall, example: wall tower, palisade tower(No attack)
     60        // "wallFort"      A blocking straight wall element with massive damage potential that lengthens the wall, example: fortress, palisade fort
     61    // Lengthening straight non/custom blocking (mainly left/right symmetric) wall elements (Gates and entries)
    6262        // "gate"          A blocking straight wall element with passability determined by owner, example: gate (Functionality not yet implemented)
    6363        // "entry"         A non-blocking straight wall element (same width as gate) but without an actual template or just a flag/column/obelisk
    64         // "entryTower"    A non-blocking straight wall element (same width as gate) represented by a single (maybe indented) template, example: defense tower, wall tower, outpost, watchtower
     64        // "entryTower"    A non-blocking straight wall element (same width as gate) represented by a single (maybe indented) template, example: defence tower, wall tower, outpost, watchtower
    6565        // "entryFort"     A non-blocking straight wall element represented by a single (maybe indented) template, example: fortress, palisade fort
    6666    // Bending wall elements (Wall corners)
    6767        // "cornerIn"      A wall element bending the wall by PI/2 "inside" (left, +, see above), example: wall tower, palisade curve
    6868        // "cornerOut"     A wall element bending the wall by PI/2 "outside" (right, -, see above), example: wall tower, palisade curve
    6969        // "cornerHalfIn"  A wall element bending the wall by PI/4 "inside" (left, +, see above), example: wall tower, palisade curve. NOTE: Not yet implemented
    7070        // "cornerHalfOut" A wall element bending the wall by PI/4 "outside" (right, -, see above), example: wall tower, palisade curve. NOTE: Not yet implemented
    71     // Zero length straight indented (mainly left/right symetric) wall elements (Outposts/watchtowers and non-defensive base structures)
    72         // "outpost"       A zero-length wall element without bending far indented so it stands outside the wall, exsample: outpost, defense tower, watchtower
    73         // "house"         A zero-length wall element without bending far indented so it stands inside the wall that grants population bonus, exsample: house, hut, longhouse
    74         // "barracks"      A zero-length wall element without bending far indented so it stands inside the wall that grants unit production, exsample: barracks, tavern, ...
     71    // Zero length straight indented (mainly left/right symmetric) wall elements (Outposts/watchtowers and non-defensive base structures)
     72        // "outpost"       A zero-length wall element without bending far indented so it stands outside the wall, example: outpost, defence tower, watchtower
     73        // "house"         A zero-length wall element without bending far indented so it stands inside the wall that grants population bonus, example: house, hut, longhouse
     74        // "barracks"      A zero-length wall element without bending far indented so it stands inside the wall that grants unit production, example: barracks, tavern, ...
    7575    this.entity = entity;
    7676    this.angle = (angle !== undefined) ? angle : 0*PI;
    7777    this.width = (width !== undefined) ? width : 0;
     
    8282/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    8383//  Fortress class definition
    8484//
    85 //  A "fortress" here is a closed wall build of multiple wall elements attached togather defined in Fortress.wall
     85//  A "fortress" here is a closed wall build of multiple wall elements attached together defined in Fortress.wall
    8686//  It's mainly the abstract shape defined in a Fortress instances wall because different styles can be used for it (see wallStyles)
    8787//
    8888//  type                  Descriptive string, example: "tiny". Not really needed (WallTool.wallTypes["type string"] is used). Mainly for custom wall elements
    8989//  wall                  Optional. Array of wall element strings. Can be set afterwards. Default is an epty array.
    9090//      Example: ["entrance", "wall", "cornerIn", "wall", "gate", "wall", "entrance", "wall", "cornerIn", "wall", "gate", "wall", "cornerIn", "wall"]
    91 //  centerToFirstElement  Optional. Object with propertys "x" and "y" representing a vector from the visual center to the first wall element. Default is undefined
     91//  centerToFirstElement  Optional. Object with properties "x" and "y" representing a vector from the visual center to the first wall element. Default is undefined
    9292/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    9393function Fortress(type, wall, centerToFirstElement)
    9494{
     
    108108var wallStyles = {};
    109109
    110110// 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, "rome" : 1.5, "spart" : 1.5, "rome_siege" : 1.5};
     111var 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, "spart" : 1.5, "rome_siege" : 1.5};
    112112for (var style in wallScaleByType)
    113113{
    114114    var civ = style;
     
    127127    wallStyles[style]["wallLong"] = new WallElement("wallLong", "structures/" + style + "_wall_long", 0*PI, 6*wallScaleByType[style]);
    128128    // Gate and entrance wall elements
    129129    var gateWidth = 6*wallScaleByType[style];
    130     wallStyles[style]["gate"] = new WallElement("gate", "structures/" + style + "_wall_gate", 0*PI, gateWidth);
     130    wallStyles[style]["gate"] = new WallElement("gate", "structures/" + style + "_wall_gate", PI, gateWidth);
    131131    wallStyles[style]["entry"] = new WallElement("entry", undefined, 0*PI, gateWidth);
    132132    wallStyles[style]["entryTower"] = new WallElement("entryTower", "structures/" + civ + "_defense_tower", PI, gateWidth, -4*wallScaleByType[style]);
    133133    wallStyles[style]["entryFort"] = new WallElement("entryFort", "structures/" + civ + "_fortress", 0*PI, 8*wallScaleByType[style], 6*wallScaleByType[style]);
     
    161161wallStyles["mace"]["wallFort"] = new WallElement("wallFort", "structures/mace_fortress", 2*PI/2 /* PI/2 */, 5.1 /* 5.6 */, 1.9 /* 1.9 */);
    162162wallStyles["maur"]["wallFort"] = new WallElement("wallFort", "structures/maur_fortress", PI, 5.5);
    163163wallStyles["pers"]["wallFort"] = new WallElement("wallFort", "structures/pers_fortress", PI, 5.6/*5.5*/, 1.9/*1.7*/);
     164wallStyles["ptol"]["wallFort"] = new WallElement("wallFort", "structures/athen_fortress", 2*PI/2 /* PI/2 */, 5.1 /* 5.6 */, 1.9 /* 1.9 */);
    164165wallStyles["rome"]["wallFort"] = new WallElement("wallFort", "structures/rome_fortress", PI, 6.3, 2.1);
    165166wallStyles["spart"]["wallFort"] = new WallElement("wallFort", "structures/spart_fortress", 2*PI/2 /* PI/2 */, 5.1 /* 5.6 */, 1.9 /* 1.9 */);
    166167// Adjust "rome_siege" style
     
    237238//  fortressTypes data structure for some default fortress types
    238239//
    239240//  A fortress type is just an instance of the Fortress class with actually something in it
    240 //  fortressTypes holds all the fortressess within an associative array with a descriptive string as key (e.g. maching the map size)
    241 //  Eexamples: "tiny", "veryLarge"
     241//  fortressTypes holds all the fortresses within an associative array with a descriptive string as key (e.g. matching the map size)
     242//  Examples: "tiny", "veryLarge"
    242243////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    243244var fortressTypes = {};
    244245// Setup some default fortress types
    245246// Add fortress type "tiny"
    246247fortressTypes["tiny"] = new Fortress("tiny");
    247 var wallPart = ["gate", "wall", "cornerIn", "wall"];
     248var wallPart = ["gate", "tower", "wallShort", "cornerIn", "wallShort", "tower"];
    248249fortressTypes["tiny"].wall = wallPart.concat(wallPart, wallPart, wallPart);
    249250// Add fortress type "small"
    250251fortressTypes["small"] = new Fortress("small");
    251 var wallPart = ["gate", "endLeft", "wall", "cornerIn", "wall", "endRight"];
     252var wallPart = ["gate", "tower", "wall", "cornerIn", "wall", "tower"];
    252253fortressTypes["small"].wall = wallPart.concat(wallPart, wallPart, wallPart);
    253254// Add fortress type "medium"
    254255fortressTypes["medium"] = new Fortress("medium");
    255 var wallPart = ["gate", "endLeft", "wall", "outpost", "wall",
    256     "cornerIn", "wall", "outpost", "wall", "endRight"];
     256var wallPart = ["gate", "tower", "wallLong", "cornerIn", "wallLong", "tower"];
    257257fortressTypes["medium"].wall = wallPart.concat(wallPart, wallPart, wallPart);
    258258// Add fortress type "normal"
    259259fortressTypes["normal"] = new Fortress("normal");
    260 var wallPart = ["gate", "endLeft", "wall", "tower", "wall",
    261     "cornerIn", "wall", "tower", "wall", "endRight"];
     260var wallPart = ["gate", "tower", "wall", "cornerIn", "wall", "cornerOut", "wall", "cornerIn", "wall", "tower"];
    262261fortressTypes["normal"].wall = wallPart.concat(wallPart, wallPart, wallPart);
    263262// Add fortress type "large"
    264263fortressTypes["large"] = new Fortress("large");
    265 var wallPart = ["gate", "endLeft", "wall", "outpost", "wall", "cornerIn", "wall",
    266     "cornerOut", "wall", "cornerIn", "wall", "outpost", "wall", "endRight"];
     264var wallPart = ["gate", "tower", "wallLong", "cornerIn", "wallLong", "cornerOut", "wallLong", "cornerIn", "wallLong", "tower"];
    267265fortressTypes["large"].wall = wallPart.concat(wallPart, wallPart, wallPart);
    268266// Add fortress type "veryLarge"
    269267fortressTypes["veryLarge"] = new Fortress("veryLarge");
    270 var wallPart = ["gate", "endLeft", "wall", "tower", "wall", "cornerIn", "wall",
    271     "cornerOut", "wall", "cornerIn", "wall", "tower", "wall", "endRight"];
     268var wallPart = ["gate", "tower", "wall", "cornerIn", "wall", "cornerOut", "wallLong", "cornerIn", "wallLong", "cornerOut", "wall", "cornerIn", "wall", "tower"];
    272269fortressTypes["veryLarge"].wall = wallPart.concat(wallPart, wallPart, wallPart);
    273270// Add fortress type "giant"
    274271fortressTypes["giant"] = new Fortress("giant");
    275 var wallPart = ["gate", "endLeft", "wall", "outpost", "wall", "cornerIn", "wall", "outpost", "wall",
    276     "cornerOut", "wall", "outpost", "wall", "cornerIn", "wall", "outpost", "wall", "endRight"];
     272var wallPart = ["gate", "tower", "wallLong", "cornerIn", "wallLong", "cornerOut", "wallLong", "cornerIn", "wallLong", "cornerOut", "wallLong", "cornerIn", "wallLong", "tower"];
    277273fortressTypes["giant"].wall = wallPart.concat(wallPart, wallPart, wallPart);
    278274
    279275// Setup some better looking semi default fortresses for "palisades" style
     
    283279    var newKey = fortressTypeKeys[i] + "Palisades";
    284280    var oldWall = fortressTypes[fortressTypeKeys[i]].wall;
    285281    fortressTypes[newKey] = new Fortress(newKey);
    286     var fillTowersBetween = ["wall", "endLeft", "endRight", "cornerIn", "cornerOut"];
     282    var fillTowersBetween = ["wallShort", "wall", "wallLong", "endLeft", "endRight", "cornerIn", "cornerOut"];
    287283    for (var j = 0; j < oldWall.length; j++)
    288284    {
    289285        fortressTypes[newKey].wall.push(oldWall[j]); // Only works if the first element is not in fillTowersBetween (e.g. entry or gate like it should be)
     
    323319//
    324320//  Returns a list of objects containing all information to place all the wall elements entities with placeObject (but the player ID)
    325321//  Placing the first wall element at startX/startY placed with an angle given by orientation
    326 //  An alignement can be used to get the "center" of a "wall" (more likely used for fortresses) with getCenterToFirstElement
     322//  An alignment can be used to get the "center" of a "wall" (more likely used for fortresses) with getCenterToFirstElement
    327323/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    328324function getWallAlignment(startX, startY, wall, style, orientation)
    329325{
     326    // Graciously handle arguments
     327    if (wall === undefined)
     328        wall = [];
     329    if (!wallStyles.hasOwnProperty(style))
     330    {
     331        warn("Function getWallAlignment: Unknown style: " + style + ' (falling back to "athen")');
     332        style = "athen";
     333    }
    330334    orientation = (orientation || 0);
     335   
    331336    var alignment = [];
    332337    var wallX = startX;
    333338    var wallY = startY;
     
    395400//////////////////////////////////////////////////////////////////
    396401function getWallLength(wall, style)
    397402{
     403    // Graciously handle arguments
     404    if (wall === undefined)
     405        wall = [];
     406    if (!wallStyles.hasOwnProperty(style))
     407    {
     408        warn("Function getWallLength: Unknown style: " + style + ' (falling back to "athen")');
     409        style = "athen";
     410    }
     411   
    398412    var length = 0;
    399413    for (var i = 0; i < wall.length; i++)
    400414    {
     
    424438/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    425439function placeWall(startX, startY, wall, style, playerId, orientation)
    426440{
    427     // Setup optional arguments
     441    // Graciously handle arguments
     442    if (wall === undefined)
     443        wall = [];
    428444    playerId = (playerId || 0);
    429     if (playerId == 0)
    430         style = (style || "palisades");
    431     else
    432         style = (style || g_MapSettings.PlayerData[playerId-1].Civ);
     445    if (!wallStyles.hasOwnProperty(style))
     446    {
     447        if (playerId == 0)
     448            style = (style || "palisades");
     449        else
     450            style = (getCivCode(playerId-1));
     451    }
    433452    orientation = (orientation || 0);
     453   
    434454    // Get wall alignment
    435455    var AM = getWallAlignment(startX, startY, wall, style, orientation);
    436456    // Place the wall
     
    455475/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    456476function placeCustomFortress(centerX, centerY, fortress, style, playerId, orientation)
    457477{
    458     // Setup optional arguments
    459     fortress = (fortress || fortressTypes["tiny"]);
     478    // Graciously handle arguments
     479    fortress = (fortress || fortressTypes["medium"]);
    460480    playerId = (playerId || 0);
    461     if (playerId == 0)
    462         style = (style || "palisades");
    463     else
    464         style = (style || g_MapSettings.PlayerData[playerId-1].Civ);
     481    if (!wallStyles.hasOwnProperty(style))
     482    {
     483        if (playerId == 0)
     484            style = (style || "palisades");
     485        else
     486            style = (getCivCode(playerId-1));
     487    }
    465488    orientation = (orientation || 0);
     489   
    466490    // Calculate center if fortress.centerToFirstElement is undefined (default)
    467491    var centerToFirstElement = fortress.centerToFirstElement;
    468492    if (centerToFirstElement === undefined)
     
    480504///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    481505function placeFortress(centerX, centerY, type, style, playerId, orientation)
    482506{
    483     // Setup optional arguments
    484     type = (type || "tiny");
     507    // Graciously handle arguments
     508    type = (type || "medium");
    485509    playerId = (playerId || 0);
    486     if (playerId == 0)
    487         style = (style || "palisades");
    488     else
    489         style = (style || g_MapSettings.PlayerData[playerId-1].Civ);
     510    if (!wallStyles.hasOwnProperty(style))
     511    {
     512        if (playerId == 0)
     513            style = (style || "palisades");
     514        else
     515            style = (getCivCode(playerId-1));
     516    }
    490517    orientation = (orientation || 0);
     518   
    491519    // Call placeCustomFortress with the given arguments
    492520    placeCustomFortress(centerX, centerY, fortressTypes[type], style, playerId, orientation);
    493521}
     
    495523//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    496524//  placeLinearWall
    497525//
    498 //  Places a straight wall from a given coordinate to an other repeatant using the wall parts.
     526//  Places a straight wall from a given coordinate to an other repeatedly using the wall parts.
    499527//
    500528//  startX/startY    Coordinate of the approximate beginning of the wall (Not the place of the first wall element)
    501529//  targetX/targetY  Coordinate of the approximate ending of the wall (Not the place of the last wall element)
     
    511539    // Setup optional arguments to the default
    512540    wallPart = (wallPart || ["tower", "wallLong"]);
    513541    playerId = (playerId || 0);
    514     if (playerId == 0)
    515         style = (style || "palisades");
    516     else
    517         style = (style || g_MapSettings.PlayerData[playerId-1].Civ);
     542    if (!wallStyles.hasOwnProperty(style))
     543    {
     544        if (playerId == 0)
     545            style = (style || "palisades");
     546        else
     547            style = (getCivCode(playerId-1));
     548    }
    518549    endWithFirst = typeof endWithFirst == "undefined" ? true : endWithFirst;
     550   
    519551    // Check arguments
    520552    for (var elementIndex = 0; elementIndex < wallPart.length; elementIndex++)
    521553    {
     
    578610/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    579611//  placeCircularWall
    580612//
    581 //  Place a circular wall of repeatant wall elements given in the argument wallPart arround centerX/centerY with the given radius
    582 //  The wall can be opend forming more an arc than a circle if maxAngle < 2*PI
    583 //  The orientation then determines where this open part faces (0 means right like unrotated building's droppoints)
     613//  Place a circular wall of repeated wall elements given in the argument wallPart around centerX/centerY with the given radius
     614//  The wall can be opened forming more an arc than a circle if maxAngle < 2*PI
     615//  The orientation then determines where this open part faces (0 means right like unrotated building's drop-points)
    584616//
    585617//  centerX/Y     Coordinates of the circle's center
    586 //  radius        How wide the circle should be (aproximate, especially if maxBendOff != 0)
     618//  radius        How wide the circle should be (approximate, especially if maxBendOff != 0)
    587619//  wallPart      Optional. An array of NON-BENDING wall element type strings. Default is ["tower", "wallLong"]
    588620//  style         Optional. Wall style string. Default is the civ of the given player, "palisades" for gaia
    589621//  playerId      Optional. Integer number of the player. Default is 0 (gaia)
     
    601633    // Setup optional arguments to the default
    602634    wallPart = (wallPart || ["tower", "wallLong"]);
    603635    playerId = (playerId || 0);
    604     if (playerId == 0)
    605         style = (style || "palisades");
    606     else
    607         style = (style || g_MapSettings.PlayerData[playerId-1].Civ);
     636    if (!wallStyles.hasOwnProperty(style))
     637    {
     638        if (playerId == 0)
     639            style = (style || "palisades");
     640        else
     641            style = (getCivCode(playerId-1));
     642    }
    608643    orientation = (orientation || 0);
    609644    maxAngle = (maxAngle || 2*PI);
    610645    if (endWithFirst === undefined)
     
    615650            endWithFirst = true;
    616651    }
    617652    maxBendOff = (maxBendOff || 0);
     653   
    618654    // Check arguments
    619655    if (maxBendOff > PI/2 || maxBendOff < 0)
    620656        warn("placeCircularWall maxBendOff sould satisfy 0 < maxBendOff < PI/2 (~1.5) but it is: " + maxBendOff);
     
    689725/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    690726//  placePolygonalWall
    691727//
    692 //  Place a polygonal wall of repeatant wall elements given in the argument wallPart arround centerX/centerY with the given radius
     728//  Place a polygonal wall of repeated wall elements given in the argument wallPart around centerX/centerY with the given radius
    693729//
    694730//  centerX/Y          Coordinates of the polygon's center
    695 //  radius             How wide the circle should be in wich the polygon fits
     731//  radius             How wide the circle should be in which the polygon fits
    696732//  wallPart           Optional. An array of NON-BENDING wall element type strings. Default is ["wallLong", "tower"]
    697733//  cornerWallElement  Optional. Wall element to be placed at the polygon's corners. Default is "tower"
    698734//  style              Optional. Wall style string. Default is the civ of the given player, "palisades" for gaia
     
    712748    wallPart = (wallPart || ["wallLong", "tower"]);
    713749    cornerWallElement = (cornerWallElement || "tower"); // Don't use wide elements for this. Not supported well...
    714750    playerId = (playerId || 0);
    715     if (playerId == 0)
    716         style = (style || "palisades");
    717     else
    718         style = (style || g_MapSettings.PlayerData[playerId-1].Civ);
     751    if (!wallStyles.hasOwnProperty(style))
     752    {
     753        if (playerId == 0)
     754            style = (style || "palisades");
     755        else
     756            style = (getCivCode(playerId-1));
     757    }
    719758    orientation = (orientation || 0);
    720759    numCorners = (numCorners || 8);
    721760    skipFirstWall = (skipFirstWall || true);
     761   
    722762    // Setup angles
    723763    var angleAdd = 2*PI/numCorners;
    724764    var angleStart = orientation - angleAdd/2;
     
    747787////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    748788//  placeIrregularPolygonalWall
    749789//
    750 //  Place an irregular polygonal wall of some wall parts to choose from arround centerX/centerY with the given radius
     790//  Place an irregular polygonal wall of some wall parts to choose from around centerX/centerY with the given radius
    751791//
    752792//  centerX/Y            Coordinates of the polygon's center
    753 //  radius               How wide the circle should be in wich the polygon fits
     793//  radius               How wide the circle should be in which the polygon fits
    754794//  cornerWallElement    Optional. Wall element to be placed at the polygon's corners. Default is "tower"
    755795//  style                Optional. Wall style string. Default is the civ of the given player, "palisades" for gaia
    756796//  playerId             Optional. Integer number of the player. Default is 0 (gaia)
     
    758798//  numCorners           Optional. How many corners the polygon will have. Default is 8 (matching a civ centers territory)
    759799//  irregularity         Optional. How irregular the polygon will be. 0 means regular, 1 means VERY irregular. Default is 0.5
    760800//  skipFirstWall        Optional. Boolean. If the first linear wall part will be left opened as entrance. Default is true
    761 //  wallPartsAssortment  Optional. An array of wall part arrays to choose from for each linear wall connecting the corners. Default is hard to decribe ^^
     801//  wallPartsAssortment  Optional. An array of wall part arrays to choose from for each linear wall connecting the corners. Default is hard to describe ^^
    762802//
    763803//  NOTE: wallPartsAssortment is put to the end because it's hardest to set
    764804//  NOTE: Don't use wall elements with bending like corners!
     
    770810{
    771811    // Setup optional arguments
    772812    playerId = (playerId || 0);
    773     if (playerId == 0)
    774         style = (style || "palisades");
    775     else
    776         style = (style || g_MapSettings.PlayerData[playerId-1].Civ);
    777     // Generating a generic wall part assortment with each wall part including 1 gate enlengthend by walls and towers
     813    if (!wallStyles.hasOwnProperty(style))
     814    {
     815        if (playerId == 0)
     816            style = (style || "palisades");
     817        else
     818            style = (getCivCode(playerId-1));
     819    }
     820   
     821    // Generating a generic wall part assortment with each wall part including 1 gate lengthened by walls and towers
    778822    // NOTE: It might be a good idea to write an own function for that...
    779823    var defaultWallPartsAssortment = [["wallShort"], ["wall"], ["wallLong"], ["gate", "tower", "wallShort"]];
    780824    var centeredWallPart = ["gate"];
     
    838882    {
    839883        var bestWallPart = []; // This is a simpel wall part not a wallPartsAssortment!
    840884        var bestWallLength = 99999999;
    841         // NOTE: This is not exsactly like the length the wall will be in the end. Has to be tweeked...
     885        // NOTE: This is not exactly like the length the wall will be in the end. Has to be tweaked...
    842886        var wallLength = getDistance(corners[i][0], corners[i][1], corners[(i+1)%numCorners][0], corners[(i+1)%numCorners][1]);
    843887        var numWallParts = ceil(wallLength/maxWallPartLength);
    844888        for (var partIndex = 0; partIndex < wallPartsAssortment.length; partIndex++)
     
    873917//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    874918//  placeGenericFortress
    875919//
    876 //  Places a generic fortress with towers at the edges connected with long walls and gates (entries untill gates work)
     920//  Places a generic fortress with towers at the edges connected with long walls and gates (entries until gates work)
    877921//  This is the default Iberian civ bonus starting wall
    878922//
    879 //  centerX/Y      The aproximate center coordinates of the fortress
     923//  centerX/Y      The approximate center coordinates of the fortress
    880924//  radius         The approximate radius of the wall to be placed
    881925//  playerId       Optional. Integer number of the player. Default is 0 (gaia)
    882926//  style          Optional. Wall style string. Default is the civ of the given player, "palisades" for gaia
     
    889933    // Setup optional arguments
    890934    radius = (radius || 20);
    891935    playerId = (playerId || 0);
    892     if (playerId == 0)
    893         style = (style || "palisades");
    894     else
    895         style = (style || g_MapSettings.PlayerData[playerId-1].Civ);
     936    if (!wallStyles.hasOwnProperty(style))
     937    {
     938        if (playerId == 0)
     939            style = (style || "palisades");
     940        else
     941            style = (getCivCode(playerId-1));
     942    }
    896943    irregularity = (irregularity || 1/2);
    897944    gateOccurence = (gateOccurence || 3);
    898945    maxTrys = (maxTrys || 100);
     946   
    899947    // Setup some vars
    900948    var startAngle = randFloat(0, 2*PI);
    901949    var actualOffX = radius*cos(startAngle);
  • data/mods/public/maps/random/wall_demo.js

     
    6363var actualY = distToMapBorder;
    6464// Wall styles are chosen by strings so the civ strings got by g_MapSettings.PlayerData[playerId - 1].Civ can be used
    6565// 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", "rome", "spart", "rome_siege", "palisades"];
     66const wallStyleList = ["athen", "brit", "cart", "celt", "gaul", "hele", "iber", "mace", "maur", "pers", "ptol", "rome", "spart", "rome_siege", "palisades"];
    6767
    6868
    6969////////////////////////////////////////