forked from github/server
fix: alliance-crash when leader faction died
This commit is contained in:
parent
250e086eb1
commit
cb88302668
6 changed files with 27 additions and 19 deletions
|
@ -944,10 +944,11 @@ show_alliances_cr(FILE * F, const faction * f)
|
||||||
{
|
{
|
||||||
if (f->alliance) {
|
if (f->alliance) {
|
||||||
alliance * al = f->alliance;
|
alliance * al = f->alliance;
|
||||||
assert(al->leader);
|
faction * lead = alliance_get_leader(al);
|
||||||
|
assert(lead);
|
||||||
fprintf(F, "ALLIANCE %d\n", al->id);
|
fprintf(F, "ALLIANCE %d\n", al->id);
|
||||||
fprintf(F, "\"%s\";name\n", al->name);
|
fprintf(F, "\"%s\";name\n", al->name);
|
||||||
fprintf(F, "%d;leader\n", al->leader->no);
|
fprintf(F, "%d;leader\n", lead->no);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1618,7 +1618,8 @@ name_cmd(unit * u, struct order * ord)
|
||||||
case P_ALLIANCE:
|
case P_ALLIANCE:
|
||||||
if (foreign==false && u->faction->alliance) {
|
if (foreign==false && u->faction->alliance) {
|
||||||
alliance * al = u->faction->alliance;
|
alliance * al = u->faction->alliance;
|
||||||
if (al->leader==u->faction) {
|
faction * lead = alliance_get_leader(al);
|
||||||
|
if (lead==u->faction) {
|
||||||
s = &al->name;
|
s = &al->name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2074,7 +2074,7 @@ report_plaintext(const char * filename, report_context * ctx, const char * chars
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (f->alliance) {
|
if (f->alliance) {
|
||||||
m = msg_message("nr_alliance", "leader name id", f->alliance->leader, f->alliance->name, f->alliance->id);
|
m = msg_message("nr_alliance", "leader name id", alliance_get_leader(f->alliance), f->alliance->name, f->alliance->id);
|
||||||
nr_render(m, f->locale, buf, sizeof(buf), f);
|
nr_render(m, f->locale, buf, sizeof(buf), f);
|
||||||
msg_release(m);
|
msg_release(m);
|
||||||
centre(F, buf, true);
|
centre(F, buf, true);
|
||||||
|
|
|
@ -89,9 +89,15 @@ typedef struct alliance_transaction {
|
||||||
static struct alliance_transaction * transactions[ALLIANCE_MAX];
|
static struct alliance_transaction * transactions[ALLIANCE_MAX];
|
||||||
|
|
||||||
|
|
||||||
static faction * alliance_leader(const alliance * al)
|
faction *
|
||||||
|
alliance_get_leader(alliance * al)
|
||||||
{
|
{
|
||||||
return al->leader;
|
if (!al->_leader) {
|
||||||
|
if (al->members) {
|
||||||
|
al->_leader = al->members->data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return al->_leader;
|
||||||
}
|
}
|
||||||
|
|
||||||
// static alliance_transaction **
|
// static alliance_transaction **
|
||||||
|
@ -166,7 +172,7 @@ perform_kick(void)
|
||||||
alliance_transaction * ta = *tap;
|
alliance_transaction * ta = *tap;
|
||||||
alliance * al = ta->u->faction->alliance;
|
alliance * al = ta->u->faction->alliance;
|
||||||
|
|
||||||
if (al && alliance_leader(al)==ta->u->faction) {
|
if (al && alliance_get_leader(al)==ta->u->faction) {
|
||||||
faction * f;
|
faction * f;
|
||||||
init_tokens(ta->ord);
|
init_tokens(ta->ord);
|
||||||
skip_token();
|
skip_token();
|
||||||
|
@ -237,14 +243,14 @@ perform_transfer(void)
|
||||||
alliance_transaction * ta = *tap;
|
alliance_transaction * ta = *tap;
|
||||||
alliance * al = ta->u->faction->alliance;
|
alliance * al = ta->u->faction->alliance;
|
||||||
|
|
||||||
if (al && alliance_leader(al)==ta->u->faction) {
|
if (al && alliance_get_leader(al)==ta->u->faction) {
|
||||||
faction * f;
|
faction * f;
|
||||||
init_tokens(ta->ord);
|
init_tokens(ta->ord);
|
||||||
skip_token();
|
skip_token();
|
||||||
skip_token();
|
skip_token();
|
||||||
f = getfaction();
|
f = getfaction();
|
||||||
if (f && f->alliance==al) {
|
if (f && f->alliance==al) {
|
||||||
al->leader = f;
|
al->_leader = f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*tap = ta->next;
|
*tap = ta->next;
|
||||||
|
@ -390,11 +396,11 @@ setalliance(struct faction * f, alliance * al)
|
||||||
flistp = &flist->next;
|
flistp = &flist->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (f->alliance->leader==f) {
|
if (f->alliance->_leader==f) {
|
||||||
if (f->alliance->members) {
|
if (f->alliance->members) {
|
||||||
f->alliance->leader = f->alliance->members->data;
|
f->alliance->_leader = f->alliance->members->data;
|
||||||
} else {
|
} else {
|
||||||
f->alliance->leader = NULL;
|
f->alliance->_leader = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -410,8 +416,8 @@ setalliance(struct faction * f, alliance * al)
|
||||||
}
|
}
|
||||||
*flistp = flist;
|
*flistp = flist;
|
||||||
flist->next = NULL;
|
flist->next = NULL;
|
||||||
if (al->leader==NULL) {
|
if (al->_leader==NULL) {
|
||||||
al->leader = f;
|
al->_leader = f;
|
||||||
}
|
}
|
||||||
flist = NULL;
|
flist = NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ enum {
|
||||||
|
|
||||||
typedef struct alliance {
|
typedef struct alliance {
|
||||||
struct alliance * next;
|
struct alliance * next;
|
||||||
struct faction * leader;
|
struct faction * _leader;
|
||||||
struct faction_list * members;
|
struct faction_list * members;
|
||||||
unsigned int flags;
|
unsigned int flags;
|
||||||
int id;
|
int id;
|
||||||
|
@ -49,7 +49,7 @@ extern alliance * makealliance(int id, const char * name);
|
||||||
extern const char * alliancename(const struct alliance * al);
|
extern const char * alliancename(const struct alliance * al);
|
||||||
extern void setalliance(struct faction * f, alliance * al);
|
extern void setalliance(struct faction * f, alliance * al);
|
||||||
void free_alliance(struct alliance * al);
|
void free_alliance(struct alliance * al);
|
||||||
|
extern struct faction * alliance_get_leader(struct alliance * al);
|
||||||
extern void alliance_cmd(void);
|
extern void alliance_cmd(void);
|
||||||
|
|
||||||
void alliance_setname(alliance * self, const char * name);
|
void alliance_setname(alliance * self, const char * name);
|
||||||
|
|
|
@ -563,7 +563,7 @@ read_alliances(struct storage * store)
|
||||||
store->r_str_buf(store, aname, sizeof(aname));
|
store->r_str_buf(store, aname, sizeof(aname));
|
||||||
al = makealliance(id, aname);
|
al = makealliance(id, aname);
|
||||||
if (store->version>=ALLIANCELEADER_VERSION) {
|
if (store->version>=ALLIANCELEADER_VERSION) {
|
||||||
read_reference(&al->leader, store, read_faction_reference, resolve_faction);
|
read_reference(&al->_leader, store, read_faction_reference, resolve_faction);
|
||||||
id = store->r_id(store);
|
id = store->r_id(store);
|
||||||
} else{
|
} else{
|
||||||
store->r_str_buf(store, pbuf, sizeof(pbuf));
|
store->r_str_buf(store, pbuf, sizeof(pbuf));
|
||||||
|
@ -577,11 +577,11 @@ write_alliances(struct storage * store)
|
||||||
{
|
{
|
||||||
alliance * al = alliances;
|
alliance * al = alliances;
|
||||||
while (al) {
|
while (al) {
|
||||||
if (al->leader) {
|
if (al->_leader) {
|
||||||
store->w_id(store, al->id);
|
store->w_id(store, al->id);
|
||||||
store->w_str(store, al->name);
|
store->w_str(store, al->name);
|
||||||
if (store->version>=ALLIANCELEADER_VERSION) {
|
if (store->version>=ALLIANCELEADER_VERSION) {
|
||||||
write_faction_reference(al->leader, store);
|
write_faction_reference(al->_leader, store);
|
||||||
}
|
}
|
||||||
store->w_brk(store);
|
store->w_brk(store);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue