forked from github/server
Merge branch 'develop' of github.com:ennorehling/eressea into develop
This commit is contained in:
commit
44d0a0acec
|
@ -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
|
|
@ -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);
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -408,9 +408,6 @@ void destroyfaction(faction ** fp)
|
||||||
f->next = dead_factions;
|
f->next = dead_factions;
|
||||||
dead_factions = f;
|
dead_factions = f;
|
||||||
|
|
||||||
fset(f, FFL_QUIT);
|
|
||||||
f->_alive = false;
|
|
||||||
|
|
||||||
if (f->spellbook) {
|
if (f->spellbook) {
|
||||||
spellbook_clear(f->spellbook);
|
spellbook_clear(f->spellbook);
|
||||||
free(f->spellbook);
|
free(f->spellbook);
|
||||||
|
@ -463,6 +460,8 @@ void destroyfaction(faction ** fp)
|
||||||
setalliance(f, NULL);
|
setalliance(f, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fset(f, FFL_QUIT);
|
||||||
|
f->_alive = false;
|
||||||
funhash(f);
|
funhash(f);
|
||||||
|
|
||||||
/* units of other factions that were disguised as this faction
|
/* units of other factions that were disguised as this faction
|
||||||
|
|
|
@ -952,8 +952,7 @@ int sp_hero(struct castorder * co)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m =
|
m = msg_message("cast_hero_effect", "mage spell amount", fi->unit, sp, targets);
|
||||||
msg_message("cast_hero_effect", "mage spell amount", fi->unit, sp, targets);
|
|
||||||
message_all(b, m);
|
message_all(b, m);
|
||||||
msg_release(m);
|
msg_release(m);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue