when reading alliances, duplicate ids are impossible.

makealliance does too much work, new_alliance is simpler.
This commit is contained in:
Enno Rehling 2016-08-17 21:22:50 +02:00
parent a3ff8781c4
commit abd6600cfe
3 changed files with 16 additions and 8 deletions

View File

@ -58,7 +58,7 @@ void free_alliances(void)
alliance *makealliance(int id, const char *name)
{
alliance *al;;
alliance *al;
for (;;) {
if (id > 0) {
@ -73,6 +73,13 @@ alliance *makealliance(int id, const char *name)
}
id = id ? id : (1 + (rng_int() % MAX_UNIT_NR));
}
return new_alliance(id, name);
}
alliance *new_alliance(int id, const char *name) {
alliance *al;
assert(id>0);
al = calloc(1, sizeof(alliance));
al->id = id;
if (name) {

View File

@ -54,13 +54,14 @@ extern "C" {
} alliance;
extern alliance *alliances;
extern alliance *findalliance(int id);
extern alliance *makealliance(int id, const char *name);
extern const char *alliancename(const struct alliance *al);
extern void setalliance(struct faction *f, alliance * al);
alliance *findalliance(int id);
alliance *new_alliance(int id, const char *name);
alliance *makealliance(int id, const char *name);
const char *alliancename(const struct alliance *al);
void setalliance(struct faction *f, alliance * al);
void free_alliances(void);
extern struct faction *alliance_get_leader(struct alliance *al);
extern void alliance_cmd(void);
struct faction *alliance_get_leader(struct alliance *al);
void alliance_cmd(void);
bool is_allied(const struct faction *f1, const struct faction *f2);
void alliance_setname(alliance * self, const char *name);

View File

@ -436,7 +436,7 @@ static void read_alliances(struct gamedata *data)
char aname[128];
alliance *al;
READ_STR(store, aname, sizeof(aname));
al = makealliance(id, aname);
al = new_alliance(id, aname);
if (data->version >= OWNER_2_VERSION) {
READ_INT(store, &al->flags);
}