| Scripts/lave_mission_1.js | "use strict";
this.name = "lave_mission_1";
this.author = "phkb";
this.copyright = "2024 phkb";
this.description = "Mission type 1 for Lave system";
this.license = "CC-BY-NC-SA 4.0";
this._missionShips = [];
this._pirates = [];
this._progress = null;
this._sentLastOneComms = false;
//-------------------------------------------------------------------------------------------------------------
this.startUpComplete = function () {
    var status = worldScripts.lave_missions._missionStatus["mission_1"];
    // check if the player has reloaded the game while it was in progress
    if (status == "STARTED") {
        this.$setupMission();
        return;
    }
    if (status == "FAILED" || status == "PARTIAL_COMPLETE" || status == "COMPLETE") {
        this.missionScreenOpportunity = this.missionScreenOpportunity_hold;
    }
}
//-------------------------------------------------------------------------------------------------------------
this.$setupMission = function () {
    mission.setInstructionsKey(this.name + "_instructions", this.name);
    this.shipLaunchedFromStation = this.shipLaunchedFromStation_hold;
    this.missionScreenOpportunity = this.missionScreenOpportunity_hold;
    this.shipWillDockWithStation = this.shipWillDockWithStation_hold;
    this.shipWillEnterWitchspace = this.shipWillEnterWitchspace_hold;
    this.playerEnteredNewGalaxy = this.playerEnteredNewGalaxy_hold;
}
//-------------------------------------------------------------------------------------------------------------
this.$cleanUp = function () {
    delete this.shipLaunchedFromStation;
    delete this.missionScreenOpportunity;
    delete this.shipWillDockWithStation;
    delete this.shipWillEnterWitchspace;
    delete this.playerEnteredNewGalaxy;
}
//-------------------------------------------------------------------------------------------------------------
this.shipLaunchedFromStation_hold = function (station) {
    var pos = Vector3D.interpolate(system.sun.position, station.position, 0.66);
    // create the instructor flight and put them all in a group
    this._missionShips = system.addShips("instructor_mission", 1, pos, 1000);
    // make sure all the escorts are in the missionShips array
    for (var i = 0; i < this._missionShips[0].escorts.length; i++) {
        this._missionShips.push(this._missionShips[0].escorts[i]);
    }
    // create our pirates
    this._pirates = system.addShips("pirate", 4, pos, 10000);
    var prGroup = new ShipGroup("pirate_flight", this._pirates[0]);
    var i = this._pirates.length;
    while (i--) {
        // we're removing fuel injectors, because this mission gets messy if everything spreads out too much
        // and the player has to chase the bad guys too much
        this._pirates[i].removeEquipment("EQ_FUEL_INJECTION");
        prGroup.addShip(this._pirates[i]);
        this._pirates[i].group = prGroup;
        this._pirates[i].target = this._missionShips[parseInt(Math.random() * this._missionShips.length)];
        this._pirates[i].performAttack();
    }
    this._progress = new Timer(this, this.$checkProgress, 5, 5);
    delete this.shipLaunchedFromStation;
}
//-------------------------------------------------------------------------------------------------------------
this.shipWillEnterWitchspace_hold = function () {
    if (worldScripts.lave_missions._missionStatus["mission_1"] == "STARTED") {
        worldScripts.lave_missions._missionStatus["mission_1"] = "FAILED";
        mission.setInstructionsKey(this.name + "_instructions_complete", this.name);
    }
}
//-------------------------------------------------------------------------------------------------------------
this.playerEnteredNewGalaxy_hold = function () {
    if (worldScripts.lave_missions._missionStatus["mission_1"] == "STARTED") {
        worldScripts.lave_missions._missionStatus["mission_1"] = "FINISHED";
        mission.setInstructionsKey(null, this.name);
        this.$cleanUp();
    }
}
//-------------------------------------------------------------------------------------------------------------
this.shipWillDockWithStation_hold = function (station) {
    if (this._progress.isRunning) this._progress.stop();
    var status = worldScripts.lave_missions._missionStatus["mission_1"];
    if (status == "STARTED") {
        // have we finished but wasn't close enough to any of the mission ships to get the final message?
        var pr = this._pirates;
        var i = pr.length;
        while (i--) {
            // if there's at least one valid pirate left, it's still on
            // todo: check if they ran away - despawn them if they get too far from the mission ships
            if (pr[i] && pr[i].isValid) return;
        }
        var ms = this._missionShips;
        var i = ms.length;
        var deaths = 0;
        while (i--) {
            if (!ms[i] || !ms[i].isValid) deaths += 1;
        }
        if (deaths == ms.length) {
            worldScripts.lave_missions._missionStatus["mission_1"] = "FAILED";
        } else {
            worldScripts.lave_missions._missionStatus["mission_1"] = (deaths > 0 ? "PARTIAL_COMPLETE" : "COMPLETE");
        }
        mission.setInstructionsKey(this.name + "_instructions_complete", this.name);
        this.$sendFlightHome();
    }
}
//-------------------------------------------------------------------------------------------------------------
this.missionScreenOpportunity_hold = function () {
    if (player.ship.dockedStation.dataKey == "laveAcademy_academy") {
        var status = worldScripts.lave_missions._missionStatus["mission_1"];
        if (status == "NOT_STARTED" || status == "FINISHED" || status == "STARTED") return; // player redocked for some reason
        // otherwise, we're finished
        worldScripts.lave_missions._missionStatus["mission_1"] = "FINISHED";
        switch (status) {
            case "FAILED":
                mission.runScreen({ title: expandMissionText("lave_mission_1_title_1"), messageKey: "lave_mission_1_failed", screenID: "lave_missions" });
                break;
            case "PARTIAL_COMPLETE":
                mission.runScreen({ title: expandMissionText("lave_mission_1_title_2"), messageKey: "lave_mission_1_partial", screenID: "lave_missions" });
                player.credits += 200;
                break;
            case "COMPLETE":
                mission.runScreen({ title: expandMissionText("lave_mission_1_title_3"), messageKey: "lave_mission_1_complete", screenID: "lave_missions" });
                player.credits += 1000;
                break;
        }
        mission.setInstructionsKey(null, this.name);
        this.$cleanUp();
        worldScripts.lave_missions._checkForMission = false; // so we don't get asked about a new mission when we finish this one
    }
}
//-------------------------------------------------------------------------------------------------------------
this.$checkProgress = function $checkProgress() {
    var pr = this._pirates;
    var i = pr.length;
    var enemies = 0;
    while (i--) {
        // if there's at least one valid pirate left, it's still on
        if (pr[i] && pr[i].isValid) {
            // todo: check if they ran away - despawn them if they get too far from the mission ships
            enemies += 1;
        }
    }
    if (enemies == 1 && this._sentLastOneComms == false) {
        this._sentLastOneComms = true;
        var sc = player.ship.checkScanner(true);
        i = sc.length;
        while (i--) {
            if (sc[i].roles.indexOf("lave_mission")) {
                sc[i].commsMessage(expandMissionText("lave_mission_1_comms_1"), player.ship);
                break;
            }
        }
    }
    if (enemies > 0) return;
    var ms = this._missionShips;
    var i = ms.length;
    var commSource;
    var deaths = 0;
    while (i--) {
        if (!ms[i] || !ms[i].isValid) {
            deaths += 1;
        } else {
            commSource = ms[i]; // get a reference to a valid ship object
        }
    }
    if (deaths == ms.length) {
        worldScripts.lave_missions._missionStatus["mission_1"] = "FAILED";
        this._progress.stop();
        return;
    }
    // we'd only get to this point if all the pirates are dead and at least 1 of the group is still alive
    // get one of the ships to send a message once they're in range
    if (commSource && commSource.isValid) {
        if (commSource.position.distanceTo(player.ship) < player.ship.scannerRange) {
            commSource.commsMessage(expandMissionText("lave_mission_1_comms_2"), player.ship);
            worldScripts.lave_missions._missionStatus["mission_1"] = (deaths > 0 ? "PARTIAL_COMPLETE" : "COMPLETE");
            mission.setInstructionsKey(this.name + "_instructions_complete", this.name);
            this._progress.stop();
        }
    }
    this.$sendFlightHome();
}
//-------------------------------------------------------------------------------------------------------------
this.$sendFlightHome = function () {
    if (this._missionShips.length == 0) return;
    var stnLoc = system.shipsWithRole("laveAcademy_academy")[0];
    // check if we got an actual ship location returned
    if (stnLoc) {
        if (this._missionShips[0].isValid) {
            this._missionShips[0].switchAI("oolite-shuttleAI.js");
            // send leader back to academy - escorts will follow so no need to do this for them
            this._missionShips[0].AIScript.oolite_priorityai.setParameter("oolite_selectedPlanet", null);
            this._missionShips[0].AIScript.oolite_priorityai.setParameter("oolite_selectedStation", stnLoc);
            this._missionShips[0].AIScript.oolite_priorityai.reconsiderNow();
        } else {
            // unless the leader is dead, so send all trainees back to the station individually
            for (var i = 1; i < this._missionShips.length; i++) {
                if (this._missionShips[i].isValid) {
                    this._missionShips[i].switchAI("oolite-shuttleAI.js");
                    this._missionShips[i].AIScript.oolite_priorityai.setParameter("oolite_selectedPlanet", null);
                    this._missionShips[i].AIScript.oolite_priorityai.setParameter("oolite_selectedStation", stnLoc);
                    this._missionShips[i].AIScript.oolite_priorityai.reconsiderNow();
                }
            }
        }
    }
} | 
                
                    | Scripts/lave_mission_2.js | "use strict";
this.name = "lave_mission_2";
this.author = "phkb";
this.copyright = "2024 phkb";
this.description = "Mission type 2 for Lave system";
this.license = "CC-BY-NC-SA 4.0";
this._targetSystem = -2;
this._sourceSystem = -1;
this._missionShip = null;
this._messages = [];
this._checkForRefueling = false;
this._dist = 0;
this._holdShipName = "";
//-------------------------------------------------------------------------------------------------------------
this.startUp = function () {
    if (missionVariables.LaveMission_SourceSystemID) {
        this._sourceSystem = missionVariables.LaveMission2_SourceSystemID;
    }
    if (missionVariables.LaveMission_TargetSystemID) {
        this._targetSystem = missionVariables.LaveMission2_TargetSystemID;
    }
    if (this._sourceSystem != -1 && this._targetSystem != -2) {
        this.$setupFunctions();
    }
}
//-------------------------------------------------------------------------------------------------------------
this.$setupMission = function () {
    // pick a system within 7 ly of current.
    var syslist = system.info.systemsInRange(7);
    var sys = syslist[parseInt(Math.random() * syslist.length)];
    this._targetSystem = sys.systemID;
    this._sourceSystem = system.ID;
    missionVariables.LaveMission2_SourceSystemID = system.ID;
    missionVariables.LaveMission2_SourceSystem = system.name;
    missionVariables.LaveMission2_TargetSystemID = this._targetSystem;
    this.$setupFunctions();
}
//-------------------------------------------------------------------------------------------------------------
this.$setupFunctions = function () {
    this.systemWillPopulate = this.systemWillPopulate_hold;
    this.missionScreenOpportunity = this.missionScreenOpportunity_hold;
    this.playerEnteredNewGalaxy = this.playerEnteredNewGalaxy_hold;
    this.playerWillEnterWitchspace = this.playerWillEnterWitchspace_hold;
    mission.setInstructionsKey(this.name + "_instructions", this.name);
}
//-------------------------------------------------------------------------------------------------------------
this.$cleanUp = function () {
    this._targetSystem = -2;
    if (this._progress && this._progress.isRunning) this._progress.stop();
    delete missionVariables.LaveMission2_SourceSystem;
    delete missionVariables.LaveMission2_TargetSystemID;
    delete missionVariables.LaveMission2_SourceSystemID;
    delete this.systemWillPopulate;
    delete this.missionScreenOpportunity;
    delete this.playerEnteredNewGalaxy;
    delete this.playerWillEnterWitchspace;
}
//-------------------------------------------------------------------------------------------------------------
this.playerWillEnterWitchspace = function () {
    if (this._progress && this._progress.isRunning) this._progress.stop();
}
//-------------------------------------------------------------------------------------------------------------
this.systemWillPopulate_hold = function () {
    if (system.ID == this._targetSystem) {
        this._missionShip = system.addShips("trainee_lost1", 1, [0, 0, 0], 5000)[0];
        this._progress = new Timer(this, this.$checkProgress.bind(this), 10, 5);
    }
    if (system.ID == this._sourceSystem && worldScripts.lave_missions._missionStatus["mission_2"] == "FOUND") {
        this._missionShip = system.addShips("trainee_lost2", 1, [0, 0, 0], 5000)[0];
        this._delay = new Timer(this, this.$sendFlightHome, 3, 0);
        if (this._holdShipName != "") {
            this._missionShip.displayName = this._holdShipName;
        }
    }
}
//-------------------------------------------------------------------------------------------------------------
this.playerEnteredNewGalaxy_hold = function () {
    if (worldScripts.lave_missions._missionStatus["mission_2"] == "STARTED") {
        worldScripts.lave_missions._missionStatus["mission_2"] = "FINISHED";
        mission.setInstructionsKey(null, this.name);
        this.$cleanUp();
    }
}
//-------------------------------------------------------------------------------------------------------------
this.missionScreenOpportunity_hold = function () {
    if (player.ship.dockedStation.dataKey == "laveAcademy_academy") {
        var status = worldScripts.lave_missions._missionStatus["mission_2"];
        if (status == "NOT_STARTED" || status == "FINISHED" || status == "STARTED") return; // player redocked for some reason
        // otherwise, we're finished
        switch (status) {
            case "FAILED":
                mission.runScreen({ title: expandMissionText("lave_mission_2_title_1"), messageKey: "lave_mission_2_failed", screenID: "lave_missions" });
                break;
            case "FOUND":
                // trainee hasn't docked yet
                return;
            case "COMPLETE":
                mission.runScreen({ title: expandMissionText("lave_mission_2_title_2"), messageKey: "lave_mission_2_complete", screenID: "lave_missions" });
                player.credits += 1000;
                break;
        }
        worldScripts.lave_missions._missionStatus["mission_2"] = "FINISHED";
        mission.setInstructionsKey(null, this.name);
        this.$cleanUp();
        worldScripts.lave_missions._checkForMission = false; // so we don't get asked about a new mission when we finish this one
    }
}
//-------------------------------------------------------------------------------------------------------------
this.$checkProgress = function $checkProgress() {
    if (system.ID == this._targetSystem) {
        if (worldScripts.lave_missions._missionStatus["mission_2"] == "STARTED" && this._missionShip.position.distanceTo(player.ship) < player.ship.scannerRange * 0.8) {
            worldScripts.lave_missions._missionStatus["mission_2"] = "FOUND";
            mission.setInstructionsKey(this.name + "_instructions_found", this.name);
            if (this._holdShipName == "") this._holdShipName = this._missionShip.displayName;
            this._dist = system.info.distanceToSystem(System.infoForSystem(galaxyNumber, this._sourceSystem));
            if (player.ship.fuel < this._dist) {
                // offer some fuel to player
                this._messages = expandMissionText("lave_mission_2_offerfuel").split("|");
                this._checkForRefueling = true;
            } else {
                // thank player for coming
                this._messages = expandMissionText("lave_mission_2_thanksforhelp").split("|");
            }
        }
    }
    if (this._messages.length > 0 && this._missionShip.position.distanceTo(player.ship) < player.ship.scannerRange) {
        var text = this._messages.shift();
        this._missionShip.commsMessage(text, player.ship);
    }
    if (this._checkForRefueling == true && player.ship.fuel < this._dist && this._missionShip.position.distanceTo(player.ship) <= 86) {
        player.consoleMessage(expandMissionText("lave_mission_2_fuel"), 4);
        player.ship.fuel += 1;
    }
    if (this._checkForRefueling == true && player.ship.fuel >= this._dist) {
        this._checkForRefueling = false;
        this._missionShip.commsMessage(expandMissionText("lave_mission_2_comms_1"), player.ship);
        this._messages = [expandMissionText("lave_mission_2_comms_2")];
    }
}
//-------------------------------------------------------------------------------------------------------------
this.$updateStatus = function () {
    mission.setInstructionsKey(this.name + "_instructions_complete", this.name);
}
//-------------------------------------------------------------------------------------------------------------
this.$sendFlightHome = function $sendFlightHome() {
    var stnLoc = system.shipsWithRole("laveAcademy_academy")[0];
    // check if we got an actual ship location returned
    if (stnLoc) {
        if (this._missionShip.isValid) {
            // send ship back to academy
            this._missionShip.AIScript.oolite_priorityai.setParameter("oolite_selectedPlanet", null);
            this._missionShip.AIScript.oolite_priorityai.setParameter("oolite_selectedStation", stnLoc);
            this._missionShip.AIScript.oolite_priorityai.reconsiderNow();
        }
    }
} | 
                
                    | Scripts/lave_mission_3.js | "use strict";
this.name = "lave_mission_3";
this.author = "phkb";
this.copyright = "2024 phkb";
this.description = "Mission type 3 for Lave system";
this.license = "CC-BY-NC-SA 4.0";
this._rhRoles = ["rockhermit", "rockhermit-chaotic", "rockhermit-pirate"];
//-------------------------------------------------------------------------------------------------------------
this.startUp = function () {
    if (missionVariables.LaveMission3_SourceSystemID) {
        if (system.ID == missionVariables.LaveMission3_SourceSystemID) {
            this.$setupMission();
        } else {
            this.systemWillPopulate = this.systemWillPopulate_hold;
        }
    }
}
//-------------------------------------------------------------------------------------------------------------
this.$setupMission = function () {
    this.missionScreenOpportunity = this.missionScreenOpportunity_hold;
    this.playerEnteredNewGalaxy = this.playerEnteredNewGalaxy_hold;
    var rhlist = [].concat(system.shipsWithRole("rockhermit")).concat(system.shipsWithRole("rockhermit-chaotic")).concat(system.shipsWithRole("rockhermit-pirate"));
    var idx = parseInt(Math.random() * rhlist.length);
    rhlist[idx]._laveMission3 = true;
    mission.setInstructionsKey(this.name + "_instructions", this.name);
    missionVariables.LaveMission3_SourceSystemID = system.ID;
}
//-------------------------------------------------------------------------------------------------------------
this.$cleanUp = function () {
    delete missionVariables.LaveMission3_SourceSystemID;
    delete this.missionScreenOpportunity;
    delete this.playerEnteredNewGalaxy;
    delete this.systemWillPopulate;
}
//-------------------------------------------------------------------------------------------------------------
this.systemWillPopulate_hold = function () {
    if (missionVariables.LaveMission3_SourceSystemID && system.ID == missionVariables.LaveMission3_SourceSystemID) {
        this.$setupMission();
    }
}
//-------------------------------------------------------------------------------------------------------------
this.playerEnteredNewGalaxy_hold = function () {
    if (worldScripts.lave_missions._missionStatus["mission_3"] == "STARTED") {
        worldScripts.lave_missions._missionStatus["mission_3"] = "FINISHED";
        mission.setInstructionsKey(null, this.name);
        this.$cleanUp();
    }
}
//-------------------------------------------------------------------------------------------------------------
this.missionScreenOpportunity_hold = function () {
    var stn = player.ship.dockedStation;
    if (this._rhRoles.indexOf(stn.primaryRole) >= 0) {
        if (stn.hasOwnProperty("_laveMission3") && stn._laveMission3 == true) {
            stn._laveMission3 = false;
            worldScripts.lave_missions._missionStatus["mission_3"] = "COMPLETE";
            mission.runScreen({ title: expandMissionText("lave_mission_3_title_1"), messageKey: "lave_mission_3_found", screenID: "lave_missions" });
            mission.setInstructionsKey(this.name + "_instructions_complete", this.name);
            this._missionShip = stn.launchShipWithRole("trainee_repaired");
            this._delay = new Timer(this, this.$sendFlightHome, 10, 0);
            return;
        }
    }
    if (player.ship.dockedStation.dataKey == "laveAcademy_academy") {
        var status = worldScripts.lave_missions._missionStatus["mission_3"];
        if (status == "NOT_STARTED" || status == "FINISHED" || status == "STARTED") return; // player redocked for some reason
        // otherwise, we're finished
        switch (status) {
            case "COMPLETE":
                mission.runScreen({ title: expandMissionText("lave_mission_3_title_2"), messageKey: "lave_mission_3_complete", screenID: "lave_missions" });
                player.credits += 200;
                break;
        }
        worldScripts.lave_missions._missionStatus["mission_3"] = "FINISHED";
        mission.setInstructionsKey(null, this.name);
        this.$cleanUp();
        worldScripts.lave_missions._checkForMission = false; // so we don't get asked about a new mission when we finish this one
    }
}
//-------------------------------------------------------------------------------------------------------------
this.$sendFlightHome = function $sendFlightHome() {
    var stnLoc = system.shipsWithRole("laveAcademy_academy")[0];
    // check if we got an actual ship location returned
    if (stnLoc) {
        if (this._missionShip.isValid) {
            // send ship back to academy
            this._missionShip.AIScript.oolite_priorityai.setParameter("oolite_selectedPlanet", null);
            this._missionShip.AIScript.oolite_priorityai.setParameter("oolite_selectedStation", stnLoc);
            this._missionShip.AIScript.oolite_priorityai.reconsiderNow();
        }
    }
} | 
                
                    | Scripts/lave_missions.js | "use strict";
this.name = "lave_missions";
this.author = "phkb";
this.copyright = "2024 phkb";
this.description = "Missions for Lave";
this.license = "CC-BY-NC-SA 4.0";
/*
    Mission 1: help a flight of students who have fallen under pirate attack on their way to the sun.
    Mission 2: find lost student who fell through wormhole and got stranded.
    Mission 3: rescue a learner who has broken down and docked at a Rock Hermit. Deliver parts to rock hermit so Learner can repair ship
*/
this._checkForMission = false;
this._missionStatus = {};
this._forceStart = "";
this._hold = "";
//-------------------------------------------------------------------------------------------------------------
this.startUp = function() {
    if (missionVariables.LaveMissions) {
        this._missionStatus = JSON.parse(missionVariables.LaveMissions);
    } else {
        this._missionStatus["mission_1"] = "NOT_STARTED";
        this._missionStatus["mission_2"] = "NOT_STARTED";
        this._missionStatus["mission_3"] = "NOT_STARTED";
    }
}
//-------------------------------------------------------------------------------------------------------------
this.startUpComplete = function() {
    if (player.ship.dockedStation.dataKey == "laveAcademy_academy") {
        this._checkForMission = true;
    }
}
//-------------------------------------------------------------------------------------------------------------
this.playerWillSaveGame = function() {
    missionVariables.LaveMissions = JSON.stringify(this._missionStatus);
}
//-------------------------------------------------------------------------------------------------------------
this.shipWillDockWithStation = function(station) {
    this._checkForMission = false;
    if (station.dataKey == "laveAcademy_academy") {
        this._checkForMission = true;
    }
}
//-------------------------------------------------------------------------------------------------------------
this.missionScreenOpportunity = function() {
    if (this._checkForMission == true) {
        this._checkForMission = false;
        if ((player.score >= 128 && Math.random() > 0.9) || this._forceStart != "") {
            this._hold = this.$availableMission();
            if (this._forceStart != "" && this._hold != "NONE") this._hold = this._forceStart;
            if (this._hold == "NONE") return;
            if (this._hold == "mission_3") {
                missionVariables.LaveMission3_RockHermitSummary = this.$rhSummary();
            }
            // start the mission
            mission.runScreen({ title: expandMissionText("lave_missions_urgent_help"), messageKey: "lave_" + this._hold + "_briefing", choicesKey: "lave_mission_options", screenID:"lave_missions" },
                function (choice) {
                    var lm = worldScripts.lave_missions;
                    if (!choice) choice = "02_NO";
                    if (choice == "01_YES") {
                        this._missionStatus[lm._hold] = "STARTED";
                        worldScripts["lave_" + lm._hold].$setupMission();
                        mission.runScreen({ title: expandMissionText("lave_missions_urgent_help"), messageKey: "lave_" + this._hold + "_briefing_yes", screenID:"lave_missions"});
                    }
                    if (choice == "02_NO") {
                        this._missionStatus[lm._hold] = "SKIPPED";
                        mission.runScreen({ title: expandMissionText("lave_missions_urgent_help"), messageKey: "lave_" + this._hold + "_briefing_no", screenID:"lave_missions"});
                    }
                });
            delete missionVariables.LaveMission3_RockHermitSummary;
        }
    }
}
//-------------------------------------------------------------------------------------------------------------
this.$availableMission = function() {
    var avail = "";
    var missions = Object.keys(this._missionStatus);
    var finishedTypes = ["SKIPPED", "FINISHED", "NOT_STARTED"];
    for (var i = 0; i < missions.length; i++) {
        if (this._missionStatus[missions[i]] == "NOT_STARTED" && avail == "") avail = missions[i];
        // if we're part way through a mission, always return "NONE"
        if (finishedTypes.indexOf(this._missionStatus[missions[i]]) == -1) {avail = "NONE"; break; }
    }
    if (avail == "") avail = "NONE";
    return avail;
}
//-------------------------------------------------------------------------------------------------------------
this.$rhSummary = function() {
    var text = "";
    var rhlist = [].concat(system.shipsWithRole("rockhermit")).concat(system.shipsWithRole("rockhermit-chaotic")).concat(system.shipsWithRole("rockhermit-pirate"));
    if (rhlist.length == 1) text = expandMissionText("lave_mission_rockhermits_one");
    if (rhlist.length == 2) text = expandMissionText("lave_mission_rockhermits_two");
    if (rhlist.length > 2) text = expandMissionText("lave_mission_rockhermits_three");
    if (rhlist.length > 3) text += expandMissionText("lavel_mission_rockhermits_more");
    return text;
} | 
                
                    | Scripts/lave_populator.js | "use strict";
this.name = "lave_populator";
this.author = "phkb";
this.copyright = "2024 phkb";
this.description = "Makeover for the Lave System in Chart One";
this.license = "CC-BY-NC-SA 4.0";
//-------------------------------------------------------------------------------------------------------------
this.startUp = function() {
    this.blockSystemRedux();
	if (worldScripts["Famous Planets Overhaul"]) {
		// we want to keep our texture for the planet
		var fpo = worldScripts["Famous Planets Overhaul"];
		var idx = fpo.planetList[0].indexOf(7);
		fpo.planetList.splice(idx, 1);
	}
	var pf = worldScripts.PlanetFall2;
	if (!pf) return;
    pf._locationOverrides["0 7"] = {
        main: [
            {
                roles: ["capitalCity", "capitalCity", "leisureComplex", "factory"],
                names: expandDescription("[lave_pf_city_names]").split("|"),
            },
        ],
        moon: [
            {
                roles: ["colonyDome"],
                names: [expandDescription("[lave_pf_moon_city_name]")],
            }
        ],
    };
}
//-------------------------------------------------------------------------------------------------------------
this.startUpComplete = function() {
    // make sure our texture wins any races to be the last texture installed
    var info = System.infoForSystem(0, 7);
    info.texture = "lave_planet_diffuse.png";
}
//-------------------------------------------------------------------------------------------------------------
this.systemWillPopulate = function() {
    if (galaxyNumber == 0 && system.ID == 7) {
        var mn = system.addMoon("murgh_moon_lave");
        if (worldScripts.PlanetFall2) {
            var pf = worldScripts.PlanetFall2;
            pf.$addExtraPlanetDocksForPlanet(mn);
        }
        var pl;
        if (system.countShipsWithRole("liner") < 1) {
            pl = Vector3D(14000, 50720, 34350).fromCoordinateSystem("pwm");
            system.addShips("lave_liner", 1, pl);
        }
        if (system.countShipsWithRole("junk") < 1) {
            pl = Vector3D(18730, 62700, 2500).fromCoordinateSystem("pwm");
            system.addShips("junk", 1, pl);
        }
        if (system.countShipsWithRole("junk1") < 1) {
            pl = Vector3D(16650, 70000, 17700).fromCoordinateSystem("pwm");
            system.addShips("junk1", 1, pl);
        }
        if (system.countShipsWithRole("eatcobra") < 1) {
            pl = Vector3D(31410, 71830, 20120).fromCoordinateSystem("pwm");
            system.addShips("eatcobra", 1, pl);
        }
        if (system.countShipsWithRole("bugtran") < 1) {
            pl = Vector3D(13935, 41730, 14230).fromCoordinateSystem("pwm");
            system.addShips("bugtran", 1, pl);
        }
        if (system.countShipsWithRole("ophidianpt") < 1) {
            pl = Vector3D(18935, 41730, 14230).fromCoordinateSystem("pwm");
            system.addShips("ophidianpt", 1, pl);
        }
        if (system.countShipsWithRole("trainee") < 3) {
            pl = Vector3D(16585, 59787, 20280).fromCoordinateSystem("pwm");
            system.addShips("trainee", 3, pl, 2000);
        }
        if (system.countShipsWithRole("instructor") < 1) {
            pl = Vector3D(16585, 59787, 20280).fromCoordinateSystem("pwm");
            system.addShips("instructor", 1, pl, 2000);
        }
        if (system.countShipsWithRole("lave_add1") < 1) {
            pl = Vector3D(18015, 66700, 22486).fromCoordinateSystem("pwm");
            system.addShips("lave_add1", 1, pl, 10000);
        }
        if (system.countShipsWithRole("lave_add2") < 1) {
            pl = Vector3D(18015, 66700, 22486).fromCoordinateSystem("pwm");
            system.addShips("lave_add2", 1, pl, 10000);
        }
        if (system.countShipsWithRole("lave_add3") < 1) {
            pl = Vector3D(18015, 66700, 22486).fromCoordinateSystem("pwm");
            system.addShips("lave_add3", 1, pl, 10000);
        }
        if (system.countShipsWithRole("lave_add4") < 1) {
            pl = Vector3D(18015, 66700, 22486).fromCoordinateSystem("pwm");
            system.addShips("lave_add4", 1, pl, 10000);
        }
    }
}
//-------------------------------------------------------------------------------------------------------------
this.blockSystemRedux = function () {
	if (worldScripts["System Redux"]) {
		var sr = worldScripts["System Redux"];
		// make sure system redux startup script has been run before we try to add moon exclusions
		if (!sr.excl) {
			sr.startUp();
		}
		delete sr.startUp;
		if (sr.excl[0].indexOf(7) == -1) sr.excl[0].push(7);
	}
}
 |