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.30 by root, Sat Dec 9 16:11:09 2006 UTC vs.
Revision 1.52 by root, Thu Dec 21 23:37:06 2006 UTC

20 20
21 The author can be reached via e-mail to <crossfire@schmorp.de> 21 The author can be reached via e-mail to <crossfire@schmorp.de>
22*/ 22*/
23 23
24#include <global.h> 24#include <global.h>
25#ifndef WIN32 /* ---win32 remove headers */
26# include <pwd.h> 25#include <pwd.h>
27#endif
28#ifndef __CEXTRACT__
29# include <sproto.h> 26#include <sproto.h>
30#endif
31#include <sounds.h> 27#include <sounds.h>
32#include <living.h> 28#include <living.h>
33#include <object.h> 29#include <object.h>
34#include <spells.h> 30#include <spells.h>
35#include <skills.h> 31#include <skills.h>
36#include <newclient.h>
37 32
38#ifdef COZY_SERVER 33#ifdef COZY_SERVER
39extern int same_party (partylist *a, partylist *b); 34extern int same_party (partylist *a, partylist *b);
40#endif 35#endif
41 36
87 int comp; 82 int comp;
88 int size; 83 int size;
89 84
90 sprintf (buf, "%s/%s", settings.confdir, settings.motd); 85 sprintf (buf, "%s/%s", settings.confdir, settings.motd);
91 if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL) 86 if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL)
92 {
93 return; 87 return;
94 } 88
95 motd[0] = '\0'; 89 motd[0] = '\0';
96 size = 0; 90 size = 0;
91
97 while (fgets (buf, MAX_BUF, fp) != NULL) 92 while (fgets (buf, MAX_BUF, fp) != NULL)
98 { 93 {
99 if (*buf == '#') 94 if (*buf == '#')
100 continue; 95 continue;
96
101 strncat (motd + size, buf, HUGE_BUF - size); 97 strncat (motd + size, buf, HUGE_BUF - size);
102 size += strlen (buf); 98 size += strlen (buf);
103 } 99 }
100
104 draw_ext_info (NDI_UNIQUE | NDI_GREEN, 0, op, MSG_TYPE_MOTD, MSG_SUBTYPE_NONE, motd, NULL); 101 draw_ext_info (NDI_UNIQUE | NDI_GREEN, 0, op, MSG_TYPE_MOTD, MSG_SUBTYPE_NONE, motd, NULL);
105 close_and_delete (fp, comp); 102 close_and_delete (fp, comp);
106} 103}
107 104
108void 105void
114 int comp; 111 int comp;
115 int size; 112 int size;
116 113
117 sprintf (buf, "%s/%s", settings.confdir, settings.rules); 114 sprintf (buf, "%s/%s", settings.confdir, settings.rules);
118 if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL) 115 if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL)
119 {
120 return; 116 return;
121 } 117
122 rules[0] = '\0'; 118 rules[0] = '\0';
123 size = 0; 119 size = 0;
120
124 while (fgets (buf, MAX_BUF, fp) != NULL) 121 while (fgets (buf, MAX_BUF, fp) != NULL)
125 { 122 {
126 if (*buf == '#') 123 if (*buf == '#')
127 continue; 124 continue;
125
128 if (size + strlen (buf) >= HUGE_BUF) 126 if (size + strlen (buf) >= HUGE_BUF)
129 { 127 {
130 LOG (llevDebug, "Warning, rules size is > %d bytes.\n", HUGE_BUF); 128 LOG (llevDebug, "Warning, rules size is > %d bytes.\n", HUGE_BUF);
131 break; 129 break;
132 } 130 }
131
133 strncat (rules + size, buf, HUGE_BUF - size); 132 strncat (rules + size, buf, HUGE_BUF - size);
134 size += strlen (buf); 133 size += strlen (buf);
135 } 134 }
135
136 draw_ext_info (NDI_UNIQUE | NDI_GREEN, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_RULES, rules, NULL); 136 draw_ext_info (NDI_UNIQUE | NDI_GREEN, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_RULES, rules, NULL);
137 close_and_delete (fp, comp); 137 close_and_delete (fp, comp);
138} 138}
139 139
140void 140void
148 int size; 148 int size;
149 149
150 sprintf (buf, "%s/%s", settings.confdir, settings.news); 150 sprintf (buf, "%s/%s", settings.confdir, settings.news);
151 if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL) 151 if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL)
152 return; 152 return;
153
153 news[0] = '\0'; 154 news[0] = '\0';
154 subject[0] = '\0'; 155 subject[0] = '\0';
155 size = 0; 156 size = 0;
157
156 while (fgets (buf, MAX_BUF, fp) != NULL) 158 while (fgets (buf, MAX_BUF, fp) != NULL)
157 { 159 {
158 if (*buf == '#') 160 if (*buf == '#')
159 continue; 161 continue;
162
160 if (*buf == '%') 163 if (*buf == '%')
161 { /* send one news */ 164 { /* send one news */
162 if (size > 0) 165 if (size > 0)
163 draw_ext_info_format (NDI_UNIQUE | NDI_GREEN, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_NEWS, "INFORMATION: %s\n%s", "%s\n%s", subject, news); /*send previously read news */ 166 draw_ext_info_format (NDI_UNIQUE | NDI_GREEN, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_NEWS, "INFORMATION: %s\n%s", "%s\n%s", subject, news); /*send previously read news */
164 strcpy (subject, buf + 1); 167 strcpy (subject, buf + 1);
191 return 0; 194 return 0;
192 195
193 for (; *cp != '\0'; cp++) 196 for (; *cp != '\0'; cp++)
194 if (!((*cp >= 'a' && *cp <= 'z') || (*cp >= 'A' && *cp <= 'Z')) && *cp != '-' && *cp != '_') 197 if (!((*cp >= 'a' && *cp <= 'z') || (*cp >= 'A' && *cp <= 'Z')) && *cp != '-' && *cp != '_')
195 return 0; 198 return 0;
199
196 return 1; 200 return 1;
197} 201}
198 202
199/* This no longer sets the player map. Also, it now updates 203/* This no longer sets the player map. Also, it now updates
200 * all the pointers so the caller doesn't need to do that. 204 * all the pointers so the caller doesn't need to do that.
208 * the one that is passed. 212 * the one that is passed.
209 */ 213 */
210static player * 214static player *
211get_player (player *p) 215get_player (player *p)
212{ 216{
213 object *op = arch_to_object (get_player_archetype (NULL)); 217 object *op = arch_to_object (get_player_archetype (0));
214 int i; 218 int i;
215
216 if (!p)
217 {
218 p = new player;
219
220 /* This adds the player in the linked list. There is extra
221 * complexity here because we want to add the new player at the
222 * end of the list - there is in fact no compelling reason that
223 * that needs to be done except for things like output of
224 * 'who'.
225 */
226 player *tmp = first_player;
227
228 while (tmp != NULL && tmp->next != NULL)
229 tmp = tmp->next;
230 if (tmp != NULL)
231 tmp->next = p;
232 else
233 first_player = p;
234
235 p->next = NULL;
236 }
237 219
238 /* Clears basically the entire player structure except 220 /* Clears basically the entire player structure except
239 * for next and socket. 221 * for next and socket.
240 */ 222 */
241 p->clear (); 223 p->clear ();
260 op->speed_left = 0.5; 242 op->speed_left = 0.5;
261 op->speed = 1.0; 243 op->speed = 1.0;
262 op->direction = 5; /* So player faces south */ 244 op->direction = 5; /* So player faces south */
263 op->stats.wc = 2; 245 op->stats.wc = 2;
264 op->run_away = 25; /* Then we panick... */ 246 op->run_away = 25; /* Then we panick... */
247
248 {
249 int oldmon = p->ns->monitor_spells; // what a hack
265 p->socket.monitor_spells = 0; /* Needed because esrv_update_spells( ) gets called by roll_stats */ 250 p->ns->monitor_spells = 0; /* Needed because esrv_update_spells( ) gets called by roll_stats */
266
267 roll_stats (op); 251 roll_stats (op);
252 p->ns->monitor_spells = oldmon;
253 }
268 p->state = ST_ROLL_STAT; 254 p->ns->state = ST_ROLL_STAT;
269 clear_los (op); 255 clear_los (op);
270 256
271 p->gen_sp_armour = 10; 257 p->gen_sp_armour = 10;
272 p->last_speed = -1; 258 p->last_speed = -1;
273 p->shoottype = range_none; 259 p->shoottype = range_none;
277 p->usekeys = containers; 263 p->usekeys = containers;
278 p->last_weapon_sp = -1; 264 p->last_weapon_sp = -1;
279 p->peaceful = 1; /* default peaceful */ 265 p->peaceful = 1; /* default peaceful */
280 p->do_los = 1; 266 p->do_los = 1;
281 p->explore = 0; 267 p->explore = 0;
282 p->no_shout = 0; /* default can shout */
283 268
284 assign (p->title, op->arch->clone.name); 269 assign (p->title, op->arch->clone.name);
285 op->race = op->arch->clone.race; 270 op->race = op->arch->clone.race;
286 271
287 CLEAR_FLAG (op, FLAG_READY_SKILL); 272 CLEAR_FLAG (op, FLAG_READY_SKILL);
294 for (i = 0; i < NUM_SKILLS; i++) 279 for (i = 0; i < NUM_SKILLS; i++)
295 { 280 {
296 p->last_skill_exp[i] = -1; 281 p->last_skill_exp[i] = -1;
297 p->last_skill_ob[i] = NULL; 282 p->last_skill_ob[i] = NULL;
298 } 283 }
284
299 for (i = 0; i < NROFATTACKS; i++) 285 for (i = 0; i < NROFATTACKS; i++)
300 {
301 p->last_resist[i] = -1; 286 p->last_resist[i] = -1;
302 } 287
303 p->last_stats.exp = -1; 288 p->last_stats.exp = -1;
304 p->last_weight = (uint32) - 1; 289 p->last_weight = (uint32) - 1;
305 290
306 p->socket.update_look = 0; 291 p->ns->update_look = 0;
307 p->socket.look_position = 0; 292 p->ns->look_position = 0;
293
308 return p; 294 return p;
309} 295}
310 296
311/* This loads the first map an puts the player on it. */ 297/* This loads the first map an puts the player on it. */
312static void 298static void
313set_first_map (object *op) 299set_first_map (object *op)
314{ 300{
315 strcpy (op->contr->maplevel, first_map_path); 301 strcpy (op->contr->maplevel, first_map_path);
316 op->x = -1; 302 op->x = -1;
317 op->y = -1; 303 op->y = -1;
318 enter_exit (op, NULL); 304 enter_exit (op, 0);
319} 305}
320 306
321/* Tries to add player on the connection passwd in ns. 307/* Tries to add player on the connection passwd in ns.
322 * All we can really get in this is some settings like host and display 308 * All we can really get in this is some settings like host and display
323 * mode. 309 * mode.
324 */ 310 */
325 311
326int 312int
327add_player (NewSocket * ns) 313add_player (client *ns)
328{ 314{
329 player *p; 315 player *p = new player;
330 316
317 p->ns = ns;
318 ns->pl = p;
319
320 p->next = first_player;
321 first_player = p;
322
331 p = get_player (NULL); 323 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 324
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); 325 set_first_map (p->ob);
345 326
346 CLEAR_FLAG (p->ob, FLAG_FRIENDLY); 327 CLEAR_FLAG (p->ob, FLAG_FRIENDLY);
347 add_friendly_object (p->ob); 328 add_friendly_object (p->ob);
348 send_rules (p->ob); 329 send_rules (p->ob);
349 send_news (p->ob); 330 send_news (p->ob);
350 display_motd (p->ob); 331 display_motd (p->ob);
332
351 get_name (p->ob); 333 get_name (p->ob);
352 334
353 return 0; 335 return 0;
354} 336}
355 337
367 { 349 {
368 if (at == NULL || at->next == NULL) 350 if (at == NULL || at->next == NULL)
369 at = first_archetype; 351 at = first_archetype;
370 else 352 else
371 at = at->next; 353 at = at->next;
354
372 if (at->clone.type == PLAYER) 355 if (at->clone.type == PLAYER)
373 return at; 356 return at;
357
374 if (at == start) 358 if (at == start)
375 { 359 {
376 LOG (llevError, "No Player archetypes\n"); 360 LOG (llevError, "No Player archetypes\n");
377 exit (-1); 361 exit (-1);
378 } 362 }
379 } 363 }
380} 364}
381
382 365
383object * 366object *
384get_nearest_player (object *mon) 367get_nearest_player (object *mon)
385{ 368{
386 object *op = NULL; 369 object *op = NULL;
646 (op->type == ARMOUR || op->type == BOOTS || 629 (op->type == ARMOUR || op->type == BOOTS ||
647 op->type == CLOAK || op->type == HELMET || 630 op->type == CLOAK || op->type == HELMET ||
648 op->type == SHIELD || op->type == GLOVES || 631 op->type == SHIELD || op->type == GLOVES ||
649 op->type == BRACERS || op->type == GIRDLE)) || (!QUERY_FLAG (pl, FLAG_USE_WEAPON) && op->type == WEAPON)) 632 op->type == BRACERS || op->type == GIRDLE)) || (!QUERY_FLAG (pl, FLAG_USE_WEAPON) && op->type == WEAPON))
650 { 633 {
651 remove_ob (op); 634 op->destroy ();
652 free_object (op);
653 continue; 635 continue;
654 } 636 }
655 } 637 }
656 638
657 /* This really needs to be better - we should really give 639 /* This really needs to be better - we should really give
668 if (tmp->type == op->type && tmp->name == op->name) 650 if (tmp->type == op->type && tmp->name == op->name)
669 break; 651 break;
670 652
671 if (tmp) 653 if (tmp)
672 { 654 {
673 remove_ob (op); 655 op->destroy ();
674 free_object (op);
675 LOG (llevError, "give_initial_items: Removing duplicate object %s\n", &tmp->name); 656 LOG (llevError, "give_initial_items: Removing duplicate object %s\n", &tmp->name);
676 continue; 657 continue;
677 } 658 }
659
678 if (op->nrof > 1) 660 if (op->nrof > 1)
679 op->nrof = 1; 661 op->nrof = 1;
680 } 662 }
681 663
682 if (op->type == SPELLBOOK && op->inv) 664 if (op->type == SPELLBOOK && op->inv)
694 CLEAR_FLAG (op, FLAG_CURSED); 676 CLEAR_FLAG (op, FLAG_CURSED);
695 CLEAR_FLAG (op, FLAG_DAMNED); 677 CLEAR_FLAG (op, FLAG_DAMNED);
696 } 678 }
697 if (op->type == SPELL) 679 if (op->type == SPELL)
698 { 680 {
699 remove_ob (op); 681 op->destroy ();
700 free_object (op);
701 continue; 682 continue;
702 } 683 }
703 else if (op->type == SKILL) 684 else if (op->type == SKILL)
704 { 685 {
705 SET_FLAG (op, FLAG_CAN_USE_SKILL); 686 SET_FLAG (op, FLAG_CAN_USE_SKILL);
717 698
718void 699void
719get_name (object *op) 700get_name (object *op)
720{ 701{
721 op->contr->write_buf[0] = '\0'; 702 op->contr->write_buf[0] = '\0';
722 op->contr->state = ST_GET_NAME; 703 op->contr->ns->state = ST_GET_NAME;
723 send_query (&op->contr->socket, 0, "What is your name?\n:"); 704 send_query (op->contr->ns, 0, "What is your name?\n:");
724} 705}
725 706
726void 707void
727get_password (object *op) 708get_password (object *op)
728{ 709{
729 op->contr->write_buf[0] = '\0'; 710 op->contr->write_buf[0] = '\0';
730 op->contr->state = ST_GET_PASSWORD; 711 op->contr->ns->state = ST_GET_PASSWORD;
731 send_query (&op->contr->socket, CS_QUERY_HIDEINPUT, "What is your password?\n:"); 712 send_query (op->contr->ns, CS_QUERY_HIDEINPUT, "What is your password?\n:");
732} 713}
733 714
734void 715void
735play_again (object *op) 716play_again (object *op)
736{ 717{
737 op->contr->state = ST_PLAY_AGAIN; 718 op->contr->ns->state = ST_PLAY_AGAIN;
738 op->chosen_skill = NULL; 719 op->chosen_skill = NULL;
739 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "Do you want to play again (a/q)?"); 720 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 721 /* a bit of a hack, but there are various places early in th
741 * player creation process that a user can quit (eg, roll 722 * player creation process that a user can quit (eg, roll
742 * stats) that isn't removing the player. Taking a quick 723 * stats) that isn't removing the player. Taking a quick
743 * look, there are many places that call play_again without 724 * look, there are many places that call play_again without
744 * removing the player - it probably makes more sense 725 * removing the player - it probably makes more sense
745 * to leave it to play_again to remove the object in all 726 * to leave it to play_again to remove the object in all
746 * cases. 727 * cases.
747 */ 728 */
748 if (!QUERY_FLAG (op, FLAG_REMOVED)) 729 if (!QUERY_FLAG (op, FLAG_REMOVED))
749 remove_ob (op); 730 op->remove ();
731
750 /* Need to set this to null - otherwise, it could point to garbage, 732 /* 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 733 * and draw() doesn't check to see if the player is removed, only if
752 * the map is null or not swapped out. 734 * the map is null or not swapped out.
753 */ 735 */
754 op->map = NULL; 736 op->map = NULL;
792void 774void
793confirm_password (object *op) 775confirm_password (object *op)
794{ 776{
795 777
796 op->contr->write_buf[0] = '\0'; 778 op->contr->write_buf[0] = '\0';
797 op->contr->state = ST_CONFIRM_PASSWORD; 779 op->contr->ns->state = ST_CONFIRM_PASSWORD;
798 send_query (&op->contr->socket, CS_QUERY_HIDEINPUT, "Please type your password again.\n:"); 780 send_query (op->contr->ns, CS_QUERY_HIDEINPUT, "Please type your password again.\n:");
799} 781}
800 782
801void 783void
802get_party_password (object *op, partylist *party) 784get_party_password (object *op, partylist *party)
803{ 785{
805 { 787 {
806 LOG (llevError, "get_party_password(): tried to make player %s join a NULL party", &op->name); 788 LOG (llevError, "get_party_password(): tried to make player %s join a NULL party", &op->name);
807 return; 789 return;
808 } 790 }
809 op->contr->write_buf[0] = '\0'; 791 op->contr->write_buf[0] = '\0';
810 op->contr->state = ST_GET_PARTY_PASSWORD; 792 op->contr->ns->state = ST_GET_PARTY_PASSWORD;
811 op->contr->party_to_join = party; 793 op->contr->party_to_join = party;
812 send_query (&op->contr->socket, CS_QUERY_HIDEINPUT, "What is the password?\n:"); 794 send_query (op->contr->ns, CS_QUERY_HIDEINPUT, "What is the password?\n:");
813} 795}
814 796
815 797
816/* This rolls four 1-6 rolls and sums the best 3 of the 4. */ 798/* This rolls four 1-6 rolls and sums the best 3 of the 4. */
817int 799int
914 896
915void 897void
916Roll_Again (object *op) 898Roll_Again (object *op)
917{ 899{
918 esrv_new_player (op->contr, 0); 900 esrv_new_player (op->contr, 0);
919 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, 901 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)? "); 902 "[y] to roll new stats [n] to use stats\n[1-7] [1-7] to swap stats.\nRoll again (y/n/1-7)? ");
921} 903}
922 904
923void 905void
924Swap_Stat (object *op, int Swap_Second) 906Swap_Stat (object *op, int Swap_Second)
991 new_draw_info (NDI_UNIQUE, 0, op, buf); 973 new_draw_info (NDI_UNIQUE, 0, op, buf);
992 } 974 }
993 else 975 else
994 Swap_Stat (op, stat_trans[keynum]); 976 Swap_Stat (op, stat_trans[keynum]);
995 977
996 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, ""); 978 send_query (op->contr->ns, CS_QUERY_SINGLECHAR, "");
997 return 1; 979 return 1;
998 } 980 }
999 switch (key) 981 switch (key)
1000 { 982 {
1001 case 'n': 983 case 'n':
1015 enter_exit (op, NULL); 997 enter_exit (op, NULL);
1016#endif 998#endif
1017 SET_ANIMATION (op, 2); /* So player faces south */ 999 SET_ANIMATION (op, 2); /* So player faces south */
1018 /* Enter exit adds a player otherwise */ 1000 /* Enter exit adds a player otherwise */
1019 add_statbonus (op); 1001 add_statbonus (op);
1020 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, 1002 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"); 1003 "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n");
1022 op->contr->state = ST_CHANGE_CLASS; 1004 op->contr->ns->state = ST_CHANGE_CLASS;
1023 if (op->msg) 1005 if (op->msg)
1024 new_draw_info (NDI_BLUE, 0, op, op->msg); 1006 new_draw_info (NDI_BLUE, 0, op, op->msg);
1025 return 0; 1007 return 0;
1026 } 1008 }
1027 case 'y': 1009 case 'y':
1028 case 'Y': 1010 case 'Y':
1029 roll_stats (op); 1011 roll_stats (op);
1030 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, ""); 1012 send_query (op->contr->ns, CS_QUERY_SINGLECHAR, "");
1031 return 1; 1013 return 1;
1032 1014
1033 case 'q': 1015 case 'q':
1034 case 'Q': 1016 case 'Q':
1035 play_again (op); 1017 play_again (op);
1036 return 1; 1018 return 1;
1037 1019
1038 default: 1020 default:
1039 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "Yes, No, Quit or 1-6. Roll again?"); 1021 send_query (op->contr->ns, CS_QUERY_SINGLECHAR, "Yes, No, Quit or 1-6. Roll again?");
1040 return 0; 1022 return 0;
1041 } 1023 }
1042 return 0; 1024 return 0;
1043} 1025}
1044 1026
1054{ 1036{
1055 int tmp_loop; 1037 int tmp_loop;
1056 1038
1057 if (key == 'q' || key == 'Q') 1039 if (key == 'q' || key == 'Q')
1058 { 1040 {
1059 remove_ob (op); 1041 op->remove ();
1060 play_again (op); 1042 play_again (op);
1061 return 0; 1043 return 0;
1062 } 1044 }
1063 if (key == 'd' || key == 'D') 1045 if (key == 'd' || key == 'D')
1064 { 1046 {
1065 char buf[MAX_BUF]; 1047 char buf[MAX_BUF];
1066 1048
1067 /* this must before then initial items are given */ 1049 /* this must before then initial items are given */
1068 esrv_new_player (op->contr, op->weight + op->carrying); 1050 esrv_new_player (op->contr, op->weight + op->carrying);
1051
1069 create_treasure (find_treasurelist ("starting_wealth"), op, 0, 0, 0); 1052 treasurelist *tl = find_treasurelist ("starting_wealth");
1053 if (tl)
1054 create_treasure (tl, op, 0, 0, 0);
1070 1055
1071 INVOKE_PLAYER (BIRTH, op->contr); 1056 INVOKE_PLAYER (BIRTH, op->contr);
1072 INVOKE_PLAYER (LOGIN, op->contr); 1057 INVOKE_PLAYER (LOGIN, op->contr);
1073 1058
1074 op->contr->state = ST_PLAYING; 1059 op->contr->ns->state = ST_PLAYING;
1075 1060
1076 if (op->msg) 1061 if (op->msg)
1077 op->msg = NULL; 1062 op->msg = NULL;
1078 1063
1079 /* We create this now because some of the unique maps will need it 1064 /* We create this now because some of the unique maps will need it
1099 { 1084 {
1100 object *tmp; 1085 object *tmp;
1101 char mapname[MAX_BUF]; 1086 char mapname[MAX_BUF];
1102 1087
1103 snprintf (mapname, MAX_BUF - 1, "%s/%s", first_map_ext_path, &op->arch->name); 1088 snprintf (mapname, MAX_BUF - 1, "%s/%s", first_map_ext_path, &op->arch->name);
1104 tmp = get_object (); 1089 tmp = object::create ();
1105 EXIT_PATH (tmp) = mapname; 1090 EXIT_PATH (tmp) = mapname;
1106 EXIT_X (tmp) = op->x; 1091 EXIT_X (tmp) = op->x;
1107 EXIT_Y (tmp) = op->y; 1092 EXIT_Y (tmp) = op->y;
1108 enter_exit (op, tmp); /* we don't really care if it succeeded; 1093 enter_exit (op, tmp); /* we don't really care if it succeeded;
1109 * if the map isn't there, then stay on the 1094 * if the map isn't there, then stay on the
1110 * default initial map */ 1095 * default initial map */
1111 free_object (tmp); 1096 tmp->destroy ();
1112 } 1097 }
1113 else 1098 else
1114 {
1115 LOG (llevDebug, "first_map_ext_path not set\n"); 1099 LOG (llevDebug, "first_map_ext_path not set\n");
1116 } 1100
1117 return 0; 1101 return 0;
1118 } 1102 }
1119 1103
1120 /* Following actually changes the race - this is the default command 1104 /* Following actually changes the race - this is the default command
1121 * if we don't match with one of the options above. 1105 * if we don't match with one of the options above.
1126 { 1110 {
1127 shstr name = op->name; 1111 shstr name = op->name;
1128 int x = op->x, y = op->y; 1112 int x = op->x, y = op->y;
1129 1113
1130 remove_statbonus (op); 1114 remove_statbonus (op);
1131 remove_ob (op); 1115 op->remove ();
1132 op->arch = get_player_archetype (op->arch); 1116 op->arch = get_player_archetype (op->arch);
1133 copy_object (&op->arch->clone, op); 1117 op->arch->clone.copy_to (op);
1134 op->instantiate (); 1118 op->instantiate ();
1135 op->stats = op->contr->orig_stats; 1119 op->stats = op->contr->orig_stats;
1136 op->name = op->name_pl = name; 1120 op->name = op->name_pl = name;
1137 op->x = x; 1121 op->x = x;
1138 op->y = y; 1122 op->y = y;
1151 op->stats.grace = 0; 1135 op->stats.grace = 0;
1152 1136
1153 if (op->msg) 1137 if (op->msg)
1154 new_draw_info (NDI_BLUE, 0, op, op->msg); 1138 new_draw_info (NDI_BLUE, 0, op, op->msg);
1155 1139
1156 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "Press any key for the next race.\nPress `d' to play this race.\n"); 1140 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; 1141 return 0;
1158} 1142}
1159 1143
1160int 1144int
1161key_confirm_quit (object *op, char key) 1145key_confirm_quit (object *op, char key)
1162{ 1146{
1163 char buf[MAX_BUF]; 1147 char buf[MAX_BUF];
1164 1148
1165 if (key != 'y' && key != 'Y' && key != 'q' && key != 'Q') 1149 if (key != 'y' && key != 'Y' && key != 'q' && key != 'Q')
1166 { 1150 {
1167 op->contr->state = ST_PLAYING; 1151 op->contr->ns->state = ST_PLAYING;
1168 new_draw_info (NDI_UNIQUE, 0, op, "OK, continuing to play."); 1152 new_draw_info (NDI_UNIQUE, 0, op, "OK, continuing to play.");
1169 return 1; 1153 return 1;
1170 } 1154 }
1171 1155
1172 INVOKE_PLAYER (LOGOUT, op->contr); 1156 INVOKE_PLAYER (LOGOUT, op->contr);
1241 { 1225 {
1242 op->enemy = NULL; 1226 op->enemy = NULL;
1243 CLEAR_FLAG (op, FLAG_SCARED); 1227 CLEAR_FLAG (op, FLAG_SCARED);
1244 return; 1228 return;
1245 } 1229 }
1230
1246 get_rangevector (op, op->enemy, &rv, 0); 1231 get_rangevector (op, op->enemy, &rv, 0);
1247 1232
1248 dir = absdir (4 + rv.direction); 1233 dir = absdir (4 + rv.direction);
1249 for (diff = 0; diff < 3; diff++) 1234 for (diff = 0; diff < 3; diff++)
1250 { 1235 {
1251 int m = 1 - (RANDOM () & 2); 1236 int m = 1 - (RANDOM () & 2);
1252 1237
1253 if (move_ob (op, absdir (dir + diff * m), op) || (diff == 0 && move_ob (op, absdir (dir - diff * m), op))) 1238 if (move_ob (op, absdir (dir + diff * m), op) || (diff == 0 && move_ob (op, absdir (dir - diff * m), op)))
1254 {
1255 return; 1239 return;
1256 }
1257 } 1240 }
1241
1258 /* Cornered, get rid of scared */ 1242 /* Cornered, get rid of scared */
1259 CLEAR_FLAG (op, FLAG_SCARED); 1243 CLEAR_FLAG (op, FLAG_SCARED);
1260 op->enemy = NULL; 1244 op->enemy = NULL;
1261} 1245}
1262 1246
1818 if (!dir) 1802 if (!dir)
1819 { 1803 {
1820 new_draw_info (NDI_UNIQUE, 0, op, "You can't shoot yourself!"); 1804 new_draw_info (NDI_UNIQUE, 0, op, "You can't shoot yourself!");
1821 return 0; 1805 return 0;
1822 } 1806 }
1807
1823 if (op->type == PLAYER) 1808 if (op->type == PLAYER)
1824 bow = op->contr->ranges[range_bow]; 1809 bow = op->contr->ranges[range_bow];
1825 else 1810 else
1826 { 1811 {
1827 for (bow = op->inv; bow; bow = bow->below) 1812 for (bow = op->inv; bow; bow = bow->below)
1835 { 1820 {
1836 LOG (llevError, "Range: bow without activated bow (%s).\n", &op->name); 1821 LOG (llevError, "Range: bow without activated bow (%s).\n", &op->name);
1837 return 0; 1822 return 0;
1838 } 1823 }
1839 } 1824 }
1825
1840 if (!bow->race || !bow->skill) 1826 if (!bow->race || !bow->skill)
1841 { 1827 {
1842 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s is broken.", &bow->name); 1828 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s is broken.", &bow->name);
1843 return 0; 1829 return 0;
1844 } 1830 }
1846 bowspeed = bow->stats.sp + dex_bonus[op->stats.Dex]; 1832 bowspeed = bow->stats.sp + dex_bonus[op->stats.Dex];
1847 1833
1848 /* penalize ROF for bestarrow */ 1834 /* penalize ROF for bestarrow */
1849 if (op->type == PLAYER && op->contr->bowtype == bow_bestarrow) 1835 if (op->type == PLAYER && op->contr->bowtype == bow_bestarrow)
1850 bowspeed -= dex_bonus[op->stats.Dex] + 5; 1836 bowspeed -= dex_bonus[op->stats.Dex] + 5;
1837
1851 if (bowspeed < 1) 1838 if (bowspeed < 1)
1852 bowspeed = 1; 1839 bowspeed = 1;
1853 1840
1854 if (arrow == NULL) 1841 if (arrow == NULL)
1855 { 1842 {
1861 else 1848 else
1862 CLEAR_FLAG (op, FLAG_READY_BOW); 1849 CLEAR_FLAG (op, FLAG_READY_BOW);
1863 return 0; 1850 return 0;
1864 } 1851 }
1865 } 1852 }
1853
1866 mflags = get_map_flags (op->map, &m, sx, sy, &sx, &sy); 1854 mflags = get_map_flags (op->map, &m, sx, sy, &sx, &sy);
1867 if (mflags & P_OUT_OF_MAP) 1855 if (mflags & P_OUT_OF_MAP)
1868 {
1869 return 0; 1856 return 0;
1870 } 1857
1871 if (GET_MAP_MOVE_BLOCK (m, sx, sy) == MOVE_FLY_LOW) 1858 if (GET_MAP_MOVE_BLOCK (m, sx, sy) == MOVE_FLY_LOW)
1872 { 1859 {
1873 new_draw_info (NDI_UNIQUE, 0, op, "Something is in the way."); 1860 new_draw_info (NDI_UNIQUE, 0, op, "Something is in the way.");
1874 return 0; 1861 return 0;
1875 } 1862 }
1876 1863
1877 /* this should not happen, but sometimes does */ 1864 /* this should not happen, but sometimes does */
1878 if (arrow->nrof == 0) 1865 if (arrow->nrof == 0)
1879 { 1866 {
1880 remove_ob (arrow); 1867 arrow->destroy ();
1881 free_object (arrow);
1882 return 0; 1868 return 0;
1883 } 1869 }
1884 1870
1885 left = arrow; /* these are arrows left to the player */ 1871 left = arrow; /* these are arrows left to the player */
1886 arrow = get_split_ob (arrow, 1); 1872 arrow = get_split_ob (arrow, 1);
1887 if (arrow == NULL) 1873 if (!arrow)
1888 { 1874 {
1889 new_draw_info_format (NDI_UNIQUE, 0, op, "You have no %s left.", &bow->race); 1875 new_draw_info_format (NDI_UNIQUE, 0, op, "You have no %s left.", &bow->race);
1890 return 0; 1876 return 0;
1891 } 1877 }
1892 set_owner (arrow, op); 1878
1879 arrow->set_owner (op);
1893 arrow->skill = bow->skill; 1880 arrow->skill = bow->skill;
1894 1881
1895 arrow->direction = dir; 1882 arrow->direction = dir;
1896 arrow->x = sx; 1883 arrow->x = sx;
1897 arrow->y = sy; 1884 arrow->y = sy;
1905 SET_ANIMATION (arrow, arrow->direction); 1892 SET_ANIMATION (arrow, arrow->direction);
1906 arrow->stats.sp = arrow->stats.wc; /* save original wc and dam */ 1893 arrow->stats.sp = arrow->stats.wc; /* save original wc and dam */
1907 arrow->stats.hp = arrow->stats.dam; 1894 arrow->stats.hp = arrow->stats.dam;
1908 arrow->stats.grace = arrow->attacktype; 1895 arrow->stats.grace = arrow->attacktype;
1909 if (arrow->slaying != NULL) 1896 if (arrow->slaying != NULL)
1910 arrow->spellarg = strdup_local (arrow->slaying); 1897 arrow->spellarg = strdup (arrow->slaying);
1911 1898
1912 /* Note that this was different for monsters - they got their level 1899 /* Note that this was different for monsters - they got their level
1913 * added to the damage. I think the strength bonus is more proper. 1900 * added to the damage. I think the strength bonus is more proper.
1914 */ 1901 */
1915 1902
1939 } 1926 }
1940 1927
1941 if (arrow->attacktype == AT_PHYSICAL) 1928 if (arrow->attacktype == AT_PHYSICAL)
1942 arrow->attacktype |= bow->attacktype; 1929 arrow->attacktype |= bow->attacktype;
1943 1930
1944 if (bow->slaying != NULL) 1931 if (bow->slaying)
1945 arrow->slaying = bow->slaying; 1932 arrow->slaying = bow->slaying;
1946 1933
1947 arrow->map = m; 1934 arrow->map = m;
1948 arrow->move_type = MOVE_FLY_LOW; 1935 arrow->move_type = MOVE_FLY_LOW;
1949 arrow->move_on = MOVE_FLY_LOW | MOVE_WALK; 1936 arrow->move_on = MOVE_FLY_LOW | MOVE_WALK;
2065 CLEAR_FLAG (item, FLAG_ANIMATE); 2052 CLEAR_FLAG (item, FLAG_ANIMATE);
2066 item->face = item->arch->clone.face; 2053 item->face = item->arch->clone.face;
2067 item->speed = 0; 2054 item->speed = 0;
2068 update_ob_speed (item); 2055 update_ob_speed (item);
2069 } 2056 }
2070 if ((tmp = is_player_inv (item))) 2057 if ((tmp = item->in_player ()))
2071 esrv_update_item (UPD_ANIM, tmp, item); 2058 esrv_update_item (UPD_ANIM, tmp, item);
2072 } 2059 }
2073 } 2060 }
2074 else if (item->type == ROD || item->type == HORN) 2061 else if (item->type == ROD || item->type == HORN)
2075 { 2062 {
2225 * 0 otherwise 2212 * 0 otherwise
2226 */ 2213 */
2227static int 2214static int
2228player_attack_door (object *op, object *door) 2215player_attack_door (object *op, object *door)
2229{ 2216{
2230
2231 /* If its a door, try to find a use a key. If we do destroy the door, 2217 /* If its a door, try to find a use a key. If we do destroy the door,
2232 * might as well return immediately as there is nothing more to do - 2218 * might as well return immediately as there is nothing more to do -
2233 * otherwise, we fall through to the rest of the code. 2219 * otherwise, we fall through to the rest of the code.
2234 */ 2220 */
2235 object *key = find_key (op, op, door); 2221 object *key = find_key (op, op, door);
2273 * It should keep the code cleaner. 2259 * It should keep the code cleaner.
2274 * When this is called, the players direction has been updated 2260 * When this is called, the players direction has been updated
2275 * (taking into account confusion.) The player is also actually 2261 * (taking into account confusion.) The player is also actually
2276 * going to try and move (not fire weapons). 2262 * going to try and move (not fire weapons).
2277 */ 2263 */
2278
2279void 2264void
2280move_player_attack (object *op, int dir) 2265move_player_attack (object *op, int dir)
2281{ 2266{
2282 object *tmp, *mon; 2267 object *tmp, *mon;
2283 sint16 nx, ny; 2268 sint16 nx, ny;
2285 maptile *m; 2270 maptile *m;
2286 2271
2287 nx = freearr_x[dir] + op->x; 2272 nx = freearr_x[dir] + op->x;
2288 ny = freearr_y[dir] + op->y; 2273 ny = freearr_y[dir] + op->y;
2289 2274
2290 on_battleground = op_on_battleground (op, NULL, NULL); 2275 on_battleground = op_on_battleground (op, 0, 0);
2291 2276
2292 /* If braced, or can't move to the square, and it is not out of the 2277 /* If braced, or can't move to the square, and it is not out of the
2293 * map, attack it. Note order of if statement is important - don't 2278 * map, attack it. Note order of if statement is important - don't
2294 * want to be calling move_ob if braced, because move_ob will move the 2279 * want to be calling move_ob if braced, because move_ob will move the
2295 * player. This is a pretty nasty hack, because if we could 2280 * player. This is a pretty nasty hack, because if we could
2307 return; /* Don't think this should happen */ 2292 return; /* Don't think this should happen */
2308 } 2293 }
2309 else 2294 else
2310 m = op->map; 2295 m = op->map;
2311 2296
2312 if ((tmp = get_map_ob (m, nx, ny)) == NULL) 2297 if ((tmp = GET_MAP_OB (m, nx, ny)) == NULL)
2313 { 2298 {
2314 /* LOG(llevError,"player_move_attack: get_map_ob returns NULL, but player can not more there.\n"); */ 2299 /* LOG(llevError,"player_move_attack: GET_MAP_OB returns NULL, but player can not move there.\n"); */
2315 return; 2300 return;
2316 } 2301 }
2317 2302
2318 mon = NULL; 2303 mon = 0;
2319 /* Go through all the objects, and find ones of interest. Only stop if 2304 /* Go through all the objects, and find ones of interest. Only stop if
2320 * we find a monster - that is something we know we want to attack. 2305 * we find a monster - that is something we know we want to attack.
2321 * if its a door or barrel (can roll) see if there may be monsters 2306 * if its a door or barrel (can roll) see if there may be monsters
2322 * on the space 2307 * on the space
2323 */ 2308 */
2324 while (tmp != NULL) 2309 while (tmp)
2325 { 2310 {
2326 if (tmp == op) 2311 if (tmp == op)
2327 { 2312 {
2328 tmp = tmp->above; 2313 tmp = tmp->above;
2329 continue; 2314 continue;
2339 mon = tmp; 2324 mon = tmp;
2340 2325
2341 tmp = tmp->above; 2326 tmp = tmp->above;
2342 } 2327 }
2343 2328
2344 if (mon == NULL) /* This happens anytime the player tries to move */ 2329 if (!mon) /* This happens anytime the player tries to move */
2345 return; /* into a wall */ 2330 return; /* into a wall */
2346 2331
2347 if (mon->head != NULL) 2332 if (mon->head)
2348 mon = mon->head; 2333 mon = mon->head;
2349 2334
2350 if ((mon->type == DOOR && mon->stats.hp >= 0) || (mon->type == LOCKED_DOOR)) 2335 if ((mon->type == DOOR && mon->stats.hp >= 0) || (mon->type == LOCKED_DOOR))
2351 if (player_attack_door (op, mon)) 2336 if (player_attack_door (op, mon))
2352 return; 2337 return;
2364 * player owns it and it is either friendly or unagressive. 2349 * player owns it and it is either friendly or unagressive.
2365 */ 2350 */
2366 if ((op->type == PLAYER) 2351 if ((op->type == PLAYER)
2367#if COZY_SERVER 2352#if COZY_SERVER
2368 && 2353 &&
2369 ((get_owner (mon) && get_owner (mon)->contr 2354 ((mon->owner && mon->owner->contr
2370 && 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)
2371#else 2356#else
2372 && get_owner (mon) == op 2357 && mon->owner == op
2373#endif 2358#endif
2374 && (QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY))) 2359 && (QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY)))
2375 { 2360 {
2376 /* 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 */
2377 if (op->contr->braced) 2362 if (op->contr->braced)
2389 * attack them either. 2374 * attack them either.
2390 */ 2375 */
2391 if ((mon->type == PLAYER || mon->enemy != op) && 2376 if ((mon->type == PLAYER || mon->enemy != op) &&
2392 (mon->type == PLAYER || QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY)) && ( 2377 (mon->type == PLAYER || QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY)) && (
2393#ifdef PROHIBIT_PLAYERKILL 2378#ifdef PROHIBIT_PLAYERKILL
2394 (op->contr->peaceful 2379 (op->contr->peaceful
2395 || (mon->type == PLAYER 2380 || (mon->type == PLAYER
2396 && mon->contr-> 2381 && mon->contr->
2397 peaceful)) && 2382 peaceful)) &&
2398#else 2383#else
2399 op->contr->peaceful && 2384 op->contr->peaceful &&
2400#endif 2385#endif
2401 !on_battleground)) 2386 !on_battleground))
2402 { 2387 {
2403 if (!op->contr->braced) 2388 if (!op->contr->braced)
2404 { 2389 {
2405 play_sound_map (op->map, op->x, op->y, SOUND_PUSH_PLAYER); 2390 play_sound_map (op->map, op->x, op->y, SOUND_PUSH_PLAYER);
2406 (void) push_ob (mon, dir, op); 2391 (void) push_ob (mon, dir, op);
2407 } 2392 }
2408 else 2393 else
2409 {
2410 new_draw_info (0, 0, op, "You withhold your attack"); 2394 new_draw_info (0, 0, op, "You withhold your attack");
2411 } 2395
2412 if (op->contr->tmp_invis || op->hide) 2396 if (op->contr->tmp_invis || op->hide)
2413 make_visible (op); 2397 make_visible (op);
2414 } 2398 }
2415 2399
2416 /* If the object is a boulder or other rollable object, then 2400 /* If the object is a boulder or other rollable object, then
2444 op->speed_left += op->speed / op->contr->weapon_sp; 2428 op->speed_left += op->speed / op->contr->weapon_sp;
2445 2429
2446 op->contr->has_hit = 1; /* The last action was to hit, so use weapon_sp */ 2430 op->contr->has_hit = 1; /* The last action was to hit, so use weapon_sp */
2447 } 2431 }
2448 2432
2449 skill_attack (mon, op, 0, NULL, NULL); 2433 skill_attack (mon, op, 0, 0, 0);
2450 2434
2451 /* If attacking another player, that player gets automatic 2435 /* If attacking another player, that player gets automatic
2452 * hitback, and doesn't loose luck either. 2436 * hitback, and doesn't loose luck either.
2453 * Disable hitback on the battleground or if the target is 2437 * Disable hitback on the battleground or if the target is
2454 * the wiz. 2438 * the wiz.
2456 if (mon->type == PLAYER && mon->stats.hp >= 0 && !mon->contr->has_hit && !on_battleground && !QUERY_FLAG (mon, FLAG_WIZ)) 2440 if (mon->type == PLAYER && mon->stats.hp >= 0 && !mon->contr->has_hit && !on_battleground && !QUERY_FLAG (mon, FLAG_WIZ))
2457 { 2441 {
2458 short luck = mon->stats.luck; 2442 short luck = mon->stats.luck;
2459 2443
2460 mon->contr->has_hit = 1; 2444 mon->contr->has_hit = 1;
2461 skill_attack (op, mon, 0, NULL, NULL); 2445 skill_attack (op, mon, 0, 0, 0);
2462 mon->stats.luck = luck; 2446 mon->stats.luck = luck;
2463 } 2447 }
2448
2464 if (action_makes_visible (op)) 2449 if (action_makes_visible (op))
2465 make_visible (op); 2450 make_visible (op);
2466 } 2451 }
2467 } /* if player should attack something */ 2452 } /* if player should attack something */
2468} 2453}
2503 2488
2504 /* Add special check for newcs players and fire on - this way, the 2489 /* Add special check for newcs players and fire on - this way, the
2505 * server can handle repeat firing. 2490 * server can handle repeat firing.
2506 */ 2491 */
2507 if (op->contr->fire_on || (op->contr->run_on && pick != 0)) 2492 if (op->contr->fire_on || (op->contr->run_on && pick != 0))
2508 {
2509 op->direction = dir; 2493 op->direction = dir;
2510 }
2511 else 2494 else
2512 {
2513 op->direction = 0; 2495 op->direction = 0;
2514 } 2496
2515 /* Update how the player looks. Use the facing, so direction may 2497 /* Update how the player looks. Use the facing, so direction may
2516 * get reset to zero. This allows for full animation capabilities 2498 * get reset to zero. This allows for full animation capabilities
2517 * for players. 2499 * for players.
2518 */ 2500 */
2519 animate_object (op, op->facing); 2501 animate_object (op, op->facing);
2571 2553
2572 /* call this here - we also will call this in do_ericserver, but 2554 /* call this here - we also will call this in do_ericserver, but
2573 * the players time has been increased when doericserver has been 2555 * the players time has been increased when doericserver has been
2574 * called, so we recheck it here. 2556 * called, so we recheck it here.
2575 */ 2557 */
2576 HandleClient (&op->contr->socket, op->contr); 2558 //TODO: better than handling 8 commands, use some more intelligent rate-limiting
2559 for (int rep = 8; --rep && op->contr->ns->handle_command (); )
2560 ;
2561
2577 if (op->speed_left < 0) 2562 if (op->speed_left < 0)
2578 return 0; 2563 return 0;
2579 2564
2580 if (op->direction && (op->contr->run_on || op->contr->fire_on)) 2565 if (op->direction && (op->contr->run_on || op->contr->fire_on))
2581 { 2566 {
2590 if (op->speed_left > 0) 2575 if (op->speed_left > 0)
2591 return 1; 2576 return 1;
2592 else 2577 else
2593 return 0; 2578 return 0;
2594 } 2579 }
2580
2595 return 0; 2581 return 0;
2596} 2582}
2597 2583
2598int 2584int
2599save_life (object *op) 2585save_life (object *op)
2600{ 2586{
2601 object *tmp;
2602
2603 if (!QUERY_FLAG (op, FLAG_LIFESAVE)) 2587 if (!QUERY_FLAG (op, FLAG_LIFESAVE))
2604 return 0; 2588 return 0;
2605 2589
2606 for (tmp = op->inv; tmp != NULL; tmp = tmp->below) 2590 for (object *tmp = op->inv; tmp; tmp = tmp->below)
2607 if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE)) 2591 if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE))
2608 { 2592 {
2609 play_sound_map (op->map, op->x, op->y, SOUND_OB_EVAPORATE); 2593 play_sound_map (op->map, op->x, op->y, SOUND_OB_EVAPORATE);
2610 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s vibrates violently, then evaporates.", query_name (tmp)); 2594 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s vibrates violently, then evaporates.", query_name (tmp));
2595
2611 if (op->contr) 2596 if (op->contr)
2612 esrv_del_item (op->contr, tmp->count); 2597 esrv_del_item (op->contr, tmp->count);
2613 remove_ob (tmp); 2598
2614 free_object (tmp); 2599 tmp->destroy ();
2615 CLEAR_FLAG (op, FLAG_LIFESAVE); 2600 CLEAR_FLAG (op, FLAG_LIFESAVE);
2601
2616 if (op->stats.hp < 0) 2602 if (op->stats.hp < 0)
2617 op->stats.hp = op->stats.maxhp; 2603 op->stats.hp = op->stats.maxhp;
2604
2618 if (op->stats.food < 0) 2605 if (op->stats.food < 0)
2619 op->stats.food = 999; 2606 op->stats.food = 999;
2607
2620 fix_player (op); 2608 fix_player (op);
2621 return 1; 2609 return 1;
2622 } 2610 }
2611
2623 LOG (llevError, "Error: LIFESAVE set without applied object.\n"); 2612 LOG (llevError, "Error: LIFESAVE set without applied object.\n");
2624 CLEAR_FLAG (op, FLAG_LIFESAVE); 2613 CLEAR_FLAG (op, FLAG_LIFESAVE);
2625 enter_player_savebed (op); /* bring him home. */ 2614 enter_player_savebed (op); /* bring him home. */
2626 return 0; 2615 return 0;
2627} 2616}
2641 next = op->below; /* Make sure we have a good value, in case 2630 next = op->below; /* Make sure we have a good value, in case
2642 * we remove object 'op' 2631 * we remove object 'op'
2643 */ 2632 */
2644 if (QUERY_FLAG (op, FLAG_UNPAID)) 2633 if (QUERY_FLAG (op, FLAG_UNPAID))
2645 { 2634 {
2646 remove_ob (op); 2635 op->remove ();
2647 op->x = env->x; 2636 op->x = env->x;
2648 op->y = env->y; 2637 op->y = env->y;
2649 if (env->type == PLAYER) 2638 if (env->type == PLAYER)
2650 esrv_del_item (env->contr, op->count); 2639 esrv_del_item (env->contr, op->count);
2651 insert_ob_in_map (op, env->map, NULL, 0); 2640 insert_ob_in_map (op, env->map, NULL, 0);
2652 } 2641 }
2653 else if (op->inv) 2642 else if (op->inv)
2654 remove_unpaid_objects (op->inv, env); 2643 remove_unpaid_objects (op->inv, env);
2644
2655 op = next; 2645 op = next;
2656 } 2646 }
2657} 2647}
2658 2648
2659 2649
2674 strcpy (buf2, " R.I.P.\n\n"); 2664 strcpy (buf2, " R.I.P.\n\n");
2675 if (op->type == PLAYER) 2665 if (op->type == PLAYER)
2676 sprintf (buf, "%s the %s\n", &op->name, op->contr->title); 2666 sprintf (buf, "%s the %s\n", &op->name, op->contr->title);
2677 else 2667 else
2678 sprintf (buf, "%s\n", &op->name); 2668 sprintf (buf, "%s\n", &op->name);
2669
2679 strncat (buf2, " ", 20 - strlen (buf) / 2); 2670 strncat (buf2, " ", 20 - strlen (buf) / 2);
2680 strcat (buf2, buf); 2671 strcat (buf2, buf);
2681 if (op->type == PLAYER) 2672 if (op->type == PLAYER)
2682 sprintf (buf, "who was in level %d when killed\n", op->level); 2673 sprintf (buf, "who was in level %d when killed\n", op->level);
2683 else 2674 else
2684 sprintf (buf, "who was in level %d when died.\n\n", op->level); 2675 sprintf (buf, "who was in level %d when died.\n\n", op->level);
2676
2685 strncat (buf2, " ", 20 - strlen (buf) / 2); 2677 strncat (buf2, " ", 20 - strlen (buf) / 2);
2686 strcat (buf2, buf); 2678 strcat (buf2, buf);
2687 if (op->type == PLAYER) 2679 if (op->type == PLAYER)
2688 { 2680 {
2689 sprintf (buf, "by %s.\n\n", op->contr->killer); 2681 sprintf (buf, "by %s.\n\n", op->contr->killer);
2690 strncat (buf2, " ", 21 - strlen (buf) / 2); 2682 strncat (buf2, " ", 21 - strlen (buf) / 2);
2691 strcat (buf2, buf); 2683 strcat (buf2, buf);
2692 } 2684 }
2685
2693 strftime (buf, MAX_BUF, "%b %d %Y\n", localtime (&now)); 2686 strftime (buf, MAX_BUF, "%b %d %Y\n", localtime (&now));
2694 strncat (buf2, " ", 20 - strlen (buf) / 2); 2687 strncat (buf2, " ", 20 - strlen (buf) / 2);
2695 strcat (buf2, buf); 2688 strcat (buf2, buf);
2689
2696 return buf2; 2690 return buf2;
2697} 2691}
2698 2692
2699 2693
2700 2694
2717 for (i = 0; i < NUM_OUTPUT_BUFS; i++) 2711 for (i = 0; i < NUM_OUTPUT_BUFS; i++)
2718 if (op->contr->outputs[i].buf != NULL && (op->contr->outputs[i].first_update + op->contr->outputs_sync) < (uint16) pticks) 2712 if (op->contr->outputs[i].buf != NULL && (op->contr->outputs[i].first_update + op->contr->outputs_sync) < (uint16) pticks)
2719 flush_output_element (op, &op->contr->outputs[i]); 2713 flush_output_element (op, &op->contr->outputs[i]);
2720 } 2714 }
2721 2715
2722 if (op->contr->state == ST_PLAYING) 2716 if (op->contr->ns->state == ST_PLAYING)
2723 { 2717 {
2724 2718
2725 /* these next three if clauses make it possible to SLOW DOWN 2719 /* these next three if clauses make it possible to SLOW DOWN
2726 hp/grace/spellpoint regeneration. */ 2720 hp/grace/spellpoint regeneration. */
2727 if (op->contr->gen_hp >= 0) 2721 if (op->contr->gen_hp >= 0)
2869 if (!QUERY_FLAG (op, FLAG_WIZ)) 2863 if (!QUERY_FLAG (op, FLAG_WIZ))
2870 op->stats.food--; 2864 op->stats.food--;
2871 } 2865 }
2872 } 2866 }
2873 2867
2874 if (op->contr->state == ST_PLAYING && op->stats.food < 0 && op->stats.hp >= 0) 2868 if (op->contr->ns->state == ST_PLAYING && op->stats.food < 0 && op->stats.hp >= 0)
2875 { 2869 {
2876 object *tmp, *flesh = NULL; 2870 object *tmp, *flesh = NULL;
2877 2871
2878 for (tmp = op->inv; tmp != NULL; tmp = tmp->below) 2872 for (tmp = op->inv; tmp != NULL; tmp = tmp->below)
2879 { 2873 {
2901 } /* end if player is starving */ 2895 } /* end if player is starving */
2902 2896
2903 while (op->stats.food < 0 && op->stats.hp > 0) 2897 while (op->stats.food < 0 && op->stats.hp > 0)
2904 op->stats.food++, op->stats.hp--; 2898 op->stats.food++, op->stats.hp--;
2905 2899
2906 if (!op->contr->state && !QUERY_FLAG (op, FLAG_WIZ) && (op->stats.hp < 0 || op->stats.food < 0)) 2900 if (!op->contr->ns->state && !QUERY_FLAG (op, FLAG_WIZ) && (op->stats.hp < 0 || op->stats.food < 0))
2907 kill_player (op); 2901 kill_player (op);
2908} 2902}
2909 2903
2910 2904
2911 2905
2948 /* restore player */ 2942 /* restore player */
2949 at = archetype::find ("poisoning"); 2943 at = archetype::find ("poisoning");
2950 tmp = present_arch_in_ob (at, op); 2944 tmp = present_arch_in_ob (at, op);
2951 if (tmp) 2945 if (tmp)
2952 { 2946 {
2953 remove_ob (tmp); 2947 tmp->destroy ();
2954 free_object (tmp);
2955 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed"); 2948 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed");
2956 } 2949 }
2957 2950
2958 at = archetype::find ("confusion"); 2951 at = archetype::find ("confusion");
2959 tmp = present_arch_in_ob (at, op); 2952 tmp = present_arch_in_ob (at, op);
2960 if (tmp) 2953 if (tmp)
2961 { 2954 {
2962 remove_ob (tmp); 2955 tmp->destroy ();
2963 free_object (tmp);
2964 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer"); 2956 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer");
2965 } 2957 }
2966 2958
2967 cure_disease (op, 0); /* remove any disease */ 2959 cure_disease (op, 0); /* remove any disease */
2968 op->stats.hp = op->stats.maxhp; 2960 op->stats.hp = op->stats.maxhp;
3178 3170
3179 /* remove any poisoning and confusion the character may be suffering. */ 3171 /* remove any poisoning and confusion the character may be suffering. */
3180 /* restore player */ 3172 /* restore player */
3181 at = archetype::find ("poisoning"); 3173 at = archetype::find ("poisoning");
3182 tmp = present_arch_in_ob (at, op); 3174 tmp = present_arch_in_ob (at, op);
3175
3183 if (tmp) 3176 if (tmp)
3184 { 3177 {
3185 remove_ob (tmp); 3178 tmp->destroy ();
3186 free_object (tmp);
3187 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed"); 3179 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed");
3188 } 3180 }
3189 3181
3190 at = archetype::find ("confusion"); 3182 at = archetype::find ("confusion");
3191 tmp = present_arch_in_ob (at, op); 3183 tmp = present_arch_in_ob (at, op);
3192 if (tmp) 3184 if (tmp)
3193 { 3185 {
3194 remove_ob (tmp); 3186 tmp->destroy ();
3195 free_object (tmp);
3196 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer"); 3187 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer");
3197 } 3188 }
3198 3189
3199 cure_disease (op, 0); /* remove any disease */ 3190 cure_disease (op, 0); /* remove any disease */
3200 3191
3234 * at his savebed location, and that can have long lasting 3225 * at his savebed location, and that can have long lasting
3235 * spell effects. So first see if there is a spell effect 3226 * spell effects. So first see if there is a spell effect
3236 * on the space that might harm the player. 3227 * on the space that might harm the player.
3237 */ 3228 */
3238 will_kill_again = 0; 3229 will_kill_again = 0;
3239 for (tmp = get_map_ob (op->map, op->x, op->y); tmp; tmp = tmp->above) 3230 for (tmp = GET_MAP_OB (op->map, op->x, op->y); tmp; tmp = tmp->above)
3240 if (tmp->type == SPELL_EFFECT) 3231 if (tmp->type == SPELL_EFFECT)
3241 will_kill_again |= tmp->attacktype; 3232 will_kill_again |= tmp->attacktype;
3242 3233
3243 if (will_kill_again) 3234 if (will_kill_again)
3244 { 3235 {
3275 check_score (op); 3266 check_score (op);
3276 3267
3277 if (op->contr->ranges[range_golem]) 3268 if (op->contr->ranges[range_golem])
3278 { 3269 {
3279 remove_friendly_object (op->contr->ranges[range_golem]); 3270 remove_friendly_object (op->contr->ranges[range_golem]);
3280 remove_ob (op->contr->ranges[range_golem]); 3271 op->contr->ranges[range_golem]->destroy ();
3281 free_object (op->contr->ranges[range_golem]);
3282 op->contr->ranges[range_golem] = 0; 3272 op->contr->ranges[range_golem] = 0;
3283 } 3273 }
3284 3274
3285 loot_object (op); /* Remove some of the items for good */ 3275 loot_object (op); /* Remove some of the items for good */
3286 remove_ob (op); 3276 op->remove ();
3287 op->direction = 0; 3277 op->direction = 0;
3288 3278
3289 if (!QUERY_FLAG (op, FLAG_WAS_WIZ) && op->stats.exp) 3279 if (!QUERY_FLAG (op, FLAG_WAS_WIZ) && op->stats.exp)
3290 { 3280 {
3291 delete_character (op->name, 0); 3281 delete_character (op->name, 0);
3342 } 3332 }
3343 3333
3344 for (tmp = op->inv; tmp != NULL; tmp = next) 3334 for (tmp = op->inv; tmp != NULL; tmp = next)
3345 { 3335 {
3346 next = tmp->below; 3336 next = tmp->below;
3347 if (tmp->type == EXPERIENCE || tmp->invisible) 3337 if (tmp->invisible)
3348 continue; 3338 continue;
3349 remove_ob (tmp); 3339 tmp->remove ();
3350 tmp->x = op->x, tmp->y = op->y; 3340 tmp->x = op->x, tmp->y = op->y;
3351 if (tmp->type == CONTAINER) 3341 if (tmp->type == CONTAINER)
3352 { /* empty container to ground */ 3342 { /* empty container to ground */
3353 loot_object (tmp); 3343 loot_object (tmp);
3354 } 3344 }
3355 if (!QUERY_FLAG (tmp, FLAG_UNIQUE) && (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || QUERY_FLAG (tmp, FLAG_NO_DROP) || !(RANDOM () % 3))) 3345 if (!QUERY_FLAG (tmp, FLAG_UNIQUE) && (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || QUERY_FLAG (tmp, FLAG_NO_DROP) || !(RANDOM () % 3)))
3356 { 3346 {
3357 if (tmp->nrof > 1) 3347 if (tmp->nrof > 1)
3358 { 3348 {
3359 tmp2 = get_split_ob (tmp, 1 + RANDOM () % (tmp->nrof - 1)); 3349 tmp2 = get_split_ob (tmp, 1 + RANDOM () % (tmp->nrof - 1));
3360 free_object (tmp2); 3350 tmp2->destroy ();
3361 insert_ob_in_map (tmp, op->map, NULL, 0); 3351 insert_ob_in_map (tmp, op->map, NULL, 0);
3362 } 3352 }
3363 else 3353 else
3364 free_object (tmp); 3354 tmp->destroy ();
3365 } 3355 }
3366 else 3356 else
3367 insert_ob_in_map (tmp, op->map, NULL, 0); 3357 insert_ob_in_map (tmp, op->map, NULL, 0);
3368 } 3358 }
3369} 3359}
3394fix_luck (void) 3384fix_luck (void)
3395{ 3385{
3396 player *pl; 3386 player *pl;
3397 3387
3398 for (pl = first_player; pl != NULL; pl = pl->next) 3388 for (pl = first_player; pl != NULL; pl = pl->next)
3399 if (!pl->ob->contr->state) 3389 if (!pl->ob->contr->ns->state)
3400 change_luck (pl->ob, 0); 3390 change_luck (pl->ob, 0);
3401} 3391}
3402 3392
3403 3393
3404/* cast_dust() - handles op throwing objects of type 'DUST'. 3394/* cast_dust() - handles op throwing objects of type 'DUST'.
3434 if (op->type == PLAYER) 3424 if (op->type == PLAYER)
3435 new_draw_info_format (NDI_UNIQUE, 0, op, "You cast %s.", &spob->name); 3425 new_draw_info_format (NDI_UNIQUE, 0, op, "You cast %s.", &spob->name);
3436 3426
3437 cast_spell (op, throw_ob, dir, spob, NULL); 3427 cast_spell (op, throw_ob, dir, spob, NULL);
3438 3428
3439 if (!QUERY_FLAG (throw_ob, FLAG_REMOVED)) 3429 throw_ob->destroy ();
3440 remove_ob (throw_ob);
3441 free_object (throw_ob);
3442} 3430}
3443 3431
3444void 3432void
3445make_visible (object *op) 3433make_visible (object *op)
3446{ 3434{
3460 object *tmp = NULL; 3448 object *tmp = NULL;
3461 3449
3462 if (QUERY_FLAG (&op->arch->clone, FLAG_UNDEAD)) 3450 if (QUERY_FLAG (&op->arch->clone, FLAG_UNDEAD))
3463 return 1; 3451 return 1;
3464 3452
3465 if (op->type == PLAYER)
3466 for (tmp = op->inv; tmp; tmp = tmp->below)
3467 if (tmp->type == EXPERIENCE && tmp->stats.Wis)
3468 if (QUERY_FLAG (tmp, FLAG_UNDEAD))
3469 return 1;
3470 return 0; 3453 return 0;
3471} 3454}
3472 3455
3473/* look at the surrounding terrain to determine 3456/* look at the surrounding terrain to determine
3474 * the hideability of this object. Positive levels 3457 * the hideability of this object. Positive levels
3589 if (mflags & P_OUT_OF_MAP) 3572 if (mflags & P_OUT_OF_MAP)
3590 continue; 3573 continue;
3591 if (OB_TYPE_MOVE_BLOCK (who, GET_MAP_MOVE_BLOCK (m, x, y))) 3574 if (OB_TYPE_MOVE_BLOCK (who, GET_MAP_MOVE_BLOCK (m, x, y)))
3592 continue; 3575 continue;
3593 3576
3594 for (tmp = get_map_ob (m, x, y); tmp; tmp = tmp->above) 3577 for (tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above)
3595 { 3578 {
3596 if ((player ||friendly) &&QUERY_FLAG (tmp, FLAG_MONSTER) && !QUERY_FLAG (tmp, FLAG_UNAGGRESSIVE)) 3579 if ((player ||friendly) &&QUERY_FLAG (tmp, FLAG_MONSTER) && !QUERY_FLAG (tmp, FLAG_UNAGGRESSIVE))
3597 return 1; 3580 return 1;
3598 else if (tmp->type == PLAYER) 3581 else if (tmp->type == PLAYER)
3599 { 3582 {
3653 3636
3654 /* only the viewable area the player sees is updated by LOS 3637 /* only the viewable area the player sees is updated by LOS
3655 * code, so we need to restrict ourselves to that range of values 3638 * code, so we need to restrict ourselves to that range of values
3656 * for any meaningful values. 3639 * for any meaningful values.
3657 */ 3640 */
3658 if (FABS (dx) <= (pl->contr->socket.mapx / 2) && 3641 if (FABS (dx) <= (pl->contr->ns->mapx / 2) &&
3659 FABS (dy) <= (pl->contr->socket.mapy / 2) && 3642 FABS (dy) <= (pl->contr->ns->mapy / 2) &&
3660 !pl->contr->blocked_los[dx + (pl->contr->socket.mapx / 2)][dy + (pl->contr->socket.mapy / 2)]) 3643 !pl->contr->blocked_los[dx + (pl->contr->ns->mapx / 2)][dy + (pl->contr->ns->mapy / 2)])
3661 return 1; 3644 return 1;
3662 op = op->more; 3645 op = op->more;
3663 } 3646 }
3664 return 0; 3647 return 0;
3665} 3648}
3851 { 3834 {
3852 /* forces in the treasurelist can alter the player's stats */ 3835 /* forces in the treasurelist can alter the player's stats */
3853 object *skin; 3836 object *skin;
3854 3837
3855 /* first get the dragon skin force */ 3838 /* first get the dragon skin force */
3839 shstr_cmp dragon_skin_force ("dragon_skin_force");
3856 for (skin = who->inv; skin != NULL && strcmp (skin->arch->name, "dragon_skin_force") != 0; skin = skin->below); 3840 for (skin = who->inv; skin && !(skin->arch->name == dragon_skin_force); skin = skin->below)
3841 ;
3842
3857 if (skin == NULL) 3843 if (!skin)
3858 return; 3844 return;
3859 3845
3860 /* adding new spellpath attunements */ 3846 /* adding new spellpath attunements */
3861 if (item->path_attuned > 0 && !(skin->path_attuned & item->path_attuned)) 3847 if (item->path_attuned > 0 && !(skin->path_attuned & item->path_attuned))
3862 { 3848 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines