I'm working on this mod [MOD 0.14] Programmable Warfare - command units via signals and I'm having a few problems with the composite unit/vehicle setup.
The current setup is a car-type vehicle (a tank) and a unit-type entity with no collision that sits on top of the vehicle and acts like a turret. You can control the vehicle's angle and speed remotely and the unit stays locked to the vehicle. If you give a go-to type command the the collision settings swap so the unit can move with pathfinding an vehicle entity is positioned underneath the unit as it travels. So far that's working ok(ish) but there are some issues that I can't find good ways to work around.
I want the unit/vehicle to use ammo:
I can't find a way of making the unit's weapon use actual ammo or give it an ammo slot.
I can't control the vehicle's built-in turret/weapon with lua.
If I try to attach an actual turret-type entity on top of the vehicle then it can fire and use ammo but when the vehicle is moving the turret can only face in 1 of 4 directions, orientation does not work and I cant direct the turret part of the turret to the right direction.
In theory I could use an invisible turret-type as the turret and have a fake display that can be controlled, but if the fake display is a unit then it might target the wrong thing. If the fake display is a vehicle then I would have more control over the direction, but as far as I can tell there's no way to tell what direction a turret if facing or what it's attacking.
Is there some way to detect a turret's current target, or even IF a turret or unit is firing/attacking?
If anyone has ideas on a better solution, or tips and tricks that would be great.
Composite Vehicle/Unit/Turret issues
Re: Composite Vehicle/Unit/Turret issues
So it seems to me that without the ability to set the smooth orientation of a turret, and without the ability to tell whether a unit is attacking in order to consume ammo, my only option that will actually work is to do everything with scripts...
Frankly, it seems like a horribly inefficient solution considering that only thing preventing me from using actual turret tops is that the graphics would be stuck at right-angles most of the time. To get the script method to work I'll have to use a separate vehicle as the visual turret top so it can be rotated. I'll need to set up enemy proximity detection in order to pick a target, and I'll need to spawn all of the projectiles with scripts.
The enemy detection is the part that I'm really concerned about. I want the mod to support multiple opponent player controlled forces, so it's not simply a case of finding enemy units, my units will also need to evaluate enemy units, structures, everything, as a potential target.
Are there any mods that have already solved the detection problem? The moded turrets I've seen just use the built-in turret firing and robot army uses unit firing.
Frankly, it seems like a horribly inefficient solution considering that only thing preventing me from using actual turret tops is that the graphics would be stuck at right-angles most of the time. To get the script method to work I'll have to use a separate vehicle as the visual turret top so it can be rotated. I'll need to set up enemy proximity detection in order to pick a target, and I'll need to spawn all of the projectiles with scripts.
The enemy detection is the part that I'm really concerned about. I want the mod to support multiple opponent player controlled forces, so it's not simply a case of finding enemy units, my units will also need to evaluate enemy units, structures, everything, as a potential target.
Are there any mods that have already solved the detection problem? The moded turrets I've seen just use the built-in turret firing and robot army uses unit firing.
- aubergine18
- Smart Inserter
- Posts: 1264
- Joined: Fri Jul 22, 2016 8:51 pm
- Contact:
Re: Composite Vehicle/Unit/Turret issues
Not sure if it's any use, but saw a post while back where someone was trying to do something similar to what you're doing (I think?):
GIF: https://gfycat.com/NeighboringEvergreenConey
Topic: viewtopic.php?f=28&t=25599
Github: https://github.com/msu320/turrets_API
As for evaluating enemy targets, I think the Additional Turrets mod was planning to do something along those lines (eg. make artillery prioritise spawners rather than mobile units such as biters and spitters).
GIF: https://gfycat.com/NeighboringEvergreenConey
Topic: viewtopic.php?f=28&t=25599
Github: https://github.com/msu320/turrets_API
As for evaluating enemy targets, I think the Additional Turrets mod was planning to do something along those lines (eg. make artillery prioritise spawners rather than mobile units such as biters and spitters).
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
Re: Composite Vehicle/Unit/Turret issues
I'll be doing some testing on this, but does surface.find_nearest_enemy() return just units, units and turret, units turrets and unit-spawners, or any entity of an enemy force (such as enemy assembly machine)?
- aubergine18
- Smart Inserter
- Posts: 1264
- Joined: Fri Jul 22, 2016 8:51 pm
- Contact:
Re: Composite Vehicle/Unit/Turret issues
I've not tested personally, but I think it returns entities from the `enemy` force, without filtering by entity type or name.
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
Re: Composite Vehicle/Unit/Turret issues
Thanks. I'll look into those.aubergine18 wrote:Not sure if it's any use, but saw a post while back where someone was trying to do something similar to what you're doing (I think?):
GIF: https://gfycat.com/NeighboringEvergreenConey
Topic: viewtopic.php?f=28&t=25599
Github: https://github.com/msu320/turrets_API
As for evaluating enemy targets, I think the Additional Turrets mod was planning to do something along those lines (eg. make artillery prioritise spawners rather than mobile units such as biters and spitters).
Re: Composite Vehicle/Unit/Turret issues
So this is weird.
find_nearest_enemy will find enemy units, spawners, worms, but also enemy gun turrets and radars, but not other enemy structures like assembly machines.
find_enemy_units will find enemy units, spawners, worms, but NOT enemy gun turrets or anything else not biter-specific.
find_nearest_enemy will find enemy units, spawners, worms, but also enemy gun turrets and radars, but not other enemy structures like assembly machines.
find_enemy_units will find enemy units, spawners, worms, but NOT enemy gun turrets or anything else not biter-specific.
Re: Composite Vehicle/Unit/Turret issues
Update: find_nearest_enemy seems to be surprisingly quick. I've managed to replicate some turret functionality using a rotatable vehicle as a turret graphic and making it fire using surface.create_entity for the projectiles. The really nice thing about doing this is that the script knows when the unit has a target in range so the unit will be able to report back on how long it has been since it was in combat.
Re: Composite Vehicle/Unit/Turret issues
Indeed it's what the core game uses to find something for a turret to shoot at.Earendel wrote:Update: find_nearest_enemy seems to be surprisingly quick. ...
If you want to get ahold of me I'm almost always on Discord.