- neues handling von verbosity fuer weniger spam

- tests fuer event-handler (die jetzt auch klappen)
- mehr funktionen (und etwas TODO)

commit #4000 !
This commit is contained in:
Enno Rehling 2008-12-20 22:31:18 +00:00
parent 71f5bc7b6f
commit 22cfb0d5d1
28 changed files with 201 additions and 115 deletions

View File

@ -77,7 +77,7 @@ without prior permission by the authors of Eressea.
#include <string.h>
/* imports */
extern int quiet;
extern int verbosity;
boolean opt_cr_absolute_coords = false;
/* globals */

View File

@ -170,7 +170,7 @@ checkorders(void)
{
faction *f;
puts(" - Warne spaete Spieler...");
if (verbosity>=1) puts(" - Warne spaete Spieler...");
for (f = factions; f; f = f->next)
if (!is_monsters(f) && turn - f->lastorders == NMRTimeout() - 1)
ADDMSG(&f->msgs, msg_message("turnreminder", ""));
@ -841,7 +841,7 @@ demographics(void)
remove_empty_units();
puts(" - Einwanderung...");
if (verbosity>=1) puts(" - Einwanderung...");
for (r = regions; r; r = r->next) {
if (r->land && r->land->newpeasants) {
int rp = rpeasants(r) + r->land->newpeasants;
@ -1061,7 +1061,7 @@ parse_restart(void)
}
}
puts(" - beseitige Spieler, die sich zu lange nicht mehr gemeldet haben...");
if (verbosity>=1) puts(" - beseitige Spieler, die sich zu lange nicht mehr gemeldet haben...");
for (f = factions; f; f = f->next) {
if(fval(f, FFL_NOIDLEOUT)) f->lastorders = turn;
@ -1095,8 +1095,10 @@ parse_restart(void)
continue;
}
}
puts(" - beseitige Spieler, die sich nach der Anmeldung nicht "
"gemeldet haben...");
if (verbosity>=1) {
puts(" - beseitige Spieler, die sich nach der Anmeldung nicht "
"gemeldet haben...");
}
age = calloc(MAX(4,turn+1), sizeof(int));
for (f = factions; f; f = f->next) if (!is_monsters(f)) {
@ -1119,7 +1121,7 @@ parse_restart(void)
}
/* Clear away debris of destroyed factions */
puts(" - beseitige leere Einheiten und leere Parteien...");
if (verbosity>=1) puts(" - beseitige leere Einheiten und leere Parteien...");
remove_empty_units();
}
/* ------------------------------------------------------------- */
@ -3573,9 +3575,9 @@ process(void)
region *r;
processor *pglobal = proc;
printf("- Step %u\n", prio);
if (verbosity>=3) printf("- Step %u\n", prio);
while (proc && proc->priority==prio) {
if (proc->name) log_stdio(stdout, " - %s\n", proc->name);
if (proc->name && verbosity>=1) log_stdio(stdout, " - %s\n", proc->name);
proc = proc->next;
}
@ -3652,7 +3654,7 @@ process(void)
}
}
if (quiet<2) printf("\n - Leere Gruppen loeschen...\n");
if (verbosity>=3) printf("\n - Leere Gruppen loeschen...\n");
for (f=factions; f; f=f->next) {
group ** gp = &f->groups;
while (*gp) {
@ -3882,7 +3884,7 @@ processorders (void)
process();
/*************************************************/
puts(" - Attribute altern");
if (verbosity>=1) puts(" - Attribute altern");
ageing();
remove_empty_units();

View File

@ -1081,7 +1081,7 @@ spawn_dragons(void)
fset(u, UFL_ISNEW|UFL_MOVED);
equip_unit(u, get_equipment("monster_dragon"));
if (!quiet) {
if (verbosity>=2) {
log_printf("%d %s in %s.\n", u->number,
LOC(default_locale, rc_name(u->race, u->number!=1)), regionname(r, NULL));
}
@ -1147,7 +1147,7 @@ spawn_undead(void)
deathcounts(r, -undead);
name_unit(u);
if (!quiet) {
if (verbosity>=2) {
log_printf("%d %s in %s.\n", u->number,
LOC(default_locale, rc_name(u->race, u->number!=1)), regionname(r, NULL));
}

View File

@ -1077,7 +1077,7 @@ demon_skillchanges(void)
while (weeks--) learn_skill(u, sv->id, 1.0);
}
if (sv->old>sv->level) {
if (!quiet) {
if (verbosity>=3) {
log_printf("%s dropped from %u to %u:%u in %s\n",
unitname(u), sv->old, sv->level, sv->weeks, skillname(sv->id, NULL));
}

View File

@ -97,7 +97,7 @@
#include <sys/stat.h>
#endif
extern int quiet;
extern int verbosity;
extern int *storms;
extern int weeks_per_month;
extern int months_per_year;

View File

@ -580,7 +580,7 @@ count_skill(faction * f, skill_t sk)
return n;
}
int quiet = 0;
int verbosity = 0;
FILE *debug;
@ -675,7 +675,7 @@ verify_data(void)
unit *u;
int mage, alchemist;
puts(" - Überprüfe Daten auf Korrektheit...");
if (verbosity>=1) puts(" - Überprüfe Daten auf Korrektheit...");
list_foreach(faction, factions, f) {
mage = 0;
@ -2260,7 +2260,7 @@ remove_empty_factions(boolean writedropouts)
if ((f->units==NULL || f->alive == 0) && !is_monsters(f)) {
ursprung * ur = f->ursprung;
while (ur && ur->id!=0) ur=ur->next;
if (!quiet) log_stdio(stdout, "\t%s\n", factionname(f));
if (verbosity>=2) log_stdio(stdout, "\t%s\n", factionname(f));
/* Einfach in eine Datei schreiben und später vermailen */

View File

@ -143,7 +143,7 @@ typedef struct strlist {
#define freset(u, i) ((u)->flags &= ~(i))
extern int turn;
extern int quiet;
extern int verbosity;
/* parteinummern */
extern boolean faction_id_is_unused(int);

View File

@ -380,7 +380,7 @@ readorders(const char *filename)
if (filename) F = cfopen(filename, "rb");
if (F==NULL) return 0;
puts(" - lese Befehlsdatei...\n");
if (verbosity>=1) puts(" - lese Befehlsdatei...\n");
/* TODO: recognize UTF8 BOM */
b = getbuf(F, enc_gamedata);

View File

@ -44,7 +44,7 @@
void
init_triggers(void)
{
if (quiet<2) printf("- registering triggers\n");
if (verbosity>=2) printf("- registering triggers\n");
tt_register(&tt_changefaction);
tt_register(&tt_changerace);
tt_register(&tt_createcurse);

View File

@ -66,7 +66,7 @@
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="libxml2.lib pdcurses.lib lua5.1_d.lib tolua.lib luabind_d.lib"
AdditionalDependencies="libxml2.lib pdcurses.lib lua5.1_d.lib tolua++.lib luabind_d.lib"
OutputFile="$(OutDir)\eressea.exe"
LinkIncremental="2"
GenerateDebugInformation="true"

View File

@ -495,7 +495,7 @@ read_args(int argc, char **argv, lua_State * luaState)
turn = atoi(argv[++i]);
break;
case 'q':
quiet = 1;
verbosity = 0;
break;
case 'v':
if (i<argc) {
@ -582,7 +582,7 @@ load_inifile(const char * filename)
str = iniparser_getstring(d, "common:encoding", NULL);
if (str) enc_gamedata = xmlParseCharEncoding(str);
quiet = iniparser_getint(d, "eressea:verbose", 0)?0:1;
verbosity = iniparser_getint(d, "eressea:verbose", 2);
battledebug = iniparser_getint(d, "eressea:debug", battledebug)?1:0;
luafile = iniparser_getstring(d, "eressea:run", luafile);
@ -608,9 +608,6 @@ main(int argc, char *argv[])
sqlpatch = true;
log_open("eressea.log");
printf("\n%s PBEM host\n"
"Copyright (C) 1996-2005 C. Schlittchen, K. Zedel, E. Rehling, H. Peters.\n\n"
"Compilation: " __DATE__ " at " __TIME__ "\nVersion: %f\n\n", global.gamename, version());
lc_ctype = setlocale(LC_CTYPE, "");
lc_numeric = setlocale(LC_NUMERIC, "C");
@ -621,6 +618,11 @@ main(int argc, char *argv[])
lua_State * luaState = lua_init();
global.vm_state = luaState;
load_inifile("eressea.ini");
if (verbosity>=4) {
printf("\n%s PBEM host\n"
"Copyright (C) 1996-2005 C. Schlittchen, K. Zedel, E. Rehling, H. Peters.\n\n"
"Compilation: " __DATE__ " at " __TIME__ "\nVersion: %f\n\n", global.gamename, version());
}
if ((i=read_args(argc, argv, luaState))!=0) return i;
#ifdef CRTDBG

View File

@ -19,7 +19,7 @@ without prior permission by the authors of Eressea.
#include <kernel/region.h>
#include <lua.h>
#include <tolua.h>
#include <tolua++.h>
int tolua_buildinglist_next(lua_State *tolua_S)
{

View File

@ -25,7 +25,7 @@ without prior permission by the authors of Eressea.
#include <util/language.h>
#include <lua.h>
#include <tolua.h>
#include <tolua++.h>
int tolua_factionlist_next(lua_State *tolua_S)
@ -426,34 +426,12 @@ tolua_faction_open(lua_State* tolua_S)
#ifdef TODO
def("faction_origin", &faction_getorigin, pure_out_value(_2) + pure_out_value(_3)),
// heroes
.def("heroes", &faction_countheroes)
.def("max_heroes", &faction_maxheroes)
.def_readonly("name", &faction::name)
.def_readonly("score", &faction::score)
.def_readonly("id", &faction::no)
.def_readwrite("age", &faction::age)
.def_readwrite("options", &faction::options)
.def_readwrite("flags", &faction::flags)
.def_readwrite("subscription", &faction::subscription)
.def_readwrite("lastturn", &faction::lastorders)
.def("add_item", &faction_additem)
.property("items", &faction_items, return_stl_iterator)
.property("x", &faction_getorigin_x, &faction_setorigin_x)
.property("y", &faction_getorigin_y, &faction_setorigin_y)
.def("renum", &faction_renumber)
.def("add_notice", &faction_addnotice)
.property("password", &faction_get_passw, &faction_set_passw)
.property("info", &faction_get_banner, &faction_set_banner)
.property("email", &faction_get_email, &faction_set_email)
.property("locale", &faction_getlocale, &faction_setlocale)
.property("units", &faction_units, return_stl_iterator)
.property("alliance", &faction_getalliance, &faction_setalliance)
.property("race", &faction_getrace, &faction_setrace)
.property("objects", &eressea::get_objects<faction>)
#endif
tolua_variable(tolua_S, "objects", tolua_faction_get_objects, NULL);
}

View File

@ -7,7 +7,7 @@
#include <kernel/region.h>
#include <lua.h>
#include <tolua.h>
#include <tolua++.h>
static int
tolua_run_mapper(lua_State* tolua_S)

View File

@ -24,7 +24,7 @@ without prior permission by the authors of Eressea.
#include <util/attrib.h>
#include <lua.h>
#include <tolua.h>
#include <tolua++.h>
#include <assert.h>

View File

@ -13,7 +13,7 @@
// lua includes
#include <lua.h>
#include <tolua.h>
#include <tolua++.h>
#define E_OK 0
#define E_INVALID_MESSAGE 1
@ -257,6 +257,21 @@ tolua_msg_set_region(lua_State * tolua_S)
return 1;
}
static int
tolua_msg_set(lua_State * tolua_S)
{
tolua_Error err;
if (tolua_isnumber(tolua_S, 3, 0, &err)) {
return tolua_msg_set_int(tolua_S);
} else if (tolua_isusertype(tolua_S, 3, "region", 0, &err)) {
return tolua_msg_set_region(tolua_S);
} else if (tolua_isusertype(tolua_S, 3, "unit", 0, &err)) {
return tolua_msg_set_unit(tolua_S);
}
tolua_pushnumber(tolua_S, (lua_Number)-1);
return 1;
}
static int
tolua_msg_send_region(lua_State * tolua_S)
{
@ -291,6 +306,7 @@ tolua_message_open(lua_State* tolua_S)
tolua_cclass(tolua_S, "message", "message", "", NULL);
tolua_beginmodule(tolua_S, "message");
{
tolua_function(tolua_S, "set", tolua_msg_set);
tolua_function(tolua_S, "set_unit", tolua_msg_set_unit);
tolua_function(tolua_S, "set_region", tolua_msg_set_region);
tolua_function(tolua_S, "set_resource", tolua_msg_set_resource);
@ -300,7 +316,6 @@ tolua_message_open(lua_State* tolua_S)
tolua_function(tolua_S, "send_region", tolua_msg_send_region);
tolua_function(tolua_S, "create", tolua_msg_create);
// tolua_function(tolua_S, "destroy", tolua_msg_destroy);
}
tolua_endmodule(tolua_S);
}

View File

@ -32,7 +32,7 @@ without prior permission by the authors of Eressea.
#include <util/language.h>
#include <lua.h>
#include <tolua.h>
#include <tolua++.h>
int tolua_regionlist_next(lua_State *tolua_S)
{

View File

@ -22,7 +22,7 @@ without prior permission by the authors of Eressea.
#include <util/language.h>
#include <lua.h>
#include <tolua.h>
#include <tolua++.h>
int tolua_shiplist_next(lua_State *tolua_S)
{

View File

@ -44,7 +44,7 @@ without prior permission by the authors of Eressea.
#include <util/log.h>
#include <lua.h>
#include <tolua.h>
#include <tolua++.h>
#include <limits.h>
@ -377,12 +377,14 @@ fctr_handle(struct trigger * tp, void * data)
unit * u = fd->target;
evt.args = (event_arg*)data;
lua_rawgeti(L, LUA_REGISTRYINDEX, fd->fhandle);
tolua_pushusertype(L, u, "unit");
tolua_pushusertype(L, &evt, "event");
if (lua_pcall(L, 2, 0, 0)!=0) {
const char* error = lua_tostring(L, -1);
log_error(("event (%s): %s", unitname(u), error));
log_error(("event (%s): %s\n", unitname(u), error));
lua_pop(L, 1);
tolua_error(L, "event handler call failed", NULL);
}
return 0;
@ -840,6 +842,40 @@ tolua_unit_tostring(lua_State *tolua_S)
return 1;
}
static int
tolua_event_gettype(lua_State *tolua_S)
{
event * self = (event *)tolua_tousertype(tolua_S, 1, 0);
int index = (int)tolua_tonumber(tolua_S, 2, 0);
lua_pushstring(tolua_S, self->args[index].type);
return 1;
}
static int
tolua_event_get(lua_State *tolua_S)
{
struct event * self = (struct event *)tolua_tousertype(tolua_S, 1, 0);
int index = (int)tolua_tonumber(tolua_S, 2, 0);
event_arg * arg = self->args+index;
if (arg->type) {
if (strcmp(arg->type, "string")==0) {
tolua_pushstring(tolua_S, (const char *)arg->data.v);
} else if (strcmp(arg->type, "int")==0) {
tolua_pushnumber(tolua_S, (lua_Number)arg->data.i);
} else if (strcmp(arg->type, "float")==0) {
tolua_pushnumber(tolua_S, (lua_Number)arg->data.f);
} else {
/* this is pretty lazy */
tolua_pushusertype(tolua_S, (void*)arg->data.v, arg->type);
}
return 1;
}
tolua_error(tolua_S, "invalid type argument for event", NULL);
return 0;
}
void
tolua_unit_open(lua_State * tolua_S)
{
@ -850,6 +886,14 @@ tolua_unit_open(lua_State * tolua_S)
tolua_module(tolua_S, NULL, 0);
tolua_beginmodule(tolua_S, NULL);
{
tolua_cclass(tolua_S, "event", "event", "", NULL);
tolua_beginmodule(tolua_S, "event");
{
tolua_function(tolua_S, "get_type", tolua_event_gettype);
tolua_function(tolua_S, "get", tolua_event_get);
}
tolua_endmodule(tolua_S);
tolua_cclass(tolua_S, "unit", "unit", "", NULL);
tolua_beginmodule(tolua_S, "unit");
{

View File

@ -53,7 +53,7 @@ without prior permission by the authors of Eressea.
#include <util/rand.h>
#include <util/rng.h>
#include <tolua.h>
#include <tolua++.h>
#include <lua.h>
#include <time.h>
@ -172,7 +172,8 @@ tolua_message_unit(lua_State* tolua_S)
unit * sender = (unit *)tolua_tousertype(tolua_S, 1, 0);
unit * target = (unit *)tolua_tousertype(tolua_S, 2, 0);
const char * str = tolua_tostring(tolua_S, 3, 0);
if (!target) tolua_error(tolua_S, "target is nil", NULL);
if (!sender) tolua_error(tolua_S, "sender is nil", NULL);
deliverMail(target->faction, sender->region, sender, str, target);
return 0;
}
@ -183,6 +184,8 @@ tolua_message_faction(lua_State * tolua_S)
unit * sender = (unit *)tolua_tousertype(tolua_S, 1, 0);
faction * target = (faction *)tolua_tousertype(tolua_S, 2, 0);
const char * str = tolua_tostring(tolua_S, 3, 0);
if (!target) tolua_error(tolua_S, "target is nil", NULL);
if (!sender) tolua_error(tolua_S, "sender is nil", NULL);
deliverMail(target, sender->region, sender, str, NULL);
return 0;
@ -194,6 +197,7 @@ tolua_message_region(lua_State * tolua_S)
unit * sender = (unit *)tolua_tousertype(tolua_S, 1, 0);
const char * str = tolua_tostring(tolua_S, 2, 0);
if (!sender) tolua_error(tolua_S, "sender is nil", NULL);
ADDMSG(&sender->region->msgs, msg_message("mail_result", "unit message", sender, str));
return 0;
@ -220,6 +224,7 @@ call_script(lua_State * L, struct unit * u)
const attrib * a = a_findc(u->attribs, &at_script);
if (a==NULL) a = a_findc(u->race->attribs, &at_script);
if (a!=NULL && a->data.i>0) {
lua_rawgeti(L, LUA_REGISTRYINDEX, a->data.i);
if (lua_pcall(L, 1, 0, 0)!=0) {
const char* error = lua_tostring(L, -1);
log_error(("call_script (%s): %s", unitname(u), error));

View File

@ -28,7 +28,7 @@ without prior permission by the authors of Eressea.
#include <kernel/region.h>
#include <lua.h>
#include <tolua.h>
#include <tolua++.h>
#include <assert.h>

View File

@ -46,7 +46,7 @@ function mktunnel()
local from = gmtool.get_cursor()
local to = gmtool.get_selection()()
if to~=nil then
terraform(from.x, from.y, "glacier")
region.create(from.x, from.y, "glacier")
create_tunnel(from, to)
gmtool.select(to, 0)
gmtool.highlight(to, 1)
@ -67,12 +67,12 @@ function mkanchors()
end
end
-- terraform and prepare all hell-regions to become wonky gates
-- region.create and prepare all hell-regions to become wonky gates
function mkgates()
for r in regions() do
if r.plane_id==0 and r.terrain=="hell" then
create_tunnel(r, "tnnL")
terraform(r.x, r.y, "glacier")
region.create(r.x, r.y, "glacier")
end
end
end

View File

@ -23,7 +23,7 @@ local function get_target(param)
r:set_flag(0, false)
end
if (r.terrain=="ocean") then
r = terraform(r.x, r.y, "plain")
r = region.create(r.x, r.y, "plain")
end
targets[ntargets] = r
ntargets = ntargets + 1

View File

@ -51,7 +51,7 @@ function test_free()
end
function test_reorder()
r = terraform(0, 0, "plain")
r = region.create(0, 0, "plain")
f = faction.create("enno@ix.de", "orc", "de")
s1 = add_ship(r, "boat")
s1.size = 1
@ -65,45 +65,45 @@ function test_reorder()
b2.size = 2
b3 = add_building(r, "portal")
b3.size = 3
u = add_unit(f, r)
u = unit.create(f, r)
u.number = 1
u.name = "a"
u = add_unit(f, r)
u = unit.create(f, r)
u.number = 1
u.name = "b"
u.ship = s3
u = add_unit(f, r)
u = unit.create(f, r)
u.number = 1
u.name = "c"
u.building = b1
u = add_unit(f, r)
u = unit.create(f, r)
u.number = 1
u.name = "d"
u.ship = s2
u = add_unit(f, r)
u = unit.create(f, r)
u.name = "e"
u.number = 1
u.building = b1
u = add_unit(f, r)
u = unit.create(f, r)
u.name = "f"
u.number = 1
u.building = b3
u = add_unit(f, r)
u = unit.create(f, r)
u.name = "g"
u.number = 1
u.ship = s2
u = add_unit(f, r)
u = unit.create(f, r)
u.name = "h"
u.number = 1
u.building = b2
u = add_unit(f, r)
u = unit.create(f, r)
u.name = "i"
u.number = 1
u = add_unit(f, r)
u = unit.create(f, r)
u.name = "j"
u.number = 1
u.building = b1
u = add_unit(f, r)
u = unit.create(f, r)
u.name = "k"
u.number = 1
u.ship = s1
@ -205,10 +205,10 @@ function action(b, param)
end
function test_tunnels()
r = terraform(0, 0, "glacier")
r = region.create(0, 0, "glacier")
b = add_building(r, "portal")
b:add_action("tunnel_action", "tnnL")
r2 = terraform(5, 5, "plain")
r2 = region.create(5, 5, "plain")
r2:set_key("tnnL", true)
process_orders()
end

View File

@ -1,5 +1,5 @@
function mkunit(f, r, num)
u = add_unit(f, r)
u = unit.create(f, r)
u.number = num
u:add_item("money", num*10)
u:clear_orders()
@ -11,16 +11,16 @@ function test_movement()
east = direction("east")
-- im westen ohne strassen
ocean = terraform(-3, 0, "ocean")
w2 = terraform(-2, 0, "plain")
w1 = terraform(-1, 0, "plain")
ocean = region.create(-3, 0, "ocean")
w2 = region.create(-2, 0, "plain")
w1 = region.create(-1, 0, "plain")
-- im osten mit strassen
r0 = terraform(0, 0, "plain")
r1 = terraform(1, 0, "desert")
r2 = terraform(2, 0, "glacier")
r3 = terraform(3, 0, "plain")
r4 = terraform(4, 0, "glacier")
r0 = region.create(0, 0, "plain")
r1 = region.create(1, 0, "desert")
r2 = region.create(2, 0, "glacier")
r3 = region.create(3, 0, "plain")
r4 = region.create(4, 0, "glacier")
r0:add_direction(r4, "Wirbel", "Nimm die Abkürzung, Luke")
@ -110,7 +110,7 @@ function test_movement()
bug:add_order("GIB 0 ALLES Holz")
bug:add_order("FAHREN " .. itoa36(orc.id))
u = add_unit(orcs, r0)
u = unit.create(orcs, r0)
u.number = 1
u:add_item("horse", u.number*3)
u:add_item("money", u.number*10)
@ -122,7 +122,7 @@ function test_movement()
u:add_order("NUMMER EINHEIT foLg")
u:add_order("BENENNE EINHEIT Verfolger")
u2 = add_unit(orcs, r0)
u2 = unit.create(orcs, r0)
u2.number = 1
u2:add_item("horse", u2.number*3)
u2:add_item("money", u.number*10)
@ -137,12 +137,12 @@ end
function test_sail()
r0 = terraform(0, 0, "plain")
r0 = region.create(0, 0, "plain")
orcs = faction.create("enno@eressea.de", "orc", "de")
orcs.age = 20
orc = add_unit(orcs, r0)
orc = unit.create(orcs, r0)
orc.number = 1
orc:add_item("speedsail", orc.number)
@ -166,13 +166,13 @@ function test_handler()
message_region(u, "thanks region, i got your message: " .. str)
end
plain = terraform(0, 0, "plain")
plain = region.create(0, 0, "plain")
skill = 8
f = faction.create("enno@eressea.de", "orc", "de")
f.age = 20
u = add_unit(f, plain)
u = unit.create(f, plain)
u.number = 1
u:add_item("money", u.number*100)
u:clear_orders()
@ -183,7 +183,7 @@ function test_handler()
f = faction.create("enno@eressea.de", "elf", "de")
f.age = 20
u = add_unit(f, plain)
u = unit.create(f, plain)
u.number = 1
u:add_item("money", u.number*100)
u:clear_orders()
@ -194,13 +194,13 @@ end
function test_combat()
plain = terraform(0, 0, "plain")
plain = region.create(0, 0, "plain")
skill = 8
f = faction.create("enno@eressea.de", "orc", "de")
f.age = 20
u = add_unit(f, plain)
u = unit.create(f, plain)
u.number = 100
u:add_item("money", u.number*100)
u:add_item("sword", u.number)
@ -214,7 +214,7 @@ function test_combat()
f = faction.create("enno@eressea.de", "elf", "de")
f.age = 20
u = add_unit(f, plain)
u = unit.create(f, plain)
u.number = 100
u:add_item("money", u.number*100)
u:add_item("sword", u.number)
@ -229,12 +229,12 @@ end
function test_rewards()
-- this script tests manufacturing and fighting.
plain = terraform(0, 0, "plain")
plain = region.create(0, 0, "plain")
skill = 5
f = faction.create("enno@eressea.de", "human", "de")
f.age = 20
u = add_unit(f, plain)
u = unit.create(f, plain)
u.number = 10
u:add_item("money", u.number*100)
u:add_item("greatbow", u.number)
@ -243,7 +243,7 @@ function test_rewards()
u:add_order("KAEMPFE")
attack = "ATTACKIERE " .. itoa36(u.id)
u = add_unit(f, plain)
u = unit.create(f, plain)
u.number = 7
u:add_item("money", u.number*100)
u:add_item("mallorn", u.number*10)
@ -255,7 +255,7 @@ function test_rewards()
f = faction.create("enno@eressea.de", "elf", "de")
f.age = 20
u = add_unit(f, plain)
u = unit.create(f, plain)
u.number = 7
u:add_item("money", u.number*100)
u:add_item("greatbow", u.number)
@ -264,7 +264,7 @@ function test_rewards()
u:add_order("KAEMPFE HINTEN")
u:add_order(attack)
u = add_unit(f, plain)
u = unit.create(f, plain)
u.number = 7
u:add_item("money", u.number*100)
u:add_item("mallorn", u.number*10)
@ -274,7 +274,7 @@ function test_rewards()
u:add_order("MACHEN Elfenbogen")
u:add_order("NUMMER PARTEI eviL")
u = add_unit(f, plain)
u = unit.create(f, plain)
u.number = 7
u:add_item("money", u.number*100)
u:add_item("mallorn", u.number*10)
@ -296,10 +296,10 @@ function test_rewards()
end
function test_give()
plain = terraform(0, 0, "plain")
plain = region.create(0, 0, "plain")
f = faction.create("enno@eressea.de", "human", "de")
f.age = 20
u = add_unit(f, plain)
u = unit.create(f, plain)
u.number = 10
u:add_item("money", u.number*100)
u:clear_orders()
@ -342,12 +342,12 @@ end
function test_parser()
-- this script tests the changes to quotes
plain = terraform(0, 0, "plain")
plain = region.create(0, 0, "plain")
skill = 5
f = faction.create("enno@eressea.de", "human", "de")
f.age = 20
u = add_unit(f, plain)
u = unit.create(f, plain)
u.number = 10
u:clear_orders()
u:add_order("Nummer Partei test")
@ -356,7 +356,7 @@ function test_parser()
end
function test_fail()
plain = terraform(0, 0, "plain")
plain = region.create(0, 0, "plain")
skill = 5
f = faction.create("enno@eressea.de", "human", "de")

View File

@ -179,6 +179,45 @@ local function test_hashtable()
assert(f.objects:get("age") == nil)
end
function test_events()
local fail = 1
local function msg_handler(u, evt)
str = evt:get(0)
u2 = evt:get(1)
assert(u2~=nil)
print(str=="Du Elf stinken")
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)
fail = 0
end
plain = region.create(0, 0, "plain")
skill = 8
f = faction.create("enno@eressea.de", "orc", "de")
f.age = 20
u = unit.create(f, plain)
u.number = 1
u:add_item("money", u.number*100)
u:clear_orders()
u:add_order("NUMMER PARTEI test")
u:add_handler("message", msg_handler)
msg = "BOTSCHAFT EINHEIT " .. itoa36(u.id) .. " Du~Elf~stinken"
f = faction.create("enno@eressea.de", "elf", "de")
f.age = 20
u = unit.create(f, plain)
u.number = 1
u:add_item("money", u.number*100)
u:clear_orders()
u:add_order("NUMMER PARTEI eviL")
u:add_order(msg)
process_orders()
assert(fail==0)
end
loadscript("extensions.lua")
tests = {
["test_pure"] = test_pure,
@ -189,7 +228,8 @@ tests = {
["test_unit"] = test_unit,
["test_message"] = test_message,
["test_hashtable"] = test_hashtable,
["test_gmtool"] = test_gmtool
["test_gmtool"] = test_gmtool,
["test_events"] = test_events
}
fail = 0

View File

@ -62,7 +62,7 @@ function make_faction(position, alliance, number, email, race)
print("\n" .. email .. " (" .. itoa36(f.id) .. ")")
f.alliance = alliance
local u = add_unit(f, position)
local u = unit.create(f, position)
-- erster ist der, der die extras kriegt:
u.number = 1
local units = units - 1
@ -79,7 +79,7 @@ function make_faction(position, alliance, number, email, race)
local sk
local skill
for sk, skill in pairs(skills) do
u = add_unit(f, position)
u = unit.create(f, position)
-- anzahl personen berechnen
local number = math.floor(units / skillno)

View File

@ -93,8 +93,8 @@ function sphinx_handler()
for r in regions() do
m:send_region(r)
end
-- Region terraformen
terraform(u2.region.x, u.region.y, "plain")
-- Region region.createen
region.create(u2.region.x, u.region.y, "plain")
u2.region.set_resource(u2.region, "tree", 721)
u2.region.set_resource(u2.region, "peasant", 2312)
u2.add_item(u2, "trappedairelemental", 5)