Invincible women on survival of the fittest to prevent women fights and cheap tower...
[0ad.git] / binaries / data / mods / public / maps / random / wall_demo.js
blobde3e9169e9f2de1e092ffd236d3511bb6fea95ce
1 RMS.LoadLibrary("rmgen");
3 // initialize map
4 log("Initializing map...");
5 InitMap();
8 // General map setup
9 var mapSize = getMapSize();
10 var mapCenterX = mapSize/2;
11 var mapCenterY = mapSize/2;
12 const BUILDING_ANlE = -PI/4;
15 ////////////////////////////////////////
16 // Demonstration code for wall placement
17 ////////////////////////////////////////
19 // Some general notes to the arguments:
21 // First all the place functions take the coordinates needed to place the wall
22 // X and Y coordinate are taken in seperate arguments like in placeObject
23 // Their meaning differs for different placement methods but are mainly self explanatory
24 // placeLinearWall takes 4 arguments here (2 coordinates) for startX, startY, targetX and targetY
26 // The next argument is always the 'wall' definition, an array of wall element type strings in most cases
27 // That looks like ['endLeft', 'wall', 'tower', 'wall', 'endRight', 'entry', 'endLeft', 'wall', 'tower', 'wall', 'endRight']
28 // For placeCircularWall and placeLinearWall only wall parts are needed like: ['tower', 'wall']
29 // They will automatically end with the first wall element if that makes sense (e.g. the wall is not closed)
30 // NOTE: They take further optional arguments to adjust this behaviour (See the wall_builder.js for that)
31 // placeFortress just takes a fortress type string that includes the wall definition
32 // The default fortress type strings are made for easy placement of predefined fortresses
33 // They are chosen like map sizes: 'tiny', 'small', 'medium', 'normal', 'large', 'veryLarge' and 'giant'
34 // NOTE: To place a custom fortress use placeCustomFortress instead
35 // It takes an instance of the Fortress class instead of the default fortress type strings
37 // The next argument is always the wall style string
38 // Wall styles are chosen by strings so the civ strings got by getCivCode() can be used
39 // Other styles may be present as well but besides the civ styles only 'palisades' includes all wall element types (yet)
41 // The next argument is always the index of the player that owns the wall.
42 // 0 is Gaia, 1 is Player 1 (default color blue), 2 is Player 2 (default color red), ...
44 // The next argument is an angle defining the orientation of the wall
45 // placeLinearWall does not need an angle since it's defined by startX/Y and targetX/Y
46 // Orientation works like the angle argument in placeObject
47 // 0 is always right (towards positive X)
48 // Raising the angle will rotate the wall counter-clockwise (mathmatical positive in default 2D)
49 // PI/2 faces top (positive Y)
50 // Orientation might be a little confusing for placeWall since it defines where the wall has its 'front' or 'outside' not the direction it will be build to.
51 // It's because all other methods work like that and it's intuitive there
52 // That means the walls outside by default (orientation = 0) faces positive X and (without bending wall elements) will be build towards positive Y
54 // Some other arguments are taken but all of them are optional and in most cases not needed
55 // One example is maxAngle for placeCircularWall that defines how far the wall will circumvent the center. Default is 2*PI which makes a full circle
58 // General wall placement setup
59 const distToMapBorder = 5;
60 const distToOtherWalls = 10;
61 var buildableMapSize = mapSize - 2 * distToMapBorder;
62 var actualX = distToMapBorder;
63 var actualY = distToMapBorder;
64 // 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"];
69 ////////////////////////////////////////
70 // Custom wall placement (element based)
71 ////////////////////////////////////////
72 var wall = ['endLeft', 'wallLong', 'tower', 'wall', 'outpost', 'wall', 'cornerOut', 'wall', 'cornerIn', 'wall', 'house', 'endRight', 'entryTower', 'endLeft', 'wallShort', 'barracks', 'gate', 'tower', 'wall', 'wallFort', 'wall', 'endRight'];
73 for (var styleIndex = 0; styleIndex < wallStyleList.length; styleIndex++)
75         var startX = actualX + styleIndex * buildableMapSize/wallStyleList.length; // X coordinate of the first wall element
76         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)
79         // That means the wall will be build towards top (positive Y) if no corners are used
80         var playerId = 0; // Owner of the wall (like in placeObject). 0 is Gaia, 1 is Player 1 (default color blue), ...
81         placeWall(startX, startY, wall, style, playerId, orientation); // Actually placing the wall
83 actualX = distToMapBorder; // Reset actualX
84 actualY += 80 + distToOtherWalls; // Increase actualY for next wall placement method
86 //////////////////////////////////////////////////////////////
87 // Default fortress placement (chosen by fortress type string)
88 //////////////////////////////////////////////////////////////
89 var fortressRadius = 15; // The space the fortresses take in average. Just for design of this map
90 for (var styleIndex = 0; styleIndex < wallStyleList.length; styleIndex++)
92         var centerX = actualX + fortressRadius + styleIndex * buildableMapSize/wallStyleList.length; // X coordinate of the center of the fortress
93         var centerY = actualY + fortressRadius; // Y coordinate of the center of the fortress
94         var type = 'tiny'; // Default fortress types are like map sizes: 'tiny', 'small', 'medium', 'large', 'veryLarge', 'giant'
95         var style = wallStyleList[styleIndex]; // The wall's style like 'cart', 'iber', 'pers', 'rome', 'romeSiege' or 'palisades'
96         var playerId = 0; // Owner of the wall. 0 is Gaia, 1 is Player 1 (default color blue), ...
97         var orientation = styleIndex * PI/32; // Where the 'main entrance' of the fortress should face (like in placeObject). All fortresses walls should start with an entrance
98         placeFortress(centerX, centerY, type, style, playerId, orientation); // Actually placing the fortress
99         placeObject(centerX, centerY, 'other/obelisk', 0, 0*PI); // Place visual marker to see the center of the fortress
101 actualX = distToMapBorder; // Reset actualX
102 actualY += 2 * fortressRadius + 2 * distToOtherWalls; // Increase actualY for next wall placement method
104 //////////////////////////
105 // Circular wall placement
106 //////////////////////////
107 // NOTE: Don't use bending wall elements like corners here!
108 var radius = min((mapSize - actualY - distToOtherWalls) / 3, (buildableMapSize / wallStyleList.length - distToOtherWalls) / 2); // The radius of wall circle
109 var centerY = actualY + radius; // Y coordinate of the center of the wall circle
110 var orientation = 0; // Where the wall circle will be open if maxAngle < 2*PI, see below. Otherwise where the first wall element will be placed
111 for (var styleIndex = 0; styleIndex < wallStyleList.length; styleIndex++)
113         var centerX = actualX + radius + styleIndex * buildableMapSize/wallStyleList.length; // X coordinate of the center of the wall circle
114         var playerId = 0; // Player ID of the player owning the wall, 0 is Gaia, 1 is the first player (default blue), ...
115         var wallPart = ['tower', 'wall', 'house']; // List of wall elements the wall will be build of. Optional, default id ['wall']
116         var style = wallStyleList[styleIndex]; // The wall's style like 'cart', 'iber', 'pers', 'rome', 'romeSiege' or 'palisades'
117         var maxAngle = PI/2 * (styleIndex%3 + 2); // How far the wall should circumvent the center
118         placeCircularWall(centerX, centerY, radius, wallPart, style, playerId, orientation, maxAngle); // Actually placing the wall
119         placeObject(centerX, centerY, 'other/obelisk', 0, 0*PI); // Place visual marker to see the center of the wall circle
120         orientation += PI/16; // Increasing orientation to see how rotation works (like for object placement)
122 actualX = distToMapBorder; // Reset actualX
123 actualY += 2 * radius + distToOtherWalls; // Increase actualY for next wall placement method
125 ///////////////////////////
126 // Polygonal wall placement
127 ///////////////////////////
128 // NOTE: Don't use bending wall elements like corners here!
129 var radius = min((mapSize - actualY - distToOtherWalls) / 2, (buildableMapSize / wallStyleList.length - distToOtherWalls) / 2); // The radius of wall polygons
130 var centerY = actualY + radius; // Y coordinate of the center of the wall polygon
131 var orientation = 0; // Where the wall circle will be open if ???, see below. Otherwise where the first wall will be placed
132 for (var styleIndex = 0; styleIndex < wallStyleList.length; styleIndex++)
134         var centerX = actualX + radius + styleIndex * buildableMapSize/wallStyleList.length; // X coordinate of the center of the wall circle
135         var playerId = 0; // Player ID of the player owning the wall, 0 is Gaia, 1 is the first player (default blue), ...
136         var cornerWallElement = 'tower'; // With wall element type will be uset for the corners of the polygon
137         var wallPart = ['wall', 'tower']; // List of wall elements the wall will be build of. Optional, default id ['wall']
138         var style = wallStyleList[styleIndex]; // The wall's style like 'cart', 'iber', 'pers', 'rome', 'romeSiege' or 'palisades'
139         var numCorners = (styleIndex)%6 + 3; // How many corners the plogon will have
140         var skipFirstWall = true; // If the wall should be open towards orientation
141         placePolygonalWall(centerX, centerY, radius, wallPart, cornerWallElement, style, playerId, orientation, numCorners, skipFirstWall);
142         placeObject(centerX, centerY, 'other/obelisk', 0, 0*PI); // Place visual marker to see the center of the wall circle
143         orientation += PI/16; // Increasing orientation to see how rotation works (like for object placement)
145 actualX = distToMapBorder; // Reset actualX
146 actualY += 2 * radius + distToOtherWalls; // Increase actualY for next wall placement method
148 ////////////////////////
149 // Linear wall placement
150 ////////////////////////
151 // NOTE: Don't use bending wall elements like corners here!
152 var maxWallLength = (mapSize - actualY - distToMapBorder - distToOtherWalls); // Just for this maps design. How long the longest wall will be
153 var numWallsPerStyle = floor(buildableMapSize / distToOtherWalls / wallStyleList.length); // Just for this maps design. How many walls of the same style will be placed
154 for (var styleIndex = 0; styleIndex < wallStyleList.length; styleIndex++)
156         for (var wallIndex = 0; wallIndex < numWallsPerStyle; wallIndex++)
157         {
158                 var startX = actualX + (styleIndex * numWallsPerStyle + wallIndex) * distToOtherWalls; // X coordinate the wall will start from
159                 var startY = actualY; // Y coordinate the wall will start from
160                 var endX = startX; // X coordinate the wall will end
161                 var endY = actualY + (wallIndex + 1) * maxWallLength/numWallsPerStyle; // Y coordinate the wall will end
162                 var playerId = 0; // Player ID of the player owning the wall, 0 is Gaia, 1 is the first player (default blue), ...
163                 var wallPart = ['tower', 'wall']; // List of wall elements the wall will be build of
164                 var style = wallStyleList[styleIndex]; // The wall's style like 'cart', 'iber', 'pers', 'rome', 'romeSiege' or 'palisades'
165                 placeLinearWall(startX, startY, endX, endY, wallPart, style, playerId); // Actually placing the wall
166                 // placeObject(startX, startY, 'other/obelisk', 0, 0*PI); // Place visual marker to see where exsactly the wall begins
167                 // placeObject(endX, endY, 'other/obelisk', 0, 0*PI); // Place visual marker to see where exsactly the wall ends
168         }
170 actualX = distToMapBorder; // Reset actualX
171 actualY += maxWallLength + distToOtherWalls; // Increase actualY for next wall placement method
174 // Export map data
175 ExportMap();