Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 [2]

Author Topic: [0.9.1a] 'Remnant-like' mod factions - Fleet generation issues - Ship Tags  (Read 3059 times)

TrashMan

  • Admiral
  • *****
  • Posts: 1314
    • View Profile

I have 1 faction (AI) that should work like Remnant. With bases they spawn near, but I want them to be aggressive (raids)

I also have another faction that does NOT have bases. I just want them to have fleets spawn in random system and travel to random populated worlds to either attacks or scout.

This is the OLD code that definitely doesn't work anymore (still uses old FleetFactory):
Code
package data.scripts.world;

import com.fs.starfarer.api.Global;
import com.fs.starfarer.api.Script;
import com.fs.starfarer.api.campaign.*;
import com.fs.starfarer.api.fleet.FleetMemberAPI;
import com.fs.starfarer.api.fleet.FleetMemberType;
import com.fs.starfarer.api.impl.campaign.fleets.FleetFactory;
import com.fs.starfarer.api.impl.campaign.ids.Commodities;
import com.fs.starfarer.api.impl.campaign.ids.ShipRoles;
import org.apache.log4j.Logger;

import java.util.Random;

import static com.fs.starfarer.api.Global.getSector;



StarSystemAPI system = Global.getSector().getStarSystems().get(...);
if (system.getAsteroids().size() == 0) {
//does not have asteroids
}
else {
//has asteroids
}



public class FleetSpawner {

    public static Logger log = Global.getLogger(FleetSpawner.class);

    public static void rock_spawner()
    {
        int fleets = getSector().getEntitiesWithTag("generated_rock").size();
        //Global.getSector().getCampaignUI().addMessage("Total number of AI fleets: "+ai_fleets);

                String target_name = "";
                target_name = xle_mining_sites[rnd.nextInt(xle_mining_sites.length)];
                SectorEntityToken target = getSector().getStarSystem(target_name).getStar();

Random rnd;
for (StarSystemAPI system : Global.getSector().getStarSystems()) {
if (system.getAsteroids().size() == 0) {
//does not have asteroids
}
else {
//has asteroids
if (rnd.nextInt(8) >= 4) {
CampaignFleetAPI fleet = FleetFactory.createGenericFleet("ROCK", "Beast", 1f, 0);
fleet.getFleetData().sort();
FleetFactory.finishAndSync(fleet);
system.getContainingLocation().addEntity(fleet);

                    system.getContainingLocation().addEntity(fleet);
                    fleet.setLocation(system.getLocation().x + (float)Math.random()*1000, system.getLocation().y - (float)Math.random()*1000);
                    fleet.addAssignment(FleetAssignment.GO_TO_LOCATION, target, 1000, "traveling to an unknown destination");
                    fleet.addAssignment(FleetAssignment.ORBIT_AGGRESSIVE, target, 30, "feeding at "+target.getName());
                    fleet.addAssignment(FleetAssignment.GO_TO_LOCATION_AND_DESPAWN, system, 1000, "traveling to an unknown destination");
                    fleet.addTag("generated_rock");

                    fleet.getCargo().addCommodity("volatiles", (float) Math.random()*75 + 75);
                    fleet.getCargo().addCommodity("rare_ore", (float) Math.random()*50 + 100);
                    fleet.getCargo().addCommodity("ore", (float) Math.random()*100 + 100);

                    log.info("Spawned a Rock Fly to feed at "+target.getName()+" in "+target_name+" system");


}
}
}
    }


    public static void AI_spawner()
    {
        int ai_fleets = getSector().getEntitiesWithTag("generated_ai").size();
        //Global.getSector().getCampaignUI().addMessage("Total number of AI fleets: "+ai_fleets);



        if (ai_fleets <= 2)
        {
            String spawn_name = "telmun_label_id";
            String target_name = "";
            SectorEntityToken spawn = getSector().getEntityById(spawn_name);
            int fleets_to_spawn = 3;

            Script ai_increase = createAIscript(spawn);

            for (int i=0; i < fleets_to_spawn; i++)
            {

                SectorEntityToken target1 = getSector().getStarSystems(random).getCenter();
                SectorEntityToken target2 = getSector().getStarSystems(random).getCenter();
                SectorEntityToken target3 = getSector().getStarSystems(random).getCenter();

                CampaignFleetAPI fleet = FleetFactory.createGenericFleet("AI", "Scouts", 1f, 0);

                if (spawn.hasTag("+5"))
                {
                    getSector().getFaction("AI").pickShipAndAddToFleet(ShipRoles.COMBAT_LARGE, 1, fleet);
                    getSector().getFaction("AI").pickShipAndAddToFleet(ShipRoles.COMBAT_MEDIUM, 1, fleet);
                    getSector().getFaction("AI").pickShipAndAddToFleet(ShipRoles.COMBAT_MEDIUM, 1, fleet);
                    getSector().getFaction("AI").pickShipAndAddToFleet(ShipRoles.COMBAT_MEDIUM, 1, fleet);
                    getSector().getFaction("AI").pickShipAndAddToFleet(ShipRoles.COMBAT_MEDIUM, 1, fleet);
                    getSector().getFaction("AI").pickShipAndAddToFleet(ShipRoles.COMBAT_SMALL, 1, fleet);
                    getSector().getFaction("AI").pickShipAndAddToFleet(ShipRoles.COMBAT_SMALL, 1, fleet);

                    fleet.getFleetData().sort();
                    FleetFactory.finishAndSync(fleet);

                    spawn.getContainingLocation().addEntity(fleet);
                    fleet.setLocation(spawn.getLocation().x + (float)Math.random()*1000, spawn.getLocation().y - (float)Math.random()*1000);
                    fleet.addAssignment(FleetAssignment.GO_TO_LOCATION, target1, 1000, "traveling to an unknown destination");
                    fleet.addAssignment(FleetAssignment.ATTACK_LOCATION, target1, 30, "attacking "+target1.getName());
                    fleet.addAssignment(FleetAssignment.GO_TO_LOCATION_AND_DESPAWN, spawn, 1000, "traveling to an unknown destination", ai_increase);
                    fleet.addTag("generated_ai_assaulters");
                    fleet.setName("Eradicator Fleet");
                    spawn.removeTag("+5");
                    spawn.removeTag("+4");
                    spawn.removeTag("+3");
                    spawn.removeTag("+2");
                    spawn.removeTag("+1");

                    log.info("Spawned an AI Eradicator fleet to attack "+target1.getName());

                }

                else
                {

                    fleet.getFleetData().sort();
                    FleetFactory.finishAndSync(fleet);

                    spawn.getContainingLocation().addEntity(fleet);
                    fleet.setLocation(spawn.getLocation().x + (float)Math.random()*1000, spawn.getLocation().y - (float)Math.random()*1000);
                    fleet.addAssignment(FleetAssignment.GO_TO_LOCATION, target1, 1000, "traveling to an unknown destination");
                    fleet.addAssignment(FleetAssignment.ORBIT_AGGRESSIVE, target1, 7, "surveying "+target1.getName());
                    fleet.addAssignment(FleetAssignment.GO_TO_LOCATION, target2, 1000, "traveling to an unknown destination");
                    fleet.addAssignment(FleetAssignment.ORBIT_AGGRESSIVE, target2, 7, "surveying "+target2.getName());
                    fleet.addAssignment(FleetAssignment.GO_TO_LOCATION, target3, 1000, "traveling to an unknown destination");
                    fleet.addAssignment(FleetAssignment.ORBIT_AGGRESSIVE, target3, 7, "surveying "+target3.getName());
                    fleet.addAssignment(FleetAssignment.GO_TO_LOCATION_AND_DESPAWN, spawn, 1000, "traveling to an unknown destination", ai_increase);
                    fleet.addTag("generated_ai");


                    log.info("Spawned AI to scout "+target1.getName()+", "+target2.getName()+ " and "+target3.getName());

                    //Global.getSector().getCampaignUI().addMessage("Generated AI fleet to explore "+target1.getName()+", "+target2.getName()+" and "+target3.getName());
                }

                fleet.getCargo().addCommodity("rare_metals", fleet.getCargo().getSpaceLeft()/2);
                fleet.getCargo().addCommodity("volatiles", fleet.getCargo().getSpaceLeft()/2);
            }
        }
    }

    public static void aliens_spawner()
    {
        int ai_fleets = getSector().getEntitiesWithTag("generated_alien").size();
        //Global.getSector().getCampaignUI().addMessage("Total number of AI fleets: "+ai_fleets);


        if (ai_fleets <= 2)
        {
            String spawn_name = "cathedral_label_id";
            String target_name = "";
            SectorEntityToken spawn = getSector().getEntityById(spawn_name);
            int fleets_to_spawn = 4;

            Script ai_increase = createAIscript(spawn);

            for (int i=0; i < fleets_to_spawn; i++)
            {

                SectorEntityToken target = getSector().getStarSystems(random).getCenter();


                if (spawn.hasTag("+5"))
                {
                    CampaignFleetAPI fleet = FleetFactory.createGenericFleet("ALIENS", "Abductors", 1f, 0);
                    Script harvest = createHarvestscript(fleet);

                    getSector().getFaction("ALIENS").pickShipAndAddToFleet(ShipRoles.CARRIER_SMALL, 1, fleet);
                    getSector().getFaction("ALIENS").pickShipAndAddToFleet(ShipRoles.COMBAT_MEDIUM, 1, fleet);
                    getSector().getFaction("ALIENS").pickShipAndAddToFleet(ShipRoles.COMBAT_SMALL, 1, fleet);
                    getSector().getFaction("ALIENS").pickShipAndAddToFleet(ShipRoles.COMBAT_SMALL, 1, fleet);

                    fleet.getFleetData().sort();
                    FleetFactory.finishAndSync(fleet);

                    spawn.getContainingLocation().addEntity(fleet);
                    fleet.setLocation(spawn.getLocation().x + (float) Math.random() * 1000, spawn.getLocation().y - (float) Math.random() * 1000);
                    fleet.addAssignment(FleetAssignment.GO_TO_LOCATION, target, 1000, "traveling to an unknown destination");
                    fleet.addAssignment(FleetAssignment.ORBIT_PASSIVE, target, 14, "abducting populace of "+target.getName(), harvest);
                    fleet.addAssignment(FleetAssignment.GO_TO_LOCATION_AND_DESPAWN, spawn, 1000, "traveling to an unknown destination", ai_increase);
                    fleet.addTag("generated_alien_abductors");
                    spawn.removeTag("+5");
                    spawn.removeTag("+4");
                    spawn.removeTag("+3");
                    spawn.removeTag("+2");
                    spawn.removeTag("+1");

fleet.getCargo().addCommodity("rare_metals", fleet.getCargo().getSpaceLeft()/2);
fleet.getCargo().addCommodity("volatiles", fleet.getCargo().getSpaceLeft()/2);

                    log.info("Spawned Alien Abductors to harrass "+target.getName());
                    //Global.getSector().getCampaignUI().addMessage("Generated AI retaliation fleet to attack "+target1.getName());
                }

                else
                {
                    CampaignFleetAPI fleet = FleetFactory.createGenericFleet("ALIENS", "Probe", 1f, 0);

                    fleet.getFleetData().sort();
                    FleetFactory.finishAndSync(fleet);

                    spawn.getContainingLocation().addEntity(fleet);
                    fleet.setLocation(spawn.getLocation().x + (float) Math.random() * 1000, spawn.getLocation().y - (float) Math.random() * 1000);
                    fleet.addAssignment(FleetAssignment.GO_TO_LOCATION, target, 1000, "traveling to an unknown destination");
                    fleet.addAssignment(FleetAssignment.ORBIT_PASSIVE, target, 7, "probing populace of "+target.getName());
                    fleet.addAssignment(FleetAssignment.GO_TO_LOCATION_AND_DESPAWN, spawn, 1000, "traveling to an unknown destination", ai_increase);
                    fleet.addTag("generated_alien");

fleet.getCargo().addCommodity("rare_metals", fleet.getCargo().getSpaceLeft()/3);
fleet.getCargo().addCommodity("volatiles", fleet.getCargo().getSpaceLeft()/3);



                    log.info("Spawned Alien fleet to probe "+target.getName());
                    //Global.getSector().getCampaignUI().addMessage("Generated AI fleet to explore "+target1.getName()+", "+target2.getName()+" and "+target3.getName());
                }
            }
        }
    }

    private static Script createAIscript(final SectorEntityToken spawn)
    {
        return new Script()
        {
            public void run()
            {
                if (!spawn.hasTag("+5") && spawn.hasTag("+4")) spawn.addTag("+5");
                else if (!spawn.hasTag("+4") && spawn.hasTag("+3")) spawn.addTag("+5");
                else if (!spawn.hasTag("+3") && spawn.hasTag("+2")) spawn.addTag("+5");
                else if (!spawn.hasTag("+2") && spawn.hasTag("+1")) spawn.addTag("+5");
                else if (!spawn.hasTag("+1")) spawn.addTag("+5");

                log.info("Increased AI or Alien activity counter");
            }
        };
    }

    private static Script createHarvestscript(final CampaignFleetAPI fleet)
    {
        return new Script()
        {
            public void run()
            {
                fleet.getCargo().addCommodity(Commodities.ORGANS, fleet.getCargo().getSpaceLeft()/2);

                log.info("Loaded the Abductors with harvested organs");
            }
        };
    }




public static void vnsmain_spawner()
    {
        int vns_mainfleet = getSector().getEntitiesWithTag("vns_mainfleet").size();
        if (vns_mainfleet < 1)
        {
 
            String dest_name = "vaynar";
            String home_name = "avalon";
            SectorEntityToken home = getSector().getEntityById(home_name);
            SectorEntityToken dest = getSector().getEntityById(dest_name);

            home = getSector().getEntityById("avalon");
            log.info("Spawning VNS main fleet in Vaynar.");


            CampaignFleetAPI vns_firstfleet = FleetFactory.createGenericFleet("VNS", "1st Fleet", 1, 200);
                vns_firstfleet.addTag("vns_mainfleet");

            getSector().getFaction("VNS").pickShipAndAddToFleet(ShipRoles.FREIGHTER_MEDIUM, 1, vns_firstfleet);
            getSector().getFaction("VNS").pickShipAndAddToFleet(ShipRoles.TANKER_MEDIUM, 1, vns_firstfleet);


            FleetMemberAPI member = Global.getFactory().createFleetMember(FleetMemberType.SHIP, "vns_archangel_standard");
member.setShipName("VNS Archangel");
member.setFlagship(true);
vns_firstfleet.getFleetData().addFleetMember(member);

            FleetMemberAPI member2 = Global.getFactory().createFleetMember(FleetMemberType.SHIP, "vns_cobra2_assault2");
member2.setShipName("VNS Venom");
vns_firstfleet.getFleetData().addFleetMember(member2);    
            FleetMemberAPI member3 = Global.getFactory().createFleetMember(FleetMemberType.SHIP, "vns_cobrax_advanced");
member3.setShipName("VNS Deimos");
vns_firstfleet.getFleetData().addFleetMember(member3);
            FleetMemberAPI member4 = Global.getFactory().createFleetMember(FleetMemberType.SHIP, "vns_cobrax_advanced");
member4.setShipName("VNS Phobos");
vns_firstfleet.getFleetData().addFleetMember(member4);
            FleetMemberAPI member5 = Global.getFactory().createFleetMember(FleetMemberType.SHIP, "vns_dedalus_elite");
member5.setShipName("VNS Dedalus");
vns_firstfleet.getFleetData().addFleetMember(member5);
            FleetMemberAPI member6 = Global.getFactory().createFleetMember(FleetMemberType.SHIP, "vns_prometheus_elite");
member6.setShipName("VNS Caldabolg");
vns_firstfleet.getFleetData().addFleetMember(member6);
            FleetMemberAPI member7 = Global.getFactory().createFleetMember(FleetMemberType.SHIP, "vns_avenger_mk1_elite");
member7.setShipName("VNS Gae bolg");
vns_firstfleet.getFleetData().addFleetMember(member7);
            FleetMemberAPI member8 = Global.getFactory().createFleetMember(FleetMemberType.SHIP, "vns_paladin_elite");
member8.setShipName("VNS Ascension");
vns_firstfleet.getFleetData().addFleetMember(member8);
            FleetMemberAPI member9 = Global.getFactory().createFleetMember(FleetMemberType.SHIP, "vns_paladin_elite");
member9.setShipName("VNS Tempestus Irae");
vns_firstfleet.getFleetData().addFleetMember(member9);

            FleetMemberAPI member10 = Global.getFactory().createFleetMember(FleetMemberType.SHIP, "vns_perserverance_elite");
member10.setShipName("VNS Eternity");
vns_firstfleet.getFleetData().addFleetMember(member10);
            FleetMemberAPI member11 = Global.getFactory().createFleetMember(FleetMemberType.SHIP, "vns_avenger_mk2_elite");
member11.setShipName("VNS Radiance");
vns_firstfleet.getFleetData().addFleetMember(member11);


            vns_firstfleet.getCargo().addCrew(vns_firstfleet.getCargo().getMaxPersonnel());
            vns_firstfleet.getCargo().addSupplies(vns_firstfleet.getCargo().getMaxCapacity()/3);
            vns_firstfleet.getCargo().addFuel(vns_firstfleet.getCargo().getMaxFuel());

            vns_firstfleet.getFleetData().sort();
            FleetFactory.finishAndSync(vns_firstfleet);


            home.getContainingLocation().addEntity(vns_firstfleet);
            vns_firstfleet.setLocation(home.getLocation().x + 0, home.getLocation().y + 0);
            vns_firstfleet.addAssignment(FleetAssignment.ORBIT_PASSIVE, home, 3, "preparing for duty");
            vns_firstfleet.addAssignment(FleetAssignment.DEFEND_LOCATION, home, 21, "patrolling around "+home.getName());
            vns_firstfleet.addAssignment(FleetAssignment.ORBIT_AGGRESSIVE, home, 3, "standing down from duty");
            vns_firstfleet.addAssignment(FleetAssignment.GO_TO_LOCATION_AND_DESPAWN, home, 1000, "returning to "+home.getName());
            vns_firstfleet.setPreferredResupplyLocation(home);

            log.info("Spawned VNS main fleet in Vaynar");
        }
    }





    private static String [] rsf_markets =
            {
                    "jangala",
                    "barnard_guard_station",
                    "barnard_gas_station",
                    "chugun",
                    "vostok",
                    "gagarin_shipyard",
                    "gagarin_scrapyard",
                    "denisovka",
                    "denisovka_station",
                    "stal",
                    "rzhavaya",
                    "rzhavaya_sentry_station",
                    "plavka",
            };

    private static String [] isa_markets =
            {
                    "dwarf",
                    "argos_shipyard",
                    "sterilla",
                    "darloth_station",
                    "washingtonia",
                    "jorgia",
                    "ulysses",
                    "simpson",
                    "hiram",
                    "washingtonia",
                    "danbridge",
            };

    private static String [] uin_markets =
            {
                    "achiles_scrapyard",
                    "sands",
                    "archemedes",
                    "centronom_fabricator",
                    "freya",
                    "vella",
                    "selena",
                    "snowball",
            };

    private static String [] xle_markets =
            {
                    "khabara",
                    "khabara_a",
                    "khabara_a_station",
                    "pango",
                    "procyon_guard_station",
                    "omio",
                    "moizi",
                    "uomoz_scrapyard",
            };

    private static String [] ffs_markets =
            {
                    "unity",
                    "adra_station1",
                    "adra_station2",
                    "freedom",
                    "impalo_station",
                    "liberty",
                    "kores_station1",
                    "independence",
            };

    private static String [] all_spawns =
            {
                    "jangala",
                    "barnard_guard_station",
                    "barnard_gas_station",
                    "chugun",
                    "vostok",
                    "gagarin_shipyard",
                    "gagarin_scrapyard",
                    "denisovka",
                    "denisovka_station",
                    "stal",
                    "rzhavaya",
                    "rzhavaya_sentry_station",
                    "plavka",
                    "dwarf",
                    "argos_shipyard",
                    "sterilla",
                    "darloth_station",
                    "washingtonia",
                    "jorgia",
                    "ulysses",
                    "simpson",
                    "hiram",
                    "washingtonia",
                    "danbridge",
                    "achiles_scrapyard",
                    "sands",
                    "archemedes",
                    "centronom_fabricator",
                    "freya",
                    "vella",
                    "selena",
                    "snowball",
                    "khabara",
                    "khabara_a",
                    "khabara_a_station",
                    "pango",
                    "procyon_guard_station",
                    "omio",
                    "moizi",
                    "uomoz_scrapyard",
                    "vixis",
                    "vaynar_guard_station",
                    "avalon",
                    "avalon_shipyard",
"vaynar_pirate",
            };

    private static String [] vns_markets =
            {
                    "vixis",
                    "vaynar_guard_station",
                    "avalon",
                    "avalon_shipyard",
                    "helios",
            };

}
« Last Edit: May 24, 2019, 02:19:48 PM by TrashMan »
Logged

TrashMan

  • Admiral
  • *****
  • Posts: 1314
    • View Profile

There are plenty of tutorials on Starsector modding, but none that cover creating special factions (no markets, just patroling or raiding systems).

That should be rectified.
Logged
Pages: 1 [2]