Been fiddling around with this for an hour or so. It's simple, and it seems to work well. The idea is that inventory in an orbital station is randomly eaten up as time progresses, providing the feeling that you're not the only one making purchases from stations. With a little tweaking, this can easily prevent a station from having boatloads of crew, fuel, and supplies in your mod. It can also make resupplying more interesting, as perhaps one station will not have enough inventory to satisfy your demand.
I haven't attempted to try to do this with weapons yet, as I'm short on time. If anyone has any ideas on how to do that, feel free to respond, as I'd love to know.
Also, thanks to vorpal+5 because I used his dynamic reinforcements script as a simple template for this.
Here's the code:
package data.scripts.world.corvus;
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;
import com.fs.starfarer.api.campaign.FactionAPI;
import com.fs.starfarer.api.campaign.StarSystemAPI;
import com.fs.starfarer.api.campaign.CargoAPI.CrewXPLevel;
import com.fs.starfarer.api.fleet.FleetMemberType;
import com.fs.starfarer.api.Global;
import com.fs.starfarer.api.Script;
import data.scripts.world.BaseSpawnPoint;
import java.util.List;
@SuppressWarnings("unchecked")
public class stationrapist extends BaseSpawnPoint {
private final SectorEntityToken station;
public stationrapist(SectorAPI sector, LocationAPI location, float daysInterval, int maxFleets, SectorEntityToken anchor, SectorEntityToken station) {
super(sector, location, daysInterval, maxFleets, anchor);
this.station = station;
}
@Override
public CampaignFleetAPI spawnFleet() {
CargoAPI cargo = station.getCargo();
//sets up all the different cargo items, and gets their amounts
float supplies = cargo.getSupplies();
float fuel = cargo.getFuel();
float crewg = cargo.getCrew(CrewXPLevel.GREEN);
float crewr = cargo.getCrew(CrewXPLevel.REGULAR);
float marines = cargo.getMarines();
int f;
//As long as the supplies at a station are greater than or equal to 400, there's a 16% chance that this code will run
if ((supplies >= 400) && ((float) Math.random() > 0.84)) {
//the 60s here are the minimum value that can be removed. 350 is the maximum value. Make sure the maximum value is below the value in the if statement above, which is 400 here.
//Otherwise, you might get negatives and I don't know how Starfarer will like that.
f = 60 + (int)(Math.random() * ((350 - 60) + 1));
cargo.removeSupplies(f);
//uncomment this to get an ingame notification when this code runs
//Global.getSectorAPI().addMessage("Station rapist-supplies");
}
if ((fuel >= 600) && ((float) Math.random() > 0.66)) {
f = 160 + (int)(Math.random() * ((350 - 160) + 1));
cargo.removeFuel(f);
//Global.getSectorAPI().addMessage("Station rapist-fuel");
}
if ((crewg >= 700) && ((float) Math.random() > 0.95)) {
f = 10 + (int)(Math.random() * ((120 - 10) + 1));
cargo.removeCrew(CrewXPLevel.GREEN,f);
//Global.getSectorAPI().addMessage("Station rapist-green crew");
}
if ((crewr >= 260) && ((float) Math.random() > 0.84)) {
f = 20 + (int)(Math.random() * ((190 - 20) + 1));
cargo.removeCrew(CrewXPLevel.REGULAR,f);
//Global.getSectorAPI().addMessage("Station rapist-regular crew");
}
if ((marines >= 60) && ((float) Math.random() > 0.91)) {
f = 6 + (int)(Math.random() * ((35 - 6) + 1));
cargo.removeMarines(f);
//Global.getSectorAPI().addMessage("Station rapist-marines");
}
//Veteran and elite crew weren't added because they're rare enough as it is, but if you do want them to be removed, it should be easy to copy.
CampaignFleetAPI derp = null;
return derp;
}
}
And you'll need one of these lines in your corvus.java file for the station you want this script to run on:
stationrapist NAMEHERE = new stationrapist(sector, system, 1, 999, token, STATIONHERE);
system.addSpawnPoint(NAMEHERE);
Sorry about the... uh... crude name, but that's how I keep myself entertained while programming. Those of you who have looked through Ascendency's betrayal script should know that