crashbug dying clone-mages

This commit is contained in:
Enno Rehling 2006-05-21 10:35:08 +00:00
parent 4ea7779932
commit d57e05fcd7
3 changed files with 95 additions and 92 deletions

View File

@ -181,97 +181,98 @@ distribute_items(unit * u)
void void
destroy_unit(unit * u) destroy_unit(unit * u)
{ {
region *r = u->region; region *r = u->region;
boolean zombie = false; boolean zombie = false;
unit *clone; unit *clone;
if (!ufindhash(u->no)) return; if (!ufindhash(u->no)) return;
if (!fval(u->race, RCF_ILLUSIONARY)) { if (!fval(u->race, RCF_ILLUSIONARY)) {
item ** p_item = &u->items; item ** p_item = &u->items;
unit * u3; unit * u3;
/* u->faction->no_units--; */ /* happens in u_setfaction now */ /* u->faction->no_units--; */ /* happens in u_setfaction now */
if (r) for (u3 = r->units; u3; u3 = u3->next) { if (r) for (u3 = r->units; u3; u3 = u3->next) {
if (u3 != u && u3->faction == u->faction && playerrace(u3->race)) { if (u3 != u && u3->faction == u->faction && playerrace(u3->race)) {
i_merge(&u3->items, &u->items); i_merge(&u3->items, &u->items);
u->items = NULL; u->items = NULL;
break; break;
} }
} }
u3 = NULL; u3 = NULL;
while (*p_item) { while (*p_item) {
item * item = *p_item; item * item = *p_item;
if (item->number && item->type->flags & ITF_NOTLOST) { if (item->number && item->type->flags & ITF_NOTLOST) {
if (u3==NULL) { if (u3==NULL) {
u3 = r->units; u3 = r->units;
while (u3 && u3!=u) u3 = u3->next; while (u3 && u3!=u) u3 = u3->next;
if (!u3) { if (!u3) {
zombie = true; zombie = true;
break; break;
} }
} }
if (u3) { if (u3) {
i_add(&u3->items, i_remove(p_item, item)); i_add(&u3->items, i_remove(p_item, item));
} }
} }
if (*p_item == item) p_item=&item->next; if (*p_item == item) p_item=&item->next;
} }
if (u->items && strlen(u->faction->passw)>0) { if (u->items && strlen(u->faction->passw)>0) {
distribute_items(u); distribute_items(u);
} }
} }
/* Wir machen das erst nach dem Löschen der Items. Der Klon darf keine /* Wir machen das erst nach dem Löschen der Items. Der Klon darf keine
* Items haben, sonst Memory-Leak. */ * Items haben, sonst Memory-Leak. */
clone = has_clone(u); clone = has_clone(u);
if (clone && rng_int()%100 < 90) { if (clone && rng_int()%100 < 90) {
attrib *a; attrib *a;
int i; int i;
/* TODO: Messages generieren. */ /* TODO: Messages generieren. */
u->region = clone->region; u->region = clone->region;
u->ship = clone->ship; u->ship = clone->ship;
u->building = clone->building; u->building = clone->building;
u->hp = 1; u->hp = 1;
i = u->no; i = u->no;
uunhash(u); uunhash(u);
uunhash(clone); uunhash(clone);
u->no = clone->no; u->no = clone->no;
clone->no = i; clone->no = i;
uhash(u); uhash(u);
uhash(clone); uhash(clone);
set_number(u, 1); set_number(u, 1);
set_spellpoints(u, 0); set_spellpoints(u, 0);
a = a_find(u->attribs, &at_clone); a = a_find(u->attribs, &at_clone);
a_remove(&u->attribs, a); if (a!=NULL) a_remove(&u->attribs, a);
a = a_find(clone->attribs, &at_clonemage); a = a_find(clone->attribs, &at_clonemage);
a_remove(&clone->attribs, a); if (a!=NULL) a_remove(&clone->attribs, a);
fset(u, UFL_LONGACTION); fset(u, UFL_LONGACTION);
set_number(clone, 0); set_number(clone, 0);
u = clone; u = clone;
zombie = false; zombie = false;
} }
if (zombie) { if (zombie) {
u_setfaction(u, findfaction(MONSTER_FACTION)); u_setfaction(u, findfaction(MONSTER_FACTION));
scale_number(u, 1); scale_number(u, 1);
u->race = u->irace = new_race[RC_ZOMBIE]; u->race = u->irace = new_race[RC_ZOMBIE];
} else { } else {
if (u->number) set_number(u, 0); if (u->number) set_number(u, 0);
handle_event(&u->attribs, "destroy", u); handle_event(&u->attribs, "destroy", u);
if (r && !fval(r->terrain, SEA_REGION)) if (r && !fval(r->terrain, SEA_REGION)) {
rsetmoney(r, rmoney(r) + get_money(u)); rsetmoney(r, rmoney(r) + get_money(u));
dhash(u->no, u->faction); }
u_setfaction(u, NULL); dhash(u->no, u->faction);
if (r) leave(r, u); u_setfaction(u, NULL);
uunhash(u); if (r) leave(r, u);
if (r) choplist(&r->units, u); uunhash(u);
u->next = udestroy; if (r) choplist(&r->units, u);
udestroy = u; u->next = udestroy;
} udestroy = u;
}
} }
unit * unit *

View File

@ -156,6 +156,7 @@ a_unlink(attrib ** pa, attrib * a)
attrib ** pnexttype = pa; attrib ** pnexttype = pa;
attrib ** pnext = NULL; attrib ** pnext = NULL;
assert(a!=NULL);
while (*pnexttype) { while (*pnexttype) {
attrib * next = *pnexttype; attrib * next = *pnexttype;
if (next->type==a->type) break; if (next->type==a->type) break;
@ -187,10 +188,11 @@ a_unlink(attrib ** pa, attrib * a)
int int
a_remove(attrib ** pa, attrib * a) a_remove(attrib ** pa, attrib * a)
{ {
int ok; int ok;
ok = a_unlink(pa, a); assert(a!=NULL);
if (ok) a_free(a); ok = a_unlink(pa, a);
return ok; if (ok) a_free(a);
return ok;
} }
void void

View File

@ -776,7 +776,7 @@
<arg name="ship" type="ship"/> <arg name="ship" type="ship"/>
<arg name="dir" type="direction"/> <arg name="dir" type="direction"/>
</type> </type>
<text locale="de">"Die $region($ship) treibt nach $direction($dir)."</text> <text locale="de">"Die $ship($ship) treibt nach $direction($dir)."</text>
<text locale="fr">"The ship $ship($ship) drifts to the $direction($dir)."</text> <text locale="fr">"The ship $ship($ship) drifts to the $direction($dir)."</text>
<text locale="en">"The ship $ship($ship) drifts to the $direction($dir)."</text> <text locale="en">"The ship $ship($ship) drifts to the $direction($dir)."</text>
</message> </message>