use quicklist to store ship types.

This commit is contained in:
Enno Rehling 2011-03-06 21:11:17 -08:00
parent 3677e899af
commit 36e53069e0
2 changed files with 80 additions and 77 deletions

View file

@ -35,6 +35,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <util/language.h>
#include <util/lists.h>
#include <util/umlaut.h>
#include <util/quicklist.h>
#include <util/storage.h>
#include <util/xml.h>
@ -45,7 +46,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <string.h>
ship_typelist *shiptypes = NULL;
quicklist *shiptypes = NULL;
static local_names * snames;
@ -60,16 +61,19 @@ findshiptype(const char * name, const struct locale * lang)
sn=sn->next;
}
if (!sn) {
struct ship_typelist * stl = shiptypes;
sn = calloc(sizeof(local_names), 1);
quicklist * ql;
int qi;
sn = (local_names *)calloc(sizeof(local_names), 1);
sn->next = snames;
sn->lang = lang;
while (stl) {
for (qi=0,ql=shiptypes;ql;ql_advance(&ql, &qi, 1)) {
ship_type * stype = (ship_type *)ql_get(ql, qi);
variant var;
const char * n = locale_string(lang, stl->type->name[0]);
var.v = (void*)stl->type;
const char * n = locale_string(lang, stype->name[0]);
var.v = (void*)stype;
addtoken(&sn->names, n, var);
stl = stl->next;
}
snames = sn;
}
@ -80,17 +84,21 @@ findshiptype(const char * name, const struct locale * lang)
const ship_type *
st_find(const char* name)
{
const struct ship_typelist * stl = shiptypes;
while (stl && strcmp(stl->type->name[0], name)) stl = stl->next;
return stl?stl->type:NULL;
quicklist * ql;
int qi;
for (qi=0,ql=shiptypes;ql;ql_advance(&ql, &qi, 1)) {
ship_type * stype = (ship_type *)ql_get(ql, qi);
if (strcmp(stype->name[0], name)==0) {
return stype;
}
}
return NULL;
}
void
st_register(const ship_type * type) {
struct ship_typelist * stl = malloc(sizeof(ship_type));
stl->type = type;
stl->next = shiptypes;
shiptypes = stl;
ql_push(&shiptypes, (void *)type);
}
#define SMAXHASH 7919

View file

@ -59,12 +59,7 @@ typedef struct ship_type {
struct construction * construction; /* how to build a ship */
} ship_type;
typedef struct ship_typelist {
struct ship_typelist * next;
const ship_type * type;
} ship_typelist;
extern ship_typelist *shiptypes;
extern struct quicklist *shiptypes;
/* Alte Schiffstypen: */