forked from github/server
unit_create function instead of wild calloc calls.
This commit is contained in:
parent
d9167b8a59
commit
85fe80d858
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue