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.234 by root, Thu Oct 15 21:40:42 2009 UTC vs.
Revision 1.237 by root, Thu Nov 5 15:18:26 2009 UTC

161 ns->reset_stats (); 161 ns->reset_stats ();
162 ns->pl = 0; 162 ns->pl = 0;
163 ns = 0; 163 ns = 0;
164 } 164 }
165 165
166 observe = ob; 166 // this is important for the player scheduler to get the correct refcount
167 // when ns = 0
168 observe = viewpoint = ob;
167 169
168 deactivate (); 170 deactivate ();
169} 171}
170 172
171// the need for this function can be explained 173// the need for this function can be explained
172// by load_object not returning the object 174// by load_object not returning the object
173void 175void
174player::set_object (object *op) 176player::set_object (object *op)
175{ 177{
176 ob = observe = op; 178 ob = observe = viewpoint = op;
177 ob->contr = this; /* this aren't yet in archetype */ 179 ob->contr = this; /* this aren't yet in archetype */
178 180
179 ob->speed = 1.0f; 181 ob->speed = 1.0f;
180 ob->speed_left = 0.5f; 182 ob->speed_left = 0.5f;
181 183
210} 212}
211 213
212void 214void
213player::set_observe (object *op) 215player::set_observe (object *op)
214{ 216{
215 observe = op ? op : ob; 217 observe = viewpoint = op ? op : ob;
218 do_los = 1;
219}
220
221void
222player::set_viewpoint (object *op)
223{
224 viewpoint = op ? op : (object *)observe;
216 do_los = 1; 225 do_los = 1;
217} 226}
218 227
219player::player () 228player::player ()
220{ 229{
249 { 258 {
250 ob->destroy_inv (false); 259 ob->destroy_inv (false);
251 ob->destroy (); 260 ob->destroy ();
252 } 261 }
253 262
254 ob = observe = 0; 263 ob = observe = viewpoint = 0;
255} 264}
256 265
257player::~player () 266player::~player ()
258{ 267{
259 /* Clear item stack */ 268 /* Clear item stack */
1646 } 1655 }
1647 1656
1648 return true; 1657 return true;
1649} 1658}
1650 1659
1651/* find_key 1660static object *
1652 * We try to find a key for the door as passed. If we find a key
1653 * and successfully use it, we return the key, otherwise NULL
1654 * This function merges both normal and locked door, since the logic
1655 * for both is the same - just the specific key is different.
1656 * pl is the player,
1657 * inv is the objects inventory to searched
1658 * door is the door we are trying to match against.
1659 * This function can be called recursively to search containers.
1660 */
1661object *
1662find_key (object *pl, object *container, object *door) 1661find_key_ (object *pl, object *container, object *door)
1663{ 1662{
1664 object *tmp, *key; 1663 object *tmp, *key;
1665 1664
1666 /* Should not happen, but sanity checking is never bad */ 1665 /* Should not happen, but sanity checking is never bad */
1667 if (!container->inv) 1666 if (!container->inv)
1688 if (!tmp) 1687 if (!tmp)
1689 { 1688 {
1690 for (tmp = container->inv; tmp; tmp = tmp->below) 1689 for (tmp = container->inv; tmp; tmp = tmp->below)
1691 /* No reason to search empty containers */ 1690 /* No reason to search empty containers */
1692 if (tmp->type == CONTAINER && tmp->inv) 1691 if (tmp->type == CONTAINER && tmp->inv)
1693 if ((key = find_key (pl, tmp, door))) 1692 if ((key = find_key_ (pl, tmp, door)))
1694 return key; 1693 return key;
1695 1694
1696 if (!tmp) 1695 if (!tmp)
1697 return 0; 1696 return 0;
1698 } 1697 }
1717 * inv must have been an container and must have been active. 1716 * inv must have been an container and must have been active.
1718 * 1717 *
1719 * Change the color so that the message doesn't disappear with 1718 * Change the color so that the message doesn't disappear with
1720 * all the others. 1719 * all the others.
1721 */ 1720 */
1722 if (pl->contr->usekeys == key_inventory || 1721 if (pl->contr->usekeys == key_inventory
1723 !QUERY_FLAG (container, FLAG_APPLIED) || 1722 || !QUERY_FLAG (container, FLAG_APPLIED)
1724 (pl->contr->usekeys == keyrings && container->race != shstr_keys)) 1723 || (pl->contr->usekeys == keyrings && container->race != shstr_keys))
1725 { 1724 {
1726 new_draw_info_format (NDI_UNIQUE | NDI_BROWN, 0, pl, 1725 new_draw_info_format (NDI_UNIQUE | NDI_BROWN, 0, pl,
1727 "The %s in your %s vibrates as you approach the door", query_name (tmp), query_name (container)); 1726 "The %s in your %s vibrates as you approach the door", query_name (tmp), query_name (container));
1728 return NULL; 1727 return NULL;
1729 } 1728 }
1730 } 1729 }
1731 1730
1732 return tmp; 1731 return tmp;
1732}
1733
1734/* find_key
1735 * We try to find a key for the door as passed. If we find a key
1736 * and successfully use it, we return the key, otherwise NULL
1737 * This function merges both normal and locked door, since the logic
1738 * for both is the same - just the specific key is different.
1739 * pl is the player,
1740 * inv is the objects inventory to searched
1741 * door is the door we are trying to match against.
1742 * This function can be called recursively to search containers.
1743 */
1744object *
1745find_key (object *pl, object *container, object *door)
1746{
1747 if (door->slaying && is_match_expr (door->slaying))
1748 {
1749 // for match expressions, we try to find the key by applying the match
1750 // to the op itself, which is supposed to find the "key", instead
1751 // of searching through containers ourselves.
1752
1753 return match_one (door->slaying, container, door, pl, pl);
1754 }
1755 else
1756 return find_key_ (pl, container, door);
1733} 1757}
1734 1758
1735/* moved door processing out of move_player_attack. 1759/* moved door processing out of move_player_attack.
1736 * returns 1 if player has opened the door with a key 1760 * returns 1 if player has opened the door with a key
1737 * such that the caller should not do anything more, 1761 * such that the caller should not do anything more,

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines