From b46efa76d4db246c0fcd8c11a7ac46610199d568 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 24 Jun 2004 16:48:47 +0000 Subject: [PATCH] - Monster-Skripting in Lua (fertig, fehler gefunden) - Beispielskripte --- src/eressea/lua/script.cpp | 2 +- src/scripts/samples.lua | 150 +++++++++++++++++++++++++++++++++++++ 2 files changed, 151 insertions(+), 1 deletion(-) create mode 100644 src/scripts/samples.lua diff --git a/src/eressea/lua/script.cpp b/src/eressea/lua/script.cpp index 0ec9eea26..a82725f75 100644 --- a/src/eressea/lua/script.cpp +++ b/src/eressea/lua/script.cpp @@ -45,7 +45,7 @@ call_script(struct unit * u) if (a==NULL) a = a_findc(u->race->attribs, &at_script); if (a!=NULL && a->data.v!=NULL) { luabind::functor * func = (luabind::functor *)a->data.v; - func->operator()(*u); + func->operator()(u); } return -1; } diff --git a/src/scripts/samples.lua b/src/scripts/samples.lua new file mode 100644 index 000000000..493a87c71 --- /dev/null +++ b/src/scripts/samples.lua @@ -0,0 +1,150 @@ +function test_combat() + + plain = terraform(0, 0, "plain") + skill = 8 + + f = add_faction("enno@eressea.de", "orc", "de") + f.age = 20 + + u = add_unit(f, plain) + u.number = 100 + u:add_item("money", u.number*100) + u:add_item("sword", u.number) + u:set_skill("sk_melee", skill) + u:clear_orders() + u:add_order("NUMMER PARTEI test") + u:add_order("KÄMPFE") + u:add_order("BEFÖRDERUNG") + attack = "ATTACKIERE " .. itoa36(u.id) + + f = add_faction("enno@eressea.de", "elf", "de") + f.age = 20 + + u = add_unit(f, plain) + u.number = 100 + u:add_item("money", u.number*100) + u:add_item("sword", u.number) + u:set_skill("sk_melee", skill+2) + u:clear_orders() + u:add_order("NUMMER PARTEI eviL") + u:add_order("KAEMPFE") + u:add_order(attack) + + process_orders() + write_reports() +end + +function test_rewards() + -- this script tests manufacturing and fighting. + + plain = terraform(0, 0, "plain") + skill = 5 + + f = add_faction("enno@eressea.de", "human", "de") + f.age = 20 + u = add_unit(f, plain) + u.number = 10 + u:add_item("money", u.number*100) + u:add_item("greatbow", u.number) + u:set_skill("sk_bow", skill) + u:clear_orders() + u:add_order("KAEMPFE") + attack = "ATTACKIERE " .. itoa36(u.id) + + u = add_unit(f, plain) + u.number = 7 + u:add_item("money", u.number*100) + u:add_item("mallorn", u.number*10) + u:set_skill("sk_weaponsmithing", 7) + u:clear_orders() + u:add_order("KAEMPFE NICHT") + u:add_order("MACHEN Elfenbogen") + u:add_order("NUMMER PARTEI test") + + f = add_faction("enno@eressea.de", "elf", "de") + f.age = 20 + u = add_unit(f, plain) + u.number = 7 + u:add_item("money", u.number*100) + u:add_item("greatbow", u.number) + u:set_skill("sk_bow", skill) + u:clear_orders() + u:add_order("KAEMPFE HINTEN") + u:add_order(attack) + + u = add_unit(f, plain) + u.number = 7 + u:add_item("money", u.number*100) + u:add_item("mallorn", u.number*10) + u:set_skill("sk_weaponsmithing", 7) + u:clear_orders() + u:add_order("KAEMPFE NICHT") + u:add_order("MACHEN Elfenbogen") + u:add_order("NUMMER PARTEI eviL") + + u = add_unit(f, plain) + u.number = 7 + u:add_item("money", u.number*100) + u:add_item("mallorn", u.number*10) + u:set_skill("sk_weaponsmithing", 7) + u:clear_orders() + u:add_order("KAEMPFE NICHT") + + items = { "hornofdancing", "trappedairelemental", + "aurapotion50", "bagpipeoffear", + "instantartacademy", "instantartsculpture" } + for index in items do + u:add_item(items[index], 1) + u:add_order('@BENUTZEN "' .. get_string("de", items[index]) .. '"') + end + u:add_order("NUMMER PARTEI eviL") + + process_orders() + write_reports() +end + +function test_give() + plain = terraform(0, 0, "plain") + f = add_faction("enno@eressea.de", "human", "de") + f.age = 20 + u = add_unit(f, plain) + u.number = 10 + u:add_item("money", u.number*100) + u:clear_orders() + u:add_order("MACHE TEMP eins") + u:add_order("REKRUTIERE 1") + u:add_order("ENDE") + u:add_order("GIB TEMP eins ALLES silber") + u:add_order("NUMMER PARTEI test") + + process_orders() + write_reports() +end + +function test_write() + read_game("24") + read_orders("befehle") + process_orders() + write_reports() + write_game("25") +end + +function move_north(u) + u:clear_orders() + u:add_order("NACH NORDEN") +end + +function test_monsters() + read_game("23") + set_brain("braineater", move_north) + plan_monsters() + process_orders() +end + +test_monsters() +-- test_combat() +-- test_rewards() +-- test_give() +-- test_write() +-- read_game("test") +-- write_game("test")