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.53 by root, Fri Dec 22 16:03:21 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
42player * 37player *
43find_player (const char *plname) 38find_player (const char *plname)
44{ 39{
45 player *pl; 40 player *pl;
46 41
47 for (pl = first_player; pl != NULL; pl = pl->next) 42 for (pl = first_player; pl; pl = pl->next)
48 { 43 {
49 if (pl->ob != NULL && !strcmp (query_name (pl->ob), plname)) 44 if (pl->obL && !strcmp (query_name (pl->ob), plname))
50 return pl; 45 return pl;
51 }; 46 };
47
52 return NULL; 48 return 0;
53} 49}
54 50
55player * 51player *
56find_player_partial_name (const char *plname) 52find_player_partial_name (const char *plname)
57{ 53{
58 player *pl; 54 player *pl;
59 player *found = NULL; 55 player *found = NULL;
60 size_t namelen = strlen (plname); 56 size_t namelen = strlen (plname);
61 57
62 for (pl = first_player; pl != NULL; pl = pl->next) 58 for (pl = first_player; pl; pl = pl->next)
63 { 59 {
64 if ((size_t) strlen (pl->ob->name) < namelen) 60 if ((size_t) strlen (pl->ob->name) < namelen)
65 continue; 61 continue;
66 62
67 if (!strcmp (pl->ob->name, plname)) 63 if (!strcmp (pl->ob->name, plname))
68 return pl; 64 return pl;
69 65
70 if (!strncasecmp (pl->ob->name, plname, namelen)) 66 if (!strncasecmp (pl->ob->name, plname, namelen))
71 { 67 {
72 if (found) 68 if (found)
73 return NULL; 69 return 0;
74 70
75 found = pl; 71 found = pl;
76 } 72 }
77 } 73 }
74
78 return found; 75 return found;
79} 76}
80 77
81void 78void
82display_motd (const object *op) 79display_motd (const object *op)
87 int comp; 84 int comp;
88 int size; 85 int size;
89 86
90 sprintf (buf, "%s/%s", settings.confdir, settings.motd); 87 sprintf (buf, "%s/%s", settings.confdir, settings.motd);
91 if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL) 88 if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL)
92 {
93 return; 89 return;
94 } 90
95 motd[0] = '\0'; 91 motd[0] = '\0';
96 size = 0; 92 size = 0;
93
97 while (fgets (buf, MAX_BUF, fp) != NULL) 94 while (fgets (buf, MAX_BUF, fp))
98 { 95 {
99 if (*buf == '#') 96 if (*buf == '#')
100 continue; 97 continue;
98
101 strncat (motd + size, buf, HUGE_BUF - size); 99 strncat (motd + size, buf, HUGE_BUF - size);
102 size += strlen (buf); 100 size += strlen (buf);
103 } 101 }
102
104 draw_ext_info (NDI_UNIQUE | NDI_GREEN, 0, op, MSG_TYPE_MOTD, MSG_SUBTYPE_NONE, motd, NULL); 103 draw_ext_info (NDI_UNIQUE | NDI_GREEN, 0, op, MSG_TYPE_MOTD, MSG_SUBTYPE_NONE, motd, NULL);
105 close_and_delete (fp, comp); 104 close_and_delete (fp, comp);
106} 105}
107 106
108void 107void
114 int comp; 113 int comp;
115 int size; 114 int size;
116 115
117 sprintf (buf, "%s/%s", settings.confdir, settings.rules); 116 sprintf (buf, "%s/%s", settings.confdir, settings.rules);
118 if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL) 117 if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL)
119 {
120 return; 118 return;
121 } 119
122 rules[0] = '\0'; 120 rules[0] = '\0';
123 size = 0; 121 size = 0;
122
124 while (fgets (buf, MAX_BUF, fp) != NULL) 123 while (fgets (buf, MAX_BUF, fp))
125 { 124 {
126 if (*buf == '#') 125 if (*buf == '#')
127 continue; 126 continue;
127
128 if (size + strlen (buf) >= HUGE_BUF) 128 if (size + strlen (buf) >= HUGE_BUF)
129 { 129 {
130 LOG (llevDebug, "Warning, rules size is > %d bytes.\n", HUGE_BUF); 130 LOG (llevDebug, "Warning, rules size is > %d bytes.\n", HUGE_BUF);
131 break; 131 break;
132 } 132 }
133
133 strncat (rules + size, buf, HUGE_BUF - size); 134 strncat (rules + size, buf, HUGE_BUF - size);
134 size += strlen (buf); 135 size += strlen (buf);
135 } 136 }
137
136 draw_ext_info (NDI_UNIQUE | NDI_GREEN, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_RULES, rules, NULL); 138 draw_ext_info (NDI_UNIQUE | NDI_GREEN, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_RULES, rules, NULL);
137 close_and_delete (fp, comp); 139 close_and_delete (fp, comp);
138} 140}
139 141
140void 142void
148 int size; 150 int size;
149 151
150 sprintf (buf, "%s/%s", settings.confdir, settings.news); 152 sprintf (buf, "%s/%s", settings.confdir, settings.news);
151 if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL) 153 if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL)
152 return; 154 return;
155
153 news[0] = '\0'; 156 news[0] = '\0';
154 subject[0] = '\0'; 157 subject[0] = '\0';
155 size = 0; 158 size = 0;
159
156 while (fgets (buf, MAX_BUF, fp) != NULL) 160 while (fgets (buf, MAX_BUF, fp) != NULL)
157 { 161 {
158 if (*buf == '#') 162 if (*buf == '#')
159 continue; 163 continue;
164
160 if (*buf == '%') 165 if (*buf == '%')
161 { /* send one news */ 166 { /* send one news */
162 if (size > 0) 167 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 */ 168 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); 169 strcpy (subject, buf + 1);
191 return 0; 196 return 0;
192 197
193 for (; *cp != '\0'; cp++) 198 for (; *cp != '\0'; cp++)
194 if (!((*cp >= 'a' && *cp <= 'z') || (*cp >= 'A' && *cp <= 'Z')) && *cp != '-' && *cp != '_') 199 if (!((*cp >= 'a' && *cp <= 'z') || (*cp >= 'A' && *cp <= 'Z')) && *cp != '-' && *cp != '_')
195 return 0; 200 return 0;
201
196 return 1; 202 return 1;
197} 203}
198 204
199/* This no longer sets the player map. Also, it now updates 205/* This no longer sets the player map. Also, it now updates
200 * all the pointers so the caller doesn't need to do that. 206 * all the pointers so the caller doesn't need to do that.
208 * the one that is passed. 214 * the one that is passed.
209 */ 215 */
210static player * 216static player *
211get_player (player *p) 217get_player (player *p)
212{ 218{
213 object *op = arch_to_object (get_player_archetype (NULL)); 219 object *op = arch_to_object (get_player_archetype (0));
214 int i; 220 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 221
238 /* Clears basically the entire player structure except 222 /* Clears basically the entire player structure except
239 * for next and socket. 223 * for next and socket.
240 */ 224 */
241 p->clear (); 225 p->clear ();
260 op->speed_left = 0.5; 244 op->speed_left = 0.5;
261 op->speed = 1.0; 245 op->speed = 1.0;
262 op->direction = 5; /* So player faces south */ 246 op->direction = 5; /* So player faces south */
263 op->stats.wc = 2; 247 op->stats.wc = 2;
264 op->run_away = 25; /* Then we panick... */ 248 op->run_away = 25; /* Then we panick... */
249
250 {
251 int oldmon = p->ns->monitor_spells; // what a hack
265 p->socket.monitor_spells = 0; /* Needed because esrv_update_spells( ) gets called by roll_stats */ 252 p->ns->monitor_spells = 0; /* Needed because esrv_update_spells( ) gets called by roll_stats */
266
267 roll_stats (op); 253 roll_stats (op);
254 p->ns->monitor_spells = oldmon;
255 }
268 p->state = ST_ROLL_STAT; 256 p->ns->state = ST_ROLL_STAT;
269 clear_los (op); 257 clear_los (op);
270 258
271 p->gen_sp_armour = 10; 259 p->gen_sp_armour = 10;
272 p->last_speed = -1; 260 p->last_speed = -1;
273 p->shoottype = range_none; 261 p->shoottype = range_none;
277 p->usekeys = containers; 265 p->usekeys = containers;
278 p->last_weapon_sp = -1; 266 p->last_weapon_sp = -1;
279 p->peaceful = 1; /* default peaceful */ 267 p->peaceful = 1; /* default peaceful */
280 p->do_los = 1; 268 p->do_los = 1;
281 p->explore = 0; 269 p->explore = 0;
282 p->no_shout = 0; /* default can shout */
283 270
284 assign (p->title, op->arch->clone.name); 271 assign (p->title, op->arch->clone.name);
285 op->race = op->arch->clone.race; 272 op->race = op->arch->clone.race;
286 273
287 CLEAR_FLAG (op, FLAG_READY_SKILL); 274 CLEAR_FLAG (op, FLAG_READY_SKILL);
294 for (i = 0; i < NUM_SKILLS; i++) 281 for (i = 0; i < NUM_SKILLS; i++)
295 { 282 {
296 p->last_skill_exp[i] = -1; 283 p->last_skill_exp[i] = -1;
297 p->last_skill_ob[i] = NULL; 284 p->last_skill_ob[i] = NULL;
298 } 285 }
286
299 for (i = 0; i < NROFATTACKS; i++) 287 for (i = 0; i < NROFATTACKS; i++)
300 {
301 p->last_resist[i] = -1; 288 p->last_resist[i] = -1;
302 } 289
303 p->last_stats.exp = -1; 290 p->last_stats.exp = -1;
304 p->last_weight = (uint32) - 1; 291 p->last_weight = (uint32) - 1;
305 292
306 p->socket.update_look = 0; 293 p->ns->update_look = 0;
307 p->socket.look_position = 0; 294 p->ns->look_position = 0;
295
308 return p; 296 return p;
309} 297}
310 298
311/* This loads the first map an puts the player on it. */ 299/* This loads the first map an puts the player on it. */
312static void 300static void
313set_first_map (object *op) 301set_first_map (object *op)
314{ 302{
315 strcpy (op->contr->maplevel, first_map_path); 303 strcpy (op->contr->maplevel, first_map_path);
316 op->x = -1; 304 op->x = -1;
317 op->y = -1; 305 op->y = -1;
318 enter_exit (op, NULL); 306 enter_exit (op, 0);
319} 307}
320 308
321/* Tries to add player on the connection passwd in ns. 309/* 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 310 * All we can really get in this is some settings like host and display
323 * mode. 311 * mode.
324 */ 312 */
325 313
326int 314int
327add_player (NewSocket * ns) 315add_player (client *ns)
328{ 316{
329 player *p; 317 player *p = new player;
330 318
319 p->ns = ns;
320 ns->pl = p;
321
322 p->next = first_player;
323 first_player = p;
324
331 p = get_player (NULL); 325 p = get_player (p);
332 p->socket = *ns;
333 p->socket.faces_sent = (uint8 *) malloc (p->socket.faces_sent_len * sizeof (*p->socket.faces_sent));
334 326
335 if (p->socket.faces_sent == NULL)
336 fatal (OUT_OF_MEMORY);
337
338 memcpy (p->socket.faces_sent, ns->faces_sent, p->socket.faces_sent_len * sizeof (*p->socket.faces_sent));
339 /* Needed because the socket we just copied over needs to be cleared.
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); 327 set_first_map (p->ob);
345 328
346 CLEAR_FLAG (p->ob, FLAG_FRIENDLY); 329 CLEAR_FLAG (p->ob, FLAG_FRIENDLY);
347 add_friendly_object (p->ob); 330 add_friendly_object (p->ob);
348 send_rules (p->ob); 331 send_rules (p->ob);
349 send_news (p->ob); 332 send_news (p->ob);
350 display_motd (p->ob); 333 display_motd (p->ob);
334
351 get_name (p->ob); 335 get_name (p->ob);
352 336
353 return 0; 337 return 0;
354} 338}
355 339
367 { 351 {
368 if (at == NULL || at->next == NULL) 352 if (at == NULL || at->next == NULL)
369 at = first_archetype; 353 at = first_archetype;
370 else 354 else
371 at = at->next; 355 at = at->next;
356
372 if (at->clone.type == PLAYER) 357 if (at->clone.type == PLAYER)
373 return at; 358 return at;
359
374 if (at == start) 360 if (at == start)
375 { 361 {
376 LOG (llevError, "No Player archetypes\n"); 362 LOG (llevError, "No Player archetypes\n");
377 exit (-1); 363 exit (-1);
378 } 364 }
379 } 365 }
380} 366}
381
382 367
383object * 368object *
384get_nearest_player (object *mon) 369get_nearest_player (object *mon)
385{ 370{
386 object *op = NULL; 371 object *op = NULL;
646 (op->type == ARMOUR || op->type == BOOTS || 631 (op->type == ARMOUR || op->type == BOOTS ||
647 op->type == CLOAK || op->type == HELMET || 632 op->type == CLOAK || op->type == HELMET ||
648 op->type == SHIELD || op->type == GLOVES || 633 op->type == SHIELD || op->type == GLOVES ||
649 op->type == BRACERS || op->type == GIRDLE)) || (!QUERY_FLAG (pl, FLAG_USE_WEAPON) && op->type == WEAPON)) 634 op->type == BRACERS || op->type == GIRDLE)) || (!QUERY_FLAG (pl, FLAG_USE_WEAPON) && op->type == WEAPON))
650 { 635 {
651 remove_ob (op); 636 op->destroy ();
652 free_object (op);
653 continue; 637 continue;
654 } 638 }
655 } 639 }
656 640
657 /* This really needs to be better - we should really give 641 /* This really needs to be better - we should really give
668 if (tmp->type == op->type && tmp->name == op->name) 652 if (tmp->type == op->type && tmp->name == op->name)
669 break; 653 break;
670 654
671 if (tmp) 655 if (tmp)
672 { 656 {
673 remove_ob (op); 657 op->destroy ();
674 free_object (op);
675 LOG (llevError, "give_initial_items: Removing duplicate object %s\n", &tmp->name); 658 LOG (llevError, "give_initial_items: Removing duplicate object %s\n", &tmp->name);
676 continue; 659 continue;
677 } 660 }
661
678 if (op->nrof > 1) 662 if (op->nrof > 1)
679 op->nrof = 1; 663 op->nrof = 1;
680 } 664 }
681 665
682 if (op->type == SPELLBOOK && op->inv) 666 if (op->type == SPELLBOOK && op->inv)
694 CLEAR_FLAG (op, FLAG_CURSED); 678 CLEAR_FLAG (op, FLAG_CURSED);
695 CLEAR_FLAG (op, FLAG_DAMNED); 679 CLEAR_FLAG (op, FLAG_DAMNED);
696 } 680 }
697 if (op->type == SPELL) 681 if (op->type == SPELL)
698 { 682 {
699 remove_ob (op); 683 op->destroy ();
700 free_object (op);
701 continue; 684 continue;
702 } 685 }
703 else if (op->type == SKILL) 686 else if (op->type == SKILL)
704 { 687 {
705 SET_FLAG (op, FLAG_CAN_USE_SKILL); 688 SET_FLAG (op, FLAG_CAN_USE_SKILL);
717 700
718void 701void
719get_name (object *op) 702get_name (object *op)
720{ 703{
721 op->contr->write_buf[0] = '\0'; 704 op->contr->write_buf[0] = '\0';
722 op->contr->state = ST_GET_NAME; 705 op->contr->ns->state = ST_GET_NAME;
723 send_query (&op->contr->socket, 0, "What is your name?\n:"); 706 send_query (op->contr->ns, 0, "What is your name?\n:");
724} 707}
725 708
726void 709void
727get_password (object *op) 710get_password (object *op)
728{ 711{
729 op->contr->write_buf[0] = '\0'; 712 op->contr->write_buf[0] = '\0';
730 op->contr->state = ST_GET_PASSWORD; 713 op->contr->ns->state = ST_GET_PASSWORD;
731 send_query (&op->contr->socket, CS_QUERY_HIDEINPUT, "What is your password?\n:"); 714 send_query (op->contr->ns, CS_QUERY_HIDEINPUT, "What is your password?\n:");
732} 715}
733 716
734void 717void
735play_again (object *op) 718play_again (object *op)
736{ 719{
737 op->contr->state = ST_PLAY_AGAIN; 720 op->contr->ns->state = ST_PLAY_AGAIN;
738 op->chosen_skill = NULL; 721 op->chosen_skill = NULL;
739 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "Do you want to play again (a/q)?"); 722 send_query (op->contr->ns, 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 723 /* a bit of a hack, but there are various places early in th
741 * player creation process that a user can quit (eg, roll 724 * player creation process that a user can quit (eg, roll
742 * stats) that isn't removing the player. Taking a quick 725 * stats) that isn't removing the player. Taking a quick
743 * look, there are many places that call play_again without 726 * look, there are many places that call play_again without
744 * removing the player - it probably makes more sense 727 * removing the player - it probably makes more sense
745 * to leave it to play_again to remove the object in all 728 * to leave it to play_again to remove the object in all
746 * cases. 729 * cases.
747 */ 730 */
748 if (!QUERY_FLAG (op, FLAG_REMOVED)) 731 if (!QUERY_FLAG (op, FLAG_REMOVED))
749 remove_ob (op); 732 op->remove ();
733
750 /* Need to set this to null - otherwise, it could point to garbage, 734 /* 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 735 * and draw() doesn't check to see if the player is removed, only if
752 * the map is null or not swapped out. 736 * the map is null or not swapped out.
753 */ 737 */
754 op->map = NULL; 738 op->map = NULL;
792void 776void
793confirm_password (object *op) 777confirm_password (object *op)
794{ 778{
795 779
796 op->contr->write_buf[0] = '\0'; 780 op->contr->write_buf[0] = '\0';
797 op->contr->state = ST_CONFIRM_PASSWORD; 781 op->contr->ns->state = ST_CONFIRM_PASSWORD;
798 send_query (&op->contr->socket, CS_QUERY_HIDEINPUT, "Please type your password again.\n:"); 782 send_query (op->contr->ns, CS_QUERY_HIDEINPUT, "Please type your password again.\n:");
799} 783}
800 784
801void 785void
802get_party_password (object *op, partylist *party) 786get_party_password (object *op, partylist *party)
803{ 787{
805 { 789 {
806 LOG (llevError, "get_party_password(): tried to make player %s join a NULL party", &op->name); 790 LOG (llevError, "get_party_password(): tried to make player %s join a NULL party", &op->name);
807 return; 791 return;
808 } 792 }
809 op->contr->write_buf[0] = '\0'; 793 op->contr->write_buf[0] = '\0';
810 op->contr->state = ST_GET_PARTY_PASSWORD; 794 op->contr->ns->state = ST_GET_PARTY_PASSWORD;
811 op->contr->party_to_join = party; 795 op->contr->party_to_join = party;
812 send_query (&op->contr->socket, CS_QUERY_HIDEINPUT, "What is the password?\n:"); 796 send_query (op->contr->ns, CS_QUERY_HIDEINPUT, "What is the password?\n:");
813} 797}
814 798
815 799
816/* This rolls four 1-6 rolls and sums the best 3 of the 4. */ 800/* This rolls four 1-6 rolls and sums the best 3 of the 4. */
817int 801int
914 898
915void 899void
916Roll_Again (object *op) 900Roll_Again (object *op)
917{ 901{
918 esrv_new_player (op->contr, 0); 902 esrv_new_player (op->contr, 0);
919 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, 903 send_query (op->contr->ns, 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)? "); 904 "[y] to roll new stats [n] to use stats\n[1-7] [1-7] to swap stats.\nRoll again (y/n/1-7)? ");
921} 905}
922 906
923void 907void
924Swap_Stat (object *op, int Swap_Second) 908Swap_Stat (object *op, int Swap_Second)
991 new_draw_info (NDI_UNIQUE, 0, op, buf); 975 new_draw_info (NDI_UNIQUE, 0, op, buf);
992 } 976 }
993 else 977 else
994 Swap_Stat (op, stat_trans[keynum]); 978 Swap_Stat (op, stat_trans[keynum]);
995 979
996 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, ""); 980 send_query (op->contr->ns, CS_QUERY_SINGLECHAR, "");
997 return 1; 981 return 1;
998 } 982 }
999 switch (key) 983 switch (key)
1000 { 984 {
1001 case 'n': 985 case 'n':
1015 enter_exit (op, NULL); 999 enter_exit (op, NULL);
1016#endif 1000#endif
1017 SET_ANIMATION (op, 2); /* So player faces south */ 1001 SET_ANIMATION (op, 2); /* So player faces south */
1018 /* Enter exit adds a player otherwise */ 1002 /* Enter exit adds a player otherwise */
1019 add_statbonus (op); 1003 add_statbonus (op);
1020 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, 1004 send_query (op->contr->ns, CS_QUERY_SINGLECHAR,
1021 "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n"); 1005 "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n");
1022 op->contr->state = ST_CHANGE_CLASS; 1006 op->contr->ns->state = ST_CHANGE_CLASS;
1023 if (op->msg) 1007 if (op->msg)
1024 new_draw_info (NDI_BLUE, 0, op, op->msg); 1008 new_draw_info (NDI_BLUE, 0, op, op->msg);
1025 return 0; 1009 return 0;
1026 } 1010 }
1027 case 'y': 1011 case 'y':
1028 case 'Y': 1012 case 'Y':
1029 roll_stats (op); 1013 roll_stats (op);
1030 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, ""); 1014 send_query (op->contr->ns, CS_QUERY_SINGLECHAR, "");
1031 return 1; 1015 return 1;
1032 1016
1033 case 'q': 1017 case 'q':
1034 case 'Q': 1018 case 'Q':
1035 play_again (op); 1019 play_again (op);
1036 return 1; 1020 return 1;
1037 1021
1038 default: 1022 default:
1039 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "Yes, No, Quit or 1-6. Roll again?"); 1023 send_query (op->contr->ns, CS_QUERY_SINGLECHAR, "Yes, No, Quit or 1-6. Roll again?");
1040 return 0; 1024 return 0;
1041 } 1025 }
1042 return 0; 1026 return 0;
1043} 1027}
1044 1028
1054{ 1038{
1055 int tmp_loop; 1039 int tmp_loop;
1056 1040
1057 if (key == 'q' || key == 'Q') 1041 if (key == 'q' || key == 'Q')
1058 { 1042 {
1059 remove_ob (op); 1043 op->remove ();
1060 play_again (op); 1044 play_again (op);
1061 return 0; 1045 return 0;
1062 } 1046 }
1063 if (key == 'd' || key == 'D') 1047 if (key == 'd' || key == 'D')
1064 { 1048 {
1065 char buf[MAX_BUF]; 1049 char buf[MAX_BUF];
1066 1050
1067 /* this must before then initial items are given */ 1051 /* this must before then initial items are given */
1068 esrv_new_player (op->contr, op->weight + op->carrying); 1052 esrv_new_player (op->contr, op->weight + op->carrying);
1053
1069 create_treasure (find_treasurelist ("starting_wealth"), op, 0, 0, 0); 1054 treasurelist *tl = find_treasurelist ("starting_wealth");
1055 if (tl)
1056 create_treasure (tl, op, 0, 0, 0);
1070 1057
1071 INVOKE_PLAYER (BIRTH, op->contr); 1058 INVOKE_PLAYER (BIRTH, op->contr);
1072 INVOKE_PLAYER (LOGIN, op->contr); 1059 INVOKE_PLAYER (LOGIN, op->contr);
1073 1060
1074 op->contr->state = ST_PLAYING; 1061 op->contr->ns->state = ST_PLAYING;
1075 1062
1076 if (op->msg) 1063 if (op->msg)
1077 op->msg = NULL; 1064 op->msg = NULL;
1078 1065
1079 /* We create this now because some of the unique maps will need it 1066 /* We create this now because some of the unique maps will need it
1099 { 1086 {
1100 object *tmp; 1087 object *tmp;
1101 char mapname[MAX_BUF]; 1088 char mapname[MAX_BUF];
1102 1089
1103 snprintf (mapname, MAX_BUF - 1, "%s/%s", first_map_ext_path, &op->arch->name); 1090 snprintf (mapname, MAX_BUF - 1, "%s/%s", first_map_ext_path, &op->arch->name);
1104 tmp = get_object (); 1091 tmp = object::create ();
1105 EXIT_PATH (tmp) = mapname; 1092 EXIT_PATH (tmp) = mapname;
1106 EXIT_X (tmp) = op->x; 1093 EXIT_X (tmp) = op->x;
1107 EXIT_Y (tmp) = op->y; 1094 EXIT_Y (tmp) = op->y;
1108 enter_exit (op, tmp); /* we don't really care if it succeeded; 1095 enter_exit (op, tmp); /* we don't really care if it succeeded;
1109 * if the map isn't there, then stay on the 1096 * if the map isn't there, then stay on the
1110 * default initial map */ 1097 * default initial map */
1111 free_object (tmp); 1098 tmp->destroy ();
1112 } 1099 }
1113 else 1100 else
1114 {
1115 LOG (llevDebug, "first_map_ext_path not set\n"); 1101 LOG (llevDebug, "first_map_ext_path not set\n");
1116 } 1102
1117 return 0; 1103 return 0;
1118 } 1104 }
1119 1105
1120 /* Following actually changes the race - this is the default command 1106 /* Following actually changes the race - this is the default command
1121 * if we don't match with one of the options above. 1107 * if we don't match with one of the options above.
1126 { 1112 {
1127 shstr name = op->name; 1113 shstr name = op->name;
1128 int x = op->x, y = op->y; 1114 int x = op->x, y = op->y;
1129 1115
1130 remove_statbonus (op); 1116 remove_statbonus (op);
1131 remove_ob (op); 1117 op->remove ();
1132 op->arch = get_player_archetype (op->arch); 1118 op->arch = get_player_archetype (op->arch);
1133 copy_object (&op->arch->clone, op); 1119 op->arch->clone.copy_to (op);
1134 op->instantiate (); 1120 op->instantiate ();
1135 op->stats = op->contr->orig_stats; 1121 op->stats = op->contr->orig_stats;
1136 op->name = op->name_pl = name; 1122 op->name = op->name_pl = name;
1137 op->x = x; 1123 op->x = x;
1138 op->y = y; 1124 op->y = y;
1151 op->stats.grace = 0; 1137 op->stats.grace = 0;
1152 1138
1153 if (op->msg) 1139 if (op->msg)
1154 new_draw_info (NDI_BLUE, 0, op, op->msg); 1140 new_draw_info (NDI_BLUE, 0, op, op->msg);
1155 1141
1156 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "Press any key for the next race.\nPress `d' to play this race.\n"); 1142 send_query (op->contr->ns, CS_QUERY_SINGLECHAR, "Press any key for the next race.\nPress `d' to play this race.\n");
1157 return 0; 1143 return 0;
1158} 1144}
1159 1145
1160int 1146int
1161key_confirm_quit (object *op, char key) 1147key_confirm_quit (object *op, char key)
1162{ 1148{
1163 char buf[MAX_BUF]; 1149 char buf[MAX_BUF];
1164 1150
1165 if (key != 'y' && key != 'Y' && key != 'q' && key != 'Q') 1151 if (key != 'y' && key != 'Y' && key != 'q' && key != 'Q')
1166 { 1152 {
1167 op->contr->state = ST_PLAYING; 1153 op->contr->ns->state = ST_PLAYING;
1168 new_draw_info (NDI_UNIQUE, 0, op, "OK, continuing to play."); 1154 new_draw_info (NDI_UNIQUE, 0, op, "OK, continuing to play.");
1169 return 1; 1155 return 1;
1170 } 1156 }
1171 1157
1172 INVOKE_PLAYER (LOGOUT, op->contr); 1158 INVOKE_PLAYER (LOGOUT, op->contr);
1241 { 1227 {
1242 op->enemy = NULL; 1228 op->enemy = NULL;
1243 CLEAR_FLAG (op, FLAG_SCARED); 1229 CLEAR_FLAG (op, FLAG_SCARED);
1244 return; 1230 return;
1245 } 1231 }
1232
1246 get_rangevector (op, op->enemy, &rv, 0); 1233 get_rangevector (op, op->enemy, &rv, 0);
1247 1234
1248 dir = absdir (4 + rv.direction); 1235 dir = absdir (4 + rv.direction);
1249 for (diff = 0; diff < 3; diff++) 1236 for (diff = 0; diff < 3; diff++)
1250 { 1237 {
1251 int m = 1 - (RANDOM () & 2); 1238 int m = 1 - (RANDOM () & 2);
1252 1239
1253 if (move_ob (op, absdir (dir + diff * m), op) || (diff == 0 && move_ob (op, absdir (dir - diff * m), op))) 1240 if (move_ob (op, absdir (dir + diff * m), op) || (diff == 0 && move_ob (op, absdir (dir - diff * m), op)))
1254 {
1255 return; 1241 return;
1256 }
1257 } 1242 }
1243
1258 /* Cornered, get rid of scared */ 1244 /* Cornered, get rid of scared */
1259 CLEAR_FLAG (op, FLAG_SCARED); 1245 CLEAR_FLAG (op, FLAG_SCARED);
1260 op->enemy = NULL; 1246 op->enemy = NULL;
1261} 1247}
1262 1248
1426 /* question: don't pick up known-poisonous stuff? */ 1412 /* question: don't pick up known-poisonous stuff? */
1427 if (op->contr->mode & PU_FOOD) 1413 if (op->contr->mode & PU_FOOD)
1428 if (tmp->type == FOOD) 1414 if (tmp->type == FOOD)
1429 { 1415 {
1430 pick_up (op, tmp); 1416 pick_up (op, tmp);
1431 if (0)
1432 fprintf (stderr, "FOOD\n");
1433 continue; 1417 continue;
1434 } 1418 }
1419
1435 if (op->contr->mode & PU_DRINK) 1420 if (op->contr->mode & PU_DRINK)
1436 if (tmp->type == DRINK || (tmp->type == POISON && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))) 1421 if (tmp->type == DRINK || (tmp->type == POISON && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)))
1437 { 1422 {
1438 pick_up (op, tmp); 1423 pick_up (op, tmp);
1439 if (0)
1440 fprintf (stderr, "DRINK\n");
1441 continue; 1424 continue;
1442 } 1425 }
1443 1426
1444 if (op->contr->mode & PU_POTION) 1427 if (op->contr->mode & PU_POTION)
1445 if (tmp->type == POTION) 1428 if (tmp->type == POTION)
1446 { 1429 {
1447 pick_up (op, tmp); 1430 pick_up (op, tmp);
1448 if (0)
1449 fprintf (stderr, "POTION\n");
1450 continue; 1431 continue;
1451 } 1432 }
1452 1433
1453 /* spellbooks, skillscrolls and normal books/scrolls */ 1434 /* spellbooks, skillscrolls and normal books/scrolls */
1454 if (op->contr->mode & PU_SPELLBOOK) 1435 if (op->contr->mode & PU_SPELLBOOK)
1455 if (tmp->type == SPELLBOOK) 1436 if (tmp->type == SPELLBOOK)
1456 { 1437 {
1457 pick_up (op, tmp); 1438 pick_up (op, tmp);
1458 if (0)
1459 fprintf (stderr, "SPELLBOOK\n");
1460 continue; 1439 continue;
1461 } 1440 }
1441
1462 if (op->contr->mode & PU_SKILLSCROLL) 1442 if (op->contr->mode & PU_SKILLSCROLL)
1463 if (tmp->type == SKILLSCROLL) 1443 if (tmp->type == SKILLSCROLL)
1464 { 1444 {
1465 pick_up (op, tmp); 1445 pick_up (op, tmp);
1466 if (0)
1467 fprintf (stderr, "SKILLSCROLL\n");
1468 continue; 1446 continue;
1469 } 1447 }
1448
1470 if (op->contr->mode & PU_READABLES) 1449 if (op->contr->mode & PU_READABLES)
1471 if (tmp->type == BOOK || tmp->type == SCROLL) 1450 if (tmp->type == BOOK || tmp->type == SCROLL)
1472 { 1451 {
1473 pick_up (op, tmp); 1452 pick_up (op, tmp);
1474 if (0)
1475 fprintf (stderr, "READABLES\n");
1476 continue; 1453 continue;
1477 } 1454 }
1478 1455
1479 /* wands/staves/rods/horns */ 1456 /* wands/staves/rods/horns */
1480 if (op->contr->mode & PU_MAGIC_DEVICE) 1457 if (op->contr->mode & PU_MAGIC_DEVICE)
1481 if (tmp->type == WAND || tmp->type == ROD || tmp->type == HORN) 1458 if (tmp->type == WAND || tmp->type == ROD || tmp->type == HORN)
1482 { 1459 {
1483 pick_up (op, tmp); 1460 pick_up (op, tmp);
1484 if (0)
1485 fprintf (stderr, "MAGIC_DEVICE\n");
1486 continue; 1461 continue;
1487 } 1462 }
1488 1463
1489 /* pick up all magical items */ 1464 /* pick up all magical items */
1490 if (op->contr->mode & PU_MAGICAL) 1465 if (op->contr->mode & PU_MAGICAL)
1491 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)) 1466 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))
1492 { 1467 {
1493 pick_up (op, tmp); 1468 pick_up (op, tmp);
1494 if (0)
1495 fprintf (stderr, "MAGICAL\n");
1496 continue; 1469 continue;
1497 } 1470 }
1498 1471
1499 if (op->contr->mode & PU_VALUABLES) 1472 if (op->contr->mode & PU_VALUABLES)
1500 { 1473 {
1501 if (tmp->type == MONEY || tmp->type == GEM) 1474 if (tmp->type == MONEY || tmp->type == GEM)
1502 { 1475 {
1503 pick_up (op, tmp); 1476 pick_up (op, tmp);
1504 if (0)
1505 fprintf (stderr, "MONEY/GEM\n");
1506 continue; 1477 continue;
1507 } 1478 }
1508 } 1479 }
1509 1480
1510 /* rings & amulets - talismans seems to be typed AMULET */ 1481 /* rings & amulets - talismans seems to be typed AMULET */
1511 if (op->contr->mode & PU_JEWELS) 1482 if (op->contr->mode & PU_JEWELS)
1512 if (tmp->type == RING || tmp->type == AMULET) 1483 if (tmp->type == RING || tmp->type == AMULET)
1513 { 1484 {
1514 pick_up (op, tmp); 1485 pick_up (op, tmp);
1486 continue;
1515 if (0) 1487 }
1516 fprintf (stderr, "JEWELS\n"); 1488
1489 /* we don't forget dragon food */
1490 if (op->contr->mode & PU_FLESH)
1491 if (tmp->type == FLESH)
1492 {
1493 pick_up (op, tmp);
1517 continue; 1494 continue;
1518 } 1495 }
1519 1496
1520 /* bows and arrows. Bows are good for selling! */ 1497 /* bows and arrows. Bows are good for selling! */
1521 if (op->contr->mode & PU_BOW) 1498 if (op->contr->mode & PU_BOW)
1522 if (tmp->type == BOW) 1499 if (tmp->type == BOW)
1523 { 1500 {
1524 pick_up (op, tmp); 1501 pick_up (op, tmp);
1525 if (0)
1526 fprintf (stderr, "BOW\n");
1527 continue; 1502 continue;
1528 } 1503 }
1504
1529 if (op->contr->mode & PU_ARROW) 1505 if (op->contr->mode & PU_ARROW)
1530 if (tmp->type == ARROW) 1506 if (tmp->type == ARROW)
1531 { 1507 {
1532 pick_up (op, tmp); 1508 pick_up (op, tmp);
1533 if (0)
1534 fprintf (stderr, "ARROW\n");
1535 continue; 1509 continue;
1536 } 1510 }
1537 1511
1538 /* all kinds of armor etc. */ 1512 /* all kinds of armor etc. */
1539 if (op->contr->mode & PU_ARMOUR) 1513 if (op->contr->mode & PU_ARMOUR)
1540 if (tmp->type == ARMOUR) 1514 if (tmp->type == ARMOUR)
1541 { 1515 {
1542 pick_up (op, tmp); 1516 pick_up (op, tmp);
1543 if (0)
1544 fprintf (stderr, "ARMOUR\n");
1545 continue; 1517 continue;
1546 } 1518 }
1519
1547 if (op->contr->mode & PU_HELMET) 1520 if (op->contr->mode & PU_HELMET)
1548 if (tmp->type == HELMET) 1521 if (tmp->type == HELMET)
1549 { 1522 {
1550 pick_up (op, tmp); 1523 pick_up (op, tmp);
1551 if (0)
1552 fprintf (stderr, "HELMET\n");
1553 continue; 1524 continue;
1554 } 1525 }
1526
1555 if (op->contr->mode & PU_SHIELD) 1527 if (op->contr->mode & PU_SHIELD)
1556 if (tmp->type == SHIELD) 1528 if (tmp->type == SHIELD)
1557 { 1529 {
1558 pick_up (op, tmp); 1530 pick_up (op, tmp);
1559 if (0)
1560 fprintf (stderr, "SHIELD\n");
1561 continue; 1531 continue;
1562 } 1532 }
1533
1563 if (op->contr->mode & PU_BOOTS) 1534 if (op->contr->mode & PU_BOOTS)
1564 if (tmp->type == BOOTS) 1535 if (tmp->type == BOOTS)
1565 { 1536 {
1566 pick_up (op, tmp); 1537 pick_up (op, tmp);
1567 if (0)
1568 fprintf (stderr, "BOOTS\n");
1569 continue; 1538 continue;
1570 } 1539 }
1540
1571 if (op->contr->mode & PU_GLOVES) 1541 if (op->contr->mode & PU_GLOVES)
1572 if (tmp->type == GLOVES) 1542 if (tmp->type == GLOVES)
1573 { 1543 {
1574 pick_up (op, tmp); 1544 pick_up (op, tmp);
1575 if (0)
1576 fprintf (stderr, "GLOVES\n");
1577 continue; 1545 continue;
1578 } 1546 }
1547
1579 if (op->contr->mode & PU_CLOAK) 1548 if (op->contr->mode & PU_CLOAK)
1580 if (tmp->type == CLOAK) 1549 if (tmp->type == CLOAK)
1581 { 1550 {
1582 pick_up (op, tmp); 1551 pick_up (op, tmp);
1583 if (0)
1584 fprintf (stderr, "GLOVES\n");
1585 continue; 1552 continue;
1586 } 1553 }
1587 1554
1588 /* hoping to catch throwing daggers here */ 1555 /* hoping to catch throwing daggers here */
1589 if (op->contr->mode & PU_MISSILEWEAPON) 1556 if (op->contr->mode & PU_MISSILEWEAPON)
1590 if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_IS_THROWN)) 1557 if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_IS_THROWN))
1591 { 1558 {
1592 pick_up (op, tmp); 1559 pick_up (op, tmp);
1593 if (0)
1594 fprintf (stderr, "MISSILEWEAPON\n");
1595 continue; 1560 continue;
1596 } 1561 }
1597 1562
1598 /* careful: chairs and tables are weapons! */ 1563 /* careful: chairs and tables are weapons! */
1599 if (op->contr->mode & PU_ALLWEAPON) 1564 if (op->contr->mode & PU_ALLWEAPON)
1602 { 1567 {
1603 if (strstr (tmp->name, "table") == NULL && strstr (tmp->arch->name, "table") == NULL && 1568 if (strstr (tmp->name, "table") == NULL && strstr (tmp->arch->name, "table") == NULL &&
1604 strstr (tmp->name, "chair") && strstr (tmp->arch->name, "chair") == NULL) 1569 strstr (tmp->name, "chair") && strstr (tmp->arch->name, "chair") == NULL)
1605 { 1570 {
1606 pick_up (op, tmp); 1571 pick_up (op, tmp);
1607 if (0)
1608 fprintf (stderr, "WEAPON\n");
1609 continue; 1572 continue;
1610 } 1573 }
1611 } 1574 }
1575
1612 if (tmp->type == WEAPON && tmp->name == NULL) 1576 if (tmp->type == WEAPON && tmp->name == NULL)
1613 { 1577 {
1614 if (strstr (tmp->arch->name, "table") == NULL && strstr (tmp->arch->name, "chair") == NULL) 1578 if (strstr (tmp->arch->name, "table") == NULL && strstr (tmp->arch->name, "chair") == NULL)
1615 { 1579 {
1616 pick_up (op, tmp); 1580 pick_up (op, tmp);
1617 if (0)
1618 fprintf (stderr, "WEAPON\n");
1619 continue; 1581 continue;
1620 } 1582 }
1621 } 1583 }
1622 } 1584 }
1623 1585
1624 /* misc stuff that's useful */ 1586 /* misc stuff that's useful */
1625 if (op->contr->mode & PU_KEY) 1587 if (op->contr->mode & PU_KEY)
1626 if (tmp->type == KEY || tmp->type == SPECIAL_KEY) 1588 if (tmp->type == KEY || tmp->type == SPECIAL_KEY)
1627 { 1589 {
1628 pick_up (op, tmp); 1590 pick_up (op, tmp);
1629 if (0)
1630 fprintf (stderr, "KEY\n");
1631 continue; 1591 continue;
1632 } 1592 }
1633 1593
1634 /* any of the last 4 bits set means we use the ratio for value 1594 /* any of the last 4 bits set means we use the ratio for value
1635 * pickups */ 1595 * pickups */
1657 continue; 1617 continue;
1658 } 1618 }
1659 } 1619 }
1660 } /* the new pickup model */ 1620 } /* the new pickup model */
1661 } 1621 }
1622
1662 return !stop; 1623 return !stop;
1663} 1624}
1664 1625
1665/* 1626/*
1666 * Find an arrow in the inventory and after that 1627 * Find an arrow in the inventory and after that
1843 if (!dir) 1804 if (!dir)
1844 { 1805 {
1845 new_draw_info (NDI_UNIQUE, 0, op, "You can't shoot yourself!"); 1806 new_draw_info (NDI_UNIQUE, 0, op, "You can't shoot yourself!");
1846 return 0; 1807 return 0;
1847 } 1808 }
1809
1848 if (op->type == PLAYER) 1810 if (op->type == PLAYER)
1849 bow = op->contr->ranges[range_bow]; 1811 bow = op->contr->ranges[range_bow];
1850 else 1812 else
1851 { 1813 {
1852 for (bow = op->inv; bow; bow = bow->below) 1814 for (bow = op->inv; bow; bow = bow->below)
1860 { 1822 {
1861 LOG (llevError, "Range: bow without activated bow (%s).\n", &op->name); 1823 LOG (llevError, "Range: bow without activated bow (%s).\n", &op->name);
1862 return 0; 1824 return 0;
1863 } 1825 }
1864 } 1826 }
1827
1865 if (!bow->race || !bow->skill) 1828 if (!bow->race || !bow->skill)
1866 { 1829 {
1867 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s is broken.", &bow->name); 1830 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s is broken.", &bow->name);
1868 return 0; 1831 return 0;
1869 } 1832 }
1871 bowspeed = bow->stats.sp + dex_bonus[op->stats.Dex]; 1834 bowspeed = bow->stats.sp + dex_bonus[op->stats.Dex];
1872 1835
1873 /* penalize ROF for bestarrow */ 1836 /* penalize ROF for bestarrow */
1874 if (op->type == PLAYER && op->contr->bowtype == bow_bestarrow) 1837 if (op->type == PLAYER && op->contr->bowtype == bow_bestarrow)
1875 bowspeed -= dex_bonus[op->stats.Dex] + 5; 1838 bowspeed -= dex_bonus[op->stats.Dex] + 5;
1839
1876 if (bowspeed < 1) 1840 if (bowspeed < 1)
1877 bowspeed = 1; 1841 bowspeed = 1;
1878 1842
1879 if (arrow == NULL) 1843 if (arrow == NULL)
1880 { 1844 {
1886 else 1850 else
1887 CLEAR_FLAG (op, FLAG_READY_BOW); 1851 CLEAR_FLAG (op, FLAG_READY_BOW);
1888 return 0; 1852 return 0;
1889 } 1853 }
1890 } 1854 }
1855
1891 mflags = get_map_flags (op->map, &m, sx, sy, &sx, &sy); 1856 mflags = get_map_flags (op->map, &m, sx, sy, &sx, &sy);
1892 if (mflags & P_OUT_OF_MAP) 1857 if (mflags & P_OUT_OF_MAP)
1893 {
1894 return 0; 1858 return 0;
1895 } 1859
1896 if (GET_MAP_MOVE_BLOCK (m, sx, sy) == MOVE_FLY_LOW) 1860 if (GET_MAP_MOVE_BLOCK (m, sx, sy) == MOVE_FLY_LOW)
1897 { 1861 {
1898 new_draw_info (NDI_UNIQUE, 0, op, "Something is in the way."); 1862 new_draw_info (NDI_UNIQUE, 0, op, "Something is in the way.");
1899 return 0; 1863 return 0;
1900 } 1864 }
1901 1865
1902 /* this should not happen, but sometimes does */ 1866 /* this should not happen, but sometimes does */
1903 if (arrow->nrof == 0) 1867 if (arrow->nrof == 0)
1904 { 1868 {
1905 remove_ob (arrow); 1869 arrow->destroy ();
1906 free_object (arrow);
1907 return 0; 1870 return 0;
1908 } 1871 }
1909 1872
1910 left = arrow; /* these are arrows left to the player */ 1873 left = arrow; /* these are arrows left to the player */
1911 arrow = get_split_ob (arrow, 1); 1874 arrow = get_split_ob (arrow, 1);
1912 if (arrow == NULL) 1875 if (!arrow)
1913 { 1876 {
1914 new_draw_info_format (NDI_UNIQUE, 0, op, "You have no %s left.", &bow->race); 1877 new_draw_info_format (NDI_UNIQUE, 0, op, "You have no %s left.", &bow->race);
1915 return 0; 1878 return 0;
1916 } 1879 }
1917 set_owner (arrow, op); 1880
1881 arrow->set_owner (op);
1918 arrow->skill = bow->skill; 1882 arrow->skill = bow->skill;
1919 1883
1920 arrow->direction = dir; 1884 arrow->direction = dir;
1921 arrow->x = sx; 1885 arrow->x = sx;
1922 arrow->y = sy; 1886 arrow->y = sy;
1930 SET_ANIMATION (arrow, arrow->direction); 1894 SET_ANIMATION (arrow, arrow->direction);
1931 arrow->stats.sp = arrow->stats.wc; /* save original wc and dam */ 1895 arrow->stats.sp = arrow->stats.wc; /* save original wc and dam */
1932 arrow->stats.hp = arrow->stats.dam; 1896 arrow->stats.hp = arrow->stats.dam;
1933 arrow->stats.grace = arrow->attacktype; 1897 arrow->stats.grace = arrow->attacktype;
1934 if (arrow->slaying != NULL) 1898 if (arrow->slaying != NULL)
1935 arrow->spellarg = strdup_local (arrow->slaying); 1899 arrow->spellarg = strdup (arrow->slaying);
1936 1900
1937 /* Note that this was different for monsters - they got their level 1901 /* Note that this was different for monsters - they got their level
1938 * added to the damage. I think the strength bonus is more proper. 1902 * added to the damage. I think the strength bonus is more proper.
1939 */ 1903 */
1940 1904
1964 } 1928 }
1965 1929
1966 if (arrow->attacktype == AT_PHYSICAL) 1930 if (arrow->attacktype == AT_PHYSICAL)
1967 arrow->attacktype |= bow->attacktype; 1931 arrow->attacktype |= bow->attacktype;
1968 1932
1969 if (bow->slaying != NULL) 1933 if (bow->slaying)
1970 arrow->slaying = bow->slaying; 1934 arrow->slaying = bow->slaying;
1971 1935
1972 arrow->map = m; 1936 arrow->map = m;
1973 arrow->move_type = MOVE_FLY_LOW; 1937 arrow->move_type = MOVE_FLY_LOW;
1974 arrow->move_on = MOVE_FLY_LOW | MOVE_WALK; 1938 arrow->move_on = MOVE_FLY_LOW | MOVE_WALK;
2090 CLEAR_FLAG (item, FLAG_ANIMATE); 2054 CLEAR_FLAG (item, FLAG_ANIMATE);
2091 item->face = item->arch->clone.face; 2055 item->face = item->arch->clone.face;
2092 item->speed = 0; 2056 item->speed = 0;
2093 update_ob_speed (item); 2057 update_ob_speed (item);
2094 } 2058 }
2095 if ((tmp = is_player_inv (item))) 2059 if ((tmp = item->in_player ()))
2096 esrv_update_item (UPD_ANIM, tmp, item); 2060 esrv_update_item (UPD_ANIM, tmp, item);
2097 } 2061 }
2098 } 2062 }
2099 else if (item->type == ROD || item->type == HORN) 2063 else if (item->type == ROD || item->type == HORN)
2100 { 2064 {
2130 case range_misc: 2094 case range_misc:
2131 fire_misc_object (op, dir); 2095 fire_misc_object (op, dir);
2132 return; 2096 return;
2133 2097
2134 case range_golem: /* Control summoned monsters from scrolls */ 2098 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) 2099 if (QUERY_FLAG (op->contr->ranges[range_golem], FLAG_REMOVED))
2136 { 2100 {
2137 op->contr->ranges[range_golem] = NULL; 2101 op->contr->ranges[range_golem] = 0;
2138 op->contr->shoottype = range_none; 2102 op->contr->shoottype = range_none;
2139 op->contr->golem_count = 0;
2140 } 2103 }
2141 else 2104 else
2142 control_golem (op->contr->ranges[range_golem], dir); 2105 control_golem (op->contr->ranges[range_golem], dir);
2143 return; 2106 return;
2144 2107
2251 * 0 otherwise 2214 * 0 otherwise
2252 */ 2215 */
2253static int 2216static int
2254player_attack_door (object *op, object *door) 2217player_attack_door (object *op, object *door)
2255{ 2218{
2256
2257 /* If its a door, try to find a use a key. If we do destroy the door, 2219 /* If its a door, try to find a use a key. If we do destroy the door,
2258 * might as well return immediately as there is nothing more to do - 2220 * might as well return immediately as there is nothing more to do -
2259 * otherwise, we fall through to the rest of the code. 2221 * otherwise, we fall through to the rest of the code.
2260 */ 2222 */
2261 object *key = find_key (op, op, door); 2223 object *key = find_key (op, op, door);
2299 * It should keep the code cleaner. 2261 * It should keep the code cleaner.
2300 * When this is called, the players direction has been updated 2262 * When this is called, the players direction has been updated
2301 * (taking into account confusion.) The player is also actually 2263 * (taking into account confusion.) The player is also actually
2302 * going to try and move (not fire weapons). 2264 * going to try and move (not fire weapons).
2303 */ 2265 */
2304
2305void 2266void
2306move_player_attack (object *op, int dir) 2267move_player_attack (object *op, int dir)
2307{ 2268{
2308 object *tmp, *mon; 2269 object *tmp, *mon;
2309 sint16 nx, ny; 2270 sint16 nx, ny;
2311 maptile *m; 2272 maptile *m;
2312 2273
2313 nx = freearr_x[dir] + op->x; 2274 nx = freearr_x[dir] + op->x;
2314 ny = freearr_y[dir] + op->y; 2275 ny = freearr_y[dir] + op->y;
2315 2276
2316 on_battleground = op_on_battleground (op, NULL, NULL); 2277 on_battleground = op_on_battleground (op, 0, 0);
2317 2278
2318 /* If braced, or can't move to the square, and it is not out of the 2279 /* If braced, or can't move to the square, and it is not out of the
2319 * map, attack it. Note order of if statement is important - don't 2280 * map, attack it. Note order of if statement is important - don't
2320 * want to be calling move_ob if braced, because move_ob will move the 2281 * want to be calling move_ob if braced, because move_ob will move the
2321 * player. This is a pretty nasty hack, because if we could 2282 * player. This is a pretty nasty hack, because if we could
2333 return; /* Don't think this should happen */ 2294 return; /* Don't think this should happen */
2334 } 2295 }
2335 else 2296 else
2336 m = op->map; 2297 m = op->map;
2337 2298
2338 if ((tmp = get_map_ob (m, nx, ny)) == NULL) 2299 if ((tmp = GET_MAP_OB (m, nx, ny)) == NULL)
2339 { 2300 {
2340 /* LOG(llevError,"player_move_attack: get_map_ob returns NULL, but player can not more there.\n"); */ 2301 /* LOG(llevError,"player_move_attack: GET_MAP_OB returns NULL, but player can not move there.\n"); */
2341 return; 2302 return;
2342 } 2303 }
2343 2304
2344 mon = NULL; 2305 mon = 0;
2345 /* Go through all the objects, and find ones of interest. Only stop if 2306 /* Go through all the objects, and find ones of interest. Only stop if
2346 * we find a monster - that is something we know we want to attack. 2307 * we find a monster - that is something we know we want to attack.
2347 * if its a door or barrel (can roll) see if there may be monsters 2308 * if its a door or barrel (can roll) see if there may be monsters
2348 * on the space 2309 * on the space
2349 */ 2310 */
2350 while (tmp != NULL) 2311 while (tmp)
2351 { 2312 {
2352 if (tmp == op) 2313 if (tmp == op)
2353 { 2314 {
2354 tmp = tmp->above; 2315 tmp = tmp->above;
2355 continue; 2316 continue;
2365 mon = tmp; 2326 mon = tmp;
2366 2327
2367 tmp = tmp->above; 2328 tmp = tmp->above;
2368 } 2329 }
2369 2330
2370 if (mon == NULL) /* This happens anytime the player tries to move */ 2331 if (!mon) /* This happens anytime the player tries to move */
2371 return; /* into a wall */ 2332 return; /* into a wall */
2372 2333
2373 if (mon->head != NULL) 2334 if (mon->head)
2374 mon = mon->head; 2335 mon = mon->head;
2375 2336
2376 if ((mon->type == DOOR && mon->stats.hp >= 0) || (mon->type == LOCKED_DOOR)) 2337 if ((mon->type == DOOR && mon->stats.hp >= 0) || (mon->type == LOCKED_DOOR))
2377 if (player_attack_door (op, mon)) 2338 if (player_attack_door (op, mon))
2378 return; 2339 return;
2390 * player owns it and it is either friendly or unagressive. 2351 * player owns it and it is either friendly or unagressive.
2391 */ 2352 */
2392 if ((op->type == PLAYER) 2353 if ((op->type == PLAYER)
2393#if COZY_SERVER 2354#if COZY_SERVER
2394 && 2355 &&
2395 ((get_owner (mon) && get_owner (mon)->contr 2356 ((mon->owner && mon->owner->contr
2396 && same_party (get_owner (mon)->contr->party, op->contr->party)) || get_owner (mon) == op) 2357 && same_party (mon->owner->contr->party, op->contr->party)) || mon->owner == op)
2397#else 2358#else
2398 && get_owner (mon) == op 2359 && mon->owner == op
2399#endif 2360#endif
2400 && (QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY))) 2361 && (QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY)))
2401 { 2362 {
2402 /* If we're braced, we don't want to switch places with it */ 2363 /* If we're braced, we don't want to switch places with it */
2403 if (op->contr->braced) 2364 if (op->contr->braced)
2415 * attack them either. 2376 * attack them either.
2416 */ 2377 */
2417 if ((mon->type == PLAYER || mon->enemy != op) && 2378 if ((mon->type == PLAYER || mon->enemy != op) &&
2418 (mon->type == PLAYER || QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY)) && ( 2379 (mon->type == PLAYER || QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY)) && (
2419#ifdef PROHIBIT_PLAYERKILL 2380#ifdef PROHIBIT_PLAYERKILL
2420 (op->contr->peaceful 2381 (op->contr->peaceful
2421 || (mon->type == PLAYER 2382 || (mon->type == PLAYER
2422 && mon->contr-> 2383 && mon->contr->
2423 peaceful)) && 2384 peaceful)) &&
2424#else 2385#else
2425 op->contr->peaceful && 2386 op->contr->peaceful &&
2426#endif 2387#endif
2427 !on_battleground)) 2388 !on_battleground))
2428 { 2389 {
2429 if (!op->contr->braced) 2390 if (!op->contr->braced)
2430 { 2391 {
2431 play_sound_map (op->map, op->x, op->y, SOUND_PUSH_PLAYER); 2392 play_sound_map (op->map, op->x, op->y, SOUND_PUSH_PLAYER);
2432 (void) push_ob (mon, dir, op); 2393 (void) push_ob (mon, dir, op);
2433 } 2394 }
2434 else 2395 else
2435 {
2436 new_draw_info (0, 0, op, "You withhold your attack"); 2396 new_draw_info (0, 0, op, "You withhold your attack");
2437 } 2397
2438 if (op->contr->tmp_invis || op->hide) 2398 if (op->contr->tmp_invis || op->hide)
2439 make_visible (op); 2399 make_visible (op);
2440 } 2400 }
2441 2401
2442 /* If the object is a boulder or other rollable object, then 2402 /* If the object is a boulder or other rollable object, then
2470 op->speed_left += op->speed / op->contr->weapon_sp; 2430 op->speed_left += op->speed / op->contr->weapon_sp;
2471 2431
2472 op->contr->has_hit = 1; /* The last action was to hit, so use weapon_sp */ 2432 op->contr->has_hit = 1; /* The last action was to hit, so use weapon_sp */
2473 } 2433 }
2474 2434
2475 skill_attack (mon, op, 0, NULL, NULL); 2435 skill_attack (mon, op, 0, 0, 0);
2476 2436
2477 /* If attacking another player, that player gets automatic 2437 /* If attacking another player, that player gets automatic
2478 * hitback, and doesn't loose luck either. 2438 * hitback, and doesn't loose luck either.
2479 * Disable hitback on the battleground or if the target is 2439 * Disable hitback on the battleground or if the target is
2480 * the wiz. 2440 * the wiz.
2482 if (mon->type == PLAYER && mon->stats.hp >= 0 && !mon->contr->has_hit && !on_battleground && !QUERY_FLAG (mon, FLAG_WIZ)) 2442 if (mon->type == PLAYER && mon->stats.hp >= 0 && !mon->contr->has_hit && !on_battleground && !QUERY_FLAG (mon, FLAG_WIZ))
2483 { 2443 {
2484 short luck = mon->stats.luck; 2444 short luck = mon->stats.luck;
2485 2445
2486 mon->contr->has_hit = 1; 2446 mon->contr->has_hit = 1;
2487 skill_attack (op, mon, 0, NULL, NULL); 2447 skill_attack (op, mon, 0, 0, 0);
2488 mon->stats.luck = luck; 2448 mon->stats.luck = luck;
2489 } 2449 }
2450
2490 if (action_makes_visible (op)) 2451 if (action_makes_visible (op))
2491 make_visible (op); 2452 make_visible (op);
2492 } 2453 }
2493 } /* if player should attack something */ 2454 } /* if player should attack something */
2494} 2455}
2529 2490
2530 /* Add special check for newcs players and fire on - this way, the 2491 /* Add special check for newcs players and fire on - this way, the
2531 * server can handle repeat firing. 2492 * server can handle repeat firing.
2532 */ 2493 */
2533 if (op->contr->fire_on || (op->contr->run_on && pick != 0)) 2494 if (op->contr->fire_on || (op->contr->run_on && pick != 0))
2534 {
2535 op->direction = dir; 2495 op->direction = dir;
2536 }
2537 else 2496 else
2538 {
2539 op->direction = 0; 2497 op->direction = 0;
2540 } 2498
2541 /* Update how the player looks. Use the facing, so direction may 2499 /* Update how the player looks. Use the facing, so direction may
2542 * get reset to zero. This allows for full animation capabilities 2500 * get reset to zero. This allows for full animation capabilities
2543 * for players. 2501 * for players.
2544 */ 2502 */
2545 animate_object (op, op->facing); 2503 animate_object (op, op->facing);
2590 /* I've been seeing crashes where the golem has been destroyed, but 2548 /* 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 2549 * 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 2550 * 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. 2551 * put this in a a workaround to clean up the golem pointer.
2594 */ 2552 */
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))) 2553 if (op->contr->ranges[range_golem] && QUERY_FLAG (op->contr->ranges[range_golem], FLAG_REMOVED))
2597 {
2598 op->contr->ranges[range_golem] = NULL; 2554 op->contr->ranges[range_golem] = 0;
2599 op->contr->golem_count = 0;
2600 }
2601 2555
2602 /* call this here - we also will call this in do_ericserver, but 2556 /* call this here - we also will call this in do_ericserver, but
2603 * the players time has been increased when doericserver has been 2557 * the players time has been increased when doericserver has been
2604 * called, so we recheck it here. 2558 * called, so we recheck it here.
2605 */ 2559 */
2606 HandleClient (&op->contr->socket, op->contr); 2560 //TODO: better than handling 8 commands, use some more intelligent rate-limiting
2561 for (int rep = 8; --rep && op->contr->ns->handle_command (); )
2562 ;
2563
2607 if (op->speed_left < 0) 2564 if (op->speed_left < 0)
2608 return 0; 2565 return 0;
2609 2566
2610 if (op->direction && (op->contr->run_on || op->contr->fire_on)) 2567 if (op->direction && (op->contr->run_on || op->contr->fire_on))
2611 { 2568 {
2620 if (op->speed_left > 0) 2577 if (op->speed_left > 0)
2621 return 1; 2578 return 1;
2622 else 2579 else
2623 return 0; 2580 return 0;
2624 } 2581 }
2582
2625 return 0; 2583 return 0;
2626} 2584}
2627 2585
2628int 2586int
2629save_life (object *op) 2587save_life (object *op)
2630{ 2588{
2631 object *tmp;
2632
2633 if (!QUERY_FLAG (op, FLAG_LIFESAVE)) 2589 if (!QUERY_FLAG (op, FLAG_LIFESAVE))
2634 return 0; 2590 return 0;
2635 2591
2636 for (tmp = op->inv; tmp != NULL; tmp = tmp->below) 2592 for (object *tmp = op->inv; tmp; tmp = tmp->below)
2637 if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE)) 2593 if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE))
2638 { 2594 {
2639 play_sound_map (op->map, op->x, op->y, SOUND_OB_EVAPORATE); 2595 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)); 2596 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s vibrates violently, then evaporates.", query_name (tmp));
2597
2641 if (op->contr) 2598 if (op->contr)
2642 esrv_del_item (op->contr, tmp->count); 2599 esrv_del_item (op->contr, tmp->count);
2643 remove_ob (tmp); 2600
2644 free_object (tmp); 2601 tmp->destroy ();
2645 CLEAR_FLAG (op, FLAG_LIFESAVE); 2602 CLEAR_FLAG (op, FLAG_LIFESAVE);
2603
2646 if (op->stats.hp < 0) 2604 if (op->stats.hp < 0)
2647 op->stats.hp = op->stats.maxhp; 2605 op->stats.hp = op->stats.maxhp;
2606
2648 if (op->stats.food < 0) 2607 if (op->stats.food < 0)
2649 op->stats.food = 999; 2608 op->stats.food = 999;
2609
2650 fix_player (op); 2610 fix_player (op);
2651 return 1; 2611 return 1;
2652 } 2612 }
2613
2653 LOG (llevError, "Error: LIFESAVE set without applied object.\n"); 2614 LOG (llevError, "Error: LIFESAVE set without applied object.\n");
2654 CLEAR_FLAG (op, FLAG_LIFESAVE); 2615 CLEAR_FLAG (op, FLAG_LIFESAVE);
2655 enter_player_savebed (op); /* bring him home. */ 2616 enter_player_savebed (op); /* bring him home. */
2656 return 0; 2617 return 0;
2657} 2618}
2671 next = op->below; /* Make sure we have a good value, in case 2632 next = op->below; /* Make sure we have a good value, in case
2672 * we remove object 'op' 2633 * we remove object 'op'
2673 */ 2634 */
2674 if (QUERY_FLAG (op, FLAG_UNPAID)) 2635 if (QUERY_FLAG (op, FLAG_UNPAID))
2675 { 2636 {
2676 remove_ob (op); 2637 op->remove ();
2677 op->x = env->x; 2638 op->x = env->x;
2678 op->y = env->y; 2639 op->y = env->y;
2679 if (env->type == PLAYER) 2640 if (env->type == PLAYER)
2680 esrv_del_item (env->contr, op->count); 2641 esrv_del_item (env->contr, op->count);
2681 insert_ob_in_map (op, env->map, NULL, 0); 2642 insert_ob_in_map (op, env->map, NULL, 0);
2682 } 2643 }
2683 else if (op->inv) 2644 else if (op->inv)
2684 remove_unpaid_objects (op->inv, env); 2645 remove_unpaid_objects (op->inv, env);
2646
2685 op = next; 2647 op = next;
2686 } 2648 }
2687} 2649}
2688 2650
2689 2651
2704 strcpy (buf2, " R.I.P.\n\n"); 2666 strcpy (buf2, " R.I.P.\n\n");
2705 if (op->type == PLAYER) 2667 if (op->type == PLAYER)
2706 sprintf (buf, "%s the %s\n", &op->name, op->contr->title); 2668 sprintf (buf, "%s the %s\n", &op->name, op->contr->title);
2707 else 2669 else
2708 sprintf (buf, "%s\n", &op->name); 2670 sprintf (buf, "%s\n", &op->name);
2671
2709 strncat (buf2, " ", 20 - strlen (buf) / 2); 2672 strncat (buf2, " ", 20 - strlen (buf) / 2);
2710 strcat (buf2, buf); 2673 strcat (buf2, buf);
2711 if (op->type == PLAYER) 2674 if (op->type == PLAYER)
2712 sprintf (buf, "who was in level %d when killed\n", op->level); 2675 sprintf (buf, "who was in level %d when killed\n", op->level);
2713 else 2676 else
2714 sprintf (buf, "who was in level %d when died.\n\n", op->level); 2677 sprintf (buf, "who was in level %d when died.\n\n", op->level);
2678
2715 strncat (buf2, " ", 20 - strlen (buf) / 2); 2679 strncat (buf2, " ", 20 - strlen (buf) / 2);
2716 strcat (buf2, buf); 2680 strcat (buf2, buf);
2717 if (op->type == PLAYER) 2681 if (op->type == PLAYER)
2718 { 2682 {
2719 sprintf (buf, "by %s.\n\n", op->contr->killer); 2683 sprintf (buf, "by %s.\n\n", op->contr->killer);
2720 strncat (buf2, " ", 21 - strlen (buf) / 2); 2684 strncat (buf2, " ", 21 - strlen (buf) / 2);
2721 strcat (buf2, buf); 2685 strcat (buf2, buf);
2722 } 2686 }
2687
2723 strftime (buf, MAX_BUF, "%b %d %Y\n", localtime (&now)); 2688 strftime (buf, MAX_BUF, "%b %d %Y\n", localtime (&now));
2724 strncat (buf2, " ", 20 - strlen (buf) / 2); 2689 strncat (buf2, " ", 20 - strlen (buf) / 2);
2725 strcat (buf2, buf); 2690 strcat (buf2, buf);
2691
2726 return buf2; 2692 return buf2;
2727} 2693}
2728 2694
2729 2695
2730 2696
2747 for (i = 0; i < NUM_OUTPUT_BUFS; i++) 2713 for (i = 0; i < NUM_OUTPUT_BUFS; i++)
2748 if (op->contr->outputs[i].buf != NULL && (op->contr->outputs[i].first_update + op->contr->outputs_sync) < (uint16) pticks) 2714 if (op->contr->outputs[i].buf != NULL && (op->contr->outputs[i].first_update + op->contr->outputs_sync) < (uint16) pticks)
2749 flush_output_element (op, &op->contr->outputs[i]); 2715 flush_output_element (op, &op->contr->outputs[i]);
2750 } 2716 }
2751 2717
2752 if (op->contr->state == ST_PLAYING) 2718 if (op->contr->ns->state == ST_PLAYING)
2753 { 2719 {
2754 2720
2755 /* these next three if clauses make it possible to SLOW DOWN 2721 /* these next three if clauses make it possible to SLOW DOWN
2756 hp/grace/spellpoint regeneration. */ 2722 hp/grace/spellpoint regeneration. */
2757 if (op->contr->gen_hp >= 0) 2723 if (op->contr->gen_hp >= 0)
2899 if (!QUERY_FLAG (op, FLAG_WIZ)) 2865 if (!QUERY_FLAG (op, FLAG_WIZ))
2900 op->stats.food--; 2866 op->stats.food--;
2901 } 2867 }
2902 } 2868 }
2903 2869
2904 if (op->contr->state == ST_PLAYING && op->stats.food < 0 && op->stats.hp >= 0) 2870 if (op->contr->ns->state == ST_PLAYING && op->stats.food < 0 && op->stats.hp >= 0)
2905 { 2871 {
2906 object *tmp, *flesh = NULL; 2872 object *tmp, *flesh = NULL;
2907 2873
2908 for (tmp = op->inv; tmp != NULL; tmp = tmp->below) 2874 for (tmp = op->inv; tmp != NULL; tmp = tmp->below)
2909 { 2875 {
2931 } /* end if player is starving */ 2897 } /* end if player is starving */
2932 2898
2933 while (op->stats.food < 0 && op->stats.hp > 0) 2899 while (op->stats.food < 0 && op->stats.hp > 0)
2934 op->stats.food++, op->stats.hp--; 2900 op->stats.food++, op->stats.hp--;
2935 2901
2936 if (!op->contr->state && !QUERY_FLAG (op, FLAG_WIZ) && (op->stats.hp < 0 || op->stats.food < 0)) 2902 if (!op->contr->ns->state && !QUERY_FLAG (op, FLAG_WIZ) && (op->stats.hp < 0 || op->stats.food < 0))
2937 kill_player (op); 2903 kill_player (op);
2938} 2904}
2939 2905
2940 2906
2941 2907
2978 /* restore player */ 2944 /* restore player */
2979 at = archetype::find ("poisoning"); 2945 at = archetype::find ("poisoning");
2980 tmp = present_arch_in_ob (at, op); 2946 tmp = present_arch_in_ob (at, op);
2981 if (tmp) 2947 if (tmp)
2982 { 2948 {
2983 remove_ob (tmp); 2949 tmp->destroy ();
2984 free_object (tmp);
2985 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed"); 2950 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed");
2986 } 2951 }
2987 2952
2988 at = archetype::find ("confusion"); 2953 at = archetype::find ("confusion");
2989 tmp = present_arch_in_ob (at, op); 2954 tmp = present_arch_in_ob (at, op);
2990 if (tmp) 2955 if (tmp)
2991 { 2956 {
2992 remove_ob (tmp); 2957 tmp->destroy ();
2993 free_object (tmp);
2994 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer"); 2958 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer");
2995 } 2959 }
2996 2960
2997 cure_disease (op, 0); /* remove any disease */ 2961 cure_disease (op, 0); /* remove any disease */
2998 op->stats.hp = op->stats.maxhp; 2962 op->stats.hp = op->stats.maxhp;
3175 /* determine_god() seems to not work sometimes... why is this? 3139 /* determine_god() seems to not work sometimes... why is this?
3176 Should I be using something else? GD */ 3140 Should I be using something else? GD */
3177 const char *god = determine_god (op); 3141 const char *god = determine_god (op);
3178 3142
3179 if (god && (strcmp (god, "none"))) 3143 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); 3144 new_draw_info_format (NDI_UNIQUE, 0, op, "For a brief moment you feel the holy presence of %s protecting" " you.", god);
3181 else 3145 else
3182 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you" " feel a holy presence protecting you."); 3146 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you feel a holy presence protecting you.");
3183 } 3147 }
3148#else
3149 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you" " feel a holy presence protecting you from losing yourself completely.");
3184#endif 3150#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 3151
3187 /* Put a gravestone up where the character 'almost' died. List the 3152 /* Put a gravestone up where the character 'almost' died. List the
3188 * exp loss on the stone. 3153 * exp loss on the stone.
3189 */ 3154 */
3190 tmp = arch_to_object (archetype::find ("gravestone")); 3155 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); 3160 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; 3161 tmp->msg = buf;
3197 tmp->x = op->x, tmp->y = op->y; 3162 tmp->x = op->x, tmp->y = op->y;
3198 insert_ob_in_map (tmp, op->map, NULL, 0); 3163 insert_ob_in_map (tmp, op->map, NULL, 0);
3199 3164
3200 /**************************************/ 3165 /**************************************/
3201 /* */ 3166 /* */
3202 /* Subtract the experience points, */ 3167 /* Subtract the experience points, */
3203 /* if we died cause of food, give us */ 3168 /* if we died cause of food, give us */
3204 /* food, and reset HP's... */ 3169 /* food, and reset HP's... */
3205 /* */ 3170 /* */
3206
3207 /**************************************/ 3171 /**************************************/
3208 3172
3209 /* remove any poisoning and confusion the character may be suffering. */ 3173 /* remove any poisoning and confusion the character may be suffering. */
3210 /* restore player */ 3174 /* restore player */
3211 at = archetype::find ("poisoning"); 3175 at = archetype::find ("poisoning");
3212 tmp = present_arch_in_ob (at, op); 3176 tmp = present_arch_in_ob (at, op);
3177
3213 if (tmp) 3178 if (tmp)
3214 { 3179 {
3215 remove_ob (tmp); 3180 tmp->destroy ();
3216 free_object (tmp);
3217 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed"); 3181 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed");
3218 } 3182 }
3219 3183
3220 at = archetype::find ("confusion"); 3184 at = archetype::find ("confusion");
3221 tmp = present_arch_in_ob (at, op); 3185 tmp = present_arch_in_ob (at, op);
3222 if (tmp) 3186 if (tmp)
3223 { 3187 {
3224 remove_ob (tmp); 3188 tmp->destroy ();
3225 free_object (tmp);
3226 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer"); 3189 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer");
3227 } 3190 }
3191
3228 cure_disease (op, 0); /* remove any disease */ 3192 cure_disease (op, 0); /* remove any disease */
3229 3193
3230 /*add_exp(op, (op->stats.exp * -0.20)); */ 3194 /*add_exp(op, (op->stats.exp * -0.20)); */
3231 apply_death_exp_penalty (op); 3195 apply_death_exp_penalty (op);
3232 if (op->stats.food < 100) 3196 if (op->stats.food < 100)
3242 */ 3206 */
3243 3207
3244 if (is_in_shop (op)) 3208 if (is_in_shop (op))
3245 remove_unpaid_objects (op->inv, op); 3209 remove_unpaid_objects (op->inv, op);
3246 3210
3247 /****************************************/ 3211 /****************************************/
3248 /* */ 3212 /* */
3249 /* Move player to his current respawn- */ 3213 /* Move player to his current respawn- */
3250 /* position (usually last savebed) */ 3214 /* position (usually last savebed) */
3251 /* */ 3215 /* */
3252
3253 /****************************************/ 3216 /****************************************/
3254 3217
3255 enter_player_savebed (op); 3218 enter_player_savebed (op);
3256 3219
3257 /* Save the player before inserting the force to reduce 3220 /* Save the player before inserting the force to reduce
3258 * chance of abuse. 3221 * chance of abuse.
3264 * at his savebed location, and that can have long lasting 3227 * at his savebed location, and that can have long lasting
3265 * spell effects. So first see if there is a spell effect 3228 * spell effects. So first see if there is a spell effect
3266 * on the space that might harm the player. 3229 * on the space that might harm the player.
3267 */ 3230 */
3268 will_kill_again = 0; 3231 will_kill_again = 0;
3269 for (tmp = get_map_ob (op->map, op->x, op->y); tmp; tmp = tmp->above) 3232 for (tmp = GET_MAP_OB (op->map, op->x, op->y); tmp; tmp = tmp->above)
3270 {
3271 if (tmp->type == SPELL_EFFECT) 3233 if (tmp->type == SPELL_EFFECT)
3272 will_kill_again |= tmp->attacktype; 3234 will_kill_again |= tmp->attacktype;
3273 } 3235
3274 if (will_kill_again) 3236 if (will_kill_again)
3275 { 3237 {
3276 object *force; 3238 object *force;
3277 int at; 3239 int at;
3278 3240
3280 /* 50 ticks should be enough time for the spell to abate */ 3242 /* 50 ticks should be enough time for the spell to abate */
3281 force->speed = 0.1; 3243 force->speed = 0.1;
3282 force->speed_left = -5.0; 3244 force->speed_left = -5.0;
3283 SET_FLAG (force, FLAG_APPLIED); 3245 SET_FLAG (force, FLAG_APPLIED);
3284 for (at = 0; at < NROFATTACKS; at++) 3246 for (at = 0; at < NROFATTACKS; at++)
3285 {
3286 if (will_kill_again & (1 << at)) 3247 if (will_kill_again & (1 << at))
3287 force->resist[at] = 100; 3248 force->resist[at] = 100;
3288 } 3249
3289 insert_ob_in_ob (force, op); 3250 insert_ob_in_ob (force, op);
3290 fix_player (op); 3251 fix_player (op);
3291 3252
3292 } 3253 }
3293 3254
3303 op->contr->party = NULL; 3264 op->contr->party = NULL;
3304 if (settings.set_title == TRUE) 3265 if (settings.set_title == TRUE)
3305 op->contr->own_title[0] = '\0'; 3266 op->contr->own_title[0] = '\0';
3306 new_draw_info (NDI_UNIQUE | NDI_ALL, 0, NULL, buf); 3267 new_draw_info (NDI_UNIQUE | NDI_ALL, 0, NULL, buf);
3307 check_score (op); 3268 check_score (op);
3269
3308 if (op->contr->ranges[range_golem] != NULL) 3270 if (op->contr->ranges[range_golem])
3309 { 3271 {
3310 remove_friendly_object (op->contr->ranges[range_golem]); 3272 remove_friendly_object (op->contr->ranges[range_golem]);
3311 remove_ob (op->contr->ranges[range_golem]); 3273 op->contr->ranges[range_golem]->destroy ();
3312 free_object (op->contr->ranges[range_golem]);
3313 op->contr->ranges[range_golem] = NULL; 3274 op->contr->ranges[range_golem] = 0;
3314 op->contr->golem_count = 0;
3315 } 3275 }
3276
3316 loot_object (op); /* Remove some of the items for good */ 3277 loot_object (op); /* Remove some of the items for good */
3317 remove_ob (op); 3278 op->remove ();
3318 op->direction = 0; 3279 op->direction = 0;
3319 3280
3320 if (!QUERY_FLAG (op, FLAG_WAS_WIZ) && op->stats.exp) 3281 if (!QUERY_FLAG (op, FLAG_WAS_WIZ) && op->stats.exp)
3321 { 3282 {
3322 delete_character (op->name, 0); 3283 delete_character (op->name, 0);
3373 } 3334 }
3374 3335
3375 for (tmp = op->inv; tmp != NULL; tmp = next) 3336 for (tmp = op->inv; tmp != NULL; tmp = next)
3376 { 3337 {
3377 next = tmp->below; 3338 next = tmp->below;
3378 if (tmp->type == EXPERIENCE || tmp->invisible) 3339 if (tmp->invisible)
3379 continue; 3340 continue;
3380 remove_ob (tmp); 3341 tmp->remove ();
3381 tmp->x = op->x, tmp->y = op->y; 3342 tmp->x = op->x, tmp->y = op->y;
3382 if (tmp->type == CONTAINER) 3343 if (tmp->type == CONTAINER)
3383 { /* empty container to ground */ 3344 { /* empty container to ground */
3384 loot_object (tmp); 3345 loot_object (tmp);
3385 } 3346 }
3386 if (!QUERY_FLAG (tmp, FLAG_UNIQUE) && (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || QUERY_FLAG (tmp, FLAG_NO_DROP) || !(RANDOM () % 3))) 3347 if (!QUERY_FLAG (tmp, FLAG_UNIQUE) && (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || QUERY_FLAG (tmp, FLAG_NO_DROP) || !(RANDOM () % 3)))
3387 { 3348 {
3388 if (tmp->nrof > 1) 3349 if (tmp->nrof > 1)
3389 { 3350 {
3390 tmp2 = get_split_ob (tmp, 1 + RANDOM () % (tmp->nrof - 1)); 3351 tmp2 = get_split_ob (tmp, 1 + RANDOM () % (tmp->nrof - 1));
3391 free_object (tmp2); 3352 tmp2->destroy ();
3392 insert_ob_in_map (tmp, op->map, NULL, 0); 3353 insert_ob_in_map (tmp, op->map, NULL, 0);
3393 } 3354 }
3394 else 3355 else
3395 free_object (tmp); 3356 tmp->destroy ();
3396 } 3357 }
3397 else 3358 else
3398 insert_ob_in_map (tmp, op->map, NULL, 0); 3359 insert_ob_in_map (tmp, op->map, NULL, 0);
3399 } 3360 }
3400} 3361}
3425fix_luck (void) 3386fix_luck (void)
3426{ 3387{
3427 player *pl; 3388 player *pl;
3428 3389
3429 for (pl = first_player; pl != NULL; pl = pl->next) 3390 for (pl = first_player; pl != NULL; pl = pl->next)
3430 if (!pl->ob->contr->state) 3391 if (!pl->ob->contr->ns->state)
3431 change_luck (pl->ob, 0); 3392 change_luck (pl->ob, 0);
3432} 3393}
3433 3394
3434 3395
3435/* cast_dust() - handles op throwing objects of type 'DUST'. 3396/* cast_dust() - handles op throwing objects of type 'DUST'.
3465 if (op->type == PLAYER) 3426 if (op->type == PLAYER)
3466 new_draw_info_format (NDI_UNIQUE, 0, op, "You cast %s.", &spob->name); 3427 new_draw_info_format (NDI_UNIQUE, 0, op, "You cast %s.", &spob->name);
3467 3428
3468 cast_spell (op, throw_ob, dir, spob, NULL); 3429 cast_spell (op, throw_ob, dir, spob, NULL);
3469 3430
3470 if (!QUERY_FLAG (throw_ob, FLAG_REMOVED)) 3431 throw_ob->destroy ();
3471 remove_ob (throw_ob);
3472 free_object (throw_ob);
3473} 3432}
3474 3433
3475void 3434void
3476make_visible (object *op) 3435make_visible (object *op)
3477{ 3436{
3491 object *tmp = NULL; 3450 object *tmp = NULL;
3492 3451
3493 if (QUERY_FLAG (&op->arch->clone, FLAG_UNDEAD)) 3452 if (QUERY_FLAG (&op->arch->clone, FLAG_UNDEAD))
3494 return 1; 3453 return 1;
3495 3454
3496 if (op->type == PLAYER)
3497 for (tmp = op->inv; tmp; tmp = tmp->below)
3498 if (tmp->type == EXPERIENCE && tmp->stats.Wis)
3499 if (QUERY_FLAG (tmp, FLAG_UNDEAD))
3500 return 1;
3501 return 0; 3455 return 0;
3502} 3456}
3503 3457
3504/* look at the surrounding terrain to determine 3458/* look at the surrounding terrain to determine
3505 * the hideability of this object. Positive levels 3459 * the hideability of this object. Positive levels
3620 if (mflags & P_OUT_OF_MAP) 3574 if (mflags & P_OUT_OF_MAP)
3621 continue; 3575 continue;
3622 if (OB_TYPE_MOVE_BLOCK (who, GET_MAP_MOVE_BLOCK (m, x, y))) 3576 if (OB_TYPE_MOVE_BLOCK (who, GET_MAP_MOVE_BLOCK (m, x, y)))
3623 continue; 3577 continue;
3624 3578
3625 for (tmp = get_map_ob (m, x, y); tmp; tmp = tmp->above) 3579 for (tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above)
3626 { 3580 {
3627 if ((player ||friendly) &&QUERY_FLAG (tmp, FLAG_MONSTER) && !QUERY_FLAG (tmp, FLAG_UNAGGRESSIVE)) 3581 if ((player ||friendly) &&QUERY_FLAG (tmp, FLAG_MONSTER) && !QUERY_FLAG (tmp, FLAG_UNAGGRESSIVE))
3628 return 1; 3582 return 1;
3629 else if (tmp->type == PLAYER) 3583 else if (tmp->type == PLAYER)
3630 { 3584 {
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->ns->mapx / 2) &&
3690 FABS (dy) <= (pl->contr->socket.mapy / 2) && 3644 FABS (dy) <= (pl->contr->ns->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->ns->mapx / 2)][dy + (pl->contr->ns->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}
3882 { 3836 {
3883 /* forces in the treasurelist can alter the player's stats */ 3837 /* forces in the treasurelist can alter the player's stats */
3884 object *skin; 3838 object *skin;
3885 3839
3886 /* first get the dragon skin force */ 3840 /* first get the dragon skin force */
3841 shstr_cmp dragon_skin_force ("dragon_skin_force");
3887 for (skin = who->inv; skin != NULL && strcmp (skin->arch->name, "dragon_skin_force") != 0; skin = skin->below); 3842 for (skin = who->inv; skin && !(skin->arch->name == dragon_skin_force); skin = skin->below)
3843 ;
3844
3888 if (skin == NULL) 3845 if (!skin)
3889 return; 3846 return;
3890 3847
3891 /* adding new spellpath attunements */ 3848 /* adding new spellpath attunements */
3892 if (item->path_attuned > 0 && !(skin->path_attuned & item->path_attuned)) 3849 if (item->path_attuned > 0 && !(skin->path_attuned & item->path_attuned))
3893 { 3850 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines