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.18 by root, Sun Sep 10 15:59:57 2006 UTC vs.
Revision 1.37 by root, Thu Dec 14 02:37:37 2006 UTC

1
2/*
3 * static char *rcsid_player_c =
4 * "$Id: player.C,v 1.18 2006/09/10 15:59:57 root Exp $";
5 */
6
7/* 1/*
8 CrossFire, A Multiplayer game for X-windows 2 CrossFire, A Multiplayer game for X-windows
9 3
10 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 4 Copyright (C) 2002 Mark Wedel & Crossfire Development Team
11 Copyright (C) 1992 Frank Tore Johansen 5 Copyright (C) 1992 Frank Tore Johansen
22 16
23 You should have received a copy of the GNU General Public License 17 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software 18 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 20
27 The author can be reached via e-mail to crossfire-devel@real-time.com 21 The author can be reached via e-mail to <crossfire@schmorp.de>
28*/ 22*/
29 23
30#include <global.h> 24#include <global.h>
31#ifndef WIN32 /* ---win32 remove headers */
32# include <pwd.h> 25#include <pwd.h>
33#endif
34#ifndef __CEXTRACT__ 26#ifndef __CEXTRACT__
35# include <sproto.h> 27# include <sproto.h>
36#endif 28#endif
37#include <sounds.h> 29#include <sounds.h>
38#include <living.h> 30#include <living.h>
285 p->peaceful = 1; /* default peaceful */ 277 p->peaceful = 1; /* default peaceful */
286 p->do_los = 1; 278 p->do_los = 1;
287 p->explore = 0; 279 p->explore = 0;
288 p->no_shout = 0; /* default can shout */ 280 p->no_shout = 0; /* default can shout */
289 281
290 strncpy (p->title, op->arch->clone.name, sizeof (p->title) - 1); 282 assign (p->title, op->arch->clone.name);
291 p->title[sizeof (p->title) - 1] = '\0';
292 op->race = op->arch->clone.race; 283 op->race = op->arch->clone.race;
293 284
294 CLEAR_FLAG (op, FLAG_READY_SKILL); 285 CLEAR_FLAG (op, FLAG_READY_SKILL);
295 286
296 /* we need to clear these to -1 and not zero - otherwise, 287 /* we need to clear these to -1 and not zero - otherwise,
329 * All we can really get in this is some settings like host and display 320 * All we can really get in this is some settings like host and display
330 * mode. 321 * mode.
331 */ 322 */
332 323
333int 324int
334add_player (NewSocket * ns) 325add_player (client_socket * ns)
335{ 326{
336 player *p; 327 player *p;
337 328
338 p = get_player (NULL); 329 p = get_player (NULL);
339 p->socket = *ns; 330 p->socket = *ns;
340 p->socket.faces_sent = (uint8 *) malloc (p->socket.faces_sent_len * sizeof (*p->socket.faces_sent)); 331 p->socket.faces_sent = (uint8 *) malloc (p->socket.faces_sent_len * sizeof (*p->socket.faces_sent));
332
341 if (p->socket.faces_sent == NULL) 333 if (p->socket.faces_sent == NULL)
342 fatal (OUT_OF_MEMORY); 334 fatal (OUT_OF_MEMORY);
335
343 memcpy (p->socket.faces_sent, ns->faces_sent, p->socket.faces_sent_len * sizeof (*p->socket.faces_sent)); 336 memcpy (p->socket.faces_sent, ns->faces_sent, p->socket.faces_sent_len * sizeof (*p->socket.faces_sent));
344 /* Needed because the socket we just copied over needs to be cleared. 337 /* Needed because the socket we just copied over needs to be cleared.
345 * Note that this can result in a client reset if there is partial data 338 * Note that this can result in a client reset if there is partial data
346 * on the uncoming socket. 339 * on the uncoming socket.
347 */ 340 */
341 //TODO socket copying is EVIL, do not do this
348 p->socket.inbuf.len = 0; 342 p->socket.inbuf_len = 0;
349 set_first_map (p->ob); 343 set_first_map (p->ob);
350 344
351 CLEAR_FLAG (p->ob, FLAG_FRIENDLY); 345 CLEAR_FLAG (p->ob, FLAG_FRIENDLY);
352 add_friendly_object (p->ob); 346 add_friendly_object (p->ob);
353 send_rules (p->ob); 347 send_rules (p->ob);
354 send_news (p->ob); 348 send_news (p->ob);
355 display_motd (p->ob); 349 display_motd (p->ob);
356 get_name (p->ob); 350 get_name (p->ob);
351
357 return 0; 352 return 0;
358} 353}
359 354
360/* 355/*
361 * get_player_archetype() return next player archetype from archetype 356 * get_player_archetype() return next player archetype from archetype
496path_to_player (object *mon, object *pl, unsigned mindiff) 491path_to_player (object *mon, object *pl, unsigned mindiff)
497{ 492{
498 rv_vector rv; 493 rv_vector rv;
499 sint16 x, y; 494 sint16 x, y;
500 int lastx, lasty, dir, i, diff, firstdir = 0, lastdir, max = MAX_SPACES, mflags, blocked; 495 int lastx, lasty, dir, i, diff, firstdir = 0, lastdir, max = MAX_SPACES, mflags, blocked;
501 mapstruct *m, *lastmap; 496 maptile *m, *lastmap;
502 497
503 get_rangevector (mon, pl, &rv, 0); 498 get_rangevector (mon, pl, &rv, 0);
504 499
505 if (rv.distance < mindiff) 500 if (rv.distance < mindiff)
506 return 0; 501 return 0;
650 (op->type == ARMOUR || op->type == BOOTS || 645 (op->type == ARMOUR || op->type == BOOTS ||
651 op->type == CLOAK || op->type == HELMET || 646 op->type == CLOAK || op->type == HELMET ||
652 op->type == SHIELD || op->type == GLOVES || 647 op->type == SHIELD || op->type == GLOVES ||
653 op->type == BRACERS || op->type == GIRDLE)) || (!QUERY_FLAG (pl, FLAG_USE_WEAPON) && op->type == WEAPON)) 648 op->type == BRACERS || op->type == GIRDLE)) || (!QUERY_FLAG (pl, FLAG_USE_WEAPON) && op->type == WEAPON))
654 { 649 {
655 remove_ob (op); 650 op->destroy ();
656 free_object (op);
657 continue; 651 continue;
658 } 652 }
659 } 653 }
660 654
661 /* This really needs to be better - we should really give 655 /* This really needs to be better - we should really give
672 if (tmp->type == op->type && tmp->name == op->name) 666 if (tmp->type == op->type && tmp->name == op->name)
673 break; 667 break;
674 668
675 if (tmp) 669 if (tmp)
676 { 670 {
677 remove_ob (op); 671 op->destroy ();
678 free_object (op);
679 LOG (llevError, "give_initial_items: Removing duplicate object %s\n", &tmp->name); 672 LOG (llevError, "give_initial_items: Removing duplicate object %s\n", &tmp->name);
680 continue; 673 continue;
681 } 674 }
675
682 if (op->nrof > 1) 676 if (op->nrof > 1)
683 op->nrof = 1; 677 op->nrof = 1;
684 } 678 }
685 679
686 if (op->type == SPELLBOOK && op->inv) 680 if (op->type == SPELLBOOK && op->inv)
698 CLEAR_FLAG (op, FLAG_CURSED); 692 CLEAR_FLAG (op, FLAG_CURSED);
699 CLEAR_FLAG (op, FLAG_DAMNED); 693 CLEAR_FLAG (op, FLAG_DAMNED);
700 } 694 }
701 if (op->type == SPELL) 695 if (op->type == SPELL)
702 { 696 {
703 remove_ob (op); 697 op->destroy ();
704 free_object (op);
705 continue; 698 continue;
706 } 699 }
707 else if (op->type == SKILL) 700 else if (op->type == SKILL)
708 { 701 {
709 SET_FLAG (op, FLAG_CAN_USE_SKILL); 702 SET_FLAG (op, FLAG_CAN_USE_SKILL);
748 * removing the player - it probably makes more sense 741 * removing the player - it probably makes more sense
749 * to leave it to play_again to remove the object in all 742 * to leave it to play_again to remove the object in all
750 * cases. 743 * cases.
751 */ 744 */
752 if (!QUERY_FLAG (op, FLAG_REMOVED)) 745 if (!QUERY_FLAG (op, FLAG_REMOVED))
753 remove_ob (op); 746 op->remove ();
754 /* Need to set this to null - otherwise, it could point to garbage, 747 /* Need to set this to null - otherwise, it could point to garbage,
755 * and draw() doesn't check to see if the player is removed, only if 748 * and draw() doesn't check to see if the player is removed, only if
756 * the map is null or not swapped out. 749 * the map is null or not swapped out.
757 */ 750 */
758 op->map = NULL; 751 op->map = NULL;
759} 752}
760 753
761
762int 754int
763receive_play_again (object *op, char key) 755receive_play_again (object *op, char key)
764{ 756{
765 if (key == 'q' || key == 'Q') 757 if (key == 'q' || key == 'Q')
766 { 758 {
771 else if (key == 'a' || key == 'A') 763 else if (key == 'a' || key == 'A')
772 { 764 {
773 player *pl = op->contr; 765 player *pl = op->contr;
774 shstr name = op->name; 766 shstr name = op->name;
775 767
776 remove_friendly_object (op); 768 op->contr = 0;
777 free_object (op); 769 op->type = 0;
770 op->destroy (1);
778 pl = get_player (pl); 771 pl = get_player (pl);
779 op = pl->ob; 772 op = pl->ob;
780 add_friendly_object (op); 773 add_friendly_object (op);
781 op->contr->password[0] = '~'; 774 op->contr->password[0] = '~';
782 op->name = op->name_pl = 0; 775 op->name = op->name_pl = 0;
785 get_name (op); 778 get_name (op);
786 op->name = op->name_pl = name; 779 op->name = op->name_pl = name;
787 set_first_map (op); 780 set_first_map (op);
788 } 781 }
789 else 782 else
790 {
791 /* user pressed something else so just ask again... */ 783 /* user pressed something else so just ask again... */
792 play_again (op); 784 play_again (op);
793 } 785
794 return 0; 786 return 0;
795} 787}
796 788
797void 789void
798confirm_password (object *op) 790confirm_password (object *op)
1001 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, ""); 993 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "");
1002 return 1; 994 return 1;
1003 } 995 }
1004 switch (key) 996 switch (key)
1005 { 997 {
1006 case 'n': 998 case 'n':
1007 case 'N': 999 case 'N':
1008 { 1000 {
1009 SET_FLAG (op, FLAG_WIZ); 1001 SET_FLAG (op, FLAG_WIZ);
1010 if (op->map == NULL) 1002 if (op->map == NULL)
1011 { 1003 {
1012 LOG (llevError, "Map == NULL in state 2\n"); 1004 LOG (llevError, "Map == NULL in state 2\n");
1013 break; 1005 break;
1014 } 1006 }
1015 1007
1016#if 0 1008#if 0
1017 /* So that enter_exit will put us at startx/starty */ 1009 /* So that enter_exit will put us at startx/starty */
1018 op->x = -1; 1010 op->x = -1;
1019 1011
1020 enter_exit (op, NULL); 1012 enter_exit (op, NULL);
1021#endif 1013#endif
1022 SET_ANIMATION (op, 2); /* So player faces south */ 1014 SET_ANIMATION (op, 2); /* So player faces south */
1023 /* Enter exit adds a player otherwise */ 1015 /* Enter exit adds a player otherwise */
1024 add_statbonus (op); 1016 add_statbonus (op);
1025 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, 1017 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR,
1026 "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n"); 1018 "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n");
1027 op->contr->state = ST_CHANGE_CLASS; 1019 op->contr->state = ST_CHANGE_CLASS;
1028 if (op->msg) 1020 if (op->msg)
1029 new_draw_info (NDI_BLUE, 0, op, op->msg); 1021 new_draw_info (NDI_BLUE, 0, op, op->msg);
1030 return 0;
1031 }
1032 case 'y':
1033 case 'Y':
1034 roll_stats (op);
1035 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "");
1036 return 1;
1037
1038 case 'q':
1039 case 'Q':
1040 play_again (op);
1041 return 1;
1042
1043 default:
1044 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "Yes, No, Quit or 1-6. Roll again?");
1045 return 0; 1022 return 0;
1023 }
1024 case 'y':
1025 case 'Y':
1026 roll_stats (op);
1027 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "");
1028 return 1;
1029
1030 case 'q':
1031 case 'Q':
1032 play_again (op);
1033 return 1;
1034
1035 default:
1036 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "Yes, No, Quit or 1-6. Roll again?");
1037 return 0;
1046 } 1038 }
1047 return 0; 1039 return 0;
1048} 1040}
1049 1041
1050/* This function takes the key that is passed, and does the 1042/* This function takes the key that is passed, and does the
1059{ 1051{
1060 int tmp_loop; 1052 int tmp_loop;
1061 1053
1062 if (key == 'q' || key == 'Q') 1054 if (key == 'q' || key == 'Q')
1063 { 1055 {
1064 remove_ob (op); 1056 op->remove ();
1065 play_again (op); 1057 play_again (op);
1066 return 0; 1058 return 0;
1067 } 1059 }
1068 if (key == 'd' || key == 'D') 1060 if (key == 'd' || key == 'D')
1069 { 1061 {
1070 char buf[MAX_BUF]; 1062 char buf[MAX_BUF];
1071 1063
1072 /* this must before then initial items are given */ 1064 /* this must before then initial items are given */
1073 esrv_new_player (op->contr, op->weight + op->carrying); 1065 esrv_new_player (op->contr, op->weight + op->carrying);
1066
1074 create_treasure (find_treasurelist ("starting_wealth"), op, 0, 0, 0); 1067 treasurelist *tl = find_treasurelist ("starting_wealth");
1068 if (tl)
1069 create_treasure (tl, op, 0, 0, 0);
1075 1070
1076 INVOKE_PLAYER (BIRTH, op->contr); 1071 INVOKE_PLAYER (BIRTH, op->contr);
1077 INVOKE_PLAYER (LOGIN, op->contr); 1072 INVOKE_PLAYER (LOGIN, op->contr);
1078 1073
1079 op->contr->state = ST_PLAYING; 1074 op->contr->state = ST_PLAYING;
1104 { 1099 {
1105 object *tmp; 1100 object *tmp;
1106 char mapname[MAX_BUF]; 1101 char mapname[MAX_BUF];
1107 1102
1108 snprintf (mapname, MAX_BUF - 1, "%s/%s", first_map_ext_path, &op->arch->name); 1103 snprintf (mapname, MAX_BUF - 1, "%s/%s", first_map_ext_path, &op->arch->name);
1109 tmp = get_object (); 1104 tmp = object::create ();
1110 EXIT_PATH (tmp) = mapname; 1105 EXIT_PATH (tmp) = mapname;
1111 EXIT_X (tmp) = op->x; 1106 EXIT_X (tmp) = op->x;
1112 EXIT_Y (tmp) = op->y; 1107 EXIT_Y (tmp) = op->y;
1113 enter_exit (op, tmp); /* we don't really care if it succeeded; 1108 enter_exit (op, tmp); /* we don't really care if it succeeded;
1114 * if the map isn't there, then stay on the 1109 * if the map isn't there, then stay on the
1115 * default initial map */ 1110 * default initial map */
1116 free_object (tmp); 1111 tmp->destroy ();
1117 } 1112 }
1118 else 1113 else
1119 { 1114 {
1120 LOG (llevDebug, "first_map_ext_path not set\n"); 1115 LOG (llevDebug, "first_map_ext_path not set\n");
1121 } 1116 }
1131 { 1126 {
1132 shstr name = op->name; 1127 shstr name = op->name;
1133 int x = op->x, y = op->y; 1128 int x = op->x, y = op->y;
1134 1129
1135 remove_statbonus (op); 1130 remove_statbonus (op);
1136 remove_ob (op); 1131 op->remove ();
1137 op->arch = get_player_archetype (op->arch); 1132 op->arch = get_player_archetype (op->arch);
1138 copy_object (&op->arch->clone, op); 1133 op->arch->clone.copy_to (op);
1139 op->instantiate (); 1134 op->instantiate ();
1140 op->stats = op->contr->orig_stats; 1135 op->stats = op->contr->orig_stats;
1141 op->name = op->name_pl = name; 1136 op->name = op->name_pl = name;
1142 op->x = x; 1137 op->x = x;
1143 op->y = y; 1138 op->y = y;
1144 SET_ANIMATION (op, 2); /* So player faces south */ 1139 SET_ANIMATION (op, 2); /* So player faces south */
1145 insert_ob_in_map (op, op->map, op, 0); 1140 insert_ob_in_map (op, op->map, op, 0);
1146 strncpy (op->contr->title, op->arch->clone.name, sizeof (op->contr->title) - 1); 1141 assign (op->contr->title, op->arch->clone.name);
1147 op->contr->title[sizeof (op->contr->title) - 1] = '\0';
1148 add_statbonus (op); 1142 add_statbonus (op);
1149 tmp_loop = allowed_class (op); 1143 tmp_loop = allowed_class (op);
1150 } 1144 }
1145
1151 update_object (op, UP_OBJ_FACE); 1146 update_object (op, UP_OBJ_FACE);
1152 esrv_update_item (UPD_FACE, op, op); 1147 esrv_update_item (UPD_FACE, op, op);
1153 fix_player (op); 1148 fix_player (op);
1154 op->stats.hp = op->stats.maxhp; 1149 op->stats.hp = op->stats.maxhp;
1155 op->stats.sp = op->stats.maxsp; 1150 op->stats.sp = op->stats.maxsp;
1156 op->stats.grace = 0; 1151 op->stats.grace = 0;
1152
1157 if (op->msg) 1153 if (op->msg)
1158 new_draw_info (NDI_BLUE, 0, op, op->msg); 1154 new_draw_info (NDI_BLUE, 0, op, op->msg);
1155
1159 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "Press any key for the next race.\nPress `d' to play this race.\n"); 1156 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "Press any key for the next race.\nPress `d' to play this race.\n");
1160 return 0; 1157 return 0;
1161} 1158}
1162 1159
1163int 1160int
1186 if (settings.set_title == TRUE) 1183 if (settings.set_title == TRUE)
1187 op->contr->own_title[0] = '\0'; 1184 op->contr->own_title[0] = '\0';
1188 1185
1189 if (!QUERY_FLAG (op, FLAG_WAS_WIZ)) 1186 if (!QUERY_FLAG (op, FLAG_WAS_WIZ))
1190 { 1187 {
1191 mapstruct *mp, *next; 1188 maptile *mp, *next;
1192 1189
1193 /* We need to hunt for any per player unique maps in memory and 1190 /* We need to hunt for any per player unique maps in memory and
1194 * get rid of them. The trailing slash in the path is intentional, 1191 * get rid of them. The trailing slash in the path is intentional,
1195 * so that players named 'Ab' won't match against players 'Abe' pathname 1192 * so that players named 'Ab' won't match against players 'Abe' pathname
1196 */ 1193 */
1202 delete_map (mp); 1199 delete_map (mp);
1203 } 1200 }
1204 1201
1205 delete_character (op->name, 1); 1202 delete_character (op->name, 1);
1206 } 1203 }
1204
1207 play_again (op); 1205 play_again (op);
1208 return 1; 1206 return 1;
1209} 1207}
1210 1208
1211void 1209void
1269 */ 1267 */
1270int 1268int
1271check_pick (object *op) 1269check_pick (object *op)
1272{ 1270{
1273 object *tmp, *next; 1271 object *tmp, *next;
1274 tag_t next_tag = 0, op_tag;
1275 int stop = 0; 1272 int stop = 0;
1276 int j, k, wvratio; 1273 int j, k, wvratio;
1277 char putstring[128], tmpstr[16]; 1274 char putstring[128], tmpstr[16];
1278 1275
1279
1280 /* if you're flying, you cna't pick up anything */ 1276 /* if you're flying, you cna't pick up anything */
1281 if (op->move_type & MOVE_FLYING) 1277 if (op->move_type & MOVE_FLYING)
1282 return 1; 1278 return 1;
1283 1279
1284 op_tag = op->count;
1285
1286 next = op->below; 1280 next = op->below;
1287 if (next)
1288 next_tag = next->count;
1289 1281
1290 /* loop while there are items on the floor that are not marked as 1282 /* loop while there are items on the floor that are not marked as
1291 * destroyed */ 1283 * destroyed */
1292 while (next && !was_destroyed (next, next_tag)) 1284 while (next && !next->destroyed ())
1293 { 1285 {
1294 tmp = next; 1286 tmp = next;
1295 next = tmp->below; 1287 next = tmp->below;
1296 if (next)
1297 next_tag = next->count;
1298 1288
1299 if (was_destroyed (op, op_tag)) 1289 if (op->destroyed ())
1300 return 0; 1290 return 0;
1301 1291
1302 if (!can_pick (op, tmp)) 1292 if (!can_pick (op, tmp))
1303 continue; 1293 continue;
1304 1294
1312 /* high not bit set? We're using the old autopickup model */ 1302 /* high not bit set? We're using the old autopickup model */
1313 if (!(op->contr->mode & PU_NEWMODE)) 1303 if (!(op->contr->mode & PU_NEWMODE))
1314 { 1304 {
1315 switch (op->contr->mode) 1305 switch (op->contr->mode)
1316 { 1306 {
1317 case 0: 1307 case 0:
1318 return 1; /* don't pick up */ 1308 return 1; /* don't pick up */
1319 case 1: 1309 case 1:
1310 pick_up (op, tmp);
1311 return 1;
1312 case 2:
1313 pick_up (op, tmp);
1314 return 0;
1315 case 3:
1316 return 0; /* stop before pickup */
1317 case 4:
1318 pick_up (op, tmp);
1319 break;
1320 case 5:
1321 pick_up (op, tmp);
1322 stop = 1;
1323 break;
1324 case 6:
1325 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))
1320 pick_up (op, tmp); 1326 pick_up (op, tmp);
1321 return 1; 1327 break;
1328
1322 case 2: 1329 case 7:
1330 if (tmp->type == MONEY || tmp->type == GEM)
1323 pick_up (op, tmp); 1331 pick_up (op, tmp);
1324 return 0; 1332 break;
1325 case 3: 1333
1326 return 0; /* stop before pickup */ 1334 default:
1327 case 4: 1335 /* use value density */
1336 if (!QUERY_FLAG (tmp, FLAG_UNPAID)
1337 && (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))) >= op->contr->mode)
1328 pick_up (op, tmp); 1338 pick_up (op, tmp);
1329 break;
1330 case 5:
1331 pick_up (op, tmp);
1332 stop = 1;
1333 break;
1334 case 6:
1335 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))
1336 pick_up (op, tmp);
1337 break;
1338
1339 case 7:
1340 if (tmp->type == MONEY || tmp->type == GEM)
1341 pick_up (op, tmp);
1342 break;
1343
1344 default:
1345 /* use value density */
1346 if (!QUERY_FLAG (tmp, FLAG_UNPAID)
1347 && (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))) >= op->contr->mode)
1348 pick_up (op, tmp);
1349 } 1339 }
1350 } 1340 }
1351 else 1341 else
1352 { /* old model */ 1342 { /* old model */
1353 /* NEW pickup handling */ 1343 /* NEW pickup handling */
1436 /* question: don't pick up known-poisonous stuff? */ 1426 /* question: don't pick up known-poisonous stuff? */
1437 if (op->contr->mode & PU_FOOD) 1427 if (op->contr->mode & PU_FOOD)
1438 if (tmp->type == FOOD) 1428 if (tmp->type == FOOD)
1439 { 1429 {
1440 pick_up (op, tmp); 1430 pick_up (op, tmp);
1441 if (0)
1442 fprintf (stderr, "FOOD\n");
1443 continue; 1431 continue;
1444 } 1432 }
1433
1445 if (op->contr->mode & PU_DRINK) 1434 if (op->contr->mode & PU_DRINK)
1446 if (tmp->type == DRINK || (tmp->type == POISON && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))) 1435 if (tmp->type == DRINK || (tmp->type == POISON && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)))
1447 { 1436 {
1448 pick_up (op, tmp); 1437 pick_up (op, tmp);
1449 if (0)
1450 fprintf (stderr, "DRINK\n");
1451 continue; 1438 continue;
1452 } 1439 }
1453 1440
1454 if (op->contr->mode & PU_POTION) 1441 if (op->contr->mode & PU_POTION)
1455 if (tmp->type == POTION) 1442 if (tmp->type == POTION)
1456 { 1443 {
1457 pick_up (op, tmp); 1444 pick_up (op, tmp);
1458 if (0)
1459 fprintf (stderr, "POTION\n");
1460 continue; 1445 continue;
1461 } 1446 }
1462 1447
1463 /* spellbooks, skillscrolls and normal books/scrolls */ 1448 /* spellbooks, skillscrolls and normal books/scrolls */
1464 if (op->contr->mode & PU_SPELLBOOK) 1449 if (op->contr->mode & PU_SPELLBOOK)
1465 if (tmp->type == SPELLBOOK) 1450 if (tmp->type == SPELLBOOK)
1466 { 1451 {
1467 pick_up (op, tmp); 1452 pick_up (op, tmp);
1468 if (0)
1469 fprintf (stderr, "SPELLBOOK\n");
1470 continue; 1453 continue;
1471 } 1454 }
1455
1472 if (op->contr->mode & PU_SKILLSCROLL) 1456 if (op->contr->mode & PU_SKILLSCROLL)
1473 if (tmp->type == SKILLSCROLL) 1457 if (tmp->type == SKILLSCROLL)
1474 { 1458 {
1475 pick_up (op, tmp); 1459 pick_up (op, tmp);
1476 if (0)
1477 fprintf (stderr, "SKILLSCROLL\n");
1478 continue; 1460 continue;
1479 } 1461 }
1462
1480 if (op->contr->mode & PU_READABLES) 1463 if (op->contr->mode & PU_READABLES)
1481 if (tmp->type == BOOK || tmp->type == SCROLL) 1464 if (tmp->type == BOOK || tmp->type == SCROLL)
1482 { 1465 {
1483 pick_up (op, tmp); 1466 pick_up (op, tmp);
1484 if (0)
1485 fprintf (stderr, "READABLES\n");
1486 continue; 1467 continue;
1487 } 1468 }
1488 1469
1489 /* wands/staves/rods/horns */ 1470 /* wands/staves/rods/horns */
1490 if (op->contr->mode & PU_MAGIC_DEVICE) 1471 if (op->contr->mode & PU_MAGIC_DEVICE)
1491 if (tmp->type == WAND || tmp->type == ROD || tmp->type == HORN) 1472 if (tmp->type == WAND || tmp->type == ROD || tmp->type == HORN)
1492 { 1473 {
1493 pick_up (op, tmp); 1474 pick_up (op, tmp);
1494 if (0)
1495 fprintf (stderr, "MAGIC_DEVICE\n");
1496 continue; 1475 continue;
1497 } 1476 }
1498 1477
1499 /* pick up all magical items */ 1478 /* pick up all magical items */
1500 if (op->contr->mode & PU_MAGICAL) 1479 if (op->contr->mode & PU_MAGICAL)
1501 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)) 1480 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))
1502 { 1481 {
1503 pick_up (op, tmp); 1482 pick_up (op, tmp);
1504 if (0)
1505 fprintf (stderr, "MAGICAL\n");
1506 continue; 1483 continue;
1507 } 1484 }
1508 1485
1509 if (op->contr->mode & PU_VALUABLES) 1486 if (op->contr->mode & PU_VALUABLES)
1510 { 1487 {
1511 if (tmp->type == MONEY || tmp->type == GEM) 1488 if (tmp->type == MONEY || tmp->type == GEM)
1512 { 1489 {
1513 pick_up (op, tmp); 1490 pick_up (op, tmp);
1514 if (0)
1515 fprintf (stderr, "MONEY/GEM\n");
1516 continue; 1491 continue;
1517 } 1492 }
1518 } 1493 }
1519 1494
1520 /* rings & amulets - talismans seems to be typed AMULET */ 1495 /* rings & amulets - talismans seems to be typed AMULET */
1521 if (op->contr->mode & PU_JEWELS) 1496 if (op->contr->mode & PU_JEWELS)
1522 if (tmp->type == RING || tmp->type == AMULET) 1497 if (tmp->type == RING || tmp->type == AMULET)
1523 { 1498 {
1524 pick_up (op, tmp); 1499 pick_up (op, tmp);
1500 continue;
1525 if (0) 1501 }
1526 fprintf (stderr, "JEWELS\n"); 1502
1503 /* we don't forget dragon food */
1504 if (op->contr->mode & PU_FLESH)
1505 if (tmp->type == FLESH)
1506 {
1507 pick_up (op, tmp);
1527 continue; 1508 continue;
1528 } 1509 }
1529 1510
1530 /* bows and arrows. Bows are good for selling! */ 1511 /* bows and arrows. Bows are good for selling! */
1531 if (op->contr->mode & PU_BOW) 1512 if (op->contr->mode & PU_BOW)
1532 if (tmp->type == BOW) 1513 if (tmp->type == BOW)
1533 { 1514 {
1534 pick_up (op, tmp); 1515 pick_up (op, tmp);
1535 if (0)
1536 fprintf (stderr, "BOW\n");
1537 continue; 1516 continue;
1538 } 1517 }
1518
1539 if (op->contr->mode & PU_ARROW) 1519 if (op->contr->mode & PU_ARROW)
1540 if (tmp->type == ARROW) 1520 if (tmp->type == ARROW)
1541 { 1521 {
1542 pick_up (op, tmp); 1522 pick_up (op, tmp);
1543 if (0)
1544 fprintf (stderr, "ARROW\n");
1545 continue; 1523 continue;
1546 } 1524 }
1547 1525
1548 /* all kinds of armor etc. */ 1526 /* all kinds of armor etc. */
1549 if (op->contr->mode & PU_ARMOUR) 1527 if (op->contr->mode & PU_ARMOUR)
1550 if (tmp->type == ARMOUR) 1528 if (tmp->type == ARMOUR)
1551 { 1529 {
1552 pick_up (op, tmp); 1530 pick_up (op, tmp);
1553 if (0)
1554 fprintf (stderr, "ARMOUR\n");
1555 continue; 1531 continue;
1556 } 1532 }
1533
1557 if (op->contr->mode & PU_HELMET) 1534 if (op->contr->mode & PU_HELMET)
1558 if (tmp->type == HELMET) 1535 if (tmp->type == HELMET)
1559 { 1536 {
1560 pick_up (op, tmp); 1537 pick_up (op, tmp);
1561 if (0)
1562 fprintf (stderr, "HELMET\n");
1563 continue; 1538 continue;
1564 } 1539 }
1540
1565 if (op->contr->mode & PU_SHIELD) 1541 if (op->contr->mode & PU_SHIELD)
1566 if (tmp->type == SHIELD) 1542 if (tmp->type == SHIELD)
1567 { 1543 {
1568 pick_up (op, tmp); 1544 pick_up (op, tmp);
1569 if (0)
1570 fprintf (stderr, "SHIELD\n");
1571 continue; 1545 continue;
1572 } 1546 }
1547
1573 if (op->contr->mode & PU_BOOTS) 1548 if (op->contr->mode & PU_BOOTS)
1574 if (tmp->type == BOOTS) 1549 if (tmp->type == BOOTS)
1575 { 1550 {
1576 pick_up (op, tmp); 1551 pick_up (op, tmp);
1577 if (0)
1578 fprintf (stderr, "BOOTS\n");
1579 continue; 1552 continue;
1580 } 1553 }
1554
1581 if (op->contr->mode & PU_GLOVES) 1555 if (op->contr->mode & PU_GLOVES)
1582 if (tmp->type == GLOVES) 1556 if (tmp->type == GLOVES)
1583 { 1557 {
1584 pick_up (op, tmp); 1558 pick_up (op, tmp);
1585 if (0)
1586 fprintf (stderr, "GLOVES\n");
1587 continue; 1559 continue;
1588 } 1560 }
1561
1589 if (op->contr->mode & PU_CLOAK) 1562 if (op->contr->mode & PU_CLOAK)
1590 if (tmp->type == CLOAK) 1563 if (tmp->type == CLOAK)
1591 { 1564 {
1592 pick_up (op, tmp); 1565 pick_up (op, tmp);
1593 if (0)
1594 fprintf (stderr, "GLOVES\n");
1595 continue; 1566 continue;
1596 } 1567 }
1597 1568
1598 /* hoping to catch throwing daggers here */ 1569 /* hoping to catch throwing daggers here */
1599 if (op->contr->mode & PU_MISSILEWEAPON) 1570 if (op->contr->mode & PU_MISSILEWEAPON)
1600 if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_IS_THROWN)) 1571 if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_IS_THROWN))
1601 { 1572 {
1602 pick_up (op, tmp); 1573 pick_up (op, tmp);
1603 if (0)
1604 fprintf (stderr, "MISSILEWEAPON\n");
1605 continue; 1574 continue;
1606 } 1575 }
1607 1576
1608 /* careful: chairs and tables are weapons! */ 1577 /* careful: chairs and tables are weapons! */
1609 if (op->contr->mode & PU_ALLWEAPON) 1578 if (op->contr->mode & PU_ALLWEAPON)
1612 { 1581 {
1613 if (strstr (tmp->name, "table") == NULL && strstr (tmp->arch->name, "table") == NULL && 1582 if (strstr (tmp->name, "table") == NULL && strstr (tmp->arch->name, "table") == NULL &&
1614 strstr (tmp->name, "chair") && strstr (tmp->arch->name, "chair") == NULL) 1583 strstr (tmp->name, "chair") && strstr (tmp->arch->name, "chair") == NULL)
1615 { 1584 {
1616 pick_up (op, tmp); 1585 pick_up (op, tmp);
1617 if (0)
1618 fprintf (stderr, "WEAPON\n");
1619 continue; 1586 continue;
1620 } 1587 }
1621 } 1588 }
1589
1622 if (tmp->type == WEAPON && tmp->name == NULL) 1590 if (tmp->type == WEAPON && tmp->name == NULL)
1623 { 1591 {
1624 if (strstr (tmp->arch->name, "table") == NULL && strstr (tmp->arch->name, "chair") == NULL) 1592 if (strstr (tmp->arch->name, "table") == NULL && strstr (tmp->arch->name, "chair") == NULL)
1625 { 1593 {
1626 pick_up (op, tmp); 1594 pick_up (op, tmp);
1627 if (0)
1628 fprintf (stderr, "WEAPON\n");
1629 continue; 1595 continue;
1630 } 1596 }
1631 } 1597 }
1632 } 1598 }
1633 1599
1634 /* misc stuff that's useful */ 1600 /* misc stuff that's useful */
1635 if (op->contr->mode & PU_KEY) 1601 if (op->contr->mode & PU_KEY)
1636 if (tmp->type == KEY || tmp->type == SPECIAL_KEY) 1602 if (tmp->type == KEY || tmp->type == SPECIAL_KEY)
1637 { 1603 {
1638 pick_up (op, tmp); 1604 pick_up (op, tmp);
1639 if (0)
1640 fprintf (stderr, "KEY\n");
1641 continue; 1605 continue;
1642 } 1606 }
1643 1607
1644 /* any of the last 4 bits set means we use the ratio for value 1608 /* any of the last 4 bits set means we use the ratio for value
1645 * pickups */ 1609 * pickups */
1667 continue; 1631 continue;
1668 } 1632 }
1669 } 1633 }
1670 } /* the new pickup model */ 1634 } /* the new pickup model */
1671 } 1635 }
1636
1672 return !stop; 1637 return !stop;
1673} 1638}
1674 1639
1675/* 1640/*
1676 * Find an arrow in the inventory and after that 1641 * Find an arrow in the inventory and after that
1775 1740
1776object * 1741object *
1777pick_arrow_target (object *op, const char *type, int dir) 1742pick_arrow_target (object *op, const char *type, int dir)
1778{ 1743{
1779 object *tmp = NULL; 1744 object *tmp = NULL;
1780 mapstruct *m; 1745 maptile *m;
1781 int i, mflags, found, number; 1746 int i, mflags, found, number;
1782 sint16 x, y; 1747 sint16 x, y;
1783 1748
1784 if (op->map == NULL) 1749 if (op->map == NULL)
1785 return find_arrow (op, type); 1750 return find_arrow (op, type);
1845 */ 1810 */
1846int 1811int
1847fire_bow (object *op, object *part, object *arrow, int dir, int wc_mod, sint16 sx, sint16 sy) 1812fire_bow (object *op, object *part, object *arrow, int dir, int wc_mod, sint16 sx, sint16 sy)
1848{ 1813{
1849 object *left, *bow; 1814 object *left, *bow;
1850 tag_t left_tag, tag;
1851 int bowspeed, mflags; 1815 int bowspeed, mflags;
1852 mapstruct *m; 1816 maptile *m;
1853 1817
1854 if (!dir) 1818 if (!dir)
1855 { 1819 {
1856 new_draw_info (NDI_UNIQUE, 0, op, "You can't shoot yourself!"); 1820 new_draw_info (NDI_UNIQUE, 0, op, "You can't shoot yourself!");
1857 return 0; 1821 return 0;
1911 } 1875 }
1912 1876
1913 /* this should not happen, but sometimes does */ 1877 /* this should not happen, but sometimes does */
1914 if (arrow->nrof == 0) 1878 if (arrow->nrof == 0)
1915 { 1879 {
1916 remove_ob (arrow); 1880 arrow->destroy ();
1917 free_object (arrow);
1918 return 0; 1881 return 0;
1919 } 1882 }
1920 1883
1921 left = arrow; /* these are arrows left to the player */ 1884 left = arrow; /* these are arrows left to the player */
1922 left_tag = left->count;
1923 arrow = get_split_ob (arrow, 1); 1885 arrow = get_split_ob (arrow, 1);
1924 if (arrow == NULL) 1886 if (arrow == NULL)
1925 { 1887 {
1926 new_draw_info_format (NDI_UNIQUE, 0, op, "You have no %s left.", &bow->race); 1888 new_draw_info_format (NDI_UNIQUE, 0, op, "You have no %s left.", &bow->race);
1927 return 0; 1889 return 0;
1928 } 1890 }
1929 set_owner (arrow, op); 1891 arrow->set_owner (op);
1930 arrow->skill = bow->skill; 1892 arrow->skill = bow->skill;
1931 1893
1932 arrow->direction = dir; 1894 arrow->direction = dir;
1933 arrow->x = sx; 1895 arrow->x = sx;
1934 arrow->y = sy; 1896 arrow->y = sy;
1970 arrow->level = op->chosen_skill ? op->chosen_skill->level : op->level; 1932 arrow->level = op->chosen_skill ? op->chosen_skill->level : op->level;
1971 } 1933 }
1972 else 1934 else
1973 { 1935 {
1974 arrow->stats.wc = op->stats.wc - bow->magic - arrow->magic - arrow->stats.wc + wc_mod; 1936 arrow->stats.wc = op->stats.wc - bow->magic - arrow->magic - arrow->stats.wc + wc_mod;
1975
1976 arrow->level = op->level; 1937 arrow->level = op->level;
1977 } 1938 }
1939
1978 if (arrow->attacktype == AT_PHYSICAL) 1940 if (arrow->attacktype == AT_PHYSICAL)
1979 arrow->attacktype |= bow->attacktype; 1941 arrow->attacktype |= bow->attacktype;
1942
1980 if (bow->slaying != NULL) 1943 if (bow->slaying != NULL)
1981 arrow->slaying = bow->slaying; 1944 arrow->slaying = bow->slaying;
1982 1945
1983 arrow->map = m; 1946 arrow->map = m;
1984 arrow->move_type = MOVE_FLY_LOW; 1947 arrow->move_type = MOVE_FLY_LOW;
1985 arrow->move_on = MOVE_FLY_LOW | MOVE_WALK; 1948 arrow->move_on = MOVE_FLY_LOW | MOVE_WALK;
1986 1949
1987 play_sound_map (op->map, op->x, op->y, SOUND_FIRE_ARROW); 1950 play_sound_map (op->map, op->x, op->y, SOUND_FIRE_ARROW);
1988 tag = arrow->count;
1989 insert_ob_in_map (arrow, m, op, 0); 1951 insert_ob_in_map (arrow, m, op, 0);
1990 1952
1991 if (!was_destroyed (arrow, tag)) 1953 if (!arrow->destroyed ())
1992 move_arrow (arrow); 1954 move_arrow (arrow);
1993 1955
1994 if (op->type == PLAYER) 1956 if (op->type == PLAYER)
1995 { 1957 {
1996 if (was_destroyed (left, left_tag)) 1958 if (left->destroyed ())
1997 esrv_del_item (op->contr, left_tag); 1959 esrv_del_item (op->contr, left->count);
1998 else 1960 else
1999 esrv_send_item (op, left); 1961 esrv_send_item (op, left);
2000 } 1962 }
1963
2001 return 1; 1964 return 1;
2002} 1965}
2003 1966
2004/* Special fire code for players - this takes into 1967/* Special fire code for players - this takes into
2005 * account the special fire modes players can have 1968 * account the special fire modes players can have
2125 if (action_makes_visible (op)) 2088 if (action_makes_visible (op))
2126 make_visible (op); 2089 make_visible (op);
2127 2090
2128 switch (op->contr->shoottype) 2091 switch (op->contr->shoottype)
2129 { 2092 {
2130 case range_none: 2093 case range_none:
2131 return; 2094 return;
2132 2095
2133 case range_bow: 2096 case range_bow:
2134 player_fire_bow (op, dir); 2097 player_fire_bow (op, dir);
2135 return; 2098 return;
2136 2099
2137 case range_magic: /* Casting spells */ 2100 case range_magic: /* Casting spells */
2138 spellcost = (cast_spell (op, op, dir, op->contr->ranges[range_magic], op->contr->spellparam[0] ? op->contr->spellparam : NULL)); 2101 spellcost = (cast_spell (op, op, dir, op->contr->ranges[range_magic], op->contr->spellparam[0] ? op->contr->spellparam : 0));
2139 return; 2102 return;
2140 2103
2141 case range_misc: 2104 case range_misc:
2142 fire_misc_object (op, dir); 2105 fire_misc_object (op, dir);
2143 return; 2106 return;
2144 2107
2145 case range_golem: /* Control summoned monsters from scrolls */ 2108 case range_golem: /* Control summoned monsters from scrolls */
2146 if (op->contr->ranges[range_golem] == NULL || op->contr->golem_count != op->contr->ranges[range_golem]->count) 2109 if (QUERY_FLAG (op->contr->ranges[range_golem], FLAG_REMOVED))
2147 { 2110 {
2148 op->contr->ranges[range_golem] = NULL; 2111 op->contr->ranges[range_golem] = 0;
2149 op->contr->shoottype = range_none; 2112 op->contr->shoottype = range_none;
2150 op->contr->golem_count = 0;
2151 } 2113 }
2152 else 2114 else
2153 control_golem (op->contr->ranges[range_golem], dir); 2115 control_golem (op->contr->ranges[range_golem], dir);
2154 return; 2116 return;
2155 2117
2156 case range_skill: 2118 case range_skill:
2157 if (!op->chosen_skill) 2119 if (!op->chosen_skill)
2158 { 2120 {
2159 if (op->type == PLAYER) 2121 if (op->type == PLAYER)
2160 new_draw_info (NDI_UNIQUE, 0, op, "You have no applicable skill to use."); 2122 new_draw_info (NDI_UNIQUE, 0, op, "You have no applicable skill to use.");
2161 return; 2123 return;
2162 } 2124 }
2163 (void) do_skill (op, op, op->chosen_skill, dir, NULL); 2125 (void) do_skill (op, op, op->chosen_skill, dir, NULL);
2164 return; 2126 return;
2165 case range_builder: 2127 case range_builder:
2166 apply_map_builder (op, dir); 2128 apply_map_builder (op, dir);
2167 return; 2129 return;
2168 default: 2130 default:
2169 new_draw_info (NDI_UNIQUE, 0, op, "Illegal shoot type."); 2131 new_draw_info (NDI_UNIQUE, 0, op, "Illegal shoot type.");
2170 return; 2132 return;
2171 } 2133 }
2172} 2134}
2173 2135
2174 2136
2175 2137
2317move_player_attack (object *op, int dir) 2279move_player_attack (object *op, int dir)
2318{ 2280{
2319 object *tmp, *mon; 2281 object *tmp, *mon;
2320 sint16 nx, ny; 2282 sint16 nx, ny;
2321 int on_battleground; 2283 int on_battleground;
2322 mapstruct *m; 2284 maptile *m;
2323 2285
2324 nx = freearr_x[dir] + op->x; 2286 nx = freearr_x[dir] + op->x;
2325 ny = freearr_y[dir] + op->y; 2287 ny = freearr_y[dir] + op->y;
2326 2288
2327 on_battleground = op_on_battleground (op, NULL, NULL); 2289 on_battleground = op_on_battleground (op, NULL, NULL);
2363 if (tmp == op) 2325 if (tmp == op)
2364 { 2326 {
2365 tmp = tmp->above; 2327 tmp = tmp->above;
2366 continue; 2328 continue;
2367 } 2329 }
2330
2368 if (QUERY_FLAG (tmp, FLAG_ALIVE)) 2331 if (QUERY_FLAG (tmp, FLAG_ALIVE))
2369 { 2332 {
2370 mon = tmp; 2333 mon = tmp;
2371 break; 2334 break;
2372 } 2335 }
2336
2373 if (tmp->type == LOCKED_DOOR || QUERY_FLAG (tmp, FLAG_CAN_ROLL)) 2337 if (tmp->type == LOCKED_DOOR || QUERY_FLAG (tmp, FLAG_CAN_ROLL))
2374 mon = tmp; 2338 mon = tmp;
2339
2375 tmp = tmp->above; 2340 tmp = tmp->above;
2376 } 2341 }
2377 2342
2378 if (mon == NULL) /* This happens anytime the player tries to move */ 2343 if (mon == NULL) /* This happens anytime the player tries to move */
2379 return; /* into a wall */ 2344 return; /* into a wall */
2398 * player owns it and it is either friendly or unagressive. 2363 * player owns it and it is either friendly or unagressive.
2399 */ 2364 */
2400 if ((op->type == PLAYER) 2365 if ((op->type == PLAYER)
2401#if COZY_SERVER 2366#if COZY_SERVER
2402 && 2367 &&
2403 ((get_owner (mon) && get_owner (mon)->contr 2368 ((mon->owner && mon->owner->contr
2404 && same_party (get_owner (mon)->contr->party, op->contr->party)) || get_owner (mon) == op) 2369 && same_party (mon->owner->contr->party, op->contr->party)) || mon->owner == op)
2405#else 2370#else
2406 && get_owner (mon) == op 2371 && mon->owner == op
2407#endif 2372#endif
2408 && (QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY))) 2373 && (QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY)))
2409 { 2374 {
2410 /* If we're braced, we don't want to switch places with it */ 2375 /* If we're braced, we don't want to switch places with it */
2411 if (op->contr->braced) 2376 if (op->contr->braced)
2598 /* I've been seeing crashes where the golem has been destroyed, but 2563 /* I've been seeing crashes where the golem has been destroyed, but
2599 * the player object still points to the defunct golem. The code that 2564 * the player object still points to the defunct golem. The code that
2600 * destroys the golem looks correct, and it doesn't always happen, so 2565 * destroys the golem looks correct, and it doesn't always happen, so
2601 * put this in a a workaround to clean up the golem pointer. 2566 * put this in a a workaround to clean up the golem pointer.
2602 */ 2567 */
2603 if (op->contr->ranges[range_golem] &&
2604 ((op->contr->golem_count != op->contr->ranges[range_golem]->count) || QUERY_FLAG (op->contr->ranges[range_golem], FLAG_REMOVED))) 2568 if (op->contr->ranges[range_golem] && QUERY_FLAG (op->contr->ranges[range_golem], FLAG_REMOVED))
2605 {
2606 op->contr->ranges[range_golem] = NULL; 2569 op->contr->ranges[range_golem] = 0;
2607 op->contr->golem_count = 0;
2608 }
2609 2570
2610 /* call this here - we also will call this in do_ericserver, but 2571 /* call this here - we also will call this in do_ericserver, but
2611 * the players time has been increased when doericserver has been 2572 * the players time has been increased when doericserver has been
2612 * called, so we recheck it here. 2573 * called, so we recheck it here.
2613 */ 2574 */
2644 for (tmp = op->inv; tmp != NULL; tmp = tmp->below) 2605 for (tmp = op->inv; tmp != NULL; tmp = tmp->below)
2645 if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE)) 2606 if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE))
2646 { 2607 {
2647 play_sound_map (op->map, op->x, op->y, SOUND_OB_EVAPORATE); 2608 play_sound_map (op->map, op->x, op->y, SOUND_OB_EVAPORATE);
2648 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s vibrates violently, then evaporates.", query_name (tmp)); 2609 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s vibrates violently, then evaporates.", query_name (tmp));
2610
2649 if (op->contr) 2611 if (op->contr)
2650 esrv_del_item (op->contr, tmp->count); 2612 esrv_del_item (op->contr, tmp->count);
2651 remove_ob (tmp); 2613
2652 free_object (tmp); 2614 tmp->destroy ();
2653 CLEAR_FLAG (op, FLAG_LIFESAVE); 2615 CLEAR_FLAG (op, FLAG_LIFESAVE);
2616
2654 if (op->stats.hp < 0) 2617 if (op->stats.hp < 0)
2655 op->stats.hp = op->stats.maxhp; 2618 op->stats.hp = op->stats.maxhp;
2619
2656 if (op->stats.food < 0) 2620 if (op->stats.food < 0)
2657 op->stats.food = 999; 2621 op->stats.food = 999;
2622
2658 fix_player (op); 2623 fix_player (op);
2659 return 1; 2624 return 1;
2660 } 2625 }
2661 LOG (llevError, "Error: LIFESAVE set without applied object.\n"); 2626 LOG (llevError, "Error: LIFESAVE set without applied object.\n");
2662 CLEAR_FLAG (op, FLAG_LIFESAVE); 2627 CLEAR_FLAG (op, FLAG_LIFESAVE);
2679 next = op->below; /* Make sure we have a good value, in case 2644 next = op->below; /* Make sure we have a good value, in case
2680 * we remove object 'op' 2645 * we remove object 'op'
2681 */ 2646 */
2682 if (QUERY_FLAG (op, FLAG_UNPAID)) 2647 if (QUERY_FLAG (op, FLAG_UNPAID))
2683 { 2648 {
2684 remove_ob (op); 2649 op->remove ();
2685 op->x = env->x; 2650 op->x = env->x;
2686 op->y = env->y; 2651 op->y = env->y;
2687 if (env->type == PLAYER) 2652 if (env->type == PLAYER)
2688 esrv_del_item (env->contr, op->count); 2653 esrv_del_item (env->contr, op->count);
2689 insert_ob_in_map (op, env->map, NULL, 0); 2654 insert_ob_in_map (op, env->map, NULL, 0);
2957{ 2922{
2958 char buf[MAX_BUF]; 2923 char buf[MAX_BUF];
2959 int x, y; 2924 int x, y;
2960 2925
2961 //int i; 2926 //int i;
2962 mapstruct *map; /* this is for resurrection */ 2927 maptile *map; /* this is for resurrection */
2963 2928
2964 /* int z; 2929 /* int z;
2965 int num_stats_lose; 2930 int num_stats_lose;
2966 int lost_a_stat; 2931 int lost_a_stat;
2967 int lose_this_stat; 2932 int lose_this_stat;
2982 { 2947 {
2983 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, "You have been defeated in combat!"); 2948 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, "You have been defeated in combat!");
2984 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, "Local medics have saved your life..."); 2949 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, "Local medics have saved your life...");
2985 2950
2986 /* restore player */ 2951 /* restore player */
2987 at = find_archetype ("poisoning"); 2952 at = archetype::find ("poisoning");
2988 tmp = present_arch_in_ob (at, op); 2953 tmp = present_arch_in_ob (at, op);
2989 if (tmp) 2954 if (tmp)
2990 { 2955 {
2991 remove_ob (tmp); 2956 tmp->destroy ();
2992 free_object (tmp);
2993 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed"); 2957 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed");
2994 } 2958 }
2995 2959
2996 at = find_archetype ("confusion"); 2960 at = archetype::find ("confusion");
2997 tmp = present_arch_in_ob (at, op); 2961 tmp = present_arch_in_ob (at, op);
2998 if (tmp) 2962 if (tmp)
2999 { 2963 {
3000 remove_ob (tmp); 2964 tmp->destroy ();
3001 free_object (tmp);
3002 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer"); 2965 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer");
3003 } 2966 }
3004 2967
3005 cure_disease (op, 0); /* remove any disease */ 2968 cure_disease (op, 0); /* remove any disease */
3006 op->stats.hp = op->stats.maxhp; 2969 op->stats.hp = op->stats.maxhp;
3007 if (op->stats.food <= 0) 2970 if (op->stats.food <= 0)
3008 op->stats.food = 999; 2971 op->stats.food = 999;
3009 2972
3010 /* create a bodypart-trophy to make the winner happy */ 2973 /* create a bodypart-trophy to make the winner happy */
3011 tmp = arch_to_object (find_archetype ("finger")); 2974 tmp = arch_to_object (archetype::find ("finger"));
3012 if (tmp != NULL) 2975 if (tmp != NULL)
3013 { 2976 {
3014 sprintf (buf, "%s's finger", &op->name); 2977 sprintf (buf, "%s's finger", &op->name);
3015 tmp->name = buf; 2978 tmp->name = buf;
3016 sprintf (buf, " This finger has been cut off %s\n" 2979 sprintf (buf, " This finger has been cut off %s\n"
3113 lost_a_stat = 1; 3076 lost_a_stat = 1;
3114 } 3077 }
3115 else 3078 else
3116 { 3079 {
3117 /* deplete a stat */ 3080 /* deplete a stat */
3118 archetype *deparch = find_archetype ("depletion"); 3081 archetype *deparch = archetype::find ("depletion");
3119 object *dep; 3082 object *dep;
3120 3083
3121 dep = present_arch_in_ob (deparch, op); 3084 dep = present_arch_in_ob (deparch, op);
3122 if (!dep) 3085 if (!dep)
3123 { 3086 {
3183 /* determine_god() seems to not work sometimes... why is this? 3146 /* determine_god() seems to not work sometimes... why is this?
3184 Should I be using something else? GD */ 3147 Should I be using something else? GD */
3185 const char *god = determine_god (op); 3148 const char *god = determine_god (op);
3186 3149
3187 if (god && (strcmp (god, "none"))) 3150 if (god && (strcmp (god, "none")))
3188 new_draw_info_format (NDI_UNIQUE, 0, op, "For a brief " "moment you feel the holy presence of %s protecting" " you.", god); 3151 new_draw_info_format (NDI_UNIQUE, 0, op, "For a brief moment you feel the holy presence of %s protecting" " you.", god);
3189 else 3152 else
3190 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you" " feel a holy presence protecting you."); 3153 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you feel a holy presence protecting you.");
3191 } 3154 }
3155#else
3156 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you" " feel a holy presence protecting you from losing yourself completely.");
3192#endif 3157#endif
3193 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you" " feel a holy presence protecting you from losing yourself completely.");
3194 3158
3195 /* Put a gravestone up where the character 'almost' died. List the 3159 /* Put a gravestone up where the character 'almost' died. List the
3196 * exp loss on the stone. 3160 * exp loss on the stone.
3197 */ 3161 */
3198 tmp = arch_to_object (find_archetype ("gravestone")); 3162 tmp = arch_to_object (archetype::find ("gravestone"));
3199 sprintf (buf, "%s's gravestone", &op->name); 3163 sprintf (buf, "%s's gravestone", &op->name);
3200 tmp->name = buf; 3164 tmp->name = buf;
3201 sprintf (buf, "%s's gravestones", &op->name); 3165 sprintf (buf, "%s's gravestones", &op->name);
3202 tmp->name_pl = buf; 3166 tmp->name_pl = buf;
3203 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); 3167 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);
3204 tmp->msg = buf; 3168 tmp->msg = buf;
3205 tmp->x = op->x, tmp->y = op->y; 3169 tmp->x = op->x, tmp->y = op->y;
3206 insert_ob_in_map (tmp, op->map, NULL, 0); 3170 insert_ob_in_map (tmp, op->map, NULL, 0);
3207 3171
3208 /**************************************/ 3172 /**************************************/
3209 /* */ 3173 /* */
3210 /* Subtract the experience points, */ 3174 /* Subtract the experience points, */
3211 /* if we died cause of food, give us */ 3175 /* if we died cause of food, give us */
3212 /* food, and reset HP's... */ 3176 /* food, and reset HP's... */
3213 /* */ 3177 /* */
3214
3215 /**************************************/ 3178 /**************************************/
3216 3179
3217 /* remove any poisoning and confusion the character may be suffering. */ 3180 /* remove any poisoning and confusion the character may be suffering. */
3218 /* restore player */ 3181 /* restore player */
3219 at = find_archetype ("poisoning"); 3182 at = archetype::find ("poisoning");
3183 tmp = present_arch_in_ob (at, op);
3184
3185 if (tmp)
3186 {
3187 tmp->destroy ();
3188 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed");
3189 }
3190
3191 at = archetype::find ("confusion");
3220 tmp = present_arch_in_ob (at, op); 3192 tmp = present_arch_in_ob (at, op);
3221 if (tmp) 3193 if (tmp)
3222 { 3194 {
3223 remove_ob (tmp); 3195 tmp->destroy ();
3224 free_object (tmp);
3225 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed");
3226 }
3227
3228 at = find_archetype ("confusion");
3229 tmp = present_arch_in_ob (at, op);
3230 if (tmp)
3231 {
3232 remove_ob (tmp);
3233 free_object (tmp);
3234 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer"); 3196 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer");
3235 } 3197 }
3198
3236 cure_disease (op, 0); /* remove any disease */ 3199 cure_disease (op, 0); /* remove any disease */
3237 3200
3238 /*add_exp(op, (op->stats.exp * -0.20)); */ 3201 /*add_exp(op, (op->stats.exp * -0.20)); */
3239 apply_death_exp_penalty (op); 3202 apply_death_exp_penalty (op);
3240 if (op->stats.food < 100) 3203 if (op->stats.food < 100)
3250 */ 3213 */
3251 3214
3252 if (is_in_shop (op)) 3215 if (is_in_shop (op))
3253 remove_unpaid_objects (op->inv, op); 3216 remove_unpaid_objects (op->inv, op);
3254 3217
3255 /****************************************/ 3218 /****************************************/
3256 /* */ 3219 /* */
3257 /* Move player to his current respawn- */ 3220 /* Move player to his current respawn- */
3258 /* position (usually last savebed) */ 3221 /* position (usually last savebed) */
3259 /* */ 3222 /* */
3260
3261 /****************************************/ 3223 /****************************************/
3262 3224
3263 enter_player_savebed (op); 3225 enter_player_savebed (op);
3264 3226
3265 /* Save the player before inserting the force to reduce 3227 /* Save the player before inserting the force to reduce
3266 * chance of abuse. 3228 * chance of abuse.
3273 * spell effects. So first see if there is a spell effect 3235 * spell effects. So first see if there is a spell effect
3274 * on the space that might harm the player. 3236 * on the space that might harm the player.
3275 */ 3237 */
3276 will_kill_again = 0; 3238 will_kill_again = 0;
3277 for (tmp = get_map_ob (op->map, op->x, op->y); tmp; tmp = tmp->above) 3239 for (tmp = get_map_ob (op->map, op->x, op->y); tmp; tmp = tmp->above)
3278 {
3279 if (tmp->type == SPELL_EFFECT) 3240 if (tmp->type == SPELL_EFFECT)
3280 will_kill_again |= tmp->attacktype; 3241 will_kill_again |= tmp->attacktype;
3281 } 3242
3282 if (will_kill_again) 3243 if (will_kill_again)
3283 { 3244 {
3284 object *force; 3245 object *force;
3285 int at; 3246 int at;
3286 3247
3288 /* 50 ticks should be enough time for the spell to abate */ 3249 /* 50 ticks should be enough time for the spell to abate */
3289 force->speed = 0.1; 3250 force->speed = 0.1;
3290 force->speed_left = -5.0; 3251 force->speed_left = -5.0;
3291 SET_FLAG (force, FLAG_APPLIED); 3252 SET_FLAG (force, FLAG_APPLIED);
3292 for (at = 0; at < NROFATTACKS; at++) 3253 for (at = 0; at < NROFATTACKS; at++)
3293 {
3294 if (will_kill_again & (1 << at)) 3254 if (will_kill_again & (1 << at))
3295 force->resist[at] = 100; 3255 force->resist[at] = 100;
3296 } 3256
3297 insert_ob_in_ob (force, op); 3257 insert_ob_in_ob (force, op);
3298 fix_player (op); 3258 fix_player (op);
3299 3259
3300 } 3260 }
3301
3302 /**************************************/
3303 /* */
3304 /* Repaint the characters inv, and */
3305 /* stats, and show a nasty message ;) */
3306 /* */
3307
3308 /**************************************/
3309 3261
3310 new_draw_info (NDI_UNIQUE, 0, op, "YOU HAVE DIED."); 3262 new_draw_info (NDI_UNIQUE, 0, op, "YOU HAVE DIED.");
3311 return; 3263 return;
3312 } /* NOT_PERMADETH */ 3264 } /* NOT_PERMADETH */
3313 else 3265 else
3319 op->contr->party = NULL; 3271 op->contr->party = NULL;
3320 if (settings.set_title == TRUE) 3272 if (settings.set_title == TRUE)
3321 op->contr->own_title[0] = '\0'; 3273 op->contr->own_title[0] = '\0';
3322 new_draw_info (NDI_UNIQUE | NDI_ALL, 0, NULL, buf); 3274 new_draw_info (NDI_UNIQUE | NDI_ALL, 0, NULL, buf);
3323 check_score (op); 3275 check_score (op);
3276
3324 if (op->contr->ranges[range_golem] != NULL) 3277 if (op->contr->ranges[range_golem])
3325 { 3278 {
3326 remove_friendly_object (op->contr->ranges[range_golem]); 3279 remove_friendly_object (op->contr->ranges[range_golem]);
3327 remove_ob (op->contr->ranges[range_golem]); 3280 op->contr->ranges[range_golem]->destroy ();
3328 free_object (op->contr->ranges[range_golem]);
3329 op->contr->ranges[range_golem] = NULL; 3281 op->contr->ranges[range_golem] = 0;
3330 op->contr->golem_count = 0;
3331 } 3282 }
3283
3332 loot_object (op); /* Remove some of the items for good */ 3284 loot_object (op); /* Remove some of the items for good */
3333 remove_ob (op); 3285 op->remove ();
3334 op->direction = 0; 3286 op->direction = 0;
3335 3287
3336 if (!QUERY_FLAG (op, FLAG_WAS_WIZ) && op->stats.exp) 3288 if (!QUERY_FLAG (op, FLAG_WAS_WIZ) && op->stats.exp)
3337 { 3289 {
3338 delete_character (op->name, 0); 3290 delete_character (op->name, 0);
3357 op->map = map; 3309 op->map = map;
3358 /* please see resurrection.c: peterm */ 3310 /* please see resurrection.c: peterm */
3359 dead_player (op); 3311 dead_player (op);
3360 } 3312 }
3361 else 3313 else
3362 {
3363 delete_character (op->name, 1); 3314 delete_character (op->name, 1);
3364 } 3315 }
3365 } 3316
3366 play_again (op); 3317 play_again (op);
3367 3318
3368 /* peterm: added to create a corpse at deathsite. */ 3319 /* peterm: added to create a corpse at deathsite. */
3369 tmp = arch_to_object (find_archetype ("corpse_pl")); 3320 tmp = arch_to_object (archetype::find ("corpse_pl"));
3370 sprintf (buf, "%s", &op->name); 3321 sprintf (buf, "%s", &op->name);
3371 tmp->name = tmp->name_pl = buf; 3322 tmp->name = tmp->name_pl = buf;
3372 tmp->level = op->level; 3323 tmp->level = op->level;
3373 tmp->x = x; 3324 tmp->x = x;
3374 tmp->y = y; 3325 tmp->y = y;
3392 for (tmp = op->inv; tmp != NULL; tmp = next) 3343 for (tmp = op->inv; tmp != NULL; tmp = next)
3393 { 3344 {
3394 next = tmp->below; 3345 next = tmp->below;
3395 if (tmp->type == EXPERIENCE || tmp->invisible) 3346 if (tmp->type == EXPERIENCE || tmp->invisible)
3396 continue; 3347 continue;
3397 remove_ob (tmp); 3348 tmp->remove ();
3398 tmp->x = op->x, tmp->y = op->y; 3349 tmp->x = op->x, tmp->y = op->y;
3399 if (tmp->type == CONTAINER) 3350 if (tmp->type == CONTAINER)
3400 { /* empty container to ground */ 3351 { /* empty container to ground */
3401 loot_object (tmp); 3352 loot_object (tmp);
3402 } 3353 }
3403 if (!QUERY_FLAG (tmp, FLAG_UNIQUE) && (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || QUERY_FLAG (tmp, FLAG_NO_DROP) || !(RANDOM () % 3))) 3354 if (!QUERY_FLAG (tmp, FLAG_UNIQUE) && (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || QUERY_FLAG (tmp, FLAG_NO_DROP) || !(RANDOM () % 3)))
3404 { 3355 {
3405 if (tmp->nrof > 1) 3356 if (tmp->nrof > 1)
3406 { 3357 {
3407 tmp2 = get_split_ob (tmp, 1 + RANDOM () % (tmp->nrof - 1)); 3358 tmp2 = get_split_ob (tmp, 1 + RANDOM () % (tmp->nrof - 1));
3408 free_object (tmp2); 3359 tmp2->destroy ();
3409 insert_ob_in_map (tmp, op->map, NULL, 0); 3360 insert_ob_in_map (tmp, op->map, NULL, 0);
3410 } 3361 }
3411 else 3362 else
3412 free_object (tmp); 3363 tmp->destroy ();
3413 } 3364 }
3414 else 3365 else
3415 insert_ob_in_map (tmp, op->map, NULL, 0); 3366 insert_ob_in_map (tmp, op->map, NULL, 0);
3416 } 3367 }
3417} 3368}
3482 if (op->type == PLAYER) 3433 if (op->type == PLAYER)
3483 new_draw_info_format (NDI_UNIQUE, 0, op, "You cast %s.", &spob->name); 3434 new_draw_info_format (NDI_UNIQUE, 0, op, "You cast %s.", &spob->name);
3484 3435
3485 cast_spell (op, throw_ob, dir, spob, NULL); 3436 cast_spell (op, throw_ob, dir, spob, NULL);
3486 3437
3487 if (!QUERY_FLAG (throw_ob, FLAG_REMOVED)) 3438 throw_ob->destroy ();
3488 remove_ob (throw_ob);
3489 free_object (throw_ob);
3490} 3439}
3491 3440
3492void 3441void
3493make_visible (object *op) 3442make_visible (object *op)
3494{ 3443{
3610int 3559int
3611stand_near_hostile (object *who) 3560stand_near_hostile (object *who)
3612{ 3561{
3613 object *tmp = NULL; 3562 object *tmp = NULL;
3614 int i, friendly = 0, player = 0, mflags; 3563 int i, friendly = 0, player = 0, mflags;
3615 mapstruct *m; 3564 maptile *m;
3616 sint16 x, y; 3565 sint16 x, y;
3617 3566
3618 if (!who) 3567 if (!who)
3619 return 0; 3568 return 0;
3620 3569

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines