Fix Atlas warning on reinit.

AIDiff is undefined when calling InitGame. But this cheat stuff should
not be in the helper.
(Now people don't need to change the helper if they want a non-cheating
AI. @Silier)

This patch is favoured over @trompetin17's by Wilfy:
https://irclogs.wildfiregames.com/%230ad-dev/2023-01-16-QuakeNet-%230ad-dev.log
@ 21:14.

Reported by: @Langbart
Differential revision: https://code.wildfiregames.com/D4881
Fixes #6302

This was SVN commit r27463.
This commit is contained in:
Freagarach 2023-01-18 07:56:03 +00:00
parent 490aceb4ff
commit de72510c60
4 changed files with 27 additions and 16 deletions

View file

@ -320,11 +320,28 @@ PETRA.Config.prototype.setConfig = function(gameState)
"roots": this.criticalRootFactors[this.difficulty],
};
this.Cheat(gameState);
if (this.debug < 2)
return;
API3.warn(" >>> Petra bot: personality = " + uneval(this.personality));
};
PETRA.Config.prototype.Cheat = function(gameState)
{
// Sandbox, Very Easy, Easy, Medium, Hard, Very Hard
// rate apply on resource stockpiling as gathering and trading
// time apply on building, upgrading, packing, training and technologies
const rate = [ 0.42, 0.56, 0.75, 1.00, 1.25, 1.56 ];
const time = [ 1.40, 1.25, 1.10, 1.00, 1.00, 1.00 ];
const AIDiff = Math.min(this.difficulty, rate.length - 1);
SimEngine.QueryInterface(Sim.SYSTEM_ENTITY, Sim.IID_ModifiersManager).AddModifiers("AI Bonus", {
"ResourceGatherer/BaseSpeed": [{ "affects": ["Unit", "Structure"], "multiply": rate[AIDiff] }],
"Trader/GainMultiplier": [{ "affects": ["Unit", "Structure"], "multiply": rate[AIDiff] }],
"Cost/BuildTime": [{ "affects": ["Unit", "Structure"], "multiply": time[AIDiff] }],
}, gameState.playerData.entity);
};
PETRA.Config.prototype.Serialize = function()
{
var data = {};

View file

@ -97,6 +97,7 @@ GuiInterface.prototype.GetSimulationState = function()
"name": cmpIdentity.GetName(),
"civ": cmpIdentity.GetCiv(),
"color": cmpPlayer.GetColor(),
"entity": cmpPlayer.entity,
"controlsAll": cmpPlayer.CanControlAllUnits(),
"popCount": cmpPlayer.GetPopulationCount(),
"popLimit": cmpPlayer.GetPopulationLimit(),

View file

@ -100,6 +100,7 @@ AddMock(SYSTEM_ENTITY, IID_Timer, {
});
AddMock(100, IID_Player, {
"entity": 100,
"GetColor": function() { return { "r": 1, "g": 1, "b": 1, "a": 1 }; },
"CanControlAllUnits": function() { return false; },
"GetPopulationCount": function() { return 10; },
@ -192,6 +193,7 @@ AddMock(100, IID_StatisticsTracker, {
});
AddMock(101, IID_Player, {
"entity": 101,
"GetColor": function() { return { "r": 1, "g": 0, "b": 0, "a": 1 }; },
"CanControlAllUnits": function() { return true; },
"GetPopulationCount": function() { return 40; },
@ -292,6 +294,7 @@ TS_ASSERT_UNEVAL_EQUALS(cmp.GetSimulationState(), {
"name": "Player 1",
"civ": "gaia",
"color": { "r": 1, "g": 1, "b": 1, "a": 1 },
"entity": 100,
"controlsAll": false,
"popCount": 10,
"popLimit": 20,
@ -342,6 +345,7 @@ TS_ASSERT_UNEVAL_EQUALS(cmp.GetSimulationState(), {
"name": "Player 2",
"civ": "mace",
"color": { "r": 1, "g": 0, "b": 0, "a": 1 },
"entity": 101,
"controlsAll": true,
"popCount": 40,
"popLimit": 30,
@ -402,6 +406,7 @@ TS_ASSERT_UNEVAL_EQUALS(cmp.GetExtendedSimulationState(), {
"name": "Player 1",
"civ": "gaia",
"color": { "r": 1, "g": 1, "b": 1, "a": 1 },
"entity": 100,
"controlsAll": false,
"popCount": 10,
"popLimit": 20,
@ -475,6 +480,7 @@ TS_ASSERT_UNEVAL_EQUALS(cmp.GetExtendedSimulationState(), {
"name": "Player 2",
"civ": "mace",
"color": { "r": 1, "g": 0, "b": 0, "a": 1 },
"entity": 101,
"controlsAll": true,
"popCount": 40,
"popLimit": 30,

View file

@ -41,29 +41,16 @@ function InitGame(settings)
cmpRangeManager.ExploreMap(i);
}
// Sandbox, Very Easy, Easy, Medium, Hard, Very Hard
// rate apply on resource stockpiling as gathering and trading
// time apply on building, upgrading, packing, training and technologies
let rate = [ 0.42, 0.56, 0.75, 1.00, 1.25, 1.56 ];
let time = [ 1.40, 1.25, 1.10, 1.00, 1.00, 1.00 ];
let cmpModifiersManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_ModifiersManager);
let cmpAIManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_AIManager);
const cmpAIManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_AIManager);
for (let i = 0; i < settings.PlayerData.length; ++i)
{
let cmpPlayer = QueryPlayerIDInterface(i);
const cmpPlayer = QueryPlayerIDInterface(i);
cmpPlayer.SetCheatsEnabled(!!settings.CheatsEnabled);
if (settings.PlayerData[i] && !!settings.PlayerData[i].AI)
{
let AIDiff = +settings.PlayerData[i].AIDiff;
cmpAIManager.AddPlayer(settings.PlayerData[i].AI, i, AIDiff, settings.PlayerData[i].AIBehavior || "random");
cmpAIManager.AddPlayer(settings.PlayerData[i].AI, i, +settings.PlayerData[i].AIDiff, settings.PlayerData[i].AIBehavior || "random");
cmpPlayer.SetAI(true);
AIDiff = Math.min(AIDiff, rate.length - 1);
cmpModifiersManager.AddModifiers("AI Bonus", {
"ResourceGatherer/BaseSpeed": [{ "affects": ["Unit", "Structure"], "multiply": rate[AIDiff] }],
"Trader/GainMultiplier": [{ "affects": ["Unit", "Structure"], "multiply": rate[AIDiff] }],
"Cost/BuildTime": [{ "affects": ["Unit", "Structure"], "multiply": time[AIDiff] }],
}, cmpPlayer.entity);
}
if (settings.PopulationCap)