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.175 by elmex, Mon Nov 26 12:54:32 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 object *op, *next = NULL;
639
640 if (pl->randomitems != NULL) 645 if (pl->randomitems)
641 create_treasure (items, pl, GT_STARTEQUIP | GT_ONLY_GOOD, 1, 0); 646 create_treasure (items, pl, GT_STARTEQUIP | GT_ONLY_GOOD, 1, 0);
642 647
643 for (op = pl->inv; op; op = next) 648 for (object *next, *op = pl->inv; op; op = next)
644 { 649 {
645 next = op->below; 650 next = op->below;
646 651
647 /* Forces get applied per default, unless they have the 652 /* Forces get applied per default, unless they have the
648 * flag "neutral" set. Sorry but I can't think of a better way 653 * flag "neutral" set. Sorry but I can't think of a better way
653 /* we never give weapons/armour if these cannot be used 658 /* we never give weapons/armour if these cannot be used
654 * by this player due to race restrictions 659 * by this player due to race restrictions
655 */ 660 */
656 if (pl->type == PLAYER) 661 if (pl->type == PLAYER)
657 { 662 {
658 if ((!QUERY_FLAG (pl, FLAG_USE_ARMOUR) && 663 if ((!QUERY_FLAG (pl, FLAG_USE_ARMOUR)
664 &&
659 (op->type == ARMOUR || op->type == BOOTS || 665 (op->type == ARMOUR || op->type == BOOTS
660 op->type == CLOAK || op->type == HELMET || 666 || op->type == CLOAK || op->type == HELMET
661 op->type == SHIELD || op->type == GLOVES || 667 || op->type == SHIELD || op->type == GLOVES
668 || op->type == BRACERS || op->type == GIRDLE))
662 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))
663 { 670 {
664 op->destroy (); 671 op->destroy ();
665 continue; 672 continue;
666 } 673 }
667 } 674 }
690 if (op->nrof > 1) 697 if (op->nrof > 1)
691 op->nrof = 1; 698 op->nrof = 1;
692 } 699 }
693 700
694 if (op->type == SPELLBOOK && op->inv) 701 if (op->type == SPELLBOOK && op->inv)
695 {
696 CLEAR_FLAG (op->inv, FLAG_STARTEQUIP); 702 CLEAR_FLAG (op->inv, FLAG_STARTEQUIP);
697 }
698 703
699 /* Give starting characters identified, uncursed, and undamned 704 /* Give starting characters identified, uncursed, and undamned
700 * 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
701 * merged properly. 706 * merged properly.
702 */ 707 */
703 if (need_identify (op)) 708 if (need_identify (op))
704 { 709 {
705 SET_FLAG (op, FLAG_IDENTIFIED); 710 SET_FLAG (op, FLAG_IDENTIFIED);
706 CLEAR_FLAG (op, FLAG_CURSED); 711 CLEAR_FLAG (op, FLAG_CURSED);
707 CLEAR_FLAG (op, FLAG_DAMNED); 712 CLEAR_FLAG (op, FLAG_DAMNED);
708 } 713 }
714
709 if (op->type == SPELL) 715 if (op->type == SPELL)
710 { 716 {
711 op->destroy (); 717 op->destroy ();
712 continue; 718 continue;
713 } 719 }
715 { 721 {
716 SET_FLAG (op, FLAG_CAN_USE_SKILL); 722 SET_FLAG (op, FLAG_CAN_USE_SKILL);
717 op->stats.exp = 0; 723 op->stats.exp = 0;
718 op->level = 1; 724 op->level = 1;
719 } 725 }
720 /* lock all 'normal items by default */ 726 else /* lock all 'normal items by default */
721 else
722 SET_FLAG (op, FLAG_INV_LOCKED); 727 SET_FLAG (op, FLAG_INV_LOCKED);
723 } /* for loop of objects in player inv */ 728 } /* for loop of objects in player inv */
724 729
725 /* Need to set up the skill pointers */ 730 /* Need to set up the skill pointers */
726 link_player_skills (pl); 731 link_player_skills (pl);
832static void 837static void
833start_info (object *op) 838start_info (object *op)
834{ 839{
835 char buf[MAX_BUF]; 840 char buf[MAX_BUF];
836 841
837 sprintf (buf, "Welcome to Crossfire v%s!", VERSION); 842 sprintf (buf, "Welcome to Deliantra v%s!", VERSION);
838 new_draw_info (NDI_UNIQUE, 0, op, buf); 843 new_draw_info (NDI_UNIQUE, 0, op, buf);
839 //new_draw_info (NDI_UNIQUE, 0, op, "Press `?' for help");
840 //new_draw_info (NDI_UNIQUE, 0, op, " ");
841} 844}
842 845
843/* This function takes the key that is passed, and does the 846/* This function takes the key that is passed, and does the
844 * appropriate action with it (change race, or other things). 847 * appropriate action with it (change race, or other things).
845 * The function name is for historical reasons - now we have 848 * The function name is for historical reasons - now we have
1357 * found object is returned. 1360 * found object is returned.
1358 */ 1361 */
1359object * 1362object *
1360find_arrow (object *op, const char *type) 1363find_arrow (object *op, const char *type)
1361{ 1364{
1362 object *tmp = 0;
1363
1364 for (op = op->inv; op; op = op->below) 1365 for (object *tmp = op->inv; tmp; tmp = tmp->below)
1365 if (!tmp && op->type == CONTAINER && op->race == type && QUERY_FLAG (op, FLAG_APPLIED))
1366 tmp = find_arrow (splay (op), type);
1367 else if (op->type == ARROW && op->race == type) 1366 if (tmp->type == ARROW && !strcmp (&tmp->race, type))
1368 return splay (op); 1367 return splay (tmp);
1369 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
1370 return tmp; 1377 return 0;
1371} 1378}
1372 1379
1373/* 1380/*
1374 * 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
1375 * 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
1596 arrow->destroy (); 1603 arrow->destroy ();
1597 return 0; 1604 return 0;
1598 } 1605 }
1599 1606
1600 left = arrow; /* these are arrows left to the player */ 1607 left = arrow; /* these are arrows left to the player */
1601 arrow = get_split_ob (arrow, 1); 1608 arrow = arrow->split ();
1602 if (!arrow) 1609 if (!arrow)
1603 { 1610 {
1604 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);
1605 return 0; 1612 return 0;
1606 } 1613 }
1673 op->play_sound (sound_find ("fire_arrow")); 1680 op->play_sound (sound_find ("fire_arrow"));
1674 m->insert (arrow, sx, sy, op); 1681 m->insert (arrow, sx, sy, op);
1675 1682
1676 if (!arrow->destroyed ()) 1683 if (!arrow->destroyed ())
1677 move_arrow (arrow); 1684 move_arrow (arrow);
1678
1679 if (op->type == PLAYER)
1680 {
1681 if (left->destroyed ())
1682 esrv_del_item (op->contr, left->count);
1683 else
1684 esrv_send_item (op, left);
1685 }
1686 1685
1687 return 1; 1686 return 1;
1688} 1687}
1689 1688
1690/* Special fire code for players - this takes into 1689/* Special fire code for players - this takes into
1980 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);
1981 remove_door2 (door); /* remove door without violence ;-) */ 1980 remove_door2 (door); /* remove door without violence ;-) */
1982 } 1981 }
1983 1982
1984 /* Do this after we print the message */ 1983 /* Do this after we print the message */
1985 decrease_ob (key); /* Use up one of the keys */ 1984 key->decrease (); /* Use up one of the keys */
1986 /* Need to update the weight the container the key was in */ 1985 /* Need to update the weight the container the key was in */
1987 if (container != op) 1986 if (container != op)
1988 esrv_update_item (UPD_WEIGHT, op, container); 1987 esrv_update_item (UPD_WEIGHT, op, container);
1989 1988
1990 return 1; /* Nothing more to do below */ 1989 return 1; /* Nothing more to do below */
2174bool 2173bool
2175move_player (object *op, int dir) 2174move_player (object *op, int dir)
2176{ 2175{
2177 int pick; 2176 int pick;
2178 2177
2179 if (!op->map || op->map->in_memory != MAP_IN_MEMORY) 2178 if (!op->map || op->map->in_memory != MAP_ACTIVE)
2180 return 0; 2179 return 0;
2181 2180
2182 /* Sanity check: make sure dir is valid */ 2181 /* Sanity check: make sure dir is valid */
2183 if ((dir < 0) || (dir >= 9)) 2182 if ((dir < 0) || (dir >= 9))
2184 { 2183 {
2927 2926
2928 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))))
2929 { 2928 {
2930 if (tmp->nrof > 1) 2929 if (tmp->nrof > 1)
2931 { 2930 {
2932 tmp2 = get_split_ob (tmp, 1 + RANDOM () % (tmp->nrof - 1)); 2931 tmp->decrease (rndm (1, tmp->nrof - 1));
2933 tmp2->destroy ();
2934 insert_ob_in_map (tmp, op->map, NULL, 0); 2932 insert_ob_in_map (tmp, op->map, NULL, 0);
2935 } 2933 }
2936 else 2934 else
2937 tmp->destroy (); 2935 tmp->destroy ();
2938 } 2936 }
2949void 2947void
2950fix_weight (void) 2948fix_weight (void)
2951{ 2949{
2952 for_all_players (pl) 2950 for_all_players (pl)
2953 { 2951 {
2954 int old = pl->ob->carrying, sum = sum_weight (pl->ob); 2952 sint32 old = pl->ob->carrying;
2955 2953
2956 if (old == sum) 2954 pl->ob->update_weight ();
2957 continue; 2955
2956 if (old != pl->ob->carrying)
2957 {
2958 pl->ob->update_stats (); 2958 pl->ob->update_stats ();
2959 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 }
2960 } 2961 }
2961} 2962}
2962 2963
2963void 2964void
2964fix_luck (void) 2965fix_luck (void)
3050 * as bad as carrying a light on a pitch dark map */ 3051 * as bad as carrying a light on a pitch dark map */
3051 if (has_carried_lights (ob)) 3052 if (has_carried_lights (ob))
3052 level = -(10 + (2 * ob->map->darkness)); 3053 level = -(10 + (2 * ob->map->darkness));
3053 3054
3054 /* scan through all nearby squares for terrain to hide in */ 3055 /* scan through all nearby squares for terrain to hide in */
3055 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])
3056 { 3059 {
3057 mflag = get_map_flags (ob->map, NULL, x, y, NULL, NULL); 3060 mflag = get_map_flags (ob->map, NULL, x, y, NULL, NULL);
3058 if (mflag & P_OUT_OF_MAP) 3061 if (mflag & P_OUT_OF_MAP)
3059 {
3060 continue; 3062 continue;
3061 } 3063
3062 if (mflag & P_BLOCKSVIEW) /* something to hide near! */ 3064 if (mflag & P_BLOCKSVIEW) /* something to hide near! */
3063 level += 2; 3065 level += 2;
3064 else /* open terrain! */ 3066 else /* open terrain! */
3065 level -= 1; 3067 level -= 1;
3066 } 3068 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines