Staredit Network > Forums > Modding Assistance > Topic: Cloak unit when switching into siege mode
Cloak unit when switching into siege mode
Aug 22 2020, 7:43 am
By: Netbek  

Aug 22 2020, 7:43 am Netbek Post #1

I want to create a 'sneak mode' ability, which makes a unit cloaked but slower & unable to attack.
I figured I'd base it on siege mode instead of cloak, because I want a transition animation, and I also want to be able to give the sneaking unit a different walk animation.
I modified 'siege_transform.cpp' from the general-plugin-template-project to set/unset UnitStatus::Cloaked, UnitStatus::RequiresDetection, and UnitStatus::CloakingForFree after the unit is replaced via replaceUnitWithType().

It works, BUT only after switching back and forth one time. So the first transform does NOT cloak the unit as intended, but all following do. Another problem is that the unit becomes invisible instantly upon hitting its 'siege mode' form, but I would prefer if it became cloaked at the end of the transform anim.

Attachment: Modified 'siege_transform.cpp'

Hits: 3 Size: 7.65kb

Aug 22 2020, 11:49 am UndeadStar Post #2

Based on recent research and Arbiter cloaking code, I think you need to set the CloakingForFree status on the unit (based on observing the Arbiter effect), and give OrderId::Cloak as secondaryOrderId to the unit (because the Arbiter force surrounding units to execute the content of that order), so that the unit cloak by itself.
Logically it should work like that, unless there's something that can turn the cloaking off somewhere.

edit: whoops, thinking back on that, decloaking may not be that simple if using that method...though it may seems to work at first.

edit2: somehow, to decloak, just setting secondaryOrderId to OrderId::Decloak should work, I guess most cloaking effects are actually cleared on every frame, which is why they are renewed either by the "cloak nearby" order of the arbiter, or the secondary order of the unit cloaking by itself.

edit3: I was rereading your code, what start the invisibility is in TankMode, and what remove it is in SiegeMode, you may have it backward?

Post has been edited 3 time(s), last time on Aug 22 2020, 12:05 pm by UndeadStar.

Aug 23 2020, 9:47 pm Netbek Post #3

Thank you, it has worked! :thumbup:
I ended up changing "game_hooks.cpp" instead of "siege_transform.cpp".
Here is the code I put in "game_hooks.cpp":
//Loop through all visible units in the game.
for (CUnit *unit = *firstVisibleUnit; unit; unit = unit-> {
    if(unit->id == UnitId::siege_tank_s) {
        if(unit->sprite->mainGraphic->animation == IscriptAnimation::SpecialState2) {
        if(unit->sprite->mainGraphic->animation == IscriptAnimation::Init) {
            if(unit->sprite->mainGraphic->frameIndex == 5) {
                unit->status |= UnitStatus::CloakingForFree;

Here's a video showing the result. The video shows the code in the beginning. The description also contains a detailed step-by-step for future searchers:
It works exactly the way I want, even with the delay before cloak when entering siege mode. The Code is based on stuff Voyager taught me here (and on what you just told me ofc).

Post has been edited 1 time(s), last time on Aug 24 2020, 12:28 pm by Netbek.

  Back to forum
Please log in to reply to this topic or to report it.
Members in this topic: None.
[12:50 am]
MTiger156 -- Could try an automatic difficulty scaling based on player count. Turning down enemy HP and damage via EUD, or reducing enemy count?
[07:59 pm]
Ultraviolet -- Ya I heard that watching the vid, too. Was considering submitting Impossible Ultraviolet, but it's only technically playable with one person.. in practice playing with one person would be terrible
[05:52 pm]
MTiger156 -- Oh, the full rules for submissions only appear in the Discord server. "Single Player Only" is a big oof since I'm only good at multiplayer concepts. However I will inquire about trying a multiplayer PvE concept that can be fully played and won alone.
[10:34 am]
C(a)HeK -- greetings all, test #7 is complete :)
[08:10 am]
Ultraviolet -- you all talk Tiger :P
[03:33 am]
MTiger156 -- Holy shit, this "Maporino! 2021" event that just got announced... this is something that takes place every year? Damn I wish I knew about it sooner, this can be my huge breakthrough in motivation :0_0:
[2021-2-26. : 7:23 am]
C(a)HeK -- thank you!
[2021-2-26. : 5:14 am]
C(a)HeK -- hello all, test 6 is complete - :)
[2021-2-26. : 3:09 am]
RdeRenato -- yes
[2021-2-25. : 2:55 pm]
MTiger156 -- General Kenobi
Please log in to shout.

Members Online: armitage, Roy, MTiger156