[Freeciv-Dev] Re: (PR#3007) return(and recover) for ships
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
On Sat, Feb 15, 2003 at 06:40:20AM -0800, Gregory Berkolaiko wrote:
> Quoting Jason Short via RT <rt@xxxxxxxxxxxxxx>:
>
> > [ue80@xxxxxxxxxxxxxxxxxxxxx - Thu Feb 6 10:15:36 2003]:
> >
> > > 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)
> >
> > The client_goto_map patch has been applied.
> >
> > Can you update this patch with:
>
> Is it possible to wait with the patch? It seems that path-finding is going to
> be committed anytime soon and updating/merging find_nearest_harbour or
> whatever
> would be a good first use for the path-finding.
I didn't change the goto part, but updated things for menu.
Feel free to update the gotopart :-)
> > - Update it to current CVS, if necessary.
Diff against today cvs.
> > - Fix all the freelog() calls. All of the messages should be in
> > English. Make sure the log level (LOG_ERROR versus LOG_DEBUG) is right.
> > LOG_ERROR messages may be translated, if you want.
fixed.
> > - Rename find_closest_owned_port() to find_closest_owned_coastal_city(),
> > or another similar name. The problem is that 'port' has a special
> > significance.
used your suggestion, perhaps i should have used
"find_closest_safe_coastal_city()"
> > - find_closest_owned_coastal_city() should return the current city, if
> > the unit is already in a city (even though the current caller guarantees
> > this won't happen). I'd recommend initializing 'dist' to -1, and
> > comparing to that value instead of to 0 within the loop.
I don't think so. as long we use clostest city + ships we don't need to
check this, there is only a problem with railroad.
Tested with not having a coastal city -> no prob.
Tested in city -> no prob.
If used in allied city the ship won't move, because of the check before,
but normally we would go to the next owned_coastal_city.
> > - gui-gtk-2.0 needs menu sensitivity to be updated just like gui-gtk.
> > You can probably just take a diff of your gui-gtk changes and apply it
> > directly to gui-gtk-2.0.
gui-gtk-2.0 updated.
> > - Except, 'Build road' is not a good menu entry to hide this
> > functionality under! I know you intend this as a feature for veteran
> > players, but that doesn't mean it can't have a good interface. It may
> > be possible to have two menu entries, "Build Road" and "Return/Recover",
> > both of which use 'r' so long as they're never both enabled at the same
> > time. Or it may be possible to rebuild the unit orders menu
> > dynamically, or just to rename that one entry depending on what unit is
> > selected. You may want to leave this up to the GUI authors and just
> > introduce a new menu entry for now, though.
Used the same construction as used for caravan/railroad.
Thomas
Index: client/control.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/control.c,v
retrieving revision 1.94
diff -u -r1.94 control.c
--- client/control.c 2003/02/10 21:43:40 1.94
+++ client/control.c 2003/02/19 15:15:06
@@ -1352,7 +1352,25 @@
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_coastal_city(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/19 15:15:06
@@ -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.46
diff -u -r1.46 goto.c
--- client/goto.c 2003/02/17 02:11:25 1.46
+++ client/goto.c 2003/02/19 15:15:07
@@ -55,6 +55,7 @@
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
@@ -871,6 +872,41 @@
send_packet_goto_route(&aconnection, &p, ROUTE_PATROL);
free(p.pos);
p.pos = NULL;
+}
+
+/**************************************************************************
+This function finds the next own port.
+We don't check if we are already in a city, distance will be 0 then.
+***************************************************************************/
+struct city *find_closest_owned_coastal_city(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.8
diff -u -r1.8 goto.h
--- client/goto.h 2003/02/13 17:03:56 1.8
+++ client/goto.h 2003/02/19 15:15:07
@@ -30,4 +30,7 @@
void send_patrol_route(struct unit *punit);
void send_goto_route(struct unit *punit);
+struct city *find_closest_owned_coastal_city(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/19 15:15:10
@@ -321,8 +321,12 @@
break;
case MENU_ORDER_ROAD:
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)){
+ return_and_recover(punit);
+ }
else
key_unit_road();
}
@@ -1039,6 +1043,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));
@@ -1094,6 +1099,9 @@
if (unit_flag(punit, F_TRADE_ROUTE))
menus_rename("<main>/_Orders/Build _Road", _("Make Trade _Route"));
+ else if (is_sailing_unit(punit)){
+ menus_rename("<main>/_Orders/Build _Road", _("_Return to next City"));
+ }
else if (unit_flag(punit, F_SETTLERS)) {
if (map_has_special(punit->x, punit->y, S_ROAD)) {
roadtext = _("Build _Railroad");
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.13
diff -u -r1.13 menu.c
--- client/gui-gtk-2.0/menu.c 2003/02/13 00:48:45 1.13
+++ client/gui-gtk-2.0/menu.c 2003/02/19 15:15:10
@@ -327,6 +327,9 @@
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())){
+ return_and_recover(get_unit_in_focus());
+ }
else
key_unit_road();
}
@@ -1117,6 +1120,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));
@@ -1172,6 +1176,9 @@
if (unit_flag(punit, F_TRADE_ROUTE))
menus_rename("<main>/_Orders/Build _Road", _("Make Trade _Route"));
+ else if (is_sailing_unit(punit)){
+ menus_rename("<main>/_Orders/Build _Road", _("_Return to next City"));
+ }
else if (unit_flag(punit, F_SETTLERS)) {
if (map_has_special(punit->x, punit->y, S_ROAD)) {
roadtext = _("Build _Railroad");
|
|