Back to Index Page generated: Dec 20, 2024, 7:22:09 AM

Expansion buyable/sellable Yasen-N turrets.

Content

Manifest

from Expansion Manager's OXP list from Expansion Manifest
Description Adds an upgrade path for the basic Yasen-N class ship by making the turret a buyable/sellable equipment. (Needs the Mimoriarty's RL ships and Shipstoragehelper Adds an upgrade path for the basic Yasen-N class ship by making the turret a buyable/sellable equipment. (Needs the Mimoriarty's RL ships and Shipstoragehelper
Identifier oolite.oxp.amah.noshaders_Mimoriarty_rl_yasenturret_upgrade oolite.oxp.amah.noshaders_Mimoriarty_rl_yasenturret_upgrade
Title buyable/sellable Yasen-N turrets. buyable/sellable Yasen-N turrets.
Category Equipment Equipment
Author phkb, Michael -Amah- Doering phkb, Michael -Amah- Doering
Version 0.6 0.6
Tags ships ships
Required Oolite Version
Maximum Oolite Version
Required Expansions
Optional Expansions
Conflict Expansions
Information URL http://wiki.alioth.net/index.php/No_Shaders_alternate_or_extra_ships_and_accessories n/a
Download URL https://wiki.alioth.net/img_auth.php/1/13/Oolite.oxp.amah.noshaders_Mimoriarty_rl_yasenturret_upgrade.oxz n/a
License CC-BY-NC-SA 4.0 CC-BY-NC-SA 4.0
File Size n/a
Upload date 1610873237

Documentation

Also read http://wiki.alioth.net/index.php/buyable/sellable%20Yasen-N%20turrets.

readme/


        

readme/Changelog.txt

Buyable/sellable Turret for MiMoriaty Yasen N Advanced


v0.1			based on phkb's briliant shiprespray, needs ship storage helper
			adapted, messed up and mutilated for making turrets buyable by Amah
v0.2			fixed bug eating up credits when selling turret
v0.3			reduced price for the turret
v0.4			cleaned up, text updates, disabled cheating the turret setup with shiprespray.
v0.5			fixed bug when using phkb ship configuration and large cargobay
v0.5			fixed forgetting to change shipclass when buying/selling a turret

Needs: Radical Logistics ships & Shipstorage helper installed.

License: CC-SA-40

readme/shiprespray_readme.txt

Ship Respray 1.1.0
by Nick Rogers

About this OXP
==============
This OXP provides a way to quickly switch the style of your ship, using whatever OXP player templates you have installed of the same class type. That is, if you are flying a Cobra Mark III, and you have Z_Groovy's Variety Packs installed, you can quickly and easily give your ship a new paint job, without having to mess about in the save game file.

There are a couple of variations for the Cobra Mark III, Cobra Mark I and the Python that come with Oolite by default, but not that many. For this OXP to do something really useful you need to have some extra ship OXP's installed. For instance:
	http://wiki.alioth.net/index.php/Griff_Industries
	http://wiki.alioth.net/index.php/Staer9%27s_Shipset
	http://wiki.alioth.net/index.php/No_Shaders_alternate_or_extra_ships_and_accessories#Dertien.27s_Griff_repaint_Variety
	http://wiki.alioth.net/index.php/Deepspace_Ships
You can get a lot of additional shipsets from the download manager inside Oolite.
	
Once this OXP is installed a menu will appear on the ship outfitting screen, labelled "Ship Respray". When you select this, a new screen will appear, listing all the available resprays for your ship. Select one of these, and you can then see what the respray will look like on your ship. Some ship models use the "entityPersonality" to adjust the look of the ship. You can select a random personality by selecting "Change personality". 

Once you have selected a model, and found a personality look-and-feel you like, to go ahead with the paint job select "Purchase this respray" from the menu. The amount of time it will take to do the respray is showing on the menu item, and can be anywhere from 24 to 60 hours, depending on the size of the vessel.

This OXP uses the ShipStorageHelper to update the players ship to the selected model.

This OXP is slightly different to the "Respray for Griffs" OXP by Capt Murphy, as this will work with OXP's other than Griffs, and in no-shader mode.

Licence
=======
This work is licensed under the Creative Commons Attribution-Noncommercial-Share Alike 4.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/4.0/

Image from https://icons8.com/

Version History
===============
1.2.0
- Added overlay background image to initial interface screen.

1.1.3
- Added a missing semi-colon in the manifest file.
- Added routine to use 1.83/4 code to check for big GUI HUD's.

1.1.2
- Fixed shipdata.plist entries for alternate Cobra Mk3's having reduced max speed and thrust.

1.1.1
- Added check for "allo_big_gui" HUD's

1.1.0
- Added menu option to turn on/off view of ship data keys
- Improvements to the auto selection of menu items.

1.0.3 
- Removed ship keys from screen interfaces

1.0.2
- Added some extra shipdata.plist and shipyard.plist entries so the player can choose from the built-in variations of the Cobra Mk III, Cobra Mk I, and the Python.
- Fixed a bug where the current page index was not being reset when opening the respray interface.

1.0.1
- For Oolite 1.82 and later, added an "installation_time" of 1 second to the equipment item, so opening the respray screen doesn't take any time.
- For Oolite 1.80, changed the cost of the equipment item to zero, so only 10 minutes of time is taken up when opening the initial page.
- Added a mass-based installation time calculation to the end of the process. So, respraying a Boa takes longer than respraying an Adder.
- The "Purchase this respray" option now also includes the installation time.
- Fixed a bug where doing a respray, buying a new ship and doing another respray could end up with a confused menu.
- Code cleanup

1.0.0
- Initial release

Equipment

Name Visible Cost [deci-credits] Tech-Level
Yasen-N Turret yes 0 13+
sell Yasen-N Turret yes 0 13+

Ships

This expansion declares no ships.

Models

This expansion declares no models.

Scripts

Path
Scripts/yasenturret-buysell.js
"use strict";
this.name        = "yasenturret-buysell";
this.author      = "phkb, adapted for yasen-n Amah";
this.copyright   = "2015 phkb";
this.description = "Allows user buy/sell a turret for the yasen-N";
this.licence     = "CC BY-NC-SA 4.0";

this._yasenshiptype = "yasen-n-adv";	// the shiptype to up/dowgrade
this._yasenshipname = "Yasen-N 'Advanced'";	// the shiptype to up/dowgrade
this._data = [];			// storage array of ship data keys
this._selectedItem = "";		// currently selected item from the main list
this._selectedIndex = 0;		// index of the currently selected item
this._personality = 0;			// current entityPersonality setting
this._displayType = 0;			// respray gui display mode 0 = main list, 1 = selected item
this._lastchoice = null;		// last item chosen from the list
this._curpage = 0;				// current page being shown
this._pagesize = 16;			// max number of entries on a page
this._lastsubchoice = "";		// last item chosen from the selected item display
this._showDetails = false;		// when on, displays the datakey on the list and on the selected item page
this._baseTime = 48;			// base time, using cobra mk3 as a reference
this._bigGuiHUD = ["XenonHUD.plist"]; 	// until there is a property we can check, I'll be listing HUD's that have the allow_big_gui property set here


//-------------------------------------------------------------------------------------------------------------
this.playerBoughtEquipment = function(equipment) {

	var buy = false;
	var sell = false;

	if (equipment == "EQ_YASEN-TURRET") {
		player.ship.removeEquipment("EQ_YASEN-TURRET");
		// for 1.82 and later, refund the credits at this point - if the player buys the respray it will be deducted later
		//player.credits += 1; //refund
		this._yasenshiptype = "yasen-n-adv";
		this._yasenshipname = "Yasen-N 'Advanced'";
		buy = true; 
		}

	if (equipment == "EQ_YASEN-TURRET_REMOVE") {
		player.ship.removeEquipment("EQ_YASEN-TURRET_REMOVE");
		// for 1.82 and later, refund the credits at this point - if the player buys the respray it will be deducted later
		//player.credits += 1; //refund
		this._yasenshiptype = "yasen-n";
		this._yasenshipname = "Yasen-N";
		sell = true;
		}

	if (buy == true || sell == true) {
		this.$compileData();
		// pick a random personality to start with
		this._personality = this.$rand(32768) - 1;
		// reset the menu before displaying
		this._displayType = 0;
		this._curpage = 0;
		this._selectedItem = "";
		this._selectedIndex = 0;
		this.$showPage();
	}
}

//-------------------------------------------------------------------------------------------------------------
// get a list of all datakeys avaiable for the players current ship class type (ie. "Cobra Mark III")
this.$compileData = function() {

	this._data = [];

	// get a list of all ship keys that have a role of "player" (ie. these are playable ships, not NPC ships)
	var shipKeys = Ship.keysForRole(this._yasenshiptype);
	var freq = "";
	// loop through the list
	for (var i = 0; i < shipKeys.length; i++) {
		// get the shipdata entry for this key
		var shipdata = Ship.shipDataForKey(shipKeys[i]);

		// add it to the array if it's not there already
		if (this.$itemIsInArray(shipKeys[i], this._data) == false) {
			this._data.push(shipKeys[i]);
		}
	}
	// sort the array (basic alpha sort)
	this._data.sort();

}

//-------------------------------------------------------------------------------------------------------------
this.playerBoughtNewShip = function(ship, price) {
	// recompile the list whenever the player buys a new ship
	this.$compileData();
}

//=============================================================================================================
// screen interfaces

//-------------------------------------------------------------------------------------------------------------
this.$showPage = function() {

	var curChoices = {};

	if (this.$isBigGuiActive() == true) {
		this._pagesize = 23;
	} else {
		this._pagesize = 16;
	}

	if (this._displayType == 0) {

		var min = (this._curpage * this._pagesize);
		var max = this._curpage * this._pagesize + this._pagesize;
		if (max >= this._data.length) max = this._data.length;

		for (var i = min; i < max; i++) {
		 if (this._yasenshiptype == "yasen-n-adv") {
			curChoices["01_ITEM_" + (i < 10 ? "0" : "") + i + "~" + this._data[i]] = {text:player.ship.shipClassName + " Advanced turret setup "+ (i + 1).toString() +
			(this._showDetails == true ? " (" + this._data[i] + ")" : ""), color:"orangeColor", alignment:"LEFT"};
		 } else {
			curChoices["01_ITEM_" + (i < 10 ? "0" : "") + i + "~" + this._data[i]] = {text:player.ship.shipClassName + " - Basic model" +
			(this._showDetails == true ? " (" + this._data[i] + ")" : ""), color:"orangeColor", alignment:"LEFT"};
		 }
		}

		if (max - min < this._pagesize) {
			for (var i = (this._pagesize - (max - min)); i > 0; i--) {
				curChoices["02_SPACER_" + (i < 10 ? "0" : "") + i] = "";
			}
		}

		curChoices["99_EXIT"] = {text:"Exit", color:"yellowColor"};

		var def = "99_EXIT";
		if (this._yasenshiptype == "yasen-n-adv") {
			var opts = {
				screenID: "Turret Outfitter",
				title: "Arkadi's " + player.ship.shipClassName + " Turrets LTD.",
				allowInterrupt: true,
				//overlay: {name:"paint.png", height:546},
				exitScreen: "GUI_SCREEN_EQUIP_SHIP",
				choices: curChoices,
				initialChoicesKey: this._lastchoice?this._lastchoice:def,
				message: "Select a turret setup"
			};
		} else {
			var opts = {
				screenID: "Turret Outfitter",
				title: "Arkadi's " + player.ship.shipClassName + " Turrets LTD.",
				allowInterrupt: true,
				//overlay: {name:"paint.png", height:546},
				exitScreen: "GUI_SCREEN_EQUIP_SHIP",
				choices: curChoices,
				initialChoicesKey: this._lastchoice?this._lastchoice:def,
				message: "Remove turrets..."
			};
		}
	}

	if (this._displayType == 1) {

		var calc = Math.floor((player.ship.mass / 214737.6875) * this._baseTime);
		if (calc < 24) calc = 24;

		var def = "98_CLOSE";

		if (this._yasenshiptype == "yasen-n-adv") {
			if (player.credits > 99999) { // does the player have enough cash?
				curChoices["02_SELECT"] = {text:"Purchase this turret (100000 Cr, " + calc + " hours)", color:"yellowColor"};
			} else {
				curChoices["02_SELECT"] = {text:"Not enough money - You need 100000 Cr to purchase this turret", color:"darkGrayColor", unselectable:true};
			};
		} else {
			curChoices["02_SELECT"] = {text:"Sell the Turret ( 31337 Cr refund, " + calc + " hours)", color:"yellowColor"};
		}

		curChoices["98_CLOSE"] = {text:"Close", color:"yellowColor"};
		var opts = {
			screenID: "Turret outfitter",
			title: "Arkadi's " + player.ship.shipClassName + " Turrets LTD.",
			model:"[" + this._selectedItem + "]",
			modelPersonality: this._personality,
			allowInterrupt: true,
			choices: curChoices,
			initialChoicesKey: this._lastsubchoice?this._lastsubchoice:def,
			message: player.ship.shipClassName + " turret setup " + (this._selectedIndex + 1).toString() + (this._showDetails == true ? " (" + this._selectedItem + ")" : "")
		};

	}
	mission.runScreen(opts, this.$selectScreenHandler, this);

}

//-------------------------------------------------------------------------------------------------------------
this.$selectScreenHandler = function(choice) {

	if (choice.indexOf("~") >= 0) {
		this._displayType = 1;
		this._selectedItem = choice.substring(choice.indexOf("~") + 1);
		this._selectedIndex = parseInt(choice.substring(8, 10));
		this._lastchoice = choice;
		this._lastsubchoice = null;

	} else if (choice == "02_SELECT") {
		// need code to recreate player ship, transferring all cargo and equipment
		this.$addturretShip(this._selectedItem, this._personality);
		choice = "99_EXIT";
	} else if (choice == "96_PREV") {
		this._curpage -= 1;
		if (this._curpage > 0) {
			this._lastchoice = choice;
		} else {
			this._lastchoice = "97_NEXT";
		}
	} else if (choice == "98_CLOSE") {
		this._displayType = 0;
	}

	if (choice != "99_EXIT") {
		this.$showPage();
	}
}

//-------------------------------------------------------------------------------------------------------------
// do the change, using ShipStorageHelper
this.$addturretShip = function(dataKey, personality) {

	var p = player.ship;
	var playershipname = p.shipUniqueName;

	var hud = p.hud;

	//Do we have a Largecargobay
	var largecargobay = p.canAwardEquipment("EQ_CARGO_BAY");

	// first, store all equipment and cargo the player might have
	var shipstr = worldScripts["Ship_Storage_Helper.js"].storeCurrentShip();

	// change the datakey to the new one
	var data = JSON.parse(shipstr);
	data[1] = dataKey; // apply the data key to the ship
	data[13] = personality; // apply the selected personality to the ship
	shipstr = JSON.stringify(data);

	// restore the players ship
	worldScripts["Ship_Storage_Helper.js"].restoreStoredShip(shipstr);

	// restore some things that the storage helper doesn't replace
	p.shipUniqueName = playershipname;
	p.shipClassName = this._yasenshipname;
	p.hud = hud;

	// email system is installed ?
	var w = worldScripts.EmailSystem;

	if (this._yasenshiptype == "yasen-n-adv") {
		// remove large cargo bay capacity if present
		if (!largecargobay){
			p.cargoSpaceCapacity = p.cargoSpaceCapacity-15;
			}

		// charge the player
		player.credits -= 100000;

		// send a buy email if the email system is installed
		if (w) {
			var ga = worldScripts.GalCopAdminServices;
			w.$createEmail({sender:expandDescription("[purchase-maintenance-sender]"),
				subject:"Your " + p.shipClassName + " Turret- setup",
				date:global.clock.seconds,
				message:expandDescription("[turretbuy_email]", {shipclass:p.shipClassName}),
				expiryDays:ga._defaultExpiryDays}
			);
		}

	} else {
		//refund player
		player.credits += 31337;	//a refund for 1337 captains

		// send a sell email if the email system is installed
		if (w) {
			var ga = worldScripts.GalCopAdminServices;
			w.$createEmail({sender:expandDescription("[purchase-maintenance-sender]"),
				subject:"Your " + p.shipClassName + " Turret removal",
				date:global.clock.seconds,
				message:expandDescription("[turretsell_email]", {shipclass:p.shipClassName}),
				expiryDays:ga._defaultExpiryDays}
			);
		}

	}


	// work out how much install time is required
	// using cobra mass as the benchmark
	var install = Math.floor((p.mass / 214737.6875) * this._baseTime);
	if (install < 24) install = 24;
	install = install * 60 * 60;

	global.clock.addSeconds(install);

	// if the station dock control is installed, tell it to check for launched ships
	if (worldScripts.StationDockControl) {
		var w = worldScripts.StationDockControl;
		if (w._disable == false) {
			w.$checkForLaunchedShips();
		}
	}

	this._displayType = 0;
	this._lastchoice = null;

}
//=============================================================================================================
// helper functions

//-------------------------------------------------------------------------------------------------------------
// return a random number between 1 and max
this.$rand = function(max) {
	return Math.floor((Math.random() * max) + 1)
}

//-------------------------------------------------------------------------------------------------------------
// checks if a given element is in the array
this.$itemIsInArray = function(element, array) {
	var found = false;
	if (array != null && array.length > 0) {
		for (var i = 0; i < array.length; i++) {
			if (array[i] == element) found = true;
		}
	}
	return found;
}

//-------------------------------------------------------------------------------------------------------------
// returns true if a HUD with allowBigGUI is enabled, otherwise false
this.$isBigGuiActive = function() {
	if (oolite.compareVersion("1.83") < 0) {
		return player.ship.hudAllowsBigGui;
	} else {
		if (this._bigGuiHUD.indexOf(player.ship.hud) >= 0) {
			return true;
		} else {
			return false;
		}
	}
}
Scripts/yasenturret-conditions.js
"use strict";

this.name		= "yasenturret-conditions";
this.author		= "amah";
this.copyright		= "This script is hereby placed in the public domain.";
this.version		= "1.0";


this.allowAwardEquipment = function(equipment, ship, context)
{
	if (context != "purchase") return false;
	return true;
}