package data.scripts.world;

import com.fs.starfarer.api.campaign.StarSystemAPI;
import com.fs.starfarer.api.campaign.CampaignFleetAPI;
import com.fs.starfarer.api.campaign.FleetAssignment;
import com.fs.starfarer.api.campaign.LocationAPI;
import com.fs.starfarer.api.campaign.SectorAPI;
import com.fs.starfarer.api.campaign.SectorEntityToken;
import com.fs.starfarer.api.campaign.CargoAPI;

public class SBGExecutiveSpawnPoint extends BaseSpawnPoint 
{
 public SBGExecutiveSpawnPoint(SectorAPI sector, LocationAPI location,float daysInterval, int maxFleets,SBGDatabase sbgd) 
	{super(sector, location, daysInterval, maxFleets, null);sbg_database=sbgd;}

	private SBGDatabase sbg_database;

	@Override
	protected CampaignFleetAPI spawnFleet() 
	{
	 String type = null;
	 float r = (float) Math.random();
	 if (r > .7f) type = "salesman";
	 else if (r > .3f) type = "executive1";
	 else type = "executive2";
			 
	 float angle = (float) ((float) Math.random() * Math.PI * 2f);
	 float x = (float) (Math.cos(angle) * 15000f);
	 float y = (float) (Math.sin(angle) * 15000f);
	 SectorEntityToken spawnPoint = getLocation().createToken(x, y);					
													
	 StarSystemAPI system = getSector().getStarSystem("Corvus");
	 String station_name=ShipBuildersGuildSpawnPoint.select_station(system);
	 SectorEntityToken station=system.getEntityByName(station_name);
	
	 CampaignFleetAPI fleet = getSector().createFleet("shipbuilders_guild", type);
	 getLocation().spawnFleet(spawnPoint, 0, 0, fleet);

	 fleet.addAssignment(FleetAssignment.DELIVER_RESOURCES, station, 1000);
	 fleet.addAssignment(FleetAssignment.GO_TO_LOCATION_AND_DESPAWN, spawnPoint, 1000);
	 
	 CargoAPI cargo = fleet.getCargo();
	 sbg_database.add_wp_weapons(cargo,2,1);

	 return fleet;	
	}


}