As an example use-case, it is not possible to create a Battery powered Cargo Ship without explicit support from both mods (bug report on how Battery Pack doesn't work with Cargo Ships).
Battery Pack needs to know that a Cargo Ship consists of the visible cargo ship (a wagon) and a Ship Engine (an invisible locomotive) and that it is placed by a proxy entity so that when deriving battery-powered locomotives, it knows that it needs to also create a new proxy entity, to which the recipe it creates is associated.
Cargo Ships needs to know that a new proxy entity has been created and that it consists of the regular cargo ship, and a battery-powered ship engine.
At present, the only way to do this is to encode specific knowledge about Cargo Ships into Battery Pack, and about Battery Pack into Cargo Ships.
If there was a method to describe a compound entity that is shared between data and control stage, it should make doing something like the above significantly simpler.
I figure something like:
Code: Select all
data:extend{
{
type = "compound-entity",
name = "battery-powered-cargo-ship",
control_script = "cargo-ships",
proxy_entity = "battey-powered-cargo-ship",
components = {
{
name = "battery-powered-ship-engine",
amount = 1
},
{
name = "the-visible-cargo-ship",
amount = 1
}
}
},
{
type = "compound-entity",
name = "gun-turret-with-piercing-rounds-magazine",
control_script = "LoadedTurrets-0_18",
proxy_entity = "gun-turret-with-piercing-rounds-magazine",
components = {
{
name = "gun-turret",
amount = 1
},
{
type = "item",
name = "piercing-rounds-magazine",
amount = 10
}
}
}
}
- proxy_entity - the proxy entity that the player places
- control_script - an arbitrary string to associate a given compound-entity with the control script that implements it.
- components - an ingredients list that accepts entities (by default), but also items and fluids (if explicitly specified).
Code: Select all
local my_compound_entities = game.find_compound_entities_filtered{ control_script = 'my-tag'}
local my_entity_filter = {}
local my_entity_lookup = {}
for _,compound_entity in pairs(my_compound_entities) do
local proxy_entity_name = compound_entity.proxy_entity
table.insert(my_entity_filter,{
type = "entity-name",
name = proxy_entity_name
})
-- determining which components of compound_entity go where, and recording them for later use goes here.
my_entity_lookup[proxy_entity_name] = compound_entity
end
local function build_compound_entity(event)
local entity = event.entity
local entity_name = entity.name
local compound_entity = my_entity_lookup[entity_name]
if not compound_entity then error() end
-- magic (creating and configuring entities) goes here.
end
script.on_event(defines.events.on_player_built_entity, build_compound_entity, my_entity_filter)