Fix GIVE 0 behavior on oceans.

This commit is contained in:
Enno Rehling 2014-12-11 08:35:05 +01:00
parent 215136465b
commit ef415c66d0
3 changed files with 75 additions and 13 deletions

View File

@ -7112,6 +7112,15 @@
<text locale="en">"$unit($target) receives $int($amount) $resource($resource,$amount) from $unit($unit)."</text>
</message>
<message name="give_person_ocean" section="economy">
<type>
<arg name="unit" type="unit"/>
<arg name="amount" type="int"/>
</type>
<text locale="de">"$unit($unit) ertränkt $int($amount) Person$if($eq($amount,1),"","en")."</text>
<text locale="en">"$unit($unit) drowns $int($amount)."</text>
</message>
<message name="give_person_peasants" section="economy">
<type>
<arg name="unit" type="unit"/>

View File

@ -393,6 +393,9 @@ message * disband_men(int n, unit * u, struct order *ord) {
a->data.i += n;
}
#endif
if (fval(u->region->terrain, SEA_REGION)) {
return msg_message("give_person_ocean", "unit amount", u, n);
}
return msg_message("give_person_peasants", "unit amount", u, n);
}
@ -421,12 +424,19 @@ void give_unit(unit * u, unit * u2, order * ord)
}
if (u2 == NULL) {
message *msg;
if (fval(r->terrain, SEA_REGION)) {
cmistake(u, ord, 152, MSG_COMMERCE);
/* TODO: why is this here, but the unit does not actually seem to lose any men? */
msg = disband_men(u->number, u, ord);
if (msg) {
ADDMSG(&u->faction->msgs, msg);
}
else {
cmistake(u, ord, 152, MSG_COMMERCE);
}
}
else if (getunitpeasants) {
unit *u3;
message *msg;
for (u3 = r->units; u3; u3 = u3->next)
if (u3->faction == u->faction && u != u3)
@ -596,12 +606,10 @@ void give_cmd(unit * u, order * ord)
msg_feedback(u, ord, "race_notake", "race", u_race(u2)));
return;
}
if (!u2) {
if (!getunitpeasants) {
ADDMSG(&u->faction->msgs, msg_feedback(u, ord,
"feedback_unit_not_found", ""));
return;
}
if (!u2 && !getunitpeasants) {
ADDMSG(&u->faction->msgs, msg_feedback(u, ord,
"feedback_unit_not_found", ""));
return;
}
if (u->items) {
item **itmp = &u->items;
@ -691,7 +699,7 @@ void give_cmd(unit * u, order * ord)
}
else {
message * msg;
msg = getunitpeasants ? disband_men(u->number, u, ord) : give_men(u->number, u, u2, ord);
msg = u2 ? give_men(u->number, u, u2, ord) : disband_men(u->number, u, ord);
if (msg) {
ADDMSG(&u->faction->msgs, msg);
}
@ -747,7 +755,7 @@ void give_cmd(unit * u, order * ord)
msg_feedback(u, ord, "race_noregroup", "race", u_race(u)));
return;
}
msg = getunitpeasants ? disband_men(u->number, u, ord) : give_men(u->number, u, u2, ord);
msg = u2 ? give_men(u->number, u, u2, ord) : disband_men(u->number, u, ord);
if (msg) {
ADDMSG(&u->faction->msgs, msg);
}

View File

@ -36,6 +36,33 @@ static void setup_give(struct give *env) {
env->itype->flags |= ITF_HERB;
}
static void test_give_unit_to_peasants(CuTest * tc) {
struct give env;
test_cleanup();
env.f1 = test_create_faction(0);
env.f2 = 0;
setup_give(&env);
rsetpeasants(env.r, 0);
getunitpeasants = true;
give_unit(env.src, NULL, NULL);
CuAssertIntEquals(tc, 0, env.src->number);
CuAssertIntEquals(tc, 1, env.r->land->peasants);
test_cleanup();
}
static void test_give_unit_in_ocean(CuTest * tc) {
struct give env;
test_cleanup();
env.f1 = test_create_faction(0);
env.f2 = 0;
setup_give(&env);
env.r->terrain = test_create_terrain("ocean", SEA_REGION);
getunitpeasants = true;
give_unit(env.src, NULL, NULL);
CuAssertIntEquals(tc, 0, env.src->number);
test_cleanup();
}
static void test_give_men(CuTest * tc) {
struct give env;
test_cleanup();
@ -47,6 +74,21 @@ static void test_give_men(CuTest * tc) {
test_cleanup();
}
static void test_give_men_in_ocean(CuTest * tc) {
struct give env;
message * msg;
test_cleanup();
env.f1 = test_create_faction(0);
env.f2 = 0;
setup_give(&env);
env.r->terrain = test_create_terrain("ocean", SEA_REGION);
msg = disband_men(1, env.src, NULL);
CuAssertStrEquals(tc, "give_person_ocean", (const char *)msg->parameters[0].v);
CuAssertIntEquals(tc, 0, env.src->number);
test_cleanup();
}
static void test_give_men_too_many(CuTest * tc) {
struct give env;
test_cleanup();
@ -118,16 +160,16 @@ static void test_give_men_not_to_self(CuTest * tc) {
static void test_give_peasants(CuTest * tc) {
struct give env;
message * msg;
int peasants;
test_cleanup();
env.f1 = test_create_faction(0);
env.f2 = 0;
setup_give(&env);
peasants = env.r->land->peasants;
rsetpeasants(env.r, 0);
msg = disband_men(1, env.src, NULL);
CuAssertStrEquals(tc, "give_person_peasants", (const char*)msg->parameters[0].v);
CuAssertIntEquals(tc, 0, env.src->number);
CuAssertIntEquals(tc, peasants+1, env.r->land->peasants);
CuAssertIntEquals(tc, 1, env.r->land->peasants);
test_cleanup();
}
@ -207,11 +249,14 @@ CuSuite *get_give_suite(void)
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_give);
SUITE_ADD_TEST(suite, test_give_men);
SUITE_ADD_TEST(suite, test_give_men_in_ocean);
SUITE_ADD_TEST(suite, test_give_men_none);
SUITE_ADD_TEST(suite, test_give_men_too_many);
SUITE_ADD_TEST(suite, test_give_men_other_faction);
SUITE_ADD_TEST(suite, test_give_men_requires_contact);
SUITE_ADD_TEST(suite, test_give_men_not_to_self);
SUITE_ADD_TEST(suite, test_give_unit_in_ocean);
SUITE_ADD_TEST(suite, test_give_unit_to_peasants);
SUITE_ADD_TEST(suite, test_give_peasants);
SUITE_ADD_TEST(suite, test_give_herbs);
SUITE_ADD_TEST(suite, test_give_okay);