Scripts/taranis_market.js |
"use strict";
this.name = "taranis_market";
this.author = "spara";
this.copyright = "2014 spara";
this.license = "CC BY-NC-SA 4.0";
this.$originalDefs = {
"food": [0, 0, 0, 0, 0, 0, 0, 0, 0],
"textiles": [0, 0, 0, 0, 0, 0, 0, 0, 0],
"radioactives": [0, 0, 0, 0, 0, 0, 0, 0, 0],
"slaves": [0, 0, 0, 0, 0, 0, 0, 0, 0],
"liquor_wines": [0, 0, 0, 0, 0, 0, 0, 0, 0],
"luxuries": [0, 0, 196, 8, 8, 73, 3, 3, 0],
"narcotics": [0, 0, 0, 0, 0, 0, 0, 0, 0],
"computers": [0, 0, 0, 0, 0, 0, 0, 0, 0],
"machinery": [0, 0, 0, 0, 0, 0, 0, 0, 0],
"alloys": [0, 0, 0, 0, 0, 0, 0, 0, 0],
"firearms": [0, 0, 0, 0, 0, 0, 0, 0, 0],
"furs": [0, 0, 0, 0, 0, 0, 0, 0, 0],
"minerals": [0, 0, 0, 0, 0, 0, 0, 0, 0],
"gold": [0, 0, 0, 0, 0, 0, 0, 0, 1],
"platinum": [0, 0, 0, 0, 0, 0, 0, 0, 1],
"gem_stones": [0, 0, 0, 0, 0, 0, 0, 0, 2],
"alien_items": [0, 0, 0, 0, 0, 0, 0, 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/taranis_one.js |
"use strict";
this.name = "taranis_one";
this.author = "Robert Todd (Roberto on Oolite Forums)";
this.copyright = "© 2006 Creative Commons: attribution, non-commercial, sharealike.";
this.description = "worldScript for the taranis mission";
//-------------------------------------------------------------------------------------------------------------
this.startUp = function () {
if (missionVariables.taranis_one == "TAR1_COMPLETE" || missionVariables.taranis_one == "TAR1_FAILED") {
this.$cleanUp();
}
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(141);
fpo.planetList.splice(idx, 1);
}
};
//-------------------------------------------------------------------------------------------------------------
this.startUpComplete = function() {
// make sure our texture wins any races to be the last texture installed
var info = System.infoForSystem(0, 141);
info.texture = "lerelace_diffuse.png";
}
//-------------------------------------------------------------------------------------------------------------
this.turnStationToEntity = function (station, entity) {
var targetVector = entity.position.subtract(station.position).direction();
station.orientation = targetVector.rotationTo([0, 0, 1]);
}
//-------------------------------------------------------------------------------------------------------------
this.systemWillPopulate = function() {
if (galaxyNumber === 0 && system.ID === 141) {
var stationPos = Vector3D(157000, 37000, 28000).fromCoordinateSystem("pwm");
system.setPopulator("taranis_station", {
callback: function (pos) {
if (system.countShipsWithRole("taranis") == 0) {
var stn = system.addShips("taranis", 1, pos, 0)[0];
worldScripts["taranis_one"].turnStationToEntity(stn, system.mainPlanet);
// add a ve to mask the issue of the walls of the dock disappearing when you enter
var ve = system.addVisualEffect("taranis-dock-ve", stn.position.add(stn.vectorForward.multiply(2339)));
ve.scale(1.01);
ve.orientation = stn.orientation;
}
},
location: "COORDINATES",
coordinates: stationPos,
deterministic: true
});
}
}
//-------------------------------------------------------------------------------------------------------------
this.missionScreenOpportunity = function () {
if (!player.ship.docked || galaxyNumber != 0) return;
this.missionOffers();
};
//-------------------------------------------------------------------------------------------------------------
this.missionOffers = function () {
if (player.ship.dockedStation.isMainStation) {
if (missionVariables.taranis_one == "TAR1_ACTIVE" && missionVariables.taranis_one_startdate + 2 < clock.days) {
mission.runScreen({
title: "Taranis one",
screenID: "taranis",
messageKey: "taranis_one_incoming",
music: "taranis_comms.ogg",
choicesKey: "taranis_one_incoming2_justyes"
}, this.choiceEvaluation
);
}
if (missionVariables.taranis_one == "TAR1_DESTROYED") {
mission.runScreen({
title: "Taranis one",
screenID: "taranis",
messageKey: "taranis_one_incoming",
music: "taranis_comms.ogg",
choicesKey: "taranis_one_incoming_justyes"
}, this.choiceEvaluation
);
}
} else if (system.ID == 141 && player.ship.dockedStation.name == "Taranis Corporation HQ") {
if (!missionVariables.taranis_one && player.score > 127 && player.bounty < 5) {
mission.runScreen({
title: "Taranis one",
screenID: "taranis",
messageKey: "taranis_one_preamble",
choicesKey: "taranis_one_preamble_justyes",
music: "swifts_theme.ogg"
}, this.choiceEvaluation
);
}
}
};
//-------------------------------------------------------------------------------------------------------------
this.choiceEvaluation = function (choice) {
switch (choice) {
case "1":
mission.runScreen({
title: "Taranis one",
screenID: "taranis",
messageKey: "taranis_one_intro1",
choicesKey: "taranis_one_cont1_justyes",
music: "swifts_theme.ogg"
}, this.choiceEvaluation
);
break;
case "2":
mission.runScreen({
title: "Taranis one",
screenID: "taranis",
messageKey: "taranis_one_intro2",
choicesKey: "taranis_one_cont2_justyes",
music: "swifts_theme.ogg"
}, this.choiceEvaluation
);
break;
case "3":
mission.runScreen({
title: "Taranis one",
screenID: "taranis",
messageKey: "taranis_one_decision",
choicesKey: "taranis_one_offer_yesno",
music: "swifts_theme.ogg"
}, this.choiceEvaluation
);
break;
case "4":
mission.runScreen({
title: "Taranis one",
screenID: "taranis",
messageKey: "taranis_one_accepted",
choicesKey: "taranis_one_cont3_justyes",
music: "swifts_theme.ogg"
}, this.choiceEvaluation
);
break;
case "5":
missionVariables.taranis_one = "TAR1_PASSED";
mission.runScreen({
title: "Taranis one",
screenID: "taranis",
messageKey: "taranis_one_declined"
});
break;
case "6":
missionVariables.taranis_one_startdate = clock.days;
missionVariables.taranis_one = "TAR1_ACTIVE";
mission.runScreen({
title: "Taranis one",
screenID: "taranis",
messageKey: "taranis_one_briefing",
music: "swifts_theme.ogg"
});
mission.markSystem({ system: 111, name: "taranis" });
player.credits += 2000;
this.updateTimeLeft();
break;
case "7":
missionVariables.taranis_one = "TAR1_COMPLETE";
mission.runScreen({
title: "Taranis one",
screenID: "taranis",
messageKey: "taranis_one_success",
music: "swifts_theme.ogg"
});
mission.setInstructionsKey(null);
mission.unmarkSystem({ system: 111, name: "taranis" });
player.credits += 2000;
delete missionVariables.taranis_one_startdate;
delete missionVariables.taranis_one_daysremaining;
this.$cleanUp();
break;
case "8":
missionVariables.taranis_one = "TAR1_FAILED";
mission.runScreen({
title: "Taranis one",
screenID: "taranis",
messageKey: "taranis_one_failure",
music: "swifts_theme.ogg"
});
mission.setInstructionsKey(null);
mission.unmarkSystem({ system: 111, name: "taranis" });
// repay the advance fee for the mission.
if (player.credits > 2000) player.credits -= 2000; else player.credits = 0;
delete missionVariables.taranis_one_startdate;
delete missionVariables.taranis_one_daysremaining;
this.$cleanUp();
break;
default:
break;
}
};
//-------------------------------------------------------------------------------------------------------------
this.shipLaunchedFromStation = function () {
if (missionVariables.taranis_one == "TAR1_ACTIVE") {
this.updateTimeLeft();
}
};
//-------------------------------------------------------------------------------------------------------------
this.shipExitedWitchspace = function () {
if (missionVariables.taranis_one == "TAR1_ACTIVE" && !this.messagesTimer) {
this.messagesTimer = new Timer(this, this.waitForAdjusting, 0, 2); // clock might not be valid yet.
}
if (missionVariables.taranis_one == "TAR1_PASSED" && Math.random() < 0.05) {
missionVariables.taranis_one = null; // restart mission offers
}
};
//-------------------------------------------------------------------------------------------------------------
this.waitForAdjusting = function () {
if (clock.isAdjusting) return;
var timePast = this.updateTimeLeft();
if (system.ID == 111 && timePast < 3) {
system.addShips("taranis-wolf", 1, Vector3D(127112, 20303, 662546).fromCoordinateSystem("pwm"), 0);
}
this.messagesTimer.stop();
delete this.messagesTimer;
}
//-------------------------------------------------------------------------------------------------------------
this.updateTimeLeft = function () {
var timePast = clock.days - missionVariables.taranis_one_startdate;
switch (timePast) {
case 0:
missionVariables.taranis_one_daysremaining = "three days";
break;
case 1:
missionVariables.taranis_one_daysremaining = "two days";
break;
case 2:
missionVariables.taranis_one_daysremaining = "one day";
break;
default:
// Mission ended not in time.
mission.setInstructionsKey("mission_taranis_one_desc2");
mission.unmarkSystem({ system: 111, name: "taranis" });
break;
}
if (timePast < 3) mission.setInstructionsKey("mission_taranis_one_desc1");
return timePast;
};
//-------------------------------------------------------------------------------------------------------------
this.$cleanUp = function () {
delete this.missionScreenOpportunity;
delete this.shipLaunchedFromStation;
delete this.shipExitedWitchspace;
};
|