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.198 by root, Sat May 17 00:17:02 2008 UTC vs.
Revision 1.218 by root, Sun Dec 28 10:05:42 2008 UTC

122 continue; 122 continue;
123 123
124 if (*buf == '%') 124 if (*buf == '%')
125 { /* send one news */ 125 { /* send one news */
126 if (size > 0) 126 if (size > 0)
127 draw_ext_info_format (NDI_UNIQUE | NDI_GREEN, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_NEWS, "INFORMATION: %s\n%s", (char *)"%s\n%s", subject, news); /*send previously read news */ 127 draw_ext_info_format (NDI_UNIQUE | NDI_GREEN, 0, op,
128 MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_NEWS,
129 "INFORMATION: %s\n%s", (char *)"%s\n%s",
130 subject, news); /*send previously read news */
128 131
129 strcpy (subject, buf + 1); 132 strcpy (subject, buf + 1);
130 strip_endline (subject); 133 strip_endline (subject);
131 size = 0; 134 size = 0;
132 news[0] = '\0'; 135 news[0] = '\0';
207 ob->close_container (); //TODO: client-specific 210 ob->close_container (); //TODO: client-specific
208 211
209 ns->update_look = 0; 212 ns->update_look = 0;
210 ns->look_position = 0; 213 ns->look_position = 0;
211 214
212 clear_los (this); 215 clear_los ();
213 216
214 ns->reset_stats (); 217 ns->reset_stats ();
215 218
216 /* make sure he's a player -- needed because of class change. */ 219 /* make sure he's a player -- needed because of class change. */
217 ob->type = PLAYER; // we are paranoid 220 ob->type = PLAYER; // we are paranoid
218 ob->race = ob->arch->race; 221 ob->race = ob->arch->race;
219 222
220 ob->update_weight (); 223 ob->update_weight ();
221 link_player_skills (ob); 224 link_skills ();
222 225
223 CLEAR_FLAG (ob, FLAG_NO_FIX_PLAYER); 226 CLEAR_FLAG (ob, FLAG_NO_FIX_PLAYER);
224 227
225 assign (title, ob->arch->object::name); 228 assign (title, ob->arch->object::name);
226 229
345 savebed_map = first_map_path; /* Init. respawn position */ 348 savebed_map = first_map_path; /* Init. respawn position */
346 349
347 gen_sp_armour = 10; 350 gen_sp_armour = 10;
348 bowtype = bow_normal; 351 bowtype = bow_normal;
349 petmode = pet_normal; 352 petmode = pet_normal;
350 listening = 10;
351 usekeys = containers; 353 usekeys = containers;
352 peaceful = 1; /* default peaceful */ 354 peaceful = 1; /* default peaceful */
353 do_los = 1; 355 do_los = 1;
354 356
355 weapon_sp = 1.0f; 357 weapon_sp = 1.0f;
726 else /* lock all 'normal items by default */ 728 else /* lock all 'normal items by default */
727 SET_FLAG (op, FLAG_INV_LOCKED); 729 SET_FLAG (op, FLAG_INV_LOCKED);
728 } /* for loop of objects in player inv */ 730 } /* for loop of objects in player inv */
729 731
730 /* Need to set up the skill pointers */ 732 /* Need to set up the skill pointers */
731 link_player_skills (pl); 733 pl->contr->link_skills ();
732} 734}
733 735
734void 736void
735get_party_password (object *op, partylist *party) 737get_party_password (object *op, partylist *party)
736{ 738{
868 ob->msg = 0; 870 ob->msg = 0;
869 871
870 start_info (ob); 872 start_info (ob);
871 CLEAR_FLAG (ob, FLAG_WIZ); 873 CLEAR_FLAG (ob, FLAG_WIZ);
872 give_initial_items (ob, ob->randomitems); 874 give_initial_items (ob, ob->randomitems);
873 link_player_skills (ob);
874 esrv_send_inventory (ob, ob); 875 esrv_send_inventory (ob, ob);
875 ob->update_stats (); 876 ob->update_stats ();
876 877
877 /* This moves the player to a different start map, if there 878 /* This moves the player to a different start map, if there
878 * is one for this race 879 * is one for this race
930 LOG (llevDebug, "Fleeing player is dead.\n"); 931 LOG (llevDebug, "Fleeing player is dead.\n");
931 CLEAR_FLAG (op, FLAG_SCARED); 932 CLEAR_FLAG (op, FLAG_SCARED);
932 return; 933 return;
933 } 934 }
934 935
935 if (op->enemy == NULL) 936 if (!op->enemy)
936 { 937 {
937 LOG (llevDebug, "Fleeing player had no enemy.\n"); 938 LOG (llevDebug, "Fleeing player had no enemy.\n");
938 CLEAR_FLAG (op, FLAG_SCARED); 939 CLEAR_FLAG (op, FLAG_SCARED);
939 return; 940 return;
940 } 941 }
941 942
942 /* Seen some crashes here. Since we don't store an
943 * op->enemy_count, it is possible that something destroys the
944 * actual enemy, and the object is recycled.
945 */
946 if (op->enemy->map == NULL)
947 {
948 CLEAR_FLAG (op, FLAG_SCARED);
949 op->enemy = NULL;
950 return;
951 }
952
953 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))
954 { 944 {
955 op->enemy = NULL; 945 op->enemy = NULL;
956 CLEAR_FLAG (op, FLAG_SCARED); 946 CLEAR_FLAG (op, FLAG_SCARED);
957 return; 947 return;
960 get_rangevector (op, op->enemy, &rv, 0); 950 get_rangevector (op, op->enemy, &rv, 0);
961 951
962 dir = absdir (4 + rv.direction); 952 dir = absdir (4 + rv.direction);
963 for (diff = 0; diff < 3; diff++) 953 for (diff = 0; diff < 3; diff++)
964 { 954 {
965 int m = 1 - (RANDOM () & 2); 955 int m = 1 - rndm (2) * 2;
966 956
967 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)))
968 return; 958 return;
969 } 959 }
970 960
981check_pick (object *op) 971check_pick (object *op)
982{ 972{
983 object *tmp, *next; 973 object *tmp, *next;
984 int stop = 0; 974 int stop = 0;
985 int wvratio; 975 int wvratio;
986 char putstring[128];
987 976
988 /* if you're flying, you cna't pick up anything */ 977 /* if you're flying, you cna't pick up anything */
989 if (op->move_type & MOVE_FLYING) 978 if (op->move_type & MOVE_FLYING)
990 return 1; 979 return 1;
991 980
1015 1004
1016 if (op->contr->search_str[0] != '\0' && settings.search_items == TRUE) 1005 if (op->contr->search_str[0] != '\0' && settings.search_items == TRUE)
1017 { 1006 {
1018 if (item_matched_string (op, tmp, op->contr->search_str)) 1007 if (item_matched_string (op, tmp, op->contr->search_str))
1019 CHK_PICK_PICKUP; 1008 CHK_PICK_PICKUP;
1009
1020 continue; 1010 continue;
1021 } 1011 }
1022 1012
1023 /* high not bit set? We're using the old autopickup model */ 1013 /* high not bit set? We're using the old autopickup model */
1024 if (!(op->contr->mode & PU_NEWMODE)) 1014 if (!(op->contr->mode & PU_NEWMODE))
1064 { /* old model */ 1054 { /* old model */
1065 /* NEW pickup handling */ 1055 /* NEW pickup handling */
1066 if (op->contr->mode & PU_DEBUG) 1056 if (op->contr->mode & PU_DEBUG)
1067 { 1057 {
1068 /* some debugging code to figure out item information */ 1058 /* some debugging code to figure out item information */
1069 if (tmp->name != NULL) 1059 const char *str = tmp->name
1070 sprintf (putstring, "item name: %s item type: %d weight/value: %d", 1060 ? format ("item name: %s item type: %d weight/value: %d",
1071 &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))))
1072 else
1073 sprintf (putstring, "item name: %s item type: %d weight/value: %d", 1062 : format ("item name: %s item type: %d weight/value: %d",
1074 &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))));
1075 1064
1076 new_draw_info (NDI_UNIQUE, 0, op, putstring); 1065 new_draw_info (NDI_UNIQUE, 0, op, str);
1077 } 1066 }
1078 1067
1079 /* philosophy: 1068 /* philosophy:
1080 * 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
1081 * generic. This takes no game-time. For more detailed pickups 1070 * generic. This takes no game-time. For more detailed pickups
1305 if (op->contr->mode & PU_RATIO) 1294 if (op->contr->mode & PU_RATIO)
1306 { 1295 {
1307 /* use value density to decide what else to grab */ 1296 /* use value density to decide what else to grab */
1308 /* >=7 was >= op->contr->mode */ 1297 /* >=7 was >= op->contr->mode */
1309 /* >=7 is the old standard setting. Now we take the last 4 bits 1298 /* >=7 is the old standard setting. Now we take the last 4 bits
1310 * and multiply them by 5, giving 0..15*5== 5..75 */ 1299 */
1311 wvratio = (op->contr->mode & PU_RATIO) * 5; 1300 wvratio = op->contr->mode & PU_RATIO;
1312 if ((query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))) >= (unsigned int) wvratio) 1301 if (1000 * query_cost (tmp, op, F_TRUE) / tmp->total_weight () >= wvratio * 100)
1313 { 1302 {
1314 CHK_PICK_PICKUP; 1303 CHK_PICK_PICKUP;
1315#if 0 1304#if 0
1316 fprintf (stderr, "HIGH WEIGHT/VALUE ["); 1305 fprintf (stderr, "HIGH WEIGHT/VALUE [");
1317 if (tmp->name != NULL) 1306 if (tmp->name != NULL)
1461 for (i = 0, found = 0; i < 20; i++) 1450 for (i = 0, found = 0; i < 20; i++)
1462 { 1451 {
1463 x += freearr_x[dir]; 1452 x += freearr_x[dir];
1464 y += freearr_y[dir]; 1453 y += freearr_y[dir];
1465 mflags = get_map_flags (m, &m, x, y, &x, &y); 1454 mflags = get_map_flags (m, &m, x, y, &x, &y);
1455
1466 if (mflags & P_OUT_OF_MAP || mflags & P_BLOCKSVIEW) 1456 if (mflags & P_OUT_OF_MAP || mflags & P_BLOCKSVIEW)
1467 { 1457 {
1468 tmp = NULL; 1458 tmp = 0;
1469 break; 1459 break;
1470 } 1460 }
1471 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)
1472 { 1462 {
1473 /* This block presumes arrows and the like are MOVE_FLY_SLOW - 1463 /* This block presumes arrows and the like are MOVE_FLY_SLOW -
1474 * perhaps a bad assumption. 1464 * perhaps a bad assumption.
1475 */ 1465 */
1476 tmp = NULL; 1466 tmp = 0;
1477 break; 1467 break;
1478 } 1468 }
1469
1479 if (mflags & P_IS_ALIVE) 1470 if (mflags & P_IS_ALIVE)
1480 {
1481 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)
1482 if (QUERY_FLAG (tmp, FLAG_ALIVE)) 1472 if (QUERY_FLAG (tmp, FLAG_ALIVE))
1483 {
1484 found++;
1485 break;
1486 }
1487 if (found)
1488 break; 1473 break;
1489 }
1490 } 1474 }
1491 if (tmp == NULL) 1475
1476 if (!tmp)
1492 return find_arrow (op, type); 1477 return find_arrow (op, type);
1493 1478
1494 if (tmp->head) 1479 if (tmp->head)
1495 tmp = tmp->head; 1480 tmp = tmp->head;
1496 1481
1541 if (bow->below) 1526 if (bow->below)
1542 { 1527 {
1543 bow->remove (); 1528 bow->remove ();
1544 op->insert (bow); 1529 op->insert (bow);
1545 } 1530 }
1546
1547 } 1531 }
1548 1532
1549 if (!bow->race || !bow->skill) 1533 if (!bow->race || !bow->skill)
1550 { 1534 {
1551 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);
1577 } 1561 }
1578 1562
1579 /* this should not happen, but sometimes does */ 1563 /* this should not happen, but sometimes does */
1580 if (arrow->nrof == 0) 1564 if (arrow->nrof == 0)
1581 { 1565 {
1566 LOG (llevError | logBacktrace, "arrow (%s) has nrof 0\n", arrow->debug_desc ());
1582 arrow->destroy (); 1567 arrow->destroy ();
1583 return 0; 1568 return 0;
1584 } 1569 }
1585 1570
1586 left = arrow; /* these are arrows left to the player */ 1571 left = arrow; /* these are arrows left to the player */
1673 * hence the function name. 1658 * hence the function name.
1674 */ 1659 */
1675int 1660int
1676player_fire_bow (object *op, int dir) 1661player_fire_bow (object *op, int dir)
1677{ 1662{
1678 int ret = 0, wcmod = 0; 1663 int ret;
1679 1664
1680 if (op->contr->bowtype == bow_bestarrow) 1665 if (op->contr->bowtype == bow_bestarrow)
1681 { 1666 {
1682 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);
1683 } 1668 }
1684 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)
1685 { 1670 {
1686 if (!similar_direction (dir, op->contr->bowtype - bow_n + 1)) 1671 int wcmod = similar_direction (dir, op->contr->bowtype - bow_n + 1) ? 0 : -1;
1687 wcmod = -1;
1688
1689 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);
1690 } 1673 }
1691 else if (op->contr->bowtype == bow_threewide) 1674 else if (op->contr->bowtype == bow_threewide)
1692 { 1675 {
1693 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);
1694 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)]);
1695 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)]);
1696 } 1679 }
1697 else if (op->contr->bowtype == bow_spreadshot) 1680 else if (op->contr->bowtype == bow_spreadshot)
1698 { 1681 {
1699 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);
1700 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);
1701 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);
1702 } 1685 }
1703 else 1686 else
1704 { 1687 {
1761 } 1744 }
1762 } 1745 }
1763 1746
1764 if (cast_spell (op, item, dir, item->inv, NULL)) 1747 if (cast_spell (op, item, dir, item->inv, NULL))
1765 { 1748 {
1766 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
1767 if (item->type == WAND) 1751 if (item->type == WAND)
1768 { 1752 {
1769 if (!(--item->stats.food)) 1753 if (!(--item->stats.food))
1770 { 1754 {
1771 object *tmp; 1755 object *tmp;
1791bool 1775bool
1792fire (object *op, int dir) 1776fire (object *op, int dir)
1793{ 1777{
1794 int spellcost = 0; 1778 int spellcost = 0;
1795 1779
1796 /* check for loss of invisiblity/hide */
1797 if (action_makes_visible (op))
1798 make_visible (op);
1799
1800 player *pl = op->contr; 1780 player *pl = op->contr;
1801 1781
1802 if (pl->golem) 1782 if (pl->golem)
1803 { 1783 {
1804 control_golem (op->contr->golem, dir); 1784 control_golem (op->contr->golem, dir);
1806 } 1786 }
1807 1787
1808 object *ob = pl->ranged_ob; 1788 object *ob = pl->ranged_ob;
1809 1789
1810 if (!ob) 1790 if (!ob)
1811 return false;
1812
1813 if (!op->change_weapon (ob))
1814 return false; 1791 return false;
1815 1792
1816 if (op->speed_left > 0.f) 1793 if (op->speed_left > 0.f)
1817 --op->speed_left; 1794 --op->speed_left;
1818 else 1795 else
1819 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);
1820 1804
1821 switch (ob->type) 1805 switch (ob->type)
1822 { 1806 {
1823 case BOW: 1807 case BOW:
1824 player_fire_bow (op, dir); 1808 player_fire_bow (op, dir);
2069 --op->speed_left; 2053 --op->speed_left;
2070 2054
2071 op->play_sound (sound_find ("push_player")); 2055 op->play_sound (sound_find ("push_player"));
2072 push_ob (mon, dir, op); 2056 push_ob (mon, dir, op);
2073 2057
2074 if (op->contr->tmp_invis || op->hide) 2058 if (action_makes_visible (op))
2075 make_visible (op); 2059 make_visible (op);
2076 2060
2077 return true; 2061 return true;
2078 } 2062 }
2079 else 2063 else
2101 push_ob (mon, dir, op); 2085 push_ob (mon, dir, op);
2102 } 2086 }
2103 else 2087 else
2104 op->statusmsg ("You withhold your attack"); 2088 op->statusmsg ("You withhold your attack");
2105 2089
2106 if (op->contr->tmp_invis || op->hide) 2090 if (op->contr->tmp_invis || op->flag [FLAG_HIDDEN])
2107 make_visible (op); 2091 make_visible (op);
2108 2092
2109 return true; 2093 return true;
2110 } 2094 }
2111 } 2095 }
2169 if (QUERY_FLAG (op, FLAG_CONFUSED) && dir) 2153 if (QUERY_FLAG (op, FLAG_CONFUSED) && dir)
2170 dir = absdir (dir + rndm (3) + rndm (3) - 2); 2154 dir = absdir (dir + rndm (3) + rndm (3) - 2);
2171 2155
2172 op->facing = dir; 2156 op->facing = dir;
2173 2157
2174 if (op->hide) 2158 if (op->flag [FLAG_HIDDEN])
2175 do_hidden_move (op); 2159 do_hidden_move (op);
2176 2160
2177 bool retval; 2161 bool retval;
2178 2162
2179 if (INVOKE_PLAYER (MOVE, op->contr, ARG_INT (dir))) 2163 if (INVOKE_PLAYER (MOVE, op->contr, ARG_INT (dir)))
2310const char * 2294const char *
2311gravestone_text (object *op) 2295gravestone_text (object *op)
2312{ 2296{
2313 static dynbuf_text buf; 2297 static dynbuf_text buf;
2314 2298
2315 buf << "---- R.I.P. ----\n\n"; 2299 buf << "---- R.I.P. ----\n\n"
2316 op->name; 2300 << op->name;
2317 2301
2318 if (op->type == PLAYER) 2302 if (op->type == PLAYER)
2319 buf << " the " << op->contr->title; 2303 buf << " the " << op->contr->title;
2320 2304
2321 buf << "\n\n"; 2305 buf << "\n\n";
2497 { 2481 {
2498 over_hp = (gen_hp < 20 ? 30 : gen_hp + 10) / rate_hp; 2482 over_hp = (gen_hp < 20 ? 30 : gen_hp + 10) / rate_hp;
2499 2483
2500 if (over_hp > 0) 2484 if (over_hp > 0)
2501 { 2485 {
2502 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;
2503 op->last_heal = 0; 2487 op->last_heal = 0;
2504 } 2488 }
2505 else 2489 else
2506 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);
2507 } 2491 }
2563 2547
2564 if (op->stats.food < 0) 2548 if (op->stats.food < 0)
2565 { 2549 {
2566 op->stats.hp += op->stats.food; 2550 op->stats.hp += op->stats.food;
2567 op->stats.food = 0; 2551 op->stats.food = 0;
2552
2553 if (op->stats.hp < 0)
2554 {
2555 op->contr->killer = archetype::get ("killer_starvation");
2556 op->contr->killer->destroy ();
2568 } 2557 }
2558 }
2569 2559
2560 /* killer should be set here already */
2570 if (op->stats.hp < 0 && !QUERY_FLAG (op, FLAG_WIZ)) 2561 if (op->stats.hp < 0 && !QUERY_FLAG (op, FLAG_WIZ))
2571 kill_player (op); 2562 kill_player (op);
2572 } 2563 }
2573} 2564}
2574 2565
2643 2634
2644 INVOKE_PLAYER (DEATH, op->contr); 2635 INVOKE_PLAYER (DEATH, op->contr);
2645 2636
2646 command_kill_pets (op, 0); 2637 command_kill_pets (op, 0);
2647 2638
2648 if (op->stats.food < 0)
2649 {
2650 op->contr->killer = archetype::get ("killer_starvation");
2651 op->contr->killer->destroy ();
2652 }
2653
2654 op->contr->play_sound (sound_find ("player_dies")); 2639 op->contr->play_sound (sound_find ("player_dies"));
2655 2640
2656 /* save the map location for corpse, gravestone */ 2641 /* save the map location for corpse, gravestone */
2657 x = op->x; 2642 x = op->x;
2658 y = op->y; 2643 y = op->y;
2687 2672
2688 lost_a_stat = 0; 2673 lost_a_stat = 0;
2689 2674
2690 for (z = 0; z < num_stats_lose; z++) 2675 for (z = 0; z < num_stats_lose; z++)
2691 { 2676 {
2692 i = RANDOM () % NUM_STATS; 2677 i = rndm (NUM_STATS);
2693 2678
2694 if (settings.stat_loss_on_death) 2679 if (settings.stat_loss_on_death)
2695 { 2680 {
2696 /* 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
2697 * what he lost. 2682 * what he lost.
2789 * exp loss on the stone. 2774 * exp loss on the stone.
2790 */ 2775 */
2791 tmp = arch_to_object (archetype::find ("gravestone")); 2776 tmp = arch_to_object (archetype::find ("gravestone"));
2792 tmp->name = format ("%s's gravestone", &op->name); 2777 tmp->name = format ("%s's gravestone", &op->name);
2793 tmp->name_pl = format ("%s's gravestones", &op->name); 2778 tmp->name_pl = format ("%s's gravestones", &op->name);
2794 tmp->msg = format ("RIP\nHere rests the hero %s the %s,\nwho was killed\nby %s.\n", &op->name, op->contr->title, op->contr->killer_name ()); 2779 tmp->msg = format ("T<RIP>\n\nHere rests the hero %s the %s,\rwho was killed\rby %s.\n",
2780 &op->name, op->contr->title, op->contr->killer_name ());
2795 tmp->x = op->x, tmp->y = op->y; 2781 tmp->x = op->x, tmp->y = op->y;
2796 insert_ob_in_map (tmp, op->map, NULL, 0); 2782 insert_ob_in_map (tmp, op->map, NULL, 0);
2797 2783
2798 /**************************************/ 2784 /**************************************/
2799 /* */ 2785 /* */
2887 if (will_kill_again & (1 << at)) 2873 if (will_kill_again & (1 << at))
2888 force->resist[at] = 100; 2874 force->resist[at] = 100;
2889 2875
2890 insert_ob_in_ob (force, op); 2876 insert_ob_in_ob (force, op);
2891 op->update_stats (); 2877 op->update_stats ();
2892
2893 } 2878 }
2894 2879
2895 new_draw_info (NDI_UNIQUE, 0, op, "YOU HAVE DIED."); 2880 new_draw_info (NDI_UNIQUE, 0, op, "YOU HAVE DIED.");
2896} 2881}
2897 2882
2998} 2983}
2999 2984
3000void 2985void
3001make_visible (object *op) 2986make_visible (object *op)
3002{ 2987{
3003 op->hide = 0; 2988 op->flag [FLAG_HIDDEN] = 0;
3004 op->invisible = 0; 2989 op->invisible = 0;
3005 2990
3006 if (op->type == PLAYER) 2991 if (op->type == PLAYER)
3007 { 2992 {
3008 op->contr->tmp_invis = 0; 2993 op->contr->tmp_invis = 0;
3033 3018
3034 if (!ob || !ob->map) 3019 if (!ob || !ob->map)
3035 return 0; 3020 return 0;
3036 3021
3037 /* so, on normal lighted maps, its hard to hide */ 3022 /* so, on normal lighted maps, its hard to hide */
3038 level = ob->map->darkness - 2; 3023 level = ob->map->darklevel () - 2;
3039 3024
3040 /* this also picks up whether the object is glowing. 3025 /* this also picks up whether the object is glowing.
3041 * 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
3042 * as bad as carrying a light on a pitch dark map */ 3027 * as bad as carrying a light on a pitch dark map */
3043 if (has_carried_lights (ob)) 3028 if (has_carried_lights (ob))
3044 level = -(10 + (2 * ob->map->darkness)); 3029 level = -(10 + (2 * ob->map->darklevel ()));
3045 3030
3046 /* scan through all nearby squares for terrain to hide in */ 3031 /* scan through all nearby squares for terrain to hide in */
3047 for (i = 0, x = ob->x, y = ob->y; 3032 for (i = 0, x = ob->x, y = ob->y;
3048 i <= SIZEOFFREE1; 3033 i <= SIZEOFFREE1;
3049 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])
3196 while (op) 3181 while (op)
3197 { 3182 {
3198 dx = rv.distance_x + op->arch->x; 3183 dx = rv.distance_x + op->arch->x;
3199 dy = rv.distance_y + op->arch->y; 3184 dy = rv.distance_y + op->arch->y;
3200 3185
3201 /* only the viewable area the player sees is updated by LOS 3186 if (pl->contr->blocked_los (dx, dy) != LOS_BLOCKED)
3202 * code, so we need to restrict ourselves to that range of values
3203 * for any meaningful values.
3204 */
3205 if (abs (dx) <= (pl->contr->ns->mapx / 2) &&
3206 abs (dy) <= (pl->contr->ns->mapy / 2) &&
3207 !pl->contr->blocked_los[dx + (pl->contr->ns->mapx / 2)][dy + (pl->contr->ns->mapy / 2)])
3208 return 1; 3187 return 1;
3209 3188
3210 op = op->more; 3189 op = op->more;
3211 } 3190 }
3212 3191
3213 return 0; 3192 return 0;
3214} 3193}
3215 3194
3216/* routine for both players and monsters. We call this when 3195/* routine for both players and monsters. We call this when
3217 * there is a possibility for our action distrubing our hiding 3196 * there is a possibility for our action distrubing our hiding
3218 * place or invisiblity spell. Artefact invisiblity is not 3197 * place or invisiblity spell. Artefact invisiblity causes
3219 * effected by this. If we arent invisible to begin with, we 3198 * "noise" instead. If we arent invisible to begin with, we
3220 * return 0. 3199 * return 0.
3221 */ 3200 */
3222int 3201int
3223action_makes_visible (object *op) 3202action_makes_visible (object *op)
3224{ 3203{
3225 if (op->invisible && QUERY_FLAG (op, FLAG_ALIVE)) 3204 if (op->invisible && QUERY_FLAG (op, FLAG_ALIVE))
3226 { 3205 {
3227 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
3228 return 0; 3213 return 0;
3214 }
3229 3215
3230 if (op->contr && op->contr->tmp_invis == 0) 3216 if (op->contr && op->contr->tmp_invis == 0)
3231 return 0; 3217 return 0;
3232 3218
3233 /* If monsters, they should become visible */ 3219 /* If monsters, they should become visible */
3234 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))
3235 { 3221 {
3236 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");
3237 return 1; 3223 return 1;
3238 } 3224 }
3239 } 3225 }
3240 3226
3241 return 0; 3227 return 0;
3469 if (pl->ranged_ob == ob) 3455 if (pl->ranged_ob == ob)
3470 pl->ranged_ob = 0; 3456 pl->ranged_ob = 0;
3471} 3457}
3472 3458
3473sint8 3459sint8
3474player::visibility_at (maptile *map, int x, int y) const 3460player::darkness_at (maptile *map, int x, int y) const
3475{ 3461{
3476 if (!ns) 3462 if (!ns)
3477 return 0; 3463 return LOS_BLOCKED;
3478 3464
3479 int dx, dy; 3465 int dx, dy;
3480 if (!adjacent_map (map, ns->current_map, &dx, &dy)) 3466 if (!adjacent_map (map, ns->current_map, &dx, &dy))
3481 return 0; 3467 return LOS_BLOCKED;
3482 3468
3483 x += dx - ns->current_x + ns->mapx / 2; 3469 x += dx - ns->current_x;
3484 y += dy - ns->current_y + ns->mapy / 2; 3470 y += dy - ns->current_y;
3485 3471
3486 if (!IN_RANGE_EXC (x, 0, ns->mapx) || !IN_RANGE_EXC (y, 0, ns->mapy))
3487 return 0;
3488
3489 return 100 - blocked_los [x][y]; 3472 return blocked_los (x, y);
3490} 3473}
3491 3474
3492void 3475void
3493player::infobox (const char *title, const char *msg, int color) 3476player::infobox (const char *title, const char *msg, int color)
3494{ 3477{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines