I'm toying around with an industry NewGRF which borrows a feature from dSPI, namely the idea of handling "electricity" by having a power plant store it's production value in the persistent storage of the town as related parent object of the industry. I looked into the sources of dSPI how this is achieved and now I'm trying to copy it - but I fail to get it working. The sources for dSPI mention that this is somewhat tricky and finicky with jumping between SELF and PARENT, as well as somehow requiring STORE_TEMP and STORE_PERM beforehand, so I'm a bit confused on the details here.
The industry itself works and produces "electricity", which can also be stored in the persistent storage of the industry itself. But I completely fail to set a value of produced "electricity" in the persistent storage of the town. In some cases I do not even get to see any persistent registers for the town in the info window within the game, and I have not yet figured out which piece of my code changes that behavior.
Relevant code snippet:
Code: Select all
switch(FEAT_INDUSTRIES, PARENT, set_power_for_city, power,
[STORE_PERM(power, 5)]
{ return; }
switch(FEAT_INDUSTRIES, SELF, power_plant_switch_produce,
[ // check incoming_cargo_waiting, calculate how much to produce, ...
// power_produced is some calculated value based on incoming_cargo_waiting
STORE_TEMP(power_produced, 0),
// store in persistent storage of industry, this works
STORE_PERM(LOAD_TEMP(0), 0),
// try storing in persistent storage of town, this does not do anything
// I also tried other forms of calling that switch, which did not change anything
set_power_for_city(LOAD_TEMP(0))
])
{
power_plant_produce; // this is the actual produce block where the production happens
}
// ...
item(FEAT_INDUSTRIES, ...) {
graphics {
produce_256_ticks: power_plant_switch_produce;
}
}
Code: Select all
switch(FEAT_INDUSTRIES, PARENT, add_power_demand, demand,
[
STORE_PERM(LOAD_PERM(3) + demand, 3)
])
{
return;
}
switch(FEAT_INDUSTRIES, SELF, factory_switch_produce,
[
// check incoming_cargo_waiting, calculate amount of electricity needed
// for maximum production
STORE_TEMP(electricity_needed, 2),
// store value in persistent storage of town, this works, weirdly enough
add_power_demand(LOAD_TEMP(2)),
// further calculation of production amount based on available electricity
// since the persistent storage is not updated correctly by the power plant,
// production is calculated to be zero here
])
{
factory_produce;
}
Regards,
Uwe