diff --git a/scripts/tests/bindings.lua b/scripts/tests/bindings.lua index eb81b21f6..a6f8434a5 100755 --- a/scripts/tests/bindings.lua +++ b/scripts/tests/bindings.lua @@ -27,6 +27,9 @@ function test_process() 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.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 function test_settings() diff --git a/scripts/tests/orders.lua b/scripts/tests/orders.lua index 2fc1e5b77..84c02309a 100755 --- a/scripts/tests/orders.lua +++ b/scripts/tests/orders.lua @@ -105,3 +105,40 @@ function test_process_quit() eressea.read_game('test.dat') assert_equal(nil, _G.get_faction(fno)) 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 + diff --git a/src/bindings/bind_process.c b/src/bindings/bind_process.c index 105a68480..6e739ec8d 100755 --- a/src/bindings/bind_process.c +++ b/src/bindings/bind_process.c @@ -5,14 +5,56 @@ #include #include #include +#include #include #include #include +#include + +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) { struct 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 (K_MAKE == get_keyword(ord)) { + make_cmd(u, ord); + } + } + } 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) { process_cmd(K_ALLY, ally_cmd); } @@ -107,3 +133,16 @@ void process_quit(void) { process_cmd(K_QUIT, quit_cmd); 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); +} diff --git a/src/bindings/bind_process.h b/src/bindings/bind_process.h index 2cd754135..009a79325 100755 --- a/src/bindings/bind_process.h +++ b/src/bindings/bind_process.h @@ -18,6 +18,9 @@ void process_display(void); void process_group(void); void process_origin(void); void process_quit(void); +void process_study(void); +void process_movement(void); +void process_use(void); #ifdef __cplusplus } diff --git a/src/bindings/process.pkg b/src/bindings/process.pkg index 37086e1cf..ef123716c 100755 --- a/src/bindings/process.pkg +++ b/src/bindings/process.pkg @@ -4,7 +4,7 @@ module eressea { module process { void process_update_long_order @ update_long_order(void); 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_settings @ settings(void); /* EMAIL/PASSWORD/BANNER/OPTION */ void process_ally @ set_allies(void); /* HELP */ @@ -15,5 +15,8 @@ module eressea { void process_group @ set_group(void); /* GROUP */ void process_origin @ set_origin(void); /* ORIGIN */ 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 */ } } diff --git a/src/gamecode/laws.c b/src/gamecode/laws.c index 4ad866a11..7f4c9278d 100755 --- a/src/gamecode/laws.c +++ b/src/gamecode/laws.c @@ -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; int n, err = ENOITEM; diff --git a/src/gamecode/laws.h b/src/gamecode/laws.h index 2d9cc2ce7..b3503f5d7 100755 --- a/src/gamecode/laws.h +++ b/src/gamecode/laws.h @@ -61,6 +61,7 @@ extern "C" { extern int origin_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 use_cmd(struct unit *u, struct order *ord); #ifdef __cplusplus }