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.94 by root, Mon Jan 8 14:29:05 2007 UTC vs.
Revision 1.103 by root, Sat Feb 10 01:52:29 2007 UTC

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;
211player::connect (client *ns) 212player::connect (client *ns)
212{ 213{
213 this->ns = ns; 214 this->ns = ns;
214 ns->pl = this; 215 ns->pl = this;
215 216
217 run_on = 0;
218 fire_on = 0;
219 ob->close_container (); //TODO: client-specific
220
216 ns->update_look = 0; 221 ns->update_look = 0;
217 ns->look_position = 0; 222 ns->look_position = 0;
218 223
219 clear_los (ob); 224 clear_los (ob);
220 225
221//TODO: must move into client 226 ns->reset_stats ();
222/* we need to clear these to -1 and not zero - otherwise,
223 * if a player quits and starts a new character, we wont
224 * send new values to the client, as things like exp start
225 * at zero.
226 */
227for (int i = 0; i < NUM_SKILLS; i++)
228 last_skill_exp[i] = -1;
229
230for (int i = 0; i < NROFATTACKS; i++)
231 last_resist[i] = -1;
232
233last_weapon_sp = -1;
234last_level = -1;
235last_stats.exp = -1;
236last_weight = (uint32) - 1;
237last_flags = 0;
238last_weight = 0;
239last_weight_limit = 0;
240last_path_attuned = 0;
241last_path_repelled = 0;
242last_path_denied = 0;
243last_speed = 0;
244run_on = 0;
245fire_on = 0;
246memset (&last_stats, 0, sizeof (living)); //TODO dirty
247 227
248 /* make sure he's a player -- needed because of class change. */ 228 /* make sure he's a player -- needed because of class change. */
249 ob->type = PLAYER; // we are paranoid 229 ob->type = PLAYER; // we are paranoid
250 ob->race = ob->arch->clone.race; 230 ob->race = ob->arch->clone.race;
251 231
315 if (active) 295 if (active)
316 INVOKE_PLAYER (LOGOUT, this, ARG_INT (0)); 296 INVOKE_PLAYER (LOGOUT, this, ARG_INT (0));
317 297
318 INVOKE_PLAYER (DISCONNECT, this); 298 INVOKE_PLAYER (DISCONNECT, this);
319 299
300 ns->reset_stats ();
320 ns->pl = 0; 301 ns->pl = 0;
321 this->ns = 0; 302 this->ns = 0;
322 } 303 }
323 304
305 ob->close_container (); //TODO: client-specific
324 deactivate (); 306 deactivate ();
325} 307}
326 308
327// the need for this function can be explained 309// the need for this function can be explained
328// by load_object not returning the object 310// by load_object not returning the object
545 x = mon->x; 527 x = mon->x;
546 y = mon->y; 528 y = mon->y;
547 m = mon->map; 529 m = mon->map;
548 dir = rv.direction; 530 dir = rv.direction;
549 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 */
550 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
551 /* 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. */
552 if (diff > max) 535 if (diff > max)
553 return 0; 536 return 0;
537
554 while (diff > 1 && max > 0) 538 while (diff > 1 && max > 0)
555 { 539 {
556 lastx = x; 540 lastx = x;
557 lasty = y; 541 lasty = y;
558 lastmap = m; 542 lastmap = m;
640 max--; 624 max--;
641 lastdir = dir; 625 lastdir = dir;
642 if (!firstdir) 626 if (!firstdir)
643 firstdir = dir; 627 firstdir = dir;
644 } 628 }
629
645 if (diff <= 1) 630 if (diff <= 1)
646 { 631 {
647 /* Recalculate diff (distance) because we may not have actually 632 /* Recalculate diff (distance) because we may not have actually
648 * headed toward player for entire distance. 633 * headed toward player for entire distance.
649 */ 634 */
650 get_rangevector_from_mapcoord (m, x, y, pl, &rv, 0); 635 get_rangevector_from_mapcoord (m, x, y, pl, &rv, 0);
651 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));
652 } 637 }
638
653 if (diff > max) 639 if (diff > max)
654 return 0; 640 return 0;
655 } 641 }
642
656 /* 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 */
657 if (!max) 644 if (!max)
658 return 0; 645 return 0;
659 646
660 return firstdir; 647 return firstdir;
774roll_stat (void) 761roll_stat (void)
775{ 762{
776 int a[4], i, j, k; 763 int a[4], i, j, k;
777 764
778 for (i = 0; i < 4; i++) 765 for (i = 0; i < 4; i++)
779 a[i] = (int) RANDOM () % 6 + 1; 766 a[i] = (int) rndm (6) + 1;
780 767
781 for (i = 0, j = 0, k = 7; i < 4; i++) 768 for (i = 0, j = 0, k = 7; i < 4; i++)
782 if (a[i] < k) 769 if (a[i] < k)
783 k = a[i], j = i; 770 k = a[i], j = i;
784 771
914 * to save here. 901 * to save here.
915 */ 902 */
916 sprintf (buf, "%s/%s/%s", settings.localdir, settings.playerdir, &op->name); 903 sprintf (buf, "%s/%s/%s", settings.localdir, settings.playerdir, &op->name);
917 make_path_to_file (buf); 904 make_path_to_file (buf);
918 905
919#ifdef AUTOSAVE
920 op->contr->last_save_tick = pticks;
921#endif
922 start_info (op); 906 start_info (op);
923 CLEAR_FLAG (op, FLAG_WIZ); 907 CLEAR_FLAG (op, FLAG_WIZ);
924 give_initial_items (op, op->randomitems); 908 give_initial_items (op, op->randomitems);
925 link_player_skills (op); 909 link_player_skills (op);
926 esrv_send_inventory (op, op); 910 esrv_send_inventory (op, op);
1400 * found object is returned. 1384 * found object is returned.
1401 */ 1385 */
1402object * 1386object *
1403find_arrow (object *op, const char *type) 1387find_arrow (object *op, const char *type)
1404{ 1388{
1405 object *tmp = NULL; 1389 object *tmp = 0;
1406 1390
1407 for (op = op->inv; op; op = op->below) 1391 for (op = op->inv; op; op = op->below)
1408 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))
1409 tmp = find_arrow (op, type); 1393 tmp = find_arrow (op, type);
1410 else if (op->type == ARROW && op->race == type) 1394 else if (op->type == ARROW && op->race == type)
1411 return op; 1395 return op;
1396
1412 return tmp; 1397 return tmp;
1413} 1398}
1414 1399
1415/* 1400/*
1416 * 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
1417 * 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
1418 * 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
1419 * 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.
1420 */ 1405 */
1421
1422object * 1406object *
1423find_better_arrow (object *op, object *target, const char *type, int *better) 1407find_better_arrow (object *op, object *target, const char *type, int *better)
1424{ 1408{
1425 object *tmp = NULL, *arrow, *ntmp; 1409 object *tmp = NULL, *arrow, *ntmp;
1426 int attacknum, attacktype, betterby = 0, i; 1410 int attacknum, attacktype, betterby = 0, i;
1886 new_draw_info (NDI_UNIQUE, 0, op, "Illegal shoot type."); 1870 new_draw_info (NDI_UNIQUE, 0, op, "Illegal shoot type.");
1887 return; 1871 return;
1888 } 1872 }
1889} 1873}
1890 1874
1891
1892
1893/* find_key 1875/* find_key
1894 * 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
1895 * and successfully use it, we return the key, otherwise NULL 1877 * and successfully use it, we return the key, otherwise NULL
1896 * This function merges both normal and locked door, since the logic 1878 * This function merges both normal and locked door, since the logic
1897 * for both is the same - just the specific key is different. 1879 * for both is the same - just the specific key is different.
1898 * pl is the player, 1880 * pl is the player,
1899 * inv is the objects inventory to searched 1881 * inv is the objects inventory to searched
1900 * door is the door we are trying to match against. 1882 * door is the door we are trying to match against.
1901 * This function can be called recursively to search containers. 1883 * This function can be called recursively to search containers.
1902 */ 1884 */
1903
1904object * 1885object *
1905find_key (object *pl, object *container, object *door) 1886find_key (object *pl, object *container, object *door)
1906{ 1887{
1907 object *tmp, *key; 1888 object *tmp, *key;
1908 1889
1909 /* Should not happen, but sanity checking is never bad */ 1890 /* Should not happen, but sanity checking is never bad */
1910 if (container->inv == NULL) 1891 if (!container->inv)
1911 return NULL; 1892 return 0;
1912 1893
1913 /* 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 */
1914 for (tmp = container->inv; tmp != NULL; tmp = tmp->below) 1895 for (tmp = container->inv; tmp; tmp = tmp->below)
1915 { 1896 {
1916 if (door->type == DOOR && tmp->type == KEY) 1897 if (door->type == DOOR && tmp->type == KEY)
1917 break; 1898 break;
1918 /* For sanity, we should really check door type, but other stuff 1899 /* For sanity, we should really check door type, but other stuff
1919 * (like containers) can be locked with special keys 1900 * (like containers) can be locked with special keys
1920 */ 1901 */
1921 if (tmp->slaying && tmp->type == SPECIAL_KEY && tmp->slaying == door->slaying) 1902 if (tmp->slaying && tmp->type == SPECIAL_KEY && tmp->slaying == door->slaying)
1922 break; 1903 break;
1923 } 1904 }
1905
1924 /* No key found - lets search inventories now */ 1906 /* No key found - lets search inventories now */
1925 /* 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.
1926 * 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
1927 * a key, return 1909 * a key, return
1928 */ 1910 */
1929 if (!tmp) 1911 if (!tmp)
1930 { 1912 {
1931 for (tmp = container->inv; tmp != NULL; tmp = tmp->below) 1913 for (tmp = container->inv; tmp; tmp = tmp->below)
1932 { 1914 {
1933 /* No reason to search empty containers */ 1915 /* No reason to search empty containers */
1934 if (tmp->type == CONTAINER && tmp->inv) 1916 if (tmp->type == CONTAINER && tmp->inv)
1935 { 1917 {
1936 if ((key = find_key (pl, tmp, door)) != NULL) 1918 if ((key = find_key (pl, tmp, door)))
1937 return key; 1919 return key;
1938 } 1920 }
1939 } 1921 }
1922
1940 if (!tmp) 1923 if (!tmp)
1941 return NULL; 1924 return NULL;
1942 } 1925 }
1926
1943 /* 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,
1944 * see if we actually want to use it 1928 * see if we actually want to use it
1945 */ 1929 */
1946 if (pl != container) 1930 if (pl != container)
1947 { 1931 {
1968 new_draw_info_format (NDI_UNIQUE | NDI_BROWN, 0, pl, 1952 new_draw_info_format (NDI_UNIQUE | NDI_BROWN, 0, pl,
1969 "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));
1970 return NULL; 1954 return NULL;
1971 } 1955 }
1972 } 1956 }
1957
1973 return tmp; 1958 return tmp;
1974} 1959}
1975 1960
1976/* moved door processing out of move_player_attack. 1961/* moved door processing out of move_player_attack.
1977 * returns 1 if player has opened the door with a key 1962 * returns 1 if player has opened the door with a key
1995 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);
1996 if (action_makes_visible (op)) 1981 if (action_makes_visible (op))
1997 make_visible (op); 1982 make_visible (op);
1998 if (door->inv && (door->inv->type == RUNE || door->inv->type == TRAP)) 1983 if (door->inv && (door->inv->type == RUNE || door->inv->type == TRAP))
1999 spring_trap (door->inv, op); 1984 spring_trap (door->inv, op);
1985
2000 if (door->type == DOOR) 1986 if (door->type == DOOR)
2001 {
2002 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 */
2003 }
2004 else if (door->type == LOCKED_DOOR) 1988 else if (door->type == LOCKED_DOOR)
2005 { 1989 {
2006 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));
2007 remove_door2 (door); /* remove door without violence ;-) */ 1991 remove_door2 (door); /* remove door without violence ;-) */
2008 } 1992 }
1993
2009 /* Do this after we print the message */ 1994 /* Do this after we print the message */
2010 decrease_ob (key); /* Use up one of the keys */ 1995 decrease_ob (key); /* Use up one of the keys */
2011 /* Need to update the weight the container the key was in */ 1996 /* Need to update the weight the container the key was in */
2012 if (container != op) 1997 if (container != op)
2013 esrv_update_item (UPD_WEIGHT, op, container); 1998 esrv_update_item (UPD_WEIGHT, op, container);
1999
2014 return 1; /* Nothing more to do below */ 2000 return 1; /* Nothing more to do below */
2015 } 2001 }
2016 else if (door->type == LOCKED_DOOR) 2002 else if (door->type == LOCKED_DOOR)
2017 { 2003 {
2018 /* Might as well return now - no other way to open this */ 2004 /* Might as well return now - no other way to open this */
2019 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, door->msg); 2005 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, door->msg);
2020 return 1; 2006 return 1;
2021 } 2007 }
2008
2022 return 0; 2009 return 0;
2023} 2010}
2024 2011
2025/* This function is just part of a breakup from move_player. 2012/* This function is just part of a breakup from move_player.
2026 * It should keep the code cleaner. 2013 * It should keep the code cleaner.
2232 return 0; 2219 return 0;
2233 } 2220 }
2234 2221
2235 /* peterm: added following line */ 2222 /* peterm: added following line */
2236 if (QUERY_FLAG (op, FLAG_CONFUSED) && dir) 2223 if (QUERY_FLAG (op, FLAG_CONFUSED) && dir)
2237 dir = absdir (dir + RANDOM () % 3 + RANDOM () % 3 - 2); 2224 dir = absdir (dir + rndm (3) + rndm (3) - 2);
2238 2225
2239 op->facing = dir; 2226 op->facing = dir;
2240 2227
2241 if (op->hide) 2228 if (op->hide)
2242 do_hidden_move (op); 2229 do_hidden_move (op);
2383 * from. 2370 * from.
2384 */ 2371 */
2385void 2372void
2386remove_unpaid_objects (object *op, object *env) 2373remove_unpaid_objects (object *op, object *env)
2387{ 2374{
2388 object *next;
2389
2390 while (op) 2375 while (op)
2391 { 2376 {
2392 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' */
2393 2378
2394 if (QUERY_FLAG (op, FLAG_UNPAID)) 2379 if (QUERY_FLAG (op, FLAG_UNPAID))
2724 tmp->name = buf; 2709 tmp->name = buf;
2725 sprintf (buf, " This finger has been cut off %s\n" 2710 sprintf (buf, " This finger has been cut off %s\n"
2726 " 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",
2727 &op->name, op->contr->title, (int) (op->level), op->contr->killer); 2712 &op->name, op->contr->title, (int) (op->level), op->contr->killer);
2728 tmp->msg = buf; 2713 tmp->msg = buf;
2729 tmp->value = 0, tmp->material = 0, tmp->type = 0; 2714 tmp->value = 0, tmp->type = 0;
2730 tmp->materialname = NULL; 2715 tmp->materialname = "organics";
2731 tmp->insert_at (op, tmp); 2716 tmp->insert_at (op, tmp);
2732 } 2717 }
2733 2718
2734 /* teleport defeated player to new destination */ 2719 /* teleport defeated player to new destination */
2735 transfer_ob (op, x, y, 0, NULL); 2720 transfer_ob (op, x, y, 0, NULL);
2987void 2972void
2988loot_object (object *op) 2973loot_object (object *op)
2989{ /* Grab and destroy some treasure */ 2974{ /* Grab and destroy some treasure */
2990 object *tmp, *tmp2, *next; 2975 object *tmp, *tmp2, *next;
2991 2976
2992 if (op->container) 2977 op->close_container (); /* close open sack first */
2993 esrv_apply_container (op, op->container); /* close open sack first */
2994 2978
2995 for (tmp = op->inv; tmp; tmp = next) 2979 for (tmp = op->inv; tmp; tmp = next)
2996 { 2980 {
2997 next = tmp->below; 2981 next = tmp->below;
2998 2982
2999 if (tmp->invisible) 2983 if (tmp->invisible)
3000 continue; 2984 continue;
3001 2985
3002 tmp->remove (); 2986 tmp->remove ();
3003 tmp->x = op->x, tmp->y = op->y; 2987 tmp->x = op->x, tmp->y = op->y;
2988
3004 if (tmp->type == CONTAINER) 2989 if (tmp->type == CONTAINER)
3005 { /* empty container to ground */ 2990 loot_object (tmp); /* empty container to ground */
3006 loot_object (tmp); 2991
3007 }
3008 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))))
3009 { 2993 {
3010 if (tmp->nrof > 1) 2994 if (tmp->nrof > 1)
3011 { 2995 {
3012 tmp2 = get_split_ob (tmp, 1 + RANDOM () % (tmp->nrof - 1)); 2996 tmp2 = get_split_ob (tmp, 1 + RANDOM () % (tmp->nrof - 1));
3013 tmp2->destroy (); 2997 tmp2->destroy ();
3024/* 3008/*
3025 * fix_weight(): Check recursively the weight of all players, and fix 3009 * fix_weight(): Check recursively the weight of all players, and fix
3026 * 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
3027 * was changed. 3011 * was changed.
3028 */ 3012 */
3029
3030void 3013void
3031fix_weight (void) 3014fix_weight (void)
3032{ 3015{
3033 for_all_players (pl) 3016 for_all_players (pl)
3034 { 3017 {
3547 * not readied. 3530 * not readied.
3548 */ 3531 */
3549void 3532void
3550player_unready_range_ob (player *pl, object *ob) 3533player_unready_range_ob (player *pl, object *ob)
3551{ 3534{
3552 rangetype i;
3553
3554 for (i = (rangetype) 0; i < range_size; i = (rangetype) ((int) i + 1)) 3535 for (rangetype i = (rangetype) 0; i < range_size; i = (rangetype) ((int) i + 1))
3555 {
3556 if (pl->ranges[i] == ob) 3536 if (pl->ranges[i] == ob)
3557 { 3537 {
3558 pl->ranges[i] = NULL; 3538 pl->ranges[i] = 0;
3559 if (pl->shoottype == i) 3539 if (pl->shoottype == i)
3560 {
3561 pl->shoottype = range_none; 3540 pl->shoottype = range_none;
3562 }
3563 } 3541 }
3564 }
3565} 3542}
3543
3544sint8
3545player::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}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines