forked from github/server
Merge branch 'develop' of github.com:eressea/server into develop
This commit is contained in:
commit
f69311b141
12 changed files with 90 additions and 17 deletions
|
@ -210,6 +210,7 @@ set(TESTS_SRC
|
||||||
upkeep.test.c
|
upkeep.test.c
|
||||||
spells/flyingship.test.c
|
spells/flyingship.test.c
|
||||||
spells/magicresistance.test.c
|
spells/magicresistance.test.c
|
||||||
|
triggers/shock.test.c
|
||||||
${ATTRIBUTES_TESTS}
|
${ATTRIBUTES_TESTS}
|
||||||
${UTIL_TESTS}
|
${UTIL_TESTS}
|
||||||
${KERNEL_TESTS}
|
${KERNEL_TESTS}
|
||||||
|
|
|
@ -2898,17 +2898,17 @@ static void expandloot(region * r, request * lootorders)
|
||||||
if (!norders)
|
if (!norders)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (i = 0; i != norders && rmoney(r) > TAXFRACTION * 2; i++) {
|
for (i = 0; i != norders && startmoney > looted + TAXFRACTION * 2; i++) {
|
||||||
change_money(oa[i].unit, TAXFRACTION);
|
change_money(oa[i].unit, TAXFRACTION);
|
||||||
oa[i].unit->n += TAXFRACTION;
|
oa[i].unit->n += TAXFRACTION;
|
||||||
/*Looting destroys double the money*/
|
/*Looting destroys double the money*/
|
||||||
rsetmoney(r, rmoney(r) - TAXFRACTION * 2);
|
looted += TAXFRACTION * 2;
|
||||||
looted = looted + TAXFRACTION * 2;
|
|
||||||
}
|
}
|
||||||
|
rsetmoney(r, startmoney - looted);
|
||||||
free(oa);
|
free(oa);
|
||||||
|
|
||||||
/* Lowering morale by 1 depending on the looted money (+20%) */
|
/* Lowering morale by 1 depending on the looted money (+20%) */
|
||||||
if (rng_int() % 100 < ((looted / startmoney) + 0.2)) {
|
if (rng_int() % 100 < 20 + (looted * 80) / startmoney) {
|
||||||
int m = region_get_morale(r);
|
int m = region_get_morale(r);
|
||||||
if (m) {
|
if (m) {
|
||||||
/*Nur Moral -1, turns is not changed, so the first time nothing happens if the morale is good*/
|
/*Nur Moral -1, turns is not changed, so the first time nothing happens if the morale is good*/
|
||||||
|
|
|
@ -187,6 +187,7 @@ resource_type *rt_get_or_create(const char *name) {
|
||||||
else {
|
else {
|
||||||
rtype->_name = _strdup(name);
|
rtype->_name = _strdup(name);
|
||||||
rt_register(rtype);
|
rt_register(rtype);
|
||||||
|
return rt_find(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return rtype;
|
return rtype;
|
||||||
|
|
|
@ -123,11 +123,11 @@ static void test_scale_number(CuTest *tc) {
|
||||||
u = test_create_unit(test_create_faction(test_create_race("human")), findregion(0, 0));
|
u = test_create_unit(test_create_faction(test_create_race("human")), findregion(0, 0));
|
||||||
change_effect(u, ptype, 1);
|
change_effect(u, ptype, 1);
|
||||||
CuAssertIntEquals(tc, 1, u->number);
|
CuAssertIntEquals(tc, 1, u->number);
|
||||||
CuAssertIntEquals(tc, 1, u->hp);
|
CuAssertIntEquals(tc, 20, u->hp);
|
||||||
CuAssertIntEquals(tc, 1, get_effect(u, ptype));
|
CuAssertIntEquals(tc, 1, get_effect(u, ptype));
|
||||||
scale_number(u, 2);
|
scale_number(u, 2);
|
||||||
CuAssertIntEquals(tc, 2, u->number);
|
CuAssertIntEquals(tc, 2, u->number);
|
||||||
CuAssertIntEquals(tc, 2, u->hp);
|
CuAssertIntEquals(tc, 40, u->hp);
|
||||||
CuAssertIntEquals(tc, 2, get_effect(u, ptype));
|
CuAssertIntEquals(tc, 2, get_effect(u, ptype));
|
||||||
set_level(u, SK_ALCHEMY, 1);
|
set_level(u, SK_ALCHEMY, 1);
|
||||||
scale_number(u, 0);
|
scale_number(u, 0);
|
||||||
|
|
11
src/magic.c
11
src/magic.c
|
@ -995,6 +995,11 @@ cancast(unit * u, const spell * sp, int level, int range, struct order * ord)
|
||||||
if (reslist != NULL) {
|
if (reslist != NULL) {
|
||||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "missing_components_list",
|
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "missing_components_list",
|
||||||
"list", reslist));
|
"list", reslist));
|
||||||
|
while (reslist) {
|
||||||
|
resource *res = reslist->next;
|
||||||
|
free(reslist);
|
||||||
|
reslist = res;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -2973,7 +2978,7 @@ spellbook * get_spellbook(const char * name)
|
||||||
spellbook * result;
|
spellbook * result;
|
||||||
void * match;
|
void * match;
|
||||||
|
|
||||||
if (cb_find_prefix(&cb_spellbooks, name, strlen(name), &match, 1, 0)) {
|
if (cb_find_prefix(&cb_spellbooks, name, strlen(name), &match, 1, 0) > 0) {
|
||||||
cb_get_kv(match, &result, sizeof(result));
|
cb_get_kv(match, &result, sizeof(result));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -2985,6 +2990,10 @@ spellbook * get_spellbook(const char * name)
|
||||||
log_error("cb_insert failed although cb_find returned nothing for spellbook=%s", name);
|
log_error("cb_insert failed although cb_find returned nothing for spellbook=%s", name);
|
||||||
assert(!"should not happen");
|
assert(!"should not happen");
|
||||||
}
|
}
|
||||||
|
result = 0;
|
||||||
|
if (cb_find_prefix(&cb_spellbooks, name, strlen(name), &match, 1, 0) > 0) {
|
||||||
|
cb_get_kv(match, &result, sizeof(result));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,8 +53,9 @@ void test_spellbooks(CuTest * tc)
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
|
|
||||||
herp = get_spellbook("herp");
|
herp = get_spellbook("herp");
|
||||||
derp = get_spellbook("derp");
|
|
||||||
CuAssertPtrNotNull(tc, herp);
|
CuAssertPtrNotNull(tc, herp);
|
||||||
|
CuAssertPtrEquals(tc, herp, get_spellbook("herp"));
|
||||||
|
derp = get_spellbook("derp");
|
||||||
CuAssertPtrNotNull(tc, derp);
|
CuAssertPtrNotNull(tc, derp);
|
||||||
CuAssertTrue(tc, derp != herp);
|
CuAssertTrue(tc, derp != herp);
|
||||||
CuAssertStrEquals(tc, "herp", herp->name);
|
CuAssertStrEquals(tc, "herp", herp->name);
|
||||||
|
|
|
@ -96,8 +96,8 @@ void do_markets(void)
|
||||||
const struct race *rc = f ? f->race : NULL;
|
const struct race *rc = f ? f->race : NULL;
|
||||||
int p = rpeasants(r);
|
int p = rpeasants(r);
|
||||||
int numlux = rc_luxury_trade(rc), numherbs = rc_herb_trade(rc);
|
int numlux = rc_luxury_trade(rc), numherbs = rc_herb_trade(rc);
|
||||||
numlux = (p + numlux - MIN_PEASANTS) / numlux;
|
if (numlux>0) numlux = (p + numlux - MIN_PEASANTS) / numlux;
|
||||||
numherbs = (p + numherbs - MIN_PEASANTS) / numherbs;
|
if (numherbs>0) numherbs = (p + numherbs - MIN_PEASANTS) / numherbs;
|
||||||
if (numlux > 0 || numherbs > 0) {
|
if (numlux > 0 || numherbs > 0) {
|
||||||
int d, nmarkets = 0;
|
int d, nmarkets = 0;
|
||||||
const item_type *lux = r_luxury(r);
|
const item_type *lux = r_luxury(r);
|
||||||
|
|
|
@ -1541,8 +1541,8 @@ static void prepare_report(struct report_context *ctx, faction *f)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mkreportdir(const char *rpath) {
|
static void mkreportdir(const char *rpath) {
|
||||||
if (_access(rpath, 0) < 0) {
|
if (_mkdir(rpath) != 0) {
|
||||||
if (_mkdir(rpath) != 0) {
|
if (_access(rpath, 0) < 0) {
|
||||||
log_error("could not create reports directory %s: %s", rpath, strerror(errno));
|
log_error("could not create reports directory %s: %s", rpath, strerror(errno));
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,6 +127,7 @@ int RunAllTests(int argc, char *argv[])
|
||||||
ADD_SUITE(wormhole);
|
ADD_SUITE(wormhole);
|
||||||
ADD_SUITE(spy);
|
ADD_SUITE(spy);
|
||||||
ADD_SUITE(study);
|
ADD_SUITE(study);
|
||||||
|
ADD_SUITE(shock);
|
||||||
|
|
||||||
if (suites) {
|
if (suites) {
|
||||||
CuSuite *summary = CuSuiteNew();
|
CuSuite *summary = CuSuiteNew();
|
||||||
|
|
|
@ -35,6 +35,8 @@ struct race *test_create_race(const char *name)
|
||||||
{
|
{
|
||||||
race *rc = rc_get_or_create(name);
|
race *rc = rc_get_or_create(name);
|
||||||
rc->maintenance = 10;
|
rc->maintenance = 10;
|
||||||
|
rc->hitpoints = 20;
|
||||||
|
rc->maxaura = 1.0;
|
||||||
rc->ec_flags |= GETITEM;
|
rc->ec_flags |= GETITEM;
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
@ -59,7 +61,7 @@ struct region *test_create_region(int x, int y, const terrain_type *terrain)
|
||||||
|
|
||||||
struct faction *test_create_faction(const struct race *rc)
|
struct faction *test_create_faction(const struct race *rc)
|
||||||
{
|
{
|
||||||
faction *f = addfaction("nobody@eressea.de", NULL, rc ? rc : rc_get_or_create("human"), default_locale, 0);
|
faction *f = addfaction("nobody@eressea.de", NULL, rc ? rc : test_create_race("human"), default_locale, 0);
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -59,13 +59,18 @@ static void do_shock(unit * u, const char *reason)
|
||||||
|
|
||||||
if (u->number > 0) {
|
if (u->number > 0) {
|
||||||
/* HP - Verlust */
|
/* HP - Verlust */
|
||||||
u->hp = (unit_max_hp(u) * u->number) / 10;
|
int hp = (unit_max_hp(u) * u->number) / 10;
|
||||||
u->hp = _max(1, u->hp);
|
hp = _min(u->hp, hp);
|
||||||
|
u->hp = _max(1, hp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Aura - Verlust */
|
/* Aura - Verlust */
|
||||||
if (is_mage(u)) {
|
if (is_mage(u)) {
|
||||||
set_spellpoints(u, max_spellpoints(u->region, u) / 10);
|
int aura = max_spellpoints(u->region, u) / 10;
|
||||||
|
int now = get_spellpoints(u);
|
||||||
|
if (now > aura) {
|
||||||
|
set_spellpoints(u, aura);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Evt. Talenttageverlust */
|
/* Evt. Talenttageverlust */
|
||||||
|
@ -86,7 +91,7 @@ static void do_shock(unit * u, const char *reason)
|
||||||
}
|
}
|
||||||
if (u->faction != NULL) {
|
if (u->faction != NULL) {
|
||||||
ADDMSG(&u->faction->msgs, msg_message("shock",
|
ADDMSG(&u->faction->msgs, msg_message("shock",
|
||||||
"mage reason", u, _strdup(reason)));
|
"mage reason", u, reason));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
53
src/triggers/shock.test.c
Normal file
53
src/triggers/shock.test.c
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
#include <platform.h>
|
||||||
|
#include "shock.h"
|
||||||
|
#include "../magic.h"
|
||||||
|
|
||||||
|
#include <kernel/unit.h>
|
||||||
|
#include <kernel/faction.h>
|
||||||
|
#include <util/event.h>
|
||||||
|
|
||||||
|
#include <tests.h>
|
||||||
|
#include <CuTest.h>
|
||||||
|
|
||||||
|
static void test_shock(CuTest *tc) {
|
||||||
|
unit *u;
|
||||||
|
trigger *tt;
|
||||||
|
test_cleanup();
|
||||||
|
|
||||||
|
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
|
||||||
|
create_mage(u, M_GRAY);
|
||||||
|
set_level(u, SK_MAGIC, 5);
|
||||||
|
set_spellpoints(u, 10);
|
||||||
|
u->hp = 10;
|
||||||
|
tt = trigger_shock(u);
|
||||||
|
tt->type->handle(tt, u);
|
||||||
|
CuAssertIntEquals(tc, 2, u->hp);
|
||||||
|
CuAssertIntEquals(tc, 2, get_spellpoints(u));
|
||||||
|
CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "shock"));
|
||||||
|
test_cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_shock_low(CuTest *tc) {
|
||||||
|
unit *u;
|
||||||
|
trigger *tt;
|
||||||
|
test_cleanup();
|
||||||
|
|
||||||
|
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
|
||||||
|
create_mage(u, M_GRAY);
|
||||||
|
set_level(u, SK_MAGIC, 5);
|
||||||
|
set_spellpoints(u, 1);
|
||||||
|
u->hp = 1;
|
||||||
|
tt = trigger_shock(u);
|
||||||
|
tt->type->handle(tt, u);
|
||||||
|
CuAssertIntEquals(tc, 1, u->hp);
|
||||||
|
CuAssertIntEquals(tc, 1, get_spellpoints(u));
|
||||||
|
test_cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
|
CuSuite *get_shock_suite(void)
|
||||||
|
{
|
||||||
|
CuSuite *suite = CuSuiteNew();
|
||||||
|
SUITE_ADD_TEST(suite, test_shock);
|
||||||
|
SUITE_ADD_TEST(suite, test_shock_low);
|
||||||
|
return suite;
|
||||||
|
}
|
Loading…
Reference in a new issue