[Freeciv-Dev] (PR#9662) activities as orders
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://rt.freeciv.org/Ticket/Display.html?id=9662 >
This patch allows orders to include some activities.
This is basically the server part of the connect-as-orders patch
(PR#7282), with connect left unchanged and some other simple activities
added in. It's pretty straightforward but not that easy to test without
adding lots of code elsewhere.
It's also much like the activities part of Arnstein's extended-orders
patch (PR#6941?).
The only thing I'm not sure of is backwards-compatability of savegames.
jason
? new
? orig
Index: client/goto.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/goto.c,v
retrieving revision 1.70
diff -u -r1.70 goto.c
--- client/goto.c 21 Jun 2004 15:14:43 -0000 1.70
+++ client/goto.c 10 Aug 2004 17:21:28 -0000
@@ -548,6 +548,7 @@
} else {
p.orders[i] = ORDER_MOVE;
p.dir[i] = get_direction_for_step(old_x, old_y, new_x, new_y);
+ p.activity[i] = ACTIVITY_LAST;
freelog(PACKET_LOG_LEVEL, " packet[%d] = move %s: %d,%d => %d,%d",
i, dir_get_name(p.dir[i]), old_x, old_y, new_x, new_y);
}
Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.393
diff -u -r1.393 packhand.c
--- client/packhand.c 2 Aug 2004 16:59:14 -0000 1.393
+++ client/packhand.c 10 Aug 2004 17:21:29 -0000
@@ -126,6 +126,7 @@
for (i = 0; i < punit->orders.length; i++) {
punit->orders.list[i].order = packet->orders[i];
punit->orders.list[i].dir = packet->orders_dirs[i];
+ punit->orders.list[i].activity = packet->orders_activities[i];
}
}
return punit;
Index: common/capstr.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/capstr.c,v
retrieving revision 1.175
diff -u -r1.175 capstr.c
--- common/capstr.c 30 Jul 2004 20:40:49 -0000 1.175
+++ common/capstr.c 10 Aug 2004 17:21:29 -0000
@@ -78,7 +78,7 @@
"+change_production +tilespec1 +no_earth +trans " \
"+want_hack invasions bombard +killstack2 spec +spec2 " \
"+city_map startunits +turn_last_built +happyborders " \
- "+connid +love"
+ "+connid +love +orders3"
/* "+1.14.delta" is the new delta protocol for 1.14.0-dev.
*
@@ -136,6 +136,8 @@
* info sent to clients.
*
* "love" means that we show the AI love for you in the client
+ *
+ * "orders3" gives some additional orders that can be given
*/
void init_our_capability(void)
Index: common/map.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.h,v
retrieving revision 1.203
diff -u -r1.203 map.h
--- common/map.h 5 Aug 2004 10:41:34 -0000 1.203
+++ common/map.h 10 Aug 2004 17:21:29 -0000
@@ -575,6 +575,7 @@
struct unit_order {
enum unit_orders order;
enum direction8 dir; /* Only valid for ORDER_MOVE. */
+ enum unit_activity activity; /* Only valid for ORDER_ACTIVITY. */
};
/* return the reverse of the direction */
Index: common/packets.def
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.def,v
retrieving revision 1.36
diff -u -r1.36 packets.def
--- common/packets.def 30 Jul 2004 20:40:49 -0000 1.36
+++ common/packets.def 10 Aug 2004 17:21:29 -0000
@@ -621,6 +621,7 @@
BOOL orders_repeat, orders_vigilant;
ORDERS orders[MAX_LEN_ROUTE:orders_length];
DIRECTION orders_dirs[MAX_LEN_ROUTE:orders_length];
+ ACTIVITY orders_activities[MAX_LEN_ROUTE:orders_length];
end
PACKET_UNIT_SHORT_INFO=50; is-info,sc,lsend
@@ -692,6 +693,7 @@
BOOL repeat, vigilant;
ORDERS orders[MAX_LEN_ROUTE:length];
DIRECTION dir[MAX_LEN_ROUTE:length];
+ ACTIVITY activity[MAX_LEN_ROUTE:length];
COORD dest_x, dest_y;
end
Index: common/unit.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unit.h,v
retrieving revision 1.121
diff -u -r1.121 unit.h
--- common/unit.h 2 Aug 2004 16:59:14 -0000 1.121
+++ common/unit.h 10 Aug 2004 17:21:29 -0000
@@ -41,7 +41,7 @@
/* Changing this enum will break savegame and network compatability. */
enum unit_orders {
- ORDER_MOVE, ORDER_FINISH_TURN,
+ ORDER_MOVE, ORDER_FINISH_TURN, ORDER_ACTIVITY,
ORDER_LAST
};
Index: server/savegame.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/savegame.c,v
retrieving revision 1.175
diff -u -r1.175 savegame.c
--- server/savegame.c 8 Aug 2004 15:09:12 -0000 1.175
+++ server/savegame.c 10 Aug 2004 17:21:30 -0000
@@ -1252,7 +1252,7 @@
int len = secfile_lookup_int_default(file, 0,
"player%d.u%d.orders_length", plrno, i);
if (len > 0) {
- char *orders_buf, *dir_buf;
+ char *orders_buf, *dir_buf, *act_buf;
punit->orders.list = fc_malloc(len * sizeof(*(punit->orders.list)));
punit->orders.length = len;
@@ -1267,14 +1267,18 @@
"player%d.u%d.orders_list", plrno, i);
dir_buf = secfile_lookup_str_default(file, "",
"player%d.u%d.dir_list", plrno, i);
+ act_buf = secfile_lookup_str_default(file, "",
+ "player%d.u%d.activity_list", plrno, i);
for (j = 0; j < len; j++) {
- if (orders_buf[j] == '\0' || dir_buf == '\0') {
+ if (orders_buf[j] == '\0' || dir_buf == '\0'
+ || act_buf[j] == '\0') {
freelog(LOG_ERROR, _("Savegame error: invalid unit orders."));
free_unit_orders(punit);
break;
}
punit->orders.list[j].order = orders_buf[j] - 'a';
punit->orders.list[j].dir = dir_buf[j] - 'a';
+ punit->orders.list[j].activity = act_buf[j] - 'a';
}
punit->has_orders = TRUE;
} else {
@@ -2286,7 +2290,7 @@
"player%d.u%d.transported_by", plrno, i);
if (punit->has_orders) {
int len = punit->orders.length, j;
- char orders_buf[len + 1], dir_buf[len + 1];
+ char orders_buf[len + 1], dir_buf[len + 1], act_buf[len + 1];
secfile_insert_int(file, len, "player%d.u%d.orders_length", plrno, i);
secfile_insert_int(file, punit->orders.index,
@@ -2299,13 +2303,16 @@
for (j = 0; j < len; j++) {
orders_buf[j] = 'a' + punit->orders.list[j].order;
dir_buf[j] = 'a' + punit->orders.list[j].dir;
+ act_buf[j] = 'a' + punit->orders.list[j].activity;
}
- orders_buf[len] = dir_buf[len] = '\0';
+ orders_buf[len] = dir_buf[len] = act_buf[len] = '\0';
secfile_insert_str(file, orders_buf,
"player%d.u%d.orders_list", plrno, i);
secfile_insert_str(file, dir_buf,
"player%d.u%d.dir_list", plrno, i);
+ secfile_insert_str(file, act_buf,
+ "player%d.u%d.activity_list", plrno, i);
} else {
/* Put all the same fields into the savegame. Otherwise the
* registry code gets confused (although it still works). */
Index: server/unithand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/unithand.c,v
retrieving revision 1.301
diff -u -r1.301 unithand.c
--- server/unithand.c 8 Aug 2004 14:15:14 -0000 1.301
+++ server/unithand.c 10 Aug 2004 17:21:30 -0000
@@ -1626,6 +1626,28 @@
return;
}
break;
+ case ORDER_ACTIVITY:
+ switch (packet->activity[i]) {
+ case ACTIVITY_POLLUTION:
+ case ACTIVITY_ROAD:
+ case ACTIVITY_MINE:
+ case ACTIVITY_IRRIGATE:
+ case ACTIVITY_FORTRESS:
+ case ACTIVITY_RAILROAD:
+ case ACTIVITY_TRANSFORM:
+ case ACTIVITY_AIRBASE:
+ /* Simple activities. */
+ break;
+ case ACTIVITY_SENTRY:
+ if (i != packet->length - 1) {
+ /* Only allowed as the last order. */
+ return;
+ }
+ break;
+ default:
+ return;
+ }
+ break;
case ORDER_FINISH_TURN:
break;
default:
@@ -1653,6 +1675,7 @@
for (i = 0; i < packet->length; i++) {
punit->orders.list[i].order = packet->orders[i];
punit->orders.list[i].dir = packet->dir[i];
+ punit->orders.list[i].activity = packet->activity[i];
}
if (!packet->repeat) {
Index: server/unittools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/unittools.c,v
retrieving revision 1.297
diff -u -r1.297 unittools.c
--- server/unittools.c 6 Aug 2004 14:46:28 -0000 1.297
+++ server/unittools.c 10 Aug 2004 17:21:31 -0000
@@ -1854,6 +1854,7 @@
for (i = 0; i < punit->orders.length; i++) {
packet->orders[i] = punit->orders.list[i].order;
packet->orders_dirs[i] = punit->orders.list[i].dir;
+ packet->orders_activities[i] = punit->orders.list[i].activity;
}
} else {
packet->orders_length = packet->orders_index = 0;
@@ -2927,9 +2928,16 @@
int unitid = punit->id;
struct player *pplayer = unit_owner(punit);
int moves_made = 0;
+ enum unit_activity activity;
assert(unit_has_orders(punit));
+ if (punit->activity != ACTIVITY_IDLE) {
+ /* Unit's in the middle of an activity; wait for it to finish. */
+ punit->done_moving = TRUE;
+ return TRUE;
+ }
+
freelog(LOG_DEBUG, "Executing orders for %s %d",
unit_name(punit->type), punit->id);
@@ -2989,6 +2997,20 @@
freelog(LOG_DEBUG, " waiting this turn");
send_unit_info(NULL, punit);
break;
+ case ORDER_ACTIVITY:
+ activity = order.activity;
+ if (!can_unit_do_activity(punit, activity)) {
+ cancel_orders(punit, " orders canceled because of failed activity");
+ notify_player_ex(pplayer, punit->x, punit->y, E_UNIT_ORDERS,
+ _("Game: Orders for %s aborted since they "
+ "give an invalid activity."),
+ unit_name(punit->type));
+ return TRUE;
+ }
+ punit->done_moving = TRUE;
+ set_unit_activity(punit, activity);
+ send_unit_info(NULL, punit);
+ break;
case ORDER_MOVE:
/* Move unit */
if (!MAPSTEP(dest_x, dest_y, punit->x, punit->y, order.dir)) {
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#9662) activities as orders,
Jason Short <=
|
|