… | |
… | |
215 | |
215 | |
216 | /* make sure he's a player -- needed because of class change. */ |
216 | /* make sure he's a player -- needed because of class change. */ |
217 | ob->type = PLAYER; // we are paranoid |
217 | ob->type = PLAYER; // we are paranoid |
218 | ob->race = ob->arch->race; |
218 | ob->race = ob->arch->race; |
219 | |
219 | |
220 | ob->carrying = sum_weight (ob); |
220 | ob->update_weight (); |
221 | link_player_skills (ob); |
221 | link_player_skills (ob); |
222 | |
222 | |
223 | CLEAR_FLAG (ob, FLAG_NO_FIX_PLAYER); |
223 | CLEAR_FLAG (ob, FLAG_NO_FIX_PLAYER); |
224 | |
224 | |
225 | assign (title, ob->arch->object::name); |
225 | assign (title, ob->arch->object::name); |
… | |
… | |
404 | * Note: there MUST be at least one player archetype! |
404 | * Note: there MUST be at least one player archetype! |
405 | */ |
405 | */ |
406 | archetype * |
406 | archetype * |
407 | get_player_archetype (archetype *at) |
407 | get_player_archetype (archetype *at) |
408 | { |
408 | { |
|
|
409 | // archetypes could have been reloaded |
|
|
410 | archetype *nat = at ? archetype::find (at->archname) : archetypes [0]; |
|
|
411 | |
|
|
412 | if (!nat) |
|
|
413 | return at; |
|
|
414 | |
409 | archvec::iterator i = at ? archetypes.find (at) : archetypes.begin (); |
415 | archvec::iterator i = archetypes.find (nat); |
410 | |
416 | |
411 | for (;;) |
417 | for (;;) |
412 | { |
418 | { |
413 | if (++i == archetypes.end ()) |
419 | if (++i == archetypes.end ()) |
414 | i = archetypes.begin (); |
420 | i = archetypes.begin (); |
… | |
… | |
632 | |
638 | |
633 | return firstdir; |
639 | return firstdir; |
634 | } |
640 | } |
635 | |
641 | |
636 | void |
642 | void |
637 | give_initial_items (object *pl, treasurelist * items) |
643 | give_initial_items (object *pl, treasurelist *items) |
638 | { |
644 | { |
639 | if (pl->randomitems) |
645 | if (pl->randomitems) |
640 | create_treasure (items, pl, GT_STARTEQUIP | GT_ONLY_GOOD, 1, 0); |
646 | create_treasure (items, pl, GT_STARTEQUIP | GT_ONLY_GOOD, 1, 0); |
641 | |
647 | |
642 | for (object *next, *op = pl->inv; op; op = next) |
648 | for (object *next, *op = pl->inv; op; op = next) |
… | |
… | |
652 | /* we never give weapons/armour if these cannot be used |
658 | /* we never give weapons/armour if these cannot be used |
653 | * by this player due to race restrictions |
659 | * by this player due to race restrictions |
654 | */ |
660 | */ |
655 | if (pl->type == PLAYER) |
661 | if (pl->type == PLAYER) |
656 | { |
662 | { |
657 | if ((!QUERY_FLAG (pl, FLAG_USE_ARMOUR) && |
663 | if ((!QUERY_FLAG (pl, FLAG_USE_ARMOUR) |
|
|
664 | && |
658 | (op->type == ARMOUR || op->type == BOOTS || |
665 | (op->type == ARMOUR || op->type == BOOTS |
659 | op->type == CLOAK || op->type == HELMET || |
666 | || op->type == CLOAK || op->type == HELMET |
660 | op->type == SHIELD || op->type == GLOVES || |
667 | || op->type == SHIELD || op->type == GLOVES |
|
|
668 | || op->type == BRACERS || op->type == GIRDLE)) |
661 | op->type == BRACERS || op->type == GIRDLE)) || (!QUERY_FLAG (pl, FLAG_USE_WEAPON) && op->type == WEAPON)) |
669 | || (!QUERY_FLAG (pl, FLAG_USE_WEAPON) && op->type == WEAPON)) |
662 | { |
670 | { |
663 | op->destroy (); |
671 | op->destroy (); |
664 | continue; |
672 | continue; |
665 | } |
673 | } |
666 | } |
674 | } |
… | |
… | |
692 | |
700 | |
693 | if (op->type == SPELLBOOK && op->inv) |
701 | if (op->type == SPELLBOOK && op->inv) |
694 | CLEAR_FLAG (op->inv, FLAG_STARTEQUIP); |
702 | CLEAR_FLAG (op->inv, FLAG_STARTEQUIP); |
695 | |
703 | |
696 | /* Give starting characters identified, uncursed, and undamned |
704 | /* Give starting characters identified, uncursed, and undamned |
697 | * items. Just don't identify gold or silver, or it won't be |
705 | * items. Just don't identify gold or silver, or it won't be |
698 | * merged properly. |
706 | * merged properly. |
699 | */ |
707 | */ |
700 | if (need_identify (op)) |
708 | if (need_identify (op)) |
701 | { |
709 | { |
702 | SET_FLAG (op, FLAG_IDENTIFIED); |
710 | SET_FLAG (op, FLAG_IDENTIFIED); |
703 | CLEAR_FLAG (op, FLAG_CURSED); |
711 | CLEAR_FLAG (op, FLAG_CURSED); |
704 | CLEAR_FLAG (op, FLAG_DAMNED); |
712 | CLEAR_FLAG (op, FLAG_DAMNED); |
705 | } |
713 | } |
|
|
714 | |
706 | if (op->type == SPELL) |
715 | if (op->type == SPELL) |
707 | { |
716 | { |
708 | op->destroy (); |
717 | op->destroy (); |
709 | continue; |
718 | continue; |
710 | } |
719 | } |
… | |
… | |
712 | { |
721 | { |
713 | SET_FLAG (op, FLAG_CAN_USE_SKILL); |
722 | SET_FLAG (op, FLAG_CAN_USE_SKILL); |
714 | op->stats.exp = 0; |
723 | op->stats.exp = 0; |
715 | op->level = 1; |
724 | op->level = 1; |
716 | } |
725 | } |
717 | /* lock all 'normal items by default */ |
726 | else /* lock all 'normal items by default */ |
718 | else |
|
|
719 | SET_FLAG (op, FLAG_INV_LOCKED); |
727 | SET_FLAG (op, FLAG_INV_LOCKED); |
720 | } /* for loop of objects in player inv */ |
728 | } /* for loop of objects in player inv */ |
721 | |
729 | |
722 | /* Need to set up the skill pointers */ |
730 | /* Need to set up the skill pointers */ |
723 | link_player_skills (pl); |
731 | link_player_skills (pl); |
… | |
… | |
1595 | arrow->destroy (); |
1603 | arrow->destroy (); |
1596 | return 0; |
1604 | return 0; |
1597 | } |
1605 | } |
1598 | |
1606 | |
1599 | left = arrow; /* these are arrows left to the player */ |
1607 | left = arrow; /* these are arrows left to the player */ |
1600 | arrow = get_split_ob (arrow, 1); |
1608 | arrow = arrow->split (); |
1601 | if (!arrow) |
1609 | if (!arrow) |
1602 | { |
1610 | { |
1603 | new_draw_info_format (NDI_UNIQUE, 0, op, "You have no %s left.", &bow->race); |
1611 | new_draw_info_format (NDI_UNIQUE, 0, op, "You have no %s left.", &bow->race); |
1604 | return 0; |
1612 | return 0; |
1605 | } |
1613 | } |
… | |
… | |
1672 | op->play_sound (sound_find ("fire_arrow")); |
1680 | op->play_sound (sound_find ("fire_arrow")); |
1673 | m->insert (arrow, sx, sy, op); |
1681 | m->insert (arrow, sx, sy, op); |
1674 | |
1682 | |
1675 | if (!arrow->destroyed ()) |
1683 | if (!arrow->destroyed ()) |
1676 | move_arrow (arrow); |
1684 | move_arrow (arrow); |
1677 | |
|
|
1678 | if (op->type == PLAYER) |
|
|
1679 | { |
|
|
1680 | if (left->destroyed ()) |
|
|
1681 | esrv_del_item (op->contr, left->count); |
|
|
1682 | else |
|
|
1683 | esrv_send_item (op, left); |
|
|
1684 | } |
|
|
1685 | |
1685 | |
1686 | return 1; |
1686 | return 1; |
1687 | } |
1687 | } |
1688 | |
1688 | |
1689 | /* Special fire code for players - this takes into |
1689 | /* Special fire code for players - this takes into |
… | |
… | |
1979 | op->statusmsg (format ("You open the door with the %s", query_short_name (key)), NDI_BROWN); |
1979 | op->statusmsg (format ("You open the door with the %s", query_short_name (key)), NDI_BROWN); |
1980 | remove_door2 (door); /* remove door without violence ;-) */ |
1980 | remove_door2 (door); /* remove door without violence ;-) */ |
1981 | } |
1981 | } |
1982 | |
1982 | |
1983 | /* Do this after we print the message */ |
1983 | /* Do this after we print the message */ |
1984 | decrease_ob (key); /* Use up one of the keys */ |
1984 | key->decrease (); /* Use up one of the keys */ |
1985 | /* Need to update the weight the container the key was in */ |
1985 | /* Need to update the weight the container the key was in */ |
1986 | if (container != op) |
1986 | if (container != op) |
1987 | esrv_update_item (UPD_WEIGHT, op, container); |
1987 | esrv_update_item (UPD_WEIGHT, op, container); |
1988 | |
1988 | |
1989 | return 1; /* Nothing more to do below */ |
1989 | return 1; /* Nothing more to do below */ |
… | |
… | |
2173 | bool |
2173 | bool |
2174 | move_player (object *op, int dir) |
2174 | move_player (object *op, int dir) |
2175 | { |
2175 | { |
2176 | int pick; |
2176 | int pick; |
2177 | |
2177 | |
2178 | if (!op->map || op->map->in_memory != MAP_IN_MEMORY) |
2178 | if (!op->map || op->map->in_memory != MAP_ACTIVE) |
2179 | return 0; |
2179 | return 0; |
2180 | |
2180 | |
2181 | /* Sanity check: make sure dir is valid */ |
2181 | /* Sanity check: make sure dir is valid */ |
2182 | if ((dir < 0) || (dir >= 9)) |
2182 | if ((dir < 0) || (dir >= 9)) |
2183 | { |
2183 | { |
… | |
… | |
2926 | |
2926 | |
2927 | if (!QUERY_FLAG (tmp, FLAG_UNIQUE) && (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || QUERY_FLAG (tmp, FLAG_NO_DROP) || !(rndm (3)))) |
2927 | if (!QUERY_FLAG (tmp, FLAG_UNIQUE) && (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || QUERY_FLAG (tmp, FLAG_NO_DROP) || !(rndm (3)))) |
2928 | { |
2928 | { |
2929 | if (tmp->nrof > 1) |
2929 | if (tmp->nrof > 1) |
2930 | { |
2930 | { |
2931 | tmp2 = get_split_ob (tmp, 1 + RANDOM () % (tmp->nrof - 1)); |
2931 | tmp->decrease (rndm (1, tmp->nrof - 1)); |
2932 | tmp2->destroy (); |
|
|
2933 | insert_ob_in_map (tmp, op->map, NULL, 0); |
2932 | insert_ob_in_map (tmp, op->map, NULL, 0); |
2934 | } |
2933 | } |
2935 | else |
2934 | else |
2936 | tmp->destroy (); |
2935 | tmp->destroy (); |
2937 | } |
2936 | } |
… | |
… | |
2948 | void |
2947 | void |
2949 | fix_weight (void) |
2948 | fix_weight (void) |
2950 | { |
2949 | { |
2951 | for_all_players (pl) |
2950 | for_all_players (pl) |
2952 | { |
2951 | { |
2953 | int old = pl->ob->carrying, sum = sum_weight (pl->ob); |
2952 | sint32 old = pl->ob->carrying; |
2954 | |
2953 | |
2955 | if (old == sum) |
2954 | pl->ob->update_weight (); |
2956 | continue; |
2955 | |
|
|
2956 | if (old != pl->ob->carrying) |
|
|
2957 | { |
2957 | pl->ob->update_stats (); |
2958 | pl->ob->update_stats (); |
2958 | LOG (llevDebug, "Fixed inventory in %s (%d -> %d)\n", &pl->ob->name, old, sum); |
2959 | LOG (llevDebug, "Fixed inventory in %s (%d -> %d)\n", &pl->ob->name, (int)old, (int)pl->ob->carrying); |
|
|
2960 | } |
2959 | } |
2961 | } |
2960 | } |
2962 | } |
2961 | |
2963 | |
2962 | void |
2964 | void |
2963 | fix_luck (void) |
2965 | fix_luck (void) |
… | |
… | |
3049 | * as bad as carrying a light on a pitch dark map */ |
3051 | * as bad as carrying a light on a pitch dark map */ |
3050 | if (has_carried_lights (ob)) |
3052 | if (has_carried_lights (ob)) |
3051 | level = -(10 + (2 * ob->map->darkness)); |
3053 | level = -(10 + (2 * ob->map->darkness)); |
3052 | |
3054 | |
3053 | /* scan through all nearby squares for terrain to hide in */ |
3055 | /* scan through all nearby squares for terrain to hide in */ |
3054 | for (i = 0, x = ob->x, y = ob->y; i < 9; i++, x = ob->x + freearr_x[i], y = ob->y + freearr_y[i]) |
3056 | for (i = 0, x = ob->x, y = ob->y; |
|
|
3057 | i <= SIZEOFFREE1; |
|
|
3058 | i++, x = ob->x + freearr_x[i], y = ob->y + freearr_y[i]) |
3055 | { |
3059 | { |
3056 | mflag = get_map_flags (ob->map, NULL, x, y, NULL, NULL); |
3060 | mflag = get_map_flags (ob->map, NULL, x, y, NULL, NULL); |
3057 | if (mflag & P_OUT_OF_MAP) |
3061 | if (mflag & P_OUT_OF_MAP) |
3058 | { |
|
|
3059 | continue; |
3062 | continue; |
3060 | } |
3063 | |
3061 | if (mflag & P_BLOCKSVIEW) /* something to hide near! */ |
3064 | if (mflag & P_BLOCKSVIEW) /* something to hide near! */ |
3062 | level += 2; |
3065 | level += 2; |
3063 | else /* open terrain! */ |
3066 | else /* open terrain! */ |
3064 | level -= 1; |
3067 | level -= 1; |
3065 | } |
3068 | } |