ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/player.C
(Generate patch)

Comparing deliantra/server/server/player.C (file contents):
Revision 1.177 by root, Thu Dec 27 15:32:41 2007 UTC vs.
Revision 1.187 by root, Mon Apr 21 07:07:36 2008 UTC

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);
321 combat_ob = op; 321 combat_ob = op;
322 break; 322 break;
323 } 323 }
324 324
325 ob->change_weapon (combat_ob ? combat_ob : ranged_ob); 325 ob->change_weapon (combat_ob ? combat_ob : ranged_ob);
326 ob->deactivate (); // change_Weapon activates, fix this better
326} 327}
327 328
328void 329void
329player::set_observe (object *op) 330player::set_observe (object *op)
330{ 331{
403 * Note: there MUST be at least one player archetype! 404 * Note: there MUST be at least one player archetype!
404 */ 405 */
405archetype * 406archetype *
406get_player_archetype (archetype *at) 407get_player_archetype (archetype *at)
407{ 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
408 archvec::iterator i = at ? archetypes.find (at) : archetypes.begin (); 415 archvec::iterator i = archetypes.find (nat);
409 416
410 for (;;) 417 for (;;)
411 { 418 {
412 if (++i == archetypes.end ()) 419 if (++i == archetypes.end ())
413 i = archetypes.begin (); 420 i = archetypes.begin ();
631 638
632 return firstdir; 639 return firstdir;
633} 640}
634 641
635void 642void
636give_initial_items (object *pl, treasurelist * items) 643give_initial_items (object *pl, treasurelist *items)
637{ 644{
638 if (pl->randomitems) 645 if (pl->randomitems)
639 create_treasure (items, pl, GT_STARTEQUIP | GT_ONLY_GOOD, 1, 0); 646 create_treasure (items, pl, GT_STARTEQUIP | GT_ONLY_GOOD, 1, 0);
640 647
641 for (object *next, *op = pl->inv; op; op = next) 648 for (object *next, *op = pl->inv; op; op = next)
651 /* we never give weapons/armour if these cannot be used 658 /* we never give weapons/armour if these cannot be used
652 * by this player due to race restrictions 659 * by this player due to race restrictions
653 */ 660 */
654 if (pl->type == PLAYER) 661 if (pl->type == PLAYER)
655 { 662 {
656 if ((!QUERY_FLAG (pl, FLAG_USE_ARMOUR) && 663 if ((!QUERY_FLAG (pl, FLAG_USE_ARMOUR)
664 &&
657 (op->type == ARMOUR || op->type == BOOTS || 665 (op->type == ARMOUR || op->type == BOOTS
658 op->type == CLOAK || op->type == HELMET || 666 || op->type == CLOAK || op->type == HELMET
659 op->type == SHIELD || op->type == GLOVES || 667 || op->type == SHIELD || op->type == GLOVES
668 || op->type == BRACERS || op->type == GIRDLE))
660 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))
661 { 670 {
662 op->destroy (); 671 op->destroy ();
663 continue; 672 continue;
664 } 673 }
665 } 674 }
691 700
692 if (op->type == SPELLBOOK && op->inv) 701 if (op->type == SPELLBOOK && op->inv)
693 CLEAR_FLAG (op->inv, FLAG_STARTEQUIP); 702 CLEAR_FLAG (op->inv, FLAG_STARTEQUIP);
694 703
695 /* Give starting characters identified, uncursed, and undamned 704 /* Give starting characters identified, uncursed, and undamned
696 * 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
697 * merged properly. 706 * merged properly.
698 */ 707 */
699 if (need_identify (op)) 708 if (need_identify (op))
700 { 709 {
701 SET_FLAG (op, FLAG_IDENTIFIED); 710 SET_FLAG (op, FLAG_IDENTIFIED);
702 CLEAR_FLAG (op, FLAG_CURSED); 711 CLEAR_FLAG (op, FLAG_CURSED);
703 CLEAR_FLAG (op, FLAG_DAMNED); 712 CLEAR_FLAG (op, FLAG_DAMNED);
704 } 713 }
714
705 if (op->type == SPELL) 715 if (op->type == SPELL)
706 { 716 {
707 op->destroy (); 717 op->destroy ();
708 continue; 718 continue;
709 } 719 }
711 { 721 {
712 SET_FLAG (op, FLAG_CAN_USE_SKILL); 722 SET_FLAG (op, FLAG_CAN_USE_SKILL);
713 op->stats.exp = 0; 723 op->stats.exp = 0;
714 op->level = 1; 724 op->level = 1;
715 } 725 }
716 /* lock all 'normal items by default */ 726 else /* lock all 'normal items by default */
717 else
718 SET_FLAG (op, FLAG_INV_LOCKED); 727 SET_FLAG (op, FLAG_INV_LOCKED);
719 } /* for loop of objects in player inv */ 728 } /* for loop of objects in player inv */
720 729
721 /* Need to set up the skill pointers */ 730 /* Need to set up the skill pointers */
722 link_player_skills (pl); 731 link_player_skills (pl);
1351 * found object is returned. 1360 * found object is returned.
1352 */ 1361 */
1353object * 1362object *
1354find_arrow (object *op, const char *type) 1363find_arrow (object *op, const char *type)
1355{ 1364{
1356 object *tmp = 0;
1357
1358 for (op = op->inv; op; op = op->below) 1365 for (object *tmp = op->inv; tmp; tmp = tmp->below)
1359 if (!tmp && op->type == CONTAINER && op->race == type && QUERY_FLAG (op, FLAG_APPLIED))
1360 tmp = find_arrow (splay (op), type);
1361 else if (op->type == ARROW && op->race == type) 1366 if (tmp->type == ARROW && !strcmp (&tmp->race, type))
1362 return splay (op); 1367 return splay (tmp);
1363 1368
1369 for (object *tmp = op->inv; tmp; tmp = tmp->below)
1370 if (tmp->type == CONTAINER && QUERY_FLAG (tmp, FLAG_APPLIED) && !strcmp (&tmp->race, type))
1371 if (object *arrow = find_arrow (tmp, type))
1372 {
1373 splay (tmp);
1374 return arrow;
1375 }
1376
1364 return tmp; 1377 return 0;
1365} 1378}
1366 1379
1367/* 1380/*
1368 * Similar to find_arrow, but looks for (roughly) the best arrow to use 1381 * Similar to find_arrow, but looks for (roughly) the best arrow to use
1369 * against the target. A full test is not performed, simply a basic test 1382 * against the target. A full test is not performed, simply a basic test
1590 arrow->destroy (); 1603 arrow->destroy ();
1591 return 0; 1604 return 0;
1592 } 1605 }
1593 1606
1594 left = arrow; /* these are arrows left to the player */ 1607 left = arrow; /* these are arrows left to the player */
1595 arrow = get_split_ob (arrow, 1); 1608 arrow = arrow->split ();
1596 if (!arrow) 1609 if (!arrow)
1597 { 1610 {
1598 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);
1599 return 0; 1612 return 0;
1600 } 1613 }
1667 op->play_sound (sound_find ("fire_arrow")); 1680 op->play_sound (sound_find ("fire_arrow"));
1668 m->insert (arrow, sx, sy, op); 1681 m->insert (arrow, sx, sy, op);
1669 1682
1670 if (!arrow->destroyed ()) 1683 if (!arrow->destroyed ())
1671 move_arrow (arrow); 1684 move_arrow (arrow);
1672
1673 if (op->type == PLAYER)
1674 {
1675 if (left->destroyed ())
1676 esrv_del_item (op->contr, left->count);
1677 else
1678 esrv_send_item (op, left);
1679 }
1680 1685
1681 return 1; 1686 return 1;
1682} 1687}
1683 1688
1684/* Special fire code for players - this takes into 1689/* Special fire code for players - this takes into
1974 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);
1975 remove_door2 (door); /* remove door without violence ;-) */ 1980 remove_door2 (door); /* remove door without violence ;-) */
1976 } 1981 }
1977 1982
1978 /* Do this after we print the message */ 1983 /* Do this after we print the message */
1979 decrease_ob (key); /* Use up one of the keys */ 1984 key->decrease (); /* Use up one of the keys */
1980 /* Need to update the weight the container the key was in */ 1985 /* Need to update the weight the container the key was in */
1981 if (container != op) 1986 if (container != op)
1982 esrv_update_item (UPD_WEIGHT, op, container); 1987 esrv_update_item (UPD_WEIGHT, op, container);
1983 1988
1984 return 1; /* Nothing more to do below */ 1989 return 1; /* Nothing more to do below */
2168bool 2173bool
2169move_player (object *op, int dir) 2174move_player (object *op, int dir)
2170{ 2175{
2171 int pick; 2176 int pick;
2172 2177
2173 if (!op->map || op->map->in_memory != MAP_IN_MEMORY) 2178 if (!op->map || op->map->in_memory != MAP_ACTIVE)
2174 return 0; 2179 return 0;
2175 2180
2176 /* Sanity check: make sure dir is valid */ 2181 /* Sanity check: make sure dir is valid */
2177 if ((dir < 0) || (dir >= 9)) 2182 if ((dir < 0) || (dir >= 9))
2178 { 2183 {
2921 2926
2922 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))))
2923 { 2928 {
2924 if (tmp->nrof > 1) 2929 if (tmp->nrof > 1)
2925 { 2930 {
2926 tmp2 = get_split_ob (tmp, 1 + RANDOM () % (tmp->nrof - 1)); 2931 tmp->decrease (rndm (1, tmp->nrof - 1));
2927 tmp2->destroy ();
2928 insert_ob_in_map (tmp, op->map, NULL, 0); 2932 insert_ob_in_map (tmp, op->map, NULL, 0);
2929 } 2933 }
2930 else 2934 else
2931 tmp->destroy (); 2935 tmp->destroy ();
2932 } 2936 }
2943void 2947void
2944fix_weight (void) 2948fix_weight (void)
2945{ 2949{
2946 for_all_players (pl) 2950 for_all_players (pl)
2947 { 2951 {
2948 int old = pl->ob->carrying, sum = sum_weight (pl->ob); 2952 sint32 old = pl->ob->carrying;
2949 2953
2950 if (old == sum) 2954 pl->ob->update_weight ();
2951 continue; 2955
2956 if (old != pl->ob->carrying)
2957 {
2952 pl->ob->update_stats (); 2958 pl->ob->update_stats ();
2953 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 }
2954 } 2961 }
2955} 2962}
2956 2963
2957void 2964void
2958fix_luck (void) 2965fix_luck (void)
3044 * as bad as carrying a light on a pitch dark map */ 3051 * as bad as carrying a light on a pitch dark map */
3045 if (has_carried_lights (ob)) 3052 if (has_carried_lights (ob))
3046 level = -(10 + (2 * ob->map->darkness)); 3053 level = -(10 + (2 * ob->map->darkness));
3047 3054
3048 /* scan through all nearby squares for terrain to hide in */ 3055 /* scan through all nearby squares for terrain to hide in */
3049 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])
3050 { 3059 {
3051 mflag = get_map_flags (ob->map, NULL, x, y, NULL, NULL); 3060 mflag = get_map_flags (ob->map, NULL, x, y, NULL, NULL);
3052 if (mflag & P_OUT_OF_MAP) 3061 if (mflag & P_OUT_OF_MAP)
3053 {
3054 continue; 3062 continue;
3055 } 3063
3056 if (mflag & P_BLOCKSVIEW) /* something to hide near! */ 3064 if (mflag & P_BLOCKSVIEW) /* something to hide near! */
3057 level += 2; 3065 level += 2;
3058 else /* open terrain! */ 3066 else /* open terrain! */
3059 level -= 1; 3067 level -= 1;
3060 } 3068 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines