Can scripts access whether a ship has been damaged?

Creation, discussion, and balancing of game content such as techs, buildings, ship parts.

Moderators: Oberlus, Committer

Post Reply
Message
Author
Telos
Space Squid
Posts: 50
Joined: Thu May 09, 2013 4:46 am

Can scripts access whether a ship has been damaged?

#1 Post by Telos »

In game, it would be helpful if the numerous SitReps reporting ship damaged in a battle could prominently display the *amount* of damage each ship received (or perhaps even better report its current structure / maximum structure), and not just that the ship had been damaged, as that would remove some of the busy-work from determining which ships were so badly hurt that they deserve a trip back to drydock.

Also, I've been fiddling with scripting some more interesting organic ship behavior for growth and injury and it would help a lot if I could detect which of a ship's missing HP was genuinely new damage, or at least if I could detect if the ship had been damaged this turn, even if I couldn't know how much of its missing HP had been lost earlier.

I think I can use (very low priority) scripts to compare current structure to max-structure to determine if a ship is damaged, and I think I can detect whether the ship was in combat this turn, but I don't yet know how to detect whether it got *hurt* in combat this turn, nor how *much* it got hurt, nor whether it might have taken damage from other sources, like mines.

o01eg
Programmer
Posts: 2004
Joined: Sat Dec 10, 2011 5:46 am

Re: Can scripts access whether a ship has been damaged?

#2 Post by o01eg »

There some information on "Combat" situation report.
Gentoo Linux x64, gcc-11.2, boost-1.78.0
Ubuntu Server 22.04 x64, gcc-12, boost-1.74.0
Welcome to the slow multiplayer game at freeorion-lt.dedyn.io.Version 2024-03-15.b3de094.
Donations're welcome:BTC:bc1q007qldm6eppqcukewtfkfcj0naut9njj7audnm

Ophiuchus
Programmer
Posts: 3433
Joined: Tue Sep 30, 2014 10:01 am
Location: Wall IV

Re: Can scripts access whether a ship has been damaged?

#3 Post by Ophiuchus »

Telos wrote: Sun Jan 13, 2019 5:58 amI think I can use (very low priority) scripts to compare current structure to max-structure to determine if a ship is damaged, and I think I can detect whether the ship was in combat this turn, but I don't yet know how to detect whether it got *hurt* in combat this turn, nor how *much* it got hurt, nor whether it might have taken damage from other sources, like mines.
I think your assessment is right. While theoretically one could parse the combat reports manually there is no FOCS way to do that.
I think it would be a minor to medium cpp change to add a LastTurnDamage or WasAttackedLastTurn properties to ships.

But the information of "low health and not in a position to heal" is probably the one wants anyway? Also i think this should be more of a fleet management than sitrep thingy.

"Split badly damaged ships from fleet".. something like that.
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

Look, ma... four combat bouts!

Telos
Space Squid
Posts: 50
Joined: Thu May 09, 2013 4:46 am

Re: Can scripts access whether a ship has been damaged?

#4 Post by Telos »

Yeah, it would be a nice quality of life improvement to have the right-click menu that includes things like "Split fleet" also include an option to "Split off injured ships" (or perhaps multiple such options, with different percent-thresholds for what counts as "injured").

Since that would require CPP program changes, for now, it still could be good to have CustomSitReps do a better job of warning which ships are most in need of repair. I think there might still be some usefulness to using a "was damaged this turn" criterion for those sitreps too, rather than spamming someone repeatedly with messages for a ship that they, for whatever reasons, decided to leave in place after it was last damaged.

I started puzzling over this in trying to script organic ship and shippart effects that would treat severe damage to organic parts of the ship as causing semi-permanent injuries to max-structure, not just quickly-repairable injuries to current structure. For that purpose, it would help a lot to be able to distinguish "new damage" (which might cause new lasting injuries) from "old damage" (that had already caused whatever lasting injuries it should cause to organic parts, and just consists of damage to other parts that hasn't been repaired yet). It seems like the closest approximation FOCS can currently come to that is by combining (1) a test for whether the ship is below max-structure, together with (2) some sort of imperfect test for whether it might have received damage this turn, which probably checks (2a) for whether it was in combat this turn or (2b) whether it is in a system with a planet owned by an enemy who has researched mines.

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Can scripts access whether a ship has been damaged?

#5 Post by Geoff the Medio »

Telos wrote: Thu Jan 17, 2019 2:25 amYeah, it would be a nice quality of life improvement to have the right-click menu that includes things like "Split fleet" also include an option to "Split off injured ships"...
It does...?
split fleet commands on fleet with damaged ships
split fleet commands on fleet with damaged ships
Split_Fleet_Commands.png (64.38 KiB) Viewed 8088 times

Ophiuchus
Programmer
Posts: 3433
Joined: Tue Sep 30, 2014 10:01 am
Location: Wall IV

Re: Can scripts access whether a ship has been damaged?

#6 Post by Ophiuchus »

Geoff the Medio wrote: Thu Jan 17, 2019 9:45 am
Telos wrote: Thu Jan 17, 2019 2:25 amYeah, it would be a nice quality of life improvement to have the right-click menu that includes things like "Split fleet" also include an option to "Split off injured ships"...
It does...?
Let me rephrase - what he wanted was "Split badly damaged ships from fleet" (or "damaged last turn") which is different from what we have.
Telos wrote: Thu Jan 17, 2019 2:25 amI started puzzling over this in trying to script organic ship and shippart effects that would treat severe damage to organic parts of the ship as causing semi-permanent injuries to max-structure, not just quickly-repairable injuries to current structure. For that purpose, it would help a lot to be able to distinguish "new damage" (which might cause new lasting injuries) from "old damage" (that had already caused whatever lasting injuries it should cause to organic parts, and just consists of damage to other parts that hasn't been repaired yet).
You could record critical-damage in a special's capacity and make an effect which reduces maxstructure using that capacity.

For testing damage-received-last-turn you could record last turn structure in a special's capacity for each ship. But i also think the approximation is good enough.
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

Look, ma... four combat bouts!

User avatar
Oberlus
Cosmic Dragon
Posts: 5713
Joined: Mon Apr 10, 2017 4:25 pm

Re: Can scripts access whether a ship has been damaged?

#7 Post by Oberlus »

An alternative solution for the "I want to be able to split badly damaged ships from the rest of the fleet without having to browse the entire fleet cherry-picking by hand" problem without having to add an option with a variable percentage or number parameter:

Order (automatically or via a GUI option) the ships in a fleet by ascending remaining hull points. Thus you could select the first ship (the more hurt) and shift-click on the last one you want to extract from the fleet, and drag-and-drop those damaged ships into a new fleet.

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Can scripts access whether a ship has been damaged?

#8 Post by Geoff the Medio »

Ophiuchus wrote: Thu Jan 17, 2019 12:17 pmYou could record critical-damage in a special's capacity and make an effect which reduces maxstructure using that capacity.
Or just have it be a binary flag, so that if the ship ever has less than 40% structure, it is permanently injured and thereafter receives a penalty to something: max structure or speed or fuel or whatever.

Ophiuchus
Programmer
Posts: 3433
Joined: Tue Sep 30, 2014 10:01 am
Location: Wall IV

Re: Can scripts access whether a ship has been damaged?

#9 Post by Ophiuchus »

Geoff the Medio wrote: Thu Jan 17, 2019 1:08 pm
Ophiuchus wrote: Thu Jan 17, 2019 12:17 pmYou could record critical-damage in a special's capacity and make an effect which reduces maxstructure using that capacity.
Or just have it be a binary flag, so that if the ship ever has less than 40% structure, it is permanently injured and thereafter receives a penalty to something: max structure or speed or fuel or whatever.
What you suggest is adding the "BADLY_INJURED" special without caring about capacity, right?
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

Look, ma... four combat bouts!

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Can scripts access whether a ship has been damaged?

#10 Post by Geoff the Medio »

Ophiuchus wrote: Thu Jan 17, 2019 2:46 pmWhat you suggest is adding the "BADLY_INJURED" special without caring about capacity, right?
Yes.

Telos
Space Squid
Posts: 50
Joined: Thu May 09, 2013 4:46 am

Re: Can scripts access whether a ship has been damaged?

#11 Post by Telos »

Thanks folks for pointing out that a version of "split off damaged ships" functionality does exist. I had no idea that was there because it doesn't appear when all your ships are healthy, which is the main circumstance when I've used the right-click interface, mostly just to split apart troop ships that the game "helpfully" merged together on production. Quality of life improved!

(That still doesn't solve the scripting challenge that started the thread though.)

Ophiuchus
Programmer
Posts: 3433
Joined: Tue Sep 30, 2014 10:01 am
Location: Wall IV

Re: Can scripts access whether a ship has been damaged?

#12 Post by Ophiuchus »

Telos wrote: Thu Jan 17, 2019 6:37 pm That still doesn't solve the scripting challenge that started the thread though.
Well there were solution suggestions; for the original request: record the current hp every turn (current turn is next turn's last turn) in a capacity or special and then you can calculate the damage as a difference in the next turn
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

Look, ma... four combat bouts!

Post Reply