OpenXcom Forum

Modding => Help => Topic started by: WaldoTheRanger on March 16, 2020, 07:21:30 pm

Title: XCF readiness mechanics edits. new problem
Post by: WaldoTheRanger 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;'
Title: Re: XCF readiness mechanics edits. stuck trying to call variables
Post by: Yankes 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.
Title: Re: XCF readiness mechanics edits. stuck trying to call variables
Post by: WaldoTheRanger on March 16, 2020, 08:30:09 pm
ah. that worked.
thanks.
Title: Re: XCF readiness mechanics edits. new problem
Post by: WaldoTheRanger 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.
Title: Re: XCF readiness mechanics edits. new problem
Post by: Yankes 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.
Title: Re: XCF readiness mechanics edits. new problem
Post by: WaldoTheRanger 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?
Title: Re: XCF readiness mechanics edits. new problem
Post by: Yankes 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`.
Title: Re: XCF readiness mechanics edits. new problem
Post by: WaldoTheRanger on March 17, 2020, 03:24:13 am
Oh, yeah. That should have made sense much earlier.
my bad.
Title: Re: XCF readiness mechanics edits. new problem
Post by: WaldoTheRanger 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;
Title: Re: XCF readiness mechanics edits. new problem
Post by: WaldoTheRanger 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.
Title: Re: XCF readiness mechanics edits. new problem
Post by: Yankes 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.
Title: Re: XCF readiness mechanics edits. new problem
Post by: WaldoTheRanger on March 17, 2020, 07:21:01 pm
Oh sweet.
Thanks a ton.
Title: Re: XCF readiness mechanics edits. new problem
Post by: WaldoTheRanger 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.
Title: Re: XCF readiness mechanics edits. new problem
Post by: ohartenstein23 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.
Title: Re: XCF readiness mechanics edits. new problem
Post by: WaldoTheRanger 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?
Title: Re: XCF readiness mechanics edits. new problem
Post by: ohartenstein23 on March 17, 2020, 09:06:03 pm
If you only get one firing experience point, you have a chance of rolling +0 gain in firing accuracy but still get the secondary stat rolls. You need at least 3 experience in primary stats to guarantee at least +1 in that stat, except for bravery which needs something like 10 experience for guaranteed gain.
Title: Re: XCF readiness mechanics edits. new problem
Post by: WaldoTheRanger on March 17, 2020, 09:22:22 pm
Oh I'm dum. I was confused by the difference between xp and the actual stat increases.
that's cool. actually a bit more useful anyways.
Title: Re: XCF readiness mechanics edits. new problem
Post by: Solarius Scorch on March 19, 2020, 12:42:23 pm
Guys, I appreciate the enthusiasm, but I've already made some decisions (based on our previous conversation). So feel free to experiment of course, but we don't really need anything else at this point for XCF.
Title: Re: XCF readiness mechanics edits. new problem
Post by: WaldoTheRanger on March 20, 2020, 10:46:56 pm
What a relief. I was very quickly getting in over my head :)

can't wait to see what you've got coming.