Enemy Alert


This mod alerts you when biters are grouping, attacking, or expanding, as well as when spawners start consuming pollution

Utilities
5 months ago
2.0
1.24K

b Crashing error when enemies can attack.

6 months ago

I downloaded rampant, which recommended an enemy alert mod, so I downloaded this one. Rampant comes with a peaceful timer which by default doesn't allow enemies to attack for 20 minutes. Upon reaching the 20 minute timer, and seeing the message in chat "Nauvis:Peacefull mode expired. enemies can attack" the game immediately crashes with this message.

The mod Rampant, fixed (2.0.8) caused a non-recoverable error.
Please report this error to the mod author.

Error while running event RampantFixed::on_unit_group_finished_gathering (ID 152)
The mod Enemy Alert (1.0.1) caused a non-recoverable error.
Please report this error to the mod author.

Error while running event enemy-alert::on_unit_group_finished_gathering (ID 152)
value for required field 'position' is missing
stack traceback:
[C]: in function 'create_entity'
enemy-alert/control.lua:57: in function <enemy-alert/control.lua:48>
stack traceback:
[C]: in function 'start_moving'
RampantFixed/libs/SquadAttack.lua:562: in function 'attackMove'
RampantFixed/libs/SquadAttack.lua:720: in function 'squadDispatch'
RampantFixed/control.lua:947: in function <RampantFixed/control.lua:907>

If necessary I can provide a save file of 15 minutes that can be sped up to reproduce the bug every time, but I achieved it on accident the first time and the first attempt to "reproduce" it and just spam burners for 20 minutes to pollute and make enemies "expand" caused it to crash, so im assuming this is pretty easy to replicate if I can't avoid it.

It is an incompatibility between the mods, if I disable one or the other the save works fine, but never with both, so I'm really unsure what the issue is but nobody has mentioned this yet so I thought I might as well.

6 months ago
(updated 6 months ago)

I've encountered a similar problem with enemies from https://mods.factorio.com/mod/enemyracemanager (ERM), when the event on_unit_group_finished_gathering is fired. Might be the same root cause for the problem, though I didn't check with Rampant.

The problem seems to be that "Enemy Alert" doesn't handle compound commands well, which I guess (maybe) Rampant and ERM fires, maybe base Factorio doesn't (I'm not a modder, I have no clue).

At control.lua:57/59, Enemy Alert tries to access the property command.destination. That works well for all types of commands as defined here https://lua-api.factorio.com/latest/defines.html#defines.command, but not for the compound type, which is itself an array of multiple commands. Within all these commands, there is a property "destination"; but not on the parent compound command.

E.g. this is the result if you hack a "log(serpent.block(group.command))" into control.lua at line 52:


{
commands = {
{
destination = {
x = -75,
y = 52
},
distraction = 1,
pathfind_flags = {
allow_destroy_friendly_entities = false,
allow_paths_through_own_entities = false,
cache = true,
low_priority = false,
no_break = false,
prefer_straight_paths = false
},
radius = 32,
type = 2
},
{
destination = {
x = -18,
y = -146
},
distraction = 1,
radius = 32,
type = 5
}
},
structure_type = 2,
type = 3
}


type 3 is compound, and within it is a type 2 (go_to_location) and a type 5 (attack_area) command. The event probably fired because the compound command contains a type 2, thus Enemy Alert ist triggered, but instead of taking into account the compound command and iterating through the array of commands to find the "real" go_to_location command and get its property "destination", it tries to get "destination" from the parent compound command, which fails.

Whereas a "simple" command looks like this:


{
destination = {
x = -727.12109375,
y = -1083.7578125
},
distraction = 1,
ignore_planner = false,
type = 7
}


On the latter, the property "destination" is defined and Enemy Alert works. On the former, the encapsulated commands all have their property "destination", but not the parent structure, this Enemy Alert fails and crashes Factorio.

5 months ago

Hello, thanks for reporting the issue and debug it. I've published a fix for this (v1.0.2). Please let me know if you encounter any issues

New response