70 CampaignFleetAPI playerFleet =
context.getPlayerFleet();
71 CampaignFleetAPI otherFleet =
context.getOtherFleet();
72 FleetGoal playerGoal =
context.getPlayerGoal();
73 FleetGoal enemyGoal =
context.getOtherGoal();
78 Random random = Misc.getRandom(Misc.getSalvageSeed(otherFleet) *
79 (
long)otherFleet.getFleetData().getNumMembers(), 23);
84 escape = playerGoal == FleetGoal.ESCAPE || enemyGoal == FleetGoal.ESCAPE;
89 for (FleetMemberAPI member : playerFleet.getFleetData().getMembersListCopy()) {
90 if (member.canBeDeployedForCombat() || playerGoal == FleetGoal.ESCAPE) {
91 fpOne += member.getUnmodifiedDeploymentPointsCost();
94 for (FleetMemberAPI member : otherFleet.getFleetData().getMembersListCopy()) {
95 if (member.canBeDeployedForCombat() || playerGoal == FleetGoal.ESCAPE) {
96 fpTwo += member.getUnmodifiedDeploymentPointsCost();
100 int smaller = Math.min(fpOne, fpTwo);
102 boolean withObjectives = smaller > maxFP;
103 if (!
context.objectivesAllowed) {
104 withObjectives =
false;
107 int numObjectives = 0;
108 if (withObjectives) {
115 if (fpOne + fpTwo > maxFP + 70) {
119 numObjectives = 3 + random.nextInt(2);
125 if (numObjectives > 4) {
132 loader.initFleet(FleetSide.PLAYER,
"ISS", playerGoal,
false,
133 context.getPlayerCommandPoints() - baseCommandPoints,
134 (int) playerFleet.getCommanderStats().getCommandPoints().getModifiedValue() - baseCommandPoints);
135 loader.initFleet(FleetSide.ENEMY,
"", enemyGoal,
true,
136 (
int) otherFleet.getCommanderStats().getCommandPoints().getModifiedValue() - baseCommandPoints);
138 List<FleetMemberAPI> playerShips = playerFleet.getFleetData().getCombatReadyMembersListCopy();
139 if (playerGoal == FleetGoal.ESCAPE) {
140 playerShips = playerFleet.getFleetData().getMembersListCopy();
142 for (FleetMemberAPI member : playerShips) {
143 loader.addFleetMember(FleetSide.PLAYER, member);
147 List<FleetMemberAPI> enemyShips = otherFleet.getFleetData().getCombatReadyMembersListCopy();
148 if (enemyGoal == FleetGoal.ESCAPE) {
149 enemyShips = otherFleet.getFleetData().getMembersListCopy();
151 for (FleetMemberAPI member : enemyShips) {
152 loader.addFleetMember(FleetSide.ENEMY, member);
162 }
else if (withObjectives) {
164 if (numObjectives == 2) {
173 context.setInitialDeploymentBurnDuration(1.5f);
174 context.setNormalDeploymentBurnDuration(6f);
175 context.setEscapeDeploymentBurnDuration(1.5f);
193 if (withObjectives) {
197 context.setStandoffRange(6000f);
206 String name =
"Corona";
208 else if (
corona !=
null) name =
corona.getTerrainName();
210 final String name2 = name;
215 final Object key1 =
new Object();
216 final Object key2 =
new Object();
218 engine.addPlugin(
new BaseEveryFrameCombatPlugin() {
220 public void advance(
float amount, List<InputEventAPI> events) {
221 engine.maintainStatusForPlayerShip(key1, icon, name2,
"reduced peak time",
true);
222 engine.maintainStatusForPlayerShip(key2, icon, name2,
"faster CR degradation",
true);
228 Color color = Misc.scaleColor(Color.white, 1f -
abyssalDepth);
229 engine.setBackgroundColor(color);
232 engine.setBackgroundGlowColor(color);
233 engine.setBackgroundGlowColorNonAdditive(
true);
235 if (
abyssalDepth > HyperspaceAbyssPluginImpl.DEPTH_THRESHOLD_FOR_NO_DUST_PARTICLES_IN_COMBAT) {
236 engine.setRenderStarfield(
false);
239 final Object key1 =
new Object();
240 final Object key2 =
new Object();
242 final String name =
"Abyssal hyperspace";
243 engine.addPlugin(
new BaseEveryFrameCombatPlugin() {
245 public void advance(
float amount, List<InputEventAPI> events) {
248 engine.maintainStatusForPlayerShip(key1, icon, name, percentSpeed +
" top speed",
true);
249 engine.maintainStatusForPlayerShip(key2, icon, name, percentMissile +
" missle speed / range",
true);
251 String modId =
"abyssal";
256 for (ShipAPI curr : engine.getShips()) {
257 if (curr.isHulk())
continue;
259 curr.getEngineController().fadeToOtherColor(
this, Color.black,
null, 1f,
abyssalDepth * 0.4f);
260 curr.getEngineController().extendFlame(
this, modL, modW, modG);
262 curr.getMutableStats().getMaxSpeed().modifyMult(modId,
264 curr.getMutableStats().getMissileWeaponRangeBonus().modifyMult(modId,
266 curr.getMutableStats().getMissileMaxSpeedBonus().modifyMult(modId,
270 for (MissileAPI missile : engine.getMissiles()) {
271 missile.getEngineController().fadeToOtherColor(
this, Color.black,
null, 1f,
abyssalDepth * 0.4f);
272 missile.getEngineController().extendFlame(
this, modL, modW, 0f);
289 CampaignFleetAPI playerFleet =
context.getPlayerFleet();
290 String nebulaTex =
null;
291 String nebulaMapTex =
null;
292 boolean inNebula =
false;
294 boolean protectedFromCorona =
false;
295 for (CustomCampaignEntityAPI curr : playerFleet.getContainingLocation().getCustomEntitiesWithTag(Tags.PROTECTS_FROM_CORONA_IN_BATTLE)) {
296 if (Misc.getDistance(curr.getLocation(), playerFleet.getLocation()) <= curr.getRadius() +
Global.
getSector().getPlayerFleet().getRadius() + 10f) {
297 protectedFromCorona =
true;
306 Color coronaColor =
null;
308 for (CampaignTerrainAPI terrain : playerFleet.getContainingLocation().getTerrainCopy()) {
311 if (terrain.getPlugin().containsEntity(playerFleet)) {
319 if (nebulaTex ==
null) {
327 }
else if (terrain.getPlugin() instanceof StarCoronaTerrainPlugin &&
pulsar ==
null && !protectedFromCorona) {
328 StarCoronaTerrainPlugin plugin = (StarCoronaTerrainPlugin) terrain.getPlugin();
329 if (plugin.containsEntity(playerFleet)) {
330 float angle = Misc.getAngleInDegrees(terrain.getLocation(), playerFleet.getLocation());
331 Color color = plugin.getAuroraColorForAngle(angle);
332 float intensity = plugin.getIntensityAtPoint(playerFleet.getLocation());
333 intensity = 0.4f + 0.6f * intensity;
334 int alpha = (int)(80f * intensity);
335 color = Misc.setAlpha(color, alpha);
336 if (coronaColor ==
null || coronaColor.getAlpha() < alpha) {
342 }
else if (terrain.getPlugin() instanceof PulsarBeamTerrainPlugin && !protectedFromCorona) {
343 PulsarBeamTerrainPlugin plugin = (PulsarBeamTerrainPlugin) terrain.getPlugin();
344 if (plugin.containsEntity(playerFleet)) {
345 float angle = Misc.getAngleInDegreesStrict(terrain.getLocation(), playerFleet.getLocation());
346 Color color = plugin.getPulsarColorForAngle(angle);
347 float intensity = plugin.getIntensityAtPoint(playerFleet.getLocation());
348 intensity = 0.4f + 0.6f * intensity;
349 int alpha = (int)(80f * intensity);
350 color = Misc.setAlpha(color, alpha);
351 if (coronaColor ==
null || coronaColor.getAlpha() < alpha) {
358 }
else if (terrain.getType().equals(Terrain.RING)) {
359 if (terrain.getPlugin().containsEntity(playerFleet)) {
364 if (nebulaTex !=
null) {
365 loader.setNebulaTex(nebulaTex);
366 loader.setNebulaMapTex(nebulaMapTex);
369 if (coronaColor !=
null) {
370 loader.setBackgroundGlowColor(coronaColor);
377 if (!inNebula && playerFleet.isInHyperspace()) {
381 for (
int i = 0; i < numNebula; i++) {
382 float x = random.nextFloat() *
width -
width/2;
384 float radius = 100f + random.nextFloat() * 400f;
386 radius += 100f + 500f * random.nextFloat();
388 loader.addNebula(x, y, radius);
393 int numAsteroids = Math.min(400, (
int)((numAsteroidsWithinRange + 1f) * 20f));
395 loader.addAsteroidField(0, 0, random.nextFloat() * 360f,
width,
396 20f, 70f, numAsteroids);
399 int numRingAsteroids = (int) (numRings * 300 + (numRings * 600f) * random.nextFloat());
401 if (numRingAsteroids > 1500) {
402 numRingAsteroids = 1500;
404 loader.addRingAsteroids(0, 0, random.nextFloat() * 360f,
width,
405 100f, 200f, numRingAsteroids);
409 loader.setBackgroundSpriteName(playerFleet.getContainingLocation().getBackgroundTextureFilename());
413 if (playerFleet.getContainingLocation() ==
Global.
getSector().getHyperspace()) {
414 loader.setHyperspaceMode(
true);
416 loader.setHyperspaceMode(
false);
424 float bgWidth = 2048f;
425 float bgHeight = 2048f;
428 if (planet ==
null)
return;
430 float dist = Vector2f.sub(
context.getPlayerFleet().getLocation(), planet.getLocation(),
new Vector2f()).length() - planet.getRadius();
431 if (dist < 0) dist = 0;
432 float baseRadius = planet.getRadius();
433 float scaleFactor = 1.5f;
434 float maxRadius = 500f;
435 float minRadius = 100f;
443 if (maxDist < 1) maxDist = 1;
446 boolean playerHasStation =
false;
447 boolean enemyHasStation =
false;
449 for (FleetMemberAPI curr :
context.getPlayerFleet().getFleetData().getMembersListCopy()) {
450 if (curr.isStation()) {
451 playerHasStation =
true;
456 for (FleetMemberAPI curr :
context.getOtherFleet().getFleetData().getMembersListCopy()) {
457 if (curr.isStation()) {
458 enemyHasStation =
true;
463 float planetYOffset = 0;
465 if (playerHasStation) {
466 planetYOffset = -bgHeight / 2f * 0.5f;
468 if (enemyHasStation) {
469 planetYOffset = bgHeight / 2f * 0.5f;
473 float f = (maxDist - dist) / maxDist * 0.65f + 0.35f;
474 float radius = baseRadius * f * scaleFactor;
475 if (radius > maxRadius) radius = maxRadius;
476 if (radius < minRadius) radius = minRadius;
477 loader.setPlanetBgSize(bgWidth * f, bgHeight * f);
478 loader.addPlanet(0f, planetYOffset, radius, planet, 0f,
true);
482 float bgWidth = 2048f;
483 float bgHeight = 2048f;
484 loader.setPlanetBgSize(bgWidth, bgHeight);
488 if (!planets.isEmpty()) {
490 for (NearbyPlanetData data : planets) {
491 float dist = Vector2f.sub(
context.getPlayerFleet().getLocation(), data.planet.getLocation(),
new Vector2f()).length();
492 float baseRadius = data.planet.getRadius();
493 float scaleFactor = 1.5f;
494 float maxRadius = 500f;
496 if (data.planet.isStar()) {
503 float f = (maxDist - dist) / maxDist * 0.65f + 0.35f;
504 float radius = baseRadius * f * scaleFactor;
505 if (radius > maxRadius) radius = maxRadius;
509 radius, data.planet.getTypeId(), 0f,
true);
535 objs =
new ArrayList<String>(Arrays.asList(
new String [] {
545 objs =
new ArrayList<String>(Arrays.asList(
new String [] {
554 }
else if (num == 3) {
555 float r = random.nextFloat();
560 }
else if (r < 0.67f) {
565 if (random.nextFloat() < 0.5f) {
575 }
else if (num == 4) {
576 float r = random.nextFloat();
578 String [] maybeRelays =
pickCommRelays(2, 2,
false,
true,
true,
false, random);
583 }
else if (r < 0.67f) {
584 String [] maybeRelays =
pickCommRelays(1, 2,
true,
false,
true,
false, random);
590 if (random.nextFloat() < 0.5f) {
591 String [] maybeRelays =
pickCommRelays(1, 2,
true,
false,
true,
false, random);
597 String [] maybeRelays =
pickCommRelays(1, 2,
false,
true,
false,
true, random);
626 objs =
new ArrayList<String>(Arrays.asList(
new String [] {
635 float r = random.nextFloat();
639 }
else if (r < 0.67f) {
646 }
else if (num == 3) {
647 float r = random.nextFloat();
652 }
else if (r < 0.67f) {
661 }
else if (num == 4) {
662 float r = random.nextFloat();
668 }
else if (r < 0.67f) {
685 protected void addObjectiveAt(
float xMult,
float yMult,
float xOff,
float yOff, String type, Random random) {
689 if (
objs !=
null &&
objs.size() > 0) {
690 int index = (int) (random.nextDouble() *
objs.size());
691 type =
objs.remove(index);
698 float x = (
width -
xPad * 2f) * xMult + minX;
699 float y = (
height -
yPad * 2f) * yMult + minY;
701 x = ((int) x / 1000) * 1000f;
702 y = ((int) y / 1000) * 1000f;
704 float offsetX = Math.round((random.nextFloat() - 0.5f) * xOff * 1f) * 1000f;
705 float offsetY = Math.round((random.nextFloat() - 0.5f) * yOff * 1f) * 1000f;
710 float xDir = (float) Math.signum(offsetX);
711 float yDir = (float) Math.signum(offsetY);
715 offsetX = Math.abs(offsetX) * -
prevXDir;
720 offsetY = Math.abs(offsetY) * -
prevYDir;
729 loader.addObjective(x, y, type);
731 if (random.nextFloat() > 0.6f &&
loader.hasNebula()) {
732 float nebulaSize = random.nextFloat() * 1500f + 500f;
733 loader.addNebula(x, y, nebulaSize);
774 LocationAPI loc = playerFleet.getContainingLocation();
775 List<NearbyPlanetData> result =
new ArrayList<NearbyPlanetData>();
776 if (loc instanceof StarSystemAPI) {
777 StarSystemAPI system = (StarSystemAPI) loc;
778 List<PlanetAPI> planets = system.getPlanets();
779 for (PlanetAPI planet : planets) {
780 float diffX = planet.getLocation().x - playerFleet.getLocation().x;
781 float diffY = planet.getLocation().y - playerFleet.getLocation().y;
784 result.add(
new NearbyPlanetData(
new Vector2f(diffX, diffY), planet));
792 LocationAPI loc = playerFleet.getContainingLocation();
793 PlanetAPI closest =
null;
794 float minDist = Float.MAX_VALUE;
795 if (loc instanceof StarSystemAPI) {
796 StarSystemAPI system = (StarSystemAPI) loc;
797 List<PlanetAPI> planets = system.getPlanets();
798 for (PlanetAPI planet : planets) {
799 if (planet.isStar())
continue;
800 if (Planets.PLANET_LAVA.equals(planet.getTypeId()))
continue;
801 if (Planets.PLANET_LAVA_MINOR.equals(planet.getTypeId()))
continue;
802 if (planet.getSpec().isDoNotShowInCombat())
continue;
804 float dist = Vector2f.sub(
context.getPlayerFleet().getLocation(), planet.getLocation(),
new Vector2f()).length();