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

Hi,

This feature may have been in the editor previously but is probably commented 
out now, so I tried to implement it the "proper way". With this patch you can 
let cities build items like improvements and units while in editor mode by 
clicking on the "buy" button of the general cityreport dialog (Hotkey "F4" in 
the GTK GUI, where you get a list of all cities of one player). This will 
cost nothing for the player owning the city and the improvements/units will 
be immediately added to the given city without having to wait one turn like 
in the usual context of this button. This feature should work with any 
clients supporting the Editor mode however, it won't affect the "buy" button 
you get in the normal city dialog when double clicking on a city (either on 
the map or in the general cityreport). That's what I'm currently looking 
after to change, but it looks like this button and it's callback is 
implemented GUI specific, but that is just guessing of mine.

As you may have thought I'm completely new to this project and am just mostly 
busy trying to learn to look through the existing code and guessing how I 
could work with it. So any further contributions may take some time. ;)

Greetings
Nico

diff -Nur -Xdiff_ignore trunk/client/climisc.c changed/client/climisc.c
--- trunk/client/climisc.c	2008-07-05 19:58:11.000000000 +0200
+++ changed/client/climisc.c	2008-07-13 22:47:33.000000000 +0200
@@ -1023,25 +1023,36 @@
 **************************************************************************/
 void cityrep_buy(struct city *pcity)
 {
-  int value;
-
-  if (city_production_has_flag(pcity, IF_GOLD)) {
-    create_event(pcity->tile, E_BAD_COMMAND,
-		_("You don't buy %s in %s!"),
-		improvement_name_translation(pcity->production.value.building),
-		city_name(pcity));
-    return;
-  }
-  value = city_production_buy_gold_cost(pcity);
-
-  if (city_owner(pcity)->economic.gold >= value) {
-    city_buy_production(pcity);
+  if (!can_conn_edit(&client.conn)) {
+    int value;
+    
+    if (city_production_has_flag(pcity, IF_GOLD)) {
+      create_event(pcity->tile, E_BAD_COMMAND,
+                   _("You don't buy %s in %s!"),
+                   improvement_name_translation(
+                                           pcity->production.value.building),
+                   city_name(pcity));
+      return;
+    }
+    value = city_production_buy_gold_cost(pcity);
+  
+    if (city_owner(pcity)->economic.gold >= value) {
+      city_buy_production(pcity);
+    } else {
+      create_event(NULL, E_BAD_COMMAND,
+                   _("%s costs %d gold and you only have %d gold."),
+                     city_production_name_translation(pcity),
+                         value,
+                         city_owner(pcity)->economic.gold);
+    }
   } else {
-    create_event(NULL, E_BAD_COMMAND,
-		 _("%s costs %d gold and you only have %d gold."),
-		 city_production_name_translation(pcity),
-		 value,
-		 city_owner(pcity)->economic.gold);
+    /* Editor mode can build without any cost or waiting for next turn */
+    if (client.conn.playing != NULL) {
+      /* Not a global observer */
+      dsend_packet_edit_city_build(&client.conn, 
+                                   player_number(client.conn.playing),
+                                   pcity->id);
+    }
   }
 }
 
diff -Nur -Xdiff_ignore trunk/common/packets.def changed/common/packets.def
--- trunk/common/packets.def	2008-07-11 21:46:56.000000000 +0200
+++ changed/common/packets.def	2008-07-13 22:32:38.000000000 +0200
@@ -1551,10 +1551,15 @@
   UINT8 size;
 end
 
+PACKET_EDIT_CITY_BUILD=168;cs,handle-per-conn,dsend
+  PLAYER playerno;
+  CITY cityID;
+end
+
 /* Always keep this as the last edit type packet,
  * so that the test in server/srv_main.c +1203
  * is easy to write. */
-PACKET_EDIT_PLAYER_TECH=168;cs,handle-per-conn,dsend
+PACKET_EDIT_PLAYER_TECH=169;cs,handle-per-conn,dsend
   PLAYER          playerno;
   TECH            tech;
   EDIT_TECH_MODE  mode;
diff -Nur -Xdiff_ignore trunk/server/edithand.c changed/server/edithand.c
--- trunk/server/edithand.c	2008-07-05 19:56:36.000000000 +0200
+++ changed/server/edithand.c	2008-07-13 22:42:53.000000000 +0200
@@ -627,6 +627,43 @@
 #endif
 
 /****************************************************************************
+  Build the item currently in production of a given city immediately
+****************************************************************************/
+void handle_edit_city_build(struct connection *pc, int playerno, int cityID)
+{
+  if (!can_conn_edit(pc)) {
+    notify_conn(pc->self, NULL, E_BAD_COMMAND,
+                _("You are not allowed to edit."));
+    return;
+  }
+  struct city *pcity = game_find_city_by_number(cityID);
+  struct player *pplayer = player_by_number(playerno);
+  if (city_production_has_flag(pcity, IF_GOLD)) {
+    notify_conn(pc->self, pcity->tile, E_CITY_CANTBUILD, 
+                  _("Cannot \"build\" coinage in %s"), city_name(pcity));
+    return;
+  } else if (pcity->production.kind == VUT_IMPROVEMENT) {
+    /* 2DO: Checks for Wonders not being built multiple times */
+    struct impr_type *pimprove = pcity->production.value.building;
+    city_add_improvement(pcity, pimprove);
+  } else if (pcity->production.kind == VUT_UTYPE) {
+    struct unit_type *utype = pcity->production.value.utype;
+    int veteran = do_make_unit_veteran(pcity, utype);
+    int moves = utype->move_rate;
+    create_unit(pplayer, pcity->tile, utype, veteran, pcity->id, moves);
+  } else {
+    /* shouldn't be happening */
+    assert(0);
+    return;
+  }
+  /* 2DO: Pick next item of worklist for production, choose_build_target
+   * from /server/cityturn.c would do the trick but can't be called here */ 
+  advisor_choose_build(pplayer, pcity); /* Chooses anything but units */
+  city_refresh(pcity);
+  send_city_info(NULL, pcity);
+}
+
+/****************************************************************************
   Allows the editor to change city size directly.
 ****************************************************************************/
 void handle_edit_city_size(struct connection *pc,
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to