1
0
forked from mirrors/0ad

Delete redundant per player CheatsEnable property

We do not see benefit in enabling cheats for certain players but not for the rest.
The AI cheats irrespective of the CheatsEnable property.

This patch uses InitAttributes to check if cheats are enabled making it
slightly harder to workaround it from js.

See SetLosRevealAll in CCmpAIManager and PETRA.Config.prototype.Cheat.

refs 996a32125c / #879 (AI reveal los);
refs 202a02568b /  #1555 (cheat codes, cheatsEnable for AI);
refs 25293ce0cc  (AIDiff GatherRateMultiplier),
refs f6e0c4c5a4  / #2019 (no more cheatsEnable for AI),
refs 3246b02cda  (SetTradeRateMultiplier)
refs de72510c60  / #6302 (move from InitGame.js to petra/config.js)
This commit is contained in:
elexis
2024-12-17 02:00:22 +01:00
committed by Ralph Sennhauser
parent 94c907342a
commit 8b11f6a151
8 changed files with 5 additions and 25 deletions
@@ -25,7 +25,7 @@ class Cheats
{
const player = Engine.GetPlayerID();
if (!controlsPlayer(player) ||
!g_Players[player].cheatsEnabled)
!g_InitAttributes.settings.CheatsEnabled)
return false;
// Find the cheat code that is a prefix of the user input
@@ -395,7 +395,6 @@ function updatePlayerData()
},
"team": playerState.team,
"teamLocked": playerState.teamLocked,
"cheatsEnabled": playerState.cheatsEnabled,
"state": playerState.state,
"isAlly": playerState.isAlly,
"isMutualAlly": playerState.isMutualAlly,
@@ -112,7 +112,6 @@ GuiInterface.prototype.GetSimulationState = function()
"state": cmpPlayer.GetState(),
"team": cmpDiplomacy.GetTeam(),
"teamLocked": cmpDiplomacy.IsTeamLocked(),
"cheatsEnabled": cmpPlayer.GetCheatsEnabled(),
"disabledTemplates": cmpPlayer.GetDisabledTemplates(),
"disabledTechnologies": cmpPlayer.GetDisabledTechnologies(),
"hasSharedDropsites": cmpDiplomacy.HasSharedDropsites(),
@@ -66,7 +66,6 @@ Player.prototype.Init = function()
this.controlAllUnits = false;
this.isAI = false;
this.isRemoved = false;
this.cheatsEnabled = false;
this.panelEntities = [];
this.resourceNames = {};
this.disabledTemplates = {};
@@ -658,16 +657,6 @@ Player.prototype.OnValueModification = function(msg)
}
};
Player.prototype.SetCheatsEnabled = function(flag)
{
this.cheatsEnabled = flag;
};
Player.prototype.GetCheatsEnabled = function()
{
return this.cheatsEnabled;
};
Player.prototype.TributeResource = function(player, amounts)
{
const cmpPlayer = QueryPlayerIDInterface(player);
@@ -118,7 +118,6 @@ AddMock(100, IID_Player, {
"GetPanelEntities": function() { return []; },
"IsTrainingBlocked": function() { return false; },
"GetState": function() { return "active"; },
"GetCheatsEnabled": function() { return false; },
"GetDisabledTemplates": function() { return {}; },
"GetDisabledTechnologies": function() { return {}; },
"CanBarter": function() { return false; },
@@ -214,7 +213,6 @@ AddMock(101, IID_Player, {
"GetPanelEntities": function() { return []; },
"IsTrainingBlocked": function() { return false; },
"GetState": function() { return "active"; },
"GetCheatsEnabled": function() { return false; },
"GetDisabledTemplates": function() { return {}; },
"GetDisabledTechnologies": function() { return {}; },
"CanBarter": function() { return false; },
@@ -319,7 +317,6 @@ TS_ASSERT_UNEVAL_EQUALS(cmp.GetSimulationState(), {
"state": "active",
"team": -1,
"teamLocked": false,
"cheatsEnabled": false,
"disabledTemplates": {},
"disabledTechnologies": {},
"hasSharedDropsites": false,
@@ -370,7 +367,6 @@ TS_ASSERT_UNEVAL_EQUALS(cmp.GetSimulationState(), {
"state": "active",
"team": -1,
"teamLocked": false,
"cheatsEnabled": false,
"disabledTemplates": {},
"disabledTechnologies": {},
"hasSharedDropsites": false,
@@ -432,7 +428,6 @@ TS_ASSERT_UNEVAL_EQUALS(cmp.GetExtendedSimulationState(), {
"state": "active",
"team": -1,
"teamLocked": false,
"cheatsEnabled": false,
"disabledTemplates": {},
"disabledTechnologies": {},
"hasSharedDropsites": false,
@@ -506,7 +501,6 @@ TS_ASSERT_UNEVAL_EQUALS(cmp.GetExtendedSimulationState(), {
"state": "active",
"team": -1,
"teamLocked": false,
"cheatsEnabled": false,
"disabledTemplates": {},
"disabledTechnologies": {},
"hasSharedDropsites": false,
@@ -8,7 +8,7 @@ function Cheat(input)
if (playerEnt == INVALID_ENTITY)
return;
const cmpPlayer = Engine.QueryInterface(playerEnt, IID_Player);
if (!cmpPlayer?.GetCheatsEnabled())
if (!InitAttributes.settings.CheatsEnabled)
return;
const cmpGuiInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
@@ -71,7 +71,7 @@ var g_Commands = {
"control-all": function(player, cmd, data)
{
if (!data.cmpPlayer.GetCheatsEnabled())
if (!InitAttributes.settings.CheatsEnabled)
return;
var cmpGuiInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
@@ -86,7 +86,7 @@ var g_Commands = {
"reveal-map": function(player, cmd, data)
{
if (!data.cmpPlayer.GetCheatsEnabled())
if (!InitAttributes.settings.CheatsEnabled)
return;
var cmpGuiInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
@@ -614,7 +614,7 @@ var g_Commands = {
"promote": function(player, cmd, data)
{
if (!data.cmpPlayer.GetCheatsEnabled())
if (!InitAttributes.settings.CheatsEnabled)
return;
var cmpGuiInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
@@ -45,7 +45,6 @@ function InitGame(settings)
for (let i = 0; i < settings.PlayerData.length; ++i)
{
const cmpPlayer = QueryPlayerIDInterface(i);
cmpPlayer.SetCheatsEnabled(!!settings.CheatsEnabled);
if (settings.PlayerData[i])
{