Page 1 of 1

Using Technology to Upgrade Entity Characteristics

Posted: Wed Jun 15, 2016 2:48 am
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?

Re: Using Technology to Upgrade Entity Characteristics

Posted: Wed Jun 15, 2016 4:28 am
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.)

Re: Using Technology to Upgrade Entity Characteristics

Posted: Wed Jun 15, 2016 11:58 am
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?

Re: Using Technology to Upgrade Entity Characteristics

Posted: Wed Jun 15, 2016 3:47 pm
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.

Re: Using Technology to Upgrade Entity Characteristics

Posted: Thu Jun 16, 2016 12:26 pm
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.

Re: Using Technology to Upgrade Entity Characteristics

Posted: Thu Jun 16, 2016 1:09 pm
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.

Re: Using Technology to Upgrade Entity Characteristics

Posted: Thu Jun 16, 2016 1:29 pm
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 :)

Re: Using Technology to Upgrade Entity Characteristics

Posted: Thu Jun 16, 2016 2:45 pm
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

Re: Using Technology to Upgrade Entity Characteristics

Posted: Thu Jun 16, 2016 3:19 pm
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.

Re: Using Technology to Upgrade Entity Characteristics

Posted: Thu Jun 16, 2016 3:47 pm
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.