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.259 by root, Sun Mar 28 02:53:46 2010 UTC vs.
Revision 1.268 by root, Wed Apr 7 19:54:45 2010 UTC

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
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;
141 ob->flag [FLAG_READY_RANGE] = false; 139 ob->flag [FLAG_READY_RANGE] = false;
142 ob->flag [FLAG_READY_BOW] = false; 140 ob->flag [FLAG_READY_BOW] = false;
143 141
144 for (object *op = ob->inv; op; op = op->below) 142 ob->update_stats (); // we unapplied stuff above
145 if (op->flag [FLAG_APPLIED]) 143 activate ();
146 switch (op->type)
147 {
148 case SKILL:
149 op->flag [FLAG_APPLIED] = false;
150 break;
151
152 case WAND:
153 case ROD:
154 case HORN:
155 case BOW:
156 ranged_ob = op;
157 break;
158
159 case WEAPON:
160 combat_ob = op;
161 break;
162 }
163
164 ob->current_weapon = 0;
165 ob->change_weapon (combat_ob ? combat_ob : ranged_ob);
166 activate (); // change_weapon also activates, but this doesn't hurt
167 144
168 INVOKE_PLAYER (CONNECT, this); 145 INVOKE_PLAYER (CONNECT, this);
169 INVOKE_PLAYER (LOGIN, this); 146 INVOKE_PLAYER (LOGIN, this);
170} 147}
171 148
257 disconnect (); 234 disconnect ();
258 235
259 attachable::do_destroy (); 236 attachable::do_destroy ();
260 237
261 if (ob) 238 if (ob)
262 {
263 ob->destroy_inv (false);
264 ob->destroy (); 239 ob->destroy ();
265 }
266 240
267 ob = observe = viewpoint = 0; 241 ob = observe = viewpoint = 0;
268} 242}
269 243
270player::~player () 244player::~player ()
1585 { 1559 {
1586 LOG (llevError, "Object %s lacks a spell\n", &item->name); 1560 LOG (llevError, "Object %s lacks a spell\n", &item->name);
1587 return; 1561 return;
1588 } 1562 }
1589 1563
1590 if (!op->change_weapon (item)) 1564 if (!op->apply (item))
1591 return; 1565 return;
1592 1566
1593 if (item->type == WAND) 1567 if (item->type == WAND)
1594 { 1568 {
1595 if (item->stats.food <= 0) 1569 if (item->stats.food <= 0)
1646} 1620}
1647 1621
1648/* Received a fire command for the player - go and do it. 1622/* Received a fire command for the player - go and do it.
1649 */ 1623 */
1650bool 1624bool
1651fire (object *op, int dir) 1625fire (object *who, int dir)
1652{ 1626{
1653 int spellcost = 0; 1627 int spellcost = 0;
1654 1628
1655 player *pl = op->contr; 1629 player *pl = who->contr;
1656 1630
1657 if (pl->golem) 1631 if (pl->golem)
1658 { 1632 {
1659 control_golem (op->contr->golem, dir); 1633 control_golem (who->contr->golem, dir);
1660 return false; 1634 return false;
1661 } 1635 }
1662 1636
1663 object *ob = pl->ranged_ob; 1637 object *ob = pl->ranged_ob;
1664 1638
1665 if (!ob) 1639 if (!ob)
1666 return false; 1640 return false;
1667 1641
1668 if (op->speed_left > 0.f) 1642 if (who->speed_left > 0.f)
1669 --op->speed_left; 1643 --who->speed_left;
1670 else 1644 else
1671 return false; 1645 return false;
1672 1646
1673 if (!op->change_weapon (ob)) 1647 if (!who->apply (ob))
1674 return false; 1648 return false;
1675 1649
1676 /* check for loss of invisiblity/hide */ 1650 /* check for loss of invisiblity/hide */
1677 if (action_makes_visible (op)) 1651 if (action_makes_visible (who))
1678 make_visible (op); 1652 make_visible (who);
1679 1653
1680 switch (ob->type) 1654 switch (ob->type)
1681 { 1655 {
1682 case BOW: 1656 case BOW:
1683 player_fire_bow (op, dir); 1657 player_fire_bow (who, dir);
1684 break; 1658 break;
1685 1659
1686 case SPELL: 1660 case SPELL:
1687 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);
1688 break; 1662 break;
1689 1663
1690 case BUILDER: 1664 case BUILDER:
1691 apply_map_builder (op, dir); 1665 apply_map_builder (who, dir);
1692 break; 1666 break;
1693 1667
1694 case SKILL: 1668 case SKILL:
1695 do_skill (op, op, ob, dir, 0); 1669 do_skill (who, who, ob, dir, 0);
1696 break; 1670 break;
1697 1671
1698 case SKILL_TOOL: 1672 case RANGED:
1699 // change_weapon ensures that chosen_skill is uptodate
1700 do_skill (op, op, op->chosen_skill, dir, 0); 1673 do_skill (who, ob, who->chosen_skill, dir, 0);
1701 break; 1674 break;
1702 1675
1703 default: 1676 default:
1704 fire_misc_object (op, dir); 1677 fire_misc_object (who, dir);
1705 break; 1678 break;
1706 } 1679 }
1707 1680
1708 return true; 1681 return true;
1709} 1682}
2132 2105
2133 if (op->stats.hp < 0) 2106 if (op->stats.hp < 0)
2134 op->stats.hp = op->stats.maxhp; 2107 op->stats.hp = op->stats.maxhp;
2135 2108
2136 if (op->stats.food < 0) 2109 if (op->stats.food < 0)
2137 op->stats.food = 999; 2110 op->stats.food = MAX_FOOD;
2138 2111
2139 op->update_stats (); 2112 op->update_stats ();
2140 return 1; 2113 return 1;
2141 } 2114 }
2142 2115
2371 2344
2372 if (tmp->type == FOOD || tmp->type == DRINK || tmp->type == POISON) 2345 if (tmp->type == FOOD || tmp->type == DRINK || tmp->type == POISON)
2373 { 2346 {
2374 op->statusmsg ("You blindly grab for a bite of food. " 2347 op->statusmsg ("You blindly grab for a bite of food. "
2375 "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.>");
2376 manual_apply (op, tmp, 0); 2349 op->apply (tmp);
2377 2350
2378 if (op->stats.food >= 0 || op->stats.hp < 0) 2351 if (op->stats.food >= 0 || op->stats.hp < 0)
2379 break; 2352 break;
2380 } 2353 }
2381 else if (tmp->type == FLESH) 2354 else if (tmp->type == FLESH)
2387 */ 2360 */
2388 if (op->stats.food < 0 && op->stats.hp >= 0 && flesh) 2361 if (op->stats.food < 0 && op->stats.hp >= 0 && flesh)
2389 { 2362 {
2390 op->statusmsg ("You blindly grab for a bite of food. " 2363 op->statusmsg ("You blindly grab for a bite of food. "
2391 "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.>");
2392 manual_apply (op, flesh, 0); 2365 op->apply (flesh);
2393 } 2366 }
2394 2367
2395 // If player is still starving, alert him! 2368 // If player is still starving, alert him!
2396 if (op->stats.food < 0) 2369 if (op->stats.food < 0)
2397 op->failmsg ("You are starving! " 2370 op->failmsg ("You are starving! "
2453 cure_disease (op, 0, 0); /* remove any disease */ 2426 cure_disease (op, 0, 0); /* remove any disease */
2454 2427
2455 max_it (op->stats.hp , op->stats.maxhp); 2428 max_it (op->stats.hp , op->stats.maxhp);
2456 max_it (op->stats.sp , op->stats.maxsp); 2429 max_it (op->stats.sp , op->stats.maxsp);
2457 max_it (op->stats.grace, op->stats.maxgrace); 2430 max_it (op->stats.grace, op->stats.maxgrace);
2458
2459 if (op->stats.food <= 0) 2431 max_it (op->stats.food , 200);
2460 op->stats.food = 999;
2461 2432
2462 // remove all spell effects that are active 2433 // remove all spell effects that are active
2463 // to avoid long-term effects such as word-of-recall 2434 // to avoid long-term effects such as word-of-recall
2464 for (object *item = op->inv; item; ) 2435 for (object *item = op->inv; item; )
2465 { 2436 {
3204 else 3175 else
3205 j = 1; 3176 j = 1;
3206 strcat (buf, spellpathnames[i]); 3177 strcat (buf, spellpathnames[i]);
3207 } 3178 }
3208 } 3179 }
3180
3209 strcat (buf, "."); 3181 strcat (buf, ".");
3210 new_draw_info (NDI_UNIQUE | NDI_BLUE, 0, who, buf); 3182 new_draw_info (NDI_UNIQUE | NDI_BLUE, 0, who, buf);
3211 } 3183 }
3212 3184
3213 /* evtl. adding flags: */ 3185 /* evtl. adding flags: */
3229 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));
3230 who->insert (tmp); 3202 who->insert (tmp);
3231 } 3203 }
3232} 3204}
3233 3205
3234/**
3235 * Unready an object for a player. This function does nothing if the object was
3236 * not readied.
3237 */
3238void
3239player_unready_range_ob (player *pl, object *ob)
3240{
3241 if (pl->ob->current_weapon == ob)
3242 pl->ob->change_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 3206//-GPL
3252 3207
3253sint8 3208sint8
3254player::darkness_at (maptile *map, int x, int y) const 3209player::darkness_at (maptile *map, int x, int y) const
3255{ 3210{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines