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.191 by elmex, Thu Apr 24 10:42:22 2008 UTC vs.
Revision 1.198 by root, Sat May 17 00:17:02 2008 UTC

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 ob->deactivate (); // change_weapon activates, fix this better
327} 327}
328 328
329void 329void
330player::set_observe (object *op) 330player::set_observe (object *op)
331{ 331{
865 ob->contr->ns->state = ST_PLAYING; 865 ob->contr->ns->state = ST_PLAYING;
866 866
867 if (ob->msg) 867 if (ob->msg)
868 ob->msg = 0; 868 ob->msg = 0;
869 869
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); 870 start_info (ob);
880 CLEAR_FLAG (ob, FLAG_WIZ); 871 CLEAR_FLAG (ob, FLAG_WIZ);
881 give_initial_items (ob, ob->randomitems); 872 give_initial_items (ob, ob->randomitems);
882 link_player_skills (ob); 873 link_player_skills (ob);
883 esrv_send_inventory (ob, ob); 874 esrv_send_inventory (ob, ob);
885 876
886 /* This moves the player to a different start map, if there 877 /* This moves the player to a different start map, if there
887 * is one for this race 878 * is one for this race
888 */ 879 */
889 if (*first_map_ext_path) 880 if (*first_map_ext_path)
890 { 881 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 882 else
905 LOG (llevDebug, "first_map_ext_path not set\n"); 883 LOG (llevDebug, "first_map_ext_path not set\n");
906} 884}
907 885
908void 886void
1405 } 1383 }
1406 } 1384 }
1407 else if (arrow->type == ARROW && arrow->race == type) 1385 else if (arrow->type == ARROW && arrow->race == type)
1408 { 1386 {
1409 /* allways prefer assasination/slaying */ 1387 /* allways prefer assasination/slaying */
1410 if (target->race != NULL && arrow->slaying != NULL && strstr (arrow->slaying, target->race)) 1388 if (target->race && arrow->slaying && strstr (arrow->slaying, target->race))
1411 { 1389 {
1412 if (arrow->attacktype & AT_DEATH) 1390 if (arrow->attacktype & AT_DEATH)
1413 { 1391 {
1414 *better = 100; 1392 *better = 100;
1415 return arrow; 1393 return arrow;
1443 betterby = 1 + arrow->magic + arrow->stats.dam; 1421 betterby = 1 + arrow->magic + arrow->stats.dam;
1444 } 1422 }
1445 } 1423 }
1446 } 1424 }
1447 } 1425 }
1426
1448 if (tmp == NULL && arrow == NULL) 1427 if (tmp == NULL && arrow == NULL)
1449 return find_arrow (op, type); 1428 return find_arrow (op, type);
1450 1429
1451 *better = betterby; 1430 *better = betterby;
1452 return tmp; 1431 return tmp;
2326 * Moved from apply.c to player.c - player.c is what 2305 * Moved from apply.c to player.c - player.c is what
2327 * actually uses this function. player.c may not be quite the 2306 * actually uses this function. player.c may not be quite the
2328 * best, a misc file for object actions is probably better, 2307 * best, a misc file for object actions is probably better,
2329 * but there isn't one in the server directory. 2308 * but there isn't one in the server directory.
2330 */ 2309 */
2331char * 2310const char *
2332gravestone_text (object *op) 2311gravestone_text (object *op)
2333{ 2312{
2334 static char buf2[MAX_BUF]; 2313 static dynbuf_text buf;
2335 char buf[MAX_BUF];
2336 time_t now = time (NULL);
2337 2314
2338 strcpy (buf2, " R.I.P.\n\n"); 2315 buf << "---- R.I.P. ----\n\n";
2316 op->name;
2317
2339 if (op->type == PLAYER) 2318 if (op->type == PLAYER)
2340 sprintf (buf, "%s the %s\n", &op->name, op->contr->title); 2319 buf << " the " << op->contr->title;
2341 else
2342 sprintf (buf, "%s\n", &op->name);
2343 2320
2344 strncat (buf2, " ", 20 - strlen (buf) / 2); 2321 buf << "\n\n";
2345 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
2346 if (op->type == PLAYER) 2327 if (op->type == PLAYER)
2347 sprintf (buf, "who was in level %d when killed\n", op->level); 2328 buf << "by " << op->contr->killer_name () << ".\n\n";
2348 else
2349 sprintf (buf, "who was in level %d when died.\n\n", op->level);
2350 2329
2351 strncat (buf2, " ", 20 - strlen (buf) / 2);
2352 strcat (buf2, buf);
2353 if (op->type == PLAYER)
2354 { 2330 {
2355 sprintf (buf, "by %s.\n\n", op->contr->killer); 2331 static char buf2[128];
2356 strncat (buf2, " ", 21 - strlen (buf) / 2); 2332 time_t now = time (NULL);
2357 strcat (buf2, buf);
2358 }
2359
2360 strftime (buf, MAX_BUF, "%b %d %Y\n", localtime (&now)); 2333 strftime (buf2, 128, "%b %d %Y\n\n", localtime (&now));
2361 strncat (buf2, " ", 20 - strlen (buf) / 2); 2334 buf << buf2;
2362 strcat (buf2, buf); 2335 }
2363 2336
2364 return buf2; 2337 return buf;
2365} 2338}
2366 2339
2367void 2340void
2368do_some_living (object *op) 2341do_some_living (object *op)
2369{ 2342{
2550 op->stats.food--; 2523 op->stats.food--;
2551 } 2524 }
2552 2525
2553 if (op->stats.food < 0 && op->stats.hp >= 0) 2526 if (op->stats.food < 0 && op->stats.hp >= 0)
2554 { 2527 {
2555 object *tmp, *flesh = 0; 2528 object *flesh = 0;
2556 2529
2557 for (tmp = op->inv; tmp; tmp = tmp->below) 2530 for_inv_removable (op, tmp)
2558 { 2531 {
2559 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)
2560 { 2536 {
2561 if (tmp->type == FOOD || tmp->type == DRINK || tmp->type == POISON) 2537 op->statusmsg ("You blindly grab for a bite of food. "
2562 { 2538 "H<To prevent you from starving, you ate some random item from your backpack.>");
2563 new_draw_info (NDI_UNIQUE, 0, op, "You blindly grab for a bite of food.");
2564 manual_apply (op, tmp, 0); 2539 manual_apply (op, tmp, 0);
2540
2565 if (op->stats.food >= 0 || op->stats.hp < 0) 2541 if (op->stats.food >= 0 || op->stats.hp < 0)
2566 break; 2542 break;
2567 } 2543 }
2568 else if (tmp->type == FLESH) 2544 else if (tmp->type == FLESH)
2569 flesh = tmp; 2545 flesh = tmp;
2570 } /* End if paid for object */ 2546 }
2571 } /* end of for loop */
2572 2547
2573 /* 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
2574 * eat flesh instead. 2549 * eat flesh instead.
2575 */ 2550 */
2576 if (op->stats.food < 0 && op->stats.hp >= 0 && flesh) 2551 if (op->stats.food < 0 && op->stats.hp >= 0 && flesh)
2577 { 2552 {
2578 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.>");
2579 manual_apply (op, flesh, 0); 2555 manual_apply (op, flesh, 0);
2580 } 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.>");
2581 } 2562 }
2582 2563
2583 if (op->stats.food < 0) 2564 if (op->stats.food < 0)
2584 { 2565 {
2585 op->stats.hp += op->stats.food; 2566 op->stats.hp += op->stats.food;
2586 op->stats.food = 0; 2567 op->stats.food = 0;
2587 } 2568 }
2588 2569
2589 if (op->stats.hp < 0 && !QUERY_FLAG (op, FLAG_WIZ)) 2570 if (op->stats.hp < 0 && !QUERY_FLAG (op, FLAG_WIZ))
2590 kill_player (op); 2571 kill_player (op);
2643 { 2624 {
2644 tmp->name = format ("%s's finger" , &op->name); 2625 tmp->name = format ("%s's finger" , &op->name);
2645 tmp->name_pl = format ("%s's fingers", &op->name); 2626 tmp->name_pl = format ("%s's fingers", &op->name);
2646 tmp->msg = format ( 2627 tmp->msg = format (
2647 "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",
2648 &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 ()
2649 ); 2632 );
2650 tmp->value = 0, tmp->type = 0; 2633 tmp->value = 0, tmp->type = 0;
2651 tmp->materialname = "organics"; 2634 tmp->materialname = "organics";
2652 tmp->insert_at (op, tmp); 2635 tmp->insert_at (op, tmp);
2653 } 2636 }
2661 INVOKE_PLAYER (DEATH, op->contr); 2644 INVOKE_PLAYER (DEATH, op->contr);
2662 2645
2663 command_kill_pets (op, 0); 2646 command_kill_pets (op, 0);
2664 2647
2665 if (op->stats.food < 0) 2648 if (op->stats.food < 0)
2666 strcpy (op->contr->killer, "starvation"); 2649 {
2650 op->contr->killer = archetype::get ("killer_starvation");
2651 op->contr->killer->destroy ();
2652 }
2667 2653
2668 op->contr->play_sound (sound_find ("player_dies")); 2654 op->contr->play_sound (sound_find ("player_dies"));
2669 2655
2670 /* save the map location for corpse, gravestone */ 2656 /* save the map location for corpse, gravestone */
2671 x = op->x; 2657 x = op->x;
2780 lost_a_stat = 1; 2766 lost_a_stat = 1;
2781 } 2767 }
2782 } 2768 }
2783 } 2769 }
2784 } 2770 }
2771
2785 /* If no stat lost, tell the player. */ 2772 /* If no stat lost, tell the player. */
2786 if (!lost_a_stat) 2773 if (!lost_a_stat)
2787 { 2774 {
2788 /* determine_god() seems to not work sometimes... why is this? 2775 /* determine_god() seems to not work sometimes... why is this?
2789 Should I be using something else? GD */ 2776 Should I be using something else? GD */
2793 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);
2794 else 2781 else
2795 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.");
2796 } 2783 }
2797#else 2784#else
2798 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.");
2799#endif 2786#endif
2800 2787
2801 /* Put a gravestone up where the character 'almost' died. List the 2788 /* Put a gravestone up where the character 'almost' died. List the
2802 * exp loss on the stone. 2789 * exp loss on the stone.
2803 */ 2790 */
2804 tmp = arch_to_object (archetype::find ("gravestone")); 2791 tmp = arch_to_object (archetype::find ("gravestone"));
2805 sprintf (buf, "%s's gravestone", &op->name); 2792 tmp->name = format ("%s's gravestone", &op->name);
2806 tmp->name = buf; 2793 tmp->name_pl = format ("%s's gravestones", &op->name);
2807 sprintf (buf, "%s's gravestones", &op->name);
2808 tmp->name_pl = buf;
2809 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 ());
2810 tmp->msg = buf;
2811 tmp->x = op->x, tmp->y = op->y; 2795 tmp->x = op->x, tmp->y = op->y;
2812 insert_ob_in_map (tmp, op->map, NULL, 0); 2796 insert_ob_in_map (tmp, op->map, NULL, 0);
2813 2797
2814 /**************************************/ 2798 /**************************************/
2815 /* */ 2799 /* */
2838 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer"); 2822 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer");
2839 } 2823 }
2840 2824
2841 cure_disease (op, 0, 0); /* remove any disease */ 2825 cure_disease (op, 0, 0); /* remove any disease */
2842 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
2843 /*add_exp(op, (op->stats.exp * -0.20)); */ 2839 /*add_exp(op, (op->stats.exp * -0.20)); */
2844 apply_death_exp_penalty (op); 2840 apply_death_exp_penalty (op);
2841
2845 if (op->stats.food < 100) 2842 if (op->stats.food < 100)
2846 op->stats.food = 900; 2843 op->stats.food = 900;
2844
2847 op->stats.hp = op->stats.maxhp; 2845 op->stats.hp = op->stats.maxhp;
2848 op->stats.sp = MAX (op->stats.sp, op->stats.maxsp); 2846 op->stats.sp = MAX (op->stats.sp, op->stats.maxsp);
2849 op->stats.grace = MAX (op->stats.grace, op->stats.maxgrace); 2847 op->stats.grace = MAX (op->stats.grace, op->stats.maxgrace);
2850 2848
2851 /* 2849 /*
3072 * spot (surrounded by clear terrain in broad daylight). -b.t. 3070 * spot (surrounded by clear terrain in broad daylight). -b.t.
3073 */ 3071 */
3074void 3072void
3075do_hidden_move (object *op) 3073do_hidden_move (object *op)
3076{ 3074{
3077 int hide = 0, num = random_roll (0, 19, op, PREFER_LOW); 3075 int hide = 0;
3078 object *skop;
3079 3076
3080 if (!op || !op->map) 3077 if (!op || !op->map)
3081 return; 3078 return;
3082 3079
3083 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);
3084 3082
3085 /* 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! */
3086 if (op->type == PLAYER && op->contr->run_on) 3084 if (op->type == PLAYER && op->contr->run_on)
3087 if (!skop || num >= skop->level) 3085 if (!skop || num >= skop->level)
3088 { 3086 {
3098 num -= hide; 3096 num -= hide;
3099 3097
3100 if ((op->type == PLAYER && hide < -10) || ((op->invisible -= num) <= 0)) 3098 if ((op->type == PLAYER && hide < -10) || ((op->invisible -= num) <= 0))
3101 { 3099 {
3102 make_visible (op); 3100 make_visible (op);
3101
3103 if (op->type == PLAYER) 3102 if (op->type == PLAYER)
3104 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!");
3105 } 3104 }
3106 else if (op->type == PLAYER && skop) 3105 else if (op->type == PLAYER && skop)
3107 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);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines