Page 1 of 1

Coding an Aura

PostPosted: Wednesday, 13th January 2016, 23:42
by infinitevox
--Decided to revert to an earlier version and try something different, still getting an error xD--
What I want, is a doughnut shaped "silence" aura. ie, it affects a square 2 tiles around the player, but not the tile the player is standing on.
I can achieve an easy silence aura by just returning the radius I want in the silence_radius(), but that silences the player also. Not exactly what I need here :p

I do C#, not so much C++
If anyone has any insight, I'd really appreciate it! :)

coord-circle.h
  Code:
enum circle_type
{
    C_CIRCLE,      // circle specified by pre-squared radius
    C_POINTY,      // circle with square radius r*r
    C_ROUND,       // circle with square radius r*r+1
    C_SQUARE,      // square with radius r
    C_DOUGHNUT     // square with hole in center
};

coord-circle.cc
  Code:
 
void circle_def::init(int param, circle_type ctype)
{
    switch (ctype)
    {
    case C_CIRCLE:
        radius_sq = param;
        radius = isqrt_ceil(radius_sq);
        break;
    case C_ROUND:
        radius = param;
        radius_sq = radius * radius + 1;
        break;
    case C_POINTY:
        radius = param;
        radius_sq = radius * radius;
        break;
    case C_SQUARE:
        radius = param;
        break;
   case C_DOUGHNUT:
      radius = param;
      radius_sq = (radius - origin.rdist());     // I don't think this will work, it returns an int, but is what I want even possible using this method?
    }
    is_square = (ctype == C_SQUARE);
    init_bbox();
}

Re: Coding an Aura

PostPosted: Thursday, 14th January 2016, 12:48
by wheals
I think you're barking up the wrong tree. You want to check out the _actor_areas function in areas.cc, and add a method to the actor class so that can check if it's using your new spell instead of the normal silence spell (unless this is replacing silence entirely, in which case you can skip that), and modify the radius_iterator constructor there. There's an exclude_center parameter you can pass it.

Re: Coding an Aura

PostPosted: Thursday, 14th January 2016, 15:31
by infinitevox
wheals wrote:I think you're barking up the wrong tree. You want to check out the _actor_areas function in areas.cc, and add a method to the actor class so that can check if it's using your new spell instead of the normal silence spell (unless this is replacing silence entirely, in which case you can skip that), and modify the radius_iterator constructor there. There's an exclude_center parameter you can pass it.

That's what I tried originally, but kept running into a "FixedArray" error when I tried to compile.
The other issue is that in the radius_iterator you can only pass an int for r, but I'm guessing from what you're saying is that there is another parameter I'm missing.
I'll mess around some more and see where I can pass exclude_center, trying it that way.
Thank you for the help :)

This is probably the wrong place to try and pass this, but I'm basically guessing right now :p
  Code:
static void _actor_areas(actor *a)
{
    int r;
// regular silence spell as an example
    if ((r = a->silence_radius()) >= 0)
    {
        _agrid_centres.emplace_back(AREA_SILENCE, a->pos(), r);

        for (radius_iterator ri(a->pos(), r, C_SQUARE); ri; ++ri)
            _set_agrid_flag(*ri, areaprop::SILENCE);
        no_areas = false;
    }
// my silence aura
   if ((r = a->sil_aura_radius()) >= 0)
    {
        _agrid_centres.emplace_back(AREA_SILENCE, a->pos(), r);

        for (radius_iterator ri(a->pos(), r, C_SQUARE, exclude_center); ri; ++ri)
            _set_agrid_flag(*ri, areaprop::SILENCE);
        no_areas = false;
    }


Then:
  Code:
// return radius of silence as an example
int player::silence_radius() const
{
    return _silence_range(duration[DUR_SILENCE]);
}

// return radius of my silence aura
int player::sil_aura_radius() const
{
   if (you.species == SP_FOO)
   {
      return 2;
   }
   return -1;
}

// snippet to handle monster radius
int monster::sil_aura_radius() const
{
    return -1;
}

Re: Coding an Aura

PostPosted: Thursday, 14th January 2016, 17:01
by wheals
infinitevox wrote:
  Code:

        for (radius_iterator ri(a->pos(), r, C_SQUARE, true); ri; ++ri)



I think this will get it working (you need to pass true for exclude_center so it, well, excludes the center).

Re: Coding an Aura

PostPosted: Thursday, 14th January 2016, 21:27
by infinitevox
Thank you for that
I won't be able to compile and test until tonight, at the earliest, but I'm rather hopeful about this :D

Re: Coding an Aura

PostPosted: Monday, 18th January 2016, 19:48
by infinitevox
wheals wrote:
infinitevox wrote:
  Code:

        for (radius_iterator ri(a->pos(), r, C_SQUARE, true); ri; ++ri)



I think this will get it working (you need to pass true for exclude_center so it, well, excludes the center).


Sorry for double post and stuff, but I wanted to let you know that this worked perfectly!
It kills me that I didn't see that you could pass _exlude_center there though :p
Thanks again!