forked from github/server
lua properties for get/set familiar.
This commit is contained in:
parent
7db317b2e0
commit
da12fb8586
5 changed files with 64 additions and 36 deletions
|
@ -2086,6 +2086,13 @@ typedef struct familiar_data {
|
|||
unit * familiar;
|
||||
} famililar_data;
|
||||
|
||||
boolean
|
||||
is_familiar(const unit *u)
|
||||
{
|
||||
attrib * a = a_find(u->attribs, &at_familiarmage);
|
||||
return i2b(a!=NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
write_unit(const attrib * a, FILE * F)
|
||||
{
|
||||
|
@ -2162,41 +2169,47 @@ remove_familiar(unit *mage)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
boolean
|
||||
create_newfamiliar(unit * mage, unit * familiar)
|
||||
{
|
||||
/* if the skill modifier for the mage does not yet exist, add it */
|
||||
attrib * 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;
|
||||
}
|
||||
attrib *a;
|
||||
attrib *afam = a_find(mage->attribs, &at_familiar);
|
||||
attrib *amage = a_find(familiar->attribs, &at_familiarmage);
|
||||
|
||||
a = a_find(mage->attribs, &at_familiar);
|
||||
if (a==NULL) {
|
||||
a = a_add(&mage->attribs, a_new(&at_familiar));
|
||||
a->data.v = familiar;
|
||||
} else assert(!a->data.v || a->data.v == familiar);
|
||||
/* TODO: Diese Attribute beim Tod des Familiars entfernen: */
|
||||
if ((afam==NULL || afam->data.v==NULL) && (amage==NULL || amage->data.v==NULL)) {
|
||||
afam = a_add(&mage->attribs, a_new(&at_familiar));
|
||||
afam->data.v = familiar;
|
||||
|
||||
a = a_find(familiar->attribs, &at_familiarmage);
|
||||
if (a==NULL) {
|
||||
a = a_add(&familiar->attribs, a_new(&at_familiarmage));
|
||||
a->data.v = mage;
|
||||
} else assert(!a->data.v || a->data.v == mage);
|
||||
amage = a_add(&familiar->attribs, a_new(&at_familiarmage));
|
||||
amage->data.v = mage;
|
||||
} else {
|
||||
assert(afam->data.v == familiar);
|
||||
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 */
|
||||
add_trigger(&mage->attribs, "destroy", trigger_killunit(familiar));
|
||||
/* Wenn der Vertraute stirbt, dann bekommt der Magier einen Schock */
|
||||
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 *
|
||||
|
|
|
@ -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_familiarmage;
|
||||
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 struct unit * has_clone(struct unit * mage);
|
||||
|
||||
|
|
|
@ -504,13 +504,6 @@ select_familiar(const race * magerace, magic_t magiegebiet)
|
|||
/* ------------------------------------------------------------- */
|
||||
/* der Vertraue des Magiers */
|
||||
|
||||
boolean
|
||||
is_familiar(const unit *u)
|
||||
{
|
||||
attrib * a = a_find(u->attribs, &at_familiarmage);
|
||||
return i2b(a!=NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
make_familiar(unit *familiar, unit *mage)
|
||||
{
|
||||
|
|
|
@ -227,10 +227,30 @@ unit_addspell(unit& u, const char * name)
|
|||
if (!add) log_error(("spell %s could not be found\n", name));
|
||||
}
|
||||
|
||||
static bool
|
||||
static unit *
|
||||
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
|
||||
|
@ -536,6 +556,9 @@ bind_unit(lua_State * L)
|
|||
.property("weight", &unit_weight)
|
||||
.property("capacity", &unit_capacity)
|
||||
|
||||
.property("is_familiar", &unit_isfamiliar)
|
||||
.property("familiar", &unit_getfamiliar, &unit_setfamiliar)
|
||||
|
||||
// orders:
|
||||
.def("add_order", &unit_addorder)
|
||||
.def("clear_orders", &unit_clearorders)
|
||||
|
@ -572,7 +595,6 @@ bind_unit(lua_State * L)
|
|||
.property("building", &unit_getbuilding, &unit_setbuilding)
|
||||
.property("ship", &unit_getship, &unit_setship)
|
||||
.property("region", &unit_getregion, &unit_setregion)
|
||||
.property("is_familiar", &unit_isfamiliar)
|
||||
.property("spells", &unit_spells, return_stl_iterator)
|
||||
.property("number", &unit_getnumber, &unit_setnumber)
|
||||
.property("race", &unit_getrace, &unit_setrace)
|
||||
|
|
|
@ -954,7 +954,7 @@
|
|||
<arg name="target" type="region"/>
|
||||
</type>
|
||||
<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 name="magiccreate_effect" section="magic">
|
||||
<type>
|
||||
|
|
Loading…
Reference in a new issue