Ticket #2944: generic_wall_builder_rmgen.patch
File generic_wall_builder_rmgen.patch, 8.4 KB (added by , 9 years ago) |
---|
-
binaries/data/mods/public/maps/random/rmgen/library.js
394 394 return g_MapSettings.PlayerData.length; 395 395 } 396 396 397 // Takes nothing, Returns an array of strings representing all available civilizations 398 function 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 397 408 function getCivCode(player) 398 409 { 399 410 if (g_MapSettings.PlayerData[player].Civ) -
binaries/data/mods/public/maps/random/rmgen/misc.js
157 157 } 158 158 } 159 159 160 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 160 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 161 161 // placeCivDefaultEntities 162 162 // 163 163 // Creates the default starting player entities depending on the players civ 164 164 // fx&fy: position of player base 165 165 // playerid: id of player 166 166 // angle: angle of main base building, optional, default is BUILDING_ANGlE 167 // kwargs: Takes some optional keyword arguments to tweek things168 // 'iberWall': may be false, 'walls' (default) or 'towers'. Determines the defensive structures Iberians get as civ bonus167 // 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 169 169 // 170 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 170 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 171 171 function placeCivDefaultEntities(fx, fz, playerid, angle, kwargs) 172 172 { 173 173 // Unpack kwargs -
binaries/data/mods/public/maps/random/rmgen/wall_builder.js
107 107 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 108 108 var wallStyles = {}; 109 109 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... 111 var civList = getCivList(); 112 var wallScaleByType = {}; 113 for (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 123 wallScaleByType.rome_siege = 1.5; 112 124 for (var style in wallScaleByType) 113 125 { 114 126 var civ = style; … … 626 638 // maxBendOff Optional. How irregular the circle should be. 0 means regular circle, PI/2 means very irregular. Default is 0 (regular circle) 627 639 // 628 640 // 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 630 643 // TODO: Perhaps add functionality for spirals 631 644 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 632 645 function placeCircularWall(centerX, centerY, radius, wallPart, style, playerId, orientation, maxAngle, endWithFirst, maxBendOff) … … 654 667 655 668 // Check arguments 656 669 if (maxBendOff > PI/2 || maxBendOff < 0) 657 warn("placeCircularWall maxBendOff s ould 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); 658 671 for (var elementIndex = 0; elementIndex < wallPart.length; elementIndex++) 659 672 { 660 673 var bending = wallStyles[style][wallPart[elementIndex]].bending; -
binaries/data/mods/public/maps/random/wall_demo.js
61 61 var buildableMapSize = mapSize - 2 * distToMapBorder; 62 62 var actualX = distToMapBorder; 63 63 var actualY = distToMapBorder; 64 64 65 // 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"]; 66 var wallStyleList = getCivList(); 67 // Remove civ "theb" if present (not a full faction) 68 if (wallStyleList.indexOf("theb") != -1) 69 wallStyleList.splice(wallStyleList.indexOf("theb"), 1); 70 // Other styles may be available as well... 71 wallStyleList.push("rome_siege"); 72 wallStyleList.push("palisades"); 67 73 68 74 69 75 //////////////////////////////////////// … … 75 81 var startX = actualX + styleIndex * buildableMapSize/wallStyleList.length; // X coordinate of the first wall element 76 82 var startY = actualY; // Y coordinate of the first wall element 77 83 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) 79 85 // That means the wall will be build towards top (positive Y) if no corners are used 80 86 var playerId = 0; // Owner of the wall (like in placeObject). 0 is Gaia, 1 is Player 1 (default colour blue), ... 81 87 placeWall(startX, startY, wall, style, playerId, orientation); // Actually placing the wall … … 155 161 { 156 162 for (var wallIndex = 0; wallIndex < numWallsPerStyle; wallIndex++) 157 163 { 158 var startX = actualX + (styleIndex * numWallsPerStyle + wallIndex) * distToOtherWalls; // X coordinate the wall will start from164 var startX = actualX + (styleIndex * numWallsPerStyle + wallIndex) * buildableMapSize/wallStyleList.length/numWallsPerStyle; // X coordinate the wall will start from 159 165 var startY = actualY; // Y coordinate the wall will start from 160 166 var endX = startX; // X coordinate the wall will end 161 167 var endY = actualY + (wallIndex + 1) * maxWallLength/numWallsPerStyle; // Y coordinate the wall will end … … 167 173 // placeObject(endX, endY, 'other/obelisk', 0, 0*PI); // Place visual marker to see where exsactly the wall ends 168 174 } 169 175 } 170 actualX = distToMapBorder; // Reset actualX171 actualY += maxWallLength + distToOtherWalls; // Increase actualY for next wall placement method172 176 173 177 174 178 // Export map data -
binaries/data/mods/public/maps/random/wall_demo.json
2 2 "settings" : { 3 3 "Name" : "Wall Demo", 4 4 "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!", 6 6 "BaseTerrain" : ["grass1"], 7 7 "BaseHeight" : 0, 8 8 "Keywords": ["demo"],