Lethal effect applied per percentage of armor damaged

A place for discussion of making game modifications.
User avatar
siyoa
Posts: 182
Joined: Fri Apr 21, 2017 3:19 pm

Lethal effect applied per percentage of armor damaged

Postby siyoa » Tue Mar 24, 2020 7:23 pm

Serenitis wrote:What I'd like to suggest is that the armour present on the target still blocks the lethal effects, but only upto it's overall integrity.
So a target with 100% armour when hit by a tagged weapon will not suffer any lethal effects, same as now.
But if 15% of the armour is damaged in that attack, then the next attack will only block (100-15) 85% of the lethal effects. And so on.


it should work from Mods folder

any damage that penetrates shields from weapon that is Lethal is first applied to the armor and then the crew is damaged as per suggestion, non Lethal weapons work old way (when it comes to crew damage)

not tested (game starts, but not sure if it is doing what it's supposed to :?:, it should ;) ), please report any issues

description of Lethal weapons is vanilla, i.e. says armor needs to go down first (want to keep it simple, and not edit too many files)
Attachments
ship_damage.zip
(6.98 KiB) Downloaded 665 times
Last edited by siyoa on Wed Mar 25, 2020 7:51 pm, edited 3 times in total.
How did YOU get a key? All right, go in.

User avatar
siyoa
Posts: 182
Joined: Fri Apr 21, 2017 3:19 pm

Re: Lethal effect applied per percentage of armor damaged

Postby siyoa » Tue Mar 24, 2020 7:46 pm

Serenitis wrote:There also is the option to have an equippable item, or a specific class/variant of armour that will raise the floor value of protection against lethal (or potentially other special) effects.


since it seems you are quite keen to poke around the files yourself :D

you can check my shield_damage_negation, there should be thread about it

basically you add to appropriate shield definition in SYSTEMS.lua following (X is amount of damage shield will negate, MoO II style)

Code: Select all

  shield_damage_negation=X,


then in ship_damage.lua, you create a function

Code: Select all

function ShipProperty.shield_damage_negation(ship)
  local max_negation = 0
  for s in systems(ship)
    if (s.health > s.damage) and s.shield_damage_negation
      max_negation =max(max_negation , s.shield_damage_negation)
    end
  end
  return max_negation
end


now you have a ship property you can use in your code, in my case, I am subtracting X damage from each weapon that hits a ship

Code: Select all

damage = damage - ship.shield_damage_negation


you can use the very same approach for armor to protect crew, add this to any armor definition, or Marine Quarters definition

Code: Select all

  crew_protection=1,


create a new function

Code: Select all

function ShipProperty.crew_protection(ship)
  local crew_protection= 0
  for s in systems(ship)
    if (s.health > s.damage) and s.crew_protection
      crew_protection=max(crew_protection, s.crew_protection)
    end
  end
  return crew_protection
end


and then in ship_damage.lua where function is called to damage crew just make that call conditional

Code: Select all

if not (ship.crew_protection==1)
How did YOU get a key? All right, go in.

User avatar
siyoa
Posts: 182
Joined: Fri Apr 21, 2017 3:19 pm

Re: Lethal effect applied per percentage of armor damaged

Postby siyoa » Wed Mar 25, 2020 7:33 pm

I guess you were not looking for binary

a) crew can be damaged
b) crew is protected from any damage

so for your request,
raise the floor value of protection against lethal
you need to use newly created ship property ship.crew_protection little differently

if you look inside function deal_damage in file ship_damage.lua you see that damage is applied in stages

a) shield is damaged
b) armor is damaged
c) structure is damaged and so on

you move to next stage only if there is any carry over damage, otherwise you terminate function execution

vanilla crew damage was being executed at c) structure damage stage

if you check the file I posted in the first post, I did very small changes to function deal_damage

I left non Lethal weapons crew damage application at the vanilla code location, just changed it to

Code: Select all

  if not(weapon:special "Kills Crew")
    damage_crew(damage,ship)
  end


I moved Lethal weapons crew damage higher in the code, and also stored how much damage is applied into new variable local kc_damage = damage, please check my modified ship_damage.lua for details

so going back to your original request about raising the floor of protection, you can just add that newly created ship property here

Code: Select all

  if weapon:special "Kills Crew"
    damage_crew(2*kc_damage*((ship.armor_damage or 0)/ship.armor)*(1/(ship.crew_protection or 1)),ship)
  end


with that change to my modified file, if you add to your definition of ship armor (or any other system) that crew_protection=2, and lets say we have 15% damage to the armor, i.e. ship.armor_damage=30 and total ship.armor=200, you are limiting crew damage from Lethal weapon to (30/200)*(1/2), i.e. 7.5% rather than 15% if there is no
raise the floor value of protection against lethal


hope, this is not too confusing explanation

EDIT: if a weapon exists with both weapon:special "Armor Piercing" and weapon:special "Kills Crew", my code would need a change at respective locations to work properly ... I think

Code: Select all

  if weapon:special "Kills Crew" and not weapon:special "Armor Piercing"
    damage_crew(2*kc_damage*((ship.armor_damage or 0)/ship.armor)*(1/(ship.crew_protection or 1)),ship)
  end


Code: Select all

  if weapon:special "Kills Crew" and weapon:special "Armor Piercing"
    damage_crew(2*damage,ship)
  end
  if not(weapon:special "Kills Crew")
    damage_crew(damage,ship)
  end
How did YOU get a key? All right, go in.

Serenitis
Posts: 75
Joined: Sat Jan 04, 2020 10:09 am

Re: Lethal effect applied per percentage of armor damaged

Postby Serenitis » Thu Mar 26, 2020 10:48 pm

Neat. Thanks for this.
Gameplay seems much the same at first, as the effects don't really kick in until damage builds up. But it is noticable.
Just for confirmation, I bumped up the multiplier to *3, and yeah. It's definitely working. Crew starts getting peeled off before even 1/2 the armour is gone.

It's a fun little addition.


Return to “Modding”

Who is online

Users browsing this forum: No registered users and 18 guests