clarify building_type.maxsize and add error logging for bug 2221.

https://bugs.eressea.de/view.php?id=2221
This commit is contained in:
Enno Rehling 2016-08-06 13:52:29 +02:00
parent 3dab1876ae
commit db5b90e80b
12 changed files with 47 additions and 28 deletions

26
.editorconfig Normal file
View File

@ -0,0 +1,26 @@
# EditorConfig is awesome: http://EditorConfig.org
# top-most EditorConfig file
root = true
# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
# 4 space indentation
[*.{c,h,lua}]
indent_style = space
indent_size = 4
[*.{xml,json}]
charset = utf-8
# Tab indentation (no size specified)
[Makefile]
indent_style = tab
# Matches exact files
[.travis.yml]
indent_style = space
indent_size = 2

View File

@ -3,7 +3,7 @@
<xi:include href="config://default/buildings/castle-2.xml" /> <xi:include href="config://default/buildings/castle-2.xml" />
<building name="watch" capacity="1" maxsize="10" fort="yes"> <building name="watch" capacity="1" fort="yes">
<function name="name" value="fort_name"/> <function name="name" value="fort_name"/>
<function name="protection" value="building_protection"/> <function name="protection" value="building_protection"/>
<function name="taxes" value="lua_building_taxes"/> <function name="taxes" value="lua_building_taxes"/>

View File

@ -849,7 +849,6 @@ build_building(unit * u, const building_type * btype, int id, int want, order *
b->size += built; b->size += built;
if (b->type->maxsize > 0 && b->size > b->type->maxsize) { if (b->type->maxsize > 0 && b->size > b->type->maxsize) {
// this seems to be okay for a watch, but is not okay for an academy or harbour
log_error("build: %s has size=%d, maxsize=%d", buildingname(b), b->size, b->type->maxsize); log_error("build: %s has size=%d, maxsize=%d", buildingname(b), b->size, b->type->maxsize);
} }
fset(b, BLD_EXPANDED); fset(b, BLD_EXPANDED);

View File

@ -132,7 +132,7 @@ int buildingcapacity(const building * b)
} }
return b->size * b->type->capacity; return b->size * b->type->capacity;
} }
if (b->size >= b->type->maxsize) { if (building_finished(b)) {
if (b->type->maxcapacity >= 0) { if (b->type->maxcapacity >= 0) {
return b->type->maxcapacity; return b->type->maxcapacity;
} }
@ -648,15 +648,20 @@ buildingtype_exists(const region * r, const building_type * bt, bool working)
building *b; building *b;
for (b = rbuildings(r); b; b = b->next) { for (b = rbuildings(r); b; b = b->next) {
if (b->type == bt && b->size >= bt->maxsize && (!working || fval(b, BLD_WORKING))) if (b->type == bt && (!working || fval(b, BLD_WORKING)) && building_finished(b)) {
return true; return true;
} }
}
return false; return false;
} }
bool building_finished(const struct building *b) {
return b->size >= b->type->maxsize;
}
bool building_is_active(const struct building *b) { bool building_is_active(const struct building *b) {
return b && fval(b, BLD_WORKING) && b->size >= b->type->maxsize; return b && fval(b, BLD_WORKING) && building_finished(b);
} }
building *active_building(const unit *u, const struct building_type *btype) { building *active_building(const unit *u, const struct building_type *btype) {

View File

@ -92,15 +92,7 @@ extern "C" {
const struct building *b, int bsize); const struct building *b, int bsize);
bool in_safe_building(struct unit *u1, struct unit *u2); bool in_safe_building(struct unit *u1, struct unit *u2);
/* buildingt => building_type
* Name => locale_string(name)
* MaxGroesse => levels
* MinBauTalent => construction->minskill
* Kapazitaet => capacity, maxcapacity
* Materialien => construction->materials
* UnterSilber, UnterSpezialTyp, UnterSpezial => maintenance
* per_size => !maintenance->fixed
*/
#define BFL_NONE 0x00 #define BFL_NONE 0x00
#define BLD_MAINTAINED 0x01 /* vital maintenance paid for */ #define BLD_MAINTAINED 0x01 /* vital maintenance paid for */
#define BLD_WORKING 0x02 /* full maintenance paid, it works */ #define BLD_WORKING 0x02 /* full maintenance paid, it works */
@ -138,6 +130,7 @@ extern "C" {
struct region *r, const struct locale *lang); struct region *r, const struct locale *lang);
int build_building(struct unit *u, const struct building_type *typ, int build_building(struct unit *u, const struct building_type *typ,
int id, int size, struct order *ord); int id, int size, struct order *ord);
bool building_finished(const struct building *b);
/* Alte Gebäudetypen: */ /* Alte Gebäudetypen: */
@ -173,10 +166,6 @@ extern "C" {
bool building_is_active(const struct building *b); bool building_is_active(const struct building *b);
struct building *active_building(const struct unit *u, const struct building_type *btype); struct building *active_building(const struct unit *u, const struct building_type *btype);
#ifdef WDW_PYRAMID
extern int wdw_pyramid_level(const struct building *b);
#endif
extern const char *buildingname(const struct building *b); extern const char *buildingname(const struct building *b);
extern const char *building_getname(const struct building *b); extern const char *building_getname(const struct building *b);

View File

@ -1676,6 +1676,7 @@ int read_game(gamedata *data) {
if (b->type == bt_lighthouse) { if (b->type == bt_lighthouse) {
r->flags |= RF_LIGHTHOUSE; r->flags |= RF_LIGHTHOUSE;
} }
// repairs, bug 2221: // repairs, bug 2221:
if (b->type->maxsize>0 && b->size>b->type->maxsize) { if (b->type->maxsize>0 && b->size>b->type->maxsize) {
log_error("building too big: %s (%s size %d of %d), fixing.", buildingname(b), b->type->_name, b->size, b->type->maxsize); log_error("building too big: %s (%s size %d of %d), fixing.", buildingname(b), b->type->_name, b->size, b->type->maxsize);

View File

@ -1044,7 +1044,7 @@ struct building *inside_building(const struct unit *u)
if (!u->building) { if (!u->building) {
return NULL; return NULL;
} }
else if (u->building->size < u->building->type->maxsize) { else if (!building_finished(u->building)) {
/* Gebaeude noch nicht fertig */ /* Gebaeude noch nicht fertig */
return NULL; return NULL;
} }

View File

@ -10,7 +10,7 @@
without prior permission by the authors of Eressea. without prior permission by the authors of Eressea.
*/ */
#define INTPAK_VERSION 329 /* in binary, ints can get packed */ #define INTPAK_VERSION 329 /* in binary, ints can get packed. starting with E2/572 */
#define NOZEROIDS_VERSION 330 /* 2008-05-16 zero is not a valid ID for anything (including factions) */ #define NOZEROIDS_VERSION 330 /* 2008-05-16 zero is not a valid ID for anything (including factions) */
#define NOBORDERATTRIBS_VERSION 331 /* 2008-05-17 connection::attribs has been moved to userdata */ #define NOBORDERATTRIBS_VERSION 331 /* 2008-05-17 connection::attribs has been moved to userdata */
#define UIDHASH_VERSION 332 /* 2008-05-22 borders use the region.uid to store */ #define UIDHASH_VERSION 332 /* 2008-05-22 borders use the region.uid to store */

View File

@ -1758,7 +1758,7 @@ unit *owner_buildingtyp(const region * r, const building_type * bt)
for (b = rbuildings(r); b; b = b->next) { for (b = rbuildings(r); b; b = b->next) {
owner = building_owner(b); owner = building_owner(b);
if (b->type == bt && owner != NULL) { if (b->type == bt && owner != NULL) {
if (b->size >= bt->maxsize) { if (building_finished(b)) {
return owner; return owner;
} }
} }

View File

@ -1898,7 +1898,7 @@ const faction * f)
} }
} }
if (b->size < b->type->maxsize) { if (!building_finished(b)) {
bytes = (int)strlcpy(bufp, LOC(lang, "nr_building_inprogress"), size); bytes = (int)strlcpy(bufp, LOC(lang, "nr_building_inprogress"), size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();

View File

@ -975,7 +975,7 @@ static int sp_blessstonecircle(castorder * co)
return 0; return 0;
} }
if (b->size < b->type->maxsize) { if (!building_finished(b)) {
ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order, ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order,
"error_notcomplete", "building", b)); "error_notcomplete", "building", b));
return 0; return 0;
@ -4502,11 +4502,11 @@ int sp_icastle(castorder * co)
if (type == bt_illusion) { if (type == bt_illusion) {
b->size = (rng_int() % (int)((power * power) + 1) * 10); b->size = (rng_int() % (int)((power * power) + 1) * 10);
} }
else if (type->maxsize == -1) { else if (type->maxsize >0) {
b->size = ((rng_int() % (int)(power)) + 1) * 5; b->size = type->maxsize;
} }
else { else {
b->size = type->maxsize; b->size = ((rng_int() % (int)(power)) + 1) * 5;
} }
if (type->name == NULL) { if (type->name == NULL) {

View File

@ -149,8 +149,7 @@ make_wormhole(const building_type * bt_wormhole, region * r1, region * r2)
attrib *a2 = a_add(&b2->attribs, a_new(&at_wormhole)); attrib *a2 = a_add(&b2->attribs, a_new(&at_wormhole));
a1->data.v = b2->region; a1->data.v = b2->region;
a2->data.v = b1->region; a2->data.v = b1->region;
b1->size = bt_wormhole->maxsize; b1->size = b2->size = bt_wormhole->maxcapacity * bt_wormhole->capacity;
b2->size = bt_wormhole->maxsize;
ADDMSG(&r1->msgs, msg_message("wormhole_appear", "region", r1)); ADDMSG(&r1->msgs, msg_message("wormhole_appear", "region", r1));
ADDMSG(&r2->msgs, msg_message("wormhole_appear", "region", r2)); ADDMSG(&r2->msgs, msg_message("wormhole_appear", "region", r2));
} }