From 5d559840fa5687a14062bf215656dfff22f3f454 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 11 Apr 2004 15:11:19 +0000 Subject: [PATCH] neue lua-exporte: - unit:tostring - unit:operator== MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit mehrere wdw-parameter aus defines raus, und ins datenfile rein (traumziel ist, den gleichen server für alle spiele zu nehmen) --- src/common/kernel/magic.c | 180 +++++++++++++++++++--------------- src/common/kernel/resources.c | 74 ++++++++------ src/common/settings-wdw.h | 3 - src/eressea/lua/eressea.cpp | 2 +- src/eressea/lua/unit.cpp | 18 ++++ src/res/messages.xml | 9 ++ src/res/vinyambar-wdw.xml | 3 + src/scripts/default.lua | 3 +- 8 files changed, 177 insertions(+), 115 deletions(-) diff --git a/src/common/kernel/magic.c b/src/common/kernel/magic.c index 8266623ad..d877328c3 100644 --- a/src/common/kernel/magic.c +++ b/src/common/kernel/magic.c @@ -84,6 +84,28 @@ attrib_type at_reportspell = { ** TODO: separate castle-appearance from illusion-effects **/ +static double +MagicRegeneration(void) +{ + static double value = -1.0; + if (value<0) { + const char * str = get_param(global.parameters, "magic.regeneration"); + value = str?atof(str):1.0; + } + return value; +} + +static double +MagicPower(void) +{ + static double value = -1.0; + if (value<0) { + const char * str = get_param(global.parameters, "magic.power"); + value = str?atof(str):1.0; + } + return value; +} + static ship * findshipr(const region *r, int n) /* Ein Schiff in einer bestimmten Region finden: */ @@ -1009,9 +1031,7 @@ spellpower(region * r, unit * u, spell * sp, int cast_level) cmistake(u, findorder(u, u->thisorder), 185, MSG_MAGIC); } -#ifdef MAGICPOWER - force = force * MAGICPOWER; -#endif + force = force * MagicPower(); return max(force, 0); } @@ -1254,84 +1274,86 @@ fumble(region * r, unit * u, spell * sp, int cast_grade) static void do_fumble(castorder *co) { - curse * c; - region * r = co->rt; - unit * u = (unit*)co->magician; - spell * sp = co->sp; - int level = co->level; - int duration; + curse * c; + region * r = co->rt; + unit * u = (unit*)co->magician; + spell * sp = co->sp; + int level = co->level; + int duration; + const char * sp_name = spell_name(sp, u->faction->locale); - switch (rand() % 10) { - /* wenn vorhanden spezieller Patzer, ansonsten nix */ - case 0: - sp->patzer(co); - break; - case 1: - /* Kröte */ - duration = rand()%level/2; - if (duration<2) duration = 2; - { - /* one or two things will happen: the toad changes her race back, - * and may or may not get toadslime. - * The list of things to happen are attached to a timeout - * trigger and that's added to the triggerlit of the mage gone toad. - */ - trigger * trestore = trigger_changerace(u, u->race, u->irace); - if (rand()%10>2) t_add(&trestore, trigger_giveitem(u, olditemtype[I_TOADSLIME], 1)); - add_trigger(&u->attribs, "timer", trigger_timeout(duration, trestore)); - } - u->race = new_race[RC_TOAD]; - u->irace = new_race[RC_TOAD]; - sprintf(buf, "Eine Botschaft von %s: 'Ups! Quack, Quack!'", unitname(u)); - addmessage(r, 0, buf, MSG_MAGIC, ML_MISTAKE); - break; - case 2: - /* temporärer Stufenverlust */ - duration = max(rand()%level/2, 2); - c = create_curse(u, &u->attribs, ct_find("skil"), level, duration, - -(level/2), 1); - c->data = (void*)SK_MAGIC; - add_message(&u->faction->msgs, - new_message(u->faction, "patzer2%u:unit%r:region", u, r)); - break; - case 3: - case 4: - /* Spruch schlägt fehl, alle Magiepunkte weg */ - set_spellpoints(u, 0); - add_message(&u->faction->msgs, msg_message("patzer3", - "unit region command", - u, r, spell_name(sp, u->faction->locale))); - break; + ADDMSG(&u->faction->msgs, msg_message("patzer", "unit region spell", + u, r, sp_name)); + switch (rand() % 10) { + case 0: + /* wenn vorhanden spezieller Patzer, ansonsten nix */ + sp->patzer(co); + break; - case 5: - case 6: - /* Spruch gelingt, aber alle Magiepunkte weg */ - ((nspell_f)sp->sp_function)(co); - set_spellpoints(u, 0); - sprintf(buf, "Als %s versucht, '%s' zu zaubern erhebt sich " - "plötzlich ein dunkler Wind. Bizarre geisterhafte " - "Gestalten kreisen um den Magier und scheinen sich von " - "den magischen Energien des Zaubers zu ernähren. Mit letzter " - "Kraft gelingt es %s dennoch den Spruch zu zaubern.", - unitname(u), spell_name(sp, u->faction->locale), unitname(u)); - addmessage(0, u->faction, buf, MSG_MAGIC, ML_WARN); - break; + case 1: + /* Kröte */ + duration = rand()%level/2; + if (duration<2) duration = 2; + { + /* one or two things will happen: the toad changes her race back, + * and may or may not get toadslime. + * The list of things to happen are attached to a timeout + * trigger and that's added to the triggerlit of the mage gone toad. + */ + trigger * trestore = trigger_changerace(u, u->race, u->irace); + if (rand()%10>2) t_add(&trestore, trigger_giveitem(u, olditemtype[I_TOADSLIME], 1)); + add_trigger(&u->attribs, "timer", trigger_timeout(duration, trestore)); + } + u->race = new_race[RC_TOAD]; + u->irace = new_race[RC_TOAD]; + sprintf(buf, "Eine Botschaft von %s: 'Ups! Quack, Quack!'", unitname(u)); + addmessage(r, 0, buf, MSG_MAGIC, ML_MISTAKE); + break; - case 7: - case 8: - case 9: - default: - /* Spruch gelingt, alle nachfolgenden Sprüche werden 2^4 so teuer */ - ((nspell_f)sp->sp_function)(co); - sprintf(buf, "%s fühlt sich nach dem Zaubern von %s viel erschöpfter " - "als sonst und hat das Gefühl, dass alle weiteren Zauber deutlich " - "mehr Kraft als normalerweise kosten werden.", unitname(u), - spell_name(sp, u->faction->locale)); - addmessage(0, u->faction, buf, MSG_MAGIC, ML_WARN); - countspells(u,3); - } + case 2: + /* temporärer Stufenverlust */ + duration = max(rand()%level/2, 2); + c = create_curse(u, &u->attribs, ct_find("skil"), level, duration, + -(level/2), 1); + c->data = (void*)SK_MAGIC; + ADDMSG(&u->faction->msgs, msg_message("patzer2", "unit region", u, r)); + break; + case 3: + case 4: + /* Spruch schlägt fehl, alle Magiepunkte weg */ + set_spellpoints(u, 0); + ADDMSG(&u->faction->msgs, msg_message("patzer3", "unit region command", + u, r, sp_name)); + break; - return; + case 5: + case 6: + /* Spruch gelingt, aber alle Magiepunkte weg */ + ((nspell_f)sp->sp_function)(co); + set_spellpoints(u, 0); + sprintf(buf, "Als %s versucht, '%s' zu zaubern erhebt sich " + "plötzlich ein dunkler Wind. Bizarre geisterhafte " + "Gestalten kreisen um den Magier und scheinen sich von " + "den magischen Energien des Zaubers zu ernähren. Mit letzter " + "Kraft gelingt es %s dennoch den Spruch zu zaubern.", + unitname(u), sp_name, unitname(u)); + addmessage(0, u->faction, buf, MSG_MAGIC, ML_WARN); + break; + + case 7: + case 8: + case 9: + default: + /* Spruch gelingt, alle nachfolgenden Sprüche werden 2^4 so teuer */ + ((nspell_f)sp->sp_function)(co); + sprintf(buf, "%s fühlt sich nach dem Zaubern von %s viel erschöpfter " + "als sonst und hat das Gefühl, dass alle weiteren Zauber deutlich " + "mehr Kraft als normalerweise kosten werden.", unitname(u), sp_name); + addmessage(0, u->faction, buf, MSG_MAGIC, ML_WARN); + countspells(u, 3); + } + + return; } /* ------------------------------------------------------------- */ @@ -1361,9 +1383,7 @@ regeneration(unit * u) /* Würfeln */ aura = (rand() % d + rand() % d)/2 + 1; -#ifdef MAGICREGEN - aura = (int)(aura * MAGICREGEN); -#endif + aura = (int)(aura * MagicRegeneration()); return aura; } diff --git a/src/common/kernel/resources.c b/src/common/kernel/resources.c index 04b84a75b..6b79882d8 100644 --- a/src/common/kernel/resources.c +++ b/src/common/kernel/resources.c @@ -25,18 +25,39 @@ #include #include +static double +ResourceFactor(void) +{ + static double value = -1.0; + if (value<0) { + const char * str = get_param(global.parameters, "resource.factor"); + value = str?atof(str):1.0; + } + return value; +} + void update_resources(region * r) { - struct rawmaterial * res = r->resources; - while (res) { - if (res->type->update) res->type->update(res, r); - res = res->next; - } + struct rawmaterial * res = r->resources; + while (res) { + if (res->type->update) res->type->update(res, r); + res = res->next; + } } extern int dice_rand(const char *s); +static void +update_resource(struct rawmaterial * res, double modifier) +{ + double amount = 1 + (res->level-res->startlevel) * res->divisor/100.0; + amount = ResourceFactor() * res->base * amount * modifier; + if (amount<1.0) res->amount = 1; + else res->amount = (int)amount; + assert(res->amount>0); +} + void terraform_resources(region * r) { @@ -53,6 +74,7 @@ terraform_resources(region * r) if (rand()%100 < tdata->rawmaterials[i].chance) { struct rawmaterial * res = calloc(sizeof(struct rawmaterial), 1); + res->next = r->resources; r->resources = res; res->level = dice_rand(tdata->rawmaterials[i].startlevel); @@ -61,12 +83,7 @@ terraform_resources(region * r) res->divisor = dice_rand(tdata->rawmaterials[i].divisor); res->flags = 0; res->type = tdata->rawmaterials[i].type; - res->amount = (int)(res->base * (1+(res->level-res->startlevel)*(res->divisor/100.0))); -#ifdef RESOURCE_FACTOR - res->amount = (int)(res->amount * RESOURCE_FACTOR); - if (res->amount == 0) res->amount = 1; -#endif - assert(res->amount>0); + update_resource(res, 1.0); res->type->terraform(res, r); } } @@ -120,28 +137,25 @@ visible_default(const rawmaterial *res, int skilllevel) return -1; } -static void use_default(rawmaterial *res, const region * r, int amount) +static void +use_default(rawmaterial *res, const region * r, int amount) { - const terraindata_t * tdata = &terrain[rterrain(r)]; - assert(res->amount>0 && amount>=0 && amount <= res->amount); - res->amount-=amount; - while (res->amount==0) { - double modifier = 1.0 + ((rand() % (SHIFT*2+1)) - SHIFT) * ((rand() % (SHIFT*2+1)) - SHIFT) / 10000.0; - int i; + const terraindata_t * tdata = &terrain[rterrain(r)]; + assert(res->amount>0 && amount>=0 && amount <= res->amount); + res->amount-=amount; + while (res->amount==0) { + double modifier = 1.0 + ((rand() % (SHIFT*2+1)) - SHIFT) * ((rand() % (SHIFT*2+1)) - SHIFT) / 10000.0; + int i; - for (i=0; i!=3; ++i) { - const rawmaterial_type * rmtype = tdata->rawmaterials[i].type; - assert(rmtype); - if (rmtype==res->type) break; - } + for (i=0; i!=3; ++i) { + const rawmaterial_type * rmtype = tdata->rawmaterials[i].type; + assert(rmtype); + if (rmtype==res->type) break; + } - ++res->level; - res->amount = (int)(modifier * res->base * (1+(res->level-res->startlevel)*res->divisor/100.0)); - /* random adjustment, +/- 91% */ -#ifdef RESOURCE_QUANTITY - res->amount = (int)(res->amount * RESOURCE_QUANTITY); -#endif - } + ++res->level; + update_resource(res, modifier); + } } struct rawmaterial * diff --git a/src/common/settings-wdw.h b/src/common/settings-wdw.h index 917e7c9cf..eaaaca0d8 100644 --- a/src/common/settings-wdw.h +++ b/src/common/settings-wdw.h @@ -35,10 +35,7 @@ #define PEASANTS_DO_NOT_STARVE 0 #define NEW_MIGRATION 1 #define MIGRANTS_CAN_LEARN_EXPENSIVE_SKILLS 1 /* vinyambar 3 only */ -#define MAGICPOWER 0.5 -#define MAGICREGEN 0.5 #define ASTRAL_HUNGER -#define RESOURCE_FACTOR 0.25 #if NEWATSROI == 1 #define ATSBONUS 2 diff --git a/src/eressea/lua/eressea.cpp b/src/eressea/lua/eressea.cpp index dd3bd9def..5a8b9a929 100644 --- a/src/eressea/lua/eressea.cpp +++ b/src/eressea/lua/eressea.cpp @@ -88,6 +88,6 @@ bind_eressea(lua_State * L) def("remove_empty_units", &remove_empty_units), /* planes not really implemented */ - def("find_plane_id", &find_plane_id) + def("get_plane_id", &find_plane_id) ]; } diff --git a/src/eressea/lua/unit.cpp b/src/eressea/lua/unit.cpp index 169f4bd37..45bf3b58e 100644 --- a/src/eressea/lua/unit.cpp +++ b/src/eressea/lua/unit.cpp @@ -15,11 +15,14 @@ #include #include +#include + // lua includes #include #include #include +#include using namespace luabind; class bind_spell_ptr { @@ -217,6 +220,19 @@ unit_setname(unit& u, const char * name) set_string(&u.name, name); } +static std::ostream& +operator<<(std::ostream& stream, unit& u) +{ + stream << u.name << " (" << itoa36(u.no) << ")"; + return stream; +} + +static bool +operator==(const unit& a, const unit&b) +{ + return a.no==b.no; +} + void bind_unit(lua_State * L) { @@ -226,6 +242,8 @@ bind_unit(lua_State * L) class_("unit") .property("name", &unit_getname, &unit_setname) + .def(tostring(self)) + .def(self == unit()) .def_readonly("faction", &unit::faction) .def_readonly("id", &unit::no) .def_readwrite("hp", &unit::hp) diff --git a/src/res/messages.xml b/src/res/messages.xml index 1fcaa072d..391ea31a9 100644 --- a/src/res/messages.xml +++ b/src/res/messages.xml @@ -1267,6 +1267,15 @@ "$unit($mage) erleidet einen Schock ${reason}." + + + + + + + "$unit($unit) unterläuft in $region($region) beim Zaubern von $command ein Patzer:" + "$unit($unit) fumbles while casting $command in $region($region):" + diff --git a/src/res/vinyambar-wdw.xml b/src/res/vinyambar-wdw.xml index a5f5b6557..ed65c05ad 100644 --- a/src/res/vinyambar-wdw.xml +++ b/src/res/vinyambar-wdw.xml @@ -28,6 +28,9 @@ + + + diff --git a/src/scripts/default.lua b/src/scripts/default.lua index b1546738d..36dd731ba 100644 --- a/src/scripts/default.lua +++ b/src/scripts/default.lua @@ -19,9 +19,10 @@ end function wyrm() print("- running the wyrm quest") local grave = get_region(-9995,4) - local plane = find_plane_id("arena") + local plane = get_plane_id("arena") local map = {} local mapsize = 0 + local r for r in regions() do mapsize=mapsize+1 map[mapsize] = r