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

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

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] client-side air goto (PR#4684)
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 7 Oct 2003 13:57:22 -0700
Reply-to: rt@xxxxxxxxxxxxxx

Here's a somewhat improved client-side air goto patch.

Now that pauses work for client-side goto, things work better.  However, 
there are still substantial problems:

1.  What should be done about helicoptors?  Currently they're treated 
just like fighters, unless the player has United Nations in which case 
no positions are marked dangerous.

2.  How can we handle fuel?  Currently bombers are treated just like 
fighters, and I see no way to change this without core PF changes.

Note that the draw_goto_line variable is no longer necessary, although 
it is not removed in this patch.

jason

Index: client/control.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/control.c,v
retrieving revision 1.115
diff -u -r1.115 control.c
--- client/control.c    2003/10/07 18:55:08     1.115
+++ client/control.c    2003/10/07 20:50:08
@@ -602,14 +602,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();
   }
@@ -671,11 +666,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);
@@ -936,13 +926,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();
@@ -1451,18 +1436,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.79
diff -u -r1.79 menu.c
--- client/gui-gtk/menu.c       2003/09/15 16:05:35     1.79
+++ client/gui-gtk/menu.c       2003/10/07 20:50:08
@@ -1148,8 +1148,6 @@
                           can_unit_do_connect(punit, ACTIVITY_IDLE));
       menus_set_sensitive("<main>/_Orders/Patrol (_Q)",
                           can_unit_do_activity(punit, ACTIVITY_PATROL));
-      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.23
diff -u -r1.23 menu.c
--- client/gui-gtk-2.0/menu.c   2003/09/15 16:05:35     1.23
+++ client/gui-gtk-2.0/menu.c   2003/10/07 20:50:08
@@ -1169,8 +1169,6 @@
                           can_unit_do_connect(punit, ACTIVITY_IDLE));
       menus_set_sensitive("<main>/_Orders/Patrol (_Q)",
                           can_unit_do_activity(punit, ACTIVITY_PATROL));
-      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.23
diff -u -r1.23 menu.c
--- client/gui-sdl/menu.c       2003/10/02 21:37:44     1.23
+++ client/gui-sdl/menu.c       2003/10/07 20:50:08
@@ -1226,12 +1226,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.57
diff -u -r1.57 menu.c
--- client/gui-xaw/menu.c       2003/09/15 16:05:35     1.57
+++ client/gui-xaw/menu.c       2003/10/07 20:50:08
@@ -376,8 +376,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.8
diff -u -r1.8 pf_tools.c
--- common/aicore/pf_tools.c    2003/09/21 09:06:43     1.8
+++ common/aicore/pf_tools.c    2003/10/07 20:50:08
@@ -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,6 +388,30 @@
   return map_get_terrain(x, y) == T_OCEAN && !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)) > 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]
  • [Freeciv-Dev] client-side air goto (PR#4684), Jason Short <=