forked from github/server
add param.[hc], at last.
This commit is contained in:
parent
bc5f2ea6d1
commit
d3a37179ef
34 changed files with 317 additions and 246 deletions
|
@ -20,7 +20,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#ifdef _MSC_VER
|
||||
#include <platform.h>
|
||||
#endif
|
||||
#include <kernel/config.h>
|
||||
|
||||
#include "economy.h"
|
||||
|
||||
#include "alchemy.h"
|
||||
|
@ -45,10 +45,13 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
|
||||
/* kernel includes */
|
||||
#include "kernel/ally.h"
|
||||
#include "kernel/attrib.h"
|
||||
#include "kernel/building.h"
|
||||
#include "kernel/calendar.h"
|
||||
#include "kernel/config.h"
|
||||
#include "kernel/curse.h"
|
||||
#include "kernel/equipment.h"
|
||||
#include "kernel/event.h"
|
||||
#include "kernel/faction.h"
|
||||
#include "kernel/item.h"
|
||||
#include "kernel/messages.h"
|
||||
|
@ -64,13 +67,12 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include "kernel/unit.h"
|
||||
|
||||
/* util includes */
|
||||
#include <kernel/attrib.h>
|
||||
#include <util/base36.h>
|
||||
#include <kernel/event.h>
|
||||
#include <util/goodies.h>
|
||||
#include <util/language.h>
|
||||
#include <util/lists.h>
|
||||
#include <util/log.h>
|
||||
#include "util/param.h"
|
||||
#include <util/parser.h>
|
||||
#include <util/rng.h>
|
||||
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
#include <attributes/racename.h>
|
||||
|
||||
/* kernel includes */
|
||||
#include <kernel/attrib.h>
|
||||
#include <kernel/event.h>
|
||||
#include <kernel/ally.h>
|
||||
#include <kernel/build.h>
|
||||
#include <kernel/curse.h>
|
||||
|
@ -41,11 +43,10 @@
|
|||
#include <kernel/unit.h>
|
||||
|
||||
/* util includes */
|
||||
#include <kernel/attrib.h>
|
||||
#include <util/base36.h>
|
||||
#include <kernel/event.h>
|
||||
#include <util/log.h>
|
||||
#include <util/macros.h>
|
||||
#include <util/param.h>
|
||||
#include <util/parser.h>
|
||||
|
||||
/* libc includes */
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include <util/base36.h>
|
||||
#include <util/language.h>
|
||||
#include <util/message.h>
|
||||
#include <util/param.h>
|
||||
|
||||
#include <CuTest.h>
|
||||
#include <tests.h>
|
||||
|
|
|
@ -33,10 +33,12 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
/* kernel includes */
|
||||
#include <kernel/ally.h>
|
||||
#include <kernel/alliance.h>
|
||||
#include <kernel/connection.h>
|
||||
#include <kernel/attrib.h>
|
||||
#include <kernel/building.h>
|
||||
#include <kernel/config.h>
|
||||
#include <kernel/connection.h>
|
||||
#include <kernel/curse.h>
|
||||
#include <kernel/event.h>
|
||||
#include <kernel/faction.h>
|
||||
#include <kernel/group.h>
|
||||
#include <kernel/item.h>
|
||||
|
@ -52,12 +54,11 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <kernel/unit.h>
|
||||
|
||||
/* from libutil */
|
||||
#include <kernel/attrib.h>
|
||||
#include <util/base36.h>
|
||||
#include <kernel/event.h>
|
||||
#include <util/goodies.h>
|
||||
#include <util/language.h>
|
||||
#include <util/log.h>
|
||||
#include <util/param.h>
|
||||
#include <util/parser.h>
|
||||
#include <util/resolve.h>
|
||||
|
||||
|
|
|
@ -1,19 +1,24 @@
|
|||
#ifdef _MSC_VER
|
||||
#include <platform.h>
|
||||
#include <kernel/config.h>
|
||||
#endif
|
||||
|
||||
#include <kernel/messages.h>
|
||||
#include "alchemy.h"
|
||||
#include "types.h"
|
||||
#include "build.h"
|
||||
#include "guard.h"
|
||||
#include "order.h"
|
||||
#include "unit.h"
|
||||
#include "building.h"
|
||||
#include "config.h"
|
||||
#include "faction.h"
|
||||
#include "region.h"
|
||||
#include "race.h"
|
||||
#include "guard.h"
|
||||
#include "item.h"
|
||||
#include <util/language.h>
|
||||
#include "messages.h"
|
||||
#include "order.h"
|
||||
#include "race.h"
|
||||
#include "region.h"
|
||||
#include "types.h"
|
||||
#include "unit.h"
|
||||
|
||||
#include "util/language.h"
|
||||
#include "util/param.h"
|
||||
|
||||
#include <CuTest.h>
|
||||
#include <tests.h>
|
||||
|
||||
|
|
|
@ -45,6 +45,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <kernel/gamedata.h>
|
||||
#include <util/language.h>
|
||||
#include <util/log.h>
|
||||
#include <util/param.h>
|
||||
#include <util/resolve.h>
|
||||
#include <util/strings.h>
|
||||
#include <util/umlaut.h>
|
||||
|
|
|
@ -60,6 +60,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <util/log.h>
|
||||
#include <util/lists.h>
|
||||
#include <util/macros.h>
|
||||
#include <util/param.h>
|
||||
#include <util/parser.h>
|
||||
#include <util/path.h>
|
||||
#include <util/rand.h>
|
||||
|
@ -92,54 +93,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#endif
|
||||
struct settings global;
|
||||
|
||||
const char *parameters[MAXPARAMS] = {
|
||||
"LOCALE",
|
||||
"ALLES",
|
||||
"JEDEM",
|
||||
"BAUERN",
|
||||
"BURG",
|
||||
"EINHEIT",
|
||||
"PRIVAT",
|
||||
"HINTEN",
|
||||
"KOMMANDO",
|
||||
"KRAEUTER",
|
||||
"NICHT",
|
||||
"NAECHSTER",
|
||||
"PARTEI",
|
||||
"ERESSEA",
|
||||
"PERSONEN",
|
||||
"REGION",
|
||||
"SCHIFF",
|
||||
"SILBER",
|
||||
"STRASSEN",
|
||||
"TEMP",
|
||||
"FLIEHE",
|
||||
"GEBAEUDE",
|
||||
"GIB", /* HELFE GIB */
|
||||
"KAEMPFE",
|
||||
"DURCHREISE",
|
||||
"BEWACHE",
|
||||
"ZAUBER",
|
||||
"PAUSE",
|
||||
"VORNE",
|
||||
"AGGRESSIV",
|
||||
"DEFENSIV",
|
||||
"STUFE",
|
||||
"HELFE",
|
||||
"FREMDES",
|
||||
"AURA",
|
||||
"HINTER",
|
||||
"VOR",
|
||||
"ANZAHL",
|
||||
"GEGENSTAENDE",
|
||||
"TRAENKE",
|
||||
"GRUPPE",
|
||||
"PARTEITARNUNG",
|
||||
"BAEUME",
|
||||
"ALLIANZ",
|
||||
"AUTO"
|
||||
};
|
||||
|
||||
int findoption(const char *s, const struct locale *lang)
|
||||
{
|
||||
void **tokens = get_translations(lang, UT_OPTIONS);
|
||||
|
@ -151,78 +104,6 @@ int findoption(const char *s, const struct locale *lang)
|
|||
return NODIRECTION;
|
||||
}
|
||||
|
||||
param_t findparam(const char *s, const struct locale * lang)
|
||||
{
|
||||
param_t result = NOPARAM;
|
||||
char buffer[64];
|
||||
char * str = s ? transliterate(buffer, sizeof(buffer) - sizeof(int), s) : 0;
|
||||
|
||||
if (str && *str) {
|
||||
int i;
|
||||
void * match;
|
||||
void **tokens = get_translations(lang, UT_PARAMS);
|
||||
critbit_tree *cb = (critbit_tree *)*tokens;
|
||||
if (!cb) {
|
||||
log_warning("no parameters defined in locale %s", locale_name(lang));
|
||||
}
|
||||
else if (cb_find_prefix(cb, str, strlen(str), &match, 1, 0)) {
|
||||
cb_get_kv(match, &i, sizeof(int));
|
||||
result = (param_t)i;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
param_t findparam_block(const char *s, const struct locale *lang, bool any_locale)
|
||||
{
|
||||
param_t p;
|
||||
if (!s || s[0] == '@') {
|
||||
return NOPARAM;
|
||||
}
|
||||
p = findparam(s, lang);
|
||||
if (any_locale && p==NOPARAM) {
|
||||
const struct locale *loc;
|
||||
for (loc=locales;loc;loc=nextlocale(loc)) {
|
||||
if (loc!=lang) {
|
||||
p = findparam(s, loc);
|
||||
if (p==P_FACTION || p==P_GAMENAME) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
param_t findparam_ex(const char *s, const struct locale * lang)
|
||||
{
|
||||
param_t result = findparam(s, lang);
|
||||
|
||||
if (result == NOPARAM) {
|
||||
const building_type *btype = findbuildingtype(s, lang);
|
||||
if (btype != NULL)
|
||||
return P_GEBAEUDE;
|
||||
}
|
||||
return (result == P_BUILDING) ? P_GEBAEUDE : result;
|
||||
}
|
||||
|
||||
bool isparam(const char *s, const struct locale * lang, param_t param)
|
||||
{
|
||||
assert(s);
|
||||
if (s[0] > '@') {
|
||||
param_t p = (param == P_GEBAEUDE) ? findparam_ex(s, lang) : findparam(s, lang);
|
||||
return p == param;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
param_t getparam(const struct locale * lang)
|
||||
{
|
||||
char token[64];
|
||||
const char *s = gettoken(token, sizeof(token));
|
||||
return s ? findparam(s, lang) : NOPARAM;
|
||||
}
|
||||
|
||||
/* -- Erschaffung neuer Einheiten ------------------------------ */
|
||||
|
||||
static const char *forbidden[] = { "t", "te", "tem", "temp", NULL };
|
||||
|
@ -268,17 +149,6 @@ int newcontainerid(void)
|
|||
return random_no;
|
||||
}
|
||||
|
||||
static const char * parameter_key(int i)
|
||||
{
|
||||
assert(i < MAXPARAMS && i >= 0);
|
||||
return parameters[i];
|
||||
}
|
||||
|
||||
void init_parameters(struct locale *lang) {
|
||||
init_translations(lang, UT_PARAMS, parameter_key, MAXPARAMS);
|
||||
}
|
||||
|
||||
|
||||
void init_terrains_translation(const struct locale *lang) {
|
||||
void **tokens;
|
||||
const terrain_type *terrain;
|
||||
|
|
|
@ -44,12 +44,6 @@ extern "C" {
|
|||
|
||||
int findoption(const char *s, const struct locale *lang);
|
||||
|
||||
param_t findparam(const char *s, const struct locale *lang);
|
||||
param_t findparam_block(const char *s, const struct locale *lang, bool any_locale);
|
||||
param_t findparam_ex(const char *s, const struct locale * lang);
|
||||
bool isparam(const char *s, const struct locale * lang, param_t param);
|
||||
param_t getparam(const struct locale *lang);
|
||||
|
||||
const char * game_name(void);
|
||||
const char * game_mailcmd(void);
|
||||
int game_id(void);
|
||||
|
@ -132,12 +126,9 @@ extern "C" {
|
|||
|
||||
struct order *default_order(const struct locale *lang);
|
||||
|
||||
void init_parameters(struct locale *lang);
|
||||
|
||||
void free_gamedata(void);
|
||||
void free_config(void);
|
||||
|
||||
extern const char *parameters[];
|
||||
extern settings global;
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -5,8 +5,11 @@
|
|||
#include <kernel/terrain.h>
|
||||
#include <kernel/unit.h>
|
||||
#include <kernel/order.h>
|
||||
#include <util/language.h>
|
||||
|
||||
#include <util/base36.h>
|
||||
#include <util/language.h>
|
||||
#include <util/param.h>
|
||||
|
||||
#include <kernel/attrib.h>
|
||||
|
||||
#include <iniparser.h>
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "util/keyword.h"
|
||||
#include <util/language.h>
|
||||
#include <util/log.h>
|
||||
#include <util/param.h>
|
||||
#include <util/parser.h>
|
||||
#include <util/strings.h>
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <kernel/skills.h>
|
||||
#include <kernel/unit.h>
|
||||
|
||||
#include "util/param.h"
|
||||
#include <util/parser.h>
|
||||
#include <util/language.h>
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <util/language.h>
|
||||
#include <util/lists.h>
|
||||
#include <util/log.h>
|
||||
#include <util/param.h>
|
||||
#include <util/strings.h>
|
||||
#include <util/umlaut.h>
|
||||
|
||||
|
|
|
@ -83,58 +83,6 @@ typedef enum {
|
|||
ST_FLEE
|
||||
} status_t;
|
||||
|
||||
/* ----------------- Parameter --------------------------------- */
|
||||
|
||||
typedef enum {
|
||||
P_LOCALE,
|
||||
P_ANY,
|
||||
P_EACH,
|
||||
P_PEASANT,
|
||||
P_BUILDING,
|
||||
P_UNIT,
|
||||
P_PRIVAT,
|
||||
P_BEHIND,
|
||||
P_CONTROL,
|
||||
P_HERBS,
|
||||
P_NOT,
|
||||
P_NEXT,
|
||||
P_FACTION,
|
||||
P_GAMENAME,
|
||||
P_PERSON,
|
||||
P_REGION,
|
||||
P_SHIP,
|
||||
P_MONEY,
|
||||
P_ROAD,
|
||||
P_TEMP,
|
||||
P_FLEE,
|
||||
P_GEBAEUDE,
|
||||
P_GIVE,
|
||||
P_FIGHT,
|
||||
P_TRAVEL,
|
||||
P_GUARD,
|
||||
P_ZAUBER,
|
||||
P_PAUSE,
|
||||
P_VORNE,
|
||||
P_AGGRO,
|
||||
P_CHICKEN,
|
||||
P_LEVEL,
|
||||
P_HELP,
|
||||
P_FOREIGN,
|
||||
P_AURA,
|
||||
P_AFTER,
|
||||
P_BEFORE,
|
||||
P_NUMBER,
|
||||
P_ITEMS,
|
||||
P_POTIONS,
|
||||
P_GROUP,
|
||||
P_FACTIONSTEALTH,
|
||||
P_TREES,
|
||||
P_ALLIANCE,
|
||||
P_AUTO,
|
||||
MAXPARAMS,
|
||||
NOPARAM
|
||||
} param_t;
|
||||
|
||||
typedef enum { /* Fehler und Meldungen im Report */
|
||||
MSG_BATTLE,
|
||||
MSG_EVENT,
|
||||
|
@ -156,8 +104,6 @@ enum { /* Message-Level */
|
|||
ML_MAX
|
||||
};
|
||||
|
||||
extern const char *parameters[MAXPARAMS];
|
||||
|
||||
/* --------------- Reports Typen ------------------------------- */
|
||||
|
||||
enum {
|
||||
|
|
|
@ -21,12 +21,16 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include "unit.h"
|
||||
|
||||
#include "ally.h"
|
||||
#include "attrib.h"
|
||||
#include "building.h"
|
||||
#include "calendar.h"
|
||||
#include "faction.h"
|
||||
#include "group.h"
|
||||
#include "connection.h"
|
||||
#include "curse.h"
|
||||
#include "event.h"
|
||||
#include "faction.h"
|
||||
#include "gamedata.h"
|
||||
#include "group.h"
|
||||
#include "guard.h"
|
||||
#include "item.h"
|
||||
#include "move.h"
|
||||
#include "order.h"
|
||||
|
@ -47,18 +51,13 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <spells/unitcurse.h>
|
||||
#include <spells/regioncurse.h>
|
||||
|
||||
#include "guard.h"
|
||||
|
||||
/* util includes */
|
||||
#include <kernel/attrib.h>
|
||||
#include <util/base36.h>
|
||||
#include <kernel/event.h>
|
||||
#include <kernel/gamedata.h>
|
||||
#include <util/strings.h>
|
||||
#include <util/language.h>
|
||||
#include <util/lists.h>
|
||||
#include <util/log.h>
|
||||
#include <util/macros.h>
|
||||
#include <util/param.h>
|
||||
#include <util/parser.h>
|
||||
#include <util/rand.h>
|
||||
#include <util/resolve.h>
|
||||
|
|
13
src/laws.c
13
src/laws.c
|
@ -80,6 +80,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <util/log.h>
|
||||
#include <util/macros.h>
|
||||
#include <util/message.h>
|
||||
#include <util/param.h>
|
||||
#include <util/parser.h>
|
||||
#include <util/password.h>
|
||||
#include <util/path.h>
|
||||
|
@ -127,7 +128,17 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#define DMRISE 0.1F /* weekly chance that demand goes up */
|
||||
#define DMRISEHAFEN 0.2F /* weekly chance that demand goes up with harbor */
|
||||
|
||||
/* - exported global symbols ----------------------------------- */
|
||||
param_t findparam_ex(const char *s, const struct locale * lang)
|
||||
{
|
||||
param_t result = findparam(s, lang);
|
||||
|
||||
if (result == NOPARAM) {
|
||||
const building_type *btype = findbuildingtype(s, lang);
|
||||
if (btype != NULL)
|
||||
return P_GEBAEUDE;
|
||||
}
|
||||
return (result == P_BUILDING) ? P_GEBAEUDE : result;
|
||||
}
|
||||
|
||||
int NewbieImmunity(void)
|
||||
{
|
||||
|
|
|
@ -19,13 +19,14 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#ifndef H_GC_LAWS
|
||||
#define H_GC_LAWS
|
||||
|
||||
#include <kernel/types.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
enum param_t;
|
||||
|
||||
struct locale;
|
||||
struct unit;
|
||||
struct region;
|
||||
struct building;
|
||||
|
@ -115,6 +116,8 @@ extern "C" {
|
|||
bool IsImmune(const struct faction *f);
|
||||
bool help_enter(struct unit *uo, struct unit *u);
|
||||
|
||||
enum param_t findparam_ex(const char *s, const struct locale * lang);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include <util/base36.h>
|
||||
#include <util/language.h>
|
||||
#include <util/message.h>
|
||||
#include <util/param.h>
|
||||
#include <util/rand.h>
|
||||
|
||||
#include <CuTest.h>
|
||||
|
|
|
@ -70,6 +70,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <util/lists.h>
|
||||
#include <util/log.h>
|
||||
#include <util/macros.h>
|
||||
#include <util/param.h>
|
||||
#include <util/parser.h>
|
||||
#include <util/rand.h>
|
||||
#include <util/resolve.h>
|
||||
|
|
|
@ -23,6 +23,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
|
||||
/* kernel includes */
|
||||
#include "kernel/ally.h"
|
||||
#include "kernel/attrib.h"
|
||||
#include "kernel/build.h"
|
||||
#include "kernel/building.h"
|
||||
#include "kernel/calendar.h"
|
||||
|
@ -30,6 +31,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include "kernel/connection.h"
|
||||
#include "kernel/curse.h"
|
||||
#include "kernel/faction.h"
|
||||
#include "kernel/gamedata.h"
|
||||
#include "kernel/item.h"
|
||||
#include "kernel/messages.h"
|
||||
#include "kernel/order.h"
|
||||
|
@ -72,13 +74,12 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
|
||||
/* util includes */
|
||||
#include <util/assert.h>
|
||||
#include <kernel/attrib.h>
|
||||
#include <util/base36.h>
|
||||
#include <kernel/gamedata.h>
|
||||
#include <util/language.h>
|
||||
#include <util/lists.h>
|
||||
#include <util/log.h>
|
||||
#include <util/macros.h>
|
||||
#include <util/param.h>
|
||||
#include <util/parser.h>
|
||||
#include <util/rand.h>
|
||||
#include <util/rng.h>
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#include <platform.h>
|
||||
#include <kernel/config.h>
|
||||
#include "orderfile.h"
|
||||
|
||||
#include "kernel/calendar.h"
|
||||
|
@ -8,12 +7,14 @@
|
|||
#include "kernel/order.h"
|
||||
#include "kernel/unit.h"
|
||||
|
||||
#include <util/base36.h>
|
||||
#include <util/message.h>
|
||||
#include <util/language.h>
|
||||
#include <util/log.h>
|
||||
#include <util/filereader.h>
|
||||
#include <util/parser.h>
|
||||
#include "util/base36.h"
|
||||
#include "util/message.h"
|
||||
#include "util/language.h"
|
||||
#include "util/log.h"
|
||||
#include "util/filereader.h"
|
||||
#include "util/param.h"
|
||||
#include "util/parser.h"
|
||||
#include "util/order_parser.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
@ -33,9 +34,9 @@ static unit *unitorders(input *in, faction *f)
|
|||
if (u && u->faction == f) {
|
||||
order **ordp;
|
||||
|
||||
if (!fval(u, UFL_ORDERS)) {
|
||||
if (u->flags & UFL_ORDERS) {
|
||||
/* alle wiederholbaren, langen befehle werden gesichert: */
|
||||
fset(u, UFL_ORDERS);
|
||||
u->flags |= UFL_ORDERS;
|
||||
u->old_orders = u->orders;
|
||||
ordp = &u->old_orders;
|
||||
while (*ordp) {
|
||||
|
@ -125,7 +126,7 @@ static faction *factionorders(void)
|
|||
int fid = getid();
|
||||
faction *f = findfaction(fid);
|
||||
|
||||
if (f != NULL && !fval(f, FFL_NPC)) {
|
||||
if (f != NULL && (f->flags & FFL_NPC) == 0) {
|
||||
char token[128];
|
||||
const char *pass = gettoken(token, sizeof(token));
|
||||
|
||||
|
@ -151,6 +152,10 @@ int read_orders(input *in)
|
|||
int nfactions = 0;
|
||||
struct faction *f = NULL;
|
||||
const struct locale *lang = default_locale;
|
||||
OP_Parser parser;
|
||||
|
||||
parser = OP_ParserCreate();
|
||||
OP_ParserFree(parser);
|
||||
|
||||
/* TODO: recognize UTF8 BOM */
|
||||
b = in->getbuf(in->data);
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
#include <platform.h>
|
||||
#include "renumber.h"
|
||||
|
||||
#include "laws.h"
|
||||
|
||||
#include <kernel/attrib.h>
|
||||
#include <kernel/config.h>
|
||||
#include <kernel/faction.h>
|
||||
#include <kernel/building.h>
|
||||
|
@ -9,8 +12,8 @@
|
|||
#include <kernel/order.h>
|
||||
#include <kernel/messages.h>
|
||||
|
||||
#include <kernel/attrib.h>
|
||||
#include <util/base36.h>
|
||||
#include <util/param.h>
|
||||
#include <util/parser.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <util/base36.h>
|
||||
#include <util/language.h>
|
||||
#include <util/message.h>
|
||||
#include <util/param.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <CuTest.h>
|
||||
|
|
|
@ -19,7 +19,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#ifdef _MSC_VER
|
||||
#include <platform.h>
|
||||
#endif
|
||||
#include <kernel/config.h>
|
||||
|
||||
#include "report.h"
|
||||
#include "reports.h"
|
||||
|
@ -50,8 +49,11 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include "teleport.h"
|
||||
|
||||
/* kernel includes */
|
||||
#include "kernel/alliance.h"
|
||||
#include "kernel/ally.h"
|
||||
#include "kernel/attrib.h"
|
||||
#include "kernel/calendar.h"
|
||||
#include "kernel/config.h"
|
||||
#include "kernel/connection.h"
|
||||
#include "kernel/build.h"
|
||||
#include "kernel/building.h"
|
||||
|
@ -74,10 +76,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include "kernel/terrain.h"
|
||||
#include "kernel/terrainid.h"
|
||||
#include "kernel/unit.h"
|
||||
#include "kernel/alliance.h"
|
||||
|
||||
/* util includes */
|
||||
#include <kernel/attrib.h>
|
||||
#include <util/base36.h>
|
||||
#include "util/bsdstring.h"
|
||||
#include <util/goodies.h>
|
||||
|
@ -86,6 +86,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <util/log.h>
|
||||
#include <util/message.h>
|
||||
#include <util/nrmessage.h>
|
||||
#include "util/param.h"
|
||||
#include <util/rng.h>
|
||||
#include <util/strings.h>
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#include "reports.h"
|
||||
|
||||
#include "guard.h"
|
||||
#include "keyword.h"
|
||||
#include "util/keyword.h"
|
||||
#include "lighthouse.h"
|
||||
#include "laws.h"
|
||||
#include "move.h"
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
#include <util/umlaut.h>
|
||||
#include <util/language.h>
|
||||
#include <util/log.h>
|
||||
#include <util/param.h>
|
||||
|
||||
#include <critbit.h>
|
||||
|
||||
#include <string.h>
|
||||
|
|
|
@ -27,6 +27,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include "study.h"
|
||||
|
||||
/* kernel includes */
|
||||
#include <kernel/attrib.h>
|
||||
#include <kernel/config.h>
|
||||
#include <kernel/item.h>
|
||||
#include <kernel/faction.h>
|
||||
|
@ -44,8 +45,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <attributes/stealth.h>
|
||||
|
||||
/* util includes */
|
||||
#include <kernel/attrib.h>
|
||||
#include <util/base36.h>
|
||||
#include <util/param.h>
|
||||
#include <util/parser.h>
|
||||
#include <util/rand.h>
|
||||
#include <util/rng.h>
|
||||
|
|
|
@ -12,8 +12,10 @@
|
|||
#include <kernel/item.h>
|
||||
#include <kernel/messages.h>
|
||||
#include <kernel/attrib.h>
|
||||
|
||||
#include <util/language.h>
|
||||
#include <util/message.h>
|
||||
#include "util/param.h"
|
||||
#include <util/crmessage.h>
|
||||
#include <tests.h>
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <spells/regioncurse.h>
|
||||
|
||||
#include <kernel/ally.h>
|
||||
#include <kernel/attrib.h>
|
||||
#include <kernel/building.h>
|
||||
#include <kernel/curse.h>
|
||||
#include <kernel/faction.h>
|
||||
|
@ -46,10 +47,10 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <kernel/unit.h>
|
||||
|
||||
/* util includes */
|
||||
#include <kernel/attrib.h>
|
||||
#include <util/base36.h>
|
||||
#include <util/language.h>
|
||||
#include <util/log.h>
|
||||
#include <util/param.h>
|
||||
#include <util/parser.h>
|
||||
#include <util/rand.h>
|
||||
#include <util/rng.h>
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
#include <platform.h>
|
||||
#include "tests.h"
|
||||
#include "keyword.h"
|
||||
#include "prefix.h"
|
||||
#include "reports.h"
|
||||
#include "kernel/calendar.h"
|
||||
#include "vortex.h"
|
||||
|
||||
#include "kernel/calendar.h"
|
||||
#include <kernel/config.h>
|
||||
#include <kernel/alliance.h>
|
||||
#include <kernel/equipment.h>
|
||||
|
@ -24,11 +23,14 @@
|
|||
#include <kernel/spell.h>
|
||||
#include <kernel/spellbook.h>
|
||||
#include <kernel/terrain.h>
|
||||
|
||||
#include <util/functions.h>
|
||||
#include "util/keyword.h"
|
||||
#include <util/language.h>
|
||||
#include <util/lists.h>
|
||||
#include <util/message.h>
|
||||
#include <util/log.h>
|
||||
#include "util/param.h"
|
||||
#include <util/rand.h>
|
||||
#include <util/assert.h>
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#ifndef ERESSEA_TESTS_H
|
||||
#define ERESSEA_TESTS_H
|
||||
|
||||
#include <kernel/types.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -10,6 +9,8 @@ extern "C" {
|
|||
|
||||
#define ASSERT_DBL_DELTA 0.001
|
||||
|
||||
enum param_t;
|
||||
|
||||
struct region;
|
||||
struct unit;
|
||||
struct faction;
|
||||
|
@ -61,7 +62,7 @@ extern "C" {
|
|||
struct spell * test_create_spell(void);
|
||||
int test_set_item(struct unit * u, const struct item_type *itype, int value);
|
||||
|
||||
void test_translate_param(const struct locale *lang, param_t param, const char *text);
|
||||
void test_translate_param(const struct locale *lang, enum param_t param, const char *text);
|
||||
const char * test_get_messagetype(const struct message *msg);
|
||||
struct message * test_find_messagetype_ex(struct message_list *msgs, const char *name, struct message *prev);
|
||||
struct message * test_find_messagetype(struct message_list *msgs, const char *name);
|
||||
|
|
|
@ -17,6 +17,7 @@ language.test.c
|
|||
message.test.c
|
||||
# nrmessage.test.c
|
||||
# order_parser.test.c
|
||||
# param.test.c
|
||||
parser.test.c
|
||||
password.test.c
|
||||
# rand.test.c
|
||||
|
@ -47,6 +48,7 @@ message.c
|
|||
mt19937ar.c
|
||||
nrmessage.c
|
||||
order_parser.c
|
||||
param.c
|
||||
parser.c
|
||||
password.c
|
||||
path.c
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#ifndef H_KEYWORD_H
|
||||
#define H_KEYWORD_H
|
||||
|
||||
#include "kernel/types.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
134
src/util/param.c
Normal file
134
src/util/param.c
Normal file
|
@ -0,0 +1,134 @@
|
|||
#ifdef _MSC_VER
|
||||
#include <platform.h>
|
||||
#endif
|
||||
|
||||
#include "language.h"
|
||||
#include "log.h"
|
||||
#include "param.h"
|
||||
#include "parser.h"
|
||||
#include "umlaut.h"
|
||||
|
||||
#include <critbit.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
const char *parameters[MAXPARAMS] = {
|
||||
"LOCALE",
|
||||
"ALLES",
|
||||
"JEDEM",
|
||||
"BAUERN",
|
||||
"BURG",
|
||||
"EINHEIT",
|
||||
"PRIVAT",
|
||||
"HINTEN",
|
||||
"KOMMANDO",
|
||||
"KRAEUTER",
|
||||
"NICHT",
|
||||
"NAECHSTER",
|
||||
"PARTEI",
|
||||
"ERESSEA",
|
||||
"PERSONEN",
|
||||
"REGION",
|
||||
"SCHIFF",
|
||||
"SILBER",
|
||||
"STRASSEN",
|
||||
"TEMP",
|
||||
"FLIEHE",
|
||||
"GEBAEUDE",
|
||||
"GIB", /* HELFE GIB */
|
||||
"KAEMPFE",
|
||||
"DURCHREISE",
|
||||
"BEWACHE",
|
||||
"ZAUBER",
|
||||
"PAUSE",
|
||||
"VORNE",
|
||||
"AGGRESSIV",
|
||||
"DEFENSIV",
|
||||
"STUFE",
|
||||
"HELFE",
|
||||
"FREMDES",
|
||||
"AURA",
|
||||
"HINTER",
|
||||
"VOR",
|
||||
"ANZAHL",
|
||||
"GEGENSTAENDE",
|
||||
"TRAENKE",
|
||||
"GRUPPE",
|
||||
"PARTEITARNUNG",
|
||||
"BAEUME",
|
||||
"ALLIANZ",
|
||||
"AUTO"
|
||||
};
|
||||
|
||||
param_t findparam(const char *s, const struct locale * lang)
|
||||
{
|
||||
param_t result = NOPARAM;
|
||||
char buffer[64];
|
||||
char * str = s ? transliterate(buffer, sizeof(buffer) - sizeof(int), s) : 0;
|
||||
|
||||
if (str && *str) {
|
||||
int i;
|
||||
void * match;
|
||||
void **tokens = get_translations(lang, UT_PARAMS);
|
||||
critbit_tree *cb = (critbit_tree *)*tokens;
|
||||
if (!cb) {
|
||||
log_warning("no parameters defined in locale %s", locale_name(lang));
|
||||
}
|
||||
else if (cb_find_prefix(cb, str, strlen(str), &match, 1, 0)) {
|
||||
cb_get_kv(match, &i, sizeof(int));
|
||||
result = (param_t)i;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
param_t findparam_block(const char *s, const struct locale *lang, bool any_locale)
|
||||
{
|
||||
param_t p;
|
||||
if (!s || s[0] == '@') {
|
||||
return NOPARAM;
|
||||
}
|
||||
p = findparam(s, lang);
|
||||
if (any_locale && p == NOPARAM) {
|
||||
const struct locale *loc;
|
||||
for (loc = locales; loc; loc = nextlocale(loc)) {
|
||||
if (loc != lang) {
|
||||
p = findparam(s, loc);
|
||||
if (p == P_FACTION || p == P_GAMENAME) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
bool isparam(const char *s, const struct locale * lang, param_t param)
|
||||
{
|
||||
assert(s);
|
||||
assert(param != P_GEBAEUDE);
|
||||
assert(param != P_BUILDING);
|
||||
if (s[0] > '@') {
|
||||
param_t p = findparam(s, lang);
|
||||
return p == param;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
param_t getparam(const struct locale * lang)
|
||||
{
|
||||
char token[64];
|
||||
const char *s = gettoken(token, sizeof(token));
|
||||
return s ? findparam(s, lang) : NOPARAM;
|
||||
}
|
||||
|
||||
static const char * parameter_key(int i)
|
||||
{
|
||||
assert(i < MAXPARAMS && i >= 0);
|
||||
return parameters[i];
|
||||
}
|
||||
|
||||
void init_parameters(struct locale *lang) {
|
||||
init_translations(lang, UT_PARAMS, parameter_key, MAXPARAMS);
|
||||
}
|
77
src/util/param.h
Normal file
77
src/util/param.h
Normal file
|
@ -0,0 +1,77 @@
|
|||
#pragma once
|
||||
|
||||
#ifndef H_PARAM_H
|
||||
#define H_PARAM_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct locale;
|
||||
|
||||
typedef enum param_t {
|
||||
P_LOCALE,
|
||||
P_ANY,
|
||||
P_EACH,
|
||||
P_PEASANT,
|
||||
P_BUILDING,
|
||||
P_UNIT,
|
||||
P_PRIVAT,
|
||||
P_BEHIND,
|
||||
P_CONTROL,
|
||||
P_HERBS,
|
||||
P_NOT,
|
||||
P_NEXT,
|
||||
P_FACTION,
|
||||
P_GAMENAME,
|
||||
P_PERSON,
|
||||
P_REGION,
|
||||
P_SHIP,
|
||||
P_MONEY,
|
||||
P_ROAD,
|
||||
P_TEMP,
|
||||
P_FLEE,
|
||||
P_GEBAEUDE,
|
||||
P_GIVE,
|
||||
P_FIGHT,
|
||||
P_TRAVEL,
|
||||
P_GUARD,
|
||||
P_ZAUBER,
|
||||
P_PAUSE,
|
||||
P_VORNE,
|
||||
P_AGGRO,
|
||||
P_CHICKEN,
|
||||
P_LEVEL,
|
||||
P_HELP,
|
||||
P_FOREIGN,
|
||||
P_AURA,
|
||||
P_AFTER,
|
||||
P_BEFORE,
|
||||
P_NUMBER,
|
||||
P_ITEMS,
|
||||
P_POTIONS,
|
||||
P_GROUP,
|
||||
P_FACTIONSTEALTH,
|
||||
P_TREES,
|
||||
P_ALLIANCE,
|
||||
P_AUTO,
|
||||
MAXPARAMS,
|
||||
NOPARAM
|
||||
} param_t;
|
||||
|
||||
extern const char *parameters[MAXPARAMS];
|
||||
|
||||
param_t findparam(const char *s, const struct locale *lang);
|
||||
param_t findparam_block(const char *s, const struct locale *lang, bool any_locale);
|
||||
bool isparam(const char *s, const struct locale * lang, param_t param);
|
||||
param_t getparam(const struct locale *lang);
|
||||
|
||||
void init_parameters(struct locale *lang);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
Loading…
Add table
Reference in a new issue