aliens

Author Topic: XCF readiness mechanics edits. new problem  (Read 4274 times)

Offline WaldoTheRanger

  • Colonel
  • ****
  • Posts: 112
    • View Profile
XCF readiness mechanics edits. new problem
« on: March 16, 2020, 07:21:30 pm »
Hello. I am trying to do something similar to what I described in this post:
https://openxcom.org/forum/index.php/topic,7987.msg124573.html#msg124573

I have gotten stuck trying to call the variable unit.getMorale and using it.

I have no idea why. it is being called and used only about 12 lines up in another script using a very similar hook.

unit.getMoraleMax seems to be working just fine.


these are the edits I'm trying to make:

from scripts_XCOMFILES.rul
Code: [Select]
   
newTurnUnit:
      - offset: 1
        code: |

          #add morale and energy totals for calculating readiness
          var int moraleLostTurn;
          var int energySpentTurn;

          var int currentMorale;
          var int currentEnergy;

          unit.getMoraleMax moraleLostTurn;
          unit.getEnergyMax energySpentTurn;
         
          unit.getMorale currentMorale;
          unit.getEnergy currentEnergy;

          sub moraleLostTurn unit.getMorale;
          sub energySpentTurn unit.getEnergy;
          unit.setTag Tag.UNIT_TOTAL_MORALE_LOST moraleLostTurn;
          unit.setTag Tag.UNIT_TOTAL_ENERGY_SPENT energySpentTurn;

          debug_log "Total Morale Lost is now" UNIT_TOTAL_MORALE_LOST;
          debug_log "Total Energy Spent is now" UNIT_TOTAL_ENERGY_SPENT;

and this is the error message I get in the log file:

[16-03-2020_07-06-48]   [ERROR]   Unknown argument 'unit.getMorale'
[16-03-2020_07-06-48]   [ERROR]   Error in matching arguments for operator 'sub'
[16-03-2020_07-06-48]   [ERROR]   Error in parsing script 'newTurnUnit' for 'Global Event Script': invalid operation in line: 'sub moraleLostTurn unit.getMorale;'
« Last Edit: March 16, 2020, 10:07:19 pm by WaldoTheRanger »

Offline Yankes

  • Commander
  • *****
  • Posts: 3194
    • View Profile
Re: XCF readiness mechanics edits. stuck trying to call variables
« Reply #1 on: March 16, 2020, 07:31:28 pm »
problem is that you can't do two operations in one:

Code: [Select]
sub moraleLostTurn unit.getMorale;Errors is that `sub` expect value as second argument not "function".
you need do something like:

Code: [Select]
unit.getMorale x; sub moraleLostTurn x;where `x` is new variable.

Offline WaldoTheRanger

  • Colonel
  • ****
  • Posts: 112
    • View Profile
Re: XCF readiness mechanics edits. stuck trying to call variables
« Reply #2 on: March 16, 2020, 08:30:09 pm »
ah. that worked.
thanks.

Offline WaldoTheRanger

  • Colonel
  • ****
  • Posts: 112
    • View Profile
Re: XCF readiness mechanics edits. new problem
« Reply #3 on: March 16, 2020, 10:10:15 pm »
now I'm trying to use those stats to set mana at the battle end, like so:
Code: [Select]
    returnFromMissionUnit:
      - offset: 1
        code: |
         
          #Mana
          var int manaCurrent;
          var int x;
          var int y;

          unit.getTag x Tag.UNIT_TOTAL_MORALE_LOST;
          unit.getTag y Tag.UNIT_TOTAL_ENERGY_SPENT;

          unit.getMana manaCurrent;
          muldiv x 1 1;
          muldiv y 1 1;
          sub manaCurrent x;
          sub manaCurrent y;
          unit.setMana manaCurrent;
It is doing nothing, but there are no compile errors.
it worked when I edited the manapool, using
Code: [Select]
BattleUnit.Stats.getManaPool and
Code: [Select]
BattleUnit.Stats.setManaPoolbut that's not quite what I want.

the muldiv 1 1 thing is for testing purposes.

Offline Yankes

  • Commander
  • *****
  • Posts: 3194
    • View Profile
Re: XCF readiness mechanics edits. new problem
« Reply #4 on: March 16, 2020, 10:29:35 pm »
Fist one, what you want change? battle unit or soldiers? this is two separate things, battle unit exists only for duration of battle and soldier exists for hole game (until he is killed).
If you use any function that start with `BattleUnit` this mean you edit game object that will soon deleted without trace.
You need look for `GeoscapeSoldier` and operations available on it.

Offline WaldoTheRanger

  • Colonel
  • ****
  • Posts: 112
    • View Profile
Re: XCF readiness mechanics edits. new problem
« Reply #5 on: March 16, 2020, 10:44:06 pm »
I am trying to change the geoscape soldier's available mana, similar to how readiness works in xcf currently, but not based on amount of turns.

So, something like this?:

Code: [Select]
          unit.getMana manaCurrent;
          muldiv x 1 1;
          muldiv y 1 1;
          sub manaCurrent x;
          sub manaCurrent y;
          GeoscapeSoldier.setMana manaCurrent;

that gives this error:
[16-03-2020_10-40-44]   [ERROR]   Error in parsing script 'returnFromMissionUnit' for 'Global Event Script': invalid operation in line: 'GeoscapeSoldier.setMana manaCurrent;'

would I need to change things to reference a geoscape soldier in other places also?

Offline Yankes

  • Commander
  • *****
  • Posts: 3194
    • View Profile
Re: XCF readiness mechanics edits. new problem
« Reply #6 on: March 16, 2020, 11:21:42 pm »
First of all you need check what operations are available for given object.
Second "Mana" is only concept in battlespace, same as health. Correct stats for Solders are `*ManaPool` or even more accuracy `setManaMissing` or `getManaMissing`.

Offline WaldoTheRanger

  • Colonel
  • ****
  • Posts: 112
    • View Profile
Re: XCF readiness mechanics edits. new problem
« Reply #7 on: March 17, 2020, 03:24:13 am »
Oh, yeah. That should have made sense much earlier.
my bad.

Offline WaldoTheRanger

  • Colonel
  • ****
  • Posts: 112
    • View Profile
Re: XCF readiness mechanics edits. new problem
« Reply #8 on: March 17, 2020, 04:13:33 am »
Well, I'm not getting any errors, but it's not doing anything. manaMissing seems to be unaffected by the script.

Code: [Select]
    returnFromMissionUnit:
     - offset: 1
        code: |         
          #Mana
          var int manaCurrent;
          var int x;
          var int y;
          var int z;

          unit.getTag x Tag.UNIT_TOTAL_MORALE_LOST;
          unit.getTag y Tag.UNIT_TOTAL_ENERGY_SPENT;

          muldiv x 1 2;
          muldiv y 1 10;
          add x y;

          soldier.getManaMissing z;
          add x z;
          soldier.setManaMissing x;
« Last Edit: March 17, 2020, 05:51:10 am by WaldoTheRanger »

Offline WaldoTheRanger

  • Colonel
  • ****
  • Posts: 112
    • View Profile
Re: XCF readiness mechanics edits. new problem
« Reply #9 on: March 17, 2020, 07:04:30 pm »
I find this really weird.
when I use soldier.setManaMissing x; it does nothing.
when I use soldier.Stats.setManaPool x;, that works. but that's not what I want. I don't want soldiers to be permanently crippled after a single gang fight.

Offline Yankes

  • Commander
  • *****
  • Posts: 3194
    • View Profile
Re: XCF readiness mechanics edits. new problem
« Reply #10 on: March 17, 2020, 07:17:52 pm »
Ok, unfortunate code order, script is first run and after that game update `setManaMissing`this mean overwrite value you set.
I will see how best handle this case, I will fix it to allow custom scripts to alter it in one way or another.

Offline WaldoTheRanger

  • Colonel
  • ****
  • Posts: 112
    • View Profile
Re: XCF readiness mechanics edits. new problem
« Reply #11 on: March 17, 2020, 07:21:01 pm »
Oh sweet.
Thanks a ton.

Offline WaldoTheRanger

  • Colonel
  • ****
  • Posts: 112
    • View Profile
Re: XCF readiness mechanics edits. new problem
« Reply #12 on: March 17, 2020, 08:30:19 pm »
Also, if there isn't a particular reason for there not being a BattleUnit.Exp.get[stat increase] for time units, stamina, and health, then it would be nice if those could be added.

Offline ohartenstein23

  • Commander
  • *****
  • Posts: 1931
  • Flamethrowers fry cyberdisk circuits
    • View Profile
Re: XCF readiness mechanics edits. new problem
« Reply #13 on: March 17, 2020, 08:34:00 pm »
Also, if there isn't a particular reason for there not being a BattleUnit.Exp.get[stat increase] for time units, stamina, and health, then it would be nice if those could be added.

Those can't be added because they don't exist even in the unscripted part of the code. If you get battle experience in any way, you automatically get a chance to roll increases in those stats.

Offline WaldoTheRanger

  • Colonel
  • ****
  • Posts: 112
    • View Profile
Re: XCF readiness mechanics edits. new problem
« Reply #14 on: March 17, 2020, 08:55:52 pm »
ok. makes sense.

so does that also mean that there's no circumstance in which you'd only get an increase in those stats and nothing else?