forked from github/server
refactoring: moving unitname to unit.c.
also removing static-string some cruft from config.c.
This commit is contained in:
parent
669712f04f
commit
b551edbdb3
|
@ -15,6 +15,7 @@
|
||||||
#include "command.h"
|
#include "command.h"
|
||||||
|
|
||||||
#include <kernel/order.h>
|
#include <kernel/order.h>
|
||||||
|
#include <kernel/unit.h>
|
||||||
|
|
||||||
#include <util/umlaut.h>
|
#include <util/umlaut.h>
|
||||||
#include <util/language.h>
|
#include <util/language.h>
|
||||||
|
|
|
@ -1097,28 +1097,7 @@ typedef char name[OBJECTIDSIZE + 1];
|
||||||
static name idbuf[8];
|
static name idbuf[8];
|
||||||
static int nextbuf = 0;
|
static int nextbuf = 0;
|
||||||
|
|
||||||
char *estring_i(char *ibuf)
|
char *untilde(char *ibuf)
|
||||||
{
|
|
||||||
char *p = ibuf;
|
|
||||||
|
|
||||||
while (*p) {
|
|
||||||
if (isxspace(*(unsigned *)p) == ' ') {
|
|
||||||
*p = '~';
|
|
||||||
}
|
|
||||||
++p;
|
|
||||||
}
|
|
||||||
return ibuf;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *estring(const char *s)
|
|
||||||
{
|
|
||||||
char *ibuf = idbuf[(++nextbuf) % 8];
|
|
||||||
|
|
||||||
strlcpy(ibuf, s, sizeof(name));
|
|
||||||
return estring_i(ibuf);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *cstring_i(char *ibuf)
|
|
||||||
{
|
{
|
||||||
char *p = ibuf;
|
char *p = ibuf;
|
||||||
|
|
||||||
|
@ -1131,14 +1110,6 @@ char *cstring_i(char *ibuf)
|
||||||
return ibuf;
|
return ibuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *cstring(const char *s)
|
|
||||||
{
|
|
||||||
char *ibuf = idbuf[(++nextbuf) % 8];
|
|
||||||
|
|
||||||
strlcpy(ibuf, s, sizeof(name));
|
|
||||||
return cstring_i(ibuf);
|
|
||||||
}
|
|
||||||
|
|
||||||
building *largestbuilding(const region * r, cmp_building_cb cmp_gt,
|
building *largestbuilding(const region * r, cmp_building_cb cmp_gt,
|
||||||
bool imaginary)
|
bool imaginary)
|
||||||
{
|
{
|
||||||
|
@ -1157,19 +1128,6 @@ building *largestbuilding(const region * r, cmp_building_cb cmp_gt,
|
||||||
return best;
|
return best;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *write_unitname(const unit * u, char *buffer, size_t size)
|
|
||||||
{
|
|
||||||
slprintf(buffer, size, "%s (%s)", (const char *)u->name, itoa36(u->no));
|
|
||||||
buffer[size - 1] = 0;
|
|
||||||
return buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *unitname(const unit * u)
|
|
||||||
{
|
|
||||||
char *ubuf = idbuf[(++nextbuf) % 8];
|
|
||||||
return write_unitname(u, ubuf, sizeof(name));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* -- Erschaffung neuer Einheiten ------------------------------ */
|
/* -- Erschaffung neuer Einheiten ------------------------------ */
|
||||||
|
|
||||||
extern faction *dfindhash(int i);
|
extern faction *dfindhash(int i);
|
||||||
|
|
|
@ -34,6 +34,7 @@ extern "C" {
|
||||||
#define INSECT_POTION /* Spezialtrank für Insekten */
|
#define INSECT_POTION /* Spezialtrank für Insekten */
|
||||||
#define ORCIFICATION /* giving snotlings to the peasants gets counted */
|
#define ORCIFICATION /* giving snotlings to the peasants gets counted */
|
||||||
|
|
||||||
|
// TODO: remove macro, move all alliance code into a module.
|
||||||
#define ALLIED(f1, f2) (f1==f2 || (f1->alliance && f1->alliance==f2->alliance))
|
#define ALLIED(f1, f2) (f1==f2 || (f1->alliance && f1->alliance==f2->alliance))
|
||||||
|
|
||||||
/* for some good prime numbers, check http://www.math.niu.edu/~rusin/known-math/98/pi_x */
|
/* for some good prime numbers, check http://www.math.niu.edu/~rusin/known-math/98/pi_x */
|
||||||
|
@ -179,12 +180,7 @@ extern "C" {
|
||||||
|
|
||||||
struct faction *getfaction(void);
|
struct faction *getfaction(void);
|
||||||
|
|
||||||
char *estring(const char *s);
|
char *untilde(char *s);
|
||||||
char *estring_i(char *s);
|
|
||||||
char *cstring(const char *s);
|
|
||||||
char *cstring_i(char *s);
|
|
||||||
const char *unitname(const struct unit *u);
|
|
||||||
char *write_unitname(const struct unit *u, char *buffer, size_t size);
|
|
||||||
|
|
||||||
typedef int(*cmp_building_cb) (const struct building * b,
|
typedef int(*cmp_building_cb) (const struct building * b,
|
||||||
const struct building * a);
|
const struct building * a);
|
||||||
|
|
|
@ -1843,3 +1843,21 @@ void remove_empty_units(void)
|
||||||
remove_empty_units_in_region(r);
|
remove_empty_units_in_region(r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef char name[OBJECTIDSIZE + 1];
|
||||||
|
static name idbuf[8];
|
||||||
|
static int nextbuf = 0;
|
||||||
|
|
||||||
|
char *write_unitname(const unit * u, char *buffer, size_t size)
|
||||||
|
{
|
||||||
|
slprintf(buffer, size, "%s (%s)", (const char *)u->name, itoa36(u->no));
|
||||||
|
buffer[size - 1] = 0;
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *unitname(const unit * u)
|
||||||
|
{
|
||||||
|
char *ubuf = idbuf[(++nextbuf) % 8];
|
||||||
|
return write_unitname(u, ubuf, sizeof(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -247,6 +247,9 @@ extern "C" {
|
||||||
|
|
||||||
struct unit *findunitr(const struct region *r, int n);
|
struct unit *findunitr(const struct region *r, int n);
|
||||||
|
|
||||||
|
const char *unitname(const struct unit *u);
|
||||||
|
char *write_unitname(const struct unit *u, char *buffer, size_t size);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -86,7 +86,7 @@ static int a_readdirection(attrib * a, void *owner, struct storage *store)
|
||||||
READ_TOK(store, NULL, 0);
|
READ_TOK(store, NULL, 0);
|
||||||
READ_TOK(store, lbuf, sizeof(lbuf));
|
READ_TOK(store, lbuf, sizeof(lbuf));
|
||||||
|
|
||||||
cstring_i(lbuf);
|
untilde(lbuf);
|
||||||
for (; dl; dl = dl->next) {
|
for (; dl; dl = dl->next) {
|
||||||
if (strcmp(lbuf, dl->oldname) == 0) {
|
if (strcmp(lbuf, dl->oldname) == 0) {
|
||||||
d->keyword = _strdup(dl->name);
|
d->keyword = _strdup(dl->name);
|
||||||
|
|
Loading…
Reference in New Issue