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.23 by root, Thu Sep 14 22:34:04 2006 UTC vs.
Revision 1.38 by root, Thu Dec 14 04:30:32 2006 UTC

20 20
21 The author can be reached via e-mail to <crossfire@schmorp.de> 21 The author can be reached via e-mail to <crossfire@schmorp.de>
22*/ 22*/
23 23
24#include <global.h> 24#include <global.h>
25#ifndef WIN32 /* ---win32 remove headers */
26# include <pwd.h> 25#include <pwd.h>
27#endif
28#ifndef __CEXTRACT__
29# include <sproto.h> 26#include <sproto.h>
30#endif
31#include <sounds.h> 27#include <sounds.h>
32#include <living.h> 28#include <living.h>
33#include <object.h> 29#include <object.h>
34#include <spells.h> 30#include <spells.h>
35#include <skills.h> 31#include <skills.h>
208 * the one that is passed. 204 * the one that is passed.
209 */ 205 */
210static player * 206static player *
211get_player (player *p) 207get_player (player *p)
212{ 208{
213 object *op = arch_to_object (get_player_archetype (NULL)); 209 object *op = arch_to_object (get_player_archetype (0));
214 int i; 210 int i;
215
216 if (!p)
217 {
218 p = new player;
219
220 /* This adds the player in the linked list. There is extra
221 * complexity here because we want to add the new player at the
222 * end of the list - there is in fact no compelling reason that
223 * that needs to be done except for things like output of
224 * 'who'.
225 */
226 player *tmp = first_player;
227
228 while (tmp != NULL && tmp->next != NULL)
229 tmp = tmp->next;
230 if (tmp != NULL)
231 tmp->next = p;
232 else
233 first_player = p;
234
235 p->next = NULL;
236 }
237 211
238 /* Clears basically the entire player structure except 212 /* Clears basically the entire player structure except
239 * for next and socket. 213 * for next and socket.
240 */ 214 */
241 p->clear (); 215 p->clear ();
260 op->speed_left = 0.5; 234 op->speed_left = 0.5;
261 op->speed = 1.0; 235 op->speed = 1.0;
262 op->direction = 5; /* So player faces south */ 236 op->direction = 5; /* So player faces south */
263 op->stats.wc = 2; 237 op->stats.wc = 2;
264 op->run_away = 25; /* Then we panick... */ 238 op->run_away = 25; /* Then we panick... */
265 p->socket.monitor_spells = 0; /* Needed because esrv_update_spells( ) gets called by roll_stats */ 239 p->socket->monitor_spells = 0; /* Needed because esrv_update_spells( ) gets called by roll_stats */
266 240
267 roll_stats (op); 241 roll_stats (op);
268 p->state = ST_ROLL_STAT; 242 p->state = ST_ROLL_STAT;
269 clear_los (op); 243 clear_los (op);
270 244
294 for (i = 0; i < NUM_SKILLS; i++) 268 for (i = 0; i < NUM_SKILLS; i++)
295 { 269 {
296 p->last_skill_exp[i] = -1; 270 p->last_skill_exp[i] = -1;
297 p->last_skill_ob[i] = NULL; 271 p->last_skill_ob[i] = NULL;
298 } 272 }
273
299 for (i = 0; i < NROFATTACKS; i++) 274 for (i = 0; i < NROFATTACKS; i++)
300 {
301 p->last_resist[i] = -1; 275 p->last_resist[i] = -1;
302 } 276
303 p->last_stats.exp = -1; 277 p->last_stats.exp = -1;
304 p->last_weight = (uint32) - 1; 278 p->last_weight = (uint32) - 1;
305 279
306 p->socket.update_look = 0; 280 p->socket->update_look = 0;
307 p->socket.look_position = 0; 281 p->socket->look_position = 0;
282
308 return p; 283 return p;
309} 284}
310 285
311/* This loads the first map an puts the player on it. */ 286/* This loads the first map an puts the player on it. */
312static void 287static void
322 * All we can really get in this is some settings like host and display 297 * All we can really get in this is some settings like host and display
323 * mode. 298 * mode.
324 */ 299 */
325 300
326int 301int
327add_player (NewSocket * ns) 302add_player (client_socket *ns)
328{ 303{
329 player *p; 304 player *p = new player;
330 305
331 p = get_player (NULL);
332 p->socket = *ns; 306 p->socket = ns;
333 p->socket.faces_sent = (uint8 *) malloc (p->socket.faces_sent_len * sizeof (*p->socket.faces_sent)); 307 ns->pl = p;
334 if (p->socket.faces_sent == NULL) 308
335 fatal (OUT_OF_MEMORY); 309 p->next = first_player;
336 memcpy (p->socket.faces_sent, ns->faces_sent, p->socket.faces_sent_len * sizeof (*p->socket.faces_sent)); 310 first_player = p;
337 /* Needed because the socket we just copied over needs to be cleared. 311
338 * Note that this can result in a client reset if there is partial data 312 p = get_player (p);
339 * on the uncoming socket. 313
340 */
341 p->socket.inbuf.len = 0;
342 set_first_map (p->ob); 314 set_first_map (p->ob);
343 315
344 CLEAR_FLAG (p->ob, FLAG_FRIENDLY); 316 CLEAR_FLAG (p->ob, FLAG_FRIENDLY);
345 add_friendly_object (p->ob); 317 add_friendly_object (p->ob);
346 send_rules (p->ob); 318 send_rules (p->ob);
347 send_news (p->ob); 319 send_news (p->ob);
348 display_motd (p->ob); 320 display_motd (p->ob);
349 get_name (p->ob); 321 get_name (p->ob);
322
350 return 0; 323 return 0;
351} 324}
352 325
353/* 326/*
354 * get_player_archetype() return next player archetype from archetype 327 * get_player_archetype() return next player archetype from archetype
489path_to_player (object *mon, object *pl, unsigned mindiff) 462path_to_player (object *mon, object *pl, unsigned mindiff)
490{ 463{
491 rv_vector rv; 464 rv_vector rv;
492 sint16 x, y; 465 sint16 x, y;
493 int lastx, lasty, dir, i, diff, firstdir = 0, lastdir, max = MAX_SPACES, mflags, blocked; 466 int lastx, lasty, dir, i, diff, firstdir = 0, lastdir, max = MAX_SPACES, mflags, blocked;
494 mapstruct *m, *lastmap; 467 maptile *m, *lastmap;
495 468
496 get_rangevector (mon, pl, &rv, 0); 469 get_rangevector (mon, pl, &rv, 0);
497 470
498 if (rv.distance < mindiff) 471 if (rv.distance < mindiff)
499 return 0; 472 return 0;
643 (op->type == ARMOUR || op->type == BOOTS || 616 (op->type == ARMOUR || op->type == BOOTS ||
644 op->type == CLOAK || op->type == HELMET || 617 op->type == CLOAK || op->type == HELMET ||
645 op->type == SHIELD || op->type == GLOVES || 618 op->type == SHIELD || op->type == GLOVES ||
646 op->type == BRACERS || op->type == GIRDLE)) || (!QUERY_FLAG (pl, FLAG_USE_WEAPON) && op->type == WEAPON)) 619 op->type == BRACERS || op->type == GIRDLE)) || (!QUERY_FLAG (pl, FLAG_USE_WEAPON) && op->type == WEAPON))
647 { 620 {
648 remove_ob (op); 621 op->destroy ();
649 free_object (op);
650 continue; 622 continue;
651 } 623 }
652 } 624 }
653 625
654 /* This really needs to be better - we should really give 626 /* This really needs to be better - we should really give
665 if (tmp->type == op->type && tmp->name == op->name) 637 if (tmp->type == op->type && tmp->name == op->name)
666 break; 638 break;
667 639
668 if (tmp) 640 if (tmp)
669 { 641 {
670 remove_ob (op); 642 op->destroy ();
671 free_object (op);
672 LOG (llevError, "give_initial_items: Removing duplicate object %s\n", &tmp->name); 643 LOG (llevError, "give_initial_items: Removing duplicate object %s\n", &tmp->name);
673 continue; 644 continue;
674 } 645 }
646
675 if (op->nrof > 1) 647 if (op->nrof > 1)
676 op->nrof = 1; 648 op->nrof = 1;
677 } 649 }
678 650
679 if (op->type == SPELLBOOK && op->inv) 651 if (op->type == SPELLBOOK && op->inv)
691 CLEAR_FLAG (op, FLAG_CURSED); 663 CLEAR_FLAG (op, FLAG_CURSED);
692 CLEAR_FLAG (op, FLAG_DAMNED); 664 CLEAR_FLAG (op, FLAG_DAMNED);
693 } 665 }
694 if (op->type == SPELL) 666 if (op->type == SPELL)
695 { 667 {
696 remove_ob (op); 668 op->destroy ();
697 free_object (op);
698 continue; 669 continue;
699 } 670 }
700 else if (op->type == SKILL) 671 else if (op->type == SKILL)
701 { 672 {
702 SET_FLAG (op, FLAG_CAN_USE_SKILL); 673 SET_FLAG (op, FLAG_CAN_USE_SKILL);
715void 686void
716get_name (object *op) 687get_name (object *op)
717{ 688{
718 op->contr->write_buf[0] = '\0'; 689 op->contr->write_buf[0] = '\0';
719 op->contr->state = ST_GET_NAME; 690 op->contr->state = ST_GET_NAME;
720 send_query (&op->contr->socket, 0, "What is your name?\n:"); 691 send_query (op->contr->socket, 0, "What is your name?\n:");
721} 692}
722 693
723void 694void
724get_password (object *op) 695get_password (object *op)
725{ 696{
726 op->contr->write_buf[0] = '\0'; 697 op->contr->write_buf[0] = '\0';
727 op->contr->state = ST_GET_PASSWORD; 698 op->contr->state = ST_GET_PASSWORD;
728 send_query (&op->contr->socket, CS_QUERY_HIDEINPUT, "What is your password?\n:"); 699 send_query (op->contr->socket, CS_QUERY_HIDEINPUT, "What is your password?\n:");
729} 700}
730 701
731void 702void
732play_again (object *op) 703play_again (object *op)
733{ 704{
734 op->contr->state = ST_PLAY_AGAIN; 705 op->contr->state = ST_PLAY_AGAIN;
735 op->chosen_skill = NULL; 706 op->chosen_skill = NULL;
736 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "Do you want to play again (a/q)?"); 707 send_query (op->contr->socket, CS_QUERY_SINGLECHAR, "Do you want to play again (a/q)?");
737 /* a bit of a hack, but there are various places early in th 708 /* a bit of a hack, but there are various places early in th
738 * player creation process that a user can quit (eg, roll 709 * player creation process that a user can quit (eg, roll
739 * stats) that isn't removing the player. Taking a quick 710 * stats) that isn't removing the player. Taking a quick
740 * look, there are many places that call play_again without 711 * look, there are many places that call play_again without
741 * removing the player - it probably makes more sense 712 * removing the player - it probably makes more sense
742 * to leave it to play_again to remove the object in all 713 * to leave it to play_again to remove the object in all
743 * cases. 714 * cases.
744 */ 715 */
745 if (!QUERY_FLAG (op, FLAG_REMOVED)) 716 if (!QUERY_FLAG (op, FLAG_REMOVED))
746 remove_ob (op); 717 op->remove ();
747 /* Need to set this to null - otherwise, it could point to garbage, 718 /* Need to set this to null - otherwise, it could point to garbage,
748 * and draw() doesn't check to see if the player is removed, only if 719 * and draw() doesn't check to see if the player is removed, only if
749 * the map is null or not swapped out. 720 * the map is null or not swapped out.
750 */ 721 */
751 op->map = NULL; 722 op->map = NULL;
765 player *pl = op->contr; 736 player *pl = op->contr;
766 shstr name = op->name; 737 shstr name = op->name;
767 738
768 op->contr = 0; 739 op->contr = 0;
769 op->type = 0; 740 op->type = 0;
770 op->free (1); 741 op->destroy (1);
771 pl = get_player (pl); 742 pl = get_player (pl);
772 op = pl->ob; 743 op = pl->ob;
773 add_friendly_object (op); 744 add_friendly_object (op);
774 op->contr->password[0] = '~'; 745 op->contr->password[0] = '~';
775 op->name = op->name_pl = 0; 746 op->name = op->name_pl = 0;
790confirm_password (object *op) 761confirm_password (object *op)
791{ 762{
792 763
793 op->contr->write_buf[0] = '\0'; 764 op->contr->write_buf[0] = '\0';
794 op->contr->state = ST_CONFIRM_PASSWORD; 765 op->contr->state = ST_CONFIRM_PASSWORD;
795 send_query (&op->contr->socket, CS_QUERY_HIDEINPUT, "Please type your password again.\n:"); 766 send_query (op->contr->socket, CS_QUERY_HIDEINPUT, "Please type your password again.\n:");
796} 767}
797 768
798void 769void
799get_party_password (object *op, partylist *party) 770get_party_password (object *op, partylist *party)
800{ 771{
804 return; 775 return;
805 } 776 }
806 op->contr->write_buf[0] = '\0'; 777 op->contr->write_buf[0] = '\0';
807 op->contr->state = ST_GET_PARTY_PASSWORD; 778 op->contr->state = ST_GET_PARTY_PASSWORD;
808 op->contr->party_to_join = party; 779 op->contr->party_to_join = party;
809 send_query (&op->contr->socket, CS_QUERY_HIDEINPUT, "What is the password?\n:"); 780 send_query (op->contr->socket, CS_QUERY_HIDEINPUT, "What is the password?\n:");
810} 781}
811 782
812 783
813/* This rolls four 1-6 rolls and sums the best 3 of the 4. */ 784/* This rolls four 1-6 rolls and sums the best 3 of the 4. */
814int 785int
911 882
912void 883void
913Roll_Again (object *op) 884Roll_Again (object *op)
914{ 885{
915 esrv_new_player (op->contr, 0); 886 esrv_new_player (op->contr, 0);
916 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, 887 send_query (op->contr->socket, CS_QUERY_SINGLECHAR,
917 "[y] to roll new stats [n] to use stats\n[1-7] [1-7] to swap stats.\nRoll again (y/n/1-7)? "); 888 "[y] to roll new stats [n] to use stats\n[1-7] [1-7] to swap stats.\nRoll again (y/n/1-7)? ");
918} 889}
919 890
920void 891void
921Swap_Stat (object *op, int Swap_Second) 892Swap_Stat (object *op, int Swap_Second)
988 new_draw_info (NDI_UNIQUE, 0, op, buf); 959 new_draw_info (NDI_UNIQUE, 0, op, buf);
989 } 960 }
990 else 961 else
991 Swap_Stat (op, stat_trans[keynum]); 962 Swap_Stat (op, stat_trans[keynum]);
992 963
993 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, ""); 964 send_query (op->contr->socket, CS_QUERY_SINGLECHAR, "");
994 return 1; 965 return 1;
995 } 966 }
996 switch (key) 967 switch (key)
997 { 968 {
998 case 'n': 969 case 'n':
1012 enter_exit (op, NULL); 983 enter_exit (op, NULL);
1013#endif 984#endif
1014 SET_ANIMATION (op, 2); /* So player faces south */ 985 SET_ANIMATION (op, 2); /* So player faces south */
1015 /* Enter exit adds a player otherwise */ 986 /* Enter exit adds a player otherwise */
1016 add_statbonus (op); 987 add_statbonus (op);
1017 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, 988 send_query (op->contr->socket, CS_QUERY_SINGLECHAR,
1018 "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n"); 989 "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n");
1019 op->contr->state = ST_CHANGE_CLASS; 990 op->contr->state = ST_CHANGE_CLASS;
1020 if (op->msg) 991 if (op->msg)
1021 new_draw_info (NDI_BLUE, 0, op, op->msg); 992 new_draw_info (NDI_BLUE, 0, op, op->msg);
1022 return 0; 993 return 0;
1023 } 994 }
1024 case 'y': 995 case 'y':
1025 case 'Y': 996 case 'Y':
1026 roll_stats (op); 997 roll_stats (op);
1027 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, ""); 998 send_query (op->contr->socket, CS_QUERY_SINGLECHAR, "");
1028 return 1; 999 return 1;
1029 1000
1030 case 'q': 1001 case 'q':
1031 case 'Q': 1002 case 'Q':
1032 play_again (op); 1003 play_again (op);
1033 return 1; 1004 return 1;
1034 1005
1035 default: 1006 default:
1036 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "Yes, No, Quit or 1-6. Roll again?"); 1007 send_query (op->contr->socket, CS_QUERY_SINGLECHAR, "Yes, No, Quit or 1-6. Roll again?");
1037 return 0; 1008 return 0;
1038 } 1009 }
1039 return 0; 1010 return 0;
1040} 1011}
1041 1012
1051{ 1022{
1052 int tmp_loop; 1023 int tmp_loop;
1053 1024
1054 if (key == 'q' || key == 'Q') 1025 if (key == 'q' || key == 'Q')
1055 { 1026 {
1056 remove_ob (op); 1027 op->remove ();
1057 play_again (op); 1028 play_again (op);
1058 return 0; 1029 return 0;
1059 } 1030 }
1060 if (key == 'd' || key == 'D') 1031 if (key == 'd' || key == 'D')
1061 { 1032 {
1062 char buf[MAX_BUF]; 1033 char buf[MAX_BUF];
1063 1034
1064 /* this must before then initial items are given */ 1035 /* this must before then initial items are given */
1065 esrv_new_player (op->contr, op->weight + op->carrying); 1036 esrv_new_player (op->contr, op->weight + op->carrying);
1037
1066 create_treasure (find_treasurelist ("starting_wealth"), op, 0, 0, 0); 1038 treasurelist *tl = find_treasurelist ("starting_wealth");
1039 if (tl)
1040 create_treasure (tl, op, 0, 0, 0);
1067 1041
1068 INVOKE_PLAYER (BIRTH, op->contr); 1042 INVOKE_PLAYER (BIRTH, op->contr);
1069 INVOKE_PLAYER (LOGIN, op->contr); 1043 INVOKE_PLAYER (LOGIN, op->contr);
1070 1044
1071 op->contr->state = ST_PLAYING; 1045 op->contr->state = ST_PLAYING;
1096 { 1070 {
1097 object *tmp; 1071 object *tmp;
1098 char mapname[MAX_BUF]; 1072 char mapname[MAX_BUF];
1099 1073
1100 snprintf (mapname, MAX_BUF - 1, "%s/%s", first_map_ext_path, &op->arch->name); 1074 snprintf (mapname, MAX_BUF - 1, "%s/%s", first_map_ext_path, &op->arch->name);
1101 tmp = get_object (); 1075 tmp = object::create ();
1102 EXIT_PATH (tmp) = mapname; 1076 EXIT_PATH (tmp) = mapname;
1103 EXIT_X (tmp) = op->x; 1077 EXIT_X (tmp) = op->x;
1104 EXIT_Y (tmp) = op->y; 1078 EXIT_Y (tmp) = op->y;
1105 enter_exit (op, tmp); /* we don't really care if it succeeded; 1079 enter_exit (op, tmp); /* we don't really care if it succeeded;
1106 * if the map isn't there, then stay on the 1080 * if the map isn't there, then stay on the
1107 * default initial map */ 1081 * default initial map */
1108 free_object (tmp); 1082 tmp->destroy ();
1109 } 1083 }
1110 else 1084 else
1111 { 1085 {
1112 LOG (llevDebug, "first_map_ext_path not set\n"); 1086 LOG (llevDebug, "first_map_ext_path not set\n");
1113 } 1087 }
1123 { 1097 {
1124 shstr name = op->name; 1098 shstr name = op->name;
1125 int x = op->x, y = op->y; 1099 int x = op->x, y = op->y;
1126 1100
1127 remove_statbonus (op); 1101 remove_statbonus (op);
1128 remove_ob (op); 1102 op->remove ();
1129 op->arch = get_player_archetype (op->arch); 1103 op->arch = get_player_archetype (op->arch);
1130 copy_object (&op->arch->clone, op); 1104 op->arch->clone.copy_to (op);
1131 op->instantiate (); 1105 op->instantiate ();
1132 op->stats = op->contr->orig_stats; 1106 op->stats = op->contr->orig_stats;
1133 op->name = op->name_pl = name; 1107 op->name = op->name_pl = name;
1134 op->x = x; 1108 op->x = x;
1135 op->y = y; 1109 op->y = y;
1148 op->stats.grace = 0; 1122 op->stats.grace = 0;
1149 1123
1150 if (op->msg) 1124 if (op->msg)
1151 new_draw_info (NDI_BLUE, 0, op, op->msg); 1125 new_draw_info (NDI_BLUE, 0, op, op->msg);
1152 1126
1153 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "Press any key for the next race.\nPress `d' to play this race.\n"); 1127 send_query (op->contr->socket, CS_QUERY_SINGLECHAR, "Press any key for the next race.\nPress `d' to play this race.\n");
1154 return 0; 1128 return 0;
1155} 1129}
1156 1130
1157int 1131int
1158key_confirm_quit (object *op, char key) 1132key_confirm_quit (object *op, char key)
1180 if (settings.set_title == TRUE) 1154 if (settings.set_title == TRUE)
1181 op->contr->own_title[0] = '\0'; 1155 op->contr->own_title[0] = '\0';
1182 1156
1183 if (!QUERY_FLAG (op, FLAG_WAS_WIZ)) 1157 if (!QUERY_FLAG (op, FLAG_WAS_WIZ))
1184 { 1158 {
1185 mapstruct *mp, *next; 1159 maptile *mp, *next;
1186 1160
1187 /* We need to hunt for any per player unique maps in memory and 1161 /* We need to hunt for any per player unique maps in memory and
1188 * get rid of them. The trailing slash in the path is intentional, 1162 * get rid of them. The trailing slash in the path is intentional,
1189 * so that players named 'Ab' won't match against players 'Abe' pathname 1163 * so that players named 'Ab' won't match against players 'Abe' pathname
1190 */ 1164 */
1264 */ 1238 */
1265int 1239int
1266check_pick (object *op) 1240check_pick (object *op)
1267{ 1241{
1268 object *tmp, *next; 1242 object *tmp, *next;
1269 tag_t next_tag = 0, op_tag;
1270 int stop = 0; 1243 int stop = 0;
1271 int j, k, wvratio; 1244 int j, k, wvratio;
1272 char putstring[128], tmpstr[16]; 1245 char putstring[128], tmpstr[16];
1273 1246
1274
1275 /* if you're flying, you cna't pick up anything */ 1247 /* if you're flying, you cna't pick up anything */
1276 if (op->move_type & MOVE_FLYING) 1248 if (op->move_type & MOVE_FLYING)
1277 return 1; 1249 return 1;
1278 1250
1279 op_tag = op->count;
1280
1281 next = op->below; 1251 next = op->below;
1282 if (next)
1283 next_tag = next->count;
1284 1252
1285 /* loop while there are items on the floor that are not marked as 1253 /* loop while there are items on the floor that are not marked as
1286 * destroyed */ 1254 * destroyed */
1287 while (next && !was_destroyed (next, next_tag)) 1255 while (next && !next->destroyed ())
1288 { 1256 {
1289 tmp = next; 1257 tmp = next;
1290 next = tmp->below; 1258 next = tmp->below;
1291 if (next)
1292 next_tag = next->count;
1293 1259
1294 if (was_destroyed (op, op_tag)) 1260 if (op->destroyed ())
1295 return 0; 1261 return 0;
1296 1262
1297 if (!can_pick (op, tmp)) 1263 if (!can_pick (op, tmp))
1298 continue; 1264 continue;
1299 1265
1431 /* question: don't pick up known-poisonous stuff? */ 1397 /* question: don't pick up known-poisonous stuff? */
1432 if (op->contr->mode & PU_FOOD) 1398 if (op->contr->mode & PU_FOOD)
1433 if (tmp->type == FOOD) 1399 if (tmp->type == FOOD)
1434 { 1400 {
1435 pick_up (op, tmp); 1401 pick_up (op, tmp);
1436 if (0)
1437 fprintf (stderr, "FOOD\n");
1438 continue; 1402 continue;
1439 } 1403 }
1404
1440 if (op->contr->mode & PU_DRINK) 1405 if (op->contr->mode & PU_DRINK)
1441 if (tmp->type == DRINK || (tmp->type == POISON && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))) 1406 if (tmp->type == DRINK || (tmp->type == POISON && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)))
1442 { 1407 {
1443 pick_up (op, tmp); 1408 pick_up (op, tmp);
1444 if (0)
1445 fprintf (stderr, "DRINK\n");
1446 continue; 1409 continue;
1447 } 1410 }
1448 1411
1449 if (op->contr->mode & PU_POTION) 1412 if (op->contr->mode & PU_POTION)
1450 if (tmp->type == POTION) 1413 if (tmp->type == POTION)
1451 { 1414 {
1452 pick_up (op, tmp); 1415 pick_up (op, tmp);
1453 if (0)
1454 fprintf (stderr, "POTION\n");
1455 continue; 1416 continue;
1456 } 1417 }
1457 1418
1458 /* spellbooks, skillscrolls and normal books/scrolls */ 1419 /* spellbooks, skillscrolls and normal books/scrolls */
1459 if (op->contr->mode & PU_SPELLBOOK) 1420 if (op->contr->mode & PU_SPELLBOOK)
1460 if (tmp->type == SPELLBOOK) 1421 if (tmp->type == SPELLBOOK)
1461 { 1422 {
1462 pick_up (op, tmp); 1423 pick_up (op, tmp);
1463 if (0)
1464 fprintf (stderr, "SPELLBOOK\n");
1465 continue; 1424 continue;
1466 } 1425 }
1426
1467 if (op->contr->mode & PU_SKILLSCROLL) 1427 if (op->contr->mode & PU_SKILLSCROLL)
1468 if (tmp->type == SKILLSCROLL) 1428 if (tmp->type == SKILLSCROLL)
1469 { 1429 {
1470 pick_up (op, tmp); 1430 pick_up (op, tmp);
1471 if (0)
1472 fprintf (stderr, "SKILLSCROLL\n");
1473 continue; 1431 continue;
1474 } 1432 }
1433
1475 if (op->contr->mode & PU_READABLES) 1434 if (op->contr->mode & PU_READABLES)
1476 if (tmp->type == BOOK || tmp->type == SCROLL) 1435 if (tmp->type == BOOK || tmp->type == SCROLL)
1477 { 1436 {
1478 pick_up (op, tmp); 1437 pick_up (op, tmp);
1479 if (0)
1480 fprintf (stderr, "READABLES\n");
1481 continue; 1438 continue;
1482 } 1439 }
1483 1440
1484 /* wands/staves/rods/horns */ 1441 /* wands/staves/rods/horns */
1485 if (op->contr->mode & PU_MAGIC_DEVICE) 1442 if (op->contr->mode & PU_MAGIC_DEVICE)
1486 if (tmp->type == WAND || tmp->type == ROD || tmp->type == HORN) 1443 if (tmp->type == WAND || tmp->type == ROD || tmp->type == HORN)
1487 { 1444 {
1488 pick_up (op, tmp); 1445 pick_up (op, tmp);
1489 if (0)
1490 fprintf (stderr, "MAGIC_DEVICE\n");
1491 continue; 1446 continue;
1492 } 1447 }
1493 1448
1494 /* pick up all magical items */ 1449 /* pick up all magical items */
1495 if (op->contr->mode & PU_MAGICAL) 1450 if (op->contr->mode & PU_MAGICAL)
1496 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)) 1451 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))
1497 { 1452 {
1498 pick_up (op, tmp); 1453 pick_up (op, tmp);
1499 if (0)
1500 fprintf (stderr, "MAGICAL\n");
1501 continue; 1454 continue;
1502 } 1455 }
1503 1456
1504 if (op->contr->mode & PU_VALUABLES) 1457 if (op->contr->mode & PU_VALUABLES)
1505 { 1458 {
1506 if (tmp->type == MONEY || tmp->type == GEM) 1459 if (tmp->type == MONEY || tmp->type == GEM)
1507 { 1460 {
1508 pick_up (op, tmp); 1461 pick_up (op, tmp);
1509 if (0)
1510 fprintf (stderr, "MONEY/GEM\n");
1511 continue; 1462 continue;
1512 } 1463 }
1513 } 1464 }
1514 1465
1515 /* rings & amulets - talismans seems to be typed AMULET */ 1466 /* rings & amulets - talismans seems to be typed AMULET */
1516 if (op->contr->mode & PU_JEWELS) 1467 if (op->contr->mode & PU_JEWELS)
1517 if (tmp->type == RING || tmp->type == AMULET) 1468 if (tmp->type == RING || tmp->type == AMULET)
1518 { 1469 {
1519 pick_up (op, tmp); 1470 pick_up (op, tmp);
1471 continue;
1520 if (0) 1472 }
1521 fprintf (stderr, "JEWELS\n"); 1473
1474 /* we don't forget dragon food */
1475 if (op->contr->mode & PU_FLESH)
1476 if (tmp->type == FLESH)
1477 {
1478 pick_up (op, tmp);
1522 continue; 1479 continue;
1523 } 1480 }
1524 1481
1525 /* bows and arrows. Bows are good for selling! */ 1482 /* bows and arrows. Bows are good for selling! */
1526 if (op->contr->mode & PU_BOW) 1483 if (op->contr->mode & PU_BOW)
1527 if (tmp->type == BOW) 1484 if (tmp->type == BOW)
1528 { 1485 {
1529 pick_up (op, tmp); 1486 pick_up (op, tmp);
1530 if (0)
1531 fprintf (stderr, "BOW\n");
1532 continue; 1487 continue;
1533 } 1488 }
1489
1534 if (op->contr->mode & PU_ARROW) 1490 if (op->contr->mode & PU_ARROW)
1535 if (tmp->type == ARROW) 1491 if (tmp->type == ARROW)
1536 { 1492 {
1537 pick_up (op, tmp); 1493 pick_up (op, tmp);
1538 if (0)
1539 fprintf (stderr, "ARROW\n");
1540 continue; 1494 continue;
1541 } 1495 }
1542 1496
1543 /* all kinds of armor etc. */ 1497 /* all kinds of armor etc. */
1544 if (op->contr->mode & PU_ARMOUR) 1498 if (op->contr->mode & PU_ARMOUR)
1545 if (tmp->type == ARMOUR) 1499 if (tmp->type == ARMOUR)
1546 { 1500 {
1547 pick_up (op, tmp); 1501 pick_up (op, tmp);
1548 if (0)
1549 fprintf (stderr, "ARMOUR\n");
1550 continue; 1502 continue;
1551 } 1503 }
1504
1552 if (op->contr->mode & PU_HELMET) 1505 if (op->contr->mode & PU_HELMET)
1553 if (tmp->type == HELMET) 1506 if (tmp->type == HELMET)
1554 { 1507 {
1555 pick_up (op, tmp); 1508 pick_up (op, tmp);
1556 if (0)
1557 fprintf (stderr, "HELMET\n");
1558 continue; 1509 continue;
1559 } 1510 }
1511
1560 if (op->contr->mode & PU_SHIELD) 1512 if (op->contr->mode & PU_SHIELD)
1561 if (tmp->type == SHIELD) 1513 if (tmp->type == SHIELD)
1562 { 1514 {
1563 pick_up (op, tmp); 1515 pick_up (op, tmp);
1564 if (0)
1565 fprintf (stderr, "SHIELD\n");
1566 continue; 1516 continue;
1567 } 1517 }
1518
1568 if (op->contr->mode & PU_BOOTS) 1519 if (op->contr->mode & PU_BOOTS)
1569 if (tmp->type == BOOTS) 1520 if (tmp->type == BOOTS)
1570 { 1521 {
1571 pick_up (op, tmp); 1522 pick_up (op, tmp);
1572 if (0)
1573 fprintf (stderr, "BOOTS\n");
1574 continue; 1523 continue;
1575 } 1524 }
1525
1576 if (op->contr->mode & PU_GLOVES) 1526 if (op->contr->mode & PU_GLOVES)
1577 if (tmp->type == GLOVES) 1527 if (tmp->type == GLOVES)
1578 { 1528 {
1579 pick_up (op, tmp); 1529 pick_up (op, tmp);
1580 if (0)
1581 fprintf (stderr, "GLOVES\n");
1582 continue; 1530 continue;
1583 } 1531 }
1532
1584 if (op->contr->mode & PU_CLOAK) 1533 if (op->contr->mode & PU_CLOAK)
1585 if (tmp->type == CLOAK) 1534 if (tmp->type == CLOAK)
1586 { 1535 {
1587 pick_up (op, tmp); 1536 pick_up (op, tmp);
1588 if (0)
1589 fprintf (stderr, "GLOVES\n");
1590 continue; 1537 continue;
1591 } 1538 }
1592 1539
1593 /* hoping to catch throwing daggers here */ 1540 /* hoping to catch throwing daggers here */
1594 if (op->contr->mode & PU_MISSILEWEAPON) 1541 if (op->contr->mode & PU_MISSILEWEAPON)
1595 if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_IS_THROWN)) 1542 if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_IS_THROWN))
1596 { 1543 {
1597 pick_up (op, tmp); 1544 pick_up (op, tmp);
1598 if (0)
1599 fprintf (stderr, "MISSILEWEAPON\n");
1600 continue; 1545 continue;
1601 } 1546 }
1602 1547
1603 /* careful: chairs and tables are weapons! */ 1548 /* careful: chairs and tables are weapons! */
1604 if (op->contr->mode & PU_ALLWEAPON) 1549 if (op->contr->mode & PU_ALLWEAPON)
1607 { 1552 {
1608 if (strstr (tmp->name, "table") == NULL && strstr (tmp->arch->name, "table") == NULL && 1553 if (strstr (tmp->name, "table") == NULL && strstr (tmp->arch->name, "table") == NULL &&
1609 strstr (tmp->name, "chair") && strstr (tmp->arch->name, "chair") == NULL) 1554 strstr (tmp->name, "chair") && strstr (tmp->arch->name, "chair") == NULL)
1610 { 1555 {
1611 pick_up (op, tmp); 1556 pick_up (op, tmp);
1612 if (0)
1613 fprintf (stderr, "WEAPON\n");
1614 continue; 1557 continue;
1615 } 1558 }
1616 } 1559 }
1560
1617 if (tmp->type == WEAPON && tmp->name == NULL) 1561 if (tmp->type == WEAPON && tmp->name == NULL)
1618 { 1562 {
1619 if (strstr (tmp->arch->name, "table") == NULL && strstr (tmp->arch->name, "chair") == NULL) 1563 if (strstr (tmp->arch->name, "table") == NULL && strstr (tmp->arch->name, "chair") == NULL)
1620 { 1564 {
1621 pick_up (op, tmp); 1565 pick_up (op, tmp);
1622 if (0)
1623 fprintf (stderr, "WEAPON\n");
1624 continue; 1566 continue;
1625 } 1567 }
1626 } 1568 }
1627 } 1569 }
1628 1570
1629 /* misc stuff that's useful */ 1571 /* misc stuff that's useful */
1630 if (op->contr->mode & PU_KEY) 1572 if (op->contr->mode & PU_KEY)
1631 if (tmp->type == KEY || tmp->type == SPECIAL_KEY) 1573 if (tmp->type == KEY || tmp->type == SPECIAL_KEY)
1632 { 1574 {
1633 pick_up (op, tmp); 1575 pick_up (op, tmp);
1634 if (0)
1635 fprintf (stderr, "KEY\n");
1636 continue; 1576 continue;
1637 } 1577 }
1638 1578
1639 /* any of the last 4 bits set means we use the ratio for value 1579 /* any of the last 4 bits set means we use the ratio for value
1640 * pickups */ 1580 * pickups */
1662 continue; 1602 continue;
1663 } 1603 }
1664 } 1604 }
1665 } /* the new pickup model */ 1605 } /* the new pickup model */
1666 } 1606 }
1607
1667 return !stop; 1608 return !stop;
1668} 1609}
1669 1610
1670/* 1611/*
1671 * Find an arrow in the inventory and after that 1612 * Find an arrow in the inventory and after that
1770 1711
1771object * 1712object *
1772pick_arrow_target (object *op, const char *type, int dir) 1713pick_arrow_target (object *op, const char *type, int dir)
1773{ 1714{
1774 object *tmp = NULL; 1715 object *tmp = NULL;
1775 mapstruct *m; 1716 maptile *m;
1776 int i, mflags, found, number; 1717 int i, mflags, found, number;
1777 sint16 x, y; 1718 sint16 x, y;
1778 1719
1779 if (op->map == NULL) 1720 if (op->map == NULL)
1780 return find_arrow (op, type); 1721 return find_arrow (op, type);
1840 */ 1781 */
1841int 1782int
1842fire_bow (object *op, object *part, object *arrow, int dir, int wc_mod, sint16 sx, sint16 sy) 1783fire_bow (object *op, object *part, object *arrow, int dir, int wc_mod, sint16 sx, sint16 sy)
1843{ 1784{
1844 object *left, *bow; 1785 object *left, *bow;
1845 tag_t left_tag, tag;
1846 int bowspeed, mflags; 1786 int bowspeed, mflags;
1847 mapstruct *m; 1787 maptile *m;
1848 1788
1849 if (!dir) 1789 if (!dir)
1850 { 1790 {
1851 new_draw_info (NDI_UNIQUE, 0, op, "You can't shoot yourself!"); 1791 new_draw_info (NDI_UNIQUE, 0, op, "You can't shoot yourself!");
1852 return 0; 1792 return 0;
1906 } 1846 }
1907 1847
1908 /* this should not happen, but sometimes does */ 1848 /* this should not happen, but sometimes does */
1909 if (arrow->nrof == 0) 1849 if (arrow->nrof == 0)
1910 { 1850 {
1911 remove_ob (arrow); 1851 arrow->destroy ();
1912 free_object (arrow);
1913 return 0; 1852 return 0;
1914 } 1853 }
1915 1854
1916 left = arrow; /* these are arrows left to the player */ 1855 left = arrow; /* these are arrows left to the player */
1917 left_tag = left->count;
1918 arrow = get_split_ob (arrow, 1); 1856 arrow = get_split_ob (arrow, 1);
1919 if (arrow == NULL) 1857 if (arrow == NULL)
1920 { 1858 {
1921 new_draw_info_format (NDI_UNIQUE, 0, op, "You have no %s left.", &bow->race); 1859 new_draw_info_format (NDI_UNIQUE, 0, op, "You have no %s left.", &bow->race);
1922 return 0; 1860 return 0;
1923 } 1861 }
1924 set_owner (arrow, op); 1862 arrow->set_owner (op);
1925 arrow->skill = bow->skill; 1863 arrow->skill = bow->skill;
1926 1864
1927 arrow->direction = dir; 1865 arrow->direction = dir;
1928 arrow->x = sx; 1866 arrow->x = sx;
1929 arrow->y = sy; 1867 arrow->y = sy;
1965 arrow->level = op->chosen_skill ? op->chosen_skill->level : op->level; 1903 arrow->level = op->chosen_skill ? op->chosen_skill->level : op->level;
1966 } 1904 }
1967 else 1905 else
1968 { 1906 {
1969 arrow->stats.wc = op->stats.wc - bow->magic - arrow->magic - arrow->stats.wc + wc_mod; 1907 arrow->stats.wc = op->stats.wc - bow->magic - arrow->magic - arrow->stats.wc + wc_mod;
1970
1971 arrow->level = op->level; 1908 arrow->level = op->level;
1972 } 1909 }
1910
1973 if (arrow->attacktype == AT_PHYSICAL) 1911 if (arrow->attacktype == AT_PHYSICAL)
1974 arrow->attacktype |= bow->attacktype; 1912 arrow->attacktype |= bow->attacktype;
1913
1975 if (bow->slaying != NULL) 1914 if (bow->slaying != NULL)
1976 arrow->slaying = bow->slaying; 1915 arrow->slaying = bow->slaying;
1977 1916
1978 arrow->map = m; 1917 arrow->map = m;
1979 arrow->move_type = MOVE_FLY_LOW; 1918 arrow->move_type = MOVE_FLY_LOW;
1980 arrow->move_on = MOVE_FLY_LOW | MOVE_WALK; 1919 arrow->move_on = MOVE_FLY_LOW | MOVE_WALK;
1981 1920
1982 play_sound_map (op->map, op->x, op->y, SOUND_FIRE_ARROW); 1921 play_sound_map (op->map, op->x, op->y, SOUND_FIRE_ARROW);
1983 tag = arrow->count;
1984 insert_ob_in_map (arrow, m, op, 0); 1922 insert_ob_in_map (arrow, m, op, 0);
1985 1923
1986 if (!was_destroyed (arrow, tag)) 1924 if (!arrow->destroyed ())
1987 move_arrow (arrow); 1925 move_arrow (arrow);
1988 1926
1989 if (op->type == PLAYER) 1927 if (op->type == PLAYER)
1990 { 1928 {
1991 if (was_destroyed (left, left_tag)) 1929 if (left->destroyed ())
1992 esrv_del_item (op->contr, left_tag); 1930 esrv_del_item (op->contr, left->count);
1993 else 1931 else
1994 esrv_send_item (op, left); 1932 esrv_send_item (op, left);
1995 } 1933 }
1934
1996 return 1; 1935 return 1;
1997} 1936}
1998 1937
1999/* Special fire code for players - this takes into 1938/* Special fire code for players - this takes into
2000 * account the special fire modes players can have 1939 * account the special fire modes players can have
2136 case range_misc: 2075 case range_misc:
2137 fire_misc_object (op, dir); 2076 fire_misc_object (op, dir);
2138 return; 2077 return;
2139 2078
2140 case range_golem: /* Control summoned monsters from scrolls */ 2079 case range_golem: /* Control summoned monsters from scrolls */
2141 if (op->contr->ranges[range_golem] == NULL || op->contr->golem_count != op->contr->ranges[range_golem]->count) 2080 if (QUERY_FLAG (op->contr->ranges[range_golem], FLAG_REMOVED))
2142 { 2081 {
2143 op->contr->ranges[range_golem] = NULL; 2082 op->contr->ranges[range_golem] = 0;
2144 op->contr->shoottype = range_none; 2083 op->contr->shoottype = range_none;
2145 op->contr->golem_count = 0;
2146 } 2084 }
2147 else 2085 else
2148 control_golem (op->contr->ranges[range_golem], dir); 2086 control_golem (op->contr->ranges[range_golem], dir);
2149 return; 2087 return;
2150 2088
2312move_player_attack (object *op, int dir) 2250move_player_attack (object *op, int dir)
2313{ 2251{
2314 object *tmp, *mon; 2252 object *tmp, *mon;
2315 sint16 nx, ny; 2253 sint16 nx, ny;
2316 int on_battleground; 2254 int on_battleground;
2317 mapstruct *m; 2255 maptile *m;
2318 2256
2319 nx = freearr_x[dir] + op->x; 2257 nx = freearr_x[dir] + op->x;
2320 ny = freearr_y[dir] + op->y; 2258 ny = freearr_y[dir] + op->y;
2321 2259
2322 on_battleground = op_on_battleground (op, NULL, NULL); 2260 on_battleground = op_on_battleground (op, NULL, NULL);
2358 if (tmp == op) 2296 if (tmp == op)
2359 { 2297 {
2360 tmp = tmp->above; 2298 tmp = tmp->above;
2361 continue; 2299 continue;
2362 } 2300 }
2301
2363 if (QUERY_FLAG (tmp, FLAG_ALIVE)) 2302 if (QUERY_FLAG (tmp, FLAG_ALIVE))
2364 { 2303 {
2365 mon = tmp; 2304 mon = tmp;
2366 break; 2305 break;
2367 } 2306 }
2307
2368 if (tmp->type == LOCKED_DOOR || QUERY_FLAG (tmp, FLAG_CAN_ROLL)) 2308 if (tmp->type == LOCKED_DOOR || QUERY_FLAG (tmp, FLAG_CAN_ROLL))
2369 mon = tmp; 2309 mon = tmp;
2310
2370 tmp = tmp->above; 2311 tmp = tmp->above;
2371 } 2312 }
2372 2313
2373 if (mon == NULL) /* This happens anytime the player tries to move */ 2314 if (mon == NULL) /* This happens anytime the player tries to move */
2374 return; /* into a wall */ 2315 return; /* into a wall */
2393 * player owns it and it is either friendly or unagressive. 2334 * player owns it and it is either friendly or unagressive.
2394 */ 2335 */
2395 if ((op->type == PLAYER) 2336 if ((op->type == PLAYER)
2396#if COZY_SERVER 2337#if COZY_SERVER
2397 && 2338 &&
2398 ((get_owner (mon) && get_owner (mon)->contr 2339 ((mon->owner && mon->owner->contr
2399 && same_party (get_owner (mon)->contr->party, op->contr->party)) || get_owner (mon) == op) 2340 && same_party (mon->owner->contr->party, op->contr->party)) || mon->owner == op)
2400#else 2341#else
2401 && get_owner (mon) == op 2342 && mon->owner == op
2402#endif 2343#endif
2403 && (QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY))) 2344 && (QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY)))
2404 { 2345 {
2405 /* If we're braced, we don't want to switch places with it */ 2346 /* If we're braced, we don't want to switch places with it */
2406 if (op->contr->braced) 2347 if (op->contr->braced)
2593 /* I've been seeing crashes where the golem has been destroyed, but 2534 /* I've been seeing crashes where the golem has been destroyed, but
2594 * the player object still points to the defunct golem. The code that 2535 * the player object still points to the defunct golem. The code that
2595 * destroys the golem looks correct, and it doesn't always happen, so 2536 * destroys the golem looks correct, and it doesn't always happen, so
2596 * put this in a a workaround to clean up the golem pointer. 2537 * put this in a a workaround to clean up the golem pointer.
2597 */ 2538 */
2598 if (op->contr->ranges[range_golem] &&
2599 ((op->contr->golem_count != op->contr->ranges[range_golem]->count) || QUERY_FLAG (op->contr->ranges[range_golem], FLAG_REMOVED))) 2539 if (op->contr->ranges[range_golem] && QUERY_FLAG (op->contr->ranges[range_golem], FLAG_REMOVED))
2600 {
2601 op->contr->ranges[range_golem] = NULL; 2540 op->contr->ranges[range_golem] = 0;
2602 op->contr->golem_count = 0;
2603 }
2604 2541
2605 /* call this here - we also will call this in do_ericserver, but 2542 /* call this here - we also will call this in do_ericserver, but
2606 * the players time has been increased when doericserver has been 2543 * the players time has been increased when doericserver has been
2607 * called, so we recheck it here. 2544 * called, so we recheck it here.
2608 */ 2545 */
2609 HandleClient (&op->contr->socket, op->contr); 2546 HandleClient (op->contr->socket, op->contr);
2610 if (op->speed_left < 0) 2547 if (op->speed_left < 0)
2611 return 0; 2548 return 0;
2612 2549
2613 if (op->direction && (op->contr->run_on || op->contr->fire_on)) 2550 if (op->direction && (op->contr->run_on || op->contr->fire_on))
2614 { 2551 {
2639 for (tmp = op->inv; tmp != NULL; tmp = tmp->below) 2576 for (tmp = op->inv; tmp != NULL; tmp = tmp->below)
2640 if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE)) 2577 if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE))
2641 { 2578 {
2642 play_sound_map (op->map, op->x, op->y, SOUND_OB_EVAPORATE); 2579 play_sound_map (op->map, op->x, op->y, SOUND_OB_EVAPORATE);
2643 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s vibrates violently, then evaporates.", query_name (tmp)); 2580 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s vibrates violently, then evaporates.", query_name (tmp));
2581
2644 if (op->contr) 2582 if (op->contr)
2645 esrv_del_item (op->contr, tmp->count); 2583 esrv_del_item (op->contr, tmp->count);
2646 remove_ob (tmp); 2584
2647 free_object (tmp); 2585 tmp->destroy ();
2648 CLEAR_FLAG (op, FLAG_LIFESAVE); 2586 CLEAR_FLAG (op, FLAG_LIFESAVE);
2587
2649 if (op->stats.hp < 0) 2588 if (op->stats.hp < 0)
2650 op->stats.hp = op->stats.maxhp; 2589 op->stats.hp = op->stats.maxhp;
2590
2651 if (op->stats.food < 0) 2591 if (op->stats.food < 0)
2652 op->stats.food = 999; 2592 op->stats.food = 999;
2593
2653 fix_player (op); 2594 fix_player (op);
2654 return 1; 2595 return 1;
2655 } 2596 }
2656 LOG (llevError, "Error: LIFESAVE set without applied object.\n"); 2597 LOG (llevError, "Error: LIFESAVE set without applied object.\n");
2657 CLEAR_FLAG (op, FLAG_LIFESAVE); 2598 CLEAR_FLAG (op, FLAG_LIFESAVE);
2674 next = op->below; /* Make sure we have a good value, in case 2615 next = op->below; /* Make sure we have a good value, in case
2675 * we remove object 'op' 2616 * we remove object 'op'
2676 */ 2617 */
2677 if (QUERY_FLAG (op, FLAG_UNPAID)) 2618 if (QUERY_FLAG (op, FLAG_UNPAID))
2678 { 2619 {
2679 remove_ob (op); 2620 op->remove ();
2680 op->x = env->x; 2621 op->x = env->x;
2681 op->y = env->y; 2622 op->y = env->y;
2682 if (env->type == PLAYER) 2623 if (env->type == PLAYER)
2683 esrv_del_item (env->contr, op->count); 2624 esrv_del_item (env->contr, op->count);
2684 insert_ob_in_map (op, env->map, NULL, 0); 2625 insert_ob_in_map (op, env->map, NULL, 0);
2952{ 2893{
2953 char buf[MAX_BUF]; 2894 char buf[MAX_BUF];
2954 int x, y; 2895 int x, y;
2955 2896
2956 //int i; 2897 //int i;
2957 mapstruct *map; /* this is for resurrection */ 2898 maptile *map; /* this is for resurrection */
2958 2899
2959 /* int z; 2900 /* int z;
2960 int num_stats_lose; 2901 int num_stats_lose;
2961 int lost_a_stat; 2902 int lost_a_stat;
2962 int lose_this_stat; 2903 int lose_this_stat;
2981 /* restore player */ 2922 /* restore player */
2982 at = archetype::find ("poisoning"); 2923 at = archetype::find ("poisoning");
2983 tmp = present_arch_in_ob (at, op); 2924 tmp = present_arch_in_ob (at, op);
2984 if (tmp) 2925 if (tmp)
2985 { 2926 {
2986 remove_ob (tmp); 2927 tmp->destroy ();
2987 free_object (tmp);
2988 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed"); 2928 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed");
2989 } 2929 }
2990 2930
2991 at = archetype::find ("confusion"); 2931 at = archetype::find ("confusion");
2992 tmp = present_arch_in_ob (at, op); 2932 tmp = present_arch_in_ob (at, op);
2993 if (tmp) 2933 if (tmp)
2994 { 2934 {
2995 remove_ob (tmp); 2935 tmp->destroy ();
2996 free_object (tmp);
2997 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer"); 2936 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer");
2998 } 2937 }
2999 2938
3000 cure_disease (op, 0); /* remove any disease */ 2939 cure_disease (op, 0); /* remove any disease */
3001 op->stats.hp = op->stats.maxhp; 2940 op->stats.hp = op->stats.maxhp;
3178 /* determine_god() seems to not work sometimes... why is this? 3117 /* determine_god() seems to not work sometimes... why is this?
3179 Should I be using something else? GD */ 3118 Should I be using something else? GD */
3180 const char *god = determine_god (op); 3119 const char *god = determine_god (op);
3181 3120
3182 if (god && (strcmp (god, "none"))) 3121 if (god && (strcmp (god, "none")))
3183 new_draw_info_format (NDI_UNIQUE, 0, op, "For a brief " "moment you feel the holy presence of %s protecting" " you.", god); 3122 new_draw_info_format (NDI_UNIQUE, 0, op, "For a brief moment you feel the holy presence of %s protecting" " you.", god);
3184 else 3123 else
3185 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you" " feel a holy presence protecting you."); 3124 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you feel a holy presence protecting you.");
3186 } 3125 }
3126#else
3127 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you" " feel a holy presence protecting you from losing yourself completely.");
3187#endif 3128#endif
3188 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you" " feel a holy presence protecting you from losing yourself completely.");
3189 3129
3190 /* Put a gravestone up where the character 'almost' died. List the 3130 /* Put a gravestone up where the character 'almost' died. List the
3191 * exp loss on the stone. 3131 * exp loss on the stone.
3192 */ 3132 */
3193 tmp = arch_to_object (archetype::find ("gravestone")); 3133 tmp = arch_to_object (archetype::find ("gravestone"));
3198 sprintf (buf, "RIP\nHere rests the hero %s the %s,\n" "who was killed\n" "by %s.\n", &op->name, op->contr->title, op->contr->killer); 3138 sprintf (buf, "RIP\nHere rests the hero %s the %s,\n" "who was killed\n" "by %s.\n", &op->name, op->contr->title, op->contr->killer);
3199 tmp->msg = buf; 3139 tmp->msg = buf;
3200 tmp->x = op->x, tmp->y = op->y; 3140 tmp->x = op->x, tmp->y = op->y;
3201 insert_ob_in_map (tmp, op->map, NULL, 0); 3141 insert_ob_in_map (tmp, op->map, NULL, 0);
3202 3142
3203 /**************************************/ 3143 /**************************************/
3204 /* */ 3144 /* */
3205 /* Subtract the experience points, */ 3145 /* Subtract the experience points, */
3206 /* if we died cause of food, give us */ 3146 /* if we died cause of food, give us */
3207 /* food, and reset HP's... */ 3147 /* food, and reset HP's... */
3208 /* */ 3148 /* */
3209
3210 /**************************************/ 3149 /**************************************/
3211 3150
3212 /* remove any poisoning and confusion the character may be suffering. */ 3151 /* remove any poisoning and confusion the character may be suffering. */
3213 /* restore player */ 3152 /* restore player */
3214 at = archetype::find ("poisoning"); 3153 at = archetype::find ("poisoning");
3215 tmp = present_arch_in_ob (at, op); 3154 tmp = present_arch_in_ob (at, op);
3155
3216 if (tmp) 3156 if (tmp)
3217 { 3157 {
3218 remove_ob (tmp); 3158 tmp->destroy ();
3219 free_object (tmp);
3220 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed"); 3159 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed");
3221 } 3160 }
3222 3161
3223 at = archetype::find ("confusion"); 3162 at = archetype::find ("confusion");
3224 tmp = present_arch_in_ob (at, op); 3163 tmp = present_arch_in_ob (at, op);
3225 if (tmp) 3164 if (tmp)
3226 { 3165 {
3227 remove_ob (tmp); 3166 tmp->destroy ();
3228 free_object (tmp);
3229 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer"); 3167 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer");
3230 } 3168 }
3169
3231 cure_disease (op, 0); /* remove any disease */ 3170 cure_disease (op, 0); /* remove any disease */
3232 3171
3233 /*add_exp(op, (op->stats.exp * -0.20)); */ 3172 /*add_exp(op, (op->stats.exp * -0.20)); */
3234 apply_death_exp_penalty (op); 3173 apply_death_exp_penalty (op);
3235 if (op->stats.food < 100) 3174 if (op->stats.food < 100)
3245 */ 3184 */
3246 3185
3247 if (is_in_shop (op)) 3186 if (is_in_shop (op))
3248 remove_unpaid_objects (op->inv, op); 3187 remove_unpaid_objects (op->inv, op);
3249 3188
3250 /****************************************/ 3189 /****************************************/
3251 /* */ 3190 /* */
3252 /* Move player to his current respawn- */ 3191 /* Move player to his current respawn- */
3253 /* position (usually last savebed) */ 3192 /* position (usually last savebed) */
3254 /* */ 3193 /* */
3255
3256 /****************************************/ 3194 /****************************************/
3257 3195
3258 enter_player_savebed (op); 3196 enter_player_savebed (op);
3259 3197
3260 /* Save the player before inserting the force to reduce 3198 /* Save the player before inserting the force to reduce
3261 * chance of abuse. 3199 * chance of abuse.
3268 * spell effects. So first see if there is a spell effect 3206 * spell effects. So first see if there is a spell effect
3269 * on the space that might harm the player. 3207 * on the space that might harm the player.
3270 */ 3208 */
3271 will_kill_again = 0; 3209 will_kill_again = 0;
3272 for (tmp = get_map_ob (op->map, op->x, op->y); tmp; tmp = tmp->above) 3210 for (tmp = get_map_ob (op->map, op->x, op->y); tmp; tmp = tmp->above)
3273 {
3274 if (tmp->type == SPELL_EFFECT) 3211 if (tmp->type == SPELL_EFFECT)
3275 will_kill_again |= tmp->attacktype; 3212 will_kill_again |= tmp->attacktype;
3276 } 3213
3277 if (will_kill_again) 3214 if (will_kill_again)
3278 { 3215 {
3279 object *force; 3216 object *force;
3280 int at; 3217 int at;
3281 3218
3283 /* 50 ticks should be enough time for the spell to abate */ 3220 /* 50 ticks should be enough time for the spell to abate */
3284 force->speed = 0.1; 3221 force->speed = 0.1;
3285 force->speed_left = -5.0; 3222 force->speed_left = -5.0;
3286 SET_FLAG (force, FLAG_APPLIED); 3223 SET_FLAG (force, FLAG_APPLIED);
3287 for (at = 0; at < NROFATTACKS; at++) 3224 for (at = 0; at < NROFATTACKS; at++)
3288 {
3289 if (will_kill_again & (1 << at)) 3225 if (will_kill_again & (1 << at))
3290 force->resist[at] = 100; 3226 force->resist[at] = 100;
3291 } 3227
3292 insert_ob_in_ob (force, op); 3228 insert_ob_in_ob (force, op);
3293 fix_player (op); 3229 fix_player (op);
3294 3230
3295 } 3231 }
3296 3232
3306 op->contr->party = NULL; 3242 op->contr->party = NULL;
3307 if (settings.set_title == TRUE) 3243 if (settings.set_title == TRUE)
3308 op->contr->own_title[0] = '\0'; 3244 op->contr->own_title[0] = '\0';
3309 new_draw_info (NDI_UNIQUE | NDI_ALL, 0, NULL, buf); 3245 new_draw_info (NDI_UNIQUE | NDI_ALL, 0, NULL, buf);
3310 check_score (op); 3246 check_score (op);
3247
3311 if (op->contr->ranges[range_golem] != NULL) 3248 if (op->contr->ranges[range_golem])
3312 { 3249 {
3313 remove_friendly_object (op->contr->ranges[range_golem]); 3250 remove_friendly_object (op->contr->ranges[range_golem]);
3314 remove_ob (op->contr->ranges[range_golem]); 3251 op->contr->ranges[range_golem]->destroy ();
3315 free_object (op->contr->ranges[range_golem]);
3316 op->contr->ranges[range_golem] = NULL; 3252 op->contr->ranges[range_golem] = 0;
3317 op->contr->golem_count = 0;
3318 } 3253 }
3254
3319 loot_object (op); /* Remove some of the items for good */ 3255 loot_object (op); /* Remove some of the items for good */
3320 remove_ob (op); 3256 op->remove ();
3321 op->direction = 0; 3257 op->direction = 0;
3322 3258
3323 if (!QUERY_FLAG (op, FLAG_WAS_WIZ) && op->stats.exp) 3259 if (!QUERY_FLAG (op, FLAG_WAS_WIZ) && op->stats.exp)
3324 { 3260 {
3325 delete_character (op->name, 0); 3261 delete_character (op->name, 0);
3378 for (tmp = op->inv; tmp != NULL; tmp = next) 3314 for (tmp = op->inv; tmp != NULL; tmp = next)
3379 { 3315 {
3380 next = tmp->below; 3316 next = tmp->below;
3381 if (tmp->type == EXPERIENCE || tmp->invisible) 3317 if (tmp->type == EXPERIENCE || tmp->invisible)
3382 continue; 3318 continue;
3383 remove_ob (tmp); 3319 tmp->remove ();
3384 tmp->x = op->x, tmp->y = op->y; 3320 tmp->x = op->x, tmp->y = op->y;
3385 if (tmp->type == CONTAINER) 3321 if (tmp->type == CONTAINER)
3386 { /* empty container to ground */ 3322 { /* empty container to ground */
3387 loot_object (tmp); 3323 loot_object (tmp);
3388 } 3324 }
3389 if (!QUERY_FLAG (tmp, FLAG_UNIQUE) && (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || QUERY_FLAG (tmp, FLAG_NO_DROP) || !(RANDOM () % 3))) 3325 if (!QUERY_FLAG (tmp, FLAG_UNIQUE) && (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || QUERY_FLAG (tmp, FLAG_NO_DROP) || !(RANDOM () % 3)))
3390 { 3326 {
3391 if (tmp->nrof > 1) 3327 if (tmp->nrof > 1)
3392 { 3328 {
3393 tmp2 = get_split_ob (tmp, 1 + RANDOM () % (tmp->nrof - 1)); 3329 tmp2 = get_split_ob (tmp, 1 + RANDOM () % (tmp->nrof - 1));
3394 free_object (tmp2); 3330 tmp2->destroy ();
3395 insert_ob_in_map (tmp, op->map, NULL, 0); 3331 insert_ob_in_map (tmp, op->map, NULL, 0);
3396 } 3332 }
3397 else 3333 else
3398 free_object (tmp); 3334 tmp->destroy ();
3399 } 3335 }
3400 else 3336 else
3401 insert_ob_in_map (tmp, op->map, NULL, 0); 3337 insert_ob_in_map (tmp, op->map, NULL, 0);
3402 } 3338 }
3403} 3339}
3468 if (op->type == PLAYER) 3404 if (op->type == PLAYER)
3469 new_draw_info_format (NDI_UNIQUE, 0, op, "You cast %s.", &spob->name); 3405 new_draw_info_format (NDI_UNIQUE, 0, op, "You cast %s.", &spob->name);
3470 3406
3471 cast_spell (op, throw_ob, dir, spob, NULL); 3407 cast_spell (op, throw_ob, dir, spob, NULL);
3472 3408
3473 if (!QUERY_FLAG (throw_ob, FLAG_REMOVED)) 3409 throw_ob->destroy ();
3474 remove_ob (throw_ob);
3475 free_object (throw_ob);
3476} 3410}
3477 3411
3478void 3412void
3479make_visible (object *op) 3413make_visible (object *op)
3480{ 3414{
3596int 3530int
3597stand_near_hostile (object *who) 3531stand_near_hostile (object *who)
3598{ 3532{
3599 object *tmp = NULL; 3533 object *tmp = NULL;
3600 int i, friendly = 0, player = 0, mflags; 3534 int i, friendly = 0, player = 0, mflags;
3601 mapstruct *m; 3535 maptile *m;
3602 sint16 x, y; 3536 sint16 x, y;
3603 3537
3604 if (!who) 3538 if (!who)
3605 return 0; 3539 return 0;
3606 3540
3687 3621
3688 /* only the viewable area the player sees is updated by LOS 3622 /* only the viewable area the player sees is updated by LOS
3689 * code, so we need to restrict ourselves to that range of values 3623 * code, so we need to restrict ourselves to that range of values
3690 * for any meaningful values. 3624 * for any meaningful values.
3691 */ 3625 */
3692 if (FABS (dx) <= (pl->contr->socket.mapx / 2) && 3626 if (FABS (dx) <= (pl->contr->socket->mapx / 2) &&
3693 FABS (dy) <= (pl->contr->socket.mapy / 2) && 3627 FABS (dy) <= (pl->contr->socket->mapy / 2) &&
3694 !pl->contr->blocked_los[dx + (pl->contr->socket.mapx / 2)][dy + (pl->contr->socket.mapy / 2)]) 3628 !pl->contr->blocked_los[dx + (pl->contr->socket->mapx / 2)][dy + (pl->contr->socket->mapy / 2)])
3695 return 1; 3629 return 1;
3696 op = op->more; 3630 op = op->more;
3697 } 3631 }
3698 return 0; 3632 return 0;
3699} 3633}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines