… | |
… | |
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 |
37 | extern int same_party (partylist *a, partylist *b); |
34 | extern int same_party (partylist *a, partylist *b); |
38 | #endif |
35 | #endif |
39 | |
36 | |
… | |
… | |
206 | * the one that is passed. |
203 | * the one that is passed. |
207 | */ |
204 | */ |
208 | static player * |
205 | static player * |
209 | get_player (player *p) |
206 | get_player (player *p) |
210 | { |
207 | { |
211 | object *op = arch_to_object (get_player_archetype (NULL)); |
208 | object *op = arch_to_object (get_player_archetype (0)); |
212 | int i; |
209 | 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 | |
210 | |
236 | /* Clears basically the entire player structure except |
211 | /* Clears basically the entire player structure except |
237 | * for next and socket. |
212 | * for next and socket. |
238 | */ |
213 | */ |
239 | p->clear (); |
214 | p->clear (); |
… | |
… | |
258 | op->speed_left = 0.5; |
233 | op->speed_left = 0.5; |
259 | op->speed = 1.0; |
234 | op->speed = 1.0; |
260 | op->direction = 5; /* So player faces south */ |
235 | op->direction = 5; /* So player faces south */ |
261 | op->stats.wc = 2; |
236 | op->stats.wc = 2; |
262 | op->run_away = 25; /* Then we panick... */ |
237 | op->run_away = 25; /* Then we panick... */ |
|
|
238 | |
|
|
239 | { |
|
|
240 | 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 */ |
241 | p->socket->monitor_spells = 0; /* Needed because esrv_update_spells( ) gets called by roll_stats */ |
264 | |
|
|
265 | roll_stats (op); |
242 | roll_stats (op); |
|
|
243 | p->socket->monitor_spells = oldmon; |
|
|
244 | } |
266 | p->state = ST_ROLL_STAT; |
245 | p->state = ST_ROLL_STAT; |
267 | clear_los (op); |
246 | clear_los (op); |
268 | |
247 | |
269 | p->gen_sp_armour = 10; |
248 | p->gen_sp_armour = 10; |
270 | p->last_speed = -1; |
249 | p->last_speed = -1; |
… | |
… | |
292 | for (i = 0; i < NUM_SKILLS; i++) |
271 | for (i = 0; i < NUM_SKILLS; i++) |
293 | { |
272 | { |
294 | p->last_skill_exp[i] = -1; |
273 | p->last_skill_exp[i] = -1; |
295 | p->last_skill_ob[i] = NULL; |
274 | p->last_skill_ob[i] = NULL; |
296 | } |
275 | } |
|
|
276 | |
297 | for (i = 0; i < NROFATTACKS; i++) |
277 | for (i = 0; i < NROFATTACKS; i++) |
298 | { |
|
|
299 | p->last_resist[i] = -1; |
278 | p->last_resist[i] = -1; |
300 | } |
279 | |
301 | p->last_stats.exp = -1; |
280 | p->last_stats.exp = -1; |
302 | p->last_weight = (uint32) - 1; |
281 | p->last_weight = (uint32) - 1; |
303 | |
282 | |
304 | p->socket.update_look = 0; |
283 | p->socket->update_look = 0; |
305 | p->socket.look_position = 0; |
284 | p->socket->look_position = 0; |
|
|
285 | |
306 | return p; |
286 | return p; |
307 | } |
287 | } |
308 | |
288 | |
309 | /* This loads the first map an puts the player on it. */ |
289 | /* This loads the first map an puts the player on it. */ |
310 | static void |
290 | static void |
… | |
… | |
320 | * All we can really get in this is some settings like host and display |
300 | * All we can really get in this is some settings like host and display |
321 | * mode. |
301 | * mode. |
322 | */ |
302 | */ |
323 | |
303 | |
324 | int |
304 | int |
325 | add_player (NewSocket * ns) |
305 | add_player (client *ns) |
326 | { |
306 | { |
327 | player *p; |
307 | player *p = new player; |
328 | |
308 | |
329 | p = get_player (NULL); |
|
|
330 | p->socket = *ns; |
309 | p->socket = ns; |
331 | p->socket.faces_sent = (uint8 *) malloc (p->socket.faces_sent_len * sizeof (*p->socket.faces_sent)); |
310 | ns->pl = p; |
332 | |
311 | |
333 | if (p->socket.faces_sent == NULL) |
312 | p->next = first_player; |
334 | fatal (OUT_OF_MEMORY); |
313 | first_player = p; |
335 | |
314 | |
336 | memcpy (p->socket.faces_sent, ns->faces_sent, p->socket.faces_sent_len * sizeof (*p->socket.faces_sent)); |
315 | p = get_player (p); |
337 | /* Needed because the socket we just copied over needs to be cleared. |
316 | |
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); |
317 | set_first_map (p->ob); |
343 | |
318 | |
344 | CLEAR_FLAG (p->ob, FLAG_FRIENDLY); |
319 | CLEAR_FLAG (p->ob, FLAG_FRIENDLY); |
345 | add_friendly_object (p->ob); |
320 | add_friendly_object (p->ob); |
346 | send_rules (p->ob); |
321 | send_rules (p->ob); |
… | |
… | |
644 | (op->type == ARMOUR || op->type == BOOTS || |
619 | (op->type == ARMOUR || op->type == BOOTS || |
645 | op->type == CLOAK || op->type == HELMET || |
620 | op->type == CLOAK || op->type == HELMET || |
646 | op->type == SHIELD || op->type == GLOVES || |
621 | op->type == SHIELD || op->type == GLOVES || |
647 | op->type == BRACERS || op->type == GIRDLE)) || (!QUERY_FLAG (pl, FLAG_USE_WEAPON) && op->type == WEAPON)) |
622 | op->type == BRACERS || op->type == GIRDLE)) || (!QUERY_FLAG (pl, FLAG_USE_WEAPON) && op->type == WEAPON)) |
648 | { |
623 | { |
649 | op->remove (); |
|
|
650 | op->destroy (0); |
624 | op->destroy (); |
651 | continue; |
625 | continue; |
652 | } |
626 | } |
653 | } |
627 | } |
654 | |
628 | |
655 | /* This really needs to be better - we should really give |
629 | /* This really needs to be better - we should really give |
… | |
… | |
666 | if (tmp->type == op->type && tmp->name == op->name) |
640 | if (tmp->type == op->type && tmp->name == op->name) |
667 | break; |
641 | break; |
668 | |
642 | |
669 | if (tmp) |
643 | if (tmp) |
670 | { |
644 | { |
671 | op->remove (); |
|
|
672 | op->destroy (0); |
645 | op->destroy (); |
673 | LOG (llevError, "give_initial_items: Removing duplicate object %s\n", &tmp->name); |
646 | LOG (llevError, "give_initial_items: Removing duplicate object %s\n", &tmp->name); |
674 | continue; |
647 | continue; |
675 | } |
648 | } |
|
|
649 | |
676 | if (op->nrof > 1) |
650 | if (op->nrof > 1) |
677 | op->nrof = 1; |
651 | op->nrof = 1; |
678 | } |
652 | } |
679 | |
653 | |
680 | if (op->type == SPELLBOOK && op->inv) |
654 | if (op->type == SPELLBOOK && op->inv) |
… | |
… | |
692 | CLEAR_FLAG (op, FLAG_CURSED); |
666 | CLEAR_FLAG (op, FLAG_CURSED); |
693 | CLEAR_FLAG (op, FLAG_DAMNED); |
667 | CLEAR_FLAG (op, FLAG_DAMNED); |
694 | } |
668 | } |
695 | if (op->type == SPELL) |
669 | if (op->type == SPELL) |
696 | { |
670 | { |
697 | op->remove (); |
|
|
698 | op->destroy (0); |
671 | op->destroy (); |
699 | continue; |
672 | continue; |
700 | } |
673 | } |
701 | else if (op->type == SKILL) |
674 | else if (op->type == SKILL) |
702 | { |
675 | { |
703 | SET_FLAG (op, FLAG_CAN_USE_SKILL); |
676 | SET_FLAG (op, FLAG_CAN_USE_SKILL); |
… | |
… | |
716 | void |
689 | void |
717 | get_name (object *op) |
690 | get_name (object *op) |
718 | { |
691 | { |
719 | op->contr->write_buf[0] = '\0'; |
692 | op->contr->write_buf[0] = '\0'; |
720 | op->contr->state = ST_GET_NAME; |
693 | op->contr->state = ST_GET_NAME; |
721 | send_query (&op->contr->socket, 0, "What is your name?\n:"); |
694 | send_query (op->contr->socket, 0, "What is your name?\n:"); |
722 | } |
695 | } |
723 | |
696 | |
724 | void |
697 | void |
725 | get_password (object *op) |
698 | get_password (object *op) |
726 | { |
699 | { |
727 | op->contr->write_buf[0] = '\0'; |
700 | op->contr->write_buf[0] = '\0'; |
728 | op->contr->state = ST_GET_PASSWORD; |
701 | op->contr->state = ST_GET_PASSWORD; |
729 | send_query (&op->contr->socket, CS_QUERY_HIDEINPUT, "What is your password?\n:"); |
702 | send_query (op->contr->socket, CS_QUERY_HIDEINPUT, "What is your password?\n:"); |
730 | } |
703 | } |
731 | |
704 | |
732 | void |
705 | void |
733 | play_again (object *op) |
706 | play_again (object *op) |
734 | { |
707 | { |
735 | op->contr->state = ST_PLAY_AGAIN; |
708 | op->contr->state = ST_PLAY_AGAIN; |
736 | op->chosen_skill = NULL; |
709 | op->chosen_skill = NULL; |
737 | send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "Do you want to play again (a/q)?"); |
710 | send_query (op->contr->socket, CS_QUERY_SINGLECHAR, "Do you want to play again (a/q)?"); |
738 | /* a bit of a hack, but there are various places early in th |
711 | /* a bit of a hack, but there are various places early in th |
739 | * player creation process that a user can quit (eg, roll |
712 | * player creation process that a user can quit (eg, roll |
740 | * stats) that isn't removing the player. Taking a quick |
713 | * stats) that isn't removing the player. Taking a quick |
741 | * look, there are many places that call play_again without |
714 | * look, there are many places that call play_again without |
742 | * removing the player - it probably makes more sense |
715 | * removing the player - it probably makes more sense |
… | |
… | |
791 | confirm_password (object *op) |
764 | confirm_password (object *op) |
792 | { |
765 | { |
793 | |
766 | |
794 | op->contr->write_buf[0] = '\0'; |
767 | op->contr->write_buf[0] = '\0'; |
795 | op->contr->state = ST_CONFIRM_PASSWORD; |
768 | op->contr->state = ST_CONFIRM_PASSWORD; |
796 | send_query (&op->contr->socket, CS_QUERY_HIDEINPUT, "Please type your password again.\n:"); |
769 | send_query (op->contr->socket, CS_QUERY_HIDEINPUT, "Please type your password again.\n:"); |
797 | } |
770 | } |
798 | |
771 | |
799 | void |
772 | void |
800 | get_party_password (object *op, partylist *party) |
773 | get_party_password (object *op, partylist *party) |
801 | { |
774 | { |
… | |
… | |
805 | return; |
778 | return; |
806 | } |
779 | } |
807 | op->contr->write_buf[0] = '\0'; |
780 | op->contr->write_buf[0] = '\0'; |
808 | op->contr->state = ST_GET_PARTY_PASSWORD; |
781 | op->contr->state = ST_GET_PARTY_PASSWORD; |
809 | op->contr->party_to_join = party; |
782 | op->contr->party_to_join = party; |
810 | send_query (&op->contr->socket, CS_QUERY_HIDEINPUT, "What is the password?\n:"); |
783 | send_query (op->contr->socket, CS_QUERY_HIDEINPUT, "What is the password?\n:"); |
811 | } |
784 | } |
812 | |
785 | |
813 | |
786 | |
814 | /* This rolls four 1-6 rolls and sums the best 3 of the 4. */ |
787 | /* This rolls four 1-6 rolls and sums the best 3 of the 4. */ |
815 | int |
788 | int |
… | |
… | |
912 | |
885 | |
913 | void |
886 | void |
914 | Roll_Again (object *op) |
887 | Roll_Again (object *op) |
915 | { |
888 | { |
916 | esrv_new_player (op->contr, 0); |
889 | esrv_new_player (op->contr, 0); |
917 | send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, |
890 | send_query (op->contr->socket, CS_QUERY_SINGLECHAR, |
918 | "[y] to roll new stats [n] to use stats\n[1-7] [1-7] to swap stats.\nRoll again (y/n/1-7)? "); |
891 | "[y] to roll new stats [n] to use stats\n[1-7] [1-7] to swap stats.\nRoll again (y/n/1-7)? "); |
919 | } |
892 | } |
920 | |
893 | |
921 | void |
894 | void |
922 | Swap_Stat (object *op, int Swap_Second) |
895 | Swap_Stat (object *op, int Swap_Second) |
… | |
… | |
989 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
962 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
990 | } |
963 | } |
991 | else |
964 | else |
992 | Swap_Stat (op, stat_trans[keynum]); |
965 | Swap_Stat (op, stat_trans[keynum]); |
993 | |
966 | |
994 | send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, ""); |
967 | send_query (op->contr->socket, CS_QUERY_SINGLECHAR, ""); |
995 | return 1; |
968 | return 1; |
996 | } |
969 | } |
997 | switch (key) |
970 | switch (key) |
998 | { |
971 | { |
999 | case 'n': |
972 | case 'n': |
… | |
… | |
1013 | enter_exit (op, NULL); |
986 | enter_exit (op, NULL); |
1014 | #endif |
987 | #endif |
1015 | SET_ANIMATION (op, 2); /* So player faces south */ |
988 | SET_ANIMATION (op, 2); /* So player faces south */ |
1016 | /* Enter exit adds a player otherwise */ |
989 | /* Enter exit adds a player otherwise */ |
1017 | add_statbonus (op); |
990 | add_statbonus (op); |
1018 | send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, |
991 | send_query (op->contr->socket, CS_QUERY_SINGLECHAR, |
1019 | "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n"); |
992 | "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n"); |
1020 | op->contr->state = ST_CHANGE_CLASS; |
993 | op->contr->state = ST_CHANGE_CLASS; |
1021 | if (op->msg) |
994 | if (op->msg) |
1022 | new_draw_info (NDI_BLUE, 0, op, op->msg); |
995 | new_draw_info (NDI_BLUE, 0, op, op->msg); |
1023 | return 0; |
996 | return 0; |
1024 | } |
997 | } |
1025 | case 'y': |
998 | case 'y': |
1026 | case 'Y': |
999 | case 'Y': |
1027 | roll_stats (op); |
1000 | roll_stats (op); |
1028 | send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, ""); |
1001 | send_query (op->contr->socket, CS_QUERY_SINGLECHAR, ""); |
1029 | return 1; |
1002 | return 1; |
1030 | |
1003 | |
1031 | case 'q': |
1004 | case 'q': |
1032 | case 'Q': |
1005 | case 'Q': |
1033 | play_again (op); |
1006 | play_again (op); |
1034 | return 1; |
1007 | return 1; |
1035 | |
1008 | |
1036 | default: |
1009 | default: |
1037 | send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "Yes, No, Quit or 1-6. Roll again?"); |
1010 | send_query (op->contr->socket, CS_QUERY_SINGLECHAR, "Yes, No, Quit or 1-6. Roll again?"); |
1038 | return 0; |
1011 | return 0; |
1039 | } |
1012 | } |
1040 | return 0; |
1013 | return 0; |
1041 | } |
1014 | } |
1042 | |
1015 | |
… | |
… | |
1062 | { |
1035 | { |
1063 | char buf[MAX_BUF]; |
1036 | char buf[MAX_BUF]; |
1064 | |
1037 | |
1065 | /* this must before then initial items are given */ |
1038 | /* this must before then initial items are given */ |
1066 | esrv_new_player (op->contr, op->weight + op->carrying); |
1039 | esrv_new_player (op->contr, op->weight + op->carrying); |
|
|
1040 | |
1067 | create_treasure (find_treasurelist ("starting_wealth"), op, 0, 0, 0); |
1041 | treasurelist *tl = find_treasurelist ("starting_wealth"); |
|
|
1042 | if (tl) |
|
|
1043 | create_treasure (tl, op, 0, 0, 0); |
1068 | |
1044 | |
1069 | INVOKE_PLAYER (BIRTH, op->contr); |
1045 | INVOKE_PLAYER (BIRTH, op->contr); |
1070 | INVOKE_PLAYER (LOGIN, op->contr); |
1046 | INVOKE_PLAYER (LOGIN, op->contr); |
1071 | |
1047 | |
1072 | op->contr->state = ST_PLAYING; |
1048 | op->contr->state = ST_PLAYING; |
… | |
… | |
1097 | { |
1073 | { |
1098 | object *tmp; |
1074 | object *tmp; |
1099 | char mapname[MAX_BUF]; |
1075 | char mapname[MAX_BUF]; |
1100 | |
1076 | |
1101 | snprintf (mapname, MAX_BUF - 1, "%s/%s", first_map_ext_path, &op->arch->name); |
1077 | snprintf (mapname, MAX_BUF - 1, "%s/%s", first_map_ext_path, &op->arch->name); |
1102 | tmp = get_object (); |
1078 | tmp = object::create (); |
1103 | EXIT_PATH (tmp) = mapname; |
1079 | EXIT_PATH (tmp) = mapname; |
1104 | EXIT_X (tmp) = op->x; |
1080 | EXIT_X (tmp) = op->x; |
1105 | EXIT_Y (tmp) = op->y; |
1081 | EXIT_Y (tmp) = op->y; |
1106 | enter_exit (op, tmp); /* we don't really care if it succeeded; |
1082 | enter_exit (op, tmp); /* we don't really care if it succeeded; |
1107 | * if the map isn't there, then stay on the |
1083 | * if the map isn't there, then stay on the |
1108 | * default initial map */ |
1084 | * default initial map */ |
1109 | tmp->destroy (0); |
1085 | tmp->destroy (); |
1110 | } |
1086 | } |
1111 | else |
1087 | else |
1112 | { |
1088 | { |
1113 | LOG (llevDebug, "first_map_ext_path not set\n"); |
1089 | LOG (llevDebug, "first_map_ext_path not set\n"); |
1114 | } |
1090 | } |
… | |
… | |
1126 | int x = op->x, y = op->y; |
1102 | int x = op->x, y = op->y; |
1127 | |
1103 | |
1128 | remove_statbonus (op); |
1104 | remove_statbonus (op); |
1129 | op->remove (); |
1105 | op->remove (); |
1130 | op->arch = get_player_archetype (op->arch); |
1106 | op->arch = get_player_archetype (op->arch); |
1131 | copy_object (&op->arch->clone, op); |
1107 | op->arch->clone.copy_to (op); |
1132 | op->instantiate (); |
1108 | op->instantiate (); |
1133 | op->stats = op->contr->orig_stats; |
1109 | op->stats = op->contr->orig_stats; |
1134 | op->name = op->name_pl = name; |
1110 | op->name = op->name_pl = name; |
1135 | op->x = x; |
1111 | op->x = x; |
1136 | op->y = y; |
1112 | op->y = y; |
… | |
… | |
1149 | op->stats.grace = 0; |
1125 | op->stats.grace = 0; |
1150 | |
1126 | |
1151 | if (op->msg) |
1127 | if (op->msg) |
1152 | new_draw_info (NDI_BLUE, 0, op, op->msg); |
1128 | new_draw_info (NDI_BLUE, 0, op, op->msg); |
1153 | |
1129 | |
1154 | send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "Press any key for the next race.\nPress `d' to play this race.\n"); |
1130 | send_query (op->contr->socket, CS_QUERY_SINGLECHAR, "Press any key for the next race.\nPress `d' to play this race.\n"); |
1155 | return 0; |
1131 | return 0; |
1156 | } |
1132 | } |
1157 | |
1133 | |
1158 | int |
1134 | int |
1159 | key_confirm_quit (object *op, char key) |
1135 | key_confirm_quit (object *op, char key) |
… | |
… | |
1873 | } |
1849 | } |
1874 | |
1850 | |
1875 | /* this should not happen, but sometimes does */ |
1851 | /* this should not happen, but sometimes does */ |
1876 | if (arrow->nrof == 0) |
1852 | if (arrow->nrof == 0) |
1877 | { |
1853 | { |
1878 | arrow->remove (); |
|
|
1879 | arrow->destroy (0); |
1854 | arrow->destroy (); |
1880 | return 0; |
1855 | return 0; |
1881 | } |
1856 | } |
1882 | |
1857 | |
1883 | left = arrow; /* these are arrows left to the player */ |
1858 | left = arrow; /* these are arrows left to the player */ |
1884 | arrow = get_split_ob (arrow, 1); |
1859 | arrow = get_split_ob (arrow, 1); |
1885 | if (arrow == NULL) |
1860 | if (arrow == NULL) |
1886 | { |
1861 | { |
1887 | new_draw_info_format (NDI_UNIQUE, 0, op, "You have no %s left.", &bow->race); |
1862 | new_draw_info_format (NDI_UNIQUE, 0, op, "You have no %s left.", &bow->race); |
1888 | return 0; |
1863 | return 0; |
1889 | } |
1864 | } |
1890 | set_owner (arrow, op); |
1865 | arrow->set_owner (op); |
1891 | arrow->skill = bow->skill; |
1866 | arrow->skill = bow->skill; |
1892 | |
1867 | |
1893 | arrow->direction = dir; |
1868 | arrow->direction = dir; |
1894 | arrow->x = sx; |
1869 | arrow->x = sx; |
1895 | arrow->y = sy; |
1870 | arrow->y = sy; |
… | |
… | |
1903 | SET_ANIMATION (arrow, arrow->direction); |
1878 | SET_ANIMATION (arrow, arrow->direction); |
1904 | arrow->stats.sp = arrow->stats.wc; /* save original wc and dam */ |
1879 | arrow->stats.sp = arrow->stats.wc; /* save original wc and dam */ |
1905 | arrow->stats.hp = arrow->stats.dam; |
1880 | arrow->stats.hp = arrow->stats.dam; |
1906 | arrow->stats.grace = arrow->attacktype; |
1881 | arrow->stats.grace = arrow->attacktype; |
1907 | if (arrow->slaying != NULL) |
1882 | if (arrow->slaying != NULL) |
1908 | arrow->spellarg = strdup_local (arrow->slaying); |
1883 | arrow->spellarg = strdup (arrow->slaying); |
1909 | |
1884 | |
1910 | /* Note that this was different for monsters - they got their level |
1885 | /* Note that this was different for monsters - they got their level |
1911 | * added to the damage. I think the strength bonus is more proper. |
1886 | * added to the damage. I think the strength bonus is more proper. |
1912 | */ |
1887 | */ |
1913 | |
1888 | |
… | |
… | |
2362 | * player owns it and it is either friendly or unagressive. |
2337 | * player owns it and it is either friendly or unagressive. |
2363 | */ |
2338 | */ |
2364 | if ((op->type == PLAYER) |
2339 | if ((op->type == PLAYER) |
2365 | #if COZY_SERVER |
2340 | #if COZY_SERVER |
2366 | && |
2341 | && |
2367 | ((get_owner (mon) && get_owner (mon)->contr |
2342 | ((mon->owner && mon->owner->contr |
2368 | && same_party (get_owner (mon)->contr->party, op->contr->party)) || get_owner (mon) == op) |
2343 | && same_party (mon->owner->contr->party, op->contr->party)) || mon->owner == op) |
2369 | #else |
2344 | #else |
2370 | && get_owner (mon) == op |
2345 | && mon->owner == op |
2371 | #endif |
2346 | #endif |
2372 | && (QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY))) |
2347 | && (QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY))) |
2373 | { |
2348 | { |
2374 | /* If we're braced, we don't want to switch places with it */ |
2349 | /* If we're braced, we don't want to switch places with it */ |
2375 | if (op->contr->braced) |
2350 | if (op->contr->braced) |
… | |
… | |
2569 | |
2544 | |
2570 | /* call this here - we also will call this in do_ericserver, but |
2545 | /* call this here - we also will call this in do_ericserver, but |
2571 | * the players time has been increased when doericserver has been |
2546 | * the players time has been increased when doericserver has been |
2572 | * called, so we recheck it here. |
2547 | * called, so we recheck it here. |
2573 | */ |
2548 | */ |
2574 | HandleClient (&op->contr->socket, op->contr); |
2549 | op->contr->socket->handle_command (); |
2575 | if (op->speed_left < 0) |
2550 | if (op->speed_left < 0) |
2576 | return 0; |
2551 | return 0; |
2577 | |
2552 | |
2578 | if (op->direction && (op->contr->run_on || op->contr->fire_on)) |
2553 | if (op->direction && (op->contr->run_on || op->contr->fire_on)) |
2579 | { |
2554 | { |
… | |
… | |
2588 | if (op->speed_left > 0) |
2563 | if (op->speed_left > 0) |
2589 | return 1; |
2564 | return 1; |
2590 | else |
2565 | else |
2591 | return 0; |
2566 | return 0; |
2592 | } |
2567 | } |
|
|
2568 | |
2593 | return 0; |
2569 | return 0; |
2594 | } |
2570 | } |
2595 | |
2571 | |
2596 | int |
2572 | int |
2597 | save_life (object *op) |
2573 | save_life (object *op) |
2598 | { |
2574 | { |
2599 | object *tmp; |
|
|
2600 | |
|
|
2601 | if (!QUERY_FLAG (op, FLAG_LIFESAVE)) |
2575 | if (!QUERY_FLAG (op, FLAG_LIFESAVE)) |
2602 | return 0; |
2576 | return 0; |
2603 | |
2577 | |
2604 | for (tmp = op->inv; tmp != NULL; tmp = tmp->below) |
2578 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
2605 | if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE)) |
2579 | if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE)) |
2606 | { |
2580 | { |
2607 | play_sound_map (op->map, op->x, op->y, SOUND_OB_EVAPORATE); |
2581 | play_sound_map (op->map, op->x, op->y, SOUND_OB_EVAPORATE); |
2608 | new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s vibrates violently, then evaporates.", query_name (tmp)); |
2582 | new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s vibrates violently, then evaporates.", query_name (tmp)); |
|
|
2583 | |
2609 | if (op->contr) |
2584 | if (op->contr) |
2610 | esrv_del_item (op->contr, tmp->count); |
2585 | esrv_del_item (op->contr, tmp->count); |
2611 | tmp->remove (); |
2586 | |
2612 | tmp->destroy (0); |
2587 | tmp->destroy (); |
2613 | CLEAR_FLAG (op, FLAG_LIFESAVE); |
2588 | CLEAR_FLAG (op, FLAG_LIFESAVE); |
|
|
2589 | |
2614 | if (op->stats.hp < 0) |
2590 | if (op->stats.hp < 0) |
2615 | op->stats.hp = op->stats.maxhp; |
2591 | op->stats.hp = op->stats.maxhp; |
|
|
2592 | |
2616 | if (op->stats.food < 0) |
2593 | if (op->stats.food < 0) |
2617 | op->stats.food = 999; |
2594 | op->stats.food = 999; |
|
|
2595 | |
2618 | fix_player (op); |
2596 | fix_player (op); |
2619 | return 1; |
2597 | return 1; |
2620 | } |
2598 | } |
|
|
2599 | |
2621 | LOG (llevError, "Error: LIFESAVE set without applied object.\n"); |
2600 | LOG (llevError, "Error: LIFESAVE set without applied object.\n"); |
2622 | CLEAR_FLAG (op, FLAG_LIFESAVE); |
2601 | CLEAR_FLAG (op, FLAG_LIFESAVE); |
2623 | enter_player_savebed (op); /* bring him home. */ |
2602 | enter_player_savebed (op); /* bring him home. */ |
2624 | return 0; |
2603 | return 0; |
2625 | } |
2604 | } |
… | |
… | |
2648 | esrv_del_item (env->contr, op->count); |
2627 | esrv_del_item (env->contr, op->count); |
2649 | insert_ob_in_map (op, env->map, NULL, 0); |
2628 | insert_ob_in_map (op, env->map, NULL, 0); |
2650 | } |
2629 | } |
2651 | else if (op->inv) |
2630 | else if (op->inv) |
2652 | remove_unpaid_objects (op->inv, env); |
2631 | remove_unpaid_objects (op->inv, env); |
|
|
2632 | |
2653 | op = next; |
2633 | op = next; |
2654 | } |
2634 | } |
2655 | } |
2635 | } |
2656 | |
2636 | |
2657 | |
2637 | |
… | |
… | |
2672 | strcpy (buf2, " R.I.P.\n\n"); |
2652 | strcpy (buf2, " R.I.P.\n\n"); |
2673 | if (op->type == PLAYER) |
2653 | if (op->type == PLAYER) |
2674 | sprintf (buf, "%s the %s\n", &op->name, op->contr->title); |
2654 | sprintf (buf, "%s the %s\n", &op->name, op->contr->title); |
2675 | else |
2655 | else |
2676 | sprintf (buf, "%s\n", &op->name); |
2656 | sprintf (buf, "%s\n", &op->name); |
|
|
2657 | |
2677 | strncat (buf2, " ", 20 - strlen (buf) / 2); |
2658 | strncat (buf2, " ", 20 - strlen (buf) / 2); |
2678 | strcat (buf2, buf); |
2659 | strcat (buf2, buf); |
2679 | if (op->type == PLAYER) |
2660 | if (op->type == PLAYER) |
2680 | sprintf (buf, "who was in level %d when killed\n", op->level); |
2661 | sprintf (buf, "who was in level %d when killed\n", op->level); |
2681 | else |
2662 | else |
2682 | sprintf (buf, "who was in level %d when died.\n\n", op->level); |
2663 | sprintf (buf, "who was in level %d when died.\n\n", op->level); |
|
|
2664 | |
2683 | strncat (buf2, " ", 20 - strlen (buf) / 2); |
2665 | strncat (buf2, " ", 20 - strlen (buf) / 2); |
2684 | strcat (buf2, buf); |
2666 | strcat (buf2, buf); |
2685 | if (op->type == PLAYER) |
2667 | if (op->type == PLAYER) |
2686 | { |
2668 | { |
2687 | sprintf (buf, "by %s.\n\n", op->contr->killer); |
2669 | sprintf (buf, "by %s.\n\n", op->contr->killer); |
2688 | strncat (buf2, " ", 21 - strlen (buf) / 2); |
2670 | strncat (buf2, " ", 21 - strlen (buf) / 2); |
2689 | strcat (buf2, buf); |
2671 | strcat (buf2, buf); |
2690 | } |
2672 | } |
|
|
2673 | |
2691 | strftime (buf, MAX_BUF, "%b %d %Y\n", localtime (&now)); |
2674 | strftime (buf, MAX_BUF, "%b %d %Y\n", localtime (&now)); |
2692 | strncat (buf2, " ", 20 - strlen (buf) / 2); |
2675 | strncat (buf2, " ", 20 - strlen (buf) / 2); |
2693 | strcat (buf2, buf); |
2676 | strcat (buf2, buf); |
|
|
2677 | |
2694 | return buf2; |
2678 | return buf2; |
2695 | } |
2679 | } |
2696 | |
2680 | |
2697 | |
2681 | |
2698 | |
2682 | |
… | |
… | |
2946 | /* restore player */ |
2930 | /* restore player */ |
2947 | at = archetype::find ("poisoning"); |
2931 | at = archetype::find ("poisoning"); |
2948 | tmp = present_arch_in_ob (at, op); |
2932 | tmp = present_arch_in_ob (at, op); |
2949 | if (tmp) |
2933 | if (tmp) |
2950 | { |
2934 | { |
2951 | tmp->remove (); |
|
|
2952 | tmp->destroy (0); |
2935 | tmp->destroy (); |
2953 | new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed"); |
2936 | new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed"); |
2954 | } |
2937 | } |
2955 | |
2938 | |
2956 | at = archetype::find ("confusion"); |
2939 | at = archetype::find ("confusion"); |
2957 | tmp = present_arch_in_ob (at, op); |
2940 | tmp = present_arch_in_ob (at, op); |
2958 | if (tmp) |
2941 | if (tmp) |
2959 | { |
2942 | { |
2960 | tmp->remove (); |
|
|
2961 | tmp->destroy (0); |
2943 | tmp->destroy (); |
2962 | new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer"); |
2944 | new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer"); |
2963 | } |
2945 | } |
2964 | |
2946 | |
2965 | cure_disease (op, 0); /* remove any disease */ |
2947 | cure_disease (op, 0); /* remove any disease */ |
2966 | op->stats.hp = op->stats.maxhp; |
2948 | op->stats.hp = op->stats.maxhp; |
… | |
… | |
3176 | |
3158 | |
3177 | /* remove any poisoning and confusion the character may be suffering. */ |
3159 | /* remove any poisoning and confusion the character may be suffering. */ |
3178 | /* restore player */ |
3160 | /* restore player */ |
3179 | at = archetype::find ("poisoning"); |
3161 | at = archetype::find ("poisoning"); |
3180 | tmp = present_arch_in_ob (at, op); |
3162 | tmp = present_arch_in_ob (at, op); |
|
|
3163 | |
3181 | if (tmp) |
3164 | if (tmp) |
3182 | { |
3165 | { |
3183 | tmp->remove (); |
|
|
3184 | tmp->destroy (0); |
3166 | tmp->destroy (); |
3185 | new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed"); |
3167 | new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed"); |
3186 | } |
3168 | } |
3187 | |
3169 | |
3188 | at = archetype::find ("confusion"); |
3170 | at = archetype::find ("confusion"); |
3189 | tmp = present_arch_in_ob (at, op); |
3171 | tmp = present_arch_in_ob (at, op); |
3190 | if (tmp) |
3172 | if (tmp) |
3191 | { |
3173 | { |
3192 | tmp->remove (); |
|
|
3193 | tmp->destroy (0); |
3174 | tmp->destroy (); |
3194 | new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer"); |
3175 | new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer"); |
3195 | } |
3176 | } |
3196 | |
3177 | |
3197 | cure_disease (op, 0); /* remove any disease */ |
3178 | cure_disease (op, 0); /* remove any disease */ |
3198 | |
3179 | |
… | |
… | |
3273 | check_score (op); |
3254 | check_score (op); |
3274 | |
3255 | |
3275 | if (op->contr->ranges[range_golem]) |
3256 | if (op->contr->ranges[range_golem]) |
3276 | { |
3257 | { |
3277 | remove_friendly_object (op->contr->ranges[range_golem]); |
3258 | remove_friendly_object (op->contr->ranges[range_golem]); |
3278 | op->contr->ranges[range_golem]->remove (); |
|
|
3279 | op->contr->ranges[range_golem]->destroy (0); |
3259 | op->contr->ranges[range_golem]->destroy (); |
3280 | op->contr->ranges[range_golem] = 0; |
3260 | op->contr->ranges[range_golem] = 0; |
3281 | } |
3261 | } |
3282 | |
3262 | |
3283 | loot_object (op); /* Remove some of the items for good */ |
3263 | loot_object (op); /* Remove some of the items for good */ |
3284 | op->remove (); |
3264 | op->remove (); |
… | |
… | |
3353 | if (!QUERY_FLAG (tmp, FLAG_UNIQUE) && (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || QUERY_FLAG (tmp, FLAG_NO_DROP) || !(RANDOM () % 3))) |
3333 | if (!QUERY_FLAG (tmp, FLAG_UNIQUE) && (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || QUERY_FLAG (tmp, FLAG_NO_DROP) || !(RANDOM () % 3))) |
3354 | { |
3334 | { |
3355 | if (tmp->nrof > 1) |
3335 | if (tmp->nrof > 1) |
3356 | { |
3336 | { |
3357 | tmp2 = get_split_ob (tmp, 1 + RANDOM () % (tmp->nrof - 1)); |
3337 | tmp2 = get_split_ob (tmp, 1 + RANDOM () % (tmp->nrof - 1)); |
3358 | tmp2->destroy (0); |
3338 | tmp2->destroy (); |
3359 | insert_ob_in_map (tmp, op->map, NULL, 0); |
3339 | insert_ob_in_map (tmp, op->map, NULL, 0); |
3360 | } |
3340 | } |
3361 | else |
3341 | else |
3362 | tmp->destroy (0); |
3342 | tmp->destroy (); |
3363 | } |
3343 | } |
3364 | else |
3344 | else |
3365 | insert_ob_in_map (tmp, op->map, NULL, 0); |
3345 | insert_ob_in_map (tmp, op->map, NULL, 0); |
3366 | } |
3346 | } |
3367 | } |
3347 | } |
… | |
… | |
3432 | if (op->type == PLAYER) |
3412 | if (op->type == PLAYER) |
3433 | new_draw_info_format (NDI_UNIQUE, 0, op, "You cast %s.", &spob->name); |
3413 | new_draw_info_format (NDI_UNIQUE, 0, op, "You cast %s.", &spob->name); |
3434 | |
3414 | |
3435 | cast_spell (op, throw_ob, dir, spob, NULL); |
3415 | cast_spell (op, throw_ob, dir, spob, NULL); |
3436 | |
3416 | |
3437 | if (!QUERY_FLAG (throw_ob, FLAG_REMOVED)) |
|
|
3438 | throw_ob->remove (); |
|
|
3439 | throw_ob->destroy (0); |
3417 | throw_ob->destroy (); |
3440 | } |
3418 | } |
3441 | |
3419 | |
3442 | void |
3420 | void |
3443 | make_visible (object *op) |
3421 | make_visible (object *op) |
3444 | { |
3422 | { |
… | |
… | |
3651 | |
3629 | |
3652 | /* only the viewable area the player sees is updated by LOS |
3630 | /* only the viewable area the player sees is updated by LOS |
3653 | * code, so we need to restrict ourselves to that range of values |
3631 | * code, so we need to restrict ourselves to that range of values |
3654 | * for any meaningful values. |
3632 | * for any meaningful values. |
3655 | */ |
3633 | */ |
3656 | if (FABS (dx) <= (pl->contr->socket.mapx / 2) && |
3634 | if (FABS (dx) <= (pl->contr->socket->mapx / 2) && |
3657 | FABS (dy) <= (pl->contr->socket.mapy / 2) && |
3635 | FABS (dy) <= (pl->contr->socket->mapy / 2) && |
3658 | !pl->contr->blocked_los[dx + (pl->contr->socket.mapx / 2)][dy + (pl->contr->socket.mapy / 2)]) |
3636 | !pl->contr->blocked_los[dx + (pl->contr->socket->mapx / 2)][dy + (pl->contr->socket->mapy / 2)]) |
3659 | return 1; |
3637 | return 1; |
3660 | op = op->more; |
3638 | op = op->more; |
3661 | } |
3639 | } |
3662 | return 0; |
3640 | return 0; |
3663 | } |
3641 | } |