aliens

Author Topic: How to force a blaster explosion?  (Read 4858 times)

Offline TCH

  • Squaddie
  • *
  • Posts: 8
    • View Profile
How to force a blaster explosion?
« on: August 21, 2019, 04:32:00 pm »
I'm trying to add a new hotkey in debug mode for creating a blaster explosion. However, it does not want to work.

Code: [Select]
// B - create blaster bomb explosion
else if (_save->getDebugMode() && action->getDetails()->key.keysym.sym == SDLK_b && (SDL_GetModState() & KMOD_CTRL) != 0)
{
debug("Blast it!");
Position newPos;
_map->getSelectorPosition(&newPos);
newPos.x *= 16;
newPos.y *= 16;
newPos.z *= 24;
if (newPos.x >= 0)
{
//_save->getTileEngine()->explode(newPos, 320, DT_HE, 16, _save->getSelectedUnit());
_battleGame->statePushFront(new ExplosionBState(_battleGame, newPos, new BattleItem(new RuleItem("STR_HWP_FUSION_BOMB"), _save->getCurrentItemId()), _save->getSelectedUnit()));
}
}

The explode() call what is commented out, works, but only makes the terrain changes and do the damage to items and units. I could live without the animation and sound of the explosion, but the so-damaged-they-should-die units only die after the end of turn.

I tried to copy the ExplosionBState calls, but i am missing something.

Any ideas?

Offline kevL

  • Colonel
  • ****
  • Posts: 482
  • pitchforks and torches
    • View Profile
Re: How to force a blaster explosion?
« Reply #1 on: August 22, 2019, 10:11:49 am »
look into BattlescapeGame::checkForCasualties()

iirc, that "finalizes the dead"

and take a look at the debugmode autokill command to get a general idea of its usage:
https://github.com/OpenXcom/OpenXcom/blob/master/src/Battlescape/BattlescapeState.cpp#L1564

and search "checkForCasualties" in the codebase


the reason they die at the end of the turn is because, iirc, checkForCasualties() is run as a sort of safety clean-up at the end of every turn,

Offline TCH

  • Squaddie
  • *
  • Posts: 8
    • View Profile
Re: How to force a blaster explosion?
« Reply #2 on: August 22, 2019, 04:30:46 pm »
Thanks for answering. I've copied the necessary code and it worked, now the damaged units which should have died, died. However i forgot to tell in the opening post, that the explode() also do not trigger the chain explosions until end of turn. I've found checkForExplosions() and applied and that worked too.

However in the meantime i figured it out, that if i give no item, unit and tile to ExplosionBState and i use statePushNext() instead of statePushFront() then the explosion works normally. However, it's power is always 120, because if i try to create a blaster item and use it, then it does not explode.

So, instead of futile tryings, i modified the ExplosionBState class to be able to accept a new param (forcedPower) which overwrites the wired-in 120. (But i had set its' default to 120, to preserve backward compatibility.) I also modified the tile and itemless explosion's default radius (6), to divide the given power by 20. (Which is 120, so the default radius is still 6, but now it's dynamic.)

Patch is here: http://oscomp.hu/depot/ExplosionBState.patch

And with that, i was able to add the new function to debug mode, to create custom explosions. I made it configurable (debugBlast in options.cfg) and i added two more hotkeys (Ctrl + KP_PLUS/Ctrl + KP_MINUS), to be able to increase/decrease this value ingame. The step is also configurable. (debugBlastStep)

Patch for this is here: http://oscomp.hu/depot/DebugBlast.patch