2010-08-08 10:06:34 +02:00
|
|
|
|
/*
|
2015-01-30 22:10:29 +01:00
|
|
|
|
Copyright (c) 1998-2015, Enno Rehling <enno@eressea.de>
|
2014-07-23 11:54:51 +02:00
|
|
|
|
Katja Zedel <katze@felidae.kn-bremen.de
|
|
|
|
|
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
|
purpose with or without fee is hereby granted, provided that the above
|
|
|
|
|
copyright notice and this permission notice appear in all copies.
|
|
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
#include <platform.h>
|
|
|
|
|
#include <kernel/config.h>
|
|
|
|
|
|
|
|
|
|
/* attributes includes */
|
|
|
|
|
#include <attributes/reduceproduction.h>
|
|
|
|
|
|
|
|
|
|
/* kernel includes */
|
|
|
|
|
#include "alliance.h"
|
2012-06-30 20:07:28 +02:00
|
|
|
|
#include "ally.h"
|
2010-08-08 10:06:34 +02:00
|
|
|
|
#include "alchemy.h"
|
2014-12-25 18:16:24 +01:00
|
|
|
|
#include "curse.h"
|
2010-08-08 10:06:34 +02:00
|
|
|
|
#include "connection.h"
|
|
|
|
|
#include "building.h"
|
|
|
|
|
#include "calendar.h"
|
2014-06-16 03:34:39 +02:00
|
|
|
|
#include "direction.h"
|
2010-08-08 10:06:34 +02:00
|
|
|
|
#include "faction.h"
|
|
|
|
|
#include "group.h"
|
|
|
|
|
#include "item.h"
|
2014-06-16 17:01:59 +02:00
|
|
|
|
#include "keyword.h"
|
2014-06-09 18:54:48 +02:00
|
|
|
|
#include "messages.h"
|
2010-08-08 10:06:34 +02:00
|
|
|
|
#include "move.h"
|
|
|
|
|
#include "objtypes.h"
|
|
|
|
|
#include "order.h"
|
|
|
|
|
#include "plane.h"
|
|
|
|
|
#include "pool.h"
|
|
|
|
|
#include "race.h"
|
2014-07-06 05:14:11 +02:00
|
|
|
|
#include "reports.h"
|
2010-08-08 10:06:34 +02:00
|
|
|
|
#include "region.h"
|
|
|
|
|
#include "ship.h"
|
|
|
|
|
#include "skill.h"
|
|
|
|
|
#include "terrain.h"
|
2014-11-01 12:09:56 +01:00
|
|
|
|
#include "types.h"
|
2010-08-08 10:06:34 +02:00
|
|
|
|
#include "unit.h"
|
|
|
|
|
|
2015-09-12 23:38:31 +02:00
|
|
|
|
|
2014-06-17 07:19:19 +02:00
|
|
|
|
#include <kernel/spell.h>
|
|
|
|
|
#include <kernel/spellbook.h>
|
2014-11-01 12:09:56 +01:00
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* util includes */
|
|
|
|
|
#include <util/attrib.h>
|
|
|
|
|
#include <util/base36.h>
|
2011-02-25 16:23:02 +01:00
|
|
|
|
#include <util/bsdstring.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
|
#include <util/crmessage.h>
|
|
|
|
|
#include <util/event.h>
|
|
|
|
|
#include <util/language.h>
|
2014-06-10 05:14:08 +02:00
|
|
|
|
#include <util/functions.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
|
#include <util/log.h>
|
|
|
|
|
#include <util/lists.h>
|
|
|
|
|
#include <util/parser.h>
|
2012-05-31 04:55:17 +02:00
|
|
|
|
#include <quicklist.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
|
#include <util/rand.h>
|
|
|
|
|
#include <util/rng.h>
|
|
|
|
|
#include <util/translation.h>
|
2011-02-25 16:23:02 +01:00
|
|
|
|
#include <util/unicode.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
|
#include <util/umlaut.h>
|
|
|
|
|
#include <util/xml.h>
|
|
|
|
|
|
2015-09-09 15:45:20 +02:00
|
|
|
|
#include "donations.h"
|
2015-09-12 23:38:31 +02:00
|
|
|
|
#include "guard.h"
|
2015-09-12 12:29:42 +02:00
|
|
|
|
#include "prefix.h"
|
2015-09-09 15:45:20 +02:00
|
|
|
|
|
2014-06-10 05:14:08 +02:00
|
|
|
|
#ifdef USE_LIBXML2
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* libxml includes */
|
|
|
|
|
#include <libxml/tree.h>
|
|
|
|
|
#include <libxml/xpath.h>
|
2014-06-10 05:14:08 +02:00
|
|
|
|
#endif
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2012-05-31 04:17:08 +02:00
|
|
|
|
/* external libraries */
|
|
|
|
|
#include <iniparser.h>
|
2014-06-16 03:34:39 +02:00
|
|
|
|
#include <critbit.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
/* libc includes */
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <ctype.h>
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
#include <limits.h>
|
|
|
|
|
#include <time.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
|
|
struct settings global = {
|
2014-07-23 11:54:51 +02:00
|
|
|
|
"Eressea", /* gamename */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
};
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2014-05-04 22:49:06 +02:00
|
|
|
|
bool lomem = false;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
FILE *logfile;
|
2012-06-24 07:41:07 +02:00
|
|
|
|
bool battledebug = false;
|
2014-04-25 07:47:23 +02:00
|
|
|
|
int turn = -1;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
int NewbieImmunity(void)
|
|
|
|
|
{
|
2015-11-22 10:44:46 +01:00
|
|
|
|
return config_get_int("NewbieImmunity", 0);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-06-24 07:41:07 +02:00
|
|
|
|
bool IsImmune(const faction * f)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2014-07-23 11:54:51 +02:00
|
|
|
|
return !fval(f, FFL_NPC) && f->age < NewbieImmunity();
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-06-24 07:41:07 +02:00
|
|
|
|
bool ExpensiveMigrants(void)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2015-11-22 10:44:46 +01:00
|
|
|
|
return config_get_int("study.expensivemigrants", 0) != 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
|
|
|
|
int LongHunger(const struct unit *u)
|
|
|
|
|
{
|
2014-07-23 11:54:51 +02:00
|
|
|
|
if (u != NULL) {
|
|
|
|
|
if (!fval(u, UFL_HUNGER))
|
|
|
|
|
return false;
|
|
|
|
|
if (u_race(u) == get_race(RC_DAEMON))
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2015-11-22 10:44:46 +01:00
|
|
|
|
return config_get_int("hunger.long", 0);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
int NMRTimeout(void)
|
|
|
|
|
{
|
2015-11-22 10:44:46 +01:00
|
|
|
|
return config_get_int("nmr.timeout", 0);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
race_t old_race(const struct race * rc)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2014-07-23 11:54:51 +02:00
|
|
|
|
race_t i;
|
|
|
|
|
for (i = 0; i != MAXRACES; ++i) {
|
|
|
|
|
if (get_race(i) == rc) return i;
|
|
|
|
|
}
|
|
|
|
|
return NORACE;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
helpmode helpmodes[] = {
|
2015-01-30 20:37:14 +01:00
|
|
|
|
{ "all", HELP_ALL }
|
|
|
|
|
,
|
|
|
|
|
{ "money", HELP_MONEY }
|
|
|
|
|
,
|
|
|
|
|
{ "fight", HELP_FIGHT }
|
|
|
|
|
,
|
|
|
|
|
{ "observe", HELP_OBSERVE }
|
|
|
|
|
,
|
|
|
|
|
{ "give", HELP_GIVE }
|
|
|
|
|
,
|
|
|
|
|
{ "guard", HELP_GUARD }
|
|
|
|
|
,
|
|
|
|
|
{ "stealth", HELP_FSTEALTH }
|
|
|
|
|
,
|
|
|
|
|
{ "travel", HELP_TRAVEL }
|
|
|
|
|
,
|
|
|
|
|
{ NULL, 0 }
|
2010-08-08 10:06:34 +02:00
|
|
|
|
};
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
const char *parameters[MAXPARAMS] = {
|
2014-07-23 11:54:51 +02:00
|
|
|
|
"LOCALE",
|
|
|
|
|
"ALLES",
|
|
|
|
|
"JEDEM",
|
|
|
|
|
"BAUERN",
|
|
|
|
|
"BURG",
|
|
|
|
|
"EINHEIT",
|
|
|
|
|
"PRIVAT",
|
|
|
|
|
"HINTEN",
|
|
|
|
|
"KOMMANDO",
|
|
|
|
|
"KRAEUTER",
|
|
|
|
|
"NICHT",
|
|
|
|
|
"NAECHSTER",
|
|
|
|
|
"PARTEI",
|
|
|
|
|
"ERESSEA",
|
|
|
|
|
"PERSONEN",
|
|
|
|
|
"REGION",
|
|
|
|
|
"SCHIFF",
|
|
|
|
|
"SILBER",
|
|
|
|
|
"STRASSEN",
|
2014-08-17 14:24:19 +02:00
|
|
|
|
"TEMP",
|
2014-07-23 11:54:51 +02:00
|
|
|
|
"FLIEHE",
|
|
|
|
|
"GEBAEUDE",
|
|
|
|
|
"GIB", /* F<>r HELFE */
|
|
|
|
|
"KAEMPFE",
|
|
|
|
|
"DURCHREISE",
|
|
|
|
|
"BEWACHE",
|
|
|
|
|
"ZAUBER",
|
|
|
|
|
"PAUSE",
|
|
|
|
|
"VORNE",
|
|
|
|
|
"AGGRESSIV",
|
|
|
|
|
"DEFENSIV",
|
|
|
|
|
"STUFE",
|
|
|
|
|
"HELFE",
|
|
|
|
|
"FREMDES",
|
|
|
|
|
"AURA",
|
|
|
|
|
"HINTER",
|
|
|
|
|
"VOR",
|
|
|
|
|
"ANZAHL",
|
|
|
|
|
"GEGENSTAENDE",
|
|
|
|
|
"TRAENKE",
|
|
|
|
|
"GRUPPE",
|
|
|
|
|
"PARTEITARNUNG",
|
|
|
|
|
"BAEUME",
|
|
|
|
|
"ALLIANZ"
|
2010-08-08 10:06:34 +02:00
|
|
|
|
};
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
const char *report_options[MAX_MSG] = {
|
2014-07-23 11:54:51 +02:00
|
|
|
|
"Kampf",
|
|
|
|
|
"Ereignisse",
|
|
|
|
|
"Bewegung",
|
|
|
|
|
"Einkommen",
|
|
|
|
|
"Handel",
|
|
|
|
|
"Produktion",
|
|
|
|
|
"Orkvermehrung",
|
|
|
|
|
"Zauber",
|
|
|
|
|
"",
|
|
|
|
|
""
|
2010-08-08 10:06:34 +02:00
|
|
|
|
};
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
const char *message_levels[ML_MAX] = {
|
2014-07-23 11:54:51 +02:00
|
|
|
|
"Wichtig",
|
|
|
|
|
"Debug",
|
|
|
|
|
"Fehler",
|
|
|
|
|
"Warnungen",
|
|
|
|
|
"Infos"
|
2010-08-08 10:06:34 +02:00
|
|
|
|
};
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
const char *options[MAXOPTIONS] = {
|
2014-07-23 11:54:51 +02:00
|
|
|
|
"AUSWERTUNG",
|
|
|
|
|
"COMPUTER",
|
|
|
|
|
"ZUGVORLAGE",
|
|
|
|
|
NULL,
|
|
|
|
|
"STATISTIK",
|
|
|
|
|
"DEBUG",
|
|
|
|
|
"ZIPPED",
|
|
|
|
|
"ZEITUNG", /* Option hat Sonderbehandlung! */
|
|
|
|
|
NULL,
|
|
|
|
|
"ADRESSEN",
|
|
|
|
|
"BZIP2",
|
|
|
|
|
"PUNKTE",
|
|
|
|
|
"SHOWSKCHANGE"
|
2010-08-08 10:06:34 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
FILE *debug;
|
|
|
|
|
|
|
|
|
|
void
|
2014-07-23 11:54:51 +02:00
|
|
|
|
parse(keyword_t kword, int(*dofun) (unit *, struct order *), bool thisorder)
|
|
|
|
|
{
|
|
|
|
|
region *r;
|
|
|
|
|
|
|
|
|
|
for (r = regions; r; r = r->next) {
|
|
|
|
|
unit **up = &r->units;
|
|
|
|
|
while (*up) {
|
|
|
|
|
unit *u = *up;
|
|
|
|
|
order **ordp = &u->orders;
|
|
|
|
|
if (thisorder)
|
|
|
|
|
ordp = &u->thisorder;
|
|
|
|
|
while (*ordp) {
|
|
|
|
|
order *ord = *ordp;
|
|
|
|
|
if (getkeyword(ord) == kword) {
|
|
|
|
|
if (dofun(u, ord) != 0)
|
|
|
|
|
break;
|
|
|
|
|
if (u->orders == NULL)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (thisorder)
|
|
|
|
|
break;
|
|
|
|
|
if (*ordp == ord)
|
|
|
|
|
ordp = &ord->next;
|
|
|
|
|
}
|
|
|
|
|
if (*up == u)
|
|
|
|
|
up = &u->next;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
const struct race *findrace(const char *s, const struct locale *lang)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2014-07-23 11:54:51 +02:00
|
|
|
|
void **tokens = get_translations(lang, UT_RACES);
|
|
|
|
|
variant token;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-07-23 11:54:51 +02:00
|
|
|
|
assert(lang);
|
|
|
|
|
if (tokens && findtoken(*tokens, s, &token) == E_TOK_SUCCESS) {
|
|
|
|
|
return (const struct race *)token.v;
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
int findoption(const char *s, const struct locale *lang)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2014-07-23 11:54:51 +02:00
|
|
|
|
void **tokens = get_translations(lang, UT_OPTIONS);
|
|
|
|
|
variant token;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-07-23 11:54:51 +02:00
|
|
|
|
if (findtoken(*tokens, s, &token) == E_TOK_SUCCESS) {
|
|
|
|
|
return (direction_t)token.i;
|
|
|
|
|
}
|
|
|
|
|
return NODIRECTION;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
param_t findparam(const char *s, const struct locale * lang)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2014-07-03 06:17:31 +02:00
|
|
|
|
param_t result = NOPARAM;
|
|
|
|
|
char buffer[64];
|
2014-08-23 09:17:58 +02:00
|
|
|
|
char * str = s ? transliterate(buffer, sizeof(buffer) - sizeof(int), s) : 0;
|
2014-07-23 11:54:51 +02:00
|
|
|
|
|
2014-07-03 06:17:31 +02:00
|
|
|
|
if (str && *str) {
|
|
|
|
|
int i;
|
2015-07-12 10:35:09 +02:00
|
|
|
|
void * match;
|
2014-07-03 06:17:31 +02:00
|
|
|
|
void **tokens = get_translations(lang, UT_PARAMS);
|
|
|
|
|
critbit_tree *cb = (critbit_tree *)*tokens;
|
|
|
|
|
if (!cb) {
|
2014-08-11 12:02:16 +02:00
|
|
|
|
log_error("no parameters defined in locale %s", locale_name(lang));
|
2014-07-03 06:17:31 +02:00
|
|
|
|
}
|
|
|
|
|
else if (cb_find_prefix(cb, str, strlen(str), &match, 1, 0)) {
|
|
|
|
|
cb_get_kv(match, &i, sizeof(int));
|
|
|
|
|
result = (param_t)i;
|
|
|
|
|
}
|
2012-05-16 21:06:44 +02:00
|
|
|
|
}
|
2014-07-03 06:17:31 +02:00
|
|
|
|
return result;
|
2012-05-16 21:06:44 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
param_t findparam_ex(const char *s, const struct locale * lang)
|
|
|
|
|
{
|
2014-07-23 11:54:51 +02:00
|
|
|
|
param_t result = findparam(s, lang);
|
2012-05-16 21:06:44 +02:00
|
|
|
|
|
2014-07-23 11:54:51 +02:00
|
|
|
|
if (result == NOPARAM) {
|
|
|
|
|
const building_type *btype = findbuildingtype(s, lang);
|
|
|
|
|
if (btype != NULL)
|
|
|
|
|
return P_GEBAEUDE;
|
|
|
|
|
}
|
|
|
|
|
return (result == P_BUILDING) ? P_GEBAEUDE : result;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-06-24 08:04:12 +02:00
|
|
|
|
bool isparam(const char *s, const struct locale * lang, param_t param)
|
2012-05-16 21:06:44 +02:00
|
|
|
|
{
|
2014-08-23 09:17:58 +02:00
|
|
|
|
assert(s);
|
2014-07-23 11:54:51 +02:00
|
|
|
|
if (s[0] > '@') {
|
|
|
|
|
param_t p = (param == P_GEBAEUDE) ? findparam_ex(s, lang) : findparam(s, lang);
|
|
|
|
|
return p == param;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2012-05-16 21:06:44 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
param_t getparam(const struct locale * lang)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2014-12-22 16:28:17 +01:00
|
|
|
|
char token[64];
|
|
|
|
|
const char *s = gettoken(token, sizeof(token));
|
2014-09-21 16:43:17 +02:00
|
|
|
|
return s ? findparam(s, lang) : NOPARAM;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
unit *getnewunit(const region * r, const faction * f)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2014-07-23 11:54:51 +02:00
|
|
|
|
int n;
|
|
|
|
|
n = getid();
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-07-23 11:54:51 +02:00
|
|
|
|
return findnewunit(r, f, n);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* - Namen der Strukturen -------------------------------------- */
|
2014-12-09 05:55:16 +01:00
|
|
|
|
char *untilde(char *ibuf)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2014-07-23 11:54:51 +02:00
|
|
|
|
char *p = ibuf;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-07-23 11:54:51 +02:00
|
|
|
|
while (*p) {
|
|
|
|
|
if (*p == '~') {
|
|
|
|
|
*p = ' ';
|
|
|
|
|
}
|
|
|
|
|
++p;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2014-07-23 11:54:51 +02:00
|
|
|
|
return ibuf;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
building *largestbuilding(const region * r, cmp_building_cb cmp_gt,
|
2014-07-23 11:54:51 +02:00
|
|
|
|
bool imaginary)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2014-07-23 11:54:51 +02:00
|
|
|
|
building *b, *best = NULL;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-07-23 11:54:51 +02:00
|
|
|
|
for (b = rbuildings(r); b; b = b->next) {
|
|
|
|
|
if (cmp_gt(b, best) <= 0)
|
|
|
|
|
continue;
|
|
|
|
|
if (!imaginary) {
|
|
|
|
|
const attrib *a = a_find(b->attribs, &at_icastle);
|
|
|
|
|
if (a)
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
best = b;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2014-07-23 11:54:51 +02:00
|
|
|
|
return best;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -- Erschaffung neuer Einheiten ------------------------------ */
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static const char *forbidden[] = { "t", "te", "tem", "temp", NULL };
|
2015-09-05 19:25:55 +02:00
|
|
|
|
// PEASANT: "b", "ba", "bau", "baue", "p", "pe", "pea", "peas"
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
int forbiddenid(int id)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2014-07-23 11:54:51 +02:00
|
|
|
|
static int *forbid = NULL;
|
|
|
|
|
static size_t len;
|
|
|
|
|
size_t i;
|
|
|
|
|
if (id <= 0)
|
|
|
|
|
return 1;
|
|
|
|
|
if (!forbid) {
|
|
|
|
|
while (forbidden[len])
|
|
|
|
|
++len;
|
|
|
|
|
forbid = calloc(len, sizeof(int));
|
|
|
|
|
for (i = 0; i != len; ++i) {
|
2015-05-15 19:08:44 +02:00
|
|
|
|
forbid[i] = atoi36(forbidden[i]);
|
2014-07-23 11:54:51 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for (i = 0; i != len; ++i)
|
|
|
|
|
if (id == forbid[i])
|
|
|
|
|
return 1;
|
|
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
int newcontainerid(void)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2014-07-23 11:54:51 +02:00
|
|
|
|
int random_no;
|
|
|
|
|
int start_random_no;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-07-23 11:54:51 +02:00
|
|
|
|
random_no = 1 + (rng_int() % MAX_CONTAINER_NR);
|
|
|
|
|
start_random_no = random_no;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-07-23 11:54:51 +02:00
|
|
|
|
while (findship(random_no) || findbuilding(random_no)) {
|
|
|
|
|
random_no++;
|
|
|
|
|
if (random_no == MAX_CONTAINER_NR + 1) {
|
|
|
|
|
random_no = 1;
|
|
|
|
|
}
|
|
|
|
|
if (random_no == start_random_no) {
|
|
|
|
|
random_no = (int)MAX_CONTAINER_NR + 1;
|
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2014-07-23 11:54:51 +02:00
|
|
|
|
return random_no;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
int maxworkingpeasants(const struct region *r)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2014-09-18 12:10:42 +02:00
|
|
|
|
int size = production(r);
|
|
|
|
|
int treespace = (rtrees(r, 2) + rtrees(r, 1) / 2) * TREESIZE;
|
2015-01-30 20:37:14 +01:00
|
|
|
|
return _max(size - treespace, _min(size / 10, 200));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-05-22 02:45:54 +02:00
|
|
|
|
static const char * parameter_key(int i)
|
|
|
|
|
{
|
2014-07-23 11:54:51 +02:00
|
|
|
|
assert(i < MAXPARAMS && i >= 0);
|
|
|
|
|
return parameters[i];
|
2012-05-22 02:45:54 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-08-05 12:19:17 +02:00
|
|
|
|
void init_parameters(struct locale *lang) {
|
|
|
|
|
init_translations(lang, UT_PARAMS, parameter_key, MAXPARAMS);
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-17 00:45:45 +02:00
|
|
|
|
|
|
|
|
|
void init_terrains_translation(const struct locale *lang) {
|
|
|
|
|
void **tokens;
|
|
|
|
|
const terrain_type *terrain;
|
2014-07-23 11:54:51 +02:00
|
|
|
|
|
2014-07-17 00:45:45 +02:00
|
|
|
|
tokens = get_translations(lang, UT_TERRAINS);
|
|
|
|
|
for (terrain = terrains(); terrain != NULL; terrain = terrain->next) {
|
|
|
|
|
variant var;
|
|
|
|
|
const char *name;
|
|
|
|
|
var.v = (void *)terrain;
|
2015-01-08 20:55:29 +01:00
|
|
|
|
name = locale_string(lang, terrain->_name, false);
|
2014-07-17 00:45:45 +02:00
|
|
|
|
if (name) {
|
|
|
|
|
addtoken(tokens, name, var);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2015-01-08 20:55:29 +01:00
|
|
|
|
log_debug("no translation for terrain %s in locale %s", terrain->_name, locale_name(lang));
|
2014-07-17 00:45:45 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void init_options_translation(const struct locale * lang) {
|
|
|
|
|
void **tokens;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
tokens = get_translations(lang, UT_OPTIONS);
|
|
|
|
|
for (i = 0; i != MAXOPTIONS; ++i) {
|
|
|
|
|
variant var;
|
|
|
|
|
var.i = i;
|
|
|
|
|
if (options[i]) {
|
2015-01-08 20:55:29 +01:00
|
|
|
|
const char *name = locale_string(lang, options[i], false);
|
2014-07-17 00:45:45 +02:00
|
|
|
|
if (name) {
|
|
|
|
|
addtoken(tokens, name, var);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2015-01-08 20:55:29 +01:00
|
|
|
|
log_debug("no translation for OPTION %s in locale %s", options[i], locale_name(lang));
|
2014-07-17 00:45:45 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-29 21:19:07 +02:00
|
|
|
|
void init_locale(struct locale *lang)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2014-06-14 16:52:32 +02:00
|
|
|
|
variant var;
|
|
|
|
|
int i;
|
|
|
|
|
const struct race *rc;
|
|
|
|
|
void **tokens;
|
|
|
|
|
|
|
|
|
|
tokens = get_translations(lang, UT_MAGIC);
|
|
|
|
|
if (tokens) {
|
2015-11-22 10:44:46 +01:00
|
|
|
|
const char *str = config_get("rules.magic.playerschools");
|
2014-06-14 16:52:32 +02:00
|
|
|
|
char *sstr, *tok;
|
|
|
|
|
if (str == NULL) {
|
|
|
|
|
str = "gwyrrd illaun draig cerddor tybied";
|
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-06-14 16:52:32 +02:00
|
|
|
|
sstr = _strdup(str);
|
|
|
|
|
tok = strtok(sstr, " ");
|
|
|
|
|
while (tok) {
|
2014-07-17 00:45:45 +02:00
|
|
|
|
const char *name;
|
2014-06-14 16:52:32 +02:00
|
|
|
|
for (i = 0; i != MAXMAGIETYP; ++i) {
|
|
|
|
|
if (strcmp(tok, magic_school[i]) == 0) break;
|
|
|
|
|
}
|
|
|
|
|
assert(i != MAXMAGIETYP);
|
|
|
|
|
var.i = i;
|
2014-07-17 00:45:45 +02:00
|
|
|
|
name = LOC(lang, mkname("school", tok));
|
|
|
|
|
if (name) {
|
|
|
|
|
addtoken(tokens, name, var);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2015-06-19 13:17:01 +02:00
|
|
|
|
log_warning("no translation for magic school %s in locale %s", tok, locale_name(lang));
|
2014-07-17 00:45:45 +02:00
|
|
|
|
}
|
2014-06-14 16:52:32 +02:00
|
|
|
|
tok = strtok(NULL, " ");
|
|
|
|
|
}
|
|
|
|
|
free(sstr);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-16 03:34:39 +02:00
|
|
|
|
init_directions(lang);
|
2014-06-16 17:01:59 +02:00
|
|
|
|
init_keywords(lang);
|
2014-06-21 23:39:56 +02:00
|
|
|
|
init_skills(lang);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-06-14 16:52:32 +02:00
|
|
|
|
tokens = get_translations(lang, UT_RACES);
|
|
|
|
|
for (rc = races; rc; rc = rc->next) {
|
2014-07-17 00:45:45 +02:00
|
|
|
|
const char *name;
|
2014-06-14 16:52:32 +02:00
|
|
|
|
var.v = (void *)rc;
|
2015-01-08 20:55:29 +01:00
|
|
|
|
name = locale_string(lang, rc_name_s(rc, NAME_PLURAL), false);
|
2014-07-17 00:45:45 +02:00
|
|
|
|
if (name) addtoken(tokens, name, var);
|
2015-01-08 20:55:29 +01:00
|
|
|
|
name = locale_string(lang, rc_name_s(rc, NAME_SINGULAR), false);
|
2014-07-17 00:45:45 +02:00
|
|
|
|
if (name) addtoken(tokens, name, var);
|
2014-06-14 16:52:32 +02:00
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2015-08-05 12:19:17 +02:00
|
|
|
|
init_parameters(lang);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-07-17 00:45:45 +02:00
|
|
|
|
init_options_translation(lang);
|
|
|
|
|
init_terrains_translation(lang);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
typedef struct param {
|
2015-11-20 15:48:09 +01:00
|
|
|
|
critbit_tree cb;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
} param;
|
|
|
|
|
|
2015-11-20 15:48:09 +01:00
|
|
|
|
size_t pack_keyval(const char *key, const char *value, char *data, size_t len) {
|
|
|
|
|
size_t klen = strlen(key);
|
|
|
|
|
size_t vlen = strlen(value);
|
|
|
|
|
assert(klen + vlen + 2 + sizeof(vlen) <= len);
|
|
|
|
|
memcpy(data, key, klen + 1);
|
|
|
|
|
memcpy(data + klen + 1, value, vlen + 1);
|
|
|
|
|
return klen + vlen + 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void set_param(struct param **p, const char *key, const char *value)
|
|
|
|
|
{
|
|
|
|
|
struct param *par;
|
|
|
|
|
assert(p);
|
|
|
|
|
|
|
|
|
|
par = *p;
|
|
|
|
|
if (!par && value) {
|
|
|
|
|
*p = par = calloc(1, sizeof(param));
|
|
|
|
|
}
|
|
|
|
|
if (par) {
|
|
|
|
|
void *match;
|
|
|
|
|
size_t klen = strlen(key) + 1;
|
|
|
|
|
if (cb_find_prefix(&par->cb, key, klen, &match, 1, 0) > 0) {
|
|
|
|
|
const char * kv = (const char *)match;
|
|
|
|
|
size_t vlen = strlen(kv + klen) + 1;
|
|
|
|
|
cb_erase(&par->cb, kv, klen + vlen);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (value) {
|
|
|
|
|
char data[512];
|
|
|
|
|
size_t sz = pack_keyval(key, value, data, sizeof(data));
|
2015-11-22 12:50:10 +01:00
|
|
|
|
cb_insert(&par->cb, data, sz);
|
2015-11-20 15:48:09 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-05 18:14:28 +02:00
|
|
|
|
void free_params(struct param **pp) {
|
2015-11-20 15:48:09 +01:00
|
|
|
|
param *p = *pp;
|
|
|
|
|
if (p) {
|
|
|
|
|
cb_clear(&p->cb);
|
2015-09-05 18:14:28 +02:00
|
|
|
|
free(p);
|
|
|
|
|
}
|
2015-11-20 15:48:09 +01:00
|
|
|
|
*pp = 0;
|
2015-09-05 18:14:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
const char *get_param(const struct param *p, const char *key)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2015-11-20 15:48:09 +01:00
|
|
|
|
void *match;
|
2015-11-21 13:52:47 +01:00
|
|
|
|
if (p && cb_find_prefix(&p->cb, key, strlen(key) + 1, &match, 1, 0) > 0) {
|
2015-11-20 15:48:09 +01:00
|
|
|
|
cb_get_kv_ex(match, &match);
|
|
|
|
|
return (const char *)match;
|
2014-06-25 16:22:39 +02:00
|
|
|
|
}
|
|
|
|
|
return NULL;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
int get_param_int(const struct param *p, const char *key, int def)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2014-06-25 16:22:39 +02:00
|
|
|
|
const char * str = get_param(p, key);
|
|
|
|
|
return str ? atoi(str) : def;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2014-08-08 13:29:26 +02:00
|
|
|
|
int check_param(const struct param *p, const char *key, const char *searchvalue)
|
|
|
|
|
{
|
2014-12-31 01:00:10 +01:00
|
|
|
|
int result = 0;
|
2014-08-08 13:29:26 +02:00
|
|
|
|
const char *value = get_param(p, key);
|
|
|
|
|
if (!value) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2014-12-31 01:00:10 +01:00
|
|
|
|
char *p_value = _strdup(value);
|
2014-08-08 13:29:26 +02:00
|
|
|
|
const char *delimiter = " ,;";
|
|
|
|
|
char *v = strtok(p_value, delimiter);
|
|
|
|
|
|
|
|
|
|
while (v != NULL) {
|
2014-12-31 01:00:10 +01:00
|
|
|
|
if (strcmp(v, searchvalue) == 0) {
|
|
|
|
|
result = 1;
|
|
|
|
|
break;
|
2014-08-08 13:29:26 +02:00
|
|
|
|
}
|
|
|
|
|
v = strtok(NULL, delimiter);
|
|
|
|
|
}
|
2014-12-31 01:00:10 +01:00
|
|
|
|
free(p_value);
|
|
|
|
|
return result;
|
2014-08-08 13:29:26 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-01-29 17:49:27 +01:00
|
|
|
|
static const char *g_basedir;
|
|
|
|
|
const char *basepath(void)
|
|
|
|
|
{
|
|
|
|
|
if (g_basedir)
|
|
|
|
|
return g_basedir;
|
|
|
|
|
return ".";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void set_basepath(const char *path)
|
|
|
|
|
{
|
|
|
|
|
g_basedir = path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef WIN32
|
2016-01-29 19:11:48 +01:00
|
|
|
|
#define PATH_DELIM '\\'
|
2016-01-29 17:49:27 +01:00
|
|
|
|
#else
|
2016-01-29 19:11:48 +01:00
|
|
|
|
#define PATH_DELIM '/'
|
2016-01-29 17:49:27 +01:00
|
|
|
|
#endif
|
2016-01-29 19:11:48 +01:00
|
|
|
|
|
|
|
|
|
char * join_path(const char *p1, const char *p2, char *dst, size_t len) {
|
|
|
|
|
size_t sz;
|
|
|
|
|
assert(p1 && p2);
|
2016-02-05 23:10:05 +01:00
|
|
|
|
assert(p2 != dst);
|
|
|
|
|
if (dst == p1) {
|
|
|
|
|
sz = strlen(p1);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
sz = strlcpy(dst, p1, len);
|
|
|
|
|
}
|
2016-01-29 19:11:48 +01:00
|
|
|
|
assert(sz < len);
|
|
|
|
|
dst[sz++] = PATH_DELIM;
|
|
|
|
|
strlcpy(dst + sz, p2, len - sz);
|
|
|
|
|
return dst;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char * relpath(char *buf, size_t sz, const char *path) {
|
|
|
|
|
if (g_basedir) {
|
|
|
|
|
join_path(g_basedir, path, buf, sz);
|
2016-01-29 17:49:27 +01:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
strlcpy(buf, path, sz);
|
|
|
|
|
}
|
2015-10-30 11:39:47 +01:00
|
|
|
|
return buf;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static const char *g_datadir;
|
|
|
|
|
const char *datapath(void)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2014-08-24 22:54:40 +02:00
|
|
|
|
static char zText[MAX_PATH]; // FIXME: static return value
|
2014-07-23 11:54:51 +02:00
|
|
|
|
if (g_datadir)
|
|
|
|
|
return g_datadir;
|
2016-01-29 17:49:27 +01:00
|
|
|
|
return relpath(zText, sizeof(zText), "data");
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
void set_datapath(const char *path)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2014-07-23 11:54:51 +02:00
|
|
|
|
g_datadir = path;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
static const char *g_reportdir;
|
|
|
|
|
const char *reportpath(void)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2014-08-24 22:54:40 +02:00
|
|
|
|
static char zText[MAX_PATH]; // FIXME: static return value
|
2014-07-23 11:54:51 +02:00
|
|
|
|
if (g_reportdir)
|
|
|
|
|
return g_reportdir;
|
2016-01-29 17:49:27 +01:00
|
|
|
|
return relpath(zText, sizeof(zText), "reports");
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
void set_reportpath(const char *path)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2014-07-23 11:54:51 +02:00
|
|
|
|
g_reportdir = path;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-02-01 09:26:24 +01:00
|
|
|
|
int create_directories(void) {
|
|
|
|
|
int err;
|
|
|
|
|
err = _mkdir(datapath());
|
|
|
|
|
if (err) {
|
|
|
|
|
if (errno == EEXIST) errno = 0;
|
|
|
|
|
else return err;
|
|
|
|
|
}
|
|
|
|
|
err = _mkdir(reportpath());
|
|
|
|
|
if (err && errno == EEXIST) {
|
|
|
|
|
errno = 0;
|
|
|
|
|
}
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-12 16:38:39 +02:00
|
|
|
|
double get_param_flt(const struct param *p, const char *key, double def)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2014-06-25 16:25:54 +02:00
|
|
|
|
const char *str = get_param(p, key);
|
2015-09-12 16:38:39 +02:00
|
|
|
|
return str ? atof(str) : def;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
void kernel_done(void)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2014-07-23 11:54:51 +02:00
|
|
|
|
/* calling this function releases memory assigned to static variables, etc.
|
|
|
|
|
* calling it is optional, e.g. a release server will most likely not do it.
|
|
|
|
|
*/
|
|
|
|
|
translation_done();
|
2014-12-31 01:17:49 +01:00
|
|
|
|
free_attribs();
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifndef HAVE_STRDUP
|
2013-12-29 14:38:58 +01:00
|
|
|
|
char *_strdup(const char *s)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2014-07-23 11:54:51 +02:00
|
|
|
|
return strcpy((char *)malloc(sizeof(char) * (strlen(s) + 1)), s);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* Lohn bei den einzelnen Burgstufen f<>r Normale Typen, Orks, Bauern,
|
|
|
|
|
* Modifikation f<EFBFBD>r St<EFBFBD>dter. */
|
|
|
|
|
|
|
|
|
|
static const int wagetable[7][4] = {
|
2015-01-30 20:37:14 +01:00
|
|
|
|
{ 10, 10, 11, -7 }, /* Baustelle */
|
|
|
|
|
{ 10, 10, 11, -5 }, /* Handelsposten */
|
|
|
|
|
{ 11, 11, 12, -3 }, /* Befestigung */
|
|
|
|
|
{ 12, 11, 13, -1 }, /* Turm */
|
|
|
|
|
{ 13, 12, 14, 0 }, /* Burg */
|
|
|
|
|
{ 14, 12, 15, 1 }, /* Festung */
|
|
|
|
|
{ 15, 13, 16, 2 } /* Zitadelle */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
};
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
int cmp_wage(const struct building *b, const building * a)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2014-07-23 11:54:51 +02:00
|
|
|
|
const struct building_type *bt_castle = bt_find("castle");
|
|
|
|
|
if (b->type == bt_castle) {
|
|
|
|
|
if (!a)
|
|
|
|
|
return 1;
|
|
|
|
|
if (b->size > a->size)
|
|
|
|
|
return 1;
|
|
|
|
|
if (b->size == a->size)
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-06-24 07:41:07 +02:00
|
|
|
|
bool is_owner_building(const struct building * b)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2014-07-23 11:54:51 +02:00
|
|
|
|
region *r = b->region;
|
|
|
|
|
if (b->type->taxes && r->land && r->land->ownership) {
|
|
|
|
|
unit *u = building_owner(b);
|
|
|
|
|
return u && u->faction == r->land->ownership->owner;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
int cmp_taxes(const building * b, const building * a)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2014-07-23 11:54:51 +02:00
|
|
|
|
faction *f = region_get_owner(b->region);
|
|
|
|
|
if (b->type->taxes) {
|
|
|
|
|
unit *u = building_owner(b);
|
|
|
|
|
if (!u) {
|
2011-03-07 08:02:35 +01:00
|
|
|
|
return -1;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2014-07-23 11:54:51 +02:00
|
|
|
|
else if (a) {
|
|
|
|
|
int newsize = buildingeffsize(b, false);
|
|
|
|
|
double newtaxes = b->type->taxes(b, newsize);
|
|
|
|
|
int oldsize = buildingeffsize(a, false);
|
|
|
|
|
double oldtaxes = a->type->taxes(a, oldsize);
|
|
|
|
|
|
|
|
|
|
if (newtaxes < oldtaxes)
|
|
|
|
|
return -1;
|
|
|
|
|
else if (newtaxes > oldtaxes)
|
|
|
|
|
return 1;
|
|
|
|
|
else if (b->size < a->size)
|
|
|
|
|
return -1;
|
|
|
|
|
else if (b->size > a->size)
|
|
|
|
|
return 1;
|
|
|
|
|
else {
|
|
|
|
|
if (u && u->faction == f) {
|
|
|
|
|
u = building_owner(a);
|
|
|
|
|
if (u && u->faction == f)
|
|
|
|
|
return -1;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2014-07-23 11:54:51 +02:00
|
|
|
|
return -1;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
int cmp_current_owner(const building * b, const building * a)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2014-07-23 11:54:51 +02:00
|
|
|
|
faction *f = region_get_owner(b->region);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-07-23 11:54:51 +02:00
|
|
|
|
assert(rule_region_owners());
|
|
|
|
|
if (f && b->type->taxes) {
|
|
|
|
|
unit *u = building_owner(b);
|
|
|
|
|
if (!u || u->faction != f)
|
|
|
|
|
return -1;
|
|
|
|
|
if (a) {
|
|
|
|
|
int newsize = buildingeffsize(b, false);
|
|
|
|
|
double newtaxes = b->type->taxes(b, newsize);
|
|
|
|
|
int oldsize = buildingeffsize(a, false);
|
|
|
|
|
double oldtaxes = a->type->taxes(a, oldsize);
|
|
|
|
|
|
|
|
|
|
if (newtaxes != oldtaxes)
|
|
|
|
|
return (newtaxes > oldtaxes) ? 1 : -1;
|
|
|
|
|
if (newsize != oldsize)
|
|
|
|
|
return newsize - oldsize;
|
|
|
|
|
return (b->size - a->size);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2014-07-23 11:54:51 +02:00
|
|
|
|
return -1;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-11-09 13:36:52 +01:00
|
|
|
|
bool rule_stealth_other(void)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2015-11-22 10:44:46 +01:00
|
|
|
|
int rule = config_get_int("stealth.faction.other", 1);
|
2015-11-09 13:36:52 +01:00
|
|
|
|
return rule != 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool rule_stealth_anon(void)
|
|
|
|
|
{
|
2015-11-22 10:44:46 +01:00
|
|
|
|
int rule = config_get_int("stealth.faction.anon", 1);
|
2015-11-21 13:52:47 +01:00
|
|
|
|
return rule != 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-09-11 10:04:08 +02:00
|
|
|
|
bool rule_region_owners(void)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2015-11-22 10:44:46 +01:00
|
|
|
|
int rule = config_get_int("rules.region_owners", 0);
|
2015-11-21 13:52:47 +01:00
|
|
|
|
return rule != 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int rule_blessed_harvest(void)
|
|
|
|
|
{
|
2015-11-22 10:44:46 +01:00
|
|
|
|
int rule = config_get_int("rules.blessed_harvest.flags",
|
2015-11-21 18:13:16 +01:00
|
|
|
|
HARVEST_WORK);
|
|
|
|
|
assert(rule >= 0);
|
2014-07-23 11:54:51 +02:00
|
|
|
|
return rule;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int rule_alliance_limit(void)
|
|
|
|
|
{
|
2015-11-22 10:44:46 +01:00
|
|
|
|
int rule = config_get_int("rules.limit.alliance", 0);
|
2015-11-21 18:13:16 +01:00
|
|
|
|
assert(rule >= 0);
|
2014-07-23 11:54:51 +02:00
|
|
|
|
return rule;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int rule_faction_limit(void)
|
|
|
|
|
{
|
2015-11-22 10:44:46 +01:00
|
|
|
|
int rule = config_get_int("rules.limit.faction", 0);
|
2015-11-21 18:13:16 +01:00
|
|
|
|
assert(rule >= 0);
|
2014-07-23 11:54:51 +02:00
|
|
|
|
return rule;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2011-03-07 08:02:35 +01:00
|
|
|
|
default_wage(const region * r, const faction * f, const race * rc, int in_turn)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2014-07-23 11:54:51 +02:00
|
|
|
|
building *b = largestbuilding(r, &cmp_wage, false);
|
|
|
|
|
int esize = 0;
|
|
|
|
|
curse *c;
|
|
|
|
|
double wage;
|
|
|
|
|
attrib *a;
|
|
|
|
|
const building_type *artsculpture_type = bt_find("artsculpture");
|
|
|
|
|
static const curse_type *drought_ct, *blessedharvest_ct;
|
|
|
|
|
static bool init;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-07-23 11:54:51 +02:00
|
|
|
|
if (!init) {
|
|
|
|
|
init = true;
|
|
|
|
|
drought_ct = ct_find("drought");
|
|
|
|
|
blessedharvest_ct = ct_find("blessedharvest");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (b != NULL) {
|
|
|
|
|
/* TODO: this reveals imaginary castles */
|
|
|
|
|
esize = buildingeffsize(b, false);
|
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-07-23 11:54:51 +02:00
|
|
|
|
if (f != NULL) {
|
|
|
|
|
int index = 0;
|
|
|
|
|
if (rc == get_race(RC_ORC) || rc == get_race(RC_SNOTLING)) {
|
|
|
|
|
index = 1;
|
|
|
|
|
}
|
|
|
|
|
wage = wagetable[esize][index];
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (is_mourning(r, in_turn)) {
|
|
|
|
|
wage = 10;
|
|
|
|
|
}
|
|
|
|
|
else if (fval(r->terrain, SEA_REGION)) {
|
|
|
|
|
wage = 11;
|
|
|
|
|
}
|
|
|
|
|
else if (fval(r, RF_ORCIFIED)) {
|
|
|
|
|
wage = wagetable[esize][1];
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
wage = wagetable[esize][2];
|
|
|
|
|
}
|
|
|
|
|
if (rule_blessed_harvest() == HARVEST_WORK) {
|
|
|
|
|
/* E1 rules */
|
|
|
|
|
wage += curse_geteffect(get_curse(r->attribs, blessedharvest_ct));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Artsculpture: Income +5 */
|
|
|
|
|
for (b = r->buildings; b; b = b->next) {
|
|
|
|
|
if (b->type == artsculpture_type) {
|
|
|
|
|
wage += 5;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Godcurse: Income -10 */
|
|
|
|
|
if (curse_active(get_curse(r->attribs, ct_find("godcursezone")))) {
|
|
|
|
|
wage = _max(0, wage - 10);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Bei einer D<>rre verdient man nur noch ein Viertel */
|
|
|
|
|
if (drought_ct) {
|
|
|
|
|
c = get_curse(r->attribs, drought_ct);
|
|
|
|
|
if (curse_active(c))
|
|
|
|
|
wage /= curse_geteffect(c);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
a = a_find(r->attribs, &at_reduceproduction);
|
|
|
|
|
if (a)
|
|
|
|
|
wage = (wage * a->data.sa[0]) / 100;
|
|
|
|
|
|
|
|
|
|
return (int)wage;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2011-03-07 08:02:35 +01:00
|
|
|
|
minimum_wage(const region * r, const faction * f, const race * rc, int in_turn)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2014-07-23 11:54:51 +02:00
|
|
|
|
if (f && rc) {
|
|
|
|
|
return rc->maintenance;
|
|
|
|
|
}
|
|
|
|
|
return default_wage(r, f, rc, in_turn);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Gibt Arbeitslohn f<>r entsprechende Rasse zur<75>ck, oder f<>r
|
|
|
|
|
* die Bauern wenn f == NULL. */
|
2011-03-07 08:02:35 +01:00
|
|
|
|
int wage(const region * r, const faction * f, const race * rc, int in_turn)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2014-07-23 11:54:51 +02:00
|
|
|
|
if (global.functions.wage) {
|
|
|
|
|
return global.functions.wage(r, f, rc, in_turn);
|
|
|
|
|
}
|
|
|
|
|
return default_wage(r, f, rc, in_turn);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
int lovar(double xpct_x2)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2014-07-23 11:54:51 +02:00
|
|
|
|
int n = (int)(xpct_x2 * 500) + 1;
|
|
|
|
|
if (n == 0)
|
|
|
|
|
return 0;
|
|
|
|
|
return (rng_int() % n + rng_int() % n) / 1000;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
void kernel_init(void)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2014-07-06 05:14:11 +02:00
|
|
|
|
register_reports();
|
2015-08-17 19:35:07 +02:00
|
|
|
|
mt_clear();
|
2014-07-06 05:14:11 +02:00
|
|
|
|
translation_init();
|
2015-11-24 19:32:52 +01:00
|
|
|
|
register_function((pf_generic)minimum_wage, "minimum_wage");
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-05-16 22:07:28 +02:00
|
|
|
|
static order * defaults[MAXLOCALES];
|
2015-08-05 00:03:30 +02:00
|
|
|
|
keyword_t default_keyword = NOKEYWORD;
|
|
|
|
|
|
|
|
|
|
void set_default_order(int kwd) {
|
|
|
|
|
default_keyword = (keyword_t)kwd;
|
|
|
|
|
}
|
2012-05-16 22:07:28 +02:00
|
|
|
|
|
2015-10-14 12:51:45 +02:00
|
|
|
|
// TODO: outside of tests, default_keyword is never used, why is this here?
|
|
|
|
|
// see also test_long_order_hungry
|
2011-03-07 08:02:35 +01:00
|
|
|
|
order *default_order(const struct locale *lang)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2014-07-23 11:54:51 +02:00
|
|
|
|
static int usedefault = 1;
|
|
|
|
|
int i = locale_index(lang);
|
|
|
|
|
order *result = 0;
|
|
|
|
|
assert(i < MAXLOCALES);
|
2015-08-05 00:03:30 +02:00
|
|
|
|
|
2015-11-21 13:52:47 +01:00
|
|
|
|
if (default_keyword != NOKEYWORD) {
|
2015-08-05 00:03:30 +02:00
|
|
|
|
return create_order(default_keyword, lang, 0);
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-23 11:54:51 +02:00
|
|
|
|
result = defaults[i];
|
|
|
|
|
if (!result && usedefault) {
|
2015-01-08 20:55:29 +01:00
|
|
|
|
const char * str = LOC(lang, "defaultorder");
|
2014-07-23 11:54:51 +02:00
|
|
|
|
if (str) {
|
|
|
|
|
result = defaults[i] = parse_order(str, lang);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
usedefault = 0;
|
|
|
|
|
}
|
2012-05-16 22:07:28 +02:00
|
|
|
|
}
|
2014-07-23 11:54:51 +02:00
|
|
|
|
return result ? copy_order(result) : 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
int entertainmoney(const region * r)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2014-07-23 11:54:51 +02:00
|
|
|
|
double n;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-07-23 11:54:51 +02:00
|
|
|
|
if (is_cursed(r->attribs, C_DEPRESSION, 0)) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-07-23 11:54:51 +02:00
|
|
|
|
n = rmoney(r) / ENTERTAINFRACTION;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-07-23 11:54:51 +02:00
|
|
|
|
if (is_cursed(r->attribs, C_GENEROUS, 0)) {
|
|
|
|
|
n *= get_curseeffect(r->attribs, C_GENEROUS, 0);
|
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-07-23 11:54:51 +02:00
|
|
|
|
return (int)n;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int rule_give(void)
|
|
|
|
|
{
|
2015-11-22 10:44:46 +01:00
|
|
|
|
return config_get_int("rules.give.flags", GIVE_DEFAULT);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-11-09 13:36:52 +01:00
|
|
|
|
bool markets_module(void)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2015-11-22 10:44:46 +01:00
|
|
|
|
return config_get_int("modules.markets", 0);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-11-22 12:27:08 +01:00
|
|
|
|
static struct param *configuration;
|
|
|
|
|
|
2015-11-22 10:33:31 +01:00
|
|
|
|
void config_set(const char *key, const char *value) {
|
2015-11-22 12:27:08 +01:00
|
|
|
|
set_param(&configuration, key, value);
|
2015-11-22 10:33:31 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char *config_get(const char *key) {
|
2015-11-22 12:27:08 +01:00
|
|
|
|
return get_param(configuration, key);
|
2015-11-22 10:33:31 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int config_get_int(const char *key, int def) {
|
2015-11-22 12:27:08 +01:00
|
|
|
|
return get_param_int(configuration, key, def);
|
2015-11-22 10:33:31 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double config_get_flt(const char *key, double def) {
|
2015-11-22 12:27:08 +01:00
|
|
|
|
return get_param_flt(configuration, key, def);
|
2015-11-22 10:33:31 +01:00
|
|
|
|
}
|
|
|
|
|
|
2015-11-22 12:20:33 +01:00
|
|
|
|
bool config_token(const char *key, const char *tok) {
|
2015-11-22 12:27:08 +01:00
|
|
|
|
return !!check_param(configuration, key, tok);
|
2015-11-22 12:24:27 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void free_config(void) {
|
|
|
|
|
global.functions.maintenance = NULL;
|
|
|
|
|
global.functions.wage = NULL;
|
2015-11-22 12:27:08 +01:00
|
|
|
|
free_params(&configuration);
|
2015-11-22 12:20:33 +01:00
|
|
|
|
}
|
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/** releases all memory associated with the game state.
|
|
|
|
|
* call this function before calling read_game() to load a new game
|
|
|
|
|
* if you have a previously loaded state in memory.
|
|
|
|
|
*/
|
2011-03-07 08:02:35 +01:00
|
|
|
|
void free_gamedata(void)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2014-07-23 11:54:51 +02:00
|
|
|
|
int i;
|
2015-09-09 15:45:20 +02:00
|
|
|
|
free_donations();
|
2014-07-23 11:54:51 +02:00
|
|
|
|
|
|
|
|
|
for (i = 0; i != MAXLOCALES; ++i) {
|
|
|
|
|
if (defaults[i]) {
|
|
|
|
|
free_order(defaults[i]);
|
|
|
|
|
defaults[i] = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-01-11 18:17:24 +01:00
|
|
|
|
free_factions();
|
2016-01-11 18:03:53 +01:00
|
|
|
|
free_units();
|
|
|
|
|
free_regions();
|
|
|
|
|
free_borders();
|
|
|
|
|
free_alliances();
|
2014-07-23 11:54:51 +02:00
|
|
|
|
|
|
|
|
|
while (planes) {
|
|
|
|
|
plane *pl = planes;
|
|
|
|
|
planes = planes->next;
|
|
|
|
|
free(pl->name);
|
|
|
|
|
free(pl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (global.attribs) {
|
|
|
|
|
a_remove(&global.attribs, global.attribs);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char * game_name(void) {
|
2015-11-22 10:44:46 +01:00
|
|
|
|
const char * param = config_get("game.name");
|
2014-07-23 11:54:51 +02:00
|
|
|
|
return param ? param : global.gamename;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int game_id(void) {
|
2015-11-22 10:44:46 +01:00
|
|
|
|
return config_get_int("game.id", 0);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|