forked from github/server
micro optimizations.
removing a lot of mallocs through strdup by replacing getcommand calls with get_command, which takes a buffer. only one left. removing mkname calls with a static buffer for keyword-tokens. commit the schema file I had lying around.
This commit is contained in:
parent
9ca206ec3f
commit
dafe71f4b8
|
@ -0,0 +1,6 @@
|
||||||
|
CREATE TABLE email(id INTEGER PRIMARY KEY, md5 VARCHAR(32) UNIQUE NOT NULL, email VARCHAR(32), bounces INT DEFAULT 0, confirmed TIMESTAMP DEFAULT NULL);
|
||||||
|
CREATE TABLE faction (id INTEGER PRIMARY KEY, user_id INTEGER REFERENCES user(id), no INTEGER, name VARCHAR(64), game_id INTEGER REFERENCES game(id), race VARCHAR(10), lang CHAR(2));
|
||||||
|
CREATE TABLE faction_email (faction_id INTEGER REFERENCES faction(id), email_id INTEGER REFERENCES email(id));
|
||||||
|
CREATE TABLE game (id INTEGER PRIMARY KEY, name VARCHAR(20), last_turn INTEGER);
|
||||||
|
CREATE TABLE score (turn INTEGER, faction_id INTEGER REFERENCES faction(id), value INTEGER, UNIQUE(turn, faction_id));
|
||||||
|
CREATE TABLE user(id INTEGER PRIMARY KEY, email_id INTEGER REFERENCES email(id), creation TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
|
|
@ -119,7 +119,8 @@ static const char *translate(const char *key, const char *value)
|
||||||
if (junkyard) {
|
if (junkyard) {
|
||||||
t = junkyard;
|
t = junkyard;
|
||||||
junkyard = junkyard->next;
|
junkyard = junkyard->next;
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
t = malloc(sizeof(translation));
|
t = malloc(sizeof(translation));
|
||||||
t->key = _strdup(key);
|
t->key = _strdup(key);
|
||||||
t->value = value;
|
t->value = value;
|
||||||
|
@ -194,7 +195,8 @@ cr_output_curses(FILE * F, const faction * viewer, const void *obj, objtype_t ty
|
||||||
if (owner != NULL) {
|
if (owner != NULL) {
|
||||||
if (owner->faction == viewer) {
|
if (owner->faction == viewer) {
|
||||||
self = 2;
|
self = 2;
|
||||||
} else { /* steht eine person der Partei auf dem Schiff? */
|
}
|
||||||
|
else { /* steht eine person der Partei auf dem Schiff? */
|
||||||
unit *u = NULL;
|
unit *u = NULL;
|
||||||
for (u = r->units; u; u = u->next) {
|
for (u = r->units; u; u = u->next) {
|
||||||
if (u->ship == sh) {
|
if (u->ship == sh) {
|
||||||
|
@ -204,7 +206,8 @@ cr_output_curses(FILE * F, const faction * viewer, const void *obj, objtype_t ty
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (typ == TYP_BUILDING) {
|
}
|
||||||
|
else if (typ == TYP_BUILDING) {
|
||||||
building *b = (building *)obj;
|
building *b = (building *)obj;
|
||||||
unit *owner = building_owner(b);
|
unit *owner = building_owner(b);
|
||||||
a = b->attribs;
|
a = b->attribs;
|
||||||
|
@ -212,7 +215,8 @@ cr_output_curses(FILE * F, const faction * viewer, const void *obj, objtype_t ty
|
||||||
if (owner != NULL) {
|
if (owner != NULL) {
|
||||||
if (owner->faction == viewer) {
|
if (owner->faction == viewer) {
|
||||||
self = 2;
|
self = 2;
|
||||||
} else { /* steht eine Person der Partei in der Burg? */
|
}
|
||||||
|
else { /* steht eine Person der Partei in der Burg? */
|
||||||
unit *u = NULL;
|
unit *u = NULL;
|
||||||
for (u = r->units; u; u = u->next) {
|
for (u = r->units; u; u = u->next) {
|
||||||
if (u->building == b) {
|
if (u->building == b) {
|
||||||
|
@ -222,17 +226,20 @@ cr_output_curses(FILE * F, const faction * viewer, const void *obj, objtype_t ty
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (typ == TYP_UNIT) {
|
}
|
||||||
|
else if (typ == TYP_UNIT) {
|
||||||
unit *u = (unit *)obj;
|
unit *u = (unit *)obj;
|
||||||
a = u->attribs;
|
a = u->attribs;
|
||||||
r = u->region;
|
r = u->region;
|
||||||
if (u->faction == viewer) {
|
if (u->faction == viewer) {
|
||||||
self = 2;
|
self = 2;
|
||||||
}
|
}
|
||||||
} else if (typ == TYP_REGION) {
|
}
|
||||||
|
else if (typ == TYP_REGION) {
|
||||||
r = (region *)obj;
|
r = (region *)obj;
|
||||||
a = r->attribs;
|
a = r->attribs;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
/* fehler */
|
/* fehler */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,7 +263,8 @@ cr_output_curses(FILE * F, const faction * viewer, const void *obj, objtype_t ty
|
||||||
fprintf(F, "\"%s\"\n", buf);
|
fprintf(F, "\"%s\"\n", buf);
|
||||||
msg_release(msg);
|
msg_release(msg);
|
||||||
}
|
}
|
||||||
} else if (a->type == &at_effect && self) {
|
}
|
||||||
|
else if (a->type == &at_effect && self) {
|
||||||
effect_data *data = (effect_data *)a->data.v;
|
effect_data *data = (effect_data *)a->data.v;
|
||||||
if (data->value > 0) {
|
if (data->value > 0) {
|
||||||
const char *key = resourcename(data->type->itype->rtype, 0);
|
const char *key = resourcename(data->type->itype->rtype, 0);
|
||||||
|
@ -365,12 +373,14 @@ static int cr_order(variant var, char *buffer, const void *userdata)
|
||||||
{
|
{
|
||||||
order *ord = (order *)var.v;
|
order *ord = (order *)var.v;
|
||||||
if (ord != NULL) {
|
if (ord != NULL) {
|
||||||
|
char cmd[ORDERSIZE];
|
||||||
char *wp = buffer;
|
char *wp = buffer;
|
||||||
char *cmd = getcommand(ord);
|
const char *rp;
|
||||||
const char *rp = cmd;
|
|
||||||
|
get_command(ord, cmd, sizeof(cmd));
|
||||||
|
|
||||||
*wp++ = '\"';
|
*wp++ = '\"';
|
||||||
while (*rp) {
|
for (rp = cmd; *rp;) {
|
||||||
switch (*rp) {
|
switch (*rp) {
|
||||||
case '\"':
|
case '\"':
|
||||||
case '\\':
|
case '\\':
|
||||||
|
@ -383,7 +393,8 @@ static int cr_order(variant var, char *buffer, const void *userdata)
|
||||||
*wp++ = 0;
|
*wp++ = 0;
|
||||||
|
|
||||||
free(cmd);
|
free(cmd);
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
strcpy(buffer, "\"\"");
|
strcpy(buffer, "\"\"");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -434,7 +445,8 @@ static int cr_regions(variant var, char *buffer, const void *userdata)
|
||||||
wp += sprintf(wp, ", %d %d %d", nx, ny, z);
|
wp += sprintf(wp, ", %d %d %d", nx, ny, z);
|
||||||
}
|
}
|
||||||
strcat(wp, "\"");
|
strcat(wp, "\"");
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
strcpy(buffer, "\"\"");
|
strcpy(buffer, "\"\"");
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -457,7 +469,8 @@ static int cr_curse(variant var, char *buffer, const void *userdata)
|
||||||
const curse_type *ctype = (const curse_type *)var.v;
|
const curse_type *ctype = (const curse_type *)var.v;
|
||||||
if (ctype != NULL) {
|
if (ctype != NULL) {
|
||||||
sprintf(buffer, "\"%s\"", curse_name(ctype, report->locale));
|
sprintf(buffer, "\"%s\"", curse_name(ctype, report->locale));
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
strcpy(buffer, "\"\"");
|
strcpy(buffer, "\"\"");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -561,7 +574,8 @@ static void render_messages(FILE * F, faction * f, message_list * msgs)
|
||||||
}
|
}
|
||||||
fputs(crbuffer, F);
|
fputs(crbuffer, F);
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
log_error("could not render cr-message %p: %s\n", m->msg, m->msg->type->name);
|
log_error("could not render cr-message %p: %s\n", m->msg, m->msg->type->name);
|
||||||
}
|
}
|
||||||
if (printed) {
|
if (printed) {
|
||||||
|
@ -603,7 +617,8 @@ cr_output_building(FILE * F, building * b, const unit * owner, int fno,
|
||||||
fprintf(F, "\"%s\";wahrerTyp\n", translate(bname, LOC(f->locale,
|
fprintf(F, "\"%s\";wahrerTyp\n", translate(bname, LOC(f->locale,
|
||||||
bname)));
|
bname)));
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
fprintf(F, "\"%s\";Typ\n", translate(bname, LOC(f->locale, bname)));
|
fprintf(F, "\"%s\";Typ\n", translate(bname, LOC(f->locale, bname)));
|
||||||
}
|
}
|
||||||
fprintf(F, "\"%s\";Name\n", b->name);
|
fprintf(F, "\"%s\";Name\n", b->name);
|
||||||
|
@ -777,11 +792,13 @@ static void cr_output_unit(FILE * F, const region * r, const faction * f,
|
||||||
if (mage) {
|
if (mage) {
|
||||||
fprintf(F, "%u;familiarmage\n", mage->no);
|
fprintf(F, "%u;familiarmage\n", mage->no);
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
if (fval(u, UFL_ANON_FACTION)) {
|
if (fval(u, UFL_ANON_FACTION)) {
|
||||||
/* faction info is hidden */
|
/* faction info is hidden */
|
||||||
fprintf(F, "%d;Parteitarnung\n", i2b(fval(u, UFL_ANON_FACTION)));
|
fprintf(F, "%d;Parteitarnung\n", i2b(fval(u, UFL_ANON_FACTION)));
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
const attrib *a_otherfaction = a_find(u->attribs, &at_otherfaction);
|
const attrib *a_otherfaction = a_find(u->attribs, &at_otherfaction);
|
||||||
const faction *otherfaction =
|
const faction *otherfaction =
|
||||||
a_otherfaction ? get_otherfaction(a_otherfaction) : NULL;
|
a_otherfaction ? get_otherfaction(a_otherfaction) : NULL;
|
||||||
|
@ -808,7 +825,8 @@ static void cr_output_unit(FILE * F, const region * r, const faction * f,
|
||||||
if (u->faction != f && a_fshidden
|
if (u->faction != f && a_fshidden
|
||||||
&& a_fshidden->data.ca[0] == 1 && effskill(u, SK_STEALTH) >= 6) {
|
&& a_fshidden->data.ca[0] == 1 && effskill(u, SK_STEALTH) >= 6) {
|
||||||
fprintf(F, "-1;Anzahl\n");
|
fprintf(F, "-1;Anzahl\n");
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
fprintf(F, "%d;Anzahl\n", u->number);
|
fprintf(F, "%d;Anzahl\n", u->number);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -820,7 +838,8 @@ static void cr_output_unit(FILE * F, const region * r, const faction * f,
|
||||||
fprintf(F, "\"%s\";wahrerTyp\n",
|
fprintf(F, "\"%s\";wahrerTyp\n",
|
||||||
translate(zRace, locale_string(f->locale, zRace)));
|
translate(zRace, locale_string(f->locale, zRace)));
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
const race *irace = u_irace(u);
|
const race *irace = u_irace(u);
|
||||||
const char *zRace = rc_name(irace, 1);
|
const char *zRace = rc_name(irace, 1);
|
||||||
fprintf(F, "\"%s\";Typ\n",
|
fprintf(F, "\"%s\";Typ\n",
|
||||||
|
@ -950,7 +969,8 @@ static void cr_output_unit(FILE * F, const region * r, const faction * f,
|
||||||
pr = 0;
|
pr = 0;
|
||||||
if (f == u->faction || omniscient(f)) {
|
if (f == u->faction || omniscient(f)) {
|
||||||
show = u->items;
|
show = u->items;
|
||||||
} else if (!itemcloak && mode >= see_unit && !(a_fshidden
|
}
|
||||||
|
else if (!itemcloak && mode >= see_unit && !(a_fshidden
|
||||||
&& a_fshidden->data.ca[1] == 1 && effskill(u, SK_STEALTH) >= 3)) {
|
&& a_fshidden->data.ca[1] == 1 && effskill(u, SK_STEALTH) >= 3)) {
|
||||||
int n = report_items(u->items, result, MAX_INVENTORY, u, f);
|
int n = report_items(u->items, result, MAX_INVENTORY, u, f);
|
||||||
assert(n >= 0);
|
assert(n >= 0);
|
||||||
|
@ -958,7 +978,8 @@ static void cr_output_unit(FILE * F, const region * r, const faction * f,
|
||||||
show = result;
|
show = result;
|
||||||
else
|
else
|
||||||
show = NULL;
|
show = NULL;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
show = NULL;
|
show = NULL;
|
||||||
}
|
}
|
||||||
lasttype = NULL;
|
lasttype = NULL;
|
||||||
|
@ -1203,7 +1224,8 @@ cr_region_header(FILE * F, int plid, int nx, int ny, unsigned int uid)
|
||||||
{
|
{
|
||||||
if (plid == 0) {
|
if (plid == 0) {
|
||||||
fprintf(F, "REGION %d %d\n", nx, ny);
|
fprintf(F, "REGION %d %d\n", nx, ny);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
fprintf(F, "REGION %d %d %d\n", nx, ny, plid);
|
fprintf(F, "REGION %d %d %d\n", nx, ny, plid);
|
||||||
}
|
}
|
||||||
if (uid)
|
if (uid)
|
||||||
|
@ -1229,7 +1251,8 @@ static void cr_output_region(FILE * F, report_context * ctx, seen_region * sr)
|
||||||
if (opt_cr_absolute_coords) {
|
if (opt_cr_absolute_coords) {
|
||||||
nx = r->x;
|
nx = r->x;
|
||||||
ny = r->y;
|
ny = r->y;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
nx = r->x, ny = r->y;
|
nx = r->x, ny = r->y;
|
||||||
pnormalize(&nx, &ny, pl);
|
pnormalize(&nx, &ny, pl);
|
||||||
adjust_coordinates(f, &nx, &ny, pl, r);
|
adjust_coordinates(f, &nx, &ny, pl, r);
|
||||||
|
@ -1274,7 +1297,8 @@ static void cr_output_region(FILE * F, report_context * ctx, seen_region * sr)
|
||||||
fprintf(F, "\"%s\";visibility\n", visibility[sr->mode]);
|
fprintf(F, "\"%s\";visibility\n", visibility[sr->mode]);
|
||||||
if (sr->mode == see_neighbour) {
|
if (sr->mode == see_neighbour) {
|
||||||
cr_borders(ctx->seen, r, f, sr->mode, F);
|
cr_borders(ctx->seen, r, f, sr->mode, F);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
building *b;
|
building *b;
|
||||||
ship *sh;
|
ship *sh;
|
||||||
unit *u;
|
unit *u;
|
||||||
|
@ -1302,7 +1326,8 @@ static void cr_output_region(FILE * F, report_context * ctx, seen_region * sr)
|
||||||
}
|
}
|
||||||
if (is_cursed(r->attribs, C_RIOT, 0)) {
|
if (is_cursed(r->attribs, C_RIOT, 0)) {
|
||||||
fputs("0;Rekruten\n", F);
|
fputs("0;Rekruten\n", F);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
fprintf(F, "%d;Rekruten\n", rpeasants(r) / RECRUITFRACTION);
|
fprintf(F, "%d;Rekruten\n", rpeasants(r) / RECRUITFRACTION);
|
||||||
}
|
}
|
||||||
if (production(r)) {
|
if (production(r)) {
|
||||||
|
@ -1339,7 +1364,8 @@ static void cr_output_region(FILE * F, report_context * ctx, seen_region * sr)
|
||||||
locale_string(f->locale, ch)));
|
locale_string(f->locale, ch)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (rpeasants(r) / TRADE_FRACTION > 0) {
|
}
|
||||||
|
else if (rpeasants(r) / TRADE_FRACTION > 0) {
|
||||||
struct demand *dmd = r->land->demands;
|
struct demand *dmd = r->land->demands;
|
||||||
fputs("PREISE\n", F);
|
fputs("PREISE\n", F);
|
||||||
while (dmd) {
|
while (dmd) {
|
||||||
|
@ -1476,7 +1502,8 @@ report_computer(const char *filename, report_context * ctx, const char *charset)
|
||||||
if (F == NULL) {
|
if (F == NULL) {
|
||||||
perror(filename);
|
perror(filename);
|
||||||
return -1;
|
return -1;
|
||||||
} else if (_strcmpl(charset, "utf-8")==0 || _strcmpl(charset, "utf8")==0) {
|
}
|
||||||
|
else if (_strcmpl(charset, "utf-8") == 0 || _strcmpl(charset, "utf8") == 0) {
|
||||||
const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf, 0 };
|
const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf, 0 };
|
||||||
fwrite(utf8_bom, 1, 3, F);
|
fwrite(utf8_bom, 1, 3, F);
|
||||||
}
|
}
|
||||||
|
@ -1560,7 +1587,8 @@ report_computer(const char *filename, report_context * ctx, const char *charset)
|
||||||
int flag = want(i);
|
int flag = want(i);
|
||||||
if (options[i]) {
|
if (options[i]) {
|
||||||
fprintf(F, "%d;%s\n", (f->options & flag) ? 1 : 0, options[i]);
|
fprintf(F, "%d;%s\n", (f->options & flag) ? 1 : 0, options[i]);
|
||||||
} else if (f->options & flag) {
|
}
|
||||||
|
else if (f->options & flag) {
|
||||||
f->options &= (~flag);
|
f->options &= (~flag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1671,7 +1699,8 @@ int crwritemap(const char *filename)
|
||||||
int plid = plane_id(pl);
|
int plid = plane_id(pl);
|
||||||
if (plid) {
|
if (plid) {
|
||||||
fprintf(F, "REGION %d %d %d\n", r->x, r->y, plid);
|
fprintf(F, "REGION %d %d %d\n", r->x, r->y, plid);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
fprintf(F, "REGION %d %d\n", r->x, r->y);
|
fprintf(F, "REGION %d %d\n", r->x, r->y);
|
||||||
}
|
}
|
||||||
fprintf(F, "\"%s\";Name\n\"%s\";Terrain\n", rname(r, default_locale),
|
fprintf(F, "\"%s\";Name\n\"%s\";Terrain\n", rname(r, default_locale),
|
||||||
|
|
|
@ -81,7 +81,8 @@ static int do_command_i(const void *keys, struct unit *u, struct order *ord)
|
||||||
if (cmd->nodes && *c) {
|
if (cmd->nodes && *c) {
|
||||||
assert(!cmd->fun);
|
assert(!cmd->fun);
|
||||||
return do_command_i(cmd->nodes, u, ord);
|
return do_command_i(cmd->nodes, u, ord);
|
||||||
} else if (cmd->fun) {
|
}
|
||||||
|
else if (cmd->fun) {
|
||||||
cmd->fun(cmd->nodes, u, ord);
|
cmd->fun(cmd->nodes, u, ord);
|
||||||
return E_TOK_SUCCESS;
|
return E_TOK_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -94,8 +95,8 @@ void do_command(const void *keys, struct unit *u, struct order *ord)
|
||||||
init_tokens(ord);
|
init_tokens(ord);
|
||||||
skip_token();
|
skip_token();
|
||||||
if (do_command_i(keys, u, ord) != E_TOK_SUCCESS) {
|
if (do_command_i(keys, u, ord) != E_TOK_SUCCESS) {
|
||||||
char *cmd = getcommand(ord);
|
char cmd[ORDERSIZE];
|
||||||
|
get_command(ord, cmd, sizeof(cmd));
|
||||||
log_warning("%s failed command '%s'\n", unitname(u), cmd);
|
log_warning("%s failed command '%s'\n", unitname(u), cmd);
|
||||||
free(cmd);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,6 +88,7 @@ extern "C" {
|
||||||
#define ENCCHANCE 10 /* %-Chance für einmalige Zufallsbegegnung */
|
#define ENCCHANCE 10 /* %-Chance für einmalige Zufallsbegegnung */
|
||||||
|
|
||||||
#define DISPLAYSIZE 8192 /* max. Länge einer Beschreibung, incl trailing 0 */
|
#define DISPLAYSIZE 8192 /* max. Länge einer Beschreibung, incl trailing 0 */
|
||||||
|
#define ORDERSIZE (DISPLAYSIZE*2) /* max. length of an order */
|
||||||
#define NAMESIZE 128 /* max. Länge eines Namens, incl trailing 0 */
|
#define NAMESIZE 128 /* max. Länge eines Namens, incl trailing 0 */
|
||||||
#define IDSIZE 16 /* max. Länge einer no (als String), incl trailing 0 */
|
#define IDSIZE 16 /* max. Länge einer no (als String), incl trailing 0 */
|
||||||
#define KEYWORDSIZE 16 /* max. Länge eines Keyword, incl trailing 0 */
|
#define KEYWORDSIZE 16 /* max. Länge eines Keyword, incl trailing 0 */
|
||||||
|
|
|
@ -93,7 +93,7 @@ keyword_t getkeyword(const order * ord)
|
||||||
* This is the inverse function to the parse_order command. Note that
|
* This is the inverse function to the parse_order command. Note that
|
||||||
* keywords are expanded to their full length.
|
* keywords are expanded to their full length.
|
||||||
*/
|
*/
|
||||||
static char* get_command(const order *ord, char *sbuffer, size_t size) {
|
char* get_command(const order *ord, char *sbuffer, size_t size) {
|
||||||
char *bufp = sbuffer;
|
char *bufp = sbuffer;
|
||||||
const char *text = ORD_STRING(ord);
|
const char *text = ORD_STRING(ord);
|
||||||
keyword_t kwd = ORD_KEYWORD(ord);
|
keyword_t kwd = ORD_KEYWORD(ord);
|
||||||
|
@ -141,12 +141,6 @@ static char* get_command(const order *ord, char *sbuffer, size_t size) {
|
||||||
return sbuffer;
|
return sbuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *getcommand(const order * ord)
|
|
||||||
{
|
|
||||||
char sbuffer[DISPLAYSIZE * 2];
|
|
||||||
return _strdup(get_command(ord, sbuffer, sizeof(sbuffer)));
|
|
||||||
}
|
|
||||||
|
|
||||||
void free_order(order * ord)
|
void free_order(order * ord)
|
||||||
{
|
{
|
||||||
if (ord != NULL) {
|
if (ord != NULL) {
|
||||||
|
@ -423,6 +417,7 @@ bool is_repeated(const order * ord)
|
||||||
s = getstrtoken();
|
s = getstrtoken();
|
||||||
result = !isparam(s, lang, P_TEMP);
|
result = !isparam(s, lang, P_TEMP);
|
||||||
parser_popstate();
|
parser_popstate();
|
||||||
|
// TODO: push/popstate is slow, we can do better.
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
result = 0;
|
result = 0;
|
||||||
|
@ -589,6 +584,12 @@ void push_order(order ** ordp, order * ord)
|
||||||
*ordp = ord;
|
*ordp = ord;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char *getcommand(const order * ord)
|
||||||
|
{
|
||||||
|
char cmd[ORDERSIZE];
|
||||||
|
return _strdup(get_command(ord, cmd, sizeof(cmd)));
|
||||||
|
}
|
||||||
|
|
||||||
void init_tokens(const struct order *ord)
|
void init_tokens(const struct order *ord)
|
||||||
{
|
{
|
||||||
char *cmd = getcommand(ord);
|
char *cmd = getcommand(ord);
|
||||||
|
|
|
@ -50,13 +50,14 @@ extern "C" {
|
||||||
extern void push_order(struct order **olist, struct order *ord);
|
extern void push_order(struct order **olist, struct order *ord);
|
||||||
|
|
||||||
/* access functions for orders */
|
/* access functions for orders */
|
||||||
extern keyword_t getkeyword(const order * ord);
|
keyword_t getkeyword(const order * ord);
|
||||||
extern void set_order(order ** destp, order * src);
|
void set_order(order ** destp, order * src);
|
||||||
extern char *getcommand(const order * ord);
|
char *getcommand(const order * ord);
|
||||||
extern bool is_persistent(const order * ord);
|
char* get_command(const order *ord, char *buffer, size_t size);
|
||||||
extern bool is_exclusive(const order * ord);
|
bool is_persistent(const order * ord);
|
||||||
extern bool is_repeated(const order * ord);
|
bool is_exclusive(const order * ord);
|
||||||
extern bool is_long(const order * ord);
|
bool is_repeated(const order * ord);
|
||||||
|
bool is_long(const order * ord);
|
||||||
|
|
||||||
extern char *write_order(const order * ord, char *buffer, size_t size);
|
extern char *write_order(const order * ord, char *buffer, size_t size);
|
||||||
extern void init_tokens(const struct order *ord); /* initialize token parsing */
|
extern void init_tokens(const struct order *ord); /* initialize token parsing */
|
||||||
|
|
|
@ -152,7 +152,8 @@ report_item(const unit * owner, const item * i, const faction * viewer,
|
||||||
*basename = resourcename(i->type->rtype, 0);
|
*basename = resourcename(i->type->rtype, 0);
|
||||||
if (number)
|
if (number)
|
||||||
*number = i->number;
|
*number = i->number;
|
||||||
} else if (owner && i->type->rtype == rsilver) {
|
}
|
||||||
|
else if (owner && i->type->rtype == rsilver) {
|
||||||
int pp = i->number / owner->number;
|
int pp = i->number / owner->number;
|
||||||
if (number)
|
if (number)
|
||||||
*number = 1;
|
*number = 1;
|
||||||
|
@ -161,17 +162,20 @@ report_item(const unit * owner, const item * i, const faction * viewer,
|
||||||
*name = locale_string(viewer->locale, "dragonhoard");
|
*name = locale_string(viewer->locale, "dragonhoard");
|
||||||
if (basename)
|
if (basename)
|
||||||
*basename = "dragonhoard";
|
*basename = "dragonhoard";
|
||||||
} else if (pp > 5000) {
|
}
|
||||||
|
else if (pp > 5000) {
|
||||||
if (name)
|
if (name)
|
||||||
*name = locale_string(viewer->locale, "moneychest");
|
*name = locale_string(viewer->locale, "moneychest");
|
||||||
if (basename)
|
if (basename)
|
||||||
*basename = "moneychest";
|
*basename = "moneychest";
|
||||||
} else if (pp > 500) {
|
}
|
||||||
|
else if (pp > 500) {
|
||||||
if (name)
|
if (name)
|
||||||
*name = locale_string(viewer->locale, "moneybag");
|
*name = locale_string(viewer->locale, "moneybag");
|
||||||
if (basename)
|
if (basename)
|
||||||
*basename = "moneybag";
|
*basename = "moneybag";
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
if (number)
|
if (number)
|
||||||
*number = 0;
|
*number = 0;
|
||||||
if (name)
|
if (name)
|
||||||
|
@ -179,7 +183,8 @@ report_item(const unit * owner, const item * i, const faction * viewer,
|
||||||
if (basename)
|
if (basename)
|
||||||
*basename = NULL;
|
*basename = NULL;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
if (name)
|
if (name)
|
||||||
*name =
|
*name =
|
||||||
locale_string(viewer->locale, resourcename(i->type->rtype,
|
locale_string(viewer->locale, resourcename(i->type->rtype,
|
||||||
|
@ -212,7 +217,8 @@ int update_nmrs(void)
|
||||||
for (f = factions; f; f = f->next) {
|
for (f = factions; f; f = f->next) {
|
||||||
if (fval(f, FFL_ISNEW)) {
|
if (fval(f, FFL_ISNEW)) {
|
||||||
++newplayers;
|
++newplayers;
|
||||||
} else if (!is_monsters(f) && f->alive) {
|
}
|
||||||
|
else if (!is_monsters(f) && f->alive) {
|
||||||
int nmr = turn - f->lastorders + 1;
|
int nmr = turn - f->lastorders + 1;
|
||||||
if (nmr < 0 || nmr > NMRTimeout()) {
|
if (nmr < 0 || nmr > NMRTimeout()) {
|
||||||
log_error("faction %s has %d NMRS\n", factionid(f), nmr);
|
log_error("faction %s has %d NMRS\n", factionid(f), nmr);
|
||||||
|
@ -236,10 +242,11 @@ static size_t buforder(char *bufp, size_t size, const order * ord, int mode)
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
if (wrptr(&bufp, &size, bytes) != 0)
|
||||||
WARN_STATIC_BUFFER();
|
WARN_STATIC_BUFFER();
|
||||||
if (mode < ORDERS_IN_NR) {
|
if (mode < ORDERS_IN_NR) {
|
||||||
char *cmd = getcommand(ord);
|
char cmd[ORDERSIZE];
|
||||||
|
get_command(ord, cmd, sizeof(cmd));
|
||||||
bytes = (int)strlcpy(bufp, cmd, size);
|
bytes = (int)strlcpy(bufp, cmd, size);
|
||||||
free(cmd);
|
}
|
||||||
} else {
|
else {
|
||||||
bytes = (int)strlcpy(bufp, "...", size);
|
bytes = (int)strlcpy(bufp, "...", size);
|
||||||
}
|
}
|
||||||
tsize += bytes;
|
tsize += bytes;
|
||||||
|
@ -249,7 +256,8 @@ static size_t buforder(char *bufp, size_t size, const order * ord, int mode)
|
||||||
if (size > 1) {
|
if (size > 1) {
|
||||||
*bufp++ = '\"';
|
*bufp++ = '\"';
|
||||||
--size;
|
--size;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
WARN_STATIC_BUFFER();
|
WARN_STATIC_BUFFER();
|
||||||
}
|
}
|
||||||
++tsize;
|
++tsize;
|
||||||
|
@ -324,7 +332,8 @@ void report_race(const struct unit *u, const char **name, const char **illusion)
|
||||||
const race *irace = u_irace(u);
|
const race *irace = u_irace(u);
|
||||||
if (irace && irace != u_race(u)) {
|
if (irace && irace != u_race(u)) {
|
||||||
*illusion = irace->_name[0];
|
*illusion = irace->_name[0];
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
*illusion = NULL;
|
*illusion = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -420,7 +429,8 @@ report_resources(const seen_region * sr, resource_report * result, int size,
|
||||||
if (res->type->visible == NULL) {
|
if (res->type->visible == NULL) {
|
||||||
visible = res->amount;
|
visible = res->amount;
|
||||||
level = res->level + itype->construction->minskill - 1;
|
level = res->level + itype->construction->minskill - 1;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
const unit *u;
|
const unit *u;
|
||||||
for (u = r->units; visible != res->amount && u != NULL; u = u->next) {
|
for (u = r->units; visible != res->amount && u != NULL; u = u->next) {
|
||||||
if (u->faction == viewer) {
|
if (u->faction == viewer) {
|
||||||
|
@ -495,7 +505,8 @@ bufunit(const faction * f, const unit * u, int indent, int mode, char *buf,
|
||||||
bytes = (int)strlcpy(bufp, LOC(f->locale, "anonymous"), size);
|
bytes = (int)strlcpy(bufp, LOC(f->locale, "anonymous"), size);
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
if (wrptr(&bufp, &size, bytes) != 0)
|
||||||
WARN_STATIC_BUFFER();
|
WARN_STATIC_BUFFER();
|
||||||
} else if (a_otherfaction) {
|
}
|
||||||
|
else if (a_otherfaction) {
|
||||||
faction *otherfaction = get_otherfaction(a_otherfaction);
|
faction *otherfaction = get_otherfaction(a_otherfaction);
|
||||||
if (otherfaction) {
|
if (otherfaction) {
|
||||||
bytes = (int)strlcpy(bufp, ", ", size);
|
bytes = (int)strlcpy(bufp, ", ", size);
|
||||||
|
@ -506,7 +517,8 @@ bufunit(const faction * f, const unit * u, int indent, int mode, char *buf,
|
||||||
WARN_STATIC_BUFFER();
|
WARN_STATIC_BUFFER();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
if (getarnt) {
|
if (getarnt) {
|
||||||
bytes = (int)strlcpy(bufp, ", ", size);
|
bytes = (int)strlcpy(bufp, ", ", size);
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
if (wrptr(&bufp, &size, bytes) != 0)
|
||||||
|
@ -514,7 +526,8 @@ bufunit(const faction * f, const unit * u, int indent, int mode, char *buf,
|
||||||
bytes = (int)strlcpy(bufp, LOC(f->locale, "anonymous"), size);
|
bytes = (int)strlcpy(bufp, LOC(f->locale, "anonymous"), size);
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
if (wrptr(&bufp, &size, bytes) != 0)
|
||||||
WARN_STATIC_BUFFER();
|
WARN_STATIC_BUFFER();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
if (a_otherfaction && alliedunit(u, f, HELP_FSTEALTH)) {
|
if (a_otherfaction && alliedunit(u, f, HELP_FSTEALTH)) {
|
||||||
faction *f = get_otherfaction(a_otherfaction);
|
faction *f = get_otherfaction(a_otherfaction);
|
||||||
bytes =
|
bytes =
|
||||||
|
@ -522,7 +535,8 @@ bufunit(const faction * f, const unit * u, int indent, int mode, char *buf,
|
||||||
factionname(u->faction));
|
factionname(u->faction));
|
||||||
if (bytes < 0 || wrptr(&bufp, &size, bytes) != 0)
|
if (bytes < 0 || wrptr(&bufp, &size, bytes) != 0)
|
||||||
WARN_STATIC_BUFFER();
|
WARN_STATIC_BUFFER();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
bytes = (int)strlcpy(bufp, ", ", size);
|
bytes = (int)strlcpy(bufp, ", ", size);
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
if (wrptr(&bufp, &size, bytes) != 0)
|
||||||
WARN_STATIC_BUFFER();
|
WARN_STATIC_BUFFER();
|
||||||
|
@ -541,7 +555,8 @@ bufunit(const faction * f, const unit * u, int indent, int mode, char *buf,
|
||||||
if (u->faction != f && a_fshidden && a_fshidden->data.ca[0] == 1
|
if (u->faction != f && a_fshidden && a_fshidden->data.ca[0] == 1
|
||||||
&& effskill(u, SK_STEALTH) >= 6) {
|
&& effskill(u, SK_STEALTH) >= 6) {
|
||||||
bytes = (int)strlcpy(bufp, "? ", size);
|
bytes = (int)strlcpy(bufp, "? ", size);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
bytes = _snprintf(bufp, size, "%d ", u->number);
|
bytes = _snprintf(bufp, size, "%d ", u->number);
|
||||||
}
|
}
|
||||||
if (bytes < 0 || wrptr(&bufp, &size, bytes) != 0)
|
if (bytes < 0 || wrptr(&bufp, &size, bytes) != 0)
|
||||||
|
@ -564,7 +579,8 @@ bufunit(const faction * f, const unit * u, int indent, int mode, char *buf,
|
||||||
--size;
|
--size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
const race *irace = u_irace(u);
|
const race *irace = u_irace(u);
|
||||||
bytes = (int)strlcpy(bufp, racename(f->locale, u, irace), size);
|
bytes = (int)strlcpy(bufp, racename(f->locale, u, irace), size);
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
if (wrptr(&bufp, &size, bytes) != 0)
|
||||||
|
@ -658,7 +674,8 @@ bufunit(const faction * f, const unit * u, int indent, int mode, char *buf,
|
||||||
dh = 0;
|
dh = 0;
|
||||||
if (f == u->faction || telepath_see || omniscient(f)) {
|
if (f == u->faction || telepath_see || omniscient(f)) {
|
||||||
show = u->items;
|
show = u->items;
|
||||||
} else if (!itemcloak && mode >= see_unit && !(a_fshidden
|
}
|
||||||
|
else if (!itemcloak && mode >= see_unit && !(a_fshidden
|
||||||
&& a_fshidden->data.ca[1] == 1 && effskill(u, SK_STEALTH) >= 3)) {
|
&& a_fshidden->data.ca[1] == 1 && effskill(u, SK_STEALTH) >= 3)) {
|
||||||
int n = report_items(u->items, result, MAX_INVENTORY, u, f);
|
int n = report_items(u->items, result, MAX_INVENTORY, u, f);
|
||||||
assert(n >= 0);
|
assert(n >= 0);
|
||||||
|
@ -666,7 +683,8 @@ bufunit(const faction * f, const unit * u, int indent, int mode, char *buf,
|
||||||
show = result;
|
show = result;
|
||||||
else
|
else
|
||||||
show = NULL;
|
show = NULL;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
show = NULL;
|
show = NULL;
|
||||||
}
|
}
|
||||||
for (itm = show; itm; itm = itm->next) {
|
for (itm = show; itm; itm = itm->next) {
|
||||||
|
@ -687,7 +705,8 @@ bufunit(const faction * f, const unit * u, int indent, int mode, char *buf,
|
||||||
}
|
}
|
||||||
if (in == 1) {
|
if (in == 1) {
|
||||||
bytes = (int)strlcpy(bufp, ic, size);
|
bytes = (int)strlcpy(bufp, ic, size);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
bytes = _snprintf(bufp, size, "%d %s", in, ic);
|
bytes = _snprintf(bufp, size, "%d %s", in, ic);
|
||||||
}
|
}
|
||||||
if (bytes < 0 || wrptr(&bufp, &size, bytes) != 0)
|
if (bytes < 0 || wrptr(&bufp, &size, bytes) != 0)
|
||||||
|
@ -711,7 +730,8 @@ bufunit(const faction * f, const unit * u, int indent, int mode, char *buf,
|
||||||
if (!header) {
|
if (!header) {
|
||||||
bytes = _snprintf(bufp, size, ", %s: ", LOC(f->locale, "nr_spells"));
|
bytes = _snprintf(bufp, size, ", %s: ", LOC(f->locale, "nr_spells"));
|
||||||
header = 1;
|
header = 1;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
bytes = (int)strlcpy(bufp, ", ", size);
|
bytes = (int)strlcpy(bufp, ", ", size);
|
||||||
}
|
}
|
||||||
if (bytes < 0 || wrptr(&bufp, &size, bytes) != 0) {
|
if (bytes < 0 || wrptr(&bufp, &size, bytes) != 0) {
|
||||||
|
@ -739,7 +759,8 @@ bufunit(const faction * f, const unit * u, int indent, int mode, char *buf,
|
||||||
const spell *sp;
|
const spell *sp;
|
||||||
if (!dh) {
|
if (!dh) {
|
||||||
dh = 1;
|
dh = 1;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
bytes = (int)strlcpy(bufp, ", ", size);
|
bytes = (int)strlcpy(bufp, ", ", size);
|
||||||
if (bytes && wrptr(&bufp, &size, bytes) != 0) {
|
if (bytes && wrptr(&bufp, &size, bytes) != 0) {
|
||||||
WARN_STATIC_BUFFER();
|
WARN_STATIC_BUFFER();
|
||||||
|
@ -759,7 +780,8 @@ bufunit(const faction * f, const unit * u, int indent, int mode, char *buf,
|
||||||
if (bytes < 0 || wrptr(&bufp, &size, bytes) != 0)
|
if (bytes < 0 || wrptr(&bufp, &size, bytes) != 0)
|
||||||
WARN_STATIC_BUFFER();
|
WARN_STATIC_BUFFER();
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
bytes = (int)strlcpy(bufp, LOC(f->locale, "nr_nospells"), size);
|
bytes = (int)strlcpy(bufp, LOC(f->locale, "nr_nospells"), size);
|
||||||
if (bytes && wrptr(&bufp, &size, bytes) != 0)
|
if (bytes && wrptr(&bufp, &size, bytes) != 0)
|
||||||
WARN_STATIC_BUFFER();
|
WARN_STATIC_BUFFER();
|
||||||
|
@ -776,7 +798,8 @@ bufunit(const faction * f, const unit * u, int indent, int mode, char *buf,
|
||||||
bytes = (int)buforder(bufp, size, ord, printed++);
|
bytes = (int)buforder(bufp, size, ord, printed++);
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
if (wrptr(&bufp, &size, bytes) != 0)
|
||||||
WARN_STATIC_BUFFER();
|
WARN_STATIC_BUFFER();
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -787,7 +810,8 @@ bufunit(const faction * f, const unit * u, int indent, int mode, char *buf,
|
||||||
bytes = (int)buforder(bufp, size, ord, printed++);
|
bytes = (int)buforder(bufp, size, ord, printed++);
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
if (wrptr(&bufp, &size, bytes) != 0)
|
||||||
WARN_STATIC_BUFFER();
|
WARN_STATIC_BUFFER();
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -977,7 +1001,8 @@ struct message *msg_curse(const struct curse *c, const void *obj, objtype_t typ,
|
||||||
if (c->type->curseinfo) {
|
if (c->type->curseinfo) {
|
||||||
/* if curseinfo returns NULL, then we don't want to tell the viewer anything. */
|
/* if curseinfo returns NULL, then we don't want to tell the viewer anything. */
|
||||||
return c->type->curseinfo(obj, typ, c, self);
|
return c->type->curseinfo(obj, typ, c, self);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
message *msg = cinfo_simple(obj, typ, c, self);
|
message *msg = cinfo_simple(obj, typ, c, self);
|
||||||
if (msg == NULL) {
|
if (msg == NULL) {
|
||||||
const char *unknown[] =
|
const char *unknown[] =
|
||||||
|
@ -985,7 +1010,8 @@ struct message *msg_curse(const struct curse *c, const void *obj, objtype_t typ,
|
||||||
"ship_unknown" };
|
"ship_unknown" };
|
||||||
msg = msg_message(mkname("curseinfo", unknown[typ]), "id", c->no);
|
msg = msg_message(mkname("curseinfo", unknown[typ]), "id", c->no);
|
||||||
log_error("no curseinfo function for %s and no fallback either.\n", c->type->cname);
|
log_error("no curseinfo function for %s and no fallback either.\n", c->type->cname);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
log_error("no curseinfo function for %s, using cinfo_simple fallback.\n", c->type->cname);
|
log_error("no curseinfo function for %s, using cinfo_simple fallback.\n", c->type->cname);
|
||||||
}
|
}
|
||||||
return msg;
|
return msg;
|
||||||
|
@ -1063,7 +1089,8 @@ static void get_addresses(report_context * ctx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (sr->mode == see_travel) {
|
}
|
||||||
|
else if (sr->mode == see_travel) {
|
||||||
unit *u = r->units;
|
unit *u = r->units;
|
||||||
while (u) {
|
while (u) {
|
||||||
faction *sf = visible_faction(ctx->f, u);
|
faction *sf = visible_faction(ctx->f, u);
|
||||||
|
@ -1084,7 +1111,8 @@ static void get_addresses(report_context * ctx)
|
||||||
}
|
}
|
||||||
u = u->next;
|
u = u->next;
|
||||||
}
|
}
|
||||||
} else if (sr->mode > see_travel) {
|
}
|
||||||
|
else if (sr->mode > see_travel) {
|
||||||
const unit *u = r->units;
|
const unit *u = r->units;
|
||||||
while (u != NULL) {
|
while (u != NULL) {
|
||||||
if (u->faction != ctx->f) {
|
if (u->faction != ctx->f) {
|
||||||
|
@ -1216,7 +1244,8 @@ add_seen(struct seen_region *seehash[], struct region *r, unsigned char mode,
|
||||||
find->nextHash = seehash[index];
|
find->nextHash = seehash[index];
|
||||||
seehash[index] = find;
|
seehash[index] = find;
|
||||||
find->r = r;
|
find->r = r;
|
||||||
} else if (find->mode >= mode) {
|
}
|
||||||
|
else if (find->mode >= mode) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
find->mode = mode;
|
find->mode = mode;
|
||||||
|
@ -1355,7 +1384,8 @@ recurse_regatta(struct seen_region **seen, region * center, region * r,
|
||||||
if (add_seen(seen, r2, see_far, false)) {
|
if (add_seen(seen, r2, see_far, false)) {
|
||||||
recurse_regatta(seen, center, r2, f, maxdist);
|
recurse_regatta(seen, center, r2, f, maxdist);
|
||||||
}
|
}
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
add_seen(seen, r2, see_neighbour, false);
|
add_seen(seen, r2, see_neighbour, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1422,7 +1452,8 @@ void reorder_units(region * r)
|
||||||
*umove = u->next;
|
*umove = u->next;
|
||||||
u->next = *uinsert;
|
u->next = *uinsert;
|
||||||
*uinsert = u;
|
*uinsert = u;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
/* no need to move, skip ahead */
|
/* no need to move, skip ahead */
|
||||||
umove = &u->next;
|
umove = &u->next;
|
||||||
}
|
}
|
||||||
|
@ -1430,7 +1461,8 @@ void reorder_units(region * r)
|
||||||
/* we have a new well-placed unit. jump over it */
|
/* we have a new well-placed unit. jump over it */
|
||||||
unext = &u->next;
|
unext = &u->next;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
umove = &u->next;
|
umove = &u->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1449,13 +1481,15 @@ void reorder_units(region * r)
|
||||||
*umove = u->next;
|
*umove = u->next;
|
||||||
u->next = *unext;
|
u->next = *unext;
|
||||||
*unext = u;
|
*unext = u;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
/* no need to move, skip ahead */
|
/* no need to move, skip ahead */
|
||||||
umove = &u->next;
|
umove = &u->next;
|
||||||
}
|
}
|
||||||
/* we have a new well-placed unit. jump over it */
|
/* we have a new well-placed unit. jump over it */
|
||||||
unext = &u->next;
|
unext = &u->next;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
umove = &u->next;
|
umove = &u->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1476,7 +1510,8 @@ void reorder_units(region * r)
|
||||||
*umove = u->next;
|
*umove = u->next;
|
||||||
u->next = *uinsert;
|
u->next = *uinsert;
|
||||||
*uinsert = u;
|
*uinsert = u;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
/* no need to move, skip ahead */
|
/* no need to move, skip ahead */
|
||||||
umove = &u->next;
|
umove = &u->next;
|
||||||
}
|
}
|
||||||
|
@ -1484,7 +1519,8 @@ void reorder_units(region * r)
|
||||||
/* we have a new well-placed unit. jump over it */
|
/* we have a new well-placed unit. jump over it */
|
||||||
unext = &u->next;
|
unext = &u->next;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
umove = &u->next;
|
umove = &u->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1671,7 +1707,8 @@ static void nmr_warnings(void)
|
||||||
if (f->alliance && f->alliance == fa->alliance) {
|
if (f->alliance && f->alliance == fa->alliance) {
|
||||||
warn = 1;
|
warn = 1;
|
||||||
}
|
}
|
||||||
} else if (alliedfaction(NULL, f, fa, FRIEND)
|
}
|
||||||
|
else if (alliedfaction(NULL, f, fa, FRIEND)
|
||||||
&& alliedfaction(NULL, fa, f, FRIEND)) {
|
&& alliedfaction(NULL, fa, f, FRIEND)) {
|
||||||
warn = 1;
|
warn = 1;
|
||||||
}
|
}
|
||||||
|
@ -1872,7 +1909,8 @@ f_regionid(const region * r, const faction * f, char *buffer, size_t size)
|
||||||
size_t len;
|
size_t len;
|
||||||
if (!r) {
|
if (!r) {
|
||||||
len = strlcpy(buffer, "(Chaos)", size);
|
len = strlcpy(buffer, "(Chaos)", size);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
plane *pl = rplane(r);
|
plane *pl = rplane(r);
|
||||||
const char *name = pl ? pl->name : 0;
|
const char *name = pl ? pl->name : 0;
|
||||||
int nx = r->x, ny = r->y;
|
int nx = r->x, ny = r->y;
|
||||||
|
@ -2022,7 +2060,8 @@ static void eval_alliance(struct opstack **stack, const void *userdata)
|
||||||
if (c != NULL) {
|
if (c != NULL) {
|
||||||
size_t len = strlen(c);
|
size_t len = strlen(c);
|
||||||
var.v = strcpy(balloc(len + 1), c);
|
var.v = strcpy(balloc(len + 1), c);
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
var.v = NULL;
|
var.v = NULL;
|
||||||
opush(stack, var);
|
opush(stack, var);
|
||||||
}
|
}
|
||||||
|
@ -2087,14 +2126,17 @@ static void eval_weight(struct opstack **stack, const void *userdata)
|
||||||
if (weight % SCALEWEIGHT == 0) {
|
if (weight % SCALEWEIGHT == 0) {
|
||||||
if (weight == SCALEWEIGHT) {
|
if (weight == SCALEWEIGHT) {
|
||||||
sprintf(buffer, "1 %s", LOC(lang, "weight_unit"));
|
sprintf(buffer, "1 %s", LOC(lang, "weight_unit"));
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
sprintf(buffer, "%u %s", weight / SCALEWEIGHT, LOC(lang,
|
sprintf(buffer, "%u %s", weight / SCALEWEIGHT, LOC(lang,
|
||||||
"weight_unit_p"));
|
"weight_unit_p"));
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
if (weight == 1) {
|
if (weight == 1) {
|
||||||
sprintf(buffer, "1 %s %u", LOC(lang, "weight_per"), SCALEWEIGHT);
|
sprintf(buffer, "1 %s %u", LOC(lang, "weight_per"), SCALEWEIGHT);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
sprintf(buffer, "%u %s %u", weight, LOC(lang, "weight_per_p"),
|
sprintf(buffer, "%u %s %u", weight, LOC(lang, "weight_per_p"),
|
||||||
SCALEWEIGHT);
|
SCALEWEIGHT);
|
||||||
}
|
}
|
||||||
|
@ -2190,7 +2232,8 @@ static void eval_regions(struct opstack **stack, const void *userdata)
|
||||||
|
|
||||||
if (regions == NULL) {
|
if (regions == NULL) {
|
||||||
end = begin;
|
end = begin;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
if (i >= 0)
|
if (i >= 0)
|
||||||
end = begin + i;
|
end = begin + i;
|
||||||
else
|
else
|
||||||
|
@ -2240,9 +2283,11 @@ static void eval_trail(struct opstack **stack, const void *userdata)
|
||||||
|
|
||||||
if (i + 2 < end) {
|
if (i + 2 < end) {
|
||||||
bytes = (int)strlcpy(bufp, ", ", size);
|
bytes = (int)strlcpy(bufp, ", ", size);
|
||||||
} else if (i + 1 < end) {
|
}
|
||||||
|
else if (i + 1 < end) {
|
||||||
bytes = (int)strlcpy(bufp, LOC(lang, "list_and"), size);
|
bytes = (int)strlcpy(bufp, LOC(lang, "list_and"), size);
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
bytes = 0;
|
bytes = 0;
|
||||||
|
|
||||||
if (bytes && wrptr(&bufp, &size, bytes) != 0)
|
if (bytes && wrptr(&bufp, &size, bytes) != 0)
|
||||||
|
@ -2338,17 +2383,20 @@ int report_action(region * r, unit * actor, message * msg, int flags)
|
||||||
/* Bei Fernzaubern sieht nur die eigene Partei den Magier */
|
/* Bei Fernzaubern sieht nur die eigene Partei den Magier */
|
||||||
show = show || (r == actor->region
|
show = show || (r == actor->region
|
||||||
&& cansee(u->faction, r, actor, 0));
|
&& cansee(u->faction, r, actor, 0));
|
||||||
} else if (view == ACTION_CANNOTSEE) {
|
}
|
||||||
|
else if (view == ACTION_CANNOTSEE) {
|
||||||
show = !show && !(r == actor->region
|
show = !show && !(r == actor->region
|
||||||
&& cansee(u->faction, r, actor, 0));
|
&& cansee(u->faction, r, actor, 0));
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
/* the unliely (or lazy) case */
|
/* the unliely (or lazy) case */
|
||||||
show = true;
|
show = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (show) {
|
if (show) {
|
||||||
r_addmessage(r, u->faction, msg);
|
r_addmessage(r, u->faction, msg);
|
||||||
} else { /* Partei des Magiers, sieht diesen immer */
|
}
|
||||||
|
else { /* Partei des Magiers, sieht diesen immer */
|
||||||
result = 1;
|
result = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,10 +10,19 @@
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
static const char * keyword_key(int i)
|
const char * keyword(keyword_t kwd)
|
||||||
{
|
{
|
||||||
assert(i<MAXKEYWORDS&& i>=0);
|
static char result[KEYWORDSIZE];
|
||||||
return mkname("keyword", keywords[i]);
|
if (!result[0]) {
|
||||||
|
strcpy(result, "keyword::");
|
||||||
|
}
|
||||||
|
strcpy(result+9, keywords[kwd]);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char * keyword_key(int kwd) {
|
||||||
|
assert(kwd < MAXKEYWORDS && kwd >= 0);
|
||||||
|
return keyword((keyword_t)kwd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_keyword(const struct locale *lang, keyword_t kwd, const char *str) {
|
void init_keyword(const struct locale *lang, keyword_t kwd, const char *str) {
|
||||||
|
|
|
@ -80,7 +80,8 @@ void init_keywords(const struct locale *lang);
|
||||||
void init_keyword(const struct locale *lang, keyword_t kwd, const char *str);
|
void init_keyword(const struct locale *lang, keyword_t kwd, const char *str);
|
||||||
bool keyword_disabled(keyword_t kwd);
|
bool keyword_disabled(keyword_t kwd);
|
||||||
void enable_keyword(keyword_t kwd, bool enabled);
|
void enable_keyword(keyword_t kwd, bool enabled);
|
||||||
#define keyword(kwd) mkname("keyword", keywords[kwd])
|
const char *keyword(keyword_t kwd);
|
||||||
|
// #define keyword(kwd) mkname("keyword", keywords[kwd])
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -53,7 +53,8 @@ void init_tokens_str(const char *initstr, char *cmd)
|
||||||
{
|
{
|
||||||
if (states == NULL) {
|
if (states == NULL) {
|
||||||
states = malloc(sizeof(parser_state));
|
states = malloc(sizeof(parser_state));
|
||||||
} else if (states->current_cmd) {
|
}
|
||||||
|
else if (states->current_cmd && states->current_cmd!=cmd) {
|
||||||
free(states->current_cmd);
|
free(states->current_cmd);
|
||||||
}
|
}
|
||||||
states->current_cmd = cmd;
|
states->current_cmd = cmd;
|
||||||
|
|
Loading…
Reference in New Issue