| Scripts/thargoidWars.js |
"use strict";
this.name = "thargoid_wars";
this.author = "eric walch";
this.copyright = "� 2008 Murgh.";
this.description = "script that brings the war to normal space";
this.version = "4.7";
//-------------------------------------------------------------------------------------------------------------
this.startUp = function () {
if (!missionVariables.thargoidwars_station_attack) {
if (!missionVariables.station_attack) { // backward compatibility with old name.
this.initialise();
} else {
missionVariables.thargoidwars_station_attack = missionVariables.station_attack;
}
}
this.medals = ["NONE", "BRONZE", "SILVER", "GOLD", "CRYSTAL"];
this.medalNumber = this.medals.indexOf(missionVariables.thargoidwars_medal); // turn into number.
}
//-------------------------------------------------------------------------------------------------------------
this.initialise = function () {
missionVariables.thargoidwars_station_attack = "INITIALISE";
missionVariables.thargoidwars_number = 0;
missionVariables.thargoidwars_medal_number = 0;
missionVariables.thargoidwars_medal = "NONE";
// Initialise unused variables for backward compatibility in case someone plays with both versions.
missionVariables.thargoid_ambush = "IMPOSSIBLE"; // unused in JS
missionVariables.thargoidwars_timer = 0; // unused in JS
missionVariables.thargoidwars_timer_start = "NO"; // unused in JS
missionVariables.thargoidwars_ambush_timer = -1; // unused in JS
missionVariables.thargoidwars_ambush_timer_start = "NO"; // unused in JS
missionVariables.thargoidwars_satellite_timer = -1; // unused in JS
missionVariables.thargoidwars_satellite_timer_start = "NO"; // unused in JS
}
//-------------------------------------------------------------------------------------------------------------
this.shipDockedWithStation = function (station) {
this.justDocked = true;
}
//-------------------------------------------------------------------------------------------------------------
this.missionScreenOpportunity = function () {
if (player.ship.docked) this.missionOffers();
}
//-------------------------------------------------------------------------------------------------------------
this.missionOffers = function () {
if (player.ship.dockedStation.isMainStation) {
var stationAttack = missionVariables.thargoidwars_station_attack;
var thargoidwarsNumber = missionVariables.thargoidwars_number;
if (stationAttack === "INITIALISE" && (missionVariables.thargplans === "MISSION_COMPLETE" || galaxyNumber > 0) &&
system.ID !== 36 && Math.random() < 0.2) {
mission.runScreen({
titleKey: "thargoidwars_title",
messageKey: "thargoidwars_station_attack_inews",
overlay: "thargoid_wars_iNews.png"
});
missionVariables.thargoidwars_station_attack = "IMPOSSIBLE";
}
if (stationAttack === "ATTACKED") {
// the check: stationAttack === "ATTACKED" is only added to fix old saved games containing this value.
this.announceStationAttack();
}
if (stationAttack === "IN_PROGRESS") {
if (!this.attackedSystem || this.attackedSystem !== system.ID) { // could happens when starting from a saved game.
missionVariables.thargoidwars_station_attack = "IMPOSSIBLE";
return;
}
var thargoidCount;
if (0 < oolite.compareVersion("1.75")) {
thargoidCount = system.entitiesWithScanClass("CLASS_THARGOID", player.ship.dockedStation, 20E3).length;
} else {
thargoidCount = system.countEntitiesWithScanClass("CLASS_THARGOID", player.ship.dockedStation, 20E3); // faster code
}
if (thargoidCount === 0) {
missionVariables.thargoidwars_station_attack = "IMPOSSIBLE";
if (Math.random() < 0.3) stationAttack = "POSSIBLE"; // Random chance of 2nd wave.
missionVariables.thargoidwars_number += this.difficulty; // bonus for getting them all.
delete this.attackedSystem;
} else if (this.justDocked) {
mission.runScreen({
titleKey: "thargoidwars_title",
messageKey: "thargoidwars_station_attack_unfinished",
music: "siren.ogg"
});
if (this.difficulty > 1) this.difficulty--;
this.justDocked = false;
}
}
if (stationAttack === "POSSIBLE" && !this.stationWillBeAttacked) {
// if we're doing the cataclysm station attack mission, don't do this one as well
if (missionVariables.cataclysm_missions == "STATION_ATTACK") return;
this.stationWillBeAttacked = true;
this.attackTimer = new Timer(this, this.stationAttack.bind(this), 15 + 45 * Math.random(), 20);
}
if (thargoidwarsNumber > 5 && !missionVariables.thargoid_satellite) {
mission.runScreen({
titleKey: "thargoidwars_title",
messageKey: "thargoidwars_spy_satellite",
model: "thargoid_wars_satellite"
});
missionVariables.thargoid_satellite = "INFORMED";
return;
}
if (thargoidwarsNumber > 9) {
player.credits += 1000;
missionVariables.thargoidwars_number = 0;
if (worldScripts.GalCopBB_Reputation) {
var rep = worldScripts.GalCopBB_Reputation;
rep.$adjustReputationForEntity(expandDescription("[gcm_reputation_galcop]"), system.ID, "Success", 1, 1);
rep.$adjustReputationForEntity(expandDescription("[gcm_reputation_localgov]"), system.ID, "Success", 1, 1);
rep.$adjustReputationForEntity(expandDescription("[gcm_reputation_navy]"), system.ID, "Success", 1, 1);
}
if (++missionVariables.thargoidwars_medal_number < 5) {
mission.runScreen({ titleKey: "thargoidwars_title", messageKey: "thargoidwars_reward", overlay: { name: "thargoid_wars_navy_star.png", height: 546 } });
} else {
missionVariables.thargoidwars_medal_number = 0;
this.medalNumber++;
switch (missionVariables.thargoidwars_medal) {
case "NONE":
mission.runScreen({
titleKey: "thargoidwars_title",
messageKey: "thargoidwars_bronze",
overlay: { name: "thargoid_wars_bronze.png", height: 546 }
});
missionVariables.thargoidwars_medal = "BRONZE";
this.$addPadLogEntry(expandMissionText("thargoidwars_reward_bronze"));
if (rep) {
rep.$addAward({
title: expandMissionText("thargoidwars_bronze_title"),
worldScript: this.name,
description: expandMissionText("thargoidwars_award_description"),
entity: expandDescription("[gcm_reputation_navy]"),
system: system.ID,
galaxy: galaxyNumber,
received: clock.adjustedSeconds,
image: { name: "thargoid_wars_bronze.png", height: 546 }
});
}
break;
case "BRONZE":
mission.runScreen({
titleKey: "thargoidwars_title",
messageKey: "thargoidwars_silver",
overlay: { name: "thargoid_wars_silver.png", height: 546 }
});
missionVariables.thargoidwars_medal = "SILVER";
this.$addPadLogEntry(expandMissionText("thargoidwars_reward_silver"));
if (rep) {
rep.$addAward({
title: expandMissionText("thargoidwars_silver_title"),
worldScript: this.name,
description: expandMissionText("thargoidwars_award_description"),
entity: expandDescription("[gcm_reputation_navy]"),
system: system.ID,
galaxy: galaxyNumber,
received: clock.adjustedSeconds,
image: { name: "thargoid_wars_silver.png", height: 546 }
});
}
break;
case "SILVER":
mission.runScreen({
titleKey: "thargoidwars_title",
messageKey: "thargoidwars_gold",
overlay: { name: "thargoid_wars_gold.png", height: 546 }
});
this.$addPadLogEntry(expandMissionText("thargoidwars_reward_gold"));
missionVariables.thargoidwars_medal = "GOLD";
if (rep) {
rep.$addAward({
title: expandMissionText("thargoidwars_gold_title"),
worldScript: this.name,
description: expandMissionText("thargoidwars_award_description"),
entity: expandDescription("[gcm_reputation_navy]"),
system: system.ID,
galaxy: galaxyNumber,
received: clock.adjustedSeconds,
image: { name: "thargoid_wars_gold.png", height: 546 }
});
}
break;
case "GOLD":
mission.runScreen({
titleKey: "thargoidwars_title",
messageKey: "thargoidwars_crystal",
overlay: { name: "thargoid_wars_crystal.png", height: 546 }
});
this.$addPadLogEntry(expandMissionText("thargoidwars_reward_crystal"));
missionVariables.thargoidwars_medal = "CRYSTAL";
if (rep) {
rep.$addAward({
title: expandMissionText("thargoidwars_crystal_title"),
worldScript: this.name,
description: expandMissionText("thargoidwars_award_description"),
entity: expandDescription("[gcm_reputation_navy]"),
system: system.ID,
galaxy: galaxyNumber,
received: clock.adjustedSeconds,
image: { name: "thargoid_wars_crystal.png", height: 546 }
});
}
break;
case "CRYSTAL":
default:
mission.runScreen({
titleKey: "thargoidwars_title",
messageKey: "thargoidwars_reward",
overlay: { name: "thargoid_wars_navy_star.png", height: 546 }
});
break;
}
}
}
}
}
//-------------------------------------------------------------------------------------------------------------
this.stationAttack = function stationAttack() { // Delayed missionoffer, called by a timer
if (guiScreen === "GUI_SCREEN_MISSION" || guiScreen === "GUI_SCREEN_REPORT" || guiScreen === "GUI_SCREEN_SAVE") return;
this.attackTimer.stop();
delete this.attackTimer;
if (player.ship.docked) this.announceStationAttack(); // docked and on a safe screen for display.
this.stationWillBeAttacked = false;
}
//-------------------------------------------------------------------------------------------------------------
this.announceStationAttack = function () {
this.difficulty = Math.ceil(Math.random() * 3);
this.runStationAttackScreen();
}
//-------------------------------------------------------------------------------------------------------------
this.runStationAttackScreen = function () {
mission.runScreen({
titleKey: "thargoidwars_title",
messageKey: "thargoidwars_station_attack",
choicesKey: "thargoidwars_station_attack_yesno",
initialChoicesKey: "MAKE_CHOICE",
music: "siren.ogg"
},
function (choice) {
if (choice === "NO_THARGOID") {
missionVariables.thargoidwars_station_attack = "IMPOSSIBLE";
mission.runScreen({
titleKey: "thargoidwars_title",
messageKey: "thargoidwars_station_attack_coward",
overlay: { name: "thargoid_wars_coward.png", height: 546 }
});
missionVariables.thargoidwars_number--;
worldScripts.thargoid_wars.$addPadLogEntry(expandMissionText("thargoidwars_station_declined"));
} else if (choice === "MAKE_CHOICE") {
worldScripts.thargoid_wars.runStationAttackScreen();
return;
} else {
// choice === "YES_THARGOID" or player launched without making choice.
worldScripts.thargoid_wars.$addPadLogEntry(expandMissionText("thargoidwars_station_accepted"));
missionVariables.thargoidwars_station_attack = "IN_PROGRESS";
worldScripts.thargoid_wars.addStationAttackThargoids(this.difficulty);
var saved_legalstatus = player.bounty;
player.ship.launch();
player.bounty = saved_legalstatus; // don't penalise a ship with illegal goods when helping the station.
}
}
);
}
//-------------------------------------------------------------------------------------------------------------
this.shipExitedWitchspace = function () {
if (system.isInterstellarSpace || missionVariables.thargoidwars_station_attack === "INITIALISE" || system.sun.hasGoneNova) return;
if (Math.random() < 0.06 && missionVariables.thargoidwars_station_attack === "IMPOSSIBLE") { // thargoid Station Attack
missionVariables.thargoidwars_station_attack = "POSSIBLE";
}
if (Math.random() < 0.04 && system.countEntitiesWithScanClass("CLASS_THARGOID") === 0) {
this.setUpRewards(system.addGroupToRoute("thargoid", 3, 0.05, "wp"));
}
if (Math.random() < 0.05) { // thargoid Ambush
var decoyOffset = 0.5 * Math.random();
var decoy = system.addShipsToRoute("thargoid", 1, 0.88 - decoyOffset, "pw")[0];
decoy.setScript("wombatsThargoidWarsDecoy.js");
decoy.switchAI("dumbAI.plist");
if (Math.random() < 5) {
this.setUpRewards(system.addGroupToRoute("thargoid", 3, 0.755 - decoyOffset, "pw"));
system.addShipsToRoute("police", 3, 0.756 - decoyOffset, "pw");
system.addShipsToRoute("trader", 3, 0.754 - decoyOffset, "pw");
}
}
if (Math.random() < 0.06 && missionVariables.thargoid_satellite === "INFORMED") { // thargoid Satellite
system.addShips("thargoid_wars_satellite", 1, [0, 0, -20E3], 5E3);
}
}
//-------------------------------------------------------------------------------------------------------------
this.addStationAttackThargoids = function (count) {
this.attackedSystem = system.ID;
this.setUpRewards(system.addGroup("thargoid", count, player.ship.position, 25E3));
system.addShips("trader", 2 * count, player.ship.position, 25E3);
if (count > 1) system.addShips("police", count - 1, player.ship.position, 25E3);
}
//-------------------------------------------------------------------------------------------------------------
// code below is triggered by ship scripts.
this.thargoidDecoy = function (position) {
this.decoyTimer = new Timer(this, this.$addThargoids.bind(this), 15 + 30 * Math.random());
this.decoyPosition = position;
}
//-------------------------------------------------------------------------------------------------------------
this.$addThargoids = function $addThargoids() {
this.setUpRewards(system.addGroup("thargoid", 3, this.decoyPosition, 2000));
}
//-------------------------------------------------------------------------------------------------------------
this.thargoidSatellite = function () {
if (Math.random() < 0.5) this.satelliteTimer = new Timer(this, this.$addThargoid.bind(this), 15 + 30 * Math.random());
}
//-------------------------------------------------------------------------------------------------------------
this.$addThargoid = function $addThargoid() {
this.setUpRewards(system.addGroup("thargoid", 1, [0, 0, 20E3], 5E3));
}
//-------------------------------------------------------------------------------------------------------------
this.setUpRewards = function (group) {
// Insert a counter in all groupmember death-actions.
for (var i = 0; i < group.count; i++) {
var thargoid = group.ships[i];
if (thargoid.script.shipDied) thargoid.script.thargoidWarsOriginal = thargoid.script.shipDied;
thargoid.script.shipDied = function (who, why) {
if (who && who.isPlayer) {
missionVariables.thargoidwars_number++;
if (worldScripts.GalCopBB_Reputation) {
var rep = worldScripts.GalCopBB_Reputation;
rep.$adjustReputationForEntity(expandDescription("[gcm_reputation_galcop]"), system.ID, "Success", 0.1, 1);
rep.$adjustReputationForEntity(expandDescription("[gcm_reputation_localgov]"), system.ID, "Success", 0.1, 1);
rep.$adjustReputationForEntity(expandDescription("[gcm_reputation_navy]"), system.ID, "Success", 0.1, 1);
}
}
if (this.thargoidWarsOriginal) this.thargoidWarsOriginal(who, why);
}
}
}
//-------------------------------------------------------------------------------------------------------------
this.$addPadLogEntry = function (text) {
var pad = worldScripts.Lib_PAD;
if (!pad) return;
pad._setPageEntry("LOGS.GENERIC.list", text);
}
|
| Scripts/wombatsThargoidWarsSatellite.js |
"use strict";
this.name = "wombatsThargoidWarsSatellite";
this.author = "eric walch";
this.copyright = "� 2008 eric walch.";
this.description = "Code for the thargoid satellite";
this.version = "1.11";
//-------------------------------------------------------------------------------------------------------------
this.shipSpawned = function () {
this.ship.orientation = [1, 0, 1, 0];
this.addThargoidTimer = new Timer(this, this.$addThargoids, 15 + Math.random() * 25);
}
//-------------------------------------------------------------------------------------------------------------
this.shipDied = function (who) {
this.ship.commsMessage(expandMissionText("thargoidwars_shush"));
if (who && who.isPlayer) {
missionVariables.thargoidwars_number++;
if (worldScripts.GalCopBB_Reputation) {
var rep = worldScripts.GalCopBB_Reputation;
rep.$adjustReputationForEntity(expandDescription("[gcm_reputation_galcop]"), system.ID, "Success", 0.5, 1);
rep.$adjustReputationForEntity(expandDescription("[gcm_reputation_localgov]"), system.ID, "Success", 0.5, 1);
rep.$adjustReputationForEntity(expandDescription("[gcm_reputation_navy]"), system.ID, "Success", 0.5, 1);
}
}
worldScripts.thargoid_wars.thargoidSatellite();
}
//-------------------------------------------------------------------------------------------------------------
this.entityDestroyed = function () {
if (this.addThargoidTimer) { this.addThargoidTimer.stop(); delete this.addThargoidTimer };
}
//-------------------------------------------------------------------------------------------------------------
this.$addThargoids = function $addThargoids() {
// Satellite was not killed in time.
// Inform the thargoid fleet that the player is in the system.
var count = 2 + Math.ceil(Math.random() * 3);
worldScripts.thargoid_wars.setUpRewards(system.addGroup("thargoid", count, [0, 0, 50E3], 5E3));
count = 1 + Math.round(Math.random() * 2);
worldScripts.thargoid_wars.setUpRewards(system.addGroup("thargoid", count, this.ship.position, 15E3));
} |