From fa4a09ae994e111346cb58827057b263b0927371 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 1 Apr 2002 14:22:00 +0000 Subject: [PATCH] =?UTF-8?q?*=20BUGFIX:=20recycling=20bei=20geb=C3=A4udeein?= =?UTF-8?q?riss=20repariert=20*=20BUGFIX:=20einlesen=20von=20mehr=20als=20?= =?UTF-8?q?einem=20konstruktionsmaterial?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/kernel/build.c | 30 +++++++++++ src/common/kernel/build.h | 98 +++++++++++------------------------- src/common/kernel/building.c | 31 +----------- src/common/kernel/building.h | 2 +- src/common/kernel/ship.c | 29 +---------- src/res/buildings.xml | 96 +++++++++++++++++------------------ 6 files changed, 109 insertions(+), 177 deletions(-) diff --git a/src/common/kernel/build.c b/src/common/kernel/build.c index 011160ee5..23ec9251f 100644 --- a/src/common/kernel/build.c +++ b/src/common/kernel/build.c @@ -46,6 +46,7 @@ #include #include #include +#include /* from libc */ #include @@ -1211,3 +1212,32 @@ do_misc(char try) } } +void +xml_readrequirement(const struct xml_tag * tag, construction * con) +{ + requirement * radd; + const resource_type * rtype; + resource_t type = NORESOURCE; + + assert(con!=NULL); + + if (con->materials) { + int size = 0; + while (con->materials[size].number) ++size; + con->materials = realloc(con->materials, sizeof(requirement) * (size+2)); + radd = con->materials+size; + } else { + radd = con->materials = malloc(sizeof(requirement) * 2); + } + radd->number = xml_ivalue(tag, "quantity"); + radd->recycle = xml_fvalue(tag, "recycle"); + rtype = rt_find(xml_value(tag, "type")); + for (type=0;type!=MAX_RESOURCES;++type) { + if (oldresourcetype[type]==rtype) { + radd->type = type; + break; + } + } + radd[1].number = 0; + radd[1].type = 0; +} diff --git a/src/common/kernel/build.h b/src/common/kernel/build.h index 823bdba18..2ed55bd57 100644 --- a/src/common/kernel/build.h +++ b/src/common/kernel/build.h @@ -26,74 +26,7 @@ * wichtig */ -#ifndef NEW_BUILDINGS - -enum { - B_SITE, -#if LARGE_CASTLES - B_TRADEPOST, -#endif - B_FORTIFICATION, - B_TOWER, - B_CASTLE, - B_FORTRESS, - B_CITADEL, - MAXBUILDINGS -}; - -enum { - BT_BURG, - BT_LEUCHTTURM, - BT_BERGWERK, - BT_STEINBRUCH, - BT_HAFEN, - BT_UNIVERSITAET, - BT_MAGIERTURM, - BT_SCHMIEDE, - BT_SAEGEWERK, - BT_PFERDEZUCHT, - BT_MONUMENT, - BT_DAMM, - BT_KARAWANSEREI, - BT_TUNNEL, - BT_TAVERNE, - BT_STONECIRCLE, - BT_BLESSEDSTONECIRCLE, - BT_ICASTLE, - MAXBUILDINGTYPES, - NOBUILDING = -1 -}; -#endif - - -extern char *buildingnames[MAXBUILDINGS]; - -void destroy(struct region * r, struct unit * u, const char * cmd); - -extern boolean can_contact(const struct region *r, const struct unit *u, const struct unit *u2); - -void do_siege(void); -void build_road(struct region * r, struct unit * u, int size, direction_t d); -void create_ship(struct region * r, struct unit * u, const struct ship_type * newtype, int size); -void continue_ship(struct region * r, struct unit * u, int size); - -struct building * getbuilding(const struct region * r); -struct ship *getship(const struct region * r); - -void remove_contacts(void); -void do_leave(void); -void do_misc(char try); - -void reportevent(struct region * r, char *s); - -void shash(struct ship * sh); -void sunhash(struct ship * sh); - -void destroy_ship(struct ship * s, struct region * r); - -/* ** ** ** ** ** ** * - * new build rules * - * ** ** ** ** ** ** */ +struct xml_tag; typedef struct requirement { #ifdef NO_OLD_ITEMS @@ -125,8 +58,33 @@ typedef struct construction { /* stores skill modifiers and other attributes */ } construction; -int build(struct unit * u, const construction * ctype, int completed, int want); -int maxbuild(const struct unit *u, const construction *cons); +void destroy(struct region * r, struct unit * u, const char * cmd); + +extern boolean can_contact(const struct region *r, const struct unit *u, const struct unit *u2); + +void do_siege(void); +void build_road(struct region * r, struct unit * u, int size, direction_t d); +void create_ship(struct region * r, struct unit * u, const struct ship_type * newtype, int size); +void continue_ship(struct region * r, struct unit * u, int size); + +struct building * getbuilding(const struct region * r); +struct ship *getship(const struct region * r); + +void remove_contacts(void); +void do_leave(void); +void do_misc(char try); + +void reportevent(struct region * r, char *s); + +void shash(struct ship * sh); +void sunhash(struct ship * sh); + +void destroy_ship(struct ship * s, struct region * r); + +extern int build(struct unit * u, const construction * ctype, int completed, int want); +extern int maxbuild(const struct unit *u, const construction *cons); + +extern void xml_readrequirement(const struct xml_tag * tag, construction * con); /** error messages that build may return: */ #define ELOWSKILL -1 diff --git a/src/common/kernel/building.c b/src/common/kernel/building.c index 8bb857868..83e65ddd9 100644 --- a/src/common/kernel/building.c +++ b/src/common/kernel/building.c @@ -183,7 +183,6 @@ findbuilding(int i) /** Building: Fortification */ -#ifdef NEW_BUILDINGS enum { B_SITE, #if LARGE_CASTLES @@ -196,7 +195,6 @@ enum { B_CITADEL, MAXBUILDINGS }; -#endif static int sm_smithy(const unit * u, const region * r, skill_t sk, int value) /* skillmod */ @@ -408,34 +406,7 @@ tagbegin(struct xml_stack * stack) if (xml_bvalue(tag, "variable")) mt[len].flags |= MTF_VARIABLE; if (xml_bvalue(tag, "vital")) mt[len].flags |= MTF_VITAL; } else if (strcmp(tag->name, "requirement")==0) { - construction * con = (construction *)bt->construction; - if (con!=NULL) { - const resource_type * rtype; - resource_t type = NORESOURCE; - requirement * radd = con->materials; - if (radd) { - requirement * rnew; - int size; - for (size=0;radd[size++].number;); - rnew = malloc(sizeof(requirement) * (size+2)); - memcpy(rnew, radd, size*sizeof(requirement)); - free(radd); - con->materials = rnew; - radd = rnew+size; - } else { - radd = con->materials = calloc(sizeof(requirement), 2); - } - radd[0].number = xml_ivalue(tag, "quantity"); - rtype = rt_find(xml_value(tag, "type")); - for (type=0;type!=MAX_RESOURCES;++type) { - if (oldresourcetype[type]==rtype) { - radd[0].type = type; - break; - } - } - radd[1].number = 0; - radd[1].type = 0; - } + xml_readrequirement(tag, bt->construction); } } return XML_OK; diff --git a/src/common/kernel/building.h b/src/common/kernel/building.h index 67f0537ba..a2d9bb615 100644 --- a/src/common/kernel/building.h +++ b/src/common/kernel/building.h @@ -47,7 +47,7 @@ typedef struct building_type { int fumblebonus; /* bonus that reduces fumbling */ double auraregen; /* modifier for aura regeneration inside building */ struct maintenance * maintenance; /* array of requirements */ - const struct construction * construction; /* construction of 1 building-level */ + struct construction * construction; /* construction of 1 building-level */ const char * (*name)(int size); void (*init)(struct building_type*); diff --git a/src/common/kernel/ship.c b/src/common/kernel/ship.c index 72a6321ce..b5103825b 100644 --- a/src/common/kernel/ship.c +++ b/src/common/kernel/ship.c @@ -289,34 +289,7 @@ tagbegin(struct xml_stack * stack) con->reqsize = xml_ivalue(tag, "reqsize"); con->skill = sk_find(xml_value(tag, "skill")); } else if (strcmp(tag->name, "requirement")==0) { - construction * con = st->construction; - if (con!=NULL) { - const resource_type * rtype; - resource_t type = NORESOURCE; - requirement * radd = con->materials; - if (radd) { - requirement * rnew; - int size; - for (size=0;radd[size++].number;); - rnew = malloc(sizeof(requirement) * (size+2)); - memcpy(rnew, radd, size*sizeof(requirement)); - free(radd); - con->materials = rnew; - radd = rnew+size; - } else { - radd = con->materials = calloc(sizeof(requirement), 2); - } - radd[0].number = xml_ivalue(tag, "quantity"); - rtype = rt_find(xml_value(tag, "type")); - for (type=0;type!=MAX_RESOURCES;++type) { - if (oldresourcetype[type]==rtype) { - radd[0].type = type; - break; - } - } - radd[1].number = 0; - radd[1].type = 0; - } + xml_readrequirement(tag, st->construction); } } return XML_OK; diff --git a/src/res/buildings.xml b/src/res/buildings.xml index 2517178c3..53998e83e 100644 --- a/src/res/buildings.xml +++ b/src/res/buildings.xml @@ -15,35 +15,35 @@ - - + + - - + + - - - + + + - + - - - + + + @@ -52,29 +52,29 @@ - - - + + + - + - - - + + + - - - + + + @@ -82,9 +82,9 @@ - - - + + + @@ -92,9 +92,9 @@ - - - + + + @@ -102,11 +102,11 @@ - + - - - + + + @@ -114,10 +114,10 @@ - - + + - + @@ -126,9 +126,9 @@ - - - + + + @@ -136,8 +136,8 @@ - - + + @@ -145,9 +145,9 @@ - - - + + + @@ -155,9 +155,9 @@ - - - + + + @@ -165,9 +165,9 @@ - - - + + +