diff --git a/src/common/gamecode/laws.c b/src/common/gamecode/laws.c index f0f347ff6..701851c48 100644 --- a/src/common/gamecode/laws.c +++ b/src/common/gamecode/laws.c @@ -1780,7 +1780,7 @@ name_cmd(unit * u, struct order * ord) } /* ------------------------------------------------------------- */ -static void +void deliverMail(faction * f, region * r, unit * u, const char *s, unit * receiver) { if (!cansee(f, r, u, 0)) { diff --git a/src/common/gamecode/laws.h b/src/common/gamecode/laws.h index 68e9b90a9..24528f507 100644 --- a/src/common/gamecode/laws.h +++ b/src/common/gamecode/laws.h @@ -32,10 +32,10 @@ void demographics(void); void last_orders(void); void find_address(void); void update_guards(void); + extern void deliverMail(struct faction * f, struct region * r, struct unit * u, const char *s, struct unit * receiver); /* eressea-specific. put somewhere else, please. */ #include "resolve.h" - void processorders(void); extern attrib_type at_germs; diff --git a/src/eressea/lua/gamecode.cpp b/src/eressea/lua/gamecode.cpp index cd0ccb469..fe304c8e3 100644 --- a/src/eressea/lua/gamecode.cpp +++ b/src/eressea/lua/gamecode.cpp @@ -147,6 +147,25 @@ update_subscriptions(void) fclose(F); } +static void +message_unit(unit& sender, unit& target, const char * str) +{ + deliverMail(target.faction, sender.region, &sender, str, &target); +} + +static void +message_faction(unit& sender, faction& target, const char * str) +{ + deliverMail(&target, sender.region, &sender, str, NULL); +} + +static void +message_region(unit& sender, const char * str) +{ + sprintf(buf, "von %s: '%s'", unitname(&sender), str); + addmessage(sender.region, 0, buf, MSG_MESSAGE, ML_IMPORTANT); +} + static void lua_learnskill(unit& u, const char * skname, float chances) { @@ -266,6 +285,10 @@ bind_gamecode(lua_State * L) def("write_report", &lua_writereport), def("update_guards", &update_guards), + def("message_unit", &message_unit), + def("message_faction", &message_faction), + def("message_region", &message_region), + /* scripted monsters */ def("spawn_braineaters", &spawn_braineaters), def("spawn_undead", &spawn_undead), diff --git a/src/scripts/samples.lua b/src/scripts/samples.lua index 00e4e4a63..7e3ec2f5b 100644 --- a/src/scripts/samples.lua +++ b/src/scripts/samples.lua @@ -161,6 +161,9 @@ function test_handler() print(u) print(u2) print(str) + message_unit(u, u2, "thanks unit, i got your message: " .. str) + message_faction(u, u2.faction, "thanks faction, i got your message: " .. str) + message_region(u, "thanks region, i got your message: " .. str) end plain = terraform(0, 0, "plain") @@ -373,9 +376,42 @@ function run_scripts() end end +function test_moving() + test_movement() + run_scripts() + process_orders() + write_reports() + + if swim.region==ocean then + print "ERROR: Meermenschen können nicht anschwimmen" + end + if sail.region~=r0 then + print "ERROR: Kapitän kann Schiff mit NACH ohne VERLASSE verlassen" + end + if crew.region==r0 then + print "ERROR: Einheiten kann Schiff nicht mit NACH ohne VERLASSE verlassen" + end + drift = false + for i = 1, 100 do + if ships[i].region ~= ocean then + drift = true + break + end + end + if not drift then + print "ERROR: Unbemannte Schiffe treiben nicht ab" + end + if foot.region ~= w1 then + print "ERROR: Fusseinheit hat ihr NACH nicht korrekt ausgeführt" + end + if astra.region ~= r4 then + print "ERROR: Astraleinheit konnte Wirbel nicht benutzen" + end +end + -- test_movement() -- test_fail() --- test_handler() +test_handler() -- test_parser() -- test_monsters() -- test_combat() @@ -387,33 +423,8 @@ end -- write_game("../testg.txt") -- read_game("../testg.txt") -test_movement() run_scripts() process_orders() write_reports() -if swim.region==ocean then - print "ERROR: Meermenschen können nicht anschwimmen" -end -if sail.region~=r0 then - print "ERROR: Kapitän kann Schiff mit NACH ohne VERLASSE verlassen" -end -if crew.region==r0 then - print "ERROR: Einheiten kann Schiff nicht mit NACH ohne VERLASSE verlassen" -end -drift = false -for i = 1, 100 do - if ships[i].region ~= ocean then - drift = true - break - end -end -if not drift then - print "ERROR: Unbemannte Schiffe treiben nicht ab" -end -if foot.region ~= w1 then - print "ERROR: Fusseinheit hat ihr NACH nicht korrekt ausgeführt" -end -if astra.region ~= r4 then - print "ERROR: Astraleinheit konnte Wirbel nicht benutzen" -end +-- test_moving()