WDW Änderungen vom Wochenende.

- besseres Error-handling in eventhandlern
- bugfix get_variable

Scriptänderungen Sphinx
! bedarf noch eines Cleanup
This commit is contained in:
Christian Schlittchen 2004-08-18 22:24:48 +00:00
parent 9f8c55b492
commit 8ee6431125
5 changed files with 138 additions and 15 deletions

View File

@ -71,8 +71,8 @@ get_variable(attrib *a, const char *key)
{ {
attrib *ap; attrib *ap;
for(ap = a; ap; ap=ap->nexttype) { for(ap = a_find(a, &at_variable); ap; ap=ap->nexttype) {
if(strcmp(key, ((variable *)ap->data.v)->key)) { if(strcmp(key, ((variable *)ap->data.v)->key) == 0) {
break; break;
} }
} }
@ -91,8 +91,8 @@ set_variable(attrib **app, const char *key, const char *value)
assert(value); assert(value);
for(ap = *app; ap; ap=ap->nexttype) { for(ap = a_find(*app, &at_variable); ap; ap=ap->nexttype) {
if(strcmp(key, ((variable *)ap->data.v)->key)) { if(strcmp(key, ((variable *)ap->data.v)->key) == 0) {
break; break;
} }
} }
@ -112,8 +112,8 @@ delete_variable(attrib **app, const char *key)
{ {
attrib *ap; attrib *ap;
for(ap = *app; ap; ap=ap->nexttype) { for(ap = a_find(*app, &at_variable); ap; ap=ap->nexttype) {
if(strcmp(key, ((variable *)ap->data.v)->key)) { if(strcmp(key, ((variable *)ap->data.v)->key) == 0) {
break; break;
} }
} }

View File

@ -406,7 +406,9 @@ const char *keywords[MAXKEYWORDS] =
"WERWESEN", "WERWESEN",
"XONTORMIA", "XONTORMIA",
"ALLIANZ", "ALLIANZ",
#ifdef HEROES
"PROMOTION" "PROMOTION"
#endif
}; };
const char *report_options[MAX_MSG] = const char *report_options[MAX_MSG] =

View File

@ -412,12 +412,25 @@ typedef struct fctr_data {
luabind::functor<void> * fptr; luabind::functor<void> * fptr;
} fctr_data; } fctr_data;
static int #include <exception>
fctr_handle(trigger * t, void * data)
int __cdecl
fctr_handle(struct trigger * tp, void * data)
{ {
trigger * t = tp;
event * evt = new event(NULL, (event_arg*)data); event * evt = new event(NULL, (event_arg*)data);
fctr_data * fd = (fctr_data*)t->data.v; fctr_data * fd = (fctr_data*)t->data.v;
try {
fd->fptr->operator()(fd->target, evt); fd->fptr->operator()(fd->target, evt);
}
catch (luabind::error& e) {
lua_State* L = e.state();
const char* error = lua_tostring(L, -1);
log_error((error));
lua_pop(L, 1);
std::terminate();
}
delete evt; delete evt;
return 0; return 0;
} }

View File

@ -16,7 +16,6 @@ function init_sphinxhints()
end end
end end
end end
end end
init_sphinxhints() init_sphinxhints()

View File

@ -1,3 +1,107 @@
function init_sphinxhints()
for f in factions() do
hints = {}
for i=0,14,1 do
hints[i] = 0
end
for i=0,4,1 do
if f:get_variable("sphinxhint"..tostring(i)) == nil then
repeat
hint = math.random(0,14)
until hints[hint] == 0
hints[hint] = 1
f:set_variable("sphinxhint"..tostring(i),tostring(hint))
end
end
end
end
function sphinx_handler()
local function send_gotHint(u, usphinx)
usphinx:add_order("botschaft einheit " .. itoa36(u.id) .. " \"Du hast diese Woche bereits einen Hinweis erhalten!\"")
end
local function send_hint(u, usphinx)
hintText = {}
possibleHint = {}
hintText[0] = "Das Schiff des Elfen hat ein rotes Segel"
hintText[1] = "Der Zwerg hat eine Nuss dabei"
hintText[2] = "Die Katze führt eine Hellebarde"
hintText[3] = "Das Schiff mit dem grünen Segel liegt links neben dem mit einem weissen Segel"
hintText[4] = "Auf dem Schiff mit grünen Segeln kam der Speerkämpfer"
hintText[5] = "Der Krieger mit dem Kreis im Wappen hat einen Keks"
hintText[6] = "Der Krieger des mittleren Schiffs hat ein Schwert"
hintText[7] = "Auf dem gelben Segel prankt ein Kreuz als Wappen"
hintText[8] = "Der Mensch kam mit dem ersten Schiff"
hintText[9] = "Das Schiff mit dem Stern im Wappen liegt neben dem der einen Mandelkern hat"
hintText[10] = "Das Schiff des Kriegers, der ein Apfel hat, liegt neben dem, der ein Kreuz als Wappen hat"
hintText[11] = "Der Krieger mit dem Turm im Wappen trägt eine Axt"
hintText[12] = "Das Schiff des Menschen liegt neben dem blauen Schiff"
hintText[13] = "Das Insekt trägt einen Baum als Wappen"
hintText[14] = "Das Schiff mit dem Stern im Wappen liegt neben dem des Kriegers, der einen Zweihänder führt"
for i=0,4,1 do
possibleHint[i] = tonumber(u.faction:get_variable("sphinxhint"..tostring(i)))
end
hint = math.random(0,4)
usphinx:add_order("botschaft einheit " .. itoa36(u.id) .. " \"" .. hintText[possibleHint[hint]] .. "!\"")
end
local function msg_handler(u, evt)
str = evt:get_string(0)
u2 = evt:get_unit(1)
if string.lower(str) == "hinweis" then
if u2.faction:get_variable("sphinxGotHint"..itoa36(u.id)) ~= nil then
send_gotHint(u2)
else
send_hint(u2, u)
end
end
end
local f = get_faction(atoi36("ycx9"))
local u = get_unit(atoi36("si7z"))
if u ~= nil and u.faction == f then
u:add_handler("message", msg_handler)
end
local f = get_faction(atoi36("ycx9"))
local u = get_unit(atoi36("qcph"))
if u ~= nil and u.faction == f then
u:add_handler("message", msg_handler)
end
end
function sphinx_weekly()
local f = get_faction(atoi36("ycx9"))
local u = get_unit(atoi36("si7z"))
if u ~= nil and u.faction == f then
u.region:add_notice("Eine Botschaft von Sphinx (si7z): Mit einer Botschaft \"Hinweis\" gebe ich euch einen Hinweis, mit einer Botschaft \"Antwort <Eure Antwort>\" könnt ihr mir eure Antwort mitteilen. Doch Vorsicht, falsche Antworten werde ich bestrafen!")
u.region:add_notice("Eine Botschaft von Sphinx (si7z): Fünf Krieger kamen auf ihren Schiffen in die Ebene der Helden, wollten um die Ehre ringen. Jedes Schiff trug ein anderes Segel, auf dem das Wappen des Kriegers prankte. Ein jeder trug seine liebste Waffe und das Signum seines Volkes und doch war keiner gleich.")
u.region:add_notice("Eine Botschaft von Sphinx (si7z): Wer hat den Schneeball?")
end
local u = get_unit(atoi36("qcph"))
if u ~= nil and u.faction == f then
u.region:add_notice("Eine Botschaft von Sphinx (qcph): Mit einer Botschaft \"Hinweis\" gebe ich euch einen Hinweis, mit einer Botschaft \"Antwort <Eure Antwort>\" könnt ihr mir eure Antwort mitteilen. Doch Vorsicht, falsche Antworten werde ich bestrafen!")
u.region:add_notice("Eine Botschaft von Sphinx (qcph): Fünf Krieger kamen auf ihren Schiffen in die Ebene der Helden, wollten um die Ehre ringen. Jedes Schiff trug ein anderes Segel, auf dem das Wappen des Kriegers prankte. Ein jeder trug seine liebste Waffe und das Signum seines Volkes und doch war keiner gleich.")
u.region:add_notice("Eine Botschaft von Sphinx (qcph): Wer hat den Schneeball?")
end
for faction in factions() do
faction:delete_variable("sphinxGotHintsi7z");
faction:delete_variable("sphinx2GotHintqcph");
end
end
function run_wdw() function run_wdw()
local turnfile = "" .. get_turn() local turnfile = "" .. get_turn()
if read_game(turnfile)~=0 then if read_game(turnfile)~=0 then
@ -7,8 +111,11 @@ function run_wdw()
-- run the turn (not yet) -- run the turn (not yet)
read_orders(orderfile) read_orders(orderfile)
sphinx_initfactions() print("init_sphinxhints")
init_sphinxhints()
print("sphinx_weekly")
sphinx_weekly() sphinx_weekly()
sphinx_handler()
plan_monsters() plan_monsters()
process_orders() process_orders()
outfile = "" .. get_turn() outfile = "" .. get_turn()
@ -28,17 +135,19 @@ function run_wdw()
end end
end end
print("- Running wdw-run.lua")
scripts = { scripts = {
"spinx-initfactions.lua",
"sphinx-announce.lua"
} }
scriptpath = "/home/vinyambar/wdw/scripts/" scriptpath = "/home/vinyambar/wdw-test/scripts/"
for index in scripts do for index in scripts do
local script = scriptpath .. scripts[index] local script = scriptpath .. scripts[index]
print("- running " .. script)
if pcall(dofile, script)==0 then if pcall(dofile, script)==0 then
print("Could not load " .. script) print("error: could not load " .. script)
end end
end end