Allow trigger_target_mask to be an empty table

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Post Reply
Pi-C
Smart Inserter
Smart Inserter
Posts: 1651
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Allow trigger_target_mask to be an empty table

Post by Pi-C »

What?
Every entity prototype has a trigger_target_mask. If it is not specified, or if it is set to nil, it will default to {"common"}. If empty lists could be used, modders would be able to create entity prototypes that can't be attacked, without wasting valuable resources. However, currently assigning an empty list will crash the game on loading.
Why?
The trigger_target_mask of an entity prototype is an array of TriggerTargetType. Given two prototypes A and B, if A.trigger_target_mask and B.attack_target_mask have at least one TriggerTargetType in common, entities based on A may be attacked by entities based on B unless A.trigger_target_mask and B.ignore_target_mask share a TriggerTargetType as well.

A mod can define a new TriggerTargetType and add it to the trigger_target_mask of one entity prototype as well as the ignore_target_mask of other entity prototypes to prevent attacks. However, TriggerTargetTypes are a rare asset, as only 56 instances may be defined. There may be different mods that want to protect their entity prototypes by creating a new TriggerTargetType. It's likely that each mod would use its own TriggerTargetType. As only so few of these can be created, using multiple TriggerTargetTypes to the same end seems like a waste of valuable resources.
Solution
If entity prototype were allowed to have an empty trigger_target_mask (i.e. "{ }"), there would be nothing in it that could match a TriggerTargetType from any attack_target_mask. Thus, entities based on such a prototype could never be attacked, while no new TriggerTargetType would have to be created. Even better: As no new TriggerTargetType has been defined, it would also be unnecessary to change any ignore_target_mask!

In most cases, the default trigger_target_mask -- i.e. {"common"} -- is what should be used, so I'm not arguing for changing the default value. But if somebody intentionally changes the trigger_target_mask to an empty list, it's likely done for a reason and should not break the game.
Use case
I suppose empty target_trigger_masks are mainly relevant for modded entities that are hidden, or part of a compound entity. My particular use case is an invisible radar that will give free radar coverage of a one-chunk area to a particular force (here, it would not be possible to create a separate force for all the radars). The invisible radars can't be placed by players; they are meant to be indestructible, so they are immune to all damage types. However, radars are considered to be military structures, so enemy units and turrets would continuously attack them if the default trigger_target_mask was used.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

posila
Factorio Staff
Factorio Staff
Posts: 5202
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

Re: Allow trigger_target_mask to be an empty table

Post by posila »

Not that the request is invalid, but in your particular case, since you seem to create the entity through the script anyway...
https://lua-api.factorio.com/1.1.49/Lua ... structible

Pi-C
Smart Inserter
Smart Inserter
Posts: 1651
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Allow trigger_target_mask to be an empty table

Post by Pi-C »

posila wrote:
Wed Dec 15, 2021 7:23 pm
… in your particular case, since you seem to create the entity through the script anyway...
https://lua-api.factorio.com/1.1.49/Lua ... structible
Thanks for the hint! Indeed, this solves my problem with enemy units attacking the invisible radars. But the description is misleading: "When the entity is not destructible it can't be damaged" -- from a user's perspective, an entity with full immunity against all resistances can't be damaged as well, but will be attacked. (Technically, it will take damage, but final_damage will be 0.) I've suggested a change in the documentation.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

Post Reply

Return to “Modding interface requests”