[Ohrrpgce] SVN: james/8786 the cats() array is now almost always accessed via helper functions

Ralph Versteegen teeemcee at gmail.com
Thu Jun 1 18:21:13 PDT 2017


On 2 June 2017 at 02:50, James Paige <Bob at hamsterrepublic.com> wrote:

> On Wed, May 31, 2017 at 9:27 PM, Ralph Versteegen <teeemcee at gmail.com>
> wrote:
>
>>
>>
>> On 1 June 2017 at 08:12, <subversion at hamsterrepublic.com> wrote:
>>
>>> james
>>> 2017-05-31 13:12:35 -0700 (Wed, 31 May 2017)
>>> 455
>>> the cats() array is now almost always accessed via helper functions
>>> herox() heroy() herox() and herodir()
>>>
>>> These are byref functions, so values can be assigned to them also.
>>>
>>> These functions take hero caterpillar rank as an argument,
>>> eliminating all the many places where catx(n * 5) was accessed.
>>>
>>> Also added herotx() and heroty() that replace all the many times
>>> when the x and y return values were immediately divided / 20 to get
>>> hero tile x and tile y
>>> ---
>>> U   wip/game.bas
>>> U   wip/game.bi
>>> U   wip/game_udts.bi
>>> U   wip/moresubs.rbas
>>> U   wip/savegame.rbas
>>> U   wip/scriptcommands.bas
>>> U   wip/walkabouts.bas
>>> U   wip/yetmore2.bas
>>>
>>
>> Altogether, adding that bitset was quite a big project! A lot of helpful
>> cleanup.
>>
>> This would be a good use for properties actually: turn
>> hero{x,y,z,dir,tx,ty} into properties of herow. Then we will finally have a
>> real hero walkabout UDT. (And can add XYpair versions, and allow assigning
>> to tx/ty).
>>
>
> I had actually considered making these methods of herow() but herow is an
> array of 4 HeroWalkabout objects, and (as far as I know) there is no way
> for an array member to be aware of what element of the array it is in
> (short of adding a .index member and keeping it updated whenever the array
> changes)
>
> I didn't want to be writing herow(i).x(i) all over the place,especially
> since the first (i) in that would be effectively meaningless
>

I didn't think of that. But it is actually possible to look up the index
using pointer arithmetic: "this - @herow(0)".

But a .index member might be cleaner. doswap is the only place in the code
that I think of where it would need to be updated. Wait a minute... doswap
doesn't actually swap herow() elements!! It looks like swapping two heroes
will cause their speeds and xgo/ygo to be swapped! I guess this bug has
always been present, since the revision that added herow (r4792) didn't
remove anything from doswap. (doswap does call party_change_updates, which
causes herow(i).sl to be updated, but I actually think that's a bad thing.
It would be better not to unnecessarily recreate hero slices when they are
swapped since they might be customised by scripting. Of course, that sub is
called in many places, so it's a general problem).


>
>
>
>> Also, the tx, ty accessors are a great idea. I feel like supporting
>> larger tile sizes isn't going to be such a huge project.
>>
>>
> Perhaps NPCInst could also use .tx() and .ty() helper methods that do the
> same thing
>

Yes, that was what I was implying!


>
>
> _______________________________________________
> Ohrrpgce mailing list
> ohrrpgce at lists.motherhamster.org
> http://lists.motherhamster.org/listinfo.cgi/ohrrpgce-motherhamster.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.motherhamster.org/pipermail/ohrrpgce-motherhamster.org/attachments/20170602/465f1a29/attachment.htm>


More information about the Ohrrpgce mailing list