forked from github/server
Bug 2605: testing horses and carts
fixing indentation in battle.c
This commit is contained in:
parent
cc77ce6f20
commit
ddc8c27489
|
@ -1134,19 +1134,6 @@ function test_route_pause()
|
||||||
assert_equal(r1, u.region)
|
assert_equal(r1, u.region)
|
||||||
end
|
end
|
||||||
|
|
||||||
function test_bug_2393_cart()
|
|
||||||
local r1 = region.create(0, 0, "plain")
|
|
||||||
local r2 = region.create(1, 0, "plain")
|
|
||||||
local f = faction.create("human", "cart@example.com")
|
|
||||||
local u = unit.create(f, r1, 2)
|
|
||||||
u:add_order("NACH O")
|
|
||||||
u:add_item('stone', 2)
|
|
||||||
u:add_item('horse', 2)
|
|
||||||
u:add_item('cart', 1)
|
|
||||||
process_orders()
|
|
||||||
assert_equal(r1, u.region)
|
|
||||||
end
|
|
||||||
|
|
||||||
function test_immunity_stops_guard()
|
function test_immunity_stops_guard()
|
||||||
eressea.settings.set("NewbieImmunity", 2)
|
eressea.settings.set("NewbieImmunity", 2)
|
||||||
local f = faction.create('human')
|
local f = faction.create('human')
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
require "lunit"
|
require "lunit"
|
||||||
|
|
||||||
module("tests.e2.capacity", package.seeall, lunit.testcase)
|
module("tests.e2.carts", package.seeall, lunit.testcase)
|
||||||
|
|
||||||
function setup()
|
function setup()
|
||||||
eressea.free_game()
|
eressea.free_game()
|
||||||
|
@ -116,3 +116,72 @@ function test_rider_leads_horses()
|
||||||
assert_equal(r1, u2.region)
|
assert_equal(r1, u2.region)
|
||||||
assert_equal(r1, u3.region)
|
assert_equal(r1, u3.region)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function test_carts()
|
||||||
|
local r0 = region.create(0, 0, "plain")
|
||||||
|
local r1 = region.create(1, 0, "plain")
|
||||||
|
local r2 = region.create(2, 0, "plain")
|
||||||
|
local r3 = region.create(3, 0, "plain")
|
||||||
|
local f = faction.create("human")
|
||||||
|
-- 1. two walkers, each with two horses and a cart:
|
||||||
|
local u1 = unit.create(f, r0, 2)
|
||||||
|
u1:add_item("horse", 2)
|
||||||
|
u1:add_item("cart", 1)
|
||||||
|
u1:add_order("NACH O O O")
|
||||||
|
-- 2. two riders, each with two horses and a cart:
|
||||||
|
local u2 = unit.create(f, r0, 2)
|
||||||
|
u2:set_skill("riding", 1)
|
||||||
|
u2:add_item("horse", 4)
|
||||||
|
u2:add_item("cart", 2)
|
||||||
|
u2:add_order("NACH O O O")
|
||||||
|
-- 2. two riders, each with five horses, and max carts:
|
||||||
|
local u3 = unit.create(f, r0, 2)
|
||||||
|
u3:set_skill("riding", 1)
|
||||||
|
u3:add_item("horse", 10)
|
||||||
|
u3:add_item("cart", 5)
|
||||||
|
u3:add_order("NACH O O O")
|
||||||
|
|
||||||
|
process_orders()
|
||||||
|
assert_equal(r1, u1.region)
|
||||||
|
assert_equal(r2, u2.region)
|
||||||
|
assert_equal(r1, u3.region)
|
||||||
|
end
|
||||||
|
|
||||||
|
function test_walking_carts()
|
||||||
|
local r0 = region.create(0, 0, "plain")
|
||||||
|
local r1 = region.create(1, 0, "plain")
|
||||||
|
local r2 = region.create(2, 0, "plain")
|
||||||
|
local r3 = region.create(3, 0, "plain")
|
||||||
|
local f = faction.create("human")
|
||||||
|
-- 1. ten riders walk with 50 horses and 25 carts, carry 3554 GE:
|
||||||
|
local u1 = unit.create(f, r0, 10)
|
||||||
|
u1:set_skill("riding", 1)
|
||||||
|
u1:add_item("horse", 50)
|
||||||
|
u1:add_item("cart", 25)
|
||||||
|
u1:add_item("money", 355400)
|
||||||
|
u1:add_order("NACH O O O")
|
||||||
|
|
||||||
|
process_orders()
|
||||||
|
assert_equal(r1, u1.region)
|
||||||
|
end
|
||||||
|
|
||||||
|
function test_trolls_pull_carts()
|
||||||
|
local r0 = region.create(0, 0, "plain")
|
||||||
|
local r1 = region.create(1, 0, "plain")
|
||||||
|
local r2 = region.create(2, 0, "plain")
|
||||||
|
local r3 = region.create(3, 0, "plain")
|
||||||
|
local f = faction.create("troll")
|
||||||
|
-- 1. 20 trolls can pull 5 loaded carts:
|
||||||
|
local u1 = unit.create(f, r0, 20)
|
||||||
|
u1:add_item("cart", 5)
|
||||||
|
-- trolls carry 10.8 GE, carts carry 100 GE:
|
||||||
|
u1:add_item("money", 100 * (5 * 100 + 2 * 108))
|
||||||
|
u1:add_order("NACH O O O")
|
||||||
|
|
||||||
|
process_orders()
|
||||||
|
assert_equal(r1, u1.region)
|
||||||
|
|
||||||
|
u1:add_item("money", 1) -- just one wafer thin mint
|
||||||
|
process_orders()
|
||||||
|
assert_equal(r1, u1.region)
|
||||||
|
end
|
|
@ -1,4 +1,4 @@
|
||||||
require 'tests.e2.horses'
|
require 'tests.e2.carts'
|
||||||
require 'tests.e2.quit'
|
require 'tests.e2.quit'
|
||||||
require 'tests.e2.movement'
|
require 'tests.e2.movement'
|
||||||
require 'tests.e2.astral'
|
require 'tests.e2.astral'
|
||||||
|
|
|
@ -134,63 +134,3 @@ function assert_capacity(text, u, silver, r1, r2, rx)
|
||||||
process_orders()
|
process_orders()
|
||||||
assert_equal(rx, u.region, text .. "unit should not move")
|
assert_equal(rx, u.region, text .. "unit should not move")
|
||||||
end
|
end
|
||||||
|
|
||||||
function test_dwarf_example()
|
|
||||||
local r1 = region.create(0, 0, "plain")
|
|
||||||
local r2 = region.create(1, 0, "plain")
|
|
||||||
region.create(2, 0, "plain")
|
|
||||||
local f = faction.create("dwarf", "dwarf@example.com", "de")
|
|
||||||
local u = unit.create(f, r1, 5)
|
|
||||||
u:add_item("horse", 5)
|
|
||||||
u:add_item("cart", 2)
|
|
||||||
|
|
||||||
-- 5 dwarves + 5 horse - 2 carts = 27 + 100 - 80 = 47.00
|
|
||||||
assert_capacity("dwarves", u, 4700, r1, r2)
|
|
||||||
|
|
||||||
u:set_skill("riding", 3)
|
|
||||||
assert_equal(1, u:eff_skill("riding"))
|
|
||||||
-- 5 dwarves + 5 horses + 2 carts = 327.00
|
|
||||||
assert_capacity("riding", u, 32700, r1, r2)
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
function test_troll_example()
|
|
||||||
local r1 = region.create(0, 0, "plain")
|
|
||||||
local r2 = region.create(1, 0, "plain")
|
|
||||||
local r3 = region.create(2, 0, "plain")
|
|
||||||
local f = faction.create("troll", "troll@example.com", "de")
|
|
||||||
local u1 = unit.create(f, r1, 3)
|
|
||||||
|
|
||||||
u1:add_item("cart", 1)
|
|
||||||
u1:clear_orders()
|
|
||||||
|
|
||||||
-- 3 trolls - 1 cart = 320, but not allowed?
|
|
||||||
u1.name='XXX'
|
|
||||||
assert_nomove("3 trolls", u1)
|
|
||||||
|
|
||||||
u1.number = 4
|
|
||||||
|
|
||||||
-- 4 trolls + 1 cart = 14320
|
|
||||||
assert_capacity("1 cart", u1, 14320, r1, r2)
|
|
||||||
|
|
||||||
|
|
||||||
u1:add_item("horse", 4)
|
|
||||||
-- 4 horses, 4 trolls, 1 cart
|
|
||||||
assert_capacity("4 horses", u1, 22320, r1, r2)
|
|
||||||
|
|
||||||
|
|
||||||
u1:add_item("cart", 1)
|
|
||||||
|
|
||||||
-- 4 horses + 4 trolls + 1 cart - 1 cart
|
|
||||||
assert_capacity("2 carts", u1, 18320, r1, r2)
|
|
||||||
|
|
||||||
u1:set_skill("riding", 3)
|
|
||||||
assert_equal(1, u1:eff_skill("riding"))
|
|
||||||
|
|
||||||
-- 4 horses + 4 trolls + 2 carts = 323.20
|
|
||||||
assert_capacity("walking", u1, 32320, r1, r2)
|
|
||||||
|
|
||||||
-- 4 horses + 2 carts - 4 trolls = 200.00
|
|
||||||
assert_capacity("riding", u1, 20000, r1, r3, r2)
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
5500
src/battle.c
5500
src/battle.c
File diff suppressed because it is too large
Load Diff
|
@ -272,7 +272,7 @@ static int tolua_faction_debug_messages(lua_State * L)
|
||||||
}
|
}
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
for (ml = self->msgs->begin; ml; ml = ml->next, ++i) {
|
for (ml = self->msgs->begin; ml; ml = ml->next, ++i) {
|
||||||
char buf[80];
|
char buf[120];
|
||||||
nr_render(ml->msg, default_locale, buf, sizeof(buf), NULL);
|
nr_render(ml->msg, default_locale, buf, sizeof(buf), NULL);
|
||||||
puts(buf);
|
puts(buf);
|
||||||
}
|
}
|
||||||
|
|
25
src/move.c
25
src/move.c
|
@ -258,6 +258,14 @@ get_transporters(const item * itm, int *p_animals, int *p_acap, int *p_vehicles,
|
||||||
*p_acap = acap;
|
*p_acap = acap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int walking_horse_limit(const unit *u, int skill) {
|
||||||
|
return (1 + skill * 4) * u->number;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int riding_horse_limit(const unit *u, int skill) {
|
||||||
|
return skill * 2 * u->number;
|
||||||
|
}
|
||||||
|
|
||||||
static int ridingcapacity(const unit * u)
|
static int ridingcapacity(const unit * u)
|
||||||
{
|
{
|
||||||
int vehicles = 0, vcap = 0;
|
int vehicles = 0, vcap = 0;
|
||||||
|
@ -270,7 +278,7 @@ static int ridingcapacity(const unit * u)
|
||||||
** tragen nichts (siehe walkingcapacity). Ein Wagen zaehlt nur, wenn er
|
** tragen nichts (siehe walkingcapacity). Ein Wagen zaehlt nur, wenn er
|
||||||
** von zwei Pferden gezogen wird */
|
** von zwei Pferden gezogen wird */
|
||||||
|
|
||||||
horses = effskill(u, SK_RIDING, NULL) * u->number * 2;
|
horses = riding_horse_limit(u, effskill(u, SK_RIDING, NULL));
|
||||||
if (animals > horses) animals = horses;
|
if (animals > horses) animals = horses;
|
||||||
|
|
||||||
if (fval(u_race(u), RCF_HORSE))
|
if (fval(u_race(u), RCF_HORSE))
|
||||||
|
@ -297,7 +305,7 @@ int walkingcapacity(const struct unit *u)
|
||||||
/* Das Gewicht, welches die Pferde tragen, plus das Gewicht, welches
|
/* Das Gewicht, welches die Pferde tragen, plus das Gewicht, welches
|
||||||
* die Leute tragen */
|
* die Leute tragen */
|
||||||
|
|
||||||
horses = effskill(u, SK_RIDING, NULL) * u->number * 4;
|
horses = walking_horse_limit(u, effskill(u, SK_RIDING, NULL));
|
||||||
pferde_fuer_wagen = (animals < horses) ? animals : horses;
|
pferde_fuer_wagen = (animals < horses) ? animals : horses;
|
||||||
if (fval(u_race(u), RCF_HORSE)) {
|
if (fval(u_race(u), RCF_HORSE)) {
|
||||||
animals += u->number;
|
animals += u->number;
|
||||||
|
@ -366,7 +374,6 @@ static int canwalk(unit * u)
|
||||||
int maxwagen, maxpferde;
|
int maxwagen, maxpferde;
|
||||||
int vehicles = 0, vcap = 0;
|
int vehicles = 0, vcap = 0;
|
||||||
int animals = 0, acap = 0;
|
int animals = 0, acap = 0;
|
||||||
int effsk;
|
|
||||||
/* workaround: monsters are too stupid to drop items, therefore they have
|
/* workaround: monsters are too stupid to drop items, therefore they have
|
||||||
* infinite carrying capacity */
|
* infinite carrying capacity */
|
||||||
|
|
||||||
|
@ -375,13 +382,12 @@ static int canwalk(unit * u)
|
||||||
|
|
||||||
get_transporters(u->items, &animals, &acap, &vehicles, &vcap);
|
get_transporters(u->items, &animals, &acap, &vehicles, &vcap);
|
||||||
|
|
||||||
effsk = effskill(u, SK_RIDING, NULL);
|
maxpferde = walking_horse_limit(u, effskill(u, SK_RIDING, NULL));
|
||||||
maxwagen = effsk * u->number * 2;
|
maxwagen = maxpferde / 2;
|
||||||
if (u_race(u) == get_race(RC_TROLL)) {
|
if (u_race(u) == get_race(RC_TROLL)) {
|
||||||
int trolls = u->number / 4;
|
int trolls = u->number / 4;
|
||||||
if (maxwagen > trolls) maxwagen = trolls;
|
if (maxwagen < trolls) maxwagen = trolls;
|
||||||
}
|
}
|
||||||
maxpferde = effsk * u->number * 4 + u->number;
|
|
||||||
|
|
||||||
if (animals > maxpferde)
|
if (animals > maxpferde)
|
||||||
return E_CANWALK_TOOMANYHORSES;
|
return E_CANWALK_TOOMANYHORSES;
|
||||||
|
@ -440,7 +446,7 @@ bool canswim(unit * u)
|
||||||
static int walk_mode(const unit * u)
|
static int walk_mode(const unit * u)
|
||||||
{
|
{
|
||||||
int horses = 0, maxhorses, unicorns = 0, maxunicorns;
|
int horses = 0, maxhorses, unicorns = 0, maxunicorns;
|
||||||
int skill = effskill(u, SK_RIDING, NULL);
|
int skill;
|
||||||
item *itm;
|
item *itm;
|
||||||
const item_type *it_horse, *it_elvenhorse, *it_charger;
|
const item_type *it_horse, *it_elvenhorse, *it_charger;
|
||||||
const resource_type *rtype;
|
const resource_type *rtype;
|
||||||
|
@ -458,8 +464,9 @@ static int walk_mode(const unit * u)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
skill = effskill(u, SK_RIDING, NULL);
|
||||||
maxunicorns = (skill / 5) * u->number;
|
maxunicorns = (skill / 5) * u->number;
|
||||||
maxhorses = skill * u->number * 2;
|
maxhorses = riding_horse_limit(u, skill);
|
||||||
|
|
||||||
if (!(u_race(u)->flags & RCF_HORSE)
|
if (!(u_race(u)->flags & RCF_HORSE)
|
||||||
&& ((horses == 0 && unicorns == 0)
|
&& ((horses == 0 && unicorns == 0)
|
||||||
|
|
Loading…
Reference in New Issue