@RufusShinraSB wrote:
OK, so after an evening of testing and debugging, I can say that it does work as a pretty comprehensive proof of concept.
Earlier today, on the Torpedo Attacker Script, I had an idea to kinda deal with my very long-running ammunition management issue in a radical way. @HW_Lover built an excellent script to create a torpedo that isn’t a torpedo but a ship, appearing on its carrying vessel until dropped and I thought (post taken from the Torpedo Attacker Script thread):
Why not push this even further?
Why exactly don’t we make all missiles like this? OK, that would of course require an initial coding job to do it, but the more I think about it, the more advantages I’m seeing. The whole “visible torpedo” on the outside of the ship is an awesome option indeed, but we could push the whole thing further:
We have our missile-armed craft, using global tables like described in this thread: [QUESTION] Detecting an animation or madstate
Now, this table management system can get ammunition counts, of course, but also reload time for the weapon, and we have range from the Torpedo Attacker Script: the base for a weapon.
What if we do this for all missiles? Anti-ship, anti-fighters and so on? A .ship based missile could have the kinematics optimized for the missile job, and would maybe not even require a CustomCode of its own to work unless you want to do some quirky thing with it (like the cloaking device). Spawn it with the launcher ship’s CustomCode, get it unselectable, order it to Kamikaze on the target and there we go. This would avoid the huge lag trap that dozens or hundreds of CustomCode ships updating at once would cause (though the main issue would be to stress-test how laggy we’d get with all missile-equipped ships having code like the one I posted, but from what I’ve seen playing Flag Commander in SP or MP, it’s not too much of an issue, not like, say, my ill-thought attempt at generating ship names which made the stuff lag very quickly).
However, we could then start doing quirky things. HWR is not really designed for anti-missile defences, so complete roundabouts had to be made to allow the stuff like area missile defence and the like, so what could we do if, in our hypothetical mod, missiles were .ship rather than .missile?
For example, we could get some smart targeting or multiple independant vehicles, like cluster missiles in which each cluster automatically targets a different ship, or clusters of different warheads, like area of effect bombs, anti-fighter missiles and anti-ship missiles at the same time.
Something even more interesting in my opinion is the possibility to introduce ECM, Electronic Counter-Measures. Detecting and acting on missiles would become a completely different toolbox in this case. You could have, for example, decoys, “missiles” that would actually have a CustomCode defining a short lifetime and looking for enemy units belonging to the SobGroup “AntiFighterMissiles”, choosing one of them and forcefully changing the original target to get the missile to kamikaze on the decoy instead. Or a dedicated ship around which missiles would be forced to swerve and fly away in some “repulsor field” way. Or even take control of enemy missiles and turn them back to their sender if some temporary special weapon is turned on.
SEAD (Suppression of Enemy Air Defences) could be made a lot simpler for mods in which capital ships have individual targetable turrets, with dedicated bombers simply attacking the capital ship and dropping one or several missiles that could be made to directly target subsystems of the target ship.
That’s a lead I think we should think about, maybe not generalizing it to all missiles and limiting it to specific stuff, but the OP opened, IMO, a very interesting door for game mechanics.
[/end of the previous post]
So, here is a working script for a torpedo bomber that has entirely tunable ammunition, fuel, reload times between shots in flight and weapon range. Integrated with is a special landing script that keeps only one plane in a landing pattern while the others automatically guard the carrier as well as the fuel and ammunition reload while landed. It doesn’t need any special human interaction and should work properly in the hands of the bots too. This version of the code has a LOT of prints that can be removed in a mod release for better performance, of course.
The fuel can be removed from the script to allow pure ammunition management, which with a quick edit could lead to properly regenerating ammunition like in the HW1 missile destroyers. The reload procedure could be changed, for example by detecting in proximity some specific class of ship, tankers or missile cargoes, which would allow for actual resupply convoys behind the frontline.
To make this code work, it will obviously need to be invoked by the bomber to use, and it will need the “missile ship”, with attack capability. Tinker with the mass and collision multipliers to achieve the desired effect.
@EvilleJedi, if I remember correctly, you had some passing interest in that stuff for Star Wars bombers, so I tag you.
dofilepath("data:scripts/lib/custom/shiptable.lua") function OnCreate(CustomGroup, playerID, shipID) dofilepath("data:scripts/lib/custom/shiptable.lua") -- if targets==nil then -- print("Table créée.") -- targets = {} -- else -- print("Table trouvée.") -- end if ships==nil then print("Table créée.") ships = {} fuel = {} fuel.fuel = 1000 -- my starting fuel fuel.fuel_max = 1000 -- my fuel tank weapon = {} weapon.subsname = "myweapon" weapon.ammo = 1 -- my starting torpedo reserve weapon.ammo_max = 1 -- my max ammo reserve weapon.ammo_use = 1 -- per shot weapon.reload = 0 weapon.reload_max = 50 -- the number of recharge ticks needed before being allowed to fire weapon.recharge = 1 -- how many ticks I will gain every time the script is run else print("Table trouvée.") end ships.weapon = weapon ships.fuel = fuel print(shipID) a = shipID print(a) ships[a] = ships print(ships) -- the table is updated with the weapon and fuel structure for this ship end function OnUpdate(CustomGroup, playerID, shipID) dofilepath("data:scripts/lib/custom/shiptable.lua") b = shipID print("Test 1") print(ships) print(b) print(ships[b].weapon.ammo) c = ships[b].fuel.fuel d = ships[b].weapon.ammo print("Munitions pour vaisseau :") print(d) e = ships[b].weapon.reload if e<ships[b].weapon.reload_max then ships[b].weapon.reload = e + ships[b].weapon.recharge -- if my torpedo is not ready, let's keep readying it by adding the ticks end print("Cycle de rechargement pour vaisseau :") print(e) if c>0 then ships[b].fuel.fuel = c-1 -- let's burn a bit more fuel, baby! print("Carburant pour vaisseau :") print(c) RTB = 0 -- I still have fuel else RTB = 1 -- I am Bingo Fuel, out of fuel, let's Return To Base end if d>0 then RTB = 0 -- I still have torpedoes else RTB = 1 -- I am Winchester, out of ammunition, let's Return To Base end if d>0 and e==ships[b].weapon.reload_max then -- I have torpedoes AND one of them is ready, so we can go with the torpedo attack script if(SobGroup_GetCurrentOrder(CustomGroup)==COMMAND_Attack)then -- Am I actually attacking? SobGroup_CreateIfNotExist("TorpedoAttackerTargetTempGroup") SobGroup_Clear("TorpedoAttackerTargetTempGroup") SobGroup_GetCommandTargets("TorpedoAttackerTargetTempGroup", CustomGroup, COMMAND_Attack) -- Here is my target! if(SobGroup_Count("TorpedoAttackerTargetTempGroup")==1)then -- I am actually attacking someone if(SobGroup_AreAnyFromTheseAttackFamilies("TorpedoAttackerTargetTempGroup", "Capturer, Frigate, SmallCapitalShip, BigCapitalShip, Mothership, Utility")==1)then--edit the attack families the attacker can attack, or simply copy this from the attacker's .ship file SobGroup_CreateIfNotExist("TorpedoAttackerTargetTempGroup2") -- So, my target is a big boy, let's arm the torpedo, then! SobGroup_Clear("TorpedoAttackerTargetTempGroup2") SobGroup_FillProximitySobGroup("TorpedoAttackerTargetTempGroup2", "TorpedoAttackerTargetTempGroup" , CustomGroup , 4500)--edit the firerange of the torpedo, how far the attack will fire upon the target if(SobGroup_Empty("TorpedoAttackerTargetTempGroup2")==0)then -- I am in weapon range, my torpedo is ready, let's unleash hell! print("I'm in range!") SobGroup_CreateIfNotExist("TorpedoTempGroup") -- the torpedo will be there print("A") SobGroup_Clear("TorpedoTempGroup") print("B") Volume_AddSphere("AttackerPositionVolume", SobGroup_GetPosition(CustomGroup), 0) -- it will appear in this location print("C") SobGroup_SpawnNewShipInSobGroup(playerID, "msl_torpedo", "msl_torpedo"..shipID, "TorpedoTempGroup", "AttackerPositionVolume")--replace [msl_torpedo] by your torpedo unit's ship name print("D") Volume_Delete("AttackerPositionVolume") print("E") --SobGroup_ParadeSobGroup("TorpedoTempGroup", CustomGroup, 2) print("F") --SobGroup_Attack(PlayerIndex, "TorpedoTempGroup", "TorpedoAttackerTargetTempGroup") print("G") SobGroup_Kamikaze("TorpedoTempGroup", "TorpedoAttackerTargetTempGroup") -- Tora! Tora! Tora! print("H") SobGroup_MakeSelectable("TorpedoTempGroup",0) -- Good bye, my little torpedo, you will be missed, but please do not miss. print("I") ships[b].weapon.reload = 0 -- Yay, let's go through another reload cycle! print("J") -- aa = GetShipId("msl_torpedo") -- print("ID du missile tiré") -- print(aa) -- missile = aa -- target ships[b].weapon.ammo = d-1 -- let's consume a torpedo from the reserve --SobGroup_SetHealth("TorpedoTempGroup", 0) else print("Almost in range...") -- Are we theeeeeere yet? No, kids. end end end end end SobGroup_SetHardPointHealth(CustomGroup,'FUELTANK',c/ships[b].fuel.fuel_max) SobGroup_SetHardPointHealth(CustomGroup,'TORPEDO',d/ships[b].weapon.ammo_max) -- these two lines above are there to allow a visual indicator of the fuel and ammunition level. Get two subsystems on your craft and call the subsystems FUELTANK and TORPEDO in the .ship file. Then you'll get the values displayed as a bar. if RTB == 1 then -- I want to return to base SobGroup_FillProximitySobGroup("Test1", "Player_Ships"..playerID, CustomGroup, 1500) -- Who is around me, me included? SobGroup_FillProximitySobGroup("OwnShip", "Player_Ships"..playerID, CustomGroup, 5) -- Me! SobGroup_FillSubstract("Test2", "Test1", "OwnShip") -- Who is around me, me NOT included. Useful, you'll see why later. if SobGroup_AreAnyOfTheseTypes("Test2", "cfd_carrier, cfd_confederation, cfd_jutland, cfd_lexington, cfd_mothership, cfd_naval_base, cfd_savannah, cfd_victory, klr_bhantkara, klr_dubav, klr_hvarkann, klr_shipyard, klr_starbase, ubw_carrier, ubw_mothership, ubw_shipyard")==1 then -- there's a carrier in proximity, let's not go all over the map for nothing, shall we? Replace this by a list of your carrier-capable units. print("CV found near me.") SobGroup_CreateIfNotExist("Carrier") SobGroup_Clear("Carrier") SobGroup_FillShipsByType( "Carrier", "Test2", "cfd_carrier, cfd_confederation, cfd_jutland, cfd_lexington, cfd_mothership, cfd_naval_base, cfd_savannah, cfd_victory, klr_bhantkara, klr_dubav, klr_hvarkann, klr_shipyard, klr_starbase, ubw_carrier, ubw_mothership, ubw_shipyard") if SobGroup_IsDoingAbility("Test2", AB_Dock)==1 then print("No Priority") SobGroup_GuardSobGroup(CustomGroup, "Carrier") -- there are other ships waiting to land on the carrier near me, I'll guard my carrier instead of sitting like a target else print("Priority") -- looks like noone is waiting to land, the sky is empty or everyone else is on guard, so it's my turn to land -- what happened is that when you are RTB near a carrier, you will want to land. The first one to run the script in proximity to the carrier will land. Everyone after will see that landing plane and will get in guard position. When the plane landed, the next RTB plane to run the script will not see anyone landing and will start landing, etc., keeping only one plane on the landing pattern at all times! SobGroup_DockSobGroup(CustomGroup, "Carrier") end else print("No CV found around me.") -- no carrier around, I'll land on a random friendly carrier SobGroup_DockSobGroup(CustomGroup, "AllShips") end end if SobGroup_IsDocked(CustomGroup)==1 then ships[b].weapon.ammo = weapon.ammo_max -- I got my ammunition reloaded by the ground crews ships[b].fuel.fuel = fuel.fuel_max -- I got my fuel reloaded by the ground crews end end
Posts: 11
Participants: 6