Page MenuHomeWildfire Games

petra: revisit the phasing up
ClosedPublic

Authored by mimo on Jun 18 2017, 1:53 PM.

Details

Summary

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.

Test Plan

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

mimo created this revision.Jun 18 2017, 1:53 PM
Vulcan added a subscriber: Vulcan.Jun 18 2017, 2:41 PM

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.

mimo updated this revision to Diff 3121.Aug 14 2017, 1:07 PM

rebased version, with numerous improvments.

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.

elexis added a subscriber: elexis.Aug 14 2017, 2:16 PM

(Some verbose linting that can be ignored)

binaries/data/mods/public/simulation/ai/common-api/entity.js
79 ↗(On Diff #3121)
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))

)

mimo added inline comments.Aug 14 2017, 3:35 PM
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

mimo updated this revision to Diff 3122.Aug 14 2017, 3:42 PM

update

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.

This revision was automatically updated to reflect the committed changes.