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

 This adds resource editing functionality to editor.


 - ML

diff -Nurd -X.diff_ignore freeciv/client/editor.c freeciv/client/editor.c
--- freeciv/client/editor.c	2007-02-26 14:16:19.000000000 +0200
+++ freeciv/client/editor.c	2007-03-02 00:47:57.000000000 +0200
@@ -36,6 +36,7 @@
 static enum editor_tool_type selected_tool = ETOOL_PAINT;
 static enum tile_special_type selected_special = S_LAST;
 static struct terrain *selected_terrain = NULL;
+static struct resource *selected_resource = NULL;
 static enum editor_paint_type selected_paint_type = EPAINT_LAST;
 static struct unit *selected_unit;
 static struct city *selected_city;
@@ -64,6 +65,7 @@
   selected_special = S_LAST;
   selected_paint_type = EPAINT_LAST;
   selected_terrain = NULL;
+  selected_resource = NULL;
 }
 
 /****************************************************************************
@@ -99,6 +101,14 @@
 }
 
 /****************************************************************************
+  Sets the selected editor resource.
+****************************************************************************/
+void editor_set_selected_resource(struct resource *presource)
+{
+  selected_resource = presource;
+}
+
+/****************************************************************************
   Returns the selected unit.
 ****************************************************************************/
 struct unit *editor_get_selected_unit(void)
@@ -215,6 +225,16 @@
       return CURSOR_INVALID;
     }
     break;
+  case EPAINT_RESOURCE:
+    /* Replace tile resource with new one */
+    if (selected_resource) {
+      tile_set_resource(&tile, selected_resource);
+    } else if (tile_get_resource(&tile)) {
+      tile_set_resource(&tile, NULL);
+    } else {
+      return CURSOR_INVALID;
+    }
+    break;
   case EPAINT_LAST:
   default:
     return CURSOR_INVALID;
diff -Nurd -X.diff_ignore freeciv/client/editor.h freeciv/client/editor.h
--- freeciv/client/editor.h	2007-02-26 14:16:19.000000000 +0200
+++ freeciv/client/editor.h	2007-03-02 00:42:42.000000000 +0200
@@ -26,8 +26,9 @@
 };
 
 enum editor_paint_type {
-  EPAINT_TERRAIN,
+  EPAINT_TERRAIN = 0,
   EPAINT_SPECIAL,
+  EPAINT_RESOURCE,
   EPAINT_LAST
 };
 
@@ -40,6 +41,7 @@
 void editor_set_selected_paint_type(enum editor_paint_type type);
 void editor_set_selected_terrain(struct terrain *pterrain);
 void editor_set_selected_special(enum tile_special_type special);
+void editor_set_selected_resource(struct resource *presource);
 
 struct unit *editor_get_selected_unit(void);
 struct city *editor_get_selected_city(void);
diff -Nurd -X.diff_ignore freeciv/client/gui-gtk-2.0/editdlg.c freeciv/client/gui-gtk-2.0/editdlg.c
--- freeciv/client/gui-gtk-2.0/editdlg.c	2007-02-26 14:16:16.000000000 +0200
+++ freeciv/client/gui-gtk-2.0/editdlg.c	2007-03-02 01:00:24.000000000 +0200
@@ -70,6 +70,8 @@
   { NULL, S_FALLOUT }
 };
 
+static paint_item *resources;
+
 static char *tool_names[ETOOL_LAST] = {
   N_("Paint"), N_("Unit"), N_("City"), N_("Player"), N_("Delete")
 };
@@ -173,6 +175,13 @@
   case EPAINT_SPECIAL:
     editor_set_selected_special(specials[id].paint);
     break;
+  case EPAINT_RESOURCE:
+    if (id == 0) {
+      editor_set_selected_resource(NULL);
+    } else {
+      editor_set_selected_resource(get_resource(resources[id - 1].paint));
+    }
+    break;   
   case EPAINT_LAST:
     break;
   }
@@ -256,12 +265,18 @@
   GtkWidget *table = gtk_table_new(12, TABLE_WIDTH, TRUE);
   int i, j, sig; 
   int magic[3] = { 0, 5, 11 }; /* magic numbers to make the table look good */
-  int types_num[] = { game.control.terrain_count, SPECIALS_NUM };
-  paint_item *ptype[EPAINT_LAST] = { NULL, specials };
+  int types_num[] = { game.control.terrain_count, SPECIALS_NUM,
+                      game.control.resource_count + 1 };
+  paint_item *ptype[EPAINT_LAST] = { NULL, specials, NULL };
   
   terrains = fc_realloc(terrains,
 			game.control.terrain_count * sizeof(*terrains));
-  ptype[0] = terrains;
+  ptype[EPAINT_TERRAIN] = terrains;
+
+  resources = fc_realloc(resources,
+                         (game.control.resource_count + 1) * sizeof(*resources));
+  ptype[EPAINT_RESOURCE] = resources;
+
   
   vbox = gtk_vbox_new(TRUE, 5);
   
@@ -279,6 +294,14 @@
 	  item->name = get_special_name(item->paint);
 	}
         break;
+      case EPAINT_RESOURCE:
+        item->paint = j;
+        if (j == 0) {
+          item->name = _("None");
+        } else {
+          item->name = get_resource(item->paint - 1)->name;
+        } 
+        break;
       }
 
       button = gtk_toggle_button_new_with_label(item->name);
diff -Nurd -X.diff_ignore freeciv/client/packhand.c freeciv/client/packhand.c
--- freeciv/client/packhand.c	2007-03-01 22:59:22.000000000 +0200
+++ freeciv/client/packhand.c	2007-03-02 00:54:17.000000000 +0200
@@ -1954,6 +1954,7 @@
 {
   struct tile *ptile = map_pos_to_tile(packet->x, packet->y);
   enum known_type old_known = client_tile_get_known(ptile);
+  int old_resource;
   bool tile_changed = FALSE;
   bool known_changed = FALSE;
   enum tile_special_type spe;
@@ -1976,6 +1977,16 @@
     }
   }
 
+  if (ptile->resource) {
+    old_resource = ptile->resource->index;
+  } else {
+    old_resource = -1;
+  }
+
+  if (old_resource != packet->resource) {
+    tile_changed = TRUE;
+  }
+
   ptile->resource = get_resource(packet->resource);
   if (packet->owner == MAP_TILE_OWNER_NULL) {
     if (ptile->owner) {
diff -Nurd -X.diff_ignore freeciv/server/edithand.c freeciv/server/edithand.c
--- freeciv/server/edithand.c	2007-02-26 14:15:28.000000000 +0200
+++ freeciv/server/edithand.c	2007-03-02 00:51:19.000000000 +0200
@@ -64,8 +64,6 @@
 /****************************************************************************
   Handles new tile information from the client, to make local edits to
   the map.
-
-  TODO: Handle resources.
 ****************************************************************************/
 void handle_edit_tile(struct connection *pc, int x, int y,
                       Terrain_type_id terrain, Resource_type_id resource,
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to