Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2005:
[Freeciv-Dev] (PR#13499) clean up autosettlers in the client
Home

[Freeciv-Dev] (PR#13499) clean up autosettlers in the client

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#13499) clean up autosettlers in the client
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 20 Jul 2005 12:24:57 -0700
Reply-to: bugs@xxxxxxxxxxx

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

This miscellaneous patch (requested by per) cleans up some of the
autosettler code in the client.  Note that autoattack no longer works
like it did so all the old autoattack code is apparently obsolete (or so
I'm told).  Additionally, the way autosettlers and autoattack units are
lumped together is very counter-intuitive.

In the patch:

- All xxx_unit_auto() functions are renamed as xxx_unit_autosettlers.
Only settler (worker) units can do this naturally.

- It's no longer possible for the client to request military units to
autoattack (as I said this autoattack has been disabled so this just
gets the unit stuck in an unusable state).

The latter is a bug and probably applies to 2.0 also.

-jason

Index: client/control.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/control.c,v
retrieving revision 1.182
diff -p -u -r1.182 control.c
--- client/control.c    14 Jul 2005 19:25:44 -0000      1.182
+++ client/control.c    20 Jul 2005 19:20:50 -0000
@@ -964,16 +964,16 @@ void request_unit_upgrade(struct unit *p
   }
 }
 
-/**************************************************************************
-...
-**************************************************************************/
-void request_unit_auto(struct unit *punit)
+/****************************************************************************
+  Call to request (from the server) that the settler unit is put into
+  autosettler mode.
+****************************************************************************/
+void request_unit_autosettlers(const struct unit *punit)
 {
-  if (can_unit_do_auto(punit)) {
-    dsend_packet_unit_auto(&aconnection, punit->id);
+  if (punit && can_unit_do_autosettlers(punit)) {
+    dsend_packet_unit_autosettlers(&aconnection, punit->id);
   } else {
-    append_output_window(_("Only settler units and military units"
-                          " in cities can be put in auto-mode."));
+    append_output_window(_("Only settler units can be put into auto mode."));
   }
 }
 
@@ -1990,17 +1990,6 @@ void key_unit_airbase(void)
 /**************************************************************************
 ...
 **************************************************************************/
-void key_unit_auto_attack(void)
-{
-  if (punit_focus && !unit_flag(punit_focus, F_SETTLERS) &&
-      can_unit_do_auto(punit_focus)) {
-    request_unit_auto(punit_focus);
-  }
-}
-
-/**************************************************************************
-...
-**************************************************************************/
 void key_unit_auto_explore(void)
 {
   if (punit_focus &&
@@ -2010,13 +1999,13 @@ void key_unit_auto_explore(void)
 }
 
 /**************************************************************************
-...
+  Call to request (from the server) that the focus unit is put into
+  autosettler mode.
 **************************************************************************/
 void key_unit_auto_settle(void)
 {
-  if (punit_focus && unit_flag(punit_focus, F_SETTLERS) &&
-      can_unit_do_auto(punit_focus)) {
-    request_unit_auto(punit_focus);
+  if (punit_focus && can_unit_do_autosettlers(punit_focus)) {
+    request_unit_autosettlers(punit_focus);
   }
 }
 
Index: client/control.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/control.h,v
retrieving revision 1.51
diff -p -u -r1.51 control.h
--- client/control.h    1 Jun 2005 00:32:31 -0000       1.51
+++ client/control.h    20 Jul 2005 19:20:50 -0000
@@ -60,7 +60,7 @@ void request_new_unit_activity_targeted(
                                        enum tile_special_type tgt);
 void request_unit_load(struct unit *pcargo, struct unit *ptransporter);
 void request_unit_unload(struct unit *pcargo);
-void request_unit_auto(struct unit *punit);
+void request_unit_autosettlers(const struct unit *punit);
 void request_unit_build_city(struct unit *punit);
 void request_unit_caravan_action(struct unit *punit, enum packet_type action);
 void request_unit_change_homecity(struct unit *punit);
@@ -143,7 +143,6 @@ void key_quickselect(enum quickselect_ty
 void key_recall_previous_focus_unit(void);
 void key_unit_move(enum direction8 gui_dir);
 void key_unit_airbase(void);
-void key_unit_auto_attack(void);
 void key_unit_auto_explore(void);
 void key_unit_auto_settle(void);
 void key_unit_build_city(void);
Index: client/gui-gtk-2.0/menu.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/menu.c,v
retrieving revision 1.81
diff -p -u -r1.81 menu.c
--- client/gui-gtk-2.0/menu.c   14 Jul 2005 19:25:45 -0000      1.81
+++ client/gui-gtk-2.0/menu.c   20 Jul 2005 19:20:51 -0000
@@ -472,8 +472,7 @@ static void orders_menu_callback(gpointe
     key_unit_wakeup_others();
     break;
    case MENU_ORDER_AUTO_SETTLER:
-    if(get_unit_in_focus())
-      request_unit_auto(get_unit_in_focus());
+     request_unit_autosettlers(get_unit_in_focus());
     break;
    case MENU_ORDER_AUTO_EXPLORE:
     key_unit_auto_explore();
@@ -1343,7 +1342,7 @@ void update_menus(void)
                          is_unit_activity_on_tile(ACTIVITY_SENTRY,
                                                    punit->tile));
       menus_set_sensitive("<main>/_Orders/_Auto Settler",
-                          can_unit_do_auto(punit));
+                          can_unit_do_autosettlers(punit));
       menus_set_sensitive("<main>/_Orders/Auto E_xplore",
                           can_unit_do_activity(punit, ACTIVITY_EXPLORE));
       menus_set_sensitive("<main>/_Orders/_Connect/_Road",
@@ -1424,12 +1423,6 @@ void update_menus(void)
        menus_rename("<main>/_Orders/Clean _Pollution", _("Clean _Pollution"));
       }
 
-      if (!unit_flag(punit, F_SETTLERS)) {
-       menus_rename("<main>/_Orders/_Auto Settler", _("_Auto Attack"));
-      } else {
-       menus_rename("<main>/_Orders/_Auto Settler", _("_Auto Settler"));
-      }
-
       menus_set_sensitive("<main>/_Orders", TRUE);
     } else {
       menus_set_sensitive("<main>/_Orders", FALSE);
Index: common/packets.def
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.def,v
retrieving revision 1.142
diff -p -u -r1.142 packets.def
--- common/packets.def  18 Jul 2005 17:16:16 -0000      1.142
+++ common/packets.def  20 Jul 2005 19:20:51 -0000
@@ -795,7 +795,8 @@ PACKET_UNIT_ORDERS=59;cs
   COORD dest_x, dest_y;
 end
 
-PACKET_UNIT_AUTO=60;cs,dsend
+# Enable autosettlers for a unit.  Only works for settler units naturally.
+PACKET_UNIT_AUTOSETTLERS=60;cs,dsend
   UNIT unit_id;
 end
 
Index: common/unit.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unit.c,v
retrieving revision 1.245
diff -p -u -r1.245 unit.c
--- common/unit.c       14 Jul 2005 19:25:45 -0000      1.245
+++ common/unit.c       20 Jul 2005 19:20:51 -0000
@@ -488,19 +488,17 @@ int get_turns_for_activity_at(const stru
 }
 
 /**************************************************************************
-  Return whether the unit can be put in auto-mode.
-  (Auto-settler for settlers, auto-attack for military units.)
+  Return whether the unit can be put in auto-settler mode.
+
+  NOTE: we used to have "auto" mode including autosettlers and auto-attack.
+  This was bad because the two were indestinguishable even though they
+  are very different.  Now auto-attack is done differently so we just have
+  auto-settlers.  If any new auto modes are introduced they should be
+  handled separately.
 **************************************************************************/
-bool can_unit_do_auto(const struct unit *punit) 
+bool can_unit_do_autosettlers(const struct unit *punit) 
 {
-  if (unit_flag(punit, F_SETTLERS)) {
-    return TRUE;
-  }
-  if (is_military_unit(punit) && is_attack_unit(punit)
-      && tile_get_city(punit->tile)) {
-    return TRUE;
-  }
-  return FALSE;
+  return unit_flag(punit, F_SETTLERS);
 }
 
 /**************************************************************************
Index: common/unit.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unit.h,v
retrieving revision 1.145
diff -p -u -r1.145 unit.h
--- common/unit.h       4 Jul 2005 17:48:37 -0000       1.145
+++ common/unit.h       20 Jul 2005 19:20:51 -0000
@@ -266,7 +266,7 @@ int get_activity_rate_this_turn(const st
 int get_turns_for_activity_at(const struct unit *punit,
                              enum unit_activity activity,
                              const struct tile *ptile);
-bool can_unit_do_auto(const struct unit *punit); 
+bool can_unit_do_autosettlers(const struct unit *punit); 
 bool is_unit_activity_on_tile(enum unit_activity activity,
                              const struct tile *ptile);
 bv_special get_unit_tile_pillage_set(const struct tile *ptile);
Index: server/unithand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/unithand.c,v
retrieving revision 1.343
diff -p -u -r1.343 unithand.c
--- server/unithand.c   13 Jul 2005 16:49:39 -0000      1.343
+++ server/unithand.c   20 Jul 2005 19:20:52 -0000
@@ -1436,11 +1436,11 @@ void handle_unit_establish_trade(struct 
 /**************************************************************************
 ...
 **************************************************************************/
-void handle_unit_auto(struct player *pplayer, int unit_id)
+void handle_unit_autosettlers(struct player *pplayer, int unit_id)
 {
   struct unit *punit = player_find_unit_by_id(pplayer, unit_id);
 
-  if (!punit || !can_unit_do_auto(punit))
+  if (!punit || !can_unit_do_autosettlers(punit))
     return;
 
   punit->ai.control = TRUE;

[Prev in Thread] Current Thread [Next in Thread]