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. |
… | |
… | |
76 | ob->remove (); |
76 | ob->remove (); |
77 | ob->enemy = 0; // sometimes keeps an extra refcount on itself |
77 | ob->enemy = 0; // sometimes keeps an extra refcount on itself |
78 | ob->map = 0; |
78 | ob->map = 0; |
79 | party = 0; |
79 | party = 0; |
80 | |
80 | |
81 | combat_ob = ranged_ob = 0; //TODO, should be special marker, non-refcounted, not this |
|
|
82 | |
|
|
83 | players.erase (this); |
81 | players.erase (this); |
84 | } |
82 | } |
85 | |
83 | |
86 | // connect the player with a specific client |
84 | // connect the player with a specific client |
87 | // also changes, rationalises, and fixes some incorrect settings |
85 | // also changes, rationalises, and fixes some incorrect settings |
… | |
… | |
136 | esrv_send_inventory (ob, ob); |
134 | esrv_send_inventory (ob, ob); |
137 | esrv_add_spells (this, 0); |
135 | esrv_add_spells (this, 0); |
138 | |
136 | |
139 | ob->flag [FLAG_READY_WEAPON] = false; |
137 | ob->flag [FLAG_READY_WEAPON] = false; |
140 | ob->flag [FLAG_READY_SKILL] = false; |
138 | ob->flag [FLAG_READY_SKILL] = false; |
|
|
139 | ob->flag [FLAG_READY_RANGE] = false; |
141 | ob->flag [FLAG_READY_BOW] = false; |
140 | ob->flag [FLAG_READY_BOW] = false; |
142 | |
141 | |
143 | for (object *op = ob->inv; op; op = op->below) |
142 | ob->update_stats (); // we unapplied stuff above |
144 | if (op->flag [FLAG_APPLIED]) |
143 | 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 | |
144 | |
167 | INVOKE_PLAYER (CONNECT, this); |
145 | INVOKE_PLAYER (CONNECT, this); |
168 | INVOKE_PLAYER (LOGIN, this); |
146 | INVOKE_PLAYER (LOGIN, this); |
169 | } |
147 | } |
170 | |
148 | |
… | |
… | |
858 | { |
836 | { |
859 | object *tmp, *next; |
837 | object *tmp, *next; |
860 | int stop = 0; |
838 | int stop = 0; |
861 | int wvratio; |
839 | int wvratio; |
862 | |
840 | |
863 | /* if you're flying, you cna't pick up anything */ |
841 | /* if you're flying, you can't pick up anything */ |
864 | if (op->move_type & MOVE_FLYING) |
842 | if (op->move_type & MOVE_FLYING) |
865 | return 1; |
843 | return 1; |
866 | |
844 | |
867 | next = op->below; |
845 | next = op->below; |
868 | |
846 | |
… | |
… | |
1584 | { |
1562 | { |
1585 | LOG (llevError, "Object %s lacks a spell\n", &item->name); |
1563 | LOG (llevError, "Object %s lacks a spell\n", &item->name); |
1586 | return; |
1564 | return; |
1587 | } |
1565 | } |
1588 | |
1566 | |
1589 | if (!op->change_weapon (item)) |
1567 | if (!op->apply (item)) |
1590 | return; |
1568 | return; |
1591 | |
1569 | |
1592 | if (item->type == WAND) |
1570 | if (item->type == WAND) |
1593 | { |
1571 | { |
1594 | if (item->stats.food <= 0) |
1572 | if (item->stats.food <= 0) |
… | |
… | |
1645 | } |
1623 | } |
1646 | |
1624 | |
1647 | /* Received a fire command for the player - go and do it. |
1625 | /* Received a fire command for the player - go and do it. |
1648 | */ |
1626 | */ |
1649 | bool |
1627 | bool |
1650 | fire (object *op, int dir) |
1628 | fire (object *who, int dir) |
1651 | { |
1629 | { |
1652 | int spellcost = 0; |
1630 | int spellcost = 0; |
1653 | |
1631 | |
1654 | player *pl = op->contr; |
1632 | player *pl = who->contr; |
1655 | |
1633 | |
1656 | if (pl->golem) |
1634 | if (pl->golem) |
1657 | { |
1635 | { |
1658 | control_golem (op->contr->golem, dir); |
1636 | control_golem (who->contr->golem, dir); |
1659 | return false; |
1637 | return false; |
1660 | } |
1638 | } |
1661 | |
1639 | |
1662 | object *ob = pl->ranged_ob; |
1640 | object *ob = pl->ranged_ob; |
1663 | |
1641 | |
1664 | if (!ob) |
1642 | if (!ob) |
1665 | return false; |
1643 | return false; |
1666 | |
1644 | |
1667 | if (op->speed_left > 0.f) |
1645 | if (who->speed_left > 0.f) |
1668 | --op->speed_left; |
1646 | --who->speed_left; |
1669 | else |
1647 | else |
1670 | return false; |
1648 | return false; |
1671 | |
1649 | |
1672 | if (!op->change_weapon (ob)) |
1650 | if (!who->apply (ob)) |
1673 | return false; |
1651 | return false; |
1674 | |
1652 | |
1675 | /* check for loss of invisiblity/hide */ |
1653 | /* check for loss of invisiblity/hide */ |
1676 | if (action_makes_visible (op)) |
1654 | if (action_makes_visible (who)) |
1677 | make_visible (op); |
1655 | make_visible (who); |
1678 | |
1656 | |
1679 | switch (ob->type) |
1657 | switch (ob->type) |
1680 | { |
1658 | { |
1681 | case BOW: |
1659 | case BOW: |
1682 | player_fire_bow (op, dir); |
1660 | player_fire_bow (who, dir); |
1683 | break; |
1661 | break; |
1684 | |
1662 | |
1685 | case SPELL: |
1663 | case SPELL: |
1686 | spellcost = cast_spell (op, op, dir, ob, *pl->spellparam ? pl->spellparam : 0); |
1664 | spellcost = cast_spell (who, who, dir, ob, *pl->spellparam ? pl->spellparam : 0); |
1687 | break; |
1665 | break; |
1688 | |
1666 | |
1689 | case BUILDER: |
1667 | case BUILDER: |
1690 | apply_map_builder (op, dir); |
1668 | apply_map_builder (who, dir); |
1691 | break; |
1669 | break; |
1692 | |
1670 | |
1693 | case SKILL: |
1671 | case SKILL: |
1694 | do_skill (op, op, ob, dir, 0); |
1672 | do_skill (who, who, ob, dir, 0); |
1695 | break; |
1673 | break; |
1696 | |
1674 | |
|
|
1675 | case RANGED: |
|
|
1676 | do_skill (who, ob, who->chosen_skill, dir, 0); |
|
|
1677 | break; |
|
|
1678 | |
1697 | default: |
1679 | default: |
1698 | fire_misc_object (op, dir); |
1680 | fire_misc_object (who, dir); |
1699 | break; |
1681 | break; |
1700 | } |
1682 | } |
1701 | |
1683 | |
1702 | return true; |
1684 | return true; |
1703 | } |
1685 | } |
… | |
… | |
2126 | |
2108 | |
2127 | if (op->stats.hp < 0) |
2109 | if (op->stats.hp < 0) |
2128 | op->stats.hp = op->stats.maxhp; |
2110 | op->stats.hp = op->stats.maxhp; |
2129 | |
2111 | |
2130 | if (op->stats.food < 0) |
2112 | if (op->stats.food < 0) |
2131 | op->stats.food = 999; |
2113 | op->stats.food = MAX_FOOD; |
2132 | |
2114 | |
2133 | op->update_stats (); |
2115 | op->update_stats (); |
2134 | return 1; |
2116 | return 1; |
2135 | } |
2117 | } |
2136 | |
2118 | |
… | |
… | |
2365 | |
2347 | |
2366 | if (tmp->type == FOOD || tmp->type == DRINK || tmp->type == POISON) |
2348 | if (tmp->type == FOOD || tmp->type == DRINK || tmp->type == POISON) |
2367 | { |
2349 | { |
2368 | op->statusmsg ("You blindly grab for a bite of food. " |
2350 | op->statusmsg ("You blindly grab for a bite of food. " |
2369 | "H<To prevent you from starving, you ate some random item from your backpack.>"); |
2351 | "H<To prevent you from starving, you ate some random item from your backpack.>"); |
2370 | manual_apply (op, tmp, 0); |
2352 | op->apply (tmp); |
2371 | |
2353 | |
2372 | if (op->stats.food >= 0 || op->stats.hp < 0) |
2354 | if (op->stats.food >= 0 || op->stats.hp < 0) |
2373 | break; |
2355 | break; |
2374 | } |
2356 | } |
2375 | else if (tmp->type == FLESH) |
2357 | else if (tmp->type == FLESH) |
… | |
… | |
2381 | */ |
2363 | */ |
2382 | if (op->stats.food < 0 && op->stats.hp >= 0 && flesh) |
2364 | if (op->stats.food < 0 && op->stats.hp >= 0 && flesh) |
2383 | { |
2365 | { |
2384 | op->statusmsg ("You blindly grab for a bite of food. " |
2366 | op->statusmsg ("You blindly grab for a bite of food. " |
2385 | "H<To prevent you from starving, you ate some random item from your backpack.>"); |
2367 | "H<To prevent you from starving, you ate some random item from your backpack.>"); |
2386 | manual_apply (op, flesh, 0); |
2368 | op->apply (flesh); |
2387 | } |
2369 | } |
2388 | |
2370 | |
2389 | // If player is still starving, alert him! |
2371 | // If player is still starving, alert him! |
2390 | if (op->stats.food < 0) |
2372 | if (op->stats.food < 0) |
2391 | op->failmsg ("You are starving! " |
2373 | op->failmsg ("You are starving! " |
… | |
… | |
2447 | cure_disease (op, 0, 0); /* remove any disease */ |
2429 | cure_disease (op, 0, 0); /* remove any disease */ |
2448 | |
2430 | |
2449 | max_it (op->stats.hp , op->stats.maxhp); |
2431 | max_it (op->stats.hp , op->stats.maxhp); |
2450 | max_it (op->stats.sp , op->stats.maxsp); |
2432 | max_it (op->stats.sp , op->stats.maxsp); |
2451 | max_it (op->stats.grace, op->stats.maxgrace); |
2433 | max_it (op->stats.grace, op->stats.maxgrace); |
2452 | |
|
|
2453 | if (op->stats.food <= 0) |
2434 | max_it (op->stats.food , 200); |
2454 | op->stats.food = 999; |
|
|
2455 | |
2435 | |
2456 | // remove all spell effects that are active |
2436 | // remove all spell effects that are active |
2457 | // to avoid long-term effects such as word-of-recall |
2437 | // to avoid long-term effects such as word-of-recall |
2458 | for (object *item = op->inv; item; ) |
2438 | for (object *item = op->inv; item; ) |
2459 | { |
2439 | { |
… | |
… | |
3198 | else |
3178 | else |
3199 | j = 1; |
3179 | j = 1; |
3200 | strcat (buf, spellpathnames[i]); |
3180 | strcat (buf, spellpathnames[i]); |
3201 | } |
3181 | } |
3202 | } |
3182 | } |
|
|
3183 | |
3203 | strcat (buf, "."); |
3184 | strcat (buf, "."); |
3204 | new_draw_info (NDI_UNIQUE | NDI_BLUE, 0, who, buf); |
3185 | new_draw_info (NDI_UNIQUE | NDI_BLUE, 0, who, buf); |
3205 | } |
3186 | } |
3206 | |
3187 | |
3207 | /* evtl. adding flags: */ |
3188 | /* evtl. adding flags: */ |
… | |
… | |
3223 | new_draw_info_format (NDI_UNIQUE | NDI_BLUE, 0, who, "You gained %s", query_short_name (tmp)); |
3204 | new_draw_info_format (NDI_UNIQUE | NDI_BLUE, 0, who, "You gained %s", query_short_name (tmp)); |
3224 | who->insert (tmp); |
3205 | who->insert (tmp); |
3225 | } |
3206 | } |
3226 | } |
3207 | } |
3227 | |
3208 | |
3228 | /** |
|
|
3229 | * Unready an object for a player. This function does nothing if the object was |
|
|
3230 | * not readied. |
|
|
3231 | */ |
|
|
3232 | void |
|
|
3233 | player_unready_range_ob (player *pl, object *ob) |
|
|
3234 | { |
|
|
3235 | if (pl->ob->current_weapon == ob) |
|
|
3236 | pl->ob->current_weapon = 0; |
|
|
3237 | |
|
|
3238 | if (pl->combat_ob == ob) |
|
|
3239 | pl->combat_ob = 0; |
|
|
3240 | |
|
|
3241 | if (pl->ranged_ob == ob) |
|
|
3242 | pl->ranged_ob = 0; |
|
|
3243 | } |
|
|
3244 | |
|
|
3245 | //-GPL |
3209 | //-GPL |
3246 | |
3210 | |
3247 | sint8 |
3211 | sint8 |
3248 | player::darkness_at (maptile *map, int x, int y) const |
3212 | player::darkness_at (maptile *map, int x, int y) const |
3249 | { |
3213 | { |