indentation + whitespace changes

This commit is contained in:
Enno Rehling 2014-08-08 01:03:46 +02:00
parent bf4bda36a2
commit 1918f56990
6 changed files with 7236 additions and 7054 deletions

View File

@ -1,7 +1,8 @@
/*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de>
Copyright (c) 1998-2014,
Enno Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
@ -158,7 +159,7 @@ static void expandorders(region * r, request * requests)
if (norders > 0) {
int i = 0;
oa = (request *) calloc(norders, sizeof(request));
oa = (request *)calloc(norders, sizeof(request));
for (o = requests; o; o = o->next) {
if (o->qty > 0) {
int j;
@ -170,7 +171,8 @@ static void expandorders(region * r, request * requests)
}
}
scramble(oa, norders, sizeof(request));
} else {
}
else {
oa = NULL;
}
while (requests) {
@ -203,7 +205,7 @@ typedef struct recruitment {
* to the faction's struct and to total.
*/
static recruitment *select_recruitment(request ** rop,
int (*quantify) (const struct race *, int), int *total)
int(*quantify) (const struct race *, int), int *total)
{
recruitment *recruits = NULL;
@ -216,7 +218,8 @@ static recruitment *select_recruitment(request ** rop,
if (qty < 0) {
rop = &ro->next; /* skip this one */
} else {
}
else {
*rop = ro->next; /* remove this one */
while (rec && rec->f != u->faction)
rec = rec->next;
@ -250,7 +253,8 @@ static void add_recruits(unit * u, int number, int wanted)
set_number(u, number);
u->hp = number * unit_max_hp(u);
unew = u;
} else {
}
else {
unew = create_unit(r, u->faction, number, u_race(u), 0, NULL, u);
}
@ -281,11 +285,11 @@ static int any_recruiters(const struct race *rc, int qty)
/*static int peasant_recruiters(const struct race *rc, int qty)
{
if (rc->ec_flags & ECF_REC_ETHEREAL)
return -1;
if (rc->ec_flags & ECF_REC_HORSES)
return -1;
return (int)(qty * 2 * rc->recruit_multi);
if (rc->ec_flags & ECF_REC_ETHEREAL)
return -1;
if (rc->ec_flags & ECF_REC_HORSES)
return -1;
return (int)(qty * 2 * rc->recruit_multi);
}*/
static int horse_recruiters(const struct race *rc, int qty)
@ -408,7 +412,8 @@ static bool can_give(const unit * u, const unit * u2, const item_type * itype, i
}
return (rule & mask) != 0;
}
} else {
}
else {
int rule = rule_give();
return (rule & GIVE_PEASANTS) != 0;
}
@ -478,9 +483,10 @@ static int recruit_cost(const faction * f, const race * rc)
{
if (is_monsters(f) || f->race == rc) {
return rc->recruitcost;
} else if (valid_race(f, rc)) {
}
else if (valid_race(f, rc)) {
return rc->recruitcost;
/* return get_param_int(f->race->parameters, "other_cost", -1); */
/* return get_param_int(f->race->parameters, "other_cost", -1); */
}
return -1;
}
@ -613,7 +619,7 @@ static void recruit(unit * u, struct order *ord, request ** recruitorders)
return;
}
o = (request *) calloc(1, sizeof(request));
o = (request *)calloc(1, sizeof(request));
o->qty = n;
o->unit = u;
o->ord = copy_order(ord);
@ -637,7 +643,7 @@ void give_control(unit * u, unit * u2)
region *r = u->region;
faction *f = region_get_owner(r);
assert(u->building==u2->building);
assert(u->building == u2->building);
if (f == u->faction) {
building *b = largestbuilding(r, &cmp_current_owner, false);
if (b == u->building) {
@ -648,7 +654,7 @@ void give_control(unit * u, unit * u2)
building_set_owner(u2);
}
if (u->ship) {
assert(u->ship==u2->ship);
assert(u->ship == u2->ship);
ship_set_owner(u2);
}
}
@ -673,18 +679,23 @@ int give_control_cmd(unit * u, order * ord)
if (!u2 || u2->number == 0) {
msg = msg_feedback(u, ord, "feedback_unit_not_found", "");
ADDMSG(&u->faction->msgs, msg);
} else if (!u->building && !u->ship) {
}
else if (!u->building && !u->ship) {
msg = cmistake(u, ord, 140, MSG_EVENT);
} else if (u->building) {
if (u!=building_owner(u->building)) {
}
else if (u->building) {
if (u != building_owner(u->building)) {
msg = cmistake(u, ord, 49, MSG_EVENT);
} else if (u2->building != u->building) {
}
else if (u2->building != u->building) {
msg = cmistake(u, ord, 33, MSG_EVENT);
}
} else if (u->ship) {
if (u!=ship_owner(u->ship)) {
}
else if (u->ship) {
if (u != ship_owner(u->ship)) {
msg = cmistake(u, ord, 49, MSG_EVENT);
} else if (u2->ship != u->ship) {
}
else if (u2->ship != u->ship) {
msg = cmistake(u, ord, 32, MSG_EVENT);
}
}
@ -724,7 +735,7 @@ static void give_cmd(unit * u, order * ord)
u2 = getunit(r, u->faction);
s = getstrtoken();
n = atoip(s);
p = (n>0) ? NOPARAM : findparam(s, u->faction->locale);
p = (n > 0) ? NOPARAM : findparam(s, u->faction->locale);
/* first, do all the ones that do not require HELP_GIVE or CONTACT */
if (p == P_CONTROL) {
@ -878,22 +889,27 @@ static void give_cmd(unit * u, order * ord)
itmp = &itm->next;
}
}
} else {
}
else {
if (isparam(s, u->faction->locale, P_PERSON)) {
if (!(u_race(u)->ec_flags & GIVEPERSON)) {
ADDMSG(&u->faction->msgs,
msg_feedback(u, ord, "race_noregroup", "race", u_race(u)));
} else {
}
else {
n = u->number;
give_men(n, u, u2, ord);
}
} else if (!(u_race(u)->ec_flags & GIVEITEM) && u2 != NULL) {
}
else if (!(u_race(u)->ec_flags & GIVEITEM) && u2 != NULL) {
ADDMSG(&u->faction->msgs,
msg_feedback(u, ord, "race_nogive", "race", u_race(u)));
} else if (u2 && !(u_race(u2)->ec_flags & GETITEM)) {
}
else if (u2 && !(u_race(u2)->ec_flags & GETITEM)) {
ADDMSG(&u->faction->msgs,
msg_feedback(u, ord, "race_notake", "race", u_race(u2)));
} else {
}
else {
itype = finditemtype(s, u->faction->locale);
if (itype != NULL) {
item *i = *i_find(&u->items, itype);
@ -901,7 +917,8 @@ static void give_cmd(unit * u, order * ord)
if (can_give(u, u2, itype, 0)) {
n = i->number - get_reservation(u, itype->rtype);
give_item(n, itype, u, u2, ord);
} else {
}
else {
feedback_give_not_allowed(u, ord);
}
}
@ -909,7 +926,8 @@ static void give_cmd(unit * u, order * ord)
}
}
return;
} else if (p == P_EACH) {
}
else if (p == P_EACH) {
if (u2 == NULL) {
ADDMSG(&u->faction->msgs,
msg_feedback(u, ord, "peasants_give_invalid", ""));
@ -953,7 +971,8 @@ static void give_cmd(unit * u, order * ord)
if (itype != NULL) {
if (can_give(u, u2, itype, 0)) {
give_item(n, itype, u, u2, ord);
} else {
}
else {
feedback_give_not_allowed(u, ord);
}
return;
@ -1118,7 +1137,8 @@ static bool maintain(building * b, bool first)
}
assert(cost == 0);
}
} else {
}
else {
ADDMSG(&u->faction->msgs, msg_message("maintenancefail", "unit building", u, b));
return false;
}
@ -1143,7 +1163,8 @@ void maintain_buildings(region * r, bool crash)
if (u) {
add_message(&u->faction->msgs, msg);
r_addmessage(r, u->faction, msg);
} else {
}
else {
add_message(&r->msgs, msg);
}
msg_release(msg);
@ -1169,7 +1190,8 @@ void economics(region * r)
keyword_t kwd = getkeyword(ord);
if (kwd == K_GIVE) {
give_cmd(u, ord);
} else if (kwd == K_FORGET) {
}
else if (kwd == K_FORGET) {
forget_cmd(u, ord);
}
if (u->orders == NULL) {
@ -1272,7 +1294,8 @@ static void manufacture(unit * u, const item_type * itype, int want)
ADDMSG(&u->faction->msgs, msg_message("manufacture",
"unit region amount wanted resource", u, u->region, n, want,
itype->rtype));
} else {
}
else {
ADDMSG(&u->faction->msgs, msg_feedback(u, u->thisorder, "error_cannotmake",
""));
}
@ -1322,7 +1345,7 @@ static void allocate_resource(unit * u, const resource_type * rtype, int want)
allocation_list *alist;
allocation *al;
attrib *a = a_find(rtype->attribs, &at_resourcelimit);
resource_limit *rdata = (resource_limit *) a->data.v;
resource_limit *rdata = (resource_limit *)a->data.v;
const resource_type *rring;
int amount, skill;
@ -1374,7 +1397,7 @@ static void allocate_resource(unit * u, const resource_type * rtype, int want)
* Als magische Wesen 'sehen' Bergwächter alles und werden durch
* Belagerung nicht aufgehalten. (Ansonsten wie oben bei Elfen anpassen).
*/
if (itype->rtype && (itype->rtype==get_resourcetype(R_IRON) || itype->rtype==rt_find("laen"))) {
if (itype->rtype && (itype->rtype == get_resourcetype(R_IRON) || itype->rtype == rt_find("laen"))) {
unit *u2;
for (u2 = r->units; u2; u2 = u2->next) {
if (is_guard(u, GUARD_MINING)
@ -1403,7 +1426,8 @@ static void allocate_resource(unit * u, const resource_type * rtype, int want)
"skill minskill product", sk, itype->construction->minskill,
itype->rtype));
return;
} else {
}
else {
struct building *b = inside_building(u);
const struct building_type *btype = b ? b->type : NULL;
@ -1515,10 +1539,12 @@ leveled_allocation(const resource_type * rtype, region * r, allocation * alist)
>= rm->level + itype->construction->minskill - 1) {
if (req) {
norders += req;
} else {
}
else {
fset(al, AFL_DONE);
}
} else {
}
else {
fset(al, AFL_DONE);
if (first)
fset(al, AFL_LOWSKILL);
@ -1561,7 +1587,7 @@ attrib_allocation(const resource_type * rtype, region * r, allocation * alist)
allocation *al;
int norders = 0;
attrib *a = a_find(rtype->attribs, &at_resourcelimit);
resource_limit *rdata = (resource_limit *) a->data.v;
resource_limit *rdata = (resource_limit *)a->data.v;
int avail = rdata->value;
for (al = alist; al; al = al->next) {
@ -1595,15 +1621,15 @@ attrib_allocation(const resource_type * rtype, region * r, allocation * alist)
assert(avail == 0 || norders == 0);
}
typedef void (*allocate_function) (const resource_type *, struct region *,
struct allocation *);
typedef void(*allocate_function) (const resource_type *, struct region *,
struct allocation *);
static allocate_function get_allocator(const struct resource_type *rtype)
{
attrib *a = a_find(rtype->attribs, &at_resourcelimit);
if (a != NULL) {
resource_limit *rdata = (resource_limit *) a->data.v;
resource_limit *rdata = (resource_limit *)a->data.v;
if (rdata->value > 0 || rdata->limit != NULL) {
return attrib_allocation;
}
@ -1697,7 +1723,8 @@ static void create_item(unit * u, const item_type * itype, int want)
}
#endif
allocate_resource(u, itype->rtype, want);
} else {
}
else {
const potion_type *ptype = resource2potion(itype->rtype);
if (ptype != NULL)
create_potion(u, ptype, want);
@ -1731,7 +1758,8 @@ int make_cmd(unit * u, struct order *ord)
if (!strcmp(ibuf, (const char *)s)) {
/* first came a want-paramter */
s = getstrtoken();
} else {
}
else {
m = INT_MAX;
}
@ -1745,25 +1773,30 @@ int make_cmd(unit * u, struct order *ord)
plane *pl = rplane(r);
if (pl && fval(pl, PFL_NOBUILD)) {
cmistake(u, ord, 275, MSG_PRODUCE);
} else {
}
else {
direction_t d = get_direction(getstrtoken(), u->faction->locale);
if (d != NODIRECTION) {
build_road(r, u, m, d);
} else {
}
else {
/* Die Richtung wurde nicht erkannt */
cmistake(u, ord, 71, MSG_PRODUCE);
}
}
return 0;
} else if (p == P_SHIP) {
}
else if (p == P_SHIP) {
plane *pl = rplane(r);
if (pl && fval(pl, PFL_NOBUILD)) {
cmistake(u, ord, 276, MSG_PRODUCE);
} else {
}
else {
continue_ship(r, u, m);
}
return 0;
} else if (p == P_HERBS) {
}
else if (p == P_HERBS) {
herbsearch(r, u, m);
return 0;
}
@ -1780,14 +1813,16 @@ int make_cmd(unit * u, struct order *ord)
if (itype->construction == NULL) {
/* if the item cannot be made, we probably didn't mean to make it */
itype = NULL;
} else if (stype != NULL) {
}
else if (stype != NULL) {
const char *sname = LOC(lang, stype->_name);
const char *iname = LOC(lang, resourcename(itype->rtype, 0));
if (strlen(iname) < strlen(sname))
stype = NULL;
else
itype = NULL;
} else {
}
else {
const char *bname = LOC(lang, btype->_name);
const char *iname = LOC(lang, resourcename(itype->rtype, 0));
if (strlen(iname) < strlen(bname))
@ -1810,20 +1845,25 @@ int make_cmd(unit * u, struct order *ord)
plane *pl = rplane(r);
if (pl && fval(pl, PFL_NOBUILD)) {
cmistake(u, ord, 276, MSG_PRODUCE);
} else {
}
else {
create_ship(r, u, stype, m, ord);
}
} else if (btype != NOBUILDING) {
}
else if (btype != NOBUILDING) {
plane *pl = rplane(r);
if (pl && fval(pl, PFL_NOBUILD)) {
cmistake(u, ord, 94, MSG_PRODUCE);
} else {
}
else {
int id = getid();
build_building(u, btype, id, m, ord);
}
} else if (itype != NULL) {
}
else if (itype != NULL) {
create_item(u, itype, m);
} else {
}
else {
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_cannotmake", ""));
}
@ -1834,7 +1874,7 @@ int make_cmd(unit * u, struct order *ord)
static void free_luxuries(struct attrib *a)
{
item *itm = (item *) a->data.v;
item *itm = (item *)a->data.v;
a->data.v = NULL;
i_freeall(&itm);
}
@ -1941,7 +1981,7 @@ static void expandbuying(region * r, request * buyorders)
if (a == NULL)
continue;
ADDMSG(&u->faction->msgs, msg_message("buy", "unit money", u, u->n));
for (itm = (item *) a->data.v; itm; itm = itm->next) {
for (itm = (item *)a->data.v; itm; itm = itm->next) {
if (itm->number) {
ADDMSG(&u->faction->msgs, msg_message("buyamount",
"unit amount resource", u, itm->number, itm->type->rtype));
@ -2000,7 +2040,8 @@ static void buy(unit * u, request ** buyorders, struct order *ord)
cmistake(u, ord, 119, MSG_COMMERCE);
return;
}
} else {
}
else {
/* ...oder in der Region muß es eine Burg geben. */
building *b = 0;
if (r->buildings) {
@ -2026,7 +2067,8 @@ static void buy(unit * u, request ** buyorders, struct order *ord)
a = a_find(u->attribs, &at_trades);
if (!a) {
a = a_add(&u->attribs, a_new(&at_trades));
} else {
}
else {
k -= a->data.i;
}
@ -2053,7 +2095,7 @@ static void buy(unit * u, request ** buyorders, struct order *ord)
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "luxury_notsold", ""));
return;
}
o = (request *) calloc(1, sizeof(request));
o = (request *)calloc(1, sizeof(request));
o->type.ltype = ltype; /* sollte immer gleich sein */
o->unit = u;
@ -2073,8 +2115,8 @@ static void expandselling(region * r, request * sellorders, int limit)
int maxsize = 0, maxeffsize = 0;
int taxcollected = 0;
int hafencollected = 0;
unit *maxowner = (unit *) NULL;
building *maxb = (building *) NULL;
unit *maxowner = (unit *)NULL;
building *maxb = (building *)NULL;
building *b;
unit *u;
unit *hafenowner;
@ -2086,7 +2128,8 @@ static void expandselling(region * r, request * sellorders, int limit)
for (ltype = luxurytypes; ltype; ltype = ltype->next)
++ncounter;
counter = (int *)gc_add(calloc(sizeof(int), ncounter));
} else {
}
else {
memset(counter, 0, sizeof(int) * ncounter);
}
@ -2102,19 +2145,20 @@ static void expandselling(region * r, request * sellorders, int limit)
maxb = b;
maxsize = b->size;
maxowner = building_owner(b);
} else if (b->size == maxsize && b->type == bt_find("castle")) {
maxb = (building *) NULL;
maxowner = (unit *) NULL;
}
else if (b->size == maxsize && b->type == bt_find("castle")) {
maxb = (building *)NULL;
maxowner = (unit *)NULL;
}
}
hafenowner = owner_buildingtyp(r, bt_find("harbour"));
if (maxb != (building *) NULL && maxowner != (unit *) NULL) {
if (maxb != (building *)NULL && maxowner != (unit *)NULL) {
maxeffsize = buildingeffsize(maxb, false);
if (maxeffsize == 0) {
maxb = (building *) NULL;
maxowner = (unit *) NULL;
maxb = (building *)NULL;
maxowner = (unit *)NULL;
}
}
/* Die Region muss genug Geld haben, um die Produkte kaufen zu können. */
@ -2146,7 +2190,7 @@ static void expandselling(region * r, request * sellorders, int limit)
int multi = r_demand(r, ltype);
int i;
int use = 0;
for (i=0,search=luxurytypes; search!=ltype; search=search->next) {
for (i = 0, search = luxurytypes; search != ltype; search = search->next) {
++i;
}
if (counter[i] >= limit)
@ -2163,7 +2207,7 @@ static void expandselling(region * r, request * sellorders, int limit)
attrib *a = a_find(u->attribs, &at_luxuries);
if (a == NULL)
a = a_add(&u->attribs, a_new(&at_luxuries));
itm = (item *) a->data.v;
itm = (item *)a->data.v;
i_change(&itm, ltype->itype, 1);
a->data.v = itm;
++use;
@ -2241,7 +2285,7 @@ static void expandselling(region * r, request * sellorders, int limit)
item *itm;
if (a == NULL)
continue;
for (itm = (item *) a->data.v; itm; itm = itm->next) {
for (itm = (item *)a->data.v; itm; itm = itm->next) {
if (itm->number) {
ADDMSG(&u->faction->msgs, msg_message("sellamount",
"unit amount resource", u, itm->number, itm->type->rtype));
@ -2250,7 +2294,7 @@ static void expandselling(region * r, request * sellorders, int limit)
a_remove(&u->attribs, a);
add_income(u, IC_TRADE, u->n, u->n);
}
}
}
static bool sell(unit * u, request ** sellorders, struct order *ord)
{
@ -2282,7 +2326,8 @@ static bool sell(unit * u, request ** sellorders, struct order *ord)
cmistake(u, ord, 303, MSG_COMMERCE);
return false;
}
} else {
}
else {
n = atoi((const char *)s);
if (n == 0) {
cmistake(u, ord, 27, MSG_COMMERCE);
@ -2303,7 +2348,8 @@ static bool sell(unit * u, request ** sellorders, struct order *ord)
cmistake(u, ord, 119, MSG_COMMERCE);
return false;
}
} else {
}
else {
/* ...oder in der Region muß es eine Burg geben. */
building *b = 0;
if (r->buildings) {
@ -2333,7 +2379,8 @@ static bool sell(unit * u, request ** sellorders, struct order *ord)
if (ltype == NULL) {
cmistake(u, ord, 126, MSG_COMMERCE);
return false;
} else {
}
else {
attrib *a;
request *o;
int k, available;
@ -2374,7 +2421,8 @@ static bool sell(unit * u, request ** sellorders, struct order *ord)
a = a_find(u->attribs, &at_trades);
if (!a) {
a = a_add(&u->attribs, a_new(&at_trades));
} else {
}
else {
k -= a->data.i;
}
@ -2382,7 +2430,7 @@ static bool sell(unit * u, request ** sellorders, struct order *ord)
assert(n >= 0);
/* die Menge der verkauften Güter merken */
a->data.i += n;
o = (request *) calloc(1, sizeof(request));
o = (request *)calloc(1, sizeof(request));
o->unit = u;
o->qty = n;
o->type.ltype = ltype;
@ -2426,9 +2474,9 @@ static void expandstealing(region * r, request * stealorders)
if (u2->faction == u->faction) {
uct += maintenance_cost(u2);
}
}
}
n -= uct * 2;
}
}
#endif
if (n > 10 && rplane(r) && (rplane(r)->flags & PFL_NOALLIANCES)) {
/* In Questen nur reduziertes Klauen */
@ -2673,13 +2721,15 @@ static void breed_cmd(unit * u, struct order *ord)
if (m != 0) {
/* first came a want-paramter */
s = getstrtoken();
} else {
}
else {
m = INT_MAX;
}
if (!s[0]) {
p = P_ANY;
} else {
}
else {
p = findparam(s, u->faction->locale);
}
@ -2696,7 +2746,8 @@ static void breed_cmd(unit * u, struct order *ord)
if (rtype == get_resourcetype(R_SEED) || rtype == get_resourcetype(R_MALLORNSEED)) {
breedtrees(r, u, m);
break;
} else if (rtype != get_resourcetype(R_HORSE)) {
}
else if (rtype != get_resourcetype(R_HORSE)) {
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_cannotmake", ""));
break;
}
@ -2712,11 +2763,14 @@ static const char *rough_amount(int a, int m)
if (p < 10) {
return "sehr wenige";
} else if (p < 30) {
}
else if (p < 30) {
return "wenige";
} else if (p < 60) {
}
else if (p < 60) {
return "relativ viele";
} else if (p < 90) {
}
else if (p < 90) {
return "viele";
}
return "sehr viele";
@ -2747,11 +2801,13 @@ static void research_cmd(unit * u, struct order *ord)
ADDMSG(&u->faction->msgs, msg_message("researchherb",
"unit region amount herb",
u, r, rough_amount(rherbs(r), 100), itype->rtype));
} else {
}
else {
ADDMSG(&u->faction->msgs, msg_message("researchherb_none",
"unit region", u, r));
}
} else {
}
else {
ADDMSG(&u->faction->msgs, msg_message("researchherb_none",
"unit region", u, r));
}
@ -2816,7 +2872,8 @@ static void steal_cmd(unit * u, struct order *ord, request ** stealorders)
if (u2 && u2->region == u->region) {
f = u2->faction;
} else {
}
else {
f = dfindhash(id);
}
@ -2856,12 +2913,14 @@ static void steal_cmd(unit * u, struct order *ord, request ** stealorders)
ADDMSG(&u->faction->msgs, msg_message("stealfail", "unit target", u, u2));
if (n == 0) {
ADDMSG(&u2->faction->msgs, msg_message("stealdetect", "unit", u2));
} else {
}
else {
ADDMSG(&u2->faction->msgs, msg_message("thiefdiscover", "unit target",
u, u2));
}
return;
} else {
}
else {
ADDMSG(&u->faction->msgs, msg_message("stealfatal", "unit target", u,
u2));
ADDMSG(&u2->faction->msgs, msg_message("thiefdiscover", "unit target", u,
@ -2874,7 +2933,8 @@ static void steal_cmd(unit * u, struct order *ord, request ** stealorders)
i = _min(u->number, i_get(u->items, rring->itype));
if (i > 0) {
n *= STEALINCOME * (u->number + i * (roqf_factor() - 1));
} else {
}
else {
n *= u->number * STEALINCOME;
}
@ -2883,7 +2943,7 @@ static void steal_cmd(unit * u, struct order *ord, request ** stealorders)
/* wer dank unsichtbarkeitsringen klauen kann, muss nicht unbedingt ein
* guter dieb sein, schliesslich macht man immer noch sehr viel laerm */
o = (request *) calloc(1, sizeof(request));
o = (request *)calloc(1, sizeof(request));
o->unit = u;
o->qty = 1; /* Betrag steht in u->wants */
o->no = u2->no;
@ -3063,7 +3123,8 @@ static int do_work(unit * u, order * ord, request * o)
o->qty = u->number * w;
working += u->number;
return 0;
} else if (ord && !is_monsters(u->faction)) {
}
else if (ord && !is_monsters(u->faction)) {
ADDMSG(&u->faction->msgs,
msg_feedback(u, ord, "race_cantwork", "race", u_race(u)));
}
@ -3132,7 +3193,8 @@ void tax_cmd(unit * u, struct order *ord, request ** taxorders)
max = INT_MAX;
if (!playerrace(u_race(u))) {
u->wants = _min(income(u), max);
} else {
}
else {
u->wants = _min(n * eff_skill(u, SK_TAXING, r) * 20, max);
}
@ -3147,7 +3209,7 @@ void tax_cmd(unit * u, struct order *ord, request ** taxorders)
* fraktionen werden dann bei eintreiben unter allen eintreibenden
* einheiten aufgeteilt. */
o = (request *) calloc(1, sizeof(request));
o = (request *)calloc(1, sizeof(request));
o->qty = u->wants / TAXFRACTION;
o->unit = u;
addlist(taxorders, o);
@ -3278,7 +3340,8 @@ void produce(struct region *r)
if (kwd == K_BUY) {
buy(u, &buyorders, ord);
trader = true;
} else if (kwd == K_SELL) {
}
else if (kwd == K_SELL) {
/* sell returns true if the sale is not limited
* by the region limit */
limited &= !sell(u, &sellorders, ord);

View File

@ -2,7 +2,7 @@
+-------------------+ 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>
| (c) 1998 - 2014 | Henning Peters <faroul@beyond.kn-bremen.de>
| | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.de>
+-------------------+ Stefan Reich <reich@halbling.de>
@ -63,14 +63,16 @@ static int GiveRestriction(void)
static void
add_give(unit * u, unit * u2, int given, int received,
const resource_type * rtype, struct order *ord, int error)
const resource_type * rtype, struct order *ord, int error)
{
if (error) {
cmistake(u, ord, error, MSG_COMMERCE);
} else if (u2 == NULL) {
}
else if (u2 == NULL) {
ADDMSG(&u->faction->msgs,
msg_message("give_peasants", "unit resource amount", u, rtype, given));
} else if (u2->faction != u->faction) {
}
else if (u2->faction != u->faction) {
message *msg;
msg =
@ -114,7 +116,7 @@ int give_quota(const unit * src, const unit * dst, const item_type * type,
int
give_item(int want, const item_type * itype, unit * src, unit * dest,
struct order *ord)
struct order *ord)
{
short error = 0;
int n, r;
@ -130,7 +132,8 @@ give_item(int want, const item_type * itype, unit * src, unit * dest,
"turns", GiveRestriction()));
}
return -1;
} else if (n == 0) {
}
else if (n == 0) {
int reserve = get_reservation(src, itype->rtype);
if (reserve) {
msg_feedback(src, ord, "nogive_reserved", "resource reservation",
@ -138,9 +141,11 @@ give_item(int want, const item_type * itype, unit * src, unit * dest,
return -1;
}
error = 36;
} else if (itype->flags & ITF_CURSED) {
}
else if (itype->flags & ITF_CURSED) {
error = 25;
} else if (itype->give == NULL || itype->give(src, dest, itype, n, ord) != 0) {
}
else if (itype->give == NULL || itype->give(src, dest, itype, n, ord) != 0) {
int use = use_pooled(src, item2resource(itype), GET_SLACK, n);
if (use < n)
use +=
@ -184,43 +189,56 @@ void give_men(int n, unit * u, unit * u2, struct order *ord)
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "giverestriction",
"turns", GiveRestriction()));
return;
} else if (u == u2) {
}
else if (u == u2) {
error = 10;
}
else if (!u2 && u_race(u) == get_race(RC_SNOTLING)) {
/* snotlings may not be given to the peasants. */
error = 307;
} else if (u2 && u2->number && (fval(u, UFL_HERO) != fval(u2, UFL_HERO))) {
}
else if (u2 && u2->number && (fval(u, UFL_HERO) != fval(u2, UFL_HERO))) {
/* heroes may not be given to non-heroes and vice versa */
error = 75;
} else if (unit_has_cursed_item(u) || (u2 && unit_has_cursed_item(u2))) {
}
else if (unit_has_cursed_item(u) || (u2 && unit_has_cursed_item(u2))) {
error = 78;
} else if (fval(u, UFL_LOCKED) || is_cursed(u->attribs, C_SLAVE, 0)) {
}
else if (fval(u, UFL_LOCKED) || is_cursed(u->attribs, C_SLAVE, 0)) {
error = 74;
} else if (u2 && fval(u, UFL_HUNGER)) {
}
else if (u2 && fval(u, UFL_HUNGER)) {
/* hungry people cannot be given away */
error = 73;
} else if (u2 && (fval(u2, UFL_LOCKED) || is_cursed(u2->attribs, C_SLAVE, 0))) {
}
else if (u2 && (fval(u2, UFL_LOCKED) || is_cursed(u2->attribs, C_SLAVE, 0))) {
error = 75;
} else if (u2 && !ucontact(u2, u)) {
}
else if (u2 && !ucontact(u2, u)) {
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "feedback_no_contact",
"target", u2));
error = -1;
} else if (u2 && (has_skill(u, SK_MAGIC) || has_skill(u2, SK_MAGIC))) {
}
else if (u2 && (has_skill(u, SK_MAGIC) || has_skill(u2, SK_MAGIC))) {
/* cannot give units to and from magicians */
error = 158;
} else if (u2 && (fval(u, UFL_WERE) != fval(u2, UFL_WERE))) {
}
else if (u2 && (fval(u, UFL_WERE) != fval(u2, UFL_WERE))) {
/* werewolves can't be given to non-werewolves and vice-versa */
error = 312;
} else if (u2 && u2->number != 0 && u_race(u2) != u_race(u)) {
}
else if (u2 && u2->number != 0 && u_race(u2) != u_race(u)) {
log_warning("faction %s attempts to give %s to %s.\n", itoa36(u->faction->no), u_race(u)->_name[0], u_race(u2)->_name[1]);
error = 139;
} else if (u2 != NULL && (get_racename(u2->attribs)
}
else if (u2 != NULL && (get_racename(u2->attribs)
|| get_racename(u->attribs))) {
error = 139;
} else if (u2 && u2->faction != u->faction && !rule_transfermen()) {
}
else if (u2 && u2->faction != u->faction && !rule_transfermen()) {
error = 74;
} else {
}
else {
if (n > u->number)
n = u->number;
if (u2 && n + u2->number > UNIT_MAXSIZE) {
@ -231,18 +249,23 @@ void give_men(int n, unit * u, unit * u2, struct order *ord)
}
if (n == 0) {
error = 96;
} else if (u2 && u->faction != u2->faction) {
}
else if (u2 && u->faction != u2->faction) {
if (u2->faction->newbies + n > MAXNEWBIES) {
error = 129;
} else if (u_race(u) != u2->faction->race) {
}
else if (u_race(u) != u2->faction->race) {
if (u2->faction->race != get_race(RC_HUMAN)) {
error = 120;
} else if (count_migrants(u2->faction) + n >
}
else if (count_migrants(u2->faction) + n >
count_maxmigrants(u2->faction)) {
error = 128;
} else if (has_limited_skills(u) || has_limited_skills(u2)) {
}
else if (has_limited_skills(u) || has_limited_skills(u2)) {
error = 154;
} else if (u2->number != 0) {
}
else if (u2->number != 0) {
error = 139;
}
}
@ -294,7 +317,8 @@ void give_men(int n, unit * u, unit * u2, struct order *ord)
if (u->faction != u2->faction) {
u2->faction->newbies += n;
}
} else {
}
else {
if (getunitpeasants) {
#ifdef ORCIFICATION
if (u_race(u) == get_race(RC_SNOTLING) && !fval(u->region, RF_ORCIFIED)) {
@ -305,17 +329,20 @@ void give_men(int n, unit * u, unit * u2, struct order *ord)
}
#endif
transfermen(u, NULL, n);
} else {
}
else {
error = 159;
}
}
}
if (error > 0) {
cmistake(u, ord, error, MSG_COMMERCE);
} else if (!u2) {
}
else if (!u2) {
ADDMSG(&u->faction->msgs,
msg_message("give_person_peasants", "unit amount", u, n));
} else if (u2->faction != u->faction) {
}
else if (u2->faction != u->faction) {
message *msg = msg_message("give_person", "unit target amount", u, u2, n);
add_message(&u->faction->msgs, msg);
add_message(&u2->faction->msgs, msg);
@ -350,7 +377,8 @@ void give_unit(unit * u, unit * u2, order * ord)
if (u2 == NULL) {
if (fval(r->terrain, SEA_REGION)) {
cmistake(u, ord, 152, MSG_COMMERCE);
} else if (getunitpeasants) {
}
else if (getunitpeasants) {
unit *u3;
for (u3 = r->units; u3; u3 = u3->next)
@ -371,7 +399,8 @@ void give_unit(unit * u, unit * u2, order * ord)
}
give_men(u->number, u, NULL, ord);
cmistake(u, ord, 153, MSG_COMMERCE);
} else {
}
else {
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "feedback_unit_not_found",
""));
}

View File

@ -1,7 +1,8 @@
/*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de>
Copyright (c) 1998-2014,
Enno Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
@ -127,7 +128,7 @@ float MagicPower(void)
static int a_readicastle(attrib * a, void *owner, struct storage *store)
{
icastle_data *data = (icastle_data *) a->data.v;
icastle_data *data = (icastle_data *)a->data.v;
variant bno;
char token[32];
READ_TOK(store, token, sizeof(token));
@ -145,7 +146,7 @@ static int a_readicastle(attrib * a, void *owner, struct storage *store)
static void
a_writeicastle(const attrib * a, const void *owner, struct storage *store)
{
icastle_data *data = (icastle_data *) a->data.v;
icastle_data *data = (icastle_data *)a->data.v;
WRITE_TOK(store, data->type->_name);
WRITE_INT(store, data->building->no);
WRITE_INT(store, data->time);
@ -153,7 +154,7 @@ a_writeicastle(const attrib * a, const void *owner, struct storage *store)
static int a_ageicastle(struct attrib *a)
{
icastle_data *data = (icastle_data *) a->data.v;
icastle_data *data = (icastle_data *)a->data.v;
if (data->time <= 0) {
building *b = data->building;
region *r = b->region;
@ -161,7 +162,8 @@ static int a_ageicastle(struct attrib *a)
/* remove_building lets units leave the building */
remove_building(&r->buildings, b);
return AT_AGE_REMOVE;
} else
}
else
data->time--;
return AT_AGE_KEEP;
}
@ -201,7 +203,7 @@ static void init_mage(attrib * a)
static void free_mage(attrib * a)
{
sc_mage *mage = (sc_mage *) a->data.v;
sc_mage *mage = (sc_mage *)a->data.v;
if (mage->spellbook) {
spellbook_clear(mage->spellbook);
free(mage->spellbook);
@ -220,7 +222,7 @@ int FactionSpells(void)
}
void read_spells(struct quicklist **slistp, magic_t mtype,
struct storage *store)
struct storage *store)
{
for (;;) {
spell *sp;
@ -231,8 +233,9 @@ void read_spells(struct quicklist **slistp, magic_t mtype,
READ_INT(store, &i);
if (i < 0)
break;
sp = find_spellbyid((unsigned int) i);
} else {
sp = find_spellbyid((unsigned int)i);
}
else {
READ_TOK(store, spname, sizeof(spname));
if (strcmp(spname, "end") == 0)
break;
@ -258,7 +261,7 @@ int get_spell_level_mage(const spell * sp, void * cbdata)
static int read_mage(attrib * a, void *owner, struct storage *store)
{
int i, mtype;
sc_mage *mage = (sc_mage *) a->data.v;
sc_mage *mage = (sc_mage *)a->data.v;
char spname[64];
READ_INT(store, &mtype);
@ -273,9 +276,10 @@ static int read_mage(attrib * a, void *owner, struct storage *store)
READ_INT(store, &spid);
READ_INT(store, &level);
if (spid >= 0) {
sp = find_spellbyid((unsigned int) spid);
sp = find_spellbyid((unsigned int)spid);
}
} else {
}
else {
READ_TOK(store, spname, sizeof(spname));
READ_INT(store, &level);
@ -300,9 +304,10 @@ static int read_mage(attrib * a, void *owner, struct storage *store)
}
}
}
if (mage->magietyp==M_GRAY) {
if (mage->magietyp == M_GRAY) {
read_spellbook(&mage->spellbook, store, get_spell_level_mage, mage);
} else {
}
else {
read_spellbook(0, store, 0, mage);
}
return AT_READ_OK;
@ -314,7 +319,7 @@ void write_spells(struct quicklist *slist, struct storage *store)
int qi;
for (ql = slist, qi = 0; ql; ql_advance(&ql, &qi, 1)) {
spell *sp = (spell *) ql_get(ql, qi);
spell *sp = (spell *)ql_get(ql, qi);
WRITE_TOK(store, sp->sname);
}
WRITE_TOK(store, "end");
@ -324,7 +329,7 @@ static void
write_mage(const attrib * a, const void *owner, struct storage *store)
{
int i;
sc_mage *mage = (sc_mage *) a->data.v;
sc_mage *mage = (sc_mage *)a->data.v;
WRITE_INT(store, mage->magietyp);
WRITE_INT(store, mage->spellpoints);
@ -359,7 +364,7 @@ sc_mage *get_mage(const unit * u)
if (a)
return a->data.v;
}
return (sc_mage *) NULL;
return (sc_mage *)NULL;
}
/* ------------------------------------------------------------- */
@ -379,9 +384,10 @@ static int read_seenspell(attrib * a, void *owner, struct storage *store)
READ_TOK(store, token, sizeof(token));
i = atoi(token);
if (i != 0) {
sp = find_spellbyid((unsigned int) i);
} else {
if (global.data_version<UNIQUE_SPELLS_VERSION) {
sp = find_spellbyid((unsigned int)i);
}
else {
if (global.data_version < UNIQUE_SPELLS_VERSION) {
READ_INT(store, 0); /* ignore mtype */
}
sp = find_spell(token);
@ -428,7 +434,7 @@ void show_new_spells(faction * f, int level, const spellbook *book)
int qi;
for (qi = 0; ql; ql_advance(&ql, &qi, 1)) {
spellbook_entry *sbe = (spellbook_entry *) ql_get(ql, qi);
spellbook_entry *sbe = (spellbook_entry *)ql_get(ql, qi);
if (sbe->level <= level) {
if (!already_seen(f, sbe->sp)) {
@ -458,7 +464,7 @@ void pick_random_spells(faction * f, int level, spellbook * book, int num_spells
}
for (qi = 0, ql = book->spells; ql; ql_advance(&ql, &qi, 1)) {
spellbook_entry * sbe = (spellbook_entry *) ql_get(ql, qi);
spellbook_entry * sbe = (spellbook_entry *)ql_get(ql, qi);
if (sbe->level <= level) {
commonspells[numspells++] = sbe;
}
@ -475,20 +481,21 @@ void pick_random_spells(faction * f, int level, spellbook * book, int num_spells
while (!sbe && maxspell>0) {
spellno = rng_int() % maxspell;
sbe = commonspells[spellno];
if (sbe->level>f->max_spelllevel) {
if (sbe->level > f->max_spelllevel) {
commonspells[spellno] = commonspells[--maxspell];
commonspells[maxspell] = sbe;
sbe = 0;
} else if (f->spellbook && spellbook_get(f->spellbook, sbe->sp)) {
}
else if (f->spellbook && spellbook_get(f->spellbook, sbe->sp)) {
commonspells[spellno] = commonspells[--numspells];
if (maxspell>numspells) {
if (maxspell > numspells) {
maxspell = numspells;
}
sbe = 0;
}
}
if (spellno<maxspell) {
if (spellno < maxspell) {
if (!f->spellbook) {
f->spellbook = create_spellbook(0);
}
@ -525,7 +532,7 @@ int u_hasspell(const unit *u, const struct spell *sp)
spellbook * book = unit_get_spellbook(u);
spellbook_entry * sbe = book ? spellbook_get(book, sp) : 0;
if (sbe) {
return sbe->level<=effskill(u, SK_MAGIC);
return sbe->level <= effskill(u, SK_MAGIC);
}
return 0;
}
@ -556,7 +563,8 @@ const spell *get_combatspell(const unit * u, int nr)
m = get_mage(u);
if (m) {
return m->combatspells[nr].sp;
} else if (u_race(u)->precombatspell != NULL) {
}
else if (u_race(u)->precombatspell != NULL) {
return u_race(u)->precombatspell;
}
@ -613,15 +621,18 @@ void unset_combatspell(unit * u, spell * sp)
for (i = 0; i < MAXCOMBATSPELLS; i++) {
m->combatspells[i].sp = NULL;
}
} else if (sp->sptyp & PRECOMBATSPELL) {
}
else if (sp->sptyp & PRECOMBATSPELL) {
if (sp != get_combatspell(u, 0))
return;
} else if (sp->sptyp & COMBATSPELL) {
}
else if (sp->sptyp & COMBATSPELL) {
if (sp != get_combatspell(u, 1)) {
return;
}
nr = 1;
} else if (sp->sptyp & POSTCOMBATSPELL) {
}
else if (sp->sptyp & POSTCOMBATSPELL) {
if (sp != get_combatspell(u, 2)) {
return;
}
@ -842,7 +853,8 @@ int eff_spelllevel(unit * u, const spell * sp, int cast_level, int range)
* gezauberten Sprüche abhängig */
if (sp->components[k].type == r_aura) {
needplevel = spellcost(u, sp) * range;
} else {
}
else {
needplevel = sp->components[k].amount * range;
}
maxlevel =
@ -856,12 +868,14 @@ int eff_spelllevel(unit * u, const spell * sp, int cast_level, int range)
cast_level = 0;
/* ansonsten wird das Minimum aus maximal möglicher Stufe und der
* gewünschten gebildet */
} else if (sp->components[k].cost == SPC_LEVEL) {
}
else if (sp->components[k].cost == SPC_LEVEL) {
costtyp = SPC_LEVEL;
cast_level = _min(cast_level, maxlevel);
/* bei Typ Linear müssen die Kosten in Höhe der Stufe vorhanden
* sein, ansonsten schlägt der Spruch fehl */
} else if (sp->components[k].cost == SPC_LINEAR) {
}
else if (sp->components[k].cost == SPC_LINEAR) {
costtyp = SPC_LINEAR;
if (maxlevel < cast_level)
cast_level = 0;
@ -896,11 +910,12 @@ void pay_spell(unit * u, const spell * sp, int cast_level, int range)
int k;
int resuse;
assert(cast_level>0);
assert(cast_level > 0);
for (k = 0; sp->components[k].type; k++) {
if (sp->components[k].type == r_aura) {
resuse = spellcost(u, sp) * range;
} else {
}
else {
resuse = sp->components[k].amount * range;
}
@ -926,7 +941,7 @@ bool knowsspell(const region * r, const unit * u, const spell * sp)
return false;
}
/* steht der Spruch in der Spruchliste? */
return u_hasspell(u, sp)!=0;
return u_hasspell(u, sp) != 0;
}
/* Um einen Spruch zu beherrschen, muss der Magier die Stufe des
@ -965,7 +980,8 @@ cancast(unit * u, const spell * sp, int level, int range, struct order * ord)
* gezauberten Sprüche abhängig */
if (rtype == r_aura) {
itemanz = spellcost(u, sp) * range;
} else {
}
else {
itemanz = sp->components[k].amount * range;
}
@ -1020,7 +1036,8 @@ spellpower(region * r, unit * u, const spell * sp, int cast_level, struct order
if (sp == NULL) {
return 0;
} else {
}
else {
/* Bonus durch Magieturm und gesegneten Steinkreis */
struct building *b = inside_building(u);
const struct building_type *btype = b ? b->type : NULL;
@ -1048,7 +1065,8 @@ spellpower(region * r, unit * u, const spell * sp, int cast_level, struct order
if (force > 0) {
ADDMSG(&mage->faction->msgs, msg_message("reduce_spell",
"self mage region", mage, u, r));
} else {
}
else {
ADDMSG(&mage->faction->msgs, msg_message("block_spell",
"self mage region", mage, u, r));
}
@ -1066,7 +1084,8 @@ spellpower(region * r, unit * u, const spell * sp, int cast_level, struct order
if (force > 0) {
ADDMSG(&mage->faction->msgs, msg_message("reduce_spell",
"self mage region", mage, u, r));
} else {
}
else {
ADDMSG(&mage->faction->msgs, msg_message("block_spell",
"self mage region", mage, u, r));
}
@ -1115,7 +1134,7 @@ double magic_resistance(unit * target)
attrib *a;
curse *c;
int n;
const curse_type * ct_goodresist = 0, * ct_badresist = 0;
const curse_type * ct_goodresist = 0, *ct_badresist = 0;
const resource_type *rtype;
double probability = u_race(target)->magres;
@ -1143,7 +1162,7 @@ double magic_resistance(unit * target)
ct_goodresist = ct_find("goodmagicresistancezone");
}
while (a && a->type == &at_curse) {
curse *c = (curse *) a->data.v;
curse *c = (curse *)a->data.v;
unit *mage = c->magician;
if (mage != NULL) {
@ -1152,7 +1171,8 @@ double magic_resistance(unit * target)
probability += curse_geteffect(c) * 0.01;
ct_goodresist = 0; /* only one effect per region */
}
} else if (ct_badresist && c->type == ct_badresist) {
}
else if (ct_badresist && c->type == ct_badresist) {
if (!alliedunit(mage, target->faction, HELP_GUARD)) {
probability -= curse_geteffect(c) * 0.01;
ct_badresist = 0; /* only one effect per region */
@ -1202,7 +1222,7 @@ target_resists_magic(unit * magician, void *obj, int objtyp, int t_bonus)
{
int at, pa = 0;
skill *sv;
unit *u = (unit *) obj;
unit *u = (unit *)obj;
at = effskill(magician, SK_MAGIC);
@ -1215,30 +1235,30 @@ target_resists_magic(unit * magician, void *obj, int objtyp, int t_bonus)
/* Contest */
probability = 0.05 * (10 + pa - at);
probability += magic_resistance((unit *) obj);
probability += magic_resistance((unit *)obj);
break;
}
case TYP_REGION:
/* Bonus durch Zauber */
probability +=
0.01 * get_curseeffect(((region *) obj)->attribs, C_RESIST_MAGIC, 0);
0.01 * get_curseeffect(((region *)obj)->attribs, C_RESIST_MAGIC, 0);
break;
case TYP_BUILDING:
/* Bonus durch Zauber */
probability +=
0.01 * get_curseeffect(((building *) obj)->attribs, C_RESIST_MAGIC, 0);
0.01 * get_curseeffect(((building *)obj)->attribs, C_RESIST_MAGIC, 0);
/* Bonus durch Typ */
probability += 0.01 * ((building *) obj)->type->magres;
probability += 0.01 * ((building *)obj)->type->magres;
break;
case TYP_SHIP:
/* Bonus durch Zauber */
probability +=
0.01 * get_curseeffect(((ship *) obj)->attribs, C_RESIST_MAGIC, 0);
0.01 * get_curseeffect(((ship *)obj)->attribs, C_RESIST_MAGIC, 0);
break;
}
@ -1255,7 +1275,7 @@ target_resists_magic(unit * magician, void *obj, int objtyp, int t_bonus)
bool is_magic_resistant(unit * magician, unit * target, int resist_bonus)
{
return (bool) target_resists_magic(magician, target, TYP_UNIT,
return (bool)target_resists_magic(magician, target, TYP_UNIT,
resist_bonus);
}
@ -1272,7 +1292,7 @@ bool is_magic_resistant(unit * magician, unit * target, int resist_bonus)
bool fumble(region * r, unit * u, const spell * sp, int cast_grade)
{
/* X ergibt Zahl zwischen 1 und 0, je kleiner, desto besser der Magier.
/* X ergibt Zahl zwischen 1 und 0, je kleiner, desto besser der Magier.
* 0,5*40-20=0, dh wenn der Magier doppelt so gut ist, wie der Spruch
* benötigt, gelingt er immer, ist er gleich gut, gelingt der Spruch mit
* 20% Warscheinlichkeit nicht
@ -1380,7 +1400,7 @@ static void do_fumble(castorder * co)
case 2:
/* temporary skill loss */
duration = _max(rng_int() % level / 2, 2);
effect = -(float)level/2;
effect = -(float)level / 2;
c = create_curse(u, &u->attribs, ct_find("skillmod"), (float)level,
duration, effect, 1);
c->data.i = SK_MAGIC;
@ -1502,7 +1522,7 @@ void regenerate_aura(void)
static bool
verify_ship(region * r, unit * mage, const spell * sp, spllprm * spobj,
order * ord)
order * ord)
{
ship *sh = findship(spobj->data.i);
@ -1525,7 +1545,7 @@ verify_ship(region * r, unit * mage, const spell * sp, spllprm * spobj,
static bool
verify_building(region * r, unit * mage, const spell * sp, spllprm * spobj,
order * ord)
order * ord)
{
building *b = findbuilding(spobj->data.i);
@ -1555,7 +1575,8 @@ message *msg_unitnotfound(const struct unit * mage, struct order * ord,
if (spobj->typ == SPP_UNIT) {
uid = itoa36(spobj->data.i);
} else {
}
else {
sprintf(tbuf, "%s %s", LOC(mage->faction->locale,
parameters[P_TEMP]), itoa36(spobj->data.i));
uid = tbuf;
@ -1566,7 +1587,7 @@ message *msg_unitnotfound(const struct unit * mage, struct order * ord,
static bool
verify_unit(region * r, unit * mage, const spell * sp, spllprm * spobj,
order * ord)
order * ord)
{
unit *u = NULL;
switch (spobj->typ) {
@ -1737,7 +1758,8 @@ verify_targets(castorder * co, int *invalid, int *resist, int *success)
break;
}
}
} else {
}
else {
/* der Zauber hat keine expliziten Parameter/Ziele, es kann sich
* aber um einen Regionszauber handeln. Wenn notwendig hier die
* Magieresistenz der Region prüfen. */
@ -1761,13 +1783,16 @@ verify_targets(castorder * co, int *invalid, int *resist, int *success)
"unit region command", mage, mage->region, co->order));
spobj->flag = TARGET_RESISTS;
++*resist;
} else {
}
else {
++*success;
}
} else {
}
else {
++*success;
}
} else {
}
else {
++*success;
}
}
@ -1846,14 +1871,15 @@ static int addparam_building(const char *const param[], spllprm ** spobjp)
static int
addparam_region(const char *const param[], spllprm ** spobjp, const unit * u,
order * ord, plane * pl)
order * ord, plane * pl)
{
assert(param[0]);
if (param[1] == 0) {
/* Fehler: Zielregion vergessen */
cmistake(u, ord, 194, MSG_MAGIC);
return -1;
} else {
}
else {
int tx = atoi((const char *)param[0]), ty = atoi((const char *)param[1]);
int x = rel_to_abs(pl, u->faction, tx, 0);
int y = rel_to_abs(pl, u->faction, ty, 1);
@ -1868,7 +1894,8 @@ addparam_region(const char *const param[], spllprm ** spobjp, const unit * u,
spobj->flag = 0;
spobj->typ = SPP_REGION;
spobj->data.r = rt;
} else {
}
else {
/* Fehler: Zielregion vergessen */
cmistake(u, ord, 194, MSG_MAGIC);
return -1;
@ -1879,7 +1906,7 @@ addparam_region(const char *const param[], spllprm ** spobjp, const unit * u,
static int
addparam_unit(const char *const param[], spllprm ** spobjp, const unit * u,
order * ord)
order * ord)
{
spllprm *spobj;
int i = 0;
@ -2125,7 +2152,7 @@ bool is_familiar(const unit * u)
static void
a_write_unit(const attrib * a, const void *owner, struct storage *store)
{
unit *u = (unit *) a->data.v;
unit *u = (unit *)a->data.v;
write_unit_reference(u, store);
}
@ -2153,14 +2180,14 @@ static void set_familiar(unit * mage, unit * familiar)
/* if the skill modifier for the mage does not yet exist, add it */
attrib *a = a_find(mage->attribs, &at_skillmod);
while (a && a->type == &at_skillmod) {
skillmod_data *smd = (skillmod_data *) a->data.v;
skillmod_data *smd = (skillmod_data *)a->data.v;
if (smd->special == sm_familiar)
break;
a = a->next;
}
if (a == NULL) {
attrib *an = a_add(&mage->attribs, a_new(&at_skillmod));
skillmod_data *smd = (skillmod_data *) an->data.v;
skillmod_data *smd = (skillmod_data *)an->data.v;
smd->special = sm_familiar;
smd->skill = NOSKILL;
}
@ -2169,7 +2196,8 @@ static void set_familiar(unit * mage, unit * familiar)
if (a == NULL) {
a = a_add(&mage->attribs, a_new(&at_familiar));
a->data.v = familiar;
} else
}
else
assert(!a->data.v || a->data.v == familiar);
/* TODO: Diese Attribute beim Tod des Familiars entfernen: */
@ -2177,7 +2205,8 @@ static void set_familiar(unit * mage, unit * familiar)
if (a == NULL) {
a = a_add(&familiar->attribs, a_new(&at_familiarmage));
a->data.v = mage;
} else
}
else
assert(!a->data.v || a->data.v == mage);
}
@ -2193,7 +2222,7 @@ void remove_familiar(unit * mage)
a = a_find(mage->attribs, &at_skillmod);
while (a && a->type == &at_skillmod) {
an = a->next;
smd = (skillmod_data *) a->data.v;
smd = (skillmod_data *)a->data.v;
if (smd->special == sm_familiar)
a_remove(&mage->attribs, a);
a = an;
@ -2224,14 +2253,14 @@ bool create_newfamiliar(unit * mage, unit * familiar)
a = a_find(mage->attribs, &at_skillmod);
while (a && a->type == &at_skillmod) {
skillmod_data *smd = (skillmod_data *) a->data.v;
skillmod_data *smd = (skillmod_data *)a->data.v;
if (smd->special == sm_familiar)
break;
a = a->next;
}
if (a == NULL) {
attrib *an = a_add(&mage->attribs, a_new(&at_skillmod));
skillmod_data *smd = (skillmod_data *) an->data.v;
skillmod_data *smd = (skillmod_data *)an->data.v;
smd->special = sm_familiar;
smd->skill = NOSKILL;
}
@ -2245,11 +2274,11 @@ static int resolve_familiar(variant data, void *addr)
if (result == 0 && familiar) {
attrib *a = a_find(familiar->attribs, &at_familiarmage);
if (a != NULL && a->data.v) {
unit *mage = (unit *) a->data.v;
unit *mage = (unit *)a->data.v;
set_familiar(mage, familiar);
}
}
*(unit **) addr = familiar;
*(unit **)addr = familiar;
return result;
}
@ -2273,7 +2302,8 @@ void create_newclone(unit * mage, unit * clone)
if (a == NULL) {
a = a_add(&mage->attribs, a_new(&at_clone));
a->data.v = clone;
} else
}
else
assert(!a->data.v || a->data.v == clone);
/* TODO: Diese Attribute beim Tod des Klons entfernen: */
@ -2281,7 +2311,8 @@ void create_newclone(unit * mage, unit * clone)
if (a == NULL) {
a = a_add(&clone->attribs, a_new(&at_clonemage));
a->data.v = mage;
} else
}
else
assert(!a->data.v || a->data.v == mage);
/* Wenn der Magier stirbt, wird das in destroy_unit abgefangen.
@ -2299,14 +2330,16 @@ static void set_clone(unit * mage, unit * clone)
if (a == NULL) {
a = a_add(&mage->attribs, a_new(&at_clone));
a->data.v = clone;
} else
}
else
assert(!a->data.v || a->data.v == clone);
a = a_find(clone->attribs, &at_clonemage);
if (a == NULL) {
a = a_add(&clone->attribs, a_new(&at_clonemage));
a->data.v = mage;
} else
}
else
assert(!a->data.v || a->data.v == mage);
}
@ -2314,7 +2347,7 @@ unit *has_clone(unit * mage)
{
attrib *a = a_find(mage->attribs, &at_clone);
if (a)
return (unit *) a->data.v;
return (unit *)a->data.v;
return NULL;
}
@ -2325,11 +2358,11 @@ static int resolve_clone(variant data, void *addr)
if (result == 0 && clone) {
attrib *a = a_find(clone->attribs, &at_clonemage);
if (a != NULL && a->data.v) {
unit *mage = (unit *) a->data.v;
unit *mage = (unit *)a->data.v;
set_clone(mage, clone);
}
}
*(unit **) addr = clone;
*(unit **)addr = clone;
return result;
}
@ -2352,11 +2385,11 @@ static int resolve_mage(variant data, void *addr)
if (result == 0 && mage) {
attrib *a = a_find(mage->attribs, &at_familiar);
if (a != NULL && a->data.v) {
unit *familiar = (unit *) a->data.v;
unit *familiar = (unit *)a->data.v;
set_familiar(mage, familiar);
}
}
*(unit **) addr = mage;
*(unit **)addr = mage;
return result;
}
@ -2373,7 +2406,7 @@ static int read_magician(attrib * a, void *owner, struct storage *store)
static int age_unit(attrib * a)
/* if unit is gone or dead, remove the attribute */
{
unit *u = (unit *) a->data.v;
unit *u = (unit *)a->data.v;
return (u != NULL && u->number > 0) ? AT_AGE_KEEP : AT_AGE_REMOVE;
}
@ -2421,7 +2454,7 @@ unit *get_familiar(const unit * u)
{
attrib *a = a_find(u->attribs, &at_familiar);
if (a != NULL) {
unit *u = (unit *) a->data.v;
unit *u = (unit *)a->data.v;
if (u->number > 0)
return u;
}
@ -2432,7 +2465,7 @@ unit *get_familiar_mage(const unit * u)
{
attrib *a = a_find(u->attribs, &at_familiarmage);
if (a != NULL) {
unit *u = (unit *) a->data.v;
unit *u = (unit *)a->data.v;
if (u->number > 0)
return u;
}
@ -2443,7 +2476,7 @@ unit *get_clone(const unit * u)
{
attrib *a = a_find(u->attribs, &at_clone);
if (a != NULL) {
unit *u = (unit *) a->data.v;
unit *u = (unit *)a->data.v;
if (u->number > 0)
return u;
}
@ -2454,7 +2487,7 @@ unit *get_clone_mage(const unit * u)
{
attrib *a = a_find(u->attribs, &at_clonemage);
if (a != NULL) {
unit *u = (unit *) a->data.v;
unit *u = (unit *)a->data.v;
if (u->number > 0)
return u;
}
@ -2562,7 +2595,8 @@ static castorder *cast_cmd(unit * u, order * ord)
if (caster) {
familiar = u;
sp = unit_getspell(caster, s, caster->faction->locale);
} else {
}
else {
/* somehow, this familiar has no mage! */
log_error("cast_cmd: familiar %s is without a mage?\n", unitname(u));
caster = u;
@ -2604,7 +2638,8 @@ static castorder *cast_cmd(unit * u, order * ord)
}
/* Auf bewegenden Schiffen kann man nur explizit als
* ONSHIPCAST deklarierte Zauber sprechen */
} else if (u->ship) {
}
else if (u->ship) {
if (is_moving_ship(r, u->ship)) {
if (!(sp->sptyp & ONSHIPCAST)) {
/* Fehler: "Diesen Spruch kann man nicht auf einem sich
@ -2817,7 +2852,8 @@ void magic(void)
/* kein Ziel gefunden, Fehlermeldungen sind in verify_targets */
/* keine kosten für den zauber */
continue; /* äußere Schleife, nächster Zauberer */
} else if (co->force > 0 && resist > 0) {
}
else if (co->force > 0 && resist > 0) {
/* einige oder alle Ziele waren magieresistent */
if (success == 0) {
co->force = 0;
@ -2834,7 +2870,8 @@ void magic(void)
if (fumble(target_r, u, sp, co->level)) {
/* zuerst bezahlen, dann evt in do_fumble alle Aura verlieren */
fumbled = true;
} else {
}
else {
co->level = sp->cast(co);
if (co->level <= 0) {
/* Kosten nur für real benötige Stufe berechnen */
@ -2843,7 +2880,7 @@ void magic(void)
}
}
/* erst bezahlen, dann Kostenzähler erhöhen */
if (co->level>0) {
if (co->level > 0) {
pay_spell(u, sp, co->level, co->distance);
}
if (fumbled) {
@ -2902,7 +2939,8 @@ spell *unit_getspell(struct unit *u, const char *name, const struct locale * lan
const char *n = spell_name(sp, lang);
if (!n) {
log_error("no translation in locale %s for spell %s\n", locale_name(lang), sp->sname);
} else {
}
else {
token.v = sp;
addtoken(&tokens, n, token);
}
@ -2912,7 +2950,7 @@ spell *unit_getspell(struct unit *u, const char *name, const struct locale * lan
if (tokens) {
if (findtoken(tokens, name, &token) != E_TOK_NOMATCH) {
freetokens(tokens);
return (spell *) token.v;
return (spell *)token.v;
}
freetokens(tokens);
}
@ -2930,10 +2968,11 @@ spellbook * get_spellbook(const char * name)
if (cb_find_prefix(&cb_spellbooks, name, strlen(name), &match, 1, 0)) {
cb_get_kv(match, &result, sizeof(result));
} else {
}
else {
size_t len = strlen(name);
result = create_spellbook(name);
assert(strlen(name)+sizeof(result)<sizeof(buffer));
assert(strlen(name) + sizeof(result) < sizeof(buffer));
len = cb_new_kv(name, len, &result, sizeof(result), buffer);
cb_insert(&cb_spellbooks, buffer, len);
}

View File

@ -1,7 +1,7 @@
/*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de>
Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
@ -97,7 +97,7 @@ typedef struct follower {
static void
get_followers(unit * target, region * r, const region_list * route_end,
follower ** followers)
follower ** followers)
{
unit *uf;
for (uf = r->units; uf; uf = uf->next) {
@ -127,7 +127,7 @@ static void shiptrail_finalize(attrib * a)
static int shiptrail_age(attrib * a)
{
traveldir *t = (traveldir *) (a->data.v);
traveldir *t = (traveldir *)(a->data.v);
t->age--;
return (t->age > 0) ? AT_AGE_KEEP : AT_AGE_REMOVE;
@ -136,7 +136,7 @@ static int shiptrail_age(attrib * a)
static int shiptrail_read(attrib * a, void *owner, struct storage *store)
{
int n;
traveldir *t = (traveldir *) (a->data.v);
traveldir *t = (traveldir *)(a->data.v);
READ_INT(store, &t->no);
READ_INT(store, &n);
@ -148,7 +148,7 @@ static int shiptrail_read(attrib * a, void *owner, struct storage *store)
static void
shiptrail_write(const attrib * a, const void *owner, struct storage *store)
{
traveldir *t = (traveldir *) (a->data.v);
traveldir *t = (traveldir *)(a->data.v);
WRITE_INT(store, t->no);
WRITE_INT(store, t->dir);
WRITE_INT(store, t->age);
@ -217,7 +217,7 @@ static int eff_weight(const unit * u)
static void
get_transporters(const item * itm, int *p_animals, int *p_acap, int *p_vehicles,
int *p_vcap)
int *p_vcap)
{
int vehicles = 0, vcap = 0;
int animals = 0, acap = 0;
@ -286,7 +286,8 @@ int walkingcapacity(const struct unit *u)
if (fval(u_race(u), RCF_HORSE)) {
animals += u->number;
people = 0;
} else {
}
else {
people = u->number;
}
@ -425,7 +426,8 @@ static int canride(unit * u)
for (itm = u->items; itm; itm = itm->next) {
if (itm->type == it_horse || itm->type == it_charger) {
horses += itm->number;
} else if (itm->type == it_elvenhorse) {
}
else if (itm->type == it_elvenhorse) {
unicorns += itm->number;
}
}
@ -457,7 +459,8 @@ static bool cansail(const region * r, ship * sh)
if (sh->type->construction && sh->size != sh->type->construction->maxsize) {
return false;
} else {
}
else {
int n = 0, p = 0;
int mweight = shipcapacity(sh);
int mcabins = sh->type->cabins;
@ -550,7 +553,7 @@ static void leave_trail(ship * sh, region * from, region_list * route)
attrib *a = a_find(r->attribs, &at_shiptrail);
while (a != NULL && a->type == &at_shiptrail) {
td = (traveldir *) a->data.v;
td = (traveldir *)a->data.v;
if (td->no == sh->no)
break;
a = a->next;
@ -558,7 +561,7 @@ static void leave_trail(ship * sh, region * from, region_list * route)
if (a == NULL || a->type != &at_shiptrail) {
a = a_add(&(r->attribs), a_new(&at_shiptrail));
td = (traveldir *) a->data.v;
td = (traveldir *)a->data.v;
td->no = sh->no;
}
td->dir = dir;
@ -571,7 +574,7 @@ static void leave_trail(ship * sh, region * from, region_list * route)
static void
mark_travelthru(const unit * u, region * r, const region_list * route,
const region_list * route_end)
const region_list * route_end)
{
/* kein travelthru in der letzten region! */
while (route != route_end) {
@ -685,10 +688,12 @@ static void set_coast(ship * sh, region * r, region * rnext)
{
if (sh->type->flags & SFL_NOCOAST) {
sh->coast = NODIRECTION;
} else if (!fval(rnext->terrain, SEA_REGION) && !flying_ship(sh)) {
}
else if (!fval(rnext->terrain, SEA_REGION) && !flying_ship(sh)) {
sh->coast = reldirection(rnext, r);
assert(fval(r->terrain, SEA_REGION));
} else {
}
else {
sh->coast = NODIRECTION;
}
}
@ -705,7 +710,7 @@ static float damage_drift(void)
static void drifting_ships(region * r)
{
direction_t d;
bool drift = get_param_int(global.parameters, "rules.ship.drifting", 1)!=0;
bool drift = get_param_int(global.parameters, "rules.ship.drifting", 1) != 0;
if (fval(r->terrain, SEA_REGION)) {
ship **shp = &r->ships;
@ -752,7 +757,7 @@ static void drifting_ships(region * r)
d_offset = rng_int() % MAXDIRECTIONS;
for (d = 0; d != MAXDIRECTIONS; ++d) {
region *rn;
dir = (direction_t) ((d + d_offset) % MAXDIRECTIONS);
dir = (direction_t)((d + d_offset) % MAXDIRECTIONS);
rn = rconnect(r, dir);
if (rn != NULL && fval(rn->terrain, SAIL_INTO) && check_ship_allowed(sh, rn) > 0) {
rnext = rn;
@ -807,7 +812,7 @@ static void drifting_ships(region * r)
static bool present(region * r, unit * u)
{
return (bool) (u && u->region == r);
return (bool)(u && u->region == r);
}
static void caught_target(region * r, unit * u)
@ -819,12 +824,13 @@ static void caught_target(region * r, unit * u)
* Umstaenden eine Warnung. */
if (a) {
unit *target = (unit *) a->data.v;
unit *target = (unit *)a->data.v;
if (!present(r, target)) {
ADDMSG(&u->faction->msgs, msg_message("followfail", "unit follower",
target, u));
} else if (!alliedunit(target, u->faction, HELP_ALL)
}
else if (!alliedunit(target, u->faction, HELP_ALL)
&& cansee(target->faction, r, u, 0)) {
ADDMSG(&target->faction->msgs, msg_message("followdetect",
"unit follower", target, u));
@ -873,7 +879,7 @@ static unit *bewegung_blockiert_von(unit * reisender, region * r)
else if (sk >= stealth) {
double prob_u = (sk - stealth) * skill_prob;
/* amulet counts at most once */
prob_u += _min (1, _min(u->number, i_get(u->items, ramulet->itype))) * amulet_prob;
prob_u += _min(1, _min(u->number, i_get(u->items, ramulet->itype))) * amulet_prob;
if (prob_u >= prob) {
prob = prob_u;
guard = u;
@ -915,7 +921,7 @@ static bool is_guardian_r(const unit * guard)
return false;
/* if region_owners exist then they may be guardians: */
if (guard->building && rule_region_owners() && guard==building_owner(guard->building)) {
if (guard->building && rule_region_owners() && guard == building_owner(guard->building)) {
faction *owner = region_get_owner(guard->region);
if (owner == guard->faction) {
building *bowner = largestbuilding(guard->region, &cmp_taxes, false);
@ -979,7 +985,8 @@ unit *is_guarded(region * r, unit * u, unsigned int mask)
return NULL;
}
u2 = guard;
} else {
}
else {
/* exhausted all the guards in the cache, but maybe we'll find one later? */
break;
}
@ -1052,10 +1059,12 @@ static void cycle_route(order * ord, unit * u, int gereist)
d = get_direction(token, lang);
if (d == D_PAUSE) {
pause = true;
} else if (d == NODIRECTION) {
}
else if (d == NODIRECTION) {
break;
}
} else {
}
else {
break;
}
if (cm < gereist) {
@ -1072,7 +1081,8 @@ static void cycle_route(order * ord, unit * u, int gereist)
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
}
} else if (strlen(neworder) > sizeof(neworder) / 2)
}
else if (strlen(neworder) > sizeof(neworder) / 2)
break;
else if (cm == gereist && !paused && pause) {
const char *loc = LOC(lang, parameters[P_PAUSE]);
@ -1083,14 +1093,16 @@ static void cycle_route(order * ord, unit * u, int gereist)
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
paused = true;
} else if (pause) {
}
else if (pause) {
/* da PAUSE nicht in ein shortdirections[d] umgesetzt wird (ist
* hier keine normale direction), muss jede PAUSE einzeln
* herausgefiltert und explizit gesetzt werden */
if (neworder[0])
strcat(neworder, " ");
strcat(neworder, LOC(lang, parameters[P_PAUSE]));
} else {
}
else {
if (neworder[0])
strcat(neworder, " ");
strcat(neworder, LOC(lang, shortdirections[d]));
@ -1099,7 +1111,8 @@ static void cycle_route(order * ord, unit * u, int gereist)
if (neworder[0]) {
norder = create_order(K_ROUTE, u->faction->locale, "%s %s", neworder, tail);
} else {
}
else {
norder = create_order(K_ROUTE, u->faction->locale, "%s", tail);
}
replace_order(&u->orders, ord, norder);
@ -1161,7 +1174,8 @@ static void init_transportation(void)
if (!transport(ut, u)) {
if (cansee(u->faction, r, ut, 0)) {
cmistake(u, u->thisorder, 286, MSG_MOVE);
} else {
}
else {
ADDMSG(&u->faction->msgs, msg_feedback(u, u->thisorder,
"feedback_unit_not_found", ""));
}
@ -1429,9 +1443,9 @@ static arg_regions *var_copy_regions(const region_list * begin, int size)
if (size > 0) {
int i = 0;
arg_regions *dst =
(arg_regions *) malloc(sizeof(arg_regions) + sizeof(region *) * size);
(arg_regions *)malloc(sizeof(arg_regions) + sizeof(region *) * size);
dst->nregions = size;
dst->regions = (region **) (dst + 1);
dst->regions = (region **)(dst + 1);
for (rsrc = begin; i != size; rsrc = rsrc->next) {
dst->regions[i++] = rsrc->data;
}
@ -1481,18 +1495,21 @@ static const region_list *travel_route(unit * u,
break;
}
landing = true;
} else if ((u_race(u)->flags & RCF_WALK) == 0) {
}
else if ((u_race(u)->flags & RCF_WALK) == 0) {
/* Spezialeinheiten, die nicht laufen können. */
ADDMSG(&u->faction->msgs, msg_message("detectocean",
"unit region", u, next));
break;
} else if (landing) {
}
else if (landing) {
/* wir sind diese woche angelandet */
ADDMSG(&u->faction->msgs, msg_message("detectocean",
"unit region", u, next));
break;
}
} else {
}
else {
/* Ozeanfelder können nur von Einheiten mit Schwimmen und ohne
* Pferde betreten werden. */
if (!(canswim(u) || canfly(u))) {
@ -1583,7 +1600,8 @@ static const region_list *travel_route(unit * u,
if (canride(u)) {
walkmode = 1;
produceexp(u, SK_RIDING, u->number);
} else {
}
else {
walkmode = 2;
}
@ -1608,7 +1626,7 @@ static const region_list *travel_route(unit * u,
static bool ship_ready(const region * r, unit * u)
{
if (!u->ship || u!=ship_owner(u->ship)) {
if (!u->ship || u != ship_owner(u->ship)) {
cmistake(u, u->thisorder, 146, MSG_MOVE);
return false;
}
@ -1625,7 +1643,7 @@ static bool ship_ready(const region * r, unit * u)
}
if (!enoughsailors(u->ship, r)) {
cmistake(u, u->thisorder, 1, MSG_MOVE);
/* mistake(u, u->thisorder,
/* mistake(u, u->thisorder,
"Auf dem Schiff befinden sich zuwenig erfahrene Seeleute.", MSG_MOVE); */
return false;
}
@ -1673,9 +1691,9 @@ static bool check_takeoff(ship * sh, region * from, region * to)
if (!fval(from->terrain, SEA_REGION) && sh->coast != NODIRECTION) {
direction_t coast = sh->coast;
direction_t dir = reldirection(from, to);
direction_t coastr = (direction_t) ((coast + 1) % MAXDIRECTIONS);
direction_t coastr = (direction_t)((coast + 1) % MAXDIRECTIONS);
direction_t coastl =
(direction_t) ((coast + MAXDIRECTIONS - 1) % MAXDIRECTIONS);
(direction_t)((coast + MAXDIRECTIONS - 1) % MAXDIRECTIONS);
if (dir != coast && dir != coastl && dir != coastr
&& !buildingtype_exists(from, bt_find("harbour"), true)) {
@ -1739,7 +1757,7 @@ sail(unit * u, order * ord, bool move_on_land, region_list ** routep)
assert(sh == u->ship || !"ship has sunk, but we didn't notice it");
if (fval(next_point->terrain, FORBIDDEN_REGION)||fval(next_point,RF_BLOCKED)) {
if (fval(next_point->terrain, FORBIDDEN_REGION) || fval(next_point, RF_BLOCKED)) {
ADDMSG(&f->msgs, msg_message("sailforbidden",
"ship region", sh, next_point));
break;
@ -1752,7 +1770,7 @@ sail(unit * u, order * ord, bool move_on_land, region_list ** routep)
int reason;
if (gamecookie != global.cookie) {
bool storms_enabled = get_param_int(global.parameters, "rules.ship.storms", 1)!=0;
bool storms_enabled = get_param_int(global.parameters, "rules.ship.storms", 1) != 0;
if (storms_enabled) {
gamedate date;
get_gamedate(turn, &date);
@ -1781,7 +1799,7 @@ sail(unit * u, order * ord, bool move_on_land, region_list ** routep)
direction_t d;
/* Sturm nur, wenn nächste Region Hochsee ist. */
for (d = 0; d != MAXDIRECTIONS; ++d) {
direction_t dnext = (direction_t) ((d + d_offset) % MAXDIRECTIONS);
direction_t dnext = (direction_t)((d + d_offset) % MAXDIRECTIONS);
region *rn = rconnect(current_point, dnext);
if (rn != NULL) {
@ -1819,14 +1837,16 @@ sail(unit * u, order * ord, bool move_on_land, region_list ** routep)
"ship region", sh, next_point));
break;
}
} else {
}
else {
if (!check_takeoff(sh, current_point, next_point)) {
/* Schiff kann nicht ablegen */
cmistake(u, ord, 182, MSG_MOVE);
break;
}
}
} else if (fval(tnext, SEA_REGION)) {
}
else if (fval(tnext, SEA_REGION)) {
/* target region is an ocean, and we're not leaving a shore */
if (!(sh->type->flags & SFL_OPENSEA)) {
/* ship can only stay close to shore */
@ -1846,11 +1866,12 @@ sail(unit * u, order * ord, bool move_on_land, region_list ** routep)
}
reason = check_ship_allowed(sh, next_point);
if (reason<0) {
if (reason < 0) {
/* for some reason or another, we aren't allowed in there.. */
if (check_leuchtturm(current_point, NULL) || reason == SA_NO_INSECT) {
ADDMSG(&f->msgs, msg_message("sailnolandingstorm", "ship region", sh, next_point));
} else {
}
else {
float dmg =
get_param_flt(global.parameters, "rules.ship.damage.nolanding",
0.10F);
@ -1931,7 +1952,8 @@ sail(unit * u, order * ord, bool move_on_land, region_list ** routep)
if (is_cursed(sh->attribs, C_SHIP_FLYING, 0)) {
ADDMSG(&f->msgs, msg_message("shipfly", "ship from to", sh,
starting_point, current_point));
} else {
}
else {
ADDMSG(&f->msgs, msg_message("shipsail", "ship from to", sh,
starting_point, current_point));
}
@ -2061,9 +2083,11 @@ static const region_list *travel_i(unit * u, const region_list * route_begin,
if (ut->building && !can_leave(ut)) {
cmistake(ut, ut->thisorder, 150, MSG_MOVE);
cmistake(u, ord, 99, MSG_MOVE);
} else if (!can_move(ut)) {
}
else if (!can_move(ut)) {
cmistake(u, ord, 99, MSG_MOVE);
} else {
}
else {
bool found = false;
if (!fval(ut, UFL_NOTMOVING) && !LongHunger(ut)) {
@ -2085,14 +2109,16 @@ static const region_list *travel_i(unit * u, const region_list * route_begin,
if (!found) {
if (cansee(u->faction, u->region, ut, 0)) {
cmistake(u, ord, 90, MSG_MOVE);
} else {
}
else {
ADDMSG(&u->faction->msgs, msg_feedback(u, ord,
"feedback_unit_not_found", ""));
}
}
}
}
} else {
}
else {
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "feedback_unit_not_found",
""));
}
@ -2139,7 +2165,8 @@ static void travel(unit * u, region_list ** routep)
cmistake(u, u->thisorder, 143, MSG_MOVE);
return;
}
} else if (u->ship && fval(u->ship, SF_MOVED)) {
}
else if (u->ship && fval(u->ship, SF_MOVED)) {
/* die Einheit ist auf einem Schiff, das sich bereits bewegt hat */
cmistake(u, u->thisorder, 13, MSG_MOVE);
return;
@ -2184,9 +2211,10 @@ static void move(unit * u, bool move_on_land)
region_list *route = NULL;
assert(u->number);
if (u->ship && u==ship_owner(u->ship)) {
if (u->ship && u == ship_owner(u->ship)) {
sail(u, u->thisorder, move_on_land, &route);
} else {
}
else {
travel(u, &route);
}
@ -2252,7 +2280,7 @@ static void piracy_cmd(unit * u, struct order *ord)
return;
}
if (!u->ship || u!=ship_owner(u->ship)) {
if (!u->ship || u != ship_owner(u->ship)) {
cmistake(u, ord, 146, MSG_MOVE);
return;
}
@ -2373,7 +2401,7 @@ static direction_t hunted_dir(attrib * at, int id)
direction_t d = NODIRECTION;
while (a != NULL && a->type == &at_shiptrail) {
traveldir *t = (traveldir *) (a->data.v);
traveldir *t = (traveldir *)(a->data.v);
if (t->no == id) {
d = t->dir;
/* do not break, because we want the last one for this ship */
@ -2394,13 +2422,16 @@ static int hunt(unit * u, order * ord)
if (fval(u, UFL_NOTMOVING)) {
return 0;
} else if (!u->ship) {
}
else if (!u->ship) {
cmistake(u, ord, 144, MSG_MOVE);
return 0;
} else if (u!=ship_owner(u->ship)) {
}
else if (u != ship_owner(u->ship)) {
cmistake(u, ord, 146, MSG_MOVE);
return 0;
} else if (!can_move(u)) {
}
else if (!can_move(u)) {
cmistake(u, ord, 55, MSG_MOVE);
return 0;
}
@ -2432,7 +2463,8 @@ static int hunt(unit * u, order * ord)
speed = getuint();
if (speed == 0) {
speed = shipspeed(u->ship, u);
} else {
}
else {
int maxspeed = shipspeed(u->ship, u);
if (maxspeed < speed)
speed = maxspeed;
@ -2513,7 +2545,8 @@ static void move_hunters(void)
if (fval(u, UFL_NOTMOVING)) {
cmistake(u, ord, 52, MSG_MOVE);
break;
} else if (!can_move(u)) {
}
else if (!can_move(u)) {
cmistake(u, ord, 55, MSG_MOVE);
break;
}
@ -2552,7 +2585,8 @@ static void move_pirates(void)
if (*up == u) {
/* not moved, use next unit */
up = &u->next;
} else if (*up && (*up)->region != r) {
}
else if (*up && (*up)->region != r) {
/* moved the previous unit along with u (units on same ship)
* must start from the beginning again */
up = &r->units;
@ -2602,25 +2636,30 @@ void movement(void)
if (fval(u, UFL_LONGACTION)) {
cmistake(u, u->thisorder, 52, MSG_MOVE);
set_order(&u->thisorder, NULL);
} else {
}
else {
cmistake(u, u->thisorder, 319, MSG_MOVE);
set_order(&u->thisorder, NULL);
}
} else if (fval(u, UFL_MOVED)) {
}
else if (fval(u, UFL_MOVED)) {
cmistake(u, u->thisorder, 187, MSG_MOVE);
set_order(&u->thisorder, NULL);
} else if (!can_move(u)) {
}
else if (!can_move(u)) {
cmistake(u, u->thisorder, 55, MSG_MOVE);
set_order(&u->thisorder, NULL);
} else {
}
else {
if (ships) {
if (u->ship && ship_owner(u->ship)==u) {
if (u->ship && ship_owner(u->ship) == u) {
init_tokens(u->thisorder);
skip_token();
move(u, false);
}
} else {
if (!u->ship || ship_owner(u->ship)!=u) {
}
else {
if (!u->ship || ship_owner(u->ship) != u) {
init_tokens(u->thisorder);
skip_token();
move(u, false);
@ -2631,13 +2670,15 @@ void movement(void)
if (u->region == r) {
/* not moved, use next unit */
up = &u->next;
} else {
}
else {
if (*up && (*up)->region != r) {
/* moved the upcoming unit along with u (units on ships or followers,
* for example). must start from the beginning again immediately */
up = &r->units;
repeat = false;
} else {
}
else {
repeat = true;
}
}
@ -2690,10 +2731,12 @@ void follow_unit(unit * u)
unit *uf = findunit(id);
if (!a) {
a = a_add(&u->attribs, make_follow(uf));
} else {
}
else {
a->data.v = uf;
}
} else if (a) {
}
else if (a) {
a_remove(&u->attribs, a);
a = NULL;
}
@ -2726,7 +2769,7 @@ void follow_unit(unit * u)
}
}
if ((a || followship )&& !fval(u, UFL_MOVED | UFL_NOTMOVING)) {
if ((a || followship) && !fval(u, UFL_MOVED | UFL_NOTMOVING)) {
if (!followship) {
u2 = a->data.v;
}

View File

@ -8,7 +8,7 @@
This program may not be used, modified or distributed
without prior permission by the authors of Eressea.
*/
*/
#include <platform.h>
#include <kernel/config.h>
@ -103,7 +103,8 @@ static char* get_command(const order *ord, char *sbuffer, size_t size) {
if (size > 0) {
*bufp++ = '@';
--size;
} else {
}
else {
WARN_STATIC_BUFFER();
}
}
@ -116,7 +117,8 @@ static char* get_command(const order *ord, char *sbuffer, size_t size) {
bytes = (int)strlcpy(bufp, str, size);
if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER();
if (text) *bufp++ = ' ';
} else {
}
else {
WARN_STATIC_BUFFER();
}
}
@ -158,7 +160,7 @@ void free_order(order * ord)
order *copy_order(const order * src)
{
if (src != NULL) {
order *ord = (order *) malloc(sizeof(order));
order *ord = (order *)malloc(sizeof(order));
ord->next = NULL;
ord->_persistent = src->_persistent;
ord->data = src->data;
@ -208,11 +210,11 @@ static order_data *create_data(keyword_t kwd, const char *sptr, int lindex)
data = locale_array[lindex]->study_orders[sk];
if (data == NULL) {
const char *skname = skillname(sk, lang);
data = (order_data *) malloc(sizeof(order_data));
data = (order_data *)malloc(sizeof(order_data));
locale_array[lindex]->study_orders[sk] = data;
data->_keyword = kwd;
data->_lindex = lindex;
assert(data->_lindex>=0);
assert(data->_lindex >= 0);
if (strchr(skname, ' ') != NULL) {
size_t len = strlen(skname);
data->_str = malloc(len + 3);
@ -220,7 +222,8 @@ static order_data *create_data(keyword_t kwd, const char *sptr, int lindex)
memcpy(data->_str + 1, skname, len);
data->_str[len + 1] = '\"';
data->_str[len + 2] = '\0';
} else {
}
else {
data->_str = _strdup(skname);
}
data->_refcount = 1;
@ -234,21 +237,21 @@ static order_data *create_data(keyword_t kwd, const char *sptr, int lindex)
else if (kwd != NOKEYWORD && *sptr == 0) {
data = locale_array[lindex]->short_orders[kwd];
if (data == NULL) {
data = (order_data *) malloc(sizeof(order_data));
data = (order_data *)malloc(sizeof(order_data));
locale_array[lindex]->short_orders[kwd] = data;
data->_keyword = kwd;
data->_lindex = lindex;
assert(data->_lindex>=0);
assert(data->_lindex >= 0);
data->_str = NULL;
data->_refcount = 1;
}
++data->_refcount;
return data;
}
data = (order_data *) malloc(sizeof(order_data));
data = (order_data *)malloc(sizeof(order_data));
data->_keyword = kwd;
data->_lindex = lindex;
assert(data->_lindex>=0);
assert(data->_lindex >= 0);
data->_str = s ? _strdup(s) : NULL;
data->_refcount = 1;
return data;
@ -276,12 +279,12 @@ static order *create_order_i(keyword_t kwd, const char *sptr, int persistent,
break;
}
if (lindex == nlocales) {
locale_array[nlocales] = (locale_data *) calloc(1, sizeof(locale_data));
locale_array[nlocales] = (locale_data *)calloc(1, sizeof(locale_data));
locale_array[nlocales]->lang = lang;
++nlocales;
}
ord = (order *) malloc(sizeof(order));
ord = (order *)malloc(sizeof(order));
ord->_persistent = persistent;
ord->next = NULL;
@ -328,7 +331,8 @@ order *create_order(keyword_t kwd, const struct locale * lang,
default:
assert(!"unknown format-character in create_order");
}
} else if (size > 0) {
}
else if (size > 0) {
*bufp++ = *params;
--size;
}
@ -336,7 +340,8 @@ order *create_order(keyword_t kwd, const struct locale * lang,
}
va_end(marker);
*bufp = 0;
} else {
}
else {
zBuffer[0] = 0;
}
return create_order_i(kwd, zBuffer, 0, lang);
@ -563,12 +568,14 @@ char *write_order(const order * ord, char *buffer, size_t size)
{
if (ord == 0) {
buffer[0] = 0;
} else {
}
else {
keyword_t kwd = ORD_KEYWORD(ord);
if (kwd == NOKEYWORD) {
const char *text = ORD_STRING(ord);
strlcpy(buffer, (const char *)text, size);
} else {
}
else {
get_command(ord, buffer, size);
}
}

View File

@ -1,5 +1,6 @@
/*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
Copyright (c) 1998-2014,
Enno Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de>