Page 1 of 1

Blacklist for prototypes turrets shouldn't attack

Posted: Sun Jun 21, 2020 7:21 am
by Pi-C
I'd like to prevent that water turrets can attack certain entities. Currently, if an entity (character/unit-spawner/turret) or unit from an enemy force is in range of a water turret, this water turret will attack it.

Let's say I don't want water turrets to attack spawners and worms. Currently, I listen to on_entity_damaged; if the damage was dealt by a water turret and if the damaged entity was a spawner or a turret (the prototype worms are based on), I restore the health and set turret.shooting_target = nil. I believe it would be way cheaper UPS-wise if I could just set a property like "turret.blacklist_targets = { "unit-spawner", "turret" } directly in the prototype, so the turret wouldn't even try to attack such entities. (Something to that effect already exists in vanilla, with artillery turrets that automatically targeting spawners/worms only.)

It would be even better if we could make that like a filter:

Code: Select all

turret.blacklist_targets = {
	{filter  = "type", type = "unit-spawner"},
	{filter = "type", type = "turret", mode = "or"},
	{filter = "name", name = "small-worm", mode = "and"}
}
This would allow to filter complete classes of entities (e.g. all spawners, including modded ones), but also specific prototypes (e.g. if mods have to abuse some unrelated prototype to make a new entity for some special behavior).

Is there any chance to get that implemented? :-)

Re: Blacklist for prototypes turrets shouldn't attack

Posted: Sun Jun 21, 2020 9:50 am
by posila
I think this is excellent use case for trigger-target-type and trigger_target_mask (71657)

So for 0.18.33 I added, attack_target_mask and ignore_target_mask to turret prototype.

What you'll need to do is to define new trigget-target-type

Code: Select all

  {
    type = "trigger-target-type",
    name = "water-resistant"
  }
and add it to types or entities you want to filter

Code: Select all

local default_target_masks = data.raw["utility-constants"].default.default_trigger_target_mask_by_type
default_target_masks["unit-spawner"] = default_target_masks["unit-spawner"] or { "common" } -- everything should have "common", unless there is specific reason not to 
table.insert(default_target_masks["unit-spawner"], "water-resistant")

local small_worm = data.raw["turret"]["small-worm"]
small_worm.trigger_target_mask = small_worm.trigger_target_mask or default_target_masks["turret"] or { "common" }
table.insert(small_worm.trigger_target_mask, "water-resistant")
and then just use ignore_target_mask on turret prototype

Code: Select all

  ignore_target_mask = { "water-resistant" },
It requires more setup than your suggestion, and relies on defining new trigger target types of which there is very limited number (max 64), but this way it is does have essentially zero impact on performace, and was easy for me to implement.

Re: Blacklist for prototypes turrets shouldn't attack

Posted: Sun Jun 21, 2020 4:58 pm
by Pi-C
posila wrote: Sun Jun 21, 2020 9:50 am I think this is excellent use case for trigger-target-type and trigger_target_mask (71657)
I must have missed those before…
So for 0.18.33 I added, attack_target_mask and ignore_target_mask to turret prototype.
Excellent! I never thought this would be added so quick, so you've made me very happy. Thanks a lot for this great work! :-)
It requires more setup than your suggestion, and relies on defining new trigger target types of which there is very limited number (max 64), but this way it is does have essentially zero impact on performace, and was easy for me to implement.
Given this limit, I imagine that quite a lot of mods would compete for trigger target types (similar to the situation with tiles, where just installing a couple of mods like Alien Biomes, Asphal Roads, and Dectorio will get you to the limit pretty fast). Practically every mod that introduces a new weapon or damage type is a potential participant. It probably would make sense to agree on a common nomenclature, so mods can share trigger target types -- there's no need for having one mod use, say, "water-resistant" and another "my-mod_water" if both are meant to achieve the same thing. Any suggestions from the community before we can use this in our mods? :-)