aliens

Author Topic: [Solved] constantAnimation question  (Read 3759 times)

Offline pjlasl

  • Captain
  • ***
  • Posts: 54
    • View Profile
[Solved] constantAnimation question
« on: December 31, 2021, 04:55:15 am »
Hi,

I am trying to learn how to add "floating" units so I decided to use the BETA alien found here: https://openxcom.org/forum/index.php?topic=4960.0

When I load the unit in game, you can tell it has what should be particles below it. I tried enabling the constantAnimation: true, but it doesn't work.

here is a snippet of my code, can someone tell me what I'm doing wrong?

Spoiler:
armors:
  - type: STR_BETHARIAN_ARMOR0
    spriteSheet: BETHARIAN.PCK
    spriteInv: BETHARIAN_INVENTORY.SPK
    corpseBattle:
      - STR_BETHARIAN_CORPSE
    frontArmor: 15
    sideArmor: 12
    rearArmor: 14
    underArmor: 12
    drawingRoutine: 2 # FLOATER DRAWING ROUTINE   
    movementType: 1
    constantAnimation: true
    damageModifier:
      - 1.0 # DAMAGE TYPE - NONE
      - 1.0 # DAMAGE TYPE - ARMOR PIERCING
      - 1.0 # DAMAGE TYPE - INCENDIARY
      - 1.0 # DAMAGE TYPE - HIGH EXPLOSIVE
      - 1.0 # DAMAGE TYPE - LASER
      - 1.1 # DAMAGE TYPE - PLASMA
      - 1.0 # DAMAGE TYPE - STUN
      - 1.2 # DAMAGE TYPE - MELEE
      - 1.0 # DAMAGE TYPE - ACID
      - 0.0 # DAMAGE TYPE - SMOKE
    loftempsSet: [ 1 ]


« Last Edit: February 12, 2023, 03:11:57 pm by Meridian »

Offline The Martian

  • Commander
  • *****
  • Posts: 754
  • "It implores you to listen to its arguments..."
    • View Profile
Re: constantAnimation question
« Reply #1 on: December 31, 2021, 12:21:40 pm »
You don't appear to be making any mistakes.

The sprite sheet of the Beta Alien only has the energy effect beneath it while it is in motion:


These frames are while the unit is stationary:




It should
be possible to script animated energy under the Beta Alien while stationary by adapting the code found on this thread '[Question] [Solved] [y-script] Animated armor'.

The code for the script will need to be altered to support the additional frames as at the moment it is providing a two frame torso animation.
(The specific file I'm thinking of is the chaosNA.rul file Yankes posted HERE)



Here is a modified sprite sheet for use with a script that includes an eight frame animation for while the unit is stationary:



Edit:
I just realized that there is a problem with what I suggested in that the script will draw the stationary animated torso frames while the Beta Alien is moving, overlapping the normal motion frames.

The drawingRoutine: 0 (soldier) the script was designed for has a single torso frame set that is drawn over each moving frame. The Beta Alien's drawingRoutine: 2 (floater) already includes the torso as part of each of the movement frames image.

I think It could still work if you can figure out a way to tell the script not to run while the unit is moving.
« Last Edit: December 31, 2021, 01:04:08 pm by The Martian »

Offline pjlasl

  • Captain
  • ***
  • Posts: 54
    • View Profile
Re: constantAnimation question
« Reply #2 on: December 31, 2021, 06:07:15 pm »
Thanks for the new spritesheet and explanation. I will dig into the information you provided.

It would be really nice if one could simply provide something like this:

constantAnimation: true
constantAnimationSpriteSheet: ANIMATION.PCK

extraSprites:
 - type: ANIMATION.PCK
   files:
    0: Resources/Animation/

Offline Yankes

  • Global Moderator
  • Commander
  • *****
  • Posts: 3350
    • View Profile
Re: constantAnimation question
« Reply #3 on: December 31, 2021, 06:40:22 pm »
This lined script was not exactly for this case, I make another script that have more similar case:
https://openxcom.org/forum/index.php/topic,5245.msg78242.html#msg78242
But this one work for different `drawingRoutine`.

I could prepare dedicated script that will work with this `drawingRoutine`.

Offline pjlasl

  • Captain
  • ***
  • Posts: 54
    • View Profile
Re: constantAnimation question
« Reply #4 on: December 31, 2021, 06:44:02 pm »
Ok, so I implemented the script and there is animation, but it is not what I expected LOL.

Edit: I modified the drawingRoutine to a 4 and it looks a lot better...

I need some help with what the different lines in the script do...

What exactly is being desynced?
offsetmod temp 11 0 8; #desync animation of different units

Where is anim_frame coming from?
add temp anim_frame;

What is wavegen_saw doing?
wavegen_saw temp 8 8 7;

Explain this...
mul sprite_offset 8;
add sprite_offset 8;
add sprite_offset temp;

I cannot find any documentation on what these functions do, I only found a documentation thread with examples.
« Last Edit: December 31, 2021, 06:46:02 pm by pjlasl »

Offline pjlasl

  • Captain
  • ***
  • Posts: 54
    • View Profile
Re: constantAnimation question
« Reply #5 on: December 31, 2021, 06:51:20 pm »
I copied the scripted verbatim and changed the drawingRoutine after seeing Yankes reply.
It looks better, but can it be changed to only allow the bottom to be animated?
« Last Edit: December 31, 2021, 06:56:52 pm by pjlasl »

Offline Yankes

  • Global Moderator
  • Commander
  • *****
  • Posts: 3350
    • View Profile
Re: constantAnimation question
« Reply #6 on: December 31, 2021, 07:45:37 pm »
Ok, so I implemented the script and there is animation, but it is not what I expected LOL.

Edit: I modified the drawingRoutine to a 4 and it looks a lot better...

I need some help with what the different lines in the script do...

What exactly is being desynced?
offsetmod temp 11 0 8; #desync animation of different units
Animations, without it every unit would have exactly same animation steps, and it will look very fake.
This make that each unit animation look independent of each other

Where is anim_frame coming from?
add temp anim_frame;
This is parameter to this script, there is predefined list of names that store specific script data, like:
`anim_frame` - this is global animation frame counter
`sprite_index` - this is base sprite offset in spritesheet, usually multiple of 8
`sprite_offset` - this is offset that usually change based on unit rotation

What exactly values are send to `sprite_index` and `sprite_offset` depend on current `drawingRoutine`

What is wavegen_saw doing?
wavegen_saw temp 8 8 7;

Explain this...
mul sprite_offset 8;
add sprite_offset 8;
add sprite_offset temp;

I cannot find any documentation on what these functions do, I only found a documentation thread with examples.
Exe its self is documentation, when you set verbose logging user option then it will dump all script metadata to log.
There you can find description of majority of available functions in given script.
And one fast tip: use script operation `debug_log unit "sprite_offset:" sprite_offset "sprite_index:" sprite_index;` to dump to log what exactly values script send to your script, final value returned from script will be index to current spritesheet (aka if value is `0` then it will take first sprite in it, if `1` then it will take next one).


I copied the scripted verbatim and changed the drawingRoutine after seeing Yankes reply.
It looks better, but can it be changed to only allow the bottom to be animated?
As far I know there is no "bottom", it try animate whole whole unit and because "parrot" and your unit have different layout of sprites in spritesheet you get this result.

Offline pjlasl

  • Captain
  • ***
  • Posts: 54
    • View Profile
Re: constantAnimation question
« Reply #7 on: December 31, 2021, 10:28:07 pm »
Thank you for all the help with this. one last question...

I am using the latest vscode ruleset extension and it says that I shouldn't be using scripts:. How should I structure this code?

armors:
  - type: STR_BETHARIAN_ARMOR0
    spriteSheet: BETHARIAN.PCK
    spriteInv: BETHARIAN_INVENTORY.SPK
    scripts: # <- this node
      selectUnitSprite: |
        var int temp;
        var int walking;
        unit.isWalking walking;

Offline Yankes

  • Global Moderator
  • Commander
  • *****
  • Posts: 3350
    • View Profile
Re: constantAnimation question
« Reply #8 on: January 02, 2022, 01:06:15 pm »
But for OXCE or OXC? as both have differences and I recall you need explicit set what version you check.

Offline Yankes

  • Global Moderator
  • Commander
  • *****
  • Posts: 3350
    • View Profile
Re: constantAnimation question
« Reply #9 on: January 02, 2022, 06:15:01 pm »
Code: [Select]
  - type: FLOATER_ARMOR0
    drawingRoutine: 1
    scripts:
      selectUnitSprite: |
        var int temp;
        var int walking;
        unit.isWalking walking;
        if and eq walking 0 eq blit_part BODYPART_TORSO;
          unit.getId temp;
          offsetmod temp 11 0 8; #desync animation of different units
          add temp anim_frame;
          wavegen_saw temp 5 5 5;
         
         
          mul sprite_offset 5; # `drawingRoutine: 1` have blocks of 5 frames per direction, we convert `0,1,2,...` to `0,5,10,...` offsets
          add sprite_offset temp;
         
          add sprite_index 8; #moving animations frames starts after 8 standing one
          add sprite_index sprite_offset;
        else;
          add sprite_index sprite_offset;
        end;
        return sprite_index;
Example of FLOATER animation.

Offline pjlasl

  • Captain
  • ***
  • Posts: 54
    • View Profile
Re: constantAnimation question
« Reply #10 on: January 03, 2022, 04:37:34 pm »
Sorry for the late reply. I will take a look at your scripts today. I appreciate all the help!