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.54 by root, Fri Dec 22 16:34:00 2006 UTC vs.
Revision 1.91 by root, Sun Jan 7 23:10:43 2007 UTC

1/* 1/*
2 CrossFire, A Multiplayer game for X-windows 2 * CrossFire, A Multiplayer game
3 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
4 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team
5 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (C) 1992 Frank Tore Johansen
6 7 *
7 This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version. 11 * (at your option) any later version.
11 12 *
12 This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 16 * GNU General Public License for more details.
16 17 *
17 You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software 19 * along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 21 *
21 The author can be reached via e-mail to <crossfire@schmorp.de> 22 * The author can be reached via e-mail to <crossfire@schmorp.de>
22*/ 23 */
23 24
24#include <global.h> 25#include <global.h>
25#include <pwd.h> 26#include <pwd.h>
26#include <sproto.h> 27#include <sproto.h>
27#include <sounds.h> 28#include <sounds.h>
31#include <skills.h> 32#include <skills.h>
32 33
33#include <algorithm> 34#include <algorithm>
34#include <functional> 35#include <functional>
35 36
36player * 37playervec players;
37find_player (const char *plname)
38{
39 player *pl;
40
41 for (pl = first_player; pl; pl = pl->next)
42 if (pl->ob && !strcmp (query_name (pl->ob), plname))
43 return pl;
44
45 return 0;
46}
47 38
48void 39void
49display_motd (const object *op) 40display_motd (const object *op)
50{ 41{
51 char buf[MAX_BUF]; 42 char buf[MAX_BUF];
134 125
135 if (*buf == '%') 126 if (*buf == '%')
136 { /* send one news */ 127 { /* send one news */
137 if (size > 0) 128 if (size > 0)
138 draw_ext_info_format (NDI_UNIQUE | NDI_GREEN, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_NEWS, "INFORMATION: %s\n%s", "%s\n%s", subject, news); /*send previously read news */ 129 draw_ext_info_format (NDI_UNIQUE | NDI_GREEN, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_NEWS, "INFORMATION: %s\n%s", "%s\n%s", subject, news); /*send previously read news */
130
139 strcpy (subject, buf + 1); 131 strcpy (subject, buf + 1);
140 strip_endline (subject); 132 strip_endline (subject);
141 size = 0; 133 size = 0;
142 news[0] = '\0'; 134 news[0] = '\0';
143 } 135 }
160 152
161/* This loads the first map an puts the player on it. */ 153/* This loads the first map an puts the player on it. */
162static void 154static void
163set_first_map (object *op) 155set_first_map (object *op)
164{ 156{
165 strcpy (op->contr->maplevel, first_map_path); 157 op->contr->maplevel = first_map_path;
166 op->x = -1; 158 op->x = -1;
167 op->y = -1; 159 op->y = -1;
160}
161
162void
163player::enter_map ()
164{
165 object *tmp = object::create ();
166
167 EXIT_PATH (tmp) = maplevel;
168 EXIT_X (tmp) = ob->x;
169 EXIT_Y (tmp) = ob->y;
168 enter_exit (op, 0); 170 ob->enter_exit (tmp);
169}
170 171
172 tmp->destroy ();
173}
174
175void
176player::activate ()
177{
178 if (active)
179 return;
180
181 players.insert (this);
182 ob->remove ();
183 ob->map = 0;
184 ob->activate_recursive ();
185 enter_map ();
186}
187
188void
189player::deactivate ()
190{
191 if (!active)
192 return;
193
194 terminate_all_pets (ob);
195 ob->deactivate_recursive ();
196 ob->remove ();
197 ob->map = 0;
198
199 players.erase (this);
200}
201
202// connect the player with a specific client
203// also changed, rationalises, and fixes some incorrect settings
171void 204void
172player::connect (client *ns) 205player::connect (client *ns)
173{ 206{
174 this->ns = ns; 207 this->ns = ns;
175 ns->pl = this; 208 ns->pl = this;
176 209
177 next = first_player;
178 first_player = this;
179
180 ns->update_look = 0; 210 ns->update_look = 0;
181 ns->look_position = 0; 211 ns->look_position = 0;
182 212
183 clear_los (ob); 213 clear_los (ob);
184 214
215 /* make sure he's a player -- needed because of class change. */
185 ob->type = PLAYER; // we are paranoid 216 ob->type = PLAYER; // we are paranoid
186 ob->race = ob->arch->clone.race; 217 ob->race = ob->arch->clone.race;
187 218
188 CLEAR_FLAG (ob, FLAG_NO_FIX_PLAYER); 219 if (!legal_range (ob, shoottype))
189 ob->update_stats (); 220 shoottype = range_none;
190 update_ob_speed (ob);
191 221
192 ob->carrying = sum_weight (ob); 222 ob->carrying = sum_weight (ob);
193 link_player_skills (ob); 223 link_player_skills (ob);
194 224
195 if (!legal_range (ob, shoottype)) 225 CLEAR_FLAG (ob, FLAG_NO_FIX_PLAYER);
196 shoottype = range_none;
197 226
198 assign (title, ob->arch->clone.name); 227 assign (title, ob->arch->clone.name);
199 228
200 /* can_use_shield is a new flag. However, the can_use.. seems to largely come 229 /* can_use_shield is a new flag. However, the can_use.. seems to largely come
201 * from the class, and not race. I don't see any way to get the class information 230 * from the class, and not race. I don't see any way to get the class information
226 } 255 }
227 256
228 CLEAR_FLAG (ob, FLAG_FRIENDLY); 257 CLEAR_FLAG (ob, FLAG_FRIENDLY);
229 add_friendly_object (ob); 258 add_friendly_object (ob);
230 259
231 LOG (llevInfo, "LOGIN: Player named %s from ip %s\n", &ob->name, ns->host);
232
233 new_draw_info (NDI_UNIQUE, 0, ob, "Welcome Back!"); 260 new_draw_info (NDI_UNIQUE, 0, ob, "Welcome Back!");
234 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, NULL, "%s has entered the game.", &ob->name);
235 261
262 esrv_new_player (this, ob->weight + ob->carrying);
263
264 ob->update_stats ();
236 ns->floorbox_update (); 265 ns->floorbox_update ();
237 266
238 esrv_new_player (this, ob->weight + ob->carrying);
239 esrv_send_inventory (ob, ob); 267 esrv_send_inventory (ob, ob);
240 esrv_add_spells (this, 0); 268 esrv_add_spells (this, 0);
241 269
242 enter_exit (ob, 0); 270 activate ();
243 271
244// send_rules (ob);//TODO 272 send_rules (ob);
245// send_news (ob);//TODO 273 send_news (ob);
246// display_motd (ob);//TODO 274 display_motd (ob);
275
276 INVOKE_PLAYER (CONNECT, this);
247 INVOKE_PLAYER (LOGIN, this); 277 INVOKE_PLAYER (LOGIN, this);
278}
279
280void
281player::disconnect ()
282{
283 if (ns)
284 {
285 if (active)
286 INVOKE_PLAYER (LOGOUT, this, ARG_INT (0));
287
288 INVOKE_PLAYER (DISCONNECT, this);
289
290 ns->pl = 0;
291 this->ns = 0;
292 }
293
294 deactivate ();
248} 295}
249 296
250// the need for this function can be explained 297// the need for this function can be explained
251// by load_object not returning the object 298// by load_object not returning the object
252void 299void
259 ob->speed = 1.0; 306 ob->speed = 1.0;
260 ob->direction = 5; /* So player faces south */ 307 ob->direction = 5; /* So player faces south */
261 ob->stats.wc = 2; 308 ob->stats.wc = 2;
262 ob->run_away = 25; /* Then we panick... */ 309 ob->run_away = 25; /* Then we panick... */
263 310
264 set_first_map (ob);
265
266 ob->roll_stats (); 311 ob->roll_stats ();
267} 312}
268 313
269player::player () 314player::player ()
270{ 315{
271 /* There are some elements we want initialized to non zero value - 316 /* There are some elements we want initialised to non zero value -
272 * we deal with that below this point. 317 * we deal with that below this point.
273 */ 318 */
274 outputs_sync = 16; /* Every 2 seconds */ 319 outputs_sync = 16; /* Every 2 seconds */
275 outputs_count = 8; /* Keeps present behaviour */ 320 outputs_count = 8; /* Keeps present behaviour */
276 unapply = unapply_nochoice; 321 unapply = unapply_nochoice;
277 322
278 assign (savebed_map, first_map_path); /* Init. respawn position */ 323 savebed_map = first_map_path; /* Init. respawn position */
279 324
280 gen_sp_armour = 10; 325 gen_sp_armour = 10;
281 last_speed = -1; 326 last_speed = -1;
282 shoottype = range_none; 327 shoottype = range_none;
283 bowtype = bow_normal; 328 bowtype = bow_normal;
301 346
302 last_stats.exp = -1; 347 last_stats.exp = -1;
303 last_weight = (uint32) - 1; 348 last_weight = (uint32) - 1;
304} 349}
305 350
351void
352player::do_destroy ()
353{
354 disconnect ();
355
356 attachable::do_destroy ();
357
358 if (ob)
359 {
360 ob->destroy_inv (false);
361 ob->destroy ();
362 }
363}
364
306player::~player () 365player::~player ()
307{ 366{
308 terminate_all_pets (ob);
309
310 if (first_player != this)
311 {
312 player *prev = first_player;
313
314 while (prev && prev->next && prev->next != this)
315 prev = prev->next;
316
317 if (prev->next != this)
318 {
319 LOG (llevError, "Free_player: Can't find previous player.\n");
320 abort ();
321 }
322
323 prev->next = next;
324 }
325 else
326 first_player = next;
327
328 if (ob)
329 {
330 ob->contr = 0;
331 ob->destroy (1);
332 }
333
334 if (ns)
335 {
336 ns->send_packet ("goodbye");
337 ns->flush ();
338 ns->pl = 0;
339 ns->destroy ();
340 }
341
342 /* Clear item stack */ 367 /* Clear item stack */
343 free (stack_items); 368 free (stack_items);
344} 369}
345 370
346/* Tries to add player on the connection passed in ns. 371/* Tries to add player on the connection passed in ns.
351player::create () 376player::create ()
352{ 377{
353 player *pl = new player; 378 player *pl = new player;
354 379
355 pl->set_object (arch_to_object (get_player_archetype (0))); 380 pl->set_object (arch_to_object (get_player_archetype (0)));
381 set_first_map (pl->ob);
356 382
357 return pl; 383 return pl;
358} 384}
359 385
360/* 386/*
387 413
388object * 414object *
389get_nearest_player (object *mon) 415get_nearest_player (object *mon)
390{ 416{
391 object *op = NULL; 417 object *op = NULL;
392 player *pl = NULL;
393 objectlink *ol; 418 objectlink *ol;
394 unsigned lastdist; 419 unsigned lastdist;
395 rv_vector rv; 420 rv_vector rv;
396 421
397 for (ol = first_friendly_object, lastdist = 1000; ol != NULL; ol = ol->next) 422 for (ol = first_friendly_object, lastdist = 1000; ol != NULL; ol = ol->next)
429 { 454 {
430 op = ol->ob; 455 op = ol->ob;
431 lastdist = rv.distance; 456 lastdist = rv.distance;
432 } 457 }
433 } 458 }
434 for (pl = first_player; pl != NULL; pl = pl->next) 459
435 { 460 for_all_players (pl)
436 if (can_detect_enemy (mon, pl->ob, &rv)) 461 if (can_detect_enemy (mon, pl->ob, &rv))
437 {
438
439 if (lastdist > rv.distance) 462 if (lastdist > rv.distance)
440 { 463 {
441 op = pl->ob; 464 op = pl->ob;
442 lastdist = rv.distance; 465 lastdist = rv.distance;
443 } 466 }
444 } 467
445 }
446#if 0 468#if 0
447 LOG (llevDebug, "get_nearest_player() finds player: %s\n", op ? &op->name : "(null)"); 469 LOG (llevDebug, "get_nearest_player() finds player: %s\n", op ? &op->name : "(null)");
448#endif 470#endif
449 return op; 471 return op;
450} 472}
830 852
831 contr->orig_stats = stats; 853 contr->orig_stats = stats;
832 } 854 }
833} 855}
834 856
857static void
858start_info (object *op)
859{
860 char buf[MAX_BUF];
861
862 sprintf (buf, "Welcome to Crossfire v%s!", VERSION);
863 new_draw_info (NDI_UNIQUE, 0, op, buf);
864 //new_draw_info (NDI_UNIQUE, 0, op, "Press `?' for help");
865 //new_draw_info (NDI_UNIQUE, 0, op, " ");
866}
867
835/* This function takes the key that is passed, and does the 868/* This function takes the key that is passed, and does the
836 * appropriate action with it (change race, or other things). 869 * appropriate action with it (change race, or other things).
837 * The function name is for historical reasons - now we have 870 * The function name is for historical reasons - now we have
838 * separate race and class; this actually changes the RACE, 871 * separate race and class; this actually changes the RACE,
839 * not the class. 872 * not the class.
884 if (*first_map_ext_path) 917 if (*first_map_ext_path)
885 { 918 {
886 object *tmp; 919 object *tmp;
887 char mapname[MAX_BUF]; 920 char mapname[MAX_BUF];
888 921
889 snprintf (mapname, MAX_BUF - 1, "%s/%s", first_map_ext_path, &op->arch->name); 922 snprintf (mapname, MAX_BUF - 1, "%s/%s", &first_map_ext_path, &op->arch->name);
890 tmp = object::create (); 923 tmp = object::create ();
891 EXIT_PATH (tmp) = mapname; 924 EXIT_PATH (tmp) = mapname;
892 EXIT_X (tmp) = op->x; 925 EXIT_X (tmp) = op->x;
893 EXIT_Y (tmp) = op->y; 926 EXIT_Y (tmp) = op->y;
894 enter_exit (op, tmp); /* we don't really care if it succeeded; 927 op->enter_exit (tmp); /* we don't really care if it succeeded;
895 * if the map isn't there, then stay on the 928 * if the map isn't there, then stay on the
896 * default initial map */ 929 * default initial map */
897 tmp->destroy (); 930 tmp->destroy ();
898 } 931 }
899 else 932 else
938 if (op->msg) 971 if (op->msg)
939 new_draw_info (NDI_BLUE, 0, op, op->msg); 972 new_draw_info (NDI_BLUE, 0, op, op->msg);
940 973
941 send_query (op->contr->ns, CS_QUERY_SINGLECHAR, "Press any key for the next race.\nPress `d' to play this race.\n"); 974 send_query (op->contr->ns, CS_QUERY_SINGLECHAR, "Press any key for the next race.\nPress `d' to play this race.\n");
942 return 0; 975 return 0;
943}
944
945int
946key_confirm_quit (object *op, char key)
947{
948 if (key != 'y' && key != 'Y' && key != 'q' && key != 'Q')
949 {
950 op->contr->ns->state = ST_PLAYING;
951 new_draw_info (NDI_UNIQUE, 0, op, "OK, continuing to play.");
952 return 1;
953 }
954
955 INVOKE_PLAYER (LOGOUT, op->contr);
956 INVOKE_PLAYER (QUIT, op->contr);
957
958 terminate_all_pets (op);
959 leave_map (op);
960 op->direction = 0;
961 new_draw_info_format (NDI_UNIQUE | NDI_ALL, 5, NULL, "%s quits the game.", &op->name);
962
963 strcpy (op->contr->killer, "quit");
964 check_score (op);
965 op->contr->party = 0;
966 op->contr->own_title[0] = '\0';
967
968 object_ptr ob = op;
969
970 delete ob->contr;
971
972 /* We need to hunt for any per player unique maps in memory and
973 * get rid of them. The trailing slash in the path is intentional,
974 * so that players named 'Ab' won't match against players 'Abe' pathname
975 */
976 char buf[MAX_BUF];
977 sprintf (buf, "%s/%s/%s/", settings.localdir, settings.playerdir, &op->name);
978
979 for (maptile *next, *mp = first_map; mp; mp = next)
980 {
981 next = mp->next;
982
983 if (!strncmp (mp->path, buf, strlen (buf)))
984 delete_map (mp);
985 }
986
987 delete_character (ob->name, 1);
988
989 return 1;
990} 976}
991 977
992void 978void
993flee_player (object *op) 979flee_player (object *op)
994{ 980{
1131 sprintf (putstring, "item name: %s item type: %d weight/value: %d", 1117 sprintf (putstring, "item name: %s item type: %d weight/value: %d",
1132 &tmp->name, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1)))); 1118 &tmp->name, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))));
1133 else 1119 else
1134 sprintf (putstring, "item name: %s item type: %d weight/value: %d", 1120 sprintf (putstring, "item name: %s item type: %d weight/value: %d",
1135 &tmp->arch->name, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1)))); 1121 &tmp->arch->name, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))));
1122
1136 new_draw_info (NDI_UNIQUE, 0, op, putstring); 1123 new_draw_info (NDI_UNIQUE, 0, op, putstring);
1137
1138 sprintf (putstring, "...flags: ");
1139 for (k = 0; k < 4; k++)
1140 {
1141 for (j = 0; j < 32; j++)
1142 {
1143 if ((tmp->flags[k] >> j) & 0x01)
1144 {
1145 sprintf (tmpstr, "%d ", k * 32 + j);
1146 strcat (putstring, tmpstr);
1147 }
1148 }
1149 }
1150 new_draw_info (NDI_UNIQUE, 0, op, putstring);
1151
1152#if 0
1153 /* print the flags too */
1154 for (k = 0; k < 4; k++)
1155 {
1156 fprintf (stderr, "%d [%d] ", k, k * 32 + 31);
1157 for (j = 0; j < 32; j++)
1158 {
1159 fprintf (stderr, "%d", tmp->flags[k] >> (31 - j) & 0x01);
1160 if (!((j + 1) % 4))
1161 fprintf (stderr, " ");
1162 }
1163 fprintf (stderr, " [%d]\n", k * 32);
1164 }
1165#endif
1166 } 1124 }
1125
1167 /* philosophy: 1126 /* philosophy:
1168 * It's easy to grab an item type from a pile, as long as it's 1127 * It's easy to grab an item type from a pile, as long as it's
1169 * generic. This takes no game-time. For more detailed pickups 1128 * generic. This takes no game-time. For more detailed pickups
1170 * and selections, select-items shoul dbe used. This is a 1129 * and selections, select-items should be used. This is a
1171 * grab-as-you-run type mode that's really useful for arrows for 1130 * grab-as-you-run type mode that's really useful for arrows for
1172 * example. 1131 * example.
1173 * The drawback: right now it has no frontend, so you need to 1132 * The drawback: right now it has no frontend, so you need to
1174 * stick the bits you want into a calculator in hex mode and then 1133 * stick the bits you want into a calculator in hex mode and then
1175 * convert to decimal and then 'pickup <#> 1134 * convert to decimal and then 'pickup <#>
1675 return 0; 1634 return 0;
1676 } 1635 }
1677 1636
1678 arrow->set_owner (op); 1637 arrow->set_owner (op);
1679 arrow->skill = bow->skill; 1638 arrow->skill = bow->skill;
1680
1681 arrow->direction = dir; 1639 arrow->direction = dir;
1682 arrow->x = sx;
1683 arrow->y = sy;
1684 1640
1685 if (op->type == PLAYER) 1641 if (op->type == PLAYER)
1686 { 1642 {
1687 op->speed_left = 0.01 - (float) FABS (op->speed) * 100 / bowspeed; 1643 op->speed_left = 0.01 - (float) FABS (op->speed) * 100 / bowspeed;
1688 op->update_stats (); 1644 op->update_stats ();
1703 1659
1704 /* update the speed */ 1660 /* update the speed */
1705 arrow->speed = (float) ((QUERY_FLAG (bow, FLAG_NO_STRENGTH) ? 1661 arrow->speed = (float) ((QUERY_FLAG (bow, FLAG_NO_STRENGTH) ?
1706 0 : dam_bonus[op->stats.Str]) + bow->magic + arrow->magic) / 5.0 + (float) bow->stats.dam / 7.0; 1662 0 : dam_bonus[op->stats.Str]) + bow->magic + arrow->magic) / 5.0 + (float) bow->stats.dam / 7.0;
1707 1663
1708 if (arrow->speed < 1.0) 1664 arrow->set_speed (max (arrow->speed, 1.0));
1709 arrow->speed = 1.0;
1710 update_ob_speed (arrow);
1711 arrow->speed_left = 0; 1665 arrow->speed_left = 0;
1712 1666
1713 if (op->type == PLAYER) 1667 if (op->type == PLAYER)
1714 { 1668 {
1715 arrow->stats.wc = 20 - bow->magic - arrow->magic - 1669 arrow->stats.wc = 20 - bow->magic - arrow->magic -
1728 arrow->attacktype |= bow->attacktype; 1682 arrow->attacktype |= bow->attacktype;
1729 1683
1730 if (bow->slaying) 1684 if (bow->slaying)
1731 arrow->slaying = bow->slaying; 1685 arrow->slaying = bow->slaying;
1732 1686
1733 arrow->map = m;
1734 arrow->move_type = MOVE_FLY_LOW; 1687 arrow->move_type = MOVE_FLY_LOW;
1735 arrow->move_on = MOVE_FLY_LOW | MOVE_WALK; 1688 arrow->move_on = MOVE_FLY_LOW | MOVE_WALK;
1736 1689
1737 play_sound_map (op->map, op->x, op->y, SOUND_FIRE_ARROW); 1690 play_sound_map (op->map, op->x, op->y, SOUND_FIRE_ARROW);
1738 insert_ob_in_map (arrow, m, op, 0); 1691 m->insert (arrow, sx, sy, op);
1739 1692
1740 if (!arrow->destroyed ()) 1693 if (!arrow->destroyed ())
1741 move_arrow (arrow); 1694 move_arrow (arrow);
1742 1695
1743 if (op->type == PLAYER) 1696 if (op->type == PLAYER)
1769 } 1722 }
1770 else if (op->contr->bowtype >= bow_n && op->contr->bowtype <= bow_nw) 1723 else if (op->contr->bowtype >= bow_n && op->contr->bowtype <= bow_nw)
1771 { 1724 {
1772 if (!similar_direction (dir, op->contr->bowtype - bow_n + 1)) 1725 if (!similar_direction (dir, op->contr->bowtype - bow_n + 1))
1773 wcmod = -1; 1726 wcmod = -1;
1727
1774 ret = fire_bow (op, op, NULL, op->contr->bowtype - bow_n + 1, wcmod, op->x, op->y); 1728 ret = fire_bow (op, op, NULL, op->contr->bowtype - bow_n + 1, wcmod, op->x, op->y);
1775 } 1729 }
1776 else if (op->contr->bowtype == bow_threewide) 1730 else if (op->contr->bowtype == bow_threewide)
1777 { 1731 {
1778 ret = fire_bow (op, op, NULL, dir, 0, op->x, op->y); 1732 ret = fire_bow (op, op, NULL, dir, 0, op->x, op->y);
1848 1802
1849 if (item->arch) 1803 if (item->arch)
1850 { 1804 {
1851 CLEAR_FLAG (item, FLAG_ANIMATE); 1805 CLEAR_FLAG (item, FLAG_ANIMATE);
1852 item->face = item->arch->clone.face; 1806 item->face = item->arch->clone.face;
1853 item->speed = 0; 1807 item->set_speed (0);
1854 update_ob_speed (item);
1855 } 1808 }
1809
1856 if ((tmp = item->in_player ())) 1810 if ((tmp = item->in_player ()))
1857 esrv_update_item (UPD_ANIM, tmp, item); 1811 esrv_update_item (UPD_ANIM, tmp, item);
1858 } 1812 }
1859 } 1813 }
1860 else if (item->type == ROD || item->type == HORN) 1814 else if (item->type == ROD || item->type == HORN)
1861 {
1862 drain_rod_charge (item); 1815 drain_rod_charge (item);
1863 }
1864 } 1816 }
1865} 1817}
1866 1818
1867/* Received a fire command for the player - go and do it. 1819/* Received a fire command for the player - go and do it.
1868 */ 1820 */
2084 */ 2036 */
2085 if ((op->contr->braced || !move_ob (op, dir, op)) && !out_of_map (op->map, nx, ny)) 2037 if ((op->contr->braced || !move_ob (op, dir, op)) && !out_of_map (op->map, nx, ny))
2086 { 2038 {
2087 if (OUT_OF_REAL_MAP (op->map, nx, ny)) 2039 if (OUT_OF_REAL_MAP (op->map, nx, ny))
2088 { 2040 {
2089 m = get_map_from_coord (op->map, &nx, &ny); 2041 m = op->map->xy_find (nx, ny);
2090 if (!m) 2042 if (!m)
2091 return; /* Don't think this should happen */ 2043 return; /* Don't think this should happen */
2092 } 2044 }
2093 else 2045 else
2094 m = op->map; 2046 m = op->map;
2095 2047
2096 if ((tmp = GET_MAP_OB (m, nx, ny)) == NULL) 2048 if (!(tmp = m->at (nx, ny).bot))
2097 {
2098 /* LOG(llevError,"player_move_attack: GET_MAP_OB returns NULL, but player can not move there.\n"); */
2099 return; 2049 return;
2100 }
2101 2050
2102 mon = 0; 2051 mon = 0;
2103 /* Go through all the objects, and find ones of interest. Only stop if 2052 /* Go through all the objects, and find ones of interest. Only stop if
2104 * we find a monster - that is something we know we want to attack. 2053 * we find a monster - that is something we know we want to attack.
2105 * if its a door or barrel (can roll) see if there may be monsters 2054 * if its a door or barrel (can roll) see if there may be monsters
2158 && (QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY))) 2107 && (QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY)))
2159 { 2108 {
2160 /* If we're braced, we don't want to switch places with it */ 2109 /* If we're braced, we don't want to switch places with it */
2161 if (op->contr->braced) 2110 if (op->contr->braced)
2162 return; 2111 return;
2112
2163 play_sound_map (op->map, op->x, op->y, SOUND_PUSH_PLAYER); 2113 play_sound_map (op->map, op->x, op->y, SOUND_PUSH_PLAYER);
2164 (void) push_ob (mon, dir, op); 2114 (void) push_ob (mon, dir, op);
2165 if (op->contr->tmp_invis || op->hide) 2115 if (op->contr->tmp_invis || op->hide)
2166 make_visible (op); 2116 make_visible (op);
2117
2167 return; 2118 return;
2168 } 2119 }
2169 2120
2170 /* in certain circumstances, you shouldn't attack friendly 2121 /* in certain circumstances, you shouldn't attack friendly
2171 * creatures. Note that if you are braced, you can't push 2122 * creatures. Note that if you are braced, you can't push
2185 !on_battleground)) 2136 !on_battleground))
2186 { 2137 {
2187 if (!op->contr->braced) 2138 if (!op->contr->braced)
2188 { 2139 {
2189 play_sound_map (op->map, op->x, op->y, SOUND_PUSH_PLAYER); 2140 play_sound_map (op->map, op->x, op->y, SOUND_PUSH_PLAYER);
2190 (void) push_ob (mon, dir, op); 2141 push_ob (mon, dir, op);
2191 } 2142 }
2192 else 2143 else
2193 new_draw_info (0, 0, op, "You withhold your attack"); 2144 new_draw_info (0, 0, op, "You withhold your attack");
2194 2145
2195 if (op->contr->tmp_invis || op->hide) 2146 if (op->contr->tmp_invis || op->hide)
2210 * Way it works is like this: First, it must have some hit points 2161 * Way it works is like this: First, it must have some hit points
2211 * and be living. Then, it must be one of the following: 2162 * and be living. Then, it must be one of the following:
2212 * 1) Not a player, 2) A player, but of a different party. Note 2163 * 1) Not a player, 2) A player, but of a different party. Note
2213 * that party_number -1 is no party, so attacks can still happen. 2164 * that party_number -1 is no party, so attacks can still happen.
2214 */ 2165 */
2215
2216 else if ((mon->stats.hp >= 0) && QUERY_FLAG (mon, FLAG_ALIVE) && 2166 else if ((mon->stats.hp >= 0) && QUERY_FLAG (mon, FLAG_ALIVE) &&
2217 ((mon->type != PLAYER || op->contr->party == NULL || op->contr->party != mon->contr->party))) 2167 ((mon->type != PLAYER || op->contr->party == NULL || op->contr->party != mon->contr->party)))
2218 { 2168 {
2219 2169
2220 /* If the player hasn't hit something this tick, and does 2170 /* If the player hasn't hit something this tick, and does
2254int 2204int
2255move_player (object *op, int dir) 2205move_player (object *op, int dir)
2256{ 2206{
2257 int pick; 2207 int pick;
2258 2208
2259 if (op->map == NULL || op->map->in_memory != MAP_IN_MEMORY) 2209 if (!op->map || op->map->in_memory != MAP_IN_MEMORY)
2260 return 0; 2210 return 0;
2261 2211
2262 /* Sanity check: make sure dir is valid */ 2212 /* Sanity check: make sure dir is valid */
2263 if ((dir < 0) || (dir >= 9)) 2213 if ((dir < 0) || (dir >= 9))
2264 { 2214 {
2265 LOG (llevError, "move_player: invalid direction %d\n", dir); 2215 LOG (llevError, "move_player: invalid direction %d\n", dir);
2266 return 0; 2216 return 0;
2267 } 2217 }
2268 2218
2269 /* peterm: added following line */ 2219 /* peterm: added following line */
2270 if (QUERY_FLAG (op, FLAG_CONFUSED) && dir) 2220 if (QUERY_FLAG (op, FLAG_CONFUSED) && dir)
2271 dir = absdir (dir + RANDOM () % 3 + RANDOM () % 3 - 2); 2221 dir = absdir (dir + RANDOM () % 3 + RANDOM () % 3 - 2);
2272 2222
2273 op->facing = dir; 2223 op->facing = dir;
2274 2224
2352 2302
2353 /* call this here - we also will call this in do_ericserver, but 2303 /* call this here - we also will call this in do_ericserver, but
2354 * the players time has been increased when doericserver has been 2304 * the players time has been increased when doericserver has been
2355 * called, so we recheck it here. 2305 * called, so we recheck it here.
2356 */ 2306 */
2357 //TODO: better than handling 8 commands, use some more intelligent rate-limiting 2307 if (op->contr->ns->handle_command ())
2358 for (int rep = 8; --rep && op->contr->ns->handle_command (); ) 2308 return 1;
2359 ;
2360 2309
2361 if (op->speed_left < 0) 2310 if (op->speed_left > 0)
2362 return 0; 2311 {
2363
2364 if (op->direction && (op->contr->run_on || op->contr->fire_on)) 2312 if (op->direction && (op->contr->run_on || op->contr->fire_on))
2365 { 2313 {
2366 /* All move commands take 1 tick, at least for now */ 2314 /* All move commands take 1 tick, at least for now */
2367 op->speed_left--; 2315 op->speed_left--;
2368 2316
2369 /* Instead of all the stuff below, let move_player take care 2317 /* Instead of all the stuff below, let move_player take care
2370 * of it. Also, some of the skill stuff is only put in 2318 * of it. Also, some of the skill stuff is only put in
2371 * there, as well as the confusion stuff. 2319 * there, as well as the confusion stuff.
2372 */ 2320 */
2373 move_player (op, op->direction); 2321 move_player (op, op->direction);
2374 if (op->speed_left > 0) 2322
2375 return 1; 2323 return op->speed_left > 0;
2376 else 2324 }
2377 return 0;
2378 } 2325 }
2379 2326
2380 return 0; 2327 return 0;
2381} 2328}
2382 2329
2424{ 2371{
2425 object *next; 2372 object *next;
2426 2373
2427 while (op) 2374 while (op)
2428 { 2375 {
2429 next = op->below; /* Make sure we have a good value, in case 2376 object *next = op->below; /* Make sure we have a good value, in case we remove object 'op' */
2430 * we remove object 'op' 2377
2431 */
2432 if (QUERY_FLAG (op, FLAG_UNPAID)) 2378 if (QUERY_FLAG (op, FLAG_UNPAID))
2433 { 2379 {
2434 op->remove ();
2435 op->x = env->x;
2436 op->y = env->y;
2437 if (env->type == PLAYER) 2380 if (env->type == PLAYER)
2438 esrv_del_item (env->contr, op->count); 2381 esrv_del_item (env->contr, op->count);
2439 insert_ob_in_map (op, env->map, NULL, 0); 2382
2383 op->insert_at (env);
2440 } 2384 }
2441 else if (op->inv) 2385 else if (op->inv)
2442 remove_unpaid_objects (op->inv, env); 2386 remove_unpaid_objects (op->inv, env);
2443 2387
2444 op = next; 2388 op = next;
2445 } 2389 }
2446} 2390}
2447
2448 2391
2449/* 2392/*
2450 * Returns pointer a static string containing gravestone text 2393 * Returns pointer a static string containing gravestone text
2451 * Moved from apply.c to player.c - player.c is what 2394 * Moved from apply.c to player.c - player.c is what
2452 * actually uses this function. player.c may not be quite the 2395 * actually uses this function. player.c may not be quite the
2486 strncat (buf2, " ", 20 - strlen (buf) / 2); 2429 strncat (buf2, " ", 20 - strlen (buf) / 2);
2487 strcat (buf2, buf); 2430 strcat (buf2, buf);
2488 2431
2489 return buf2; 2432 return buf2;
2490} 2433}
2491
2492
2493 2434
2494void 2435void
2495do_some_living (object *op) 2436do_some_living (object *op)
2496{ 2437{
2497 int last_food = op->stats.food; 2438 int last_food = op->stats.food;
2506 const int max_grace = 1; 2447 const int max_grace = 1;
2507 2448
2508 if (op->contr->outputs_sync) 2449 if (op->contr->outputs_sync)
2509 { 2450 {
2510 for (i = 0; i < NUM_OUTPUT_BUFS; i++) 2451 for (i = 0; i < NUM_OUTPUT_BUFS; i++)
2511 if (op->contr->outputs[i].buf != NULL && (op->contr->outputs[i].first_update + op->contr->outputs_sync) < (uint16) pticks) 2452 if (op->contr->outputs[i].buf && (op->contr->outputs[i].first_update + op->contr->outputs_sync) < (uint16) pticks)
2512 flush_output_element (op, &op->contr->outputs[i]); 2453 flush_output_element (op, &op->contr->outputs[i]);
2513 } 2454 }
2514 2455
2515 if (op->contr->ns->state == ST_PLAYING) 2456 if (op->contr->ns->state == ST_PLAYING)
2516 { 2457 {
2517
2518 /* these next three if clauses make it possible to SLOW DOWN 2458 /* these next three if clauses make it possible to SLOW DOWN
2519 hp/grace/spellpoint regeneration. */ 2459 hp/grace/spellpoint regeneration. */
2520 if (op->contr->gen_hp >= 0) 2460 if (op->contr->gen_hp >= 0)
2521 gen_hp = (op->contr->gen_hp + 1) * op->stats.maxhp; 2461 gen_hp = (op->contr->gen_hp + 1) * op->stats.maxhp;
2522 else 2462 else
2523 { 2463 {
2524 gen_hp = op->stats.maxhp; 2464 gen_hp = op->stats.maxhp;
2525 rate_hp -= rate_hp / 2 * op->contr->gen_hp; 2465 rate_hp -= rate_hp / 2 * op->contr->gen_hp;
2526 } 2466 }
2467
2527 if (op->contr->gen_sp >= 0) 2468 if (op->contr->gen_sp >= 0)
2528 gen_sp = (op->contr->gen_sp + 1) * op->stats.maxsp; 2469 gen_sp = (op->contr->gen_sp + 1) * op->stats.maxsp;
2529 else 2470 else
2530 { 2471 {
2531 gen_sp = op->stats.maxsp; 2472 gen_sp = op->stats.maxsp;
2532 rate_sp -= rate_sp / 2 * op->contr->gen_sp; 2473 rate_sp -= rate_sp / 2 * op->contr->gen_sp;
2533 } 2474 }
2475
2534 if (op->contr->gen_grace >= 0) 2476 if (op->contr->gen_grace >= 0)
2535 gen_grace = (op->contr->gen_grace + 1) * op->stats.maxgrace; 2477 gen_grace = (op->contr->gen_grace + 1) * op->stats.maxgrace;
2536 else 2478 else
2537 { 2479 {
2538 gen_grace = op->stats.maxgrace; 2480 gen_grace = op->stats.maxgrace;
2554 op->stats.food += op->contr->digestion; 2496 op->stats.food += op->contr->digestion;
2555 else if (op->contr->digestion > 0 && random_roll (0, op->contr->digestion, op, PREFER_HIGH)) 2497 else if (op->contr->digestion > 0 && random_roll (0, op->contr->digestion, op, PREFER_HIGH))
2556 op->stats.food = last_food; 2498 op->stats.food = last_food;
2557 } 2499 }
2558 } 2500 }
2501
2559 if (max_sp > 1) 2502 if (max_sp > 1)
2560 { 2503 {
2561 over_sp = (gen_sp + 10) / rate_sp; 2504 over_sp = (gen_sp + 10) / rate_sp;
2562 if (over_sp > 0) 2505 if (over_sp > 0)
2563 { 2506 {
2564 if (op->stats.sp < op->stats.maxsp) 2507 if (op->stats.sp < op->stats.maxsp)
2565 { 2508 {
2566 op->stats.sp += over_sp > max_sp ? max_sp : over_sp; 2509 op->stats.sp += over_sp > max_sp ? max_sp : over_sp;
2510
2567 if (random_roll (0, rate_sp - 1, op, PREFER_LOW) > ((gen_sp + 10) % rate_sp)) 2511 if (random_roll (0, rate_sp - 1, op, PREFER_LOW) > ((gen_sp + 10) % rate_sp))
2568 op->stats.sp--; 2512 op->stats.sp--;
2513
2569 if (op->stats.sp > op->stats.maxsp) 2514 if (op->stats.sp > op->stats.maxsp)
2570 op->stats.sp = op->stats.maxsp; 2515 op->stats.sp = op->stats.maxsp;
2571 } 2516 }
2572 op->last_sp = 0; 2517 op->last_sp = 0;
2573 } 2518 }
2574 else 2519 else
2575 {
2576 op->last_sp = rate_sp / (gen_sp < 20 ? 30 : gen_sp + 10); 2520 op->last_sp = rate_sp / (gen_sp < 20 ? 30 : gen_sp + 10);
2577 }
2578 } 2521 }
2579 else 2522 else
2580 {
2581 op->last_sp = rate_sp / (gen_sp < 20 ? 30 : gen_sp + 10); 2523 op->last_sp = rate_sp / (gen_sp < 20 ? 30 : gen_sp + 10);
2582 }
2583 } 2524 }
2584 2525
2585 /* Regenerate Grace */ 2526 /* Regenerate Grace */
2586 /* I altered this a little - maximum grace is ony achieved through prayer -b.t. */ 2527 /* I altered this a little - maximum grace is ony achieved through prayer -b.t. */
2587 if (--op->last_grace < 0) 2528 if (--op->last_grace < 0)
2588 { 2529 {
2589 if (op->stats.grace < op->stats.maxgrace / 2) 2530 if (op->stats.grace < op->stats.maxgrace / 2)
2590 op->stats.grace++; /* no penalty in food for regaining grace */ 2531 op->stats.grace++; /* no penalty in food for regaining grace */
2532
2591 if (max_grace > 1) 2533 if (max_grace > 1)
2592 { 2534 {
2593 over_grace = (gen_grace < 20 ? 30 : gen_grace + 10) / rate_grace; 2535 over_grace = (gen_grace < 20 ? 30 : gen_grace + 10) / rate_grace;
2594 if (over_grace > 0) 2536 if (over_grace > 0)
2595 { 2537 {
2623 op->stats.food += op->contr->digestion; 2565 op->stats.food += op->contr->digestion;
2624 else if (op->contr->digestion > 0 && random_roll (0, op->contr->digestion, op, PREFER_HIGH)) 2566 else if (op->contr->digestion > 0 && random_roll (0, op->contr->digestion, op, PREFER_HIGH))
2625 op->stats.food = last_food; 2567 op->stats.food = last_food;
2626 } 2568 }
2627 } 2569 }
2570
2628 if (max_hp > 1) 2571 if (max_hp > 1)
2629 { 2572 {
2630 over_hp = (gen_hp < 20 ? 30 : gen_hp + 10) / rate_hp; 2573 over_hp = (gen_hp < 20 ? 30 : gen_hp + 10) / rate_hp;
2631 if (over_hp > 0) 2574 if (over_hp > 0)
2632 { 2575 {
2656 2599
2657 if (op->contr->gen_hp > 0) 2600 if (op->contr->gen_hp > 0)
2658 op->last_eat = 25 * (1 + bonus) / (op->contr->gen_hp + penalty + 1); 2601 op->last_eat = 25 * (1 + bonus) / (op->contr->gen_hp + penalty + 1);
2659 else 2602 else
2660 op->last_eat = 25 * (1 + bonus) / (penalty + 1); 2603 op->last_eat = 25 * (1 + bonus) / (penalty + 1);
2604
2661 /* dms do not consume food */ 2605 /* dms do not consume food */
2662 if (!QUERY_FLAG (op, FLAG_WIZ)) 2606 if (!QUERY_FLAG (op, FLAG_WIZ))
2663 op->stats.food--; 2607 op->stats.food--;
2664 } 2608 }
2665 }
2666 2609
2667 if (op->contr->ns->state == ST_PLAYING && op->stats.food < 0 && op->stats.hp >= 0) 2610 if (op->stats.food < 0 && op->stats.hp >= 0)
2668 { 2611 {
2669 object *tmp, *flesh = NULL; 2612 object *tmp, *flesh = 0;
2670 2613
2671 for (tmp = op->inv; tmp != NULL; tmp = tmp->below) 2614 for (tmp = op->inv; tmp; tmp = tmp->below)
2672 { 2615 {
2673 if (!QUERY_FLAG (tmp, FLAG_UNPAID)) 2616 if (!QUERY_FLAG (tmp, FLAG_UNPAID))
2674 {
2675 if (tmp->type == FOOD || tmp->type == DRINK || tmp->type == POISON)
2676 { 2617 {
2618 if (tmp->type == FOOD || tmp->type == DRINK || tmp->type == POISON)
2619 {
2677 new_draw_info (NDI_UNIQUE, 0, op, "You blindly grab for a bite of food."); 2620 new_draw_info (NDI_UNIQUE, 0, op, "You blindly grab for a bite of food.");
2678 manual_apply (op, tmp, 0); 2621 manual_apply (op, tmp, 0);
2679 if (op->stats.food >= 0 || op->stats.hp < 0) 2622 if (op->stats.food >= 0 || op->stats.hp < 0)
2680 break; 2623 break;
2681 } 2624 }
2682 else if (tmp->type == FLESH) 2625 else if (tmp->type == FLESH)
2683 flesh = tmp; 2626 flesh = tmp;
2684 } /* End if paid for object */ 2627 } /* End if paid for object */
2685 } /* end of for loop */ 2628 } /* end of for loop */
2629
2686 /* If player is still starving, it means they don't have any food, so 2630 /* If player is still starving, it means they don't have any food, so
2687 * eat flesh instead. 2631 * eat flesh instead.
2688 */ 2632 */
2689 if (op->stats.food < 0 && op->stats.hp >= 0 && flesh) 2633 if (op->stats.food < 0 && op->stats.hp >= 0 && flesh)
2690 { 2634 {
2691 new_draw_info (NDI_UNIQUE, 0, op, "You blindly grab for a bite of food."); 2635 new_draw_info (NDI_UNIQUE, 0, op, "You blindly grab for a bite of food.");
2692 manual_apply (op, flesh, 0); 2636 manual_apply (op, flesh, 0);
2693 } 2637 }
2694 } /* end if player is starving */ 2638 }
2695 2639
2696 while (op->stats.food < 0 && op->stats.hp > 0) 2640 while (op->stats.food < 0 && op->stats.hp >= 0)
2697 op->stats.food++, op->stats.hp--; 2641 op->stats.food++, op->stats.hp--;
2698 2642
2699 if (!op->contr->ns->state && !QUERY_FLAG (op, FLAG_WIZ) && (op->stats.hp < 0 || op->stats.food < 0)) 2643 if (op->stats.hp < 0 && !QUERY_FLAG (op, FLAG_WIZ))
2700 kill_player (op); 2644 kill_player (op);
2645 }
2701} 2646}
2702
2703
2704 2647
2705/* If the player should die (lack of hp, food, etc), we call this. 2648/* If the player should die (lack of hp, food, etc), we call this.
2706 * op is the player in jeopardy. If the player can not be saved (not 2649 * op is the player in jeopardy. If the player can not be saved (not
2707 * permadeath, no lifesave), this will take care of removing the player 2650 * permadeath, no lifesave), this will take care of removing the player
2708 * file. 2651 * file.
2738 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, "You have been defeated in combat!"); 2681 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, "You have been defeated in combat!");
2739 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, "Local medics have saved your life..."); 2682 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, "Local medics have saved your life...");
2740 2683
2741 /* restore player */ 2684 /* restore player */
2742 at = archetype::find ("poisoning"); 2685 at = archetype::find ("poisoning");
2743 tmp = present_arch_in_ob (at, op); 2686 if (object *tmp = present_arch_in_ob (at, op))
2744 if (tmp)
2745 { 2687 {
2746 tmp->destroy (); 2688 tmp->destroy ();
2747 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed"); 2689 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed");
2748 } 2690 }
2749 2691
2750 at = archetype::find ("confusion"); 2692 at = archetype::find ("confusion");
2751 tmp = present_arch_in_ob (at, op); 2693 if (object *tmp = present_arch_in_ob (at, op))
2752 if (tmp)
2753 { 2694 {
2754 tmp->destroy (); 2695 tmp->destroy ();
2755 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer"); 2696 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer");
2756 } 2697 }
2757 2698
2759 op->stats.hp = op->stats.maxhp; 2700 op->stats.hp = op->stats.maxhp;
2760 if (op->stats.food <= 0) 2701 if (op->stats.food <= 0)
2761 op->stats.food = 999; 2702 op->stats.food = 999;
2762 2703
2763 /* create a bodypart-trophy to make the winner happy */ 2704 /* create a bodypart-trophy to make the winner happy */
2764 tmp = arch_to_object (archetype::find ("finger")); 2705 if (object *tmp = arch_to_object (archetype::find ("finger")))
2765 if (tmp != NULL)
2766 { 2706 {
2767 sprintf (buf, "%s's finger", &op->name); 2707 sprintf (buf, "%s's finger", &op->name);
2768 tmp->name = buf; 2708 tmp->name = buf;
2769 sprintf (buf, " This finger has been cut off %s\n" 2709 sprintf (buf, " This finger has been cut off %s\n"
2770 " the %s, when he was defeated at\n level %d by %s.\n", 2710 " the %s, when he was defeated at\n level %d by %s.\n",
2771 &op->name, op->contr->title, (int) (op->level), op->contr->killer); 2711 &op->name, op->contr->title, (int) (op->level), op->contr->killer);
2772 tmp->msg = buf; 2712 tmp->msg = buf;
2773 tmp->value = 0, tmp->material = 0, tmp->type = 0; 2713 tmp->value = 0, tmp->material = 0, tmp->type = 0;
2774 tmp->materialname = NULL; 2714 tmp->materialname = NULL;
2775 tmp->x = op->x, tmp->y = op->y; 2715 tmp->insert_at (op, tmp);
2776 insert_ob_in_map (tmp, op->map, op, 0);
2777 } 2716 }
2778 2717
2779 /* teleport defeated player to new destination */ 2718 /* teleport defeated player to new destination */
2780 transfer_ob (op, x, y, 0, NULL); 2719 transfer_ob (op, x, y, 0, NULL);
2781 op->contr->braced = 0; 2720 op->contr->braced = 0;
2786 2725
2787 command_kill_pets (op, 0); 2726 command_kill_pets (op, 0);
2788 2727
2789 if (op->stats.food < 0) 2728 if (op->stats.food < 0)
2790 { 2729 {
2791 if (op->contr->explore)
2792 {
2793 new_draw_info (NDI_UNIQUE, 0, op, "You would have starved, but you are");
2794 new_draw_info (NDI_UNIQUE, 0, op, "in explore mode, so...");
2795 op->stats.food = 999;
2796 return;
2797 }
2798 sprintf (buf, "%s starved to death.", &op->name); 2730 sprintf (buf, "%s starved to death.", &op->name);
2799 strcpy (op->contr->killer, "starvation"); 2731 strcpy (op->contr->killer, "starvation");
2800 } 2732 }
2801 else 2733 else
2802 {
2803 if (op->contr->explore)
2804 {
2805 new_draw_info (NDI_UNIQUE, 0, op, "You would have died, but you are");
2806 new_draw_info (NDI_UNIQUE, 0, op, "in explore mode, so...");
2807 op->stats.hp = op->stats.maxhp;
2808 return;
2809 }
2810 sprintf (buf, "%s died.", &op->name); 2734 sprintf (buf, "%s died.", &op->name);
2811 } 2735
2812 play_sound_player_only (op->contr, SOUND_PLAYER_DIES, 0, 0); 2736 play_sound_player_only (op->contr, SOUND_PLAYER_DIES, 0, 0);
2813 2737
2814 /* save the map location for corpse, gravestone */ 2738 /* save the map location for corpse, gravestone */
2815 x = op->x; 2739 x = op->x;
2816 y = op->y; 2740 y = op->y;
2817 map = op->map; 2741 map = op->map;
2818
2819 2742
2820 /* NOT_PERMADEATH code. This basically brings the character back to 2743 /* NOT_PERMADEATH code. This basically brings the character back to
2821 * life if they are dead - it takes some exp and a random stat. 2744 * life if they are dead - it takes some exp and a random stat.
2822 * See the config.h file for a little more in depth detail about this. 2745 * See the config.h file for a little more in depth detail about this.
2823 */ 2746 */
2840 num_stats_lose = 1; 2763 num_stats_lose = 1;
2841 else 2764 else
2842 num_stats_lose = 1 + op->level / BALSL_NUMBER_LOSSES_RATIO; 2765 num_stats_lose = 1 + op->level / BALSL_NUMBER_LOSSES_RATIO;
2843 } 2766 }
2844 else 2767 else
2845 {
2846 num_stats_lose = 1; 2768 num_stats_lose = 1;
2847 } 2769
2848 lost_a_stat = 0; 2770 lost_a_stat = 0;
2849 2771
2850 for (z = 0; z < num_stats_lose; z++) 2772 for (z = 0; z < num_stats_lose; z++)
2851 { 2773 {
2852 i = RANDOM () % NUM_STATS; 2774 i = RANDOM () % NUM_STATS;
3010 /* */ 2932 /* */
3011 /****************************************/ 2933 /****************************************/
3012 2934
3013 enter_player_savebed (op); 2935 enter_player_savebed (op);
3014 2936
3015 /* Save the player before inserting the force to reduce
3016 * chance of abuse.
3017 */
3018 op->contr->braced = 0; 2937 op->contr->braced = 0;
3019 op->contr->save ();
3020 2938
3021 /* it is possible that the player has blown something up 2939 /* it is possible that the player has blown something up
3022 * at his savebed location, and that can have long lasting 2940 * at his savebed location, and that can have long lasting
3023 * spell effects. So first see if there is a spell effect 2941 * spell effects. So first see if there is a spell effect
3024 * on the space that might harm the player. 2942 * on the space that might harm the player.
3094 */ 3012 */
3095 3013
3096void 3014void
3097fix_weight (void) 3015fix_weight (void)
3098{ 3016{
3099 for (player *pl = first_player; pl; pl = pl->next) 3017 for_all_players (pl)
3100 { 3018 {
3101 int old = pl->ob->carrying, sum = sum_weight (pl->ob); 3019 int old = pl->ob->carrying, sum = sum_weight (pl->ob);
3102 3020
3103 if (old == sum) 3021 if (old == sum)
3104 continue; 3022 continue;
3108} 3026}
3109 3027
3110void 3028void
3111fix_luck (void) 3029fix_luck (void)
3112{ 3030{
3113 for (player *pl = first_player; pl; pl = pl->next) 3031 for_all_players (pl)
3114 if (!pl->ob->contr->ns->state) 3032 if (!pl->ob->contr->ns->state)
3115 pl->ob->change_luck (0); 3033 pl->ob->change_luck (0);
3116} 3034}
3117 3035
3118/* cast_dust() - handles op throwing objects of type 'DUST'. 3036/* cast_dust() - handles op throwing objects of type 'DUST'.
3236 3154
3237 skop = find_obj_by_type_subtype (op, SKILL, SK_HIDING); 3155 skop = find_obj_by_type_subtype (op, SKILL, SK_HIDING);
3238 3156
3239 /* its *extremely* hard to run and sneak/hide at the same time! */ 3157 /* its *extremely* hard to run and sneak/hide at the same time! */
3240 if (op->type == PLAYER && op->contr->run_on) 3158 if (op->type == PLAYER && op->contr->run_on)
3241 {
3242 if (!skop || num >= skop->level) 3159 if (!skop || num >= skop->level)
3243 { 3160 {
3244 new_draw_info (NDI_UNIQUE, 0, op, "You ran too much! You are no longer hidden!"); 3161 new_draw_info (NDI_UNIQUE, 0, op, "You ran too much! You are no longer hidden!");
3245 make_visible (op); 3162 make_visible (op);
3246 return; 3163 return;
3247 } 3164 }
3248 else 3165 else
3249 num += 20; 3166 num += 20;
3250 } 3167
3251 num += op->map->difficulty; 3168 num += op->map->difficulty;
3252 hide = hideability (op); /* modify by terrain hidden level */ 3169 hide = hideability (op); /* modify by terrain hidden level */
3253 num -= hide; 3170 num -= hide;
3171
3254 if ((op->type == PLAYER && hide < -10) || ((op->invisible -= num) <= 0)) 3172 if ((op->type == PLAYER && hide < -10) || ((op->invisible -= num) <= 0))
3255 { 3173 {
3256 make_visible (op); 3174 make_visible (op);
3257 if (op->type == PLAYER) 3175 if (op->type == PLAYER)
3258 new_draw_info (NDI_UNIQUE, 0, op, "You moved out of hiding! You are visible!"); 3176 new_draw_info (NDI_UNIQUE, 0, op, "You moved out of hiding! You are visible!");
3259 } 3177 }
3260 else if (op->type == PLAYER && skop) 3178 else if (op->type == PLAYER && skop)
3261 {
3262 change_exp (op, calc_skill_exp (op, NULL, skop), skop->skill, 0); 3179 change_exp (op, calc_skill_exp (op, NULL, skop), skop->skill, 0);
3263 }
3264} 3180}
3265 3181
3266/* determine if who is standing near a hostile creature. */ 3182/* determine if who is standing near a hostile creature. */
3267 3183
3268int 3184int
3335 if (pl->type != PLAYER) 3251 if (pl->type != PLAYER)
3336 { 3252 {
3337 LOG (llevError, "player_can_view() called for non-player object\n"); 3253 LOG (llevError, "player_can_view() called for non-player object\n");
3338 return -1; 3254 return -1;
3339 } 3255 }
3256
3340 if (!pl || !op) 3257 if (!pl || !op)
3341 return 0; 3258 return 0;
3342 3259
3343 if (op->head)
3344 {
3345 op = op->head; 3260 op = op->head_ ();
3346 } 3261
3347 get_rangevector (pl, op, &rv, 0x1); 3262 get_rangevector (pl, op, &rv, 0x1);
3348 3263
3349 /* starting with the 'head' part, lets loop 3264 /* starting with the 'head' part, lets loop
3350 * through the object and find if it has any 3265 * through the object and find if it has any
3351 * part that is in the los array but isnt on 3266 * part that is in the los array but isnt on
3481 if (trlist == NULL || who->type != PLAYER) 3396 if (trlist == NULL || who->type != PLAYER)
3482 return; 3397 return;
3483 3398
3484 for (i = 0, tr = trlist->items; tr != NULL && i < level - 1; tr = tr->next, i++); 3399 for (i = 0, tr = trlist->items; tr != NULL && i < level - 1; tr = tr->next, i++);
3485 3400
3486 if (tr == NULL || tr->item == NULL) 3401 if (!tr || !tr->item)
3487 { 3402 {
3488 /* LOG(llevDebug, "-> no more treasure for %s\n", change_resist_msg[atnr]); */ 3403 /* LOG(llevDebug, "-> no more treasure for %s\n", change_resist_msg[atnr]); */
3489 return; 3404 return;
3490 } 3405 }
3491 3406

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines