Workaround for entity destruction on tile change
Posted: Sat Apr 20, 2019 11:57 pm
There may already be a workaround for this, but I can't find one.
The problem occurs when you have a tile, and an entity overlapping that tile. The tile get changed, either by mining the tile, or putting flooring down. The change causes the collision mask to change, the entity gets destroyed.
There are times you'd want this to happen, such as landfill removing fish.
But there are times when you don't: You have space platform with an expensive structure on it. You mine a tile accidentally, the structure disappears.
I can see thee solutions to the problem, but there may be a better one.
Option 1:
Two new events: on_pre_player_changed_tile and on_pre_robot_changed_tile
The event return values could be similar to on_player_built_tile, except that tiles would be an array of 'NewTileAndPosition' (instead of old).
A mod maker could then use these events to search for entities in the affected area, check if they would be destroyed.
Option 2:
The game prevents you from mining tiles that would destroy entities. Some entities could have flags to not block tile changes (fish).
The game prevents you from building tiles where they would destroy entities (unless they are flagged to not block tile changes).
Option 3:
Basically like option 2, but instead of preventing the action, it forces the player or bot to perform a mining action on the conflicting entity if possible.
I.e. you try to mine the tile, and entity is in the way, you automatically start mining the entity first.
The problem occurs when you have a tile, and an entity overlapping that tile. The tile get changed, either by mining the tile, or putting flooring down. The change causes the collision mask to change, the entity gets destroyed.
There are times you'd want this to happen, such as landfill removing fish.
But there are times when you don't: You have space platform with an expensive structure on it. You mine a tile accidentally, the structure disappears.
I can see thee solutions to the problem, but there may be a better one.
Option 1:
Two new events: on_pre_player_changed_tile and on_pre_robot_changed_tile
The event return values could be similar to on_player_built_tile, except that tiles would be an array of 'NewTileAndPosition' (instead of old).
A mod maker could then use these events to search for entities in the affected area, check if they would be destroyed.
Option 2:
The game prevents you from mining tiles that would destroy entities. Some entities could have flags to not block tile changes (fish).
The game prevents you from building tiles where they would destroy entities (unless they are flagged to not block tile changes).
Option 3:
Basically like option 2, but instead of preventing the action, it forces the player or bot to perform a mining action on the conflicting entity if possible.
I.e. you try to mine the tile, and entity is in the way, you automatically start mining the entity first.