… | |
… | |
258 | |
258 | |
259 | new_draw_info (NDI_UNIQUE, 0, ob, "Welcome Back!"); |
259 | new_draw_info (NDI_UNIQUE, 0, ob, "Welcome Back!"); |
260 | |
260 | |
261 | esrv_new_player (this, ob->weight + ob->carrying); |
261 | esrv_new_player (this, ob->weight + ob->carrying); |
262 | |
262 | |
|
|
263 | ob->flag [FLAG_READY_WEAPON] = false; |
|
|
264 | ob->flag [FLAG_READY_SKILL] = false; |
|
|
265 | ob->flag [FLAG_READY_BOW] = false; |
|
|
266 | |
263 | for (object *op = ob->inv; op; op = op->below) |
267 | for (object *op = ob->inv; op; op = op->below) |
264 | if (op->flag [FLAG_APPLIED]) |
268 | if (op->flag [FLAG_APPLIED]) |
265 | switch (op->type) |
269 | switch (op->type) |
266 | { |
270 | { |
|
|
271 | case SKILL: |
|
|
272 | ob->flag [FLAG_APPLIED] = false; |
|
|
273 | break; |
|
|
274 | |
267 | case WAND: |
275 | case WAND: |
268 | case ROD: |
276 | case ROD: |
269 | case HORN: |
277 | case HORN: |
270 | case BOW: |
278 | case BOW: |
271 | case SKILL: |
279 | ranged_ob = op; |
272 | case SKILL_TOOL: |
280 | break; |
|
|
281 | |
273 | case WEAPON: |
282 | case WEAPON: |
274 | apply_special (ob, op, AP_UNAPPLY); |
283 | combat_ob = op; |
275 | apply_special (ob, op, AP_APPLY); |
|
|
276 | break; |
284 | break; |
277 | } |
285 | } |
278 | |
286 | |
|
|
287 | ob->change_weapon (combat_ob ? combat_ob : ranged_ob); |
279 | ob->update_stats (); |
288 | ob->update_stats (); |
|
|
289 | |
280 | ns->floorbox_update (); |
290 | ns->floorbox_update (); |
281 | |
|
|
282 | esrv_send_inventory (ob, ob); |
291 | esrv_send_inventory (ob, ob); |
283 | esrv_add_spells (this, 0); |
292 | esrv_add_spells (this, 0); |
284 | |
293 | |
285 | activate (); |
294 | activate (); |
286 | |
295 | |
… | |
… | |
319 | player::set_object (object *op) |
328 | player::set_object (object *op) |
320 | { |
329 | { |
321 | ob = op; |
330 | ob = op; |
322 | ob->contr = this; /* this aren't yet in archetype */ |
331 | ob->contr = this; /* this aren't yet in archetype */ |
323 | |
332 | |
324 | ob->speed_left = 0.5; |
|
|
325 | ob->speed = 1.0; |
333 | ob->speed = 1.0f; |
|
|
334 | ob->speed_left = 0.5f; |
|
|
335 | |
326 | ob->direction = 5; /* So player faces south */ |
336 | ob->direction = 5; /* So player faces south */ |
327 | } |
337 | } |
328 | |
338 | |
329 | player::player () |
339 | player::player () |
330 | { |
340 | { |
331 | /* There are some elements we want initialised to non zero value - |
341 | /* There are some elements we want initialised to non zero value - |
… | |
… | |
342 | petmode = pet_normal; |
352 | petmode = pet_normal; |
343 | listening = 10; |
353 | listening = 10; |
344 | usekeys = containers; |
354 | usekeys = containers; |
345 | peaceful = 1; /* default peaceful */ |
355 | peaceful = 1; /* default peaceful */ |
346 | do_los = 1; |
356 | do_los = 1; |
|
|
357 | |
|
|
358 | weapon_sp = 1.0f; |
|
|
359 | weapon_sp_left = 0.5f; |
347 | } |
360 | } |
348 | |
361 | |
349 | void |
362 | void |
350 | player::do_destroy () |
363 | player::do_destroy () |
351 | { |
364 | { |
… | |
… | |
784 | } |
797 | } |
785 | |
798 | |
786 | void |
799 | void |
787 | object::roll_stats () |
800 | object::roll_stats () |
788 | { |
801 | { |
789 | int statsort [7]; |
802 | int statsort [NUM_STATS]; |
790 | |
803 | |
791 | for (;;) |
804 | for (;;) |
792 | { |
805 | { |
793 | int sum = 0; |
806 | int sum = 0; |
794 | for (int i = 7; i--; ) |
807 | for (int i = NUM_STATS; i--; ) |
795 | sum += statsort [i] = roll_stat (); |
808 | sum += statsort [i] = roll_stat (); |
796 | |
809 | |
797 | if (sum >= 82 && sum <= 116) |
810 | if (sum >= 82 && sum <= 116) |
798 | break; |
811 | break; |
799 | } |
812 | } |
800 | |
813 | |
801 | // Sort the stats so that rerolling is easier... |
814 | // Sort the stats so that rerolling is easier... |
802 | std::sort (statsort, statsort + 7, std::greater<int>()); |
815 | std::sort (statsort, statsort + NUM_STATS, std::greater<int>()); |
803 | |
816 | |
|
|
817 | for (int i = 0; i < NUM_STATS; ++i) |
804 | stats.Str = statsort[0]; |
818 | 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 | |
819 | |
812 | stats.exp = 0; |
820 | stats.exp = 0; |
813 | stats.ac = 0; |
821 | stats.ac = 0; |
814 | |
822 | |
815 | stats.hp = stats.maxhp; |
823 | stats.hp = stats.maxhp; |
… | |
… | |
827 | } |
835 | } |
828 | |
836 | |
829 | void |
837 | void |
830 | object::swap_stats (int a, int b) |
838 | object::swap_stats (int a, int b) |
831 | { |
839 | { |
832 | int tmp = get_attr_value (&contr->orig_stats, a); |
840 | 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 | |
841 | |
|
|
842 | for (int i = 0; i < NUM_STATS; ++i) |
836 | stats.Str = contr->orig_stats.Str; |
843 | 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 | |
844 | |
844 | //TODO: the following code looks so borked and should, at the very least, |
845 | //TODO: the following code looks so borked and should, at the very least, |
845 | // be merged with the similar code in roll_stats |
846 | // be merged with the similar code in roll_stats |
846 | stats.ac = 0; |
847 | stats.ac = 0; |
847 | |
848 | |
… | |
… | |
1547 | */ |
1548 | */ |
1548 | int |
1549 | int |
1549 | fire_bow (object *op, object *part, object *arrow, int dir, int wc_mod, sint16 sx, sint16 sy) |
1550 | fire_bow (object *op, object *part, object *arrow, int dir, int wc_mod, sint16 sx, sint16 sy) |
1550 | { |
1551 | { |
1551 | object *left, *bow; |
1552 | object *left, *bow; |
1552 | int bowspeed, mflags; |
1553 | int mflags; |
1553 | maptile *m; |
1554 | maptile *m; |
1554 | |
1555 | |
1555 | if (!dir) |
1556 | if (!dir) |
1556 | { |
1557 | { |
1557 | new_draw_info (NDI_UNIQUE, 0, op, "You can't shoot yourself!"); |
1558 | new_draw_info (NDI_UNIQUE, 0, op, "You can't shoot yourself!"); |
1558 | return 0; |
1559 | return 0; |
1559 | } |
1560 | } |
1560 | |
1561 | |
1561 | if (player *pl = op->contr) |
1562 | if (op->contr) |
1562 | { |
1563 | bow = op->current_weapon; |
1563 | bow = pl->ranged_ob; |
|
|
1564 | op->set_weapon (bow); |
|
|
1565 | } |
|
|
1566 | else |
1564 | else |
1567 | { |
1565 | { |
1568 | for (bow = op->inv; bow; bow = bow->below) |
1566 | for (bow = op->inv; bow; bow = bow->below) |
1569 | /* Don't check for applied - monsters don't apply bows - in that way, they |
1567 | /* Don't check for applied - monsters don't apply bows - in that way, they |
1570 | * don't need to switch back and forth between bows and weapons. |
1568 | * don't need to switch back and forth between bows and weapons. |
… | |
… | |
1591 | { |
1589 | { |
1592 | new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s is broken.", &bow->name); |
1590 | new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s is broken.", &bow->name); |
1593 | return 0; |
1591 | return 0; |
1594 | } |
1592 | } |
1595 | |
1593 | |
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) |
1594 | if (arrow == NULL) |
1606 | { |
1595 | { |
1607 | if ((arrow = find_arrow (op, bow->race)) == NULL) |
1596 | if ((arrow = find_arrow (op, bow->race)) == NULL) |
1608 | { |
1597 | { |
1609 | if (op->type == PLAYER) |
1598 | if (op->type == PLAYER) |
… | |
… | |
1650 | arrow->stats.grace = arrow->attacktype; |
1639 | arrow->stats.grace = arrow->attacktype; |
1651 | |
1640 | |
1652 | if (arrow->slaying) |
1641 | if (arrow->slaying) |
1653 | arrow->spellarg = strdup (arrow->slaying); |
1642 | arrow->spellarg = strdup (arrow->slaying); |
1654 | |
1643 | |
|
|
1644 | #if 0 |
|
|
1645 | if (player *pl = op->contr) |
|
|
1646 | { |
|
|
1647 | float speed = pl->weapon_sp; |
|
|
1648 | |
|
|
1649 | /* penalize ROF for bestarrow */ |
|
|
1650 | if (pl->bowtype == bow_bestarrow) |
|
|
1651 | speed *= .9f; |
|
|
1652 | else |
|
|
1653 | speed *= 1.f + dex_bonus[op->stats.Dex] * .2f; |
|
|
1654 | |
|
|
1655 | op->speed_left += speed - op->speed; |
|
|
1656 | } |
|
|
1657 | #endif |
|
|
1658 | |
|
|
1659 | SET_ANIMATION (arrow, arrow->direction); |
|
|
1660 | |
|
|
1661 | /* update the speed */ |
|
|
1662 | arrow->speed = ((bow->flag [FLAG_NO_STRENGTH] ? 0 : dam_bonus[op->stats.Str]) + bow->magic + arrow->magic) / 5.f |
|
|
1663 | + bow->stats.dam / 7.f; |
|
|
1664 | |
|
|
1665 | arrow->set_speed (max (arrow->speed, 2.f)); |
|
|
1666 | arrow->speed_left = 0; |
|
|
1667 | |
|
|
1668 | int wc = op->stats.wc + wc_mod - arrow->magic - arrow->stats.wc; |
|
|
1669 | |
1655 | if (op->type == PLAYER) |
1670 | if (op->type == PLAYER) |
1656 | { |
1671 | { |
1657 | op->speed_left = 0.01 - (float) FABS (op->speed) * 100 / bowspeed; |
|
|
1658 | op->update_stats (); |
|
|
1659 | } |
|
|
1660 | |
|
|
1661 | SET_ANIMATION (arrow, arrow->direction); |
|
|
1662 | |
|
|
1663 | arrow->stats.dam += op->stats.dam + arrow->magic; |
|
|
1664 | |
|
|
1665 | /* update the speed */ |
|
|
1666 | arrow->speed = (float) ((QUERY_FLAG (bow, FLAG_NO_STRENGTH) ? |
|
|
1667 | 0 : dam_bonus[op->stats.Str]) + bow->magic + arrow->magic) / 5.0 + (float) bow->stats.dam / 7.0; |
|
|
1668 | |
|
|
1669 | arrow->set_speed (max (arrow->speed, 1.0)); |
|
|
1670 | arrow->speed_left = 0; |
|
|
1671 | |
|
|
1672 | arrow->stats.wc = op->stats.wc + wc_mod - arrow->magic - arrow->stats.wc; |
|
|
1673 | |
|
|
1674 | if (op->type == PLAYER) |
|
|
1675 | { |
|
|
1676 | arrow->level = op->chosen_skill ? op->chosen_skill->level : op->level; |
1672 | arrow->level = op->chosen_skill ? op->chosen_skill->level : op->level; |
1677 | arrow->stats.wc -= dex_bonus[op->stats.Dex]; |
1673 | wc -= dex_bonus[op->stats.Dex]; |
1678 | |
1674 | |
1679 | if (!arrow->slaying) |
1675 | if (!arrow->slaying) |
1680 | arrow->slaying = op->slaying; |
1676 | arrow->slaying = op->slaying; |
1681 | |
1677 | |
1682 | arrow->attacktype |= op->attacktype; |
1678 | arrow->attacktype |= op->attacktype; |
… | |
… | |
1690 | arrow->slaying = bow->slaying; |
1686 | arrow->slaying = bow->slaying; |
1691 | |
1687 | |
1692 | arrow->attacktype |= bow->attacktype; |
1688 | arrow->attacktype |= bow->attacktype; |
1693 | } |
1689 | } |
1694 | |
1690 | |
1695 | arrow->stats.wc -= arrow->level; |
1691 | wc -= arrow->level; |
|
|
1692 | arrow->stats.dam = clamp (arrow->stats.dam + op->stats.dam + arrow->magic, MIN_DAM, MAX_DAM); |
1696 | |
1693 | |
|
|
1694 | arrow->stats.wc = clamp (wc, MIN_WC, MAX_WC); |
1697 | arrow->move_type = MOVE_FLY_LOW; |
1695 | arrow->move_type = MOVE_FLY_LOW; |
1698 | arrow->move_on = MOVE_FLY_LOW | MOVE_WALK; |
1696 | arrow->move_on = MOVE_FLY_LOW | MOVE_WALK; |
1699 | |
1697 | |
1700 | play_sound_map (op->map, op->x, op->y, SOUND_FIRE_ARROW); |
1698 | play_sound_map (op->map, op->x, op->y, SOUND_FIRE_ARROW); |
1701 | m->insert (arrow, sx, sy, op); |
1699 | m->insert (arrow, sx, sy, op); |
… | |
… | |
1756 | } |
1754 | } |
1757 | |
1755 | |
1758 | return ret; |
1756 | return ret; |
1759 | } |
1757 | } |
1760 | |
1758 | |
1761 | |
|
|
1762 | /* Fires a misc (wand/rod/horn) object in 'dir'. |
1759 | /* Fires a misc (wand/rod/horn) object in 'dir'. |
1763 | * Broken apart from 'fire' to keep it more readable. |
1760 | * Broken apart from 'fire' to keep it more readable. |
1764 | */ |
1761 | */ |
1765 | void |
1762 | void |
1766 | fire_misc_object (object *op, int dir) |
1763 | fire_misc_object (object *op, int dir) |
… | |
… | |
1777 | { |
1774 | { |
1778 | LOG (llevError, "Object %s lacks a spell\n", &item->name); |
1775 | LOG (llevError, "Object %s lacks a spell\n", &item->name); |
1779 | return; |
1776 | return; |
1780 | } |
1777 | } |
1781 | |
1778 | |
1782 | op->set_weapon (item); |
1779 | if (!op->change_weapon (item)) |
|
|
1780 | return; |
1783 | |
1781 | |
1784 | if (item->type == WAND) |
1782 | if (item->type == WAND) |
1785 | { |
1783 | { |
1786 | if (item->stats.food <= 0) |
1784 | if (item->stats.food <= 0) |
1787 | { |
1785 | { |
… | |
… | |
1831 | } |
1829 | } |
1832 | } |
1830 | } |
1833 | |
1831 | |
1834 | /* Received a fire command for the player - go and do it. |
1832 | /* Received a fire command for the player - go and do it. |
1835 | */ |
1833 | */ |
1836 | void |
1834 | bool |
1837 | fire (object *op, int dir) |
1835 | fire (object *op, int dir) |
1838 | { |
1836 | { |
1839 | int spellcost = 0; |
1837 | int spellcost = 0; |
1840 | |
1838 | |
1841 | /* check for loss of invisiblity/hide */ |
1839 | /* check for loss of invisiblity/hide */ |
… | |
… | |
1845 | player *pl = op->contr; |
1843 | player *pl = op->contr; |
1846 | |
1844 | |
1847 | if (pl->golem) |
1845 | if (pl->golem) |
1848 | { |
1846 | { |
1849 | control_golem (op->contr->golem, dir); |
1847 | control_golem (op->contr->golem, dir); |
1850 | return; |
1848 | return false; |
1851 | } |
1849 | } |
1852 | |
1850 | |
1853 | object *ob = pl->ranged_ob; |
1851 | object *ob = pl->ranged_ob; |
1854 | |
1852 | |
1855 | if (!ob) |
1853 | if (!ob) |
1856 | return; |
1854 | return false; |
|
|
1855 | |
|
|
1856 | if (!op->change_weapon (ob)) |
|
|
1857 | return false; |
|
|
1858 | |
|
|
1859 | if (op->speed_left > 0.f) |
|
|
1860 | --op->speed_left; |
|
|
1861 | else |
|
|
1862 | return false; |
1857 | |
1863 | |
1858 | switch (ob->type) |
1864 | switch (ob->type) |
1859 | { |
1865 | { |
1860 | case BOW: |
1866 | case BOW: |
1861 | player_fire_bow (op, dir); |
1867 | player_fire_bow (op, dir); |
… | |
… | |
1868 | case BUILDER: |
1874 | case BUILDER: |
1869 | apply_map_builder (op, dir); |
1875 | apply_map_builder (op, dir); |
1870 | break; |
1876 | break; |
1871 | |
1877 | |
1872 | case SKILL: |
1878 | case SKILL: |
1873 | case SKILL_TOOL: |
|
|
1874 | do_skill (op, op, ob, dir, 0); |
1879 | do_skill (op, op, ob, dir, 0); |
1875 | break; |
1880 | break; |
1876 | |
1881 | |
1877 | default: |
1882 | default: |
1878 | fire_misc_object (op, dir); |
1883 | fire_misc_object (op, dir); |
1879 | break; |
1884 | break; |
1880 | } |
1885 | } |
|
|
1886 | |
|
|
1887 | return true; |
1881 | } |
1888 | } |
1882 | |
1889 | |
1883 | /* find_key |
1890 | /* find_key |
1884 | * We try to find a key for the door as passed. If we find a key |
1891 | * We try to find a key for the door as passed. If we find a key |
1885 | * and successfully use it, we return the key, otherwise NULL |
1892 | * and successfully use it, we return the key, otherwise NULL |
… | |
… | |
1972 | * 0 otherwise |
1979 | * 0 otherwise |
1973 | */ |
1980 | */ |
1974 | static int |
1981 | static int |
1975 | player_attack_door (object *op, object *door) |
1982 | player_attack_door (object *op, object *door) |
1976 | { |
1983 | { |
1977 | /* If its a door, try to find a use a key. If we do destroy the door, |
1984 | /* If its a door, try to find a key. If we do destroy the door, |
1978 | * might as well return immediately as there is nothing more to do - |
1985 | * might as well return immediately as there is nothing more to do - |
1979 | * otherwise, we fall through to the rest of the code. |
1986 | * otherwise, we fall through to the rest of the code. |
1980 | */ |
1987 | */ |
1981 | object *key = find_key (op, op, door); |
1988 | object *key = find_key (op, op, door); |
1982 | |
1989 | |
1983 | /* IF we found a key, do some extra work */ |
1990 | /* If we found a key, do some extra work */ |
1984 | if (key) |
1991 | if (key) |
1985 | { |
1992 | { |
1986 | object *container = key->env; |
1993 | object *container = key->env; |
1987 | |
1994 | |
1988 | play_sound_map (op->map, op->x, op->y, SOUND_OPEN_DOOR); |
1995 | play_sound_map (op->map, op->x, op->y, SOUND_OPEN_DOOR); |
… | |
… | |
2023 | * It should keep the code cleaner. |
2030 | * It should keep the code cleaner. |
2024 | * When this is called, the players direction has been updated |
2031 | * When this is called, the players direction has been updated |
2025 | * (taking into account confusion.) The player is also actually |
2032 | * (taking into account confusion.) The player is also actually |
2026 | * going to try and move (not fire weapons). |
2033 | * going to try and move (not fire weapons). |
2027 | */ |
2034 | */ |
2028 | void |
2035 | bool |
2029 | move_player_attack (object *op, int dir) |
2036 | move_player_attack (object *op, int dir) |
2030 | { |
2037 | { |
2031 | object *tmp, *mon; |
|
|
2032 | int on_battleground; |
2038 | int on_battleground; |
2033 | maptile *m; |
|
|
2034 | |
2039 | |
2035 | sint16 nx = freearr_x[dir] + op->x; |
2040 | sint16 nx = freearr_x[dir] + op->x; |
2036 | sint16 ny = freearr_y[dir] + op->y; |
2041 | sint16 ny = freearr_y[dir] + op->y; |
2037 | |
2042 | |
2038 | on_battleground = op_on_battleground (op, 0, 0); |
2043 | on_battleground = op_on_battleground (op, 0, 0); |
|
|
2044 | |
|
|
2045 | if (out_of_map (op->map, nx, ny)) |
|
|
2046 | return false; |
|
|
2047 | |
|
|
2048 | if (!op->contr->braced && op->speed_left > 0.f && move_ob (op, dir, op)) |
|
|
2049 | { |
|
|
2050 | --op->speed_left; |
|
|
2051 | return true; |
|
|
2052 | } |
2039 | |
2053 | |
2040 | /* If braced, or can't move to the square, and it is not out of the |
2054 | /* If braced, or can't move to the square, and it is not out of the |
2041 | * map, attack it. Note order of if statement is important - don't |
2055 | * map, attack it. Note order of if statement is important - don't |
2042 | * want to be calling move_ob if braced, because move_ob will move the |
2056 | * want to be calling move_ob if braced, because move_ob will move the |
2043 | * player. This is a pretty nasty hack, because if we could |
2057 | * player. This is a pretty nasty hack, because if we could |
2044 | * move to some space, it then means that if we are braced, we should |
2058 | * move to some space, it then means that if we are braced, we should |
2045 | * do nothing at all. As it is, if we are braced, we go through |
2059 | * do nothing at all. As it is, if we are braced, we go through |
2046 | * quite a bit of processing. However, it probably is less than what |
2060 | * quite a bit of processing. However, it probably is less than what |
2047 | * move_ob uses. |
2061 | * move_ob uses. |
2048 | */ |
2062 | */ |
2049 | if ((op->contr->braced || !move_ob (op, dir, op)) && !out_of_map (op->map, nx, ny)) |
|
|
2050 | { |
|
|
2051 | if (OUT_OF_REAL_MAP (op->map, nx, ny)) |
|
|
2052 | { |
|
|
2053 | m = op->map->xy_find (nx, ny); |
2063 | maptile *m = op->map->xy_find (nx, ny); |
2054 | if (!m) |
|
|
2055 | return; /* Don't think this should happen */ |
|
|
2056 | } |
|
|
2057 | else |
|
|
2058 | m = op->map; |
|
|
2059 | |
2064 | |
2060 | if (!(tmp = m->at (nx, ny).bot)) |
|
|
2061 | return; |
|
|
2062 | |
|
|
2063 | mon = 0; |
|
|
2064 | /* Go through all the objects, and find ones of interest. Only stop if |
2065 | /* Go through all the objects, and find ones of interest. Only stop if |
2065 | * we find a monster - that is something we know we want to attack. |
2066 | * we find a monster - that is something we know we want to attack. |
2066 | * if its a door or barrel (can roll) see if there may be monsters |
2067 | * if its a door or barrel (can roll) see if there may be monsters |
2067 | * on the space |
2068 | * on the space |
2068 | */ |
2069 | */ |
2069 | while (tmp) |
2070 | object *mon; |
2070 | { |
2071 | for (mon = m->at (nx, ny).bot; mon; mon = mon->above) |
2071 | if (tmp == op) |
2072 | { |
2072 | { |
2073 | if ((mon->flag [FLAG_ALIVE] |
2073 | tmp = tmp->above; |
2074 | || mon->type == LOCKED_DOOR |
2074 | continue; |
2075 | || mon->flag [FLAG_CAN_ROLL]) |
2075 | } |
|
|
2076 | |
|
|
2077 | if (QUERY_FLAG (tmp, FLAG_ALIVE)) |
|
|
2078 | { |
|
|
2079 | mon = tmp; |
2076 | && mon != op) |
2080 | break; |
2077 | break; |
2081 | } |
2078 | } |
2082 | |
2079 | |
2083 | if (tmp->type == LOCKED_DOOR || QUERY_FLAG (tmp, FLAG_CAN_ROLL)) |
|
|
2084 | mon = tmp; |
|
|
2085 | |
|
|
2086 | tmp = tmp->above; |
|
|
2087 | } |
|
|
2088 | |
|
|
2089 | if (!mon) /* This happens anytime the player tries to move */ |
2080 | if (!mon) /* This happens anytime the player tries to move */ |
2090 | return; /* into a wall */ |
2081 | return false; /* into a wall */ |
2091 | |
2082 | |
2092 | if (mon->head) |
|
|
2093 | mon = mon->head; |
2083 | mon = mon->head_ (); |
2094 | |
2084 | |
2095 | if ((mon->type == DOOR && mon->stats.hp >= 0) || (mon->type == LOCKED_DOOR)) |
2085 | if ((mon->type == DOOR && mon->stats.hp >= 0) || (mon->type == LOCKED_DOOR)) |
|
|
2086 | if (op->contr->weapon_sp_left > 0.f) |
2096 | if (player_attack_door (op, mon)) |
2087 | if (player_attack_door (op, mon)) |
|
|
2088 | { |
|
|
2089 | --op->contr->weapon_sp_left; |
2097 | return; |
2090 | return true; |
|
|
2091 | } |
2098 | |
2092 | |
2099 | /* The following deals with possibly attacking peaceful |
2093 | /* The following deals with possibly attacking peaceful |
2100 | * or frienddly creatures. Basically, all players are considered |
2094 | * or friendly creatures. Basically, all players are considered |
2101 | * unaggressive. If the moving player has peaceful set, then the |
2095 | * unaggressive. If the moving player has peaceful set, then the |
2102 | * object should be pushed instead of attacked. It is assumed that |
2096 | * object should be pushed instead of attacked. It is assumed that |
2103 | * if you are braced, you will not attack friends accidently, |
2097 | * if you are braced, you will not attack friends accidently, |
2104 | * and thus will not push them. |
2098 | * and thus will not push them. |
2105 | */ |
2099 | */ |
2106 | |
2100 | |
2107 | /* If the creature is a pet, push it even if the player is not |
2101 | /* If the creature is a pet, push it even if the player is not |
2108 | * peaceful. Our assumption is the creature is a pet if the |
2102 | * peaceful. Our assumption is the creature is a pet if the |
2109 | * player owns it and it is either friendly or unagressive. |
2103 | * player owns it and it is either friendly or unagressive. |
2110 | */ |
2104 | */ |
2111 | if ((op->type == PLAYER) |
2105 | if (op->type == PLAYER |
2112 | #if COZY_SERVER |
|
|
2113 | && |
|
|
2114 | ((mon->owner && mon->owner->contr |
2106 | && ((mon->owner && mon->owner->contr |
2115 | && same_party (mon->owner->contr->party, op->contr->party)) || mon->owner == op) |
2107 | && same_party (mon->owner->contr->party, op->contr->party)) |
2116 | #else |
|
|
2117 | && mon->owner == op |
2108 | || mon->owner == op) |
2118 | #endif |
|
|
2119 | && (QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY))) |
2109 | && (QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY))) |
2120 | { |
2110 | { |
2121 | /* If we're braced, we don't want to switch places with it */ |
2111 | /* If we're braced, we don't want to switch places with it */ |
2122 | if (op->contr->braced) |
2112 | if (op->contr->braced) |
2123 | return; |
2113 | return false; |
|
|
2114 | |
|
|
2115 | if (op->speed_left > 0.f) |
|
|
2116 | { |
|
|
2117 | --op->speed_left; |
2124 | |
2118 | |
2125 | play_sound_map (op->map, op->x, op->y, SOUND_PUSH_PLAYER); |
2119 | play_sound_map (op->map, op->x, op->y, SOUND_PUSH_PLAYER); |
2126 | push_ob (mon, dir, op); |
2120 | push_ob (mon, dir, op); |
|
|
2121 | |
2127 | if (op->contr->tmp_invis || op->hide) |
2122 | if (op->contr->tmp_invis || op->hide) |
2128 | make_visible (op); |
2123 | make_visible (op); |
2129 | |
2124 | |
2130 | return; |
2125 | return true; |
2131 | } |
2126 | } |
|
|
2127 | else |
|
|
2128 | return false; |
|
|
2129 | } |
2132 | |
2130 | |
2133 | /* in certain circumstances, you shouldn't attack friendly |
2131 | /* in certain circumstances, you shouldn't attack friendly |
2134 | * creatures. Note that if you are braced, you can't push |
2132 | * creatures. Note that if you are braced, you can't push |
2135 | * someone, but put it inside this loop so that you won't |
2133 | * someone, but put it inside this loop so that you won't |
2136 | * attack them either. |
2134 | * attack them either. |
2137 | */ |
2135 | */ |
2138 | if ((mon->type == PLAYER || mon->enemy != op) && |
2136 | if ((mon->type == PLAYER || mon->enemy != op) |
2139 | (mon->type == PLAYER || QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY)) && ( |
2137 | && (mon->type == PLAYER || QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY)) |
2140 | #ifdef PROHIBIT_PLAYERKILL |
|
|
2141 | (op->contr->peaceful |
2138 | && ((op->contr->peaceful |
2142 | || (mon->type == PLAYER |
2139 | || (mon->type == PLAYER && mon->contr->peaceful)) |
2143 | && mon->contr-> |
|
|
2144 | peaceful)) && |
|
|
2145 | #else |
|
|
2146 | op->contr->peaceful && |
|
|
2147 | #endif |
|
|
2148 | !on_battleground)) |
2140 | && !on_battleground)) |
|
|
2141 | { |
|
|
2142 | if (op->speed_left > 0.f) |
2149 | { |
2143 | { |
|
|
2144 | --op->speed_left; |
|
|
2145 | |
2150 | if (!op->contr->braced) |
2146 | if (!op->contr->braced) |
2151 | { |
2147 | { |
2152 | play_sound_map (op->map, op->x, op->y, SOUND_PUSH_PLAYER); |
2148 | play_sound_map (op->map, op->x, op->y, SOUND_PUSH_PLAYER); |
2153 | push_ob (mon, dir, op); |
2149 | push_ob (mon, dir, op); |
2154 | } |
2150 | } |
2155 | else |
2151 | else |
2156 | new_draw_info (0, 0, op, "You withhold your attack"); |
2152 | new_draw_info (0, 0, op, "You withhold your attack"); |
2157 | |
2153 | |
2158 | if (op->contr->tmp_invis || op->hide) |
2154 | if (op->contr->tmp_invis || op->hide) |
2159 | make_visible (op); |
2155 | make_visible (op); |
2160 | } |
|
|
2161 | |
2156 | |
|
|
2157 | return true; |
|
|
2158 | } |
|
|
2159 | } |
2162 | /* If the object is a boulder or other rollable object, then |
2160 | /* If the object is a boulder or other rollable object, then |
2163 | * roll it if not braced. You can't roll it if you are braced. |
2161 | * roll it if not braced. You can't roll it if you are braced. |
2164 | */ |
2162 | */ |
2165 | else if (QUERY_FLAG (mon, FLAG_CAN_ROLL) && (!op->contr->braced)) |
2163 | else if (QUERY_FLAG (mon, FLAG_CAN_ROLL) && (!op->contr->braced)) |
|
|
2164 | { |
|
|
2165 | if (op->speed_left > 0.f) |
2166 | { |
2166 | { |
|
|
2167 | --op->speed_left; |
|
|
2168 | |
2167 | recursive_roll (mon, dir, op); |
2169 | recursive_roll (mon, dir, op); |
2168 | if (action_makes_visible (op)) |
2170 | if (action_makes_visible (op)) |
2169 | make_visible (op); |
2171 | make_visible (op); |
2170 | } |
|
|
2171 | |
2172 | |
|
|
2173 | return true; |
|
|
2174 | } |
|
|
2175 | } |
2172 | /* Any generic living creature. Including things like doors. |
2176 | /* Any generic living creature. Including things like doors. |
2173 | * Way it works is like this: First, it must have some hit points |
2177 | * Way it works is like this: First, it must have some hit points |
2174 | * and be living. Then, it must be one of the following: |
2178 | * and be living. Then, it must be one of the following: |
2175 | * 1) Not a player, 2) A player, but of a different party. Note |
2179 | * 1) Not a player, 2) A player, but of a different party. Note |
2176 | * that party_number -1 is no party, so attacks can still happen. |
2180 | * that party_number -1 is no party, so attacks can still happen. |
2177 | */ |
2181 | */ |
2178 | else if ((mon->stats.hp >= 0) && QUERY_FLAG (mon, FLAG_ALIVE) && |
2182 | else if ((mon->stats.hp >= 0) && QUERY_FLAG (mon, FLAG_ALIVE) && |
2179 | ((mon->type != PLAYER || op->contr->party == NULL || op->contr->party != mon->contr->party))) |
2183 | ((mon->type != PLAYER || op->contr->party == NULL || op->contr->party != mon->contr->party))) |
2180 | { |
2184 | { |
2181 | |
2185 | if (op->contr->weapon_sp_left > 0.f && !op->flag [FLAG_WIZPASS]) |
2182 | /* If the player hasn't hit something this tick, and does |
|
|
2183 | * so, give them speed boost based on weapon speed. Doing |
|
|
2184 | * it here is better than process_players2, which basically |
|
|
2185 | * incurred a 1 tick offset. |
|
|
2186 | */ |
|
|
2187 | if (!op->contr->has_hit) |
|
|
2188 | { |
2186 | { |
2189 | op->speed_left += op->speed / op->contr->weapon_sp; |
2187 | --op->contr->weapon_sp_left; |
2190 | |
|
|
2191 | op->contr->has_hit = 1; /* The last action was to hit, so use weapon_sp */ |
|
|
2192 | } |
|
|
2193 | |
2188 | |
2194 | skill_attack (mon, op, 0, 0, 0); |
2189 | skill_attack (mon, op, 0, 0, 0); |
2195 | |
|
|
2196 | /* If attacking another player, that player gets automatic |
|
|
2197 | * hitback, and doesn't loose luck either. |
|
|
2198 | * Disable hitback on the battleground or if the target is |
|
|
2199 | * the wiz. |
|
|
2200 | */ |
|
|
2201 | if (mon->type == PLAYER && mon->stats.hp >= 0 && !mon->contr->has_hit && !on_battleground && !QUERY_FLAG (mon, FLAG_WIZ)) |
|
|
2202 | { |
|
|
2203 | short luck = mon->stats.luck; |
|
|
2204 | |
|
|
2205 | mon->contr->has_hit = 1; |
|
|
2206 | skill_attack (op, mon, 0, 0, 0); |
|
|
2207 | mon->stats.luck = luck; |
|
|
2208 | } |
|
|
2209 | |
2190 | |
2210 | if (action_makes_visible (op)) |
2191 | if (action_makes_visible (op)) |
2211 | make_visible (op); |
2192 | make_visible (op); |
2212 | } |
|
|
2213 | } /* if player should attack something */ |
|
|
2214 | } |
|
|
2215 | |
2193 | |
2216 | int |
2194 | return true; |
|
|
2195 | } |
|
|
2196 | } |
|
|
2197 | |
|
|
2198 | return false; |
|
|
2199 | } |
|
|
2200 | |
|
|
2201 | bool |
2217 | move_player (object *op, int dir) |
2202 | move_player (object *op, int dir) |
2218 | { |
2203 | { |
2219 | int pick; |
2204 | int pick; |
2220 | |
2205 | |
2221 | if (!op->map || op->map->in_memory != MAP_IN_MEMORY) |
2206 | if (!op->map || op->map->in_memory != MAP_IN_MEMORY) |
… | |
… | |
2235 | op->facing = dir; |
2220 | op->facing = dir; |
2236 | |
2221 | |
2237 | if (op->hide) |
2222 | if (op->hide) |
2238 | do_hidden_move (op); |
2223 | do_hidden_move (op); |
2239 | |
2224 | |
|
|
2225 | bool retval; |
|
|
2226 | |
2240 | if (INVOKE_PLAYER (MOVE, op->contr, ARG_INT (dir))) |
2227 | if (INVOKE_PLAYER (MOVE, op->contr, ARG_INT (dir))) |
2241 | /*nop */ ; |
2228 | retval = RESULT_INT (0); |
2242 | else if (op->contr->fire_on) |
2229 | else if (op->contr->fire_on) |
2243 | fire (op, dir); |
2230 | retval = fire (op, dir); |
2244 | else |
2231 | else |
2245 | { |
2232 | { |
2246 | move_player_attack (op, dir); |
2233 | retval = move_player_attack (op, dir); |
2247 | pick = check_pick (op); |
2234 | pick = check_pick (op); |
2248 | } |
2235 | } |
2249 | |
2236 | |
2250 | /* Add special check for newcs players and fire on - this way, the |
2237 | /* Add special check for newcs players and fire on - this way, the |
2251 | * server can handle repeat firing. |
2238 | * server can handle repeat firing. |
… | |
… | |
2258 | /* Update how the player looks. Use the facing, so direction may |
2245 | /* Update how the player looks. Use the facing, so direction may |
2259 | * get reset to zero. This allows for full animation capabilities |
2246 | * get reset to zero. This allows for full animation capabilities |
2260 | * for players. |
2247 | * for players. |
2261 | */ |
2248 | */ |
2262 | animate_object (op, op->facing); |
2249 | animate_object (op, op->facing); |
2263 | return 0; |
2250 | |
|
|
2251 | return retval; |
2264 | } |
2252 | } |
2265 | |
2253 | |
2266 | /* This is similar to handle_player, below, but is only used by the |
2254 | /* This is similar to handle_player, below, but is only used by the |
2267 | * new client/server stuff. |
2255 | * new client/server stuff. |
2268 | * This is sort of special, in that the new client/server actually uses |
2256 | * This is sort of special, in that the new client/server actually uses |
2269 | * the new speed values for commands. |
2257 | * the new speed values for commands. |
2270 | * |
2258 | * |
2271 | * Returns true if there are more actions we can do. |
2259 | * Returns true if there are more actions we can do. Should not do |
|
|
2260 | * many actions in a row, as that would be too unfair to other |
|
|
2261 | * players. |
2272 | */ |
2262 | */ |
2273 | int |
2263 | bool |
2274 | handle_newcs_player (object *op) |
2264 | handle_newcs_player (object *op) |
2275 | { |
2265 | { |
2276 | if (QUERY_FLAG (op, FLAG_SCARED)) |
2266 | if (QUERY_FLAG (op, FLAG_SCARED)) |
2277 | { |
2267 | { |
2278 | flee_player (op); |
2268 | if (op->speed_left > 0.f) |
2279 | /* If player is still scared, that is his action for this tick */ |
|
|
2280 | if (QUERY_FLAG (op, FLAG_SCARED)) |
|
|
2281 | { |
2269 | { |
2282 | op->speed_left--; |
2270 | --op->speed_left; |
|
|
2271 | flee_player (op); |
|
|
2272 | |
2283 | return 0; |
2273 | return true; |
2284 | } |
2274 | } |
|
|
2275 | else |
|
|
2276 | return false; |
2285 | } |
2277 | } |
2286 | |
2278 | |
2287 | /* 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 |
2288 | * the players time has been increased when doericserver has been |
2280 | * the players time has been increased when doericserver has been |
2289 | * called, so we recheck it here. |
2281 | * called, so we recheck it here. |
2290 | */ |
2282 | */ |
2291 | if (op->contr->ns->handle_command ()) |
2283 | if (op->contr->ns->handle_command ()) |
2292 | return 1; |
2284 | return true; |
2293 | |
2285 | |
2294 | if (op->speed_left > 0) |
|
|
2295 | { |
|
|
2296 | if (op->direction && (op->contr->run_on || op->contr->fire_on)) |
2286 | if (op->direction && (op->contr->run_on || op->contr->fire_on)) |
2297 | { |
|
|
2298 | /* All move commands take 1 tick, at least for now */ |
|
|
2299 | op->speed_left--; |
|
|
2300 | |
|
|
2301 | /* Instead of all the stuff below, let move_player take care |
|
|
2302 | * of it. Also, some of the skill stuff is only put in |
|
|
2303 | * there, as well as the confusion stuff. |
|
|
2304 | */ |
|
|
2305 | move_player (op, op->direction); |
2287 | return move_player (op, op->direction); |
2306 | |
2288 | |
2307 | return op->speed_left > 0; |
|
|
2308 | } |
|
|
2309 | } |
|
|
2310 | |
|
|
2311 | return 0; |
2289 | return false; |
2312 | } |
2290 | } |
2313 | |
2291 | |
2314 | int |
2292 | int |
2315 | save_life (object *op) |
2293 | save_life (object *op) |
2316 | { |
2294 | { |
… | |
… | |
2582 | } |
2560 | } |
2583 | |
2561 | |
2584 | /* Digestion */ |
2562 | /* Digestion */ |
2585 | if (--op->last_eat < 0) |
2563 | if (--op->last_eat < 0) |
2586 | { |
2564 | { |
2587 | #ifdef COZY_SERVER |
|
|
2588 | int dg = op->contr->digestion >= 0 && op->contr->digestion < 2 ? 2 : op->contr->digestion; |
|
|
2589 | int bonus = dg > 0 ? dg : 0, penalty = dg < 0 ? -dg : 0; |
|
|
2590 | #else |
|
|
2591 | int bonus = op->contr->digestion > 0 ? op->contr->digestion : 0, penalty = op->contr->digestion < 0 ? -op->contr->digestion : 0; |
2565 | int bonus = op->contr->digestion > 0 ? op->contr->digestion : 0, penalty = op->contr->digestion < 0 ? -op->contr->digestion : 0; |
2592 | #endif |
|
|
2593 | |
2566 | |
2594 | if (op->contr->gen_hp > 0) |
2567 | if (op->contr->gen_hp > 0) |
2595 | op->last_eat = 25 * (1 + bonus) / (op->contr->gen_hp + penalty + 1); |
2568 | op->last_eat = 25 * (1 + bonus) / (op->contr->gen_hp + penalty + 1); |
2596 | else |
2569 | else |
2597 | op->last_eat = 25 * (1 + bonus) / (penalty + 1); |
2570 | op->last_eat = 25 * (1 + bonus) / (penalty + 1); |
… | |
… | |
2942 | object *force; |
2915 | object *force; |
2943 | int at; |
2916 | int at; |
2944 | |
2917 | |
2945 | force = get_archetype (FORCE_NAME); |
2918 | force = get_archetype (FORCE_NAME); |
2946 | /* 50 ticks should be enough time for the spell to abate */ |
2919 | /* 50 ticks should be enough time for the spell to abate */ |
2947 | force->speed = 0.1; |
2920 | force->speed = 0.1f; |
2948 | force->speed_left = -5.0; |
2921 | force->speed_left = -5.f; |
2949 | SET_FLAG (force, FLAG_APPLIED); |
2922 | SET_FLAG (force, FLAG_APPLIED); |
2950 | for (at = 0; at < NROFATTACKS; at++) |
2923 | for (at = 0; at < NROFATTACKS; at++) |
2951 | if (will_kill_again & (1 << at)) |
2924 | if (will_kill_again & (1 << at)) |
2952 | force->resist[at] = 100; |
2925 | force->resist[at] = 100; |
2953 | |
2926 | |
… | |
… | |
3128 | /* For Hidden creatures - a chance of becoming 'unhidden' |
3101 | /* For Hidden creatures - a chance of becoming 'unhidden' |
3129 | * every time they move - as we subtract off 'invisibility' |
3102 | * every time they move - as we subtract off 'invisibility' |
3130 | * AND, for players, if they move into a ridiculously unhideable |
3103 | * AND, for players, if they move into a ridiculously unhideable |
3131 | * spot (surrounded by clear terrain in broad daylight). -b.t. |
3104 | * spot (surrounded by clear terrain in broad daylight). -b.t. |
3132 | */ |
3105 | */ |
3133 | |
|
|
3134 | void |
3106 | void |
3135 | do_hidden_move (object *op) |
3107 | do_hidden_move (object *op) |
3136 | { |
3108 | { |
3137 | int hide = 0, num = random_roll (0, 19, op, PREFER_LOW); |
3109 | int hide = 0, num = random_roll (0, 19, op, PREFER_LOW); |
3138 | object *skop; |
3110 | object *skop; |