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.54 by root, Tue Dec 26 08:54:59 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 maptile *exitmap;
2432
2433 if (exit->stats.exp != 1) 2431 if (exit->stats.exp != 1)
2434 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 */
2435 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 */
2437#endif
2438 2438
2439 /* To know if an exit has a correspondant, we look at 2439 maptile *exitmap = maptile::find_sync (EXIT_PATH (exit), exit->map);
2440 * all the exits in destination and try to find one with same path as
2441 * the current exit's position */
2442 if (!strncmp (EXIT_PATH (exit), settings.localdir, strlen (settings.localdir)))
2443 exitmap = ready_map_name (EXIT_PATH (exit), MAP_PLAYER_UNIQUE);
2444 else
2445 exitmap = ready_map_name (EXIT_PATH (exit), 0);
2446 2440
2447 if (exitmap) 2441 if (exitmap)
2448 { 2442 {
2443 exitmap->load_sync ();
2444
2449 tmp = GET_MAP_OB (exitmap, EXIT_X (exit), EXIT_Y (exit)); 2445 object *tmp = exitmap->at (EXIT_X (exit), EXIT_Y (exit)).bot;
2450 2446
2451 if (!tmp) 2447 if (!tmp)
2452 return 0; 2448 return 0;
2453 2449
2454 for ((tmp = GET_MAP_OB (exitmap, EXIT_X (exit), EXIT_Y (exit))); tmp; tmp = tmp->above) 2450 for (; tmp; tmp = tmp->above)
2455 { 2451 {
2456 if (tmp->type != EXIT) 2452 if (tmp->type != EXIT)
2457 continue; /*Not an exit */ 2453 continue; /*Not an exit */
2458 2454
2459 if (!EXIT_PATH (tmp)) 2455 if (!EXIT_PATH (tmp))
2470 * town portals to prevent strangers from visiting your appartments 2466 * town portals to prevent strangers from visiting your appartments
2471 */ 2467 */
2472 if (!exit->race) 2468 if (!exit->race)
2473 return 1; /*No owner, free for all! */ 2469 return 1; /*No owner, free for all! */
2474 2470
2475 exit_owner = NULL; 2471 object *exit_owner = 0;
2476 2472
2477 for_all_players (pp) 2473 for_all_players (pp)
2478 { 2474 {
2479 if (!pp->ob) 2475 if (!pp->ob)
2480 continue; 2476 continue;
2559 { 2555 {
2560 new_draw_info (NDI_UNIQUE, 0, op, "You turn the handle."); 2556 new_draw_info (NDI_UNIQUE, 0, op, "You turn the handle.");
2561 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);
2562 } 2558 }
2563 else 2559 else
2564 {
2565 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.");
2566 } 2561
2567 return 1; 2562 return 1;
2568 2563
2569 case EXIT: 2564 case EXIT:
2570 if (op->type != PLAYER) 2565 if (op->type != PLAYER)
2571 return 0; 2566 return 0;
2567
2572 if (!EXIT_PATH (tmp) || !is_legal_2ways_exit (op, tmp)) 2568 if (!EXIT_PATH (tmp) || !is_legal_2ways_exit (op, tmp))
2573 { 2569 {
2574 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));
2575 } 2571 }
2576 else 2572 else
2577 { 2573 {
2578 /* Don't display messages for random maps. */ 2574 /* Don't display messages for random maps. */
2579 if (tmp->msg && strncmp (EXIT_PATH (tmp), "/!", 2) && strncmp (EXIT_PATH (tmp), "/random/", 8)) 2575 if (tmp->msg && strncmp (EXIT_PATH (tmp), "/!", 2))
2580 new_draw_info (NDI_NAVY, 0, op, tmp->msg); 2576 new_draw_info (NDI_NAVY, 0, op, tmp->msg);
2577
2581 enter_exit (op, tmp); 2578 op->enter_exit (tmp);
2582 } 2579 }
2583 return 1; 2580 return 1;
2584 2581
2585 case SIGN: 2582 case SIGN:
2586 apply_sign (op, tmp, 0); 2583 apply_sign (op, tmp, 0);
3343 } 3340 }
3344 else 3341 else
3345 { 3342 {
3346 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))
3347 { 3344 {
3348 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:");
3349 unapply_for_ob (who, op, AP_PRINT); 3346 unapply_for_ob (who, op, AP_PRINT);
3350 return 1; 3347 return 1;
3351 } 3348 }
3352 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))
3353 { 3350 {
3355 if (i) 3352 if (i)
3356 return 1; 3353 return 1;
3357 } 3354 }
3358 } 3355 }
3359 } 3356 }
3357
3360 if (op->skill && op->type != SKILL && op->type != SKILL_TOOL) 3358 if (op->skill && op->type != SKILL && op->type != SKILL_TOOL)
3361 { 3359 {
3362 skop = find_skill_by_name (who, op->skill); 3360 skop = find_skill_by_name (who, op->skill);
3363 if (!skop) 3361 if (!skop)
3364 { 3362 {
3686 * when an original map is loaded) and performs special actions for 3684 * when an original map is loaded) and performs special actions for
3687 * certain objects (most initialization of chests and creation of 3685 * certain objects (most initialization of chests and creation of
3688 * treasures and stuff). Calls auto_apply if appropriate. 3686 * treasures and stuff). Calls auto_apply if appropriate.
3689 */ 3687 */
3690void 3688void
3691fix_auto_apply (maptile *m) 3689maptile::fix_auto_apply ()
3692{ 3690{
3693 object *tmp, *above = NULL; 3691 if (!spaces)
3694 int x, y;
3695
3696 if (m == NULL)
3697 return; 3692 return;
3698 3693
3699 for (x = 0; x < m->width; x++) 3694 for (mapspace *ms = spaces + size (); ms-- > spaces; )
3700 for (y = 0; y < m->height; y++) 3695 for (object *tmp = ms->bot; tmp; )
3701 for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = above)
3702 { 3696 {
3703 above = tmp->above; 3697 object *above = tmp->above;
3704 3698
3705 if (tmp->inv) 3699 if (tmp->inv)
3706 { 3700 {
3707 object *invtmp, *invnext; 3701 object *invtmp, *invnext;
3708 3702
3709 for (invtmp = tmp->inv; invtmp != NULL; invtmp = invnext) 3703 for (invtmp = tmp->inv; invtmp != NULL; invtmp = invnext)
3710 { 3704 {
3711 invnext = invtmp->below; 3705 invnext = invtmp->below;
3712 3706
3713 if (QUERY_FLAG (invtmp, FLAG_AUTO_APPLY)) 3707 if (QUERY_FLAG (invtmp, FLAG_AUTO_APPLY))
3714 auto_apply (invtmp); 3708 auto_apply (invtmp);
3715 else if (invtmp->type == TREASURE && invtmp->has_random_items ()) 3709 else if (invtmp->type == TREASURE && invtmp->has_random_items ())
3716 { 3710 {
3717 while ((invtmp->stats.hp--) > 0) 3711 while ((invtmp->stats.hp--) > 0)
3718 create_treasure (invtmp->randomitems, invtmp, 0, m->difficulty, 0); 3712 create_treasure (invtmp->randomitems, invtmp, 0, difficulty, 0);
3719 3713
3720 invtmp->randomitems = NULL; 3714 invtmp->randomitems = NULL;
3721 } 3715 }
3722 else if (invtmp && invtmp->arch 3716 else if (invtmp && invtmp->arch
3723 && 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 ())
3724 { 3718 {
3725 create_treasure (invtmp->randomitems, invtmp, 0, m->difficulty, 0); 3719 create_treasure (invtmp->randomitems, invtmp, 0, difficulty, 0);
3726 /* Need to clear this so that we never try to create 3720 /* Need to clear this so that we never try to create
3727 * treasure again for this object 3721 * treasure again for this object
3728 */ 3722 */
3729 invtmp->randomitems = NULL; 3723 invtmp->randomitems = NULL;
3730 } 3724 }
3731 } 3725 }
3732 /* This is really temporary - the code at the bottom will 3726 /* This is really temporary - the code at the bottom will
3733 * also set randomitems to null. The problem is there are bunches 3727 * also set randomitems to null. The problem is there are bunches
3734 * of maps/players already out there with items that have spells 3728 * of maps/players already out there with items that have spells
3735 * which haven't had the randomitems set to null yet. 3729 * which haven't had the randomitems set to null yet.
3736 * MSW 2004-05-13 3730 * MSW 2004-05-13
3737 * 3731 *
3738 * 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,
3739 * else you get two spells in the book ^_- 3733 * else you get two spells in the book ^_-
3740 * Ryo 2004-08-16 3734 * Ryo 2004-08-16
3741 */ 3735 */
3742 if (tmp->type == WAND || tmp->type == ROD || tmp->type == SCROLL 3736 if (tmp->type == WAND || tmp->type == ROD || tmp->type == SCROLL
3743 || 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)
3744 tmp->randomitems = NULL;
3745
3746 }
3747
3748 if (QUERY_FLAG (tmp, FLAG_AUTO_APPLY))
3749 auto_apply (tmp);
3750 else if ((tmp->type == TREASURE || (tmp->type == CONTAINER)) && tmp->has_random_items ())
3751 {
3752 while ((tmp->stats.hp--) > 0)
3753 create_treasure (tmp->randomitems, tmp, 0, m->difficulty, 0);
3754 tmp->randomitems = NULL; 3738 tmp->randomitems = NULL;
3739
3755 } 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 }
3756 else if (tmp->type == TIMED_GATE) 3750 else if (tmp->type == TIMED_GATE)
3757 { 3751 {
3758 object *head = tmp->head != NULL ? tmp->head : tmp; 3752 object *head = tmp->head != NULL ? tmp->head : tmp;
3759 3753
3760 if (QUERY_FLAG (head, FLAG_IS_LINKED)) 3754 if (QUERY_FLAG (head, FLAG_IS_LINKED))
3761 tmp->set_speed (0); 3755 tmp->set_speed (0);
3762 } 3756 }
3763 /* 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
3764 * 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
3765 * 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
3766 * 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.
3767 * 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
3768 * which say how many times to make the treasure. 3762 * which say how many times to make the treasure.
3769 */ 3763 */
3770 else if (tmp && tmp->arch && tmp->type != PLAYER 3764 else if (tmp && tmp->arch && tmp->type != PLAYER
3771 && tmp->type != TREASURE && tmp->type != SPELL 3765 && tmp->type != TREASURE && tmp->type != SPELL
3772 && tmp->type != PLAYER_CHANGER && tmp->type != CLASS && tmp->has_random_items ()) 3766 && tmp->type != PLAYER_CHANGER && tmp->type != CLASS && tmp->has_random_items ())
3773 { 3767 {
3774 create_treasure (tmp->randomitems, tmp, GT_APPLY, m->difficulty, 0); 3768 create_treasure (tmp->randomitems, tmp, GT_APPLY, difficulty, 0);
3775 tmp->randomitems = NULL; 3769 tmp->randomitems = NULL;
3776 } 3770 }
3771
3772 tmp = above;
3777 } 3773 }
3778 3774
3779 for (x = 0; x < m->width; x++) 3775 for (mapspace *ms = spaces + size (); ms-- > spaces; )
3780 for (y = 0; y < m->height; y++) 3776 for (object *tmp = ms->bot; tmp; tmp = tmp->above)
3781 for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = tmp->above)
3782 if (tmp->above && (tmp->type == TRIGGER_BUTTON || tmp->type == TRIGGER_PEDESTAL)) 3777 if (tmp->above && (tmp->type == TRIGGER_BUTTON || tmp->type == TRIGGER_PEDESTAL))
3783 check_trigger (tmp, tmp->above); 3778 check_trigger (tmp, tmp->above);
3784} 3779}
3785 3780
3786/** 3781/**
3787 * Handles player eating food that temporarily changes status (resistances, stats). 3782 * Handles player eating food that temporarily changes status (resistances, stats).
3788 * This used to call cast_change_attr(), but 3783 * This used to call cast_change_attr(), but

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines