Complete.Org: Mailing Lists: Archives: freeciv-dev: February 2003:
[Freeciv-Dev] (PR#3007) return(and recover) for ships
Home

[Freeciv-Dev] (PR#3007) return(and recover) for ships

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients:;
Subject: [Freeciv-Dev] (PR#3007) return(and recover) for ships
From: "ue80@xxxxxxxxxxxxxxxxxxxxx via RT" <rt@xxxxxxxxxxxxxx>
Date: Thu, 6 Feb 2003 02:15:36 -0800
Reply-to: rt.freeciv.org@xxxxxxxxxxxxxx

Hi,

this is a part from iuz_warclient. With pressing "r" a ship will return
to the nearest own harbour. 
The only difference to the orginal is that i'm using the new
client_goto_map. (Hope that patch is applying)

Thomas
-- 
Thomas Strub  ***  eMail ue80@xxxxxxxxxxxxxxxxxxxxx
Wenn Du nicht programmieren kannst und Dir für Arbeit zu schade bist:
Werde Berater, Analyst oder organisiere Kongresse.

Index: client/control.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/control.c,v
retrieving revision 1.93
diff -u -r1.93 control.c
--- client/control.c    2003/02/05 07:23:47     1.93
+++ client/control.c    2003/02/06 09:48:10
@@ -1351,7 +1351,24 @@
 
   set_hover_state(NULL, HOVER_NONE);
 }
- 
+
+/**************************************************************************
+ Send ship to closest port and Sentry
+**************************************************************************/
+void return_and_recover(struct unit *punit)
+{
+  if (!map_get_city(punit->x, punit->y)){ 
+  struct city *pcity = find_closest_owned_port(punit, NULL);
+    if (pcity) {
+  /* For recover, after other parts of warclient are applied
+   *   if (punit->activity == ACTIVITY_GOTO)
+   *     bg_un_target_tile(punit);
+   *   punit->mission_flag = TRUE;
+   *   punit->orders = ORDERS_SENTRY;  */
+      send_goto_unit(punit, pcity->x, pcity->y);
+    }
+  }
+}
+
 /**************************************************************************
 ...
 **************************************************************************/
Index: client/control.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/control.h,v
retrieving revision 1.32
diff -u -r1.32 control.h
--- client/control.h    2003/02/05 07:23:47     1.32
+++ client/control.h    2003/02/06 09:48:10
@@ -29,6 +29,8 @@
 extern bool draw_goto_line;
 extern bool non_ai_unit_focus;
 
+void return_and_recover(struct unit *punit);
+
 void do_move_unit(struct unit *punit, struct packet_unit_info *pinfo);
 void do_unit_goto(int x, int y);
 void do_unit_nuke(struct unit *punit);
Index: client/goto.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/goto.c,v
retrieving revision 1.44
diff -u -r1.44 goto.c
--- client/goto.c       2003/01/09 02:36:36     1.44
+++ client/goto.c       2003/02/06 09:48:10
@@ -30,8 +30,32 @@
 static void undraw_line(void);
 static unsigned char *get_drawn_char(int x, int y, int dir);
+static int find_goto_distance(struct unit *punit, struct city *pcity);
 
 /**************************************************************************
 Various stuff for the goto routes
@@ -865,6 +872,39 @@
   send_packet_goto_route(&aconnection, &p, ROUTE_PATROL);
   free(p.pos);
   p.pos = NULL;
+}
+
+/**************************************************************************
+This function finds the next own port.
+***************************************************************************/
+struct city *find_closest_owned_port(struct unit *punit, struct city *except)
+{
+  int check = -1;
+  int dist = 0;
+  struct city *rcity = NULL;
+
+  city_list_iterate(game.player_ptr->cities, pcity) {
+    if (is_terrain_near_tile(pcity->x, pcity->y, T_OCEAN)
+      && (!except || pcity != except))
+        dist = find_goto_distance(punit, pcity);
+
+    if (dist && (dist < check || check == -1)) {
+      check = dist;
+      rcity = pcity;
+    }
+  }
+  city_list_iterate_end;
+
+  return rcity;
+}
+
+/**************************************************************************
+Ideally, this should return the goto distance for punit to pcity.
+***************************************************************************/
+int find_goto_distance(struct unit *punit, struct city *pcity)
+{ 
+  create_goto_map(punit, punit->x, punit->y, GOTO_MOVE_ANY);
+  return MOVE_COST(pcity->x, pcity->y);  
 }
 
 /**********************************************************************
Index: client/goto.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/goto.h,v
retrieving revision 1.7
diff -u -r1.7 goto.h
--- client/goto.h       2002/12/06 22:25:12     1.7
+++ client/goto.h       2003/02/06 06:55:10
@@ -39,5 +29,7 @@
 
 void send_patrol_route(struct unit *punit);
 void send_goto_route(struct unit *punit);
+
+struct city *find_closest_owned_port(struct unit *punit, struct city *except);
 
 #endif /* FC__GOTO_H */
Index: client/gui-gtk/menu.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/menu.c,v
retrieving revision 1.72
diff -u -r1.72 menu.c
--- client/gui-gtk/menu.c       2003/01/01 11:51:33     1.72
+++ client/gui-gtk/menu.c       2003/02/06 09:48:30
@@ -320,9 +320,15 @@
     }
     break;
    case MENU_ORDER_ROAD:
+    freelog(LOG_ERROR,"Zeig 1dich");
     if (get_unit_in_focus()) {
-      if (unit_can_est_traderoute_here(get_unit_in_focus()))
+      struct unit *punit = get_unit_in_focus();
+      if (unit_can_est_traderoute_here(punit))
        key_unit_traderoute();
+      else if (is_sailing_unit(punit)){
+        freelog(LOG_ERROR,"Zeig dich");
+        return_and_recover(punit);
+      }
       else
        key_unit_road();
     }
@@ -1039,6 +1045,7 @@
       menus_set_sensitive("<main>/_Orders/Build _Road",
                           (can_unit_do_activity(punit, ACTIVITY_ROAD) ||
                            can_unit_do_activity(punit, ACTIVITY_RAILROAD) ||
+                          is_sailing_unit(punit) ||
                            unit_can_est_traderoute_here(punit)));
       menus_set_sensitive("<main>/_Orders/Build _Irrigation",
                           can_unit_do_activity(punit, ACTIVITY_IRRIGATE));
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.12
diff -u -r1.12 menu.c
--- client/gui-gtk-2.0/menu.c   2003/01/31 23:31:19     1.12
+++ client/gui-gtk-2.0/menu.c   2003/02/06 09:48:49
@@ -324,6 +324,10 @@
     if (get_unit_in_focus()) {
       if (unit_can_est_traderoute_here(get_unit_in_focus()))
        key_unit_traderoute();
+      else if (is_sailing_unit(get_unit_in_focus())){
+        freelog(LOG_ERROR,"Zeig dich");
+        return_and_recover(get_unit_in_focus());
+      }
       else
        key_unit_road();
     }

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