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.33 by root, Tue Dec 12 21:39:57 2006 UTC vs.
Revision 1.52 by root, Thu Dec 21 23:37:06 2006 UTC

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#include <pwd.h> 25#include <pwd.h>
26#ifndef __CEXTRACT__
27# include <sproto.h> 26#include <sproto.h>
28#endif
29#include <sounds.h> 27#include <sounds.h>
30#include <living.h> 28#include <living.h>
31#include <object.h> 29#include <object.h>
32#include <spells.h> 30#include <spells.h>
33#include <skills.h> 31#include <skills.h>
34#include <newclient.h>
35 32
36#ifdef COZY_SERVER 33#ifdef COZY_SERVER
37extern int same_party (partylist *a, partylist *b); 34extern int same_party (partylist *a, partylist *b);
38#endif 35#endif
39 36
85 int comp; 82 int comp;
86 int size; 83 int size;
87 84
88 sprintf (buf, "%s/%s", settings.confdir, settings.motd); 85 sprintf (buf, "%s/%s", settings.confdir, settings.motd);
89 if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL) 86 if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL)
90 {
91 return; 87 return;
92 } 88
93 motd[0] = '\0'; 89 motd[0] = '\0';
94 size = 0; 90 size = 0;
91
95 while (fgets (buf, MAX_BUF, fp) != NULL) 92 while (fgets (buf, MAX_BUF, fp) != NULL)
96 { 93 {
97 if (*buf == '#') 94 if (*buf == '#')
98 continue; 95 continue;
96
99 strncat (motd + size, buf, HUGE_BUF - size); 97 strncat (motd + size, buf, HUGE_BUF - size);
100 size += strlen (buf); 98 size += strlen (buf);
101 } 99 }
100
102 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);
103 close_and_delete (fp, comp); 102 close_and_delete (fp, comp);
104} 103}
105 104
106void 105void
112 int comp; 111 int comp;
113 int size; 112 int size;
114 113
115 sprintf (buf, "%s/%s", settings.confdir, settings.rules); 114 sprintf (buf, "%s/%s", settings.confdir, settings.rules);
116 if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL) 115 if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL)
117 {
118 return; 116 return;
119 } 117
120 rules[0] = '\0'; 118 rules[0] = '\0';
121 size = 0; 119 size = 0;
120
122 while (fgets (buf, MAX_BUF, fp) != NULL) 121 while (fgets (buf, MAX_BUF, fp) != NULL)
123 { 122 {
124 if (*buf == '#') 123 if (*buf == '#')
125 continue; 124 continue;
125
126 if (size + strlen (buf) >= HUGE_BUF) 126 if (size + strlen (buf) >= HUGE_BUF)
127 { 127 {
128 LOG (llevDebug, "Warning, rules size is > %d bytes.\n", HUGE_BUF); 128 LOG (llevDebug, "Warning, rules size is > %d bytes.\n", HUGE_BUF);
129 break; 129 break;
130 } 130 }
131
131 strncat (rules + size, buf, HUGE_BUF - size); 132 strncat (rules + size, buf, HUGE_BUF - size);
132 size += strlen (buf); 133 size += strlen (buf);
133 } 134 }
135
134 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);
135 close_and_delete (fp, comp); 137 close_and_delete (fp, comp);
136} 138}
137 139
138void 140void
146 int size; 148 int size;
147 149
148 sprintf (buf, "%s/%s", settings.confdir, settings.news); 150 sprintf (buf, "%s/%s", settings.confdir, settings.news);
149 if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL) 151 if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL)
150 return; 152 return;
153
151 news[0] = '\0'; 154 news[0] = '\0';
152 subject[0] = '\0'; 155 subject[0] = '\0';
153 size = 0; 156 size = 0;
157
154 while (fgets (buf, MAX_BUF, fp) != NULL) 158 while (fgets (buf, MAX_BUF, fp) != NULL)
155 { 159 {
156 if (*buf == '#') 160 if (*buf == '#')
157 continue; 161 continue;
162
158 if (*buf == '%') 163 if (*buf == '%')
159 { /* send one news */ 164 { /* send one news */
160 if (size > 0) 165 if (size > 0)
161 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 */
162 strcpy (subject, buf + 1); 167 strcpy (subject, buf + 1);
189 return 0; 194 return 0;
190 195
191 for (; *cp != '\0'; cp++) 196 for (; *cp != '\0'; cp++)
192 if (!((*cp >= 'a' && *cp <= 'z') || (*cp >= 'A' && *cp <= 'Z')) && *cp != '-' && *cp != '_') 197 if (!((*cp >= 'a' && *cp <= 'z') || (*cp >= 'A' && *cp <= 'Z')) && *cp != '-' && *cp != '_')
193 return 0; 198 return 0;
199
194 return 1; 200 return 1;
195} 201}
196 202
197/* This no longer sets the player map. Also, it now updates 203/* This no longer sets the player map. Also, it now updates
198 * 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.
206 * the one that is passed. 212 * the one that is passed.
207 */ 213 */
208static player * 214static player *
209get_player (player *p) 215get_player (player *p)
210{ 216{
211 object *op = arch_to_object (get_player_archetype (NULL)); 217 object *op = arch_to_object (get_player_archetype (0));
212 int i; 218 int i;
213
214 if (!p)
215 {
216 p = new player;
217
218 /* This adds the player in the linked list. There is extra
219 * complexity here because we want to add the new player at the
220 * end of the list - there is in fact no compelling reason that
221 * that needs to be done except for things like output of
222 * 'who'.
223 */
224 player *tmp = first_player;
225
226 while (tmp != NULL && tmp->next != NULL)
227 tmp = tmp->next;
228 if (tmp != NULL)
229 tmp->next = p;
230 else
231 first_player = p;
232
233 p->next = NULL;
234 }
235 219
236 /* Clears basically the entire player structure except 220 /* Clears basically the entire player structure except
237 * for next and socket. 221 * for next and socket.
238 */ 222 */
239 p->clear (); 223 p->clear ();
258 op->speed_left = 0.5; 242 op->speed_left = 0.5;
259 op->speed = 1.0; 243 op->speed = 1.0;
260 op->direction = 5; /* So player faces south */ 244 op->direction = 5; /* So player faces south */
261 op->stats.wc = 2; 245 op->stats.wc = 2;
262 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
263 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 */
264
265 roll_stats (op); 251 roll_stats (op);
252 p->ns->monitor_spells = oldmon;
253 }
266 p->state = ST_ROLL_STAT; 254 p->ns->state = ST_ROLL_STAT;
267 clear_los (op); 255 clear_los (op);
268 256
269 p->gen_sp_armour = 10; 257 p->gen_sp_armour = 10;
270 p->last_speed = -1; 258 p->last_speed = -1;
271 p->shoottype = range_none; 259 p->shoottype = range_none;
275 p->usekeys = containers; 263 p->usekeys = containers;
276 p->last_weapon_sp = -1; 264 p->last_weapon_sp = -1;
277 p->peaceful = 1; /* default peaceful */ 265 p->peaceful = 1; /* default peaceful */
278 p->do_los = 1; 266 p->do_los = 1;
279 p->explore = 0; 267 p->explore = 0;
280 p->no_shout = 0; /* default can shout */
281 268
282 assign (p->title, op->arch->clone.name); 269 assign (p->title, op->arch->clone.name);
283 op->race = op->arch->clone.race; 270 op->race = op->arch->clone.race;
284 271
285 CLEAR_FLAG (op, FLAG_READY_SKILL); 272 CLEAR_FLAG (op, FLAG_READY_SKILL);
292 for (i = 0; i < NUM_SKILLS; i++) 279 for (i = 0; i < NUM_SKILLS; i++)
293 { 280 {
294 p->last_skill_exp[i] = -1; 281 p->last_skill_exp[i] = -1;
295 p->last_skill_ob[i] = NULL; 282 p->last_skill_ob[i] = NULL;
296 } 283 }
284
297 for (i = 0; i < NROFATTACKS; i++) 285 for (i = 0; i < NROFATTACKS; i++)
298 {
299 p->last_resist[i] = -1; 286 p->last_resist[i] = -1;
300 } 287
301 p->last_stats.exp = -1; 288 p->last_stats.exp = -1;
302 p->last_weight = (uint32) - 1; 289 p->last_weight = (uint32) - 1;
303 290
304 p->socket.update_look = 0; 291 p->ns->update_look = 0;
305 p->socket.look_position = 0; 292 p->ns->look_position = 0;
293
306 return p; 294 return p;
307} 295}
308 296
309/* This loads the first map an puts the player on it. */ 297/* This loads the first map an puts the player on it. */
310static void 298static void
311set_first_map (object *op) 299set_first_map (object *op)
312{ 300{
313 strcpy (op->contr->maplevel, first_map_path); 301 strcpy (op->contr->maplevel, first_map_path);
314 op->x = -1; 302 op->x = -1;
315 op->y = -1; 303 op->y = -1;
316 enter_exit (op, NULL); 304 enter_exit (op, 0);
317} 305}
318 306
319/* Tries to add player on the connection passwd in ns. 307/* Tries to add player on the connection passwd in ns.
320 * 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
321 * mode. 309 * mode.
322 */ 310 */
323 311
324int 312int
325add_player (NewSocket * ns) 313add_player (client *ns)
326{ 314{
327 player *p; 315 player *p = new player;
328 316
317 p->ns = ns;
318 ns->pl = p;
319
320 p->next = first_player;
321 first_player = p;
322
329 p = get_player (NULL); 323 p = get_player (p);
330 p->socket = *ns;
331 p->socket.faces_sent = (uint8 *) malloc (p->socket.faces_sent_len * sizeof (*p->socket.faces_sent));
332 324
333 if (p->socket.faces_sent == NULL)
334 fatal (OUT_OF_MEMORY);
335
336 memcpy (p->socket.faces_sent, ns->faces_sent, p->socket.faces_sent_len * sizeof (*p->socket.faces_sent));
337 /* Needed because the socket we just copied over needs to be cleared.
338 * Note that this can result in a client reset if there is partial data
339 * on the uncoming socket.
340 */
341 p->socket.inbuf.len = 0;
342 set_first_map (p->ob); 325 set_first_map (p->ob);
343 326
344 CLEAR_FLAG (p->ob, FLAG_FRIENDLY); 327 CLEAR_FLAG (p->ob, FLAG_FRIENDLY);
345 add_friendly_object (p->ob); 328 add_friendly_object (p->ob);
346 send_rules (p->ob); 329 send_rules (p->ob);
347 send_news (p->ob); 330 send_news (p->ob);
348 display_motd (p->ob); 331 display_motd (p->ob);
332
349 get_name (p->ob); 333 get_name (p->ob);
350 334
351 return 0; 335 return 0;
352} 336}
353 337
365 { 349 {
366 if (at == NULL || at->next == NULL) 350 if (at == NULL || at->next == NULL)
367 at = first_archetype; 351 at = first_archetype;
368 else 352 else
369 at = at->next; 353 at = at->next;
354
370 if (at->clone.type == PLAYER) 355 if (at->clone.type == PLAYER)
371 return at; 356 return at;
357
372 if (at == start) 358 if (at == start)
373 { 359 {
374 LOG (llevError, "No Player archetypes\n"); 360 LOG (llevError, "No Player archetypes\n");
375 exit (-1); 361 exit (-1);
376 } 362 }
377 } 363 }
378} 364}
379
380 365
381object * 366object *
382get_nearest_player (object *mon) 367get_nearest_player (object *mon)
383{ 368{
384 object *op = NULL; 369 object *op = NULL;
713 698
714void 699void
715get_name (object *op) 700get_name (object *op)
716{ 701{
717 op->contr->write_buf[0] = '\0'; 702 op->contr->write_buf[0] = '\0';
718 op->contr->state = ST_GET_NAME; 703 op->contr->ns->state = ST_GET_NAME;
719 send_query (&op->contr->socket, 0, "What is your name?\n:"); 704 send_query (op->contr->ns, 0, "What is your name?\n:");
720} 705}
721 706
722void 707void
723get_password (object *op) 708get_password (object *op)
724{ 709{
725 op->contr->write_buf[0] = '\0'; 710 op->contr->write_buf[0] = '\0';
726 op->contr->state = ST_GET_PASSWORD; 711 op->contr->ns->state = ST_GET_PASSWORD;
727 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:");
728} 713}
729 714
730void 715void
731play_again (object *op) 716play_again (object *op)
732{ 717{
733 op->contr->state = ST_PLAY_AGAIN; 718 op->contr->ns->state = ST_PLAY_AGAIN;
734 op->chosen_skill = NULL; 719 op->chosen_skill = NULL;
735 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)?");
736 /* 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
737 * player creation process that a user can quit (eg, roll 722 * player creation process that a user can quit (eg, roll
738 * stats) that isn't removing the player. Taking a quick 723 * stats) that isn't removing the player. Taking a quick
739 * look, there are many places that call play_again without 724 * look, there are many places that call play_again without
740 * removing the player - it probably makes more sense 725 * removing the player - it probably makes more sense
741 * 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
742 * cases. 727 * cases.
743 */ 728 */
744 if (!QUERY_FLAG (op, FLAG_REMOVED)) 729 if (!QUERY_FLAG (op, FLAG_REMOVED))
745 op->remove (); 730 op->remove ();
731
746 /* 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,
747 * 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
748 * the map is null or not swapped out. 734 * the map is null or not swapped out.
749 */ 735 */
750 op->map = NULL; 736 op->map = NULL;
788void 774void
789confirm_password (object *op) 775confirm_password (object *op)
790{ 776{
791 777
792 op->contr->write_buf[0] = '\0'; 778 op->contr->write_buf[0] = '\0';
793 op->contr->state = ST_CONFIRM_PASSWORD; 779 op->contr->ns->state = ST_CONFIRM_PASSWORD;
794 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:");
795} 781}
796 782
797void 783void
798get_party_password (object *op, partylist *party) 784get_party_password (object *op, partylist *party)
799{ 785{
801 { 787 {
802 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);
803 return; 789 return;
804 } 790 }
805 op->contr->write_buf[0] = '\0'; 791 op->contr->write_buf[0] = '\0';
806 op->contr->state = ST_GET_PARTY_PASSWORD; 792 op->contr->ns->state = ST_GET_PARTY_PASSWORD;
807 op->contr->party_to_join = party; 793 op->contr->party_to_join = party;
808 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:");
809} 795}
810 796
811 797
812/* 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. */
813int 799int
910 896
911void 897void
912Roll_Again (object *op) 898Roll_Again (object *op)
913{ 899{
914 esrv_new_player (op->contr, 0); 900 esrv_new_player (op->contr, 0);
915 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, 901 send_query (op->contr->ns, CS_QUERY_SINGLECHAR,
916 "[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)? ");
917} 903}
918 904
919void 905void
920Swap_Stat (object *op, int Swap_Second) 906Swap_Stat (object *op, int Swap_Second)
987 new_draw_info (NDI_UNIQUE, 0, op, buf); 973 new_draw_info (NDI_UNIQUE, 0, op, buf);
988 } 974 }
989 else 975 else
990 Swap_Stat (op, stat_trans[keynum]); 976 Swap_Stat (op, stat_trans[keynum]);
991 977
992 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, ""); 978 send_query (op->contr->ns, CS_QUERY_SINGLECHAR, "");
993 return 1; 979 return 1;
994 } 980 }
995 switch (key) 981 switch (key)
996 { 982 {
997 case 'n': 983 case 'n':
1011 enter_exit (op, NULL); 997 enter_exit (op, NULL);
1012#endif 998#endif
1013 SET_ANIMATION (op, 2); /* So player faces south */ 999 SET_ANIMATION (op, 2); /* So player faces south */
1014 /* Enter exit adds a player otherwise */ 1000 /* Enter exit adds a player otherwise */
1015 add_statbonus (op); 1001 add_statbonus (op);
1016 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, 1002 send_query (op->contr->ns, CS_QUERY_SINGLECHAR,
1017 "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");
1018 op->contr->state = ST_CHANGE_CLASS; 1004 op->contr->ns->state = ST_CHANGE_CLASS;
1019 if (op->msg) 1005 if (op->msg)
1020 new_draw_info (NDI_BLUE, 0, op, op->msg); 1006 new_draw_info (NDI_BLUE, 0, op, op->msg);
1021 return 0; 1007 return 0;
1022 } 1008 }
1023 case 'y': 1009 case 'y':
1024 case 'Y': 1010 case 'Y':
1025 roll_stats (op); 1011 roll_stats (op);
1026 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, ""); 1012 send_query (op->contr->ns, CS_QUERY_SINGLECHAR, "");
1027 return 1; 1013 return 1;
1028 1014
1029 case 'q': 1015 case 'q':
1030 case 'Q': 1016 case 'Q':
1031 play_again (op); 1017 play_again (op);
1032 return 1; 1018 return 1;
1033 1019
1034 default: 1020 default:
1035 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?");
1036 return 0; 1022 return 0;
1037 } 1023 }
1038 return 0; 1024 return 0;
1039} 1025}
1040 1026
1060 { 1046 {
1061 char buf[MAX_BUF]; 1047 char buf[MAX_BUF];
1062 1048
1063 /* this must before then initial items are given */ 1049 /* this must before then initial items are given */
1064 esrv_new_player (op->contr, op->weight + op->carrying); 1050 esrv_new_player (op->contr, op->weight + op->carrying);
1051
1065 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);
1066 1055
1067 INVOKE_PLAYER (BIRTH, op->contr); 1056 INVOKE_PLAYER (BIRTH, op->contr);
1068 INVOKE_PLAYER (LOGIN, op->contr); 1057 INVOKE_PLAYER (LOGIN, op->contr);
1069 1058
1070 op->contr->state = ST_PLAYING; 1059 op->contr->ns->state = ST_PLAYING;
1071 1060
1072 if (op->msg) 1061 if (op->msg)
1073 op->msg = NULL; 1062 op->msg = NULL;
1074 1063
1075 /* 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
1105 * if the map isn't there, then stay on the 1094 * if the map isn't there, then stay on the
1106 * default initial map */ 1095 * default initial map */
1107 tmp->destroy (); 1096 tmp->destroy ();
1108 } 1097 }
1109 else 1098 else
1110 {
1111 LOG (llevDebug, "first_map_ext_path not set\n"); 1099 LOG (llevDebug, "first_map_ext_path not set\n");
1112 } 1100
1113 return 0; 1101 return 0;
1114 } 1102 }
1115 1103
1116 /* Following actually changes the race - this is the default command 1104 /* Following actually changes the race - this is the default command
1117 * if we don't match with one of the options above. 1105 * if we don't match with one of the options above.
1147 op->stats.grace = 0; 1135 op->stats.grace = 0;
1148 1136
1149 if (op->msg) 1137 if (op->msg)
1150 new_draw_info (NDI_BLUE, 0, op, op->msg); 1138 new_draw_info (NDI_BLUE, 0, op, op->msg);
1151 1139
1152 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");
1153 return 0; 1141 return 0;
1154} 1142}
1155 1143
1156int 1144int
1157key_confirm_quit (object *op, char key) 1145key_confirm_quit (object *op, char key)
1158{ 1146{
1159 char buf[MAX_BUF]; 1147 char buf[MAX_BUF];
1160 1148
1161 if (key != 'y' && key != 'Y' && key != 'q' && key != 'Q') 1149 if (key != 'y' && key != 'Y' && key != 'q' && key != 'Q')
1162 { 1150 {
1163 op->contr->state = ST_PLAYING; 1151 op->contr->ns->state = ST_PLAYING;
1164 new_draw_info (NDI_UNIQUE, 0, op, "OK, continuing to play."); 1152 new_draw_info (NDI_UNIQUE, 0, op, "OK, continuing to play.");
1165 return 1; 1153 return 1;
1166 } 1154 }
1167 1155
1168 INVOKE_PLAYER (LOGOUT, op->contr); 1156 INVOKE_PLAYER (LOGOUT, op->contr);
1237 { 1225 {
1238 op->enemy = NULL; 1226 op->enemy = NULL;
1239 CLEAR_FLAG (op, FLAG_SCARED); 1227 CLEAR_FLAG (op, FLAG_SCARED);
1240 return; 1228 return;
1241 } 1229 }
1230
1242 get_rangevector (op, op->enemy, &rv, 0); 1231 get_rangevector (op, op->enemy, &rv, 0);
1243 1232
1244 dir = absdir (4 + rv.direction); 1233 dir = absdir (4 + rv.direction);
1245 for (diff = 0; diff < 3; diff++) 1234 for (diff = 0; diff < 3; diff++)
1246 { 1235 {
1247 int m = 1 - (RANDOM () & 2); 1236 int m = 1 - (RANDOM () & 2);
1248 1237
1249 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)))
1250 {
1251 return; 1239 return;
1252 }
1253 } 1240 }
1241
1254 /* Cornered, get rid of scared */ 1242 /* Cornered, get rid of scared */
1255 CLEAR_FLAG (op, FLAG_SCARED); 1243 CLEAR_FLAG (op, FLAG_SCARED);
1256 op->enemy = NULL; 1244 op->enemy = NULL;
1257} 1245}
1258 1246
1814 if (!dir) 1802 if (!dir)
1815 { 1803 {
1816 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!");
1817 return 0; 1805 return 0;
1818 } 1806 }
1807
1819 if (op->type == PLAYER) 1808 if (op->type == PLAYER)
1820 bow = op->contr->ranges[range_bow]; 1809 bow = op->contr->ranges[range_bow];
1821 else 1810 else
1822 { 1811 {
1823 for (bow = op->inv; bow; bow = bow->below) 1812 for (bow = op->inv; bow; bow = bow->below)
1831 { 1820 {
1832 LOG (llevError, "Range: bow without activated bow (%s).\n", &op->name); 1821 LOG (llevError, "Range: bow without activated bow (%s).\n", &op->name);
1833 return 0; 1822 return 0;
1834 } 1823 }
1835 } 1824 }
1825
1836 if (!bow->race || !bow->skill) 1826 if (!bow->race || !bow->skill)
1837 { 1827 {
1838 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);
1839 return 0; 1829 return 0;
1840 } 1830 }
1842 bowspeed = bow->stats.sp + dex_bonus[op->stats.Dex]; 1832 bowspeed = bow->stats.sp + dex_bonus[op->stats.Dex];
1843 1833
1844 /* penalize ROF for bestarrow */ 1834 /* penalize ROF for bestarrow */
1845 if (op->type == PLAYER && op->contr->bowtype == bow_bestarrow) 1835 if (op->type == PLAYER && op->contr->bowtype == bow_bestarrow)
1846 bowspeed -= dex_bonus[op->stats.Dex] + 5; 1836 bowspeed -= dex_bonus[op->stats.Dex] + 5;
1837
1847 if (bowspeed < 1) 1838 if (bowspeed < 1)
1848 bowspeed = 1; 1839 bowspeed = 1;
1849 1840
1850 if (arrow == NULL) 1841 if (arrow == NULL)
1851 { 1842 {
1857 else 1848 else
1858 CLEAR_FLAG (op, FLAG_READY_BOW); 1849 CLEAR_FLAG (op, FLAG_READY_BOW);
1859 return 0; 1850 return 0;
1860 } 1851 }
1861 } 1852 }
1853
1862 mflags = get_map_flags (op->map, &m, sx, sy, &sx, &sy); 1854 mflags = get_map_flags (op->map, &m, sx, sy, &sx, &sy);
1863 if (mflags & P_OUT_OF_MAP) 1855 if (mflags & P_OUT_OF_MAP)
1864 {
1865 return 0; 1856 return 0;
1866 } 1857
1867 if (GET_MAP_MOVE_BLOCK (m, sx, sy) == MOVE_FLY_LOW) 1858 if (GET_MAP_MOVE_BLOCK (m, sx, sy) == MOVE_FLY_LOW)
1868 { 1859 {
1869 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.");
1870 return 0; 1861 return 0;
1871 } 1862 }
1877 return 0; 1868 return 0;
1878 } 1869 }
1879 1870
1880 left = arrow; /* these are arrows left to the player */ 1871 left = arrow; /* these are arrows left to the player */
1881 arrow = get_split_ob (arrow, 1); 1872 arrow = get_split_ob (arrow, 1);
1882 if (arrow == NULL) 1873 if (!arrow)
1883 { 1874 {
1884 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);
1885 return 0; 1876 return 0;
1886 } 1877 }
1887 set_owner (arrow, op); 1878
1879 arrow->set_owner (op);
1888 arrow->skill = bow->skill; 1880 arrow->skill = bow->skill;
1889 1881
1890 arrow->direction = dir; 1882 arrow->direction = dir;
1891 arrow->x = sx; 1883 arrow->x = sx;
1892 arrow->y = sy; 1884 arrow->y = sy;
1900 SET_ANIMATION (arrow, arrow->direction); 1892 SET_ANIMATION (arrow, arrow->direction);
1901 arrow->stats.sp = arrow->stats.wc; /* save original wc and dam */ 1893 arrow->stats.sp = arrow->stats.wc; /* save original wc and dam */
1902 arrow->stats.hp = arrow->stats.dam; 1894 arrow->stats.hp = arrow->stats.dam;
1903 arrow->stats.grace = arrow->attacktype; 1895 arrow->stats.grace = arrow->attacktype;
1904 if (arrow->slaying != NULL) 1896 if (arrow->slaying != NULL)
1905 arrow->spellarg = strdup_local (arrow->slaying); 1897 arrow->spellarg = strdup (arrow->slaying);
1906 1898
1907 /* Note that this was different for monsters - they got their level 1899 /* Note that this was different for monsters - they got their level
1908 * 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.
1909 */ 1901 */
1910 1902
1934 } 1926 }
1935 1927
1936 if (arrow->attacktype == AT_PHYSICAL) 1928 if (arrow->attacktype == AT_PHYSICAL)
1937 arrow->attacktype |= bow->attacktype; 1929 arrow->attacktype |= bow->attacktype;
1938 1930
1939 if (bow->slaying != NULL) 1931 if (bow->slaying)
1940 arrow->slaying = bow->slaying; 1932 arrow->slaying = bow->slaying;
1941 1933
1942 arrow->map = m; 1934 arrow->map = m;
1943 arrow->move_type = MOVE_FLY_LOW; 1935 arrow->move_type = MOVE_FLY_LOW;
1944 arrow->move_on = MOVE_FLY_LOW | MOVE_WALK; 1936 arrow->move_on = MOVE_FLY_LOW | MOVE_WALK;
2060 CLEAR_FLAG (item, FLAG_ANIMATE); 2052 CLEAR_FLAG (item, FLAG_ANIMATE);
2061 item->face = item->arch->clone.face; 2053 item->face = item->arch->clone.face;
2062 item->speed = 0; 2054 item->speed = 0;
2063 update_ob_speed (item); 2055 update_ob_speed (item);
2064 } 2056 }
2065 if ((tmp = is_player_inv (item))) 2057 if ((tmp = item->in_player ()))
2066 esrv_update_item (UPD_ANIM, tmp, item); 2058 esrv_update_item (UPD_ANIM, tmp, item);
2067 } 2059 }
2068 } 2060 }
2069 else if (item->type == ROD || item->type == HORN) 2061 else if (item->type == ROD || item->type == HORN)
2070 { 2062 {
2220 * 0 otherwise 2212 * 0 otherwise
2221 */ 2213 */
2222static int 2214static int
2223player_attack_door (object *op, object *door) 2215player_attack_door (object *op, object *door)
2224{ 2216{
2225
2226 /* 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,
2227 * 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 -
2228 * otherwise, we fall through to the rest of the code. 2219 * otherwise, we fall through to the rest of the code.
2229 */ 2220 */
2230 object *key = find_key (op, op, door); 2221 object *key = find_key (op, op, door);
2268 * It should keep the code cleaner. 2259 * It should keep the code cleaner.
2269 * When this is called, the players direction has been updated 2260 * When this is called, the players direction has been updated
2270 * (taking into account confusion.) The player is also actually 2261 * (taking into account confusion.) The player is also actually
2271 * going to try and move (not fire weapons). 2262 * going to try and move (not fire weapons).
2272 */ 2263 */
2273
2274void 2264void
2275move_player_attack (object *op, int dir) 2265move_player_attack (object *op, int dir)
2276{ 2266{
2277 object *tmp, *mon; 2267 object *tmp, *mon;
2278 sint16 nx, ny; 2268 sint16 nx, ny;
2280 maptile *m; 2270 maptile *m;
2281 2271
2282 nx = freearr_x[dir] + op->x; 2272 nx = freearr_x[dir] + op->x;
2283 ny = freearr_y[dir] + op->y; 2273 ny = freearr_y[dir] + op->y;
2284 2274
2285 on_battleground = op_on_battleground (op, NULL, NULL); 2275 on_battleground = op_on_battleground (op, 0, 0);
2286 2276
2287 /* 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
2288 * 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
2289 * 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
2290 * player. This is a pretty nasty hack, because if we could 2280 * player. This is a pretty nasty hack, because if we could
2302 return; /* Don't think this should happen */ 2292 return; /* Don't think this should happen */
2303 } 2293 }
2304 else 2294 else
2305 m = op->map; 2295 m = op->map;
2306 2296
2307 if ((tmp = get_map_ob (m, nx, ny)) == NULL) 2297 if ((tmp = GET_MAP_OB (m, nx, ny)) == NULL)
2308 { 2298 {
2309 /* 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"); */
2310 return; 2300 return;
2311 } 2301 }
2312 2302
2313 mon = NULL; 2303 mon = 0;
2314 /* 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
2315 * 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.
2316 * 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
2317 * on the space 2307 * on the space
2318 */ 2308 */
2319 while (tmp != NULL) 2309 while (tmp)
2320 { 2310 {
2321 if (tmp == op) 2311 if (tmp == op)
2322 { 2312 {
2323 tmp = tmp->above; 2313 tmp = tmp->above;
2324 continue; 2314 continue;
2334 mon = tmp; 2324 mon = tmp;
2335 2325
2336 tmp = tmp->above; 2326 tmp = tmp->above;
2337 } 2327 }
2338 2328
2339 if (mon == NULL) /* This happens anytime the player tries to move */ 2329 if (!mon) /* This happens anytime the player tries to move */
2340 return; /* into a wall */ 2330 return; /* into a wall */
2341 2331
2342 if (mon->head != NULL) 2332 if (mon->head)
2343 mon = mon->head; 2333 mon = mon->head;
2344 2334
2345 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))
2346 if (player_attack_door (op, mon)) 2336 if (player_attack_door (op, mon))
2347 return; 2337 return;
2359 * player owns it and it is either friendly or unagressive. 2349 * player owns it and it is either friendly or unagressive.
2360 */ 2350 */
2361 if ((op->type == PLAYER) 2351 if ((op->type == PLAYER)
2362#if COZY_SERVER 2352#if COZY_SERVER
2363 && 2353 &&
2364 ((get_owner (mon) && get_owner (mon)->contr 2354 ((mon->owner && mon->owner->contr
2365 && 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)
2366#else 2356#else
2367 && get_owner (mon) == op 2357 && mon->owner == op
2368#endif 2358#endif
2369 && (QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY))) 2359 && (QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY)))
2370 { 2360 {
2371 /* 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 */
2372 if (op->contr->braced) 2362 if (op->contr->braced)
2384 * attack them either. 2374 * attack them either.
2385 */ 2375 */
2386 if ((mon->type == PLAYER || mon->enemy != op) && 2376 if ((mon->type == PLAYER || mon->enemy != op) &&
2387 (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)) && (
2388#ifdef PROHIBIT_PLAYERKILL 2378#ifdef PROHIBIT_PLAYERKILL
2389 (op->contr->peaceful 2379 (op->contr->peaceful
2390 || (mon->type == PLAYER 2380 || (mon->type == PLAYER
2391 && mon->contr-> 2381 && mon->contr->
2392 peaceful)) && 2382 peaceful)) &&
2393#else 2383#else
2394 op->contr->peaceful && 2384 op->contr->peaceful &&
2395#endif 2385#endif
2396 !on_battleground)) 2386 !on_battleground))
2397 { 2387 {
2398 if (!op->contr->braced) 2388 if (!op->contr->braced)
2399 { 2389 {
2400 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);
2401 (void) push_ob (mon, dir, op); 2391 (void) push_ob (mon, dir, op);
2402 } 2392 }
2403 else 2393 else
2404 {
2405 new_draw_info (0, 0, op, "You withhold your attack"); 2394 new_draw_info (0, 0, op, "You withhold your attack");
2406 } 2395
2407 if (op->contr->tmp_invis || op->hide) 2396 if (op->contr->tmp_invis || op->hide)
2408 make_visible (op); 2397 make_visible (op);
2409 } 2398 }
2410 2399
2411 /* If the object is a boulder or other rollable object, then 2400 /* If the object is a boulder or other rollable object, then
2439 op->speed_left += op->speed / op->contr->weapon_sp; 2428 op->speed_left += op->speed / op->contr->weapon_sp;
2440 2429
2441 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 */
2442 } 2431 }
2443 2432
2444 skill_attack (mon, op, 0, NULL, NULL); 2433 skill_attack (mon, op, 0, 0, 0);
2445 2434
2446 /* If attacking another player, that player gets automatic 2435 /* If attacking another player, that player gets automatic
2447 * hitback, and doesn't loose luck either. 2436 * hitback, and doesn't loose luck either.
2448 * Disable hitback on the battleground or if the target is 2437 * Disable hitback on the battleground or if the target is
2449 * the wiz. 2438 * the wiz.
2451 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))
2452 { 2441 {
2453 short luck = mon->stats.luck; 2442 short luck = mon->stats.luck;
2454 2443
2455 mon->contr->has_hit = 1; 2444 mon->contr->has_hit = 1;
2456 skill_attack (op, mon, 0, NULL, NULL); 2445 skill_attack (op, mon, 0, 0, 0);
2457 mon->stats.luck = luck; 2446 mon->stats.luck = luck;
2458 } 2447 }
2448
2459 if (action_makes_visible (op)) 2449 if (action_makes_visible (op))
2460 make_visible (op); 2450 make_visible (op);
2461 } 2451 }
2462 } /* if player should attack something */ 2452 } /* if player should attack something */
2463} 2453}
2498 2488
2499 /* 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
2500 * server can handle repeat firing. 2490 * server can handle repeat firing.
2501 */ 2491 */
2502 if (op->contr->fire_on || (op->contr->run_on && pick != 0)) 2492 if (op->contr->fire_on || (op->contr->run_on && pick != 0))
2503 {
2504 op->direction = dir; 2493 op->direction = dir;
2505 }
2506 else 2494 else
2507 {
2508 op->direction = 0; 2495 op->direction = 0;
2509 } 2496
2510 /* Update how the player looks. Use the facing, so direction may 2497 /* Update how the player looks. Use the facing, so direction may
2511 * get reset to zero. This allows for full animation capabilities 2498 * get reset to zero. This allows for full animation capabilities
2512 * for players. 2499 * for players.
2513 */ 2500 */
2514 animate_object (op, op->facing); 2501 animate_object (op, op->facing);
2566 2553
2567 /* 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
2568 * the players time has been increased when doericserver has been 2555 * the players time has been increased when doericserver has been
2569 * called, so we recheck it here. 2556 * called, so we recheck it here.
2570 */ 2557 */
2571 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
2572 if (op->speed_left < 0) 2562 if (op->speed_left < 0)
2573 return 0; 2563 return 0;
2574 2564
2575 if (op->direction && (op->contr->run_on || op->contr->fire_on)) 2565 if (op->direction && (op->contr->run_on || op->contr->fire_on))
2576 { 2566 {
2585 if (op->speed_left > 0) 2575 if (op->speed_left > 0)
2586 return 1; 2576 return 1;
2587 else 2577 else
2588 return 0; 2578 return 0;
2589 } 2579 }
2580
2590 return 0; 2581 return 0;
2591} 2582}
2592 2583
2593int 2584int
2594save_life (object *op) 2585save_life (object *op)
2595{ 2586{
2596 object *tmp;
2597
2598 if (!QUERY_FLAG (op, FLAG_LIFESAVE)) 2587 if (!QUERY_FLAG (op, FLAG_LIFESAVE))
2599 return 0; 2588 return 0;
2600 2589
2601 for (tmp = op->inv; tmp != NULL; tmp = tmp->below) 2590 for (object *tmp = op->inv; tmp; tmp = tmp->below)
2602 if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE)) 2591 if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE))
2603 { 2592 {
2604 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);
2605 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));
2606 2595
2617 op->stats.food = 999; 2606 op->stats.food = 999;
2618 2607
2619 fix_player (op); 2608 fix_player (op);
2620 return 1; 2609 return 1;
2621 } 2610 }
2611
2622 LOG (llevError, "Error: LIFESAVE set without applied object.\n"); 2612 LOG (llevError, "Error: LIFESAVE set without applied object.\n");
2623 CLEAR_FLAG (op, FLAG_LIFESAVE); 2613 CLEAR_FLAG (op, FLAG_LIFESAVE);
2624 enter_player_savebed (op); /* bring him home. */ 2614 enter_player_savebed (op); /* bring him home. */
2625 return 0; 2615 return 0;
2626} 2616}
2649 esrv_del_item (env->contr, op->count); 2639 esrv_del_item (env->contr, op->count);
2650 insert_ob_in_map (op, env->map, NULL, 0); 2640 insert_ob_in_map (op, env->map, NULL, 0);
2651 } 2641 }
2652 else if (op->inv) 2642 else if (op->inv)
2653 remove_unpaid_objects (op->inv, env); 2643 remove_unpaid_objects (op->inv, env);
2644
2654 op = next; 2645 op = next;
2655 } 2646 }
2656} 2647}
2657 2648
2658 2649
2673 strcpy (buf2, " R.I.P.\n\n"); 2664 strcpy (buf2, " R.I.P.\n\n");
2674 if (op->type == PLAYER) 2665 if (op->type == PLAYER)
2675 sprintf (buf, "%s the %s\n", &op->name, op->contr->title); 2666 sprintf (buf, "%s the %s\n", &op->name, op->contr->title);
2676 else 2667 else
2677 sprintf (buf, "%s\n", &op->name); 2668 sprintf (buf, "%s\n", &op->name);
2669
2678 strncat (buf2, " ", 20 - strlen (buf) / 2); 2670 strncat (buf2, " ", 20 - strlen (buf) / 2);
2679 strcat (buf2, buf); 2671 strcat (buf2, buf);
2680 if (op->type == PLAYER) 2672 if (op->type == PLAYER)
2681 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);
2682 else 2674 else
2683 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
2684 strncat (buf2, " ", 20 - strlen (buf) / 2); 2677 strncat (buf2, " ", 20 - strlen (buf) / 2);
2685 strcat (buf2, buf); 2678 strcat (buf2, buf);
2686 if (op->type == PLAYER) 2679 if (op->type == PLAYER)
2687 { 2680 {
2688 sprintf (buf, "by %s.\n\n", op->contr->killer); 2681 sprintf (buf, "by %s.\n\n", op->contr->killer);
2689 strncat (buf2, " ", 21 - strlen (buf) / 2); 2682 strncat (buf2, " ", 21 - strlen (buf) / 2);
2690 strcat (buf2, buf); 2683 strcat (buf2, buf);
2691 } 2684 }
2685
2692 strftime (buf, MAX_BUF, "%b %d %Y\n", localtime (&now)); 2686 strftime (buf, MAX_BUF, "%b %d %Y\n", localtime (&now));
2693 strncat (buf2, " ", 20 - strlen (buf) / 2); 2687 strncat (buf2, " ", 20 - strlen (buf) / 2);
2694 strcat (buf2, buf); 2688 strcat (buf2, buf);
2689
2695 return buf2; 2690 return buf2;
2696} 2691}
2697 2692
2698 2693
2699 2694
2716 for (i = 0; i < NUM_OUTPUT_BUFS; i++) 2711 for (i = 0; i < NUM_OUTPUT_BUFS; i++)
2717 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)
2718 flush_output_element (op, &op->contr->outputs[i]); 2713 flush_output_element (op, &op->contr->outputs[i]);
2719 } 2714 }
2720 2715
2721 if (op->contr->state == ST_PLAYING) 2716 if (op->contr->ns->state == ST_PLAYING)
2722 { 2717 {
2723 2718
2724 /* these next three if clauses make it possible to SLOW DOWN 2719 /* these next three if clauses make it possible to SLOW DOWN
2725 hp/grace/spellpoint regeneration. */ 2720 hp/grace/spellpoint regeneration. */
2726 if (op->contr->gen_hp >= 0) 2721 if (op->contr->gen_hp >= 0)
2868 if (!QUERY_FLAG (op, FLAG_WIZ)) 2863 if (!QUERY_FLAG (op, FLAG_WIZ))
2869 op->stats.food--; 2864 op->stats.food--;
2870 } 2865 }
2871 } 2866 }
2872 2867
2873 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)
2874 { 2869 {
2875 object *tmp, *flesh = NULL; 2870 object *tmp, *flesh = NULL;
2876 2871
2877 for (tmp = op->inv; tmp != NULL; tmp = tmp->below) 2872 for (tmp = op->inv; tmp != NULL; tmp = tmp->below)
2878 { 2873 {
2900 } /* end if player is starving */ 2895 } /* end if player is starving */
2901 2896
2902 while (op->stats.food < 0 && op->stats.hp > 0) 2897 while (op->stats.food < 0 && op->stats.hp > 0)
2903 op->stats.food++, op->stats.hp--; 2898 op->stats.food++, op->stats.hp--;
2904 2899
2905 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))
2906 kill_player (op); 2901 kill_player (op);
2907} 2902}
2908 2903
2909 2904
2910 2905
3230 * at his savebed location, and that can have long lasting 3225 * at his savebed location, and that can have long lasting
3231 * spell effects. So first see if there is a spell effect 3226 * spell effects. So first see if there is a spell effect
3232 * on the space that might harm the player. 3227 * on the space that might harm the player.
3233 */ 3228 */
3234 will_kill_again = 0; 3229 will_kill_again = 0;
3235 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)
3236 if (tmp->type == SPELL_EFFECT) 3231 if (tmp->type == SPELL_EFFECT)
3237 will_kill_again |= tmp->attacktype; 3232 will_kill_again |= tmp->attacktype;
3238 3233
3239 if (will_kill_again) 3234 if (will_kill_again)
3240 { 3235 {
3337 } 3332 }
3338 3333
3339 for (tmp = op->inv; tmp != NULL; tmp = next) 3334 for (tmp = op->inv; tmp != NULL; tmp = next)
3340 { 3335 {
3341 next = tmp->below; 3336 next = tmp->below;
3342 if (tmp->type == EXPERIENCE || tmp->invisible) 3337 if (tmp->invisible)
3343 continue; 3338 continue;
3344 tmp->remove (); 3339 tmp->remove ();
3345 tmp->x = op->x, tmp->y = op->y; 3340 tmp->x = op->x, tmp->y = op->y;
3346 if (tmp->type == CONTAINER) 3341 if (tmp->type == CONTAINER)
3347 { /* empty container to ground */ 3342 { /* empty container to ground */
3389fix_luck (void) 3384fix_luck (void)
3390{ 3385{
3391 player *pl; 3386 player *pl;
3392 3387
3393 for (pl = first_player; pl != NULL; pl = pl->next) 3388 for (pl = first_player; pl != NULL; pl = pl->next)
3394 if (!pl->ob->contr->state) 3389 if (!pl->ob->contr->ns->state)
3395 change_luck (pl->ob, 0); 3390 change_luck (pl->ob, 0);
3396} 3391}
3397 3392
3398 3393
3399/* cast_dust() - handles op throwing objects of type 'DUST'. 3394/* cast_dust() - handles op throwing objects of type 'DUST'.
3453 object *tmp = NULL; 3448 object *tmp = NULL;
3454 3449
3455 if (QUERY_FLAG (&op->arch->clone, FLAG_UNDEAD)) 3450 if (QUERY_FLAG (&op->arch->clone, FLAG_UNDEAD))
3456 return 1; 3451 return 1;
3457 3452
3458 if (op->type == PLAYER)
3459 for (tmp = op->inv; tmp; tmp = tmp->below)
3460 if (tmp->type == EXPERIENCE && tmp->stats.Wis)
3461 if (QUERY_FLAG (tmp, FLAG_UNDEAD))
3462 return 1;
3463 return 0; 3453 return 0;
3464} 3454}
3465 3455
3466/* look at the surrounding terrain to determine 3456/* look at the surrounding terrain to determine
3467 * the hideability of this object. Positive levels 3457 * the hideability of this object. Positive levels
3582 if (mflags & P_OUT_OF_MAP) 3572 if (mflags & P_OUT_OF_MAP)
3583 continue; 3573 continue;
3584 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)))
3585 continue; 3575 continue;
3586 3576
3587 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)
3588 { 3578 {
3589 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))
3590 return 1; 3580 return 1;
3591 else if (tmp->type == PLAYER) 3581 else if (tmp->type == PLAYER)
3592 { 3582 {
3646 3636
3647 /* only the viewable area the player sees is updated by LOS 3637 /* only the viewable area the player sees is updated by LOS
3648 * 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
3649 * for any meaningful values. 3639 * for any meaningful values.
3650 */ 3640 */
3651 if (FABS (dx) <= (pl->contr->socket.mapx / 2) && 3641 if (FABS (dx) <= (pl->contr->ns->mapx / 2) &&
3652 FABS (dy) <= (pl->contr->socket.mapy / 2) && 3642 FABS (dy) <= (pl->contr->ns->mapy / 2) &&
3653 !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)])
3654 return 1; 3644 return 1;
3655 op = op->more; 3645 op = op->more;
3656 } 3646 }
3657 return 0; 3647 return 0;
3658} 3648}
3844 { 3834 {
3845 /* forces in the treasurelist can alter the player's stats */ 3835 /* forces in the treasurelist can alter the player's stats */
3846 object *skin; 3836 object *skin;
3847 3837
3848 /* first get the dragon skin force */ 3838 /* first get the dragon skin force */
3839 shstr_cmp dragon_skin_force ("dragon_skin_force");
3849 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
3850 if (skin == NULL) 3843 if (!skin)
3851 return; 3844 return;
3852 3845
3853 /* adding new spellpath attunements */ 3846 /* adding new spellpath attunements */
3854 if (item->path_attuned > 0 && !(skin->path_attuned & item->path_attuned)) 3847 if (item->path_attuned > 0 && !(skin->path_attuned & item->path_attuned))
3855 { 3848 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines