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.siege))
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
function test_settings()

View File

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

View File

@ -177,6 +177,19 @@ void process_leave(void) {
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) {
region * r;
for (r=regions; r; r=r->next) {

View File

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

View File

@ -22,5 +22,8 @@ module eressea {
void process_siege @ siege(void); /* SIEGE */
void process_leave @ leave(void); /* LEAVE */
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;
@ -3005,7 +3005,7 @@ static attrib_type at_number = {
ATF_UNIQUE
};
static void renumber_factions(void)
void renumber_factions(void)
/* gibt parteien neue nummern */
{
struct renum {
@ -3066,7 +3066,7 @@ static void renumber_factions(void)
}
}
static void reorder(void)
void restack_units(void)
{
region *r;
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;
int i;
@ -4605,7 +4605,7 @@ void init_processor(void)
if (!global.disabled[K_SORT]) {
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");
if (!global.disabled[K_NUMBER]) {

View File

@ -52,6 +52,8 @@ extern "C" {
extern void new_units(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 sinkships(struct region * r);
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 leave_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
}