Page 1 of 1

Tweaking the biters

Posted: Tue Jan 20, 2015 1:29 am
by Taehl
Hello again. I'm starting to poke around the files a little, see what's available to tinker with. I found there's apparently a "spawning_cooldown" table in the biter-spawner which looks promising. Now, if I understand correctly, one cannot simply change such variables directly, I have to use "data:extend()", right? Could someone please explain that method to me? Would I do something like this?

Code: Select all

data:extend( {
	{
		type = "unit-spawner",
		name = "biter-spawner",
		max_health = 700,			-- double health
		healing_per_tick = 0.04,		-- double healing
		spawning_cooldown = { {3600, 1500} },		-- 1/10 spawn rate
	},
} )
Also, any ideas on how I can increase the number of biters spawned per spawning? I mainly want to slow down the spawn rate (spawning waves every 2.5 seconds is ludicrous!), but know that I need to compensate for it. Any ideas besides simply spawning larger groups?

Re: Tweaking the biters

Posted: Tue Jan 20, 2015 2:07 am
by FreeER
Taehl wrote:if I understand correctly, one cannot simply change such variables directly
Actually... You use data:extend(table) to add new data. To modify data that exists in the base game (or another mod) you don't use extend but instead actually do so 'directly' via data.raw (which of course means that what you are modifying needs to be loaded before your mod using the dependencies in info.json, though it defaults to requiring base if you don't specify it at all in the info.json) ex:
--note apologies if this is a bit detailed/obvious for some, I try to provide such explanations for when people use the search feature and find the threads later

Code: Select all

data.raw.type_of_what_you_are_modifying.name_of_what_you_are_modifying.property_of_what_you_are_modifying = new_value
when one of the indexes (the names preceeded by a '.' in the line above) have '-' or spaces in them you have to use the table["name"] format instead of the table.name format so that lua doesn't get confused about what you want (trying to subtract or causing illegal syntax errors).
to modify the spawner you'd use

Code: Select all

data.raw["unit-spawner"]["biter-spawner"] = new_table_with_ALL_info_including_things_you_did_not_change
or

Code: Select all

data.raw["unit-spawner"]["biter-spawner"].max_health = 700
data.raw["unit-spawner"]["biter-spawner"].healing_per_tick = 0.04
-- note you had a nested table for spawning_cooldown, that's not how it is in base!
data.raw["unit-spawner"]["biter-spawner"].spawning_cooldown = {3600, 1500}
that last can be shortened a bit to

Code: Select all

local spawner = data.raw["unit-spawner"]["biter-spawner"]
spawner.max_health = 700
spawner.healing_per_tick = 0.04
spawner.spawning_cooldown = {3600, 1500}
The second/third is the preferred method since you won't overwrite data that some other mod may have modified (including when Factorio updates) when you didn't explicitly intend to.

note: the code would either go in data.lua or a file required by data.lua

Let me know if I didn't make that clear enough :D
For more examples download a mod that modifies the base game and see how they do it (here's a link to DyTech Core's base edits on github)
Also feel free to look at Factorio/data/core/lualib/dataloader.lua :)

Re: Tweaking the biters

Posted: Tue Jan 20, 2015 2:57 am
by Taehl
That's exactly the info I needed! Thanks, FreeER. I'm also going to play with "max_count_of_owned_units" and "max_friends_around_to_spawn". That sounds like it should control the amount of biters spawned, right?

Also, why is "result_units" a function that immediately gets executed to return a table? Couldn't it just be a table? Speaking of "result_units", why is "res[1]" a table with named indexes, but "res[2]" and "res[3]" only have numbered indexes?

Re: Tweaking the biters

Posted: Tue Jan 20, 2015 4:44 am
by FreeER
Sorry for delay in responding, distracted by python + sockets (sentdex tut on YT)...
Taehl wrote:That sounds like it should control the amount of biters spawned, right?
Sounds like :)
Taehl wrote:why is "result_units" a function
So that data.isdemo can be checked (including non-demo defined enemies in the demo == error lol).
Taehl wrote:why is "res[1]" a table with named indexes, but "res[2]" and "res[3]" only have numbered indexes?
Um... this one I have NO idea... it's changed from what I remember pre v11.

Re: Tweaking the biters

Posted: Tue Jan 20, 2015 7:04 am
by Choumiko
Taehl wrote:I'm also going to play with "max_count_of_owned_units" and "max_friends_around_to_spawn". That sounds like it should control the amount of biters spawned, right?
Look at https://forums.factorio.com/forum/vie ... =25&t=7974 and maybe https://forums.factorio.com/forum/vie ... =14&t=7935
Some useful info there ;)