package data.scripts.world;

import java.awt.Color;
import java.util.List;

import com.fs.starfarer.api.campaign.CampaignFleetAPI;
import com.fs.starfarer.api.campaign.CargoAPI;
import com.fs.starfarer.api.campaign.FactionAPI;
import com.fs.starfarer.api.campaign.FleetAssignment;
import com.fs.starfarer.api.campaign.SectorAPI;
import com.fs.starfarer.api.campaign.SectorEntityToken;
import com.fs.starfarer.api.campaign.SectorGeneratorPlugin;
import com.fs.starfarer.api.campaign.StarSystemAPI;
import com.fs.starfarer.api.campaign.CargoAPI.CrewXPLevel;
import com.fs.starfarer.api.fleet.FleetMemberType;

@SuppressWarnings("unchecked")
public class SectorGen implements SectorGeneratorPlugin {

	@Override
	public void generate(SectorAPI sector) {
		
		StarSystemAPI system = sector.createStarSystem("Corvus");
		
		SectorEntityToken star = system.initStar("star_yellow", Color.white, 500f);
		
		SectorEntityToken corvusI = system.addPlanet(star, "Corvus I", "desert", 55, 150, 3000, 100);
		SectorEntityToken corvusII = system.addPlanet(star, "Corvus II", "jungle", 235, 200, 4500, 200);
		
		system.addAsteroidBelt(star, 500, 5500, 1000, 150, 300);
		
		SectorEntityToken corvusIII = system.addPlanet(star, "Corvus III", "gas_giant", 200, 300, 7500, 400);
		SectorEntityToken corvusIIIA = system.addPlanet(corvusIII, "Corvus IIIA", "cryovolcanic", 235, 120, 800, 20);
		system.addAsteroidBelt(corvusIII, 50, 1000, 200, 10, 45);
		SectorEntityToken corvusIIIB = system.addPlanet(corvusIII, "Corvus IIIB", "barren", 235, 100, 1300, 60);
		
		SectorEntityToken corvusIV = system.addPlanet(star, "Corvus V", "barren", 0, 100, 10000, 700);
		SectorEntityToken corvusV = system.addPlanet(star, "Corvus IV", "frozen", 330, 175, 12000, 500);
		
	    SectorEntityToken corvusVI = system.addPlanet(star, "Corvus VI", "barren", 155, 145, 13500, 300);
		SectorEntityToken corvusVII = system.addPlanet(star, "Corvus VII", "anomaly", 55, 350, 12000, 300);
		initFactionRelationships(sector);

	}
	
	private void initFactionRelationships(SectorAPI sector) {
		FactionAPI hegemony = sector.getFaction("hegemony");
		FactionAPI tritachyon = sector.getFaction("tritachyon");
		FactionAPI pirates = sector.getFaction("pirates");
		FactionAPI independent = sector.getFaction("independent");
		FactionAPI player = sector.getFaction("player");
		FactionAPI junk_pirates = sector.getFaction("junk_pirates");
        
		player.setRelationship(hegemony.getId(), 0);
		player.setRelationship(tritachyon.getId(), 0);
		player.setRelationship(pirates.getId(), -1);
		player.setRelationship(independent.getId(), 0);
		player.setRelationship(junk_pirates.getId(), 0);

		hegemony.setRelationship(tritachyon.getId(), -1);
		hegemony.setRelationship(pirates.getId(), -1);
		
		junk_pirates.setRelationship("hegemony", -1);
		junk_pirates.setRelationship("tritachyon", -1);
		junk_pirates.setRelationship("pirates", 0);
		junk_pirates.setRelationship("independent", 0);
		junk_pirates.setRelationship("player", 0);             
        
		tritachyon.setRelationship(pirates.getId(), -1);
		tritachyon.setRelationship(independent.getId(), -1);
		
		pirates.setRelationship(independent.getId(), -1);
		
		//Added stuff here - DeathSG
		
		FactionAPI gunrunners = sector.getFaction("gunrunners");
		
		gunrunners.setRelationship("hegemony", -1);
		gunrunners.setRelationship("tritachyon", -1);
		gunrunners.setRelationship("pirates", 0);
		gunrunners.setRelationship("independent", 0);
		gunrunners.setRelationship("player", 0);
		
		//FactionAPI nomads = sector.getFaction("junk_pirates");
		
		//nomads.setRelationship( hegemony.getId(), -1 );
		//nomads.setRelationship( tritachyon.getId(), -1 );
		
		//alien code
		
		FactionAPI alien=sector.getFaction("alien");
		
		alien.setRelationship("hegemony", -1);
		alien.setRelationship("tritachyon", -1);
		alien.setRelationship("pirates", -1);
		alien.setRelationship("independent", -1);
		alien.setRelationship("player", -1);
		alien.setRelationship("nomads", -1);
		alien.setRelationship("junk_pirates", -1);
		alien.setRelationship("scrappers", -1);
		alien.setRelationship("mercenary", -1);
		//end of alien code
		
//		independent.setRelationship(hegemony.getId(), 0);
//		independent.setRelationship(tritachyon.getId(), 0);
//		independent.setRelationship(pirates.getId(), 0);
//		independent.setRelationship(independent.getId(), 0);
//		independent.setRelationship(player.getId(), 0);
		
	}
}