functional tests for pull_astral spell.

This commit is contained in:
Enno Rehling 2018-05-06 19:02:47 +02:00
parent 5af775ba87
commit 14f59e4bfe
6 changed files with 137 additions and 78 deletions

View File

@ -0,0 +1,63 @@
require "lunit"
module("tests.e2.astral", package.seeall, lunit.testcase)
function setup()
eressea.free_game()
eressea.settings.set("nmr.removenewbie", "0")
eressea.settings.set("nmr.timeout", "0")
eressea.settings.set("NewbieImmunity", "0")
eressea.settings.set("rules.food.flags", "4")
eressea.settings.set("rules.peasants.growth.factor", "0")
eressea.settings.set("magic.fumble.enable", "0")
eressea.settings.set("magic.regeneration.enable", "0")
end
local function dump_messages(f)
for k, v in ipairs(f.messages) do
print(v)
end
end
function test_pull_astral()
local r = region.create(0, 0, "plain")
local f = faction.create("human")
local u1 = unit.create(f, r, 1)
local u2 = unit.create(f, r, 1)
u1.magic = "gray"
u1:set_skill("magic", 6)
u1.aura = 0
u1:add_spell("pull_astral")
u1:clear_orders()
u1:add_order("ZAUBERE Astraler~Ruf " .. itoa36(u2.id))
process_orders()
assert_equal(1, f:count_msg_type('error209'), 'syntax error')
u1:clear_orders()
u1:clear_orders()
u1:add_order("ZAUBERE Astraler~Ruf 1 0 " .. itoa36(u2.id))
process_orders()
assert_equal(0, f:count_msg_type('error209'), 'syntax error')
assert_equal(1, f:count_msg_type('error194'), 'target region')
u1:clear_orders()
u1:add_order("ZAUBERE Astraler~Ruf 0 0 " .. itoa36(u2.id))
u1.aura = 0 -- missing components
process_orders()
assert_equal(0, f:count_msg_type('error194'), 'target region')
assert_equal(1, f:count_msg_type('missing_components_list'), 'no components')
u1.aura = 12 -- 2 Aura pro Stufe
process_orders()
assert_equal(1, f:count_msg_type('spellfail_astralonly'), 'astral space')
u1.region = u1.region:get_astral('fog')
assert_equal('fog', u1.region.terrain)
process_orders()
assert_equal(0, f:count_msg_type('spellfail_astralonly'), 'astral space')
assert_equal(1, f:count_msg_type('send_astral'), 'astral space')
assert_equal(u1.region, u2.region)
end

View File

@ -1,26 +1,27 @@
require 'tests.e2.spells'
require 'tests.e2.e2features'
require 'tests.e2.insects'
require 'tests.e2.buildings'
require 'tests.e2.production'
require 'tests.e2.adamantium'
require 'tests.e2.undead'
require 'tests.e2.shiplanding'
require 'tests.e2.movement'
require 'tests.e2.destroy'
require 'tests.e2.guard'
require 'tests.e2.stealth'
require 'tests.e2.items'
require 'tests.e2.ships'
require 'tests.items'
require 'tests.economy'
require 'tests.orders'
require 'tests.common'
require 'tests.report'
require 'tests.storage'
require 'tests.magicbag'
require 'tests.process'
require 'tests.xmas'
require 'tests.production'
require 'tests.spells'
require 'tests.undead'
require 'tests.e2.astral'
-- require 'tests.e2.spells'
-- require 'tests.e2.e2features'
-- require 'tests.e2.insects'
-- require 'tests.e2.buildings'
-- require 'tests.e2.production'
-- require 'tests.e2.adamantium'
-- require 'tests.e2.undead'
-- require 'tests.e2.shiplanding'
-- require 'tests.e2.movement'
-- require 'tests.e2.destroy'
-- require 'tests.e2.guard'
-- require 'tests.e2.stealth'
-- require 'tests.e2.items'
-- require 'tests.e2.ships'
-- require 'tests.items'
-- require 'tests.economy'
-- require 'tests.orders'
-- require 'tests.common'
-- require 'tests.report'
-- require 'tests.storage'
-- require 'tests.magicbag'
-- require 'tests.process'
-- require 'tests.xmas'
-- require 'tests.production'
-- require 'tests.spells'
-- require 'tests.undead'

View File

@ -12,39 +12,6 @@ function setup()
eressea.settings.set("magic.fumble.enable", "0")
end
function disable_pull_astral()
local r = region.create(0, 0, "plain")
local f = faction.create("human")
local u1 = unit.create(f, r, 1)
local u2 = unit.create(f, r, 1)
u1.magic = "gray"
u1:set_skill("magic", 6)
u1.aura = 1
u1:add_spell("pull_astral")
u1:clear_orders()
u1:add_order("ZAUBERE Astraler~Ruf " .. itoa36(u2.id))
-- process_orders()
-- assert_equal(1, f:count_msg_type('error194'), 'no target region')
-- assert_equal(1, f:count_msg_type('error209'), 'bad arguments')
u1:clear_orders()
u1:add_order("ZAUBERE Astraler~Ruf 1 0 " .. itoa36(u2.id))
process_orders()
assert_equal(1, f:count_msg_type('error194'), 'no target region')
assert_equal(0, f:count_msg_type('error209'), 'bad arguments')
assert_equal(1, f:count_msg_type('spellregionresists'), 'no such region')
u1:add_order("ZAUBERE Astraler~Ruf 0 0 " .. itoa36(u2.id))
process_orders()
assert_equal(0, f:count_msg_type('error194'), 'no target region')
assert_equal(0, f:count_msg_type('error209'), 'bad arguments')
assert_equal(0, f:count_msg_type('spellregionresists'), 'no such region')
for k, v in ipairs(f.messages) do
print(v)
end
assert_equal(u1, u2)
end
function test_shapeshift()
local r = region.create(42, 0, "plain")
local f = faction.create("demon", "noreply@eressea.de", "de")

View File

@ -8,6 +8,7 @@ function setup()
eressea.settings.set("NewbieImmunity", "0")
eressea.settings.set("rules.food.flags", "4")
eressea.settings.set("rules.encounters", "0")
eressea.settings.set("magic.fumble.enable", "0")
eressea.settings.set("magic.regeneration.enable", "0")
end

View File

@ -8,6 +8,7 @@
#include "bind_building.h"
#include "chaos.h"
#include "teleport.h"
#include <kernel/calendar.h>
#include <kernel/config.h>
@ -561,6 +562,24 @@ static int tolua_region_getkey(lua_State * L)
return 1;
}
static int tolua_region_getastral(lua_State * L)
{
region *r = (region *)tolua_tousertype(L, 1, 0);
region *rt = r_standard_to_astral(r);
if (!rt) {
const char *tname = tolua_tostring(L, 2, 0);
plane *pl = get_astralplane();
rt = new_region(real2tp(r->x), real2tp(r->y), pl, 0);
if (tname) {
const terrain_type *terrain = get_terrain(tname);
terraform_region(rt, terrain);
}
}
tolua_pushusertype(L, rt, TOLUA_CAST "region");
return 1;
}
static int tolua_region_setkey(lua_State * L)
{
region *self = (region *)tolua_tousertype(L, 1, 0);
@ -772,6 +791,8 @@ void tolua_region_open(lua_State * L)
tolua_variable(L, TOLUA_CAST "owner", &tolua_region_get_owner,
&tolua_region_set_owner);
tolua_function(L, TOLUA_CAST "get_astral", tolua_region_getastral);
tolua_function(L, TOLUA_CAST "get_key", tolua_region_getkey);
tolua_function(L, TOLUA_CAST "set_key", tolua_region_setkey);
}

View File

@ -1819,12 +1819,12 @@ 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)
order * ord, message **err)
{
assert(param[0]);
if (param[1] == NULL) {
/* Fehler: Zielregion vergessen */
cmistake(u, ord, 194, MSG_MAGIC);
*err = msg_error(u, ord, 194);
return -1;
}
else {
@ -1846,7 +1846,7 @@ addparam_region(const char *const param[], spllprm ** spobjp, const unit * u,
}
else {
/* Fehler: Zielregion vergessen */
cmistake(u, ord, 194, MSG_MAGIC);
*err = msg_error(u, ord, 194);
return -1;
}
return 2;
@ -1855,7 +1855,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, message **err)
{
spllprm *spobj;
int i = 0;
@ -1865,7 +1865,7 @@ addparam_unit(const char *const param[], spllprm ** spobjp, const unit * u,
if (isparam(param[0], u->faction->locale, P_TEMP)) {
if (param[1] == NULL) {
/* Fehler: Ziel vergessen */
cmistake(u, ord, 203, MSG_MAGIC);
*err = msg_error(u, ord, 203);
return -1;
}
++i;
@ -1883,7 +1883,7 @@ addparam_unit(const char *const param[], spllprm ** spobjp, const unit * u,
static spellparameter *add_spellparameter(region * target_r, unit * u,
const char *syntax, const char *const param[], int size, struct order *ord)
{
bool fail = false;
struct message *err = NULL;
int i = 0;
int p = 0;
const char *c;
@ -1919,7 +1919,7 @@ static spellparameter *add_spellparameter(region * target_r, unit * u,
}
par->param = malloc(size * sizeof(spllprm *));
while (!fail && *c && i < size && param[i] != NULL) {
while (!err && *c && i < size && param[i] != NULL) {
spllprm *spobj = NULL;
int j = -1;
switch (*c) {
@ -1938,13 +1938,13 @@ static spellparameter *add_spellparameter(region * target_r, unit * u,
break;
case 'u':
/* Parameter ist eine Einheit, evtl. TEMP */
j = addparam_unit(param + i, &spobj, u, ord);
j = addparam_unit(param + i, &spobj, u, ord, &err);
++c;
break;
case 'r':
/* Parameter sind zwei Regionskoordinaten innerhalb der "normalen" Plane */
if (i + 1 < size) {
j = addparam_region(param + i, &spobj, u, ord);
j = addparam_region(param + i, &spobj, u, ord, &err);
}
++c;
break;
@ -1979,7 +1979,7 @@ static spellparameter *add_spellparameter(region * target_r, unit * u,
break;
case P_UNIT:
if (i < size) {
j = addparam_unit(param + i, &spobj, u, ord);
j = addparam_unit(param + i, &spobj, u, ord, &err);
++c;
}
break;
@ -2005,8 +2005,10 @@ static spellparameter *add_spellparameter(region * target_r, unit * u,
j = -1;
break;
}
if (j < 0)
fail = true;
if (j < 0 && !err) {
/* syntax error */
err = msg_error(u, ord, 209);
}
else {
if (spobj != NULL)
par->param[p++] = spobj;
@ -2014,15 +2016,19 @@ static spellparameter *add_spellparameter(region * target_r, unit * u,
}
}
/* im Endeffekt waren es evtl. nur p parameter (wegen TEMP) */
/* im Endeffekt waren es evtl. nur p parameter (weniger weil TEMP nicht gilt) */
par->length = p;
if (par->length < minlen) {
cmistake(u, ord, 209, MSG_MAGIC);
free_spellparameter(par);
return NULL;
}
return fail ? NULL : par;
if (!err && p < minlen) {
/* syntax error */
err = msg_error(u, ord, 209);
}
if (err) {
ADDMSG(&u->faction->msgs, err);
free_spellparameter(par);
par = NULL;
}
return par;
}
struct unit * co_get_caster(const struct castorder * co) {