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.187 by root, Mon Apr 21 07:07:36 2008 UTC vs.
Revision 1.215 by root, Sat Dec 27 08:01:07 2008 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * Deliantra is free software: you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
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
239 set_dragon_name (ob, abil, skin); 242 set_dragon_name (ob, abil, skin);
240 } 243 }
241 244
242 new_draw_info (NDI_UNIQUE, 0, ob, "Welcome Back!"); 245 new_draw_info (NDI_UNIQUE, 0, ob, "Welcome Back!");
243 246
244 esrv_new_player (this, ob->weight + ob->carrying); 247 esrv_new_player (this);
245 248
246 ob->update_stats (); 249 ob->update_stats ();
247 250
248 ns->floorbox_update (); 251 ns->floorbox_update ();
249 esrv_send_inventory (ob, ob); 252 esrv_send_inventory (ob, ob);
291player::set_object (object *op) 294player::set_object (object *op)
292{ 295{
293 ob = observe = op; 296 ob = observe = op;
294 ob->contr = this; /* this aren't yet in archetype */ 297 ob->contr = this; /* this aren't yet in archetype */
295 298
296 ob->speed = 1.0f; 299 ob->speed = 1.0f;
297 ob->speed_left = 0.5f; 300 ob->speed_left = 0.5f;
298 301
299 ob->direction = 5; /* So player faces south */ 302 ob->direction = 5; /* So player faces south */
300 303
301 ob->flag [FLAG_READY_WEAPON] = false; 304 ob->flag [FLAG_READY_WEAPON] = false;
302 ob->flag [FLAG_READY_SKILL] = false; 305 ob->flag [FLAG_READY_SKILL] = false;
303 ob->flag [FLAG_READY_BOW] = false; 306 ob->flag [FLAG_READY_BOW] = false;
304 307
321 combat_ob = op; 324 combat_ob = op;
322 break; 325 break;
323 } 326 }
324 327
325 ob->change_weapon (combat_ob ? combat_ob : ranged_ob); 328 ob->change_weapon (combat_ob ? combat_ob : ranged_ob);
326 ob->deactivate (); // change_Weapon activates, fix this better 329 ob->deactivate (); // change_weapon activates, fix this better
327} 330}
328 331
329void 332void
330player::set_observe (object *op) 333player::set_observe (object *op)
331{ 334{
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{
851 */ 853 */
852void 854void
853player::chargen_race_done () 855player::chargen_race_done ()
854{ 856{
855 /* this must before then initial items are given */ 857 /* this must before then initial items are given */
856 esrv_new_player (ob->contr, ob->weight + ob->carrying); 858 esrv_new_player (ob->contr);
857 859
858 treasurelist *tl = treasurelist::find ("starting_wealth"); 860 treasurelist *tl = treasurelist::find ("starting_wealth");
859 if (tl) 861 if (tl)
860 create_treasure (tl, ob, 0, 0, 0); 862 create_treasure (tl, ob, 0, 0, 0);
861 863
865 ob->contr->ns->state = ST_PLAYING; 867 ob->contr->ns->state = ST_PLAYING;
866 868
867 if (ob->msg) 869 if (ob->msg)
868 ob->msg = 0; 870 ob->msg = 0;
869 871
870 /* We create this now because some of the unique maps will need it
871 * to save here.
872 */
873 {
874 char buf[MAX_BUF];
875 sprintf (buf, "%s/%s/%s", settings.localdir, settings.playerdir, &ob->name);
876 make_path_to_file (buf);
877 }
878
879 start_info (ob); 872 start_info (ob);
880 CLEAR_FLAG (ob, FLAG_WIZ); 873 CLEAR_FLAG (ob, FLAG_WIZ);
881 give_initial_items (ob, ob->randomitems); 874 give_initial_items (ob, ob->randomitems);
882 link_player_skills (ob);
883 esrv_send_inventory (ob, ob); 875 esrv_send_inventory (ob, ob);
884 ob->update_stats (); 876 ob->update_stats ();
885 877
886 /* This moves the player to a different start map, if there 878 /* This moves the player to a different start map, if there
887 * is one for this race 879 * is one for this race
888 */ 880 */
889 if (*first_map_ext_path) 881 if (*first_map_ext_path)
890 { 882 ob->player_goto (format ("%s/%s", &first_map_ext_path, &ob->arch->archname), ob->x, ob->y);
891 object *tmp;
892 char mapname[MAX_BUF];
893
894 snprintf (mapname, MAX_BUF - 1, "%s/%s", &first_map_ext_path, &ob->arch->archname);
895 tmp = object::create ();
896 EXIT_PATH (tmp) = mapname;
897 EXIT_X (tmp) = ob->x;
898 EXIT_Y (tmp) = ob->y;
899 ob->enter_exit (tmp); /* we don't really care if it succeeded;
900 * if the map isn't there, then stay on the
901 * default initial map */
902 tmp->destroy ();
903 }
904 else 883 else
905 LOG (llevDebug, "first_map_ext_path not set\n"); 884 LOG (llevDebug, "first_map_ext_path not set\n");
906} 885}
907 886
908void 887void
952 LOG (llevDebug, "Fleeing player is dead.\n"); 931 LOG (llevDebug, "Fleeing player is dead.\n");
953 CLEAR_FLAG (op, FLAG_SCARED); 932 CLEAR_FLAG (op, FLAG_SCARED);
954 return; 933 return;
955 } 934 }
956 935
957 if (op->enemy == NULL) 936 if (!op->enemy)
958 { 937 {
959 LOG (llevDebug, "Fleeing player had no enemy.\n"); 938 LOG (llevDebug, "Fleeing player had no enemy.\n");
960 CLEAR_FLAG (op, FLAG_SCARED); 939 CLEAR_FLAG (op, FLAG_SCARED);
961 return; 940 return;
962 } 941 }
963 942
964 /* Seen some crashes here. Since we don't store an
965 * op->enemy_count, it is possible that something destroys the
966 * actual enemy, and the object is recycled.
967 */
968 if (op->enemy->map == NULL)
969 {
970 CLEAR_FLAG (op, FLAG_SCARED);
971 op->enemy = NULL;
972 return;
973 }
974
975 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))
976 { 944 {
977 op->enemy = NULL; 945 op->enemy = NULL;
978 CLEAR_FLAG (op, FLAG_SCARED); 946 CLEAR_FLAG (op, FLAG_SCARED);
979 return; 947 return;
982 get_rangevector (op, op->enemy, &rv, 0); 950 get_rangevector (op, op->enemy, &rv, 0);
983 951
984 dir = absdir (4 + rv.direction); 952 dir = absdir (4 + rv.direction);
985 for (diff = 0; diff < 3; diff++) 953 for (diff = 0; diff < 3; diff++)
986 { 954 {
987 int m = 1 - (RANDOM () & 2); 955 int m = 1 - rndm (2) * 2;
988 956
989 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)))
990 return; 958 return;
991 } 959 }
992 960
1037 1005
1038 if (op->contr->search_str[0] != '\0' && settings.search_items == TRUE) 1006 if (op->contr->search_str[0] != '\0' && settings.search_items == TRUE)
1039 { 1007 {
1040 if (item_matched_string (op, tmp, op->contr->search_str)) 1008 if (item_matched_string (op, tmp, op->contr->search_str))
1041 CHK_PICK_PICKUP; 1009 CHK_PICK_PICKUP;
1010
1042 continue; 1011 continue;
1043 } 1012 }
1044 1013
1045 /* high not bit set? We're using the old autopickup model */ 1014 /* high not bit set? We're using the old autopickup model */
1046 if (!(op->contr->mode & PU_NEWMODE)) 1015 if (!(op->contr->mode & PU_NEWMODE))
1327 if (op->contr->mode & PU_RATIO) 1296 if (op->contr->mode & PU_RATIO)
1328 { 1297 {
1329 /* use value density to decide what else to grab */ 1298 /* use value density to decide what else to grab */
1330 /* >=7 was >= op->contr->mode */ 1299 /* >=7 was >= op->contr->mode */
1331 /* >=7 is the old standard setting. Now we take the last 4 bits 1300 /* >=7 is the old standard setting. Now we take the last 4 bits
1332 * and multiply them by 5, giving 0..15*5== 5..75 */ 1301 */
1333 wvratio = (op->contr->mode & PU_RATIO) * 5; 1302 wvratio = op->contr->mode & PU_RATIO;
1334 if ((query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))) >= (unsigned int) wvratio) 1303 if (1000 * query_cost (tmp, op, F_TRUE) / tmp->total_weight () >= wvratio * 100)
1335 { 1304 {
1336 CHK_PICK_PICKUP; 1305 CHK_PICK_PICKUP;
1337#if 0 1306#if 0
1338 fprintf (stderr, "HIGH WEIGHT/VALUE ["); 1307 fprintf (stderr, "HIGH WEIGHT/VALUE [");
1339 if (tmp->name != NULL) 1308 if (tmp->name != NULL)
1405 } 1374 }
1406 } 1375 }
1407 else if (arrow->type == ARROW && arrow->race == type) 1376 else if (arrow->type == ARROW && arrow->race == type)
1408 { 1377 {
1409 /* allways prefer assasination/slaying */ 1378 /* allways prefer assasination/slaying */
1410 if (target->race != NULL && arrow->slaying != NULL && strstr (arrow->slaying, target->race)) 1379 if (target->race && arrow->slaying && strstr (arrow->slaying, target->race))
1411 { 1380 {
1412 if (arrow->attacktype & AT_DEATH) 1381 if (arrow->attacktype & AT_DEATH)
1413 { 1382 {
1414 *better = 100; 1383 *better = 100;
1415 return arrow; 1384 return arrow;
1443 betterby = 1 + arrow->magic + arrow->stats.dam; 1412 betterby = 1 + arrow->magic + arrow->stats.dam;
1444 } 1413 }
1445 } 1414 }
1446 } 1415 }
1447 } 1416 }
1417
1448 if (tmp == NULL && arrow == NULL) 1418 if (tmp == NULL && arrow == NULL)
1449 return find_arrow (op, type); 1419 return find_arrow (op, type);
1450 1420
1451 *better = betterby; 1421 *better = betterby;
1452 return tmp; 1422 return tmp;
1482 for (i = 0, found = 0; i < 20; i++) 1452 for (i = 0, found = 0; i < 20; i++)
1483 { 1453 {
1484 x += freearr_x[dir]; 1454 x += freearr_x[dir];
1485 y += freearr_y[dir]; 1455 y += freearr_y[dir];
1486 mflags = get_map_flags (m, &m, x, y, &x, &y); 1456 mflags = get_map_flags (m, &m, x, y, &x, &y);
1457
1487 if (mflags & P_OUT_OF_MAP || mflags & P_BLOCKSVIEW) 1458 if (mflags & P_OUT_OF_MAP || mflags & P_BLOCKSVIEW)
1488 { 1459 {
1489 tmp = NULL; 1460 tmp = 0;
1490 break; 1461 break;
1491 } 1462 }
1492 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)
1493 { 1464 {
1494 /* This block presumes arrows and the like are MOVE_FLY_SLOW - 1465 /* This block presumes arrows and the like are MOVE_FLY_SLOW -
1495 * perhaps a bad assumption. 1466 * perhaps a bad assumption.
1496 */ 1467 */
1497 tmp = NULL; 1468 tmp = 0;
1498 break; 1469 break;
1499 } 1470 }
1471
1500 if (mflags & P_IS_ALIVE) 1472 if (mflags & P_IS_ALIVE)
1501 {
1502 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)
1503 if (QUERY_FLAG (tmp, FLAG_ALIVE)) 1474 if (QUERY_FLAG (tmp, FLAG_ALIVE))
1504 {
1505 found++;
1506 break;
1507 }
1508 if (found)
1509 break; 1475 break;
1510 }
1511 } 1476 }
1512 if (tmp == NULL) 1477
1478 if (!tmp)
1513 return find_arrow (op, type); 1479 return find_arrow (op, type);
1514 1480
1515 if (tmp->head) 1481 if (tmp->head)
1516 tmp = tmp->head; 1482 tmp = tmp->head;
1517 1483
1562 if (bow->below) 1528 if (bow->below)
1563 { 1529 {
1564 bow->remove (); 1530 bow->remove ();
1565 op->insert (bow); 1531 op->insert (bow);
1566 } 1532 }
1567
1568 } 1533 }
1569 1534
1570 if (!bow->race || !bow->skill) 1535 if (!bow->race || !bow->skill)
1571 { 1536 {
1572 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);
1598 } 1563 }
1599 1564
1600 /* this should not happen, but sometimes does */ 1565 /* this should not happen, but sometimes does */
1601 if (arrow->nrof == 0) 1566 if (arrow->nrof == 0)
1602 { 1567 {
1568 LOG (llevError | logBacktrace, "arrow (%s) has nrof 0\n", arrow->debug_desc ());
1603 arrow->destroy (); 1569 arrow->destroy ();
1604 return 0; 1570 return 0;
1605 } 1571 }
1606 1572
1607 left = arrow; /* these are arrows left to the player */ 1573 left = arrow; /* these are arrows left to the player */
1694 * hence the function name. 1660 * hence the function name.
1695 */ 1661 */
1696int 1662int
1697player_fire_bow (object *op, int dir) 1663player_fire_bow (object *op, int dir)
1698{ 1664{
1699 int ret = 0, wcmod = 0; 1665 int ret;
1700 1666
1701 if (op->contr->bowtype == bow_bestarrow) 1667 if (op->contr->bowtype == bow_bestarrow)
1702 { 1668 {
1703 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);
1704 } 1670 }
1705 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)
1706 { 1672 {
1707 if (!similar_direction (dir, op->contr->bowtype - bow_n + 1)) 1673 int wcmod = similar_direction (dir, op->contr->bowtype - bow_n + 1) ? 0 : -1;
1708 wcmod = -1;
1709
1710 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);
1711 } 1675 }
1712 else if (op->contr->bowtype == bow_threewide) 1676 else if (op->contr->bowtype == bow_threewide)
1713 { 1677 {
1714 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);
1715 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)]);
1716 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)]);
1717 } 1681 }
1718 else if (op->contr->bowtype == bow_spreadshot) 1682 else if (op->contr->bowtype == bow_spreadshot)
1719 { 1683 {
1720 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);
1721 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);
1722 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);
1723 } 1687 }
1724 else 1688 else
1725 { 1689 {
1763 return; 1727 return;
1764 } 1728 }
1765 } 1729 }
1766 else if (item->type == ROD || item->type == HORN) 1730 else if (item->type == ROD || item->type == HORN)
1767 { 1731 {
1768 if (item->stats.hp < MAX (item->inv->stats.sp, item->inv->stats.grace)) 1732 sint16 spell_sp = MAX (item->inv->stats.sp, item->inv->stats.grace);
1733
1734 // using the maximum of the rods charge allows at least one spell cast
1735 // for a rod or horn, this fixes some broken rods.
1736 if (item->stats.hp < MIN (spell_sp, item->stats.maxhp))
1769 { 1737 {
1770 op->contr->play_sound (sound_find ("wand_poof")); 1738 op->contr->play_sound (sound_find ("wand_poof"));
1771 1739
1772 if (item->type == ROD) 1740 if (item->type == ROD)
1773 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s whines for a while, but nothing happens.", query_base_name (item, 0)); 1741 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s whines for a while, but nothing happens.", query_base_name (item, 0));
1778 } 1746 }
1779 } 1747 }
1780 1748
1781 if (cast_spell (op, item, dir, item->inv, NULL)) 1749 if (cast_spell (op, item, dir, item->inv, NULL))
1782 { 1750 {
1783 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
1784 if (item->type == WAND) 1753 if (item->type == WAND)
1785 { 1754 {
1786 if (!(--item->stats.food)) 1755 if (!(--item->stats.food))
1787 { 1756 {
1788 object *tmp; 1757 object *tmp;
1792 CLEAR_FLAG (item, FLAG_ANIMATE); 1761 CLEAR_FLAG (item, FLAG_ANIMATE);
1793 item->face = item->arch->face; 1762 item->face = item->arch->face;
1794 item->set_speed (0); 1763 item->set_speed (0);
1795 } 1764 }
1796 1765
1797 if ((tmp = item->in_player ())) 1766 if (object *pl = item->visible_to ())
1798 esrv_update_item (UPD_ANIM, tmp, item); 1767 esrv_update_item (UPD_ANIM, pl, item);
1799 } 1768 }
1800 } 1769 }
1801 else if (item->type == ROD || item->type == HORN) 1770 else if (item->type == ROD || item->type == HORN)
1802 drain_rod_charge (item); 1771 drain_rod_charge (item);
1803 } 1772 }
1808bool 1777bool
1809fire (object *op, int dir) 1778fire (object *op, int dir)
1810{ 1779{
1811 int spellcost = 0; 1780 int spellcost = 0;
1812 1781
1813 /* check for loss of invisiblity/hide */
1814 if (action_makes_visible (op))
1815 make_visible (op);
1816
1817 player *pl = op->contr; 1782 player *pl = op->contr;
1818 1783
1819 if (pl->golem) 1784 if (pl->golem)
1820 { 1785 {
1821 control_golem (op->contr->golem, dir); 1786 control_golem (op->contr->golem, dir);
1823 } 1788 }
1824 1789
1825 object *ob = pl->ranged_ob; 1790 object *ob = pl->ranged_ob;
1826 1791
1827 if (!ob) 1792 if (!ob)
1828 return false;
1829
1830 if (!op->change_weapon (ob))
1831 return false; 1793 return false;
1832 1794
1833 if (op->speed_left > 0.f) 1795 if (op->speed_left > 0.f)
1834 --op->speed_left; 1796 --op->speed_left;
1835 else 1797 else
1836 return false; 1798 return false;
1799
1800 if (!op->change_weapon (ob))
1801 return false;
1802
1803 /* check for loss of invisiblity/hide */
1804 if (action_makes_visible (op))
1805 make_visible (op);
1837 1806
1838 switch (ob->type) 1807 switch (ob->type)
1839 { 1808 {
1840 case BOW: 1809 case BOW:
1841 player_fire_bow (op, dir); 1810 player_fire_bow (op, dir);
1980 remove_door2 (door); /* remove door without violence ;-) */ 1949 remove_door2 (door); /* remove door without violence ;-) */
1981 } 1950 }
1982 1951
1983 /* Do this after we print the message */ 1952 /* Do this after we print the message */
1984 key->decrease (); /* Use up one of the keys */ 1953 key->decrease (); /* Use up one of the keys */
1985 /* Need to update the weight the container the key was in */
1986 if (container != op)
1987 esrv_update_item (UPD_WEIGHT, op, container);
1988 1954
1989 return 1; /* Nothing more to do below */ 1955 return 1; /* Nothing more to do below */
1990 } 1956 }
1991 else if (door->type == LOCKED_DOOR) 1957 else if (door->type == LOCKED_DOOR)
1992 { 1958 {
2089 --op->speed_left; 2055 --op->speed_left;
2090 2056
2091 op->play_sound (sound_find ("push_player")); 2057 op->play_sound (sound_find ("push_player"));
2092 push_ob (mon, dir, op); 2058 push_ob (mon, dir, op);
2093 2059
2094 if (op->contr->tmp_invis || op->hide) 2060 if (action_makes_visible (op))
2095 make_visible (op); 2061 make_visible (op);
2096 2062
2097 return true; 2063 return true;
2098 } 2064 }
2099 else 2065 else
2121 push_ob (mon, dir, op); 2087 push_ob (mon, dir, op);
2122 } 2088 }
2123 else 2089 else
2124 op->statusmsg ("You withhold your attack"); 2090 op->statusmsg ("You withhold your attack");
2125 2091
2126 if (op->contr->tmp_invis || op->hide) 2092 if (op->contr->tmp_invis || op->flag [FLAG_HIDDEN])
2127 make_visible (op); 2093 make_visible (op);
2128 2094
2129 return true; 2095 return true;
2130 } 2096 }
2131 } 2097 }
2189 if (QUERY_FLAG (op, FLAG_CONFUSED) && dir) 2155 if (QUERY_FLAG (op, FLAG_CONFUSED) && dir)
2190 dir = absdir (dir + rndm (3) + rndm (3) - 2); 2156 dir = absdir (dir + rndm (3) + rndm (3) - 2);
2191 2157
2192 op->facing = dir; 2158 op->facing = dir;
2193 2159
2194 if (op->hide) 2160 if (op->flag [FLAG_HIDDEN])
2195 do_hidden_move (op); 2161 do_hidden_move (op);
2196 2162
2197 bool retval; 2163 bool retval;
2198 2164
2199 if (INVOKE_PLAYER (MOVE, op->contr, ARG_INT (dir))) 2165 if (INVOKE_PLAYER (MOVE, op->contr, ARG_INT (dir)))
2271 if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE)) 2237 if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE))
2272 { 2238 {
2273 op->play_sound (sound_find ("ob_evaporate")); 2239 op->play_sound (sound_find ("ob_evaporate"));
2274 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s vibrates violently, then evaporates.", query_name (tmp)); 2240 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s vibrates violently, then evaporates.", query_name (tmp));
2275 2241
2276 if (op->contr)
2277 esrv_del_item (op->contr, tmp->count);
2278
2279 tmp->destroy (); 2242 tmp->destroy ();
2280 CLEAR_FLAG (op, FLAG_LIFESAVE); 2243 CLEAR_FLAG (op, FLAG_LIFESAVE);
2281 2244
2282 if (op->stats.hp < 0) 2245 if (op->stats.hp < 0)
2283 op->stats.hp = op->stats.maxhp; 2246 op->stats.hp = op->stats.maxhp;
2295 return 0; 2258 return 0;
2296} 2259}
2297 2260
2298/* This goes throws the inventory and removes unpaid objects, and puts them 2261/* This goes throws the inventory and removes unpaid objects, and puts them
2299 * back in the map (location and map determined by values of env). This 2262 * back in the map (location and map determined by values of env). This
2300 * function will descend into containers. op is the object to start the search 2263 * function will descend into containers. op is the object to start the search
2301 * from. 2264 * from.
2302 */ 2265 */
2303static void 2266static void
2304drop_unpaid_items (object *op, object *env) 2267drop_unpaid_items (object *op, object *env)
2305{ 2268{
2306 while (op) 2269 while (op)
2307 { 2270 {
2308 object *next = op->below; /* Make sure we have a good value, in case we remove object 'op' */ 2271 object *next = op->below; /* Make sure we have a good value, in case we remove object 'op' */
2309 2272
2310 if (QUERY_FLAG (op, FLAG_UNPAID)) 2273 if (QUERY_FLAG (op, FLAG_UNPAID))
2311 {
2312 if (env->type == PLAYER)
2313 esrv_del_item (env->contr, op->count);
2314
2315 op->insert_at (env); 2274 op->insert_at (env);
2316 }
2317 else if (op->inv) 2275 else if (op->inv)
2318 drop_unpaid_items (op->inv, env); 2276 drop_unpaid_items (op->inv, env);
2319 2277
2320 op = next; 2278 op = next;
2321 } 2279 }
2333 * Moved from apply.c to player.c - player.c is what 2291 * Moved from apply.c to player.c - player.c is what
2334 * actually uses this function. player.c may not be quite the 2292 * actually uses this function. player.c may not be quite the
2335 * best, a misc file for object actions is probably better, 2293 * best, a misc file for object actions is probably better,
2336 * but there isn't one in the server directory. 2294 * but there isn't one in the server directory.
2337 */ 2295 */
2338char * 2296const char *
2339gravestone_text (object *op) 2297gravestone_text (object *op)
2340{ 2298{
2341 static char buf2[MAX_BUF]; 2299 static dynbuf_text buf;
2342 char buf[MAX_BUF];
2343 time_t now = time (NULL);
2344 2300
2345 strcpy (buf2, " R.I.P.\n\n"); 2301 buf << "---- R.I.P. ----\n\n"
2302 << op->name;
2303
2346 if (op->type == PLAYER) 2304 if (op->type == PLAYER)
2347 sprintf (buf, "%s the %s\n", &op->name, op->contr->title); 2305 buf << " the " << op->contr->title;
2348 else
2349 sprintf (buf, "%s\n", &op->name);
2350 2306
2351 strncat (buf2, " ", 20 - strlen (buf) / 2); 2307 buf << "\n\n";
2352 strcat (buf2, buf); 2308
2309 buf << "who was level ";
2310 buf << (sint32)op->level << "\n\n" // OO breakdown
2311 << " when " << (op->contr ? "killed" : "died") << "\n\n";
2312
2353 if (op->type == PLAYER) 2313 if (op->type == PLAYER)
2354 sprintf (buf, "who was in level %d when killed\n", op->level); 2314 buf << "by " << op->contr->killer_name () << ".\n\n";
2355 else
2356 sprintf (buf, "who was in level %d when died.\n\n", op->level);
2357 2315
2358 strncat (buf2, " ", 20 - strlen (buf) / 2);
2359 strcat (buf2, buf);
2360 if (op->type == PLAYER)
2361 { 2316 {
2362 sprintf (buf, "by %s.\n\n", op->contr->killer); 2317 static char buf2[128];
2363 strncat (buf2, " ", 21 - strlen (buf) / 2); 2318 time_t now = time (NULL);
2364 strcat (buf2, buf);
2365 }
2366
2367 strftime (buf, MAX_BUF, "%b %d %Y\n", localtime (&now)); 2319 strftime (buf2, 128, "%b %d %Y\n\n", localtime (&now));
2368 strncat (buf2, " ", 20 - strlen (buf) / 2); 2320 buf << buf2;
2369 strcat (buf2, buf); 2321 }
2370 2322
2371 return buf2; 2323 return buf;
2372} 2324}
2373 2325
2374void 2326void
2375do_some_living (object *op) 2327do_some_living (object *op)
2376{ 2328{
2531 { 2483 {
2532 over_hp = (gen_hp < 20 ? 30 : gen_hp + 10) / rate_hp; 2484 over_hp = (gen_hp < 20 ? 30 : gen_hp + 10) / rate_hp;
2533 2485
2534 if (over_hp > 0) 2486 if (over_hp > 0)
2535 { 2487 {
2536 op->stats.sp += over_hp + (RANDOM () % rate_hp > ((gen_hp < 20 ? 30 : gen_hp + 10) % rate_hp)) ? -1 : 0; 2488 op->stats.sp += over_hp + (rndm (rate_hp) > ((gen_hp < 20 ? 30 : gen_hp + 10) % rate_hp)) ? -1 : 0;
2537 op->last_heal = 0; 2489 op->last_heal = 0;
2538 } 2490 }
2539 else 2491 else
2540 op->last_heal = rate_hp / (gen_hp < 20 ? 30 : gen_hp + 10); 2492 op->last_heal = rate_hp / (gen_hp < 20 ? 30 : gen_hp + 10);
2541 } 2493 }
2557 op->stats.food--; 2509 op->stats.food--;
2558 } 2510 }
2559 2511
2560 if (op->stats.food < 0 && op->stats.hp >= 0) 2512 if (op->stats.food < 0 && op->stats.hp >= 0)
2561 { 2513 {
2562 object *tmp, *flesh = 0; 2514 object *flesh = 0;
2563 2515
2564 for (tmp = op->inv; tmp; tmp = tmp->below) 2516 for_inv_removable (op, tmp)
2565 { 2517 {
2566 if (!QUERY_FLAG (tmp, FLAG_UNPAID)) 2518 if (QUERY_FLAG (tmp, FLAG_UNPAID))
2519 continue;
2520
2521 if (tmp->type == FOOD || tmp->type == DRINK || tmp->type == POISON)
2567 { 2522 {
2568 if (tmp->type == FOOD || tmp->type == DRINK || tmp->type == POISON) 2523 op->statusmsg ("You blindly grab for a bite of food. "
2569 { 2524 "H<To prevent you from starving, you ate some random item from your backpack.>");
2570 new_draw_info (NDI_UNIQUE, 0, op, "You blindly grab for a bite of food.");
2571 manual_apply (op, tmp, 0); 2525 manual_apply (op, tmp, 0);
2526
2572 if (op->stats.food >= 0 || op->stats.hp < 0) 2527 if (op->stats.food >= 0 || op->stats.hp < 0)
2573 break; 2528 break;
2574 } 2529 }
2575 else if (tmp->type == FLESH) 2530 else if (tmp->type == FLESH)
2576 flesh = tmp; 2531 flesh = tmp;
2577 } /* End if paid for object */ 2532 }
2578 } /* end of for loop */
2579 2533
2580 /* If player is still starving, it means they don't have any food, so 2534 /* If player is still starving, it means they don't have any food, so
2581 * eat flesh instead. 2535 * eat flesh instead.
2582 */ 2536 */
2583 if (op->stats.food < 0 && op->stats.hp >= 0 && flesh) 2537 if (op->stats.food < 0 && op->stats.hp >= 0 && flesh)
2584 { 2538 {
2585 new_draw_info (NDI_UNIQUE, 0, op, "You blindly grab for a bite of food."); 2539 op->statusmsg ("You blindly grab for a bite of food. "
2540 "H<To prevent you from starving, you ate some random item from your backpack.>");
2586 manual_apply (op, flesh, 0); 2541 manual_apply (op, flesh, 0);
2587 } 2542 }
2543
2544 // If player is still starving, alert him!
2545 if (op->stats.food < 0)
2546 op->failmsg ("You are starving! "
2547 "H<Eat some food to increase your food and prevent you from an untimely death.>");
2588 } 2548 }
2589 2549
2590 if (op->stats.food < 0) 2550 if (op->stats.food < 0)
2591 { 2551 {
2592 op->stats.hp += op->stats.food; 2552 op->stats.hp += op->stats.food;
2593 op->stats.food = 0; 2553 op->stats.food = 0;
2554
2555 if (op->stats.hp < 0)
2556 {
2557 op->contr->killer = archetype::get ("killer_starvation");
2558 op->contr->killer->destroy ();
2594 } 2559 }
2560 }
2595 2561
2562 /* killer should be set here already */
2596 if (op->stats.hp < 0 && !QUERY_FLAG (op, FLAG_WIZ)) 2563 if (op->stats.hp < 0 && !QUERY_FLAG (op, FLAG_WIZ))
2597 kill_player (op); 2564 kill_player (op);
2598 } 2565 }
2599} 2566}
2600 2567
2650 { 2617 {
2651 tmp->name = format ("%s's finger" , &op->name); 2618 tmp->name = format ("%s's finger" , &op->name);
2652 tmp->name_pl = format ("%s's fingers", &op->name); 2619 tmp->name_pl = format ("%s's fingers", &op->name);
2653 tmp->msg = format ( 2620 tmp->msg = format (
2654 "This finger has been cut off of %s the %s, when he was defeated at level %d by %s.\n", 2621 "This finger has been cut off of %s the %s, when he was defeated at level %d by %s.\n",
2655 &op->name, op->contr->title, (int) (op->level), op->contr->killer 2622 &op->name, op->contr->title,
2623 (int)op->level,
2624 op->contr->killer_name ()
2656 ); 2625 );
2657 tmp->value = 0, tmp->type = 0; 2626 tmp->value = 0, tmp->type = 0;
2658 tmp->materialname = "organics"; 2627 tmp->materialname = "organics";
2659 tmp->insert_at (op, tmp); 2628 tmp->insert_at (op, tmp);
2660 } 2629 }
2666 } 2635 }
2667 2636
2668 INVOKE_PLAYER (DEATH, op->contr); 2637 INVOKE_PLAYER (DEATH, op->contr);
2669 2638
2670 command_kill_pets (op, 0); 2639 command_kill_pets (op, 0);
2671
2672 if (op->stats.food < 0)
2673 strcpy (op->contr->killer, "starvation");
2674 2640
2675 op->contr->play_sound (sound_find ("player_dies")); 2641 op->contr->play_sound (sound_find ("player_dies"));
2676 2642
2677 /* save the map location for corpse, gravestone */ 2643 /* save the map location for corpse, gravestone */
2678 x = op->x; 2644 x = op->x;
2708 2674
2709 lost_a_stat = 0; 2675 lost_a_stat = 0;
2710 2676
2711 for (z = 0; z < num_stats_lose; z++) 2677 for (z = 0; z < num_stats_lose; z++)
2712 { 2678 {
2713 i = RANDOM () % NUM_STATS; 2679 i = rndm (NUM_STATS);
2714 2680
2715 if (settings.stat_loss_on_death) 2681 if (settings.stat_loss_on_death)
2716 { 2682 {
2717 /* Pick a random stat and take a point off it. Tell the player 2683 /* Pick a random stat and take a point off it. Tell the player
2718 * what he lost. 2684 * what he lost.
2787 lost_a_stat = 1; 2753 lost_a_stat = 1;
2788 } 2754 }
2789 } 2755 }
2790 } 2756 }
2791 } 2757 }
2758
2792 /* If no stat lost, tell the player. */ 2759 /* If no stat lost, tell the player. */
2793 if (!lost_a_stat) 2760 if (!lost_a_stat)
2794 { 2761 {
2795 /* determine_god() seems to not work sometimes... why is this? 2762 /* determine_god() seems to not work sometimes... why is this?
2796 Should I be using something else? GD */ 2763 Should I be using something else? GD */
2800 new_draw_info_format (NDI_UNIQUE, 0, op, "For a brief moment you feel the holy presence of %s protecting" " you.", god); 2767 new_draw_info_format (NDI_UNIQUE, 0, op, "For a brief moment you feel the holy presence of %s protecting" " you.", god);
2801 else 2768 else
2802 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you feel a holy presence protecting you."); 2769 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you feel a holy presence protecting you.");
2803 } 2770 }
2804#else 2771#else
2805 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you" " feel a holy presence protecting you from losing yourself completely."); 2772 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you feel a holy presence protecting you from losing yourself completely.");
2806#endif 2773#endif
2807 2774
2808 /* Put a gravestone up where the character 'almost' died. List the 2775 /* Put a gravestone up where the character 'almost' died. List the
2809 * exp loss on the stone. 2776 * exp loss on the stone.
2810 */ 2777 */
2811 tmp = arch_to_object (archetype::find ("gravestone")); 2778 tmp = arch_to_object (archetype::find ("gravestone"));
2812 sprintf (buf, "%s's gravestone", &op->name); 2779 tmp->name = format ("%s's gravestone", &op->name);
2813 tmp->name = buf; 2780 tmp->name_pl = format ("%s's gravestones", &op->name);
2814 sprintf (buf, "%s's gravestones", &op->name); 2781 tmp->msg = format ("T<RIP>\n\nHere rests the hero %s the %s,\rwho was killed\rby %s.\n",
2815 tmp->name_pl = buf; 2782 &op->name, op->contr->title, op->contr->killer_name ());
2816 sprintf (buf, "RIP\nHere rests the hero %s the %s,\n" "who was killed\n" "by %s.\n", &op->name, op->contr->title, op->contr->killer);
2817 tmp->msg = buf;
2818 tmp->x = op->x, tmp->y = op->y; 2783 tmp->x = op->x, tmp->y = op->y;
2819 insert_ob_in_map (tmp, op->map, NULL, 0); 2784 insert_ob_in_map (tmp, op->map, NULL, 0);
2820 2785
2821 /**************************************/ 2786 /**************************************/
2822 /* */ 2787 /* */
2845 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer"); 2810 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer");
2846 } 2811 }
2847 2812
2848 cure_disease (op, 0, 0); /* remove any disease */ 2813 cure_disease (op, 0, 0); /* remove any disease */
2849 2814
2815 // remove all spell effects that are active
2816 // to avoid long-term effects such as word-of-recall
2817 for (object *item = op->inv; item; )
2818 {
2819 object *next = item->below;
2820
2821 if (item->type == SPELL_EFFECT && item->active)
2822 item->destroy ();
2823
2824 item = next;
2825 }
2826
2850 /*add_exp(op, (op->stats.exp * -0.20)); */ 2827 /*add_exp(op, (op->stats.exp * -0.20)); */
2851 apply_death_exp_penalty (op); 2828 apply_death_exp_penalty (op);
2829
2852 if (op->stats.food < 100) 2830 if (op->stats.food < 100)
2853 op->stats.food = 900; 2831 op->stats.food = 900;
2832
2854 op->stats.hp = op->stats.maxhp; 2833 op->stats.hp = op->stats.maxhp;
2855 op->stats.sp = MAX (op->stats.sp, op->stats.maxsp); 2834 op->stats.sp = MAX (op->stats.sp, op->stats.maxsp);
2856 op->stats.grace = MAX (op->stats.grace, op->stats.maxgrace); 2835 op->stats.grace = MAX (op->stats.grace, op->stats.maxgrace);
2857 2836
2858 /* 2837 /*
2896 if (will_kill_again & (1 << at)) 2875 if (will_kill_again & (1 << at))
2897 force->resist[at] = 100; 2876 force->resist[at] = 100;
2898 2877
2899 insert_ob_in_ob (force, op); 2878 insert_ob_in_ob (force, op);
2900 op->update_stats (); 2879 op->update_stats ();
2901
2902 } 2880 }
2903 2881
2904 new_draw_info (NDI_UNIQUE, 0, op, "YOU HAVE DIED."); 2882 new_draw_info (NDI_UNIQUE, 0, op, "YOU HAVE DIED.");
2905} 2883}
2906 2884
3007} 2985}
3008 2986
3009void 2987void
3010make_visible (object *op) 2988make_visible (object *op)
3011{ 2989{
3012 op->hide = 0; 2990 op->flag [FLAG_HIDDEN] = 0;
3013 op->invisible = 0; 2991 op->invisible = 0;
3014 2992
3015 if (op->type == PLAYER) 2993 if (op->type == PLAYER)
3016 { 2994 {
3017 op->contr->tmp_invis = 0; 2995 op->contr->tmp_invis = 0;
3042 3020
3043 if (!ob || !ob->map) 3021 if (!ob || !ob->map)
3044 return 0; 3022 return 0;
3045 3023
3046 /* so, on normal lighted maps, its hard to hide */ 3024 /* so, on normal lighted maps, its hard to hide */
3047 level = ob->map->darkness - 2; 3025 level = ob->map->darklevel () - 2;
3048 3026
3049 /* this also picks up whether the object is glowing. 3027 /* this also picks up whether the object is glowing.
3050 * 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
3051 * as bad as carrying a light on a pitch dark map */ 3029 * as bad as carrying a light on a pitch dark map */
3052 if (has_carried_lights (ob)) 3030 if (has_carried_lights (ob))
3053 level = -(10 + (2 * ob->map->darkness)); 3031 level = -(10 + (2 * ob->map->darklevel ()));
3054 3032
3055 /* scan through all nearby squares for terrain to hide in */ 3033 /* scan through all nearby squares for terrain to hide in */
3056 for (i = 0, x = ob->x, y = ob->y; 3034 for (i = 0, x = ob->x, y = ob->y;
3057 i <= SIZEOFFREE1; 3035 i <= SIZEOFFREE1;
3058 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])
3079 * spot (surrounded by clear terrain in broad daylight). -b.t. 3057 * spot (surrounded by clear terrain in broad daylight). -b.t.
3080 */ 3058 */
3081void 3059void
3082do_hidden_move (object *op) 3060do_hidden_move (object *op)
3083{ 3061{
3084 int hide = 0, num = random_roll (0, 19, op, PREFER_LOW); 3062 int hide = 0;
3085 object *skop;
3086 3063
3087 if (!op || !op->map) 3064 if (!op || !op->map)
3088 return; 3065 return;
3089 3066
3090 skop = find_obj_by_type_subtype (op, SKILL, SK_HIDING); 3067 object *skop = find_obj_by_type_subtype (op, SKILL, SK_HIDING);
3068 int num = random_roll (0, 19, op, PREFER_LOW);
3091 3069
3092 /* its *extremely* hard to run and sneak/hide at the same time! */ 3070 /* its *extremely* hard to run and sneak/hide at the same time! */
3093 if (op->type == PLAYER && op->contr->run_on) 3071 if (op->type == PLAYER && op->contr->run_on)
3094 if (!skop || num >= skop->level) 3072 if (!skop || num >= skop->level)
3095 { 3073 {
3105 num -= hide; 3083 num -= hide;
3106 3084
3107 if ((op->type == PLAYER && hide < -10) || ((op->invisible -= num) <= 0)) 3085 if ((op->type == PLAYER && hide < -10) || ((op->invisible -= num) <= 0))
3108 { 3086 {
3109 make_visible (op); 3087 make_visible (op);
3088
3110 if (op->type == PLAYER) 3089 if (op->type == PLAYER)
3111 new_draw_info (NDI_UNIQUE, 0, op, "You moved out of hiding! You are visible!"); 3090 new_draw_info (NDI_UNIQUE, 0, op, "You moved out of hiding! You are visible!");
3112 } 3091 }
3113 else if (op->type == PLAYER && skop) 3092 else if (op->type == PLAYER && skop)
3114 change_exp (op, calc_skill_exp (op, NULL, skop), skop->skill, 0); 3093 change_exp (op, calc_skill_exp (op, NULL, skop), skop->skill, 0);
3208 3187
3209 /* only the viewable area the player sees is updated by LOS 3188 /* only the viewable area the player sees is updated by LOS
3210 * 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
3211 * for any meaningful values. 3190 * for any meaningful values.
3212 */ 3191 */
3213 if (abs (dx) <= (pl->contr->ns->mapx / 2) && 3192 if (pl->contr->blocked_los (dx, dy) != LOS_BLOCKED)
3214 abs (dy) <= (pl->contr->ns->mapy / 2) &&
3215 !pl->contr->blocked_los[dx + (pl->contr->ns->mapx / 2)][dy + (pl->contr->ns->mapy / 2)])
3216 return 1; 3193 return 1;
3217 3194
3218 op = op->more; 3195 op = op->more;
3219 } 3196 }
3220 3197
3221 return 0; 3198 return 0;
3222} 3199}
3223 3200
3224/* routine for both players and monsters. We call this when 3201/* routine for both players and monsters. We call this when
3225 * there is a possibility for our action distrubing our hiding 3202 * there is a possibility for our action distrubing our hiding
3226 * place or invisiblity spell. Artefact invisiblity is not 3203 * place or invisiblity spell. Artefact invisiblity causes
3227 * effected by this. If we arent invisible to begin with, we 3204 * "noise" instead. If we arent invisible to begin with, we
3228 * return 0. 3205 * return 0.
3229 */ 3206 */
3230int 3207int
3231action_makes_visible (object *op) 3208action_makes_visible (object *op)
3232{ 3209{
3233 if (op->invisible && QUERY_FLAG (op, FLAG_ALIVE)) 3210 if (op->invisible && QUERY_FLAG (op, FLAG_ALIVE))
3234 { 3211 {
3235 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
3236 return 0; 3219 return 0;
3220 }
3237 3221
3238 if (op->contr && op->contr->tmp_invis == 0) 3222 if (op->contr && op->contr->tmp_invis == 0)
3239 return 0; 3223 return 0;
3240 3224
3241 /* If monsters, they should become visible */ 3225 /* If monsters, they should become visible */
3242 if (op->hide || !op->contr || (op->contr && op->contr->tmp_invis)) 3226 if (op->flag [FLAG_HIDDEN] || !op->contr || (op->contr && op->contr->tmp_invis))
3243 { 3227 {
3244 new_draw_info_format (NDI_UNIQUE, 0, op, "You become %s!", op->hide ? "unhidden" : "visible"); 3228 new_draw_info_format (NDI_UNIQUE, 0, op, "You become %s!", op->flag [FLAG_HIDDEN] ? "unhidden" : "visible");
3245 return 1; 3229 return 1;
3246 } 3230 }
3247 } 3231 }
3248 3232
3249 return 0; 3233 return 0;
3455 else 3439 else
3456 { 3440 {
3457 /* generate misc. treasure */ 3441 /* generate misc. treasure */
3458 tmp = arch_to_object (tr->item); 3442 tmp = arch_to_object (tr->item);
3459 new_draw_info_format (NDI_UNIQUE | NDI_BLUE, 0, who, "You gained %s", query_short_name (tmp)); 3443 new_draw_info_format (NDI_UNIQUE | NDI_BLUE, 0, who, "You gained %s", query_short_name (tmp));
3460 tmp = insert_ob_in_ob (tmp, who); 3444 who->insert (tmp);
3461 if (who->type == PLAYER)
3462 esrv_send_item (who, tmp);
3463 } 3445 }
3464} 3446}
3465 3447
3466/** 3448/**
3467 * Unready an object for a player. This function does nothing if the object was 3449 * Unready an object for a player. This function does nothing if the object was
3479 if (pl->ranged_ob == ob) 3461 if (pl->ranged_ob == ob)
3480 pl->ranged_ob = 0; 3462 pl->ranged_ob = 0;
3481} 3463}
3482 3464
3483sint8 3465sint8
3484player::visibility_at (maptile *map, int x, int y) const 3466player::darkness_at (maptile *map, int x, int y) const
3485{ 3467{
3486 if (!ns) 3468 if (ns)
3487 return 0; 3469 return LOS_BLOCKED;
3488 3470
3489 int dx, dy; 3471 int dx, dy;
3490 if (!adjacent_map (map, ns->current_map, &dx, &dy)) 3472 if (!adjacent_map (map, ns->current_map, &dx, &dy))
3491 return 0; 3473 return LOS_BLOCKED;
3492 3474
3493 x += dx - ns->current_x + ns->mapx / 2; 3475 x += dx - ns->current_x;
3494 y += dy - ns->current_y + ns->mapy / 2; 3476 y += dy - ns->current_y;
3495 3477
3496 if (!IN_RANGE_EXC (x, 0, ns->mapx) || !IN_RANGE_EXC (y, 0, ns->mapy))
3497 return 0;
3498
3499 return 100 - blocked_los [x][y]; 3478 return blocked_los (x, y);
3500} 3479}
3501 3480
3502void 3481void
3503player::infobox (const char *title, const char *msg, int color) 3482player::infobox (const char *title, const char *msg, int color)
3504{ 3483{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines