From 2fc718b983debbfb234a3add268a9f158dd76d23 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 20 May 2005 22:51:37 +0000 Subject: [PATCH] =?UTF-8?q?Der=20neuer=20Code=20von=20Corwin=20verhinderte?= =?UTF-8?q?=20neue=20Einheiten,=20wenn=20game.maxunits=20im=20XML=20file?= =?UTF-8?q?=20nicht=20gesetzt=20war=20(Regel=20im=20alten=20Code=20war=20w?= =?UTF-8?q?enn=20maxunits=3D0,=20dann=20kein=20Limit).=20War=20nicht=20gut?= =?UTF-8?q?=20f=C3=BCr=20HSE=20:-)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/gamecode/laws.c | 67 ++++++++++++++++------------------- src/common/kernel/xmlreader.c | 8 ++--- 2 files changed, 32 insertions(+), 43 deletions(-) diff --git a/src/common/gamecode/laws.c b/src/common/gamecode/laws.c index 637a473f5..3becc13e3 100644 --- a/src/common/gamecode/laws.c +++ b/src/common/gamecode/laws.c @@ -3354,54 +3354,47 @@ ageing(void) } static int -maxunits(faction *f) +maxunits(const faction *f) { - if(global.unitsperalliance == true) { - faction *f2; - float mult = 1.0; + if (global.unitsperalliance == true) { + faction *f2; + float mult = 1.0; - for(f2 = factions; f2; f2 = f2->next) { - if(f2->alliance == f->alliance) { - mult += 0.4f * fspecial(f2, FS_ADMINISTRATOR); - } - } - return (int) (global.maxunits * mult); - } + for (f2 = factions; f2; f2 = f2->next) { + if (f2->alliance == f->alliance) { + mult += 0.4f * fspecial(f2, FS_ADMINISTRATOR); + } + } + return (int) (global.maxunits * mult); + } - return (int) (global.maxunits * - (1 + 0.4 * fspecial(f, FS_ADMINISTRATOR))); + return (int) (global.maxunits * (1 + 0.4 * fspecial(f, FS_ADMINISTRATOR))); } static boolean -checkunitnumber(faction *f) +checkunitnumber(const faction *f, int add) { - if(global.unitsperalliance == true) { - faction *f2; - int unitsinalliance = 0; - - for(f2 = factions; f2; f2 = f2->next) { - if(f->alliance == f2->alliance) { - unitsinalliance += f2->no_units; - } - } + if (global.maxunits==0) return true; + if (global.unitsperalliance == true) { + /* if unitsperalliance is true, maxunits returns the + number of units allowed in an alliance */ + faction *f2; + int unitsinalliance = add; + int maxu = maxunits(f); - /* if unitsperalliance is true, maxunits returns the - number of units allowed in an alliance */ - if(unitsinalliance >= maxunits(f)) { - return false; - } else { - return true; - } - } + for (f2 = factions; f2; f2 = f2->next) { + if (f->alliance == f2->alliance) { + unitsinalliance += f2->no_units; + } + if (unitsinalliance > maxu) return false; + } - if(f->no_units >= maxunits(f)) { - return false; - } + return true; + } - return true; + return (f->no_units + add < maxunits(f)); } - static void new_units (void) { @@ -3425,7 +3418,7 @@ new_units (void) int g, alias; order ** newordersp; - if (checkunitnumber(u->faction) == false) { + if (checkunitnumber(u->faction, 1) == false) { if (global.unitsperalliance == false) { ADDMSG(&u->faction->msgs, msg_message("too_many_units_in_faction", "command unit region allowed", diff --git a/src/common/kernel/xmlreader.c b/src/common/kernel/xmlreader.c index 5735f019b..ef9450e0e 100644 --- a/src/common/kernel/xmlreader.c +++ b/src/common/kernel/xmlreader.c @@ -39,6 +39,7 @@ without prior permission by the authors of Eressea. /* libc includes */ #include #include +#include #include static boolean gamecode_enabled = false; @@ -1179,12 +1180,7 @@ parse_main(xmlDocPtr doc) } global.unitsperalliance = xml_bvalue(node, "unitsperalliance", false); - - property = xmlGetProp(node, BAD_CAST "units"); - if (property!=NULL) { - global.maxunits = atoi((const char*)property); - xmlFree(property); - } + global.maxunits = xml_ivalue(node, "units", INT_MAX); property = xmlGetProp(node, BAD_CAST "name"); if (property!=NULL) {