forked from github/server
Merge branch 'develop' of https://github.com/ennorehling/eressea into develop
This commit is contained in:
commit
c981bfb766
17 changed files with 63 additions and 64 deletions
|
@ -98,7 +98,7 @@ static int obs_read(variant *var, void *owner, struct gamedata *data)
|
|||
obs_data *od = (obs_data *)var->v;
|
||||
|
||||
UNUSED_ARG(owner);
|
||||
read_faction_reference(data, &od->f, NULL);
|
||||
read_faction_reference(data, &od->f);
|
||||
READ_INT(data->store, &od->skill);
|
||||
READ_INT(data->store, &od->timer);
|
||||
return AT_READ_OK;
|
||||
|
|
|
@ -36,7 +36,7 @@ write_targetregion(const variant *var, const void *owner, struct storage *store)
|
|||
|
||||
static int read_targetregion(variant *var, void *owner, gamedata *data)
|
||||
{
|
||||
if (read_region_reference(data, (region **)&var->v, NULL) <= 0) {
|
||||
if (read_region_reference(data, (region **)&var->v) <= 0) {
|
||||
return AT_READ_FAIL;
|
||||
}
|
||||
return AT_READ_OK;
|
||||
|
|
|
@ -359,15 +359,14 @@ void resolve_building(building *b)
|
|||
resolve(RESOLVE_BUILDING | b->no, b);
|
||||
}
|
||||
|
||||
int read_building_reference(gamedata * data, building **bp, resolve_fun fun)
|
||||
int read_building_reference(gamedata * data, building **bp)
|
||||
{
|
||||
int id;
|
||||
READ_INT(data->store, &id);
|
||||
if (id > 0) {
|
||||
*bp = findbuilding(id);
|
||||
if (*bp == NULL) {
|
||||
*bp = NULL;
|
||||
ur_add(RESOLVE_BUILDING | id, (void**)bp, fun);
|
||||
*bp = building_create(id);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -376,17 +375,23 @@ int read_building_reference(gamedata * data, building **bp, resolve_fun fun)
|
|||
return id;
|
||||
}
|
||||
|
||||
building *building_create(int id)
|
||||
{
|
||||
building *b = (building *)calloc(1, sizeof(building));
|
||||
b->no = id;
|
||||
bhash(b);
|
||||
return b;
|
||||
}
|
||||
|
||||
building *new_building(const struct building_type * btype, region * r,
|
||||
const struct locale * lang)
|
||||
{
|
||||
building **bptr = &r->buildings;
|
||||
building *b = (building *)calloc(1, sizeof(building));
|
||||
int id = newcontainerid();
|
||||
building *b = building_create(id);
|
||||
const char *bname;
|
||||
char buffer[32];
|
||||
|
||||
b->no = newcontainerid();
|
||||
bhash(b);
|
||||
|
||||
b->type = btype;
|
||||
b->region = r;
|
||||
while (*bptr)
|
||||
|
|
|
@ -127,6 +127,7 @@ extern "C" {
|
|||
const char *write_buildingname(const building * b, char *ibuf,
|
||||
size_t size);
|
||||
int buildingcapacity(const struct building *b);
|
||||
struct building *building_create(int id);
|
||||
struct building *new_building(const struct building_type *typ,
|
||||
struct region *r, const struct locale *lang);
|
||||
int build_building(struct unit *u, const struct building_type *typ,
|
||||
|
@ -166,7 +167,7 @@ extern "C" {
|
|||
void resolve_building(building *b);
|
||||
void write_building_reference(const struct building *b,
|
||||
struct storage *store);
|
||||
int read_building_reference(struct gamedata * data, struct building **bp, resolve_fun fun);
|
||||
int read_building_reference(struct gamedata * data, struct building **bp);
|
||||
|
||||
struct building *findbuilding(int n);
|
||||
|
||||
|
|
|
@ -229,7 +229,7 @@ int curse_read(variant *var, void *owner, gamedata *data)
|
|||
READ_INT(store, &c->data.i);
|
||||
}
|
||||
if (c->type->typ == CURSETYP_REGION) {
|
||||
int rr = read_region_reference(data, (region **)&c->data.v, NULL);
|
||||
int rr = read_region_reference(data, (region **)&c->data.v);
|
||||
if (ur == 0 && rr == 0 && !c->data.v) {
|
||||
return AT_READ_FAIL;
|
||||
}
|
||||
|
|
|
@ -54,7 +54,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <util/parser.h>
|
||||
#include <util/password.h>
|
||||
#include <util/path.h>
|
||||
#include <util/resolve.h>
|
||||
#include <util/rng.h>
|
||||
#include <util/strings.h>
|
||||
#include <util/variant.h>
|
||||
|
@ -331,20 +330,14 @@ bool checkpasswd(const faction * f, const char *passwd)
|
|||
return true;
|
||||
}
|
||||
|
||||
void resolve_faction(faction *f)
|
||||
{
|
||||
resolve(RESOLVE_FACTION | f->no, f);
|
||||
}
|
||||
|
||||
int read_faction_reference(gamedata * data, faction **fp, resolve_fun fun)
|
||||
int read_faction_reference(gamedata * data, faction **fp)
|
||||
{
|
||||
int id;
|
||||
READ_INT(data->store, &id);
|
||||
if (id > 0) {
|
||||
*fp = findfaction(id);
|
||||
if (*fp == NULL) {
|
||||
*fp = NULL;
|
||||
ur_add(RESOLVE_FACTION | id, (void **)fp, fun);
|
||||
*fp = faction_create(id);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -133,10 +133,7 @@ extern "C" {
|
|||
|
||||
void write_faction_reference(const struct faction *f,
|
||||
struct storage *store);
|
||||
int read_faction_reference(struct gamedata *data, struct faction **fp, resolve_fun fun);
|
||||
|
||||
#define RESOLVE_FACTION (TYP_FACTION << 24)
|
||||
void resolve_faction(struct faction *f);
|
||||
int read_faction_reference(struct gamedata *data, struct faction **fp);
|
||||
|
||||
void renumber_faction(faction * f, int no);
|
||||
void free_factions(void);
|
||||
|
|
|
@ -242,7 +242,7 @@ static void unhash_uid(region * r)
|
|||
uidhash[key].r = NULL;
|
||||
}
|
||||
|
||||
static void hash_uid(region * r)
|
||||
static void rhash_uid(region * r)
|
||||
{
|
||||
int uid = r->uid;
|
||||
for (;;) {
|
||||
|
@ -761,32 +761,35 @@ static region *last;
|
|||
|
||||
static unsigned int max_index = 0;
|
||||
|
||||
region *region_create(int uid)
|
||||
{
|
||||
region *r = (region *)calloc(1, sizeof(region));
|
||||
assert_alloc(r);
|
||||
r->uid = uid;
|
||||
rhash_uid(r);
|
||||
return r;
|
||||
}
|
||||
|
||||
region *new_region(int x, int y, struct plane *pl, int uid)
|
||||
{
|
||||
region *r;
|
||||
|
||||
pnormalize(&x, &y, pl);
|
||||
r = rfindhash(x, y);
|
||||
|
||||
if (r) {
|
||||
log_error("duplicate region discovered: %s(%d,%d)\n", regionname(r, NULL), x, y);
|
||||
if (r->units)
|
||||
log_error("duplicate region contains units\n");
|
||||
return r;
|
||||
if (!r) {
|
||||
r = region_create(uid);
|
||||
}
|
||||
r = (region *)calloc(sizeof(region), 1);
|
||||
assert_alloc(r);
|
||||
r->x = x;
|
||||
r->y = y;
|
||||
r->uid = uid;
|
||||
r->age = 1;
|
||||
r->_plane = pl;
|
||||
rhash(r);
|
||||
hash_uid(r);
|
||||
if (last)
|
||||
if (last) {
|
||||
addlist(&last, r);
|
||||
else
|
||||
}
|
||||
else {
|
||||
addlist(®ions, r);
|
||||
}
|
||||
last = r;
|
||||
assert(r->next == NULL);
|
||||
r->index = ++max_index;
|
||||
|
@ -1263,7 +1266,7 @@ void resolve_region(region *r)
|
|||
resolve(RESOLVE_REGION | r->uid, r);
|
||||
}
|
||||
|
||||
int read_region_reference(gamedata * data, region **rp, resolve_fun fun)
|
||||
int read_region_reference(gamedata * data, region **rp)
|
||||
{
|
||||
struct storage * store = data->store;
|
||||
int id = 0;
|
||||
|
@ -1271,7 +1274,7 @@ int read_region_reference(gamedata * data, region **rp, resolve_fun fun)
|
|||
READ_INT(store, &id);
|
||||
*rp = findregionbyid(id);
|
||||
if (*rp == NULL) {
|
||||
ur_add(RESOLVE_REGION | id, (void **)rp, fun);
|
||||
*rp = region_create(id);
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
|
|
@ -225,6 +225,7 @@ extern "C" {
|
|||
const char *write_regionname(const struct region *r, const struct faction *f,
|
||||
char *buffer, size_t size);
|
||||
|
||||
struct region *region_create(int uid);
|
||||
struct region *new_region(int x, int y, struct plane *pl, int uid);
|
||||
void remove_region(region ** rlist, region * r);
|
||||
void terraform_region(struct region *r, const struct terrain_type *terrain);
|
||||
|
@ -252,7 +253,7 @@ extern "C" {
|
|||
#define RESOLVE_REGION (TYP_REGION << 24)
|
||||
void resolve_region(region *r);
|
||||
void write_region_reference(const struct region *r, struct storage *store);
|
||||
int read_region_reference(struct gamedata *data, region **rp, resolve_fun fun);
|
||||
int read_region_reference(struct gamedata *data, region **rp);
|
||||
|
||||
const char *regionname(const struct region *r, const struct faction *f);
|
||||
|
||||
|
|
|
@ -123,7 +123,7 @@ static void read_alliances(gamedata *data)
|
|||
READ_INT(store, &al->flags);
|
||||
}
|
||||
if (data->version >= ALLIANCELEADER_VERSION) {
|
||||
read_faction_reference(data, &al->_leader, NULL);
|
||||
read_faction_reference(data, &al->_leader);
|
||||
READ_INT(store, &id);
|
||||
}
|
||||
else {
|
||||
|
@ -248,7 +248,7 @@ static void read_owner(gamedata *data, region_owner ** powner)
|
|||
owner->flags = 0;
|
||||
}
|
||||
if (data->version >= OWNER_3_VERSION) {
|
||||
read_faction_reference(data, &owner->last_owner, NULL);
|
||||
read_faction_reference(data, &owner->last_owner);
|
||||
}
|
||||
else if (data->version >= OWNER_2_VERSION) {
|
||||
int id;
|
||||
|
@ -261,7 +261,7 @@ static void read_owner(gamedata *data, region_owner ** powner)
|
|||
else {
|
||||
owner->last_owner = NULL;
|
||||
}
|
||||
read_faction_reference(data, &owner->owner, NULL);
|
||||
read_faction_reference(data, &owner->owner);
|
||||
*powner = owner;
|
||||
}
|
||||
else {
|
||||
|
@ -420,10 +420,7 @@ unit *read_unit(gamedata *data)
|
|||
u_setfaction(u, NULL);
|
||||
}
|
||||
else {
|
||||
u = (unit *)calloc(1, sizeof(unit));
|
||||
assert_alloc(u);
|
||||
u->no = n;
|
||||
uhash(u);
|
||||
u = unit_create(n);
|
||||
}
|
||||
|
||||
READ_INT(data->store, &n);
|
||||
|
@ -1087,7 +1084,6 @@ faction *read_faction(gamedata * data)
|
|||
if (data->version >= REGIONOWNER_VERSION) {
|
||||
read_spellbook(FactionSpells() ? &f->spellbook : 0, data, get_spell_level_faction, (void *)f);
|
||||
}
|
||||
resolve_faction(f);
|
||||
return f;
|
||||
}
|
||||
|
||||
|
|
|
@ -1375,6 +1375,12 @@ void name_unit(unit * u)
|
|||
}
|
||||
}
|
||||
|
||||
unit *unit_create(int id)
|
||||
{
|
||||
unit *u = (unit *)calloc(1, sizeof(unit));
|
||||
createunitid(u, id);
|
||||
return u;
|
||||
}
|
||||
/** creates a new unit.
|
||||
*
|
||||
* @param dname: name, set to NULL to get a default.
|
||||
|
@ -1383,7 +1389,7 @@ void name_unit(unit * u)
|
|||
unit *create_unit(region * r, faction * f, int number, const struct race *urace,
|
||||
int id, const char *dname, unit * creator)
|
||||
{
|
||||
unit *u = (unit *)calloc(1, sizeof(unit));
|
||||
unit *u = unit_create(id);
|
||||
|
||||
assert(urace);
|
||||
u_setrace(u, urace);
|
||||
|
@ -1395,10 +1401,6 @@ unit *create_unit(region * r, faction * f, int number, const struct race *urace,
|
|||
|
||||
set_number(u, number);
|
||||
|
||||
/* die nummer der neuen einheit muss vor name_unit generiert werden,
|
||||
* da der default name immer noch 'Nummer u->no' ist */
|
||||
createunitid(u, id);
|
||||
|
||||
/* zuerst in die Region setzen, da zb Drachennamen den Regionsnamen
|
||||
* enthalten */
|
||||
if (r)
|
||||
|
|
|
@ -206,8 +206,9 @@ extern "C" {
|
|||
int invisible(const struct unit *target, const struct unit *viewer);
|
||||
void free_unit(struct unit *u);
|
||||
|
||||
extern void name_unit(struct unit *u);
|
||||
extern struct unit *create_unit(struct region *r1, struct faction *f,
|
||||
void name_unit(struct unit *u);
|
||||
struct unit *unit_create(int id);
|
||||
struct unit *create_unit(struct region *r1, struct faction *f,
|
||||
int number, const struct race *rc, int id, const char *dname,
|
||||
struct unit *creator);
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ static void xmasgate_write(const trigger * t, struct storage *store)
|
|||
|
||||
static int xmasgate_read(trigger * t, struct gamedata *data)
|
||||
{
|
||||
if (read_building_reference(data, (building **)&t->data.v, NULL) <= 0) {
|
||||
if (read_building_reference(data, (building **)&t->data.v) <= 0) {
|
||||
return AT_READ_FAIL;
|
||||
}
|
||||
return AT_READ_OK;
|
||||
|
|
|
@ -87,7 +87,7 @@ static int changefaction_read(trigger * t, gamedata *data)
|
|||
changefaction_data *td = (changefaction_data *)t->data.v;
|
||||
|
||||
read_unit_reference(data, &td->unit, NULL);
|
||||
return read_faction_reference(data, &td->faction, NULL) > 0 ? AT_READ_OK : AT_READ_FAIL;
|
||||
return read_faction_reference(data, &td->faction) > 0 ? AT_READ_OK : AT_READ_FAIL;
|
||||
}
|
||||
|
||||
trigger_type tt_changefaction = {
|
||||
|
|
|
@ -94,12 +94,12 @@ static int createunit_read(trigger * t, gamedata *data)
|
|||
int id;
|
||||
int result = AT_READ_OK;
|
||||
|
||||
id = read_faction_reference(data, &td->f, NULL);
|
||||
id = read_faction_reference(data, &td->f);
|
||||
if (id <= 0) {
|
||||
result = AT_READ_FAIL;
|
||||
}
|
||||
|
||||
read_region_reference(data, &td->r, NULL);
|
||||
read_region_reference(data, &td->r);
|
||||
td->race = read_race_reference(data->store);
|
||||
if (!td->race) {
|
||||
result = AT_READ_FAIL;
|
||||
|
|
|
@ -75,8 +75,8 @@ static void gate_write(const trigger * t, struct storage *store)
|
|||
static int gate_read(trigger * t, gamedata *data)
|
||||
{
|
||||
gate_data *gd = (gate_data *)t->data.v;
|
||||
int bc = read_building_reference(data, &gd->gate, NULL);
|
||||
int rc = read_region_reference(data, &gd->target, NULL);
|
||||
int bc = read_building_reference(data, &gd->gate);
|
||||
int rc = read_region_reference(data, &gd->target);
|
||||
|
||||
if (bc <= 0 && rc <= 0) {
|
||||
return AT_READ_FAIL;
|
||||
|
|
|
@ -103,7 +103,7 @@ static int wormhole_read(variant *var, void *owner, struct gamedata *data)
|
|||
if (data->version < ATTRIBOWNER_VERSION) {
|
||||
READ_INT(data->store, NULL);
|
||||
}
|
||||
id = read_region_reference(data, (region **)&var->v, NULL);
|
||||
id = read_region_reference(data, (region **)&var->v);
|
||||
return (id <= 0) ? AT_READ_FAIL : AT_READ_OK;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue