Complete.Org: Mailing Lists: Archives: freeciv-ai: January 2003:
[freeciv-ai] Re: Goto coordinates and ai roles
Home

[freeciv-ai] Re: Goto coordinates and ai roles

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Gregory Berkolaiko <Gregory.Berkolaiko@xxxxxxxxxxxx>
Cc: Freeciv AI development <freeciv-ai@xxxxxxxxxxx>
Subject: [freeciv-ai] Re: Goto coordinates and ai roles
From: Ross Wetmore <rwetmore@xxxxxxxxxxxx>
Date: Mon, 27 Jan 2003 19:40:02 -0500


I think if you go back and reread the entire thread your option was covered
and bypassed in favour of a pointer early on. But it was the first of the
two options suggested.

Note a correction to your analysis, the pointer is not to punit, but into
it at (struct map_position) punit->goto_dest, which should make you happy
because it is lower down the struct punit body, and make the rest happy
because it doesn't have any backwards compatibility or maintenance issues
associated with it.

I would hope that where the goto_dest memory lies should be a relatively
*un*imaginative concept, i.e. pointers can reference arbitrary memory.
If not, consider this a revelation of sorts about "C" pointers :-).

Cheers,
RossW
=====

Gregory Berkolaiko wrote:
On Thu, 23 Jan 2003, Ross W. Wetmore wrote:


The map_position pointer (to independently allocated storage) is a bit
of a maintenance headache as Raimar suggests. Go the step further and
just don't do it that way.

Instead, add the pointer to the punit struct, and point it back at the
goto_dest_x, goto_dest_y elements which you can convert to an unnamed
map_position, or a union of the existing elements and a map_position
if you need to preserve backwards compatibility. There is no need to
worry about managing memory - ever as that is done when the punit struct
is created and destroyed, and it is the only one to use this memory.

If the pointer is null the goto_dest locations are not valid, if it is
non-null it is pointed correctly and can be used to access the values,
i.e. to set a goto_dest, fill in the values (just like now) and point
to the &punit->goto_dest_x or however you reference it. To mark it as
invalid, just null out the pointer.


This is a rather imaginative approach, which invokes some rather rude associations in my dirty mind.

If I understand it correctly, this pointer will have only two possible values: pointing to the unit itself, or just NULL. I think there is a special name for a variable which takes only two values (and it doesn't invoke any rude associations in my mind, yet). Why not use it?

Best wishes,
G.



[Prev in Thread] Current Thread [Next in Thread]