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.102 by root, Wed Feb 7 02:04:47 2007 UTC vs.
Revision 1.103 by root, Sat Feb 10 01:52:29 2007 UTC

214 this->ns = ns; 214 this->ns = ns;
215 ns->pl = this; 215 ns->pl = this;
216 216
217 run_on = 0; 217 run_on = 0;
218 fire_on = 0; 218 fire_on = 0;
219 ob->container = 0; //TODO: client-specific 219 ob->close_container (); //TODO: client-specific
220 220
221 ns->update_look = 0; 221 ns->update_look = 0;
222 ns->look_position = 0; 222 ns->look_position = 0;
223 223
224 clear_los (ob); 224 clear_los (ob);
300 ns->reset_stats (); 300 ns->reset_stats ();
301 ns->pl = 0; 301 ns->pl = 0;
302 this->ns = 0; 302 this->ns = 0;
303 } 303 }
304 304
305 ob->container = 0; //TODO: client-specific 305 ob->close_container (); //TODO: client-specific
306 deactivate (); 306 deactivate ();
307} 307}
308 308
309// the need for this function can be explained 309// the need for this function can be explained
310// by load_object not returning the object 310// by load_object not returning the object
1384 * found object is returned. 1384 * found object is returned.
1385 */ 1385 */
1386object * 1386object *
1387find_arrow (object *op, const char *type) 1387find_arrow (object *op, const char *type)
1388{ 1388{
1389 object *tmp = NULL; 1389 object *tmp = 0;
1390 1390
1391 for (op = op->inv; op; op = op->below) 1391 for (op = op->inv; op; op = op->below)
1392 if (!tmp && op->type == CONTAINER && op->race == type && QUERY_FLAG (op, FLAG_APPLIED)) 1392 if (!tmp && op->type == CONTAINER && op->race == type && QUERY_FLAG (op, FLAG_APPLIED))
1393 tmp = find_arrow (op, type); 1393 tmp = find_arrow (op, type);
1394 else if (op->type == ARROW && op->race == type) 1394 else if (op->type == ARROW && op->race == type)
1395 return op; 1395 return op;
1396
1396 return tmp; 1397 return tmp;
1397} 1398}
1398 1399
1399/* 1400/*
1400 * Similar to find_arrow, but looks for (roughly) the best arrow to use 1401 * Similar to find_arrow, but looks for (roughly) the best arrow to use
1401 * against the target. A full test is not performed, simply a basic test 1402 * against the target. A full test is not performed, simply a basic test
1402 * of resistances. The archer is making a quick guess at what he sees down 1403 * of resistances. The archer is making a quick guess at what he sees down
1403 * the hall. Failing that it does it's best to pick the highest plus arrow. 1404 * the hall. Failing that it does it's best to pick the highest plus arrow.
1404 */ 1405 */
1405
1406object * 1406object *
1407find_better_arrow (object *op, object *target, const char *type, int *better) 1407find_better_arrow (object *op, object *target, const char *type, int *better)
1408{ 1408{
1409 object *tmp = NULL, *arrow, *ntmp; 1409 object *tmp = NULL, *arrow, *ntmp;
1410 int attacknum, attacktype, betterby = 0, i; 1410 int attacknum, attacktype, betterby = 0, i;
1870 new_draw_info (NDI_UNIQUE, 0, op, "Illegal shoot type."); 1870 new_draw_info (NDI_UNIQUE, 0, op, "Illegal shoot type.");
1871 return; 1871 return;
1872 } 1872 }
1873} 1873}
1874 1874
1875
1876
1877/* find_key 1875/* find_key
1878 * We try to find a key for the door as passed. If we find a key 1876 * We try to find a key for the door as passed. If we find a key
1879 * and successfully use it, we return the key, otherwise NULL 1877 * and successfully use it, we return the key, otherwise NULL
1880 * This function merges both normal and locked door, since the logic 1878 * This function merges both normal and locked door, since the logic
1881 * for both is the same - just the specific key is different. 1879 * for both is the same - just the specific key is different.
1882 * pl is the player, 1880 * pl is the player,
1883 * inv is the objects inventory to searched 1881 * inv is the objects inventory to searched
1884 * door is the door we are trying to match against. 1882 * door is the door we are trying to match against.
1885 * This function can be called recursively to search containers. 1883 * This function can be called recursively to search containers.
1886 */ 1884 */
1887
1888object * 1885object *
1889find_key (object *pl, object *container, object *door) 1886find_key (object *pl, object *container, object *door)
1890{ 1887{
1891 object *tmp, *key; 1888 object *tmp, *key;
1892 1889
1893 /* Should not happen, but sanity checking is never bad */ 1890 /* Should not happen, but sanity checking is never bad */
1894 if (container->inv == NULL) 1891 if (!container->inv)
1895 return NULL; 1892 return 0;
1896 1893
1897 /* First, lets try to find a key in the top level inventory */ 1894 /* First, lets try to find a key in the top level inventory */
1898 for (tmp = container->inv; tmp != NULL; tmp = tmp->below) 1895 for (tmp = container->inv; tmp; tmp = tmp->below)
1899 { 1896 {
1900 if (door->type == DOOR && tmp->type == KEY) 1897 if (door->type == DOOR && tmp->type == KEY)
1901 break; 1898 break;
1902 /* For sanity, we should really check door type, but other stuff 1899 /* For sanity, we should really check door type, but other stuff
1903 * (like containers) can be locked with special keys 1900 * (like containers) can be locked with special keys
1904 */ 1901 */
1905 if (tmp->slaying && tmp->type == SPECIAL_KEY && tmp->slaying == door->slaying) 1902 if (tmp->slaying && tmp->type == SPECIAL_KEY && tmp->slaying == door->slaying)
1906 break; 1903 break;
1907 } 1904 }
1905
1908 /* No key found - lets search inventories now */ 1906 /* No key found - lets search inventories now */
1909 /* If we find and use a key in an inventory, return at that time. 1907 /* If we find and use a key in an inventory, return at that time.
1910 * otherwise, if we search all the inventories and still don't find 1908 * otherwise, if we search all the inventories and still don't find
1911 * a key, return 1909 * a key, return
1912 */ 1910 */
1913 if (!tmp) 1911 if (!tmp)
1914 { 1912 {
1915 for (tmp = container->inv; tmp != NULL; tmp = tmp->below) 1913 for (tmp = container->inv; tmp; tmp = tmp->below)
1916 { 1914 {
1917 /* No reason to search empty containers */ 1915 /* No reason to search empty containers */
1918 if (tmp->type == CONTAINER && tmp->inv) 1916 if (tmp->type == CONTAINER && tmp->inv)
1919 { 1917 {
1920 if ((key = find_key (pl, tmp, door)) != NULL) 1918 if ((key = find_key (pl, tmp, door)))
1921 return key; 1919 return key;
1922 } 1920 }
1923 } 1921 }
1922
1924 if (!tmp) 1923 if (!tmp)
1925 return NULL; 1924 return NULL;
1926 } 1925 }
1926
1927 /* We get down here if we have found a key. Now if its in a container, 1927 /* We get down here if we have found a key. Now if its in a container,
1928 * see if we actually want to use it 1928 * see if we actually want to use it
1929 */ 1929 */
1930 if (pl != container) 1930 if (pl != container)
1931 { 1931 {
1952 new_draw_info_format (NDI_UNIQUE | NDI_BROWN, 0, pl, 1952 new_draw_info_format (NDI_UNIQUE | NDI_BROWN, 0, pl,
1953 "The %s in your %s vibrates as you approach the door", query_name (tmp), query_name (container)); 1953 "The %s in your %s vibrates as you approach the door", query_name (tmp), query_name (container));
1954 return NULL; 1954 return NULL;
1955 } 1955 }
1956 } 1956 }
1957
1957 return tmp; 1958 return tmp;
1958} 1959}
1959 1960
1960/* moved door processing out of move_player_attack. 1961/* moved door processing out of move_player_attack.
1961 * returns 1 if player has opened the door with a key 1962 * returns 1 if player has opened the door with a key
1979 play_sound_map (op->map, op->x, op->y, SOUND_OPEN_DOOR); 1980 play_sound_map (op->map, op->x, op->y, SOUND_OPEN_DOOR);
1980 if (action_makes_visible (op)) 1981 if (action_makes_visible (op))
1981 make_visible (op); 1982 make_visible (op);
1982 if (door->inv && (door->inv->type == RUNE || door->inv->type == TRAP)) 1983 if (door->inv && (door->inv->type == RUNE || door->inv->type == TRAP))
1983 spring_trap (door->inv, op); 1984 spring_trap (door->inv, op);
1985
1984 if (door->type == DOOR) 1986 if (door->type == DOOR)
1985 {
1986 hit_player (door, 9998, op, AT_PHYSICAL, 1); /* Break through the door */ 1987 hit_player (door, 9998, op, AT_PHYSICAL, 1); /* Break through the door */
1987 }
1988 else if (door->type == LOCKED_DOOR) 1988 else if (door->type == LOCKED_DOOR)
1989 { 1989 {
1990 new_draw_info_format (NDI_UNIQUE, NDI_BROWN, op, "You open the door with the %s", query_short_name (key)); 1990 new_draw_info_format (NDI_UNIQUE, NDI_BROWN, op, "You open the door with the %s", query_short_name (key));
1991 remove_door2 (door); /* remove door without violence ;-) */ 1991 remove_door2 (door); /* remove door without violence ;-) */
1992 } 1992 }
1993
1993 /* Do this after we print the message */ 1994 /* Do this after we print the message */
1994 decrease_ob (key); /* Use up one of the keys */ 1995 decrease_ob (key); /* Use up one of the keys */
1995 /* Need to update the weight the container the key was in */ 1996 /* Need to update the weight the container the key was in */
1996 if (container != op) 1997 if (container != op)
1997 esrv_update_item (UPD_WEIGHT, op, container); 1998 esrv_update_item (UPD_WEIGHT, op, container);
1999
1998 return 1; /* Nothing more to do below */ 2000 return 1; /* Nothing more to do below */
1999 } 2001 }
2000 else if (door->type == LOCKED_DOOR) 2002 else if (door->type == LOCKED_DOOR)
2001 { 2003 {
2002 /* Might as well return now - no other way to open this */ 2004 /* Might as well return now - no other way to open this */
2003 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, door->msg); 2005 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, door->msg);
2004 return 1; 2006 return 1;
2005 } 2007 }
2008
2006 return 0; 2009 return 0;
2007} 2010}
2008 2011
2009/* This function is just part of a breakup from move_player. 2012/* This function is just part of a breakup from move_player.
2010 * It should keep the code cleaner. 2013 * It should keep the code cleaner.
2367 * from. 2370 * from.
2368 */ 2371 */
2369void 2372void
2370remove_unpaid_objects (object *op, object *env) 2373remove_unpaid_objects (object *op, object *env)
2371{ 2374{
2372 object *next;
2373
2374 while (op) 2375 while (op)
2375 { 2376 {
2376 object *next = op->below; /* Make sure we have a good value, in case we remove object 'op' */ 2377 object *next = op->below; /* Make sure we have a good value, in case we remove object 'op' */
2377 2378
2378 if (QUERY_FLAG (op, FLAG_UNPAID)) 2379 if (QUERY_FLAG (op, FLAG_UNPAID))
2971void 2972void
2972loot_object (object *op) 2973loot_object (object *op)
2973{ /* Grab and destroy some treasure */ 2974{ /* Grab and destroy some treasure */
2974 object *tmp, *tmp2, *next; 2975 object *tmp, *tmp2, *next;
2975 2976
2976 if (op->container) 2977 op->close_container (); /* close open sack first */
2977 esrv_apply_container (op, op->container); /* close open sack first */
2978 2978
2979 for (tmp = op->inv; tmp; tmp = next) 2979 for (tmp = op->inv; tmp; tmp = next)
2980 { 2980 {
2981 next = tmp->below; 2981 next = tmp->below;
2982 2982
2983 if (tmp->invisible) 2983 if (tmp->invisible)
2984 continue; 2984 continue;
2985 2985
2986 tmp->remove (); 2986 tmp->remove ();
2987 tmp->x = op->x, tmp->y = op->y; 2987 tmp->x = op->x, tmp->y = op->y;
2988
2988 if (tmp->type == CONTAINER) 2989 if (tmp->type == CONTAINER)
2989 { /* empty container to ground */ 2990 loot_object (tmp); /* empty container to ground */
2990 loot_object (tmp); 2991
2991 }
2992 if (!QUERY_FLAG (tmp, FLAG_UNIQUE) && (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || QUERY_FLAG (tmp, FLAG_NO_DROP) || !(rndm (3)))) 2992 if (!QUERY_FLAG (tmp, FLAG_UNIQUE) && (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || QUERY_FLAG (tmp, FLAG_NO_DROP) || !(rndm (3))))
2993 { 2993 {
2994 if (tmp->nrof > 1) 2994 if (tmp->nrof > 1)
2995 { 2995 {
2996 tmp2 = get_split_ob (tmp, 1 + RANDOM () % (tmp->nrof - 1)); 2996 tmp2 = get_split_ob (tmp, 1 + RANDOM () % (tmp->nrof - 1));
3008/* 3008/*
3009 * fix_weight(): Check recursively the weight of all players, and fix 3009 * fix_weight(): Check recursively the weight of all players, and fix
3010 * what needs to be fixed. Refresh windows and fix speed if anything 3010 * what needs to be fixed. Refresh windows and fix speed if anything
3011 * was changed. 3011 * was changed.
3012 */ 3012 */
3013
3014void 3013void
3015fix_weight (void) 3014fix_weight (void)
3016{ 3015{
3017 for_all_players (pl) 3016 for_all_players (pl)
3018 { 3017 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines