Page MenuHomeWildfire Games

petra: fight back when a cc is captured instead of retreating
ClosedPublic

Authored by mimo on May 29 2017, 10:58 PM.

Details

Summary

rP19655 prevented the ai defensive units to drift towards enemy territories when chasing units, but it has a side effect when the enemy succeed to capture an ai cc, as all defensive units find themselves in enemy territory and retreat.
This patch transforms then the defensive units in an attacking army who tries to get back the cc.

Test Plan

check the behaviour when an ai cc is captured

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.May 29 2017, 10:58 PM
Vulcan added a subscriber: Vulcan.May 30 2017, 12:17 AM

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/1411/ for more details.

Executing section Default...
Executing section Source...
Executing section JS...
|    | [NORMAL] ESLintBear (dot-notation):
|    | ["Attack"] is better written in dot notation.
|----|    | /mnt/data/jenkins-phabricator/workspace/phabricator_lint/binaries/data/mods/public/simulation/ai/petra/attackManager.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/phabricator_lint/binaries/data/mods/public/simulation/ai/petra/attackManager.js
| 517| 517| 		return false;
| 518| 518| 	this.totalNumber++;
| 519| 519| 	attackPlan.init(gameState);
| 520|    |-	this.startedAttacks["Attack"].push(attackPlan);
|    | 520|+	this.startedAttacks.Attack.push(attackPlan);
| 521| 521| 
| 522| 522| 	for (let i = 0; i < gameState.ai.HQ.defenseManager.armies.length; ++i)
| 523| 523| 	{

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/attackManager.js
| 520| »   this.startedAttacks["Attack"].push(attackPlan);
|    | [NORMAL] JSHintBear:
|    | ['Attack'] is better written in dot notation.

binaries/data/mods/public/simulation/ai/petra/headquarters.js
|1329| »   plan.onStart·=·function(gameState)·{·gameState.ai.queueManager.changePriority("economicBuilding",·gameState.ai.Config.priorities.economicBuilding);·};
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'gameState' is already declared in the upper scope.

binaries/data/mods/public/simulation/ai/petra/headquarters.js
|1409| »   »   plan.isGo·=·function·(gameState)·{
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'gameState' is already declared in the upper scope.

binaries/data/mods/public/simulation/ai/petra/headquarters.js
|1571| »   »   »   »   plan.onStart·=·function(gameState)·{·gameState.ai.queueManager.changePriority("defenseBuilding",·gameState.ai.Config.priorities.defenseBuilding);·};
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'gameState' is already declared in the upper scope.

binaries/data/mods/public/simulation/ai/petra/headquarters.js
|1603| »   »   plan.onStart·=·function(gameState)·{·gameState.ai.queueManager.changePriority("defenseBuilding",·gameState.ai.Config.priorities.defenseBuilding);·};
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'gameState' is already declared in the upper scope.

binaries/data/mods/public/simulation/ai/petra/headquarters.js
|1643| »   »   »   plan.onStart·=·function(gameState)·{·gameState.ai.queueManager.changePriority("militaryBuilding",·gameState.ai.Config.priorities.militaryBuilding);·};
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'gameState' is already declared in the upper scope.

binaries/data/mods/public/simulation/ai/petra/headquarters.js
| 170| »   »   »   »   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/84/ for more details.

mimo updated this revision to Diff 2321.May 30 2017, 9:40 PM
mimo edited the summary of this revision. (Show Details)

fix lint warning

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/1418/ 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/petra/headquarters.js
|1329| »   plan.onStart·=·function(gameState)·{·gameState.ai.queueManager.changePriority("economicBuilding",·gameState.ai.Config.priorities.economicBuilding);·};
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'gameState' is already declared in the upper scope.

binaries/data/mods/public/simulation/ai/petra/headquarters.js
|1409| »   »   plan.isGo·=·function·(gameState)·{
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'gameState' is already declared in the upper scope.

binaries/data/mods/public/simulation/ai/petra/headquarters.js
|1571| »   »   »   »   plan.onStart·=·function(gameState)·{·gameState.ai.queueManager.changePriority("defenseBuilding",·gameState.ai.Config.priorities.defenseBuilding);·};
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'gameState' is already declared in the upper scope.

binaries/data/mods/public/simulation/ai/petra/headquarters.js
|1603| »   »   plan.onStart·=·function(gameState)·{·gameState.ai.queueManager.changePriority("defenseBuilding",·gameState.ai.Config.priorities.defenseBuilding);·};
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'gameState' is already declared in the upper scope.

binaries/data/mods/public/simulation/ai/petra/headquarters.js
|1643| »   »   »   plan.onStart·=·function(gameState)·{·gameState.ai.queueManager.changePriority("militaryBuilding",·gameState.ai.Config.priorities.militaryBuilding);·};
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'gameState' is already declared in the upper scope.

binaries/data/mods/public/simulation/ai/petra/headquarters.js
| 170| »   »   »   »   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/87/ for more details.

Sandarac added inline comments.
binaries/data/mods/public/simulation/ai/petra/attackManager.js
507 ↗(On Diff #2321)

I think either the function name has to be changed to reflect that it is used for CCs, or this comment has to be changed to show that this is a more generic function designed to counter an attack/capture event that occurred against a generic entity.

527 ↗(On Diff #2321)

Perhaps armies that are a bit further away than what is done currently should be included; I did a little bit of testing (albeit not very thorough), and it seems to me in that in general, if an AI has a CC captured, the chances of it regaining it (or even just fighting off the enemy player) are not very high. So this may help somewhat in some cases.

mimo updated this revision to Diff 2333.May 31 2017, 5:35 PM

update

mimo added inline comments.May 31 2017, 5:44 PM
binaries/data/mods/public/simulation/ai/petra/attackManager.js
507 ↗(On Diff #2321)

yep, the comment had to be changed as this function is quite generic

527 ↗(On Diff #2321)

I agree the chances of regaining it are usually very small, but the main reason of this change was that it was strange to see the ai retreating as soon as it lost his cc without even trying to fight, and it is more fun for the human player to have to fight. On the other side, as as you said the chances for the ai to win are small, the goal was not to involve its full armies, but only those already around the cc which were fighting the enemies capturing the cc, and give some chance for the units a bit farther to be able to retreat without being attacked during their retreat.
But that said, the current distance (150m) is completely arbitrary and if you have some proposition, for a better value, just let me know it.

Sandarac accepted this revision.May 31 2017, 6:18 PM

The patch was tested, and it works as advertised.

This revision is now accepted and ready to land.May 31 2017, 6:18 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/1419/ 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/petra/headquarters.js
|1329| »   plan.onStart·=·function(gameState)·{·gameState.ai.queueManager.changePriority("economicBuilding",·gameState.ai.Config.priorities.economicBuilding);·};
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'gameState' is already declared in the upper scope.

binaries/data/mods/public/simulation/ai/petra/headquarters.js
|1409| »   »   plan.isGo·=·function·(gameState)·{
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'gameState' is already declared in the upper scope.

binaries/data/mods/public/simulation/ai/petra/headquarters.js
|1571| »   »   »   »   plan.onStart·=·function(gameState)·{·gameState.ai.queueManager.changePriority("defenseBuilding",·gameState.ai.Config.priorities.defenseBuilding);·};
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'gameState' is already declared in the upper scope.

binaries/data/mods/public/simulation/ai/petra/headquarters.js
|1603| »   »   plan.onStart·=·function(gameState)·{·gameState.ai.queueManager.changePriority("defenseBuilding",·gameState.ai.Config.priorities.defenseBuilding);·};
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'gameState' is already declared in the upper scope.

binaries/data/mods/public/simulation/ai/petra/headquarters.js
|1643| »   »   »   plan.onStart·=·function(gameState)·{·gameState.ai.queueManager.changePriority("militaryBuilding",·gameState.ai.Config.priorities.militaryBuilding);·};
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'gameState' is already declared in the upper scope.

binaries/data/mods/public/simulation/ai/petra/headquarters.js
| 170| »   »   »   »   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/88/ for more details.

This revision was automatically updated to reflect the committed changes.