document.getElementById("loadingMessage").innerHTML = 'Loading definitions...';


function PortOfCall(portName, x, y, nation, routeSecurity, portFamiliarity)
{
	var i, j;
	this.portName = portName;
	this.x = x;
	this.y = y;
	this.nation = nation;
	this.nearestNeighbor = -1;
	this.nearestHostile = -1;
	this.influence = 1000;
	this.hostileInfluence = 1000;
	this.nearNeighbors = new Array();
	this.farNeighbors = new Array();
	this.routeSecurity = routeSecurity;
	this.portFamiliarity = portFamiliarity;
	this.portHostility = 0;
	this.portLegal = 0;
	this.portPriceVariance = new Array(1, 1, 1, 1, 1, 1, 1, 1);
	this.portPriceStability = new Array(1, 1, 1, 1, 1, 1, 1, 1);
	this.portCurrentPrice = new Array(0, 0, 0, 0, 0, 0, 0, 0);
	this.portProductionRate = new Array(50, 20, 40, 15, 10, 0, 5, 3);
	this.portStock = new Array(100, 40, 80, 30, 20, 0, 10, 6);
	this.portMaxStock = new Array(500, 250, 400, 150, 100, 1000, 25, 20);
	this.primaryDescriptor = SelectRandomIndexFromArray(primaryPlanetDescriptors, randomNumberSeed);
	randomNumberSeed = randomNumberSeed + 1;
	this.secondaryDescriptor = SelectRandomIndexFromArray(secondaryPlanetDescriptors, randomNumberSeed);
	randomNumberSeed = randomNumberSeed + 1;
	this.isCapital = false;
	this.landMass = new Array((6*5*4)); // 6 * points per shape * shapes
	
	var numPoints, numShapes;
	
	numPoints = 9;
	numShapes = 4;
	
	this.landMassX = new Array(numPoints*numShapes);
	this.landMassY = new Array(numPoints*numShapes);
	this.landMassCp1X = new Array(numPoints*numShapes);
	this.landMassCp1Y = new Array(numPoints*numShapes);
	this.landMassCp2X = new Array(numPoints*numShapes);
	this.landMassCp2Y = new Array(numPoints*numShapes);
	this.baseColor = "#";
	this.continentColor = "#";

	var xOffset, yOffset, shapeSize;
	for (i=0; i < numShapes; i++) {
//		xOffset = (Math.random()*.5) + .25;
//		yOffset = (Math.random()*.5) + .25;
//		shapeSize = Math.random()/2;
		xOffset = rnd();
		yOffset = rnd();
		shapeSize = rnd()*2/5;
		for (j=0; j<numPoints; j++) {
			this.landMassX[(i*numPoints)+j] = (Math.sin(((2*Math.PI)/numPoints) * j) * shapeSize) + xOffset + ((rnd() * .2) - .1);
			this.landMassY[(i*numPoints)+j] = (Math.cos(((2*Math.PI)/numPoints) * j) * shapeSize) + xOffset + ((rnd() * .2) - .1);
			this.landMassCp1X[(i*numPoints)+j] = this.landMassX[(i*numPoints)+j] + (rnd()*.2) + .1;
			this.landMassCp2X[(i*numPoints)+j] = this.landMassX[(i*numPoints)+j] + (rnd()*.2) + .1;
			this.landMassCp1Y[(i*numPoints)+j] = this.landMassY[(i*numPoints)+j] + (rnd()*.2) + .1;
			this.landMassCp2Y[(i*numPoints)+j] = this.landMassY[(i*numPoints)+j] + (rnd()*.2) + .1;
		}
		
	}

	for (i=0; i<6; i++) {
		this.baseColor = this.baseColor + (randomInteger(9)); 
		this.continentColor = this.continentColor + (randomInteger(9)); 
	}
	this.baseColor = "rgba("+(0+randomInteger(204))+","+(0+randomInteger(204))+","+(0+randomInteger(204))+",1)";
	this.continentColor = "rgba("+(100+randomInteger(204))+","+(100+randomInteger(204))+","+(100+randomInteger(204))+",1)";
}
/*
function MissionParameter(fromSystem, toSystem, task, quantity, deadline) {
	this.fromSystem = fromSystem;
	this.toSystem = toSystem;
	this.task = task;
	this.quantity = quantity;
	this.deadline = deadline;
}

function MissionResult(type, amount) {
	this.type = type;
	this.result = result;
}
*/
function Mission(missionName, missionDescription, sourcePort, targetPort, completionPort, timeLimit, duringKarma, successSourceKarma, successTargetKarma, failureSourceKarma, failureTargetKarma, successCash, failureCash, cargoType, cargoQuantity, specialCargoName, targetType, targetQuantity, successSourceGovernment, successSourceSecurity, successTargetGovernment, successTargetSecurity)
{

	this.missionName = missionName;
	this.missionDescription = missionDescription;
	
	this.sourcePort = sourcePort;
	this.targetPort = targetPort;
	this.timeLimit = timeLimit;

	this.duringKarma = duringKarma;
	
	this.successSourceKarma = successSourceKarma;
	this.successTargetKarma = successTargetKarma;
	
	this.failureSourceKarma = failureSourceKarma;
	this.failureTargetKarma = failureTargetKarma;
	
	this.successCash = successCash;
	this.failureCash = failureCash;
	
	this.cargoType = cargoType;
	this.cargoQuantity = cargoQuantity;
	this.specialCargoName = specialCargoName;
	
	this.targetType = targetType;
	this.targetQuantity = targetQuantity;
	
	this.completionPort = completionPort;
	
	this.successSourceGovernment = successSourceGovernment;
	this.successSourceSecurity = successSourceSecurity;
	
	this.successTargetGovernment = successTargetGovernment;
	this.successTargetSecurity = successTargetSecurity;
	
	this.missionStatus = "available";
	
	
	
//	this.missionStartResults = new Array();
//	this.missionCompleteResults = new Array();
//	this.missionFailResults = new Array();
//	this.missionParameters = new Array();

}

function Crewman(firstName,lastName, navigation, gunnery, engineering, haggling, cost, face)
{
	this.ID = globalCurrentID;
	globalCurrentID++;
	this.firstName = firstName;
	this.lastName = lastName;
	this.navigation = navigation;
	this.gunnery = gunnery;
	this.engineering = engineering;
	this.haggling = haggling;
	this.cost = cost;
	this.face = face;
}

function ShipPart(shipName, partNumber, maxSpeed, maxCargo, maxCrew, maxFuel, firepower, maxArmor, x, y, maxAttachments, baseCost, rootPart, posture)
{
	var i;
	this.ID = globalCurrentID;
	globalCurrentID++;
	this.partName = shipName;
	this.partNumber = partNumber;
	this.partType = "";
	this.maxSpeed = maxSpeed;
	this.speed = 0;
	this.maxCargo = maxCargo;
	this.curCargo = 0;
	this.cargo = [0, 0, 0, 0, 0, 0, 0, 0];
	this.maxCrew = maxCrew;
	this.curCrew = 0;
	this.maxFuel = maxFuel;
	this.fuel=maxFuel;
	this.firepower=firepower;
	this.maxArmor=maxArmor;
	this.armor=maxArmor;
	this.x = x;
	this.y = y;
	this.width = 120;
	this.height = 120;
	this.posture = posture;
	this.target = -1;
//	alert(maxAttachments);

	if (this.maxCrew > 8) {
		this.maxCrew = 8;
	}
	
	this.attachments = new Array(maxAttachments);
	this.crew = new Array(maxCrew);
	this.baseCost = baseCost;
	this.bgImages = new Array(Math.ceil((maxAttachments+1)/2));
	this.midImages = new Array(Math.ceil((maxAttachments+1)/2));
	this.fgImages = new Array(Math.ceil((maxAttachments+1)/2));
	this.highlight = false;
	this.rootPart = rootPart;
	this.fgDiv = document.createElement("div");
	this.midDiv = document.createElement("div");
	this.bgDiv = document.createElement("div");
	this.healthDiv = document.createElement("div");
	this.healthContainerDiv = document.createElement("div");
	this.highlightDiv = document.createElement("div");
	this.explosionX = 40;
	this.explosionY = 40;
	this.explosionTime = 0;


	this.adjMaxSpeed = maxSpeed;
	this.adjMaxCargo = maxCargo;
	this.adjMaxFuel = maxFuel;
	this.adjMaxArmor = maxArmor;
	this.adjFirepower = firepower;
	this.adjProfitMargin = 1;
	this.adjBaseCost = baseCost;
	
	this.adjHaggling = 0;
	this.adjNavigation = 0;
	this.adjGunnery = 0;
	this.adjEngineering = 0;

	for (i=0; i<this.bgImages.length; i++)
	{
		this.bgImages[i] = Math.floor(Math.random() * 8);
		this.midImages[i] = Math.floor(Math.random() * 8);
		this.fgImages[i] = Math.floor(Math.random() * 8);
	}
	
	this.imageSeed = Math.floor(10000000 * Math.random());
	
	this.shipPosition = "";
	
	calculateAdjustedValues(this);
}



jsFilesLoaded = jsFilesLoaded + 1;

