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.27 by root, Wed Sep 27 00:36:09 2006 UTC vs.
Revision 1.44 by root, Sat Dec 16 03:21:08 2006 UTC

20 20
21 The author can be reached via e-mail to <crossfire@schmorp.de> 21 The author can be reached via e-mail to <crossfire@schmorp.de>
22*/ 22*/
23 23
24#include <global.h> 24#include <global.h>
25#ifndef WIN32 /* ---win32 remove headers */
26# include <pwd.h> 25#include <pwd.h>
27#endif
28#ifndef __CEXTRACT__
29# include <sproto.h> 26#include <sproto.h>
30#endif
31#include <sounds.h> 27#include <sounds.h>
32#include <living.h> 28#include <living.h>
33#include <object.h> 29#include <object.h>
34#include <spells.h> 30#include <spells.h>
35#include <skills.h> 31#include <skills.h>
36#include <newclient.h>
37 32
38#ifdef COZY_SERVER 33#ifdef COZY_SERVER
39extern int same_party (partylist *a, partylist *b); 34extern int same_party (partylist *a, partylist *b);
40#endif 35#endif
41 36
87 int comp; 82 int comp;
88 int size; 83 int size;
89 84
90 sprintf (buf, "%s/%s", settings.confdir, settings.motd); 85 sprintf (buf, "%s/%s", settings.confdir, settings.motd);
91 if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL) 86 if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL)
92 {
93 return; 87 return;
94 } 88
95 motd[0] = '\0'; 89 motd[0] = '\0';
96 size = 0; 90 size = 0;
91
97 while (fgets (buf, MAX_BUF, fp) != NULL) 92 while (fgets (buf, MAX_BUF, fp) != NULL)
98 { 93 {
99 if (*buf == '#') 94 if (*buf == '#')
100 continue; 95 continue;
96
101 strncat (motd + size, buf, HUGE_BUF - size); 97 strncat (motd + size, buf, HUGE_BUF - size);
102 size += strlen (buf); 98 size += strlen (buf);
103 } 99 }
100
104 draw_ext_info (NDI_UNIQUE | NDI_GREEN, 0, op, MSG_TYPE_MOTD, MSG_SUBTYPE_NONE, motd, NULL); 101 draw_ext_info (NDI_UNIQUE | NDI_GREEN, 0, op, MSG_TYPE_MOTD, MSG_SUBTYPE_NONE, motd, NULL);
105 close_and_delete (fp, comp); 102 close_and_delete (fp, comp);
106} 103}
107 104
108void 105void
114 int comp; 111 int comp;
115 int size; 112 int size;
116 113
117 sprintf (buf, "%s/%s", settings.confdir, settings.rules); 114 sprintf (buf, "%s/%s", settings.confdir, settings.rules);
118 if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL) 115 if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL)
119 {
120 return; 116 return;
121 } 117
122 rules[0] = '\0'; 118 rules[0] = '\0';
123 size = 0; 119 size = 0;
120
124 while (fgets (buf, MAX_BUF, fp) != NULL) 121 while (fgets (buf, MAX_BUF, fp) != NULL)
125 { 122 {
126 if (*buf == '#') 123 if (*buf == '#')
127 continue; 124 continue;
125
128 if (size + strlen (buf) >= HUGE_BUF) 126 if (size + strlen (buf) >= HUGE_BUF)
129 { 127 {
130 LOG (llevDebug, "Warning, rules size is > %d bytes.\n", HUGE_BUF); 128 LOG (llevDebug, "Warning, rules size is > %d bytes.\n", HUGE_BUF);
131 break; 129 break;
132 } 130 }
131
133 strncat (rules + size, buf, HUGE_BUF - size); 132 strncat (rules + size, buf, HUGE_BUF - size);
134 size += strlen (buf); 133 size += strlen (buf);
135 } 134 }
135
136 draw_ext_info (NDI_UNIQUE | NDI_GREEN, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_RULES, rules, NULL); 136 draw_ext_info (NDI_UNIQUE | NDI_GREEN, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_RULES, rules, NULL);
137 close_and_delete (fp, comp); 137 close_and_delete (fp, comp);
138} 138}
139 139
140void 140void
148 int size; 148 int size;
149 149
150 sprintf (buf, "%s/%s", settings.confdir, settings.news); 150 sprintf (buf, "%s/%s", settings.confdir, settings.news);
151 if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL) 151 if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL)
152 return; 152 return;
153
153 news[0] = '\0'; 154 news[0] = '\0';
154 subject[0] = '\0'; 155 subject[0] = '\0';
155 size = 0; 156 size = 0;
157
156 while (fgets (buf, MAX_BUF, fp) != NULL) 158 while (fgets (buf, MAX_BUF, fp) != NULL)
157 { 159 {
158 if (*buf == '#') 160 if (*buf == '#')
159 continue; 161 continue;
162
160 if (*buf == '%') 163 if (*buf == '%')
161 { /* send one news */ 164 { /* send one news */
162 if (size > 0) 165 if (size > 0)
163 draw_ext_info_format (NDI_UNIQUE | NDI_GREEN, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_NEWS, "INFORMATION: %s\n%s", "%s\n%s", subject, news); /*send previously read news */ 166 draw_ext_info_format (NDI_UNIQUE | NDI_GREEN, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_NEWS, "INFORMATION: %s\n%s", "%s\n%s", subject, news); /*send previously read news */
164 strcpy (subject, buf + 1); 167 strcpy (subject, buf + 1);
191 return 0; 194 return 0;
192 195
193 for (; *cp != '\0'; cp++) 196 for (; *cp != '\0'; cp++)
194 if (!((*cp >= 'a' && *cp <= 'z') || (*cp >= 'A' && *cp <= 'Z')) && *cp != '-' && *cp != '_') 197 if (!((*cp >= 'a' && *cp <= 'z') || (*cp >= 'A' && *cp <= 'Z')) && *cp != '-' && *cp != '_')
195 return 0; 198 return 0;
199
196 return 1; 200 return 1;
197} 201}
198 202
199/* This no longer sets the player map. Also, it now updates 203/* This no longer sets the player map. Also, it now updates
200 * all the pointers so the caller doesn't need to do that. 204 * all the pointers so the caller doesn't need to do that.
208 * the one that is passed. 212 * the one that is passed.
209 */ 213 */
210static player * 214static player *
211get_player (player *p) 215get_player (player *p)
212{ 216{
213 object *op = arch_to_object (get_player_archetype (NULL)); 217 object *op = arch_to_object (get_player_archetype (0));
214 int i; 218 int i;
215
216 if (!p)
217 {
218 p = new player;
219
220 /* This adds the player in the linked list. There is extra
221 * complexity here because we want to add the new player at the
222 * end of the list - there is in fact no compelling reason that
223 * that needs to be done except for things like output of
224 * 'who'.
225 */
226 player *tmp = first_player;
227
228 while (tmp != NULL && tmp->next != NULL)
229 tmp = tmp->next;
230 if (tmp != NULL)
231 tmp->next = p;
232 else
233 first_player = p;
234
235 p->next = NULL;
236 }
237 219
238 /* Clears basically the entire player structure except 220 /* Clears basically the entire player structure except
239 * for next and socket. 221 * for next and socket.
240 */ 222 */
241 p->clear (); 223 p->clear ();
260 op->speed_left = 0.5; 242 op->speed_left = 0.5;
261 op->speed = 1.0; 243 op->speed = 1.0;
262 op->direction = 5; /* So player faces south */ 244 op->direction = 5; /* So player faces south */
263 op->stats.wc = 2; 245 op->stats.wc = 2;
264 op->run_away = 25; /* Then we panick... */ 246 op->run_away = 25; /* Then we panick... */
247
248 {
249 int oldmon = p->socket->monitor_spells; // what a hack
265 p->socket.monitor_spells = 0; /* Needed because esrv_update_spells( ) gets called by roll_stats */ 250 p->socket->monitor_spells = 0; /* Needed because esrv_update_spells( ) gets called by roll_stats */
266
267 roll_stats (op); 251 roll_stats (op);
252 p->socket->monitor_spells = oldmon;
253 }
268 p->state = ST_ROLL_STAT; 254 p->state = ST_ROLL_STAT;
269 clear_los (op); 255 clear_los (op);
270 256
271 p->gen_sp_armour = 10; 257 p->gen_sp_armour = 10;
272 p->last_speed = -1; 258 p->last_speed = -1;
294 for (i = 0; i < NUM_SKILLS; i++) 280 for (i = 0; i < NUM_SKILLS; i++)
295 { 281 {
296 p->last_skill_exp[i] = -1; 282 p->last_skill_exp[i] = -1;
297 p->last_skill_ob[i] = NULL; 283 p->last_skill_ob[i] = NULL;
298 } 284 }
285
299 for (i = 0; i < NROFATTACKS; i++) 286 for (i = 0; i < NROFATTACKS; i++)
300 {
301 p->last_resist[i] = -1; 287 p->last_resist[i] = -1;
302 } 288
303 p->last_stats.exp = -1; 289 p->last_stats.exp = -1;
304 p->last_weight = (uint32) - 1; 290 p->last_weight = (uint32) - 1;
305 291
306 p->socket.update_look = 0; 292 p->socket->update_look = 0;
307 p->socket.look_position = 0; 293 p->socket->look_position = 0;
294
308 return p; 295 return p;
309} 296}
310 297
311/* This loads the first map an puts the player on it. */ 298/* This loads the first map an puts the player on it. */
312static void 299static void
322 * All we can really get in this is some settings like host and display 309 * All we can really get in this is some settings like host and display
323 * mode. 310 * mode.
324 */ 311 */
325 312
326int 313int
327add_player (NewSocket * ns) 314add_player (client *ns)
328{ 315{
329 player *p; 316 player *p = new player;
330 317
331 p = get_player (NULL);
332 p->socket = *ns; 318 p->socket = ns;
333 p->socket.faces_sent = (uint8 *) malloc (p->socket.faces_sent_len * sizeof (*p->socket.faces_sent)); 319 ns->pl = p;
334 320
335 if (p->socket.faces_sent == NULL) 321 p->next = first_player;
336 fatal (OUT_OF_MEMORY); 322 first_player = p;
337 323
338 memcpy (p->socket.faces_sent, ns->faces_sent, p->socket.faces_sent_len * sizeof (*p->socket.faces_sent)); 324 p = get_player (p);
339 /* Needed because the socket we just copied over needs to be cleared. 325
340 * Note that this can result in a client reset if there is partial data
341 * on the uncoming socket.
342 */
343 p->socket.inbuf.len = 0;
344 set_first_map (p->ob); 326 set_first_map (p->ob);
345 327
346 CLEAR_FLAG (p->ob, FLAG_FRIENDLY); 328 CLEAR_FLAG (p->ob, FLAG_FRIENDLY);
347 add_friendly_object (p->ob); 329 add_friendly_object (p->ob);
348 send_rules (p->ob); 330 send_rules (p->ob);
646 (op->type == ARMOUR || op->type == BOOTS || 628 (op->type == ARMOUR || op->type == BOOTS ||
647 op->type == CLOAK || op->type == HELMET || 629 op->type == CLOAK || op->type == HELMET ||
648 op->type == SHIELD || op->type == GLOVES || 630 op->type == SHIELD || op->type == GLOVES ||
649 op->type == BRACERS || op->type == GIRDLE)) || (!QUERY_FLAG (pl, FLAG_USE_WEAPON) && op->type == WEAPON)) 631 op->type == BRACERS || op->type == GIRDLE)) || (!QUERY_FLAG (pl, FLAG_USE_WEAPON) && op->type == WEAPON))
650 { 632 {
651 remove_ob (op); 633 op->destroy ();
652 free_object (op);
653 continue; 634 continue;
654 } 635 }
655 } 636 }
656 637
657 /* This really needs to be better - we should really give 638 /* This really needs to be better - we should really give
668 if (tmp->type == op->type && tmp->name == op->name) 649 if (tmp->type == op->type && tmp->name == op->name)
669 break; 650 break;
670 651
671 if (tmp) 652 if (tmp)
672 { 653 {
673 remove_ob (op); 654 op->destroy ();
674 free_object (op);
675 LOG (llevError, "give_initial_items: Removing duplicate object %s\n", &tmp->name); 655 LOG (llevError, "give_initial_items: Removing duplicate object %s\n", &tmp->name);
676 continue; 656 continue;
677 } 657 }
658
678 if (op->nrof > 1) 659 if (op->nrof > 1)
679 op->nrof = 1; 660 op->nrof = 1;
680 } 661 }
681 662
682 if (op->type == SPELLBOOK && op->inv) 663 if (op->type == SPELLBOOK && op->inv)
694 CLEAR_FLAG (op, FLAG_CURSED); 675 CLEAR_FLAG (op, FLAG_CURSED);
695 CLEAR_FLAG (op, FLAG_DAMNED); 676 CLEAR_FLAG (op, FLAG_DAMNED);
696 } 677 }
697 if (op->type == SPELL) 678 if (op->type == SPELL)
698 { 679 {
699 remove_ob (op); 680 op->destroy ();
700 free_object (op);
701 continue; 681 continue;
702 } 682 }
703 else if (op->type == SKILL) 683 else if (op->type == SKILL)
704 { 684 {
705 SET_FLAG (op, FLAG_CAN_USE_SKILL); 685 SET_FLAG (op, FLAG_CAN_USE_SKILL);
718void 698void
719get_name (object *op) 699get_name (object *op)
720{ 700{
721 op->contr->write_buf[0] = '\0'; 701 op->contr->write_buf[0] = '\0';
722 op->contr->state = ST_GET_NAME; 702 op->contr->state = ST_GET_NAME;
723 send_query (&op->contr->socket, 0, "What is your name?\n:"); 703 send_query (op->contr->socket, 0, "What is your name?\n:");
724} 704}
725 705
726void 706void
727get_password (object *op) 707get_password (object *op)
728{ 708{
729 op->contr->write_buf[0] = '\0'; 709 op->contr->write_buf[0] = '\0';
730 op->contr->state = ST_GET_PASSWORD; 710 op->contr->state = ST_GET_PASSWORD;
731 send_query (&op->contr->socket, CS_QUERY_HIDEINPUT, "What is your password?\n:"); 711 send_query (op->contr->socket, CS_QUERY_HIDEINPUT, "What is your password?\n:");
732} 712}
733 713
734void 714void
735play_again (object *op) 715play_again (object *op)
736{ 716{
737 op->contr->state = ST_PLAY_AGAIN; 717 op->contr->state = ST_PLAY_AGAIN;
738 op->chosen_skill = NULL; 718 op->chosen_skill = NULL;
739 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "Do you want to play again (a/q)?"); 719 send_query (op->contr->socket, CS_QUERY_SINGLECHAR, "Do you want to play again (a/q)?");
740 /* a bit of a hack, but there are various places early in th 720 /* a bit of a hack, but there are various places early in th
741 * player creation process that a user can quit (eg, roll 721 * player creation process that a user can quit (eg, roll
742 * stats) that isn't removing the player. Taking a quick 722 * stats) that isn't removing the player. Taking a quick
743 * look, there are many places that call play_again without 723 * look, there are many places that call play_again without
744 * removing the player - it probably makes more sense 724 * removing the player - it probably makes more sense
745 * to leave it to play_again to remove the object in all 725 * to leave it to play_again to remove the object in all
746 * cases. 726 * cases.
747 */ 727 */
748 if (!QUERY_FLAG (op, FLAG_REMOVED)) 728 if (!QUERY_FLAG (op, FLAG_REMOVED))
749 remove_ob (op); 729 op->remove ();
750 /* Need to set this to null - otherwise, it could point to garbage, 730 /* Need to set this to null - otherwise, it could point to garbage,
751 * and draw() doesn't check to see if the player is removed, only if 731 * and draw() doesn't check to see if the player is removed, only if
752 * the map is null or not swapped out. 732 * the map is null or not swapped out.
753 */ 733 */
754 op->map = NULL; 734 op->map = NULL;
793confirm_password (object *op) 773confirm_password (object *op)
794{ 774{
795 775
796 op->contr->write_buf[0] = '\0'; 776 op->contr->write_buf[0] = '\0';
797 op->contr->state = ST_CONFIRM_PASSWORD; 777 op->contr->state = ST_CONFIRM_PASSWORD;
798 send_query (&op->contr->socket, CS_QUERY_HIDEINPUT, "Please type your password again.\n:"); 778 send_query (op->contr->socket, CS_QUERY_HIDEINPUT, "Please type your password again.\n:");
799} 779}
800 780
801void 781void
802get_party_password (object *op, partylist *party) 782get_party_password (object *op, partylist *party)
803{ 783{
807 return; 787 return;
808 } 788 }
809 op->contr->write_buf[0] = '\0'; 789 op->contr->write_buf[0] = '\0';
810 op->contr->state = ST_GET_PARTY_PASSWORD; 790 op->contr->state = ST_GET_PARTY_PASSWORD;
811 op->contr->party_to_join = party; 791 op->contr->party_to_join = party;
812 send_query (&op->contr->socket, CS_QUERY_HIDEINPUT, "What is the password?\n:"); 792 send_query (op->contr->socket, CS_QUERY_HIDEINPUT, "What is the password?\n:");
813} 793}
814 794
815 795
816/* This rolls four 1-6 rolls and sums the best 3 of the 4. */ 796/* This rolls four 1-6 rolls and sums the best 3 of the 4. */
817int 797int
914 894
915void 895void
916Roll_Again (object *op) 896Roll_Again (object *op)
917{ 897{
918 esrv_new_player (op->contr, 0); 898 esrv_new_player (op->contr, 0);
919 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, 899 send_query (op->contr->socket, CS_QUERY_SINGLECHAR,
920 "[y] to roll new stats [n] to use stats\n[1-7] [1-7] to swap stats.\nRoll again (y/n/1-7)? "); 900 "[y] to roll new stats [n] to use stats\n[1-7] [1-7] to swap stats.\nRoll again (y/n/1-7)? ");
921} 901}
922 902
923void 903void
924Swap_Stat (object *op, int Swap_Second) 904Swap_Stat (object *op, int Swap_Second)
991 new_draw_info (NDI_UNIQUE, 0, op, buf); 971 new_draw_info (NDI_UNIQUE, 0, op, buf);
992 } 972 }
993 else 973 else
994 Swap_Stat (op, stat_trans[keynum]); 974 Swap_Stat (op, stat_trans[keynum]);
995 975
996 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, ""); 976 send_query (op->contr->socket, CS_QUERY_SINGLECHAR, "");
997 return 1; 977 return 1;
998 } 978 }
999 switch (key) 979 switch (key)
1000 { 980 {
1001 case 'n': 981 case 'n':
1015 enter_exit (op, NULL); 995 enter_exit (op, NULL);
1016#endif 996#endif
1017 SET_ANIMATION (op, 2); /* So player faces south */ 997 SET_ANIMATION (op, 2); /* So player faces south */
1018 /* Enter exit adds a player otherwise */ 998 /* Enter exit adds a player otherwise */
1019 add_statbonus (op); 999 add_statbonus (op);
1020 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, 1000 send_query (op->contr->socket, CS_QUERY_SINGLECHAR,
1021 "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n"); 1001 "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n");
1022 op->contr->state = ST_CHANGE_CLASS; 1002 op->contr->state = ST_CHANGE_CLASS;
1023 if (op->msg) 1003 if (op->msg)
1024 new_draw_info (NDI_BLUE, 0, op, op->msg); 1004 new_draw_info (NDI_BLUE, 0, op, op->msg);
1025 return 0; 1005 return 0;
1026 } 1006 }
1027 case 'y': 1007 case 'y':
1028 case 'Y': 1008 case 'Y':
1029 roll_stats (op); 1009 roll_stats (op);
1030 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, ""); 1010 send_query (op->contr->socket, CS_QUERY_SINGLECHAR, "");
1031 return 1; 1011 return 1;
1032 1012
1033 case 'q': 1013 case 'q':
1034 case 'Q': 1014 case 'Q':
1035 play_again (op); 1015 play_again (op);
1036 return 1; 1016 return 1;
1037 1017
1038 default: 1018 default:
1039 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "Yes, No, Quit or 1-6. Roll again?"); 1019 send_query (op->contr->socket, CS_QUERY_SINGLECHAR, "Yes, No, Quit or 1-6. Roll again?");
1040 return 0; 1020 return 0;
1041 } 1021 }
1042 return 0; 1022 return 0;
1043} 1023}
1044 1024
1054{ 1034{
1055 int tmp_loop; 1035 int tmp_loop;
1056 1036
1057 if (key == 'q' || key == 'Q') 1037 if (key == 'q' || key == 'Q')
1058 { 1038 {
1059 remove_ob (op); 1039 op->remove ();
1060 play_again (op); 1040 play_again (op);
1061 return 0; 1041 return 0;
1062 } 1042 }
1063 if (key == 'd' || key == 'D') 1043 if (key == 'd' || key == 'D')
1064 { 1044 {
1065 char buf[MAX_BUF]; 1045 char buf[MAX_BUF];
1066 1046
1067 /* this must before then initial items are given */ 1047 /* this must before then initial items are given */
1068 esrv_new_player (op->contr, op->weight + op->carrying); 1048 esrv_new_player (op->contr, op->weight + op->carrying);
1049
1069 create_treasure (find_treasurelist ("starting_wealth"), op, 0, 0, 0); 1050 treasurelist *tl = find_treasurelist ("starting_wealth");
1051 if (tl)
1052 create_treasure (tl, op, 0, 0, 0);
1070 1053
1071 INVOKE_PLAYER (BIRTH, op->contr); 1054 INVOKE_PLAYER (BIRTH, op->contr);
1072 INVOKE_PLAYER (LOGIN, op->contr); 1055 INVOKE_PLAYER (LOGIN, op->contr);
1073 1056
1074 op->contr->state = ST_PLAYING; 1057 op->contr->state = ST_PLAYING;
1099 { 1082 {
1100 object *tmp; 1083 object *tmp;
1101 char mapname[MAX_BUF]; 1084 char mapname[MAX_BUF];
1102 1085
1103 snprintf (mapname, MAX_BUF - 1, "%s/%s", first_map_ext_path, &op->arch->name); 1086 snprintf (mapname, MAX_BUF - 1, "%s/%s", first_map_ext_path, &op->arch->name);
1104 tmp = get_object (); 1087 tmp = object::create ();
1105 EXIT_PATH (tmp) = mapname; 1088 EXIT_PATH (tmp) = mapname;
1106 EXIT_X (tmp) = op->x; 1089 EXIT_X (tmp) = op->x;
1107 EXIT_Y (tmp) = op->y; 1090 EXIT_Y (tmp) = op->y;
1108 enter_exit (op, tmp); /* we don't really care if it succeeded; 1091 enter_exit (op, tmp); /* we don't really care if it succeeded;
1109 * if the map isn't there, then stay on the 1092 * if the map isn't there, then stay on the
1110 * default initial map */ 1093 * default initial map */
1111 free_object (tmp); 1094 tmp->destroy ();
1112 } 1095 }
1113 else 1096 else
1114 { 1097 {
1115 LOG (llevDebug, "first_map_ext_path not set\n"); 1098 LOG (llevDebug, "first_map_ext_path not set\n");
1116 } 1099 }
1126 { 1109 {
1127 shstr name = op->name; 1110 shstr name = op->name;
1128 int x = op->x, y = op->y; 1111 int x = op->x, y = op->y;
1129 1112
1130 remove_statbonus (op); 1113 remove_statbonus (op);
1131 remove_ob (op); 1114 op->remove ();
1132 op->arch = get_player_archetype (op->arch); 1115 op->arch = get_player_archetype (op->arch);
1133 copy_object (&op->arch->clone, op); 1116 op->arch->clone.copy_to (op);
1134 op->instantiate (); 1117 op->instantiate ();
1135 op->stats = op->contr->orig_stats; 1118 op->stats = op->contr->orig_stats;
1136 op->name = op->name_pl = name; 1119 op->name = op->name_pl = name;
1137 op->x = x; 1120 op->x = x;
1138 op->y = y; 1121 op->y = y;
1151 op->stats.grace = 0; 1134 op->stats.grace = 0;
1152 1135
1153 if (op->msg) 1136 if (op->msg)
1154 new_draw_info (NDI_BLUE, 0, op, op->msg); 1137 new_draw_info (NDI_BLUE, 0, op, op->msg);
1155 1138
1156 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "Press any key for the next race.\nPress `d' to play this race.\n"); 1139 send_query (op->contr->socket, CS_QUERY_SINGLECHAR, "Press any key for the next race.\nPress `d' to play this race.\n");
1157 return 0; 1140 return 0;
1158} 1141}
1159 1142
1160int 1143int
1161key_confirm_quit (object *op, char key) 1144key_confirm_quit (object *op, char key)
1426 /* question: don't pick up known-poisonous stuff? */ 1409 /* question: don't pick up known-poisonous stuff? */
1427 if (op->contr->mode & PU_FOOD) 1410 if (op->contr->mode & PU_FOOD)
1428 if (tmp->type == FOOD) 1411 if (tmp->type == FOOD)
1429 { 1412 {
1430 pick_up (op, tmp); 1413 pick_up (op, tmp);
1431 if (0)
1432 fprintf (stderr, "FOOD\n");
1433 continue; 1414 continue;
1434 } 1415 }
1416
1435 if (op->contr->mode & PU_DRINK) 1417 if (op->contr->mode & PU_DRINK)
1436 if (tmp->type == DRINK || (tmp->type == POISON && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))) 1418 if (tmp->type == DRINK || (tmp->type == POISON && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)))
1437 { 1419 {
1438 pick_up (op, tmp); 1420 pick_up (op, tmp);
1439 if (0)
1440 fprintf (stderr, "DRINK\n");
1441 continue; 1421 continue;
1442 } 1422 }
1443 1423
1444 if (op->contr->mode & PU_POTION) 1424 if (op->contr->mode & PU_POTION)
1445 if (tmp->type == POTION) 1425 if (tmp->type == POTION)
1446 { 1426 {
1447 pick_up (op, tmp); 1427 pick_up (op, tmp);
1448 if (0)
1449 fprintf (stderr, "POTION\n");
1450 continue; 1428 continue;
1451 } 1429 }
1452 1430
1453 /* spellbooks, skillscrolls and normal books/scrolls */ 1431 /* spellbooks, skillscrolls and normal books/scrolls */
1454 if (op->contr->mode & PU_SPELLBOOK) 1432 if (op->contr->mode & PU_SPELLBOOK)
1455 if (tmp->type == SPELLBOOK) 1433 if (tmp->type == SPELLBOOK)
1456 { 1434 {
1457 pick_up (op, tmp); 1435 pick_up (op, tmp);
1458 if (0)
1459 fprintf (stderr, "SPELLBOOK\n");
1460 continue; 1436 continue;
1461 } 1437 }
1438
1462 if (op->contr->mode & PU_SKILLSCROLL) 1439 if (op->contr->mode & PU_SKILLSCROLL)
1463 if (tmp->type == SKILLSCROLL) 1440 if (tmp->type == SKILLSCROLL)
1464 { 1441 {
1465 pick_up (op, tmp); 1442 pick_up (op, tmp);
1466 if (0)
1467 fprintf (stderr, "SKILLSCROLL\n");
1468 continue; 1443 continue;
1469 } 1444 }
1445
1470 if (op->contr->mode & PU_READABLES) 1446 if (op->contr->mode & PU_READABLES)
1471 if (tmp->type == BOOK || tmp->type == SCROLL) 1447 if (tmp->type == BOOK || tmp->type == SCROLL)
1472 { 1448 {
1473 pick_up (op, tmp); 1449 pick_up (op, tmp);
1474 if (0)
1475 fprintf (stderr, "READABLES\n");
1476 continue; 1450 continue;
1477 } 1451 }
1478 1452
1479 /* wands/staves/rods/horns */ 1453 /* wands/staves/rods/horns */
1480 if (op->contr->mode & PU_MAGIC_DEVICE) 1454 if (op->contr->mode & PU_MAGIC_DEVICE)
1481 if (tmp->type == WAND || tmp->type == ROD || tmp->type == HORN) 1455 if (tmp->type == WAND || tmp->type == ROD || tmp->type == HORN)
1482 { 1456 {
1483 pick_up (op, tmp); 1457 pick_up (op, tmp);
1484 if (0)
1485 fprintf (stderr, "MAGIC_DEVICE\n");
1486 continue; 1458 continue;
1487 } 1459 }
1488 1460
1489 /* pick up all magical items */ 1461 /* pick up all magical items */
1490 if (op->contr->mode & PU_MAGICAL) 1462 if (op->contr->mode & PU_MAGICAL)
1491 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)) 1463 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))
1492 { 1464 {
1493 pick_up (op, tmp); 1465 pick_up (op, tmp);
1494 if (0)
1495 fprintf (stderr, "MAGICAL\n");
1496 continue; 1466 continue;
1497 } 1467 }
1498 1468
1499 if (op->contr->mode & PU_VALUABLES) 1469 if (op->contr->mode & PU_VALUABLES)
1500 { 1470 {
1501 if (tmp->type == MONEY || tmp->type == GEM) 1471 if (tmp->type == MONEY || tmp->type == GEM)
1502 { 1472 {
1503 pick_up (op, tmp); 1473 pick_up (op, tmp);
1504 if (0)
1505 fprintf (stderr, "MONEY/GEM\n");
1506 continue; 1474 continue;
1507 } 1475 }
1508 } 1476 }
1509 1477
1510 /* rings & amulets - talismans seems to be typed AMULET */ 1478 /* rings & amulets - talismans seems to be typed AMULET */
1511 if (op->contr->mode & PU_JEWELS) 1479 if (op->contr->mode & PU_JEWELS)
1512 if (tmp->type == RING || tmp->type == AMULET) 1480 if (tmp->type == RING || tmp->type == AMULET)
1513 { 1481 {
1514 pick_up (op, tmp); 1482 pick_up (op, tmp);
1483 continue;
1515 if (0) 1484 }
1516 fprintf (stderr, "JEWELS\n"); 1485
1486 /* we don't forget dragon food */
1487 if (op->contr->mode & PU_FLESH)
1488 if (tmp->type == FLESH)
1489 {
1490 pick_up (op, tmp);
1517 continue; 1491 continue;
1518 } 1492 }
1519 1493
1520 /* bows and arrows. Bows are good for selling! */ 1494 /* bows and arrows. Bows are good for selling! */
1521 if (op->contr->mode & PU_BOW) 1495 if (op->contr->mode & PU_BOW)
1522 if (tmp->type == BOW) 1496 if (tmp->type == BOW)
1523 { 1497 {
1524 pick_up (op, tmp); 1498 pick_up (op, tmp);
1525 if (0)
1526 fprintf (stderr, "BOW\n");
1527 continue; 1499 continue;
1528 } 1500 }
1501
1529 if (op->contr->mode & PU_ARROW) 1502 if (op->contr->mode & PU_ARROW)
1530 if (tmp->type == ARROW) 1503 if (tmp->type == ARROW)
1531 { 1504 {
1532 pick_up (op, tmp); 1505 pick_up (op, tmp);
1533 if (0)
1534 fprintf (stderr, "ARROW\n");
1535 continue; 1506 continue;
1536 } 1507 }
1537 1508
1538 /* all kinds of armor etc. */ 1509 /* all kinds of armor etc. */
1539 if (op->contr->mode & PU_ARMOUR) 1510 if (op->contr->mode & PU_ARMOUR)
1540 if (tmp->type == ARMOUR) 1511 if (tmp->type == ARMOUR)
1541 { 1512 {
1542 pick_up (op, tmp); 1513 pick_up (op, tmp);
1543 if (0)
1544 fprintf (stderr, "ARMOUR\n");
1545 continue; 1514 continue;
1546 } 1515 }
1516
1547 if (op->contr->mode & PU_HELMET) 1517 if (op->contr->mode & PU_HELMET)
1548 if (tmp->type == HELMET) 1518 if (tmp->type == HELMET)
1549 { 1519 {
1550 pick_up (op, tmp); 1520 pick_up (op, tmp);
1551 if (0)
1552 fprintf (stderr, "HELMET\n");
1553 continue; 1521 continue;
1554 } 1522 }
1523
1555 if (op->contr->mode & PU_SHIELD) 1524 if (op->contr->mode & PU_SHIELD)
1556 if (tmp->type == SHIELD) 1525 if (tmp->type == SHIELD)
1557 { 1526 {
1558 pick_up (op, tmp); 1527 pick_up (op, tmp);
1559 if (0)
1560 fprintf (stderr, "SHIELD\n");
1561 continue; 1528 continue;
1562 } 1529 }
1530
1563 if (op->contr->mode & PU_BOOTS) 1531 if (op->contr->mode & PU_BOOTS)
1564 if (tmp->type == BOOTS) 1532 if (tmp->type == BOOTS)
1565 { 1533 {
1566 pick_up (op, tmp); 1534 pick_up (op, tmp);
1567 if (0)
1568 fprintf (stderr, "BOOTS\n");
1569 continue; 1535 continue;
1570 } 1536 }
1537
1571 if (op->contr->mode & PU_GLOVES) 1538 if (op->contr->mode & PU_GLOVES)
1572 if (tmp->type == GLOVES) 1539 if (tmp->type == GLOVES)
1573 { 1540 {
1574 pick_up (op, tmp); 1541 pick_up (op, tmp);
1575 if (0)
1576 fprintf (stderr, "GLOVES\n");
1577 continue; 1542 continue;
1578 } 1543 }
1544
1579 if (op->contr->mode & PU_CLOAK) 1545 if (op->contr->mode & PU_CLOAK)
1580 if (tmp->type == CLOAK) 1546 if (tmp->type == CLOAK)
1581 { 1547 {
1582 pick_up (op, tmp); 1548 pick_up (op, tmp);
1583 if (0)
1584 fprintf (stderr, "GLOVES\n");
1585 continue; 1549 continue;
1586 } 1550 }
1587 1551
1588 /* hoping to catch throwing daggers here */ 1552 /* hoping to catch throwing daggers here */
1589 if (op->contr->mode & PU_MISSILEWEAPON) 1553 if (op->contr->mode & PU_MISSILEWEAPON)
1590 if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_IS_THROWN)) 1554 if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_IS_THROWN))
1591 { 1555 {
1592 pick_up (op, tmp); 1556 pick_up (op, tmp);
1593 if (0)
1594 fprintf (stderr, "MISSILEWEAPON\n");
1595 continue; 1557 continue;
1596 } 1558 }
1597 1559
1598 /* careful: chairs and tables are weapons! */ 1560 /* careful: chairs and tables are weapons! */
1599 if (op->contr->mode & PU_ALLWEAPON) 1561 if (op->contr->mode & PU_ALLWEAPON)
1602 { 1564 {
1603 if (strstr (tmp->name, "table") == NULL && strstr (tmp->arch->name, "table") == NULL && 1565 if (strstr (tmp->name, "table") == NULL && strstr (tmp->arch->name, "table") == NULL &&
1604 strstr (tmp->name, "chair") && strstr (tmp->arch->name, "chair") == NULL) 1566 strstr (tmp->name, "chair") && strstr (tmp->arch->name, "chair") == NULL)
1605 { 1567 {
1606 pick_up (op, tmp); 1568 pick_up (op, tmp);
1607 if (0)
1608 fprintf (stderr, "WEAPON\n");
1609 continue; 1569 continue;
1610 } 1570 }
1611 } 1571 }
1572
1612 if (tmp->type == WEAPON && tmp->name == NULL) 1573 if (tmp->type == WEAPON && tmp->name == NULL)
1613 { 1574 {
1614 if (strstr (tmp->arch->name, "table") == NULL && strstr (tmp->arch->name, "chair") == NULL) 1575 if (strstr (tmp->arch->name, "table") == NULL && strstr (tmp->arch->name, "chair") == NULL)
1615 { 1576 {
1616 pick_up (op, tmp); 1577 pick_up (op, tmp);
1617 if (0)
1618 fprintf (stderr, "WEAPON\n");
1619 continue; 1578 continue;
1620 } 1579 }
1621 } 1580 }
1622 } 1581 }
1623 1582
1624 /* misc stuff that's useful */ 1583 /* misc stuff that's useful */
1625 if (op->contr->mode & PU_KEY) 1584 if (op->contr->mode & PU_KEY)
1626 if (tmp->type == KEY || tmp->type == SPECIAL_KEY) 1585 if (tmp->type == KEY || tmp->type == SPECIAL_KEY)
1627 { 1586 {
1628 pick_up (op, tmp); 1587 pick_up (op, tmp);
1629 if (0)
1630 fprintf (stderr, "KEY\n");
1631 continue; 1588 continue;
1632 } 1589 }
1633 1590
1634 /* any of the last 4 bits set means we use the ratio for value 1591 /* any of the last 4 bits set means we use the ratio for value
1635 * pickups */ 1592 * pickups */
1657 continue; 1614 continue;
1658 } 1615 }
1659 } 1616 }
1660 } /* the new pickup model */ 1617 } /* the new pickup model */
1661 } 1618 }
1619
1662 return !stop; 1620 return !stop;
1663} 1621}
1664 1622
1665/* 1623/*
1666 * Find an arrow in the inventory and after that 1624 * Find an arrow in the inventory and after that
1900 } 1858 }
1901 1859
1902 /* this should not happen, but sometimes does */ 1860 /* this should not happen, but sometimes does */
1903 if (arrow->nrof == 0) 1861 if (arrow->nrof == 0)
1904 { 1862 {
1905 remove_ob (arrow); 1863 arrow->destroy ();
1906 free_object (arrow);
1907 return 0; 1864 return 0;
1908 } 1865 }
1909 1866
1910 left = arrow; /* these are arrows left to the player */ 1867 left = arrow; /* these are arrows left to the player */
1911 arrow = get_split_ob (arrow, 1); 1868 arrow = get_split_ob (arrow, 1);
1912 if (arrow == NULL) 1869 if (arrow == NULL)
1913 { 1870 {
1914 new_draw_info_format (NDI_UNIQUE, 0, op, "You have no %s left.", &bow->race); 1871 new_draw_info_format (NDI_UNIQUE, 0, op, "You have no %s left.", &bow->race);
1915 return 0; 1872 return 0;
1916 } 1873 }
1917 set_owner (arrow, op); 1874 arrow->set_owner (op);
1918 arrow->skill = bow->skill; 1875 arrow->skill = bow->skill;
1919 1876
1920 arrow->direction = dir; 1877 arrow->direction = dir;
1921 arrow->x = sx; 1878 arrow->x = sx;
1922 arrow->y = sy; 1879 arrow->y = sy;
1930 SET_ANIMATION (arrow, arrow->direction); 1887 SET_ANIMATION (arrow, arrow->direction);
1931 arrow->stats.sp = arrow->stats.wc; /* save original wc and dam */ 1888 arrow->stats.sp = arrow->stats.wc; /* save original wc and dam */
1932 arrow->stats.hp = arrow->stats.dam; 1889 arrow->stats.hp = arrow->stats.dam;
1933 arrow->stats.grace = arrow->attacktype; 1890 arrow->stats.grace = arrow->attacktype;
1934 if (arrow->slaying != NULL) 1891 if (arrow->slaying != NULL)
1935 arrow->spellarg = strdup_local (arrow->slaying); 1892 arrow->spellarg = strdup (arrow->slaying);
1936 1893
1937 /* Note that this was different for monsters - they got their level 1894 /* Note that this was different for monsters - they got their level
1938 * added to the damage. I think the strength bonus is more proper. 1895 * added to the damage. I think the strength bonus is more proper.
1939 */ 1896 */
1940 1897
2130 case range_misc: 2087 case range_misc:
2131 fire_misc_object (op, dir); 2088 fire_misc_object (op, dir);
2132 return; 2089 return;
2133 2090
2134 case range_golem: /* Control summoned monsters from scrolls */ 2091 case range_golem: /* Control summoned monsters from scrolls */
2135 if (op->contr->ranges[range_golem] == NULL || op->contr->golem_count != op->contr->ranges[range_golem]->count) 2092 if (QUERY_FLAG (op->contr->ranges[range_golem], FLAG_REMOVED))
2136 { 2093 {
2137 op->contr->ranges[range_golem] = NULL; 2094 op->contr->ranges[range_golem] = 0;
2138 op->contr->shoottype = range_none; 2095 op->contr->shoottype = range_none;
2139 op->contr->golem_count = 0;
2140 } 2096 }
2141 else 2097 else
2142 control_golem (op->contr->ranges[range_golem], dir); 2098 control_golem (op->contr->ranges[range_golem], dir);
2143 return; 2099 return;
2144 2100
2390 * player owns it and it is either friendly or unagressive. 2346 * player owns it and it is either friendly or unagressive.
2391 */ 2347 */
2392 if ((op->type == PLAYER) 2348 if ((op->type == PLAYER)
2393#if COZY_SERVER 2349#if COZY_SERVER
2394 && 2350 &&
2395 ((get_owner (mon) && get_owner (mon)->contr 2351 ((mon->owner && mon->owner->contr
2396 && same_party (get_owner (mon)->contr->party, op->contr->party)) || get_owner (mon) == op) 2352 && same_party (mon->owner->contr->party, op->contr->party)) || mon->owner == op)
2397#else 2353#else
2398 && get_owner (mon) == op 2354 && mon->owner == op
2399#endif 2355#endif
2400 && (QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY))) 2356 && (QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY)))
2401 { 2357 {
2402 /* If we're braced, we don't want to switch places with it */ 2358 /* If we're braced, we don't want to switch places with it */
2403 if (op->contr->braced) 2359 if (op->contr->braced)
2590 /* I've been seeing crashes where the golem has been destroyed, but 2546 /* I've been seeing crashes where the golem has been destroyed, but
2591 * the player object still points to the defunct golem. The code that 2547 * the player object still points to the defunct golem. The code that
2592 * destroys the golem looks correct, and it doesn't always happen, so 2548 * destroys the golem looks correct, and it doesn't always happen, so
2593 * put this in a a workaround to clean up the golem pointer. 2549 * put this in a a workaround to clean up the golem pointer.
2594 */ 2550 */
2595 if (op->contr->ranges[range_golem] &&
2596 ((op->contr->golem_count != op->contr->ranges[range_golem]->count) || QUERY_FLAG (op->contr->ranges[range_golem], FLAG_REMOVED))) 2551 if (op->contr->ranges[range_golem] && QUERY_FLAG (op->contr->ranges[range_golem], FLAG_REMOVED))
2597 {
2598 op->contr->ranges[range_golem] = NULL; 2552 op->contr->ranges[range_golem] = 0;
2599 op->contr->golem_count = 0;
2600 }
2601 2553
2602 /* call this here - we also will call this in do_ericserver, but 2554 /* call this here - we also will call this in do_ericserver, but
2603 * the players time has been increased when doericserver has been 2555 * the players time has been increased when doericserver has been
2604 * called, so we recheck it here. 2556 * called, so we recheck it here.
2605 */ 2557 */
2606 HandleClient (&op->contr->socket, op->contr); 2558 op->contr->socket->handle_command ();
2607 if (op->speed_left < 0) 2559 if (op->speed_left < 0)
2608 return 0; 2560 return 0;
2609 2561
2610 if (op->direction && (op->contr->run_on || op->contr->fire_on)) 2562 if (op->direction && (op->contr->run_on || op->contr->fire_on))
2611 { 2563 {
2620 if (op->speed_left > 0) 2572 if (op->speed_left > 0)
2621 return 1; 2573 return 1;
2622 else 2574 else
2623 return 0; 2575 return 0;
2624 } 2576 }
2577
2625 return 0; 2578 return 0;
2626} 2579}
2627 2580
2628int 2581int
2629save_life (object *op) 2582save_life (object *op)
2630{ 2583{
2631 object *tmp;
2632
2633 if (!QUERY_FLAG (op, FLAG_LIFESAVE)) 2584 if (!QUERY_FLAG (op, FLAG_LIFESAVE))
2634 return 0; 2585 return 0;
2635 2586
2636 for (tmp = op->inv; tmp != NULL; tmp = tmp->below) 2587 for (object *tmp = op->inv; tmp; tmp = tmp->below)
2637 if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE)) 2588 if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE))
2638 { 2589 {
2639 play_sound_map (op->map, op->x, op->y, SOUND_OB_EVAPORATE); 2590 play_sound_map (op->map, op->x, op->y, SOUND_OB_EVAPORATE);
2640 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s vibrates violently, then evaporates.", query_name (tmp)); 2591 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s vibrates violently, then evaporates.", query_name (tmp));
2592
2641 if (op->contr) 2593 if (op->contr)
2642 esrv_del_item (op->contr, tmp->count); 2594 esrv_del_item (op->contr, tmp->count);
2643 remove_ob (tmp); 2595
2644 free_object (tmp); 2596 tmp->destroy ();
2645 CLEAR_FLAG (op, FLAG_LIFESAVE); 2597 CLEAR_FLAG (op, FLAG_LIFESAVE);
2598
2646 if (op->stats.hp < 0) 2599 if (op->stats.hp < 0)
2647 op->stats.hp = op->stats.maxhp; 2600 op->stats.hp = op->stats.maxhp;
2601
2648 if (op->stats.food < 0) 2602 if (op->stats.food < 0)
2649 op->stats.food = 999; 2603 op->stats.food = 999;
2604
2650 fix_player (op); 2605 fix_player (op);
2651 return 1; 2606 return 1;
2652 } 2607 }
2608
2653 LOG (llevError, "Error: LIFESAVE set without applied object.\n"); 2609 LOG (llevError, "Error: LIFESAVE set without applied object.\n");
2654 CLEAR_FLAG (op, FLAG_LIFESAVE); 2610 CLEAR_FLAG (op, FLAG_LIFESAVE);
2655 enter_player_savebed (op); /* bring him home. */ 2611 enter_player_savebed (op); /* bring him home. */
2656 return 0; 2612 return 0;
2657} 2613}
2671 next = op->below; /* Make sure we have a good value, in case 2627 next = op->below; /* Make sure we have a good value, in case
2672 * we remove object 'op' 2628 * we remove object 'op'
2673 */ 2629 */
2674 if (QUERY_FLAG (op, FLAG_UNPAID)) 2630 if (QUERY_FLAG (op, FLAG_UNPAID))
2675 { 2631 {
2676 remove_ob (op); 2632 op->remove ();
2677 op->x = env->x; 2633 op->x = env->x;
2678 op->y = env->y; 2634 op->y = env->y;
2679 if (env->type == PLAYER) 2635 if (env->type == PLAYER)
2680 esrv_del_item (env->contr, op->count); 2636 esrv_del_item (env->contr, op->count);
2681 insert_ob_in_map (op, env->map, NULL, 0); 2637 insert_ob_in_map (op, env->map, NULL, 0);
2682 } 2638 }
2683 else if (op->inv) 2639 else if (op->inv)
2684 remove_unpaid_objects (op->inv, env); 2640 remove_unpaid_objects (op->inv, env);
2641
2685 op = next; 2642 op = next;
2686 } 2643 }
2687} 2644}
2688 2645
2689 2646
2704 strcpy (buf2, " R.I.P.\n\n"); 2661 strcpy (buf2, " R.I.P.\n\n");
2705 if (op->type == PLAYER) 2662 if (op->type == PLAYER)
2706 sprintf (buf, "%s the %s\n", &op->name, op->contr->title); 2663 sprintf (buf, "%s the %s\n", &op->name, op->contr->title);
2707 else 2664 else
2708 sprintf (buf, "%s\n", &op->name); 2665 sprintf (buf, "%s\n", &op->name);
2666
2709 strncat (buf2, " ", 20 - strlen (buf) / 2); 2667 strncat (buf2, " ", 20 - strlen (buf) / 2);
2710 strcat (buf2, buf); 2668 strcat (buf2, buf);
2711 if (op->type == PLAYER) 2669 if (op->type == PLAYER)
2712 sprintf (buf, "who was in level %d when killed\n", op->level); 2670 sprintf (buf, "who was in level %d when killed\n", op->level);
2713 else 2671 else
2714 sprintf (buf, "who was in level %d when died.\n\n", op->level); 2672 sprintf (buf, "who was in level %d when died.\n\n", op->level);
2673
2715 strncat (buf2, " ", 20 - strlen (buf) / 2); 2674 strncat (buf2, " ", 20 - strlen (buf) / 2);
2716 strcat (buf2, buf); 2675 strcat (buf2, buf);
2717 if (op->type == PLAYER) 2676 if (op->type == PLAYER)
2718 { 2677 {
2719 sprintf (buf, "by %s.\n\n", op->contr->killer); 2678 sprintf (buf, "by %s.\n\n", op->contr->killer);
2720 strncat (buf2, " ", 21 - strlen (buf) / 2); 2679 strncat (buf2, " ", 21 - strlen (buf) / 2);
2721 strcat (buf2, buf); 2680 strcat (buf2, buf);
2722 } 2681 }
2682
2723 strftime (buf, MAX_BUF, "%b %d %Y\n", localtime (&now)); 2683 strftime (buf, MAX_BUF, "%b %d %Y\n", localtime (&now));
2724 strncat (buf2, " ", 20 - strlen (buf) / 2); 2684 strncat (buf2, " ", 20 - strlen (buf) / 2);
2725 strcat (buf2, buf); 2685 strcat (buf2, buf);
2686
2726 return buf2; 2687 return buf2;
2727} 2688}
2728 2689
2729 2690
2730 2691
2978 /* restore player */ 2939 /* restore player */
2979 at = archetype::find ("poisoning"); 2940 at = archetype::find ("poisoning");
2980 tmp = present_arch_in_ob (at, op); 2941 tmp = present_arch_in_ob (at, op);
2981 if (tmp) 2942 if (tmp)
2982 { 2943 {
2983 remove_ob (tmp); 2944 tmp->destroy ();
2984 free_object (tmp);
2985 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed"); 2945 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed");
2986 } 2946 }
2987 2947
2988 at = archetype::find ("confusion"); 2948 at = archetype::find ("confusion");
2989 tmp = present_arch_in_ob (at, op); 2949 tmp = present_arch_in_ob (at, op);
2990 if (tmp) 2950 if (tmp)
2991 { 2951 {
2992 remove_ob (tmp); 2952 tmp->destroy ();
2993 free_object (tmp);
2994 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer"); 2953 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer");
2995 } 2954 }
2996 2955
2997 cure_disease (op, 0); /* remove any disease */ 2956 cure_disease (op, 0); /* remove any disease */
2998 op->stats.hp = op->stats.maxhp; 2957 op->stats.hp = op->stats.maxhp;
3175 /* determine_god() seems to not work sometimes... why is this? 3134 /* determine_god() seems to not work sometimes... why is this?
3176 Should I be using something else? GD */ 3135 Should I be using something else? GD */
3177 const char *god = determine_god (op); 3136 const char *god = determine_god (op);
3178 3137
3179 if (god && (strcmp (god, "none"))) 3138 if (god && (strcmp (god, "none")))
3180 new_draw_info_format (NDI_UNIQUE, 0, op, "For a brief " "moment you feel the holy presence of %s protecting" " you.", god); 3139 new_draw_info_format (NDI_UNIQUE, 0, op, "For a brief moment you feel the holy presence of %s protecting" " you.", god);
3181 else 3140 else
3182 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you" " feel a holy presence protecting you."); 3141 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you feel a holy presence protecting you.");
3183 } 3142 }
3143#else
3144 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you" " feel a holy presence protecting you from losing yourself completely.");
3184#endif 3145#endif
3185 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you" " feel a holy presence protecting you from losing yourself completely.");
3186 3146
3187 /* Put a gravestone up where the character 'almost' died. List the 3147 /* Put a gravestone up where the character 'almost' died. List the
3188 * exp loss on the stone. 3148 * exp loss on the stone.
3189 */ 3149 */
3190 tmp = arch_to_object (archetype::find ("gravestone")); 3150 tmp = arch_to_object (archetype::find ("gravestone"));
3195 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); 3155 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);
3196 tmp->msg = buf; 3156 tmp->msg = buf;
3197 tmp->x = op->x, tmp->y = op->y; 3157 tmp->x = op->x, tmp->y = op->y;
3198 insert_ob_in_map (tmp, op->map, NULL, 0); 3158 insert_ob_in_map (tmp, op->map, NULL, 0);
3199 3159
3200 /**************************************/ 3160 /**************************************/
3201 /* */ 3161 /* */
3202 /* Subtract the experience points, */ 3162 /* Subtract the experience points, */
3203 /* if we died cause of food, give us */ 3163 /* if we died cause of food, give us */
3204 /* food, and reset HP's... */ 3164 /* food, and reset HP's... */
3205 /* */ 3165 /* */
3206
3207 /**************************************/ 3166 /**************************************/
3208 3167
3209 /* remove any poisoning and confusion the character may be suffering. */ 3168 /* remove any poisoning and confusion the character may be suffering. */
3210 /* restore player */ 3169 /* restore player */
3211 at = archetype::find ("poisoning"); 3170 at = archetype::find ("poisoning");
3212 tmp = present_arch_in_ob (at, op); 3171 tmp = present_arch_in_ob (at, op);
3172
3213 if (tmp) 3173 if (tmp)
3214 { 3174 {
3215 remove_ob (tmp); 3175 tmp->destroy ();
3216 free_object (tmp);
3217 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed"); 3176 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed");
3218 } 3177 }
3219 3178
3220 at = archetype::find ("confusion"); 3179 at = archetype::find ("confusion");
3221 tmp = present_arch_in_ob (at, op); 3180 tmp = present_arch_in_ob (at, op);
3222 if (tmp) 3181 if (tmp)
3223 { 3182 {
3224 remove_ob (tmp); 3183 tmp->destroy ();
3225 free_object (tmp);
3226 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer"); 3184 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer");
3227 } 3185 }
3186
3228 cure_disease (op, 0); /* remove any disease */ 3187 cure_disease (op, 0); /* remove any disease */
3229 3188
3230 /*add_exp(op, (op->stats.exp * -0.20)); */ 3189 /*add_exp(op, (op->stats.exp * -0.20)); */
3231 apply_death_exp_penalty (op); 3190 apply_death_exp_penalty (op);
3232 if (op->stats.food < 100) 3191 if (op->stats.food < 100)
3242 */ 3201 */
3243 3202
3244 if (is_in_shop (op)) 3203 if (is_in_shop (op))
3245 remove_unpaid_objects (op->inv, op); 3204 remove_unpaid_objects (op->inv, op);
3246 3205
3247 /****************************************/ 3206 /****************************************/
3248 /* */ 3207 /* */
3249 /* Move player to his current respawn- */ 3208 /* Move player to his current respawn- */
3250 /* position (usually last savebed) */ 3209 /* position (usually last savebed) */
3251 /* */ 3210 /* */
3252
3253 /****************************************/ 3211 /****************************************/
3254 3212
3255 enter_player_savebed (op); 3213 enter_player_savebed (op);
3256 3214
3257 /* Save the player before inserting the force to reduce 3215 /* Save the player before inserting the force to reduce
3258 * chance of abuse. 3216 * chance of abuse.
3265 * spell effects. So first see if there is a spell effect 3223 * spell effects. So first see if there is a spell effect
3266 * on the space that might harm the player. 3224 * on the space that might harm the player.
3267 */ 3225 */
3268 will_kill_again = 0; 3226 will_kill_again = 0;
3269 for (tmp = get_map_ob (op->map, op->x, op->y); tmp; tmp = tmp->above) 3227 for (tmp = get_map_ob (op->map, op->x, op->y); tmp; tmp = tmp->above)
3270 {
3271 if (tmp->type == SPELL_EFFECT) 3228 if (tmp->type == SPELL_EFFECT)
3272 will_kill_again |= tmp->attacktype; 3229 will_kill_again |= tmp->attacktype;
3273 } 3230
3274 if (will_kill_again) 3231 if (will_kill_again)
3275 { 3232 {
3276 object *force; 3233 object *force;
3277 int at; 3234 int at;
3278 3235
3280 /* 50 ticks should be enough time for the spell to abate */ 3237 /* 50 ticks should be enough time for the spell to abate */
3281 force->speed = 0.1; 3238 force->speed = 0.1;
3282 force->speed_left = -5.0; 3239 force->speed_left = -5.0;
3283 SET_FLAG (force, FLAG_APPLIED); 3240 SET_FLAG (force, FLAG_APPLIED);
3284 for (at = 0; at < NROFATTACKS; at++) 3241 for (at = 0; at < NROFATTACKS; at++)
3285 {
3286 if (will_kill_again & (1 << at)) 3242 if (will_kill_again & (1 << at))
3287 force->resist[at] = 100; 3243 force->resist[at] = 100;
3288 } 3244
3289 insert_ob_in_ob (force, op); 3245 insert_ob_in_ob (force, op);
3290 fix_player (op); 3246 fix_player (op);
3291 3247
3292 } 3248 }
3293 3249
3303 op->contr->party = NULL; 3259 op->contr->party = NULL;
3304 if (settings.set_title == TRUE) 3260 if (settings.set_title == TRUE)
3305 op->contr->own_title[0] = '\0'; 3261 op->contr->own_title[0] = '\0';
3306 new_draw_info (NDI_UNIQUE | NDI_ALL, 0, NULL, buf); 3262 new_draw_info (NDI_UNIQUE | NDI_ALL, 0, NULL, buf);
3307 check_score (op); 3263 check_score (op);
3264
3308 if (op->contr->ranges[range_golem] != NULL) 3265 if (op->contr->ranges[range_golem])
3309 { 3266 {
3310 remove_friendly_object (op->contr->ranges[range_golem]); 3267 remove_friendly_object (op->contr->ranges[range_golem]);
3311 remove_ob (op->contr->ranges[range_golem]); 3268 op->contr->ranges[range_golem]->destroy ();
3312 free_object (op->contr->ranges[range_golem]);
3313 op->contr->ranges[range_golem] = NULL; 3269 op->contr->ranges[range_golem] = 0;
3314 op->contr->golem_count = 0;
3315 } 3270 }
3271
3316 loot_object (op); /* Remove some of the items for good */ 3272 loot_object (op); /* Remove some of the items for good */
3317 remove_ob (op); 3273 op->remove ();
3318 op->direction = 0; 3274 op->direction = 0;
3319 3275
3320 if (!QUERY_FLAG (op, FLAG_WAS_WIZ) && op->stats.exp) 3276 if (!QUERY_FLAG (op, FLAG_WAS_WIZ) && op->stats.exp)
3321 { 3277 {
3322 delete_character (op->name, 0); 3278 delete_character (op->name, 0);
3375 for (tmp = op->inv; tmp != NULL; tmp = next) 3331 for (tmp = op->inv; tmp != NULL; tmp = next)
3376 { 3332 {
3377 next = tmp->below; 3333 next = tmp->below;
3378 if (tmp->type == EXPERIENCE || tmp->invisible) 3334 if (tmp->type == EXPERIENCE || tmp->invisible)
3379 continue; 3335 continue;
3380 remove_ob (tmp); 3336 tmp->remove ();
3381 tmp->x = op->x, tmp->y = op->y; 3337 tmp->x = op->x, tmp->y = op->y;
3382 if (tmp->type == CONTAINER) 3338 if (tmp->type == CONTAINER)
3383 { /* empty container to ground */ 3339 { /* empty container to ground */
3384 loot_object (tmp); 3340 loot_object (tmp);
3385 } 3341 }
3386 if (!QUERY_FLAG (tmp, FLAG_UNIQUE) && (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || QUERY_FLAG (tmp, FLAG_NO_DROP) || !(RANDOM () % 3))) 3342 if (!QUERY_FLAG (tmp, FLAG_UNIQUE) && (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || QUERY_FLAG (tmp, FLAG_NO_DROP) || !(RANDOM () % 3)))
3387 { 3343 {
3388 if (tmp->nrof > 1) 3344 if (tmp->nrof > 1)
3389 { 3345 {
3390 tmp2 = get_split_ob (tmp, 1 + RANDOM () % (tmp->nrof - 1)); 3346 tmp2 = get_split_ob (tmp, 1 + RANDOM () % (tmp->nrof - 1));
3391 free_object (tmp2); 3347 tmp2->destroy ();
3392 insert_ob_in_map (tmp, op->map, NULL, 0); 3348 insert_ob_in_map (tmp, op->map, NULL, 0);
3393 } 3349 }
3394 else 3350 else
3395 free_object (tmp); 3351 tmp->destroy ();
3396 } 3352 }
3397 else 3353 else
3398 insert_ob_in_map (tmp, op->map, NULL, 0); 3354 insert_ob_in_map (tmp, op->map, NULL, 0);
3399 } 3355 }
3400} 3356}
3465 if (op->type == PLAYER) 3421 if (op->type == PLAYER)
3466 new_draw_info_format (NDI_UNIQUE, 0, op, "You cast %s.", &spob->name); 3422 new_draw_info_format (NDI_UNIQUE, 0, op, "You cast %s.", &spob->name);
3467 3423
3468 cast_spell (op, throw_ob, dir, spob, NULL); 3424 cast_spell (op, throw_ob, dir, spob, NULL);
3469 3425
3470 if (!QUERY_FLAG (throw_ob, FLAG_REMOVED)) 3426 throw_ob->destroy ();
3471 remove_ob (throw_ob);
3472 free_object (throw_ob);
3473} 3427}
3474 3428
3475void 3429void
3476make_visible (object *op) 3430make_visible (object *op)
3477{ 3431{
3684 3638
3685 /* only the viewable area the player sees is updated by LOS 3639 /* only the viewable area the player sees is updated by LOS
3686 * code, so we need to restrict ourselves to that range of values 3640 * code, so we need to restrict ourselves to that range of values
3687 * for any meaningful values. 3641 * for any meaningful values.
3688 */ 3642 */
3689 if (FABS (dx) <= (pl->contr->socket.mapx / 2) && 3643 if (FABS (dx) <= (pl->contr->socket->mapx / 2) &&
3690 FABS (dy) <= (pl->contr->socket.mapy / 2) && 3644 FABS (dy) <= (pl->contr->socket->mapy / 2) &&
3691 !pl->contr->blocked_los[dx + (pl->contr->socket.mapx / 2)][dy + (pl->contr->socket.mapy / 2)]) 3645 !pl->contr->blocked_los[dx + (pl->contr->socket->mapx / 2)][dy + (pl->contr->socket->mapy / 2)])
3692 return 1; 3646 return 1;
3693 op = op->more; 3647 op = op->more;
3694 } 3648 }
3695 return 0; 3649 return 0;
3696} 3650}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines