forked from github/server
Merge pull request #545 from ennorehling/bug-2230-give-dead
Bug 2230: do not allow GIVE to dead units
This commit is contained in:
commit
348a8c24c0
|
@ -70,7 +70,11 @@ static void feedback_give_not_allowed(unit * u, order * ord)
|
|||
static bool can_give(const unit * u, const unit * u2, const item_type * itype, int mask)
|
||||
{
|
||||
if (u2) {
|
||||
if (u->faction != u2->faction) {
|
||||
if (u2->number==0 && !fval(u2, UFL_ISNEW)) {
|
||||
// https://bugs.eressea.de/view.php?id=2230
|
||||
// cannot give anything to dead units
|
||||
return false;
|
||||
} else if (u->faction != u2->faction) {
|
||||
int rule = rule_give();
|
||||
if (itype) {
|
||||
assert(mask == 0);
|
||||
|
|
|
@ -316,6 +316,34 @@ static void test_give_denied_by_rules(CuTest * tc) {
|
|||
test_cleanup();
|
||||
}
|
||||
|
||||
static void test_give_dead_unit(CuTest * tc) {
|
||||
struct give env;
|
||||
struct message *msg;
|
||||
|
||||
test_cleanup();
|
||||
env.f1 = test_create_faction(0);
|
||||
env.f2 = test_create_faction(0);
|
||||
setup_give(&env);
|
||||
env.dst->number = 0;
|
||||
freset(env.dst, UFL_ISNEW);
|
||||
CuAssertPtrNotNull(tc, msg = check_give(env.src, env.dst, 0));
|
||||
msg_release(msg);
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
static void test_give_new_unit(CuTest * tc) {
|
||||
struct give env;
|
||||
|
||||
test_cleanup();
|
||||
env.f1 = test_create_faction(0);
|
||||
env.f2 = test_create_faction(0);
|
||||
setup_give(&env);
|
||||
env.dst->number = 0;
|
||||
fset(env.dst, UFL_ISNEW);
|
||||
CuAssertPtrEquals(tc, 0, check_give(env.src, env.dst, 0));
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
static void test_give_invalid_target(CuTest *tc) {
|
||||
// bug https://bugs.eressea.de/view.php?id=1685
|
||||
struct give env;
|
||||
|
@ -357,5 +385,7 @@ CuSuite *get_give_suite(void)
|
|||
SUITE_ADD_TEST(suite, test_give_okay);
|
||||
SUITE_ADD_TEST(suite, test_give_denied_by_rules);
|
||||
SUITE_ADD_TEST(suite, test_give_invalid_target);
|
||||
SUITE_ADD_TEST(suite, test_give_new_unit);
|
||||
SUITE_ADD_TEST(suite, test_give_dead_unit);
|
||||
return suite;
|
||||
}
|
||||
|
|
|
@ -316,7 +316,7 @@ CuSuite *get_save_suite(void)
|
|||
SUITE_ADD_TEST(suite, test_readwrite_dead_faction_createunit);
|
||||
SUITE_ADD_TEST(suite, test_readwrite_dead_faction_changefaction);
|
||||
SUITE_ADD_TEST(suite, test_readwrite_dead_faction_regionowner);
|
||||
DISABLE_TEST(suite, test_readwrite_dead_faction_group);
|
||||
SUITE_ADD_TEST(suite, test_readwrite_dead_faction_group);
|
||||
SUITE_ADD_TEST(suite, test_read_password);
|
||||
SUITE_ADD_TEST(suite, test_read_password_external);
|
||||
return suite;
|
||||
|
|
Loading…
Reference in New Issue