From 52ee682a4891660fdfceb2c4ed6ec2afab1685b6 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 2 Nov 2019 19:09:15 +0100 Subject: [PATCH 1/4] =?UTF-8?q?Bug=202617:=20Berechnung=20von=20=C3=9Cberl?= =?UTF-8?q?adung=20berechnet=20Flotten=20korrekt.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/move.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/move.c b/src/move.c index 0fc6f6411..e444ead56 100644 --- a/src/move.c +++ b/src/move.c @@ -501,7 +501,7 @@ static double overload(const region * r, ship * sh) double ovl; getshipweight(sh, &n, &p); - ovl = n / (double)sh->type->cargo; + ovl = n / (double)(sh->type->cargo * sh->number); if (mcabins) { ovl = fmax(ovl, p / (double)mcabins); } @@ -746,7 +746,7 @@ double damage_overload(double overload) } /* message to all factions in ship, start from firstu, end before lastu (may be NULL) */ -static void msg_to_ship_inmates(ship *sh, unit **firstu, unit **lastu, message *msg) { +static void msg_to_passengers(ship *sh, unit **firstu, unit **lastu, message *msg) { unit *u, *shipfirst = NULL; for (u = *firstu; u != *lastu; u = u->next) { if (u->ship == sh) { @@ -836,19 +836,19 @@ static void drifting_ships(region * r) if (rnext && firstu) { message *msg = msg_message("ship_drift", "ship dir", sh, dir); - msg_to_ship_inmates(sh, &firstu, &lastu, msg); + msg_to_passengers(sh, &firstu, &lastu, msg); } fset(sh, SF_DRIFTED); if (ovl >= overload_start()) { damage_ship(sh, damage_overload(ovl)); - msg_to_ship_inmates(sh, &firstu, &lastu, msg_message("massive_overload", "ship", sh)); + msg_to_passengers(sh, &firstu, &lastu, msg_message("massive_overload", "ship", sh)); } else { damage_ship(sh, damage_drift); } if (sh->damage >= sh->size * DAMAGE_SCALE) { - msg_to_ship_inmates(sh, &firstu, &lastu, msg_message("shipsink", "ship", sh)); + msg_to_passengers(sh, &firstu, &lastu, msg_message("shipsink", "ship", sh)); sink_ship(sh); remove_ship(shp, sh); } From fd1b981983f58b86838921fb2dcdfba655e69d33 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 2 Nov 2019 21:32:11 +0100 Subject: [PATCH 2/4] simplify sail/travel, remove route from arguments. --- src/move.c | 44 +++++++++++++++++--------------------------- 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/src/move.c b/src/move.c index e444ead56..d33987d54 100644 --- a/src/move.c +++ b/src/move.c @@ -1683,12 +1683,13 @@ bool can_takeoff(const ship * sh, const region * from, const region * to) return true; } -static void sail(unit * u, order * ord, region_list ** routep, bool drifting) +static void sail(unit * u, order * ord, bool drifting) { + region_list *route = NULL; region *starting_point = u->region; region *current_point, *last_point; int k, step = 0; - region_list **iroute = routep; + region_list **iroute = &route; ship *sh = u->ship; faction *f = u->faction; region *next_point = NULL; @@ -1698,10 +1699,6 @@ static void sail(unit * u, order * ord, region_list ** routep, bool drifting) int lighthouse_div = config_get_int("rules.storm.lighthouse.divisor", 0); const char *token = getstrtoken(); - if (routep) { - *routep = NULL; - } - error = movewhere(u, token, starting_point, &next_point); if (error) { message *msg = movement_error(u, token, ord, error); @@ -1940,7 +1937,7 @@ static void sail(unit * u, order * ord, region_list ** routep, bool drifting) if (fval(u, UFL_FOLLOWING)) caught_target(current_point, u); - move_ship(sh, starting_point, current_point, routep ? *routep : NULL); + move_ship(sh, starting_point, current_point, route); /* Hafengebuehren ? */ @@ -1982,6 +1979,7 @@ static void sail(unit * u, order * ord, region_list ** routep, bool drifting) } } } + free_regionlist(route); } /* Segeln, Wandern, Reiten @@ -2088,14 +2086,12 @@ static const region_list *travel_i(unit * u, const region_list * route_begin, /** traveling without ships * walking, flying or riding units use this function */ -static void travel(unit * u, order *ord, region_list ** routep) +static void travel(unit * u, order *ord) { - region *r = u->region; - region_list *route_begin; - follower *followers = NULL; + region_list *route = NULL; - assert(routep); - *routep = NULL; + region *r = u->region; + follower *followers = NULL; /* a few pre-checks that need not be done for each step: */ if (!fval(r->terrain, SEA_REGION)) { @@ -2131,12 +2127,10 @@ static void travel(unit * u, order *ord, region_list ** routep) return; } - make_route(u, ord, routep); - route_begin = *routep; - - if (route_begin) { + make_route(u, ord, &route); + if (route) { /* und ab die post: */ - travel_i(u, route_begin, NULL, ord, TRAVEL_NORMAL, &followers); + travel_i(u, route, NULL, ord, TRAVEL_NORMAL, &followers); /* followers */ while (followers != NULL) { @@ -2157,34 +2151,30 @@ static void travel(unit * u, order *ord, region_list ** routep) follow_order = create_order(K_FOLLOW, lang, "%s %i", s, ut->no); - route_end = reroute(uf, route_begin, route_end); - travel_i(uf, route_begin, route_end, follow_order, TRAVEL_FOLLOWING, + route_end = reroute(uf, route, route_end); + travel_i(uf, route, route_end, follow_order, TRAVEL_FOLLOWING, &followers); caught_target(uf->region, uf); free_order(follow_order); } } + free_regionlist(route); } } void move_cmd(unit * u, order * ord) { - region_list *route = NULL; - assert(u->number); if (u->ship && u == ship_owner(u->ship)) { bool drifting = (getkeyword(ord) == K_MOVE); - sail(u, ord, &route, drifting); + sail(u, ord, drifting); } else { - travel(u, ord, &route); + travel(u, ord); } fset(u, UFL_LONGACTION | UFL_NOTMOVING); set_order(&u->thisorder, NULL); - - if (route != NULL) - free_regionlist(route); } static void age_traveldir(region * r) From 7850e84cea5f48983a3e5ef3cf1fed8186a4e077 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 2 Nov 2019 21:37:33 +0100 Subject: [PATCH 3/4] let's try increasing MAX_UNITSIZE to 128K --- src/kernel/unit.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/kernel/unit.h b/src/kernel/unit.h index 863dccd13..c77cfdb7a 100644 --- a/src/kernel/unit.h +++ b/src/kernel/unit.h @@ -54,7 +54,7 @@ extern "C" { /* Flags, die gespeichert werden sollen: */ #define UFL_SAVEMASK (UFL_DEFENDER|UFL_MOVED|UFL_NOAID|UFL_ANON_FACTION|UFL_LOCKED|UFL_HUNGER|UFL_TAKEALL|UFL_GUARD|UFL_STEALTH|UFL_GROUP|UFL_HERO) -#define UNIT_MAXSIZE 50000 +#define UNIT_MAXSIZE 128 * 1024 extern int maxheroes(const struct faction *f); extern int countheroes(const struct faction *f); From 75000f266306d7f940c94f9f3381f12d316c290d Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 17 Nov 2019 19:55:41 +0100 Subject: [PATCH 4/4] reduce struct person by 12 bytes on a 32-bit arch. --- src/battle.c | 18 ++++-------------- src/battle.h | 16 ++++++++-------- src/exparse.c | 2 +- src/kernel/item.c | 2 +- src/kernel/item.h | 4 ++-- src/spells/combatspells.c | 2 +- 6 files changed, 17 insertions(+), 27 deletions(-) diff --git a/src/battle.c b/src/battle.c index 835917e62..a0e03f1f9 100644 --- a/src/battle.c +++ b/src/battle.c @@ -104,8 +104,6 @@ const troop no_troop = { 0, 0 }; #define LOOT_KEEPLOOT (1<<4) #define DAMAGE_CRITICAL (1<<0) -#define DAMAGE_MELEE_BONUS (1<<1) -#define DAMAGE_MISSILE_BONUS (1<<2) /* deprecated */ #define DAMAGE_SKILL_BONUS (1<<4) static int max_turns; @@ -117,7 +115,7 @@ static int flee_chance_skill_bonus; static int skill_formula; static int rule_cavalry_skill; static int rule_population_damage; -static int rule_hero_speed; +static unsigned char rule_hero_speed; static bool rule_anon_battle; static bool rule_igjarjuk_curse; static int rule_goblin_bonus; @@ -139,7 +137,7 @@ static void init_rules(void) rule_nat_armor = config_get_int("rules.combat.nat_armor", 0); rule_tactics_formula = config_get_int("rules.tactics.formula", 0); rule_goblin_bonus = config_get_int("rules.combat.goblinbonus", 10); - rule_hero_speed = config_get_int("rules.combat.herospeed", 10); + rule_hero_speed = (unsigned char)config_get_int("rules.combat.herospeed", 10); rule_population_damage = config_get_int("rules.combat.populationdamage", 20); rule_anon_battle = config_get_int("rules.stealth.anon_battle", 1) != 0; rule_igjarjuk_curse = config_get_int("rules.combat.igjarjuk_curse", 0) != 0; @@ -157,12 +155,6 @@ static void init_rules(void) if (config_get_int("rules.combat.critical", 1)) { rule_damage |= DAMAGE_CRITICAL; } - if (config_get_int("rules.combat.melee_bonus", 1)) { - rule_damage |= DAMAGE_MELEE_BONUS; - } - if (config_get_int("rules.combat.missile_bonus", 1)) { /* deprecated */ - rule_damage |= DAMAGE_MISSILE_BONUS; - } if (config_get_int("rules.combat.skill_bonus", 1)) { rule_damage |= DAMAGE_SKILL_BONUS; } @@ -1304,9 +1296,7 @@ terminate(troop dt, troop at, int type, const char *damage_formula, bool missile if (awtype == NULL || !fval(awtype, WTF_MISSILE)) { /* melee bonus */ - if (rule_damage & DAMAGE_MELEE_BONUS) { - damage += af->person[at.index].damage; - } + damage += af->person[at.index].damage; } /* Skilldifferenzbonus */ @@ -3158,7 +3148,7 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack) fig->person[i].hp++; if (i < speeded) - fig->person[i].speed = speed; + fig->person[i].speed = (unsigned char) speed; else fig->person[i].speed = 1; diff --git a/src/battle.h b/src/battle.h index 0ce76bfea..83bcaf09a 100644 --- a/src/battle.h +++ b/src/battle.h @@ -81,9 +81,9 @@ extern "C" { int nsides; struct selist *meffects; int max_tactics; - int turn; + unsigned char turn; + signed char keeploot; /* keep (50 + keeploot) percent of items as loot */ bool has_tactics_turn; - int keeploot; bool reelarrow; int alive; struct { @@ -153,13 +153,13 @@ extern "C" { int catmsg; /* Merkt sich, ob Katapultmessage schon generiert. */ struct person { int hp; /* Trefferpunkte der Personen */ - int attack; - int defense; - int damage; int flags; - int speed; - int reload; - int last_action; + int attack; /* weapon skill bonus for attacker */ + int defense; /* weapon skill bonus for defender */ + char damage; /* bonus damage for melee attacks (e.g. troll belt) */ + unsigned char speed; + unsigned char reload; + unsigned char last_action; struct weapon *missile; /* missile weapon */ struct weapon *melee; /* melee weapon */ } *person; diff --git a/src/exparse.c b/src/exparse.c index 4160b32ba..a9c21b025 100644 --- a/src/exparse.c +++ b/src/exparse.c @@ -280,7 +280,7 @@ static void handle_weapon(parseinfo *pi, const XML_Char *el, const XML_Char **at wtype->defmod = xml_int(attr[i + 1]); } else if (xml_strequal(attr[i], "reload")) { - wtype->reload = xml_int(attr[i + 1]); + wtype->reload = (unsigned char) xml_int(attr[i + 1]); } else if (xml_strequal(attr[i], "skill")) { wtype->skill = findskill(attr[i + 1]); diff --git a/src/kernel/item.c b/src/kernel/item.c index 1533d65bc..0d2764412 100644 --- a/src/kernel/item.c +++ b/src/kernel/item.c @@ -260,7 +260,7 @@ luxury_type *new_luxurytype(item_type * itype, int price) weapon_type *new_weapontype(item_type * itype, int wflags, variant magres, const char *damage[], int offmod, int defmod, - int reload, skill_t sk) + unsigned char reload, skill_t sk) { weapon_type *wtype; diff --git a/src/kernel/item.h b/src/kernel/item.h index 0b90b7b1e..46b27505f 100644 --- a/src/kernel/item.h +++ b/src/kernel/item.h @@ -169,7 +169,7 @@ extern "C" { int offmod; int defmod; variant magres; - int reload; /* time to reload this weapon */ + unsigned char reload; /* time to reload this weapon */ weapon_mod *modifiers; /* --- functions --- */ bool(*attack) (const struct troop *, const struct weapon_type *, @@ -208,7 +208,7 @@ extern "C" { item_type *it_get_or_create(resource_type *rtype); luxury_type *new_luxurytype(item_type * itype, int price); weapon_type *new_weapontype(item_type * itype, int wflags, - variant magres, const char *damage[], int offmod, int defmod, int reload, + variant magres, const char *damage[], int offmod, int defmod, unsigned char reload, skill_t sk); void free_wtype(struct weapon_type *wtype); armor_type *new_armortype(item_type * itype, double penalty, diff --git a/src/spells/combatspells.c b/src/spells/combatspells.c index f4b8b6954..dea37345b 100644 --- a/src/spells/combatspells.c +++ b/src/spells/combatspells.c @@ -1378,7 +1378,7 @@ int sp_keeploot(struct castorder * co) message_all(b, m); msg_release(m); - b->keeploot = (int)fmax(25, b->keeploot + 5 * power); + b->keeploot = (signed char) fmax(25, b->keeploot + 5 * power); return level; }