Hostile Trees


Makes trees hate you and your factory. They will do bad things to you and your factory.

Tweaks
3 months ago
1.1 - 2.0
427
Enemies Environment

b setting the forest on fire drops ups

1 year, 9 months ago

I created a world in which there are maximum settings for forest coverage, I also set evolution to 100%:
/c game.forces["enemy"].evolution_factor=1
and when I took a flamethrower and set the forest on fire, over time, as the fire burned the forest more and more, this mod took more and more tick time (80 maximum for me, according to the profiler).
With the profiler I roughly understood the following:
85%(1000ms) - control.lua:35 - processing "on_tick", and inside the most demanding calls:
- 42:count_chunks(surface) 44ms
- 70:if trees.run_coro(story) then 266ms
- 86:local chunk = surface.get_random_chunk() 480ms
- 92:if area_util.has_player_entities(surface, box) and area_util.has_trees(surface, box) 180ms
15%(215ms) - retaliation.lua:193 -
- 199:check_for_minor_retaliation(surface, event) 104ms
- 203:check_for_major_retaliation(surface, event) 68ms
Of course, it’s better to install the profiler yourself and see how
It would be desirable to do something about this, especially considering that with this mod the forest can set itself on fire)

1 year, 9 months ago

Right, I always played with fire spread disabled for this reason. What interval did you check for building attacks? The shorter it is, the more performance impact there is.

Right now the check for trees attacking buildings is implemented as checking random points all over the generated surface, which scales linearly with number of chunks and inversely with attack interval. It's tolerable when that interval is set to something like 5 minutes.

It can probably be done in some smart way where I cache which chunks have buildings placed down or something like that, but I didn't bother to do that yet, since current method is foolproof and good enough for non-megabases and reasonable settings. It's a TODO.

run_coro and retaliation cost so much because of massive amounts of trees dying. Dunno how much can be done there. Maybe coroutines can be made a bit cheaper if I'm smarter about sleeping for N ticks.

1 year, 9 months ago

Also could you share how you profiled the code? Would be useful for me when optimizing.

1 year, 9 months ago
(updated 1 year, 9 months ago)

I tested on default settings. about profiling - you need vscode and some "rain dance".
namely, the plugin
https://marketplace.visualstudio.com/items?itemName=justarandomgeek.factoriomod-debug
and configure it according to the instructions from the repository
https://github.com/justarandomgeek/vscode-factoriomod-debug/blob/HEAD/doc/workspace.md
https://github.com/justarandomgeek/vscode-factoriomod-debug/blob/HEAD/doc/debugadapter.md

1 year, 9 months ago

Right. I'll see if it works on Linux, in 2 weeks at the earliest :(

1 year, 9 months ago

it works, I'm on arch linux myself. the only problem was that I use code - oss and there is not a microsoft plugin repository by default

1 year, 8 months ago

After a way too long break I came back and tried to reproduce this. I burned down a chunk of the forest, something like 6 by 6 chunks, and saw no slowdowns, mod stayed under 0.6ms. Do I need to burn more? Granted, I've been using a branch that doesn't call get_random_chunk() all the time, but it shouldn't be that much of an improvement.

1 year, 8 months ago

I guess it would be best if you attached the save somewhere.

1 year, 8 months ago

For what it's worth, I did come up with some more speed-ups thanks to profiling and merged them in.

1 year, 8 months ago

I guess it would be best if you attached the save somewhere.

I'll try to reproduce this problem, it takes some time and my forest was burning in a large radius

1 year, 8 months ago
(updated 1 year, 8 months ago)

I spent about an hour trying to find a setting that turns off the fire, lol
Also for some reason I can’t access the changelog from the game mod menu

1 year, 8 months ago

I caught the problem, it looks like the entity update took all the resources
Unfortunately, I forgot to enable the replay, but I think this is not a problem, I uploaded the file to my server because... I doubt that this is interesting to anyone except you and me)
https://asvdev.com/file/private/hostileTreeBurningTest.zip

1 year, 8 months ago

Alright, I did some optimizations guided by this save. It wasn't any specific bug, just a bunch of places where I called expensive entity search functions.
I pushed a commit to mod repo, this should give something like 5x performance improvements on this save when ran without debugging.

1 year, 8 months ago

Also I fixed broken changelog format not being picked up by the game.

1 year, 8 months ago
(updated 1 year, 8 months ago)

nice, I think the next step will be a filter for effects that trees can “spit” (so as not to burn each other). maybe I'll do this but first I want to finish my mod by adding synchronized music playback)

New response