increase magic power for low levels in E3 (instead of divide by 2 sometimes giving powers of < 1.0, cap it below at 1)

several spells have now had problems with powers lower than they were ever designed for, including shapeshift
also added a test and some framework for shapeshift spell (in E2).
https://bugs.eressea.de/view.php?id=1588
This commit is contained in:
Enno Rehling 2015-04-30 15:59:52 +02:00
parent ce94c9805d
commit b00d7b6d5a
6 changed files with 51 additions and 6 deletions

View File

@ -2,3 +2,4 @@ require 'tests.e2.shiplanding'
require 'tests.e2.e2features'
require 'tests.e2.movement'
require 'tests.e2.guard'
require 'tests.e2.spells'

View File

@ -0,0 +1,28 @@
require "lunit"
module("tests.e2.spells", 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.economy.food", "4")
end
function test_shapeshift()
local r = region.create(42, 0, "plain")
local f = faction.create("noreply@eressea.de", "demon", "de")
local u1 = unit.create(f, r, 1)
local u2 = unit.create(f, r, 1)
u1:clear_orders()
u1.magic = "gray"
u1:set_skill("magic", 2)
u1.aura = 1
u1:add_spell("shapeshift")
u1:add_order("ZAUBERE STUFE 1 Gestaltwandlung " .. itoa36(u2.id) .. " Goblin")
process_orders()
assert_equal(f.race, u2.race)
s = u2:show()
assert_equal("1 Goblin", string.sub(s, string.find(s, "1 Goblin")))
end

View File

@ -1868,7 +1868,7 @@ static void do_extra_spell(troop at, const att * a)
else {
int level = a->level;
assert(a->level > 0);
cast_combatspell(at, sp, level, level * MagicPower());
cast_combatspell(at, sp, level, MagicPower((float)level));
}
}

View File

@ -20,6 +20,7 @@ without prior permission by the authors of Eressea.
#include "alchemy.h"
#include "bindings.h"
#include "move.h"
#include "reports.h"
/* attributes includes */
#include <attributes/racename.h>
@ -57,6 +58,17 @@ without prior permission by the authors of Eressea.
#include <stdlib.h>
#include <limits.h>
static int tolua_bufunit(lua_State * L) {
char buf[8192];
unit *self = (unit *)tolua_tousertype(L, 1, 0);
int mode = (int)tolua_tonumber(L, 2, see_unit);
if (!self) return 0;
bufunit(self->faction, self, 0, mode, buf, sizeof(buf));
tolua_pushstring(L, buf);
return 1;
}
static int tolua_unit_get_objects(lua_State * L)
{
unit *self = (unit *)tolua_tousertype(L, 1, 0);
@ -533,7 +545,7 @@ static void unit_castspell(unit * u, const char *name, int level)
}
else {
castorder co;
create_castorder(&co, u, 0, sp, u->region, level, level * MagicPower(), 0, 0, 0);
create_castorder(&co, u, 0, sp, u->region, level, MagicPower((float)level), 0, 0, 0);
sp->cast(&co);
free_castorder(&co);
}
@ -1058,6 +1070,7 @@ void tolua_unit_open(lua_State * L)
#ifdef BSON_ATTRIB
tolua_variable(L, TOLUA_CAST "attribs", &tolua_unit_get_attribs, 0);
#endif
tolua_function(L, TOLUA_CAST "show", &tolua_bufunit);
}
tolua_endmodule(L);
}

View File

@ -117,14 +117,17 @@ static float MagicRegeneration(void)
return value;
}
float MagicPower(void)
float MagicPower(float force)
{
static float value = -1.0;
if (force <= 0) {
return 0;
}
if (value < 0) {
const char *str = get_param(global.parameters, "magic.power");
value = str ? (float)atof(str) : 1.0f;
}
return value;
return _max(value * force, 1.0f);
}
static int a_readicastle(attrib * a, void *owner, struct storage *store)
@ -1074,7 +1077,7 @@ spellpower(region * r, unit * u, const spell * sp, int cast_level, struct order
}
}
force = force * MagicPower();
force = MagicPower(force);
return _max(force, 0);
}

View File

@ -360,7 +360,7 @@ extern "C" {
extern void write_spells(struct quicklist *slist, struct storage *store);
extern void read_spells(struct quicklist **slistp, magic_t mtype,
struct storage *store);
extern float MagicPower(void);
float MagicPower(float force);
extern struct spellbook * get_spellbook(const char * name);
extern void free_spellbooks(void);