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

[Freeciv-Dev] (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] (PR#4684) client-side air goto
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 25 Jul 2003 02:39:48 -0700
Reply-to: rt@xxxxxxxxxxxxxx

Attached is an attempt at client-side air goto.

Problem:

- How can PF deal with helicoptors?  In the patch they stay as 
server-side goto.  But dealing with them badly shouldn't be too hard.

- Trying to set a waypoint at a dangerous location gives a PF segfault. 
  I couldn't make anything of it.

- Trying to goto a dangerous location fails.  I think by default we 
should have a special case: we should be allowed to end at a dangerous 
location if explicitly specified.  We just shouldn't be allowed to stop 
at one "overnight".

- Air patrolling also works, but because of the above you can only 
patrol between cities.

- I'm not sure how to decide which airbases are safe and which aren't.

- What about non-attack air units?

Once all gotos use client-side goto we should drop the draw_goto_line 
client variable, then the GOTO_TILE packet itself.  A fair amount of 
code can be removed.

The patch requires and includes PR#4683.

Also attached is a ruleset patch to make fighters, bombers, and 
helicopters easy to build.  I've only really tested with fighters.

jason

Index: client/control.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/control.c,v
retrieving revision 1.107
diff -u -r1.107 control.c
--- client/control.c    2003/07/23 13:46:01     1.107
+++ client/control.c    2003/07/25 09:33:20
@@ -596,14 +596,14 @@
   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)) {
+    /* Not yet implemented for helicopters. */
+    if (is_heli_unit(punit)) {
       draw_goto_line = FALSE;
     } else {
       enter_goto_state(punit);
       create_line_at_mouse_pos();
     }
-  } else if (!is_air_unit(punit)) {
+  } else {
     assert(goto_is_active());
     goto_add_waypoint();
   }
@@ -929,8 +929,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)) {
+    /* Not yet implemented for helicopters. */
+    if (is_heli_unit(punit)) {
       draw_goto_line = FALSE;
     } else {
       enter_goto_state(punit);
@@ -1430,18 +1430,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: common/aicore/pf_tools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/aicore/pf_tools.c,v
retrieving revision 1.5
diff -u -r1.5 pf_tools.c
--- common/aicore/pf_tools.c    2003/07/21 19:01:01     1.5
+++ common/aicore/pf_tools.c    2003/07/25 09:33:20
@@ -77,6 +77,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 
   Must put owner into *data.
@@ -279,6 +288,17 @@
   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)
+{
+  /* FIXME: enemy airbases aren't safe. */
+  return (!is_allied_city_tile(map_get_tile(x, y), param->owner)
+         && !map_has_special(x, y, S_AIRBASE));
+}
+
 
 /* =====================  Tools for filling parameters =============== */
 
@@ -295,6 +315,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:
@@ -311,6 +332,11 @@
       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;
   default:
     die("unknown move_type");
   }
@@ -325,9 +351,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;
   }
 }
 
Index: server/unittools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/unittools.c,v
retrieving revision 1.236
diff -u -r1.236 unittools.c
--- server/unittools.c  2003/07/24 16:52:28     1.236
+++ server/unittools.c  2003/07/25 09:33:20
@@ -3010,7 +3010,16 @@
     /* Move unit */
     last_tile = (((index + 1) % pgr->length) == (pgr->last_index));
     freelog(LOG_DEBUG, "handling\n");
-    res = handle_unit_move_request(punit, x, y, FALSE, !last_tile);
+    if (same_pos(punit->x, punit->y, x, y)) {
+      /* Wait here.  This can be an important part of a goto route, e.g.
+       * for tririemes.  FIXME: we shouldn't lose the movepoints but should
+       * instead return GR_WAITING and just sit tight. */
+      res = TRUE;
+      punit->moves_left = 0;
+      send_unit_info_to_onlookers(NULL, punit, punit->x, punit->y, FALSE);
+    } else {
+      res = handle_unit_move_request(punit, x, y, FALSE, !last_tile);
+    }
 
     if (!player_find_unit_by_id(pplayer, unitid)) {
       return GR_DIED;
Index: data/default/units.ruleset
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/default/units.ruleset,v
retrieving revision 1.47
diff -u -r1.47 units.ruleset
--- data/default/units.ruleset  2003/06/14 13:20:51     1.47
+++ data/default/units.ruleset  2003/07/25 09:32:47
@@ -948,7 +948,7 @@
 [unit_fighter]
 name          = _("Fighter")
 move_type     = "Air"
-tech_req      = "Flight"
+tech_req      = "None"
 obsolete_by   = "Stealth Fighter"
 graphic       = "u.fighter"
 graphic_alt   = "-"
@@ -956,7 +956,7 @@
 sound_move_alt = "m_generic"
 sound_fight   = "f_fighter"
 sound_fight_alt = "f_generic"
-build_cost    = 60
+build_cost    = 10
 pop_cost      = 0
 attack        = 4
 defense       = 3
@@ -976,7 +976,7 @@
 [unit_bomber]
 name          = _("Bomber")
 move_type     = "Air"
-tech_req      = "Advanced Flight"
+tech_req      = "None"
 obsolete_by   = "Stealth Bomber"
 graphic       = "u.bomber"
 graphic_alt   = "-"
@@ -984,7 +984,7 @@
 sound_move_alt = "m_generic"
 sound_fight   = "f_bomber"
 sound_fight_alt = "f_generic"
-build_cost    = 120
+build_cost    = 20
 pop_cost      = 0
 attack        = 12
 defense       = 1
@@ -1004,7 +1004,7 @@
 [unit_helicopter]
 name          = _("Helicopter")
 move_type     = "Heli"
-tech_req      = "Combined Arms"
+tech_req      = "None"
 obsolete_by   = "None"
 graphic       = "u.helicopter"
 graphic_alt   = "-"
@@ -1012,7 +1012,7 @@
 sound_move_alt = "m_generic"
 sound_fight   = "f_helicopter"
 sound_fight_alt = "f_generic"
-build_cost    = 100
+build_cost    = 15
 pop_cost      = 0
 attack        = 10
 defense       = 3

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