Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfixes Ritual der Aufnahme / Migrantenwerben #1065

Merged
merged 2 commits into from
Apr 7, 2024
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
32 changes: 16 additions & 16 deletions scripts/tests/e2/migration.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ end

function test_migration_success()
local r = region.create(0, 0, "plain")
local f = faction.create('human')
local f = faction.create('elf')
local u = setup_mage(f, r)
local u2 = unit.create(faction.create('human'), r)
local u2 = unit.create(faction.create('dwarf'), r)
u2:add_order('KONTAKTIERE ' .. itoa36(u.id))
u:add_order('ZAUBERE STUFE 1 "Ritual der Aufnahme" ' .. itoa36(u2.id))
u.aura = 9
Expand All @@ -40,9 +40,9 @@ end

function test_migration_no_familiars()
local r = region.create(0, 0, "plain")
local f = faction.create('human')
local f = faction.create('elf')
local u = setup_mage(f, r)
local f2 = faction.create('human')
local f2 = faction.create('dwarf')
local u2 = setup_mage(f2, r)
local u3 = unit.create(f2, r)
u3.race = 'goblin'
Expand All @@ -60,9 +60,9 @@ end

function test_migration_no_contact()
local r = region.create(0, 0, "plain")
local f = faction.create('human')
local f = faction.create('elf')
local u = setup_mage(f, r)
local u2 = unit.create(faction.create('human'), r)
local u2 = unit.create(faction.create('dwarf'), r)
u:add_order('ZAUBERE STUFE 1 "Ritual der Aufnahme" ' .. itoa36(u2.id))
u.aura = 9
u.aura_max = 9
Expand All @@ -74,9 +74,9 @@ end

function test_migration_too_many()
local r = region.create(0, 0, "plain")
local f = faction.create('human')
local f = faction.create('elf')
local u = setup_mage(f, r)
local u2 = unit.create(faction.create('human'), r)
local u2 = unit.create(faction.create('dwarf'), r)
u2:add_order('KONTAKTIERE ' .. itoa36(u.id))
u2.number = 2
u:add_order('ZAUBERE STUFE 1 "Ritual der Aufnahme" ' .. itoa36(u2.id))
Expand All @@ -90,9 +90,9 @@ end

function test_migration_with_ring()
local r = region.create(0, 0, "plain")
local f = faction.create('human')
local f = faction.create('elf')
local u = setup_mage(f, r)
local u2 = unit.create(faction.create('human'), r)
local u2 = unit.create(faction.create('dwarf'), r)
u2:add_order('KONTAKTIERE ' .. itoa36(u.id))
u2.number = 2
u:add_item('rop', 1)
Expand All @@ -109,9 +109,9 @@ end
function test_migration_insufficient_aura()
-- if unit cannot pay full costs, it casts at a lower level.
local r = region.create(0, 0, "plain")
local f = faction.create('human')
local f = faction.create('elf')
local u = setup_mage(f, r)
local u2 = unit.create(faction.create('human'), r)
local u2 = unit.create(faction.create('dwarf'), r)
u2:add_order('KONTAKTIERE ' .. itoa36(u.id))
u2.number = 2
u:add_order('ZAUBERE STUFE 2 "Ritual der Aufnahme" ' .. itoa36(u2.id))
Expand All @@ -127,9 +127,9 @@ end
function test_migration_insufficient_max_aura()
-- if unit cannot pay full costs, it casts at a lower level.
local r = region.create(0, 0, "plain")
local f = faction.create('human')
local f = faction.create('elf')
local u = setup_mage(f, r)
local u2 = unit.create(faction.create('human'), r)
local u2 = unit.create(faction.create('dwarf'), r)
u2:add_order('KONTAKTIERE ' .. itoa36(u.id))
u2.number = 2
u:add_order('ZAUBERE STUFE 2 "Ritual der Aufnahme" ' .. itoa36(u2.id))
Expand All @@ -145,9 +145,9 @@ end
function test_migration_reduced_cost()
-- if unit cannot pay full costs, it casts at a lower level.
local r = region.create(0, 0, "plain")
local f = faction.create('human')
local f = faction.create('elf')
local u = setup_mage(f, r)
local u2 = unit.create(faction.create('human'), r)
local u2 = unit.create(faction.create('dwarf'), r)
u2:add_order('KONTAKTIERE ' .. itoa36(u.id))
u:add_order('ZAUBERE STUFE 2 "Ritual der Aufnahme" ' .. itoa36(u2.id))
u.aura = 3
Expand Down
2 changes: 2 additions & 0 deletions src/spells.c
Original file line number Diff line number Diff line change
Expand Up @@ -3728,10 +3728,12 @@ int sp_migranten(castorder * co)
/* u ist von unserer Art, das Ritual waere verschwendete Aura. */
ADDMSG(&mage->faction->msgs, msg_message("sp_migranten_fail1",
"unit region command target", mage, mage->region, co->order, target));
return 0;
}
/* Auf eigene Einheiten versucht zu zaubern? Garantiert Tippfehler */
if (target->faction == mage->faction) {
cmistake(mage, co->order, 45, MSG_MAGIC);
return 0;
}

/* Keine Monstereinheiten */
Expand Down
27 changes: 24 additions & 3 deletions src/spells.test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1032,22 +1032,40 @@ static void test_migrants(CuTest *tc) {
faction *f;
castorder co;
spellparameter param, * args = NULL;
const struct race* rc;

test_setup();
u = test_create_unit(f = test_create_faction(), test_create_plain(0, 0));
param.flag = TARGET_RESISTS;
param.flag = 0;
param.typ = SPP_UNIT;
param.data.u = u2 = test_create_unit(f = test_create_faction(), u->region);
param.data.u = u2 = test_create_unit(f, u->region);
arrput(args, param);
u2->orders = create_order(K_WORK, u2->faction->locale, NULL);
u_setrace(u2, test_create_race("hobgoblin"));
u_setrace(u2, rc = test_create_race("hobgoblin"));
test_create_castorder(&co, u, 4, 5.0, 0, args);

/* bug 3019: no pay when accidentally used on own units: */
CuAssertIntEquals(tc, 0, sp_migranten(&co));
CuAssertPtrNotNull(tc, test_find_faction_message(u->faction, "error45"));
u_setfaction(u2, f = test_create_faction());
test_clear_messages(u->faction);

/* only migrants are allowed, not units of our own race: */
u_setrace(u2, u->faction->race);
CuAssertIntEquals(tc, 0, sp_migranten(&co));
CuAssertPtrNotNull(tc, test_find_faction_message(u->faction, "sp_migranten_fail1"));
u_setrace(u2, rc);
test_clear_messages(u->faction);

co.a_params[0].flag = TARGET_RESISTS;
CuAssertIntEquals(tc, u2->number, sp_migranten(&co));
CuAssertPtrEquals(tc, f, u2->faction);
test_clear_messages(u->faction);

co.a_params[0].flag = TARGET_NOTFOUND;
CuAssertIntEquals(tc, 0, sp_migranten(&co));
CuAssertPtrEquals(tc, f, u2->faction);
test_clear_messages(u->faction);

/* no contact, no cost: */
co.a_params[0].flag = 0;
Expand All @@ -1060,7 +1078,10 @@ static void test_migrants(CuTest *tc) {
CuAssertIntEquals(tc, u2->number, sp_migranten(&co));
CuAssertPtrEquals(tc, u->faction, u2->faction);
CuAssertPtrEquals(tc, NULL, u2->orders);
test_clear_messages(u->faction);

test_teardown();

}

static void test_blessstonecircle(CuTest *tc) {
Expand Down