reloading ship weapons query

Freeform discussion about anything related to modding Transcendence.
Post Reply
relanat
Militia Captain
Militia Captain
Posts: 941
Joined: Tue Nov 05, 2013 9:56 am

Was mucking about with ShivanHunter's Ranx ships mod.

Great stuff, the ship images are great. Also the turrets.

One problem with the Ranx is they run out of ammo. This includes the mod turrets.

I was looking at ways of making the Ranx ships dock and 'reload' with ammo from their station.
From info in a forum post by PM, I checked the Reenu code but it is weapon code not ship code. It also uses <OnAIUpdate> which is a bit processor hungry.

Ideally some way of getting a ship class to dock would be best rather than a ship with a particular weapon.

Looking at 0xABCDEF's XML hierarchy I saw <OnAttacked> and <OnDamage> in the ship class events. Also <OnEventHandlerInit>.

So maybe there could be an ammo check in <OnAttacked> in the ShipClass. If the ship lacked ammo it could be ordered to dock and magically reload. Or gate out if no Ranx stations were left intact.

Would this sort of thing work? Or would a separate event handler be needed? Any info at all would be good before I spend hours working on this!
And is there some way to automatically reload stations with ammo for their weapons? TIA.
Stupid code. Do what I want, not what I typed in!
NMS
Militia Captain
Militia Captain
Posts: 569
Joined: Tue Mar 05, 2013 8:26 am

OnAttacked doesn't seem ideal. OnAIUpdate should be fine as long as you don't do something very system-intensive most of the time.

It could work something like this: Check the ammo level with objHasItem with 1 for the quantity. If they're docked and low on ammo, add some ammo. Once they have enough, undock and resume normal behavior. Otherwise, if they're out of ammo or they're low on ammo and not in combat, order them to go restock. You can use the 'underAttack property or sysFindObject.

I thought some stations already events to restock the ammo for their installed weapon, but I don't see any at the moment. Maybe it's automatic now?

An event handler would let you add code to ships without totally overriding them, so you wouldn't need to update the mod if the class changed in vanilla. But if you're overriding anyway, you don't need one.
relanat
Militia Captain
Militia Captain
Posts: 941
Joined: Tue Nov 05, 2013 9:56 am

Great info, thanks.

What about using sysAddTypeRecurringTimerEvent or a recurring timer event of some sort? An event could check Ranx system objects (ships and stations) with ammo/missile using weapons every 15 or 30 seconds (real-time).
If ammo levels were below 20 or so and there was an intact station in the system the ship could be ordered to dock, magically reload, then undock and resume its previous behavior.
If no intact station then order the ship to gate.
This could handle the Ranx ships when they are attacking other objects even when the playership is elsewhere in the system.
Would this be a lighter way of doing it?

Note: Need to check if the ship will continue firing on the way to the station or gate.
Also if launchers/missiles are handled differently to ammo-using weapons/ammo.
I thought some stations already events to restock the ammo for their installed weapon, but I don't see any at the moment. Maybe it's automatic now?
The Ranx turrets in the mod have Nami missile launchers. They ran out of missiles and didn't auto-restock. I changed them to have an installed Akan 600 turret and 5 Akan shells. When they ran out they didn't restock, even after several minutes. But there may be some code needed to activate an auto-restock feature, the Ranx mod was last updated in 2012. Not sure. It would be handy.
Stupid code. Do what I want, not what I typed in!
NMS
Militia Captain
Militia Captain
Posts: 569
Joined: Tue Mar 05, 2013 8:26 am

relanat wrote:
Thu Jul 18, 2019 4:20 am
What about using sysAddTypeRecurringTimerEvent or a recurring timer event of some sort?
You'd have to add the event in every system and I don't think it's any better performance-wise. In fact it might be worse, since they'd all happen on the same tick, rather than spread out over random ticks.


relanat wrote:
Thu Jul 18, 2019 4:20 am
I thought some stations already events to restock the ammo for their installed weapon, but I don't see any at the moment. Maybe it's automatic now?
The Ranx turrets in the mod have Nami missile launchers. They ran out of missiles and didn't auto-restock. I changed them to have an installed Akan 600 turret and 5 Akan shells. When they ran out they didn't restock, even after several minutes. But there may be some code needed to activate an auto-restock feature, the Ranx mod was last updated in 2012. Not sure. It would be handy.
Maybe it only applies to stations with Trade elements that let them restock the ammo they sell? Maybe the ammo has to be defined in the Device like this?

Code: Select all

			<Device deviceID="&itAkan30Cannon;"	omnidirectional="true">
				<Items>
					<Item count="900" item="&itAkan30CannonShell;"/>
				</Items>
			</Device>
relanat
Militia Captain
Militia Captain
Posts: 941
Joined: Tue Nov 05, 2013 9:56 am

Including the Items/ammo within the <Devices> block didn't work for the turrets. No ammo was added. Possibly only supported in ShipClass UNIDs.

However a bit of trial and error gave this code:

Code: Select all

<Trade currency="credit">
	<Sell	criteria="m +unid:&itAkan30CannonShell;" inventoryAdj="100"/>
</Trade>

<Devices>
	<Device deviceID="&itAkan30Cannon;" omnidirectional="true"/>
</Devices>

<Events>
	<OnDestroy>
		(rpgDestroyItems gSource)
	</OnDestroy>
</Events>
This adds about 150-200 Akan shells every once in a while. As you say it is to restock ammo for sale but it works here. There can sometimes be a small gap between the ammo running out and the next lot "appearing" but that is acceptable. Easier than adding another event. There is still a lot of firepower available as every Ranx fortress gets 8 turrets! The 'rpgDestroyItems' reduces the leftover ammo to be looted to none or less than 100.
One query: what happens if the turret gets destroyed instantly and doesn't leave an abandoned station? "Normal" stations are immutable when destroyed. Will 'rpgDestroyItems' handle that or throw an error? Ship code can check for 'aWreckObj' but I don't think that applies to stations.
Stupid code. Do what I want, not what I typed in!
Post Reply