ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/apply.C
(Generate patch)

Comparing deliantra/server/server/apply.C (file contents):
Revision 1.50 by root, Thu Dec 21 23:37:05 2006 UTC vs.
Revision 1.51 by root, Fri Dec 22 16:34:00 2006 UTC

25#include <living.h> 25#include <living.h>
26#include <spells.h> 26#include <spells.h>
27#include <skills.h> 27#include <skills.h>
28#include <tod.h> 28#include <tod.h>
29 29
30#ifndef __CEXTRACT__
31# include <sproto.h> 30#include <sproto.h>
32#endif
33 31
34/* Want this regardless of rplay. */ 32/* Want this regardless of rplay. */
35#include <sounds.h> 33#include <sounds.h>
36 34
37/* need math lib for double-precision and pow() in dragon_eat_flesh() */ 35/* need math lib for double-precision and pow() in dragon_eat_flesh() */
219 object *depl; 217 object *depl;
220 archetype *at; 218 archetype *at;
221 219
222 if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED)) 220 if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED))
223 { 221 {
224 drain_stat (op); 222 op->drain_stat ();
225 fix_player (op); 223 op->update_stats ();
226 decrease_ob (tmp); 224 decrease_ob (tmp);
227 return 1; 225 return 1;
228 } 226 }
229 227
230 if ((at = archetype::find (ARCH_DEPLETION)) == NULL) 228 if (!(at = archetype::find (ARCH_DEPLETION)))
231 { 229 {
232 LOG (llevError, "Could not find archetype depletion\n"); 230 LOG (llevError, "Could not find archetype depletion\n");
233 return 0; 231 return 0;
234 } 232 }
235 depl = present_arch_in_ob (at, op); 233 depl = present_arch_in_ob (at, op);
236 234
237 if (depl != NULL) 235 if (depl)
238 { 236 {
239 for (i = 0; i < NUM_STATS; i++) 237 for (i = 0; i < NUM_STATS; i++)
240 if (get_attr_value (&depl->stats, i)) 238 if (get_attr_value (&depl->stats, i))
241 new_draw_info (NDI_UNIQUE, 0, op, restore_msg[i]); 239 new_draw_info (NDI_UNIQUE, 0, op, restore_msg[i]);
242 240
243 depl->destroy (); 241 depl->destroy ();
244 fix_player (op); 242 op->update_stats ();
245 } 243 }
246 else 244 else
247 new_draw_info (NDI_UNIQUE, 0, op, "You potion had no effect."); 245 new_draw_info (NDI_UNIQUE, 0, op, "You potion had no effect.");
248 246
249 decrease_ob (tmp); 247 decrease_ob (tmp);
299 297
300 if (!QUERY_FLAG (tmp, FLAG_CURSED) && !QUERY_FLAG (tmp, FLAG_DAMNED)) 298 if (!QUERY_FLAG (tmp, FLAG_CURSED) && !QUERY_FLAG (tmp, FLAG_DAMNED))
301 { 299 {
302 if (got_one) 300 if (got_one)
303 { 301 {
304 fix_player (op); 302 op->update_stats ();
305 new_draw_info (NDI_UNIQUE, 0, op, "The Gods smile upon you and remake you"); 303 new_draw_info (NDI_UNIQUE, 0, op, "The Gods smile upon you and remake you");
306 new_draw_info (NDI_UNIQUE, 0, op, "a little more in their image."); 304 new_draw_info (NDI_UNIQUE, 0, op, "a little more in their image.");
307 new_draw_info (NDI_UNIQUE, 0, op, "You feel a little more perfect."); 305 new_draw_info (NDI_UNIQUE, 0, op, "You feel a little more perfect.");
308 } 306 }
309 else 307 else
311 } 309 }
312 else 310 else
313 { /* cursed potion */ 311 { /* cursed potion */
314 if (got_one) 312 if (got_one)
315 { 313 {
316 fix_player (op); 314 op->update_stats ();
317 new_draw_info (NDI_UNIQUE, 0, op, "The Gods are angry and punish you."); 315 new_draw_info (NDI_UNIQUE, 0, op, "The Gods are angry and punish you.");
318 } 316 }
319 else 317 else
320 new_draw_info (NDI_UNIQUE, 0, op, "You are fortunate that you are so pathetic."); 318 new_draw_info (NDI_UNIQUE, 0, op, "You are fortunate that you are so pathetic.");
321 } 319 }
349 cast_spell (op, tmp, op->facing, tmp->inv, NULL); 347 cast_spell (op, tmp, op->facing, tmp->inv, NULL);
350 348
351 decrease_ob (tmp); 349 decrease_ob (tmp);
352 /* if youre dead, no point in doing this... */ 350 /* if youre dead, no point in doing this... */
353 if (!QUERY_FLAG (op, FLAG_REMOVED)) 351 if (!QUERY_FLAG (op, FLAG_REMOVED))
354 fix_player (op); 352 op->update_stats ();
355 return 1; 353 return 1;
356 } 354 }
357 355
358 /* Deal with protection potions */ 356 /* Deal with protection potions */
359 force = NULL; 357 force = NULL;
403 * that were grouped with the one consumed, his 401 * that were grouped with the one consumed, his
404 * stat will not be raised by them. fix_player just clears 402 * stat will not be raised by them. fix_player just clears
405 * up all the stats. 403 * up all the stats.
406 */ 404 */
407 CLEAR_FLAG (tmp, FLAG_APPLIED); 405 CLEAR_FLAG (tmp, FLAG_APPLIED);
408 fix_player (op); 406 op->update_stats ();
409 decrease_ob (tmp); 407 decrease_ob (tmp);
410 return 1; 408 return 1;
411} 409}
412 410
413/**************************************************************************** 411/****************************************************************************
570 weapon->last_eat++; 568 weapon->last_eat++;
571 new_draw_info_format (NDI_UNIQUE, 0, op, "Weapon's bonus to %s improved by %d", statname, sacrifice_count); 569 new_draw_info_format (NDI_UNIQUE, 0, op, "Weapon's bonus to %s improved by %d", statname, sacrifice_count);
572 decrease_ob (improver); 570 decrease_ob (improver);
573 571
574 /* So it updates the players stats and the window */ 572 /* So it updates the players stats and the window */
575 fix_player (op); 573 op->update_stats ();
576 return 1; 574 return 1;
577} 575}
578 576
579/* Types of improvements, hidden in the sp field. */ 577/* Types of improvements, hidden in the sp field. */
580#define IMPROVE_PREPARE 1 578#define IMPROVE_PREPARE 1
883 881
884 if (op->type == PLAYER) 882 if (op->type == PLAYER)
885 { 883 {
886 esrv_send_item (op, armour); 884 esrv_send_item (op, armour);
887 if (QUERY_FLAG (armour, FLAG_APPLIED)) 885 if (QUERY_FLAG (armour, FLAG_APPLIED))
888 fix_player (op); 886 op->update_stats ();
889 } 887 }
890 decrease_ob (improver); 888 decrease_ob (improver);
891 if (tmp) 889 if (tmp)
892 { 890 {
893 insert_ob_in_ob (tmp, op); 891 insert_ob_in_ob (tmp, op);
2328 2326
2329 if (i >= 0 && i < NROFATTACKS && skin->resist[i] < 95) 2327 if (i >= 0 && i < NROFATTACKS && skin->resist[i] < 95)
2330 { 2328 {
2331 /* resistance increased! */ 2329 /* resistance increased! */
2332 skin->resist[i]++; 2330 skin->resist[i]++;
2333 fix_player (op); 2331 op->update_stats ();
2334 2332
2335 sprintf (buf, "Your skin is now more resistant to %s!", change_resist_msg[i]); 2333 sprintf (buf, "Your skin is now more resistant to %s!", change_resist_msg[i]);
2336 new_draw_info (NDI_UNIQUE | NDI_RED, 0, op, buf); 2334 new_draw_info (NDI_UNIQUE | NDI_RED, 0, op, buf);
2337 } 2335 }
2338 2336
2357 } 2355 }
2358 } 2356 }
2359 return 1; 2357 return 1;
2360} 2358}
2361 2359
2362static void
2363apply_savebed (object *pl)
2364{
2365#ifndef COZY_SERVER
2366 if (!pl->contr->name_changed || !pl->stats.exp)
2367 {
2368 new_draw_info (NDI_UNIQUE, 0, pl, "You don't deserve to save your character yet.");
2369 return;
2370 }
2371#endif
2372 INVOKE_PLAYER (LOGOUT, pl->contr);
2373 /* Need to call terminate_all_pets() before we remove the player ob */
2374 terminate_all_pets (pl);
2375 pl->remove ();
2376 pl->direction = 0;
2377 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, pl, "%s leaves the game.", &pl->name);
2378
2379 /* update respawn position */
2380 strcpy (pl->contr->savebed_map, pl->map->path);
2381 pl->contr->bed_x = pl->x;
2382 pl->contr->bed_y = pl->y;
2383
2384 strcpy (pl->contr->killer, "left");
2385 check_score (pl); /* Always check score */
2386 (void) save_player (pl, 0);
2387 pl->map->players--;
2388#if MAP_MAXTIMEOUT
2389 MAP_SWAP_TIME (pl->map) = MAP_TIMEOUT (pl->map);
2390#endif
2391 play_again (pl);
2392 pl->speed = 0;
2393 update_ob_speed (pl);
2394}
2395
2396/** 2360/**
2397 * Handles applying an improve armor scroll. 2361 * Handles applying an improve armor scroll.
2398 * Does some sanity checks, then calls improve_armour. 2362 * Does some sanity checks, then calls improve_armour.
2399 */ 2363 */
2400static void 2364static void
2405 if (!QUERY_FLAG (op, FLAG_WIZCAST) && (get_map_flags (op->map, NULL, op->x, op->y, NULL, NULL) & P_NO_MAGIC)) 2369 if (!QUERY_FLAG (op, FLAG_WIZCAST) && (get_map_flags (op->map, NULL, op->x, op->y, NULL, NULL) & P_NO_MAGIC))
2406 { 2370 {
2407 new_draw_info (NDI_UNIQUE, 0, op, "Something blocks the magic of the scroll."); 2371 new_draw_info (NDI_UNIQUE, 0, op, "Something blocks the magic of the scroll.");
2408 return; 2372 return;
2409 } 2373 }
2374
2410 armor = find_marked_object (op); 2375 armor = find_marked_object (op);
2376
2411 if (!armor) 2377 if (!armor)
2412 { 2378 {
2413 new_draw_info (NDI_UNIQUE, 0, op, "You need to mark an armor object."); 2379 new_draw_info (NDI_UNIQUE, 0, op, "You need to mark an armor object.");
2414 return; 2380 return;
2415 } 2381 }
2382
2416 if (armor->type != ARMOUR 2383 if (armor->type != ARMOUR
2417 && armor->type != CLOAK 2384 && armor->type != CLOAK
2418 && armor->type != BOOTS && armor->type != GLOVES && armor->type != BRACERS && armor->type != SHIELD && armor->type != HELMET) 2385 && armor->type != BOOTS && armor->type != GLOVES && armor->type != BRACERS && armor->type != SHIELD && armor->type != HELMET)
2419 { 2386 {
2420 new_draw_info (NDI_UNIQUE, 0, op, "Your marked item is not armour!\n"); 2387 new_draw_info (NDI_UNIQUE, 0, op, "Your marked item is not armour!\n");
2422 } 2389 }
2423 2390
2424 new_draw_info (NDI_UNIQUE, 0, op, "Applying armour enchantment."); 2391 new_draw_info (NDI_UNIQUE, 0, op, "Applying armour enchantment.");
2425 improve_armour (op, tmp, armor); 2392 improve_armour (op, tmp, armor);
2426} 2393}
2427
2428 2394
2429extern void 2395extern void
2430apply_poison (object *op, object *tmp) 2396apply_poison (object *op, object *tmp)
2431{ 2397{
2432 if (op->type == PLAYER) 2398 if (op->type == PLAYER)
2553 { 2519 {
2554 new_draw_info (NDI_UNIQUE, 0, op, "You should pay for it first."); 2520 new_draw_info (NDI_UNIQUE, 0, op, "You should pay for it first.");
2555 return 1; 2521 return 1;
2556 } 2522 }
2557 else 2523 else
2558 {
2559 return 0; /* monsters just skip unpaid items */ 2524 return 0; /* monsters just skip unpaid items */
2560 }
2561 } 2525 }
2562 2526
2563 if (INVOKE_OBJECT (APPLY, tmp, ARG_OBJECT (op))) 2527 if (INVOKE_OBJECT (APPLY, tmp, ARG_OBJECT (op)))
2564 return RESULT_INT (0); 2528 return RESULT_INT (0);
2565 2529
2566 switch (tmp->type) 2530 switch (tmp->type)
2567 { 2531 {
2568
2569 case CF_HANDLE: 2532 case CF_HANDLE:
2570 new_draw_info (NDI_UNIQUE, 0, op, "You turn the handle."); 2533 new_draw_info (NDI_UNIQUE, 0, op, "You turn the handle.");
2571 play_sound_map (op->map, op->x, op->y, SOUND_TURN_HANDLE); 2534 play_sound_map (op->map, op->x, op->y, SOUND_TURN_HANDLE);
2572 tmp->value = tmp->value ? 0 : 1; 2535 tmp->value = tmp->value ? 0 : 1;
2573 SET_ANIMATION (tmp, tmp->value); 2536 SET_ANIMATION (tmp, tmp->value);
2701 case POISON: 2664 case POISON:
2702 apply_poison (op, tmp); 2665 apply_poison (op, tmp);
2703 return 1; 2666 return 1;
2704 2667
2705 case SAVEBED: 2668 case SAVEBED:
2706 if (op->type == PLAYER)
2707 {
2708 apply_savebed (op);
2709 return 1; 2669 return 1;
2710 }
2711 else
2712 {
2713 return 0;
2714 }
2715 2670
2716 case ARMOUR_IMPROVER: 2671 case ARMOUR_IMPROVER:
2717 if (op->type == PLAYER) 2672 if (op->type == PLAYER)
2718 { 2673 {
2719 apply_armour_improver (op, tmp); 2674 apply_armour_improver (op, tmp);
2720 return 1; 2675 return 1;
2721 } 2676 }
2722 else 2677 else
2723 {
2724 return 0; 2678 return 0;
2725 }
2726 2679
2727 case WEAPON_IMPROVER: 2680 case WEAPON_IMPROVER:
2728 (void) check_improve_weapon (op, tmp); 2681 (void) check_improve_weapon (op, tmp);
2729 return 1; 2682 return 1;
2730 2683
2955 if (who->type == PLAYER) 2908 if (who->type == PLAYER)
2956 esrv_del_item (who->contr, op->count); 2909 esrv_del_item (who->contr, op->count);
2957 2910
2958 op->destroy (); 2911 op->destroy ();
2959 insert_ob_in_ob (tmp2, who); 2912 insert_ob_in_ob (tmp2, who);
2960 fix_player (who); 2913 who->update_stats ();
2961 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED)) 2914 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED))
2962 { 2915 {
2963 if (who->type == PLAYER) 2916 if (who->type == PLAYER)
2964 { 2917 {
2965 new_draw_info (NDI_UNIQUE, 0, who, "Oops, it feels deadly cold!"); 2918 new_draw_info (NDI_UNIQUE, 0, who, "Oops, it feels deadly cold!");
2998 default: 2951 default:
2999 new_draw_info_format (NDI_UNIQUE, 0, who, "You unapply %s.", query_name (op)); 2952 new_draw_info_format (NDI_UNIQUE, 0, who, "You unapply %s.", query_name (op));
3000 break; 2953 break;
3001 } 2954 }
3002 2955
3003 fix_player (who); 2956 who->update_stats ();
3004 2957
3005 if (!(aflags & AP_NO_MERGE)) 2958 if (!(aflags & AP_NO_MERGE))
3006 { 2959 {
3007 object *tmp; 2960 object *tmp;
3008 2961
3497 { 3450 {
3498 (void) insert_ob_in_ob (tmp, who); 3451 (void) insert_ob_in_ob (tmp, who);
3499 if (who->type == PLAYER) 3452 if (who->type == PLAYER)
3500 esrv_send_item (who, tmp); 3453 esrv_send_item (who, tmp);
3501 } 3454 }
3502 fix_player (who); 3455 who->update_stats ();
3503 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED)) 3456 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED))
3504 { 3457 {
3505 if (who->type == PLAYER) 3458 if (who->type == PLAYER)
3506 { 3459 {
3507 new_draw_info (NDI_UNIQUE, 0, who, "Oops, it feels deadly cold!"); 3460 new_draw_info (NDI_UNIQUE, 0, who, "Oops, it feels deadly cold!");
3604 SET_FLAG (op, FLAG_APPLIED); 3557 SET_FLAG (op, FLAG_APPLIED);
3605 3558
3606 if (tmp != NULL) 3559 if (tmp != NULL)
3607 tmp = insert_ob_in_ob (tmp, who); 3560 tmp = insert_ob_in_ob (tmp, who);
3608 3561
3609 fix_player (who); 3562 who->update_stats ();
3610 3563
3611 /* We exclude spell casting objects. The fire code will set the 3564 /* We exclude spell casting objects. The fire code will set the
3612 * been applied flag when they are used - until that point, 3565 * been applied flag when they are used - until that point,
3613 * you don't know anything about them. 3566 * you don't know anything about them.
3614 */ 3567 */
3898 new_draw_info (NDI_UNIQUE, 0, who, "You feel a rush of magical energy!"); 3851 new_draw_info (NDI_UNIQUE, 0, who, "You feel a rush of magical energy!");
3899 who->stats.sp += food->stats.sp; 3852 who->stats.sp += food->stats.sp;
3900 /* place limit on max sp from food? */ 3853 /* place limit on max sp from food? */
3901 } 3854 }
3902 } 3855 }
3903 fix_player (who); 3856 who->update_stats ();
3904} 3857}
3905 3858
3906/** 3859/**
3907 * Designed primarily to light torches/lanterns/etc. 3860 * Designed primarily to light torches/lanterns/etc.
3908 * Also burns up burnable material too. First object in the inventory is 3861 * Also burns up burnable material too. First object in the inventory is
3956 new_draw_info_format (NDI_UNIQUE, 0, who, "You light the %s with the %s.", &item->name, &lighter->name); 3909 new_draw_info_format (NDI_UNIQUE, 0, who, "You light the %s with the %s.", &item->name, &lighter->name);
3957 /* Need to update the player so that the players glow radius 3910 /* Need to update the player so that the players glow radius
3958 * gets changed. 3911 * gets changed.
3959 */ 3912 */
3960 if (is_player_env) 3913 if (is_player_env)
3961 fix_player (who); 3914 who->update_stats ();
3962 } 3915 }
3963 else 3916 else
3964 new_draw_info_format (NDI_UNIQUE, 0, who, "You attempt to light the %s with the %s and fail.", &item->name, &lighter->name); 3917 new_draw_info_format (NDI_UNIQUE, 0, who, "You attempt to light the %s with the %s and fail.", &item->name, &lighter->name);
3965 } 3918 }
3966 else /* nothing to light */ 3919 else /* nothing to light */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines