… | |
… | |
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> |
… | |
… | |
206 | * the one that is passed. |
204 | * the one that is passed. |
207 | */ |
205 | */ |
208 | static player * |
206 | static player * |
209 | get_player (player *p) |
207 | get_player (player *p) |
210 | { |
208 | { |
211 | object *op = arch_to_object (get_player_archetype (NULL)); |
209 | object *op = arch_to_object (get_player_archetype (0)); |
212 | int i; |
210 | 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 | |
211 | |
236 | /* Clears basically the entire player structure except |
212 | /* Clears basically the entire player structure except |
237 | * for next and socket. |
213 | * for next and socket. |
238 | */ |
214 | */ |
239 | p->clear (); |
215 | p->clear (); |
… | |
… | |
258 | op->speed_left = 0.5; |
234 | op->speed_left = 0.5; |
259 | op->speed = 1.0; |
235 | op->speed = 1.0; |
260 | op->direction = 5; /* So player faces south */ |
236 | op->direction = 5; /* So player faces south */ |
261 | op->stats.wc = 2; |
237 | op->stats.wc = 2; |
262 | op->run_away = 25; /* Then we panick... */ |
238 | op->run_away = 25; /* Then we panick... */ |
|
|
239 | |
|
|
240 | { |
|
|
241 | 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 */ |
242 | p->socket->monitor_spells = 0; /* Needed because esrv_update_spells( ) gets called by roll_stats */ |
264 | |
|
|
265 | roll_stats (op); |
243 | roll_stats (op); |
|
|
244 | p->socket->monitor_spells = oldmon; |
|
|
245 | } |
266 | p->state = ST_ROLL_STAT; |
246 | p->state = ST_ROLL_STAT; |
267 | clear_los (op); |
247 | clear_los (op); |
268 | |
248 | |
269 | p->gen_sp_armour = 10; |
249 | p->gen_sp_armour = 10; |
270 | p->last_speed = -1; |
250 | p->last_speed = -1; |
… | |
… | |
292 | for (i = 0; i < NUM_SKILLS; i++) |
272 | for (i = 0; i < NUM_SKILLS; i++) |
293 | { |
273 | { |
294 | p->last_skill_exp[i] = -1; |
274 | p->last_skill_exp[i] = -1; |
295 | p->last_skill_ob[i] = NULL; |
275 | p->last_skill_ob[i] = NULL; |
296 | } |
276 | } |
|
|
277 | |
297 | for (i = 0; i < NROFATTACKS; i++) |
278 | for (i = 0; i < NROFATTACKS; i++) |
298 | { |
|
|
299 | p->last_resist[i] = -1; |
279 | p->last_resist[i] = -1; |
300 | } |
280 | |
301 | p->last_stats.exp = -1; |
281 | p->last_stats.exp = -1; |
302 | p->last_weight = (uint32) - 1; |
282 | p->last_weight = (uint32) - 1; |
303 | |
283 | |
304 | p->socket.update_look = 0; |
284 | p->socket->update_look = 0; |
305 | p->socket.look_position = 0; |
285 | p->socket->look_position = 0; |
|
|
286 | |
306 | return p; |
287 | return p; |
307 | } |
288 | } |
308 | |
289 | |
309 | /* This loads the first map an puts the player on it. */ |
290 | /* This loads the first map an puts the player on it. */ |
310 | static void |
291 | static void |
… | |
… | |
320 | * All we can really get in this is some settings like host and display |
301 | * All we can really get in this is some settings like host and display |
321 | * mode. |
302 | * mode. |
322 | */ |
303 | */ |
323 | |
304 | |
324 | int |
305 | int |
325 | add_player (client_socket * ns) |
306 | add_player (client_socket *ns) |
326 | { |
307 | { |
327 | player *p; |
308 | player *p = new player; |
328 | |
309 | |
329 | p = get_player (NULL); |
|
|
330 | p->socket = *ns; |
310 | p->socket = ns; |
331 | p->socket.faces_sent = (uint8 *) malloc (p->socket.faces_sent_len * sizeof (*p->socket.faces_sent)); |
311 | ns->pl = p; |
332 | |
312 | |
333 | if (p->socket.faces_sent == NULL) |
313 | p->next = first_player; |
334 | fatal (OUT_OF_MEMORY); |
314 | first_player = p; |
335 | |
315 | |
336 | memcpy (p->socket.faces_sent, ns->faces_sent, p->socket.faces_sent_len * sizeof (*p->socket.faces_sent)); |
316 | p = get_player (p); |
337 | /* Needed because the socket we just copied over needs to be cleared. |
317 | |
338 | * Note that this can result in a client reset if there is partial data |
|
|
339 | * on the uncoming socket. |
|
|
340 | */ |
|
|
341 | //TODO socket copying is EVIL, do not do this |
|
|
342 | p->socket.inbuf_len = 0; |
|
|
343 | set_first_map (p->ob); |
318 | set_first_map (p->ob); |
344 | |
319 | |
345 | CLEAR_FLAG (p->ob, FLAG_FRIENDLY); |
320 | CLEAR_FLAG (p->ob, FLAG_FRIENDLY); |
346 | add_friendly_object (p->ob); |
321 | add_friendly_object (p->ob); |
347 | send_rules (p->ob); |
322 | send_rules (p->ob); |
… | |
… | |
715 | void |
690 | void |
716 | get_name (object *op) |
691 | get_name (object *op) |
717 | { |
692 | { |
718 | op->contr->write_buf[0] = '\0'; |
693 | op->contr->write_buf[0] = '\0'; |
719 | op->contr->state = ST_GET_NAME; |
694 | op->contr->state = ST_GET_NAME; |
720 | send_query (&op->contr->socket, 0, "What is your name?\n:"); |
695 | send_query (op->contr->socket, 0, "What is your name?\n:"); |
721 | } |
696 | } |
722 | |
697 | |
723 | void |
698 | void |
724 | get_password (object *op) |
699 | get_password (object *op) |
725 | { |
700 | { |
726 | op->contr->write_buf[0] = '\0'; |
701 | op->contr->write_buf[0] = '\0'; |
727 | op->contr->state = ST_GET_PASSWORD; |
702 | op->contr->state = ST_GET_PASSWORD; |
728 | send_query (&op->contr->socket, CS_QUERY_HIDEINPUT, "What is your password?\n:"); |
703 | send_query (op->contr->socket, CS_QUERY_HIDEINPUT, "What is your password?\n:"); |
729 | } |
704 | } |
730 | |
705 | |
731 | void |
706 | void |
732 | play_again (object *op) |
707 | play_again (object *op) |
733 | { |
708 | { |
734 | op->contr->state = ST_PLAY_AGAIN; |
709 | op->contr->state = ST_PLAY_AGAIN; |
735 | op->chosen_skill = NULL; |
710 | op->chosen_skill = NULL; |
736 | send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "Do you want to play again (a/q)?"); |
711 | send_query (op->contr->socket, CS_QUERY_SINGLECHAR, "Do you want to play again (a/q)?"); |
737 | /* a bit of a hack, but there are various places early in th |
712 | /* a bit of a hack, but there are various places early in th |
738 | * player creation process that a user can quit (eg, roll |
713 | * player creation process that a user can quit (eg, roll |
739 | * stats) that isn't removing the player. Taking a quick |
714 | * stats) that isn't removing the player. Taking a quick |
740 | * look, there are many places that call play_again without |
715 | * look, there are many places that call play_again without |
741 | * removing the player - it probably makes more sense |
716 | * removing the player - it probably makes more sense |
… | |
… | |
790 | confirm_password (object *op) |
765 | confirm_password (object *op) |
791 | { |
766 | { |
792 | |
767 | |
793 | op->contr->write_buf[0] = '\0'; |
768 | op->contr->write_buf[0] = '\0'; |
794 | op->contr->state = ST_CONFIRM_PASSWORD; |
769 | op->contr->state = ST_CONFIRM_PASSWORD; |
795 | send_query (&op->contr->socket, CS_QUERY_HIDEINPUT, "Please type your password again.\n:"); |
770 | send_query (op->contr->socket, CS_QUERY_HIDEINPUT, "Please type your password again.\n:"); |
796 | } |
771 | } |
797 | |
772 | |
798 | void |
773 | void |
799 | get_party_password (object *op, partylist *party) |
774 | get_party_password (object *op, partylist *party) |
800 | { |
775 | { |
… | |
… | |
804 | return; |
779 | return; |
805 | } |
780 | } |
806 | op->contr->write_buf[0] = '\0'; |
781 | op->contr->write_buf[0] = '\0'; |
807 | op->contr->state = ST_GET_PARTY_PASSWORD; |
782 | op->contr->state = ST_GET_PARTY_PASSWORD; |
808 | op->contr->party_to_join = party; |
783 | op->contr->party_to_join = party; |
809 | send_query (&op->contr->socket, CS_QUERY_HIDEINPUT, "What is the password?\n:"); |
784 | send_query (op->contr->socket, CS_QUERY_HIDEINPUT, "What is the password?\n:"); |
810 | } |
785 | } |
811 | |
786 | |
812 | |
787 | |
813 | /* This rolls four 1-6 rolls and sums the best 3 of the 4. */ |
788 | /* This rolls four 1-6 rolls and sums the best 3 of the 4. */ |
814 | int |
789 | int |
… | |
… | |
911 | |
886 | |
912 | void |
887 | void |
913 | Roll_Again (object *op) |
888 | Roll_Again (object *op) |
914 | { |
889 | { |
915 | esrv_new_player (op->contr, 0); |
890 | esrv_new_player (op->contr, 0); |
916 | send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, |
891 | send_query (op->contr->socket, CS_QUERY_SINGLECHAR, |
917 | "[y] to roll new stats [n] to use stats\n[1-7] [1-7] to swap stats.\nRoll again (y/n/1-7)? "); |
892 | "[y] to roll new stats [n] to use stats\n[1-7] [1-7] to swap stats.\nRoll again (y/n/1-7)? "); |
918 | } |
893 | } |
919 | |
894 | |
920 | void |
895 | void |
921 | Swap_Stat (object *op, int Swap_Second) |
896 | Swap_Stat (object *op, int Swap_Second) |
… | |
… | |
988 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
963 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
989 | } |
964 | } |
990 | else |
965 | else |
991 | Swap_Stat (op, stat_trans[keynum]); |
966 | Swap_Stat (op, stat_trans[keynum]); |
992 | |
967 | |
993 | send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, ""); |
968 | send_query (op->contr->socket, CS_QUERY_SINGLECHAR, ""); |
994 | return 1; |
969 | return 1; |
995 | } |
970 | } |
996 | switch (key) |
971 | switch (key) |
997 | { |
972 | { |
998 | case 'n': |
973 | case 'n': |
… | |
… | |
1012 | enter_exit (op, NULL); |
987 | enter_exit (op, NULL); |
1013 | #endif |
988 | #endif |
1014 | SET_ANIMATION (op, 2); /* So player faces south */ |
989 | SET_ANIMATION (op, 2); /* So player faces south */ |
1015 | /* Enter exit adds a player otherwise */ |
990 | /* Enter exit adds a player otherwise */ |
1016 | add_statbonus (op); |
991 | add_statbonus (op); |
1017 | send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, |
992 | send_query (op->contr->socket, CS_QUERY_SINGLECHAR, |
1018 | "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n"); |
993 | "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n"); |
1019 | op->contr->state = ST_CHANGE_CLASS; |
994 | op->contr->state = ST_CHANGE_CLASS; |
1020 | if (op->msg) |
995 | if (op->msg) |
1021 | new_draw_info (NDI_BLUE, 0, op, op->msg); |
996 | new_draw_info (NDI_BLUE, 0, op, op->msg); |
1022 | return 0; |
997 | return 0; |
1023 | } |
998 | } |
1024 | case 'y': |
999 | case 'y': |
1025 | case 'Y': |
1000 | case 'Y': |
1026 | roll_stats (op); |
1001 | roll_stats (op); |
1027 | send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, ""); |
1002 | send_query (op->contr->socket, CS_QUERY_SINGLECHAR, ""); |
1028 | return 1; |
1003 | return 1; |
1029 | |
1004 | |
1030 | case 'q': |
1005 | case 'q': |
1031 | case 'Q': |
1006 | case 'Q': |
1032 | play_again (op); |
1007 | play_again (op); |
1033 | return 1; |
1008 | return 1; |
1034 | |
1009 | |
1035 | default: |
1010 | default: |
1036 | send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "Yes, No, Quit or 1-6. Roll again?"); |
1011 | send_query (op->contr->socket, CS_QUERY_SINGLECHAR, "Yes, No, Quit or 1-6. Roll again?"); |
1037 | return 0; |
1012 | return 0; |
1038 | } |
1013 | } |
1039 | return 0; |
1014 | return 0; |
1040 | } |
1015 | } |
1041 | |
1016 | |
… | |
… | |
1151 | op->stats.grace = 0; |
1126 | op->stats.grace = 0; |
1152 | |
1127 | |
1153 | if (op->msg) |
1128 | if (op->msg) |
1154 | new_draw_info (NDI_BLUE, 0, op, op->msg); |
1129 | new_draw_info (NDI_BLUE, 0, op, op->msg); |
1155 | |
1130 | |
1156 | send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "Press any key for the next race.\nPress `d' to play this race.\n"); |
1131 | send_query (op->contr->socket, CS_QUERY_SINGLECHAR, "Press any key for the next race.\nPress `d' to play this race.\n"); |
1157 | return 0; |
1132 | return 0; |
1158 | } |
1133 | } |
1159 | |
1134 | |
1160 | int |
1135 | int |
1161 | key_confirm_quit (object *op, char key) |
1136 | key_confirm_quit (object *op, char key) |
… | |
… | |
1904 | SET_ANIMATION (arrow, arrow->direction); |
1879 | SET_ANIMATION (arrow, arrow->direction); |
1905 | arrow->stats.sp = arrow->stats.wc; /* save original wc and dam */ |
1880 | arrow->stats.sp = arrow->stats.wc; /* save original wc and dam */ |
1906 | arrow->stats.hp = arrow->stats.dam; |
1881 | arrow->stats.hp = arrow->stats.dam; |
1907 | arrow->stats.grace = arrow->attacktype; |
1882 | arrow->stats.grace = arrow->attacktype; |
1908 | if (arrow->slaying != NULL) |
1883 | if (arrow->slaying != NULL) |
1909 | arrow->spellarg = strdup_local (arrow->slaying); |
1884 | arrow->spellarg = strdup (arrow->slaying); |
1910 | |
1885 | |
1911 | /* Note that this was different for monsters - they got their level |
1886 | /* Note that this was different for monsters - they got their level |
1912 | * added to the damage. I think the strength bonus is more proper. |
1887 | * added to the damage. I think the strength bonus is more proper. |
1913 | */ |
1888 | */ |
1914 | |
1889 | |
… | |
… | |
2570 | |
2545 | |
2571 | /* call this here - we also will call this in do_ericserver, but |
2546 | /* call this here - we also will call this in do_ericserver, but |
2572 | * the players time has been increased when doericserver has been |
2547 | * the players time has been increased when doericserver has been |
2573 | * called, so we recheck it here. |
2548 | * called, so we recheck it here. |
2574 | */ |
2549 | */ |
2575 | HandleClient (&op->contr->socket, op->contr); |
2550 | HandleClient (op->contr->socket, op->contr); |
2576 | if (op->speed_left < 0) |
2551 | if (op->speed_left < 0) |
2577 | return 0; |
2552 | return 0; |
2578 | |
2553 | |
2579 | if (op->direction && (op->contr->run_on || op->contr->fire_on)) |
2554 | if (op->direction && (op->contr->run_on || op->contr->fire_on)) |
2580 | { |
2555 | { |
… | |
… | |
3650 | |
3625 | |
3651 | /* only the viewable area the player sees is updated by LOS |
3626 | /* only the viewable area the player sees is updated by LOS |
3652 | * code, so we need to restrict ourselves to that range of values |
3627 | * code, so we need to restrict ourselves to that range of values |
3653 | * for any meaningful values. |
3628 | * for any meaningful values. |
3654 | */ |
3629 | */ |
3655 | if (FABS (dx) <= (pl->contr->socket.mapx / 2) && |
3630 | if (FABS (dx) <= (pl->contr->socket->mapx / 2) && |
3656 | FABS (dy) <= (pl->contr->socket.mapy / 2) && |
3631 | FABS (dy) <= (pl->contr->socket->mapy / 2) && |
3657 | !pl->contr->blocked_los[dx + (pl->contr->socket.mapx / 2)][dy + (pl->contr->socket.mapy / 2)]) |
3632 | !pl->contr->blocked_los[dx + (pl->contr->socket->mapx / 2)][dy + (pl->contr->socket->mapy / 2)]) |
3658 | return 1; |
3633 | return 1; |
3659 | op = op->more; |
3634 | op = op->more; |
3660 | } |
3635 | } |
3661 | return 0; |
3636 | return 0; |
3662 | } |
3637 | } |