Merge branch 'master' of github.com:eressea/server

This commit is contained in:
Enno Rehling 2014-12-29 07:33:49 +01:00
commit 6ffec7017c
25 changed files with 2083 additions and 2151 deletions

View File

@ -54,6 +54,7 @@ attrib_type at_unitdissolve = {
void register_attributes(void)
{
at_deprecate("gm", a_readint);
at_register(&at_stealth);
at_register(&at_object);
at_register(&at_unitdissolve);
@ -61,7 +62,6 @@ void register_attributes(void)
at_register(&at_raceprefix);
at_register(&at_iceberg);
at_register(&at_key);
at_deprecate("gm", a_readint);
at_register(&at_follow);
at_register(&at_targetregion);
at_register(&at_orcification);
@ -69,6 +69,7 @@ void register_attributes(void)
at_register(&at_reduceproduction);
at_register(&at_otherfaction);
at_register(&at_racename);
at_register(&at_speedup);
at_register(&at_movement);
at_register(&at_moved);
}

View File

@ -20,6 +20,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/config.h>
#include "movement.h"
#include <kernel/save.h>
#include <util/attrib.h>
#include <storage.h>
@ -60,3 +61,20 @@ void set_movement(attrib ** alist, int type)
a = a_add(alist, a_new(&at_movement));
a->data.i |= type;
}
static int age_speedup(attrib * a)
{
if (a->data.sa[0] > 0) {
a->data.sa[0] = a->data.sa[0] - a->data.sa[1];
}
return (a->data.sa[0] > 0) ? AT_AGE_KEEP : AT_AGE_REMOVE;
}
attrib_type at_speedup = {
"speedup",
NULL, NULL,
age_speedup,
a_writeint,
a_readint
};

View File

@ -22,11 +22,12 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
extern "C" {
#endif
extern bool get_movement(struct attrib *const *alist, int type);
extern void set_movement(struct attrib **alist, int type);
bool get_movement(struct attrib *const *alist, int type);
void set_movement(struct attrib **alist, int type);
extern struct attrib_type at_movement;
extern struct attrib_type at_speedup;
#ifdef __cplusplus
}
#endif

View File

@ -156,20 +156,20 @@ static void chaos(region * r)
case 0:
mfac = 100;
u =
createunit(r, get_monsters(), rng_int() % 8 + 1,
get_race(RC_FIREDRAGON));
create_unit(r, get_monsters(), rng_int() % 8 + 1,
get_race(RC_FIREDRAGON), 0, NULL, NULL);
break;
case 1:
mfac = 500;
u =
createunit(r, get_monsters(), rng_int() % 4 + 1,
get_race(RC_DRAGON));
create_unit(r, get_monsters(), rng_int() % 4 + 1,
get_race(RC_DRAGON), 0, NULL, NULL);
break;
default:
mfac = 1000;
u =
createunit(r, get_monsters(), rng_int() % 2 + 1,
get_race(RC_WYRM));
create_unit(r, get_monsters(), rng_int() % 2 + 1,
get_race(RC_WYRM), 0, NULL, NULL);
break;
}
if (mfac)

View File

@ -1647,17 +1647,16 @@ static void expandbuying(region * r, request * buyorders)
const luxury_type *type;
int number;
int multi;
} *trades, *trade;
} trades[MAXLUXURIES], *trade;
static int ntrades = 0;
int i, j;
const luxury_type *ltype;
if (ntrades == 0) {
for (ltype = luxurytypes; ltype; ltype = ltype->next)
++ntrades;
trades = gc_add(calloc(sizeof(struct trade), ntrades));
for (i = 0, ltype = luxurytypes; i != ntrades; ++i, ltype = ltype->next)
trades[i].type = ltype;
for (ntrades = 0, ltype = luxurytypes; ltype; ltype = ltype->next) {
assert(ntrades < MAXLUXURIES);
trades[ntrades++].type = ltype;
}
}
for (i = 0; i != ntrades; ++i) {
trades[i].number = 0;
@ -1887,18 +1886,17 @@ static void expandselling(region * r, request * sellorders, int limit)
building *b;
unit *u;
unit *hafenowner;
static int *counter;
static int counter[MAXLUXURIES];
static int ncounter = 0;
if (ncounter == 0) {
const luxury_type *ltype;
for (ltype = luxurytypes; ltype; ltype = ltype->next)
for (ltype = luxurytypes; ltype; ltype = ltype->next) {
assert(ncounter < MAXLUXURIES);
++ncounter;
counter = (int *)gc_add(calloc(sizeof(int), ncounter));
}
else {
memset(counter, 0, sizeof(int) * ncounter);
}
}
memset(counter, 0, sizeof(int) * ncounter);
if (!sellorders) { /* NEIN, denn Insekten können in || !r->buildings) */
return; /* Sümpfen und Wüsten auch so handeln */
@ -1958,6 +1956,7 @@ static void expandselling(region * r, request * sellorders, int limit)
int i;
int use = 0;
for (i = 0, search = luxurytypes; search != ltype; search = search->next) {
// TODO: this is slow and lame!
++i;
}
if (counter[i] >= limit)

View File

@ -29,7 +29,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/ship.h>
#include <kernel/unit.h>
#include <move.h>
#include <attributes/movement.h>
/* util includes */
#include <util/attrib.h>

View File

@ -26,10 +26,10 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "alliance.h"
#include "ally.h"
#include "alchemy.h"
#include "curse.h"
#include "connection.h"
#include "building.h"
#include "calendar.h"
#include "curse.h"
#include "direction.h"
#include "faction.h"
#include "group.h"
@ -442,117 +442,8 @@ int verbosity = 1;
FILE *debug;
static int ShipSpeedBonus(const unit * u)
{
static int level = -1;
if (level == -1) {
level =
get_param_int(global.parameters, "movement.shipspeed.skillbonus", 0);
}
if (level > 0) {
ship *sh = u->ship;
int skl = effskill(u, SK_SAILING);
int minsk = (sh->type->cptskill + 1) / 2;
return (skl - minsk) / level;
}
return 0;
}
int shipspeed(const ship * sh, const unit * u)
{
double k = sh->type->range;
static const curse_type *stormwind_ct, *nodrift_ct;
static bool init;
attrib *a;
curse *c;
if (!init) {
init = true;
stormwind_ct = ct_find("stormwind");
nodrift_ct = ct_find("nodrift");
}
assert(u->ship == sh);
assert(sh->type->construction->improvement == NULL); /* sonst ist construction::size nicht ship_type::maxsize */
if (sh->size != sh->type->construction->maxsize)
return 0;
if (curse_active(get_curse(sh->attribs, stormwind_ct)))
k *= 2;
if (curse_active(get_curse(sh->attribs, nodrift_ct)))
k += 1;
if (u->faction->race == u_race(u)) {
/* race bonus for this faction? */
if (fval(u_race(u), RCF_SHIPSPEED)) {
k += 1;
}
}
k += ShipSpeedBonus(u);
a = a_find(sh->attribs, &at_speedup);
while (a != NULL && a->type == &at_speedup) {
k += a->data.sa[0];
a = a->next;
}
c = get_curse(sh->attribs, ct_find("shipspeedup"));
while (c) {
k += curse_geteffect(c);
c = c->nexthash;
}
#ifdef SHIPSPEED
k *= SHIPSPEED;
#endif
if (sh->damage)
k =
(k * (sh->size * DAMAGE_SCALE - sh->damage) + sh->size * DAMAGE_SCALE -
1) / (sh->size * DAMAGE_SCALE);
return (int)k;
}
/* ----------------------------------------------------------------------- */
void verify_data(void)
{
#ifndef NDEBUG
int lf = -1;
faction *f;
unit *u;
int mage, alchemist;
if (verbosity >= 1)
puts(" - checking data for correctness...");
for (f = factions; f; f = f->next) {
mage = 0;
alchemist = 0;
for (u = f->units; u; u = u->nextF) {
if (eff_skill(u, SK_MAGIC, u->region)) {
mage += u->number;
}
if (eff_skill(u, SK_ALCHEMY, u->region))
alchemist += u->number;
if (u->number > UNIT_MAXSIZE) {
if (lf != f->no) {
lf = f->no;
log_printf(stdout, "Partei %s:\n", factionid(f));
}
log_warning("Einheit %s hat %d Personen\n", unitid(u), u->number);
}
}
if (f->no != 0 && ((mage > 3 && f->race != get_race(RC_ELF)) || mage > 4))
log_error("Partei %s hat %d Magier.\n", factionid(f), mage);
if (alchemist > 3)
log_error("Partei %s hat %d Alchemisten.\n", factionid(f), alchemist);
}
#endif
}
int distribute(int old, int new_value, int n)
{
int i;
@ -570,23 +461,6 @@ int distribute(int old, int new_value, int n)
return t;
}
int change_hitpoints(unit * u, int value)
{
int hp = u->hp;
hp += value;
/* Jede Person benötigt mindestens 1 HP */
if (hp < u->number) {
if (hp < 0) { /* Einheit tot */
hp = 0;
}
scale_number(u, hp);
}
u->hp = hp;
return hp;
}
bool unit_has_cursed_item(const unit * u)
{
item *itm = u->items;
@ -1030,12 +904,6 @@ int newcontainerid(void)
return random_no;
}
unit *createunit(region * r, faction * f, int number, const struct race * rc)
{
assert(rc);
return create_unit(r, f, number, rc, 0, NULL, NULL);
}
bool idle(faction * f)
{
return (bool)(f ? false : true);
@ -1048,36 +916,6 @@ int maxworkingpeasants(const struct region *r)
return _max(size-treespace, _min(size / 10 , 200));
}
void **blk_list[1024];
int list_index;
int blk_index;
static void gc_done(void)
{
int i, k;
for (i = 0; i != list_index; ++i) {
for (k = 0; k != 1024; ++k)
free(blk_list[i][k]);
free(blk_list[i]);
}
for (k = 0; k != blk_index; ++k)
free(blk_list[list_index][k]);
free(blk_list[list_index]);
}
void *gc_add(void *p)
{
if (blk_index == 0) {
blk_list[list_index] = (void **)malloc(1024 * sizeof(void *));
}
blk_list[list_index][blk_index] = p;
blk_index = (blk_index + 1) % 1024;
if (!blk_index)
++list_index;
return p;
}
static const char * parameter_key(int i)
{
assert(i < MAXPARAMS && i >= 0);
@ -1305,7 +1143,6 @@ void kernel_done(void)
* calling it is optional, e.g. a release server will most likely not do it.
*/
translation_done();
gc_done();
}
attrib_type at_germs = {
@ -1318,9 +1155,6 @@ attrib_type at_germs = {
ATF_UNIQUE
};
/*********************/
/* at_guard */
/*********************/
attrib_type at_guard = {
"guard",
DEFAULT_INIT,
@ -1392,38 +1226,6 @@ bool faction_id_is_unused(int id)
return findfaction(id) == NULL;
}
int weight(const unit * u)
{
int w = 0, n = 0, in_bag = 0;
const resource_type *rtype = get_resourcetype(R_BAG_OF_HOLDING);
item *itm;
for (itm = u->items; itm; itm = itm->next) {
w = itm->type->weight * itm->number;
n += w;
if (rtype && !fval(itm->type, ITF_BIG)) {
in_bag += w;
}
}
n += u->number * u_race(u)->weight;
if (rtype) {
w = i_get(u->items, rtype->itype) * BAGCAPACITY;
if (w > in_bag) w = in_bag;
n -= w;
}
return n;
}
void make_undead_unit(unit * u)
{
free_orders(&u->orders);
name_unit(u);
fset(u, UFL_ISNEW);
}
unsigned int guard_flags(const unit * u)
{
unsigned int flags =
@ -1816,7 +1618,6 @@ static int read_ext(attrib * a, void *owner, struct storage *store)
void attrib_init(void)
{
/* Alle speicherbaren Attribute müssen hier registriert werden */
at_register(&at_speedup);
at_register(&at_shiptrail);
at_register(&at_familiar);
at_register(&at_familiarmage);

View File

@ -40,6 +40,7 @@ extern "C" {
#ifndef MAXUNITS
# define MAXUNITS 1048573 /* must be prime for hashing. 524287 was >90% full */
#endif
#define MAXLUXURIES 16 /* there must be no more than MAXLUXURIES kinds of luxury goods in any game */
#define TREESIZE (8) /* space used by trees (in #peasants) */
@ -91,7 +92,6 @@ extern "C" {
#define want(option) (1<<option)
/* ------------------------------------------------------------- */
int shipspeed(const struct ship *sh, const struct unit *u);
#define i2b(i) ((bool)((i)?(true):(false)))
@ -105,9 +105,6 @@ extern "C" {
int max_magicians(const struct faction * f);
int findoption(const char *s, const struct locale *lang);
/* special units */
void make_undead_unit(struct unit *);
param_t findparam(const char *s, const struct locale *lang);
param_t findparam_ex(const char *s, const struct locale * lang);
bool isparam(const char *s, const struct locale * lang, param_t param);
@ -132,9 +129,6 @@ extern "C" {
int forbiddenid(int id);
int newcontainerid(void);
struct unit *createunit(struct region *r, struct faction *f,
int number, const struct race *rc);
void create_unitid(struct unit *u, int id);
int getunit(const struct region * r, const struct faction * f, struct unit **uresult);
int read_unitid(const struct faction *f, const struct region *r);
@ -187,26 +181,9 @@ extern "C" {
bool has_limited_skills(const struct unit *u);
const struct race *findrace(const char *, const struct locale *);
int ispresent(const struct faction *f, const struct region *r);
int check_option(struct faction *f, int option);
/* Anzahl Personen in einer Einheit festlegen. NUR (!) mit dieser Routine,
* sonst großes Unglück. Durch asserts an ein paar Stellen abgesichert. */
void verify_data(void);
int change_hitpoints(struct unit *u, int value);
int weight(const struct unit *u);
void changeblockchaos(void);
bool idle(struct faction *f);
bool unit_has_cursed_item(const struct unit *u);
/* simple garbage collection: */
void *gc_add(void *p);
/* grammatik-flags: */
#define GF_NONE 0
/* singular, ohne was dran */

View File

@ -258,7 +258,7 @@ unit *addplayer(region * r, faction * f)
assert(f->units == NULL);
set_ursprung(f, 0, r->x, r->y);
u = createunit(r, f, 1, f->race);
u = create_unit(r, f, 1, f->race, 0, NULL, NULL);
equip_items(&u->faction->items, get_equipment("new_faction"));
equip_unit(u, get_equipment("first_unit"));
sprintf(buffer, "first_%s", u_race(u)->_name);

File diff suppressed because it is too large Load Diff

View File

@ -274,20 +274,8 @@ int readorders(const char *filename)
const char *s;
init_tokens_str(b);
s = gettoken(token, sizeof(token));
p = s ? findparam(s, lang) : NOPARAM;
p = (s && s[0] != '@') ? findparam(s, lang) : NOPARAM;
switch (p) {
#undef LOCALE_CHANGE
#ifdef LOCALE_CHANGE
case P_LOCALE:
{
const char *s = getstrtoken();
if (f && get_locale(s)) {
f->locale = get_locale(s);
}
}
b = getbuf(F, enc_gamedata);
break;
#endif
case P_GAMENAME:
case P_FACTION:
f = factionorders();
@ -311,8 +299,8 @@ int readorders(const char *filename)
break;
}
init_tokens_str(b);
b = getstrtoken();
p = (!b || b[0] == '@') ? NOPARAM : findparam(b, lang);
s = gettoken(token, sizeof(token));
p = (s && s[0] != '@') ? findparam(s, lang) : NOPARAM;
} while ((p != P_UNIT || !f) && p != P_FACTION && p != P_NEXT
&& p != P_GAMENAME);
break;
@ -1030,11 +1018,12 @@ void writeregion(struct gamedata *data, const region * r)
WRITE_INT(data->store, rherbs(r));
WRITE_INT(data->store, rpeasants(r));
WRITE_INT(data->store, rmoney(r));
if (r->land)
if (r->land) {
for (demand = r->land->demands; demand; demand = demand->next) {
WRITE_TOK(data->store, resourcename(demand->type->itype->rtype, 0));
WRITE_INT(data->store, demand->value);
}
}
WRITE_TOK(data->store, "end");
write_items(data->store, r->land->items);
WRITE_SECTION(data->store);

View File

@ -1,7 +1,7 @@
/*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de>
Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
@ -22,6 +22,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* kernel includes */
#include "build.h"
#include "curse.h"
#include "faction.h"
#include "unit.h"
#include "item.h"
#include "race.h"
@ -39,6 +41,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <quicklist.h>
#include <util/xml.h>
#include <attributes/movement.h>
#include <storage.h>
/* libc includes */
@ -53,48 +57,48 @@ static local_names *snames;
const ship_type *findshiptype(const char *name, const struct locale *lang)
{
local_names *sn = snames;
variant var;
local_names *sn = snames;
variant var;
while (sn) {
if (sn->lang == lang)
break;
sn = sn->next;
}
if (!sn) {
quicklist *ql;
int qi;
sn = (local_names *) calloc(sizeof(local_names), 1);
sn->next = snames;
sn->lang = lang;
for (qi = 0, ql = shiptypes; ql; ql_advance(&ql, &qi, 1)) {
ship_type *stype = (ship_type *) ql_get(ql, qi);
variant var2;
const char *n = locale_string(lang, stype->_name);
var2.v = (void *)stype;
addtoken(&sn->names, n, var2);
while (sn) {
if (sn->lang == lang)
break;
sn = sn->next;
}
snames = sn;
}
if (findtoken(sn->names, name, &var) == E_TOK_NOMATCH)
return NULL;
return (const ship_type *)var.v;
if (!sn) {
quicklist *ql;
int qi;
sn = (local_names *)calloc(sizeof(local_names), 1);
sn->next = snames;
sn->lang = lang;
for (qi = 0, ql = shiptypes; ql; ql_advance(&ql, &qi, 1)) {
ship_type *stype = (ship_type *)ql_get(ql, qi);
variant var2;
const char *n = locale_string(lang, stype->_name);
var2.v = (void *)stype;
addtoken(&sn->names, n, var2);
}
snames = sn;
}
if (findtoken(sn->names, name, &var) == E_TOK_NOMATCH)
return NULL;
return (const ship_type *)var.v;
}
static ship_type *st_find_i(const char *name)
{
quicklist *ql;
int qi;
quicklist *ql;
int qi;
for (qi = 0, ql = shiptypes; ql; ql_advance(&ql, &qi, 1)) {
ship_type *stype = (ship_type *) ql_get(ql, qi);
if (strcmp(stype->_name, name) == 0) {
return stype;
for (qi = 0, ql = shiptypes; ql; ql_advance(&ql, &qi, 1)) {
ship_type *stype = (ship_type *)ql_get(ql, qi);
if (strcmp(stype->_name, name) == 0) {
return stype;
}
}
}
return NULL;
return NULL;
}
const ship_type *st_find(const char *name) {
@ -115,60 +119,60 @@ ship_type *st_get_or_create(const char * name) {
ship *shiphash[MAXSHIPHASH];
void shash(ship * s)
{
ship *old = shiphash[s->no % MAXSHIPHASH];
ship *old = shiphash[s->no % MAXSHIPHASH];
shiphash[s->no % MAXSHIPHASH] = s;
s->nexthash = old;
shiphash[s->no % MAXSHIPHASH] = s;
s->nexthash = old;
}
void sunhash(ship * s)
{
ship **show;
ship **show;
for (show = &shiphash[s->no % MAXSHIPHASH]; *show; show = &(*show)->nexthash) {
if ((*show)->no == s->no)
break;
}
if (*show) {
assert(*show == s);
*show = (*show)->nexthash;
s->nexthash = 0;
}
for (show = &shiphash[s->no % MAXSHIPHASH]; *show; show = &(*show)->nexthash) {
if ((*show)->no == s->no)
break;
}
if (*show) {
assert(*show == s);
*show = (*show)->nexthash;
s->nexthash = 0;
}
}
static ship *sfindhash(int i)
{
ship *old;
ship *old;
for (old = shiphash[i % MAXSHIPHASH]; old; old = old->nexthash)
if (old->no == i)
return old;
return 0;
for (old = shiphash[i % MAXSHIPHASH]; old; old = old->nexthash)
if (old->no == i)
return old;
return 0;
}
struct ship *findship(int i)
{
return sfindhash(i);
return sfindhash(i);
}
struct ship *findshipr(const region * r, int n)
{
ship *sh;
ship *sh;
for (sh = r->ships; sh; sh = sh->next) {
if (sh->no == n) {
assert(sh->region == r);
return sh;
for (sh = r->ships; sh; sh = sh->next) {
if (sh->no == n) {
assert(sh->region == r);
return sh;
}
}
}
return 0;
return 0;
}
void damage_ship(ship * sh, double percent)
{
double damage =
DAMAGE_SCALE * sh->type->damage * percent * sh->size + sh->damage;
sh->damage = (int)damage;
double damage =
DAMAGE_SCALE * sh->type->damage * percent * sh->size + sh->damage;
sh->damage = (int)damage;
}
/* Alte Schiffstypen: */
@ -176,62 +180,62 @@ static ship *deleted_ships;
ship *new_ship(const ship_type * stype, region * r, const struct locale *lang)
{
static char buffer[32];
ship *sh = (ship *) calloc(1, sizeof(ship));
const char *sname = 0;
static char buffer[32];
ship *sh = (ship *)calloc(1, sizeof(ship));
const char *sname = 0;
assert(stype);
sh->no = newcontainerid();
sh->coast = NODIRECTION;
sh->type = stype;
sh->region = r;
assert(stype);
sh->no = newcontainerid();
sh->coast = NODIRECTION;
sh->type = stype;
sh->region = r;
sname = LOC(lang, stype->_name);
if (!sname) {
sname = LOC(lang, parameters[P_SHIP]);
sname = LOC(lang, stype->_name);
if (!sname) {
sname = parameters[P_SHIP];
sname = LOC(lang, parameters[P_SHIP]);
if (!sname) {
sname = parameters[P_SHIP];
}
}
}
assert(sname);
slprintf(buffer, sizeof(buffer), "%s %s", sname, shipid(sh));
sh->name = _strdup(buffer);
shash(sh);
if (r) {
addlist(&r->ships, sh);
}
return sh;
assert(sname);
slprintf(buffer, sizeof(buffer), "%s %s", sname, shipid(sh));
sh->name = _strdup(buffer);
shash(sh);
if (r) {
addlist(&r->ships, sh);
}
return sh;
}
void remove_ship(ship ** slist, ship * sh)
{
region *r = sh->region;
unit *u = r->units;
region *r = sh->region;
unit *u = r->units;
handle_event(sh->attribs, "destroy", sh);
while (u) {
if (u->ship == sh) {
leave_ship(u);
handle_event(sh->attribs, "destroy", sh);
while (u) {
if (u->ship == sh) {
leave_ship(u);
}
u = u->next;
}
u = u->next;
}
sunhash(sh);
while (*slist && *slist != sh)
slist = &(*slist)->next;
assert(*slist);
*slist = sh->next;
sh->next = deleted_ships;
deleted_ships = sh;
sh->region = NULL;
sunhash(sh);
while (*slist && *slist != sh)
slist = &(*slist)->next;
assert(*slist);
*slist = sh->next;
sh->next = deleted_ships;
deleted_ships = sh;
sh->region = NULL;
}
void free_ship(ship * s)
{
while (s->attribs)
a_remove(&s->attribs, s->attribs);
free(s->name);
free(s->display);
free(s);
while (s->attribs)
a_remove(&s->attribs, s->attribs);
free(s->name);
free(s->display);
free(s);
}
void free_shiptypes(void) {
@ -242,121 +246,194 @@ void free_shiptypes(void) {
void free_ships(void)
{
while (deleted_ships) {
ship *s = deleted_ships;
deleted_ships = s->next;
}
while (deleted_ships) {
ship *s = deleted_ships;
deleted_ships = s->next;
}
}
const char *write_shipname(const ship * sh, char *ibuf, size_t size)
{
slprintf(ibuf, size, "%s (%s)", sh->name, itoa36(sh->no));
return ibuf;
slprintf(ibuf, size, "%s (%s)", sh->name, itoa36(sh->no));
return ibuf;
}
static int ShipSpeedBonus(const unit * u)
{
static int level = -1;
if (level == -1) {
level =
get_param_int(global.parameters, "movement.shipspeed.skillbonus", 0);
}
if (level > 0) {
ship *sh = u->ship;
int skl = effskill(u, SK_SAILING);
int minsk = (sh->type->cptskill + 1) / 2;
return (skl - minsk) / level;
}
return 0;
}
int shipspeed(const ship * sh, const unit * u)
{
double k = sh->type->range;
static const struct curse_type *stormwind_ct, *nodrift_ct;
static bool init;
attrib *a;
struct curse *c;
if (!init) {
init = true;
stormwind_ct = ct_find("stormwind");
nodrift_ct = ct_find("nodrift");
}
assert(u->ship == sh);
assert(sh->type->construction->improvement == NULL); /* sonst ist construction::size nicht ship_type::maxsize */
if (sh->size != sh->type->construction->maxsize)
return 0;
if (curse_active(get_curse(sh->attribs, stormwind_ct)))
k *= 2;
if (curse_active(get_curse(sh->attribs, nodrift_ct)))
k += 1;
if (u->faction->race == u_race(u)) {
/* race bonus for this faction? */
if (fval(u_race(u), RCF_SHIPSPEED)) {
k += 1;
}
}
k += ShipSpeedBonus(u);
a = a_find(sh->attribs, &at_speedup);
while (a != NULL && a->type == &at_speedup) {
k += a->data.sa[0];
a = a->next;
}
c = get_curse(sh->attribs, ct_find("shipspeedup"));
while (c) {
k += curse_geteffect(c);
c = c->nexthash;
}
#ifdef SHIPSPEED
k *= SHIPSPEED;
#endif
if (sh->damage)
k =
(k * (sh->size * DAMAGE_SCALE - sh->damage) + sh->size * DAMAGE_SCALE -
1) / (sh->size * DAMAGE_SCALE);
return (int)k;
}
const char *shipname(const ship * sh)
{
typedef char name[OBJECTIDSIZE + 1];
static name idbuf[8];
static int nextbuf = 0;
char *ibuf = idbuf[(++nextbuf) % 8];
return write_shipname(sh, ibuf, sizeof(name));
typedef char name[OBJECTIDSIZE + 1];
static name idbuf[8];
static int nextbuf = 0;
char *ibuf = idbuf[(++nextbuf) % 8];
return write_shipname(sh, ibuf, sizeof(name));
}
int shipcapacity(const ship * sh)
{
int i = sh->type->cargo;
int i = sh->type->cargo;
/* sonst ist construction:: size nicht ship_type::maxsize */
assert(!sh->type->construction
|| sh->type->construction->improvement == NULL);
/* sonst ist construction:: size nicht ship_type::maxsize */
assert(!sh->type->construction
|| sh->type->construction->improvement == NULL);
if (sh->type->construction && sh->size != sh->type->construction->maxsize)
return 0;
if (sh->type->construction && sh->size != sh->type->construction->maxsize)
return 0;
if (sh->damage) {
i = (int)ceil(i * (1.0 - sh->damage / sh->size / (double)DAMAGE_SCALE));
}
return i;
if (sh->damage) {
i = (int)ceil(i * (1.0 - sh->damage / sh->size / (double)DAMAGE_SCALE));
}
return i;
}
void getshipweight(const ship * sh, int *sweight, int *scabins)
{
unit *u;
unit *u;
*sweight = 0;
*scabins = 0;
*sweight = 0;
*scabins = 0;
for (u = sh->region->units; u; u = u->next) {
if (u->ship == sh) {
*sweight += weight(u);
if (sh->type->cabins) {
int pweight = u->number * u_race(u)->weight;
/* weight goes into number of cabins, not cargo */
*scabins += pweight;
*sweight -= pweight;
}
for (u = sh->region->units; u; u = u->next) {
if (u->ship == sh) {
*sweight += weight(u);
if (sh->type->cabins) {
int pweight = u->number * u_race(u)->weight;
/* weight goes into number of cabins, not cargo */
*scabins += pweight;
*sweight -= pweight;
}
}
}
}
}
void ship_set_owner(unit * u) {
assert(u && u->ship);
u->ship->_owner = u;
assert(u && u->ship);
u->ship->_owner = u;
}
static unit * ship_owner_ex(const ship * sh, const struct faction * last_owner)
{
unit *u, *heir = 0;
unit *u, *heir = 0;
/* Eigentümer tot oder kein Eigentümer vorhanden. Erste lebende Einheit
* nehmen. */
for (u = sh->region->units; u; u = u->next) {
if (u->ship == sh) {
if (u->number > 0) {
if (heir && last_owner && heir->faction!=last_owner && u->faction==last_owner) {
heir = u;
break; /* we found someone from the same faction who is not dead. let's take this guy */
/* Eigentümer tot oder kein Eigentümer vorhanden. Erste lebende Einheit
* nehmen. */
for (u = sh->region->units; u; u = u->next) {
if (u->ship == sh) {
if (u->number > 0) {
if (heir && last_owner && heir->faction != last_owner && u->faction == last_owner) {
heir = u;
break; /* we found someone from the same faction who is not dead. let's take this guy */
}
else if (!heir) {
heir = u; /* you'll do in an emergency */
}
}
}
else if (!heir) {
heir = u; /* you'll do in an emergency */
}
}
}
}
return heir;
return heir;
}
void ship_update_owner(ship * sh) {
unit * owner = sh->_owner;
sh->_owner = ship_owner_ex(sh, owner?owner->faction:0);
unit * owner = sh->_owner;
sh->_owner = ship_owner_ex(sh, owner ? owner->faction : 0);
}
unit *ship_owner(const ship * sh)
{
unit *owner = sh->_owner;
if (!owner || (owner->ship!=sh || owner->number<=0)) {
unit * heir = ship_owner_ex(sh, owner?owner->faction:0);
return (heir && heir->number>0) ? heir : 0;
}
return owner;
unit *owner = sh->_owner;
if (!owner || (owner->ship != sh || owner->number <= 0)) {
unit * heir = ship_owner_ex(sh, owner ? owner->faction : 0);
return (heir && heir->number > 0) ? heir : 0;
}
return owner;
}
void write_ship_reference(const struct ship *sh, struct storage *store)
{
WRITE_INT(store, (sh && sh->region) ? sh->no : 0);
WRITE_INT(store, (sh && sh->region) ? sh->no : 0);
}
void ship_setname(ship * self, const char *name)
{
free(self->name);
if (name)
self->name = _strdup(name);
else
self->name = NULL;
free(self->name);
if (name)
self->name = _strdup(name);
else
self->name = NULL;
}
const char *ship_getname(const ship * self)
{
return self->name;
return self->name;
}

View File

@ -124,6 +124,7 @@ extern "C" {
extern const char *ship_getname(const struct ship *self);
extern void ship_setname(struct ship *self, const char *name);
int shipspeed(const struct ship *sh, const struct unit *u);
#ifdef __cplusplus
}

View File

@ -159,8 +159,8 @@ void spawn_braineaters(float chance)
/* Neues Monster ? */
if (next-- == 0) {
unit *u =
createunit(r, f0, 1 + rng_int() % 10 + rng_int() % 10,
get_race(RC_HIRNTOETER));
create_unit(r, f0, 1 + rng_int() % 10 + rng_int() % 10,
get_race(RC_HIRNTOETER), 0, NULL, NULL);
equip_unit(u, get_equipment("monster_braineater"));
next = rng_int() % (int)(chance * 100);

View File

@ -67,6 +67,31 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#define FIND_FOREIGN_TEMP
int weight(const unit * u)
{
int w = 0, n = 0, in_bag = 0;
const resource_type *rtype = get_resourcetype(R_BAG_OF_HOLDING);
item *itm;
for (itm = u->items; itm; itm = itm->next) {
w = itm->type->weight * itm->number;
n += w;
if (rtype && !fval(itm->type, ITF_BIG)) {
in_bag += w;
}
}
n += u->number * u_race(u)->weight;
if (rtype) {
w = i_get(u->items, rtype->itype) * BAGCAPACITY;
if (w > in_bag) w = in_bag;
n -= w;
}
return n;
}
attrib_type at_creator = {
"creator"
/* Rest ist NULL; temporaeres, nicht alterndes Attribut */

View File

@ -125,6 +125,7 @@ extern "C" {
extern struct attrib_type at_showskchange;
int ualias(const struct unit *u);
int weight(const struct unit *u);
const struct race *u_irace(const struct unit *u);
const struct race *u_race(const struct unit *u);

View File

@ -644,7 +644,7 @@ static weapon_type *xml_readweapon(xmlXPathContextPtr xpath, item_type * itype)
xmlFree(propValue);
propValue = xmlGetProp(node, BAD_CAST "value");
wtype->damage[pos] = gc_add(_strdup((const char *)propValue));
wtype->damage[pos] = _strdup((const char *)propValue); // TODO: this is a memory leak
if (k == 0)
wtype->damage[1 - pos] = wtype->damage[pos];
xmlFree(propValue);

View File

@ -367,7 +367,7 @@ static void guardian_faction(plane * pl, int id)
}
if (u)
continue;
u = createunit(r, f, 1, get_race(RC_GOBLIN));
u = create_unit(r, f, 1, get_race(RC_GOBLIN), 0, NULL, NULL);
set_string(&u->name, "Igjarjuks Auge");
i_change(&u->items, it_find("roi"), 1);
set_order(&u->thisorder, NULL);

File diff suppressed because it is too large Load Diff

View File

@ -630,7 +630,7 @@ static void recruit_dracoids(unit * dragon, int size)
region *r = dragon->region;
const struct item *weapon = NULL;
order *new_order = NULL;
unit *un = createunit(r, f, size, get_race(RC_DRACOID));
unit *un = create_unit(r, f, size, get_race(RC_DRACOID), 0, NULL, NULL);
fset(un, UFL_ISNEW | UFL_MOVED);
@ -908,7 +908,7 @@ void spawn_dragons(void)
unit *u;
if (fval(r->terrain, SEA_REGION) && rng_int() % 10000 < 1) {
u = createunit(r, monsters, 1, get_race(RC_SEASERPENT));
u = create_unit(r, monsters, 1, get_race(RC_SEASERPENT), 0, NULL, NULL);
fset(u, UFL_ISNEW | UFL_MOVED);
equip_unit(u, get_equipment("monster_seaserpent"));
}
@ -918,9 +918,9 @@ void spawn_dragons(void)
|| r->terrain == newterrain(T_DESERT))
&& rng_int() % 10000 < (5 + 100 * chaosfactor(r))) {
if (chance(0.80)) {
u = createunit(r, monsters, nrand(60, 20) + 1, get_race(RC_FIREDRAGON));
u = create_unit(r, monsters, nrand(60, 20) + 1, get_race(RC_FIREDRAGON), 0, NULL, NULL);
} else {
u = createunit(r, monsters, nrand(30, 20) + 1, get_race(RC_DRAGON));
u = create_unit(r, monsters, nrand(30, 20) + 1, get_race(RC_DRAGON), 0, NULL, NULL);
}
fset(u, UFL_ISNEW | UFL_MOVED);
equip_unit(u, get_equipment("monster_dragon"));
@ -983,7 +983,7 @@ void spawn_undead(void)
break;
}
u = createunit(r, monsters, undead, rc);
u = create_unit(r, monsters, undead, rc, 0, NULL, NULL);
fset(u, UFL_ISNEW | UFL_MOVED);
if ((rc == get_race(RC_SKELETON) || rc == get_race(RC_ZOMBIE))
&& rng_int() % 10 < 4) {

View File

@ -170,22 +170,6 @@ attrib_type at_shiptrail = {
shiptrail_read
};
static int age_speedup(attrib * a)
{
if (a->data.sa[0] > 0) {
a->data.sa[0] = a->data.sa[0] - a->data.sa[1];
}
return (a->data.sa[0] > 0) ? AT_AGE_KEEP : AT_AGE_REMOVE;
}
attrib_type at_speedup = {
"speedup",
NULL, NULL,
age_speedup,
a_writeint,
a_readint
};
/* ------------------------------------------------------------- */
static attrib_type at_driveweight = {

View File

@ -31,7 +31,6 @@ extern "C" {
struct ship;
struct building_type;
extern struct attrib_type at_speedup;
extern struct attrib_type at_shiptrail;
/* die Zahlen sind genau äquivalent zu den race Flags */

View File

@ -15,7 +15,8 @@
extern "C" {
#endif
extern void register_races(void);
void register_races(void);
void make_undead_unit(struct unit *);
#ifdef __cplusplus
}

View File

@ -17,6 +17,7 @@
/* kernel includes */
#include <kernel/race.h>
#include <kernel/order.h>
#include <kernel/unit.h>
#include <kernel/faction.h>
#include <kernel/region.h>
@ -35,6 +36,13 @@
#define age_chance(a,b,p) (_max(0,a-b)*p)
void make_undead_unit(unit * u)
{
free_orders(&u->orders);
name_unit(u);
fset(u, UFL_ISNEW);
}
void age_undead(unit * u)
{
region *r = u->region;

View File

@ -56,6 +56,8 @@
#include <kernel/xmlreader.h>
#include <kernel/version.h>
#include <races/races.h>
/* util includes */
#include <util/attrib.h>
#include <util/base36.h>
@ -2782,6 +2784,23 @@ static int sp_unholypower(castorder * co)
return cast_level;
}
static int change_hitpoints(unit * u, int value)
{
int hp = u->hp;
hp += value;
/* Jede Person benötigt mindestens 1 HP */
if (hp < u->number) {
if (hp < 0) { /* Einheit tot */
hp = 0;
}
scale_number(u, hp);
}
u->hp = hp;
return hp;
}
static int dc_age(struct curse *c)
/* age returns 0 if the attribute needs to be removed, !=0 otherwise */
{