Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 3017: Fix message text when movement is blocked #1062

Merged
merged 2 commits into from
Mar 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion res/core/messages.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2191,7 +2191,7 @@
<arg name="target" type="region"/>
</type>
</message>
<message name="leavefail" section="errors">
<message name="enterfail" section="errors">
<type>
<arg name="unit" type="unit"/>
<arg name="region" type="region"/>
Expand Down
4 changes: 2 additions & 2 deletions res/translations/messages.de.po
Original file line number Diff line number Diff line change
Expand Up @@ -2551,8 +2551,8 @@ msgctxt "curseinfo"
msgid "maelstrom"
msgstr "Der Mahlstrom in dieser Region wird alle Schiffe, die in seinen Sog geraten, schwer beschädigen. ($int36($id))"

msgid "leavefail"
msgstr "\"$unit($unit) konnte aus $region($region) nicht ausreisen.\""
msgid "enterfail"
msgstr "\"$unit($unit) konnte nach $region($region) nicht einreisen.\""

msgid "reduced_production"
msgstr "Die Region ist verwüstet, der Boden karg."
Expand Down
4 changes: 2 additions & 2 deletions res/translations/messages.en.po
Original file line number Diff line number Diff line change
Expand Up @@ -2551,8 +2551,8 @@ msgctxt "curseinfo"
msgid "maelstrom"
msgstr "The maelstrom in this area will heavily damage all ships coming into its wake. ($int36($id))"

msgid "leavefail"
msgstr "\"$unit($unit) could not leave $region($region).\""
msgid "enterfail"
msgstr "\"$unit($unit) could not enter $region($region).\""

msgid "reduced_production"
msgstr "The region is ravaged, the ground infertile."
Expand Down
8 changes: 4 additions & 4 deletions src/move.c
Original file line number Diff line number Diff line change
Expand Up @@ -1103,14 +1103,14 @@ bool move_blocked(const unit * u, const region * r, const region * r2)
}
b = b->next;
}

#ifdef ENABLE_FOGTRAP_CURSE
if (r->attribs) {
curse *c = get_curse(r->attribs, &ct_fogtrap);
if (curse_active(c)) {
return true;
}
}

#endif
if (r2->attribs && fval(u_race(u), RCF_UNDEAD)) {
curse *c = get_curse(r2->attribs, &ct_holyground);
return curse_active(c);
Expand Down Expand Up @@ -1657,9 +1657,9 @@ static const region_list *travel_route(unit * u, const capacities *cap,

}

/* movement blocked by a wall */
/* movement blocked by a wall or curse */
if (reldir >= 0 && move_blocked(u, current, next)) {
ADDMSG(&u->faction->msgs, msg_message("leavefail",
ADDMSG(&u->faction->msgs, msg_message("enterfail",
"unit region", u, next));
break;
}
Expand Down
107 changes: 107 additions & 0 deletions src/move.test.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
#include "contact.h"
#include "lighthouse.h"
#include "attributes/follow.h"
#include "spells/regioncurse.h"

#include "kernel/attrib.h"
#include "kernel/ally.h"
#include "kernel/building.h"
#include "kernel/config.h"
#include "kernel/curse.h"
#include "kernel/faction.h"
#include "kernel/direction.h" // for D_WEST, shortdirections, D_EAST, dire...
#include "kernel/region.h"
Expand Down Expand Up @@ -39,6 +41,8 @@ static void setup_move(void) {
"unit:unit", "start:region", "end:region", "mode:int", "regions:regions", MT_NEW_END);
mt_create_va(mt_new("moveblocked", NULL),
"unit:unit", "direction:int", MT_NEW_END);
mt_create_va(mt_new("enterfail", NULL),
"unit:unit", "region:region", MT_NEW_END);
}

static void test_ship_not_allowed_in_coast(CuTest * tc)
Expand Down Expand Up @@ -1327,6 +1331,104 @@ static void test_transport_stealthed(CuTest* tc)
test_teardown();
}

#ifdef ENABLE_FOGTRAP_CURSE
static void test_move_blocked_by_fogtrap(CuTest* tc) {
unit* u;
region* r, *rt;
struct locale* lang;

test_setup();
setup_move();
register_regioncurse();
rt = test_create_region(1, 0, NULL);
r = test_create_region(2, 0, NULL);
lang = test_create_locale();
u = test_create_unit(test_create_faction(), r);
u->faction->locale = lang;
u->thisorder = create_order(K_MOVE, lang, "WEST");
create_curse(u, &rt->attribs, ct_find("fogtrap"), 2.0, 2, 4.0, 0);
/* Es wird erst gar keine Route erzeugt: */
move_cmd(u, u->thisorder);
CuAssertPtrEquals(tc, NULL, u->thisorder);
CuAssertPtrEquals(tc, NULL, test_find_messagetype(u->faction->msgs, "enterfail"));
CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "moveblocked"));
CuAssertPtrEquals(tc, r, u->region);
test_teardown();
}
#endif

static void test_holyground_blocks_undead_moves(CuTest* tc) {
unit* u;
region* r, *rt;
struct locale* lang;
race* rc;
message* msg;

test_setup();
setup_move();
register_regioncurse();
rt = test_create_region(1, 0, NULL);
r = test_create_region(2, 0, NULL);
lang = test_create_locale();
u = test_create_unit(test_create_faction(), r);
u->faction->locale = lang;
rc = test_create_race("undead");
rc->flags |= RCF_UNDEAD;
u_setrace(u, rc);
u->thisorder = create_order(K_MOVE, lang, "WEST");
create_curse(u, &rt->attribs, ct_find("holyground"), 2.0, 2, 4.0, 0);
/* Es wird erst gar keine Route erzeugt: */
move_cmd(u, u->thisorder);
CuAssertPtrEquals(tc, NULL, u->thisorder);
CuAssertPtrEquals(tc, NULL, test_find_messagetype(u->faction->msgs, "enterfail"));
CuAssertPtrNotNull(tc, msg = test_find_messagetype(u->faction->msgs, "moveblocked"));
CuAssertPtrEquals(tc, u, msg->parameters[0].v);
CuAssertIntEquals(tc, D_WEST, msg->parameters[1].i);
CuAssertPtrEquals(tc, r, u->region);
test_teardown();
}

static void test_holyground_blocks_undead_follow(CuTest* tc) {
unit* u, *u2;
region* r, *rt;
struct locale* lang;
race* rc;
message* msg;

test_setup();
setup_move();
register_regioncurse();
rt = test_create_region(1, 0, NULL);
r = test_create_region(2, 0, NULL);
lang = test_create_locale();
u = test_create_unit(test_create_faction(), r);
u->faction->locale = lang;
rc = test_create_race("undead");
rc->flags |= RCF_UNDEAD;
u_setrace(u, rc);
u2 = test_create_unit(test_create_faction(), r);
u2->thisorder = create_order(K_MOVE, lang, "WEST");
u->orders = create_order(K_FOLLOW, lang, "%s %s",
param_name(P_UNIT, lang), itoa36(u2->no));
create_curse(u, &rt->attribs, ct_find("holyground"), 2.0, 2, 4.0, 0);

follow_cmds(u);
CuAssertIntEquals(tc, UFL_FOLLOWED, u2->flags & UFL_FOLLOWED);
CuAssertIntEquals(tc, UFL_FOLLOWING, u->flags & UFL_FOLLOWING);
move_cmd(u2, u2->thisorder);
CuAssertPtrEquals(tc, rt, u2->region);
CuAssertPtrEquals(tc, r, u->region);
CuAssertPtrEquals(tc, NULL, u2->thisorder);
CuAssertPtrEquals(tc, NULL, u->thisorder);
CuAssertPtrEquals(tc, NULL, test_find_messagetype(u2->faction->msgs, "enterfail"));
CuAssertPtrEquals(tc, NULL, test_find_messagetype(u2->faction->msgs, "moveblocked"));
CuAssertPtrEquals(tc, NULL, test_find_messagetype(u->faction->msgs, "moveblocked"));
CuAssertPtrNotNull(tc, msg = test_find_messagetype(u->faction->msgs, "enterfail"));
CuAssertPtrEquals(tc, u, msg->parameters[0].v);
CuAssertPtrEquals(tc, rt, msg->parameters[1].v);
test_teardown();
}

CuSuite *get_move_suite(void)
{
CuSuite *suite = CuSuiteNew();
Expand Down Expand Up @@ -1375,5 +1477,10 @@ CuSuite *get_move_suite(void)
SUITE_ADD_TEST(suite, test_make_movement_order);
SUITE_ADD_TEST(suite, test_transport_unit);
SUITE_ADD_TEST(suite, test_transport_stealthed);
#ifdef ENABLE_FOGTRAP_CURSE
SUITE_ADD_TEST(suite, test_move_blocked_by_fogtrap);
#endif
SUITE_ADD_TEST(suite, test_holyground_blocks_undead_moves);
SUITE_ADD_TEST(suite, test_holyground_blocks_undead_follow);
return suite;
}