--- deliantra/server/common/object.C 2008/10/01 16:04:16 1.261 +++ deliantra/server/common/object.C 2008/12/28 15:28:47 1.275 @@ -34,6 +34,7 @@ UUID UUID::cur; static uint64_t seq_next_save; static const uint64 UUID_GAP = 1<<19; +uint32_t mapspace::smellcount = 10000; objectvec objects; activevec actives; @@ -325,7 +326,7 @@ if (env) { // the player inventory itself is always visible - if (env->type == PLAYER) + if (env->is_player ()) return env; // else a player could have our env open @@ -760,7 +761,7 @@ // this is likely overkill, TODO: revisit (schmorp) if ((QUERY_FLAG (op, FLAG_BLOCKSVIEW) && !(m.flags_ & P_BLOCKSVIEW)) || (QUERY_FLAG (op, FLAG_NO_MAGIC) && !(m.flags_ & P_NO_MAGIC)) - || (op->type == PLAYER && !(m.flags_ & P_PLAYER)) + || (op->is_player () && !(m.flags_ & P_PLAYER)) || (op->type == SAFE_GROUND && !(m.flags_ & P_SAFE)) || (QUERY_FLAG (op, FLAG_ALIVE) && !(m.flags_ & P_IS_ALIVE)) || (QUERY_FLAG (op, FLAG_DAMNED) && !(m.flags_ & P_NO_CLERIC)) @@ -772,14 +773,14 @@ */ || ((m.move_block | op->move_block) & ~op->move_allow) != m.move_block || 1) // the above is not strong enough a test to skip updating. los maybe? TODO (Schmorp) - m.flags_ = 0; + m.invalidate (); } /* if the object is being removed, we can't make intelligent * decisions, because remove_ob can't really pass the object * that is being removed. */ else if (action == UP_OBJ_CHANGE || action == UP_OBJ_REMOVE) - m.flags_ = 0; + m.invalidate (); else if (action == UP_OBJ_FACE) /* Nothing to do for that case */ ; else @@ -1058,6 +1059,8 @@ adjust_weight (env, -total_weight ()); + object *pl = in_player (); + /* we set up values so that it could be inserted into * the map, but we don't actually do that - it is up * to the caller to decide what we want to do. @@ -1078,8 +1081,14 @@ * made to players inventory. If set, avoiding the call * to save cpu time. */ - if ((otmp = in_player ()) && otmp->contr && !QUERY_FLAG (otmp, FLAG_NO_FIX_PLAYER)) - otmp->update_stats (); + if (pl) + if (pl->is_player () && (glow_radius || !QUERY_FLAG (pl, FLAG_NO_FIX_PLAYER))) + { + pl->update_stats (); + + if (glow_radius && pl->is_on_map ()) + update_all_los (pl->map, pl->x, pl->y); + } } else if (map) { @@ -1088,8 +1097,11 @@ if (object *pl = ms.player ()) { - if (type == PLAYER) // this == pl(!) + if (is_player ()) { + if (!flag [FLAG_WIZPASS]) + ms.smell = ++mapspace::smellcount; // remember the smell of the player + // leaving a spot always closes any open container on the ground if (container && !container->env) // this causes spurious floorbox updates, but it ensures @@ -1116,7 +1128,7 @@ above = 0; below = 0; - ms.flags_ = 0; + ms.invalidate (); if (map->in_memory == MAP_SAVING) return; @@ -1159,7 +1171,7 @@ last = tmp; } - if (flag [FLAG_BLOCKSVIEW] || glow_radius) + if (affects_los ()) update_all_los (map, x, y); } } @@ -1276,7 +1288,8 @@ * of areas of callers (eg, anything that uses find_free_spot would now * need extra work */ - if (!xy_normalise (m, op->x, op->y)) + maptile *newmap = m; + if (!xy_normalise (newmap, op->x, op->y)) { op->head_ ()->destroy ();// remove head_ once all tail object destroyers found return 0; @@ -1288,7 +1301,7 @@ CLEAR_FLAG (op, FLAG_REMOVED); - op->map = m; + op->map = newmap; mapspace &ms = op->ms (); /* this has to be done after we translate the coordinates. @@ -1416,7 +1429,7 @@ } } - if (op->type == PLAYER) + if (op->is_player ()) { op->contr->do_los = 1; ++op->map->players; @@ -1441,8 +1454,11 @@ * or just updating the P_UPTODATE for spaces within this area * of effect may be sufficient. */ - if (op->map->darkness && (op->glow_radius != 0)) - update_all_los (op->map, op->x, op->y); + if (op->affects_los ()) + { + op->ms ().invalidate (); + update_all_los (op->map, op->x, op->y); + } /* updates flags (blocked, alive, no magic, etc) for this map space */ update_object (op, UP_OBJ_INSERT); @@ -1647,11 +1663,13 @@ inserted: /* reset the light list and los of the players on the map */ - if (op->glow_radius && map && map->darkness) - update_all_los (map, x, y); - - // if this is a player's inventory, update stats - if (type == PLAYER && !flag [FLAG_NO_FIX_PLAYER]) + if (op->glow_radius && is_on_map ()) + { + update_stats (); + update_all_los (map, x, y); + } + else if (is_player () && !flag [FLAG_NO_FIX_PLAYER]) + // if this is a player's inventory, update stats update_stats (); INVOKE_OBJECT (INSERT, this); @@ -1745,7 +1763,7 @@ float diff = tmp->move_slow_penalty * fabs (op->speed); - if (op->type == PLAYER) + if (op->is_player ()) if ((QUERY_FLAG (tmp, FLAG_IS_HILLY) && find_skill_by_number (op, SK_CLIMBING)) || (QUERY_FLAG (tmp, FLAG_IS_WOODED) && find_skill_by_number (op, SK_WOODSMAN))) diff /= 4.0; @@ -1963,7 +1981,7 @@ if (OB_TYPE_MOVE_BLOCK (ob, ms.move_block)) continue; - if (ob->blocked (m, pos.x, pos.y)) + if (ob->blocked (pos.m, pos.x, pos.y)) continue; altern [index++] = i; @@ -2041,13 +2059,8 @@ int find_dir (maptile *m, int x, int y, object *exclude) { - int i, max = SIZEOFFREE, mflags; - - sint16 nx, ny; - object *tmp; - maptile *mp; - - MoveType blocked, move_type; + int max = SIZEOFFREE, mflags; + MoveType move_type; if (exclude && exclude->head_ () != exclude) { @@ -2060,33 +2073,25 @@ move_type = MOVE_ALL; } - for (i = 1; i < max; i++) + for (int i = 1; i < max; i++) { - mp = m; - nx = x + freearr_x[i]; - ny = y + freearr_y[i]; + mapxy pos (m, x, y); + pos.move (i); - mflags = get_map_flags (m, &mp, nx, ny, &nx, &ny); - - if (mflags & P_OUT_OF_MAP) + if (!pos.normalise ()) max = maxfree[i]; else { - mapspace &ms = mp->at (nx, ny); + mapspace &ms = *pos; - blocked = ms.move_block; - - if ((move_type & blocked) == move_type) - max = maxfree[i]; - else if (mflags & P_IS_ALIVE) + if ((move_type & ms.move_block) == move_type) + max = maxfree [i]; + else if (ms.flags () & P_IS_ALIVE) { - for (tmp = ms.bot; tmp; tmp = tmp->above) - if ((tmp->flag [FLAG_MONSTER] || tmp->type == PLAYER) + for (object *tmp = ms.bot; tmp; tmp = tmp->above) + if ((tmp->flag [FLAG_MONSTER] || tmp->is_player ()) && (tmp != exclude || (tmp->head_ () != tmp && tmp->head_ () != exclude))) - break; - - if (tmp) - return freedir[i]; + return freedir [i]; } } } @@ -2277,7 +2282,7 @@ { return /*QUERY_FLAG(who,FLAG_WIZ)|| */ (item->weight > 0 && !QUERY_FLAG (item, FLAG_NO_PICK) && - !QUERY_FLAG (item, FLAG_ALIVE) && !item->invisible && (who->type == PLAYER || item->weight < who->weight / 3)); + !QUERY_FLAG (item, FLAG_ALIVE) && !item->invisible && (who->is_player () || item->weight < who->weight / 3)); } /* @@ -2540,7 +2545,7 @@ return 0; } -void +object * object::force_add (const shstr name, int duration) { if (object *force = force_find (name)) @@ -2556,7 +2561,7 @@ force->flag [FLAG_IS_USED_UP] = true; force->flag [FLAG_APPLIED] = true; - insert (force); + return insert (force); } void @@ -2577,3 +2582,36 @@ map->play_sound (sound, x, y); } +void +object::make_noise () +{ + // we do not model noise in the map, so instead put + // a temporary light into the noise source + // could use the map instead, but that's less reliable for our + // goal, which is to make invisibility a bit harder to exploit + + // currently only works sensibly for players + if (!is_player ()) + return; + + // find old force, or create new one + object *force = force_find (shstr_noise_force); + + if (force) + force->speed_left = -1.f; // patch old speed up + else + { + force = archetype::get (shstr_noise_force); + + force->slaying = shstr_noise_force; + force->stats.food = 1; + force->speed_left = -1.f; + + force->set_speed (1.f / 4.f); + force->flag [FLAG_IS_USED_UP] = true; + force->flag [FLAG_APPLIED] = true; + + insert (force); + } +} +