[Freeciv-commits] r29076 - in /branches/S2_6/common: unittype.c unittype.h

2015-05-13 Thread sveinung84
Author: sveinung
Date: Wed May 13 15:38:42 2015
New Revision: 29076

URL: http://svn.gna.org/viewcvs/freeciv?rev=29076&view=rev
Log:
Add moves left can unit type act test

Add the function utype_may_act_move_frags() to make it easy to test if a
unit of the specified type can perform an action when it has a certain
amount of move fragments left.

See patch #6083

Modified:
branches/S2_6/common/unittype.c
branches/S2_6/common/unittype.h

Modified: branches/S2_6/common/unittype.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/unittype.c?rev=29076&r1=29075&r2=29076&view=diff
==
--- branches/S2_6/common/unittype.c (original)
+++ branches/S2_6/common/unittype.c Wed May 13 15:38:42 2015
@@ -482,6 +482,37 @@
   }
 }
 
+struct range {
+  int min;
+  int max;
+};
+
+#define MOVES_LEFT_INFINITY -1
+
+/**
+  Get the legal range of move fragments left of the specified requirement
+  vector.
+**/
+static struct range *moves_left_range(struct requirement_vector *reqs)
+{
+  struct range *prange = fc_malloc(sizeof(prange));
+
+  prange->min = 0;
+  prange->max = MOVES_LEFT_INFINITY;
+
+  requirement_vector_iterate(reqs, preq) {
+if (preq->source.kind == VUT_MINMOVES) {
+  if (preq->present) {
+prange->min = preq->source.value.minmoves;
+  } else {
+prange->max = preq->source.value.minmoves;
+  }
+}
+  } requirement_vector_iterate_end;
+
+  return prange;
+}
+
 /**
   Cache if any action may be possible for a unit of the type putype given
   the property tested for. Since a it could be ignored both present and
@@ -549,6 +580,52 @@
 
   return BV_ISSET(dipl_rel_action_cache[utype_id][action_id],
   requirement_diplrel_ereq(prop, REQ_RANGE_LOCAL, is_there));
+}
+
+/**
+  Return TRUE iff the given (action enabler controlled) action may be
+  performed by a unit of the given type that has the given number of move
+  fragments left.
+
+  Note: Values aren't cached. If a performance critical user appears it
+  would be a good idea to cache the (merged) ranges of move fragments
+  where a unit of the given type can perform the specified action.
+**/
+bool utype_may_act_move_frags(struct unit_type *punit_type,
+  const int action_id,
+  const int move_fragments)
+{
+  struct range *ml_range;
+
+  if (action_get_actor_kind(action_id) != AAK_UNIT) {
+/* This action isn't performed by any unit at all so this unit type
+ * can't do it. */
+return FALSE;
+  }
+
+  action_enabler_list_iterate(action_enablers_for_action(action_id),
+  enabler) {
+if (!requirement_fulfilled_by_unit_type(punit_type,
+&(enabler->actor_reqs))) {
+  /* This action can't be performed by this unit type at all. */
+  continue;
+}
+
+ml_range = moves_left_range(&(enabler->actor_reqs));
+if (ml_range->min <= move_fragments
+&& (ml_range->max == MOVES_LEFT_INFINITY
+|| ml_range->max > move_fragments)) {
+  /* The number of move fragments is in range of the action enabler. */
+
+  free(ml_range);
+
+  return TRUE;
+}
+
+free(ml_range);
+  } action_enabler_list_iterate_end;
+
+  return FALSE;
 }
 
 /

Modified: branches/S2_6/common/unittype.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/unittype.h?rev=29076&r1=29075&r2=29076&view=diff
==
--- branches/S2_6/common/unittype.h (original)
+++ branches/S2_6/common/unittype.h Wed May 13 15:38:42 2015
@@ -545,6 +545,10 @@
  const int prop,
  const bool is_there);
 
+bool utype_may_act_move_frags(struct unit_type *punit_type,
+  const int action_id,
+  const int move_fragments);
+
 /* Functions to operate on various flag and roles. */
 typedef bool (*role_unit_callback)(struct unit_type *ptype, void *data);
 


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


[Freeciv-commits] r29077 - in /trunk/common: unittype.c unittype.h

2015-05-13 Thread sveinung84
Author: sveinung
Date: Wed May 13 15:39:08 2015
New Revision: 29077

URL: http://svn.gna.org/viewcvs/freeciv?rev=29077&view=rev
Log:
Add moves left can unit type act test

Add the function utype_may_act_move_frags() to make it easy to test if a
unit of the specified type can perform an action when it has a certain
amount of move fragments left.

See patch #6083

Modified:
trunk/common/unittype.c
trunk/common/unittype.h

Modified: trunk/common/unittype.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/unittype.c?rev=29077&r1=29076&r2=29077&view=diff
==
--- trunk/common/unittype.c (original)
+++ trunk/common/unittype.c Wed May 13 15:39:08 2015
@@ -492,6 +492,37 @@
   }
 }
 
+struct range {
+  int min;
+  int max;
+};
+
+#define MOVES_LEFT_INFINITY -1
+
+/**
+  Get the legal range of move fragments left of the specified requirement
+  vector.
+**/
+static struct range *moves_left_range(struct requirement_vector *reqs)
+{
+  struct range *prange = fc_malloc(sizeof(prange));
+
+  prange->min = 0;
+  prange->max = MOVES_LEFT_INFINITY;
+
+  requirement_vector_iterate(reqs, preq) {
+if (preq->source.kind == VUT_MINMOVES) {
+  if (preq->present) {
+prange->min = preq->source.value.minmoves;
+  } else {
+prange->max = preq->source.value.minmoves;
+  }
+}
+  } requirement_vector_iterate_end;
+
+  return prange;
+}
+
 /**
   Cache if any action may be possible for a unit of the type putype given
   the property tested for. Since a it could be ignored both present and
@@ -559,6 +590,52 @@
 
   return BV_ISSET(dipl_rel_action_cache[utype_id][action_id],
   requirement_diplrel_ereq(prop, REQ_RANGE_LOCAL, is_there));
+}
+
+/**
+  Return TRUE iff the given (action enabler controlled) action may be
+  performed by a unit of the given type that has the given number of move
+  fragments left.
+
+  Note: Values aren't cached. If a performance critical user appears it
+  would be a good idea to cache the (merged) ranges of move fragments
+  where a unit of the given type can perform the specified action.
+**/
+bool utype_may_act_move_frags(struct unit_type *punit_type,
+  const int action_id,
+  const int move_fragments)
+{
+  struct range *ml_range;
+
+  if (action_get_actor_kind(action_id) != AAK_UNIT) {
+/* This action isn't performed by any unit at all so this unit type
+ * can't do it. */
+return FALSE;
+  }
+
+  action_enabler_list_iterate(action_enablers_for_action(action_id),
+  enabler) {
+if (!requirement_fulfilled_by_unit_type(punit_type,
+&(enabler->actor_reqs))) {
+  /* This action can't be performed by this unit type at all. */
+  continue;
+}
+
+ml_range = moves_left_range(&(enabler->actor_reqs));
+if (ml_range->min <= move_fragments
+&& (ml_range->max == MOVES_LEFT_INFINITY
+|| ml_range->max > move_fragments)) {
+  /* The number of move fragments is in range of the action enabler. */
+
+  free(ml_range);
+
+  return TRUE;
+}
+
+free(ml_range);
+  } action_enabler_list_iterate_end;
+
+  return FALSE;
 }
 
 /

Modified: trunk/common/unittype.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/unittype.h?rev=29077&r1=29076&r2=29077&view=diff
==
--- trunk/common/unittype.h (original)
+++ trunk/common/unittype.h Wed May 13 15:39:08 2015
@@ -538,6 +538,10 @@
  const int prop,
  const bool is_there);
 
+bool utype_may_act_move_frags(struct unit_type *punit_type,
+  const int action_id,
+  const int move_fragments);
+
 /* Functions to operate on various flag and roles. */
 typedef bool (*role_unit_callback)(struct unit_type *ptype, void *data);
 


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


[Freeciv-commits] r29078 - in /trunk: ./ common/ data/alien/ data/civ1/ data/civ2/ data/civ2civ3/ data/classic/ data/experimental/ data/multip...

2015-05-13 Thread sveinung84
Author: sveinung
Date: Wed May 13 15:39:17 2015
New Revision: 29078

URL: http://svn.gna.org/viewcvs/freeciv?rev=29078&view=rev
Log:
Unhardcode the rule that a unit must have moves left to join a city.

See patch #6084

Modified:
trunk/common/unit.c
trunk/data/alien/game.ruleset
trunk/data/civ1/game.ruleset
trunk/data/civ2/game.ruleset
trunk/data/civ2civ3/game.ruleset
trunk/data/classic/game.ruleset
trunk/data/experimental/game.ruleset
trunk/data/multiplayer/game.ruleset
trunk/doc/README.actions
trunk/fc_version
trunk/server/rscompat.c

Modified: trunk/common/unit.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/unit.c?rev=29078&r1=29077&r2=29078&view=diff
==
--- trunk/common/unit.c (original)
+++ trunk/common/unit.c Wed May 13 15:39:17 2015
@@ -418,7 +418,12 @@
   if (!is_add) {
 return UAB_NOT_ADDABLE_UNIT;
   }
-  if (punit->moves_left == 0) {
+  if (punit->moves_left == 0
+  /* TODO: Remove UAB_NO_MOVES_ADD when doing so is safe. */
+  /* The ruleset may allow joining cities when out of move
+   * fragments. */
+  && !utype_may_act_move_frags(unit_type(punit),
+   ACTION_JOIN_CITY, 0)) {
 return UAB_NO_MOVES_ADD;
   }
 

Modified: trunk/data/alien/game.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/data/alien/game.ruleset?rev=29078&r1=29077&r2=29078&view=diff
==
--- trunk/data/alien/game.ruleset   (original)
+++ trunk/data/alien/game.ruleset   Wed May 13 15:39:17 2015
@@ -338,6 +338,7 @@
 { "type",   "name", "range", "present"
   "Unitflag", "AddToCity", "Local", TRUE
   "DiplRel", "Is foreign", "Local", FALSE
+  "MinMoveFrags", "1", "Local", TRUE
 }
 
 [borders]

Modified: trunk/data/civ1/game.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/data/civ1/game.ruleset?rev=29078&r1=29077&r2=29078&view=diff
==
--- trunk/data/civ1/game.ruleset(original)
+++ trunk/data/civ1/game.rulesetWed May 13 15:39:17 2015
@@ -324,6 +324,7 @@
 { "type",   "name", "range", "present"
   "Unitflag", "AddToCity", "Local", TRUE
   "DiplRel", "Is foreign", "Local", FALSE
+  "MinMoveFrags", "1", "Local", TRUE
 }
 
 [borders]

Modified: trunk/data/civ2/game.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/data/civ2/game.ruleset?rev=29078&r1=29077&r2=29078&view=diff
==
--- trunk/data/civ2/game.ruleset(original)
+++ trunk/data/civ2/game.rulesetWed May 13 15:39:17 2015
@@ -376,6 +376,7 @@
 { "type",   "name", "range", "present"
   "Unitflag", "AddToCity", "Local", TRUE
   "DiplRel", "Is foreign", "Local", FALSE
+  "MinMoveFrags", "1", "Local", TRUE
 }
 
 [borders]

Modified: trunk/data/civ2civ3/game.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/data/civ2civ3/game.ruleset?rev=29078&r1=29077&r2=29078&view=diff
==
--- trunk/data/civ2civ3/game.ruleset(original)
+++ trunk/data/civ2civ3/game.rulesetWed May 13 15:39:17 2015
@@ -435,6 +435,7 @@
 { "type",   "name", "range", "present"
   "Unitflag", "AddToCity", "Local", TRUE
   "DiplRel", "Is foreign", "Local", FALSE
+  "MinMoveFrags", "1", "Local", TRUE
 }
 
 [borders]

Modified: trunk/data/classic/game.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/data/classic/game.ruleset?rev=29078&r1=29077&r2=29078&view=diff
==
--- trunk/data/classic/game.ruleset (original)
+++ trunk/data/classic/game.ruleset Wed May 13 15:39:17 2015
@@ -407,6 +407,7 @@
 { "type",   "name", "range", "present"
   "Unitflag", "AddToCity", "Local", TRUE
   "DiplRel", "Is foreign", "Local", FALSE
+  "MinMoveFrags", "1", "Local", TRUE
 }
 
 [borders]

Modified: trunk/data/experimental/game.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/data/experimental/game.ruleset?rev=29078&r1=29077&r2=29078&view=diff
==
--- trunk/data/experimental/game.ruleset(original)
+++ trunk/data/experimental/game.rulesetWed May 13 15:39:17 2015
@@ -425,6 +425,7 @@
 { "type",   "name", "range", "present"
   "Unitflag", "AddToCity", "Local", TRUE
   "DiplRel", "Is foreign", "Local", FALSE
+  "MinMoveFrags", "1", "Local", TRUE
 }
 
 [borders]

Modified: trunk/data/multiplayer/game.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/data/multiplayer/game.ruleset?rev=29078&r1=29077&r2=29078&view=diff
==
--- trunk/dat

[Freeciv-commits] r29079 - in /trunk: ./ common/ data/alien/ data/civ1/ data/civ2/ data/civ2civ3/ data/classic/ data/experimental/ data/multip...

2015-05-13 Thread sveinung84
Author: sveinung
Date: Wed May 13 15:39:26 2015
New Revision: 29079

URL: http://svn.gna.org/viewcvs/freeciv?rev=29079&view=rev
Log:
Unhardcode the rule that a unit must have moves left to found a city.

See patch #6085

Modified:
trunk/common/unit.c
trunk/data/alien/game.ruleset
trunk/data/civ1/game.ruleset
trunk/data/civ2/game.ruleset
trunk/data/civ2civ3/game.ruleset
trunk/data/classic/game.ruleset
trunk/data/experimental/game.ruleset
trunk/data/multiplayer/game.ruleset
trunk/doc/README.actions
trunk/fc_version
trunk/server/rscompat.c

Modified: trunk/common/unit.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/unit.c?rev=29079&r1=29078&r2=29079&view=diff
==
--- trunk/common/unit.c (original)
+++ trunk/common/unit.c Wed May 13 15:39:26 2015
@@ -395,7 +395,12 @@
 if (!is_build) {
   return UAB_NOT_BUILD_UNIT;
 }
-if (punit->moves_left == 0) {
+if (punit->moves_left == 0
+/* TODO: Remove UAB_NO_MOVES_BUILD when doing so is safe. */
+/* The ruleset may allow founding cities when out of move
+ * fragments. */
+&& !utype_may_act_move_frags(unit_type(punit),
+ ACTION_FOUND_CITY, 0)) {
   return UAB_NO_MOVES_BUILD;
 }
 switch (city_build_here_test(ptile, punit)) {

Modified: trunk/data/alien/game.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/data/alien/game.ruleset?rev=29079&r1=29078&r2=29079&view=diff
==
--- trunk/data/alien/game.ruleset   (original)
+++ trunk/data/alien/game.ruleset   Wed May 13 15:39:26 2015
@@ -330,6 +330,7 @@
 { "type",   "name", "range"
   "Unitflag", "Cities", "Local"
   "UnitState", "OnLivableTile", "Local"
+  "MinMoveFrags", "1", "Local", TRUE
 }
 
 [actionenabler_join_city]

Modified: trunk/data/civ1/game.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/data/civ1/game.ruleset?rev=29079&r1=29078&r2=29079&view=diff
==
--- trunk/data/civ1/game.ruleset(original)
+++ trunk/data/civ1/game.rulesetWed May 13 15:39:26 2015
@@ -316,6 +316,7 @@
 { "type",   "name", "range"
   "Unitflag", "Cities", "Local"
   "UnitState", "OnLivableTile", "Local"
+  "MinMoveFrags", "1", "Local", TRUE
 }
 
 [actionenabler_join_city]

Modified: trunk/data/civ2/game.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/data/civ2/game.ruleset?rev=29079&r1=29078&r2=29079&view=diff
==
--- trunk/data/civ2/game.ruleset(original)
+++ trunk/data/civ2/game.rulesetWed May 13 15:39:26 2015
@@ -368,6 +368,7 @@
 { "type",   "name", "range"
   "Unitflag", "Cities", "Local"
   "UnitState", "OnLivableTile", "Local"
+  "MinMoveFrags", "1", "Local", TRUE
 }
 
 [actionenabler_join_city]

Modified: trunk/data/civ2civ3/game.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/data/civ2civ3/game.ruleset?rev=29079&r1=29078&r2=29079&view=diff
==
--- trunk/data/civ2civ3/game.ruleset(original)
+++ trunk/data/civ2civ3/game.rulesetWed May 13 15:39:26 2015
@@ -427,6 +427,7 @@
 { "type",   "name", "range"
   "Unitflag", "Cities", "Local"
   "UnitState", "OnLivableTile", "Local"
+  "MinMoveFrags", "1", "Local", TRUE
 }
 
 [actionenabler_join_city]

Modified: trunk/data/classic/game.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/data/classic/game.ruleset?rev=29079&r1=29078&r2=29079&view=diff
==
--- trunk/data/classic/game.ruleset (original)
+++ trunk/data/classic/game.ruleset Wed May 13 15:39:26 2015
@@ -399,6 +399,7 @@
 { "type",   "name", "range"
   "Unitflag", "Cities", "Local"
   "UnitState", "OnLivableTile", "Local"
+  "MinMoveFrags", "1", "Local", TRUE
 }
 
 [actionenabler_join_city]

Modified: trunk/data/experimental/game.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/data/experimental/game.ruleset?rev=29079&r1=29078&r2=29079&view=diff
==
--- trunk/data/experimental/game.ruleset(original)
+++ trunk/data/experimental/game.rulesetWed May 13 15:39:26 2015
@@ -417,6 +417,7 @@
 { "type",   "name", "range"
   "Unitflag", "Cities", "Local"
   "UnitState", "OnLivableTile", "Local"
+  "MinMoveFrags", "1", "Local", TRUE
 }
 
 [actionenabler_join_city]

Modified: trunk/data/multiplayer/game.ruleset
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/data/multiplayer/game.ruleset?rev=29079&r1=29078&r2=29079&view=diff

[Freeciv-commits] r29080 - /trunk/client/gui-qt/citydlg.cpp

2015-05-13 Thread cazfi74
Author: cazfi
Date: Thu May 14 00:47:40 2015
New Revision: 29080

URL: http://svn.gna.org/viewcvs/freeciv?rev=29080&view=rev
Log:
Made Qt-client buy cost information pluralized.

See patch #5838

Modified:
trunk/client/gui-qt/citydlg.cpp

Modified: trunk/client/gui-qt/citydlg.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/citydlg.cpp?rev=29080&r1=29079&r2=29080&view=diff
==
--- trunk/client/gui-qt/citydlg.cpp (original)
+++ trunk/client/gui-qt/citydlg.cpp Thu May 14 00:47:40 2015
@@ -1587,7 +1587,7 @@
 
   if (!client_is_observer() && client.conn.playing != NULL) {
 value = city_production_buy_gold_cost(pcity);
-str = QString(_("Buy (%1 gold)")).arg(QString::number(value));
+str = QString(PL_("Buy (%1 gold)", "Buy (%1 gold)", 
value)).arg(QString::number(value));
 if (client.conn.playing->economic.gold >= value && value != 0) {
   buy_button->setEnabled(true);
   buy_button_p->setEnabled(true);


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


[Freeciv-commits] r29081 - /branches/S2_6/client/gui-qt/citydlg.cpp

2015-05-13 Thread cazfi74
Author: cazfi
Date: Thu May 14 00:47:48 2015
New Revision: 29081

URL: http://svn.gna.org/viewcvs/freeciv?rev=29081&view=rev
Log:
Made Qt-client buy cost information pluralized.

See patch #5838

Modified:
branches/S2_6/client/gui-qt/citydlg.cpp

Modified: branches/S2_6/client/gui-qt/citydlg.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-qt/citydlg.cpp?rev=29081&r1=29080&r2=29081&view=diff
==
--- branches/S2_6/client/gui-qt/citydlg.cpp (original)
+++ branches/S2_6/client/gui-qt/citydlg.cpp Thu May 14 00:47:48 2015
@@ -1587,7 +1587,7 @@
 
   if (!client_is_observer() && client.conn.playing != NULL) {
 value = city_production_buy_gold_cost(pcity);
-str = QString(_("Buy (%1 gold)")).arg(QString::number(value));
+str = QString(PL_("Buy (%1 gold)", "Buy (%1 gold)", 
value)).arg(QString::number(value));
 if (client.conn.playing->economic.gold >= value && value != 0) {
   buy_button->setEnabled(true);
   buy_button_p->setEnabled(true);


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


[Freeciv-commits] r29082 - /branches/S2_5/client/gui-qt/citydlg.cpp

2015-05-13 Thread cazfi74
Author: cazfi
Date: Thu May 14 00:47:58 2015
New Revision: 29082

URL: http://svn.gna.org/viewcvs/freeciv?rev=29082&view=rev
Log:
Made Qt-client buy cost information pluralized.

See patch #5838

Modified:
branches/S2_5/client/gui-qt/citydlg.cpp

Modified: branches/S2_5/client/gui-qt/citydlg.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/gui-qt/citydlg.cpp?rev=29082&r1=29081&r2=29082&view=diff
==
--- branches/S2_5/client/gui-qt/citydlg.cpp (original)
+++ branches/S2_5/client/gui-qt/citydlg.cpp Thu May 14 00:47:58 2015
@@ -1588,7 +1588,7 @@
 
   if (!client_is_observer() && client.conn.playing != NULL) {
 value = city_production_buy_gold_cost(pcity);
-str = QString(_("Buy (%1 gold)")).arg(QString::number(value));
+str = QString(PL_("Buy (%1 gold)", "Buy (%1 gold)", 
value)).arg(QString::number(value));
 if (client.conn.playing->economic.gold >= value && value != 0) {
   buy_button->setEnabled(true);
   buy_button_p->setEnabled(true);


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