Author Topic: [Documentation] Health loss for geoscape solders  (Read 2861 times)

Offline Yankes

  • Global Moderator
  • Commander
  • *****
  • Posts: 3350
    • View Profile
[Documentation] Health loss for geoscape solders
« on: March 21, 2020, 05:22:56 pm »
New functionality based on logic used by https://openxcom.org/forum/index.php/topic,7241.0.html

This mean this is make health work more similar to mana. As bonus mana and health loss can be consider as "wound" and prevent unit from participating in training or fighting (forced base defense still allow unit to defend base if total health loss is less than limit)
Code: [Select]
mana:
  #rest stay configs same
  woundThreshold: 200 #how much % of base mana cause unit to be consider "wounded"
  replenishAfterMission: true

health:
  woundThreshold: 100 #how much % of base health cause unit to be consider "wounded"
  replenishAfterMission: true

For base facilities:
Code: [Select]
facilities:
  - type: STR_MAGE_GUILD
    heathRecoveryPerDay: 3
Similar to mana this not stack, only max is taken.

Scripts now have access to both this values (mana and health loos) in script:
You can access and modify it by:
Code: [Select]
extended:
  scripts:
    returnFromMissionUnit:
      - offset: 1
        code: |
          set final_health_loss 13;
          set final_mana_loss 21;
          set recovery_time 0; #disable wound recovery time
         
          return;


Health "loss" is orthogonal to current wound status. You can mod game to simulate "wound" as heavy damage that make need hospitalization for some time, and health loss is small damage that soldier can heal by resting and still is battle ready. If you use `woundThreshold` then lot of health loss can still make unit have state "wounded", another important functionality is that mana and health regen only if unit is not really "wounded".

Offline MistarRed

  • Squaddie
  • *
  • Posts: 7
    • View Profile
Re: [Documentation] Health loss for geoscape solders
« Reply #1 on: April 05, 2020, 10:15:18 pm »
Example usage of the new functionality in a script for X-PirateZ.  Requires OXCE 6.4.3+.

Code: [Select]
# OXCE Requirement: 6.4.3+
#
# ***************************************************
# *** End of Battle Hit Point Regeneration Script ***
# ***************************************************
#
# Use for units that regenerate hit points every turn in combat.
# So at end of combat, they don't go to sick bay.
#
# Soldier Type Tag:
# MISSION_END_FULL_SOLDIER_REGEN - How many HP recovered per unit of mana (freshness/readiness)
#
# Armor Tag:
# MISSION_END_FULL_REGENERATION - How many HP recovered per unit of mana (freshness/readiness)
#
# Set either tag value to hitpoints regenerated / mana (freshness/readiness) lost
# A value of 5 means 5 hp recovered for every 1 mana (freshness/readiness).
# If Freshness tanks to 0, full HP recovery completes anyway.  Freshness stays at 0 then.
# So mana_missing becomes equal to mana_max, but does not go over that value.
#
# Armors take priority over soldiers.
# Soldier regen is baseline.  Armor value overwrites it.
# Tag value of 0 disables regeneration.
# This means you can have non-regenerating soldiers with regenerating armors.
# You could also have regenerating soldiers with non-regenerating armor, meaning their regen is disabled.

soldiers:
  - type: STR_SOLDIER_SYNTH
    tags:
      MISSION_END_FULL_SOLDIER_REGEN: 3
armors:
  - type: STR_BIO_SUIT_ADV_UC
    tags:
      MISSION_END_FULL_REGENERATION: 2
  - type: STR_BIO_SUIT_ADV_SEA_UC
    tags:
      MISSION_END_FULL_REGENERATION: 2
  - type: STR_BIO_SUIT_NECRO_UC
    tags:
      MISSION_END_FULL_REGENERATION: 3
  - type: STR_BIO_SUIT_NECRO_SEA_UC
    tags:
      MISSION_END_FULL_REGENERATION: 3
extended:
  tags:
    RuleSoldier:
      MISSION_END_FULL_SOLDIER_REGEN: int
    RuleArmor:
      MISSION_END_FULL_REGENERATION: int
  scripts:
    returnFromMissionUnit:
    - offset: 10
      code: |
        var ptr RuleArmor soldierArmor;
        var ptr RuleSoldier soldierRuleset;
        var int regenSoldier;
        var int regenArmor;
        var int recoveryCost;
        var int hpNow;
        var int hpMax;
        var int hpMissing;
        var int manaNow;
        var int manaMax;
        var int manaMissing;

        unit.getHealth hpNow;
        unit.getHealthMax hpMax;
        set hpMissing hpMax;
        sub hpMissing hpNow;

        unit.getMana manaNow;
        unit.getManaMax manaMax;
       
        unit.getRuleSoldier soldierRuleset;
        soldierRuleset.getTag regenSoldier Tag.MISSION_END_FULL_SOLDIER_REGEN;
       
        unit.getRuleArmor soldierArmor;
        soldierArmor.getTag regenArmor Tag.MISSION_END_FULL_REGENERATION;

        if gt regenSoldier 0;
          set recoveryCost regenSoldier;
        end;

        if gt regenArmor 0;
          set recoveryCost regenArmor;
        end;

        if gt recoveryCost 0;
          div hpMissing recoveryCost;
          sub manaNow hpMissing;
          limit manaNow 0 manaMax;
          set manaMissing manaMax;
          sub manaMissing manaNow;
          unit.setMana manaNow;
          unit.setHealth hpMax;
          set recovery_time 0;
          # OXCE 6.4.3+ functions, without which script does not work.
          set final_health_loss 0;
          set final_mana_loss manaMissing;
          return;
        end;

        return;
« Last Edit: April 05, 2020, 10:17:18 pm by MistarRed »