Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/rotp/model/ai/base/AIGeneral.java
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,15 @@ public void orderInvasionFleet(EmpireView v, StarSystem sys, float enemyFleetSiz
EmpireView ev = empire.viewForEmpire(empire.sv.empId(sysId));
float targetTech = ev.spies().tech().avgTechLevel(); // modnar: target tech level

if (empire.sv.hasFleetForEmpire(sys.id, empire))
if (empire.sv.orbitingFleet(sys.id) != null)
launchGroundTroops(v, sys, mult);
else if (empire.combatTransportPct() > 0)
launchGroundTroops(v, sys, mult/empire.combatTransportPct());
else if (empire.combatTransportPct() > 0) {
float transPct = empire.combatTransportPct();
if (ev.spies().tech().subspaceInterdiction()) {
transPct /= 2;
}
launchGroundTroops(v, sys, mult / transPct);
}

float baseBCPresent = empire.sv.bases(sys.id)*empire.tech().newMissileBaseCost();
float bcMultiplier = 1 + (empire.sv.hostilityLevel(sys.id));
Expand Down
75 changes: 47 additions & 28 deletions src/rotp/model/colony/Colony.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ private void init() {
for (int i = 0; i < spending.length; i++)
spending[i].init(this);

setPopulation(2);
population(2);
shipyard().goToNextDesign();
defense().updateMissileBase();
defense().maxBases(empire().defaultMaxBases());
Expand Down Expand Up @@ -257,18 +257,31 @@ public String printString() {
+ (float) Math.round(defense().shield() * 100) / 100;
}

public int displayPopulation() { return population < 1 ? (int) Math.ceil(population) : (int) population; }
public float population() { return population; }
public void setPopulation(float pop) { population = pop; }
public void adjustPopulation(float pop) { population += pop; }
public int rebels() { return rebels; }
public void rebels(int i) { rebels = i; }
public int deltaPopulation() { return (int) population - (int) previousPopulation - (int) inTransport(); }
public boolean destroyed() { return population <= 0; }
public boolean inRebellion() { return rebellion && (rebels > 0); }
public float rebellionPct() { return rebels / population(); }
public boolean hasOrders() { return !orders.isEmpty(); }

public int displayPopulation() { return population < 1 ? (int) Math.ceil(population) : (int) population; }
public int rebels() { return rebels; }
public void rebels(int i) { rebels = i; }
public int deltaPopulation() { return (int) population - (int) previousPopulation - (int) inTransport(); }
public boolean destroyed() { return population <= 0; }
public boolean inRebellion() { return rebellion && (rebels > 0); }
public float rebellionPct() { return rebels / population(); }
public boolean hasOrders() { return !orders.isEmpty(); }

public float population() { return population; }
private void population(float pop) { population = pop; }
public int setPopulation(float pop) {
float currentMaxPop = planet().currentSize();
float lost = pop - currentMaxPop;
if (lost > 0) {
population(currentMaxPop);
return (int) lost;
}
population(pop);
return 0;
}
public float adjustPopulation(float pop) {
return setPopulation(population() + pop);
}

public boolean isDeveloped() {
return defense().isCompleted() && industry().isCompleted() && ecology().isCompleted();
}
Expand Down Expand Up @@ -367,7 +380,7 @@ public void removeColonyOrder(Colony.Orders order) {
}

public void setHomeworldValues() {
setPopulation(50);
population(50);
previousPopulation = population();
industry().factories(30);
industry().previousFactories(30);
Expand Down Expand Up @@ -904,7 +917,7 @@ public void launchTransports() {
abandon();
return;
}
setPopulation(population() - transport().size());
adjustPopulation(-transport().size());
transport = new Transport(starSystem());
if (empire.isPlayerControlled())
starSystem().transportSprite().launch();
Expand All @@ -927,7 +940,7 @@ public void scheduleTransportsToSystem(StarSystem dest, int pop) {
if ((dest == starSystem()) || (xPop == 0))
clearTransport();
else {
transport().size(pop);
transport().size(xPop);
transport().setDest(dest);
transport().setDefaultTravelSpeed();
}
Expand All @@ -937,7 +950,9 @@ public void scheduleTransportsToSystem(StarSystem dest, int pop) {
empire.setVisibleShips();
}
public void acceptTransport(Transport t) {
setPopulation(min(planet.currentSize(), (population() + t.size())));
if ((adjustPopulation(t.size()) > 0) && t.empire().isPlayerControlled()) {
// TODO: Some transports lost because max population was reached. Ought to be an alert?
}
log("Accepting ", str(t.size()), " transports at: ", starSystem().name(), ". New pop:", fmt(population(), 2));
t.size(0);
}
Expand All @@ -948,7 +963,7 @@ public void resistTransportWithRebels(Transport tr) {
log(str(rebels), " ", empire().raceName(), " rebels at ", starSystem().name(), " resisting ",
str(tr.size()), " ", tr.empire().raceName(), " transports");
captives = population() - rebels;
setPopulation(rebels);
population(rebels);

if (population() > 0) {
if (empire.isPlayerControlled() || tr.empire().isPlayerControlled())
Expand All @@ -958,7 +973,7 @@ public void resistTransportWithRebels(Transport tr) {
}

rebels = (int) population();
setPopulation(rebels + captives);
population(rebels + captives);
captives = 0;

// are there rebels left?
Expand Down Expand Up @@ -1091,10 +1106,10 @@ public boolean singleCombatAgainstTransports(Transport tr) {
if (attRoll < defRoll)
tr.size(tr.size() - 1);
else
setPopulation(population() - 1);
adjustPopulation(-1);

if (population() <= 0)
setPopulation(0);
population(0);

// true: attacker defeated
// false: defender defeated
Expand Down Expand Up @@ -1138,7 +1153,9 @@ private void capturedByTransport(Transport tr) {
}
}

setPopulation(tr.size());
if ((setPopulation(tr.size()) > 0) && (tr.empire().isPlayerControlled())) {
// TODO: Excess transports lost -- ought to be an alert?
}
tr.size(0);
shipyard().capturedBy(tr.empire());
industry().capturedBy(tr.empire());
Expand Down Expand Up @@ -1167,7 +1184,9 @@ private void capturedByTransport(Transport tr) {
loser.goExtinct();
}
public void capturedOrion(Transport tr) {
setPopulation(tr.size());
if ((setPopulation(tr.size()) > 0) && (tr.empire().isPlayerControlled())) {
// TODO: Excess transports lost -- ought to be an alert?
}
tr.size(0);
industry().capturedBy(tr.empire());
defense().capturedBy(tr.empire());
Expand Down Expand Up @@ -1195,7 +1214,7 @@ public void takeTargetedCollateralDamage(float damage) {
float newPop = max(0, population() - (damage / TARGETED_DAMAGE_FOR_POPLOSS));
float newFact = max(0, industry().factories() - (damage / TARGETED_DAMAGE_FOR_FACTLOSS));

setPopulation(newPop);
population(newPop);
industry().factories(newFact);

if (population() <= 0)
Expand All @@ -1205,7 +1224,7 @@ public void takeUntargetedCollateralDamage(float damage) {
float newPop = max(0, population() - (damage / UNTARGETED_DAMAGE_FOR_POPLOSS));
float newFact = max(0, industry().factories() - (damage / UNTARGETED_DAMAGE_FOR_FACTLOSS));

setPopulation(newPop);
population(newPop);
industry().factories(newFact);

if (population() <= 0)
Expand All @@ -1214,7 +1233,7 @@ public void takeUntargetedCollateralDamage(float damage) {
public void takeBioweaponDamage(float damage) {
float popLost = max(0, damage - tech().antidoteLevel());

setPopulation(max(0, population() - popLost));
population(max(0, population() - popLost));

float newWaste = popLost * 10;
ecology().addWaste(newWaste);
Expand All @@ -1231,7 +1250,7 @@ public void abandon() {
sys.addEvent(new SystemAbandonedEvent(empire.id));
sys.abandoned(true);

setPopulation(0);
population(0);
rebels = 0;
captives = 0;
rebellion = false;
Expand Down Expand Up @@ -1260,7 +1279,7 @@ public void destroy() {
StarSystem sys = starSystem();
sys.addEvent(new SystemDestroyedEvent(empire.lastAttacker()));

setPopulation(0);
population(0);
rebels = 0;
captives = 0;
rebellion = false;
Expand Down