1
0
forked from 0ad/0ad

Fixes filter behavior in setup when switching map type.

Fixes broken texture in Latium rms.
Adds demo keyword to rms test.
Fixes default rms lighting with new model.

This was SVN commit r9127.
This commit is contained in:
historic_bruno 2011-03-27 22:00:49 +00:00
parent daad510013
commit 0dfc72bc2c
6 changed files with 129 additions and 18 deletions

View File

@ -124,9 +124,13 @@ function initMain()
// Set a default map
// TODO: This should be remembered from the last session
if (!g_IsNetworked)
{
g_GameAttributes.map = "Death Canyon";
}
else
{
g_GameAttributes.map = "Median Oasis";
}
mapTypes.selected = 0;
mapFilters.selected = 0;
@ -147,10 +151,14 @@ function initMain()
victoryConditions.onSelectionChange = function()
{ // Update attributes so other players can see change
if (this.selected != -1)
{
g_GameAttributes.settings.GameType = this.list_data[this.selected];
}
if (!g_IsInGuiUpdate)
{
updateGameAttributes();
}
};
victoryConditions.selected = -1;
@ -160,10 +168,14 @@ function initMain()
mapSize.onSelectionChange = function()
{ // Update attributes so other players can see change
if (this.selected != -1)
{
g_GameAttributes.settings.Size = this.list_data[this.selected];
}
if (!g_IsInGuiUpdate)
{
updateGameAttributes();
}
};
mapSize.selected = 1;
@ -172,7 +184,9 @@ function initMain()
g_GameAttributes.settings.RevealMap = this.checked;
if (!g_IsInGuiUpdate)
{
updateGameAttributes();
}
};
getGUIObjectByName("lockTeams").onPress = function()
@ -180,7 +194,9 @@ function initMain()
g_GameAttributes.settings.LockTeams = this.checked;
if (!g_IsInGuiUpdate)
{
updateGameAttributes();
}
};
}
else
@ -235,10 +251,14 @@ function initMain()
team.onSelectionChange = function()
{ // Update team
if (this.selected != -1)
{
g_GameAttributes.settings.PlayerData[playerSlot].Team = this.selected - 1;
}
if (!g_IsInGuiUpdate)
{
updateGameAttributes();
}
};
// Set events
@ -246,10 +266,14 @@ function initMain()
civ.onSelectionChange = function()
{ // Update civ
if (this.selected != -1)
{
g_GameAttributes.settings.PlayerData[playerSlot].Civ = this.list_data[this.selected];
}
if (!g_IsInGuiUpdate)
{
updateGameAttributes();
}
};
}
@ -289,7 +313,9 @@ function handleNetMessage(message)
case "gamesetup":
if (message.data) // (the host gets undefined data on first connect, so skip that)
{
g_GameAttributes = message.data;
}
onGameAttributesChange();
break;
@ -297,11 +323,19 @@ function handleNetMessage(message)
case "players":
// Find and report all joinings/leavings
for (var host in message.hosts)
{
if (! g_PlayerAssignments[host])
{
addChatMessage({ "type": "connect", "username": message.hosts[host].name });
}
}
for (var host in g_PlayerAssignments)
{
if (! message.hosts[host])
{
addChatMessage({ "type": "disconnect", "guid": host });
}
}
// Update the player list
g_PlayerAssignments = message.hosts;
updatePlayerList();
@ -342,11 +376,15 @@ function getMapDisplayName(map)
function getSetting(settings, defaults, property)
{
if (settings && (property in settings))
{
return settings[property];
}
// Use defaults
if (defaults && (property in defaults))
{
return defaults[property];
}
return undefined;
}
@ -406,7 +444,9 @@ function initMapNameList()
var mapData = loadMapData(file);
if (g_GameAttributes.mapFilter && mapData && testFilter(g_GameAttributes.mapFilter, mapData.settings))
{
mapList.push({ "name": getMapDisplayName(file), "file": file });
}
}
// Alphabetically sort the list, ignoring case
@ -419,7 +459,9 @@ function initMapNameList()
var selected = mapListFiles.indexOf(g_GameAttributes.map);
// Default to the first element if list is not empty and we can't find the one we searched for
if (selected == -1 && mapList.length)
{
selected = 0;
}
// Update the list control
mapSelectionBox.list = mapListNames;
@ -430,7 +472,9 @@ function initMapNameList()
function loadMapData(name)
{
if (!name)
{
return undefined;
}
if (!g_MapData[name])
{
@ -481,7 +525,9 @@ function onTick()
{
var message = Engine.PollNetworkClient();
if (!message)
{
break;
}
handleNetMessage(message);
}
}
@ -492,15 +538,21 @@ function selectNumPlayers(num)
{
// Avoid recursion
if (g_IsInGuiUpdate)
{
return;
}
// Network clients can't change number of players
if (g_IsNetworked && !g_IsController)
{
return;
}
// Only meaningful for random maps
if (g_GameAttributes.mapType != "random")
{
return;
}
// Update player data
var pData = g_GameAttributes.settings.PlayerData;
@ -522,13 +574,18 @@ function selectMapType(type)
{
// Avoid recursion
if (g_IsInGuiUpdate)
{
return;
}
// Network clients can't change map type
if (g_IsNetworked && !g_IsController)
{
return;
}
g_GameAttributes.mapType = type;
g_GameAttributes.map = undefined;
// Clear old map data
g_MapData = {};
@ -558,11 +615,15 @@ function selectMapFilter(filterName)
{
// Avoid recursion
if (g_IsInGuiUpdate)
{
return;
}
// Network clients can't change map filter
if (g_IsNetworked && !g_IsController)
{
return;
}
g_GameAttributes.mapFilter = filterName;
@ -576,15 +637,21 @@ function selectMap(name)
{
// Avoid recursion
if (g_IsInGuiUpdate)
{
return;
}
// Network clients can't change map
if (g_IsNetworked && !g_IsController)
{
return;
}
// Return if we have no map
if (!name)
{
return;
}
g_GameAttributes.map = name;
@ -629,7 +696,9 @@ function selectMap(name)
var player = g_PlayerAssignments[guid].player;
if (player <= MAX_PLAYERS && player > numPlayers)
{
Engine.AssignNetworkPlayer(player, "");
}
}
}
@ -644,6 +713,12 @@ function launchGame()
return;
}
// Check that we have a map
if (!g_GameAttributes.map)
{
return;
}
if (g_IsNetworked)
{
Engine.SetNetworkGameAttributes(g_GameAttributes);
@ -658,7 +733,9 @@ function launchGame()
{
var assignBox = getGUIObjectByName("playerAssignment["+i+"]");
if (assignBox.list_data[assignBox.selected] == "local")
{
playerID = i+1;
}
}
// Remove extra player data
g_GameAttributes.settings.PlayerData = g_GameAttributes.settings.PlayerData.slice(0, numPlayers);
@ -836,9 +913,13 @@ function onGameAttributesChange()
function updateGameAttributes()
{
if (g_IsNetworked)
{
Engine.SetNetworkGameAttributes(g_GameAttributes);
}
else
{
onGameAttributesChange();
}
}
function updatePlayerList()
@ -891,9 +972,13 @@ function updatePlayerList()
{
var aiId = g_GameAttributes.settings.PlayerData[playerSlot].AI;
if (aiId)
{
selection = aiAssignments[aiId];
}
else
{
selection = noAssignment;
}
// Since no human is assigned, show the AI config button
if (g_IsController)
@ -908,9 +993,13 @@ function updatePlayerList()
g_GameAttributes.settings.PlayerData[playerSlot].AI = ai.id;
if (g_IsNetworked)
{
Engine.SetNetworkGameAttributes(g_GameAttributes);
}
else
{
updatePlayerList();
}
}
});
};
@ -924,7 +1013,9 @@ function updatePlayerList()
{
g_GameAttributes.settings.PlayerData[playerSlot].AI = "";
if (g_IsNetworked)
{
Engine.SetNetworkGameAttributes(g_GameAttributes);
}
}
}
@ -932,7 +1023,9 @@ function updatePlayerList()
assignBox.list = hostNameList;
assignBox.list_data = hostGuidList;
if (assignBox.selected != selection)
{
assignBox.selected = selection;
}
if (g_IsNetworked && g_IsController)
{
@ -1108,12 +1201,16 @@ function testFilter(name, mapSettings)
function keywordTestAND(keywords, matches)
{
if (!keywords || !matches)
{
return false;
}
for (var m = 0; m < matches.length; ++m)
{ // Fail on not match
if (keywords.indexOf(matches[m]) == -1)
{
return false;
}
}
return true;
}
@ -1122,12 +1219,16 @@ function keywordTestAND(keywords, matches)
function keywordTestOR(keywords, matches)
{
if (!keywords || !matches)
{
return false;
}
for (var m = 0; m < matches.length; ++m)
{ // Success on match
if (keywords.indexOf(matches[m]) != -1)
{
return true;
}
}
return false;
}

View File

@ -10,7 +10,7 @@ const tOceanCoral = "medit_sea_coral_plants";
const tBeachWet = "medit_sand_wet";
const tBeachDry = "medit_sand";
const tBeachGrass = "medit_rocks_grass";
const tBeachCliff = "cliff_medit_beach";
const tBeachCliff = "medit_dirt";
const tGrassDry = ["medit_grass_field_brown", "medit_grass_field_dry", "medit_grass_field_b"];
const tGrass = ["medit_grass_field_dry", "medit_grass_field_brown", "medit_grass_field_b"];
const tGrassLush = ["grass_temperate_dry_tufts", "medit_grass_flowers"];
@ -116,7 +116,7 @@ for (var i=1; i <= numPlayers; i++)
// create TC and starting units
// TODO: Get civ specific starting units
var civ = getCivCode(i - 1);
placeObject("structures/"+civ + "_civil_centre", i, ix, iy, PI*3/4);
placeObject(ix, iy, "structures/"+civ + "_civil_centre", i, PI*3/4);
var group = new SimpleGroup(
[new SimpleObject("units/"+civ+"_support_female_citizen", 3,3, 5,5)],
true, null, ix, iy
@ -413,7 +413,7 @@ for (var ix=0; ix<mapSize; ix++)
t = (maxH - minH > 1.2) ? tGrassCliff : tGrassDry;
if (maxH - minH < 0.5 && randFloat() < 0.03)
{
placeObject(aGrassDry, 0, ix+randFloat(), iy+randFloat(), randFloat()*2*PI);
placeObject(ix+randFloat(), iy+randFloat(), aGrassDry, 0, randFloat()*2*PI);
}
}
else if (grassNoise > 0.61)
@ -424,7 +424,7 @@ for (var ix=0; ix<mapSize; ix++)
{
if ((maxH - minH) < 0.5 && randFloat() < 0.05)
{
placeObject(aGrass, 0, ix+randFloat(), iy+randFloat(), randFloat()*2*PI);
placeObject(ix+randFloat(), iy+randFloat(), aGrass, 0, randFloat()*2*PI);
}
}
}

View File

@ -2,9 +2,10 @@
"settings" : {
"Name" : "New RMS Test",
"Script" : "new_rms_test.js",
"Description" : "A test of the new integrated random map generator!",
"Description" : "A basic test of the random map generator - not playable",
"BaseTerrain" : "grass1_spring",
"BaseHeight" : 0,
"Keywords": ["demo"],
"XXXXXX" : "Optionally define other things here, like we would for a scenario"
}
}

View File

@ -27,12 +27,12 @@ function tilesToFraction(t)
function fractionToSize(f)
{
return getMapSizeSqr() * f;
return getMapArea() * f;
}
function sizeToFraction(s)
{
return s / getMapSizeSqr();
return s / getMapArea();
}
function cos(x)
@ -162,7 +162,7 @@ function createAreas(centeredPlacer, painter, constraint, num, retryFactor)
bad++;
}
}
return good;
return result;
}
function createObjectGroups(placer, player, constraint, num, retryFactor)
@ -245,7 +245,7 @@ function createSimpleTerrain(terrain)
}
}
function placeObject(type, player, x, y, angle)
function placeObject(x, y, type, player, angle)
{
g_Map.addObjects(new Entity(type, player, x, y, angle));
}
@ -297,7 +297,7 @@ function getMapSize()
return g_Map.size;
}
function getMapSizeSqr()
function getMapArea()
{
return g_Map.size*g_Map.size;
}

View File

@ -2,10 +2,10 @@ var g_Map;
var g_Environment = {
SkySet: "default",
SunColour: {r: 1.5, g: 1.5, b: 1.5, a: 0},
SunColour: {r: 0.749020, g: 0.749020, b: 0.749020, a: 0},
SunElevation: 0.785398,
SunRotation: 5.49779,
TerrainAmbientColour: {r: 0.313726, g: 0.376471, b: 0.521569, a: 0},
TerrainAmbientColour: {r: 0.501961, g: 0.501961, b: 0.501961, a: 0},
UnitsAmbientColour: {r: 0.501961, g: 0.501961, b: 0.501961, a: 0},
Water: {
WaterBody: {

View File

@ -15,9 +15,10 @@ function ClumpPlacer(size, coherence, smoothness, failFraction, x, y)
ClumpPlacer.prototype.place = function(constraint)
{
// Preliminary bounds check
if (!g_Map.validT(this.x, this.y) || !constraint.allows(this.x, this.y))
{
return false;
return undefined;
}
var retVec = [];
@ -26,7 +27,7 @@ ClumpPlacer.prototype.place = function(constraint)
var gotRet = new Array(size);
for (var i = 0; i < size; ++i)
{
gotRet[i] = new Uint8Array(size); // bool / uint8
gotRet[i] = new Uint8Array(size); // bool / uint8
}
var radius = sqrt(this.size / PI);
@ -38,10 +39,11 @@ ClumpPlacer.prototype.place = function(constraint)
if (ctrlPts > radius * 2 * PI)
ctrlPts = Math.floor(radius * 2 * PI) + 1;
var noise = new Float32Array(intPerim); //float32
var noise = new Float32Array(intPerim); //float32
var ctrlCoords = new Float32Array(ctrlPts+1); //float32
var ctrlVals = new Float32Array(ctrlPts+1); //float32
var ctrlVals = new Float32Array(ctrlPts+1); //float32
// Generate some interpolated noise
for (var i=0; i < ctrlPts; i++)
{
ctrlCoords[i] = i * perim / ctrlPts;
@ -59,6 +61,7 @@ ClumpPlacer.prototype.place = function(constraint)
looped = 1;
}
// Cubic interpolation of ctrlVals
var t = (i - ctrlCoords[c]) / ((looped ? perim : ctrlCoords[(c+1)%ctrlPts]) - ctrlCoords[c]);
var v0 = ctrlVals[(c+ctrlPts-1)%ctrlPts];
var v1 = ctrlVals[c];
@ -123,6 +126,13 @@ function RectPlacer(x1, y1, x2, y2)
RectPlacer.prototype.place = function(constraint)
{
// Preliminary bounds check
if (!g_Map.validT(this.x1, this.y1) || !constraint.allows(this.x1, this.y1) ||
!g_Map.validT(this.x2, this.y2) || !constraint.allows(this.x2, this.y2))
{
return undefined;
}
var ret = [];
var x2 = this.x2;
@ -144,7 +154,6 @@ RectPlacer.prototype.place = function(constraint)
}
return ret;
};
/////////////////////////////////////////////////////////////////////////////////////////