- construction can have building-requirements

This commit is contained in:
Enno Rehling 2009-05-18 14:52:35 +00:00
parent 9a9ff08302
commit bb50d7a9ef
8 changed files with 94 additions and 40 deletions

View file

@ -1221,6 +1221,10 @@ recruit_archetype(unit * u, order * ord)
/* no skill, or not enough skill points to build */ /* no skill, or not enough skill points to build */
cmistake(u, ord, 50, MSG_PRODUCE); cmistake(u, ord, 50, MSG_PRODUCE);
break; break;
case EBUILDINGREQ:
ADDMSG(&u->faction->msgs,
msg_feedback(u, u->thisorder, "building_needed", "building", arch->ctype->btype->_name));
break;
default: default:
assert(!"unhandled return value from build() in recruit_archetype"); assert(!"unhandled return value from build() in recruit_archetype");
} }
@ -1338,6 +1342,10 @@ manufacture(unit * u, const item_type * itype, int want)
ADDMSG(&u->faction->msgs, ADDMSG(&u->faction->msgs,
msg_feedback(u, u->thisorder, "skill_needed", "skill", sk)); msg_feedback(u, u->thisorder, "skill_needed", "skill", sk));
return; return;
case EBUILDINGREQ:
ADDMSG(&u->faction->msgs,
msg_feedback(u, u->thisorder, "building_needed", "building", itype->construction->btype->_name));
return;
case ELOWSKILL: case ELOWSKILL:
ADDMSG(&u->faction->msgs, ADDMSG(&u->faction->msgs,
msg_feedback(u, u->thisorder, "manufacture_skills", "skill minskill product", msg_feedback(u, u->thisorder, "manufacture_skills", "skill minskill product",
@ -1736,6 +1744,10 @@ create_potion(unit * u, const potion_type * ptype, int want)
/* no skill, or not enough skill points to build */ /* no skill, or not enough skill points to build */
cmistake(u, u->thisorder, 50, MSG_PRODUCE); cmistake(u, u->thisorder, 50, MSG_PRODUCE);
break; break;
case EBUILDINGREQ:
ADDMSG(&u->faction->msgs,
msg_feedback(u, u->thisorder, "building_needed", "building", ptype->itype->construction->btype->_name));
break;
case ECOMPLETE: case ECOMPLETE:
assert(0); assert(0);
break; break;

View file

@ -608,6 +608,14 @@ build(unit * u, const construction * ctype, int completed, int want)
if (type==NULL) return 0; if (type==NULL) return 0;
if (type->improvement==NULL && completed==type->maxsize) if (type->improvement==NULL && completed==type->maxsize)
return ECOMPLETE; return ECOMPLETE;
if (type->btype!=NULL) {
building * b;
if (!u->building || u->building->type!=type->btype) {
return EBUILDINGREQ;
}
b = inside_building(u);
if (b==NULL) return EBUILDINGREQ;
}
if (type->skill!=NOSKILL) { if (type->skill!=NOSKILL) {
int effsk; int effsk;

View file

@ -35,29 +35,32 @@ extern "C" {
struct xml_tag; struct xml_tag;
typedef struct requirement { typedef struct requirement {
const struct resource_type * rtype; const struct resource_type * rtype;
int number; int number;
double recycle; /* recycling quota */ double recycle; /* recycling quota */
} requirement; } requirement;
typedef struct construction { typedef struct construction {
skill_t skill; /* skill req'd per point of size */ skill_t skill; /* skill req'd per point of size */
int minskill; /* skill req'd per point of size */ int minskill; /* skill req'd per point of size */
int maxsize; /* maximum size of this type */ int maxsize; /* maximum size of this type */
int reqsize; /* size of object using up 1 set of requirement. */ int reqsize; /* size of object using up 1 set of requirement. */
requirement * materials; /* material req'd to build one object */ requirement * materials; /* material req'd to build one object */
const struct building_type * btype;
/* building type required to make this thing */
struct construction * improvement;
/* next level, if upgradable. if more than one of these items
* can be built (weapons, armour) per turn, must not be NULL,
* but point to the same type again:
* const_sword.improvement = &const_sword
* last level of a building points to NULL, as do objects of
* an unlimited size.
*/
struct attrib * attribs;
/* stores skill modifiers and other attributes */
struct construction * improvement;
/* next level, if upgradable. if more than one of these items
* can be built (weapons, armour) per turn, must not be NULL,
* but point to the same type again:
* const_sword.improvement = &const_sword
* last level of a building points to NULL, as do objects of
* an unlimited size.
*/
struct attrib * attribs;
/* stores skill modifiers and other attributes */
} construction; } construction;
extern int destroy_cmd(struct unit * u, struct order * ord); extern int destroy_cmd(struct unit * u, struct order * ord);
@ -88,6 +91,7 @@ extern struct message * msg_materials_required(struct unit * u, struct order * o
#define ENEEDSKILL -2 #define ENEEDSKILL -2
#define ECOMPLETE -3 #define ECOMPLETE -3
#define ENOMATERIALS -4 #define ENOMATERIALS -4
#define EBUILDINGREQ -5
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -384,11 +384,11 @@ findbuildingtype(const char * name, const struct locale * lang)
void void
register_buildings(void) register_buildings(void)
{ {
register_function((pf_generic)&init_smithy, "init_smithy"); register_function((pf_generic)&init_smithy, "init_smithy");
register_function((pf_generic)&castle_name, "castle_name"); register_function((pf_generic)&castle_name, "castle_name");
register_function((pf_generic)&fort_name, "fort_name"); register_function((pf_generic)&fort_name, "fort_name");
#ifdef WDW_PYRAMID #ifdef WDW_PYRAMID
register_function((pf_generic)&pyramid_name, "pyramid_name"); register_function((pf_generic)&pyramid_name, "pyramid_name");
#endif #endif
} }

View file

@ -53,6 +53,20 @@ without prior permission by the authors of Eressea.
static boolean gamecode_enabled = false; static boolean gamecode_enabled = false;
static building_type * bt_get_or_create(const char * name)
{
if (name!=NULL) {
building_type * btype = bt_find(name);
if (btype==NULL) {
btype = calloc(sizeof(building_type), 1);
btype->_name = strdup(name);
bt_register(btype);
}
return btype;
}
return NULL;
}
void void
enable_xml_gamecode(void) enable_xml_gamecode(void)
{ {
@ -180,6 +194,12 @@ xml_readconstruction(xmlXPathContextPtr xpath, xmlNodeSetPtr nodeSet, constructi
con->maxsize = xml_ivalue(node, "maxsize", -1); con->maxsize = xml_ivalue(node, "maxsize", -1);
con->minskill = xml_ivalue(node, "minskill", -1); con->minskill = xml_ivalue(node, "minskill", -1);
con->reqsize = xml_ivalue(node, "reqsize", -1); con->reqsize = xml_ivalue(node, "reqsize", -1);
propValue = xmlGetProp(node, BAD_CAST "building");
if (propValue!=NULL) {
con->btype = bt_get_or_create((const char*)propValue);
xmlFree(propValue);
}
/* read construction/requirement */ /* read construction/requirement */
xpath->node = node; xpath->node = node;
@ -244,12 +264,7 @@ parse_buildings(xmlDocPtr doc)
propValue = xmlGetProp(node, BAD_CAST "name"); propValue = xmlGetProp(node, BAD_CAST "name");
assert(propValue!=NULL); assert(propValue!=NULL);
btype = bt_find((const char*)propValue); btype = bt_get_or_create((const char*)propValue);
if (btype==NULL) {
btype = calloc(sizeof(building_type), 1);
btype->_name = strdup((const char *)propValue);
bt_register(btype);
}
xmlFree(propValue); xmlFree(propValue);
btype->capacity = xml_ivalue(node, "capacity", -1); btype->capacity = xml_ivalue(node, "capacity", -1);
@ -1026,12 +1041,7 @@ parse_resources(xmlDocPtr doc)
propValue = xmlGetProp(node, BAD_CAST "building"); propValue = xmlGetProp(node, BAD_CAST "building");
if (propValue!=NULL) { if (propValue!=NULL) {
btype = bt_find((const char*)propValue); btype = bt_get_or_create((const char*)propValue);
if (btype==NULL) {
btype = calloc(sizeof(building_type), 1);
btype->_name = strdup((const char *)propValue);
bt_register(btype);
}
xmlFree(propValue); xmlFree(propValue);
} }
rdata->modifiers[k].btype = btype; rdata->modifiers[k].btype = btype;
@ -1050,12 +1060,7 @@ parse_resources(xmlDocPtr doc)
} else if (strcmp((const char *)propValue, "require")==0) { } else if (strcmp((const char *)propValue, "require")==0) {
xmlChar * propBldg = xmlGetProp(node, BAD_CAST "building"); xmlChar * propBldg = xmlGetProp(node, BAD_CAST "building");
if (propBldg!=NULL) { if (propBldg!=NULL) {
btype = bt_find((const char*)propBldg); btype = bt_get_or_create((const char*)propBldg);
if (btype==NULL) {
btype = calloc(sizeof(building_type), 1);
btype->_name = strdup((const char *)propBldg);
bt_register(btype);
}
rdata->modifiers[k].btype = btype; rdata->modifiers[k].btype = btype;
rdata->modifiers[k].flags = RMF_REQUIREDBUILDING; rdata->modifiers[k].flags = RMF_REQUIREDBUILDING;
xmlFree(propBldg); xmlFree(propBldg);

14
src/res/e2k9/items.xml Normal file
View file

@ -0,0 +1,14 @@
<?xml version="1.0"?>
<resources>
<resource name="charger">
<item big="yes" weight="5000" score="10" capacity="7000" animal="yes">
<construction skill="training" minskill="4" reqsize="1">
<requirement type="money" quantity="200"/>
<requirement type="iron" quantity="1"/>
</construction>
<function name="give" value="givehorses"/>
</item>
</resource>
</resources>

View file

@ -38,6 +38,7 @@
<skill name="magic" modifier="-1"/> <skill name="magic" modifier="-1"/>
<skill name="mining" modifier="1"/> <skill name="mining" modifier="1"/>
<skill name="quarrying" modifier="1"/> <skill name="quarrying" modifier="1"/>
<skill name="riding" modifier="-99"/>
<skill name="sailing" modifier="-1"/> <skill name="sailing" modifier="-1"/>
<skill name="shipcraft" modifier="-1"/> <skill name="shipcraft" modifier="-1"/>
<skill name="tactics" modifier="1"/> <skill name="tactics" modifier="1"/>

View file

@ -6968,6 +6968,16 @@
<text locale="fr">"'$order($command)' - $race($race,0) are peace-loving and will not attack anyone."</text> <text locale="fr">"'$order($command)' - $race($race,0) are peace-loving and will not attack anyone."</text>
<text locale="en">"'$order($command)' - $race($race,0) are peace-loving and will not attack anyone."</text> <text locale="en">"'$order($command)' - $race($race,0) are peace-loving and will not attack anyone."</text>
</message> </message>
<message name="building_needed" section="production">
<type>
<arg name="unit" type="unit"/>
<arg name="region" type="region"/>
<arg name="command" type="order"/>
<arg name="building" type="name"/>
</type>
<text locale="de">"$unit($unit) in $region($region): '$order($command)' - Die Einheit steht nicht im benötigten Gebäude, $localize($building)."</text>
<text locale="en">"$unit($unit) in $region($region): '$order($command)' - The unit must be in a $localize($building) to produce this."</text>
</message>
<message name="skill_needed" section="production"> <message name="skill_needed" section="production">
<type> <type>
<arg name="unit" type="unit"/> <arg name="unit" type="unit"/>