Merge remote-tracking branch 'upstream/master'

Conflicts:
	src/kernel/save.c
	src/triggers/createunit.c
This commit is contained in:
Enno Rehling 2016-02-23 08:35:31 +01:00
commit 1bb215dd52
15 changed files with 82 additions and 37 deletions

View File

@ -58,7 +58,8 @@ attrib_type at_otherfaction = {
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)

View File

@ -384,8 +384,9 @@ static int tolua_faction_create(lua_State * L)
static int tolua_faction_get_password(lua_State * L)
{
unused_arg(L);
return 0;
faction *self = (faction *)tolua_tousertype(L, 1, 0);
tolua_pushstring(L, self->_password);
return 1;
}
static int tolua_faction_set_password(lua_State * L)

View File

@ -217,6 +217,7 @@ int resolve_faction(variant id, void *address)
result = -1;
}
}
assert(address);
*(faction **)address = f;
return result;
}
@ -333,7 +334,8 @@ variant read_faction_reference(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;

View File

@ -203,12 +203,12 @@ void write_groups(struct storage *store, const faction * f)
WRITE_INT(store, g->gid);
WRITE_STR(store, g->name);
for (a = g->allies; a; a = a->next) {
if (a->faction) {
if (a->faction && a->faction->_alive) {
write_faction_reference(a->faction, store);
WRITE_INT(store, a->status);
}
}
WRITE_INT(store, 0);
write_faction_reference(NULL, store);
a_write(store, g->attribs, g);
WRITE_SECTION(store);
}
@ -233,7 +233,7 @@ void read_groups(struct storage *store, faction * f)
ally *a;
variant fid;
READ_INT(store, &fid.i);
fid = read_faction_reference(store);
if (fid.i <= 0)
break;
a = ally_add(pa, findfaction(fid.i));

View File

@ -5,6 +5,8 @@
#include "faction.h"
#include "unit.h"
#include "region.h"
#include <util/attrib.h>
#include <attributes/key.h>
#include <stream.h>
#include <filestream.h>
#include <storage.h>
@ -22,34 +24,47 @@ static void test_group_readwrite(CuTest * tc)
storage store;
FILE *F;
stream strm;
int i;
F = fopen("test.dat", "w");
F = fopen("test.dat", "wb");
fstream_init(&strm, F);
binstore_init(&store, &strm);
test_cleanup();
test_create_world();
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->status = HELP_GIVE;
write_groups(&store, f);
WRITE_INT(&store, 47);
binstore_done(&store);
fstream_done(&strm);
F = fopen("test.dat", "r");
F = fopen("test.dat", "rb");
fstream_init(&strm, F);
binstore_init(&store, &strm);
f->groups = 0;
free_group(g);
read_groups(&store, f);
READ_INT(&store, &i);
binstore_done(&store);
fstream_done(&strm);
CuAssertIntEquals(tc, 47, i);
CuAssertPtrNotNull(tc, f->groups);
CuAssertPtrNotNull(tc, f->groups->allies);
CuAssertPtrEquals(tc, 0, f->groups->allies->next);
CuAssertPtrEquals(tc, f, f->groups->allies->faction);
CuAssertIntEquals(tc, HELP_GIVE, f->groups->allies->status);
CuAssertIntEquals(tc, 42, f->groups->gid);
CuAssertStrEquals(tc, "NW", f->groups->name);
CuAssertPtrNotNull(tc, f->groups->next);
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");
test_cleanup();
}

View File

@ -22,6 +22,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
extern "C" {
#endif
struct faction;
struct region;
struct faction;
struct plane;

View File

@ -66,6 +66,7 @@ extern "C" {
struct message_list;
struct rawmaterial;
struct item;
struct faction;
#define MORALE_TAX_FACTOR 0.005 /* 0.5% tax per point of morale */
#define MORALE_MAX 10 /* Maximum morale allowed */

View File

@ -513,7 +513,8 @@ static void read_owner(struct gamedata *data, region_owner ** powner)
int id;
READ_INT(data->store, &id);
owner->last_owner = id ? findfaction(id) : NULL;
} else if (data->version >= OWNER_2_VERSION) {
}
else if (data->version >= OWNER_2_VERSION) {
int id;
alliance *a;
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)
{
if (owner) {
faction *f;
WRITE_INT(data->store, owner->since_turn);
WRITE_INT(data->store, owner->morale_turn);
WRITE_INT(data->store, owner->flags);
write_faction_reference(owner->last_owner, data->store);
write_faction_reference(owner->owner, data->store);
f = owner->last_owner;
write_faction_reference((f && f->_alive) ? f : NULL, data->store);
f = owner->owner;
write_faction_reference((f && f->_alive) ? f : NULL, data->store);
}
else {
WRITE_INT(data->store, -1);

View File

@ -79,7 +79,7 @@ static void changefaction_write(const trigger * t, struct storage *store)
{
changefaction_data *td = (changefaction_data *)t->data.v;
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)

View File

@ -82,7 +82,7 @@ static int createunit_handle(trigger * t, void *data)
static void createunit_write(const trigger * t, struct storage *store)
{
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_race_reference(td->race, store);
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;
variant var;
int result = AT_READ_OK;
var = read_faction_reference(store);
if (var.i > 0) {
td->f = findfaction(var.i);
@ -104,6 +103,8 @@ static int createunit_read(trigger * t, struct storage *store)
else {
result = AT_READ_FAIL;
}
// read_reference(&td->f, store, read_faction_reference, resolve_faction);
read_reference(&td->r, store, read_region_reference,
RESOLVE_REGION(global.data_version));
td->race = (const struct race *)read_race_reference(store).v;

View File

@ -58,6 +58,7 @@ resolve_fun resolver)
void ur_add(variant data, void *ptrptr, resolve_fun fun)
{
assert(ptrptr);
if (ur_list == NULL) {
ur_list = malloc(BLOCKSIZE * sizeof(unresolved));
ur_begin = ur_current = ur_list;
@ -86,6 +87,7 @@ void resolve(void)
ur_list = ur;
continue;
}
assert(ur->ptrptr);
ur->resolve(ur->data, ur->ptrptr);
++ur;
}

Binary file not shown.

View File

@ -1,4 +1,16 @@
ERESSEA 6rLo "4jLm82"
ERESSEA 6rLo "6rLo"
EINHEIT 7Lgf
NACH NW NW
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

View File

@ -37,7 +37,7 @@ SUPP=../share/ubuntu-12_04.supp
SERVER="$VALGRIND --suppressions=$SUPP --error-exitcode=1 --leak-check=no $SERVER"
fi
echo "running $SERVER"
$SERVER -t 184 ../scripts/run-turn.lua
$SERVER -t 184 test-turn.lua
[ -d reports ] || quit 4 "no reports directory created"
CRFILE=185-zvto.cr
for file in $NEWFILES reports/$CRFILE ; do

5
tests/test-turn.lua Normal file
View File

@ -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")