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.255 by root, Fri Mar 26 00:53:26 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 ()
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}
2126 2105
2127 if (op->stats.hp < 0) 2106 if (op->stats.hp < 0)
2128 op->stats.hp = op->stats.maxhp; 2107 op->stats.hp = op->stats.maxhp;
2129 2108
2130 if (op->stats.food < 0) 2109 if (op->stats.food < 0)
2131 op->stats.food = 999; 2110 op->stats.food = MAX_FOOD;
2132 2111
2133 op->update_stats (); 2112 op->update_stats ();
2134 return 1; 2113 return 1;
2135 } 2114 }
2136 2115
2365 2344
2366 if (tmp->type == FOOD || tmp->type == DRINK || tmp->type == POISON) 2345 if (tmp->type == FOOD || tmp->type == DRINK || tmp->type == POISON)
2367 { 2346 {
2368 op->statusmsg ("You blindly grab for a bite of food. " 2347 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.>"); 2348 "H<To prevent you from starving, you ate some random item from your backpack.>");
2370 manual_apply (op, tmp, 0); 2349 op->apply (tmp);
2371 2350
2372 if (op->stats.food >= 0 || op->stats.hp < 0) 2351 if (op->stats.food >= 0 || op->stats.hp < 0)
2373 break; 2352 break;
2374 } 2353 }
2375 else if (tmp->type == FLESH) 2354 else if (tmp->type == FLESH)
2381 */ 2360 */
2382 if (op->stats.food < 0 && op->stats.hp >= 0 && flesh) 2361 if (op->stats.food < 0 && op->stats.hp >= 0 && flesh)
2383 { 2362 {
2384 op->statusmsg ("You blindly grab for a bite of food. " 2363 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.>"); 2364 "H<To prevent you from starving, you ate some random item from your backpack.>");
2386 manual_apply (op, flesh, 0); 2365 op->apply (flesh);
2387 } 2366 }
2388 2367
2389 // If player is still starving, alert him! 2368 // If player is still starving, alert him!
2390 if (op->stats.food < 0) 2369 if (op->stats.food < 0)
2391 op->failmsg ("You are starving! " 2370 op->failmsg ("You are starving! "
2447 cure_disease (op, 0, 0); /* remove any disease */ 2426 cure_disease (op, 0, 0); /* remove any disease */
2448 2427
2449 max_it (op->stats.hp , op->stats.maxhp); 2428 max_it (op->stats.hp , op->stats.maxhp);
2450 max_it (op->stats.sp , op->stats.maxsp); 2429 max_it (op->stats.sp , op->stats.maxsp);
2451 max_it (op->stats.grace, op->stats.maxgrace); 2430 max_it (op->stats.grace, op->stats.maxgrace);
2452
2453 if (op->stats.food <= 0) 2431 max_it (op->stats.food , 200);
2454 op->stats.food = 999;
2455 2432
2456 // remove all spell effects that are active 2433 // remove all spell effects that are active
2457 // to avoid long-term effects such as word-of-recall 2434 // to avoid long-term effects such as word-of-recall
2458 for (object *item = op->inv; item; ) 2435 for (object *item = op->inv; item; )
2459 { 2436 {
3198 else 3175 else
3199 j = 1; 3176 j = 1;
3200 strcat (buf, spellpathnames[i]); 3177 strcat (buf, spellpathnames[i]);
3201 } 3178 }
3202 } 3179 }
3180
3203 strcat (buf, "."); 3181 strcat (buf, ".");
3204 new_draw_info (NDI_UNIQUE | NDI_BLUE, 0, who, buf); 3182 new_draw_info (NDI_UNIQUE | NDI_BLUE, 0, who, buf);
3205 } 3183 }
3206 3184
3207 /* evtl. adding flags: */ 3185 /* evtl. adding flags: */
3223 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));
3224 who->insert (tmp); 3202 who->insert (tmp);
3225 } 3203 }
3226} 3204}
3227 3205
3228/**
3229 * Unready an object for a player. This function does nothing if the object was
3230 * not readied.
3231 */
3232void
3233player_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 3206//-GPL
3246 3207
3247sint8 3208sint8
3248player::darkness_at (maptile *map, int x, int y) const 3209player::darkness_at (maptile *map, int x, int y) const
3249{ 3210{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines