Opened 3 years ago

Closed 16 months ago

#6302 closed defect (fixed)

Warning in Atlas about GetTechModifiedProperty

Reported by: Langbart Owned by: Freagarach
Priority: Should Have Milestone: Alpha 27
Component: Atlas editor Keywords:
Cc: Patch: Phab:D4881

Description (last modified by Langbart)

Starting an AI simulation in Atlas throws the following warnings:

WARNING: GetTechModifiedProperty: numeric modification format not recognised : ({affects:["Unit", "Structure"], multiply:(void 0)})
WARNING: GetTechModifiedProperty: numeric modification format not recognised : ({affects:["Unit", "Structure"], multiply:(void 0)})

The problem can be reproduced consistently for the current SVN [25877] version, for A25, for A24b, but the warnings do not occur in A23b.

Steps:

  • Open Atlas
  • Click on Change Players
  • Select AI for player 1
  • Click on Generate map

Stan wrote under patch D3784

Pretty sure it started with the modifiers manager in A24.

The warnings do not appear at [21945] (A23b macOS), I managed to compile up to [24278] and the warnings still appear.

The ModifiersManager.js was added with [22767], but I am not able to compile with this changeset number, I get problems with the library files on macOS.

Attachments (1)

GetTechModifiedProperty.jpg (169.8 KB ) - added by Langbart 3 years ago.

Download all attachments as: .zip

Change History (10)

by Langbart, 3 years ago

Attachment: GetTechModifiedProperty.jpg added

comment:1 by Langbart, 3 years ago

Description: modified (diff)

comment:2 by Freagarach, 2 years ago

Milestone: Alpha 26Alpha 27

comment:3 by Freagarach, 16 months ago

Patch: Phab:D4881

comment:4 by Freagarach, 16 months ago

(Not assigning myself since this patch probably just hides the problem.)

comment:5 by trompetin17, 16 months ago

I was investigating this ticket and I found there reason about this error:

Im going to add the trace

GetTechModifiedProperty_numeric@globalscripts/Technologies.js:68:14
GetTechModifiedProperty@globalscripts/Technologies.js:27:10
ModifiersManager.prototype.FetchModifiedProperty@simulation/components/ModifiersManager.js:110:9
ModifiersManager.prototype.ApplyTemplateModifiers@simulation/components/ModifiersManager.js:193:14
ApplyValueModificationsToTemplate@simulation/helpers/ValueModification.js:19:31 
AIInterface.prototype.OnTemplateModification@simulation/components/AIInterface.js:256:52 
ModifiersManager.prototype.SendPlayerModifierMessages@simulation/components/ModifiersManager.js:69:9 
ModifiersManager.prototype.ModifiersChanged@simulation/components/ModifiersManager.js:60:9 
ModifiersManager.prototype.Init/this.modifiersStorage._OnItemModified@simulation/components/ModifiersManager.js:23:87 
MultiKeyMap.prototype.AddItem@globalscripts/MultiKeyMap.js:49:7 MultiKeyMap.prototype.AddItems@globalscripts/MultiKeyMap.js:62:19 
ModifiersManager.prototype.AddModifiers@simulation/components/ModifiersManager.js:265:31 
InitGame@simulation/helpers/InitGame.js:64:24

When you generate a random map it call "InitGame" and in L58

let AIDiff = +settings.PlayerData[i].AIDiff;

AIDiff is undifined but that "+" make AIDiff to "NaN", so Math.min is going to return "NaN" but rate[AIDiff] is going to return "undefined".

cmpAIManager.AddPlayer(settings.PlayerData[i].AI, 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);

the code above have a dependency for this variable.

Now why this is happen, well the current code from AtlasUI (widget) the only attribute set is AI nothing else you can see here https://code.wildfiregames.com/source/0ad/browse/ps/trunk/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Player/Player.cpp$882

so we can have three options to resolve the problem:

  1. (easy one) Add the validation about AIDiff early in the if code
if (settings.PlayerData[i] && !!settings.PlayerData[i].AI && !!settings.PlayerData[i].AIDiff)
  1. (another easy) set the default value if inst defined (like AIBehavior) with 3
let AIDiff = +settings.PlayerData[i].AIDiff || 3;
  1. (hard one) expand AtlasUI to handle AIBehavior and AIDiff

What should be use? suggestions?

comment:6 by trompetin17, 16 months ago

my third option is add this lines in https://code.wildfiregames.com/source/0ad/browse/ps/trunk/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Player/Player.cpp$882

player.set("AI", str->GetData().utf8_str());
player.setInt("AIDiff", (*playerDefs["AIDiff"]).getInt());
player.set("AIBehavior", (*playerDefs["AIBehavior"]));
Version 0, edited 16 months ago by trompetin17 (next)

comment:7 by Stan, 16 months ago

I'm not sure which option is the best yet. Depending on how long AtlasUI as we know it will stay

How are other defaults handled? In JS or in CPP?

in reply to:  6 comment:8 by Langbart, 16 months ago

Replying to trompetin17:

  1. (easy one) Add the validation about AIDiff early in the if code
if (settings.PlayerData[i] && !!settings.PlayerData[i].AI && !!settings.PlayerData[i].AIDiff)

In this solution, the entities would not be controlled by the AI in Atlas, but would just stand there.


  1. (another easy) set the default value if inst defined (like AIBehavior) with 3
let AIDiff = +settings.PlayerData[i].AIDiff || 3;

this would work, but I don't like the 3 - Don't Repeat Yourself (DRY)

default.cfg

Line 
418assignplayers = everyone ; Whether to assign joining clients to free playerslots. Possible values: everyone, buddies, disabled.
419aidifficulty = 3 ; Difficulty level, from 0 (easiest) to 5 (hardest)
420aibehavior = "random" ; Default behavior of the AI (random, balanced, aggressive or defensive)

Replying to trompetin17:

my fourth option is add this lines in Sections/Player/Player.cpp

  • source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Player/Player.cpp

    a b AtObj PlayerSettingsControl::UpdateSettingsObject()  
    880880            // ai - get id
    881881            wxStringClientData* str = dynamic_cast<wxStringClientData*>(choice->GetClientObject(choice->GetSelection()));
    882882            player.set("AI", str->GetData().utf8_str());
     883            player.setInt("AIDiff", (*playerDefs["AIDiff"]).getInt());
     884            player.set("AIBehavior", (*playerDefs["AIBehavior"]));
    883885        }
    884886        else // human
    885887            player.unset("AI");

this would work or ​Phab:D488, flip a coin, commit, close ticket.

You can let the IRC WildfireBot decide for you

# Randomly chooses <num> items out of the arguments given.
# https://github.com/progval/Limnoria/tree/master/plugins/Utilities
@sample 1 " trompetin17"  "​Freagarach"

comment:9 by Freagarach, 16 months ago

Owner: set to Freagarach
Resolution: fixed
Status: newclosed

In 27463:

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

Note: See TracTickets for help on using tickets.