forked from github/server
new attribute "object" allows arbitrary named data to be added to any object (improvement on the "key" attribute)
exported to LUA: x.objects returns the collection of objects, accessible through :get() and :set() functions
This commit is contained in:
parent
10b2d08a0a
commit
d808de65c8
15 changed files with 482 additions and 234 deletions
|
@ -49,8 +49,17 @@ object_write(const attrib *a, FILE *F)
|
||||||
{
|
{
|
||||||
const object_data * data = (object_data *)a->data.v;
|
const object_data * data = (object_data *)a->data.v;
|
||||||
int type = (int)data->type;
|
int type = (int)data->type;
|
||||||
fprintf(F, "%s %d", data->name, type);
|
fprintf(F, "%s %d ", data->name, type);
|
||||||
switch (data->type) {
|
switch (data->type) {
|
||||||
|
case TINTEGER:
|
||||||
|
fprintf(F, "%d ", data->data.i);
|
||||||
|
break;
|
||||||
|
case TREAL:
|
||||||
|
fprintf(F, "%lf ", data->data.real);
|
||||||
|
break;
|
||||||
|
case TSTRING:
|
||||||
|
fwritestr(F, data->data.str);
|
||||||
|
break;
|
||||||
case TUNIT:
|
case TUNIT:
|
||||||
write_unit_reference(data->data.u, F);
|
write_unit_reference(data->data.u, F);
|
||||||
break;
|
break;
|
||||||
|
@ -79,22 +88,33 @@ object_read(attrib *a, FILE *F)
|
||||||
{
|
{
|
||||||
object_data * data = (object_data *)a->data.v;
|
object_data * data = (object_data *)a->data.v;
|
||||||
int type;
|
int type;
|
||||||
char name[64];
|
char buffer[128];
|
||||||
fscanf(F, "%s %d", name, &type);
|
fscanf(F, "%s %d", buffer, &type);
|
||||||
|
data->name = strdup(buffer);
|
||||||
data->type = (object_type)type;
|
data->type = (object_type)type;
|
||||||
switch (data->type) {
|
switch (data->type) {
|
||||||
|
case TINTEGER:
|
||||||
|
fscanf(F, "%d", &data->data.i);
|
||||||
|
break;
|
||||||
|
case TREAL:
|
||||||
|
fscanf(F, "%lf", &data->data.real);
|
||||||
|
break;
|
||||||
|
case TSTRING:
|
||||||
|
freadstr(F, buffer, sizeof(buffer));
|
||||||
|
data->data.str = strdup(buffer);
|
||||||
|
break;
|
||||||
|
case TBUILDING:
|
||||||
|
return read_building_reference(&data->data.b, F);
|
||||||
case TUNIT:
|
case TUNIT:
|
||||||
return read_unit_reference(&data->data.u, F);
|
return read_unit_reference(&data->data.u, F);
|
||||||
case TFACTION:
|
case TFACTION:
|
||||||
return read_faction_reference(&data->data.f, F);
|
return read_faction_reference(&data->data.f, F);
|
||||||
case TBUILDING:
|
case TREGION:
|
||||||
return read_building_reference(&data->data.b, F);
|
return read_region_reference(&data->data.r, F);
|
||||||
case TSHIP:
|
case TSHIP:
|
||||||
/* return read_ship_reference(&data->data.sh, F); */
|
/* return read_ship_reference(&data->data.sh, F); */
|
||||||
assert(!"not implemented");
|
assert(!"not implemented");
|
||||||
break;
|
break;
|
||||||
case TREGION:
|
|
||||||
return read_region_reference(&data->data.r, F);
|
|
||||||
case TNONE:
|
case TNONE:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -117,6 +137,7 @@ object_done(attrib * a)
|
||||||
{
|
{
|
||||||
object_data * data = (object_data *)a->data.v;
|
object_data * data = (object_data *)a->data.v;
|
||||||
if (data->type == TSTRING) free(data->data.str);
|
if (data->type == TSTRING) free(data->data.str);
|
||||||
|
free(data->name);
|
||||||
free(a->data.v);
|
free(a->data.v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,9 +158,19 @@ object_create(const char * name, object_type type, variant value)
|
||||||
{
|
{
|
||||||
attrib * a = a_new(&at_object);
|
attrib * a = a_new(&at_object);
|
||||||
object_data * data = (object_data *)a->data.v;
|
object_data * data = (object_data *)a->data.v;
|
||||||
|
|
||||||
data->type = type;
|
|
||||||
data->name = strdup(name);
|
data->name = strdup(name);
|
||||||
|
|
||||||
|
object_set(a, type, value);
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
object_set(attrib * a, object_type type, variant value)
|
||||||
|
{
|
||||||
|
object_data * data = (object_data *)a->data.v;
|
||||||
|
|
||||||
|
if (data->type==TSTRING) free(data->data.str);
|
||||||
|
data->type = type;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case TSTRING:
|
case TSTRING:
|
||||||
data->data.str = strdup(value.v);
|
data->data.str = strdup(value.v);
|
||||||
|
@ -171,7 +202,42 @@ object_create(const char * name, object_type type, variant value)
|
||||||
assert(!"invalid object-type");
|
assert(!"invalid object-type");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return a;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extern void object_get(const struct attrib * a, variant * value, object_type * type);
|
void
|
||||||
|
object_get(const struct attrib * a, object_type * type, variant * value)
|
||||||
|
{
|
||||||
|
object_data * data = (object_data *)a->data.v;
|
||||||
|
*type = data->type;
|
||||||
|
switch (data->type) {
|
||||||
|
case TSTRING:
|
||||||
|
value->v = data->data.str;
|
||||||
|
break;
|
||||||
|
case TINTEGER:
|
||||||
|
value->i = data->data.i;
|
||||||
|
break;
|
||||||
|
case TREAL:
|
||||||
|
value->f = (float)data->data.real;
|
||||||
|
break;
|
||||||
|
case TREGION:
|
||||||
|
value->v = data->data.r;
|
||||||
|
break;
|
||||||
|
case TBUILDING:
|
||||||
|
value->v = data->data.b;
|
||||||
|
break;
|
||||||
|
case TFACTION:
|
||||||
|
value->v = data->data.f;
|
||||||
|
break;
|
||||||
|
case TUNIT:
|
||||||
|
value->v = data->data.u;
|
||||||
|
break;
|
||||||
|
case TSHIP:
|
||||||
|
value->v = data->data.sh;
|
||||||
|
break;
|
||||||
|
case TNONE:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
assert(!"invalid object-type");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -27,7 +27,8 @@ typedef enum {
|
||||||
extern attrib_type at_object;
|
extern attrib_type at_object;
|
||||||
|
|
||||||
extern struct attrib * object_create(const char * name, object_type type, variant value);
|
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 void object_get(const struct attrib * a, object_type * type, variant * value);
|
||||||
|
extern void object_set(struct attrib * a, object_type type, variant value);
|
||||||
extern const char * object_name(const struct attrib * a);
|
extern const char * object_name(const struct attrib * a);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -247,102 +247,103 @@ parse_buildings(xmlDocPtr doc)
|
||||||
{
|
{
|
||||||
xmlXPathContextPtr xpath = xmlXPathNewContext(doc);
|
xmlXPathContextPtr xpath = xmlXPathNewContext(doc);
|
||||||
xmlXPathObjectPtr buildings;
|
xmlXPathObjectPtr buildings;
|
||||||
xmlNodeSetPtr nodes;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* reading eressea/buildings/building */
|
/* reading eressea/buildings/building */
|
||||||
buildings = xmlXPathEvalExpression(BAD_CAST "/eressea/buildings/building", xpath);
|
buildings = xmlXPathEvalExpression(BAD_CAST "/eressea/buildings/building", xpath);
|
||||||
nodes = buildings->nodesetval;
|
if (buildings->nodesetval!=NULL) {
|
||||||
for (i=0;i!=nodes->nodeNr;++i) {
|
xmlNodeSetPtr nodes = buildings->nodesetval;
|
||||||
xmlNodePtr node = nodes->nodeTab[i];
|
for (i=0;i!=nodes->nodeNr;++i) {
|
||||||
xmlChar * property;
|
xmlNodePtr node = nodes->nodeTab[i];
|
||||||
building_type * bt = calloc(sizeof(building_type), 1);
|
xmlChar * property;
|
||||||
xmlXPathObjectPtr result;
|
building_type * bt = calloc(sizeof(building_type), 1);
|
||||||
int k;
|
xmlXPathObjectPtr result;
|
||||||
|
int k;
|
||||||
|
|
||||||
property = xmlGetProp(node, BAD_CAST "name");
|
property = xmlGetProp(node, BAD_CAST "name");
|
||||||
assert(property!=NULL);
|
|
||||||
bt->_name = strdup((const char *)property);
|
|
||||||
xmlFree(property);
|
|
||||||
|
|
||||||
bt->capacity = xml_ivalue(node, "capacity", -1);
|
|
||||||
bt->maxcapacity = xml_ivalue(node, "maxcapacity", -1);
|
|
||||||
bt->maxsize = xml_ivalue(node, "maxsize", -1);
|
|
||||||
|
|
||||||
bt->magres = xml_ivalue(node, "magres", 0);
|
|
||||||
bt->magresbonus = xml_ivalue(node, "magresbonus", 0);
|
|
||||||
bt->fumblebonus = xml_ivalue(node, "fumblebonus", 0);
|
|
||||||
bt->auraregen = xml_fvalue(node, "auraregen", 1.0);
|
|
||||||
|
|
||||||
if (xml_bvalue(node, "nodestroy", false)) bt->flags |= BTF_INDESTRUCTIBLE;
|
|
||||||
if (xml_bvalue(node, "oneperturn", false)) bt->flags |= BTF_ONEPERTURN;
|
|
||||||
if (xml_bvalue(node, "nobuild", false)) bt->flags |= BTF_NOBUILD;
|
|
||||||
if (xml_bvalue(node, "unique", false)) bt->flags |= BTF_UNIQUE;
|
|
||||||
if (xml_bvalue(node, "decay", false)) bt->flags |= BTF_DECAY;
|
|
||||||
if (xml_bvalue(node, "magic", false)) bt->flags |= BTF_MAGIC;
|
|
||||||
if (xml_bvalue(node, "protection", false)) bt->flags |= BTF_PROTECTION;
|
|
||||||
|
|
||||||
/* reading eressea/buildings/building/construction */
|
|
||||||
xpath->node = node;
|
|
||||||
result = xmlXPathEvalExpression(BAD_CAST "construction", xpath);
|
|
||||||
xml_readconstruction(xpath, result->nodesetval->nodeTab, result->nodesetval->nodeNr, &bt->construction);
|
|
||||||
xmlXPathFreeObject(result);
|
|
||||||
|
|
||||||
if (gamecode_enabled) {
|
|
||||||
/* reading eressea/buildings/building/function */
|
|
||||||
xpath->node = node;
|
|
||||||
result = xmlXPathEvalExpression(BAD_CAST "function", xpath);
|
|
||||||
for (k=0;k!=result->nodesetval->nodeNr;++k) {
|
|
||||||
xmlNodePtr node = result->nodesetval->nodeTab[k];
|
|
||||||
pf_generic fun;
|
|
||||||
parse_function(node, &fun, &property);
|
|
||||||
|
|
||||||
if (fun==NULL) {
|
|
||||||
log_error(("unknown function name '%s' for building %s\n",
|
|
||||||
(const char*)property, bt->_name));
|
|
||||||
xmlFree(property);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
assert(property!=NULL);
|
|
||||||
if (strcmp((const char*)property, "name")==0) {
|
|
||||||
bt->name = (const char * (*)(int size))fun;
|
|
||||||
} else if (strcmp((const char*)property, "init")==0) {
|
|
||||||
bt->init = (void (*)(struct building_type*))fun;
|
|
||||||
} else {
|
|
||||||
log_error(("unknown function type '%s' for building %s\n",
|
|
||||||
(const char*)property, bt->_name));
|
|
||||||
}
|
|
||||||
xmlFree(property);
|
|
||||||
}
|
|
||||||
xmlXPathFreeObject(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* reading eressea/buildings/building/maintenance */
|
|
||||||
result = xmlXPathEvalExpression(BAD_CAST "maintenance", xpath);
|
|
||||||
for (k=0;k!=result->nodesetval->nodeNr;++k) {
|
|
||||||
xmlNodePtr node = result->nodesetval->nodeTab[k];
|
|
||||||
maintenance * mt;
|
|
||||||
|
|
||||||
if (bt->maintenance==NULL) {
|
|
||||||
bt->maintenance = calloc(sizeof(struct maintenance), result->nodesetval->nodeNr+1);
|
|
||||||
}
|
|
||||||
mt = bt->maintenance + k;
|
|
||||||
mt->number = xml_ivalue(node, "amount", 0);
|
|
||||||
|
|
||||||
property = xmlGetProp(node, BAD_CAST "type");
|
|
||||||
assert(property!=NULL);
|
assert(property!=NULL);
|
||||||
mt->rtype = rt_find((const char*)property);
|
bt->_name = strdup((const char *)property);
|
||||||
assert(mt->rtype!=NULL);
|
|
||||||
xmlFree(property);
|
xmlFree(property);
|
||||||
|
|
||||||
if (xml_bvalue(node, "variable", false)) mt->flags |= MTF_VARIABLE;
|
bt->capacity = xml_ivalue(node, "capacity", -1);
|
||||||
if (xml_bvalue(node, "vital", false)) mt->flags |= MTF_VITAL;
|
bt->maxcapacity = xml_ivalue(node, "maxcapacity", -1);
|
||||||
|
bt->maxsize = xml_ivalue(node, "maxsize", -1);
|
||||||
|
|
||||||
|
bt->magres = xml_ivalue(node, "magres", 0);
|
||||||
|
bt->magresbonus = xml_ivalue(node, "magresbonus", 0);
|
||||||
|
bt->fumblebonus = xml_ivalue(node, "fumblebonus", 0);
|
||||||
|
bt->auraregen = xml_fvalue(node, "auraregen", 1.0);
|
||||||
|
|
||||||
|
if (xml_bvalue(node, "nodestroy", false)) bt->flags |= BTF_INDESTRUCTIBLE;
|
||||||
|
if (xml_bvalue(node, "oneperturn", false)) bt->flags |= BTF_ONEPERTURN;
|
||||||
|
if (xml_bvalue(node, "nobuild", false)) bt->flags |= BTF_NOBUILD;
|
||||||
|
if (xml_bvalue(node, "unique", false)) bt->flags |= BTF_UNIQUE;
|
||||||
|
if (xml_bvalue(node, "decay", false)) bt->flags |= BTF_DECAY;
|
||||||
|
if (xml_bvalue(node, "magic", false)) bt->flags |= BTF_MAGIC;
|
||||||
|
if (xml_bvalue(node, "protection", false)) bt->flags |= BTF_PROTECTION;
|
||||||
|
|
||||||
|
/* reading eressea/buildings/building/construction */
|
||||||
|
xpath->node = node;
|
||||||
|
result = xmlXPathEvalExpression(BAD_CAST "construction", xpath);
|
||||||
|
xml_readconstruction(xpath, result->nodesetval->nodeTab, result->nodesetval->nodeNr, &bt->construction);
|
||||||
|
xmlXPathFreeObject(result);
|
||||||
|
|
||||||
|
if (gamecode_enabled) {
|
||||||
|
/* reading eressea/buildings/building/function */
|
||||||
|
xpath->node = node;
|
||||||
|
result = xmlXPathEvalExpression(BAD_CAST "function", xpath);
|
||||||
|
for (k=0;k!=result->nodesetval->nodeNr;++k) {
|
||||||
|
xmlNodePtr node = result->nodesetval->nodeTab[k];
|
||||||
|
pf_generic fun;
|
||||||
|
parse_function(node, &fun, &property);
|
||||||
|
|
||||||
|
if (fun==NULL) {
|
||||||
|
log_error(("unknown function name '%s' for building %s\n",
|
||||||
|
(const char*)property, bt->_name));
|
||||||
|
xmlFree(property);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
assert(property!=NULL);
|
||||||
|
if (strcmp((const char*)property, "name")==0) {
|
||||||
|
bt->name = (const char * (*)(int size))fun;
|
||||||
|
} else if (strcmp((const char*)property, "init")==0) {
|
||||||
|
bt->init = (void (*)(struct building_type*))fun;
|
||||||
|
} else {
|
||||||
|
log_error(("unknown function type '%s' for building %s\n",
|
||||||
|
(const char*)property, bt->_name));
|
||||||
|
}
|
||||||
|
xmlFree(property);
|
||||||
|
}
|
||||||
|
xmlXPathFreeObject(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* reading eressea/buildings/building/maintenance */
|
||||||
|
result = xmlXPathEvalExpression(BAD_CAST "maintenance", xpath);
|
||||||
|
for (k=0;k!=result->nodesetval->nodeNr;++k) {
|
||||||
|
xmlNodePtr node = result->nodesetval->nodeTab[k];
|
||||||
|
maintenance * mt;
|
||||||
|
|
||||||
|
if (bt->maintenance==NULL) {
|
||||||
|
bt->maintenance = calloc(sizeof(struct maintenance), result->nodesetval->nodeNr+1);
|
||||||
|
}
|
||||||
|
mt = bt->maintenance + k;
|
||||||
|
mt->number = xml_ivalue(node, "amount", 0);
|
||||||
|
|
||||||
|
property = xmlGetProp(node, BAD_CAST "type");
|
||||||
|
assert(property!=NULL);
|
||||||
|
mt->rtype = rt_find((const char*)property);
|
||||||
|
assert(mt->rtype!=NULL);
|
||||||
|
xmlFree(property);
|
||||||
|
|
||||||
|
if (xml_bvalue(node, "variable", false)) mt->flags |= MTF_VARIABLE;
|
||||||
|
if (xml_bvalue(node, "vital", false)) mt->flags |= MTF_VITAL;
|
||||||
|
|
||||||
|
}
|
||||||
|
xmlXPathFreeObject(result);
|
||||||
|
|
||||||
|
/* finally, register the new building type */
|
||||||
|
bt_register(bt);
|
||||||
}
|
}
|
||||||
xmlXPathFreeObject(result);
|
|
||||||
|
|
||||||
/* finally, register the new building type */
|
|
||||||
bt_register(bt);
|
|
||||||
}
|
}
|
||||||
xmlXPathFreeObject(buildings);
|
xmlXPathFreeObject(buildings);
|
||||||
|
|
||||||
|
@ -467,68 +468,69 @@ parse_ships(xmlDocPtr doc)
|
||||||
{
|
{
|
||||||
xmlXPathContextPtr xpath = xmlXPathNewContext(doc);
|
xmlXPathContextPtr xpath = xmlXPathNewContext(doc);
|
||||||
xmlXPathObjectPtr ships;
|
xmlXPathObjectPtr ships;
|
||||||
xmlNodeSetPtr nodes;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* reading eressea/ships/ship */
|
/* reading eressea/ships/ship */
|
||||||
ships = xmlXPathEvalExpression(BAD_CAST "/eressea/ships/ship", xpath);
|
ships = xmlXPathEvalExpression(BAD_CAST "/eressea/ships/ship", xpath);
|
||||||
nodes = ships->nodesetval;
|
if (ships->nodesetval!=NULL) {
|
||||||
for (i=0;i!=nodes->nodeNr;++i) {
|
xmlNodeSetPtr nodes = ships->nodesetval;
|
||||||
xmlNodePtr node = nodes->nodeTab[i];
|
for (i=0;i!=nodes->nodeNr;++i) {
|
||||||
xmlChar * property;
|
xmlNodePtr node = nodes->nodeTab[i];
|
||||||
ship_type * st = calloc(sizeof(ship_type), 1);
|
xmlChar * property;
|
||||||
xmlXPathObjectPtr result;
|
ship_type * st = calloc(sizeof(ship_type), 1);
|
||||||
int k, c;
|
xmlXPathObjectPtr result;
|
||||||
|
int k, c;
|
||||||
|
|
||||||
property = xmlGetProp(node, BAD_CAST "name");
|
property = xmlGetProp(node, BAD_CAST "name");
|
||||||
assert(property!=NULL);
|
|
||||||
st->name[0] = strdup((const char *)property);
|
|
||||||
st->name[1] = strcat(strcpy(malloc(strlen(st->name[0])+3), st->name[0]),"_a");
|
|
||||||
xmlFree(property);
|
|
||||||
|
|
||||||
st->cabins = xml_ivalue(node, "cabins", 0);
|
|
||||||
st->cargo = xml_ivalue(node, "cargo", 0);
|
|
||||||
st->combat = xml_ivalue(node, "combat", 0);
|
|
||||||
st->cptskill = xml_ivalue(node, "cptskill", 0);
|
|
||||||
st->damage = xml_fvalue(node, "damage", 0.0);
|
|
||||||
if (xml_bvalue(node, "fly", false)) st->flags |= SFL_FLY;
|
|
||||||
if (xml_bvalue(node, "opensea", false)) st->flags |= SFL_OPENSEA;
|
|
||||||
st->minskill = xml_ivalue(node, "minskill", 0);
|
|
||||||
st->range = xml_ivalue(node, "range", 0);
|
|
||||||
st->storm = xml_fvalue(node, "storm", 1.0);
|
|
||||||
st->sumskill = xml_ivalue(node, "sumskill", 0);
|
|
||||||
|
|
||||||
/* reading eressea/ships/ship/construction */
|
|
||||||
xpath->node = node;
|
|
||||||
result = xmlXPathEvalExpression(BAD_CAST "construction", xpath);
|
|
||||||
xml_readconstruction(xpath, result->nodesetval->nodeTab, result->nodesetval->nodeNr, &st->construction);
|
|
||||||
xmlXPathFreeObject(result);
|
|
||||||
|
|
||||||
/* reading eressea/ships/ship/coast */
|
|
||||||
xpath->node = node;
|
|
||||||
result = xmlXPathEvalExpression(BAD_CAST "coast", xpath);
|
|
||||||
for (c=0,k=0;k!=result->nodesetval->nodeNr;++k) {
|
|
||||||
xmlNodePtr node = result->nodesetval->nodeTab[k];
|
|
||||||
|
|
||||||
if (k==0) {
|
|
||||||
assert(st->coasts==NULL);
|
|
||||||
st->coasts = (const terrain_type**)malloc(sizeof(const terrain_type*) * (result->nodesetval->nodeNr+1));
|
|
||||||
st->coasts[result->nodesetval->nodeNr] = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
property = xmlGetProp(node, BAD_CAST "terrain");
|
|
||||||
assert(property!=NULL);
|
assert(property!=NULL);
|
||||||
st->coasts[c] = get_terrain((const char*)property);
|
st->name[0] = strdup((const char *)property);
|
||||||
if (st->coasts[c]!=NULL) ++c;
|
st->name[1] = strcat(strcpy(malloc(strlen(st->name[0])+3), st->name[0]),"_a");
|
||||||
else {
|
|
||||||
log_warning(("ship %s mentions a non-existing terrain %s.\n", st->name[0], property));
|
|
||||||
}
|
|
||||||
xmlFree(property);
|
xmlFree(property);
|
||||||
}
|
|
||||||
xmlXPathFreeObject(result);
|
|
||||||
|
|
||||||
/* finally, register the new building type */
|
st->cabins = xml_ivalue(node, "cabins", 0);
|
||||||
st_register(st);
|
st->cargo = xml_ivalue(node, "cargo", 0);
|
||||||
|
st->combat = xml_ivalue(node, "combat", 0);
|
||||||
|
st->cptskill = xml_ivalue(node, "cptskill", 0);
|
||||||
|
st->damage = xml_fvalue(node, "damage", 0.0);
|
||||||
|
if (xml_bvalue(node, "fly", false)) st->flags |= SFL_FLY;
|
||||||
|
if (xml_bvalue(node, "opensea", false)) st->flags |= SFL_OPENSEA;
|
||||||
|
st->minskill = xml_ivalue(node, "minskill", 0);
|
||||||
|
st->range = xml_ivalue(node, "range", 0);
|
||||||
|
st->storm = xml_fvalue(node, "storm", 1.0);
|
||||||
|
st->sumskill = xml_ivalue(node, "sumskill", 0);
|
||||||
|
|
||||||
|
/* reading eressea/ships/ship/construction */
|
||||||
|
xpath->node = node;
|
||||||
|
result = xmlXPathEvalExpression(BAD_CAST "construction", xpath);
|
||||||
|
xml_readconstruction(xpath, result->nodesetval->nodeTab, result->nodesetval->nodeNr, &st->construction);
|
||||||
|
xmlXPathFreeObject(result);
|
||||||
|
|
||||||
|
/* reading eressea/ships/ship/coast */
|
||||||
|
xpath->node = node;
|
||||||
|
result = xmlXPathEvalExpression(BAD_CAST "coast", xpath);
|
||||||
|
for (c=0,k=0;k!=result->nodesetval->nodeNr;++k) {
|
||||||
|
xmlNodePtr node = result->nodesetval->nodeTab[k];
|
||||||
|
|
||||||
|
if (k==0) {
|
||||||
|
assert(st->coasts==NULL);
|
||||||
|
st->coasts = (const terrain_type**)malloc(sizeof(const terrain_type*) * (result->nodesetval->nodeNr+1));
|
||||||
|
st->coasts[result->nodesetval->nodeNr] = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
property = xmlGetProp(node, BAD_CAST "terrain");
|
||||||
|
assert(property!=NULL);
|
||||||
|
st->coasts[c] = get_terrain((const char*)property);
|
||||||
|
if (st->coasts[c]!=NULL) ++c;
|
||||||
|
else {
|
||||||
|
log_warning(("ship %s mentions a non-existing terrain %s.\n", st->name[0], property));
|
||||||
|
}
|
||||||
|
xmlFree(property);
|
||||||
|
}
|
||||||
|
xmlXPathFreeObject(result);
|
||||||
|
|
||||||
|
/* finally, register the new building type */
|
||||||
|
st_register(st);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
xmlXPathFreeObject(ships);
|
xmlXPathFreeObject(ships);
|
||||||
|
|
||||||
|
@ -1175,99 +1177,101 @@ parse_spells(xmlDocPtr doc)
|
||||||
{
|
{
|
||||||
xmlXPathContextPtr xpath = xmlXPathNewContext(doc);
|
xmlXPathContextPtr xpath = xmlXPathNewContext(doc);
|
||||||
xmlXPathObjectPtr spells;
|
xmlXPathObjectPtr spells;
|
||||||
xmlNodeSetPtr nodes;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
/* reading eressea/spells/spell */
|
/* reading eressea/spells/spell */
|
||||||
spells = xmlXPathEvalExpression(BAD_CAST "/eressea/spells/spell", xpath);
|
spells = xmlXPathEvalExpression(BAD_CAST "/eressea/spells/spell", xpath);
|
||||||
nodes = spells->nodesetval;
|
if (spells->nodesetval!=NULL) {
|
||||||
for (i=0;i!=nodes->nodeNr;++i) {
|
xmlNodeSetPtr nodes = spells->nodesetval;
|
||||||
xmlXPathObjectPtr result;
|
int i;
|
||||||
xmlNodePtr node = nodes->nodeTab[i];
|
|
||||||
xmlChar * property;
|
|
||||||
int k;
|
|
||||||
spell * sp = calloc(1, sizeof(spell));
|
|
||||||
|
|
||||||
/* spellname */
|
for (i=0;i!=nodes->nodeNr;++i) {
|
||||||
property = xmlGetProp(node, BAD_CAST "name");
|
xmlXPathObjectPtr result;
|
||||||
assert(property!=NULL);
|
xmlNodePtr node = nodes->nodeTab[i];
|
||||||
sp->sname = strdup((const char*)property);
|
xmlChar * property;
|
||||||
xmlFree(property);
|
int k;
|
||||||
|
spell * sp = calloc(1, sizeof(spell));
|
||||||
|
|
||||||
/* magic type */
|
/* spellname */
|
||||||
property = xmlGetProp(node, BAD_CAST "type");
|
property = xmlGetProp(node, BAD_CAST "name");
|
||||||
assert(property!=NULL);
|
assert(property!=NULL);
|
||||||
for (sp->magietyp=0;sp->magietyp!=MAXMAGIETYP;++sp->magietyp) {
|
sp->sname = strdup((const char*)property);
|
||||||
if (strcmp(magietypen[sp->magietyp], (const char *)property)==0) break;
|
xmlFree(property);
|
||||||
}
|
|
||||||
assert(sp->magietyp!=MAXMAGIETYP);
|
|
||||||
xmlFree(property);
|
|
||||||
|
|
||||||
/* level, rank and flags */
|
/* magic type */
|
||||||
sp->level = xml_ivalue(node, "level", -1);
|
property = xmlGetProp(node, BAD_CAST "type");
|
||||||
sp->rank = (char)xml_ivalue(node, "rank", -1);
|
assert(property!=NULL);
|
||||||
if (xml_bvalue(node, "ship", false)) sp->sptyp |= ONSHIPCAST;
|
for (sp->magietyp=0;sp->magietyp!=MAXMAGIETYP;++sp->magietyp) {
|
||||||
if (xml_bvalue(node, "ocean", false)) sp->sptyp |= OCEANCASTABLE;
|
if (strcmp(magietypen[sp->magietyp], (const char *)property)==0) break;
|
||||||
if (xml_bvalue(node, "far", false)) sp->sptyp |= FARCASTING;
|
}
|
||||||
|
assert(sp->magietyp!=MAXMAGIETYP);
|
||||||
|
xmlFree(property);
|
||||||
|
|
||||||
if (gamecode_enabled) {
|
/* level, rank and flags */
|
||||||
/* reading eressea/spells/spell/function */
|
sp->level = xml_ivalue(node, "level", -1);
|
||||||
|
sp->rank = (char)xml_ivalue(node, "rank", -1);
|
||||||
|
if (xml_bvalue(node, "ship", false)) sp->sptyp |= ONSHIPCAST;
|
||||||
|
if (xml_bvalue(node, "ocean", false)) sp->sptyp |= OCEANCASTABLE;
|
||||||
|
if (xml_bvalue(node, "far", false)) sp->sptyp |= FARCASTING;
|
||||||
|
|
||||||
|
if (gamecode_enabled) {
|
||||||
|
/* reading eressea/spells/spell/function */
|
||||||
|
xpath->node = node;
|
||||||
|
result = xmlXPathEvalExpression(BAD_CAST "function", xpath);
|
||||||
|
for (k=0;k!=result->nodesetval->nodeNr;++k) {
|
||||||
|
xmlNodePtr node = result->nodesetval->nodeTab[k];
|
||||||
|
pf_generic fun;
|
||||||
|
|
||||||
|
parse_function(node, &fun, &property);
|
||||||
|
if (fun==NULL) {
|
||||||
|
log_error(("unknown function name '%s' for spell '%s'\n",
|
||||||
|
(const char*)property, sp->sname));
|
||||||
|
xmlFree(property);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
assert(property!=NULL);
|
||||||
|
if (strcmp((const char*)property, "cast")==0) {
|
||||||
|
sp->sp_function = (spell_f)fun;
|
||||||
|
} else if (strcmp((const char*)property, "fumble")==0) {
|
||||||
|
sp->patzer = (pspell_f)fun;
|
||||||
|
} else {
|
||||||
|
log_error(("unknown function type '%s' for spell %s\n",
|
||||||
|
(const char*)property, sp->sname));
|
||||||
|
}
|
||||||
|
xmlFree(property);
|
||||||
|
}
|
||||||
|
xmlXPathFreeObject(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* reading eressea/spells/spell/resource */
|
||||||
xpath->node = node;
|
xpath->node = node;
|
||||||
result = xmlXPathEvalExpression(BAD_CAST "function", xpath);
|
result = xmlXPathEvalExpression(BAD_CAST "resource", xpath);
|
||||||
|
if (result->nodesetval->nodeNr) {
|
||||||
|
sp->components = malloc(sizeof(spell_component)*(result->nodesetval->nodeNr+1));
|
||||||
|
sp->components[result->nodesetval->nodeNr].type = 0;
|
||||||
|
}
|
||||||
for (k=0;k!=result->nodesetval->nodeNr;++k) {
|
for (k=0;k!=result->nodesetval->nodeNr;++k) {
|
||||||
xmlNodePtr node = result->nodesetval->nodeTab[k];
|
xmlNodePtr node = result->nodesetval->nodeTab[k];
|
||||||
pf_generic fun;
|
property = xmlGetProp(node, BAD_CAST "name");
|
||||||
|
assert(property);
|
||||||
parse_function(node, &fun, &property);
|
sp->components[k].type = rt_find((const char *)property);
|
||||||
if (fun==NULL) {
|
assert(sp->components[k].type);
|
||||||
log_error(("unknown function name '%s' for spell '%s'\n",
|
|
||||||
(const char*)property, sp->sname));
|
|
||||||
xmlFree(property);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
assert(property!=NULL);
|
|
||||||
if (strcmp((const char*)property, "cast")==0) {
|
|
||||||
sp->sp_function = (spell_f)fun;
|
|
||||||
} else if (strcmp((const char*)property, "fumble")==0) {
|
|
||||||
sp->patzer = (pspell_f)fun;
|
|
||||||
} else {
|
|
||||||
log_error(("unknown function type '%s' for spell %s\n",
|
|
||||||
(const char*)property, sp->sname));
|
|
||||||
}
|
|
||||||
xmlFree(property);
|
xmlFree(property);
|
||||||
|
sp->components[k].amount = xml_ivalue(node, "amount", 1);
|
||||||
|
sp->components[k].cost = SPC_FIX;
|
||||||
|
property = xmlGetProp(node, BAD_CAST "cost");
|
||||||
|
if (property!=NULL) {
|
||||||
|
if (strcmp((const char *)property, "linear")==0) {
|
||||||
|
sp->components[k].cost = SPC_LINEAR;
|
||||||
|
} else if (strcmp((const char *)property, "level")==0) {
|
||||||
|
sp->components[k].cost = SPC_LEVEL;
|
||||||
|
}
|
||||||
|
xmlFree(property);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
xmlXPathFreeObject(result);
|
xmlXPathFreeObject(result);
|
||||||
|
sp->id = 0;
|
||||||
|
register_spell(sp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* reading eressea/spells/spell/resource */
|
|
||||||
xpath->node = node;
|
|
||||||
result = xmlXPathEvalExpression(BAD_CAST "resource", xpath);
|
|
||||||
if (result->nodesetval->nodeNr) {
|
|
||||||
sp->components = malloc(sizeof(spell_component)*(result->nodesetval->nodeNr+1));
|
|
||||||
sp->components[result->nodesetval->nodeNr].type = 0;
|
|
||||||
}
|
|
||||||
for (k=0;k!=result->nodesetval->nodeNr;++k) {
|
|
||||||
xmlNodePtr node = result->nodesetval->nodeTab[k];
|
|
||||||
property = xmlGetProp(node, BAD_CAST "name");
|
|
||||||
assert(property);
|
|
||||||
sp->components[k].type = rt_find((const char *)property);
|
|
||||||
assert(sp->components[k].type);
|
|
||||||
xmlFree(property);
|
|
||||||
sp->components[k].amount = xml_ivalue(node, "amount", 1);
|
|
||||||
sp->components[k].cost = SPC_FIX;
|
|
||||||
property = xmlGetProp(node, BAD_CAST "cost");
|
|
||||||
if (property!=NULL) {
|
|
||||||
if (strcmp((const char *)property, "linear")==0) {
|
|
||||||
sp->components[k].cost = SPC_LINEAR;
|
|
||||||
} else if (strcmp((const char *)property, "level")==0) {
|
|
||||||
sp->components[k].cost = SPC_LEVEL;
|
|
||||||
}
|
|
||||||
xmlFree(property);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
xmlXPathFreeObject(result);
|
|
||||||
sp->id = 0;
|
|
||||||
register_spell(sp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
xmlXPathFreeObject(spells);
|
xmlXPathFreeObject(spells);
|
||||||
|
|
|
@ -30,9 +30,8 @@ __at_hashkey(const char* s)
|
||||||
int key = 0;
|
int key = 0;
|
||||||
size_t i = strlen(s);
|
size_t i = strlen(s);
|
||||||
|
|
||||||
while (i) {
|
while (i>0) {
|
||||||
--i;
|
key = (s[--i] + key*37);
|
||||||
key = ((key & 1) << 31) ^ (key >> 1) ^ s[i];
|
|
||||||
}
|
}
|
||||||
return key & 0x7fffffff;
|
return key & 0x7fffffff;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ LUASERVER_SOURCES =
|
||||||
<lua>event.cpp
|
<lua>event.cpp
|
||||||
<lua>faction.cpp
|
<lua>faction.cpp
|
||||||
<lua>message.cpp
|
<lua>message.cpp
|
||||||
|
<lua>objects.cpp
|
||||||
<lua>region.cpp
|
<lua>region.cpp
|
||||||
<lua>script.cpp
|
<lua>script.cpp
|
||||||
<lua>ship.cpp
|
<lua>ship.cpp
|
||||||
|
|
|
@ -287,6 +287,12 @@
|
||||||
<File
|
<File
|
||||||
RelativePath=".\lua\message.cpp">
|
RelativePath=".\lua\message.cpp">
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\lua\objects.cpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\lua\objects.h">
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\lua\region.cpp">
|
RelativePath=".\lua\region.cpp">
|
||||||
<FileConfiguration
|
<FileConfiguration
|
||||||
|
|
|
@ -13,5 +13,6 @@ extern void bind_item(struct lua_State * L);
|
||||||
extern void bind_event(struct lua_State * L);
|
extern void bind_event(struct lua_State * L);
|
||||||
extern void bind_message(struct lua_State * L);
|
extern void bind_message(struct lua_State * L);
|
||||||
extern void bind_script(struct lua_State * L);
|
extern void bind_script(struct lua_State * L);
|
||||||
|
extern void bind_objects(struct lua_State * L);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <eressea.h>
|
#include <eressea.h>
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
|
#include "objects.h"
|
||||||
#include "script.h"
|
#include "script.h"
|
||||||
|
|
||||||
// kernel includes
|
// kernel includes
|
||||||
|
@ -175,5 +176,6 @@ bind_building(lua_State * L)
|
||||||
.def_readonly("id", &building::no)
|
.def_readonly("id", &building::no)
|
||||||
.def_readwrite("size", &building::size)
|
.def_readwrite("size", &building::size)
|
||||||
.def("add_action", &building_addaction)
|
.def("add_action", &building_addaction)
|
||||||
|
.property("objects", &eressea::get_objects<building>)
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include <eressea.h>
|
#include <eressea.h>
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
|
#include "objects.h"
|
||||||
|
|
||||||
// kernel includes
|
// kernel includes
|
||||||
#include <kernel/alliance.h>
|
#include <kernel/alliance.h>
|
||||||
|
@ -298,5 +299,6 @@ bind_faction(lua_State * L)
|
||||||
.property("units", &faction_units, return_stl_iterator)
|
.property("units", &faction_units, return_stl_iterator)
|
||||||
.property("alliance", &faction_getalliance, &faction_setalliance)
|
.property("alliance", &faction_getalliance, &faction_setalliance)
|
||||||
.property("race", &faction_getrace, &faction_setrace)
|
.property("race", &faction_getrace, &faction_setrace)
|
||||||
|
.property("objects", &eressea::get_objects<faction>)
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
117
src/eressea/lua/objects.cpp
Normal file
117
src/eressea/lua/objects.cpp
Normal file
|
@ -0,0 +1,117 @@
|
||||||
|
#include <config.h>
|
||||||
|
#include <eressea.h>
|
||||||
|
#include "objects.h"
|
||||||
|
|
||||||
|
#include <kernel/region.h>
|
||||||
|
#include <kernel/unit.h>
|
||||||
|
#include <kernel/faction.h>
|
||||||
|
#include <kernel/ship.h>
|
||||||
|
#include <kernel/building.h>
|
||||||
|
#include <util/attrib.h>
|
||||||
|
|
||||||
|
// lua includes
|
||||||
|
#include <lua.hpp>
|
||||||
|
#include <luabind/luabind.hpp>
|
||||||
|
#include <luabind/object.hpp>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
using namespace luabind;
|
||||||
|
|
||||||
|
namespace eressea {
|
||||||
|
|
||||||
|
object
|
||||||
|
objects::get(const char * name) {
|
||||||
|
attrib * a = a_find(*mAttribPtr, &at_object);
|
||||||
|
for (;a;a=a->nexttype) {
|
||||||
|
if (strcmp(object_name(a), name)==0) {
|
||||||
|
lua_State * L = (lua_State *)global.vm_state;
|
||||||
|
variant val;
|
||||||
|
object_type type;
|
||||||
|
|
||||||
|
object_get(a, &type, &val);
|
||||||
|
switch (type) {
|
||||||
|
case TNONE:
|
||||||
|
break;
|
||||||
|
case TINTEGER:
|
||||||
|
return object(L, val.i);
|
||||||
|
case TREAL:
|
||||||
|
return object(L, val.f);
|
||||||
|
case TREGION:
|
||||||
|
return object(L, (region*)val.v);
|
||||||
|
case TBUILDING:
|
||||||
|
return object(L, (building*)val.v);
|
||||||
|
case TUNIT:
|
||||||
|
return object(L, (unit*)val.v);
|
||||||
|
case TSHIP:
|
||||||
|
return object(L, (ship*)val.v);
|
||||||
|
case TSTRING:
|
||||||
|
return object(L, std::string((const char*)val.v));
|
||||||
|
default:
|
||||||
|
assert(!"not implemented");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return object(); // nil
|
||||||
|
}
|
||||||
|
|
||||||
|
static void set_object(attrib **attribs, const char * name, object_type type, variant val) {
|
||||||
|
attrib * a = a_find(*attribs, &at_object);
|
||||||
|
for (;a;a=a->nexttype) {
|
||||||
|
if (strcmp(object_name(a), name)==0) break;
|
||||||
|
}
|
||||||
|
if (a==NULL) {
|
||||||
|
a = a_add(attribs, object_create(name, type, val));
|
||||||
|
} else {
|
||||||
|
object_set(a, type, val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<> void
|
||||||
|
objects::set<int, TINTEGER>(const char * name, int value) {
|
||||||
|
variant val = { 0 };
|
||||||
|
val.i = value;
|
||||||
|
set_object(mAttribPtr, name, TINTEGER, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<> void
|
||||||
|
objects::set<double, TREAL>(const char * name, double value) {
|
||||||
|
variant val = { 0 };
|
||||||
|
val.f = (float)value;
|
||||||
|
set_object(mAttribPtr, name, TREAL, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<> void
|
||||||
|
objects::set<const char *, TSTRING>(const char * name, const char * value) {
|
||||||
|
variant val = { 0 };
|
||||||
|
val.v = strdup(value);
|
||||||
|
set_object(mAttribPtr, name, TSTRING, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class V, object_type T> void
|
||||||
|
objects::set(const char * name, V value) {
|
||||||
|
variant val = { 0 };
|
||||||
|
val.v = &value;
|
||||||
|
set_object(mAttribPtr, name, T, val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
bind_objects(struct lua_State * L)
|
||||||
|
{
|
||||||
|
using namespace eressea;
|
||||||
|
|
||||||
|
module(L)[
|
||||||
|
class_<objects>("objects")
|
||||||
|
.def("get", &objects::get)
|
||||||
|
.def("set", (void(objects::*)(const char*, region&))&objects::set<region&, TREGION>)
|
||||||
|
.def("set", (void(objects::*)(const char*, unit&))&objects::set<unit&, TUNIT>)
|
||||||
|
.def("set", (void(objects::*)(const char*, faction&))&objects::set<faction&, TFACTION>)
|
||||||
|
.def("set", (void(objects::*)(const char*, building&))&objects::set<building&, TBUILDING>)
|
||||||
|
.def("set", (void(objects::*)(const char*, ship&))&objects::set<ship&, TSHIP>)
|
||||||
|
// POD:
|
||||||
|
.def("set", (void(objects::*)(const char*, int))&objects::set<int, TINTEGER>)
|
||||||
|
.def("set", (void(objects::*)(const char*, double))&objects::set<double, TREAL>)
|
||||||
|
.def("set", (void(objects::*)(const char*, const char *))&objects::set<const char *, TSTRING>)
|
||||||
|
];
|
||||||
|
}
|
36
src/eressea/lua/objects.h
Normal file
36
src/eressea/lua/objects.h
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
#ifndef LUA_OBJECTS_H
|
||||||
|
#define LUA_OBJECTS_H
|
||||||
|
|
||||||
|
#include <attributes/object.h>
|
||||||
|
|
||||||
|
struct lua_State;
|
||||||
|
|
||||||
|
namespace luabind {
|
||||||
|
class object;
|
||||||
|
};
|
||||||
|
|
||||||
|
namespace eressea {
|
||||||
|
|
||||||
|
class objects {
|
||||||
|
public:
|
||||||
|
objects(struct attrib ** attribs) : mAttribPtr(attribs) {}
|
||||||
|
|
||||||
|
luabind::object get(const char * name);
|
||||||
|
// void set(const char * name, int type, luabind::object& value);
|
||||||
|
template <class V, object_type T> void
|
||||||
|
set(const char * name, V value);
|
||||||
|
|
||||||
|
private:
|
||||||
|
struct attrib ** mAttribPtr;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
template<class T> eressea::objects
|
||||||
|
get_objects(const T& parent)
|
||||||
|
{
|
||||||
|
return eressea::objects(&const_cast<attrib *>(parent.attribs));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include <eressea.h>
|
#include <eressea.h>
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
|
#include "objects.h"
|
||||||
|
|
||||||
// kernel includes
|
// kernel includes
|
||||||
#include <kernel/building.h>
|
#include <kernel/building.h>
|
||||||
|
@ -242,6 +243,12 @@ region_move(region& r, short x, short y)
|
||||||
rhash(&r);
|
rhash(&r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
eressea::objects
|
||||||
|
region_objects(const region& r)
|
||||||
|
{
|
||||||
|
return eressea::objects(&const_cast<attrib *>(r.attribs));
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
bind_region(lua_State * L)
|
bind_region(lua_State * L)
|
||||||
{
|
{
|
||||||
|
@ -279,5 +286,6 @@ bind_region(lua_State * L)
|
||||||
.property("units", ®ion_units, return_stl_iterator)
|
.property("units", ®ion_units, return_stl_iterator)
|
||||||
.property("buildings", ®ion_buildings, return_stl_iterator)
|
.property("buildings", ®ion_buildings, return_stl_iterator)
|
||||||
.property("ships", ®ion_ships, return_stl_iterator)
|
.property("ships", ®ion_ships, return_stl_iterator)
|
||||||
|
.property("objects", &eressea::get_objects<region>)
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include <eressea.h>
|
#include <eressea.h>
|
||||||
|
#include "objects.h"
|
||||||
|
|
||||||
// kernel includes
|
// kernel includes
|
||||||
#include <build.h>
|
#include <build.h>
|
||||||
|
@ -68,5 +69,6 @@ bind_ship(lua_State * L)
|
||||||
.def_readwrite("damage", &ship::damage)
|
.def_readwrite("damage", &ship::damage)
|
||||||
.def_readwrite("size", &ship::size)
|
.def_readwrite("size", &ship::size)
|
||||||
.def_readwrite("coast", &ship::coast)
|
.def_readwrite("coast", &ship::coast)
|
||||||
|
.property("objects", &eressea::get_objects<ship>)
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include <eressea.h>
|
#include <eressea.h>
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
|
#include "objects.h"
|
||||||
#include "script.h"
|
#include "script.h"
|
||||||
#include "event.h"
|
#include "event.h"
|
||||||
|
|
||||||
|
@ -578,5 +579,6 @@ bind_unit(lua_State * L)
|
||||||
.property("number", &unit_getnumber, &unit_setnumber)
|
.property("number", &unit_getnumber, &unit_setnumber)
|
||||||
.property("race", &unit_getrace, &unit_setrace)
|
.property("race", &unit_getrace, &unit_setrace)
|
||||||
.property("hp_max", &unit_hpmax)
|
.property("hp_max", &unit_hpmax)
|
||||||
|
.property("objects", &eressea::get_objects<unit>)
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -303,6 +303,7 @@ lua_init(void)
|
||||||
luaopen_io(luaState);
|
luaopen_io(luaState);
|
||||||
luaopen_table(luaState);
|
luaopen_table(luaState);
|
||||||
luabind::open(luaState);
|
luabind::open(luaState);
|
||||||
|
bind_objects(luaState);
|
||||||
bind_eressea(luaState);
|
bind_eressea(luaState);
|
||||||
bind_script(luaState);
|
bind_script(luaState);
|
||||||
bind_spell(luaState);
|
bind_spell(luaState);
|
||||||
|
|
Loading…
Reference in a new issue