edit: Report flags change properly
Print a message, send bulletin to owner. Affects ship key 'W', land unit key 'W', and plane key 'f'. The message is necessary to give the deity a chance to catch unexpected changes, e.g. a player modifying retreat conditions right before the deity edits them. Watching out for such changes is especially important with non-interactive edit. Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
parent
ef2e2d08a2
commit
4aa2f071ba
5 changed files with 86 additions and 1 deletions
|
@ -35,6 +35,7 @@
|
|||
|
||||
#include "item.h"
|
||||
#include "nat.h"
|
||||
#include "types.h"
|
||||
|
||||
extern void report_god_takes(char *, char *, natid);
|
||||
extern void report_god_gives(char *, char *, natid);
|
||||
|
@ -48,6 +49,8 @@ extern void divine_unit_change(struct empobj *, char *, int, int, char *, ...)
|
|||
ATTRIBUTE((format (printf, 5, 6)));
|
||||
#define divine_unit_change_quiet(unit, name, change, ...) \
|
||||
divine_unit_change((unit), (name), -(change), 0, __VA_ARGS__)
|
||||
extern void divine_flag_change(struct empobj *, char *, int, int,
|
||||
struct symbol *);
|
||||
extern void report_divine_gift(natid, struct ichrstr *, int, char *);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
* types.h: Empire types
|
||||
*
|
||||
* Known contributors to this file:
|
||||
* Markus Armbruster, 2006-2011
|
||||
* Markus Armbruster, 2006-2013
|
||||
*/
|
||||
|
||||
#ifndef TYPES_H
|
||||
|
@ -56,6 +56,7 @@ struct range;
|
|||
struct sctstr;
|
||||
struct shiplist;
|
||||
struct shpstr;
|
||||
struct symbol;
|
||||
struct trdstr;
|
||||
struct trtstr;
|
||||
struct comstr;
|
||||
|
|
|
@ -844,6 +844,8 @@ edit_ship(struct shpstr *ship, char *key, char *p)
|
|||
strncpy(ship->shp_rpath, p, sizeof(ship->shp_rpath) - 1);
|
||||
break;
|
||||
case 'W':
|
||||
divine_flag_change((struct empobj *)ship, "Retreat conditions",
|
||||
ship->shp_rflags, arg, retreat_flags);
|
||||
ship->shp_rflags = arg;
|
||||
break;
|
||||
case 'c':
|
||||
|
@ -938,6 +940,8 @@ edit_land(struct lndstr *land, char *key, char *p)
|
|||
strncpy(land->lnd_rpath, p, sizeof(land->lnd_rpath) - 1);
|
||||
break;
|
||||
case 'W':
|
||||
divine_flag_change((struct empobj *)land, "Retreat condition",
|
||||
land->lnd_rflags, arg, retreat_flags);
|
||||
land->lnd_rflags = arg;
|
||||
break;
|
||||
case 'c':
|
||||
|
@ -1025,6 +1029,8 @@ edit_plane(struct plnstr *plane, char *key, char *p)
|
|||
plane->pln_land = arg;
|
||||
break;
|
||||
case 'f':
|
||||
divine_flag_change((struct empobj *)plane, "Flags",
|
||||
plane->pln_flags, arg, plane_flags);
|
||||
plane->pln_flags = arg;
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -175,6 +175,61 @@ divine_unload(struct empobj *unit, int type, int uid)
|
|||
divine_load_unload(unit, type, uid, "unloaded from");
|
||||
}
|
||||
|
||||
static int
|
||||
fmtflags (char *buf, size_t sz, int flags, struct symbol symtab[], int all)
|
||||
{
|
||||
char *sep = "";
|
||||
int n, i;
|
||||
char *p;
|
||||
|
||||
if (sz)
|
||||
buf[0] = 0;
|
||||
n = 0;
|
||||
for (i = 0; i < 32; i++) {
|
||||
if (!(flags & bit(i)))
|
||||
continue;
|
||||
p = symbol_by_value(bit(i), symtab);
|
||||
if (p)
|
||||
n += snprintf(buf + n, sz - n, "%s%s", sep, p);
|
||||
else if (all)
|
||||
n += snprintf(buf + n, sz - n, "%s#%d", sep, i);
|
||||
if (CANT_HAPPEN((size_t)n >= sz)) {
|
||||
buf = NULL;
|
||||
sz = n;
|
||||
}
|
||||
sep = ", ";
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
void
|
||||
divine_flag_change(struct empobj *unit, char *name,
|
||||
int old, int new, struct symbol sym[])
|
||||
{
|
||||
char set[1024], clr[1024];
|
||||
|
||||
if (new == old) {
|
||||
pr("%s of %s unchanged\n", name, unit_nameof(unit));
|
||||
return;
|
||||
}
|
||||
|
||||
fmtflags(set, sizeof(set), new & ~old, sym, 1);
|
||||
fmtflags(clr, sizeof(clr), old & ~new, sym, 1);
|
||||
pr("%s of %s changed: %s%s%s%s%s\n",
|
||||
name, unit_nameof(unit),
|
||||
set, set[0] ? " set" : "",
|
||||
set[0] && clr[0] ? ", and " : "",
|
||||
clr, clr[0] ? " cleared" : "");
|
||||
|
||||
if (fmtflags(set, sizeof(set), new & ~old, sym, 0)
|
||||
+ fmtflags(clr, sizeof(clr), old & ~new, sym, 0))
|
||||
wu(0, unit->own, "%s of %s changed by an act of %s: %s%s%s%s%s\n",
|
||||
name, unit_nameof(unit), cname(player->cnum),
|
||||
set, set[0] ? " set" : "",
|
||||
set[0] && clr[0] ? " and " : "",
|
||||
clr, clr[0] ? " cleared" : "");
|
||||
}
|
||||
|
||||
/*
|
||||
* Report deity giving/taking commodities to/from WHOM.
|
||||
* Give AMT of IP in PLACE.
|
||||
|
|
|
@ -1180,9 +1180,14 @@
|
|||
Play#0 output Play#0 6 0 640
|
||||
Play#0 input edit s 2 W 0 W 1
|
||||
Play#0 command edit
|
||||
Play#0 output Play#0 1 Retreat conditions of cs cargo ship (#2) unchanged
|
||||
Play#0 output Play#0 1 Retreat conditions of cs cargo ship (#2) changed: group set
|
||||
Play#0 output Play#0 6 0 640
|
||||
Play#0 input edit s 3 W 513 W 1030 W 2
|
||||
Play#0 command edit
|
||||
Play#0 output Play#0 1 Retreat conditions of cs cargo ship (#3) changed: group, #9 set
|
||||
Play#0 output Play#0 1 Retreat conditions of cs cargo ship (#3) changed: injured, torped, #10 set, and group, #9 cleared
|
||||
Play#0 output Play#0 1 Retreat conditions of cs cargo ship (#3) changed: torped, #10 cleared
|
||||
Play#0 output Play#0 6 0 640
|
||||
Play#0 input edit u 2 R ""
|
||||
Play#0 command edit
|
||||
|
@ -1192,12 +1197,18 @@
|
|||
Play#0 output Play#0 6 0 640
|
||||
Play#0 input edit u 2 W 0 W 1
|
||||
Play#0 command edit
|
||||
Play#0 output Play#0 1 Retreat condition of sup supply #2 unchanged
|
||||
Play#0 output Play#0 1 Retreat condition of sup supply #2 changed: group set
|
||||
Play#0 output Play#0 6 0 640
|
||||
Play#0 input edit u 3 W 513 W 1030 W 2
|
||||
Play#0 command edit
|
||||
Play#0 output Play#0 1 Retreat condition of sup supply #3 changed: group, #9 set
|
||||
Play#0 output Play#0 1 Retreat condition of sup supply #3 changed: injured, torped, #10 set, and group, #9 cleared
|
||||
Play#0 output Play#0 1 Retreat condition of sup supply #3 changed: torped, #10 cleared
|
||||
Play#0 output Play#0 6 0 640
|
||||
Play#0 input edit p 2 f 4
|
||||
Play#0 command edit
|
||||
Play#0 output Play#0 1 Flags of f1 Sopwith Camel #2 changed: airburst set
|
||||
Play#0 output Play#0 6 0 640
|
||||
Play#0 input edit p 2 s -1 s 9999
|
||||
Play#0 command edit
|
||||
|
@ -1675,6 +1686,9 @@
|
|||
Play#0 output Play#0 1 cs cargo ship (#2) given to you by an act of POGO!
|
||||
Play#0 output Play#0 1 f1 Sopwith Camel #2 given to you by an act of POGO!
|
||||
Play#0 output Play#0 1 sup supply #2 given to you by an act of POGO!
|
||||
Play#0 output Play#0 1 Retreat conditions of cs cargo ship (#2) changed by an act of POGO: group set
|
||||
Play#0 output Play#0 1 Retreat condition of sup supply #2 changed by an act of POGO: group set
|
||||
Play#0 output Play#0 1 Flags of f1 Sopwith Camel #2 changed by an act of POGO: airburst set
|
||||
Play#0 output Play#0 6 0 640
|
||||
Play#0 input read 3
|
||||
Play#0 command read
|
||||
|
@ -1706,6 +1720,12 @@
|
|||
Play#0 output Play#0 1 POGO gave you 50 military in cs cargo ship (#5)
|
||||
Play#0 output Play#0 1 POGO gave you 25 military in sup supply #4
|
||||
Play#0 output Play#0 1 POGO gave you 25 military in sup supply #5
|
||||
Play#0 output Play#0 1 Retreat conditions of cs cargo ship (#3) changed by an act of POGO: group set
|
||||
Play#0 output Play#0 1 Retreat conditions of cs cargo ship (#3) changed by an act of POGO: injured, torped set and group cleared
|
||||
Play#0 output Play#0 1 Retreat conditions of cs cargo ship (#3) changed by an act of POGO: torped cleared
|
||||
Play#0 output Play#0 1 Retreat condition of sup supply #3 changed by an act of POGO: group set
|
||||
Play#0 output Play#0 1 Retreat condition of sup supply #3 changed by an act of POGO: injured, torped set and group cleared
|
||||
Play#0 output Play#0 1 Retreat condition of sup supply #3 changed by an act of POGO: torped cleared
|
||||
Play#0 output Play#0 1 f1 Sopwith Camel #3 loaded onto ship #3 by an act of POGO!
|
||||
Play#0 output Play#0 1 f1 Sopwith Camel #4 loaded onto ship #4 by an act of POGO!
|
||||
Play#0 output Play#0 1 f1 Sopwith Camel #4 unloaded from ship #4 by an act of POGO!
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue