--- deliantra/server/common/object.C 2006/12/20 09:14:21 1.74 +++ deliantra/server/common/object.C 2006/12/20 11:36:38 1.75 @@ -696,7 +696,7 @@ } /* - * update_object() updates the array which represents the map. + * update_object() updates the the map. * It takes into account invisible objects (and represent squares covered * by invisible objects by whatever is below them (unless it's another * invisible object, etc...) @@ -705,10 +705,6 @@ * updating that window, though, since update_object() is called _often_) * * action is a hint of what the caller believes need to be done. - * For example, if the only thing that has changed is the face (due to - * an animation), we don't need to call update_position until that actually - * comes into view of a player. OTOH, many other things, like addition/removal - * of walls or living creatures may need us to update the flags now. * current action are: * UP_OBJ_INSERT: op was inserted * UP_OBJ_REMOVE: op was removed @@ -716,11 +712,9 @@ * as that is easier than trying to look at what may have changed. * UP_OBJ_FACE: only the objects face has changed. */ - void update_object (object *op, int action) { - int update_now = 0, flags; MoveType move_on, move_off, move_block, move_slow; if (op == NULL) @@ -730,7 +724,7 @@ return; } - if (op->env != NULL) + if (op->env) { /* Animation is currently handled by client, so nothing * to do in this case. @@ -754,64 +748,41 @@ return; } - flags = GET_MAP_FLAGS (op->map, op->x, op->y); - SET_MAP_FLAGS (op->map, op->x, op->y, flags | P_NEED_UPDATE); - move_slow = GET_MAP_MOVE_SLOW (op->map, op->x, op->y); - move_on = GET_MAP_MOVE_ON (op->map, op->x, op->y); - move_block = GET_MAP_MOVE_BLOCK (op->map, op->x, op->y); - move_off = GET_MAP_MOVE_OFF (op->map, op->x, op->y); - - if (action == UP_OBJ_INSERT) - { - if (QUERY_FLAG (op, FLAG_BLOCKSVIEW) && !(flags & P_BLOCKSVIEW)) - update_now = 1; - - if (QUERY_FLAG (op, FLAG_NO_MAGIC) && !(flags & P_NO_MAGIC)) - update_now = 1; - - if (QUERY_FLAG (op, FLAG_DAMNED) && !(flags & P_NO_CLERIC)) - update_now = 1; - - if (QUERY_FLAG (op, FLAG_ALIVE) && !(flags & P_IS_ALIVE)) - update_now = 1; - - if (op->type == SAFE_GROUND && !(flags & P_SAFE)) - update_now = 1; - - if ((move_on | op->move_on) != move_on) - update_now = 1; - - if ((move_off | op->move_off) != move_off) - update_now = 1; - - /* This isn't perfect, but I don't expect a lot of objects to - * to have move_allow right now. - */ - if (((move_block | op->move_block) & ~op->move_allow) != move_block) - update_now = 1; + mapspace &m = op->map->at (op->x, op->y); - if ((move_slow | op->move_slow) != move_slow) - update_now = 1; - } - - /* 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. - */ + if (m.flags_ & P_NEED_UPDATE) + /* nop */; + else if (action == UP_OBJ_INSERT) + { + // 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->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)) + || (m.move_on | op->move_on ) != m.move_on + || (m.move_off | op->move_off ) != m.move_off + || (m.move_slow | op->move_slow) != m.move_slow + /* This isn't perfect, but I don't expect a lot of objects to + * to have move_allow right now. + */ + || ((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_ = P_NEED_UPDATE; + } + /* 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) - update_now = 1; + m.flags_ = P_NEED_UPDATE; else if (action == UP_OBJ_FACE) /* Nothing to do for that case */ ; else LOG (llevError, "update_object called with invalid action: %d\n", action); - if (update_now) - { - SET_MAP_FLAGS (op->map, op->x, op->y, flags | P_NO_ERROR | P_NEED_UPDATE); - update_position (op->map, op->x, op->y); - } - - if (op->more != NULL) + if (op->more) update_object (op->more, action); } @@ -1072,7 +1043,7 @@ if (above) above->below = below; else - SET_MAP_TOP (map, x, y, below); /* we were top, set new top */ + map->at (x, y).top = below; /* we were top, set new top */ /* Relink the object below us, if there is one */ if (below) @@ -1094,7 +1065,7 @@ free (dump); } - SET_MAP_OB (map, x, y, above); /* goes on above it. */ + map->at (x, y).bottom = above; /* goes on above it. */ } above = 0; @@ -1147,15 +1118,7 @@ /* last == NULL of there are no objects on this space */ if (!last) - { - /* set P_NEED_UPDATE, otherwise update_position will complain. In theory, - * we could preserve the flags (GET_MAP_FLAGS), but update_position figures - * those out anyways, and if there are any flags set right now, they won't - * be correct anyways. - */ - SET_MAP_FLAGS (map, x, y, P_NEED_UPDATE); - update_position (map, x, y); - } + map->at (x, y).flags_ = P_NEED_UPDATE; else update_object (last, UP_OBJ_REMOVE); @@ -1355,7 +1318,7 @@ if (op->below) op->below->above = op; else - SET_MAP_OB (op->map, op->x, op->y, op); + op->map->at (op->x, op->y).bottom = op; /* since *below* originator, no need to update top */ originator->below = op; @@ -1411,7 +1374,7 @@ * stacking is a bit odd. */ if (!(flag & INS_ON_TOP) && - (get_map_flags (op->map, NULL, op->x, op->y, NULL, NULL) & P_BLOCKSVIEW) && (op->face && !op->face->visibility)) + (get_map_flags (op->map, 0, op->x, op->y, 0, 0) & P_BLOCKSVIEW) && (op->face && !op->face->visibility)) { for (last = top; last != floor; last = last->below) if (QUERY_FLAG (last, FLAG_BLOCKSVIEW) && (last->type != EXIT)) @@ -1444,7 +1407,7 @@ op->above->below = op; op->below = NULL; - SET_MAP_OB (op->map, op->x, op->y, op); + op->map->at (op->x, op->y).bottom = op; } else { /* get inserted into the stack above top */ @@ -1458,7 +1421,7 @@ } if (op->above == NULL) - SET_MAP_TOP (op->map, op->x, op->y, op); + op->map->at (op->x, op->y).top = op; } /* else not INS_BELOW_ORIGINATOR */ if (op->type == PLAYER) @@ -1468,9 +1431,8 @@ * it, so save a few ticks and start from there. */ if (!(flag & INS_MAP_LOAD)) - for (tmp = floor ? floor : GET_MAP_OB (op->map, op->x, op->y); tmp != NULL; tmp = tmp->above) - if (tmp->type == PLAYER) - tmp->contr->socket->floorbox_update (); + if (object *pl = op->map->at (op->x, op->y).player ()) + pl->contr->socket->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 @@ -1514,16 +1476,13 @@ } /* this function inserts an object in the map, but if it - * finds an object of its own type, it'll remove that one first. - * op is the object to insert it under: supplies x and the map. + * finds an object of its own type, it'll remove that one first. + * op is the object to insert it under: supplies x and the map. */ void replace_insert_ob_in_map (const char *arch_string, object *op) { - object * - tmp; - object * - tmp1; + object *tmp, *tmp1; /* first search for itself and remove any old instances */ @@ -2243,34 +2202,27 @@ ny = y + freearr_y[i]; mflags = get_map_flags (m, &mp, nx, ny, &nx, &ny); + if (mflags & P_OUT_OF_MAP) - { - max = maxfree[i]; - } + max = maxfree[i]; else { blocked = GET_MAP_MOVE_BLOCK (mp, nx, ny); if ((move_type & blocked) == move_type) - { - max = maxfree[i]; - } + max = maxfree[i]; else if (mflags & P_IS_ALIVE) { - for (tmp = GET_MAP_OB (mp, nx, ny); tmp != NULL; tmp = tmp->above) - { - if ((QUERY_FLAG (tmp, FLAG_MONSTER) || tmp->type == PLAYER) && (tmp != exclude || (tmp->head && tmp->head != exclude))) - { - break; - } - } + for (tmp = GET_MAP_OB (mp, nx, ny); tmp; tmp = tmp->above) + if ((QUERY_FLAG (tmp, FLAG_MONSTER) || tmp->type == PLAYER) && (tmp != exclude || (tmp->head && tmp->head != exclude))) + break; + if (tmp) - { - return freedir[i]; - } + return freedir[i]; } } } + return 0; } @@ -2282,8 +2234,7 @@ int distance (const object *ob1, const object *ob2) { - int - i; + int i; i = (ob1->x - ob2->x) * (ob1->x - ob2->x) + (ob1->y - ob2->y) * (ob1->y - ob2->y); return i; @@ -2298,8 +2249,7 @@ int find_dir_2 (int x, int y) { - int - q; + int q; if (y) q = x * 100 / y; @@ -2435,14 +2385,11 @@ * can see a direct way to get it * Modified to be map tile aware -.MSW */ - - int can_see_monsterP (maptile *m, int x, int y, int dir) { sint16 dx, dy; - int - mflags; + int mflags; if (dir < 0) return 0; /* exit condition: invalid direction */ @@ -2465,11 +2412,11 @@ /* yes, can see. */ if (dir < 9) return 1; - return can_see_monsterP (m, x, y, reduction_dir[dir][0]) | - can_see_monsterP (m, x, y, reduction_dir[dir][1]) | can_see_monsterP (m, x, y, reduction_dir[dir][2]); -} - + return can_see_monsterP (m, x, y, reduction_dir[dir][0]) + | can_see_monsterP (m, x, y, reduction_dir[dir][1]) + | can_see_monsterP (m, x, y, reduction_dir[dir][2]); +} /* * can_pick(picker, item): finds out if an object is possible to be @@ -2490,7 +2437,6 @@ !QUERY_FLAG (item, FLAG_ALIVE) && !item->invisible && (who->type == PLAYER || item->weight < who->weight / 3)); } - /* * create clone from object to another */ @@ -2519,9 +2465,7 @@ tmp->head = 0; } else - { - tmp->head = dst; - } + tmp->head = dst; tmp->more = 0;