Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@TrueBrain
Last active January 5, 2022 18:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TrueBrain/0d8d7183c6eee45e5ac90bfa57777e29 to your computer and use it in GitHub Desktop.
Save TrueBrain/0d8d7183c6eee45e5ac90bfa57777e29 to your computer and use it in GitHub Desktop.
TrueGRF custom industry production
/*
These next variables can be templated in TrueGRF, and are generated (by TrueGRF) different for each industry.
These values are from the FIRS Steeltown Bulk Terminal industry, and are meant as example.
*/
level_requirements = [
{
level: 0,
percent: 100,
},
{
level: 16,
percent: 150,
},
{
level: 16 * 5,
percent: 300,
},
]
accept_cargo_types = [
ctt.FOOD,
ctt.POTA,
ctt.CHLO,
]
supply_requirement = 8
prod_cargo_types = [
{
cargo: ctt.MNO2,
multiplier: 19,
},
{
cargo: ctt.RUBR,
multiplier: 16,
},
{
cargo: ctt.PLAS,
multiplier: 16,
},
{
cargo: ctt.FECR,
multiplier: 14,
},
{
cargo: ctt.ALUM,
multiplier: 11,
},
]
/*
The following is a replication of what FIRS is doing for a primary industry.
See: https://github.com/andythenorth/firs/blob/4.4.0/src/templates/produce_primary.pynml
*/
function produce_total_supplies_delivered() {
total_delivered = 0;
for (i = 1; i <= 27; i++) {
total_delivered += industry.storage.num_supplies_delivered[i];
}
}
function produce_calculate_current_production_level() {
produce_total_supplies_delivered();
for (level_requirement of level_requirements) {
if (total_delivered / supply_requirement >= level_requirement.level) {
industry.storage.current_production_level = level_requirement.percent;
}
}
}
function update_supplied_cycles_remaining_per_cargo() {
for (cargo of accept_cargo_types) {
industry.storage.supplied_cycles_remaining_cargo[cargo] = max(industry.storage.supplied_cycles_remaining_cargo[cargo] - 1, 0);
}
}
function produce_256_ticks_shift_supplies_delivered() {
for (i = 1; i <= 26; i++) {
industry.storage.num_supplies_delivered[i] = industry.storage.num_supplies_delivered[i + 1];
}
industry.storage.num_supplies_delivered[27] = 0;
}
function production_cargo_arrival() {
for (cargo of accept_cargo_types) {
industry.num_supplies_delivered[27] += industry.incoming_cargo_waiting[cargo]
if (industry.incoming_cargo_waiting[cargo] > 0) {
industry.storage.supplied_cycles_remaining_cargo[cargo] = 28;
}
}
produce_calculate_current_production_level();
inputs = {};
for (cargo of accept_cargo_types) {
inputs[cargo] = industry.incoming_cargo_waiting[cargo];
}
return [inputs, {}];
}
function production_every_256_ticks() {
produce_calculate_current_production_level();
update_supplied_cycles_remaining_per_cargo();
produce_256_ticks_shift_supplies_delivered();
outputs = {}
for (cargo of prod_cargo_types) {
outputs[cargo.label] = cargo.multiplier * industry.production_level * industry.storage.base_prod_factor * industry.storage.current_production_level / 16 / 16 / 100;
}
return [{}, outputs];
}
function production_initial() {
industry.storage.base_prod_factor = 16;
return 16;
}
cb = {
production_cargo_arrival,
production_every_256_ticks,
production_initial,
production_change_monthly: () => 0,
production_change_random: () => 0,
}
/*
Similar to the above, but based on 2TallTyler's Lumbarjack Industries, the Coal Mine.
See: https://github.com/2TallTyler/lumberjack_industries/blob/main/src/coal_mine.nml
*/
function production_cargo_arrival() {
inputs = {}
inputs[ctt.FUEL] = max(0, industry.incoming_cargo_waiting[ctt.FUEL] - 4096);
return inputs;
}
function production_every_256_ticks() {
inputs = {}
outputs = {}
if (industry.incoming_cargo_waiting[ctt.FUEL] >= 3) {
inputs[ctt.FUEL] += 3;
outputs[ctt.COAL] += 16;
}
outputs[ctt.COAL] += 16;
return [inputs, outputs];
}
cb = {
production_cargo_arrival,
production_every_256_ticks,
production_initial: () => 1,
production_change_monthly: () => 0,
production_change_random: () => 0,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment