| Scripts/lovecat.js | "use strict";
this.name = "wedding";
this.author = "johnsmith, JS translation by Eric Walch";
this.description = "Script used for the lovecats mission.";
this.version = "2.0";
// if the player has started Cataclysm, Curruthers has become a Rear Admiral
// so we'll tweak the rank in that case
this._rank = "Captain";
this.startUp = function () {
    if (missionVariables.wedding == "THE_END") {
        // mission is over, no need to evaluate any code anymore.
        this.$clearHandlers();
    }
    if (missionVariables.cataclysm) {
        this._rank = "Rear Admiral";
    }
	var vx = worldScripts.VimanaX_HUD;
	if (vx) {
		// update vimana to use a different model to the original
		vx._gameShips["Valrisian Hunters"] = "asp2";
		vx._gameShips["Valrisian's Hunters"] = "asp2";
		vx._gameShips["Valrisian Hunter"] = "asp2";
		vx._gameShips["Valrisian's Asp"] = "asp2";
	}
};
this.missionScreenOpportunity = function () {
    if (galaxyNumber != 3) return;
    var wedding = missionVariables.wedding;
    if (player.ship.dockedStation.isMainStation) {
        missionVariables.lovecats_rank = this._rank;
        if (system.ID > 142 && !wedding) {
            mission.runScreen({screenID:"lovecats", title: "Lovecat", messageKey: "wedding_quietword" });
            missionVariables.wedding = "STAGE199";
            missionVariables.wedding_started = "YES";
            mission.setInstructionsKey("wm1_short_desc0");
            mission.markSystem({system:141, name:"lovecats"});
        }
        if (system.ID == 141 && (wedding == "STAGE0" || wedding == "STAGE199")) {
            mission.unmarkSystem({system:141, name:"lovecats"});
            mission.runScreen({screenID:"lovecats", title: "Lovecat", messageKey: "wedding_first_briefing", choicesKey: "wedding_caruth_choice" },
                function (choice) {
                    if (choice == "WEDDING_YES") {
                        missionVariables.wedding = "STAGE1";
                        mission.setInstructionsKey("wm1_short_desc1");
                        mission.markSystem({system:149, name:"lovecats"});
                    }
                    if (choice == "WEDDING_NO") {
                        this.$missionEnded();
                    }
                });
            this.$addPadCharacter("felix");
        }
        if (system.ID > 142 && wedding == "STAGE1") {
            mission.runScreen({screenID:"lovecats", title: "Lovecat", messageKey: "wedding_news", overlay: "iNews.png" });
            missionVariables.wedding = "STAGE2";
        }
        if (system.ID == 149 && (wedding == "STAGE1" || wedding == "STAGE2")) {
            mission.unmarkSystem({system:149, name:"lovecats"});
            mission.setInstructionsKey(null); // needed here to avoid an string expansion problem in Oolite. Will be solved in Oolite 1.75.4
            mission.runScreen({screenID:"lovecats", title: "Lovecat", messageKey: "wedding_second_briefing", model: "lovecat_carlo" });
            var ship = mission.displayModel;
            ship.position = ship.position.multiply(4); // put a bit further away so it becomes smaller.
            missionVariables.wedding = "STAGE3";
            mission.setInstructionsKey("wm1_short_desc2");
            mission.markSystem({system:114, name:"lovecats"});
            this.$addPadCharacter("romeo");
            this.$addPadCharacter("oola");
        }
        if (system.ID == 16) {
            if (wedding == "DESTROYED") {
                mission.runScreen({screenID:"lovecats", title: "Lovecat", messageKey: "wedding_killed", overlay: "lovecats_Valrisian.png" });
                mission.setInstructionsKey(null);
                mission.unmarkSystem({system:16, name:"lovecats"});
                this.$missionEnded();
                player.bounty += 64;
                player.ship.manifest.narcotics += 1;
                player.ship.launch();
            }
            if (wedding == "CAPTURED") {
                mission.runScreen({screenID:"lovecats", title: "Lovecat", messageKey: "wedding_thanks_briefing", overlay: "lovecats_Valrisian.png" });
                missionVariables.wedding = "STAGE4";
                mission.setInstructionsKey(null);
                mission.unmarkSystem({system:16, name:"lovecats"});
                player.credits += 10000;
                // small hack to get the bounty system to do a full reset
                if (player.bounty == 0) player.bounty = 10;
                player.bounty = 0;
            }
        }
        if (system.ID > 17 && (wedding == "STAGE4" || wedding == "STAGE98")) { // Test for STAGE98 has historical reasons and could be in old save files.
            mission.runScreen({screenID:"lovecats", title: "Lovecat", messageKey: "wedding_oola", choicesKey: "wedding_oola_choice", overlay: "lovecats_heart.png" },
                function (choice) {
                    if (choice == "WEDDING_YES") {
                        missionVariables.wedding = "STAGE99";
                        mission.setInstructionsKey("wm1_short_desc6");
                        mission.markSystem({system:41, name:"lovecats"});
                    }
                    if (choice == "WEDDING_NO") {
                        this.$missionEnded();
                    }
                });
        }
        if (system.ID == 41 && wedding == "STAGE99") {
            mission.runScreen({screenID:"lovecats", title: "Lovecat", messageKey: "wedding_oola_thanks", overlay: "lovecats_heart.png" });
            missionVariables.wedding = "STAGE100";
            mission.setInstructionsKey(null);
            mission.unmarkSystem({system:41, name:"lovecats"});
            player.credits += 3209;
            player.score += 6;
            this.$addInfoToPadCharacter("romeo", "Married Oola Waad's sister.");
        }
        if ((system.ID == 16 || system.ID == 149) && wedding == "STAGE99") {
            mission.runScreen({screenID:"lovecats", title: "Lovecat", messageKey: "wedding_oola_betrayed", overlay: "lovecats_Valrisian.png" });
            missionVariables.wedding = "STAGE100";
            mission.setInstructionsKey(null);
            mission.unmarkSystem({system:41, name:"lovecats"});
            this.$addInfoToPadCharacter("romeo", "Married Oola Waad's sister.");
            this.$addInfoToPadCharacter("oola", "Sentenced to be executed on Teance.");
        }
        if (system.ID > 42 && wedding == "STAGE100") {
            mission.runScreen({screenID:"lovecats", title: "Lovecat", messageKey: "wedding_news2", overlay: "iNews.png" });
            this.$addInfoToPadCharacter("Assassinated " + (clock.days - 1) + ":23:02" + " on Teance.");
            this.$missionEnded();
        }
        if (this.nova_bug) {
            mission.runScreen({screenID:"lovecats", title: "Lovecat", messageKey: "nova_wedding_newsflash", overlay: {name:"solar.png", height:346} });
            this.nova_bug = false;
            if (wedding == "STAGE3" && (this.nova_bug_planet == 83 || this.nova_bug_planet == 114)) {
                mission.addMessageTextKey("nova_wedding_newsflash2");
            } else {
                this.$missionEnded(); // no solution left because of nova system.
            }
        }
        delete missionVariables.lovecats_rank;
    }
};
this.shipLaunchedFromStation = function () {
    if (galaxyNumber == 3) {
        this.$addShips();
    }
    delete this.shipLaunchedFromStation; // we only need this handler on the very first launch.
};
this.shipExitedWitchspace = function () {
    if (galaxyNumber != 3 || system.isInterstellarSpace) return;
    this.$addShips();
    if (!missionVariables.nova && missionVariables.wedding_started == "YES") {
        missionVariables.novacount = 0; // suppress the nova mission.
    }
    if (system.sun && system.sun.hasGoneNova && [16, 41, 83, 114, 141, 149].indexOf(system.ID) > -1) {
        // one of the mission systems is a nova system.
        this.nova_bug = true;
        this.nova_bug_planet = system.ID;
    }
};
this.guiScreenChanged = function () {
    if (galaxyNumber == 3 && player.ship.docked && player.ship.dockedStation.isMainStation && guiScreen == "GUI_SCREEN_SYSTEM_DATA") {
        if (system.ID == 114 && missionVariables.wedding == "STAGE3") {
            mission.addMessageTextKey("wedding_moved");
            mission.setInstructionsKey("wm1_short_desc4");
            mission.unmarkSystem({system:114, name:"lovecats"});
            mission.markSystem({system:83, name:"lovecats"});
        }
        if (system.ID == 83 && missionVariables.wedding == "STAGE3") {
            mission.addMessageTextKey("wedding_missed");
            mission.setInstructionsKey("wm1_short_desc4");
            mission.unmarkSystem({system:114, name:"lovecats"});
            mission.unmarkSystem({system:83, name:"lovecats"});
        }
    }
};
this.$addShips = function () {
    if (system.ID == 83 && missionVariables.wedding == "STAGE3") {
        var position = Vector3D(-0.02, 0, 0.11).fromCoordinateSystem("wpu");
        system.addShips("lovecat_carlo", 1, position);
        mission.setInstructionsKey("wm1_short_desc4");
    }
    if (system.ID == 41 && missionVariables.wedding == "STAGE99") {
        system.addShipsToRoute("cat_asp", 4, 0.01, "wp");
        system.addShipsToRoute("cat_asp2", 2, 0.01, "wp");
    }
    if (system.ID == 149 && missionVariables.conhunt == "MISSION_COMPLETE") {
        system.addShipsToRoute("cat_asp3", 4, 0.5, "wp");
    }
};
this.$missionEnded = function () {
    missionVariables.wedding = "THE_END";
    delete missionVariables.wedding_started;
    this.$clearHandlers();
};
this.$clearHandlers = function () {
    delete this.missionScreenOpportunity;
    delete this.shipLaunchedFromStation;
    delete this.shipExitedWitchspace;
    delete this.missionScreenOpportunity;
    delete this.guiScreenChanged;
};
//-------------------------------------------------------------------------------------------------------------
this.$addPadCharacter = function(person, info) {
    var pad = worldScripts.Lib_PAD;
	if (!pad) return;
	var dta = {};
	var cat = [];
    cat.push("PERSONS.GENERIC");
	switch (person) {
		case "romeo":
			dta.name = "Romeo Valrisian";
			dta.origin = "Teance";
			dta.species = "Feline";
			dta.gender = "Male";
			dta.age = 27;
			dta.ship = "Asp Mark II";
			dta.rank = "";
			dta.t0 = 0;
			dta.t1 = "lib_null.png";
			dta.t2 = 0;
			break;
        case "oola":
			dta.name = "Oola Waad";
			dta.origin = "Onzaenve";
			dta.species = "Feline";
			dta.gender = "Female";
			dta.age = 23;
			dta.ship = "Unknown";
			dta.rank = "";
			dta.t0 = 0;
			dta.t1 = "lib_null.png";
			dta.t2 = 0;
			break;
        case "felix":
			dta.name = "Felix Valrisian";
			dta.origin = "Teance";
			dta.species = "Feline";
			dta.gender = "Male";
			dta.age = 47;
			dta.ship = "Unknown";
			dta.rank = "Regent";
			dta.t0 = 0;
			dta.t1 = "lib_null.png";
			dta.t2 = 0;
			break;
    }
    dta.info = [];
    if (info) dta.info.push(info);
	var id = "PERSONS." + (dta.rank != "" ? dta.rank.toUpperCase() : dta.name.split(" ")[0]) + " " + dta.name.split(" ")[1].toUpperCase();
	pad._addPageInCategory(id, dta, cat, false);
}
//-------------------------------------------------------------------------------------------------------------
this.$addInfoToPadCharacter = function(person, text) {
    var pad = worldScripts.Lib_PAD;
	if (!pad) return;
    var id = "";
    switch (person) {
        case "romeo":
            id = "Romeo Valrisian".toUpperCase();
            break;
        case "oola":
            id = "Oola Waad".toUpperCase();
            break;
        case "felix":
            id = "Regent Valrisian".toUpperCase();
            break;
    }
    worldScripts.Lib_PAD._setPageEntry("PERSONS." + id + ".info", text);
} |