forked from github/server
EXPEL: additional messages and tests.
This commit is contained in:
parent
1711812b0b
commit
5926016010
|
@ -4732,6 +4732,13 @@
|
||||||
<arg name="command" type="order"/>
|
<arg name="command" type="order"/>
|
||||||
</type>
|
</type>
|
||||||
</message>
|
</message>
|
||||||
|
<message name="feedback_not_inside" section="errors">
|
||||||
|
<type>
|
||||||
|
<arg name="unit" type="unit"/>
|
||||||
|
<arg name="region" type="region"/>
|
||||||
|
<arg name="command" type="order"/>
|
||||||
|
</type>
|
||||||
|
</message>
|
||||||
<message name="feedback_unit_not_found" section="errors">
|
<message name="feedback_unit_not_found" section="errors">
|
||||||
<type>
|
<type>
|
||||||
<arg name="unit" type="unit"/>
|
<arg name="unit" type="unit"/>
|
||||||
|
|
|
@ -590,6 +590,9 @@ msgstr "\"$unit($unit) in $region($region): '$order($command)' - Um in Gletscher
|
||||||
msgid "feedback_unit_not_found"
|
msgid "feedback_unit_not_found"
|
||||||
msgstr "\"$unit($unit) in $region($region): '$order($command)' - Die Einheit wurde nicht gefunden.\""
|
msgstr "\"$unit($unit) in $region($region): '$order($command)' - Die Einheit wurde nicht gefunden.\""
|
||||||
|
|
||||||
|
msgid "feedback_not_inside"
|
||||||
|
msgstr "\"$unit($unit) in $region($region): '$order($command)' - Die Einheit kontrolliert kein Schiff oder Gebäude.\""
|
||||||
|
|
||||||
msgid "error206"
|
msgid "error206"
|
||||||
msgstr "\"$unit($unit) in $region($region): '$order($command)' - Auf dem Gebäude liegt bereits so ein Zauber.\""
|
msgstr "\"$unit($unit) in $region($region): '$order($command)' - Auf dem Gebäude liegt bereits so ein Zauber.\""
|
||||||
|
|
||||||
|
|
|
@ -590,6 +590,9 @@ msgstr "\"$unit($unit) in $region($region): '$order($command)' - You must build
|
||||||
msgid "feedback_unit_not_found"
|
msgid "feedback_unit_not_found"
|
||||||
msgstr "\"$unit($unit) in $region($region): '$order($command)' - The unit could not be found.\""
|
msgstr "\"$unit($unit) in $region($region): '$order($command)' - The unit could not be found.\""
|
||||||
|
|
||||||
|
msgid "feedback_unit_not_found"
|
||||||
|
msgstr "\"$unit($unit) in $region($region): '$order($command)' - The unit is not the owner of a ship or building.\""
|
||||||
|
|
||||||
msgid "error206"
|
msgid "error206"
|
||||||
msgstr "\"$unit($unit) in $region($region): '$order($command)' - There is alrady a spell on that building.\""
|
msgstr "\"$unit($unit) in $region($region): '$order($command)' - There is alrady a spell on that building.\""
|
||||||
|
|
||||||
|
|
22
src/battle.c
22
src/battle.c
|
@ -3925,21 +3925,25 @@ void force_leave(region *r, battle *b) {
|
||||||
if (u->building) {
|
if (u->building) {
|
||||||
uo = building_owner(u->building);
|
uo = building_owner(u->building);
|
||||||
}
|
}
|
||||||
if (u->ship && r->land) {
|
else if (u->ship && r->land) {
|
||||||
uo = ship_owner(u->ship);
|
uo = ship_owner(u->ship);
|
||||||
}
|
}
|
||||||
if (uo && is_enemy(b, uo, u)) {
|
else {
|
||||||
message *msg = NULL;
|
continue;
|
||||||
if (u->building) {
|
}
|
||||||
msg = msg_message("force_leave_building", "unit owner building", u, uo, u->building);
|
if (is_enemy(b, uo, u)) {
|
||||||
|
if (leave(u, true)) {
|
||||||
|
message *msg;
|
||||||
|
if (uo->building) {
|
||||||
|
msg = msg_message("force_leave_building", "unit owner building", u, uo, uo->building);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
msg = msg_message("force_leave_ship", "unit owner ship", u, uo, u->ship);
|
msg = msg_message("force_leave_ship", "unit owner ship", u, uo, uo->ship);
|
||||||
}
|
}
|
||||||
if (msg) {
|
add_message(&u->faction->msgs, msg);
|
||||||
ADDMSG(&u->faction->msgs, msg);
|
add_message(&uo->faction->msgs, msg);
|
||||||
|
msg_release(msg);
|
||||||
}
|
}
|
||||||
leave(u, false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
16
src/laws.c
16
src/laws.c
|
@ -4197,7 +4197,12 @@ static void expel_building(unit *u, unit *u2, order *ord) {
|
||||||
cmistake(u, ord, 5, MSG_EVENT);
|
cmistake(u, ord, 5, MSG_EVENT);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
leave_building(u2);
|
if (leave(u2, true)) {
|
||||||
|
message *msg = msg_message("force_leave_building", "owner unit building", u, u2, u->building);
|
||||||
|
add_message(&u->faction->msgs, msg);
|
||||||
|
add_message(&u2->faction->msgs, msg);
|
||||||
|
msg_release(msg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4213,7 +4218,12 @@ static void expel_ship(unit *u, unit *u2, order *ord) {
|
||||||
msg_feedback(u, ord, "error_onlandonly", NULL));
|
msg_feedback(u, ord, "error_onlandonly", NULL));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
leave_ship(u2);
|
if (leave(u2, true)) {
|
||||||
|
message *msg = msg_message("force_leave_ship", "owner unit ship", u, u2, u->ship);
|
||||||
|
add_message(&u->faction->msgs, msg);
|
||||||
|
add_message(&u2->faction->msgs, msg);
|
||||||
|
msg_release(msg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4235,6 +4245,8 @@ int expel_cmd(unit *u, order *ord) {
|
||||||
expel_ship(u, u2, ord);
|
expel_ship(u, u2, ord);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
ADDMSG(&u->faction->msgs,
|
||||||
|
msg_feedback(u, ord, "feedback_not_inside", NULL));
|
||||||
/* error: unit must be owner of a ship or building */
|
/* error: unit must be owner of a ship or building */
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -181,21 +181,30 @@ static void test_expel_building(CuTest *tc) {
|
||||||
test_setup();
|
test_setup();
|
||||||
u1 = test_create_unit(test_create_faction(), test_create_plain(0, 0));
|
u1 = test_create_unit(test_create_faction(), test_create_plain(0, 0));
|
||||||
u2 = test_create_unit(test_create_faction(), u1->region);
|
u2 = test_create_unit(test_create_faction(), u1->region);
|
||||||
|
ord = create_order(K_EXPEL, u2->faction->locale, "%s", itoa36(u1->no));
|
||||||
|
|
||||||
|
expel_cmd(u2, ord);
|
||||||
|
CuAssertPtrNotNull(tc, test_find_messagetype(u2->faction->msgs, "feedback_not_inside"));
|
||||||
|
test_clear_messages(u2->faction);
|
||||||
|
|
||||||
b = u2->building = u1->building = test_create_building(u1->region, NULL);
|
b = u2->building = u1->building = test_create_building(u1->region, NULL);
|
||||||
CuAssertPtrEquals(tc, u1, building_owner(b));
|
CuAssertPtrEquals(tc, u1, building_owner(b));
|
||||||
|
|
||||||
ord = create_order(K_EXPEL, u2->faction->locale, "%s", itoa36(u1->no));
|
|
||||||
expel_cmd(u2, ord);
|
expel_cmd(u2, ord);
|
||||||
/* Nothing happened: */
|
/* Nothing happened: */
|
||||||
CuAssertPtrEquals(tc, u1, building_owner(b));
|
CuAssertPtrEquals(tc, u1, building_owner(b));
|
||||||
CuAssertPtrEquals(tc, b, u1->building);
|
CuAssertPtrEquals(tc, b, u1->building);
|
||||||
CuAssertPtrEquals(tc, b, u2->building);
|
CuAssertPtrEquals(tc, b, u2->building);
|
||||||
|
CuAssertPtrNotNull(tc, test_find_messagetype(u2->faction->msgs, "error5"));
|
||||||
|
test_clear_messages(u1->faction);
|
||||||
free_order(ord);
|
free_order(ord);
|
||||||
|
|
||||||
ord = create_order(K_EXPEL, u1->faction->locale, "%s", itoa36(u2->no));
|
ord = create_order(K_EXPEL, u1->faction->locale, "%s", itoa36(u2->no));
|
||||||
expel_cmd(u1, ord);
|
expel_cmd(u1, ord);
|
||||||
/* owner has expelled u2: */
|
/* owner has expelled u2: */
|
||||||
CuAssertPtrEquals(tc, NULL, u2->building);
|
CuAssertPtrEquals(tc, NULL, u2->building);
|
||||||
|
CuAssertPtrNotNull(tc, test_find_messagetype(u1->faction->msgs, "force_leave_building"));
|
||||||
|
CuAssertPtrNotNull(tc, test_find_messagetype(u2->faction->msgs, "force_leave_building"));
|
||||||
test_teardown();
|
test_teardown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,15 +216,21 @@ static void test_expel_ship(CuTest *tc) {
|
||||||
test_setup();
|
test_setup();
|
||||||
u1 = test_create_unit(test_create_faction(), test_create_plain(0, 0));
|
u1 = test_create_unit(test_create_faction(), test_create_plain(0, 0));
|
||||||
u2 = test_create_unit(test_create_faction(), u1->region);
|
u2 = test_create_unit(test_create_faction(), u1->region);
|
||||||
|
ord = create_order(K_EXPEL, u2->faction->locale, "%s", itoa36(u1->no));
|
||||||
|
expel_cmd(u2, ord);
|
||||||
|
CuAssertPtrNotNull(tc, test_find_messagetype(u2->faction->msgs, "feedback_not_inside"));
|
||||||
|
test_clear_messages(u2->faction);
|
||||||
|
|
||||||
sh = u2->ship = u1->ship = test_create_ship(u1->region, NULL);
|
sh = u2->ship = u1->ship = test_create_ship(u1->region, NULL);
|
||||||
CuAssertPtrEquals(tc, u1, ship_owner(sh));
|
CuAssertPtrEquals(tc, u1, ship_owner(sh));
|
||||||
|
|
||||||
ord = create_order(K_EXPEL, u2->faction->locale, "%s", itoa36(u1->no));
|
|
||||||
expel_cmd(u2, ord);
|
expel_cmd(u2, ord);
|
||||||
/* Nothing happened: */
|
/* Nothing happened: */
|
||||||
CuAssertPtrEquals(tc, u1, ship_owner(sh));
|
CuAssertPtrEquals(tc, u1, ship_owner(sh));
|
||||||
CuAssertPtrEquals(tc, sh, u1->ship);
|
CuAssertPtrEquals(tc, sh, u1->ship);
|
||||||
CuAssertPtrEquals(tc, sh, u2->ship);
|
CuAssertPtrEquals(tc, sh, u2->ship);
|
||||||
|
CuAssertPtrNotNull(tc, test_find_messagetype(u2->faction->msgs, "error146"));
|
||||||
|
test_clear_messages(u2->faction);
|
||||||
free_order(ord);
|
free_order(ord);
|
||||||
|
|
||||||
ord = create_order(K_EXPEL, u1->faction->locale, "%s", itoa36(u2->no));
|
ord = create_order(K_EXPEL, u1->faction->locale, "%s", itoa36(u2->no));
|
||||||
|
@ -223,6 +238,27 @@ static void test_expel_ship(CuTest *tc) {
|
||||||
/* owner has expelled u2: */
|
/* owner has expelled u2: */
|
||||||
CuAssertPtrEquals(tc, NULL, u2->ship);
|
CuAssertPtrEquals(tc, NULL, u2->ship);
|
||||||
CuAssertPtrEquals(tc, sh, leftship(u2));
|
CuAssertPtrEquals(tc, sh, leftship(u2));
|
||||||
|
CuAssertPtrNotNull(tc, test_find_messagetype(u1->faction->msgs, "force_leave_ship"));
|
||||||
|
CuAssertPtrNotNull(tc, test_find_messagetype(u2->faction->msgs, "force_leave_ship"));
|
||||||
|
test_teardown();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_expel_ship_at_sea(CuTest *tc) {
|
||||||
|
unit *u1, *u2;
|
||||||
|
order *ord;
|
||||||
|
ship *sh;
|
||||||
|
|
||||||
|
test_setup();
|
||||||
|
u1 = test_create_unit(test_create_faction(), test_create_ocean(0, 0));
|
||||||
|
u2 = test_create_unit(test_create_faction(), u1->region);
|
||||||
|
sh = u2->ship = u1->ship = test_create_ship(u1->region, NULL);
|
||||||
|
CuAssertPtrEquals(tc, u1, ship_owner(sh));
|
||||||
|
|
||||||
|
ord = create_order(K_EXPEL, u1->faction->locale, "%s", itoa36(u2->no));
|
||||||
|
expel_cmd(u1, ord);
|
||||||
|
/* owner has not expelled u2: */
|
||||||
|
CuAssertPtrNotNull(tc, test_find_messagetype(u1->faction->msgs, "error_onlandonly"));
|
||||||
|
CuAssertPtrEquals(tc, sh, u2->ship);
|
||||||
test_teardown();
|
test_teardown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2375,6 +2411,7 @@ CuSuite *get_laws_suite(void)
|
||||||
SUITE_ADD_TEST(suite, test_display_cmd);
|
SUITE_ADD_TEST(suite, test_display_cmd);
|
||||||
SUITE_ADD_TEST(suite, test_expel_building);
|
SUITE_ADD_TEST(suite, test_expel_building);
|
||||||
SUITE_ADD_TEST(suite, test_expel_ship);
|
SUITE_ADD_TEST(suite, test_expel_ship);
|
||||||
|
SUITE_ADD_TEST(suite, test_expel_ship_at_sea);
|
||||||
SUITE_ADD_TEST(suite, test_rule_force_leave);
|
SUITE_ADD_TEST(suite, test_rule_force_leave);
|
||||||
SUITE_ADD_TEST(suite, test_force_leave_buildings);
|
SUITE_ADD_TEST(suite, test_force_leave_buildings);
|
||||||
SUITE_ADD_TEST(suite, test_force_leave_ships);
|
SUITE_ADD_TEST(suite, test_force_leave_ships);
|
||||||
|
|
Loading…
Reference in New Issue