… | |
… | |
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... */ |
263 | p->socket.monitor_spells = 0; /* Needed because esrv_update_spells( ) gets called by roll_stats */ |
239 | p->socket->monitor_spells = 0; /* Needed because esrv_update_spells( ) gets called by roll_stats */ |
264 | |
240 | |
265 | roll_stats (op); |
241 | roll_stats (op); |
266 | p->state = ST_ROLL_STAT; |
242 | p->state = ST_ROLL_STAT; |
267 | clear_los (op); |
243 | clear_los (op); |
268 | |
244 | |
… | |
… | |
292 | for (i = 0; i < NUM_SKILLS; i++) |
268 | for (i = 0; i < NUM_SKILLS; i++) |
293 | { |
269 | { |
294 | p->last_skill_exp[i] = -1; |
270 | p->last_skill_exp[i] = -1; |
295 | p->last_skill_ob[i] = NULL; |
271 | p->last_skill_ob[i] = NULL; |
296 | } |
272 | } |
|
|
273 | |
297 | for (i = 0; i < NROFATTACKS; i++) |
274 | for (i = 0; i < NROFATTACKS; i++) |
298 | { |
|
|
299 | p->last_resist[i] = -1; |
275 | p->last_resist[i] = -1; |
300 | } |
276 | |
301 | p->last_stats.exp = -1; |
277 | p->last_stats.exp = -1; |
302 | p->last_weight = (uint32) - 1; |
278 | p->last_weight = (uint32) - 1; |
303 | |
279 | |
304 | p->socket.update_look = 0; |
280 | p->socket->update_look = 0; |
305 | p->socket.look_position = 0; |
281 | p->socket->look_position = 0; |
|
|
282 | |
306 | return p; |
283 | return p; |
307 | } |
284 | } |
308 | |
285 | |
309 | /* This loads the first map an puts the player on it. */ |
286 | /* This loads the first map an puts the player on it. */ |
310 | static void |
287 | static void |
… | |
… | |
320 | * All we can really get in this is some settings like host and display |
297 | * All we can really get in this is some settings like host and display |
321 | * mode. |
298 | * mode. |
322 | */ |
299 | */ |
323 | |
300 | |
324 | int |
301 | int |
325 | add_player (client_socket * ns) |
302 | add_player (client_socket *ns) |
326 | { |
303 | { |
327 | player *p; |
304 | player *p = new player; |
328 | |
305 | |
329 | p = get_player (NULL); |
|
|
330 | p->socket = *ns; |
306 | p->socket = ns; |
331 | p->socket.faces_sent = (uint8 *) malloc (p->socket.faces_sent_len * sizeof (*p->socket.faces_sent)); |
307 | ns->pl = p; |
332 | |
308 | |
333 | if (p->socket.faces_sent == NULL) |
309 | p->next = first_player; |
334 | fatal (OUT_OF_MEMORY); |
310 | first_player = p; |
335 | |
311 | |
336 | memcpy (p->socket.faces_sent, ns->faces_sent, p->socket.faces_sent_len * sizeof (*p->socket.faces_sent)); |
312 | p = get_player (p); |
337 | /* Needed because the socket we just copied over needs to be cleared. |
313 | |
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); |
314 | set_first_map (p->ob); |
344 | |
315 | |
345 | CLEAR_FLAG (p->ob, FLAG_FRIENDLY); |
316 | CLEAR_FLAG (p->ob, FLAG_FRIENDLY); |
346 | add_friendly_object (p->ob); |
317 | add_friendly_object (p->ob); |
347 | send_rules (p->ob); |
318 | send_rules (p->ob); |
… | |
… | |
715 | void |
686 | void |
716 | get_name (object *op) |
687 | get_name (object *op) |
717 | { |
688 | { |
718 | op->contr->write_buf[0] = '\0'; |
689 | op->contr->write_buf[0] = '\0'; |
719 | op->contr->state = ST_GET_NAME; |
690 | op->contr->state = ST_GET_NAME; |
720 | send_query (&op->contr->socket, 0, "What is your name?\n:"); |
691 | send_query (op->contr->socket, 0, "What is your name?\n:"); |
721 | } |
692 | } |
722 | |
693 | |
723 | void |
694 | void |
724 | get_password (object *op) |
695 | get_password (object *op) |
725 | { |
696 | { |
726 | op->contr->write_buf[0] = '\0'; |
697 | op->contr->write_buf[0] = '\0'; |
727 | op->contr->state = ST_GET_PASSWORD; |
698 | op->contr->state = ST_GET_PASSWORD; |
728 | send_query (&op->contr->socket, CS_QUERY_HIDEINPUT, "What is your password?\n:"); |
699 | send_query (op->contr->socket, CS_QUERY_HIDEINPUT, "What is your password?\n:"); |
729 | } |
700 | } |
730 | |
701 | |
731 | void |
702 | void |
732 | play_again (object *op) |
703 | play_again (object *op) |
733 | { |
704 | { |
734 | op->contr->state = ST_PLAY_AGAIN; |
705 | op->contr->state = ST_PLAY_AGAIN; |
735 | op->chosen_skill = NULL; |
706 | op->chosen_skill = NULL; |
736 | send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "Do you want to play again (a/q)?"); |
707 | 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 |
708 | /* a bit of a hack, but there are various places early in th |
738 | * player creation process that a user can quit (eg, roll |
709 | * player creation process that a user can quit (eg, roll |
739 | * stats) that isn't removing the player. Taking a quick |
710 | * stats) that isn't removing the player. Taking a quick |
740 | * look, there are many places that call play_again without |
711 | * look, there are many places that call play_again without |
741 | * removing the player - it probably makes more sense |
712 | * removing the player - it probably makes more sense |
… | |
… | |
790 | confirm_password (object *op) |
761 | confirm_password (object *op) |
791 | { |
762 | { |
792 | |
763 | |
793 | op->contr->write_buf[0] = '\0'; |
764 | op->contr->write_buf[0] = '\0'; |
794 | op->contr->state = ST_CONFIRM_PASSWORD; |
765 | op->contr->state = ST_CONFIRM_PASSWORD; |
795 | send_query (&op->contr->socket, CS_QUERY_HIDEINPUT, "Please type your password again.\n:"); |
766 | send_query (op->contr->socket, CS_QUERY_HIDEINPUT, "Please type your password again.\n:"); |
796 | } |
767 | } |
797 | |
768 | |
798 | void |
769 | void |
799 | get_party_password (object *op, partylist *party) |
770 | get_party_password (object *op, partylist *party) |
800 | { |
771 | { |
… | |
… | |
804 | return; |
775 | return; |
805 | } |
776 | } |
806 | op->contr->write_buf[0] = '\0'; |
777 | op->contr->write_buf[0] = '\0'; |
807 | op->contr->state = ST_GET_PARTY_PASSWORD; |
778 | op->contr->state = ST_GET_PARTY_PASSWORD; |
808 | op->contr->party_to_join = party; |
779 | op->contr->party_to_join = party; |
809 | send_query (&op->contr->socket, CS_QUERY_HIDEINPUT, "What is the password?\n:"); |
780 | send_query (op->contr->socket, CS_QUERY_HIDEINPUT, "What is the password?\n:"); |
810 | } |
781 | } |
811 | |
782 | |
812 | |
783 | |
813 | /* This rolls four 1-6 rolls and sums the best 3 of the 4. */ |
784 | /* This rolls four 1-6 rolls and sums the best 3 of the 4. */ |
814 | int |
785 | int |
… | |
… | |
911 | |
882 | |
912 | void |
883 | void |
913 | Roll_Again (object *op) |
884 | Roll_Again (object *op) |
914 | { |
885 | { |
915 | esrv_new_player (op->contr, 0); |
886 | esrv_new_player (op->contr, 0); |
916 | send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, |
887 | 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)? "); |
888 | "[y] to roll new stats [n] to use stats\n[1-7] [1-7] to swap stats.\nRoll again (y/n/1-7)? "); |
918 | } |
889 | } |
919 | |
890 | |
920 | void |
891 | void |
921 | Swap_Stat (object *op, int Swap_Second) |
892 | Swap_Stat (object *op, int Swap_Second) |
… | |
… | |
988 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
959 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
989 | } |
960 | } |
990 | else |
961 | else |
991 | Swap_Stat (op, stat_trans[keynum]); |
962 | Swap_Stat (op, stat_trans[keynum]); |
992 | |
963 | |
993 | send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, ""); |
964 | send_query (op->contr->socket, CS_QUERY_SINGLECHAR, ""); |
994 | return 1; |
965 | return 1; |
995 | } |
966 | } |
996 | switch (key) |
967 | switch (key) |
997 | { |
968 | { |
998 | case 'n': |
969 | case 'n': |
… | |
… | |
1012 | enter_exit (op, NULL); |
983 | enter_exit (op, NULL); |
1013 | #endif |
984 | #endif |
1014 | SET_ANIMATION (op, 2); /* So player faces south */ |
985 | SET_ANIMATION (op, 2); /* So player faces south */ |
1015 | /* Enter exit adds a player otherwise */ |
986 | /* Enter exit adds a player otherwise */ |
1016 | add_statbonus (op); |
987 | add_statbonus (op); |
1017 | send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, |
988 | 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"); |
989 | "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n"); |
1019 | op->contr->state = ST_CHANGE_CLASS; |
990 | op->contr->state = ST_CHANGE_CLASS; |
1020 | if (op->msg) |
991 | if (op->msg) |
1021 | new_draw_info (NDI_BLUE, 0, op, op->msg); |
992 | new_draw_info (NDI_BLUE, 0, op, op->msg); |
1022 | return 0; |
993 | return 0; |
1023 | } |
994 | } |
1024 | case 'y': |
995 | case 'y': |
1025 | case 'Y': |
996 | case 'Y': |
1026 | roll_stats (op); |
997 | roll_stats (op); |
1027 | send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, ""); |
998 | send_query (op->contr->socket, CS_QUERY_SINGLECHAR, ""); |
1028 | return 1; |
999 | return 1; |
1029 | |
1000 | |
1030 | case 'q': |
1001 | case 'q': |
1031 | case 'Q': |
1002 | case 'Q': |
1032 | play_again (op); |
1003 | play_again (op); |
1033 | return 1; |
1004 | return 1; |
1034 | |
1005 | |
1035 | default: |
1006 | default: |
1036 | send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "Yes, No, Quit or 1-6. Roll again?"); |
1007 | send_query (op->contr->socket, CS_QUERY_SINGLECHAR, "Yes, No, Quit or 1-6. Roll again?"); |
1037 | return 0; |
1008 | return 0; |
1038 | } |
1009 | } |
1039 | return 0; |
1010 | return 0; |
1040 | } |
1011 | } |
1041 | |
1012 | |
… | |
… | |
1151 | op->stats.grace = 0; |
1122 | op->stats.grace = 0; |
1152 | |
1123 | |
1153 | if (op->msg) |
1124 | if (op->msg) |
1154 | new_draw_info (NDI_BLUE, 0, op, op->msg); |
1125 | new_draw_info (NDI_BLUE, 0, op, op->msg); |
1155 | |
1126 | |
1156 | send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "Press any key for the next race.\nPress `d' to play this race.\n"); |
1127 | 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; |
1128 | return 0; |
1158 | } |
1129 | } |
1159 | |
1130 | |
1160 | int |
1131 | int |
1161 | key_confirm_quit (object *op, char key) |
1132 | key_confirm_quit (object *op, char key) |
… | |
… | |
2570 | |
2541 | |
2571 | /* call this here - we also will call this in do_ericserver, but |
2542 | /* call this here - we also will call this in do_ericserver, but |
2572 | * the players time has been increased when doericserver has been |
2543 | * the players time has been increased when doericserver has been |
2573 | * called, so we recheck it here. |
2544 | * called, so we recheck it here. |
2574 | */ |
2545 | */ |
2575 | HandleClient (&op->contr->socket, op->contr); |
2546 | HandleClient (op->contr->socket, op->contr); |
2576 | if (op->speed_left < 0) |
2547 | if (op->speed_left < 0) |
2577 | return 0; |
2548 | return 0; |
2578 | |
2549 | |
2579 | if (op->direction && (op->contr->run_on || op->contr->fire_on)) |
2550 | if (op->direction && (op->contr->run_on || op->contr->fire_on)) |
2580 | { |
2551 | { |
… | |
… | |
3650 | |
3621 | |
3651 | /* only the viewable area the player sees is updated by LOS |
3622 | /* only the viewable area the player sees is updated by LOS |
3652 | * code, so we need to restrict ourselves to that range of values |
3623 | * code, so we need to restrict ourselves to that range of values |
3653 | * for any meaningful values. |
3624 | * for any meaningful values. |
3654 | */ |
3625 | */ |
3655 | if (FABS (dx) <= (pl->contr->socket.mapx / 2) && |
3626 | if (FABS (dx) <= (pl->contr->socket->mapx / 2) && |
3656 | FABS (dy) <= (pl->contr->socket.mapy / 2) && |
3627 | FABS (dy) <= (pl->contr->socket->mapy / 2) && |
3657 | !pl->contr->blocked_los[dx + (pl->contr->socket.mapx / 2)][dy + (pl->contr->socket.mapy / 2)]) |
3628 | !pl->contr->blocked_los[dx + (pl->contr->socket->mapx / 2)][dy + (pl->contr->socket->mapy / 2)]) |
3658 | return 1; |
3629 | return 1; |
3659 | op = op->more; |
3630 | op = op->more; |
3660 | } |
3631 | } |
3661 | return 0; |
3632 | return 0; |
3662 | } |
3633 | } |