Code: Select all
local projectile = surface.create_entity{
name = "smart-rounds-magazine",
source = event.source_entity,
position = event.source_position,
force = event.source_entity and event.source_entity.force,
target = event.target_entity or event.target_position,
cause = event.cause_entity,
item = ammo_stack, -- gotten from the source_entity, has no effect
speed = 0.5
}
Aside/details:
It would also be potentially handy for the script_trigger_effect event to have an item parameter that could be used here, since the quality of the ammo item used would also be valuable, though that I can determine from the source_entity and isn't strictly necessary as a result.
The reason I'm using a script to spawn the projectile rather than using a projectile trigger delivery is because:
1) the direction_deviation effect isn't applied for projectiles spawned with the ammo_type's target_type set to "entity" (which is important for this effect to work).
2) when the same projectiles are fired at asteroids, they don't actually have a target_entity set, and instead just a target_position. I'm assuming this is for understandable optimization reasons, but the target_position given doesn't account for target leading, so when an asteroid is moving perpendicular to or away from the turret, almost all of the projectiles "hit" where the asteroid was and don't do any damage as a result, which causes a lot of ammunition to be wasted attempting to hit the target.
If those issues were solved instead (and could be done in a performant way), that would greatly improve the performance of my mod since I wouldn't need to use on_script_trigger_effect for each projectile fired. While the direction_deviation is a visual polish thing, the aspect that's important for the gameplay is the target leading when the target is converted to a position, since that wastes a lot of bullets and defeats the purpose of the ammo being resource-efficient.
Thank you for reading!