--- deliantra/server/common/map.C 2007/03/17 21:13:21 1.97 +++ deliantra/server/common/map.C 2007/05/17 21:32:08 1.102 @@ -1,5 +1,5 @@ /* - * CrossFire, A Multiplayer game for X-windows + * CrossFire, A Multiplayer game * * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team * Copyright (C) 2001-2003 Mark Wedel & Crossfire Development Team @@ -176,8 +176,7 @@ if (!(mflags & P_IS_ALIVE) && !OB_TYPE_MOVE_BLOCK (ob, blocked)) return 0; - if (ob->head != NULL) - ob = ob->head; + ob = ob->head_ (); /* We basically go through the stack of objects, and if there is * some other object that has NO_PASS or FLAG_ALIVE set, return @@ -217,13 +216,18 @@ /* Broke apart a big nasty if into several here to make * this more readable. first check - if the space blocks * movement, can't move here. - * second - if a monster, can't move there, unles it is a + * second - if a monster, can't move there, unless it is a * hidden dm */ if (OB_MOVE_BLOCK (ob, tmp)) return 1; - if (QUERY_FLAG (tmp, FLAG_ALIVE) && tmp->head != ob && tmp != ob && - tmp->type != DOOR && !(QUERY_FLAG (tmp, FLAG_WIZ) && tmp->contr->hidden)) + + if (QUERY_FLAG (tmp, FLAG_ALIVE) + && tmp->head_ () != ob + && tmp != ob + && tmp->type != DOOR + && !tmp->flag [FLAG_WIZ] + && tmp->contr->hidden) return 1; } @@ -346,8 +350,7 @@ /* link_multipart_objects go through all the objects on the map looking * for objects whose arch says they are multipart yet according to the * info we have, they only have the head (as would be expected when - * they are saved). We do have to look for the old maps that did save - * the more sections and not re-add sections for them. + * they are saved). */ void maptile::link_multipart_objects () @@ -356,38 +359,14 @@ return; for (mapspace *ms = spaces + size (); ms-- > spaces; ) - for (object *tmp = ms->bot; tmp; tmp = tmp->above) + for (object *op = ms->bot; op; op = op->above) { /* already multipart - don't do anything more */ - if (!tmp->head && !tmp->more) + if (op->head_ () == op && !op->more && op->arch->more) { - /* If there is nothing more to this object, this for loop - * won't do anything. - */ - archetype *at; - object *last, *op; - for (at = tmp->arch->more, last = tmp; - at; - at = at->more, last = op) - { - op = arch_to_object (at); - - /* update x,y coordinates */ - op->x += tmp->x; - op->y += tmp->y; - op->head = tmp; - op->map = this; - last->more = op; - op->name = tmp->name; - op->title = tmp->title; - - /* we could link all the parts onto tmp, and then just - * call insert_ob_in_map once, but the effect is the same, - * as insert_ob_in_map will call itself with each part, and - * the coding is simpler to just to it here with each part. - */ - insert_ob_in_map (op, op->map, tmp, INS_NO_MERGE | INS_ABOVE_FLOOR_ONLY | INS_NO_WALK_ON); - } + op->remove (); + op->expand_tail (); + insert (op, op->x, op->y, 0, INS_NO_MERGE | INS_ABOVE_FLOOR_ONLY | INS_NO_WALK_ON); } } } @@ -401,7 +380,7 @@ { for (;;) { - coroapi::cede_every (1000); // cede once in a while + coroapi::cede_to_tick_every (100); // cede once in a while switch (f.kw) { @@ -434,29 +413,29 @@ void maptile::activate () { - if (!spaces) - return; + active = true; - for (mapspace *ms = spaces + size (); ms-- > spaces; ) - for (object *op = ms->bot; op; op = op->above) - op->activate_recursive (); + if (spaces) + for (mapspace *ms = spaces + size (); ms-- > spaces; ) + for (object *op = ms->bot; op; op = op->above) + op->activate_recursive (); } void maptile::deactivate () { - if (!spaces) - return; + active = false; - for (mapspace *ms = spaces + size (); ms-- > spaces; ) - for (object *op = ms->bot; op; op = op->above) - op->deactivate_recursive (); + if (spaces) + for (mapspace *ms = spaces + size (); ms-- > spaces; ) + for (object *op = ms->bot; op; op = op->above) + op->deactivate_recursive (); } bool maptile::_save_objects (object_freezer &f, int flags) { - coroapi::cede (); + coroapi::cede_to_tick (); if (flags & IO_HEADER) _save_header (f); @@ -466,22 +445,9 @@ for (int i = 0; i < size (); ++i) { -#if 0 // disabled, there still seem to be races somewhere - static int cede_count = 0; - - if (cede_count >= 500) - { - cede_count = 0; - coroapi::cede (); - } -#endif - int unique = 0; for (object *op = spaces [i].bot; op; op = op->above) { - // count per-object, but cede only when modification-safe - cede_count++; - if (op->flag [FLAG_UNIQUE] && op->flag [FLAG_IS_FLOOR]) unique = 1; @@ -498,7 +464,7 @@ } } - coroapi::cede (); + coroapi::cede_to_tick (); return true; } @@ -813,7 +779,7 @@ if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) unique = 1; - if (op->head == NULL && (QUERY_FLAG (op, FLAG_UNIQUE) || unique)) + if (op->head_ () == op && (QUERY_FLAG (op, FLAG_UNIQUE) || unique)) { op->destroy_inv (false); op->destroy (); @@ -906,11 +872,8 @@ if (spaces) { for (mapspace *ms = spaces + size (); ms-- > spaces; ) - while (object *op = ms->bot) + while (object *op = ms->bot->head_ ()) { - if (op->head) - op = op->head; - op->destroy_inv (false); op->destroy (); }