added promote, renumber, restack to eressea.process interface

fixed a test that relied on no random skill progress
This commit is contained in:
Enno Rehling 2012-06-16 23:31:25 -07:00
parent a662f88868
commit 9124fe2c6d
7 changed files with 144 additions and 111 deletions

View File

@ -33,6 +33,9 @@ function test_process()
assert_equal("function", _G.type(eressea.process.battle)) assert_equal("function", _G.type(eressea.process.battle))
assert_equal("function", _G.type(eressea.process.siege)) assert_equal("function", _G.type(eressea.process.siege))
assert_equal("function", _G.type(eressea.process.leave)) assert_equal("function", _G.type(eressea.process.leave))
assert_equal("function", _G.type(eressea.process.promote))
assert_equal("function", _G.type(eressea.process.renumber))
assert_equal("function", _G.type(eressea.process.restack))
end end
function test_settings() function test_settings()

View File

@ -14,7 +14,7 @@ function setup()
r = _G.region.create(0, 0, "mountain") r = _G.region.create(0, 0, "mountain")
f = _G.faction.create("noreply@eressea.de", "human", "de") f = _G.faction.create("noreply@eressea.de", "human", "de")
u = _G.unit.create(f, r, 1) u = _G.unit.create(f, r, 1)
u:clear_orders() u:clear_orders()
eressea.settings.set("rules.economy.food", "4") eressea.settings.set("rules.economy.food", "4")
eressea.settings.set("nmr.removenewbie", "0") eressea.settings.set("nmr.removenewbie", "0")
eressea.settings.set("nmr.timeout", "0") eressea.settings.set("nmr.timeout", "0")
@ -22,164 +22,171 @@ function setup()
end end
function test_learn() function test_learn()
u:add_order("LERNEN Hiebwaffen") u:add_order("LERNEN Hiebwaffen")
_G.process_orders() _G.process_orders()
assert_not_equal(0, u:get_skill("melee")) assert_not_equal(0, u:get_skill("melee"))
end end
function test_give() function test_give()
local u2 = _G.unit.create(f, r, 1) local u2 = _G.unit.create(f, r, 1)
u:add_item("money", 10) u:add_item("money", 10)
u:add_order("GIB " .. u2.id .. "5 SILBER") u:add_order("GIB " .. u2.id .. "5 SILBER")
_G.process_orders() _G.process_orders()
assert_not_equal(5, u:get_item("money")) assert_not_equal(5, u:get_item("money"))
assert_not_equal(5, u2:get_item("money")) assert_not_equal(5, u2:get_item("money"))
end end
function test_make_temp() function test_make_temp()
u:add_order("MACHE TEMP 123 'Herpderp'") u:add_order("MACHE TEMP 123 'Herpderp'")
u:add_order("// this comment will be copied") u:add_order("// this comment will be copied")
u:add_order("ENDE") u:add_order("ENDE")
eressea.process.make_temp() eressea.process.make_temp()
for x in f.units do for x in f.units do
if x.name == 'Herpderp' then u=x end if x.name == 'Herpderp' then u=x end
end end
assert_equal('Herpderp', u.name) assert_equal('Herpderp', u.name)
assert_equal(0, u.number) assert_equal(0, u.number)
local c = 0 local c = 0
for o in u.orders do for o in u.orders do
assert_equal('// this comment will be copied', o) assert_equal('// this comment will be copied', o)
c = c + 1 c = c + 1
end end
assert_equal(1, c) assert_equal(1, c)
end end
function test_give_temp() function test_give_temp()
u.number = 2 u.number = 2
u:add_order("GIB TEMP 123 1 PERSON") u:add_order("GIB TEMP 123 1 PERSON")
u:add_order("MACHE TEMP 123 'Herpderp'") u:add_order("MACHE TEMP 123 'Herpderp'")
u:add_order("ENDE") u:add_order("ENDE")
_G.process_orders() _G.process_orders()
assert_equal(1, u.number) assert_equal(1, u.number)
for x in f.units do for x in f.units do
if x.name == 'Herpderp' then u=x end if x.name == 'Herpderp' then u=x end
end end
assert_equal('Herpderp', u.name) assert_equal('Herpderp', u.name)
assert_equal(1, u.number) assert_equal(1, u.number)
end end
function test_process_settings() function test_process_settings()
f.options = 0 f.options = 0
u:add_order("EMAIL herp@derp.com") u:add_order("EMAIL herp@derp.com")
u:add_order("BANNER 'Herpderp'") u:add_order("BANNER 'Herpderp'")
u:add_order("PASSWORT 'HerpDerp'") u:add_order("PASSWORT 'HerpDerp'")
u:add_order("OPTION AUSWERTUNG") u:add_order("OPTION AUSWERTUNG")
eressea.process.settings() eressea.process.settings()
assert_equal("herp@derp.com", f.email) assert_equal("herp@derp.com", f.email)
assert_equal("Herpderp", f.info) assert_equal("Herpderp", f.info)
assert_equal("HerpDerp", f.password) assert_equal("HerpDerp", f.password)
assert_equal(1, f.options) assert_equal(1, f.options)
end end
function test_process_group() function test_process_group()
u:add_order("GRUPPE herp") u:add_order("GRUPPE herp")
eressea.process.set_group() eressea.process.set_group()
assert_equal('herp', u.group) assert_equal('herp', u.group)
end end
function test_process_origin() function test_process_origin()
u:add_order("URSPRUNG 1 2") u:add_order("URSPRUNG 1 2")
eressea.process.set_origin() eressea.process.set_origin()
x, y = u.faction:get_origin() x, y = u.faction:get_origin()
assert_equal(1, x) assert_equal(1, x)
assert_equal(2, y) assert_equal(2, y)
end end
function test_process_quit() function test_process_quit()
fno = f.id fno = f.id
u:add_order("STIRB '" .. u.faction.password .. "'") u:add_order("STIRB '" .. u.faction.password .. "'")
assert_not_equal(nil, _G.get_faction(fno)) assert_not_equal(nil, _G.get_faction(fno))
eressea.process.quit() eressea.process.quit()
eressea.write_game('test.dat') eressea.write_game('test.dat')
eressea.free_game() eressea.free_game()
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() function test_process_make()
u.region:set_resource('tree', 100) u.region:set_resource('tree', 100)
u:set_skill('forestry', 1) u:set_skill('forestry', 1)
u:add_order('MACHE HOLZ') u:add_order('MACHE HOLZ')
eressea.process.produce() eressea.process.produce()
assert_equal(1, u:get_item('log')) 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 end
function test_process_study() function test_process_study()
u:set_skill('forestry', 3) u:add_order("LERNEN Holzfaellen")
u2 = _G.unit.create(f, r, 10) 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_teach()
eressea.settings.set("study.random_progress", "0")
u:set_skill('forestry', 3)
u2 = _G.unit.create(f, r, 10)
u2:clear_orders() u2:clear_orders()
u2:set_skill('forestry', 1) u2:set_skill('forestry', 1)
u2:add_order("LERNEN Holzfaellen") u2:add_order("LERNEN Holzfaellen")
u:add_order("LEHREN " .. _G.itoa36(u2.id)) u:add_order("LEHREN " .. _G.itoa36(u2.id))
eressea.process.update_long_order() eressea.process.update_long_order()
eressea.process.study() eressea.process.study()
assert_equal(2, u2:get_skill('forestry')) assert_equal(2, u2:get_skill('forestry'))
end end
function test_process_move() function test_process_move()
r2 = _G.region.create(1, 0, 'plain') r2 = _G.region.create(1, 0, 'plain')
u:add_order('NACH O') u:add_order('NACH O')
assert_not_equal(r2, u.region) assert_not_equal(r2, u.region)
eressea.process.update_long_order() eressea.process.update_long_order()
eressea.process.movement() eressea.process.movement()
assert_equal(r2, u.region) assert_equal(r2, u.region)
end end
function test_process_leave() function test_process_leave()
r2 = _G.region.create(1, 0, 'plain') r2 = _G.region.create(1, 0, 'plain')
b = _G.building.create(r, default_building) b = _G.building.create(r, default_building)
u.building = b u.building = b
assert_equal(b, u.building) assert_equal(b, u.building)
u:add_order('VERLASSEN') u:add_order('VERLASSEN')
eressea.process.leave() eressea.process.leave()
assert_not_equal(b, u.building) assert_not_equal(b, u.building)
end end
function test_process_name_unit() function test_process_name_unit()
u:add_order("BENENNE EINHEIT 'Weasel'") u:add_order("BENENNE EINHEIT 'Weasel'")
u:add_order("BESCHREIBE EINHEIT 'Juanita'") u:add_order("BESCHREIBE EINHEIT 'Juanita'")
eressea.process.set_name() eressea.process.set_name()
assert_equal('Weasel', u.name) assert_equal('Weasel', u.name)
assert_equal('Juanita', u.info) assert_equal('Juanita', u.info)
end end
function test_process_name_faction() function test_process_name_faction()
u:add_order("BENENNE PARTEI 'Herpderp'") u:add_order("BENENNE PARTEI 'Herpderp'")
eressea.process.set_name() eressea.process.set_name()
assert_equal('Herpderp', f.name) assert_equal('Herpderp', f.name)
end end
function test_process_name_building() function test_process_name_building()
u:add_order("BENENNE GEBAEUDE 'Herpderp'") u:add_order("BENENNE GEBAEUDE 'Herpderp'")
u.building = _G.building.create(r, default_building) u.building = _G.building.create(r, default_building)
eressea.process.set_name() eressea.process.set_name()
assert_equal('Herpderp', u.building.name) assert_equal('Herpderp', u.building.name)
end end
function test_process_name_ship() function test_process_name_ship()
u:add_order("BENENNE SCHIFF 'Herpderp'") u:add_order("BENENNE SCHIFF 'Herpderp'")
u.ship = _G.ship.create(r, default_ship) u.ship = _G.ship.create(r, default_ship)
eressea.process.set_name() eressea.process.set_name()
assert_equal('Herpderp', u.ship.name) assert_equal('Herpderp', u.ship.name)
end
function test_process_renumber()
u:add_order("NUMMER EINHEIT 'ii'")
eressea.process.renumber()
assert_equal(666, u.id)
end end

View File

@ -177,6 +177,19 @@ void process_leave(void) {
process_cmd(K_LEAVE, leave_cmd, 0); process_cmd(K_LEAVE, leave_cmd, 0);
} }
void process_promote(void) {
process_cmd(K_PROMOTION, promotion_cmd, 0);
}
void process_renumber(void) {
process_cmd(K_NUMBER, renumber_cmd, 0);
renumber_factions();
}
void process_restack(void) {
restack_units();
}
void process_maintenance(void) { void process_maintenance(void) {
region * r; region * r;
for (r=regions; r; r=r->next) { for (r=regions; r; r=r->next) {

View File

@ -25,6 +25,9 @@ void process_battle(void);
void process_siege(void); void process_siege(void);
void process_leave(void); void process_leave(void);
void process_maintenance(void); void process_maintenance(void);
void process_promotion(void);
void process_renumber(void);
void process_restack(void);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -22,5 +22,8 @@ module eressea {
void process_siege @ siege(void); /* SIEGE */ void process_siege @ siege(void); /* SIEGE */
void process_leave @ leave(void); /* LEAVE */ void process_leave @ leave(void); /* LEAVE */
void process_maintenance @ maintenance(void); /* PAY */ void process_maintenance @ maintenance(void); /* PAY */
void process_promote @ promote(void); /* PROMOTE */
void process_renumber @ renumber(void); /* RENUMBER */
void process_restack @ restack(void); /* SORT */
} }
} }

View File

@ -2703,7 +2703,7 @@ static void reshow(unit * u, struct order *ord, const char *s, param_t p)
} }
} }
static int promotion_cmd(unit * u, struct order *ord) int promotion_cmd(unit * u, struct order *ord)
{ {
int money, people; int money, people;
@ -3005,7 +3005,7 @@ static attrib_type at_number = {
ATF_UNIQUE ATF_UNIQUE
}; };
static void renumber_factions(void) void renumber_factions(void)
/* gibt parteien neue nummern */ /* gibt parteien neue nummern */
{ {
struct renum { struct renum {
@ -3066,7 +3066,7 @@ static void renumber_factions(void)
} }
} }
static void reorder(void) void restack_units(void)
{ {
region *r; region *r;
for (r = regions; r; r = r->next) { for (r = regions; r; r = r->next) {
@ -3146,7 +3146,7 @@ static void reorder(void)
} }
} }
static int renumber_cmd(unit * u, order * ord) int renumber_cmd(unit * u, order * ord)
{ {
const char *s; const char *s;
int i; int i;
@ -4605,7 +4605,7 @@ void init_processor(void)
if (!global.disabled[K_SORT]) { if (!global.disabled[K_SORT]) {
p += 10; p += 10;
add_proc_global(p, &reorder, "Einheiten sortieren"); add_proc_global(p, restack_units, "Einheiten sortieren");
} }
add_proc_order(p, K_PROMOTION, &promotion_cmd, 0, "Heldenbefoerderung"); add_proc_order(p, K_PROMOTION, &promotion_cmd, 0, "Heldenbefoerderung");
if (!global.disabled[K_NUMBER]) { if (!global.disabled[K_NUMBER]) {

View File

@ -52,6 +52,8 @@ extern "C" {
extern void new_units(void); extern void new_units(void);
extern void quit(void); extern void quit(void);
extern void renumber_factions(void);
extern void restack_units(void);
extern void update_long_order(struct unit *u); extern void update_long_order(struct unit *u);
extern void sinkships(struct region * r); extern void sinkships(struct region * r);
extern int password_cmd(struct unit *u, struct order *ord); extern int password_cmd(struct unit *u, struct order *ord);
@ -71,6 +73,8 @@ extern "C" {
extern int siege_cmd(struct unit *u, struct order *ord); extern int siege_cmd(struct unit *u, struct order *ord);
extern int leave_cmd(struct unit *u, struct order *ord); extern int leave_cmd(struct unit *u, struct order *ord);
extern int pay_cmd(struct unit *u, struct order *ord); extern int pay_cmd(struct unit *u, struct order *ord);
extern int promotion_cmd(struct unit *u, struct order *ord);
extern int renumber_cmd(struct unit *u, struct order *ord);
#ifdef __cplusplus #ifdef __cplusplus
} }