forked from github/server
use quicklist to store ship types.
This commit is contained in:
parent
3677e899af
commit
36e53069e0
2 changed files with 80 additions and 77 deletions
|
@ -35,6 +35,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include <util/language.h>
|
#include <util/language.h>
|
||||||
#include <util/lists.h>
|
#include <util/lists.h>
|
||||||
#include <util/umlaut.h>
|
#include <util/umlaut.h>
|
||||||
|
#include <util/quicklist.h>
|
||||||
#include <util/storage.h>
|
#include <util/storage.h>
|
||||||
#include <util/xml.h>
|
#include <util/xml.h>
|
||||||
|
|
||||||
|
@ -45,7 +46,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
ship_typelist *shiptypes = NULL;
|
quicklist *shiptypes = NULL;
|
||||||
|
|
||||||
static local_names * snames;
|
static local_names * snames;
|
||||||
|
|
||||||
|
@ -60,16 +61,19 @@ findshiptype(const char * name, const struct locale * lang)
|
||||||
sn=sn->next;
|
sn=sn->next;
|
||||||
}
|
}
|
||||||
if (!sn) {
|
if (!sn) {
|
||||||
struct ship_typelist * stl = shiptypes;
|
quicklist * ql;
|
||||||
sn = calloc(sizeof(local_names), 1);
|
int qi;
|
||||||
|
|
||||||
|
sn = (local_names *)calloc(sizeof(local_names), 1);
|
||||||
sn->next = snames;
|
sn->next = snames;
|
||||||
sn->lang = lang;
|
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;
|
variant var;
|
||||||
const char * n = locale_string(lang, stl->type->name[0]);
|
const char * n = locale_string(lang, stype->name[0]);
|
||||||
var.v = (void*)stl->type;
|
var.v = (void*)stype;
|
||||||
addtoken(&sn->names, n, var);
|
addtoken(&sn->names, n, var);
|
||||||
stl = stl->next;
|
|
||||||
}
|
}
|
||||||
snames = sn;
|
snames = sn;
|
||||||
}
|
}
|
||||||
|
@ -80,17 +84,21 @@ findshiptype(const char * name, const struct locale * lang)
|
||||||
const ship_type *
|
const ship_type *
|
||||||
st_find(const char* name)
|
st_find(const char* name)
|
||||||
{
|
{
|
||||||
const struct ship_typelist * stl = shiptypes;
|
quicklist * ql;
|
||||||
while (stl && strcmp(stl->type->name[0], name)) stl = stl->next;
|
int qi;
|
||||||
return stl?stl->type:NULL;
|
|
||||||
|
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
|
void
|
||||||
st_register(const ship_type * type) {
|
st_register(const ship_type * type) {
|
||||||
struct ship_typelist * stl = malloc(sizeof(ship_type));
|
ql_push(&shiptypes, (void *)type);
|
||||||
stl->type = type;
|
|
||||||
stl->next = shiptypes;
|
|
||||||
shiptypes = stl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define SMAXHASH 7919
|
#define SMAXHASH 7919
|
||||||
|
|
|
@ -59,12 +59,7 @@ typedef struct ship_type {
|
||||||
struct construction * construction; /* how to build a ship */
|
struct construction * construction; /* how to build a ship */
|
||||||
} ship_type;
|
} ship_type;
|
||||||
|
|
||||||
typedef struct ship_typelist {
|
extern struct quicklist *shiptypes;
|
||||||
struct ship_typelist * next;
|
|
||||||
const ship_type * type;
|
|
||||||
} ship_typelist;
|
|
||||||
|
|
||||||
extern ship_typelist *shiptypes;
|
|
||||||
|
|
||||||
/* Alte Schiffstypen: */
|
/* Alte Schiffstypen: */
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue