[Freeciv-commits] r28858 - /branches/S2_6/ai/threaded/taicity.c

2015-04-24 Thread cazfi74
Author: cazfi
Date: Fri Apr 24 17:34:55 2015
New Revision: 28858

URL: http://svn.gna.org/viewcvs/freeciv?rev=28858&view=rev
Log:
Turned inner part of tai_city_worker_task_select(), checking single tile, to a 
separate function

See patch #6025

Modified:
branches/S2_6/ai/threaded/taicity.c

Modified: branches/S2_6/ai/threaded/taicity.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/ai/threaded/taicity.c?rev=28858&r1=28857&r2=28858&view=diff
==
--- branches/S2_6/ai/threaded/taicity.c (original)
+++ branches/S2_6/ai/threaded/taicity.c Fri Apr 24 17:34:55 2015
@@ -77,57 +77,135 @@
   }
 }
 
+struct tai_tile_state
+{
+  int uw_max;
+  int worst_worked;
+  int orig_worst_worked;
+  int old_worst_worked;
+};
+
 /**
-  Select worker task suitable for the city.
-
-  TODO: This largely duplicates settler_evaluate_improvements(). Should
-maybe find a way to reuse parts in some common function. OTOH
-though this has started as almost-copy of
-settler_evaluate_improvements(), this is likely to turn very different
-function as part of threaded ai with more CPU to burn.
+  Select worker task suitable for the tile.
 **/
-static bool tai_city_worker_task_select(struct player *pplayer, struct city 
*pcity,
-struct worker_task *task,
-enum tai_worker_task_limitation limit)
-{
-  struct worker_task *selected;
-  struct worker_task worked = { .ptile = NULL, .want = 0, .act = 
ACTIVITY_IDLE, .tgt = NULL };
-  struct worker_task unworked = { .ptile = NULL, .want = 0, .act = 
ACTIVITY_IDLE, .tgt = NULL };
-  int uw_max = 0;
-  int worst_worked = FC_INFINITY;
-  int old_worst_worked = FC_INFINITY;
-  int orig_worst_worked = 0;
-  struct unit_list *units = NULL;
-
-  switch (limit) {
-  case TWTL_CURRENT_UNITS:
-units = pplayer->units;
-break;
-  }
-
-  city_tile_iterate_index(city_map_radius_sq_get(pcity), city_tile(pcity),
-  ptile, cindex) {
-int orig_value;
-bool potential_worst_worked = FALSE;
-
-if (!city_can_work_tile(pcity, ptile)) {
+static void tai_tile_worker_task_select(struct player *pplayer,
+struct city *pcity, struct tile *ptile,
+int cindex, struct unit_list *units,
+struct worker_task *worked,
+struct worker_task *unworked,
+struct tai_tile_state *state)
+{
+  int orig_value;
+  bool potential_worst_worked = FALSE;
+
+  if (!city_can_work_tile(pcity, ptile)) {
+return;
+  }
+
+  orig_value = city_tile_value(pcity, ptile, 0, 0);
+
+  if (tile_worked(ptile) == pcity
+  && orig_value < state->worst_worked) {
+state->worst_worked = orig_value;
+state->orig_worst_worked = orig_value;
+potential_worst_worked = TRUE;
+  }
+
+  as_transform_activity_iterate(act) {
+bool consider = TRUE;
+bool possible = FALSE;
+enum extra_cause cause;
+enum extra_rmcause rmcause;
+
+/* Do not request activities that already are under way. */
+unit_list_iterate(ptile->units, punit) {
+  if (unit_owner(punit) == pplayer
+  && unit_has_type_flag(punit, UTYF_SETTLERS)
+  && punit->activity == act) {
+consider = FALSE;
+break;
+  }
+} unit_list_iterate_end;
+
+if (!consider) {
   continue;
 }
 
-orig_value = city_tile_value(pcity, ptile, 0, 0);
-
-if (tile_worked(ptile) == pcity
-&& orig_value < worst_worked) {
-  worst_worked = orig_value;
-  orig_worst_worked = orig_value;
-  potential_worst_worked = TRUE;
+cause = activity_to_extra_cause(act);
+rmcause = activity_to_extra_rmcause(act);
+
+unit_list_iterate(units, punit) {
+  struct extra_type *tgt = NULL;
+
+  if (cause != EC_NONE) {
+tgt = next_extra_for_tile(ptile, cause, pplayer, punit);
+  } else if (rmcause != ERM_NONE) {
+tgt = prev_extra_in_tile(ptile, rmcause, pplayer, punit);
+  }
+
+  if (can_unit_do_activity_targeted_at(punit, act, tgt, ptile)) {
+possible = TRUE;
+break;
+  }
+} unit_list_iterate_end;
+
+if (possible) {
+  int value = adv_city_worker_act_get(pcity, cindex, act);
+
+  if (tile_worked(ptile) == pcity) {
+if ((value - orig_value) * TWMP > worked->want) {
+  worked->want  = TWMP * (value - orig_value);
+  worked->ptile = ptile;
+  worked->act   = act;
+  worked->tgt   = NULL;
+}
+if (value > state->old_worst_worked) {
+  /* After improvement it would not be the worst */
+  potential_worst_worked = FALSE;
+   

[Freeciv-commits] r28857 - /trunk/ai/threaded/taicity.c

2015-04-24 Thread cazfi74
Author: cazfi
Date: Fri Apr 24 17:34:48 2015
New Revision: 28857

URL: http://svn.gna.org/viewcvs/freeciv?rev=28857&view=rev
Log:
Turned inner part of tai_city_worker_task_select(), checking single tile, to a 
separate function

See patch #6025

Modified:
trunk/ai/threaded/taicity.c

Modified: trunk/ai/threaded/taicity.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/ai/threaded/taicity.c?rev=28857&r1=28856&r2=28857&view=diff
==
--- trunk/ai/threaded/taicity.c (original)
+++ trunk/ai/threaded/taicity.c Fri Apr 24 17:34:48 2015
@@ -77,57 +77,135 @@
   }
 }
 
+struct tai_tile_state
+{
+  int uw_max;
+  int worst_worked;
+  int orig_worst_worked;
+  int old_worst_worked;
+};
+
 /**
-  Select worker task suitable for the city.
-
-  TODO: This largely duplicates settler_evaluate_improvements(). Should
-maybe find a way to reuse parts in some common function. OTOH
-though this has started as almost-copy of
-settler_evaluate_improvements(), this is likely to turn very different
-function as part of threaded ai with more CPU to burn.
+  Select worker task suitable for the tile.
 **/
-static bool tai_city_worker_task_select(struct player *pplayer, struct city 
*pcity,
-struct worker_task *task,
-enum tai_worker_task_limitation limit)
-{
-  struct worker_task *selected;
-  struct worker_task worked = { .ptile = NULL, .want = 0, .act = 
ACTIVITY_IDLE, .tgt = NULL };
-  struct worker_task unworked = { .ptile = NULL, .want = 0, .act = 
ACTIVITY_IDLE, .tgt = NULL };
-  int uw_max = 0;
-  int worst_worked = FC_INFINITY;
-  int old_worst_worked = FC_INFINITY;
-  int orig_worst_worked = 0;
-  struct unit_list *units = NULL;
-
-  switch (limit) {
-  case TWTL_CURRENT_UNITS:
-units = pplayer->units;
-break;
-  }
-
-  city_tile_iterate_index(city_map_radius_sq_get(pcity), city_tile(pcity),
-  ptile, cindex) {
-int orig_value;
-bool potential_worst_worked = FALSE;
-
-if (!city_can_work_tile(pcity, ptile)) {
+static void tai_tile_worker_task_select(struct player *pplayer,
+struct city *pcity, struct tile *ptile,
+int cindex, struct unit_list *units,
+struct worker_task *worked,
+struct worker_task *unworked,
+struct tai_tile_state *state)
+{
+  int orig_value;
+  bool potential_worst_worked = FALSE;
+
+  if (!city_can_work_tile(pcity, ptile)) {
+return;
+  }
+
+  orig_value = city_tile_value(pcity, ptile, 0, 0);
+
+  if (tile_worked(ptile) == pcity
+  && orig_value < state->worst_worked) {
+state->worst_worked = orig_value;
+state->orig_worst_worked = orig_value;
+potential_worst_worked = TRUE;
+  }
+
+  as_transform_activity_iterate(act) {
+bool consider = TRUE;
+bool possible = FALSE;
+enum extra_cause cause;
+enum extra_rmcause rmcause;
+
+/* Do not request activities that already are under way. */
+unit_list_iterate(ptile->units, punit) {
+  if (unit_owner(punit) == pplayer
+  && unit_has_type_flag(punit, UTYF_SETTLERS)
+  && punit->activity == act) {
+consider = FALSE;
+break;
+  }
+} unit_list_iterate_end;
+
+if (!consider) {
   continue;
 }
 
-orig_value = city_tile_value(pcity, ptile, 0, 0);
-
-if (tile_worked(ptile) == pcity
-&& orig_value < worst_worked) {
-  worst_worked = orig_value;
-  orig_worst_worked = orig_value;
-  potential_worst_worked = TRUE;
+cause = activity_to_extra_cause(act);
+rmcause = activity_to_extra_rmcause(act);
+
+unit_list_iterate(units, punit) {
+  struct extra_type *tgt = NULL;
+
+  if (cause != EC_NONE) {
+tgt = next_extra_for_tile(ptile, cause, pplayer, punit);
+  } else if (rmcause != ERM_NONE) {
+tgt = prev_extra_in_tile(ptile, rmcause, pplayer, punit);
+  }
+
+  if (can_unit_do_activity_targeted_at(punit, act, tgt, ptile)) {
+possible = TRUE;
+break;
+  }
+} unit_list_iterate_end;
+
+if (possible) {
+  int value = adv_city_worker_act_get(pcity, cindex, act);
+
+  if (tile_worked(ptile) == pcity) {
+if ((value - orig_value) * TWMP > worked->want) {
+  worked->want  = TWMP * (value - orig_value);
+  worked->ptile = ptile;
+  worked->act   = act;
+  worked->tgt   = NULL;
+}
+if (value > state->old_worst_worked) {
+  /* After improvement it would not be the worst */
+  potential_worst_worked = FALSE;
+} else {
+  state->worst_wo

[Freeciv-commits] r28859 - in /trunk/server: savecompat.c savegame2.c savegame3.c

2015-04-24 Thread cazfi74
Author: cazfi
Date: Fri Apr 24 21:02:42 2015
New Revision: 28859

URL: http://svn.gna.org/viewcvs/freeciv?rev=28859&view=rev
Log:
Rearranged trait information save format so tabular format can be used.

See patch #6027

Modified:
trunk/server/savecompat.c
trunk/server/savegame2.c
trunk/server/savegame3.c

Modified: trunk/server/savecompat.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/savecompat.c?rev=28859&r1=28858&r2=28859&view=diff
==
--- trunk/server/savecompat.c   (original)
+++ trunk/server/savecompat.c   Fri Apr 24 21:02:42 2015
@@ -761,6 +761,7 @@
 bool got_first_city;
 int old_barb_type;
 enum barbarian_type new_barb_type;
+int i;
 
 /* Renamed 'capital' to 'got_first_city'. */
 if (secfile_lookup_bool(loading->file, &got_first_city, 
@@ -775,6 +776,21 @@
 new_barb_type = barb_type_convert(old_barb_type);
 secfile_insert_str(loading->file, barbarian_type_name(new_barb_type),
"player%d.ai.barb_type", plrno);
+
+for (i = 0; i < loading->trait.size; i++) {
+  int val;
+
+  val = secfile_lookup_int_default(loading->file, -1, "pĺr%d.trait.val%d",
+   plrno, i);
+  if (val != -1) {
+secfile_insert_int(loading->file, val, "plr%d.trait%d.val", plrno, i);
+  }
+
+  if (secfile_lookup_int(loading->file, &val, "plr%d.trait.mod%d", plrno, 
i)) {
+log_sg("Trait mod: %s", secfile_error());
+  }
+  secfile_insert_int(loading->file, val, "plr%d.trait%d.mod", plrno, i);
+}
   }
 
   /* Units orders. */

Modified: trunk/server/savegame2.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/savegame2.c?rev=28859&r1=28858&r2=28859&view=diff
==
--- trunk/server/savegame2.c(original)
+++ trunk/server/savegame2.cFri Apr 24 21:02:42 2015
@@ -2667,7 +2667,7 @@
   enum trait tr = trait_by_name(loading->trait.order[i], fc_strcasecmp);
 
   if (trait_is_valid(tr)) {
-int val = secfile_lookup_int_default(loading->file, -1, 
"plr%d.trait.val%d",
+int val = secfile_lookup_int_default(loading->file, -1, 
"plr%d.trait%d.val",
  plrno, i);
 
 if (val != -1) {
@@ -2675,7 +2675,7 @@
 }
 
 if (secfile_lookup_int(loading->file, &val,
-   "plr%d.trait.mod%d", plrno, i)) {
+   "plr%d.trait%d.mod", plrno, i)) {
   plr->ai_common.traits[tr].mod = val;
 }
   }

Modified: trunk/server/savegame3.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/savegame3.c?rev=28859&r1=28858&r2=28859&view=diff
==
--- trunk/server/savegame3.c(original)
+++ trunk/server/savegame3.cFri Apr 24 21:02:42 2015
@@ -3644,7 +3644,7 @@
   enum trait tr = trait_by_name(loading->trait.order[i], fc_strcasecmp);
 
   if (trait_is_valid(tr)) {
-int val = secfile_lookup_int_default(loading->file, -1, 
"plr%d.trait.val%d",
+int val = secfile_lookup_int_default(loading->file, -1, 
"plr%d.trait%d.val",
  plrno, i);
 
 if (val != -1) {
@@ -3652,7 +3652,7 @@
 }
 
 if (secfile_lookup_int(loading->file, &val,
-   "plr%d.trait.mod%d", plrno, i)) {
+   "plr%d.trait%d.mod", plrno, i)) {
   plr->ai_common.traits[tr].mod = val;
 }
   }
@@ -3925,9 +3925,9 @@
 
 for (tr = trait_begin(), j = 0; tr != trait_end(); tr = trait_next(tr), 
j++) {
   secfile_insert_int(saving->file, plr->ai_common.traits[tr].val,
- "player%d.trait.val%d", plrno, j);
+ "player%d.trait%d.val", plrno, j);
   secfile_insert_int(saving->file, plr->ai_common.traits[tr].mod,
- "player%d.trait.mod%d", plrno, j);
+ "player%d.trait%d.mod", plrno, j);
 }
   }
 


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


[Freeciv-commits] r28860 - in /branches/S2_6/server: savecompat.c savegame2.c

2015-04-24 Thread cazfi74
Author: cazfi
Date: Fri Apr 24 21:02:50 2015
New Revision: 28860

URL: http://svn.gna.org/viewcvs/freeciv?rev=28860&view=rev
Log:
Rearranged trait information save format so tabular format can be used.

See patch #6027

Modified:
branches/S2_6/server/savecompat.c
branches/S2_6/server/savegame2.c

Modified: branches/S2_6/server/savecompat.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/savecompat.c?rev=28860&r1=28859&r2=28860&view=diff
==
--- branches/S2_6/server/savecompat.c   (original)
+++ branches/S2_6/server/savecompat.c   Fri Apr 24 21:02:50 2015
@@ -757,6 +757,7 @@
 bool got_first_city;
 int old_barb_type;
 enum barbarian_type new_barb_type;
+int i;
 
 /* Renamed 'capital' to 'got_first_city'. */
 if (secfile_lookup_bool(loading->file, &got_first_city, 
@@ -771,6 +772,21 @@
 new_barb_type = barb_type_convert(old_barb_type);
 secfile_insert_str(loading->file, barbarian_type_name(new_barb_type),
"player%d.ai.barb_type", plrno);
+
+for (i = 0; i < loading->trait.size; i++) {
+  int val;
+
+  val = secfile_lookup_int_default(loading->file, -1, "pĺr%d.trait.val%d",
+   plrno, i);
+  if (val != -1) {
+secfile_insert_int(loading->file, val, "plr%d.trait%d.val", plrno, i);
+  }
+
+  if (secfile_lookup_int(loading->file, &val, "plr%d.trait.mod%d", plrno, 
i)) {
+log_sg("Trait mod: %s", secfile_error());
+  }
+  secfile_insert_int(loading->file, val, "plr%d.trait%d.mod", plrno, i);
+}
   }
 
   /* Units orders. */

Modified: branches/S2_6/server/savegame2.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/savegame2.c?rev=28860&r1=28859&r2=28860&view=diff
==
--- branches/S2_6/server/savegame2.c(original)
+++ branches/S2_6/server/savegame2.cFri Apr 24 21:02:50 2015
@@ -3898,7 +3898,7 @@
   enum trait tr = trait_by_name(loading->trait.order[i], fc_strcasecmp);
 
   if (trait_is_valid(tr)) {
-int val = secfile_lookup_int_default(loading->file, -1, 
"plr%d.trait.val%d",
+int val = secfile_lookup_int_default(loading->file, -1, 
"plr%d.trait%d.val",
  plrno, i);
 
 if (val != -1) {
@@ -3906,7 +3906,7 @@
 }
 
 if (secfile_lookup_int(loading->file, &val,
-   "plr%d.trait.mod%d", plrno, i)) {
+   "plr%d.trait%d.mod", plrno, i)) {
   plr->ai_common.traits[tr].mod = val;
 }
   }
@@ -4179,9 +4179,9 @@
 
 for (tr = trait_begin(), j = 0; tr != trait_end(); tr = trait_next(tr), 
j++) {
   secfile_insert_int(saving->file, plr->ai_common.traits[tr].val,
- "player%d.trait.val%d", plrno, j);
+ "player%d.trait%d.val", plrno, j);
   secfile_insert_int(saving->file, plr->ai_common.traits[tr].mod,
- "player%d.trait.mod%d", plrno, j);
+ "player%d.trait%d.mod", plrno, j);
 }
   }
 


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


[Freeciv-commits] r28861 - in /trunk: data/multiplayer/game.ruleset doc/README.ruleset_multiplayer

2015-04-24 Thread cazfi74
Author: cazfi
Date: Fri Apr 24 21:08:46 2015
New Revision: 28861

URL: http://svn.gna.org/viewcvs/freeciv?rev=28861&view=rev
Log:
Enabled tired_attack rules in multiplayer ruleset.

Requested by pepeto 

See bug #22395

Modified:
trunk/data/multiplayer/game.ruleset
trunk/doc/README.ruleset_multiplayer

Modified: trunk/data/multiplayer/game.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/data/multiplayer/game.ruleset?rev=28861&r1=28860&r2=28861&view=diff
==
--- trunk/data/multiplayer/game.ruleset (original)
+++ trunk/data/multiplayer/game.ruleset Fri Apr 24 21:08:46 2015
@@ -174,7 +174,7 @@
 ; 2/3 move points will have attack power 2/3 of normal.
 ; If this is set to FALSE units will attack with full strength even if they
 ; have only fractional moves left.
-tired_attack = FALSE
+tired_attack = TRUE
 
 [actions]
 ; What each action should be called when showing them to the player.

Modified: trunk/doc/README.ruleset_multiplayer
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/doc/README.ruleset_multiplayer?rev=28861&r1=28860&r2=28861&view=diff
==
--- trunk/doc/README.ruleset_multiplayer(original)
+++ trunk/doc/README.ruleset_multiplayerFri Apr 24 21:08:46 2015
@@ -24,6 +24,12 @@
 
 The cost of inciting a city to change hands has been greatly
 increased.
+
+Units attacking with less than a full movement point get penalized because
+of their tiredness. Only the fragment of their normal attack strength
+equivalent to their movement point fragment is considered. If they have 2/3
+movement points, they will attack with 2/3 strength. If they have 1/3 movement
+points, they will attack with 1/3 strength.
 
 Wonder changes
 --


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


[Freeciv-commits] r28862 - in /branches/S2_6: data/multiplayer/game.ruleset doc/README.ruleset_multiplayer

2015-04-24 Thread cazfi74
Author: cazfi
Date: Fri Apr 24 21:08:55 2015
New Revision: 28862

URL: http://svn.gna.org/viewcvs/freeciv?rev=28862&view=rev
Log:
Enabled tired_attack rules in multiplayer ruleset.

Requested by pepeto 

See bug #22395

Modified:
branches/S2_6/data/multiplayer/game.ruleset
branches/S2_6/doc/README.ruleset_multiplayer

Modified: branches/S2_6/data/multiplayer/game.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/data/multiplayer/game.ruleset?rev=28862&r1=28861&r2=28862&view=diff
==
--- branches/S2_6/data/multiplayer/game.ruleset (original)
+++ branches/S2_6/data/multiplayer/game.ruleset Fri Apr 24 21:08:55 2015
@@ -173,7 +173,7 @@
 ; 2/3 move points will have attack power 2/3 of normal.
 ; If this is set to FALSE units will attack with full strength even if they
 ; have only fractional moves left.
-tired_attack = FALSE
+tired_attack = TRUE
 
 [actions]
 ; What each action should be called when showing them to the player.

Modified: branches/S2_6/doc/README.ruleset_multiplayer
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/doc/README.ruleset_multiplayer?rev=28862&r1=28861&r2=28862&view=diff
==
--- branches/S2_6/doc/README.ruleset_multiplayer(original)
+++ branches/S2_6/doc/README.ruleset_multiplayerFri Apr 24 21:08:55 2015
@@ -24,6 +24,12 @@
 
 The cost of inciting a city to change hands has been greatly
 increased.
+
+Units attacking with less than a full movement point get penalized because
+of their tiredness. Only the fragment of their normal attack strength
+equivalent to their movement point fragment is considered. If they have 2/3
+movement points, they will attack with 2/3 strength. If they have 1/3 movement
+points, they will attack with 1/3 strength.
 
 Wonder changes
 --


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


[Freeciv-commits] r28864 - in /branches/S2_6/server: generator/utilities.c generator/utilities.h srv_main.c

2015-04-24 Thread cazfi74
Author: cazfi
Date: Fri Apr 24 21:38:03 2015
New Revision: 28864

URL: http://svn.gna.org/viewcvs/freeciv?rev=28864&view=rev
Log:
Free memory allocated by map generator on exit.

See patch #6030

Modified:
branches/S2_6/server/generator/utilities.c
branches/S2_6/server/generator/utilities.h
branches/S2_6/server/srv_main.c

Modified: branches/S2_6/server/generator/utilities.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/generator/utilities.c?rev=28864&r1=28863&r2=28864&view=diff
==
--- branches/S2_6/server/generator/utilities.c  (original)
+++ branches/S2_6/server/generator/utilities.c  Fri Apr 24 21:38:03 2015
@@ -239,9 +239,9 @@
  * The _sizes arrays give the sizes (in tiles) of each continent and
  * ocean.
  */
-static Continent_id *lake_surrounders;
-static int *continent_sizes, *ocean_sizes;
-
+static Continent_id *lake_surrounders = NULL;
+static int *continent_sizes = NULL;
+static int *ocean_sizes = NULL;
 
 /**
   Calculate lake_surrounders[] array
@@ -252,7 +252,7 @@
 
   lake_surrounders = fc_realloc(lake_surrounders, size);
   memset(lake_surrounders, 0, size);
-  
+
   whole_map_iterate(ptile) {
 const struct terrain *pterrain = tile_terrain(ptile);
 Continent_id cont = tile_continent(ptile);
@@ -602,3 +602,22 @@
 }
   } whole_map_iterate_end;
 }
+
+/**
+  Free resources allocated by the generator.
+**/
+void generator_free(void)
+{
+  if (lake_surrounders != NULL) {
+free(lake_surrounders);
+lake_surrounders = NULL;
+  }
+  if (continent_sizes != NULL) {
+free(continent_sizes);
+continent_sizes = NULL;
+  }
+  if (ocean_sizes != NULL) {
+free(ocean_sizes);
+ocean_sizes = NULL;
+  }
+}

Modified: branches/S2_6/server/generator/utilities.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/generator/utilities.h?rev=28864&r1=28863&r2=28864&view=diff
==
--- branches/S2_6/server/generator/utilities.h  (original)
+++ branches/S2_6/server/generator/utilities.h  Fri Apr 24 21:38:03 2015
@@ -14,6 +14,8 @@
 #define FC__UTILITIES_H
 
 typedef void (*tile_knowledge_cb)(struct tile *ptile);
+
+void generator_free(void);
 
 void regenerate_lakes(tile_knowledge_cb knowledge_cb);
 void smooth_water_depth(void);

Modified: branches/S2_6/server/srv_main.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/srv_main.c?rev=28864&r1=28863&r2=28864&view=diff
==
--- branches/S2_6/server/srv_main.c (original)
+++ branches/S2_6/server/srv_main.c Fri Apr 24 21:38:03 2015
@@ -85,6 +85,7 @@
 
 /* server/generator */
 #include "mapgen.h"
+#include "utilities.h"
 
 /* server/scripting */
 #include "script_server.h"
@@ -1549,6 +1550,7 @@
   stdinhand_free();
   edithand_free();
   voting_free();
+  generator_free();
   close_connections_and_socket();
   rulesets_deinit();
   timing_log_free();


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


[Freeciv-commits] r28865 - in /branches/S2_5/server: generator/utilities.c generator/utilities.h srv_main.c

2015-04-24 Thread cazfi74
Author: cazfi
Date: Fri Apr 24 21:38:17 2015
New Revision: 28865

URL: http://svn.gna.org/viewcvs/freeciv?rev=28865&view=rev
Log:
Free memory allocated by map generator on exit.

See patch #6030

Modified:
branches/S2_5/server/generator/utilities.c
branches/S2_5/server/generator/utilities.h
branches/S2_5/server/srv_main.c

Modified: branches/S2_5/server/generator/utilities.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/server/generator/utilities.c?rev=28865&r1=28864&r2=28865&view=diff
==
--- branches/S2_5/server/generator/utilities.c  (original)
+++ branches/S2_5/server/generator/utilities.c  Fri Apr 24 21:38:17 2015
@@ -239,9 +239,9 @@
  * The _sizes arrays give the sizes (in tiles) of each continent and
  * ocean.
  */
-static Continent_id *lake_surrounders;
-static int *continent_sizes, *ocean_sizes;
-
+static Continent_id *lake_surrounders = NULL;
+static int *continent_sizes = NULL;
+static int *ocean_sizes = NULL;
 
 /**
   Calculate lake_surrounders[] array
@@ -252,7 +252,7 @@
 
   lake_surrounders = fc_realloc(lake_surrounders, size);
   memset(lake_surrounders, 0, size);
-  
+
   whole_map_iterate(ptile) {
 const struct terrain *pterrain = tile_terrain(ptile);
 Continent_id cont = tile_continent(ptile);
@@ -602,3 +602,22 @@
 }
   } whole_map_iterate_end;
 }
+
+/**
+  Free resources allocated by the generator.
+**/
+void generator_free(void)
+{
+  if (lake_surrounders != NULL) {
+free(lake_surrounders);
+lake_surrounders = NULL;
+  }
+  if (continent_sizes != NULL) {
+free(continent_sizes);
+continent_sizes = NULL;
+  }
+  if (ocean_sizes != NULL) {
+free(ocean_sizes);
+ocean_sizes = NULL;
+  }
+}

Modified: branches/S2_5/server/generator/utilities.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/server/generator/utilities.h?rev=28865&r1=28864&r2=28865&view=diff
==
--- branches/S2_5/server/generator/utilities.h  (original)
+++ branches/S2_5/server/generator/utilities.h  Fri Apr 24 21:38:17 2015
@@ -14,6 +14,8 @@
 #define FC__UTILITIES_H
 
 typedef void (*tile_knowledge_cb)(struct tile *ptile);
+
+void generator_free(void);
 
 void regenerate_lakes(tile_knowledge_cb knowledge_cb);
 void smooth_water_depth(void);

Modified: branches/S2_5/server/srv_main.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/server/srv_main.c?rev=28865&r1=28864&r2=28865&view=diff
==
--- branches/S2_5/server/srv_main.c (original)
+++ branches/S2_5/server/srv_main.c Fri Apr 24 21:38:17 2015
@@ -82,6 +82,7 @@
 
 /* generator */
 #include "mapgen.h"
+#include "utilities.h"
 
 /* server/scripting */
 #include "script_server.h"
@@ -1418,6 +1419,7 @@
   stdinhand_free();
   edithand_free();
   voting_free();
+  generator_free();
   close_connections_and_socket();
   rulesets_deinit();
   timing_log_free();


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


[Freeciv-commits] r28863 - in /trunk/server: generator/utilities.c generator/utilities.h srv_main.c

2015-04-24 Thread cazfi74
Author: cazfi
Date: Fri Apr 24 21:37:56 2015
New Revision: 28863

URL: http://svn.gna.org/viewcvs/freeciv?rev=28863&view=rev
Log:
Free memory allocated by map generator on exit.

See patch #6030

Modified:
trunk/server/generator/utilities.c
trunk/server/generator/utilities.h
trunk/server/srv_main.c

Modified: trunk/server/generator/utilities.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/generator/utilities.c?rev=28863&r1=28862&r2=28863&view=diff
==
--- trunk/server/generator/utilities.c  (original)
+++ trunk/server/generator/utilities.c  Fri Apr 24 21:37:56 2015
@@ -239,9 +239,9 @@
  * The _sizes arrays give the sizes (in tiles) of each continent and
  * ocean.
  */
-static Continent_id *lake_surrounders;
-static int *continent_sizes, *ocean_sizes;
-
+static Continent_id *lake_surrounders = NULL;
+static int *continent_sizes = NULL;
+static int *ocean_sizes = NULL;
 
 /**
   Calculate lake_surrounders[] array
@@ -252,7 +252,7 @@
 
   lake_surrounders = fc_realloc(lake_surrounders, size);
   memset(lake_surrounders, 0, size);
-  
+
   whole_map_iterate(ptile) {
 const struct terrain *pterrain = tile_terrain(ptile);
 Continent_id cont = tile_continent(ptile);
@@ -602,3 +602,22 @@
 }
   } whole_map_iterate_end;
 }
+
+/**
+  Free resources allocated by the generator.
+**/
+void generator_free(void)
+{
+  if (lake_surrounders != NULL) {
+free(lake_surrounders);
+lake_surrounders = NULL;
+  }
+  if (continent_sizes != NULL) {
+free(continent_sizes);
+continent_sizes = NULL;
+  }
+  if (ocean_sizes != NULL) {
+free(ocean_sizes);
+ocean_sizes = NULL;
+  }
+}

Modified: trunk/server/generator/utilities.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/generator/utilities.h?rev=28863&r1=28862&r2=28863&view=diff
==
--- trunk/server/generator/utilities.h  (original)
+++ trunk/server/generator/utilities.h  Fri Apr 24 21:37:56 2015
@@ -14,6 +14,8 @@
 #define FC__UTILITIES_H
 
 typedef void (*tile_knowledge_cb)(struct tile *ptile);
+
+void generator_free(void);
 
 void regenerate_lakes(tile_knowledge_cb knowledge_cb);
 void smooth_water_depth(void);

Modified: trunk/server/srv_main.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/srv_main.c?rev=28863&r1=28862&r2=28863&view=diff
==
--- trunk/server/srv_main.c (original)
+++ trunk/server/srv_main.c Fri Apr 24 21:37:56 2015
@@ -85,6 +85,7 @@
 
 /* server/generator */
 #include "mapgen.h"
+#include "utilities.h"
 
 /* server/scripting */
 #include "script_server.h"
@@ -1583,6 +1584,7 @@
   stdinhand_free();
   edithand_free();
   voting_free();
+  generator_free();
   close_connections_and_socket();
   rulesets_deinit();
   timing_log_free();


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