Complete.Org: Mailing Lists: Archives: freeciv-dev: August 2005:
[Freeciv-Dev] Re: Accessing City Variables
Home

[Freeciv-Dev] Re: Accessing City Variables

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: YaChu Yang <yyan050@xxxxxxxxxxxxxxxxx>
Cc: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: Accessing City Variables
From: Michael Kaufman <kaufman@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 20 Aug 2005 07:18:12 -0500

On Sat, Aug 20, 2005 at 05:27:47PM +1200, YaChu Yang wrote:
> Hi,
> 
> I'm currently looking at the FreeCiv game code. I'm a real novice in C/C++, 
> and
> am very confused as to why the following code won't work:
> 
>   struct city *pTestCity;
>   int counter;
>   for (counter = 0; counter < B_LAST; counter++) {
>       pTestCity = player_find_city_by_id(game.player_ptr,
> game.global_wonders[counter]);
>       if (pTestCity != NULL) {
>               fc_fprintf(stderr, _("Not null... \n"));
>               break;
>       }
>       else
>               fc_fprintf(stderr, _("Still NULL... \n"));
>   }
>   fc_fprintf(stderr, _("Test HERE \n"));
>   if (pTestCity == NULL)
>         fc_fprintf(stderr, _("It is NULL \n"));
>   else
>       printf(pTestCity->food_stock);
> 
> Basically I want to access the players city (all cities, not including the AI
> player cities) values e.g. gold, food, production, trade etc. for the current
> player in the client mode. And the above code seems to always be returning 
> NULL
> to pTestCity, even though in the game I have created multiple cities.
> 
> I was wondering if you might have any pointers as to how I can access the 
> player
> cities values. Any help would be greatly appreciated, thanks.
> 

because game.global_wonders[] (which is game.great_wonders in CVS) stores 
city indices only for cities that have that particular wonder (or at least
it used to). And the client should only have those indices stored for those
cities and wonders _that it knows about_. So your code will pick out the food
stock in all your cities that have wonders. Below is the code fragment that 
you want I think.

-mike  

Index: client/civclient.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/civclient.c,v
retrieving revision 1.229
diff -u -r1.229 civclient.c
--- client/civclient.c  1 Aug 2005 06:48:28 -0000       1.229
+++ client/civclient.c  20 Aug 2005 12:12:46 -0000
@@ -422,6 +422,11 @@
     return;
   }
 
+  /* */
+  city_list_iterate(game.player_ptr->cities, pcity) {
+    freelog(LOG_NORMAL, "food stock is: %d", pcity->food_stock);
+  } city_list_iterate_end;
+
   waiting_for_end_turn = FALSE;
   turn_done_sent = TRUE;
 




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