patch for A23
change the way petra deals with phasing up, to ease the way it manages the phase requirements (in particular for mods). All these requirements are now regrouped and extracted in the phaseRequirements.js file, so that it can be modified by the mods. To allow tests with different requirements (and as an example for other mods), I've implemented the delenda ones.
A later step will be to have a generic AI function which return (quickly) a list of templates with a given class, and choose the appropriate one to build.
In addition, petra is now aware of the number of phase when a mod adds additional ones.
Details
- Reviewers
- None
- Commits
- rP20039: petra: revisit the phasing up to be more mod-friendly
check that the code is correct.
test phasing up with different civs on vanilla and delenda.
Diff Detail
- Repository
- rP 0 A.D. Public Repository
- Lint
Automatic diff as part of commit; lint not applicable. - Unit
Automatic diff as part of commit; unit tests not applicable.
Event Timeline
Build is green
Updating workspaces. Build (release)... Build (debug)... Running release tests... Running cxxtest tests (306 tests)..................................................................................................................................................................................................................................................................................................................OK! Running debug tests... Running cxxtest tests (306 tests)..................................................................................................................................................................................................................................................................................................................OK! Checking XML files...
http://jw:8080/job/phabricator/1580/ for more details.
Executing section Default... Executing section Source... Executing section JS... binaries/data/mods/public/simulation/ai/petra/attackManager.js | 361| » » » let·relicsCount·=·allRelics.filter(relic·=>·relic.owner()·===·i).length; | | [NORMAL] JSHintBear: | | Don't make functions within a loop. binaries/data/mods/public/simulation/ai/common-api/gamestate.js | 269| » » switch·(entity.check) | | [NORMAL] ESLintBear (default-case): | | Expected a default case. binaries/data/mods/public/simulation/ai/common-api/gamestate.js | 286| » » » switch·(type) | | [NORMAL] ESLintBear (default-case): | | Expected a default case. binaries/data/mods/public/simulation/ai/common-api/gamestate.js | 789| » » » if·(this.phases.every(phase·=>·template._templateName·!=·phase.name)) | | [NORMAL] JSHintBear: | | Don't make functions within a loop. | | [NORMAL] ESLintBear (dot-notation): | | ["default"] is better written in dot notation. |----| | /mnt/data/jenkins-phabricator/workspace/phabricator_lint/binaries/data/mods/public/simulation/ai/petra/navalManager.js | |++++| /mnt/data/jenkins-phabricator/workspace/phabricator_lint/binaries/data/mods/public/simulation/ai/petra/navalManager.js | 109| 109| if (civ in this.Config.buildings.naval) | 110| 110| this.bNaval = this.Config.buildings.naval[civ]; | 111| 111| else | 112| |- this.bNaval = this.Config.buildings.naval['default']; | | 112|+ this.bNaval = this.Config.buildings.naval.default; | 113| 113| | 114| 114| for (let i in this.bNaval) | 115| 115| this.bNaval[i] = gameState.applyCiv(this.bNaval[i]); binaries/data/mods/public/simulation/ai/petra/navalManager.js | 321| » » » plan.units.forEach(function·(ent)·{ | | [NORMAL] JSHintBear: | | Don't make functions within a loop. binaries/data/mods/public/simulation/ai/petra/navalManager.js | 332| » » » plan.units.forEach(function·(ent)·{ | | [NORMAL] JSHintBear: | | Don't make functions within a loop. binaries/data/mods/public/simulation/ai/petra/phaseRequirements.js | 36| » » » » » let·plan·=·new·m.ConstructionPlan(gameState,·"structures/{civ}_temple"); | | [NORMAL] ESLintBear (no-shadow): | | 'plan' is already declared in the upper scope. binaries/data/mods/public/simulation/ai/petra/phaseRequirements.js | 89| » » » » plan.queueToReset·=·"majorTech" | | [NORMAL] JSHintBear: | | Missing semicolon. binaries/data/mods/public/simulation/ai/petra/phaseRequirements.js | 110| }(PETRA) | | [NORMAL] JSHintBear: | | Missing semicolon. binaries/data/mods/public/simulation/ai/petra/headquarters.js | 168| » » » » builders.forEach(function·(worker)·{ | | [NORMAL] JSHintBear: | | Don't make functions within a loop. Executing section XML GUI... Executing section Python... Executing section Perl...
http://jw:8080/job/phabricator_lint/206/ for more details.
Build is green
Updating workspaces. Build (release)... Build (debug)... Running release tests... Running cxxtest tests (306 tests)..................................................................................................................................................................................................................................................................................................................OK! Running debug tests... Running cxxtest tests (306 tests)..................................................................................................................................................................................................................................................................................................................OK! Checking XML files...
http://jw:8080/job/phabricator/1853/ for more details.
Executing section Default... Executing section Source... Executing section JS... binaries/data/mods/public/simulation/ai/common-api/gamestate.js | 269| » » switch·(entity.check) | | [NORMAL] ESLintBear (default-case): | | Expected a default case. binaries/data/mods/public/simulation/ai/common-api/gamestate.js | 286| » » » switch·(type) | | [NORMAL] ESLintBear (default-case): | | Expected a default case. binaries/data/mods/public/simulation/ai/common-api/gamestate.js | 789| » » » if·(this.phases.every(phase·=>·template._templateName·!=·phase.name)) | | [NORMAL] JSHintBear: | | Don't make functions within a loop. binaries/data/mods/public/simulation/ai/petra/navalManager.js | 309| » » » plan.units.forEach(function·(ent)·{ | | [NORMAL] JSHintBear: | | Don't make functions within a loop. binaries/data/mods/public/simulation/ai/petra/navalManager.js | 320| » » » plan.units.forEach(function·(ent)·{ | | [NORMAL] JSHintBear: | | Don't make functions within a loop. binaries/data/mods/public/simulation/ai/petra/attackManager.js | 361| » » » let·relicsCount·=·allRelics.filter(relic·=>·relic.owner()·===·i).length; | | [NORMAL] JSHintBear: | | Don't make functions within a loop. binaries/data/mods/public/simulation/ai/petra/headquarters.js | 168| » » » » builders.forEach(function·(worker)·{ | | [NORMAL] JSHintBear: | | Don't make functions within a loop. Executing section XML GUI... Executing section Python... Executing section Perl...
http://jw:8080/job/phabricator_lint/393/ for more details.
(Some verbose linting that can be ignored)
binaries/data/mods/public/simulation/ai/common-api/entity.js | ||
---|---|---|
79 ↗ | (On Diff #3121) | Could be if (techRequired.startsWith("phase_")) (ES6) https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith |
binaries/data/mods/public/simulation/ai/petra/headquarters.js | ||
432 ↗ | (On Diff #3121) | (The symmetry that 3 lines provide allow the reader to notice immediately that all conditions start with !queues. and ends with .hasQueuedUnits()) |
binaries/data/mods/public/simulation/ai/petra/researchManager.js | ||
33 ↗ | (On Diff #3121) | (If the order of the two conditions isn't relevant, parentheses could be removed and var could be inlined: if (gameState.hasResearchers(nextPhaseName, true) && (currentPhaseIndex == 1 && gameState.getPopulation() >= this.Config.Economy.popPhase2 || currentPhaseIndex == 2 && gameState.getOwnEntitiesByRole("worker", true).length > this.Config.Economy.workPhase3 || currentPhaseIndex >= 3 && gameState.getOwnEntitiesByRole("worker", true).length > this.Config.Economy.workPhase4)) ) |
binaries/data/mods/public/simulation/ai/common-api/entity.js | ||
---|---|---|
79 ↗ | (On Diff #3121) | ok |
binaries/data/mods/public/simulation/ai/petra/headquarters.js | ||
432 ↗ | (On Diff #3121) | ok |
binaries/data/mods/public/simulation/ai/petra/researchManager.js | ||
33 ↗ | (On Diff #3121) | the order matters (hasResearchers is slower), but ok that parentheses can be removed |
Build is green
Updating workspaces. Build (release)... Build (debug)... Running release tests... Running cxxtest tests (306 tests)..................................................................................................................................................................................................................................................................................................................OK! Running debug tests... Running cxxtest tests (306 tests)..................................................................................................................................................................................................................................................................................................................OK! Checking XML files...
http://jw:8080/job/phabricator/1854/ for more details.
Executing section Default... Executing section Source... Executing section JS... binaries/data/mods/public/simulation/ai/petra/attackManager.js | 361| » » » let·relicsCount·=·allRelics.filter(relic·=>·relic.owner()·===·i).length; | | [NORMAL] JSHintBear: | | Don't make functions within a loop. binaries/data/mods/public/simulation/ai/common-api/gamestate.js | 269| » » switch·(entity.check) | | [NORMAL] ESLintBear (default-case): | | Expected a default case. binaries/data/mods/public/simulation/ai/common-api/gamestate.js | 286| » » » switch·(type) | | [NORMAL] ESLintBear (default-case): | | Expected a default case. binaries/data/mods/public/simulation/ai/common-api/gamestate.js | 789| » » » if·(this.phases.every(phase·=>·template._templateName·!=·phase.name)) | | [NORMAL] JSHintBear: | | Don't make functions within a loop. binaries/data/mods/public/simulation/ai/petra/navalManager.js | 309| » » » plan.units.forEach(function·(ent)·{ | | [NORMAL] JSHintBear: | | Don't make functions within a loop. binaries/data/mods/public/simulation/ai/petra/navalManager.js | 320| » » » plan.units.forEach(function·(ent)·{ | | [NORMAL] JSHintBear: | | Don't make functions within a loop. binaries/data/mods/public/simulation/ai/petra/headquarters.js | 168| » » » » builders.forEach(function·(worker)·{ | | [NORMAL] JSHintBear: | | Don't make functions within a loop. binaries/data/mods/public/simulation/ai/petra/headquarters.js |2319| » » if·(gameState.ai.playedTurn·%·4·==·0) | | [NORMAL] JSHintBear: | | Use '===' to compare with '0'. Executing section XML GUI... Executing section Python... Executing section Perl...
http://jw:8080/job/phabricator_lint/394/ for more details.