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.48 by root, Tue Dec 19 05:41:22 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->socket->monitor_spells; // what a hack
263 p->socket.monitor_spells = 0; /* Needed because esrv_update_spells( ) gets called by roll_stats */ 250 p->socket->monitor_spells = 0; /* Needed because esrv_update_spells( ) gets called by roll_stats */
264
265 roll_stats (op); 251 roll_stats (op);
252 p->socket->monitor_spells = oldmon;
253 }
266 p->state = ST_ROLL_STAT; 254 p->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;
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->socket->update_look = 0;
305 p->socket.look_position = 0; 292 p->socket->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
329 p = get_player (NULL);
330 p->socket = *ns; 317 p->socket = ns;
331 p->socket.faces_sent = (uint8 *) malloc (p->socket.faces_sent_len * sizeof (*p->socket.faces_sent)); 318 ns->pl = p;
332 319
333 if (p->socket.faces_sent == NULL) 320 p->next = first_player;
334 fatal (OUT_OF_MEMORY); 321 first_player = p;
335 322
336 memcpy (p->socket.faces_sent, ns->faces_sent, p->socket.faces_sent_len * sizeof (*p->socket.faces_sent)); 323 p = get_player (p);
337 /* Needed because the socket we just copied over needs to be cleared. 324
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);
365 { 348 {
366 if (at == NULL || at->next == NULL) 349 if (at == NULL || at->next == NULL)
367 at = first_archetype; 350 at = first_archetype;
368 else 351 else
369 at = at->next; 352 at = at->next;
353
370 if (at->clone.type == PLAYER) 354 if (at->clone.type == PLAYER)
371 return at; 355 return at;
356
372 if (at == start) 357 if (at == start)
373 { 358 {
374 LOG (llevError, "No Player archetypes\n"); 359 LOG (llevError, "No Player archetypes\n");
375 exit (-1); 360 exit (-1);
376 } 361 }
377 } 362 }
378} 363}
379
380 364
381object * 365object *
382get_nearest_player (object *mon) 366get_nearest_player (object *mon)
383{ 367{
384 object *op = NULL; 368 object *op = NULL;
714void 698void
715get_name (object *op) 699get_name (object *op)
716{ 700{
717 op->contr->write_buf[0] = '\0'; 701 op->contr->write_buf[0] = '\0';
718 op->contr->state = ST_GET_NAME; 702 op->contr->state = ST_GET_NAME;
719 send_query (&op->contr->socket, 0, "What is your name?\n:"); 703 send_query (op->contr->socket, 0, "What is your name?\n:");
720} 704}
721 705
722void 706void
723get_password (object *op) 707get_password (object *op)
724{ 708{
725 op->contr->write_buf[0] = '\0'; 709 op->contr->write_buf[0] = '\0';
726 op->contr->state = ST_GET_PASSWORD; 710 op->contr->state = ST_GET_PASSWORD;
727 send_query (&op->contr->socket, CS_QUERY_HIDEINPUT, "What is your password?\n:"); 711 send_query (op->contr->socket, CS_QUERY_HIDEINPUT, "What is your password?\n:");
728} 712}
729 713
730void 714void
731play_again (object *op) 715play_again (object *op)
732{ 716{
733 op->contr->state = ST_PLAY_AGAIN; 717 op->contr->state = ST_PLAY_AGAIN;
734 op->chosen_skill = NULL; 718 op->chosen_skill = NULL;
735 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "Do you want to play again (a/q)?"); 719 send_query (op->contr->socket, CS_QUERY_SINGLECHAR, "Do you want to play again (a/q)?");
736 /* a bit of a hack, but there are various places early in th 720 /* a bit of a hack, but there are various places early in th
737 * player creation process that a user can quit (eg, roll 721 * player creation process that a user can quit (eg, roll
738 * stats) that isn't removing the player. Taking a quick 722 * stats) that isn't removing the player. Taking a quick
739 * look, there are many places that call play_again without 723 * look, there are many places that call play_again without
740 * removing the player - it probably makes more sense 724 * removing the player - it probably makes more sense
789confirm_password (object *op) 773confirm_password (object *op)
790{ 774{
791 775
792 op->contr->write_buf[0] = '\0'; 776 op->contr->write_buf[0] = '\0';
793 op->contr->state = ST_CONFIRM_PASSWORD; 777 op->contr->state = ST_CONFIRM_PASSWORD;
794 send_query (&op->contr->socket, CS_QUERY_HIDEINPUT, "Please type your password again.\n:"); 778 send_query (op->contr->socket, CS_QUERY_HIDEINPUT, "Please type your password again.\n:");
795} 779}
796 780
797void 781void
798get_party_password (object *op, partylist *party) 782get_party_password (object *op, partylist *party)
799{ 783{
803 return; 787 return;
804 } 788 }
805 op->contr->write_buf[0] = '\0'; 789 op->contr->write_buf[0] = '\0';
806 op->contr->state = ST_GET_PARTY_PASSWORD; 790 op->contr->state = ST_GET_PARTY_PASSWORD;
807 op->contr->party_to_join = party; 791 op->contr->party_to_join = party;
808 send_query (&op->contr->socket, CS_QUERY_HIDEINPUT, "What is the password?\n:"); 792 send_query (op->contr->socket, CS_QUERY_HIDEINPUT, "What is the password?\n:");
809} 793}
810 794
811 795
812/* This rolls four 1-6 rolls and sums the best 3 of the 4. */ 796/* This rolls four 1-6 rolls and sums the best 3 of the 4. */
813int 797int
910 894
911void 895void
912Roll_Again (object *op) 896Roll_Again (object *op)
913{ 897{
914 esrv_new_player (op->contr, 0); 898 esrv_new_player (op->contr, 0);
915 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, 899 send_query (op->contr->socket, 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)? "); 900 "[y] to roll new stats [n] to use stats\n[1-7] [1-7] to swap stats.\nRoll again (y/n/1-7)? ");
917} 901}
918 902
919void 903void
920Swap_Stat (object *op, int Swap_Second) 904Swap_Stat (object *op, int Swap_Second)
987 new_draw_info (NDI_UNIQUE, 0, op, buf); 971 new_draw_info (NDI_UNIQUE, 0, op, buf);
988 } 972 }
989 else 973 else
990 Swap_Stat (op, stat_trans[keynum]); 974 Swap_Stat (op, stat_trans[keynum]);
991 975
992 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, ""); 976 send_query (op->contr->socket, CS_QUERY_SINGLECHAR, "");
993 return 1; 977 return 1;
994 } 978 }
995 switch (key) 979 switch (key)
996 { 980 {
997 case 'n': 981 case 'n':
1011 enter_exit (op, NULL); 995 enter_exit (op, NULL);
1012#endif 996#endif
1013 SET_ANIMATION (op, 2); /* So player faces south */ 997 SET_ANIMATION (op, 2); /* So player faces south */
1014 /* Enter exit adds a player otherwise */ 998 /* Enter exit adds a player otherwise */
1015 add_statbonus (op); 999 add_statbonus (op);
1016 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, 1000 send_query (op->contr->socket, CS_QUERY_SINGLECHAR,
1017 "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n"); 1001 "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n");
1018 op->contr->state = ST_CHANGE_CLASS; 1002 op->contr->state = ST_CHANGE_CLASS;
1019 if (op->msg) 1003 if (op->msg)
1020 new_draw_info (NDI_BLUE, 0, op, op->msg); 1004 new_draw_info (NDI_BLUE, 0, op, op->msg);
1021 return 0; 1005 return 0;
1022 } 1006 }
1023 case 'y': 1007 case 'y':
1024 case 'Y': 1008 case 'Y':
1025 roll_stats (op); 1009 roll_stats (op);
1026 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, ""); 1010 send_query (op->contr->socket, CS_QUERY_SINGLECHAR, "");
1027 return 1; 1011 return 1;
1028 1012
1029 case 'q': 1013 case 'q':
1030 case 'Q': 1014 case 'Q':
1031 play_again (op); 1015 play_again (op);
1032 return 1; 1016 return 1;
1033 1017
1034 default: 1018 default:
1035 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "Yes, No, Quit or 1-6. Roll again?"); 1019 send_query (op->contr->socket, CS_QUERY_SINGLECHAR, "Yes, No, Quit or 1-6. Roll again?");
1036 return 0; 1020 return 0;
1037 } 1021 }
1038 return 0; 1022 return 0;
1039} 1023}
1040 1024
1060 { 1044 {
1061 char buf[MAX_BUF]; 1045 char buf[MAX_BUF];
1062 1046
1063 /* this must before then initial items are given */ 1047 /* this must before then initial items are given */
1064 esrv_new_player (op->contr, op->weight + op->carrying); 1048 esrv_new_player (op->contr, op->weight + op->carrying);
1049
1065 create_treasure (find_treasurelist ("starting_wealth"), op, 0, 0, 0); 1050 treasurelist *tl = find_treasurelist ("starting_wealth");
1051 if (tl)
1052 create_treasure (tl, op, 0, 0, 0);
1066 1053
1067 INVOKE_PLAYER (BIRTH, op->contr); 1054 INVOKE_PLAYER (BIRTH, op->contr);
1068 INVOKE_PLAYER (LOGIN, op->contr); 1055 INVOKE_PLAYER (LOGIN, op->contr);
1069 1056
1070 op->contr->state = ST_PLAYING; 1057 op->contr->state = ST_PLAYING;
1105 * if the map isn't there, then stay on the 1092 * if the map isn't there, then stay on the
1106 * default initial map */ 1093 * default initial map */
1107 tmp->destroy (); 1094 tmp->destroy ();
1108 } 1095 }
1109 else 1096 else
1110 {
1111 LOG (llevDebug, "first_map_ext_path not set\n"); 1097 LOG (llevDebug, "first_map_ext_path not set\n");
1112 } 1098
1113 return 0; 1099 return 0;
1114 } 1100 }
1115 1101
1116 /* Following actually changes the race - this is the default command 1102 /* Following actually changes the race - this is the default command
1117 * if we don't match with one of the options above. 1103 * if we don't match with one of the options above.
1147 op->stats.grace = 0; 1133 op->stats.grace = 0;
1148 1134
1149 if (op->msg) 1135 if (op->msg)
1150 new_draw_info (NDI_BLUE, 0, op, op->msg); 1136 new_draw_info (NDI_BLUE, 0, op, op->msg);
1151 1137
1152 send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "Press any key for the next race.\nPress `d' to play this race.\n"); 1138 send_query (op->contr->socket, CS_QUERY_SINGLECHAR, "Press any key for the next race.\nPress `d' to play this race.\n");
1153 return 0; 1139 return 0;
1154} 1140}
1155 1141
1156int 1142int
1157key_confirm_quit (object *op, char key) 1143key_confirm_quit (object *op, char key)
1814 if (!dir) 1800 if (!dir)
1815 { 1801 {
1816 new_draw_info (NDI_UNIQUE, 0, op, "You can't shoot yourself!"); 1802 new_draw_info (NDI_UNIQUE, 0, op, "You can't shoot yourself!");
1817 return 0; 1803 return 0;
1818 } 1804 }
1805
1819 if (op->type == PLAYER) 1806 if (op->type == PLAYER)
1820 bow = op->contr->ranges[range_bow]; 1807 bow = op->contr->ranges[range_bow];
1821 else 1808 else
1822 { 1809 {
1823 for (bow = op->inv; bow; bow = bow->below) 1810 for (bow = op->inv; bow; bow = bow->below)
1831 { 1818 {
1832 LOG (llevError, "Range: bow without activated bow (%s).\n", &op->name); 1819 LOG (llevError, "Range: bow without activated bow (%s).\n", &op->name);
1833 return 0; 1820 return 0;
1834 } 1821 }
1835 } 1822 }
1823
1836 if (!bow->race || !bow->skill) 1824 if (!bow->race || !bow->skill)
1837 { 1825 {
1838 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s is broken.", &bow->name); 1826 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s is broken.", &bow->name);
1839 return 0; 1827 return 0;
1840 } 1828 }
1842 bowspeed = bow->stats.sp + dex_bonus[op->stats.Dex]; 1830 bowspeed = bow->stats.sp + dex_bonus[op->stats.Dex];
1843 1831
1844 /* penalize ROF for bestarrow */ 1832 /* penalize ROF for bestarrow */
1845 if (op->type == PLAYER && op->contr->bowtype == bow_bestarrow) 1833 if (op->type == PLAYER && op->contr->bowtype == bow_bestarrow)
1846 bowspeed -= dex_bonus[op->stats.Dex] + 5; 1834 bowspeed -= dex_bonus[op->stats.Dex] + 5;
1835
1847 if (bowspeed < 1) 1836 if (bowspeed < 1)
1848 bowspeed = 1; 1837 bowspeed = 1;
1849 1838
1850 if (arrow == NULL) 1839 if (arrow == NULL)
1851 { 1840 {
1857 else 1846 else
1858 CLEAR_FLAG (op, FLAG_READY_BOW); 1847 CLEAR_FLAG (op, FLAG_READY_BOW);
1859 return 0; 1848 return 0;
1860 } 1849 }
1861 } 1850 }
1851
1862 mflags = get_map_flags (op->map, &m, sx, sy, &sx, &sy); 1852 mflags = get_map_flags (op->map, &m, sx, sy, &sx, &sy);
1863 if (mflags & P_OUT_OF_MAP) 1853 if (mflags & P_OUT_OF_MAP)
1864 {
1865 return 0; 1854 return 0;
1866 } 1855
1867 if (GET_MAP_MOVE_BLOCK (m, sx, sy) == MOVE_FLY_LOW) 1856 if (GET_MAP_MOVE_BLOCK (m, sx, sy) == MOVE_FLY_LOW)
1868 { 1857 {
1869 new_draw_info (NDI_UNIQUE, 0, op, "Something is in the way."); 1858 new_draw_info (NDI_UNIQUE, 0, op, "Something is in the way.");
1870 return 0; 1859 return 0;
1871 } 1860 }
1877 return 0; 1866 return 0;
1878 } 1867 }
1879 1868
1880 left = arrow; /* these are arrows left to the player */ 1869 left = arrow; /* these are arrows left to the player */
1881 arrow = get_split_ob (arrow, 1); 1870 arrow = get_split_ob (arrow, 1);
1882 if (arrow == NULL) 1871 if (!arrow)
1883 { 1872 {
1884 new_draw_info_format (NDI_UNIQUE, 0, op, "You have no %s left.", &bow->race); 1873 new_draw_info_format (NDI_UNIQUE, 0, op, "You have no %s left.", &bow->race);
1885 return 0; 1874 return 0;
1886 } 1875 }
1887 set_owner (arrow, op); 1876
1877 arrow->set_owner (op);
1888 arrow->skill = bow->skill; 1878 arrow->skill = bow->skill;
1889 1879
1890 arrow->direction = dir; 1880 arrow->direction = dir;
1891 arrow->x = sx; 1881 arrow->x = sx;
1892 arrow->y = sy; 1882 arrow->y = sy;
1900 SET_ANIMATION (arrow, arrow->direction); 1890 SET_ANIMATION (arrow, arrow->direction);
1901 arrow->stats.sp = arrow->stats.wc; /* save original wc and dam */ 1891 arrow->stats.sp = arrow->stats.wc; /* save original wc and dam */
1902 arrow->stats.hp = arrow->stats.dam; 1892 arrow->stats.hp = arrow->stats.dam;
1903 arrow->stats.grace = arrow->attacktype; 1893 arrow->stats.grace = arrow->attacktype;
1904 if (arrow->slaying != NULL) 1894 if (arrow->slaying != NULL)
1905 arrow->spellarg = strdup_local (arrow->slaying); 1895 arrow->spellarg = strdup (arrow->slaying);
1906 1896
1907 /* Note that this was different for monsters - they got their level 1897 /* Note that this was different for monsters - they got their level
1908 * added to the damage. I think the strength bonus is more proper. 1898 * added to the damage. I think the strength bonus is more proper.
1909 */ 1899 */
1910 1900
1934 } 1924 }
1935 1925
1936 if (arrow->attacktype == AT_PHYSICAL) 1926 if (arrow->attacktype == AT_PHYSICAL)
1937 arrow->attacktype |= bow->attacktype; 1927 arrow->attacktype |= bow->attacktype;
1938 1928
1939 if (bow->slaying != NULL) 1929 if (bow->slaying)
1940 arrow->slaying = bow->slaying; 1930 arrow->slaying = bow->slaying;
1941 1931
1942 arrow->map = m; 1932 arrow->map = m;
1943 arrow->move_type = MOVE_FLY_LOW; 1933 arrow->move_type = MOVE_FLY_LOW;
1944 arrow->move_on = MOVE_FLY_LOW | MOVE_WALK; 1934 arrow->move_on = MOVE_FLY_LOW | MOVE_WALK;
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)
2566 2556
2567 /* call this here - we also will call this in do_ericserver, but 2557 /* call this here - we also will call this in do_ericserver, but
2568 * the players time has been increased when doericserver has been 2558 * the players time has been increased when doericserver has been
2569 * called, so we recheck it here. 2559 * called, so we recheck it here.
2570 */ 2560 */
2571 HandleClient (&op->contr->socket, op->contr); 2561 //TODO: better than handling 8 commands, use some more intelligent rate-limiting
2562 for (int rep = 8; --rep && op->contr->socket->handle_command (); )
2563 ;
2564
2572 if (op->speed_left < 0) 2565 if (op->speed_left < 0)
2573 return 0; 2566 return 0;
2574 2567
2575 if (op->direction && (op->contr->run_on || op->contr->fire_on)) 2568 if (op->direction && (op->contr->run_on || op->contr->fire_on))
2576 { 2569 {
2585 if (op->speed_left > 0) 2578 if (op->speed_left > 0)
2586 return 1; 2579 return 1;
2587 else 2580 else
2588 return 0; 2581 return 0;
2589 } 2582 }
2583
2590 return 0; 2584 return 0;
2591} 2585}
2592 2586
2593int 2587int
2594save_life (object *op) 2588save_life (object *op)
2595{ 2589{
2596 object *tmp;
2597
2598 if (!QUERY_FLAG (op, FLAG_LIFESAVE)) 2590 if (!QUERY_FLAG (op, FLAG_LIFESAVE))
2599 return 0; 2591 return 0;
2600 2592
2601 for (tmp = op->inv; tmp != NULL; tmp = tmp->below) 2593 for (object *tmp = op->inv; tmp; tmp = tmp->below)
2602 if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE)) 2594 if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE))
2603 { 2595 {
2604 play_sound_map (op->map, op->x, op->y, SOUND_OB_EVAPORATE); 2596 play_sound_map (op->map, op->x, op->y, SOUND_OB_EVAPORATE);
2605 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s vibrates violently, then evaporates.", query_name (tmp)); 2597 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s vibrates violently, then evaporates.", query_name (tmp));
2606 2598
2617 op->stats.food = 999; 2609 op->stats.food = 999;
2618 2610
2619 fix_player (op); 2611 fix_player (op);
2620 return 1; 2612 return 1;
2621 } 2613 }
2614
2622 LOG (llevError, "Error: LIFESAVE set without applied object.\n"); 2615 LOG (llevError, "Error: LIFESAVE set without applied object.\n");
2623 CLEAR_FLAG (op, FLAG_LIFESAVE); 2616 CLEAR_FLAG (op, FLAG_LIFESAVE);
2624 enter_player_savebed (op); /* bring him home. */ 2617 enter_player_savebed (op); /* bring him home. */
2625 return 0; 2618 return 0;
2626} 2619}
2649 esrv_del_item (env->contr, op->count); 2642 esrv_del_item (env->contr, op->count);
2650 insert_ob_in_map (op, env->map, NULL, 0); 2643 insert_ob_in_map (op, env->map, NULL, 0);
2651 } 2644 }
2652 else if (op->inv) 2645 else if (op->inv)
2653 remove_unpaid_objects (op->inv, env); 2646 remove_unpaid_objects (op->inv, env);
2647
2654 op = next; 2648 op = next;
2655 } 2649 }
2656} 2650}
2657 2651
2658 2652
2673 strcpy (buf2, " R.I.P.\n\n"); 2667 strcpy (buf2, " R.I.P.\n\n");
2674 if (op->type == PLAYER) 2668 if (op->type == PLAYER)
2675 sprintf (buf, "%s the %s\n", &op->name, op->contr->title); 2669 sprintf (buf, "%s the %s\n", &op->name, op->contr->title);
2676 else 2670 else
2677 sprintf (buf, "%s\n", &op->name); 2671 sprintf (buf, "%s\n", &op->name);
2672
2678 strncat (buf2, " ", 20 - strlen (buf) / 2); 2673 strncat (buf2, " ", 20 - strlen (buf) / 2);
2679 strcat (buf2, buf); 2674 strcat (buf2, buf);
2680 if (op->type == PLAYER) 2675 if (op->type == PLAYER)
2681 sprintf (buf, "who was in level %d when killed\n", op->level); 2676 sprintf (buf, "who was in level %d when killed\n", op->level);
2682 else 2677 else
2683 sprintf (buf, "who was in level %d when died.\n\n", op->level); 2678 sprintf (buf, "who was in level %d when died.\n\n", op->level);
2679
2684 strncat (buf2, " ", 20 - strlen (buf) / 2); 2680 strncat (buf2, " ", 20 - strlen (buf) / 2);
2685 strcat (buf2, buf); 2681 strcat (buf2, buf);
2686 if (op->type == PLAYER) 2682 if (op->type == PLAYER)
2687 { 2683 {
2688 sprintf (buf, "by %s.\n\n", op->contr->killer); 2684 sprintf (buf, "by %s.\n\n", op->contr->killer);
2689 strncat (buf2, " ", 21 - strlen (buf) / 2); 2685 strncat (buf2, " ", 21 - strlen (buf) / 2);
2690 strcat (buf2, buf); 2686 strcat (buf2, buf);
2691 } 2687 }
2688
2692 strftime (buf, MAX_BUF, "%b %d %Y\n", localtime (&now)); 2689 strftime (buf, MAX_BUF, "%b %d %Y\n", localtime (&now));
2693 strncat (buf2, " ", 20 - strlen (buf) / 2); 2690 strncat (buf2, " ", 20 - strlen (buf) / 2);
2694 strcat (buf2, buf); 2691 strcat (buf2, buf);
2692
2695 return buf2; 2693 return buf2;
2696} 2694}
2697 2695
2698 2696
2699 2697
3646 3644
3647 /* only the viewable area the player sees is updated by LOS 3645 /* only the viewable area the player sees is updated by LOS
3648 * code, so we need to restrict ourselves to that range of values 3646 * code, so we need to restrict ourselves to that range of values
3649 * for any meaningful values. 3647 * for any meaningful values.
3650 */ 3648 */
3651 if (FABS (dx) <= (pl->contr->socket.mapx / 2) && 3649 if (FABS (dx) <= (pl->contr->socket->mapx / 2) &&
3652 FABS (dy) <= (pl->contr->socket.mapy / 2) && 3650 FABS (dy) <= (pl->contr->socket->mapy / 2) &&
3653 !pl->contr->blocked_los[dx + (pl->contr->socket.mapx / 2)][dy + (pl->contr->socket.mapy / 2)]) 3651 !pl->contr->blocked_los[dx + (pl->contr->socket->mapx / 2)][dy + (pl->contr->socket->mapy / 2)])
3654 return 1; 3652 return 1;
3655 op = op->more; 3653 op = op->more;
3656 } 3654 }
3657 return 0; 3655 return 0;
3658} 3656}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines