/** Schedule the mission tasks. */ void scheduleTasks() { if (!objective("Mission-2-Task-1").visible && !task1Once) { task1Once = true; addMission("Mission-2-Task-1", (8 + ModelUtils.randomInt(3))); } if (objective("Mission-3").isCompleted() && !task2Once) { task2Once = true; addMission("Mission-2-Task-2", (8 + ModelUtils.randomInt(3))); addMission("Mission-26-Wife-1", 2); } if (objective("Mission-4").isCompleted() && !task3Once) { task3Once = true; addMission("Mission-2-Task-3", (8 + ModelUtils.randomInt(3))); } }
/** * Issue the specific mission changes once task is completed. * * @param traderSurvived did the trader survive? * @param task the current task id */ void completeTaskN(boolean traderSurvived, int task) { if (!traderSurvived) { addTimeout("Mission-2-Task-" + task + "-Failed", 3000); clearMission("Mission-2-Task-" + task + "-Timeout"); } else { addTimeout("Mission-2-Task-" + task + "-Success", 3000); clearMission("Mission-2-Task-" + task + "-Timeout"); } Fleet tf = findTaggedFleet(MISSION_2_TRADER, player("Traders")); if (tf != null) { removeScripted(tf); for (InventoryItem ii : tf.inventory.iterable()) { ii.tag = null; } tf.task = FleetTask.IDLE; tf.moveTo(ModelUtils.random(planet("Achilles"), planet("Naxos"), planet("San Sterling"))); } Fleet pf = findTaggedFleet(MISSION_2_PIRATE, player("Pirates")); if (pf != null) { removeScripted(pf); world.removeFleet(pf); } cleanupScriptedFleets(); missionAttack = false; }
@Override public void load(XElement xmission) { super.load(xmission); task1Once = xmission.getBoolean("task-1-once", objective("Mission-2-Task-1").isCompleted()); task2Once = xmission.getBoolean("task-2-once", objective("Mission-2-Task-2").isCompleted()); task3Once = xmission.getBoolean("task-3-once", objective("Mission-2-Task-3").isCompleted()); traderMessage = xmission.getInt("trader-message", 1 + ModelUtils.randomInt(7)); }
@Override public void manage() { updateExplorationMap(); List<Planner> planners = new ArrayList<>(); planners.add(new ColonyPlanner(world, controls)); planners.add(new ResearchPlanner(world, controls, exploration)); planners.add(new ColonizationPlanner(world, controls)); planners.add( new ExplorationPlanner( world, controls, exploration, new Action1<Date>() { @Override public void invoke(Date value) { lastSatelliteDeploy = value; } })); int mix1 = planners.size(); planners.add(new EconomyPlanner(world, controls)); planners.add(new OffensePlanner(world, controls)); planners.add(new StaticDefensePlanner(world, controls)); int mix2 = planners.size(); planners.add( new AttackPlanner( world, controls, exploration, new Action1<Date>() { @Override public void invoke(Date value) { nextAttack = value; } })); ModelUtils.shuffle(planners.subList(mix1, mix2)); for (Planner p : planners) { List<Action0> acts = p.run(); if (!acts.isEmpty()) { applyActions.addAll(acts); if (p.getClass() == ColonyPlanner.class) { return; } } } }
/** * Select a target in range which the current ship can do most damage. * * @param world the world object. * @param ship the current ship */ static void selectNewTarget(SpacewarWorld world, final SpacewarStructure ship) { List<SpacewarStructure> es = world.enemiesInRange(ship); ModelUtils.shuffle(es); SpacewarStructure best = null; double bestEfficiency = 0d; for (SpacewarStructure s : es) { BattleEfficiencyModel bem = ship.getEfficiency(s); double eff = bem != null ? bem.damageMultiplier : 1d; if (eff > bestEfficiency) { best = s; bestEfficiency = eff; } } if (best != null) { world.attack(ship, best, Mode.BEAM); } }
@Override public ResponseMode diplomacy( Player other, NegotiateType about, ApproachType approach, Object argument) { DiplomaticRelation r = w.getRelation(p, other); if (r == null || !r.full) { return ResponseMode.NO; } // PlayerStrength senderStrength = getStrength(other); PlanetStatistics ownStats = p.getPlanetStatistics(null); // PlanetStatistics senderStas = computeVisibleStats(other); double rnd = ModelUtils.random(); double rel = r.value; Trait t = other.traits.trait(TraitKind.DIPLOMACY); if (t != null) { rel = rel * (1 + t.value / 100); rel = Math.min(100, Math.max(0, rel)); } switch (about) { case DIPLOMATIC_RELATIONS: if (rnd < rel / 100 && rel < p.warThreshold + 10) { return ResponseMode.MAYBE; } else if (rnd < rel / 100) { return ResponseMode.YES; } break; case ALLY: Player p3 = (Player) argument; if (p3.group == p.group) { return ResponseMode.NO; } DiplomaticRelation r2 = w.getRelation(p, p3); if (r2 != null) { if (rnd < 0.5 && rel >= p.warThreshold + 35 && r2.value < rel) { return ResponseMode.YES; } } break; case DARGSLAN: if (rnd < rel / 100 && rel >= 75 && !p.id.equals("Dargslan")) { return ResponseMode.YES; } break; case MONEY: if (rnd < rel / 100 || p.money() < 100000) { return ResponseMode.YES; } break; case SURRENDER: if (rnd < 0.1 && ownStats.planetCount < 2 && rel < p.warThreshold) { return ResponseMode.YES; } break; case TRADE: if (rnd < rel / 100) { return ResponseMode.YES; } break; default: } return ResponseMode.NO; }
/** Check the starting conditions for mission 2 tasks. */ void checkMission2Tasks() { Objective m2 = objective("Mission-2"); if (!m2.visible) { return; } if (m2.isActive()) { scheduleTasks(); for (int i = 1; i <= 3; i++) { String m2tio = String.format("Mission-2-Task-%d-Timeout", i); String m2ti = String.format("Mission-2-Task-%d", i); if (checkMission(m2tio)) { setObjectiveState(m2ti, ObjectiveState.FAILURE); cleanupShips(); } if (checkMission(m2ti)) { List<Fleet> fs = findVisibleFleets(player, false, player("Traders"), 8); fs = filterByRange( fs, world.params().groundRadarUnitSize() - 2, "Naxos", "San Sterling", "Achilles"); if (!fs.isEmpty()) { Fleet f = ModelUtils.random(fs); int fidx = ((AITrader) f.owner.ai).fleetIndex(f); traderMessage = 1 + fidx % 7; incomingMessage("Merchant-Under-Attack-" + traderMessage, m2ti); world.env.speed1(); f.stop(); f.task = FleetTask.SCRIPT; // create simple pirate fleet Fleet pf = createFleet(label("pirates.fleet_name"), player("Pirates"), f.x + 1, f.y + 1); if (i == 1) { addInventory(pf, "PirateFighter", 2); } else if (i == 2) { addInventory(pf, "PirateFighter", 3); } else { switch (world.difficulty) { case NORMAL: addInventory(pf, "PirateFighter", 1); break; case HARD: addInventory(pf, "PirateFighter", 3); break; default: } addInventory(pf, "PirateDestroyer", 1); } tagFleet(pf, MISSION_2_PIRATE); tagFleet(f, MISSION_2_TRADER); addScripted(f); addScripted(pf); // set failure timeout addMission(m2tio, 48); } else { addMission(m2ti, 0); } } } int done = 0; int success = 0; for (int i = 1; i <= 3; i++) { String m2ti = String.format("Mission-2-Task-%d", i); Objective o = objective(m2ti); if (o.state != ObjectiveState.ACTIVE) { done++; if (o.state == ObjectiveState.SUCCESS) { success++; } } } if (done == 3) { if (success == 0) { setObjectiveState("Mission-2", ObjectiveState.FAILURE); addTimeout("Mission-2-Failed", 13000); } else if (success == 3) { setObjectiveState("Mission-2", ObjectiveState.SUCCESS); addTimeout("Mission-2-Success", 13000); } else { setObjectiveState("Mission-2", ObjectiveState.SUCCESS); addTimeout("Mission-2-Success-But", 13000); incomingMessage("Douglas-Pirates"); } } for (int i = 1; i <= 3; i++) { if (checkTimeout("Mission-2-Task-" + i + "-Failed")) { setObjectiveState("Mission-2-Task-" + i, ObjectiveState.FAILURE); } else if (checkTimeout("Mission-2-Task-" + i + "-Success")) { setObjectiveState("Mission-2-Task-" + i, ObjectiveState.SUCCESS); // Reward int m = moneyReward[i]; player.addMoney(m); player.statistics.moneyIncome.value += m; world.statistics.moneyIncome.value += m; } } } if (checkTimeout("Mission-2-Failed")) { objective("Mission-2").visible = false; loseGameMessageAndMovie("Douglas-Fire-Lost-Merchants", "lose/fired_level_1"); } else if (checkTimeout("Mission-2-Success")) { objective("Mission-2").visible = false; } else if (checkTimeout("Mission-2-Success-But")) { objective("Mission-2").visible = false; } }