Merge pull request #610 from ennorehling/develop

house cleaning prior to 3.10
This commit is contained in:
Enno Rehling 2016-11-23 19:30:57 +01:00 committed by GitHub
commit 0cb8e36877
62 changed files with 518 additions and 661 deletions

View file

@ -295,7 +295,7 @@ static void a_initeffect(attrib * a)
a->data.v = calloc(sizeof(effect_data), 1); a->data.v = calloc(sizeof(effect_data), 1);
} }
static void a_finalizeeffect(attrib * a) static void a_finalizeeffect(attrib * a) //-V524
{ {
free(a->data.v); free(a->data.v);
} }

View file

@ -765,7 +765,7 @@ bool missile)
skill += CavalryBonus(tu, enemy, BONUS_SKILL); skill += CavalryBonus(tu, enemy, BONUS_SKILL);
if (wtype) if (wtype)
skill = skill =
skillmod(urace(tu)->attribs, tu, tu->region, wtype->skill, skill, skillmod(u_race(tu)->attribs, tu, tu->region, wtype->skill, skill,
SMF_RIDING); SMF_RIDING);
} }
@ -3984,7 +3984,7 @@ static bool start_battle(region * r, battle ** bp)
while (a && a->type == &at_curse) { while (a && a->type == &at_curse) {
curse *c = (curse *)a->data.v; curse *c = (curse *)a->data.v;
if (c->type == calm_ct if (c->type == calm_ct
&& curse_geteffect(c) == u2->faction->subscription) { && curse_geteffect_int(c) == u2->faction->subscription) {
if (curse_active(c)) { if (curse_active(c)) {
calm = true; calm = true;
break; break;
@ -4275,10 +4275,8 @@ void do_battle(region * r)
/* Hier ist das Gefecht beendet, und wir k<>nnen die /* Hier ist das Gefecht beendet, und wir k<>nnen die
* Hilfsstrukturen * wieder l<EFBFBD>schen: */ * Hilfsstrukturen * wieder l<EFBFBD>schen: */
if (b) {
free_battle(b); free_battle(b);
} }
}
void do_battles(void) { void do_battles(void) {
region *r; region *r;

View file

@ -30,7 +30,7 @@ extern "C" {
#define FS_HELP 2 #define FS_HELP 2
/***** Verteidigungslinien. /***** Verteidigungslinien.
* Eressea hat 4 Verteidigungslinien. 1 ist vorn, 5. enth<EFBFBD>lt Summen * Eressea hat 4 Verteidigungslinien. 1 ist vorn, 5. enthaelt Summen
*/ */
#define NUMROWS 5 #define NUMROWS 5
@ -72,9 +72,9 @@ extern "C" {
unsigned char relations[MAXSIDES]; unsigned char relations[MAXSIDES];
struct side *enemies[MAXSIDES]; struct side *enemies[MAXSIDES];
struct fighter *fighters; struct fighter *fighters;
int index; /* Eintrag der Fraktion in b->matrix/b->enemies */ unsigned int index; /* Eintrag der Fraktion in b->matrix/b->enemies */
int size[NUMROWS]; /* Anzahl Personen in Reihe X. 0 = Summe */ int size[NUMROWS]; /* Anzahl Personen in Reihe X. 0 = Summe */
int nonblockers[NUMROWS]; /* Anzahl nichtblockierender K<EFBFBD>mpfer, z.B. Schattenritter. */ int nonblockers[NUMROWS]; /* Anzahl nichtblockierender Kaempfer, z.B. Schattenritter. */
int alive; /* Die Partei hat den Kampf verlassen */ int alive; /* Die Partei hat den Kampf verlassen */
int removed; /* stoned */ int removed; /* stoned */
int flee; int flee;
@ -131,7 +131,7 @@ extern "C" {
/*** fighter::person::flags ***/ /*** fighter::person::flags ***/
#define FL_TIRED 1 #define FL_TIRED 1
#define FL_DAZZLED 2 /* durch Untote oder D<EFBFBD>monen eingesch<63>chtert */ #define FL_DAZZLED 2 /* durch Untote oder Daemonen eingeschuechtert */
#define FL_PANICED 4 #define FL_PANICED 4
#define FL_COURAGE 8 /* Helden fliehen nie */ #define FL_COURAGE 8 /* Helden fliehen nie */
#define FL_SLEEPING 16 #define FL_SLEEPING 16
@ -156,17 +156,17 @@ extern "C" {
typedef struct fighter { typedef struct fighter {
struct fighter *next; struct fighter *next;
struct side *side; struct side *side;
struct unit *unit; /* Die Einheit, die hier k<EFBFBD>mpft */ struct unit *unit; /* Die Einheit, die hier kaempft */
struct building *building; /* Geb<EFBFBD>ude, in dem die Einheit evtl. steht */ struct building *building; /* Gebaeude, in dem die Einheit evtl. steht */
status_t status; /* Kampfstatus */ status_t status; /* Kampfstatus */
struct weapon *weapons; struct weapon *weapons;
struct armor *armors; /* Anzahl R<EFBFBD>stungen jeden Typs */ struct armor *armors; /* Anzahl Ruestungen jeden Typs */
int alive; /* Anzahl der noch nicht Toten in der Einheit */ int alive; /* Anzahl der noch nicht Toten in der Einheit */
int fighting; /* Anzahl der K<EFBFBD>mpfer in der aktuellen Runde */ int fighting; /* Anzahl der Kaempfer in der aktuellen Runde */
int removed; /* Anzahl Kaempfer, die nicht tot sind, aber int removed; /* Anzahl Kaempfer, die nicht tot sind, aber
aus dem Kampf raus sind (zB weil sie aus dem Kampf raus sind (zB weil sie
versteinert wurden). Diese werden auch versteinert wurden). Diese werden auch
in alive noch mitgez<EFBFBD>hlt! */ in alive noch mitgezaehlt! */
int magic; /* Magietalent der Einheit */ int magic; /* Magietalent der Einheit */
int horses; /* Anzahl brauchbarer Pferde der Einheit */ int horses; /* Anzahl brauchbarer Pferde der Einheit */
int elvenhorses; /* Anzahl brauchbarer Elfenpferde der Einheit */ int elvenhorses; /* Anzahl brauchbarer Elfenpferde der Einheit */
@ -179,7 +179,7 @@ extern "C" {
int defence : 8; /* (Magie) Paradenbonus der Personen */ int defence : 8; /* (Magie) Paradenbonus der Personen */
int damage : 8; /* (Magie) Schadensbonus der Personen im Nahkampf */ int damage : 8; /* (Magie) Schadensbonus der Personen im Nahkampf */
int damage_rear : 8; /* (Magie) Schadensbonus der Personen im Fernkampf */ int damage_rear : 8; /* (Magie) Schadensbonus der Personen im Fernkampf */
int flags : 8; /* (Magie) Diverse Flags auf K<EFBFBD>mpfern */ int flags : 8; /* (Magie) Diverse Flags auf Kaempfern */
int speed : 8; /* (Magie) Geschwindigkeitsmultiplkator. */ int speed : 8; /* (Magie) Geschwindigkeitsmultiplkator. */
int reload : 4; /* Anzahl Runden, die die Waffe x noch laden muss. int reload : 4; /* Anzahl Runden, die die Waffe x noch laden muss.
* dahinter steckt ein array[RL_MAX] wenn er min. eine hat. */ * dahinter steckt ein array[RL_MAX] wenn er min. eine hat. */

View file

@ -756,10 +756,8 @@ static int tolua_unit_get_spells(lua_State * L)
quicklist *slist = 0; quicklist *slist = 0;
if (sb) { if (sb) {
quicklist **slist_ptr = &sb->spells; quicklist **slist_ptr = &sb->spells;
if (slist_ptr) {
slist = *slist_ptr; slist = *slist_ptr;
} }
}
return tolua_quicklist_push(L, "spellbook", "spell_entry", slist); return tolua_quicklist_push(L, "spellbook", "spell_entry", slist);
} }

View file

@ -97,7 +97,7 @@ static request *nextentertainer;
static int entertaining; static int entertaining;
static unsigned int norders; static unsigned int norders;
static request *oa; static request *g_requests;
#define RECRUIT_MERGE 1 #define RECRUIT_MERGE 1
static int rules_recruit = -1; static int rules_recruit = -1;
@ -112,6 +112,23 @@ static void recruit_init(void)
} }
} }
int entertainmoney(const region * r)
{
double n;
if (is_cursed(r->attribs, C_DEPRESSION, 0)) {
return 0;
}
n = rmoney(r) / (double)ENTERTAINFRACTION;
if (is_cursed(r->attribs, C_GENEROUS, 0)) {
n *= get_curseeffect(r->attribs, C_GENEROUS, 0);
}
return (int)n;
}
int income(const unit * u) int income(const unit * u)
{ {
const race *rc = u_race(u); const race *rc = u_race(u);
@ -154,21 +171,21 @@ static void expandorders(region * r, request * requests)
if (norders > 0) { if (norders > 0) {
int i = 0; int i = 0;
oa = (request *)calloc(norders, sizeof(request)); g_requests = (request *)calloc(norders, sizeof(request));
for (o = requests; o; o = o->next) { for (o = requests; o; o = o->next) {
if (o->qty > 0) { if (o->qty > 0) {
unsigned int j; unsigned int j;
for (j = o->qty; j; j--) { for (j = o->qty; j; j--) {
oa[i] = *o; g_requests[i] = *o;
oa[i].unit->n = 0; g_requests[i].unit->n = 0;
i++; i++;
} }
} }
} }
scramble(oa, norders, sizeof(request)); scramble(g_requests, norders, sizeof(request));
} }
else { else {
oa = NULL; g_requests = NULL;
} }
while (requests) { while (requests) {
request *o = requests->next; request *o = requests->next;
@ -1458,16 +1475,16 @@ static void expandbuying(region * r, request * buyorders)
for (j = 0; j != norders; j++) { for (j = 0; j != norders; j++) {
int price, multi; int price, multi;
ltype = oa[j].type.ltype; ltype = g_requests[j].type.ltype;
trade = trades; trade = trades;
while (trade->type != ltype) while (trade->type != ltype)
++trade; ++trade;
multi = trade->multi; multi = trade->multi;
price = ltype->price * multi; price = ltype->price * multi;
if (get_pooled(oa[j].unit, rsilver, GET_DEFAULT, if (get_pooled(g_requests[j].unit, rsilver, GET_DEFAULT,
price) >= price) { price) >= price) {
unit *u = oa[j].unit; unit *u = g_requests[j].unit;
item *items; item *items;
/* litems zählt die Güter, die verkauft wurden, u->n das Geld, das /* litems zählt die Güter, die verkauft wurden, u->n das Geld, das
@ -1481,7 +1498,7 @@ static void expandbuying(region * r, request * buyorders)
items = a->data.v; items = a->data.v;
i_change(&items, ltype->itype, 1); i_change(&items, ltype->itype, 1);
a->data.v = items; a->data.v = items;
i_change(&oa[j].unit->items, ltype->itype, 1); i_change(&g_requests[j].unit->items, ltype->itype, 1);
use_pooled(u, rsilver, GET_DEFAULT, price); use_pooled(u, rsilver, GET_DEFAULT, price);
if (u->n < 0) if (u->n < 0)
u->n = 0; u->n = 0;
@ -1499,7 +1516,7 @@ static void expandbuying(region * r, request * buyorders)
fset(u, UFL_LONGACTION | UFL_NOTMOVING); fset(u, UFL_LONGACTION | UFL_NOTMOVING);
} }
} }
free(oa); free(g_requests);
/* Ausgabe an Einheiten */ /* Ausgabe an Einheiten */
@ -1736,7 +1753,7 @@ static void expandselling(region * r, request * sellorders, int limit)
for (j = 0; j != norders; j++) { for (j = 0; j != norders; j++) {
const luxury_type *search = NULL; const luxury_type *search = NULL;
const luxury_type *ltype = oa[j].type.ltype; const luxury_type *ltype = g_requests[j].type.ltype;
int multi = r_demand(r, ltype); int multi = r_demand(r, ltype);
int i; int i;
int use = 0; int use = 0;
@ -1753,7 +1770,7 @@ static void expandselling(region * r, request * sellorders, int limit)
if (money >= price) { if (money >= price) {
int abgezogenhafen = 0; int abgezogenhafen = 0;
int abgezogensteuer = 0; int abgezogensteuer = 0;
unit *u = oa[j].unit; unit *u = g_requests[j].unit;
item *itm; item *itm;
attrib *a = a_find(u->attribs, &at_luxuries); attrib *a = a_find(u->attribs, &at_luxuries);
if (a == NULL) if (a == NULL)
@ -1801,10 +1818,10 @@ static void expandselling(region * r, request * sellorders, int limit)
} }
} }
if (use > 0) { if (use > 0) {
use_pooled(oa[j].unit, ltype->itype->rtype, GET_DEFAULT, use); use_pooled(g_requests[j].unit, ltype->itype->rtype, GET_DEFAULT, use);
} }
} }
free(oa); free(g_requests);
/* Steuern. Hier werden die Steuern dem Besitzer der größten Burg gegeben. */ /* Steuern. Hier werden die Steuern dem Besitzer der größten Burg gegeben. */
if (maxowner) { if (maxowner) {
@ -1928,7 +1945,7 @@ static bool sell(unit * u, request ** sellorders, struct order *ord)
s = gettoken(token, sizeof(token)); s = gettoken(token, sizeof(token));
itype = s ? finditemtype(s, u->faction->locale) : 0; itype = s ? finditemtype(s, u->faction->locale) : 0;
ltype = itype ? resource2luxury(itype->rtype) : 0; ltype = itype ? resource2luxury(itype->rtype) : 0;
if (ltype == NULL) { if (ltype == NULL || itype == NULL) {
cmistake(u, ord, 126, MSG_COMMERCE); cmistake(u, ord, 126, MSG_COMMERCE);
return false; return false;
} }
@ -2010,8 +2027,8 @@ static void expandstealing(region * r, request * stealorders)
* u ist die beklaute unit. oa.unit ist die klauende unit. * u ist die beklaute unit. oa.unit ist die klauende unit.
*/ */
for (j = 0; j != norders && oa[j].unit->n <= oa[j].unit->wants; j++) { for (j = 0; j != norders && g_requests[j].unit->n <= g_requests[j].unit->wants; j++) {
unit *u = findunitg(oa[j].no, r); unit *u = findunitg(g_requests[j].no, r);
int n = 0; int n = 0;
if (u && u->region == r) { if (u && u->region == r) {
n = get_pooled(u, rsilver, GET_ALL, INT_MAX); n = get_pooled(u, rsilver, GET_ALL, INT_MAX);
@ -2035,17 +2052,17 @@ static void expandstealing(region * r, request * stealorders)
n = 10; n = 10;
} }
if (n > 0) { if (n > 0) {
n = _min(n, oa[j].unit->wants); n = _min(n, g_requests[j].unit->wants);
use_pooled(u, rsilver, GET_ALL, n); use_pooled(u, rsilver, GET_ALL, n);
oa[j].unit->n = n; g_requests[j].unit->n = n;
change_money(oa[j].unit, n); change_money(g_requests[j].unit, n);
ADDMSG(&u->faction->msgs, msg_message("stealeffect", "unit region amount", ADDMSG(&u->faction->msgs, msg_message("stealeffect", "unit region amount",
u, u->region, n)); u, u->region, n));
} }
add_income(oa[j].unit, IC_STEAL, oa[j].unit->wants, oa[j].unit->n); add_income(g_requests[j].unit, IC_STEAL, g_requests[j].unit->wants, g_requests[j].unit->n);
fset(oa[j].unit, UFL_LONGACTION | UFL_NOTMOVING); fset(g_requests[j].unit, UFL_LONGACTION | UFL_NOTMOVING);
} }
free(oa); free(g_requests);
} }
/* ------------------------------------------------------------- */ /* ------------------------------------------------------------- */
@ -2060,14 +2077,14 @@ static void plant(unit * u, int raw)
if (!fval(r->terrain, LAND_REGION)) { if (!fval(r->terrain, LAND_REGION)) {
return; return;
} }
if (rherbtype(r) == NULL) { itype = rherbtype(r);
if (itype == NULL) {
cmistake(u, u->thisorder, 108, MSG_PRODUCE); cmistake(u, u->thisorder, 108, MSG_PRODUCE);
return; return;
} }
/* Skill prüfen */ /* Skill prüfen */
skill = effskill(u, SK_HERBALISM, 0); skill = effskill(u, SK_HERBALISM, 0);
itype = rherbtype(r);
if (skill < 6) { if (skill < 6) {
ADDMSG(&u->faction->msgs, ADDMSG(&u->faction->msgs,
msg_feedback(u, u->thisorder, "plant_skills", msg_feedback(u, u->thisorder, "plant_skills",
@ -2702,13 +2719,13 @@ static void expandloot(region * r, request * lootorders)
return; return;
for (i = 0; i != norders && startmoney > looted + TAXFRACTION * 2; i++) { for (i = 0; i != norders && startmoney > looted + TAXFRACTION * 2; i++) {
change_money(oa[i].unit, TAXFRACTION); change_money(g_requests[i].unit, TAXFRACTION);
oa[i].unit->n += TAXFRACTION; g_requests[i].unit->n += TAXFRACTION;
/*Looting destroys double the money*/ /*Looting destroys double the money*/
looted += TAXFRACTION * 2; looted += TAXFRACTION * 2;
} }
rsetmoney(r, startmoney - looted); rsetmoney(r, startmoney - looted);
free(oa); free(g_requests);
/* Lowering morale by 1 depending on the looted money (+20%) */ /* Lowering morale by 1 depending on the looted money (+20%) */
if (rng_int() % 100 < 20 + (looted * 80) / startmoney) { if (rng_int() % 100 < 20 + (looted * 80) / startmoney) {
@ -2737,11 +2754,11 @@ void expandtax(region * r, request * taxorders)
return; return;
for (i = 0; i != norders && rmoney(r) > TAXFRACTION; i++) { for (i = 0; i != norders && rmoney(r) > TAXFRACTION; i++) {
change_money(oa[i].unit, TAXFRACTION); change_money(g_requests[i].unit, TAXFRACTION);
oa[i].unit->n += TAXFRACTION; g_requests[i].unit->n += TAXFRACTION;
rsetmoney(r, rmoney(r) - TAXFRACTION); rsetmoney(r, rmoney(r) - TAXFRACTION);
} }
free(oa); free(g_requests);
for (u = r->units; u; u = u->next) { for (u = r->units; u; u = u->next) {
if (u->n >= 0) { if (u->n >= 0) {
@ -2939,9 +2956,10 @@ static void peasant_taxes(region * r)
maxsize = buildingeffsize(b, false); maxsize = buildingeffsize(b, false);
if (maxsize > 0) { if (maxsize > 0) {
double taxfactor = money * b->type->taxes(b, maxsize); double taxfactor = money * b->type->taxes(b, maxsize);
double morale = money * region_get_morale(r) * MORALE_TAX_FACTOR; double morale = MORALE_TAX_FACTOR * money * region_get_morale(r);
if (taxfactor > morale) if (taxfactor > morale) {
taxfactor = morale; taxfactor = morale;
}
if (taxfactor > 0) { if (taxfactor > 0) {
int taxmoney = (int)taxfactor; int taxmoney = (int)taxfactor;
change_money(u, taxmoney); change_money(u, taxmoney);

View file

@ -48,6 +48,7 @@ extern "C" {
struct request; struct request;
int income(const struct unit *u); int income(const struct unit *u);
int entertainmoney(const struct region *r);
void economics(struct region *r); void economics(struct region *r);
void produce(struct region *r); void produce(struct region *r);

View file

@ -137,7 +137,7 @@ int give_quota(const unit * src, const unit * dst, const item_type * type,
} }
if (dst && src && src->faction != dst->faction) { if (dst && src && src->faction != dst->faction) {
divisor = config_get_flt("rules.items.give_divisor", 1); divisor = config_get_flt("rules.items.give_divisor", 1);
assert(divisor == 0 || divisor >= 1); assert(divisor <= 0 || divisor >= 1);
if (divisor >= 1) { if (divisor >= 1) {
/* predictable > correct: */ /* predictable > correct: */
int x = (int)(n / divisor); int x = (int)(n / divisor);
@ -781,7 +781,7 @@ void give_cmd(unit * u, order * ord)
} }
if (u2 != NULL) { if (u2 != NULL) {
if ((u_race(u)->ec_flags & ECF_KEEP_ITEM) && u2 != NULL) { if ((u_race(u)->ec_flags & ECF_KEEP_ITEM)) {
ADDMSG(&u->faction->msgs, ADDMSG(&u->faction->msgs,
msg_feedback(u, ord, "race_nogive", "race", u_race(u))); msg_feedback(u, ord, "race_nogive", "race", u_race(u)));
return; return;

View file

@ -184,7 +184,7 @@ map_region *mr_get(const view * vi, int xofs, int yofs)
static point *coor2point(const coordinate * c, point * p) static point *coor2point(const coordinate * c, point * p)
{ {
assert(c && p); assert(c && p);
p->x = c->x * TWIDTH + c->y * TWIDTH / 2; p->x = c->x * TWIDTH + c->y * TWIDTH / 2; //-V537
p->y = c->y * THEIGHT; p->y = c->y * THEIGHT;
return p; return p;
} }
@ -262,7 +262,7 @@ static chtype mr_tile(const map_region * mr, int highlight)
const region *r = mr->r; const region *r = mr->r;
switch (r->terrain->_name[0]) { switch (r->terrain->_name[0]) {
case 'o': case 'o':
return '.' | COLOR_PAIR(hl + COLOR_CYAN) | A_BOLD; return '.' | COLOR_PAIR(hl + COLOR_CYAN) | A_BOLD; //-V525
case 'd': case 'd':
return 'D' | COLOR_PAIR(hl + COLOR_YELLOW) | A_BOLD; return 'D' | COLOR_PAIR(hl + COLOR_YELLOW) | A_BOLD;
case 't': case 't':
@ -1167,7 +1167,7 @@ static void handlekey(state * st, int c)
region *first = (mr && mr->r && mr->r->next) ? mr->r->next : regions; region *first = (mr && mr->r && mr->r->next) ? mr->r->next : regions;
if (findmode == 'f') { if (findmode == 'f') {
sprintf(sbuffer, "find-faction: %s", locate); snprintf(sbuffer, sizeof(sbuffer), "find-faction: %s", locate);
statusline(st->wnd_status->handle, sbuffer); statusline(st->wnd_status->handle, sbuffer);
f = findfaction(atoi36(locate)); f = findfaction(atoi36(locate));
if (f == NULL) { if (f == NULL) {

View file

@ -1,8 +1,8 @@
#include <platform.h> #include <platform.h>
#include <kernel/config.h>
#include "items.h" #include "items.h"
#include "study.h" #include "study.h"
#include "economy.h"
#include "move.h" #include "move.h"
#include "magic.h" #include "magic.h"
@ -114,10 +114,9 @@ struct order *ord)
const resource_type *rt_crystal = NULL; const resource_type *rt_crystal = NULL;
int i; int i;
if (rt_crystal == NULL) {
rt_crystal = rt_find("antimagic"); rt_crystal = rt_find("antimagic");
assert(rt_crystal != NULL); assert(rt_crystal != NULL);
}
for (i = 0; i != amount; ++i) { for (i = 0; i != amount; ++i) {
int effect, duration = 2; int effect, duration = 2;
double force; double force;
@ -138,7 +137,7 @@ struct order *ord)
while (*ap && force > 0) { while (*ap && force > 0) {
curse *c; curse *c;
attrib *a = *ap; attrib *a = *ap;
if (!fval(a->type, ATF_CURSE)) { if (!(a->type->flags & ATF_CURSE)) {
do { do {
ap = &(*ap)->next; ap = &(*ap)->next;
} while (*ap && a->type == (*ap)->type); } while (*ap && a->type == (*ap)->type);

View file

@ -1,8 +1,9 @@
#include "platform.h" #include "platform.h"
#include <util/base36.h>
#include "json.h" #include "json.h"
#include <util/base36.h>
#include <util/log.h>
#include <kernel/plane.h> #include <kernel/plane.h>
#include <kernel/region.h> #include <kernel/region.h>
#include <kernel/faction.h> #include <kernel/faction.h>
@ -22,12 +23,20 @@ int json_import(struct stream * out) {
assert(out && out->api); assert(out && out->api);
while (!out->api->readln(out->handle, buffer, sizeof(buffer))) { while (!out->api->readln(out->handle, buffer, sizeof(buffer))) {
size_t len = strlen(buffer); size_t len = strlen(buffer);
data = (char *)realloc(data, sz + len + 1); char *tmp;
tmp = (char *)realloc(data, sz + len + 1);
if (!tmp) {
log_fatal("allocation failure in json_import");
free(data);
return 1;
}
data = tmp;
memcpy(data + sz, buffer, len); memcpy(data + sz, buffer, len);
sz += len; sz += len;
data[sz] = 0; data[sz] = 0;
} }
json = cJSON_Parse(data); json = cJSON_Parse(data);
free(data);
child = cJSON_GetObjectItem(json, "regions"); child = cJSON_GetObjectItem(json, "regions");
if (child && child->type == cJSON_Object) { if (child && child->type == cJSON_Object) {
cJSON *j; cJSON *j;
@ -64,7 +73,7 @@ int json_export(stream * out, int flags) {
cJSON_AddItemToObject(root, "planes", json = cJSON_CreateObject()); cJSON_AddItemToObject(root, "planes", json = cJSON_CreateObject());
for (p = planes; p; p = p->next) { for (p = planes; p; p = p->next) {
cJSON *data; cJSON *data;
_snprintf(id, sizeof(id), "%u", p->id); _snprintf(id, sizeof(id), "%d", p->id);
cJSON_AddItemToObject(json, id, data = cJSON_CreateObject()); cJSON_AddItemToObject(json, id, data = cJSON_CreateObject());
cJSON_AddNumberToObject(data, "x", p->minx); cJSON_AddNumberToObject(data, "x", p->minx);
cJSON_AddNumberToObject(data, "y", p->miny); cJSON_AddNumberToObject(data, "y", p->miny);
@ -76,7 +85,7 @@ int json_export(stream * out, int flags) {
cJSON_AddItemToObject(root, "regions", json = cJSON_CreateObject()); cJSON_AddItemToObject(root, "regions", json = cJSON_CreateObject());
for (r = regions; r; r = r->next) { for (r = regions; r; r = r->next) {
cJSON *data; cJSON *data;
_snprintf(id, sizeof(id), "%u", r->uid); _snprintf(id, sizeof(id), "%d", r->uid);
cJSON_AddItemToObject(json, id, data = cJSON_CreateObject()); cJSON_AddItemToObject(json, id, data = cJSON_CreateObject());
cJSON_AddNumberToObject(data, "x", r->x); cJSON_AddNumberToObject(data, "x", r->x);
cJSON_AddNumberToObject(data, "y", r->y); cJSON_AddNumberToObject(data, "y", r->y);

View file

@ -249,7 +249,7 @@ int destroy_cmd(unit * u, struct order *ord)
} }
if (con) { if (con) {
/* TODO: Nicht an ZERSTÖRE mit Punktangabe angepasst! */ /* TODO: Nicht an ZERST<EFBFBD>RE mit Punktangabe angepasst! */
int c; int c;
for (c = 0; con->materials[c].number; ++c) { for (c = 0; con->materials[c].number; ++c) {
const requirement *rq = con->materials + c; const requirement *rq = con->materials + c;
@ -513,8 +513,8 @@ int build(unit * u, const construction * ctype, int completed, int want)
/* Hier ist entweder maxsize == -1, oder completed < maxsize. /* Hier ist entweder maxsize == -1, oder completed < maxsize.
* Andernfalls ist das Datenfile oder sonstwas kaputt... * Andernfalls ist das Datenfile oder sonstwas kaputt...
* (enno): Nein, das ist für Dinge, bei denen die chste Ausbaustufe * (enno): Nein, das ist f<EFBFBD>r Dinge, bei denen die n<EFBFBD>chste Ausbaustufe
* die gleiche wie die vorherige ist. z.b. gegenstände. * die gleiche wie die vorherige ist. z.b. gegenst<EFBFBD>nde.
*/ */
if (type->maxsize > 0) { if (type->maxsize > 0) {
completed = completed % type->maxsize; completed = completed % type->maxsize;
@ -759,10 +759,8 @@ build_building(unit * u, const building_type * btype, int id, int want, order *
return 0; return 0;
} }
} }
}
if (b)
built = b->size; built = b->size;
}
if (n <= 0 || n == INT_MAX) { if (n <= 0 || n == INT_MAX) {
if (b == NULL) { if (b == NULL) {
if (btype->maxsize > 0) { if (btype->maxsize > 0) {
@ -817,11 +815,11 @@ build_building(unit * u, const building_type * btype, int id, int want, order *
btname = LOC(lang, btype->_name); btname = LOC(lang, btype->_name);
if (want - built <= 0) { if (want - built <= 0) {
/* gebäude fertig */ /* geb<EFBFBD>ude fertig */
new_order = default_order(lang); new_order = default_order(lang);
} }
else if (want != INT_MAX && btname) { else if (want != INT_MAX && btname) {
/* reduzierte restgröße */ /* reduzierte restgr<EFBFBD><EFBFBD>e */
const char *hasspace = strchr(btname, ' '); const char *hasspace = strchr(btname, ' ');
if (hasspace) { if (hasspace) {
new_order = new_order =
@ -833,7 +831,7 @@ build_building(unit * u, const building_type * btype, int id, int want, order *
} }
} }
else if (btname) { else if (btname) {
/* Neues Haus, Befehl mit Gebäudename */ /* Neues Haus, Befehl mit Geb<EFBFBD>udename */
const char *hasspace = strchr(btname, ' '); const char *hasspace = strchr(btname, ' ');
if (hasspace) { if (hasspace) {
new_order = create_order(K_MAKE, lang, "\"%s\" %i", btname, b->no); new_order = create_order(K_MAKE, lang, "\"%s\" %i", btname, b->no);

View file

@ -22,12 +22,14 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "building.h" #include "building.h"
/* kernel includes */ /* kernel includes */
#include "curse.h"
#include "item.h" #include "item.h"
#include "unit.h" #include "unit.h"
#include "faction.h" #include "faction.h"
#include "race.h" #include "race.h"
#include "region.h" #include "region.h"
#include "skill.h" #include "skill.h"
#include "terrain.h"
#include "lighthouse.h" #include "lighthouse.h"
/* util includes */ /* util includes */
@ -52,6 +54,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <limits.h> #include <limits.h>
/* attributes includes */ /* attributes includes */
#include <attributes/reduceproduction.h>
#include <attributes/matmod.h> #include <attributes/matmod.h>
typedef struct building_typelist { typedef struct building_typelist {
@ -359,16 +362,6 @@ static int building_protection(const building * b, const unit * u, building_bonu
} }
} }
void register_buildings(void)
{
register_function((pf_generic)building_protection,
"building_protection");
register_function((pf_generic)init_smithy, "init_smithy");
register_function((pf_generic)castle_name, "castle_name");
register_function((pf_generic)castle_name_2, "castle_name_2");
register_function((pf_generic)fort_name, "fort_name");
}
void write_building_reference(const struct building *b, struct storage *store) void write_building_reference(const struct building *b, struct storage *store)
{ {
WRITE_INT(store, (b && b->region) ? b->no : 0); WRITE_INT(store, (b && b->region) ? b->no : 0);
@ -456,8 +449,8 @@ void remove_building(building ** blist, building * b)
update_lighthouse(b); update_lighthouse(b);
bunhash(b); bunhash(b);
/* Falls Karawanserei, Damm oder Tunnel einstürzen, wird die schon /* Falls Karawanserei, Damm oder Tunnel einst<EFBFBD>rzen, wird die schon
* gebaute Straße zur lfte vernichtet */ * gebaute Stra<EFBFBD>e zur H<EFBFBD>lfte vernichtet */
// TODO: caravan, tunnel, dam modularization ? is_building_type ? // TODO: caravan, tunnel, dam modularization ? is_building_type ?
if (b->type == bt_caravan || b->type == bt_dam || b->type == bt_tunnel) { if (b->type == bt_caravan || b->type == bt_dam || b->type == bt_tunnel) {
region *r = b->region; region *r = b->region;
@ -570,7 +563,7 @@ void building_set_owner(struct unit * owner)
static unit *building_owner_ex(const building * bld, const struct faction * last_owner) static unit *building_owner_ex(const building * bld, const struct faction * last_owner)
{ {
unit *u, *heir = 0; unit *u, *heir = 0;
/* Eigentümer tot oder kein Eigentümer vorhanden. Erste lebende Einheit /* Eigent<EFBFBD>mer tot oder kein Eigent<6E>mer vorhanden. Erste lebende Einheit
* nehmen. */ * nehmen. */
for (u = bld->region->units; u; u = u->next) { for (u = bld->region->units; u; u = u->next) {
if (u->building == bld) { if (u->building == bld) {
@ -702,3 +695,228 @@ bool is_building_type(const struct building_type *btype, const char *name) {
assert(btype); assert(btype);
return name && strcmp(btype->_name, name)==0; return name && strcmp(btype->_name, name)==0;
} }
building *largestbuilding(const region * r, cmp_building_cb cmp_gt,
bool imaginary)
{
building *b, *best = NULL;
for (b = rbuildings(r); b; b = b->next) {
if (cmp_gt(b, best) <= 0)
continue;
if (!imaginary) {
const attrib *a = a_find(b->attribs, &at_icastle);
if (a)
continue;
}
best = b;
}
return best;
}
/* Lohn bei den einzelnen Burgstufen f<>r Normale Typen, Orks, Bauern,
* Modifikation f<EFBFBD>r St<EFBFBD>dter. */
static const int wagetable[7][4] = {
{ 10, 10, 11, -7 }, /* Baustelle */
{ 10, 10, 11, -5 }, /* Handelsposten */
{ 11, 11, 12, -3 }, /* Befestigung */
{ 12, 11, 13, -1 }, /* Turm */
{ 13, 12, 14, 0 }, /* Burg */
{ 14, 12, 15, 1 }, /* Festung */
{ 15, 13, 16, 2 } /* Zitadelle */
};
static int
default_wage(const region * r, const faction * f, const race * rc, int in_turn)
{
building *b = largestbuilding(r, &cmp_wage, false);
int esize = 0;
double wage;
static int ct_cache;
static const struct curse_type *drought_ct;
if (ct_changed(&ct_cache)) {
drought_ct = ct_find("drought");
}
if (b != NULL) {
/* TODO: this reveals imaginary castles */
esize = buildingeffsize(b, false);
}
if (f != NULL) {
int index = 0;
if (rc == get_race(RC_ORC) || rc == get_race(RC_SNOTLING)) {
index = 1;
}
wage = wagetable[esize][index];
}
else {
if (is_mourning(r, in_turn)) {
wage = 10;
}
else if (fval(r->terrain, SEA_REGION)) {
wage = 11;
}
else {
wage = wagetable[esize][2];
}
if (rule_blessed_harvest() == HARVEST_WORK) {
/* E1 rules */
wage += curse_geteffect(get_curse(r->attribs, ct_find("blessedharvest")));
}
}
/* Artsculpture: Income +5 */
for (b = r->buildings; b; b = b->next) {
if (is_building_type(b->type, "artsculpture")) {
wage += 5;
}
}
if (r->attribs) {
attrib *a;
const struct curse_type *ctype;
/* Godcurse: Income -10 */
ctype = ct_find("godcursezone");
if (ctype && curse_active(get_curse(r->attribs, ctype))) {
wage = _max(0, wage - 10);
}
/* Bei einer D<>rre verdient man nur noch ein Viertel */
if (drought_ct) {
curse *c = get_curse(r->attribs, drought_ct);
if (curse_active(c))
wage /= curse_geteffect(c);
}
a = a_find(r->attribs, &at_reduceproduction);
if (a) {
wage = (wage * a->data.sa[0]) / 100;
}
}
return (int)wage;
}
static int
minimum_wage(const region * r, const faction * f, const race * rc, int in_turn)
{
if (f && rc) {
return rc->maintenance;
}
return default_wage(r, f, rc, in_turn);
}
/* Gibt Arbeitslohn f<>r entsprechende Rasse zur<75>ck, oder f<>r
* die Bauern wenn f == NULL. */
int wage(const region * r, const faction * f, const race * rc, int in_turn)
{
if (global.functions.wage) {
return global.functions.wage(r, f, rc, in_turn);
}
return default_wage(r, f, rc, in_turn);
}
int cmp_wage(const struct building *b, const building * a)
{
if (is_building_type(b->type, "castle")) {
if (!a)
return 1;
if (b->size > a->size)
return 1;
if (b->size == a->size)
return 0;
}
return -1;
}
bool is_owner_building(const struct building * b)
{
region *r = b->region;
if (b->type->taxes && r->land && r->land->ownership) {
unit *u = building_owner(b);
return u && u->faction == r->land->ownership->owner;
}
return false;
}
int cmp_taxes(const building * b, const building * a)
{
faction *f = region_get_owner(b->region);
if (b->type->taxes) {
unit *u = building_owner(b);
if (!u) {
return -1;
}
else if (a) {
int newsize = buildingeffsize(b, false);
double newtaxes = b->type->taxes(b, newsize);
int oldsize = buildingeffsize(a, false);
double oldtaxes = a->type->taxes(a, oldsize);
if (newtaxes < oldtaxes)
return -1;
else if (newtaxes > oldtaxes)
return 1;
else if (b->size < a->size)
return -1;
else if (b->size > a->size)
return 1;
else {
if (u && u->faction == f) {
u = building_owner(a);
if (u && u->faction == f)
return -1;
return 1;
}
}
}
else {
return 1;
}
}
return -1;
}
int cmp_current_owner(const building * b, const building * a)
{
faction *f = region_get_owner(b->region);
assert(rule_region_owners());
if (f && b->type->taxes) {
unit *u = building_owner(b);
if (!u || u->faction != f)
return -1;
if (a) {
int newsize = buildingeffsize(b, false);
double newtaxes = b->type->taxes(b, newsize);
int oldsize = buildingeffsize(a, false);
double oldtaxes = a->type->taxes(a, oldsize);
if (newtaxes > oldtaxes) {
return 1;
}
if (newtaxes < oldtaxes) {
return -1;
}
if (newsize != oldsize) {
return newsize - oldsize;
}
return (b->size - a->size);
}
else {
return 1;
}
}
return -1;
}
void register_buildings(void)
{
register_function((pf_generic)minimum_wage, "minimum_wage");
register_function((pf_generic)building_protection,
"building_protection");
register_function((pf_generic)init_smithy, "init_smithy");
register_function((pf_generic)castle_name, "castle_name");
register_function((pf_generic)castle_name_2, "castle_name_2");
register_function((pf_generic)fort_name, "fort_name");
}

View file

@ -60,8 +60,8 @@ extern "C" {
char *_name; char *_name;
int flags; /* flags */ int flags; /* flags */
int capacity; /* Kapazität pro Größenpunkt */ int capacity; /* Kapazit<EFBFBD>t pro Gr<47><72>enpunkt */
int maxcapacity; /* Max. Kapazität */ int maxcapacity; /* Max. Kapazit<EFBFBD>t */
int maxsize; /* how big can it get, with all the extensions? */ int maxsize; /* how big can it get, with all the extensions? */
int magres; /* how well it resists against spells */ int magres; /* how well it resists against spells */
int magresbonus; /* bonus it gives the target against spells */ int magresbonus; /* bonus it gives the target against spells */
@ -131,7 +131,17 @@ extern "C" {
int id, int size, struct order *ord); int id, int size, struct order *ord);
bool building_finished(const struct building *b); bool building_finished(const struct building *b);
/* Alte Gebäudetypen: */ int wage(const struct region *r, const struct faction *f,
const struct race *rc, int in_turn);
typedef int(*cmp_building_cb) (const struct building * b,
const struct building * a);
struct building *largestbuilding(const struct region *r, cmp_building_cb,
bool imaginary);
int cmp_wage(const struct building *b, const struct building *bother);
int cmp_taxes(const struct building *b, const struct building *bother);
int cmp_current_owner(const struct building *b,
const struct building *bother);
/* old functions, still in build.c: */ /* old functions, still in build.c: */
int buildingeffsize(const building * b, int imaginary); int buildingeffsize(const building * b, int imaginary);

View file

@ -405,8 +405,8 @@ static void test_buildingtype_exists(CuTest * tc)
r = findregion(-1, 0); r = findregion(-1, 0);
b = new_building(btype, r, default_locale); b = new_building(btype, r, default_locale);
b->size = 10;
CuAssertPtrNotNull(tc, b); CuAssertPtrNotNull(tc, b);
b->size = 10;
CuAssertTrue(tc, !buildingtype_exists(r, NULL, false)); CuAssertTrue(tc, !buildingtype_exists(r, NULL, false));
CuAssertTrue(tc, !buildingtype_exists(r, btype2, false)); CuAssertTrue(tc, !buildingtype_exists(r, btype2, false));

View file

@ -19,9 +19,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <platform.h> #include <platform.h>
#include <kernel/config.h> #include <kernel/config.h>
/* attributes includes */
#include <attributes/reduceproduction.h>
/* kernel includes */ /* kernel includes */
#include "alliance.h" #include "alliance.h"
#include "ally.h" #include "ally.h"
@ -183,18 +180,6 @@ parse(keyword_t kword, int(*dofun) (unit *, struct order *), bool thisorder)
} }
} }
const struct race *findrace(const char *s, const struct locale *lang)
{
void **tokens = get_translations(lang, UT_RACES);
variant token;
assert(lang);
if (tokens && findtoken(*tokens, s, &token) == E_TOK_SUCCESS) {
return (const struct race *)token.v;
}
return NULL;
}
int findoption(const char *s, const struct locale *lang) int findoption(const char *s, const struct locale *lang)
{ {
void **tokens = get_translations(lang, UT_OPTIONS); void **tokens = get_translations(lang, UT_OPTIONS);
@ -265,37 +250,6 @@ unit *getnewunit(const region * r, const faction * f)
return findnewunit(r, f, n); return findnewunit(r, f, n);
} }
/* - Namen der Strukturen -------------------------------------- */
char *untilde(char *ibuf)
{
char *p = ibuf;
while (*p) {
if (*p == '~') {
*p = ' ';
}
++p;
}
return ibuf;
}
building *largestbuilding(const region * r, cmp_building_cb cmp_gt,
bool imaginary)
{
building *b, *best = NULL;
for (b = rbuildings(r); b; b = b->next) {
if (cmp_gt(b, best) <= 0)
continue;
if (!imaginary) {
const attrib *a = a_find(b->attribs, &at_icastle);
if (a)
continue;
}
best = b;
}
return best;
}
/* -- Erschaffung neuer Einheiten ------------------------------ */ /* -- Erschaffung neuer Einheiten ------------------------------ */
@ -652,108 +606,6 @@ char *_strdup(const char *s)
} }
#endif #endif
/* Lohn bei den einzelnen Burgstufen f<>r Normale Typen, Orks, Bauern,
* Modifikation f<EFBFBD>r St<EFBFBD>dter. */
static const int wagetable[7][4] = {
{ 10, 10, 11, -7 }, /* Baustelle */
{ 10, 10, 11, -5 }, /* Handelsposten */
{ 11, 11, 12, -3 }, /* Befestigung */
{ 12, 11, 13, -1 }, /* Turm */
{ 13, 12, 14, 0 }, /* Burg */
{ 14, 12, 15, 1 }, /* Festung */
{ 15, 13, 16, 2 } /* Zitadelle */
};
int cmp_wage(const struct building *b, const building * a)
{
if (is_building_type(b->type, "castle")) {
if (!a)
return 1;
if (b->size > a->size)
return 1;
if (b->size == a->size)
return 0;
}
return -1;
}
bool is_owner_building(const struct building * b)
{
region *r = b->region;
if (b->type->taxes && r->land && r->land->ownership) {
unit *u = building_owner(b);
return u && u->faction == r->land->ownership->owner;
}
return false;
}
int cmp_taxes(const building * b, const building * a)
{
faction *f = region_get_owner(b->region);
if (b->type->taxes) {
unit *u = building_owner(b);
if (!u) {
return -1;
}
else if (a) {
int newsize = buildingeffsize(b, false);
double newtaxes = b->type->taxes(b, newsize);
int oldsize = buildingeffsize(a, false);
double oldtaxes = a->type->taxes(a, oldsize);
if (newtaxes < oldtaxes)
return -1;
else if (newtaxes > oldtaxes)
return 1;
else if (b->size < a->size)
return -1;
else if (b->size > a->size)
return 1;
else {
if (u && u->faction == f) {
u = building_owner(a);
if (u && u->faction == f)
return -1;
return 1;
}
}
}
else {
return 1;
}
}
return -1;
}
int cmp_current_owner(const building * b, const building * a)
{
faction *f = region_get_owner(b->region);
assert(rule_region_owners());
if (f && b->type->taxes) {
unit *u = building_owner(b);
if (!u || u->faction != f)
return -1;
if (a) {
int newsize = buildingeffsize(b, false);
double newtaxes = b->type->taxes(b, newsize);
int oldsize = buildingeffsize(a, false);
double oldtaxes = a->type->taxes(a, oldsize);
if (newtaxes != oldtaxes)
return (newtaxes > oldtaxes) ? 1 : -1;
if (newsize != oldsize)
return newsize - oldsize;
return (b->size - a->size);
}
else {
return 1;
}
}
return -1;
}
bool rule_stealth_other(void) bool rule_stealth_other(void)
{ {
static int rule, config; static int rule, config;
@ -814,102 +666,11 @@ int rule_faction_limit(void)
return rule; return rule;
} }
static int
default_wage(const region * r, const faction * f, const race * rc, int in_turn)
{
building *b = largestbuilding(r, &cmp_wage, false);
int esize = 0;
double wage;
static int ct_cache;
static const struct curse_type *drought_ct;
if (ct_changed(&ct_cache)) {
drought_ct = ct_find("drought");
}
if (b != NULL) {
/* TODO: this reveals imaginary castles */
esize = buildingeffsize(b, false);
}
if (f != NULL) {
int index = 0;
if (rc == get_race(RC_ORC) || rc == get_race(RC_SNOTLING)) {
index = 1;
}
wage = wagetable[esize][index];
}
else {
if (is_mourning(r, in_turn)) {
wage = 10;
}
else if (fval(r->terrain, SEA_REGION)) {
wage = 11;
}
else {
wage = wagetable[esize][2];
}
if (rule_blessed_harvest() == HARVEST_WORK) {
/* E1 rules */
wage += curse_geteffect(get_curse(r->attribs, ct_find("blessedharvest")));
}
}
/* Artsculpture: Income +5 */
for (b = r->buildings; b; b = b->next) {
if (is_building_type(b->type, "artsculpture")) {
wage += 5;
}
}
if (r->attribs) {
attrib *a;
const struct curse_type *ctype;
/* Godcurse: Income -10 */
ctype = ct_find("godcursezone");
if (ctype && curse_active(get_curse(r->attribs, ctype))) {
wage = _max(0, wage - 10);
}
/* Bei einer D<>rre verdient man nur noch ein Viertel */
if (drought_ct) {
curse *c = get_curse(r->attribs, drought_ct);
if (curse_active(c))
wage /= curse_geteffect(c);
}
a = a_find(r->attribs, &at_reduceproduction);
if (a) {
wage = (wage * a->data.sa[0]) / 100;
}
}
return (int)wage;
}
static int
minimum_wage(const region * r, const faction * f, const race * rc, int in_turn)
{
if (f && rc) {
return rc->maintenance;
}
return default_wage(r, f, rc, in_turn);
}
/* Gibt Arbeitslohn f<>r entsprechende Rasse zur<75>ck, oder f<>r
* die Bauern wenn f == NULL. */
int wage(const region * r, const faction * f, const race * rc, int in_turn)
{
if (global.functions.wage) {
return global.functions.wage(r, f, rc, in_turn);
}
return default_wage(r, f, rc, in_turn);
}
void kernel_init(void) void kernel_init(void)
{ {
register_reports(); register_reports();
mt_clear(); mt_clear();
translation_init(); translation_init();
register_function((pf_generic)minimum_wage, "minimum_wage");
} }
static order * defaults[MAXLOCALES]; static order * defaults[MAXLOCALES];
@ -936,23 +697,6 @@ order *default_order(const struct locale *lang)
return result ? copy_order(result) : 0; return result ? copy_order(result) : 0;
} }
int entertainmoney(const region * r)
{
double n;
if (is_cursed(r->attribs, C_DEPRESSION, 0)) {
return 0;
}
n = rmoney(r) / ENTERTAINFRACTION;
if (is_cursed(r->attribs, C_GENEROUS, 0)) {
n *= get_curseeffect(r->attribs, C_GENEROUS, 0);
}
return (int)n;
}
int rule_give(void) int rule_give(void)
{ {
static int config; static int config;

View file

@ -54,17 +54,6 @@ struct param;
int forbiddenid(int id); int forbiddenid(int id);
int newcontainerid(void); int newcontainerid(void);
char *untilde(char *s);
typedef int(*cmp_building_cb) (const struct building * b,
const struct building * a);
struct building *largestbuilding(const struct region *r, cmp_building_cb,
bool imaginary);
int cmp_wage(const struct building *b, const struct building *bother);
int cmp_taxes(const struct building *b, const struct building *bother);
int cmp_current_owner(const struct building *b,
const struct building *bother);
bool rule_region_owners(void); bool rule_region_owners(void);
bool rule_stealth_other(void); // units can pretend to be another faction, TARNE PARTEI <no> bool rule_stealth_other(void); // units can pretend to be another faction, TARNE PARTEI <no>
bool rule_stealth_anon(void); // units can anonymize their faction, TARNE PARTEI [NICHT] bool rule_stealth_anon(void); // units can anonymize their faction, TARNE PARTEI [NICHT]
@ -83,8 +72,6 @@ struct param;
#define GIVE_DEFAULT (GIVE_SELF|GIVE_PEASANTS|GIVE_LUXURIES|GIVE_HERBS|GIVE_GOODS) #define GIVE_DEFAULT (GIVE_SELF|GIVE_PEASANTS|GIVE_LUXURIES|GIVE_HERBS|GIVE_GOODS)
int rule_give(void); int rule_give(void);
const struct race *findrace(const char *, const struct locale *);
/* grammatik-flags: */ /* grammatik-flags: */
#define GF_NONE 0 #define GF_NONE 0
/* singular, ohne was dran */ /* singular, ohne was dran */
@ -99,9 +86,6 @@ struct param;
#define GF_PURE 64 #define GF_PURE 64
/* untranslated */ /* untranslated */
int wage(const struct region *r, const struct faction *f,
const struct race *rc, int in_turn);
const char *datapath(void); const char *datapath(void);
void set_datapath(const char *path); void set_datapath(const char *path);
@ -147,7 +131,6 @@ struct param;
struct order *default_order(const struct locale *lang); struct order *default_order(const struct locale *lang);
int entertainmoney(const struct region *r);
void init_parameters(struct locale *lang); void init_parameters(struct locale *lang);
void free_gamedata(void); void free_gamedata(void);

View file

@ -825,7 +825,7 @@ double destr_curse(curse * c, int cast_level, double force)
c->type->change_vigour(c, -(cast_level + 1) / 2); c->type->change_vigour(c, -(cast_level + 1) / 2);
} }
else { else {
c->vigour -= cast_level + 1 / 2; c->vigour -= (cast_level + 1) / 2.0;
} }
} }
} }

View file

@ -827,7 +827,7 @@ int writepasswd(void)
log_info("writing passwords..."); log_info("writing passwords...");
for (f = factions; f; f = f->next) { for (f = factions; f; f = f->next) {
fprintf(F, "%s:%s:%s:%u\n", fprintf(F, "%s:%s:%s:%d\n",
itoa36(f->no), f->email, f->_password, f->subscription); itoa36(f->no), f->email, f->_password, f->subscription);
} }
fclose(F); fclose(F);

View file

@ -82,7 +82,7 @@ static void test_group_readwrite(CuTest * tc)
mstream_init(&data.strm); mstream_init(&data.strm);
gamedata_init(&data, &store, RELEASE_VERSION); gamedata_init(&data, &store, RELEASE_VERSION);
f = test_create_faction(0); f = test_create_faction(0);
g = new_group(f, "NW", 42); new_group(f, "NW", 42);
g = new_group(f, "Egoisten", 43); g = new_group(f, "Egoisten", 43);
key_set(&g->attribs, 44); key_set(&g->attribs, 44);
al = ally_add(&g->allies, f); al = ally_add(&g->allies, f);

View file

@ -239,7 +239,6 @@ item_type *it_get_or_create(resource_type *rtype) {
item_type * itype; item_type * itype;
assert(rtype); assert(rtype);
itype = it_find(rtype->_name); itype = it_find(rtype->_name);
assert(!itype || !itype->rtype || itype->rtype == rtype);
if (!itype) { if (!itype) {
itype = (item_type *)calloc(sizeof(item_type), 1); itype = (item_type *)calloc(sizeof(item_type), 1);
} }
@ -973,7 +972,7 @@ void init_resources(void)
{ {
resource_type *rtype; resource_type *rtype;
rtype = rt_get_or_create(resourcenames[R_PERSON]); // lousy hack rt_get_or_create(resourcenames[R_PERSON]); // lousy hack
rtype = rt_get_or_create(resourcenames[R_PEASANT]); rtype = rt_get_or_create(resourcenames[R_PEASANT]);
rtype->uchange = res_changepeasants; rtype->uchange = res_changepeasants;
@ -1204,7 +1203,7 @@ void read_items(struct storage *store, item ** ilist)
itype = it_find(ibuf); itype = it_find(ibuf);
READ_INT(store, &i); READ_INT(store, &i);
if (i <= 0) { if (i <= 0) {
log_error("data contains an entry with %d %s", i, resourcename(itype->rtype, NMF_PLURAL)); log_error("data contains an entry with %d %s", i, ibuf);
} }
else { else {
if (itype && itype->rtype) { if (itype && itype->rtype) {

View file

@ -179,7 +179,7 @@ int count)
if (u != v && (v->items || rtype->uget)) { if (u != v && (v->items || rtype->uget)) {
int mask; int mask;
if ((urace(v)->ec_flags & ECF_KEEP_ITEM)) if ((u_race(v)->ec_flags & ECF_KEEP_ITEM))
continue; continue;
if (v->faction == f) { if (v->faction == f) {
@ -232,7 +232,7 @@ use_pooled(unit * u, const resource_type * rtype, unsigned int mode, int count)
for (v = r->units; use > 0 && v != NULL; v = v->next) { for (v = r->units; use > 0 && v != NULL; v = v->next) {
if (u != v) { if (u != v) {
int mask; int mask;
if ((urace(v)->ec_flags & ECF_KEEP_ITEM)) if ((u_race(v)->ec_flags & ECF_KEEP_ITEM))
continue; continue;
if (v->items == NULL && rtype->uget == NULL) if (v->items == NULL && rtype->uget == NULL)
continue; continue;

View file

@ -39,6 +39,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <util/attrib.h> #include <util/attrib.h>
#include <util/bsdstring.h> #include <util/bsdstring.h>
#include <util/functions.h> #include <util/functions.h>
#include <util/umlaut.h>
#include <util/language.h> #include <util/language.h>
#include <util/log.h> #include <util/log.h>
#include <util/rng.h> #include <util/rng.h>
@ -75,6 +76,18 @@ static const char *racenames[MAXRACES] = {
"clone" "clone"
}; };
const struct race *findrace(const char *s, const struct locale *lang)
{
void **tokens = get_translations(lang, UT_RACES);
variant token;
assert(lang);
if (tokens && findtoken(*tokens, s, &token) == E_TOK_SUCCESS) {
return (const struct race *)token.v;
}
return NULL;
}
const struct race *get_race(race_t rt) { const struct race *get_race(race_t rt) {
const char * name; const char * name;

View file

@ -44,6 +44,7 @@ extern "C" {
struct param; struct param;
struct spell; struct spell;
struct locale;
extern int num_races; extern int num_races;
@ -163,6 +164,7 @@ extern "C" {
void racelist_clear(struct race_list **rl); void racelist_clear(struct race_list **rl);
void racelist_insert(struct race_list **rl, const struct race *r); void racelist_insert(struct race_list **rl, const struct race *r);
const struct race *findrace(const char *, const struct locale *);
struct race_list *get_familiarraces(void); struct race_list *get_familiarraces(void);
struct race *races; struct race *races;

View file

@ -46,7 +46,7 @@ extern int dice_rand(const char *s);
static void update_resource(struct rawmaterial *res, double modifier) static void update_resource(struct rawmaterial *res, double modifier)
{ {
double amount = 1 + (res->level - res->startlevel) * res->divisor / 100.0; double amount = (res->level - res->startlevel) / 100.0 * res->divisor + 1;
amount = ResourceFactor() * res->base * amount * modifier; amount = ResourceFactor() * res->base * amount * modifier;
if (amount < 1.0) if (amount < 1.0)
res->amount = 1; res->amount = 1;

View file

@ -917,11 +917,6 @@ bool leave(unit * u, bool force)
return true; return true;
} }
const struct race *urace(const struct unit *u)
{
return u->_race;
}
bool can_survive(const unit * u, const region * r) bool can_survive(const unit * u, const region * r)
{ {
if ((fval(r->terrain, WALK_INTO) && (u_race(u)->flags & RCF_WALK)) if ((fval(r->terrain, WALK_INTO) && (u_race(u)->flags & RCF_WALK))

View file

@ -141,8 +141,6 @@ extern "C" {
struct unit *utarget(const struct unit *u); struct unit *utarget(const struct unit *u);
void usettarget(struct unit *u, const struct unit *b); void usettarget(struct unit *u, const struct unit *b);
extern const struct race *urace(const struct unit *u);
const char *uprivate(const struct unit *u); const char *uprivate(const struct unit *u);
void usetprivate(struct unit *u, const char *c); void usetprivate(struct unit *u, const char *c);

View file

@ -648,7 +648,7 @@ growing_trees(region * r, const int current_season, const int last_weeks_season)
* verfügbaren Fläche ab. In Gletschern gibt es weniger * verfügbaren Fläche ab. In Gletschern gibt es weniger
* Möglichkeiten als in Ebenen. */ * Möglichkeiten als in Ebenen. */
sprout = 0; sprout = 0;
seedchance = (1000 * region_maxworkers(r2)) / r2->terrain->size; seedchance = (1000.0 * region_maxworkers(r2)) / r2->terrain->size;
for (i = 0; i < seeds / MAXDIRECTIONS; i++) { for (i = 0; i < seeds / MAXDIRECTIONS; i++) {
if (rng_int() % 10000 < seedchance) if (rng_int() % 10000 < seedchance)
sprout++; sprout++;
@ -1269,7 +1269,6 @@ static void remove_idle_players(void)
} else { } else {
if (fval(f, FFL_NOIDLEOUT)) { if (fval(f, FFL_NOIDLEOUT)) {
f->lastorders = turn; f->lastorders = turn;
fp = &f->next;
} }
else if (turn != f->lastorders) { else if (turn != f->lastorders) {
char info[256]; char info[256];
@ -2997,7 +2996,7 @@ static void ageing(void)
a_age(&u->attribs, u); a_age(&u->attribs, u);
if (u == *up) if (u == *up)
handle_event(u->attribs, "timer", u); handle_event(u->attribs, "timer", u);
if (u == *up) if (u == *up) //-V581
up = &(*up)->next; up = &(*up)->next;
} }
@ -3007,7 +3006,7 @@ static void ageing(void)
a_age(&s->attribs, s); a_age(&s->attribs, s);
if (s == *sp) if (s == *sp)
handle_event(s->attribs, "timer", s); handle_event(s->attribs, "timer", s);
if (s == *sp) if (s == *sp) //-V581
sp = &(*sp)->next; sp = &(*sp)->next;
} }
@ -3636,7 +3635,7 @@ int pay_cmd(unit * u, struct order *ord)
static int reserve_i(unit * u, struct order *ord, int flags) static int reserve_i(unit * u, struct order *ord, int flags)
{ {
char token[128]; char token[128];
if (u->number > 0 && (urace(u)->ec_flags & GETITEM)) { if (u->number > 0 && (u_race(u)->ec_flags & GETITEM)) {
int use, count, para; int use, count, para;
const item_type *itype; const item_type *itype;
const char *s; const char *s;
@ -3945,7 +3944,7 @@ int armedmen(const unit * u, bool siege_weapons)
{ {
item *itm; item *itm;
int n = 0; int n = 0;
if (!(urace(u)->flags & RCF_NOWEAPONS)) { if (!(u_race(u)->flags & RCF_NOWEAPONS)) {
if (effskill(u, SK_WEAPONLESS, 0) >= 1) { if (effskill(u, SK_WEAPONLESS, 0) >= 1) {
/* kann ohne waffen bewachen: fuer drachen */ /* kann ohne waffen bewachen: fuer drachen */
n = u->number; n = u->number;

View file

@ -173,7 +173,7 @@ static void a_initicastle(struct attrib *a)
a->data.v = calloc(sizeof(icastle_data), 1); a->data.v = calloc(sizeof(icastle_data), 1);
} }
static void a_finalizeicastle(struct attrib *a) static void a_finalizeicastle(struct attrib *a) //-V524
{ {
free(a->data.v); free(a->data.v);
} }

View file

@ -19,7 +19,6 @@
#include <items/demonseye.h> #include <items/demonseye.h>
#include <attributes/key.h> #include <attributes/key.h>
#include <triggers/gate.h> #include <triggers/gate.h>
#include <triggers/unguard.h>
/* kernel includes */ /* kernel includes */
#include <kernel/building.h> #include <kernel/building.h>

View file

@ -76,17 +76,13 @@ bool monster_is_waiting(const unit * u)
static void eaten_by_monster(unit * u) static void eaten_by_monster(unit * u)
{ {
/* adjustment for smaller worlds */ /* adjustment for smaller worlds */
static double multi = 0.0; double multi = RESOURCE_QUANTITY * newterrain(T_PLAIN)->size / 10000.0;
int n = 0; int n = 0;
int horse = -1; int horse = -1;
const resource_type *rhorse = get_resourcetype(R_HORSE); const resource_type *rhorse = get_resourcetype(R_HORSE);
const race *rc = u_race(u); const race *rc = u_race(u);
attrib *a; attrib *a;
if (multi == 0.0) {
multi = RESOURCE_QUANTITY * newterrain(T_PLAIN)->size / 10000.0;
}
a = a_find(rc->attribs, &at_scare); a = a_find(rc->attribs, &at_scare);
if (a) { if (a) {
n = rng_int() & a->data.i * u->number; n = rng_int() & a->data.i * u->number;

View file

@ -695,7 +695,7 @@ static order *plan_dragon(unit * u)
int attempts = 0; int attempts = 0;
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) || (attempts < MAXSKILLS && u_race(u)->bonus[sk] < (++attempts < 10?1:-5 )))) { while (!skill_enabled(sk) || (attempts < MAXSKILLS && u_race(u)->bonus[sk] < (++attempts < 10?1:-5 ))) {
sk = (skill_t)(rng_int() % MAXSKILLS); sk = (skill_t)(rng_int() % MAXSKILLS);
} }
long_order = create_order(K_STUDY, u->faction->locale, "'%s'", long_order = create_order(K_STUDY, u->faction->locale, "'%s'",

View file

@ -1,6 +1,8 @@
#include <platform.h> #include <platform.h>
#include "prefix.h" #include "prefix.h"
#include <util/log.h>
#include <assert.h> #include <assert.h>
#include <stddef.h> #include <stddef.h>
#include <stdlib.h> #include <stdlib.h>
@ -10,7 +12,7 @@ char **race_prefixes = NULL;
static size_t size = 4; static size_t size = 4;
static unsigned int next = 0; static unsigned int next = 0;
void add_raceprefix(const char *prefix) int add_raceprefix(const char *prefix)
{ {
assert(prefix); assert(prefix);
if (race_prefixes == NULL) { if (race_prefixes == NULL) {
@ -19,11 +21,18 @@ void add_raceprefix(const char *prefix)
race_prefixes = malloc(size * sizeof(char *)); race_prefixes = malloc(size * sizeof(char *));
} }
if (next + 1 == size) { if (next + 1 == size) {
char **tmp;
tmp = realloc(race_prefixes, 2 * size * sizeof(char *));
if (!tmp) {
log_fatal("allocation failure");
return 1;
}
race_prefixes = tmp;
size *= 2; size *= 2;
race_prefixes = realloc(race_prefixes, size * sizeof(char *));
} }
race_prefixes[next++] = _strdup(prefix); race_prefixes[next++] = _strdup(prefix);
race_prefixes[next] = NULL; race_prefixes[next] = NULL;
return 0;
} }
void free_prefixes(void) { void free_prefixes(void) {

View file

@ -7,7 +7,7 @@
extern "C" { extern "C" {
#endif #endif
void add_raceprefix(const char *); int add_raceprefix(const char *);
char **race_prefixes; // zero-terminated array of valid prefixes char **race_prefixes; // zero-terminated array of valid prefixes
void free_prefixes(void); void free_prefixes(void);

View file

@ -8,11 +8,11 @@
static void test_add_prefix(CuTest *tc) { static void test_add_prefix(CuTest *tc) {
test_setup(); test_setup();
CuAssertPtrEquals(tc, 0, race_prefixes); CuAssertPtrEquals(tc, 0, race_prefixes);
add_raceprefix("sea"); CuAssertIntEquals(tc, 0, add_raceprefix("sea"));
CuAssertPtrNotNull(tc, race_prefixes); CuAssertPtrNotNull(tc, race_prefixes);
CuAssertStrEquals(tc, "sea", race_prefixes[0]); CuAssertStrEquals(tc, "sea", race_prefixes[0]);
CuAssertPtrEquals(tc, 0, race_prefixes[1]); CuAssertPtrEquals(tc, 0, race_prefixes[1]);
add_raceprefix("moon"); CuAssertIntEquals(tc, 0, add_raceprefix("moon"));
CuAssertStrEquals(tc, "sea", race_prefixes[0]); CuAssertStrEquals(tc, "sea", race_prefixes[0]);
CuAssertStrEquals(tc, "moon", race_prefixes[1]); CuAssertStrEquals(tc, "moon", race_prefixes[1]);
CuAssertPtrEquals(tc, 0, race_prefixes[2]); CuAssertPtrEquals(tc, 0, race_prefixes[2]);

View file

@ -69,7 +69,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
extern struct attrib_type at_unitdissolve; extern struct attrib_type at_unitdissolve;
/* In a->data.ca[1] steht der Prozentsatz mit dem sich die Einheit /* In a->data.ca[1] steht der Prozentsatz mit dem sich die Einheit
* auflöst, in a->data.ca[0] kann angegeben werden, wohin die Personen * aufl<EFBFBD>st, in a->data.ca[0] kann angegeben werden, wohin die Personen
* verschwinden. Passiert bereits in der ersten Runde! */ * verschwinden. Passiert bereits in der ersten Runde! */
static void dissolve_units(void) static void dissolve_units(void)
{ {
@ -442,12 +442,12 @@ static void melt_iceberg(region * r)
ADDMSG(&u->faction->msgs, msg_message("iceberg_melt", "region", r)); ADDMSG(&u->faction->msgs, msg_message("iceberg_melt", "region", r));
} }
/* driftrichtung löschen */ /* driftrichtung l<EFBFBD>schen */
a = a_find(r->attribs, &at_iceberg); a = a_find(r->attribs, &at_iceberg);
if (a) if (a)
a_remove(&r->attribs, a); a_remove(&r->attribs, a);
/* Gebäude löschen */ /* Geb<EFBFBD>ude l<>schen */
while (r->buildings) { while (r->buildings) {
remove_building(&r->buildings, r->buildings); remove_building(&r->buildings, r->buildings);
} }
@ -455,7 +455,7 @@ static void melt_iceberg(region * r)
/* in Ozean wandeln */ /* in Ozean wandeln */
terraform_region(r, newterrain(T_OCEAN)); terraform_region(r, newterrain(T_OCEAN));
/* Einheiten, die nicht schwimmen können oder in Schiffen sind, /* Einheiten, die nicht schwimmen k<EFBFBD>nnen oder in Schiffen sind,
* ertrinken */ * ertrinken */
drown(r); drown(r);
} }
@ -519,13 +519,13 @@ static void move_iceberg(region * r)
freset(sh, SF_SELECT); freset(sh, SF_SELECT);
for (sh = r->ships; sh; sh = sh->next) { for (sh = r->ships; sh; sh = sh->next) {
/* Meldung an Kapitän */ /* Meldung an Kapit<EFBFBD>n */
double dmg = config_get_flt("rules.ship.damage.intoiceberg", 0.1); double dmg = config_get_flt("rules.ship.damage.intoiceberg", 0.1);
damage_ship(sh, dmg); damage_ship(sh, dmg);
fset(sh, SF_SELECT); fset(sh, SF_SELECT);
} }
/* Personen, Schiffe und Gebäude verschieben */ /* Personen, Schiffe und Geb<EFBFBD>ude verschieben */
while (rc->buildings) { while (rc->buildings) {
rc->buildings->region = r; rc->buildings->region = r;
translist(&rc->buildings, &r->buildings, rc->buildings); translist(&rc->buildings, &r->buildings, rc->buildings);
@ -544,7 +544,7 @@ static void move_iceberg(region * r)
u_set_building(u, b); /* undo leave-prevention */ u_set_building(u, b); /* undo leave-prevention */
} }
/* Beschädigte Schiffe können sinken */ /* Besch<EFBFBD>digte Schiffe k<>nnen sinken */
for (sh = r->ships; sh;) { for (sh = r->ships; sh;) {
shn = sh->next; shn = sh->next;
@ -725,7 +725,7 @@ static void orc_growth(void)
} }
} }
/** Talente von Dämonen verschieben sich. /** Talente von D<EFBFBD>monen verschieben sich.
*/ */
static void demon_skillchanges(void) static void demon_skillchanges(void)
{ {
@ -760,7 +760,7 @@ static void icebergs(void)
} }
#define HERBS_ROT /* herbs owned by units have a chance to rot. */ #define HERBS_ROT /* herbs owned by units have a chance to rot. */
#define HERBROTCHANCE 5 /* Verrottchance für Kräuter (ifdef HERBS_ROT) */ #define HERBROTCHANCE 5 /* Verrottchance f<EFBFBD>r Kr<4B>uter (ifdef HERBS_ROT) */
#ifdef HERBS_ROT #ifdef HERBS_ROT
static void rotting_herbs(void) static void rotting_herbs(void)
{ {

View file

@ -915,14 +915,16 @@ static void describe(struct stream *out, const region * r, faction * f)
bool transparent = b->type->transparent(b, f); bool transparent = b->type->transparent(b, f);
const char *name = border_name(b, r, f, GF_DETAILED | GF_ARTICLE); const char *name = border_name(b, r, f, GF_DETAILED | GF_ARTICLE);
if (!transparent) if (!transparent) {
see[d] = false; see[d] = false;
}
if (!see_border(b, f, r)) { if (!see_border(b, f, r)) {
b = b->next; b = b->next;
continue; continue;
} }
while (e && (e->transparent != transparent || strcmp(name, e->name))) while (e && (e->transparent != transparent || strcmp(name, e->name)!=0)) {
e = e->next; e = e->next;
}
if (!e) { if (!e) {
e = calloc(sizeof(struct edge), 1); e = calloc(sizeof(struct edge), 1);
e->name = _strdup(name); e->name = _strdup(name);
@ -1730,7 +1732,7 @@ static void rpline(struct stream *out)
memset(line, '-', sizeof(line)); memset(line, '-', sizeof(line));
line[REPORTWIDTH] = '\n'; line[REPORTWIDTH] = '\n';
} }
swrite(line, sizeof(char), sizeof(line), out); swrite(line, sizeof(line), 1, out);
} }
static void list_address(struct stream *out, const faction * uf, quicklist * seenfactions) static void list_address(struct stream *out, const faction * uf, quicklist * seenfactions)
@ -2248,10 +2250,8 @@ report_plaintext(const char *filename, report_context * ctx,
*bufp = 0; *bufp = 0;
centre(out, buf, true); centre(out, buf, true);
newline(out); newline(out);
if (description == NULL) { description = mkname("potion", pname);
const char *potiontext = mkname("potion", pname); description = LOC(f->locale, description);
description = LOC(f->locale, potiontext);
}
centre(out, description, true); centre(out, description, true);
} }
} }

View file

@ -720,7 +720,7 @@ size_t size)
} }
} }
if (!isbattle) { if (!isbattle) {
bool printed = 0; int printed = 0;
order *ord;; order *ord;;
for (ord = u->old_orders; ord; ord = ord->next) { for (ord = u->old_orders; ord; ord = ord->next) {
keyword_t kwd = getkeyword(ord); keyword_t kwd = getkeyword(ord);
@ -1587,7 +1587,7 @@ static void var_free_resources(variant x)
x.v = 0; x.v = 0;
} }
static void var_free_regions(variant x) static void var_free_regions(variant x) //-V524
{ {
free(x.v); free(x.v);
} }
@ -1716,18 +1716,6 @@ static void eval_curse(struct opstack **stack, const void *userdata)
opush(stack, var); opush(stack, var);
} }
static void eval_unitname(struct opstack **stack, const void *userdata)
{ /* unit -> string */
const struct faction *f = (const struct faction *)userdata;
const struct unit *u = (const struct unit *)opop(stack).v;
const char *c = u ? unit_getname(u) : LOC(f->locale, "an_unknown_unit");
size_t len = strlen(c);
variant var;
var.v = strcpy(balloc(len + 1), c);
opush(stack, var);
}
static void eval_unitid(struct opstack **stack, const void *userdata) static void eval_unitid(struct opstack **stack, const void *userdata)
{ /* unit -> int */ { /* unit -> int */
const struct faction *f = (const struct faction *)userdata; const struct faction *f = (const struct faction *)userdata;
@ -1836,16 +1824,16 @@ static void eval_weight(struct opstack **stack, const void *userdata)
sprintf(buffer, "1 %s", LOC(lang, "weight_unit")); sprintf(buffer, "1 %s", LOC(lang, "weight_unit"));
} }
else { else {
sprintf(buffer, "%u %s", weight / SCALEWEIGHT, LOC(lang, sprintf(buffer, "%d %s", weight / SCALEWEIGHT, LOC(lang,
"weight_unit_p")); "weight_unit_p"));
} }
} }
else { else {
if (weight == 1) { if (weight == 1) {
sprintf(buffer, "1 %s %u", LOC(lang, "weight_per"), SCALEWEIGHT); sprintf(buffer, "1 %s %d", LOC(lang, "weight_per"), SCALEWEIGHT);
} }
else { else {
sprintf(buffer, "%u %s %u", weight, LOC(lang, "weight_per_p"), sprintf(buffer, "%d %s %d", weight, LOC(lang, "weight_per_p"),
SCALEWEIGHT); SCALEWEIGHT);
} }
} }
@ -2136,7 +2124,6 @@ void register_reports(void)
add_function("ship", &eval_ship); add_function("ship", &eval_ship);
add_function("unit", &eval_unit); add_function("unit", &eval_unit);
add_function("unit.dative", &eval_unit_dative); add_function("unit.dative", &eval_unit_dative);
add_function("unit.name", &eval_unitname);
add_function("unit.id", &eval_unitid); add_function("unit.id", &eval_unitid);
add_function("unit.size", &eval_unitsize); add_function("unit.size", &eval_unitsize);
add_function("building", &eval_building); add_function("building", &eval_building);

View file

@ -20,7 +20,7 @@
#undef NEWATSROI #undef NEWATSROI
/* Vermehrungsrate Bauern in 1/10000. /* Vermehrungsrate Bauern in 1/10000.
* TODO: Evt. Berechnungsfehler, reale Vermehrungsraten scheinen höher. */ * TODO: Evt. Berechnungsfehler, reale Vermehrungsraten scheinen hoeher. */
#define PEASANTGROWTH 10 #define PEASANTGROWTH 10
#define PEASANTLUCK 10 #define PEASANTLUCK 10
@ -37,22 +37,21 @@
/* experimental gameplay features (that don't affect the savefile) */ /* experimental gameplay features (that don't affect the savefile) */
/* TODO: move these settings to settings.h or into configuration files */ /* TODO: move these settings to settings.h or into configuration files */
#define GOBLINKILL /* Goblin-Spezialklau kann tödlich enden */ #define GOBLINKILL /* Goblin-Spezialklau kann toedlich enden */
#define INSECT_POTION /* Spezialtrank für Insekten */ #define INSECT_POTION /* Spezialtrank fuer Insekten */
#define ORCIFICATION /* giving snotlings to the peasants gets counted */
#define TREESIZE (8) /* space used by trees (in #peasants) */ #define TREESIZE (8) /* space used by trees (in #peasants) */
#define PEASANTFORCE 0.75 /* Chance einer Vermehrung trotz 90% Auslastung */ #define PEASANTFORCE 0.75 /* Chance einer Vermehrung trotz 90% Auslastung */
/* Gebäudegröße = Minimalbelagerer */ /* Gebaeudegroesse = Minimalbelagerer */
#define SIEGEFACTOR 2 #define SIEGEFACTOR 2
/** Magic */ /** Magic */
#define MAXMAGICIANS 3 #define MAXMAGICIANS 3
#define MAXALCHEMISTS 3 #define MAXALCHEMISTS 3
#define ENCCHANCE 10 /* %-Chance für einmalige Zufallsbegegnung */ #define ENCCHANCE 10 /* %-Chance fuer einmalige Zufallsbegegnung */
#define BAGCAPACITY 20000 /* soviel paßt in einen Bag of Holding */ #define BAGCAPACITY 20000 /* soviel passt in einen Bag of Holding */
#define PERSON_WEIGHT 1000 /* weight of a "normal" human unit */ #define PERSON_WEIGHT 1000 /* weight of a "normal" human unit */
#define STAMINA_AFFECTS_HP 1<<0 #define STAMINA_AFFECTS_HP 1<<0

View file

@ -17,7 +17,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
**/ **/
#include <platform.h> #include <platform.h>
#include <kernel/config.h>
#include "spy.h" #include "spy.h"
#include "guard.h" #include "guard.h"
#include "laws.h" #include "laws.h"
@ -26,6 +25,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "study.h" #include "study.h"
/* kernel includes */ /* kernel includes */
#include <kernel/config.h>
#include <kernel/item.h> #include <kernel/item.h>
#include <kernel/faction.h> #include <kernel/faction.h>
#include <kernel/messages.h> #include <kernel/messages.h>
@ -44,11 +44,13 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* util includes */ /* util includes */
#include <util/attrib.h> #include <util/attrib.h>
#include <util/base36.h> #include <util/base36.h>
#include <util/bsdstring.h>
#include <util/parser.h> #include <util/parser.h>
#include <quicklist.h>
#include <util/rand.h> #include <util/rand.h>
#include <util/rng.h> #include <util/rng.h>
#include <quicklist.h>
/* libc includes */ /* libc includes */
#include <assert.h> #include <assert.h>
#include <ctype.h> #include <ctype.h>
@ -98,13 +100,13 @@ void spy_message(int spy, const unit * u, const unit * target)
first = 0; first = 0;
} }
else { else {
strncat(buf, ", ", sizeof(buf) - 1); strlcat(buf, ", ", sizeof(buf));
} }
strncat(buf, (const char *)skillname((skill_t)sv->id, u->faction->locale), strlcat(buf, (const char *)skillname((skill_t)sv->id, u->faction->locale),
sizeof(buf) - 1); sizeof(buf));
strncat(buf, " ", sizeof(buf) - 1); strlcat(buf, " ", sizeof(buf));
strncat(buf, itoa10(eff_skill(target, sv, target->region)), strlcat(buf, itoa10(eff_skill(target, sv, target->region)),
sizeof(buf) - 1); sizeof(buf));
} }
} }
if (found) { if (found) {
@ -297,7 +299,7 @@ int setstealth_cmd(unit * u, struct order *ord)
break; break;
} }
else if (findparam(s, u->faction->locale) == P_NOT) { else if (findparam(s, u->faction->locale) == P_NOT) {
freset(u, UFL_ANON_FACTION); u->flags |= ~UFL_ANON_FACTION;
break; break;
} }
} }
@ -414,18 +416,18 @@ static void sink_ship(region * r, ship * sh, unit * saboteur)
/* slight optimization to avoid dereferencing u->faction each time */ /* slight optimization to avoid dereferencing u->faction each time */
if (f != u->faction) { if (f != u->faction) {
f = u->faction; f = u->faction;
freset(f, FFL_SELECT); f->flags |= ~FFL_SELECT;
} }
} }
/* figure out what a unit's chances of survival are: */ /* figure out what a unit's chances of survival are: */
if (!fval(r->terrain, SEA_REGION)) { if (!(r->terrain->flags & SEA_REGION)) {
probability = CANAL_SWIMMER_CHANCE; probability = CANAL_SWIMMER_CHANCE;
} }
else { else {
for (d = 0; d != MAXDIRECTIONS; ++d) { for (d = 0; d != MAXDIRECTIONS; ++d) {
region *rn = rconnect(r, d); region *rn = rconnect(r, d);
if (rn && !fval(rn->terrain, SEA_REGION) && !move_blocked(NULL, r, rn)) { if (rn && !(rn->terrain->flags & SEA_REGION) && !move_blocked(NULL, r, rn)) {
safety = rn; safety = rn;
probability = OCEAN_SWIMMER_CHANCE; probability = OCEAN_SWIMMER_CHANCE;
break; break;
@ -436,7 +438,7 @@ static void sink_ship(region * r, ship * sh, unit * saboteur)
unit *u = *ui; unit *u = *ui;
/* inform this faction about the sinking ship: */ /* inform this faction about the sinking ship: */
if (!fval(u->faction, FFL_SELECT)) { if (!(u->faction->flags & FFL_SELECT)) {
fset(u->faction, FFL_SELECT); fset(u->faction, FFL_SELECT);
if (sink_msg == NULL) { if (sink_msg == NULL) {
sink_msg = msg_message("sink_msg", "ship region", sh, r); sink_msg = msg_message("sink_msg", "ship region", sh, r);

View file

@ -25,6 +25,7 @@ extern "C" {
struct unit; struct unit;
struct region; struct region;
struct strlist; struct strlist;
struct order;
extern int setstealth_cmd(struct unit *u, struct order *ord); extern int setstealth_cmd(struct unit *u, struct order *ord);
extern int spy_cmd(struct unit *u, struct order *ord); extern int spy_cmd(struct unit *u, struct order *ord);

View file

@ -220,7 +220,7 @@ void report_summary(summary * s, summary * o, bool full)
fprintf(F, " Helden: %s\n", pcomp(s->heroes, o->heroes)); fprintf(F, " Helden: %s\n", pcomp(s->heroes, o->heroes));
if (full) { if (full) {
fprintf(F, "Regionen: %d\n", listlen(regions)); fprintf(F, "Regionen: %d\n", (int)listlen(regions));
fprintf(F, "Bewohnte Regionen: %d\n", s->inhabitedregions); fprintf(F, "Bewohnte Regionen: %d\n", s->inhabitedregions);
fprintf(F, "Landregionen: %d\n", s->landregionen); fprintf(F, "Landregionen: %d\n", s->landregionen);
fprintf(F, "Spielerregionen: %d\n", s->regionen_mit_spielern); fprintf(F, "Spielerregionen: %d\n", s->regionen_mit_spielern);

View file

@ -11,7 +11,6 @@ killunit.c
shock.c shock.c
timeout.c timeout.c
triggers.c triggers.c
unguard.c
unitmessage.c unitmessage.c
) )
FOREACH(_FILE ${_FILES}) FOREACH(_FILE ${_FILES})

View file

@ -17,7 +17,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
**/ **/
#include <platform.h> #include <platform.h>
#include <kernel/config.h>
#include "createcurse.h" #include "createcurse.h"
/* kernel includes */ /* kernel includes */

View file

@ -17,7 +17,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
**/ **/
#include <platform.h> #include <platform.h>
#include <kernel/config.h>
#include "createunit.h" #include "createunit.h"
/* kernel includes */ /* kernel includes */

View file

@ -28,6 +28,7 @@ extern "C" {
struct region; struct region;
struct faction; struct faction;
struct unit; struct unit;
struct race;
extern struct trigger_type tt_createunit; extern struct trigger_type tt_createunit;

View file

@ -10,7 +10,6 @@
without prior permission by the authors of Eressea. without prior permission by the authors of Eressea.
*/ */
#include <platform.h> #include <platform.h>
#include <kernel/config.h>
#include "gate.h" #include "gate.h"
/* kernel includes */ /* kernel includes */

View file

@ -17,7 +17,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
**/ **/
#include <platform.h> #include <platform.h>
#include <kernel/config.h>
#include "giveitem.h" #include "giveitem.h"
/* kernel includes */ /* kernel includes */

View file

@ -17,7 +17,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
**/ **/
#include <platform.h> #include <platform.h>
#include <kernel/config.h>
#include "killunit.h" #include "killunit.h"
#include <kernel/region.h> #include <kernel/region.h>

View file

@ -17,7 +17,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
**/ **/
#include <platform.h> #include <platform.h>
#include <kernel/config.h>
#include "shock.h" #include "shock.h"
#include "magic.h" #include "magic.h"
@ -84,7 +83,7 @@ static void do_shock(unit * u, const char *reason)
} }
/* Dies ist ein Hack, um das skillmod und familiar-Attribut beim Mage /* Dies ist ein Hack, um das skillmod und familiar-Attribut beim Mage
* zu löschen wenn der Familiar getötet wird. Da sollten wir über eine * zu l<EFBFBD>schen wenn der Familiar get<EFBFBD>tet wird. Da sollten wir <EFBFBD>ber eine
* saubere Implementation nachdenken. */ * saubere Implementation nachdenken. */
if (strcmp(reason, "trigger") == 0) { if (strcmp(reason, "trigger") == 0) {

View file

@ -17,7 +17,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
**/ **/
#include <platform.h> #include <platform.h>
#include <kernel/config.h>
#include "timeout.h" #include "timeout.h"
/* util includes */ /* util includes */

View file

@ -17,7 +17,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
**/ **/
#include <platform.h> #include <platform.h>
#include <kernel/config.h>
/* triggers includes */ /* triggers includes */
#include <triggers/changefaction.h> #include <triggers/changefaction.h>
@ -25,7 +24,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <triggers/createcurse.h> #include <triggers/createcurse.h>
#include <triggers/createunit.h> #include <triggers/createunit.h>
#include <triggers/gate.h> #include <triggers/gate.h>
#include <triggers/unguard.h>
#include <triggers/giveitem.h> #include <triggers/giveitem.h>
#include <triggers/killunit.h> #include <triggers/killunit.h>
#include <triggers/shock.h> #include <triggers/shock.h>
@ -46,7 +44,6 @@ void register_triggers(void)
tt_register(&tt_createcurse); tt_register(&tt_createcurse);
tt_register(&tt_createunit); tt_register(&tt_createunit);
tt_register(&tt_gate); tt_register(&tt_gate);
tt_register(&tt_unguard);
tt_register(&tt_giveitem); tt_register(&tt_giveitem);
tt_register(&tt_killunit); tt_register(&tt_killunit);
tt_register(&tt_shock); tt_register(&tt_shock);

View file

@ -1,76 +0,0 @@
/*
+-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
| | Enno Rehling <enno@eressea.de>
| Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>
| (c) 1998 - 2003 | Henning Peters <faroul@beyond.kn-bremen.de>
| | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.de>
+-------------------+ Stefan Reich <reich@halbling.de>
This program may not be used, modified or distributed
without prior permission by the authors of Eressea.
*/
#include <platform.h>
#include <kernel/config.h>
#include "unguard.h"
/* kernel includes */
#include <util/attrib.h>
#include <kernel/building.h>
#include <kernel/region.h>
#include <kernel/unit.h>
/* util includes */
#include <util/attrib.h>
#include <util/event.h>
#include <util/gamedata.h>
#include <util/log.h>
#include <util/resolve.h>
/* libc includes */
#include <stdlib.h>
static int unguard_handle(trigger * t, void *data)
{
building *b = (building *)t->data.v;
if (b) {
fset(b, BLD_UNGUARDED);
}
else {
log_error("could not perform unguard::handle()\n");
return -1;
}
unused_arg(data);
return 0;
}
static void unguard_write(const trigger * t, struct storage *store)
{
write_building_reference((building *)t->data.v, store);
}
static int unguard_read(trigger * t, gamedata *data)
{
int rb = read_reference(&t->data.v, data, read_building_reference,
resolve_building);
if (rb == 0 && !t->data.v) {
return AT_READ_FAIL;
}
return AT_READ_OK;
}
struct trigger_type tt_unguard = {
"building",
NULL,
NULL,
unguard_handle,
unguard_write,
unguard_read
};
trigger *trigger_unguard(building * b)
{
trigger *t = t_new(&tt_unguard);
t->data.v = (void *)b;
return t;
}

View file

@ -1,32 +0,0 @@
/*
+-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
| | Enno Rehling <enno@eressea.de>
| Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>
| (c) 1998 - 2003 | Henning Peters <faroul@beyond.kn-bremen.de>
| | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.de>
+-------------------+ Stefan Reich <reich@halbling.de>
This program may not be used, modified or distributed
without prior permission by the authors of Eressea.
*/
#ifndef UNGUARD_H
#define UNGUARD_H
#ifdef __cplusplus
extern "C" {
#endif
/* all types we use are defined here to reduce dependencies */
struct trigger_type;
struct trigger;
struct region;
struct building;
extern struct trigger_type tt_unguard;
extern struct trigger *trigger_unguard(struct building *b);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -8,7 +8,6 @@ without prior permission by the authors of Eressea.
*/ */
#include <platform.h> #include <platform.h>
#include <kernel/config.h>
#include "unitmessage.h" #include "unitmessage.h"
/* kernel includes */ /* kernel includes */

View file

@ -32,7 +32,7 @@ static void test_strlcpy(CuTest * tc)
CuAssertIntEquals(tc, 4, (int)strlcpy(buffer, "herp", 4)); CuAssertIntEquals(tc, 4, (int)strlcpy(buffer, "herp", 4));
CuAssertStrEquals(tc, "her", buffer); CuAssertStrEquals(tc, "her", buffer);
CuAssertIntEquals(tc, 4, (int)strlcpy(buffer, "herp", 8)); CuAssertIntEquals(tc, 4, (int)strlcpy(buffer, "herp", 8)); //-V666
CuAssertStrEquals(tc, "herp", buffer); CuAssertStrEquals(tc, "herp", buffer);
CuAssertIntEquals(tc, 0x7f, buffer[5]); CuAssertIntEquals(tc, 0x7f, buffer[5]);

View file

@ -244,7 +244,7 @@ void tt_register(trigger_type * tt)
trigger_type *tt_find(const char *name) trigger_type *tt_find(const char *name)
{ {
trigger_type *tt = triggertypes; trigger_type *tt = triggertypes;
while (tt && strcmp(tt->name, name)) while (tt && strcmp(tt->name, name)!=0)
tt = tt->next; tt = tt->next;
return tt; return tt;
} }

View file

@ -220,7 +220,7 @@ void log_fatal(const char *format, ...)
va_end(args); va_end(args);
} }
void log_error(const char *format, ...) void log_error(const char *format, ...) //-V524
{ {
va_list args; va_list args;
va_start(args, format); va_start(args, format);

View file

@ -103,13 +103,13 @@ void random_source_inject_constant(double value) {
r_source = &constant_provider; r_source = &constant_provider;
} }
static int i = 0;
static double *values; static double *values;
static int value_size = 0; static int value_size;
static int value_index;
static double array_source (void) { static double array_source (void) {
assert(i<value_size); assert(value_index<value_size);
return values[i++]; return values[value_index++];
} }
struct random_source array_provider = { struct random_source array_provider = {
@ -117,6 +117,7 @@ struct random_source array_provider = {
}; };
void random_source_inject_array(double inject[], int size) { void random_source_inject_array(double inject[], int size) {
int i;
assert(size > 0); assert(size > 0);
value_size = size; value_size = size;
if (values) if (values)
@ -125,7 +126,7 @@ void random_source_inject_array(double inject[], int size) {
for (i=0; i < size; ++i) { for (i=0; i < size; ++i) {
values[i] = inject[i]; values[i] = inject[i];
} }
i = 0; value_index = 0;
r_source = &array_provider; r_source = &array_provider;
} }

View file

@ -29,7 +29,7 @@ static void test_unicode_trim(CuTest * tc)
CuAssertIntEquals(tc, 3, unicode_utf8_trim(buffer)); CuAssertIntEquals(tc, 3, unicode_utf8_trim(buffer));
CuAssertStrEquals(tc, "Hello Word", buffer); CuAssertStrEquals(tc, "Hello Word", buffer);
buffer[9] = (char)0xc3; buffer[9] = -61;
CuAssertIntEquals(tc, 1, unicode_utf8_trim(buffer)); CuAssertIntEquals(tc, 1, unicode_utf8_trim(buffer));
CuAssertStrEquals(tc, "Hello Wor?", buffer); CuAssertStrEquals(tc, "Hello Wor?", buffer);
} }