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

Patch adds a "military base" tool to the editor toolbar,
temporarily using the terrain special sprite as a placeholder.
(New icons will be added soon in #40267.)


-----------------------------------------------------------------------
トイレに行く時間がなくて瓶におしっこしちゃうほど忙しいよ
>From 489550ef05d8d801085767e178c3957ede9b6d95 Mon Sep 17 00:00:00 2001
From: Madeline Book <[EMAIL PROTECTED]>
Date: Thu, 17 Jul 2008 17:31:45 -0400
Subject: [PATCH] Added military base tool, using special tool sprite as placeholder.

---
 client/editor.c              |   67 ++++++++++++++---------------------------
 client/editor.h              |    5 +--
 client/gui-gtk-2.0/editgui.c |   30 ++++++++++++++-----
 client/tilespec.c            |    1 +
 client/tilespec.h            |    3 +-
 data/misc/editor.spec        |    1 +
 6 files changed, 50 insertions(+), 57 deletions(-)

diff --git a/client/editor.c b/client/editor.c
index 030cedb..94581ba 100644
--- a/client/editor.c
+++ b/client/editor.c
@@ -115,6 +115,9 @@ void editor_init(void)
   SET_TOOL(ETT_TERRAIN_SPECIAL, _("Terrain Special"),
            ETF_HAS_VALUE | ETF_HAS_SIZE | ETF_HAS_VALUE_ERASE,
            _("Modify tile specials."));
+  SET_TOOL(ETT_MILITARY_BASE, _("Military Base"),
+           ETF_HAS_VALUE | ETF_HAS_SIZE | ETF_HAS_VALUE_ERASE,
+           _("Create a military base."));
   SET_TOOL(ETT_UNIT, _("Unit"),
            ETF_HAS_VALUE | ETF_HAS_COUNT | ETF_HAS_APPLIED_PLAYER,
            _("Create unit."));
@@ -372,8 +375,8 @@ static void editor_grab_tool(const struct tile *ptile)
       value = utype_number(unit_type(grabbed_punit));
     }
   } else if (pbase != NULL) {
-    ett = ETT_TERRAIN_SPECIAL;
-    value = editor_encode_base_number(base_number(pbase));
+    ett = ETT_MILITARY_BASE;
+    value = base_number(pbase);
 
   } else if (tile_really_has_any_specials(ptile)) {
     int specials_array[S_LAST];
@@ -742,14 +745,13 @@ void editor_apply_tool(const struct tile *ptile,
     break;
 
   case ETT_TERRAIN_SPECIAL:
-    if (editor_value_is_encoded_base_number(value)) {
-      value = editor_decode_base_value(value);
-      dsend_packet_edit_tile_base(&client.conn, ptile->x, ptile->y,
-                                  value, erase, size);
-    } else {
-      dsend_packet_edit_tile_special(&client.conn, ptile->x, ptile->y,
-                                     value, erase, size);
-    }
+    dsend_packet_edit_tile_special(&client.conn, ptile->x, ptile->y,
+                                   value, erase, size);
+    break;
+
+  case ETT_MILITARY_BASE:
+    dsend_packet_edit_tile_base(&client.conn, ptile->x, ptile->y,
+                                value, erase, size);
     break;
 
   case ETT_UNIT:
@@ -942,6 +944,7 @@ const char *editor_tool_get_value_name(enum editor_tool_type emt, int value)
   struct terrain *pterrain;
   struct resource *presource;
   struct unit_type *putype;
+  struct base_type *pbase;
 
   if (!editor) {
     return "";
@@ -957,14 +960,14 @@ const char *editor_tool_get_value_name(enum editor_tool_type emt, int value)
     return presource ? resource_name_translation(presource) : "";
     break;
   case ETT_TERRAIN_SPECIAL:
-    if (editor_value_is_encoded_base_number(value)) {
-      struct base_type *pbase;
-      
-      pbase = base_by_number(editor_decode_base_value(value));
-      return pbase != NULL ? base_name_translation(pbase) : "";
+    if (!(0 <= value && value < S_LAST)) {
+      return "";
     }
-    return 0 <= value && value < S_LAST
-      ? special_name_translation(value) : "";
+    return special_name_translation(value);
+    break;
+  case ETT_MILITARY_BASE:
+    pbase = base_by_number(value);
+    return pbase != NULL ? base_name_translation(pbase) : "";
     break;
   case ETT_UNIT:
     putype = utype_by_number(value);
@@ -1070,6 +1073,9 @@ struct sprite *editor_tool_get_sprite(enum editor_tool_type ett)
   case ETT_TERRAIN_SPECIAL:
     return sprites->terrain_special;
     break;
+  case ETT_MILITARY_BASE:
+    return sprites->military_base;
+    break;
   case ETT_UNIT:
     return sprites->unit;
     break;
@@ -1153,33 +1159,6 @@ bool editor_tool_has_value_erase(enum editor_tool_type ett)
 }
 
 /****************************************************************************
-  Encode the given base type id so that it can be stored as a value for
-  the editor tool ETT_TERRAIN_SPECIAL without conflicting with enum
-  tile_special_type.
-****************************************************************************/
-int editor_encode_base_number(int base_type_id)
-{
-  return S_LAST + base_type_id;
-}
-
-/****************************************************************************
-  Decode the given ETT_TERRAIN_SPECIAL tool value to a base type id.
-****************************************************************************/
-int editor_decode_base_value(int value)
-{
-  return value - S_LAST;
-}
-
-/****************************************************************************
-  Return TRUE if the give tool value for ETT_TERRAIN_SPECIAL is an
-  encoded base type id.
-****************************************************************************/
-bool editor_value_is_encoded_base_number(int value)
-{
-  return value >= S_LAST;
-}
-
-/****************************************************************************
   Returns the number of currently selected tiles.
 ****************************************************************************/
 int editor_selection_count(void)
diff --git a/client/editor.h b/client/editor.h
index 3ac739c..92528a6 100644
--- a/client/editor.h
+++ b/client/editor.h
@@ -20,6 +20,7 @@ enum editor_tool_type {
   ETT_TERRAIN = 0,
   ETT_TERRAIN_RESOURCE,
   ETT_TERRAIN_SPECIAL,
+  ETT_MILITARY_BASE,
   ETT_UNIT,
   ETT_CITY,
   ETT_VISION,
@@ -92,8 +93,4 @@ bool editor_tile_is_selected(const struct tile *ptile);
 void editor_apply_tool_to_selection(void);
 int editor_selection_count(void);
 
-int editor_encode_base_number(int base_type_id);
-int editor_decode_base_value(int value);
-bool editor_value_is_encoded_base_number(int value);
-
 #endif /* FC__TOOLS_H */
diff --git a/client/gui-gtk-2.0/editgui.c b/client/gui-gtk-2.0/editgui.c
index 87419a8..6f8ddf8 100644
--- a/client/gui-gtk-2.0/editgui.c
+++ b/client/gui-gtk-2.0/editgui.c
@@ -442,6 +442,8 @@ static struct editbar *editbar_create(void)
                              radio_parent, hbox);
   create_editbar_radiobutton(eb, ETT_TERRAIN_SPECIAL,
                              radio_parent, hbox);
+  create_editbar_radiobutton(eb, ETT_MILITARY_BASE,
+                             radio_parent, hbox);
   create_editbar_radiobutton(eb, ETT_UNIT,
                              radio_parent, hbox);
   create_editbar_radiobutton(eb, ETT_CITY,
@@ -741,10 +743,17 @@ static void editbar_reload_tileset(struct editbar *eb)
     gtk_list_store_set(store, &iter, TVS_COL_IMAGE, pixbuf, -1);
   } tile_special_type_iterate_end;
 
+
+  /* Reload military bases. */
+
+  tvs = eb->tool_selectors[ETT_MILITARY_BASE];
+  store = tvs->store;
+  gtk_list_store_clear(store);
+
   base_type_iterate(pbase) {
     int id;
 
-    id = editor_encode_base_number(base_number(pbase));
+    id = base_number(pbase);
 
     gtk_list_store_append(store, &iter);
     gtk_list_store_set(store, &iter,
@@ -1267,6 +1276,7 @@ static GdkPixbuf *get_tool_value_pixbuf(enum editor_tool_type ett,
   struct terrain *pterrain;
   struct resource *presource;
   struct unit_type *putype;
+  struct base_type *pbase;
   const struct editor_sprites *sprites;
 
   sprites = get_editor_sprites(tileset);
@@ -1288,13 +1298,11 @@ static GdkPixbuf *get_tool_value_pixbuf(enum editor_tool_type ett,
     }
     break;
   case ETT_TERRAIN_SPECIAL:
-    if (editor_value_is_encoded_base_number(value)) {
-      int id = editor_decode_base_value(value);
-      struct base_type *pbase = base_by_number(id);
-      pixbuf = create_military_base_pixbuf(pbase);
-    } else {
-      sprite = get_basic_special_sprite(tileset, value);
-    }
+    sprite = get_basic_special_sprite(tileset, value);
+    break;
+  case ETT_MILITARY_BASE:
+    pbase = base_by_number(value);
+    pixbuf = create_military_base_pixbuf(pbase);
     break;
   case ETT_UNIT:
     putype = utype_by_number(value);
@@ -1513,6 +1521,9 @@ static gboolean handle_edit_key_press_with_shift(GdkEventKey *ev)
   case GDK_S:
     editgui_run_tool_selection(ETT_TERRAIN_SPECIAL);
     break;
+  case GDK_M:
+    editgui_run_tool_selection(ETT_MILITARY_BASE);
+    break;
   case GDK_U:
     editgui_run_tool_selection(ETT_UNIT);
     break;
@@ -1551,6 +1562,9 @@ gboolean handle_edit_key_press(GdkEventKey *ev)
   case GDK_s:
     ett = ETT_TERRAIN_SPECIAL;
     break;
+  case GDK_m:
+    ett = ETT_MILITARY_BASE;
+    break;
   case GDK_u:
     ett = ETT_UNIT;
     break;
diff --git a/client/tilespec.c b/client/tilespec.c
index 8f9b24e..adaef6c 100644
--- a/client/tilespec.c
+++ b/client/tilespec.c
@@ -2314,6 +2314,7 @@ static void tileset_lookup_sprite_tags(struct tileset *t)
   SET_EDITOR_SPRITE(vision);
   SET_EDITOR_SPRITE(territory);
   SET_EDITOR_SPRITE(properties);
+  SET_EDITOR_SPRITE(military_base);
 #undef SET_EDITOR_SPRITE
 
   SET_SPRITE(city.disorder, "city.disorder");
diff --git a/client/tilespec.h b/client/tilespec.h
index 34330cb..794e5f0 100644
--- a/client/tilespec.h
+++ b/client/tilespec.h
@@ -232,7 +232,8 @@ struct editor_sprites {
     *city,
     *vision,
     *territory,
-    *properties;
+    *properties,
+    *military_base;
 };
 
 struct sprite *get_spaceship_sprite(const struct tileset *t,
diff --git a/data/misc/editor.spec b/data/misc/editor.spec
index b8fc2d8..dbf7f9b 100644
--- a/data/misc/editor.spec
+++ b/data/misc/editor.spec
@@ -46,4 +46,5 @@ tiles = { "row", "column", "tag"
   0,  8, "editor.vision"
   0,  9, "editor.territory"
   0, 10, "editor.properties"
+  0,  5, "editor.military_base"
 }
-- 
1.5.5.1

_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to