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.51 by root, Fri Dec 22 16:34:00 2006 UTC vs.
Revision 1.59 by pippijn, Sat Jan 6 14:42:30 2007 UTC

1/* 1/*
2 CrossFire, A Multiplayer game for X-windows 2 CrossFire, A Multiplayer game for X-windows
3 3
4 Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
4 Copyright (C) 2001 Mark Wedel & Crossfire Development Team 5 Copyright (C) 2001 Mark Wedel & Crossfire Development Team
5 Copyright (C) 1992 Frank Tore Johansen 6 Copyright (C) 1992 Frank Tore Johansen
6 7
7 This program is free software; you can redistribute it and/or modify 8 This program is free software; you can redistribute it and/or modify
8 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
978 else 979 else
979 { 980 {
980 if (converter->other_arch == NULL) 981 if (converter->other_arch == NULL)
981 { 982 {
982 LOG (llevError, "move_creator: Converter doesn't have other arch set: %s (%s, %d, %d)\n", 983 LOG (llevError, "move_creator: Converter doesn't have other arch set: %s (%s, %d, %d)\n",
983 &converter->name, converter->map->path, converter->x, converter->y); 984 &converter->name, &converter->map->path, converter->x, converter->y);
984 return -1; 985 return -1;
985 } 986 }
986 987
987 item = object_create_arch (converter->other_arch); 988 item = object_create_arch (converter->other_arch);
988 fix_generated_item (item, converter, 0, 0, GT_MINIMAL); 989 fix_generated_item (item, converter, 0, 0, GT_MINIMAL);
995 if (is_in_shop (converter)) 996 if (is_in_shop (converter))
996 SET_FLAG (item, FLAG_UNPAID); 997 SET_FLAG (item, FLAG_UNPAID);
997 else if (price_in < item->nrof * item->value) 998 else if (price_in < item->nrof * item->value)
998 { 999 {
999 LOG (llevDebug, "converter output price higher than input: %s at %s (%d, %d) in value %d, out value %d for %s\n", 1000 LOG (llevDebug, "converter output price higher than input: %s at %s (%d, %d) in value %d, out value %d for %s\n",
1000 &converter->name, converter->map->path, converter->x, converter->y, price_in, item->nrof * item->value, &item->name); 1001 &converter->name, &converter->map->path, converter->x, converter->y, price_in, item->nrof * item->value, &item->name);
1001 1002
1002 /** 1003 /**
1003 * elmex: we are going to let the game continue, as the mapcreator 1004 * elmex: we are going to let the game continue, as the mapcreator
1004 * propably had something in mind when doing this 1005 * propably had something in mind when doing this
1005 */ 1006 */
1677 if (victim->type == PLAYER && EXIT_PATH (trap)) 1678 if (victim->type == PLAYER && EXIT_PATH (trap))
1678 { 1679 {
1679 /* Basically, don't show exits leading to random maps the 1680 /* Basically, don't show exits leading to random maps the
1680 * players output. 1681 * players output.
1681 */ 1682 */
1682 if (trap->msg && strncmp (EXIT_PATH (trap), "/!", 2) && strncmp (EXIT_PATH (trap), "/random/", 8)) 1683 if (trap->msg && strncmp (EXIT_PATH (trap), "/!", 2))
1683 new_draw_info (NDI_NAVY, 0, victim, trap->msg); 1684 new_draw_info (NDI_NAVY, 0, victim, trap->msg);
1685
1684 enter_exit (victim, trap); 1686 victim->enter_exit (trap);
1685 } 1687 }
1686 goto leave; 1688 goto leave;
1687 1689
1688 case ENCOUNTER: 1690 case ENCOUNTER:
1689 /* may be some leftovers on this */ 1691 /* may be some leftovers on this */
2410 handle_apply_yield (tmp); 2412 handle_apply_yield (tmp);
2411 decrease_ob (tmp); 2413 decrease_ob (tmp);
2412} 2414}
2413 2415
2414/** 2416/**
2415 * This fonction return true if the exit is not a 2 ways one or it is 2 ways, valid exit. 2417 * This function return true if the exit is not a 2 ways one or it is 2 ways, valid exit.
2416 * A valid 2 way exit means: 2418 * A valid 2 way exit means:
2417 * -You can come back (there is another exit at the other side) 2419 * -You can come back (there is another exit at the other side)
2418 * -You are 2420 * -You are
2419 * ° the owner of the exit 2421 * ° the owner of the exit
2420 * ° or in the same party as the owner 2422 * ° or in the same party as the owner
2424 * survive in the swapping (in fact the whole exit doesn't survive). 2426 * survive in the swapping (in fact the whole exit doesn't survive).
2425 */ 2427 */
2426int 2428int
2427is_legal_2ways_exit (object *op, object *exit) 2429is_legal_2ways_exit (object *op, object *exit)
2428{ 2430{
2429 object *tmp;
2430 object *exit_owner;
2431 player *pp;
2432 maptile *exitmap;
2433
2434 if (exit->stats.exp != 1) 2431 if (exit->stats.exp != 1)
2435 return 1; /*This is not a 2 way, so it is legal */ 2432 return 1; /*This is not a 2 way, so it is legal */
2433
2434#if 0 //TODO
2436 if (!has_been_loaded (EXIT_PATH (exit)) && exit->race) 2435 if (!has_been_loaded (EXIT_PATH (exit)) && exit->race)
2437 return 0; /* This is a reset town portal */ 2436 return 0; /* This is a reset town portal */
2438 /* To know if an exit has a correspondant, we look at 2437#endif
2439 * all the exits in destination and try to find one with same path as 2438
2440 * the current exit's position */ 2439 maptile *exitmap = maptile::find_sync (EXIT_PATH (exit), exit->map);
2441 if (!strncmp (EXIT_PATH (exit), settings.localdir, strlen (settings.localdir))) 2440
2442 exitmap = ready_map_name (EXIT_PATH (exit), MAP_PLAYER_UNIQUE);
2443 else
2444 exitmap = ready_map_name (EXIT_PATH (exit), 0);
2445 if (exitmap) 2441 if (exitmap)
2446 { 2442 {
2443 exitmap->load_sync ();
2444
2447 tmp = GET_MAP_OB (exitmap, EXIT_X (exit), EXIT_Y (exit)); 2445 object *tmp = exitmap->at (EXIT_X (exit), EXIT_Y (exit)).bot;
2446
2448 if (!tmp) 2447 if (!tmp)
2449 return 0; 2448 return 0;
2450 for ((tmp = GET_MAP_OB (exitmap, EXIT_X (exit), EXIT_Y (exit))); tmp; tmp = tmp->above) 2449
2450 for (; tmp; tmp = tmp->above)
2451 { 2451 {
2452 if (tmp->type != EXIT) 2452 if (tmp->type != EXIT)
2453 continue; /*Not an exit */ 2453 continue; /*Not an exit */
2454
2454 if (!EXIT_PATH (tmp)) 2455 if (!EXIT_PATH (tmp))
2455 continue; /*Not a valid exit */ 2456 continue; /*Not a valid exit */
2457
2456 if ((EXIT_X (tmp) != exit->x) || (EXIT_Y (tmp) != exit->y)) 2458 if ((EXIT_X (tmp) != exit->x) || (EXIT_Y (tmp) != exit->y))
2457 continue; /*Not in the same place */ 2459 continue; /*Not in the same place */
2460
2458 if (strcmp (exit->map->path, EXIT_PATH (tmp)) != 0) 2461 if (strcmp (exit->map->path, EXIT_PATH (tmp)) != 0)
2459 continue; /*Not in the same map */ 2462 continue; /*Not in the same map */
2460 2463
2461 /* From here we have found the exit is valid. However we do 2464 /* From here we have found the exit is valid. However we do
2462 * here the check of the exit owner. It is important for the 2465 * here the check of the exit owner. It is important for the
2463 * town portals to prevent strangers from visiting your appartments 2466 * town portals to prevent strangers from visiting your appartments
2464 */ 2467 */
2465 if (!exit->race) 2468 if (!exit->race)
2466 return 1; /*No owner, free for all! */ 2469 return 1; /*No owner, free for all! */
2470
2467 exit_owner = NULL; 2471 object *exit_owner = 0;
2468 for (pp = first_player; pp; pp = pp->next) 2472
2473 for_all_players (pp)
2469 { 2474 {
2470 if (!pp->ob) 2475 if (!pp->ob)
2471 continue; 2476 continue;
2477
2472 if (pp->ob->name != exit->race) 2478 if (pp->ob->name != exit->race)
2473 continue; 2479 continue;
2480
2474 exit_owner = pp->ob; /*We found a player which correspond to the player name */ 2481 exit_owner = pp->ob; /*We found a player which correspond to the player name */
2475 break; 2482 break;
2476 } 2483 }
2484
2477 if (!exit_owner) 2485 if (!exit_owner)
2478 return 0; /* No more owner */ 2486 return 0; /* No more owner */
2487
2479 if (exit_owner->contr == op->contr) 2488 if (exit_owner->contr == op->contr)
2480 return 1; /*It is your exit */ 2489 return 1; /*It is your exit */
2490
2481 if (exit_owner && /*There is a owner */ 2491 if (exit_owner && /*There is a owner */
2482 (op->contr) && /*A player tries to pass */ 2492 (op->contr) && /*A player tries to pass */
2483 ((exit_owner->contr->party == NULL) || /*No pass if controller has no party */ 2493 ((exit_owner->contr->party == NULL) || /*No pass if controller has no party */
2484 (exit_owner->contr->party != op->contr->party))) /* Or not the same as op */ 2494 (exit_owner->contr->party != op->contr->party))) /* Or not the same as op */
2485 return 0; 2495 return 0;
2496
2486 return 1; 2497 return 1;
2487 } 2498 }
2488 } 2499 }
2500
2489 return 0; 2501 return 0;
2490} 2502}
2491 2503
2492 2504
2493/** 2505/**
2543 { 2555 {
2544 new_draw_info (NDI_UNIQUE, 0, op, "You turn the handle."); 2556 new_draw_info (NDI_UNIQUE, 0, op, "You turn the handle.");
2545 play_sound_map (tmp->map, tmp->x, tmp->y, SOUND_TURN_HANDLE); 2557 play_sound_map (tmp->map, tmp->x, tmp->y, SOUND_TURN_HANDLE);
2546 } 2558 }
2547 else 2559 else
2548 {
2549 new_draw_info (NDI_UNIQUE, 0, op, "The handle doesn't move."); 2560 new_draw_info (NDI_UNIQUE, 0, op, "The handle doesn't move.");
2550 } 2561
2551 return 1; 2562 return 1;
2552 2563
2553 case EXIT: 2564 case EXIT:
2554 if (op->type != PLAYER) 2565 if (op->type != PLAYER)
2555 return 0; 2566 return 0;
2567
2556 if (!EXIT_PATH (tmp) || !is_legal_2ways_exit (op, tmp)) 2568 if (!EXIT_PATH (tmp) || !is_legal_2ways_exit (op, tmp))
2557 { 2569 {
2558 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s is closed.", query_name (tmp)); 2570 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s is closed.", query_name (tmp));
2559 } 2571 }
2560 else 2572 else
2561 { 2573 {
2562 /* Don't display messages for random maps. */ 2574 /* Don't display messages for random maps. */
2563 if (tmp->msg && strncmp (EXIT_PATH (tmp), "/!", 2) && strncmp (EXIT_PATH (tmp), "/random/", 8)) 2575 if (tmp->msg && strncmp (EXIT_PATH (tmp), "/!", 2))
2564 new_draw_info (NDI_NAVY, 0, op, tmp->msg); 2576 new_draw_info (NDI_NAVY, 0, op, tmp->msg);
2577
2565 enter_exit (op, tmp); 2578 op->enter_exit (tmp);
2566 } 2579 }
2567 return 1; 2580 return 1;
2568 2581
2569 case SIGN: 2582 case SIGN:
2570 apply_sign (op, tmp, 0); 2583 apply_sign (op, tmp, 0);
3327 } 3340 }
3328 else 3341 else
3329 { 3342 {
3330 if (who->contr->unapply == unapply_never || (i & CAN_APPLY_UNAPPLY_CHOICE && who->contr->unapply == unapply_nochoice)) 3343 if (who->contr->unapply == unapply_never || (i & CAN_APPLY_UNAPPLY_CHOICE && who->contr->unapply == unapply_nochoice))
3331 { 3344 {
3332 new_draw_info (NDI_UNIQUE, 0, who, "You need to unapply some item(s):"); 3345 new_draw_info (NDI_UNIQUE, 0, who, "You need to unapply some of the following item(s) or change your applymode:");
3333 unapply_for_ob (who, op, AP_PRINT); 3346 unapply_for_ob (who, op, AP_PRINT);
3334 return 1; 3347 return 1;
3335 } 3348 }
3336 else if (who->contr->unapply == unapply_always || !(i & CAN_APPLY_UNAPPLY_CHOICE)) 3349 else if (who->contr->unapply == unapply_always || !(i & CAN_APPLY_UNAPPLY_CHOICE))
3337 { 3350 {
3339 if (i) 3352 if (i)
3340 return 1; 3353 return 1;
3341 } 3354 }
3342 } 3355 }
3343 } 3356 }
3357
3344 if (op->skill && op->type != SKILL && op->type != SKILL_TOOL) 3358 if (op->skill && op->type != SKILL && op->type != SKILL_TOOL)
3345 { 3359 {
3346 skop = find_skill_by_name (who, op->skill); 3360 skop = find_skill_by_name (who, op->skill);
3347 if (!skop) 3361 if (!skop)
3348 { 3362 {
3670 * when an original map is loaded) and performs special actions for 3684 * when an original map is loaded) and performs special actions for
3671 * certain objects (most initialization of chests and creation of 3685 * certain objects (most initialization of chests and creation of
3672 * treasures and stuff). Calls auto_apply if appropriate. 3686 * treasures and stuff). Calls auto_apply if appropriate.
3673 */ 3687 */
3674void 3688void
3675fix_auto_apply (maptile *m) 3689maptile::fix_auto_apply ()
3676{ 3690{
3677 object *tmp, *above = NULL; 3691 if (!spaces)
3678 int x, y;
3679
3680 if (m == NULL)
3681 return; 3692 return;
3682 3693
3683 for (x = 0; x < MAP_WIDTH (m); x++) 3694 for (mapspace *ms = spaces + size (); ms-- > spaces; )
3684 for (y = 0; y < MAP_HEIGHT (m); y++) 3695 for (object *tmp = ms->bot; tmp; )
3685 for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = above)
3686 { 3696 {
3687 above = tmp->above; 3697 object *above = tmp->above;
3688 3698
3689 if (tmp->inv) 3699 if (tmp->inv)
3690 { 3700 {
3691 object *invtmp, *invnext; 3701 object *invtmp, *invnext;
3692 3702
3693 for (invtmp = tmp->inv; invtmp != NULL; invtmp = invnext) 3703 for (invtmp = tmp->inv; invtmp != NULL; invtmp = invnext)
3694 { 3704 {
3695 invnext = invtmp->below; 3705 invnext = invtmp->below;
3696 3706
3697 if (QUERY_FLAG (invtmp, FLAG_AUTO_APPLY)) 3707 if (QUERY_FLAG (invtmp, FLAG_AUTO_APPLY))
3698 auto_apply (invtmp); 3708 auto_apply (invtmp);
3699 else if (invtmp->type == TREASURE && invtmp->has_random_items ()) 3709 else if (invtmp->type == TREASURE && invtmp->has_random_items ())
3700 { 3710 {
3701 while ((invtmp->stats.hp--) > 0) 3711 while ((invtmp->stats.hp--) > 0)
3702 create_treasure (invtmp->randomitems, invtmp, 0, m->difficulty, 0); 3712 create_treasure (invtmp->randomitems, invtmp, 0, difficulty, 0);
3703 3713
3704 invtmp->randomitems = NULL; 3714 invtmp->randomitems = NULL;
3705 } 3715 }
3706 else if (invtmp && invtmp->arch 3716 else if (invtmp && invtmp->arch
3707 && invtmp->type != TREASURE && invtmp->type != SPELL && invtmp->type != CLASS && invtmp->has_random_items ()) 3717 && invtmp->type != TREASURE && invtmp->type != SPELL && invtmp->type != CLASS && invtmp->has_random_items ())
3708 { 3718 {
3709 create_treasure (invtmp->randomitems, invtmp, 0, m->difficulty, 0); 3719 create_treasure (invtmp->randomitems, invtmp, 0, difficulty, 0);
3710 /* Need to clear this so that we never try to create 3720 /* Need to clear this so that we never try to create
3711 * treasure again for this object 3721 * treasure again for this object
3712 */ 3722 */
3713 invtmp->randomitems = NULL; 3723 invtmp->randomitems = NULL;
3714 } 3724 }
3715 } 3725 }
3716 /* This is really temporary - the code at the bottom will 3726 /* This is really temporary - the code at the bottom will
3717 * also set randomitems to null. The problem is there are bunches 3727 * also set randomitems to null. The problem is there are bunches
3718 * of maps/players already out there with items that have spells 3728 * of maps/players already out there with items that have spells
3719 * which haven't had the randomitems set to null yet. 3729 * which haven't had the randomitems set to null yet.
3720 * MSW 2004-05-13 3730 * MSW 2004-05-13
3721 * 3731 *
3722 * And if it's a spellbook, it's better to set randomitems to NULL too, 3732 * And if it's a spellbook, it's better to set randomitems to NULL too,
3723 * else you get two spells in the book ^_- 3733 * else you get two spells in the book ^_-
3724 * Ryo 2004-08-16 3734 * Ryo 2004-08-16
3725 */ 3735 */
3726 if (tmp->type == WAND || tmp->type == ROD || tmp->type == SCROLL 3736 if (tmp->type == WAND || tmp->type == ROD || tmp->type == SCROLL
3727 || tmp->type == HORN || tmp->type == FIREWALL || tmp->type == POTION || tmp->type == ALTAR || tmp->type == SPELLBOOK) 3737 || tmp->type == HORN || tmp->type == FIREWALL || tmp->type == POTION || tmp->type == ALTAR || tmp->type == SPELLBOOK)
3728 tmp->randomitems = NULL;
3729
3730 }
3731
3732 if (QUERY_FLAG (tmp, FLAG_AUTO_APPLY))
3733 auto_apply (tmp);
3734 else if ((tmp->type == TREASURE || (tmp->type == CONTAINER)) && tmp->has_random_items ())
3735 {
3736 while ((tmp->stats.hp--) > 0)
3737 create_treasure (tmp->randomitems, tmp, 0, m->difficulty, 0);
3738 tmp->randomitems = NULL; 3738 tmp->randomitems = NULL;
3739
3739 } 3740 }
3741
3742 if (QUERY_FLAG (tmp, FLAG_AUTO_APPLY))
3743 auto_apply (tmp);
3744 else if ((tmp->type == TREASURE || (tmp->type == CONTAINER)) && tmp->has_random_items ())
3745 {
3746 while ((tmp->stats.hp--) > 0)
3747 create_treasure (tmp->randomitems, tmp, 0, difficulty, 0);
3748 tmp->randomitems = NULL;
3749 }
3740 else if (tmp->type == TIMED_GATE) 3750 else if (tmp->type == TIMED_GATE)
3741 { 3751 {
3742 object *head = tmp->head != NULL ? tmp->head : tmp; 3752 object *head = tmp->head != NULL ? tmp->head : tmp;
3743 3753
3744 if (QUERY_FLAG (head, FLAG_IS_LINKED)) 3754 if (QUERY_FLAG (head, FLAG_IS_LINKED))
3745 {
3746 tmp->speed = 0; 3755 tmp->set_speed (0);
3747 update_ob_speed (tmp);
3748 }
3749 } 3756 }
3750 /* This function can be called everytime a map is loaded, even when 3757 /* This function can be called everytime a map is loaded, even when
3751 * swapping back in. As such, we don't want to create the treasure 3758 * swapping back in. As such, we don't want to create the treasure
3752 * over and ove again, so after we generate the treasure, blank out 3759 * over and ove again, so after we generate the treasure, blank out
3753 * randomitems so if it is swapped in again, it won't make anything. 3760 * randomitems so if it is swapped in again, it won't make anything.
3754 * This is a problem for the above objects, because they have counters 3761 * This is a problem for the above objects, because they have counters
3755 * which say how many times to make the treasure. 3762 * which say how many times to make the treasure.
3756 */ 3763 */
3757 else if (tmp && tmp->arch && tmp->type != PLAYER 3764 else if (tmp && tmp->arch && tmp->type != PLAYER
3758 && tmp->type != TREASURE && tmp->type != SPELL 3765 && tmp->type != TREASURE && tmp->type != SPELL
3759 && tmp->type != PLAYER_CHANGER && tmp->type != CLASS && tmp->has_random_items ()) 3766 && tmp->type != PLAYER_CHANGER && tmp->type != CLASS && tmp->has_random_items ())
3760 { 3767 {
3761 create_treasure (tmp->randomitems, tmp, GT_APPLY, m->difficulty, 0); 3768 create_treasure (tmp->randomitems, tmp, GT_APPLY, difficulty, 0);
3762 tmp->randomitems = NULL; 3769 tmp->randomitems = NULL;
3763 } 3770 }
3771
3772 tmp = above;
3764 } 3773 }
3765 3774
3766 for (x = 0; x < MAP_WIDTH (m); x++) 3775 for (mapspace *ms = spaces + size (); ms-- > spaces; )
3767 for (y = 0; y < MAP_HEIGHT (m); y++) 3776 for (object *tmp = ms->bot; tmp; tmp = tmp->above)
3768 for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = tmp->above)
3769 if (tmp->above && (tmp->type == TRIGGER_BUTTON || tmp->type == TRIGGER_PEDESTAL)) 3777 if (tmp->above && (tmp->type == TRIGGER_BUTTON || tmp->type == TRIGGER_PEDESTAL))
3770 check_trigger (tmp, tmp->above); 3778 check_trigger (tmp, tmp->above);
3771} 3779}
3772 3780
3773/** 3781/**
3774 * Handles player eating food that temporarily changes status (resistances, stats). 3782 * Handles player eating food that temporarily changes status (resistances, stats).
3775 * This used to call cast_change_attr(), but 3783 * This used to call cast_change_attr(), but
3806 } 3814 }
3807 } 3815 }
3808 3816
3809 if (did_one) 3817 if (did_one)
3810 { 3818 {
3811 force->speed = 0.1; 3819 force->set_speed (0.1);
3812 update_ob_speed (force);
3813 /* bigger morsel of food = longer effect time */ 3820 /* bigger morsel of food = longer effect time */
3814 force->duration = food->stats.food / 5; 3821 force->duration = food->stats.food / 5;
3815 SET_FLAG (force, FLAG_APPLIED); 3822 SET_FLAG (force, FLAG_APPLIED);
3816 change_abil (who, force); 3823 change_abil (who, force);
3817 insert_ob_in_ob (force, who); 3824 insert_ob_in_ob (force, who);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines