aliens

Author Topic: [DONE] Would it be possible to set Experience hardcoded values as parameters ?  (Read 1031 times)

Offline Aldorn

  • Commander
  • *****
  • Posts: 750
    • View Profile
Hi Meridian & Yankes,

Congrats for the amazing job you do every day/week/month/year !

I'm quite sure answer will be NO, anyway I will still ask my question, as this is a request I asked far in the past but was impossible to implement, but I'm still interested by it and potentially it may be possible now in OXCE



Would it be possible to put harcoded values regarding experience awards as parameters we could simply overwrite via ruleset ?

What I have in mind hereafter

Current Code (BattleUnit.cpp)
Spoiler:
int BattleUnit::improveStat(int exp) const
{
   if      (exp > 10) return RNG::generate(2, 6);
   else if (exp > 5)  return RNG::generate(1, 4);
   else if (exp > 2)  return RNG::generate(1, 3);
   else if (exp > 0)  return RNG::generate(0, 1);
   else               return 0;
}


Convert 12 hardcoded values to variables available for overwritting via ruleset

Spoiler:

New Ruleset variables (names to be defined properly, below is just an example):

STR_EXP_TRIGGER1 0
STR_EXP_TRIGGER2 2
STR_EXP_TRIGGER3 5
STR_EXP_TRIGGER4 10

STR_EXP_TRIGGER1_MINRNG 0
STR_EXP_TRIGGER2_MINRNG 1
STR_EXP_TRIGGER3_MINRNG 1
STR_EXP_TRIGGER4_MINRNG 2

STR_EXP_TRIGGER1_MAXRNG 1
STR_EXP_TRIGGER2_MAXRNG 3
STR_EXP_TRIGGER3_MAXRNG 4
STR_EXP_TRIGGER4_MAXRNG 6

New code:

int BattleUnit::improveStat(int exp) const
{
   if      (exp > STR_EXP_TRIGGER1) return RNG::generate(STR_EXP_TRIGGER1_MINRNG, STR_EXP_TRIGGER1_MAXRNG);
   else if (exp > STR_EXP_TRIGGER2)  return RNG::generate(STR_EXP_TRIGGER2_MINRNG, STR_EXP_TRIGGER2_MAXRNG);
   else if (exp > STR_EXP_TRIGGER3)  return RNG::generate(STR_EXP_TRIGGER3_MINRNG, STR_EXP_TRIGGER3_MAXRNG);
   else if (exp > STR_EXP_TRIGGER4)  return RNG::generate(STR_EXP_TRIGGER4_MINRNG, STR_EXP_TRIGGER4_MAXRNG);
   else               return 0;
}

Please don't hurt me if you find this request has no sense  :-[

EDIT: I saw there is now the possibility to play with experience multiplier via scripts, but I'm still interested to have access to these hardoded values
« Last Edit: January 31, 2023, 05:24:48 pm by Aldorn »

Offline Yankes

  • Commander
  • *****
  • Posts: 3206
    • View Profile
This is wrong "board", this is for mod progress and initial implementations, not requests for new features.

For request it self, I would never put 12 parameters to control this, as would only make mess in code.
Correct solution would be more one parameters like:
Code: [Select]
imporveStatsThresholds:
  1: [0, 1]
  2: [1, 3]
  5: [1, 4]
  10: [2, 6]


For implementation itself, for now I do not have free time (and I have multiple "due" requests), this mean I would not implement this, if Meridian would be interested then he could do it.



Offline Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 8615
    • View Profile
Moved to OXCE board.

As for the request, isn't it already possible to write a completely custom post-mission procedure using Y-scripts? https://github.com/MeridianOXC/OpenXcom/blob/oxce-plus/src/Savegame/BattleUnit.cpp#L3885
(Basically ignore vanilla algorithm and write your own with as many parameters as you want)

Offline Aldorn

  • Commander
  • *****
  • Posts: 750
    • View Profile
Hi both, thanks for moving my question to proper section

I will have a look at Y-scripts, if I succeed this will be perfect

https://openxcom.org/forum/index.php?topic=5245.0


Thanks for your answers
« Last Edit: January 28, 2023, 06:36:32 pm by Aldorn »

Offline Aldorn

  • Commander
  • *****
  • Posts: 750
    • View Profile
Re: [SOLVED] Would it be possible to set hardcoded values as parameters ?
« Reply #4 on: January 30, 2023, 07:32:25 pm »
Example of script to set max attributes improvement to 1 (tested successfully)

Inspired by Yankes shared example: https://openxcom.org/forum/index.php/topic,6619.msg104686.html#msg104686

Code: [Select]
# Attributes may not be increased by more than 1 per battle
extended:
  scripts:
    returnFromMissionUnit:
      - offset: 1
        code: |
          var int addStat 0;
          var int curStat 0;
         
          statChange.getBravery addStat; #how much attribute was increased by exp
          soldier.Stats.getBravery curStat; #current attribute value (already including value from exp)
          sub curStat addStat; #set current attribute back to its original value before exp
          if gt addStat 0;
            add curStat 1;
          end;
          soldier.Stats.setBravery curStat; #update attribute

          statChange.getFiring addStat;
          soldier.Stats.getFiring curStat;
          sub curStat addStat;
          if gt addStat 0;
            add curStat 1;
          end;
          soldier.Stats.setFiring curStat;

          statChange.getHealth addStat;
          soldier.Stats.getHealth curStat;
          sub curStat addStat;
          if gt addStat 0;
            add curStat 1;
          end;
          soldier.Stats.setHealth curStat;

          statChange.getReactions addStat;
          soldier.Stats.getReactions curStat;
          sub curStat addStat;
          if gt addStat 0;
            add curStat 1;
          end;
          soldier.Stats.setReactions curStat;

          statChange.getStamina addStat;
          soldier.Stats.getStamina curStat;
          sub curStat addStat;
          if gt addStat 0;
            add curStat 1;
          end;
          soldier.Stats.setStamina curStat;

          statChange.getStrength addStat;
          soldier.Stats.getStrength curStat;
          sub curStat addStat;
          if gt addStat 0;
            add curStat 1;
          end;
          soldier.Stats.setStrength curStat;

          statChange.getThrowing addStat;
          soldier.Stats.getThrowing curStat;
          sub curStat addStat;
          if gt addStat 0;
            add curStat 1;
          end;
          soldier.Stats.setThrowing curStat;

          statChange.getTimeUnits addStat;
          soldier.Stats.getTimeUnits curStat;
          sub curStat addStat;
          if gt addStat 0;
            add curStat 1;
          end;
          soldier.Stats.setTimeUnits curStat;

          return;
« Last Edit: January 31, 2023, 05:25:07 pm by Aldorn »