Re: [Freeciv-Dev] (PR#40755) [Patch] Commandline parameter to control which hostname is displayed at metaserver

2009-04-13 Thread Marko Lindqvist

URL: http://bugs.freeciv.org/Ticket/Display.html?id=40755 

2009/4/7 Marko Lindqvist cazf...@gmail.com:

  Server can have several dns names, and sometimes you want to
 communicate some other than one returned by hostname() to metaserver.
 Attached patch adds commandline parameter to set used server name
 manually.
  Since this can also work around some dns problems some users are
 reporting, I plan to commit this to S2_1 too.

 S2_1 version


 - ML

diff -Nurd -X.diff_ignore freeciv/server/civserver.c freeciv/server/civserver.c
--- freeciv/server/civserver.c	2007-11-27 20:36:02.0 +0200
+++ freeciv/server/civserver.c	2009-04-13 10:38:00.0 +0300
@@ -134,13 +134,17 @@
   fc_fprintf(stderr, _(Warning: the %s option is obsolete.  
 			   Use -m to enable the metaserver.\n), argv[inx]);
   showhelp = TRUE;
-} else if (is_option(--meta, argv[inx]))
+} else if (is_option(--meta, argv[inx])) {
   srvarg.metaserver_no_send = FALSE;
-else if ((option = get_option_malloc(--Metaserver,
+} else if ((option = get_option_malloc(--Metaserver,
 	 argv, inx, argc))) {
   sz_strlcpy(srvarg.metaserver_addr, option);
   free(option);
   srvarg.metaserver_no_send = FALSE;  /* --Metaserver implies --meta */
+} else if ((option = get_option_malloc(--identity,
+	   argv, inx, argc))) {
+  sz_strlcpy(srvarg.metaserver_name, option);
+  free(option);
 } else if ((option = get_option_malloc(--port, argv, inx, argc))) {
   if (sscanf(option, %d, srvarg.port) != 1) {
 	showhelp = TRUE;
@@ -223,6 +227,7 @@
 fc_fprintf(stderr, _(  -f, --file FILE\tLoad saved game FILE\n));
 fc_fprintf(stderr,
 	   _(  -h, --help\t\tPrint a summary of the options\n));
+   fc_fprintf(stderr, _(  -i, --identity ADDR\tBe known as ADDR at metaserver\n));
 fc_fprintf(stderr, _(  -l, --log FILE\tUse FILE as logfile\n));
 fc_fprintf(stderr, _(  -m, --meta\t\tNotify metaserver and 
 			 send server's info\n));
diff -Nurd -X.diff_ignore freeciv/server/meta.c freeciv/server/meta.c
--- freeciv/server/meta.c	2008-03-09 20:44:59.0 +0200
+++ freeciv/server/meta.c	2009-04-13 10:38:00.0 +0300
@@ -241,7 +241,9 @@
   }
 
   /* get hostname */
-  if (my_gethostname(host, sizeof(host)) != 0) {
+  if (srvarg.metaserver_name[0] != '\0') {
+sz_strlcpy(host, srvarg.metaserver_name);
+  } else if (my_gethostname(host, sizeof(host)) != 0) {
 sz_strlcpy(host, unknown);
   }
 
diff -Nurd -X.diff_ignore freeciv/server/srv_main.c freeciv/server/srv_main.c
--- freeciv/server/srv_main.c	2009-02-16 19:35:02.0 +0200
+++ freeciv/server/srv_main.c	2009-04-13 10:38:00.0 +0300
@@ -172,6 +172,7 @@
 
   srvarg.metaserver_no_send = DEFAULT_META_SERVER_NO_SEND;
   sz_strlcpy(srvarg.metaserver_addr, DEFAULT_META_SERVER_ADDR);
+  srvarg.metaserver_name[0] = '\0';
 
   srvarg.bind_addr = NULL;
   srvarg.port = DEFAULT_SOCK_PORT;
diff -Nurd -X.diff_ignore freeciv/server/srv_main.h freeciv/server/srv_main.h
--- freeciv/server/srv_main.h	2008-03-09 20:44:59.0 +0200
+++ freeciv/server/srv_main.h	2009-04-13 10:38:00.0 +0300
@@ -25,6 +25,7 @@
   /* metaserver information */
   bool metaserver_no_send;
   char metaserver_addr[256];
+  char metaserver_name[256];
   unsigned short int metaserver_port;
   /* address this server is to listen on (NULL = INADDR_ANY) */
   char *bind_addr;
___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


[Freeciv-Dev] (PR#40758) Bug with SVN Trunk rev 15609- disappearing grasslands shield

2009-04-13 Thread guest

URL: http://bugs.freeciv.org/Ticket/Display.html?id=40758 


I've created and tested a rollback patch, which removes all update22*
references/code and revert back resource identifiers to the 2.1.x default.

Should you need the dictionary approach, I could come up with a patch
for that too.

- Stéphane Messerli

 But I am still wondering if it would not just be simpler for
 the identifiers to be changed back to what they were before,
 i.e. the values they have in the update22* fields. I will
 check this and perhaps make a patch later if nobody can
 figure out a good reason why not to do this.

Index: server/ruleset.c
===
--- server/ruleset.c	(revision 15611)
+++ server/ruleset.c	(working copy)
@@ -69,10 +69,6 @@
 #define UNIT_CLASS_SECTION_PREFIX unitclass_
 #define UNIT_SECTION_PREFIX unit_
 
-/* savegame conversion: resource identifiers */
-char *update22one = NULL;
-char *update22two = NULL;
-
 static const char name_too_long[] = Name \%s\ too long; truncating.;
 #define check_name(name) (check_strlen(name, MAX_LEN_NAME, name_too_long))
 #define name_strlcpy(dst, src) \
@@ -1622,16 +1618,6 @@
   }
   game.control.resource_count = nval;
 
-  if (update22one) {
-free(update22one);
-  }
-  update22one = fc_calloc(nval, sizeof(char));
-
-  if (update22two) {
-free(update22two);
-  }
-  update22two = fc_calloc(nval, sizeof(char));
-
   /* avoid re-reading files */
   if (resource_sections) {
 free(resource_sections);
@@ -1932,33 +1918,6 @@
   }
 }
 
-update22one[i]
-  = secfile_lookup_str_default(file, identifier,
-   %s.update22one, rsection)[0];
-if (RESOURCE_NULL_IDENTIFIER == update22one[i]) {
-  ruleset_error(LOG_ERROR, \%s\ [%s] update22one missing value.,
-filename, rsection);
-}
-if (RESOURCE_NONE_IDENTIFIER == update22one[i]) {
-  ruleset_error(LOG_ERROR,
-\%s\ [%s] cannot use '%c' as an identifier;
- it is reserved.,
-filename, rsection, update22one[i]);
-}
-
-update22two[i]
-  = secfile_lookup_str_default(file, identifier,
-   %s.update22two, rsection)[0];
-if (RESOURCE_NULL_IDENTIFIER == update22two[i]) {
-  ruleset_error(LOG_ERROR, \%s\ [%s] update22two missing value.,
-filename, rsection);
-}
-if (RESOURCE_NONE_IDENTIFIER == update22two[i]) {
-  ruleset_error(LOG_ERROR,
-\%s\ [%s] cannot use '%c' as an identifier;
- it is reserved.,
-filename, rsection, update22two[i]);
-}
   } resource_type_iterate_end;
 
   /* base details */
Index: server/ruleset.h
===
--- server/ruleset.h	(revision 15611)
+++ server/ruleset.h	(working copy)
@@ -15,10 +15,6 @@
 
 struct conn_list;
 
-/* savegame conversion: resource identifiers */
-extern char *update22one;
-extern char *update22two;
-
 /* functions */
 void load_rulesets(void);
 void send_rulesets(struct conn_list *dest);
Index: server/savegame.c
===
--- server/savegame.c	(revision 15611)
+++ server/savegame.c	(working copy)
@@ -914,28 +914,6 @@
 }
 
 /
-  Convert an older resource into the current value.
-/
-static struct resource *update22_resource(char c)
-{
-  /* Different rulesets had different resources. */
-  if (strcmp(game.rulesetdir, civ1) == 0) {
-resource_type_iterate(presource) {
-  if (update22one[resource_index(presource)] == c) {
-return presource;
-  }
-} resource_type_iterate_end;
-  } else {
-resource_type_iterate(presource) {
-  if (update22two[resource_index(presource)] == c) {
-return presource;
-  }
-} resource_type_iterate_end;
-  }
-  return NULL;
-}
-
-/
   Return the resource for the given identifier.
 /
 static struct resource *identifier_to_resource(char c)
@@ -945,9 +923,6 @@
|| c == RESOURCE_NONE_IDENTIFIER) {
 return NULL;
   }
-  if (20199  game.version) {
-return update22_resource(c);
-  }
   return find_resource_by_identifier(c);
 }
 
Index: data/default/terrain.ruleset
===
--- data/default/terrain.ruleset	(revision 15611)
+++ data/default/terrain.ruleset	(working copy)
@@ -674,8 +674,6 @@
 ; identifier   = single-character identifier used in savegames.  This
 ;must be unique for each resource, and changing it will
 ;break savegame compatibility.
-; 

[Freeciv-Dev] (PR#40767) Revert resource identifiers and remove update22* fields

2009-04-13 Thread Madeline Book

URL: http://bugs.freeciv.org/Ticket/Display.html?id=40767 

As per discussion in #40758 I am starting a new ticket
for this issue.


---
きっちりかっちりしなさい。
Index: server/ruleset.c
===
--- server/ruleset.c	(revision 15611)
+++ server/ruleset.c	(working copy)
@@ -69,10 +69,6 @@
 #define UNIT_CLASS_SECTION_PREFIX unitclass_
 #define UNIT_SECTION_PREFIX unit_
 
-/* savegame conversion: resource identifiers */
-char *update22one = NULL;
-char *update22two = NULL;
-
 static const char name_too_long[] = Name \%s\ too long; truncating.;
 #define check_name(name) (check_strlen(name, MAX_LEN_NAME, name_too_long))
 #define name_strlcpy(dst, src) \
@@ -1622,16 +1618,6 @@
   }
   game.control.resource_count = nval;
 
-  if (update22one) {
-free(update22one);
-  }
-  update22one = fc_calloc(nval, sizeof(char));
-
-  if (update22two) {
-free(update22two);
-  }
-  update22two = fc_calloc(nval, sizeof(char));
-
   /* avoid re-reading files */
   if (resource_sections) {
 free(resource_sections);
@@ -1932,33 +1918,6 @@
   }
 }
 
-update22one[i]
-  = secfile_lookup_str_default(file, identifier,
-   %s.update22one, rsection)[0];
-if (RESOURCE_NULL_IDENTIFIER == update22one[i]) {
-  ruleset_error(LOG_ERROR, \%s\ [%s] update22one missing value.,
-filename, rsection);
-}
-if (RESOURCE_NONE_IDENTIFIER == update22one[i]) {
-  ruleset_error(LOG_ERROR,
-\%s\ [%s] cannot use '%c' as an identifier;
- it is reserved.,
-filename, rsection, update22one[i]);
-}
-
-update22two[i]
-  = secfile_lookup_str_default(file, identifier,
-   %s.update22two, rsection)[0];
-if (RESOURCE_NULL_IDENTIFIER == update22two[i]) {
-  ruleset_error(LOG_ERROR, \%s\ [%s] update22two missing value.,
-filename, rsection);
-}
-if (RESOURCE_NONE_IDENTIFIER == update22two[i]) {
-  ruleset_error(LOG_ERROR,
-\%s\ [%s] cannot use '%c' as an identifier;
- it is reserved.,
-filename, rsection, update22two[i]);
-}
   } resource_type_iterate_end;
 
   /* base details */
Index: server/ruleset.h
===
--- server/ruleset.h	(revision 15611)
+++ server/ruleset.h	(working copy)
@@ -15,10 +15,6 @@
 
 struct conn_list;
 
-/* savegame conversion: resource identifiers */
-extern char *update22one;
-extern char *update22two;
-
 /* functions */
 void load_rulesets(void);
 void send_rulesets(struct conn_list *dest);
Index: server/savegame.c
===
--- server/savegame.c	(revision 15611)
+++ server/savegame.c	(working copy)
@@ -914,28 +914,6 @@
 }
 
 /
-  Convert an older resource into the current value.
-/
-static struct resource *update22_resource(char c)
-{
-  /* Different rulesets had different resources. */
-  if (strcmp(game.rulesetdir, civ1) == 0) {
-resource_type_iterate(presource) {
-  if (update22one[resource_index(presource)] == c) {
-return presource;
-  }
-} resource_type_iterate_end;
-  } else {
-resource_type_iterate(presource) {
-  if (update22two[resource_index(presource)] == c) {
-return presource;
-  }
-} resource_type_iterate_end;
-  }
-  return NULL;
-}
-
-/
   Return the resource for the given identifier.
 /
 static struct resource *identifier_to_resource(char c)
@@ -945,9 +923,6 @@
|| c == RESOURCE_NONE_IDENTIFIER) {
 return NULL;
   }
-  if (20199  game.version) {
-return update22_resource(c);
-  }
   return find_resource_by_identifier(c);
 }
 
Index: data/default/terrain.ruleset
===
--- data/default/terrain.ruleset	(revision 15611)
+++ data/default/terrain.ruleset	(working copy)
@@ -674,8 +674,6 @@
 ; identifier   = single-character identifier used in savegames.  This
 ;must be unique for each resource, and changing it will
 ;break savegame compatibility.
-; update22one  = single-character identifier in  2.2 civ1 savegames.
-; update22two  = single-character identifier in  2.2 civ2 savegames.
 ; food = increased food production
 ; shield   = increased shield production
 ; trade= increased trade production
@@ -685,7 +683,6 @@
 graphic = ts.gold
 graphic_alt = -
 identifier  = $

[Freeciv-Dev] (PR#40767) Revert resource identifiers and remove update22* fields

2009-04-13 Thread Madeline Book

URL: http://bugs.freeciv.org/Ticket/Display.html?id=40767 

 [guest - Mon Apr 13 18:37:54 2009]:

 I've created and tested a rollback patch, which removes
 all update22* references/code and revert back resource
 identifiers to the 2.1.x default.

 - Stéphane Messerli

Also the terrain.ruleset files in the civ1 and civ2 ruleset
directories need to be updated. I'll test it with recent
and older savegames once these changes are made. Probably
savegames already made in 2.1.99 will become incompatible,
but that was to be expected. Hopefully this will be the
only drawback.

Thanks for doing this tedious work. :)


---
お手数をお掛けしました。

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


[Freeciv-Dev] (PR#40758) Bug with SVN Trunk rev 15609- disappearing grasslands shield

2009-04-13 Thread Madeline Book

URL: http://bugs.freeciv.org/Ticket/Display.html?id=40758 

This ticket is now resolved; I have started a new ticket
to deal with the resource identifier cleanup (#40767).
Please continue the discussion there.


---
家の居間に入りましょう。

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


Re: [Freeciv-Dev] (PR#40759) [patch] calc_city_units_upkeep

2009-04-13 Thread Matthias Pfafferodt

URL: http://bugs.freeciv.org/Ticket/Display.html?id=40759 

reminder for me ...

  - Since the upkeep value is removed from struct unitgold,
  the entire unitgold vector can be simplified to an array
  (c99 dynamic array if possible) of unit pointers.
 
 I tried to change unitgold_vector to units_list but I did not get
 it to work. To get something out, I did not changed this part.
 How would a c99 dynamic array look like?

-- 
Matthias Pfafferodt - http://www.mapfa.de
Matthias.Pfafferodt at mapfa.de



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


Re: [Freeciv-Dev] (PR#40759) [patch] calc_city_units_upkeep

2009-04-13 Thread Matthias Pfafferodt

URL: http://bugs.freeciv.org/Ticket/Display.html?id=40759 

Am Monday 13 April 2009 03:38:44 schrieb Madeline Book:
 URL: http://bugs.freeciv.org/Ticket/Display.html?id=40759 

  [guest - Sun Apr 12 18:29:01 2009]:
- Perhaps the values of the unit upkeep field should be
sent in unit info packets so that they do not have to
be recomputed at the client side.
  
   I will look into this.
 
  Should this be something like in the attached file
  (unit_upkeep_packages.patch.diff)? Or are additional changes needed?

 The field 'upkeep' being an array (i.e. pointer) you need to
 copy element by element (e.g. with a loop, memcpy, etc.).
 Your way would only work if the memory for the unit struct
 was not overwritten before the packet is serialized (likely
 true, but not a good assumption to make).

 Also you would need to unpack the value again at the client
 side (from packet to unit struct). See unit info handling
 functions in client/packhand.c.

 I was also wondering whether there are any places in the
 client that could make use of this extra information. This
 would involve checking where the upkeep calculation functions
 are called on the client side and simplifying the calling
 code to instead use the punit-upkeep field. Better yet
 would be to make an accessor unit_get_upkeep() (or with a
 similar name), that would wrap read access to the field.
 As a first step it could just use the old upkeep calculation
 functions (i.e. so that it ends up executing the old code
 path) so that you can test to make sure everything is
 alright, then if everything is ok you can make it use
 the punit-upkeep field by only having to change that one
 function.

 Hopefully the client uses the upkeep values in a simple
 enough way that this would be possible, that is it avoids
 any kind of tricky setting of the values or calculating
 virtual values (i.e. upkeep for a unit that does not
 actually exist in the game).


 ---
 彼は陰険な奴である印象を受けた。

I updated the patch and hope, that I understood all the code ...

The upkeep information is now send to the client and the values are updated 
each turn and if

* a unit is disbanded
* a unit is bribed by a spy
* a unit is disbanded and
* a unit is updated

are this to much information? i.e should the client now this about the own 
(OK) and all visible units (?)

The update code only needs to be called, if there are changes to the city and 
not each turn. Does this values need to be saved in the savegames? They can 
easily be recomputed.

The changes to the clients are in PR#40763.

All patches of this stack together do compile. I did not have the time to test 
it on a game ...



One related question:

The end of the output array is marked by O_LAST. But there are O_COUNT, O_MAX 
and the variable 'num_output_types' all with the same value. Should/can this 
be unified to O_LAST?

diff '--exclude=*svn*' -ur freeciv-2.1.99svn15584.gold//client/packhand.c freeciv-2.1.99svn15584.gold1//client/packhand.c
--- freeciv-2.1.99svn15584.gold//client/packhand.c	2009-04-13 20:57:13.610498460 +0200
+++ freeciv-2.1.99svn15584.gold1//client/packhand.c	2009-04-13 21:56:00.166499236 +0200
@@ -1195,7 +1195,7 @@
   bool check_focus = FALSE; /* conservative focus change */
   bool moved = FALSE;
   bool ret = FALSE;
-  
+
   punit = player_find_unit_by_id(unit_owner(packet_unit), packet_unit-id);
   if (!punit  game_find_unit_by_number(packet_unit-id)) {
 /* This means unit has changed owner. We deal with this here
@@ -1406,6 +1406,10 @@
   }
 }
 
+/* update unit upkeep */
+output_type_iterate(o) {
+  punit-upkeep[o] = packet_unit-upkeep[o];
+} output_type_iterate_end;
 punit-veteran = packet_unit-veteran;
 punit-moves_left = packet_unit-moves_left;
 punit-fuel = packet_unit-fuel;
diff '--exclude=*svn*' -ur freeciv-2.1.99svn15584.gold//common/fc_types.h freeciv-2.1.99svn15584.gold1//common/fc_types.h
--- freeciv-2.1.99svn15584.gold//common/fc_types.h	2009-04-13 20:57:03.206498100 +0200
+++ freeciv-2.1.99svn15584.gold1//common/fc_types.h	2009-04-13 21:04:48.062498776 +0200
@@ -75,6 +75,7 @@
 enum output_type_id {
   O_FOOD, O_SHIELD, O_TRADE, O_GOLD, O_LUXURY, O_SCIENCE, O_LAST
 };
+/* num_output_types = O_LAST; see common/city.c */
 #define O_COUNT num_output_types
 #define O_MAX O_LAST /* Changing this breaks network compatibility. */
 
diff '--exclude=*svn*' -ur freeciv-2.1.99svn15584.gold//common/packets.def freeciv-2.1.99svn15584.gold1//common/packets.def
--- freeciv-2.1.99svn15584.gold//common/packets.def	2009-04-13 20:57:29.806502033 +0200
+++ freeciv-2.1.99svn15584.gold1//common/packets.def	2009-04-13 21:04:48.062498776 +0200
@@ -747,6 +747,7 @@
   PLAYER owner;
   COORD x,y;
   CITY homecity;
+  UINT16 upkeep[O_MAX];
 
   UINT8 veteran;
   BOOL ai, paradropped;
diff '--exclude=*svn*' -ur freeciv-2.1.99svn15584.gold//common/unit.c freeciv-2.1.99svn15584.gold1//common/unit.c
--- 

Re: [Freeciv-Dev] (PR#40759) [patch] calc_city_units_upkeep

2009-04-13 Thread Matthias Pfafferodt

URL: http://bugs.freeciv.org/Ticket/Display.html?id=40759 

version 3:

* remove city_unit_upkeep(); the functionality is provided by 
calc_city_units_upkeep()
* additional simplification (common/city.c:city_support)

not tested at all - only something that I checked before going to sleep ...

diff '--exclude=*svn*' -ur freeciv-2.1.99svn15584.gold//client/packhand.c freeciv-2.1.99svn15584.gold1//client/packhand.c
--- freeciv-2.1.99svn15584.gold//client/packhand.c	2009-04-13 20:57:13.610498460 +0200
+++ freeciv-2.1.99svn15584.gold1//client/packhand.c	2009-04-13 21:56:00.166499236 +0200
@@ -1195,7 +1195,7 @@
   bool check_focus = FALSE; /* conservative focus change */
   bool moved = FALSE;
   bool ret = FALSE;
-  
+
   punit = player_find_unit_by_id(unit_owner(packet_unit), packet_unit-id);
   if (!punit  game_find_unit_by_number(packet_unit-id)) {
 /* This means unit has changed owner. We deal with this here
@@ -1406,6 +1406,10 @@
   }
 }
 
+/* update unit upkeep */
+output_type_iterate(o) {
+  punit-upkeep[o] = packet_unit-upkeep[o];
+} output_type_iterate_end;
 punit-veteran = packet_unit-veteran;
 punit-moves_left = packet_unit-moves_left;
 punit-fuel = packet_unit-fuel;
diff '--exclude=*svn*' -ur freeciv-2.1.99svn15584.gold//common/city.c freeciv-2.1.99svn15584.gold1//common/city.c
--- freeciv-2.1.99svn15584.gold//common/city.c	2009-04-13 20:57:03.182498213 +0200
+++ freeciv-2.1.99svn15584.gold1//common/city.c	2009-04-13 22:45:38.730498560 +0200
@@ -2152,50 +2152,14 @@
 }
 
 /**
-  Calculate upkeep of a given unit.
-**/
-void city_unit_upkeep(struct unit *punit, int *outputs, int *free_upkeep)
-{
-  struct unit_type *ut = unit_type(punit);
-  struct player *plr = unit_owner(punit);
-
-  assert(punit != NULL  ut != NULL 
-  free_upkeep != NULL  outputs != NULL);
-  memset(outputs, 0, O_COUNT * sizeof(*outputs));
-
-  /* set current upkeep on unit to zero */
-
-  output_type_iterate(o) {
-int cost = utype_upkeep_cost(ut, plr, o);
-if (cost  0) {
-  if (free_upkeep[o]  cost) {
-free_upkeep[o] -= cost;
-cost = 0;
-  } else {
-cost -= free_upkeep[o];
-free_upkeep[o] = 0;
-  }
-  outputs[o] = cost;
-}
-  } output_type_iterate_end;
-}
-
-/**
   Calculate upkeep costs.  This builds the pcity-usage[] array as well
   as setting some happiness values.
 **/
 static inline void city_support(struct city *pcity)
 {
-  int free_upkeep[O_COUNT];
   int free_unhappy = get_city_bonus(pcity, EFT_MAKE_CONTENT_MIL);
 
-  output_type_iterate(o) {
-free_upkeep[o] = get_city_output_bonus(pcity, get_output_type(o), 
-   EFT_UNIT_UPKEEP_FREE_PER_CITY);
-  } output_type_iterate_end;
-
   /* Clear all usage values. */
-  memset(pcity-usage, 0, O_COUNT * sizeof(*pcity-usage));
   pcity-martial_law = 0;
   pcity-unit_happy_upkeep = 0;
 
@@ -,13 +2186,10 @@
   }
 
   unit_list_iterate(pcity-units_supported, this_unit) {
-int upkeep_cost[O_COUNT];
 int happy_cost = city_unit_unhappiness(this_unit, free_unhappy);
 
-city_unit_upkeep(this_unit, upkeep_cost, free_upkeep);
-
 output_type_iterate(o) {
-  pcity-usage[o] += upkeep_cost[o];
+  pcity-usage[o] += punit-upkeep[o];
 } output_type_iterate_end;
 pcity-unit_happy_upkeep += happy_cost;
   } unit_list_iterate_end;
diff '--exclude=*svn*' -ur freeciv-2.1.99svn15584.gold//common/city.h freeciv-2.1.99svn15584.gold1//common/city.h
--- freeciv-2.1.99svn15584.gold//common/city.h	2009-04-13 20:57:03.186497822 +0200
+++ freeciv-2.1.99svn15584.gold1//common/city.h	2009-04-13 22:45:38.730498560 +0200
@@ -472,7 +472,6 @@
 
 int city_population(const struct city *pcity);
 int city_unit_unhappiness(struct unit *punit, int *free_happy);
-void city_unit_upkeep(struct unit *punit, int *outputs, int *free_upkeep);
 bool city_happy(const struct city *pcity);  /* generally use celebrating instead */
 bool city_unhappy(const struct city *pcity);/* anarchy??? */
 bool base_city_celebrating(const struct city *pcity);
diff '--exclude=*svn*' -ur freeciv-2.1.99svn15584.gold//common/fc_types.h freeciv-2.1.99svn15584.gold1//common/fc_types.h
--- freeciv-2.1.99svn15584.gold//common/fc_types.h	2009-04-13 20:57:03.206498100 +0200
+++ freeciv-2.1.99svn15584.gold1//common/fc_types.h	2009-04-13 21:04:48.062498776 +0200
@@ -75,6 +75,7 @@
 enum output_type_id {
   O_FOOD, O_SHIELD, O_TRADE, O_GOLD, O_LUXURY, O_SCIENCE, O_LAST
 };
+/* num_output_types = O_LAST; see common/city.c */
 #define O_COUNT num_output_types
 #define O_MAX O_LAST /* Changing this breaks network compatibility. */
 
diff '--exclude=*svn*' -ur 

Re: [Freeciv-Dev] (PR#40763) AutoReply: [patch] economic report

2009-04-13 Thread Matthias Pfafferodt

URL: http://bugs.freeciv.org/Ticket/Display.html?id=40763 

 if the upkeep for all units is calculated each turn, this information can
 be used for the economic report

 depends on ticket 40619, 40759

 compile tested and also with a short game

update the clients to use the upkeep information saved in the unit struct. At 
the moment the gold upkeep is not displayed correct (only tested with 
gtk-2.0), but the overall value (the sum in the balance) is calculated 
correct. In the next days I will not have much time to look into this ...

diff '--exclude=*svn*' -ur freeciv-2.1.99svn15584.gold4/client/gui-gtk-2.0/citydlg.c freeciv-2.1.99svn15584.gold5//client/gui-gtk-2.0/citydlg.c
--- freeciv-2.1.99svn15584.gold4/client/gui-gtk-2.0/citydlg.c	2009-02-01 19:26:51.0 +0100
+++ freeciv-2.1.99svn15584.gold5//client/gui-gtk-2.0/citydlg.c	2009-04-13 21:06:00.530500295 +0200
@@ -1644,14 +1644,8 @@
   struct unit_node_vector *nodes;
   int n, m, i;
   char buf[30];
-  int free_upkeep[O_COUNT];
   int free_unhappy = get_city_bonus(pdialog-pcity, EFT_MAKE_CONTENT_MIL);
 
-  output_type_iterate(o) {
-free_upkeep[o] = get_city_output_bonus(pdialog-pcity, get_output_type(o),
-   EFT_UNIT_UPKEEP_FREE_PER_CITY);
-  } output_type_iterate_end;
-
   if (NULL != client.conn.playing
city_owner(pdialog-pcity) != client.conn.playing) {
 units = pdialog-pcity-info_units_supported;
@@ -1711,11 +1705,8 @@
   i = 0;
   unit_list_iterate(units, punit) {
 struct unit_node *pnode;
-int upkeep_cost[O_COUNT];
 int happy_cost = city_unit_unhappiness(punit, free_unhappy);
 
-city_unit_upkeep(punit, upkeep_cost, free_upkeep);
-
 pnode = unit_node_vector_get(nodes, i);
 if (pnode) {
   GtkWidget *cmd, *pix;
@@ -1725,7 +1716,8 @@
 
   gtk_pixcomm_freeze(GTK_PIXCOMM(pix));
   put_unit_gpixmap(punit, GTK_PIXCOMM(pix));
-  put_unit_gpixmap_city_overlays(punit, GTK_PIXCOMM(pix), upkeep_cost, happy_cost);
+  put_unit_gpixmap_city_overlays(punit, GTK_PIXCOMM(pix), punit-upkeep,
+ happy_cost);
   gtk_pixcomm_thaw(GTK_PIXCOMM(pix));
 
   g_signal_handlers_disconnect_matched(cmd,
diff '--exclude=*svn*' -ur freeciv-2.1.99svn15584.gold4/client/gui-gtk-2.0/repodlgs.c freeciv-2.1.99svn15584.gold5//client/gui-gtk-2.0/repodlgs.c
--- freeciv-2.1.99svn15584.gold4/client/gui-gtk-2.0/repodlgs.c	2009-01-23 18:28:25.0 +0100
+++ freeciv-2.1.99svn15584.gold5//client/gui-gtk-2.0/repodlgs.c	2009-04-13 21:06:00.534498228 +0200
@@ -1202,7 +1202,7 @@
 {
   struct repoinfo {
 int active_count;
-int upkeep[O_MAX];
+int upkeep[O_LAST];
 int building_count;
   };
 
@@ -1222,23 +1222,14 @@
 
 memset(unitarray, '\0', sizeof(unitarray));
 city_list_iterate(client.conn.playing-cities, pcity) {
-  int free_upkeep[O_COUNT];
-
-  output_type_iterate(o) {
-free_upkeep[o] = get_city_output_bonus(pcity, get_output_type(o),
-   EFT_UNIT_UPKEEP_FREE_PER_CITY);
-  } output_type_iterate_end;
-
   unit_list_iterate(pcity-units_supported, punit) {
-int upkeep_cost[O_COUNT];
 Unit_type_id uti = utype_index(unit_type(punit));
 
-city_unit_upkeep(punit, upkeep_cost, free_upkeep);
 (unitarray[uti].active_count)++;
 if (punit-homecity) {
-	  output_type_iterate(o) {
-	unitarray[uti].upkeep[o] += upkeep_cost[o];
-	  } output_type_iterate_end;
+  output_type_iterate(o) {
+unitarray[uti].upkeep[o] += punit-upkeep[o];
+  } output_type_iterate_end;
 }
   } unit_list_iterate_end;
 } city_list_iterate_end;
diff '--exclude=*svn*' -ur freeciv-2.1.99svn15584.gold4/client/gui-sdl/citydlg.c freeciv-2.1.99svn15584.gold5//client/gui-sdl/citydlg.c
--- freeciv-2.1.99svn15584.gold4/client/gui-sdl/citydlg.c	2009-01-10 20:17:48.0 +0100
+++ freeciv-2.1.99svn15584.gold5//client/gui-sdl/citydlg.c	2009-04-13 21:06:00.538498675 +0200
@@ -616,9 +616,7 @@
   int i, step;
   SDL_Rect src_rect, dest;
   SDL_Surface *pSurf, *pZoomed;
-  
-  int upkeep_cost[O_COUNT];
-  int free_upkeep[O_COUNT];
+
   int free_unhappy;
   int happy_cost;
 
@@ -642,16 +640,9 @@
 
 free_unhappy = get_city_bonus(pCityDlg-pCity, EFT_MAKE_CONTENT_MIL);
 happy_cost = city_unit_unhappiness(pUnit, free_unhappy);
-
-output_type_iterate(o) {
-  free_upkeep[o] = get_city_output_bonus(pCityDlg-pCity, get_output_type(o),
- EFT_UNIT_UPKEEP_FREE_PER_CITY);
-} output_type_iterate_end;
-
-city_unit_upkeep(pUnit, upkeep_cost, free_upkeep);
 
-i = upkeep_cost[O_SHIELD] + upkeep_cost[O_FOOD] +
-	upkeep_cost[O_GOLD] + happy_cost;
+i = pUnit-upkeep[O_SHIELD] + pUnit-upkeep[O_FOOD] +
+pUnit-upkeep[O_GOLD] + happy_cost;
 
 if (i * pIcons-pFood-w  pSurf-w / 2) {
   step = (pSurf-w / 2 - pIcons-pFood-w) / (i - 1);
@@ 

[Freeciv-Dev] (PR#40767) Revert resource identifiers and remove update22* fields

2009-04-13 Thread guest

URL: http://bugs.freeciv.org/Ticket/Display.html?id=40767 

 Also the terrain.ruleset files in the civ1 and civ2 ruleset
 directories need to be updated. I'll test it with recent
 and older savegames once these changes are made. Probably
 savegames already made in 2.1.99 will become incompatible,
 but that was to be expected. Hopefully this will be the
 only drawback.

I've fixed the civ1 and civ2 terrain.ruleset files too. Resource
identifiers have been rolled back to 2.1.x version.
New patch attached (contains all changes and not only the new civ1/civ2
changes).

 Thanks for doing this tedious work. :)

No problem :-)
- Stéphane Messerli

Index: server/ruleset.c
===
--- server/ruleset.c	(revision 15611)
+++ server/ruleset.c	(working copy)
@@ -69,10 +69,6 @@
 #define UNIT_CLASS_SECTION_PREFIX unitclass_
 #define UNIT_SECTION_PREFIX unit_
 
-/* savegame conversion: resource identifiers */
-char *update22one = NULL;
-char *update22two = NULL;
-
 static const char name_too_long[] = Name \%s\ too long; truncating.;
 #define check_name(name) (check_strlen(name, MAX_LEN_NAME, name_too_long))
 #define name_strlcpy(dst, src) \
@@ -1622,16 +1618,6 @@
   }
   game.control.resource_count = nval;
 
-  if (update22one) {
-free(update22one);
-  }
-  update22one = fc_calloc(nval, sizeof(char));
-
-  if (update22two) {
-free(update22two);
-  }
-  update22two = fc_calloc(nval, sizeof(char));
-
   /* avoid re-reading files */
   if (resource_sections) {
 free(resource_sections);
@@ -1932,33 +1918,6 @@
   }
 }
 
-update22one[i]
-  = secfile_lookup_str_default(file, identifier,
-   %s.update22one, rsection)[0];
-if (RESOURCE_NULL_IDENTIFIER == update22one[i]) {
-  ruleset_error(LOG_ERROR, \%s\ [%s] update22one missing value.,
-filename, rsection);
-}
-if (RESOURCE_NONE_IDENTIFIER == update22one[i]) {
-  ruleset_error(LOG_ERROR,
-\%s\ [%s] cannot use '%c' as an identifier;
- it is reserved.,
-filename, rsection, update22one[i]);
-}
-
-update22two[i]
-  = secfile_lookup_str_default(file, identifier,
-   %s.update22two, rsection)[0];
-if (RESOURCE_NULL_IDENTIFIER == update22two[i]) {
-  ruleset_error(LOG_ERROR, \%s\ [%s] update22two missing value.,
-filename, rsection);
-}
-if (RESOURCE_NONE_IDENTIFIER == update22two[i]) {
-  ruleset_error(LOG_ERROR,
-\%s\ [%s] cannot use '%c' as an identifier;
- it is reserved.,
-filename, rsection, update22two[i]);
-}
   } resource_type_iterate_end;
 
   /* base details */
Index: server/ruleset.h
===
--- server/ruleset.h	(revision 15611)
+++ server/ruleset.h	(working copy)
@@ -15,10 +15,6 @@
 
 struct conn_list;
 
-/* savegame conversion: resource identifiers */
-extern char *update22one;
-extern char *update22two;
-
 /* functions */
 void load_rulesets(void);
 void send_rulesets(struct conn_list *dest);
Index: server/savegame.c
===
--- server/savegame.c	(revision 15611)
+++ server/savegame.c	(working copy)
@@ -914,28 +914,6 @@
 }
 
 /
-  Convert an older resource into the current value.
-/
-static struct resource *update22_resource(char c)
-{
-  /* Different rulesets had different resources. */
-  if (strcmp(game.rulesetdir, civ1) == 0) {
-resource_type_iterate(presource) {
-  if (update22one[resource_index(presource)] == c) {
-return presource;
-  }
-} resource_type_iterate_end;
-  } else {
-resource_type_iterate(presource) {
-  if (update22two[resource_index(presource)] == c) {
-return presource;
-  }
-} resource_type_iterate_end;
-  }
-  return NULL;
-}
-
-/
   Return the resource for the given identifier.
 /
 static struct resource *identifier_to_resource(char c)
@@ -945,9 +923,6 @@
|| c == RESOURCE_NONE_IDENTIFIER) {
 return NULL;
   }
-  if (20199  game.version) {
-return update22_resource(c);
-  }
   return find_resource_by_identifier(c);
 }
 
Index: data/civ1/terrain.ruleset
===
--- data/civ1/terrain.ruleset	(revision 15611)
+++ data/civ1/terrain.ruleset	(working copy)
@@ -552,8 +552,6 @@
 ; identifier   = single-character identifier used in savegames.  This
 ;must be unique for each resource, and changing it will
 ;