286
Modding / Quick Iteration through Stations
« on: September 03, 2012, 11:07:23 AM »
Heyas, was wanting to improve the implementation of the Station Supply limiter and make it less static, because of something else I wanted to do. Right now, each SupplyControl is an instance, basically a different operation:
Problem is, I'm having issues iterating through Stations, generically.
I tried this out, but I guess I'm still not getting the concept of how to do this with Java (feeling stupid, if it was Lua, I'd have it done already). This causes a crash, saying that there isn't any such method, even though StarSystemAPI is loaded. I was thinking it needs a SectorEntity as a condition, but I don't want to call ever planet, search for stations, etc., at least not more than the very first time; I'd like to build a list that this iterates through every cycle and then does the whole SupplyControl script. Then it can quit being static. If anybody's got any ideas about how to clear this up (and in general, it'd be nice to also be able to get lists of Spawn, Planet, etc. objects in this way) I'd appreciate it, it'd let me move on to the next part of my experiment without having a bunch of static junk floating around in my code
Spoiler
Relevant Corvus code:
Supply Control (mainly not written by me, but by Ventris):
Code
SectorEntityToken hegemonyStation = system.addOrbitalStation(system.getEntityByName("Corvus II"), 45, 300, 50, "Orbital Station", "hegemony");
SupplyControl controller = new SupplyControl(sector, system, 1f, 999, system.getEntityByName("Corvus IIIA"), hegemonyStation);
system.addSpawnPoint(controller);
SectorEntityToken tritachyonStation = system.addOrbitalStation(system.getEntityByName("Corvus V"), 45, 300, 50, "Corporate HQ", "tritachyon");
SupplyControl controller2 = new SupplyControl(sector, system, 1f, 999, system.getEntityByName("Corvus IIIA"), tritachyonStation);
system.addSpawnPoint(controller2);
SectorEntityToken pirateStation = system.addOrbitalStation(system.getEntityByName("Corvus IIIA"), 45, 300, 50, "Hidden Base", "pirates");
SupplyControl controller3 = new SupplyControl(sector, system, 1f, 999, system.getEntityByName("Corvus IIIA"), pirateStation);
system.addSpawnPoint(controller3);
Supply Control (mainly not written by me, but by Ventris):
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 SupplyControl extends BaseSpawnPoint {
private final SectorEntityToken station;
public SupplyControl(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()
{
/*
StarSystemAPI theStations = getOrbitalStations();
for (int i = 0; i < theStations.length - 1; i++)
{
Global.getSectorAPI().addMessage(theStations[i]);
}*/
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;
int amt;
int i;
//this randomly removes weapons from a station.
List weaponIds = getSector().getAllWeaponIds();
for (int w = 0; w < weaponIds.size(); ++w)
{
i=cargo.getNumWeapons((String)weaponIds.get(w));
//4% chance each day that a weapon will be removed.
if ((float) Math.random() > 0.96)
{
amt = (int)(Math.random() * ((i - 1)));
if (amt > 0)
{
cargo.removeWeapons((String)weaponIds.get(w),amt);
//Global.getSectorAPI().addMessage("Supply Control -Weapon");
}
}
}
//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 >= 1000) && (supplies <= 2000) && ((float) Math.random() > 0.76))
{
//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("Supply Control is truncating supplies");
}
if (supplies > 2000) {
f = (int)(supplies - 2000);
cargo.removeSupplies(f);
//Global.getSectorAPI().addMessage("Supply Control is truncating lots of supplies");
}
if ((fuel >= 600) && ((float) Math.random() > 0.60))
{
f = 160 + (int)(Math.random() * ((350 - 160) + 1));
cargo.removeFuel(f);
//Global.getSectorAPI().addMessage("Supply Control -fuel");
}
if (fuel > 2000) {
f = (int)(fuel - 2000);
cargo.removeFuel(f);
}
if ((crewg >= 700) && ((float) Math.random() > 0.93))
{
f = 10 + (int)(Math.random() * ((120 - 10) + 1));
cargo.removeCrew(CrewXPLevel.GREEN,f);
//Global.getSectorAPI().addMessage("Supply Control -green crew");
}
if ((crewr >= 500) && ((float) Math.random() > 0.80)) {
f = 20 + (int)(Math.random() * ((190 - 20) + 1));
cargo.removeCrew(CrewXPLevel.REGULAR,f);
//Global.getSectorAPI().addMessage("Supply Control -regular crew");
}
if ((marines >= 60) && ((float) Math.random() > 0.87)) {
f = 6 + (int)(Math.random() * ((35 - 6) + 1));
cargo.removeMarines(f);
//Global.getSectorAPI().addMessage("Supply Control -marines");
}
//Veteran and elite crew weren't added because they're rare enough as it is, but if you do want them to be gradually removed, it should be easy to copy.
CampaignFleetAPI derp = null;
return derp;
}
}
[close]
Problem is, I'm having issues iterating through Stations, generically.
I tried this out, but I guess I'm still not getting the concept of how to do this with Java (feeling stupid, if it was Lua, I'd have it done already). This causes a crash, saying that there isn't any such method, even though StarSystemAPI is loaded. I was thinking it needs a SectorEntity as a condition, but I don't want to call ever planet, search for stations, etc., at least not more than the very first time; I'd like to build a list that this iterates through every cycle and then does the whole SupplyControl script. Then it can quit being static. If anybody's got any ideas about how to clear this up (and in general, it'd be nice to also be able to get lists of Spawn, Planet, etc. objects in this way) I'd appreciate it, it'd let me move on to the next part of my experiment without having a bunch of static junk floating around in my code
Code
/*
StarSystemAPI theStations = getOrbitalStations();
for (int i = 0; i < theStations.length - 1; i++)
{
Global.getSectorAPI().addMessage(theStations[i]);
}*/