From c1ba34a268c15157c892fdc7f1e0f9c90a89e682 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 28 May 2007 17:31:40 +0000 Subject: [PATCH] archetype-recruiting can be limited by building-size --- src/common/gamecode/archetype.c | 6 +++++- src/common/gamecode/archetype.h | 1 + src/common/gamecode/economy.c | 28 ++++++++++++++++++++++++---- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/common/gamecode/archetype.c b/src/common/gamecode/archetype.c index 7b0a97450..be70742d1 100644 --- a/src/common/gamecode/archetype.c +++ b/src/common/gamecode/archetype.c @@ -24,6 +24,10 @@ static struct archetype * archetypes; +struct attrib_type at_recruit = { + "recruit", NULL, NULL, NULL, NULL, NULL, ATF_UNIQUE +}; + const struct archetype * find_archetype(const char * s, const struct locale * lang) { @@ -102,7 +106,7 @@ parse_archetypes(xmlDocPtr doc) xmlFree(property); } - arch->size = xml_ivalue(node, "cost", 1); + arch->size = xml_ivalue(node, "cost", 0); xpath->node = node; sub = xmlXPathEvalExpression(BAD_CAST "construction", xpath); diff --git a/src/common/gamecode/archetype.h b/src/common/gamecode/archetype.h index a966a7b15..c5634984d 100644 --- a/src/common/gamecode/archetype.h +++ b/src/common/gamecode/archetype.h @@ -32,6 +32,7 @@ extern "C" { extern void register_archetype(struct archetype * arch); extern void register_archetypes(void); + extern struct attrib_type at_recruit; #ifdef __cplusplus } diff --git a/src/common/gamecode/economy.c b/src/common/gamecode/economy.c index 48bf66075..fc1949e78 100644 --- a/src/common/gamecode/economy.c +++ b/src/common/gamecode/economy.c @@ -1068,6 +1068,7 @@ recruit_archetype(unit * u, order * ord) id = getid(); if (n>0 && s && s[0]) { const archetype * arch = find_archetype(s, u->faction->locale); + attrib * a = NULL; if (u->number>0) { ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "unit_must_be_new", "")); @@ -1080,16 +1081,35 @@ recruit_archetype(unit * u, order * ord) /* TODO: error message */ return 0; } - if (arch->btype && u->building->type!=arch->btype) { - ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "unit_must_be_in_building", "type", arch->btype)); - /* TODO: error message */ - return 0; + if (arch->btype) { + if (u->building==NULL || u->building->type!=arch->btype) { + ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "unit_must_be_in_building", "type", arch->btype)); + /* TODO: error message */ + return 0; + } + if (arch->size) { + int maxsize = u->building->size; + attrib * a = a_find(u->building->attribs, &at_recruit); + if (a!=NULL) { + maxsize -= a->data.i; + } + n = max(maxsize/arch->size, n); + if (n<=0) { + ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "recruit_capacity_exhausted", "building", u->building)); + /* TODO: error message */ + return 0; + } + } } n = build(u, arch->ctype, 0, n); if (n>0) { scale_number(u, n); equip_unit(u, arch->equip); + if (arch->size) { + if (a==NULL) a = a_add(&u->building->attribs, a_new(&at_recruit)); + a->data.i += n*arch->size; + } return n; } else switch(n) { case ENOMATERIALS: