Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/ai/petra/attackPlan.js
var PETRA = function(m) | (function(m) | ||||
{ | { | ||||
/** | /** | ||||
* This is an attack plan: | * This is an attack plan: | ||||
* It deals with everything in an attack, from picking a target to picking a path to it | * It deals with everything in an attack, from picking a target to picking a path to it | ||||
* To making sure units are built, and pushing elements to the queue manager otherwise | * To making sure units are built, and pushing elements to the queue manager otherwise | ||||
* It also handles the actual attack, though much work is needed on that. | * It also handles the actual attack, though much work is needed on that. | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 124 Lines • ▼ Show 20 Lines | else if (type == "Raid") | ||||
this.unitStat.Cavalry = { "priority": 1, "minSize": 3, "targetSize": 4, "batchSize": 2, "classes": ["Cavalry", "CitizenSoldier"], | this.unitStat.Cavalry = { "priority": 1, "minSize": 3, "targetSize": 4, "batchSize": 2, "classes": ["Cavalry", "CitizenSoldier"], | ||||
"interests": [ ["strength", 1] ] }; | "interests": [ ["strength", 1] ] }; | ||||
this.neededShips = 1; | this.neededShips = 1; | ||||
} | } | ||||
else if (type == "HugeAttack") | else if (type == "HugeAttack") | ||||
{ | { | ||||
priority = 90; | priority = 90; | ||||
// basically we want a mix of citizen soldiers so our barracks have a purpose, and champion units. | // basically we want a mix of citizen soldiers so our barracks have a purpose, and champion units. | ||||
this.unitStat.RangedInfantry = { "priority": 0.7, "minSize": 5, "targetSize": 20, "batchSize": 5, "classes": ["Infantry", "Ranged", "CitizenSoldier"], | this.unitStat.RangedInfantry = { "priority": 0.7, "minSize": 5, "targetSize": 20, "batchSize": 5, "classes": ["Infantry", "Ranged", "CitizenSoldier"], | ||||
"interests": [["strength", 3]] }; | "interests": [["strength", 3]] }; | ||||
this.unitStat.MeleeInfantry = { "priority": 0.7, "minSize": 5, "targetSize": 20, "batchSize": 5, "classes": ["Infantry", "Melee", "CitizenSoldier"], | this.unitStat.MeleeInfantry = { "priority": 0.7, "minSize": 5, "targetSize": 20, "batchSize": 5, "classes": ["Infantry", "Melee", "CitizenSoldier"], | ||||
"interests": [["strength", 3]] }; | "interests": [["strength", 3]] }; | ||||
this.unitStat.ChampRangedInfantry = { "priority": 1, "minSize": 3, "targetSize": 18, "batchSize": 3, "classes": ["Infantry", "Ranged", "Champion"], | this.unitStat.ChampRangedInfantry = { "priority": 1, "minSize": 3, "targetSize": 18, "batchSize": 3, "classes": ["Infantry", "Ranged", "Champion"], | ||||
"interests": [["strength", 3]] }; | "interests": [["strength", 3]] }; | ||||
this.unitStat.ChampMeleeInfantry = { "priority": 1, "minSize": 3, "targetSize": 18, "batchSize": 3, "classes": ["Infantry", "Melee", "Champion"], | this.unitStat.ChampMeleeInfantry = { "priority": 1, "minSize": 3, "targetSize": 18, "batchSize": 3, "classes": ["Infantry", "Melee", "Champion"], | ||||
"interests": [["strength", 3]] }; | "interests": [["strength", 3]] }; | ||||
this.unitStat.RangedCavalry = { "priority": 0.7, "minSize": 4, "targetSize": 20, "batchSize": 4, "classes": ["Cavalry", "Ranged", "CitizenSoldier"], | this.unitStat.RangedCavalry = { "priority": 0.7, "minSize": 4, "targetSize": 20, "batchSize": 4, "classes": ["Cavalry", "Ranged", "CitizenSoldier"], | ||||
"interests": [["strength", 2]] }; | "interests": [["strength", 2]] }; | ||||
this.unitStat.MeleeCavalry = { "priority": 0.7, "minSize": 4, "targetSize": 20, "batchSize": 4, "classes": ["Cavalry", "Melee", "CitizenSoldier"], | this.unitStat.MeleeCavalry = { "priority": 0.7, "minSize": 4, "targetSize": 20, "batchSize": 4, "classes": ["Cavalry", "Melee", "CitizenSoldier"], | ||||
"interests": [["strength", 2]] }; | "interests": [["strength", 2]] }; | ||||
this.unitStat.ChampRangedCavalry = { "priority": 1, "minSize": 3, "targetSize": 15, "batchSize": 3, "classes": ["Cavalry", "Ranged", "Champion"], | this.unitStat.ChampRangedCavalry = { "priority": 1, "minSize": 3, "targetSize": 15, "batchSize": 3, "classes": ["Cavalry", "Ranged", "Champion"], | ||||
"interests": [["strength", 3]] }; | "interests": [["strength", 3]] }; | ||||
this.unitStat.ChampMeleeCavalry = { "priority": 1, "minSize": 3, "targetSize": 15, "batchSize": 3, "classes": ["Cavalry", "Melee", "Champion"], | this.unitStat.ChampMeleeCavalry = { "priority": 1, "minSize": 3, "targetSize": 15, "batchSize": 3, "classes": ["Cavalry", "Melee", "Champion"], | ||||
"interests": [["strength", 2]] }; | "interests": [["strength", 2]] }; | ||||
this.unitStat.Hero = { "priority": 1, "minSize": 0, "targetSize": 1, "batchSize": 1, "classes": ["Hero"], | this.unitStat.Hero = { "priority": 1, "minSize": 0, "targetSize": 1, "batchSize": 1, "classes": ["Hero"], | ||||
"interests": [["strength", 2]] }; | "interests": [["strength", 2]] }; | ||||
this.neededShips = 5; | this.neededShips = 5; | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
priority = 70; | priority = 70; | ||||
this.unitStat.RangedInfantry = { "priority": 1, "minSize": 6, "targetSize": 16, "batchSize": 3, "classes": ["Infantry", "Ranged"], | this.unitStat.RangedInfantry = { "priority": 1, "minSize": 6, "targetSize": 16, "batchSize": 3, "classes": ["Infantry", "Ranged"], | ||||
"interests": [["canGather", 1], ["strength", 1.6], ["costsResource", 0.3, "stone"], ["costsResource", 0.3, "metal"]] }; | "interests": [["canGather", 1], ["strength", 1.6], ["costsResource", 0.3, "stone"], ["costsResource", 0.3, "metal"]] }; | ||||
this.unitStat.MeleeInfantry = { "priority": 1, "minSize": 6, "targetSize": 16, "batchSize": 3, "classes": ["Infantry", "Melee"], | this.unitStat.MeleeInfantry = { "priority": 1, "minSize": 6, "targetSize": 16, "batchSize": 3, "classes": ["Infantry", "Melee"], | ||||
"interests": [["canGather", 1], ["strength", 1.6], ["costsResource", 0.3, "stone"], ["costsResource", 0.3, "metal"]] }; | "interests": [["canGather", 1], ["strength", 1.6], ["costsResource", 0.3, "stone"], ["costsResource", 0.3, "metal"]] }; | ||||
this.unitStat.Cavalry = { "priority": 1, "minSize": 2, "targetSize": 6, "batchSize": 2, "classes": ["Cavalry", "CitizenSoldier"], | this.unitStat.Cavalry = { "priority": 1, "minSize": 2, "targetSize": 6, "batchSize": 2, "classes": ["Cavalry", "CitizenSoldier"], | ||||
"interests": [["strength", 1]] }; | "interests": [["strength", 1]] }; | ||||
this.neededShips = 3; | this.neededShips = 3; | ||||
} | } | ||||
// Put some randomness on the attack size | // Put some randomness on the attack size | ||||
let variation = randFloat(0.8, 1.2); | let variation = randFloat(0.8, 1.2); | ||||
▲ Show 20 Lines • Show All 960 Lines • ▼ Show 20 Lines | else if (struct.get("Obstruction/Unit")) | ||||
if (x*x + y*y < r*r) | if (x*x + y*y < r*r) | ||||
{ | { | ||||
blocker = struct; | blocker = struct; | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
if (blocker && blocker.hasClass("StoneWall")) | if (blocker && blocker.hasClass("StoneWall")) | ||||
Polakrity: can be merged | |||||
Done Inline ActionsI prefer not to do refactoring in the same commit as lint clean up, which is going to be hundreds of files that should be trivial to review and that ESLint can statically confirm for you does not change the execution of the code in any way (thus zero risk, except for bugs in SpiderMonkey parsing code in non-standard way which is not impossible but unlikely). I'm definitely interested in looking at Petra code more after this is done though, and a bunch of clean ups like this. I enjoy doing that :) But that also takes more time to analyse to make sure it really is redundant and I don't know the code well enough yet for that. Krinkle: I prefer not to do refactoring in the same commit as lint clean up, which is going to be… | |||||
Done Inline ActionsAlso I don't think it can be merged. Stan: Also I don't think it can be merged. | |||||
{ | { | ||||
/* if (this.hasSiegeUnits()) | |||||
{ */ | |||||
this.isBlocked = true; | this.isBlocked = true; | ||||
return blocker; | return blocker; | ||||
/* } | |||||
return undefined; */ | |||||
} | } | ||||
else if (blocker) | else if (blocker) | ||||
{ | { | ||||
this.isBlocked = true; | this.isBlocked = true; | ||||
return blocker; | return blocker; | ||||
} | } | ||||
return target; | return target; | ||||
▲ Show 20 Lines • Show All 376 Lines • ▼ Show 20 Lines | for (let check = 0; check < lgth; check++) | ||||
range = ent.attackRange("Melee").max; | range = ent.attackRange("Melee").max; | ||||
else | else | ||||
range = 10; | range = 10; | ||||
} | } | ||||
else if (attackTypes && attackTypes.indexOf("Ranged") !== -1) | else if (attackTypes && attackTypes.indexOf("Ranged") !== -1) | ||||
range = 30 + ent.attackRange("Ranged").max; | range = 30 + ent.attackRange("Ranged").max; | ||||
else if (ent.hasClass("Cavalry")) | else if (ent.hasClass("Cavalry")) | ||||
range += 30; | range += 30; | ||||
range = range * range; | range *= range; | ||||
let entAccess = m.getLandAccess(gameState, ent); | let entAccess = m.getLandAccess(gameState, ent); | ||||
// Checking for gates if we're a siege unit. | // Checking for gates if we're a siege unit. | ||||
if (siegeUnit) | if (siegeUnit) | ||||
{ | { | ||||
let mStruct = enemyStructures.filter(enemy => { | let mStruct = enemyStructures.filter(enemy => { | ||||
if (!enemy.position() || enemy.hasClass("StoneWall") && !ent.canAttackClass("StoneWall")) | if (!enemy.position() || enemy.hasClass("StoneWall") && !ent.canAttackClass("StoneWall")) | ||||
return false; | return false; | ||||
if (API3.SquareVectorDistance(enemy.position(), ent.position()) > range) | if (API3.SquareVectorDistance(enemy.position(), ent.position()) > range) | ||||
▲ Show 20 Lines • Show All 609 Lines • ▼ Show 20 Lines | for (let key in data.properties) | ||||
this[key] = data.properties[key]; | this[key] = data.properties[key]; | ||||
if (this.target) | if (this.target) | ||||
this.target = gameState.getEntityById(this.target); | this.target = gameState.getEntityById(this.target); | ||||
this.failed = undefined; | this.failed = undefined; | ||||
}; | }; | ||||
return m; | }(PETRA)); | ||||
}(PETRA); |
Wildfire Games · Phabricator
can be merged