diff --git a/src/rotp/model/ai/base/AIGeneral.java b/src/rotp/model/ai/base/AIGeneral.java index 8c6997952..a6196d6aa 100644 --- a/src/rotp/model/ai/base/AIGeneral.java +++ b/src/rotp/model/ai/base/AIGeneral.java @@ -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)); diff --git a/src/rotp/model/colony/Colony.java b/src/rotp/model/colony/Colony.java index 82c288ee1..dccde7008 100644 --- a/src/rotp/model/colony/Colony.java +++ b/src/rotp/model/colony/Colony.java @@ -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()); @@ -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(); } @@ -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); @@ -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(); @@ -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(); } @@ -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); } @@ -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()) @@ -958,7 +973,7 @@ public void resistTransportWithRebels(Transport tr) { } rebels = (int) population(); - setPopulation(rebels + captives); + population(rebels + captives); captives = 0; // are there rebels left? @@ -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 @@ -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()); @@ -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()); @@ -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) @@ -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) @@ -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); @@ -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; @@ -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;