"use strict";
this.name = "PFoohauler";
this.author = "Thargoid";
this.copyright = "Creative Commons Attribution - Non-Commercial - Share Alike 3.0 license with clauses - see readme.txt.";
this.description = "Code for Planetfall Oohauler";
this.version = "2.0";

//-------------------------------------------------------------------------------------------------------------
this.shipDied = function (whom, why) {
	missionVariables.PFoohaul_credits = 0;
	missionVariables.PFoohaul_mis_done = null;
	missionVariables.PFoohaul_mis_stage = "1";
}

//-------------------------------------------------------------------------------------------------------------
this.shipWillExitWitchspace = function () {
	this.ship.switchAI("route1traderAI.plist");
	delete this.shipDied;
}

//-------------------------------------------------------------------------------------------------------------
this.rewardPlayer1 = function() {
	this.ship.commsMessage(expandMissionText("PFoohaul_rerouted"));
	this.rewardPlayerFinal();
}

//-------------------------------------------------------------------------------------------------------------
this.rewardPlayer2 = function() {
	this.ship.commsMessage(expandMissionText("PFoohaul_ready_to_jump"));
	this.rewardPlayerFinal();
}

//-------------------------------------------------------------------------------------------------------------
this.rewardPlayerFinal = function () {
	if (worldScripts.GalCopBB_Reputation) {
		var rep = worldScripts.GalCopBB_Reputation;
		rep.$adjustReputationForEntity(expandDescription("[gcm_reputation_localgov]"), system.ID, "Success", 1, 1);
	}
	player.credits += parseInt(missionVariables.PFoohaul_credits);
	missionVariables.PFoohaul_credits = 0;
	missionVariables.PFoohaul_mis_done = null;
	missionVariables.PFoohaul_mis_stage = "1";
}

//-------------------------------------------------------------------------------------------------------------
this.missionDone = function () {
	missionVariables.PFoohaul_mis_stage = "3";
	missionVariables.PFoohaul_mis_done = "YES";
}

//-------------------------------------------------------------------------------------------------------------
this.locateConstore = function () {
	this.storeArray = system.shipsWithPrimaryRole("constore");
	if (this.storeArray.length == 0) { // where'd the constore go?
		this.ship.switchAI("PFoohaulWitAI.plist"); // let's go to the witchpoint instead then
		this.ship.AIState = "HEAD_FOR_WITCHPOINT";
	} else {
		this.ship.target = this.storeArray[0];
		this.ship.reactToAIMessage("CONSTORE_FOUND");
	}
}

//-------------------------------------------------------------------------------------------------------------
this.locateJumpPoint = function () {
	this.buoyArray = system.shipsWithPrimaryRole("buoy-witchpoint");
	if (this.buoyArray.length == 0) { // where'd the witchpoint buoy go?
		this.ship.reactToAIMessage("WITCHBUOY_NOT_FOUND");
	} else {
		this.ship.target = this.buoyArray[0];
		this.ship.reactToAIMessage("WITCHBUOY_FOUND");
	}
}