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-08-24 22:54:40 +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>
|
|
|
|
#include "race.h"
|
|
|
|
|
|
|
|
#include "alchemy.h"
|
|
|
|
#include "build.h"
|
|
|
|
#include "building.h"
|
|
|
|
#include "equipment.h"
|
|
|
|
#include "faction.h"
|
|
|
|
#include "group.h"
|
|
|
|
#include "item.h"
|
|
|
|
#include "names.h"
|
|
|
|
#include "pathfinder.h"
|
|
|
|
#include "region.h"
|
|
|
|
#include "ship.h"
|
|
|
|
#include "skill.h"
|
2017-01-28 19:42:20 +01:00
|
|
|
#include "spell.h"
|
2010-08-08 10:06:34 +02:00
|
|
|
#include "terrain.h"
|
|
|
|
#include "unit.h"
|
|
|
|
|
|
|
|
/* util includes */
|
2018-09-29 11:37:17 +02:00
|
|
|
#include <kernel/attrib.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
#include <util/functions.h>
|
2016-11-22 12:32:28 +01:00
|
|
|
#include <util/umlaut.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
#include <util/language.h>
|
|
|
|
#include <util/log.h>
|
|
|
|
#include <util/rng.h>
|
2017-12-28 18:29:40 +01:00
|
|
|
#include <util/strings.h>
|
2017-02-06 09:03:08 +01:00
|
|
|
#include <util/variant.h>
|
2013-12-31 10:06:28 +01:00
|
|
|
|
|
|
|
#include <storage.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
/* attrib includes */
|
|
|
|
#include <attributes/raceprefix.h>
|
|
|
|
|
|
|
|
/* libc includes */
|
2012-06-04 03:41:07 +02:00
|
|
|
#include <assert.h>
|
|
|
|
#include <ctype.h>
|
2017-02-28 10:48:27 +01:00
|
|
|
#include <limits.h>
|
2012-06-04 03:41:07 +02:00
|
|
|
#include <math.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
/** external variables **/
|
2011-03-07 08:02:35 +01:00
|
|
|
race *races;
|
2010-08-08 10:06:34 +02:00
|
|
|
int num_races = 0;
|
2016-09-19 06:55:32 +02:00
|
|
|
static int rc_changes = 1;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2017-04-17 20:11:44 +02:00
|
|
|
const char *racenames[MAXRACES] = {
|
2014-06-30 03:10:02 +02:00
|
|
|
"dwarf", "elf", NULL, "goblin", "human", "troll", "demon", "insect",
|
2017-02-20 20:42:31 +01:00
|
|
|
"halfling", "cat", "aquarian", "orc", "snotling", "undead", NULL,
|
2014-06-30 03:10:02 +02:00
|
|
|
"youngdragon", "dragon", "wyrm", "ent", "catdragon", "dracoid",
|
2017-05-24 08:52:19 +02:00
|
|
|
NULL, NULL, "irongolem", "stonegolem", "shadowdemon",
|
2014-06-30 03:10:02 +02:00
|
|
|
"shadowmaster", "mountainguard", "alp", "toad", "braineater", "peasant",
|
|
|
|
"wolf", NULL, NULL, NULL, NULL, "songdragon", NULL,
|
|
|
|
NULL, NULL, NULL, NULL, NULL, NULL, NULL,
|
|
|
|
NULL, NULL, NULL, NULL, NULL, "seaserpent",
|
2016-09-22 18:28:37 +02:00
|
|
|
"shadowknight", NULL, "skeleton", "skeletonlord", "zombie",
|
2017-02-20 22:07:36 +01:00
|
|
|
"juju", "ghoul", "ghast", NULL, NULL, "template",
|
2014-06-30 03:10:02 +02:00
|
|
|
"clone"
|
|
|
|
};
|
|
|
|
|
2018-10-26 16:08:46 +02:00
|
|
|
#define MAX_OPTIONS 4
|
2017-02-06 09:03:08 +01:00
|
|
|
typedef struct rcoption {
|
2018-10-26 16:08:46 +02:00
|
|
|
unsigned char key[MAX_OPTIONS];
|
|
|
|
variant value[MAX_OPTIONS];
|
2017-02-06 09:03:08 +01:00
|
|
|
} rcoption;
|
|
|
|
|
|
|
|
enum {
|
|
|
|
RCO_NONE,
|
2017-02-18 21:15:14 +01:00
|
|
|
RCO_SCARE, /* races that scare and eat peasants */
|
|
|
|
RCO_OTHER, /* may recruit from another race */
|
|
|
|
RCO_STAMINA, /* every n levels of stamina add +1 RC */
|
|
|
|
RCO_HUNGER, /* custom hunger.damage override (char *) */
|
2017-02-06 09:46:36 +01:00
|
|
|
RCO_TRADELUX,
|
2017-02-18 21:15:14 +01:00
|
|
|
RCO_TRADEHERB
|
2017-02-06 09:03:08 +01:00
|
|
|
};
|
|
|
|
|
2017-02-28 10:48:27 +01:00
|
|
|
|
2017-02-06 18:16:34 +01:00
|
|
|
static void rc_setoption(race *rc, int k, const char *value) {
|
|
|
|
unsigned char key = (unsigned char)k;
|
2017-02-06 09:03:08 +01:00
|
|
|
variant *v = NULL;
|
|
|
|
if (!rc->options) {
|
|
|
|
rc->options = malloc(sizeof(rcoption));
|
2018-12-15 19:38:40 +01:00
|
|
|
if (!rc->options) abort();
|
2017-02-06 09:03:08 +01:00
|
|
|
rc->options->key[0] = key;
|
|
|
|
rc->options->key[1] = RCO_NONE;
|
|
|
|
v = rc->options->value;
|
|
|
|
} else {
|
2018-02-25 18:30:20 +01:00
|
|
|
int i;
|
2018-10-26 16:08:46 +02:00
|
|
|
for (i=0;!v && i < MAX_OPTIONS;++i) {
|
2017-02-06 09:03:08 +01:00
|
|
|
if (rc->options->key[i]==key) {
|
|
|
|
v = rc->options->value+i;
|
2017-11-20 08:24:56 +01:00
|
|
|
break;
|
2017-02-06 09:03:08 +01:00
|
|
|
}
|
2017-11-20 08:24:56 +01:00
|
|
|
if (rc->options->key[i]==RCO_NONE) {
|
|
|
|
v = rc->options->value+i;
|
|
|
|
rc->options->key[i] = key;
|
2018-10-26 16:08:46 +02:00
|
|
|
if (i+1 < MAX_OPTIONS) {
|
2017-11-20 08:24:56 +01:00
|
|
|
rc->options->key[i+1]=RCO_NONE;
|
|
|
|
}
|
|
|
|
break;
|
2017-02-06 11:52:07 +01:00
|
|
|
}
|
2017-02-06 09:03:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
assert(v);
|
|
|
|
if (key == RCO_SCARE) {
|
|
|
|
v->i = atoi(value);
|
|
|
|
}
|
2017-02-06 09:46:36 +01:00
|
|
|
else if (key == RCO_STAMINA) {
|
|
|
|
v->i = atoi(value);
|
|
|
|
}
|
2017-02-06 09:03:08 +01:00
|
|
|
else if (key == RCO_OTHER) {
|
|
|
|
v->v = rc_get_or_create(value);
|
|
|
|
}
|
2017-02-06 09:46:36 +01:00
|
|
|
else if (key == RCO_HUNGER) {
|
2017-12-28 18:29:40 +01:00
|
|
|
v->v = str_strdup(value);
|
2017-02-06 09:46:36 +01:00
|
|
|
}
|
|
|
|
else if (key == RCO_TRADEHERB) {
|
|
|
|
v->i = atoi(value);
|
|
|
|
}
|
|
|
|
else if (key == RCO_TRADELUX) {
|
|
|
|
v->i = atoi(value);
|
|
|
|
}
|
2017-02-06 09:03:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static variant *rc_getoption(const race *rc, int key) {
|
|
|
|
if (rc->options) {
|
|
|
|
int i;
|
2018-10-26 16:08:46 +02:00
|
|
|
for (i=0;i!=MAX_OPTIONS && rc->options->key[i]!=RCO_NONE;++i) {
|
2017-02-06 09:03:08 +01:00
|
|
|
if (rc->options->key[i]==key) {
|
|
|
|
return rc->options->value+i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-11-22 12:32:28 +01:00
|
|
|
const struct race *findrace(const char *s, const struct locale *lang)
|
|
|
|
{
|
|
|
|
void **tokens = get_translations(lang, UT_RACES);
|
|
|
|
variant token;
|
|
|
|
|
|
|
|
assert(lang);
|
|
|
|
if (tokens && findtoken(*tokens, s, &token) == E_TOK_SUCCESS) {
|
|
|
|
return (const struct race *)token.v;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-09-20 20:27:41 +02:00
|
|
|
const struct race *get_race(race_t rt) {
|
2014-06-30 04:15:03 +02:00
|
|
|
const char * name;
|
2014-08-24 21:49:55 +02:00
|
|
|
|
2017-04-17 20:11:44 +02:00
|
|
|
assert(rt >= 0);
|
2014-06-30 04:15:03 +02:00
|
|
|
assert(rt < MAXRACES);
|
|
|
|
name = racenames[rt];
|
|
|
|
if (!name) {
|
2016-09-19 06:43:56 +02:00
|
|
|
return NULL;
|
2014-06-30 03:10:02 +02:00
|
|
|
}
|
2016-09-20 20:27:41 +02:00
|
|
|
return rc_find(name);
|
2014-06-30 03:10:02 +02:00
|
|
|
}
|
|
|
|
|
2016-10-04 10:34:18 +02:00
|
|
|
typedef struct xref {
|
|
|
|
race_t id;
|
|
|
|
const race *rc;
|
|
|
|
} rc_xref;
|
|
|
|
|
|
|
|
int cmp_xref(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
const rc_xref *l = (const rc_xref *)a;
|
|
|
|
const rc_xref *r = (const rc_xref *)b;
|
|
|
|
if (l->rc<r->rc) return -1;
|
|
|
|
if (l->rc>r->rc) return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-10-04 10:51:37 +02:00
|
|
|
static rc_xref *xrefs;
|
2016-10-04 10:34:18 +02:00
|
|
|
race_t old_race(const struct race * rc)
|
|
|
|
{
|
|
|
|
static int cache;
|
2018-02-25 18:30:20 +01:00
|
|
|
int l, r;
|
2016-10-04 10:34:18 +02:00
|
|
|
|
|
|
|
if (rc_changed(&cache)) {
|
2018-02-25 18:30:20 +01:00
|
|
|
int i;
|
2016-10-04 10:34:18 +02:00
|
|
|
if (!xrefs) {
|
|
|
|
xrefs = malloc(sizeof(rc_xref) * MAXRACES);
|
2018-12-15 19:38:40 +01:00
|
|
|
if (!xrefs) abort();
|
2016-10-04 10:34:18 +02:00
|
|
|
}
|
|
|
|
for (i = 0; i != MAXRACES; ++i) {
|
|
|
|
xrefs[i].rc = get_race(i);
|
|
|
|
xrefs[i].id = (race_t)i;
|
|
|
|
}
|
|
|
|
qsort(xrefs, MAXRACES, sizeof(rc_xref), cmp_xref);
|
|
|
|
}
|
|
|
|
l=0; r=MAXRACES-1;
|
|
|
|
while (l<=r) {
|
|
|
|
int m = (l+r)/2;
|
|
|
|
if (rc<xrefs[m].rc) {
|
|
|
|
r = m-1;
|
|
|
|
} else if (rc>xrefs[m].rc) {
|
|
|
|
l = m+1;
|
|
|
|
} else {
|
|
|
|
return (race_t)xrefs[m].id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NORACE;
|
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
race_list *get_familiarraces(void)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-08-24 22:54:40 +02:00
|
|
|
static int init = 0;
|
|
|
|
static race_list *familiarraces;
|
|
|
|
|
|
|
|
if (!init) {
|
|
|
|
race *rc = races;
|
|
|
|
for (; rc != NULL; rc = rc->next) {
|
2017-02-20 09:32:03 +01:00
|
|
|
if (rc->flags & RCF_FAMILIAR) {
|
2014-08-24 22:54:40 +02:00
|
|
|
racelist_insert(&familiarraces, rc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
init = false;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
2014-08-24 22:54:40 +02:00
|
|
|
return familiarraces;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
void racelist_insert(struct race_list **rl, const struct race *r)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-08-24 22:54:40 +02:00
|
|
|
race_list *rl2 = (race_list *)malloc(sizeof(race_list));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2018-12-15 19:38:40 +01:00
|
|
|
if (!rl2) abort();
|
2014-08-24 22:54:40 +02:00
|
|
|
rl2->data = r;
|
|
|
|
rl2->next = *rl;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-08-24 22:54:40 +02:00
|
|
|
*rl = rl2;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2018-04-29 13:46:17 +02:00
|
|
|
static int race_mask = 0;
|
|
|
|
|
2014-06-08 07:17:48 +02:00
|
|
|
void free_races(void) {
|
2018-04-29 13:46:17 +02:00
|
|
|
race_mask = 0;
|
2014-06-08 07:17:48 +02:00
|
|
|
while (races) {
|
2017-01-28 19:52:28 +01:00
|
|
|
int i;
|
2014-06-08 07:17:48 +02:00
|
|
|
race * rc = races->next;
|
2017-02-06 09:46:36 +01:00
|
|
|
rcoption * opt = races->options;
|
2017-01-28 19:52:28 +01:00
|
|
|
|
2017-02-06 09:46:36 +01:00
|
|
|
if (opt) {
|
2018-10-26 16:08:46 +02:00
|
|
|
for (i=0;i!=MAX_OPTIONS && opt->key[i]!=RCO_NONE;++i) {
|
2017-02-06 09:46:36 +01:00
|
|
|
if (opt->key[i]==RCO_HUNGER) {
|
|
|
|
free(opt->value[i].v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(opt);
|
|
|
|
}
|
2017-01-28 19:52:28 +01:00
|
|
|
for (i = 0; races->attack[i].type!=AT_NONE; ++i) {
|
2017-02-07 21:37:38 +01:00
|
|
|
att *at = races->attack + i;
|
|
|
|
if (at->type == AT_SPELL) {
|
|
|
|
spellref_free(at->data.sp);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
free(at->data.dice);
|
|
|
|
}
|
2017-01-28 19:52:28 +01:00
|
|
|
}
|
2016-10-04 10:51:37 +02:00
|
|
|
free(xrefs);
|
|
|
|
xrefs = 0;
|
2014-12-30 01:44:28 +01:00
|
|
|
free(races->_name);
|
|
|
|
free(races->def_damage);
|
2014-06-08 07:17:48 +02:00
|
|
|
free(races);
|
2014-08-24 22:54:40 +02:00
|
|
|
races = rc;
|
2014-06-08 07:17:48 +02:00
|
|
|
}
|
2015-11-07 18:14:38 +01:00
|
|
|
num_races = 0;
|
2016-09-19 06:55:32 +02:00
|
|
|
++rc_changes;
|
2014-06-08 07:17:48 +02:00
|
|
|
}
|
|
|
|
|
2014-06-13 07:14:07 +02:00
|
|
|
static race *rc_find_i(const char *name)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-08-24 22:54:40 +02:00
|
|
|
const char *rname = name;
|
|
|
|
race *rc = races;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2016-08-31 09:26:48 +02:00
|
|
|
while (rc && strcmp(rname, rc->_name) != 0) {
|
2014-08-24 22:54:40 +02:00
|
|
|
rc = rc->next;
|
|
|
|
}
|
2017-02-20 20:42:31 +01:00
|
|
|
if (!rc) {
|
2017-02-20 22:07:36 +01:00
|
|
|
const char *rc_depr[] = { "uruk", "orc", "illusion", "template", "juju-zombie", "juju", NULL };
|
2017-02-20 20:42:31 +01:00
|
|
|
int i;
|
|
|
|
for (i = 0; rc_depr[i]; i += 2) {
|
|
|
|
if (strcmp(name, rc_depr[i]) == 0) {
|
|
|
|
rc = rc_find_i(rc_depr[i + 1]);
|
2018-05-10 21:05:51 +02:00
|
|
|
log_info("a reference was made to the retired race '%s', returning '%s'.", name, rc->_name);
|
2017-02-20 20:42:31 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-12-12 11:28:37 +01:00
|
|
|
}
|
2014-08-24 22:54:40 +02:00
|
|
|
return rc;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2014-06-13 07:14:07 +02:00
|
|
|
const race * rc_find(const char *name) {
|
|
|
|
return rc_find_i(name);
|
|
|
|
}
|
|
|
|
|
2016-09-19 06:55:32 +02:00
|
|
|
bool rc_changed(int *cache) {
|
|
|
|
assert(cache);
|
|
|
|
if (*cache != rc_changes) {
|
|
|
|
*cache = rc_changes;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-02-28 10:48:27 +01:00
|
|
|
bool rc_can_use(const struct race *rc, const struct item_type *itype)
|
|
|
|
{
|
|
|
|
if (itype->mask_allow) {
|
2017-03-03 09:56:27 +01:00
|
|
|
return (itype->mask_allow & rc->mask_item) != 0;
|
2017-02-28 10:48:27 +01:00
|
|
|
}
|
|
|
|
if (itype->mask_deny) {
|
|
|
|
return (itype->mask_deny & rc->mask_item) == 0;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-09-20 20:27:41 +02:00
|
|
|
race *rc_create(const char *zName)
|
2014-06-13 07:14:07 +02:00
|
|
|
{
|
2014-06-30 04:15:03 +02:00
|
|
|
race *rc;
|
2015-01-19 15:13:03 +01:00
|
|
|
int i;
|
2017-02-20 21:19:13 +01:00
|
|
|
char zText[64];
|
2014-06-30 04:15:03 +02:00
|
|
|
|
|
|
|
assert(zName);
|
2018-12-15 19:38:40 +01:00
|
|
|
rc = (race *)calloc(1, sizeof(race));
|
|
|
|
if (!rc) abort();
|
2018-04-29 13:46:17 +02:00
|
|
|
|
|
|
|
rc->mask_item = 1 << race_mask;
|
|
|
|
++race_mask;
|
|
|
|
|
2017-02-24 20:47:47 +01:00
|
|
|
rc->magres.sa[1] = 1;
|
2016-09-20 20:27:41 +02:00
|
|
|
rc->hitpoints = 1;
|
2018-05-10 22:00:23 +02:00
|
|
|
rc->flags = RCF_DEFAULT;
|
2016-09-20 20:27:41 +02:00
|
|
|
rc->weight = PERSON_WEIGHT;
|
|
|
|
rc->capacity = 540;
|
2016-10-04 09:14:49 +02:00
|
|
|
rc->income = 20;
|
2016-09-20 20:27:41 +02:00
|
|
|
rc->recruit_multi = 1.0F;
|
|
|
|
rc->regaura = 1.0F;
|
|
|
|
rc->speed = 1.0F;
|
|
|
|
rc->battle_flags = 0;
|
2018-05-09 20:56:38 +02:00
|
|
|
rc->at_default = -2;
|
|
|
|
rc->df_default = -2;
|
2016-09-20 20:27:41 +02:00
|
|
|
if (strchr(zName, ' ') != NULL) {
|
|
|
|
log_error("race '%s' has an invalid name. remove spaces\n", zName);
|
|
|
|
assert(strchr(zName, ' ') == NULL);
|
2014-06-13 07:14:07 +02:00
|
|
|
}
|
2017-12-28 18:29:40 +01:00
|
|
|
rc->_name = str_strdup(zName);
|
2016-09-20 20:27:41 +02:00
|
|
|
|
|
|
|
rc->attack[0].type = AT_COMBATSPELL;
|
|
|
|
for (i = 1; i < RACE_ATTACKS; ++i)
|
|
|
|
rc->attack[i].type = AT_NONE;
|
|
|
|
rc->index = num_races++;
|
|
|
|
++rc_changes;
|
|
|
|
rc->next = races;
|
2017-02-20 21:19:13 +01:00
|
|
|
|
|
|
|
snprintf(zText, sizeof(zText), "age_%s", zName);
|
2017-02-20 22:07:36 +01:00
|
|
|
rc->age_unit = (race_func)get_function(zText);
|
|
|
|
|
|
|
|
snprintf(zText, sizeof(zText), "name_%s", zName);
|
|
|
|
rc->name_unit = (race_func)get_function(zText);
|
|
|
|
|
2016-09-20 20:27:41 +02:00
|
|
|
return races = rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
race *rc_get_or_create(const char *zName)
|
|
|
|
{
|
|
|
|
race *rc;
|
|
|
|
|
|
|
|
assert(zName);
|
|
|
|
rc = rc_find_i(zName);
|
|
|
|
return rc ? rc : rc_create(zName);
|
2014-06-13 07:14:07 +02:00
|
|
|
}
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
/** dragon movement **/
|
2012-06-24 07:41:07 +02:00
|
|
|
bool allowed_dragon(const region * src, const region * target)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-08-24 22:54:40 +02:00
|
|
|
if (fval(src->terrain, ARCTIC_REGION) && fval(target->terrain, SEA_REGION))
|
|
|
|
return false;
|
|
|
|
return allowed_fly(src, target);
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2012-06-24 07:41:07 +02:00
|
|
|
bool r_insectstalled(const region * r)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-08-24 22:54:40 +02:00
|
|
|
return fval(r->terrain, ARCTIC_REGION);
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2017-02-24 20:47:47 +01:00
|
|
|
variant rc_magres(const race *rc) {
|
|
|
|
return rc->magres;
|
2017-02-03 10:57:32 +01:00
|
|
|
}
|
|
|
|
|
2017-02-03 19:50:48 +01:00
|
|
|
double rc_maxaura(const race *rc) {
|
2017-02-03 20:06:01 +01:00
|
|
|
return rc->maxaura / 100.0;
|
2017-02-03 19:50:48 +01:00
|
|
|
}
|
|
|
|
|
2017-02-06 09:46:36 +01:00
|
|
|
const char * rc_hungerdamage(const race *rc)
|
|
|
|
{
|
|
|
|
variant *v = rc_getoption(rc, RCO_HUNGER);
|
|
|
|
return v ? (const char *)v->v : NULL;
|
|
|
|
}
|
|
|
|
|
2017-02-05 18:38:53 +01:00
|
|
|
int rc_armor_bonus(const race *rc)
|
|
|
|
{
|
2017-02-06 09:46:36 +01:00
|
|
|
variant *v = rc_getoption(rc, RCO_STAMINA);
|
|
|
|
return v ? v->i : 0;
|
2017-02-04 23:16:16 +01:00
|
|
|
}
|
|
|
|
|
2017-02-05 18:38:53 +01:00
|
|
|
int rc_scare(const struct race *rc)
|
|
|
|
{
|
2017-02-06 09:03:08 +01:00
|
|
|
variant *v = rc_getoption(rc, RCO_SCARE);
|
|
|
|
return v ? v->i : 0;
|
|
|
|
}
|
|
|
|
|
2017-02-06 09:46:36 +01:00
|
|
|
int rc_luxury_trade(const struct race *rc)
|
|
|
|
{
|
|
|
|
if (rc) {
|
|
|
|
variant *v = rc_getoption(rc, RCO_TRADELUX);
|
|
|
|
if (v) return v->i;
|
|
|
|
}
|
|
|
|
return 1000;
|
|
|
|
}
|
|
|
|
|
|
|
|
int rc_herb_trade(const struct race *rc)
|
|
|
|
{
|
|
|
|
if (rc) {
|
|
|
|
variant *v = rc_getoption(rc, RCO_TRADEHERB);
|
|
|
|
if (v) return v->i;
|
|
|
|
}
|
|
|
|
return 500;
|
|
|
|
}
|
|
|
|
|
2018-05-09 22:16:30 +02:00
|
|
|
void set_study_speed(race *rc, skill_t sk, int modifier) {
|
2018-12-15 19:38:40 +01:00
|
|
|
if (!rc->study_speed) {
|
2018-05-09 22:16:30 +02:00
|
|
|
rc->study_speed = calloc(1, MAXSKILLS);
|
2018-12-15 19:38:40 +01:00
|
|
|
if (!rc->study_speed) abort();
|
|
|
|
}
|
2018-05-09 22:16:30 +02:00
|
|
|
rc->study_speed[sk] = (char)modifier;
|
|
|
|
}
|
|
|
|
|
2017-02-06 09:03:08 +01:00
|
|
|
const race *rc_otherrace(const race *rc)
|
|
|
|
{
|
|
|
|
variant *v = rc_getoption(rc, RCO_OTHER);
|
|
|
|
return v ? (const race *)v->v : NULL;
|
2017-02-05 18:38:53 +01:00
|
|
|
}
|
|
|
|
|
2017-02-04 23:16:16 +01:00
|
|
|
int rc_migrants_formula(const race *rc)
|
|
|
|
{
|
2017-02-04 23:42:50 +01:00
|
|
|
return (rc->flags&RCF_MIGRANTS) ? MIGRANTS_LOG10 : MIGRANTS_NONE;
|
2017-02-04 23:16:16 +01:00
|
|
|
}
|
|
|
|
|
2017-02-05 16:55:51 +01:00
|
|
|
void rc_set_param(struct race *rc, const char *key, const char *value) {
|
|
|
|
if (strcmp(key, "recruit_multi") == 0) {
|
|
|
|
rc->recruit_multi = atof(value);
|
|
|
|
}
|
2017-02-06 09:03:08 +01:00
|
|
|
else if (strcmp(key, "other_race")==0) {
|
|
|
|
rc_setoption(rc, RCO_OTHER, value);
|
|
|
|
}
|
2018-05-09 22:16:30 +02:00
|
|
|
else if (strcmp(key, "scare")==0) {
|
2017-02-06 09:03:08 +01:00
|
|
|
rc_setoption(rc, RCO_SCARE, value);
|
|
|
|
}
|
2018-05-09 22:16:30 +02:00
|
|
|
else if (strcmp(key, "hunger_damage")==0) {
|
2017-02-06 09:46:36 +01:00
|
|
|
rc_setoption(rc, RCO_HUNGER, value);
|
|
|
|
}
|
|
|
|
else if (strcmp(key, "armor.stamina")==0) {
|
|
|
|
rc_setoption(rc, RCO_STAMINA, value);
|
|
|
|
}
|
|
|
|
else if (strcmp(key, "luxury_trade")==0) {
|
|
|
|
rc_setoption(rc, RCO_TRADELUX, value);
|
|
|
|
}
|
|
|
|
else if (strcmp(key, "herb_trade")==0) {
|
|
|
|
rc_setoption(rc, RCO_TRADEHERB, value);
|
|
|
|
}
|
2017-02-05 16:55:51 +01:00
|
|
|
else {
|
2017-02-06 09:46:36 +01:00
|
|
|
log_error("unknown property for race %s: %s=%s", rc->_name, key, value);
|
2017-02-05 16:55:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-17 20:11:44 +02:00
|
|
|
const char* rc_key(const char *rcname, name_t n, char *name, size_t size)
|
|
|
|
{
|
2014-08-24 21:49:55 +02:00
|
|
|
const char * postfix = 0;
|
|
|
|
switch (n) {
|
|
|
|
case NAME_SINGULAR: postfix = ""; break;
|
|
|
|
case NAME_PLURAL: postfix = "_p"; break;
|
|
|
|
case NAME_DEFINITIVE: postfix = "_d"; break;
|
|
|
|
case NAME_CATEGORY: postfix = "_x"; break;
|
2014-12-09 07:20:36 +01:00
|
|
|
default: assert(!"invalid name_t enum in rc_name_s");
|
2014-08-24 21:49:55 +02:00
|
|
|
}
|
|
|
|
if (postfix) {
|
2017-04-17 20:11:44 +02:00
|
|
|
snprintf(name, size, "race::%s%s", rcname, postfix);
|
2014-08-24 21:49:55 +02:00
|
|
|
return name;
|
|
|
|
}
|
|
|
|
return NULL;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2017-04-17 20:11:44 +02:00
|
|
|
const char* rc_name(const race * rc, name_t n, char *name, size_t size)
|
|
|
|
{
|
|
|
|
if (!rc) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return rc_key(rc->_name, n, name, size);
|
|
|
|
}
|
|
|
|
|
2014-12-09 07:20:36 +01:00
|
|
|
const char *rc_name_s(const race * rc, name_t n)
|
|
|
|
{
|
2017-02-18 21:15:14 +01:00
|
|
|
static char name[64]; /* FIXME: static return value */
|
2014-12-09 07:20:36 +01:00
|
|
|
return rc_name(rc, n, name, sizeof(name));
|
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
const char *raceprefix(const unit * u)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2018-10-26 22:12:43 +02:00
|
|
|
group *g = get_group(u);
|
|
|
|
attrib *attr = g ? g->attribs : u->faction->attribs;
|
|
|
|
return get_prefix(attr);
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
const char *racename(const struct locale *loc, const unit * u, const race * rc)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-08-24 22:54:40 +02:00
|
|
|
const char *str, *prefix = raceprefix(u);
|
|
|
|
|
|
|
|
if (prefix != NULL) {
|
2017-02-18 21:15:14 +01:00
|
|
|
static char lbuf[80]; /* FIXME: static return value */
|
2018-01-26 17:39:15 +01:00
|
|
|
sbstring sbs;
|
|
|
|
char ch[2];
|
|
|
|
|
|
|
|
sbs_init(&sbs, lbuf, sizeof(lbuf));
|
2018-12-01 20:25:06 +01:00
|
|
|
sbs_strcat(&sbs, LOC(loc, mkname("prefix", prefix)));
|
2018-01-26 17:39:15 +01:00
|
|
|
|
|
|
|
str = LOC(loc, rc_name_s(rc, u->number != 1));
|
|
|
|
assert(~str[0] & 0x80 || !"unicode/not implemented");
|
|
|
|
ch[0] = (char)tolower(*(unsigned char *)str);
|
|
|
|
ch[1] = 0;
|
|
|
|
sbs_strcat(&sbs, ch);
|
|
|
|
sbs_strcat(&sbs, str + 1);
|
2014-08-24 22:54:40 +02:00
|
|
|
|
|
|
|
return lbuf;
|
|
|
|
}
|
2014-12-09 07:20:36 +01:00
|
|
|
str = LOC(loc, rc_name_s(rc, (u->number == 1) ? NAME_SINGULAR : NAME_PLURAL));
|
2014-08-24 22:54:40 +02:00
|
|
|
return str ? str : rc->_name;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
void write_race_reference(const race * rc, struct storage *store)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-08-24 22:54:40 +02:00
|
|
|
WRITE_TOK(store, rc ? rc->_name : "none");
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2017-09-19 11:42:02 +02:00
|
|
|
struct race * read_race_reference(struct storage *store)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-08-24 22:54:40 +02:00
|
|
|
char zName[20];
|
|
|
|
READ_TOK(store, zName, sizeof(zName));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2014-08-24 22:54:40 +02:00
|
|
|
if (strcmp(zName, "none") == 0) {
|
2017-09-19 11:42:02 +02:00
|
|
|
return NULL;
|
2014-08-24 22:54:40 +02:00
|
|
|
}
|
2017-09-19 11:42:02 +02:00
|
|
|
return rc_find_i(zName);
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
2015-11-24 19:53:27 +01:00
|
|
|
|
2017-02-20 22:07:36 +01:00
|
|
|
void register_race_function(race_func func, const char *name) {
|
2016-08-28 21:02:45 +02:00
|
|
|
register_function((pf_generic)func, name);
|
2015-11-24 19:53:27 +01:00
|
|
|
}
|
2018-04-28 16:14:32 +02:00
|
|
|
|
2018-04-29 13:46:17 +02:00
|
|
|
int rc_mask(const race * rc) {
|
|
|
|
assert(rc->mask_item);
|
|
|
|
return rc->mask_item;
|
|
|
|
}
|
2018-04-28 16:14:32 +02:00
|
|
|
|
2018-04-29 13:46:17 +02:00
|
|
|
int rc_get_mask(char *list) {
|
2018-04-28 16:14:32 +02:00
|
|
|
int mask = 0;
|
|
|
|
char * tok = strtok(list, " ,");
|
|
|
|
while (tok) {
|
|
|
|
race * rc = rc_get_or_create(tok);
|
2018-04-29 13:46:17 +02:00
|
|
|
mask |= rc_mask(rc);
|
2018-04-28 16:14:32 +02:00
|
|
|
tok = strtok(NULL, " ,");
|
|
|
|
}
|
|
|
|
return mask;
|
|
|
|
}
|