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.268 by root, Wed Apr 7 19:54:45 2010 UTC vs.
Revision 1.275 by root, Tue Apr 27 07:20:49 2010 UTC

54 54
55 players.insert (this); 55 players.insert (this);
56 ob->remove (); 56 ob->remove ();
57 ob->map = 0; 57 ob->map = 0;
58 ob->activate_recursive (); 58 ob->activate_recursive ();
59 CLEAR_FLAG (ob, FLAG_FRIENDLY); 59 ob->clr_flag (FLAG_FRIENDLY);
60 add_friendly_object (ob); 60 add_friendly_object (ob);
61} 61}
62 62
63void 63void
64player::deactivate () 64player::deactivate ()
374 */ 374 */
375int 375int
376path_to_player (object *mon, object *pl, unsigned mindiff) 376path_to_player (object *mon, object *pl, unsigned mindiff)
377{ 377{
378 rv_vector rv; 378 rv_vector rv;
379 sint16 x, y;
380 int lastx, lasty, dir, i, diff, firstdir = 0, lastdir, max = MAX_SPACES, mflags, blocked; 379 int dir, i, diff, firstdir = 0, lastdir, max = MAX_SPACES, mflags, blocked;
381 maptile *m, *lastmap;
382 380
383 get_rangevector (mon, pl, &rv, 0); 381 get_rangevector (mon, pl, &rv, 0);
384 382
385 if (rv.distance < mindiff) 383 if (rv.distance < mindiff)
386 return 0; 384 return 0;
387 385
388 x = mon->x; 386 mapxy pos (mon);
389 y = mon->y;
390 m = mon->map;
391 dir = rv.direction; 387 dir = rv.direction;
392 lastdir = firstdir = rv.direction; /* perhaps we stand next to pl, init firstdir too */ 388 lastdir = firstdir = rv.direction; /* perhaps we stand next to pl, init firstdir too */
393 diff = ::max (abs (rv.distance_x), abs (rv.distance_y)); 389 diff = ::max (abs (rv.distance_x), abs (rv.distance_y));
394 390
395 /* If we can't solve it within the search distance, return now. */ 391 /* If we can't solve it within the search distance, return now. */
396 if (diff > max) 392 if (diff > max)
397 return 0; 393 return 0;
398 394
399 while (diff > 1 && max > 0) 395 while (diff > 1 && max > 0)
400 { 396 {
401 lastx = x; 397 mapxy lastpos = pos;
402 lasty = y;
403 lastmap = m;
404 x = lastx + freearr_x[dir];
405 y = lasty + freearr_y[dir];
406 398
407 mflags = get_map_flags (m, &m, x, y, &x, &y); 399 pos.move (dir);
408 blocked = (mflags & P_OUT_OF_MAP) ? MOVE_ALL : GET_MAP_MOVE_BLOCK (m, x, y);
409 400
410 /* Space is blocked - try changing direction a little */ 401 /* Space is blocked - try changing direction a little */
411 if ((mflags & P_OUT_OF_MAP) || ((OB_TYPE_MOVE_BLOCK (mon, blocked) || (mflags & P_BLOCKSVIEW)) 402 if (!pos.normalise ()
412 && (m == mon->map && blocked_link (mon, m, x, y)))) 403 || (((pos->flags () & P_BLOCKSVIEW) || OB_TYPE_MOVE_BLOCK (mon, pos->move_block))
404 && blocked_link (mon, pos.m, pos.x, pos.y)))
413 { 405 {
414 /* recalculate direction from last good location. Possible 406 /* recalculate direction from last good location. Possible
415 * we were not traversing ideal location before. 407 * we were not traversing ideal location before.
416 */ 408 */
417 get_rangevector_from_mapcoord (lastmap, lastx, lasty, pl, &rv, 0); 409 get_rangevector_from_mapcoord (lastpos.m, lastpos.x, lastpos.y, pl, &rv, 0);
418 if (rv.direction != dir) 410 if (rv.direction != dir)
419 { 411 {
420 /* OK - says direction should be different - lets reset the 412 /* OK - says direction should be different - lets reset the
421 * the values so it will try again. 413 * the values so it will try again.
422 */ 414 */
423 x = lastx;
424 y = lasty;
425 m = lastmap; 415 pos = lastpos;
426 dir = firstdir = rv.direction; 416 dir = firstdir = rv.direction;
427 } 417 }
428 else 418 else
429 { 419 {
430 /* direct path is blocked - try taking a side step to 420 /* direct path is blocked - try taking a side step to
437 */ 427 */
438 for (i = -DETOUR_AMOUNT; i <= DETOUR_AMOUNT; i++) 428 for (i = -DETOUR_AMOUNT; i <= DETOUR_AMOUNT; i++)
439 { 429 {
440 if (i == 0) 430 if (i == 0)
441 continue; /* already did this, so skip it */ 431 continue; /* already did this, so skip it */
432
442 /* Use lastdir here - otherwise, 433 /* Use lastdir here - otherwise,
443 * since the direction that the creature should move in 434 * since the direction that the creature should move in
444 * may change, you could get infinite loops. 435 * may change, you could get infinite loops.
445 * ie, player is northwest, but monster can only 436 * ie, player is northwest, but monster can only
446 * move west, so it does that. It goes some distance, 437 * move west, so it does that. It goes some distance,
448 * can't do that, but now finds it can move east, and 439 * can't do that, but now finds it can move east, and
449 * gets back to its original point. lastdir contains 440 * gets back to its original point. lastdir contains
450 * the last direction the creature has successfully 441 * the last direction the creature has successfully
451 * moved. 442 * moved.
452 */ 443 */
453
454 x = lastx + freearr_x[absdir (lastdir + i)];
455 y = lasty + freearr_y[absdir (lastdir + i)];
456 m = lastmap; 444 pos = lastpos;
457 mflags = get_map_flags (m, &m, x, y, &x, &y); 445 pos.move (absdir (lastdir + i));
458 if (mflags & P_OUT_OF_MAP) 446
447 if (!pos.normalise ())
459 continue; 448 continue;
460 blocked = GET_MAP_MOVE_BLOCK (m, x, y); 449
461 if (OB_TYPE_MOVE_BLOCK (mon, blocked)) 450 mapspace &ms = *pos;
451
452 if (ms.flags () & P_BLOCKSVIEW)
462 continue; 453 continue;
463 if (mflags & P_BLOCKSVIEW) 454
455 if (OB_TYPE_MOVE_BLOCK (mon, ms.move_block))
464 continue; 456 continue;
465 457
466 if (m == mon->map && blocked_link (mon, m, x, y)) 458 if (blocked_link (mon, pos.m, pos.x, pos.y))
467 break; 459 break;
468 } 460 }
461
469 /* go through entire loop without finding a valid 462 /* go through entire loop without finding a valid
470 * sidestep to take - thus, no valid path. 463 * sidestep to take - thus, no valid path.
471 */ 464 */
472 if (i == (DETOUR_AMOUNT + 1)) 465 if (i == DETOUR_AMOUNT + 1)
473 return 0; 466 return 0;
467
474 diff--; 468 diff--;
475 lastdir = dir; 469 lastdir = dir;
476 max--; 470 max--;
477 if (!firstdir) 471 if (!firstdir)
478 firstdir = dir + i; 472 firstdir = dir + i;
482 { 476 {
483 /* we moved towards creature, so diff is less */ 477 /* we moved towards creature, so diff is less */
484 diff--; 478 diff--;
485 max--; 479 max--;
486 lastdir = dir; 480 lastdir = dir;
481
487 if (!firstdir) 482 if (!firstdir)
488 firstdir = dir; 483 firstdir = dir;
489 } 484 }
490 485
491 if (diff <= 1) 486 if (diff <= 1)
492 { 487 {
493 /* Recalculate diff (distance) because we may not have actually 488 /* Recalculate diff (distance) because we may not have actually
494 * headed toward player for entire distance. 489 * headed toward player for entire distance.
495 */ 490 */
496 get_rangevector_from_mapcoord (m, x, y, pl, &rv, 0); 491 get_rangevector_from_mapcoord (pos.m, pos.x, pos.y, pl, &rv, 0);
497 diff = ::max (abs (rv.distance_x), abs (rv.distance_y)); 492 diff = ::max (abs (rv.distance_x), abs (rv.distance_y));
498 } 493 }
499 494
500 if (diff > max) 495 if (diff > max)
501 return 0; 496 return 0;
519 next = op->below; 514 next = op->below;
520 515
521 /* Forces get applied per default, unless they have the 516 /* Forces get applied per default, unless they have the
522 * flag "neutral" set. Sorry but I can't think of a better way 517 * flag "neutral" set. Sorry but I can't think of a better way
523 */ 518 */
524 if (op->type == FORCE && !QUERY_FLAG (op, FLAG_NEUTRAL)) 519 if (op->type == FORCE && !op->flag [FLAG_NEUTRAL])
525 SET_FLAG (op, FLAG_APPLIED); 520 op->set_flag (FLAG_APPLIED);
526 521
527 /* we never give weapons/armour if these cannot be used 522 /* we never give weapons/armour if these cannot be used
528 * by this player due to race restrictions 523 * by this player due to race restrictions
529 */ 524 */
530 if (pl->type == PLAYER) 525 if (pl->type == PLAYER)
531 { 526 {
532 if ((!QUERY_FLAG (pl, FLAG_USE_ARMOUR) 527 if ((!pl->flag [FLAG_USE_ARMOUR]
533 && 528 &&
534 (op->type == ARMOUR || op->type == BOOTS 529 (op->type == ARMOUR || op->type == BOOTS
535 || op->type == CLOAK || op->type == HELMET 530 || op->type == CLOAK || op->type == HELMET
536 || op->type == SHIELD || op->type == GLOVES 531 || op->type == SHIELD || op->type == GLOVES
537 || op->type == BRACERS || op->type == GIRDLE)) 532 || op->type == BRACERS || op->type == GIRDLE))
538 || (!QUERY_FLAG (pl, FLAG_USE_WEAPON) && op->type == WEAPON)) 533 || (!pl->flag [FLAG_USE_WEAPON] && op->type == WEAPON))
539 { 534 {
540 op->destroy (); 535 op->destroy ();
541 continue; 536 continue;
542 } 537 }
543 } 538 }
560 if (op->nrof > 1) 555 if (op->nrof > 1)
561 op->nrof = 1; 556 op->nrof = 1;
562 } 557 }
563 558
564 if (op->type == SPELLBOOK && op->inv) 559 if (op->type == SPELLBOOK && op->inv)
565 CLEAR_FLAG (op->inv, FLAG_STARTEQUIP); 560 op->inv->clr_flag (FLAG_STARTEQUIP);
566 561
567 /* Give starting characters identified, uncursed, and undamned 562 /* Give starting characters identified, uncursed, and undamned
568 * items. Just don't identify gold or silver, or it won't be 563 * items. Just don't identify gold or silver, or it won't be
569 * merged properly. 564 * merged properly.
570 */ 565 */
571 if (need_identify (op)) 566 if (op->need_identify ())
572 { 567 {
573 SET_FLAG (op, FLAG_IDENTIFIED); 568 op->set_flag (FLAG_IDENTIFIED);
574 CLEAR_FLAG (op, FLAG_CURSED); 569 op->clr_flag (FLAG_CURSED);
575 CLEAR_FLAG (op, FLAG_DAMNED); 570 op->clr_flag (FLAG_DAMNED);
576 } 571 }
577 572
578 if (op->type == SPELL) 573 if (op->type == SPELL)
579 { 574 {
580 op->destroy (); 575 op->destroy ();
581 continue; 576 continue;
582 } 577 }
583 else if (op->type == SKILL) 578 else if (op->type == SKILL)
584 { 579 {
585 SET_FLAG (op, FLAG_CAN_USE_SKILL); 580 op->set_flag (FLAG_CAN_USE_SKILL);
586 op->stats.exp = 0; 581 op->stats.exp = 0;
587 op->level = 1; 582 op->level = 1;
588 } 583 }
589 else /* lock all 'normal items by default */ 584 else /* lock all 'normal items by default */
590 SET_FLAG (op, FLAG_INV_LOCKED); 585 op->set_flag (FLAG_INV_LOCKED);
591 } /* for loop of objects in player inv */ 586 } /* for loop of objects in player inv */
592 587
593 /* Need to set up the skill pointers */ 588 /* Need to set up the skill pointers */
594 pl->contr->link_skills (); 589 pl->contr->link_skills ();
595} 590}
721 treasurelist *tl = treasurelist::find (shstr_starting_wealth); 716 treasurelist *tl = treasurelist::find (shstr_starting_wealth);
722 if (tl) 717 if (tl)
723 create_treasure (tl, ob, 0, 0, 0); 718 create_treasure (tl, ob, 0, 0, 0);
724 719
725 INVOKE_PLAYER (BIRTH, ob->contr); 720 INVOKE_PLAYER (BIRTH, ob->contr);
726 INVOKE_PLAYER (LOGIN, ob->contr);
727 721
728 ob->contr->ns->state = ST_PLAYING; 722 ob->contr->ns->state = ST_PLAYING;
729 723
730 if (ob->msg) 724 if (ob->msg)
731 ob->msg = 0; 725 ob->msg = 0;
732 726
733 start_info (ob); 727 start_info (ob);
734 CLEAR_FLAG (ob, FLAG_WIZ); 728 ob->clr_flag (FLAG_WIZ);
735 give_initial_items (ob, ob->randomitems); 729 give_initial_items (ob, ob->randomitems);
736 esrv_send_inventory (ob, ob); 730 esrv_send_inventory (ob, ob);
737 ob->update_stats (); 731 ob->update_stats ();
738 732
739 /* This moves the player to a different start map, if there 733 /* This moves the player to a different start map, if there
788 rv_vector rv; 782 rv_vector rv;
789 783
790 if (op->stats.hp < 0) 784 if (op->stats.hp < 0)
791 { 785 {
792 LOG (llevDebug, "Fleeing player is dead.\n"); 786 LOG (llevDebug, "Fleeing player is dead.\n");
793 CLEAR_FLAG (op, FLAG_SCARED); 787 op->clr_flag (FLAG_SCARED);
794 return; 788 return;
795 } 789 }
796 790
797 if (!op->enemy) 791 if (!op->enemy)
798 { 792 {
799 LOG (llevDebug, "Fleeing player had no enemy.\n"); 793 LOG (llevDebug, "Fleeing player had no enemy.\n");
800 CLEAR_FLAG (op, FLAG_SCARED); 794 op->clr_flag (FLAG_SCARED);
801 return; 795 return;
802 } 796 }
803 797
804 if (!(random_roll (0, 4, op, PREFER_LOW)) && did_make_save (op, op->level, 0)) 798 if (!(random_roll (0, 4, op, PREFER_LOW)) && did_make_save (op, op->level, 0))
805 { 799 {
806 op->enemy = NULL; 800 op->enemy = NULL;
807 CLEAR_FLAG (op, FLAG_SCARED); 801 op->clr_flag (FLAG_SCARED);
808 return; 802 return;
809 } 803 }
810 804
811 get_rangevector (op, op->enemy, &rv, 0); 805 get_rangevector (op, op->enemy, &rv, 0);
812 806
818 if (op->move (absdir (dir + diff * m)) || (diff == 0 && op->move (absdir (dir - diff * m)))) 812 if (op->move (absdir (dir + diff * m)) || (diff == 0 && op->move (absdir (dir - diff * m))))
819 return; 813 return;
820 } 814 }
821 815
822 /* Cornered, get rid of scared */ 816 /* Cornered, get rid of scared */
823 CLEAR_FLAG (op, FLAG_SCARED); 817 op->clr_flag (FLAG_SCARED);
824 op->enemy = NULL; 818 op->enemy = NULL;
825} 819}
826 820
827/* check_pick sees if there is stuff to be picked up/picks up stuff. 821/* check_pick sees if there is stuff to be picked up/picks up stuff.
828 * It returns 1 if the player should keep on moving, 0 if he should 822 * It returns 1 if the player should keep on moving, 0 if he should
920 * fighting */ 914 * fighting */
921 if (op->contr->mode & PU_INHIBIT) 915 if (op->contr->mode & PU_INHIBIT)
922 return 1; 916 return 1;
923 917
924 /* prevent us from turning into auto-thieves :) */ 918 /* prevent us from turning into auto-thieves :) */
925 if (QUERY_FLAG (tmp, FLAG_UNPAID)) 919 if (tmp->flag [FLAG_UNPAID])
926 continue; 920 continue;
927 921
928 /* ignore known cursed objects */ 922 /* ignore known cursed objects */
929 if (QUERY_FLAG (tmp, FLAG_KNOWN_CURSED) && op->contr->mode & PU_NOT_CURSED) 923 if (tmp->flag [FLAG_KNOWN_CURSED] && op->contr->mode & PU_NOT_CURSED)
930 continue; 924 continue;
931 925
932 /* all food and drink if desired */ 926 /* all food and drink if desired */
933 /* question: don't pick up known-poisonous stuff? */ 927 /* question: don't pick up known-poisonous stuff? */
934 if (op->contr->mode & PU_FOOD) 928 if (op->contr->mode & PU_FOOD)
937 CHK_PICK_PICKUP; 931 CHK_PICK_PICKUP;
938 continue; 932 continue;
939 } 933 }
940 934
941 if (op->contr->mode & PU_DRINK) 935 if (op->contr->mode & PU_DRINK)
942 if (tmp->type == DRINK || (tmp->type == POISON && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))) 936 if (tmp->type == DRINK || (tmp->type == POISON && !tmp->flag [FLAG_KNOWN_CURSED]))
943 { 937 {
944 CHK_PICK_PICKUP; 938 CHK_PICK_PICKUP;
945 continue; 939 continue;
946 } 940 }
947 941
985 continue; 979 continue;
986 } 980 }
987 981
988 /* pick up all magical items */ 982 /* pick up all magical items */
989 if (op->contr->mode & PU_MAGICAL) 983 if (op->contr->mode & PU_MAGICAL)
990 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) 984 if (tmp->flag [FLAG_KNOWN_MAGICAL]
991 && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)) 985 && !tmp->flag [FLAG_KNOWN_CURSED])
992 { 986 {
993 CHK_PICK_PICKUP; 987 CHK_PICK_PICKUP;
994 continue; 988 continue;
995 } 989 }
996 990
1080 continue; 1074 continue;
1081 } 1075 }
1082 1076
1083 /* hoping to catch throwing daggers here */ 1077 /* hoping to catch throwing daggers here */
1084 if (op->contr->mode & PU_MISSILEWEAPON) 1078 if (op->contr->mode & PU_MISSILEWEAPON)
1085 if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_IS_THROWN)) 1079 if (tmp->type == WEAPON && tmp->flag [FLAG_IS_THROWN])
1086 { 1080 {
1087 CHK_PICK_PICKUP; 1081 CHK_PICK_PICKUP;
1088 continue; 1082 continue;
1089 } 1083 }
1090 1084
1145 * return 0. 1139 * return 0.
1146 */ 1140 */
1147static int 1141static int
1148action_makes_visible (object *op) 1142action_makes_visible (object *op)
1149{ 1143{
1150 if (op->invisible && QUERY_FLAG (op, FLAG_ALIVE)) 1144 if (op->invisible && op->flag [FLAG_ALIVE])
1151 { 1145 {
1152 if (QUERY_FLAG (op, FLAG_MAKE_INVIS)) 1146 if (op->flag [FLAG_MAKE_INVIS])
1153 { 1147 {
1154 // artefact invisibility is permanent, but we still make noise 1148 // artefact invisibility is permanent, but we still make noise
1155 // this is important for game-balance. 1149 // this is important for game-balance.
1156 if (op->contr) 1150 if (op->contr)
1157 op->make_noise (); 1151 op->make_noise ();
1184 for (object *tmp = op->inv; tmp; tmp = tmp->below) 1178 for (object *tmp = op->inv; tmp; tmp = tmp->below)
1185 if (tmp->type == ARROW && !strcmp (&tmp->race, type)) 1179 if (tmp->type == ARROW && !strcmp (&tmp->race, type))
1186 return splay (tmp); 1180 return splay (tmp);
1187 1181
1188 for (object *tmp = op->inv; tmp; tmp = tmp->below) 1182 for (object *tmp = op->inv; tmp; tmp = tmp->below)
1189 if (tmp->type == CONTAINER && QUERY_FLAG (tmp, FLAG_APPLIED) && !strcmp (&tmp->race, type)) 1183 if (tmp->type == CONTAINER && tmp->flag [FLAG_APPLIED] && !strcmp (&tmp->race, type))
1190 if (object *arrow = find_arrow (tmp, type)) 1184 if (object *arrow = find_arrow (tmp, type))
1191 { 1185 {
1192 splay (tmp); 1186 splay (tmp);
1193 return arrow; 1187 return arrow;
1194 } 1188 }
1211 if (!type) 1205 if (!type)
1212 return NULL; 1206 return NULL;
1213 1207
1214 for (arrow = op->inv; arrow; arrow = arrow->below) 1208 for (arrow = op->inv; arrow; arrow = arrow->below)
1215 { 1209 {
1216 if (arrow->type == CONTAINER && arrow->race == type && QUERY_FLAG (arrow, FLAG_APPLIED)) 1210 if (arrow->type == CONTAINER && arrow->race == type && arrow->flag [FLAG_APPLIED])
1217 { 1211 {
1218 i = 0; 1212 i = 0;
1219 ntmp = find_better_arrow (arrow, target, type, &i); 1213 ntmp = find_better_arrow (arrow, target, type, &i);
1220 1214
1221 if (i > betterby) 1215 if (i > betterby)
1322 break; 1316 break;
1323 } 1317 }
1324 1318
1325 if (mflags & P_IS_ALIVE) 1319 if (mflags & P_IS_ALIVE)
1326 for (tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above) 1320 for (tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above)
1327 if (QUERY_FLAG (tmp, FLAG_ALIVE)) 1321 if (tmp->flag [FLAG_ALIVE])
1328 break; 1322 break;
1329 } 1323 }
1330 1324
1331 if (!tmp) 1325 if (!tmp)
1332 return find_arrow (op, type); 1326 return find_arrow (op, type);
1393 { 1387 {
1394 if (op->type == PLAYER) 1388 if (op->type == PLAYER)
1395 new_draw_info_format (NDI_UNIQUE, 0, op, "You have no %s left.", &bow->race); 1389 new_draw_info_format (NDI_UNIQUE, 0, op, "You have no %s left.", &bow->race);
1396 /* FLAG_READY_BOW will get reset if the monsters picks up some arrows */ 1390 /* FLAG_READY_BOW will get reset if the monsters picks up some arrows */
1397 else 1391 else
1398 CLEAR_FLAG (op, FLAG_READY_BOW); 1392 op->clr_flag (FLAG_READY_BOW);
1399 1393
1400 return 0; 1394 return 0;
1401 } 1395 }
1402 } 1396 }
1403 1397
1603 { 1597 {
1604 object *tmp; 1598 object *tmp;
1605 1599
1606 if (item->arch) 1600 if (item->arch)
1607 { 1601 {
1608 CLEAR_FLAG (item, FLAG_ANIMATE); 1602 item->clr_flag (FLAG_ANIMATE);
1609 item->face = item->arch->face; 1603 item->face = item->arch->face;
1610 item->set_speed (0); 1604 item->set_speed (0);
1611 } 1605 }
1612 1606
1613 if (object *pl = item->visible_to ()) 1607 if (object *pl = item->visible_to ())
1741 * 1735 *
1742 * Change the color so that the message doesn't disappear with 1736 * Change the color so that the message doesn't disappear with
1743 * all the others. 1737 * all the others.
1744 */ 1738 */
1745 if (pl->contr->usekeys == key_inventory 1739 if (pl->contr->usekeys == key_inventory
1746 || !QUERY_FLAG (container, FLAG_APPLIED) 1740 || !container->flag [FLAG_APPLIED]
1747 || (pl->contr->usekeys == keyrings && container->race != shstr_keys)) 1741 || (pl->contr->usekeys == keyrings && container->race != shstr_keys))
1748 { 1742 {
1749 new_draw_info_format (NDI_UNIQUE | NDI_BROWN, 0, pl, 1743 new_draw_info_format (NDI_UNIQUE | NDI_BROWN, 0, pl,
1750 "The %s in your %s vibrates as you approach the door", query_name (tmp), query_name (container)); 1744 "The %s in your %s vibrates as you approach the door", query_name (tmp), query_name (container));
1751 return NULL; 1745 return NULL;
1902 */ 1896 */
1903 if (op->type == PLAYER 1897 if (op->type == PLAYER
1904 && ((mon->owner && mon->owner->contr 1898 && ((mon->owner && mon->owner->contr
1905 && same_party (mon->owner->contr->party, op->contr->party)) 1899 && same_party (mon->owner->contr->party, op->contr->party))
1906 || mon->owner == op) 1900 || mon->owner == op)
1907 && (QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY))) 1901 && (mon->flag [FLAG_UNAGGRESSIVE] || mon->flag [FLAG_FRIENDLY]))
1908 { 1902 {
1909 /* If we're braced, we don't want to switch places with it */ 1903 /* If we're braced, we don't want to switch places with it */
1910 if (op->contr->braced) 1904 if (op->contr->braced)
1911 return false; 1905 return false;
1912 1906
1932 * creatures. Note that if you are braced, you can't push 1926 * creatures. Note that if you are braced, you can't push
1933 * someone, but put it inside this loop so that you won't 1927 * someone, but put it inside this loop so that you won't
1934 * attack them either. 1928 * attack them either.
1935 */ 1929 */
1936 if ((mon->type == PLAYER || mon->enemy != op) 1930 if ((mon->type == PLAYER || mon->enemy != op)
1937 && (mon->type == PLAYER || QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY)) 1931 && (mon->type == PLAYER || mon->flag [FLAG_UNAGGRESSIVE] || mon->flag [FLAG_FRIENDLY])
1938 && ((op->contr->peaceful 1932 && ((op->contr->peaceful
1939 || (mon->type == PLAYER && mon->contr->peaceful)) 1933 || (mon->type == PLAYER && mon->contr->peaceful))
1940 && !on_battleground)) 1934 && !on_battleground))
1941 { 1935 {
1942 if (op->speed_left > 0.f) 1936 if (op->speed_left > 0.f)
1958 } 1952 }
1959 } 1953 }
1960 /* If the object is a boulder or other rollable object, then 1954 /* If the object is a boulder or other rollable object, then
1961 * roll it if not braced. You can't roll it if you are braced. 1955 * roll it if not braced. You can't roll it if you are braced.
1962 */ 1956 */
1963 else if (QUERY_FLAG (mon, FLAG_CAN_ROLL) && (!op->contr->braced)) 1957 else if (mon->flag [FLAG_CAN_ROLL] && (!op->contr->braced))
1964 { 1958 {
1965 if (op->speed_left > 0.f) 1959 if (op->speed_left > 0.f)
1966 { 1960 {
1967 --op->speed_left; 1961 --op->speed_left;
1968 1962
1977 * Way it works is like this: First, it must have some hit points 1971 * Way it works is like this: First, it must have some hit points
1978 * and be living. Then, it must be one of the following: 1972 * and be living. Then, it must be one of the following:
1979 * 1) Not a player, 2) A player, but of a different party. Note 1973 * 1) Not a player, 2) A player, but of a different party. Note
1980 * that party_number -1 is no party, so attacks can still happen. 1974 * that party_number -1 is no party, so attacks can still happen.
1981 */ 1975 */
1982 else if ((mon->stats.hp >= 0) && QUERY_FLAG (mon, FLAG_ALIVE) && 1976 else if ((mon->stats.hp >= 0) && mon->flag [FLAG_ALIVE] &&
1983 ((mon->type != PLAYER || op->contr->party == NULL || op->contr->party != mon->contr->party))) 1977 ((mon->type != PLAYER || op->contr->party == NULL || op->contr->party != mon->contr->party)))
1984 { 1978 {
1985 if (op->contr->weapon_sp_left > 0.f && !op->flag [FLAG_WIZPASS]) 1979 if (op->contr->weapon_sp_left > 0.f && !op->flag [FLAG_WIZPASS])
1986 { 1980 {
1987 --op->contr->weapon_sp_left; 1981 --op->contr->weapon_sp_left;
2003{ 1997{
2004 if (!op->map || op->map->in_memory != MAP_ACTIVE) 1998 if (!op->map || op->map->in_memory != MAP_ACTIVE)
2005 return 0; 1999 return 0;
2006 2000
2007 /* Sanity check: make sure dir is valid */ 2001 /* Sanity check: make sure dir is valid */
2008 if (dir < 0 || dir >= 9) 2002 if (dir < 0 || dir > 8)
2009 { 2003 {
2010 LOG (llevError, "move_player: invalid direction %d\n", dir); 2004 LOG (llevError, "move_player: invalid direction %d\n", dir);
2011 return 0; 2005 return 0;
2012 } 2006 }
2013 2007
2014 /* peterm: added following line */ 2008 /* peterm: added following line */
2015 if (QUERY_FLAG (op, FLAG_CONFUSED) && dir) 2009 if (op->flag [FLAG_CONFUSED] && dir)
2016 dir = absdir (dir + rndm (3) + rndm (3) - 2); 2010 dir = absdir (dir + rndm (3) + rndm (3) - 2);
2017 2011
2018 op->facing = dir; 2012 op->facing = dir;
2019 2013
2020 if (op->flag [FLAG_HIDDEN]) 2014 if (op->flag [FLAG_HIDDEN])
2060 * players. 2054 * players.
2061 */ 2055 */
2062bool 2056bool
2063handle_newcs_player (object *op) 2057handle_newcs_player (object *op)
2064{ 2058{
2065 if (QUERY_FLAG (op, FLAG_SCARED)) 2059 if (op->flag [FLAG_SCARED])
2066 { 2060 {
2067 if (op->speed_left > 0.f) 2061 if (op->speed_left > 0.f)
2068 { 2062 {
2069 --op->speed_left; 2063 --op->speed_left;
2070 flee_player (op); 2064 flee_player (op);
2089} 2083}
2090 2084
2091static int 2085static int
2092save_life (object *op) 2086save_life (object *op)
2093{ 2087{
2094 if (!QUERY_FLAG (op, FLAG_LIFESAVE)) 2088 if (!op->flag [FLAG_LIFESAVE])
2095 return 0; 2089 return 0;
2096 2090
2097 for (object *tmp = op->inv; tmp; tmp = tmp->below) 2091 for (object *tmp = op->inv; tmp; tmp = tmp->below)
2098 if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE)) 2092 if (tmp->flag [FLAG_APPLIED] && tmp->flag [FLAG_LIFESAVE])
2099 { 2093 {
2100 op->play_sound (sound_find ("ob_evaporate")); 2094 op->play_sound (sound_find ("ob_evaporate"));
2101 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s vibrates violently, then evaporates.", query_name (tmp)); 2095 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s vibrates violently, then evaporates.", query_name (tmp));
2102 2096
2103 tmp->destroy (); 2097 tmp->destroy ();
2104 CLEAR_FLAG (op, FLAG_LIFESAVE); 2098 op->clr_flag (FLAG_LIFESAVE);
2105 2099
2106 if (op->stats.hp < 0) 2100 if (op->stats.hp < 0)
2107 op->stats.hp = op->stats.maxhp; 2101 op->stats.hp = op->stats.maxhp;
2108 2102
2109 if (op->stats.food < 0) 2103 if (op->stats.food < 0)
2112 op->update_stats (); 2106 op->update_stats ();
2113 return 1; 2107 return 1;
2114 } 2108 }
2115 2109
2116 LOG (llevError, "Error: LIFESAVE set without applied object.\n"); 2110 LOG (llevError, "Error: LIFESAVE set without applied object.\n");
2117 CLEAR_FLAG (op, FLAG_LIFESAVE); 2111 op->clr_flag (FLAG_LIFESAVE);
2118 enter_player_savebed (op); /* bring him home. */ 2112 enter_player_savebed (op); /* bring him home. */
2119 return 0; 2113 return 0;
2120} 2114}
2121 2115
2122/* This goes throws the inventory and removes unpaid objects, and puts them 2116/* This goes throws the inventory and removes unpaid objects, and puts them
2129{ 2123{
2130 while (op) 2124 while (op)
2131 { 2125 {
2132 object *next = op->below; /* Make sure we have a good value, in case we remove object 'op' */ 2126 object *next = op->below; /* Make sure we have a good value, in case we remove object 'op' */
2133 2127
2134 if (QUERY_FLAG (op, FLAG_UNPAID)) 2128 if (op->flag [FLAG_UNPAID])
2135 op->insert_at (env); 2129 op->insert_at (env);
2136 else if (op->inv) 2130 else if (op->inv)
2137 drop_unpaid_items (op->inv, env); 2131 drop_unpaid_items (op->inv, env);
2138 2132
2139 op = next; 2133 op = next;
2169 * alternate it here for it to work correctly. 2163 * alternate it here for it to work correctly.
2170 */ 2164 */
2171 if (pticks & 2) 2165 if (pticks & 2)
2172 op->invisible--; 2166 op->invisible--;
2173 } 2167 }
2174 else if (op->invisible && !(QUERY_FLAG (op, FLAG_MAKE_INVIS))) 2168 else if (op->invisible && !(op->flag [FLAG_MAKE_INVIS]))
2175 { 2169 {
2176 if (!op->invisible--) 2170 if (!op->invisible--)
2177 { 2171 {
2178 make_visible (op); 2172 make_visible (op);
2179 new_draw_info (NDI_UNIQUE, 0, op, "Your invisibility spell runs out."); 2173 new_draw_info (NDI_UNIQUE, 0, op, "Your invisibility spell runs out.");
2246 if (op->stats.sp < op->stats.maxsp) 2240 if (op->stats.sp < op->stats.maxsp)
2247 { 2241 {
2248 op->stats.sp++; 2242 op->stats.sp++;
2249 2243
2250 /* dms do not consume food */ 2244 /* dms do not consume food */
2251 if (!QUERY_FLAG (op, FLAG_WIZ)) 2245 if (!op->flag [FLAG_WIZ])
2252 { 2246 {
2253 op->stats.food--; 2247 op->stats.food--;
2254 2248
2255 if (op->contr->digestion < 0) 2249 if (op->contr->digestion < 0)
2256 op->stats.food += op->contr->digestion; 2250 op->stats.food += op->contr->digestion;
2290 if (op->stats.hp < op->stats.maxhp) 2284 if (op->stats.hp < op->stats.maxhp)
2291 { 2285 {
2292 op->stats.hp++; 2286 op->stats.hp++;
2293 2287
2294 /* dms do not consume food */ 2288 /* dms do not consume food */
2295 if (!QUERY_FLAG (op, FLAG_WIZ)) 2289 if (!op->flag [FLAG_WIZ])
2296 { 2290 {
2297 op->stats.food--; 2291 op->stats.food--;
2298 2292
2299 if (op->contr->digestion < 0) 2293 if (op->contr->digestion < 0)
2300 op->stats.food += op->contr->digestion; 2294 op->stats.food += op->contr->digestion;
2327 penalty = max (0, -op->contr->digestion); 2321 penalty = max (0, -op->contr->digestion);
2328 2322
2329 op->last_eat = 25 * (1 + bonus) / (max (0, op->contr->gen_hp) + penalty + 1); 2323 op->last_eat = 25 * (1 + bonus) / (max (0, op->contr->gen_hp) + penalty + 1);
2330 2324
2331 /* dms do not consume food */ 2325 /* dms do not consume food */
2332 if (!QUERY_FLAG (op, FLAG_WIZ)) 2326 if (!op->flag [FLAG_WIZ])
2333 op->stats.food--; 2327 op->stats.food--;
2334 } 2328 }
2335 2329
2336 if (op->stats.food < 0 && op->stats.hp >= 0) 2330 if (op->stats.food < 0 && op->stats.hp >= 0)
2337 { 2331 {
2338 object *flesh = 0; 2332 object *flesh = 0;
2339 2333
2340 for_inv_removable (op, tmp) 2334 for_inv_removable (op, tmp)
2341 { 2335 {
2342 if (QUERY_FLAG (tmp, FLAG_UNPAID)) 2336 if (tmp->flag [FLAG_UNPAID])
2343 continue; 2337 continue;
2344 2338
2345 if (tmp->type == FOOD || tmp->type == DRINK || tmp->type == POISON) 2339 if (tmp->type == FOOD || tmp->type == DRINK || tmp->type == POISON)
2346 { 2340 {
2347 op->statusmsg ("You blindly grab for a bite of food. " 2341 op->statusmsg ("You blindly grab for a bite of food. "
2382 op->contr->killer->destroy (); 2376 op->contr->killer->destroy ();
2383 } 2377 }
2384 } 2378 }
2385 2379
2386 /* killer should be set here already */ 2380 /* killer should be set here already */
2387 if (op->stats.hp < 0 && !QUERY_FLAG (op, FLAG_WIZ)) 2381 if (op->stats.hp < 0 && !op->flag [FLAG_WIZ])
2388 kill_player (op); 2382 kill_player (op);
2389 } 2383 }
2390} 2384}
2391 2385
2392/* If the player should die (lack of hp, food, etc), we call this. 2386/* If the player should die (lack of hp, food, etc), we call this.
2587 * difference. 2581 * difference.
2588 */ 2582 */
2589 if (this_stat >= -50) 2583 if (this_stat >= -50)
2590 { 2584 {
2591 change_attr_value (&(dep->stats), i, -1); 2585 change_attr_value (&(dep->stats), i, -1);
2592 SET_FLAG (dep, FLAG_APPLIED); 2586 dep->set_flag (FLAG_APPLIED);
2593 new_draw_info (NDI_UNIQUE, 0, op, lose_msg[i]); 2587 new_draw_info (NDI_UNIQUE, 0, op, lose_msg[i]);
2594 op->update_stats (); 2588 op->update_stats ();
2595 lost_a_stat = 1; 2589 lost_a_stat = 1;
2596 } 2590 }
2597 } 2591 }
2668 2662
2669 force = get_archetype (FORCE_NAME); 2663 force = get_archetype (FORCE_NAME);
2670 /* 50 ticks should be enough time for the spell to abate */ 2664 /* 50 ticks should be enough time for the spell to abate */
2671 force->speed = 0.1f; 2665 force->speed = 0.1f;
2672 force->speed_left = -5.f; 2666 force->speed_left = -5.f;
2673 SET_FLAG (force, FLAG_APPLIED); 2667 force->set_flag (FLAG_APPLIED);
2674 for (at = 0; at < NROFATTACKS; at++) 2668 for (at = 0; at < NROFATTACKS; at++)
2675 if (will_kill_again & (1 << at)) 2669 if (will_kill_again & (1 << at))
2676 force->resist[at] = 100; 2670 force->resist[at] = 100;
2677 2671
2678 insert_ob_in_ob (force, op); 2672 insert_ob_in_ob (force, op);
2700 tmp->x = op->x, tmp->y = op->y; 2694 tmp->x = op->x, tmp->y = op->y;
2701 2695
2702 if (tmp->type == CONTAINER) 2696 if (tmp->type == CONTAINER)
2703 loot_object (tmp); /* empty container to ground */ 2697 loot_object (tmp); /* empty container to ground */
2704 2698
2705 if (!QUERY_FLAG (tmp, FLAG_UNIQUE) && (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || QUERY_FLAG (tmp, FLAG_NO_DROP) || !(rndm (3)))) 2699 if (!tmp->flag [FLAG_UNIQUE] && (tmp->flag [FLAG_STARTEQUIP] || tmp->flag [FLAG_NO_DROP] || !(rndm (3))))
2706 { 2700 {
2707 if (tmp->nrof > 1) 2701 if (tmp->nrof > 1)
2708 { 2702 {
2709 tmp->decrease (rndm (1, tmp->nrof - 1)); 2703 tmp->decrease (rndm (1, tmp->nrof - 1));
2710 insert_ob_in_map (tmp, op->map, NULL, 0); 2704 insert_ob_in_map (tmp, op->map, NULL, 0);
2800} 2794}
2801 2795
2802int 2796int
2803is_true_undead (object *op) 2797is_true_undead (object *op)
2804{ 2798{
2805 if (QUERY_FLAG (op->arch, FLAG_UNDEAD)) 2799 if (op->arch->flag [FLAG_UNDEAD])
2806 return 1; 2800 return 1;
2807 2801
2808 return 0; 2802 return 0;
2809} 2803}
2810 2804
2908 2902
2909 if (who->type == PLAYER) 2903 if (who->type == PLAYER)
2910 player = 1; 2904 player = 1;
2911 2905
2912 else 2906 else
2913 friendly = QUERY_FLAG (who, FLAG_FRIENDLY); 2907 friendly = who->flag [FLAG_FRIENDLY];
2914 2908
2915 /* search adjacent squares */ 2909 /* search adjacent squares */
2916 for (i = 1; i < 9; i++) 2910 for (i = 1; i < 9; i++)
2917 { 2911 {
2918 x = who->x + freearr_x[i]; 2912 x = who->x + freearr_x[i];
2927 if (OB_TYPE_MOVE_BLOCK (who, GET_MAP_MOVE_BLOCK (m, x, y))) 2921 if (OB_TYPE_MOVE_BLOCK (who, GET_MAP_MOVE_BLOCK (m, x, y)))
2928 continue; 2922 continue;
2929 2923
2930 for (tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above) 2924 for (tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above)
2931 { 2925 {
2932 if ((player ||friendly) &&QUERY_FLAG (tmp, FLAG_MONSTER) && !QUERY_FLAG (tmp, FLAG_UNAGGRESSIVE)) 2926 if ((player ||friendly) &&tmp->flag [FLAG_MONSTER] && !tmp->flag [FLAG_UNAGGRESSIVE])
2933 return 1; 2927 return 1;
2934 else if (tmp->type == PLAYER) 2928 else if (tmp->type == PLAYER)
2935 { 2929 {
2936 /*don't let a hidden DM prevent you from hiding */ 2930 /*don't let a hidden DM prevent you from hiding */
2937 if (!QUERY_FLAG (tmp, FLAG_WIZ) || tmp->contr->hidden == 0) 2931 if (!tmp->flag [FLAG_WIZ] || tmp->contr->hidden == 0)
2938 return 1; 2932 return 1;
2939 } 2933 }
2940 } 2934 }
2941 } 2935 }
2942 return 0; 2936 return 0;
3011 * and the exit-coordinates sp/hp must both be > 0. 3005 * and the exit-coordinates sp/hp must both be > 0.
3012 * => The intention here is to prevent abuse of the battleground- 3006 * => The intention here is to prevent abuse of the battleground-
3013 * feature (like pickable or hidden battleground tiles). */ 3007 * feature (like pickable or hidden battleground tiles). */
3014 for (object *tmp = op->below; tmp; tmp = tmp->below) 3008 for (object *tmp = op->below; tmp; tmp = tmp->below)
3015 { 3009 {
3016 if (QUERY_FLAG (tmp, FLAG_IS_FLOOR)) 3010 if (tmp->flag [FLAG_IS_FLOOR])
3017 { 3011 {
3018 if (QUERY_FLAG (tmp, FLAG_NO_PICK) 3012 if (tmp->flag [FLAG_NO_PICK]
3019 && tmp->type == BATTLEGROUND 3013 && tmp->type == BATTLEGROUND
3020 && tmp->name == shstr_battleground 3014 && tmp->name == shstr_battleground
3021 && EXIT_X (tmp) && EXIT_Y (tmp)) 3015 && EXIT_X (tmp) && EXIT_Y (tmp))
3022 { 3016 {
3023 /* before we assign the exit, check if this is a teambattle */ 3017 /* before we assign the exit, check if this is a teambattle */
3181 strcat (buf, "."); 3175 strcat (buf, ".");
3182 new_draw_info (NDI_UNIQUE | NDI_BLUE, 0, who, buf); 3176 new_draw_info (NDI_UNIQUE | NDI_BLUE, 0, who, buf);
3183 } 3177 }
3184 3178
3185 /* evtl. adding flags: */ 3179 /* evtl. adding flags: */
3186 if (QUERY_FLAG (item, FLAG_XRAYS)) 3180 if (item->flag [FLAG_XRAYS])
3187 SET_FLAG (skin, FLAG_XRAYS); 3181 skin->set_flag (FLAG_XRAYS);
3188 if (QUERY_FLAG (item, FLAG_STEALTH)) 3182 if (item->flag [FLAG_STEALTH])
3189 SET_FLAG (skin, FLAG_STEALTH); 3183 skin->set_flag (FLAG_STEALTH);
3190 if (QUERY_FLAG (item, FLAG_SEE_IN_DARK)) 3184 if (item->flag [FLAG_SEE_IN_DARK])
3191 SET_FLAG (skin, FLAG_SEE_IN_DARK); 3185 skin->set_flag (FLAG_SEE_IN_DARK);
3192 3186
3193 /* print message if there is one */ 3187 /* print message if there is one */
3194 if (item->msg != NULL) 3188 if (item->msg != NULL)
3195 new_draw_info (NDI_UNIQUE | NDI_BLUE, 0, who, item->msg); 3189 new_draw_info (NDI_UNIQUE | NDI_BLUE, 0, who, item->msg);
3196 } 3190 }
3238{ 3232{
3239 play_sound (sound_find ("generic_failure")); 3233 play_sound (sound_find ("generic_failure"));
3240 statusmsg (msg, color); 3234 statusmsg (msg, color);
3241} 3235}
3242 3236
3237void
3238object::failmsgf (const char *format, ...)
3239{
3240 if (!contr)
3241 return;
3242
3243 va_list ap;
3244 va_start (ap, format);
3245 contr->failmsg (vformat (format, ap));
3246 va_end (ap);
3247}
3248
3249void
3250player::failmsgf (const char *format, ...)
3251{
3252 va_list ap;
3253 va_start (ap, format);
3254 failmsg (vformat (format, ap));
3255 va_end (ap);
3256}
3257

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines