ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/object.C
(Generate patch)

Comparing deliantra/server/common/object.C (file contents):
Revision 1.74 by root, Wed Dec 20 09:14:21 2006 UTC vs.
Revision 1.75 by root, Wed Dec 20 11:36:38 2006 UTC

694 op->active_next = NULL; 694 op->active_next = NULL;
695 op->active_prev = NULL; 695 op->active_prev = NULL;
696} 696}
697 697
698/* 698/*
699 * update_object() updates the array which represents the map. 699 * update_object() updates the the map.
700 * It takes into account invisible objects (and represent squares covered 700 * It takes into account invisible objects (and represent squares covered
701 * by invisible objects by whatever is below them (unless it's another 701 * by invisible objects by whatever is below them (unless it's another
702 * invisible object, etc...) 702 * invisible object, etc...)
703 * If the object being updated is beneath a player, the look-window 703 * If the object being updated is beneath a player, the look-window
704 * of that player is updated (this might be a suboptimal way of 704 * of that player is updated (this might be a suboptimal way of
705 * updating that window, though, since update_object() is called _often_) 705 * updating that window, though, since update_object() is called _often_)
706 * 706 *
707 * action is a hint of what the caller believes need to be done. 707 * action is a hint of what the caller believes need to be done.
708 * For example, if the only thing that has changed is the face (due to
709 * an animation), we don't need to call update_position until that actually
710 * comes into view of a player. OTOH, many other things, like addition/removal
711 * of walls or living creatures may need us to update the flags now.
712 * current action are: 708 * current action are:
713 * UP_OBJ_INSERT: op was inserted 709 * UP_OBJ_INSERT: op was inserted
714 * UP_OBJ_REMOVE: op was removed 710 * UP_OBJ_REMOVE: op was removed
715 * UP_OBJ_CHANGE: object has somehow changed. In this case, we always update 711 * UP_OBJ_CHANGE: object has somehow changed. In this case, we always update
716 * as that is easier than trying to look at what may have changed. 712 * as that is easier than trying to look at what may have changed.
717 * UP_OBJ_FACE: only the objects face has changed. 713 * UP_OBJ_FACE: only the objects face has changed.
718 */ 714 */
719
720void 715void
721update_object (object *op, int action) 716update_object (object *op, int action)
722{ 717{
723 int update_now = 0, flags;
724 MoveType move_on, move_off, move_block, move_slow; 718 MoveType move_on, move_off, move_block, move_slow;
725 719
726 if (op == NULL) 720 if (op == NULL)
727 { 721 {
728 /* this should never happen */ 722 /* this should never happen */
729 LOG (llevDebug, "update_object() called for NULL object.\n"); 723 LOG (llevDebug, "update_object() called for NULL object.\n");
730 return; 724 return;
731 } 725 }
732 726
733 if (op->env != NULL) 727 if (op->env)
734 { 728 {
735 /* Animation is currently handled by client, so nothing 729 /* Animation is currently handled by client, so nothing
736 * to do in this case. 730 * to do in this case.
737 */ 731 */
738 return; 732 return;
752 abort (); 746 abort ();
753#endif 747#endif
754 return; 748 return;
755 } 749 }
756 750
757 flags = GET_MAP_FLAGS (op->map, op->x, op->y); 751 mapspace &m = op->map->at (op->x, op->y);
758 SET_MAP_FLAGS (op->map, op->x, op->y, flags | P_NEED_UPDATE);
759 move_slow = GET_MAP_MOVE_SLOW (op->map, op->x, op->y);
760 move_on = GET_MAP_MOVE_ON (op->map, op->x, op->y);
761 move_block = GET_MAP_MOVE_BLOCK (op->map, op->x, op->y);
762 move_off = GET_MAP_MOVE_OFF (op->map, op->x, op->y);
763 752
753 if (m.flags_ & P_NEED_UPDATE)
754 /* nop */;
764 if (action == UP_OBJ_INSERT) 755 else if (action == UP_OBJ_INSERT)
765 { 756 {
757 // this is likely overkill, TODO: revisit (schmorp)
766 if (QUERY_FLAG (op, FLAG_BLOCKSVIEW) && !(flags & P_BLOCKSVIEW)) 758 if ((QUERY_FLAG (op, FLAG_BLOCKSVIEW) && !(m.flags_ & P_BLOCKSVIEW))
767 update_now = 1;
768
769 if (QUERY_FLAG (op, FLAG_NO_MAGIC) && !(flags & P_NO_MAGIC)) 759 || (QUERY_FLAG (op, FLAG_NO_MAGIC) && !(m.flags_ & P_NO_MAGIC))
770 update_now = 1; 760 || (op->type == PLAYER && !(m.flags_ & P_PLAYER))
771 761 || (op->type == SAFE_GROUND && !(m.flags_ & P_SAFE))
762 || (QUERY_FLAG (op, FLAG_ALIVE) && !(m.flags_ & P_IS_ALIVE))
772 if (QUERY_FLAG (op, FLAG_DAMNED) && !(flags & P_NO_CLERIC)) 763 || (QUERY_FLAG (op, FLAG_DAMNED) && !(m.flags_ & P_NO_CLERIC))
773 update_now = 1;
774
775 if (QUERY_FLAG (op, FLAG_ALIVE) && !(flags & P_IS_ALIVE))
776 update_now = 1;
777
778 if (op->type == SAFE_GROUND && !(flags & P_SAFE))
779 update_now = 1;
780
781 if ((move_on | op->move_on) != move_on) 764 || (m.move_on | op->move_on ) != m.move_on
782 update_now = 1;
783
784 if ((move_off | op->move_off) != move_off) 765 || (m.move_off | op->move_off ) != m.move_off
785 update_now = 1; 766 || (m.move_slow | op->move_slow) != m.move_slow
786
787 /* This isn't perfect, but I don't expect a lot of objects to 767 /* This isn't perfect, but I don't expect a lot of objects to
788 * to have move_allow right now. 768 * to have move_allow right now.
789 */ 769 */
790 if (((move_block | op->move_block) & ~op->move_allow) != move_block) 770 || ((m.move_block | op->move_block) & ~op->move_allow) != m.move_block
791 update_now = 1; 771 || 1) // the above is not strong enough a test to skip updating. los maybe? TODO (Schmorp)
792 772 m.flags_ = P_NEED_UPDATE;
793 if ((move_slow | op->move_slow) != move_slow)
794 update_now = 1;
795 } 773 }
796
797 /* if the object is being removed, we can't make intelligent 774 /* if the object is being removed, we can't make intelligent
798 * decisions, because remove_ob can't really pass the object 775 * decisions, because remove_ob can't really pass the object
799 * that is being removed. 776 * that is being removed.
800 */ 777 */
801 else if (action == UP_OBJ_CHANGE || action == UP_OBJ_REMOVE) 778 else if (action == UP_OBJ_CHANGE || action == UP_OBJ_REMOVE)
802 update_now = 1; 779 m.flags_ = P_NEED_UPDATE;
803 else if (action == UP_OBJ_FACE) 780 else if (action == UP_OBJ_FACE)
804 /* Nothing to do for that case */ ; 781 /* Nothing to do for that case */ ;
805 else 782 else
806 LOG (llevError, "update_object called with invalid action: %d\n", action); 783 LOG (llevError, "update_object called with invalid action: %d\n", action);
807 784
808 if (update_now)
809 {
810 SET_MAP_FLAGS (op->map, op->x, op->y, flags | P_NO_ERROR | P_NEED_UPDATE);
811 update_position (op->map, op->x, op->y);
812 }
813
814 if (op->more != NULL) 785 if (op->more)
815 update_object (op->more, action); 786 update_object (op->more, action);
816} 787}
817 788
818object::vector object::mortals; 789object::vector object::mortals;
819object::vector object::objects; // not yet used 790object::vector object::objects; // not yet used
1070 1041
1071 /* link the object above us */ 1042 /* link the object above us */
1072 if (above) 1043 if (above)
1073 above->below = below; 1044 above->below = below;
1074 else 1045 else
1075 SET_MAP_TOP (map, x, y, below); /* we were top, set new top */ 1046 map->at (x, y).top = below; /* we were top, set new top */
1076 1047
1077 /* Relink the object below us, if there is one */ 1048 /* Relink the object below us, if there is one */
1078 if (below) 1049 if (below)
1079 below->above = above; 1050 below->above = above;
1080 else 1051 else
1092 dump = dump_object (GET_MAP_OB (map, x, y)); 1063 dump = dump_object (GET_MAP_OB (map, x, y));
1093 LOG (llevError, "%s\n", dump); 1064 LOG (llevError, "%s\n", dump);
1094 free (dump); 1065 free (dump);
1095 } 1066 }
1096 1067
1097 SET_MAP_OB (map, x, y, above); /* goes on above it. */ 1068 map->at (x, y).bottom = above; /* goes on above it. */
1098 } 1069 }
1099 1070
1100 above = 0; 1071 above = 0;
1101 below = 0; 1072 below = 0;
1102 1073
1145 last = tmp; 1116 last = tmp;
1146 } 1117 }
1147 1118
1148 /* last == NULL of there are no objects on this space */ 1119 /* last == NULL of there are no objects on this space */
1149 if (!last) 1120 if (!last)
1150 { 1121 map->at (x, y).flags_ = P_NEED_UPDATE;
1151 /* set P_NEED_UPDATE, otherwise update_position will complain. In theory,
1152 * we could preserve the flags (GET_MAP_FLAGS), but update_position figures
1153 * those out anyways, and if there are any flags set right now, they won't
1154 * be correct anyways.
1155 */
1156 SET_MAP_FLAGS (map, x, y, P_NEED_UPDATE);
1157 update_position (map, x, y);
1158 }
1159 else 1122 else
1160 update_object (last, UP_OBJ_REMOVE); 1123 update_object (last, UP_OBJ_REMOVE);
1161 1124
1162 if (QUERY_FLAG (this, FLAG_BLOCKSVIEW) || glow_radius) 1125 if (QUERY_FLAG (this, FLAG_BLOCKSVIEW) || glow_radius)
1163 update_all_los (map, x, y); 1126 update_all_los (map, x, y);
1353 op->below = originator->below; 1316 op->below = originator->below;
1354 1317
1355 if (op->below) 1318 if (op->below)
1356 op->below->above = op; 1319 op->below->above = op;
1357 else 1320 else
1358 SET_MAP_OB (op->map, op->x, op->y, op); 1321 op->map->at (op->x, op->y).bottom = op;
1359 1322
1360 /* since *below* originator, no need to update top */ 1323 /* since *below* originator, no need to update top */
1361 originator->below = op; 1324 originator->below = op;
1362 } 1325 }
1363 else 1326 else
1409 * If INS_ON_TOP is used, don't do this processing 1372 * If INS_ON_TOP is used, don't do this processing
1410 * Need to find the object that in fact blocks view, otherwise 1373 * Need to find the object that in fact blocks view, otherwise
1411 * stacking is a bit odd. 1374 * stacking is a bit odd.
1412 */ 1375 */
1413 if (!(flag & INS_ON_TOP) && 1376 if (!(flag & INS_ON_TOP) &&
1414 (get_map_flags (op->map, NULL, op->x, op->y, NULL, NULL) & P_BLOCKSVIEW) && (op->face && !op->face->visibility)) 1377 (get_map_flags (op->map, 0, op->x, op->y, 0, 0) & P_BLOCKSVIEW) && (op->face && !op->face->visibility))
1415 { 1378 {
1416 for (last = top; last != floor; last = last->below) 1379 for (last = top; last != floor; last = last->below)
1417 if (QUERY_FLAG (last, FLAG_BLOCKSVIEW) && (last->type != EXIT)) 1380 if (QUERY_FLAG (last, FLAG_BLOCKSVIEW) && (last->type != EXIT))
1418 break; 1381 break;
1419 /* Check to see if we found the object that blocks view, 1382 /* Check to see if we found the object that blocks view,
1442 1405
1443 if (op->above) 1406 if (op->above)
1444 op->above->below = op; 1407 op->above->below = op;
1445 1408
1446 op->below = NULL; 1409 op->below = NULL;
1447 SET_MAP_OB (op->map, op->x, op->y, op); 1410 op->map->at (op->x, op->y).bottom = op;
1448 } 1411 }
1449 else 1412 else
1450 { /* get inserted into the stack above top */ 1413 { /* get inserted into the stack above top */
1451 op->above = top->above; 1414 op->above = top->above;
1452 1415
1456 op->below = top; 1419 op->below = top;
1457 top->above = op; 1420 top->above = op;
1458 } 1421 }
1459 1422
1460 if (op->above == NULL) 1423 if (op->above == NULL)
1461 SET_MAP_TOP (op->map, op->x, op->y, op); 1424 op->map->at (op->x, op->y).top = op;
1462 } /* else not INS_BELOW_ORIGINATOR */ 1425 } /* else not INS_BELOW_ORIGINATOR */
1463 1426
1464 if (op->type == PLAYER) 1427 if (op->type == PLAYER)
1465 op->contr->do_los = 1; 1428 op->contr->do_los = 1;
1466 1429
1467 /* If we have a floor, we know the player, if any, will be above 1430 /* If we have a floor, we know the player, if any, will be above
1468 * it, so save a few ticks and start from there. 1431 * it, so save a few ticks and start from there.
1469 */ 1432 */
1470 if (!(flag & INS_MAP_LOAD)) 1433 if (!(flag & INS_MAP_LOAD))
1471 for (tmp = floor ? floor : GET_MAP_OB (op->map, op->x, op->y); tmp != NULL; tmp = tmp->above) 1434 if (object *pl = op->map->at (op->x, op->y).player ())
1472 if (tmp->type == PLAYER)
1473 tmp->contr->socket->floorbox_update (); 1435 pl->contr->socket->floorbox_update ();
1474 1436
1475 /* If this object glows, it may affect lighting conditions that are 1437 /* If this object glows, it may affect lighting conditions that are
1476 * visible to others on this map. But update_all_los is really 1438 * visible to others on this map. But update_all_los is really
1477 * an inefficient way to do this, as it means los for all players 1439 * an inefficient way to do this, as it means los for all players
1478 * on the map will get recalculated. The players could very well 1440 * on the map will get recalculated. The players could very well
1512 1474
1513 return op; 1475 return op;
1514} 1476}
1515 1477
1516/* this function inserts an object in the map, but if it 1478/* this function inserts an object in the map, but if it
1517 * finds an object of its own type, it'll remove that one first. 1479 * finds an object of its own type, it'll remove that one first.
1518 * op is the object to insert it under: supplies x and the map. 1480 * op is the object to insert it under: supplies x and the map.
1519 */ 1481 */
1520void 1482void
1521replace_insert_ob_in_map (const char *arch_string, object *op) 1483replace_insert_ob_in_map (const char *arch_string, object *op)
1522{ 1484{
1523 object * 1485 object *tmp, *tmp1;
1524 tmp;
1525 object *
1526 tmp1;
1527 1486
1528 /* first search for itself and remove any old instances */ 1487 /* first search for itself and remove any old instances */
1529 1488
1530 for (tmp = GET_MAP_OB (op->map, op->x, op->y); tmp != NULL; tmp = tmp->above) 1489 for (tmp = GET_MAP_OB (op->map, op->x, op->y); tmp != NULL; tmp = tmp->above)
1531 if (!strcmp (tmp->arch->name, arch_string)) /* same archetype */ 1490 if (!strcmp (tmp->arch->name, arch_string)) /* same archetype */
2241 mp = m; 2200 mp = m;
2242 nx = x + freearr_x[i]; 2201 nx = x + freearr_x[i];
2243 ny = y + freearr_y[i]; 2202 ny = y + freearr_y[i];
2244 2203
2245 mflags = get_map_flags (m, &mp, nx, ny, &nx, &ny); 2204 mflags = get_map_flags (m, &mp, nx, ny, &nx, &ny);
2205
2246 if (mflags & P_OUT_OF_MAP) 2206 if (mflags & P_OUT_OF_MAP)
2247 {
2248 max = maxfree[i]; 2207 max = maxfree[i];
2249 }
2250 else 2208 else
2251 { 2209 {
2252 blocked = GET_MAP_MOVE_BLOCK (mp, nx, ny); 2210 blocked = GET_MAP_MOVE_BLOCK (mp, nx, ny);
2253 2211
2254 if ((move_type & blocked) == move_type) 2212 if ((move_type & blocked) == move_type)
2255 {
2256 max = maxfree[i]; 2213 max = maxfree[i];
2257 }
2258 else if (mflags & P_IS_ALIVE) 2214 else if (mflags & P_IS_ALIVE)
2259 { 2215 {
2260 for (tmp = GET_MAP_OB (mp, nx, ny); tmp != NULL; tmp = tmp->above) 2216 for (tmp = GET_MAP_OB (mp, nx, ny); tmp; tmp = tmp->above)
2261 {
2262 if ((QUERY_FLAG (tmp, FLAG_MONSTER) || tmp->type == PLAYER) && (tmp != exclude || (tmp->head && tmp->head != exclude))) 2217 if ((QUERY_FLAG (tmp, FLAG_MONSTER) || tmp->type == PLAYER) && (tmp != exclude || (tmp->head && tmp->head != exclude)))
2263 {
2264 break; 2218 break;
2265 } 2219
2266 }
2267 if (tmp) 2220 if (tmp)
2268 {
2269 return freedir[i]; 2221 return freedir[i];
2270 }
2271 } 2222 }
2272 } 2223 }
2273 } 2224 }
2225
2274 return 0; 2226 return 0;
2275} 2227}
2276 2228
2277/* 2229/*
2278 * distance(object 1, object 2) will return the square of the 2230 * distance(object 1, object 2) will return the square of the
2280 */ 2232 */
2281 2233
2282int 2234int
2283distance (const object *ob1, const object *ob2) 2235distance (const object *ob1, const object *ob2)
2284{ 2236{
2285 int 2237 int i;
2286 i;
2287 2238
2288 i = (ob1->x - ob2->x) * (ob1->x - ob2->x) + (ob1->y - ob2->y) * (ob1->y - ob2->y); 2239 i = (ob1->x - ob2->x) * (ob1->x - ob2->x) + (ob1->y - ob2->y) * (ob1->y - ob2->y);
2289 return i; 2240 return i;
2290} 2241}
2291 2242
2296 */ 2247 */
2297 2248
2298int 2249int
2299find_dir_2 (int x, int y) 2250find_dir_2 (int x, int y)
2300{ 2251{
2301 int 2252 int q;
2302 q;
2303 2253
2304 if (y) 2254 if (y)
2305 q = x * 100 / y; 2255 q = x * 100 / y;
2306 else if (x) 2256 else if (x)
2307 q = -300 * x; 2257 q = -300 * x;
2433 * find a path to that monster that we found. If not, 2383 * find a path to that monster that we found. If not,
2434 * we don't bother going toward it. Returns 1 if we 2384 * we don't bother going toward it. Returns 1 if we
2435 * can see a direct way to get it 2385 * can see a direct way to get it
2436 * Modified to be map tile aware -.MSW 2386 * Modified to be map tile aware -.MSW
2437 */ 2387 */
2438
2439
2440int 2388int
2441can_see_monsterP (maptile *m, int x, int y, int dir) 2389can_see_monsterP (maptile *m, int x, int y, int dir)
2442{ 2390{
2443 sint16 dx, dy; 2391 sint16 dx, dy;
2444 int
2445 mflags; 2392 int mflags;
2446 2393
2447 if (dir < 0) 2394 if (dir < 0)
2448 return 0; /* exit condition: invalid direction */ 2395 return 0; /* exit condition: invalid direction */
2449 2396
2450 dx = x + freearr_x[dir]; 2397 dx = x + freearr_x[dir];
2463 return 0; 2410 return 0;
2464 2411
2465 /* yes, can see. */ 2412 /* yes, can see. */
2466 if (dir < 9) 2413 if (dir < 9)
2467 return 1; 2414 return 1;
2415
2468 return can_see_monsterP (m, x, y, reduction_dir[dir][0]) | 2416 return can_see_monsterP (m, x, y, reduction_dir[dir][0])
2469 can_see_monsterP (m, x, y, reduction_dir[dir][1]) | can_see_monsterP (m, x, y, reduction_dir[dir][2]); 2417 | can_see_monsterP (m, x, y, reduction_dir[dir][1])
2418 | can_see_monsterP (m, x, y, reduction_dir[dir][2]);
2470} 2419}
2471
2472
2473 2420
2474/* 2421/*
2475 * can_pick(picker, item): finds out if an object is possible to be 2422 * can_pick(picker, item): finds out if an object is possible to be
2476 * picked up by the picker. Returnes 1 if it can be 2423 * picked up by the picker. Returnes 1 if it can be
2477 * picked up, otherwise 0. 2424 * picked up, otherwise 0.
2488 return /*QUERY_FLAG(who,FLAG_WIZ)|| */ 2435 return /*QUERY_FLAG(who,FLAG_WIZ)|| */
2489 (item->weight > 0 && !QUERY_FLAG (item, FLAG_NO_PICK) && 2436 (item->weight > 0 && !QUERY_FLAG (item, FLAG_NO_PICK) &&
2490 !QUERY_FLAG (item, FLAG_ALIVE) && !item->invisible && (who->type == PLAYER || item->weight < who->weight / 3)); 2437 !QUERY_FLAG (item, FLAG_ALIVE) && !item->invisible && (who->type == PLAYER || item->weight < who->weight / 3));
2491} 2438}
2492 2439
2493
2494/* 2440/*
2495 * create clone from object to another 2441 * create clone from object to another
2496 */ 2442 */
2497object * 2443object *
2498object_create_clone (object *asrc) 2444object_create_clone (object *asrc)
2517 { 2463 {
2518 dst = tmp; 2464 dst = tmp;
2519 tmp->head = 0; 2465 tmp->head = 0;
2520 } 2466 }
2521 else 2467 else
2522 {
2523 tmp->head = dst; 2468 tmp->head = dst;
2524 }
2525 2469
2526 tmp->more = 0; 2470 tmp->more = 0;
2527 2471
2528 if (prev) 2472 if (prev)
2529 prev->more = tmp; 2473 prev->more = tmp;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines