indentation rules, strictly applied

This commit is contained in:
Enno 2011-03-07 08:03:10 +01:00
parent 6286c3212d
commit 347a888b67
24 changed files with 4472 additions and 3270 deletions

View file

@ -10,28 +10,34 @@
#include <tolua.h> #include <tolua.h>
static int static int tolua_levitate_ship(lua_State * L)
tolua_levitate_ship(lua_State * L)
{ {
ship *sh = (ship *) tolua_tousertype(L, 1, 0); ship *sh = (ship *) tolua_tousertype(L, 1, 0);
unit *mage = (unit *) tolua_tousertype(L, 2, 0); unit *mage = (unit *) tolua_tousertype(L, 2, 0);
double power = (double)tolua_tonumber(L, 3, 0); double power = (double)tolua_tonumber(L, 3, 0);
int duration = (int)tolua_tonumber(L, 4, 0); int duration = (int)tolua_tonumber(L, 4, 0);
int cno = levitate_ship(sh, mage, power, duration); int cno = levitate_ship(sh, mage, power, duration);
tolua_pushnumber(L, (lua_Number) cno); tolua_pushnumber(L, (lua_Number) cno);
return 1; return 1;
} }
extern void spawn_undead(void); extern void spawn_undead(void);
extern void spawn_dragons(void); extern void spawn_dragons(void);
extern void plan_monsters(struct faction *f); extern void plan_monsters(struct faction *f);
static int static int tolua_planmonsters(lua_State * L)
tolua_planmonsters(lua_State * L)
{ {
faction *f = (faction *) tolua_tousertype(L, 1, get_monsters()); faction *f = (faction *) tolua_tousertype(L, 1, get_monsters());
if (f) { if (f) {
plan_monsters(f); plan_monsters(f);
} }
@ -39,31 +45,32 @@ tolua_planmonsters(lua_State * L)
return 0; return 0;
} }
static int static int tolua_spawn_dragons(lua_State * L)
tolua_spawn_dragons(lua_State * L)
{ {
spawn_dragons(); spawn_dragons();
return 0; return 0;
} }
static int static int tolua_spawn_undead(lua_State * L)
tolua_spawn_undead(lua_State * L)
{ {
spawn_undead(); spawn_undead();
return 0; return 0;
} }
static int static int fix_familiars(struct lua_State *L)
fix_familiars(struct lua_State * L)
{ {
faction *f; faction *f;
for (f = factions; f; f = f->next) { for (f = factions; f; f = f->next) {
unit *u; unit *u;
for (u = f->units; u; u = u->nextF) { for (u = f->units; u; u = u->nextF) {
struct sc_mage *mage = get_mage(u); struct sc_mage *mage = get_mage(u);
if (mage && is_familiar(u)) { if (mage && is_familiar(u)) {
if (mage->spells && mage->magietyp == M_GRAY) { if (mage->spells && mage->magietyp == M_GRAY) {
equipment *eq; equipment *eq;
char buffer[64]; char buffer[64];
ql_free(mage->spells); ql_free(mage->spells);
@ -80,8 +87,7 @@ fix_familiars(struct lua_State * L)
return 0; return 0;
} }
void void bind_eressea(struct lua_State *L)
bind_eressea(struct lua_State * L)
{ {
tolua_module(L, NULL, 0); tolua_module(L, NULL, 0);
tolua_beginmodule(L, NULL); tolua_beginmodule(L, NULL);
@ -94,4 +100,3 @@ bind_eressea(struct lua_State * L)
} }
tolua_endmodule(L); tolua_endmodule(L);
} }

View file

@ -33,17 +33,19 @@ typedef struct wallcurse {
connection *wall; connection *wall;
} wallcurse; } wallcurse;
void void cw_init(attrib * a)
cw_init(attrib * a) { {
curse *c; curse *c;
curse_init(a); curse_init(a);
c = (curse *) a->data.v; c = (curse *) a->data.v;
c->data.v = calloc(sizeof(wallcurse), 1); c->data.v = calloc(sizeof(wallcurse), 1);
} }
void void cw_write(const attrib * a, const void *target, storage * store)
cw_write(const attrib * a, const void * target, storage * store) { {
connection *b = ((wallcurse *) ((curse *) a->data.v)->data.v)->wall; connection *b = ((wallcurse *) ((curse *) a->data.v)->data.v)->wall;
curse_write(a, target, store); curse_write(a, target, store);
store->w_int(store, b->id); store->w_int(store, b->id);
} }
@ -55,12 +57,14 @@ typedef struct bresvole {
static int resolve_buddy(variant data, void *addr); static int resolve_buddy(variant data, void *addr);
static int static int cw_read(attrib * a, void *target, storage * store)
cw_read(attrib * a, void * target, storage * store)
{ {
bresolve *br = calloc(sizeof(bresolve), 1); bresolve *br = calloc(sizeof(bresolve), 1);
curse *c = (curse *) a->data.v; curse *c = (curse *) a->data.v;
wallcurse *wc = (wallcurse *) c->data.v; wallcurse *wc = (wallcurse *) c->data.v;
variant var; variant var;
curse_read(a, store, target); curse_read(a, store, target);
@ -75,8 +79,7 @@ cw_read(attrib * a, void * target, storage * store)
return AT_READ_OK; return AT_READ_OK;
} }
attrib_type at_cursewall = attrib_type at_cursewall = {
{
"cursewall", "cursewall",
cw_init, cw_init,
curse_done, curse_done,
@ -87,10 +90,10 @@ attrib_type at_cursewall =
}; };
static int static int resolve_buddy(variant data, void *addr)
resolve_buddy(variant data, void * addr)
{ {
curse *result = NULL; curse *result = NULL;
bresolve *br = (bresolve *) data.v; bresolve *br = (bresolve *) data.v;
if (br->id >= 0) { if (br->id >= 0) {
@ -98,23 +101,31 @@ resolve_buddy(variant data, void * addr)
if (b && b->from && b->to) { if (b && b->from && b->to) {
attrib *a = a_find(b->from->attribs, &at_cursewall); attrib *a = a_find(b->from->attribs, &at_cursewall);
while (a && a->data.v != br->self) { while (a && a->data.v != br->self) {
curse *c = (curse *) a->data.v; curse *c = (curse *) a->data.v;
wallcurse *wc = (wallcurse *) c->data.v; wallcurse *wc = (wallcurse *) c->data.v;
if (wc->wall->id==br->id) break;
if (wc->wall->id == br->id)
break;
a = a->next; a = a->next;
} }
if (!a || a->type != &at_cursewall) { if (!a || a->type != &at_cursewall) {
a = a_find(b->to->attribs, &at_cursewall); a = a_find(b->to->attribs, &at_cursewall);
while (a && a->type == &at_cursewall && a->data.v != br->self) { while (a && a->type == &at_cursewall && a->data.v != br->self) {
curse *c = (curse *) a->data.v; curse *c = (curse *) a->data.v;
wallcurse *wc = (wallcurse *) c->data.v; wallcurse *wc = (wallcurse *) c->data.v;
if (wc->wall->id==br->id) break;
if (wc->wall->id == br->id)
break;
a = a->next; a = a->next;
} }
} }
if (a && a->type == &at_cursewall) { if (a && a->type == &at_cursewall) {
curse *c = (curse *) a->data.v; curse *c = (curse *) a->data.v;
free(br); free(br);
result = c; result = c;
} }
@ -129,25 +140,25 @@ resolve_buddy(variant data, void * addr)
return 0; return 0;
} }
static void static void wall_init(connection * b)
wall_init(connection * b)
{ {
wall_data *fd = (wall_data *) calloc(sizeof(wall_data), 1); wall_data *fd = (wall_data *) calloc(sizeof(wall_data), 1);
fd->countdown = -1; /* infinite */ fd->countdown = -1; /* infinite */
b->data.v = fd; b->data.v = fd;
} }
static void static void wall_destroy(connection * b)
wall_destroy(connection * b)
{ {
free(b->data.v); free(b->data.v);
} }
static void static void wall_read(connection * b, storage * store)
wall_read(connection * b, storage * store)
{ {
wall_data *fd = (wall_data *) b->data.v; wall_data *fd = (wall_data *) b->data.v;
variant mno; variant mno;
assert(fd); assert(fd);
if (store->version < STORAGE_VERSION) { if (store->version < STORAGE_VERSION) {
mno.i = store->r_int(store); mno.i = store->r_int(store);
@ -165,36 +176,39 @@ wall_read(connection * b, storage * store)
fd->active = true; fd->active = true;
} }
static void static void wall_write(const connection * b, storage * store)
wall_write(const connection * b, storage * store)
{ {
wall_data *fd = (wall_data *) b->data.v; wall_data *fd = (wall_data *) b->data.v;
write_unit_reference(fd->mage, store); write_unit_reference(fd->mage, store);
store->w_int(store, fd->force); store->w_int(store, fd->force);
store->w_int(store, fd->countdown); store->w_int(store, fd->countdown);
} }
static int static int wall_age(connection * b)
wall_age(connection * b)
{ {
wall_data *fd = (wall_data *) b->data.v; wall_data *fd = (wall_data *) b->data.v;
--fd->countdown; --fd->countdown;
return (fd->countdown > 0) ? AT_AGE_KEEP : AT_AGE_REMOVE; return (fd->countdown > 0) ? AT_AGE_KEEP : AT_AGE_REMOVE;
} }
static region * static region *wall_move(const connection * b, struct unit *u,
wall_move(const connection * b, struct unit * u, struct region * from, struct region * to, boolean routing) struct region *from, struct region *to, boolean routing)
{ {
wall_data *fd = (wall_data *) b->data.v; wall_data *fd = (wall_data *) b->data.v;
if (!routing && fd->active) { if (!routing && fd->active) {
int hp = dice(3, fd->force) * u->number; int hp = dice(3, fd->force) * u->number;
hp = MIN(u->hp, hp); hp = MIN(u->hp, hp);
u->hp -= hp; u->hp -= hp;
if (u->hp) { if (u->hp) {
ADDMSG(&u->faction->msgs, msg_message("firewall_damage", ADDMSG(&u->faction->msgs, msg_message("firewall_damage",
"region unit", from, u)); "region unit", from, u));
} } else
else ADDMSG(&u->faction->msgs, msg_message("firewall_death", "region unit", from, u)); ADDMSG(&u->faction->msgs, msg_message("firewall_death", "region unit",
from, u));
if (u->number > u->hp) { if (u->number > u->hp) {
scale_number(u, u->hp); scale_number(u, u->hp);
u->hp = u->number; u->hp = u->number;
@ -203,17 +217,21 @@ wall_move(const connection * b, struct unit * u, struct region * from, struct re
return to; return to;
} }
static const char * static const char *b_namefirewall(const connection * b, const region * r,
b_namefirewall(const connection * b, const region * r, const faction * f, int gflags) const faction * f, int gflags)
{ {
const char *bname; const char *bname;
unused(f); unused(f);
unused(r); unused(r);
unused(b); unused(b);
if (gflags & GF_ARTICLE) bname = "a_firewall"; if (gflags & GF_ARTICLE)
else bname = "firewall"; bname = "a_firewall";
else
bname = "firewall";
if (gflags & GF_PURE) return bname; if (gflags & GF_PURE)
return bname;
return LOC(f->locale, mkname("border", bname)); return LOC(f->locale, mkname("border", bname));
} }
@ -239,15 +257,17 @@ void convert_firewall_timeouts(connection * b, attrib * a)
while (a) { while (a) {
if (b->type == &bt_firewall && a->type == &at_countdown) { if (b->type == &bt_firewall && a->type == &at_countdown) {
wall_data *fd = (wall_data *) b->data.v; wall_data *fd = (wall_data *) b->data.v;
fd->countdown = a->data.i; fd->countdown = a->data.i;
} }
} }
} }
static const char * static const char *wisps_name(const connection * b, const region * r,
wisps_name(const connection * b, const region * r, const faction * f, int gflags) const faction * f, int gflags)
{ {
const char *bname; const char *bname;
unused(f); unused(f);
unused(r); unused(r);
unused(b); unused(b);
@ -256,7 +276,8 @@ wisps_name(const connection * b, const region * r, const faction * f, int gflags
} else { } else {
bname = "wisps"; bname = "wisps";
} }
if (gflags & GF_PURE) return bname; if (gflags & GF_PURE)
return bname;
return LOC(f->locale, mkname("border", bname)); return LOC(f->locale, mkname("border", bname));
} }
@ -265,29 +286,37 @@ typedef struct wisps_data {
int rnd; int rnd;
} wisps_data; } wisps_data;
static region * static region *wisps_move(const connection * b, struct unit *u,
wisps_move(const connection * b, struct unit * u, struct region * from, struct region * next, boolean routing) struct region *from, struct region *next, boolean routing)
{ {
direction_t reldir = reldirection(from, next); direction_t reldir = reldirection(from, next);
wisps_data *wd = (wisps_data *) b->data.v; wisps_data *wd = (wisps_data *) b->data.v;
assert(reldir != D_SPECIAL); assert(reldir != D_SPECIAL);
if (routing && wd->wall.active) { if (routing && wd->wall.active) {
region * rl = rconnect(from, (direction_t)((reldir+MAXDIRECTIONS-1)%MAXDIRECTIONS)); region *rl =
rconnect(from,
(direction_t) ((reldir + MAXDIRECTIONS - 1) % MAXDIRECTIONS));
region *rr = rconnect(from, (direction_t) ((reldir + 1) % MAXDIRECTIONS)); region *rr = rconnect(from, (direction_t) ((reldir + 1) % MAXDIRECTIONS));
/* pick left and right region: */ /* pick left and right region: */
if (wd->rnd < 0) { if (wd->rnd < 0) {
wd->rnd = rng_int() % 3; wd->rnd = rng_int() % 3;
} }
if (wd->rnd == 1 && rl && fval(rl->terrain, LAND_REGION)==fval(next, LAND_REGION)) return rl; if (wd->rnd == 1 && rl
if (wd->rnd == 2 && rr && fval(rr->terrain, LAND_REGION)==fval(next, LAND_REGION)) return rr; && fval(rl->terrain, LAND_REGION) == fval(next, LAND_REGION))
return rl;
if (wd->rnd == 2 && rr
&& fval(rr->terrain, LAND_REGION) == fval(next, LAND_REGION))
return rr;
} }
return next; return next;
} }
static void static void wisps_init(connection * b)
wisps_init(connection * b)
{ {
wisps_data *wd = (wisps_data *) calloc(sizeof(wisps_data), 1); wisps_data *wd = (wisps_data *) calloc(sizeof(wisps_data), 1);
@ -311,8 +340,7 @@ border_type bt_wisps = {
wisps_move wisps_move
}; };
void void register_curses(void)
register_curses(void)
{ {
border_convert_cb = &convert_firewall_timeouts; border_convert_cb = &convert_firewall_timeouts;
at_register(&at_cursewall); at_register(&at_cursewall);

View file

@ -15,13 +15,17 @@
#include <tests.h> #include <tests.h>
static const char *luafile = "setup.lua"; static const char *luafile = "setup.lua";
static const char *entry_point = NULL; static const char *entry_point = NULL;
static const char *inifile = "eressea.ini"; static const char *inifile = "eressea.ini";
static int memdebug = 0; static int memdebug = 0;
static void parse_config(const char *filename) static void parse_config(const char *filename)
{ {
dictionary *d = iniparser_new(filename); dictionary *d = iniparser_new(filename);
if (d) { if (d) {
load_inifile(d); load_inifile(d);
@ -38,8 +42,7 @@ static void parse_config(const char * filename)
global.inifile = d; global.inifile = d;
} }
static int static int usage(const char *prog, const char *arg)
usage(const char * prog, const char * arg)
{ {
if (arg) { if (arg) {
fprintf(stderr, "unknown argument: %s\n\n", arg); fprintf(stderr, "unknown argument: %s\n\n", arg);
@ -50,15 +53,14 @@ usage(const char * prog, const char * arg)
"-v <level> : verbosity level\n" "-v <level> : verbosity level\n"
"-C : run in interactive mode\n" "-C : run in interactive mode\n"
"--color : force curses to use colors even when not detected\n" "--color : force curses to use colors even when not detected\n"
"--tests : run testsuite\n" "--tests : run testsuite\n" "--help : help\n", prog);
"--help : help\n", prog);
return -1; return -1;
} }
static int static int parse_args(int argc, char **argv, int *exitcode)
parse_args(int argc, char **argv, int *exitcode)
{ {
int i; int i;
int run_tests = 0; int run_tests = 0;
for (i = 1; i != argc; ++i) { for (i = 1; i != argc; ++i) {
@ -68,23 +70,21 @@ parse_args(int argc, char **argv, int *exitcode)
if (strcmp(argv[i] + 2, "version") == 0) { if (strcmp(argv[i] + 2, "version") == 0) {
printf("\n%s PBEM host\n" printf("\n%s PBEM host\n"
"Copyright (C) 1996-2005 C. Schlittchen, K. Zedel, E. Rehling, H. Peters.\n\n" "Copyright (C) 1996-2005 C. Schlittchen, K. Zedel, E. Rehling, H. Peters.\n\n"
"Compilation: " __DATE__ " at " __TIME__ "\nVersion: %f\n\n", global.gamename, version()); "Compilation: " __DATE__ " at " __TIME__ "\nVersion: %f\n\n",
} global.gamename, version());
else if (strcmp(argv[i]+2, "color")==0) { } else if (strcmp(argv[i] + 2, "color") == 0) {
/* force the editor to have colors */ /* force the editor to have colors */
force_color = 1; force_color = 1;
} } else if (strcmp(argv[i] + 2, "tests") == 0) {
else if (strcmp(argv[i]+2, "tests")==0) {
/* force the editor to have colors */ /* force the editor to have colors */
run_tests = 1; run_tests = 1;
} } else if (strcmp(argv[i] + 2, "help") == 0) {
else if (strcmp(argv[i]+2, "help")==0) {
return usage(argv[0], NULL); return usage(argv[0], NULL);
} } else {
else {
return usage(argv[0], argv[i]); return usage(argv[0], argv[i]);
} }
} else switch(argv[i][1]) { } else
switch (argv[i][1]) {
case 'C': case 'C':
entry_point = NULL; entry_point = NULL;
break; break;
@ -122,11 +122,12 @@ parse_args(int argc, char **argv, int *exitcode)
#include <execinfo.h> #include <execinfo.h>
#include <signal.h> #include <signal.h>
static void static void report_segfault(int signo, siginfo_t * sinf, void *arg)
report_segfault(int signo, siginfo_t * sinf, void * arg)
{ {
void *btrace[50]; void *btrace[50];
size_t size; size_t size;
int fd = fileno(stderr); int fd = fileno(stderr);
fflush(stdout); fflush(stdout);
@ -136,8 +137,7 @@ report_segfault(int signo, siginfo_t * sinf, void * arg)
abort(); abort();
} }
static int static int setup_signal_handler(void)
setup_signal_handler(void)
{ {
struct sigaction act; struct sigaction act;
@ -147,8 +147,7 @@ setup_signal_handler(void)
return sigaction(SIGSEGV, &act, NULL); return sigaction(SIGSEGV, &act, NULL);
} }
#else #else
static int static int setup_signal_handler(void)
setup_signal_handler(void)
{ {
return 0; return 0;
} }
@ -157,11 +156,11 @@ setup_signal_handler(void)
#undef CRTDBG #undef CRTDBG
#ifdef CRTDBG #ifdef CRTDBG
#include <crtdbg.h> #include <crtdbg.h>
void void init_crtdbg(void)
init_crtdbg(void)
{ {
#if (defined(_MSC_VER)) #if (defined(_MSC_VER))
int flags = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG); int flags = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
if (memdebug == 1) { if (memdebug == 1) {
flags |= _CRTDBG_CHECK_ALWAYS_DF; /* expensive */ flags |= _CRTDBG_CHECK_ALWAYS_DF; /* expensive */
} else if (memdebug == 2) { } else if (memdebug == 2) {
@ -177,35 +176,44 @@ init_crtdbg(void)
#endif #endif
static void static void dump_spells(void)
dump_spells(void)
{ {
struct locale *loc = find_locale("de"); struct locale *loc = find_locale("de");
FILE *F = fopen("spells.csv", "w"); FILE *F = fopen("spells.csv", "w");
quicklist *ql; quicklist *ql;
int qi; int qi;
for (ql = spells, qi = 0; ql; ql_advance(&ql, &qi, 1)) { for (ql = spells, qi = 0; ql; ql_advance(&ql, &qi, 1)) {
spell *sp = (spell *) ql_get(ql, qi); spell *sp = (spell *) ql_get(ql, qi);
spell_component *spc = sp->components; spell_component *spc = sp->components;
char components[128]; char components[128];
components[0] = 0; components[0] = 0;
for (; spc->type; ++spc) { for (; spc->type; ++spc) {
strcat(components, LOC(loc, spc->type->_name[0])); strcat(components, LOC(loc, spc->type->_name[0]));
strcat(components, ","); strcat(components, ",");
} }
fprintf(F, "%s;%d;%s;%s\n", LOC(loc, mkname("spell", sp->sname)), sp->level, LOC(loc, mkname("school", magic_school[sp->magietyp])), components); fprintf(F, "%s;%d;%s;%s\n", LOC(loc, mkname("spell", sp->sname)), sp->level,
LOC(loc, mkname("school", magic_school[sp->magietyp])), components);
} }
fclose(F); fclose(F);
} }
static void static void dump_skills(void)
dump_skills(void)
{ {
struct locale *loc = find_locale("de"); struct locale *loc = find_locale("de");
FILE *F = fopen("skills.csv", "w"); FILE *F = fopen("skills.csv", "w");
race *rc; race *rc;
skill_t sk; skill_t sk;
fputs("\"Rasse\",", F); fputs("\"Rasse\",", F);
for (rc = races; rc; rc = rc->next) { for (rc = races; rc; rc = rc->next) {
if (playerrace(rc)) { if (playerrace(rc)) {
@ -216,12 +224,15 @@ dump_skills(void)
for (sk = 0; sk != MAXSKILLS; ++sk) { for (sk = 0; sk != MAXSKILLS; ++sk) {
const char *str = skillname(sk, loc); const char *str = skillname(sk, loc);
if (str) { if (str) {
fprintf(F, "\"%s\",", str); fprintf(F, "\"%s\",", str);
for (rc = races; rc; rc = rc->next) { for (rc = races; rc; rc = rc->next) {
if (playerrace(rc)) { if (playerrace(rc)) {
if (rc->bonus[sk]) fprintf(F, "%d,", rc->bonus[sk]); if (rc->bonus[sk])
else fputc(',', F); fprintf(F, "%d,", rc->bonus[sk]);
else
fputc(',', F);
} }
} }
fputc('\n', F); fputc('\n', F);
@ -235,7 +246,9 @@ void locale_init(void)
setlocale(LC_CTYPE, ""); setlocale(LC_CTYPE, "");
setlocale(LC_NUMERIC, "C"); setlocale(LC_NUMERIC, "C");
if (towlower(0xC4) != 0xE4) { /* &Auml; => &auml; */ if (towlower(0xC4) != 0xE4) { /* &Auml; => &auml; */
log_error(("Umlaut conversion is not working properly. Wrong locale? LANG=%s\n", getenv("LANG"))); log_error(
("Umlaut conversion is not working properly. Wrong locale? LANG=%s\n",
getenv("LANG")));
} }
} }
@ -244,6 +257,7 @@ extern void bind_eressea(struct lua_State * L);
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
static int write_csv = 0; static int write_csv = 0;
int err, result = 0; int err, result = 0;
setup_signal_handler(); setup_signal_handler();
@ -282,13 +296,14 @@ int main(int argc, char ** argv)
log_error(("server execution failed with code %d\n", err)); log_error(("server execution failed with code %d\n", err));
return err; return err;
} }
#ifdef MSPACES #ifdef MSPACES
malloc_stats(); malloc_stats();
#endif #endif
eressea_done(); eressea_done();
log_close(); log_close();
if (global.inifile) iniparser_free(global.inifile); if (global.inifile)
iniparser_free(global.inifile);
return 0; return 0;
} }

View file

@ -72,11 +72,12 @@
#define DRAGON_RANGE 20 /* Max. Distanz zum nächsten Drachenziel */ #define DRAGON_RANGE 20 /* Max. Distanz zum nächsten Drachenziel */
#define MAXILLUSION_TEXTS 3 #define MAXILLUSION_TEXTS 3
static void static void reduce_weight(unit * u)
reduce_weight(unit * u)
{ {
int capacity, weight = 0; int capacity, weight = 0;
item **itmp = &u->items; item **itmp = &u->items;
int horses = get_resource(u, oldresourcetype[R_HORSE]); int horses = get_resource(u, oldresourcetype[R_HORSE]);
if (horses > 0) { if (horses > 0) {
@ -87,12 +88,15 @@ reduce_weight(unit * u)
/* 0. ditch any vehicles */ /* 0. ditch any vehicles */
while (*itmp != NULL) { while (*itmp != NULL) {
item *itm = *itmp; item *itm = *itmp;
const item_type *itype = itm->type; const item_type *itype = itm->type;
weight += itm->number * itype->weight; weight += itm->number * itype->weight;
if (itype->flags & ITF_VEHICLE) { if (itype->flags & ITF_VEHICLE) {
give_item(itm->number, itm->type, u, NULL, NULL); give_item(itm->number, itm->type, u, NULL, NULL);
} }
if (*itmp==itm) itmp=&itm->next; if (*itmp == itm)
itmp = &itm->next;
} }
capacity = walkingcapacity(u); capacity = walkingcapacity(u);
@ -100,56 +104,70 @@ reduce_weight(unit * u)
/* 1. get rid of anything that isn't silver or really lightweight or helpful in combat */ /* 1. get rid of anything that isn't silver or really lightweight or helpful in combat */
for (itmp = &u->items; *itmp && capacity > 0;) { for (itmp = &u->items; *itmp && capacity > 0;) {
item *itm = *itmp; item *itm = *itmp;
const item_type *itype = itm->type; const item_type *itype = itm->type;
weight += itm->number * itype->weight; weight += itm->number * itype->weight;
if (weight > capacity) { if (weight > capacity) {
if (itype->weight>=10 && itype->rtype->wtype==0 && itype->rtype->atype==0) { if (itype->weight >= 10 && itype->rtype->wtype == 0
&& itype->rtype->atype == 0) {
if (itype->capacity < itype->weight) { if (itype->capacity < itype->weight) {
int reduce = MIN(itm->number, -((capacity - weight) / itype->weight)); int reduce = MIN(itm->number, -((capacity - weight) / itype->weight));
give_item(reduce, itm->type, u, NULL, NULL); give_item(reduce, itm->type, u, NULL, NULL);
weight -= reduce * itype->weight; weight -= reduce * itype->weight;
} }
} }
} }
if (*itmp==itm) itmp=&itm->next; if (*itmp == itm)
itmp = &itm->next;
} }
for (itmp = &u->items; *itmp && weight > capacity;) { for (itmp = &u->items; *itmp && weight > capacity;) {
item *itm = *itmp; item *itm = *itmp;
const item_type *itype = itm->type; const item_type *itype = itm->type;
weight += itm->number * itype->weight; weight += itm->number * itype->weight;
if (itype->capacity < itype->weight) { if (itype->capacity < itype->weight) {
int reduce = MIN(itm->number, -((capacity - weight) / itype->weight)); int reduce = MIN(itm->number, -((capacity - weight) / itype->weight));
give_item(reduce, itm->type, u, NULL, NULL); give_item(reduce, itm->type, u, NULL, NULL);
weight -= reduce * itype->weight; weight -= reduce * itype->weight;
} }
if (*itmp==itm) itmp=&itm->next; if (*itmp == itm)
itmp = &itm->next;
} }
} }
static order * static order *monster_attack(unit * u, const unit * target)
monster_attack(unit * u, const unit * target)
{ {
if (u->region!=target->region) return NULL; if (u->region != target->region)
if (u->faction==target->faction) return NULL; return NULL;
if (!cansee(u->faction, u->region, target, 0)) return NULL; if (u->faction == target->faction)
if (monster_is_waiting(u)) return NULL; return NULL;
if (!cansee(u->faction, u->region, target, 0))
return NULL;
if (monster_is_waiting(u))
return NULL;
return create_order(K_ATTACK, u->faction->locale, "%i", target->no); return create_order(K_ATTACK, u->faction->locale, "%i", target->no);
} }
static order * static order *get_money_for_dragon(region * r, unit * u, int wanted)
get_money_for_dragon(region * r, unit * u, int wanted)
{ {
unit *u2; unit *u2;
int n; int n;
/* attackiere bewachende einheiten */ /* attackiere bewachende einheiten */
for (u2 = r->units; u2; u2 = u2->next) { for (u2 = r->units; u2; u2 = u2->next) {
if (u2 != u && is_guard(u2, GUARD_TAX)) { if (u2 != u && is_guard(u2, GUARD_TAX)) {
order *ord = monster_attack(u, u2); order *ord = monster_attack(u, u2);
if (ord) addlist(&u->orders, ord);
if (ord)
addlist(&u->orders, ord);
} }
} }
@ -166,9 +184,12 @@ get_money_for_dragon(region * r, unit * u, int wanted)
for (u2 = r->units; u2; u2 = u2->next) { for (u2 = r->units; u2; u2 = u2->next) {
if (u2->faction != u->faction && cansee(u->faction, r, u2, 0)) { if (u2->faction != u->faction && cansee(u->faction, r, u2, 0)) {
int m = get_money(u2); int m = get_money(u2);
if (m==0 || is_guard(u2, GUARD_TAX)) continue;
if (m == 0 || is_guard(u2, GUARD_TAX))
continue;
else { else {
order *ord = monster_attack(u, u2); order *ord = monster_attack(u, u2);
if (ord) { if (ord) {
addlist(&u->orders, ord); addlist(&u->orders, ord);
n += m; n += m;
@ -187,10 +208,10 @@ get_money_for_dragon(region * r, unit * u, int wanted)
return NULL; return NULL;
} }
static int static int all_money(region * r, faction * f)
all_money(region * r, faction * f)
{ {
unit *u; unit *u;
int m; int m;
m = rmoney(r); m = rmoney(r);
@ -202,14 +223,15 @@ all_money(region * r, faction * f)
return m; return m;
} }
static direction_t static direction_t richest_neighbour(region * r, faction * f, int absolut)
richest_neighbour(region * r, faction * f, int absolut)
{ {
/* m - maximum an Geld, d - Richtung, i - index, t = Geld hier */ /* m - maximum an Geld, d - Richtung, i - index, t = Geld hier */
double m; double m;
double t; double t;
direction_t d = NODIRECTION, i; direction_t d = NODIRECTION, i;
if (absolut == 1 || rpeasants(r) == 0) { if (absolut == 1 || rpeasants(r) == 0) {
@ -222,6 +244,7 @@ richest_neighbour(region * r, faction * f, int absolut)
for (i = 0; i != MAXDIRECTIONS; i++) { for (i = 0; i != MAXDIRECTIONS; i++) {
region *rn = rconnect(r, i); region *rn = rconnect(r, i);
if (rn != NULL && fval(rn->terrain, LAND_REGION)) { if (rn != NULL && fval(rn->terrain, LAND_REGION)) {
if (absolut == 1 || rpeasants(rn) == 0) { if (absolut == 1 || rpeasants(rn) == 0) {
t = (double)all_money(rn, f); t = (double)all_money(rn, f);
@ -238,14 +261,15 @@ richest_neighbour(region * r, faction * f, int absolut)
return d; return d;
} }
static boolean static boolean room_for_race_in_region(region * r, const race * rc)
room_for_race_in_region(region *r, const race * rc)
{ {
unit *u; unit *u;
int c = 0; int c = 0;
for (u = r->units; u; u = u->next) { for (u = r->units; u; u = u->next) {
if(u->race == rc) c += u->number; if (u->race == rc)
c += u->number;
} }
if (c > (rc->splitsize * 2)) if (c > (rc->splitsize * 2))
@ -254,11 +278,12 @@ room_for_race_in_region(region *r, const race * rc)
return true; return true;
} }
static direction_t static direction_t random_neighbour(region * r, unit * u)
random_neighbour(region * r, unit *u)
{ {
direction_t i; direction_t i;
region *rc; region *rc;
int rr, c = 0, c2 = 0; int rr, c = 0, c2 = 0;
/* Nachsehen, wieviele Regionen in Frage kommen */ /* Nachsehen, wieviele Regionen in Frage kommen */
@ -297,7 +322,8 @@ random_neighbour(region * r, unit *u)
} else if (room_for_race_in_region(rc, u->race)) { } else if (room_for_race_in_region(rc, u->race)) {
c++; c++;
} }
if (c == rr) return i; if (c == rr)
return i;
} }
} }
@ -305,11 +331,12 @@ random_neighbour(region * r, unit *u)
return NODIRECTION; return NODIRECTION;
} }
static direction_t static direction_t treeman_neighbour(region * r)
treeman_neighbour(region * r)
{ {
direction_t i; direction_t i;
int rr; int rr;
int c = 0; int c = 0;
/* Nachsehen, wieviele Regionen in Frage kommen */ /* Nachsehen, wieviele Regionen in Frage kommen */
@ -349,12 +376,12 @@ treeman_neighbour(region * r)
return NODIRECTION; return NODIRECTION;
} }
static order * static order *monster_move(region * r, unit * u)
monster_move(region * r, unit * u)
{ {
direction_t d = NODIRECTION; direction_t d = NODIRECTION;
if (monster_is_waiting(u)) return NULL; if (monster_is_waiting(u))
return NULL;
switch (old_race(u->race)) { switch (old_race(u->race)) {
case RC_FIREDRAGON: case RC_FIREDRAGON:
case RC_DRAGON: case RC_DRAGON:
@ -376,11 +403,11 @@ monster_move(region * r, unit * u)
return NULL; return NULL;
reduce_weight(u); reduce_weight(u);
return create_order(K_MOVE, u->faction->locale, "%s", LOC(u->faction->locale, directions[d])); return create_order(K_MOVE, u->faction->locale, "%s", LOC(u->faction->locale,
directions[d]));
} }
static int static int dragon_affinity_value(region * r, unit * u)
dragon_affinity_value(region *r, unit *u)
{ {
int m = all_money(r, u->faction); int m = all_money(r, u->faction);
@ -391,17 +418,20 @@ dragon_affinity_value(region *r, unit *u)
} }
} }
static attrib * static attrib *set_new_dragon_target(unit * u, region * r, int range)
set_new_dragon_target(unit * u, region * r, int range)
{ {
int max_affinity = 0; int max_affinity = 0;
region *max_region = NULL; region *max_region = NULL;
#if 1 #if 1
region_list *rptr, *rlist = regions_in_range(r, range, allowed_dragon); region_list *rptr, *rlist = regions_in_range(r, range, allowed_dragon);
for (rptr = rlist; rptr; rptr = rptr->next) { for (rptr = rlist; rptr; rptr = rptr->next) {
region *r2 = rptr->data; region *r2 = rptr->data;
int affinity = dragon_affinity_value(r2, u); int affinity = dragon_affinity_value(r2, u);
if (affinity > max_affinity) { if (affinity > max_affinity) {
max_affinity = affinity; max_affinity = affinity;
max_region = r2; max_region = r2;
@ -411,17 +441,21 @@ set_new_dragon_target(unit * u, region * r, int range)
free_regionlist(rlist); free_regionlist(rlist);
#else #else
int tx, ty; int tx, ty;
for (tx = r->x - range; tx < r->x + range; tx++) { for (tx = r->x - range; tx < r->x + range; tx++) {
for (ty = r->y - range; ty < r->y + range; ty++) { for (ty = r->y - range; ty < r->y + range; ty++) {
region *r2; region *r2;
int x = tx, y = ty; int x = tx, y = ty;
pnormalize(&x, &y, r->planep); pnormalize(&x, &y, r->planep);
r2 = findregion(x, y); r2 = findregion(x, y);
if (r2 != NULL) { if (r2 != NULL) {
int affinity = dragon_affinity_value(r2, u); int affinity = dragon_affinity_value(r2, u);
if (affinity > max_affinity) { if (affinity > max_affinity) {
if (koor_distance (r->x, r->y, x, y) <= range && path_exists(r, r2, range, allowed_dragon)) if (koor_distance(r->x, r->y, x, y) <= range
{ && path_exists(r, r2, range, allowed_dragon)) {
max_affinity = affinity; max_affinity = affinity;
max_region = r2; max_region = r2;
} }
@ -432,6 +466,7 @@ set_new_dragon_target(unit * u, region * r, int range)
#endif #endif
if (max_region && max_region != r) { if (max_region && max_region != r) {
attrib *a = a_find(u->attribs, &at_targetregion); attrib *a = a_find(u->attribs, &at_targetregion);
if (!a) { if (!a) {
a = a_add(&u->attribs, make_targetregion(max_region)); a = a_add(&u->attribs, make_targetregion(max_region));
} else { } else {
@ -442,34 +477,49 @@ set_new_dragon_target(unit * u, region * r, int range)
return NULL; return NULL;
} }
static order * static order *make_movement_order(unit * u, const region * target, int moves,
make_movement_order(unit * u, const region * target, int moves, boolean (*allowed)(const region *, const region *)) boolean(*allowed) (const region *, const region *))
{ {
region *r = u->region; region *r = u->region;
region **plan; region **plan;
int bytes, position = 0; int bytes, position = 0;
char zOrder[128], *bufp = zOrder; char zOrder[128], *bufp = zOrder;
size_t size = sizeof(zOrder) - 1; size_t size = sizeof(zOrder) - 1;
if (monster_is_waiting(u)) return NULL; if (monster_is_waiting(u))
return NULL;
plan = path_find(r, target, DRAGON_RANGE * 5, allowed); plan = path_find(r, target, DRAGON_RANGE * 5, allowed);
if (plan==NULL) return NULL; if (plan == NULL)
return NULL;
bytes = (int)strlcpy(bufp, (const char *)LOC(u->faction->locale, keywords[K_MOVE]), size); bytes =
if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER(); (int)strlcpy(bufp, (const char *)LOC(u->faction->locale, keywords[K_MOVE]),
size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
while (position != moves && plan[position + 1]) { while (position != moves && plan[position + 1]) {
region *prev = plan[position]; region *prev = plan[position];
region *next = plan[++position]; region *next = plan[++position];
direction_t dir = reldirection(prev, next); direction_t dir = reldirection(prev, next);
assert(dir != NODIRECTION && dir != D_SPECIAL); assert(dir != NODIRECTION && dir != D_SPECIAL);
if (size > 1) { if (size > 1) {
*bufp++ = ' '; *bufp++ = ' ';
--size; --size;
} }
bytes = (int)strlcpy(bufp, (const char *)LOC(u->faction->locale, directions[dir]), size); bytes =
if (wrptr(&bufp, &size, bytes)!=0) WARN_STATIC_BUFFER(); (int)strlcpy(bufp, (const char *)LOC(u->faction->locale, directions[dir]),
size);
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
} }
*bufp = 0; *bufp = 0;
@ -477,13 +527,16 @@ make_movement_order(unit * u, const region * target, int moves, boolean (*allowe
} }
#ifdef TODO_ALP #ifdef TODO_ALP
static order * static order *monster_seeks_target(region * r, unit * u)
monster_seeks_target(region *r, unit *u)
{ {
direction_t d; direction_t d;
unit *target = NULL; unit *target = NULL;
int dist, dist2; int dist, dist2;
direction_t i; direction_t i;
region *nr; region *nr;
/* Das Monster sucht ein bestimmtes Opfer. Welches, steht /* Das Monster sucht ein bestimmtes Opfer. Welches, steht
@ -508,8 +561,7 @@ monster_seeks_target(region *r, unit *u)
if (r == target->region) { /* Wir haben ihn! */ if (r == target->region) { /* Wir haben ihn! */
if (u->race == new_race[RC_ALP]) { if (u->race == new_race[RC_ALP]) {
alp_findet_opfer(u, r); alp_findet_opfer(u, r);
} } else {
else {
assert(!"Seeker-Monster hat keine Aktion fuer Ziel"); assert(!"Seeker-Monster hat keine Aktion fuer Ziel");
} }
return NULL; return NULL;
@ -532,26 +584,29 @@ monster_seeks_target(region *r, unit *u)
} }
assert(d != NODIRECTION); assert(d != NODIRECTION);
return create_order(K_MOVE, u->faction->locale, "%s", LOC(u->faction->locale, directions[d])); return create_order(K_MOVE, u->faction->locale, "%s", LOC(u->faction->locale,
directions[d]));
} }
#endif #endif
static void static void monster_attacks(unit * u)
monster_attacks(unit * u)
{ {
region *r = u->region; region *r = u->region;
unit *u2; unit *u2;
for (u2 = r->units; u2; u2 = u2->next) { for (u2 = r->units; u2; u2 = u2->next) {
if (cansee(u->faction, r, u2, 0) && u2->faction!=u->faction && chance(0.75)) { if (cansee(u->faction, r, u2, 0) && u2->faction != u->faction
&& chance(0.75)) {
order *ord = monster_attack(u, u2); order *ord = monster_attack(u, u2);
if (ord) addlist(&u->orders, ord);
if (ord)
addlist(&u->orders, ord);
} }
} }
} }
static const char * static const char *random_growl(void)
random_growl(void)
{ {
switch (rng_int() % 5) { switch (rng_int() % 5) {
case 0: case 0:
@ -570,22 +625,26 @@ random_growl(void)
extern struct attrib_type at_direction; extern struct attrib_type at_direction;
static order * static order *monster_learn(unit * u)
monster_learn(unit *u)
{ {
int c = 0; int c = 0;
int n; int n;
skill *sv; skill *sv;
const struct locale *lang = u->faction->locale; const struct locale *lang = u->faction->locale;
/* Monster lernt ein zufälliges Talent aus allen, in denen es schon /* Monster lernt ein zufälliges Talent aus allen, in denen es schon
* Lerntage hat. */ * Lerntage hat. */
for (sv = u->skills; sv != u->skills + u->skill_size; ++sv) { for (sv = u->skills; sv != u->skills + u->skill_size; ++sv) {
if (sv->level>0) ++c; if (sv->level > 0)
++c;
} }
if(c == 0) return NULL; if (c == 0)
return NULL;
n = rng_int() % c + 1; n = rng_int() % c + 1;
c = 0; c = 0;
@ -600,28 +659,33 @@ monster_learn(unit *u)
return NULL; return NULL;
} }
static boolean static boolean check_overpopulated(unit * u)
check_overpopulated(unit *u)
{ {
unit *u2; unit *u2;
int c = 0; int c = 0;
for (u2 = u->region->units; u2; u2 = u2->next) { for (u2 = u->region->units; u2; u2 = u2->next) {
if(u2->race == u->race && u != u2) c += u2->number; if (u2->race == u->race && u != u2)
c += u2->number;
} }
if(c > u->race->splitsize * 2) return true; if (c > u->race->splitsize * 2)
return true;
return false; return false;
} }
static void static void recruit_dracoids(unit * dragon, int size)
recruit_dracoids(unit * dragon, int size)
{ {
faction *f = dragon->faction; faction *f = dragon->faction;
region *r = dragon->region; region *r = dragon->region;
const struct item *weapon = NULL; const struct item *weapon = NULL;
order *new_order = NULL; order *new_order = NULL;
unit *un = createunit(r, f, size, new_race[RC_DRACOID]); unit *un = createunit(r, f, size, new_race[RC_DRACOID]);
fset(un, UFL_ISNEW | UFL_MOVED); fset(un, UFL_ISNEW | UFL_MOVED);
@ -633,6 +697,7 @@ recruit_dracoids(unit * dragon, int size)
setstatus(un, ST_FIGHT); setstatus(un, ST_FIGHT);
for (weapon = un->items; weapon; weapon = weapon->next) { for (weapon = un->items; weapon; weapon = weapon->next) {
const weapon_type *wtype = weapon->type->rtype->wtype; const weapon_type *wtype = weapon->type->rtype->wtype;
if (wtype && (wtype->flags & WTF_MISSILE)) { if (wtype && (wtype->flags & WTF_MISSILE)) {
setstatus(un, ST_BEHIND); setstatus(un, ST_BEHIND);
} }
@ -645,13 +710,16 @@ recruit_dracoids(unit * dragon, int size)
} }
} }
static order * static order *plan_dragon(unit * u)
plan_dragon(unit * u)
{ {
attrib *ta = a_find(u->attribs, &at_targetregion); attrib *ta = a_find(u->attribs, &at_targetregion);
region *r = u->region; region *r = u->region;
region *tr = NULL; region *tr = NULL;
boolean move = false; boolean move = false;
order *long_order = NULL; order *long_order = NULL;
reduce_weight(u); reduce_weight(u);
@ -664,6 +732,7 @@ plan_dragon(unit * u)
if (u->race == new_race[RC_WYRM] && !move) { if (u->race == new_race[RC_WYRM] && !move) {
unit *u2; unit *u2;
for (u2 = r->units; u2; u2 = u2->next) { for (u2 = r->units; u2; u2 = u2->next) {
/* wyrme sind einzelgänger */ /* wyrme sind einzelgänger */
if (u2 == u) { if (u2 == u) {
@ -680,13 +749,14 @@ plan_dragon(unit * u)
if (move) { if (move) {
/* dragon gets bored and looks for a different place to go */ /* dragon gets bored and looks for a different place to go */
ta = set_new_dragon_target(u, u->region, DRAGON_RANGE); ta = set_new_dragon_target(u, u->region, DRAGON_RANGE);
} } else
else ta = a_find(u->attribs, &at_targetregion); ta = a_find(u->attribs, &at_targetregion);
if (ta != NULL) { if (ta != NULL) {
tr = (region *) ta->data.v; tr = (region *) ta->data.v;
if (tr == NULL || !path_exists(u->region, tr, DRAGON_RANGE, allowed_dragon)) { if (tr == NULL || !path_exists(u->region, tr, DRAGON_RANGE, allowed_dragon)) {
ta = set_new_dragon_target(u, u->region, DRAGON_RANGE); ta = set_new_dragon_target(u, u->region, DRAGON_RANGE);
if (ta) tr = findregion(ta->data.sa[0], ta->data.sa[1]); if (ta)
tr = findregion(ta->data.sa[0], ta->data.sa[1]);
} }
} }
if (tr != NULL) { if (tr != NULL) {
@ -704,6 +774,7 @@ plan_dragon(unit * u)
} }
if (rng_int() % 100 < 15) { if (rng_int() % 100 < 15) {
const struct locale *lang = u->faction->locale; const struct locale *lang = u->faction->locale;
/* do a growl */ /* do a growl */
if (rname(tr, lang)) { if (rname(tr, lang)) {
addlist(&u->orders, create_order(K_MAIL, lang, "%s '%s... %s %s %s'", addlist(&u->orders, create_order(K_MAIL, lang, "%s '%s... %s %s %s'",
@ -718,11 +789,11 @@ plan_dragon(unit * u)
if (long_order == NULL) { if (long_order == NULL) {
/* money is gone, need a new target */ /* money is gone, need a new target */
set_new_dragon_target(u, u->region, DRAGON_RANGE); set_new_dragon_target(u, u->region, DRAGON_RANGE);
} } else if (u->race != new_race[RC_FIREDRAGON]) {
else if (u->race != new_race[RC_FIREDRAGON]) {
/* neue dracoiden! */ /* neue dracoiden! */
if (r->land && !fval(r->terrain, FORBIDDEN_REGION)) { if (r->land && !fval(r->terrain, FORBIDDEN_REGION)) {
int ra = 20 + rng_int() % 100; int ra = 20 + rng_int() % 100;
if (get_money(u) > ra * 50 + 100 && rng_int() % 100 < 50) { if (get_money(u) > ra * 50 + 100 && rng_int() % 100 < 50) {
recruit_dracoids(u, ra); recruit_dracoids(u, ra);
} }
@ -731,6 +802,7 @@ plan_dragon(unit * u)
} }
if (long_order == NULL) { if (long_order == NULL) {
skill_t sk = SK_PERCEPTION; skill_t sk = SK_PERCEPTION;
/* study perception (or a random useful skill) */ /* study perception (or a random useful skill) */
while (!skill_enabled[sk] || u->race->bonus[sk] < -5) { while (!skill_enabled[sk] || u->race->bonus[sk] < -5) {
sk = (skill_t) (rng_int() % MAXSKILLS); sk = (skill_t) (rng_int() % MAXSKILLS);
@ -741,8 +813,7 @@ plan_dragon(unit * u)
return long_order; return long_order;
} }
void void plan_monsters(faction * f)
plan_monsters(faction * f)
{ {
region *r; region *r;
@ -751,18 +822,23 @@ plan_monsters(faction * f)
for (r = regions; r; r = r->next) { for (r = regions; r; r = r->next) {
unit *u; unit *u;
double attack_chance = MONSTERATTACK; double attack_chance = MONSTERATTACK;
boolean attacking = false; boolean attacking = false;
for (u = r->units; u; u = u->next) { for (u = r->units; u; u = u->next) {
attrib *ta; attrib *ta;
order *long_order = NULL; order *long_order = NULL;
/* Ab hier nur noch Befehle für NPC-Einheiten. */ /* Ab hier nur noch Befehle für NPC-Einheiten. */
if (!is_monsters(u->faction)) continue; if (!is_monsters(u->faction))
continue;
if (attack_chance > 0.0) { if (attack_chance > 0.0) {
if (chance(attack_chance)) attacking = true; if (chance(attack_chance))
attacking = true;
attack_chance = 0.0; attack_chance = 0.0;
} }
@ -786,15 +862,17 @@ plan_monsters(faction * f)
ta = a_find(u->attribs, &at_hate); ta = a_find(u->attribs, &at_hate);
if (ta && !monster_is_waiting(u)) { if (ta && !monster_is_waiting(u)) {
unit *tu = (unit *) ta->data.v; unit *tu = (unit *) ta->data.v;
if (tu && tu->region == r) { if (tu && tu->region == r) {
addlist(&u->orders, create_order(K_ATTACK, u->faction->locale, "%i", tu->no)); addlist(&u->orders, create_order(K_ATTACK, u->faction->locale, "%i",
tu->no));
} else if (tu) { } else if (tu) {
tu = findunitg(ta->data.i, NULL); tu = findunitg(ta->data.i, NULL);
if (tu != NULL) { if (tu != NULL) {
long_order = make_movement_order(u, tu->region, 2, allowed_walk); long_order = make_movement_order(u, tu->region, 2, allowed_walk);
} }
} } else
else a_remove(&u->attribs, ta); a_remove(&u->attribs, ta);
} }
/* All monsters guard the region: */ /* All monsters guard the region: */
@ -805,6 +883,7 @@ plan_monsters(faction * f)
/* Einheiten mit Bewegungsplan kriegen ein NACH: */ /* Einheiten mit Bewegungsplan kriegen ein NACH: */
if (long_order == NULL) { if (long_order == NULL) {
attrib *ta = a_find(u->attribs, &at_targetregion); attrib *ta = a_find(u->attribs, &at_targetregion);
if (ta) { if (ta) {
if (u->region == (region *) ta->data.v) { if (u->region == (region *) ta->data.v) {
a_remove(&u->attribs, ta); a_remove(&u->attribs, ta);
@ -821,7 +900,9 @@ plan_monsters(faction * f)
* zu bewachen: */ * zu bewachen: */
if (u->race->bonus[SK_WEAPONLESS] != -99) { if (u->race->bonus[SK_WEAPONLESS] != -99) {
if (eff_skill(u, SK_WEAPONLESS, u->region) < 1) { if (eff_skill(u, SK_WEAPONLESS, u->region) < 1) {
long_order = create_order(K_STUDY, f->locale, "'%s'", skillname(SK_WEAPONLESS, f->locale)); long_order =
create_order(K_STUDY, f->locale, "'%s'", skillname(SK_WEAPONLESS,
f->locale));
} }
} }
} }
@ -862,16 +943,16 @@ plan_monsters(faction * f)
pathfinder_cleanup(); pathfinder_cleanup();
} }
static double static double chaosfactor(region * r)
chaosfactor(region * r)
{ {
attrib *a = a_find(r->attribs, &at_chaoscount); attrib *a = a_find(r->attribs, &at_chaoscount);
if (!a) return 0;
if (!a)
return 0;
return ((double)a->data.i / 1000.0); return ((double)a->data.i / 1000.0);
} }
static int static int nrand(int start, int sub)
nrand(int start, int sub)
{ {
int res = 0; int res = 0;
@ -885,10 +966,10 @@ nrand(int start, int sub)
} }
/** Drachen und Seeschlangen können entstehen */ /** Drachen und Seeschlangen können entstehen */
void void spawn_dragons(void)
spawn_dragons(void)
{ {
region *r; region *r;
faction *monsters = get_monsters(); faction *monsters = get_monsters();
for (r = regions; r; r = r->next) { for (r = regions; r; r = r->next) {
@ -900,8 +981,10 @@ spawn_dragons(void)
equip_unit(u, get_equipment("monster_seaserpent")); equip_unit(u, get_equipment("monster_seaserpent"));
} }
if ((r->terrain == newterrain(T_GLACIER) || r->terrain == newterrain(T_SWAMP) || r->terrain == newterrain(T_DESERT)) && rng_int() % 10000 < (5 + 100 * chaosfactor(r))) if ((r->terrain == newterrain(T_GLACIER)
{ || r->terrain == newterrain(T_SWAMP)
|| r->terrain == newterrain(T_DESERT))
&& rng_int() % 10000 < (5 + 100 * chaosfactor(r))) {
if (chance(0.80)) { if (chance(0.80)) {
u = createunit(r, monsters, nrand(60, 20) + 1, new_race[RC_FIREDRAGON]); u = createunit(r, monsters, nrand(60, 20) + 1, new_race[RC_FIREDRAGON]);
} else { } else {
@ -912,7 +995,8 @@ spawn_dragons(void)
if (verbosity >= 2) { if (verbosity >= 2) {
log_printf("%d %s in %s.\n", u->number, log_printf("%d %s in %s.\n", u->number,
LOC(default_locale, rc_name(u->race, u->number!=1)), regionname(r, NULL)); LOC(default_locale, rc_name(u->race, u->number != 1)), regionname(r,
NULL));
} }
name_unit(u); name_unit(u);
@ -925,44 +1009,58 @@ spawn_dragons(void)
} }
/** Untote können entstehen */ /** Untote können entstehen */
void void spawn_undead(void)
spawn_undead(void)
{ {
region *r; region *r;
faction *monsters = get_monsters(); faction *monsters = get_monsters();
for (r = regions; r; r = r->next) { for (r = regions; r; r = r->next) {
int unburied = deathcount(r); int unburied = deathcount(r);
static const curse_type *ctype = NULL; static const curse_type *ctype = NULL;
if (!ctype) ctype = ct_find("holyground"); if (!ctype)
if (ctype && curse_active(get_curse(r->attribs, ctype))) continue; ctype = ct_find("holyground");
if (ctype && curse_active(get_curse(r->attribs, ctype)))
continue;
/* Chance 0.1% * chaosfactor */ /* Chance 0.1% * chaosfactor */
if (r->land && unburied > r->land->peasants / 20 && rng_int() % 10000 < (100 + 100 * chaosfactor(r))) { if (r->land && unburied > r->land->peasants / 20
&& rng_int() % 10000 < (100 + 100 * chaosfactor(r))) {
unit *u; unit *u;
/* es ist sinnfrei, wenn irgendwo im Wald 3er-Einheiten Untote entstehen. /* es ist sinnfrei, wenn irgendwo im Wald 3er-Einheiten Untote entstehen.
* Lieber sammeln lassen, bis sie mindestens 5% der Bevölkerung sind, und * Lieber sammeln lassen, bis sie mindestens 5% der Bevölkerung sind, und
* dann erst auferstehen. */ * dann erst auferstehen. */
int undead = unburied / (rng_int() % 2 + 1); int undead = unburied / (rng_int() % 2 + 1);
const race * rc = NULL;
int i;
if (r->age<100) undead = undead * r->age / 100; /* newbie-regionen kriegen weniger ab */
if (!undead || r->age < 20) continue; const race *rc = NULL;
int i;
if (r->age < 100)
undead = undead * r->age / 100; /* newbie-regionen kriegen weniger ab */
if (!undead || r->age < 20)
continue;
switch (rng_int() % 3) { switch (rng_int() % 3) {
case 0: case 0:
rc = new_race[RC_SKELETON]; break; rc = new_race[RC_SKELETON];
break;
case 1: case 1:
rc = new_race[RC_ZOMBIE]; break; rc = new_race[RC_ZOMBIE];
break;
default: default:
rc = new_race[RC_GHOUL]; break; rc = new_race[RC_GHOUL];
break;
} }
u = createunit(r, monsters, undead, rc); u = createunit(r, monsters, undead, rc);
fset(u, UFL_ISNEW | UFL_MOVED); fset(u, UFL_ISNEW | UFL_MOVED);
if ((rc == new_race[RC_SKELETON] || rc == new_race[RC_ZOMBIE]) && rng_int()%10 < 4) { if ((rc == new_race[RC_SKELETON] || rc == new_race[RC_ZOMBIE])
&& rng_int() % 10 < 4) {
equip_unit(u, get_equipment("rising_undead")); equip_unit(u, get_equipment("rising_undead"));
} }
@ -978,15 +1076,19 @@ spawn_undead(void)
if (verbosity >= 2) { if (verbosity >= 2) {
log_printf("%d %s in %s.\n", u->number, log_printf("%d %s in %s.\n", u->number,
LOC(default_locale, rc_name(u->race, u->number!=1)), regionname(r, NULL)); LOC(default_locale, rc_name(u->race, u->number != 1)), regionname(r,
NULL));
} }
{ {
message *msg = msg_message("undeadrise", "region", r); message *msg = msg_message("undeadrise", "region", r);
add_message(&r->msgs, msg); add_message(&r->msgs, msg);
for (u=r->units;u;u=u->next) freset(u->faction, FFL_SELECT); for (u = r->units; u; u = u->next)
freset(u->faction, FFL_SELECT);
for (u = r->units; u; u = u->next) { for (u = r->units; u; u = u->next) {
if (fval(u->faction, FFL_SELECT)) continue; if (fval(u->faction, FFL_SELECT))
continue;
fset(u->faction, FFL_SELECT); fset(u->faction, FFL_SELECT);
add_message(&u->faction->msgs, msg); add_message(&u->faction->msgs, msg);
} }
@ -994,6 +1096,7 @@ spawn_undead(void)
} }
} else { } else {
int i = deathcount(r); int i = deathcount(r);
if (i) { if (i) {
/* Gräber verwittern, 3% der Untoten finden die ewige Ruhe */ /* Gräber verwittern, 3% der Untoten finden die ewige Ruhe */
deathcounts(r, (int)(-i * 0.03)); deathcounts(r, (int)(-i * 0.03));

View file

@ -27,11 +27,11 @@
#define DRAGONAGE 27 #define DRAGONAGE 27
#define WYRMAGE 68 #define WYRMAGE 68
void void age_firedragon(unit * u)
age_firedragon(unit *u)
{ {
if (u->number > 0 && rng_int() % 100 < age_chance(u->age, DRAGONAGE, 1)) { if (u->number > 0 && rng_int() % 100 < age_chance(u->age, DRAGONAGE, 1)) {
double q = (double)u->hp / (double)(unit_max_hp(u) * u->number); double q = (double)u->hp / (double)(unit_max_hp(u) * u->number);
u->race = new_race[RC_DRAGON]; u->race = new_race[RC_DRAGON];
u->irace = NULL; u->irace = NULL;
scale_number(u, 1); scale_number(u, 1);
@ -39,14 +39,13 @@ age_firedragon(unit *u)
} }
} }
void void age_dragon(unit * u)
age_dragon(unit *u)
{ {
if (u->number > 0 && rng_int() % 100 < age_chance(u->age, WYRMAGE, 1)) { if (u->number > 0 && rng_int() % 100 < age_chance(u->age, WYRMAGE, 1)) {
double q = (double)u->hp / (double)(unit_max_hp(u) * u->number); double q = (double)u->hp / (double)(unit_max_hp(u) * u->number);
u->race = new_race[RC_WYRM]; u->race = new_race[RC_WYRM];
u->irace = NULL; u->irace = NULL;
u->hp = (int)(unit_max_hp(u) * u->number * q); u->hp = (int)(unit_max_hp(u) * u->number * q);
} }
} }

View file

@ -26,13 +26,11 @@
#define ILLUSIONMAX 6 #define ILLUSIONMAX 6
void void age_illusion(unit * u)
age_illusion(unit *u)
{ {
if (u->faction->race != new_race[RC_ILLUSION]) { if (u->faction->race != new_race[RC_ILLUSION]) {
if (u->age == ILLUSIONMAX) { if (u->age == ILLUSIONMAX) {
ADDMSG(&u->faction->msgs, msg_message("warnillusiondissolve", ADDMSG(&u->faction->msgs, msg_message("warnillusiondissolve", "unit", u));
"unit", u));
} else if (u->age > ILLUSIONMAX) { } else if (u->age > ILLUSIONMAX) {
set_number(u, 0); set_number(u, 0);
ADDMSG(&u->faction->msgs, msg_message("illusiondissolve", "unit", u)); ADDMSG(&u->faction->msgs, msg_message("illusiondissolve", "unit", u));

View file

@ -28,17 +28,23 @@
#include <util/rng.h> #include <util/rng.h>
void age_firedragon(struct unit *u); void age_firedragon(struct unit *u);
void age_dragon(struct unit *u); void age_dragon(struct unit *u);
void age_illusion(struct unit *u); void age_illusion(struct unit *u);
void age_undead(struct unit *u); void age_undead(struct unit *u);
void age_skeleton(struct unit *u); void age_skeleton(struct unit *u);
void age_zombie(struct unit *u); void age_zombie(struct unit *u);
void age_ghoul(struct unit *u); void age_ghoul(struct unit *u);
static void static void oldfamiliars(unit * u)
oldfamiliars(unit * u)
{ {
char fname[64]; char fname[64];
/* these familiars have no special skills. /* these familiars have no special skills.
*/ */
snprintf(fname, sizeof(fname), "%s_familiar", u->race->_name[0]); snprintf(fname, sizeof(fname), "%s_familiar", u->race->_name[0]);
@ -46,15 +52,14 @@ oldfamiliars(unit * u)
equip_unit(u, get_equipment(fname)); equip_unit(u, get_equipment(fname));
} }
static void static void set_show_item(faction * f, item_t i)
set_show_item(faction *f, item_t i)
{ {
attrib *a = a_add(&f->attribs, a_new(&at_showitem)); attrib *a = a_add(&f->attribs, a_new(&at_showitem));
a->data.v = (void *)olditemtype[i]; a->data.v = (void *)olditemtype[i];
} }
static void static void equip_newunits(const struct equipment *eq, struct unit *u)
equip_newunits(const struct equipment * eq, struct unit *u)
{ {
struct region *r = u->region; struct region *r = u->region;
@ -69,8 +74,10 @@ equip_newunits(const struct equipment * eq, struct unit *u)
case RC_HUMAN: case RC_HUMAN:
if (u->building == NULL) { if (u->building == NULL) {
const building_type *btype = bt_find("castle"); const building_type *btype = bt_find("castle");
if (btype != NULL) { if (btype != NULL) {
building *b = new_building(btype, r, u->faction->locale); building *b = new_building(btype, r, u->faction->locale);
b->size = 10; b->size = 10;
u->building = b; u->building = b;
fset(u, UFL_OWNER); fset(u, UFL_OWNER);
@ -83,6 +90,7 @@ equip_newunits(const struct equipment * eq, struct unit *u)
case RC_AQUARIAN: case RC_AQUARIAN:
{ {
ship *sh = new_ship(st_find("boat"), u->faction->locale, r); ship *sh = new_ship(st_find("boat"), u->faction->locale, r);
sh->size = sh->type->construction->maxsize; sh->size = sh->type->construction->maxsize;
u->ship = sh; u->ship = sh;
fset(u, UFL_OWNER); fset(u, UFL_OWNER);
@ -96,8 +104,7 @@ equip_newunits(const struct equipment * eq, struct unit *u)
/* Die Funktionen werden über den hier registrierten Namen in races.xml /* Die Funktionen werden über den hier registrierten Namen in races.xml
* in die jeweilige Rassendefiniton eingebunden */ * in die jeweilige Rassendefiniton eingebunden */
void void register_races(void)
register_races(void)
{ {
/* function initfamiliar */ /* function initfamiliar */
register_function((pf_generic) oldfamiliars, "oldfamiliars"); register_function((pf_generic) oldfamiliars, "oldfamiliars");

View file

@ -20,6 +20,4 @@ extern "C" {
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif #endif

View file

@ -32,23 +32,26 @@
#define age_chance(a,b,p) (MAX(0,a-b)*p) #define age_chance(a,b,p) (MAX(0,a-b)*p)
void void age_undead(unit * u)
age_undead(unit *u)
{ {
region *r = u->region; region *r = u->region;
int n = 0; int n = 0;
/* untote, die einer partei angehoeren, koennen sich /* untote, die einer partei angehoeren, koennen sich
* absplitten, anstatt sich zu vermehren. monster * absplitten, anstatt sich zu vermehren. monster
* untote vermehren sich nur noch */ * untote vermehren sich nur noch */
if (u->number > UNDEAD_MIN && !is_monsters(u->faction) && rng_int() % 100 < UNDEAD_BREAKUP) { if (u->number > UNDEAD_MIN && !is_monsters(u->faction)
&& rng_int() % 100 < UNDEAD_BREAKUP) {
int m; int m;
unit *u2; unit *u2;
n = 0; n = 0;
for (m = u->number; m; m--) { for (m = u->number; m; m--) {
if (rng_int() % 100 < UNDEAD_BREAKUP_FRACTION) ++n; if (rng_int() % 100 < UNDEAD_BREAKUP_FRACTION)
++n;
} }
u2 = create_unit(r, get_monsters(), 0, new_race[RC_UNDEAD], 0, NULL, u); u2 = create_unit(r, get_monsters(), 0, new_race[RC_UNDEAD], 0, NULL, u);
make_undead_unit(u2); make_undead_unit(u2);
@ -56,12 +59,13 @@ age_undead(unit *u)
} }
} }
void void age_skeleton(unit * u)
age_skeleton(unit *u)
{ {
if (is_monsters(u->faction) && rng_int() % 100 < age_chance(u->age, 27, 1)) { if (is_monsters(u->faction) && rng_int() % 100 < age_chance(u->age, 27, 1)) {
int n = MAX(1, u->number / 2); int n = MAX(1, u->number / 2);
double q = (double)u->hp / (double)(unit_max_hp(u) * u->number); double q = (double)u->hp / (double)(unit_max_hp(u) * u->number);
u->race = new_race[RC_SKELETON_LORD]; u->race = new_race[RC_SKELETON_LORD];
u->irace = NULL; u->irace = NULL;
scale_number(u, n); scale_number(u, n);
@ -69,12 +73,13 @@ age_skeleton(unit *u)
} }
} }
void void age_zombie(unit * u)
age_zombie(unit *u)
{ {
if (is_monsters(u->faction) && rng_int() % 100 < age_chance(u->age, 27, 1)) { if (is_monsters(u->faction) && rng_int() % 100 < age_chance(u->age, 27, 1)) {
int n = MAX(1, u->number / 2); int n = MAX(1, u->number / 2);
double q = (double)u->hp / (double)(unit_max_hp(u) * u->number); double q = (double)u->hp / (double)(unit_max_hp(u) * u->number);
u->race = new_race[RC_ZOMBIE_LORD]; u->race = new_race[RC_ZOMBIE_LORD];
u->irace = NULL; u->irace = NULL;
scale_number(u, n); scale_number(u, n);
@ -82,16 +87,16 @@ age_zombie(unit *u)
} }
} }
void void age_ghoul(unit * u)
age_ghoul(unit *u)
{ {
if (is_monsters(u->faction) && rng_int() % 100 < age_chance(u->age, 27, 1)) { if (is_monsters(u->faction) && rng_int() % 100 < age_chance(u->age, 27, 1)) {
int n = MAX(1, u->number / 2); int n = MAX(1, u->number / 2);
double q = (double)u->hp / (double)(unit_max_hp(u) * u->number); double q = (double)u->hp / (double)(unit_max_hp(u) * u->number);
u->race = new_race[RC_GHOUL_LORD]; u->race = new_race[RC_GHOUL_LORD];
u->irace = NULL; u->irace = NULL;
scale_number(u, n); scale_number(u, n);
u->hp = (int)(unit_max_hp(u) * u->number * q); u->hp = (int)(unit_max_hp(u) * u->number * q);
} }
} }

View file

@ -48,23 +48,22 @@ typedef struct alp_data {
unit *target; unit *target;
} alp_data; } alp_data;
static void static void alp_init(attrib * a)
alp_init(attrib * a)
{ {
a->data.v = calloc(sizeof(alp_data), 1); a->data.v = calloc(sizeof(alp_data), 1);
} }
static void static void alp_done(attrib * a)
alp_done(attrib * a)
{ {
free(a->data.v); free(a->data.v);
} }
static int static int alp_verify(attrib * a)
alp_verify(attrib * a)
{ {
alp_data *ad = (alp_data *) a->data.v; alp_data *ad = (alp_data *) a->data.v;
if (ad->mage && ad->target) return 1;
if (ad->mage && ad->target)
return 1;
return 0; /* remove the attribute */ return 0; /* remove the attribute */
} }
@ -72,16 +71,19 @@ static void
alp_write(const attrib * a, const void *owner, struct storage *store) alp_write(const attrib * a, const void *owner, struct storage *store)
{ {
alp_data *ad = (alp_data *) a->data.v; alp_data *ad = (alp_data *) a->data.v;
write_unit_reference(ad->mage, store); write_unit_reference(ad->mage, store);
write_unit_reference(ad->target, store); write_unit_reference(ad->target, store);
} }
static int static int alp_read(attrib * a, void *owner, struct storage *store)
alp_read(attrib * a, void * owner, struct storage * store)
{ {
alp_data *ad = (alp_data *) a->data.v; alp_data *ad = (alp_data *) a->data.v;
int rm = read_reference(&ad->mage, store, read_unit_reference, resolve_unit); int rm = read_reference(&ad->mage, store, read_unit_reference, resolve_unit);
int rt = read_reference(&ad->target, store, read_unit_reference, resolve_unit);
int rt =
read_reference(&ad->target, store, read_unit_reference, resolve_unit);
if (rt == 0 && rm == 0 && (!ad->target || !ad->mage)) { if (rt == 0 && rm == 0 && (!ad->target || !ad->mage)) {
/* the target or mage disappeared. */ /* the target or mage disappeared. */
return AT_READ_FAIL; return AT_READ_FAIL;
@ -99,16 +101,22 @@ static attrib_type at_alp = {
ATF_UNIQUE ATF_UNIQUE
}; };
int int sp_summon_alp(struct castorder *co)
sp_summon_alp(struct castorder *co)
{ {
unit *alp, *opfer; unit *alp, *opfer;
region *r = co->rt; region *r = co->rt;
unit *mage = co->magician.u; unit *mage = co->magician.u;
int cast_level = co->level; int cast_level = co->level;
spellparameter *pa = co->par; spellparameter *pa = co->par;
const struct race *rc = new_race[RC_ALP]; const struct race *rc = new_race[RC_ALP];
struct faction *f = get_monsters(); struct faction *f = get_monsters();
struct message *msg; struct message *msg;
opfer = pa->param[0]->data.u; opfer = pa->param[0]->data.u;
@ -123,7 +131,9 @@ sp_summon_alp(struct castorder *co)
{ {
attrib *a = a_add(&alp->attribs, a_new(&at_alp)); attrib *a = a_add(&alp->attribs, a_new(&at_alp));
alp_data *ad = (alp_data *) a->data.v; alp_data *ad = (alp_data *) a->data.v;
ad->mage = mage; ad->mage = mage;
ad->target = opfer; ad->target = opfer;
} }
@ -144,15 +154,20 @@ sp_summon_alp(struct castorder *co)
} }
void void alp_findet_opfer(unit * alp, region * r)
alp_findet_opfer(unit *alp, region *r)
{ {
curse *c; curse *c;
attrib *a = a_find(alp->attribs, &at_alp); attrib *a = a_find(alp->attribs, &at_alp);
alp_data *ad = (alp_data *) a->data.v; alp_data *ad = (alp_data *) a->data.v;
unit *mage = ad->mage; unit *mage = ad->mage;
unit *opfer = ad->target; unit *opfer = ad->target;
double effect; double effect;
message *msg; message *msg;
assert(opfer); assert(opfer);
@ -173,7 +188,9 @@ alp_findet_opfer(unit *alp, region *r)
/* Alp umwandeln in Curse */ /* Alp umwandeln in Curse */
effect = -2; effect = -2;
c = create_curse(mage, &opfer->attribs, ct_find("worse"), 2, 2, effect, opfer->number); c =
create_curse(mage, &opfer->attribs, ct_find("worse"), 2, 2, effect,
opfer->number);
/* solange es noch keine spezielle alp-Antimagie gibt, reagiert der /* solange es noch keine spezielle alp-Antimagie gibt, reagiert der
* auch auf normale */ * auch auf normale */
set_number(alp, 0); set_number(alp, 0);
@ -182,16 +199,15 @@ alp_findet_opfer(unit *alp, region *r)
add_trigger(&mage->attribs, "destroy", trigger_removecurse(c, opfer)); add_trigger(&mage->attribs, "destroy", trigger_removecurse(c, opfer));
} }
void void register_alp(void)
register_alp(void)
{ {
at_register(&at_alp); at_register(&at_alp);
} }
unit * unit *alp_target(unit * alp)
alp_target(unit *alp)
{ {
alp_data *ad; alp_data *ad;
unit *target = NULL; unit *target = NULL;
attrib *a = a_find(alp->attribs, &at_alp); attrib *a = a_find(alp->attribs, &at_alp);

View file

@ -34,8 +34,8 @@
#include <assert.h> #include <assert.h>
static message * static message *cinfo_building(const void *obj, typ_t typ, const curse * c,
cinfo_building(const void * obj, typ_t typ, const curse *c, int self) int self)
{ {
unused(typ); unused(typ);
assert(typ == TYP_BUILDING); assert(typ == TYP_BUILDING);
@ -49,18 +49,22 @@ cinfo_building(const void * obj, typ_t typ, const curse *c, int self)
/* CurseInfo mit Spezialabfragen */ /* CurseInfo mit Spezialabfragen */
/* C_MAGICWALLS*/ /* C_MAGICWALLS*/
static message * static message *cinfo_magicrunes(const void *obj, typ_t typ, const curse * c,
cinfo_magicrunes(const void * obj, typ_t typ, const curse *c, int self) int self)
{ {
message *msg = NULL; message *msg = NULL;
if (typ == TYP_BUILDING) { if (typ == TYP_BUILDING) {
building *b; building *b;
b = (building *) obj; b = (building *) obj;
if (self != 0) { if (self != 0) {
msg = msg_message("curseinfo::magicrunes_building", "building id", b, c->no); msg =
msg_message("curseinfo::magicrunes_building", "building id", b, c->no);
} }
} else if (typ == TYP_SHIP) { } else if (typ == TYP_SHIP) {
ship *sh; ship *sh;
sh = (ship *) obj; sh = (ship *) obj;
if (self != 0) { if (self != 0) {
msg = msg_message("curseinfo::magicrunes_ship", "ship id", sh, c->no); msg = msg_message("curseinfo::magicrunes_ship", "ship id", sh, c->no);
@ -69,6 +73,7 @@ cinfo_magicrunes(const void * obj, typ_t typ, const curse *c, int self)
return msg; return msg;
} }
static struct curse_type ct_magicrunes = { "magicrunes", static struct curse_type ct_magicrunes = { "magicrunes",
CURSETYP_NORM, 0, M_SUMEFFECT, cinfo_magicrunes CURSETYP_NORM, 0, M_SUMEFFECT, cinfo_magicrunes
}; };
@ -89,8 +94,7 @@ static struct curse_type ct_nocostbuilding = { "nocostbuilding",
}; };
void void register_buildingcurse(void)
register_buildingcurse(void)
{ {
ct_register(&ct_magicwalls); ct_register(&ct_magicwalls);
ct_register(&ct_strongwall); ct_register(&ct_strongwall);

File diff suppressed because it is too large Load diff

View file

@ -20,36 +20,66 @@ extern "C" {
struct fighter; struct fighter;
/* Kampfzauber */ /* Kampfzauber */
extern int sp_fumbleshield(struct fighter * fi, int level, double power, struct spell * sp); extern int sp_fumbleshield(struct fighter *fi, int level, double power,
extern int sp_shadowknights(struct fighter * fi, int level, double power, struct spell * sp); struct spell *sp);
extern int sp_combatrosthauch(struct fighter * fi, int level, double power, struct spell * sp); extern int sp_shadowknights(struct fighter *fi, int level, double power,
extern int sp_kampfzauber(struct fighter * fi, int level, double power, struct spell * sp); struct spell *sp);
extern int sp_healing(struct fighter * fi, int level, double power, struct spell * sp); extern int sp_combatrosthauch(struct fighter *fi, int level, double power,
extern int sp_keeploot(struct fighter * fi, int level, double power, struct spell * sp); struct spell *sp);
extern int sp_reanimate(struct fighter * fi, int level, double power, struct spell * sp); extern int sp_kampfzauber(struct fighter *fi, int level, double power,
extern int sp_chaosrow(struct fighter * fi, int level, double power, struct spell * sp); struct spell *sp);
extern int sp_flee(struct fighter * fi, int level, double power, struct spell * sp); extern int sp_healing(struct fighter *fi, int level, double power,
extern int sp_berserk(struct fighter * fi, int level, double power, struct spell * sp); struct spell *sp);
extern int sp_tiredsoldiers(struct fighter * fi, int level, double power, struct spell * sp); extern int sp_keeploot(struct fighter *fi, int level, double power,
extern int sp_reeling_arrows(struct fighter * fi, int level, double power, struct spell * sp); struct spell *sp);
extern int sp_denyattack(struct fighter * fi, int level, double power, struct spell * sp); extern int sp_reanimate(struct fighter *fi, int level, double power,
extern int sp_sleep(struct fighter * fi, int level, double power, struct spell * sp); struct spell *sp);
extern int sp_windshield(struct fighter * fi, int level, double power, struct spell * sp); extern int sp_chaosrow(struct fighter *fi, int level, double power,
extern int sp_strong_wall(struct fighter * fi, int level, double power, struct spell * sp); struct spell *sp);
extern int sp_petrify(struct fighter * fi, int level, double power, struct spell * sp); extern int sp_flee(struct fighter *fi, int level, double power,
extern int sp_hero(struct fighter * fi, int level, double power, struct spell * sp); struct spell *sp);
extern int sp_frighten(struct fighter * fi, int level, double power, struct spell * sp); extern int sp_berserk(struct fighter *fi, int level, double power,
extern int sp_mindblast(struct fighter * fi, int level, double power, struct spell * sp); struct spell *sp);
extern int sp_mindblast_temp(struct fighter * fi, int level, double power, struct spell * sp); extern int sp_tiredsoldiers(struct fighter *fi, int level, double power,
extern int sp_speed(struct fighter * fi, int level, double power, struct spell * sp); struct spell *sp);
extern int sp_wolfhowl(struct fighter * fi, int level, double power, struct spell * sp); extern int sp_reeling_arrows(struct fighter *fi, int level, double power,
extern int sp_dragonodem(struct fighter * fi, int level, double power, struct spell * sp); struct spell *sp);
extern int sp_reduceshield(struct fighter * fi, int level, double power, struct spell * sp); extern int sp_denyattack(struct fighter *fi, int level, double power,
extern int sp_armorshield(struct fighter * fi, int level, double power, struct spell * sp); struct spell *sp);
extern int sp_stun(struct fighter * fi, int level, double power, struct spell * sp); extern int sp_sleep(struct fighter *fi, int level, double power,
extern int sp_undeadhero(struct fighter * fi, int level, double power, struct spell * sp); struct spell *sp);
extern int sp_shadowcall(struct fighter * fi, int level, double power, struct spell * sp); extern int sp_windshield(struct fighter *fi, int level, double power,
extern int sp_immolation(struct fighter * fi, int level, double power, struct spell * sp); struct spell *sp);
extern int sp_strong_wall(struct fighter *fi, int level, double power,
struct spell *sp);
extern int sp_petrify(struct fighter *fi, int level, double power,
struct spell *sp);
extern int sp_hero(struct fighter *fi, int level, double power,
struct spell *sp);
extern int sp_frighten(struct fighter *fi, int level, double power,
struct spell *sp);
extern int sp_mindblast(struct fighter *fi, int level, double power,
struct spell *sp);
extern int sp_mindblast_temp(struct fighter *fi, int level, double power,
struct spell *sp);
extern int sp_speed(struct fighter *fi, int level, double power,
struct spell *sp);
extern int sp_wolfhowl(struct fighter *fi, int level, double power,
struct spell *sp);
extern int sp_dragonodem(struct fighter *fi, int level, double power,
struct spell *sp);
extern int sp_reduceshield(struct fighter *fi, int level, double power,
struct spell *sp);
extern int sp_armorshield(struct fighter *fi, int level, double power,
struct spell *sp);
extern int sp_stun(struct fighter *fi, int level, double power,
struct spell *sp);
extern int sp_undeadhero(struct fighter *fi, int level, double power,
struct spell *sp);
extern int sp_shadowcall(struct fighter *fi, int level, double power,
struct spell *sp);
extern int sp_immolation(struct fighter *fi, int level, double power,
struct spell *sp);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -41,8 +41,8 @@
/* /*
* godcursezone * godcursezone
*/ */
static message * static message *cinfo_cursed_by_the_gods(const void *obj, typ_t typ,
cinfo_cursed_by_the_gods(const void * obj, typ_t typ, const curse *c, int self) const curse * c, int self)
{ {
region *r = (region *) obj; region *r = (region *) obj;
@ -58,7 +58,8 @@ cinfo_cursed_by_the_gods(const void * obj, typ_t typ, const curse *c, int self)
static struct curse_type ct_godcursezone = { static struct curse_type ct_godcursezone = {
"godcursezone", "godcursezone",
CURSETYP_NORM, CURSE_IMMUNE|CURSE_ISNEW, (NO_MERGE), cinfo_cursed_by_the_gods, CURSETYP_NORM, CURSE_IMMUNE | CURSE_ISNEW, (NO_MERGE),
cinfo_cursed_by_the_gods,
}; };
@ -66,8 +67,8 @@ static struct curse_type ct_godcursezone = {
/* /*
* C_GBDREAM * C_GBDREAM
*/ */
static message * static message *cinfo_dreamcurse(const void *obj, typ_t typ, const curse * c,
cinfo_dreamcurse(const void * obj, typ_t typ, const curse *c, int self) int self)
{ {
unused(self); unused(self);
unused(typ); unused(typ);
@ -90,8 +91,8 @@ static struct curse_type ct_gbdream = {
* C_MAGICSTREET * C_MAGICSTREET
* erzeugt Straßennetz * erzeugt Straßennetz
*/ */
static message * static message *cinfo_magicstreet(const void *obj, typ_t typ, const curse * c,
cinfo_magicstreet(const void * obj, typ_t typ, const curse *c, int self) int self)
{ {
unused(typ); unused(typ);
unused(self); unused(self);
@ -113,8 +114,8 @@ static struct curse_type ct_magicstreet = {
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
static message * static message *cinfo_antimagiczone(const void *obj, typ_t typ, const curse * c,
cinfo_antimagiczone(const void * obj, typ_t typ, const curse *c, int self) int self)
{ {
unused(typ); unused(typ);
unused(self); unused(self);
@ -131,10 +132,13 @@ cinfo_antimagiczone(const void * obj, typ_t typ, const curse *c, int self)
/* alle Magier können eine Antimagiezone wahrnehmen */ /* alle Magier können eine Antimagiezone wahrnehmen */
static int static int
cansee_antimagiczone(const struct faction *viewer, const void * obj, typ_t typ, const curse *c, int self) cansee_antimagiczone(const struct faction *viewer, const void *obj, typ_t typ,
const curse * c, int self)
{ {
region *r; region *r;
unit *u = NULL; unit *u = NULL;
unit *mage = c->magician; unit *mage = c->magician;
unused(typ); unused(typ);
@ -154,6 +158,7 @@ cansee_antimagiczone(const struct faction *viewer, const void * obj, typ_t typ,
} }
return self; return self;
} }
static struct curse_type ct_antimagiczone = { static struct curse_type ct_antimagiczone = {
"antimagiczone", "antimagiczone",
CURSETYP_NORM, 0, (M_DURATION | M_VIGOUR), CURSETYP_NORM, 0, (M_DURATION | M_VIGOUR),
@ -161,8 +166,8 @@ static struct curse_type ct_antimagiczone = {
}; };
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
static message * static message *cinfo_farvision(const void *obj, typ_t typ, const curse * c,
cinfo_farvision(const void * obj, typ_t typ, const curse *c, int self) int self)
{ {
unused(typ); unused(typ);
unused(obj); unused(obj);
@ -191,6 +196,7 @@ static struct curse_type ct_fogtrap = {
CURSETYP_NORM, 0, (M_DURATION | M_VIGOUR), CURSETYP_NORM, 0, (M_DURATION | M_VIGOUR),
cinfo_simple cinfo_simple
}; };
static struct curse_type ct_maelstrom = { static struct curse_type ct_maelstrom = {
"maelstrom", "maelstrom",
CURSETYP_NORM, CURSE_ISNEW, (M_DURATION | M_VIGOUR), CURSETYP_NORM, CURSE_ISNEW, (M_DURATION | M_VIGOUR),
@ -208,11 +214,13 @@ static struct curse_type ct_drought = {
CURSETYP_NORM, 0, (M_DURATION | M_VIGOUR), CURSETYP_NORM, 0, (M_DURATION | M_VIGOUR),
cinfo_simple cinfo_simple
}; };
static struct curse_type ct_badlearn = { static struct curse_type ct_badlearn = {
"badlearn", "badlearn",
CURSETYP_NORM, CURSE_ISNEW, (M_DURATION | M_VIGOUR), CURSETYP_NORM, CURSE_ISNEW, (M_DURATION | M_VIGOUR),
cinfo_simple cinfo_simple
}; };
/* Trübsal-Zauber */ /* Trübsal-Zauber */
static struct curse_type ct_depression = { static struct curse_type ct_depression = {
"depression", "depression",
@ -226,18 +234,21 @@ static struct curse_type ct_astralblock = {
CURSETYP_NORM, 0, NO_MERGE, CURSETYP_NORM, 0, NO_MERGE,
cinfo_simple cinfo_simple
}; };
/* Unterhaltungsanteil vermehren */ /* Unterhaltungsanteil vermehren */
static struct curse_type ct_generous = { static struct curse_type ct_generous = {
"generous", "generous",
CURSETYP_NORM, 0, (M_DURATION | M_VIGOUR | M_MAXEFFECT), CURSETYP_NORM, 0, (M_DURATION | M_VIGOUR | M_MAXEFFECT),
cinfo_simple cinfo_simple
}; };
/* verhindert Attackiere regional */ /* verhindert Attackiere regional */
static struct curse_type ct_peacezone = { static struct curse_type ct_peacezone = {
"peacezone", "peacezone",
CURSETYP_NORM, 0, NO_MERGE, CURSETYP_NORM, 0, NO_MERGE,
cinfo_simple cinfo_simple
}; };
/* erniedigt Magieresistenz von nicht-aliierten Einheiten, wirkt nur 1x /* erniedigt Magieresistenz von nicht-aliierten Einheiten, wirkt nur 1x
* pro Einheit */ * pro Einheit */
static struct curse_type ct_badmagicresistancezone = { static struct curse_type ct_badmagicresistancezone = {
@ -245,6 +256,7 @@ static struct curse_type ct_badmagicresistancezone = {
CURSETYP_NORM, 0, NO_MERGE, CURSETYP_NORM, 0, NO_MERGE,
cinfo_simple cinfo_simple
}; };
/* erhöht Magieresistenz von aliierten Einheiten, wirkt nur 1x pro /* erhöht Magieresistenz von aliierten Einheiten, wirkt nur 1x pro
* Einheit */ * Einheit */
static struct curse_type ct_goodmagicresistancezone = { static struct curse_type ct_goodmagicresistancezone = {
@ -252,16 +264,19 @@ static struct curse_type ct_goodmagicresistancezone = {
CURSETYP_NORM, 0, NO_MERGE, CURSETYP_NORM, 0, NO_MERGE,
cinfo_simple cinfo_simple
}; };
static struct curse_type ct_riotzone = { static struct curse_type ct_riotzone = {
"riotzone", "riotzone",
CURSETYP_NORM, 0, (M_DURATION), CURSETYP_NORM, 0, (M_DURATION),
cinfo_simple cinfo_simple
}; };
static struct curse_type ct_holyground = { static struct curse_type ct_holyground = {
"holyground", "holyground",
CURSETYP_NORM, CURSE_NOAGE, (M_VIGOUR_ADD), CURSETYP_NORM, CURSE_NOAGE, (M_VIGOUR_ADD),
cinfo_simple cinfo_simple
}; };
static struct curse_type ct_healing = { static struct curse_type ct_healing = {
"healingzone", "healingzone",
CURSETYP_NORM, 0, (M_VIGOUR | M_DURATION), CURSETYP_NORM, 0, (M_VIGOUR | M_DURATION),
@ -269,8 +284,7 @@ static struct curse_type ct_healing = {
}; };
void void register_regioncurse(void)
register_regioncurse(void)
{ {
ct_register(&ct_fogtrap); ct_register(&ct_fogtrap);
ct_register(&ct_antimagiczone); ct_register(&ct_antimagiczone);
@ -292,5 +306,3 @@ register_regioncurse(void)
ct_register(&ct_holyground); ct_register(&ct_holyground);
ct_register(&ct_healing); ct_register(&ct_healing);
} }

View file

@ -35,8 +35,7 @@
#include <assert.h> #include <assert.h>
message * message *cinfo_ship(const void *obj, typ_t typ, const curse * c, int self)
cinfo_ship(const void * obj, typ_t typ, const curse *c, int self)
{ {
message *msg; message *msg;
@ -58,8 +57,8 @@ cinfo_ship(const void * obj, typ_t typ, const curse *c, int self)
/* CurseInfo mit Spezialabfragen */ /* CurseInfo mit Spezialabfragen */
/* C_SHIP_NODRIFT */ /* C_SHIP_NODRIFT */
static message * static message *cinfo_shipnodrift(const void *obj, typ_t typ, const curse * c,
cinfo_shipnodrift(const void * obj, typ_t typ, const curse *c, int self) int self)
{ {
ship *sh = (ship *) obj; ship *sh = (ship *) obj;
@ -67,7 +66,8 @@ cinfo_shipnodrift(const void * obj, typ_t typ, const curse *c, int self)
assert(typ == TYP_SHIP); assert(typ == TYP_SHIP);
if (self != 0) { if (self != 0) {
return msg_message("curseinfo::shipnodrift_1", "ship duration id", sh, c->duration, c->no); return msg_message("curseinfo::shipnodrift_1", "ship duration id", sh,
c->duration, c->no);
} }
return msg_message("curseinfo::shipnodrift_0", "ship id", sh, c->no); return msg_message("curseinfo::shipnodrift_0", "ship id", sh, c->no);
} }
@ -76,8 +76,10 @@ static struct curse_type ct_stormwind = { "stormwind",
CURSETYP_NORM, 0, NO_MERGE, cinfo_ship CURSETYP_NORM, 0, NO_MERGE, cinfo_ship
}; };
static int flyingship_read(storage * store, curse * c, void * target) { static int flyingship_read(storage * store, curse * c, void *target)
{
ship *sh = (ship *) target; ship *sh = (ship *) target;
c->data.v = sh; c->data.v = sh;
if (store->version < FOSS_VERSION) { if (store->version < FOSS_VERSION) {
sh->flags |= SF_FLYING; sh->flags |= SF_FLYING;
@ -87,14 +89,19 @@ static int flyingship_read(storage * store, curse * c, void * target) {
return 0; return 0;
} }
static int flyingship_write(storage * store, const curse * c, const void * target) { static int flyingship_write(storage * store, const curse * c,
const void *target)
{
const ship *sh = (const ship *)target; const ship *sh = (const ship *)target;
assert(sh->flags & SF_FLYING); assert(sh->flags & SF_FLYING);
return 0; return 0;
} }
static int flyingship_age(curse * c) { static int flyingship_age(curse * c)
{
ship *sh = (ship *) c->data.v; ship *sh = (ship *) c->data.v;
if (sh && c->duration == 1) { if (sh && c->duration == 1) {
freset(sh, SF_FLYING); freset(sh, SF_FLYING);
return 1; return 1;
@ -103,19 +110,22 @@ static int flyingship_age(curse * c) {
} }
static struct curse_type ct_flyingship = { "flyingship", static struct curse_type ct_flyingship = { "flyingship",
CURSETYP_NORM, 0, NO_MERGE, cinfo_ship, NULL, flyingship_read, flyingship_write, NULL, flyingship_age CURSETYP_NORM, 0, NO_MERGE, cinfo_ship, NULL, flyingship_read,
flyingship_write, NULL, flyingship_age
}; };
static struct curse_type ct_nodrift = { "nodrift", static struct curse_type ct_nodrift = { "nodrift",
CURSETYP_NORM, 0, (M_DURATION | M_VIGOUR), cinfo_shipnodrift CURSETYP_NORM, 0, (M_DURATION | M_VIGOUR), cinfo_shipnodrift
}; };
static struct curse_type ct_shipspeedup = { "shipspeedup", static struct curse_type ct_shipspeedup = { "shipspeedup",
CURSETYP_NORM, 0, 0, cinfo_ship CURSETYP_NORM, 0, 0, cinfo_ship
}; };
curse * curse *shipcurse_flyingship(ship * sh, unit * mage, double power, int duration)
shipcurse_flyingship(ship* sh, unit * mage, double power, int duration)
{ {
static const curse_type *ct_flyingship = NULL; static const curse_type *ct_flyingship = NULL;
if (!ct_flyingship) { if (!ct_flyingship) {
ct_flyingship = ct_find("flyingship"); ct_flyingship = ct_find("flyingship");
assert(ct_flyingship); assert(ct_flyingship);
@ -126,7 +136,8 @@ shipcurse_flyingship(ship* sh, unit * mage, double power, int duration)
return NULL; return NULL;
} else { } else {
/* mit C_SHIP_NODRIFT haben wir kein Problem */ /* mit C_SHIP_NODRIFT haben wir kein Problem */
curse * c = create_curse(mage, &sh->attribs, ct_flyingship, power, duration, 0.0, 0); curse *c =
create_curse(mage, &sh->attribs, ct_flyingship, power, duration, 0.0, 0);
c->data.v = sh; c->data.v = sh;
if (c && c->duration > 0) { if (c && c->duration > 0) {
sh->flags |= SF_FLYING; sh->flags |= SF_FLYING;
@ -135,22 +146,20 @@ shipcurse_flyingship(ship* sh, unit * mage, double power, int duration)
} }
} }
int int levitate_ship(ship * sh, unit * mage, double power, int duration)
levitate_ship(ship * sh, unit * mage, double power, int duration)
{ {
curse *c = shipcurse_flyingship(sh, mage, power, duration); curse *c = shipcurse_flyingship(sh, mage, power, duration);
if (c) { if (c) {
return c->no; return c->no;
} }
return 0; return 0;
} }
void void register_shipcurse(void)
register_shipcurse(void)
{ {
ct_register(&ct_stormwind); ct_register(&ct_stormwind);
ct_register(&ct_flyingship); ct_register(&ct_flyingship);
ct_register(&ct_nodrift); ct_register(&ct_nodrift);
ct_register(&ct_shipspeedup); ct_register(&ct_shipspeedup);
} }

View file

@ -19,10 +19,13 @@ extern "C" {
struct locale; struct locale;
struct message; struct message;
extern struct message * cinfo_ship(const void * obj, typ_t typ, const struct curse *c, int self); extern struct message *cinfo_ship(const void *obj, typ_t typ,
const struct curse *c, int self);
extern void register_shipcurse(void); extern void register_shipcurse(void);
extern struct curse * shipcurse_flyingship(struct ship* sh, struct unit * mage, double power, int duration); extern struct curse *shipcurse_flyingship(struct ship *sh, struct unit *mage,
int levitate_ship(struct ship * sh, struct unit * mage, double power, int duration); double power, int duration);
int levitate_ship(struct ship *sh, struct unit *mage, double power,
int duration);
#ifdef __cplusplus #ifdef __cplusplus
} }

File diff suppressed because it is too large Load diff

View file

@ -43,10 +43,11 @@
* C_AURA * C_AURA
*/ */
/* erhöht/senkt regeneration und maxaura um effect% */ /* erhöht/senkt regeneration und maxaura um effect% */
static message * static message *cinfo_auraboost(const void *obj, typ_t typ, const curse * c,
cinfo_auraboost(const void * obj, typ_t typ, const curse *c, int self) int self)
{ {
struct unit *u = (struct unit *)obj; struct unit *u = (struct unit *)obj;
unused(typ); unused(typ);
assert(typ == TYP_UNIT); assert(typ == TYP_UNIT);
@ -59,6 +60,7 @@ cinfo_auraboost(const void * obj, typ_t typ, const curse *c, int self)
} }
return NULL; return NULL;
} }
static struct curse_type ct_auraboost = { static struct curse_type ct_auraboost = {
"auraboost", "auraboost",
CURSETYP_NORM, CURSE_SPREADMODULO, (NO_MERGE), CURSETYP_NORM, CURSE_SPREADMODULO, (NO_MERGE),
@ -75,20 +77,23 @@ static struct curse_type ct_magicboost = {
/* /*
* C_SLAVE * C_SLAVE
*/ */
static message * static message *cinfo_slave(const void *obj, typ_t typ, const curse * c,
cinfo_slave(const void * obj, typ_t typ, const curse *c, int self) int self)
{ {
unit *u; unit *u;
unused(typ); unused(typ);
assert(typ == TYP_UNIT); assert(typ == TYP_UNIT);
u = (unit *) obj; u = (unit *) obj;
if (self != 0) { if (self != 0) {
return msg_message("curseinfo::slave_1", "unit duration id", u, c->duration, c->no); return msg_message("curseinfo::slave_1", "unit duration id", u, c->duration,
c->no);
} }
return NULL; return NULL;
} }
static struct curse_type ct_slavery = { "slavery", static struct curse_type ct_slavery = { "slavery",
CURSETYP_NORM, 0, NO_MERGE, CURSETYP_NORM, 0, NO_MERGE,
cinfo_slave cinfo_slave
@ -98,18 +103,20 @@ static struct curse_type ct_slavery = { "slavery",
/* /*
* C_CALM * C_CALM
*/ */
static message * static message *cinfo_calm(const void *obj, typ_t typ, const curse * c,
cinfo_calm(const void * obj, typ_t typ, const curse *c, int self) int self)
{ {
unused(typ); unused(typ);
assert(typ == TYP_UNIT); assert(typ == TYP_UNIT);
if (c->magician && c->magician->faction) { if (c->magician && c->magician->faction) {
faction *f = c->magician->faction; faction *f = c->magician->faction;
unit *u = (unit *) obj; unit *u = (unit *) obj;
if (f == NULL || self == 0) { if (f == NULL || self == 0) {
const struct race *rc = u_irace(c->magician); const struct race *rc = u_irace(c->magician);
return msg_message("curseinfo::calm_0", "unit race id", u, rc, c->no); return msg_message("curseinfo::calm_0", "unit race id", u, rc, c->no);
} }
return msg_message("curseinfo::calm_1", "unit faction id", u, f, c->no); return msg_message("curseinfo::calm_1", "unit faction id", u, f, c->no);
@ -127,18 +134,21 @@ static struct curse_type ct_calmmonster = {
/* /*
* C_SPEED * C_SPEED
*/ */
static message * static message *cinfo_speed(const void *obj, typ_t typ, const curse * c,
cinfo_speed(const void * obj, typ_t typ, const curse *c, int self) int self)
{ {
unused(typ); unused(typ);
assert(typ == TYP_UNIT); assert(typ == TYP_UNIT);
if (self != 0) { if (self != 0) {
unit *u = (unit *) obj; unit *u = (unit *) obj;
return msg_message("curseinfo::speed_1", "unit number duration id", u, c->data.i, c->duration, c->no);
return msg_message("curseinfo::speed_1", "unit number duration id", u,
c->data.i, c->duration, c->no);
} }
return NULL; return NULL;
} }
static struct curse_type ct_speed = { static struct curse_type ct_speed = {
"speed", "speed",
CURSETYP_UNIT, CURSE_SPREADNEVER, M_MEN, CURSETYP_UNIT, CURSE_SPREADNEVER, M_MEN,
@ -149,15 +159,16 @@ static struct curse_type ct_speed = {
/* /*
* C_ORC * C_ORC
*/ */
message * message *cinfo_unit(const void *obj, typ_t typ, const curse * c, int self)
cinfo_unit(const void * obj, typ_t typ, const curse *c, int self)
{ {
unused(typ); unused(typ);
assert(typ == TYP_UNIT); assert(typ == TYP_UNIT);
if (self != 0) { if (self != 0) {
unit *u = (unit *) obj; unit *u = (unit *) obj;
return msg_message(mkname("curseinfo", c->type->cname), "unit id", u, c->no);
return msg_message(mkname("curseinfo", c->type->cname), "unit id", u,
c->no);
} }
return NULL; return NULL;
} }
@ -172,18 +183,21 @@ static struct curse_type ct_orcish = {
/* /*
* C_KAELTESCHUTZ * C_KAELTESCHUTZ
*/ */
static message * static message *cinfo_kaelteschutz(const void *obj, typ_t typ, const curse * c,
cinfo_kaelteschutz(const void * obj, typ_t typ, const curse *c, int self) int self)
{ {
unused(typ); unused(typ);
assert(typ == TYP_UNIT); assert(typ == TYP_UNIT);
if (self != 0) { if (self != 0) {
unit *u = (unit *) obj; unit *u = (unit *) obj;
return msg_message("curseinfo::warmth_1", "unit number id", u, get_cursedmen(u, c), c->no);
return msg_message("curseinfo::warmth_1", "unit number id", u,
get_cursedmen(u, c), c->no);
} }
return NULL; return NULL;
} }
static struct curse_type ct_insectfur = { static struct curse_type ct_insectfur = {
"insectfur", "insectfur",
CURSETYP_UNIT, CURSE_SPREADMODULO, (M_MEN | M_DURATION), CURSETYP_UNIT, CURSE_SPREADMODULO, (M_MEN | M_DURATION),
@ -194,8 +208,8 @@ static struct curse_type ct_insectfur = {
/* /*
* C_SPARKLE * C_SPARKLE
*/ */
static message * static message *cinfo_sparkle(const void *obj, typ_t typ, const curse * c,
cinfo_sparkle(const void * obj, typ_t typ, const curse *c, int self) int self)
{ {
const char *effects[] = { const char *effects[] = {
NULL, /* end grau */ NULL, /* end grau */
@ -224,25 +238,33 @@ cinfo_sparkle(const void * obj, typ_t typ, const curse *c, int self)
NULL, /* end draig */ NULL, /* end draig */
}; };
int m, begin = 0, end = 0; int m, begin = 0, end = 0;
unit *u; unit *u;
unused(typ); unused(typ);
assert(typ == TYP_UNIT); assert(typ == TYP_UNIT);
u = (unit *) obj; u = (unit *) obj;
if (!c->magician || !c->magician->faction) return NULL; if (!c->magician || !c->magician->faction)
return NULL;
for (m = 0; m != c->magician->faction->magiegebiet; ++m) { for (m = 0; m != c->magician->faction->magiegebiet; ++m) {
while (effects[end]!=NULL) ++end; while (effects[end] != NULL)
++end;
begin = end + 1; begin = end + 1;
end = begin; end = begin;
} }
while (effects[end]!=NULL) ++end; while (effects[end] != NULL)
if (end==begin) return NULL; ++end;
if (end == begin)
return NULL;
else { else {
int index = begin + curse_geteffect_int(c) % (end - begin); int index = begin + curse_geteffect_int(c) % (end - begin);
return msg_message(mkname("curseinfo", effects[index]), "unit id", u, c->no);
return msg_message(mkname("curseinfo", effects[index]), "unit id", u,
c->no);
} }
} }
@ -274,11 +296,14 @@ static struct curse_type ct_worse = {
static struct curse_type ct_itemcloak = { static struct curse_type ct_itemcloak = {
"itemcloak", CURSETYP_UNIT, CURSE_SPREADNEVER, M_DURATION, cinfo_unit "itemcloak", CURSETYP_UNIT, CURSE_SPREADNEVER, M_DURATION, cinfo_unit
}; };
/* ------------------------------------------------------------- */ /* ------------------------------------------------------------- */
static struct curse_type ct_fumble = { static struct curse_type ct_fumble = {
"fumble", CURSETYP_NORM, CURSE_SPREADNEVER|CURSE_ONLYONE, NO_MERGE, cinfo_unit "fumble", CURSETYP_NORM, CURSE_SPREADNEVER | CURSE_ONLYONE, NO_MERGE,
cinfo_unit
}; };
/* ------------------------------------------------------------- */ /* ------------------------------------------------------------- */
@ -296,12 +321,13 @@ static struct curse_type ct_magicresistance = {
* C_SKILL * C_SKILL
*/ */
static int static int read_skill(struct storage *store, curse * c, void *target)
read_skill(struct storage * store, curse * c, void * target)
{ {
int skill; int skill;
if (store->version < CURSETYPE_VERSION) { if (store->version < CURSETYPE_VERSION) {
int men; int men;
skill = store->r_int(store); skill = store->r_int(store);
men = store->r_int(store); men = store->r_int(store);
} else { } else {
@ -318,14 +344,16 @@ write_skill(struct storage * store, const curse * c, const void * target)
return 0; return 0;
} }
static message * static message *cinfo_skillmod(const void *obj, typ_t typ, const curse * c,
cinfo_skillmod(const void * obj, typ_t typ, const curse *c, int self) int self)
{ {
unused(typ); unused(typ);
if (self != 0) { if (self != 0) {
unit *u = (unit *) obj; unit *u = (unit *) obj;
int sk = c->data.i; int sk = c->data.i;
if (c->effect > 0) { if (c->effect > 0) {
return msg_message("curseinfo::skill_1", "unit skill id", u, sk, c->no); return msg_message("curseinfo::skill_1", "unit skill id", u, sk, c->no);
} else if (c->effect < 0) { } else if (c->effect < 0) {
@ -341,8 +369,7 @@ static struct curse_type ct_skillmod = {
}; };
/* ------------------------------------------------------------- */ /* ------------------------------------------------------------- */
void void register_unitcurse(void)
register_unitcurse(void)
{ {
ct_register(&ct_auraboost); ct_register(&ct_auraboost);
ct_register(&ct_magicboost); ct_register(&ct_magicboost);
@ -360,4 +387,3 @@ register_unitcurse(void)
ct_register(&ct_oldrace); ct_register(&ct_oldrace);
ct_register(&ct_magicresistance); ct_register(&ct_magicresistance);
} }

View file

@ -19,7 +19,8 @@ extern "C" {
struct curse; struct curse;
struct message; struct message;
extern struct message * cinfo_unit(const void * obj, typ_t typ, const struct curse *c, int self); extern struct message *cinfo_unit(const void *obj, typ_t typ,
const struct curse *c, int self);
extern void register_unitcurse(void); extern void register_unitcurse(void);