| Scripts/tianve-liner-script.js | "use strict";
/*
tianve-line-script.js
Ship script for Tianve Pulsar Liners.
Oolite - Copyright © 2009 Giles C Williams and contributors
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
Tianve.oxp - Copyright © 2009 Drew Wagar
This work is licensed under the Creative Commons
Attribution-Noncommercial-Share Alike 3.0 Unported License.
To view a copy of this license, visit
http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter
to Creative Commons, 171 Second Street, Suite 300, San Francisco,
California, 94105, USA.
*/
this.name = "tianve-liner-script";
this.author = "phkb";
this.copyright = "© 2023 phkb";
this.license = "CC-by-nc-sa 3.0";
this.linerAIPulsar = function() {
    var pws = worldScripts["oolite-tianve"];
    this.ship.destination = pws._posVE;
}
this.linerAIPoint1 = function () {
    var pws = worldScripts["oolite-tianve"];
    this.ship.destination = Vector3D(pws._pulsarPosPWM[0], pws._pulsarPosPWM[1], pws._pulsarPosPWM[2] - 160500).fromCoordinateSystem("pwm");
}
this.linerAIPoint2 = function () {
    var pws = worldScripts["oolite-tianve"];
    this.ship.destination = Vector3D(pws._pulsarPosPWM[0] - 159800, pws._pulsarPosPWM[1], pws._pulsarPosPWM[2]).fromCoordinateSystem("pwm");
}
this.linerAIPoint3 = function () {
    var pws = worldScripts["oolite-tianve"];
    this.ship.destination = Vector3D(pws._pulsarPosPWM[0], pws._pulsarPosPWM[1], pws._pulsarPosPWM[2] + 159800).fromCoordinateSystem("pwm");
}
this.linerAIPoint4 = function () {
    var pws = worldScripts["oolite-tianve"];
    this.ship.destination = Vector3D(pws._pulsarPosPWM[0] + 159800, pws._pulsarPosPWM[1], pws._pulsarPosPWM[2]).fromCoordinateSystem("pwm");
}
 | 
                
                    | Scripts/tianve-newcargoes.js | "use strict";
this.author = "cim";
this.copyright = "© 2011-2014 cim.";
this.license = "CC-BY-SA 3.0";
this.name = "CargoTypeExtension-Station-TianvePulsarStation";
this.description = "Tianve Pulsar Station market definition";
this.startUp = function () {
	if (!worldScripts.CargoTypeExtension) {
		for (var prop in this) {
			if (prop !== 'name' && prop !== 'version' && prop !== "oolite_manifest_identifier") {
				delete this[prop];
			}
		}
		return;
	}
	else {
		worldScripts["CargoTypeExtension"].registerOXPStation(this.name, "tianve-pulsar-station");
		this.$registerNewCargoTypes();
	}
}
this.$registerNewCargoTypes = function () {
	var obj = new Object;
	obj.ID = "TP-LW1";
	obj.genericType = "liquor_wines";
	obj.specificType = "Pulsar Padlamanggan";
	obj.buySystems = [[246], [], [], [], [], [], [], []];
	obj.sellSystems = [[], [], [], [], [], [], [], []];
	obj.desc = "Locally distilled under the concentrated light of the pulsar, this exotic liqueur is created in our dedicated distillery from the most exquisitely macerated mangoes from tropical Tianve.";
	worldScripts["CargoTypeExtension"].registerCargoType(obj);
}
/* Station API */
this.randomCargoChance = function (good) {
	var generic = worldScripts["CargoTypeExtension"].cargoDefinition(good, "genericType");
	if (generic == "luxuries") {
		return 0.75;
	}
	return 0;
}
this.randomCargoAmount = function (good) {
	return 3;
}
this.exportCargoAmount = function (good) {
	var generic = worldScripts["CargoTypeExtension"].cargoDefinition(good, "genericType");
	if (good == "CTE_CTS_O4" || good == "CTE_CTS_R1" || good == "CTE_CTA_O1" || good == "CTE_CTS_IS1" || good == "TP-LW1") return 2;
	return 0;
}
this.exportCargoPrice = function (good) {
	return 0.9 + (Math.random() * 0.2);
}
this.randomImportChance = function (good) {
	return 0;
}
this.systemImportChance = function (good) {
	var generic = worldScripts["CargoTypeExtension"].cargoDefinition(good, "genericType");
	if (generic == "food" || generic == "liquor_wines" || generic == "luxuries") {
		return 1;
	} else {
		return 0;
	}
}
this.importCargoPrice = function (good) {
	return 0.9 + (Math.random() * 0.2);
}
// they have police patrol ships, so they probably obey Galcop rules here
this.importPermitCheck = function () {
	return true;
}
this.exportPermitCheck = function () {
	return true;
}
this.stationGossip = function () {
	return false;
}
 | 
                
                    | Scripts/tianve-populator.js | "use strict";
this.name = "oolite-tianve";
this.author = "Drew Wagar and Contributions by Commander McLane and phkb";
this.copyright = "© 2009 Drew Wagar.";
this.description = "Makeover for the Tianve Star System in Chart One";
this.license = "CC-by-nc-sa 3.0";
this._pulsarPosPWM = [-537000, 138000, 1011250];
this._pulsarStnPWM = [];
// todo
// 3. rotate the pulsar?
// 4. add ships to shiplibrary.plist
// 5. new cargoes specialties
this._posVE;
this._posStn;
this._massLocker = null;
this._always = false; // used for debugging only
// OXP link note:
// To relocate the pulsar, change the "this._pulsarPosPWM" values during startUp function
//-------------------------------------------------------------------------------------------------------------
this.startUp = function() {
	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(246);
		fpo.planetList.splice(idx, 1);
	}
	var pf = worldScripts.PlanetFall2;
	if (!pf) return;
    pf._locationOverrides["0 246"] = {
        main: [
            {
                roles: ["capitalCity", "capitalCity", "capitalCity", "leisureComplex", "leisureComplex", "factory"],
                names: ["Tianvilus (Capital City)", "Wagarville (City)", "Drewston (City)",  "Pillars of Tiaxus (Xootian Desert)", "Mount Aliothn (Leisure Complex)", "Acid Lake City (Factory)"],
            },
        ],
    };
}
//-------------------------------------------------------------------------------------------------------------
this.startUpComplete = function () {
	var vx = worldScripts.VimanaX_HUD;
	if (vx) {
		// update vimana to use a different model to the original
		vx._gameShips["Tianve Pulsar Monitoring Station"] = "octahedron";
		vx._gameShips["The Pulsar Monitoring Station"] = "octahedron";
		vx._gameShips["Vampire Mk1.5 : Rebecca Weston"] = "vampiremk1";
		vx._gameShips["Tianve Billboard"] = "billboard";
		vx._gameShips["Tourist StarLiner - 'Join us next time, Commander!'"] = "boa_cruiser";
		vx._gameShips["Tourist StarLiner - 'Seats Available, Commander!'"] = "boa_cruiser";
	}
    // make sure our texture wins any races to be the last texture installed
    var info = System.infoForSystem(0, 246);
    info.texture = "tianve_planet.png";
}
//-------------------------------------------------------------------------------------------------------------
this.turnStationToEntity = function (station, entity) {
	var targetVector = entity.position.subtract(station.position).direction();
	station.orientation = targetVector.rotationTo([0, 0, 1]);
}
//-------------------------------------------------------------------------------------------------------------
this.systemWillPopulate = function () {
	this._posVE = null;
	this._posStn = null;
	if (galaxyNumber === 0 && system.ID === 246 || this._always == true) {
		this._pulsarStnPWM.push(this._pulsarPosPWM[0] + 9000);
		this._pulsarStnPWM.push(this._pulsarPosPWM[1] - 500);
		this._pulsarStnPWM.push(this._pulsarPosPWM[2] - 192250);
		this._posStn = Vector3D(this._pulsarStnPWM).fromCoordinateSystem("pwm");
		system.setPopulator("tianve_pulsar_station", {
			callback: function (pos) {
				var pws = worldScripts["oolite-tianve"];
				var pl = Vector3D(pws._pulsarPosPWM).fromCoordinateSystem("pwm");
				pws._posVE = pl;
				var ve = system.addVisualEffect("tianve_pulsar_flashers", pws._posVE);
				ve.orientation = system.mainPlanet.orientation;
				
				var stn = system.addShips("[tianve-pulsar-station]", 1, pos, 0)[0];
				worldScripts["oolite-tianve"].turnStationToEntity(stn, ve);
				// get the main station position as a pwm value
				var msp = Vector3D(system.mainStation.position).toCoordinateSystem("pwm");
				
				// at the main station
				system.addShips("tianve-liner-moving", 1, Vector3D.interpolate(system.mainStation, stn, 0.01));
				system.addShips("tianve-small-billboard-01", 1, Vector3D(msp[0] - 8550, msp[1] - 8500, msp[2] - 3000).fromCoordinateSystem("pwm"));
				system.addShips("tianve-liner-motionless", 1, Vector3D(msp[0] - 7000, msp[1] - 8000, msp[2] - 3000).fromCoordinateSystem("pwm"));
				// At the Witchpoint Marker
				system.addShips("tianve-small-billboard-01", 1, Vector3D(-2500, 2500, 442500).fromCoordinateSystem("pwm"));
				system.addShips("tianve-liner-moving", 1, Vector3D(-3500, 3500, 442500).fromCoordinateSystem("pwm"));
				// Halfway between the Main Station and the Pulsar
				system.addShips("tianve-liner-moving", 1, Vector3D.interpolate(system.mainStation, stn, 0.5));
				system.addShips("tianve-small-billboard-02", 1, Vector3D.interpolate(system.mainStation, stn, 0.5));
				// At the Pulsar
				system.addShips("tianve-liner-moving", 2, pos, 10000);
				system.addShips("tianve-small-billboard-03", 1, Vector3D(pws._pulsarStnPWM[0] + 6500, pws._pulsarStnPWM[1], pws._pulsarStnPWM[2] - 11500).fromCoordinateSystem("pwm"));
				system.addShips("tianve-rebecca", 1, Vector3D(pws._pulsarStnPWM[0], pws._pulsarStnPWM[1] + 10000, pws._pulsarStnPWM[2]).fromCoordinateSystem("pwm"));
			},
			location: "COORDINATES",
			coordinates: this._posStn,
			deterministic: true
		});
	}
}
//-------------------------------------------------------------------------------------------------------------
this.shipLaunchedFromStation = function (launchStation) {
	if (launchStation == system.mainStation && system.ID == 246 && galaxyNumber == 0) {
		launchStation.commsMessage("Don't forget to visit the Pulsar whilst you're here, Commander!", player.ship);
	}
	this.$startTimer();
}
//-------------------------------------------------------------------------------------------------------------
this.shipExitedWitchspace = function () {
	this.$startTimer();
	if (system.ID == 246 && galaxyNumber == 0) {
		var b = system.shipsWithPrimaryRole("buoy-witchpoint")[0];
		if (b) {
			b.commsMessage("Welcome to %H! To visit the Pulsar, select 'P' on your advanced space compass, Commander!", player.ship);
		}
	}
}
//-------------------------------------------------------------------------------------------------------------
this.playerBoughtEquipment = function (equipmentKey) {
	if (equipmentKey === "EQ_TIANVE_STICKER") {
		mission.setInstructionsKey("tianve_sticker");
		player.ship.removeEquipment("EQ_TIANVE_STICKER");
	}
}
//-------------------------------------------------------------------------------------------------------------
this.$startTimer = function() {
	if (this._timer && this._timer.isRunning) this._timer.stop();
	if (this._posVE) {
		this._timer = new Timer(this, this.$checkPosition, 0.5, 0.5);
	}
}
//-------------------------------------------------------------------------------------------------------------
this.$checkPosition = function $checkPosition() {
	if (!this._posVE) {
		this._timer.stop();
		return;
	}
	var p = player.ship;
	var dist = p.position.distanceTo(this._posVE);
	if (dist < 159200) {
		p.temperature += 0.05;
	}
	if (dist < 160000 && !this.masslocker) {
		this.masslocker = system.addShips("tianve-masslocker", 1, player.ship.position.add(player.ship.vectorUp.multiply(300)))[0];
	}
	if (dist >= 160000 && this.masslocker) {
		this.masslocker.remove(true);
		this.masslocker = null;
	}
}
 | 
                
                    | Scripts/tianve-rebecca-script.js | "use strict";
/*
tianve-rebecca-script.js
Ship script for Rebecca Weston.
Oolite - Copyright © 2009 Giles C Williams and contributors
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
Tianve.oxp - Copyright © 2009 Drew Wagar
This work is licensed under the Creative Commons
Attribution-Noncommercial-Share Alike 3.0 Unported License.
To view a copy of this license, visit
http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter
to Creative Commons, 171 Second Street, Suite 300, San Francisco,
California, 94105, USA.
*/
this.name = "tianve-rebecca-script";
this.author = "Commander McLane";
this.copyright = "© 2009 Drew Wagar";
this.license = "CC-by-nc-sa 3.0";
this.shipSpawned = function () {
	// sets primary role to "hunter", to make it accept distress calls
	this.ship.primaryRole = "hunter";
	/*	
		// establishes the station group of the monitoring station
		var pulsarStationGroup = system.shipsWithRole("tianve-pulsar-station", this.ship)[0].group;
	
		// adds Rebecca to the station group
		pulsarStationGroup.addShip(this.ship);
	
		// and makes her aware of that
		this.ship.group = pulsarStationGroup;
	*/
	// starts a timer that periodically looks for the player
	// the timer looks every ten seconds (second number)
	this.scanForPlayerTimer = new Timer(this, this.scanForPlayer, 0, 10);
}
this.scanForPlayer = function () {
	//  when having the player in scanner range for the first time ...
	if (this.ship.position.distanceTo(player.ship.position) < 25600) {
		this.$updatePAD();
		// ... a message is sent ...
		this.ship.commsMessage("So it's Commander " + expandDescription("[commander_name]") + ", eh? I've heard of you. Just behave yourself around here, or else!");
		// ... and the timer is stopped
		this.scanForPlayerTimer.stop();
	}
}
this.playerWillEnterWitchspace = this.shipDied = function () {
	// if the ship suffers an existence failure, either by dying or by the player leaving the system,
	// the timer is stopped and removed
	this.scanForPlayerTimer.stop();
	delete this.scanForPlayerTimer;
}
this.rebeccaAIPoint1 = function() {
	//-518000 137500 979000
	var pws = worldScripts["oolite-tianve"];
	this.ship.destination = Vector3D(pws._pulsarStnPWM[0] + 10000, pws._pulsarStnPWM[1], pws._pulsarStnPWM[2]).fromCoordinateSystem("pwm");
}
this.rebeccaAIPoint2 = function() {
	//-538000 137500 979000
	var pws = worldScripts["oolite-tianve"];
	this.ship.destination = Vector3D(pws._pulsarStnPWM[0] - 10000, pws._pulsarStnPWM[1], pws._pulsarStnPWM[2]).fromCoordinateSystem("pwm");
}
this.rebeccaAIPoint3 = function() {
	//-528000 147500 979000
	var pws = worldScripts["oolite-tianve"];
	this.ship.destination = Vector3D(pws._pulsarStnPWM[0], pws._pulsarStnPWM[1] + 10000, pws._pulsarStnPWM[2]).fromCoordinateSystem("pwm");
}
this.rebeccaAIPoint4 = function() {
	//-528000 127500 979000
	var pws = worldScripts["oolite-tianve"];
	this.ship.destination = Vector3D(pws._pulsarStnPWM[0], pws._pulsarStnPWM[1] - 10000, pws._pulsarStnPWM[2]).fromCoordinateSystem("pwm");
}
this.rebeccaAIPoint5 = function() {
	//-528000 137500 989000
	var pws = worldScripts["oolite-tianve"];
	this.ship.destination = Vector3D(pws._pulsarStnPWM[0], pws._pulsarStnPWM[1], pws._pulsarStnPWM[2] + 10000).fromCoordinateSystem("pwm");
}
this.rebeccaAIPoint6 = function() {
	//-528000 137500 969000
	var pws = worldScripts["oolite-tianve"];
	this.ship.destination = Vector3D(pws._pulsarStnPWM[0], pws._pulsarStnPWM[1], pws._pulsarStnPWM[2] - 10000).fromCoordinateSystem("pwm");
}
//-------------------------------------------------------------------------------------------------------------
this.$updatePAD = function () {
    // add our dead officer to PAD
    var pad = worldScripts.Lib_PAD;
    pad._addPageInCategory(
        "PERSONS.REBECCA WESTON",
        {
            name: "Rebecca Weston",
            origin: "Tianve",
            species: "Human",
            gender: "Female",
            age: 26,
            ship: "Vampire Mk1.5",
            rank: "",
            t0: 0,
            t1: "rebecca_weston.png",
            t2: 0,
            info: []
        },
        ["PERSONS.GENERIC"],
        false
    );
	var infoLines = expandDescription("[rebecca_weston_info]").split("\n");
	var i = infoLines.length;
	while (i--) {
		worldScripts.Lib_PAD._setPageEntry("PERSONS.REBECCA WESTON.info", infoLines[i]);
	}
}
 |