forked from github/server
LUA:
- Schiffe können erzeugt und Einheiten zugewiesen werden. Reichweiten-Bug (http://eressea.upb.de/mantis/view.php?id=339) evtl. gefixt, cap_route war evtl. einen zu lang.
This commit is contained in:
parent
7beb84acb4
commit
e60e14930e
|
@ -1031,12 +1031,11 @@ cap_route(region * r, region_list * route, region_list * route_end, int speed)
|
|||
region * next = iroute->data;
|
||||
direction_t reldir = reldirection(current, next);
|
||||
|
||||
iroute = iroute->next;
|
||||
|
||||
/* adjust the range of the unit */
|
||||
if (roadto(current, reldir)) moves -= BP_ROAD;
|
||||
else moves -= BP_NORMAL;
|
||||
if (moves<0) break;
|
||||
iroute = iroute->next;
|
||||
current = next;
|
||||
}
|
||||
return iroute;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include <eressea.h>
|
||||
|
||||
// kernel includes
|
||||
#include <build.h>
|
||||
#include <ship.h>
|
||||
#include <region.h>
|
||||
|
||||
|
@ -34,11 +35,21 @@ operator==(const ship& a, const ship& sh)
|
|||
return a.no==sh.no;
|
||||
}
|
||||
|
||||
static ship *
|
||||
add_ship(const char * sname, region& r)
|
||||
{
|
||||
const ship_type * stype = st_find(sname);
|
||||
ship * sh = new_ship(stype, NULL, &r);
|
||||
sh->size = stype->construction->maxsize;
|
||||
return sh;
|
||||
}
|
||||
|
||||
void
|
||||
bind_ship(lua_State * L)
|
||||
{
|
||||
module(L)[
|
||||
def("get_ship", &findship),
|
||||
def("add_ship", &add_ship),
|
||||
|
||||
class_<struct ship>("ship")
|
||||
.def(self == ship())
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include <kernel/order.h>
|
||||
#include <kernel/race.h>
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/ship.h>
|
||||
#include <kernel/skill.h>
|
||||
#include <kernel/spell.h>
|
||||
#include <kernel/unit.h>
|
||||
|
@ -250,10 +251,29 @@ unit_getregion(const unit& u)
|
|||
return u.region;
|
||||
}
|
||||
|
||||
static void
|
||||
unit_setship(unit& u, ship& s)
|
||||
{
|
||||
leave(u.region, &u);
|
||||
if (u.region!=s.region) {
|
||||
unit_setregion(u, *s.region);
|
||||
}
|
||||
u.ship = &s;
|
||||
}
|
||||
|
||||
static ship *
|
||||
unit_getship(const unit& u)
|
||||
{
|
||||
return u.ship;
|
||||
}
|
||||
|
||||
static void
|
||||
unit_setbuilding(unit& u, building& b)
|
||||
{
|
||||
leave(u.region, &u);
|
||||
if (u.region!=b.region) {
|
||||
unit_setregion(u, *b.region);
|
||||
}
|
||||
u.building = &b;
|
||||
}
|
||||
|
||||
|
@ -538,6 +558,7 @@ bind_unit(lua_State * L)
|
|||
.property("magic", &unit_getmagic, &unit_setmagic)
|
||||
.property("aura", &unit_getaura, &unit_setaura)
|
||||
.property("building", &unit_getbuilding, &unit_setbuilding)
|
||||
.property("ship", &unit_getship, &unit_setship)
|
||||
.property("region", &unit_getregion, &unit_setregion)
|
||||
.property("is_familiar", &unit_isfamiliar)
|
||||
.property("spells", &unit_spells, return_stl_iterator)
|
||||
|
|
|
@ -144,7 +144,7 @@ static int nowrite = 0;
|
|||
static boolean g_writemap = false;
|
||||
static boolean opt_reportonly = false;
|
||||
static const char * luafile = "default.lua";
|
||||
static const char * script_path = NULL;
|
||||
static const char * script_path = "scripts";
|
||||
|
||||
struct settings global = {
|
||||
"Eressea", /* gamename */
|
||||
|
|
|
@ -1,24 +1,20 @@
|
|||
function test_sail()
|
||||
r0 = terraform(0, 0, "plain")
|
||||
|
||||
orcs = add_faction("enno@eressea.de", "orc", "de")
|
||||
orcs.age = 20
|
||||
|
||||
orc = add_unit(orcs, r0)
|
||||
orc.number = 1
|
||||
orc:add_item("speedsail", orc.number)
|
||||
|
||||
orc:clear_orders()
|
||||
orc:add_order("NUMMER PARTEI orcs")
|
||||
orc:add_order("NUMMER EINHEIT orc")
|
||||
orc:add_order("BENENNE EINHEIT Orks")
|
||||
orc:add_order("ZEIGEN \"Sonnensegel\"")
|
||||
function mkunit(f, r, num)
|
||||
u = add_unit(f, r)
|
||||
u.number = num
|
||||
u:add_item("money", num*10)
|
||||
return u
|
||||
end
|
||||
|
||||
function test_movement()
|
||||
west = direction("west")
|
||||
east = direction("east")
|
||||
|
||||
-- im westen ohne strassen
|
||||
ocean = terraform(-3, 0, "ocean")
|
||||
terraform(-2, 0, "plain")
|
||||
terraform(-1, 0, "plain")
|
||||
|
||||
-- im osten mit strassen
|
||||
r0 = terraform(0, 0, "plain")
|
||||
r1 = terraform(1, 0, "desert")
|
||||
r2 = terraform(2, 0, "glacier")
|
||||
|
@ -37,18 +33,28 @@ function test_movement()
|
|||
orcs = add_faction("enno@eressea.de", "orc", "de")
|
||||
orcs.age = 20
|
||||
|
||||
orc = add_unit(orcs, r0)
|
||||
orc.number = 10
|
||||
orc:add_item("money", orc.number*10)
|
||||
orc:add_item("horse", orc.number*3)
|
||||
orc:set_skill("sk_riding", 10)
|
||||
|
||||
bugs = add_faction("enno@eressea.de", "insect", "de")
|
||||
bugs.age = 20
|
||||
|
||||
bug = add_unit(bugs, r0)
|
||||
bug.number = 1
|
||||
bug:add_item("money", bug.number*10)
|
||||
orc = mkunit(orcs, r0, 10)
|
||||
orc:add_item("horse", orc.number*3)
|
||||
orc:set_skill("sk_riding", 10)
|
||||
|
||||
foot = mkunit(orcs, r0, 1)
|
||||
|
||||
ship = add_ship("boat", r0)
|
||||
sail = mkunit(orcs, r0, 1)
|
||||
sail.ship = ship
|
||||
|
||||
bug = mkunit(bugs, r0, 1)
|
||||
|
||||
sail:clear_orders()
|
||||
sail:add_order("NACH O")
|
||||
sail:add_order("NUMMER EINHEIT saiL")
|
||||
|
||||
foot:clear_orders()
|
||||
foot:add_order("ROUTE W W")
|
||||
foot:add_order("NUMMER EINHEIT foot")
|
||||
|
||||
orc:clear_orders()
|
||||
orc:add_order("NUMMER PARTEI orcs")
|
||||
|
@ -93,6 +99,23 @@ function test_movement()
|
|||
end
|
||||
|
||||
|
||||
function test_sail()
|
||||
r0 = terraform(0, 0, "plain")
|
||||
|
||||
orcs = add_faction("enno@eressea.de", "orc", "de")
|
||||
orcs.age = 20
|
||||
|
||||
orc = add_unit(orcs, r0)
|
||||
orc.number = 1
|
||||
orc:add_item("speedsail", orc.number)
|
||||
|
||||
orc:clear_orders()
|
||||
orc:add_order("NUMMER PARTEI orcs")
|
||||
orc:add_order("NUMMER EINHEIT orc")
|
||||
orc:add_order("BENENNE EINHEIT Orks")
|
||||
orc:add_order("ZEIGEN \"Sonnensegel\"")
|
||||
end
|
||||
|
||||
function test_handler()
|
||||
|
||||
local function msg_handler(u, evt)
|
||||
|
@ -323,7 +346,12 @@ end
|
|||
-- test_give()
|
||||
-- test_write()
|
||||
|
||||
test_sail()
|
||||
-- test_sail()
|
||||
-- write_game("../testg.txt")
|
||||
-- read_game("../testg.txt")
|
||||
|
||||
test_movement()
|
||||
run_scripts()
|
||||
process_orders()
|
||||
write_reports()
|
||||
|
||||
|
|
Loading…
Reference in New Issue