--- deliantra/server/common/object.C 2009/11/29 09:41:27 1.306 +++ deliantra/server/common/object.C 2010/04/02 03:41:24 1.317 @@ -1,9 +1,9 @@ /* * This file is part of Deliantra, the Roguelike Realtime MMORPG. * - * Copyright (©) 2005,2006,2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team - * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team - * Copyright (©) 1992,2007 Frank Tore Johansen + * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team + * Copyright (©) 2001 Mark Wedel & Crossfire Development Team + * Copyright (©) 1992 Frank Tore Johansen * * Deliantra is free software: you can redistribute it and/or modify it under * the terms of the Affero GNU General Public License as published by the @@ -28,7 +28,6 @@ #include #include #include -#include #include @@ -79,7 +78,7 @@ } static void -read_uuid (void) +read_uuid () { char filename[MAX_BUF]; @@ -250,12 +249,12 @@ */ bool object::can_merge_slow (object *ob1, object *ob2) { - /* A couple quicksanity checks */ + /* A couple quick sanity checks */ if (ob1 == ob2 || ob1->type != ob2->type - || fabs (ob1->speed - ob2->speed) >= MIN_ACTIVE_SPEED || ob1->value != ob2->value - || ob1->name != ob2->name) + || ob1->name != ob2->name + || fabs (ob1->speed - ob2->speed) >= MIN_ACTIVE_SPEED) return 0; /* Do not merge objects if nrof would overflow, assume nrof @@ -286,7 +285,7 @@ || ob1->skill != ob2->skill || ob1->value != ob2->value || ob1->animation_id != ob2->animation_id - || (ob1->face != ob2->face && !ob1->animation_id) // face and animation are dependent on each other + || (ob1->face != ob2->face && !ob1->animation_id) // face and animation are dependend on each other || ob1->client_type != ob2->client_type || ob1->material != ob2->material || ob1->lore != ob2->lore @@ -523,6 +522,21 @@ } /* + * Returns the object which has the uuid equal to the argument. + * MOAR VERRRY slow. + */ + +object * +find_object_uuid (UUID i) +{ + for_all_objects (op) + if (op->uuid == i) + return op; + + return 0; +} + +/* * Returns the first object which has a name equal to the argument. * Used only by the patch command, but not all that useful. * Enables features like "patch food 999" @@ -585,45 +599,27 @@ if (current_weapon == ob) return true; - if (chosen_skill) - chosen_skill->flag [FLAG_APPLIED] = false; - - current_weapon = ob; - chosen_skill = !ob || ob->type == SKILL ? ob : find_skill_by_name (this, ob->skill); - - if (chosen_skill) - chosen_skill->flag [FLAG_APPLIED] = true; - - update_stats (); - - if (ob) + if (current_weapon && current_weapon->flag [FLAG_APPLIED]) { - // now check wether any body locations became invalid, in which case - // we cannot apply the weapon at the moment. - for (int i = 0; i < NUM_BODY_LOCATIONS; ++i) - if (slot[i].used < 0) - { - current_weapon = chosen_skill = 0; - update_stats (); + manual_apply (this, current_weapon, AP_UNAPPLY); - new_draw_info_format (NDI_UNIQUE, 0, this, - "You try to balance all your items at once, " - "but the %s is just too much for your body. " - "[You need to unapply some items first - use the 'body' command to see " - "how many items you cna wera on a specific body part.]", &ob->name); - return false; - } + if (current_weapon && !current_weapon->flag [FLAG_APPLIED])//D + LOG (llevError, "FATAL: did not clear current_weapon (%s)\n", current_weapon->debug_desc ()); - //new_draw_info_format (NDI_UNIQUE, 0, this, "You switch to your %s.", &ob->name); + if (current_weapon && current_weapon->flag [FLAG_APPLIED]) + return false; } - else - ;//new_draw_info_format (NDI_UNIQUE, 0, this, "You unwield your weapons."); - if (ob && !ob->flag [FLAG_APPLIED] && ob->type != SPELL) + current_weapon = 0; + + if (ob && !ob->flag [FLAG_APPLIED]) { - LOG (llevError | logBacktrace, "%s changed to unapplied weapon %s", - &name, ob->debug_desc ()); - return false; + manual_apply (this, ob, AP_APPLY); + + if (ob->flag [FLAG_APPLIED]) + current_weapon = ob; + else + return false; } return true; @@ -700,9 +696,9 @@ // TODO: unclean state changes, should nt be done in copy_to AND instantiate if (flag [FLAG_RANDOM_SPEED] && speed) - speed_left = -rndm (); // TODO animation + speed_left = - speed - rndm (); // TODO animation else - speed_left = -speed; + speed_left = -1.; /* copy the body_info to the body_used - this is only really * need for monsters, but doesn't hurt to do it for everything. @@ -724,7 +720,7 @@ // TODO: unclean state changes, should not be done in clone AND instantiate if (neu->flag [FLAG_RANDOM_SPEED] && neu->speed) - neu->speed_left = -rndm (); // TODO animation + neu->speed_left = - neu->speed - rndm (); // TODO animation neu->map = map; // not copied by copy_to return neu; @@ -1137,9 +1133,23 @@ if (pl && pl->is_player ()) { + if (expect_false (pl->contr->combat_ob == this)) + { + pl->apply (pl->contr->combat_ob, AP_UNAPPLY); + pl->contr->combat_ob = 0; + if (pl->contr->ranged_ob) pl->apply (pl->contr->ranged_ob); + } + + if (expect_false (pl->contr->ranged_ob == this)) + { + pl->apply (pl->contr->ranged_ob, AP_UNAPPLY); + pl->contr->ranged_ob = 0; + if (pl->contr->combat_ob) pl->apply (pl->contr->combat_ob); + } + pl->contr->queue_stats_update (); - if (glow_radius && pl->is_on_map ()) + if (expect_false (glow_radius) && pl->is_on_map ()) update_all_los (pl->map, pl->x, pl->y); } } @@ -1271,7 +1281,7 @@ for (archetype *at = (archetype *)arch->more; at; at = (archetype *)at->more) { - object *op = arch_to_object (at); + object *op = at->instance (); op->name = name; op->name_pl = name_pl; @@ -1319,7 +1329,7 @@ * * Return value: * new object if 'op' was merged with other object - * NULL if 'op' was destroyed + * NULL if there was an error (destroyed, blocked etc.) * just 'op' otherwise */ object * @@ -1556,7 +1566,7 @@ if (tmp->arch->archname == archname) /* same archetype */ tmp->destroy (); - object *tmp = arch_to_object (archetype::find (archname)); + object *tmp = archetype::find (archname)->instance (); tmp->x = op->x; tmp->y = op->y; @@ -2565,7 +2575,7 @@ // insert the "Close Container" object. if (archetype *closer = new_container->other_arch) { - object *closer = arch_to_object (new_container->other_arch); + object *closer = new_container->other_arch->instance (); closer->flag [FLAG_NO_MAP_SAVE] = 1; new_container->insert (closer); } @@ -2681,3 +2691,19 @@ } } +void object::change_move_type (MoveType mt) +{ + if (move_type == mt) + return; + + if (is_on_map ()) + { + // we are on the map, so handle move_on/off effects + remove (); + move_type = mt; + map->insert (this, x, y, this); + } + else + move_type = mt; +} +