forked from github/server
Merge pull request #877 from ennorehling/develop
use format_list for schemes
This commit is contained in:
commit
c3bb1ea1a5
2
clibs
2
clibs
|
@ -1 +1 @@
|
||||||
Subproject commit f8969f44de1ec413cfee82b23c9f4b3c32d49b56
|
Subproject commit abe774f70265de14ea7f5e530518ca130562a9c9
|
|
@ -570,8 +570,20 @@ msgstr "Dieses Ritual, ausgeführt vor einem Kampf, verwirbelt die astralen Ener
|
||||||
msgid "balloon"
|
msgid "balloon"
|
||||||
msgstr "Ballon"
|
msgstr "Ballon"
|
||||||
|
|
||||||
msgid "nr_schemes_postfix"
|
msgid "nr_schemes_template"
|
||||||
msgstr "sind erkennbar."
|
msgstr "Schemen der Regionen {0} sind erkennbar."
|
||||||
|
|
||||||
|
msgid "list_two"
|
||||||
|
msgstr "{0} und {1}"
|
||||||
|
|
||||||
|
msgid "list_start"
|
||||||
|
msgstr "{0}, {1}"
|
||||||
|
|
||||||
|
msgid "list_middle"
|
||||||
|
msgstr "{0}, {1}"
|
||||||
|
|
||||||
|
msgid "list_end"
|
||||||
|
msgstr "{0} und {1}"
|
||||||
|
|
||||||
msgid "SILBER"
|
msgid "SILBER"
|
||||||
msgstr "SILBER"
|
msgstr "SILBER"
|
||||||
|
@ -4408,9 +4420,6 @@ msgstr "Magie"
|
||||||
msgid "see_lighthouse"
|
msgid "see_lighthouse"
|
||||||
msgstr "vom Turm erblickt"
|
msgstr "vom Turm erblickt"
|
||||||
|
|
||||||
msgid "nr_schemes_prefix"
|
|
||||||
msgstr "Schemen der Regionen"
|
|
||||||
|
|
||||||
msgid "aoc_p"
|
msgid "aoc_p"
|
||||||
msgstr "Katzenamulette"
|
msgstr "Katzenamulette"
|
||||||
|
|
||||||
|
|
|
@ -444,9 +444,6 @@ msgctxt "spellinfo"
|
||||||
msgid "draigfumbleshield"
|
msgid "draigfumbleshield"
|
||||||
msgstr "This ritual, performed before a battle, causes the astral energies on the battlefield to whirl and churn and thereby makes spellcasting more difficult for the enemy mages."
|
msgstr "This ritual, performed before a battle, causes the astral energies on the battlefield to whirl and churn and thereby makes spellcasting more difficult for the enemy mages."
|
||||||
|
|
||||||
msgid "nr_schemes_postfix"
|
|
||||||
msgstr "can be discerned."
|
|
||||||
|
|
||||||
msgid "SILBER"
|
msgid "SILBER"
|
||||||
msgstr "SILVER"
|
msgstr "SILVER"
|
||||||
|
|
||||||
|
@ -3937,8 +3934,20 @@ msgstr "magic"
|
||||||
msgid "see_lighthouse"
|
msgid "see_lighthouse"
|
||||||
msgstr "from lighthouse"
|
msgstr "from lighthouse"
|
||||||
|
|
||||||
msgid "nr_schemes_prefix"
|
msgid "list_two"
|
||||||
msgstr "Schemes of "
|
msgstr "{0} and {1}"
|
||||||
|
|
||||||
|
msgid "list_start"
|
||||||
|
msgstr "{0}, {1}"
|
||||||
|
|
||||||
|
msgid "list_middle"
|
||||||
|
msgstr "{0}, {1}"
|
||||||
|
|
||||||
|
msgid "list_end"
|
||||||
|
msgstr "{0}, and {1}"
|
||||||
|
|
||||||
|
msgid "nr_schemes_template"
|
||||||
|
msgstr "Schemes of {0} can be discerned."
|
||||||
|
|
||||||
msgid "aoc_p"
|
msgid "aoc_p"
|
||||||
msgstr "amulets of the kitten"
|
msgstr "amulets of the kitten"
|
||||||
|
|
|
@ -0,0 +1,76 @@
|
||||||
|
require 'config'
|
||||||
|
|
||||||
|
eressea.read_game('1137.dat')
|
||||||
|
|
||||||
|
local dead = {"cwz", "rama"}
|
||||||
|
|
||||||
|
|
||||||
|
local function list_items(f)
|
||||||
|
local items = {}
|
||||||
|
for u in f.units do
|
||||||
|
local r = u.region
|
||||||
|
for name in u.items do
|
||||||
|
local count = u:get_item(name)
|
||||||
|
if not items[r.id] then
|
||||||
|
items[r.id] = {}
|
||||||
|
end
|
||||||
|
if not items[r.id][name] then
|
||||||
|
items[r.id][name] = count
|
||||||
|
else
|
||||||
|
items[r.id][name] = items[r.id][name] + count
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return items
|
||||||
|
end
|
||||||
|
|
||||||
|
gifts = {}
|
||||||
|
info = {}
|
||||||
|
|
||||||
|
for _, no in ipairs(dead) do
|
||||||
|
f = get_faction(no)
|
||||||
|
gifts[f.id] = list_items(f)
|
||||||
|
local allies = {}
|
||||||
|
for fno, as in pairs(f.allies) do
|
||||||
|
local f2 = get_faction(fno)
|
||||||
|
if f2:get_ally(f, 'give') then
|
||||||
|
allies[fno] = as
|
||||||
|
end
|
||||||
|
end
|
||||||
|
info[f.id] = {
|
||||||
|
['name'] = f.name,
|
||||||
|
['race'] = f.race,
|
||||||
|
['allies'] = allies
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
eressea.free_game()
|
||||||
|
eressea.read_game('1138.dat')
|
||||||
|
|
||||||
|
newf = {}
|
||||||
|
|
||||||
|
for fid, rlist in pairs(gifts) do
|
||||||
|
local name = "Erben von " .. info[fid].name
|
||||||
|
local race = info[fid].race
|
||||||
|
local f = faction.create(race, "noreply@eressea.de")
|
||||||
|
f.name = name
|
||||||
|
f.age = 10
|
||||||
|
f.lastturn = 1130
|
||||||
|
table.insert(newf, f)
|
||||||
|
for rid, items in pairs(rlist) do
|
||||||
|
local r = get_region_by_id(rid)
|
||||||
|
local u = unit.create(f, r, 1)
|
||||||
|
for name, count in pairs(items) do
|
||||||
|
u:add_item(name, count)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
for fno, as in pairs(info[fid].allies) do
|
||||||
|
local f2 = get_faction(fno)
|
||||||
|
for _, s in ipairs(as) do
|
||||||
|
f:set_ally(f2, s)
|
||||||
|
end
|
||||||
|
f2:set_ally(f, "give")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
eressea.write_game('1138.new.dat')
|
|
@ -0,0 +1,30 @@
|
||||||
|
require "lunit"
|
||||||
|
|
||||||
|
module("tests.e2.allies", package.seeall, lunit.testcase)
|
||||||
|
|
||||||
|
function skip_test_get_set_ally()
|
||||||
|
local f1 = faction.create("human")
|
||||||
|
local f2 = faction.create("human")
|
||||||
|
|
||||||
|
assert_equal(false, f1:get_ally(f2, "guard"))
|
||||||
|
f1:set_ally(f2, "guard", true)
|
||||||
|
assert_equal(true, f1:get_ally(f2, "guard"))
|
||||||
|
assert_equal(false, f1:get_ally(f2, "give"))
|
||||||
|
f1:set_ally(f2, "give", true)
|
||||||
|
assert_equal(true, f1:get_ally(f2, "give"))
|
||||||
|
end
|
||||||
|
|
||||||
|
function test_get_allies()
|
||||||
|
local f1 = faction.create("human")
|
||||||
|
local f2 = faction.create("human")
|
||||||
|
|
||||||
|
local allies = f1.allies
|
||||||
|
assert_equal('table', type(allies))
|
||||||
|
assert_equal(0, #allies)
|
||||||
|
f1:set_ally(f2, "give", true)
|
||||||
|
allies = f1.allies
|
||||||
|
assert_not_nil(allies[f2.id])
|
||||||
|
assert_equal('table', type(allies[f2.id]))
|
||||||
|
assert_equal(1, #allies[f2.id])
|
||||||
|
assert_equal("give", allies[f2.id][1])
|
||||||
|
end
|
|
@ -185,3 +185,50 @@ function test_trolls_pull_carts()
|
||||||
process_orders()
|
process_orders()
|
||||||
assert_equal(r1, u1.region)
|
assert_equal(r1, u1.region)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function test_trolls_with_horses()
|
||||||
|
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("horse", 20)
|
||||||
|
u1:add_item("money", 100 * 20 * 20)
|
||||||
|
process_orders()
|
||||||
|
assert_equal(r2, u1.region)
|
||||||
|
end
|
||||||
|
|
||||||
|
function test_trolls_ride_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 r4 = region.create(4, 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)
|
||||||
|
-- but with 10 or more horses, they should ride in the cart:
|
||||||
|
u1:set_skill("riding", 1, true)
|
||||||
|
u1:add_item("horse", 10)
|
||||||
|
-- trolls weigh 20 GE, horses carry 20, carts carry 100 GE:
|
||||||
|
u1:add_item("money", 100 * (10 * 20 + 5 * 100 - u1.number * 20))
|
||||||
|
u1:add_order("NACH O O O")
|
||||||
|
|
||||||
|
process_orders()
|
||||||
|
assert_equal(r2, u1.region)
|
||||||
|
|
||||||
|
u1:add_item("money", 1) -- just one wafer thin mint
|
||||||
|
process_orders()
|
||||||
|
assert_equal(r3, u1.region) -- can still walk
|
||||||
|
end
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
require 'tests.e2.carts'
|
require 'tests.e2.carts'
|
||||||
require 'tests.e2.quit'
|
require 'tests.e2.allies'
|
||||||
require 'tests.e2.movement'
|
require 'tests.e2.movement'
|
||||||
require 'tests.e2.astral'
|
require 'tests.e2.astral'
|
||||||
require 'tests.e2.spells'
|
require 'tests.e2.spells'
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include "bindings.h"
|
#include "bindings.h"
|
||||||
#include "magic.h"
|
#include "magic.h"
|
||||||
|
|
||||||
|
#include <kernel/ally.h>
|
||||||
#include <kernel/alliance.h>
|
#include <kernel/alliance.h>
|
||||||
#include <kernel/faction.h>
|
#include <kernel/faction.h>
|
||||||
#include <kernel/unit.h>
|
#include <kernel/unit.h>
|
||||||
|
@ -31,7 +32,10 @@
|
||||||
#include <lauxlib.h>
|
#include <lauxlib.h>
|
||||||
#include <tolua.h>
|
#include <tolua.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdbool.h> // for bool
|
||||||
|
#include <stdio.h> // for puts
|
||||||
|
|
||||||
|
struct allies;
|
||||||
|
|
||||||
int tolua_factionlist_next(lua_State * L)
|
int tolua_factionlist_next(lua_State * L)
|
||||||
{
|
{
|
||||||
|
@ -48,13 +52,13 @@ int tolua_factionlist_next(lua_State * L)
|
||||||
|
|
||||||
static int tolua_faction_get_units(lua_State * L)
|
static int tolua_faction_get_units(lua_State * L)
|
||||||
{
|
{
|
||||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
faction *f = (faction *)tolua_tousertype(L, 1, NULL);
|
||||||
unit **unit_ptr = (unit **)lua_newuserdata(L, sizeof(unit *));
|
unit **unit_ptr = (unit **)lua_newuserdata(L, sizeof(unit *));
|
||||||
|
|
||||||
luaL_getmetatable(L, TOLUA_CAST "unit");
|
luaL_getmetatable(L, TOLUA_CAST "unit");
|
||||||
lua_setmetatable(L, -2);
|
lua_setmetatable(L, -2);
|
||||||
|
|
||||||
*unit_ptr = self->units;
|
*unit_ptr = f->units;
|
||||||
|
|
||||||
lua_pushcclosure(L, tolua_unitlist_nextf, 1);
|
lua_pushcclosure(L, tolua_unitlist_nextf, 1);
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -62,7 +66,7 @@ static int tolua_faction_get_units(lua_State * L)
|
||||||
|
|
||||||
int tolua_faction_add_item(lua_State * L)
|
int tolua_faction_add_item(lua_State * L)
|
||||||
{
|
{
|
||||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
faction *f = (faction *)tolua_tousertype(L, 1, NULL);
|
||||||
const char *iname = tolua_tostring(L, 2, NULL);
|
const char *iname = tolua_tostring(L, 2, NULL);
|
||||||
int number = (int)tolua_tonumber(L, 3, 0);
|
int number = (int)tolua_tonumber(L, 3, 0);
|
||||||
int result = -1;
|
int result = -1;
|
||||||
|
@ -70,7 +74,7 @@ int tolua_faction_add_item(lua_State * L)
|
||||||
if (iname != NULL) {
|
if (iname != NULL) {
|
||||||
const resource_type *rtype = rt_find(iname);
|
const resource_type *rtype = rt_find(iname);
|
||||||
if (rtype && rtype->itype) {
|
if (rtype && rtype->itype) {
|
||||||
item *i = i_change(&self->items, rtype->itype, number);
|
item *i = i_change(&f->items, rtype->itype, number);
|
||||||
result = i ? i->number : 0;
|
result = i ? i->number : 0;
|
||||||
} /* if (itype!=NULL) */
|
} /* if (itype!=NULL) */
|
||||||
}
|
}
|
||||||
|
@ -80,38 +84,38 @@ int tolua_faction_add_item(lua_State * L)
|
||||||
|
|
||||||
static int tolua_faction_get_maxheroes(lua_State * L)
|
static int tolua_faction_get_maxheroes(lua_State * L)
|
||||||
{
|
{
|
||||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
faction *f = (faction *)tolua_tousertype(L, 1, NULL);
|
||||||
lua_pushinteger(L, maxheroes(self));
|
lua_pushinteger(L, maxheroes(f));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_faction_get_heroes(lua_State * L)
|
static int tolua_faction_get_heroes(lua_State * L)
|
||||||
{
|
{
|
||||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
faction *f = (faction *)tolua_tousertype(L, 1, NULL);
|
||||||
lua_pushinteger(L, countheroes(self));
|
lua_pushinteger(L, countheroes(f));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_faction_get_score(lua_State * L)
|
static int tolua_faction_get_score(lua_State * L)
|
||||||
{
|
{
|
||||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
faction *f = (faction *)tolua_tousertype(L, 1, NULL);
|
||||||
lua_pushnumber(L, (lua_Number)self->score);
|
lua_pushnumber(L, (lua_Number)f->score);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_faction_get_id(lua_State * L)
|
static int tolua_faction_get_id(lua_State * L)
|
||||||
{
|
{
|
||||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
faction *f = (faction *)tolua_tousertype(L, 1, NULL);
|
||||||
lua_pushinteger(L, self->no);
|
lua_pushinteger(L, f->no);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_faction_set_id(lua_State * L)
|
static int tolua_faction_set_id(lua_State * L)
|
||||||
{
|
{
|
||||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
faction *f = (faction *)tolua_tousertype(L, 1, NULL);
|
||||||
int id = (int)tolua_tonumber(L, 2, 0);
|
int id = (int)tolua_tonumber(L, 2, 0);
|
||||||
if (findfaction(id) == NULL) {
|
if (findfaction(id) == NULL) {
|
||||||
renumber_faction(self, id);
|
renumber_faction(f, id);
|
||||||
lua_pushboolean(L, 1);
|
lua_pushboolean(L, 1);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -122,20 +126,20 @@ static int tolua_faction_set_id(lua_State * L)
|
||||||
|
|
||||||
static int tolua_faction_get_magic(lua_State * L)
|
static int tolua_faction_get_magic(lua_State * L)
|
||||||
{
|
{
|
||||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
faction *f = (faction *)tolua_tousertype(L, 1, NULL);
|
||||||
lua_pushstring(L, magic_school[self->magiegebiet]);
|
lua_pushstring(L, magic_school[f->magiegebiet]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_faction_set_magic(lua_State * L)
|
static int tolua_faction_set_magic(lua_State * L)
|
||||||
{
|
{
|
||||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
faction *f = (faction *)tolua_tousertype(L, 1, NULL);
|
||||||
const char *type = tolua_tostring(L, 2, NULL);
|
const char *type = tolua_tostring(L, 2, NULL);
|
||||||
int mtype;
|
int mtype;
|
||||||
|
|
||||||
for (mtype = 0; mtype != MAXMAGIETYP; ++mtype) {
|
for (mtype = 0; mtype != MAXMAGIETYP; ++mtype) {
|
||||||
if (strcmp(magic_school[mtype], type) == 0) {
|
if (strcmp(magic_school[mtype], type) == 0) {
|
||||||
self->magiegebiet = (magic_t)mtype;
|
f->magiegebiet = (magic_t)mtype;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -144,89 +148,89 @@ static int tolua_faction_set_magic(lua_State * L)
|
||||||
|
|
||||||
static int tolua_faction_get_age(lua_State * L)
|
static int tolua_faction_get_age(lua_State * L)
|
||||||
{
|
{
|
||||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
faction *f = (faction *)tolua_tousertype(L, 1, NULL);
|
||||||
lua_pushinteger(L, self->age);
|
lua_pushinteger(L, f->age);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_faction_set_age(lua_State * L)
|
static int tolua_faction_set_age(lua_State * L)
|
||||||
{
|
{
|
||||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
faction *f = (faction *)tolua_tousertype(L, 1, NULL);
|
||||||
int age = (int)tolua_tonumber(L, 2, 0);
|
int age = (int)tolua_tonumber(L, 2, 0);
|
||||||
self->age = age;
|
f->age = age;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_faction_get_flags(lua_State * L)
|
static int tolua_faction_get_flags(lua_State * L)
|
||||||
{
|
{
|
||||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
faction *f = (faction *)tolua_tousertype(L, 1, NULL);
|
||||||
lua_pushinteger(L, self->flags);
|
lua_pushinteger(L, f->flags);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_faction_set_flags(lua_State * L)
|
static int tolua_faction_set_flags(lua_State * L)
|
||||||
{
|
{
|
||||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
faction *f = (faction *)tolua_tousertype(L, 1, NULL);
|
||||||
int flags = (int)tolua_tonumber(L, 2, self->flags);
|
int flags = (int)tolua_tonumber(L, 2, f->flags);
|
||||||
self->flags = flags;
|
f->flags = flags;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_faction_get_options(lua_State * L)
|
static int tolua_faction_get_options(lua_State * L)
|
||||||
{
|
{
|
||||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
faction *f = (faction *)tolua_tousertype(L, 1, NULL);
|
||||||
lua_pushinteger(L, self->options);
|
lua_pushinteger(L, f->options);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_faction_set_options(lua_State * L)
|
static int tolua_faction_set_options(lua_State * L)
|
||||||
{
|
{
|
||||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
faction *f = (faction *)tolua_tousertype(L, 1, NULL);
|
||||||
int options = (int)tolua_tonumber(L, 2, self->options);
|
int options = (int)tolua_tonumber(L, 2, f->options);
|
||||||
self->options = options;
|
f->options = options;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_faction_get_lastturn(lua_State * L)
|
static int tolua_faction_get_lastturn(lua_State * L)
|
||||||
{
|
{
|
||||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
faction *f = (faction *)tolua_tousertype(L, 1, NULL);
|
||||||
lua_pushinteger(L, self->lastorders);
|
lua_pushinteger(L, f->lastorders);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_faction_set_lastturn(lua_State * L)
|
static int tolua_faction_set_lastturn(lua_State * L)
|
||||||
{
|
{
|
||||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
faction *f = (faction *)tolua_tousertype(L, 1, NULL);
|
||||||
if (self) {
|
if (f) {
|
||||||
self->lastorders = (int)tolua_tonumber(L, 2, self->lastorders);
|
f->lastorders = (int)tolua_tonumber(L, 2, f->lastorders);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_faction_renumber(lua_State * L)
|
static int tolua_faction_renumber(lua_State * L)
|
||||||
{
|
{
|
||||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
faction *f = (faction *)tolua_tousertype(L, 1, NULL);
|
||||||
int no = (int)tolua_tonumber(L, 2, 0);
|
int no = (int)tolua_tonumber(L, 2, 0);
|
||||||
|
|
||||||
renumber_faction(self, no);
|
renumber_faction(f, no);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_faction_addnotice(lua_State * L)
|
static int tolua_faction_addnotice(lua_State * L)
|
||||||
{
|
{
|
||||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
faction *f = (faction *)tolua_tousertype(L, 1, NULL);
|
||||||
const char *str = tolua_tostring(L, 2, NULL);
|
const char *str = tolua_tostring(L, 2, NULL);
|
||||||
|
|
||||||
addmessage(NULL, self, str, MSG_MESSAGE, ML_IMPORTANT);
|
addmessage(NULL, f, str, MSG_MESSAGE, ML_IMPORTANT);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_faction_getkey(lua_State * L)
|
static int tolua_faction_getkey(lua_State * L)
|
||||||
{
|
{
|
||||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
faction *f = (faction *)tolua_tousertype(L, 1, NULL);
|
||||||
const char *name = tolua_tostring(L, 2, NULL);
|
const char *name = tolua_tostring(L, 2, NULL);
|
||||||
int flag = atoi36(name);
|
int flag = atoi36(name);
|
||||||
int value = key_get(self->attribs, flag);
|
int value = key_get(f->attribs, flag);
|
||||||
if (value != 0) {
|
if (value != 0) {
|
||||||
lua_pushinteger(L, value);
|
lua_pushinteger(L, value);
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -236,16 +240,16 @@ static int tolua_faction_getkey(lua_State * L)
|
||||||
|
|
||||||
static int tolua_faction_setkey(lua_State * L)
|
static int tolua_faction_setkey(lua_State * L)
|
||||||
{
|
{
|
||||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
faction *f = (faction *)tolua_tousertype(L, 1, NULL);
|
||||||
const char *name = tolua_tostring(L, 2, NULL);
|
const char *name = tolua_tostring(L, 2, NULL);
|
||||||
int value = (int)tolua_tonumber(L, 3, 1);
|
int value = (int)tolua_tonumber(L, 3, 1);
|
||||||
int flag = atoi36(name);
|
int flag = atoi36(name);
|
||||||
|
|
||||||
if (value) {
|
if (value) {
|
||||||
key_set(&self->attribs, flag, value);
|
key_set(&f->attribs, flag, value);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
key_unset(&self->attribs, flag);
|
key_unset(&f->attribs, flag);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -269,14 +273,14 @@ static int tolua_faction_debug_messages(lua_State * L)
|
||||||
|
|
||||||
static int tolua_faction_get_messages(lua_State * L)
|
static int tolua_faction_get_messages(lua_State * L)
|
||||||
{
|
{
|
||||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
faction *f = (faction *)tolua_tousertype(L, 1, NULL);
|
||||||
int i = 1;
|
int i = 1;
|
||||||
mlist *ml;
|
mlist *ml;
|
||||||
if (!self->msgs) {
|
if (!f->msgs) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
for (ml = self->msgs->begin; ml; ml = ml->next, ++i) {
|
for (ml = f->msgs->begin; ml; ml = ml->next, ++i) {
|
||||||
lua_pushnumber(L, i);
|
lua_pushnumber(L, i);
|
||||||
lua_pushstring(L, ml->msg->type->name);
|
lua_pushstring(L, ml->msg->type->name);
|
||||||
lua_rawset(L, -3);
|
lua_rawset(L, -3);
|
||||||
|
@ -285,11 +289,11 @@ static int tolua_faction_get_messages(lua_State * L)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_faction_count_msg_type(lua_State *L) {
|
static int tolua_faction_count_msg_type(lua_State *L) {
|
||||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
faction *f = (faction *)tolua_tousertype(L, 1, NULL);
|
||||||
const char *str = tolua_tostring(L, 2, NULL);
|
const char *str = tolua_tostring(L, 2, NULL);
|
||||||
int n = 0;
|
int n = 0;
|
||||||
if (self->msgs) {
|
if (f->msgs) {
|
||||||
mlist * ml = self->msgs->begin;
|
mlist * ml = f->msgs->begin;
|
||||||
while (ml) {
|
while (ml) {
|
||||||
if (strcmp(str, ml->msg->type->name) == 0) {
|
if (strcmp(str, ml->msg->type->name) == 0) {
|
||||||
++n;
|
++n;
|
||||||
|
@ -330,9 +334,9 @@ static int tolua_faction_set_origin(lua_State * L)
|
||||||
|
|
||||||
static int tolua_faction_get_origin(lua_State * L)
|
static int tolua_faction_get_origin(lua_State * L)
|
||||||
{
|
{
|
||||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
faction *f = (faction *)tolua_tousertype(L, 1, NULL);
|
||||||
int x = 0, y = 0;
|
int x = 0, y = 0;
|
||||||
faction_getorigin(self, 0, &x, &y);
|
faction_getorigin(f, 0, &x, &y);
|
||||||
|
|
||||||
lua_pushinteger(L, x);
|
lua_pushinteger(L, x);
|
||||||
lua_pushinteger(L, y);
|
lua_pushinteger(L, y);
|
||||||
|
@ -380,48 +384,48 @@ static int tolua_faction_create(lua_State * L)
|
||||||
|
|
||||||
static int tolua_faction_get_password(lua_State * L)
|
static int tolua_faction_get_password(lua_State * L)
|
||||||
{
|
{
|
||||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
faction *f = (faction *)tolua_tousertype(L, 1, NULL);
|
||||||
tolua_pushstring(L, faction_getpassword(self));
|
tolua_pushstring(L, faction_getpassword(f));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_faction_set_password(lua_State * L)
|
static int tolua_faction_set_password(lua_State * L)
|
||||||
{
|
{
|
||||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
faction *f = (faction *)tolua_tousertype(L, 1, NULL);
|
||||||
const char * passw = tolua_tostring(L, 2, NULL);
|
const char * passw = tolua_tostring(L, 2, NULL);
|
||||||
faction_setpassword(self,
|
faction_setpassword(f,
|
||||||
passw ? password_hash(passw, PASSWORD_DEFAULT) : NULL);
|
passw ? password_hash(passw, PASSWORD_DEFAULT) : NULL);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_faction_get_email(lua_State * L)
|
static int tolua_faction_get_email(lua_State * L)
|
||||||
{
|
{
|
||||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
faction *f = (faction *)tolua_tousertype(L, 1, NULL);
|
||||||
tolua_pushstring(L, faction_getemail(self));
|
tolua_pushstring(L, faction_getemail(f));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_faction_set_email(lua_State * L)
|
static int tolua_faction_set_email(lua_State * L)
|
||||||
{
|
{
|
||||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
faction *f = (faction *)tolua_tousertype(L, 1, NULL);
|
||||||
faction_setemail(self, tolua_tostring(L, 2, NULL));
|
faction_setemail(f, tolua_tostring(L, 2, NULL));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_faction_get_locale(lua_State * L)
|
static int tolua_faction_get_locale(lua_State * L)
|
||||||
{
|
{
|
||||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
faction *f = (faction *)tolua_tousertype(L, 1, NULL);
|
||||||
tolua_pushstring(L, locale_name(self->locale));
|
tolua_pushstring(L, locale_name(f->locale));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_faction_set_locale(lua_State * L)
|
static int tolua_faction_set_locale(lua_State * L)
|
||||||
{
|
{
|
||||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
faction *f = (faction *)tolua_tousertype(L, 1, NULL);
|
||||||
const char *name = tolua_tostring(L, 2, NULL);
|
const char *name = tolua_tostring(L, 2, NULL);
|
||||||
const struct locale *loc = get_locale(name);
|
const struct locale *loc = get_locale(name);
|
||||||
if (loc) {
|
if (loc) {
|
||||||
self->locale = loc;
|
f->locale = loc;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
tolua_pushstring(L, "invalid locale");
|
tolua_pushstring(L, "invalid locale");
|
||||||
|
@ -432,18 +436,18 @@ static int tolua_faction_set_locale(lua_State * L)
|
||||||
|
|
||||||
static int tolua_faction_get_race(lua_State * L)
|
static int tolua_faction_get_race(lua_State * L)
|
||||||
{
|
{
|
||||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
faction *f = (faction *)tolua_tousertype(L, 1, NULL);
|
||||||
tolua_pushstring(L, self->race->_name);
|
tolua_pushstring(L, f->race->_name);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_faction_set_race(lua_State * L)
|
static int tolua_faction_set_race(lua_State * L)
|
||||||
{
|
{
|
||||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
faction *f = (faction *)tolua_tousertype(L, 1, NULL);
|
||||||
const char *name = tolua_tostring(L, 2, NULL);
|
const char *name = tolua_tostring(L, 2, NULL);
|
||||||
const race *rc = rc_find(name);
|
const race *rc = rc_find(name);
|
||||||
if (rc != NULL) {
|
if (rc != NULL) {
|
||||||
self->race = rc;
|
f->race = rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -451,15 +455,15 @@ static int tolua_faction_set_race(lua_State * L)
|
||||||
|
|
||||||
static int tolua_faction_get_name(lua_State * L)
|
static int tolua_faction_get_name(lua_State * L)
|
||||||
{
|
{
|
||||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
faction *f = (faction *)tolua_tousertype(L, 1, NULL);
|
||||||
tolua_pushstring(L, faction_getname(self));
|
tolua_pushstring(L, faction_getname(f));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_faction_set_name(lua_State * L)
|
static int tolua_faction_set_name(lua_State * L)
|
||||||
{
|
{
|
||||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
faction *f = (faction *)tolua_tousertype(L, 1, NULL);
|
||||||
faction_setname(self, tolua_tostring(L, 2, NULL));
|
faction_setname(f, tolua_tostring(L, 2, NULL));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -479,44 +483,108 @@ static int tolua_faction_set_uid(lua_State * L)
|
||||||
|
|
||||||
static int tolua_faction_get_info(lua_State * L)
|
static int tolua_faction_get_info(lua_State * L)
|
||||||
{
|
{
|
||||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
faction *f = (faction *)tolua_tousertype(L, 1, NULL);
|
||||||
tolua_pushstring(L, faction_getbanner(self));
|
tolua_pushstring(L, faction_getbanner(f));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_faction_set_info(lua_State * L)
|
static int tolua_faction_set_info(lua_State * L)
|
||||||
{
|
{
|
||||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
faction *f = (faction *)tolua_tousertype(L, 1, NULL);
|
||||||
faction_setbanner(self, tolua_tostring(L, 2, NULL));
|
faction_setbanner(f, tolua_tostring(L, 2, NULL));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_faction_get_alliance(lua_State * L)
|
/* TODO: this is probably useful elsewhere */
|
||||||
|
static const char *status_names[] = {
|
||||||
|
"money", "fight", "observe", "give", "guard", "stealth", "travel", NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
static int cb_ally_push(struct allies *af, struct faction *f, int status, void *udata) {
|
||||||
|
struct lua_State *L = (struct lua_State *)udata;
|
||||||
|
int len = 1;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
lua_pushnumber(L, f->no);
|
||||||
|
lua_newtable(L);
|
||||||
|
for (i = 0; status_names[i]; ++i) {
|
||||||
|
int flag = 1 << i;
|
||||||
|
if (status & flag) {
|
||||||
|
lua_pushstring(L, status_names[i]);
|
||||||
|
lua_rawseti(L, -2, len++);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lua_rawset(L, -3);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int tolua_faction_get_allies(lua_State * L) {
|
||||||
|
faction *f = (faction *)tolua_tousertype(L, 1, NULL);
|
||||||
|
lua_newtable(L);
|
||||||
|
allies_walk(f->allies, cb_ally_push, L);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int tolua_faction_set_ally(lua_State * L) {
|
||||||
|
faction *f1 = (faction *)tolua_tousertype(L, 1, NULL);
|
||||||
|
faction *f2 = (faction *)tolua_tousertype(L, 2, NULL);
|
||||||
|
const char *status = tolua_tostring(L, 3, NULL);
|
||||||
|
bool value = tolua_toboolean(L, 4, 1);
|
||||||
|
if (status) {
|
||||||
|
int flag = ally_status(status);
|
||||||
|
int flags = ally_get(f1->allies, f2);
|
||||||
|
if (value) {
|
||||||
|
flags |= flag;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
flags &= ~flag;
|
||||||
|
}
|
||||||
|
ally_set(&f1->allies, f2, flags);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int tolua_faction_get_ally(lua_State * L)
|
||||||
{
|
{
|
||||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
faction *f1 = (faction *)tolua_tousertype(L, 1, NULL);
|
||||||
tolua_pushusertype(L, f_get_alliance(self), TOLUA_CAST "alliance");
|
faction *f2 = (faction *)tolua_tousertype(L, 2, NULL);
|
||||||
|
const char *status = tolua_tostring(L, 3, NULL);
|
||||||
|
if (f1 && f2 && status) {
|
||||||
|
int test = ally_status(status);
|
||||||
|
int flags = ally_get(f1->allies, f2);
|
||||||
|
lua_pushboolean(L, (test & flags) == test);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int tolua_faction_get_alliances(lua_State * L)
|
||||||
|
{
|
||||||
|
faction *f = (faction *)tolua_tousertype(L, 1, NULL);
|
||||||
|
tolua_pushusertype(L, f_get_alliance(f), TOLUA_CAST "alliance");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_faction_set_alliance(lua_State * L)
|
static int tolua_faction_set_alliance(lua_State * L)
|
||||||
{
|
{
|
||||||
struct faction *self = (struct faction *)tolua_tousertype(L, 1, NULL);
|
struct faction *f = (struct faction *)tolua_tousertype(L, 1, NULL);
|
||||||
struct alliance *alli = (struct alliance *) tolua_tousertype(L, 2, NULL);
|
struct alliance *alli = (struct alliance *) tolua_tousertype(L, 2, NULL);
|
||||||
|
|
||||||
setalliance(self, alli);
|
setalliance(f, alli);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_faction_get_items(lua_State * L)
|
static int tolua_faction_get_items(lua_State * L)
|
||||||
{
|
{
|
||||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
faction *f = (faction *)tolua_tousertype(L, 1, NULL);
|
||||||
item **item_ptr = (item **)lua_newuserdata(L, sizeof(item *));
|
item **item_ptr = (item **)lua_newuserdata(L, sizeof(item *));
|
||||||
|
|
||||||
luaL_getmetatable(L, TOLUA_CAST "item");
|
luaL_getmetatable(L, TOLUA_CAST "item");
|
||||||
lua_setmetatable(L, -2);
|
lua_setmetatable(L, -2);
|
||||||
|
|
||||||
*item_ptr = self->items;
|
*item_ptr = f->items;
|
||||||
|
|
||||||
lua_pushcclosure(L, tolua_itemlist_next, 1);
|
lua_pushcclosure(L, tolua_itemlist_next, 1);
|
||||||
|
|
||||||
|
@ -525,8 +593,8 @@ static int tolua_faction_get_items(lua_State * L)
|
||||||
|
|
||||||
static int tolua_faction_tostring(lua_State * L)
|
static int tolua_faction_tostring(lua_State * L)
|
||||||
{
|
{
|
||||||
faction *self = (faction *)tolua_tousertype(L, 1, NULL);
|
faction *f = (faction *)tolua_tousertype(L, 1, NULL);
|
||||||
lua_pushstring(L, factionname(self));
|
lua_pushstring(L, factionname(f));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -569,8 +637,6 @@ void tolua_faction_open(lua_State * L)
|
||||||
tolua_faction_set_locale);
|
tolua_faction_set_locale);
|
||||||
tolua_variable(L, TOLUA_CAST "race", tolua_faction_get_race,
|
tolua_variable(L, TOLUA_CAST "race", tolua_faction_get_race,
|
||||||
tolua_faction_set_race);
|
tolua_faction_set_race);
|
||||||
tolua_variable(L, TOLUA_CAST "alliance", tolua_faction_get_alliance,
|
|
||||||
tolua_faction_set_alliance);
|
|
||||||
tolua_variable(L, TOLUA_CAST "score", tolua_faction_get_score, NULL);
|
tolua_variable(L, TOLUA_CAST "score", tolua_faction_get_score, NULL);
|
||||||
tolua_variable(L, TOLUA_CAST "magic", tolua_faction_get_magic,
|
tolua_variable(L, TOLUA_CAST "magic", tolua_faction_get_magic,
|
||||||
tolua_faction_set_magic);
|
tolua_faction_set_magic);
|
||||||
|
@ -582,6 +648,13 @@ void tolua_faction_open(lua_State * L)
|
||||||
tolua_variable(L, TOLUA_CAST "lastturn", tolua_faction_get_lastturn,
|
tolua_variable(L, TOLUA_CAST "lastturn", tolua_faction_get_lastturn,
|
||||||
tolua_faction_set_lastturn);
|
tolua_faction_set_lastturn);
|
||||||
|
|
||||||
|
tolua_variable(L, TOLUA_CAST "alliance", tolua_faction_get_alliances,
|
||||||
|
tolua_faction_set_alliance);
|
||||||
|
|
||||||
|
tolua_variable(L, TOLUA_CAST "allies", tolua_faction_get_allies, NULL);
|
||||||
|
tolua_function(L, TOLUA_CAST "set_ally", tolua_faction_set_ally);
|
||||||
|
tolua_function(L, TOLUA_CAST "get_ally", tolua_faction_get_ally);
|
||||||
|
|
||||||
tolua_function(L, TOLUA_CAST "get_origin", tolua_faction_get_origin);
|
tolua_function(L, TOLUA_CAST "get_origin", tolua_faction_get_origin);
|
||||||
tolua_function(L, TOLUA_CAST "set_origin", tolua_faction_set_origin);
|
tolua_function(L, TOLUA_CAST "set_origin", tolua_faction_set_origin);
|
||||||
tolua_function(L, TOLUA_CAST "normalize", tolua_faction_normalize);
|
tolua_function(L, TOLUA_CAST "normalize", tolua_faction_normalize);
|
||||||
|
|
291
src/bind_unit.c
291
src/bind_unit.c
|
@ -147,129 +147,129 @@ static int tolua_unit_get_group(lua_State * L)
|
||||||
|
|
||||||
static int tolua_unit_set_group(lua_State * L)
|
static int tolua_unit_set_group(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
group *g = join_group(self, tolua_tostring(L, 2, 0));
|
group *g = join_group(u, tolua_tostring(L, 2, 0));
|
||||||
lua_pushboolean(L, g!=NULL);
|
lua_pushboolean(L, g!=NULL);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_unit_get_name(lua_State * L)
|
static int tolua_unit_get_name(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
tolua_pushstring(L, unit_getname(self));
|
tolua_pushstring(L, unit_getname(u));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_unit_set_name(lua_State * L)
|
static int tolua_unit_set_name(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
unit_setname(self, tolua_tostring(L, 2, 0));
|
unit_setname(u, tolua_tostring(L, 2, 0));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_unit_get_info(lua_State * L)
|
static int tolua_unit_get_info(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
tolua_pushstring(L, unit_getinfo(self));
|
tolua_pushstring(L, unit_getinfo(u));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_unit_set_info(lua_State * L)
|
static int tolua_unit_set_info(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
unit_setinfo(self, tolua_tostring(L, 2, 0));
|
unit_setinfo(u, tolua_tostring(L, 2, 0));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_unit_get_id(lua_State * L)
|
static int tolua_unit_get_id(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
lua_pushinteger(L, unit_getid(self));
|
lua_pushinteger(L, unit_getid(u));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_unit_set_id(lua_State * L)
|
static int tolua_unit_set_id(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
unit_setid(self, (int)tolua_tonumber(L, 2, 0));
|
unit_setid(u, (int)tolua_tonumber(L, 2, 0));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_unit_get_auramax(lua_State * L)
|
static int tolua_unit_get_auramax(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
lua_pushinteger(L, max_spellpoints_depr(self->region, self));
|
lua_pushinteger(L, max_spellpoints_depr(u->region, u));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_unit_get_hpmax(lua_State * L)
|
static int tolua_unit_get_hpmax(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
lua_pushinteger(L, unit_max_hp(self));
|
lua_pushinteger(L, unit_max_hp(u));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_unit_get_hp(lua_State * L)
|
static int tolua_unit_get_hp(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
lua_pushinteger(L, unit_gethp(self));
|
lua_pushinteger(L, unit_gethp(u));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_unit_set_hp(lua_State * L)
|
static int tolua_unit_set_hp(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
unit_sethp(self, (int)tolua_tonumber(L, 2, 0));
|
unit_sethp(u, (int)tolua_tonumber(L, 2, 0));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_unit_get_number(lua_State * L)
|
static int tolua_unit_get_number(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
lua_pushinteger(L, self->number);
|
lua_pushinteger(L, u->number);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_unit_set_number(lua_State * L)
|
static int tolua_unit_set_number(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
int number = (int)tolua_tonumber(L, 2, 0);
|
int number = (int)tolua_tonumber(L, 2, 0);
|
||||||
if (self->number == 0) {
|
if (u->number == 0) {
|
||||||
set_number(self, number);
|
set_number(u, number);
|
||||||
self->hp = unit_max_hp(self) * number;
|
u->hp = unit_max_hp(u) * number;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
scale_number(self, number);
|
scale_number(u, number);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_unit_get_flags(lua_State * L)
|
static int tolua_unit_get_flags(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
lua_pushinteger(L, self->flags);
|
lua_pushinteger(L, u->flags);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_unit_set_flags(lua_State * L)
|
static int tolua_unit_set_flags(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
self->flags = (int)tolua_tonumber(L, 2, 0);
|
u->flags = (int)tolua_tonumber(L, 2, 0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_unit_get_guard(lua_State * L)
|
static int tolua_unit_get_guard(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
lua_pushboolean(L, is_guard(self));
|
lua_pushboolean(L, is_guard(u));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_unit_set_guard(lua_State * L)
|
static int tolua_unit_set_guard(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
unsigned int flags = (unsigned int)tolua_tonumber(L, 2, 0);
|
unsigned int flags = (unsigned int)tolua_tonumber(L, 2, 0);
|
||||||
setguard(self, flags!=0);
|
setguard(u, flags!=0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -285,8 +285,8 @@ static const char *unit_getmagic(const unit * u)
|
||||||
|
|
||||||
static int tolua_unit_get_magic(lua_State * L)
|
static int tolua_unit_get_magic(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
lua_pushstring(L, unit_getmagic(self));
|
lua_pushstring(L, unit_getmagic(u));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -306,64 +306,64 @@ static void unit_setmagic(unit * u, const char *type)
|
||||||
|
|
||||||
static int tolua_unit_set_magic(lua_State * L)
|
static int tolua_unit_set_magic(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
const char *type = tolua_tostring(L, 2, 0);
|
const char *type = tolua_tostring(L, 2, 0);
|
||||||
unit_setmagic(self, type);
|
unit_setmagic(u, type);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_unit_get_aura(lua_State * L)
|
static int tolua_unit_get_aura(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
lua_pushinteger(L, get_spellpoints(self));
|
lua_pushinteger(L, get_spellpoints(u));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_unit_set_aura(lua_State * L)
|
static int tolua_unit_set_aura(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
set_spellpoints(self, (int)tolua_tonumber(L, 2, 0));
|
set_spellpoints(u, (int)tolua_tonumber(L, 2, 0));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_unit_get_age(lua_State * L)
|
static int tolua_unit_get_age(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
lua_pushinteger(L, self->age);
|
lua_pushinteger(L, u->age);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_unit_set_age(lua_State * L)
|
static int tolua_unit_set_age(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
self->age = (int)tolua_tonumber(L, 2, 0);
|
u->age = (int)tolua_tonumber(L, 2, 0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_unit_get_status(lua_State * L)
|
static int tolua_unit_get_status(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
lua_pushinteger(L, unit_getstatus(self));
|
lua_pushinteger(L, unit_getstatus(u));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_unit_set_status(lua_State * L)
|
static int tolua_unit_set_status(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
unit_setstatus(self, (status_t)tolua_tonumber(L, 2, 0));
|
unit_setstatus(u, (status_t)tolua_tonumber(L, 2, 0));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_unit_get_item(lua_State * L)
|
static int tolua_unit_get_item(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
const char *iname = tolua_tostring(L, 2, 0);
|
const char *iname = tolua_tostring(L, 2, 0);
|
||||||
int result = -1;
|
int result = -1;
|
||||||
|
|
||||||
if (iname != NULL) {
|
if (iname != NULL) {
|
||||||
const item_type *itype = it_find(iname);
|
const item_type *itype = it_find(iname);
|
||||||
if (itype != NULL) {
|
if (itype != NULL) {
|
||||||
result = i_get(self->items, itype);
|
result = i_get(u->items, itype);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lua_pushinteger(L, result);
|
lua_pushinteger(L, result);
|
||||||
|
@ -372,13 +372,13 @@ static int tolua_unit_get_item(lua_State * L)
|
||||||
|
|
||||||
static int tolua_unit_get_effect(lua_State * L)
|
static int tolua_unit_get_effect(lua_State * L)
|
||||||
{
|
{
|
||||||
const unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
const unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
const char *potion_name = tolua_tostring(L, 2, 0);
|
const char *potion_name = tolua_tostring(L, 2, 0);
|
||||||
int result = -1;
|
int result = -1;
|
||||||
const item_type *it_potion = it_find(potion_name);
|
const item_type *it_potion = it_find(potion_name);
|
||||||
|
|
||||||
if (it_potion != NULL) {
|
if (it_potion != NULL) {
|
||||||
result = get_effect(self, it_potion);
|
result = get_effect(u, it_potion);
|
||||||
}
|
}
|
||||||
|
|
||||||
lua_pushinteger(L, result);
|
lua_pushinteger(L, result);
|
||||||
|
@ -387,7 +387,7 @@ static int tolua_unit_get_effect(lua_State * L)
|
||||||
|
|
||||||
static int tolua_unit_add_item(lua_State * L)
|
static int tolua_unit_add_item(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
const char *iname = tolua_tostring(L, 2, 0);
|
const char *iname = tolua_tostring(L, 2, 0);
|
||||||
int number = (int)tolua_tonumber(L, 3, 0);
|
int number = (int)tolua_tonumber(L, 3, 0);
|
||||||
int result = -1;
|
int result = -1;
|
||||||
|
@ -395,7 +395,7 @@ static int tolua_unit_add_item(lua_State * L)
|
||||||
if (iname != NULL) {
|
if (iname != NULL) {
|
||||||
const item_type *itype = it_find(iname);
|
const item_type *itype = it_find(iname);
|
||||||
if (itype != NULL) {
|
if (itype != NULL) {
|
||||||
item *i = i_change(&self->items, itype, number);
|
item *i = i_change(&u->items, itype, number);
|
||||||
result = i ? i->number : 0;
|
result = i ? i->number : 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -405,12 +405,12 @@ static int tolua_unit_add_item(lua_State * L)
|
||||||
|
|
||||||
static int tolua_unit_getskill(lua_State * L)
|
static int tolua_unit_getskill(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
const char *skname = tolua_tostring(L, 2, 0);
|
const char *skname = tolua_tostring(L, 2, 0);
|
||||||
skill_t sk = findskill(skname);
|
skill_t sk = findskill(skname);
|
||||||
int value = -1;
|
int value = -1;
|
||||||
if (sk != NOSKILL) {
|
if (sk != NOSKILL) {
|
||||||
skill *sv = unit_skill(self, sk);
|
skill *sv = unit_skill(u, sk);
|
||||||
if (sv) {
|
if (sv) {
|
||||||
value = sv->level;
|
value = sv->level;
|
||||||
}
|
}
|
||||||
|
@ -423,10 +423,10 @@ static int tolua_unit_getskill(lua_State * L)
|
||||||
|
|
||||||
static int tolua_unit_effskill(lua_State * L)
|
static int tolua_unit_effskill(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
const char *skname = tolua_tostring(L, 2, 0);
|
const char *skname = tolua_tostring(L, 2, 0);
|
||||||
skill_t sk = findskill(skname);
|
skill_t sk = findskill(skname);
|
||||||
int value = (sk == NOSKILL) ? -1 : effskill(self, sk, NULL);
|
int value = (sk == NOSKILL) ? -1 : effskill(u, sk, NULL);
|
||||||
lua_pushinteger(L, value);
|
lua_pushinteger(L, value);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -438,10 +438,10 @@ typedef struct event {
|
||||||
|
|
||||||
static int tolua_unit_addnotice(lua_State * L)
|
static int tolua_unit_addnotice(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
const char *str = tolua_tostring(L, 2, 0);
|
const char *str = tolua_tostring(L, 2, 0);
|
||||||
|
|
||||||
addmessage(self->region, self->faction, str, MSG_MESSAGE, ML_IMPORTANT);
|
addmessage(u->region, u->faction, str, MSG_MESSAGE, ML_IMPORTANT);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -475,11 +475,11 @@ static void unit_castspell(unit * u, const char *name, int level)
|
||||||
|
|
||||||
static int tolua_unit_castspell(lua_State * L)
|
static int tolua_unit_castspell(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
const char *str = tolua_tostring(L, 2, 0);
|
const char *str = tolua_tostring(L, 2, 0);
|
||||||
int level = (int)tolua_tonumber(L, 3, 1);
|
int level = (int)tolua_tonumber(L, 3, 1);
|
||||||
|
|
||||||
unit_castspell(self, str, level);
|
unit_castspell(u, str, level);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -505,17 +505,17 @@ static int tolua_unit_addspell(lua_State * L)
|
||||||
|
|
||||||
static int tolua_unit_set_racename(lua_State * L)
|
static int tolua_unit_set_racename(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
const char *str = tolua_tostring(L, 2, 0);
|
const char *str = tolua_tostring(L, 2, 0);
|
||||||
|
|
||||||
set_racename(&self->attribs, str);
|
set_racename(&u->attribs, str);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_unit_get_racename(lua_State * L)
|
static int tolua_unit_get_racename(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
attrib *a = a_find(self->attribs, &at_racename);
|
attrib *a = a_find(u->attribs, &at_racename);
|
||||||
if (a) {
|
if (a) {
|
||||||
tolua_pushstring(L, get_racename(a));
|
tolua_pushstring(L, get_racename(a));
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -525,29 +525,30 @@ static int tolua_unit_get_racename(lua_State * L)
|
||||||
|
|
||||||
static int tolua_unit_setskill(lua_State * L)
|
static int tolua_unit_setskill(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
const char *skname = tolua_tostring(L, 2, 0);
|
const char *skname = tolua_tostring(L, 2, 0);
|
||||||
int level = (int)tolua_tonumber(L, 3, 0);
|
int level = (int)tolua_tonumber(L, 3, 0);
|
||||||
|
bool rcmod = tolua_toboolean(L, 4, 0);
|
||||||
skill_t sk = findskill(skname);
|
skill_t sk = findskill(skname);
|
||||||
|
|
||||||
if (sk != NOSKILL) {
|
if (sk != NOSKILL) {
|
||||||
set_level(self, sk, level);
|
if (rcmod) level -= u_race(u)->bonus[sk];
|
||||||
}
|
set_level(u, sk, level);
|
||||||
else {
|
|
||||||
level = -1;
|
|
||||||
}
|
|
||||||
lua_pushinteger(L, level);
|
lua_pushinteger(L, level);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int tolua_unit_use_pooled(lua_State * L)
|
static int tolua_unit_use_pooled(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
const char *iname = tolua_tostring(L, 2, 0);
|
const char *iname = tolua_tostring(L, 2, 0);
|
||||||
int number = (int)tolua_tonumber(L, 3, 0);
|
int number = (int)tolua_tonumber(L, 3, 0);
|
||||||
const resource_type *rtype = rt_find(iname);
|
const resource_type *rtype = rt_find(iname);
|
||||||
int result = -1;
|
int result = -1;
|
||||||
if (rtype != NULL) {
|
if (rtype != NULL) {
|
||||||
result = use_pooled(self, rtype, GET_DEFAULT, number);
|
result = use_pooled(u, rtype, GET_DEFAULT, number);
|
||||||
}
|
}
|
||||||
lua_pushinteger(L, result);
|
lua_pushinteger(L, result);
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -555,12 +556,12 @@ static int tolua_unit_use_pooled(lua_State * L)
|
||||||
|
|
||||||
static int tolua_unit_get_pooled(lua_State * L)
|
static int tolua_unit_get_pooled(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
const char *iname = tolua_tostring(L, 2, 0);
|
const char *iname = tolua_tostring(L, 2, 0);
|
||||||
const resource_type *rtype = rt_find(iname);
|
const resource_type *rtype = rt_find(iname);
|
||||||
int result = -1;
|
int result = -1;
|
||||||
if (rtype != NULL) {
|
if (rtype != NULL) {
|
||||||
result = get_pooled(self, rtype, GET_DEFAULT, INT_MAX);
|
result = get_pooled(u, rtype, GET_DEFAULT, INT_MAX);
|
||||||
}
|
}
|
||||||
lua_pushinteger(L, result);
|
lua_pushinteger(L, result);
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -577,8 +578,8 @@ static unit *unit_getfamiliar(const unit * u)
|
||||||
|
|
||||||
static int tolua_unit_get_familiar(lua_State * L)
|
static int tolua_unit_get_familiar(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
tolua_pushusertype(L, unit_getfamiliar(self), TOLUA_CAST "unit");
|
tolua_pushusertype(L, unit_getfamiliar(u), TOLUA_CAST "unit");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -597,8 +598,8 @@ static int tolua_unit_set_familiar(lua_State * L)
|
||||||
|
|
||||||
static int tolua_unit_get_building(lua_State * L)
|
static int tolua_unit_get_building(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
tolua_pushusertype(L, self->building, TOLUA_CAST "building");
|
tolua_pushusertype(L, u->building, TOLUA_CAST "building");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -622,8 +623,8 @@ static int tolua_unit_set_building(lua_State * L)
|
||||||
|
|
||||||
static int tolua_unit_get_ship(lua_State * L)
|
static int tolua_unit_get_ship(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
tolua_pushusertype(L, self->ship, TOLUA_CAST "ship");
|
tolua_pushusertype(L, u->ship, TOLUA_CAST "ship");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -638,17 +639,17 @@ static void unit_setship(unit * u, ship * s)
|
||||||
|
|
||||||
static int tolua_unit_set_ship(lua_State * L)
|
static int tolua_unit_set_ship(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
if (self->faction) {
|
if (u->faction) {
|
||||||
unit_setship(self, (ship *)tolua_tousertype(L, 2, 0));
|
unit_setship(u, (ship *)tolua_tousertype(L, 2, 0));
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_unit_get_region(lua_State * L)
|
static int tolua_unit_get_region(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
tolua_pushusertype(L, self->region, TOLUA_CAST "region");
|
tolua_pushusertype(L, u->region, TOLUA_CAST "region");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -659,29 +660,29 @@ static void unit_setregion(unit * u, region * r)
|
||||||
|
|
||||||
static int tolua_unit_set_region(lua_State * L)
|
static int tolua_unit_set_region(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
unit_setregion(self, (region *)tolua_tousertype(L, 2, 0));
|
unit_setregion(u, (region *)tolua_tousertype(L, 2, 0));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_unit_get_order(lua_State * L)
|
static int tolua_unit_get_order(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
int index = (int)tolua_tonumber(L, 2, -1);
|
int index = (int)tolua_tonumber(L, 2, -1);
|
||||||
order *ord = NULL;
|
order *ord = NULL;
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
ord = self->thisorder;
|
ord = u->thisorder;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int i;
|
int i;
|
||||||
ord = self->orders;
|
ord = u->orders;
|
||||||
for (i = 0; ord && i != index; ++i) {
|
for (i = 0; ord && i != index; ++i) {
|
||||||
ord = ord->next;
|
ord = ord->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ord) {
|
if (ord) {
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
get_command(ord, self->faction->locale, buffer, sizeof(buffer));
|
get_command(ord, u->faction->locale, buffer, sizeof(buffer));
|
||||||
lua_pushstring(L, buffer);
|
lua_pushstring(L, buffer);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -690,30 +691,30 @@ static int tolua_unit_get_order(lua_State * L)
|
||||||
|
|
||||||
static int tolua_unit_add_order(lua_State * L)
|
static int tolua_unit_add_order(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
const char *str = tolua_tostring(L, 2, 0);
|
const char *str = tolua_tostring(L, 2, 0);
|
||||||
order *ord = parse_order(str, self->faction->locale);
|
order *ord = parse_order(str, u->faction->locale);
|
||||||
unit_addorder(self, ord);
|
unit_addorder(u, ord);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_unit_clear_orders(lua_State * L)
|
static int tolua_unit_clear_orders(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
free_orders(&self->orders);
|
free_orders(&u->orders);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_unit_get_items(lua_State * L)
|
static int tolua_unit_get_items(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
|
|
||||||
item **item_ptr = (item **)lua_newuserdata(L, sizeof(item *));
|
item **item_ptr = (item **)lua_newuserdata(L, sizeof(item *));
|
||||||
|
|
||||||
luaL_getmetatable(L, TOLUA_CAST "item");
|
luaL_getmetatable(L, TOLUA_CAST "item");
|
||||||
lua_setmetatable(L, -2);
|
lua_setmetatable(L, -2);
|
||||||
|
|
||||||
*item_ptr = self->items;
|
*item_ptr = u->items;
|
||||||
|
|
||||||
lua_pushcclosure(L, tolua_itemlist_next, 1);
|
lua_pushcclosure(L, tolua_itemlist_next, 1);
|
||||||
|
|
||||||
|
@ -722,8 +723,8 @@ static int tolua_unit_get_items(lua_State * L)
|
||||||
|
|
||||||
static int tolua_unit_get_spells(lua_State * L)
|
static int tolua_unit_get_spells(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *) tolua_tousertype(L, 1, 0);
|
unit *u = (unit *) tolua_tousertype(L, 1, 0);
|
||||||
struct sc_mage *mage = self ? get_mage(self) : NULL;
|
struct sc_mage *mage = u ? get_mage(u) : NULL;
|
||||||
spellbook *sb = mage_get_spellbook(mage);
|
spellbook *sb = mage_get_spellbook(mage);
|
||||||
selist *slist = 0;
|
selist *slist = 0;
|
||||||
if (sb) {
|
if (sb) {
|
||||||
|
@ -734,10 +735,10 @@ static int tolua_unit_get_spells(lua_State * L)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_unit_get_curse(lua_State *L) {
|
static int tolua_unit_get_curse(lua_State *L) {
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
const char *name = tolua_tostring(L, 2, 0);
|
const char *name = tolua_tostring(L, 2, 0);
|
||||||
if (self->attribs) {
|
if (u->attribs) {
|
||||||
curse * c = get_curse(self->attribs, ct_find(name));
|
curse * c = get_curse(u->attribs, ct_find(name));
|
||||||
if (c) {
|
if (c) {
|
||||||
lua_pushnumber(L, curse_geteffect(c));
|
lua_pushnumber(L, curse_geteffect(c));
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -756,9 +757,9 @@ static int tolua_unit_clear_attribs(lua_State *L) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_unit_has_attrib(lua_State *L) {
|
static int tolua_unit_has_attrib(lua_State *L) {
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
const char *name = tolua_tostring(L, 2, 0);
|
const char *name = tolua_tostring(L, 2, 0);
|
||||||
attrib * a = self->attribs;
|
attrib * a = u->attribs;
|
||||||
while (a) {
|
while (a) {
|
||||||
if (strcmp(a->type->name, name) == 0) {
|
if (strcmp(a->type->name, name) == 0) {
|
||||||
break;
|
break;
|
||||||
|
@ -771,105 +772,105 @@ static int tolua_unit_has_attrib(lua_State *L) {
|
||||||
|
|
||||||
static int tolua_unit_get_key(lua_State * L)
|
static int tolua_unit_get_key(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
const char *name = tolua_tostring(L, 2, 0);
|
const char *name = tolua_tostring(L, 2, 0);
|
||||||
int flag = atoi36(name);
|
int flag = atoi36(name);
|
||||||
lua_pushboolean(L, key_get(self->attribs, flag));
|
lua_pushboolean(L, key_get(u->attribs, flag));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_unit_set_key(lua_State * L)
|
static int tolua_unit_set_key(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
const char *name = tolua_tostring(L, 2, 0);
|
const char *name = tolua_tostring(L, 2, 0);
|
||||||
int value = (int)tolua_tonumber(L, 3, 0);
|
int value = (int)tolua_tonumber(L, 3, 0);
|
||||||
int flag = atoi36(name);
|
int flag = atoi36(name);
|
||||||
if (value) {
|
if (value) {
|
||||||
key_set(&self->attribs, flag, value);
|
key_set(&u->attribs, flag, value);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
key_unset(&self->attribs, flag);
|
key_unset(&u->attribs, flag);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_unit_get_flag(lua_State * L)
|
static int tolua_unit_get_flag(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, NULL);
|
unit *u = (unit *)tolua_tousertype(L, 1, NULL);
|
||||||
int bit = (int)tolua_tonumber(L, 2, 0);
|
int bit = (int)tolua_tonumber(L, 2, 0);
|
||||||
|
|
||||||
lua_pushboolean(L, (self->flags & (1 << bit)));
|
lua_pushboolean(L, (u->flags & (1 << bit)));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_unit_set_flag(lua_State * L)
|
static int tolua_unit_set_flag(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, NULL);
|
unit *u = (unit *)tolua_tousertype(L, 1, NULL);
|
||||||
int bit = (int)tolua_tonumber(L, 2, 0);
|
int bit = (int)tolua_tonumber(L, 2, 0);
|
||||||
int set = tolua_toboolean(L, 3, 1);
|
int set = tolua_toboolean(L, 3, 1);
|
||||||
|
|
||||||
if (set)
|
if (set)
|
||||||
self->flags |= (1 << bit);
|
u->flags |= (1 << bit);
|
||||||
else
|
else
|
||||||
self->flags &= ~(1 << bit);
|
u->flags &= ~(1 << bit);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_unit_get_weight(lua_State * L)
|
static int tolua_unit_get_weight(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
lua_pushinteger(L, unit_getweight(self));
|
lua_pushinteger(L, unit_getweight(u));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_unit_get_capacity(lua_State * L)
|
static int tolua_unit_get_capacity(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
lua_pushinteger(L, unit_getcapacity(self));
|
lua_pushinteger(L, unit_getcapacity(u));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_unit_get_faction(lua_State * L)
|
static int tolua_unit_get_faction(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
tolua_pushusertype(L, (void *)self->faction, TOLUA_CAST "faction");
|
tolua_pushusertype(L, (void *)u->faction, TOLUA_CAST "faction");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_unit_set_faction(lua_State * L)
|
static int tolua_unit_set_faction(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
faction *f = (faction *)tolua_tousertype(L, 2, 0);
|
faction *f = (faction *)tolua_tousertype(L, 2, 0);
|
||||||
u_setfaction(self, f);
|
u_setfaction(u, f);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_unit_get_race(lua_State * L)
|
static int tolua_unit_get_race(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
tolua_pushstring(L, u_race(self)->_name);
|
tolua_pushstring(L, u_race(u)->_name);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_unit_set_race(lua_State * L)
|
static int tolua_unit_set_race(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
const char *rcname = tolua_tostring(L, 2, 0);
|
const char *rcname = tolua_tostring(L, 2, 0);
|
||||||
const race *rc = rc_find(rcname);
|
const race *rc = rc_find(rcname);
|
||||||
if (rc != NULL) {
|
if (rc != NULL) {
|
||||||
if (self->irace == u_race(self)) {
|
if (u->irace == u_race(u)) {
|
||||||
self->irace = NULL;
|
u->irace = NULL;
|
||||||
}
|
}
|
||||||
u_setrace(self, rc);
|
u_setrace(u, rc);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_unit_destroy(lua_State * L)
|
static int tolua_unit_destroy(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
if (self) {
|
if (u) {
|
||||||
remove_unit(&self->region->units, self);
|
remove_unit(&u->region->units, u);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -893,25 +894,25 @@ static int tolua_unit_create(lua_State * L)
|
||||||
|
|
||||||
static int tolua_unit_tostring(lua_State * L)
|
static int tolua_unit_tostring(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
lua_pushstring(L, unitname(self));
|
lua_pushstring(L, unitname(u));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_event_gettype(lua_State * L)
|
static int tolua_event_gettype(lua_State * L)
|
||||||
{
|
{
|
||||||
event *self = (event *)tolua_tousertype(L, 1, 0);
|
event *u = (event *)tolua_tousertype(L, 1, 0);
|
||||||
int index = (int)tolua_tonumber(L, 2, 0);
|
int index = (int)tolua_tonumber(L, 2, 0);
|
||||||
lua_pushstring(L, self->args[index].type);
|
lua_pushstring(L, u->args[index].type);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_event_get(lua_State * L)
|
static int tolua_event_get(lua_State * L)
|
||||||
{
|
{
|
||||||
struct event *self = (struct event *)tolua_tousertype(L, 1, 0);
|
struct event *u = (struct event *)tolua_tousertype(L, 1, 0);
|
||||||
int index = (int)tolua_tonumber(L, 2, 0);
|
int index = (int)tolua_tonumber(L, 2, 0);
|
||||||
|
|
||||||
event_arg *arg = self->args + index;
|
event_arg *arg = u->args + index;
|
||||||
|
|
||||||
if (arg->type) {
|
if (arg->type) {
|
||||||
if (strcmp(arg->type, "string") == 0) {
|
if (strcmp(arg->type, "string") == 0) {
|
||||||
|
|
|
@ -282,10 +282,22 @@ static int forget_cmd(unit * u, order * ord)
|
||||||
|
|
||||||
sk = get_skill(s, u->faction->locale);
|
sk = get_skill(s, u->faction->locale);
|
||||||
if (sk != NOSKILL) {
|
if (sk != NOSKILL) {
|
||||||
if (sk == SK_MAGIC && is_familiar(u)) {
|
if (sk == SK_MAGIC) {
|
||||||
|
if (is_familiar(u)) {
|
||||||
/* some units cannot forget their innate magical abilities */
|
/* some units cannot forget their innate magical abilities */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
unit *ufam = get_familiar(u);
|
||||||
|
if (ufam) {
|
||||||
|
a_removeall(&ufam->attribs, NULL);
|
||||||
|
u_setfaction(ufam, get_monsters());
|
||||||
|
unit_convert_race(ufam, NULL, "ghost");
|
||||||
|
}
|
||||||
|
a_removeall(&u->attribs, &at_mage);
|
||||||
|
a_removeall(&u->attribs, &at_familiar);
|
||||||
|
}
|
||||||
|
}
|
||||||
ADDMSG(&u->faction->msgs, msg_message("forget", "unit skill", u, sk));
|
ADDMSG(&u->faction->msgs, msg_message("forget", "unit skill", u, sk));
|
||||||
set_level(u, sk, 0);
|
set_level(u, sk, 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -185,6 +185,29 @@ static int ally_flag(const char *s, int help_mask)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ally_status(const char *s)
|
||||||
|
{
|
||||||
|
if (strcmp(s, "give") == 0) {
|
||||||
|
return HELP_GIVE;
|
||||||
|
}
|
||||||
|
else if (strcmp(s, "fight") == 0) {
|
||||||
|
return HELP_FIGHT;
|
||||||
|
}
|
||||||
|
else if (strcmp(s, "money") == 0) {
|
||||||
|
return HELP_MONEY;
|
||||||
|
}
|
||||||
|
else if (strcmp(s, "travel") == 0) {
|
||||||
|
return HELP_TRAVEL;
|
||||||
|
}
|
||||||
|
else if (strcmp(s, "guard") == 0) {
|
||||||
|
return HELP_GUARD;
|
||||||
|
}
|
||||||
|
else if (strcmp(s, "all") == 0) {
|
||||||
|
return HELP_ALL;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/** Specifies automatic alliance modes.
|
/** Specifies automatic alliance modes.
|
||||||
* If this returns a value then the bits set are immutable between alliance
|
* If this returns a value then the bits set are immutable between alliance
|
||||||
* partners (faction::alliance) and cannot be changed with the HELP command.
|
* partners (faction::alliance) and cannot be changed with the HELP command.
|
||||||
|
|
|
@ -14,6 +14,7 @@ struct allies;
|
||||||
|
|
||||||
extern struct attrib_type at_npcfaction;
|
extern struct attrib_type at_npcfaction;
|
||||||
|
|
||||||
|
int ally_status(const char *s);
|
||||||
int ally_get(struct allies *al, const struct faction *f);
|
int ally_get(struct allies *al, const struct faction *f);
|
||||||
void ally_set(struct allies **p_al, struct faction *f, int status);
|
void ally_set(struct allies **p_al, struct faction *f, int status);
|
||||||
void write_allies(struct gamedata * data, const struct allies *alist);
|
void write_allies(struct gamedata * data, const struct allies *alist);
|
||||||
|
|
|
@ -395,7 +395,7 @@ void save_special_items(unit *usrc)
|
||||||
/* some units have plural names, it would be neat if they aren't single: */
|
/* some units have plural names, it would be neat if they aren't single: */
|
||||||
scale_number(u, 2);
|
scale_number(u, 2);
|
||||||
}
|
}
|
||||||
set_racename(&u->attribs, "ghost");
|
unit_convert_race(u, rc_ghost, "ghost");
|
||||||
give_special_items(u, &usrc->items);
|
give_special_items(u, &usrc->items);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1833,3 +1833,14 @@ double u_heal_factor(const unit * u)
|
||||||
}
|
}
|
||||||
return 1.0;
|
return 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void unit_convert_race(unit *u, const race *rc, const char *rcname)
|
||||||
|
{
|
||||||
|
if (rc && u->_race != rc) {
|
||||||
|
u_setrace(u, rc);
|
||||||
|
}
|
||||||
|
if (rcname && strcmp(rcname, u->_race->_name) != 0) {
|
||||||
|
set_racename(&u->attribs, rcname);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -221,6 +221,7 @@ extern "C" {
|
||||||
char *write_unitname(const struct unit *u, char *buffer, size_t size);
|
char *write_unitname(const struct unit *u, char *buffer, size_t size);
|
||||||
bool unit_name_equals_race(const struct unit *u);
|
bool unit_name_equals_race(const struct unit *u);
|
||||||
|
|
||||||
|
void unit_convert_race(struct unit *u, const struct race *rc, const char *rcname);
|
||||||
/* getunit results: */
|
/* getunit results: */
|
||||||
#define GET_UNIT 0
|
#define GET_UNIT 0
|
||||||
#define GET_NOTFOUND 1
|
#define GET_NOTFOUND 1
|
||||||
|
|
52
src/report.c
52
src/report.c
|
@ -71,6 +71,7 @@
|
||||||
#include <util/rng.h>
|
#include <util/rng.h>
|
||||||
#include <util/strings.h>
|
#include <util/strings.h>
|
||||||
|
|
||||||
|
#include <format.h>
|
||||||
#include <selist.h>
|
#include <selist.h>
|
||||||
#include <filestream.h>
|
#include <filestream.h>
|
||||||
#include <stream.h>
|
#include <stream.h>
|
||||||
|
@ -1053,38 +1054,53 @@ static void report_region_edges(struct stream *out, const region * r, faction *
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *report_list(const struct locale *lang, char *buffer, size_t len, int argc, const char **argv) {
|
||||||
|
const char *two = LOC(lang, "list_two");
|
||||||
|
const char *start = LOC(lang, "list_start");
|
||||||
|
const char *middle = LOC(lang, "list_middle");
|
||||||
|
const char *end = LOC(lang, "list_end");
|
||||||
|
return format_list(argc, argv, buffer, len, two, start, middle, end);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define MAX_SCHEMES ((TP_RADIUS * 2 + 1) * (TP_RADIUS * 2 + 1) - 4)
|
||||||
|
|
||||||
static void report_region_schemes(struct stream *out, const region * r, faction * f) {
|
static void report_region_schemes(struct stream *out, const region * r, faction * f) {
|
||||||
char buf[4096];
|
|
||||||
sbstring sbs;
|
|
||||||
sbs_init(&sbs, buf, sizeof(buf));
|
|
||||||
|
|
||||||
if (r->seen.mode >= seen_unit && is_astral(r) &&
|
if (r->seen.mode >= seen_unit && is_astral(r) &&
|
||||||
!is_cursed(r->attribs, &ct_astralblock)) {
|
!is_cursed(r->attribs, &ct_astralblock)) {
|
||||||
/* Sonderbehandlung Teleport-Ebene */
|
/* Sonderbehandlung Teleport-Ebene */
|
||||||
region_list *rl = astralregions(r, inhabitable);
|
region *rl[MAX_SCHEMES];
|
||||||
region_list *rl2;
|
int num = get_astralregions(r, inhabitable, rl);
|
||||||
|
char buf[4096];
|
||||||
|
|
||||||
if (rl) {
|
if (num == 1) {
|
||||||
/* this localization might not work for every language but is fine for de and en */
|
/* single region is easy */
|
||||||
sbs_strcat(&sbs, LOC(f->locale, "nr_schemes_prefix"));
|
region *rn = rl[0];
|
||||||
rl2 = rl;
|
f_regionid(rn, f, buf, sizeof(buf));
|
||||||
while (rl2) {
|
}
|
||||||
|
else if (num > 1) {
|
||||||
|
int i;
|
||||||
|
const char *rnames[MAX_SCHEMES];
|
||||||
|
|
||||||
|
for (i = 0; i != num; ++i) {
|
||||||
char rbuf[REPORTWIDTH];
|
char rbuf[REPORTWIDTH];
|
||||||
f_regionid(rl2->data, f, rbuf, sizeof(rbuf));
|
region *rn = rl[i];
|
||||||
sbs_strcat(&sbs, rbuf);
|
f_regionid(rn, f, rbuf, sizeof(rbuf));
|
||||||
rl2 = rl2->next;
|
rnames[i] = str_strdup(rbuf);
|
||||||
if (rl2) {
|
}
|
||||||
sbs_strcat(&sbs, ", ");
|
report_list(f->locale, buf, sizeof(buf), num, rnames);
|
||||||
|
for (i = 0; i != num; ++i) {
|
||||||
|
free((char *)rnames[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sbs_strcat(&sbs,LOC(f->locale, "nr_schemes_postfix"));
|
if (num > 0) {
|
||||||
free_regionlist(rl);
|
if (format_replace(LOC(f->locale, "nr_schemes_template"), "{0}", buf, buf, sizeof(buf))) {
|
||||||
/* Schreibe Paragraphen */
|
|
||||||
newline(out);
|
newline(out);
|
||||||
paragraph(out, buf, 0, 0, 0);
|
paragraph(out, buf, 0, 0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void report_region(struct stream *out, const region * r, faction * f)
|
void report_region(struct stream *out, const region * r, faction * f)
|
||||||
{
|
{
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#define TE_CENTER 1000
|
#define TE_CENTER 1000
|
||||||
#define TP_RADIUS 2
|
|
||||||
#define TP_DISTANCE 4
|
#define TP_DISTANCE 4
|
||||||
|
|
||||||
int real2tp(int rk)
|
int real2tp(int rk)
|
||||||
|
@ -75,6 +74,33 @@ region_list *astralregions(const region * r, bool(*valid) (const region *))
|
||||||
return rlist;
|
return rlist;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int get_astralregions(const region * r, bool(*valid) (const region *), region *result[])
|
||||||
|
{
|
||||||
|
assert(is_astral(r));
|
||||||
|
r = r_astral_to_standard(r);
|
||||||
|
if (r) {
|
||||||
|
int x, y, num = 0;
|
||||||
|
for (x = -TP_RADIUS; x <= +TP_RADIUS; ++x) {
|
||||||
|
for (y = -TP_RADIUS; y <= +TP_RADIUS; ++y) {
|
||||||
|
region *rn;
|
||||||
|
int dist = koor_distance(0, 0, x, y);
|
||||||
|
|
||||||
|
if (dist <= TP_RADIUS) {
|
||||||
|
int nx = r->x + x, ny = r->y + y;
|
||||||
|
pnormalize(&nx, &ny, rplane(r));
|
||||||
|
rn = findregion(nx, ny);
|
||||||
|
if (rn != NULL && (valid == NULL || valid(rn))) {
|
||||||
|
result[num++] = rn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return num;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
region *r_standard_to_astral(const region * r)
|
region *r_standard_to_astral(const region * r)
|
||||||
{
|
{
|
||||||
assert(!is_astral(r));
|
assert(!is_astral(r));
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define TP_RADIUS 2 /* Radius von Schemen */
|
||||||
|
|
||||||
struct region;
|
struct region;
|
||||||
struct region_list;
|
struct region_list;
|
||||||
struct plane;
|
struct plane;
|
||||||
|
@ -20,6 +22,7 @@ extern "C" {
|
||||||
bool inhabitable(const struct region *r);
|
bool inhabitable(const struct region *r);
|
||||||
bool is_astral(const struct region *r);
|
bool is_astral(const struct region *r);
|
||||||
struct plane *get_astralplane(void);
|
struct plane *get_astralplane(void);
|
||||||
|
int get_astralregions(const struct region * r, bool(*valid) (const struct region *), struct region *result[]);
|
||||||
|
|
||||||
void create_teleport_plane(void);
|
void create_teleport_plane(void);
|
||||||
void spawn_braineaters(float chance);
|
void spawn_braineaters(float chance);
|
||||||
|
|
Loading…
Reference in New Issue