<URL: http://bugs.freeciv.org/Ticket/Display.html?id=39743 >

Pepeto _ wrote:
> 1-Static or dynamics datas?
> 
> The most of the main structures (player, connection, advance, ...)
> except city and unit are declared static (for example
> game.players[MAX_NUM_PLAYERS + MAX_NUM_BARBARIANS];). Is this a
> deliberate choice? Maybe it could be a player_list, then there shouldn't
> have maximum of players. I understand that it was certainly to find
> player by id faster, but it seems that the unit/city->owner is now a
> pointer.
> 
Apparently, according to comments in the code and the HACKING file,
everything was once indices, to be compatible with the network code.

Gradually, many things have changed to pointers.  Much easier to find
bad or uninitialized values.  I've recently done this with a lot of
player, advance, etc.  Look at trunk and 2.2, not 2.1.

In my time here, the unit/city->owner has always been a pointer, with
an accessor function that can more easily be changed.  Making sure
everything uses the accessor function has been a task I've been doing.

There are bit fields for players, so the maximum is fixed.

There are bit fields for advances, so the maximum is fixed.


> 2-struct unit
> 
> I see numerous ids in this structures. Shouldn't they be replaced by
> pointers?
> homecity could be a (struct city *)
> transported_by could be a (struct unit *)
> It could be a struct unit_list *transported_units, to find faster and
> clearer what units are transported. Then occupancy member would be
> replaced by unit_list_size().
> 
There are earlier messages on this topic.  For whatever design reason,
the unit and city are usually numbers, not pointers.  In the current
code, units and cities can suddenly disappear.  The code has to check
whether they still exist every time something is processed.

There is a way to do this with pointers and an indexed table, checking
for valid entries.  It would be a lot of work to change, and it's not a
high priority.

As for transported_by, there is already a technique for listing the
transported units, an iterator on the units at a tile.


> 3-struct city
> 

> struct trade_route {
>   struct city *city1, *city2;
>   int value;
> };


> enum trade_route_status {
>   TRADE_ROUTE_PLANNED,
>   TRADE_ROUTE_IN_ROUTE,
>   TRADE_ROUTE_IN_ROUTE_AND_PLANNED,
>   TRADE_ROUTE_ESTABLISHED
> };
> 
Seems like a good idea to me....  But not a high priority.



_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to