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

Implements a property for modifying the amount of gold
in the player's treasury. Arbitrary maximum of 1000000. ;)


-----------------------------------------------------------------------
もう少しお金はどうですか。
 client/gui-gtk-2.0/editprop.c |   17 +++++++++++++++++
 server/edithand.c             |   14 ++++++++++++++
 2 files changed, 31 insertions(+), 0 deletions(-)

diff --git a/client/gui-gtk-2.0/editprop.c b/client/gui-gtk-2.0/editprop.c
index 8c0863c..1aa4a32 100644
--- a/client/gui-gtk-2.0/editprop.c
+++ b/client/gui-gtk-2.0/editprop.c
@@ -314,6 +314,7 @@ enum object_property_ids {
   OPID_PLAYER_NATION,
   OPID_PLAYER_ADDRESS,
   OPID_PLAYER_INVENTIONS,
+  OPID_PLAYER_GOLD,
 
   OPID_GAME_YEAR
 };
@@ -1543,6 +1544,9 @@ static struct propval *objbind_get_value_from_object(struct objbind *ob,
       } advance_index_iterate_end;
       pv->must_free = TRUE;
       break;
+    case OPID_PLAYER_GOLD:
+      pv->data.v_int = pplayer->economic.gold;
+      break;
     default:
       freelog(LOG_ERROR, "Unhandled request for value of property %d "
               "(%s) from object of type \"%s\" in "
@@ -1701,6 +1705,12 @@ static bool objbind_get_allowed_value_span(struct objbind *ob,
   } else if (objtype == OBJTYPE_PLAYER) {
 
     switch (propid) {
+    case OPID_PLAYER_GOLD:
+      min = 0;
+      max = 1000000; /* Arbitrary. */
+      step = 1;
+      big_step = 100;
+      break;
     default:
       freelog(LOG_ERROR, "Unhandled request for value range of "
               "property %d (%s) from object of type \"%s\" in "
@@ -2161,6 +2171,9 @@ static void objbind_pack_modified_value(struct objbind *ob,
         packet->inventions[tech] = pv->data.v_inventions[tech];
       } advance_index_iterate_end;
       break;
+    case OPID_PLAYER_GOLD:
+      packet->gold = pv->data.v_int;
+      break;
     default:
       freelog(LOG_ERROR, "Unhandled request to pack value of "
               "property %d (%s) from object of type \"%s\" in "
@@ -2549,6 +2562,7 @@ static void objprop_setup_widget(struct objprop *op)
 
   case OPID_CITY_SIZE:
   case OPID_CITY_SHIELD_STOCK:
+  case OPID_PLAYER_GOLD:
   case OPID_GAME_YEAR:
     spin = gtk_spin_button_new_with_range(0.0, 100.0, 1.0);
     g_signal_connect(spin, "value-changed",
@@ -2724,6 +2738,7 @@ static void objprop_refresh_widget(struct objprop *op,
 
   case OPID_CITY_SIZE:
   case OPID_CITY_SHIELD_STOCK:
+  case OPID_PLAYER_GOLD:
   case OPID_GAME_YEAR:
     spin = objprop_get_child_widget(op, "spin");
     if (pv) {
@@ -3669,6 +3684,8 @@ static void property_page_setup_objprops(struct property_page *pp)
             | OPF_HAS_WIDGET | OPF_EDITABLE, VALTYPE_NATION);
     ADDPROP(OPID_PLAYER_INVENTIONS, _("Inventions"), OPF_IN_LISTVIEW
             | OPF_HAS_WIDGET | OPF_EDITABLE, VALTYPE_INVENTIONS_ARRAY);
+    ADDPROP(OPID_PLAYER_GOLD, _("Gold"), OPF_IN_LISTVIEW
+            | OPF_HAS_WIDGET | OPF_EDITABLE, VALTYPE_INT);
     break;
 
   case OBJTYPE_GAME:
diff --git a/server/edithand.c b/server/edithand.c
index 46f0612..b80ec90 100644
--- a/server/edithand.c
+++ b/server/edithand.c
@@ -1012,6 +1012,20 @@ void handle_edit_player(struct connection *pc,
     update_research = TRUE;
   } advance_index_iterate_end;
   
+  /* Handle a change in the player's gold. */
+  if (packet->gold != pplayer->economic.gold) {
+    if (!(0 <= packet->gold && packet->gold <= 1000000)) {
+      notify_conn(pc->self, NULL, E_BAD_COMMAND,
+                  _("Cannot set gold for player %d (%s) because "
+                    "the value %d is outside the allowed range."),
+                  player_number(pplayer), player_name(pplayer),
+                  packet->gold);
+    } else {
+      pplayer->economic.gold = packet->gold;
+      changed = TRUE;
+    }
+  }
+
 
   /* TODO: Handle more property edits. */
 
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to