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.84 by root, Wed Jan 3 20:32:13 2007 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}
160 158
161/* This loads the first map an puts the player on it. */ 159/* This loads the first map an puts the player on it. */
162static void 160static void
163set_first_map (object *op) 161set_first_map (object *op)
164{ 162{
165 strcpy (op->contr->maplevel, first_map_path); 163 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);
260
261 INVOKE_PLAYER (CONNECT, this);
249 INVOKE_PLAYER (LOGIN, this); 262 INVOKE_PLAYER (LOGIN, this);
263}
264
265void
266player::disconnect ()
267{
268 if (ob)
269 ob->deactivate_recursive ();
270
271 //TODO: don't be so harsh and destroy :)
272 if (ns)
273 {
274 if (enable_save)
275 {
276 INVOKE_PLAYER (LOGOUT, this, ARG_INT (0));
277 save (true);
278 }
279
280 INVOKE_PLAYER (DISCONNECT, this);
281
282 client *ns = this->ns;
283 ns->send_packet ("goodbye");
284 ns->flush ();
285 ns->pl = 0;
286 this->ns = 0;
287
288 ns->destroy ();
289 destroy ();
290 }
250} 291}
251 292
252// the need for this function can be explained 293// the need for this function can be explained
253// by load_object not returning the object 294// by load_object not returning the object
254void 295void
261 ob->speed = 1.0; 302 ob->speed = 1.0;
262 ob->direction = 5; /* So player faces south */ 303 ob->direction = 5; /* So player faces south */
263 ob->stats.wc = 2; 304 ob->stats.wc = 2;
264 ob->run_away = 25; /* Then we panick... */ 305 ob->run_away = 25; /* Then we panick... */
265 306
266 set_first_map (ob);
267
268 ob->roll_stats (); 307 ob->roll_stats ();
269} 308}
270 309
271player::player () 310player::player ()
272{ 311{
273 /* There are some elements we want initialized to non zero value - 312 /* There are some elements we want initialised to non zero value -
274 * we deal with that below this point. 313 * we deal with that below this point.
275 */ 314 */
276 outputs_sync = 16; /* Every 2 seconds */ 315 outputs_sync = 16; /* Every 2 seconds */
277 outputs_count = 8; /* Keeps present behaviour */ 316 outputs_count = 8; /* Keeps present behaviour */
278 unapply = unapply_nochoice; 317 unapply = unapply_nochoice;
279 318
280 assign (savebed_map, first_map_path); /* Init. respawn position */ 319 savebed_map = first_map_path; /* Init. respawn position */
281 320
282 gen_sp_armour = 10; 321 gen_sp_armour = 10;
283 last_speed = -1; 322 last_speed = -1;
284 shoottype = range_none; 323 shoottype = range_none;
285 bowtype = bow_normal; 324 bowtype = bow_normal;
303 342
304 last_stats.exp = -1; 343 last_stats.exp = -1;
305 last_weight = (uint32) - 1; 344 last_weight = (uint32) - 1;
306} 345}
307 346
308player::~player () 347void
348player::do_destroy ()
309{ 349{
350 disconnect ();
351
352 save (false);
353 enable_save = false;
354
355 attachable::do_destroy ();
356
310 terminate_all_pets (ob); 357 terminate_all_pets (ob);
311 358
312 if (first_player != this) 359 if (first_player != this)
313 { 360 {
314 player *prev = first_player; 361 player *prev = first_player;
327 else 374 else
328 first_player = next; 375 first_player = next;
329 376
330 if (ob) 377 if (ob)
331 { 378 {
332 ob->contr = 0; 379 ob->destroy_inv (false);
333 ob->destroy (1); 380 ob->destroy ();
334 }
335
336 if (ns)
337 { 381 }
338 ns->send_packet ("goodbye"); 382}
339 ns->flush ();
340 ns->pl = 0;
341 ns->destroy ();
342 }
343 383
384player::~player ()
385{
344 /* Clear item stack */ 386 /* Clear item stack */
345 free (stack_items); 387 free (stack_items);
346} 388}
347 389
348/* Tries to add player on the connection passed in ns. 390/* Tries to add player on the connection passed in ns.
353player::create () 395player::create ()
354{ 396{
355 player *pl = new player; 397 player *pl = new player;
356 398
357 pl->set_object (arch_to_object (get_player_archetype (0))); 399 pl->set_object (arch_to_object (get_player_archetype (0)));
400 set_first_map (pl->ob);
358 401
359 return pl; 402 return pl;
360} 403}
361 404
362/* 405/*
389 432
390object * 433object *
391get_nearest_player (object *mon) 434get_nearest_player (object *mon)
392{ 435{
393 object *op = NULL; 436 object *op = NULL;
394 player *pl = NULL;
395 objectlink *ol; 437 objectlink *ol;
396 unsigned lastdist; 438 unsigned lastdist;
397 rv_vector rv; 439 rv_vector rv;
398 440
399 for (ol = first_friendly_object, lastdist = 1000; ol != NULL; ol = ol->next) 441 for (ol = first_friendly_object, lastdist = 1000; ol != NULL; ol = ol->next)
431 { 473 {
432 op = ol->ob; 474 op = ol->ob;
433 lastdist = rv.distance; 475 lastdist = rv.distance;
434 } 476 }
435 } 477 }
436 for (pl = first_player; pl != NULL; pl = pl->next) 478
437 { 479 for_all_players (pl)
438 if (can_detect_enemy (mon, pl->ob, &rv)) 480 if (can_detect_enemy (mon, pl->ob, &rv))
439 {
440
441 if (lastdist > rv.distance) 481 if (lastdist > rv.distance)
442 { 482 {
443 op = pl->ob; 483 op = pl->ob;
444 lastdist = rv.distance; 484 lastdist = rv.distance;
445 } 485 }
446 } 486
447 }
448#if 0 487#if 0
449 LOG (llevDebug, "get_nearest_player() finds player: %s\n", op ? &op->name : "(null)"); 488 LOG (llevDebug, "get_nearest_player() finds player: %s\n", op ? &op->name : "(null)");
450#endif 489#endif
451 return op; 490 return op;
452} 491}
832 871
833 contr->orig_stats = stats; 872 contr->orig_stats = stats;
834 } 873 }
835} 874}
836 875
876static void
877start_info (object *op)
878{
879 char buf[MAX_BUF];
880
881 sprintf (buf, "Welcome to Crossfire v%s!", VERSION);
882 new_draw_info (NDI_UNIQUE, 0, op, buf);
883 //new_draw_info (NDI_UNIQUE, 0, op, "Press `?' for help");
884 //new_draw_info (NDI_UNIQUE, 0, op, " ");
885}
886
837/* This function takes the key that is passed, and does the 887/* This function takes the key that is passed, and does the
838 * appropriate action with it (change race, or other things). 888 * appropriate action with it (change race, or other things).
839 * The function name is for historical reasons - now we have 889 * The function name is for historical reasons - now we have
840 * separate race and class; this actually changes the RACE, 890 * separate race and class; this actually changes the RACE,
841 * not the class. 891 * not the class.
886 if (*first_map_ext_path) 936 if (*first_map_ext_path)
887 { 937 {
888 object *tmp; 938 object *tmp;
889 char mapname[MAX_BUF]; 939 char mapname[MAX_BUF];
890 940
891 snprintf (mapname, MAX_BUF - 1, "%s/%s", first_map_ext_path, &op->arch->name); 941 snprintf (mapname, MAX_BUF - 1, "%s/%s", &first_map_ext_path, &op->arch->name);
892 tmp = object::create (); 942 tmp = object::create ();
893 EXIT_PATH (tmp) = mapname; 943 EXIT_PATH (tmp) = mapname;
894 EXIT_X (tmp) = op->x; 944 EXIT_X (tmp) = op->x;
895 EXIT_Y (tmp) = op->y; 945 EXIT_Y (tmp) = op->y;
896 enter_exit (op, tmp); /* we don't really care if it succeeded; 946 op->enter_exit (tmp); /* we don't really care if it succeeded;
897 * if the map isn't there, then stay on the 947 * if the map isn't there, then stay on the
898 * default initial map */ 948 * default initial map */
899 tmp->destroy (); 949 tmp->destroy ();
900 } 950 }
901 else 951 else
955 } 1005 }
956 1006
957 INVOKE_PLAYER (LOGOUT, op->contr); 1007 INVOKE_PLAYER (LOGOUT, op->contr);
958 INVOKE_PLAYER (QUIT, op->contr); 1008 INVOKE_PLAYER (QUIT, op->contr);
959 1009
1010 op->contr->enable_save = false;
1011
960 terminate_all_pets (op); 1012 terminate_all_pets (op);
961 leave_map (op); 1013 op->remove ();
962 op->direction = 0; 1014 op->direction = 0;
963 new_draw_info_format (NDI_UNIQUE | NDI_ALL, 5, NULL, "%s quits the game.", &op->name); 1015 new_draw_info_format (NDI_UNIQUE | NDI_ALL, 5, NULL, "%s quits the game.", &op->name);
964 1016
965 strcpy (op->contr->killer, "quit"); 1017 strcpy (op->contr->killer, "quit");
966 check_score (op); 1018 check_score (op);
967 op->contr->party = 0; 1019 op->contr->party = 0;
968 op->contr->own_title[0] = '\0'; 1020 op->contr->own_title[0] = '\0';
969 1021 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 1022
991 return 1; 1023 return 1;
992} 1024}
993 1025
994void 1026void
1133 sprintf (putstring, "item name: %s item type: %d weight/value: %d", 1165 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)))); 1166 &tmp->name, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))));
1135 else 1167 else
1136 sprintf (putstring, "item name: %s item type: %d weight/value: %d", 1168 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)))); 1169 &tmp->arch->name, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))));
1170
1138 new_draw_info (NDI_UNIQUE, 0, op, putstring); 1171 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 } 1172 }
1173
1169 /* philosophy: 1174 /* philosophy:
1170 * It's easy to grab an item type from a pile, as long as it's 1175 * 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 1176 * generic. This takes no game-time. For more detailed pickups
1172 * and selections, select-items shoul dbe used. This is a 1177 * and selections, select-items should be used. This is a
1173 * grab-as-you-run type mode that's really useful for arrows for 1178 * grab-as-you-run type mode that's really useful for arrows for
1174 * example. 1179 * example.
1175 * The drawback: right now it has no frontend, so you need to 1180 * 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 1181 * stick the bits you want into a calculator in hex mode and then
1177 * convert to decimal and then 'pickup <#> 1182 * convert to decimal and then 'pickup <#>
1677 return 0; 1682 return 0;
1678 } 1683 }
1679 1684
1680 arrow->set_owner (op); 1685 arrow->set_owner (op);
1681 arrow->skill = bow->skill; 1686 arrow->skill = bow->skill;
1682
1683 arrow->direction = dir; 1687 arrow->direction = dir;
1684 arrow->x = sx;
1685 arrow->y = sy;
1686 1688
1687 if (op->type == PLAYER) 1689 if (op->type == PLAYER)
1688 { 1690 {
1689 op->speed_left = 0.01 - (float) FABS (op->speed) * 100 / bowspeed; 1691 op->speed_left = 0.01 - (float) FABS (op->speed) * 100 / bowspeed;
1690 op->update_stats (); 1692 op->update_stats ();
1705 1707
1706 /* update the speed */ 1708 /* update the speed */
1707 arrow->speed = (float) ((QUERY_FLAG (bow, FLAG_NO_STRENGTH) ? 1709 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; 1710 0 : dam_bonus[op->stats.Str]) + bow->magic + arrow->magic) / 5.0 + (float) bow->stats.dam / 7.0;
1709 1711
1710 if (arrow->speed < 1.0) 1712 arrow->set_speed (max (arrow->speed, 1.0));
1711 arrow->speed = 1.0;
1712 update_ob_speed (arrow);
1713 arrow->speed_left = 0; 1713 arrow->speed_left = 0;
1714 1714
1715 if (op->type == PLAYER) 1715 if (op->type == PLAYER)
1716 { 1716 {
1717 arrow->stats.wc = 20 - bow->magic - arrow->magic - 1717 arrow->stats.wc = 20 - bow->magic - arrow->magic -
1730 arrow->attacktype |= bow->attacktype; 1730 arrow->attacktype |= bow->attacktype;
1731 1731
1732 if (bow->slaying) 1732 if (bow->slaying)
1733 arrow->slaying = bow->slaying; 1733 arrow->slaying = bow->slaying;
1734 1734
1735 arrow->map = m;
1736 arrow->move_type = MOVE_FLY_LOW; 1735 arrow->move_type = MOVE_FLY_LOW;
1737 arrow->move_on = MOVE_FLY_LOW | MOVE_WALK; 1736 arrow->move_on = MOVE_FLY_LOW | MOVE_WALK;
1738 1737
1739 play_sound_map (op->map, op->x, op->y, SOUND_FIRE_ARROW); 1738 play_sound_map (op->map, op->x, op->y, SOUND_FIRE_ARROW);
1740 insert_ob_in_map (arrow, m, op, 0); 1739 m->insert (arrow, sx, sy, op);
1741 1740
1742 if (!arrow->destroyed ()) 1741 if (!arrow->destroyed ())
1743 move_arrow (arrow); 1742 move_arrow (arrow);
1744 1743
1745 if (op->type == PLAYER) 1744 if (op->type == PLAYER)
1771 } 1770 }
1772 else if (op->contr->bowtype >= bow_n && op->contr->bowtype <= bow_nw) 1771 else if (op->contr->bowtype >= bow_n && op->contr->bowtype <= bow_nw)
1773 { 1772 {
1774 if (!similar_direction (dir, op->contr->bowtype - bow_n + 1)) 1773 if (!similar_direction (dir, op->contr->bowtype - bow_n + 1))
1775 wcmod = -1; 1774 wcmod = -1;
1775
1776 ret = fire_bow (op, op, NULL, op->contr->bowtype - bow_n + 1, wcmod, op->x, op->y); 1776 ret = fire_bow (op, op, NULL, op->contr->bowtype - bow_n + 1, wcmod, op->x, op->y);
1777 } 1777 }
1778 else if (op->contr->bowtype == bow_threewide) 1778 else if (op->contr->bowtype == bow_threewide)
1779 { 1779 {
1780 ret = fire_bow (op, op, NULL, dir, 0, op->x, op->y); 1780 ret = fire_bow (op, op, NULL, dir, 0, op->x, op->y);
1850 1850
1851 if (item->arch) 1851 if (item->arch)
1852 { 1852 {
1853 CLEAR_FLAG (item, FLAG_ANIMATE); 1853 CLEAR_FLAG (item, FLAG_ANIMATE);
1854 item->face = item->arch->clone.face; 1854 item->face = item->arch->clone.face;
1855 item->speed = 0; 1855 item->set_speed (0);
1856 update_ob_speed (item);
1857 } 1856 }
1857
1858 if ((tmp = item->in_player ())) 1858 if ((tmp = item->in_player ()))
1859 esrv_update_item (UPD_ANIM, tmp, item); 1859 esrv_update_item (UPD_ANIM, tmp, item);
1860 } 1860 }
1861 } 1861 }
1862 else if (item->type == ROD || item->type == HORN) 1862 else if (item->type == ROD || item->type == HORN)
1863 {
1864 drain_rod_charge (item); 1863 drain_rod_charge (item);
1865 }
1866 } 1864 }
1867} 1865}
1868 1866
1869/* Received a fire command for the player - go and do it. 1867/* Received a fire command for the player - go and do it.
1870 */ 1868 */
2256int 2254int
2257move_player (object *op, int dir) 2255move_player (object *op, int dir)
2258{ 2256{
2259 int pick; 2257 int pick;
2260 2258
2261 if (op->map == NULL || op->map->in_memory != MAP_IN_MEMORY) 2259 if (!op->map || op->map->in_memory != MAP_IN_MEMORY)
2262 return 0; 2260 return 0;
2263 2261
2264 /* Sanity check: make sure dir is valid */ 2262 /* Sanity check: make sure dir is valid */
2265 if ((dir < 0) || (dir >= 9)) 2263 if ((dir < 0) || (dir >= 9))
2266 { 2264 {
2267 LOG (llevError, "move_player: invalid direction %d\n", dir); 2265 LOG (llevError, "move_player: invalid direction %d\n", dir);
2268 return 0; 2266 return 0;
2269 } 2267 }
2270 2268
2271 /* peterm: added following line */ 2269 /* peterm: added following line */
2272 if (QUERY_FLAG (op, FLAG_CONFUSED) && dir) 2270 if (QUERY_FLAG (op, FLAG_CONFUSED) && dir)
2273 dir = absdir (dir + RANDOM () % 3 + RANDOM () % 3 - 2); 2271 dir = absdir (dir + RANDOM () % 3 + RANDOM () % 3 - 2);
2274 2272
2275 op->facing = dir; 2273 op->facing = dir;
2276 2274
2354 2352
2355 /* call this here - we also will call this in do_ericserver, but 2353 /* call this here - we also will call this in do_ericserver, but
2356 * the players time has been increased when doericserver has been 2354 * the players time has been increased when doericserver has been
2357 * called, so we recheck it here. 2355 * called, so we recheck it here.
2358 */ 2356 */
2359 //TODO: better than handling 8 commands, use some more intelligent rate-limiting 2357 if (op->contr->ns->handle_command ())
2360 for (int rep = 8; --rep && op->contr->ns->handle_command (); ) 2358 return 1;
2361 ;
2362 2359
2363 if (op->speed_left < 0) 2360 if (op->speed_left > 0)
2364 return 0; 2361 {
2365
2366 if (op->direction && (op->contr->run_on || op->contr->fire_on)) 2362 if (op->direction && (op->contr->run_on || op->contr->fire_on))
2367 { 2363 {
2368 /* All move commands take 1 tick, at least for now */ 2364 /* All move commands take 1 tick, at least for now */
2369 op->speed_left--; 2365 op->speed_left--;
2370 2366
2371 /* Instead of all the stuff below, let move_player take care 2367 /* Instead of all the stuff below, let move_player take care
2372 * of it. Also, some of the skill stuff is only put in 2368 * of it. Also, some of the skill stuff is only put in
2373 * there, as well as the confusion stuff. 2369 * there, as well as the confusion stuff.
2374 */ 2370 */
2375 move_player (op, op->direction); 2371 move_player (op, op->direction);
2376 if (op->speed_left > 0) 2372
2377 return 1; 2373 return op->speed_left > 0;
2378 else 2374 }
2379 return 0;
2380 } 2375 }
2381 2376
2382 return 0; 2377 return 0;
2383} 2378}
2384 2379
2426{ 2421{
2427 object *next; 2422 object *next;
2428 2423
2429 while (op) 2424 while (op)
2430 { 2425 {
2431 next = op->below; /* Make sure we have a good value, in case 2426 object *next = op->below; /* Make sure we have a good value, in case we remove object 'op' */
2432 * we remove object 'op' 2427
2433 */
2434 if (QUERY_FLAG (op, FLAG_UNPAID)) 2428 if (QUERY_FLAG (op, FLAG_UNPAID))
2435 { 2429 {
2436 op->remove ();
2437 op->x = env->x;
2438 op->y = env->y;
2439 if (env->type == PLAYER) 2430 if (env->type == PLAYER)
2440 esrv_del_item (env->contr, op->count); 2431 esrv_del_item (env->contr, op->count);
2441 insert_ob_in_map (op, env->map, NULL, 0); 2432
2433 op->insert_at (env);
2442 } 2434 }
2443 else if (op->inv) 2435 else if (op->inv)
2444 remove_unpaid_objects (op->inv, env); 2436 remove_unpaid_objects (op->inv, env);
2445 2437
2446 op = next; 2438 op = next;
2739 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, "You have been defeated in combat!"); 2731 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..."); 2732 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, "Local medics have saved your life...");
2741 2733
2742 /* restore player */ 2734 /* restore player */
2743 at = archetype::find ("poisoning"); 2735 at = archetype::find ("poisoning");
2744 tmp = present_arch_in_ob (at, op); 2736 if (object *tmp = present_arch_in_ob (at, op))
2745 if (tmp)
2746 { 2737 {
2747 tmp->destroy (); 2738 tmp->destroy ();
2748 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed"); 2739 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed");
2749 } 2740 }
2750 2741
2751 at = archetype::find ("confusion"); 2742 at = archetype::find ("confusion");
2752 tmp = present_arch_in_ob (at, op); 2743 if (object *tmp = present_arch_in_ob (at, op))
2753 if (tmp)
2754 { 2744 {
2755 tmp->destroy (); 2745 tmp->destroy ();
2756 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer"); 2746 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer");
2757 } 2747 }
2758 2748
2760 op->stats.hp = op->stats.maxhp; 2750 op->stats.hp = op->stats.maxhp;
2761 if (op->stats.food <= 0) 2751 if (op->stats.food <= 0)
2762 op->stats.food = 999; 2752 op->stats.food = 999;
2763 2753
2764 /* create a bodypart-trophy to make the winner happy */ 2754 /* create a bodypart-trophy to make the winner happy */
2765 tmp = arch_to_object (archetype::find ("finger")); 2755 if (object *tmp = arch_to_object (archetype::find ("finger")))
2766 if (tmp != NULL)
2767 { 2756 {
2768 sprintf (buf, "%s's finger", &op->name); 2757 sprintf (buf, "%s's finger", &op->name);
2769 tmp->name = buf; 2758 tmp->name = buf;
2770 sprintf (buf, " This finger has been cut off %s\n" 2759 sprintf (buf, " This finger has been cut off %s\n"
2771 " the %s, when he was defeated at\n level %d by %s.\n", 2760 " 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); 2761 &op->name, op->contr->title, (int) (op->level), op->contr->killer);
2773 tmp->msg = buf; 2762 tmp->msg = buf;
2774 tmp->value = 0, tmp->material = 0, tmp->type = 0; 2763 tmp->value = 0, tmp->material = 0, tmp->type = 0;
2775 tmp->materialname = NULL; 2764 tmp->materialname = NULL;
2776 tmp->x = op->x, tmp->y = op->y; 2765 op->insert_at (tmp, op);
2777 insert_ob_in_map (tmp, op->map, op, 0);
2778 } 2766 }
2779 2767
2780 /* teleport defeated player to new destination */ 2768 /* teleport defeated player to new destination */
2781 transfer_ob (op, x, y, 0, NULL); 2769 transfer_ob (op, x, y, 0, NULL);
2782 op->contr->braced = 0; 2770 op->contr->braced = 0;
2808 op->stats.hp = op->stats.maxhp; 2796 op->stats.hp = op->stats.maxhp;
2809 return; 2797 return;
2810 } 2798 }
2811 sprintf (buf, "%s died.", &op->name); 2799 sprintf (buf, "%s died.", &op->name);
2812 } 2800 }
2801
2813 play_sound_player_only (op->contr, SOUND_PLAYER_DIES, 0, 0); 2802 play_sound_player_only (op->contr, SOUND_PLAYER_DIES, 0, 0);
2814 2803
2815 /* save the map location for corpse, gravestone */ 2804 /* save the map location for corpse, gravestone */
2816 x = op->x; 2805 x = op->x;
2817 y = op->y; 2806 y = op->y;
2818 map = op->map; 2807 map = op->map;
2819
2820 2808
2821 /* NOT_PERMADEATH code. This basically brings the character back to 2809 /* NOT_PERMADEATH code. This basically brings the character back to
2822 * life if they are dead - it takes some exp and a random stat. 2810 * 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. 2811 * See the config.h file for a little more in depth detail about this.
2824 */ 2812 */
2841 num_stats_lose = 1; 2829 num_stats_lose = 1;
2842 else 2830 else
2843 num_stats_lose = 1 + op->level / BALSL_NUMBER_LOSSES_RATIO; 2831 num_stats_lose = 1 + op->level / BALSL_NUMBER_LOSSES_RATIO;
2844 } 2832 }
2845 else 2833 else
2846 {
2847 num_stats_lose = 1; 2834 num_stats_lose = 1;
2848 } 2835
2849 lost_a_stat = 0; 2836 lost_a_stat = 0;
2850 2837
2851 for (z = 0; z < num_stats_lose; z++) 2838 for (z = 0; z < num_stats_lose; z++)
2852 { 2839 {
2853 i = RANDOM () % NUM_STATS; 2840 i = RANDOM () % NUM_STATS;
3095 */ 3082 */
3096 3083
3097void 3084void
3098fix_weight (void) 3085fix_weight (void)
3099{ 3086{
3100 for (player *pl = first_player; pl; pl = pl->next) 3087 for_all_players (pl)
3101 { 3088 {
3102 int old = pl->ob->carrying, sum = sum_weight (pl->ob); 3089 int old = pl->ob->carrying, sum = sum_weight (pl->ob);
3103 3090
3104 if (old == sum) 3091 if (old == sum)
3105 continue; 3092 continue;
3109} 3096}
3110 3097
3111void 3098void
3112fix_luck (void) 3099fix_luck (void)
3113{ 3100{
3114 for (player *pl = first_player; pl; pl = pl->next) 3101 for_all_players (pl)
3115 if (!pl->ob->contr->ns->state) 3102 if (!pl->ob->contr->ns->state)
3116 pl->ob->change_luck (0); 3103 pl->ob->change_luck (0);
3117} 3104}
3118 3105
3119/* cast_dust() - handles op throwing objects of type 'DUST'. 3106/* cast_dust() - handles op throwing objects of type 'DUST'.
3336 if (pl->type != PLAYER) 3323 if (pl->type != PLAYER)
3337 { 3324 {
3338 LOG (llevError, "player_can_view() called for non-player object\n"); 3325 LOG (llevError, "player_can_view() called for non-player object\n");
3339 return -1; 3326 return -1;
3340 } 3327 }
3328
3341 if (!pl || !op) 3329 if (!pl || !op)
3342 return 0; 3330 return 0;
3343 3331
3344 if (op->head)
3345 {
3346 op = op->head; 3332 op = op->head_ ();
3347 } 3333
3348 get_rangevector (pl, op, &rv, 0x1); 3334 get_rangevector (pl, op, &rv, 0x1);
3349 3335
3350 /* starting with the 'head' part, lets loop 3336 /* starting with the 'head' part, lets loop
3351 * through the object and find if it has any 3337 * through the object and find if it has any
3352 * part that is in the los array but isnt on 3338 * part that is in the los array but isnt on
3482 if (trlist == NULL || who->type != PLAYER) 3468 if (trlist == NULL || who->type != PLAYER)
3483 return; 3469 return;
3484 3470
3485 for (i = 0, tr = trlist->items; tr != NULL && i < level - 1; tr = tr->next, i++); 3471 for (i = 0, tr = trlist->items; tr != NULL && i < level - 1; tr = tr->next, i++);
3486 3472
3487 if (tr == NULL || tr->item == NULL) 3473 if (!tr || !tr->item)
3488 { 3474 {
3489 /* LOG(llevDebug, "-> no more treasure for %s\n", change_resist_msg[atnr]); */ 3475 /* LOG(llevDebug, "-> no more treasure for %s\n", change_resist_msg[atnr]); */
3490 return; 3476 return;
3491 } 3477 }
3492 3478

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines