--- deliantra/server/common/object.C 2007/05/14 19:56:45 1.149 +++ deliantra/server/common/object.C 2007/08/12 13:10:00 1.177 @@ -1,25 +1,24 @@ /* - * CrossFire, A Multiplayer game + * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. * - * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team - * Copyright (C) 2001 Mark Wedel & Crossfire Development Team - * Copyright (C) 1992 Frank Tore Johansen + * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team + * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team + * Copyright (©) 1992,2007 Frank Tore Johansen * - * This program is free software; you can redistribute it and/or modify + * Crossfire TRT is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * The authors can be reached via e-mail at + * along with this program. If not, see . + * + * The authors can be reached via e-mail to */ /* Eneq(@csd.uu.se): Added weight-modifiers in environment of objects. @@ -302,14 +301,14 @@ return 0; } - //TODO: generate an event or call into perl for additional checks if (ob1->self || ob2->self) { ob1->optimise (); ob2->optimise (); if (ob1->self || ob2->self) - return 0; + if (!cfperl_can_merge (ob1, ob2)) + return 0; } /* Everything passes, must be OK. */ @@ -475,9 +474,15 @@ 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) @@ -491,8 +496,9 @@ update_stats (); new_draw_info_format (NDI_UNIQUE, 0, this, - "You try to balance your applied items all at once, but the %s is too much. " - "You need to unapply some items first.", &ob->name); + "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.]", &ob->name); return false; } @@ -501,6 +507,13 @@ else ;//new_draw_info_format (NDI_UNIQUE, 0, this, "You unwield your weapons."); + if (ob && !ob->flag [FLAG_APPLIED] && ob->type != SPELL) + { + LOG (llevError | logBacktrace, "%s changed to unapplied weapon %s", + &name, ob->debug_desc ()); + return false; + } + return true; } @@ -925,18 +938,19 @@ y = 1; } - head = 0; - if (more) { more->destroy (); more = 0; } - // clear those pointers that likely might have circular references to us - owner = 0; - enemy = 0; - attacked_by = 0; + head = 0; + + // clear those pointers that likely might cause circular references + owner = 0; + enemy = 0; + attacked_by = 0; + current_weapon = 0; } void @@ -948,6 +962,12 @@ if (destroy_inventory) destroy_inv (false); + if (is_head ()) + if (sound_destroy) + play_sound (sound_destroy); + else if (flag [FLAG_MONSTER]) + play_sound (sound_find ("monster_destroy")); // quick hack, too lazy to create a generic mechanism + attachable::destroy (); } @@ -1071,28 +1091,24 @@ int check_walk_off = !flag [FLAG_NO_APPLY]; + if (object *pl = ms.player ()) + { + if (pl->container == this) + /* If a container that the player is currently using somehow gets + * removed (most likely destroyed), update the player view + * appropriately. + */ + pl->close_container (); + + pl->contr->ns->floorbox_update (); + } + for (tmp = ms.bot; tmp; tmp = tmp->above) { /* No point updating the players look faces if he is the object * being removed. */ - if (tmp->type == PLAYER && tmp != this) - { - /* If a container that the player is currently using somehow gets - * removed (most likely destroyed), update the player view - * appropriately. - */ - if (tmp->container == this) - { - flag [FLAG_APPLIED] = 0; - tmp->container = 0; - } - - if (tmp->contr->ns) - tmp->contr->ns->floorbox_update (); - } - /* See if object moving off should effect something */ if (check_walk_off && ((move_type & tmp->move_off) @@ -1104,11 +1120,6 @@ LOG (llevError, "BUG: remove_ob(): name %s, destroyed leaving object\n", tmp->debug_desc ()); } - /* Eneq(@csd.uu.se): Fixed this to skip tmp->above=tmp */ - //TODO: why is this horrible hacka fix? get rid of this code=bug! (schmorp) - if (tmp->above == tmp) - tmp->above = 0; - last = tmp; } @@ -1169,7 +1180,7 @@ object *prev = this; - for (archetype *at = arch->more; at; at = at->more) + for (archetype *at = (archetype *)arch->more; at; at = (archetype *)at->more) { object *op = arch_to_object (at); @@ -1193,8 +1204,8 @@ { for (object *tmp = op->head_ (); tmp; tmp = tmp->more) { - tmp->x = x + tmp->arch->clone.x; - tmp->y = y + tmp->arch->clone.y; + tmp->x = x + tmp->arch->x; + tmp->y = y + tmp->arch->y; } return insert_ob_in_map (op, m, originator, flag); @@ -1225,7 +1236,7 @@ { assert (!op->flag [FLAG_FREED]); - object *tmp, *top, *floor = NULL; + object *top, *floor = NULL; op->remove (); @@ -1251,15 +1262,8 @@ } if (object *more = op->more) - { - if (!insert_ob_in_map (more, m, originator, flag)) - { - if (!op->head) - LOG (llevError, "BUG: insert_ob_in_map(): inserting op->more killed op\n"); - - return 0; - } - } + if (!insert_ob_in_map (more, m, originator, flag)) + return 0; CLEAR_FLAG (op, FLAG_REMOVED); @@ -1276,7 +1280,7 @@ /* this has to be done after we translate the coordinates. */ if (op->nrof && !(flag & INS_NO_MERGE)) - for (tmp = ms.bot; tmp; tmp = tmp->above) + for (object *tmp = ms.bot; tmp; tmp = tmp->above) if (object::can_merge (op, tmp)) { op->nrof += tmp->nrof; @@ -1375,7 +1379,6 @@ top = last->below; } } /* If objects on this space */ - if (flag & INS_MAP_LOAD) top = ms.top; @@ -1425,8 +1428,7 @@ */ if (!(flag & INS_MAP_LOAD)) if (object *pl = ms.player ()) - if (pl->contr->ns) - pl->contr->ns->floorbox_update (); + pl->contr->ns->floorbox_update (); /* If this object glows, it may affect lighting conditions that are * visible to others on this map. But update_all_los is really @@ -1455,7 +1457,7 @@ */ /* if this is not the head or flag has been passed, don't check walk on status */ - if (!(flag & INS_NO_WALK_ON) && !op->head) + if (!(flag & INS_NO_WALK_ON) && op->head_ () == op) { if (check_move_on (op, originator)) return 0; @@ -1463,7 +1465,7 @@ /* If we are a multi part object, lets work our way through the check * walk on's. */ - for (tmp = op->more; tmp != NULL; tmp = tmp->more) + for (object *tmp = op->more; tmp; tmp = tmp->more) if (check_move_on (tmp, originator)) return 0; } @@ -1483,7 +1485,7 @@ /* first search for itself and remove any old instances */ for (tmp = op->ms ().bot; tmp; tmp = tmp->above) - if (!strcmp (tmp->arch->name, arch_string)) /* same archetype */ + if (!strcmp (tmp->arch->archname, arch_string)) /* same archetype */ tmp->destroy (); tmp1 = arch_to_object (archetype::find (arch_string)); @@ -1654,9 +1656,9 @@ return op; } - if (where->head) + if (where->head_ () != where) { - LOG (llevDebug, "Warning: Tried to insert object into wrong part of multipart object.\n"); + LOG (llevError | logBacktrace, "Warning: Tried to insert object into wrong part of multipart object.\n"); where = where->head; } @@ -1997,19 +1999,6 @@ } /* - * set_cheat(object) sets the cheat flag (WAS_WIZ) in the object and in - * all it's inventory (recursively). - * If checksums are used, a player will get set_cheat called for - * him/her-self and all object carried by a call to this function. - */ -void -set_cheat (object *op) -{ - SET_FLAG (op, FLAG_WAS_WIZ); - flag_inv (op, FLAG_WAS_WIZ); -} - -/* * find_free_spot(object, map, x, y, start, stop) will search for * a spot at the given map and coordinates which will be able to contain * the given object. start and stop specifies how many squares @@ -2134,7 +2123,7 @@ MoveType blocked, move_type; - if (exclude && exclude->head) + if (exclude && exclude->head_ () != exclude) { exclude = exclude->head; move_type = exclude->move_type; @@ -2167,7 +2156,7 @@ { for (tmp = ms.bot; tmp; tmp = tmp->above) if ((tmp->flag [FLAG_MONSTER] || tmp->type == PLAYER) - && (tmp != exclude || (tmp->head && tmp->head != exclude))) + && (tmp != exclude || (tmp->head_ () != tmp && tmp->head_ () != exclude))) break; if (tmp) @@ -2357,7 +2346,6 @@ * * Add a check so we can't pick up invisible objects (0.93.8) */ - int can_pick (const object *who, const object *item) { @@ -2372,17 +2360,15 @@ object * object_create_clone (object *asrc) { - object *dst = 0, *tmp, *src, *part, *prev, *item; + object *dst = 0, *tmp, *src, *prev, *item; if (!asrc) return 0; - src = asrc; - if (src->head) - src = src->head; + src = asrc->head_ (); prev = 0; - for (part = src; part; part = part->more) + for (object *part = src; part; part = part->more) { tmp = part->clone (); tmp->x -= src->x; @@ -2505,7 +2491,7 @@ * it, we save the empty value so that when we load, * we get this value back again. */ - if (get_ob_key_link (&op->arch->clone, canonical_key)) + if (get_ob_key_link (op->arch, canonical_key)) field->value = 0; else { @@ -2584,7 +2570,6 @@ item = item->env; } - const char * object::flag_desc (char *desc, int len) const { @@ -2656,13 +2641,10 @@ const materialtype_t * object::dominant_material () const { - if (materialtype_t *mat = name_to_material (materialname)) - return mat; - - // omfg this is slow, this has to be temporary :) - shstr unknown ("unknown"); + if (materialtype_t *mt = name_to_material (materialname)) + return mt; - return name_to_material (unknown); + return name_to_material (shstr_unknown); } void @@ -2688,6 +2670,7 @@ esrv_update_item (UPD_FLAGS, this, old_container); new_draw_info_format (NDI_UNIQUE, 0, this, "You close %s.", query_name (old_container)); + play_sound (sound_find ("chest_close")); } if (new_container) @@ -2713,7 +2696,39 @@ esrv_update_item (UPD_FLAGS, this, new_container); esrv_send_inventory (this, new_container); + play_sound (sound_find ("chest_open")); } } +object * +object::force_find (const shstr name) +{ + /* cycle through his inventory to look for the MARK we want to + * place + */ + for (object *tmp = inv; tmp; tmp = tmp->below) + if (tmp->type == FORCE && tmp->slaying == name) + return splay (tmp); + + return 0; +} + +void +object::force_add (const shstr name, int duration) +{ + if (object *force = force_find (name)) + force->destroy (); + + object *force = get_archetype (FORCE_NAME); + + force->slaying = name; + force->stats.food = 1; + force->speed_left = -1.f; + + force->set_speed (duration ? 1.f / duration : 0.f); + force->flag [FLAG_IS_USED_UP] = true; + force->flag [FLAG_APPLIED] = true; + + insert (force); +}