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.19 by root, Mon Sep 11 23:53:30 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.19 2006/09/11 23:53:30 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;
772 player *pl = op->contr; 765 player *pl = op->contr;
773 shstr name = op->name; 766 shstr name = op->name;
774 767
775 op->contr = 0; 768 op->contr = 0;
776 op->type = 0; 769 op->type = 0;
777 op->free (1); 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;
1000 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, ""); 993 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "");
1001 return 1; 994 return 1;
1002 } 995 }
1003 switch (key) 996 switch (key)
1004 { 997 {
1005 case 'n': 998 case 'n':
1006 case 'N': 999 case 'N':
1007 { 1000 {
1008 SET_FLAG (op, FLAG_WIZ); 1001 SET_FLAG (op, FLAG_WIZ);
1009 if (op->map == NULL) 1002 if (op->map == NULL)
1010 { 1003 {
1011 LOG (llevError, "Map == NULL in state 2\n"); 1004 LOG (llevError, "Map == NULL in state 2\n");
1012 break; 1005 break;
1013 } 1006 }
1014 1007
1015#if 0 1008#if 0
1016 /* So that enter_exit will put us at startx/starty */ 1009 /* So that enter_exit will put us at startx/starty */
1017 op->x = -1; 1010 op->x = -1;
1018 1011
1019 enter_exit (op, NULL); 1012 enter_exit (op, NULL);
1020#endif 1013#endif
1021 SET_ANIMATION (op, 2); /* So player faces south */ 1014 SET_ANIMATION (op, 2); /* So player faces south */
1022 /* Enter exit adds a player otherwise */ 1015 /* Enter exit adds a player otherwise */
1023 add_statbonus (op); 1016 add_statbonus (op);
1024 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, 1017 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR,
1025 "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");
1026 op->contr->state = ST_CHANGE_CLASS; 1019 op->contr->state = ST_CHANGE_CLASS;
1027 if (op->msg) 1020 if (op->msg)
1028 new_draw_info (NDI_BLUE, 0, op, op->msg); 1021 new_draw_info (NDI_BLUE, 0, op, op->msg);
1029 return 0;
1030 }
1031 case 'y':
1032 case 'Y':
1033 roll_stats (op);
1034 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "");
1035 return 1;
1036
1037 case 'q':
1038 case 'Q':
1039 play_again (op);
1040 return 1;
1041
1042 default:
1043 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "Yes, No, Quit or 1-6. Roll again?");
1044 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;
1045 } 1038 }
1046 return 0; 1039 return 0;
1047} 1040}
1048 1041
1049/* This function takes the key that is passed, and does the 1042/* This function takes the key that is passed, and does the
1058{ 1051{
1059 int tmp_loop; 1052 int tmp_loop;
1060 1053
1061 if (key == 'q' || key == 'Q') 1054 if (key == 'q' || key == 'Q')
1062 { 1055 {
1063 remove_ob (op); 1056 op->remove ();
1064 play_again (op); 1057 play_again (op);
1065 return 0; 1058 return 0;
1066 } 1059 }
1067 if (key == 'd' || key == 'D') 1060 if (key == 'd' || key == 'D')
1068 { 1061 {
1069 char buf[MAX_BUF]; 1062 char buf[MAX_BUF];
1070 1063
1071 /* this must before then initial items are given */ 1064 /* this must before then initial items are given */
1072 esrv_new_player (op->contr, op->weight + op->carrying); 1065 esrv_new_player (op->contr, op->weight + op->carrying);
1066
1073 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);
1074 1070
1075 INVOKE_PLAYER (BIRTH, op->contr); 1071 INVOKE_PLAYER (BIRTH, op->contr);
1076 INVOKE_PLAYER (LOGIN, op->contr); 1072 INVOKE_PLAYER (LOGIN, op->contr);
1077 1073
1078 op->contr->state = ST_PLAYING; 1074 op->contr->state = ST_PLAYING;
1103 { 1099 {
1104 object *tmp; 1100 object *tmp;
1105 char mapname[MAX_BUF]; 1101 char mapname[MAX_BUF];
1106 1102
1107 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);
1108 tmp = get_object (); 1104 tmp = object::create ();
1109 EXIT_PATH (tmp) = mapname; 1105 EXIT_PATH (tmp) = mapname;
1110 EXIT_X (tmp) = op->x; 1106 EXIT_X (tmp) = op->x;
1111 EXIT_Y (tmp) = op->y; 1107 EXIT_Y (tmp) = op->y;
1112 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;
1113 * if the map isn't there, then stay on the 1109 * if the map isn't there, then stay on the
1114 * default initial map */ 1110 * default initial map */
1115 free_object (tmp); 1111 tmp->destroy ();
1116 } 1112 }
1117 else 1113 else
1118 { 1114 {
1119 LOG (llevDebug, "first_map_ext_path not set\n"); 1115 LOG (llevDebug, "first_map_ext_path not set\n");
1120 } 1116 }
1130 { 1126 {
1131 shstr name = op->name; 1127 shstr name = op->name;
1132 int x = op->x, y = op->y; 1128 int x = op->x, y = op->y;
1133 1129
1134 remove_statbonus (op); 1130 remove_statbonus (op);
1135 remove_ob (op); 1131 op->remove ();
1136 op->arch = get_player_archetype (op->arch); 1132 op->arch = get_player_archetype (op->arch);
1137 copy_object (&op->arch->clone, op); 1133 op->arch->clone.copy_to (op);
1138 op->instantiate (); 1134 op->instantiate ();
1139 op->stats = op->contr->orig_stats; 1135 op->stats = op->contr->orig_stats;
1140 op->name = op->name_pl = name; 1136 op->name = op->name_pl = name;
1141 op->x = x; 1137 op->x = x;
1142 op->y = y; 1138 op->y = y;
1143 SET_ANIMATION (op, 2); /* So player faces south */ 1139 SET_ANIMATION (op, 2); /* So player faces south */
1144 insert_ob_in_map (op, op->map, op, 0); 1140 insert_ob_in_map (op, op->map, op, 0);
1145 strncpy (op->contr->title, op->arch->clone.name, sizeof (op->contr->title) - 1); 1141 assign (op->contr->title, op->arch->clone.name);
1146 op->contr->title[sizeof (op->contr->title) - 1] = '\0';
1147 add_statbonus (op); 1142 add_statbonus (op);
1148 tmp_loop = allowed_class (op); 1143 tmp_loop = allowed_class (op);
1149 } 1144 }
1150 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 */
1270 */ 1267 */
1271int 1268int
1272check_pick (object *op) 1269check_pick (object *op)
1273{ 1270{
1274 object *tmp, *next; 1271 object *tmp, *next;
1275 tag_t next_tag = 0, op_tag;
1276 int stop = 0; 1272 int stop = 0;
1277 int j, k, wvratio; 1273 int j, k, wvratio;
1278 char putstring[128], tmpstr[16]; 1274 char putstring[128], tmpstr[16];
1279 1275
1280
1281 /* if you're flying, you cna't pick up anything */ 1276 /* if you're flying, you cna't pick up anything */
1282 if (op->move_type & MOVE_FLYING) 1277 if (op->move_type & MOVE_FLYING)
1283 return 1; 1278 return 1;
1284 1279
1285 op_tag = op->count;
1286
1287 next = op->below; 1280 next = op->below;
1288 if (next)
1289 next_tag = next->count;
1290 1281
1291 /* 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
1292 * destroyed */ 1283 * destroyed */
1293 while (next && !was_destroyed (next, next_tag)) 1284 while (next && !next->destroyed ())
1294 { 1285 {
1295 tmp = next; 1286 tmp = next;
1296 next = tmp->below; 1287 next = tmp->below;
1297 if (next)
1298 next_tag = next->count;
1299 1288
1300 if (was_destroyed (op, op_tag)) 1289 if (op->destroyed ())
1301 return 0; 1290 return 0;
1302 1291
1303 if (!can_pick (op, tmp)) 1292 if (!can_pick (op, tmp))
1304 continue; 1293 continue;
1305 1294
1313 /* high not bit set? We're using the old autopickup model */ 1302 /* high not bit set? We're using the old autopickup model */
1314 if (!(op->contr->mode & PU_NEWMODE)) 1303 if (!(op->contr->mode & PU_NEWMODE))
1315 { 1304 {
1316 switch (op->contr->mode) 1305 switch (op->contr->mode)
1317 { 1306 {
1318 case 0: 1307 case 0:
1319 return 1; /* don't pick up */ 1308 return 1; /* don't pick up */
1320 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))
1321 pick_up (op, tmp); 1326 pick_up (op, tmp);
1322 return 1; 1327 break;
1328
1323 case 2: 1329 case 7:
1330 if (tmp->type == MONEY || tmp->type == GEM)
1324 pick_up (op, tmp); 1331 pick_up (op, tmp);
1325 return 0; 1332 break;
1326 case 3: 1333
1327 return 0; /* stop before pickup */ 1334 default:
1328 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)
1329 pick_up (op, tmp); 1338 pick_up (op, tmp);
1330 break;
1331 case 5:
1332 pick_up (op, tmp);
1333 stop = 1;
1334 break;
1335 case 6:
1336 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))
1337 pick_up (op, tmp);
1338 break;
1339
1340 case 7:
1341 if (tmp->type == MONEY || tmp->type == GEM)
1342 pick_up (op, tmp);
1343 break;
1344
1345 default:
1346 /* use value density */
1347 if (!QUERY_FLAG (tmp, FLAG_UNPAID)
1348 && (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))) >= op->contr->mode)
1349 pick_up (op, tmp);
1350 } 1339 }
1351 } 1340 }
1352 else 1341 else
1353 { /* old model */ 1342 { /* old model */
1354 /* NEW pickup handling */ 1343 /* NEW pickup handling */
1437 /* question: don't pick up known-poisonous stuff? */ 1426 /* question: don't pick up known-poisonous stuff? */
1438 if (op->contr->mode & PU_FOOD) 1427 if (op->contr->mode & PU_FOOD)
1439 if (tmp->type == FOOD) 1428 if (tmp->type == FOOD)
1440 { 1429 {
1441 pick_up (op, tmp); 1430 pick_up (op, tmp);
1442 if (0)
1443 fprintf (stderr, "FOOD\n");
1444 continue; 1431 continue;
1445 } 1432 }
1433
1446 if (op->contr->mode & PU_DRINK) 1434 if (op->contr->mode & PU_DRINK)
1447 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)))
1448 { 1436 {
1449 pick_up (op, tmp); 1437 pick_up (op, tmp);
1450 if (0)
1451 fprintf (stderr, "DRINK\n");
1452 continue; 1438 continue;
1453 } 1439 }
1454 1440
1455 if (op->contr->mode & PU_POTION) 1441 if (op->contr->mode & PU_POTION)
1456 if (tmp->type == POTION) 1442 if (tmp->type == POTION)
1457 { 1443 {
1458 pick_up (op, tmp); 1444 pick_up (op, tmp);
1459 if (0)
1460 fprintf (stderr, "POTION\n");
1461 continue; 1445 continue;
1462 } 1446 }
1463 1447
1464 /* spellbooks, skillscrolls and normal books/scrolls */ 1448 /* spellbooks, skillscrolls and normal books/scrolls */
1465 if (op->contr->mode & PU_SPELLBOOK) 1449 if (op->contr->mode & PU_SPELLBOOK)
1466 if (tmp->type == SPELLBOOK) 1450 if (tmp->type == SPELLBOOK)
1467 { 1451 {
1468 pick_up (op, tmp); 1452 pick_up (op, tmp);
1469 if (0)
1470 fprintf (stderr, "SPELLBOOK\n");
1471 continue; 1453 continue;
1472 } 1454 }
1455
1473 if (op->contr->mode & PU_SKILLSCROLL) 1456 if (op->contr->mode & PU_SKILLSCROLL)
1474 if (tmp->type == SKILLSCROLL) 1457 if (tmp->type == SKILLSCROLL)
1475 { 1458 {
1476 pick_up (op, tmp); 1459 pick_up (op, tmp);
1477 if (0)
1478 fprintf (stderr, "SKILLSCROLL\n");
1479 continue; 1460 continue;
1480 } 1461 }
1462
1481 if (op->contr->mode & PU_READABLES) 1463 if (op->contr->mode & PU_READABLES)
1482 if (tmp->type == BOOK || tmp->type == SCROLL) 1464 if (tmp->type == BOOK || tmp->type == SCROLL)
1483 { 1465 {
1484 pick_up (op, tmp); 1466 pick_up (op, tmp);
1485 if (0)
1486 fprintf (stderr, "READABLES\n");
1487 continue; 1467 continue;
1488 } 1468 }
1489 1469
1490 /* wands/staves/rods/horns */ 1470 /* wands/staves/rods/horns */
1491 if (op->contr->mode & PU_MAGIC_DEVICE) 1471 if (op->contr->mode & PU_MAGIC_DEVICE)
1492 if (tmp->type == WAND || tmp->type == ROD || tmp->type == HORN) 1472 if (tmp->type == WAND || tmp->type == ROD || tmp->type == HORN)
1493 { 1473 {
1494 pick_up (op, tmp); 1474 pick_up (op, tmp);
1495 if (0)
1496 fprintf (stderr, "MAGIC_DEVICE\n");
1497 continue; 1475 continue;
1498 } 1476 }
1499 1477
1500 /* pick up all magical items */ 1478 /* pick up all magical items */
1501 if (op->contr->mode & PU_MAGICAL) 1479 if (op->contr->mode & PU_MAGICAL)
1502 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))
1503 { 1481 {
1504 pick_up (op, tmp); 1482 pick_up (op, tmp);
1505 if (0)
1506 fprintf (stderr, "MAGICAL\n");
1507 continue; 1483 continue;
1508 } 1484 }
1509 1485
1510 if (op->contr->mode & PU_VALUABLES) 1486 if (op->contr->mode & PU_VALUABLES)
1511 { 1487 {
1512 if (tmp->type == MONEY || tmp->type == GEM) 1488 if (tmp->type == MONEY || tmp->type == GEM)
1513 { 1489 {
1514 pick_up (op, tmp); 1490 pick_up (op, tmp);
1515 if (0)
1516 fprintf (stderr, "MONEY/GEM\n");
1517 continue; 1491 continue;
1518 } 1492 }
1519 } 1493 }
1520 1494
1521 /* rings & amulets - talismans seems to be typed AMULET */ 1495 /* rings & amulets - talismans seems to be typed AMULET */
1522 if (op->contr->mode & PU_JEWELS) 1496 if (op->contr->mode & PU_JEWELS)
1523 if (tmp->type == RING || tmp->type == AMULET) 1497 if (tmp->type == RING || tmp->type == AMULET)
1524 { 1498 {
1525 pick_up (op, tmp); 1499 pick_up (op, tmp);
1500 continue;
1526 if (0) 1501 }
1527 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);
1528 continue; 1508 continue;
1529 } 1509 }
1530 1510
1531 /* bows and arrows. Bows are good for selling! */ 1511 /* bows and arrows. Bows are good for selling! */
1532 if (op->contr->mode & PU_BOW) 1512 if (op->contr->mode & PU_BOW)
1533 if (tmp->type == BOW) 1513 if (tmp->type == BOW)
1534 { 1514 {
1535 pick_up (op, tmp); 1515 pick_up (op, tmp);
1536 if (0)
1537 fprintf (stderr, "BOW\n");
1538 continue; 1516 continue;
1539 } 1517 }
1518
1540 if (op->contr->mode & PU_ARROW) 1519 if (op->contr->mode & PU_ARROW)
1541 if (tmp->type == ARROW) 1520 if (tmp->type == ARROW)
1542 { 1521 {
1543 pick_up (op, tmp); 1522 pick_up (op, tmp);
1544 if (0)
1545 fprintf (stderr, "ARROW\n");
1546 continue; 1523 continue;
1547 } 1524 }
1548 1525
1549 /* all kinds of armor etc. */ 1526 /* all kinds of armor etc. */
1550 if (op->contr->mode & PU_ARMOUR) 1527 if (op->contr->mode & PU_ARMOUR)
1551 if (tmp->type == ARMOUR) 1528 if (tmp->type == ARMOUR)
1552 { 1529 {
1553 pick_up (op, tmp); 1530 pick_up (op, tmp);
1554 if (0)
1555 fprintf (stderr, "ARMOUR\n");
1556 continue; 1531 continue;
1557 } 1532 }
1533
1558 if (op->contr->mode & PU_HELMET) 1534 if (op->contr->mode & PU_HELMET)
1559 if (tmp->type == HELMET) 1535 if (tmp->type == HELMET)
1560 { 1536 {
1561 pick_up (op, tmp); 1537 pick_up (op, tmp);
1562 if (0)
1563 fprintf (stderr, "HELMET\n");
1564 continue; 1538 continue;
1565 } 1539 }
1540
1566 if (op->contr->mode & PU_SHIELD) 1541 if (op->contr->mode & PU_SHIELD)
1567 if (tmp->type == SHIELD) 1542 if (tmp->type == SHIELD)
1568 { 1543 {
1569 pick_up (op, tmp); 1544 pick_up (op, tmp);
1570 if (0)
1571 fprintf (stderr, "SHIELD\n");
1572 continue; 1545 continue;
1573 } 1546 }
1547
1574 if (op->contr->mode & PU_BOOTS) 1548 if (op->contr->mode & PU_BOOTS)
1575 if (tmp->type == BOOTS) 1549 if (tmp->type == BOOTS)
1576 { 1550 {
1577 pick_up (op, tmp); 1551 pick_up (op, tmp);
1578 if (0)
1579 fprintf (stderr, "BOOTS\n");
1580 continue; 1552 continue;
1581 } 1553 }
1554
1582 if (op->contr->mode & PU_GLOVES) 1555 if (op->contr->mode & PU_GLOVES)
1583 if (tmp->type == GLOVES) 1556 if (tmp->type == GLOVES)
1584 { 1557 {
1585 pick_up (op, tmp); 1558 pick_up (op, tmp);
1586 if (0)
1587 fprintf (stderr, "GLOVES\n");
1588 continue; 1559 continue;
1589 } 1560 }
1561
1590 if (op->contr->mode & PU_CLOAK) 1562 if (op->contr->mode & PU_CLOAK)
1591 if (tmp->type == CLOAK) 1563 if (tmp->type == CLOAK)
1592 { 1564 {
1593 pick_up (op, tmp); 1565 pick_up (op, tmp);
1594 if (0)
1595 fprintf (stderr, "GLOVES\n");
1596 continue; 1566 continue;
1597 } 1567 }
1598 1568
1599 /* hoping to catch throwing daggers here */ 1569 /* hoping to catch throwing daggers here */
1600 if (op->contr->mode & PU_MISSILEWEAPON) 1570 if (op->contr->mode & PU_MISSILEWEAPON)
1601 if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_IS_THROWN)) 1571 if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_IS_THROWN))
1602 { 1572 {
1603 pick_up (op, tmp); 1573 pick_up (op, tmp);
1604 if (0)
1605 fprintf (stderr, "MISSILEWEAPON\n");
1606 continue; 1574 continue;
1607 } 1575 }
1608 1576
1609 /* careful: chairs and tables are weapons! */ 1577 /* careful: chairs and tables are weapons! */
1610 if (op->contr->mode & PU_ALLWEAPON) 1578 if (op->contr->mode & PU_ALLWEAPON)
1613 { 1581 {
1614 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 &&
1615 strstr (tmp->name, "chair") && strstr (tmp->arch->name, "chair") == NULL) 1583 strstr (tmp->name, "chair") && strstr (tmp->arch->name, "chair") == NULL)
1616 { 1584 {
1617 pick_up (op, tmp); 1585 pick_up (op, tmp);
1618 if (0)
1619 fprintf (stderr, "WEAPON\n");
1620 continue; 1586 continue;
1621 } 1587 }
1622 } 1588 }
1589
1623 if (tmp->type == WEAPON && tmp->name == NULL) 1590 if (tmp->type == WEAPON && tmp->name == NULL)
1624 { 1591 {
1625 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)
1626 { 1593 {
1627 pick_up (op, tmp); 1594 pick_up (op, tmp);
1628 if (0)
1629 fprintf (stderr, "WEAPON\n");
1630 continue; 1595 continue;
1631 } 1596 }
1632 } 1597 }
1633 } 1598 }
1634 1599
1635 /* misc stuff that's useful */ 1600 /* misc stuff that's useful */
1636 if (op->contr->mode & PU_KEY) 1601 if (op->contr->mode & PU_KEY)
1637 if (tmp->type == KEY || tmp->type == SPECIAL_KEY) 1602 if (tmp->type == KEY || tmp->type == SPECIAL_KEY)
1638 { 1603 {
1639 pick_up (op, tmp); 1604 pick_up (op, tmp);
1640 if (0)
1641 fprintf (stderr, "KEY\n");
1642 continue; 1605 continue;
1643 } 1606 }
1644 1607
1645 /* 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
1646 * pickups */ 1609 * pickups */
1668 continue; 1631 continue;
1669 } 1632 }
1670 } 1633 }
1671 } /* the new pickup model */ 1634 } /* the new pickup model */
1672 } 1635 }
1636
1673 return !stop; 1637 return !stop;
1674} 1638}
1675 1639
1676/* 1640/*
1677 * Find an arrow in the inventory and after that 1641 * Find an arrow in the inventory and after that
1776 1740
1777object * 1741object *
1778pick_arrow_target (object *op, const char *type, int dir) 1742pick_arrow_target (object *op, const char *type, int dir)
1779{ 1743{
1780 object *tmp = NULL; 1744 object *tmp = NULL;
1781 mapstruct *m; 1745 maptile *m;
1782 int i, mflags, found, number; 1746 int i, mflags, found, number;
1783 sint16 x, y; 1747 sint16 x, y;
1784 1748
1785 if (op->map == NULL) 1749 if (op->map == NULL)
1786 return find_arrow (op, type); 1750 return find_arrow (op, type);
1846 */ 1810 */
1847int 1811int
1848fire_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)
1849{ 1813{
1850 object *left, *bow; 1814 object *left, *bow;
1851 tag_t left_tag, tag;
1852 int bowspeed, mflags; 1815 int bowspeed, mflags;
1853 mapstruct *m; 1816 maptile *m;
1854 1817
1855 if (!dir) 1818 if (!dir)
1856 { 1819 {
1857 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!");
1858 return 0; 1821 return 0;
1912 } 1875 }
1913 1876
1914 /* this should not happen, but sometimes does */ 1877 /* this should not happen, but sometimes does */
1915 if (arrow->nrof == 0) 1878 if (arrow->nrof == 0)
1916 { 1879 {
1917 remove_ob (arrow); 1880 arrow->destroy ();
1918 free_object (arrow);
1919 return 0; 1881 return 0;
1920 } 1882 }
1921 1883
1922 left = arrow; /* these are arrows left to the player */ 1884 left = arrow; /* these are arrows left to the player */
1923 left_tag = left->count;
1924 arrow = get_split_ob (arrow, 1); 1885 arrow = get_split_ob (arrow, 1);
1925 if (arrow == NULL) 1886 if (arrow == NULL)
1926 { 1887 {
1927 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);
1928 return 0; 1889 return 0;
1929 } 1890 }
1930 set_owner (arrow, op); 1891 arrow->set_owner (op);
1931 arrow->skill = bow->skill; 1892 arrow->skill = bow->skill;
1932 1893
1933 arrow->direction = dir; 1894 arrow->direction = dir;
1934 arrow->x = sx; 1895 arrow->x = sx;
1935 arrow->y = sy; 1896 arrow->y = sy;
1971 arrow->level = op->chosen_skill ? op->chosen_skill->level : op->level; 1932 arrow->level = op->chosen_skill ? op->chosen_skill->level : op->level;
1972 } 1933 }
1973 else 1934 else
1974 { 1935 {
1975 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;
1976
1977 arrow->level = op->level; 1937 arrow->level = op->level;
1978 } 1938 }
1939
1979 if (arrow->attacktype == AT_PHYSICAL) 1940 if (arrow->attacktype == AT_PHYSICAL)
1980 arrow->attacktype |= bow->attacktype; 1941 arrow->attacktype |= bow->attacktype;
1942
1981 if (bow->slaying != NULL) 1943 if (bow->slaying != NULL)
1982 arrow->slaying = bow->slaying; 1944 arrow->slaying = bow->slaying;
1983 1945
1984 arrow->map = m; 1946 arrow->map = m;
1985 arrow->move_type = MOVE_FLY_LOW; 1947 arrow->move_type = MOVE_FLY_LOW;
1986 arrow->move_on = MOVE_FLY_LOW | MOVE_WALK; 1948 arrow->move_on = MOVE_FLY_LOW | MOVE_WALK;
1987 1949
1988 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);
1989 tag = arrow->count;
1990 insert_ob_in_map (arrow, m, op, 0); 1951 insert_ob_in_map (arrow, m, op, 0);
1991 1952
1992 if (!was_destroyed (arrow, tag)) 1953 if (!arrow->destroyed ())
1993 move_arrow (arrow); 1954 move_arrow (arrow);
1994 1955
1995 if (op->type == PLAYER) 1956 if (op->type == PLAYER)
1996 { 1957 {
1997 if (was_destroyed (left, left_tag)) 1958 if (left->destroyed ())
1998 esrv_del_item (op->contr, left_tag); 1959 esrv_del_item (op->contr, left->count);
1999 else 1960 else
2000 esrv_send_item (op, left); 1961 esrv_send_item (op, left);
2001 } 1962 }
1963
2002 return 1; 1964 return 1;
2003} 1965}
2004 1966
2005/* Special fire code for players - this takes into 1967/* Special fire code for players - this takes into
2006 * account the special fire modes players can have 1968 * account the special fire modes players can have
2126 if (action_makes_visible (op)) 2088 if (action_makes_visible (op))
2127 make_visible (op); 2089 make_visible (op);
2128 2090
2129 switch (op->contr->shoottype) 2091 switch (op->contr->shoottype)
2130 { 2092 {
2131 case range_none: 2093 case range_none:
2132 return; 2094 return;
2133 2095
2134 case range_bow: 2096 case range_bow:
2135 player_fire_bow (op, dir); 2097 player_fire_bow (op, dir);
2136 return; 2098 return;
2137 2099
2138 case range_magic: /* Casting spells */ 2100 case range_magic: /* Casting spells */
2139 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));
2140 return; 2102 return;
2141 2103
2142 case range_misc: 2104 case range_misc:
2143 fire_misc_object (op, dir); 2105 fire_misc_object (op, dir);
2144 return; 2106 return;
2145 2107
2146 case range_golem: /* Control summoned monsters from scrolls */ 2108 case range_golem: /* Control summoned monsters from scrolls */
2147 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))
2148 { 2110 {
2149 op->contr->ranges[range_golem] = NULL; 2111 op->contr->ranges[range_golem] = 0;
2150 op->contr->shoottype = range_none; 2112 op->contr->shoottype = range_none;
2151 op->contr->golem_count = 0;
2152 } 2113 }
2153 else 2114 else
2154 control_golem (op->contr->ranges[range_golem], dir); 2115 control_golem (op->contr->ranges[range_golem], dir);
2155 return; 2116 return;
2156 2117
2157 case range_skill: 2118 case range_skill:
2158 if (!op->chosen_skill) 2119 if (!op->chosen_skill)
2159 { 2120 {
2160 if (op->type == PLAYER) 2121 if (op->type == PLAYER)
2161 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.");
2162 return; 2123 return;
2163 } 2124 }
2164 (void) do_skill (op, op, op->chosen_skill, dir, NULL); 2125 (void) do_skill (op, op, op->chosen_skill, dir, NULL);
2165 return; 2126 return;
2166 case range_builder: 2127 case range_builder:
2167 apply_map_builder (op, dir); 2128 apply_map_builder (op, dir);
2168 return; 2129 return;
2169 default: 2130 default:
2170 new_draw_info (NDI_UNIQUE, 0, op, "Illegal shoot type."); 2131 new_draw_info (NDI_UNIQUE, 0, op, "Illegal shoot type.");
2171 return; 2132 return;
2172 } 2133 }
2173} 2134}
2174 2135
2175 2136
2176 2137
2318move_player_attack (object *op, int dir) 2279move_player_attack (object *op, int dir)
2319{ 2280{
2320 object *tmp, *mon; 2281 object *tmp, *mon;
2321 sint16 nx, ny; 2282 sint16 nx, ny;
2322 int on_battleground; 2283 int on_battleground;
2323 mapstruct *m; 2284 maptile *m;
2324 2285
2325 nx = freearr_x[dir] + op->x; 2286 nx = freearr_x[dir] + op->x;
2326 ny = freearr_y[dir] + op->y; 2287 ny = freearr_y[dir] + op->y;
2327 2288
2328 on_battleground = op_on_battleground (op, NULL, NULL); 2289 on_battleground = op_on_battleground (op, NULL, NULL);
2364 if (tmp == op) 2325 if (tmp == op)
2365 { 2326 {
2366 tmp = tmp->above; 2327 tmp = tmp->above;
2367 continue; 2328 continue;
2368 } 2329 }
2330
2369 if (QUERY_FLAG (tmp, FLAG_ALIVE)) 2331 if (QUERY_FLAG (tmp, FLAG_ALIVE))
2370 { 2332 {
2371 mon = tmp; 2333 mon = tmp;
2372 break; 2334 break;
2373 } 2335 }
2336
2374 if (tmp->type == LOCKED_DOOR || QUERY_FLAG (tmp, FLAG_CAN_ROLL)) 2337 if (tmp->type == LOCKED_DOOR || QUERY_FLAG (tmp, FLAG_CAN_ROLL))
2375 mon = tmp; 2338 mon = tmp;
2339
2376 tmp = tmp->above; 2340 tmp = tmp->above;
2377 } 2341 }
2378 2342
2379 if (mon == NULL) /* This happens anytime the player tries to move */ 2343 if (mon == NULL) /* This happens anytime the player tries to move */
2380 return; /* into a wall */ 2344 return; /* into a wall */
2399 * player owns it and it is either friendly or unagressive. 2363 * player owns it and it is either friendly or unagressive.
2400 */ 2364 */
2401 if ((op->type == PLAYER) 2365 if ((op->type == PLAYER)
2402#if COZY_SERVER 2366#if COZY_SERVER
2403 && 2367 &&
2404 ((get_owner (mon) && get_owner (mon)->contr 2368 ((mon->owner && mon->owner->contr
2405 && 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)
2406#else 2370#else
2407 && get_owner (mon) == op 2371 && mon->owner == op
2408#endif 2372#endif
2409 && (QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY))) 2373 && (QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY)))
2410 { 2374 {
2411 /* 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 */
2412 if (op->contr->braced) 2376 if (op->contr->braced)
2599 /* 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
2600 * 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
2601 * 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
2602 * 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.
2603 */ 2567 */
2604 if (op->contr->ranges[range_golem] &&
2605 ((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))
2606 {
2607 op->contr->ranges[range_golem] = NULL; 2569 op->contr->ranges[range_golem] = 0;
2608 op->contr->golem_count = 0;
2609 }
2610 2570
2611 /* 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
2612 * the players time has been increased when doericserver has been 2572 * the players time has been increased when doericserver has been
2613 * called, so we recheck it here. 2573 * called, so we recheck it here.
2614 */ 2574 */
2645 for (tmp = op->inv; tmp != NULL; tmp = tmp->below) 2605 for (tmp = op->inv; tmp != NULL; tmp = tmp->below)
2646 if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE)) 2606 if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE))
2647 { 2607 {
2648 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);
2649 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
2650 if (op->contr) 2611 if (op->contr)
2651 esrv_del_item (op->contr, tmp->count); 2612 esrv_del_item (op->contr, tmp->count);
2652 remove_ob (tmp); 2613
2653 free_object (tmp); 2614 tmp->destroy ();
2654 CLEAR_FLAG (op, FLAG_LIFESAVE); 2615 CLEAR_FLAG (op, FLAG_LIFESAVE);
2616
2655 if (op->stats.hp < 0) 2617 if (op->stats.hp < 0)
2656 op->stats.hp = op->stats.maxhp; 2618 op->stats.hp = op->stats.maxhp;
2619
2657 if (op->stats.food < 0) 2620 if (op->stats.food < 0)
2658 op->stats.food = 999; 2621 op->stats.food = 999;
2622
2659 fix_player (op); 2623 fix_player (op);
2660 return 1; 2624 return 1;
2661 } 2625 }
2662 LOG (llevError, "Error: LIFESAVE set without applied object.\n"); 2626 LOG (llevError, "Error: LIFESAVE set without applied object.\n");
2663 CLEAR_FLAG (op, FLAG_LIFESAVE); 2627 CLEAR_FLAG (op, FLAG_LIFESAVE);
2680 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
2681 * we remove object 'op' 2645 * we remove object 'op'
2682 */ 2646 */
2683 if (QUERY_FLAG (op, FLAG_UNPAID)) 2647 if (QUERY_FLAG (op, FLAG_UNPAID))
2684 { 2648 {
2685 remove_ob (op); 2649 op->remove ();
2686 op->x = env->x; 2650 op->x = env->x;
2687 op->y = env->y; 2651 op->y = env->y;
2688 if (env->type == PLAYER) 2652 if (env->type == PLAYER)
2689 esrv_del_item (env->contr, op->count); 2653 esrv_del_item (env->contr, op->count);
2690 insert_ob_in_map (op, env->map, NULL, 0); 2654 insert_ob_in_map (op, env->map, NULL, 0);
2958{ 2922{
2959 char buf[MAX_BUF]; 2923 char buf[MAX_BUF];
2960 int x, y; 2924 int x, y;
2961 2925
2962 //int i; 2926 //int i;
2963 mapstruct *map; /* this is for resurrection */ 2927 maptile *map; /* this is for resurrection */
2964 2928
2965 /* int z; 2929 /* int z;
2966 int num_stats_lose; 2930 int num_stats_lose;
2967 int lost_a_stat; 2931 int lost_a_stat;
2968 int lose_this_stat; 2932 int lose_this_stat;
2983 { 2947 {
2984 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!");
2985 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...");
2986 2950
2987 /* restore player */ 2951 /* restore player */
2988 at = find_archetype ("poisoning"); 2952 at = archetype::find ("poisoning");
2989 tmp = present_arch_in_ob (at, op); 2953 tmp = present_arch_in_ob (at, op);
2990 if (tmp) 2954 if (tmp)
2991 { 2955 {
2992 remove_ob (tmp); 2956 tmp->destroy ();
2993 free_object (tmp);
2994 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed"); 2957 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed");
2995 } 2958 }
2996 2959
2997 at = find_archetype ("confusion"); 2960 at = archetype::find ("confusion");
2998 tmp = present_arch_in_ob (at, op); 2961 tmp = present_arch_in_ob (at, op);
2999 if (tmp) 2962 if (tmp)
3000 { 2963 {
3001 remove_ob (tmp); 2964 tmp->destroy ();
3002 free_object (tmp);
3003 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer"); 2965 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer");
3004 } 2966 }
3005 2967
3006 cure_disease (op, 0); /* remove any disease */ 2968 cure_disease (op, 0); /* remove any disease */
3007 op->stats.hp = op->stats.maxhp; 2969 op->stats.hp = op->stats.maxhp;
3008 if (op->stats.food <= 0) 2970 if (op->stats.food <= 0)
3009 op->stats.food = 999; 2971 op->stats.food = 999;
3010 2972
3011 /* create a bodypart-trophy to make the winner happy */ 2973 /* create a bodypart-trophy to make the winner happy */
3012 tmp = arch_to_object (find_archetype ("finger")); 2974 tmp = arch_to_object (archetype::find ("finger"));
3013 if (tmp != NULL) 2975 if (tmp != NULL)
3014 { 2976 {
3015 sprintf (buf, "%s's finger", &op->name); 2977 sprintf (buf, "%s's finger", &op->name);
3016 tmp->name = buf; 2978 tmp->name = buf;
3017 sprintf (buf, " This finger has been cut off %s\n" 2979 sprintf (buf, " This finger has been cut off %s\n"
3114 lost_a_stat = 1; 3076 lost_a_stat = 1;
3115 } 3077 }
3116 else 3078 else
3117 { 3079 {
3118 /* deplete a stat */ 3080 /* deplete a stat */
3119 archetype *deparch = find_archetype ("depletion"); 3081 archetype *deparch = archetype::find ("depletion");
3120 object *dep; 3082 object *dep;
3121 3083
3122 dep = present_arch_in_ob (deparch, op); 3084 dep = present_arch_in_ob (deparch, op);
3123 if (!dep) 3085 if (!dep)
3124 { 3086 {
3184 /* determine_god() seems to not work sometimes... why is this? 3146 /* determine_god() seems to not work sometimes... why is this?
3185 Should I be using something else? GD */ 3147 Should I be using something else? GD */
3186 const char *god = determine_god (op); 3148 const char *god = determine_god (op);
3187 3149
3188 if (god && (strcmp (god, "none"))) 3150 if (god && (strcmp (god, "none")))
3189 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);
3190 else 3152 else
3191 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.");
3192 } 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.");
3193#endif 3157#endif
3194 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you" " feel a holy presence protecting you from losing yourself completely.");
3195 3158
3196 /* Put a gravestone up where the character 'almost' died. List the 3159 /* Put a gravestone up where the character 'almost' died. List the
3197 * exp loss on the stone. 3160 * exp loss on the stone.
3198 */ 3161 */
3199 tmp = arch_to_object (find_archetype ("gravestone")); 3162 tmp = arch_to_object (archetype::find ("gravestone"));
3200 sprintf (buf, "%s's gravestone", &op->name); 3163 sprintf (buf, "%s's gravestone", &op->name);
3201 tmp->name = buf; 3164 tmp->name = buf;
3202 sprintf (buf, "%s's gravestones", &op->name); 3165 sprintf (buf, "%s's gravestones", &op->name);
3203 tmp->name_pl = buf; 3166 tmp->name_pl = buf;
3204 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);
3205 tmp->msg = buf; 3168 tmp->msg = buf;
3206 tmp->x = op->x, tmp->y = op->y; 3169 tmp->x = op->x, tmp->y = op->y;
3207 insert_ob_in_map (tmp, op->map, NULL, 0); 3170 insert_ob_in_map (tmp, op->map, NULL, 0);
3208 3171
3209 /**************************************/ 3172 /**************************************/
3210 /* */ 3173 /* */
3211 /* Subtract the experience points, */ 3174 /* Subtract the experience points, */
3212 /* if we died cause of food, give us */ 3175 /* if we died cause of food, give us */
3213 /* food, and reset HP's... */ 3176 /* food, and reset HP's... */
3214 /* */ 3177 /* */
3215
3216 /**************************************/ 3178 /**************************************/
3217 3179
3218 /* remove any poisoning and confusion the character may be suffering. */ 3180 /* remove any poisoning and confusion the character may be suffering. */
3219 /* restore player */ 3181 /* restore player */
3220 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");
3221 tmp = present_arch_in_ob (at, op); 3192 tmp = present_arch_in_ob (at, op);
3222 if (tmp) 3193 if (tmp)
3223 { 3194 {
3224 remove_ob (tmp); 3195 tmp->destroy ();
3225 free_object (tmp);
3226 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed");
3227 }
3228
3229 at = find_archetype ("confusion");
3230 tmp = present_arch_in_ob (at, op);
3231 if (tmp)
3232 {
3233 remove_ob (tmp);
3234 free_object (tmp);
3235 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer"); 3196 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer");
3236 } 3197 }
3198
3237 cure_disease (op, 0); /* remove any disease */ 3199 cure_disease (op, 0); /* remove any disease */
3238 3200
3239 /*add_exp(op, (op->stats.exp * -0.20)); */ 3201 /*add_exp(op, (op->stats.exp * -0.20)); */
3240 apply_death_exp_penalty (op); 3202 apply_death_exp_penalty (op);
3241 if (op->stats.food < 100) 3203 if (op->stats.food < 100)
3251 */ 3213 */
3252 3214
3253 if (is_in_shop (op)) 3215 if (is_in_shop (op))
3254 remove_unpaid_objects (op->inv, op); 3216 remove_unpaid_objects (op->inv, op);
3255 3217
3256 /****************************************/ 3218 /****************************************/
3257 /* */ 3219 /* */
3258 /* Move player to his current respawn- */ 3220 /* Move player to his current respawn- */
3259 /* position (usually last savebed) */ 3221 /* position (usually last savebed) */
3260 /* */ 3222 /* */
3261
3262 /****************************************/ 3223 /****************************************/
3263 3224
3264 enter_player_savebed (op); 3225 enter_player_savebed (op);
3265 3226
3266 /* Save the player before inserting the force to reduce 3227 /* Save the player before inserting the force to reduce
3267 * chance of abuse. 3228 * chance of abuse.
3274 * spell effects. So first see if there is a spell effect 3235 * spell effects. So first see if there is a spell effect
3275 * on the space that might harm the player. 3236 * on the space that might harm the player.
3276 */ 3237 */
3277 will_kill_again = 0; 3238 will_kill_again = 0;
3278 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)
3279 {
3280 if (tmp->type == SPELL_EFFECT) 3240 if (tmp->type == SPELL_EFFECT)
3281 will_kill_again |= tmp->attacktype; 3241 will_kill_again |= tmp->attacktype;
3282 } 3242
3283 if (will_kill_again) 3243 if (will_kill_again)
3284 { 3244 {
3285 object *force; 3245 object *force;
3286 int at; 3246 int at;
3287 3247
3289 /* 50 ticks should be enough time for the spell to abate */ 3249 /* 50 ticks should be enough time for the spell to abate */
3290 force->speed = 0.1; 3250 force->speed = 0.1;
3291 force->speed_left = -5.0; 3251 force->speed_left = -5.0;
3292 SET_FLAG (force, FLAG_APPLIED); 3252 SET_FLAG (force, FLAG_APPLIED);
3293 for (at = 0; at < NROFATTACKS; at++) 3253 for (at = 0; at < NROFATTACKS; at++)
3294 {
3295 if (will_kill_again & (1 << at)) 3254 if (will_kill_again & (1 << at))
3296 force->resist[at] = 100; 3255 force->resist[at] = 100;
3297 } 3256
3298 insert_ob_in_ob (force, op); 3257 insert_ob_in_ob (force, op);
3299 fix_player (op); 3258 fix_player (op);
3300 3259
3301 } 3260 }
3302 3261
3312 op->contr->party = NULL; 3271 op->contr->party = NULL;
3313 if (settings.set_title == TRUE) 3272 if (settings.set_title == TRUE)
3314 op->contr->own_title[0] = '\0'; 3273 op->contr->own_title[0] = '\0';
3315 new_draw_info (NDI_UNIQUE | NDI_ALL, 0, NULL, buf); 3274 new_draw_info (NDI_UNIQUE | NDI_ALL, 0, NULL, buf);
3316 check_score (op); 3275 check_score (op);
3276
3317 if (op->contr->ranges[range_golem] != NULL) 3277 if (op->contr->ranges[range_golem])
3318 { 3278 {
3319 remove_friendly_object (op->contr->ranges[range_golem]); 3279 remove_friendly_object (op->contr->ranges[range_golem]);
3320 remove_ob (op->contr->ranges[range_golem]); 3280 op->contr->ranges[range_golem]->destroy ();
3321 free_object (op->contr->ranges[range_golem]);
3322 op->contr->ranges[range_golem] = NULL; 3281 op->contr->ranges[range_golem] = 0;
3323 op->contr->golem_count = 0;
3324 } 3282 }
3283
3325 loot_object (op); /* Remove some of the items for good */ 3284 loot_object (op); /* Remove some of the items for good */
3326 remove_ob (op); 3285 op->remove ();
3327 op->direction = 0; 3286 op->direction = 0;
3328 3287
3329 if (!QUERY_FLAG (op, FLAG_WAS_WIZ) && op->stats.exp) 3288 if (!QUERY_FLAG (op, FLAG_WAS_WIZ) && op->stats.exp)
3330 { 3289 {
3331 delete_character (op->name, 0); 3290 delete_character (op->name, 0);
3356 } 3315 }
3357 3316
3358 play_again (op); 3317 play_again (op);
3359 3318
3360 /* peterm: added to create a corpse at deathsite. */ 3319 /* peterm: added to create a corpse at deathsite. */
3361 tmp = arch_to_object (find_archetype ("corpse_pl")); 3320 tmp = arch_to_object (archetype::find ("corpse_pl"));
3362 sprintf (buf, "%s", &op->name); 3321 sprintf (buf, "%s", &op->name);
3363 tmp->name = tmp->name_pl = buf; 3322 tmp->name = tmp->name_pl = buf;
3364 tmp->level = op->level; 3323 tmp->level = op->level;
3365 tmp->x = x; 3324 tmp->x = x;
3366 tmp->y = y; 3325 tmp->y = y;
3384 for (tmp = op->inv; tmp != NULL; tmp = next) 3343 for (tmp = op->inv; tmp != NULL; tmp = next)
3385 { 3344 {
3386 next = tmp->below; 3345 next = tmp->below;
3387 if (tmp->type == EXPERIENCE || tmp->invisible) 3346 if (tmp->type == EXPERIENCE || tmp->invisible)
3388 continue; 3347 continue;
3389 remove_ob (tmp); 3348 tmp->remove ();
3390 tmp->x = op->x, tmp->y = op->y; 3349 tmp->x = op->x, tmp->y = op->y;
3391 if (tmp->type == CONTAINER) 3350 if (tmp->type == CONTAINER)
3392 { /* empty container to ground */ 3351 { /* empty container to ground */
3393 loot_object (tmp); 3352 loot_object (tmp);
3394 } 3353 }
3395 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)))
3396 { 3355 {
3397 if (tmp->nrof > 1) 3356 if (tmp->nrof > 1)
3398 { 3357 {
3399 tmp2 = get_split_ob (tmp, 1 + RANDOM () % (tmp->nrof - 1)); 3358 tmp2 = get_split_ob (tmp, 1 + RANDOM () % (tmp->nrof - 1));
3400 free_object (tmp2); 3359 tmp2->destroy ();
3401 insert_ob_in_map (tmp, op->map, NULL, 0); 3360 insert_ob_in_map (tmp, op->map, NULL, 0);
3402 } 3361 }
3403 else 3362 else
3404 free_object (tmp); 3363 tmp->destroy ();
3405 } 3364 }
3406 else 3365 else
3407 insert_ob_in_map (tmp, op->map, NULL, 0); 3366 insert_ob_in_map (tmp, op->map, NULL, 0);
3408 } 3367 }
3409} 3368}
3474 if (op->type == PLAYER) 3433 if (op->type == PLAYER)
3475 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);
3476 3435
3477 cast_spell (op, throw_ob, dir, spob, NULL); 3436 cast_spell (op, throw_ob, dir, spob, NULL);
3478 3437
3479 if (!QUERY_FLAG (throw_ob, FLAG_REMOVED)) 3438 throw_ob->destroy ();
3480 remove_ob (throw_ob);
3481 free_object (throw_ob);
3482} 3439}
3483 3440
3484void 3441void
3485make_visible (object *op) 3442make_visible (object *op)
3486{ 3443{
3602int 3559int
3603stand_near_hostile (object *who) 3560stand_near_hostile (object *who)
3604{ 3561{
3605 object *tmp = NULL; 3562 object *tmp = NULL;
3606 int i, friendly = 0, player = 0, mflags; 3563 int i, friendly = 0, player = 0, mflags;
3607 mapstruct *m; 3564 maptile *m;
3608 sint16 x, y; 3565 sint16 x, y;
3609 3566
3610 if (!who) 3567 if (!who)
3611 return 0; 3568 return 0;
3612 3569

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines