Deduplicate add/remove entity to/from AIs resource map.
Also moves the function to the shared_script, since that is the prototype it uses and the function doesn't use anything of the terrain_analysis (as per @Angen's request).
Differential revision: https://code.wildfiregames.com/D3906
Comments by: @Angen, @wraitii