5.5 C
New York
Saturday, March 15, 2025

structure – Tips on how to Deal with Complicated Facet Results and Occasion Sequencing in a Flip-Based mostly Sport Like XCOM?


I am attempting to make a turn-based sport like XCOM, and I’ve run into an architectural drawback that I have never been capable of resolve for fairly a very long time.

In my sport, logic is totally separated from animations – when one thing occurs within the sport world, for instance, a unit is given a command to maneuver, then all the consequences of this motion are calculated, and the corresponding animations are simply queued for playback.

However I do not perceive learn how to construct logic structure bearing in mind varied negative effects correctly. The same old depth-first method, when one impact merely causes one other, and so forth in a cascade, is just not fairly appropriate.

For instance, there’s the next state of affairs:

  • a unit makes a shot (motion factors are deducted, ammo is subtracted, trajectory is calculated)

  • the shot hits an explosive barrel. its well being drops to zero and it “dies”

  • the barrel triggers the “demise rattle” impact, and it explodes

  • all items and objects across the barrel take injury

  • all tiles across the barrel are engulfed in flames

  • every affected unit loses morale

  • some items and objects die from the injury they take

  • one of many destroyed objects is one other barrel, and it additionally triggers the “demise rattle”, which ends up in a sequence response

  • panicked items begin to play out their panic actions in flip – escape, shoot, which might additionally result in chain reactions

on this state of affairs, dealing injury doesn’t instantly lead on to the demise of a unit, and its demise doesn’t instantly result in the “demise rattle”, they’ve some sort of delayed impact. and it appears to me that the system should work in a layered model – first all injury is dealt, then all deaths, then all demise rattles, and so on.

Nevertheless, there’s one other state of affairs during which this logic ought to work in another way:

  • a unit makes a sequence of photographs (a machine gun burst)

  • every of the photographs hits some goal, this goal is straight away broken, its morale drops, and a number of the victims go into the “lifeless” standing.

  • when all of the photographs are completed, the remaining results are performed – demise rattle, unit panic, chain reactions

It can be crucial right here that a number of the results ought to occur instantly after the bullet “hits”, and a few after all the “hits” – that is obligatory for the proper animation order:

  • projectile animation 1

  • injury animation

  • demise animation

  • projectile animation 2

  • injury animation

  • demise animation

  • demise rattle 1

  • demise rattle 2

  • panic 1

  • panic 2

  • and so on.

that is basically completely different from the instance with the explosion earlier, as a result of the explosion from the viewpoint of time occurs at one second, whereas the road of photographs is already stretched out in time.

the remainder of the consequences needs to be performed as regular – after all of the hits. as a result of it could be unusual if through the line some unit panicked and ran away.

I perceive learn how to hardcode such a system, however it’ll end in a really great amount of labor, and it appears to me that there’s a extra elegant method right here, which I can’t get to.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles