lua functions:

message_unit
  message_region
  message_faction
This commit is contained in:
Enno Rehling 2006-10-04 22:25:39 +00:00
parent 99a5f4d525
commit d8cff1f61f
4 changed files with 63 additions and 29 deletions

View File

@ -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) deliverMail(faction * f, region * r, unit * u, const char *s, unit * receiver)
{ {
if (!cansee(f, r, u, 0)) { if (!cansee(f, r, u, 0)) {

View File

@ -32,10 +32,10 @@ void demographics(void);
void last_orders(void); void last_orders(void);
void find_address(void); void find_address(void);
void update_guards(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. */ /* eressea-specific. put somewhere else, please. */
#include "resolve.h" #include "resolve.h"
void processorders(void); void processorders(void);
extern attrib_type at_germs; extern attrib_type at_germs;

View File

@ -147,6 +147,25 @@ update_subscriptions(void)
fclose(F); 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 static void
lua_learnskill(unit& u, const char * skname, float chances) lua_learnskill(unit& u, const char * skname, float chances)
{ {
@ -266,6 +285,10 @@ bind_gamecode(lua_State * L)
def("write_report", &lua_writereport), def("write_report", &lua_writereport),
def("update_guards", &update_guards), def("update_guards", &update_guards),
def("message_unit", &message_unit),
def("message_faction", &message_faction),
def("message_region", &message_region),
/* scripted monsters */ /* scripted monsters */
def("spawn_braineaters", &spawn_braineaters), def("spawn_braineaters", &spawn_braineaters),
def("spawn_undead", &spawn_undead), def("spawn_undead", &spawn_undead),

View File

@ -161,6 +161,9 @@ function test_handler()
print(u) print(u)
print(u2) print(u2)
print(str) 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 end
plain = terraform(0, 0, "plain") plain = terraform(0, 0, "plain")
@ -373,9 +376,42 @@ function run_scripts()
end end
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_movement()
-- test_fail() -- test_fail()
-- test_handler() test_handler()
-- test_parser() -- test_parser()
-- test_monsters() -- test_monsters()
-- test_combat() -- test_combat()
@ -387,33 +423,8 @@ end
-- write_game("../testg.txt") -- write_game("../testg.txt")
-- read_game("../testg.txt") -- read_game("../testg.txt")
test_movement()
run_scripts() run_scripts()
process_orders() process_orders()
write_reports() write_reports()
if swim.region==ocean then -- test_moving()
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