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.58 by root, Thu Jan 4 16:19:32 2007 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines