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.127 by root, Sat May 12 18:14:48 2007 UTC vs.
Revision 1.136 by root, Wed May 16 11:10:01 2007 UTC

147 draw_ext_info_format (NDI_UNIQUE | NDI_GREEN, 0, op, 147 draw_ext_info_format (NDI_UNIQUE | NDI_GREEN, 0, op,
148 MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_NEWS, "INFORMATION: %s\n%s\n", (char *)"%s\n%s", subject, news); 148 MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_NEWS, "INFORMATION: %s\n%s\n", (char *)"%s\n%s", subject, news);
149 close_and_delete (fp, comp); 149 close_and_delete (fp, comp);
150} 150}
151 151
152float
153player::weapon_speed () const
154{
155 return ob->speed / weapon_sp * .5f;//TODO, the .5 is arbitrary
156}
157
152/* This loads the first map an puts the player on it. */ 158/* This loads the first map an puts the player on it. */
153static void 159static void
154set_first_map (object *op) 160set_first_map (object *op)
155{ 161{
156 op->contr->maplevel = first_map_path; 162 op->contr->maplevel = first_map_path;
319player::set_object (object *op) 325player::set_object (object *op)
320{ 326{
321 ob = op; 327 ob = op;
322 ob->contr = this; /* this aren't yet in archetype */ 328 ob->contr = this; /* this aren't yet in archetype */
323 329
324 ob->speed_left = 0.5; 330 ob->speed_left = 0.5f;
325 ob->speed = 1.0; 331 ob->speed = 1.0f;
326 ob->direction = 5; /* So player faces south */ 332 ob->direction = 5; /* So player faces south */
327} 333}
328 334
329player::player () 335player::player ()
330{ 336{
784} 790}
785 791
786void 792void
787object::roll_stats () 793object::roll_stats ()
788{ 794{
789 int statsort [7]; 795 int statsort [NUM_STATS];
790 796
791 for (;;) 797 for (;;)
792 { 798 {
793 int sum = 0; 799 int sum = 0;
794 for (int i = 7; i--; ) 800 for (int i = NUM_STATS; i--; )
795 sum += statsort [i] = roll_stat (); 801 sum += statsort [i] = roll_stat ();
796 802
797 if (sum >= 82 && sum <= 116) 803 if (sum >= 82 && sum <= 116)
798 break; 804 break;
799 } 805 }
800 806
801 // Sort the stats so that rerolling is easier... 807 // Sort the stats so that rerolling is easier...
802 std::sort (statsort, statsort + 7, std::greater<int>()); 808 std::sort (statsort, statsort + NUM_STATS, std::greater<int>());
803 809
810 for (int i = 0; i < NUM_STATS; ++i)
804 stats.Str = statsort[0]; 811 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 812
812 stats.exp = 0; 813 stats.exp = 0;
813 stats.ac = 0; 814 stats.ac = 0;
814 815
815 stats.hp = stats.maxhp; 816 stats.hp = stats.maxhp;
1540 */ 1541 */
1541int 1542int
1542fire_bow (object *op, object *part, object *arrow, int dir, int wc_mod, sint16 sx, sint16 sy) 1543fire_bow (object *op, object *part, object *arrow, int dir, int wc_mod, sint16 sx, sint16 sy)
1543{ 1544{
1544 object *left, *bow; 1545 object *left, *bow;
1545 int bowspeed, mflags; 1546 int mflags;
1546 maptile *m; 1547 maptile *m;
1547 1548
1548 if (!dir) 1549 if (!dir)
1549 { 1550 {
1550 new_draw_info (NDI_UNIQUE, 0, op, "You can't shoot yourself!"); 1551 new_draw_info (NDI_UNIQUE, 0, op, "You can't shoot yourself!");
1551 return 0; 1552 return 0;
1552 } 1553 }
1553 1554
1554 if (player *pl = op->contr) 1555 if (op->contr)
1555 { 1556 bow = op->current_weapon;
1556 bow = pl->ranged_ob;
1557 if (!op->change_weapon (bow))
1558 return 0;
1559 }
1560 else 1557 else
1561 { 1558 {
1562 for (bow = op->inv; bow; bow = bow->below) 1559 for (bow = op->inv; bow; bow = bow->below)
1563 /* Don't check for applied - monsters don't apply bows - in that way, they 1560 /* Don't check for applied - monsters don't apply bows - in that way, they
1564 * don't need to switch back and forth between bows and weapons. 1561 * don't need to switch back and forth between bows and weapons.
1585 { 1582 {
1586 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s is broken.", &bow->name); 1583 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s is broken.", &bow->name);
1587 return 0; 1584 return 0;
1588 } 1585 }
1589 1586
1590 bowspeed = bow->stats.sp + dex_bonus[op->stats.Dex];
1591
1592 /* penalize ROF for bestarrow */
1593 if (op->type == PLAYER && op->contr->bowtype == bow_bestarrow)
1594 bowspeed -= dex_bonus[op->stats.Dex] + 5;
1595
1596 if (bowspeed < 1)
1597 bowspeed = 1;
1598
1599 if (arrow == NULL) 1587 if (arrow == NULL)
1600 { 1588 {
1601 if ((arrow = find_arrow (op, bow->race)) == NULL) 1589 if ((arrow = find_arrow (op, bow->race)) == NULL)
1602 { 1590 {
1603 if (op->type == PLAYER) 1591 if (op->type == PLAYER)
1644 arrow->stats.grace = arrow->attacktype; 1632 arrow->stats.grace = arrow->attacktype;
1645 1633
1646 if (arrow->slaying) 1634 if (arrow->slaying)
1647 arrow->spellarg = strdup (arrow->slaying); 1635 arrow->spellarg = strdup (arrow->slaying);
1648 1636
1649 if (op->type == PLAYER) 1637 if (player *pl = op->contr)
1650 { 1638 {
1651 op->speed_left = 0.01 - (float) FABS (op->speed) * 100 / bowspeed; 1639 if (!pl->has_hit)
1652 op->update_stats (); 1640 {
1641 pl->has_hit = 1;
1642 pl->ob->speed_left += pl->weapon_speed () - pl->ob->speed;
1643 }
1644#if 0
1645 float speed = pl->weapon_sp;
1646
1647 /* penalize ROF for bestarrow */
1648 if (pl->bowtype == bow_bestarrow)
1649 speed *= .9f;
1650 else
1651 speed *= 1.f + dex_bonus[op->stats.Dex] * .2f;
1652
1653 op->speed_left += speed - op->speed;
1654#endif
1653 } 1655 }
1654 1656
1655 SET_ANIMATION (arrow, arrow->direction); 1657 SET_ANIMATION (arrow, arrow->direction);
1656
1657 arrow->stats.dam += op->stats.dam + arrow->magic;
1658 1658
1659 /* update the speed */ 1659 /* update the speed */
1660 arrow->speed = ((bow->flag [FLAG_NO_STRENGTH] ? 0 : dam_bonus[op->stats.Str]) + bow->magic + arrow->magic) / 5.0 1660 arrow->speed = ((bow->flag [FLAG_NO_STRENGTH] ? 0 : dam_bonus[op->stats.Str]) + bow->magic + arrow->magic) / 5.0
1661 + bow->stats.dam / 7.0; 1661 + bow->stats.dam / 7.0;
1662 1662
1663 arrow->set_speed (max (arrow->speed, 2.0)); 1663 arrow->set_speed (max (arrow->speed, 2.0));
1664 arrow->speed_left = 0; 1664 arrow->speed_left = 0;
1665 1665
1666 arrow->stats.wc = op->stats.wc + wc_mod - arrow->magic - arrow->stats.wc; 1666 int wc = op->stats.wc + wc_mod - arrow->magic - arrow->stats.wc;
1667 1667
1668 if (op->type == PLAYER) 1668 if (op->type == PLAYER)
1669 { 1669 {
1670 arrow->level = op->chosen_skill ? op->chosen_skill->level : op->level; 1670 arrow->level = op->chosen_skill ? op->chosen_skill->level : op->level;
1671 arrow->stats.wc -= dex_bonus[op->stats.Dex]; 1671 wc -= dex_bonus[op->stats.Dex];
1672 1672
1673 if (!arrow->slaying) 1673 if (!arrow->slaying)
1674 arrow->slaying = op->slaying; 1674 arrow->slaying = op->slaying;
1675 1675
1676 arrow->attacktype |= op->attacktype; 1676 arrow->attacktype |= op->attacktype;
1684 arrow->slaying = bow->slaying; 1684 arrow->slaying = bow->slaying;
1685 1685
1686 arrow->attacktype |= bow->attacktype; 1686 arrow->attacktype |= bow->attacktype;
1687 } 1687 }
1688 1688
1689 arrow->stats.wc -= arrow->level; 1689 wc -= arrow->level;
1690 arrow->stats.dam = clamp (arrow->stats.dam + op->stats.dam + arrow->magic, MIN_DAM, MAX_DAM);
1690 1691
1692 arrow->stats.wc = clamp (wc, MIN_WC, MAX_WC);
1691 arrow->move_type = MOVE_FLY_LOW; 1693 arrow->move_type = MOVE_FLY_LOW;
1692 arrow->move_on = MOVE_FLY_LOW | MOVE_WALK; 1694 arrow->move_on = MOVE_FLY_LOW | MOVE_WALK;
1693 1695
1694 play_sound_map (op->map, op->x, op->y, SOUND_FIRE_ARROW); 1696 play_sound_map (op->map, op->x, op->y, SOUND_FIRE_ARROW);
1695 m->insert (arrow, sx, sy, op); 1697 m->insert (arrow, sx, sy, op);
1750 } 1752 }
1751 1753
1752 return ret; 1754 return ret;
1753} 1755}
1754 1756
1755
1756/* Fires a misc (wand/rod/horn) object in 'dir'. 1757/* Fires a misc (wand/rod/horn) object in 'dir'.
1757 * Broken apart from 'fire' to keep it more readable. 1758 * Broken apart from 'fire' to keep it more readable.
1758 */ 1759 */
1759void 1760void
1760fire_misc_object (object *op, int dir) 1761fire_misc_object (object *op, int dir)
1848 object *ob = pl->ranged_ob; 1849 object *ob = pl->ranged_ob;
1849 1850
1850 if (!ob) 1851 if (!ob)
1851 return; 1852 return;
1852 1853
1854 if (!op->change_weapon (ob))
1855 return;
1856
1853 switch (ob->type) 1857 switch (ob->type)
1854 { 1858 {
1855 case BOW: 1859 case BOW:
1856 player_fire_bow (op, dir); 1860 player_fire_bow (op, dir);
1857 break; 1861 break;
1863 case BUILDER: 1867 case BUILDER:
1864 apply_map_builder (op, dir); 1868 apply_map_builder (op, dir);
1865 break; 1869 break;
1866 1870
1867 case SKILL: 1871 case SKILL:
1868 case SKILL_TOOL:
1869 do_skill (op, op, ob, dir, 0); 1872 do_skill (op, op, ob, dir, 0);
1870 break; 1873 break;
1871 1874
1872 default: 1875 default:
1873 fire_misc_object (op, dir); 1876 fire_misc_object (op, dir);
2171 * that party_number -1 is no party, so attacks can still happen. 2174 * that party_number -1 is no party, so attacks can still happen.
2172 */ 2175 */
2173 else if ((mon->stats.hp >= 0) && QUERY_FLAG (mon, FLAG_ALIVE) && 2176 else if ((mon->stats.hp >= 0) && QUERY_FLAG (mon, FLAG_ALIVE) &&
2174 ((mon->type != PLAYER || op->contr->party == NULL || op->contr->party != mon->contr->party))) 2177 ((mon->type != PLAYER || op->contr->party == NULL || op->contr->party != mon->contr->party)))
2175 { 2178 {
2176
2177 /* If the player hasn't hit something this tick, and does
2178 * so, give them speed boost based on weapon speed. Doing
2179 * it here is better than process_players2, which basically
2180 * incurred a 1 tick offset.
2181 */
2182 if (!op->contr->has_hit) 2179 if (!op->contr->has_hit)
2183 { 2180 {
2181 op->contr->has_hit = 1;
2184 op->speed_left += op->speed / op->contr->weapon_sp; 2182 op->speed_left += op->contr->weapon_speed () - op->speed;
2185
2186 op->contr->has_hit = 1; /* The last action was to hit, so use weapon_sp */
2187 } 2183 }
2188 2184
2189 skill_attack (mon, op, 0, 0, 0); 2185 skill_attack (mon, op, 0, 0, 0);
2190 2186
2191 /* If attacking another player, that player gets automatic 2187 /* If attacking another player, that player gets automatic
2269handle_newcs_player (object *op) 2265handle_newcs_player (object *op)
2270{ 2266{
2271 if (QUERY_FLAG (op, FLAG_SCARED)) 2267 if (QUERY_FLAG (op, FLAG_SCARED))
2272 { 2268 {
2273 flee_player (op); 2269 flee_player (op);
2270
2274 /* If player is still scared, that is his action for this tick */ 2271 /* If player is still scared, that is his action for this tick */
2275 if (QUERY_FLAG (op, FLAG_SCARED)) 2272 if (op->flag [FLAG_SCARED])
2276 { 2273 {
2277 op->speed_left--; 2274 --op->speed_left;
2278 return 0; 2275 return 0;
2279 } 2276 }
2280 } 2277 }
2281 2278
2282 /* call this here - we also will call this in do_ericserver, but 2279 /* call this here - we also will call this in do_ericserver, but
2284 * called, so we recheck it here. 2281 * called, so we recheck it here.
2285 */ 2282 */
2286 if (op->contr->ns->handle_command ()) 2283 if (op->contr->ns->handle_command ())
2287 return 1; 2284 return 1;
2288 2285
2289 if (op->speed_left > 0) 2286 if (op->speed_left > 0.f)
2290 { 2287 {
2291 if (op->direction && (op->contr->run_on || op->contr->fire_on)) 2288 if (op->direction && (op->contr->run_on || op->contr->fire_on))
2292 { 2289 {
2293 /* All move commands take 1 tick, at least for now */ 2290 /* All move commands take 1 tick, at least for now */
2294 op->speed_left--; 2291 --op->speed_left;
2295 2292
2296 /* Instead of all the stuff below, let move_player take care 2293 /* Instead of all the stuff below, let move_player take care
2297 * of it. Also, some of the skill stuff is only put in 2294 * of it. Also, some of the skill stuff is only put in
2298 * there, as well as the confusion stuff. 2295 * there, as well as the confusion stuff.
2299 */ 2296 */
2300 move_player (op, op->direction); 2297 move_player (op, op->direction);
2301 2298
2302 return op->speed_left > 0; 2299 return op->speed_left > 0.f;
2303 } 2300 }
2304 } 2301 }
2305 2302
2306 return 0; 2303 return 0;
2307} 2304}
2937 object *force; 2934 object *force;
2938 int at; 2935 int at;
2939 2936
2940 force = get_archetype (FORCE_NAME); 2937 force = get_archetype (FORCE_NAME);
2941 /* 50 ticks should be enough time for the spell to abate */ 2938 /* 50 ticks should be enough time for the spell to abate */
2942 force->speed = 0.1; 2939 force->speed = 0.1f;
2943 force->speed_left = -5.0; 2940 force->speed_left = -5.f;
2944 SET_FLAG (force, FLAG_APPLIED); 2941 SET_FLAG (force, FLAG_APPLIED);
2945 for (at = 0; at < NROFATTACKS; at++) 2942 for (at = 0; at < NROFATTACKS; at++)
2946 if (will_kill_again & (1 << at)) 2943 if (will_kill_again & (1 << at))
2947 force->resist[at] = 100; 2944 force->resist[at] = 100;
2948 2945

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines