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.123 by root, Fri May 11 21:07:14 2007 UTC vs.
Revision 1.133 by root, Sat May 12 22:04:20 2007 UTC

319player::set_object (object *op) 319player::set_object (object *op)
320{ 320{
321 ob = op; 321 ob = op;
322 ob->contr = this; /* this aren't yet in archetype */ 322 ob->contr = this; /* this aren't yet in archetype */
323 323
324 ob->speed_left = 0.5; 324 ob->speed_left = 0.5f;
325 ob->speed = 1.0; 325 ob->speed = 1.0f;
326 ob->direction = 5; /* So player faces south */ 326 ob->direction = 5; /* So player faces south */
327} 327}
328 328
329player::player () 329player::player ()
330{ 330{
784} 784}
785 785
786void 786void
787object::roll_stats () 787object::roll_stats ()
788{ 788{
789 int statsort [7]; 789 int statsort [NUM_STATS];
790 790
791 for (;;) 791 for (;;)
792 { 792 {
793 int sum = 0; 793 int sum = 0;
794 for (int i = 7; i--; ) 794 for (int i = NUM_STATS; i--; )
795 sum += statsort [i] = roll_stat (); 795 sum += statsort [i] = roll_stat ();
796 796
797 if (sum >= 82 && sum <= 116) 797 if (sum >= 82 && sum <= 116)
798 break; 798 break;
799 } 799 }
800 800
801 // Sort the stats so that rerolling is easier... 801 // Sort the stats so that rerolling is easier...
802 std::sort (statsort, statsort + 7, std::greater<int>()); 802 std::sort (statsort, statsort + NUM_STATS, std::greater<int>());
803 803
804 for (int i = 0; i < NUM_STATS; ++i)
804 stats.Str = statsort[0]; 805 stats.stat (i) = statsort [i];
805 stats.Dex = statsort[1];
806 stats.Con = statsort[2];
807 stats.Int = statsort[3];
808 stats.Wis = statsort[4];
809 stats.Pow = statsort[5];
810 stats.Cha = statsort[6];
811 806
812 stats.exp = 0; 807 stats.exp = 0;
813 stats.ac = 0; 808 stats.ac = 0;
814 809
815 stats.hp = stats.maxhp; 810 stats.hp = stats.maxhp;
827} 822}
828 823
829void 824void
830object::swap_stats (int a, int b) 825object::swap_stats (int a, int b)
831{ 826{
832 int tmp = get_attr_value (&contr->orig_stats, a); 827 swap (contr->orig_stats.stat (a), contr->orig_stats.stat (b));
833 set_attr_value (&contr->orig_stats, a, get_attr_value (&contr->orig_stats, b));
834 set_attr_value (&contr->orig_stats, b, tmp);
835 828
829 for (int i = 0; i < NUM_STATS; ++i)
836 stats.Str = contr->orig_stats.Str; 830 stats.stat (i) = contr->orig_stats.stat (i);
837 stats.Dex = contr->orig_stats.Dex;
838 stats.Con = contr->orig_stats.Con;
839 stats.Int = contr->orig_stats.Int;
840 stats.Wis = contr->orig_stats.Wis;
841 stats.Pow = contr->orig_stats.Pow;
842 stats.Cha = contr->orig_stats.Cha;
843 831
844 //TODO: the following code looks so borked and should, at the very least, 832 //TODO: the following code looks so borked and should, at the very least,
845 // be merged with the similar code in roll_stats 833 // be merged with the similar code in roll_stats
846 stats.ac = 0; 834 stats.ac = 0;
847 835
1547 */ 1535 */
1548int 1536int
1549fire_bow (object *op, object *part, object *arrow, int dir, int wc_mod, sint16 sx, sint16 sy) 1537fire_bow (object *op, object *part, object *arrow, int dir, int wc_mod, sint16 sx, sint16 sy)
1550{ 1538{
1551 object *left, *bow; 1539 object *left, *bow;
1552 int bowspeed, mflags; 1540 int mflags;
1553 maptile *m; 1541 maptile *m;
1554 1542
1555 if (!dir) 1543 if (!dir)
1556 { 1544 {
1557 new_draw_info (NDI_UNIQUE, 0, op, "You can't shoot yourself!"); 1545 new_draw_info (NDI_UNIQUE, 0, op, "You can't shoot yourself!");
1559 } 1547 }
1560 1548
1561 if (player *pl = op->contr) 1549 if (player *pl = op->contr)
1562 { 1550 {
1563 bow = pl->ranged_ob; 1551 bow = pl->ranged_ob;
1564 op->set_weapon (bow); 1552 if (!op->change_weapon (bow))
1553 return 0;
1565 } 1554 }
1566 else 1555 else
1567 { 1556 {
1568 for (bow = op->inv; bow; bow = bow->below) 1557 for (bow = op->inv; bow; bow = bow->below)
1569 /* Don't check for applied - monsters don't apply bows - in that way, they 1558 /* Don't check for applied - monsters don't apply bows - in that way, they
1591 { 1580 {
1592 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s is broken.", &bow->name); 1581 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s is broken.", &bow->name);
1593 return 0; 1582 return 0;
1594 } 1583 }
1595 1584
1596 bowspeed = bow->stats.sp + dex_bonus[op->stats.Dex];
1597
1598 /* penalize ROF for bestarrow */
1599 if (op->type == PLAYER && op->contr->bowtype == bow_bestarrow)
1600 bowspeed -= dex_bonus[op->stats.Dex] + 5;
1601
1602 if (bowspeed < 1)
1603 bowspeed = 1;
1604
1605 if (arrow == NULL) 1585 if (arrow == NULL)
1606 { 1586 {
1607 if ((arrow = find_arrow (op, bow->race)) == NULL) 1587 if ((arrow = find_arrow (op, bow->race)) == NULL)
1608 { 1588 {
1609 if (op->type == PLAYER) 1589 if (op->type == PLAYER)
1643 1623
1644 arrow->set_owner (op); 1624 arrow->set_owner (op);
1645 arrow->skill = bow->skill; 1625 arrow->skill = bow->skill;
1646 arrow->direction = dir; 1626 arrow->direction = dir;
1647 1627
1648 if (op->type == PLAYER)
1649 {
1650 op->speed_left = 0.01 - (float) FABS (op->speed) * 100 / bowspeed;
1651 op->update_stats ();
1652 }
1653
1654 SET_ANIMATION (arrow, arrow->direction);
1655
1656 arrow->stats.sp = arrow->stats.wc; /* save original wc and dam */ 1628 arrow->stats.sp = arrow->stats.wc; /* save original wc, dam, attacktype and slaying */
1657 arrow->stats.hp = arrow->stats.dam; 1629 arrow->stats.hp = arrow->stats.dam;
1658 arrow->stats.grace = arrow->attacktype; 1630 arrow->stats.grace = arrow->attacktype;
1659 1631
1660 if (arrow->slaying) 1632 if (arrow->slaying)
1661 arrow->spellarg = strdup (arrow->slaying); 1633 arrow->spellarg = strdup (arrow->slaying);
1662 1634
1663 arrow->stats.dam += op->stats.dam + arrow->magic; 1635 if (player *pl = op->contr)
1636 {
1637 pl->has_hit = 1;
1638#if 0
1639 float speed = pl->weapon_sp;
1640
1641 /* penalize ROF for bestarrow */
1642 if (pl->bowtype == bow_bestarrow)
1643 speed *= .9f;
1644 else
1645 speed *= 1.f + dex_bonus[op->stats.Dex] * .2f;
1646
1647 op->speed_left += speed - op->speed;
1648#endif
1649 }
1650
1651 SET_ANIMATION (arrow, arrow->direction);
1664 1652
1665 /* update the speed */ 1653 /* update the speed */
1666 arrow->speed = (float) ((QUERY_FLAG (bow, FLAG_NO_STRENGTH) ? 1654 arrow->speed = ((bow->flag [FLAG_NO_STRENGTH] ? 0 : dam_bonus[op->stats.Str]) + bow->magic + arrow->magic) / 5.0
1667 0 : dam_bonus[op->stats.Str]) + bow->magic + arrow->magic) / 5.0 + (float) bow->stats.dam / 7.0; 1655 + bow->stats.dam / 7.0;
1668 1656
1669 arrow->set_speed (max (arrow->speed, 1.0)); 1657 arrow->set_speed (max (arrow->speed, 2.0));
1670 arrow->speed_left = 0; 1658 arrow->speed_left = 0;
1671 1659
1672 arrow->stats.wc = op->stats.wc + wc_mod - arrow->magic - arrow->stats.wc; 1660 int wc = op->stats.wc + wc_mod - arrow->magic - arrow->stats.wc;
1673 1661
1674 if (op->type == PLAYER) 1662 if (op->type == PLAYER)
1675 { 1663 {
1676 arrow->level = op->chosen_skill ? op->chosen_skill->level : op->level; 1664 arrow->level = op->chosen_skill ? op->chosen_skill->level : op->level;
1677 arrow->stats.wc -= dex_bonus[op->stats.Dex]; 1665 wc -= dex_bonus[op->stats.Dex];
1678 1666
1679 if (!arrow->slaying) 1667 if (!arrow->slaying)
1680 arrow->slaying = op->slaying; 1668 arrow->slaying = op->slaying;
1669
1670 arrow->attacktype |= op->attacktype;
1681 } 1671 }
1682 else 1672 else
1683 { 1673 {
1684 arrow->level = op->level; 1674 arrow->level = op->level;
1685 arrow->stats.wc -= bow->magic; 1675 arrow->stats.wc -= bow->magic;
1686 1676
1687 if (!arrow->slaying) 1677 if (!arrow->slaying)
1688 arrow->slaying = bow->slaying; 1678 arrow->slaying = bow->slaying;
1689 }
1690 1679
1691 arrow->stats.wc -= arrow->level;
1692
1693 arrow->attacktype |= bow->attacktype; 1680 arrow->attacktype |= bow->attacktype;
1681 }
1694 1682
1683 wc -= arrow->level;
1684 arrow->stats.dam = clamp (arrow->stats.dam + op->stats.dam + arrow->magic, MIN_DAM, MAX_DAM);
1685
1686 arrow->stats.wc = clamp (wc, MIN_WC, MAX_WC);
1695 arrow->move_type = MOVE_FLY_LOW; 1687 arrow->move_type = MOVE_FLY_LOW;
1696 arrow->move_on = MOVE_FLY_LOW | MOVE_WALK; 1688 arrow->move_on = MOVE_FLY_LOW | MOVE_WALK;
1697 1689
1698 play_sound_map (op->map, op->x, op->y, SOUND_FIRE_ARROW); 1690 play_sound_map (op->map, op->x, op->y, SOUND_FIRE_ARROW);
1699 m->insert (arrow, sx, sy, op); 1691 m->insert (arrow, sx, sy, op);
1775 { 1767 {
1776 LOG (llevError, "Object %s lacks a spell\n", &item->name); 1768 LOG (llevError, "Object %s lacks a spell\n", &item->name);
1777 return; 1769 return;
1778 } 1770 }
1779 1771
1780 op->set_weapon (item); 1772 if (!op->change_weapon (item))
1773 return;
1781 1774
1782 if (item->type == WAND) 1775 if (item->type == WAND)
1783 { 1776 {
1784 if (item->stats.food <= 0) 1777 if (item->stats.food <= 0)
1785 { 1778 {
2174 * that party_number -1 is no party, so attacks can still happen. 2167 * that party_number -1 is no party, so attacks can still happen.
2175 */ 2168 */
2176 else if ((mon->stats.hp >= 0) && QUERY_FLAG (mon, FLAG_ALIVE) && 2169 else if ((mon->stats.hp >= 0) && QUERY_FLAG (mon, FLAG_ALIVE) &&
2177 ((mon->type != PLAYER || op->contr->party == NULL || op->contr->party != mon->contr->party))) 2170 ((mon->type != PLAYER || op->contr->party == NULL || op->contr->party != mon->contr->party)))
2178 { 2171 {
2179
2180 /* If the player hasn't hit something this tick, and does
2181 * so, give them speed boost based on weapon speed. Doing
2182 * it here is better than process_players2, which basically
2183 * incurred a 1 tick offset.
2184 */
2185 if (!op->contr->has_hit) 2172 op->contr->has_hit = 1;
2186 {
2187 op->speed_left += op->speed / op->contr->weapon_sp;
2188
2189 op->contr->has_hit = 1; /* The last action was to hit, so use weapon_sp */
2190 }
2191 2173
2192 skill_attack (mon, op, 0, 0, 0); 2174 skill_attack (mon, op, 0, 0, 0);
2193 2175
2194 /* If attacking another player, that player gets automatic 2176 /* If attacking another player, that player gets automatic
2195 * hitback, and doesn't loose luck either. 2177 * hitback, and doesn't loose luck either.
2272handle_newcs_player (object *op) 2254handle_newcs_player (object *op)
2273{ 2255{
2274 if (QUERY_FLAG (op, FLAG_SCARED)) 2256 if (QUERY_FLAG (op, FLAG_SCARED))
2275 { 2257 {
2276 flee_player (op); 2258 flee_player (op);
2259
2277 /* If player is still scared, that is his action for this tick */ 2260 /* If player is still scared, that is his action for this tick */
2278 if (QUERY_FLAG (op, FLAG_SCARED)) 2261 if (op->flag [FLAG_SCARED])
2279 { 2262 {
2280 op->speed_left--; 2263 --op->speed_left;
2281 return 0; 2264 return 0;
2282 } 2265 }
2283 } 2266 }
2284 2267
2285 /* call this here - we also will call this in do_ericserver, but 2268 /* call this here - we also will call this in do_ericserver, but
2287 * called, so we recheck it here. 2270 * called, so we recheck it here.
2288 */ 2271 */
2289 if (op->contr->ns->handle_command ()) 2272 if (op->contr->ns->handle_command ())
2290 return 1; 2273 return 1;
2291 2274
2292 if (op->speed_left > 0) 2275 if (op->speed_left > 0.f)
2293 { 2276 {
2294 if (op->direction && (op->contr->run_on || op->contr->fire_on)) 2277 if (op->direction && (op->contr->run_on || op->contr->fire_on))
2295 { 2278 {
2296 /* All move commands take 1 tick, at least for now */ 2279 /* All move commands take 1 tick, at least for now */
2297 op->speed_left--; 2280 --op->speed_left;
2298 2281
2299 /* Instead of all the stuff below, let move_player take care 2282 /* Instead of all the stuff below, let move_player take care
2300 * of it. Also, some of the skill stuff is only put in 2283 * of it. Also, some of the skill stuff is only put in
2301 * there, as well as the confusion stuff. 2284 * there, as well as the confusion stuff.
2302 */ 2285 */
2303 move_player (op, op->direction); 2286 move_player (op, op->direction);
2304 2287
2305 return op->speed_left > 0; 2288 return op->speed_left > 0.f;
2306 } 2289 }
2307 } 2290 }
2308 2291
2309 return 0; 2292 return 0;
2310} 2293}
2940 object *force; 2923 object *force;
2941 int at; 2924 int at;
2942 2925
2943 force = get_archetype (FORCE_NAME); 2926 force = get_archetype (FORCE_NAME);
2944 /* 50 ticks should be enough time for the spell to abate */ 2927 /* 50 ticks should be enough time for the spell to abate */
2945 force->speed = 0.1; 2928 force->speed = 0.1f;
2946 force->speed_left = -5.0; 2929 force->speed_left = -5.f;
2947 SET_FLAG (force, FLAG_APPLIED); 2930 SET_FLAG (force, FLAG_APPLIED);
2948 for (at = 0; at < NROFATTACKS; at++) 2931 for (at = 0; at < NROFATTACKS; at++)
2949 if (will_kill_again & (1 << at)) 2932 if (will_kill_again & (1 << at))
2950 force->resist[at] = 100; 2933 force->resist[at] = 100;
2951 2934

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines