From 85fe80d858d9939b0097533d70df9a8031468d89 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 1 Nov 2018 10:16:49 +0100 Subject: [PATCH] unit_create function instead of wild calloc calls. --- src/kernel/save.c | 5 +---- src/kernel/unit.c | 12 +++++++----- src/kernel/unit.h | 7 ++++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/kernel/save.c b/src/kernel/save.c index 928c1938a..ceaf78ee1 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -420,10 +420,7 @@ unit *read_unit(gamedata *data) u_setfaction(u, NULL); } else { - u = (unit *)calloc(1, sizeof(unit)); - assert_alloc(u); - u->no = n; - uhash(u); + u = unit_create(n); } READ_INT(data->store, &n); diff --git a/src/kernel/unit.c b/src/kernel/unit.c index d0737eaba..8b2248d39 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -1375,6 +1375,12 @@ void name_unit(unit * u) } } +unit *unit_create(int id) +{ + unit *u = (unit *)calloc(1, sizeof(unit)); + createunitid(u, id); + return u; +} /** creates a new unit. * * @param dname: name, set to NULL to get a default. @@ -1383,7 +1389,7 @@ void name_unit(unit * u) unit *create_unit(region * r, faction * f, int number, const struct race *urace, int id, const char *dname, unit * creator) { - unit *u = (unit *)calloc(1, sizeof(unit)); + unit *u = unit_create(id); assert(urace); u_setrace(u, urace); @@ -1395,10 +1401,6 @@ unit *create_unit(region * r, faction * f, int number, const struct race *urace, set_number(u, number); - /* die nummer der neuen einheit muss vor name_unit generiert werden, - * da der default name immer noch 'Nummer u->no' ist */ - createunitid(u, id); - /* zuerst in die Region setzen, da zb Drachennamen den Regionsnamen * enthalten */ if (r) diff --git a/src/kernel/unit.h b/src/kernel/unit.h index 86c2e2e61..e08ca1ef3 100644 --- a/src/kernel/unit.h +++ b/src/kernel/unit.h @@ -206,10 +206,11 @@ extern "C" { int invisible(const struct unit *target, const struct unit *viewer); void free_unit(struct unit *u); - extern void name_unit(struct unit *u); - extern struct unit *create_unit(struct region *r1, struct faction *f, + void name_unit(struct unit *u); + struct unit *unit_create(int id); + struct unit *create_unit(struct region *r1, struct faction *f, int number, const struct race *rc, int id, const char *dname, - struct unit *creator); + struct unit *creator); void uhash(struct unit *u); void uunhash(struct unit *u);