Scripts/ionics_main.js |
this.name = "ionics_v_rlf";
this.author = "Galileo, JS translation by Eric Walch";
this.description = "Script only used for the ionics mission.";
this.version = "1.3.1";
this.startUp = function() {
var end = missionVariables.ionics;
if (end === "RAMAZA_WAR_OVER" || end === "MISSION_COMPLETE_2B" || end === "MISSION_COMPLETE_3A") {
// mission is over, no need to evaluate any code anymore.
delete this.missionScreenOpportunity;
delete this.shipLaunchedFromStation;
delete this.shipExitedWitchspace;
}
};
this.missionScreenOpportunity = function () {
if (galaxyNumber != 1) return;
var ionics = missionVariables.ionics;
if (player.ship.dockedStation.isMainStation) {
// Side with RLF
if (system.ID === 251 && !ionics) {
// Zaria: First visit to Zaria.
mission.runScreen({title: "Ionics", messageKey: "ionics_zaria_news_1"});
missionVariables.ionics = "PRE_STAGE1";
missionVariables.ionics_ramaza_status = "RLF_1";
return;
}
if (system.ID === 26 && ionics === "PRE_STAGE1") {
// Ramaza: First orders.
mission.runScreen({title: "Ionics", messageKey: "ionics_order_1", choicesKey: "ionics_question_1"
},
function (choice) {
if (choice === "ACCEPT_OFFER_1") {
missionVariables.ionics = "STAGE1";
mission.setInstructionsKey("ionics_short_desc1");
mission.markSystem(251);
}
if (choice === "REJECT_OFFER_1") {
missionVariables.ionics = "MISSION_COMPLETE_1";
}
});
}
if (system.ID === 251 && ionics === "STAGE1") {
// Zaria: Collected package.
mission.unmarkSystem(251);
player.credits += 500;
missionVariables.ionics = "STAGE2A";
mission.setInstructionsKey("ionics_short_desc2a");
mission.markSystem(26);
mission.runScreen({title: "Ionics", messageKey: "ionics_order_2a"});
}
if (system.ID === 26 && ionics === "STAGE2A") {
// Ramaza: Package delivered. RLF make offer to destroy fleet.
mission.unmarkSystem(26);
player.credits += 500;
mission.runScreen({title: "Ionics", messageKey: "ionics_order_3a", choicesKey: "ionics_question_3"
},
function (choice) {
if (choice === "ACCEPT_OFFER_3A") {
// Ramaza: Accept offer to destroy fleet.
missionVariables.ionics = "STAGE3A";
mission.setInstructionsKey("ionics_short_desc3a");
mission.markSystem(251);
}
if (choice === "REJECT_OFFER_3A") {
// Ramaza: Rejected offer to destroy fleet. Missions end completely.
missionVariables.ionics = "MISSION_COMPLETE_3A";
}
});
}
if (system.ID === 251 && ionics === "MISSION_SUCCESSFUL") {
// Zaria: Ionics fleet destroyed, refuelling for trip back to Ramaza.
missionVariables.ionics = "ZARIA_NEWS_2";
mission.runScreen({title: "Ionics", messageKey: "ionics_zaria_news_2"});
mission.setInstructionsKey("ionics_short_desc4");
}
if (system.ID === 26 && (ionics === "MISSION_SUCCESSFUL" || ionics === "ZARIA_NEWS_2")) {
// Ramaza: Ionics fleet destroyed, RLF makes payment.
missionVariables.ionics = "MISSION_COMPLETE_A";
player.credits += 15000;
mission.unmarkSystem(26);
mission.runScreen({title: "Ionics", messageKey: "ionics_order_4a"});
mission.setInstructionsKey(null);
}
if (system.ID === 251 && ionics === "MISSION_COMPLETE_A") {
// Zaria: The Link becomes involved.
missionVariables.ionics = "ZARIA_NEWS_3";
missionVariables.ionics_ramaza_status = "RLF_2";
mission.runScreen({title: "Ionics", messageKey: "ionics_zaria_news_3"});
}
if (system.ID === 198 && ionics === "STAGE5") {
// Cevera: Pick up equipment.
missionVariables.ionics = "STAGE6";
missionVariables.ionics_ramaza_status = "RLF_2";
mission.unmarkSystem(198);
mission.markSystem(26);
mission.runScreen({title: "Ionics", messageKey: "ionics_order_6"});
mission.setInstructionsKey("ionics_short_desc6");
}
if (system.ID === 251 && ionics === "MISSION_COMPLETE_1") {
// Zaria: Ionics makes offer.
mission.runScreen({title: "Ionics", messageKey: "ionics_order_2b", choicesKey: "ionics_question_2b"
},
function (choice) {
if (choice === "ACCEPT_OFFER_2B") {
// Zaria: Accept Ionics offer.
missionVariables.ionics = "STAGE2B";
mission.setInstructionsKey("ionics_short_desc2b");
mission.markSystem(26);
}
if (choice === "REJECT_OFFER_2B") {
// Zaria: Rejected Ionics offer. Missions end completely.
missionVariables.ionics = "MISSION_COMPLETE_2B";
}
});
}
if (system.ID === 26 && ionics === "STAGE2B") {
// Ramaza: RLF infiltrated.
missionVariables.ionics = "STAGE3B";
mission.unmarkSystem(26);
mission.markSystem(251);
mission.runScreen({title: "Ionics", messageKey: "ionics_order_3b"});
mission.setInstructionsKey("ionics_short_desc3b");
}
if (system.ID === 251 && ionics === "STAGE3B") {
// Zaria: RLF infiltrated. Ionics makes payment.
missionVariables.ionics = "MISSION_COMPLETE_B";
mission.unmarkSystem(251);
player.credits += 1500;
mission.runScreen({title: "Ionics", messageKey: "ionics_order_4b"});
mission.setInstructionsKey(null);
}
if (system.ID === 26 && ionics === "WAR_IN_RAMAZA") {
// Ramaza: war going on.
var display_stats = this.ionics_display_stats;
if (display_stats === "REJECT") {
// Ramaza: war going on, launch player.*
this.ionics_display_stats = false;
player.ship.launch();
return;
}
if (display_stats && missionVariables.ionics_government_kills > 25) {
// Ramaza: war going on warn player.
mission.runScreen({title: "Ionics", messageKey: "ionics_war_ramaza"});
this.ionics_display_stats = "REJECT";
}
}
}
if (player.ship.dockedStation.name === "The Link Base") {
// Player docked at the link base. Always in Ramaza (system.ID = 26)
function firstVisit(choice) {
// Handles the choices of next check
switch(choice) {
case "WHAT_IS_THE_LINK":{
// Ramaza: answer question about The Link.
mission.runScreen({title: "Ionics", messageKey: "ionics_answer_1", choicesKey: "ionics_question_5"}, firstVisit);
break;
}
case "ACCEPT_OFFER_4": {
// Ramaza: accept mission.
missionVariables.ionics = "STAGE5";
mission.markSystem(198);
mission.setInstructionsKey("ionics_short_desc5");
break;
}
case "REJECT_OFFER_4": {
// Ramaza: reject mission. END.
missionVariables.ionics = "MISSION_REJECTED_STAGE5";
break;
}
}
}
if (ionics === "ZARIA_NEWS_3") {
// Ramaza: First time docked at The Link base.
mission.runScreen({title: "Ionics", messageKey: "ionics_order_5", choicesKey: "ionics_question_4"}, firstVisit);
}
if (ionics === "STAGE6") {
// Ramaza: Second docking, admitted to The Link.
mission.runScreen({title: "Ionics", messageKey: "ionics_order_7"});
mission.markSystem(26);
// Ramaza: Setup war in Ramaza.
missionVariables.ionics = "WAR_IN_RAMAZA";
mission.setInstructionsKey("ionics_short_desc7");
missionVariables.ionics_government_fleet_size = 200;
missionVariables.ionics_link_fleet_size = 100;
missionVariables.ionics_rlf_fleet_size = 50;
this.ionics_display_stats = false;
missionVariables.ionics_ramaza_status = "RLF_3";
missionVariables.ionics_government_kills = 0;
}
if (ionics === "WAR_IN_RAMAZA" && this.ionics_display_stats) {
// Ramaza: Docked at Link Base, free refuel and display war progress.
mission.runScreen({title: "Ionics", messageKey: "ionics_war_progress"});
this.ionics_display_stats = false;
player.ship.fuel = 7;
var emptySlots = player.ship.missileCapacity - player.ship.missiles.length;
for (var i=0; i<emptySlots; i++) {player.ship.awardEquipment("EQ_MISSILE")};
var missileText = emptySlots ? ("and " + emptySlots + " missile silo(s) ") : "";
var legalStatus = player.bounty ? " and your legal status has been cleaned" : "";
player.bounty = 0;
mission.addMessageText("Your fuel tanks " + missileText + "have been replenished" + legalStatus + ".");
this.validatePosition(system.shipsWithPrimaryRole("ramazan_government_vessel"));
}
if (ionics === "WAR_IN_RAMAZA_VICTORY") {
// Ramaza: Docked at Link Base, war is won.
mission.runScreen({title: "Ionics", messageKey: "ionics_ramaza_victory"});
missionVariables.ionics = "RAMAZA_WAR_OVER";
missionVariables.ionics_ramaza_status = "LIBERATED";
player.bounty = 0;
mission.unmarkSystem(26);
mission.setInstructionsKey(null);
// remove no longer used variables
delete missionVariables.ionics_government_fleet_size;
delete missionVariables.ionics_link_fleet_size;
delete missionVariables.ionics_rlf_fleet_size;
delete missionVariables.ionics_government_kills;
}
}
};
this.shipLaunchedFromStation = function () {
// reset display for mission.
if (galaxyNumber === 1 && system.ID === 26 && missionVariables.ionics === "WAR_IN_RAMAZA" && !this.warTimer) {
// this.warTimer is undefined when loading a gaved game. In all other cases we already entered through witchspace.
this.startWar();
}
};
this.shipExitedWitchspace = function() {
if (galaxyNumber !== 1) return;
var ionics = missionVariables.ionics;
if (system.ID === 26 && ionics === "STAGE2A" && Math.random() < 0.5) {
// Ramaza: Delivering package, Ionics assassin strikes (maybe).
var redback = system.addShips("redback", 1, [0, 0, 1500]);
redback[0].commsMessage("Die rebel scum!");
}
if (system.ID === 251 && ionics === "STAGE3A") {
// Zaria: Setup Ionics fleet delivery battle.
var funnelweb = system.addShips("funnelweb_mission", 1, [0, 0, 10000], 5E3)[0];
var redback = system.addShips("redback_mission", 2, [0, 0, 9500], 5E3);
var whitetail = system.addShips("whitetail_mission", 4, [0, 0, 9250], 5E3);
system.addShips("rlf_leader", 1, [0, 0, 2000], 5E3);
system.addGroup("rlf_fighter", 4, [0, 0, 2500], 5E3);
if (!funnelweb.group) funnelweb.group = new ShipGroup("Weapon Transport");
funnelweb.group.addShip(funnelweb);
for (var i=0; i<redback.length; i++) this.addToGroup(funnelweb.group, redback[i]);
for (var i=0; i<whitetail.length; i++) this.addToGroup(funnelweb.group, whitetail[i]);
funnelweb.group.leader = funnelweb;
// funnelweb.group.name = "Weapon Transport";
this.sendToPlanet(system.shipsWithPrimaryRole("police"));
}
if (system.ID === 26 && ionics === "ZARIA_NEWS_3") {
// Ramaza: Link sends comms message to commander.
var message = "Please dock at The Link Base, we urgently require your assistance.";
if (player.ship.equipmentStatus("EQ_ADVANCED_COMPASS") === "EQUIPMENT_OK") {
message = message + " The coordinates have been uploaded to your space compass.";
} else {
message = message + "You need an advanced space compass for the coordinates.";
}
player.commsMessage(message, 10);
}
if ((ionics === "STAGE5" || ionics === "STAGE6") && Math.random() < 0.75) {
// Anywhere: Ramazan government attacks
var whitetail = system.addShips("whitetail_mission", 4, [0, 0, -1000]);
whitetail[0].commsMessage("You will pay dearly for your interference Commander!");
}
if (system.ID === 26 && missionVariables.ionics === "WAR_IN_RAMAZA") {
this.startWar();
}
};
this.validatePosition = function (ships) {
/*
This code makes sure that ships that did drift away while fighting, are put back in the battlezone when called.
This should prevent that the player can't find any ship at all, while new ones are not added.
*/
for (var i=0; i<ships.length; i++) {
if (this.battlezone.subtract(ships[i].position).magnitude() > 50E3 && ships[i].AIState == "ATTACK_SHIP") {
ships[i].position = battlezone.add(Vector3D.random(10E3));
}
}
};
this.sendToPlanet = function (ships) {
/*
This code sets all ships in the state: HEAD_FOR_PLANET when they have that state.
This should delay the pressence of regular police that by default start with going to the
whichpoint.
*/
for (var i=0; i<ships.length; i++) ships[i].AIState = "HEAD_FOR_PLANET";
}
this.addToGroup = function (mainGroup, ship) {
// add ship and possible escorts to group. Main reason is to let Oolite deal with friendly fire.
if (ship.escortGroup) {
// there are escorts. (ship is part of escort group)
for (var i=0; i<ship.escortGroup.count; i++) {
mainGroup.addShip(ship.escortGroup.ships[i]);
}
} else {
mainGroup.addShip(ship);
}
ship.group = mainGroup;
};
this.startWar = function (){
this.ionics_display_stats = true;
this.linkStation = system.shipsWithPrimaryRole("ionics_linkbase")[0];
if (!this.government_vessels) this.government_vessels = new ShipGroup("government vessels");
if (!this.link_vessels) this.link_vessels = new ShipGroup("link vessels");
this.rlf_additionPoint = Vector3D(0, 200000, 200000).toCoordinateSystem("wpm");
this.battlezone = Vector3D(200000, 0, 0).toCoordinateSystem("pwm");
if (this.warTimer) {
this.warTimer.start();
} else {
this.warTimer = new Timer(this, this.warProgess, 5, 15);
}
// missionVariables.ionics_government_kills is added in 1.3.
// Initialise here in case a player started the mission with the legacy version.
if (!missionVariables.ionics_government_kills) missionVariables.ionics_government_kills = 0;
};
this.setupWar = function (){
// this code was previously in 'planetInfo.plist' for system 26
system.addShips("asteroid", 20, Vector3D(400E3, 0, 0).toCoordinateSystem("pwm"), 20E3);
system.addShips("ionics_RLF_vessel", 5, Vector3D(400E3, 0, 0).toCoordinateSystem("pwm"), 1);
system.addShips("ionics_link_vessel", 5, Vector3D(400E3, 0, 0).toCoordinateSystem("pwm"), 1);
system.addShips("ionics_linkbase", 1, Vector3D(400E3, 0, 0).toCoordinateSystem("pwm"), 1);
}
// add the next with a timer:
this.warProgess = function() {
if (system.ID !== 26) {this.warTimer.stop(); return}; // Player jumped out of system.
if (system.countShipsWithPrimaryRole("ramazan_government_vessel") == 0 && this.government_vessels.count == 0) {
var fleet = missionVariables.ionics_government_fleet_size;
if (fleet > 5) fleet = 5;
for (var i = 0; i<fleet; i++) this.addToGroup(this.government_vessels, system.mainStation.launchShipWithRole("ramazan_government_vessel", true));
}
if (system.countShipsWithPrimaryRole("ionics_link_vessel") == 0 && this.link_vessels.count == 0 && this.linkStation && this.linkStation.isValid) {
var fleet = missionVariables.ionics_link_fleet_size;
if (fleet > 5) fleet = 5;
for (var i = 0; i<fleet; i++) this.addToGroup(this.link_vessels, this.linkStation.launchShipWithRole("ionics_link_vessel", true));
}
if (system.countShipsWithPrimaryRole("ionics_RLF_vessel") == 0) {
var fleet = missionVariables.ionics_rlf_fleet_size;
if (fleet > 5) fleet = 5;
if (fleet > 0) system.addShips("ionics_RLF_vessel", fleet, this.rlf_additionPoint);
}
if (missionVariables.ionics_government_fleet_size < 1) {
missionVariables.ionics = "WAR_IN_RAMAZA_VICTORY";
player.commsMessage("We've won the war!!! All vessels return to base for debriefing", 10);
mission.setInstructionsKey("ionics_short_desc8");
var weaponPlatforms = system.shipsWithPrimaryRole("ionics_weapons_platform");
for (var i=0; i<weaponPlatforms.length; i++) weaponPlatforms[i].switchAI("nullAI.plist");
this.warTimer.stop();
delete this.warTimer;
}
}; |