Scripts/erehwonMarket.js |
"use strict";
this.name = "erehwon_market";
this.author = "spara";
this.copyright = "2014 spara";
this.license = "CC BY-NC-SA 4.0";
this.$originalDefs = {
"food": [0, 0, 19, -2, 0, 0, 1, 0, 0],
"textiles": [0, 0, 20, -1, 0, 0, 3, 0, 0],
"radioactives": [0, 0, 42, -3, -3, 1, 7, 3, 0],
"slaves": [0, 0, 40, -5, 0, 0, 31, 0, 0],
"liquor_wines": [0, 0, 105, -5, 0, 0, 15, 0, 0],
"luxuries": [0, 0, 236, 8, 0, 0, 3, 0, 0],
"narcotics": [0, 0, 235, 29, 0, 0, 120, 0, 0],
"computers": [0, 0, 51, 14, 0, 0, 3, 0, 0],
"machinery": [0, 0, 117, 6, 0, 0, 7, 0, 0],
"alloys": [0, 0, 78, 1, 0, 0, 31, 0, 0],
"firearms": [0, 0, 32, 13, 0, 0, 7, 0, 0],
"furs": [0, 0, 36, -9, 0, 0, 63, 0, 0],
"minerals": [0, 0, 16, -1, -1, 85, 3, 3, 0],
"gold": [0, 0, 73 , -1, -1, 5, 7, 3, 1],
"platinum": [0, 0, 145, -2, -2, 6, 31, 7, 1],
"gem_stones": [0, 0, 25, -1, -1, 250, 15, 15, 2],
"alien_items": [0, 0, 22, 15, 0, 0, 7, 0, 0]
};
this.updateLocalCommodityDefinition = function(goodDefinition) {
var commodity = goodDefinition.key;
var oldDefs = this.$originalDefs[commodity];
//old style definition found for the good. calculate it the old way
if (oldDefs) {
var market_base_price = oldDefs[2];
var market_eco_adjust_price = oldDefs[3];
var market_eco_adjust_quantity = oldDefs[4];
var market_base_quantity = oldDefs[5];
var market_mask_price = oldDefs[6];
var market_mask_quantity = oldDefs[7];
var market_rnd = Math.floor(Math.random() * 256);
var economy = system.economy;
var price = (market_base_price + (market_rnd & market_mask_price) + (economy * market_eco_adjust_price)) & 255;
price *= 0.4;
var quantity = (market_base_quantity + (market_rnd & market_mask_quantity) - (economy * market_eco_adjust_quantity)) & 255;
if (quantity > 127) quantity = 0;
quantity &= 63;
goodDefinition.price = price * 10;
goodDefinition.quantity = quantity;
}
//no definition found. nullify the goods.
else {
goodDefinition.price = 0;
goodDefinition.quantity = 0;
}
return goodDefinition;
}
|
Scripts/erehwonMission.js |
"use strict";
this.name = "Tionisla Reporter";
this.author = "Eric Walch";
this.copyright = "2011-2012 Eric Walch";
this.description = "worldScript for the erehwon mission";
this.licence = "CC-by-NC-SA 3.0";
// Code adjusted by phkb to make Ewehwon appear in the same location any time the player misjumps between USLE and BIORLE
this._restoreIST = false;
//-------------------------------------------------------------------------------------------------------------
this.startUp = function (){
//this.misjumpInfo = "";
if (!missionVariables.erehwonReconnaissance) {
missionVariables.erehwonReconnaissance = "START";
missionVariables.erehwonFotoShot = "NO";
missionVariables.erehwonGotStory = "NO";
missionVariables.erehwomMisJumpInfo = "";
} else if (missionVariables.erehwonReconnaissance == "FINISHED") {
this.cleanUp();
}
}
//-------------------------------------------------------------------------------------------------------------
this.missionScreenOpportunity = function (){
if (!player.ship.docked || galaxyNumber != 0) return;
this.missionOffers();
}
//-------------------------------------------------------------------------------------------------------------
this.missionOffers = function (){
if (player.ship.dockedStation.isMainStation) {
if (system.ID == 124) {
if (missionVariables.erehwonReconnaissance == "START") {
mission.runScreen({
screenID:"tionisla_reporter",
title: "Tionisla Chronicle",
messageKey: "erehwonReconnaissance_briefing",
choicesKey: "erehwonReconnaissance_choice"
}, this.choiceEvaluation
);
}
if (missionVariables.erehwonReconnaissance == "SUCCESS") {
mission.runScreen({
screenID:"tionisla_reporter",
title: "Tionisla Chronicle",
messageKey: "erehwonReconnaissance_debriefing",
model: "erehwonStation"
}
);
mission.displayModel.orientation = [0.75, 0, -0.6, 0];
delete missionVariables.erehwonGotStory;
delete missionVariables.erehwonFotoShot;
delete missionVariables.erehwonPictureCount;
//delete missionVariables.showErehwon;
delete missionVariables.erehwomMisJumpInfo;
missionVariables.erehwonReconnaissance = "EPILOGUE";
missionVariables.erehwonEpilogue = 1;
missionVariables.erehwonActiontime = clock.days + 30;
player.ship.removeEquipment("EQ_EREHWON_PHOTOCAMERA");
mission.setInstructionsKey(null);
this.$unmarkSystem(124);
player.credits += 500;
}
if (missionVariables.erehwonReconnaissance == "ACCEPTED" &&
missionVariables.erehwonPictureCount == 0 && missionVariables.erehwonFotoShot == "NO") {
mission.runScreen({
screenID:"tionisla_reporter",
title: "Tionisla Chronicle",
messageKey: "erehwonReconnaissance_failure",
choicesKey: "erehwonReconnaissance_choice2"
}, this.choiceEvaluation
);
}
if (missionVariables.erehwonReconnaissance == "ACCEPTED" &&
player.ship.equipmentStatus("EQ_EREHWON_PHOTOCAMERA") == "EQUIPMENT_DAMAGED") {
mission.runScreen({
screenID:"tionisla_reporter",
title: "Tionisla Chronicle",
messageKey: "erehwonReconnaissance_damaged",
choicesKey: "erehwonReconnaissance_choice2"
}, this.choiceEvaluation
);
}
}
/*if (system.ID == 144 && missionVariables.erehwomMisJumpInfo !== "") {
missionVariables.erehwomMisJumpInfo = "BIORLE";
}
if (system.ID == 48 && missionVariables.erehwomMisJumpInfo == "BIORLE") {
missionVariables.erehwomMisJumpInfo = "USLE";
}*/
if (system.ID == 144 && missionVariables.erehwomMisJumpInfo !== "GIVEN") {
mission.runScreen({
title: "Tionisla Chronicle",
messageKey: "erehwonReconnaissance_biorle"
});
missionVariables.erehwomMisJumpInfo = "GIVEN";
}
if (missionVariables.erehwonReconnaissance == "DECLINED" && missionVariables.erehwonActiontime > clock.days) {
mission.runScreen({
screenID:"tionisla_reporter",
title: "Tionisla Chronicle",
messageKey: "erehwonReconnaissance_declined"
});
missionVariables.erehwonReconnaissance = "FINISHED";
missionVariables.erehwonTimerStart = null;
this.cleanUp();
}
if (missionVariables.erehwonReconnaissance == "EPILOGUE" && clock.days > missionVariables.erehwonActiontime) {
if (!missionVariables.erehwonDestroyed || missionVariables.erehwonDestroyed === false) {
// credits for the idea and next 6 messages go to SandJ
var erehwonEpilogue = missionVariables.erehwonEpilogue++;
missionVariables.erehwonActiontime = clock.days + 30; // set new time
mission.runScreen({
screenID:"tionisla_reporter",
title: "Tionisla Chronicle",
messageKey: "erehwonReconnaissance_epilogue_" + erehwonEpilogue
});
switch(erehwonEpilogue) {
case 1:
player.credits += 50;
break;
case 2:
player.ship.fuel = 7;
break;
case 3:
var narcotics = player.ship.cargoSpaceAvailable;
if (narcotics > 35) narcotics = 35; // add a limit
manifest.narcotics += narcotics;
break;
case 4:
player.credits += 75;
break;
case 5:
player.credits += 50;
missionVariables.erehwonActiontime += 100; // wait a bit longer for the last one
break;
case 6:
manifest.gem_stones += 100;
default:
// we ran out of messages. Clean up now.
missionVariables.erehwonActiontime = null;
missionVariables.erehwonEpilogue = null;
missionVariables.erehwonReconnaissance = "FINISHED";
this.cleanUp();
break;
}
}
}
} else if (player.ship.dockedStation.displayName == "Erehwon Station") {
if (missionVariables.erehwonGotStory && missionVariables.erehwonGotStory == "NO") {
missionVariables.erehwonGotStory = "YES";
mission.runScreen({
screenID:"tionisla_reporter",
title: "Tionisla Chronicle",
messageKey: "erehwonReconnaissance_story"
});
}
if (missionVariables.erehwonFotoShot && missionVariables.erehwonFotoShot == "YES") {
if (missionVariables.erehwonReconnaissance != "SUCCESS")
{
this.$unmarkSystem(144);
this.$markSystem(124);
}
missionVariables.erehwonReconnaissance = "SUCCESS";
mission.setInstructionsKey("erehwonReconnaissance_missioninfo2");
}
}
}
//-------------------------------------------------------------------------------------------------------------
this.choiceEvaluation = function (choice) {
switch (choice) {
case "OFFER_ACCEPTED":
missionVariables.erehwonReconnaissance = "ACCEPTED";
player.ship.awardEquipment("EQ_EREHWON_PHOTOCAMERA");
missionVariables.erehwonPictureCount = 10;
mission.setInstructionsKey("erehwonReconnaissance_missioninfo1");
this.$markSystem(144);
mission.runScreen({
screenID:"tionisla_reporter",
title: "Tionisla Chronicle",
messageKey: "erehwonReconnaissance_accepted"
}
);
break;
case "OFFER_DECLINED":
missionVariables.erehwonReconnaissance = "DECLINED";
missionVariables.erehwonActiontime = clock.days + 30;
break;
}
}
//-------------------------------------------------------------------------------------------------------------
this.shipWillEnterWitchspace = function (cause) {
missionVariables.showErehwon = "NO"; // avoid adding planet on multiple misjumps.
if (!system.isInterstellarSpace && galaxyNumber === 0) {
if (cause === "standard jump" && (system.ID === 48 || system.ID === 144)) {
missionVariables.showErehwon = "YES";
if (missionVariables.erehwomMisJumpInfo == "GIVEN" && (system.ID == 48 || system.ID == 144) && cause === "standard jump") {
if ((player.ship.targetSystem == 48 || player.ship.targetSystem == 144) && Math.random() < 0.2) {
player.ship.scriptedMisjump = true;
}
}
}
}
}
//-------------------------------------------------------------------------------------------------------------
this.shipExitedWitchspace = function () {
if (this._restoreIST === true) {
worldScripts["IST_masterScript"].shipWillExitWitchspace = worldScripts["IST_masterScript"].$hold_shipWillExitWitchspace;
delete worldScripts["IST_masterScript"].$hold_shipWillExitWitchspace;
this._restoreIST = false;
}
}
//-------------------------------------------------------------------------------------------------------------
this.$markSystem = function (ID) {
if (0 < oolite.compareVersion("1.77")) {
mission.markSystem(ID);
} else {
mission.markSystem({
system: ID,
name: "Tionisla Reporter",
markerColor: "magentaColor",
markerShape: "MARKER_DIAMOND"
});
}
}
//-------------------------------------------------------------------------------------------------------------
this.$unmarkSystem = function (ID) {
if (0 < oolite.compareVersion("1.77")) {
mission.unmarkSystem(ID);
} else {
var ok = mission.unmarkSystem({system: ID, name: "Tionisla Reporter"});
if (!ok) mission.unmarkSystem(ID); // must have had a legacy marker. Clear that also.
}
}
//-------------------------------------------------------------------------------------------------------------
this.cleanUp = function () {
delete this.missionScreenOpportunity;
//delete this.shipWillEnterWitchspace;
}
//-------------------------------------------------------------------------------------------------------------
this.$erehwon_systemWillPopulate = function() {
if (this.$populatorRun) return;
// turn off IST, just in case
if (worldScripts["IST_masterScript"]) {
worldScripts["IST_masterScript"].$hold_shipWillExitWitchspace = worldScripts["IST_masterScript"].shipWillExitWitchspace;
delete worldScripts["IST_masterScript"].shipWillExitWitchspace;
this._restoreIST = true;
}
system.setPopulator("oolite-interstellar-thargoids", {
priority: 10,
location: "WITCHPOINT",
groupCount: 2 + Math.floor(Math.random() * 4),
callback: function(pos) {system.addShips("thargoid", 1, pos, 0);}
});
this.$populatorRun = true;
if (missionVariables.showErehwon === "YES") {
system.addPlanet("Planet_Erehwon");
// only add the station if it hasn't been destroyed
if (!missionVariables.erehwonDestroyed || missionVariables.erehwonDestroyed === false) {
system.addShips("erehwonStation", 1, Vector3D(-50000, 4000, 413000).fromCoordinateSystem("abs"), 1);
}
}
}
|