From 080a9a8bba281f4d4e9482705688cca64403b176 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 22 Dec 2004 00:53:12 +0000 Subject: [PATCH] Weihnachtsevent mit dickem Gnom und Sonnensegeln, jetzt komplett implementiert. Beinhaltet Partei-Inventory und neuen Befehl CLAIM / BEANSPRUCHEN. --- src/common/gamecode/creport.c | 9 +++++++- src/common/gamecode/laws.c | 33 +++++++++++++++++++++++++++ src/common/gamecode/report.c | 20 +++++++++++++++- src/common/kernel/eressea.c | 3 ++- src/common/kernel/eressea.h | 4 +++- src/common/kernel/faction.h | 1 + src/common/kernel/save.c | 9 ++++++++ src/eressea/lua/faction.cpp | 22 ++++++++++++++++++ src/res/de/strings.xml | 22 ++++++++++++++++++ src/scripts/default.lua | 27 ++++++++++++++-------- src/scripts/samples.lua | 43 +++++++++++++++-------------------- src/scripts/xmas2004.lua | 17 ++++++++++++++ 12 files changed, 171 insertions(+), 39 deletions(-) create mode 100644 src/scripts/xmas2004.lua diff --git a/src/common/gamecode/creport.c b/src/common/gamecode/creport.c index 221c8a689..1c092f335 100644 --- a/src/common/gamecode/creport.c +++ b/src/common/gamecode/creport.c @@ -746,6 +746,7 @@ cr_output_unit(FILE * F, const region * r, fputs("1;hero\n", F); } #endif + if (fval(u, UFL_HUNGER) && (u->faction == f)) { fputs("1;hunger\n", F); } @@ -753,7 +754,6 @@ cr_output_unit(FILE * F, const region * r, fprintf(F, "%d;Aura\n", get_spellpoints(u)); fprintf(F, "%d;Auramax\n", max_spellpoints(u->region,u)); } - /* default commands */ fprintf(F, "COMMANDS\n"); if (u->lastorder) { @@ -1085,6 +1085,7 @@ report_computer(FILE * F, faction * f, const faction_list * addresses, const time_t report_time) { int i; + item * itm; const char * prefix; region * r; building *b; @@ -1159,6 +1160,12 @@ report_computer(FILE * F, faction * f, const faction_list * addresses, fprintf(F, "\"%s\";Parteiname\n", f->name); fprintf(F, "\"%s\";email\n", f->email); fprintf(F, "\"%s\";banner\n", f->banner); + for (itm=f->items; itm; itm=itm->next) { + int in = itm->number; + const char * ic = LOC(f->locale, resourcename(itm->type->rtype, in)); + if (itm==f->items) fputs("GEGENSTAENDE\n", F); + fprintf(F, "%d;%s\n", in, add_translation(ic, LOC(f->locale, ic))); + } fputs("OPTIONEN\n", F); for (i=0;i!=MAXOPTIONS;++i) { fprintf(F, "%d;%s\n", (f->options&want(i))?1:0, options[i]); diff --git a/src/common/gamecode/laws.c b/src/common/gamecode/laws.c index 5cf85bd76..d1c893541 100644 --- a/src/common/gamecode/laws.c +++ b/src/common/gamecode/laws.c @@ -3644,6 +3644,38 @@ use_cmd(unit * u, struct order * ord) return 0; } +static int +claim_cmd(unit * u, struct order * ord) +{ + const char * t; + int n; + const item_type * itype; + + init_tokens(ord); + skip_token(); + + t = getstrtoken(); + n = atoi(t); + if (n==0) { + n = 1; + } else { + t = getstrtoken(); + } + itype = finditemtype(t, u->faction->locale); + + if (itype!=NULL) { + item ** iclaim = i_find(&u->faction->items, itype); + if (iclaim!=NULL) { + n = min(n, (*iclaim)->number); + i_change(iclaim, itype, -n); + i_change(&u->items, itype, n); + } + } else { + cmistake(u, ord, 43, MSG_PRODUCE); + } + return 0; +} + void processorders (void) { @@ -3666,6 +3698,7 @@ processorders (void) age_factions(); puts(" - Benutzen"); + parse(K_CLAIM, claim_cmd, false); parse(K_USE, use_cmd, false); puts(" - Kontaktieren, Betreten von Schiffen und Gebäuden (1.Versuch)"); diff --git a/src/common/gamecode/report.c b/src/common/gamecode/report.c index 58d704d0a..49497876f 100644 --- a/src/common/gamecode/report.c +++ b/src/common/gamecode/report.c @@ -2016,7 +2016,7 @@ report(FILE *F, faction * f, const faction_list * addresses, if(dh > 0) centre(F, buf, true); dh = 0; - if(f->karma > 0) { + if (f->karma > 0) { sprintf(buf, "Deine Partei hat %d Karma.", f->karma); centre(F, buf, true); } @@ -2065,6 +2065,24 @@ report(FILE *F, faction * f, const faction_list * addresses, } #endif + if (f->items!=NULL) { + item * iclaim = f->items; + char * edit = buf; + strcpy(edit, LOC(f->locale, "claimable")); + edit += strlen(edit); + while (iclaim!=NULL) { + sprintf(edit, "%d %s", iclaim->number, + LOC(f->locale, resourcename(iclaim->type->rtype, iclaim->number))); + iclaim = iclaim->next; + if (iclaim!=NULL) { + strcat(edit, ", "); + } + edit += strlen(edit); + } + rnl(F); + centre(F, buf, true); + } + if (f->age > 1 && f->lastorders != turn) { rnl(F); if (turn - f->lastorders == 1) { diff --git a/src/common/kernel/eressea.c b/src/common/kernel/eressea.c index 312914649..557c26fed 100644 --- a/src/common/kernel/eressea.c +++ b/src/common/kernel/eressea.c @@ -406,8 +406,9 @@ const char *keywords[MAXKEYWORDS] = "WERWESEN", "XONTORMIA", "ALLIANZ", + "BEANSPRUCHEN", #ifdef HEROES - "PROMOTION" + "PROMOTION", #endif }; diff --git a/src/common/kernel/eressea.h b/src/common/kernel/eressea.h index 7b2912f28..9dd02eb98 100644 --- a/src/common/kernel/eressea.h +++ b/src/common/kernel/eressea.h @@ -160,6 +160,7 @@ struct building_type; #define CURSEVIGOURISFLOAT_VERSION 315 #define SAVEXMLNAME_VERSION 316 #define SAVEALLIANCE_VERSION 317 +#define CLAIM_VERSION 318 #define MIN_VERSION ALLIANCES_VERSION #define REGIONOWNERS_VERSION 400 @@ -168,7 +169,7 @@ struct building_type; #ifdef REGIONOWNERS # define RELEASE_VERSION REGIONOWNERS_VERSION #else -# define RELEASE_VERSION SAVEALLIANCE_VERSION +# define RELEASE_VERSION CLAIM_VERSION #endif #if RESOURCE_CONVERSION @@ -448,6 +449,7 @@ enum { K_WEREWOLF, K_XE, K_ALLIANCE, + K_CLAIM, #ifdef HEROES K_PROMOTION, #endif diff --git a/src/common/kernel/faction.h b/src/common/kernel/faction.h index aa6dc2a35..fada66f40 100644 --- a/src/common/kernel/faction.h +++ b/src/common/kernel/faction.h @@ -97,6 +97,7 @@ typedef struct faction { struct region * r; struct message_list * msgs; } * battles; + struct item * items; /* items this faction can claim */ } faction; typedef struct faction_list { diff --git a/src/common/kernel/save.c b/src/common/kernel/save.c index 06b5f5571..3b7e09314 100644 --- a/src/common/kernel/save.c +++ b/src/common/kernel/save.c @@ -1578,6 +1578,11 @@ readfaction(FILE * F) freset(f, FFL_OVERRIDE); a_read(F, &f->attribs); +#if RELEASE_VERSION>=CLAIM_VERSION + if (global.data_version>=CLAIM_VERSION) { + read_items(F, &f->items); + } +#endif #ifdef MSG_LEVELS read_msglevels(&f->warnings, F); #else @@ -1670,6 +1675,10 @@ writefaction(FILE * F, const faction * f) wi(F, f->flags); a_write(F, f->attribs); wnl(F); + if (global.data_version>=CLAIM_VERSION) { + write_items(F, f->items); + wnl(F); + } #ifdef MSG_LEVELS write_msglevels(f->warnings, F); #else diff --git a/src/eressea/lua/faction.cpp b/src/eressea/lua/faction.cpp index 85d65107f..732a473b7 100644 --- a/src/eressea/lua/faction.cpp +++ b/src/eressea/lua/faction.cpp @@ -5,6 +5,8 @@ // kernel includes #include #include +#include +#include #include // util includes @@ -146,6 +148,24 @@ faction_delete_variable(faction& f, const char *key) return delete_variable(&((&f)->attribs), key); } +static int +faction_additem(faction& f, const char * iname, int number) +{ + const item_type * itype = it_find(iname); + if (itype!=NULL) { + item * i = i_change(&f.items, itype, number); + return i?i->number:0; + } // if (itype!=NULL) + return -1; +} + +static void +faction_addnotice(faction& f, const char * str) +{ + str = LOC(f.locale, str); + ADDMSG(&f.msgs, msg_message("msg_event", "string", str)); +} + void bind_faction(lua_State * L) { @@ -170,6 +190,8 @@ bind_faction(lua_State * L) .def_readwrite("age", &faction::age) .def_readwrite("subscription", &faction::subscription) .def_readwrite("lastturn", &faction::lastorders) + .def("add_item", &faction_additem) + .def("add_notice", &faction_addnotice) .property("locale", &faction_locale) .property("units", &faction_units, return_stl_iterator) .property("alliance", &faction_getalliance, &faction_setalliance) diff --git a/src/res/de/strings.xml b/src/res/de/strings.xml index 146a16243..01ec09e5c 100644 --- a/src/res/de/strings.xml +++ b/src/res/de/strings.xml @@ -1848,6 +1848,10 @@ BIETEN + + BEANSPRUCHEN + CLAIM + BEKLAUEN @@ -6003,4 +6007,22 @@ + + Einheiten können die folgenden Gegenstände beansprucht werden: + Units can claim the following items: + + + + 'Ho ho ho!' Ein dicker Gnom fliegt auf einem von + 8 Jungdrachen gezogenen Schlitten durch die Nacht und vermacht Deiner + Partei ein Sonnensegel. (Um das Segel einer Einheit zu geben, gib + ihr den Befehl 'BEANSPRUCHE 1 Sonnensegel'). + 'Ho ho ho!' A fat little gnome Gnom on a sled + pulled by 8 young dragons flies through the stary night and presents + your faction with a solar sail. (To claim this item, one of your units + must issue the order 'CLAIM 1 solar sail' + Partei ein Sonnensegel. (Um das Segel einer Einheit zu geben, gib + ihr den Befehl 'BEANSPRUCHE 1 Sonnensegel'). + + diff --git a/src/scripts/default.lua b/src/scripts/default.lua index 0ad9e2e44..60cfbdbb9 100644 --- a/src/scripts/default.lua +++ b/src/scripts/default.lua @@ -18,6 +18,19 @@ function write_emails() end end +function run_scripts() + scripts = { + "xmas2004" + } + for index in scripts do + local script = scriptpath .. "/" .. scripts[index] + print("- loading " .. script) + if pcall(dofile, script)==0 then + print("Could not load " .. script) + end + end +end + function process(orders) file = "" .. get_turn() if read_game(file)~=0 then @@ -33,12 +46,12 @@ function process(orders) add_equipment("money", 2000 + get_turn() * 10); -- run the turn: - read_orders(orders) + read_orders(orders) plan_monsters() - -- igjarjuk gets called: - -- require("igjarjuk-call.lua") - -- call_igjarjuk() + -- load scripts: + run_scripts() + u = get_unit(atoi36("50ki")) if u~=nil then u.region:set_flag(14, true) @@ -46,12 +59,6 @@ function process(orders) -- process_orders() - -- igjarjuk special - -- if get_turn() > 374 then - -- require("igjarjuk.lua") - -- wyrm() - -- end - write_passwords() write_reports() diff --git a/src/scripts/samples.lua b/src/scripts/samples.lua index d1e463c43..bd0c305be 100644 --- a/src/scripts/samples.lua +++ b/src/scripts/samples.lua @@ -13,9 +13,6 @@ function test_sail() orc:add_order("NUMMER EINHEIT orc") orc:add_order("BENENNE EINHEIT Orks") orc:add_order("ZEIGEN \"Sonnensegel\"") - - process_orders() - write_reports() end function test_movement() @@ -93,9 +90,6 @@ function test_movement() u2:add_order("NUMMER EINHEIT Last") u2:add_order("BENENNE EINHEIT Verfolger-Verfolger") - - process_orders() - write_reports() end @@ -133,8 +127,6 @@ function test_handler() u:add_order("NUMMER PARTEI eviL") u:add_order(msg) - process_orders() - write_reports() end function test_combat() @@ -169,8 +161,6 @@ function test_combat() u:add_order("KAEMPFE") u:add_order(attack) - process_orders() - write_reports() end function test_rewards() @@ -238,8 +228,6 @@ function test_rewards() end u:add_order("NUMMER PARTEI eviL") - process_orders() - write_reports() end function test_give() @@ -256,16 +244,11 @@ function test_give() 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) @@ -291,7 +274,6 @@ function test_monsters() set_brain("braineater", move_north) plan_monsters() - process_orders() end function test_parser() @@ -308,10 +290,6 @@ function test_parser() u:add_order("Nummer Partei test") u:add_order("BENENNE PARTEI \"Diese Partei heisst \\\"Enno's Schergen\\\".\"") u:add_order("BENENNE EINHEIT \"Mein Name ist \\\"Enno\\\".\"") - - process_orders() - write_reports() - write_game("parser") end function test_fail() @@ -322,7 +300,19 @@ function test_fail() print(f) end -test_sail() +function run_scripts() + scripts = { + "xmas2004.lua" + } + for index in scripts do + local script = scriptpath .. "/" .. scripts[index] + print("- loading " .. script) + if pcall(dofile, script)==0 then + print("Could not load " .. script) + end + end +end + -- test_movement() -- test_fail() -- test_handler() @@ -332,5 +322,8 @@ test_sail() -- test_rewards() -- test_give() -- test_write() --- read_game("test") --- write_game("test") + +test_sail() +run_scripts() +process_orders() +write_reports() diff --git a/src/scripts/xmas2004.lua b/src/scripts/xmas2004.lua new file mode 100644 index 000000000..49e20b4c9 --- /dev/null +++ b/src/scripts/xmas2004.lua @@ -0,0 +1,17 @@ +function xmas2004() + print(get_gamename()) + if get_gamename() == "Eressea" then + if not get_flag("xm04") then + print("Es weihnachtet sehr") + set_flag("xm04", true) + for f in factions() do + f:add_item("speedsail", 1) + f:add_notice("santa2004") + print(f) + end + end + end +end + +print("Ja, ist denn schon Weihnachten?") +xmas2004()