From 48284eda6840f9e1c63f5cebfa32fb7798832733 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 30 Apr 2005 18:54:25 +0000 Subject: [PATCH] saving a little memory. --- src/common/kernel/unit.c | 28 ++++++++++++++++------------ src/common/kernel/unit.h | 11 +++++------ 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/common/kernel/unit.c b/src/common/kernel/unit.c index f8046f072..e1e5430a6 100644 --- a/src/common/kernel/unit.c +++ b/src/common/kernel/unit.c @@ -46,9 +46,10 @@ #include /* libc includes */ -#include #include +#include #include +#include #include #define FIND_FOREIGN_TEMP @@ -59,9 +60,10 @@ int demonfix = 0; const unit * u_peasants(void) { - static unit peasants = { NULL, NULL, NULL, NULL, NULL, 2, NULL }; + static unit peasants = { 0 }; if (peasants.name==NULL) { peasants.name = strdup("die Bauern"); + peasants.no = 2; } return &peasants; } @@ -69,9 +71,10 @@ u_peasants(void) const unit * u_unknown(void) { - static unit unknown = { NULL, NULL, NULL, NULL, NULL, 1, NULL }; + static unit unknown = { 0 }; if (unknown.name==NULL) { unknown.name =strdup("eine unbekannte Einheit"); + unknown.no = 1; } return &unknown; } @@ -805,6 +808,7 @@ void u_setfaction(unit * u, faction * f) { int cnt = u->number; + unit ** iunit; if (u->faction==f) return; if (u->faction) { set_number(u, 0); @@ -818,20 +822,18 @@ u_setfaction(unit * u, faction * f) set_order(&u->lastorder, NULL); #endif } - if (u->prevF) u->prevF->nextF = u->nextF; - else if (u->faction) { - assert(u->faction->units==u); - u->faction->units = u->nextF; - } - if (u->nextF) u->nextF->prevF = u->prevF; + + iunit = &f->units; + while (*iunit!=u) iunit=&(*iunit)->next; + assert(*iunit); + + *iunit = u->nextF; if (f!=NULL) { u->nextF = f->units; f->units = u; } else u->nextF = NULL; - if (u->nextF) u->nextF->prevF = u; - u->prevF = NULL; u->faction = f; if (u->region) update_interval(f, u->region); @@ -847,6 +849,8 @@ void set_number(unit * u, int count) { assert (count >= 0); + assert (count <= SHRT_MAX); + #ifndef NDEBUG assert (u->faction != 0 || u->number > 0); #endif @@ -860,7 +864,7 @@ set_number(unit * u, int count) if (playerrace(u->race)) { u->faction->num_people += count - u->number; } - u->number = count; + u->number = (short)count; } boolean diff --git a/src/common/kernel/unit.h b/src/common/kernel/unit.h index 4a2f200d9..1162a6db2 100644 --- a/src/common/kernel/unit.h +++ b/src/common/kernel/unit.h @@ -69,20 +69,19 @@ typedef struct unit { struct unit *next; /* needs to be first entry, for region's unitlist */ struct unit *nexthash; struct unit *nextF; /* nächste Einheit der Partei */ - struct unit *prevF; /* letzte Einheit der Partei */ struct region *region; - int no; + int no; + int hp; char *name; char *display; - int number; - int hp; - short age; struct faction *faction; struct building *building; struct ship *ship; + short age; + short number; /* skill data */ - int skill_size; + short skill_size; struct skill *skills; struct item * items; struct reservation {