Update wall_builder and add wall_demo map. Patch by FeXoR. Closes #1311.
This was SVN commit r11515.
This commit is contained in:
parent
9c4a7b8086
commit
1ee8bfe231
@ -54,11 +54,8 @@ var mapCenterX = mapRadius;
|
||||
var mapCenterZ = mapRadius;
|
||||
|
||||
// Setup players and bases
|
||||
var fortresses = false;
|
||||
var numPlayers = getNumPlayers();
|
||||
var baseRadius = 20;
|
||||
if (fortresses == true)
|
||||
baseRadius = 30;
|
||||
var minPlayerRadius = min(mapRadius-1.5*baseRadius, 5*mapRadius/8);
|
||||
var maxPlayerRadius = min(mapRadius-baseRadius, 3*mapRadius/4);
|
||||
const BUILDING_ANlE = -PI/4;
|
||||
@ -77,8 +74,6 @@ var radiusEC = max(mapRadius/8, baseRadius/2);
|
||||
var pathSucsessRadius = baseRadius/2;
|
||||
var pathAngleOff = PI/2;
|
||||
var pathWidth = 5; // This is not really the path's sickness in tiles but the number of tiles in the clumbs of the path
|
||||
if (fortresses == true)
|
||||
pathSucsessRadius = baseRadius;;
|
||||
|
||||
// Setup additional resources
|
||||
var resourceRadius = 2*mapRadius/3; // 3*mapRadius/8;
|
||||
@ -104,14 +99,6 @@ for (var i=0; i < numPlayers; i++)
|
||||
var placer = new ClumpPlacer(2*baseRadius*baseRadius, 2/3, 1/8, 10, x, z);
|
||||
var painter = [new LayeredPainter([terrainBaseBorder, terrainBase], [baseRadius/4]), paintClass(clPlayer)];
|
||||
createArea(placer, painter);
|
||||
// Place fortresses
|
||||
if (fortresses == true)
|
||||
{
|
||||
// Place fortresses
|
||||
new wallTool(civ, "small").place(x, z, i+1, BUILDING_ANlE);
|
||||
// if (civ == "iber")
|
||||
// new wallTool("iber").setGenericFortress(x, z, i+1, 20, PI/6);
|
||||
};
|
||||
// Place starting resources
|
||||
var distToSL = 10;
|
||||
var resStartAngle = playerAngle[i] + PI;
|
||||
@ -123,8 +110,8 @@ for (var i=0; i < numPlayers; i++)
|
||||
var placeZ = z + distToSL*sin(resStartAngle + rIndex*resAddAngle + angleOff);
|
||||
placeObject(placeX, placeZ, startingResourcees[rIndex], 0, randFloat(0, 2*PI));
|
||||
addToClass(round(placeX), round(placeZ), clBaseResource);
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
RMS.SetProgress(10);
|
||||
|
||||
@ -190,14 +177,14 @@ for (var i = 0; i < maxI; i++)
|
||||
{
|
||||
x += round(cos(angle + randFloat(-pathAngleOff, pathAngleOff)));
|
||||
z += round(sin(angle + randFloat(-pathAngleOff, pathAngleOff)));
|
||||
};
|
||||
}
|
||||
if (getDistance(x, z, targetX, targetZ) < pathSucsessRadius)
|
||||
targetReached = true;
|
||||
tries++;
|
||||
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RMS.SetProgress(50);
|
||||
|
||||
@ -216,8 +203,8 @@ for (var i=0; i < numPlayers; i++)
|
||||
var placer = new ClumpPlacer(40, 1/2, 1/8, 1, placeX, placeZ);
|
||||
var painter = [new LayeredPainter([terrainHillBorder, terrainHill], [1]), new ElevationPainter(1+randFloat()), paintClass(clHill)];
|
||||
createArea(placer, painter);
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
RMS.SetProgress(60);
|
||||
|
||||
@ -255,20 +242,17 @@ for (var x = 0; x < mapSize; x++)
|
||||
var placer = new ClumpPlacer(1, 1.0, 1.0, 1, x, z);
|
||||
var painter = [new TerrainPainter(terrainWood), new ElevationPainter(randFloat()), paintClass(clForest)];
|
||||
createArea(placer, painter, avoidClasses(clPath, 2, clHill, 1));
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
// General hight map
|
||||
var hVarMiddleHill = mapSize/64 * (1+cos(3*PI/2 * radius/mapRadius));
|
||||
var hVarHills = 5*(1+sin(x/10)*sin(z/10));
|
||||
setHeight(x, z, getHeight(x, z) + hVarMiddleHill + hVarHills + 1);
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
RMS.SetProgress(95);
|
||||
|
||||
// Test linear wall
|
||||
// new wallTool("palisades").placeLinearWall(mapCenterX, mapCenterZ, playerStartLocX[0], playerStartLocZ[0], 0, ["tower", "wall"])
|
||||
|
||||
|
||||
// Export map data
|
||||
ExportMap();
|
||||
|
@ -153,32 +153,26 @@ for (var i=0; i < numPlayers; i++)
|
||||
// Base texture
|
||||
var placer = new ClumpPlacer(PI*baseRadius*baseRadius/4, 1/2, 1/8, 10, playerX[i], playerZ[i]);
|
||||
createArea(placer,[new TerrainPainter(tRoad), paintClass(clPlayer)]);
|
||||
// Place fortresses
|
||||
// new wallTool(civ, "medium").place(x, z, i+1, buildAngle);
|
||||
|
||||
// Place fortresses Spahbod (custom fortress method, standart for this case but no function "setFortress" implemented yet)
|
||||
var fType = new fortress('Spahbod'+civ);
|
||||
// Place custom fortress
|
||||
if (civ == "celt" || civ == "iber")
|
||||
{
|
||||
fType.wall = ['entry', 'wall', 'wall',
|
||||
var wall = ['entryTower', 'wall', 'wall',
|
||||
'cornerIn', 'wall', 'barracks', 'wall', 'gate', 'wall', 'house', 'wall',
|
||||
'cornerIn', 'wall', 'house', 'wall', 'entry', 'wall', 'house', 'wall',
|
||||
'cornerIn', 'wall', 'house', 'wall', 'entryTower', 'wall', 'house', 'wall',
|
||||
'cornerIn', 'wall', 'house', 'wall', 'gate', 'wall', 'house', 'wall',
|
||||
'cornerIn', 'wall', 'house', 'wall'];
|
||||
}
|
||||
else
|
||||
{
|
||||
fType.wall = ['entry', 'wall', 'wall',
|
||||
var wall = ['entryTower', 'wall', 'wall',
|
||||
'cornerIn', 'wall', 'barracks', 'wall', 'gate', 'wall', 'wall',
|
||||
'cornerIn', 'wall', 'house', 'wall', 'entry', 'wall', 'wall',
|
||||
'cornerIn', 'wall', 'house', 'wall', 'entryTower', 'wall', 'wall',
|
||||
'cornerIn', 'wall', 'house', 'wall', 'gate', 'wall', 'wall',
|
||||
'cornerIn', 'wall', 'house', 'wall'];
|
||||
};
|
||||
var fort = new wallTool(civ);
|
||||
fort.setFortress(fType);
|
||||
fort.place(playerX[i], playerZ[i], i+1, BUILDING_ANGlE);
|
||||
|
||||
};
|
||||
}
|
||||
placeCustomFortress(playerX[i], playerZ[i], new Fortress("Spahbod", wall), civ, i+1, BUILDING_ANGlE);
|
||||
}
|
||||
|
||||
// create lakes
|
||||
log("Creating lakes...");
|
||||
@ -459,4 +453,4 @@ createObjectGroups(group, 0,
|
||||
);
|
||||
|
||||
// Export map data
|
||||
ExportMap();
|
||||
ExportMap();
|
||||
|
File diff suppressed because it is too large
Load Diff
153
binaries/data/mods/public/maps/random/wall_demo.js
Normal file
153
binaries/data/mods/public/maps/random/wall_demo.js
Normal file
@ -0,0 +1,153 @@
|
||||
RMS.LoadLibrary("rmgen");
|
||||
|
||||
// initialize map
|
||||
log("Initializing map...");
|
||||
InitMap();
|
||||
|
||||
|
||||
// General map setup
|
||||
var mapSize = getMapSize();
|
||||
var mapCenterX = mapSize/2;
|
||||
var mapCenterY = mapSize/2;
|
||||
const BUILDING_ANlE = -PI/4;
|
||||
|
||||
|
||||
////////////////////////////////////////
|
||||
// Demonstration code for wall placement
|
||||
////////////////////////////////////////
|
||||
|
||||
// Some general notes to the arguments:
|
||||
|
||||
// First all the place functions take the coordinates needed to place the wall
|
||||
// X and Y coordinate are taken in seperate arguments like in placeObject
|
||||
// Their meaning differs for different placement methods but are mainly self explanatory
|
||||
// placeLinearWall takes 4 arguments here (2 coordinates) for startX, startY, targetX and targetY
|
||||
|
||||
// The next argument is always the 'wall' definition, an array of wall element type strings in most cases
|
||||
// That looks like ['endLeft', 'wall', 'tower', 'wall', 'endRight', 'entry', 'endLeft', 'wall', 'tower', 'wall', 'endRight']
|
||||
// For placeCircularWall and placeLinearWall only wall parts are needed like: ['tower', 'wall']
|
||||
// They will automatically end with the first wall element if that makes sense (e.g. the wall is not closed)
|
||||
// NOTE: They take further optional arguments to adjust this behaviour (See the wall_builder.js for that)
|
||||
// placeFortress just takes a fortress type string that includes the wall definition
|
||||
// The default fortress type strings are made for easy placement of predefined fortresses
|
||||
// They are chosen like map sizes: 'tiny', 'small', 'medium', 'normal', 'large', 'veryLarge' and 'giant'
|
||||
// NOTE: To place a custom fortress use placeCustomFortress instead
|
||||
// It takes an instance of the Fortress class instead of the default fortress type strings
|
||||
|
||||
// The next argument is always the wall style string
|
||||
// Wall styles are chosen by strings so the civ strings got by g_MapSettings.PlayerData[playerId - 1].Civ can be used
|
||||
// Other styles may be present as well but besides the civ styles only 'palisades' includes all wall element types (yet)
|
||||
|
||||
// The next argument is always the index of the player that owns the wall.
|
||||
// 0 is Gaia, 1 is Player 1 (default colour blue), 2 is Player 2 (default colour red), ...
|
||||
|
||||
// The next argument is an angle defining the orientation of the wall
|
||||
// placeLinearWall does not need an angle since it's defined by startX/Y and targetX/Y
|
||||
// Orientation works like the angle argument in placeObject
|
||||
// 0 is always right (towards positive X)
|
||||
// Raising the angle will rotate the wall counter-clockwise (mathmatical positive in default 2D)
|
||||
// PI/2 faces top (positive Y)
|
||||
// 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.
|
||||
// It's because all other methods work like that and it's intuitive there
|
||||
// That means the walls outside by default (orientation = 0) faces positive X and (without bending wall elements) will be build towards positive Y
|
||||
|
||||
// Some other arguments are taken but all of them are optional and in most cases not needed
|
||||
// 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
|
||||
|
||||
|
||||
// General wall placement setup
|
||||
const distToMapBorder = 5;
|
||||
const distToOtherWalls = 5;
|
||||
var buildableMapSize = mapSize - 2 * distToMapBorder;
|
||||
var actualX = distToMapBorder;
|
||||
var actualY = distToMapBorder;
|
||||
// Wall styles are chosen by strings so the civ strings got by g_MapSettings.PlayerData[playerId - 1].Civ can be used
|
||||
// Other styles may be present as well but besides the civ styles only 'palisades' includes all wall element types (yet)
|
||||
const wallStyleList = ['cart', 'celt', 'hele', 'iber', 'pers', 'rome', 'romeSiege', 'palisades'];
|
||||
|
||||
|
||||
////////////////////////////////////////
|
||||
// Custom wall placement (element based)
|
||||
////////////////////////////////////////
|
||||
var wall = ['endLeft', 'wall', 'tower', 'wall', 'outpost', 'wall', 'cornerOut', 'wall', 'cornerIn', 'wall', 'house', 'endRight', 'entryTower', 'endLeft', 'wall', 'barracks', 'gate', 'tower', 'wall', 'wallFort', 'wall', 'endRight'];
|
||||
for (var styleIndex = 0; styleIndex < wallStyleList.length; styleIndex++)
|
||||
{
|
||||
var startX = actualX + styleIndex * buildableMapSize/wallStyleList.length; // X coordinate of the first wall element
|
||||
var startY = actualY; // Y coordinate of the first wall element
|
||||
var style = wallStyleList[styleIndex]; // // The wall's style like 'cart', 'celt', 'hele', 'iber', 'pers', 'rome', 'romeSiege' or 'palisades'
|
||||
var orientation = styleIndex * PI/32; // Orientation of the first wall element. 0 means 'outside' or 'front' is right (positive X, like object placement)
|
||||
// That means the wall will be build towards top (positive Y) if no corners are used
|
||||
var playerId = 0; // Owner of the wall (like in placeObject). 0 is Gaia, 1 is Player 1 (default colour blue), ...
|
||||
placeWall(startX, startY, wall, style, playerId, orientation); // Actually placing the wall
|
||||
}
|
||||
actualX = distToMapBorder; // Reset actualX
|
||||
actualY += 80 + distToOtherWalls; // Increase actualY for next wall placement method
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
// Default fortress placement (chosen by fortress type string)
|
||||
//////////////////////////////////////////////////////////////
|
||||
var fortressRadius = 15; // The space the fortresses take in average. Just for design of this map
|
||||
for (var styleIndex = 0; styleIndex < wallStyleList.length; styleIndex++)
|
||||
{
|
||||
var centerX = actualX + fortressRadius + styleIndex * buildableMapSize/wallStyleList.length; // X coordinate of the center of the fortress
|
||||
var centerY = actualY + fortressRadius; // Y coordinate of the center of the fortress
|
||||
var type = 'tiny'; // Default fortress types are like map sizes: 'tiny', 'small', 'medium', 'large', 'veryLarge', 'giant'
|
||||
var style = wallStyleList[styleIndex]; // The wall's style like 'cart', 'celt', 'hele', 'iber', 'pers', 'rome', 'romeSiege' or 'palisades'
|
||||
var playerId = 0; // Owner of the wall. 0 is Gaia, 1 is Player 1 (default colour blue), ...
|
||||
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
|
||||
placeFortress(centerX, centerY, type, style, playerId, orientation); // Actually placing the fortress
|
||||
placeObject(centerX, centerY, 'other/obelisk', 0, 0*PI); // Place visual marker to see the center of the fortress
|
||||
}
|
||||
actualX = distToMapBorder; // Reset actualX
|
||||
actualY += 2 * fortressRadius + 2 * distToOtherWalls; // Increase actualY for next wall placement method
|
||||
|
||||
//////////////////////////
|
||||
// Circular wall placement
|
||||
//////////////////////////
|
||||
// NOTE: Don't use bending wall elements like corners here!
|
||||
var radius = min((mapSize - actualY - distToOtherWalls) / 2, (buildableMapSize / wallStyleList.length - distToOtherWalls) / 2); // The radius of wall circle
|
||||
var centerY = actualY + radius; // Y coordinate of the center of the wall circle
|
||||
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
|
||||
for (var styleIndex = 0; styleIndex < wallStyleList.length; styleIndex++)
|
||||
{
|
||||
var centerX = actualX + radius + styleIndex * buildableMapSize/wallStyleList.length; // X coordinate of the center of the wall circle
|
||||
var playerID = 0; // Player ID of the player owning the wall, 0 is Gaia, 1 is the first player (default blue), ...
|
||||
var wallPart = ['tower', 'wall', 'house']; // List of wall elements the wall will be build of. Optional, default id ['wall']
|
||||
var style = wallStyleList[styleIndex]; // The wall's style like 'cart', 'celt', 'hele', 'iber', 'pers', 'rome', 'romeSiege' or 'palisades'
|
||||
var maxAngle = PI/2 * (styleIndex%3 + 2); // How far the wall should circumvent the center
|
||||
placeCircularWall(centerX, centerY, radius, wallPart, style, playerID, orientation, maxAngle) // Actually placing the wall
|
||||
placeObject(centerX, centerY, 'other/obelisk', 0, 0*PI); // Place visual marker to see the center of the wall circle
|
||||
orientation += PI/4; // Increasing orientation to see how rotation works (like for object placement)
|
||||
}
|
||||
actualX = distToMapBorder; // Reset actualX
|
||||
actualY += 2 * radius + distToOtherWalls; // Increase actualY for next wall placement method
|
||||
|
||||
////////////////////////
|
||||
// Linear wall placement
|
||||
////////////////////////
|
||||
// NOTE: Don't use bending wall elements like corners here!
|
||||
var maxWallLength = (mapSize - actualY - distToMapBorder - distToOtherWalls); // Just for this maps design. How long the longest wall will be
|
||||
var numWallsPerStyle = floor(buildableMapSize / distToOtherWalls / wallStyleList.length); // Just for this maps design. How many walls of the same style will be placed
|
||||
for (var styleIndex = 0; styleIndex < wallStyleList.length; styleIndex++)
|
||||
{
|
||||
for (var wallIndex = 0; wallIndex < numWallsPerStyle; wallIndex++)
|
||||
{
|
||||
var startX = actualX + (styleIndex * numWallsPerStyle + wallIndex) * distToOtherWalls; // X coordinate the wall will start from
|
||||
var startY = actualY; // Y coordinate the wall will start from
|
||||
var endX = actualX + (styleIndex * numWallsPerStyle + wallIndex) * distToOtherWalls; // X coordinate the wall will end
|
||||
var endY = actualY + (wallIndex + 1) * maxWallLength/numWallsPerStyle; // Y coordinate the wall will end
|
||||
var playerID = 0; // Player ID of the player owning the wall, 0 is Gaia, 1 is the first player (default blue), ...
|
||||
var wallPart = ['tower', 'wall']; // List of wall elements the wall will be build of
|
||||
var style = wallStyleList[styleIndex]; // The wall's style like 'cart', 'celt', 'hele', 'iber', 'pers', 'rome', 'romeSiege' or 'palisades'
|
||||
placeLinearWall(startX, startY, endX, endY, wallPart, style, playerID); // Actually placing the wall
|
||||
// placeObject(startX, startY, 'other/obelisk', 0, 0*PI); // Place visual marker to see where exsactly the wall begins
|
||||
// placeObject(endX, endY, 'other/obelisk', 0, 0*PI); // Place visual marker to see where exsactly the wall ends
|
||||
}
|
||||
}
|
||||
actualX = distToMapBorder; // Reset actualX
|
||||
actualY += maxWallLength + distToOtherWalls; // Increase actualY for next wall placement method
|
||||
|
||||
|
||||
// Export map data
|
||||
ExportMap();
|
12
binaries/data/mods/public/maps/random/wall_demo.json
Normal file
12
binaries/data/mods/public/maps/random/wall_demo.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"settings" : {
|
||||
"Name" : "Wall Demo",
|
||||
"Script" : "wall_demo.js",
|
||||
"Description" : "A demonstration of wall placement methods/code in random maps. Medium map size is recommended.",
|
||||
"BaseTerrain" : ["grass1"],
|
||||
"BaseHeight" : 0,
|
||||
"Keywords": ["demo"],
|
||||
"CircularMap" : false,
|
||||
"XXXXXX" : "Optionally define other things here, like we would for a scenario"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user