First: Can I count on market.getCommodityData(commodity).getDemand().getDemand().modified to return reasonably accurate values if called before the economy load phase at start? Should I call market.reapplyConditions() first?[/li][/list]
You mean in ModPlugin.onNewGame(), right? Before ModPlugin.onNewGameAfterEconomyLoad()?
At that point, the MarketAPI objects don't even exist.
Second: in Population.java:
float crewAndMarines = market.getDemand(Commodities.MARINES).getRollingAverageStockpileUtility();
crewAndMarines += market.getDemand(Commodities.REGULAR_CREW).getRollingAverageStockpileUtility();
market.getDemand(Commodities.SUPPLIES).getDemand().modifyFlat(id, crewAndMarines * ConditionData.POPULATION_SUPPLIES_FOR_CREW_MARINES);
Barring the getDemand() thing, is there a way to get how much supplies will be demanded in this fashion? Or at least some rule of thumb I can use?
I don't think so, and that's a problem. I think this is one of the things that's making it difficult for the economy to stabilize; I'll have to take a closer look at it at some point.
For now, I would suggest trying a couple of things:
1) Reducing "price variability" for all commodities, to something in the 1-3 range. If it's at 0, prices won't be affect by supply/demand at all. This will affect shortage/disruption events, though, likely making them less profitable. Probably the easier option with more downsides.
2) You might "fudge" the economy after it's loaded, which I'd imagine is what you're already thinking about. So, say you want to make sure supplies are balanced supply/demand wise. In onNewGameAfterEconomyLoad(), you might then:
- Set the average and current stockpiles of supplies everywhere to be equal to the local demand, just so it starts from a good place
- Compute the total demand
- Do whatever market condition fudging necessary to make supply match demand. In a more direct way, i.e. not just adding autofactories (which need a chain of commodities to work properly - if you're lacking ore or whatnot, you may end up underproducing supplies), but just adding a fixed +X supplies supply to autofactories.
In fact, if you do this every month or so, that seems like it wouldn't even be computationally expensive. Figure out total demand for supplies, figure out supply production, and figure out what X should be based on that. All linear time with small data sets.