Ticket #1311: wall_demo.js

File wall_demo.js, 10.0 KB (added by FeXoR, 12 years ago)
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.
56// Default is 2*PI which makes a full circle
57
58
59// General wall placement setup
60const distToMapBorder = 5;
61const distToOtherWalls = 5;
62var buildableMapSize = mapSize - 2 * distToMapBorder;
63var actualX = distToMapBorder;
64var actualY = distToMapBorder;
65// Wall styles are chosen by strings so the civ strings got by g_MapSettings.PlayerData[playerId - 1].Civ can be used
66// Other styles may be present as well but besides the civ styles only 'palisades' includes all wall element types (yet)
67const wallStyleList = ['cart', 'celt', 'hele', 'iber', 'pers', 'rome', 'romeSiege', 'palisades'];
68
69
70////////////////////////////////////////
71// Custom wall placement (element based)
72////////////////////////////////////////
73var wall = ['endLeft', 'wall', 'tower', 'wall', 'outpost', 'wall', 'cornerOut', 'wall', 'cornerIn', 'wall', 'house', 'endRight', 'entryTower', 'endLeft', 'wall', 'barracks', 'gate', 'tower', 'wall', 'wallFort', 'wall', 'endRight'];
74for (var styleIndex = 0; styleIndex < wallStyleList.length; styleIndex++)
75{
76 var startX = actualX + styleIndex * buildableMapSize/wallStyleList.length; // X coordinate of the first wall element
77 var startY = actualY; // Y coordinate of the first wall element
78 var style = wallStyleList[styleIndex]; // // The wall's style like 'cart', 'celt', 'hele', 'iber', 'pers', 'rome', 'romeSiege' or 'palisades'
79 var orientation = styleIndex * PI/32; // Orientation of the first wall element. 0 means 'outside' or 'front' is right (positive X, like object placement)
80 // That means the wall will be build towards top (positive Y) if no corners are used
81 var playerId = 0; // Owner of the wall (like in placeObject). 0 is Gaia, 1 is Player 1 (default colour blue), ...
82 placeWall(startX, startY, wall, style, playerId, orientation); // Actually placing the wall
83};
84actualX = distToMapBorder; // Reset actualX
85actualY += 80 + distToOtherWalls; // Increase actualY for next wall placement method
86
87//////////////////////////////////////////////////////////////
88// Default fortress placement (chosen by fortress type string)
89//////////////////////////////////////////////////////////////
90var fortressRadius = 15; // The space the fortresses take in average. Just for design of this map
91for (var styleIndex = 0; styleIndex < wallStyleList.length; styleIndex++)
92{
93 var centerX = actualX + fortressRadius + styleIndex * buildableMapSize/wallStyleList.length; // X coordinate of the center of the fortress
94 var centerY = actualY + fortressRadius; // Y coordinate of the center of the fortress
95 var type = 'tiny'; // Default fortress types are like map sizes: 'tiny', 'small', 'medium', 'large', 'veryLarge', 'giant'
96 var style = wallStyleList[styleIndex]; // The wall's style like 'cart', 'celt', 'hele', 'iber', 'pers', 'rome', 'romeSiege' or 'palisades'
97 var playerId = 0; // Owner of the wall. 0 is Gaia, 1 is Player 1 (default colour blue), ...
98 var orientation = styleIndex * PI/16; // Where the 'main entrance' of the fortress should face (like in placeObject). All fortresses walls should start with an entrance
99 placeFortress(centerX, centerY, type, style, playerId, orientation); // Actually placing the fortress
100 placeObject(centerX, centerY, 'other/obelisk', 0, 0*PI); // Place visual marker to see the center of the fortress
101};
102actualX = distToMapBorder; // Reset actualX
103actualY += 2 * fortressRadius + 2 * distToOtherWalls; // Increase actualY for next wall placement method
104
105//////////////////////////
106// Circular wall placement
107//////////////////////////
108// NOTE: Don't use bending wall elements like corners here!
109var radius = min((mapSize - actualY - distToOtherWalls) / 2, (buildableMapSize / wallStyleList.length - distToOtherWalls) / 2); // The radius of wall circle
110var centerY = actualY + radius; // Y coordinate of the center of the wall circle
111var orientation = 0; // Where the wall circle will be open if maxAngle < 2*PI or 360°, see below. Otherwise where the first wall element will be placed
112for (var styleIndex = 0; styleIndex < wallStyleList.length; styleIndex++)
113{
114 var centerX = actualX + radius + styleIndex * buildableMapSize/wallStyleList.length; // X coordinate of the center of the wall circle
115 var playerID = 0; // Player ID of the player owning the wall, 0 is Gaia, 1 is the first player (default blue), ...
116 var wallPart = ['tower', 'wall', 'house']; // List of wall elements the wall will be build of. Optional, default id ['wall']
117 var style = wallStyleList[styleIndex]; // The wall's style like 'cart', 'celt', 'hele', 'iber', 'pers', 'rome', 'romeSiege' or 'palisades'
118 var maxAngle = PI/2 * (styleIndex%3 + 2); // How far the wall should circumvent the center
119 placeCircularWall(centerX, centerY, radius, wallPart, style, playerID, orientation, maxAngle) // Actually placing the wall
120 placeObject(centerX, centerY, 'other/obelisk', 0, 0*PI); // Place visual marker to see the center of the wall circle
121 orientation += PI/4; // Increasing orientation to see how rotation works (like for object placement)
122};
123actualX = distToMapBorder; // Reset actualX
124actualY += 2 * radius + distToOtherWalls; // Increase actualY for next wall placement method
125
126////////////////////////
127// Linear wall placement
128////////////////////////
129// NOTE: Don't use bending wall elements like corners here!
130var maxWallLength = (mapSize - actualY - distToMapBorder - distToOtherWalls); // Just for this maps design. How long the longest wall will be
131var numWallsPerStyle = floor(buildableMapSize / distToOtherWalls / wallStyleList.length); // Just for this maps design. How many walls of the same style will be placed
132for (var styleIndex = 0; styleIndex < wallStyleList.length; styleIndex++)
133{
134 for (var wallIndex = 0; wallIndex < numWallsPerStyle; wallIndex++)
135 {
136 var startX = actualX + (styleIndex * numWallsPerStyle + wallIndex) * distToOtherWalls; // X coordinate the wall will start from
137 var startY = actualY; // Y coordinate the wall will start from
138 var endX = actualX + (styleIndex * numWallsPerStyle + wallIndex) * distToOtherWalls; // X coordinate the wall will end
139 var endY = actualY + (wallIndex + 1) * maxWallLength/numWallsPerStyle; // Y coordinate the wall will end
140 var playerID = 0; // Player ID of the player owning the wall, 0 is Gaia, 1 is the first player (default blue), ...
141 var wallPart = ['tower', 'wall']; // List of wall elements the wall will be build of
142 var style = wallStyleList[styleIndex]; // The wall's style like 'cart', 'celt', 'hele', 'iber', 'pers', 'rome', 'romeSiege' or 'palisades'
143 placeLinearWall(startX, startY, endX, endY, wallPart, style, playerID); // Actually placing the wall
144 // placeObject(startX, startY, 'other/obelisk', 0, 0*PI); // Place visual marker to see where exsactly the wall begins
145 // placeObject(endX, endY, 'other/obelisk', 0, 0*PI); // Place visual marker to see where exsactly the wall ends
146 };
147};
148actualX = distToMapBorder; // Reset actualX
149actualY += maxWallLength + distToOtherWalls; // Increase actualY for next wall placement method
150
151
152// Export map data
153ExportMap();