1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * the terms of the Affero GNU General Public License as published by the |
9 | * the terms of the Affero GNU General Public License as published by the |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * option) any later version. |
11 | * option) any later version. |
… | |
… | |
110 | link_skills (); |
110 | link_skills (); |
111 | |
111 | |
112 | assign (title, ob->arch->object::name); |
112 | assign (title, ob->arch->object::name); |
113 | |
113 | |
114 | /* if it's a dragon player, set the correct title here */ |
114 | /* if it's a dragon player, set the correct title here */ |
115 | if (is_dragon_pl (ob)) |
115 | if (ob->is_dragon ()) |
116 | { |
116 | { |
117 | object *tmp, *abil = 0, *skin = 0; |
117 | object *tmp, *abil = 0, *skin = 0; |
118 | |
118 | |
119 | for (tmp = ob->inv; tmp; tmp = tmp->below) |
119 | for (tmp = ob->inv; tmp; tmp = tmp->below) |
120 | if (tmp->type == FORCE) |
120 | if (tmp->type == FORCE) |
… | |
… | |
136 | esrv_send_inventory (ob, ob); |
136 | esrv_send_inventory (ob, ob); |
137 | esrv_add_spells (this, 0); |
137 | esrv_add_spells (this, 0); |
138 | |
138 | |
139 | ob->flag [FLAG_READY_WEAPON] = false; |
139 | ob->flag [FLAG_READY_WEAPON] = false; |
140 | ob->flag [FLAG_READY_SKILL] = false; |
140 | ob->flag [FLAG_READY_SKILL] = false; |
|
|
141 | ob->flag [FLAG_READY_RANGE] = false; |
141 | ob->flag [FLAG_READY_BOW] = false; |
142 | ob->flag [FLAG_READY_BOW] = false; |
142 | |
143 | |
143 | for (object *op = ob->inv; op; op = op->below) |
144 | ob->update_stats (); // we unapplied stuff above |
144 | if (op->flag [FLAG_APPLIED]) |
145 | activate (); |
145 | switch (op->type) |
|
|
146 | { |
|
|
147 | case SKILL: |
|
|
148 | op->flag [FLAG_APPLIED] = false; |
|
|
149 | break; |
|
|
150 | |
|
|
151 | case WAND: |
|
|
152 | case ROD: |
|
|
153 | case HORN: |
|
|
154 | case BOW: |
|
|
155 | ranged_ob = op; |
|
|
156 | break; |
|
|
157 | |
|
|
158 | case WEAPON: |
|
|
159 | combat_ob = op; |
|
|
160 | break; |
|
|
161 | } |
|
|
162 | |
|
|
163 | ob->current_weapon = 0; |
|
|
164 | ob->change_weapon (combat_ob ? combat_ob : ranged_ob); |
|
|
165 | activate (); // change_weapon also activates, but this doesn't hurt |
|
|
166 | |
146 | |
167 | INVOKE_PLAYER (CONNECT, this); |
147 | INVOKE_PLAYER (CONNECT, this); |
168 | INVOKE_PLAYER (LOGIN, this); |
148 | INVOKE_PLAYER (LOGIN, this); |
169 | } |
149 | } |
170 | |
150 | |
… | |
… | |
838 | dir = absdir (4 + rv.direction); |
818 | dir = absdir (4 + rv.direction); |
839 | for (diff = 0; diff < 3; diff++) |
819 | for (diff = 0; diff < 3; diff++) |
840 | { |
820 | { |
841 | int m = 1 - rndm (2) * 2; |
821 | int m = 1 - rndm (2) * 2; |
842 | |
822 | |
843 | if (move_ob (op, absdir (dir + diff * m), op) || (diff == 0 && move_ob (op, absdir (dir - diff * m), op))) |
823 | if (op->move (absdir (dir + diff * m)) || (diff == 0 && op->move (absdir (dir - diff * m)))) |
844 | return; |
824 | return; |
845 | } |
825 | } |
846 | |
826 | |
847 | /* Cornered, get rid of scared */ |
827 | /* Cornered, get rid of scared */ |
848 | CLEAR_FLAG (op, FLAG_SCARED); |
828 | CLEAR_FLAG (op, FLAG_SCARED); |
… | |
… | |
858 | { |
838 | { |
859 | object *tmp, *next; |
839 | object *tmp, *next; |
860 | int stop = 0; |
840 | int stop = 0; |
861 | int wvratio; |
841 | int wvratio; |
862 | |
842 | |
863 | /* if you're flying, you cna't pick up anything */ |
843 | /* if you're flying, you can't pick up anything */ |
864 | if (op->move_type & MOVE_FLYING) |
844 | if (op->move_type & MOVE_FLYING) |
865 | return 1; |
845 | return 1; |
866 | |
846 | |
867 | next = op->below; |
847 | next = op->below; |
868 | |
848 | |
… | |
… | |
1584 | { |
1564 | { |
1585 | LOG (llevError, "Object %s lacks a spell\n", &item->name); |
1565 | LOG (llevError, "Object %s lacks a spell\n", &item->name); |
1586 | return; |
1566 | return; |
1587 | } |
1567 | } |
1588 | |
1568 | |
1589 | if (!op->change_weapon (item)) |
1569 | if (!op->apply (item)) |
1590 | return; |
1570 | return; |
1591 | |
1571 | |
1592 | if (item->type == WAND) |
1572 | if (item->type == WAND) |
1593 | { |
1573 | { |
1594 | if (item->stats.food <= 0) |
1574 | if (item->stats.food <= 0) |
… | |
… | |
1645 | } |
1625 | } |
1646 | |
1626 | |
1647 | /* Received a fire command for the player - go and do it. |
1627 | /* Received a fire command for the player - go and do it. |
1648 | */ |
1628 | */ |
1649 | bool |
1629 | bool |
1650 | fire (object *op, int dir) |
1630 | fire (object *who, int dir) |
1651 | { |
1631 | { |
1652 | int spellcost = 0; |
1632 | int spellcost = 0; |
1653 | |
1633 | |
1654 | player *pl = op->contr; |
1634 | player *pl = who->contr; |
1655 | |
1635 | |
1656 | if (pl->golem) |
1636 | if (pl->golem) |
1657 | { |
1637 | { |
1658 | control_golem (op->contr->golem, dir); |
1638 | control_golem (who->contr->golem, dir); |
1659 | return false; |
1639 | return false; |
1660 | } |
1640 | } |
1661 | |
1641 | |
1662 | object *ob = pl->ranged_ob; |
1642 | object *ob = pl->ranged_ob; |
1663 | |
1643 | |
1664 | if (!ob) |
1644 | if (!ob) |
1665 | return false; |
1645 | return false; |
1666 | |
1646 | |
1667 | if (op->speed_left > 0.f) |
1647 | if (who->speed_left > 0.f) |
1668 | --op->speed_left; |
1648 | --who->speed_left; |
1669 | else |
1649 | else |
1670 | return false; |
1650 | return false; |
1671 | |
1651 | |
1672 | if (!op->change_weapon (ob)) |
1652 | if (!who->apply (ob)) |
1673 | return false; |
1653 | return false; |
1674 | |
1654 | |
1675 | /* check for loss of invisiblity/hide */ |
1655 | /* check for loss of invisiblity/hide */ |
1676 | if (action_makes_visible (op)) |
1656 | if (action_makes_visible (who)) |
1677 | make_visible (op); |
1657 | make_visible (who); |
1678 | |
1658 | |
1679 | switch (ob->type) |
1659 | switch (ob->type) |
1680 | { |
1660 | { |
1681 | case BOW: |
1661 | case BOW: |
1682 | player_fire_bow (op, dir); |
1662 | player_fire_bow (who, dir); |
1683 | break; |
1663 | break; |
1684 | |
1664 | |
1685 | case SPELL: |
1665 | case SPELL: |
1686 | spellcost = cast_spell (op, op, dir, ob, *pl->spellparam ? pl->spellparam : 0); |
1666 | spellcost = cast_spell (who, who, dir, ob, *pl->spellparam ? pl->spellparam : 0); |
1687 | break; |
1667 | break; |
1688 | |
1668 | |
1689 | case BUILDER: |
1669 | case BUILDER: |
1690 | apply_map_builder (op, dir); |
1670 | apply_map_builder (who, dir); |
1691 | break; |
1671 | break; |
1692 | |
1672 | |
1693 | case SKILL: |
1673 | case SKILL: |
1694 | do_skill (op, op, ob, dir, 0); |
1674 | do_skill (who, who, ob, dir, 0); |
1695 | break; |
1675 | break; |
1696 | |
1676 | |
|
|
1677 | case RANGED: |
|
|
1678 | do_skill (who, ob, who->chosen_skill, dir, 0); |
|
|
1679 | break; |
|
|
1680 | |
1697 | default: |
1681 | default: |
1698 | fire_misc_object (op, dir); |
1682 | fire_misc_object (who, dir); |
1699 | break; |
1683 | break; |
1700 | } |
1684 | } |
1701 | |
1685 | |
1702 | return true; |
1686 | return true; |
1703 | } |
1687 | } |
… | |
… | |
1856 | * going to try and move (not fire weapons). |
1840 | * going to try and move (not fire weapons). |
1857 | */ |
1841 | */ |
1858 | bool |
1842 | bool |
1859 | move_player_attack (object *op, int dir) |
1843 | move_player_attack (object *op, int dir) |
1860 | { |
1844 | { |
1861 | if (!op->contr->braced && op->speed_left > 0.f && move_ob (op, dir, op)) |
1845 | if (!op->contr->braced && op->speed_left > 0.f && op->move (dir)) |
1862 | { |
1846 | { |
1863 | --op->speed_left; |
1847 | --op->speed_left; |
1864 | return true; |
1848 | return true; |
1865 | } |
1849 | } |
1866 | |
1850 | |
1867 | int on_battleground; |
|
|
1868 | |
|
|
1869 | sint16 nx = freearr_x[dir] + op->x; |
1851 | sint16 nx = freearr_x[dir] + op->x; |
1870 | sint16 ny = freearr_y[dir] + op->y; |
1852 | sint16 ny = freearr_y[dir] + op->y; |
1871 | |
|
|
1872 | on_battleground = op_on_battleground (op, 0, 0); |
|
|
1873 | |
1853 | |
1874 | if (out_of_map (op->map, nx, ny)) |
1854 | if (out_of_map (op->map, nx, ny)) |
1875 | return false; |
1855 | return false; |
1876 | |
1856 | |
1877 | /* If braced, or can't move to the square, and it is not out of the |
1857 | /* If braced, or can't move to the square, and it is not out of the |
… | |
… | |
1949 | } |
1929 | } |
1950 | else |
1930 | else |
1951 | return false; |
1931 | return false; |
1952 | } |
1932 | } |
1953 | |
1933 | |
|
|
1934 | bool on_battleground = op_on_battleground (op, 0, 0); |
|
|
1935 | |
1954 | /* in certain circumstances, you shouldn't attack friendly |
1936 | /* in certain circumstances, you shouldn't attack friendly |
1955 | * creatures. Note that if you are braced, you can't push |
1937 | * creatures. Note that if you are braced, you can't push |
1956 | * someone, but put it inside this loop so that you won't |
1938 | * someone, but put it inside this loop so that you won't |
1957 | * attack them either. |
1939 | * attack them either. |
1958 | */ |
1940 | */ |
… | |
… | |
2026 | { |
2008 | { |
2027 | if (!op->map || op->map->in_memory != MAP_ACTIVE) |
2009 | if (!op->map || op->map->in_memory != MAP_ACTIVE) |
2028 | return 0; |
2010 | return 0; |
2029 | |
2011 | |
2030 | /* Sanity check: make sure dir is valid */ |
2012 | /* Sanity check: make sure dir is valid */ |
2031 | if ((dir < 0) || (dir >= 9)) |
2013 | if (dir < 0 || dir >= 9) |
2032 | { |
2014 | { |
2033 | LOG (llevError, "move_player: invalid direction %d\n", dir); |
2015 | LOG (llevError, "move_player: invalid direction %d\n", dir); |
2034 | return 0; |
2016 | return 0; |
2035 | } |
2017 | } |
2036 | |
2018 | |
… | |
… | |
2128 | |
2110 | |
2129 | if (op->stats.hp < 0) |
2111 | if (op->stats.hp < 0) |
2130 | op->stats.hp = op->stats.maxhp; |
2112 | op->stats.hp = op->stats.maxhp; |
2131 | |
2113 | |
2132 | if (op->stats.food < 0) |
2114 | if (op->stats.food < 0) |
2133 | op->stats.food = 999; |
2115 | op->stats.food = MAX_FOOD; |
2134 | |
2116 | |
2135 | op->update_stats (); |
2117 | op->update_stats (); |
2136 | return 1; |
2118 | return 1; |
2137 | } |
2119 | } |
2138 | |
2120 | |
… | |
… | |
2367 | |
2349 | |
2368 | if (tmp->type == FOOD || tmp->type == DRINK || tmp->type == POISON) |
2350 | if (tmp->type == FOOD || tmp->type == DRINK || tmp->type == POISON) |
2369 | { |
2351 | { |
2370 | op->statusmsg ("You blindly grab for a bite of food. " |
2352 | op->statusmsg ("You blindly grab for a bite of food. " |
2371 | "H<To prevent you from starving, you ate some random item from your backpack.>"); |
2353 | "H<To prevent you from starving, you ate some random item from your backpack.>"); |
2372 | manual_apply (op, tmp, 0); |
2354 | op->apply (tmp); |
2373 | |
2355 | |
2374 | if (op->stats.food >= 0 || op->stats.hp < 0) |
2356 | if (op->stats.food >= 0 || op->stats.hp < 0) |
2375 | break; |
2357 | break; |
2376 | } |
2358 | } |
2377 | else if (tmp->type == FLESH) |
2359 | else if (tmp->type == FLESH) |
… | |
… | |
2383 | */ |
2365 | */ |
2384 | if (op->stats.food < 0 && op->stats.hp >= 0 && flesh) |
2366 | if (op->stats.food < 0 && op->stats.hp >= 0 && flesh) |
2385 | { |
2367 | { |
2386 | op->statusmsg ("You blindly grab for a bite of food. " |
2368 | op->statusmsg ("You blindly grab for a bite of food. " |
2387 | "H<To prevent you from starving, you ate some random item from your backpack.>"); |
2369 | "H<To prevent you from starving, you ate some random item from your backpack.>"); |
2388 | manual_apply (op, flesh, 0); |
2370 | op->apply (flesh); |
2389 | } |
2371 | } |
2390 | |
2372 | |
2391 | // If player is still starving, alert him! |
2373 | // If player is still starving, alert him! |
2392 | if (op->stats.food < 0) |
2374 | if (op->stats.food < 0) |
2393 | op->failmsg ("You are starving! " |
2375 | op->failmsg ("You are starving! " |
… | |
… | |
2449 | cure_disease (op, 0, 0); /* remove any disease */ |
2431 | cure_disease (op, 0, 0); /* remove any disease */ |
2450 | |
2432 | |
2451 | max_it (op->stats.hp , op->stats.maxhp); |
2433 | max_it (op->stats.hp , op->stats.maxhp); |
2452 | max_it (op->stats.sp , op->stats.maxsp); |
2434 | max_it (op->stats.sp , op->stats.maxsp); |
2453 | max_it (op->stats.grace, op->stats.maxgrace); |
2435 | max_it (op->stats.grace, op->stats.maxgrace); |
2454 | |
|
|
2455 | if (op->stats.food <= 0) |
2436 | max_it (op->stats.food , 200); |
2456 | op->stats.food = 999; |
|
|
2457 | |
2437 | |
2458 | // remove all spell effects that are active |
2438 | // remove all spell effects that are active |
2459 | // to avoid long-term effects such as word-of-recall |
2439 | // to avoid long-term effects such as word-of-recall |
2460 | for (object *item = op->inv; item; ) |
2440 | for (object *item = op->inv; item; ) |
2461 | { |
2441 | { |
… | |
… | |
3045 | && tmp->name == shstr_battleground |
3025 | && tmp->name == shstr_battleground |
3046 | && EXIT_X (tmp) && EXIT_Y (tmp)) |
3026 | && EXIT_X (tmp) && EXIT_Y (tmp)) |
3047 | { |
3027 | { |
3048 | /* before we assign the exit, check if this is a teambattle */ |
3028 | /* before we assign the exit, check if this is a teambattle */ |
3049 | if (EXIT_ALT_X (tmp) && EXIT_ALT_Y (tmp) && EXIT_PATH (tmp)) |
3029 | if (EXIT_ALT_X (tmp) && EXIT_ALT_Y (tmp) && EXIT_PATH (tmp)) |
3050 | { |
|
|
3051 | for (object *invtmp = op->inv; invtmp; invtmp = invtmp->below) |
3030 | for (object *invtmp = op->inv; invtmp; invtmp = invtmp->below) |
|
|
3031 | if (invtmp->type == FORCE && invtmp->slaying && tmp->slaying == invtmp->slaying) |
3052 | { |
3032 | { |
3053 | if (invtmp->type == FORCE && invtmp->slaying && tmp->slaying == invtmp->slaying) |
|
|
3054 | { |
|
|
3055 | if (x && y) |
3033 | if (x && y) |
3056 | *x = EXIT_ALT_X (tmp), *y = EXIT_ALT_Y (tmp); |
3034 | *x = EXIT_ALT_X (tmp), *y = EXIT_ALT_Y (tmp); |
3057 | |
3035 | |
3058 | return 1; |
3036 | return 1; |
3059 | } |
|
|
3060 | } |
3037 | } |
3061 | } |
|
|
3062 | |
3038 | |
3063 | if (x && y) |
3039 | if (x && y) |
3064 | *x = EXIT_X (tmp), *y = EXIT_Y (tmp); |
3040 | *x = EXIT_X (tmp), *y = EXIT_Y (tmp); |
3065 | |
3041 | |
3066 | return 1; |
3042 | return 1; |
… | |
… | |
3204 | else |
3180 | else |
3205 | j = 1; |
3181 | j = 1; |
3206 | strcat (buf, spellpathnames[i]); |
3182 | strcat (buf, spellpathnames[i]); |
3207 | } |
3183 | } |
3208 | } |
3184 | } |
|
|
3185 | |
3209 | strcat (buf, "."); |
3186 | strcat (buf, "."); |
3210 | new_draw_info (NDI_UNIQUE | NDI_BLUE, 0, who, buf); |
3187 | new_draw_info (NDI_UNIQUE | NDI_BLUE, 0, who, buf); |
3211 | } |
3188 | } |
3212 | |
3189 | |
3213 | /* evtl. adding flags: */ |
3190 | /* evtl. adding flags: */ |
… | |
… | |
3229 | new_draw_info_format (NDI_UNIQUE | NDI_BLUE, 0, who, "You gained %s", query_short_name (tmp)); |
3206 | new_draw_info_format (NDI_UNIQUE | NDI_BLUE, 0, who, "You gained %s", query_short_name (tmp)); |
3230 | who->insert (tmp); |
3207 | who->insert (tmp); |
3231 | } |
3208 | } |
3232 | } |
3209 | } |
3233 | |
3210 | |
3234 | /** |
|
|
3235 | * Unready an object for a player. This function does nothing if the object was |
|
|
3236 | * not readied. |
|
|
3237 | */ |
|
|
3238 | void |
|
|
3239 | player_unready_range_ob (player *pl, object *ob) |
|
|
3240 | { |
|
|
3241 | if (pl->ob->current_weapon == ob) |
|
|
3242 | pl->ob->current_weapon = 0; |
|
|
3243 | |
|
|
3244 | if (pl->combat_ob == ob) |
|
|
3245 | pl->combat_ob = 0; |
|
|
3246 | |
|
|
3247 | if (pl->ranged_ob == ob) |
|
|
3248 | pl->ranged_ob = 0; |
|
|
3249 | } |
|
|
3250 | |
|
|
3251 | //-GPL |
3211 | //-GPL |
3252 | |
3212 | |
3253 | sint8 |
3213 | sint8 |
3254 | player::darkness_at (maptile *map, int x, int y) const |
3214 | player::darkness_at (maptile *map, int x, int y) const |
3255 | { |
3215 | { |