mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-16 05:13:58 -07:00
Split up cheats into multiple files. Patch by lsdh/ldsh. Fixes #2019.
Replace buggy hasAllies with the inlined check if we have a team at all.
Fix setting of starting resources (broken in 58fa0c7c58).
This was SVN commit r13620.
This commit is contained in:
parent
c438a1eb82
commit
f6e0c4c5a4
22 changed files with 195 additions and 174 deletions
|
|
@ -9,7 +9,22 @@ const NOTIFICATION_TIMEOUT = 10000;
|
|||
const MAX_NUM_NOTIFICATION_LINES = 3;
|
||||
var notifications = [];
|
||||
var notificationsTimers = [];
|
||||
var cheatList = parseJSONData("simulation/data/cheats.json").Cheats;
|
||||
var cheats = getCheatsData();
|
||||
|
||||
function getCheatsData()
|
||||
{
|
||||
var cheats = {};
|
||||
var cheatFileList = getJSONFileList("simulation/data/cheats/");
|
||||
for each (var fileName in cheatFileList)
|
||||
{
|
||||
var currentCheat = parseJSONData("simulation/data/cheats/"+fileName+".json");
|
||||
if (Object.keys(cheats).indexOf(currentCheat.Name) !== -1)
|
||||
warn("Cheat name '"+currentCheat.Name+"' is already present");
|
||||
else
|
||||
cheats[currentCheat.Name] = currentCheat.Data;
|
||||
}
|
||||
return cheats;
|
||||
}
|
||||
|
||||
// Notifications
|
||||
function handleNotifications()
|
||||
|
|
@ -219,32 +234,33 @@ function submitChatInput()
|
|||
var isCheat = false;
|
||||
if (text.length)
|
||||
{
|
||||
for (var i = 0; i < cheatList.length; i++)
|
||||
if (g_Players[Engine.GetPlayerID()].cheatsEnabled)
|
||||
{
|
||||
var cheat = cheatList[i];
|
||||
|
||||
// Line must start with the cheat.
|
||||
if (text.indexOf(cheat.Name) == 0)
|
||||
for each (var cheat in Object.keys(cheats))
|
||||
{
|
||||
// Line must start with the cheat.
|
||||
if (text.indexOf(cheat) !== 0)
|
||||
continue
|
||||
|
||||
var number;
|
||||
if (cheat.IsNumeric)
|
||||
if (cheats[cheat].DefaultNumber !== undefined)
|
||||
{
|
||||
// Match the first word in the substring.
|
||||
var match = text.substr(cheat.Name.length).match(/\S+/);
|
||||
var match = text.substr(cheat.length).match(/\S+/);
|
||||
if (match && match[0])
|
||||
number = Math.floor(match[0]);
|
||||
|
||||
if (number <= 0 || isNaN(number))
|
||||
number = cheat.DefaultNumber;
|
||||
number = cheats[cheat].DefaultNumber;
|
||||
}
|
||||
|
||||
Engine.PostNetworkCommand({
|
||||
"type": "cheat",
|
||||
"action": cheat.Action,
|
||||
"action": cheats[cheat].Action,
|
||||
"number": number,
|
||||
"text": cheat.Type,
|
||||
"text": cheats[cheat].Type,
|
||||
"selected": g_Selection.toList(),
|
||||
"templates": cheat.Templates,
|
||||
"templates": cheats[cheat].Templates,
|
||||
"player": Engine.GetPlayerID()});
|
||||
isCheat = true;
|
||||
break;
|
||||
|
|
@ -420,62 +436,62 @@ function parseChatCommands(msg, playerAssignments)
|
|||
// Parse commands embedded in the message.
|
||||
switch (split[0])
|
||||
{
|
||||
case "/all":
|
||||
// Resets values that 'team' or 'enemy' may have set.
|
||||
msg.prefix = "";
|
||||
msg.hide = false;
|
||||
recurse = true;
|
||||
break;
|
||||
case "/team":
|
||||
var playerData = getPlayerData();
|
||||
if (hasAllies(sender, playerData))
|
||||
{
|
||||
if (playerData[Engine.GetPlayerID()].team != playerData[sender].team)
|
||||
msg.hide = true;
|
||||
else
|
||||
msg.prefix = "(Team) ";
|
||||
} else {
|
||||
case "/all":
|
||||
// Resets values that 'team' or 'enemy' may have set.
|
||||
msg.prefix = "";
|
||||
msg.hide = false;
|
||||
recurse = true;
|
||||
break;
|
||||
case "/team":
|
||||
// Check if we are in a team.
|
||||
if (g_Players[Engine.GetPlayerID()] && g_Players[Engine.GetPlayerID()].team != -1)
|
||||
{
|
||||
if (g_Players[Engine.GetPlayerID()].team != g_Players[sender].team)
|
||||
msg.hide = true;
|
||||
}
|
||||
recurse = true;
|
||||
break;
|
||||
case "/enemy":
|
||||
var playerData = getPlayerData();
|
||||
if (hasAllies(sender, playerData))
|
||||
{
|
||||
if (playerData[Engine.GetPlayerID()].team == playerData[sender].team && sender != Engine.GetPlayerID())
|
||||
msg.hide = true;
|
||||
else
|
||||
msg.prefix = "(Enemy) ";
|
||||
}
|
||||
recurse = true;
|
||||
break;
|
||||
case "/me":
|
||||
msg.action = true;
|
||||
break;
|
||||
case "/msg":
|
||||
var trimmed = msg.text.substr(split[0].length + 1);
|
||||
var matched = "";
|
||||
|
||||
// Reject names which don't match or are a superset of the intended name.
|
||||
for each (var player in playerAssignments)
|
||||
if (trimmed.indexOf(player.name + " ") == 0 && player.name.length > matched.length)
|
||||
matched = player.name;
|
||||
|
||||
// If the local player's name was the longest one matched, show the message.
|
||||
var playerName = g_Players[Engine.GetPlayerID()].name;
|
||||
if (matched.length && (matched == playerName || sender == Engine.GetPlayerID()))
|
||||
{
|
||||
msg.prefix = "(Private) ";
|
||||
msg.text = trimmed.substr(matched.length + 1);
|
||||
msg.hide = false; // Might override team message hiding.
|
||||
return;
|
||||
}
|
||||
else
|
||||
msg.prefix = "(Team) ";
|
||||
}
|
||||
else
|
||||
msg.hide = true;
|
||||
recurse = true;
|
||||
break;
|
||||
case "/enemy":
|
||||
// Check if we are in a team.
|
||||
if (g_Players[Engine.GetPlayerID()] && g_Players[Engine.GetPlayerID()].team != -1)
|
||||
{
|
||||
if (g_Players[Engine.GetPlayerID()].team == g_Players[sender].team && sender != Engine.GetPlayerID())
|
||||
msg.hide = true;
|
||||
break;
|
||||
default:
|
||||
else
|
||||
msg.prefix = "(Enemy) ";
|
||||
}
|
||||
recurse = true;
|
||||
break;
|
||||
case "/me":
|
||||
msg.action = true;
|
||||
break;
|
||||
case "/msg":
|
||||
var trimmed = msg.text.substr(split[0].length + 1);
|
||||
var matched = "";
|
||||
|
||||
// Reject names which don't match or are a superset of the intended name.
|
||||
for each (var player in playerAssignments)
|
||||
if (trimmed.indexOf(player.name + " ") == 0 && player.name.length > matched.length)
|
||||
matched = player.name;
|
||||
|
||||
// If the local player's name was the longest one matched, show the message.
|
||||
var playerName = g_Players[Engine.GetPlayerID()].name;
|
||||
if (matched.length && (matched == playerName || sender == Engine.GetPlayerID()))
|
||||
{
|
||||
msg.prefix = "(Private) ";
|
||||
msg.text = trimmed.substr(matched.length + 1);
|
||||
msg.hide = false; // Might override team message hiding.
|
||||
return;
|
||||
}
|
||||
else
|
||||
msg.hide = true;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
msg.text = msg.text.substr(split[0].length + 1);
|
||||
|
|
|
|||
|
|
@ -60,6 +60,7 @@ function getPlayerData(playerAssignments)
|
|||
"color": color,
|
||||
"team": playerState.team,
|
||||
"teamsLocked": playerState.teamsLocked,
|
||||
"cheatsEnabled": playerState.cheatsEnabled,
|
||||
"state": playerState.state,
|
||||
"isAlly": playerState.isAlly,
|
||||
"isMutualAlly": playerState.isMutualAlly,
|
||||
|
|
@ -88,18 +89,6 @@ function getPlayerData(playerAssignments)
|
|||
return players;
|
||||
}
|
||||
|
||||
// Returns whether a player has physical allies.
|
||||
function hasAllies(playerID, playerData)
|
||||
{
|
||||
if (playerData[playerID] && playerData[playerID].team != -1)
|
||||
{
|
||||
for (var i = 0; i < playerData.length; i++)
|
||||
if (playerData[i].team == playerData[playerID].team)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function findGuidForPlayerID(playerAssignments, player)
|
||||
{
|
||||
for (var playerGuid in playerAssignments)
|
||||
|
|
|
|||
|
|
@ -87,6 +87,7 @@ GuiInterface.prototype.GetSimulationState = function(player)
|
|||
"state": cmpPlayer.GetState(),
|
||||
"team": cmpPlayer.GetTeam(),
|
||||
"teamsLocked": cmpPlayer.GetLockTeams(),
|
||||
"cheatsEnabled": cmpPlayer.GetCheatsEnabled(),
|
||||
"phase": phase,
|
||||
"isAlly": allies,
|
||||
"isMutualAlly": mutualAllies,
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ Player.prototype.Init = function()
|
|||
this.controlAllUnits = false;
|
||||
this.isAI = false;
|
||||
this.gatherRateMultiplier = 1;
|
||||
this.cheatsEnabled = true;
|
||||
this.cheatsEnabled = false;
|
||||
this.cheatTimeMultiplier = 1;
|
||||
this.heroes = [];
|
||||
};
|
||||
|
|
@ -550,12 +550,12 @@ Player.prototype.OnDiplomacyChanged = function()
|
|||
this.UpdateSharedLos();
|
||||
};
|
||||
|
||||
Player.prototype.SetCheatEnabled = function(flag)
|
||||
Player.prototype.SetCheatsEnabled = function(flag)
|
||||
{
|
||||
this.cheatsEnabled = flag;
|
||||
};
|
||||
|
||||
Player.prototype.GetCheatEnabled = function()
|
||||
Player.prototype.GetCheatsEnabled = function()
|
||||
{
|
||||
return this.cheatsEnabled;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -64,6 +64,7 @@ AddMock(100, IID_Player, {
|
|||
GetState: function() { return "active"; },
|
||||
GetTeam: function() { return -1; },
|
||||
GetLockTeams: function() { return false; },
|
||||
GetCheatsEnabled: function() { return false; },
|
||||
GetDiplomacy: function() { return [-1, 1]; },
|
||||
GetConquestCriticalEntitiesCount: function() { return 1; },
|
||||
IsAlly: function() { return false; },
|
||||
|
|
@ -119,6 +120,7 @@ AddMock(101, IID_Player, {
|
|||
GetState: function() { return "active"; },
|
||||
GetTeam: function() { return -1; },
|
||||
GetLockTeams: function() {return false; },
|
||||
GetCheatsEnabled: function() { return false; },
|
||||
GetDiplomacy: function() { return [-1, 1]; },
|
||||
GetConquestCriticalEntitiesCount: function() { return 1; },
|
||||
IsAlly: function() { return true; },
|
||||
|
|
@ -217,6 +219,7 @@ TS_ASSERT_UNEVAL_EQUALS(cmp.GetSimulationState(), {
|
|||
state: "active",
|
||||
team: -1,
|
||||
teamsLocked: false,
|
||||
cheatsEnabled: false,
|
||||
phase: "village",
|
||||
isAlly: [false, false],
|
||||
isMutualAlly: [false, false],
|
||||
|
|
@ -244,6 +247,7 @@ TS_ASSERT_UNEVAL_EQUALS(cmp.GetSimulationState(), {
|
|||
state: "active",
|
||||
team: -1,
|
||||
teamsLocked: false,
|
||||
cheatsEnabled: false,
|
||||
phase: "village",
|
||||
isAlly: [true, true],
|
||||
isMutualAlly: [false, false],
|
||||
|
|
@ -278,6 +282,7 @@ TS_ASSERT_UNEVAL_EQUALS(cmp.GetExtendedSimulationState(), {
|
|||
state: "active",
|
||||
team: -1,
|
||||
teamsLocked: false,
|
||||
cheatsEnabled: false,
|
||||
phase: "village",
|
||||
isAlly: [false, false],
|
||||
isMutualAlly: [false, false],
|
||||
|
|
@ -321,6 +326,7 @@ TS_ASSERT_UNEVAL_EQUALS(cmp.GetExtendedSimulationState(), {
|
|||
state: "active",
|
||||
team: -1,
|
||||
teamsLocked: false,
|
||||
cheatsEnabled: false,
|
||||
phase: "village",
|
||||
isAlly: [true, true],
|
||||
isMutualAlly: [false, false],
|
||||
|
|
|
|||
|
|
@ -1,91 +0,0 @@
|
|||
{
|
||||
"Cheats":
|
||||
[
|
||||
{
|
||||
"Name": "i want pizza",
|
||||
"Action": "addresource",
|
||||
"Type": "food",
|
||||
"IsNumeric": true,
|
||||
"DefaultNumber": 1000
|
||||
},
|
||||
{
|
||||
"Name": "bring me my axe",
|
||||
"Action": "addresource",
|
||||
"Type": "wood",
|
||||
"IsNumeric": true,
|
||||
"DefaultNumber": 1000
|
||||
},
|
||||
{
|
||||
"Name": "your money or your life",
|
||||
"Action": "addresource",
|
||||
"Type": "metal",
|
||||
"IsNumeric": true,
|
||||
"DefaultNumber": 1000
|
||||
},
|
||||
{
|
||||
"Name": "i see a mountain here",
|
||||
"Action": "addresource",
|
||||
"Type": "stone",
|
||||
"IsNumeric": true,
|
||||
"DefaultNumber": 1000
|
||||
},
|
||||
{
|
||||
"Name": "jame jam",
|
||||
"Action": "revealmap",
|
||||
"IsNumeric": false
|
||||
},
|
||||
{
|
||||
"Name": "the hive master",
|
||||
"Action": "maxpopulation",
|
||||
"IsNumeric": false
|
||||
},
|
||||
{
|
||||
"Name": "TARDIS",
|
||||
"Action": "changemaxpopulation",
|
||||
"IsNumeric": false
|
||||
},
|
||||
{
|
||||
"Name": "iwanttopwnthem",
|
||||
"Action": "createunits",
|
||||
"IsNumeric": true,
|
||||
"DefaultNumber": 1,
|
||||
"Templates": ["units/cart_hero_hamilcar", "units/cart_hero_hannibal", "units/cart_hero_maharbal", "units/rome_hero_marcellus", "units/rome_hero_maximus", "units/rome_hero_scipio", "units/pers_hero_cyrus", "units/pers_hero_darius", "units/pers_hero_xerxes"]
|
||||
},
|
||||
{
|
||||
"Name": "wololo",
|
||||
"Action": "convertunit",
|
||||
"IsNumeric": false
|
||||
},
|
||||
{
|
||||
"Name": "black death",
|
||||
"Action": "killunits",
|
||||
"IsNumeric": false
|
||||
},
|
||||
{
|
||||
"Name": "exodia",
|
||||
"Action": "defeatplayer",
|
||||
"IsNumeric": true,
|
||||
"DefaultNumber": 2
|
||||
},
|
||||
{
|
||||
"Name": "i am too busy",
|
||||
"Action": "fastactions",
|
||||
"IsNumeric": false
|
||||
},
|
||||
{
|
||||
"Name": "how do you turn this on?",
|
||||
"Action": "createunits",
|
||||
"IsNumeric": true,
|
||||
"DefaultNumber": 1,
|
||||
"Templates": ["other/plane"]
|
||||
},
|
||||
{
|
||||
"Name": "salad bowl",
|
||||
"Action": "createunits",
|
||||
"IsNumeric": true,
|
||||
"DefaultNumber": 10,
|
||||
"Templates": ["units/athen_infantry_spearman_b", "units/brit_infantry_spearman_b", "units/cart_infantry_spearman_b", "units/gaul_infantry_spearman_b", "units/iber_infantry_spearman_b",
|
||||
"units/mace_infantry_spearman_b", "units/maur_infantry_spearman_b", "units/pers_infantry_spearman_b", "units/rome_infantry_spearman_b", "units/spart_infantry_spearman_b"]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"Name": "TARDIS",
|
||||
"Data": {
|
||||
"Action": "changemaxpopulation"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"Name": "wololo",
|
||||
"Data": {
|
||||
"Action": "convertunit"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"Name": "iwanttopwnthem",
|
||||
"Data": {
|
||||
"Action": "createunits",
|
||||
"DefaultNumber": 1,
|
||||
"Templates": ["units/cart_hero_hamilcar", "units/cart_hero_hannibal", "units/cart_hero_maharbal", "units/rome_hero_marcellus", "units/rome_hero_maximus", "units/rome_hero_scipio", "units/pers_hero_cyrus", "units/pers_hero_darius", "units/pers_hero_xerxes"]
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"Name": "how do you turn this on?",
|
||||
"Data": {
|
||||
"Action": "createunits",
|
||||
"DefaultNumber": 1,
|
||||
"Templates": ["other/plane"]
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"Name": "salad bowl",
|
||||
"Data": {
|
||||
"Action": "createunits",
|
||||
"DefaultNumber": 10,
|
||||
"Templates": ["units/athen_infantry_spearman_b", "units/brit_infantry_spearman_b", "units/cart_infantry_spearman_b", "units/gaul_infantry_spearman_b", "units/iber_infantry_spearman_b",
|
||||
"units/mace_infantry_spearman_b", "units/maur_infantry_spearman_b", "units/pers_infantry_spearman_b", "units/rome_infantry_spearman_b", "units/spart_infantry_spearman_b"]
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"Name": "exodia",
|
||||
"Data": {
|
||||
"Action": "defeatplayer",
|
||||
"DefaultNumber": 2
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"Name": "i am too busy",
|
||||
"Data": {
|
||||
"Action": "fastactions"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"Name": "i want pizza",
|
||||
"Data": {
|
||||
"Action": "addresource",
|
||||
"Type": "food",
|
||||
"DefaultNumber": 1000
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"Name": "black death",
|
||||
"Data": {
|
||||
"Action": "killunits"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"Name": "the hive master",
|
||||
"Data": {
|
||||
"Action": "maxpopulation"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"Name": "your money or your life",
|
||||
"Data": {
|
||||
"Action": "addresource",
|
||||
"Type": "metal",
|
||||
"DefaultNumber": 1000
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"Name": "jame jam",
|
||||
"Data": {
|
||||
"Action": "revealmap"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"Name": "i see a mountain here",
|
||||
"Data": {
|
||||
"Action": "addresource",
|
||||
"Type": "stone",
|
||||
"DefaultNumber": 1000
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"Name": "bring me my axe",
|
||||
"Data": {
|
||||
"Action": "addresource",
|
||||
"Type": "wood",
|
||||
"DefaultNumber": 1000
|
||||
}
|
||||
}
|
||||
|
|
@ -11,7 +11,7 @@ function Cheat(input)
|
|||
return;
|
||||
|
||||
var cmpGuiInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
|
||||
if (!cmpPlayer.GetCheatEnabled())
|
||||
if (!cmpPlayer.GetCheatsEnabled())
|
||||
{
|
||||
cmpGuiInterface.PushNotification({"type": "chat", "player": input.player, "message": "Cheats are disbaled in this match"});
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -14,24 +14,24 @@ function InitGame(settings)
|
|||
for (var i = 0; i < settings.PlayerData.length; ++i)
|
||||
{
|
||||
var cmpPlayer = Engine.QueryInterface(cmpPlayerManager.GetPlayerByID(i+1), IID_Player);
|
||||
if (!settings.CheatsEnabled)
|
||||
cmpPlayer.SetCheatEnabled(false);
|
||||
cmpPlayer.SetCheatsEnabled(!!settings.CheatsEnabled);
|
||||
if (settings.PlayerData[i] && settings.PlayerData[i].AI && settings.PlayerData[i].AI != "")
|
||||
{
|
||||
cmpAIManager.AddPlayer(settings.PlayerData[i].AI, i+1, settings.PlayerData[i].AIDiff);
|
||||
cmpPlayer.SetAI(true);
|
||||
cmpPlayer.SetGatherRateMultiplier((+settings.PlayerData[i].AIDiff+2)/3.0) // Medium is 1, easy is 66%, hard is 133%, very hard 166%
|
||||
cmpPlayer.SetCheatEnabled(true);
|
||||
}
|
||||
if (settings.PopulationCap)
|
||||
cmpPlayer.SetMaxPopulation(settings.PopulationCap);
|
||||
|
||||
if (settings.mapType !== "scenario" && settings.StartingResources)
|
||||
{
|
||||
var resourceCounts = cmpPlayer.GetResourceCounts();
|
||||
var newResourceCounts = {};
|
||||
for (var resouces in resourceCounts)
|
||||
newResourceCounts[resouces] = settings.StartingResources;
|
||||
cmpPlayer.SetResourceCounts(newResourceCounts);
|
||||
}
|
||||
}
|
||||
cmpAIManager.TryLoadSharedComponent();
|
||||
cmpAIManager.RunGamestateInit();
|
||||
|
|
|
|||
Loading…
Reference in a new issue