ToME's archeryShoot, ActorProject and Projectile

All development conversation and discussion takes place here

Moderator: Moderator

Post Reply
Message
Author
yufra
Perspiring Physicist
Posts: 1332
Joined: Tue Jul 13, 2010 2:53 pm

ToME's archeryShoot, ActorProject and Projectile

#1 Post by yufra »

In an effort to understand the Skeleton Master Archer game Freeze bug I started looking at the Projectile code and at first my eyes did indeed bleed as DG predicted. :D I believe I have a working understanding now, and am outlining my understanding of the code below.

Currently:
  1. Projectile is an Entity. This allows an Actor to move into the same tile as it.
  2. Projectile has an on_move function, so when an Actor does move into its tile the Projectile hits it. (specifically ActorProject:projectDoStop, see below).
  3. Projectile:projectile has a damtype argument that can be either a function (as it is in archeryShoot) or a simple damage type (think PHYSICAL, or ACID, etc). This can be confusing at first, but makes it very easy to generalize what a Projectile does without modifying the Projectile class itself.
  4. Projectile has a project.def table that holds the definitions(?) for the projectile, things like range, starting position, target position, damtype, etc). Very nested namespace, but is that really a problem?
  5. Projectile has an act function. This allows the Projectile to be updated by the game's tick. The actual functions are found in the ActorProject interface, namely projectDoMove, projectDoAct and projectDoStop.
  6. ActorProject:projectDoMove draws a line from the starting position to the target position, then finds the projectile's current position along that line. The next position along the line is determined and we check if there is something there to hit. The actual movement is done in Projectile:act before the ActorProject:projectDoAct or ActorProject:projectDoStop function calls.
  7. ActorProject:projectDoAct deals the damage without killing the projectile. The damtype argument is checked and either executed (if it is a function) or uses the DamageType:get(damtype).projector chain. The damage only appears to be applied to the current tile, although a custom damage projector could change this.
  8. ActorProject:projectDoStop deals damage and kills the projectile. This function explicitly checks for what type of damage (ball, cone or single tile) and then calls ActorProject:projectDoAct on each affected tile.
I am not terribly excited about the 5th point and would prefer to have the activity all within the Projectile object instead of constantly calling ActorProject to figure out how to move next, act next, etc. Before I suggest a refactor I want to check that my opinion isn't due to my poor understanding of the current code, the interfaces design pattern, or some unforeseen implication.

Also, is there a reason that ActorProject:projectDoAct doesn't have the explicit check for ball/cone types of damage? One case that would favor that sort of check would be a massive fireball that doesn't explode on impact, simply moves through and possibly knocking back (ouch!). We could generalize the in-flight action and on-stop action to be completely independent so you can have a piercing arrow (single tile PHYSICAL damage when in-flight) ending with an explosion (cone ACID damage from the vial of acid within the arrow shaft).

Specific to ToME is the 7th point, where ToME calls the huge function defined in Combat:archeryShoot. One odd thing I noticed is that the actual removal of ammo from the shooting actor is saved until this point, which seems counter-intuitive. I understand the reason (variable ammo in the case of Dual Arrows, Volley of Arrows, etc) but think this deserves some more thought. Maybe remove the maximum number of ammo for the talent at the time of shooting? If you can potentially hit 5 things shouldn't you have to shoot 5 arrows?

I wanted to get these initial thoughts out there so DG and others can look over them, and if I get the green light from DG will come up with a more detailed refactor proposal. Cheers!
<DarkGod> lets say it's intended

darkgod
Master of Eyal
Posts: 10750
Joined: Wed Jul 24, 2002 9:26 pm
Location: Angolwen
Contact:

Re: ToME's archeryShoot, ActorProject and Projectile

#2 Post by darkgod »

Yeah you got it right :)
Except that DoAct is called by DoStop to project the cone/ball on each spot.
A modification to have a huge moving ball is much deeper than you think, do not do it please :)

As for point 5, this is because a projectile is not bound to only work with talents, I plan to add more possibilities, and let the module define it's own.
So it works by having the option to work with a projection, but you could imagine heat-guided missiles and such that would not work under the basic system. Do not change either, there are very good reasons to have made it this way ;)

As for ToME archery, yes it's sucks, but I rewrote it today ;)
[tome] joylove: You can't just release an expansion like one would release a Kraken XD
--
[tome] phantomfrettchen: your ability not to tease anyone is simply stunning ;)

yufra
Perspiring Physicist
Posts: 1332
Joined: Tue Jul 13, 2010 2:53 pm

Re: ToME's archeryShoot, ActorProject and Projectile

#3 Post by yufra »

darkgod wrote:Yeah you got it right :)
Except that DoAct is called by DoStop to project the cone/ball on each spot.
Right, that is what I tried to express in the later part of point 8.
A modification to have a huge moving ball is much deeper than you think, do not do it please :)
But, but, but... ok. :D I wasn't actually thinking about having a big ball displayed on the screen, simply the fire effect reaching out from the projectile and letting the flame particle effect work its magic.
As for point 5, this is because a projectile is not bound to only work with talents, I plan to add more possibilities, and let the module define it's own.
So it works by having the option to work with a projection, but you could imagine heat-guided missiles and such that would not work under the basic system. Do not change either, there are very good reasons to have made it this way ;)
Haha, this is exactly the example I was rolling around in my head on my way to work. It brought me to a question of status: should Projectile be a first-class object that is completely independent of the Actor once launched, with its own AI (the classic projectile is move in a straight line, homing missile is A* at each step). Essentially an Actor object that can move through other Actors? Or should it be a second-class object, tied to the source Actor and have a default link as a ranged projector of damage (or some crazy function)? It sounds like you are thinking about letting it be both... I'll wait and see what your evil genius cooks up!
As for ToME archery, yes it's sucks, but I rewrote it today ;)
I thought I was careful to say it didn't suck! Hehe, I'll check out the SVN and look at the new code.
<DarkGod> lets say it's intended

darkgod
Master of Eyal
Posts: 10750
Joined: Wed Jul 24, 2002 9:26 pm
Location: Angolwen
Contact:

Re: ToME's archeryShoot, ActorProject and Projectile

#4 Post by darkgod »

Well projectiles will usually have a source entity because otherwise the game can't know who did the damage, but that does not make them "second class" IMO :)
[tome] joylove: You can't just release an expansion like one would release a Kraken XD
--
[tome] phantomfrettchen: your ability not to tease anyone is simply stunning ;)

yufra
Perspiring Physicist
Posts: 1332
Joined: Tue Jul 13, 2010 2:53 pm

Re: ToME's archeryShoot, ActorProject and Projectile

#5 Post by yufra »

darkgod wrote:Well projectiles will usually have a source entity because otherwise the game can't know who did the damage, but that does not make them "second class" IMO :)
I had not considered the link to the source entity for purposes of damage, although it is obvious now. :) My idea of "second class" was that the projectile cannot function without reference to the source entity, as opposed to a simple resolve at damage/death time to say who (the source) actually was responsible for the damage. Maybe "dependent" and "independent" rather than "first" and "second" class?
<DarkGod> lets say it's intended

darkgod
Master of Eyal
Posts: 10750
Joined: Wed Jul 24, 2002 9:26 pm
Location: Angolwen
Contact:

Re: ToME's archeryShoot, ActorProject and Projectile

#6 Post by darkgod »

Well you could make a projectile which is it's own damage source, if you had like environmental acid rains or whatever :)
[tome] joylove: You can't just release an expansion like one would release a Kraken XD
--
[tome] phantomfrettchen: your ability not to tease anyone is simply stunning ;)

shani
Halfling
Posts: 83
Joined: Tue Aug 22, 2006 9:27 am
Location: Israel

Re: ToME's archeryShoot, ActorProject and Projectile

#7 Post by shani »

Your idea of acid rains makes me want to do a module :)
I think i'll do a bizzare module with acid rains and huge man eating frogs
maybe I'll toss in a recurring friendly NPC that will tell bad jokes every now and then.
Just for the fun of programming...
Last edited by shani on Fri Aug 06, 2010 9:16 pm, edited 1 time in total.

darkgod
Master of Eyal
Posts: 10750
Joined: Wed Jul 24, 2002 9:26 pm
Location: Angolwen
Contact:

Re: ToME's archeryShoot, ActorProject and Projectile

#8 Post by darkgod »

lol:)
[tome] joylove: You can't just release an expansion like one would release a Kraken XD
--
[tome] phantomfrettchen: your ability not to tease anyone is simply stunning ;)

Post Reply