Biters attack indestructible cars

Place to get help with not working mods / modding interface.
PFQNiet
Filter Inserter
Filter Inserter
Posts: 290
Joined: Sat Sep 05, 2020 7:48 pm
Contact:

Biters attack indestructible cars

Post by PFQNiet »

Normally enemies don't bother attacking indestructible things, since they're... well, indestructible.

But I just drove this indestructible car into a biter camp and got out. They completely ignored me, even when I attacked them myself, instead remaining fixated on the car.

Image
"Guys? I'm right here..."

Any way to prevent this? Happy to accept hacky workarounds if needed.
User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 2529
Joined: Fri Nov 06, 2015 7:41 pm

Re: Biters attack indestructible cars

Post by Deadlock989 »

With regards to forcing units to switch targets, we had some recent success with a low-UPS-impact quick teleport to another surface and back. I have found this easier and less disruptive than messing with unit commands. It has to be another surface because killer lag can ensue if you teleport characters any kind of distance on the same surface while under attack. This would also work with vehicles as they are the only thing other than players that can currently be teleported cross-surface. You could look for it in on_player_driving_changed_state.

Code: Select all

local function create_limbo()
	local settings = {
		width = 16,
		height = 16,
		water = 0,
		default_enable_all_autoplace_controls = false,
		seed = 666,
		starting_area = 0,
		starting_points = {[1]={x=0,y=0}},
		autoplace_settings = {
			tile = {
				treat_missing_as_default = false,
				settings = {
					["dry-dirt"] = {
						frequency = 2,
						size = 2,
						richness = 2,
					},
				},
			},
			decorative = {
				treat_missing_as_default = false,
				settings = {
				},
			}
		},
		peaceful_mode = true,
		map_gen_settings = {
			property_expression_names = {
				["tile:dry-dirt:probability"] = 100
			},
		},		
	}
	local limbo = game.create_surface(DIR.limbo_surface_name, settings)
	limbo.freeze_daytime = true
	limbo.daytime = 0.5
	limbo.solar_power_multiplier = 0
	limbo.brightness_visual_weights = { 0, 1/0.75, 1/0.75 }
end

function CONTROL.send_player_to_limbo(player)
	if not game.surfaces[DIR.limbo_surface_name] then create_limbo() end
	player.teleport({0,0}, DIR.limbo_surface_name)
end

local position = player.position
local surface = player.surface
CONTROL.send_player_to_limbo(player)
player.teleport(position,surface)
However if biters aren't ignoring indestructible vehicles the way they ignore other things there would be nothing to stop them "reacquiring" the vehicle. If you're sure the car is always indestructible when it comes into "perception range", I think it would count as a bug worth reporting - indestructible things should be treated consistently.
PFQNiet
Filter Inserter
Filter Inserter
Posts: 290
Joined: Sat Sep 05, 2020 7:48 pm
Contact:

Re: Biters attack indestructible cars

Post by PFQNiet »

Well, I can confirm that if an unoccupied car coasts into enemy territory then the biters do indeed ignore it. I ran in to chase after the car and aggro'd them myself, then when I got into the car they started attacking it, and when I left the car they stayed attacking it.

So it does indeed seem like if I can get them to de-aggro it, everything should be fine.

EDIT: enemy.set_command{type=defines.command.stop, time_to_wait=1} causes them to de-aggro just fine too, no need for teleport shenanigans.
Last edited by PFQNiet on Tue Nov 03, 2020 2:39 pm, edited 1 time in total.
User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 2529
Joined: Fri Nov 06, 2015 7:41 pm

Re: Biters attack indestructible cars

Post by Deadlock989 »

It could be that biters will attack an indestructible car if there is a destructible character driving it.

Biters won't change targets if an entity's destructible state changes, but they should ignore things if they are indestructible in the tick that the biter considers them as a new target.

By the way there is absolutely no reason for the perpetual night-time and the dark red lighting in that limbo surface function above, I just like it that way.
User avatar
Deadlock989
Smart Inserter
Smart Inserter
Posts: 2529
Joined: Fri Nov 06, 2015 7:41 pm

Re: Biters attack indestructible cars

Post by Deadlock989 »

PFQNiet wrote: Tue Nov 03, 2020 2:36 pm EDIT: enemy.set_command{type=defines.command.stop, time_to_wait=1} causes them to de-aggro just fine too, no need for teleport shenanigans.
YMMV but I wasn't convinced that this wasn't messing them up in other ways. Personally I don't like messing with unit commands unless they're purely scripted non-autonomous units. I felt like the affected biters weren't responding correctly to the player when I returned (many minutes) later, it might just be in my head, and being sometimes indestructible and sometimes not in my testing area wasn't helping keep track of it. Also, with stop or flee they don't seem to consider other viable targets they way they normally would, they just wander after the timeout. Also, searching for local biters in an area has a bigger UPS cost than the teleport - a unit or worm could be targeted on the player but be many, many tiles away.
PFQNiet
Filter Inserter
Filter Inserter
Posts: 290
Joined: Sat Sep 05, 2020 7:48 pm
Contact:

Re: Biters attack indestructible cars

Post by PFQNiet »

I solved my problem like so:

Code: Select all

local function onDamaged(event)
	if event.entity.type == "car" then
		local driver = event.entity.get_driver()
		if not driver and event.cause and event.cause.type == "unit" then
			event.cause.set_command{
				type = defines.command.stop,
				ticks_to_wait = 1
			}
		end
	end
end
Since I am already manually giving commands to units anyway (mostly to make them return to their spawn point after completing a "distraction" command, so they don't end up camping your corpse) this should work just fine.

Thanks for the pointers!
Post Reply

Return to “Modding help”