Author Topic: What determines the order grenades detonate?  (Read 3396 times)

Offline Countdown

  • Colonel
  • ****
  • Posts: 246
    • View Profile
What determines the order grenades detonate?
« on: August 15, 2017, 08:44:22 am »
I can't figure out how the order of grenade detonation works in TFTD when you throw multiple grenades in a single turn. In UFO it seems straightforward. The grenades go off in the order you throw them. This makes logical sense since grenades would have identical timers so the one you threw first would detonate first, the second would go off second and so on.


But in TFTD it seems inconsistent and random. I'm sure that it's not and that there is some pattern I can't detect, but they definitely don't go off based on the order you throw them. Anyone know how it works and if this is intentional or a bug?


It sounds trivial, but actually can be a little frustrating at times when you're trying to get a certain soldier a kill and then throw another grenade as backup, but the second soldier ends up getting the kill since his grenade goes off first. Or in the instance that just happened, had the grenades gone off in proper order, my man would have lived, but unfortunately they went off in reverse order and the last grenade I threw blew his cover so the earlier one which was closest to him killed him. :P


EDIT: I think they may go off based on position on the map rather than the order they are thrown, but I'm not 100% positive. And I don't know if this is how it should be or if it is an error.

EDIT 2: Apparently it doesn't go off in the order you throw them in UFO although I could swear it did.
« Last Edit: August 16, 2017, 09:46:03 am by Countdown »

Offline ohartenstein23

  • Commander
  • *****
  • Posts: 1933
  • Flamethrowers fry cyberdisk circuits
    • View Profile
Re: Grenade Detonation Order - UFO vs TFTD
« Reply #1 on: August 15, 2017, 01:47:49 pm »
The order shouldn't be different between UFO and TFTD; likely the order is the id number attached to the item when it is spawned on the battlescape, in which case the only way to tell is to look in the saved game file which will go off first.  You might notice this more in TFTD with sonic pulsers, since they cannot be destroyed by another explosion before detonating.

Offline Countdown

  • Colonel
  • ****
  • Posts: 246
    • View Profile
Re: Grenade Detonation Order - UFO vs TFTD
« Reply #2 on: August 16, 2017, 06:25:56 am »
The order shouldn't be different between UFO and TFTD

I really could swear that in UFO they exploded in the order you threw them, but when I just went and tested this wasn't the case. So unless it has changed at some point, apparently I was wrong about this.


likely the order is the id number attached to the item when it is spawned on the battlescape
Nope, I thought this might be the case too, but it's not. If it was, when testing and reloading a save, the same soldier's grenade would always be the first to go off, but I'm finding that it changes who's goes off first, but it isn't related to which soldier threw it or who threw it first or last.

So what is it then? I really can't figure this out. What determines the order they go off?

Offline ohartenstein23

  • Commander
  • *****
  • Posts: 1933
  • Flamethrowers fry cyberdisk circuits
    • View Profile
Re: What determines the order grenades detonate?
« Reply #3 on: August 16, 2017, 02:56:04 pm »
Here's where the end of turn grenade handling starts in the code.  It looks like it goes through map tiles in their ID number order, with multiple grenades in a single tile going off in the order they were loaded into the game engine, which is why it could shuffle when saving and loading.

Offline Countdown

  • Colonel
  • ****
  • Posts: 246
    • View Profile
Re: What determines the order grenades detonate?
« Reply #4 on: August 16, 2017, 07:21:08 pm »
Here's where the end of turn grenade handling starts in the code.  It looks like it goes through map tiles in their ID number order...

Hey ohartenstein23, thanks for looking into the relevant code for me (I don't know C++ myself, but I really should learn).

I guess I was on the right track when I said, "I think they may go off based on position on the map." I noticed in testing that often the grenade furthest away would go off first, and in light of the code you pointed out, I assume because it was a lower map tile number towards the map's edge. That probably means I really don't have any control over the order they go off like I was intending. Good to know for future missions.
« Last Edit: August 16, 2017, 07:22:59 pm by Countdown »