fix production of items in produce()

add use, move and study/teach to bindings
This commit is contained in:
Enno Rehling 2012-06-12 22:36:29 -07:00
parent 77575bad89
commit d38c5f5cfb
7 changed files with 104 additions and 18 deletions

View File

@ -27,6 +27,9 @@ function test_process()
assert_equal("function", _G.type(eressea.process.set_group)) assert_equal("function", _G.type(eressea.process.set_group))
assert_equal("function", _G.type(eressea.process.set_origin)) assert_equal("function", _G.type(eressea.process.set_origin))
assert_equal("function", _G.type(eressea.process.quit)) assert_equal("function", _G.type(eressea.process.quit))
assert_equal("function", _G.type(eressea.process.study))
assert_equal("function", _G.type(eressea.process.movement))
assert_equal("function", _G.type(eressea.process.use))
end end
function test_settings() function test_settings()

View File

@ -105,3 +105,40 @@ function test_process_quit()
eressea.read_game('test.dat') eressea.read_game('test.dat')
assert_equal(nil, _G.get_faction(fno)) assert_equal(nil, _G.get_faction(fno))
end end
function test_process_make()
u.region:set_resource('tree', 100)
u:set_skill('forestry', 1)
u:add_order('MACHE HOLZ')
eressea.process.produce()
assert_equal(1, u:get_item('log'))
end
function test_process_teach()
u:add_order("LERNEN Holzfaellen")
eressea.process.update_long_order()
eressea.process.study()
x, y = u.faction:get_origin()
assert_equal(1, u:get_skill('forestry'))
end
function test_process_study()
u:set_skill('forestry', 3)
u2 = _G.unit.create(f, r, 10)
u2:clear_orders()
u2:set_skill('forestry', 1)
u2:add_order("LERNEN Holzfaellen")
u:add_order("LEHREN " .. _G.itoa36(u2.id))
eressea.process.update_long_order()
eressea.process.study()
assert_equal(2, u2:get_skill('forestry'))
end
function test_process_move()
r2 = _G.region.create(1, 0, 'plain')
u:add_order('NACH O')
eressea.process.update_long_order()
eressea.process.movement()
assert_equal(r2, u.region)
end

View File

@ -5,14 +5,56 @@
#include <kernel/order.h> #include <kernel/order.h>
#include <kernel/region.h> #include <kernel/region.h>
#include <kernel/unit.h> #include <kernel/unit.h>
#include <kernel/move.h>
#include <gamecode/economy.h> #include <gamecode/economy.h>
#include <gamecode/laws.h> #include <gamecode/laws.h>
#include <gamecode/market.h> #include <gamecode/market.h>
#include <gamecode/study.h>
static void process_cmd(keyword_t kwd, int (*callback)(unit *, order *))
{
region * r;
for (r=regions; r; r=r->next) {
unit * u;
for (u=r->units; u; u=u->next) {
order * ord;
for (ord=u->orders; ord; ord=ord->next) {
if (kwd == get_keyword(ord)) {
callback(u, ord);
}
}
}
}
}
static void process_long_cmd(keyword_t kwd, int (*callback)(unit *, order *))
{
region * r;
for (r=regions; r; r=r->next) {
unit * u;
for (u=r->units; u; u=u->next) {
order * ord = u->thisorder;
if (kwd == get_keyword(ord)) {
callback(u, ord);
}
}
}
}
void process_produce(void) { void process_produce(void) {
struct region *r; struct region *r;
for (r = regions; r; r = r->next) { for (r = regions; r; r = r->next) {
unit * u;
for (u=r->units; u; u=u->next) {
order * ord;
for (ord=u->orders; ord; ord=ord->next) {
if (K_MAKE == get_keyword(ord)) {
make_cmd(u, ord);
}
}
}
produce(r); produce(r);
split_allocations(r);
} }
} }
@ -59,22 +101,6 @@ void process_settings(void) {
} }
} }
static void process_cmd(keyword_t kwd, int (*callback)(unit *, order *))
{
region * r;
for (r=regions; r; r=r->next) {
unit * u;
for (u=r->units; u; u=u->next) {
order * ord;
for (ord=u->orders; ord; ord=ord->next) {
if (kwd == get_keyword(ord)) {
callback(u, ord);
}
}
}
}
}
void process_ally(void) { void process_ally(void) {
process_cmd(K_ALLY, ally_cmd); process_cmd(K_ALLY, ally_cmd);
} }
@ -107,3 +133,16 @@ void process_quit(void) {
process_cmd(K_QUIT, quit_cmd); process_cmd(K_QUIT, quit_cmd);
quit(); quit();
} }
void process_study(void) {
process_long_cmd(K_TEACH, teach_cmd);
process_long_cmd(K_STUDY, learn_cmd);
}
void process_movement(void) {
movement();
}
void process_use(void) {
process_cmd(K_USE, use_cmd);
}

View File

@ -18,6 +18,9 @@ void process_display(void);
void process_group(void); void process_group(void);
void process_origin(void); void process_origin(void);
void process_quit(void); void process_quit(void);
void process_study(void);
void process_movement(void);
void process_use(void);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -4,7 +4,7 @@ module eressea {
module process { module process {
void process_update_long_order @ update_long_order(void); void process_update_long_order @ update_long_order(void);
void process_markets @ markets(void); /* operate the e3 markets */ void process_markets @ markets(void); /* operate the e3 markets */
void process_produce @ produce(void); /* BUY/SELL/ENTERTAIN/WORK/TAX/STEAL/SPY/SABOTAGE/PLANT/BREED/RESEARCH */ void process_produce @ produce(void); /* MAKE+BUY/SELL/ENTERTAIN/WORK/TAX/STEAL/SPY/SABOTAGE/PLANT/BREED/RESEARCH */
void process_make_temp @ make_temp(void); /* MAKE TEMP */ void process_make_temp @ make_temp(void); /* MAKE TEMP */
void process_settings @ settings(void); /* EMAIL/PASSWORD/BANNER/OPTION */ void process_settings @ settings(void); /* EMAIL/PASSWORD/BANNER/OPTION */
void process_ally @ set_allies(void); /* HELP */ void process_ally @ set_allies(void); /* HELP */
@ -15,5 +15,8 @@ module eressea {
void process_group @ set_group(void); /* GROUP */ void process_group @ set_group(void); /* GROUP */
void process_origin @ set_origin(void); /* ORIGIN */ void process_origin @ set_origin(void); /* ORIGIN */
void process_quit @ quit(void); /* QUIT */ void process_quit @ quit(void); /* QUIT */
void process_study @ study(void); /* LEARN/TEACH */
void process_movement @ movement(void); /* MOVE/FOLLOW/ROUTE */
void process_use @ use(void); /* USE */
} }
} }

View File

@ -3777,7 +3777,7 @@ static void age_factions(void)
} }
} }
static int use_cmd(unit * u, struct order *ord) int use_cmd(unit * u, struct order *ord)
{ {
const char *t; const char *t;
int n, err = ENOITEM; int n, err = ENOITEM;

View File

@ -61,6 +61,7 @@ extern "C" {
extern int origin_cmd(struct unit *u, struct order *ord); extern int origin_cmd(struct unit *u, struct order *ord);
extern int quit_cmd(struct unit *u, struct order *ord); extern int quit_cmd(struct unit *u, struct order *ord);
extern int name_cmd(struct unit *u, struct order *ord); extern int name_cmd(struct unit *u, struct order *ord);
extern int use_cmd(struct unit *u, struct order *ord);
#ifdef __cplusplus #ifdef __cplusplus
} }