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.126 by root, Sat May 12 16:06:42 2007 UTC vs.
Revision 1.137 by root, Thu May 17 14:14:55 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;
827} 828}
828 829
829void 830void
830object::swap_stats (int a, int b) 831object::swap_stats (int a, int b)
831{ 832{
832 int tmp = get_attr_value (&contr->orig_stats, a); 833 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 834
835 for (int i = 0; i < NUM_STATS; ++i)
836 stats.Str = contr->orig_stats.Str; 836 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 837
844 //TODO: the following code looks so borked and should, at the very least, 838 //TODO: the following code looks so borked and should, at the very least,
845 // be merged with the similar code in roll_stats 839 // be merged with the similar code in roll_stats
846 stats.ac = 0; 840 stats.ac = 0;
847 841
1547 */ 1541 */
1548int 1542int
1549fire_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)
1550{ 1544{
1551 object *left, *bow; 1545 object *left, *bow;
1552 int bowspeed, mflags; 1546 int mflags;
1553 maptile *m; 1547 maptile *m;
1554 1548
1555 if (!dir) 1549 if (!dir)
1556 { 1550 {
1557 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!");
1558 return 0; 1552 return 0;
1559 } 1553 }
1560 1554
1561 if (player *pl = op->contr) 1555 if (op->contr)
1562 { 1556 bow = op->current_weapon;
1563 bow = pl->ranged_ob;
1564 if (!op->change_weapon (bow))
1565 return 0;
1566 }
1567 else 1557 else
1568 { 1558 {
1569 for (bow = op->inv; bow; bow = bow->below) 1559 for (bow = op->inv; bow; bow = bow->below)
1570 /* 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
1571 * 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.
1592 { 1582 {
1593 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);
1594 return 0; 1584 return 0;
1595 } 1585 }
1596 1586
1597 bowspeed = bow->stats.sp + dex_bonus[op->stats.Dex];
1598
1599 /* penalize ROF for bestarrow */
1600 if (op->type == PLAYER && op->contr->bowtype == bow_bestarrow)
1601 bowspeed -= dex_bonus[op->stats.Dex] + 5;
1602
1603 if (bowspeed < 1)
1604 bowspeed = 1;
1605
1606 if (arrow == NULL) 1587 if (arrow == NULL)
1607 { 1588 {
1608 if ((arrow = find_arrow (op, bow->race)) == NULL) 1589 if ((arrow = find_arrow (op, bow->race)) == NULL)
1609 { 1590 {
1610 if (op->type == PLAYER) 1591 if (op->type == PLAYER)
1651 arrow->stats.grace = arrow->attacktype; 1632 arrow->stats.grace = arrow->attacktype;
1652 1633
1653 if (arrow->slaying) 1634 if (arrow->slaying)
1654 arrow->spellarg = strdup (arrow->slaying); 1635 arrow->spellarg = strdup (arrow->slaying);
1655 1636
1656 if (op->type == PLAYER) 1637 if (player *pl = op->contr)
1657 { 1638 {
1658 op->speed_left = 0.01 - (float) FABS (op->speed) * 100 / bowspeed; 1639 if (!pl->has_hit)
1659 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
1660 } 1655 }
1661 1656
1662 SET_ANIMATION (arrow, arrow->direction); 1657 SET_ANIMATION (arrow, arrow->direction);
1663
1664 arrow->stats.dam += op->stats.dam + arrow->magic;
1665 1658
1666 /* update the speed */ 1659 /* update the speed */
1667 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
1668 + bow->stats.dam / 7.0; 1661 + bow->stats.dam / 7.0;
1669 1662
1670 arrow->set_speed (max (arrow->speed, 2.0)); 1663 arrow->set_speed (max (arrow->speed, 2.0));
1671 arrow->speed_left = 0; 1664 arrow->speed_left = 0;
1672 1665
1673 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;
1674 1667
1675 if (op->type == PLAYER) 1668 if (op->type == PLAYER)
1676 { 1669 {
1677 arrow->level = op->chosen_skill ? op->chosen_skill->level : op->level; 1670 arrow->level = op->chosen_skill ? op->chosen_skill->level : op->level;
1678 arrow->stats.wc -= dex_bonus[op->stats.Dex]; 1671 wc -= dex_bonus[op->stats.Dex];
1679 1672
1680 if (!arrow->slaying) 1673 if (!arrow->slaying)
1681 arrow->slaying = op->slaying; 1674 arrow->slaying = op->slaying;
1682 1675
1683 arrow->attacktype |= op->attacktype; 1676 arrow->attacktype |= op->attacktype;
1691 arrow->slaying = bow->slaying; 1684 arrow->slaying = bow->slaying;
1692 1685
1693 arrow->attacktype |= bow->attacktype; 1686 arrow->attacktype |= bow->attacktype;
1694 } 1687 }
1695 1688
1696 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);
1697 1691
1692 arrow->stats.wc = clamp (wc, MIN_WC, MAX_WC);
1698 arrow->move_type = MOVE_FLY_LOW; 1693 arrow->move_type = MOVE_FLY_LOW;
1699 arrow->move_on = MOVE_FLY_LOW | MOVE_WALK; 1694 arrow->move_on = MOVE_FLY_LOW | MOVE_WALK;
1700 1695
1701 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);
1702 m->insert (arrow, sx, sy, op); 1697 m->insert (arrow, sx, sy, op);
1757 } 1752 }
1758 1753
1759 return ret; 1754 return ret;
1760} 1755}
1761 1756
1762
1763/* Fires a misc (wand/rod/horn) object in 'dir'. 1757/* Fires a misc (wand/rod/horn) object in 'dir'.
1764 * Broken apart from 'fire' to keep it more readable. 1758 * Broken apart from 'fire' to keep it more readable.
1765 */ 1759 */
1766void 1760void
1767fire_misc_object (object *op, int dir) 1761fire_misc_object (object *op, int dir)
1855 object *ob = pl->ranged_ob; 1849 object *ob = pl->ranged_ob;
1856 1850
1857 if (!ob) 1851 if (!ob)
1858 return; 1852 return;
1859 1853
1854 if (!op->change_weapon (ob))
1855 return;
1856
1860 switch (ob->type) 1857 switch (ob->type)
1861 { 1858 {
1862 case BOW: 1859 case BOW:
1863 player_fire_bow (op, dir); 1860 player_fire_bow (op, dir);
1864 break; 1861 break;
1870 case BUILDER: 1867 case BUILDER:
1871 apply_map_builder (op, dir); 1868 apply_map_builder (op, dir);
1872 break; 1869 break;
1873 1870
1874 case SKILL: 1871 case SKILL:
1875 case SKILL_TOOL:
1876 do_skill (op, op, ob, dir, 0); 1872 do_skill (op, op, ob, dir, 0);
1877 break; 1873 break;
1878 1874
1879 default: 1875 default:
1880 fire_misc_object (op, dir); 1876 fire_misc_object (op, dir);
2108 2104
2109 /* If the creature is a pet, push it even if the player is not 2105 /* If the creature is a pet, push it even if the player is not
2110 * peaceful. Our assumption is the creature is a pet if the 2106 * peaceful. Our assumption is the creature is a pet if the
2111 * player owns it and it is either friendly or unagressive. 2107 * player owns it and it is either friendly or unagressive.
2112 */ 2108 */
2113 if ((op->type == PLAYER) 2109 if (op->type == PLAYER
2114#if COZY_SERVER
2115 &&
2116 ((mon->owner && mon->owner->contr 2110 && ((mon->owner && mon->owner->contr
2117 && same_party (mon->owner->contr->party, op->contr->party)) || mon->owner == op) 2111 && same_party (mon->owner->contr->party, op->contr->party))
2118#else
2119 && mon->owner == op 2112 || mon->owner == op)
2120#endif
2121 && (QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY))) 2113 && (QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY)))
2122 { 2114 {
2123 /* If we're braced, we don't want to switch places with it */ 2115 /* If we're braced, we don't want to switch places with it */
2124 if (op->contr->braced) 2116 if (op->contr->braced)
2125 return; 2117 return;
2135 /* in certain circumstances, you shouldn't attack friendly 2127 /* in certain circumstances, you shouldn't attack friendly
2136 * creatures. Note that if you are braced, you can't push 2128 * creatures. Note that if you are braced, you can't push
2137 * someone, but put it inside this loop so that you won't 2129 * someone, but put it inside this loop so that you won't
2138 * attack them either. 2130 * attack them either.
2139 */ 2131 */
2140 if ((mon->type == PLAYER || mon->enemy != op) && 2132 if ((mon->type == PLAYER || mon->enemy != op)
2141 (mon->type == PLAYER || QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY)) && ( 2133 && (mon->type == PLAYER || QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY))
2142#ifdef PROHIBIT_PLAYERKILL
2143 (op->contr->peaceful 2134 && ((op->contr->peaceful
2144 || (mon->type == PLAYER 2135 || (mon->type == PLAYER && mon->contr->peaceful))
2145 && mon->contr->
2146 peaceful)) &&
2147#else
2148 op->contr->peaceful &&
2149#endif
2150 !on_battleground)) 2136 && !on_battleground))
2151 { 2137 {
2152 if (!op->contr->braced) 2138 if (!op->contr->braced)
2153 { 2139 {
2154 play_sound_map (op->map, op->x, op->y, SOUND_PUSH_PLAYER); 2140 play_sound_map (op->map, op->x, op->y, SOUND_PUSH_PLAYER);
2155 push_ob (mon, dir, op); 2141 push_ob (mon, dir, op);
2178 * that party_number -1 is no party, so attacks can still happen. 2164 * that party_number -1 is no party, so attacks can still happen.
2179 */ 2165 */
2180 else if ((mon->stats.hp >= 0) && QUERY_FLAG (mon, FLAG_ALIVE) && 2166 else if ((mon->stats.hp >= 0) && QUERY_FLAG (mon, FLAG_ALIVE) &&
2181 ((mon->type != PLAYER || op->contr->party == NULL || op->contr->party != mon->contr->party))) 2167 ((mon->type != PLAYER || op->contr->party == NULL || op->contr->party != mon->contr->party)))
2182 { 2168 {
2183
2184 /* If the player hasn't hit something this tick, and does
2185 * so, give them speed boost based on weapon speed. Doing
2186 * it here is better than process_players2, which basically
2187 * incurred a 1 tick offset.
2188 */
2189 if (!op->contr->has_hit) 2169 if (!op->contr->has_hit)
2190 { 2170 {
2171 op->contr->has_hit = 1;
2191 op->speed_left += op->speed / op->contr->weapon_sp; 2172 op->speed_left += op->contr->weapon_speed () - op->speed;
2192
2193 op->contr->has_hit = 1; /* The last action was to hit, so use weapon_sp */
2194 } 2173 }
2195 2174
2196 skill_attack (mon, op, 0, 0, 0); 2175 skill_attack (mon, op, 0, 0, 0);
2197 2176
2198 /* If attacking another player, that player gets automatic 2177 /* If attacking another player, that player gets automatic
2276handle_newcs_player (object *op) 2255handle_newcs_player (object *op)
2277{ 2256{
2278 if (QUERY_FLAG (op, FLAG_SCARED)) 2257 if (QUERY_FLAG (op, FLAG_SCARED))
2279 { 2258 {
2280 flee_player (op); 2259 flee_player (op);
2260
2281 /* If player is still scared, that is his action for this tick */ 2261 /* If player is still scared, that is his action for this tick */
2282 if (QUERY_FLAG (op, FLAG_SCARED)) 2262 if (op->flag [FLAG_SCARED])
2283 { 2263 {
2284 op->speed_left--; 2264 --op->speed_left;
2285 return 0; 2265 return 0;
2286 } 2266 }
2287 } 2267 }
2288 2268
2289 /* call this here - we also will call this in do_ericserver, but 2269 /* call this here - we also will call this in do_ericserver, but
2291 * called, so we recheck it here. 2271 * called, so we recheck it here.
2292 */ 2272 */
2293 if (op->contr->ns->handle_command ()) 2273 if (op->contr->ns->handle_command ())
2294 return 1; 2274 return 1;
2295 2275
2296 if (op->speed_left > 0) 2276 if (op->speed_left > 0.f)
2297 { 2277 {
2298 if (op->direction && (op->contr->run_on || op->contr->fire_on)) 2278 if (op->direction && (op->contr->run_on || op->contr->fire_on))
2299 { 2279 {
2300 /* All move commands take 1 tick, at least for now */ 2280 /* All move commands take 1 tick, at least for now */
2301 op->speed_left--; 2281 --op->speed_left;
2302 2282
2303 /* Instead of all the stuff below, let move_player take care 2283 /* Instead of all the stuff below, let move_player take care
2304 * of it. Also, some of the skill stuff is only put in 2284 * of it. Also, some of the skill stuff is only put in
2305 * there, as well as the confusion stuff. 2285 * there, as well as the confusion stuff.
2306 */ 2286 */
2307 move_player (op, op->direction); 2287 move_player (op, op->direction);
2308 2288
2309 return op->speed_left > 0; 2289 return op->speed_left > 0.f;
2310 } 2290 }
2311 } 2291 }
2312 2292
2313 return 0; 2293 return 0;
2314} 2294}
2584 } 2564 }
2585 2565
2586 /* Digestion */ 2566 /* Digestion */
2587 if (--op->last_eat < 0) 2567 if (--op->last_eat < 0)
2588 { 2568 {
2589#ifdef COZY_SERVER
2590 int dg = op->contr->digestion >= 0 && op->contr->digestion < 2 ? 2 : op->contr->digestion;
2591 int bonus = dg > 0 ? dg : 0, penalty = dg < 0 ? -dg : 0;
2592#else
2593 int bonus = op->contr->digestion > 0 ? op->contr->digestion : 0, penalty = op->contr->digestion < 0 ? -op->contr->digestion : 0; 2569 int bonus = op->contr->digestion > 0 ? op->contr->digestion : 0, penalty = op->contr->digestion < 0 ? -op->contr->digestion : 0;
2594#endif
2595 2570
2596 if (op->contr->gen_hp > 0) 2571 if (op->contr->gen_hp > 0)
2597 op->last_eat = 25 * (1 + bonus) / (op->contr->gen_hp + penalty + 1); 2572 op->last_eat = 25 * (1 + bonus) / (op->contr->gen_hp + penalty + 1);
2598 else 2573 else
2599 op->last_eat = 25 * (1 + bonus) / (penalty + 1); 2574 op->last_eat = 25 * (1 + bonus) / (penalty + 1);
2944 object *force; 2919 object *force;
2945 int at; 2920 int at;
2946 2921
2947 force = get_archetype (FORCE_NAME); 2922 force = get_archetype (FORCE_NAME);
2948 /* 50 ticks should be enough time for the spell to abate */ 2923 /* 50 ticks should be enough time for the spell to abate */
2949 force->speed = 0.1; 2924 force->speed = 0.1f;
2950 force->speed_left = -5.0; 2925 force->speed_left = -5.f;
2951 SET_FLAG (force, FLAG_APPLIED); 2926 SET_FLAG (force, FLAG_APPLIED);
2952 for (at = 0; at < NROFATTACKS; at++) 2927 for (at = 0; at < NROFATTACKS; at++)
2953 if (will_kill_again & (1 << at)) 2928 if (will_kill_again & (1 << at))
2954 force->resist[at] = 100; 2929 force->resist[at] = 100;
2955 2930

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines