forked from github/server
Merge remote-tracking branch 'upstream/master'
Conflicts: src/kernel/save.c src/triggers/createunit.c
This commit is contained in:
commit
1bb215dd52
|
@ -58,7 +58,8 @@ attrib_type at_otherfaction = {
|
||||||
|
|
||||||
struct faction *get_otherfaction(const struct attrib *a)
|
struct faction *get_otherfaction(const struct attrib *a)
|
||||||
{
|
{
|
||||||
return (faction *)(a->data.v);
|
faction * f = (faction *)(a->data.v);
|
||||||
|
return (f && f->_alive) ? f : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct attrib *make_otherfaction(struct faction *f)
|
struct attrib *make_otherfaction(struct faction *f)
|
||||||
|
|
|
@ -384,8 +384,9 @@ 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)
|
||||||
{
|
{
|
||||||
unused_arg(L);
|
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||||
return 0;
|
tolua_pushstring(L, self->_password);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_faction_set_password(lua_State * L)
|
static int tolua_faction_set_password(lua_State * L)
|
||||||
|
|
|
@ -217,6 +217,7 @@ int resolve_faction(variant id, void *address)
|
||||||
result = -1;
|
result = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
assert(address);
|
||||||
*(faction **)address = f;
|
*(faction **)address = f;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -333,7 +334,8 @@ variant read_faction_reference(struct storage * store)
|
||||||
|
|
||||||
void write_faction_reference(const faction * f, struct storage *store)
|
void write_faction_reference(const faction * f, struct storage *store)
|
||||||
{
|
{
|
||||||
WRITE_INT(store, (f && f->_alive) ? f->no : 0);
|
assert(!f || f->_alive);
|
||||||
|
WRITE_INT(store, f ? f->no : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static faction *dead_factions;
|
static faction *dead_factions;
|
||||||
|
|
|
@ -203,12 +203,12 @@ void write_groups(struct storage *store, const faction * f)
|
||||||
WRITE_INT(store, g->gid);
|
WRITE_INT(store, g->gid);
|
||||||
WRITE_STR(store, g->name);
|
WRITE_STR(store, g->name);
|
||||||
for (a = g->allies; a; a = a->next) {
|
for (a = g->allies; a; a = a->next) {
|
||||||
if (a->faction) {
|
if (a->faction && a->faction->_alive) {
|
||||||
write_faction_reference(a->faction, store);
|
write_faction_reference(a->faction, store);
|
||||||
WRITE_INT(store, a->status);
|
WRITE_INT(store, a->status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
WRITE_INT(store, 0);
|
write_faction_reference(NULL, store);
|
||||||
a_write(store, g->attribs, g);
|
a_write(store, g->attribs, g);
|
||||||
WRITE_SECTION(store);
|
WRITE_SECTION(store);
|
||||||
}
|
}
|
||||||
|
@ -233,7 +233,7 @@ void read_groups(struct storage *store, faction * f)
|
||||||
ally *a;
|
ally *a;
|
||||||
variant fid;
|
variant fid;
|
||||||
|
|
||||||
READ_INT(store, &fid.i);
|
fid = read_faction_reference(store);
|
||||||
if (fid.i <= 0)
|
if (fid.i <= 0)
|
||||||
break;
|
break;
|
||||||
a = ally_add(pa, findfaction(fid.i));
|
a = ally_add(pa, findfaction(fid.i));
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
#include "faction.h"
|
#include "faction.h"
|
||||||
#include "unit.h"
|
#include "unit.h"
|
||||||
#include "region.h"
|
#include "region.h"
|
||||||
|
#include <util/attrib.h>
|
||||||
|
#include <attributes/key.h>
|
||||||
#include <stream.h>
|
#include <stream.h>
|
||||||
#include <filestream.h>
|
#include <filestream.h>
|
||||||
#include <storage.h>
|
#include <storage.h>
|
||||||
|
@ -22,34 +24,47 @@ static void test_group_readwrite(CuTest * tc)
|
||||||
storage store;
|
storage store;
|
||||||
FILE *F;
|
FILE *F;
|
||||||
stream strm;
|
stream strm;
|
||||||
|
int i;
|
||||||
|
|
||||||
F = fopen("test.dat", "w");
|
F = fopen("test.dat", "wb");
|
||||||
fstream_init(&strm, F);
|
fstream_init(&strm, F);
|
||||||
binstore_init(&store, &strm);
|
binstore_init(&store, &strm);
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
test_create_world();
|
test_create_world();
|
||||||
f = test_create_faction(0);
|
f = test_create_faction(0);
|
||||||
g = new_group(f, "test", 42);
|
g = new_group(f, "NW", 42);
|
||||||
|
g = new_group(f, "Egoisten", 43);
|
||||||
|
a_add(&g->attribs, make_key(44));
|
||||||
al = ally_add(&g->allies, f);
|
al = ally_add(&g->allies, f);
|
||||||
al->status = HELP_GIVE;
|
al->status = HELP_GIVE;
|
||||||
write_groups(&store, f);
|
write_groups(&store, f);
|
||||||
|
WRITE_INT(&store, 47);
|
||||||
binstore_done(&store);
|
binstore_done(&store);
|
||||||
fstream_done(&strm);
|
fstream_done(&strm);
|
||||||
|
|
||||||
F = fopen("test.dat", "r");
|
F = fopen("test.dat", "rb");
|
||||||
fstream_init(&strm, F);
|
fstream_init(&strm, F);
|
||||||
binstore_init(&store, &strm);
|
binstore_init(&store, &strm);
|
||||||
f->groups = 0;
|
f->groups = 0;
|
||||||
free_group(g);
|
|
||||||
read_groups(&store, f);
|
read_groups(&store, f);
|
||||||
|
READ_INT(&store, &i);
|
||||||
binstore_done(&store);
|
binstore_done(&store);
|
||||||
fstream_done(&strm);
|
fstream_done(&strm);
|
||||||
|
|
||||||
|
CuAssertIntEquals(tc, 47, i);
|
||||||
CuAssertPtrNotNull(tc, f->groups);
|
CuAssertPtrNotNull(tc, f->groups);
|
||||||
CuAssertPtrNotNull(tc, f->groups->allies);
|
CuAssertIntEquals(tc, 42, f->groups->gid);
|
||||||
CuAssertPtrEquals(tc, 0, f->groups->allies->next);
|
CuAssertStrEquals(tc, "NW", f->groups->name);
|
||||||
CuAssertPtrEquals(tc, f, f->groups->allies->faction);
|
CuAssertPtrNotNull(tc, f->groups->next);
|
||||||
CuAssertIntEquals(tc, HELP_GIVE, f->groups->allies->status);
|
CuAssertIntEquals(tc, 43, f->groups->next->gid);
|
||||||
|
CuAssertStrEquals(tc, "Egoisten", f->groups->next->name);
|
||||||
|
CuAssertPtrEquals(tc, 0, f->groups->allies);
|
||||||
|
g = f->groups->next;
|
||||||
|
CuAssertPtrNotNull(tc, find_key(g->attribs, 44));
|
||||||
|
CuAssertPtrNotNull(tc, g->allies);
|
||||||
|
CuAssertPtrEquals(tc, 0, g->allies->next);
|
||||||
|
CuAssertPtrEquals(tc, f, g->allies->faction);
|
||||||
|
CuAssertIntEquals(tc, HELP_GIVE, g->allies->status);
|
||||||
remove("test.dat");
|
remove("test.dat");
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
struct faction;
|
||||||
struct region;
|
struct region;
|
||||||
struct faction;
|
struct faction;
|
||||||
struct plane;
|
struct plane;
|
||||||
|
|
|
@ -66,6 +66,7 @@ extern "C" {
|
||||||
struct message_list;
|
struct message_list;
|
||||||
struct rawmaterial;
|
struct rawmaterial;
|
||||||
struct item;
|
struct item;
|
||||||
|
struct faction;
|
||||||
|
|
||||||
#define MORALE_TAX_FACTOR 0.005 /* 0.5% tax per point of morale */
|
#define MORALE_TAX_FACTOR 0.005 /* 0.5% tax per point of morale */
|
||||||
#define MORALE_MAX 10 /* Maximum morale allowed */
|
#define MORALE_MAX 10 /* Maximum morale allowed */
|
||||||
|
|
|
@ -513,7 +513,8 @@ static void read_owner(struct gamedata *data, region_owner ** powner)
|
||||||
int id;
|
int id;
|
||||||
READ_INT(data->store, &id);
|
READ_INT(data->store, &id);
|
||||||
owner->last_owner = id ? findfaction(id) : NULL;
|
owner->last_owner = id ? findfaction(id) : NULL;
|
||||||
} else if (data->version >= OWNER_2_VERSION) {
|
}
|
||||||
|
else if (data->version >= OWNER_2_VERSION) {
|
||||||
int id;
|
int id;
|
||||||
alliance *a;
|
alliance *a;
|
||||||
READ_INT(data->store, &id);
|
READ_INT(data->store, &id);
|
||||||
|
@ -535,11 +536,14 @@ static void read_owner(struct gamedata *data, region_owner ** powner)
|
||||||
static void write_owner(struct gamedata *data, region_owner * owner)
|
static void write_owner(struct gamedata *data, region_owner * owner)
|
||||||
{
|
{
|
||||||
if (owner) {
|
if (owner) {
|
||||||
|
faction *f;
|
||||||
WRITE_INT(data->store, owner->since_turn);
|
WRITE_INT(data->store, owner->since_turn);
|
||||||
WRITE_INT(data->store, owner->morale_turn);
|
WRITE_INT(data->store, owner->morale_turn);
|
||||||
WRITE_INT(data->store, owner->flags);
|
WRITE_INT(data->store, owner->flags);
|
||||||
write_faction_reference(owner->last_owner, data->store);
|
f = owner->last_owner;
|
||||||
write_faction_reference(owner->owner, data->store);
|
write_faction_reference((f && f->_alive) ? f : NULL, data->store);
|
||||||
|
f = owner->owner;
|
||||||
|
write_faction_reference((f && f->_alive) ? f : NULL, data->store);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
WRITE_INT(data->store, -1);
|
WRITE_INT(data->store, -1);
|
||||||
|
|
|
@ -79,7 +79,7 @@ static void changefaction_write(const trigger * t, struct storage *store)
|
||||||
{
|
{
|
||||||
changefaction_data *td = (changefaction_data *)t->data.v;
|
changefaction_data *td = (changefaction_data *)t->data.v;
|
||||||
write_unit_reference(td->unit, store);
|
write_unit_reference(td->unit, store);
|
||||||
write_faction_reference(td->faction, store);
|
write_faction_reference(td->faction->_alive ? td->faction : NULL, store);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int changefaction_read(trigger * t, struct storage *store)
|
static int changefaction_read(trigger * t, struct storage *store)
|
||||||
|
|
|
@ -82,7 +82,7 @@ static int createunit_handle(trigger * t, void *data)
|
||||||
static void createunit_write(const trigger * t, struct storage *store)
|
static void createunit_write(const trigger * t, struct storage *store)
|
||||||
{
|
{
|
||||||
createunit_data *td = (createunit_data *)t->data.v;
|
createunit_data *td = (createunit_data *)t->data.v;
|
||||||
write_faction_reference(td->f, store);
|
write_faction_reference(td->f->_alive ? td->f : NULL, store);
|
||||||
write_region_reference(td->r, store);
|
write_region_reference(td->r, store);
|
||||||
write_race_reference(td->race, store);
|
write_race_reference(td->race, store);
|
||||||
WRITE_INT(store, td->number);
|
WRITE_INT(store, td->number);
|
||||||
|
@ -93,7 +93,6 @@ static int createunit_read(trigger * t, struct storage *store)
|
||||||
createunit_data *td = (createunit_data *)t->data.v;
|
createunit_data *td = (createunit_data *)t->data.v;
|
||||||
variant var;
|
variant var;
|
||||||
int result = AT_READ_OK;
|
int result = AT_READ_OK;
|
||||||
|
|
||||||
var = read_faction_reference(store);
|
var = read_faction_reference(store);
|
||||||
if (var.i > 0) {
|
if (var.i > 0) {
|
||||||
td->f = findfaction(var.i);
|
td->f = findfaction(var.i);
|
||||||
|
@ -104,6 +103,8 @@ static int createunit_read(trigger * t, struct storage *store)
|
||||||
else {
|
else {
|
||||||
result = AT_READ_FAIL;
|
result = AT_READ_FAIL;
|
||||||
}
|
}
|
||||||
|
// read_reference(&td->f, store, read_faction_reference, resolve_faction);
|
||||||
|
|
||||||
read_reference(&td->r, store, read_region_reference,
|
read_reference(&td->r, store, read_region_reference,
|
||||||
RESOLVE_REGION(global.data_version));
|
RESOLVE_REGION(global.data_version));
|
||||||
td->race = (const struct race *)read_race_reference(store).v;
|
td->race = (const struct race *)read_race_reference(store).v;
|
||||||
|
|
|
@ -58,6 +58,7 @@ resolve_fun resolver)
|
||||||
|
|
||||||
void ur_add(variant data, void *ptrptr, resolve_fun fun)
|
void ur_add(variant data, void *ptrptr, resolve_fun fun)
|
||||||
{
|
{
|
||||||
|
assert(ptrptr);
|
||||||
if (ur_list == NULL) {
|
if (ur_list == NULL) {
|
||||||
ur_list = malloc(BLOCKSIZE * sizeof(unresolved));
|
ur_list = malloc(BLOCKSIZE * sizeof(unresolved));
|
||||||
ur_begin = ur_current = ur_list;
|
ur_begin = ur_current = ur_list;
|
||||||
|
@ -86,6 +87,7 @@ void resolve(void)
|
||||||
ur_list = ur;
|
ur_list = ur;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
assert(ur->ptrptr);
|
||||||
ur->resolve(ur->data, ur->ptrptr);
|
ur->resolve(ur->data, ur->ptrptr);
|
||||||
++ur;
|
++ur;
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
|
@ -1,4 +1,16 @@
|
||||||
ERESSEA 6rLo "4jLm82"
|
ERESSEA 6rLo "6rLo"
|
||||||
EINHEIT 7Lgf
|
EINHEIT 7Lgf
|
||||||
NACH NW NW
|
NACH NW NW
|
||||||
NAECHSTER
|
NAECHSTER
|
||||||
|
ERESSEA w86y "w86y"
|
||||||
|
EINHEIT uc3u
|
||||||
|
STIRB "mrqa"
|
||||||
|
NAECHSTER
|
||||||
|
ERESSEA ngij "ngij"
|
||||||
|
EINHEIT iwbz
|
||||||
|
HELFE w86y ALLES
|
||||||
|
EINHEIT j536
|
||||||
|
GRUPPE "Hodor"
|
||||||
|
HELFE w86y ALLES
|
||||||
|
HELFE w86y SILBER NICHT
|
||||||
|
NAECHSTER
|
||||||
|
|
|
@ -37,7 +37,7 @@ SUPP=../share/ubuntu-12_04.supp
|
||||||
SERVER="$VALGRIND --suppressions=$SUPP --error-exitcode=1 --leak-check=no $SERVER"
|
SERVER="$VALGRIND --suppressions=$SUPP --error-exitcode=1 --leak-check=no $SERVER"
|
||||||
fi
|
fi
|
||||||
echo "running $SERVER"
|
echo "running $SERVER"
|
||||||
$SERVER -t 184 ../scripts/run-turn.lua
|
$SERVER -t 184 test-turn.lua
|
||||||
[ -d reports ] || quit 4 "no reports directory created"
|
[ -d reports ] || quit 4 "no reports directory created"
|
||||||
CRFILE=185-zvto.cr
|
CRFILE=185-zvto.cr
|
||||||
for file in $NEWFILES reports/$CRFILE ; do
|
for file in $NEWFILES reports/$CRFILE ; do
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
dofile('../scripts/run-turn.lua')
|
||||||
|
turn = get_turn()
|
||||||
|
eressea.free_game()
|
||||||
|
print("trying to read data from " .. turn)
|
||||||
|
eressea.read_game(turn .. ".dat")
|
Loading…
Reference in New Issue