Author Topic: [Example] Random fuse time.  (Read 2315 times)

Offline Nord

  • Commander
  • *****
  • Posts: 1637
  • The Gate is open.
    • View Profile
[Example] Random fuse time.
« on: August 29, 2020, 10:49:37 am »
Is there any combination of
"fuseType", "fuseTriggerEvents" and "specialChance"
, that will allow to create grenade, exploding in a random turn? Like throw and maybe it will bang in your hand or maybe after 10 hours. Or at least that can explode or not explode after timer runs out.
All i can get now is a grenade, that explode immediately after throw with random chance.
« Last Edit: February 12, 2023, 02:57:02 pm by Meridian »

Offline Yankes

  • Commander
  • *****
  • Posts: 3207
    • View Profile
Re: Random fuse time.
« Reply #1 on: August 29, 2020, 12:11:15 pm »
One way I see to do it is use scripts, rulesets set fuse to 60 and next turn script check if current value is equal it, if is then reduce it to some lower random value.

Offline Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 8616
    • View Profile
Re: Random fuse time.
« Reply #2 on: August 30, 2020, 01:26:54 pm »
Here's the script, and sample usage on xcom1 grenade.

Code: [Select]
# Random Fuse Length script by Meridian
extended:
  tags:
    RuleItem:
      RFL_IS_RANDOM: int
    BattleItem:
      RFL_IS_SET: int

  scripts:
    newTurnItem:
      - offset: 98
        code: |
          var ptr RuleItem rule;
          var int temp;
          item.getFuseTimer temp;
          # debug_log "newTurnItem: -------------";
          # debug_log "newTurnItem: getFuseTimer:" temp;
          # debug_log "newTurnItem: check if primed";
          if ge temp 0;
            item.getRuleItem rule;
            rule.getTag temp Tag.RFL_IS_RANDOM;
            # debug_log "newTurnItem: RFL_IS_RANDOM:" temp;
            # debug_log "newTurnItem: check if should be randomized";
            if neq temp 0;
              item.getTag temp Tag.RFL_IS_SET;
              # debug_log "newTurnItem: RFL_IS_SET:" temp;
              # debug_log "newTurnItem: check if already randomized";
              if eq temp 0;
                item.getFuseTimer temp;
                battle_game.randomRange temp 0 temp;
                # debug_log "newTurnItem: set new fuse length to:" temp;
                item.setFuseTimer temp;
                # debug_log "newTurnItem: mark item as processed";
                item.setTag Tag.RFL_IS_SET 1;
                return;
              end;
            end;
          end;
          # debug_log "newTurnItem: ignored";
          return;

items:
  - type: STR_GRENADE
    fuseType: 10          # 10 half-turns = 5 turns
    tags:
      RFL_IS_RANDOM: 1    # anything else than zero means true

Offline Nord

  • Commander
  • *****
  • Posts: 1637
  • The Gate is open.
    • View Profile
Re: Random fuse time.
« Reply #3 on: August 31, 2020, 02:11:43 am »
Thanks. I hope AI will use such things. It can touch player emotions unpredictably.

Offline Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 8616
    • View Profile
Re: Random fuse time.
« Reply #4 on: August 31, 2020, 10:34:58 am »
Yes, for AI this is just a normal grenade, it will use it.