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.56 by root, Sat Dec 23 05:25:18 2006 UTC vs.
Revision 1.76 by root, Sun Dec 31 17:17:23 2006 UTC

34#include <functional> 34#include <functional>
35 35
36player * 36player *
37find_player (const char *plname) 37find_player (const char *plname)
38{ 38{
39 player *pl; 39 for_all_players (pl)
40
41 for (pl = first_player; pl; pl = pl->next)
42 if (pl->ob && !strcmp (query_name (pl->ob), plname)) 40 if (pl->ob && !strcmp (query_name (pl->ob), plname))
43 return pl; 41 return pl;
44 42
45 return 0; 43 return 0;
46} 44}
163set_first_map (object *op) 161set_first_map (object *op)
164{ 162{
165 strcpy (op->contr->maplevel, first_map_path); 163 strcpy (op->contr->maplevel, first_map_path);
166 op->x = -1; 164 op->x = -1;
167 op->y = -1; 165 op->y = -1;
166}
167
168void
169player::enter_map ()
170{
171 object *tmp = object::create ();
172
173 EXIT_PATH (tmp) = maplevel;
174 EXIT_X (tmp) = ob->x;
175 EXIT_Y (tmp) = ob->y;
168 enter_exit (op, 0); 176 ob->enter_exit (tmp);
177
178 tmp->destroy ();
169} 179}
170 180
171// connect the player with a specific client 181// connect the player with a specific client
172// also changed, rationalises, and fixes some incorrect settings 182// also changed, rationalises, and fixes some incorrect settings
173void 183void
182 ns->update_look = 0; 192 ns->update_look = 0;
183 ns->look_position = 0; 193 ns->look_position = 0;
184 194
185 clear_los (ob); 195 clear_los (ob);
186 196
197 /* make sure he's a player -- needed because of class change. */
187 ob->type = PLAYER; // we are paranoid 198 ob->type = PLAYER; // we are paranoid
188 ob->race = ob->arch->clone.race; 199 ob->race = ob->arch->clone.race;
189 200
190 if (!legal_range (ob, shoottype)) 201 if (!legal_range (ob, shoottype))
191 shoottype = range_none; 202 shoottype = range_none;
192 203
193 ob->carrying = sum_weight (ob); 204 ob->carrying = sum_weight (ob);
194 link_player_skills (ob); 205 link_player_skills (ob);
195 206
196 CLEAR_FLAG (ob, FLAG_NO_FIX_PLAYER); 207 CLEAR_FLAG (ob, FLAG_NO_FIX_PLAYER);
197 ob->update_stats ();
198 update_ob_speed (ob);
199 208
200 assign (title, ob->arch->clone.name); 209 assign (title, ob->arch->clone.name);
201 210
202 /* can_use_shield is a new flag. However, the can_use.. seems to largely come 211 /* can_use_shield is a new flag. However, the can_use.. seems to largely come
203 * from the class, and not race. I don't see any way to get the class information 212 * from the class, and not race. I don't see any way to get the class information
231 add_friendly_object (ob); 240 add_friendly_object (ob);
232 241
233 LOG (llevInfo, "LOGIN: Player named %s from ip %s\n", &ob->name, ns->host); 242 LOG (llevInfo, "LOGIN: Player named %s from ip %s\n", &ob->name, ns->host);
234 243
235 new_draw_info (NDI_UNIQUE, 0, ob, "Welcome Back!"); 244 new_draw_info (NDI_UNIQUE, 0, ob, "Welcome Back!");
236 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, NULL, "%s has entered the game.", &ob->name);
237 245
246 esrv_new_player (this, ob->weight + ob->carrying);
247
248 ob->update_stats ();
238 ns->floorbox_update (); 249 ns->floorbox_update ();
239 250
240 esrv_new_player (this, ob->weight + ob->carrying);
241 esrv_send_inventory (ob, ob); 251 esrv_send_inventory (ob, ob);
242 esrv_add_spells (this, 0); 252 esrv_add_spells (this, 0);
243 253
244 enter_exit (ob, 0); 254 ob->activate_recursive ();
255 enter_map ();
245 256
246// send_rules (ob);//TODO 257 send_rules (ob);
247// send_news (ob);//TODO 258 send_news (ob);
248// display_motd (ob);//TODO 259 display_motd (ob);
249 INVOKE_PLAYER (LOGIN, this); 260 INVOKE_PLAYER (LOGIN, this);
261}
262
263void
264player::disconnect ()
265{
266 if (ob)
267 ob->deactivate_recursive ();
268
269 //TODO: don't be so harsh and destroy :)
270 if (ns)
271 {
272 if (enable_save)
273 INVOKE_PLAYER (LOGOUT, this, ARG_INT (0));
274
275 client *ns = this->ns;
276 ns->send_packet ("goodbye");
277 ns->flush ();
278 ns->pl = 0;
279 this->ns = 0;
280
281 ns->destroy ();
282 destroy ();
283 }
250} 284}
251 285
252// the need for this function can be explained 286// the need for this function can be explained
253// by load_object not returning the object 287// by load_object not returning the object
254void 288void
260 ob->speed_left = 0.5; 294 ob->speed_left = 0.5;
261 ob->speed = 1.0; 295 ob->speed = 1.0;
262 ob->direction = 5; /* So player faces south */ 296 ob->direction = 5; /* So player faces south */
263 ob->stats.wc = 2; 297 ob->stats.wc = 2;
264 ob->run_away = 25; /* Then we panick... */ 298 ob->run_away = 25; /* Then we panick... */
265
266 set_first_map (ob);
267 299
268 ob->roll_stats (); 300 ob->roll_stats ();
269} 301}
270 302
271player::player () 303player::player ()
303 335
304 last_stats.exp = -1; 336 last_stats.exp = -1;
305 last_weight = (uint32) - 1; 337 last_weight = (uint32) - 1;
306} 338}
307 339
308player::~player () 340void
341player::do_destroy ()
309{ 342{
343 disconnect ();
344
345 save (false);
346 enable_save = false;
347
348 attachable::do_destroy ();
349
310 terminate_all_pets (ob); 350 terminate_all_pets (ob);
311 351
312 if (first_player != this) 352 if (first_player != this)
313 { 353 {
314 player *prev = first_player; 354 player *prev = first_player;
327 else 367 else
328 first_player = next; 368 first_player = next;
329 369
330 if (ob) 370 if (ob)
331 { 371 {
332 ob->contr = 0; 372 ob->destroy_inv (false);
333 ob->destroy (1); 373 ob->destroy ();
334 }
335
336 if (ns)
337 { 374 }
338 ns->send_packet ("goodbye"); 375}
339 ns->flush ();
340 ns->pl = 0;
341 ns->destroy ();
342 }
343 376
377player::~player ()
378{
344 /* Clear item stack */ 379 /* Clear item stack */
345 free (stack_items); 380 free (stack_items);
346} 381}
347 382
348/* Tries to add player on the connection passed in ns. 383/* Tries to add player on the connection passed in ns.
353player::create () 388player::create ()
354{ 389{
355 player *pl = new player; 390 player *pl = new player;
356 391
357 pl->set_object (arch_to_object (get_player_archetype (0))); 392 pl->set_object (arch_to_object (get_player_archetype (0)));
393 set_first_map (pl->ob);
358 394
359 return pl; 395 return pl;
360} 396}
361 397
362/* 398/*
389 425
390object * 426object *
391get_nearest_player (object *mon) 427get_nearest_player (object *mon)
392{ 428{
393 object *op = NULL; 429 object *op = NULL;
394 player *pl = NULL;
395 objectlink *ol; 430 objectlink *ol;
396 unsigned lastdist; 431 unsigned lastdist;
397 rv_vector rv; 432 rv_vector rv;
398 433
399 for (ol = first_friendly_object, lastdist = 1000; ol != NULL; ol = ol->next) 434 for (ol = first_friendly_object, lastdist = 1000; ol != NULL; ol = ol->next)
431 { 466 {
432 op = ol->ob; 467 op = ol->ob;
433 lastdist = rv.distance; 468 lastdist = rv.distance;
434 } 469 }
435 } 470 }
436 for (pl = first_player; pl != NULL; pl = pl->next) 471
437 { 472 for_all_players (pl)
438 if (can_detect_enemy (mon, pl->ob, &rv)) 473 if (can_detect_enemy (mon, pl->ob, &rv))
439 {
440
441 if (lastdist > rv.distance) 474 if (lastdist > rv.distance)
442 { 475 {
443 op = pl->ob; 476 op = pl->ob;
444 lastdist = rv.distance; 477 lastdist = rv.distance;
445 } 478 }
446 } 479
447 }
448#if 0 480#if 0
449 LOG (llevDebug, "get_nearest_player() finds player: %s\n", op ? &op->name : "(null)"); 481 LOG (llevDebug, "get_nearest_player() finds player: %s\n", op ? &op->name : "(null)");
450#endif 482#endif
451 return op; 483 return op;
452} 484}
832 864
833 contr->orig_stats = stats; 865 contr->orig_stats = stats;
834 } 866 }
835} 867}
836 868
869static void
870start_info (object *op)
871{
872 char buf[MAX_BUF];
873
874 sprintf (buf, "Welcome to Crossfire v%s!", VERSION);
875 new_draw_info (NDI_UNIQUE, 0, op, buf);
876 //new_draw_info (NDI_UNIQUE, 0, op, "Press `?' for help");
877 //new_draw_info (NDI_UNIQUE, 0, op, " ");
878}
879
837/* This function takes the key that is passed, and does the 880/* This function takes the key that is passed, and does the
838 * appropriate action with it (change race, or other things). 881 * appropriate action with it (change race, or other things).
839 * The function name is for historical reasons - now we have 882 * The function name is for historical reasons - now we have
840 * separate race and class; this actually changes the RACE, 883 * separate race and class; this actually changes the RACE,
841 * not the class. 884 * not the class.
891 snprintf (mapname, MAX_BUF - 1, "%s/%s", first_map_ext_path, &op->arch->name); 934 snprintf (mapname, MAX_BUF - 1, "%s/%s", first_map_ext_path, &op->arch->name);
892 tmp = object::create (); 935 tmp = object::create ();
893 EXIT_PATH (tmp) = mapname; 936 EXIT_PATH (tmp) = mapname;
894 EXIT_X (tmp) = op->x; 937 EXIT_X (tmp) = op->x;
895 EXIT_Y (tmp) = op->y; 938 EXIT_Y (tmp) = op->y;
896 enter_exit (op, tmp); /* we don't really care if it succeeded; 939 op->enter_exit (tmp); /* we don't really care if it succeeded;
897 * if the map isn't there, then stay on the 940 * if the map isn't there, then stay on the
898 * default initial map */ 941 * default initial map */
899 tmp->destroy (); 942 tmp->destroy ();
900 } 943 }
901 else 944 else
955 } 998 }
956 999
957 INVOKE_PLAYER (LOGOUT, op->contr); 1000 INVOKE_PLAYER (LOGOUT, op->contr);
958 INVOKE_PLAYER (QUIT, op->contr); 1001 INVOKE_PLAYER (QUIT, op->contr);
959 1002
1003 op->contr->enable_save = false;
1004
960 terminate_all_pets (op); 1005 terminate_all_pets (op);
961 leave_map (op); 1006 op->remove ();
962 op->direction = 0; 1007 op->direction = 0;
963 new_draw_info_format (NDI_UNIQUE | NDI_ALL, 5, NULL, "%s quits the game.", &op->name); 1008 new_draw_info_format (NDI_UNIQUE | NDI_ALL, 5, NULL, "%s quits the game.", &op->name);
964 1009
965 strcpy (op->contr->killer, "quit"); 1010 strcpy (op->contr->killer, "quit");
966 check_score (op); 1011 check_score (op);
967 op->contr->party = 0; 1012 op->contr->party = 0;
968 op->contr->own_title[0] = '\0'; 1013 op->contr->own_title[0] = '\0';
969 1014 op->contr->destroy ();
970 object_ptr ob = op;
971
972 delete ob->contr;
973
974 /* We need to hunt for any per player unique maps in memory and
975 * get rid of them. The trailing slash in the path is intentional,
976 * so that players named 'Ab' won't match against players 'Abe' pathname
977 */
978 char buf[MAX_BUF];
979 sprintf (buf, "%s/%s/%s/", settings.localdir, settings.playerdir, &op->name);
980
981 for (maptile *next, *mp = first_map; mp; mp = next)
982 {
983 next = mp->next;
984
985 if (!strncmp (mp->path, buf, strlen (buf)))
986 delete_map (mp);
987 }
988
989 delete_character (ob->name, 1);
990 1015
991 return 1; 1016 return 1;
992} 1017}
993 1018
994void 1019void
1133 sprintf (putstring, "item name: %s item type: %d weight/value: %d", 1158 sprintf (putstring, "item name: %s item type: %d weight/value: %d",
1134 &tmp->name, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1)))); 1159 &tmp->name, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))));
1135 else 1160 else
1136 sprintf (putstring, "item name: %s item type: %d weight/value: %d", 1161 sprintf (putstring, "item name: %s item type: %d weight/value: %d",
1137 &tmp->arch->name, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1)))); 1162 &tmp->arch->name, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))));
1163
1138 new_draw_info (NDI_UNIQUE, 0, op, putstring); 1164 new_draw_info (NDI_UNIQUE, 0, op, putstring);
1139
1140 sprintf (putstring, "...flags: ");
1141 for (k = 0; k < 4; k++)
1142 {
1143 for (j = 0; j < 32; j++)
1144 {
1145 if ((tmp->flags[k] >> j) & 0x01)
1146 {
1147 sprintf (tmpstr, "%d ", k * 32 + j);
1148 strcat (putstring, tmpstr);
1149 }
1150 }
1151 }
1152 new_draw_info (NDI_UNIQUE, 0, op, putstring);
1153
1154#if 0
1155 /* print the flags too */
1156 for (k = 0; k < 4; k++)
1157 {
1158 fprintf (stderr, "%d [%d] ", k, k * 32 + 31);
1159 for (j = 0; j < 32; j++)
1160 {
1161 fprintf (stderr, "%d", tmp->flags[k] >> (31 - j) & 0x01);
1162 if (!((j + 1) % 4))
1163 fprintf (stderr, " ");
1164 }
1165 fprintf (stderr, " [%d]\n", k * 32);
1166 }
1167#endif
1168 } 1165 }
1166
1169 /* philosophy: 1167 /* philosophy:
1170 * It's easy to grab an item type from a pile, as long as it's 1168 * It's easy to grab an item type from a pile, as long as it's
1171 * generic. This takes no game-time. For more detailed pickups 1169 * generic. This takes no game-time. For more detailed pickups
1172 * and selections, select-items shoul dbe used. This is a 1170 * and selections, select-items should be used. This is a
1173 * grab-as-you-run type mode that's really useful for arrows for 1171 * grab-as-you-run type mode that's really useful for arrows for
1174 * example. 1172 * example.
1175 * The drawback: right now it has no frontend, so you need to 1173 * The drawback: right now it has no frontend, so you need to
1176 * stick the bits you want into a calculator in hex mode and then 1174 * stick the bits you want into a calculator in hex mode and then
1177 * convert to decimal and then 'pickup <#> 1175 * convert to decimal and then 'pickup <#>
1677 return 0; 1675 return 0;
1678 } 1676 }
1679 1677
1680 arrow->set_owner (op); 1678 arrow->set_owner (op);
1681 arrow->skill = bow->skill; 1679 arrow->skill = bow->skill;
1682
1683 arrow->direction = dir; 1680 arrow->direction = dir;
1684 arrow->x = sx;
1685 arrow->y = sy;
1686 1681
1687 if (op->type == PLAYER) 1682 if (op->type == PLAYER)
1688 { 1683 {
1689 op->speed_left = 0.01 - (float) FABS (op->speed) * 100 / bowspeed; 1684 op->speed_left = 0.01 - (float) FABS (op->speed) * 100 / bowspeed;
1690 op->update_stats (); 1685 op->update_stats ();
1705 1700
1706 /* update the speed */ 1701 /* update the speed */
1707 arrow->speed = (float) ((QUERY_FLAG (bow, FLAG_NO_STRENGTH) ? 1702 arrow->speed = (float) ((QUERY_FLAG (bow, FLAG_NO_STRENGTH) ?
1708 0 : dam_bonus[op->stats.Str]) + bow->magic + arrow->magic) / 5.0 + (float) bow->stats.dam / 7.0; 1703 0 : dam_bonus[op->stats.Str]) + bow->magic + arrow->magic) / 5.0 + (float) bow->stats.dam / 7.0;
1709 1704
1710 if (arrow->speed < 1.0) 1705 arrow->set_speed (max (arrow->speed, 1.0));
1711 arrow->speed = 1.0;
1712 update_ob_speed (arrow);
1713 arrow->speed_left = 0; 1706 arrow->speed_left = 0;
1714 1707
1715 if (op->type == PLAYER) 1708 if (op->type == PLAYER)
1716 { 1709 {
1717 arrow->stats.wc = 20 - bow->magic - arrow->magic - 1710 arrow->stats.wc = 20 - bow->magic - arrow->magic -
1730 arrow->attacktype |= bow->attacktype; 1723 arrow->attacktype |= bow->attacktype;
1731 1724
1732 if (bow->slaying) 1725 if (bow->slaying)
1733 arrow->slaying = bow->slaying; 1726 arrow->slaying = bow->slaying;
1734 1727
1735 arrow->map = m;
1736 arrow->move_type = MOVE_FLY_LOW; 1728 arrow->move_type = MOVE_FLY_LOW;
1737 arrow->move_on = MOVE_FLY_LOW | MOVE_WALK; 1729 arrow->move_on = MOVE_FLY_LOW | MOVE_WALK;
1738 1730
1739 play_sound_map (op->map, op->x, op->y, SOUND_FIRE_ARROW); 1731 play_sound_map (op->map, op->x, op->y, SOUND_FIRE_ARROW);
1740 insert_ob_in_map (arrow, m, op, 0); 1732 m->insert (arrow, sx, sy, op);
1741 1733
1742 if (!arrow->destroyed ()) 1734 if (!arrow->destroyed ())
1743 move_arrow (arrow); 1735 move_arrow (arrow);
1744 1736
1745 if (op->type == PLAYER) 1737 if (op->type == PLAYER)
1771 } 1763 }
1772 else if (op->contr->bowtype >= bow_n && op->contr->bowtype <= bow_nw) 1764 else if (op->contr->bowtype >= bow_n && op->contr->bowtype <= bow_nw)
1773 { 1765 {
1774 if (!similar_direction (dir, op->contr->bowtype - bow_n + 1)) 1766 if (!similar_direction (dir, op->contr->bowtype - bow_n + 1))
1775 wcmod = -1; 1767 wcmod = -1;
1768
1776 ret = fire_bow (op, op, NULL, op->contr->bowtype - bow_n + 1, wcmod, op->x, op->y); 1769 ret = fire_bow (op, op, NULL, op->contr->bowtype - bow_n + 1, wcmod, op->x, op->y);
1777 } 1770 }
1778 else if (op->contr->bowtype == bow_threewide) 1771 else if (op->contr->bowtype == bow_threewide)
1779 { 1772 {
1780 ret = fire_bow (op, op, NULL, dir, 0, op->x, op->y); 1773 ret = fire_bow (op, op, NULL, dir, 0, op->x, op->y);
1850 1843
1851 if (item->arch) 1844 if (item->arch)
1852 { 1845 {
1853 CLEAR_FLAG (item, FLAG_ANIMATE); 1846 CLEAR_FLAG (item, FLAG_ANIMATE);
1854 item->face = item->arch->clone.face; 1847 item->face = item->arch->clone.face;
1855 item->speed = 0; 1848 item->set_speed (0);
1856 update_ob_speed (item);
1857 } 1849 }
1850
1858 if ((tmp = item->in_player ())) 1851 if ((tmp = item->in_player ()))
1859 esrv_update_item (UPD_ANIM, tmp, item); 1852 esrv_update_item (UPD_ANIM, tmp, item);
1860 } 1853 }
1861 } 1854 }
1862 else if (item->type == ROD || item->type == HORN) 1855 else if (item->type == ROD || item->type == HORN)
1863 {
1864 drain_rod_charge (item); 1856 drain_rod_charge (item);
1865 }
1866 } 1857 }
1867} 1858}
1868 1859
1869/* Received a fire command for the player - go and do it. 1860/* Received a fire command for the player - go and do it.
1870 */ 1861 */
2426{ 2417{
2427 object *next; 2418 object *next;
2428 2419
2429 while (op) 2420 while (op)
2430 { 2421 {
2431 next = op->below; /* Make sure we have a good value, in case 2422 object *next = op->below; /* Make sure we have a good value, in case we remove object 'op' */
2432 * we remove object 'op' 2423
2433 */
2434 if (QUERY_FLAG (op, FLAG_UNPAID)) 2424 if (QUERY_FLAG (op, FLAG_UNPAID))
2435 { 2425 {
2436 op->remove ();
2437 op->x = env->x;
2438 op->y = env->y;
2439 if (env->type == PLAYER) 2426 if (env->type == PLAYER)
2440 esrv_del_item (env->contr, op->count); 2427 esrv_del_item (env->contr, op->count);
2441 insert_ob_in_map (op, env->map, NULL, 0); 2428
2429 op->insert_at (env);
2442 } 2430 }
2443 else if (op->inv) 2431 else if (op->inv)
2444 remove_unpaid_objects (op->inv, env); 2432 remove_unpaid_objects (op->inv, env);
2445 2433
2446 op = next; 2434 op = next;
2739 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, "You have been defeated in combat!"); 2727 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, "You have been defeated in combat!");
2740 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, "Local medics have saved your life..."); 2728 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, "Local medics have saved your life...");
2741 2729
2742 /* restore player */ 2730 /* restore player */
2743 at = archetype::find ("poisoning"); 2731 at = archetype::find ("poisoning");
2744 tmp = present_arch_in_ob (at, op); 2732 if (object *tmp = present_arch_in_ob (at, op))
2745 if (tmp)
2746 { 2733 {
2747 tmp->destroy (); 2734 tmp->destroy ();
2748 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed"); 2735 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed");
2749 } 2736 }
2750 2737
2751 at = archetype::find ("confusion"); 2738 at = archetype::find ("confusion");
2752 tmp = present_arch_in_ob (at, op); 2739 if (object *tmp = present_arch_in_ob (at, op))
2753 if (tmp)
2754 { 2740 {
2755 tmp->destroy (); 2741 tmp->destroy ();
2756 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer"); 2742 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer");
2757 } 2743 }
2758 2744
2760 op->stats.hp = op->stats.maxhp; 2746 op->stats.hp = op->stats.maxhp;
2761 if (op->stats.food <= 0) 2747 if (op->stats.food <= 0)
2762 op->stats.food = 999; 2748 op->stats.food = 999;
2763 2749
2764 /* create a bodypart-trophy to make the winner happy */ 2750 /* create a bodypart-trophy to make the winner happy */
2765 tmp = arch_to_object (archetype::find ("finger")); 2751 if (object *tmp = arch_to_object (archetype::find ("finger")))
2766 if (tmp != NULL)
2767 { 2752 {
2768 sprintf (buf, "%s's finger", &op->name); 2753 sprintf (buf, "%s's finger", &op->name);
2769 tmp->name = buf; 2754 tmp->name = buf;
2770 sprintf (buf, " This finger has been cut off %s\n" 2755 sprintf (buf, " This finger has been cut off %s\n"
2771 " the %s, when he was defeated at\n level %d by %s.\n", 2756 " the %s, when he was defeated at\n level %d by %s.\n",
2772 &op->name, op->contr->title, (int) (op->level), op->contr->killer); 2757 &op->name, op->contr->title, (int) (op->level), op->contr->killer);
2773 tmp->msg = buf; 2758 tmp->msg = buf;
2774 tmp->value = 0, tmp->material = 0, tmp->type = 0; 2759 tmp->value = 0, tmp->material = 0, tmp->type = 0;
2775 tmp->materialname = NULL; 2760 tmp->materialname = NULL;
2776 tmp->x = op->x, tmp->y = op->y; 2761 op->insert_at (tmp, op);
2777 insert_ob_in_map (tmp, op->map, op, 0);
2778 } 2762 }
2779 2763
2780 /* teleport defeated player to new destination */ 2764 /* teleport defeated player to new destination */
2781 transfer_ob (op, x, y, 0, NULL); 2765 transfer_ob (op, x, y, 0, NULL);
2782 op->contr->braced = 0; 2766 op->contr->braced = 0;
2808 op->stats.hp = op->stats.maxhp; 2792 op->stats.hp = op->stats.maxhp;
2809 return; 2793 return;
2810 } 2794 }
2811 sprintf (buf, "%s died.", &op->name); 2795 sprintf (buf, "%s died.", &op->name);
2812 } 2796 }
2797
2813 play_sound_player_only (op->contr, SOUND_PLAYER_DIES, 0, 0); 2798 play_sound_player_only (op->contr, SOUND_PLAYER_DIES, 0, 0);
2814 2799
2815 /* save the map location for corpse, gravestone */ 2800 /* save the map location for corpse, gravestone */
2816 x = op->x; 2801 x = op->x;
2817 y = op->y; 2802 y = op->y;
2818 map = op->map; 2803 map = op->map;
2819
2820 2804
2821 /* NOT_PERMADEATH code. This basically brings the character back to 2805 /* NOT_PERMADEATH code. This basically brings the character back to
2822 * life if they are dead - it takes some exp and a random stat. 2806 * life if they are dead - it takes some exp and a random stat.
2823 * See the config.h file for a little more in depth detail about this. 2807 * See the config.h file for a little more in depth detail about this.
2824 */ 2808 */
2841 num_stats_lose = 1; 2825 num_stats_lose = 1;
2842 else 2826 else
2843 num_stats_lose = 1 + op->level / BALSL_NUMBER_LOSSES_RATIO; 2827 num_stats_lose = 1 + op->level / BALSL_NUMBER_LOSSES_RATIO;
2844 } 2828 }
2845 else 2829 else
2846 {
2847 num_stats_lose = 1; 2830 num_stats_lose = 1;
2848 } 2831
2849 lost_a_stat = 0; 2832 lost_a_stat = 0;
2850 2833
2851 for (z = 0; z < num_stats_lose; z++) 2834 for (z = 0; z < num_stats_lose; z++)
2852 { 2835 {
2853 i = RANDOM () % NUM_STATS; 2836 i = RANDOM () % NUM_STATS;
3095 */ 3078 */
3096 3079
3097void 3080void
3098fix_weight (void) 3081fix_weight (void)
3099{ 3082{
3100 for (player *pl = first_player; pl; pl = pl->next) 3083 for_all_players (pl)
3101 { 3084 {
3102 int old = pl->ob->carrying, sum = sum_weight (pl->ob); 3085 int old = pl->ob->carrying, sum = sum_weight (pl->ob);
3103 3086
3104 if (old == sum) 3087 if (old == sum)
3105 continue; 3088 continue;
3109} 3092}
3110 3093
3111void 3094void
3112fix_luck (void) 3095fix_luck (void)
3113{ 3096{
3114 for (player *pl = first_player; pl; pl = pl->next) 3097 for_all_players (pl)
3115 if (!pl->ob->contr->ns->state) 3098 if (!pl->ob->contr->ns->state)
3116 pl->ob->change_luck (0); 3099 pl->ob->change_luck (0);
3117} 3100}
3118 3101
3119/* cast_dust() - handles op throwing objects of type 'DUST'. 3102/* cast_dust() - handles op throwing objects of type 'DUST'.
3336 if (pl->type != PLAYER) 3319 if (pl->type != PLAYER)
3337 { 3320 {
3338 LOG (llevError, "player_can_view() called for non-player object\n"); 3321 LOG (llevError, "player_can_view() called for non-player object\n");
3339 return -1; 3322 return -1;
3340 } 3323 }
3324
3341 if (!pl || !op) 3325 if (!pl || !op)
3342 return 0; 3326 return 0;
3343 3327
3344 if (op->head)
3345 {
3346 op = op->head; 3328 op = op->head_ ();
3347 } 3329
3348 get_rangevector (pl, op, &rv, 0x1); 3330 get_rangevector (pl, op, &rv, 0x1);
3349 3331
3350 /* starting with the 'head' part, lets loop 3332 /* starting with the 'head' part, lets loop
3351 * through the object and find if it has any 3333 * through the object and find if it has any
3352 * part that is in the los array but isnt on 3334 * part that is in the los array but isnt on

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines