… | |
… | |
194 | return; |
194 | return; |
195 | |
195 | |
196 | terminate_all_pets (ob); |
196 | terminate_all_pets (ob); |
197 | remove_friendly_object (ob); |
197 | remove_friendly_object (ob); |
198 | ob->deactivate_recursive (); |
198 | ob->deactivate_recursive (); |
|
|
199 | maplevel = ob->map->path; |
199 | ob->remove (); |
200 | ob->remove (); |
200 | ob->map = 0; |
201 | ob->map = 0; |
201 | |
202 | |
202 | // for weird reasons, this is often "ob", keeping a circular reference |
203 | // for weird reasons, this is often "ob", keeping a circular reference |
203 | ranges [range_skill] = 0; |
204 | ranges [range_skill] = 0; |
… | |
… | |
213 | this->ns = ns; |
214 | this->ns = ns; |
214 | ns->pl = this; |
215 | ns->pl = this; |
215 | |
216 | |
216 | run_on = 0; |
217 | run_on = 0; |
217 | fire_on = 0; |
218 | fire_on = 0; |
|
|
219 | ob->close_container (); //TODO: client-specific |
218 | |
220 | |
219 | ns->update_look = 0; |
221 | ns->update_look = 0; |
220 | ns->look_position = 0; |
222 | ns->look_position = 0; |
221 | |
223 | |
222 | clear_los (ob); |
224 | clear_los (ob); |
… | |
… | |
293 | if (active) |
295 | if (active) |
294 | INVOKE_PLAYER (LOGOUT, this, ARG_INT (0)); |
296 | INVOKE_PLAYER (LOGOUT, this, ARG_INT (0)); |
295 | |
297 | |
296 | INVOKE_PLAYER (DISCONNECT, this); |
298 | INVOKE_PLAYER (DISCONNECT, this); |
297 | |
299 | |
|
|
300 | ns->reset_stats (); |
298 | ns->pl = 0; |
301 | ns->pl = 0; |
299 | this->ns = 0; |
302 | this->ns = 0; |
300 | } |
303 | } |
301 | |
304 | |
|
|
305 | ob->close_container (); //TODO: client-specific |
302 | deactivate (); |
306 | deactivate (); |
303 | } |
307 | } |
304 | |
308 | |
305 | // the need for this function can be explained |
309 | // the need for this function can be explained |
306 | // by load_object not returning the object |
310 | // by load_object not returning the object |
… | |
… | |
523 | x = mon->x; |
527 | x = mon->x; |
524 | y = mon->y; |
528 | y = mon->y; |
525 | m = mon->map; |
529 | m = mon->map; |
526 | dir = rv.direction; |
530 | dir = rv.direction; |
527 | lastdir = firstdir = rv.direction; /* perhaps we stand next to pl, init firstdir too */ |
531 | lastdir = firstdir = rv.direction; /* perhaps we stand next to pl, init firstdir too */ |
528 | diff = FABS (rv.distance_x) > FABS (rv.distance_y) ? FABS (rv.distance_x) : FABS (rv.distance_y); |
532 | diff = ::max (abs (rv.distance_x), abs (rv.distance_y)); |
|
|
533 | |
529 | /* If we can't solve it within the search distance, return now. */ |
534 | /* If we can't solve it within the search distance, return now. */ |
530 | if (diff > max) |
535 | if (diff > max) |
531 | return 0; |
536 | return 0; |
|
|
537 | |
532 | while (diff > 1 && max > 0) |
538 | while (diff > 1 && max > 0) |
533 | { |
539 | { |
534 | lastx = x; |
540 | lastx = x; |
535 | lasty = y; |
541 | lasty = y; |
536 | lastmap = m; |
542 | lastmap = m; |
… | |
… | |
618 | max--; |
624 | max--; |
619 | lastdir = dir; |
625 | lastdir = dir; |
620 | if (!firstdir) |
626 | if (!firstdir) |
621 | firstdir = dir; |
627 | firstdir = dir; |
622 | } |
628 | } |
|
|
629 | |
623 | if (diff <= 1) |
630 | if (diff <= 1) |
624 | { |
631 | { |
625 | /* Recalculate diff (distance) because we may not have actually |
632 | /* Recalculate diff (distance) because we may not have actually |
626 | * headed toward player for entire distance. |
633 | * headed toward player for entire distance. |
627 | */ |
634 | */ |
628 | get_rangevector_from_mapcoord (m, x, y, pl, &rv, 0); |
635 | get_rangevector_from_mapcoord (m, x, y, pl, &rv, 0); |
629 | diff = FABS (rv.distance_x) > FABS (rv.distance_y) ? FABS (rv.distance_x) : FABS (rv.distance_y); |
636 | diff = ::max (abs (rv.distance_x), abs (rv.distance_y)); |
630 | } |
637 | } |
|
|
638 | |
631 | if (diff > max) |
639 | if (diff > max) |
632 | return 0; |
640 | return 0; |
633 | } |
641 | } |
|
|
642 | |
634 | /* If we reached the max, didn't find a direction in time */ |
643 | /* If we reached the max, didn't find a direction in time */ |
635 | if (!max) |
644 | if (!max) |
636 | return 0; |
645 | return 0; |
637 | |
646 | |
638 | return firstdir; |
647 | return firstdir; |
… | |
… | |
752 | roll_stat (void) |
761 | roll_stat (void) |
753 | { |
762 | { |
754 | int a[4], i, j, k; |
763 | int a[4], i, j, k; |
755 | |
764 | |
756 | for (i = 0; i < 4; i++) |
765 | for (i = 0; i < 4; i++) |
757 | a[i] = (int) RANDOM () % 6 + 1; |
766 | a[i] = (int) rndm (6) + 1; |
758 | |
767 | |
759 | for (i = 0, j = 0, k = 7; i < 4; i++) |
768 | for (i = 0, j = 0, k = 7; i < 4; i++) |
760 | if (a[i] < k) |
769 | if (a[i] < k) |
761 | k = a[i], j = i; |
770 | k = a[i], j = i; |
762 | |
771 | |
… | |
… | |
1375 | * found object is returned. |
1384 | * found object is returned. |
1376 | */ |
1385 | */ |
1377 | object * |
1386 | object * |
1378 | find_arrow (object *op, const char *type) |
1387 | find_arrow (object *op, const char *type) |
1379 | { |
1388 | { |
1380 | object *tmp = NULL; |
1389 | object *tmp = 0; |
1381 | |
1390 | |
1382 | for (op = op->inv; op; op = op->below) |
1391 | for (op = op->inv; op; op = op->below) |
1383 | 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)) |
1384 | tmp = find_arrow (op, type); |
1393 | tmp = find_arrow (op, type); |
1385 | else if (op->type == ARROW && op->race == type) |
1394 | else if (op->type == ARROW && op->race == type) |
1386 | return op; |
1395 | return op; |
|
|
1396 | |
1387 | return tmp; |
1397 | return tmp; |
1388 | } |
1398 | } |
1389 | |
1399 | |
1390 | /* |
1400 | /* |
1391 | * 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 |
1392 | * 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 |
1393 | * 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 |
1394 | * 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. |
1395 | */ |
1405 | */ |
1396 | |
|
|
1397 | object * |
1406 | object * |
1398 | find_better_arrow (object *op, object *target, const char *type, int *better) |
1407 | find_better_arrow (object *op, object *target, const char *type, int *better) |
1399 | { |
1408 | { |
1400 | object *tmp = NULL, *arrow, *ntmp; |
1409 | object *tmp = NULL, *arrow, *ntmp; |
1401 | int attacknum, attacktype, betterby = 0, i; |
1410 | int attacknum, attacktype, betterby = 0, i; |
… | |
… | |
1861 | new_draw_info (NDI_UNIQUE, 0, op, "Illegal shoot type."); |
1870 | new_draw_info (NDI_UNIQUE, 0, op, "Illegal shoot type."); |
1862 | return; |
1871 | return; |
1863 | } |
1872 | } |
1864 | } |
1873 | } |
1865 | |
1874 | |
1866 | |
|
|
1867 | |
|
|
1868 | /* find_key |
1875 | /* find_key |
1869 | * 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 |
1870 | * and successfully use it, we return the key, otherwise NULL |
1877 | * and successfully use it, we return the key, otherwise NULL |
1871 | * This function merges both normal and locked door, since the logic |
1878 | * This function merges both normal and locked door, since the logic |
1872 | * for both is the same - just the specific key is different. |
1879 | * for both is the same - just the specific key is different. |
1873 | * pl is the player, |
1880 | * pl is the player, |
1874 | * inv is the objects inventory to searched |
1881 | * inv is the objects inventory to searched |
1875 | * door is the door we are trying to match against. |
1882 | * door is the door we are trying to match against. |
1876 | * This function can be called recursively to search containers. |
1883 | * This function can be called recursively to search containers. |
1877 | */ |
1884 | */ |
1878 | |
|
|
1879 | object * |
1885 | object * |
1880 | find_key (object *pl, object *container, object *door) |
1886 | find_key (object *pl, object *container, object *door) |
1881 | { |
1887 | { |
1882 | object *tmp, *key; |
1888 | object *tmp, *key; |
1883 | |
1889 | |
1884 | /* Should not happen, but sanity checking is never bad */ |
1890 | /* Should not happen, but sanity checking is never bad */ |
1885 | if (container->inv == NULL) |
1891 | if (!container->inv) |
1886 | return NULL; |
1892 | return 0; |
1887 | |
1893 | |
1888 | /* 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 */ |
1889 | for (tmp = container->inv; tmp != NULL; tmp = tmp->below) |
1895 | for (tmp = container->inv; tmp; tmp = tmp->below) |
1890 | { |
1896 | { |
1891 | if (door->type == DOOR && tmp->type == KEY) |
1897 | if (door->type == DOOR && tmp->type == KEY) |
1892 | break; |
1898 | break; |
1893 | /* For sanity, we should really check door type, but other stuff |
1899 | /* For sanity, we should really check door type, but other stuff |
1894 | * (like containers) can be locked with special keys |
1900 | * (like containers) can be locked with special keys |
1895 | */ |
1901 | */ |
1896 | if (tmp->slaying && tmp->type == SPECIAL_KEY && tmp->slaying == door->slaying) |
1902 | if (tmp->slaying && tmp->type == SPECIAL_KEY && tmp->slaying == door->slaying) |
1897 | break; |
1903 | break; |
1898 | } |
1904 | } |
|
|
1905 | |
1899 | /* No key found - lets search inventories now */ |
1906 | /* No key found - lets search inventories now */ |
1900 | /* 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. |
1901 | * 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 |
1902 | * a key, return |
1909 | * a key, return |
1903 | */ |
1910 | */ |
1904 | if (!tmp) |
1911 | if (!tmp) |
1905 | { |
1912 | { |
1906 | for (tmp = container->inv; tmp != NULL; tmp = tmp->below) |
1913 | for (tmp = container->inv; tmp; tmp = tmp->below) |
1907 | { |
1914 | { |
1908 | /* No reason to search empty containers */ |
1915 | /* No reason to search empty containers */ |
1909 | if (tmp->type == CONTAINER && tmp->inv) |
1916 | if (tmp->type == CONTAINER && tmp->inv) |
1910 | { |
1917 | { |
1911 | if ((key = find_key (pl, tmp, door)) != NULL) |
1918 | if ((key = find_key (pl, tmp, door))) |
1912 | return key; |
1919 | return key; |
1913 | } |
1920 | } |
1914 | } |
1921 | } |
|
|
1922 | |
1915 | if (!tmp) |
1923 | if (!tmp) |
1916 | return NULL; |
1924 | return NULL; |
1917 | } |
1925 | } |
|
|
1926 | |
1918 | /* 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, |
1919 | * see if we actually want to use it |
1928 | * see if we actually want to use it |
1920 | */ |
1929 | */ |
1921 | if (pl != container) |
1930 | if (pl != container) |
1922 | { |
1931 | { |
… | |
… | |
1943 | new_draw_info_format (NDI_UNIQUE | NDI_BROWN, 0, pl, |
1952 | new_draw_info_format (NDI_UNIQUE | NDI_BROWN, 0, pl, |
1944 | "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)); |
1945 | return NULL; |
1954 | return NULL; |
1946 | } |
1955 | } |
1947 | } |
1956 | } |
|
|
1957 | |
1948 | return tmp; |
1958 | return tmp; |
1949 | } |
1959 | } |
1950 | |
1960 | |
1951 | /* moved door processing out of move_player_attack. |
1961 | /* moved door processing out of move_player_attack. |
1952 | * returns 1 if player has opened the door with a key |
1962 | * returns 1 if player has opened the door with a key |
… | |
… | |
1970 | 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); |
1971 | if (action_makes_visible (op)) |
1981 | if (action_makes_visible (op)) |
1972 | make_visible (op); |
1982 | make_visible (op); |
1973 | if (door->inv && (door->inv->type == RUNE || door->inv->type == TRAP)) |
1983 | if (door->inv && (door->inv->type == RUNE || door->inv->type == TRAP)) |
1974 | spring_trap (door->inv, op); |
1984 | spring_trap (door->inv, op); |
|
|
1985 | |
1975 | if (door->type == DOOR) |
1986 | if (door->type == DOOR) |
1976 | { |
|
|
1977 | 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 */ |
1978 | } |
|
|
1979 | else if (door->type == LOCKED_DOOR) |
1988 | else if (door->type == LOCKED_DOOR) |
1980 | { |
1989 | { |
1981 | 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)); |
1982 | remove_door2 (door); /* remove door without violence ;-) */ |
1991 | remove_door2 (door); /* remove door without violence ;-) */ |
1983 | } |
1992 | } |
|
|
1993 | |
1984 | /* Do this after we print the message */ |
1994 | /* Do this after we print the message */ |
1985 | decrease_ob (key); /* Use up one of the keys */ |
1995 | decrease_ob (key); /* Use up one of the keys */ |
1986 | /* Need to update the weight the container the key was in */ |
1996 | /* Need to update the weight the container the key was in */ |
1987 | if (container != op) |
1997 | if (container != op) |
1988 | esrv_update_item (UPD_WEIGHT, op, container); |
1998 | esrv_update_item (UPD_WEIGHT, op, container); |
|
|
1999 | |
1989 | return 1; /* Nothing more to do below */ |
2000 | return 1; /* Nothing more to do below */ |
1990 | } |
2001 | } |
1991 | else if (door->type == LOCKED_DOOR) |
2002 | else if (door->type == LOCKED_DOOR) |
1992 | { |
2003 | { |
1993 | /* Might as well return now - no other way to open this */ |
2004 | /* Might as well return now - no other way to open this */ |
1994 | new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, door->msg); |
2005 | new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, door->msg); |
1995 | return 1; |
2006 | return 1; |
1996 | } |
2007 | } |
|
|
2008 | |
1997 | return 0; |
2009 | return 0; |
1998 | } |
2010 | } |
1999 | |
2011 | |
2000 | /* This function is just part of a breakup from move_player. |
2012 | /* This function is just part of a breakup from move_player. |
2001 | * It should keep the code cleaner. |
2013 | * It should keep the code cleaner. |
… | |
… | |
2207 | return 0; |
2219 | return 0; |
2208 | } |
2220 | } |
2209 | |
2221 | |
2210 | /* peterm: added following line */ |
2222 | /* peterm: added following line */ |
2211 | if (QUERY_FLAG (op, FLAG_CONFUSED) && dir) |
2223 | if (QUERY_FLAG (op, FLAG_CONFUSED) && dir) |
2212 | dir = absdir (dir + RANDOM () % 3 + RANDOM () % 3 - 2); |
2224 | dir = absdir (dir + rndm (3) + rndm (3) - 2); |
2213 | |
2225 | |
2214 | op->facing = dir; |
2226 | op->facing = dir; |
2215 | |
2227 | |
2216 | if (op->hide) |
2228 | if (op->hide) |
2217 | do_hidden_move (op); |
2229 | do_hidden_move (op); |
… | |
… | |
2358 | * from. |
2370 | * from. |
2359 | */ |
2371 | */ |
2360 | void |
2372 | void |
2361 | remove_unpaid_objects (object *op, object *env) |
2373 | remove_unpaid_objects (object *op, object *env) |
2362 | { |
2374 | { |
2363 | object *next; |
|
|
2364 | |
|
|
2365 | while (op) |
2375 | while (op) |
2366 | { |
2376 | { |
2367 | 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' */ |
2368 | |
2378 | |
2369 | if (QUERY_FLAG (op, FLAG_UNPAID)) |
2379 | if (QUERY_FLAG (op, FLAG_UNPAID)) |
… | |
… | |
2699 | tmp->name = buf; |
2709 | tmp->name = buf; |
2700 | sprintf (buf, " This finger has been cut off %s\n" |
2710 | sprintf (buf, " This finger has been cut off %s\n" |
2701 | " the %s, when he was defeated at\n level %d by %s.\n", |
2711 | " the %s, when he was defeated at\n level %d by %s.\n", |
2702 | &op->name, op->contr->title, (int) (op->level), op->contr->killer); |
2712 | &op->name, op->contr->title, (int) (op->level), op->contr->killer); |
2703 | tmp->msg = buf; |
2713 | tmp->msg = buf; |
2704 | tmp->value = 0, tmp->material = 0, tmp->type = 0; |
2714 | tmp->value = 0, tmp->type = 0; |
2705 | tmp->materialname = NULL; |
2715 | tmp->materialname = "organics"; |
2706 | tmp->insert_at (op, tmp); |
2716 | tmp->insert_at (op, tmp); |
2707 | } |
2717 | } |
2708 | |
2718 | |
2709 | /* teleport defeated player to new destination */ |
2719 | /* teleport defeated player to new destination */ |
2710 | transfer_ob (op, x, y, 0, NULL); |
2720 | transfer_ob (op, x, y, 0, NULL); |
… | |
… | |
2962 | void |
2972 | void |
2963 | loot_object (object *op) |
2973 | loot_object (object *op) |
2964 | { /* Grab and destroy some treasure */ |
2974 | { /* Grab and destroy some treasure */ |
2965 | object *tmp, *tmp2, *next; |
2975 | object *tmp, *tmp2, *next; |
2966 | |
2976 | |
2967 | if (op->container) |
2977 | op->close_container (); /* close open sack first */ |
2968 | esrv_apply_container (op, op->container); /* close open sack first */ |
|
|
2969 | |
2978 | |
2970 | for (tmp = op->inv; tmp; tmp = next) |
2979 | for (tmp = op->inv; tmp; tmp = next) |
2971 | { |
2980 | { |
2972 | next = tmp->below; |
2981 | next = tmp->below; |
2973 | |
2982 | |
2974 | if (tmp->invisible) |
2983 | if (tmp->invisible) |
2975 | continue; |
2984 | continue; |
2976 | |
2985 | |
2977 | tmp->remove (); |
2986 | tmp->remove (); |
2978 | tmp->x = op->x, tmp->y = op->y; |
2987 | tmp->x = op->x, tmp->y = op->y; |
|
|
2988 | |
2979 | if (tmp->type == CONTAINER) |
2989 | if (tmp->type == CONTAINER) |
2980 | { /* empty container to ground */ |
2990 | loot_object (tmp); /* empty container to ground */ |
2981 | loot_object (tmp); |
2991 | |
2982 | } |
|
|
2983 | if (!QUERY_FLAG (tmp, FLAG_UNIQUE) && (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || QUERY_FLAG (tmp, FLAG_NO_DROP) || !(RANDOM () % 3))) |
2992 | if (!QUERY_FLAG (tmp, FLAG_UNIQUE) && (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || QUERY_FLAG (tmp, FLAG_NO_DROP) || !(rndm (3)))) |
2984 | { |
2993 | { |
2985 | if (tmp->nrof > 1) |
2994 | if (tmp->nrof > 1) |
2986 | { |
2995 | { |
2987 | tmp2 = get_split_ob (tmp, 1 + RANDOM () % (tmp->nrof - 1)); |
2996 | tmp2 = get_split_ob (tmp, 1 + RANDOM () % (tmp->nrof - 1)); |
2988 | tmp2->destroy (); |
2997 | tmp2->destroy (); |
… | |
… | |
2999 | /* |
3008 | /* |
3000 | * fix_weight(): Check recursively the weight of all players, and fix |
3009 | * fix_weight(): Check recursively the weight of all players, and fix |
3001 | * 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 |
3002 | * was changed. |
3011 | * was changed. |
3003 | */ |
3012 | */ |
3004 | |
|
|
3005 | void |
3013 | void |
3006 | fix_weight (void) |
3014 | fix_weight (void) |
3007 | { |
3015 | { |
3008 | for_all_players (pl) |
3016 | for_all_players (pl) |
3009 | { |
3017 | { |
… | |
… | |
3530 | pl->ranges[i] = 0; |
3538 | pl->ranges[i] = 0; |
3531 | if (pl->shoottype == i) |
3539 | if (pl->shoottype == i) |
3532 | pl->shoottype = range_none; |
3540 | pl->shoottype = range_none; |
3533 | } |
3541 | } |
3534 | } |
3542 | } |
|
|
3543 | |
|
|
3544 | sint8 |
|
|
3545 | player::visibility_at (maptile *map, int x, int y) const |
|
|
3546 | { |
|
|
3547 | if (!ns) |
|
|
3548 | return 0; |
|
|
3549 | |
|
|
3550 | int dx, dy; |
|
|
3551 | if (!adjacent_map (map, ns->current_map, &dx, &dy)) |
|
|
3552 | return 0; |
|
|
3553 | |
|
|
3554 | x += dx - ns->current_x + ns->mapx / 2; |
|
|
3555 | y += dy - ns->current_y + ns->mapy / 2; |
|
|
3556 | |
|
|
3557 | if (!IN_RANGE_EXC (x, 0, ns->mapx) || !IN_RANGE_EXC (y, 0, ns->mapy)) |
|
|
3558 | return 0; |
|
|
3559 | |
|
|
3560 | return 100 - blocked_los [x][y]; |
|
|
3561 | } |