[Freeciv-Dev] caravan orders
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
This patch allows caravan actions (help build wonder, or establish
trade route) for caravans (or freights) already inside cities,
via the orders menu or key commands.
Re-use keys: "b"=(b)uild wonder, "r"=trade (r)oute.
This allows you to use goto into city, and then give a command,
or to stockpile and then use without having to move out and back
in again. (The latter could be considered a rules change, but
I think its reasonable.)
-- David
diff -u -r --exclude-from exclude freeciv-cvs/client/mapctrl.c
freeciv-mod/client/mapctrl.c
--- freeciv-cvs/client/mapctrl.c Sat Feb 13 14:42:27 1999
+++ freeciv-mod/client/mapctrl.c Sat Feb 20 23:43:06 1999
@@ -44,6 +44,7 @@
#include <menu.h>
#include <graphics.h>
#include <colors.h>
+#include <log.h>
extern Display *display;
extern GC fill_tile_gc;
@@ -293,6 +294,28 @@
/**************************************************************************
...
**************************************************************************/
+void request_unit_caravan_action(struct unit *punit, enum packet_type action)
+{
+ struct packet_unit_request req;
+ struct city *pcity = map_get_city(punit->x, punit->y);
+
+ if (!pcity) return;
+ if (!(action==PACKET_UNIT_ESTABLISH_TRADE
+ ||(action==PACKET_UNIT_HELP_BUILD_WONDER))) {
+ freelog(LOG_NORMAL, "Bad action (%d) in request_unit_caravan_action",
+ action);
+ return;
+ }
+
+ req.unit_id = punit->id;
+ req.city_id = pcity->id;
+ req.name[0]='\0';
+ send_packet_unit_request(&aconnection, &req, action);
+}
+
+/**************************************************************************
+...
+**************************************************************************/
void key_unit_disband(Widget w, XEvent *event, String *argv, Cardinal *argc)
{
struct unit *punit=get_unit_in_focus();
@@ -417,8 +440,12 @@
void key_unit_build_city(Widget w, XEvent *event, String *argv, Cardinal *argc)
{
struct unit *punit=get_unit_in_focus();
- if(punit)
+ if (!punit) return;
+ if (unit_flag(punit->type, F_CARAVAN)) {
+ request_unit_caravan_action(punit, PACKET_UNIT_HELP_BUILD_WONDER);
+ } else {
request_unit_build_city(punit);
+ }
}
/**************************************************************************
@@ -539,11 +566,18 @@
**************************************************************************/
void key_unit_road(Widget w, XEvent *event, String *argv, Cardinal *argc)
{
- if(get_unit_in_focus()) {
- if(can_unit_do_activity(punit_focus, ACTIVITY_ROAD))
- request_new_unit_activity(punit_focus, ACTIVITY_ROAD);
- else if(can_unit_do_activity(punit_focus, ACTIVITY_RAILROAD))
- request_new_unit_activity(punit_focus, ACTIVITY_RAILROAD);
+ struct unit *punit=get_unit_in_focus();
+
+ if (!punit) return;
+
+ if (unit_flag(punit->type, F_CARAVAN)) {
+ request_unit_caravan_action(punit, PACKET_UNIT_ESTABLISH_TRADE);
+ }
+ else {
+ if(can_unit_do_activity(punit, ACTIVITY_ROAD))
+ request_new_unit_activity(punit, ACTIVITY_ROAD);
+ else if(can_unit_do_activity(punit, ACTIVITY_RAILROAD))
+ request_new_unit_activity(punit, ACTIVITY_RAILROAD);
}
}
diff -u -r --exclude-from exclude freeciv-cvs/client/mapctrl.h
freeciv-mod/client/mapctrl.h
--- freeciv-cvs/client/mapctrl.h Sat Feb 13 14:42:28 1999
+++ freeciv-mod/client/mapctrl.h Sat Feb 20 23:22:09 1999
@@ -33,6 +33,8 @@
void request_new_unit_activity(struct unit *punit, enum unit_activity act);
+void request_unit_caravan_action(struct unit *punit, enum packet_type action);
+
void butt_down_mapcanvas(Widget w, XEvent *event, String *argv, Cardinal
*argc);
void butt_down_wakeup(Widget w, XEvent *event, String *argv, Cardinal *argc);
void set_unit_focus(struct unit *punit);
diff -u -r --exclude-from exclude freeciv-cvs/client/menu.c
freeciv-mod/client/menu.c
--- freeciv-cvs/client/menu.c Thu Feb 18 18:39:19 1999
+++ freeciv-mod/client/menu.c Sat Feb 20 23:25:02 1999
@@ -79,6 +79,8 @@
MENU_ORDER_GOTO,
MENU_ORDER_GOTO_CITY,
MENU_ORDER_DISBAND,
+ MENU_ORDER_BUILD_WONDER,
+ MENU_ORDER_TRADE_ROUTE,
MENU_ORDER_DONE,
MENU_REPORT_CITY,
@@ -159,6 +161,8 @@
{ "Disband Unit D", MENU_ORDER_DISBAND, 0},
{ "Pillage P", MENU_ORDER_PILLAGE, 0},
{ "Auto-explore x", MENU_ORDER_EXPLORE, 0},
+ { "Help Build Wonder B", MENU_ORDER_BUILD_WONDER, 0},
+ { "Make Trade Route R", MENU_ORDER_TRADE_ROUTE, 0},
{ "Done spc", MENU_ORDER_DONE, 0},
{ 0, MENU_END_OF_LIST, 0}
};
@@ -294,6 +298,10 @@
menu_entry_sensitive(orders_menu, MENU_ORDER_WAKEUP,
is_unit_activity_on_tile(ACTIVITY_SENTRY,
punit->x,punit->y));
+ menu_entry_sensitive(orders_menu, MENU_ORDER_BUILD_WONDER,
+ unit_can_help_build_wonder_here(punit));
+ menu_entry_sensitive(orders_menu, MENU_ORDER_TRADE_ROUTE,
+ unit_can_est_traderoute_here(punit));
switch(map_get_tile(punit->x, punit->y)->terrain) {
case T_ARCTIC:
@@ -497,6 +505,16 @@
case MENU_ORDER_EXPLORE:
if(get_unit_in_focus())
request_new_unit_activity(get_unit_in_focus(), ACTIVITY_EXPLORE);
+ break;
+ case MENU_ORDER_BUILD_WONDER:
+ if(get_unit_in_focus())
+ request_unit_caravan_action(get_unit_in_focus(),
+ PACKET_UNIT_HELP_BUILD_WONDER);
+ break;
+ case MENU_ORDER_TRADE_ROUTE:
+ if(get_unit_in_focus())
+ request_unit_caravan_action(get_unit_in_focus(),
+ PACKET_UNIT_ESTABLISH_TRADE);
break;
case MENU_ORDER_DONE:
if(get_unit_in_focus())
diff -u -r --exclude-from exclude freeciv-cvs/common/unit.c
freeciv-mod/common/unit.c
--- freeciv-cvs/common/unit.c Sat Feb 13 14:42:37 1999
+++ freeciv-mod/common/unit.c Sat Feb 20 23:28:50 1999
@@ -197,12 +197,38 @@
**************************************************************************/
int unit_can_help_build_wonder(struct unit *punit, struct city *pcity)
{
- return is_tiles_adjacent(punit->x, punit->y, pcity->x, pcity->y) &&
+ return unit_flag(punit->type, F_CARAVAN) &&
+ is_tiles_adjacent(punit->x, punit->y, pcity->x, pcity->y) &&
punit->owner==pcity->owner && !pcity->is_building_unit &&
is_wonder(pcity->currently_building) &&
(pcity->shield_stock < improvement_value(pcity->currently_building));
}
+
+/**************************************************************************
+...
+**************************************************************************/
+int unit_can_help_build_wonder_here(struct unit *punit)
+{
+ struct city *pcity = map_get_city(punit->x, punit->y);
+ return pcity && unit_can_help_build_wonder(punit, pcity);
+}
+
+
+/**************************************************************************
+...
+**************************************************************************/
+int unit_can_est_traderoute_here(struct unit *punit)
+{
+ struct city *phomecity, *pdestcity;
+
+ if (!unit_flag(punit->type, F_CARAVAN)) return 0;
+ pdestcity = map_get_city(punit->x, punit->y);
+ if (!pdestcity) return 0;
+ phomecity = find_city_by_id(punit->homecity);
+ if (!phomecity) return 0;
+ return can_establish_trade_route(phomecity, pdestcity);
+}
/**************************************************************************
...
diff -u -r --exclude-from exclude freeciv-cvs/common/unit.h
freeciv-mod/common/unit.h
--- freeciv-cvs/common/unit.h Sat Feb 13 14:42:37 1999
+++ freeciv-mod/common/unit.h Sat Feb 20 23:36:14 1999
@@ -246,6 +246,8 @@
int unit_move_rate(struct unit *punit);
int unit_can_help_build_wonder(struct unit *punit, struct city *pcity);
+int unit_can_help_build_wonder_here(struct unit *punit);
+int unit_can_est_traderoute_here(struct unit *punit);
int unit_can_defend_here(struct unit *punit);
int unit_can_airlift_to(struct unit *punit, struct city *pcity);
diff -u -r --exclude-from exclude freeciv-cvs/data/helpdata.txt
freeciv-mod/data/helpdata.txt
--- freeciv-cvs/data/helpdata.txt Sat Feb 20 16:11:21 1999
+++ freeciv-mod/data/helpdata.txt Sat Feb 20 23:37:49 1999
@@ -352,6 +352,7 @@
A: (A)uto-attack (military units) space: Unit stay put
c: (C)enter view on unit return: Turn done
b: (B)uild City
+ B: Help (B)uild Wonder
D: (D)isband unit
f: (F)ortify unit
F: Build (F)ortress on tile
@@ -364,6 +365,7 @@
p: clean (p)ollution
P: (P)illage tile
r: Build (r)oad/railroad
+ R: Establish trade(R)oute
s: (S)entry unit
u: (U)nload boat
w: (W)ait until later in turn
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] caravan orders,
David Pfitzner <=
|
|