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.206 by root, Mon Sep 29 10:20:49 2008 UTC vs.
Revision 1.218 by root, Sun Dec 28 10:05:42 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
366 attachable::do_destroy (); 366 attachable::do_destroy ();
367 367
368 if (ob) 368 if (ob)
369 { 369 {
370 ob->destroy_inv (false); 370 ob->destroy_inv (false);
371 ob->destroy (true); 371 ob->destroy ();
372 } 372 }
373 373
374 ob = observe = 0; 374 ob = observe = 0;
375} 375}
376 376
668 || op->type == CLOAK || op->type == HELMET 668 || op->type == CLOAK || op->type == HELMET
669 || op->type == SHIELD || op->type == GLOVES 669 || op->type == SHIELD || op->type == GLOVES
670 || op->type == BRACERS || op->type == GIRDLE)) 670 || op->type == BRACERS || op->type == GIRDLE))
671 || (!QUERY_FLAG (pl, FLAG_USE_WEAPON) && op->type == WEAPON)) 671 || (!QUERY_FLAG (pl, FLAG_USE_WEAPON) && op->type == WEAPON))
672 { 672 {
673 op->destroy (true); 673 op->destroy ();
674 continue; 674 continue;
675 } 675 }
676 } 676 }
677 677
678 /* This really needs to be better - we should really give 678 /* This really needs to be better - we should really give
689 if (tmp->type == op->type && tmp->name == op->name) 689 if (tmp->type == op->type && tmp->name == op->name)
690 break; 690 break;
691 691
692 if (tmp) 692 if (tmp)
693 { 693 {
694 op->destroy (true); 694 op->destroy ();
695 LOG (llevError, "give_initial_items: Removing duplicate object %s\n", &tmp->name); 695 LOG (llevError, "give_initial_items: Removing duplicate object %s\n", &tmp->name);
696 continue; 696 continue;
697 } 697 }
698 698
699 if (op->nrof > 1) 699 if (op->nrof > 1)
714 CLEAR_FLAG (op, FLAG_DAMNED); 714 CLEAR_FLAG (op, FLAG_DAMNED);
715 } 715 }
716 716
717 if (op->type == SPELL) 717 if (op->type == SPELL)
718 { 718 {
719 op->destroy (true); 719 op->destroy ();
720 continue; 720 continue;
721 } 721 }
722 else if (op->type == SKILL) 722 else if (op->type == SKILL)
723 { 723 {
724 SET_FLAG (op, FLAG_CAN_USE_SKILL); 724 SET_FLAG (op, FLAG_CAN_USE_SKILL);
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; 940 return;
941 } 941 }
942 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;
952 }
953
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 {
956 op->enemy = NULL; 945 op->enemy = NULL;
957 CLEAR_FLAG (op, FLAG_SCARED); 946 CLEAR_FLAG (op, FLAG_SCARED);
958 return; 947 return;
961 get_rangevector (op, op->enemy, &rv, 0); 950 get_rangevector (op, op->enemy, &rv, 0);
962 951
963 dir = absdir (4 + rv.direction); 952 dir = absdir (4 + rv.direction);
964 for (diff = 0; diff < 3; diff++) 953 for (diff = 0; diff < 3; diff++)
965 { 954 {
966 int m = 1 - (RANDOM () & 2); 955 int m = 1 - rndm (2) * 2;
967 956
968 if (move_ob (op, absdir (dir + diff * m), op) || (diff == 0 && move_ob (op, absdir (dir - diff * m), op))) 957 if (move_ob (op, absdir (dir + diff * m), op) || (diff == 0 && move_ob (op, absdir (dir - diff * m), op)))
969 return; 958 return;
970 } 959 }
971 960
982check_pick (object *op) 971check_pick (object *op)
983{ 972{
984 object *tmp, *next; 973 object *tmp, *next;
985 int stop = 0; 974 int stop = 0;
986 int wvratio; 975 int wvratio;
987 char putstring[128];
988 976
989 /* if you're flying, you cna't pick up anything */ 977 /* if you're flying, you cna't pick up anything */
990 if (op->move_type & MOVE_FLYING) 978 if (op->move_type & MOVE_FLYING)
991 return 1; 979 return 1;
992 980
1016 1004
1017 if (op->contr->search_str[0] != '\0' && settings.search_items == TRUE) 1005 if (op->contr->search_str[0] != '\0' && settings.search_items == TRUE)
1018 { 1006 {
1019 if (item_matched_string (op, tmp, op->contr->search_str)) 1007 if (item_matched_string (op, tmp, op->contr->search_str))
1020 CHK_PICK_PICKUP; 1008 CHK_PICK_PICKUP;
1009
1021 continue; 1010 continue;
1022 } 1011 }
1023 1012
1024 /* high not bit set? We're using the old autopickup model */ 1013 /* high not bit set? We're using the old autopickup model */
1025 if (!(op->contr->mode & PU_NEWMODE)) 1014 if (!(op->contr->mode & PU_NEWMODE))
1065 { /* old model */ 1054 { /* old model */
1066 /* NEW pickup handling */ 1055 /* NEW pickup handling */
1067 if (op->contr->mode & PU_DEBUG) 1056 if (op->contr->mode & PU_DEBUG)
1068 { 1057 {
1069 /* some debugging code to figure out item information */ 1058 /* some debugging code to figure out item information */
1070 if (tmp->name != NULL) 1059 const char *str = tmp->name
1071 sprintf (putstring, "item name: %s item type: %d weight/value: %d", 1060 ? format ("item name: %s item type: %d weight/value: %d",
1072 &tmp->name, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1)))); 1061 &tmp->name, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))))
1073 else
1074 sprintf (putstring, "item name: %s item type: %d weight/value: %d", 1062 : format ("item name: %s item type: %d weight/value: %d",
1075 &tmp->arch->archname, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1)))); 1063 &tmp->arch->archname, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))));
1076 1064
1077 new_draw_info (NDI_UNIQUE, 0, op, putstring); 1065 new_draw_info (NDI_UNIQUE, 0, op, str);
1078 } 1066 }
1079 1067
1080 /* philosophy: 1068 /* philosophy:
1081 * It's easy to grab an item type from a pile, as long as it's 1069 * It's easy to grab an item type from a pile, as long as it's
1082 * generic. This takes no game-time. For more detailed pickups 1070 * generic. This takes no game-time. For more detailed pickups
1462 for (i = 0, found = 0; i < 20; i++) 1450 for (i = 0, found = 0; i < 20; i++)
1463 { 1451 {
1464 x += freearr_x[dir]; 1452 x += freearr_x[dir];
1465 y += freearr_y[dir]; 1453 y += freearr_y[dir];
1466 mflags = get_map_flags (m, &m, x, y, &x, &y); 1454 mflags = get_map_flags (m, &m, x, y, &x, &y);
1455
1467 if (mflags & P_OUT_OF_MAP || mflags & P_BLOCKSVIEW) 1456 if (mflags & P_OUT_OF_MAP || mflags & P_BLOCKSVIEW)
1468 { 1457 {
1469 tmp = NULL; 1458 tmp = 0;
1470 break; 1459 break;
1471 } 1460 }
1472 else if (GET_MAP_MOVE_BLOCK (m, x, y) == MOVE_FLY_LOW) 1461 else if (GET_MAP_MOVE_BLOCK (m, x, y) == MOVE_FLY_LOW)
1473 { 1462 {
1474 /* This block presumes arrows and the like are MOVE_FLY_SLOW - 1463 /* This block presumes arrows and the like are MOVE_FLY_SLOW -
1475 * perhaps a bad assumption. 1464 * perhaps a bad assumption.
1476 */ 1465 */
1477 tmp = NULL; 1466 tmp = 0;
1478 break; 1467 break;
1479 } 1468 }
1469
1480 if (mflags & P_IS_ALIVE) 1470 if (mflags & P_IS_ALIVE)
1481 {
1482 for (tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above) 1471 for (tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above)
1483 if (QUERY_FLAG (tmp, FLAG_ALIVE)) 1472 if (QUERY_FLAG (tmp, FLAG_ALIVE))
1484 {
1485 found++;
1486 break;
1487 }
1488 if (found)
1489 break; 1473 break;
1490 }
1491 } 1474 }
1492 if (tmp == NULL) 1475
1476 if (!tmp)
1493 return find_arrow (op, type); 1477 return find_arrow (op, type);
1494 1478
1495 if (tmp->head) 1479 if (tmp->head)
1496 tmp = tmp->head; 1480 tmp = tmp->head;
1497 1481
1542 if (bow->below) 1526 if (bow->below)
1543 { 1527 {
1544 bow->remove (); 1528 bow->remove ();
1545 op->insert (bow); 1529 op->insert (bow);
1546 } 1530 }
1547
1548 } 1531 }
1549 1532
1550 if (!bow->race || !bow->skill) 1533 if (!bow->race || !bow->skill)
1551 { 1534 {
1552 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s is broken.", &bow->name); 1535 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s is broken.", &bow->name);
1579 1562
1580 /* this should not happen, but sometimes does */ 1563 /* this should not happen, but sometimes does */
1581 if (arrow->nrof == 0) 1564 if (arrow->nrof == 0)
1582 { 1565 {
1583 LOG (llevError | logBacktrace, "arrow (%s) has nrof 0\n", arrow->debug_desc ()); 1566 LOG (llevError | logBacktrace, "arrow (%s) has nrof 0\n", arrow->debug_desc ());
1584 arrow->destroy (true); 1567 arrow->destroy ();
1585 return 0; 1568 return 0;
1586 } 1569 }
1587 1570
1588 left = arrow; /* these are arrows left to the player */ 1571 left = arrow; /* these are arrows left to the player */
1589 arrow = arrow->split (); 1572 arrow = arrow->split ();
1675 * hence the function name. 1658 * hence the function name.
1676 */ 1659 */
1677int 1660int
1678player_fire_bow (object *op, int dir) 1661player_fire_bow (object *op, int dir)
1679{ 1662{
1680 int ret = 0, wcmod = 0; 1663 int ret;
1681 1664
1682 if (op->contr->bowtype == bow_bestarrow) 1665 if (op->contr->bowtype == bow_bestarrow)
1683 { 1666 {
1684 ret = fire_bow (op, op, pick_arrow_target (op, op->contr->ranged_ob->race, dir), dir, 0, op->x, op->y); 1667 ret = fire_bow (op, op, pick_arrow_target (op, op->contr->ranged_ob->race, dir), dir, 0, op->x, op->y);
1685 } 1668 }
1686 else if (op->contr->bowtype >= bow_n && op->contr->bowtype <= bow_nw) 1669 else if (op->contr->bowtype >= bow_n && op->contr->bowtype <= bow_nw)
1687 { 1670 {
1688 if (!similar_direction (dir, op->contr->bowtype - bow_n + 1)) 1671 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); 1672 ret = fire_bow (op, op, NULL, op->contr->bowtype - bow_n + 1, wcmod, op->x, op->y);
1692 } 1673 }
1693 else if (op->contr->bowtype == bow_threewide) 1674 else if (op->contr->bowtype == bow_threewide)
1694 { 1675 {
1695 ret = fire_bow (op, op, NULL, dir, 0, op->x, op->y); 1676 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)]); 1677 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)]); 1678 ret |= fire_bow (op, op, NULL, dir, -5, op->x + freearr_x[absdir (dir - 2)], op->y + freearr_y[absdir (dir - 2)]);
1698 } 1679 }
1699 else if (op->contr->bowtype == bow_spreadshot) 1680 else if (op->contr->bowtype == bow_spreadshot)
1700 { 1681 {
1701 ret |= fire_bow (op, op, NULL, dir, 0, op->x, op->y); 1682 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); 1683 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); 1684 ret |= fire_bow (op, op, NULL, absdir (dir + 1), -5, op->x, op->y);
1704 } 1685 }
1705 else 1686 else
1706 { 1687 {
1763 } 1744 }
1764 } 1745 }
1765 1746
1766 if (cast_spell (op, item, dir, item->inv, NULL)) 1747 if (cast_spell (op, item, dir, item->inv, NULL))
1767 { 1748 {
1768 SET_FLAG (op, FLAG_BEEN_APPLIED); /* You now know something about it */ 1749 item->flag [FLAG_BEEN_APPLIED] = true; /* You now know something about it */
1750
1769 if (item->type == WAND) 1751 if (item->type == WAND)
1770 { 1752 {
1771 if (!(--item->stats.food)) 1753 if (!(--item->stats.food))
1772 { 1754 {
1773 object *tmp; 1755 object *tmp;
1793bool 1775bool
1794fire (object *op, int dir) 1776fire (object *op, int dir)
1795{ 1777{
1796 int spellcost = 0; 1778 int spellcost = 0;
1797 1779
1798 /* check for loss of invisiblity/hide */
1799 if (action_makes_visible (op))
1800 make_visible (op);
1801
1802 player *pl = op->contr; 1780 player *pl = op->contr;
1803 1781
1804 if (pl->golem) 1782 if (pl->golem)
1805 { 1783 {
1806 control_golem (op->contr->golem, dir); 1784 control_golem (op->contr->golem, dir);
1808 } 1786 }
1809 1787
1810 object *ob = pl->ranged_ob; 1788 object *ob = pl->ranged_ob;
1811 1789
1812 if (!ob) 1790 if (!ob)
1813 return false;
1814
1815 if (!op->change_weapon (ob))
1816 return false; 1791 return false;
1817 1792
1818 if (op->speed_left > 0.f) 1793 if (op->speed_left > 0.f)
1819 --op->speed_left; 1794 --op->speed_left;
1820 else 1795 else
1821 return false; 1796 return false;
1797
1798 if (!op->change_weapon (ob))
1799 return false;
1800
1801 /* check for loss of invisiblity/hide */
1802 if (action_makes_visible (op))
1803 make_visible (op);
1822 1804
1823 switch (ob->type) 1805 switch (ob->type)
1824 { 1806 {
1825 case BOW: 1807 case BOW:
1826 player_fire_bow (op, dir); 1808 player_fire_bow (op, dir);
2071 --op->speed_left; 2053 --op->speed_left;
2072 2054
2073 op->play_sound (sound_find ("push_player")); 2055 op->play_sound (sound_find ("push_player"));
2074 push_ob (mon, dir, op); 2056 push_ob (mon, dir, op);
2075 2057
2076 if (op->contr->tmp_invis || op->hide) 2058 if (action_makes_visible (op))
2077 make_visible (op); 2059 make_visible (op);
2078 2060
2079 return true; 2061 return true;
2080 } 2062 }
2081 else 2063 else
2103 push_ob (mon, dir, op); 2085 push_ob (mon, dir, op);
2104 } 2086 }
2105 else 2087 else
2106 op->statusmsg ("You withhold your attack"); 2088 op->statusmsg ("You withhold your attack");
2107 2089
2108 if (op->contr->tmp_invis || op->hide) 2090 if (op->contr->tmp_invis || op->flag [FLAG_HIDDEN])
2109 make_visible (op); 2091 make_visible (op);
2110 2092
2111 return true; 2093 return true;
2112 } 2094 }
2113 } 2095 }
2171 if (QUERY_FLAG (op, FLAG_CONFUSED) && dir) 2153 if (QUERY_FLAG (op, FLAG_CONFUSED) && dir)
2172 dir = absdir (dir + rndm (3) + rndm (3) - 2); 2154 dir = absdir (dir + rndm (3) + rndm (3) - 2);
2173 2155
2174 op->facing = dir; 2156 op->facing = dir;
2175 2157
2176 if (op->hide) 2158 if (op->flag [FLAG_HIDDEN])
2177 do_hidden_move (op); 2159 do_hidden_move (op);
2178 2160
2179 bool retval; 2161 bool retval;
2180 2162
2181 if (INVOKE_PLAYER (MOVE, op->contr, ARG_INT (dir))) 2163 if (INVOKE_PLAYER (MOVE, op->contr, ARG_INT (dir)))
2253 if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE)) 2235 if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE))
2254 { 2236 {
2255 op->play_sound (sound_find ("ob_evaporate")); 2237 op->play_sound (sound_find ("ob_evaporate"));
2256 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s vibrates violently, then evaporates.", query_name (tmp)); 2238 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s vibrates violently, then evaporates.", query_name (tmp));
2257 2239
2258 tmp->destroy (true); 2240 tmp->destroy ();
2259 CLEAR_FLAG (op, FLAG_LIFESAVE); 2241 CLEAR_FLAG (op, FLAG_LIFESAVE);
2260 2242
2261 if (op->stats.hp < 0) 2243 if (op->stats.hp < 0)
2262 op->stats.hp = op->stats.maxhp; 2244 op->stats.hp = op->stats.maxhp;
2263 2245
2499 { 2481 {
2500 over_hp = (gen_hp < 20 ? 30 : gen_hp + 10) / rate_hp; 2482 over_hp = (gen_hp < 20 ? 30 : gen_hp + 10) / rate_hp;
2501 2483
2502 if (over_hp > 0) 2484 if (over_hp > 0)
2503 { 2485 {
2504 op->stats.sp += over_hp + (RANDOM () % rate_hp > ((gen_hp < 20 ? 30 : gen_hp + 10) % rate_hp)) ? -1 : 0; 2486 op->stats.sp += over_hp + (rndm (rate_hp) > ((gen_hp < 20 ? 30 : gen_hp + 10) % rate_hp)) ? -1 : 0;
2505 op->last_heal = 0; 2487 op->last_heal = 0;
2506 } 2488 }
2507 else 2489 else
2508 op->last_heal = rate_hp / (gen_hp < 20 ? 30 : gen_hp + 10); 2490 op->last_heal = rate_hp / (gen_hp < 20 ? 30 : gen_hp + 10);
2509 } 2491 }
2569 op->stats.food = 0; 2551 op->stats.food = 0;
2570 2552
2571 if (op->stats.hp < 0) 2553 if (op->stats.hp < 0)
2572 { 2554 {
2573 op->contr->killer = archetype::get ("killer_starvation"); 2555 op->contr->killer = archetype::get ("killer_starvation");
2574 op->contr->killer->destroy (true); 2556 op->contr->killer->destroy ();
2575 } 2557 }
2576 } 2558 }
2577 2559
2578 /* killer should be set here already */ 2560 /* killer should be set here already */
2579 if (op->stats.hp < 0 && !QUERY_FLAG (op, FLAG_WIZ)) 2561 if (op->stats.hp < 0 && !QUERY_FLAG (op, FLAG_WIZ))
2610 2592
2611 /* restore player */ 2593 /* restore player */
2612 at = archetype::find ("poisoning"); 2594 at = archetype::find ("poisoning");
2613 if (object *tmp = present_arch_in_ob (at, op)) 2595 if (object *tmp = present_arch_in_ob (at, op))
2614 { 2596 {
2615 tmp->destroy (true); 2597 tmp->destroy ();
2616 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed"); 2598 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed");
2617 } 2599 }
2618 2600
2619 at = archetype::find ("confusion"); 2601 at = archetype::find ("confusion");
2620 if (object *tmp = present_arch_in_ob (at, op)) 2602 if (object *tmp = present_arch_in_ob (at, op))
2621 { 2603 {
2622 tmp->destroy (true); 2604 tmp->destroy ();
2623 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer"); 2605 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer");
2624 } 2606 }
2625 2607
2626 cure_disease (op, 0, 0); /* remove any disease */ 2608 cure_disease (op, 0, 0); /* remove any disease */
2627 op->stats.hp = op->stats.maxhp; 2609 op->stats.hp = op->stats.maxhp;
2690 2672
2691 lost_a_stat = 0; 2673 lost_a_stat = 0;
2692 2674
2693 for (z = 0; z < num_stats_lose; z++) 2675 for (z = 0; z < num_stats_lose; z++)
2694 { 2676 {
2695 i = RANDOM () % NUM_STATS; 2677 i = rndm (NUM_STATS);
2696 2678
2697 if (settings.stat_loss_on_death) 2679 if (settings.stat_loss_on_death)
2698 { 2680 {
2699 /* Pick a random stat and take a point off it. Tell the player 2681 /* Pick a random stat and take a point off it. Tell the player
2700 * what he lost. 2682 * what he lost.
2812 at = archetype::find ("poisoning"); 2794 at = archetype::find ("poisoning");
2813 tmp = present_arch_in_ob (at, op); 2795 tmp = present_arch_in_ob (at, op);
2814 2796
2815 if (tmp) 2797 if (tmp)
2816 { 2798 {
2817 tmp->destroy (true); 2799 tmp->destroy ();
2818 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed"); 2800 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed");
2819 } 2801 }
2820 2802
2821 at = archetype::find ("confusion"); 2803 at = archetype::find ("confusion");
2822 tmp = present_arch_in_ob (at, op); 2804 tmp = present_arch_in_ob (at, op);
2823 if (tmp) 2805 if (tmp)
2824 { 2806 {
2825 tmp->destroy (true); 2807 tmp->destroy ();
2826 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer"); 2808 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer");
2827 } 2809 }
2828 2810
2829 cure_disease (op, 0, 0); /* remove any disease */ 2811 cure_disease (op, 0, 0); /* remove any disease */
2830 2812
2833 for (object *item = op->inv; item; ) 2815 for (object *item = op->inv; item; )
2834 { 2816 {
2835 object *next = item->below; 2817 object *next = item->below;
2836 2818
2837 if (item->type == SPELL_EFFECT && item->active) 2819 if (item->type == SPELL_EFFECT && item->active)
2838 item->destroy (true); 2820 item->destroy ();
2839 2821
2840 item = next; 2822 item = next;
2841 } 2823 }
2842 2824
2843 /*add_exp(op, (op->stats.exp * -0.20)); */ 2825 /*add_exp(op, (op->stats.exp * -0.20)); */
2924 { 2906 {
2925 tmp->decrease (rndm (1, tmp->nrof - 1)); 2907 tmp->decrease (rndm (1, tmp->nrof - 1));
2926 insert_ob_in_map (tmp, op->map, NULL, 0); 2908 insert_ob_in_map (tmp, op->map, NULL, 0);
2927 } 2909 }
2928 else 2910 else
2929 tmp->destroy (true); 2911 tmp->destroy ();
2930 } 2912 }
2931 else 2913 else
2932 insert_ob_in_map (tmp, op->map, NULL, 0); 2914 insert_ob_in_map (tmp, op->map, NULL, 0);
2933 } 2915 }
2934} 2916}
2995 if (op->type == PLAYER) 2977 if (op->type == PLAYER)
2996 new_draw_info_format (NDI_UNIQUE, 0, op, "You cast %s.", &spob->name); 2978 new_draw_info_format (NDI_UNIQUE, 0, op, "You cast %s.", &spob->name);
2997 2979
2998 cast_spell (op, throw_ob, dir, spob, NULL); 2980 cast_spell (op, throw_ob, dir, spob, NULL);
2999 2981
3000 throw_ob->destroy (true); 2982 throw_ob->destroy ();
3001} 2983}
3002 2984
3003void 2985void
3004make_visible (object *op) 2986make_visible (object *op)
3005{ 2987{
3006 op->hide = 0; 2988 op->flag [FLAG_HIDDEN] = 0;
3007 op->invisible = 0; 2989 op->invisible = 0;
3008 2990
3009 if (op->type == PLAYER) 2991 if (op->type == PLAYER)
3010 { 2992 {
3011 op->contr->tmp_invis = 0; 2993 op->contr->tmp_invis = 0;
3036 3018
3037 if (!ob || !ob->map) 3019 if (!ob || !ob->map)
3038 return 0; 3020 return 0;
3039 3021
3040 /* so, on normal lighted maps, its hard to hide */ 3022 /* so, on normal lighted maps, its hard to hide */
3041 level = ob->map->darkness - 2; 3023 level = ob->map->darklevel () - 2;
3042 3024
3043 /* this also picks up whether the object is glowing. 3025 /* this also picks up whether the object is glowing.
3044 * If you carry a light on a non-dark map, its not 3026 * If you carry a light on a non-dark map, its not
3045 * as bad as carrying a light on a pitch dark map */ 3027 * as bad as carrying a light on a pitch dark map */
3046 if (has_carried_lights (ob)) 3028 if (has_carried_lights (ob))
3047 level = -(10 + (2 * ob->map->darkness)); 3029 level = -(10 + (2 * ob->map->darklevel ()));
3048 3030
3049 /* scan through all nearby squares for terrain to hide in */ 3031 /* scan through all nearby squares for terrain to hide in */
3050 for (i = 0, x = ob->x, y = ob->y; 3032 for (i = 0, x = ob->x, y = ob->y;
3051 i <= SIZEOFFREE1; 3033 i <= SIZEOFFREE1;
3052 i++, x = ob->x + freearr_x[i], y = ob->y + freearr_y[i]) 3034 i++, x = ob->x + freearr_x[i], y = ob->y + freearr_y[i])
3199 while (op) 3181 while (op)
3200 { 3182 {
3201 dx = rv.distance_x + op->arch->x; 3183 dx = rv.distance_x + op->arch->x;
3202 dy = rv.distance_y + op->arch->y; 3184 dy = rv.distance_y + op->arch->y;
3203 3185
3204 /* only the viewable area the player sees is updated by LOS 3186 if (pl->contr->blocked_los (dx, dy) != LOS_BLOCKED)
3205 * code, so we need to restrict ourselves to that range of values
3206 * for any meaningful values.
3207 */
3208 if (abs (dx) <= (pl->contr->ns->mapx / 2) &&
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; 3187 return 1;
3212 3188
3213 op = op->more; 3189 op = op->more;
3214 } 3190 }
3215 3191
3216 return 0; 3192 return 0;
3217} 3193}
3218 3194
3219/* routine for both players and monsters. We call this when 3195/* routine for both players and monsters. We call this when
3220 * there is a possibility for our action distrubing our hiding 3196 * there is a possibility for our action distrubing our hiding
3221 * place or invisiblity spell. Artefact invisiblity is not 3197 * place or invisiblity spell. Artefact invisiblity causes
3222 * effected by this. If we arent invisible to begin with, we 3198 * "noise" instead. If we arent invisible to begin with, we
3223 * return 0. 3199 * return 0.
3224 */ 3200 */
3225int 3201int
3226action_makes_visible (object *op) 3202action_makes_visible (object *op)
3227{ 3203{
3228 if (op->invisible && QUERY_FLAG (op, FLAG_ALIVE)) 3204 if (op->invisible && QUERY_FLAG (op, FLAG_ALIVE))
3229 { 3205 {
3230 if (QUERY_FLAG (op, FLAG_MAKE_INVIS)) 3206 if (QUERY_FLAG (op, FLAG_MAKE_INVIS))
3207 {
3208 // artefact invisibility is permanent, but we still make noise
3209 // this is important for game-balance.
3210 if (op->contr)
3211 op->make_noise ();
3212
3231 return 0; 3213 return 0;
3214 }
3232 3215
3233 if (op->contr && op->contr->tmp_invis == 0) 3216 if (op->contr && op->contr->tmp_invis == 0)
3234 return 0; 3217 return 0;
3235 3218
3236 /* If monsters, they should become visible */ 3219 /* If monsters, they should become visible */
3237 if (op->hide || !op->contr || (op->contr && op->contr->tmp_invis)) 3220 if (op->flag [FLAG_HIDDEN] || !op->contr || (op->contr && op->contr->tmp_invis))
3238 { 3221 {
3239 new_draw_info_format (NDI_UNIQUE, 0, op, "You become %s!", op->hide ? "unhidden" : "visible"); 3222 new_draw_info_format (NDI_UNIQUE, 0, op, "You become %s!", op->flag [FLAG_HIDDEN] ? "unhidden" : "visible");
3240 return 1; 3223 return 1;
3241 } 3224 }
3242 } 3225 }
3243 3226
3244 return 0; 3227 return 0;
3472 if (pl->ranged_ob == ob) 3455 if (pl->ranged_ob == ob)
3473 pl->ranged_ob = 0; 3456 pl->ranged_ob = 0;
3474} 3457}
3475 3458
3476sint8 3459sint8
3477player::visibility_at (maptile *map, int x, int y) const 3460player::darkness_at (maptile *map, int x, int y) const
3478{ 3461{
3479 if (!ns) 3462 if (!ns)
3480 return 0; 3463 return LOS_BLOCKED;
3481 3464
3482 int dx, dy; 3465 int dx, dy;
3483 if (!adjacent_map (map, ns->current_map, &dx, &dy)) 3466 if (!adjacent_map (map, ns->current_map, &dx, &dy))
3484 return 0; 3467 return LOS_BLOCKED;
3485 3468
3486 x += dx - ns->current_x + ns->mapx / 2; 3469 x += dx - ns->current_x;
3487 y += dy - ns->current_y + ns->mapy / 2; 3470 y += dy - ns->current_y;
3488 3471
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]; 3472 return blocked_los (x, y);
3493} 3473}
3494 3474
3495void 3475void
3496player::infobox (const char *title, const char *msg, int color) 3476player::infobox (const char *title, const char *msg, int color)
3497{ 3477{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines