Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Starsector 0.97a is out! (02/02/24); New blog post: Simulator Enhancements (03/13/24)

Author Topic: How I find the vanilla market disruption event triggers to mod them? How I copy?  (Read 2700 times)

speeder

  • Captain
  • ****
  • Posts: 364
    • View Profile

I want to change the vanilla market disruption events (food shortage and market disruption due to combat, both).

I also want to create my own similar events (I want to make one based on actual supply and demand available, a event for oversupply and another for excessive demand, or something like that).

How I do that? I found that the food shortage has an Event and an Condition, but I didn't found where the Event is fired, neither where the Condition is applied (and unapplied).
Logged

Histidine

  • Admiral
  • *****
  • Posts: 4661
    • View Profile
    • GitHub profile

The vanilla events are controlled from CoreEventProbabilityManager (look for updateFoodShortageProbatility and startTradeDisruptionEventsIfNeeded). The events add the conditions (market.addCondition()).

To alter the event behaviour, make your own event class (inherit from the vanilla one) and reference it in your events.json. Example from Nexerelin:

Code: json
# vanilla overrides
"investigation":{
"script":"exerelin.campaign.events.ExerelinInvestigationEvent",
},
"investigation_smuggling":{
"script":"exerelin.campaign.events.ExerelinInvestigationEventSmuggling",
},
"rep_tracker":{
"script":"exerelin.campaign.events.ExerelinRepTrackerEvent",
},
"faction_commission":{
"script":"exerelin.campaign.events.ExerelinFactionCommissionMissionEvent",
},
"faction_hostility":{
"probabilityMult":0,    #should disable it outright
},

To make your own events, just do a CampaignEventListener/EveryFrameScript and run it at start. Inside, track the things you need to and use Global.getSector().getEventManager().startEvent() when the time comes.
Logged

speeder

  • Captain
  • ****
  • Posts: 364
    • View Profile

Thanks!

I already found the event listener, and considered in using EveryFrame, I didn't want to, but I foudn no other decent way...

Anyway, if I use EveryFrame I will have to loop through all markets (including fleet ones! whiel searching for this on the forums I found out that the ICE mod dude managed to make a market that is a fleet O.O), but I don't found yet how.

So, how I loop through all markets? Or there is some event triggered by the markets that I can use instead?
Logged

Histidine

  • Admiral
  • *****
  • Posts: 4661
    • View Profile
    • GitHub profile

Global.getSector().getEconomy().getMarketsCopy();

If for whatever reason you only need to run the script on certain markets instead of all of them, you can add a copy of the script to each market (and only do stuff with that market) instead of adding it to the sector.

(also I'm sure you know this already, but you can use an IntervalUtil or some simple custom code to run an event only every day or so instead of every frame)
Logged

speeder

  • Captain
  • ****
  • Posts: 364
    • View Profile

I think I will do like vanilla and check for events every "x" days (vanilla default is 30... it is in a staggered fashion though).

What do you mean add event to the market? (instead of chekign all of them)
Logged

Histidine

  • Admiral
  • *****
  • Posts: 4661
    • View Profile
    • GitHub profile

What do you mean add event to the market? (instead of chekign all of them)
Script, not event (although events can also be global or be tied to a specific market).
For instance, some fleet managers (patrols, Lion's Guard) are added to specific markets and only handle stuff pertaining to that market.
Spoiler
In CoreScript.java:
Code: java
	public void assignPatrolSpawningScripts() {
for (MarketAPI market : Global.getSector().getEconomy().getMarketsCopy()) {
if (SharedData.getData().getMarketsWithoutPatrolSpawn().contains(market.getId())) continue;

//if (market.getFactionId().equals(Factions.PIRATES)) continue;
if (market.getFaction().getCustom().optBoolean(Factions.CUSTOM_NO_PATROLS)) continue;

String id = market.getId();


if (marketsWithAssignedPatrolScripts.contains(id)) continue;
marketsWithAssignedPatrolScripts.add(id);

if (id.equals("sindria")) {
LionsGuardFleetManager script = new LionsGuardFleetManager(market);
SectorEntityToken entity = market.getPrimaryEntity();
entity.addScript(script);
}


PatrolFleetManager script = new PatrolFleetManager(market);
SectorEntityToken entity = market.getPrimaryEntity();
entity.addScript(script);
log.info("Added patrol fleet spawning script to market [" + market.getName() + "]");

// MercAndPirateFleetManager pirateScript = new MercAndPirateFleetManager(market);
// entity.addScript(pirateScript);
// log.info("Added pirate fleet spawning script to market [" + market.getName() + "]");

}
}
[close]

Others, like the EconomyFleetManager and LuddicPathFleetManager are added to the sector (sector.addScript()) and iterate over all markets when they want to do things.
Though you can of course tell them to handle only specific markets/entities/etc. anyway.
Logged