forked from github/server
remove UFL_OWNER anywhere but in save.c
This commit is contained in:
parent
e501ed5bbd
commit
0c2531f259
13 changed files with 52 additions and 62 deletions
|
@ -658,22 +658,28 @@ int give_control_cmd(unit * u, order * ord)
|
|||
|
||||
/* first, do all the ones that do not require HELP_GIVE or CONTACT */
|
||||
if (p == P_CONTROL) {
|
||||
message *msg;
|
||||
message *msg = 0;
|
||||
|
||||
if (!u2 || u2->number == 0) {
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "feedback_unit_not_found",
|
||||
""));
|
||||
msg = msg_feedback(u, ord, "feedback_unit_not_found", "");
|
||||
ADDMSG(&u->faction->msgs, msg);
|
||||
} else if (!u->building && !u->ship) {
|
||||
cmistake(u, ord, 140, MSG_EVENT);
|
||||
} else if (u->building && u2->building != u->building) {
|
||||
cmistake(u, ord, 33, MSG_EVENT);
|
||||
} else if (u->ship && u2->ship != u->ship) {
|
||||
cmistake(u, ord, 32, MSG_EVENT);
|
||||
} else if (!fval(u, UFL_OWNER)) {
|
||||
cmistake(u, ord, 49, MSG_EVENT);
|
||||
} else {
|
||||
msg = cmistake(u, ord, 140, MSG_EVENT);
|
||||
} else if (u->building) {
|
||||
if (u!=building_owner(u->building)) {
|
||||
msg = cmistake(u, ord, 49, MSG_EVENT);
|
||||
} else if (u2->building != u->building) {
|
||||
msg = cmistake(u, ord, 33, MSG_EVENT);
|
||||
}
|
||||
} else if (u->ship) {
|
||||
if (u!=ship_owner(u->ship)) {
|
||||
msg = cmistake(u, ord, 49, MSG_EVENT);
|
||||
} else if (u2->ship != u->ship) {
|
||||
msg = cmistake(u, ord, 32, MSG_EVENT);
|
||||
}
|
||||
}
|
||||
if (!msg) {
|
||||
give_control(u, u2);
|
||||
|
||||
msg = msg_message("givecommand", "unit recipient", u, u2);
|
||||
add_message(&u->faction->msgs, msg);
|
||||
if (u->faction != u2->faction) {
|
||||
|
|
|
@ -2876,7 +2876,7 @@ static void reorder(void)
|
|||
id = getid();
|
||||
v = findunit(id);
|
||||
|
||||
if (v == NULL || v->faction != u->faction || v->region != r) {
|
||||
if (!v || v->faction != u->faction || v->region != r) {
|
||||
cmistake(u, ord, 258, MSG_EVENT);
|
||||
} else if (v->building != u->building || v->ship != u->ship) {
|
||||
cmistake(u, ord, 259, MSG_EVENT);
|
||||
|
|
|
@ -627,11 +627,7 @@ const char *buildingname(const building * b)
|
|||
void building_set_owner(struct building *b, struct unit * owner)
|
||||
{
|
||||
assert(b && owner && owner->building==b);
|
||||
if (b->_owner && b->_owner!=owner) {
|
||||
freset(b->_owner, UFL_OWNER);
|
||||
}
|
||||
b->_owner = owner;
|
||||
fset(owner, UFL_OWNER);
|
||||
}
|
||||
|
||||
static unit *building_owner_ex(const building * bld, const faction * last_owner)
|
||||
|
@ -651,7 +647,6 @@ static unit *building_owner_ex(const building * bld, const faction * last_owner)
|
|||
heir = u; /* you'll do in an emergency */
|
||||
}
|
||||
}
|
||||
freset(u, UFL_OWNER);
|
||||
}
|
||||
}
|
||||
return heir;
|
||||
|
|
|
@ -156,7 +156,6 @@ static void test_buildingowner_goes_to_same_faction_when_empty(CuTest * tc)
|
|||
u_set_building(u2, bld);
|
||||
u_set_building(u3, bld);
|
||||
CuAssertPtrEquals(tc, u, building_owner(bld));
|
||||
CuAssertTrue(tc, fval(u, UFL_OWNER));
|
||||
u->number = 0;
|
||||
CuAssertPtrEquals(tc, u3, building_owner(bld));
|
||||
u3->number = 0;
|
||||
|
|
|
@ -2367,7 +2367,7 @@ unsigned int getguard(const unit * u)
|
|||
{
|
||||
attrib *a;
|
||||
|
||||
assert((u->building && fval(u, UFL_OWNER)) || fval(u, UFL_GUARD)
|
||||
assert(fval(u, UFL_GUARD) || (u->building && u==building_owner(u->building))
|
||||
|| !"you're doing it wrong! check is_guard first");
|
||||
a = a_find(u->attribs, &at_guard);
|
||||
if (a) {
|
||||
|
|
|
@ -251,15 +251,18 @@ void addmessage(region * r, faction * f, const char *s, msg_t mtype, int level)
|
|||
caddmessage(r, f, s, mtype, level);
|
||||
}
|
||||
|
||||
void cmistake(const unit * u, struct order *ord, int mno, int mtype)
|
||||
message * cmistake(const unit * u, struct order *ord, int mno, int mtype)
|
||||
{
|
||||
message * result;
|
||||
static char msgname[20];
|
||||
unused(mtype);
|
||||
|
||||
if (is_monsters(u->faction))
|
||||
return;
|
||||
return 0;
|
||||
sprintf(msgname, "error%d", mno);
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, msgname, ""));
|
||||
result = msg_feedback(u, ord, msgname, "");
|
||||
ADDMSG(&u->faction->msgs, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
extern unsigned int new_hashstring(const char *s);
|
||||
|
|
|
@ -56,7 +56,7 @@ extern "C" {
|
|||
|
||||
#define ADDMSG(msgs, mcreate) { message * m = mcreate; if (m) { assert(m->refcount>=1); add_message(msgs, m); msg_release(m); } }
|
||||
|
||||
extern void cmistake(const struct unit *u, struct order *ord, int mno,
|
||||
extern struct message * cmistake(const struct unit *u, struct order *ord, int mno,
|
||||
int mtype);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -894,7 +894,7 @@ static boolean is_guardian_r(const unit * guard)
|
|||
return false;
|
||||
|
||||
/* if region_owners exist then they may be guardians: */
|
||||
if (guard->building && rule_region_owners() && fval(guard, UFL_OWNER)) {
|
||||
if (guard->building && rule_region_owners() && guard==building_owner(guard->building)) {
|
||||
faction *owner = region_get_owner(guard->region);
|
||||
if (owner == guard->faction) {
|
||||
building *bowner = largestbuilding(guard->region, &cmp_taxes, false);
|
||||
|
@ -1590,7 +1590,7 @@ static const region_list *travel_route(unit * u,
|
|||
|
||||
static boolean ship_ready(const region * r, unit * u)
|
||||
{
|
||||
if (!fval(u, UFL_OWNER)) {
|
||||
if (!u->ship || u!=ship_owner(u->ship)) {
|
||||
cmistake(u, u->thisorder, 146, MSG_MOVE);
|
||||
return false;
|
||||
}
|
||||
|
@ -2159,7 +2159,7 @@ static void move(unit * u, boolean move_on_land)
|
|||
region_list *route = NULL;
|
||||
|
||||
assert(u->number);
|
||||
if (u->ship && fval(u, UFL_OWNER)) {
|
||||
if (u->ship && u==ship_owner(u->ship)) {
|
||||
sail(u, u->thisorder, move_on_land, &route);
|
||||
} else {
|
||||
travel(u, &route);
|
||||
|
@ -2227,7 +2227,7 @@ static void piracy_cmd(unit * u, struct order *ord)
|
|||
return;
|
||||
}
|
||||
|
||||
if (!fval(u, UFL_OWNER)) {
|
||||
if (!u->ship || u!=ship_owner(u->ship)) {
|
||||
cmistake(u, ord, 146, MSG_MOVE);
|
||||
return;
|
||||
}
|
||||
|
@ -2370,11 +2370,11 @@ static int hunt(unit * u, order * ord)
|
|||
|
||||
if (fval(u, UFL_NOTMOVING)) {
|
||||
return 0;
|
||||
} else if (u->ship == NULL) {
|
||||
} else if (!u->ship) {
|
||||
cmistake(u, ord, 144, MSG_MOVE);
|
||||
fset(u, UFL_LONGACTION | UFL_NOTMOVING); /* FOLGE SCHIFF ist immer lang */
|
||||
return 0;
|
||||
} else if (!fval(u, UFL_OWNER)) {
|
||||
} else if (u!=ship_owner(u->ship)) {
|
||||
cmistake(u, ord, 146, MSG_MOVE);
|
||||
fset(u, UFL_LONGACTION | UFL_NOTMOVING); /* FOLGE SCHIFF ist immer lang */
|
||||
return 0;
|
||||
|
|
|
@ -1414,14 +1414,13 @@ void reorder_units(region * r)
|
|||
while (*unext && b) {
|
||||
unit **ufirst = unext; /* where the first unit in the building should go */
|
||||
unit **umove = unext; /* a unit we consider moving */
|
||||
unit *owner = NULL;
|
||||
while (*umove) {
|
||||
unit *owner = building_owner(b);
|
||||
while (owner && *umove) {
|
||||
unit *u = *umove;
|
||||
if (u->number && u->building == b) {
|
||||
if (u->building == b) {
|
||||
unit **uinsert = unext;
|
||||
if (fval(u, UFL_OWNER)) {
|
||||
if (u==owner) {
|
||||
uinsert = ufirst;
|
||||
owner = u;
|
||||
}
|
||||
if (umove != uinsert) {
|
||||
*umove = u->next;
|
||||
|
@ -1439,10 +1438,6 @@ void reorder_units(region * r)
|
|||
umove = &u->next;
|
||||
}
|
||||
}
|
||||
if (!owner && ufirst != unext) {
|
||||
owner = *ufirst;
|
||||
fset(owner, UFL_OWNER);
|
||||
}
|
||||
b = b->next;
|
||||
}
|
||||
}
|
||||
|
@ -1472,12 +1467,12 @@ void reorder_units(region * r)
|
|||
while (*unext && sh) {
|
||||
unit **ufirst = unext; /* where the first unit in the building should go */
|
||||
unit **umove = unext; /* a unit we consider moving */
|
||||
unit *owner = NULL;
|
||||
while (*umove) {
|
||||
unit *owner = ship_owner(sh);
|
||||
while (owner && *umove) {
|
||||
unit *u = *umove;
|
||||
if (u->number && u->ship == sh) {
|
||||
unit **uinsert = unext;
|
||||
if (fval(u, UFL_OWNER)) {
|
||||
if (u==owner) {
|
||||
uinsert = ufirst;
|
||||
owner = u;
|
||||
}
|
||||
|
@ -1497,10 +1492,6 @@ void reorder_units(region * r)
|
|||
umove = &u->next;
|
||||
}
|
||||
}
|
||||
if (!owner && ufirst != unext) {
|
||||
owner = *ufirst;
|
||||
fset(owner, UFL_OWNER);
|
||||
}
|
||||
sh = sh->next;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -796,6 +796,9 @@ unit *read_unit(struct storage *store)
|
|||
building * b = findbuilding(n);
|
||||
if (b) {
|
||||
u_set_building(u, b);
|
||||
if (fval(u, UFL_OWNER)) {
|
||||
building_set_owner(b, u);
|
||||
}
|
||||
} else {
|
||||
log_error("read_unit: unit in unkown building '%s'\n", itoa36(n));
|
||||
}
|
||||
|
@ -806,6 +809,9 @@ unit *read_unit(struct storage *store)
|
|||
ship * sh = findship(n);
|
||||
if (sh) {
|
||||
u_set_ship(u, sh);
|
||||
if (fval(u, UFL_OWNER)) {
|
||||
ship_set_owner(sh, u);
|
||||
}
|
||||
} else {
|
||||
log_error("read_unit: unit in unkown ship '%s'\n", itoa36(n));
|
||||
}
|
||||
|
@ -880,7 +886,9 @@ void write_unit(struct storage *store, const unit * u)
|
|||
{
|
||||
order *ord;
|
||||
int i, p = 0;
|
||||
unsigned int flags = u->flags & UFL_SAVEMASK;
|
||||
const race *irace = u_irace(u);
|
||||
|
||||
write_unit_reference(u, store);
|
||||
write_faction_reference(u->faction, store);
|
||||
store->w_str(store, (const char *)u->name);
|
||||
|
@ -892,7 +900,9 @@ void write_unit(struct storage *store, const unit * u)
|
|||
write_building_reference(u->building, store);
|
||||
write_ship_reference(u->ship, store);
|
||||
store->w_int(store, u->status);
|
||||
store->w_int(store, u->flags & UFL_SAVEMASK);
|
||||
if (u->building && u==building_owner(u->building)) flags |= UFL_OWNER;
|
||||
if (u->ship && u==ship_owner(u->ship)) flags |= UFL_OWNER;
|
||||
store->w_int(store, flags);
|
||||
store->w_brk(store);
|
||||
for (ord = u->old_orders; ord; ord = ord->next) {
|
||||
if (++p < MAXPERSISTENT) {
|
||||
|
|
|
@ -288,11 +288,7 @@ void getshipweight(const ship * sh, int *sweight, int *scabins)
|
|||
|
||||
void ship_set_owner(ship * sh, unit * u) {
|
||||
assert(u->ship==sh);
|
||||
if (sh->_owner && sh->_owner!=u) {
|
||||
freset(sh->_owner, UFL_OWNER);
|
||||
}
|
||||
sh->_owner = u;
|
||||
fset(u, UFL_OWNER);
|
||||
}
|
||||
|
||||
unit *ship_owner(const ship * sh)
|
||||
|
@ -314,14 +310,9 @@ unit *ship_owner(const ship * sh)
|
|||
heir = u; /* you'll do in an emergency */
|
||||
}
|
||||
}
|
||||
freset(u, UFL_OWNER);
|
||||
}
|
||||
}
|
||||
freset(owner, UFL_OWNER);
|
||||
owner = heir;
|
||||
if (owner) {
|
||||
fset(owner, UFL_OWNER);
|
||||
}
|
||||
}
|
||||
/* Eigentümer tot oder kein Eigentümer vorhanden. Erste lebende Einheit
|
||||
* nehmen. */
|
||||
|
|
|
@ -155,15 +155,10 @@ static void test_shipowner_goes_to_same_faction_after_death(CuTest * tc)
|
|||
u_set_ship(u2, sh);
|
||||
u_set_ship(u3, sh);
|
||||
CuAssertPtrEquals(tc, u, ship_owner(sh));
|
||||
CuAssertTrue(tc, fval(u, UFL_OWNER));
|
||||
u->number = 0;
|
||||
CuAssertPtrEquals(tc, u3, ship_owner(sh));
|
||||
CuAssertTrue(tc, !fval(u, UFL_OWNER));
|
||||
CuAssertTrue(tc, fval(u3, UFL_OWNER));
|
||||
u3->number = 0;
|
||||
CuAssertPtrEquals(tc, u2, ship_owner(sh));
|
||||
CuAssertTrue(tc, !fval(u3, UFL_OWNER));
|
||||
CuAssertTrue(tc, fval(u2, UFL_OWNER));
|
||||
}
|
||||
|
||||
static void test_shipowner_goes_to_next_after_leave(CuTest * tc)
|
||||
|
|
|
@ -63,7 +63,7 @@ extern "C" {
|
|||
#define UFL_GROUP (1<<28)
|
||||
|
||||
/* Flags, die gespeichert werden sollen: */
|
||||
#define UFL_SAVEMASK (UFL_DEFENDER|UFL_MOVED|UFL_NOAID|UFL_OWNER|UFL_ANON_FACTION|UFL_LOCKED|UFL_HUNGER|UFL_TAKEALL|UFL_GUARD|UFL_STEALTH|UFL_GROUP|UFL_HERO)
|
||||
#define UFL_SAVEMASK (UFL_DEFENDER|UFL_MOVED|UFL_NOAID|UFL_ANON_FACTION|UFL_LOCKED|UFL_HUNGER|UFL_TAKEALL|UFL_GUARD|UFL_STEALTH|UFL_GROUP|UFL_HERO)
|
||||
|
||||
#define UNIT_MAXSIZE 50000
|
||||
extern int maxheroes(const struct faction *f);
|
||||
|
|
Loading…
Add table
Reference in a new issue