neue lua-exporte:

- int get_plane_id(string)

unit.number setzt auch auf 0 (killen)
This commit is contained in:
Enno Rehling 2004-04-10 23:59:03 +00:00
parent 5f0ba5c2a0
commit a53cc0a25c
3 changed files with 43 additions and 30 deletions

View File

@ -779,43 +779,43 @@ eff_stealth (const unit * u, const region * r)
void void
scale_number (unit * u, int n) scale_number (unit * u, int n)
{ {
skill_t sk; skill_t sk;
const attrib * a; const attrib * a;
int remain; int remain;
if (n == u->number) return; if (n == u->number) return;
if (n && u->number) { if (n && u->number) {
int full; int full;
remain = ((u->hp%u->number) * (n % u->number)) % u->number; remain = ((u->hp%u->number) * (n % u->number)) % u->number;
full = u->hp/u->number; /* wieviel kriegt jede person mindestens */ full = u->hp/u->number; /* wieviel kriegt jede person mindestens */
u->hp = full * n + (u->hp-full*u->number) * n / u->number; u->hp = full * n + (u->hp-full*u->number) * n / u->number;
assert(u->hp>=0); assert(u->hp>=0);
if ((rand() % u->number) < remain) if ((rand() % u->number) < remain)
++u->hp; /* Nachkommastellen */ ++u->hp; /* Nachkommastellen */
} else { } else {
remain = 0; remain = 0;
u->hp = 0; u->hp = 0;
} }
for (a = a_find(u->attribs, &at_effect);a;a=a->nexttype) { for (a = a_find(u->attribs, &at_effect);a;a=a->nexttype) {
effect_data * data = (effect_data *)a->data.v; effect_data * data = (effect_data *)a->data.v;
int snew = data->value / u->number * n; int snew = data->value / u->number * n;
if (n) { if (n) {
remain = data->value - snew / n * u->number; remain = data->value - snew / n * u->number;
snew += remain * n / u->number; snew += remain * n / u->number;
remain = (remain * n) % u->number; remain = (remain * n) % u->number;
if ((rand() % u->number) < remain) if ((rand() % u->number) < remain)
++snew; /* Nachkommastellen */ ++snew; /* Nachkommastellen */
} }
data->value = snew; data->value = snew;
} }
if (u->number==0 || n==0) { if (u->number==0 || n==0) {
for (sk = 0; sk < MAXSKILLS; sk++) { for (sk = 0; sk < MAXSKILLS; sk++) {
remove_skill(u, sk); remove_skill(u, sk);
} }
} }
set_number(u, n); set_number(u, n);
} }
boolean boolean

View File

@ -5,6 +5,7 @@
// kernel includes // kernel includes
#include <gamecode/laws.h> #include <gamecode/laws.h>
#include <kernel/race.h> #include <kernel/race.h>
#include <kernel/plane.h>
#include <kernel/item.h> #include <kernel/item.h>
#include <kernel/reports.h> #include <kernel/reports.h>
#include <kernel/save.h> #include <kernel/save.h>
@ -63,6 +64,13 @@ write_reports()
extern int process_orders(void); extern int process_orders(void);
static int
find_plane_id(const char * name)
{
plane * pl = getplanebyname(name);
return pl?pl->id:0;
}
void void
bind_eressea(lua_State * L) bind_eressea(lua_State * L)
{ {
@ -76,6 +84,9 @@ bind_eressea(lua_State * L)
def("read_orders", &readorders), def("read_orders", &readorders),
def("process_orders", &process_orders), def("process_orders", &process_orders),
def("add_equipment", &lua_addequipment), 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)
]; ];
} }

View File

@ -61,6 +61,8 @@ unit_setnumber(unit& u, int number)
if (u.number==0) { if (u.number==0) {
set_number(&u, number); set_number(&u, number);
u.hp = unit_max_hp(&u) * number; u.hp = unit_max_hp(&u) * number;
} else {
scale_number(&u, number);
} }
} }