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.269 by root, Sat Apr 10 04:54:10 2010 UTC vs.
Revision 1.274 by root, Wed Apr 21 06:40:57 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}
729 724
730 if (ob->msg) 725 if (ob->msg)
731 ob->msg = 0; 726 ob->msg = 0;
732 727
733 start_info (ob); 728 start_info (ob);
734 CLEAR_FLAG (ob, FLAG_WIZ); 729 ob->clr_flag (FLAG_WIZ);
735 give_initial_items (ob, ob->randomitems); 730 give_initial_items (ob, ob->randomitems);
736 esrv_send_inventory (ob, ob); 731 esrv_send_inventory (ob, ob);
737 ob->update_stats (); 732 ob->update_stats ();
738 733
739 /* This moves the player to a different start map, if there 734 /* This moves the player to a different start map, if there
788 rv_vector rv; 783 rv_vector rv;
789 784
790 if (op->stats.hp < 0) 785 if (op->stats.hp < 0)
791 { 786 {
792 LOG (llevDebug, "Fleeing player is dead.\n"); 787 LOG (llevDebug, "Fleeing player is dead.\n");
793 CLEAR_FLAG (op, FLAG_SCARED); 788 op->clr_flag (FLAG_SCARED);
794 return; 789 return;
795 } 790 }
796 791
797 if (!op->enemy) 792 if (!op->enemy)
798 { 793 {
799 LOG (llevDebug, "Fleeing player had no enemy.\n"); 794 LOG (llevDebug, "Fleeing player had no enemy.\n");
800 CLEAR_FLAG (op, FLAG_SCARED); 795 op->clr_flag (FLAG_SCARED);
801 return; 796 return;
802 } 797 }
803 798
804 if (!(random_roll (0, 4, op, PREFER_LOW)) && did_make_save (op, op->level, 0)) 799 if (!(random_roll (0, 4, op, PREFER_LOW)) && did_make_save (op, op->level, 0))
805 { 800 {
806 op->enemy = NULL; 801 op->enemy = NULL;
807 CLEAR_FLAG (op, FLAG_SCARED); 802 op->clr_flag (FLAG_SCARED);
808 return; 803 return;
809 } 804 }
810 805
811 get_rangevector (op, op->enemy, &rv, 0); 806 get_rangevector (op, op->enemy, &rv, 0);
812 807
818 if (op->move (absdir (dir + diff * m)) || (diff == 0 && op->move (absdir (dir - diff * m)))) 813 if (op->move (absdir (dir + diff * m)) || (diff == 0 && op->move (absdir (dir - diff * m))))
819 return; 814 return;
820 } 815 }
821 816
822 /* Cornered, get rid of scared */ 817 /* Cornered, get rid of scared */
823 CLEAR_FLAG (op, FLAG_SCARED); 818 op->clr_flag (FLAG_SCARED);
824 op->enemy = NULL; 819 op->enemy = NULL;
825} 820}
826 821
827/* check_pick sees if there is stuff to be picked up/picks up stuff. 822/* 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 823 * It returns 1 if the player should keep on moving, 0 if he should
920 * fighting */ 915 * fighting */
921 if (op->contr->mode & PU_INHIBIT) 916 if (op->contr->mode & PU_INHIBIT)
922 return 1; 917 return 1;
923 918
924 /* prevent us from turning into auto-thieves :) */ 919 /* prevent us from turning into auto-thieves :) */
925 if (QUERY_FLAG (tmp, FLAG_UNPAID)) 920 if (tmp->flag [FLAG_UNPAID])
926 continue; 921 continue;
927 922
928 /* ignore known cursed objects */ 923 /* ignore known cursed objects */
929 if (QUERY_FLAG (tmp, FLAG_KNOWN_CURSED) && op->contr->mode & PU_NOT_CURSED) 924 if (tmp->flag [FLAG_KNOWN_CURSED] && op->contr->mode & PU_NOT_CURSED)
930 continue; 925 continue;
931 926
932 /* all food and drink if desired */ 927 /* all food and drink if desired */
933 /* question: don't pick up known-poisonous stuff? */ 928 /* question: don't pick up known-poisonous stuff? */
934 if (op->contr->mode & PU_FOOD) 929 if (op->contr->mode & PU_FOOD)
937 CHK_PICK_PICKUP; 932 CHK_PICK_PICKUP;
938 continue; 933 continue;
939 } 934 }
940 935
941 if (op->contr->mode & PU_DRINK) 936 if (op->contr->mode & PU_DRINK)
942 if (tmp->type == DRINK || (tmp->type == POISON && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))) 937 if (tmp->type == DRINK || (tmp->type == POISON && !tmp->flag [FLAG_KNOWN_CURSED]))
943 { 938 {
944 CHK_PICK_PICKUP; 939 CHK_PICK_PICKUP;
945 continue; 940 continue;
946 } 941 }
947 942
985 continue; 980 continue;
986 } 981 }
987 982
988 /* pick up all magical items */ 983 /* pick up all magical items */
989 if (op->contr->mode & PU_MAGICAL) 984 if (op->contr->mode & PU_MAGICAL)
990 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) 985 if (tmp->flag [FLAG_KNOWN_MAGICAL]
991 && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)) 986 && !tmp->flag [FLAG_KNOWN_CURSED])
992 { 987 {
993 CHK_PICK_PICKUP; 988 CHK_PICK_PICKUP;
994 continue; 989 continue;
995 } 990 }
996 991
1080 continue; 1075 continue;
1081 } 1076 }
1082 1077
1083 /* hoping to catch throwing daggers here */ 1078 /* hoping to catch throwing daggers here */
1084 if (op->contr->mode & PU_MISSILEWEAPON) 1079 if (op->contr->mode & PU_MISSILEWEAPON)
1085 if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_IS_THROWN)) 1080 if (tmp->type == WEAPON && tmp->flag [FLAG_IS_THROWN])
1086 { 1081 {
1087 CHK_PICK_PICKUP; 1082 CHK_PICK_PICKUP;
1088 continue; 1083 continue;
1089 } 1084 }
1090 1085
1145 * return 0. 1140 * return 0.
1146 */ 1141 */
1147static int 1142static int
1148action_makes_visible (object *op) 1143action_makes_visible (object *op)
1149{ 1144{
1150 if (op->invisible && QUERY_FLAG (op, FLAG_ALIVE)) 1145 if (op->invisible && op->flag [FLAG_ALIVE])
1151 { 1146 {
1152 if (QUERY_FLAG (op, FLAG_MAKE_INVIS)) 1147 if (op->flag [FLAG_MAKE_INVIS])
1153 { 1148 {
1154 // artefact invisibility is permanent, but we still make noise 1149 // artefact invisibility is permanent, but we still make noise
1155 // this is important for game-balance. 1150 // this is important for game-balance.
1156 if (op->contr) 1151 if (op->contr)
1157 op->make_noise (); 1152 op->make_noise ();
1184 for (object *tmp = op->inv; tmp; tmp = tmp->below) 1179 for (object *tmp = op->inv; tmp; tmp = tmp->below)
1185 if (tmp->type == ARROW && !strcmp (&tmp->race, type)) 1180 if (tmp->type == ARROW && !strcmp (&tmp->race, type))
1186 return splay (tmp); 1181 return splay (tmp);
1187 1182
1188 for (object *tmp = op->inv; tmp; tmp = tmp->below) 1183 for (object *tmp = op->inv; tmp; tmp = tmp->below)
1189 if (tmp->type == CONTAINER && QUERY_FLAG (tmp, FLAG_APPLIED) && !strcmp (&tmp->race, type)) 1184 if (tmp->type == CONTAINER && tmp->flag [FLAG_APPLIED] && !strcmp (&tmp->race, type))
1190 if (object *arrow = find_arrow (tmp, type)) 1185 if (object *arrow = find_arrow (tmp, type))
1191 { 1186 {
1192 splay (tmp); 1187 splay (tmp);
1193 return arrow; 1188 return arrow;
1194 } 1189 }
1211 if (!type) 1206 if (!type)
1212 return NULL; 1207 return NULL;
1213 1208
1214 for (arrow = op->inv; arrow; arrow = arrow->below) 1209 for (arrow = op->inv; arrow; arrow = arrow->below)
1215 { 1210 {
1216 if (arrow->type == CONTAINER && arrow->race == type && QUERY_FLAG (arrow, FLAG_APPLIED)) 1211 if (arrow->type == CONTAINER && arrow->race == type && arrow->flag [FLAG_APPLIED])
1217 { 1212 {
1218 i = 0; 1213 i = 0;
1219 ntmp = find_better_arrow (arrow, target, type, &i); 1214 ntmp = find_better_arrow (arrow, target, type, &i);
1220 1215
1221 if (i > betterby) 1216 if (i > betterby)
1322 break; 1317 break;
1323 } 1318 }
1324 1319
1325 if (mflags & P_IS_ALIVE) 1320 if (mflags & P_IS_ALIVE)
1326 for (tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above) 1321 for (tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above)
1327 if (QUERY_FLAG (tmp, FLAG_ALIVE)) 1322 if (tmp->flag [FLAG_ALIVE])
1328 break; 1323 break;
1329 } 1324 }
1330 1325
1331 if (!tmp) 1326 if (!tmp)
1332 return find_arrow (op, type); 1327 return find_arrow (op, type);
1393 { 1388 {
1394 if (op->type == PLAYER) 1389 if (op->type == PLAYER)
1395 new_draw_info_format (NDI_UNIQUE, 0, op, "You have no %s left.", &bow->race); 1390 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 */ 1391 /* FLAG_READY_BOW will get reset if the monsters picks up some arrows */
1397 else 1392 else
1398 CLEAR_FLAG (op, FLAG_READY_BOW); 1393 op->clr_flag (FLAG_READY_BOW);
1399 1394
1400 return 0; 1395 return 0;
1401 } 1396 }
1402 } 1397 }
1403 1398
1603 { 1598 {
1604 object *tmp; 1599 object *tmp;
1605 1600
1606 if (item->arch) 1601 if (item->arch)
1607 { 1602 {
1608 CLEAR_FLAG (item, FLAG_ANIMATE); 1603 item->clr_flag (FLAG_ANIMATE);
1609 item->face = item->arch->face; 1604 item->face = item->arch->face;
1610 item->set_speed (0); 1605 item->set_speed (0);
1611 } 1606 }
1612 1607
1613 if (object *pl = item->visible_to ()) 1608 if (object *pl = item->visible_to ())
1741 * 1736 *
1742 * Change the color so that the message doesn't disappear with 1737 * Change the color so that the message doesn't disappear with
1743 * all the others. 1738 * all the others.
1744 */ 1739 */
1745 if (pl->contr->usekeys == key_inventory 1740 if (pl->contr->usekeys == key_inventory
1746 || !QUERY_FLAG (container, FLAG_APPLIED) 1741 || !container->flag [FLAG_APPLIED]
1747 || (pl->contr->usekeys == keyrings && container->race != shstr_keys)) 1742 || (pl->contr->usekeys == keyrings && container->race != shstr_keys))
1748 { 1743 {
1749 new_draw_info_format (NDI_UNIQUE | NDI_BROWN, 0, pl, 1744 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)); 1745 "The %s in your %s vibrates as you approach the door", query_name (tmp), query_name (container));
1751 return NULL; 1746 return NULL;
1902 */ 1897 */
1903 if (op->type == PLAYER 1898 if (op->type == PLAYER
1904 && ((mon->owner && mon->owner->contr 1899 && ((mon->owner && mon->owner->contr
1905 && same_party (mon->owner->contr->party, op->contr->party)) 1900 && same_party (mon->owner->contr->party, op->contr->party))
1906 || mon->owner == op) 1901 || mon->owner == op)
1907 && (QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY))) 1902 && (mon->flag [FLAG_UNAGGRESSIVE] || mon->flag [FLAG_FRIENDLY]))
1908 { 1903 {
1909 /* If we're braced, we don't want to switch places with it */ 1904 /* If we're braced, we don't want to switch places with it */
1910 if (op->contr->braced) 1905 if (op->contr->braced)
1911 return false; 1906 return false;
1912 1907
1932 * creatures. Note that if you are braced, you can't push 1927 * creatures. Note that if you are braced, you can't push
1933 * someone, but put it inside this loop so that you won't 1928 * someone, but put it inside this loop so that you won't
1934 * attack them either. 1929 * attack them either.
1935 */ 1930 */
1936 if ((mon->type == PLAYER || mon->enemy != op) 1931 if ((mon->type == PLAYER || mon->enemy != op)
1937 && (mon->type == PLAYER || QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY)) 1932 && (mon->type == PLAYER || mon->flag [FLAG_UNAGGRESSIVE] || mon->flag [FLAG_FRIENDLY])
1938 && ((op->contr->peaceful 1933 && ((op->contr->peaceful
1939 || (mon->type == PLAYER && mon->contr->peaceful)) 1934 || (mon->type == PLAYER && mon->contr->peaceful))
1940 && !on_battleground)) 1935 && !on_battleground))
1941 { 1936 {
1942 if (op->speed_left > 0.f) 1937 if (op->speed_left > 0.f)
1958 } 1953 }
1959 } 1954 }
1960 /* If the object is a boulder or other rollable object, then 1955 /* 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. 1956 * roll it if not braced. You can't roll it if you are braced.
1962 */ 1957 */
1963 else if (QUERY_FLAG (mon, FLAG_CAN_ROLL) && (!op->contr->braced)) 1958 else if (mon->flag [FLAG_CAN_ROLL] && (!op->contr->braced))
1964 { 1959 {
1965 if (op->speed_left > 0.f) 1960 if (op->speed_left > 0.f)
1966 { 1961 {
1967 --op->speed_left; 1962 --op->speed_left;
1968 1963
1977 * Way it works is like this: First, it must have some hit points 1972 * 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: 1973 * 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 1974 * 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. 1975 * that party_number -1 is no party, so attacks can still happen.
1981 */ 1976 */
1982 else if ((mon->stats.hp >= 0) && QUERY_FLAG (mon, FLAG_ALIVE) && 1977 else if ((mon->stats.hp >= 0) && mon->flag [FLAG_ALIVE] &&
1983 ((mon->type != PLAYER || op->contr->party == NULL || op->contr->party != mon->contr->party))) 1978 ((mon->type != PLAYER || op->contr->party == NULL || op->contr->party != mon->contr->party)))
1984 { 1979 {
1985 if (op->contr->weapon_sp_left > 0.f && !op->flag [FLAG_WIZPASS]) 1980 if (op->contr->weapon_sp_left > 0.f && !op->flag [FLAG_WIZPASS])
1986 { 1981 {
1987 --op->contr->weapon_sp_left; 1982 --op->contr->weapon_sp_left;
2003{ 1998{
2004 if (!op->map || op->map->in_memory != MAP_ACTIVE) 1999 if (!op->map || op->map->in_memory != MAP_ACTIVE)
2005 return 0; 2000 return 0;
2006 2001
2007 /* Sanity check: make sure dir is valid */ 2002 /* Sanity check: make sure dir is valid */
2008 if (dir < 0 || dir >= 9) 2003 if (dir < 0 || dir > 8)
2009 { 2004 {
2010 LOG (llevError, "move_player: invalid direction %d\n", dir); 2005 LOG (llevError, "move_player: invalid direction %d\n", dir);
2011 return 0; 2006 return 0;
2012 } 2007 }
2013 2008
2014 /* peterm: added following line */ 2009 /* peterm: added following line */
2015 if (QUERY_FLAG (op, FLAG_CONFUSED) && dir) 2010 if (op->flag [FLAG_CONFUSED] && dir)
2016 dir = absdir (dir + rndm (3) + rndm (3) - 2); 2011 dir = absdir (dir + rndm (3) + rndm (3) - 2);
2017 2012
2018 op->facing = dir; 2013 op->facing = dir;
2019 2014
2020 if (op->flag [FLAG_HIDDEN]) 2015 if (op->flag [FLAG_HIDDEN])
2060 * players. 2055 * players.
2061 */ 2056 */
2062bool 2057bool
2063handle_newcs_player (object *op) 2058handle_newcs_player (object *op)
2064{ 2059{
2065 if (QUERY_FLAG (op, FLAG_SCARED)) 2060 if (op->flag [FLAG_SCARED])
2066 { 2061 {
2067 if (op->speed_left > 0.f) 2062 if (op->speed_left > 0.f)
2068 { 2063 {
2069 --op->speed_left; 2064 --op->speed_left;
2070 flee_player (op); 2065 flee_player (op);
2089} 2084}
2090 2085
2091static int 2086static int
2092save_life (object *op) 2087save_life (object *op)
2093{ 2088{
2094 if (!QUERY_FLAG (op, FLAG_LIFESAVE)) 2089 if (!op->flag [FLAG_LIFESAVE])
2095 return 0; 2090 return 0;
2096 2091
2097 for (object *tmp = op->inv; tmp; tmp = tmp->below) 2092 for (object *tmp = op->inv; tmp; tmp = tmp->below)
2098 if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE)) 2093 if (tmp->flag [FLAG_APPLIED] && tmp->flag [FLAG_LIFESAVE])
2099 { 2094 {
2100 op->play_sound (sound_find ("ob_evaporate")); 2095 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)); 2096 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s vibrates violently, then evaporates.", query_name (tmp));
2102 2097
2103 tmp->destroy (); 2098 tmp->destroy ();
2104 CLEAR_FLAG (op, FLAG_LIFESAVE); 2099 op->clr_flag (FLAG_LIFESAVE);
2105 2100
2106 if (op->stats.hp < 0) 2101 if (op->stats.hp < 0)
2107 op->stats.hp = op->stats.maxhp; 2102 op->stats.hp = op->stats.maxhp;
2108 2103
2109 if (op->stats.food < 0) 2104 if (op->stats.food < 0)
2112 op->update_stats (); 2107 op->update_stats ();
2113 return 1; 2108 return 1;
2114 } 2109 }
2115 2110
2116 LOG (llevError, "Error: LIFESAVE set without applied object.\n"); 2111 LOG (llevError, "Error: LIFESAVE set without applied object.\n");
2117 CLEAR_FLAG (op, FLAG_LIFESAVE); 2112 op->clr_flag (FLAG_LIFESAVE);
2118 enter_player_savebed (op); /* bring him home. */ 2113 enter_player_savebed (op); /* bring him home. */
2119 return 0; 2114 return 0;
2120} 2115}
2121 2116
2122/* This goes throws the inventory and removes unpaid objects, and puts them 2117/* This goes throws the inventory and removes unpaid objects, and puts them
2129{ 2124{
2130 while (op) 2125 while (op)
2131 { 2126 {
2132 object *next = op->below; /* Make sure we have a good value, in case we remove object 'op' */ 2127 object *next = op->below; /* Make sure we have a good value, in case we remove object 'op' */
2133 2128
2134 if (QUERY_FLAG (op, FLAG_UNPAID)) 2129 if (op->flag [FLAG_UNPAID])
2135 op->insert_at (env); 2130 op->insert_at (env);
2136 else if (op->inv) 2131 else if (op->inv)
2137 drop_unpaid_items (op->inv, env); 2132 drop_unpaid_items (op->inv, env);
2138 2133
2139 op = next; 2134 op = next;
2169 * alternate it here for it to work correctly. 2164 * alternate it here for it to work correctly.
2170 */ 2165 */
2171 if (pticks & 2) 2166 if (pticks & 2)
2172 op->invisible--; 2167 op->invisible--;
2173 } 2168 }
2174 else if (op->invisible && !(QUERY_FLAG (op, FLAG_MAKE_INVIS))) 2169 else if (op->invisible && !(op->flag [FLAG_MAKE_INVIS]))
2175 { 2170 {
2176 if (!op->invisible--) 2171 if (!op->invisible--)
2177 { 2172 {
2178 make_visible (op); 2173 make_visible (op);
2179 new_draw_info (NDI_UNIQUE, 0, op, "Your invisibility spell runs out."); 2174 new_draw_info (NDI_UNIQUE, 0, op, "Your invisibility spell runs out.");
2246 if (op->stats.sp < op->stats.maxsp) 2241 if (op->stats.sp < op->stats.maxsp)
2247 { 2242 {
2248 op->stats.sp++; 2243 op->stats.sp++;
2249 2244
2250 /* dms do not consume food */ 2245 /* dms do not consume food */
2251 if (!QUERY_FLAG (op, FLAG_WIZ)) 2246 if (!op->flag [FLAG_WIZ])
2252 { 2247 {
2253 op->stats.food--; 2248 op->stats.food--;
2254 2249
2255 if (op->contr->digestion < 0) 2250 if (op->contr->digestion < 0)
2256 op->stats.food += op->contr->digestion; 2251 op->stats.food += op->contr->digestion;
2290 if (op->stats.hp < op->stats.maxhp) 2285 if (op->stats.hp < op->stats.maxhp)
2291 { 2286 {
2292 op->stats.hp++; 2287 op->stats.hp++;
2293 2288
2294 /* dms do not consume food */ 2289 /* dms do not consume food */
2295 if (!QUERY_FLAG (op, FLAG_WIZ)) 2290 if (!op->flag [FLAG_WIZ])
2296 { 2291 {
2297 op->stats.food--; 2292 op->stats.food--;
2298 2293
2299 if (op->contr->digestion < 0) 2294 if (op->contr->digestion < 0)
2300 op->stats.food += op->contr->digestion; 2295 op->stats.food += op->contr->digestion;
2327 penalty = max (0, -op->contr->digestion); 2322 penalty = max (0, -op->contr->digestion);
2328 2323
2329 op->last_eat = 25 * (1 + bonus) / (max (0, op->contr->gen_hp) + penalty + 1); 2324 op->last_eat = 25 * (1 + bonus) / (max (0, op->contr->gen_hp) + penalty + 1);
2330 2325
2331 /* dms do not consume food */ 2326 /* dms do not consume food */
2332 if (!QUERY_FLAG (op, FLAG_WIZ)) 2327 if (!op->flag [FLAG_WIZ])
2333 op->stats.food--; 2328 op->stats.food--;
2334 } 2329 }
2335 2330
2336 if (op->stats.food < 0 && op->stats.hp >= 0) 2331 if (op->stats.food < 0 && op->stats.hp >= 0)
2337 { 2332 {
2338 object *flesh = 0; 2333 object *flesh = 0;
2339 2334
2340 for_inv_removable (op, tmp) 2335 for_inv_removable (op, tmp)
2341 { 2336 {
2342 if (QUERY_FLAG (tmp, FLAG_UNPAID)) 2337 if (tmp->flag [FLAG_UNPAID])
2343 continue; 2338 continue;
2344 2339
2345 if (tmp->type == FOOD || tmp->type == DRINK || tmp->type == POISON) 2340 if (tmp->type == FOOD || tmp->type == DRINK || tmp->type == POISON)
2346 { 2341 {
2347 op->statusmsg ("You blindly grab for a bite of food. " 2342 op->statusmsg ("You blindly grab for a bite of food. "
2382 op->contr->killer->destroy (); 2377 op->contr->killer->destroy ();
2383 } 2378 }
2384 } 2379 }
2385 2380
2386 /* killer should be set here already */ 2381 /* killer should be set here already */
2387 if (op->stats.hp < 0 && !QUERY_FLAG (op, FLAG_WIZ)) 2382 if (op->stats.hp < 0 && !op->flag [FLAG_WIZ])
2388 kill_player (op); 2383 kill_player (op);
2389 } 2384 }
2390} 2385}
2391 2386
2392/* If the player should die (lack of hp, food, etc), we call this. 2387/* If the player should die (lack of hp, food, etc), we call this.
2587 * difference. 2582 * difference.
2588 */ 2583 */
2589 if (this_stat >= -50) 2584 if (this_stat >= -50)
2590 { 2585 {
2591 change_attr_value (&(dep->stats), i, -1); 2586 change_attr_value (&(dep->stats), i, -1);
2592 SET_FLAG (dep, FLAG_APPLIED); 2587 dep->set_flag (FLAG_APPLIED);
2593 new_draw_info (NDI_UNIQUE, 0, op, lose_msg[i]); 2588 new_draw_info (NDI_UNIQUE, 0, op, lose_msg[i]);
2594 op->update_stats (); 2589 op->update_stats ();
2595 lost_a_stat = 1; 2590 lost_a_stat = 1;
2596 } 2591 }
2597 } 2592 }
2668 2663
2669 force = get_archetype (FORCE_NAME); 2664 force = get_archetype (FORCE_NAME);
2670 /* 50 ticks should be enough time for the spell to abate */ 2665 /* 50 ticks should be enough time for the spell to abate */
2671 force->speed = 0.1f; 2666 force->speed = 0.1f;
2672 force->speed_left = -5.f; 2667 force->speed_left = -5.f;
2673 SET_FLAG (force, FLAG_APPLIED); 2668 force->set_flag (FLAG_APPLIED);
2674 for (at = 0; at < NROFATTACKS; at++) 2669 for (at = 0; at < NROFATTACKS; at++)
2675 if (will_kill_again & (1 << at)) 2670 if (will_kill_again & (1 << at))
2676 force->resist[at] = 100; 2671 force->resist[at] = 100;
2677 2672
2678 insert_ob_in_ob (force, op); 2673 insert_ob_in_ob (force, op);
2700 tmp->x = op->x, tmp->y = op->y; 2695 tmp->x = op->x, tmp->y = op->y;
2701 2696
2702 if (tmp->type == CONTAINER) 2697 if (tmp->type == CONTAINER)
2703 loot_object (tmp); /* empty container to ground */ 2698 loot_object (tmp); /* empty container to ground */
2704 2699
2705 if (!QUERY_FLAG (tmp, FLAG_UNIQUE) && (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || QUERY_FLAG (tmp, FLAG_NO_DROP) || !(rndm (3)))) 2700 if (!tmp->flag [FLAG_UNIQUE] && (tmp->flag [FLAG_STARTEQUIP] || tmp->flag [FLAG_NO_DROP] || !(rndm (3))))
2706 { 2701 {
2707 if (tmp->nrof > 1) 2702 if (tmp->nrof > 1)
2708 { 2703 {
2709 tmp->decrease (rndm (1, tmp->nrof - 1)); 2704 tmp->decrease (rndm (1, tmp->nrof - 1));
2710 insert_ob_in_map (tmp, op->map, NULL, 0); 2705 insert_ob_in_map (tmp, op->map, NULL, 0);
2800} 2795}
2801 2796
2802int 2797int
2803is_true_undead (object *op) 2798is_true_undead (object *op)
2804{ 2799{
2805 if (QUERY_FLAG (op->arch, FLAG_UNDEAD)) 2800 if (op->arch->flag [FLAG_UNDEAD])
2806 return 1; 2801 return 1;
2807 2802
2808 return 0; 2803 return 0;
2809} 2804}
2810 2805
2908 2903
2909 if (who->type == PLAYER) 2904 if (who->type == PLAYER)
2910 player = 1; 2905 player = 1;
2911 2906
2912 else 2907 else
2913 friendly = QUERY_FLAG (who, FLAG_FRIENDLY); 2908 friendly = who->flag [FLAG_FRIENDLY];
2914 2909
2915 /* search adjacent squares */ 2910 /* search adjacent squares */
2916 for (i = 1; i < 9; i++) 2911 for (i = 1; i < 9; i++)
2917 { 2912 {
2918 x = who->x + freearr_x[i]; 2913 x = who->x + freearr_x[i];
2927 if (OB_TYPE_MOVE_BLOCK (who, GET_MAP_MOVE_BLOCK (m, x, y))) 2922 if (OB_TYPE_MOVE_BLOCK (who, GET_MAP_MOVE_BLOCK (m, x, y)))
2928 continue; 2923 continue;
2929 2924
2930 for (tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above) 2925 for (tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above)
2931 { 2926 {
2932 if ((player ||friendly) &&QUERY_FLAG (tmp, FLAG_MONSTER) && !QUERY_FLAG (tmp, FLAG_UNAGGRESSIVE)) 2927 if ((player ||friendly) &&tmp->flag [FLAG_MONSTER] && !tmp->flag [FLAG_UNAGGRESSIVE])
2933 return 1; 2928 return 1;
2934 else if (tmp->type == PLAYER) 2929 else if (tmp->type == PLAYER)
2935 { 2930 {
2936 /*don't let a hidden DM prevent you from hiding */ 2931 /*don't let a hidden DM prevent you from hiding */
2937 if (!QUERY_FLAG (tmp, FLAG_WIZ) || tmp->contr->hidden == 0) 2932 if (!tmp->flag [FLAG_WIZ] || tmp->contr->hidden == 0)
2938 return 1; 2933 return 1;
2939 } 2934 }
2940 } 2935 }
2941 } 2936 }
2942 return 0; 2937 return 0;
3011 * and the exit-coordinates sp/hp must both be > 0. 3006 * and the exit-coordinates sp/hp must both be > 0.
3012 * => The intention here is to prevent abuse of the battleground- 3007 * => The intention here is to prevent abuse of the battleground-
3013 * feature (like pickable or hidden battleground tiles). */ 3008 * feature (like pickable or hidden battleground tiles). */
3014 for (object *tmp = op->below; tmp; tmp = tmp->below) 3009 for (object *tmp = op->below; tmp; tmp = tmp->below)
3015 { 3010 {
3016 if (QUERY_FLAG (tmp, FLAG_IS_FLOOR)) 3011 if (tmp->flag [FLAG_IS_FLOOR])
3017 { 3012 {
3018 if (QUERY_FLAG (tmp, FLAG_NO_PICK) 3013 if (tmp->flag [FLAG_NO_PICK]
3019 && tmp->type == BATTLEGROUND 3014 && tmp->type == BATTLEGROUND
3020 && tmp->name == shstr_battleground 3015 && tmp->name == shstr_battleground
3021 && EXIT_X (tmp) && EXIT_Y (tmp)) 3016 && EXIT_X (tmp) && EXIT_Y (tmp))
3022 { 3017 {
3023 /* before we assign the exit, check if this is a teambattle */ 3018 /* before we assign the exit, check if this is a teambattle */
3181 strcat (buf, "."); 3176 strcat (buf, ".");
3182 new_draw_info (NDI_UNIQUE | NDI_BLUE, 0, who, buf); 3177 new_draw_info (NDI_UNIQUE | NDI_BLUE, 0, who, buf);
3183 } 3178 }
3184 3179
3185 /* evtl. adding flags: */ 3180 /* evtl. adding flags: */
3186 if (QUERY_FLAG (item, FLAG_XRAYS)) 3181 if (item->flag [FLAG_XRAYS])
3187 SET_FLAG (skin, FLAG_XRAYS); 3182 skin->set_flag (FLAG_XRAYS);
3188 if (QUERY_FLAG (item, FLAG_STEALTH)) 3183 if (item->flag [FLAG_STEALTH])
3189 SET_FLAG (skin, FLAG_STEALTH); 3184 skin->set_flag (FLAG_STEALTH);
3190 if (QUERY_FLAG (item, FLAG_SEE_IN_DARK)) 3185 if (item->flag [FLAG_SEE_IN_DARK])
3191 SET_FLAG (skin, FLAG_SEE_IN_DARK); 3186 skin->set_flag (FLAG_SEE_IN_DARK);
3192 3187
3193 /* print message if there is one */ 3188 /* print message if there is one */
3194 if (item->msg != NULL) 3189 if (item->msg != NULL)
3195 new_draw_info (NDI_UNIQUE | NDI_BLUE, 0, who, item->msg); 3190 new_draw_info (NDI_UNIQUE | NDI_BLUE, 0, who, item->msg);
3196 } 3191 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines