bind more processing functions to Lua (almost done)

This commit is contained in:
Enno Rehling 2012-07-24 00:16:25 -07:00
parent a08cb98fd2
commit ea618453f7
10 changed files with 156 additions and 52 deletions

View File

@ -45,6 +45,14 @@ function test_process()
assert_equal("function", _G.type(eressea.process.regeneration))
assert_equal("function", _G.type(eressea.process.guard_on))
assert_equal("function", _G.type(eressea.process.guard_off))
assert_equal("function", _G.type(eressea.process.explain))
assert_equal("function", _G.type(eressea.process.messages))
assert_equal("function", _G.type(eressea.process.reserve))
assert_equal("function", _G.type(eressea.process.claim))
assert_equal("function", _G.type(eressea.process.follow))
assert_equal("function", _G.type(eressea.process.alliance))
assert_equal("function", _G.type(eressea.process.idle))
assert_equal("function", _G.type(eressea.process.set_default))
end
function test_settings()

View File

@ -236,3 +236,31 @@ end
function test_process_guard_off()
eressea.process.guard_off()
end
function test_process_explain()
eressea.process.explain()
end
function test_process_messages()
eressea.process.messages()
end
function test_process_reserve()
eressea.process.reserve()
end
function test_process_claim()
eressea.process.claim()
end
function test_process_follow()
eressea.process.follow()
end
function test_process_idle()
eressea.process.idle()
end
function test_process_set_default()
eressea.process.set_default()
end

View File

@ -2,6 +2,8 @@
#include <platform.h>
#include <kernel/types.h>
#include <kernel/alliance.h>
#include <kernel/config.h>
#include <kernel/magic.h>
#include <kernel/order.h>
#include <kernel/battle.h>
@ -215,6 +217,32 @@ void process_guard_on(void) {
process_cmd(K_GUARD, guard_on_cmd, PROC_LAND_REGION);
}
void process_explain(void) {
process_cmd(K_RESHOW, reshow_cmd, 0);
}
void process_reserve(void) {
process_cmd(K_RESERVE, reserve_cmd, 0);
}
void process_claim(void) {
process_cmd(K_CLAIM, claim_cmd, 0);
}
void process_follow(void) {
struct region *r;
for (r = regions; r; r = r->next) {
unit * u;
for (u=r->units; u; u=u->next) {
follow_unit(u);
}
}
}
void process_messages(void) {
process_cmd(K_MAIL, mail_cmd, 0);
}
void process_guard_off(void) {
process_cmd(K_GUARD, guard_off_cmd, PROC_LAND_REGION);
}
@ -247,3 +275,20 @@ void process_maintenance(void) {
maintain_buildings(r, 0);
}
}
void process_alliance(void) {
alliance_cmd();
}
void process_idle(void) {
region * r;
for (r=regions; r; r=r->next) {
auto_work(r);
}
}
void process_set_default(void) {
if (!global.disabled[K_DEFAULT]) {
defaultorders();
}
}

View File

@ -37,6 +37,14 @@ void process_give_control(void);
void process_regeneration(void);
void process_guard_on(void);
void process_guard_off(void);
void process_explain(void);
void process_messages(void);
void process_reserve(void);
void process_claim(void);
void process_follow(void);
void process_alliance(void);
void process_idle(void);
void process_set_default(void);
#ifdef __cplusplus
}

View File

@ -34,5 +34,13 @@ module eressea {
void process_regeneration @ regeneration(void); /* regen health & aura */
void process_guard_on @ guard_on(void); /* GUARD */
void process_guard_off @ guard_off(void); /* GUARD NOT */
void process_explain @ explain(void); /* SHOW */
void process_messages @ messages(void); /* MESSAGE */
void process_reserve @ reserve(void); /* RESERVE */
void process_claim @ claim(void); /* CLAIM */
void process_follow @ follow(void); /* FOLLOW */
void process_alliance @ alliance(void); /* FOLLOW */
void process_idle @ idle(void); /* work.auto */
void process_set_default @ set_default(void); /* work.auto */
}
}

View File

@ -2166,7 +2166,7 @@ static void mailfaction(unit * u, int n, struct order *ord, const char *s)
cmistake(u, ord, 66, MSG_MESSAGE);
}
static int mail_cmd(unit * u, struct order *ord)
int mail_cmd(unit * u, struct order *ord)
{
region *r = u->region;
unit *u2;
@ -2781,7 +2781,7 @@ int guard_off_cmd(unit * u, struct order *ord)
return 0;
}
static int reshow_cmd(unit * u, struct order *ord)
int reshow_cmd(unit * u, struct order *ord)
{
const char *s;
param_t p = NOPARAM;
@ -3867,9 +3867,11 @@ static void remove_exclusive(order ** ordp)
}
}
static void defaultorders(void)
void defaultorders(void)
{
region *r;
assert(!global.disabled[K_DEFAULT]);
for (r = regions; r; r = r->next) {
unit *u;
for (u = r->units; u; u = u->next) {
@ -4054,7 +4056,39 @@ int pay_cmd(unit * u, struct order *ord)
return 0;
}
static int claim_cmd(unit * u, struct order *ord)
int reserve_cmd(unit * u, struct order *ord)
{
if (u->number > 0 && (urace(u)->ec_flags & GETITEM)) {
int use, count;
const resource_type *rtype;
const char *s;
init_tokens(ord);
skip_token();
s = getstrtoken();
count = atoip((const char *)s);
if (count == 0 && findparam(s, u->faction->locale) == P_EACH) {
count = getint() * u->number;
}
rtype = findresourcetype(getstrtoken(), u->faction->locale);
if (rtype == NULL)
return 0;
set_resvalue(u, rtype, 0); /* make sure the pool is empty */
use = use_pooled(u, rtype, GET_DEFAULT, count);
if (use) {
set_resvalue(u, rtype, use);
change_resource(u, rtype, use);
return use;
}
}
return 0;
}
int claim_cmd(unit * u, struct order *ord)
{
const char *t;
int n;

View File

@ -50,6 +50,7 @@ extern "C" {
extern int enter_ship(struct unit *u, struct order *ord, int id, int report);
extern void new_units(void);
extern void defaultorders(void);
extern void quit(void);
extern void monthly_healing(void);
extern void renumber_factions(void);
@ -81,7 +82,12 @@ extern "C" {
extern int contact_cmd(struct unit *u, struct order *ord);
extern int guard_on_cmd(struct unit *u, struct order *ord);
extern int guard_off_cmd(struct unit *u, struct order *ord);
extern int reshow_cmd(struct unit *u, struct order *ord);
extern int mail_cmd(struct unit *u, struct order *ord);
extern int reserve_cmd(struct unit *u, struct order *ord);
extern int claim_cmd(struct unit *u, struct order *ord);
extern int follow_cmd(struct unit *u, struct order *ord);
#ifdef __cplusplus
}
#endif

View File

@ -96,7 +96,7 @@ int change_resource(unit * u, const resource_type * rtype, int change)
int get_reservation(const unit * u, const resource_type * rtype)
{
struct reservation *res = u->reservations;
reservation *res = u->reservations;
if (rtype == oldresourcetype[R_STONE] && (u->race->flags & RCF_STONEGOLEM))
return (u->number * GOLEM_STONE);
@ -111,7 +111,7 @@ int get_reservation(const unit * u, const resource_type * rtype)
int change_reservation(unit * u, const resource_type * rtype, int value)
{
struct reservation *res, **rp = &u->reservations;
reservation *res, **rp = &u->reservations;
if (!value)
return 0;
@ -120,7 +120,7 @@ int change_reservation(unit * u, const resource_type * rtype, int value)
rp = &(*rp)->next;
res = *rp;
if (!res) {
*rp = res = calloc(sizeof(struct reservation), 1);
*rp = res = calloc(sizeof(reservation), 1);
res->type = rtype;
res->value = value;
} else if (res && res->value + value <= 0) {
@ -133,9 +133,9 @@ int change_reservation(unit * u, const resource_type * rtype, int value)
return res->value;
}
static int new_set_resvalue(unit * u, const resource_type * rtype, int value)
int set_resvalue(unit * u, const resource_type * rtype, int value)
{
struct reservation *res, **rp = &u->reservations;
reservation *res, **rp = &u->reservations;
while (*rp && (*rp)->type != rtype)
rp = &(*rp)->next;
@ -143,7 +143,7 @@ static int new_set_resvalue(unit * u, const resource_type * rtype, int value)
if (!res) {
if (!value)
return 0;
*rp = res = calloc(sizeof(struct reservation), 1);
*rp = res = calloc(sizeof(reservation), 1);
res->type = rtype;
res->value = value;
} else if (res && value <= 0) {
@ -253,34 +253,3 @@ use_pooled(unit * u, const resource_type * rtype, unsigned int mode, int count)
}
return count - use;
}
int reserve_cmd(unit * u, struct order *ord)
{
if (u->number > 0 && (urace(u)->ec_flags & GETITEM)) {
int use, count;
const resource_type *rtype;
const char *s;
init_tokens(ord);
skip_token();
s = getstrtoken();
count = atoip((const char *)s);
if (count == 0 && findparam(s, u->faction->locale) == P_EACH) {
count = getint() * u->number;
}
rtype = findresourcetype(getstrtoken(), u->faction->locale);
if (rtype == NULL)
return 0;
new_set_resvalue(u, rtype, 0); /* make sure the pool is empty */
use = use_pooled(u, rtype, GET_DEFAULT, count);
if (use) {
new_set_resvalue(u, rtype, use);
change_resource(u, rtype, use);
return use;
}
}
return 0;
}

View File

@ -54,11 +54,7 @@ extern "C" {
int change_reservation(struct unit *u, const struct resource_type *res,
int value);
int reserve_cmd(struct unit *u, struct order *ord);
/** init_pool
* initialisiert den regionalen Pool.
*/
int set_resvalue(struct unit * u, const struct resource_type * rtype, int value);
#ifdef __cplusplus
}

View File

@ -71,6 +71,12 @@ extern "C" {
extern int maxheroes(const struct faction *f);
extern int countheroes(const struct faction *f);
typedef struct reservation {
struct reservation *next;
const struct resource_type *type;
int value;
} reservation;
typedef struct unit {
struct unit *next; /* needs to be first entry, for region's unitlist */
struct unit *nextF; /* nächste Einheit der Partei */
@ -90,11 +96,7 @@ extern "C" {
short skill_size;
struct skill *skills;
struct item *items;
struct reservation {
struct reservation *next;
const struct resource_type *type;
int value;
} *reservations;
reservation *reservations;
/* orders */
struct order *orders;