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.25 by root, Sat Sep 16 22:24:13 2006 UTC vs.
Revision 1.50 by elmex, Wed Dec 20 10:31:00 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;
277 p->usekeys = containers; 263 p->usekeys = containers;
278 p->last_weapon_sp = -1; 264 p->last_weapon_sp = -1;
279 p->peaceful = 1; /* default peaceful */ 265 p->peaceful = 1; /* default peaceful */
280 p->do_los = 1; 266 p->do_los = 1;
281 p->explore = 0; 267 p->explore = 0;
282 p->no_shout = 0; /* default can shout */
283 268
284 assign (p->title, op->arch->clone.name); 269 assign (p->title, op->arch->clone.name);
285 op->race = op->arch->clone.race; 270 op->race = op->arch->clone.race;
286 271
287 CLEAR_FLAG (op, FLAG_READY_SKILL); 272 CLEAR_FLAG (op, FLAG_READY_SKILL);
294 for (i = 0; i < NUM_SKILLS; i++) 279 for (i = 0; i < NUM_SKILLS; i++)
295 { 280 {
296 p->last_skill_exp[i] = -1; 281 p->last_skill_exp[i] = -1;
297 p->last_skill_ob[i] = NULL; 282 p->last_skill_ob[i] = NULL;
298 } 283 }
284
299 for (i = 0; i < NROFATTACKS; i++) 285 for (i = 0; i < NROFATTACKS; i++)
300 {
301 p->last_resist[i] = -1; 286 p->last_resist[i] = -1;
302 } 287
303 p->last_stats.exp = -1; 288 p->last_stats.exp = -1;
304 p->last_weight = (uint32) - 1; 289 p->last_weight = (uint32) - 1;
305 290
306 p->socket.update_look = 0; 291 p->socket->update_look = 0;
307 p->socket.look_position = 0; 292 p->socket->look_position = 0;
293
308 return p; 294 return p;
309} 295}
310 296
311/* This loads the first map an puts the player on it. */ 297/* This loads the first map an puts the player on it. */
312static void 298static void
313set_first_map (object *op) 299set_first_map (object *op)
314{ 300{
315 strcpy (op->contr->maplevel, first_map_path); 301 strcpy (op->contr->maplevel, first_map_path);
316 op->x = -1; 302 op->x = -1;
317 op->y = -1; 303 op->y = -1;
318 enter_exit (op, NULL); 304 enter_exit (op, 0);
319} 305}
320 306
321/* Tries to add player on the connection passwd in ns. 307/* Tries to add player on the connection passwd in ns.
322 * All we can really get in this is some settings like host and display 308 * All we can really get in this is some settings like host and display
323 * mode. 309 * mode.
324 */ 310 */
325 311
326int 312int
327add_player (NewSocket * ns) 313add_player (client *ns)
328{ 314{
329 player *p; 315 player *p = new player;
330 316
331 p = get_player (NULL);
332 p->socket = *ns; 317 p->socket = ns;
333 p->socket.faces_sent = (uint8 *) malloc (p->socket.faces_sent_len * sizeof (*p->socket.faces_sent)); 318 ns->pl = p;
334 if (p->socket.faces_sent == NULL) 319
335 fatal (OUT_OF_MEMORY); 320 p->next = first_player;
336 memcpy (p->socket.faces_sent, ns->faces_sent, p->socket.faces_sent_len * sizeof (*p->socket.faces_sent)); 321 first_player = p;
337 /* Needed because the socket we just copied over needs to be cleared. 322
338 * Note that this can result in a client reset if there is partial data 323 p = get_player (p);
339 * on the uncoming socket. 324
340 */
341 p->socket.inbuf.len = 0;
342 set_first_map (p->ob); 325 set_first_map (p->ob);
343 326
344 CLEAR_FLAG (p->ob, FLAG_FRIENDLY); 327 CLEAR_FLAG (p->ob, FLAG_FRIENDLY);
345 add_friendly_object (p->ob); 328 add_friendly_object (p->ob);
346 send_rules (p->ob); 329 send_rules (p->ob);
347 send_news (p->ob); 330 send_news (p->ob);
348 display_motd (p->ob); 331 display_motd (p->ob);
349 get_name (p->ob); 332 get_name (p->ob);
333
350 return 0; 334 return 0;
351} 335}
352 336
353/* 337/*
354 * get_player_archetype() return next player archetype from archetype 338 * get_player_archetype() return next player archetype from archetype
364 { 348 {
365 if (at == NULL || at->next == NULL) 349 if (at == NULL || at->next == NULL)
366 at = first_archetype; 350 at = first_archetype;
367 else 351 else
368 at = at->next; 352 at = at->next;
353
369 if (at->clone.type == PLAYER) 354 if (at->clone.type == PLAYER)
370 return at; 355 return at;
356
371 if (at == start) 357 if (at == start)
372 { 358 {
373 LOG (llevError, "No Player archetypes\n"); 359 LOG (llevError, "No Player archetypes\n");
374 exit (-1); 360 exit (-1);
375 } 361 }
376 } 362 }
377} 363}
378
379 364
380object * 365object *
381get_nearest_player (object *mon) 366get_nearest_player (object *mon)
382{ 367{
383 object *op = NULL; 368 object *op = NULL;
643 (op->type == ARMOUR || op->type == BOOTS || 628 (op->type == ARMOUR || op->type == BOOTS ||
644 op->type == CLOAK || op->type == HELMET || 629 op->type == CLOAK || op->type == HELMET ||
645 op->type == SHIELD || op->type == GLOVES || 630 op->type == SHIELD || op->type == GLOVES ||
646 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))
647 { 632 {
648 remove_ob (op); 633 op->destroy ();
649 free_object (op);
650 continue; 634 continue;
651 } 635 }
652 } 636 }
653 637
654 /* This really needs to be better - we should really give 638 /* This really needs to be better - we should really give
665 if (tmp->type == op->type && tmp->name == op->name) 649 if (tmp->type == op->type && tmp->name == op->name)
666 break; 650 break;
667 651
668 if (tmp) 652 if (tmp)
669 { 653 {
670 remove_ob (op); 654 op->destroy ();
671 free_object (op);
672 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);
673 continue; 656 continue;
674 } 657 }
658
675 if (op->nrof > 1) 659 if (op->nrof > 1)
676 op->nrof = 1; 660 op->nrof = 1;
677 } 661 }
678 662
679 if (op->type == SPELLBOOK && op->inv) 663 if (op->type == SPELLBOOK && op->inv)
691 CLEAR_FLAG (op, FLAG_CURSED); 675 CLEAR_FLAG (op, FLAG_CURSED);
692 CLEAR_FLAG (op, FLAG_DAMNED); 676 CLEAR_FLAG (op, FLAG_DAMNED);
693 } 677 }
694 if (op->type == SPELL) 678 if (op->type == SPELL)
695 { 679 {
696 remove_ob (op); 680 op->destroy ();
697 free_object (op);
698 continue; 681 continue;
699 } 682 }
700 else if (op->type == SKILL) 683 else if (op->type == SKILL)
701 { 684 {
702 SET_FLAG (op, FLAG_CAN_USE_SKILL); 685 SET_FLAG (op, FLAG_CAN_USE_SKILL);
715void 698void
716get_name (object *op) 699get_name (object *op)
717{ 700{
718 op->contr->write_buf[0] = '\0'; 701 op->contr->write_buf[0] = '\0';
719 op->contr->state = ST_GET_NAME; 702 op->contr->state = ST_GET_NAME;
720 send_query (&op->contr->socket, 0, "What is your name?\n:"); 703 send_query (op->contr->socket, 0, "What is your name?\n:");
721} 704}
722 705
723void 706void
724get_password (object *op) 707get_password (object *op)
725{ 708{
726 op->contr->write_buf[0] = '\0'; 709 op->contr->write_buf[0] = '\0';
727 op->contr->state = ST_GET_PASSWORD; 710 op->contr->state = ST_GET_PASSWORD;
728 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:");
729} 712}
730 713
731void 714void
732play_again (object *op) 715play_again (object *op)
733{ 716{
734 op->contr->state = ST_PLAY_AGAIN; 717 op->contr->state = ST_PLAY_AGAIN;
735 op->chosen_skill = NULL; 718 op->chosen_skill = NULL;
736 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)?");
737 /* 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
738 * player creation process that a user can quit (eg, roll 721 * player creation process that a user can quit (eg, roll
739 * stats) that isn't removing the player. Taking a quick 722 * stats) that isn't removing the player. Taking a quick
740 * look, there are many places that call play_again without 723 * look, there are many places that call play_again without
741 * removing the player - it probably makes more sense 724 * removing the player - it probably makes more sense
742 * 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
743 * cases. 726 * cases.
744 */ 727 */
745 if (!QUERY_FLAG (op, FLAG_REMOVED)) 728 if (!QUERY_FLAG (op, FLAG_REMOVED))
746 remove_ob (op); 729 op->remove ();
747 /* 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,
748 * 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
749 * the map is null or not swapped out. 732 * the map is null or not swapped out.
750 */ 733 */
751 op->map = NULL; 734 op->map = NULL;
765 player *pl = op->contr; 748 player *pl = op->contr;
766 shstr name = op->name; 749 shstr name = op->name;
767 750
768 op->contr = 0; 751 op->contr = 0;
769 op->type = 0; 752 op->type = 0;
770 op->free (1); 753 op->destroy (1);
771 pl = get_player (pl); 754 pl = get_player (pl);
772 op = pl->ob; 755 op = pl->ob;
773 add_friendly_object (op); 756 add_friendly_object (op);
774 op->contr->password[0] = '~'; 757 op->contr->password[0] = '~';
775 op->name = op->name_pl = 0; 758 op->name = op->name_pl = 0;
790confirm_password (object *op) 773confirm_password (object *op)
791{ 774{
792 775
793 op->contr->write_buf[0] = '\0'; 776 op->contr->write_buf[0] = '\0';
794 op->contr->state = ST_CONFIRM_PASSWORD; 777 op->contr->state = ST_CONFIRM_PASSWORD;
795 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:");
796} 779}
797 780
798void 781void
799get_party_password (object *op, partylist *party) 782get_party_password (object *op, partylist *party)
800{ 783{
804 return; 787 return;
805 } 788 }
806 op->contr->write_buf[0] = '\0'; 789 op->contr->write_buf[0] = '\0';
807 op->contr->state = ST_GET_PARTY_PASSWORD; 790 op->contr->state = ST_GET_PARTY_PASSWORD;
808 op->contr->party_to_join = party; 791 op->contr->party_to_join = party;
809 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:");
810} 793}
811 794
812 795
813/* 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. */
814int 797int
911 894
912void 895void
913Roll_Again (object *op) 896Roll_Again (object *op)
914{ 897{
915 esrv_new_player (op->contr, 0); 898 esrv_new_player (op->contr, 0);
916 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, 899 send_query (op->contr->socket, CS_QUERY_SINGLECHAR,
917 "[y] to roll new stats [n] to use stats\n[1-7] [1-7] to swap stats.\nRoll again (y/n/1-7)? "); 900 "[y] to roll new stats [n] to use stats\n[1-7] [1-7] to swap stats.\nRoll again (y/n/1-7)? ");
918} 901}
919 902
920void 903void
921Swap_Stat (object *op, int Swap_Second) 904Swap_Stat (object *op, int Swap_Second)
988 new_draw_info (NDI_UNIQUE, 0, op, buf); 971 new_draw_info (NDI_UNIQUE, 0, op, buf);
989 } 972 }
990 else 973 else
991 Swap_Stat (op, stat_trans[keynum]); 974 Swap_Stat (op, stat_trans[keynum]);
992 975
993 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, ""); 976 send_query (op->contr->socket, CS_QUERY_SINGLECHAR, "");
994 return 1; 977 return 1;
995 } 978 }
996 switch (key) 979 switch (key)
997 { 980 {
998 case 'n': 981 case 'n':
1012 enter_exit (op, NULL); 995 enter_exit (op, NULL);
1013#endif 996#endif
1014 SET_ANIMATION (op, 2); /* So player faces south */ 997 SET_ANIMATION (op, 2); /* So player faces south */
1015 /* Enter exit adds a player otherwise */ 998 /* Enter exit adds a player otherwise */
1016 add_statbonus (op); 999 add_statbonus (op);
1017 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, 1000 send_query (op->contr->socket, CS_QUERY_SINGLECHAR,
1018 "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n"); 1001 "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n");
1019 op->contr->state = ST_CHANGE_CLASS; 1002 op->contr->state = ST_CHANGE_CLASS;
1020 if (op->msg) 1003 if (op->msg)
1021 new_draw_info (NDI_BLUE, 0, op, op->msg); 1004 new_draw_info (NDI_BLUE, 0, op, op->msg);
1022 return 0; 1005 return 0;
1023 } 1006 }
1024 case 'y': 1007 case 'y':
1025 case 'Y': 1008 case 'Y':
1026 roll_stats (op); 1009 roll_stats (op);
1027 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, ""); 1010 send_query (op->contr->socket, CS_QUERY_SINGLECHAR, "");
1028 return 1; 1011 return 1;
1029 1012
1030 case 'q': 1013 case 'q':
1031 case 'Q': 1014 case 'Q':
1032 play_again (op); 1015 play_again (op);
1033 return 1; 1016 return 1;
1034 1017
1035 default: 1018 default:
1036 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?");
1037 return 0; 1020 return 0;
1038 } 1021 }
1039 return 0; 1022 return 0;
1040} 1023}
1041 1024
1051{ 1034{
1052 int tmp_loop; 1035 int tmp_loop;
1053 1036
1054 if (key == 'q' || key == 'Q') 1037 if (key == 'q' || key == 'Q')
1055 { 1038 {
1056 remove_ob (op); 1039 op->remove ();
1057 play_again (op); 1040 play_again (op);
1058 return 0; 1041 return 0;
1059 } 1042 }
1060 if (key == 'd' || key == 'D') 1043 if (key == 'd' || key == 'D')
1061 { 1044 {
1062 char buf[MAX_BUF]; 1045 char buf[MAX_BUF];
1063 1046
1064 /* this must before then initial items are given */ 1047 /* this must before then initial items are given */
1065 esrv_new_player (op->contr, op->weight + op->carrying); 1048 esrv_new_player (op->contr, op->weight + op->carrying);
1049
1066 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);
1067 1053
1068 INVOKE_PLAYER (BIRTH, op->contr); 1054 INVOKE_PLAYER (BIRTH, op->contr);
1069 INVOKE_PLAYER (LOGIN, op->contr); 1055 INVOKE_PLAYER (LOGIN, op->contr);
1070 1056
1071 op->contr->state = ST_PLAYING; 1057 op->contr->state = ST_PLAYING;
1096 { 1082 {
1097 object *tmp; 1083 object *tmp;
1098 char mapname[MAX_BUF]; 1084 char mapname[MAX_BUF];
1099 1085
1100 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);
1101 tmp = get_object (); 1087 tmp = object::create ();
1102 EXIT_PATH (tmp) = mapname; 1088 EXIT_PATH (tmp) = mapname;
1103 EXIT_X (tmp) = op->x; 1089 EXIT_X (tmp) = op->x;
1104 EXIT_Y (tmp) = op->y; 1090 EXIT_Y (tmp) = op->y;
1105 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;
1106 * if the map isn't there, then stay on the 1092 * if the map isn't there, then stay on the
1107 * default initial map */ 1093 * default initial map */
1108 free_object (tmp); 1094 tmp->destroy ();
1109 } 1095 }
1110 else 1096 else
1111 {
1112 LOG (llevDebug, "first_map_ext_path not set\n"); 1097 LOG (llevDebug, "first_map_ext_path not set\n");
1113 } 1098
1114 return 0; 1099 return 0;
1115 } 1100 }
1116 1101
1117 /* Following actually changes the race - this is the default command 1102 /* Following actually changes the race - this is the default command
1118 * if we don't match with one of the options above. 1103 * if we don't match with one of the options above.
1123 { 1108 {
1124 shstr name = op->name; 1109 shstr name = op->name;
1125 int x = op->x, y = op->y; 1110 int x = op->x, y = op->y;
1126 1111
1127 remove_statbonus (op); 1112 remove_statbonus (op);
1128 remove_ob (op); 1113 op->remove ();
1129 op->arch = get_player_archetype (op->arch); 1114 op->arch = get_player_archetype (op->arch);
1130 copy_object (&op->arch->clone, op); 1115 op->arch->clone.copy_to (op);
1131 op->instantiate (); 1116 op->instantiate ();
1132 op->stats = op->contr->orig_stats; 1117 op->stats = op->contr->orig_stats;
1133 op->name = op->name_pl = name; 1118 op->name = op->name_pl = name;
1134 op->x = x; 1119 op->x = x;
1135 op->y = y; 1120 op->y = y;
1148 op->stats.grace = 0; 1133 op->stats.grace = 0;
1149 1134
1150 if (op->msg) 1135 if (op->msg)
1151 new_draw_info (NDI_BLUE, 0, op, op->msg); 1136 new_draw_info (NDI_BLUE, 0, op, op->msg);
1152 1137
1153 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "Press any key for the next race.\nPress `d' to play this race.\n"); 1138 send_query (op->contr->socket, CS_QUERY_SINGLECHAR, "Press any key for the next race.\nPress `d' to play this race.\n");
1154 return 0; 1139 return 0;
1155} 1140}
1156 1141
1157int 1142int
1158key_confirm_quit (object *op, char key) 1143key_confirm_quit (object *op, char key)
1238 { 1223 {
1239 op->enemy = NULL; 1224 op->enemy = NULL;
1240 CLEAR_FLAG (op, FLAG_SCARED); 1225 CLEAR_FLAG (op, FLAG_SCARED);
1241 return; 1226 return;
1242 } 1227 }
1228
1243 get_rangevector (op, op->enemy, &rv, 0); 1229 get_rangevector (op, op->enemy, &rv, 0);
1244 1230
1245 dir = absdir (4 + rv.direction); 1231 dir = absdir (4 + rv.direction);
1246 for (diff = 0; diff < 3; diff++) 1232 for (diff = 0; diff < 3; diff++)
1247 { 1233 {
1248 int m = 1 - (RANDOM () & 2); 1234 int m = 1 - (RANDOM () & 2);
1249 1235
1250 if (move_ob (op, absdir (dir + diff * m), op) || (diff == 0 && move_ob (op, absdir (dir - diff * m), op))) 1236 if (move_ob (op, absdir (dir + diff * m), op) || (diff == 0 && move_ob (op, absdir (dir - diff * m), op)))
1251 {
1252 return; 1237 return;
1253 }
1254 } 1238 }
1239
1255 /* Cornered, get rid of scared */ 1240 /* Cornered, get rid of scared */
1256 CLEAR_FLAG (op, FLAG_SCARED); 1241 CLEAR_FLAG (op, FLAG_SCARED);
1257 op->enemy = NULL; 1242 op->enemy = NULL;
1258} 1243}
1259 1244
1423 /* question: don't pick up known-poisonous stuff? */ 1408 /* question: don't pick up known-poisonous stuff? */
1424 if (op->contr->mode & PU_FOOD) 1409 if (op->contr->mode & PU_FOOD)
1425 if (tmp->type == FOOD) 1410 if (tmp->type == FOOD)
1426 { 1411 {
1427 pick_up (op, tmp); 1412 pick_up (op, tmp);
1428 if (0)
1429 fprintf (stderr, "FOOD\n");
1430 continue; 1413 continue;
1431 } 1414 }
1415
1432 if (op->contr->mode & PU_DRINK) 1416 if (op->contr->mode & PU_DRINK)
1433 if (tmp->type == DRINK || (tmp->type == POISON && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))) 1417 if (tmp->type == DRINK || (tmp->type == POISON && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)))
1434 { 1418 {
1435 pick_up (op, tmp); 1419 pick_up (op, tmp);
1436 if (0)
1437 fprintf (stderr, "DRINK\n");
1438 continue; 1420 continue;
1439 } 1421 }
1440 1422
1441 if (op->contr->mode & PU_POTION) 1423 if (op->contr->mode & PU_POTION)
1442 if (tmp->type == POTION) 1424 if (tmp->type == POTION)
1443 { 1425 {
1444 pick_up (op, tmp); 1426 pick_up (op, tmp);
1445 if (0)
1446 fprintf (stderr, "POTION\n");
1447 continue; 1427 continue;
1448 } 1428 }
1449 1429
1450 /* spellbooks, skillscrolls and normal books/scrolls */ 1430 /* spellbooks, skillscrolls and normal books/scrolls */
1451 if (op->contr->mode & PU_SPELLBOOK) 1431 if (op->contr->mode & PU_SPELLBOOK)
1452 if (tmp->type == SPELLBOOK) 1432 if (tmp->type == SPELLBOOK)
1453 { 1433 {
1454 pick_up (op, tmp); 1434 pick_up (op, tmp);
1455 if (0)
1456 fprintf (stderr, "SPELLBOOK\n");
1457 continue; 1435 continue;
1458 } 1436 }
1437
1459 if (op->contr->mode & PU_SKILLSCROLL) 1438 if (op->contr->mode & PU_SKILLSCROLL)
1460 if (tmp->type == SKILLSCROLL) 1439 if (tmp->type == SKILLSCROLL)
1461 { 1440 {
1462 pick_up (op, tmp); 1441 pick_up (op, tmp);
1463 if (0)
1464 fprintf (stderr, "SKILLSCROLL\n");
1465 continue; 1442 continue;
1466 } 1443 }
1444
1467 if (op->contr->mode & PU_READABLES) 1445 if (op->contr->mode & PU_READABLES)
1468 if (tmp->type == BOOK || tmp->type == SCROLL) 1446 if (tmp->type == BOOK || tmp->type == SCROLL)
1469 { 1447 {
1470 pick_up (op, tmp); 1448 pick_up (op, tmp);
1471 if (0)
1472 fprintf (stderr, "READABLES\n");
1473 continue; 1449 continue;
1474 } 1450 }
1475 1451
1476 /* wands/staves/rods/horns */ 1452 /* wands/staves/rods/horns */
1477 if (op->contr->mode & PU_MAGIC_DEVICE) 1453 if (op->contr->mode & PU_MAGIC_DEVICE)
1478 if (tmp->type == WAND || tmp->type == ROD || tmp->type == HORN) 1454 if (tmp->type == WAND || tmp->type == ROD || tmp->type == HORN)
1479 { 1455 {
1480 pick_up (op, tmp); 1456 pick_up (op, tmp);
1481 if (0)
1482 fprintf (stderr, "MAGIC_DEVICE\n");
1483 continue; 1457 continue;
1484 } 1458 }
1485 1459
1486 /* pick up all magical items */ 1460 /* pick up all magical items */
1487 if (op->contr->mode & PU_MAGICAL) 1461 if (op->contr->mode & PU_MAGICAL)
1488 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)) 1462 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))
1489 { 1463 {
1490 pick_up (op, tmp); 1464 pick_up (op, tmp);
1491 if (0)
1492 fprintf (stderr, "MAGICAL\n");
1493 continue; 1465 continue;
1494 } 1466 }
1495 1467
1496 if (op->contr->mode & PU_VALUABLES) 1468 if (op->contr->mode & PU_VALUABLES)
1497 { 1469 {
1498 if (tmp->type == MONEY || tmp->type == GEM) 1470 if (tmp->type == MONEY || tmp->type == GEM)
1499 { 1471 {
1500 pick_up (op, tmp); 1472 pick_up (op, tmp);
1501 if (0)
1502 fprintf (stderr, "MONEY/GEM\n");
1503 continue; 1473 continue;
1504 } 1474 }
1505 } 1475 }
1506 1476
1507 /* rings & amulets - talismans seems to be typed AMULET */ 1477 /* rings & amulets - talismans seems to be typed AMULET */
1508 if (op->contr->mode & PU_JEWELS) 1478 if (op->contr->mode & PU_JEWELS)
1509 if (tmp->type == RING || tmp->type == AMULET) 1479 if (tmp->type == RING || tmp->type == AMULET)
1510 { 1480 {
1511 pick_up (op, tmp); 1481 pick_up (op, tmp);
1482 continue;
1512 if (0) 1483 }
1513 fprintf (stderr, "JEWELS\n"); 1484
1485 /* we don't forget dragon food */
1486 if (op->contr->mode & PU_FLESH)
1487 if (tmp->type == FLESH)
1488 {
1489 pick_up (op, tmp);
1514 continue; 1490 continue;
1515 } 1491 }
1516 1492
1517 /* bows and arrows. Bows are good for selling! */ 1493 /* bows and arrows. Bows are good for selling! */
1518 if (op->contr->mode & PU_BOW) 1494 if (op->contr->mode & PU_BOW)
1519 if (tmp->type == BOW) 1495 if (tmp->type == BOW)
1520 { 1496 {
1521 pick_up (op, tmp); 1497 pick_up (op, tmp);
1522 if (0)
1523 fprintf (stderr, "BOW\n");
1524 continue; 1498 continue;
1525 } 1499 }
1500
1526 if (op->contr->mode & PU_ARROW) 1501 if (op->contr->mode & PU_ARROW)
1527 if (tmp->type == ARROW) 1502 if (tmp->type == ARROW)
1528 { 1503 {
1529 pick_up (op, tmp); 1504 pick_up (op, tmp);
1530 if (0)
1531 fprintf (stderr, "ARROW\n");
1532 continue; 1505 continue;
1533 } 1506 }
1534 1507
1535 /* all kinds of armor etc. */ 1508 /* all kinds of armor etc. */
1536 if (op->contr->mode & PU_ARMOUR) 1509 if (op->contr->mode & PU_ARMOUR)
1537 if (tmp->type == ARMOUR) 1510 if (tmp->type == ARMOUR)
1538 { 1511 {
1539 pick_up (op, tmp); 1512 pick_up (op, tmp);
1540 if (0)
1541 fprintf (stderr, "ARMOUR\n");
1542 continue; 1513 continue;
1543 } 1514 }
1515
1544 if (op->contr->mode & PU_HELMET) 1516 if (op->contr->mode & PU_HELMET)
1545 if (tmp->type == HELMET) 1517 if (tmp->type == HELMET)
1546 { 1518 {
1547 pick_up (op, tmp); 1519 pick_up (op, tmp);
1548 if (0)
1549 fprintf (stderr, "HELMET\n");
1550 continue; 1520 continue;
1551 } 1521 }
1522
1552 if (op->contr->mode & PU_SHIELD) 1523 if (op->contr->mode & PU_SHIELD)
1553 if (tmp->type == SHIELD) 1524 if (tmp->type == SHIELD)
1554 { 1525 {
1555 pick_up (op, tmp); 1526 pick_up (op, tmp);
1556 if (0)
1557 fprintf (stderr, "SHIELD\n");
1558 continue; 1527 continue;
1559 } 1528 }
1529
1560 if (op->contr->mode & PU_BOOTS) 1530 if (op->contr->mode & PU_BOOTS)
1561 if (tmp->type == BOOTS) 1531 if (tmp->type == BOOTS)
1562 { 1532 {
1563 pick_up (op, tmp); 1533 pick_up (op, tmp);
1564 if (0)
1565 fprintf (stderr, "BOOTS\n");
1566 continue; 1534 continue;
1567 } 1535 }
1536
1568 if (op->contr->mode & PU_GLOVES) 1537 if (op->contr->mode & PU_GLOVES)
1569 if (tmp->type == GLOVES) 1538 if (tmp->type == GLOVES)
1570 { 1539 {
1571 pick_up (op, tmp); 1540 pick_up (op, tmp);
1572 if (0)
1573 fprintf (stderr, "GLOVES\n");
1574 continue; 1541 continue;
1575 } 1542 }
1543
1576 if (op->contr->mode & PU_CLOAK) 1544 if (op->contr->mode & PU_CLOAK)
1577 if (tmp->type == CLOAK) 1545 if (tmp->type == CLOAK)
1578 { 1546 {
1579 pick_up (op, tmp); 1547 pick_up (op, tmp);
1580 if (0)
1581 fprintf (stderr, "GLOVES\n");
1582 continue; 1548 continue;
1583 } 1549 }
1584 1550
1585 /* hoping to catch throwing daggers here */ 1551 /* hoping to catch throwing daggers here */
1586 if (op->contr->mode & PU_MISSILEWEAPON) 1552 if (op->contr->mode & PU_MISSILEWEAPON)
1587 if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_IS_THROWN)) 1553 if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_IS_THROWN))
1588 { 1554 {
1589 pick_up (op, tmp); 1555 pick_up (op, tmp);
1590 if (0)
1591 fprintf (stderr, "MISSILEWEAPON\n");
1592 continue; 1556 continue;
1593 } 1557 }
1594 1558
1595 /* careful: chairs and tables are weapons! */ 1559 /* careful: chairs and tables are weapons! */
1596 if (op->contr->mode & PU_ALLWEAPON) 1560 if (op->contr->mode & PU_ALLWEAPON)
1599 { 1563 {
1600 if (strstr (tmp->name, "table") == NULL && strstr (tmp->arch->name, "table") == NULL && 1564 if (strstr (tmp->name, "table") == NULL && strstr (tmp->arch->name, "table") == NULL &&
1601 strstr (tmp->name, "chair") && strstr (tmp->arch->name, "chair") == NULL) 1565 strstr (tmp->name, "chair") && strstr (tmp->arch->name, "chair") == NULL)
1602 { 1566 {
1603 pick_up (op, tmp); 1567 pick_up (op, tmp);
1604 if (0)
1605 fprintf (stderr, "WEAPON\n");
1606 continue; 1568 continue;
1607 } 1569 }
1608 } 1570 }
1571
1609 if (tmp->type == WEAPON && tmp->name == NULL) 1572 if (tmp->type == WEAPON && tmp->name == NULL)
1610 { 1573 {
1611 if (strstr (tmp->arch->name, "table") == NULL && strstr (tmp->arch->name, "chair") == NULL) 1574 if (strstr (tmp->arch->name, "table") == NULL && strstr (tmp->arch->name, "chair") == NULL)
1612 { 1575 {
1613 pick_up (op, tmp); 1576 pick_up (op, tmp);
1614 if (0)
1615 fprintf (stderr, "WEAPON\n");
1616 continue; 1577 continue;
1617 } 1578 }
1618 } 1579 }
1619 } 1580 }
1620 1581
1621 /* misc stuff that's useful */ 1582 /* misc stuff that's useful */
1622 if (op->contr->mode & PU_KEY) 1583 if (op->contr->mode & PU_KEY)
1623 if (tmp->type == KEY || tmp->type == SPECIAL_KEY) 1584 if (tmp->type == KEY || tmp->type == SPECIAL_KEY)
1624 { 1585 {
1625 pick_up (op, tmp); 1586 pick_up (op, tmp);
1626 if (0)
1627 fprintf (stderr, "KEY\n");
1628 continue; 1587 continue;
1629 } 1588 }
1630 1589
1631 /* any of the last 4 bits set means we use the ratio for value 1590 /* any of the last 4 bits set means we use the ratio for value
1632 * pickups */ 1591 * pickups */
1654 continue; 1613 continue;
1655 } 1614 }
1656 } 1615 }
1657 } /* the new pickup model */ 1616 } /* the new pickup model */
1658 } 1617 }
1618
1659 return !stop; 1619 return !stop;
1660} 1620}
1661 1621
1662/* 1622/*
1663 * Find an arrow in the inventory and after that 1623 * Find an arrow in the inventory and after that
1840 if (!dir) 1800 if (!dir)
1841 { 1801 {
1842 new_draw_info (NDI_UNIQUE, 0, op, "You can't shoot yourself!"); 1802 new_draw_info (NDI_UNIQUE, 0, op, "You can't shoot yourself!");
1843 return 0; 1803 return 0;
1844 } 1804 }
1805
1845 if (op->type == PLAYER) 1806 if (op->type == PLAYER)
1846 bow = op->contr->ranges[range_bow]; 1807 bow = op->contr->ranges[range_bow];
1847 else 1808 else
1848 { 1809 {
1849 for (bow = op->inv; bow; bow = bow->below) 1810 for (bow = op->inv; bow; bow = bow->below)
1857 { 1818 {
1858 LOG (llevError, "Range: bow without activated bow (%s).\n", &op->name); 1819 LOG (llevError, "Range: bow without activated bow (%s).\n", &op->name);
1859 return 0; 1820 return 0;
1860 } 1821 }
1861 } 1822 }
1823
1862 if (!bow->race || !bow->skill) 1824 if (!bow->race || !bow->skill)
1863 { 1825 {
1864 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s is broken.", &bow->name); 1826 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s is broken.", &bow->name);
1865 return 0; 1827 return 0;
1866 } 1828 }
1868 bowspeed = bow->stats.sp + dex_bonus[op->stats.Dex]; 1830 bowspeed = bow->stats.sp + dex_bonus[op->stats.Dex];
1869 1831
1870 /* penalize ROF for bestarrow */ 1832 /* penalize ROF for bestarrow */
1871 if (op->type == PLAYER && op->contr->bowtype == bow_bestarrow) 1833 if (op->type == PLAYER && op->contr->bowtype == bow_bestarrow)
1872 bowspeed -= dex_bonus[op->stats.Dex] + 5; 1834 bowspeed -= dex_bonus[op->stats.Dex] + 5;
1835
1873 if (bowspeed < 1) 1836 if (bowspeed < 1)
1874 bowspeed = 1; 1837 bowspeed = 1;
1875 1838
1876 if (arrow == NULL) 1839 if (arrow == NULL)
1877 { 1840 {
1883 else 1846 else
1884 CLEAR_FLAG (op, FLAG_READY_BOW); 1847 CLEAR_FLAG (op, FLAG_READY_BOW);
1885 return 0; 1848 return 0;
1886 } 1849 }
1887 } 1850 }
1851
1888 mflags = get_map_flags (op->map, &m, sx, sy, &sx, &sy); 1852 mflags = get_map_flags (op->map, &m, sx, sy, &sx, &sy);
1889 if (mflags & P_OUT_OF_MAP) 1853 if (mflags & P_OUT_OF_MAP)
1890 {
1891 return 0; 1854 return 0;
1892 } 1855
1893 if (GET_MAP_MOVE_BLOCK (m, sx, sy) == MOVE_FLY_LOW) 1856 if (GET_MAP_MOVE_BLOCK (m, sx, sy) == MOVE_FLY_LOW)
1894 { 1857 {
1895 new_draw_info (NDI_UNIQUE, 0, op, "Something is in the way."); 1858 new_draw_info (NDI_UNIQUE, 0, op, "Something is in the way.");
1896 return 0; 1859 return 0;
1897 } 1860 }
1898 1861
1899 /* this should not happen, but sometimes does */ 1862 /* this should not happen, but sometimes does */
1900 if (arrow->nrof == 0) 1863 if (arrow->nrof == 0)
1901 { 1864 {
1902 remove_ob (arrow); 1865 arrow->destroy ();
1903 free_object (arrow);
1904 return 0; 1866 return 0;
1905 } 1867 }
1906 1868
1907 left = arrow; /* these are arrows left to the player */ 1869 left = arrow; /* these are arrows left to the player */
1908 arrow = get_split_ob (arrow, 1); 1870 arrow = get_split_ob (arrow, 1);
1909 if (arrow == NULL) 1871 if (!arrow)
1910 { 1872 {
1911 new_draw_info_format (NDI_UNIQUE, 0, op, "You have no %s left.", &bow->race); 1873 new_draw_info_format (NDI_UNIQUE, 0, op, "You have no %s left.", &bow->race);
1912 return 0; 1874 return 0;
1913 } 1875 }
1914 set_owner (arrow, op); 1876
1877 arrow->set_owner (op);
1915 arrow->skill = bow->skill; 1878 arrow->skill = bow->skill;
1916 1879
1917 arrow->direction = dir; 1880 arrow->direction = dir;
1918 arrow->x = sx; 1881 arrow->x = sx;
1919 arrow->y = sy; 1882 arrow->y = sy;
1927 SET_ANIMATION (arrow, arrow->direction); 1890 SET_ANIMATION (arrow, arrow->direction);
1928 arrow->stats.sp = arrow->stats.wc; /* save original wc and dam */ 1891 arrow->stats.sp = arrow->stats.wc; /* save original wc and dam */
1929 arrow->stats.hp = arrow->stats.dam; 1892 arrow->stats.hp = arrow->stats.dam;
1930 arrow->stats.grace = arrow->attacktype; 1893 arrow->stats.grace = arrow->attacktype;
1931 if (arrow->slaying != NULL) 1894 if (arrow->slaying != NULL)
1932 arrow->spellarg = strdup_local (arrow->slaying); 1895 arrow->spellarg = strdup (arrow->slaying);
1933 1896
1934 /* Note that this was different for monsters - they got their level 1897 /* Note that this was different for monsters - they got their level
1935 * added to the damage. I think the strength bonus is more proper. 1898 * added to the damage. I think the strength bonus is more proper.
1936 */ 1899 */
1937 1900
1961 } 1924 }
1962 1925
1963 if (arrow->attacktype == AT_PHYSICAL) 1926 if (arrow->attacktype == AT_PHYSICAL)
1964 arrow->attacktype |= bow->attacktype; 1927 arrow->attacktype |= bow->attacktype;
1965 1928
1966 if (bow->slaying != NULL) 1929 if (bow->slaying)
1967 arrow->slaying = bow->slaying; 1930 arrow->slaying = bow->slaying;
1968 1931
1969 arrow->map = m; 1932 arrow->map = m;
1970 arrow->move_type = MOVE_FLY_LOW; 1933 arrow->move_type = MOVE_FLY_LOW;
1971 arrow->move_on = MOVE_FLY_LOW | MOVE_WALK; 1934 arrow->move_on = MOVE_FLY_LOW | MOVE_WALK;
2087 CLEAR_FLAG (item, FLAG_ANIMATE); 2050 CLEAR_FLAG (item, FLAG_ANIMATE);
2088 item->face = item->arch->clone.face; 2051 item->face = item->arch->clone.face;
2089 item->speed = 0; 2052 item->speed = 0;
2090 update_ob_speed (item); 2053 update_ob_speed (item);
2091 } 2054 }
2092 if ((tmp = is_player_inv (item))) 2055 if ((tmp = item->in_player ()))
2093 esrv_update_item (UPD_ANIM, tmp, item); 2056 esrv_update_item (UPD_ANIM, tmp, item);
2094 } 2057 }
2095 } 2058 }
2096 else if (item->type == ROD || item->type == HORN) 2059 else if (item->type == ROD || item->type == HORN)
2097 { 2060 {
2127 case range_misc: 2090 case range_misc:
2128 fire_misc_object (op, dir); 2091 fire_misc_object (op, dir);
2129 return; 2092 return;
2130 2093
2131 case range_golem: /* Control summoned monsters from scrolls */ 2094 case range_golem: /* Control summoned monsters from scrolls */
2132 if (op->contr->ranges[range_golem] == NULL || op->contr->golem_count != op->contr->ranges[range_golem]->count) 2095 if (QUERY_FLAG (op->contr->ranges[range_golem], FLAG_REMOVED))
2133 { 2096 {
2134 op->contr->ranges[range_golem] = NULL; 2097 op->contr->ranges[range_golem] = 0;
2135 op->contr->shoottype = range_none; 2098 op->contr->shoottype = range_none;
2136 op->contr->golem_count = 0;
2137 } 2099 }
2138 else 2100 else
2139 control_golem (op->contr->ranges[range_golem], dir); 2101 control_golem (op->contr->ranges[range_golem], dir);
2140 return; 2102 return;
2141 2103
2248 * 0 otherwise 2210 * 0 otherwise
2249 */ 2211 */
2250static int 2212static int
2251player_attack_door (object *op, object *door) 2213player_attack_door (object *op, object *door)
2252{ 2214{
2253
2254 /* If its a door, try to find a use a key. If we do destroy the door, 2215 /* If its a door, try to find a use a key. If we do destroy the door,
2255 * might as well return immediately as there is nothing more to do - 2216 * might as well return immediately as there is nothing more to do -
2256 * otherwise, we fall through to the rest of the code. 2217 * otherwise, we fall through to the rest of the code.
2257 */ 2218 */
2258 object *key = find_key (op, op, door); 2219 object *key = find_key (op, op, door);
2296 * It should keep the code cleaner. 2257 * It should keep the code cleaner.
2297 * When this is called, the players direction has been updated 2258 * When this is called, the players direction has been updated
2298 * (taking into account confusion.) The player is also actually 2259 * (taking into account confusion.) The player is also actually
2299 * going to try and move (not fire weapons). 2260 * going to try and move (not fire weapons).
2300 */ 2261 */
2301
2302void 2262void
2303move_player_attack (object *op, int dir) 2263move_player_attack (object *op, int dir)
2304{ 2264{
2305 object *tmp, *mon; 2265 object *tmp, *mon;
2306 sint16 nx, ny; 2266 sint16 nx, ny;
2308 maptile *m; 2268 maptile *m;
2309 2269
2310 nx = freearr_x[dir] + op->x; 2270 nx = freearr_x[dir] + op->x;
2311 ny = freearr_y[dir] + op->y; 2271 ny = freearr_y[dir] + op->y;
2312 2272
2313 on_battleground = op_on_battleground (op, NULL, NULL); 2273 on_battleground = op_on_battleground (op, 0, 0);
2314 2274
2315 /* If braced, or can't move to the square, and it is not out of the 2275 /* If braced, or can't move to the square, and it is not out of the
2316 * map, attack it. Note order of if statement is important - don't 2276 * map, attack it. Note order of if statement is important - don't
2317 * want to be calling move_ob if braced, because move_ob will move the 2277 * want to be calling move_ob if braced, because move_ob will move the
2318 * player. This is a pretty nasty hack, because if we could 2278 * player. This is a pretty nasty hack, because if we could
2330 return; /* Don't think this should happen */ 2290 return; /* Don't think this should happen */
2331 } 2291 }
2332 else 2292 else
2333 m = op->map; 2293 m = op->map;
2334 2294
2335 if ((tmp = get_map_ob (m, nx, ny)) == NULL) 2295 if ((tmp = GET_MAP_OB (m, nx, ny)) == NULL)
2336 { 2296 {
2337 /* LOG(llevError,"player_move_attack: get_map_ob returns NULL, but player can not more there.\n"); */ 2297 /* LOG(llevError,"player_move_attack: GET_MAP_OB returns NULL, but player can not move there.\n"); */
2338 return; 2298 return;
2339 } 2299 }
2340 2300
2341 mon = NULL; 2301 mon = 0;
2342 /* Go through all the objects, and find ones of interest. Only stop if 2302 /* Go through all the objects, and find ones of interest. Only stop if
2343 * we find a monster - that is something we know we want to attack. 2303 * we find a monster - that is something we know we want to attack.
2344 * if its a door or barrel (can roll) see if there may be monsters 2304 * if its a door or barrel (can roll) see if there may be monsters
2345 * on the space 2305 * on the space
2346 */ 2306 */
2347 while (tmp != NULL) 2307 while (tmp)
2348 { 2308 {
2349 if (tmp == op) 2309 if (tmp == op)
2350 { 2310 {
2351 tmp = tmp->above; 2311 tmp = tmp->above;
2352 continue; 2312 continue;
2353 } 2313 }
2314
2354 if (QUERY_FLAG (tmp, FLAG_ALIVE)) 2315 if (QUERY_FLAG (tmp, FLAG_ALIVE))
2355 { 2316 {
2356 mon = tmp; 2317 mon = tmp;
2357 break; 2318 break;
2358 } 2319 }
2320
2359 if (tmp->type == LOCKED_DOOR || QUERY_FLAG (tmp, FLAG_CAN_ROLL)) 2321 if (tmp->type == LOCKED_DOOR || QUERY_FLAG (tmp, FLAG_CAN_ROLL))
2360 mon = tmp; 2322 mon = tmp;
2323
2361 tmp = tmp->above; 2324 tmp = tmp->above;
2362 } 2325 }
2363 2326
2364 if (mon == NULL) /* This happens anytime the player tries to move */ 2327 if (!mon) /* This happens anytime the player tries to move */
2365 return; /* into a wall */ 2328 return; /* into a wall */
2366 2329
2367 if (mon->head != NULL) 2330 if (mon->head)
2368 mon = mon->head; 2331 mon = mon->head;
2369 2332
2370 if ((mon->type == DOOR && mon->stats.hp >= 0) || (mon->type == LOCKED_DOOR)) 2333 if ((mon->type == DOOR && mon->stats.hp >= 0) || (mon->type == LOCKED_DOOR))
2371 if (player_attack_door (op, mon)) 2334 if (player_attack_door (op, mon))
2372 return; 2335 return;
2384 * player owns it and it is either friendly or unagressive. 2347 * player owns it and it is either friendly or unagressive.
2385 */ 2348 */
2386 if ((op->type == PLAYER) 2349 if ((op->type == PLAYER)
2387#if COZY_SERVER 2350#if COZY_SERVER
2388 && 2351 &&
2389 ((get_owner (mon) && get_owner (mon)->contr 2352 ((mon->owner && mon->owner->contr
2390 && same_party (get_owner (mon)->contr->party, op->contr->party)) || get_owner (mon) == op) 2353 && same_party (mon->owner->contr->party, op->contr->party)) || mon->owner == op)
2391#else 2354#else
2392 && get_owner (mon) == op 2355 && mon->owner == op
2393#endif 2356#endif
2394 && (QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY))) 2357 && (QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY)))
2395 { 2358 {
2396 /* If we're braced, we don't want to switch places with it */ 2359 /* If we're braced, we don't want to switch places with it */
2397 if (op->contr->braced) 2360 if (op->contr->braced)
2409 * attack them either. 2372 * attack them either.
2410 */ 2373 */
2411 if ((mon->type == PLAYER || mon->enemy != op) && 2374 if ((mon->type == PLAYER || mon->enemy != op) &&
2412 (mon->type == PLAYER || QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY)) && ( 2375 (mon->type == PLAYER || QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY)) && (
2413#ifdef PROHIBIT_PLAYERKILL 2376#ifdef PROHIBIT_PLAYERKILL
2414 (op->contr->peaceful 2377 (op->contr->peaceful
2415 || (mon->type == PLAYER 2378 || (mon->type == PLAYER
2416 && mon->contr-> 2379 && mon->contr->
2417 peaceful)) && 2380 peaceful)) &&
2418#else 2381#else
2419 op->contr->peaceful && 2382 op->contr->peaceful &&
2420#endif 2383#endif
2421 !on_battleground)) 2384 !on_battleground))
2422 { 2385 {
2423 if (!op->contr->braced) 2386 if (!op->contr->braced)
2424 { 2387 {
2425 play_sound_map (op->map, op->x, op->y, SOUND_PUSH_PLAYER); 2388 play_sound_map (op->map, op->x, op->y, SOUND_PUSH_PLAYER);
2426 (void) push_ob (mon, dir, op); 2389 (void) push_ob (mon, dir, op);
2427 } 2390 }
2428 else 2391 else
2429 {
2430 new_draw_info (0, 0, op, "You withhold your attack"); 2392 new_draw_info (0, 0, op, "You withhold your attack");
2431 } 2393
2432 if (op->contr->tmp_invis || op->hide) 2394 if (op->contr->tmp_invis || op->hide)
2433 make_visible (op); 2395 make_visible (op);
2434 } 2396 }
2435 2397
2436 /* If the object is a boulder or other rollable object, then 2398 /* If the object is a boulder or other rollable object, then
2464 op->speed_left += op->speed / op->contr->weapon_sp; 2426 op->speed_left += op->speed / op->contr->weapon_sp;
2465 2427
2466 op->contr->has_hit = 1; /* The last action was to hit, so use weapon_sp */ 2428 op->contr->has_hit = 1; /* The last action was to hit, so use weapon_sp */
2467 } 2429 }
2468 2430
2469 skill_attack (mon, op, 0, NULL, NULL); 2431 skill_attack (mon, op, 0, 0, 0);
2470 2432
2471 /* If attacking another player, that player gets automatic 2433 /* If attacking another player, that player gets automatic
2472 * hitback, and doesn't loose luck either. 2434 * hitback, and doesn't loose luck either.
2473 * Disable hitback on the battleground or if the target is 2435 * Disable hitback on the battleground or if the target is
2474 * the wiz. 2436 * the wiz.
2476 if (mon->type == PLAYER && mon->stats.hp >= 0 && !mon->contr->has_hit && !on_battleground && !QUERY_FLAG (mon, FLAG_WIZ)) 2438 if (mon->type == PLAYER && mon->stats.hp >= 0 && !mon->contr->has_hit && !on_battleground && !QUERY_FLAG (mon, FLAG_WIZ))
2477 { 2439 {
2478 short luck = mon->stats.luck; 2440 short luck = mon->stats.luck;
2479 2441
2480 mon->contr->has_hit = 1; 2442 mon->contr->has_hit = 1;
2481 skill_attack (op, mon, 0, NULL, NULL); 2443 skill_attack (op, mon, 0, 0, 0);
2482 mon->stats.luck = luck; 2444 mon->stats.luck = luck;
2483 } 2445 }
2446
2484 if (action_makes_visible (op)) 2447 if (action_makes_visible (op))
2485 make_visible (op); 2448 make_visible (op);
2486 } 2449 }
2487 } /* if player should attack something */ 2450 } /* if player should attack something */
2488} 2451}
2523 2486
2524 /* Add special check for newcs players and fire on - this way, the 2487 /* Add special check for newcs players and fire on - this way, the
2525 * server can handle repeat firing. 2488 * server can handle repeat firing.
2526 */ 2489 */
2527 if (op->contr->fire_on || (op->contr->run_on && pick != 0)) 2490 if (op->contr->fire_on || (op->contr->run_on && pick != 0))
2528 {
2529 op->direction = dir; 2491 op->direction = dir;
2530 }
2531 else 2492 else
2532 {
2533 op->direction = 0; 2493 op->direction = 0;
2534 } 2494
2535 /* Update how the player looks. Use the facing, so direction may 2495 /* Update how the player looks. Use the facing, so direction may
2536 * get reset to zero. This allows for full animation capabilities 2496 * get reset to zero. This allows for full animation capabilities
2537 * for players. 2497 * for players.
2538 */ 2498 */
2539 animate_object (op, op->facing); 2499 animate_object (op, op->facing);
2584 /* I've been seeing crashes where the golem has been destroyed, but 2544 /* I've been seeing crashes where the golem has been destroyed, but
2585 * the player object still points to the defunct golem. The code that 2545 * the player object still points to the defunct golem. The code that
2586 * destroys the golem looks correct, and it doesn't always happen, so 2546 * destroys the golem looks correct, and it doesn't always happen, so
2587 * put this in a a workaround to clean up the golem pointer. 2547 * put this in a a workaround to clean up the golem pointer.
2588 */ 2548 */
2589 if (op->contr->ranges[range_golem] &&
2590 ((op->contr->golem_count != op->contr->ranges[range_golem]->count) || QUERY_FLAG (op->contr->ranges[range_golem], FLAG_REMOVED))) 2549 if (op->contr->ranges[range_golem] && QUERY_FLAG (op->contr->ranges[range_golem], FLAG_REMOVED))
2591 {
2592 op->contr->ranges[range_golem] = NULL; 2550 op->contr->ranges[range_golem] = 0;
2593 op->contr->golem_count = 0;
2594 }
2595 2551
2596 /* call this here - we also will call this in do_ericserver, but 2552 /* call this here - we also will call this in do_ericserver, but
2597 * the players time has been increased when doericserver has been 2553 * the players time has been increased when doericserver has been
2598 * called, so we recheck it here. 2554 * called, so we recheck it here.
2599 */ 2555 */
2600 HandleClient (&op->contr->socket, op->contr); 2556 //TODO: better than handling 8 commands, use some more intelligent rate-limiting
2557 for (int rep = 8; --rep && op->contr->socket->handle_command (); )
2558 ;
2559
2601 if (op->speed_left < 0) 2560 if (op->speed_left < 0)
2602 return 0; 2561 return 0;
2603 2562
2604 if (op->direction && (op->contr->run_on || op->contr->fire_on)) 2563 if (op->direction && (op->contr->run_on || op->contr->fire_on))
2605 { 2564 {
2614 if (op->speed_left > 0) 2573 if (op->speed_left > 0)
2615 return 1; 2574 return 1;
2616 else 2575 else
2617 return 0; 2576 return 0;
2618 } 2577 }
2578
2619 return 0; 2579 return 0;
2620} 2580}
2621 2581
2622int 2582int
2623save_life (object *op) 2583save_life (object *op)
2624{ 2584{
2625 object *tmp;
2626
2627 if (!QUERY_FLAG (op, FLAG_LIFESAVE)) 2585 if (!QUERY_FLAG (op, FLAG_LIFESAVE))
2628 return 0; 2586 return 0;
2629 2587
2630 for (tmp = op->inv; tmp != NULL; tmp = tmp->below) 2588 for (object *tmp = op->inv; tmp; tmp = tmp->below)
2631 if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE)) 2589 if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE))
2632 { 2590 {
2633 play_sound_map (op->map, op->x, op->y, SOUND_OB_EVAPORATE); 2591 play_sound_map (op->map, op->x, op->y, SOUND_OB_EVAPORATE);
2634 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s vibrates violently, then evaporates.", query_name (tmp)); 2592 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s vibrates violently, then evaporates.", query_name (tmp));
2593
2635 if (op->contr) 2594 if (op->contr)
2636 esrv_del_item (op->contr, tmp->count); 2595 esrv_del_item (op->contr, tmp->count);
2637 remove_ob (tmp); 2596
2638 free_object (tmp); 2597 tmp->destroy ();
2639 CLEAR_FLAG (op, FLAG_LIFESAVE); 2598 CLEAR_FLAG (op, FLAG_LIFESAVE);
2599
2640 if (op->stats.hp < 0) 2600 if (op->stats.hp < 0)
2641 op->stats.hp = op->stats.maxhp; 2601 op->stats.hp = op->stats.maxhp;
2602
2642 if (op->stats.food < 0) 2603 if (op->stats.food < 0)
2643 op->stats.food = 999; 2604 op->stats.food = 999;
2605
2644 fix_player (op); 2606 fix_player (op);
2645 return 1; 2607 return 1;
2646 } 2608 }
2609
2647 LOG (llevError, "Error: LIFESAVE set without applied object.\n"); 2610 LOG (llevError, "Error: LIFESAVE set without applied object.\n");
2648 CLEAR_FLAG (op, FLAG_LIFESAVE); 2611 CLEAR_FLAG (op, FLAG_LIFESAVE);
2649 enter_player_savebed (op); /* bring him home. */ 2612 enter_player_savebed (op); /* bring him home. */
2650 return 0; 2613 return 0;
2651} 2614}
2665 next = op->below; /* Make sure we have a good value, in case 2628 next = op->below; /* Make sure we have a good value, in case
2666 * we remove object 'op' 2629 * we remove object 'op'
2667 */ 2630 */
2668 if (QUERY_FLAG (op, FLAG_UNPAID)) 2631 if (QUERY_FLAG (op, FLAG_UNPAID))
2669 { 2632 {
2670 remove_ob (op); 2633 op->remove ();
2671 op->x = env->x; 2634 op->x = env->x;
2672 op->y = env->y; 2635 op->y = env->y;
2673 if (env->type == PLAYER) 2636 if (env->type == PLAYER)
2674 esrv_del_item (env->contr, op->count); 2637 esrv_del_item (env->contr, op->count);
2675 insert_ob_in_map (op, env->map, NULL, 0); 2638 insert_ob_in_map (op, env->map, NULL, 0);
2676 } 2639 }
2677 else if (op->inv) 2640 else if (op->inv)
2678 remove_unpaid_objects (op->inv, env); 2641 remove_unpaid_objects (op->inv, env);
2642
2679 op = next; 2643 op = next;
2680 } 2644 }
2681} 2645}
2682 2646
2683 2647
2698 strcpy (buf2, " R.I.P.\n\n"); 2662 strcpy (buf2, " R.I.P.\n\n");
2699 if (op->type == PLAYER) 2663 if (op->type == PLAYER)
2700 sprintf (buf, "%s the %s\n", &op->name, op->contr->title); 2664 sprintf (buf, "%s the %s\n", &op->name, op->contr->title);
2701 else 2665 else
2702 sprintf (buf, "%s\n", &op->name); 2666 sprintf (buf, "%s\n", &op->name);
2667
2703 strncat (buf2, " ", 20 - strlen (buf) / 2); 2668 strncat (buf2, " ", 20 - strlen (buf) / 2);
2704 strcat (buf2, buf); 2669 strcat (buf2, buf);
2705 if (op->type == PLAYER) 2670 if (op->type == PLAYER)
2706 sprintf (buf, "who was in level %d when killed\n", op->level); 2671 sprintf (buf, "who was in level %d when killed\n", op->level);
2707 else 2672 else
2708 sprintf (buf, "who was in level %d when died.\n\n", op->level); 2673 sprintf (buf, "who was in level %d when died.\n\n", op->level);
2674
2709 strncat (buf2, " ", 20 - strlen (buf) / 2); 2675 strncat (buf2, " ", 20 - strlen (buf) / 2);
2710 strcat (buf2, buf); 2676 strcat (buf2, buf);
2711 if (op->type == PLAYER) 2677 if (op->type == PLAYER)
2712 { 2678 {
2713 sprintf (buf, "by %s.\n\n", op->contr->killer); 2679 sprintf (buf, "by %s.\n\n", op->contr->killer);
2714 strncat (buf2, " ", 21 - strlen (buf) / 2); 2680 strncat (buf2, " ", 21 - strlen (buf) / 2);
2715 strcat (buf2, buf); 2681 strcat (buf2, buf);
2716 } 2682 }
2683
2717 strftime (buf, MAX_BUF, "%b %d %Y\n", localtime (&now)); 2684 strftime (buf, MAX_BUF, "%b %d %Y\n", localtime (&now));
2718 strncat (buf2, " ", 20 - strlen (buf) / 2); 2685 strncat (buf2, " ", 20 - strlen (buf) / 2);
2719 strcat (buf2, buf); 2686 strcat (buf2, buf);
2687
2720 return buf2; 2688 return buf2;
2721} 2689}
2722 2690
2723 2691
2724 2692
2972 /* restore player */ 2940 /* restore player */
2973 at = archetype::find ("poisoning"); 2941 at = archetype::find ("poisoning");
2974 tmp = present_arch_in_ob (at, op); 2942 tmp = present_arch_in_ob (at, op);
2975 if (tmp) 2943 if (tmp)
2976 { 2944 {
2977 remove_ob (tmp); 2945 tmp->destroy ();
2978 free_object (tmp);
2979 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed"); 2946 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed");
2980 } 2947 }
2981 2948
2982 at = archetype::find ("confusion"); 2949 at = archetype::find ("confusion");
2983 tmp = present_arch_in_ob (at, op); 2950 tmp = present_arch_in_ob (at, op);
2984 if (tmp) 2951 if (tmp)
2985 { 2952 {
2986 remove_ob (tmp); 2953 tmp->destroy ();
2987 free_object (tmp);
2988 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer"); 2954 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer");
2989 } 2955 }
2990 2956
2991 cure_disease (op, 0); /* remove any disease */ 2957 cure_disease (op, 0); /* remove any disease */
2992 op->stats.hp = op->stats.maxhp; 2958 op->stats.hp = op->stats.maxhp;
3169 /* determine_god() seems to not work sometimes... why is this? 3135 /* determine_god() seems to not work sometimes... why is this?
3170 Should I be using something else? GD */ 3136 Should I be using something else? GD */
3171 const char *god = determine_god (op); 3137 const char *god = determine_god (op);
3172 3138
3173 if (god && (strcmp (god, "none"))) 3139 if (god && (strcmp (god, "none")))
3174 new_draw_info_format (NDI_UNIQUE, 0, op, "For a brief " "moment you feel the holy presence of %s protecting" " you.", god); 3140 new_draw_info_format (NDI_UNIQUE, 0, op, "For a brief moment you feel the holy presence of %s protecting" " you.", god);
3175 else 3141 else
3176 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you" " feel a holy presence protecting you."); 3142 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you feel a holy presence protecting you.");
3177 } 3143 }
3144#else
3145 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you" " feel a holy presence protecting you from losing yourself completely.");
3178#endif 3146#endif
3179 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you" " feel a holy presence protecting you from losing yourself completely.");
3180 3147
3181 /* Put a gravestone up where the character 'almost' died. List the 3148 /* Put a gravestone up where the character 'almost' died. List the
3182 * exp loss on the stone. 3149 * exp loss on the stone.
3183 */ 3150 */
3184 tmp = arch_to_object (archetype::find ("gravestone")); 3151 tmp = arch_to_object (archetype::find ("gravestone"));
3189 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); 3156 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);
3190 tmp->msg = buf; 3157 tmp->msg = buf;
3191 tmp->x = op->x, tmp->y = op->y; 3158 tmp->x = op->x, tmp->y = op->y;
3192 insert_ob_in_map (tmp, op->map, NULL, 0); 3159 insert_ob_in_map (tmp, op->map, NULL, 0);
3193 3160
3194 /**************************************/ 3161 /**************************************/
3195 /* */ 3162 /* */
3196 /* Subtract the experience points, */ 3163 /* Subtract the experience points, */
3197 /* if we died cause of food, give us */ 3164 /* if we died cause of food, give us */
3198 /* food, and reset HP's... */ 3165 /* food, and reset HP's... */
3199 /* */ 3166 /* */
3200
3201 /**************************************/ 3167 /**************************************/
3202 3168
3203 /* remove any poisoning and confusion the character may be suffering. */ 3169 /* remove any poisoning and confusion the character may be suffering. */
3204 /* restore player */ 3170 /* restore player */
3205 at = archetype::find ("poisoning"); 3171 at = archetype::find ("poisoning");
3206 tmp = present_arch_in_ob (at, op); 3172 tmp = present_arch_in_ob (at, op);
3173
3207 if (tmp) 3174 if (tmp)
3208 { 3175 {
3209 remove_ob (tmp); 3176 tmp->destroy ();
3210 free_object (tmp);
3211 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed"); 3177 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed");
3212 } 3178 }
3213 3179
3214 at = archetype::find ("confusion"); 3180 at = archetype::find ("confusion");
3215 tmp = present_arch_in_ob (at, op); 3181 tmp = present_arch_in_ob (at, op);
3216 if (tmp) 3182 if (tmp)
3217 { 3183 {
3218 remove_ob (tmp); 3184 tmp->destroy ();
3219 free_object (tmp);
3220 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer"); 3185 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer");
3221 } 3186 }
3187
3222 cure_disease (op, 0); /* remove any disease */ 3188 cure_disease (op, 0); /* remove any disease */
3223 3189
3224 /*add_exp(op, (op->stats.exp * -0.20)); */ 3190 /*add_exp(op, (op->stats.exp * -0.20)); */
3225 apply_death_exp_penalty (op); 3191 apply_death_exp_penalty (op);
3226 if (op->stats.food < 100) 3192 if (op->stats.food < 100)
3236 */ 3202 */
3237 3203
3238 if (is_in_shop (op)) 3204 if (is_in_shop (op))
3239 remove_unpaid_objects (op->inv, op); 3205 remove_unpaid_objects (op->inv, op);
3240 3206
3241 /****************************************/ 3207 /****************************************/
3242 /* */ 3208 /* */
3243 /* Move player to his current respawn- */ 3209 /* Move player to his current respawn- */
3244 /* position (usually last savebed) */ 3210 /* position (usually last savebed) */
3245 /* */ 3211 /* */
3246
3247 /****************************************/ 3212 /****************************************/
3248 3213
3249 enter_player_savebed (op); 3214 enter_player_savebed (op);
3250 3215
3251 /* Save the player before inserting the force to reduce 3216 /* Save the player before inserting the force to reduce
3252 * chance of abuse. 3217 * chance of abuse.
3258 * at his savebed location, and that can have long lasting 3223 * at his savebed location, and that can have long lasting
3259 * spell effects. So first see if there is a spell effect 3224 * spell effects. So first see if there is a spell effect
3260 * on the space that might harm the player. 3225 * on the space that might harm the player.
3261 */ 3226 */
3262 will_kill_again = 0; 3227 will_kill_again = 0;
3263 for (tmp = get_map_ob (op->map, op->x, op->y); tmp; tmp = tmp->above) 3228 for (tmp = GET_MAP_OB (op->map, op->x, op->y); tmp; tmp = tmp->above)
3264 {
3265 if (tmp->type == SPELL_EFFECT) 3229 if (tmp->type == SPELL_EFFECT)
3266 will_kill_again |= tmp->attacktype; 3230 will_kill_again |= tmp->attacktype;
3267 } 3231
3268 if (will_kill_again) 3232 if (will_kill_again)
3269 { 3233 {
3270 object *force; 3234 object *force;
3271 int at; 3235 int at;
3272 3236
3274 /* 50 ticks should be enough time for the spell to abate */ 3238 /* 50 ticks should be enough time for the spell to abate */
3275 force->speed = 0.1; 3239 force->speed = 0.1;
3276 force->speed_left = -5.0; 3240 force->speed_left = -5.0;
3277 SET_FLAG (force, FLAG_APPLIED); 3241 SET_FLAG (force, FLAG_APPLIED);
3278 for (at = 0; at < NROFATTACKS; at++) 3242 for (at = 0; at < NROFATTACKS; at++)
3279 {
3280 if (will_kill_again & (1 << at)) 3243 if (will_kill_again & (1 << at))
3281 force->resist[at] = 100; 3244 force->resist[at] = 100;
3282 } 3245
3283 insert_ob_in_ob (force, op); 3246 insert_ob_in_ob (force, op);
3284 fix_player (op); 3247 fix_player (op);
3285 3248
3286 } 3249 }
3287 3250
3297 op->contr->party = NULL; 3260 op->contr->party = NULL;
3298 if (settings.set_title == TRUE) 3261 if (settings.set_title == TRUE)
3299 op->contr->own_title[0] = '\0'; 3262 op->contr->own_title[0] = '\0';
3300 new_draw_info (NDI_UNIQUE | NDI_ALL, 0, NULL, buf); 3263 new_draw_info (NDI_UNIQUE | NDI_ALL, 0, NULL, buf);
3301 check_score (op); 3264 check_score (op);
3265
3302 if (op->contr->ranges[range_golem] != NULL) 3266 if (op->contr->ranges[range_golem])
3303 { 3267 {
3304 remove_friendly_object (op->contr->ranges[range_golem]); 3268 remove_friendly_object (op->contr->ranges[range_golem]);
3305 remove_ob (op->contr->ranges[range_golem]); 3269 op->contr->ranges[range_golem]->destroy ();
3306 free_object (op->contr->ranges[range_golem]);
3307 op->contr->ranges[range_golem] = NULL; 3270 op->contr->ranges[range_golem] = 0;
3308 op->contr->golem_count = 0;
3309 } 3271 }
3272
3310 loot_object (op); /* Remove some of the items for good */ 3273 loot_object (op); /* Remove some of the items for good */
3311 remove_ob (op); 3274 op->remove ();
3312 op->direction = 0; 3275 op->direction = 0;
3313 3276
3314 if (!QUERY_FLAG (op, FLAG_WAS_WIZ) && op->stats.exp) 3277 if (!QUERY_FLAG (op, FLAG_WAS_WIZ) && op->stats.exp)
3315 { 3278 {
3316 delete_character (op->name, 0); 3279 delete_character (op->name, 0);
3367 } 3330 }
3368 3331
3369 for (tmp = op->inv; tmp != NULL; tmp = next) 3332 for (tmp = op->inv; tmp != NULL; tmp = next)
3370 { 3333 {
3371 next = tmp->below; 3334 next = tmp->below;
3372 if (tmp->type == EXPERIENCE || tmp->invisible) 3335 if (tmp->invisible)
3373 continue; 3336 continue;
3374 remove_ob (tmp); 3337 tmp->remove ();
3375 tmp->x = op->x, tmp->y = op->y; 3338 tmp->x = op->x, tmp->y = op->y;
3376 if (tmp->type == CONTAINER) 3339 if (tmp->type == CONTAINER)
3377 { /* empty container to ground */ 3340 { /* empty container to ground */
3378 loot_object (tmp); 3341 loot_object (tmp);
3379 } 3342 }
3380 if (!QUERY_FLAG (tmp, FLAG_UNIQUE) && (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || QUERY_FLAG (tmp, FLAG_NO_DROP) || !(RANDOM () % 3))) 3343 if (!QUERY_FLAG (tmp, FLAG_UNIQUE) && (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || QUERY_FLAG (tmp, FLAG_NO_DROP) || !(RANDOM () % 3)))
3381 { 3344 {
3382 if (tmp->nrof > 1) 3345 if (tmp->nrof > 1)
3383 { 3346 {
3384 tmp2 = get_split_ob (tmp, 1 + RANDOM () % (tmp->nrof - 1)); 3347 tmp2 = get_split_ob (tmp, 1 + RANDOM () % (tmp->nrof - 1));
3385 free_object (tmp2); 3348 tmp2->destroy ();
3386 insert_ob_in_map (tmp, op->map, NULL, 0); 3349 insert_ob_in_map (tmp, op->map, NULL, 0);
3387 } 3350 }
3388 else 3351 else
3389 free_object (tmp); 3352 tmp->destroy ();
3390 } 3353 }
3391 else 3354 else
3392 insert_ob_in_map (tmp, op->map, NULL, 0); 3355 insert_ob_in_map (tmp, op->map, NULL, 0);
3393 } 3356 }
3394} 3357}
3459 if (op->type == PLAYER) 3422 if (op->type == PLAYER)
3460 new_draw_info_format (NDI_UNIQUE, 0, op, "You cast %s.", &spob->name); 3423 new_draw_info_format (NDI_UNIQUE, 0, op, "You cast %s.", &spob->name);
3461 3424
3462 cast_spell (op, throw_ob, dir, spob, NULL); 3425 cast_spell (op, throw_ob, dir, spob, NULL);
3463 3426
3464 if (!QUERY_FLAG (throw_ob, FLAG_REMOVED)) 3427 throw_ob->destroy ();
3465 remove_ob (throw_ob);
3466 free_object (throw_ob);
3467} 3428}
3468 3429
3469void 3430void
3470make_visible (object *op) 3431make_visible (object *op)
3471{ 3432{
3485 object *tmp = NULL; 3446 object *tmp = NULL;
3486 3447
3487 if (QUERY_FLAG (&op->arch->clone, FLAG_UNDEAD)) 3448 if (QUERY_FLAG (&op->arch->clone, FLAG_UNDEAD))
3488 return 1; 3449 return 1;
3489 3450
3490 if (op->type == PLAYER)
3491 for (tmp = op->inv; tmp; tmp = tmp->below)
3492 if (tmp->type == EXPERIENCE && tmp->stats.Wis)
3493 if (QUERY_FLAG (tmp, FLAG_UNDEAD))
3494 return 1;
3495 return 0; 3451 return 0;
3496} 3452}
3497 3453
3498/* look at the surrounding terrain to determine 3454/* look at the surrounding terrain to determine
3499 * the hideability of this object. Positive levels 3455 * the hideability of this object. Positive levels
3614 if (mflags & P_OUT_OF_MAP) 3570 if (mflags & P_OUT_OF_MAP)
3615 continue; 3571 continue;
3616 if (OB_TYPE_MOVE_BLOCK (who, GET_MAP_MOVE_BLOCK (m, x, y))) 3572 if (OB_TYPE_MOVE_BLOCK (who, GET_MAP_MOVE_BLOCK (m, x, y)))
3617 continue; 3573 continue;
3618 3574
3619 for (tmp = get_map_ob (m, x, y); tmp; tmp = tmp->above) 3575 for (tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above)
3620 { 3576 {
3621 if ((player ||friendly) &&QUERY_FLAG (tmp, FLAG_MONSTER) && !QUERY_FLAG (tmp, FLAG_UNAGGRESSIVE)) 3577 if ((player ||friendly) &&QUERY_FLAG (tmp, FLAG_MONSTER) && !QUERY_FLAG (tmp, FLAG_UNAGGRESSIVE))
3622 return 1; 3578 return 1;
3623 else if (tmp->type == PLAYER) 3579 else if (tmp->type == PLAYER)
3624 { 3580 {
3678 3634
3679 /* only the viewable area the player sees is updated by LOS 3635 /* only the viewable area the player sees is updated by LOS
3680 * code, so we need to restrict ourselves to that range of values 3636 * code, so we need to restrict ourselves to that range of values
3681 * for any meaningful values. 3637 * for any meaningful values.
3682 */ 3638 */
3683 if (FABS (dx) <= (pl->contr->socket.mapx / 2) && 3639 if (FABS (dx) <= (pl->contr->socket->mapx / 2) &&
3684 FABS (dy) <= (pl->contr->socket.mapy / 2) && 3640 FABS (dy) <= (pl->contr->socket->mapy / 2) &&
3685 !pl->contr->blocked_los[dx + (pl->contr->socket.mapx / 2)][dy + (pl->contr->socket.mapy / 2)]) 3641 !pl->contr->blocked_los[dx + (pl->contr->socket->mapx / 2)][dy + (pl->contr->socket->mapy / 2)])
3686 return 1; 3642 return 1;
3687 op = op->more; 3643 op = op->more;
3688 } 3644 }
3689 return 0; 3645 return 0;
3690} 3646}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines