forked from github/server
BUG 2343: fix clone_men (hitpoints), add test.
This commit is contained in:
parent
2dab88b118
commit
beecc0e323
|
@ -493,7 +493,7 @@ const curse_type * ct)
|
|||
/* ------------------------------------------------------------- */
|
||||
/* gibt bei Personenbeschränkten Verzauberungen die Anzahl der
|
||||
* betroffenen Personen zurück. Ansonsten wird 0 zurückgegeben. */
|
||||
int get_cursedmen(unit * u, const curse * c)
|
||||
int get_cursedmen(const unit * u, const curse * c)
|
||||
{
|
||||
int cursedmen = u->number;
|
||||
|
||||
|
@ -631,7 +631,7 @@ curse *create_curse(unit * magician, attrib ** ap, const curse_type * ct,
|
|||
/* hier müssen alle c-typen, die auf Einheiten gezaubert werden können,
|
||||
* berücksichtigt werden */
|
||||
|
||||
static void do_transfer_curse(curse * c, unit * u, unit * u2, int n)
|
||||
static void do_transfer_curse(curse * c, const unit * u, unit * u2, int n)
|
||||
{
|
||||
int cursedmen = 0;
|
||||
int men = get_cursedmen(u, c);
|
||||
|
@ -678,7 +678,7 @@ static void do_transfer_curse(curse * c, unit * u, unit * u2, int n)
|
|||
}
|
||||
}
|
||||
|
||||
void transfer_curse(unit * u, unit * u2, int n)
|
||||
void transfer_curse(const unit * u, unit * u2, int n)
|
||||
{
|
||||
attrib *a;
|
||||
|
||||
|
|
|
@ -267,7 +267,7 @@ extern "C" {
|
|||
|
||||
/* gibt bei Personenbeschränkten Verzauberungen die Anzahl der
|
||||
* betroffenen Personen zurück. Ansonsten wird 0 zurückgegeben. */
|
||||
int get_cursedmen(struct unit *u, const struct curse *c);
|
||||
int get_cursedmen(const struct unit *u, const struct curse *c);
|
||||
|
||||
/* setzt/loescht Spezialflag einer Verzauberung (zB 'dauert ewig') */
|
||||
void c_setflag(curse * c, unsigned int flag);
|
||||
|
@ -277,7 +277,7 @@ extern "C" {
|
|||
* korrekt gehandhabt werden. Je nach internen Flag kann dies
|
||||
* unterschiedlich gewünscht sein
|
||||
* */
|
||||
void transfer_curse(struct unit *u, struct unit *u2, int n);
|
||||
void transfer_curse(const struct unit *u, struct unit *u2, int n);
|
||||
|
||||
/* gibt pointer auf die erste curse-struct zurück, deren Typ ctype ist,
|
||||
* oder einen NULL-pointer
|
||||
|
|
|
@ -981,10 +981,9 @@ void move_unit(unit * u, region * r, unit ** ulist)
|
|||
/* ist mist, aber wegen nicht skalierender attribute notwendig: */
|
||||
#include "alchemy.h"
|
||||
|
||||
void clone_men(unit * u, unit * dst, int n)
|
||||
void clone_men(const unit * u, unit * dst, int n)
|
||||
{
|
||||
const attrib *a;
|
||||
int hp = u->hp;
|
||||
region *r = u->region;
|
||||
|
||||
if (n == 0)
|
||||
|
@ -1073,11 +1072,9 @@ void clone_men(unit * u, unit * dst, int n)
|
|||
if (u->attribs) {
|
||||
transfer_curse(u, dst, n);
|
||||
}
|
||||
}
|
||||
if (dst) {
|
||||
set_number(dst, dst->number + n);
|
||||
hp -= u->hp;
|
||||
dst->hp += hp;
|
||||
dst->hp += u->hp * dst->number / u->number;
|
||||
assert(dst->hp >= dst->number);
|
||||
/* TODO: Das ist schnarchlahm! und gehoert nicht hierhin */
|
||||
a = a_find(dst->attribs, &at_effect);
|
||||
while (a && a->type == &at_effect) {
|
||||
|
@ -1530,7 +1527,9 @@ unit *create_unit(region * r, faction * f, int number, const struct race *urace,
|
|||
|
||||
/* u->race muss bereits gesetzt sein, wird fuer default-hp gebraucht */
|
||||
/* u->region auch */
|
||||
if (number > 0) {
|
||||
u->hp = unit_max_hp(u) * number;
|
||||
}
|
||||
|
||||
if (dname) {
|
||||
u->_name = strdup(dname);
|
||||
|
|
|
@ -166,7 +166,7 @@ extern "C" {
|
|||
void set_level(struct unit *u, skill_t id, int level);
|
||||
int get_level(const struct unit *u, skill_t id);
|
||||
void transfermen(struct unit *src, struct unit *dst, int n);
|
||||
void clone_men(struct unit *src, struct unit *dst, int n); /* like transfer, but do not subtract from src */
|
||||
void clone_men(const struct unit *src, struct unit *dst, int n); /* like transfer, but do not subtract from src */
|
||||
|
||||
int eff_skill(const struct unit *u, const struct skill *sv, const struct region *r);
|
||||
int effskill_study(const struct unit *u, skill_t sk, const struct region *r);
|
||||
|
|
|
@ -525,6 +525,29 @@ static void test_unlimited_units(CuTest *tc) {
|
|||
test_cleanup();
|
||||
}
|
||||
|
||||
static void test_clone_men(CuTest *tc) {
|
||||
unit *u1, *u2;
|
||||
region *r;
|
||||
faction *f;
|
||||
test_setup();
|
||||
r = test_create_region(0, 0, NULL);
|
||||
f = test_create_faction(NULL);
|
||||
u1 = test_create_unit(f, r);
|
||||
scale_number(u1, 10);
|
||||
u2 = test_create_unit(f, r);
|
||||
scale_number(u2, 0);
|
||||
CuAssertIntEquals(tc, 10, u1->number);
|
||||
CuAssertIntEquals(tc, 200, u1->hp);
|
||||
CuAssertIntEquals(tc, 0, u2->number);
|
||||
CuAssertIntEquals(tc, 0, u2->hp);
|
||||
clone_men(u1, u2, 1);
|
||||
CuAssertIntEquals(tc, 10, u1->number);
|
||||
CuAssertIntEquals(tc, 200, u1->hp);
|
||||
CuAssertIntEquals(tc, 1, u2->number);
|
||||
CuAssertIntEquals(tc, 20, u2->hp);
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
CuSuite *get_unit_suite(void)
|
||||
{
|
||||
CuSuite *suite = CuSuiteNew();
|
||||
|
@ -533,6 +556,7 @@ CuSuite *get_unit_suite(void)
|
|||
SUITE_ADD_TEST(suite, test_unit_name);
|
||||
SUITE_ADD_TEST(suite, test_unit_name_from_race);
|
||||
SUITE_ADD_TEST(suite, test_update_monster_name);
|
||||
SUITE_ADD_TEST(suite, test_clone_men);
|
||||
SUITE_ADD_TEST(suite, test_remove_unit);
|
||||
SUITE_ADD_TEST(suite, test_remove_empty_units);
|
||||
SUITE_ADD_TEST(suite, test_remove_units_without_faction);
|
||||
|
|
|
@ -191,6 +191,7 @@ void get_food(region * r)
|
|||
int need = lifestyle(u);
|
||||
faction *f = u->faction;
|
||||
|
||||
assert(u->hp > 0);
|
||||
need -= MAX(0, get_money(u));
|
||||
|
||||
if (need > 0) {
|
||||
|
|
Loading…
Reference in New Issue