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.66 by root, Mon Feb 5 02:07:40 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
9 the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version. 11 * (at your option) any later version.
11 12 *
12 This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 16 * GNU General Public License for more details.
16 17 *
17 You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software 19 * along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 21 *
21 The authors can be reached via e-mail to <crossfire@schmorp.de> 22 * The authors can be reached via e-mail to <crossfire@schmorp.de>
22*/ 23 */
23 24
24#include <global.h> 25#include <global.h>
25#include <living.h> 26#include <living.h>
26#include <spells.h> 27#include <spells.h>
27#include <skills.h> 28#include <skills.h>
64 { 65 {
65 arch_flag = 1; 66 arch_flag = 1;
66 name_flag = 1; 67 name_flag = 1;
67 race_flag = 1; 68 race_flag = 1;
68 } 69 }
70
69 /* If the director has race set, only affect objects with a arch, 71 /* If the director has race set, only affect objects with a arch,
70 * name or race that matches. 72 * name or race that matches.
71 */ 73 */
72 if ((op->race) && 74 if ((op->race) &&
73 ((!(victim->arch && arch_flag && victim->arch->name) || strcmp (op->race, victim->arch->name))) && 75 ((!(victim->arch && arch_flag && victim->arch->name) || op->race != victim->arch->name)) &&
74 ((!(victim->name && name_flag) || strcmp (op->race, victim->name))) && 76 ((!(victim->name && name_flag) || op->race != victim->name)) &&
75 ((!(victim->race && race_flag) || strcmp (op->race, victim->race)))) 77 ((!(victim->race && race_flag) || op->race != victim->race)))
76 {
77 return 1; 78 return 1;
78 } 79
79 /* If the director has slaying set, only affect objects where none 80 /* If the director has slaying set, only affect objects where none
80 * of arch, name, or race match. 81 * of arch, name, or race match.
81 */ 82 */
82 if ((op->slaying) && (((victim->arch && arch_flag && victim->arch->name && !strcmp (op->slaying, victim->arch->name))) || 83 if ((op->slaying) && (((victim->arch && arch_flag && victim->arch->name && op->slaying == victim->arch->name))) ||
83 ((victim->name && name_flag && !strcmp (op->slaying, victim->name))) || 84 ((victim->name && name_flag && op->slaying == victim->name)) ||
84 ((victim->race && race_flag && !strcmp (op->slaying, victim->race))))) 85 ((victim->race && race_flag && op->slaying == victim->race)))
85 {
86 return 1; 86 return 1;
87 } 87
88 return 0; 88 return 0;
89} 89}
90 90
91/** 91/**
92 * This handles a player dropping money on an altar to identify stuff. 92 * This handles a player dropping money on an altar to identify stuff.
421 int count = 0; 421 int count = 0;
422 422
423 423
424 if (item == NULL) 424 if (item == NULL)
425 return 0; 425 return 0;
426
426 op = op->below; 427 op = op->below;
427 while (op != NULL) 428 while (op != NULL)
428 { 429 {
429 if (strcmp (op->arch->name, item) == 0) 430 if (strcmp (op->arch->name, item) == 0)
430 { 431 {
435 count++; 436 count++;
436 else 437 else
437 count += op->nrof; 438 count += op->nrof;
438 } 439 }
439 } 440 }
441
440 op = op->below; 442 op = op->below;
441 } 443 }
444
442 return count; 445 return count;
443} 446}
444 447
445/** 448/**
446 * This removes 'nrof' of what item->slaying says to remove. 449 * This removes 'nrof' of what item->slaying says to remove.
978 else 981 else
979 { 982 {
980 if (converter->other_arch == NULL) 983 if (converter->other_arch == NULL)
981 { 984 {
982 LOG (llevError, "move_creator: Converter doesn't have other arch set: %s (%s, %d, %d)\n", 985 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); 986 &converter->name, &converter->map->path, converter->x, converter->y);
984 return -1; 987 return -1;
985 } 988 }
986 989
987 item = object_create_arch (converter->other_arch); 990 item = object_create_arch (converter->other_arch);
988 fix_generated_item (item, converter, 0, 0, GT_MINIMAL); 991 fix_generated_item (item, converter, 0, 0, GT_MINIMAL);
995 if (is_in_shop (converter)) 998 if (is_in_shop (converter))
996 SET_FLAG (item, FLAG_UNPAID); 999 SET_FLAG (item, FLAG_UNPAID);
997 else if (price_in < item->nrof * item->value) 1000 else if (price_in < item->nrof * item->value)
998 { 1001 {
999 LOG (llevDebug, "converter output price higher than input: %s at %s (%d, %d) in value %d, out value %d for %s\n", 1002 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); 1003 &converter->name, &converter->map->path, converter->x, converter->y, price_in, item->nrof * item->value, &item->name);
1001 1004
1002 /** 1005 /**
1003 * elmex: we are going to let the game continue, as the mapcreator 1006 * elmex: we are going to let the game continue, as the mapcreator
1004 * propably had something in mind when doing this 1007 * propably had something in mind when doing this
1005 */ 1008 */
1627 1630
1628 1631
1629 case CONVERTER: 1632 case CONVERTER:
1630 if (convert_item (victim, trap) < 0) 1633 if (convert_item (victim, trap) < 0)
1631 { 1634 {
1632 object *op;
1633
1634 new_draw_info_format (NDI_UNIQUE, 0, originator, "The %s seems to be broken!", query_name (trap)); 1635 new_draw_info_format (NDI_UNIQUE, 0, originator, "The %s seems to be broken!", query_name (trap));
1635 1636 get_archetype ("burnout")->insert_at (trap, trap);
1636 op = get_archetype ("burnout");
1637 if (op != NULL)
1638 {
1639 op->x = trap->x;
1640 op->y = trap->y;
1641 insert_ob_in_map (op, trap->map, trap, 0);
1642 } 1637 }
1643 } 1638
1644 goto leave; 1639 goto leave;
1645 1640
1646 case TRIGGER_BUTTON: 1641 case TRIGGER_BUTTON:
1647 case TRIGGER_PEDESTAL: 1642 case TRIGGER_PEDESTAL:
1648 case TRIGGER_ALTAR: 1643 case TRIGGER_ALTAR:
1677 if (victim->type == PLAYER && EXIT_PATH (trap)) 1672 if (victim->type == PLAYER && EXIT_PATH (trap))
1678 { 1673 {
1679 /* Basically, don't show exits leading to random maps the 1674 /* Basically, don't show exits leading to random maps the
1680 * players output. 1675 * players output.
1681 */ 1676 */
1682 if (trap->msg && strncmp (EXIT_PATH (trap), "/!", 2) && strncmp (EXIT_PATH (trap), "/random/", 8)) 1677 if (trap->msg && strncmp (EXIT_PATH (trap), "/!", 2))
1683 new_draw_info (NDI_NAVY, 0, victim, trap->msg); 1678 new_draw_info (NDI_NAVY, 0, victim, trap->msg);
1679
1684 enter_exit (victim, trap); 1680 victim->enter_exit (trap);
1685 } 1681 }
1686 goto leave; 1682 goto leave;
1687 1683
1688 case ENCOUNTER: 1684 case ENCOUNTER:
1689 /* may be some leftovers on this */ 1685 /* may be some leftovers on this */
2225 if (meal->type != FLESH || !is_dragon_pl (op)) 2221 if (meal->type != FLESH || !is_dragon_pl (op))
2226 return 0; 2222 return 0;
2227 2223
2228 /* now grab the 'dragon_skin'- and 'dragon_ability'-forces 2224 /* now grab the 'dragon_skin'- and 'dragon_ability'-forces
2229 from the player's inventory */ 2225 from the player's inventory */
2226 shstr_cmp dragon_ability_force ("dragon_ability_force");
2227 shstr_cmp dragon_skin_force ("dragon_skin_force");
2228
2230 for (tmp = op->inv; tmp != NULL; tmp = tmp->below) 2229 for (tmp = op->inv; tmp; tmp = tmp->below)
2231 {
2232 if (tmp->type == FORCE) 2230 if (tmp->type == FORCE)
2233 {
2234 if (strcmp (tmp->arch->name, "dragon_skin_force") == 0) 2231 if (tmp->arch->name == dragon_skin_force)
2235 skin = tmp; 2232 skin = tmp;
2236 else if (strcmp (tmp->arch->name, "dragon_ability_force") == 0) 2233 else if (tmp->arch->name == dragon_ability_force)
2237 abil = tmp; 2234 abil = tmp;
2238 }
2239 }
2240 2235
2241 /* if either skin or ability are missing, this is an old player 2236 /* if either skin or ability are missing, this is an old player
2242 which is not to be considered a dragon -> bail out */ 2237 which is not to be considered a dragon -> bail out */
2243 if (skin == NULL || abil == NULL) 2238 if (skin == NULL || abil == NULL)
2244 return 0; 2239 return 0;
2285 /* doubled chance for resistance of ability-focus */ 2280 /* doubled chance for resistance of ability-focus */
2286 if (i == abil->stats.exp) 2281 if (i == abil->stats.exp)
2287 chance = MIN (100., chance * 2.); 2282 chance = MIN (100., chance * 2.);
2288 2283
2289 /* now make the throw and save all winners (Don't insert luck bonus here!) */ 2284 /* now make the throw and save all winners (Don't insert luck bonus here!) */
2290 if (RANDOM () % 10000 < (int) (chance * 100)) 2285 if (rndm (10000) < (int) (chance * 100))
2291 { 2286 {
2292 atnr_winner[winners] = i; 2287 atnr_winner[winners] = i;
2293 winners++; 2288 winners++;
2294 } 2289 }
2295 2290
2410 handle_apply_yield (tmp); 2405 handle_apply_yield (tmp);
2411 decrease_ob (tmp); 2406 decrease_ob (tmp);
2412} 2407}
2413 2408
2414/** 2409/**
2415 * This fonction return true if the exit is not a 2 ways one or it is 2 ways, valid exit. 2410 * 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: 2411 * A valid 2 way exit means:
2417 * -You can come back (there is another exit at the other side) 2412 * -You can come back (there is another exit at the other side)
2418 * -You are 2413 * -You are
2419 * ° the owner of the exit 2414 * ° the owner of the exit
2420 * ° or in the same party as the owner 2415 * ° or in the same party as the owner
2424 * survive in the swapping (in fact the whole exit doesn't survive). 2419 * survive in the swapping (in fact the whole exit doesn't survive).
2425 */ 2420 */
2426int 2421int
2427is_legal_2ways_exit (object *op, object *exit) 2422is_legal_2ways_exit (object *op, object *exit)
2428{ 2423{
2429 object *tmp;
2430 object *exit_owner;
2431 player *pp;
2432 maptile *exitmap;
2433
2434 if (exit->stats.exp != 1) 2424 if (exit->stats.exp != 1)
2435 return 1; /*This is not a 2 way, so it is legal */ 2425 return 1; /*This is not a 2 way, so it is legal */
2426
2427#if 0 //TODO
2436 if (!has_been_loaded (EXIT_PATH (exit)) && exit->race) 2428 if (!has_been_loaded (EXIT_PATH (exit)) && exit->race)
2437 return 0; /* This is a reset town portal */ 2429 return 0; /* This is a reset town portal */
2438 /* To know if an exit has a correspondant, we look at 2430#endif
2439 * all the exits in destination and try to find one with same path as 2431
2440 * the current exit's position */ 2432 maptile *exitmap = maptile::find_sync (EXIT_PATH (exit), exit->map);
2441 if (!strncmp (EXIT_PATH (exit), settings.localdir, strlen (settings.localdir))) 2433
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) 2434 if (exitmap)
2446 { 2435 {
2436 exitmap->load_sync ();
2437
2447 tmp = GET_MAP_OB (exitmap, EXIT_X (exit), EXIT_Y (exit)); 2438 object *tmp = exitmap->at (EXIT_X (exit), EXIT_Y (exit)).bot;
2439
2448 if (!tmp) 2440 if (!tmp)
2449 return 0; 2441 return 0;
2450 for ((tmp = GET_MAP_OB (exitmap, EXIT_X (exit), EXIT_Y (exit))); tmp; tmp = tmp->above) 2442
2443 for (; tmp; tmp = tmp->above)
2451 { 2444 {
2452 if (tmp->type != EXIT) 2445 if (tmp->type != EXIT)
2453 continue; /*Not an exit */ 2446 continue; /*Not an exit */
2447
2454 if (!EXIT_PATH (tmp)) 2448 if (!EXIT_PATH (tmp))
2455 continue; /*Not a valid exit */ 2449 continue; /*Not a valid exit */
2450
2456 if ((EXIT_X (tmp) != exit->x) || (EXIT_Y (tmp) != exit->y)) 2451 if ((EXIT_X (tmp) != exit->x) || (EXIT_Y (tmp) != exit->y))
2457 continue; /*Not in the same place */ 2452 continue; /*Not in the same place */
2453
2458 if (strcmp (exit->map->path, EXIT_PATH (tmp)) != 0) 2454 if (exit->map->path != EXIT_PATH (tmp))
2459 continue; /*Not in the same map */ 2455 continue; /*Not in the same map */
2460 2456
2461 /* From here we have found the exit is valid. However we do 2457 /* 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 2458 * here the check of the exit owner. It is important for the
2463 * town portals to prevent strangers from visiting your appartments 2459 * town portals to prevent strangers from visiting your appartments
2464 */ 2460 */
2465 if (!exit->race) 2461 if (!exit->race)
2466 return 1; /*No owner, free for all! */ 2462 return 1; /*No owner, free for all! */
2463
2467 exit_owner = NULL; 2464 object *exit_owner = 0;
2468 for (pp = first_player; pp; pp = pp->next) 2465
2466 for_all_players (pp)
2469 { 2467 {
2470 if (!pp->ob) 2468 if (!pp->ob)
2471 continue; 2469 continue;
2470
2472 if (pp->ob->name != exit->race) 2471 if (pp->ob->name != exit->race)
2473 continue; 2472 continue;
2473
2474 exit_owner = pp->ob; /*We found a player which correspond to the player name */ 2474 exit_owner = pp->ob; /*We found a player which correspond to the player name */
2475 break; 2475 break;
2476 } 2476 }
2477
2477 if (!exit_owner) 2478 if (!exit_owner)
2478 return 0; /* No more owner */ 2479 return 0; /* No more owner */
2480
2479 if (exit_owner->contr == op->contr) 2481 if (exit_owner->contr == op->contr)
2480 return 1; /*It is your exit */ 2482 return 1; /*It is your exit */
2483
2481 if (exit_owner && /*There is a owner */ 2484 if (exit_owner && /*There is a owner */
2482 (op->contr) && /*A player tries to pass */ 2485 (op->contr) && /*A player tries to pass */
2483 ((exit_owner->contr->party == NULL) || /*No pass if controller has no party */ 2486 ((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 */ 2487 (exit_owner->contr->party != op->contr->party))) /* Or not the same as op */
2485 return 0; 2488 return 0;
2489
2486 return 1; 2490 return 1;
2487 } 2491 }
2488 } 2492 }
2493
2489 return 0; 2494 return 0;
2490} 2495}
2491 2496
2492 2497
2493/** 2498/**
2543 { 2548 {
2544 new_draw_info (NDI_UNIQUE, 0, op, "You turn the handle."); 2549 new_draw_info (NDI_UNIQUE, 0, op, "You turn the handle.");
2545 play_sound_map (tmp->map, tmp->x, tmp->y, SOUND_TURN_HANDLE); 2550 play_sound_map (tmp->map, tmp->x, tmp->y, SOUND_TURN_HANDLE);
2546 } 2551 }
2547 else 2552 else
2548 {
2549 new_draw_info (NDI_UNIQUE, 0, op, "The handle doesn't move."); 2553 new_draw_info (NDI_UNIQUE, 0, op, "The handle doesn't move.");
2550 } 2554
2551 return 1; 2555 return 1;
2552 2556
2553 case EXIT: 2557 case EXIT:
2554 if (op->type != PLAYER) 2558 if (op->type != PLAYER)
2555 return 0; 2559 return 0;
2560
2556 if (!EXIT_PATH (tmp) || !is_legal_2ways_exit (op, tmp)) 2561 if (!EXIT_PATH (tmp) || !is_legal_2ways_exit (op, tmp))
2557 { 2562 {
2558 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s is closed.", query_name (tmp)); 2563 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s is closed.", query_name (tmp));
2559 } 2564 }
2560 else 2565 else
2561 { 2566 {
2562 /* Don't display messages for random maps. */ 2567 /* Don't display messages for random maps. */
2563 if (tmp->msg && strncmp (EXIT_PATH (tmp), "/!", 2) && strncmp (EXIT_PATH (tmp), "/random/", 8)) 2568 if (tmp->msg && strncmp (EXIT_PATH (tmp), "/!", 2))
2564 new_draw_info (NDI_NAVY, 0, op, tmp->msg); 2569 new_draw_info (NDI_NAVY, 0, op, tmp->msg);
2570
2565 enter_exit (op, tmp); 2571 op->enter_exit (tmp);
2566 } 2572 }
2567 return 1; 2573 return 1;
2568 2574
2569 case SIGN: 2575 case SIGN:
2570 apply_sign (op, tmp, 0); 2576 apply_sign (op, tmp, 0);
3327 } 3333 }
3328 else 3334 else
3329 { 3335 {
3330 if (who->contr->unapply == unapply_never || (i & CAN_APPLY_UNAPPLY_CHOICE && who->contr->unapply == unapply_nochoice)) 3336 if (who->contr->unapply == unapply_never || (i & CAN_APPLY_UNAPPLY_CHOICE && who->contr->unapply == unapply_nochoice))
3331 { 3337 {
3332 new_draw_info (NDI_UNIQUE, 0, who, "You need to unapply some item(s):"); 3338 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); 3339 unapply_for_ob (who, op, AP_PRINT);
3334 return 1; 3340 return 1;
3335 } 3341 }
3336 else if (who->contr->unapply == unapply_always || !(i & CAN_APPLY_UNAPPLY_CHOICE)) 3342 else if (who->contr->unapply == unapply_always || !(i & CAN_APPLY_UNAPPLY_CHOICE))
3337 { 3343 {
3339 if (i) 3345 if (i)
3340 return 1; 3346 return 1;
3341 } 3347 }
3342 } 3348 }
3343 } 3349 }
3350
3344 if (op->skill && op->type != SKILL && op->type != SKILL_TOOL) 3351 if (op->skill && op->type != SKILL && op->type != SKILL_TOOL)
3345 { 3352 {
3346 skop = find_skill_by_name (who, op->skill); 3353 skop = find_skill_by_name (who, op->skill);
3347 if (!skop) 3354 if (!skop)
3348 { 3355 {
3388 new_draw_info (NDI_UNIQUE, 0, who, "It would consume your soul!."); 3395 new_draw_info (NDI_UNIQUE, 0, who, "It would consume your soul!.");
3389 if (tmp != NULL) 3396 if (tmp != NULL)
3390 (void) insert_ob_in_ob (tmp, who); 3397 (void) insert_ob_in_ob (tmp, who);
3391 return 1; 3398 return 1;
3392 } 3399 }
3400
3401 //TODO: this obviously fails for players using a shiorter prefix
3402 // i.e. "R" can use Ragnarok's swors.
3393 if (op->level && (strncmp (op->name, who->name, strlen (who->name)))) 3403 if (op->level && (strncmp (op->name, who->name, strlen (who->name))))
3394 { 3404 {
3395 /* if the weapon does not have the name as the character, can't use it. */ 3405 /* if the weapon does not have the name as the character, can't use it. */
3396 /* (Ragnarok's sword attempted to be used by Foo: won't work) */ 3406 /* (Ragnarok's sword attempted to be used by Foo: won't work) */
3397 new_draw_info (NDI_UNIQUE, 0, who, "The weapon does not recognize you as its owner."); 3407 new_draw_info (NDI_UNIQUE, 0, who, "The weapon does not recognize you as its owner.");
3408
3398 if (tmp != NULL) 3409 if (tmp)
3399 (void) insert_ob_in_ob (tmp, who); 3410 insert_ob_in_ob (tmp, who);
3411
3400 return 1; 3412 return 1;
3401 } 3413 }
3414
3402 SET_FLAG (op, FLAG_APPLIED); 3415 SET_FLAG (op, FLAG_APPLIED);
3403 3416
3404 if (skop) 3417 if (skop)
3405 change_skill (who, skop, 1); 3418 change_skill (who, skop, 1);
3406 if (!QUERY_FLAG (who, FLAG_READY_WEAPON)) 3419 if (!QUERY_FLAG (who, FLAG_READY_WEAPON))
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);
3822 /* check for hp, sp change */ 3828 /* check for hp, sp change */
3823 if (food->stats.hp != 0) 3829 if (food->stats.hp != 0)
3824 { 3830 {
3825 if (QUERY_FLAG (food, FLAG_CURSED)) 3831 if (QUERY_FLAG (food, FLAG_CURSED))
3826 { 3832 {
3827 strcpy (who->contr->killer, food->name); 3833 assign (who->contr->killer, food->name);
3828 hit_player (who, food->stats.hp, food, AT_POISON, 1); 3834 hit_player (who, food->stats.hp, food, AT_POISON, 1);
3829 new_draw_info (NDI_UNIQUE, 0, who, "Eck!...that was poisonous!"); 3835 new_draw_info (NDI_UNIQUE, 0, who, "Eck!...that was poisonous!");
3830 } 3836 }
3831 else 3837 else
3832 { 3838 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines