ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/player.C
(Generate patch)

Comparing deliantra/server/server/player.C (file contents):
Revision 1.18 by root, Sun Sep 10 15:59:57 2006 UTC vs.
Revision 1.48 by root, Tue Dec 19 05:41:22 2006 UTC

1
2/*
3 * static char *rcsid_player_c =
4 * "$Id: player.C,v 1.18 2006/09/10 15:59:57 root Exp $";
5 */
6
7/* 1/*
8 CrossFire, A Multiplayer game for X-windows 2 CrossFire, A Multiplayer game for X-windows
9 3
10 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 4 Copyright (C) 2002 Mark Wedel & Crossfire Development Team
11 Copyright (C) 1992 Frank Tore Johansen 5 Copyright (C) 1992 Frank Tore Johansen
22 16
23 You should have received a copy of the GNU General Public License 17 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software 18 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 20
27 The author can be reached via e-mail to crossfire-devel@real-time.com 21 The author can be reached via e-mail to <crossfire@schmorp.de>
28*/ 22*/
29 23
30#include <global.h> 24#include <global.h>
31#ifndef WIN32 /* ---win32 remove headers */
32# include <pwd.h> 25#include <pwd.h>
33#endif
34#ifndef __CEXTRACT__
35# include <sproto.h> 26#include <sproto.h>
36#endif
37#include <sounds.h> 27#include <sounds.h>
38#include <living.h> 28#include <living.h>
39#include <object.h> 29#include <object.h>
40#include <spells.h> 30#include <spells.h>
41#include <skills.h> 31#include <skills.h>
42#include <newclient.h>
43 32
44#ifdef COZY_SERVER 33#ifdef COZY_SERVER
45extern int same_party (partylist *a, partylist *b); 34extern int same_party (partylist *a, partylist *b);
46#endif 35#endif
47 36
93 int comp; 82 int comp;
94 int size; 83 int size;
95 84
96 sprintf (buf, "%s/%s", settings.confdir, settings.motd); 85 sprintf (buf, "%s/%s", settings.confdir, settings.motd);
97 if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL) 86 if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL)
98 {
99 return; 87 return;
100 } 88
101 motd[0] = '\0'; 89 motd[0] = '\0';
102 size = 0; 90 size = 0;
91
103 while (fgets (buf, MAX_BUF, fp) != NULL) 92 while (fgets (buf, MAX_BUF, fp) != NULL)
104 { 93 {
105 if (*buf == '#') 94 if (*buf == '#')
106 continue; 95 continue;
96
107 strncat (motd + size, buf, HUGE_BUF - size); 97 strncat (motd + size, buf, HUGE_BUF - size);
108 size += strlen (buf); 98 size += strlen (buf);
109 } 99 }
100
110 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);
111 close_and_delete (fp, comp); 102 close_and_delete (fp, comp);
112} 103}
113 104
114void 105void
120 int comp; 111 int comp;
121 int size; 112 int size;
122 113
123 sprintf (buf, "%s/%s", settings.confdir, settings.rules); 114 sprintf (buf, "%s/%s", settings.confdir, settings.rules);
124 if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL) 115 if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL)
125 {
126 return; 116 return;
127 } 117
128 rules[0] = '\0'; 118 rules[0] = '\0';
129 size = 0; 119 size = 0;
120
130 while (fgets (buf, MAX_BUF, fp) != NULL) 121 while (fgets (buf, MAX_BUF, fp) != NULL)
131 { 122 {
132 if (*buf == '#') 123 if (*buf == '#')
133 continue; 124 continue;
125
134 if (size + strlen (buf) >= HUGE_BUF) 126 if (size + strlen (buf) >= HUGE_BUF)
135 { 127 {
136 LOG (llevDebug, "Warning, rules size is > %d bytes.\n", HUGE_BUF); 128 LOG (llevDebug, "Warning, rules size is > %d bytes.\n", HUGE_BUF);
137 break; 129 break;
138 } 130 }
131
139 strncat (rules + size, buf, HUGE_BUF - size); 132 strncat (rules + size, buf, HUGE_BUF - size);
140 size += strlen (buf); 133 size += strlen (buf);
141 } 134 }
135
142 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);
143 close_and_delete (fp, comp); 137 close_and_delete (fp, comp);
144} 138}
145 139
146void 140void
154 int size; 148 int size;
155 149
156 sprintf (buf, "%s/%s", settings.confdir, settings.news); 150 sprintf (buf, "%s/%s", settings.confdir, settings.news);
157 if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL) 151 if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL)
158 return; 152 return;
153
159 news[0] = '\0'; 154 news[0] = '\0';
160 subject[0] = '\0'; 155 subject[0] = '\0';
161 size = 0; 156 size = 0;
157
162 while (fgets (buf, MAX_BUF, fp) != NULL) 158 while (fgets (buf, MAX_BUF, fp) != NULL)
163 { 159 {
164 if (*buf == '#') 160 if (*buf == '#')
165 continue; 161 continue;
162
166 if (*buf == '%') 163 if (*buf == '%')
167 { /* send one news */ 164 { /* send one news */
168 if (size > 0) 165 if (size > 0)
169 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 */
170 strcpy (subject, buf + 1); 167 strcpy (subject, buf + 1);
197 return 0; 194 return 0;
198 195
199 for (; *cp != '\0'; cp++) 196 for (; *cp != '\0'; cp++)
200 if (!((*cp >= 'a' && *cp <= 'z') || (*cp >= 'A' && *cp <= 'Z')) && *cp != '-' && *cp != '_') 197 if (!((*cp >= 'a' && *cp <= 'z') || (*cp >= 'A' && *cp <= 'Z')) && *cp != '-' && *cp != '_')
201 return 0; 198 return 0;
199
202 return 1; 200 return 1;
203} 201}
204 202
205/* This no longer sets the player map. Also, it now updates 203/* This no longer sets the player map. Also, it now updates
206 * 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.
214 * the one that is passed. 212 * the one that is passed.
215 */ 213 */
216static player * 214static player *
217get_player (player *p) 215get_player (player *p)
218{ 216{
219 object *op = arch_to_object (get_player_archetype (NULL)); 217 object *op = arch_to_object (get_player_archetype (0));
220 int i; 218 int i;
221
222 if (!p)
223 {
224 p = new player;
225
226 /* This adds the player in the linked list. There is extra
227 * complexity here because we want to add the new player at the
228 * end of the list - there is in fact no compelling reason that
229 * that needs to be done except for things like output of
230 * 'who'.
231 */
232 player *tmp = first_player;
233
234 while (tmp != NULL && tmp->next != NULL)
235 tmp = tmp->next;
236 if (tmp != NULL)
237 tmp->next = p;
238 else
239 first_player = p;
240
241 p->next = NULL;
242 }
243 219
244 /* Clears basically the entire player structure except 220 /* Clears basically the entire player structure except
245 * for next and socket. 221 * for next and socket.
246 */ 222 */
247 p->clear (); 223 p->clear ();
266 op->speed_left = 0.5; 242 op->speed_left = 0.5;
267 op->speed = 1.0; 243 op->speed = 1.0;
268 op->direction = 5; /* So player faces south */ 244 op->direction = 5; /* So player faces south */
269 op->stats.wc = 2; 245 op->stats.wc = 2;
270 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
271 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 */
272
273 roll_stats (op); 251 roll_stats (op);
252 p->socket->monitor_spells = oldmon;
253 }
274 p->state = ST_ROLL_STAT; 254 p->state = ST_ROLL_STAT;
275 clear_los (op); 255 clear_los (op);
276 256
277 p->gen_sp_armour = 10; 257 p->gen_sp_armour = 10;
278 p->last_speed = -1; 258 p->last_speed = -1;
283 p->usekeys = containers; 263 p->usekeys = containers;
284 p->last_weapon_sp = -1; 264 p->last_weapon_sp = -1;
285 p->peaceful = 1; /* default peaceful */ 265 p->peaceful = 1; /* default peaceful */
286 p->do_los = 1; 266 p->do_los = 1;
287 p->explore = 0; 267 p->explore = 0;
288 p->no_shout = 0; /* default can shout */
289 268
290 strncpy (p->title, op->arch->clone.name, sizeof (p->title) - 1); 269 assign (p->title, op->arch->clone.name);
291 p->title[sizeof (p->title) - 1] = '\0';
292 op->race = op->arch->clone.race; 270 op->race = op->arch->clone.race;
293 271
294 CLEAR_FLAG (op, FLAG_READY_SKILL); 272 CLEAR_FLAG (op, FLAG_READY_SKILL);
295 273
296 /* we need to clear these to -1 and not zero - otherwise, 274 /* we need to clear these to -1 and not zero - otherwise,
301 for (i = 0; i < NUM_SKILLS; i++) 279 for (i = 0; i < NUM_SKILLS; i++)
302 { 280 {
303 p->last_skill_exp[i] = -1; 281 p->last_skill_exp[i] = -1;
304 p->last_skill_ob[i] = NULL; 282 p->last_skill_ob[i] = NULL;
305 } 283 }
284
306 for (i = 0; i < NROFATTACKS; i++) 285 for (i = 0; i < NROFATTACKS; i++)
307 {
308 p->last_resist[i] = -1; 286 p->last_resist[i] = -1;
309 } 287
310 p->last_stats.exp = -1; 288 p->last_stats.exp = -1;
311 p->last_weight = (uint32) - 1; 289 p->last_weight = (uint32) - 1;
312 290
313 p->socket.update_look = 0; 291 p->socket->update_look = 0;
314 p->socket.look_position = 0; 292 p->socket->look_position = 0;
293
315 return p; 294 return p;
316} 295}
317 296
318/* This loads the first map an puts the player on it. */ 297/* This loads the first map an puts the player on it. */
319static void 298static void
320set_first_map (object *op) 299set_first_map (object *op)
321{ 300{
322 strcpy (op->contr->maplevel, first_map_path); 301 strcpy (op->contr->maplevel, first_map_path);
323 op->x = -1; 302 op->x = -1;
324 op->y = -1; 303 op->y = -1;
325 enter_exit (op, NULL); 304 enter_exit (op, 0);
326} 305}
327 306
328/* Tries to add player on the connection passwd in ns. 307/* Tries to add player on the connection passwd in ns.
329 * 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
330 * mode. 309 * mode.
331 */ 310 */
332 311
333int 312int
334add_player (NewSocket * ns) 313add_player (client *ns)
335{ 314{
336 player *p; 315 player *p = new player;
337 316
338 p = get_player (NULL);
339 p->socket = *ns; 317 p->socket = ns;
340 p->socket.faces_sent = (uint8 *) malloc (p->socket.faces_sent_len * sizeof (*p->socket.faces_sent)); 318 ns->pl = p;
341 if (p->socket.faces_sent == NULL) 319
342 fatal (OUT_OF_MEMORY); 320 p->next = first_player;
343 memcpy (p->socket.faces_sent, ns->faces_sent, p->socket.faces_sent_len * sizeof (*p->socket.faces_sent)); 321 first_player = p;
344 /* Needed because the socket we just copied over needs to be cleared. 322
345 * Note that this can result in a client reset if there is partial data 323 p = get_player (p);
346 * on the uncoming socket. 324
347 */
348 p->socket.inbuf.len = 0;
349 set_first_map (p->ob); 325 set_first_map (p->ob);
350 326
351 CLEAR_FLAG (p->ob, FLAG_FRIENDLY); 327 CLEAR_FLAG (p->ob, FLAG_FRIENDLY);
352 add_friendly_object (p->ob); 328 add_friendly_object (p->ob);
353 send_rules (p->ob); 329 send_rules (p->ob);
354 send_news (p->ob); 330 send_news (p->ob);
355 display_motd (p->ob); 331 display_motd (p->ob);
356 get_name (p->ob); 332 get_name (p->ob);
333
357 return 0; 334 return 0;
358} 335}
359 336
360/* 337/*
361 * get_player_archetype() return next player archetype from archetype 338 * get_player_archetype() return next player archetype from archetype
371 { 348 {
372 if (at == NULL || at->next == NULL) 349 if (at == NULL || at->next == NULL)
373 at = first_archetype; 350 at = first_archetype;
374 else 351 else
375 at = at->next; 352 at = at->next;
353
376 if (at->clone.type == PLAYER) 354 if (at->clone.type == PLAYER)
377 return at; 355 return at;
356
378 if (at == start) 357 if (at == start)
379 { 358 {
380 LOG (llevError, "No Player archetypes\n"); 359 LOG (llevError, "No Player archetypes\n");
381 exit (-1); 360 exit (-1);
382 } 361 }
383 } 362 }
384} 363}
385
386 364
387object * 365object *
388get_nearest_player (object *mon) 366get_nearest_player (object *mon)
389{ 367{
390 object *op = NULL; 368 object *op = NULL;
496path_to_player (object *mon, object *pl, unsigned mindiff) 474path_to_player (object *mon, object *pl, unsigned mindiff)
497{ 475{
498 rv_vector rv; 476 rv_vector rv;
499 sint16 x, y; 477 sint16 x, y;
500 int lastx, lasty, dir, i, diff, firstdir = 0, lastdir, max = MAX_SPACES, mflags, blocked; 478 int lastx, lasty, dir, i, diff, firstdir = 0, lastdir, max = MAX_SPACES, mflags, blocked;
501 mapstruct *m, *lastmap; 479 maptile *m, *lastmap;
502 480
503 get_rangevector (mon, pl, &rv, 0); 481 get_rangevector (mon, pl, &rv, 0);
504 482
505 if (rv.distance < mindiff) 483 if (rv.distance < mindiff)
506 return 0; 484 return 0;
650 (op->type == ARMOUR || op->type == BOOTS || 628 (op->type == ARMOUR || op->type == BOOTS ||
651 op->type == CLOAK || op->type == HELMET || 629 op->type == CLOAK || op->type == HELMET ||
652 op->type == SHIELD || op->type == GLOVES || 630 op->type == SHIELD || op->type == GLOVES ||
653 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))
654 { 632 {
655 remove_ob (op); 633 op->destroy ();
656 free_object (op);
657 continue; 634 continue;
658 } 635 }
659 } 636 }
660 637
661 /* This really needs to be better - we should really give 638 /* This really needs to be better - we should really give
672 if (tmp->type == op->type && tmp->name == op->name) 649 if (tmp->type == op->type && tmp->name == op->name)
673 break; 650 break;
674 651
675 if (tmp) 652 if (tmp)
676 { 653 {
677 remove_ob (op); 654 op->destroy ();
678 free_object (op);
679 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);
680 continue; 656 continue;
681 } 657 }
658
682 if (op->nrof > 1) 659 if (op->nrof > 1)
683 op->nrof = 1; 660 op->nrof = 1;
684 } 661 }
685 662
686 if (op->type == SPELLBOOK && op->inv) 663 if (op->type == SPELLBOOK && op->inv)
698 CLEAR_FLAG (op, FLAG_CURSED); 675 CLEAR_FLAG (op, FLAG_CURSED);
699 CLEAR_FLAG (op, FLAG_DAMNED); 676 CLEAR_FLAG (op, FLAG_DAMNED);
700 } 677 }
701 if (op->type == SPELL) 678 if (op->type == SPELL)
702 { 679 {
703 remove_ob (op); 680 op->destroy ();
704 free_object (op);
705 continue; 681 continue;
706 } 682 }
707 else if (op->type == SKILL) 683 else if (op->type == SKILL)
708 { 684 {
709 SET_FLAG (op, FLAG_CAN_USE_SKILL); 685 SET_FLAG (op, FLAG_CAN_USE_SKILL);
722void 698void
723get_name (object *op) 699get_name (object *op)
724{ 700{
725 op->contr->write_buf[0] = '\0'; 701 op->contr->write_buf[0] = '\0';
726 op->contr->state = ST_GET_NAME; 702 op->contr->state = ST_GET_NAME;
727 send_query (&op->contr->socket, 0, "What is your name?\n:"); 703 send_query (op->contr->socket, 0, "What is your name?\n:");
728} 704}
729 705
730void 706void
731get_password (object *op) 707get_password (object *op)
732{ 708{
733 op->contr->write_buf[0] = '\0'; 709 op->contr->write_buf[0] = '\0';
734 op->contr->state = ST_GET_PASSWORD; 710 op->contr->state = ST_GET_PASSWORD;
735 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:");
736} 712}
737 713
738void 714void
739play_again (object *op) 715play_again (object *op)
740{ 716{
741 op->contr->state = ST_PLAY_AGAIN; 717 op->contr->state = ST_PLAY_AGAIN;
742 op->chosen_skill = NULL; 718 op->chosen_skill = NULL;
743 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)?");
744 /* 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
745 * player creation process that a user can quit (eg, roll 721 * player creation process that a user can quit (eg, roll
746 * stats) that isn't removing the player. Taking a quick 722 * stats) that isn't removing the player. Taking a quick
747 * look, there are many places that call play_again without 723 * look, there are many places that call play_again without
748 * removing the player - it probably makes more sense 724 * removing the player - it probably makes more sense
749 * 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
750 * cases. 726 * cases.
751 */ 727 */
752 if (!QUERY_FLAG (op, FLAG_REMOVED)) 728 if (!QUERY_FLAG (op, FLAG_REMOVED))
753 remove_ob (op); 729 op->remove ();
754 /* 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,
755 * 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
756 * the map is null or not swapped out. 732 * the map is null or not swapped out.
757 */ 733 */
758 op->map = NULL; 734 op->map = NULL;
759} 735}
760 736
761
762int 737int
763receive_play_again (object *op, char key) 738receive_play_again (object *op, char key)
764{ 739{
765 if (key == 'q' || key == 'Q') 740 if (key == 'q' || key == 'Q')
766 { 741 {
771 else if (key == 'a' || key == 'A') 746 else if (key == 'a' || key == 'A')
772 { 747 {
773 player *pl = op->contr; 748 player *pl = op->contr;
774 shstr name = op->name; 749 shstr name = op->name;
775 750
776 remove_friendly_object (op); 751 op->contr = 0;
777 free_object (op); 752 op->type = 0;
753 op->destroy (1);
778 pl = get_player (pl); 754 pl = get_player (pl);
779 op = pl->ob; 755 op = pl->ob;
780 add_friendly_object (op); 756 add_friendly_object (op);
781 op->contr->password[0] = '~'; 757 op->contr->password[0] = '~';
782 op->name = op->name_pl = 0; 758 op->name = op->name_pl = 0;
785 get_name (op); 761 get_name (op);
786 op->name = op->name_pl = name; 762 op->name = op->name_pl = name;
787 set_first_map (op); 763 set_first_map (op);
788 } 764 }
789 else 765 else
790 {
791 /* user pressed something else so just ask again... */ 766 /* user pressed something else so just ask again... */
792 play_again (op); 767 play_again (op);
793 } 768
794 return 0; 769 return 0;
795} 770}
796 771
797void 772void
798confirm_password (object *op) 773confirm_password (object *op)
799{ 774{
800 775
801 op->contr->write_buf[0] = '\0'; 776 op->contr->write_buf[0] = '\0';
802 op->contr->state = ST_CONFIRM_PASSWORD; 777 op->contr->state = ST_CONFIRM_PASSWORD;
803 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:");
804} 779}
805 780
806void 781void
807get_party_password (object *op, partylist *party) 782get_party_password (object *op, partylist *party)
808{ 783{
812 return; 787 return;
813 } 788 }
814 op->contr->write_buf[0] = '\0'; 789 op->contr->write_buf[0] = '\0';
815 op->contr->state = ST_GET_PARTY_PASSWORD; 790 op->contr->state = ST_GET_PARTY_PASSWORD;
816 op->contr->party_to_join = party; 791 op->contr->party_to_join = party;
817 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:");
818} 793}
819 794
820 795
821/* 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. */
822int 797int
919 894
920void 895void
921Roll_Again (object *op) 896Roll_Again (object *op)
922{ 897{
923 esrv_new_player (op->contr, 0); 898 esrv_new_player (op->contr, 0);
924 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, 899 send_query (op->contr->socket, CS_QUERY_SINGLECHAR,
925 "[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)? ");
926} 901}
927 902
928void 903void
929Swap_Stat (object *op, int Swap_Second) 904Swap_Stat (object *op, int Swap_Second)
996 new_draw_info (NDI_UNIQUE, 0, op, buf); 971 new_draw_info (NDI_UNIQUE, 0, op, buf);
997 } 972 }
998 else 973 else
999 Swap_Stat (op, stat_trans[keynum]); 974 Swap_Stat (op, stat_trans[keynum]);
1000 975
1001 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, ""); 976 send_query (op->contr->socket, CS_QUERY_SINGLECHAR, "");
1002 return 1; 977 return 1;
1003 } 978 }
1004 switch (key) 979 switch (key)
1005 { 980 {
1006 case 'n': 981 case 'n':
1007 case 'N': 982 case 'N':
1008 { 983 {
1009 SET_FLAG (op, FLAG_WIZ); 984 SET_FLAG (op, FLAG_WIZ);
1010 if (op->map == NULL) 985 if (op->map == NULL)
1011 { 986 {
1012 LOG (llevError, "Map == NULL in state 2\n"); 987 LOG (llevError, "Map == NULL in state 2\n");
1013 break; 988 break;
1014 } 989 }
1015 990
1016#if 0 991#if 0
1017 /* So that enter_exit will put us at startx/starty */ 992 /* So that enter_exit will put us at startx/starty */
1018 op->x = -1; 993 op->x = -1;
1019 994
1020 enter_exit (op, NULL); 995 enter_exit (op, NULL);
1021#endif 996#endif
1022 SET_ANIMATION (op, 2); /* So player faces south */ 997 SET_ANIMATION (op, 2); /* So player faces south */
1023 /* Enter exit adds a player otherwise */ 998 /* Enter exit adds a player otherwise */
1024 add_statbonus (op); 999 add_statbonus (op);
1025 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, 1000 send_query (op->contr->socket, CS_QUERY_SINGLECHAR,
1026 "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n"); 1001 "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n");
1027 op->contr->state = ST_CHANGE_CLASS; 1002 op->contr->state = ST_CHANGE_CLASS;
1028 if (op->msg) 1003 if (op->msg)
1029 new_draw_info (NDI_BLUE, 0, op, op->msg); 1004 new_draw_info (NDI_BLUE, 0, op, op->msg);
1030 return 0;
1031 }
1032 case 'y':
1033 case 'Y':
1034 roll_stats (op);
1035 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "");
1036 return 1;
1037
1038 case 'q':
1039 case 'Q':
1040 play_again (op);
1041 return 1;
1042
1043 default:
1044 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "Yes, No, Quit or 1-6. Roll again?");
1045 return 0; 1005 return 0;
1006 }
1007 case 'y':
1008 case 'Y':
1009 roll_stats (op);
1010 send_query (op->contr->socket, CS_QUERY_SINGLECHAR, "");
1011 return 1;
1012
1013 case 'q':
1014 case 'Q':
1015 play_again (op);
1016 return 1;
1017
1018 default:
1019 send_query (op->contr->socket, CS_QUERY_SINGLECHAR, "Yes, No, Quit or 1-6. Roll again?");
1020 return 0;
1046 } 1021 }
1047 return 0; 1022 return 0;
1048} 1023}
1049 1024
1050/* This function takes the key that is passed, and does the 1025/* This function takes the key that is passed, and does the
1059{ 1034{
1060 int tmp_loop; 1035 int tmp_loop;
1061 1036
1062 if (key == 'q' || key == 'Q') 1037 if (key == 'q' || key == 'Q')
1063 { 1038 {
1064 remove_ob (op); 1039 op->remove ();
1065 play_again (op); 1040 play_again (op);
1066 return 0; 1041 return 0;
1067 } 1042 }
1068 if (key == 'd' || key == 'D') 1043 if (key == 'd' || key == 'D')
1069 { 1044 {
1070 char buf[MAX_BUF]; 1045 char buf[MAX_BUF];
1071 1046
1072 /* this must before then initial items are given */ 1047 /* this must before then initial items are given */
1073 esrv_new_player (op->contr, op->weight + op->carrying); 1048 esrv_new_player (op->contr, op->weight + op->carrying);
1049
1074 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);
1075 1053
1076 INVOKE_PLAYER (BIRTH, op->contr); 1054 INVOKE_PLAYER (BIRTH, op->contr);
1077 INVOKE_PLAYER (LOGIN, op->contr); 1055 INVOKE_PLAYER (LOGIN, op->contr);
1078 1056
1079 op->contr->state = ST_PLAYING; 1057 op->contr->state = ST_PLAYING;
1104 { 1082 {
1105 object *tmp; 1083 object *tmp;
1106 char mapname[MAX_BUF]; 1084 char mapname[MAX_BUF];
1107 1085
1108 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);
1109 tmp = get_object (); 1087 tmp = object::create ();
1110 EXIT_PATH (tmp) = mapname; 1088 EXIT_PATH (tmp) = mapname;
1111 EXIT_X (tmp) = op->x; 1089 EXIT_X (tmp) = op->x;
1112 EXIT_Y (tmp) = op->y; 1090 EXIT_Y (tmp) = op->y;
1113 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;
1114 * if the map isn't there, then stay on the 1092 * if the map isn't there, then stay on the
1115 * default initial map */ 1093 * default initial map */
1116 free_object (tmp); 1094 tmp->destroy ();
1117 } 1095 }
1118 else 1096 else
1119 {
1120 LOG (llevDebug, "first_map_ext_path not set\n"); 1097 LOG (llevDebug, "first_map_ext_path not set\n");
1121 } 1098
1122 return 0; 1099 return 0;
1123 } 1100 }
1124 1101
1125 /* Following actually changes the race - this is the default command 1102 /* Following actually changes the race - this is the default command
1126 * if we don't match with one of the options above. 1103 * if we don't match with one of the options above.
1131 { 1108 {
1132 shstr name = op->name; 1109 shstr name = op->name;
1133 int x = op->x, y = op->y; 1110 int x = op->x, y = op->y;
1134 1111
1135 remove_statbonus (op); 1112 remove_statbonus (op);
1136 remove_ob (op); 1113 op->remove ();
1137 op->arch = get_player_archetype (op->arch); 1114 op->arch = get_player_archetype (op->arch);
1138 copy_object (&op->arch->clone, op); 1115 op->arch->clone.copy_to (op);
1139 op->instantiate (); 1116 op->instantiate ();
1140 op->stats = op->contr->orig_stats; 1117 op->stats = op->contr->orig_stats;
1141 op->name = op->name_pl = name; 1118 op->name = op->name_pl = name;
1142 op->x = x; 1119 op->x = x;
1143 op->y = y; 1120 op->y = y;
1144 SET_ANIMATION (op, 2); /* So player faces south */ 1121 SET_ANIMATION (op, 2); /* So player faces south */
1145 insert_ob_in_map (op, op->map, op, 0); 1122 insert_ob_in_map (op, op->map, op, 0);
1146 strncpy (op->contr->title, op->arch->clone.name, sizeof (op->contr->title) - 1); 1123 assign (op->contr->title, op->arch->clone.name);
1147 op->contr->title[sizeof (op->contr->title) - 1] = '\0';
1148 add_statbonus (op); 1124 add_statbonus (op);
1149 tmp_loop = allowed_class (op); 1125 tmp_loop = allowed_class (op);
1150 } 1126 }
1127
1151 update_object (op, UP_OBJ_FACE); 1128 update_object (op, UP_OBJ_FACE);
1152 esrv_update_item (UPD_FACE, op, op); 1129 esrv_update_item (UPD_FACE, op, op);
1153 fix_player (op); 1130 fix_player (op);
1154 op->stats.hp = op->stats.maxhp; 1131 op->stats.hp = op->stats.maxhp;
1155 op->stats.sp = op->stats.maxsp; 1132 op->stats.sp = op->stats.maxsp;
1156 op->stats.grace = 0; 1133 op->stats.grace = 0;
1134
1157 if (op->msg) 1135 if (op->msg)
1158 new_draw_info (NDI_BLUE, 0, op, op->msg); 1136 new_draw_info (NDI_BLUE, 0, op, op->msg);
1137
1159 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");
1160 return 0; 1139 return 0;
1161} 1140}
1162 1141
1163int 1142int
1164key_confirm_quit (object *op, char key) 1143key_confirm_quit (object *op, char key)
1186 if (settings.set_title == TRUE) 1165 if (settings.set_title == TRUE)
1187 op->contr->own_title[0] = '\0'; 1166 op->contr->own_title[0] = '\0';
1188 1167
1189 if (!QUERY_FLAG (op, FLAG_WAS_WIZ)) 1168 if (!QUERY_FLAG (op, FLAG_WAS_WIZ))
1190 { 1169 {
1191 mapstruct *mp, *next; 1170 maptile *mp, *next;
1192 1171
1193 /* We need to hunt for any per player unique maps in memory and 1172 /* We need to hunt for any per player unique maps in memory and
1194 * get rid of them. The trailing slash in the path is intentional, 1173 * get rid of them. The trailing slash in the path is intentional,
1195 * so that players named 'Ab' won't match against players 'Abe' pathname 1174 * so that players named 'Ab' won't match against players 'Abe' pathname
1196 */ 1175 */
1202 delete_map (mp); 1181 delete_map (mp);
1203 } 1182 }
1204 1183
1205 delete_character (op->name, 1); 1184 delete_character (op->name, 1);
1206 } 1185 }
1186
1207 play_again (op); 1187 play_again (op);
1208 return 1; 1188 return 1;
1209} 1189}
1210 1190
1211void 1191void
1269 */ 1249 */
1270int 1250int
1271check_pick (object *op) 1251check_pick (object *op)
1272{ 1252{
1273 object *tmp, *next; 1253 object *tmp, *next;
1274 tag_t next_tag = 0, op_tag;
1275 int stop = 0; 1254 int stop = 0;
1276 int j, k, wvratio; 1255 int j, k, wvratio;
1277 char putstring[128], tmpstr[16]; 1256 char putstring[128], tmpstr[16];
1278 1257
1279
1280 /* if you're flying, you cna't pick up anything */ 1258 /* if you're flying, you cna't pick up anything */
1281 if (op->move_type & MOVE_FLYING) 1259 if (op->move_type & MOVE_FLYING)
1282 return 1; 1260 return 1;
1283 1261
1284 op_tag = op->count;
1285
1286 next = op->below; 1262 next = op->below;
1287 if (next)
1288 next_tag = next->count;
1289 1263
1290 /* loop while there are items on the floor that are not marked as 1264 /* loop while there are items on the floor that are not marked as
1291 * destroyed */ 1265 * destroyed */
1292 while (next && !was_destroyed (next, next_tag)) 1266 while (next && !next->destroyed ())
1293 { 1267 {
1294 tmp = next; 1268 tmp = next;
1295 next = tmp->below; 1269 next = tmp->below;
1296 if (next)
1297 next_tag = next->count;
1298 1270
1299 if (was_destroyed (op, op_tag)) 1271 if (op->destroyed ())
1300 return 0; 1272 return 0;
1301 1273
1302 if (!can_pick (op, tmp)) 1274 if (!can_pick (op, tmp))
1303 continue; 1275 continue;
1304 1276
1312 /* high not bit set? We're using the old autopickup model */ 1284 /* high not bit set? We're using the old autopickup model */
1313 if (!(op->contr->mode & PU_NEWMODE)) 1285 if (!(op->contr->mode & PU_NEWMODE))
1314 { 1286 {
1315 switch (op->contr->mode) 1287 switch (op->contr->mode)
1316 { 1288 {
1317 case 0: 1289 case 0:
1318 return 1; /* don't pick up */ 1290 return 1; /* don't pick up */
1319 case 1: 1291 case 1:
1292 pick_up (op, tmp);
1293 return 1;
1294 case 2:
1295 pick_up (op, tmp);
1296 return 0;
1297 case 3:
1298 return 0; /* stop before pickup */
1299 case 4:
1300 pick_up (op, tmp);
1301 break;
1302 case 5:
1303 pick_up (op, tmp);
1304 stop = 1;
1305 break;
1306 case 6:
1307 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))
1320 pick_up (op, tmp); 1308 pick_up (op, tmp);
1321 return 1; 1309 break;
1310
1322 case 2: 1311 case 7:
1312 if (tmp->type == MONEY || tmp->type == GEM)
1323 pick_up (op, tmp); 1313 pick_up (op, tmp);
1324 return 0; 1314 break;
1325 case 3: 1315
1326 return 0; /* stop before pickup */ 1316 default:
1327 case 4: 1317 /* use value density */
1318 if (!QUERY_FLAG (tmp, FLAG_UNPAID)
1319 && (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))) >= op->contr->mode)
1328 pick_up (op, tmp); 1320 pick_up (op, tmp);
1329 break;
1330 case 5:
1331 pick_up (op, tmp);
1332 stop = 1;
1333 break;
1334 case 6:
1335 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))
1336 pick_up (op, tmp);
1337 break;
1338
1339 case 7:
1340 if (tmp->type == MONEY || tmp->type == GEM)
1341 pick_up (op, tmp);
1342 break;
1343
1344 default:
1345 /* use value density */
1346 if (!QUERY_FLAG (tmp, FLAG_UNPAID)
1347 && (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))) >= op->contr->mode)
1348 pick_up (op, tmp);
1349 } 1321 }
1350 } 1322 }
1351 else 1323 else
1352 { /* old model */ 1324 { /* old model */
1353 /* NEW pickup handling */ 1325 /* NEW pickup handling */
1436 /* question: don't pick up known-poisonous stuff? */ 1408 /* question: don't pick up known-poisonous stuff? */
1437 if (op->contr->mode & PU_FOOD) 1409 if (op->contr->mode & PU_FOOD)
1438 if (tmp->type == FOOD) 1410 if (tmp->type == FOOD)
1439 { 1411 {
1440 pick_up (op, tmp); 1412 pick_up (op, tmp);
1441 if (0)
1442 fprintf (stderr, "FOOD\n");
1443 continue; 1413 continue;
1444 } 1414 }
1415
1445 if (op->contr->mode & PU_DRINK) 1416 if (op->contr->mode & PU_DRINK)
1446 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)))
1447 { 1418 {
1448 pick_up (op, tmp); 1419 pick_up (op, tmp);
1449 if (0)
1450 fprintf (stderr, "DRINK\n");
1451 continue; 1420 continue;
1452 } 1421 }
1453 1422
1454 if (op->contr->mode & PU_POTION) 1423 if (op->contr->mode & PU_POTION)
1455 if (tmp->type == POTION) 1424 if (tmp->type == POTION)
1456 { 1425 {
1457 pick_up (op, tmp); 1426 pick_up (op, tmp);
1458 if (0)
1459 fprintf (stderr, "POTION\n");
1460 continue; 1427 continue;
1461 } 1428 }
1462 1429
1463 /* spellbooks, skillscrolls and normal books/scrolls */ 1430 /* spellbooks, skillscrolls and normal books/scrolls */
1464 if (op->contr->mode & PU_SPELLBOOK) 1431 if (op->contr->mode & PU_SPELLBOOK)
1465 if (tmp->type == SPELLBOOK) 1432 if (tmp->type == SPELLBOOK)
1466 { 1433 {
1467 pick_up (op, tmp); 1434 pick_up (op, tmp);
1468 if (0)
1469 fprintf (stderr, "SPELLBOOK\n");
1470 continue; 1435 continue;
1471 } 1436 }
1437
1472 if (op->contr->mode & PU_SKILLSCROLL) 1438 if (op->contr->mode & PU_SKILLSCROLL)
1473 if (tmp->type == SKILLSCROLL) 1439 if (tmp->type == SKILLSCROLL)
1474 { 1440 {
1475 pick_up (op, tmp); 1441 pick_up (op, tmp);
1476 if (0)
1477 fprintf (stderr, "SKILLSCROLL\n");
1478 continue; 1442 continue;
1479 } 1443 }
1444
1480 if (op->contr->mode & PU_READABLES) 1445 if (op->contr->mode & PU_READABLES)
1481 if (tmp->type == BOOK || tmp->type == SCROLL) 1446 if (tmp->type == BOOK || tmp->type == SCROLL)
1482 { 1447 {
1483 pick_up (op, tmp); 1448 pick_up (op, tmp);
1484 if (0)
1485 fprintf (stderr, "READABLES\n");
1486 continue; 1449 continue;
1487 } 1450 }
1488 1451
1489 /* wands/staves/rods/horns */ 1452 /* wands/staves/rods/horns */
1490 if (op->contr->mode & PU_MAGIC_DEVICE) 1453 if (op->contr->mode & PU_MAGIC_DEVICE)
1491 if (tmp->type == WAND || tmp->type == ROD || tmp->type == HORN) 1454 if (tmp->type == WAND || tmp->type == ROD || tmp->type == HORN)
1492 { 1455 {
1493 pick_up (op, tmp); 1456 pick_up (op, tmp);
1494 if (0)
1495 fprintf (stderr, "MAGIC_DEVICE\n");
1496 continue; 1457 continue;
1497 } 1458 }
1498 1459
1499 /* pick up all magical items */ 1460 /* pick up all magical items */
1500 if (op->contr->mode & PU_MAGICAL) 1461 if (op->contr->mode & PU_MAGICAL)
1501 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))
1502 { 1463 {
1503 pick_up (op, tmp); 1464 pick_up (op, tmp);
1504 if (0)
1505 fprintf (stderr, "MAGICAL\n");
1506 continue; 1465 continue;
1507 } 1466 }
1508 1467
1509 if (op->contr->mode & PU_VALUABLES) 1468 if (op->contr->mode & PU_VALUABLES)
1510 { 1469 {
1511 if (tmp->type == MONEY || tmp->type == GEM) 1470 if (tmp->type == MONEY || tmp->type == GEM)
1512 { 1471 {
1513 pick_up (op, tmp); 1472 pick_up (op, tmp);
1514 if (0)
1515 fprintf (stderr, "MONEY/GEM\n");
1516 continue; 1473 continue;
1517 } 1474 }
1518 } 1475 }
1519 1476
1520 /* rings & amulets - talismans seems to be typed AMULET */ 1477 /* rings & amulets - talismans seems to be typed AMULET */
1521 if (op->contr->mode & PU_JEWELS) 1478 if (op->contr->mode & PU_JEWELS)
1522 if (tmp->type == RING || tmp->type == AMULET) 1479 if (tmp->type == RING || tmp->type == AMULET)
1523 { 1480 {
1524 pick_up (op, tmp); 1481 pick_up (op, tmp);
1482 continue;
1525 if (0) 1483 }
1526 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);
1527 continue; 1490 continue;
1528 } 1491 }
1529 1492
1530 /* bows and arrows. Bows are good for selling! */ 1493 /* bows and arrows. Bows are good for selling! */
1531 if (op->contr->mode & PU_BOW) 1494 if (op->contr->mode & PU_BOW)
1532 if (tmp->type == BOW) 1495 if (tmp->type == BOW)
1533 { 1496 {
1534 pick_up (op, tmp); 1497 pick_up (op, tmp);
1535 if (0)
1536 fprintf (stderr, "BOW\n");
1537 continue; 1498 continue;
1538 } 1499 }
1500
1539 if (op->contr->mode & PU_ARROW) 1501 if (op->contr->mode & PU_ARROW)
1540 if (tmp->type == ARROW) 1502 if (tmp->type == ARROW)
1541 { 1503 {
1542 pick_up (op, tmp); 1504 pick_up (op, tmp);
1543 if (0)
1544 fprintf (stderr, "ARROW\n");
1545 continue; 1505 continue;
1546 } 1506 }
1547 1507
1548 /* all kinds of armor etc. */ 1508 /* all kinds of armor etc. */
1549 if (op->contr->mode & PU_ARMOUR) 1509 if (op->contr->mode & PU_ARMOUR)
1550 if (tmp->type == ARMOUR) 1510 if (tmp->type == ARMOUR)
1551 { 1511 {
1552 pick_up (op, tmp); 1512 pick_up (op, tmp);
1553 if (0)
1554 fprintf (stderr, "ARMOUR\n");
1555 continue; 1513 continue;
1556 } 1514 }
1515
1557 if (op->contr->mode & PU_HELMET) 1516 if (op->contr->mode & PU_HELMET)
1558 if (tmp->type == HELMET) 1517 if (tmp->type == HELMET)
1559 { 1518 {
1560 pick_up (op, tmp); 1519 pick_up (op, tmp);
1561 if (0)
1562 fprintf (stderr, "HELMET\n");
1563 continue; 1520 continue;
1564 } 1521 }
1522
1565 if (op->contr->mode & PU_SHIELD) 1523 if (op->contr->mode & PU_SHIELD)
1566 if (tmp->type == SHIELD) 1524 if (tmp->type == SHIELD)
1567 { 1525 {
1568 pick_up (op, tmp); 1526 pick_up (op, tmp);
1569 if (0)
1570 fprintf (stderr, "SHIELD\n");
1571 continue; 1527 continue;
1572 } 1528 }
1529
1573 if (op->contr->mode & PU_BOOTS) 1530 if (op->contr->mode & PU_BOOTS)
1574 if (tmp->type == BOOTS) 1531 if (tmp->type == BOOTS)
1575 { 1532 {
1576 pick_up (op, tmp); 1533 pick_up (op, tmp);
1577 if (0)
1578 fprintf (stderr, "BOOTS\n");
1579 continue; 1534 continue;
1580 } 1535 }
1536
1581 if (op->contr->mode & PU_GLOVES) 1537 if (op->contr->mode & PU_GLOVES)
1582 if (tmp->type == GLOVES) 1538 if (tmp->type == GLOVES)
1583 { 1539 {
1584 pick_up (op, tmp); 1540 pick_up (op, tmp);
1585 if (0)
1586 fprintf (stderr, "GLOVES\n");
1587 continue; 1541 continue;
1588 } 1542 }
1543
1589 if (op->contr->mode & PU_CLOAK) 1544 if (op->contr->mode & PU_CLOAK)
1590 if (tmp->type == CLOAK) 1545 if (tmp->type == CLOAK)
1591 { 1546 {
1592 pick_up (op, tmp); 1547 pick_up (op, tmp);
1593 if (0)
1594 fprintf (stderr, "GLOVES\n");
1595 continue; 1548 continue;
1596 } 1549 }
1597 1550
1598 /* hoping to catch throwing daggers here */ 1551 /* hoping to catch throwing daggers here */
1599 if (op->contr->mode & PU_MISSILEWEAPON) 1552 if (op->contr->mode & PU_MISSILEWEAPON)
1600 if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_IS_THROWN)) 1553 if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_IS_THROWN))
1601 { 1554 {
1602 pick_up (op, tmp); 1555 pick_up (op, tmp);
1603 if (0)
1604 fprintf (stderr, "MISSILEWEAPON\n");
1605 continue; 1556 continue;
1606 } 1557 }
1607 1558
1608 /* careful: chairs and tables are weapons! */ 1559 /* careful: chairs and tables are weapons! */
1609 if (op->contr->mode & PU_ALLWEAPON) 1560 if (op->contr->mode & PU_ALLWEAPON)
1612 { 1563 {
1613 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 &&
1614 strstr (tmp->name, "chair") && strstr (tmp->arch->name, "chair") == NULL) 1565 strstr (tmp->name, "chair") && strstr (tmp->arch->name, "chair") == NULL)
1615 { 1566 {
1616 pick_up (op, tmp); 1567 pick_up (op, tmp);
1617 if (0)
1618 fprintf (stderr, "WEAPON\n");
1619 continue; 1568 continue;
1620 } 1569 }
1621 } 1570 }
1571
1622 if (tmp->type == WEAPON && tmp->name == NULL) 1572 if (tmp->type == WEAPON && tmp->name == NULL)
1623 { 1573 {
1624 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)
1625 { 1575 {
1626 pick_up (op, tmp); 1576 pick_up (op, tmp);
1627 if (0)
1628 fprintf (stderr, "WEAPON\n");
1629 continue; 1577 continue;
1630 } 1578 }
1631 } 1579 }
1632 } 1580 }
1633 1581
1634 /* misc stuff that's useful */ 1582 /* misc stuff that's useful */
1635 if (op->contr->mode & PU_KEY) 1583 if (op->contr->mode & PU_KEY)
1636 if (tmp->type == KEY || tmp->type == SPECIAL_KEY) 1584 if (tmp->type == KEY || tmp->type == SPECIAL_KEY)
1637 { 1585 {
1638 pick_up (op, tmp); 1586 pick_up (op, tmp);
1639 if (0)
1640 fprintf (stderr, "KEY\n");
1641 continue; 1587 continue;
1642 } 1588 }
1643 1589
1644 /* 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
1645 * pickups */ 1591 * pickups */
1667 continue; 1613 continue;
1668 } 1614 }
1669 } 1615 }
1670 } /* the new pickup model */ 1616 } /* the new pickup model */
1671 } 1617 }
1618
1672 return !stop; 1619 return !stop;
1673} 1620}
1674 1621
1675/* 1622/*
1676 * Find an arrow in the inventory and after that 1623 * Find an arrow in the inventory and after that
1775 1722
1776object * 1723object *
1777pick_arrow_target (object *op, const char *type, int dir) 1724pick_arrow_target (object *op, const char *type, int dir)
1778{ 1725{
1779 object *tmp = NULL; 1726 object *tmp = NULL;
1780 mapstruct *m; 1727 maptile *m;
1781 int i, mflags, found, number; 1728 int i, mflags, found, number;
1782 sint16 x, y; 1729 sint16 x, y;
1783 1730
1784 if (op->map == NULL) 1731 if (op->map == NULL)
1785 return find_arrow (op, type); 1732 return find_arrow (op, type);
1845 */ 1792 */
1846int 1793int
1847fire_bow (object *op, object *part, object *arrow, int dir, int wc_mod, sint16 sx, sint16 sy) 1794fire_bow (object *op, object *part, object *arrow, int dir, int wc_mod, sint16 sx, sint16 sy)
1848{ 1795{
1849 object *left, *bow; 1796 object *left, *bow;
1850 tag_t left_tag, tag;
1851 int bowspeed, mflags; 1797 int bowspeed, mflags;
1852 mapstruct *m; 1798 maptile *m;
1853 1799
1854 if (!dir) 1800 if (!dir)
1855 { 1801 {
1856 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!");
1857 return 0; 1803 return 0;
1858 } 1804 }
1805
1859 if (op->type == PLAYER) 1806 if (op->type == PLAYER)
1860 bow = op->contr->ranges[range_bow]; 1807 bow = op->contr->ranges[range_bow];
1861 else 1808 else
1862 { 1809 {
1863 for (bow = op->inv; bow; bow = bow->below) 1810 for (bow = op->inv; bow; bow = bow->below)
1871 { 1818 {
1872 LOG (llevError, "Range: bow without activated bow (%s).\n", &op->name); 1819 LOG (llevError, "Range: bow without activated bow (%s).\n", &op->name);
1873 return 0; 1820 return 0;
1874 } 1821 }
1875 } 1822 }
1823
1876 if (!bow->race || !bow->skill) 1824 if (!bow->race || !bow->skill)
1877 { 1825 {
1878 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);
1879 return 0; 1827 return 0;
1880 } 1828 }
1882 bowspeed = bow->stats.sp + dex_bonus[op->stats.Dex]; 1830 bowspeed = bow->stats.sp + dex_bonus[op->stats.Dex];
1883 1831
1884 /* penalize ROF for bestarrow */ 1832 /* penalize ROF for bestarrow */
1885 if (op->type == PLAYER && op->contr->bowtype == bow_bestarrow) 1833 if (op->type == PLAYER && op->contr->bowtype == bow_bestarrow)
1886 bowspeed -= dex_bonus[op->stats.Dex] + 5; 1834 bowspeed -= dex_bonus[op->stats.Dex] + 5;
1835
1887 if (bowspeed < 1) 1836 if (bowspeed < 1)
1888 bowspeed = 1; 1837 bowspeed = 1;
1889 1838
1890 if (arrow == NULL) 1839 if (arrow == NULL)
1891 { 1840 {
1897 else 1846 else
1898 CLEAR_FLAG (op, FLAG_READY_BOW); 1847 CLEAR_FLAG (op, FLAG_READY_BOW);
1899 return 0; 1848 return 0;
1900 } 1849 }
1901 } 1850 }
1851
1902 mflags = get_map_flags (op->map, &m, sx, sy, &sx, &sy); 1852 mflags = get_map_flags (op->map, &m, sx, sy, &sx, &sy);
1903 if (mflags & P_OUT_OF_MAP) 1853 if (mflags & P_OUT_OF_MAP)
1904 {
1905 return 0; 1854 return 0;
1906 } 1855
1907 if (GET_MAP_MOVE_BLOCK (m, sx, sy) == MOVE_FLY_LOW) 1856 if (GET_MAP_MOVE_BLOCK (m, sx, sy) == MOVE_FLY_LOW)
1908 { 1857 {
1909 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.");
1910 return 0; 1859 return 0;
1911 } 1860 }
1912 1861
1913 /* this should not happen, but sometimes does */ 1862 /* this should not happen, but sometimes does */
1914 if (arrow->nrof == 0) 1863 if (arrow->nrof == 0)
1915 { 1864 {
1916 remove_ob (arrow); 1865 arrow->destroy ();
1917 free_object (arrow);
1918 return 0; 1866 return 0;
1919 } 1867 }
1920 1868
1921 left = arrow; /* these are arrows left to the player */ 1869 left = arrow; /* these are arrows left to the player */
1922 left_tag = left->count;
1923 arrow = get_split_ob (arrow, 1); 1870 arrow = get_split_ob (arrow, 1);
1924 if (arrow == NULL) 1871 if (!arrow)
1925 { 1872 {
1926 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);
1927 return 0; 1874 return 0;
1928 } 1875 }
1929 set_owner (arrow, op); 1876
1877 arrow->set_owner (op);
1930 arrow->skill = bow->skill; 1878 arrow->skill = bow->skill;
1931 1879
1932 arrow->direction = dir; 1880 arrow->direction = dir;
1933 arrow->x = sx; 1881 arrow->x = sx;
1934 arrow->y = sy; 1882 arrow->y = sy;
1942 SET_ANIMATION (arrow, arrow->direction); 1890 SET_ANIMATION (arrow, arrow->direction);
1943 arrow->stats.sp = arrow->stats.wc; /* save original wc and dam */ 1891 arrow->stats.sp = arrow->stats.wc; /* save original wc and dam */
1944 arrow->stats.hp = arrow->stats.dam; 1892 arrow->stats.hp = arrow->stats.dam;
1945 arrow->stats.grace = arrow->attacktype; 1893 arrow->stats.grace = arrow->attacktype;
1946 if (arrow->slaying != NULL) 1894 if (arrow->slaying != NULL)
1947 arrow->spellarg = strdup_local (arrow->slaying); 1895 arrow->spellarg = strdup (arrow->slaying);
1948 1896
1949 /* Note that this was different for monsters - they got their level 1897 /* Note that this was different for monsters - they got their level
1950 * 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.
1951 */ 1899 */
1952 1900
1970 arrow->level = op->chosen_skill ? op->chosen_skill->level : op->level; 1918 arrow->level = op->chosen_skill ? op->chosen_skill->level : op->level;
1971 } 1919 }
1972 else 1920 else
1973 { 1921 {
1974 arrow->stats.wc = op->stats.wc - bow->magic - arrow->magic - arrow->stats.wc + wc_mod; 1922 arrow->stats.wc = op->stats.wc - bow->magic - arrow->magic - arrow->stats.wc + wc_mod;
1975
1976 arrow->level = op->level; 1923 arrow->level = op->level;
1977 } 1924 }
1925
1978 if (arrow->attacktype == AT_PHYSICAL) 1926 if (arrow->attacktype == AT_PHYSICAL)
1979 arrow->attacktype |= bow->attacktype; 1927 arrow->attacktype |= bow->attacktype;
1928
1980 if (bow->slaying != NULL) 1929 if (bow->slaying)
1981 arrow->slaying = bow->slaying; 1930 arrow->slaying = bow->slaying;
1982 1931
1983 arrow->map = m; 1932 arrow->map = m;
1984 arrow->move_type = MOVE_FLY_LOW; 1933 arrow->move_type = MOVE_FLY_LOW;
1985 arrow->move_on = MOVE_FLY_LOW | MOVE_WALK; 1934 arrow->move_on = MOVE_FLY_LOW | MOVE_WALK;
1986 1935
1987 play_sound_map (op->map, op->x, op->y, SOUND_FIRE_ARROW); 1936 play_sound_map (op->map, op->x, op->y, SOUND_FIRE_ARROW);
1988 tag = arrow->count;
1989 insert_ob_in_map (arrow, m, op, 0); 1937 insert_ob_in_map (arrow, m, op, 0);
1990 1938
1991 if (!was_destroyed (arrow, tag)) 1939 if (!arrow->destroyed ())
1992 move_arrow (arrow); 1940 move_arrow (arrow);
1993 1941
1994 if (op->type == PLAYER) 1942 if (op->type == PLAYER)
1995 { 1943 {
1996 if (was_destroyed (left, left_tag)) 1944 if (left->destroyed ())
1997 esrv_del_item (op->contr, left_tag); 1945 esrv_del_item (op->contr, left->count);
1998 else 1946 else
1999 esrv_send_item (op, left); 1947 esrv_send_item (op, left);
2000 } 1948 }
1949
2001 return 1; 1950 return 1;
2002} 1951}
2003 1952
2004/* Special fire code for players - this takes into 1953/* Special fire code for players - this takes into
2005 * account the special fire modes players can have 1954 * account the special fire modes players can have
2125 if (action_makes_visible (op)) 2074 if (action_makes_visible (op))
2126 make_visible (op); 2075 make_visible (op);
2127 2076
2128 switch (op->contr->shoottype) 2077 switch (op->contr->shoottype)
2129 { 2078 {
2130 case range_none: 2079 case range_none:
2131 return; 2080 return;
2132 2081
2133 case range_bow: 2082 case range_bow:
2134 player_fire_bow (op, dir); 2083 player_fire_bow (op, dir);
2135 return; 2084 return;
2136 2085
2137 case range_magic: /* Casting spells */ 2086 case range_magic: /* Casting spells */
2138 spellcost = (cast_spell (op, op, dir, op->contr->ranges[range_magic], op->contr->spellparam[0] ? op->contr->spellparam : NULL)); 2087 spellcost = (cast_spell (op, op, dir, op->contr->ranges[range_magic], op->contr->spellparam[0] ? op->contr->spellparam : 0));
2139 return; 2088 return;
2140 2089
2141 case range_misc: 2090 case range_misc:
2142 fire_misc_object (op, dir); 2091 fire_misc_object (op, dir);
2143 return; 2092 return;
2144 2093
2145 case range_golem: /* Control summoned monsters from scrolls */ 2094 case range_golem: /* Control summoned monsters from scrolls */
2146 if (op->contr->ranges[range_golem] == NULL || op->contr->golem_count != op->contr->ranges[range_golem]->count) 2095 if (QUERY_FLAG (op->contr->ranges[range_golem], FLAG_REMOVED))
2147 { 2096 {
2148 op->contr->ranges[range_golem] = NULL; 2097 op->contr->ranges[range_golem] = 0;
2149 op->contr->shoottype = range_none; 2098 op->contr->shoottype = range_none;
2150 op->contr->golem_count = 0;
2151 } 2099 }
2152 else 2100 else
2153 control_golem (op->contr->ranges[range_golem], dir); 2101 control_golem (op->contr->ranges[range_golem], dir);
2154 return; 2102 return;
2155 2103
2156 case range_skill: 2104 case range_skill:
2157 if (!op->chosen_skill) 2105 if (!op->chosen_skill)
2158 { 2106 {
2159 if (op->type == PLAYER) 2107 if (op->type == PLAYER)
2160 new_draw_info (NDI_UNIQUE, 0, op, "You have no applicable skill to use."); 2108 new_draw_info (NDI_UNIQUE, 0, op, "You have no applicable skill to use.");
2161 return; 2109 return;
2162 } 2110 }
2163 (void) do_skill (op, op, op->chosen_skill, dir, NULL); 2111 (void) do_skill (op, op, op->chosen_skill, dir, NULL);
2164 return; 2112 return;
2165 case range_builder: 2113 case range_builder:
2166 apply_map_builder (op, dir); 2114 apply_map_builder (op, dir);
2167 return; 2115 return;
2168 default: 2116 default:
2169 new_draw_info (NDI_UNIQUE, 0, op, "Illegal shoot type."); 2117 new_draw_info (NDI_UNIQUE, 0, op, "Illegal shoot type.");
2170 return; 2118 return;
2171 } 2119 }
2172} 2120}
2173 2121
2174 2122
2175 2123
2317move_player_attack (object *op, int dir) 2265move_player_attack (object *op, int dir)
2318{ 2266{
2319 object *tmp, *mon; 2267 object *tmp, *mon;
2320 sint16 nx, ny; 2268 sint16 nx, ny;
2321 int on_battleground; 2269 int on_battleground;
2322 mapstruct *m; 2270 maptile *m;
2323 2271
2324 nx = freearr_x[dir] + op->x; 2272 nx = freearr_x[dir] + op->x;
2325 ny = freearr_y[dir] + op->y; 2273 ny = freearr_y[dir] + op->y;
2326 2274
2327 on_battleground = op_on_battleground (op, NULL, NULL); 2275 on_battleground = op_on_battleground (op, NULL, NULL);
2363 if (tmp == op) 2311 if (tmp == op)
2364 { 2312 {
2365 tmp = tmp->above; 2313 tmp = tmp->above;
2366 continue; 2314 continue;
2367 } 2315 }
2316
2368 if (QUERY_FLAG (tmp, FLAG_ALIVE)) 2317 if (QUERY_FLAG (tmp, FLAG_ALIVE))
2369 { 2318 {
2370 mon = tmp; 2319 mon = tmp;
2371 break; 2320 break;
2372 } 2321 }
2322
2373 if (tmp->type == LOCKED_DOOR || QUERY_FLAG (tmp, FLAG_CAN_ROLL)) 2323 if (tmp->type == LOCKED_DOOR || QUERY_FLAG (tmp, FLAG_CAN_ROLL))
2374 mon = tmp; 2324 mon = tmp;
2325
2375 tmp = tmp->above; 2326 tmp = tmp->above;
2376 } 2327 }
2377 2328
2378 if (mon == NULL) /* This happens anytime the player tries to move */ 2329 if (mon == NULL) /* This happens anytime the player tries to move */
2379 return; /* into a wall */ 2330 return; /* into a wall */
2398 * player owns it and it is either friendly or unagressive. 2349 * player owns it and it is either friendly or unagressive.
2399 */ 2350 */
2400 if ((op->type == PLAYER) 2351 if ((op->type == PLAYER)
2401#if COZY_SERVER 2352#if COZY_SERVER
2402 && 2353 &&
2403 ((get_owner (mon) && get_owner (mon)->contr 2354 ((mon->owner && mon->owner->contr
2404 && same_party (get_owner (mon)->contr->party, op->contr->party)) || get_owner (mon) == op) 2355 && same_party (mon->owner->contr->party, op->contr->party)) || mon->owner == op)
2405#else 2356#else
2406 && get_owner (mon) == op 2357 && mon->owner == op
2407#endif 2358#endif
2408 && (QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY))) 2359 && (QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY)))
2409 { 2360 {
2410 /* If we're braced, we don't want to switch places with it */ 2361 /* If we're braced, we don't want to switch places with it */
2411 if (op->contr->braced) 2362 if (op->contr->braced)
2598 /* I've been seeing crashes where the golem has been destroyed, but 2549 /* I've been seeing crashes where the golem has been destroyed, but
2599 * the player object still points to the defunct golem. The code that 2550 * the player object still points to the defunct golem. The code that
2600 * destroys the golem looks correct, and it doesn't always happen, so 2551 * destroys the golem looks correct, and it doesn't always happen, so
2601 * put this in a a workaround to clean up the golem pointer. 2552 * put this in a a workaround to clean up the golem pointer.
2602 */ 2553 */
2603 if (op->contr->ranges[range_golem] &&
2604 ((op->contr->golem_count != op->contr->ranges[range_golem]->count) || QUERY_FLAG (op->contr->ranges[range_golem], FLAG_REMOVED))) 2554 if (op->contr->ranges[range_golem] && QUERY_FLAG (op->contr->ranges[range_golem], FLAG_REMOVED))
2605 {
2606 op->contr->ranges[range_golem] = NULL; 2555 op->contr->ranges[range_golem] = 0;
2607 op->contr->golem_count = 0;
2608 }
2609 2556
2610 /* call this here - we also will call this in do_ericserver, but 2557 /* call this here - we also will call this in do_ericserver, but
2611 * the players time has been increased when doericserver has been 2558 * the players time has been increased when doericserver has been
2612 * called, so we recheck it here. 2559 * called, so we recheck it here.
2613 */ 2560 */
2614 HandleClient (&op->contr->socket, op->contr); 2561 //TODO: better than handling 8 commands, use some more intelligent rate-limiting
2562 for (int rep = 8; --rep && op->contr->socket->handle_command (); )
2563 ;
2564
2615 if (op->speed_left < 0) 2565 if (op->speed_left < 0)
2616 return 0; 2566 return 0;
2617 2567
2618 if (op->direction && (op->contr->run_on || op->contr->fire_on)) 2568 if (op->direction && (op->contr->run_on || op->contr->fire_on))
2619 { 2569 {
2628 if (op->speed_left > 0) 2578 if (op->speed_left > 0)
2629 return 1; 2579 return 1;
2630 else 2580 else
2631 return 0; 2581 return 0;
2632 } 2582 }
2583
2633 return 0; 2584 return 0;
2634} 2585}
2635 2586
2636int 2587int
2637save_life (object *op) 2588save_life (object *op)
2638{ 2589{
2639 object *tmp;
2640
2641 if (!QUERY_FLAG (op, FLAG_LIFESAVE)) 2590 if (!QUERY_FLAG (op, FLAG_LIFESAVE))
2642 return 0; 2591 return 0;
2643 2592
2644 for (tmp = op->inv; tmp != NULL; tmp = tmp->below) 2593 for (object *tmp = op->inv; tmp; tmp = tmp->below)
2645 if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE)) 2594 if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE))
2646 { 2595 {
2647 play_sound_map (op->map, op->x, op->y, SOUND_OB_EVAPORATE); 2596 play_sound_map (op->map, op->x, op->y, SOUND_OB_EVAPORATE);
2648 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s vibrates violently, then evaporates.", query_name (tmp)); 2597 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s vibrates violently, then evaporates.", query_name (tmp));
2598
2649 if (op->contr) 2599 if (op->contr)
2650 esrv_del_item (op->contr, tmp->count); 2600 esrv_del_item (op->contr, tmp->count);
2651 remove_ob (tmp); 2601
2652 free_object (tmp); 2602 tmp->destroy ();
2653 CLEAR_FLAG (op, FLAG_LIFESAVE); 2603 CLEAR_FLAG (op, FLAG_LIFESAVE);
2604
2654 if (op->stats.hp < 0) 2605 if (op->stats.hp < 0)
2655 op->stats.hp = op->stats.maxhp; 2606 op->stats.hp = op->stats.maxhp;
2607
2656 if (op->stats.food < 0) 2608 if (op->stats.food < 0)
2657 op->stats.food = 999; 2609 op->stats.food = 999;
2610
2658 fix_player (op); 2611 fix_player (op);
2659 return 1; 2612 return 1;
2660 } 2613 }
2614
2661 LOG (llevError, "Error: LIFESAVE set without applied object.\n"); 2615 LOG (llevError, "Error: LIFESAVE set without applied object.\n");
2662 CLEAR_FLAG (op, FLAG_LIFESAVE); 2616 CLEAR_FLAG (op, FLAG_LIFESAVE);
2663 enter_player_savebed (op); /* bring him home. */ 2617 enter_player_savebed (op); /* bring him home. */
2664 return 0; 2618 return 0;
2665} 2619}
2679 next = op->below; /* Make sure we have a good value, in case 2633 next = op->below; /* Make sure we have a good value, in case
2680 * we remove object 'op' 2634 * we remove object 'op'
2681 */ 2635 */
2682 if (QUERY_FLAG (op, FLAG_UNPAID)) 2636 if (QUERY_FLAG (op, FLAG_UNPAID))
2683 { 2637 {
2684 remove_ob (op); 2638 op->remove ();
2685 op->x = env->x; 2639 op->x = env->x;
2686 op->y = env->y; 2640 op->y = env->y;
2687 if (env->type == PLAYER) 2641 if (env->type == PLAYER)
2688 esrv_del_item (env->contr, op->count); 2642 esrv_del_item (env->contr, op->count);
2689 insert_ob_in_map (op, env->map, NULL, 0); 2643 insert_ob_in_map (op, env->map, NULL, 0);
2690 } 2644 }
2691 else if (op->inv) 2645 else if (op->inv)
2692 remove_unpaid_objects (op->inv, env); 2646 remove_unpaid_objects (op->inv, env);
2647
2693 op = next; 2648 op = next;
2694 } 2649 }
2695} 2650}
2696 2651
2697 2652
2712 strcpy (buf2, " R.I.P.\n\n"); 2667 strcpy (buf2, " R.I.P.\n\n");
2713 if (op->type == PLAYER) 2668 if (op->type == PLAYER)
2714 sprintf (buf, "%s the %s\n", &op->name, op->contr->title); 2669 sprintf (buf, "%s the %s\n", &op->name, op->contr->title);
2715 else 2670 else
2716 sprintf (buf, "%s\n", &op->name); 2671 sprintf (buf, "%s\n", &op->name);
2672
2717 strncat (buf2, " ", 20 - strlen (buf) / 2); 2673 strncat (buf2, " ", 20 - strlen (buf) / 2);
2718 strcat (buf2, buf); 2674 strcat (buf2, buf);
2719 if (op->type == PLAYER) 2675 if (op->type == PLAYER)
2720 sprintf (buf, "who was in level %d when killed\n", op->level); 2676 sprintf (buf, "who was in level %d when killed\n", op->level);
2721 else 2677 else
2722 sprintf (buf, "who was in level %d when died.\n\n", op->level); 2678 sprintf (buf, "who was in level %d when died.\n\n", op->level);
2679
2723 strncat (buf2, " ", 20 - strlen (buf) / 2); 2680 strncat (buf2, " ", 20 - strlen (buf) / 2);
2724 strcat (buf2, buf); 2681 strcat (buf2, buf);
2725 if (op->type == PLAYER) 2682 if (op->type == PLAYER)
2726 { 2683 {
2727 sprintf (buf, "by %s.\n\n", op->contr->killer); 2684 sprintf (buf, "by %s.\n\n", op->contr->killer);
2728 strncat (buf2, " ", 21 - strlen (buf) / 2); 2685 strncat (buf2, " ", 21 - strlen (buf) / 2);
2729 strcat (buf2, buf); 2686 strcat (buf2, buf);
2730 } 2687 }
2688
2731 strftime (buf, MAX_BUF, "%b %d %Y\n", localtime (&now)); 2689 strftime (buf, MAX_BUF, "%b %d %Y\n", localtime (&now));
2732 strncat (buf2, " ", 20 - strlen (buf) / 2); 2690 strncat (buf2, " ", 20 - strlen (buf) / 2);
2733 strcat (buf2, buf); 2691 strcat (buf2, buf);
2692
2734 return buf2; 2693 return buf2;
2735} 2694}
2736 2695
2737 2696
2738 2697
2957{ 2916{
2958 char buf[MAX_BUF]; 2917 char buf[MAX_BUF];
2959 int x, y; 2918 int x, y;
2960 2919
2961 //int i; 2920 //int i;
2962 mapstruct *map; /* this is for resurrection */ 2921 maptile *map; /* this is for resurrection */
2963 2922
2964 /* int z; 2923 /* int z;
2965 int num_stats_lose; 2924 int num_stats_lose;
2966 int lost_a_stat; 2925 int lost_a_stat;
2967 int lose_this_stat; 2926 int lose_this_stat;
2982 { 2941 {
2983 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, "You have been defeated in combat!"); 2942 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, "You have been defeated in combat!");
2984 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, "Local medics have saved your life..."); 2943 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, "Local medics have saved your life...");
2985 2944
2986 /* restore player */ 2945 /* restore player */
2987 at = find_archetype ("poisoning"); 2946 at = archetype::find ("poisoning");
2988 tmp = present_arch_in_ob (at, op); 2947 tmp = present_arch_in_ob (at, op);
2989 if (tmp) 2948 if (tmp)
2990 { 2949 {
2991 remove_ob (tmp); 2950 tmp->destroy ();
2992 free_object (tmp);
2993 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed"); 2951 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed");
2994 } 2952 }
2995 2953
2996 at = find_archetype ("confusion"); 2954 at = archetype::find ("confusion");
2997 tmp = present_arch_in_ob (at, op); 2955 tmp = present_arch_in_ob (at, op);
2998 if (tmp) 2956 if (tmp)
2999 { 2957 {
3000 remove_ob (tmp); 2958 tmp->destroy ();
3001 free_object (tmp);
3002 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer"); 2959 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer");
3003 } 2960 }
3004 2961
3005 cure_disease (op, 0); /* remove any disease */ 2962 cure_disease (op, 0); /* remove any disease */
3006 op->stats.hp = op->stats.maxhp; 2963 op->stats.hp = op->stats.maxhp;
3007 if (op->stats.food <= 0) 2964 if (op->stats.food <= 0)
3008 op->stats.food = 999; 2965 op->stats.food = 999;
3009 2966
3010 /* create a bodypart-trophy to make the winner happy */ 2967 /* create a bodypart-trophy to make the winner happy */
3011 tmp = arch_to_object (find_archetype ("finger")); 2968 tmp = arch_to_object (archetype::find ("finger"));
3012 if (tmp != NULL) 2969 if (tmp != NULL)
3013 { 2970 {
3014 sprintf (buf, "%s's finger", &op->name); 2971 sprintf (buf, "%s's finger", &op->name);
3015 tmp->name = buf; 2972 tmp->name = buf;
3016 sprintf (buf, " This finger has been cut off %s\n" 2973 sprintf (buf, " This finger has been cut off %s\n"
3113 lost_a_stat = 1; 3070 lost_a_stat = 1;
3114 } 3071 }
3115 else 3072 else
3116 { 3073 {
3117 /* deplete a stat */ 3074 /* deplete a stat */
3118 archetype *deparch = find_archetype ("depletion"); 3075 archetype *deparch = archetype::find ("depletion");
3119 object *dep; 3076 object *dep;
3120 3077
3121 dep = present_arch_in_ob (deparch, op); 3078 dep = present_arch_in_ob (deparch, op);
3122 if (!dep) 3079 if (!dep)
3123 { 3080 {
3183 /* determine_god() seems to not work sometimes... why is this? 3140 /* determine_god() seems to not work sometimes... why is this?
3184 Should I be using something else? GD */ 3141 Should I be using something else? GD */
3185 const char *god = determine_god (op); 3142 const char *god = determine_god (op);
3186 3143
3187 if (god && (strcmp (god, "none"))) 3144 if (god && (strcmp (god, "none")))
3188 new_draw_info_format (NDI_UNIQUE, 0, op, "For a brief " "moment you feel the holy presence of %s protecting" " you.", god); 3145 new_draw_info_format (NDI_UNIQUE, 0, op, "For a brief moment you feel the holy presence of %s protecting" " you.", god);
3189 else 3146 else
3190 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you" " feel a holy presence protecting you."); 3147 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you feel a holy presence protecting you.");
3191 } 3148 }
3149#else
3150 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you" " feel a holy presence protecting you from losing yourself completely.");
3192#endif 3151#endif
3193 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you" " feel a holy presence protecting you from losing yourself completely.");
3194 3152
3195 /* Put a gravestone up where the character 'almost' died. List the 3153 /* Put a gravestone up where the character 'almost' died. List the
3196 * exp loss on the stone. 3154 * exp loss on the stone.
3197 */ 3155 */
3198 tmp = arch_to_object (find_archetype ("gravestone")); 3156 tmp = arch_to_object (archetype::find ("gravestone"));
3199 sprintf (buf, "%s's gravestone", &op->name); 3157 sprintf (buf, "%s's gravestone", &op->name);
3200 tmp->name = buf; 3158 tmp->name = buf;
3201 sprintf (buf, "%s's gravestones", &op->name); 3159 sprintf (buf, "%s's gravestones", &op->name);
3202 tmp->name_pl = buf; 3160 tmp->name_pl = buf;
3203 sprintf (buf, "RIP\nHere rests the hero %s the %s,\n" "who was killed\n" "by %s.\n", &op->name, op->contr->title, op->contr->killer); 3161 sprintf (buf, "RIP\nHere rests the hero %s the %s,\n" "who was killed\n" "by %s.\n", &op->name, op->contr->title, op->contr->killer);
3204 tmp->msg = buf; 3162 tmp->msg = buf;
3205 tmp->x = op->x, tmp->y = op->y; 3163 tmp->x = op->x, tmp->y = op->y;
3206 insert_ob_in_map (tmp, op->map, NULL, 0); 3164 insert_ob_in_map (tmp, op->map, NULL, 0);
3207 3165
3208 /**************************************/ 3166 /**************************************/
3209 /* */ 3167 /* */
3210 /* Subtract the experience points, */ 3168 /* Subtract the experience points, */
3211 /* if we died cause of food, give us */ 3169 /* if we died cause of food, give us */
3212 /* food, and reset HP's... */ 3170 /* food, and reset HP's... */
3213 /* */ 3171 /* */
3214
3215 /**************************************/ 3172 /**************************************/
3216 3173
3217 /* remove any poisoning and confusion the character may be suffering. */ 3174 /* remove any poisoning and confusion the character may be suffering. */
3218 /* restore player */ 3175 /* restore player */
3219 at = find_archetype ("poisoning"); 3176 at = archetype::find ("poisoning");
3177 tmp = present_arch_in_ob (at, op);
3178
3179 if (tmp)
3180 {
3181 tmp->destroy ();
3182 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed");
3183 }
3184
3185 at = archetype::find ("confusion");
3220 tmp = present_arch_in_ob (at, op); 3186 tmp = present_arch_in_ob (at, op);
3221 if (tmp) 3187 if (tmp)
3222 { 3188 {
3223 remove_ob (tmp); 3189 tmp->destroy ();
3224 free_object (tmp);
3225 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed");
3226 }
3227
3228 at = find_archetype ("confusion");
3229 tmp = present_arch_in_ob (at, op);
3230 if (tmp)
3231 {
3232 remove_ob (tmp);
3233 free_object (tmp);
3234 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer"); 3190 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer");
3235 } 3191 }
3192
3236 cure_disease (op, 0); /* remove any disease */ 3193 cure_disease (op, 0); /* remove any disease */
3237 3194
3238 /*add_exp(op, (op->stats.exp * -0.20)); */ 3195 /*add_exp(op, (op->stats.exp * -0.20)); */
3239 apply_death_exp_penalty (op); 3196 apply_death_exp_penalty (op);
3240 if (op->stats.food < 100) 3197 if (op->stats.food < 100)
3250 */ 3207 */
3251 3208
3252 if (is_in_shop (op)) 3209 if (is_in_shop (op))
3253 remove_unpaid_objects (op->inv, op); 3210 remove_unpaid_objects (op->inv, op);
3254 3211
3255 /****************************************/ 3212 /****************************************/
3256 /* */ 3213 /* */
3257 /* Move player to his current respawn- */ 3214 /* Move player to his current respawn- */
3258 /* position (usually last savebed) */ 3215 /* position (usually last savebed) */
3259 /* */ 3216 /* */
3260
3261 /****************************************/ 3217 /****************************************/
3262 3218
3263 enter_player_savebed (op); 3219 enter_player_savebed (op);
3264 3220
3265 /* Save the player before inserting the force to reduce 3221 /* Save the player before inserting the force to reduce
3266 * chance of abuse. 3222 * chance of abuse.
3273 * spell effects. So first see if there is a spell effect 3229 * spell effects. So first see if there is a spell effect
3274 * on the space that might harm the player. 3230 * on the space that might harm the player.
3275 */ 3231 */
3276 will_kill_again = 0; 3232 will_kill_again = 0;
3277 for (tmp = get_map_ob (op->map, op->x, op->y); tmp; tmp = tmp->above) 3233 for (tmp = get_map_ob (op->map, op->x, op->y); tmp; tmp = tmp->above)
3278 {
3279 if (tmp->type == SPELL_EFFECT) 3234 if (tmp->type == SPELL_EFFECT)
3280 will_kill_again |= tmp->attacktype; 3235 will_kill_again |= tmp->attacktype;
3281 } 3236
3282 if (will_kill_again) 3237 if (will_kill_again)
3283 { 3238 {
3284 object *force; 3239 object *force;
3285 int at; 3240 int at;
3286 3241
3288 /* 50 ticks should be enough time for the spell to abate */ 3243 /* 50 ticks should be enough time for the spell to abate */
3289 force->speed = 0.1; 3244 force->speed = 0.1;
3290 force->speed_left = -5.0; 3245 force->speed_left = -5.0;
3291 SET_FLAG (force, FLAG_APPLIED); 3246 SET_FLAG (force, FLAG_APPLIED);
3292 for (at = 0; at < NROFATTACKS; at++) 3247 for (at = 0; at < NROFATTACKS; at++)
3293 {
3294 if (will_kill_again & (1 << at)) 3248 if (will_kill_again & (1 << at))
3295 force->resist[at] = 100; 3249 force->resist[at] = 100;
3296 } 3250
3297 insert_ob_in_ob (force, op); 3251 insert_ob_in_ob (force, op);
3298 fix_player (op); 3252 fix_player (op);
3299 3253
3300 } 3254 }
3301
3302 /**************************************/
3303 /* */
3304 /* Repaint the characters inv, and */
3305 /* stats, and show a nasty message ;) */
3306 /* */
3307
3308 /**************************************/
3309 3255
3310 new_draw_info (NDI_UNIQUE, 0, op, "YOU HAVE DIED."); 3256 new_draw_info (NDI_UNIQUE, 0, op, "YOU HAVE DIED.");
3311 return; 3257 return;
3312 } /* NOT_PERMADETH */ 3258 } /* NOT_PERMADETH */
3313 else 3259 else
3319 op->contr->party = NULL; 3265 op->contr->party = NULL;
3320 if (settings.set_title == TRUE) 3266 if (settings.set_title == TRUE)
3321 op->contr->own_title[0] = '\0'; 3267 op->contr->own_title[0] = '\0';
3322 new_draw_info (NDI_UNIQUE | NDI_ALL, 0, NULL, buf); 3268 new_draw_info (NDI_UNIQUE | NDI_ALL, 0, NULL, buf);
3323 check_score (op); 3269 check_score (op);
3270
3324 if (op->contr->ranges[range_golem] != NULL) 3271 if (op->contr->ranges[range_golem])
3325 { 3272 {
3326 remove_friendly_object (op->contr->ranges[range_golem]); 3273 remove_friendly_object (op->contr->ranges[range_golem]);
3327 remove_ob (op->contr->ranges[range_golem]); 3274 op->contr->ranges[range_golem]->destroy ();
3328 free_object (op->contr->ranges[range_golem]);
3329 op->contr->ranges[range_golem] = NULL; 3275 op->contr->ranges[range_golem] = 0;
3330 op->contr->golem_count = 0;
3331 } 3276 }
3277
3332 loot_object (op); /* Remove some of the items for good */ 3278 loot_object (op); /* Remove some of the items for good */
3333 remove_ob (op); 3279 op->remove ();
3334 op->direction = 0; 3280 op->direction = 0;
3335 3281
3336 if (!QUERY_FLAG (op, FLAG_WAS_WIZ) && op->stats.exp) 3282 if (!QUERY_FLAG (op, FLAG_WAS_WIZ) && op->stats.exp)
3337 { 3283 {
3338 delete_character (op->name, 0); 3284 delete_character (op->name, 0);
3357 op->map = map; 3303 op->map = map;
3358 /* please see resurrection.c: peterm */ 3304 /* please see resurrection.c: peterm */
3359 dead_player (op); 3305 dead_player (op);
3360 } 3306 }
3361 else 3307 else
3362 {
3363 delete_character (op->name, 1); 3308 delete_character (op->name, 1);
3364 } 3309 }
3365 } 3310
3366 play_again (op); 3311 play_again (op);
3367 3312
3368 /* peterm: added to create a corpse at deathsite. */ 3313 /* peterm: added to create a corpse at deathsite. */
3369 tmp = arch_to_object (find_archetype ("corpse_pl")); 3314 tmp = arch_to_object (archetype::find ("corpse_pl"));
3370 sprintf (buf, "%s", &op->name); 3315 sprintf (buf, "%s", &op->name);
3371 tmp->name = tmp->name_pl = buf; 3316 tmp->name = tmp->name_pl = buf;
3372 tmp->level = op->level; 3317 tmp->level = op->level;
3373 tmp->x = x; 3318 tmp->x = x;
3374 tmp->y = y; 3319 tmp->y = y;
3392 for (tmp = op->inv; tmp != NULL; tmp = next) 3337 for (tmp = op->inv; tmp != NULL; tmp = next)
3393 { 3338 {
3394 next = tmp->below; 3339 next = tmp->below;
3395 if (tmp->type == EXPERIENCE || tmp->invisible) 3340 if (tmp->type == EXPERIENCE || tmp->invisible)
3396 continue; 3341 continue;
3397 remove_ob (tmp); 3342 tmp->remove ();
3398 tmp->x = op->x, tmp->y = op->y; 3343 tmp->x = op->x, tmp->y = op->y;
3399 if (tmp->type == CONTAINER) 3344 if (tmp->type == CONTAINER)
3400 { /* empty container to ground */ 3345 { /* empty container to ground */
3401 loot_object (tmp); 3346 loot_object (tmp);
3402 } 3347 }
3403 if (!QUERY_FLAG (tmp, FLAG_UNIQUE) && (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || QUERY_FLAG (tmp, FLAG_NO_DROP) || !(RANDOM () % 3))) 3348 if (!QUERY_FLAG (tmp, FLAG_UNIQUE) && (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || QUERY_FLAG (tmp, FLAG_NO_DROP) || !(RANDOM () % 3)))
3404 { 3349 {
3405 if (tmp->nrof > 1) 3350 if (tmp->nrof > 1)
3406 { 3351 {
3407 tmp2 = get_split_ob (tmp, 1 + RANDOM () % (tmp->nrof - 1)); 3352 tmp2 = get_split_ob (tmp, 1 + RANDOM () % (tmp->nrof - 1));
3408 free_object (tmp2); 3353 tmp2->destroy ();
3409 insert_ob_in_map (tmp, op->map, NULL, 0); 3354 insert_ob_in_map (tmp, op->map, NULL, 0);
3410 } 3355 }
3411 else 3356 else
3412 free_object (tmp); 3357 tmp->destroy ();
3413 } 3358 }
3414 else 3359 else
3415 insert_ob_in_map (tmp, op->map, NULL, 0); 3360 insert_ob_in_map (tmp, op->map, NULL, 0);
3416 } 3361 }
3417} 3362}
3482 if (op->type == PLAYER) 3427 if (op->type == PLAYER)
3483 new_draw_info_format (NDI_UNIQUE, 0, op, "You cast %s.", &spob->name); 3428 new_draw_info_format (NDI_UNIQUE, 0, op, "You cast %s.", &spob->name);
3484 3429
3485 cast_spell (op, throw_ob, dir, spob, NULL); 3430 cast_spell (op, throw_ob, dir, spob, NULL);
3486 3431
3487 if (!QUERY_FLAG (throw_ob, FLAG_REMOVED)) 3432 throw_ob->destroy ();
3488 remove_ob (throw_ob);
3489 free_object (throw_ob);
3490} 3433}
3491 3434
3492void 3435void
3493make_visible (object *op) 3436make_visible (object *op)
3494{ 3437{
3610int 3553int
3611stand_near_hostile (object *who) 3554stand_near_hostile (object *who)
3612{ 3555{
3613 object *tmp = NULL; 3556 object *tmp = NULL;
3614 int i, friendly = 0, player = 0, mflags; 3557 int i, friendly = 0, player = 0, mflags;
3615 mapstruct *m; 3558 maptile *m;
3616 sint16 x, y; 3559 sint16 x, y;
3617 3560
3618 if (!who) 3561 if (!who)
3619 return 0; 3562 return 0;
3620 3563
3701 3644
3702 /* only the viewable area the player sees is updated by LOS 3645 /* only the viewable area the player sees is updated by LOS
3703 * code, so we need to restrict ourselves to that range of values 3646 * code, so we need to restrict ourselves to that range of values
3704 * for any meaningful values. 3647 * for any meaningful values.
3705 */ 3648 */
3706 if (FABS (dx) <= (pl->contr->socket.mapx / 2) && 3649 if (FABS (dx) <= (pl->contr->socket->mapx / 2) &&
3707 FABS (dy) <= (pl->contr->socket.mapy / 2) && 3650 FABS (dy) <= (pl->contr->socket->mapy / 2) &&
3708 !pl->contr->blocked_los[dx + (pl->contr->socket.mapx / 2)][dy + (pl->contr->socket.mapy / 2)]) 3651 !pl->contr->blocked_los[dx + (pl->contr->socket->mapx / 2)][dy + (pl->contr->socket->mapy / 2)])
3709 return 1; 3652 return 1;
3710 op = op->more; 3653 op = op->more;
3711 } 3654 }
3712 return 0; 3655 return 0;
3713} 3656}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines