Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion scripts/tests/e2/economy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
1 change: 0 additions & 1 deletion src/alchemy.test.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

#include <util/base36.h>
#include <util/keyword.h>
#include <util/variant.h>

#include <kernel/attrib.h>
#include <kernel/event.h>
Expand Down
41 changes: 26 additions & 15 deletions src/battle.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down
5 changes: 3 additions & 2 deletions src/battle.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/battle.test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion src/recruit.test.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

#include "util/keyword.h" // for K_RECRUIT
#include "util/message.h"
#include "util/variant.h"

#include "stb_ds.h"

Expand Down
1 change: 0 additions & 1 deletion src/spells.test.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include "util/language.h"
#include "util/message.h"
#include "util/rand.h"
#include "util/variant.h" // for variant

#include <spells/borders.h>
#include <spells/regioncurse.h>
Expand Down
91 changes: 43 additions & 48 deletions src/spells/combatspells.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -1040,7 +1037,6 @@ int sp_frighten(struct castorder * co)
df->person[dt.index].defense -= df_malus;
targets++;
}
--force;
}

m =
Expand Down Expand Up @@ -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;

Expand All @@ -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);
Expand Down
1 change: 0 additions & 1 deletion src/steal.test.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include <util/base36.h>
#include <util/keyword.h>
#include <util/message.h>
#include <util/variant.h>

#include <stb_ds.h>

Expand Down
4 changes: 2 additions & 2 deletions src/tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down