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: Jason Dorje Short <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Cc: freeciv-ai@xxxxxxxxxxx
Subject: [freeciv-ai] Re: Goto coordinates and ai roles
From: Raimar Falke <rf13@xxxxxxxxxxxxxxxxx>
Date: Tue, 21 Jan 2003 08:36:33 +0100

On Mon, Jan 20, 2003 at 10:45:36PM -0500, Jason Dorje Short wrote:
> Mike Kaufman wrote:
> >On Sat, Jan 18, 2003 at 12:05:39PM -0500, Ross W. Wetmore wrote:
> >
> >>If you cannot rely on an arbitrary map_position to represent an invalid
> >>position (i.e. all map positions are potentially valid), then you need an
> >>extra bit of information somewhere. There are two common ways to do this.
> >>
> >>Set a goto_active guard bit and do things like 
> >> if (punit->goto_active) {
> >>   /* punit->goto_dest_x, punit->goto_dest_y accesses */
> >> }
> >>
> >>Make the goto_dest a map_position pointer and use null as the guard test.
> >> if (punit->goto_dest) {
> >>   /* punit->goto_dest->x, punit->goto_dest->y accesses */
> >> }
> >>
> >>Note, the pointer can point back into the punit structure, so you don't
> >>need to track extra memory allocations, and can in fact directly access 
> >>the punit goto(x,y) values if necessary, bypassing the guard check. The
> >>pointer acts very much as a guard test that allows you to turn the goto
> >>map_position on and off.
> >>
> >>Both of these mean breaking backwards compatibility for the (-1,-1)
> >>error assumptions including over network communications. But the tests
> >>are much simpler than a same_pos() or some unnormalized version to
> >>detect the special case. 
> >
> >
> >yes, either of these is far better than (-1,-1) which I've never ever had a
> >good feeling about. Take your pick really, but I prefer the the 
> >map_position
> >pointer because it's cleaner...
> 
> I agree.  I remember Raimar vetoing this idea a *long* time ago, but 
> that was for (IIRC) using pointers to positions for events (e.g., the 
> vnotify_conn_ex argument), as opposed to goto destinations.  I believe 
> his reasons were (1) (-1,-1) should be used over the network anyway to 
> preserve backward-compatability, and (2) using a pointer is slower.

(3) memory leaks you may get with this. So I'm for exactly two places
where this struct of the position is allocated and freed.

        Raimar

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
 "How about the new language C&? No, that's not 'c ampersand', 'c reference', 
  'reference to c' or 'c and'. It's pronounced 'campersand', to confuse the 
  hell out of people who are unfamiliar with it, and it will, of course, 
  have no pointers."
    -- Xazziri in comp.lang.c++ about C#



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