Ticket #2942: wall_demo.js

File wall_demo.js, 11.7 KB (added by FeXoR, 9 years ago)

Adding Seleucids wall style for RMS wall_demo.js (changes included in the patch)

Line 
1RMS.LoadLibrary("rmgen");
2
3// initialize map
4log("Initializing map...");
5InitMap();
6
7
8// General map setup
9var mapSize = getMapSize();
10var mapCenterX = mapSize/2;
11var mapCenterY = mapSize/2;
12const BUILDING_ANlE = -PI/4;
13
14
15////////////////////////////////////////
16// Demonstration code for wall placement
17////////////////////////////////////////
18
19// Some general notes to the arguments:
20
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
25
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
36
37// The next argument is always the wall style string
38// Wall styles are chosen by strings so the civ strings got by g_MapSettings.PlayerData[playerId - 1].Civ can be used
39// Other styles may be present as well but besides the civ styles only 'palisades' includes all wall element types (yet)
40
41// The next argument is always the index of the player that owns the wall.
42// 0 is Gaia, 1 is Player 1 (default colour blue), 2 is Player 2 (default colour red), ...
43
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
53
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
56
57
58// General wall placement setup
59const distToMapBorder = 5;
60const distToOtherWalls = 10;
61var buildableMapSize = mapSize - 2 * distToMapBorder;
62var actualX = distToMapBorder;
63var actualY = distToMapBorder;
64// 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)
66const wallStyleList = ["athen", "brit", "cart", "celt", "gaul", "hele", "iber", "mace", "maur", "pers", "ptol", "rome", "sele", "spart", "rome_siege", "palisades"];
67
68
69////////////////////////////////////////
70// Custom wall placement (element based)
71////////////////////////////////////////
72var wall = ['endLeft', 'wallLong', 'tower', 'wall', 'outpost', 'wall', 'cornerOut', 'wall', 'cornerIn', 'wall', 'house', 'endRight', 'entryTower', 'endLeft', 'wallShort', 'barracks', 'gate', 'tower', 'wall', 'wallFort', 'wall', 'endRight'];
73for (var styleIndex = 0; styleIndex < wallStyleList.length; styleIndex++)
74{
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', '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)
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 colour blue), ...
81 placeWall(startX, startY, wall, style, playerId, orientation); // Actually placing the wall
82}
83actualX = distToMapBorder; // Reset actualX
84actualY += 80 + distToOtherWalls; // Increase actualY for next wall placement method
85
86//////////////////////////////////////////////////////////////
87// Default fortress placement (chosen by fortress type string)
88//////////////////////////////////////////////////////////////
89var fortressRadius = 15; // The space the fortresses take in average. Just for design of this map
90for (var styleIndex = 0; styleIndex < wallStyleList.length; styleIndex++)
91{
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', 'celt', 'hele', 'iber', 'pers', 'rome', 'romeSiege' or 'palisades'
96 var playerId = 0; // Owner of the wall. 0 is Gaia, 1 is Player 1 (default colour 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
100}
101actualX = distToMapBorder; // Reset actualX
102actualY += 2 * fortressRadius + 2 * distToOtherWalls; // Increase actualY for next wall placement method
103
104//////////////////////////
105// Circular wall placement
106//////////////////////////
107// NOTE: Don't use bending wall elements like corners here!
108var radius = min((mapSize - actualY - distToOtherWalls) / 3, (buildableMapSize / wallStyleList.length - distToOtherWalls) / 2); // The radius of wall circle
109var centerY = actualY + radius; // Y coordinate of the center of the wall circle
110var orientation = 0; // Where the wall circle will be open if maxAngle < 2*PI, see below. Otherwise where the first wall element will be placed
111for (var styleIndex = 0; styleIndex < wallStyleList.length; styleIndex++)
112{
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', 'celt', 'hele', '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)
121}
122actualX = distToMapBorder; // Reset actualX
123actualY += 2 * radius + distToOtherWalls; // Increase actualY for next wall placement method
124
125///////////////////////////
126// Polygonal wall placement
127///////////////////////////
128// NOTE: Don't use bending wall elements like corners here!
129var radius = min((mapSize - actualY - distToOtherWalls) / 2, (buildableMapSize / wallStyleList.length - distToOtherWalls) / 2); // The radius of wall polygons
130var centerY = actualY + radius; // Y coordinate of the center of the wall polygon
131var orientation = 0; // Where the wall circle will be open if ???, see below. Otherwise where the first wall will be placed
132for (var styleIndex = 0; styleIndex < wallStyleList.length; styleIndex++)
133{
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', 'celt', 'hele', '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)
144}
145actualX = distToMapBorder; // Reset actualX
146actualY += 2 * radius + distToOtherWalls; // Increase actualY for next wall placement method
147
148////////////////////////
149// Linear wall placement
150////////////////////////
151// NOTE: Don't use bending wall elements like corners here!
152var maxWallLength = (mapSize - actualY - distToMapBorder - distToOtherWalls); // Just for this maps design. How long the longest wall will be
153var numWallsPerStyle = floor(buildableMapSize / distToOtherWalls / wallStyleList.length); // Just for this maps design. How many walls of the same style will be placed
154for (var styleIndex = 0; styleIndex < wallStyleList.length; styleIndex++)
155{
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', 'celt', 'hele', '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 }
169}
170actualX = distToMapBorder; // Reset actualX
171actualY += maxWallLength + distToOtherWalls; // Increase actualY for next wall placement method
172
173
174// Export map data
175ExportMap();