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.252 by root, Wed Mar 24 17:23:43 2010 UTC vs.
Revision 1.268 by root, Wed Apr 7 19:54:45 2010 UTC

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
256 disconnect (); 234 disconnect ();
257 235
258 attachable::do_destroy (); 236 attachable::do_destroy ();
259 237
260 if (ob) 238 if (ob)
261 {
262 ob->destroy_inv (false);
263 ob->destroy (); 239 ob->destroy ();
264 }
265 240
266 ob = observe = viewpoint = 0; 241 ob = observe = viewpoint = 0;
267} 242}
268 243
269player::~player () 244player::~player ()
838 dir = absdir (4 + rv.direction); 813 dir = absdir (4 + rv.direction);
839 for (diff = 0; diff < 3; diff++) 814 for (diff = 0; diff < 3; diff++)
840 { 815 {
841 int m = 1 - rndm (2) * 2; 816 int m = 1 - rndm (2) * 2;
842 817
843 if (move_ob (op, absdir (dir + diff * m), op) || (diff == 0 && move_ob (op, absdir (dir - diff * m), op))) 818 if (op->move (absdir (dir + diff * m)) || (diff == 0 && op->move (absdir (dir - diff * m))))
844 return; 819 return;
845 } 820 }
846 821
847 /* Cornered, get rid of scared */ 822 /* Cornered, get rid of scared */
848 CLEAR_FLAG (op, FLAG_SCARED); 823 CLEAR_FLAG (op, FLAG_SCARED);
858{ 833{
859 object *tmp, *next; 834 object *tmp, *next;
860 int stop = 0; 835 int stop = 0;
861 int wvratio; 836 int wvratio;
862 837
863 /* if you're flying, you cna't pick up anything */ 838 /* if you're flying, you can't pick up anything */
864 if (op->move_type & MOVE_FLYING) 839 if (op->move_type & MOVE_FLYING)
865 return 1; 840 return 1;
866 841
867 next = op->below; 842 next = op->below;
868 843
1584 { 1559 {
1585 LOG (llevError, "Object %s lacks a spell\n", &item->name); 1560 LOG (llevError, "Object %s lacks a spell\n", &item->name);
1586 return; 1561 return;
1587 } 1562 }
1588 1563
1589 if (!op->change_weapon (item)) 1564 if (!op->apply (item))
1590 return; 1565 return;
1591 1566
1592 if (item->type == WAND) 1567 if (item->type == WAND)
1593 { 1568 {
1594 if (item->stats.food <= 0) 1569 if (item->stats.food <= 0)
1645} 1620}
1646 1621
1647/* Received a fire command for the player - go and do it. 1622/* Received a fire command for the player - go and do it.
1648 */ 1623 */
1649bool 1624bool
1650fire (object *op, int dir) 1625fire (object *who, int dir)
1651{ 1626{
1652 int spellcost = 0; 1627 int spellcost = 0;
1653 1628
1654 player *pl = op->contr; 1629 player *pl = who->contr;
1655 1630
1656 if (pl->golem) 1631 if (pl->golem)
1657 { 1632 {
1658 control_golem (op->contr->golem, dir); 1633 control_golem (who->contr->golem, dir);
1659 return false; 1634 return false;
1660 } 1635 }
1661 1636
1662 object *ob = pl->ranged_ob; 1637 object *ob = pl->ranged_ob;
1663 1638
1664 if (!ob) 1639 if (!ob)
1665 return false; 1640 return false;
1666 1641
1667 if (op->speed_left > 0.f) 1642 if (who->speed_left > 0.f)
1668 --op->speed_left; 1643 --who->speed_left;
1669 else 1644 else
1670 return false; 1645 return false;
1671 1646
1672 if (!op->change_weapon (ob)) 1647 if (!who->apply (ob))
1673 return false; 1648 return false;
1674 1649
1675 /* check for loss of invisiblity/hide */ 1650 /* check for loss of invisiblity/hide */
1676 if (action_makes_visible (op)) 1651 if (action_makes_visible (who))
1677 make_visible (op); 1652 make_visible (who);
1678 1653
1679 switch (ob->type) 1654 switch (ob->type)
1680 { 1655 {
1681 case BOW: 1656 case BOW:
1682 player_fire_bow (op, dir); 1657 player_fire_bow (who, dir);
1683 break; 1658 break;
1684 1659
1685 case SPELL: 1660 case SPELL:
1686 spellcost = cast_spell (op, op, dir, ob, *pl->spellparam ? pl->spellparam : 0); 1661 spellcost = cast_spell (who, who, dir, ob, *pl->spellparam ? pl->spellparam : 0);
1687 break; 1662 break;
1688 1663
1689 case BUILDER: 1664 case BUILDER:
1690 apply_map_builder (op, dir); 1665 apply_map_builder (who, dir);
1691 break; 1666 break;
1692 1667
1693 case SKILL: 1668 case SKILL:
1694 do_skill (op, op, ob, dir, 0); 1669 do_skill (who, who, ob, dir, 0);
1695 break; 1670 break;
1696 1671
1672 case RANGED:
1673 do_skill (who, ob, who->chosen_skill, dir, 0);
1674 break;
1675
1697 default: 1676 default:
1698 fire_misc_object (op, dir); 1677 fire_misc_object (who, dir);
1699 break; 1678 break;
1700 } 1679 }
1701 1680
1702 return true; 1681 return true;
1703} 1682}
1856 * going to try and move (not fire weapons). 1835 * going to try and move (not fire weapons).
1857 */ 1836 */
1858bool 1837bool
1859move_player_attack (object *op, int dir) 1838move_player_attack (object *op, int dir)
1860{ 1839{
1861 if (!op->contr->braced && op->speed_left > 0.f && move_ob (op, dir, op)) 1840 if (!op->contr->braced && op->speed_left > 0.f && op->move (dir))
1862 { 1841 {
1863 --op->speed_left; 1842 --op->speed_left;
1864 return true; 1843 return true;
1865 } 1844 }
1866 1845
1867 int on_battleground;
1868
1869 sint16 nx = freearr_x[dir] + op->x; 1846 sint16 nx = freearr_x[dir] + op->x;
1870 sint16 ny = freearr_y[dir] + op->y; 1847 sint16 ny = freearr_y[dir] + op->y;
1871
1872 on_battleground = op_on_battleground (op, 0, 0);
1873 1848
1874 if (out_of_map (op->map, nx, ny)) 1849 if (out_of_map (op->map, nx, ny))
1875 return false; 1850 return false;
1876 1851
1877 /* If braced, or can't move to the square, and it is not out of the 1852 /* If braced, or can't move to the square, and it is not out of the
1949 } 1924 }
1950 else 1925 else
1951 return false; 1926 return false;
1952 } 1927 }
1953 1928
1929 bool on_battleground = op_on_battleground (op, 0, 0);
1930
1954 /* in certain circumstances, you shouldn't attack friendly 1931 /* in certain circumstances, you shouldn't attack friendly
1955 * creatures. Note that if you are braced, you can't push 1932 * creatures. Note that if you are braced, you can't push
1956 * someone, but put it inside this loop so that you won't 1933 * someone, but put it inside this loop so that you won't
1957 * attack them either. 1934 * attack them either.
1958 */ 1935 */
2026{ 2003{
2027 if (!op->map || op->map->in_memory != MAP_ACTIVE) 2004 if (!op->map || op->map->in_memory != MAP_ACTIVE)
2028 return 0; 2005 return 0;
2029 2006
2030 /* Sanity check: make sure dir is valid */ 2007 /* Sanity check: make sure dir is valid */
2031 if ((dir < 0) || (dir >= 9)) 2008 if (dir < 0 || dir >= 9)
2032 { 2009 {
2033 LOG (llevError, "move_player: invalid direction %d\n", dir); 2010 LOG (llevError, "move_player: invalid direction %d\n", dir);
2034 return 0; 2011 return 0;
2035 } 2012 }
2036 2013
2128 2105
2129 if (op->stats.hp < 0) 2106 if (op->stats.hp < 0)
2130 op->stats.hp = op->stats.maxhp; 2107 op->stats.hp = op->stats.maxhp;
2131 2108
2132 if (op->stats.food < 0) 2109 if (op->stats.food < 0)
2133 op->stats.food = 999; 2110 op->stats.food = MAX_FOOD;
2134 2111
2135 op->update_stats (); 2112 op->update_stats ();
2136 return 1; 2113 return 1;
2137 } 2114 }
2138 2115
2367 2344
2368 if (tmp->type == FOOD || tmp->type == DRINK || tmp->type == POISON) 2345 if (tmp->type == FOOD || tmp->type == DRINK || tmp->type == POISON)
2369 { 2346 {
2370 op->statusmsg ("You blindly grab for a bite of food. " 2347 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.>"); 2348 "H<To prevent you from starving, you ate some random item from your backpack.>");
2372 manual_apply (op, tmp, 0); 2349 op->apply (tmp);
2373 2350
2374 if (op->stats.food >= 0 || op->stats.hp < 0) 2351 if (op->stats.food >= 0 || op->stats.hp < 0)
2375 break; 2352 break;
2376 } 2353 }
2377 else if (tmp->type == FLESH) 2354 else if (tmp->type == FLESH)
2383 */ 2360 */
2384 if (op->stats.food < 0 && op->stats.hp >= 0 && flesh) 2361 if (op->stats.food < 0 && op->stats.hp >= 0 && flesh)
2385 { 2362 {
2386 op->statusmsg ("You blindly grab for a bite of food. " 2363 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.>"); 2364 "H<To prevent you from starving, you ate some random item from your backpack.>");
2388 manual_apply (op, flesh, 0); 2365 op->apply (flesh);
2389 } 2366 }
2390 2367
2391 // If player is still starving, alert him! 2368 // If player is still starving, alert him!
2392 if (op->stats.food < 0) 2369 if (op->stats.food < 0)
2393 op->failmsg ("You are starving! " 2370 op->failmsg ("You are starving! "
2449 cure_disease (op, 0, 0); /* remove any disease */ 2426 cure_disease (op, 0, 0); /* remove any disease */
2450 2427
2451 max_it (op->stats.hp , op->stats.maxhp); 2428 max_it (op->stats.hp , op->stats.maxhp);
2452 max_it (op->stats.sp , op->stats.maxsp); 2429 max_it (op->stats.sp , op->stats.maxsp);
2453 max_it (op->stats.grace, op->stats.maxgrace); 2430 max_it (op->stats.grace, op->stats.maxgrace);
2454
2455 if (op->stats.food <= 0) 2431 max_it (op->stats.food , 200);
2456 op->stats.food = 999;
2457 2432
2458 // remove all spell effects that are active 2433 // remove all spell effects that are active
2459 // to avoid long-term effects such as word-of-recall 2434 // to avoid long-term effects such as word-of-recall
2460 for (object *item = op->inv; item; ) 2435 for (object *item = op->inv; item; )
2461 { 2436 {
3200 else 3175 else
3201 j = 1; 3176 j = 1;
3202 strcat (buf, spellpathnames[i]); 3177 strcat (buf, spellpathnames[i]);
3203 } 3178 }
3204 } 3179 }
3180
3205 strcat (buf, "."); 3181 strcat (buf, ".");
3206 new_draw_info (NDI_UNIQUE | NDI_BLUE, 0, who, buf); 3182 new_draw_info (NDI_UNIQUE | NDI_BLUE, 0, who, buf);
3207 } 3183 }
3208 3184
3209 /* evtl. adding flags: */ 3185 /* evtl. adding flags: */
3225 new_draw_info_format (NDI_UNIQUE | NDI_BLUE, 0, who, "You gained %s", query_short_name (tmp)); 3201 new_draw_info_format (NDI_UNIQUE | NDI_BLUE, 0, who, "You gained %s", query_short_name (tmp));
3226 who->insert (tmp); 3202 who->insert (tmp);
3227 } 3203 }
3228} 3204}
3229 3205
3230/**
3231 * Unready an object for a player. This function does nothing if the object was
3232 * not readied.
3233 */
3234void
3235player_unready_range_ob (player *pl, object *ob)
3236{
3237 if (pl->ob->current_weapon == ob)
3238 pl->ob->current_weapon = 0;
3239
3240 if (pl->combat_ob == ob)
3241 pl->combat_ob = 0;
3242
3243 if (pl->ranged_ob == ob)
3244 pl->ranged_ob = 0;
3245}
3246
3247//-GPL 3206//-GPL
3248 3207
3249sint8 3208sint8
3250player::darkness_at (maptile *map, int x, int y) const 3209player::darkness_at (maptile *map, int x, int y) const
3251{ 3210{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines