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

Comparing deliantra/server/server/player.C (file contents):
Revision 1.209 by root, Thu Dec 18 05:13:38 2008 UTC vs.
Revision 1.213 by root, Fri Dec 26 13:33:22 2008 UTC

210 ob->close_container (); //TODO: client-specific 210 ob->close_container (); //TODO: client-specific
211 211
212 ns->update_look = 0; 212 ns->update_look = 0;
213 ns->look_position = 0; 213 ns->look_position = 0;
214 214
215 clear_los (this); 215 clear_los ();
216 216
217 ns->reset_stats (); 217 ns->reset_stats ();
218 218
219 /* make sure he's a player -- needed because of class change. */ 219 /* make sure he's a player -- needed because of class change. */
220 ob->type = PLAYER; // we are paranoid 220 ob->type = PLAYER; // we are paranoid
931 LOG (llevDebug, "Fleeing player is dead.\n"); 931 LOG (llevDebug, "Fleeing player is dead.\n");
932 CLEAR_FLAG (op, FLAG_SCARED); 932 CLEAR_FLAG (op, FLAG_SCARED);
933 return; 933 return;
934 } 934 }
935 935
936 if (op->enemy == NULL) 936 if (!op->enemy)
937 { 937 {
938 LOG (llevDebug, "Fleeing player had no enemy.\n"); 938 LOG (llevDebug, "Fleeing player had no enemy.\n");
939 CLEAR_FLAG (op, FLAG_SCARED); 939 CLEAR_FLAG (op, FLAG_SCARED);
940 return;
941 }
942
943 /* Seen some crashes here. Since we don't store an
944 * op->enemy_count, it is possible that something destroys the
945 * actual enemy, and the object is recycled.
946 */
947 if (op->enemy->map == NULL)
948 {
949 CLEAR_FLAG (op, FLAG_SCARED);
950 op->enemy = NULL;
951 return; 940 return;
952 } 941 }
953 942
954 if (!(random_roll (0, 4, op, PREFER_LOW)) && did_make_save (op, op->level, 0)) 943 if (!(random_roll (0, 4, op, PREFER_LOW)) && did_make_save (op, op->level, 0))
955 { 944 {
1016 1005
1017 if (op->contr->search_str[0] != '\0' && settings.search_items == TRUE) 1006 if (op->contr->search_str[0] != '\0' && settings.search_items == TRUE)
1018 { 1007 {
1019 if (item_matched_string (op, tmp, op->contr->search_str)) 1008 if (item_matched_string (op, tmp, op->contr->search_str))
1020 CHK_PICK_PICKUP; 1009 CHK_PICK_PICKUP;
1010
1021 continue; 1011 continue;
1022 } 1012 }
1023 1013
1024 /* high not bit set? We're using the old autopickup model */ 1014 /* high not bit set? We're using the old autopickup model */
1025 if (!(op->contr->mode & PU_NEWMODE)) 1015 if (!(op->contr->mode & PU_NEWMODE))
1462 for (i = 0, found = 0; i < 20; i++) 1452 for (i = 0, found = 0; i < 20; i++)
1463 { 1453 {
1464 x += freearr_x[dir]; 1454 x += freearr_x[dir];
1465 y += freearr_y[dir]; 1455 y += freearr_y[dir];
1466 mflags = get_map_flags (m, &m, x, y, &x, &y); 1456 mflags = get_map_flags (m, &m, x, y, &x, &y);
1457
1467 if (mflags & P_OUT_OF_MAP || mflags & P_BLOCKSVIEW) 1458 if (mflags & P_OUT_OF_MAP || mflags & P_BLOCKSVIEW)
1468 { 1459 {
1469 tmp = NULL; 1460 tmp = 0;
1470 break; 1461 break;
1471 } 1462 }
1472 else if (GET_MAP_MOVE_BLOCK (m, x, y) == MOVE_FLY_LOW) 1463 else if (GET_MAP_MOVE_BLOCK (m, x, y) == MOVE_FLY_LOW)
1473 { 1464 {
1474 /* This block presumes arrows and the like are MOVE_FLY_SLOW - 1465 /* This block presumes arrows and the like are MOVE_FLY_SLOW -
1475 * perhaps a bad assumption. 1466 * perhaps a bad assumption.
1476 */ 1467 */
1477 tmp = NULL; 1468 tmp = 0;
1478 break; 1469 break;
1479 } 1470 }
1471
1480 if (mflags & P_IS_ALIVE) 1472 if (mflags & P_IS_ALIVE)
1481 {
1482 for (tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above) 1473 for (tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above)
1483 if (QUERY_FLAG (tmp, FLAG_ALIVE)) 1474 if (QUERY_FLAG (tmp, FLAG_ALIVE))
1484 {
1485 found++;
1486 break;
1487 }
1488 if (found)
1489 break; 1475 break;
1490 }
1491 } 1476 }
1492 if (tmp == NULL) 1477
1478 if (!tmp)
1493 return find_arrow (op, type); 1479 return find_arrow (op, type);
1494 1480
1495 if (tmp->head) 1481 if (tmp->head)
1496 tmp = tmp->head; 1482 tmp = tmp->head;
1497 1483
1542 if (bow->below) 1528 if (bow->below)
1543 { 1529 {
1544 bow->remove (); 1530 bow->remove ();
1545 op->insert (bow); 1531 op->insert (bow);
1546 } 1532 }
1547
1548 } 1533 }
1549 1534
1550 if (!bow->race || !bow->skill) 1535 if (!bow->race || !bow->skill)
1551 { 1536 {
1552 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s is broken.", &bow->name); 1537 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s is broken.", &bow->name);
1675 * hence the function name. 1660 * hence the function name.
1676 */ 1661 */
1677int 1662int
1678player_fire_bow (object *op, int dir) 1663player_fire_bow (object *op, int dir)
1679{ 1664{
1680 int ret = 0, wcmod = 0; 1665 int ret;
1681 1666
1682 if (op->contr->bowtype == bow_bestarrow) 1667 if (op->contr->bowtype == bow_bestarrow)
1683 { 1668 {
1684 ret = fire_bow (op, op, pick_arrow_target (op, op->contr->ranged_ob->race, dir), dir, 0, op->x, op->y); 1669 ret = fire_bow (op, op, pick_arrow_target (op, op->contr->ranged_ob->race, dir), dir, 0, op->x, op->y);
1685 } 1670 }
1686 else if (op->contr->bowtype >= bow_n && op->contr->bowtype <= bow_nw) 1671 else if (op->contr->bowtype >= bow_n && op->contr->bowtype <= bow_nw)
1687 { 1672 {
1688 if (!similar_direction (dir, op->contr->bowtype - bow_n + 1)) 1673 int wcmod = similar_direction (dir, op->contr->bowtype - bow_n + 1) ? 0 : -1;
1689 wcmod = -1;
1690
1691 ret = fire_bow (op, op, NULL, op->contr->bowtype - bow_n + 1, wcmod, op->x, op->y); 1674 ret = fire_bow (op, op, NULL, op->contr->bowtype - bow_n + 1, wcmod, op->x, op->y);
1692 } 1675 }
1693 else if (op->contr->bowtype == bow_threewide) 1676 else if (op->contr->bowtype == bow_threewide)
1694 { 1677 {
1695 ret = fire_bow (op, op, NULL, dir, 0, op->x, op->y); 1678 ret = fire_bow (op, op, NULL, dir, 0, op->x, op->y);
1696 ret |= fire_bow (op, op, NULL, dir, -5, op->x + freearr_x[absdir (dir + 2)], op->y + freearr_y[absdir (dir + 2)]); 1679 ret |= fire_bow (op, op, NULL, dir, -5, op->x + freearr_x[absdir (dir + 2)], op->y + freearr_y[absdir (dir + 2)]);
1697 ret |= fire_bow (op, op, NULL, dir, -5, op->x + freearr_x[absdir (dir - 2)], op->y + freearr_y[absdir (dir - 2)]); 1680 ret |= fire_bow (op, op, NULL, dir, -5, op->x + freearr_x[absdir (dir - 2)], op->y + freearr_y[absdir (dir - 2)]);
1698 } 1681 }
1699 else if (op->contr->bowtype == bow_spreadshot) 1682 else if (op->contr->bowtype == bow_spreadshot)
1700 { 1683 {
1701 ret |= fire_bow (op, op, NULL, dir, 0, op->x, op->y); 1684 ret = fire_bow (op, op, NULL, dir, 0, op->x, op->y);
1702 ret |= fire_bow (op, op, NULL, absdir (dir - 1), -5, op->x, op->y); 1685 ret |= fire_bow (op, op, NULL, absdir (dir - 1), -5, op->x, op->y);
1703 ret |= fire_bow (op, op, NULL, absdir (dir + 1), -5, op->x, op->y); 1686 ret |= fire_bow (op, op, NULL, absdir (dir + 1), -5, op->x, op->y);
1704 } 1687 }
1705 else 1688 else
1706 { 1689 {
1763 } 1746 }
1764 } 1747 }
1765 1748
1766 if (cast_spell (op, item, dir, item->inv, NULL)) 1749 if (cast_spell (op, item, dir, item->inv, NULL))
1767 { 1750 {
1768 SET_FLAG (op, FLAG_BEEN_APPLIED); /* You now know something about it */ 1751 item->flag [FLAG_BEEN_APPLIED] = true; /* You now know something about it */
1752
1769 if (item->type == WAND) 1753 if (item->type == WAND)
1770 { 1754 {
1771 if (!(--item->stats.food)) 1755 if (!(--item->stats.food))
1772 { 1756 {
1773 object *tmp; 1757 object *tmp;
2071 --op->speed_left; 2055 --op->speed_left;
2072 2056
2073 op->play_sound (sound_find ("push_player")); 2057 op->play_sound (sound_find ("push_player"));
2074 push_ob (mon, dir, op); 2058 push_ob (mon, dir, op);
2075 2059
2076 if (op->contr->tmp_invis || op->flag [FLAG_HIDDEN]) 2060 if (action_makes_visible (op))
2077 make_visible (op); 2061 make_visible (op);
2078 2062
2079 return true; 2063 return true;
2080 } 2064 }
2081 else 2065 else
3036 3020
3037 if (!ob || !ob->map) 3021 if (!ob || !ob->map)
3038 return 0; 3022 return 0;
3039 3023
3040 /* so, on normal lighted maps, its hard to hide */ 3024 /* so, on normal lighted maps, its hard to hide */
3041 level = ob->map->darkness - 2; 3025 level = ob->map->darklevel () - 2;
3042 3026
3043 /* this also picks up whether the object is glowing. 3027 /* this also picks up whether the object is glowing.
3044 * If you carry a light on a non-dark map, its not 3028 * If you carry a light on a non-dark map, its not
3045 * as bad as carrying a light on a pitch dark map */ 3029 * as bad as carrying a light on a pitch dark map */
3046 if (has_carried_lights (ob)) 3030 if (has_carried_lights (ob))
3047 level = -(10 + (2 * ob->map->darkness)); 3031 level = -(10 + (2 * ob->map->darklevel ()));
3048 3032
3049 /* scan through all nearby squares for terrain to hide in */ 3033 /* scan through all nearby squares for terrain to hide in */
3050 for (i = 0, x = ob->x, y = ob->y; 3034 for (i = 0, x = ob->x, y = ob->y;
3051 i <= SIZEOFFREE1; 3035 i <= SIZEOFFREE1;
3052 i++, x = ob->x + freearr_x[i], y = ob->y + freearr_y[i]) 3036 i++, x = ob->x + freearr_x[i], y = ob->y + freearr_y[i])
3203 3187
3204 /* only the viewable area the player sees is updated by LOS 3188 /* only the viewable area the player sees is updated by LOS
3205 * code, so we need to restrict ourselves to that range of values 3189 * code, so we need to restrict ourselves to that range of values
3206 * for any meaningful values. 3190 * for any meaningful values.
3207 */ 3191 */
3208 if (abs (dx) <= (pl->contr->ns->mapx / 2) && 3192 if (pl->contr->blocked_los (dx, dy) != LOS_BLOCKED)
3209 abs (dy) <= (pl->contr->ns->mapy / 2) &&
3210 !pl->contr->blocked_los[dx + (pl->contr->ns->mapx / 2)][dy + (pl->contr->ns->mapy / 2)])
3211 return 1; 3193 return 1;
3212 3194
3213 op = op->more; 3195 op = op->more;
3214 } 3196 }
3215 3197
3216 return 0; 3198 return 0;
3217} 3199}
3218 3200
3219/* routine for both players and monsters. We call this when 3201/* routine for both players and monsters. We call this when
3220 * there is a possibility for our action distrubing our hiding 3202 * there is a possibility for our action distrubing our hiding
3221 * place or invisiblity spell. Artefact invisiblity is not 3203 * place or invisiblity spell. Artefact invisiblity causes
3222 * effected by this. If we arent invisible to begin with, we 3204 * "noise" instead. If we arent invisible to begin with, we
3223 * return 0. 3205 * return 0.
3224 */ 3206 */
3225int 3207int
3226action_makes_visible (object *op) 3208action_makes_visible (object *op)
3227{ 3209{
3228 if (op->invisible && QUERY_FLAG (op, FLAG_ALIVE)) 3210 if (op->invisible && QUERY_FLAG (op, FLAG_ALIVE))
3229 { 3211 {
3230 if (QUERY_FLAG (op, FLAG_MAKE_INVIS)) 3212 if (QUERY_FLAG (op, FLAG_MAKE_INVIS))
3213 {
3214 // artefact invisibility is permanent, but we still make noise
3215 // this is important for game-balance.
3216 if (op->contr)
3217 op->make_noise ();
3218
3231 return 0; 3219 return 0;
3220 }
3232 3221
3233 if (op->contr && op->contr->tmp_invis == 0) 3222 if (op->contr && op->contr->tmp_invis == 0)
3234 return 0; 3223 return 0;
3235 3224
3236 /* If monsters, they should become visible */ 3225 /* If monsters, they should become visible */
3481 3470
3482 int dx, dy; 3471 int dx, dy;
3483 if (!adjacent_map (map, ns->current_map, &dx, &dy)) 3472 if (!adjacent_map (map, ns->current_map, &dx, &dy))
3484 return 0; 3473 return 0;
3485 3474
3486 x += dx - ns->current_x + ns->mapx / 2; 3475 x += dx - ns->current_x;
3487 y += dy - ns->current_y + ns->mapy / 2; 3476 y += dy - ns->current_y;
3488 3477
3489 if (!IN_RANGE_EXC (x, 0, ns->mapx) || !IN_RANGE_EXC (y, 0, ns->mapy))
3490 return 0;
3491
3492 return 100 - blocked_los [x][y]; 3478 return 100 - blocked_los (x, y);
3493} 3479}
3494 3480
3495void 3481void
3496player::infobox (const char *title, const char *msg, int color) 3482player::infobox (const char *title, const char *msg, int color)
3497{ 3483{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines