Skip to content

Commit

Permalink
Update NewShipTemplate.java
Browse files Browse the repository at this point in the history
The willingness of the AI to use repulsor-beam now scales with how many opponent ships have long range. It will be higher if there's only a few but drop down to 0 if all opponent ships use them.
  • Loading branch information
Xilmi committed Jun 11, 2021
1 parent 08c7d07 commit 2462633
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/rotp/model/ai/xilmi/NewShipTemplate.java
Expand Up @@ -240,6 +240,7 @@ private ShipDesign newDesign(ShipDesigner ai, DesignType role, int size) {
float topSpeed = 0;
float avgECM = 0;
float avgSHD = 0;
float longRangePct = 0;
float totalCost = 0;

for(EmpireView ev : ai.empire().contacts())
Expand All @@ -250,23 +251,39 @@ private ShipDesign newDesign(ShipDesigner ai, DesignType role, int size) {
{
continue;
}
boolean isLongRange = false;
if(enemyDesign.repulsorRange() > 0)
{
needRange = true;
}
for (int j=0;j<maxSpecials();j++)
{
if(enemyDesign.special(j).createsBlackHole())
boostInertial = true;
if(enemyDesign.special(j).beamRangeBonus() > 0)
isLongRange = true;
}
for (int i=0; i<maxWeapons(); i++)
{
ShipWeapon weapon = enemyDesign.weapon(i);
if(weapon == null)
continue;
if(weapon.range() > 1)
isLongRange = true;
}
if(enemyDesign.combatSpeed() > topSpeed)
topSpeed = enemyDesign.combatSpeed();
float count = ev.empire().shipDesignCount(enemyDesign.id());
avgECM += enemyDesign.ecm().level() * enemyDesign.cost() * count;
avgSHD += enemyDesign.shieldLevel() * enemyDesign.cost() * count;
if(isLongRange)
longRangePct += enemyDesign.cost() * count;
totalCost += enemyDesign.cost() * count;
}
}
if(totalCost > 0)
{
longRangePct /= totalCost;
avgECM /= totalCost;
avgSHD /= totalCost;
}
Expand All @@ -275,11 +292,11 @@ private ShipDesign newDesign(ShipDesigner ai, DesignType role, int size) {

switch (role) {
case BOMBER:
specials = buildSpecialsList(d, ai, enemyMissilePercentage, true, false, boostInertial, size, specialsSpace);
specials = buildSpecialsList(d, ai, enemyMissilePercentage, true, false, boostInertial, size, specialsSpace, longRangePct);
break;
case FIGHTER:
default:
specials = buildSpecialsList(d, ai, enemyMissilePercentage, false, needRange, boostInertial, size, specialsSpace);
specials = buildSpecialsList(d, ai, enemyMissilePercentage, false, needRange, boostInertial, size, specialsSpace, longRangePct);
break;
}

Expand Down Expand Up @@ -415,7 +432,7 @@ private float setFittingECM(ShipDesigner ai, ShipDesign d, float spaceAllowed) {

// ********** SPECIALS SELECTION AND FITTING FUNCTIONS ********** //

private SortedMap<Float, ShipSpecial> buildSpecialsList(ShipDesign d, ShipDesigner ai, float antiMissle, boolean bomber, boolean needRange, boolean boostInertial, int size, float specialsSpace) {
private SortedMap<Float, ShipSpecial> buildSpecialsList(ShipDesign d, ShipDesigner ai, float antiMissle, boolean bomber, boolean needRange, boolean boostInertial, int size, float specialsSpace, float longRangePct) {
SortedMap<Float, ShipSpecial> specials = new TreeMap<>(Collections.reverseOrder());
List<ShipSpecial> allSpecials = ai.lab().specials();

Expand Down Expand Up @@ -512,7 +529,7 @@ else if(tech.isType(Tech.MISSILE_SHIELD))
}
else if(tech.isType(Tech.REPULSOR))
{
currentScore = 50;
currentScore = 250 * (1 - longRangePct);
if(bomber)
currentScore /= 5;
if(needRange)
Expand Down

0 comments on commit 2462633

Please sign in to comment.