From a53cc0a25c5d6981eac90865536e14799e33e300 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 10 Apr 2004 23:59:03 +0000 Subject: [PATCH] neue lua-exporte: - int get_plane_id(string) unit.number setzt auch auf 0 (killen) --- src/common/kernel/eressea.c | 58 ++++++++++++++++++------------------- src/eressea/lua/eressea.cpp | 13 ++++++++- src/eressea/lua/unit.cpp | 2 ++ 3 files changed, 43 insertions(+), 30 deletions(-) diff --git a/src/common/kernel/eressea.c b/src/common/kernel/eressea.c index 516b980ea..feebe323f 100644 --- a/src/common/kernel/eressea.c +++ b/src/common/kernel/eressea.c @@ -779,43 +779,43 @@ eff_stealth (const unit * u, const region * r) void scale_number (unit * u, int n) { - skill_t sk; - const attrib * a; - int remain; + skill_t sk; + const attrib * a; + int remain; - if (n == u->number) return; - if (n && u->number) { - int full; - remain = ((u->hp%u->number) * (n % u->number)) % u->number; + if (n == u->number) return; + if (n && u->number) { + int full; + remain = ((u->hp%u->number) * (n % u->number)) % u->number; - full = u->hp/u->number; /* wieviel kriegt jede person mindestens */ - u->hp = full * n + (u->hp-full*u->number) * n / u->number; - assert(u->hp>=0); - if ((rand() % u->number) < remain) - ++u->hp; /* Nachkommastellen */ - } else { - remain = 0; - u->hp = 0; - } - for (a = a_find(u->attribs, &at_effect);a;a=a->nexttype) { - effect_data * data = (effect_data *)a->data.v; - int snew = data->value / u->number * n; - if (n) { - remain = data->value - snew / n * u->number; - snew += remain * n / u->number; - remain = (remain * n) % u->number; - if ((rand() % u->number) < remain) - ++snew; /* Nachkommastellen */ - } - data->value = snew; - } + full = u->hp/u->number; /* wieviel kriegt jede person mindestens */ + u->hp = full * n + (u->hp-full*u->number) * n / u->number; + assert(u->hp>=0); + if ((rand() % u->number) < remain) + ++u->hp; /* Nachkommastellen */ + } else { + remain = 0; + u->hp = 0; + } + for (a = a_find(u->attribs, &at_effect);a;a=a->nexttype) { + effect_data * data = (effect_data *)a->data.v; + int snew = data->value / u->number * n; + if (n) { + remain = data->value - snew / n * u->number; + snew += remain * n / u->number; + remain = (remain * n) % u->number; + if ((rand() % u->number) < remain) + ++snew; /* Nachkommastellen */ + } + data->value = snew; + } if (u->number==0 || n==0) { for (sk = 0; sk < MAXSKILLS; sk++) { remove_skill(u, sk); } } - set_number(u, n); + set_number(u, n); } boolean diff --git a/src/eressea/lua/eressea.cpp b/src/eressea/lua/eressea.cpp index 7d10273d9..d4ec8ccd2 100644 --- a/src/eressea/lua/eressea.cpp +++ b/src/eressea/lua/eressea.cpp @@ -5,6 +5,7 @@ // kernel includes #include #include +#include #include #include #include @@ -63,6 +64,13 @@ write_reports() extern int process_orders(void); +static int +find_plane_id(const char * name) +{ + plane * pl = getplanebyname(name); + return pl?pl->id:0; +} + void bind_eressea(lua_State * L) { @@ -76,6 +84,9 @@ bind_eressea(lua_State * L) def("read_orders", &readorders), def("process_orders", &process_orders), def("add_equipment", &lua_addequipment), - def("get_turn", &get_turn) + def("get_turn", &get_turn), + + /* planes not really implemented */ + def("find_plane_id", &find_plane_id) ]; } diff --git a/src/eressea/lua/unit.cpp b/src/eressea/lua/unit.cpp index e9d9c49cd..c83e8149e 100644 --- a/src/eressea/lua/unit.cpp +++ b/src/eressea/lua/unit.cpp @@ -61,6 +61,8 @@ unit_setnumber(unit& u, int number) if (u.number==0) { set_number(&u, number); u.hp = unit_max_hp(&u) * number; + } else { + scale_number(&u, number); } }