Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2006:
[Freeciv-Dev] (PR#15843) Editor: Fix fortress, paint city
Home

[Freeciv-Dev] (PR#15843) Editor: Fix fortress, paint city

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#15843) Editor: Fix fortress, paint city
From: "Per I. Mathisen" <per@xxxxxxxxxxx>
Date: Fri, 10 Mar 2006 14:53:21 -0800
Reply-to: bugs@xxxxxxxxxxx

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

This patch fixes two bugs in regards to fortresses. The first is that they
could be painted as unowned, thus causing an assert failure in the borders
code. The second is that the assert failure is triggered even when borders
are not activated.

It also moves the city painting into the paint tab. You can now select
which player to paint as for cities and fortresses in the paint tab. The
city tab is removed.

However, I screwed up the widget packing in the paint tab, so someone
better than me in gtk magic must realign the widgets.

BTW, I noticed that you no longer can paint specials underneath cities.
Oops. My fault, I guess. I guess what happens when you click on a city
should be dependent on which tool you have selected?

  - Per

Index: server/edithand.c
===================================================================
--- server/edithand.c   (revision 11751)
+++ server/edithand.c   (working copy)
@@ -59,17 +59,17 @@
 
 /****************************************************************************
   Handles new tile information from the client, to make local edits to
-  the map.
+  the map. Toggle specials, and remember to add/remove ownership for 
+  fortresses when they are used as border sources.
 
   TODO: Handle resources.
 ****************************************************************************/
-void handle_edit_tile(struct connection *pc, int x, int y,
-                      Terrain_type_id terrain, Resource_type_id resource,
-                     bv_special special)
+void handle_edit_tile(struct connection *pc, struct packet_edit_tile *packet)
 {
-  struct tile *ptile = map_pos_to_tile(x, y);
-  struct terrain *pterrain = get_terrain(terrain), *old_terrain;
-  struct resource *presource = get_resource(resource);
+  struct tile *ptile = map_pos_to_tile(packet->x, packet->y);
+  struct terrain *pterrain = get_terrain(packet->terrain), *old_terrain;
+  struct resource *presource = get_resource(packet->resource);
+  struct player *owner = get_player(packet->owner);
 
   if (pc->access_level != ALLOW_HACK || !game.info.is_edit_mode
       || !ptile || !pterrain) {
@@ -79,10 +79,18 @@
   old_terrain = ptile->terrain;
 
   specials_iterate(s) {
-    if (contains_special(special, s) && !tile_has_special(ptile, s)) {
+    if (contains_special(packet->special, s) && !tile_has_special(ptile, s)) {
       tile_add_special(ptile, s);
-    } else if (!contains_special(special, s) && tile_has_special(ptile, s)) {
+      if (game.info.borders > 0 && owner && s == S_FORTRESS) {
+        map_claim_ownership(ptile, owner, ptile);
+      }
+    } else if (!contains_special(packet->special, s)
+               && tile_has_special(ptile, s)) {
       tile_remove_special(ptile, s);
+      if (s == S_FORTRESS && ptile->owner) {
+        ptile->owner = NULL;
+        ptile->owner_source = NULL;
+      }
     }
   } specials_iterate_end;
 
Index: server/sanitycheck.c
===================================================================
--- server/sanitycheck.c        (revision 11751)
+++ server/sanitycheck.c        (working copy)
@@ -88,7 +88,7 @@
     SANITY_TILE(ptile, pterrain->index >= T_FIRST 
                        && pterrain->index < T_COUNT);
 
-    if (contains_special(special, S_FORTRESS)) {
+    if (game.info.borders > 0 && contains_special(special, S_FORTRESS)) {
       SANITY_TILE(ptile, ptile->owner != NULL);
     }
   } whole_map_iterate_end;
Index: common/packets.def
===================================================================
--- common/packets.def  (revision 11751)
+++ common/packets.def  (working copy)
@@ -1362,6 +1362,7 @@
   TERRAIN terrain;
   RESOURCE resource;
   BV_SPECIAL special;
+  PLAYER owner; # for fortress
 end
 
 PACKET_EDIT_UNIT=126;cs,handle-per-conn,lsend
Index: client/gui-gtk-2.0/editdlg.c
===================================================================
--- client/gui-gtk-2.0/editdlg.c        (revision 11751)
+++ client/gui-gtk-2.0/editdlg.c        (working copy)
@@ -39,7 +39,7 @@
 #include "gui_stuff.h"
 
 #define TABLE_WIDTH 3
-#define TOOL_WIDTH 5
+#define TOOL_WIDTH 4
 
 enum unit_param {
   UPARAM_OWNER,
@@ -62,9 +62,11 @@
 } paint_item;
 
 static paint_item *terrains;
-
+static paint_item paint_city[] = {
+ { N_("City"), 0 }
+};
 static paint_item specials[] = {
-  { N_("clear all"), S_LAST },
+  { N_("Clear all"), S_LAST },
   { NULL, S_ROAD },
   { NULL, S_IRRIGATION },
   { NULL, S_RAILROAD },
@@ -79,11 +81,13 @@
 };
 
 static char *tool_names[ETOOL_LAST] = {
-  N_("Paint"), N_("Unit"), N_("City"), N_("Player"), N_("Delete")
+  N_("Paint"), N_("Unit"), N_("Player"), N_("Delete")
 };
 
 #define SPECIALS_NUM ARRAY_SIZE(specials)
+#define CITY_NUM ARRAY_SIZE(paint_city)
 
+static GtkWidget *paint_spin = NULL;
 static GtkWidget *toolwin;
 static GtkWidget *notebook;
 
@@ -177,11 +181,25 @@
   switch(paint){
   case EPAINT_TERRAIN:
     editor_set_selected_terrain(get_terrain(terrains[id].paint));
+    if (paint_spin) {
+      gtk_widget_set_sensitive(paint_spin, FALSE);
+    }
     break;
   case EPAINT_SPECIAL:
     editor_set_selected_special(specials[id].paint);
+    if (paint_spin) {
+      gtk_widget_set_sensitive(paint_spin, specials[id].paint == S_FORTRESS);
+    }
     break;
+  case EPAINT_CITY:
+    if (paint_spin) {
+      gtk_widget_set_sensitive(paint_spin, TRUE);
+    }
+    break;
   case EPAINT_LAST:
+    if (paint_spin) {
+      gtk_widget_set_sensitive(paint_spin, FALSE);
+    }
     break;
   }
 }
@@ -222,23 +240,14 @@
 }
 
 /****************************************************************************
- FIXME: this is for demonstration purposes only (and not demonstration of
-          coding goodness to be sure!)
+  Select which player is owning painted cities and fortresses.
 ****************************************************************************/
 static void city_callback(GtkSpinButton *spinbutton, gpointer data)
 {
-  struct city *pcity = editor_get_selected_city();
-  enum city_param param = GPOINTER_TO_INT(data);
+  struct player *pplayer;
 
-  switch (param) {
-  case CPARAM_OWNER:
-    pcity->owner = get_player(gtk_spin_button_get_value_as_int(spinbutton));
-    return;
-  case CPARAM_LAST:
-    break;
-  }
-
-  assert(0);
+  pplayer = get_player(gtk_spin_button_get_value_as_int(spinbutton));
+  editor_set_selected_paint_player(pplayer);
 }
 
 #if 0
@@ -256,12 +265,13 @@
 ****************************************************************************/
 static GtkWidget *create_map_palette(void)
 {
-  GtkWidget *button, *vbox;
+  GtkWidget *button, *vbox, *label, *hbox;
+  GtkAdjustment *adj;
   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, CITY_NUM };
+  paint_item *ptype[EPAINT_LAST] = { NULL, specials, paint_city };
   
   terrains = fc_realloc(terrains,
                        game.control.terrain_count * sizeof(*terrains));
@@ -283,6 +293,8 @@
          item->name = get_special_name(item->paint);
        }
         break;
+      case EPAINT_CITY:
+        break;
       }
 
       button = gtk_toggle_button_new_with_label(item->name);
@@ -308,10 +320,25 @@
       g_object_set_data(G_OBJECT(button), "sigid", GINT_TO_POINTER(sig));
     }
   }
-  
+
+  adj = GTK_ADJUSTMENT(gtk_adjustment_new(game.player_ptr->player_no, 0, 
+                                          game.info.nplayers - 1,
+                                          1.0, 5.0, 5.0));
+  editor_set_selected_paint_player(game.player_ptr);
   editor_set_selected_terrain(get_terrain(terrains[0].paint));
+
+  hbox = gtk_hbox_new(FALSE, 5);
+  paint_spin = gtk_spin_button_new(adj, 1, 0);
+  label = gtk_label_new(_("Owner"));
+  gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
+  gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0);
+  gtk_box_pack_start(GTK_BOX(hbox), paint_spin, TRUE, TRUE, 0);
+  g_signal_connect(paint_spin, "value-changed", G_CALLBACK(city_callback), 
NULL);
+
   gtk_box_pack_start(GTK_BOX(vbox), table, TRUE, TRUE, 5);
   gtk_widget_show_all(vbox);
+
+  gtk_widget_set_sensitive(paint_spin, FALSE);
   
   return vbox;
 }
@@ -360,40 +387,6 @@
   return vbox;
 }
 
-/****************************************************************************
-  Create the tab for the city editor tool.
-****************************************************************************/
-static GtkWidget *create_city_palette(void)
-{
-  GtkWidget *hbox, *vbox, *label, *sb;
-  GtkAdjustment *adj;
-  int i;
-  struct city *pcity = editor_get_selected_city();
-
-  const char *names[CPARAM_LAST] = { _("Owner"), };
-  int inits[CPARAM_LAST][3] = {
-    {pcity->owner->player_no, 0, game.info.nplayers - 1},
-  };
-
-  vbox = gtk_vbox_new(FALSE, 5);
-
-  for (i = 0; i < CPARAM_LAST; i++) {
-    adj = GTK_ADJUSTMENT(gtk_adjustment_new(inits[i][0], inits[i][1], 
-                                           inits[i][2], 1.0, 5.0, 5.0));
-    hbox = gtk_hbox_new(FALSE, 5);
-    sb = gtk_spin_button_new(adj, 1, 0);
-    label = gtk_label_new(names[i]);
-    gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
-    gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0);
-    gtk_box_pack_start(GTK_BOX(hbox), sb, TRUE, TRUE, 0);
-
-    g_signal_connect(sb, "value-changed", G_CALLBACK(city_callback),
-                     GINT_TO_POINTER(i));
-  }
-
-  return vbox;
-}
-
 #if 0
 /****************************************************************************
   Create the tab for the player editor tool.
@@ -450,8 +443,6 @@
                           create_map_palette(), NULL);
   gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
                           create_units_palette(), NULL);
-  gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
-                          create_city_palette(), NULL);
 #if 0
   gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
                           create_player_palette(), NULL);
Index: client/editor.c
===================================================================
--- client/editor.c     (revision 11751)
+++ client/editor.c     (working copy)
@@ -38,6 +38,7 @@
 static enum editor_paint_type selected_paint_type = EPAINT_LAST;
 static struct unit *selected_unit;
 static struct city *selected_city;
+static struct player *paint_player = NULL;
 
 /****************************************************************************
   Initialize the editor tools data.
@@ -66,7 +67,7 @@
 }
 
 /****************************************************************************
-  Returns the currently selected editor tool type.
+  Sets the currently selected editor tool type.
 ****************************************************************************/
 void editor_set_selected_tool_type(enum editor_tool_type type)
 {
@@ -74,7 +75,7 @@
 }
 
 /****************************************************************************
-  Returns the currently selected editor paint type.
+  Sets the currently selected editor paint type.
 ****************************************************************************/
 void editor_set_selected_paint_type(enum editor_paint_type type)
 {
@@ -98,6 +99,14 @@
 }
 
 /****************************************************************************
+  Sets the selected player in the paint dialog.
+****************************************************************************/
+void editor_set_selected_paint_player(struct player *pplayer)
+{
+  paint_player = pplayer;
+}
+
+/****************************************************************************
   Returns the selected unit.
 ****************************************************************************/
 struct unit *editor_get_selected_unit(void)
@@ -197,16 +206,20 @@
       tile_add_special(&tile, selected_special);
     }
     break;
+  case EPAINT_CITY:
+    do_city(ptile);
+    return;
   case EPAINT_LAST:
     return;
-  } 
+  }
 
   /* send the result to the server for changing */
   /* FIXME: No way to change resources. */
   dsend_packet_edit_tile(&aconnection, ptile->x, ptile->y,
                         tile.terrain->index,
                         tile.resource ? tile.resource->index : -1,
-                        tile.special);
+                        tile.special, 
+                         paint_player ? paint_player->player_no : 0);
 }
 
 /****************************************************************************
@@ -228,9 +241,6 @@
   case ETOOL_UNIT:
     do_unit(ptile);
     break;
-  case ETOOL_CITY:
-    do_city(ptile);
-    break;
   case ETOOL_PLAYER:
   case ETOOL_DELETE:
   case ETOOL_LAST:
Index: client/editor.h
===================================================================
--- client/editor.h     (revision 11751)
+++ client/editor.h     (working copy)
@@ -19,7 +19,6 @@
 enum editor_tool_type {
   ETOOL_PAINT,
   ETOOL_UNIT,
-  ETOOL_CITY,
   ETOOL_PLAYER,
   ETOOL_DELETE,
   ETOOL_LAST
@@ -28,6 +27,7 @@
 enum editor_paint_type {
   EPAINT_TERRAIN,
   EPAINT_SPECIAL,
+  EPAINT_CITY,
   EPAINT_LAST
 };
 
@@ -40,6 +40,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_paint_player(struct player *pplayer);
 
 struct unit *editor_get_selected_unit(void);
 struct city *editor_get_selected_city(void);

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#15843) Editor: Fix fortress, paint city, Per I. Mathisen <=