diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 88ab34a28..4d39d0559 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -31,6 +31,10 @@ jobs: sudo apt install libutf8proc-dev libexpat1-dev liblua5.2-dev lua5.2 luarocks libtolua-dev libncurses5-dev libsqlite3-dev libiniparser-dev libcjson-dev libbsd-dev cppcheck shellcheck clang-tools iwyu luarocks install lunitx --local luarocks path + - name: print version numbers + run: | + iwyu --version + tolua -v # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - name: Checkout repository uses: actions/checkout@v6 diff --git a/scripts/tests/e2/economy.lua b/scripts/tests/e2/economy.lua index e85fc20a9..4cbda63ea 100644 --- a/scripts/tests/e2/economy.lua +++ b/scripts/tests/e2/economy.lua @@ -81,7 +81,6 @@ function test_guards_block_buy() local loc = "Juwel" r.luxury = lux u:add_item("money", 100000) - u.name = "Xolgrim" u:set_orders("KAUFE 1 " .. loc) process_orders() assert_equal(1, u:get_item(lux)) diff --git a/src/alchemy.test.c b/src/alchemy.test.c index c7892d5a0..fccb47feb 100644 --- a/src/alchemy.test.c +++ b/src/alchemy.test.c @@ -9,7 +9,6 @@ #include #include -#include #include #include diff --git a/src/battle.c b/src/battle.c index 536358dcb..e4edf1083 100644 --- a/src/battle.c +++ b/src/battle.c @@ -1454,6 +1454,28 @@ count_enemies(const fighter *af, int minrow, int maxrow, int select) return 0; } +bool escapes_tactics(const fighter *af, const troop dt) +{ + side *as = af->side; + battle *b = as->battle; + if (b->turn != 0) return false; + if (dt.fighter) { + if (rule_tactics_formula == 1) { + int tactics = get_tactics(as, dt.fighter->side); + + /* percentage chance to get this attack */ + if (tactics > 0) { + double tacch = tactics_chance(af->unit, tactics); + return !chance(tacch); + } + else { + return false; + } + } + } + return true; +} + troop select_enemy(fighter * af, int minrow, int maxrow, int select) { side *as = af->side; @@ -1507,20 +1529,9 @@ troop select_enemy(fighter * af, int minrow, int maxrow, int select) troop dt; dt.index = selected; dt.fighter = df; - if (b->turn == 0 && dt.fighter) { - if (rule_tactics_formula == 1) { - int tactics = get_tactics(as, dt.fighter->side); - - /* percentage chance to get this attack */ - if (tactics > 0) { - double tacch = tactics_chance(af->unit, tactics); - if (!chance(tacch)) { - dt.fighter = NULL; - } - } - else { - dt.fighter = NULL; - } + if (0 == (select & SELECT_IGNORE_TACTICS)) { + if (escapes_tactics(af, dt)) { + dt.fighter = NULL; } } return dt; @@ -2545,7 +2556,7 @@ void loot_items(fighter * corpse) if (maxrow > 0) { if (looting == 1) { /* enemies get dibs */ - fig = select_enemy(corpse, FIGHT_ROW, maxrow, 0).fighter; + fig = select_enemy(corpse, FIGHT_ROW, maxrow, SELECT_IGNORE_TACTICS).fighter; } if (!fig) { /* self and allies get second pick */ diff --git a/src/battle.h b/src/battle.h index 5bd5d5662..26dfa4f9f 100644 --- a/src/battle.h +++ b/src/battle.h @@ -188,18 +188,19 @@ side* get_side(battle* b, const struct unit* u); void do_battles(void); /* for combat spells and special attacks */ -enum { SELECT_ADVANCE = 0x1, SELECT_DISTANCE = 0x2, SELECT_FIND = 0x4 }; +enum { SELECT_ADVANCE = 0x1, SELECT_DISTANCE = 0x2, SELECT_FIND = 0x4, SELECT_IGNORE_TACTICS = 0x8 }; enum { ALLY_SELF, ALLY_ANY }; int get_unitrow(const fighter* af, const side* vs); +int count_enemies(const struct fighter *af, int minrow, int maxrow, int select); +bool escapes_tactics(const fighter *af, const troop dt); troop select_enemy(struct fighter* af, int minrow, int maxrow, int select); troop select_ally(struct fighter* af, int minrow, int maxrow, int allytype); int get_tactics(const struct side* as, const struct side* ds); -int count_enemies(const struct fighter* af, int minrow, int maxrow, int select); int natural_armor(struct unit* u); const struct armor_type* select_armor(struct troop t, bool shield); const struct weapon* select_weapon(const struct troop t, bool attacking, bool ismissile); diff --git a/src/battle.test.c b/src/battle.test.c index 9ba14b10e..47c173295 100644 --- a/src/battle.test.c +++ b/src/battle.test.c @@ -247,7 +247,7 @@ static void test_select_enemy(CuTest * tc) CuAssertIntEquals(tc, E_ENEMY|E_ATTACKING, get_relation(as, ds)); CuAssertIntEquals(tc, E_ENEMY, get_relation(ds, as)); - at = select_enemy(df, FIRST_ROW, LAST_ROW, SELECT_ADVANCE); + at = select_enemy(df, FIRST_ROW, LAST_ROW, SELECT_ADVANCE|SELECT_IGNORE_TACTICS); CuAssertPtrEquals(tc, af, at.fighter); free_battle(b); diff --git a/src/recruit.test.c b/src/recruit.test.c index 7c7f8fa8a..ef67e2942 100644 --- a/src/recruit.test.c +++ b/src/recruit.test.c @@ -12,7 +12,6 @@ #include "util/keyword.h" // for K_RECRUIT #include "util/message.h" -#include "util/variant.h" #include "stb_ds.h" diff --git a/src/spells.test.c b/src/spells.test.c index 4e860d9b2..8c0b8fdb1 100644 --- a/src/spells.test.c +++ b/src/spells.test.c @@ -29,7 +29,6 @@ #include "util/language.h" #include "util/message.h" #include "util/rand.h" -#include "util/variant.h" // for variant #include #include diff --git a/src/spells/combatspells.c b/src/spells/combatspells.c index a621b3833..6ccb7b991 100644 --- a/src/spells/combatspells.c +++ b/src/spells/combatspells.c @@ -174,15 +174,16 @@ int sp_petrify(struct castorder * co) return 0; } - while (force && stoned < enemies) { + while (force-- && stoned < enemies) { troop dt = select_enemy(fi, FIGHT_ROW, BEHIND_ROW, SELECT_ADVANCE); - unit *du = dt.fighter->unit; - if (!is_magic_resistant(mage, du, 0)) { - /* person ans ende hinter die lebenden schieben */ - remove_troop(dt); - ++stoned; + if (dt.fighter) { + unit *du = dt.fighter->unit; + if (!is_magic_resistant(mage, du, 0)) { + /* person ans ende hinter die lebenden schieben */ + remove_troop(dt); + ++stoned; + } } - --force; } m = msg_message("cast_petrify_effect", "mage spell amount", fi->unit, sp, @@ -220,15 +221,12 @@ int sp_stun(struct castorder * co) } stunned = 0; - while (force && stunned < enemies) { + while (force-- && stunned < enemies) { troop dt = select_enemy(fi, FIGHT_ROW, BEHIND_ROW, SELECT_ADVANCE); - fighter *df = dt.fighter; - if (df) { - unit *du = df->unit; - - --force; + if (dt.fighter) { + unit *du = dt.fighter->unit; if (!is_magic_resistant(mage, du, 0)) { - df->person[dt.index].flags |= FL_STUNNED; + dt.fighter->person[dt.index].flags |= FL_STUNNED; ++stunned; } } @@ -366,17 +364,16 @@ int sp_sleep(struct castorder * co) msg_release(m); return 0; } - while (force && enemies) { - unit *du; + while (force-- && enemies) { troop dt = select_enemy(fi, FIGHT_ROW, BEHIND_ROW, SELECT_ADVANCE); - assert(dt.fighter); - du = dt.fighter->unit; - if (!is_magic_resistant(mage, du, 0)) { - dt.fighter->person[dt.index].flags |= FL_SLEEPING; - ++k; - --enemies; + if (dt.fighter) { + unit *du = dt.fighter->unit; + if (!is_magic_resistant(mage, du, 0)) { + dt.fighter->person[dt.index].flags |= FL_SLEEPING; + ++k; + --enemies; + } } - --force; } m = msg_message("cast_sleep_effect", "mage spell amount", fi->unit, sp, k); @@ -490,32 +487,32 @@ int sp_mindblast(struct castorder * co) } while (force > 0 && enemies > 0) { - unit *du; - troop dt = select_enemy(fi, FIGHT_ROW, BEHIND_ROW, SELECT_ADVANCE); + troop dt = select_enemy(fi, FIGHT_ROW, BEHIND_ROW, SELECT_ADVANCE|SELECT_IGNORE_TACTICS); - assert(dt.fighter); - du = dt.fighter->unit; - if (du->flags & UFL_MARK) { - /* not this one again */ - continue; - } + if (dt.fighter) { + unit *du = dt.fighter->unit; + if (du->flags & UFL_MARK) { + /* not this one again */ + continue; + } - if (humanoidrace(u_race(du)) && force >= du->number) { - if (!is_magic_resistant(mage, du, 0)) { - skill_t sk = random_skill(du, true); - if (sk != NOSKILL) { - int n = 1 + rng_int() % maxloss; - attrib *a = make_skillmod(sk, NULL, 0.0, n); - /* neat: you can add a whole lot of these to a unit, they stack */ - a_add(&du->attribs, a); + if (humanoidrace(u_race(du)) && force >= du->number) { + if (!(is_magic_resistant(mage, du, 0) || escapes_tactics(fi, dt))) { + skill_t sk = random_skill(du, true); + if (sk != NOSKILL) { + int n = 1 + rng_int() % maxloss; + attrib *a = make_skillmod(sk, NULL, 0.0, n); + /* neat: you can add a whole lot of these to a unit, they stack */ + a_add(&du->attribs, a); + } + k += du->number; } - k += du->number; + force -= du->number; } - force -= du->number; + du->flags |= UFL_MARK; + reset = 1; + enemies -= du->number; } - du->flags |= UFL_MARK; - reset = 1; - enemies -= du->number; } if (reset) { @@ -1022,7 +1019,7 @@ int sp_frighten(struct castorder * co) return 0; } - while (force && enemies) { + while (force-- && enemies) { troop dt = select_enemy(fi, FIGHT_ROW, BEHIND_ROW - 1, SELECT_ADVANCE); fighter *df = dt.fighter; --enemies; @@ -1040,7 +1037,6 @@ int sp_frighten(struct castorder * co) df->person[dt.index].defense -= df_malus; targets++; } - --force; } m = @@ -1071,7 +1067,7 @@ int sp_tiredsoldiers(struct castorder * co) return 0; } - while (force) { + while (force--) { troop t = select_enemy(fi, FIGHT_ROW, BEHIND_ROW, SELECT_ADVANCE); fighter *df = t.fighter; @@ -1086,7 +1082,6 @@ int sp_tiredsoldiers(struct castorder * co) ++n; } } - --force; } m = msg_message("cast_tired_effect", "mage spell amount", fi->unit, sp, n); diff --git a/src/steal.test.c b/src/steal.test.c index c0b7d01ef..4e09bf28c 100644 --- a/src/steal.test.c +++ b/src/steal.test.c @@ -12,7 +12,6 @@ #include #include #include -#include #include diff --git a/src/tests.h b/src/tests.h index bcb3d097e..1b875805b 100644 --- a/src/tests.h +++ b/src/tests.h @@ -3,8 +3,8 @@ #define ASSERT_DBL_DELTA 0.001 -enum param_t; -enum skill_t; +#include "kernel/skill.h" // for skill_t +#include "util/param.h" // for param_t struct region; struct unit;