Complete.Org: Mailing Lists: Archives: freeciv-dev: January 2004:
[Freeciv-Dev] Re: (PR#4684) client-side air goto
Home

[Freeciv-Dev] Re: (PR#4684) client-side air goto

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] Re: (PR#4684) client-side air goto
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 20 Jan 2004 22:31:16 -0800
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=4684 >

> Here's a new version of the air-goto-in-pf patch.  I think this should
> go in fairly soon.  Removing server-side client goto will make a lot of
> things much prettier.

Index: client/control.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/control.c,v
retrieving revision 1.124
diff -u -r1.124 control.c
--- client/control.c    2004/01/20 21:52:06     1.124
+++ client/control.c    2004/01/21 06:22:33
@@ -594,14 +594,9 @@
   if (hover_state != HOVER_GOTO) {
     set_hover_state(punit, HOVER_GOTO);
     update_unit_info_label(punit);
-    /* Not yet implemented for air units, including helicopters. */
-    if (is_air_unit(punit) || is_heli_unit(punit)) {
-      draw_goto_line = FALSE;
-    } else {
-      enter_goto_state(punit);
-      create_line_at_mouse_pos();
-    }
-  } else if (!is_air_unit(punit) && !is_heli_unit(punit)) {
+    enter_goto_state(punit);
+    create_line_at_mouse_pos();
+  } else {
     assert(goto_is_active());
     goto_add_waypoint();
   }
@@ -650,11 +645,6 @@
 {
   struct pf_path *path;
 
-  if (is_air_unit(punit) || is_heli_unit(punit)) {
-    /* PF doesn't support air or helicopter units yet. */
-    return;
-  }
-
   if ((path = path_to_nearest_allied_city(punit))) {
     send_goto_path(punit, path);
     pf_destroy_path(path);
@@ -867,13 +857,8 @@
   if (hover_state != HOVER_PATROL) {
     set_hover_state(punit, HOVER_PATROL);
     update_unit_info_label(punit);
-    /* Not yet implemented for air units, including helicopters. */
-    if (is_air_unit(punit) || is_heli_unit(punit)) {
-      draw_goto_line = FALSE;
-    } else {
-      enter_goto_state(punit);
-      create_line_at_mouse_pos();
-    }
+    enter_goto_state(punit);
+    create_line_at_mouse_pos();
   } else {
     assert(goto_is_active());
     goto_add_waypoint();
@@ -1507,18 +1492,14 @@
 **************************************************************************/
 void do_unit_patrol_to(struct unit *punit, int x, int y)
 {
-  if (is_air_unit(punit)) {
-    append_output_window(_("Game: Sorry, airunit patrol not yet 
implemented."));
-    return;
+  int dest_x, dest_y;
+
+  draw_line(x, y);
+  get_line_dest(&dest_x, &dest_y);
+  if (same_pos(dest_x, dest_y, x, y)) {
+    send_patrol_route(punit);
   } else {
-    int dest_x, dest_y;
-    draw_line(x, y);
-    get_line_dest(&dest_x, &dest_y);
-    if (same_pos(dest_x, dest_y, x, y)) {
-      send_patrol_route(punit);
-    } else {
-      append_output_window(_("Game: Didn't find a route to the destination!"));
-    }
+    append_output_window(_("Game: Didn't find a route to the destination!"));
   }
 
   set_hover_state(NULL, HOVER_NONE);
Index: client/gui-gtk/menu.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/menu.c,v
retrieving revision 1.81
diff -u -r1.81 menu.c
--- client/gui-gtk/menu.c       2004/01/20 21:52:07     1.81
+++ client/gui-gtk/menu.c       2004/01/21 06:22:34
@@ -1146,8 +1146,6 @@
                           can_unit_do_activity(punit, ACTIVITY_EXPLORE));
       menus_set_sensitive("<main>/_Orders/_Connect",
                           can_unit_do_connect(punit, ACTIVITY_IDLE));
-      menus_set_sensitive("<main>/_Orders/Return to nearest city",
-                         !(is_air_unit(punit) || is_heli_unit(punit)));
       menus_set_sensitive("<main>/_Orders/_Disband Unit",
                           !unit_flag(punit, F_UNDISBANDABLE));
       menus_set_sensitive("<main>/_Orders/Diplomat|Spy Actions",
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.26
diff -u -r1.26 menu.c
--- client/gui-gtk-2.0/menu.c   2004/01/20 21:52:07     1.26
+++ client/gui-gtk-2.0/menu.c   2004/01/21 06:22:34
@@ -1175,8 +1175,6 @@
                           can_unit_do_activity(punit, ACTIVITY_EXPLORE));
       menus_set_sensitive("<main>/_Orders/_Connect",
                           can_unit_do_connect(punit, ACTIVITY_IDLE));
-      menus_set_sensitive("<main>/_Orders/Return to nearest city",
-                         !(is_air_unit(punit) || is_heli_unit(punit)));
       menus_set_sensitive("<main>/_Orders/Diplomat\\/Spy Actions",
                           (is_diplomat_unit(punit)
                            && diplomat_can_do_action(punit, 
DIPLOMAT_ANY_ACTION,
Index: client/gui-sdl/menu.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-sdl/menu.c,v
retrieving revision 1.24
diff -u -r1.24 menu.c
--- client/gui-sdl/menu.c       2004/01/20 21:52:07     1.24
+++ client/gui-sdl/menu.c       2004/01/21 06:22:34
@@ -1220,12 +1220,6 @@
        local_hide(ID_UNIT_ORDER_AIRLIFT);
       }
 
-      if (!pTile->city && !is_air_unittype(pUnit->type)) {
-        local_show(ID_UNIT_ORDER_RETURN);
-      } else {
-       local_hide(ID_UNIT_ORDER_RETURN);
-      }
-      
       if (pTile->city && can_upgrade_unittype(game.player_ptr, pUnit->type) != 
-1) {
        local_show(ID_UNIT_ORDER_UPGRADE);
       } else {
Index: client/gui-xaw/menu.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/menu.c,v
retrieving revision 1.59
diff -u -r1.59 menu.c
--- client/gui-xaw/menu.c       2004/01/20 21:52:08     1.59
+++ client/gui-xaw/menu.c       2004/01/21 06:22:34
@@ -375,8 +375,6 @@
                           unit_can_help_build_wonder_here(punit));
       menu_entry_sensitive(MENU_ORDER, MENU_ORDER_TRADEROUTE,
                           unit_can_est_traderoute_here(punit));
-      menu_entry_sensitive(MENU_ORDER, MENU_ORDER_RETURN,
-                          !(is_air_unit(punit) || is_heli_unit(punit)));
       menu_entry_sensitive(MENU_ORDER, MENU_ORDER_DIPLOMAT_DLG,
                           (is_diplomat_unit(punit)
                            && diplomat_can_do_action(punit, 
DIPLOMAT_ANY_ACTION,
Index: common/aicore/pf_tools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/aicore/pf_tools.c,v
retrieving revision 1.11
diff -u -r1.11 pf_tools.c
--- common/aicore/pf_tools.c    2004/01/19 06:01:22     1.11
+++ common/aicore/pf_tools.c    2004/01/21 06:22:35
@@ -99,6 +99,15 @@
   return PF_IMPOSSIBLE_MC;
 }
 
+/*************************************************************
+  A cost function for AIR_MOVING.
+*************************************************************/
+static int airmove(int x, int y, enum direction8 dir,
+                  int x1, int y1, struct pf_parameter *param)
+{
+  return SINGLE_MOVE;
+}
+
 /************************************************************ 
   LAND_MOVE cost function for a unit 
 ************************************************************/
@@ -379,7 +388,31 @@
   return is_ocean(map_get_terrain(x, y)) && !is_coastline(x, y);
 }
 
+/**********************************************************************
+  Position-dangerous callback for air units.
+***********************************************************************/
+static bool air_is_pos_dangerous(int x, int y, enum known_type known,
+                                struct pf_parameter *param)
+{
+  struct tile *ptile = map_get_tile(x, y);
+
+  /* FIXME: bombers with fuel remaining should not worry about danger. */
+
+  if (is_allied_city_tile(ptile, param->owner)) {
+    return FALSE;
+  }
 
+  if (map_has_special(x, y, S_AIRBASE)) {
+    /* All airbases are considered non-dangerous, although non-allied ones
+     * are inaccessible. */
+    return FALSE;
+  }
+
+  /* Carriers are ignored since they are likely to move. */
+  return TRUE;
+}
+
+
 /* =====================  Tools for filling parameters =============== */
 
 /**********************************************************************
@@ -395,6 +428,7 @@
   parameter->owner = unit_owner(punit);
   parameter->unit_flags = unit_type(punit)->flags;
   parameter->omniscience = !ai_handicap(unit_owner(punit), H_MAP);
+  parameter->is_pos_dangerous = NULL;
 
   switch (unit_type(punit)->move_type) {
   case LAND_MOVING:
@@ -411,6 +445,23 @@
       parameter->get_MC = seamove;
     }
     break;
+  case AIR_MOVING:
+    parameter->get_MC = airmove;
+    parameter->is_pos_dangerous = air_is_pos_dangerous;
+    parameter->turn_mode = TM_WORST_TIME;
+    break;
+  case HELI_MOVING:
+    /* Helicoptors are treated similarly to airplanes. */
+    parameter->get_MC = airmove;
+    if (player_owns_active_wonder(unit_owner(punit), B_UNITED)) {
+      /* United nations currently cancels out helicoptor fuel loss. */
+      parameter->is_pos_dangerous = NULL;
+    } else {
+      /* Otherwise, don't risk fuel loss. */
+      parameter->is_pos_dangerous = air_is_pos_dangerous;
+      parameter->turn_mode = TM_WORST_TIME;
+    }
+    break;
   default:
     die("unknown move_type");
   }
@@ -425,9 +476,8 @@
   if (unit_flag(punit, F_TRIREME)
       && base_trireme_loss_pct(unit_owner(punit), punit) > 0) {
     parameter->turn_mode = TM_WORST_TIME;
+    assert(parameter->is_pos_dangerous == NULL);
     parameter->is_pos_dangerous = trireme_is_pos_dangerous;
-  } else {
-    parameter->is_pos_dangerous = NULL;
   }
 }
 

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