diff --git a/src/common/gamecode/laws.c b/src/common/gamecode/laws.c index c375eed2e..16bbd385b 100644 --- a/src/common/gamecode/laws.c +++ b/src/common/gamecode/laws.c @@ -3356,7 +3356,49 @@ ageing(void) static int maxunits(faction *f) { - return (int) (global.maxunits * (1 + 0.4 * fspecial(f, FS_ADMINISTRATOR))); + if(global.unitsperalliance == true) { + faction *f2; + float mult = 1.0; + + for(f2 = factions; f2; f2 = f2->next) { + if(f2->alliance == f->alliance) { + mult += 0.4 * fspecial(f2, FS_ADMINISTRATOR); + } + } + return (int) (global.maxunits * mult); + } + + return (int) (global.maxunits * + (1 + 0.4 * fspecial(f, FS_ADMINISTRATOR))); +} + +static boolean +checkunitnumber(faction *f) +{ + 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 unitsperalliance is true, maxunits returns the + number of units allowed in an alliance */ + if(unitsinalliance >= maxunits(f)) { + return false; + } else { + return true; + } + } + + if(f->no_units >= maxunits(f)) { + return false; + } + + return true; } @@ -3381,13 +3423,18 @@ new_units (void) if (getparam(u->faction->locale) == P_TEMP) { char * name; int g, alias; - int mu = maxunits(u->faction); order ** newordersp; - if(u->faction->no_units >= mu) { - sprintf(buf, "Eine Partei darf aus nicht mehr als %d " - "Einheiten bestehen.", mu); - mistake(u, makeord, buf, MSG_PRODUCE); + if(checkunitnumber(u->faction) == false) { + if(global.unitsperalliance == false) { + ADDMSG(&u->faction->msgs, msg_message("too_many_units_in_faction", + "command unit region allowed", + getcommand(makeord), u, r, maxunits(u->faction))); + } else { + ADDMSG(&u->faction->msgs, msg_message("too_many_units_in_alliance", + "command unit region allowed", + getcommand(makeord), u, r, maxunits(u->faction))); + } ordp = &makeord->next; while (*ordp) { diff --git a/src/common/kernel/eressea.h b/src/common/kernel/eressea.h index 31851c79e..0d6e7ba4e 100644 --- a/src/common/kernel/eressea.h +++ b/src/common/kernel/eressea.h @@ -1156,6 +1156,7 @@ extern const struct race * new_race[]; typedef struct settings { const char *gamename; const char *welcomepath; + boolean unitsperalliance; unsigned int maxunits; struct attrib *attribs; unsigned int data_version; diff --git a/src/common/kernel/xmlreader.c b/src/common/kernel/xmlreader.c index b493a156d..547491a06 100644 --- a/src/common/kernel/xmlreader.c +++ b/src/common/kernel/xmlreader.c @@ -1177,6 +1177,15 @@ parse_main(xmlDocPtr doc) global.welcomepath = strdup((const char*)property); xmlFree(property); } + + global.unitsperalliance = false; + property = xmlGetProp(node, BAD_CAST "unitsperalliance"); + if (property!=NULL) { + if(!strcmp(property, "yes")) { + global.unitsperalliance = true; + } + xmlFree(property); + } property = xmlGetProp(node, BAD_CAST "units"); if (property!=NULL) { diff --git a/src/res/messages.xml b/src/res/messages.xml index 57c1776b9..91a97ad38 100644 --- a/src/res/messages.xml +++ b/src/res/messages.xml @@ -6186,5 +6186,27 @@ "$unit($unit) sends the plague on $region($region)." + + + + + + + + "$unit($unit) in $region($region): '$order($command)' - Eine Partei darf aus nicht mehr als $int($allowed) Einheiten bestehen." + "$unit($unit) in $region($region): '$order($command)' - A faction may not consist of more than $int($allowed) units." + + + + + + + + + + "$unit($unit) in $region($region): '$order($command)' - Eine Allianz darf aus nicht mehr als $int($allowed) Einheiten bestehen." + "$unit($unit) in $region($region): '$order($command)' - An alliance may not consist of more than $int($allowed) units." + + diff --git a/src/res/vinyambar-wdw.xml b/src/res/vinyambar-wdw.xml index 9d557949a..efd64dfda 100644 --- a/src/res/vinyambar-wdw.xml +++ b/src/res/vinyambar-wdw.xml @@ -14,7 +14,7 @@ - + Game specific