Trying to understand and modifying detonator.h

I would like to modify detonator.h for my personal use.

  1. Is there a reason for detonator.h to use BUTTON_POWER & BUTTON_AUX2 instead of BUTTON_POWER & BUTTON_AUX ?

  2. I am trying to change the latching power button to non-latching power button:

  • One click on & armed
  • Next click off & disarmed
       case EVENTID(BUTTON_POWER, EVENT_FIRST_CLICK_SHORT, MODE_OFF):
        armed_ = false;
        SetPower(true);
        On();
        return true;

      case EVENTID(BUTTON_POWER, EVENT_FIRST_CLICK_SHORT, MODE_ON):
        SetPower(false);
        Off();
        return true;

instead of:

    switch (EVENTID(button, event, modifiers)) {
      case EVENTID(BUTTON_POWER, EVENT_LATCH_ON, MODE_OFF):
        armed_ = false;
        SetPower(true);
        On();
        return true;

      case EVENTID(BUTTON_POWER, EVENT_LATCH_OFF, MODE_ON):
      case EVENTID(BUTTON_POWER, EVENT_LATCH_OFF, MODE_OFF):
        SetPower(false);
        Off();
        return true;

Will this work ?

      case EVENTID(BUTTON_AUX2, EVENT_PRESSED, MODE_ON):
	beginArm();
	break;

      case EVENTID(BUTTON_AUX2, EVENT_RELEASED, MODE_ON):
        blast();
	return armed_;

When I press and keep pressing AUX2, I get the sound for bgnarm followed by the sound for armhum looping for as long as AUX2 is pressed (so far so good, but it doesn’t matter how long I keep it pressed, armhum just keeps on going. Isn’t it supposed to be on a timer and if timer expires, “boom”? How long is the time delay?
But then when I release AUX2, I get the sound for endarm followed by boom. Shouldn’t this be endarm OR boom ?

Thanks for any help understanding.

Cheers

  1. is working the way I want
  2. I am still getting endarm.wav followed by boom.wav:
      case EVENTID(BUTTON_AUX, EVENT_PRESSED, MODE_ON):
        beginArm();
        break;

      case EVENTID(BUTTON_AUX, EVENT_FIRST_CLICK_LONG, MODE_ON):
      case EVENTID(BUTTON_NONE, EVENT_CLASH, MODE_ON):
        blast();
        return armed_;

What can I do to get just boom.wav without endarm.wav ?

No.

The latching button is for the slider on the TD.
Does your TD not have a slider?

It’s supposed to work like a grenade.
Pushing the button 2 two seconds arms it.
After releasing the button there is a 4-second delay before it explodes.

That does seem kind of odd. It’s been a while since I configured my TD, but that doesn’t sound right.

I should try upgrading my TD to 8.x and see if it behaves as intended or not.

I don’t have a TD, I have a test bed with 3 momentary buttons.

There is no 2sec or 4 sec “delay” code in detonator.h from Github master.
There is 1.6 sec delay if ENABLE_AUDIO not enabled or delay of GetCurrentEffectLength() (less than 1 second in my case)

I am glad you agree. :grin:

Then why are you trying to modify detonator.h?

The delays come from the length of the sounds I think.
It’s been a while and I’ll have go to back and read the code to figure out how it’s supposed to work.

Arming:
Pressing AUX2 calls beginArm().
That sets lockup to ARMED and we do this:

  void SB_BeginLockup() {
    Effect *once = nullptr;
    Effect *loop = nullptr;
    switch (SaberBase::Lockup()) {
      case SaberBase::LOCKUP_ARMED:
        if (SFX_bgnarm) once = &SFX_bgnarm;
        if (SFX_armhum) loop = &SFX_armhum;
        if (!SFX_armhum && SFX_swing) loop = &SFX_swing;  // Thermal-D fallback
        break;

Then SetNextActionF(NEXT_ACTION_ARM, len); , where len is the bgnarm sound duration, and is the delay until armhum begins looping.
Then it’s armed.

BOOM:
Releasing AUX2 calls blast().
That does EndLockup, and sets the delay based on endarm.wav duration, and then calls Off(OFF_BLAST), which will do SaberBase::DoEffect(EFFECT_BOOM, 0);

Because I want to add it to the multi_prop.h portfolio of: “One prop to rule them all, and in your config bind them!” :stuck_out_tongue_winking_eye:
So I need to make it work with two non latching buttons.

Oh, it does come from the length of the sound. However, the delay is way too short to pretend it’s a grenade, unless you want to go out with it! :wink:
It needs at least 3 to 4 armhum.wav length to pretend to be a grenade (I believe somewhere between 6 to 7 seconds is the norm for a grenade to go boom).

This is one cycle of the shortest of mine (2 seconds):

so just make your endarm the length you want?

But I don’t want endarm to play before boom!
If I hear endarm I shouldn’t hear boom because boom should be “deactivated”, or did I understand wrong?

The way I see it it is either:

  • beginarm, armhum & boom
    or
  • beginarm, armhum & endarm
    or
  • you “throw” the grenade and just boom when it hits

So, you’re not wrong. My setup never had an endarm sound, so it didn’t really matter.

Generally speaking latching and non-latching buttons generate different events, so there is no reason a prop can’t support both at the same time.

If it comes from the sounds, that just means you need a longer sound, right?

The length of the arhum isn’t what matters though.
The length of bgnarm is “how long you need to hold the button to arm the grenade”. (Once it is armed, there is no going back, you have to throw it.) If you release the button before bgnarm ends, it just goes back to playing the hum sound. (maybe it should play endarm at that point.)

Then there is the delay after you let go of the button, which is a part of “boom.wav”.

The plecter detonator cards have a whole bunch of functions where they do different things and play quotes and stuff, but I really wanted my TD to just work like a grenated, although I didn’t care if the timings were actually accurate or not. AFAIK there is no lore that actually specifies exactly how a TD really works, which is why I had to go back to how real grenades work…

So if we make it a space grenade, maybe it works like:
Press button, bgnarm plays->armhum.
Release button. If button clicked within 3 seconds, endarm. (whew!)
At this point, the latching slider thing could be closed to turn everything off.
“He agrees!”
If button not re-pressed within 3 seconds (take cover), play boom.

If a longer delay is desired before the boom, just edit boom to have some more armhum sound at the front end.

Unless we’re gonna get real meta about it and theorize like “what if it lands on the button when you throw it and it disarms instead of exploding?”

Like this?

      case EVENTID(BUTTON_POWER, EVENT_LATCH_ON, MODE_OFF):
      case EVENTID(BUTTON_POWER, EVENT_FIRST_CLICK_SHORT, MODE_OFF):
        armed_ = false;
        SetPower(true);
        On();
        return true;

      case EVENTID(BUTTON_POWER, EVENT_LATCH_OFF, MODE_ON):
      case EVENTID(BUTTON_POWER, EVENT_LATCH_OFF, MODE_OFF):
      case EVENTID(BUTTON_POWER, EVENT_FIRST_CLICK_SHORT, MODE_ON):
        armed_ = false;
        SetPower(false);
        Off();
        return true;

Line 9 above doesn’t make sense to me. How can you have EVENT_LATCH_OFF in MODE_OFF? This is from the unmodified detonator.h on line 109. I believe that line can’t ever “do” anything? How can it disarm and turn off if it’s already off?

I just re-watched the scene of ROTJ in Jabba’s palace. The slider starts beginarm & armhum when moved to the on position. Then the slider does the endarm when it’s back to the off position. Oh and armhum runs for 41-42 seconds in that scene.

I don’t know by hart of an example of a TD going boom. There are many in rebels and the clone wars but if memory serves, they are of a different kind: flat magnetic bottom and a protruding button at the top (I have always imagined that the protruding button could rotate to set the delay or set the remote controlled detonation mode, but I have no lore proof of this)

And I can think of a third kind of detonator from the ark where Ahsoka goes to train Saw Gerrera’s rebels. She teaches them to throw it “gently” so it can roll inside the shield of the Droideka (Destroyer Droid) and produces an EMP to disable them. That one might be on a 3-4 seconds delay.

Why not “hold” button?
THe latching button thing is for the slider, not the button.
Why change how the button works?

Detonating the TD turns it off. (So that the hum stops playing.)

You can also add throw and bounce sounds, or something like “fire in the hole”…

IMHO, that would be a suicide grenade.
Basically, I think the slider is kind of like the “pin” on a real grenade.
And the button is kind of like the “spoon”.

On a real grenade, you remove the pin, then hold the spoon for two seconds to arm the grenade. Once you release the spoon, you have a small number of seconds before the grenade explodes.

Of course, real grenades don’t have sounds as far as I know.

On my TD, you slide the switch back: hum and lights activate. (this is the sound we hear in the movie btw.)
When you hold the button, the grenade starts beeping (bgnarm.wav)
After three beeps (~2 seconds): the grenade is ready to explode, it beeps rapidly and ligths flash rapidly for as long as the button is held. (armhum.wav)
When the button is released, we transition from armhum to boom, lights flash rapidly, then turn off, after boom has played, grenade is off and no sound or lights are playing. Detonation works the same as turning a lightsaber off, but plays “boom.wav” instead of “out.wav”.
To do the sequence again, close the slider, and re-open it.
Before starting the sequence again, it is also possible to use the button to switch presets.
(And possibly other things in the future, like accessing menus.)

My interpretation of the movie sequence is that it never goes so far as to actually arm the grenade.

We see TDs being used a fair bit in clone wars, but I haven’t studied that to see if they have better explanations for how it works. They also do remote triggering and a bunch of other stuff, as far as I remember, they just treat TDs as “throw it and it will explode when you want it to”.

I would rather not have to hold a button too long.

I don’t have a slider, I have temporary push buttons! :grin:

But my hum stopped playing anyway after boom . I made two TD fonts: one with a silent hum and the second with an audible hum. After boom, they are both silent and I had removed all EVENT_LATCH_ON/OFF from my case EVENTID

But that is what is going on in episode 6!

If you remove the pin, as long as you hold the spoon, nothing will happen.
You can even put the pin back and the grenade will be “safe” again. It is when you release the spoon that it will detonate no matter what you do. There has been several hostage situations where the bad guys did such things.

But Boushh never touched the button and it was still beeping for 42 seconds until the slider was moved back to off.

It doesn’t seem like this discussion is going anywhere. I mean, I like how my TD works, and I won’t allow incompatible changes. If you want it to work differently, you can always make your own prop, right?

Oh, I completely thought that was the purpose of this discussion; to inherit from the base detonator prop and make the actions custom to taste.

I think that’s what I meant. Press and hold. The spoon thing.

My apologies if I gave you that impression. I don’t want to change your TD. I want to change it to make my own (for personal use). I do have a PR for yours but it is mainly removing empty spaces, tabs, and adding a display controller for it because every prop deserve a bit of eye candy. I am not trying to change how your TD works. I just wanted to understand how/why it works the way it does.