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.176 by root, Sun Dec 16 01:25:17 2007 UTC vs.
Revision 1.198 by root, Sat May 17 00:17:02 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
215 215
216 /* make sure he's a player -- needed because of class change. */ 216 /* make sure he's a player -- needed because of class change. */
217 ob->type = PLAYER; // we are paranoid 217 ob->type = PLAYER; // we are paranoid
218 ob->race = ob->arch->race; 218 ob->race = ob->arch->race;
219 219
220 ob->carrying = sum_weight (ob); 220 ob->update_weight ();
221 link_player_skills (ob); 221 link_player_skills (ob);
222 222
223 CLEAR_FLAG (ob, FLAG_NO_FIX_PLAYER); 223 CLEAR_FLAG (ob, FLAG_NO_FIX_PLAYER);
224 224
225 assign (title, ob->arch->object::name); 225 assign (title, ob->arch->object::name);
239 set_dragon_name (ob, abil, skin); 239 set_dragon_name (ob, abil, skin);
240 } 240 }
241 241
242 new_draw_info (NDI_UNIQUE, 0, ob, "Welcome Back!"); 242 new_draw_info (NDI_UNIQUE, 0, ob, "Welcome Back!");
243 243
244 esrv_new_player (this, ob->weight + ob->carrying); 244 esrv_new_player (this);
245 245
246 ob->update_stats (); 246 ob->update_stats ();
247 247
248 ns->floorbox_update (); 248 ns->floorbox_update ();
249 esrv_send_inventory (ob, ob); 249 esrv_send_inventory (ob, ob);
291player::set_object (object *op) 291player::set_object (object *op)
292{ 292{
293 ob = observe = op; 293 ob = observe = op;
294 ob->contr = this; /* this aren't yet in archetype */ 294 ob->contr = this; /* this aren't yet in archetype */
295 295
296 ob->speed = 1.0f; 296 ob->speed = 1.0f;
297 ob->speed_left = 0.5f; 297 ob->speed_left = 0.5f;
298 298
299 ob->direction = 5; /* So player faces south */ 299 ob->direction = 5; /* So player faces south */
300 300
301 ob->flag [FLAG_READY_WEAPON] = false; 301 ob->flag [FLAG_READY_WEAPON] = false;
302 ob->flag [FLAG_READY_SKILL] = false; 302 ob->flag [FLAG_READY_SKILL] = false;
303 ob->flag [FLAG_READY_BOW] = false; 303 ob->flag [FLAG_READY_BOW] = false;
304 304
321 combat_ob = op; 321 combat_ob = op;
322 break; 322 break;
323 } 323 }
324 324
325 ob->change_weapon (combat_ob ? combat_ob : ranged_ob); 325 ob->change_weapon (combat_ob ? combat_ob : ranged_ob);
326 ob->deactivate (); // change_weapon activates, fix this better
326} 327}
327 328
328void 329void
329player::set_observe (object *op) 330player::set_observe (object *op)
330{ 331{
403 * Note: there MUST be at least one player archetype! 404 * Note: there MUST be at least one player archetype!
404 */ 405 */
405archetype * 406archetype *
406get_player_archetype (archetype *at) 407get_player_archetype (archetype *at)
407{ 408{
409 // archetypes could have been reloaded
410 archetype *nat = at ? archetype::find (at->archname) : archetypes [0];
411
412 if (!nat)
413 return at;
414
408 archvec::iterator i = at ? archetypes.find (at) : archetypes.begin (); 415 archvec::iterator i = archetypes.find (nat);
409 416
410 for (;;) 417 for (;;)
411 { 418 {
412 if (++i == archetypes.end ()) 419 if (++i == archetypes.end ())
413 i = archetypes.begin (); 420 i = archetypes.begin ();
631 638
632 return firstdir; 639 return firstdir;
633} 640}
634 641
635void 642void
636give_initial_items (object *pl, treasurelist * items) 643give_initial_items (object *pl, treasurelist *items)
637{ 644{
638 if (pl->randomitems) 645 if (pl->randomitems)
639 create_treasure (items, pl, GT_STARTEQUIP | GT_ONLY_GOOD, 1, 0); 646 create_treasure (items, pl, GT_STARTEQUIP | GT_ONLY_GOOD, 1, 0);
640 647
641 for (object *next, *op = pl->inv; op; op = next) 648 for (object *next, *op = pl->inv; op; op = next)
651 /* we never give weapons/armour if these cannot be used 658 /* we never give weapons/armour if these cannot be used
652 * by this player due to race restrictions 659 * by this player due to race restrictions
653 */ 660 */
654 if (pl->type == PLAYER) 661 if (pl->type == PLAYER)
655 { 662 {
656 if ((!QUERY_FLAG (pl, FLAG_USE_ARMOUR) && 663 if ((!QUERY_FLAG (pl, FLAG_USE_ARMOUR)
664 &&
657 (op->type == ARMOUR || op->type == BOOTS || 665 (op->type == ARMOUR || op->type == BOOTS
658 op->type == CLOAK || op->type == HELMET || 666 || op->type == CLOAK || op->type == HELMET
659 op->type == SHIELD || op->type == GLOVES || 667 || op->type == SHIELD || op->type == GLOVES
668 || op->type == BRACERS || op->type == GIRDLE))
660 op->type == BRACERS || op->type == GIRDLE)) || (!QUERY_FLAG (pl, FLAG_USE_WEAPON) && op->type == WEAPON)) 669 || (!QUERY_FLAG (pl, FLAG_USE_WEAPON) && op->type == WEAPON))
661 { 670 {
662 op->destroy (); 671 op->destroy ();
663 continue; 672 continue;
664 } 673 }
665 } 674 }
691 700
692 if (op->type == SPELLBOOK && op->inv) 701 if (op->type == SPELLBOOK && op->inv)
693 CLEAR_FLAG (op->inv, FLAG_STARTEQUIP); 702 CLEAR_FLAG (op->inv, FLAG_STARTEQUIP);
694 703
695 /* Give starting characters identified, uncursed, and undamned 704 /* Give starting characters identified, uncursed, and undamned
696 * items. Just don't identify gold or silver, or it won't be 705 * items. Just don't identify gold or silver, or it won't be
697 * merged properly. 706 * merged properly.
698 */ 707 */
699 if (need_identify (op)) 708 if (need_identify (op))
700 { 709 {
701 SET_FLAG (op, FLAG_IDENTIFIED); 710 SET_FLAG (op, FLAG_IDENTIFIED);
702 CLEAR_FLAG (op, FLAG_CURSED); 711 CLEAR_FLAG (op, FLAG_CURSED);
703 CLEAR_FLAG (op, FLAG_DAMNED); 712 CLEAR_FLAG (op, FLAG_DAMNED);
704 } 713 }
714
705 if (op->type == SPELL) 715 if (op->type == SPELL)
706 { 716 {
707 op->destroy (); 717 op->destroy ();
708 continue; 718 continue;
709 } 719 }
711 { 721 {
712 SET_FLAG (op, FLAG_CAN_USE_SKILL); 722 SET_FLAG (op, FLAG_CAN_USE_SKILL);
713 op->stats.exp = 0; 723 op->stats.exp = 0;
714 op->level = 1; 724 op->level = 1;
715 } 725 }
716 /* lock all 'normal items by default */ 726 else /* lock all 'normal items by default */
717 else
718 SET_FLAG (op, FLAG_INV_LOCKED); 727 SET_FLAG (op, FLAG_INV_LOCKED);
719 } /* for loop of objects in player inv */ 728 } /* for loop of objects in player inv */
720 729
721 /* Need to set up the skill pointers */ 730 /* Need to set up the skill pointers */
722 link_player_skills (pl); 731 link_player_skills (pl);
828static void 837static void
829start_info (object *op) 838start_info (object *op)
830{ 839{
831 char buf[MAX_BUF]; 840 char buf[MAX_BUF];
832 841
833 sprintf (buf, "Welcome to Crossfire v%s!", VERSION); 842 sprintf (buf, "Welcome to Deliantra v%s!", VERSION);
834 new_draw_info (NDI_UNIQUE, 0, op, buf); 843 new_draw_info (NDI_UNIQUE, 0, op, buf);
835 //new_draw_info (NDI_UNIQUE, 0, op, "Press `?' for help");
836 //new_draw_info (NDI_UNIQUE, 0, op, " ");
837} 844}
838 845
839/* This function takes the key that is passed, and does the 846/* This function takes the key that is passed, and does the
840 * appropriate action with it (change race, or other things). 847 * appropriate action with it (change race, or other things).
841 * The function name is for historical reasons - now we have 848 * The function name is for historical reasons - now we have
844 */ 851 */
845void 852void
846player::chargen_race_done () 853player::chargen_race_done ()
847{ 854{
848 /* this must before then initial items are given */ 855 /* this must before then initial items are given */
849 esrv_new_player (ob->contr, ob->weight + ob->carrying); 856 esrv_new_player (ob->contr);
850 857
851 treasurelist *tl = treasurelist::find ("starting_wealth"); 858 treasurelist *tl = treasurelist::find ("starting_wealth");
852 if (tl) 859 if (tl)
853 create_treasure (tl, ob, 0, 0, 0); 860 create_treasure (tl, ob, 0, 0, 0);
854 861
857 864
858 ob->contr->ns->state = ST_PLAYING; 865 ob->contr->ns->state = ST_PLAYING;
859 866
860 if (ob->msg) 867 if (ob->msg)
861 ob->msg = 0; 868 ob->msg = 0;
862
863 /* We create this now because some of the unique maps will need it
864 * to save here.
865 */
866 {
867 char buf[MAX_BUF];
868 sprintf (buf, "%s/%s/%s", settings.localdir, settings.playerdir, &ob->name);
869 make_path_to_file (buf);
870 }
871 869
872 start_info (ob); 870 start_info (ob);
873 CLEAR_FLAG (ob, FLAG_WIZ); 871 CLEAR_FLAG (ob, FLAG_WIZ);
874 give_initial_items (ob, ob->randomitems); 872 give_initial_items (ob, ob->randomitems);
875 link_player_skills (ob); 873 link_player_skills (ob);
878 876
879 /* This moves the player to a different start map, if there 877 /* This moves the player to a different start map, if there
880 * is one for this race 878 * is one for this race
881 */ 879 */
882 if (*first_map_ext_path) 880 if (*first_map_ext_path)
883 { 881 ob->player_goto (format ("%s/%s", &first_map_ext_path, &ob->arch->archname), ob->x, ob->y);
884 object *tmp;
885 char mapname[MAX_BUF];
886
887 snprintf (mapname, MAX_BUF - 1, "%s/%s", &first_map_ext_path, &ob->arch->archname);
888 tmp = object::create ();
889 EXIT_PATH (tmp) = mapname;
890 EXIT_X (tmp) = ob->x;
891 EXIT_Y (tmp) = ob->y;
892 ob->enter_exit (tmp); /* we don't really care if it succeeded;
893 * if the map isn't there, then stay on the
894 * default initial map */
895 tmp->destroy ();
896 }
897 else 882 else
898 LOG (llevDebug, "first_map_ext_path not set\n"); 883 LOG (llevDebug, "first_map_ext_path not set\n");
899} 884}
900 885
901void 886void
1353 * found object is returned. 1338 * found object is returned.
1354 */ 1339 */
1355object * 1340object *
1356find_arrow (object *op, const char *type) 1341find_arrow (object *op, const char *type)
1357{ 1342{
1358 object *tmp = 0;
1359
1360 for (op = op->inv; op; op = op->below) 1343 for (object *tmp = op->inv; tmp; tmp = tmp->below)
1361 if (!tmp && op->type == CONTAINER && op->race == type && QUERY_FLAG (op, FLAG_APPLIED))
1362 tmp = find_arrow (splay (op), type);
1363 else if (op->type == ARROW && op->race == type) 1344 if (tmp->type == ARROW && !strcmp (&tmp->race, type))
1364 return splay (op); 1345 return splay (tmp);
1365 1346
1347 for (object *tmp = op->inv; tmp; tmp = tmp->below)
1348 if (tmp->type == CONTAINER && QUERY_FLAG (tmp, FLAG_APPLIED) && !strcmp (&tmp->race, type))
1349 if (object *arrow = find_arrow (tmp, type))
1350 {
1351 splay (tmp);
1352 return arrow;
1353 }
1354
1366 return tmp; 1355 return 0;
1367} 1356}
1368 1357
1369/* 1358/*
1370 * Similar to find_arrow, but looks for (roughly) the best arrow to use 1359 * Similar to find_arrow, but looks for (roughly) the best arrow to use
1371 * against the target. A full test is not performed, simply a basic test 1360 * against the target. A full test is not performed, simply a basic test
1394 } 1383 }
1395 } 1384 }
1396 else if (arrow->type == ARROW && arrow->race == type) 1385 else if (arrow->type == ARROW && arrow->race == type)
1397 { 1386 {
1398 /* allways prefer assasination/slaying */ 1387 /* allways prefer assasination/slaying */
1399 if (target->race != NULL && arrow->slaying != NULL && strstr (arrow->slaying, target->race)) 1388 if (target->race && arrow->slaying && strstr (arrow->slaying, target->race))
1400 { 1389 {
1401 if (arrow->attacktype & AT_DEATH) 1390 if (arrow->attacktype & AT_DEATH)
1402 { 1391 {
1403 *better = 100; 1392 *better = 100;
1404 return arrow; 1393 return arrow;
1432 betterby = 1 + arrow->magic + arrow->stats.dam; 1421 betterby = 1 + arrow->magic + arrow->stats.dam;
1433 } 1422 }
1434 } 1423 }
1435 } 1424 }
1436 } 1425 }
1426
1437 if (tmp == NULL && arrow == NULL) 1427 if (tmp == NULL && arrow == NULL)
1438 return find_arrow (op, type); 1428 return find_arrow (op, type);
1439 1429
1440 *better = betterby; 1430 *better = betterby;
1441 return tmp; 1431 return tmp;
1592 arrow->destroy (); 1582 arrow->destroy ();
1593 return 0; 1583 return 0;
1594 } 1584 }
1595 1585
1596 left = arrow; /* these are arrows left to the player */ 1586 left = arrow; /* these are arrows left to the player */
1597 arrow = get_split_ob (arrow, 1); 1587 arrow = arrow->split ();
1598 if (!arrow) 1588 if (!arrow)
1599 { 1589 {
1600 new_draw_info_format (NDI_UNIQUE, 0, op, "You have no %s left.", &bow->race); 1590 new_draw_info_format (NDI_UNIQUE, 0, op, "You have no %s left.", &bow->race);
1601 return 0; 1591 return 0;
1602 } 1592 }
1669 op->play_sound (sound_find ("fire_arrow")); 1659 op->play_sound (sound_find ("fire_arrow"));
1670 m->insert (arrow, sx, sy, op); 1660 m->insert (arrow, sx, sy, op);
1671 1661
1672 if (!arrow->destroyed ()) 1662 if (!arrow->destroyed ())
1673 move_arrow (arrow); 1663 move_arrow (arrow);
1674
1675 if (op->type == PLAYER)
1676 {
1677 if (left->destroyed ())
1678 esrv_del_item (op->contr, left->count);
1679 else
1680 esrv_send_item (op, left);
1681 }
1682 1664
1683 return 1; 1665 return 1;
1684} 1666}
1685 1667
1686/* Special fire code for players - this takes into 1668/* Special fire code for players - this takes into
1760 return; 1742 return;
1761 } 1743 }
1762 } 1744 }
1763 else if (item->type == ROD || item->type == HORN) 1745 else if (item->type == ROD || item->type == HORN)
1764 { 1746 {
1765 if (item->stats.hp < MAX (item->inv->stats.sp, item->inv->stats.grace)) 1747 sint16 spell_sp = MAX (item->inv->stats.sp, item->inv->stats.grace);
1748
1749 // using the maximum of the rods charge allows at least one spell cast
1750 // for a rod or horn, this fixes some broken rods.
1751 if (item->stats.hp < MIN (spell_sp, item->stats.maxhp))
1766 { 1752 {
1767 op->contr->play_sound (sound_find ("wand_poof")); 1753 op->contr->play_sound (sound_find ("wand_poof"));
1768 1754
1769 if (item->type == ROD) 1755 if (item->type == ROD)
1770 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s whines for a while, but nothing happens.", query_base_name (item, 0)); 1756 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s whines for a while, but nothing happens.", query_base_name (item, 0));
1789 CLEAR_FLAG (item, FLAG_ANIMATE); 1775 CLEAR_FLAG (item, FLAG_ANIMATE);
1790 item->face = item->arch->face; 1776 item->face = item->arch->face;
1791 item->set_speed (0); 1777 item->set_speed (0);
1792 } 1778 }
1793 1779
1794 if ((tmp = item->in_player ())) 1780 if (object *pl = item->visible_to ())
1795 esrv_update_item (UPD_ANIM, tmp, item); 1781 esrv_update_item (UPD_ANIM, pl, item);
1796 } 1782 }
1797 } 1783 }
1798 else if (item->type == ROD || item->type == HORN) 1784 else if (item->type == ROD || item->type == HORN)
1799 drain_rod_charge (item); 1785 drain_rod_charge (item);
1800 } 1786 }
1976 op->statusmsg (format ("You open the door with the %s", query_short_name (key)), NDI_BROWN); 1962 op->statusmsg (format ("You open the door with the %s", query_short_name (key)), NDI_BROWN);
1977 remove_door2 (door); /* remove door without violence ;-) */ 1963 remove_door2 (door); /* remove door without violence ;-) */
1978 } 1964 }
1979 1965
1980 /* Do this after we print the message */ 1966 /* Do this after we print the message */
1981 decrease_ob (key); /* Use up one of the keys */ 1967 key->decrease (); /* Use up one of the keys */
1982 /* Need to update the weight the container the key was in */
1983 if (container != op)
1984 esrv_update_item (UPD_WEIGHT, op, container);
1985 1968
1986 return 1; /* Nothing more to do below */ 1969 return 1; /* Nothing more to do below */
1987 } 1970 }
1988 else if (door->type == LOCKED_DOOR) 1971 else if (door->type == LOCKED_DOOR)
1989 { 1972 {
2170bool 2153bool
2171move_player (object *op, int dir) 2154move_player (object *op, int dir)
2172{ 2155{
2173 int pick; 2156 int pick;
2174 2157
2175 if (!op->map || op->map->in_memory != MAP_IN_MEMORY) 2158 if (!op->map || op->map->in_memory != MAP_ACTIVE)
2176 return 0; 2159 return 0;
2177 2160
2178 /* Sanity check: make sure dir is valid */ 2161 /* Sanity check: make sure dir is valid */
2179 if ((dir < 0) || (dir >= 9)) 2162 if ((dir < 0) || (dir >= 9))
2180 { 2163 {
2268 if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE)) 2251 if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE))
2269 { 2252 {
2270 op->play_sound (sound_find ("ob_evaporate")); 2253 op->play_sound (sound_find ("ob_evaporate"));
2271 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s vibrates violently, then evaporates.", query_name (tmp)); 2254 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s vibrates violently, then evaporates.", query_name (tmp));
2272 2255
2273 if (op->contr)
2274 esrv_del_item (op->contr, tmp->count);
2275
2276 tmp->destroy (); 2256 tmp->destroy ();
2277 CLEAR_FLAG (op, FLAG_LIFESAVE); 2257 CLEAR_FLAG (op, FLAG_LIFESAVE);
2278 2258
2279 if (op->stats.hp < 0) 2259 if (op->stats.hp < 0)
2280 op->stats.hp = op->stats.maxhp; 2260 op->stats.hp = op->stats.maxhp;
2292 return 0; 2272 return 0;
2293} 2273}
2294 2274
2295/* This goes throws the inventory and removes unpaid objects, and puts them 2275/* This goes throws the inventory and removes unpaid objects, and puts them
2296 * back in the map (location and map determined by values of env). This 2276 * back in the map (location and map determined by values of env). This
2297 * function will descend into containers. op is the object to start the search 2277 * function will descend into containers. op is the object to start the search
2298 * from. 2278 * from.
2299 */ 2279 */
2300static void 2280static void
2301drop_unpaid_items (object *op, object *env) 2281drop_unpaid_items (object *op, object *env)
2302{ 2282{
2303 while (op) 2283 while (op)
2304 { 2284 {
2305 object *next = op->below; /* Make sure we have a good value, in case we remove object 'op' */ 2285 object *next = op->below; /* Make sure we have a good value, in case we remove object 'op' */
2306 2286
2307 if (QUERY_FLAG (op, FLAG_UNPAID)) 2287 if (QUERY_FLAG (op, FLAG_UNPAID))
2308 {
2309 if (env->type == PLAYER)
2310 esrv_del_item (env->contr, op->count);
2311
2312 op->insert_at (env); 2288 op->insert_at (env);
2313 }
2314 else if (op->inv) 2289 else if (op->inv)
2315 drop_unpaid_items (op->inv, env); 2290 drop_unpaid_items (op->inv, env);
2316 2291
2317 op = next; 2292 op = next;
2318 } 2293 }
2330 * Moved from apply.c to player.c - player.c is what 2305 * Moved from apply.c to player.c - player.c is what
2331 * actually uses this function. player.c may not be quite the 2306 * actually uses this function. player.c may not be quite the
2332 * best, a misc file for object actions is probably better, 2307 * best, a misc file for object actions is probably better,
2333 * but there isn't one in the server directory. 2308 * but there isn't one in the server directory.
2334 */ 2309 */
2335char * 2310const char *
2336gravestone_text (object *op) 2311gravestone_text (object *op)
2337{ 2312{
2338 static char buf2[MAX_BUF]; 2313 static dynbuf_text buf;
2339 char buf[MAX_BUF];
2340 time_t now = time (NULL);
2341 2314
2342 strcpy (buf2, " R.I.P.\n\n"); 2315 buf << "---- R.I.P. ----\n\n";
2316 op->name;
2317
2343 if (op->type == PLAYER) 2318 if (op->type == PLAYER)
2344 sprintf (buf, "%s the %s\n", &op->name, op->contr->title); 2319 buf << " the " << op->contr->title;
2345 else
2346 sprintf (buf, "%s\n", &op->name);
2347 2320
2348 strncat (buf2, " ", 20 - strlen (buf) / 2); 2321 buf << "\n\n";
2349 strcat (buf2, buf); 2322
2323 buf << "who was level ";
2324 buf << (sint32)op->level << "\n\n" // OO breakdown
2325 << " when " << (op->contr ? "killed" : "died") << "\n\n";
2326
2350 if (op->type == PLAYER) 2327 if (op->type == PLAYER)
2351 sprintf (buf, "who was in level %d when killed\n", op->level); 2328 buf << "by " << op->contr->killer_name () << ".\n\n";
2352 else
2353 sprintf (buf, "who was in level %d when died.\n\n", op->level);
2354 2329
2355 strncat (buf2, " ", 20 - strlen (buf) / 2);
2356 strcat (buf2, buf);
2357 if (op->type == PLAYER)
2358 { 2330 {
2359 sprintf (buf, "by %s.\n\n", op->contr->killer); 2331 static char buf2[128];
2360 strncat (buf2, " ", 21 - strlen (buf) / 2); 2332 time_t now = time (NULL);
2361 strcat (buf2, buf);
2362 }
2363
2364 strftime (buf, MAX_BUF, "%b %d %Y\n", localtime (&now)); 2333 strftime (buf2, 128, "%b %d %Y\n\n", localtime (&now));
2365 strncat (buf2, " ", 20 - strlen (buf) / 2); 2334 buf << buf2;
2366 strcat (buf2, buf); 2335 }
2367 2336
2368 return buf2; 2337 return buf;
2369} 2338}
2370 2339
2371void 2340void
2372do_some_living (object *op) 2341do_some_living (object *op)
2373{ 2342{
2554 op->stats.food--; 2523 op->stats.food--;
2555 } 2524 }
2556 2525
2557 if (op->stats.food < 0 && op->stats.hp >= 0) 2526 if (op->stats.food < 0 && op->stats.hp >= 0)
2558 { 2527 {
2559 object *tmp, *flesh = 0; 2528 object *flesh = 0;
2560 2529
2561 for (tmp = op->inv; tmp; tmp = tmp->below) 2530 for_inv_removable (op, tmp)
2562 { 2531 {
2563 if (!QUERY_FLAG (tmp, FLAG_UNPAID)) 2532 if (QUERY_FLAG (tmp, FLAG_UNPAID))
2533 continue;
2534
2535 if (tmp->type == FOOD || tmp->type == DRINK || tmp->type == POISON)
2564 { 2536 {
2565 if (tmp->type == FOOD || tmp->type == DRINK || tmp->type == POISON) 2537 op->statusmsg ("You blindly grab for a bite of food. "
2566 { 2538 "H<To prevent you from starving, you ate some random item from your backpack.>");
2567 new_draw_info (NDI_UNIQUE, 0, op, "You blindly grab for a bite of food.");
2568 manual_apply (op, tmp, 0); 2539 manual_apply (op, tmp, 0);
2540
2569 if (op->stats.food >= 0 || op->stats.hp < 0) 2541 if (op->stats.food >= 0 || op->stats.hp < 0)
2570 break; 2542 break;
2571 } 2543 }
2572 else if (tmp->type == FLESH) 2544 else if (tmp->type == FLESH)
2573 flesh = tmp; 2545 flesh = tmp;
2574 } /* End if paid for object */ 2546 }
2575 } /* end of for loop */
2576 2547
2577 /* If player is still starving, it means they don't have any food, so 2548 /* If player is still starving, it means they don't have any food, so
2578 * eat flesh instead. 2549 * eat flesh instead.
2579 */ 2550 */
2580 if (op->stats.food < 0 && op->stats.hp >= 0 && flesh) 2551 if (op->stats.food < 0 && op->stats.hp >= 0 && flesh)
2581 { 2552 {
2582 new_draw_info (NDI_UNIQUE, 0, op, "You blindly grab for a bite of food."); 2553 op->statusmsg ("You blindly grab for a bite of food. "
2554 "H<To prevent you from starving, you ate some random item from your backpack.>");
2583 manual_apply (op, flesh, 0); 2555 manual_apply (op, flesh, 0);
2584 } 2556 }
2557
2558 // If player is still starving, alert him!
2559 if (op->stats.food < 0)
2560 op->failmsg ("You are starving! "
2561 "H<Eat some food to increase your food and prevent you from an untimely death.>");
2585 } 2562 }
2586 2563
2587 if (op->stats.food < 0) 2564 if (op->stats.food < 0)
2588 { 2565 {
2589 op->stats.hp += op->stats.food; 2566 op->stats.hp += op->stats.food;
2590 op->stats.food = 0; 2567 op->stats.food = 0;
2591 } 2568 }
2592 2569
2593 if (op->stats.hp < 0 && !QUERY_FLAG (op, FLAG_WIZ)) 2570 if (op->stats.hp < 0 && !QUERY_FLAG (op, FLAG_WIZ))
2594 kill_player (op); 2571 kill_player (op);
2647 { 2624 {
2648 tmp->name = format ("%s's finger" , &op->name); 2625 tmp->name = format ("%s's finger" , &op->name);
2649 tmp->name_pl = format ("%s's fingers", &op->name); 2626 tmp->name_pl = format ("%s's fingers", &op->name);
2650 tmp->msg = format ( 2627 tmp->msg = format (
2651 "This finger has been cut off of %s the %s, when he was defeated at level %d by %s.\n", 2628 "This finger has been cut off of %s the %s, when he was defeated at level %d by %s.\n",
2652 &op->name, op->contr->title, (int) (op->level), op->contr->killer 2629 &op->name, op->contr->title,
2630 (int)op->level,
2631 op->contr->killer_name ()
2653 ); 2632 );
2654 tmp->value = 0, tmp->type = 0; 2633 tmp->value = 0, tmp->type = 0;
2655 tmp->materialname = "organics"; 2634 tmp->materialname = "organics";
2656 tmp->insert_at (op, tmp); 2635 tmp->insert_at (op, tmp);
2657 } 2636 }
2665 INVOKE_PLAYER (DEATH, op->contr); 2644 INVOKE_PLAYER (DEATH, op->contr);
2666 2645
2667 command_kill_pets (op, 0); 2646 command_kill_pets (op, 0);
2668 2647
2669 if (op->stats.food < 0) 2648 if (op->stats.food < 0)
2670 strcpy (op->contr->killer, "starvation"); 2649 {
2650 op->contr->killer = archetype::get ("killer_starvation");
2651 op->contr->killer->destroy ();
2652 }
2671 2653
2672 op->contr->play_sound (sound_find ("player_dies")); 2654 op->contr->play_sound (sound_find ("player_dies"));
2673 2655
2674 /* save the map location for corpse, gravestone */ 2656 /* save the map location for corpse, gravestone */
2675 x = op->x; 2657 x = op->x;
2784 lost_a_stat = 1; 2766 lost_a_stat = 1;
2785 } 2767 }
2786 } 2768 }
2787 } 2769 }
2788 } 2770 }
2771
2789 /* If no stat lost, tell the player. */ 2772 /* If no stat lost, tell the player. */
2790 if (!lost_a_stat) 2773 if (!lost_a_stat)
2791 { 2774 {
2792 /* determine_god() seems to not work sometimes... why is this? 2775 /* determine_god() seems to not work sometimes... why is this?
2793 Should I be using something else? GD */ 2776 Should I be using something else? GD */
2797 new_draw_info_format (NDI_UNIQUE, 0, op, "For a brief moment you feel the holy presence of %s protecting" " you.", god); 2780 new_draw_info_format (NDI_UNIQUE, 0, op, "For a brief moment you feel the holy presence of %s protecting" " you.", god);
2798 else 2781 else
2799 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you feel a holy presence protecting you."); 2782 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you feel a holy presence protecting you.");
2800 } 2783 }
2801#else 2784#else
2802 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you" " feel a holy presence protecting you from losing yourself completely."); 2785 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you feel a holy presence protecting you from losing yourself completely.");
2803#endif 2786#endif
2804 2787
2805 /* Put a gravestone up where the character 'almost' died. List the 2788 /* Put a gravestone up where the character 'almost' died. List the
2806 * exp loss on the stone. 2789 * exp loss on the stone.
2807 */ 2790 */
2808 tmp = arch_to_object (archetype::find ("gravestone")); 2791 tmp = arch_to_object (archetype::find ("gravestone"));
2809 sprintf (buf, "%s's gravestone", &op->name); 2792 tmp->name = format ("%s's gravestone", &op->name);
2810 tmp->name = buf; 2793 tmp->name_pl = format ("%s's gravestones", &op->name);
2811 sprintf (buf, "%s's gravestones", &op->name);
2812 tmp->name_pl = buf;
2813 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); 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 ());
2814 tmp->msg = buf;
2815 tmp->x = op->x, tmp->y = op->y; 2795 tmp->x = op->x, tmp->y = op->y;
2816 insert_ob_in_map (tmp, op->map, NULL, 0); 2796 insert_ob_in_map (tmp, op->map, NULL, 0);
2817 2797
2818 /**************************************/ 2798 /**************************************/
2819 /* */ 2799 /* */
2842 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer"); 2822 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer");
2843 } 2823 }
2844 2824
2845 cure_disease (op, 0, 0); /* remove any disease */ 2825 cure_disease (op, 0, 0); /* remove any disease */
2846 2826
2827 // remove all spell effects that are active
2828 // to avoid long-term effects such as word-of-recall
2829 for (object *item = op->inv; item; )
2830 {
2831 object *next = item->below;
2832
2833 if (item->type == SPELL_EFFECT && item->active)
2834 item->destroy ();
2835
2836 item = next;
2837 }
2838
2847 /*add_exp(op, (op->stats.exp * -0.20)); */ 2839 /*add_exp(op, (op->stats.exp * -0.20)); */
2848 apply_death_exp_penalty (op); 2840 apply_death_exp_penalty (op);
2841
2849 if (op->stats.food < 100) 2842 if (op->stats.food < 100)
2850 op->stats.food = 900; 2843 op->stats.food = 900;
2844
2851 op->stats.hp = op->stats.maxhp; 2845 op->stats.hp = op->stats.maxhp;
2852 op->stats.sp = MAX (op->stats.sp, op->stats.maxsp); 2846 op->stats.sp = MAX (op->stats.sp, op->stats.maxsp);
2853 op->stats.grace = MAX (op->stats.grace, op->stats.maxgrace); 2847 op->stats.grace = MAX (op->stats.grace, op->stats.maxgrace);
2854 2848
2855 /* 2849 /*
2923 2917
2924 if (!QUERY_FLAG (tmp, FLAG_UNIQUE) && (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || QUERY_FLAG (tmp, FLAG_NO_DROP) || !(rndm (3)))) 2918 if (!QUERY_FLAG (tmp, FLAG_UNIQUE) && (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || QUERY_FLAG (tmp, FLAG_NO_DROP) || !(rndm (3))))
2925 { 2919 {
2926 if (tmp->nrof > 1) 2920 if (tmp->nrof > 1)
2927 { 2921 {
2928 tmp2 = get_split_ob (tmp, 1 + RANDOM () % (tmp->nrof - 1)); 2922 tmp->decrease (rndm (1, tmp->nrof - 1));
2929 tmp2->destroy ();
2930 insert_ob_in_map (tmp, op->map, NULL, 0); 2923 insert_ob_in_map (tmp, op->map, NULL, 0);
2931 } 2924 }
2932 else 2925 else
2933 tmp->destroy (); 2926 tmp->destroy ();
2934 } 2927 }
2945void 2938void
2946fix_weight (void) 2939fix_weight (void)
2947{ 2940{
2948 for_all_players (pl) 2941 for_all_players (pl)
2949 { 2942 {
2950 int old = pl->ob->carrying, sum = sum_weight (pl->ob); 2943 sint32 old = pl->ob->carrying;
2951 2944
2952 if (old == sum) 2945 pl->ob->update_weight ();
2953 continue; 2946
2947 if (old != pl->ob->carrying)
2948 {
2954 pl->ob->update_stats (); 2949 pl->ob->update_stats ();
2955 LOG (llevDebug, "Fixed inventory in %s (%d -> %d)\n", &pl->ob->name, old, sum); 2950 LOG (llevDebug, "Fixed inventory in %s (%d -> %d)\n", &pl->ob->name, (int)old, (int)pl->ob->carrying);
2951 }
2956 } 2952 }
2957} 2953}
2958 2954
2959void 2955void
2960fix_luck (void) 2956fix_luck (void)
3046 * as bad as carrying a light on a pitch dark map */ 3042 * as bad as carrying a light on a pitch dark map */
3047 if (has_carried_lights (ob)) 3043 if (has_carried_lights (ob))
3048 level = -(10 + (2 * ob->map->darkness)); 3044 level = -(10 + (2 * ob->map->darkness));
3049 3045
3050 /* scan through all nearby squares for terrain to hide in */ 3046 /* scan through all nearby squares for terrain to hide in */
3051 for (i = 0, x = ob->x, y = ob->y; i < 9; i++, x = ob->x + freearr_x[i], y = ob->y + freearr_y[i]) 3047 for (i = 0, x = ob->x, y = ob->y;
3048 i <= SIZEOFFREE1;
3049 i++, x = ob->x + freearr_x[i], y = ob->y + freearr_y[i])
3052 { 3050 {
3053 mflag = get_map_flags (ob->map, NULL, x, y, NULL, NULL); 3051 mflag = get_map_flags (ob->map, NULL, x, y, NULL, NULL);
3054 if (mflag & P_OUT_OF_MAP) 3052 if (mflag & P_OUT_OF_MAP)
3055 {
3056 continue; 3053 continue;
3057 } 3054
3058 if (mflag & P_BLOCKSVIEW) /* something to hide near! */ 3055 if (mflag & P_BLOCKSVIEW) /* something to hide near! */
3059 level += 2; 3056 level += 2;
3060 else /* open terrain! */ 3057 else /* open terrain! */
3061 level -= 1; 3058 level -= 1;
3062 } 3059 }
3073 * spot (surrounded by clear terrain in broad daylight). -b.t. 3070 * spot (surrounded by clear terrain in broad daylight). -b.t.
3074 */ 3071 */
3075void 3072void
3076do_hidden_move (object *op) 3073do_hidden_move (object *op)
3077{ 3074{
3078 int hide = 0, num = random_roll (0, 19, op, PREFER_LOW); 3075 int hide = 0;
3079 object *skop;
3080 3076
3081 if (!op || !op->map) 3077 if (!op || !op->map)
3082 return; 3078 return;
3083 3079
3084 skop = find_obj_by_type_subtype (op, SKILL, SK_HIDING); 3080 object *skop = find_obj_by_type_subtype (op, SKILL, SK_HIDING);
3081 int num = random_roll (0, 19, op, PREFER_LOW);
3085 3082
3086 /* its *extremely* hard to run and sneak/hide at the same time! */ 3083 /* its *extremely* hard to run and sneak/hide at the same time! */
3087 if (op->type == PLAYER && op->contr->run_on) 3084 if (op->type == PLAYER && op->contr->run_on)
3088 if (!skop || num >= skop->level) 3085 if (!skop || num >= skop->level)
3089 { 3086 {
3099 num -= hide; 3096 num -= hide;
3100 3097
3101 if ((op->type == PLAYER && hide < -10) || ((op->invisible -= num) <= 0)) 3098 if ((op->type == PLAYER && hide < -10) || ((op->invisible -= num) <= 0))
3102 { 3099 {
3103 make_visible (op); 3100 make_visible (op);
3101
3104 if (op->type == PLAYER) 3102 if (op->type == PLAYER)
3105 new_draw_info (NDI_UNIQUE, 0, op, "You moved out of hiding! You are visible!"); 3103 new_draw_info (NDI_UNIQUE, 0, op, "You moved out of hiding! You are visible!");
3106 } 3104 }
3107 else if (op->type == PLAYER && skop) 3105 else if (op->type == PLAYER && skop)
3108 change_exp (op, calc_skill_exp (op, NULL, skop), skop->skill, 0); 3106 change_exp (op, calc_skill_exp (op, NULL, skop), skop->skill, 0);
3449 else 3447 else
3450 { 3448 {
3451 /* generate misc. treasure */ 3449 /* generate misc. treasure */
3452 tmp = arch_to_object (tr->item); 3450 tmp = arch_to_object (tr->item);
3453 new_draw_info_format (NDI_UNIQUE | NDI_BLUE, 0, who, "You gained %s", query_short_name (tmp)); 3451 new_draw_info_format (NDI_UNIQUE | NDI_BLUE, 0, who, "You gained %s", query_short_name (tmp));
3454 tmp = insert_ob_in_ob (tmp, who); 3452 who->insert (tmp);
3455 if (who->type == PLAYER)
3456 esrv_send_item (who, tmp);
3457 } 3453 }
3458} 3454}
3459 3455
3460/** 3456/**
3461 * Unready an object for a player. This function does nothing if the object was 3457 * Unready an object for a player. This function does nothing if the object was

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines