forked from github/server
new attribute "object" allows arbitrary named data to be added to any object (improvement on the "key" attribute)
This commit is contained in:
parent
402fbb24e5
commit
10b2d08a0a
|
@ -10,7 +10,6 @@ SubDirHdrs $(SUBDIR)/../.. ;
|
|||
SOURCES =
|
||||
aggressive.c
|
||||
alliance.c
|
||||
at_movement.c
|
||||
attributes.c
|
||||
fleechance.c
|
||||
follow.c
|
||||
|
@ -20,7 +19,9 @@ SOURCES =
|
|||
iceberg.c
|
||||
key.c
|
||||
matmod.c
|
||||
movement.c
|
||||
moved.c
|
||||
object.c
|
||||
option.c
|
||||
orcification.c
|
||||
otherfaction.c
|
||||
|
|
|
@ -17,34 +17,42 @@
|
|||
#include "attributes.h"
|
||||
|
||||
/* attributes includes */
|
||||
#include "key.h"
|
||||
#include "gm.h"
|
||||
#include "targetregion.h"
|
||||
#include "orcification.h"
|
||||
#include "reduceproduction.h"
|
||||
#include "follow.h"
|
||||
#include "iceberg.h"
|
||||
#include "gm.h"
|
||||
#include "hate.h"
|
||||
#include "overrideroads.h"
|
||||
#include "iceberg.h"
|
||||
#include "key.h"
|
||||
#include "moved.h"
|
||||
#include "movement.h"
|
||||
#include "object.h"
|
||||
#include "orcification.h"
|
||||
#include "otherfaction.h"
|
||||
#include "overrideroads.h"
|
||||
#include "racename.h"
|
||||
#include "raceprefix.h"
|
||||
#include "reduceproduction.h"
|
||||
#include "synonym.h"
|
||||
#include "at_movement.h"
|
||||
#include "targetregion.h"
|
||||
#include "variable.h"
|
||||
#ifdef USE_UGROUPS
|
||||
# include "ugroup.h"
|
||||
# include "ugroup.h"
|
||||
#endif
|
||||
#ifdef AT_OPTION
|
||||
# include "option.h"
|
||||
#endif
|
||||
#include "moved.h"
|
||||
#include "variable.h"
|
||||
#ifdef WDW_PYRAMID
|
||||
#include "alliance.h"
|
||||
# include "alliance.h"
|
||||
#endif
|
||||
|
||||
/* kernel includes */
|
||||
#include <kernel/unit.h>
|
||||
#include <kernel/faction.h>
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/ship.h>
|
||||
#include <kernel/building.h>
|
||||
|
||||
/* util includes */
|
||||
#include <attrib.h>
|
||||
#include <util/attrib.h>
|
||||
|
||||
/*
|
||||
* library initialization
|
||||
|
@ -53,6 +61,7 @@
|
|||
void
|
||||
init_attributes(void)
|
||||
{
|
||||
at_register(&at_object);
|
||||
at_register(&at_overrideroads);
|
||||
at_register(&at_raceprefix);
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
ProjectType="Visual C++"
|
||||
Version="7.10"
|
||||
Name="attributes"
|
||||
RootNamespace="attributes"
|
||||
SccProjectName=""
|
||||
SccLocalPath="">
|
||||
<Platforms>
|
||||
|
@ -205,6 +206,9 @@
|
|||
<File
|
||||
RelativePath=".\moved.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\object.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\option.h">
|
||||
</File>
|
||||
|
@ -245,9 +249,6 @@
|
|||
RelativePath=".\viewrange.h">
|
||||
</File>
|
||||
</Filter>
|
||||
<File
|
||||
RelativePath=".\at_movement.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\attributes.c">
|
||||
</File>
|
||||
|
@ -278,6 +279,15 @@
|
|||
<File
|
||||
RelativePath=".\moved.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\movement.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\movement.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\object.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\option.c">
|
||||
</File>
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
#include <config.h>
|
||||
#include <eressea.h>
|
||||
#include <attrib.h>
|
||||
#include "at_movement.h"
|
||||
#include "movement.h"
|
||||
|
||||
static void
|
||||
write_movement(const attrib * a, FILE * F)
|
|
@ -0,0 +1,177 @@
|
|||
/* vi: set ts=2:
|
||||
*
|
||||
*
|
||||
* Eressea PB(E)M host Copyright (C) 1998-2003
|
||||
* Christian Schlittchen (corwin@amber.kn-bremen.de)
|
||||
* Katja Zedel (katze@felidae.kn-bremen.de)
|
||||
* Henning Peters (faroul@beyond.kn-bremen.de)
|
||||
* Enno Rehling (enno@eressea-pbem.de)
|
||||
* Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de)
|
||||
*
|
||||
* This program may not be used, modified or distributed without
|
||||
* prior permission by the authors of Eressea.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <eressea.h>
|
||||
#include "object.h"
|
||||
|
||||
/* kernel includes */
|
||||
#include <kernel/unit.h>
|
||||
#include <kernel/faction.h>
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/ship.h>
|
||||
#include <kernel/building.h>
|
||||
|
||||
/* util includes */
|
||||
#include <util/attrib.h>
|
||||
|
||||
/* stdc includes */
|
||||
#include <string.h>
|
||||
|
||||
typedef struct object_data {
|
||||
object_type type;
|
||||
char * name;
|
||||
union {
|
||||
int i;
|
||||
char * str;
|
||||
double real;
|
||||
struct unit * u;
|
||||
struct region * r;
|
||||
struct building * b;
|
||||
struct ship * sh;
|
||||
struct faction * f;
|
||||
} data;
|
||||
} object_data;
|
||||
|
||||
static void
|
||||
object_write(const attrib *a, FILE *F)
|
||||
{
|
||||
const object_data * data = (object_data *)a->data.v;
|
||||
int type = (int)data->type;
|
||||
fprintf(F, "%s %d", data->name, type);
|
||||
switch (data->type) {
|
||||
case TUNIT:
|
||||
write_unit_reference(data->data.u, F);
|
||||
break;
|
||||
case TFACTION:
|
||||
write_faction_reference(data->data.f, F);
|
||||
break;
|
||||
case TBUILDING:
|
||||
write_building_reference(data->data.b, F);
|
||||
break;
|
||||
case TSHIP:
|
||||
/* write_ship_reference(data->data.sh, F); */
|
||||
assert(!"not implemented");
|
||||
break;
|
||||
case TREGION:
|
||||
write_region_reference(data->data.r, F);
|
||||
break;
|
||||
case TNONE:
|
||||
break;
|
||||
default:
|
||||
assert(!"illegal type in object-attribute");
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
object_read(attrib *a, FILE *F)
|
||||
{
|
||||
object_data * data = (object_data *)a->data.v;
|
||||
int type;
|
||||
char name[64];
|
||||
fscanf(F, "%s %d", name, &type);
|
||||
data->type = (object_type)type;
|
||||
switch (data->type) {
|
||||
case TUNIT:
|
||||
return read_unit_reference(&data->data.u, F);
|
||||
case TFACTION:
|
||||
return read_faction_reference(&data->data.f, F);
|
||||
case TBUILDING:
|
||||
return read_building_reference(&data->data.b, F);
|
||||
case TSHIP:
|
||||
/* return read_ship_reference(&data->data.sh, F); */
|
||||
assert(!"not implemented");
|
||||
break;
|
||||
case TREGION:
|
||||
return read_region_reference(&data->data.r, F);
|
||||
case TNONE:
|
||||
break;
|
||||
default:
|
||||
return AT_READ_FAIL;
|
||||
}
|
||||
return AT_READ_OK;
|
||||
}
|
||||
|
||||
static void
|
||||
object_init(attrib * a)
|
||||
{
|
||||
object_data * data;
|
||||
a->data.v = malloc(sizeof(object_data));
|
||||
data = (object_data *)a->data.v;
|
||||
data->type = TNONE;
|
||||
}
|
||||
|
||||
static void
|
||||
object_done(attrib * a)
|
||||
{
|
||||
object_data * data = (object_data *)a->data.v;
|
||||
if (data->type == TSTRING) free(data->data.str);
|
||||
free(a->data.v);
|
||||
}
|
||||
|
||||
attrib_type at_object = {
|
||||
"object", object_init, object_done, NULL,
|
||||
object_write, object_read
|
||||
};
|
||||
|
||||
const char *
|
||||
object_name(const attrib * a)
|
||||
{
|
||||
object_data * data = (object_data *)a->data.v;
|
||||
return data->name;
|
||||
}
|
||||
|
||||
struct attrib *
|
||||
object_create(const char * name, object_type type, variant value)
|
||||
{
|
||||
attrib * a = a_new(&at_object);
|
||||
object_data * data = (object_data *)a->data.v;
|
||||
|
||||
data->type = type;
|
||||
data->name = strdup(name);
|
||||
switch (type) {
|
||||
case TSTRING:
|
||||
data->data.str = strdup(value.v);
|
||||
break;
|
||||
case TINTEGER:
|
||||
data->data.i = value.i;
|
||||
break;
|
||||
case TREAL:
|
||||
data->data.real = value.f;
|
||||
break;
|
||||
case TREGION:
|
||||
data->data.r = (region*)value.v;
|
||||
break;
|
||||
case TBUILDING:
|
||||
data->data.b = (building*)value.v;
|
||||
break;
|
||||
case TFACTION:
|
||||
data->data.f = (faction*)value.v;
|
||||
break;
|
||||
case TUNIT:
|
||||
data->data.u = (unit*)value.v;
|
||||
break;
|
||||
case TSHIP:
|
||||
data->data.sh = (ship*)value.v;
|
||||
break;
|
||||
case TNONE:
|
||||
break;
|
||||
default:
|
||||
assert(!"invalid object-type");
|
||||
break;
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
extern void object_get(const struct attrib * a, variant * value, object_type * type);
|
|
@ -0,0 +1,37 @@
|
|||
/* vi: set ts=2:
|
||||
+-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
| | Enno Rehling <enno@eressea-pbem.de>
|
||||
| Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>
|
||||
| (c) 1998 - 2003 | Henning Peters <faroul@beyond.kn-bremen.de>
|
||||
| | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.de>
|
||||
+-------------------+ Stefan Reich <reich@halbling.de>
|
||||
|
||||
This program may not be used, modified or distributed
|
||||
without prior permission by the authors of Eressea.
|
||||
*/
|
||||
|
||||
#ifndef H_ATTRIBUTE_OBJECT
|
||||
#define H_ATTRIBUTE_OBJECT
|
||||
|
||||
#include <util/variant.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
TNONE = 0, TINTEGER = 1, TREAL = 2, TSTRING = 3,
|
||||
TUNIT = 10, TFACTION = 11, TREGION = 12, TBUILDING = 13, TSHIP = 14,
|
||||
} object_type;
|
||||
|
||||
extern attrib_type at_object;
|
||||
|
||||
extern struct attrib * object_create(const char * name, object_type type, variant value);
|
||||
extern void object_get(const struct attrib * a, variant * value, object_type * type);
|
||||
extern const char * object_name(const struct attrib * a);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
|
@ -30,6 +30,7 @@
|
|||
#include <util/base36.h>
|
||||
#include <util/event.h>
|
||||
#include <util/goodies.h>
|
||||
#include <util/resolve.h>
|
||||
#include <util/variant.h>
|
||||
|
||||
#include <attributes/otherfaction.h>
|
||||
|
@ -178,6 +179,33 @@ checkpasswd(const faction * f, const char * passwd, boolean shortp)
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
read_faction_reference(faction ** f, FILE * F)
|
||||
{
|
||||
variant id;
|
||||
if (global.data_version >= BASE36IDS_VERSION) {
|
||||
char zText[10];
|
||||
fscanf(F, "%s ", zText);
|
||||
id.i = atoi36(zText);
|
||||
} else {
|
||||
fscanf(F, "%d ", &id.i);
|
||||
}
|
||||
if (id.i<0) {
|
||||
*f = NULL;
|
||||
return AT_READ_FAIL;
|
||||
}
|
||||
*f = findfaction(id.i);
|
||||
if (*f==NULL) ur_add(id, (void**)f, resolve_faction);
|
||||
return AT_READ_OK;
|
||||
}
|
||||
|
||||
void
|
||||
write_faction_reference(const faction * f, FILE * F)
|
||||
{
|
||||
fprintf(F, "%s ", itoa36(f->no));
|
||||
}
|
||||
|
||||
void
|
||||
destroyfaction(faction * f)
|
||||
{
|
||||
|
|
|
@ -130,6 +130,10 @@ extern void add_enemy(struct faction * f, struct faction * enemy);
|
|||
extern void remove_enemy(struct faction * f, struct faction * enemy);
|
||||
#endif
|
||||
|
||||
extern void write_faction_reference(const struct faction * f, FILE * F);
|
||||
extern int read_faction_reference(struct faction ** f, FILE * F);
|
||||
|
||||
|
||||
#ifdef SMART_INTERVALS
|
||||
extern void update_interval(struct faction * f, struct region * r);
|
||||
#endif
|
||||
|
|
|
@ -60,7 +60,7 @@
|
|||
/* attributes includes */
|
||||
#include <attributes/follow.h>
|
||||
#include <attributes/targetregion.h>
|
||||
#include <attributes/at_movement.h>
|
||||
#include <attributes/movement.h>
|
||||
#include <attributes/otherfaction.h>
|
||||
|
||||
int * storms;
|
||||
|
|
|
@ -988,32 +988,6 @@ lastturn(void)
|
|||
return turn;
|
||||
}
|
||||
|
||||
int
|
||||
read_faction_reference(faction ** f, FILE * F)
|
||||
{
|
||||
variant id;
|
||||
if (global.data_version >= BASE36IDS_VERSION) {
|
||||
char zText[10];
|
||||
fscanf(F, "%s ", zText);
|
||||
id.i = atoi36(zText);
|
||||
} else {
|
||||
fscanf(F, "%d ", &id.i);
|
||||
}
|
||||
if (id.i<0) {
|
||||
*f = NULL;
|
||||
return AT_READ_FAIL;
|
||||
}
|
||||
*f = findfaction(id.i);
|
||||
if (*f==NULL) ur_add(id, (void**)f, resolve_faction);
|
||||
return AT_READ_OK;
|
||||
}
|
||||
|
||||
void
|
||||
write_faction_reference(const faction * f, FILE * F)
|
||||
{
|
||||
fprintf(F, "%s ", itoa36(f->no));
|
||||
}
|
||||
|
||||
void
|
||||
fwriteorder(FILE * F, const order * ord, const struct locale * lang)
|
||||
{
|
||||
|
|
|
@ -56,9 +56,6 @@ extern void write_items(FILE *f, struct item *it);
|
|||
extern void a_read(FILE * f, struct attrib ** attribs);
|
||||
extern void a_write(FILE * f, const struct attrib * attribs);
|
||||
|
||||
extern void write_faction_reference(const struct faction * f, FILE * F);
|
||||
extern int read_faction_reference(struct faction ** f, FILE * F);
|
||||
|
||||
extern const char * datapath(void);
|
||||
|
||||
#if RESOURCE_CONVERSION
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
#include <unit.h>
|
||||
#include <base36.h>
|
||||
|
||||
#include <attributes/at_movement.h>
|
||||
#include <attributes/movement.h>
|
||||
|
||||
/* libc includes */
|
||||
#include <ctype.h>
|
||||
|
|
Loading…
Reference in New Issue