mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-18 14:23:56 -07:00
Move starting player entity rmgen functions from misc.js to a new player.js, refs #4804.
Remove two duplicates of the starting entity placement code in the Fortress map of208e642089and placeCivDefaultEntities of9c3e94acfdby just making the distance an argument, refs #4805. Equally to the starting cavalry, don't spawn special units like dogs or worker elephants on Fortress twice, but only the women and Infantry. Consider the weird kwargs iberWalls argument of placeCivDefaultEntities from9c3e94acfddeprecated and just make the orientation a regular optional argument. Rename createStartingPlayerEntities to placeStartingEntities. This was SVN commit r20415.
This commit is contained in:
parent
a10b8e16c2
commit
df14c914e6
4 changed files with 58 additions and 92 deletions
|
|
@ -59,24 +59,18 @@ var [playerIDs, playerX, playerZ] = radialPlayerPlacement();
|
|||
|
||||
for (var i=0; i < numPlayers; i++)
|
||||
{
|
||||
log("Creating base for player " + playerIDs[i] + "...");
|
||||
playerX[i] *= mapSize;
|
||||
playerZ[i] *= mapSize;
|
||||
|
||||
var startEntities = getStartingEntities(i);
|
||||
// Place starting entities
|
||||
createStartingPlayerEntities(playerX[i], playerZ[i], i+1, startEntities);
|
||||
var uDist = 8;
|
||||
var uSpace = 2;
|
||||
for (var j = 1; j < startEntities.length - 1; ++j)
|
||||
for (let dist of [6, 8])
|
||||
{
|
||||
var uAngle = BUILDING_ORIENTATION - PI * (2-j) / 2;
|
||||
var count = (startEntities[j].Count !== undefined ? startEntities[j].Count : 1);
|
||||
for (var numberofentities = 0; numberofentities < count; numberofentities++)
|
||||
{
|
||||
var ux = playerX[i] + uDist * cos(uAngle) + numberofentities * uSpace * cos(uAngle + PI/2) - (0.75 * uSpace * floor(count / 2) * cos(uAngle + PI/2));
|
||||
var uz = playerZ[i] + uDist * sin(uAngle) + numberofentities * uSpace * sin(uAngle + PI/2) - (0.75 * uSpace * floor(count / 2) * sin(uAngle + PI/2));
|
||||
placeObject(ux, uz, startEntities[j].Template, i+1, uAngle);
|
||||
}
|
||||
let ents = getStartingEntities(i);
|
||||
|
||||
if (dist == 8)
|
||||
ents = ents.filter(ent => ent.Template.indexOf("female") != -1 || ent.Template.indexOf("infantry") != -1);
|
||||
|
||||
placeStartingEntities(playerX[i], playerZ[i], i + 1, ents, dist);
|
||||
}
|
||||
|
||||
// Create treasure
|
||||
|
|
|
|||
|
|
@ -1,80 +1,3 @@
|
|||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
// createStartingPlayerEntities
|
||||
//
|
||||
// Creates the starting player entities
|
||||
// fx&fz: position of player base
|
||||
// playerid: id of player
|
||||
// civEntities: use getStartingEntities(id-1) fo this one
|
||||
// orientation: orientation of the main base building, default is BUILDING_ORIENTATION
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
function createStartingPlayerEntities(fx, fz, playerid, civEntities, orientation = BUILDING_ORIENTATION)
|
||||
{
|
||||
var uDist = 6;
|
||||
var uSpace = 2;
|
||||
placeObject(fx, fz, civEntities[0].Template, playerid, orientation);
|
||||
for (var j = 1; j < civEntities.length; ++j)
|
||||
{
|
||||
var uAngle = orientation - PI * (2-j) / 2;
|
||||
var count = (civEntities[j].Count !== undefined ? civEntities[j].Count : 1);
|
||||
for (var numberofentities = 0; numberofentities < count; numberofentities++)
|
||||
{
|
||||
var ux = fx + uDist * cos(uAngle) + numberofentities * uSpace * cos(uAngle + PI/2) - (0.75 * uSpace * floor(count / 2) * cos(uAngle + PI/2));
|
||||
var uz = fz + uDist * sin(uAngle) + numberofentities * uSpace * sin(uAngle + PI/2) - (0.75 * uSpace * floor(count / 2) * sin(uAngle + PI/2));
|
||||
placeObject(ux, uz, civEntities[j].Template, playerid, uAngle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// placeCivDefaultEntities
|
||||
//
|
||||
// Creates the default starting player entities depending on the players civ
|
||||
// fx&fy: position of player base
|
||||
// playerid: id of player
|
||||
// kwargs: Takes some optional keyword arguments to tweek things
|
||||
// 'iberWall': may be false, 'walls' (default) or 'towers'. Determines the defensive structures Iberians get as civ bonus
|
||||
// 'orientation': angle of the main base building, default is BUILDING_ORIENTATION
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
function placeCivDefaultEntities(fx, fz, playerid, kwargs = {})
|
||||
{
|
||||
// Unpack kwargs
|
||||
var iberWall = 'walls';
|
||||
if (getMapSize() <= 128)
|
||||
iberWall = false;
|
||||
if ('iberWall' in kwargs)
|
||||
iberWall = kwargs['iberWall'];
|
||||
var orientation = BUILDING_ORIENTATION;
|
||||
if ('orientation' in kwargs)
|
||||
orientation = kwargs['orientation'];
|
||||
// Place default civ starting entities
|
||||
var civ = getCivCode(playerid-1);
|
||||
var civEntities = getStartingEntities(playerid-1);
|
||||
var uDist = 6;
|
||||
var uSpace = 2;
|
||||
placeObject(fx, fz, civEntities[0].Template, playerid, orientation);
|
||||
for (var j = 1; j < civEntities.length; ++j)
|
||||
{
|
||||
var uAngle = orientation - PI * (2-j) / 2;
|
||||
var count = (civEntities[j].Count !== undefined ? civEntities[j].Count : 1);
|
||||
for (var numberofentities = 0; numberofentities < count; numberofentities++)
|
||||
{
|
||||
var ux = fx + uDist * cos(uAngle) + numberofentities * uSpace * cos(uAngle + PI/2) - (0.75 * uSpace * floor(count / 2) * cos(uAngle + PI/2));
|
||||
var uz = fz + uDist * sin(uAngle) + numberofentities * uSpace * sin(uAngle + PI/2) - (0.75 * uSpace * floor(count / 2) * sin(uAngle + PI/2));
|
||||
placeObject(ux, uz, civEntities[j].Template, playerid, uAngle);
|
||||
}
|
||||
}
|
||||
// Add defensive structiures for Iberians as their civ bonus
|
||||
if (civ == 'iber' && iberWall != false)
|
||||
{
|
||||
if (iberWall == 'towers')
|
||||
placePolygonalWall(fx, fz, 15, ['entry'], 'tower', civ, playerid, orientation, 7);
|
||||
else
|
||||
placeGenericFortress(fx, fz, 20/*radius*/, playerid);
|
||||
}
|
||||
}
|
||||
|
||||
function placeDefaultChicken(playerX, playerZ, tileClass, constraint = undefined, template = "gaia/fauna_chicken")
|
||||
{
|
||||
for (let j = 0; j < 2; ++j)
|
||||
|
|
|
|||
49
binaries/data/mods/public/maps/random/rmgen/player.js
Normal file
49
binaries/data/mods/public/maps/random/rmgen/player.js
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
/**
|
||||
* Places the given entities at the given location (typically a civic center and starting units).
|
||||
* @param civEntities - An array of objects with the Template property and optionally a Count property.
|
||||
* The first entity is placed in the center, the other ones surround it.
|
||||
*/
|
||||
function placeStartingEntities(fx, fz, playerID, civEntities, dist = 6, orientation = BUILDING_ORIENTATION)
|
||||
{
|
||||
// Place the central structure
|
||||
let i = 0;
|
||||
let firstTemplate = civEntities[i].Template;
|
||||
if (firstTemplate.startsWith("structures/"))
|
||||
{
|
||||
placeObject(fx, fz, firstTemplate, playerID, orientation);
|
||||
++i;
|
||||
}
|
||||
|
||||
// Place entities surrounding it
|
||||
let space = 2;
|
||||
for (let j = i; j < civEntities.length; ++j)
|
||||
{
|
||||
let angle = orientation - Math.PI * (1 - j / 2);
|
||||
let count = civEntities[j].Count || 1;
|
||||
|
||||
for (let num = 0; num < count; ++num)
|
||||
placeObject(
|
||||
fx + dist * Math.cos(angle) + space * (-num + 0.75 * Math.floor(count / 2)) * Math.sin(angle),
|
||||
fz + dist * Math.sin(angle) + space * (num - 0.75 * Math.floor(count / 2)) * Math.cos(angle),
|
||||
civEntities[j].Template,
|
||||
playerID,
|
||||
angle);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Places the default starting entities as defined by the civilization definition and walls for Iberians.
|
||||
*/
|
||||
function placeCivDefaultEntities(fx, fz, playerID, kwargs, dist = 6, orientation = BUILDING_ORIENTATION)
|
||||
{
|
||||
placeStartingEntities(fx, fz, playerID, getStartingEntities(playerID - 1), dist, orientation);
|
||||
|
||||
let civ = getCivCode(playerID - 1);
|
||||
if (civ == 'iber' && getMapSize() > 128)
|
||||
{
|
||||
if (kwargs && kwargs.iberWall == 'towers')
|
||||
placePolygonalWall(fx, fz, 15, ['entry'], 'tower', civ, playerID, orientation, 7);
|
||||
else if (!kwargs || kwargs.iberWall)
|
||||
placeGenericFortress(fx, fz, 20, playerID);
|
||||
}
|
||||
}
|
||||
|
|
@ -680,7 +680,7 @@ for (let i = 0; i < resourceSpots.length; ++i)
|
|||
{
|
||||
if (mercenaryCamps)
|
||||
{
|
||||
createStartingPlayerEntities(resourceSpots[i].x, resourceSpots[i].y, 0, mercenaryCampGuards[currentBiome()]);
|
||||
placeStartingEntities(resourceSpots[i].x, resourceSpots[i].y, 0, mercenaryCampGuards[currentBiome()]);
|
||||
rectangularSmoothToHeight(resourceSpots[i], 15, 15, g_Map.height[resourceSpots[i].x][resourceSpots[i].y], 0.5);
|
||||
--mercenaryCamps;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue