Skip to content
This repository has been archived by the owner on Sep 5, 2022. It is now read-only.

Commit

Permalink
Add support for 0AD A25 (#7)
Browse files Browse the repository at this point in the history
* Add support for 0AD A25

* AllyMap -> AllyView + bump version.

* All "Ally Map" changed to "Ally View". Also changed code names for
consistency.
* Bump version number

* Add missing newlines (to meet unix file spec).

* Remove pointless comments

* Reduce code + more mod-friendly

Rather than re-defining entire classes/ functions, just extend the code
we want to extend (by e.g. saving game code temporarily an "old"
variable and re-defining). Reduces code duplication + more friendly
towards other mods that may want to modify the same classes/ functions.
  • Loading branch information
Jammyjamjamman authored Jun 3, 2021
1 parent d2003fe commit 7353985
Show file tree
Hide file tree
Showing 9 changed files with 459 additions and 0 deletions.
10 changes: 10 additions & 0 deletions a25/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# CartographyMode

A [0 A.D.](https://play0ad.com/) mod; adds an "ally view" option to the
game set-up menu, which allows allies to share vision at game start.

[Forum post](https://wildfiregames.com/forum/index.php?/topic/27265-theres-any-mod-so-you-can-see-what-your-allies-see-from-the-start/&do=findComment&comment=397504)

This mod was created by
[Jammyjamjamman](https://github.com/jammyjamjamman) and maintained by
him and [Andy Alt](https://github.com/andy5995).
254 changes: 254 additions & 0 deletions a25/gui/common/gamedescription_CartographyMode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,254 @@
/**
* Sets an additional map label, map preview image and describes the chosen gamesettings more closely.
*
* Requires g_GameAttributes and g_VictoryConditions.
*/
function getGameDescriptionList(initAttributes, mapCache)
{
let titles = [];
if (!initAttributes.settings.VictoryConditions.length)
titles.push({
"label": translateWithContext("victory condition", "Endless Game"),
"value": translate("No winner will be determined, even if everyone is defeated.")
});

for (let victoryCondition of g_VictoryConditions)
{
if (initAttributes.settings.VictoryConditions.indexOf(victoryCondition.Name) == -1)
continue;

let title = translateVictoryCondition(victoryCondition.Name);
if (victoryCondition.Name == "wonder")
{
let wonderDuration = Math.round(initAttributes.settings.WonderDuration);
title = sprintf(
translatePluralWithContext(
"victory condition",
"Wonder (%(min)s minute)",
"Wonder (%(min)s minutes)",
wonderDuration
),
{ "min": wonderDuration });
}

let isCaptureTheRelic = victoryCondition.Name == "capture_the_relic";
if (isCaptureTheRelic)
{
let relicDuration = Math.round(initAttributes.settings.RelicDuration);
title = sprintf(
translatePluralWithContext(
"victory condition",
"Capture the Relic (%(min)s minute)",
"Capture the Relic (%(min)s minutes)",
relicDuration
),
{ "min": relicDuration });
}

titles.push({
"label": title,
"value": victoryCondition.Description
});

if (isCaptureTheRelic)
titles.push({
"label": translate("Relic Count"),
"value": Math.round(initAttributes.settings.RelicCount)
});

if (victoryCondition.Name == "regicide")
if (initAttributes.settings.RegicideGarrison)
titles.push({
"label": translate("Hero Garrison"),
"value": translate("Heroes can be garrisoned.")
});
else
titles.push({
"label": translate("Exposed Heroes"),
"value": translate("Heroes cannot be garrisoned and they are vulnerable to raids.")
});
}

if (initAttributes.settings.RatingEnabled &&
initAttributes.settings.PlayerData.length == 2)
titles.push({
"label": translate("Rated game"),
"value": translate("When the winner of this match is determined, the lobby score will be adapted.")
});

if (initAttributes.settings.LockTeams)
titles.push({
"label": translate("Locked Teams"),
"value": translate("Players can't change the initial teams.")
});
else
titles.push({
"label": translate("Diplomacy"),
"value": translate("Players can make alliances and declare war on allies.")
});

if (initAttributes.settings.LastManStanding)
titles.push({
"label": translate("Last Man Standing"),
"value": translate("Only one player can win the game. If the remaining players are allies, the game continues until only one remains.")
});
else
titles.push({
"label": translate("Allied Victory"),
"value": translate("If one player wins, his or her allies win too. If one group of allies remains, they win.")
});

let ceasefire = Math.round(initAttributes.settings.Ceasefire);
titles.push({
"label": translate("Ceasefire"),
"value":
!ceasefire ?
translate("disabled") :
sprintf(translatePlural(
"For the first minute, other players will stay neutral.",
"For the first %(min)s minutes, other players will stay neutral.",
ceasefire),
{ "min": ceasefire })
});

if (initAttributes.map == "random")
titles.push({
"label": translateWithContext("Map Selection", "Random Map"),
"value": translate("Randomly select a map from the list.")
});
else
{
titles.push({
"label": translate("Map Name"),
"value": mapCache.translateMapName(
mapCache.getTranslatableMapName(initAttributes.mapType, initAttributes.map, initAttributes))
});

titles.push({
"label": translate("Map Description"),
"value": mapCache.getTranslatedMapDescription(initAttributes.mapType, initAttributes.map)
});
}

titles.push({
"label": translate("Map Type"),
"value": g_MapTypes.Title[g_MapTypes.Name.indexOf(initAttributes.mapType)]
});

if (initAttributes.mapType == "random")
{
let mapSize = g_MapSizes.Name[g_MapSizes.Tiles.indexOf(initAttributes.settings.Size)];
if (mapSize)
titles.push({
"label": translate("Map Size"),
"value": mapSize
});
}

if (initAttributes.settings.Biome)
{
let biome = g_Settings.Biomes.find(b => b.Id == initAttributes.settings.Biome);
titles.push({
"label": biome ? biome.Title : translateWithContext("biome", "Random Biome"),
"value": biome ? biome.Description : translate("Randomly select a biome from the list.")
});
}

if (initAttributes.settings.TriggerDifficulty !== undefined)
{
let triggerDifficulty = g_Settings.TriggerDifficulties.find(difficulty => difficulty.Difficulty == initAttributes.settings.TriggerDifficulty);
titles.push({
"label": triggerDifficulty.Title,
"value": triggerDifficulty.Tooltip
});
}

if (initAttributes.settings.Nomad !== undefined)
titles.push({
"label": initAttributes.settings.Nomad ? translate("Nomad Mode") : translate("Civic Centers"),
"value":
initAttributes.settings.Nomad ?
translate("Players start with only few units and have to find a suitable place to build their city.") :
translate("Players start with a Civic Center.")
});

if (initAttributes.settings.StartingResources !== undefined)
titles.push({
"label": translate("Starting Resources"),
"value":
initAttributes.settings.PlayerData &&
initAttributes.settings.PlayerData.some(pData => pData && pData.Resources !== undefined) ?
translateWithContext("starting resources", "Per Player") :
sprintf(translate("%(startingResourcesTitle)s (%(amount)s)"), {
"startingResourcesTitle":
g_StartingResources.Title[
g_StartingResources.Resources.indexOf(
initAttributes.settings.StartingResources)],
"amount": initAttributes.settings.StartingResources
})
});

if (initAttributes.settings.PopulationCap !== undefined)
titles.push({
"label": translate("Population Limit"),
"value":
initAttributes.settings.PlayerData &&
initAttributes.settings.PlayerData.some(pData => pData && pData.PopulationLimit !== undefined) ?
translateWithContext("population limit", "Per Player") :
g_PopulationCapacities.Title[
g_PopulationCapacities.Population.indexOf(
initAttributes.settings.PopulationCap)]
});

if (initAttributes.settings.WorldPopulationCap !== undefined)
titles.push({
"label": translate("World Population Cap"),
"value":
g_WorldPopulationCapacities.Title[
g_WorldPopulationCapacities.Population.indexOf(
initAttributes.settings.WorldPopulationCap)]
});

titles.push({
"label": translate("Treasures"),
"value": initAttributes.settings.DisableTreasures ?
translateWithContext("treasures", "Disabled") :
translateWithContext("treasures", "As defined by the map.")
});

titles.push({
"label": translate("Explored Map"),
"value": initAttributes.settings.ExploreMap
});

titles.push({
"label": translate("Revealed Map"),
"value": initAttributes.settings.RevealMap
});

titles.push({
"label": translate("Cheats"),
"value": initAttributes.settings.CheatsEnabled
});

return titles;
}

function modDescriptions(initAttributes, titles) {
titles.push({
"label": translate("Allied View"),
"value": initAttributes.settings.AllyView
});
return titles;
}

function getGameDescription(initAttributes, mapCache) {
let titles = getGameDescriptionList(initAttributes, mapCache);
titles = modDescriptions(initAttributes, titles);
return titles.map(title => sprintf(translate("%(label)s %(details)s"), {
"label": coloredText(title.label, g_DescriptionHighlight),
"details":
title.value === true ? translateWithContext("game setup option", "enabled") :
title.value || translateWithContext("game setup option", "disabled")
})).join("\n");
}
37 changes: 37 additions & 0 deletions a25/gui/gamesettings/attributes/MapExploration_CartographyMode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
let initOld = GameSettings.prototype.Attributes.MapExploration.prototype.init;
GameSettings.prototype.Attributes.MapExploration.prototype.init = function () {
initOld.call(this);
this.allied = false;
}

let toInitAttributesOld = GameSettings.prototype.Attributes.MapExploration.prototype.toInitAttributes;
GameSettings.prototype.Attributes.MapExploration.prototype.toInitAttributes = function (attribs) {
toInitAttributesOld.call(this, attribs);
attribs.settings.AllyView = this.allied;
}

let fromInitAttributesOld = GameSettings.prototype.Attributes.MapExploration.prototype.fromInitAttributes;
GameSettings.prototype.Attributes.MapExploration.prototype.fromInitAttributes = function (attribs) {
fromInitAttributesOld.call(this, attribs);
this.allied = !!this.getLegacySetting(attribs, "AllyView");
}

let onMapChangeOld = GameSettings.prototype.Attributes.MapExploration.prototype.onMapChange;
GameSettings.prototype.Attributes.MapExploration.prototype.onMapChange = function (mapData) {
onMapChangeOld.call(this, mapData);
this.setRevealed(this.getMapSetting("AllyView"));
}

let setRevealedOld = GameSettings.prototype.Attributes.MapExploration.prototype.setRevealed;
GameSettings.prototype.Attributes.MapExploration.prototype.setRevealed = function (enabled) {
setRevealedOld.call(this, enabled);
this.allied = this.allied || enabled;
}

GameSettings.prototype.Attributes.MapExploration.prototype.setAllied = function (enabled) {
this.allied = enabled;
this.revealed = this.revealed && this.allied;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
g_GameSettingsLayout[0]["settings"].push("AlliedView");
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
GameSettingControls.AlliedView = class AlliedView extends GameSettingControlCheckbox
{
constructor(...args)
{
super(...args);
g_GameSettings.mapExploration.watch(() => this.render(), ["allied"]);
g_GameSettings.map.watch(() => this.render(), ["type"]);
this.render();
}

render()
{
this.setEnabled(g_GameSettings.map.type != "scenario");
this.setChecked(g_GameSettings.mapExploration.allied);
}

onPress(checked)
{
g_GameSettings.mapExploration.setAllied(checked);
this.gameSettingsController.setNetworkInitAttributes();
}
};

GameSettingControls.AlliedView.prototype.TitleCaption =
translate("Allied View");

GameSettingControls.AlliedView.prototype.Tooltip =
translate("Toggle allied view (see what your allies see).");
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
let registerWatchersOld = GameDescription.prototype.registerWatchers;
GameDescription.prototype.registerWatchers = function () {
registerWatchersOld.call(this);
let update = () => this.updateGameDescription();
g_GameSettings.mapExploration.watch(update, ["allied"]);
}
}
11 changes: 11 additions & 0 deletions a25/l10n/en_GB.public-gui-gamesetup-CartographyMode.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#. Translation: Make sure to differentiate between the revealed map and
#. ally view settings!
#: gui/gamesetup/gamesetup_CartographMode.js
msgid "Ally View"
msgstr "Ally View"

#. Translation: Make sure to differentiate between the revealed map and
#. ally view settings!
#: gui/gamesetup/gamesetup_CarographyMode.js
msgid "Toggle allied view (see everything you + allies can see)."
msgstr "Toggle allied view (see everything you + allies can see)."
7 changes: 7 additions & 0 deletions a25/mod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "CartographyMode",
"version": "2.0.0",
"label": "Cartography Mode",
"description": "Start a game with \"cartography mode\" researched for all players. Everyone sees what their allies can see from the start of the game.",
"dependencies": ["0ad=0.0.25"]
}
Loading

0 comments on commit 7353985

Please sign in to comment.