BUG 2415: eliminate at_potiondelay and WdL delay.

BUG 2419: refactor ointment and healing, add tests for USE
This commit is contained in:
Enno Rehling 2018-02-15 20:25:58 +01:00
parent 7d789d9896
commit bf591ecec5
13 changed files with 74 additions and 83 deletions

View File

@ -28,7 +28,7 @@ end
function test_nestwarmth_insect()
local r = region.create(0, 0, "plain")
local f = faction.create("insect", "noreply@eressea.de", "de")
local f = faction.create("insect")
local u = unit.create(f, r, 1)
local flags = u.flags
u:add_item("nestwarmth", 2)
@ -44,7 +44,7 @@ end
function test_nestwarmth_other()
local r = region.create(0, 0, "plain")
local f = faction.create("human", "noreply@eressea.de", "de")
local f = faction.create("human")
local u = unit.create(f, r, 1)
local flags = u.flags
u:add_item("nestwarmth", 2)
@ -60,7 +60,7 @@ end
function test_meow()
local r = region.create(0, 0, "plain")
local f = faction.create("human", "noreply@eressea.de", "de")
local f = faction.create("human")
local u = unit.create(f, r, 1)
u:add_item("aoc", 1)
u:clear_orders()
@ -74,7 +74,7 @@ end
function test_aurapotion50()
local r = region.create(0, 0, "plain")
local f = faction.create("human", "noreply@eressea.de", "de")
local f = faction.create("human")
local u = unit.create(f, r, 1)
u:add_item("aurapotion50", 1)
u:set_skill('magic', 10);
@ -92,7 +92,7 @@ end
function test_bagpipe()
local r = region.create(0, 0, "plain")
local f = faction.create("human", "noreply@eressea.de", "de")
local f = faction.create("human")
local u = unit.create(f, r, 1)
turn_begin()
u:add_item("bagpipeoffear", 1)
@ -109,9 +109,52 @@ function test_bagpipe()
assert_equal(0, r:get_curse('depression'))
end
function test_monthly_healing()
local r = region.create(0, 0, "plain")
local f = faction.create("human")
local u = unit.create(f, r, 30)
assert_equal(600, u.hp)
u.hp = 100
process_orders()
assert_equal(130, u.hp)
end
function test_ointment()
local r = region.create(0, 0, "plain")
local f = faction.create("human")
local u = unit.create(f, r, 30)
assert_equal(600, u.hp)
u.hp = 100
turn_begin()
u:add_item("ointment", 1)
u:clear_orders()
u:add_order("BENUTZEN 1 Wundsalbe")
turn_process()
assert_equal(530, u.hp)
assert_equal(0, u:get_item("ointment"))
turn_end()
end
function test_use_healing_potion()
-- Heiltrank kann (auch) mit BENUTZE eingesetzt werden
local r = region.create(0, 0, "plain")
local f = faction.create("human")
local u = unit.create(f, r, 30)
assert_equal(600, u.hp)
u.hp = 100
turn_begin()
u:add_item("p14", 1)
u:clear_orders()
u:add_order("BENUTZEN 1 Heiltrank")
turn_process()
assert_equal(530, u.hp)
assert_equal(0, u:get_item("p14"))
turn_end()
end
function test_speedsail()
local r = region.create(0, 0, "plain")
local f = faction.create("human", "noreply@eressea.de", "de")
local f = faction.create("human")
local u = unit.create(f, r, 1)
turn_begin()
@ -130,7 +173,7 @@ end
function disable_test_foolpotion()
local r = region.create(0, 0, "plain")
local f = faction.create("human", "noreply@eressea.de", "de")
local f = faction.create("human")
local u = unit.create(f, r, 1)
turn_begin()
u:add_item('p7', 2)
@ -159,7 +202,7 @@ end
function test_snowman()
local r = region.create(0, 0, "glacier")
local f = faction.create("human", "noreply@eressea.de", "de")
local f = faction.create("human")
local u = unit.create(f, r, 1)
u:add_item("snowman", 1)
u:clear_orders()

View File

@ -53,7 +53,6 @@ function test_dwarf_no_mining_bonus()
local r = region.create(0, 0, 'mountain')
local f = create_faction('dwarf')
local u = unit.create(f, r, 1)
u.name = 'Xolgrim'
turn_begin()
r:set_resource('iron', 100)

View File

@ -211,7 +211,7 @@ void show_potions(faction *f, int sklevel)
}
}
static int potion_healing(unit * u, int amount) {
static int potion_ointment(unit * u, int amount) {
int maxhp = unit_max_hp(u) * u->number;
u->hp = u->hp + 400 * amount;
if (u->hp > maxhp) u->hp = maxhp;
@ -244,8 +244,8 @@ static int do_potion(unit * u, region *r, const item_type * itype, int amount)
if (itype == oldpotiontype[P_LIFE]) {
return potion_water_of_life(u, r, amount);
}
else if (itype == oldpotiontype[P_HEILWASSER]) {
return potion_healing(u, amount);
else if (itype == oldpotiontype[P_OINTMENT]) {
return potion_ointment(u, amount);
}
else if (itype == oldpotiontype[P_PEOPLE]) {
return potion_luck(u, r, &at_peasantluck, amount);
@ -277,58 +277,6 @@ int use_potion(unit * u, const item_type * itype, int amount, struct order *ord)
return 0;
}
typedef struct potiondelay {
unit *u;
region *r;
const item_type *itype;
int amount;
} potiondelay;
static void init_potiondelay(variant *var)
{
var->v = malloc(sizeof(potiondelay));
}
static int age_potiondelay(attrib * a, void *owner)
{
potiondelay *pd = (potiondelay *)a->data.v;
UNUSED_ARG(owner);
pd->amount = do_potion(pd->u, pd->r, pd->itype, pd->amount);
return AT_AGE_REMOVE;
}
attrib_type at_potiondelay = {
"potiondelay",
init_potiondelay,
a_free_voidptr,
age_potiondelay, 0, 0
};
static attrib *make_potiondelay(unit * u, const item_type * itype, int amount)
{
attrib *a = a_new(&at_potiondelay);
potiondelay *pd = (potiondelay *)a->data.v;
pd->u = u;
pd->r = u->region;
pd->itype = itype;
pd->amount = amount;
return a;
}
int
use_potion_delayed(unit * u, const item_type * itype, int amount,
struct order *ord)
{
int result = begin_potion(u, itype, ord);
if (result)
return result;
a_add(&u->attribs, make_potiondelay(u, itype, amount));
end_potion(u, itype, amount);
return 0;
}
/*****************/
/* at_effect */
/*****************/

View File

@ -41,7 +41,7 @@ extern "C" {
P_LIFE,
/* Stufe 2 */
P_DOMORE,
P_HEILWASSER,
P_OINTMENT,
P_BAUERNBLUT,
/* Stufe 3 */
P_WISE, /* 6 */
@ -64,8 +64,6 @@ extern "C" {
void herbsearch(struct unit *u, int max);
int use_potion(struct unit *u, const struct item_type *itype,
int amount, struct order *);
int use_potion_delayed(struct unit *u, const struct item_type *itype,
int amount, struct order *);
int get_effect(const struct unit *u, const struct item_type *effect);
int change_effect(struct unit *u, const struct item_type *effect,

View File

@ -28,6 +28,7 @@ extern "C" {
struct message;
struct selist;
union variant;
/** more defines **/
#define FS_ENEMY 1

View File

@ -13,6 +13,7 @@
#define H_GC_CREPORT
#include <kernel/types.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {

View File

@ -16,6 +16,7 @@
#include <spells/regioncurse.h>
#include <kernel/curse.h>
#include <kernel/config.h>
#include <kernel/faction.h>
#include <kernel/item.h>
#include <kernel/messages.h>
@ -321,8 +322,8 @@ static int heal(unit * user, int effect)
}
static int
use_healingpotion(struct unit *user, const struct item_type *itype, int amount,
struct order *ord)
use_healingpotion(struct unit *user, const struct item_type *itype,
int amount, struct order *ord)
{
int effect = amount * 400;
unit *u = user->region->units;
@ -400,8 +401,7 @@ static int use_warmthpotion(unit *u, const item_type *itype,
cmistake(u, ord, 163, MSG_EVENT);
return ECUSTOM;
}
use_pooled(u, itype->rtype, GET_SLACK | GET_RESERVE | GET_POOLED_SLACK,
amount);
use_pooled(u, itype->rtype, GET_DEFAULT, amount);
usetpotionuse(u, itype);
ADDMSG(&u->faction->msgs, msg_message("usepotion",
@ -422,9 +422,9 @@ void register_itemfunctions(void)
register_item_use(use_birthdayamulet, "use_aoc");
register_item_use(use_foolpotion, "use_p7");
register_item_use(use_bloodpotion, "use_peasantblood");
register_item_use(use_healingpotion, "use_ointment");
register_item_use(use_potion, "use_ointment");
register_item_use(use_healingpotion, "use_p14");
register_item_use(use_warmthpotion, "use_nestwarmth");
/* ungetestet: Wasser des Lebens */
register_item_use(use_potion_delayed, "use_p2");
/* p2 = P_LIFE = Wasser des Lebens */
register_item_use(use_potion, "use_p2");
}

View File

@ -21,6 +21,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/types.h>
#include <util/resolve.h>
#include <util/variant.h>
#include <stddef.h>
#include <stdbool.h>

View File

@ -16,7 +16,7 @@ void test_terraform(CuTest *tc) {
item_type *itype;
test_setup();
itype = test_create_itemtype("ointment");
itype = test_create_itemtype("oil");
itype->rtype->flags |= (RTF_ITEM | RTF_POOLED);
new_luxurytype(itype, 0);

View File

@ -496,7 +496,7 @@ unit *read_unit(gamedata *data)
}
READ_INT(data->store, &n);
unit_setstatus(u, n);
unit_setstatus(u, (status_t)n);
READ_INT(data->store, &u->flags);
u->flags &= UFL_SAVEMASK;
if ((u->flags & UFL_ANON_FACTION) && !rule_stealth_anon()) {

View File

@ -20,9 +20,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#define ERESSEA_TYPES_H
#include <settings.h>
#include <util/variant.h>
typedef short item_t;
struct attrib;
struct attrib_type;
@ -77,15 +74,14 @@ typedef enum {
/* ------------------ Status von Einheiten --------------------- */
typedef unsigned char status_t;
enum {
typedef enum {
ST_AGGRO,
ST_FIGHT,
ST_BEHIND,
ST_CHICKEN,
ST_AVOID,
ST_FLEE
};
} status_t;
/* ----------------- Parameter --------------------------------- */

View File

@ -20,6 +20,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#define H_KRNL_MAGIC
#include <kernel/types.h>
#include <util/variant.h>
#include <stdbool.h>
#ifdef __cplusplus

View File

@ -19,6 +19,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#ifndef H_GC_VOLCANO
#define H_GC_VOLCANO
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif