move items with tests to items.c

This commit is contained in:
Enno Rehling 2017-02-27 14:10:12 +01:00
parent 60c2f1e807
commit 5ffe60193b
2 changed files with 133 additions and 135 deletions

View File

@ -1,6 +1,7 @@
#include <platform.h> #include <platform.h>
#include "items.h" #include "items.h"
#include "alchemy.h"
#include "study.h" #include "study.h"
#include "economy.h" #include "economy.h"
#include "move.h" #include "move.h"
@ -14,6 +15,7 @@
#include <kernel/order.h> #include <kernel/order.h>
#include <kernel/plane.h> #include <kernel/plane.h>
#include <kernel/pool.h> #include <kernel/pool.h>
#include <kernel/race.h>
#include <kernel/region.h> #include <kernel/region.h>
#include <kernel/ship.h> #include <kernel/ship.h>
#include <kernel/spell.h> #include <kernel/spell.h>
@ -21,9 +23,15 @@
#include <items/demonseye.h> #include <items/demonseye.h>
/* triggers includes */
#include <triggers/changerace.h>
#include <triggers/timeout.h>
#include <util/attrib.h> #include <util/attrib.h>
#include <util/event.h>
#include <util/parser.h> #include <util/parser.h>
#include <util/rand.h> #include <util/rand.h>
#include <util/rng.h>
#include <assert.h> #include <assert.h>
#include <limits.h> #include <limits.h>
@ -125,15 +133,15 @@ struct order *ord)
UNUSED_ARG(ord); UNUSED_ARG(ord);
assert(sp); assert(sp);
/* Reduziert die Stärke jedes Spruchs um effect */ /* Reduziert die St<EFBFBD>rke jedes Spruchs um effect */
effect = 5; effect = 5;
/* Hält Sprüche bis zu einem summierten Gesamtlevel von power aus. /* H<EFBFBD>lt Spr<70>che bis zu einem summierten Gesamtlevel von power aus.
* Jeder Zauber reduziert die 'Lebenskraft' (vigour) der Antimagiezone * Jeder Zauber reduziert die 'Lebenskraft' (vigour) der Antimagiezone
* um seine Stufe */ * um seine Stufe */
force = effect * 20; /* Stufe 5 =~ 100 */ force = effect * 20; /* Stufe 5 =~ 100 */
/* Regionszauber auflösen */ /* Regionszauber aufl<EFBFBD>sen */
while (*ap && force > 0) { while (*ap && force > 0) {
curse *c; curse *c;
attrib *a = *ap; attrib *a = *ap;
@ -145,7 +153,7 @@ struct order *ord)
} }
c = (curse *)a->data.v; c = (curse *)a->data.v;
/* Immunität prüfen */ /* Immunit<EFBFBD>t pr<70>fen */
if (c_flags(c) & CURSE_IMMUNE) { if (c_flags(c) & CURSE_IMMUNE) {
do { do {
ap = &(*ap)->next; ap = &(*ap)->next;
@ -264,6 +272,118 @@ int amount, struct order *ord)
return 0; return 0;
} }
static int
use_birthdayamulet(unit * u, const struct item_type *itype, int amount,
struct order *ord)
{
direction_t d;
message *msg = msg_message("meow", "");
UNUSED_ARG(ord);
UNUSED_ARG(amount);
UNUSED_ARG(itype);
add_message(&u->region->msgs, msg);
for (d = 0; d < MAXDIRECTIONS; d++) {
region *tr = rconnect(u->region, d);
if (tr)
add_message(&tr->msgs, msg);
}
msg_release(msg);
return 0;
}
static int use_foolpotion(unit *u, const item_type *itype, int amount,
struct order *ord)
{
int targetno = read_unitid(u->faction, u->region);
unit *target = findunit(targetno);
if (target == NULL || u->region != target->region) {
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "feedback_unit_not_found",
""));
return ECUSTOM;
}
if (effskill(u, SK_STEALTH, 0) <= effskill(target, SK_PERCEPTION, 0)) {
cmistake(u, ord, 64, MSG_EVENT);
return ECUSTOM;
}
ADDMSG(&u->faction->msgs, msg_message("givedumb",
"unit recipient amount", u, target, amount));
change_effect(target, itype->rtype->ptype, amount);
use_pooled(u, itype->rtype, GET_DEFAULT, amount);
return 0;
}
static int
use_bloodpotion(struct unit *u, const struct item_type *itype, int amount,
struct order *ord)
{
if (u->number == 0 || u_race(u) == get_race(RC_DAEMON)) {
change_effect(u, itype->rtype->ptype, 100 * amount);
}
else {
const race *irace = u_irace(u);
if (irace == u_race(u)) {
const race *rcfailure = rc_find("smurf");
if (!rcfailure) {
rcfailure = rc_find("toad");
}
if (rcfailure) {
trigger *trestore = trigger_changerace(u, u_race(u), irace);
if (trestore) {
int duration = 2 + rng_int() % 8;
add_trigger(&u->attribs, "timer", trigger_timeout(duration,
trestore));
u->irace = NULL;
u_setrace(u, rcfailure);
}
}
}
}
use_pooled(u, itype->rtype, GET_SLACK | GET_RESERVE | GET_POOLED_SLACK,
amount);
usetpotionuse(u, itype->rtype->ptype);
ADDMSG(&u->faction->msgs, msg_message("usepotion",
"unit potion", u, itype->rtype));
return 0;
}
static int heal(unit * user, int effect)
{
int req = unit_max_hp(user) * user->number - user->hp;
if (req > 0) {
req = MIN(req, effect);
effect -= req;
user->hp += req;
}
return effect;
}
static int
use_healingpotion(struct unit *user, const struct item_type *itype, int amount,
struct order *ord)
{
int effect = amount * 400;
unit *u = user->region->units;
effect = heal(user, effect);
while (effect > 0 && u != NULL) {
if (u->faction == user->faction) {
effect = heal(u, effect);
}
u = u->next;
}
use_pooled(user, itype->rtype, GET_SLACK | GET_RESERVE | GET_POOLED_SLACK,
amount);
usetpotionuse(user, itype->rtype->ptype);
ADDMSG(&user->faction->msgs, msg_message("usepotion",
"unit potion", user, itype->rtype));
return 0;
}
void register_itemfunctions(void) void register_itemfunctions(void)
{ {
register_demonseye(); register_demonseye();
@ -274,4 +394,10 @@ void register_itemfunctions(void)
register_item_use(use_instantartacademy, "use_instantartacademy"); register_item_use(use_instantartacademy, "use_instantartacademy");
register_item_use(use_bagpipeoffear, "use_bagpipeoffear"); register_item_use(use_bagpipeoffear, "use_bagpipeoffear");
register_item_use(use_aurapotion50, "use_aurapotion50"); register_item_use(use_aurapotion50, "use_aurapotion50");
/* have tests: */
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");
} }

View File

@ -34,23 +34,18 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "terrain.h" #include "terrain.h"
#include "unit.h" #include "unit.h"
/* triggers includes */
#include <triggers/changerace.h>
#include <triggers/timeout.h>
/* util includes */ /* util includes */
#include <util/attrib.h> #include <util/attrib.h>
#include <util/base36.h> #include <util/base36.h>
#include <critbit.h>
#include <util/event.h>
#include <util/functions.h> #include <util/functions.h>
#include <util/goodies.h> #include <util/goodies.h>
#include <util/log.h> #include <util/log.h>
#include <util/language.h> #include <util/language.h>
#include <util/message.h> #include <util/message.h>
#include <util/umlaut.h>
#include <util/rng.h> #include <util/rng.h>
#include <util/umlaut.h>
#include <critbit.h>
#include <storage.h> #include <storage.h>
/* libc includes */ /* libc includes */
@ -675,27 +670,6 @@ int set_item(unit * u, const item_type *itype, int value)
return value; return value;
} }
static int
use_birthdayamulet(unit * u, const struct item_type *itype, int amount,
struct order *ord)
{
direction_t d;
message *msg = msg_message("meow", "");
UNUSED_ARG(ord);
UNUSED_ARG(amount);
UNUSED_ARG(itype);
add_message(&u->region->msgs, msg);
for (d = 0; d < MAXDIRECTIONS; d++) {
region *tr = rconnect(u->region, d);
if (tr)
add_message(&tr->msgs, msg);
}
msg_release(msg);
return 0;
}
/* t_item::flags */ /* t_item::flags */
#define FL_ITEM_CURSED (1<<0) #define FL_ITEM_CURSED (1<<0)
#define FL_ITEM_NOTLOST (1<<1) #define FL_ITEM_NOTLOST (1<<1)
@ -766,17 +740,6 @@ mod_dwarves_only(const unit * u, const region * r, skill_t sk, int value)
return -118; return -118;
} }
static int heal(unit * user, int effect)
{
int req = unit_max_hp(user) * user->number - user->hp;
if (req > 0) {
req = MIN(req, effect);
effect -= req;
user->hp += req;
}
return effect;
}
void void
register_item_give(int(*foo) (struct unit *, struct unit *, register_item_give(int(*foo) (struct unit *, struct unit *,
const struct item_type *, int, struct order *), const char *name) const struct item_type *, int, struct order *), const char *name)
@ -791,35 +754,6 @@ struct order *), const char *name)
register_function((pf_generic)foo, name); register_function((pf_generic)foo, name);
} }
void
register_item_useonother(int(*foo) (struct unit *, int,
const struct item_type *, int, struct order *), const char *name)
{
register_function((pf_generic)foo, name);
}
static int
use_healingpotion(struct unit *user, const struct item_type *itype, int amount,
struct order *ord)
{
int effect = amount * 400;
unit *u = user->region->units;
effect = heal(user, effect);
while (effect > 0 && u != NULL) {
if (u->faction == user->faction) {
effect = heal(u, effect);
}
u = u->next;
}
use_pooled(user, itype->rtype, GET_SLACK | GET_RESERVE | GET_POOLED_SLACK,
amount);
usetpotionuse(user, itype->rtype->ptype);
ADDMSG(&user->faction->msgs, msg_message("usepotion",
"unit potion", user, itype->rtype));
return 0;
}
static int use_warmthpotion(unit *u, const item_type *itype, static int use_warmthpotion(unit *u, const item_type *itype,
int amount, struct order *ord) int amount, struct order *ord)
{ {
@ -840,64 +774,6 @@ static int use_warmthpotion(unit *u, const item_type *itype,
return 0; return 0;
} }
static int use_foolpotion(unit *u, const item_type *itype, int amount,
struct order *ord)
{
int targetno = read_unitid(u->faction, u->region);
unit *target = findunit(targetno);
if (target == NULL || u->region != target->region) {
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "feedback_unit_not_found",
""));
return ECUSTOM;
}
if (effskill(u, SK_STEALTH, 0) <= effskill(target, SK_PERCEPTION, 0)) {
cmistake(u, ord, 64, MSG_EVENT);
return ECUSTOM;
}
ADDMSG(&u->faction->msgs, msg_message("givedumb",
"unit recipient amount", u, target, amount));
change_effect(target, itype->rtype->ptype, amount);
use_pooled(u, itype->rtype, GET_DEFAULT, amount);
return 0;
}
static int
use_bloodpotion(struct unit *u, const struct item_type *itype, int amount,
struct order *ord)
{
if (u->number == 0 || u_race(u) == get_race(RC_DAEMON)) {
change_effect(u, itype->rtype->ptype, 100 * amount);
}
else {
const race *irace = u_irace(u);
if (irace == u_race(u)) {
const race *rcfailure = rc_find("smurf");
if (!rcfailure) {
rcfailure = rc_find("toad");
}
if (rcfailure) {
trigger *trestore = trigger_changerace(u, u_race(u), irace);
if (trestore) {
int duration = 2 + rng_int() % 8;
add_trigger(&u->attribs, "timer", trigger_timeout(duration,
trestore));
u->irace = NULL;
u_setrace(u, rcfailure);
}
}
}
}
use_pooled(u, itype->rtype, GET_SLACK | GET_RESERVE | GET_POOLED_SLACK,
amount);
usetpotionuse(u, itype->rtype->ptype);
ADDMSG(&u->faction->msgs, msg_message("usepotion",
"unit potion", u, itype->rtype));
return 0;
}
#include <attributes/fleechance.h> #include <attributes/fleechance.h>
static int static int
use_mistletoe(struct unit *user, const struct item_type *itype, int amount, use_mistletoe(struct unit *user, const struct item_type *itype, int amount,
@ -1288,12 +1164,8 @@ void register_resources(void)
register_function((pf_generic)res_changeaura, "changeaura"); register_function((pf_generic)res_changeaura, "changeaura");
register_item_use(use_potion_delayed, "use_p2"); register_item_use(use_potion_delayed, "use_p2");
register_item_use(use_tacticcrystal, "use_tacticcrystal");
register_item_use(use_birthdayamulet, "use_aoc");
register_item_use(use_warmthpotion, "use_nestwarmth"); register_item_use(use_warmthpotion, "use_nestwarmth");
register_item_use(use_bloodpotion, "use_peasantblood"); register_item_use(use_tacticcrystal, "use_tacticcrystal");
register_item_use(use_healingpotion, "use_ointment");
register_item_use(use_foolpotion, "use_p7");
register_item_use(use_mistletoe, "usemistletoe"); register_item_use(use_mistletoe, "usemistletoe");
register_item_use(use_magicboost, "usemagicboost"); register_item_use(use_magicboost, "usemagicboost");
register_item_use(use_snowball, "usesnowball"); register_item_use(use_snowball, "usesnowball");