Using Technology to Upgrade Entity Characteristics

Place to get help with not working mods / modding interface.
Post Reply
pulsar9
Burner Inserter
Burner Inserter
Posts: 14
Joined: Wed Jun 15, 2016 2:19 am
Contact:

Using Technology to Upgrade Entity Characteristics

Post by pulsar9 »

I just started working on a mod but I am having trouble understanding how I can use technology upgrades to upgrade specific characteristics of an entity. suppose I have:

Code: Select all

type = "pipe-to-ground",
name = "pipe-to-ground"
...
fluid_box =
        {
          base_area = 1,
          pipe_covers = pipecoverspictures(),
          pipe_connections =
          {
            { position = {0, -1} },
            {
              position = {0, 1},
              max_underground_distance = 10
            }
          },
        }
...
and I want to change "max_underground_distance" to be something other than 10 when a technology is researched, kinda like the following

Code: Select all

type = "technology",
        name = "pipe-upgrade-1",
        icon = "__base__/graphics/icons/pipe-to-ground.png",
        effects =
        {
          {
            -- This is what I don't know how to do
            type = "max_underground_distance",
            modifier = "50"
          }
        },
How can I go about doing that?

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3700
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Using Technology to Upgrade Entity Characteristics

Post by DaveMcW »

Create a new entity, pipe-to-ground-2. Give it identical stats to pipe-to-ground, except for max_underground_distance = 50.

When the tech is researched, find and replace all pipe-to-ground on the map with pipe-to-ground-2.

For completeness, you should also check in on_init to catch your mod being added to an existing save.

You can look at control.lua in the Blueprint String mod to see how I handle the events. (It spawns a button when the tech is researched.)

pulsar9
Burner Inserter
Burner Inserter
Posts: 14
Joined: Wed Jun 15, 2016 2:19 am
Contact:

Re: Using Technology to Upgrade Entity Characteristics

Post by pulsar9 »

Thanks you for your response. What you suggests make sense though I was hoping that the technology type was extensible enough that I could add a custom effect which would modify the existing pipe to ground. Is the way I am trying to do this truly impossible?

Rseding91
Factorio Staff
Factorio Staff
Posts: 13229
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Using Technology to Upgrade Entity Characteristics

Post by Rseding91 »

pulsar9 wrote:Thanks you for your response. What you suggests make sense though I was hoping that the technology type was extensible enough that I could add a custom effect which would modify the existing pipe to ground. Is the way I am trying to do this truly impossible?
Yes, pipe to ground distances are determined by the prototype of the entity.

If the distance was modifiable runtime it would need to be included in the save file for each pipe-to-ground increasing the save file size, save time, load time, and memory usage while running.
If you want to get ahold of me I'm almost always on Discord.

pulsar9
Burner Inserter
Burner Inserter
Posts: 14
Joined: Wed Jun 15, 2016 2:19 am
Contact:

Re: Using Technology to Upgrade Entity Characteristics

Post by pulsar9 »

Rseding91 wrote: Yes, pipe to ground distances are determined by the prototype of the entity.

If the distance was modifiable runtime it would need to be included in the save file for each pipe-to-ground increasing the save file size, save time, load time, and memory usage while running.
Alright, look like I will need to change my approach.
Thank again.

ratchetfreak
Filter Inserter
Filter Inserter
Posts: 952
Joined: Sat May 23, 2015 12:10 pm
Contact:

Re: Using Technology to Upgrade Entity Characteristics

Post by ratchetfreak »

Rseding91 wrote:
pulsar9 wrote:Thanks you for your response. What you suggests make sense though I was hoping that the technology type was extensible enough that I could add a custom effect which would modify the existing pipe to ground. Is the way I am trying to do this truly impossible?
Yes, pipe to ground distances are determined by the prototype of the entity.

If the distance was modifiable runtime it would need to be included in the save file for each pipe-to-ground increasing the save file size, save time, load time, and memory usage while running.
By a grand total of 4 bytes each.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13229
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Using Technology to Upgrade Entity Characteristics

Post by Rseding91 »

ratchetfreak wrote:
Rseding91 wrote:
pulsar9 wrote:Thanks you for your response. What you suggests make sense though I was hoping that the technology type was extensible enough that I could add a custom effect which would modify the existing pipe to ground. Is the way I am trying to do this truly impossible?
Yes, pipe to ground distances are determined by the prototype of the entity.

If the distance was modifiable runtime it would need to be included in the save file for each pipe-to-ground increasing the save file size, save time, load time, and memory usage while running.
By a grand total of 4 bytes each.
4 bytes * number of pipes yes. Then take that same reasoning and apply it to every other thing that isn't part of the save file and now the save file is double or more the size :)
If you want to get ahold of me I'm almost always on Discord.

ratchetfreak
Filter Inserter
Filter Inserter
Posts: 952
Joined: Sat May 23, 2015 12:10 pm
Contact:

Re: Using Technology to Upgrade Entity Characteristics

Post by ratchetfreak »

Rseding91 wrote:
ratchetfreak wrote: By a grand total of 4 bytes each.
4 bytes * number of pipes yes. Then take that same reasoning and apply it to every other thing that isn't part of the save file and now the save file is double or more the size :)
unless it's just the prototype

then it's 4 bytes * number of entitytypes of that prototype

Rseding91
Factorio Staff
Factorio Staff
Posts: 13229
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Using Technology to Upgrade Entity Characteristics

Post by Rseding91 »

ratchetfreak wrote:unless it's just the prototype

then it's 4 bytes * number of entitytypes of that prototype
huh? I'm not understanding what you're saying.
If you want to get ahold of me I'm almost always on Discord.

ratchetfreak
Filter Inserter
Filter Inserter
Posts: 952
Joined: Sat May 23, 2015 12:10 pm
Contact:

Re: Using Technology to Upgrade Entity Characteristics

Post by ratchetfreak »

Rseding91 wrote:
ratchetfreak wrote:unless it's just the prototype

then it's 4 bytes * number of entitytypes of that prototype
huh? I'm not understanding what you're saying.
Instead of letting the prototypes be immutable after game startup you can let research and mod code change them and save those changes to the savefile.

Then the running ram will remain the same, (the prototypes will need to be regenerated from base when starting a new game but can be loaded in from the save game on load). The save file only grows in proportion of how many entities prototypes there are.

Then the hard part is making sure the change propagates to all the entities of that prototype.

Post Reply

Return to “Modding help”