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.218 by root, Sun Dec 28 10:05:42 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
1003check_pick (object *op) 971check_pick (object *op)
1004{ 972{
1005 object *tmp, *next; 973 object *tmp, *next;
1006 int stop = 0; 974 int stop = 0;
1007 int wvratio; 975 int wvratio;
1008 char putstring[128];
1009 976
1010 /* if you're flying, you cna't pick up anything */ 977 /* if you're flying, you cna't pick up anything */
1011 if (op->move_type & MOVE_FLYING) 978 if (op->move_type & MOVE_FLYING)
1012 return 1; 979 return 1;
1013 980
1037 1004
1038 if (op->contr->search_str[0] != '\0' && settings.search_items == TRUE) 1005 if (op->contr->search_str[0] != '\0' && settings.search_items == TRUE)
1039 { 1006 {
1040 if (item_matched_string (op, tmp, op->contr->search_str)) 1007 if (item_matched_string (op, tmp, op->contr->search_str))
1041 CHK_PICK_PICKUP; 1008 CHK_PICK_PICKUP;
1009
1042 continue; 1010 continue;
1043 } 1011 }
1044 1012
1045 /* high not bit set? We're using the old autopickup model */ 1013 /* high not bit set? We're using the old autopickup model */
1046 if (!(op->contr->mode & PU_NEWMODE)) 1014 if (!(op->contr->mode & PU_NEWMODE))
1086 { /* old model */ 1054 { /* old model */
1087 /* NEW pickup handling */ 1055 /* NEW pickup handling */
1088 if (op->contr->mode & PU_DEBUG) 1056 if (op->contr->mode & PU_DEBUG)
1089 { 1057 {
1090 /* some debugging code to figure out item information */ 1058 /* some debugging code to figure out item information */
1091 if (tmp->name != NULL) 1059 const char *str = tmp->name
1092 sprintf (putstring, "item name: %s item type: %d weight/value: %d", 1060 ? format ("item name: %s item type: %d weight/value: %d",
1093 &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))))
1094 else
1095 sprintf (putstring, "item name: %s item type: %d weight/value: %d", 1062 : format ("item name: %s item type: %d weight/value: %d",
1096 &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))));
1097 1064
1098 new_draw_info (NDI_UNIQUE, 0, op, putstring); 1065 new_draw_info (NDI_UNIQUE, 0, op, str);
1099 } 1066 }
1100 1067
1101 /* philosophy: 1068 /* philosophy:
1102 * 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
1103 * generic. This takes no game-time. For more detailed pickups 1070 * generic. This takes no game-time. For more detailed pickups
1327 if (op->contr->mode & PU_RATIO) 1294 if (op->contr->mode & PU_RATIO)
1328 { 1295 {
1329 /* use value density to decide what else to grab */ 1296 /* use value density to decide what else to grab */
1330 /* >=7 was >= op->contr->mode */ 1297 /* >=7 was >= op->contr->mode */
1331 /* >=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
1332 * and multiply them by 5, giving 0..15*5== 5..75 */ 1299 */
1333 wvratio = (op->contr->mode & PU_RATIO) * 5; 1300 wvratio = op->contr->mode & PU_RATIO;
1334 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)
1335 { 1302 {
1336 CHK_PICK_PICKUP; 1303 CHK_PICK_PICKUP;
1337#if 0 1304#if 0
1338 fprintf (stderr, "HIGH WEIGHT/VALUE ["); 1305 fprintf (stderr, "HIGH WEIGHT/VALUE [");
1339 if (tmp->name != NULL) 1306 if (tmp->name != NULL)
1405 } 1372 }
1406 } 1373 }
1407 else if (arrow->type == ARROW && arrow->race == type) 1374 else if (arrow->type == ARROW && arrow->race == type)
1408 { 1375 {
1409 /* allways prefer assasination/slaying */ 1376 /* allways prefer assasination/slaying */
1410 if (target->race != NULL && arrow->slaying != NULL && strstr (arrow->slaying, target->race)) 1377 if (target->race && arrow->slaying && strstr (arrow->slaying, target->race))
1411 { 1378 {
1412 if (arrow->attacktype & AT_DEATH) 1379 if (arrow->attacktype & AT_DEATH)
1413 { 1380 {
1414 *better = 100; 1381 *better = 100;
1415 return arrow; 1382 return arrow;
1443 betterby = 1 + arrow->magic + arrow->stats.dam; 1410 betterby = 1 + arrow->magic + arrow->stats.dam;
1444 } 1411 }
1445 } 1412 }
1446 } 1413 }
1447 } 1414 }
1415
1448 if (tmp == NULL && arrow == NULL) 1416 if (tmp == NULL && arrow == NULL)
1449 return find_arrow (op, type); 1417 return find_arrow (op, type);
1450 1418
1451 *better = betterby; 1419 *better = betterby;
1452 return tmp; 1420 return tmp;
1482 for (i = 0, found = 0; i < 20; i++) 1450 for (i = 0, found = 0; i < 20; i++)
1483 { 1451 {
1484 x += freearr_x[dir]; 1452 x += freearr_x[dir];
1485 y += freearr_y[dir]; 1453 y += freearr_y[dir];
1486 mflags = get_map_flags (m, &m, x, y, &x, &y); 1454 mflags = get_map_flags (m, &m, x, y, &x, &y);
1455
1487 if (mflags & P_OUT_OF_MAP || mflags & P_BLOCKSVIEW) 1456 if (mflags & P_OUT_OF_MAP || mflags & P_BLOCKSVIEW)
1488 { 1457 {
1489 tmp = NULL; 1458 tmp = 0;
1490 break; 1459 break;
1491 } 1460 }
1492 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)
1493 { 1462 {
1494 /* This block presumes arrows and the like are MOVE_FLY_SLOW - 1463 /* This block presumes arrows and the like are MOVE_FLY_SLOW -
1495 * perhaps a bad assumption. 1464 * perhaps a bad assumption.
1496 */ 1465 */
1497 tmp = NULL; 1466 tmp = 0;
1498 break; 1467 break;
1499 } 1468 }
1469
1500 if (mflags & P_IS_ALIVE) 1470 if (mflags & P_IS_ALIVE)
1501 {
1502 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)
1503 if (QUERY_FLAG (tmp, FLAG_ALIVE)) 1472 if (QUERY_FLAG (tmp, FLAG_ALIVE))
1504 {
1505 found++;
1506 break;
1507 }
1508 if (found)
1509 break; 1473 break;
1510 }
1511 } 1474 }
1512 if (tmp == NULL) 1475
1476 if (!tmp)
1513 return find_arrow (op, type); 1477 return find_arrow (op, type);
1514 1478
1515 if (tmp->head) 1479 if (tmp->head)
1516 tmp = tmp->head; 1480 tmp = tmp->head;
1517 1481
1562 if (bow->below) 1526 if (bow->below)
1563 { 1527 {
1564 bow->remove (); 1528 bow->remove ();
1565 op->insert (bow); 1529 op->insert (bow);
1566 } 1530 }
1567
1568 } 1531 }
1569 1532
1570 if (!bow->race || !bow->skill) 1533 if (!bow->race || !bow->skill)
1571 { 1534 {
1572 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);
1598 } 1561 }
1599 1562
1600 /* this should not happen, but sometimes does */ 1563 /* this should not happen, but sometimes does */
1601 if (arrow->nrof == 0) 1564 if (arrow->nrof == 0)
1602 { 1565 {
1566 LOG (llevError | logBacktrace, "arrow (%s) has nrof 0\n", arrow->debug_desc ());
1603 arrow->destroy (); 1567 arrow->destroy ();
1604 return 0; 1568 return 0;
1605 } 1569 }
1606 1570
1607 left = arrow; /* these are arrows left to the player */ 1571 left = arrow; /* these are arrows left to the player */
1694 * hence the function name. 1658 * hence the function name.
1695 */ 1659 */
1696int 1660int
1697player_fire_bow (object *op, int dir) 1661player_fire_bow (object *op, int dir)
1698{ 1662{
1699 int ret = 0, wcmod = 0; 1663 int ret;
1700 1664
1701 if (op->contr->bowtype == bow_bestarrow) 1665 if (op->contr->bowtype == bow_bestarrow)
1702 { 1666 {
1703 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);
1704 } 1668 }
1705 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)
1706 { 1670 {
1707 if (!similar_direction (dir, op->contr->bowtype - bow_n + 1)) 1671 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); 1672 ret = fire_bow (op, op, NULL, op->contr->bowtype - bow_n + 1, wcmod, op->x, op->y);
1711 } 1673 }
1712 else if (op->contr->bowtype == bow_threewide) 1674 else if (op->contr->bowtype == bow_threewide)
1713 { 1675 {
1714 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);
1715 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)]);
1716 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)]);
1717 } 1679 }
1718 else if (op->contr->bowtype == bow_spreadshot) 1680 else if (op->contr->bowtype == bow_spreadshot)
1719 { 1681 {
1720 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);
1721 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);
1722 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);
1723 } 1685 }
1724 else 1686 else
1725 { 1687 {
1763 return; 1725 return;
1764 } 1726 }
1765 } 1727 }
1766 else if (item->type == ROD || item->type == HORN) 1728 else if (item->type == ROD || item->type == HORN)
1767 { 1729 {
1768 if (item->stats.hp < MAX (item->inv->stats.sp, item->inv->stats.grace)) 1730 sint16 spell_sp = MAX (item->inv->stats.sp, item->inv->stats.grace);
1731
1732 // using the maximum of the rods charge allows at least one spell cast
1733 // for a rod or horn, this fixes some broken rods.
1734 if (item->stats.hp < MIN (spell_sp, item->stats.maxhp))
1769 { 1735 {
1770 op->contr->play_sound (sound_find ("wand_poof")); 1736 op->contr->play_sound (sound_find ("wand_poof"));
1771 1737
1772 if (item->type == ROD) 1738 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)); 1739 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s whines for a while, but nothing happens.", query_base_name (item, 0));
1778 } 1744 }
1779 } 1745 }
1780 1746
1781 if (cast_spell (op, item, dir, item->inv, NULL)) 1747 if (cast_spell (op, item, dir, item->inv, NULL))
1782 { 1748 {
1783 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
1784 if (item->type == WAND) 1751 if (item->type == WAND)
1785 { 1752 {
1786 if (!(--item->stats.food)) 1753 if (!(--item->stats.food))
1787 { 1754 {
1788 object *tmp; 1755 object *tmp;
1792 CLEAR_FLAG (item, FLAG_ANIMATE); 1759 CLEAR_FLAG (item, FLAG_ANIMATE);
1793 item->face = item->arch->face; 1760 item->face = item->arch->face;
1794 item->set_speed (0); 1761 item->set_speed (0);
1795 } 1762 }
1796 1763
1797 if ((tmp = item->in_player ())) 1764 if (object *pl = item->visible_to ())
1798 esrv_update_item (UPD_ANIM, tmp, item); 1765 esrv_update_item (UPD_ANIM, pl, item);
1799 } 1766 }
1800 } 1767 }
1801 else if (item->type == ROD || item->type == HORN) 1768 else if (item->type == ROD || item->type == HORN)
1802 drain_rod_charge (item); 1769 drain_rod_charge (item);
1803 } 1770 }
1808bool 1775bool
1809fire (object *op, int dir) 1776fire (object *op, int dir)
1810{ 1777{
1811 int spellcost = 0; 1778 int spellcost = 0;
1812 1779
1813 /* check for loss of invisiblity/hide */
1814 if (action_makes_visible (op))
1815 make_visible (op);
1816
1817 player *pl = op->contr; 1780 player *pl = op->contr;
1818 1781
1819 if (pl->golem) 1782 if (pl->golem)
1820 { 1783 {
1821 control_golem (op->contr->golem, dir); 1784 control_golem (op->contr->golem, dir);
1823 } 1786 }
1824 1787
1825 object *ob = pl->ranged_ob; 1788 object *ob = pl->ranged_ob;
1826 1789
1827 if (!ob) 1790 if (!ob)
1828 return false;
1829
1830 if (!op->change_weapon (ob))
1831 return false; 1791 return false;
1832 1792
1833 if (op->speed_left > 0.f) 1793 if (op->speed_left > 0.f)
1834 --op->speed_left; 1794 --op->speed_left;
1835 else 1795 else
1836 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);
1837 1804
1838 switch (ob->type) 1805 switch (ob->type)
1839 { 1806 {
1840 case BOW: 1807 case BOW:
1841 player_fire_bow (op, dir); 1808 player_fire_bow (op, dir);
1980 remove_door2 (door); /* remove door without violence ;-) */ 1947 remove_door2 (door); /* remove door without violence ;-) */
1981 } 1948 }
1982 1949
1983 /* Do this after we print the message */ 1950 /* Do this after we print the message */
1984 key->decrease (); /* Use up one of the keys */ 1951 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 1952
1989 return 1; /* Nothing more to do below */ 1953 return 1; /* Nothing more to do below */
1990 } 1954 }
1991 else if (door->type == LOCKED_DOOR) 1955 else if (door->type == LOCKED_DOOR)
1992 { 1956 {
2089 --op->speed_left; 2053 --op->speed_left;
2090 2054
2091 op->play_sound (sound_find ("push_player")); 2055 op->play_sound (sound_find ("push_player"));
2092 push_ob (mon, dir, op); 2056 push_ob (mon, dir, op);
2093 2057
2094 if (op->contr->tmp_invis || op->hide) 2058 if (action_makes_visible (op))
2095 make_visible (op); 2059 make_visible (op);
2096 2060
2097 return true; 2061 return true;
2098 } 2062 }
2099 else 2063 else
2121 push_ob (mon, dir, op); 2085 push_ob (mon, dir, op);
2122 } 2086 }
2123 else 2087 else
2124 op->statusmsg ("You withhold your attack"); 2088 op->statusmsg ("You withhold your attack");
2125 2089
2126 if (op->contr->tmp_invis || op->hide) 2090 if (op->contr->tmp_invis || op->flag [FLAG_HIDDEN])
2127 make_visible (op); 2091 make_visible (op);
2128 2092
2129 return true; 2093 return true;
2130 } 2094 }
2131 } 2095 }
2189 if (QUERY_FLAG (op, FLAG_CONFUSED) && dir) 2153 if (QUERY_FLAG (op, FLAG_CONFUSED) && dir)
2190 dir = absdir (dir + rndm (3) + rndm (3) - 2); 2154 dir = absdir (dir + rndm (3) + rndm (3) - 2);
2191 2155
2192 op->facing = dir; 2156 op->facing = dir;
2193 2157
2194 if (op->hide) 2158 if (op->flag [FLAG_HIDDEN])
2195 do_hidden_move (op); 2159 do_hidden_move (op);
2196 2160
2197 bool retval; 2161 bool retval;
2198 2162
2199 if (INVOKE_PLAYER (MOVE, op->contr, ARG_INT (dir))) 2163 if (INVOKE_PLAYER (MOVE, op->contr, ARG_INT (dir)))
2271 if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE)) 2235 if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE))
2272 { 2236 {
2273 op->play_sound (sound_find ("ob_evaporate")); 2237 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)); 2238 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s vibrates violently, then evaporates.", query_name (tmp));
2275 2239
2276 if (op->contr)
2277 esrv_del_item (op->contr, tmp->count);
2278
2279 tmp->destroy (); 2240 tmp->destroy ();
2280 CLEAR_FLAG (op, FLAG_LIFESAVE); 2241 CLEAR_FLAG (op, FLAG_LIFESAVE);
2281 2242
2282 if (op->stats.hp < 0) 2243 if (op->stats.hp < 0)
2283 op->stats.hp = op->stats.maxhp; 2244 op->stats.hp = op->stats.maxhp;
2295 return 0; 2256 return 0;
2296} 2257}
2297 2258
2298/* This goes throws the inventory and removes unpaid objects, and puts them 2259/* 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 2260 * 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 2261 * function will descend into containers. op is the object to start the search
2301 * from. 2262 * from.
2302 */ 2263 */
2303static void 2264static void
2304drop_unpaid_items (object *op, object *env) 2265drop_unpaid_items (object *op, object *env)
2305{ 2266{
2306 while (op) 2267 while (op)
2307 { 2268 {
2308 object *next = op->below; /* Make sure we have a good value, in case we remove object 'op' */ 2269 object *next = op->below; /* Make sure we have a good value, in case we remove object 'op' */
2309 2270
2310 if (QUERY_FLAG (op, FLAG_UNPAID)) 2271 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); 2272 op->insert_at (env);
2316 }
2317 else if (op->inv) 2273 else if (op->inv)
2318 drop_unpaid_items (op->inv, env); 2274 drop_unpaid_items (op->inv, env);
2319 2275
2320 op = next; 2276 op = next;
2321 } 2277 }
2333 * Moved from apply.c to player.c - player.c is what 2289 * Moved from apply.c to player.c - player.c is what
2334 * actually uses this function. player.c may not be quite the 2290 * actually uses this function. player.c may not be quite the
2335 * best, a misc file for object actions is probably better, 2291 * best, a misc file for object actions is probably better,
2336 * but there isn't one in the server directory. 2292 * but there isn't one in the server directory.
2337 */ 2293 */
2338char * 2294const char *
2339gravestone_text (object *op) 2295gravestone_text (object *op)
2340{ 2296{
2341 static char buf2[MAX_BUF]; 2297 static dynbuf_text buf;
2342 char buf[MAX_BUF];
2343 time_t now = time (NULL);
2344 2298
2345 strcpy (buf2, " R.I.P.\n\n"); 2299 buf << "---- R.I.P. ----\n\n"
2300 << op->name;
2301
2346 if (op->type == PLAYER) 2302 if (op->type == PLAYER)
2347 sprintf (buf, "%s the %s\n", &op->name, op->contr->title); 2303 buf << " the " << op->contr->title;
2348 else
2349 sprintf (buf, "%s\n", &op->name);
2350 2304
2351 strncat (buf2, " ", 20 - strlen (buf) / 2); 2305 buf << "\n\n";
2352 strcat (buf2, buf); 2306
2307 buf << "who was level ";
2308 buf << (sint32)op->level << "\n\n" // OO breakdown
2309 << " when " << (op->contr ? "killed" : "died") << "\n\n";
2310
2353 if (op->type == PLAYER) 2311 if (op->type == PLAYER)
2354 sprintf (buf, "who was in level %d when killed\n", op->level); 2312 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 2313
2358 strncat (buf2, " ", 20 - strlen (buf) / 2);
2359 strcat (buf2, buf);
2360 if (op->type == PLAYER)
2361 { 2314 {
2362 sprintf (buf, "by %s.\n\n", op->contr->killer); 2315 static char buf2[128];
2363 strncat (buf2, " ", 21 - strlen (buf) / 2); 2316 time_t now = time (NULL);
2364 strcat (buf2, buf);
2365 }
2366
2367 strftime (buf, MAX_BUF, "%b %d %Y\n", localtime (&now)); 2317 strftime (buf2, 128, "%b %d %Y\n\n", localtime (&now));
2368 strncat (buf2, " ", 20 - strlen (buf) / 2); 2318 buf << buf2;
2369 strcat (buf2, buf); 2319 }
2370 2320
2371 return buf2; 2321 return buf;
2372} 2322}
2373 2323
2374void 2324void
2375do_some_living (object *op) 2325do_some_living (object *op)
2376{ 2326{
2531 { 2481 {
2532 over_hp = (gen_hp < 20 ? 30 : gen_hp + 10) / rate_hp; 2482 over_hp = (gen_hp < 20 ? 30 : gen_hp + 10) / rate_hp;
2533 2483
2534 if (over_hp > 0) 2484 if (over_hp > 0)
2535 { 2485 {
2536 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;
2537 op->last_heal = 0; 2487 op->last_heal = 0;
2538 } 2488 }
2539 else 2489 else
2540 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);
2541 } 2491 }
2557 op->stats.food--; 2507 op->stats.food--;
2558 } 2508 }
2559 2509
2560 if (op->stats.food < 0 && op->stats.hp >= 0) 2510 if (op->stats.food < 0 && op->stats.hp >= 0)
2561 { 2511 {
2562 object *tmp, *flesh = 0; 2512 object *flesh = 0;
2563 2513
2564 for (tmp = op->inv; tmp; tmp = tmp->below) 2514 for_inv_removable (op, tmp)
2565 { 2515 {
2566 if (!QUERY_FLAG (tmp, FLAG_UNPAID)) 2516 if (QUERY_FLAG (tmp, FLAG_UNPAID))
2517 continue;
2518
2519 if (tmp->type == FOOD || tmp->type == DRINK || tmp->type == POISON)
2567 { 2520 {
2568 if (tmp->type == FOOD || tmp->type == DRINK || tmp->type == POISON) 2521 op->statusmsg ("You blindly grab for a bite of food. "
2569 { 2522 "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); 2523 manual_apply (op, tmp, 0);
2524
2572 if (op->stats.food >= 0 || op->stats.hp < 0) 2525 if (op->stats.food >= 0 || op->stats.hp < 0)
2573 break; 2526 break;
2574 } 2527 }
2575 else if (tmp->type == FLESH) 2528 else if (tmp->type == FLESH)
2576 flesh = tmp; 2529 flesh = tmp;
2577 } /* End if paid for object */ 2530 }
2578 } /* end of for loop */
2579 2531
2580 /* If player is still starving, it means they don't have any food, so 2532 /* If player is still starving, it means they don't have any food, so
2581 * eat flesh instead. 2533 * eat flesh instead.
2582 */ 2534 */
2583 if (op->stats.food < 0 && op->stats.hp >= 0 && flesh) 2535 if (op->stats.food < 0 && op->stats.hp >= 0 && flesh)
2584 { 2536 {
2585 new_draw_info (NDI_UNIQUE, 0, op, "You blindly grab for a bite of food."); 2537 op->statusmsg ("You blindly grab for a bite of food. "
2538 "H<To prevent you from starving, you ate some random item from your backpack.>");
2586 manual_apply (op, flesh, 0); 2539 manual_apply (op, flesh, 0);
2587 } 2540 }
2541
2542 // If player is still starving, alert him!
2543 if (op->stats.food < 0)
2544 op->failmsg ("You are starving! "
2545 "H<Eat some food to increase your food and prevent you from an untimely death.>");
2588 } 2546 }
2589 2547
2590 if (op->stats.food < 0) 2548 if (op->stats.food < 0)
2591 { 2549 {
2592 op->stats.hp += op->stats.food; 2550 op->stats.hp += op->stats.food;
2593 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 ();
2594 } 2557 }
2558 }
2595 2559
2560 /* killer should be set here already */
2596 if (op->stats.hp < 0 && !QUERY_FLAG (op, FLAG_WIZ)) 2561 if (op->stats.hp < 0 && !QUERY_FLAG (op, FLAG_WIZ))
2597 kill_player (op); 2562 kill_player (op);
2598 } 2563 }
2599} 2564}
2600 2565
2650 { 2615 {
2651 tmp->name = format ("%s's finger" , &op->name); 2616 tmp->name = format ("%s's finger" , &op->name);
2652 tmp->name_pl = format ("%s's fingers", &op->name); 2617 tmp->name_pl = format ("%s's fingers", &op->name);
2653 tmp->msg = format ( 2618 tmp->msg = format (
2654 "This finger has been cut off of %s the %s, when he was defeated at level %d by %s.\n", 2619 "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 2620 &op->name, op->contr->title,
2621 (int)op->level,
2622 op->contr->killer_name ()
2656 ); 2623 );
2657 tmp->value = 0, tmp->type = 0; 2624 tmp->value = 0, tmp->type = 0;
2658 tmp->materialname = "organics"; 2625 tmp->materialname = "organics";
2659 tmp->insert_at (op, tmp); 2626 tmp->insert_at (op, tmp);
2660 } 2627 }
2666 } 2633 }
2667 2634
2668 INVOKE_PLAYER (DEATH, op->contr); 2635 INVOKE_PLAYER (DEATH, op->contr);
2669 2636
2670 command_kill_pets (op, 0); 2637 command_kill_pets (op, 0);
2671
2672 if (op->stats.food < 0)
2673 strcpy (op->contr->killer, "starvation");
2674 2638
2675 op->contr->play_sound (sound_find ("player_dies")); 2639 op->contr->play_sound (sound_find ("player_dies"));
2676 2640
2677 /* save the map location for corpse, gravestone */ 2641 /* save the map location for corpse, gravestone */
2678 x = op->x; 2642 x = op->x;
2708 2672
2709 lost_a_stat = 0; 2673 lost_a_stat = 0;
2710 2674
2711 for (z = 0; z < num_stats_lose; z++) 2675 for (z = 0; z < num_stats_lose; z++)
2712 { 2676 {
2713 i = RANDOM () % NUM_STATS; 2677 i = rndm (NUM_STATS);
2714 2678
2715 if (settings.stat_loss_on_death) 2679 if (settings.stat_loss_on_death)
2716 { 2680 {
2717 /* 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
2718 * what he lost. 2682 * what he lost.
2787 lost_a_stat = 1; 2751 lost_a_stat = 1;
2788 } 2752 }
2789 } 2753 }
2790 } 2754 }
2791 } 2755 }
2756
2792 /* If no stat lost, tell the player. */ 2757 /* If no stat lost, tell the player. */
2793 if (!lost_a_stat) 2758 if (!lost_a_stat)
2794 { 2759 {
2795 /* determine_god() seems to not work sometimes... why is this? 2760 /* determine_god() seems to not work sometimes... why is this?
2796 Should I be using something else? GD */ 2761 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); 2765 new_draw_info_format (NDI_UNIQUE, 0, op, "For a brief moment you feel the holy presence of %s protecting" " you.", god);
2801 else 2766 else
2802 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you feel a holy presence protecting you."); 2767 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you feel a holy presence protecting you.");
2803 } 2768 }
2804#else 2769#else
2805 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you" " feel a holy presence protecting you from losing yourself completely."); 2770 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you feel a holy presence protecting you from losing yourself completely.");
2806#endif 2771#endif
2807 2772
2808 /* Put a gravestone up where the character 'almost' died. List the 2773 /* Put a gravestone up where the character 'almost' died. List the
2809 * exp loss on the stone. 2774 * exp loss on the stone.
2810 */ 2775 */
2811 tmp = arch_to_object (archetype::find ("gravestone")); 2776 tmp = arch_to_object (archetype::find ("gravestone"));
2812 sprintf (buf, "%s's gravestone", &op->name); 2777 tmp->name = format ("%s's gravestone", &op->name);
2813 tmp->name = buf; 2778 tmp->name_pl = format ("%s's gravestones", &op->name);
2814 sprintf (buf, "%s's gravestones", &op->name); 2779 tmp->msg = format ("T<RIP>\n\nHere rests the hero %s the %s,\rwho was killed\rby %s.\n",
2815 tmp->name_pl = buf; 2780 &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; 2781 tmp->x = op->x, tmp->y = op->y;
2819 insert_ob_in_map (tmp, op->map, NULL, 0); 2782 insert_ob_in_map (tmp, op->map, NULL, 0);
2820 2783
2821 /**************************************/ 2784 /**************************************/
2822 /* */ 2785 /* */
2845 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer"); 2808 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer");
2846 } 2809 }
2847 2810
2848 cure_disease (op, 0, 0); /* remove any disease */ 2811 cure_disease (op, 0, 0); /* remove any disease */
2849 2812
2813 // remove all spell effects that are active
2814 // to avoid long-term effects such as word-of-recall
2815 for (object *item = op->inv; item; )
2816 {
2817 object *next = item->below;
2818
2819 if (item->type == SPELL_EFFECT && item->active)
2820 item->destroy ();
2821
2822 item = next;
2823 }
2824
2850 /*add_exp(op, (op->stats.exp * -0.20)); */ 2825 /*add_exp(op, (op->stats.exp * -0.20)); */
2851 apply_death_exp_penalty (op); 2826 apply_death_exp_penalty (op);
2827
2852 if (op->stats.food < 100) 2828 if (op->stats.food < 100)
2853 op->stats.food = 900; 2829 op->stats.food = 900;
2830
2854 op->stats.hp = op->stats.maxhp; 2831 op->stats.hp = op->stats.maxhp;
2855 op->stats.sp = MAX (op->stats.sp, op->stats.maxsp); 2832 op->stats.sp = MAX (op->stats.sp, op->stats.maxsp);
2856 op->stats.grace = MAX (op->stats.grace, op->stats.maxgrace); 2833 op->stats.grace = MAX (op->stats.grace, op->stats.maxgrace);
2857 2834
2858 /* 2835 /*
2896 if (will_kill_again & (1 << at)) 2873 if (will_kill_again & (1 << at))
2897 force->resist[at] = 100; 2874 force->resist[at] = 100;
2898 2875
2899 insert_ob_in_ob (force, op); 2876 insert_ob_in_ob (force, op);
2900 op->update_stats (); 2877 op->update_stats ();
2901
2902 } 2878 }
2903 2879
2904 new_draw_info (NDI_UNIQUE, 0, op, "YOU HAVE DIED."); 2880 new_draw_info (NDI_UNIQUE, 0, op, "YOU HAVE DIED.");
2905} 2881}
2906 2882
3007} 2983}
3008 2984
3009void 2985void
3010make_visible (object *op) 2986make_visible (object *op)
3011{ 2987{
3012 op->hide = 0; 2988 op->flag [FLAG_HIDDEN] = 0;
3013 op->invisible = 0; 2989 op->invisible = 0;
3014 2990
3015 if (op->type == PLAYER) 2991 if (op->type == PLAYER)
3016 { 2992 {
3017 op->contr->tmp_invis = 0; 2993 op->contr->tmp_invis = 0;
3042 3018
3043 if (!ob || !ob->map) 3019 if (!ob || !ob->map)
3044 return 0; 3020 return 0;
3045 3021
3046 /* so, on normal lighted maps, its hard to hide */ 3022 /* so, on normal lighted maps, its hard to hide */
3047 level = ob->map->darkness - 2; 3023 level = ob->map->darklevel () - 2;
3048 3024
3049 /* this also picks up whether the object is glowing. 3025 /* this also picks up whether the object is glowing.
3050 * 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
3051 * as bad as carrying a light on a pitch dark map */ 3027 * as bad as carrying a light on a pitch dark map */
3052 if (has_carried_lights (ob)) 3028 if (has_carried_lights (ob))
3053 level = -(10 + (2 * ob->map->darkness)); 3029 level = -(10 + (2 * ob->map->darklevel ()));
3054 3030
3055 /* scan through all nearby squares for terrain to hide in */ 3031 /* scan through all nearby squares for terrain to hide in */
3056 for (i = 0, x = ob->x, y = ob->y; 3032 for (i = 0, x = ob->x, y = ob->y;
3057 i <= SIZEOFFREE1; 3033 i <= SIZEOFFREE1;
3058 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])
3079 * spot (surrounded by clear terrain in broad daylight). -b.t. 3055 * spot (surrounded by clear terrain in broad daylight). -b.t.
3080 */ 3056 */
3081void 3057void
3082do_hidden_move (object *op) 3058do_hidden_move (object *op)
3083{ 3059{
3084 int hide = 0, num = random_roll (0, 19, op, PREFER_LOW); 3060 int hide = 0;
3085 object *skop;
3086 3061
3087 if (!op || !op->map) 3062 if (!op || !op->map)
3088 return; 3063 return;
3089 3064
3090 skop = find_obj_by_type_subtype (op, SKILL, SK_HIDING); 3065 object *skop = find_obj_by_type_subtype (op, SKILL, SK_HIDING);
3066 int num = random_roll (0, 19, op, PREFER_LOW);
3091 3067
3092 /* its *extremely* hard to run and sneak/hide at the same time! */ 3068 /* its *extremely* hard to run and sneak/hide at the same time! */
3093 if (op->type == PLAYER && op->contr->run_on) 3069 if (op->type == PLAYER && op->contr->run_on)
3094 if (!skop || num >= skop->level) 3070 if (!skop || num >= skop->level)
3095 { 3071 {
3105 num -= hide; 3081 num -= hide;
3106 3082
3107 if ((op->type == PLAYER && hide < -10) || ((op->invisible -= num) <= 0)) 3083 if ((op->type == PLAYER && hide < -10) || ((op->invisible -= num) <= 0))
3108 { 3084 {
3109 make_visible (op); 3085 make_visible (op);
3086
3110 if (op->type == PLAYER) 3087 if (op->type == PLAYER)
3111 new_draw_info (NDI_UNIQUE, 0, op, "You moved out of hiding! You are visible!"); 3088 new_draw_info (NDI_UNIQUE, 0, op, "You moved out of hiding! You are visible!");
3112 } 3089 }
3113 else if (op->type == PLAYER && skop) 3090 else if (op->type == PLAYER && skop)
3114 change_exp (op, calc_skill_exp (op, NULL, skop), skop->skill, 0); 3091 change_exp (op, calc_skill_exp (op, NULL, skop), skop->skill, 0);
3204 while (op) 3181 while (op)
3205 { 3182 {
3206 dx = rv.distance_x + op->arch->x; 3183 dx = rv.distance_x + op->arch->x;
3207 dy = rv.distance_y + op->arch->y; 3184 dy = rv.distance_y + op->arch->y;
3208 3185
3209 /* only the viewable area the player sees is updated by LOS 3186 if (pl->contr->blocked_los (dx, dy) != LOS_BLOCKED)
3210 * code, so we need to restrict ourselves to that range of values
3211 * for any meaningful values.
3212 */
3213 if (abs (dx) <= (pl->contr->ns->mapx / 2) &&
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; 3187 return 1;
3217 3188
3218 op = op->more; 3189 op = op->more;
3219 } 3190 }
3220 3191
3221 return 0; 3192 return 0;
3222} 3193}
3223 3194
3224/* routine for both players and monsters. We call this when 3195/* routine for both players and monsters. We call this when
3225 * there is a possibility for our action distrubing our hiding 3196 * there is a possibility for our action distrubing our hiding
3226 * place or invisiblity spell. Artefact invisiblity is not 3197 * place or invisiblity spell. Artefact invisiblity causes
3227 * effected by this. If we arent invisible to begin with, we 3198 * "noise" instead. If we arent invisible to begin with, we
3228 * return 0. 3199 * return 0.
3229 */ 3200 */
3230int 3201int
3231action_makes_visible (object *op) 3202action_makes_visible (object *op)
3232{ 3203{
3233 if (op->invisible && QUERY_FLAG (op, FLAG_ALIVE)) 3204 if (op->invisible && QUERY_FLAG (op, FLAG_ALIVE))
3234 { 3205 {
3235 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
3236 return 0; 3213 return 0;
3214 }
3237 3215
3238 if (op->contr && op->contr->tmp_invis == 0) 3216 if (op->contr && op->contr->tmp_invis == 0)
3239 return 0; 3217 return 0;
3240 3218
3241 /* If monsters, they should become visible */ 3219 /* If monsters, they should become visible */
3242 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))
3243 { 3221 {
3244 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");
3245 return 1; 3223 return 1;
3246 } 3224 }
3247 } 3225 }
3248 3226
3249 return 0; 3227 return 0;
3455 else 3433 else
3456 { 3434 {
3457 /* generate misc. treasure */ 3435 /* generate misc. treasure */
3458 tmp = arch_to_object (tr->item); 3436 tmp = arch_to_object (tr->item);
3459 new_draw_info_format (NDI_UNIQUE | NDI_BLUE, 0, who, "You gained %s", query_short_name (tmp)); 3437 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); 3438 who->insert (tmp);
3461 if (who->type == PLAYER)
3462 esrv_send_item (who, tmp);
3463 } 3439 }
3464} 3440}
3465 3441
3466/** 3442/**
3467 * Unready an object for a player. This function does nothing if the object was 3443 * Unready an object for a player. This function does nothing if the object was
3479 if (pl->ranged_ob == ob) 3455 if (pl->ranged_ob == ob)
3480 pl->ranged_ob = 0; 3456 pl->ranged_ob = 0;
3481} 3457}
3482 3458
3483sint8 3459sint8
3484player::visibility_at (maptile *map, int x, int y) const 3460player::darkness_at (maptile *map, int x, int y) const
3485{ 3461{
3486 if (!ns) 3462 if (!ns)
3487 return 0; 3463 return LOS_BLOCKED;
3488 3464
3489 int dx, dy; 3465 int dx, dy;
3490 if (!adjacent_map (map, ns->current_map, &dx, &dy)) 3466 if (!adjacent_map (map, ns->current_map, &dx, &dy))
3491 return 0; 3467 return LOS_BLOCKED;
3492 3468
3493 x += dx - ns->current_x + ns->mapx / 2; 3469 x += dx - ns->current_x;
3494 y += dy - ns->current_y + ns->mapy / 2; 3470 y += dy - ns->current_y;
3495 3471
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]; 3472 return blocked_los (x, y);
3500} 3473}
3501 3474
3502void 3475void
3503player::infobox (const char *title, const char *msg, int color) 3476player::infobox (const char *title, const char *msg, int color)
3504{ 3477{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines