neue lua-exporte:

- unit:tostring
- unit:operator==

mehrere wdw-parameter aus defines raus, und ins datenfile rein (traumziel ist, den gleichen server für alle spiele zu nehmen)
This commit is contained in:
Enno Rehling 2004-04-11 15:11:19 +00:00
parent 846f110268
commit 5d559840fa
8 changed files with 177 additions and 115 deletions

View File

@ -84,6 +84,28 @@ attrib_type at_reportspell = {
** TODO: separate castle-appearance from illusion-effects ** 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 * static ship *
findshipr(const region *r, int n) findshipr(const region *r, int n)
/* Ein Schiff in einer bestimmten Region finden: */ /* 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); cmistake(u, findorder(u, u->thisorder), 185, MSG_MAGIC);
} }
#ifdef MAGICPOWER force = force * MagicPower();
force = force * MAGICPOWER;
#endif
return max(force, 0); return max(force, 0);
} }
@ -1254,84 +1274,86 @@ fumble(region * r, unit * u, spell * sp, int cast_grade)
static void static void
do_fumble(castorder *co) do_fumble(castorder *co)
{ {
curse * c; curse * c;
region * r = co->rt; region * r = co->rt;
unit * u = (unit*)co->magician; unit * u = (unit*)co->magician;
spell * sp = co->sp; spell * sp = co->sp;
int level = co->level; int level = co->level;
int duration; int duration;
const char * sp_name = spell_name(sp, u->faction->locale);
switch (rand() % 10) { ADDMSG(&u->faction->msgs, msg_message("patzer", "unit region spell",
/* wenn vorhanden spezieller Patzer, ansonsten nix */ u, r, sp_name));
case 0: switch (rand() % 10) {
sp->patzer(co); case 0:
break; /* wenn vorhanden spezieller Patzer, ansonsten nix */
case 1: sp->patzer(co);
/* Kröte */ break;
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;
case 5: case 1:
case 6: /* Kröte */
/* Spruch gelingt, aber alle Magiepunkte weg */ duration = rand()%level/2;
((nspell_f)sp->sp_function)(co); if (duration<2) duration = 2;
set_spellpoints(u, 0); {
sprintf(buf, "Als %s versucht, '%s' zu zaubern erhebt sich " /* one or two things will happen: the toad changes her race back,
"plötzlich ein dunkler Wind. Bizarre geisterhafte " * and may or may not get toadslime.
"Gestalten kreisen um den Magier und scheinen sich von " * The list of things to happen are attached to a timeout
"den magischen Energien des Zaubers zu ernähren. Mit letzter " * trigger and that's added to the triggerlit of the mage gone toad.
"Kraft gelingt es %s dennoch den Spruch zu zaubern.", */
unitname(u), spell_name(sp, u->faction->locale), unitname(u)); trigger * trestore = trigger_changerace(u, u->race, u->irace);
addmessage(0, u->faction, buf, MSG_MAGIC, ML_WARN); if (rand()%10>2) t_add(&trestore, trigger_giveitem(u, olditemtype[I_TOADSLIME], 1));
break; 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 2:
case 8: /* temporärer Stufenverlust */
case 9: duration = max(rand()%level/2, 2);
default: c = create_curse(u, &u->attribs, ct_find("skil"), level, duration,
/* Spruch gelingt, alle nachfolgenden Sprüche werden 2^4 so teuer */ -(level/2), 1);
((nspell_f)sp->sp_function)(co); c->data = (void*)SK_MAGIC;
sprintf(buf, "%s fühlt sich nach dem Zaubern von %s viel erschöpfter " ADDMSG(&u->faction->msgs, msg_message("patzer2", "unit region", u, r));
"als sonst und hat das Gefühl, dass alle weiteren Zauber deutlich " break;
"mehr Kraft als normalerweise kosten werden.", unitname(u), case 3:
spell_name(sp, u->faction->locale)); case 4:
addmessage(0, u->faction, buf, MSG_MAGIC, ML_WARN); /* Spruch schlägt fehl, alle Magiepunkte weg */
countspells(u,3); 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 */ /* Würfeln */
aura = (rand() % d + rand() % d)/2 + 1; aura = (rand() % d + rand() % d)/2 + 1;
#ifdef MAGICREGEN aura = (int)(aura * MagicRegeneration());
aura = (int)(aura * MAGICREGEN);
#endif
return aura; return aura;
} }

View File

@ -25,18 +25,39 @@
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
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 void
update_resources(region * r) update_resources(region * r)
{ {
struct rawmaterial * res = r->resources; struct rawmaterial * res = r->resources;
while (res) { while (res) {
if (res->type->update) res->type->update(res, r); if (res->type->update) res->type->update(res, r);
res = res->next; res = res->next;
} }
} }
extern int dice_rand(const char *s); 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 void
terraform_resources(region * r) terraform_resources(region * r)
{ {
@ -53,6 +74,7 @@ terraform_resources(region * r)
if (rand()%100 < tdata->rawmaterials[i].chance) { if (rand()%100 < tdata->rawmaterials[i].chance) {
struct rawmaterial * res = calloc(sizeof(struct rawmaterial), 1); struct rawmaterial * res = calloc(sizeof(struct rawmaterial), 1);
res->next = r->resources; res->next = r->resources;
r->resources = res; r->resources = res;
res->level = dice_rand(tdata->rawmaterials[i].startlevel); 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->divisor = dice_rand(tdata->rawmaterials[i].divisor);
res->flags = 0; res->flags = 0;
res->type = tdata->rawmaterials[i].type; res->type = tdata->rawmaterials[i].type;
res->amount = (int)(res->base * (1+(res->level-res->startlevel)*(res->divisor/100.0))); update_resource(res, 1.0);
#ifdef RESOURCE_FACTOR
res->amount = (int)(res->amount * RESOURCE_FACTOR);
if (res->amount == 0) res->amount = 1;
#endif
assert(res->amount>0);
res->type->terraform(res, r); res->type->terraform(res, r);
} }
} }
@ -120,28 +137,25 @@ visible_default(const rawmaterial *res, int skilllevel)
return -1; 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)]; const terraindata_t * tdata = &terrain[rterrain(r)];
assert(res->amount>0 && amount>=0 && amount <= res->amount); assert(res->amount>0 && amount>=0 && amount <= res->amount);
res->amount-=amount; res->amount-=amount;
while (res->amount==0) { while (res->amount==0) {
double modifier = 1.0 + ((rand() % (SHIFT*2+1)) - SHIFT) * ((rand() % (SHIFT*2+1)) - SHIFT) / 10000.0; double modifier = 1.0 + ((rand() % (SHIFT*2+1)) - SHIFT) * ((rand() % (SHIFT*2+1)) - SHIFT) / 10000.0;
int i; int i;
for (i=0; i!=3; ++i) { for (i=0; i!=3; ++i) {
const rawmaterial_type * rmtype = tdata->rawmaterials[i].type; const rawmaterial_type * rmtype = tdata->rawmaterials[i].type;
assert(rmtype); assert(rmtype);
if (rmtype==res->type) break; if (rmtype==res->type) break;
} }
++res->level; ++res->level;
res->amount = (int)(modifier * res->base * (1+(res->level-res->startlevel)*res->divisor/100.0)); update_resource(res, modifier);
/* random adjustment, +/- 91% */ }
#ifdef RESOURCE_QUANTITY
res->amount = (int)(res->amount * RESOURCE_QUANTITY);
#endif
}
} }
struct rawmaterial * struct rawmaterial *

View File

@ -35,10 +35,7 @@
#define PEASANTS_DO_NOT_STARVE 0 #define PEASANTS_DO_NOT_STARVE 0
#define NEW_MIGRATION 1 #define NEW_MIGRATION 1
#define MIGRANTS_CAN_LEARN_EXPENSIVE_SKILLS 1 /* vinyambar 3 only */ #define MIGRANTS_CAN_LEARN_EXPENSIVE_SKILLS 1 /* vinyambar 3 only */
#define MAGICPOWER 0.5
#define MAGICREGEN 0.5
#define ASTRAL_HUNGER #define ASTRAL_HUNGER
#define RESOURCE_FACTOR 0.25
#if NEWATSROI == 1 #if NEWATSROI == 1
#define ATSBONUS 2 #define ATSBONUS 2

View File

@ -88,6 +88,6 @@ bind_eressea(lua_State * L)
def("remove_empty_units", &remove_empty_units), def("remove_empty_units", &remove_empty_units),
/* planes not really implemented */ /* planes not really implemented */
def("find_plane_id", &find_plane_id) def("get_plane_id", &find_plane_id)
]; ];
} }

View File

@ -15,11 +15,14 @@
#include <kernel/magic.h> #include <kernel/magic.h>
#include <kernel/spell.h> #include <kernel/spell.h>
#include <util/base36.h>
// lua includes // lua includes
#include <lua.hpp> #include <lua.hpp>
#include <luabind/luabind.hpp> #include <luabind/luabind.hpp>
#include <luabind/iterator_policy.hpp> #include <luabind/iterator_policy.hpp>
#include <ostream>
using namespace luabind; using namespace luabind;
class bind_spell_ptr { class bind_spell_ptr {
@ -217,6 +220,19 @@ unit_setname(unit& u, const char * name)
set_string(&u.name, 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 void
bind_unit(lua_State * L) bind_unit(lua_State * L)
{ {
@ -226,6 +242,8 @@ bind_unit(lua_State * L)
class_<struct unit>("unit") class_<struct unit>("unit")
.property("name", &unit_getname, &unit_setname) .property("name", &unit_getname, &unit_setname)
.def(tostring(self))
.def(self == unit())
.def_readonly("faction", &unit::faction) .def_readonly("faction", &unit::faction)
.def_readonly("id", &unit::no) .def_readonly("id", &unit::no)
.def_readwrite("hp", &unit::hp) .def_readwrite("hp", &unit::hp)

View File

@ -1267,6 +1267,15 @@
</type> </type>
<text locale="de">"$unit($mage) erleidet einen Schock ${reason}."</text> <text locale="de">"$unit($mage) erleidet einen Schock ${reason}."</text>
</message> </message>
<message name="patzer" section="magic">
<type>
<arg name="unit" type="unit"></arg>
<arg name="region" type="region"></arg>
<arg name="spell" type="string"></arg>
</type>
<text locale="de">"$unit($unit) unterläuft in $region($region) beim Zaubern von $command ein Patzer:"</text>
<text locale="en">"$unit($unit) fumbles while casting $command in $region($region):"</text>
</message>
<message name="patzer3" section="magic"> <message name="patzer3" section="magic">
<type> <type>
<arg name="unit" type="unit"></arg> <arg name="unit" type="unit"></arg>

View File

@ -28,6 +28,9 @@
<param name="allied.skilllimit" value="15"/> <param name="allied.skilllimit" value="15"/>
<param name="atsroi.ats" value="2"/> <param name="atsroi.ats" value="2"/>
<param name="atsroi.roi" value="4"/> <param name="atsroi.roi" value="4"/>
<param name="magic.regeneration" value="0.5"/>
<param name="magic.power" value="0.5"/>
<param name="resource.factor" value="0.25"/>
</game> </game>
<xi:include href="vinyambar/wdw-strings.xml"/> <xi:include href="vinyambar/wdw-strings.xml"/>

View File

@ -19,9 +19,10 @@ end
function wyrm() function wyrm()
print("- running the wyrm quest") print("- running the wyrm quest")
local grave = get_region(-9995,4) local grave = get_region(-9995,4)
local plane = find_plane_id("arena") local plane = get_plane_id("arena")
local map = {} local map = {}
local mapsize = 0 local mapsize = 0
local r
for r in regions() do for r in regions() do
mapsize=mapsize+1 mapsize=mapsize+1
map[mapsize] = r map[mapsize] = r