mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-07-04 05:55:47 -07:00
New gamesetup option enabling the host to vary the time required to win the wonder-gamemode. Patch by svott, fixes #3234.
This was SVN commit r18075.
This commit is contained in:
parent
46443f92c9
commit
b2fdfeba53
9 changed files with 156 additions and 30 deletions
|
|
@ -32,6 +32,7 @@ function loadSettingsValues()
|
|||
"AIDescriptions": loadAIDescriptions(),
|
||||
"AIDifficulties": loadAIDifficulties(),
|
||||
"Ceasefire": loadCeasefire(),
|
||||
"WonderDurations": loadWonderDuration(),
|
||||
"GameSpeeds": loadSettingValuesFile("game_speeds.json"),
|
||||
"MapTypes": loadMapTypes(),
|
||||
"MapSizes": loadSettingValuesFile("map_sizes.json"),
|
||||
|
|
@ -130,6 +131,27 @@ function loadAIDifficulties()
|
|||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads available wonder-victory times
|
||||
*/
|
||||
function loadWonderDuration()
|
||||
{
|
||||
var jsonFile = "wonder_times.json";
|
||||
var json = Engine.ReadJSONFile(g_SettingsDirectory + jsonFile);
|
||||
|
||||
if (!json || json.Default === undefined || !json.Times || !Array.isArray(json.Times))
|
||||
{
|
||||
error("Could not load " + jsonFile);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return json.Times.map(duration => ({
|
||||
"Duration": duration,
|
||||
"Default": duration == json.Default,
|
||||
"Title": sprintf(translatePluralWithContext("wonder victory", "%(min)s minute", "%(min)s minutes", duration), { "min": duration })
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads available ceasefire settings.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ const g_MapTypes = prepareForDropdown(g_Settings && g_Settings.MapTypes);
|
|||
const g_PopulationCapacities = prepareForDropdown(g_Settings && g_Settings.PopulationCapacities);
|
||||
const g_StartingResources = prepareForDropdown(g_Settings && g_Settings.StartingResources);
|
||||
const g_VictoryConditions = prepareForDropdown(g_Settings && g_Settings.VictoryConditions);
|
||||
const g_WonderDurations = prepareForDropdown(g_Settings && g_Settings.WonderDurations);
|
||||
|
||||
/**
|
||||
* All selectable playercolors except gaia.
|
||||
|
|
@ -248,6 +249,7 @@ function initGUIObjects()
|
|||
initPopulationCaps();
|
||||
initStartingResources();
|
||||
initCeasefire();
|
||||
initWonderDurations();
|
||||
initVictoryConditions();
|
||||
initMapSizes();
|
||||
initRadioButtons();
|
||||
|
|
@ -300,22 +302,49 @@ function initMapFilters()
|
|||
}
|
||||
|
||||
/**
|
||||
* Sets the size of the more-options dialog.
|
||||
* Remove empty space in case of hidden options (like cheats, rating or wonder duration)
|
||||
*/
|
||||
function resizeMoreOptionsWindow()
|
||||
{
|
||||
// For singleplayer reduce the size of more options dialog by two options (cheats, rated game = 60px)
|
||||
if (!g_IsNetworked)
|
||||
const elementHeight = 30;
|
||||
const elements = [
|
||||
"optionGameSpeed",
|
||||
"optionVictoryCondition",
|
||||
"optionWonderDuration",
|
||||
"optionPopulationCap",
|
||||
"optionStartingResources",
|
||||
"optionCeasefire",
|
||||
"optionRevealMap",
|
||||
"optionExploreMap",
|
||||
"optionDisableTreasures",
|
||||
"optionLockTeams",
|
||||
"optionCheats",
|
||||
"optionRating",
|
||||
"hideMoreOptions"
|
||||
];
|
||||
|
||||
let yPos = undefined;
|
||||
for (let element of elements)
|
||||
{
|
||||
Engine.GetGUIObjectByName("moreOptions").size = "50%-200 50%-195 50%+200 50%+160";
|
||||
Engine.GetGUIObjectByName("hideMoreOptions").size = "50%-70 310 50%+70 336";
|
||||
}
|
||||
// For non-lobby multiplayergames reduce the size of the dialog by one option (rated game, 30px)
|
||||
else if (!Engine.HasXmppClient())
|
||||
{
|
||||
Engine.GetGUIObjectByName("moreOptions").size = "50%-200 50%-195 50%+200 50%+190";
|
||||
Engine.GetGUIObjectByName("hideMoreOptions").size = "50%-70 340 50%+70 366";
|
||||
let guiOption = Engine.GetGUIObjectByName(element);
|
||||
let gSize = guiOption.size;
|
||||
yPos = yPos || gSize.top;
|
||||
|
||||
if (guiOption.hidden)
|
||||
continue;
|
||||
|
||||
gSize.top = yPos;
|
||||
gSize.bottom = yPos + elementHeight - 2;
|
||||
guiOption.size = gSize;
|
||||
|
||||
yPos += elementHeight;
|
||||
}
|
||||
|
||||
// Resize the vertically centered window containing the options
|
||||
let moreOptions = Engine.GetGUIObjectByName("moreOptions");
|
||||
let mSize = moreOptions.size;
|
||||
mSize.bottom = mSize.top + yPos + 20;
|
||||
moreOptions.size = mSize;
|
||||
}
|
||||
|
||||
function initNumberOfPlayers()
|
||||
|
|
@ -406,6 +435,21 @@ function initVictoryConditions()
|
|||
victoryConditions.selected = g_VictoryConditions.Default;
|
||||
}
|
||||
|
||||
function initWonderDurations()
|
||||
{
|
||||
let wonderConditions = Engine.GetGUIObjectByName("wonderDuration");
|
||||
wonderConditions.list = g_WonderDurations.Title;
|
||||
wonderConditions.list_data = g_WonderDurations.Duration;
|
||||
wonderConditions.onSelectionChange = function()
|
||||
{
|
||||
if (this.selected != -1)
|
||||
g_GameAttributes.settings.WonderDuration = g_WonderDurations.Duration[this.selected];
|
||||
|
||||
updateGameAttributes();
|
||||
};
|
||||
wonderConditions.selected = g_WonderDurations.Default;
|
||||
}
|
||||
|
||||
function initMapSizes()
|
||||
{
|
||||
let mapSize = Engine.GetGUIObjectByName("mapSize");
|
||||
|
|
@ -1090,6 +1134,9 @@ function selectMap(name)
|
|||
g_GameAttributes.settings.VictoryScripts = g_VictoryConditions.Scripts[victoryIdx];
|
||||
}
|
||||
|
||||
if (g_GameAttributes.mapType == "scenario")
|
||||
delete g_GameAttributes.settings.WonderDuration;
|
||||
|
||||
if (mapSettings.PlayerData)
|
||||
sanitizePlayerData(mapSettings.PlayerData);
|
||||
|
||||
|
|
@ -1243,6 +1290,7 @@ function updateGUIObjects()
|
|||
// These dropdowns might set the default (as they ignore g_IsInGuiUpdate)
|
||||
let mapSizeIdx = mapSettings.Size !== undefined ? g_MapSizes.Tiles.indexOf(mapSettings.Size) : g_MapSizes.Default;
|
||||
let victoryIdx = mapSettings.GameType !== undefined ? g_VictoryConditions.Name.indexOf(mapSettings.GameType) : g_VictoryConditions.Default;
|
||||
let wonderDurationIdx = mapSettings.WonderDuration !== undefined ? g_WonderDurations.Duration.indexOf(mapSettings.WonderDuration) : g_WonderDurations.Default;
|
||||
let popIdx = mapSettings.PopulationCap !== undefined ? g_PopulationCapacities.Population.indexOf(mapSettings.PopulationCap) : g_PopulationCapacities.Default;
|
||||
let startingResIdx = mapSettings.StartingResources !== undefined ? g_StartingResources.Resources.indexOf(mapSettings.StartingResources) : g_StartingResources.Default;
|
||||
let ceasefireIdx = mapSettings.Ceasefire !== undefined ? g_Ceasefire.Duration.indexOf(mapSettings.Ceasefire) : g_Ceasefire.Default;
|
||||
|
|
@ -1256,6 +1304,7 @@ function updateGUIObjects()
|
|||
Engine.GetGUIObjectByName("mapSize").selected = mapSizeIdx;
|
||||
Engine.GetGUIObjectByName("numPlayersSelection").selected = numPlayers - 1;
|
||||
Engine.GetGUIObjectByName("victoryCondition").selected = victoryIdx;
|
||||
Engine.GetGUIObjectByName("wonderDuration").selected = wonderDurationIdx;
|
||||
Engine.GetGUIObjectByName("populationCap").selected = popIdx;
|
||||
Engine.GetGUIObjectByName("gameSpeed").selected = gameSpeedIdx;
|
||||
Engine.GetGUIObjectByName("ceasefire").selected = ceasefireIdx;
|
||||
|
|
@ -1273,6 +1322,7 @@ function updateGUIObjects()
|
|||
Engine.GetGUIObjectByName("mapSizeText").caption = g_GameAttributes.mapType == "random" ? g_MapSizes.LongName[mapSizeIdx] : translate("Default");
|
||||
Engine.GetGUIObjectByName("numPlayersText").caption = numPlayers;
|
||||
Engine.GetGUIObjectByName("victoryConditionText").caption = g_VictoryConditions.Title[victoryIdx];
|
||||
Engine.GetGUIObjectByName("wonderDurationText").caption = g_WonderDurations.Title[wonderDurationIdx];
|
||||
Engine.GetGUIObjectByName("populationCapText").caption = g_PopulationCapacities.Title[popIdx];
|
||||
Engine.GetGUIObjectByName("startingResourcesText").caption = g_StartingResources.Title[startingResIdx];
|
||||
Engine.GetGUIObjectByName("ceasefireText").caption = g_Ceasefire.Title[ceasefireIdx];
|
||||
|
|
@ -1285,6 +1335,10 @@ function updateGUIObjects()
|
|||
setGUIBoolean("lockTeams", "lockTeamsText", !!mapSettings.LockTeams);
|
||||
setGUIBoolean("enableRating", "enableRatingText", !!mapSettings.RatingEnabled);
|
||||
|
||||
Engine.GetGUIObjectByName("optionWonderDuration").hidden =
|
||||
g_GameAttributes.settings.GameType &&
|
||||
g_GameAttributes.settings.GameType != "wonder";
|
||||
|
||||
Engine.GetGUIObjectByName("cheatWarningText").hidden = !g_IsNetworked || !mapSettings.CheatsEnabled;
|
||||
|
||||
Engine.GetGUIObjectByName("enableCheats").enabled = !mapSettings.RatingEnabled;
|
||||
|
|
@ -1299,6 +1353,7 @@ function updateGUIObjects()
|
|||
|
||||
let notScenario = g_GameAttributes.mapType != "scenario" && g_IsController ;
|
||||
hideControl("victoryCondition", "victoryConditionText", notScenario);
|
||||
hideControl("wonderDuration", "wonderDurationText", notScenario);
|
||||
hideControl("populationCap", "populationCapText", notScenario);
|
||||
hideControl("startingResources", "startingResourcesText", notScenario);
|
||||
hideControl("ceasefire", "ceasefireText", notScenario);
|
||||
|
|
@ -1356,6 +1411,8 @@ function updateGUIObjects()
|
|||
pColorPicker.selected = g_PlayerColors.findIndex(col => sameColor(col, color));
|
||||
}
|
||||
|
||||
resizeMoreOptionsWindow();
|
||||
|
||||
g_IsInGuiUpdate = false;
|
||||
|
||||
// Game attributes include AI settings, so update the player list
|
||||
|
|
@ -1374,7 +1431,21 @@ function setMapDescription()
|
|||
let mapName = g_GameAttributes.map || "";
|
||||
|
||||
let victoryIdx = Math.max(0, g_VictoryConditions.Name.indexOf(g_GameAttributes.settings.GameType || ""));
|
||||
let victoryTitle = g_VictoryConditions.Title[victoryIdx];
|
||||
let victoryTitle;
|
||||
|
||||
if (g_VictoryConditions.Name[victoryIdx] == "wonder")
|
||||
victoryTitle = sprintf(
|
||||
translatePluralWithContext(
|
||||
"victory condition",
|
||||
"Wonder (%(min)s minute)",
|
||||
"Wonder (%(min)s minutes)",
|
||||
g_GameAttributes.settings.WonderDuration
|
||||
),
|
||||
{ "min": g_GameAttributes.settings.WonderDuration }
|
||||
);
|
||||
else
|
||||
victoryTitle = g_VictoryConditions.Title[victoryIdx];
|
||||
|
||||
if (victoryIdx != g_VictoryConditions.Default)
|
||||
victoryTitle = "[color=\"" + g_VictoryColor + "\"]" + victoryTitle + "[/color]";
|
||||
|
||||
|
|
|
|||
|
|
@ -276,7 +276,7 @@
|
|||
<translatableAttribute id="caption">More Options</translatableAttribute>
|
||||
</object>
|
||||
|
||||
<object size="14 38 94% 66">
|
||||
<object name="optionGameSpeed" size="14 38 94% 66">
|
||||
<object size="0 0 40% 28" type="text" style="ModernRightLabelText">
|
||||
<translatableAttribute id="caption">Game Speed:</translatableAttribute>
|
||||
</object>
|
||||
|
|
@ -286,7 +286,7 @@
|
|||
</object>
|
||||
</object>
|
||||
|
||||
<object size="14 68 94% 96">
|
||||
<object name="optionVictoryCondition" size="14 68 94% 96">
|
||||
<object size="0 0 40% 28" type="text" style="ModernRightLabelText">
|
||||
<translatableAttribute id="caption">Victory Condition:</translatableAttribute>
|
||||
</object>
|
||||
|
|
@ -296,7 +296,17 @@
|
|||
</object>
|
||||
</object>
|
||||
|
||||
<object size="14 98 94% 126">
|
||||
<object name="optionWonderDuration" size="14 188 94% 216">
|
||||
<object size="0 0 40% 28" type="text" style="ModernRightLabelText">
|
||||
<translatableAttribute id="caption">Wonder Victory:</translatableAttribute>
|
||||
</object>
|
||||
<object name="wonderDurationText" size="40% 0 100% 100%" type="text" style="ModernLeftLabelText"/>
|
||||
<object name="wonderDuration" size="40%+10 0 100% 28" type="dropdown" style="ModernDropDown" hidden="true" tooltip_style="onscreenToolTip">
|
||||
<translatableAttribute id="tooltip">Number of minutes that the player has to keep the wonder in order to win.</translatableAttribute>
|
||||
</object>
|
||||
</object>
|
||||
|
||||
<object name="optionPopulationCap" size="14 98 94% 126">
|
||||
<object size="0 0 40% 28" type="text" style="ModernRightLabelText">
|
||||
<translatableAttribute id="caption">Population Cap:</translatableAttribute>
|
||||
</object>
|
||||
|
|
@ -306,7 +316,7 @@
|
|||
</object>
|
||||
</object>
|
||||
|
||||
<object size="14 128 94% 156">
|
||||
<object name="optionStartingResources" size="14 128 94% 156">
|
||||
<object size="0 0 40% 28" type="text" style="ModernRightLabelText">
|
||||
<translatableAttribute id="caption">Starting Resources:</translatableAttribute>
|
||||
</object>
|
||||
|
|
@ -316,7 +326,7 @@
|
|||
</object>
|
||||
</object>
|
||||
|
||||
<object size="14 158 94% 186">
|
||||
<object name="optionCeasefire" size="14 158 94% 186">
|
||||
<object size="0 0 40% 28" type="text" style="ModernRightLabelText">
|
||||
<translatableAttribute id="caption">Ceasefire:</translatableAttribute>
|
||||
</object>
|
||||
|
|
@ -326,7 +336,7 @@
|
|||
</object>
|
||||
</object>
|
||||
|
||||
<object size="14 188 94% 216">
|
||||
<object name="optionRevealMap" size="14 218 94% 246">
|
||||
<object size="0 0 40% 28" type="text" style="ModernRightLabelText">
|
||||
<translatableAttribute id="caption" comment="Make sure to differentiate between the revealed map and explored map options!">Revealed Map:</translatableAttribute>
|
||||
</object>
|
||||
|
|
@ -336,7 +346,7 @@
|
|||
</object>
|
||||
</object>
|
||||
|
||||
<object size="14 218 94% 246">
|
||||
<object name="optionExploreMap" size="14 248 94% 276">
|
||||
<object size="0 0 40% 28" type="text" style="ModernRightLabelText">
|
||||
<translatableAttribute id="caption" comment="Make sure to differentiate between the revealed map and explored map options!">Explored Map:</translatableAttribute>
|
||||
</object>
|
||||
|
|
@ -346,7 +356,7 @@
|
|||
</object>
|
||||
</object>
|
||||
|
||||
<object size="14 248 94% 276">
|
||||
<object name="optionDisableTreasures" size="14 278 94% 306">
|
||||
<object size="0 0 40% 28" type="text" style="ModernRightLabelText">
|
||||
<translatableAttribute id="caption">Disable Treasures:</translatableAttribute>
|
||||
</object>
|
||||
|
|
@ -356,7 +366,7 @@
|
|||
</object>
|
||||
</object>
|
||||
|
||||
<object size="14 278 94% 306">
|
||||
<object name="optionLockTeams" size="14 308 94% 336">
|
||||
<object size="0 0 40% 28" type="text" style="ModernRightLabelText">
|
||||
<translatableAttribute id="caption">Teams Locked:</translatableAttribute>
|
||||
</object>
|
||||
|
|
@ -366,7 +376,7 @@
|
|||
</object>
|
||||
</object>
|
||||
|
||||
<object name="optionCheats" size="14 308 94% 336" hidden="true">
|
||||
<object name="optionCheats" size="14 338 94% 366" hidden="true">
|
||||
<object size="0 0 40% 28" type="text" style="ModernRightLabelText">
|
||||
<translatableAttribute id="caption">Cheats:</translatableAttribute>
|
||||
</object>
|
||||
|
|
@ -376,7 +386,7 @@
|
|||
</object>
|
||||
</object>
|
||||
|
||||
<object name="optionRating" size="14 338 94% 366" hidden="true">
|
||||
<object name="optionRating" size="14 368 94% 396" hidden="true">
|
||||
<object size="0 0 40% 28" hidden="false" type="text" style="ModernRightLabelText">
|
||||
<translatableAttribute id="caption">Rated Game:</translatableAttribute>
|
||||
</object>
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ Trigger.prototype.CheckWonderVictory = function(data)
|
|||
if (i != data.to)
|
||||
players.push(i);
|
||||
|
||||
var time = cmpWonder.GetTimeTillVictory()*1000;
|
||||
var time = cmpWonder.GetVictoryDuration();
|
||||
messages.otherMessage = cmpGuiInterface.AddTimeNotification({
|
||||
"message": markForTranslation("%(player)s will have won in %(time)s"),
|
||||
"players": players,
|
||||
|
|
|
|||
|
|
@ -15,7 +15,9 @@ EndGameManager.prototype.Init = function()
|
|||
// Game type, initialised from the map settings.
|
||||
// One of: "conquest" (default) and "endless"
|
||||
this.gameType = "conquest";
|
||||
|
||||
|
||||
this.wonderDuration = 10 * 60 * 1000;
|
||||
|
||||
// Allied victory means allied players can win if victory conditions are met for each of them
|
||||
// Would be false for a "last man standing" game (when diplomacy is fully implemented)
|
||||
this.alliedVictory = true;
|
||||
|
|
@ -37,6 +39,16 @@ EndGameManager.prototype.CheckGameType = function(type)
|
|||
return this.gameType == type;
|
||||
};
|
||||
|
||||
EndGameManager.prototype.SetWonderDuration = function(wonderDuration)
|
||||
{
|
||||
this.wonderDuration = wonderDuration;
|
||||
};
|
||||
|
||||
EndGameManager.prototype.GetWonderDuration = function()
|
||||
{
|
||||
return this.wonderDuration;
|
||||
};
|
||||
|
||||
EndGameManager.prototype.MarkPlayerAsWon = function(playerID)
|
||||
{
|
||||
var cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
function Wonder() {}
|
||||
|
||||
Wonder.prototype.Schema =
|
||||
"<element name='TimeTillVictory'>" +
|
||||
"<data type='nonNegativeInteger'/>" +
|
||||
"<element name='DurationMultiplier' a:help='A civ-specific time-bonus/handicap for the wonder-victory-condition.'>" +
|
||||
"<ref name='nonNegativeDecimal'/>" +
|
||||
"</element>";
|
||||
|
||||
Wonder.prototype.Init = function()
|
||||
|
|
@ -11,9 +11,13 @@ Wonder.prototype.Init = function()
|
|||
|
||||
Wonder.prototype.Serialize = null;
|
||||
|
||||
Wonder.prototype.GetTimeTillVictory = function()
|
||||
/**
|
||||
* Returns the number of minutes that a player has to keep the wonder in order to win.
|
||||
*/
|
||||
Wonder.prototype.GetVictoryDuration = function()
|
||||
{
|
||||
return +this.template.TimeTillVictory;
|
||||
var cmpEndGameManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_EndGameManager);
|
||||
return cmpEndGameManager.GetWonderDuration() * this.template.DurationMultiplier;
|
||||
};
|
||||
|
||||
Engine.RegisterComponentType(IID_Wonder, "Wonder", Wonder);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"Times": [1, 3, 5, 10, 15, 20, 25, 30, 45, 60],
|
||||
"Default": 15
|
||||
}
|
||||
|
||||
|
|
@ -49,6 +49,8 @@ function LoadMapSettings(settings)
|
|||
var cmpEndGameManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_EndGameManager);
|
||||
if (settings.GameType)
|
||||
cmpEndGameManager.SetGameType(settings.GameType);
|
||||
if (settings.WonderDuration)
|
||||
cmpEndGameManager.SetWonderDuration(settings.WonderDuration * 60 * 1000);
|
||||
|
||||
if (settings.Garrison)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -91,6 +91,6 @@
|
|||
<FoundationActor>structures/fndn_6x6.xml</FoundationActor>
|
||||
</VisualActor>
|
||||
<Wonder>
|
||||
<TimeTillVictory>600</TimeTillVictory>
|
||||
<DurationMultiplier>1</DurationMultiplier>
|
||||
</Wonder>
|
||||
</Entity>
|
||||
|
|
|
|||
Loading…
Reference in a new issue