--- deliantra/server/common/object.C 2009/11/09 03:08:23 1.300 +++ deliantra/server/common/object.C 2010/03/28 02:53:46 1.316 @@ -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,9 +285,9 @@ || 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->materialname != ob2->materialname + || ob1->material != ob2->material || ob1->lore != ob2->lore || ob1->subtype != ob2->subtype || ob1->move_type != ob2->move_type @@ -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" @@ -602,7 +616,10 @@ // we cannot apply the weapon at the moment. for (int i = 0; i < NUM_BODY_LOCATIONS; ++i) if (slot[i].used < 0) - { + { + if (chosen_skill) + chosen_skill->flag [FLAG_APPLIED] = false; + current_weapon = chosen_skill = 0; update_stats (); @@ -610,7 +627,7 @@ "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); + "how many items you can wear on a specific body part.]", &ob->name); return false; } @@ -689,9 +706,6 @@ } } - if (speed < 0) - dst->speed_left -= rndm (); - dst->activate (); } @@ -701,7 +715,12 @@ if (!uuid.seq) // HACK uuid = UUID::gen (); - speed_left = -0.1f; + // TODO: unclean state changes, should nt be done in copy_to AND instantiate + if (flag [FLAG_RANDOM_SPEED] && speed) + speed_left = - speed - rndm (); // TODO animation + else + 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. * by doing so, when a monster is created, it has good starting @@ -719,6 +738,11 @@ { object *neu = create (); copy_to (neu); + + // TODO: unclean state changes, should not be done in clone AND instantiate + if (neu->flag [FLAG_RANDOM_SPEED] && neu->speed) + neu->speed_left = - neu->speed - rndm (); // TODO animation + neu->map = map; // not copied by copy_to return neu; } @@ -846,7 +870,8 @@ SET_FLAG (this, FLAG_REMOVED); //expmul = 1.0; declared const for the time being - face = blank_face; + face = blank_face; + material = MATERIAL_NULL; } object::~object () @@ -1127,18 +1152,13 @@ below = 0; env = 0; - /* NO_FIX_PLAYER is set when a great many changes are being - * made to players inventory. If set, avoiding the call - * to save cpu time. - */ - if (pl) - if (pl->is_player () && (glow_radius || !QUERY_FLAG (pl, FLAG_NO_FIX_PLAYER))) - { - pl->update_stats (); + if (pl && pl->is_player ()) + { + pl->contr->queue_stats_update (); - if (glow_radius && pl->is_on_map ()) - update_all_los (pl->map, pl->x, pl->y); - } + if (glow_radius && pl->is_on_map ()) + update_all_los (pl->map, pl->x, pl->y); + } } else if (map) { @@ -1268,7 +1288,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; @@ -1316,7 +1336,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 * @@ -1553,7 +1573,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; @@ -1570,7 +1590,7 @@ return where->map->insert (this, where->x, where->y, originator, flags); } -// check whether we can put this into the map, respect max_nrof, max_volume, max_items +// check whether we can put this into the map, respect max_volume, max_items bool object::can_drop_at (maptile *m, int x, int y, object *originator) { @@ -1580,8 +1600,7 @@ if (!items // testing !items ensures we can drop at least one item || (items < m->max_items - && ms.volume () < m->max_volume - && nrof <= m->max_nrof)) + && ms.volume () < m->max_volume)) return true; if (originator && originator->is_player ()) @@ -1740,9 +1759,9 @@ update_stats (); update_all_los (map, x, y); } - else if (is_player () && !flag [FLAG_NO_FIX_PLAYER]) + else if (is_player ()) // if this is a player's inventory, update stats - update_stats (); + contr->queue_stats_update (); INVOKE_OBJECT (INSERT, this); @@ -2520,15 +2539,6 @@ : region::default_region (); } -const materialtype_t * -object::dominant_material () const -{ - if (materialtype_t *mt = name_to_material (materialname)) - return mt; - - return name_to_material (shstr_unknown); -} - void object::open_container (object *new_container) { @@ -2572,7 +2582,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); } @@ -2688,3 +2698,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; +} +