lua properties for get/set familiar.

This commit is contained in:
Enno Rehling 2006-04-22 11:32:28 +00:00
parent 7db317b2e0
commit da12fb8586
5 changed files with 64 additions and 36 deletions

View file

@ -2086,6 +2086,13 @@ typedef struct familiar_data {
unit * familiar; unit * familiar;
} famililar_data; } famililar_data;
boolean
is_familiar(const unit *u)
{
attrib * a = a_find(u->attribs, &at_familiarmage);
return i2b(a!=NULL);
}
static void static void
write_unit(const attrib * a, FILE * F) write_unit(const attrib * a, FILE * F)
{ {
@ -2162,41 +2169,47 @@ remove_familiar(unit *mage)
} }
} }
void boolean
create_newfamiliar(unit * mage, unit * familiar) create_newfamiliar(unit * mage, unit * familiar)
{ {
/* if the skill modifier for the mage does not yet exist, add it */ /* if the skill modifier for the mage does not yet exist, add it */
attrib * a = a_find(mage->attribs, &at_skillmod); attrib *a;
while (a && a->type==&at_skillmod) { attrib *afam = a_find(mage->attribs, &at_familiar);
skillmod_data * smd = (skillmod_data *)a->data.v; attrib *amage = a_find(familiar->attribs, &at_familiarmage);
if (smd->special==sm_familiar) break;
a = a->next;
}
if (a==NULL) {
attrib * an = a_add(&mage->attribs, a_new(&at_skillmod));
skillmod_data * smd = (skillmod_data *)an->data.v;
smd->special = sm_familiar;
smd->skill=NOSKILL;
}
a = a_find(mage->attribs, &at_familiar); if ((afam==NULL || afam->data.v==NULL) && (amage==NULL || amage->data.v==NULL)) {
if (a==NULL) { afam = a_add(&mage->attribs, a_new(&at_familiar));
a = a_add(&mage->attribs, a_new(&at_familiar)); afam->data.v = familiar;
a->data.v = familiar;
} else assert(!a->data.v || a->data.v == familiar);
/* TODO: Diese Attribute beim Tod des Familiars entfernen: */
a = a_find(familiar->attribs, &at_familiarmage); amage = a_add(&familiar->attribs, a_new(&at_familiarmage));
if (a==NULL) { amage->data.v = mage;
a = a_add(&familiar->attribs, a_new(&at_familiarmage)); } else {
a->data.v = mage; assert(afam->data.v == familiar);
} else assert(!a->data.v || a->data.v == mage); assert(amage->data.v == mage);
if (afam->data.v != familiar || amage->data.v != mage) {
return false;
}
}
/* TODO: Diese Attribute beim Tod des Familiars entfernen: */
/* Wenn der Magier stirbt, dann auch der Vertraute */ /* Wenn der Magier stirbt, dann auch der Vertraute */
add_trigger(&mage->attribs, "destroy", trigger_killunit(familiar)); add_trigger(&mage->attribs, "destroy", trigger_killunit(familiar));
/* Wenn der Vertraute stirbt, dann bekommt der Magier einen Schock */ /* Wenn der Vertraute stirbt, dann bekommt der Magier einen Schock */
add_trigger(&familiar->attribs, "destroy", trigger_shock(mage)); add_trigger(&familiar->attribs, "destroy", trigger_shock(mage));
a = a_find(mage->attribs, &at_skillmod);
while (a && a->type==&at_skillmod) {
skillmod_data * smd = (skillmod_data *)a->data.v;
if (smd->special==sm_familiar) break;
a = a->next;
}
if (a==NULL) {
attrib * an = a_add(&mage->attribs, a_new(&at_skillmod));
skillmod_data * smd = (skillmod_data *)an->data.v;
smd->special = sm_familiar;
smd->skill=NOSKILL;
}
return true;
} }
static void * static void *

View file

@ -365,7 +365,7 @@ extern struct unit * get_clone_mage(const struct unit *u);
extern struct attrib_type at_familiar; extern struct attrib_type at_familiar;
extern struct attrib_type at_familiarmage; extern struct attrib_type at_familiarmage;
extern void remove_familiar(struct unit * mage); extern void remove_familiar(struct unit * mage);
extern void create_newfamiliar(struct unit * mage, struct unit * familiar); extern boolean create_newfamiliar(struct unit * mage, struct unit * familiar);
extern void create_newclone(struct unit * mage, struct unit * familiar); extern void create_newclone(struct unit * mage, struct unit * familiar);
extern struct unit * has_clone(struct unit * mage); extern struct unit * has_clone(struct unit * mage);

View file

@ -504,13 +504,6 @@ select_familiar(const race * magerace, magic_t magiegebiet)
/* ------------------------------------------------------------- */ /* ------------------------------------------------------------- */
/* der Vertraue des Magiers */ /* der Vertraue des Magiers */
boolean
is_familiar(const unit *u)
{
attrib * a = a_find(u->attribs, &at_familiarmage);
return i2b(a!=NULL);
}
static void static void
make_familiar(unit *familiar, unit *mage) make_familiar(unit *familiar, unit *mage)
{ {

View file

@ -227,10 +227,30 @@ unit_addspell(unit& u, const char * name)
if (!add) log_error(("spell %s could not be found\n", name)); if (!add) log_error(("spell %s could not be found\n", name));
} }
static bool static unit *
unit_isfamiliar(const unit& u) unit_isfamiliar(const unit& u)
{ {
return is_familiar(&u)!=0; attrib * a = a_find(u.attribs, &at_familiarmage);
if (a!=NULL) {
return (unit*)a->data.v;
}
return NULL;
}
static unit *
unit_getfamiliar(const unit& u)
{
attrib * a = a_find(u.attribs, &at_familiar);
if (a!=NULL) {
return (unit*)a->data.v;
}
return NULL;
}
static void
unit_setfamiliar(unit& mage, unit& familiar)
{
create_newfamiliar(&mage, &familiar);
} }
static void static void
@ -536,6 +556,9 @@ bind_unit(lua_State * L)
.property("weight", &unit_weight) .property("weight", &unit_weight)
.property("capacity", &unit_capacity) .property("capacity", &unit_capacity)
.property("is_familiar", &unit_isfamiliar)
.property("familiar", &unit_getfamiliar, &unit_setfamiliar)
// orders: // orders:
.def("add_order", &unit_addorder) .def("add_order", &unit_addorder)
.def("clear_orders", &unit_clearorders) .def("clear_orders", &unit_clearorders)
@ -572,7 +595,6 @@ bind_unit(lua_State * L)
.property("building", &unit_getbuilding, &unit_setbuilding) .property("building", &unit_getbuilding, &unit_setbuilding)
.property("ship", &unit_getship, &unit_setship) .property("ship", &unit_getship, &unit_setship)
.property("region", &unit_getregion, &unit_setregion) .property("region", &unit_getregion, &unit_setregion)
.property("is_familiar", &unit_isfamiliar)
.property("spells", &unit_spells, return_stl_iterator) .property("spells", &unit_spells, return_stl_iterator)
.property("number", &unit_getnumber, &unit_setnumber) .property("number", &unit_getnumber, &unit_setnumber)
.property("race", &unit_getrace, &unit_setrace) .property("race", &unit_getrace, &unit_setrace)

View file

@ -954,7 +954,7 @@
<arg name="target" type="region"/> <arg name="target" type="region"/>
</type> </type>
<text locale="de">"$unit($unit) in $region($region): '$order($command)' - $unit($unit) ruft Drachen nach $region($target)."</text> <text locale="de">"$unit($unit) in $region($region): '$order($command)' - $unit($unit) ruft Drachen nach $region($target)."</text>
<text locale="en">"$unit($unit) in $region($region): '$order($command)' - $unit($unit) calls dragons to $region($rtarget)."</text> <text locale="en">"$unit($unit) in $region($region): '$order($command)' - $unit($unit) calls dragons to $region($target)."</text>
</message> </message>
<message name="magiccreate_effect" section="magic"> <message name="magiccreate_effect" section="magic">
<type> <type>