From 9b56ccf53c00d35246f1f3b01443b432ebd17978 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 9 Dec 2014 14:14:35 +0100 Subject: [PATCH] cleaning up some alliance code, killing bitrot from WDW. --- src/attributes/CMakeLists.txt | 1 - src/attributes/alliance.c | 33 --------------------- src/attributes/alliance.h | 30 ------------------- src/attributes/attributes.c | 43 +++++++++++---------------- src/kernel/alliance.c | 4 +++ src/kernel/alliance.h | 1 + src/kernel/build.c | 7 ----- src/kernel/building.c | 42 -------------------------- src/kernel/config.h | 3 -- src/kernel/order.c | 1 + src/report.c | 56 ++--------------------------------- src/reports.c | 2 +- src/spells.c | 49 ------------------------------ 13 files changed, 27 insertions(+), 245 deletions(-) delete mode 100644 src/attributes/alliance.c delete mode 100644 src/attributes/alliance.h diff --git a/src/attributes/CMakeLists.txt b/src/attributes/CMakeLists.txt index 05d3a17a5..7bb3f91ba 100644 --- a/src/attributes/CMakeLists.txt +++ b/src/attributes/CMakeLists.txt @@ -4,7 +4,6 @@ stealth.test.c ) SET(_FILES -alliance.c attributes.c fleechance.c follow.c diff --git a/src/attributes/alliance.c b/src/attributes/alliance.c deleted file mode 100644 index b0f2c6301..000000000 --- a/src/attributes/alliance.c +++ /dev/null @@ -1,33 +0,0 @@ -/* -Copyright (c) 1998-2010, Enno Rehling - Katja Zedel - -Permission to use, copy, modify, and/or distribute this software for any -purpose with or without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -**/ - -#include -#include "alliance.h" - -#include -#include - -attrib_type at_alliance = { - "alliance", - NULL, - NULL, - NULL, - a_writeint, - a_readint, - ATF_UNIQUE -}; diff --git a/src/attributes/alliance.h b/src/attributes/alliance.h deleted file mode 100644 index ca90da4ac..000000000 --- a/src/attributes/alliance.h +++ /dev/null @@ -1,30 +0,0 @@ -/* -Copyright (c) 1998-2010, Enno Rehling - Katja Zedel - -Permission to use, copy, modify, and/or distribute this software for any -purpose with or without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -**/ - -#ifndef H_ATTRIBUTE_ALLIANCE -#define H_ATTRIBUTE_ALLIANCE -#ifdef __cplusplus -extern "C" { -#endif - - extern struct attrib_type at_alliance; - -#ifdef __cplusplus -} -#endif -#endif diff --git a/src/attributes/attributes.c b/src/attributes/attributes.c index d9d62149d..b078d062f 100644 --- a/src/attributes/attributes.c +++ b/src/attributes/attributes.c @@ -1,7 +1,7 @@ /* Copyright (c) 1998-2010, Enno Rehling - Katja Zedel +Katja Zedel Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -37,9 +37,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "raceprefix.h" #include "reduceproduction.h" #include "targetregion.h" -#ifdef WDW_PYRAMID -# include "alliance.h" -#endif /* kernel includes */ #include @@ -53,30 +50,26 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include attrib_type at_unitdissolve = { - "unitdissolve", NULL, NULL, NULL, a_writechars, a_readchars + "unitdissolve", NULL, NULL, NULL, a_writechars, a_readchars }; void register_attributes(void) { at_register(&at_stealth); at_register(&at_object); - at_register(&at_unitdissolve); - at_register(&at_overrideroads); - at_register(&at_raceprefix); - at_register(&at_iceberg); - at_register(&at_key); - at_register(&at_gm); - at_register(&at_follow); - at_register(&at_targetregion); - at_register(&at_orcification); - at_register(&at_hate); - at_register(&at_reduceproduction); - at_register(&at_otherfaction); - at_register(&at_racename); - at_register(&at_movement); - at_register(&at_moved); - -#ifdef WDW_PYRAMID - at_register(&at_alliance); -#endif /* WDW_PYRAMID */ + at_register(&at_unitdissolve); + at_register(&at_overrideroads); + at_register(&at_raceprefix); + at_register(&at_iceberg); + at_register(&at_key); + at_register(&at_gm); + at_register(&at_follow); + at_register(&at_targetregion); + at_register(&at_orcification); + at_register(&at_hate); + at_register(&at_reduceproduction); + at_register(&at_otherfaction); + at_register(&at_racename); + at_register(&at_movement); + at_register(&at_moved); } diff --git a/src/kernel/alliance.c b/src/kernel/alliance.c index 70390ca4d..2192e0672 100644 --- a/src/kernel/alliance.c +++ b/src/kernel/alliance.c @@ -513,3 +513,7 @@ void alliance_setname(alliance * self, const char *name) else self->name = NULL; } + +bool is_allied(const struct faction *f1, const struct faction *f2) { + return (f1 == f2 || (f1->alliance && f1->alliance == f2->alliance)); +} diff --git a/src/kernel/alliance.h b/src/kernel/alliance.h index e2562c1f3..830dd8d3b 100644 --- a/src/kernel/alliance.h +++ b/src/kernel/alliance.h @@ -60,6 +60,7 @@ extern "C" { void free_alliance(struct alliance *al); extern struct faction *alliance_get_leader(struct alliance *al); extern void alliance_cmd(void); + bool is_allied(const struct faction *f1, const struct faction *f2); void alliance_setname(alliance * self, const char *name); /* execute commands */ diff --git a/src/kernel/build.c b/src/kernel/build.c index 73199d94a..808f7f87d 100644 --- a/src/kernel/build.c +++ b/src/kernel/build.c @@ -65,7 +65,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /* attributes inclues */ #include -#include struct building *getbuilding(const struct region *r) { @@ -775,12 +774,6 @@ build_building(unit * u, const building_type * btype, int id, int want, order * if (u->number && leave(u, false)) { u_set_building(u, b); } -#ifdef WDW_PYRAMID - if (b->type == bt_find("pyramid") && f_get_alliance(u->faction) != NULL) { - attrib *a = a_add(&b->attribs, a_new(&at_alliance)); - a->data.i = u->faction->alliance->id; - } -#endif } btname = LOC(lang, btype->_name); diff --git a/src/kernel/building.c b/src/kernel/building.c index bf8bb8d08..ffed936a2 100644 --- a/src/kernel/building.c +++ b/src/kernel/building.c @@ -270,45 +270,6 @@ static const char *fort_name(const struct building_type *btype, return castle_name_i(btype, b, bsize, fname); } -#ifdef WDW_PYRAMID - -static const char *pyramid_name(const struct building_type *btype, int bsize) -{ - static char p_name_buf[32]; - int level = 0; - const construction *ctype; - - ctype = btype->construction; - - while (ctype && ctype->maxsize != -1 && ctype->maxsize <= bsize) { - bsize -= ctype->maxsize; - ctype = ctype->improvement; - ++level; - } - - sprintf(p_name_buf, "pyramid%d", level); - - return p_name_buf; -} - -int wdw_pyramid_level(const struct building *b) -{ - const construction *ctype = b->type->construction; - int completed = b->size; - int level = 0; - - while (ctype->improvement != NULL && - ctype->improvement != ctype && - ctype->maxsize > 0 && ctype->maxsize <= completed) { - ++level; - completed -= ctype->maxsize; - ctype = ctype->improvement; - } - - return level; -} -#endif - /* for finding out what was meant by a particular building string */ static local_names *bnames; @@ -371,9 +332,6 @@ void register_buildings(void) register_function((pf_generic) & castle_name, "castle_name"); register_function((pf_generic) & castle_name_2, "castle_name_2"); register_function((pf_generic) & fort_name, "fort_name"); -#ifdef WDW_PYRAMID - register_function((pf_generic) & pyramid_name, "pyramid_name"); -#endif } void write_building_reference(const struct building *b, struct storage *store) diff --git a/src/kernel/config.h b/src/kernel/config.h index a3e218a82..95a59ac1d 100644 --- a/src/kernel/config.h +++ b/src/kernel/config.h @@ -34,9 +34,6 @@ extern "C" { #define INSECT_POTION /* Spezialtrank für Insekten */ #define ORCIFICATION /* giving snotlings to the peasants gets counted */ -// TODO: remove macro, move all alliance code into a module. -#define ALLIED(f1, f2) (f1==f2 || (f1->alliance && f1->alliance==f2->alliance)) - /* for some good prime numbers, check http://www.math.niu.edu/~rusin/known-math/98/pi_x */ #ifndef MAXREGIONS # define MAXREGIONS 524287 /* must be prime for hashing. 262139 was a little small */ diff --git a/src/kernel/order.c b/src/kernel/order.c index 5d2ab53da..93e3d6c96 100644 --- a/src/kernel/order.c +++ b/src/kernel/order.c @@ -568,6 +568,7 @@ keyword_t init_order(const struct order *ord) { char *cmd = 0; + assert(ord && ord->data); if (ord->data->_str) cmd = _strdup(ord->data->_str); init_tokens_str(cmd, cmd); return ord->data->_keyword; diff --git a/src/report.c b/src/report.c index 1b21a4cc6..7bc09d60c 100644 --- a/src/report.c +++ b/src/report.c @@ -31,7 +31,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /* attributes includes */ #include #include -#include #include /* gamecode includes */ @@ -711,8 +710,7 @@ nr_unit(FILE * F, const faction * f, const unit * u, int indent, int mode) if (u->faction == f) { marker = '*'; } - else if ALLIED - (u->faction, f) { + else if (is_allied(u->faction, f)) { marker = 'o'; } else if (a_otherfaction && f != u->faction @@ -1889,7 +1887,7 @@ static void list_address(FILE * F, const faction * uf, quicklist * seenfactions) f->banner ? f->banner : ""); if (uf == f) label = '*'; - else if (ALLIED(uf, f)) + else if (is_allied(uf, f)) label = 'o'; else if (alliedfaction(NULL, uf, f, HELP_ALL)) label = '+'; @@ -2046,62 +2044,12 @@ const faction * f) WARN_STATIC_BUFFER(); i = b->display[strlen(b->display) - 1]; } -#ifdef WDW_PYRAMID - - if (i != '!' && i != '?' && i != '.') { - scat(", "); - } - - if (b->type == bt_find("pyramid")) { - unit *owner = building_owner(b); - scat("Größenstufe "); - icat(wdw_pyramid_level(b)); - scat("."); - - if (owner && owner->faction == f) { - const construction *ctype = b->type->construction; - int completed = b->size; - int c; - - scat(" Baukosten pro Größenpunkt: "); - - while (ctype->improvement != NULL && - ctype->improvement != ctype && - ctype->maxsize > 0 && ctype->maxsize <= completed) { - completed -= ctype->maxsize; - ctype = ctype->improvement; - } - - assert(ctype->materials != NULL); - - for (c = 0; ctype->materials[c].number; c++) { - const resource_type *rtype = ctype->materials[c].rtype; - int number = ctype->materials[c].number; - - if (c > 0) { - scat(", "); - } - icat(number); - scat(" "); - scat(locale_string(lang, resourcename(rtype, - number != 1 ? GR_PLURAL : 0))); - } - - scat("."); - - scat(" Erforderlicher Talentwert: "); - icat(b->type->construction->minskill); - scat("."); - } - } -#else if (i != '!' && i != '?' && i != '.') { bytes = (int)strlcpy(bufp, ".", size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); } -#endif *bufp = 0; rparagraph(F, buffer, 2, 0, 0); diff --git a/src/reports.c b/src/reports.c index 2e0278775..ad43fdfe9 100644 --- a/src/reports.c +++ b/src/reports.c @@ -1108,7 +1108,7 @@ static void get_addresses(report_context * ctx) faction *sf = visible_faction(ctx->f, u); bool ballied = sf && sf != ctx->f && sf != lastf && !fval(u, UFL_ANON_FACTION) && cansee(ctx->f, r, u, stealthmod); - if (ballied || ALLIED(ctx->f, sf)) { + if (ballied || is_allied(ctx->f, sf)) { add_seen_faction_i(&flist, sf); lastf = sf; } diff --git a/src/spells.c b/src/spells.c index 82714ed63..c2ec72c24 100644 --- a/src/spells.c +++ b/src/spells.c @@ -6526,54 +6526,6 @@ int sp_becomewyrm(castorder * co) return 0; } -/* ------------------------------------------------------------- */ -/* Name: WDW-Pyramidenfindezauber - * Stufe: unterschiedlich - * Gebiet: alle - * Wirkung: - * gibt die ungefaehre Entfernung zur naechstgelegenen Pyramiden- - * region an. - * - * Flags: - */ -static int sp_wdwpyramid(castorder * co) -{ - region *r = co_get_region(co); - unit *mage = co->magician.u; - int cast_level = co->level; - - if (a_find(r->attribs, &at_wdwpyramid) != NULL) { - ADDMSG(&mage->faction->msgs, msg_message("wdw_pyramidspell_found", - "unit region command", mage, r, co->order)); - } - else { - region *r2; - int mindist = INT_MAX; - int minshowdist; - int maxshowdist; - - for (r2 = regions; r2; r2 = r2->next) { - if (a_find(r2->attribs, &at_wdwpyramid) != NULL) { - int dist = distance(mage->region, r2); - if (dist < mindist) { - mindist = dist; - } - } - } - - assert(mindist >= 1); - - minshowdist = mindist - rng_int() % 5; - maxshowdist = minshowdist + 4; - - ADDMSG(&mage->faction->msgs, msg_message("wdw_pyramidspell_notfound", - "unit region command mindist maxdist", mage, r, co->order, - _max(1, minshowdist), maxshowdist)); - } - - return cast_level; -} - typedef struct spelldata { const char *sname; spell_f cast; @@ -6861,7 +6813,6 @@ void register_spells(void) ct_register(&ct_deathcloud); register_function((pf_generic)sp_blessedharvest, "cast_blessedharvest"); - register_function((pf_generic)sp_wdwpyramid, "wdwpyramid"); register_function((pf_generic)sp_summon_familiar, "cast_familiar"); register_function((pf_generic)sp_babbler, "cast_babbler"); register_function((pf_generic)sp_readmind, "cast_readmind");