1 | /* |
1 | /* |
2 | * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Crossfire TRT is free software: you can redistribute it and/or modify |
8 | * Deliantra is free software: you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by |
9 | * it under the terms of the GNU General Public License as published by |
10 | * the Free Software Foundation, either version 3 of the License, or |
10 | * the Free Software Foundation, either version 3 of the License, or |
11 | * (at your option) any later version. |
11 | * (at your option) any later version. |
12 | * |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
… | |
… | |
16 | * GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the GNU General Public License |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 | * |
20 | * |
21 | * The authors can be reached via e-mail to <crossfire@schmorp.de> |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | */ |
22 | */ |
23 | |
23 | |
24 | #include <global.h> |
24 | #include <global.h> |
25 | #include <sproto.h> |
25 | #include <sproto.h> |
26 | #include <sounds.h> |
26 | #include <sounds.h> |
… | |
… | |
215 | |
215 | |
216 | /* make sure he's a player -- needed because of class change. */ |
216 | /* make sure he's a player -- needed because of class change. */ |
217 | ob->type = PLAYER; // we are paranoid |
217 | ob->type = PLAYER; // we are paranoid |
218 | ob->race = ob->arch->race; |
218 | ob->race = ob->arch->race; |
219 | |
219 | |
220 | ob->carrying = sum_weight (ob); |
220 | ob->update_weight (); |
221 | link_player_skills (ob); |
221 | link_player_skills (ob); |
222 | |
222 | |
223 | CLEAR_FLAG (ob, FLAG_NO_FIX_PLAYER); |
223 | CLEAR_FLAG (ob, FLAG_NO_FIX_PLAYER); |
224 | |
224 | |
225 | assign (title, ob->arch->object::name); |
225 | assign (title, ob->arch->object::name); |
… | |
… | |
239 | set_dragon_name (ob, abil, skin); |
239 | set_dragon_name (ob, abil, skin); |
240 | } |
240 | } |
241 | |
241 | |
242 | new_draw_info (NDI_UNIQUE, 0, ob, "Welcome Back!"); |
242 | new_draw_info (NDI_UNIQUE, 0, ob, "Welcome Back!"); |
243 | |
243 | |
244 | esrv_new_player (this, ob->weight + ob->carrying); |
244 | esrv_new_player (this); |
|
|
245 | |
|
|
246 | ob->update_stats (); |
|
|
247 | |
|
|
248 | ns->floorbox_update (); |
|
|
249 | esrv_send_inventory (ob, ob); |
|
|
250 | esrv_add_spells (this, 0); |
|
|
251 | |
|
|
252 | activate (); |
|
|
253 | |
|
|
254 | send_rules (ob); |
|
|
255 | send_news (ob); |
|
|
256 | display_motd (ob); |
|
|
257 | |
|
|
258 | INVOKE_PLAYER (CONNECT, this); |
|
|
259 | INVOKE_PLAYER (LOGIN, this); |
|
|
260 | } |
|
|
261 | |
|
|
262 | void |
|
|
263 | player::disconnect () |
|
|
264 | { |
|
|
265 | if (ob) |
|
|
266 | { |
|
|
267 | ob->close_container (); //TODO: client-specific |
|
|
268 | ob->drop_unpaid_items (); |
|
|
269 | } |
|
|
270 | |
|
|
271 | if (ns) |
|
|
272 | { |
|
|
273 | if (active) |
|
|
274 | INVOKE_PLAYER (LOGOUT, this, ARG_INT (0)); |
|
|
275 | |
|
|
276 | INVOKE_PLAYER (DISCONNECT, this); |
|
|
277 | |
|
|
278 | ns->reset_stats (); |
|
|
279 | ns->pl = 0; |
|
|
280 | ns = 0; |
|
|
281 | } |
|
|
282 | |
|
|
283 | observe = ob; |
|
|
284 | |
|
|
285 | deactivate (); |
|
|
286 | } |
|
|
287 | |
|
|
288 | // the need for this function can be explained |
|
|
289 | // by load_object not returning the object |
|
|
290 | void |
|
|
291 | player::set_object (object *op) |
|
|
292 | { |
|
|
293 | ob = observe = op; |
|
|
294 | ob->contr = this; /* this aren't yet in archetype */ |
|
|
295 | |
|
|
296 | ob->speed = 1.0f; |
|
|
297 | ob->speed_left = 0.5f; |
|
|
298 | |
|
|
299 | ob->direction = 5; /* So player faces south */ |
245 | |
300 | |
246 | ob->flag [FLAG_READY_WEAPON] = false; |
301 | ob->flag [FLAG_READY_WEAPON] = false; |
247 | ob->flag [FLAG_READY_SKILL] = false; |
302 | ob->flag [FLAG_READY_SKILL] = false; |
248 | ob->flag [FLAG_READY_BOW] = false; |
303 | ob->flag [FLAG_READY_BOW] = false; |
249 | |
304 | |
… | |
… | |
266 | combat_ob = op; |
321 | combat_ob = op; |
267 | break; |
322 | break; |
268 | } |
323 | } |
269 | |
324 | |
270 | ob->change_weapon (combat_ob ? combat_ob : ranged_ob); |
325 | ob->change_weapon (combat_ob ? combat_ob : ranged_ob); |
271 | ob->update_stats (); |
326 | ob->deactivate (); // change_Weapon activates, fix this better |
272 | |
|
|
273 | ns->floorbox_update (); |
|
|
274 | esrv_send_inventory (ob, ob); |
|
|
275 | esrv_add_spells (this, 0); |
|
|
276 | |
|
|
277 | activate (); |
|
|
278 | |
|
|
279 | send_rules (ob); |
|
|
280 | send_news (ob); |
|
|
281 | display_motd (ob); |
|
|
282 | |
|
|
283 | INVOKE_PLAYER (CONNECT, this); |
|
|
284 | INVOKE_PLAYER (LOGIN, this); |
|
|
285 | } |
|
|
286 | |
|
|
287 | void |
|
|
288 | player::disconnect () |
|
|
289 | { |
|
|
290 | if (ob) |
|
|
291 | { |
|
|
292 | ob->close_container (); //TODO: client-specific |
|
|
293 | ob->drop_unpaid_items (); |
|
|
294 | } |
|
|
295 | |
|
|
296 | if (ns) |
|
|
297 | { |
|
|
298 | if (active) |
|
|
299 | INVOKE_PLAYER (LOGOUT, this, ARG_INT (0)); |
|
|
300 | |
|
|
301 | INVOKE_PLAYER (DISCONNECT, this); |
|
|
302 | |
|
|
303 | ns->reset_stats (); |
|
|
304 | ns->pl = 0; |
|
|
305 | ns = 0; |
|
|
306 | } |
|
|
307 | |
|
|
308 | observe = ob; |
|
|
309 | |
|
|
310 | deactivate (); |
|
|
311 | } |
|
|
312 | |
|
|
313 | // the need for this function can be explained |
|
|
314 | // by load_object not returning the object |
|
|
315 | void |
|
|
316 | player::set_object (object *op) |
|
|
317 | { |
|
|
318 | ob = observe = op; |
|
|
319 | ob->contr = this; /* this aren't yet in archetype */ |
|
|
320 | |
|
|
321 | ob->speed = 1.0f; |
|
|
322 | ob->speed_left = 0.5f; |
|
|
323 | |
|
|
324 | ob->direction = 5; /* So player faces south */ |
|
|
325 | } |
327 | } |
326 | |
328 | |
327 | void |
329 | void |
328 | player::set_observe (object *op) |
330 | player::set_observe (object *op) |
329 | { |
331 | { |
… | |
… | |
402 | * Note: there MUST be at least one player archetype! |
404 | * Note: there MUST be at least one player archetype! |
403 | */ |
405 | */ |
404 | archetype * |
406 | archetype * |
405 | get_player_archetype (archetype *at) |
407 | get_player_archetype (archetype *at) |
406 | { |
408 | { |
|
|
409 | // archetypes could have been reloaded |
|
|
410 | archetype *nat = at ? archetype::find (at->archname) : archetypes [0]; |
|
|
411 | |
|
|
412 | if (!nat) |
|
|
413 | return at; |
|
|
414 | |
407 | archvec::iterator i = at ? archetypes.find (at) : archetypes.begin (); |
415 | archvec::iterator i = archetypes.find (nat); |
408 | |
416 | |
409 | for (;;) |
417 | for (;;) |
410 | { |
418 | { |
411 | if (++i == archetypes.end ()) |
419 | if (++i == archetypes.end ()) |
412 | i = archetypes.begin (); |
420 | i = archetypes.begin (); |
… | |
… | |
630 | |
638 | |
631 | return firstdir; |
639 | return firstdir; |
632 | } |
640 | } |
633 | |
641 | |
634 | void |
642 | void |
635 | give_initial_items (object *pl, treasurelist * items) |
643 | give_initial_items (object *pl, treasurelist *items) |
636 | { |
644 | { |
637 | object *op, *next = NULL; |
|
|
638 | |
|
|
639 | if (pl->randomitems != NULL) |
645 | if (pl->randomitems) |
640 | create_treasure (items, pl, GT_STARTEQUIP | GT_ONLY_GOOD, 1, 0); |
646 | create_treasure (items, pl, GT_STARTEQUIP | GT_ONLY_GOOD, 1, 0); |
641 | |
647 | |
642 | for (op = pl->inv; op; op = next) |
648 | for (object *next, *op = pl->inv; op; op = next) |
643 | { |
649 | { |
644 | next = op->below; |
650 | next = op->below; |
645 | |
651 | |
646 | /* Forces get applied per default, unless they have the |
652 | /* Forces get applied per default, unless they have the |
647 | * flag "neutral" set. Sorry but I can't think of a better way |
653 | * flag "neutral" set. Sorry but I can't think of a better way |
… | |
… | |
652 | /* we never give weapons/armour if these cannot be used |
658 | /* we never give weapons/armour if these cannot be used |
653 | * by this player due to race restrictions |
659 | * by this player due to race restrictions |
654 | */ |
660 | */ |
655 | if (pl->type == PLAYER) |
661 | if (pl->type == PLAYER) |
656 | { |
662 | { |
657 | if ((!QUERY_FLAG (pl, FLAG_USE_ARMOUR) && |
663 | if ((!QUERY_FLAG (pl, FLAG_USE_ARMOUR) |
|
|
664 | && |
658 | (op->type == ARMOUR || op->type == BOOTS || |
665 | (op->type == ARMOUR || op->type == BOOTS |
659 | op->type == CLOAK || op->type == HELMET || |
666 | || op->type == CLOAK || op->type == HELMET |
660 | op->type == SHIELD || op->type == GLOVES || |
667 | || op->type == SHIELD || op->type == GLOVES |
|
|
668 | || op->type == BRACERS || op->type == GIRDLE)) |
661 | op->type == BRACERS || op->type == GIRDLE)) || (!QUERY_FLAG (pl, FLAG_USE_WEAPON) && op->type == WEAPON)) |
669 | || (!QUERY_FLAG (pl, FLAG_USE_WEAPON) && op->type == WEAPON)) |
662 | { |
670 | { |
663 | op->destroy (); |
671 | op->destroy (); |
664 | continue; |
672 | continue; |
665 | } |
673 | } |
666 | } |
674 | } |
… | |
… | |
689 | if (op->nrof > 1) |
697 | if (op->nrof > 1) |
690 | op->nrof = 1; |
698 | op->nrof = 1; |
691 | } |
699 | } |
692 | |
700 | |
693 | if (op->type == SPELLBOOK && op->inv) |
701 | if (op->type == SPELLBOOK && op->inv) |
694 | { |
|
|
695 | CLEAR_FLAG (op->inv, FLAG_STARTEQUIP); |
702 | CLEAR_FLAG (op->inv, FLAG_STARTEQUIP); |
696 | } |
|
|
697 | |
703 | |
698 | /* Give starting characters identified, uncursed, and undamned |
704 | /* Give starting characters identified, uncursed, and undamned |
699 | * items. Just don't identify gold or silver, or it won't be |
705 | * items. Just don't identify gold or silver, or it won't be |
700 | * merged properly. |
706 | * merged properly. |
701 | */ |
707 | */ |
702 | if (need_identify (op)) |
708 | if (need_identify (op)) |
703 | { |
709 | { |
704 | SET_FLAG (op, FLAG_IDENTIFIED); |
710 | SET_FLAG (op, FLAG_IDENTIFIED); |
705 | CLEAR_FLAG (op, FLAG_CURSED); |
711 | CLEAR_FLAG (op, FLAG_CURSED); |
706 | CLEAR_FLAG (op, FLAG_DAMNED); |
712 | CLEAR_FLAG (op, FLAG_DAMNED); |
707 | } |
713 | } |
|
|
714 | |
708 | if (op->type == SPELL) |
715 | if (op->type == SPELL) |
709 | { |
716 | { |
710 | op->destroy (); |
717 | op->destroy (); |
711 | continue; |
718 | continue; |
712 | } |
719 | } |
… | |
… | |
714 | { |
721 | { |
715 | SET_FLAG (op, FLAG_CAN_USE_SKILL); |
722 | SET_FLAG (op, FLAG_CAN_USE_SKILL); |
716 | op->stats.exp = 0; |
723 | op->stats.exp = 0; |
717 | op->level = 1; |
724 | op->level = 1; |
718 | } |
725 | } |
719 | /* lock all 'normal items by default */ |
726 | else /* lock all 'normal items by default */ |
720 | else |
|
|
721 | SET_FLAG (op, FLAG_INV_LOCKED); |
727 | SET_FLAG (op, FLAG_INV_LOCKED); |
722 | } /* for loop of objects in player inv */ |
728 | } /* for loop of objects in player inv */ |
723 | |
729 | |
724 | /* Need to set up the skill pointers */ |
730 | /* Need to set up the skill pointers */ |
725 | link_player_skills (pl); |
731 | link_player_skills (pl); |
… | |
… | |
831 | static void |
837 | static void |
832 | start_info (object *op) |
838 | start_info (object *op) |
833 | { |
839 | { |
834 | char buf[MAX_BUF]; |
840 | char buf[MAX_BUF]; |
835 | |
841 | |
836 | sprintf (buf, "Welcome to Crossfire v%s!", VERSION); |
842 | sprintf (buf, "Welcome to Deliantra v%s!", VERSION); |
837 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
843 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
838 | //new_draw_info (NDI_UNIQUE, 0, op, "Press `?' for help"); |
|
|
839 | //new_draw_info (NDI_UNIQUE, 0, op, " "); |
|
|
840 | } |
844 | } |
841 | |
845 | |
842 | /* This function takes the key that is passed, and does the |
846 | /* This function takes the key that is passed, and does the |
843 | * appropriate action with it (change race, or other things). |
847 | * appropriate action with it (change race, or other things). |
844 | * The function name is for historical reasons - now we have |
848 | * The function name is for historical reasons - now we have |
… | |
… | |
847 | */ |
851 | */ |
848 | void |
852 | void |
849 | player::chargen_race_done () |
853 | player::chargen_race_done () |
850 | { |
854 | { |
851 | /* this must before then initial items are given */ |
855 | /* this must before then initial items are given */ |
852 | esrv_new_player (ob->contr, ob->weight + ob->carrying); |
856 | esrv_new_player (ob->contr); |
853 | |
857 | |
854 | treasurelist *tl = treasurelist::find ("starting_wealth"); |
858 | treasurelist *tl = treasurelist::find ("starting_wealth"); |
855 | if (tl) |
859 | if (tl) |
856 | create_treasure (tl, ob, 0, 0, 0); |
860 | create_treasure (tl, ob, 0, 0, 0); |
857 | |
861 | |
… | |
… | |
1007 | if (op->move_type & MOVE_FLYING) |
1011 | if (op->move_type & MOVE_FLYING) |
1008 | return 1; |
1012 | return 1; |
1009 | |
1013 | |
1010 | next = op->below; |
1014 | next = op->below; |
1011 | |
1015 | |
|
|
1016 | int cnt = MAX_ITEM_PER_DROP; |
|
|
1017 | #define CHK_PICK_PICKUP do { pick_up (op, tmp); cnt--; } while (0) |
|
|
1018 | |
1012 | /* loop while there are items on the floor that are not marked as |
1019 | /* loop while there are items on the floor that are not marked as |
1013 | * destroyed */ |
1020 | * destroyed */ |
1014 | while (next && !next->destroyed ()) |
1021 | while (next && !next->destroyed ()) |
1015 | { |
1022 | { |
1016 | tmp = next; |
1023 | tmp = next; |
1017 | next = tmp->below; |
1024 | next = tmp->below; |
1018 | |
1025 | |
|
|
1026 | if (cnt <= 0) |
|
|
1027 | { |
|
|
1028 | op->failmsg ("Couldn't pickup all items at once."); |
|
|
1029 | return 0; |
|
|
1030 | } |
|
|
1031 | |
1019 | if (op->destroyed ()) |
1032 | if (op->destroyed ()) |
1020 | return 0; |
1033 | return 0; |
1021 | |
1034 | |
1022 | if (!can_pick (op, tmp)) |
1035 | if (!can_pick (op, tmp)) |
1023 | continue; |
1036 | continue; |
1024 | |
1037 | |
1025 | if (op->contr->search_str[0] != '\0' && settings.search_items == TRUE) |
1038 | if (op->contr->search_str[0] != '\0' && settings.search_items == TRUE) |
1026 | { |
1039 | { |
1027 | if (item_matched_string (op, tmp, op->contr->search_str)) |
1040 | if (item_matched_string (op, tmp, op->contr->search_str)) |
1028 | pick_up (op, tmp); |
1041 | CHK_PICK_PICKUP; |
1029 | continue; |
1042 | continue; |
1030 | } |
1043 | } |
1031 | |
1044 | |
1032 | /* high not bit set? We're using the old autopickup model */ |
1045 | /* high not bit set? We're using the old autopickup model */ |
1033 | if (!(op->contr->mode & PU_NEWMODE)) |
1046 | if (!(op->contr->mode & PU_NEWMODE)) |
… | |
… | |
1035 | switch (op->contr->mode) |
1048 | switch (op->contr->mode) |
1036 | { |
1049 | { |
1037 | case 0: |
1050 | case 0: |
1038 | return 1; /* don't pick up */ |
1051 | return 1; /* don't pick up */ |
1039 | case 1: |
1052 | case 1: |
1040 | pick_up (op, tmp); |
1053 | CHK_PICK_PICKUP; |
1041 | return 1; |
1054 | return 1; |
1042 | case 2: |
1055 | case 2: |
1043 | pick_up (op, tmp); |
1056 | CHK_PICK_PICKUP; |
1044 | return 0; |
1057 | return 0; |
1045 | case 3: |
1058 | case 3: |
1046 | return 0; /* stop before pickup */ |
1059 | return 0; /* stop before pickup */ |
1047 | case 4: |
1060 | case 4: |
1048 | pick_up (op, tmp); |
1061 | CHK_PICK_PICKUP; |
1049 | break; |
1062 | break; |
1050 | case 5: |
1063 | case 5: |
1051 | pick_up (op, tmp); |
1064 | CHK_PICK_PICKUP; |
1052 | stop = 1; |
1065 | stop = 1; |
1053 | break; |
1066 | break; |
1054 | case 6: |
1067 | case 6: |
1055 | if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)) |
1068 | if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) |
1056 | pick_up (op, tmp); |
1069 | && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)) |
|
|
1070 | CHK_PICK_PICKUP; |
1057 | break; |
1071 | break; |
1058 | |
1072 | |
1059 | case 7: |
1073 | case 7: |
1060 | if (tmp->type == MONEY || tmp->type == GEM) |
1074 | if (tmp->type == MONEY || tmp->type == GEM) |
1061 | pick_up (op, tmp); |
1075 | CHK_PICK_PICKUP; |
1062 | break; |
1076 | break; |
1063 | |
1077 | |
1064 | default: |
1078 | default: |
1065 | /* use value density */ |
1079 | /* use value density */ |
1066 | if (!QUERY_FLAG (tmp, FLAG_UNPAID) |
1080 | if (!QUERY_FLAG (tmp, FLAG_UNPAID) |
1067 | && (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))) >= op->contr->mode) |
1081 | && (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))) >= op->contr->mode) |
1068 | pick_up (op, tmp); |
1082 | CHK_PICK_PICKUP; |
1069 | } |
1083 | } |
1070 | } |
1084 | } |
1071 | else |
1085 | else |
1072 | { /* old model */ |
1086 | { /* old model */ |
1073 | /* NEW pickup handling */ |
1087 | /* NEW pickup handling */ |
… | |
… | |
1128 | /* all food and drink if desired */ |
1142 | /* all food and drink if desired */ |
1129 | /* question: don't pick up known-poisonous stuff? */ |
1143 | /* question: don't pick up known-poisonous stuff? */ |
1130 | if (op->contr->mode & PU_FOOD) |
1144 | if (op->contr->mode & PU_FOOD) |
1131 | if (tmp->type == FOOD) |
1145 | if (tmp->type == FOOD) |
1132 | { |
1146 | { |
1133 | pick_up (op, tmp); |
1147 | CHK_PICK_PICKUP; |
1134 | continue; |
1148 | continue; |
1135 | } |
1149 | } |
1136 | |
1150 | |
1137 | if (op->contr->mode & PU_DRINK) |
1151 | if (op->contr->mode & PU_DRINK) |
1138 | if (tmp->type == DRINK || (tmp->type == POISON && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))) |
1152 | if (tmp->type == DRINK || (tmp->type == POISON && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))) |
1139 | { |
1153 | { |
1140 | pick_up (op, tmp); |
1154 | CHK_PICK_PICKUP; |
1141 | continue; |
1155 | continue; |
1142 | } |
1156 | } |
1143 | |
1157 | |
1144 | if (op->contr->mode & PU_POTION) |
1158 | if (op->contr->mode & PU_POTION) |
1145 | if (tmp->type == POTION) |
1159 | if (tmp->type == POTION) |
1146 | { |
1160 | { |
1147 | pick_up (op, tmp); |
1161 | CHK_PICK_PICKUP; |
1148 | continue; |
1162 | continue; |
1149 | } |
1163 | } |
1150 | |
1164 | |
1151 | /* spellbooks, skillscrolls and normal books/scrolls */ |
1165 | /* spellbooks, skillscrolls and normal books/scrolls */ |
1152 | if (op->contr->mode & PU_SPELLBOOK) |
1166 | if (op->contr->mode & PU_SPELLBOOK) |
1153 | if (tmp->type == SPELLBOOK) |
1167 | if (tmp->type == SPELLBOOK) |
1154 | { |
1168 | { |
1155 | pick_up (op, tmp); |
1169 | CHK_PICK_PICKUP; |
1156 | continue; |
1170 | continue; |
1157 | } |
1171 | } |
1158 | |
1172 | |
1159 | if (op->contr->mode & PU_SKILLSCROLL) |
1173 | if (op->contr->mode & PU_SKILLSCROLL) |
1160 | if (tmp->type == SKILLSCROLL) |
1174 | if (tmp->type == SKILLSCROLL) |
1161 | { |
1175 | { |
1162 | pick_up (op, tmp); |
1176 | CHK_PICK_PICKUP; |
1163 | continue; |
1177 | continue; |
1164 | } |
1178 | } |
1165 | |
1179 | |
1166 | if (op->contr->mode & PU_READABLES) |
1180 | if (op->contr->mode & PU_READABLES) |
1167 | if (tmp->type == BOOK || tmp->type == SCROLL || tmp->type == INSCRIBABLE) |
1181 | if (tmp->type == BOOK || tmp->type == SCROLL || tmp->type == INSCRIBABLE) |
1168 | { |
1182 | { |
1169 | pick_up (op, tmp); |
1183 | CHK_PICK_PICKUP; |
1170 | continue; |
1184 | continue; |
1171 | } |
1185 | } |
1172 | |
1186 | |
1173 | /* wands/staves/rods/horns */ |
1187 | /* wands/staves/rods/horns */ |
1174 | if (op->contr->mode & PU_MAGIC_DEVICE) |
1188 | if (op->contr->mode & PU_MAGIC_DEVICE) |
1175 | if (tmp->type == WAND || tmp->type == ROD || tmp->type == HORN) |
1189 | if (tmp->type == WAND || tmp->type == ROD || tmp->type == HORN) |
1176 | { |
1190 | { |
1177 | pick_up (op, tmp); |
1191 | CHK_PICK_PICKUP; |
1178 | continue; |
1192 | continue; |
1179 | } |
1193 | } |
1180 | |
1194 | |
1181 | /* pick up all magical items */ |
1195 | /* pick up all magical items */ |
1182 | if (op->contr->mode & PU_MAGICAL) |
1196 | if (op->contr->mode & PU_MAGICAL) |
1183 | if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)) |
1197 | if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)) |
1184 | { |
1198 | { |
1185 | pick_up (op, tmp); |
1199 | CHK_PICK_PICKUP; |
1186 | continue; |
1200 | continue; |
1187 | } |
1201 | } |
1188 | |
1202 | |
1189 | if (op->contr->mode & PU_VALUABLES) |
1203 | if (op->contr->mode & PU_VALUABLES) |
1190 | { |
1204 | { |
1191 | if (tmp->type == MONEY || tmp->type == GEM) |
1205 | if (tmp->type == MONEY || tmp->type == GEM) |
1192 | { |
1206 | { |
1193 | pick_up (op, tmp); |
1207 | CHK_PICK_PICKUP; |
1194 | continue; |
1208 | continue; |
1195 | } |
1209 | } |
1196 | } |
1210 | } |
1197 | |
1211 | |
1198 | /* rings & amulets - talismans seems to be typed AMULET */ |
1212 | /* rings & amulets - talismans seems to be typed AMULET */ |
1199 | if (op->contr->mode & PU_JEWELS) |
1213 | if (op->contr->mode & PU_JEWELS) |
1200 | if (tmp->type == RING || tmp->type == AMULET) |
1214 | if (tmp->type == RING || tmp->type == AMULET) |
1201 | { |
1215 | { |
1202 | pick_up (op, tmp); |
1216 | CHK_PICK_PICKUP; |
1203 | continue; |
1217 | continue; |
1204 | } |
1218 | } |
1205 | |
1219 | |
1206 | /* we don't forget dragon food */ |
1220 | /* we don't forget dragon food */ |
1207 | if (op->contr->mode & PU_FLESH) |
1221 | if (op->contr->mode & PU_FLESH) |
1208 | if (tmp->type == FLESH) |
1222 | if (tmp->type == FLESH) |
1209 | { |
1223 | { |
1210 | pick_up (op, tmp); |
1224 | CHK_PICK_PICKUP; |
1211 | continue; |
1225 | continue; |
1212 | } |
1226 | } |
1213 | |
1227 | |
1214 | /* bows and arrows. Bows are good for selling! */ |
1228 | /* bows and arrows. Bows are good for selling! */ |
1215 | if (op->contr->mode & PU_BOW) |
1229 | if (op->contr->mode & PU_BOW) |
1216 | if (tmp->type == BOW) |
1230 | if (tmp->type == BOW) |
1217 | { |
1231 | { |
1218 | pick_up (op, tmp); |
1232 | CHK_PICK_PICKUP; |
1219 | continue; |
1233 | continue; |
1220 | } |
1234 | } |
1221 | |
1235 | |
1222 | if (op->contr->mode & PU_ARROW) |
1236 | if (op->contr->mode & PU_ARROW) |
1223 | if (tmp->type == ARROW) |
1237 | if (tmp->type == ARROW) |
1224 | { |
1238 | { |
1225 | pick_up (op, tmp); |
1239 | CHK_PICK_PICKUP; |
1226 | continue; |
1240 | continue; |
1227 | } |
1241 | } |
1228 | |
1242 | |
1229 | /* all kinds of armor etc. */ |
1243 | /* all kinds of armor etc. */ |
1230 | if (op->contr->mode & PU_ARMOUR) |
1244 | if (op->contr->mode & PU_ARMOUR) |
1231 | if (tmp->type == ARMOUR) |
1245 | if (tmp->type == ARMOUR) |
1232 | { |
1246 | { |
1233 | pick_up (op, tmp); |
1247 | CHK_PICK_PICKUP; |
1234 | continue; |
1248 | continue; |
1235 | } |
1249 | } |
1236 | |
1250 | |
1237 | if (op->contr->mode & PU_HELMET) |
1251 | if (op->contr->mode & PU_HELMET) |
1238 | if (tmp->type == HELMET) |
1252 | if (tmp->type == HELMET) |
1239 | { |
1253 | { |
1240 | pick_up (op, tmp); |
1254 | CHK_PICK_PICKUP; |
1241 | continue; |
1255 | continue; |
1242 | } |
1256 | } |
1243 | |
1257 | |
1244 | if (op->contr->mode & PU_SHIELD) |
1258 | if (op->contr->mode & PU_SHIELD) |
1245 | if (tmp->type == SHIELD) |
1259 | if (tmp->type == SHIELD) |
1246 | { |
1260 | { |
1247 | pick_up (op, tmp); |
1261 | CHK_PICK_PICKUP; |
1248 | continue; |
1262 | continue; |
1249 | } |
1263 | } |
1250 | |
1264 | |
1251 | if (op->contr->mode & PU_BOOTS) |
1265 | if (op->contr->mode & PU_BOOTS) |
1252 | if (tmp->type == BOOTS) |
1266 | if (tmp->type == BOOTS) |
1253 | { |
1267 | { |
1254 | pick_up (op, tmp); |
1268 | CHK_PICK_PICKUP; |
1255 | continue; |
1269 | continue; |
1256 | } |
1270 | } |
1257 | |
1271 | |
1258 | if (op->contr->mode & PU_GLOVES) |
1272 | if (op->contr->mode & PU_GLOVES) |
1259 | if (tmp->type == GLOVES) |
1273 | if (tmp->type == GLOVES) |
1260 | { |
1274 | { |
1261 | pick_up (op, tmp); |
1275 | CHK_PICK_PICKUP; |
1262 | continue; |
1276 | continue; |
1263 | } |
1277 | } |
1264 | |
1278 | |
1265 | if (op->contr->mode & PU_CLOAK) |
1279 | if (op->contr->mode & PU_CLOAK) |
1266 | if (tmp->type == CLOAK) |
1280 | if (tmp->type == CLOAK) |
1267 | { |
1281 | { |
1268 | pick_up (op, tmp); |
1282 | CHK_PICK_PICKUP; |
1269 | continue; |
1283 | continue; |
1270 | } |
1284 | } |
1271 | |
1285 | |
1272 | /* hoping to catch throwing daggers here */ |
1286 | /* hoping to catch throwing daggers here */ |
1273 | if (op->contr->mode & PU_MISSILEWEAPON) |
1287 | if (op->contr->mode & PU_MISSILEWEAPON) |
1274 | if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_IS_THROWN)) |
1288 | if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_IS_THROWN)) |
1275 | { |
1289 | { |
1276 | pick_up (op, tmp); |
1290 | CHK_PICK_PICKUP; |
1277 | continue; |
1291 | continue; |
1278 | } |
1292 | } |
1279 | |
1293 | |
1280 | /* careful: chairs and tables are weapons! */ |
1294 | /* careful: chairs and tables are weapons! */ |
1281 | if (op->contr->mode & PU_ALLWEAPON) |
1295 | if (op->contr->mode & PU_ALLWEAPON) |
… | |
… | |
1283 | if (tmp->type == WEAPON && tmp->name != NULL) |
1297 | if (tmp->type == WEAPON && tmp->name != NULL) |
1284 | { |
1298 | { |
1285 | if (strstr (tmp->name, "table") == NULL && strstr (tmp->arch->archname, "table") == NULL && |
1299 | if (strstr (tmp->name, "table") == NULL && strstr (tmp->arch->archname, "table") == NULL && |
1286 | strstr (tmp->name, "chair") && strstr (tmp->arch->archname, "chair") == NULL) |
1300 | strstr (tmp->name, "chair") && strstr (tmp->arch->archname, "chair") == NULL) |
1287 | { |
1301 | { |
1288 | pick_up (op, tmp); |
1302 | CHK_PICK_PICKUP; |
1289 | continue; |
1303 | continue; |
1290 | } |
1304 | } |
1291 | } |
1305 | } |
1292 | |
1306 | |
1293 | if (tmp->type == WEAPON && tmp->name == NULL) |
1307 | if (tmp->type == WEAPON && tmp->name == NULL) |
1294 | { |
1308 | { |
1295 | if (strstr (tmp->arch->archname, "table") == NULL && strstr (tmp->arch->archname, "chair") == NULL) |
1309 | if (strstr (tmp->arch->archname, "table") == NULL && strstr (tmp->arch->archname, "chair") == NULL) |
1296 | { |
1310 | { |
1297 | pick_up (op, tmp); |
1311 | CHK_PICK_PICKUP; |
1298 | continue; |
1312 | continue; |
1299 | } |
1313 | } |
1300 | } |
1314 | } |
1301 | } |
1315 | } |
1302 | |
1316 | |
1303 | /* misc stuff that's useful */ |
1317 | /* misc stuff that's useful */ |
1304 | if (op->contr->mode & PU_KEY) |
1318 | if (op->contr->mode & PU_KEY) |
1305 | if (tmp->type == KEY || tmp->type == SPECIAL_KEY) |
1319 | if (tmp->type == KEY || tmp->type == SPECIAL_KEY) |
1306 | { |
1320 | { |
1307 | pick_up (op, tmp); |
1321 | CHK_PICK_PICKUP; |
1308 | continue; |
1322 | continue; |
1309 | } |
1323 | } |
1310 | |
1324 | |
1311 | /* any of the last 4 bits set means we use the ratio for value |
1325 | /* any of the last 4 bits set means we use the ratio for value |
1312 | * pickups */ |
1326 | * pickups */ |
… | |
… | |
1317 | /* >=7 is the old standard setting. Now we take the last 4 bits |
1331 | /* >=7 is the old standard setting. Now we take the last 4 bits |
1318 | * and multiply them by 5, giving 0..15*5== 5..75 */ |
1332 | * and multiply them by 5, giving 0..15*5== 5..75 */ |
1319 | wvratio = (op->contr->mode & PU_RATIO) * 5; |
1333 | wvratio = (op->contr->mode & PU_RATIO) * 5; |
1320 | if ((query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))) >= (unsigned int) wvratio) |
1334 | if ((query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))) >= (unsigned int) wvratio) |
1321 | { |
1335 | { |
1322 | pick_up (op, tmp); |
1336 | CHK_PICK_PICKUP; |
1323 | #if 0 |
1337 | #if 0 |
1324 | fprintf (stderr, "HIGH WEIGHT/VALUE ["); |
1338 | fprintf (stderr, "HIGH WEIGHT/VALUE ["); |
1325 | if (tmp->name != NULL) |
1339 | if (tmp->name != NULL) |
1326 | { |
1340 | { |
1327 | fprintf (stderr, "%s", tmp->name); |
1341 | fprintf (stderr, "%s", tmp->name); |
… | |
… | |
1346 | * found object is returned. |
1360 | * found object is returned. |
1347 | */ |
1361 | */ |
1348 | object * |
1362 | object * |
1349 | find_arrow (object *op, const char *type) |
1363 | find_arrow (object *op, const char *type) |
1350 | { |
1364 | { |
1351 | object *tmp = 0; |
|
|
1352 | |
|
|
1353 | for (op = op->inv; op; op = op->below) |
1365 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
1354 | if (!tmp && op->type == CONTAINER && op->race == type && QUERY_FLAG (op, FLAG_APPLIED)) |
|
|
1355 | tmp = find_arrow (op, type); |
|
|
1356 | else if (op->type == ARROW && op->race == type) |
1366 | if (tmp->type == ARROW && !strcmp (&tmp->race, type)) |
|
|
1367 | return splay (tmp); |
|
|
1368 | |
|
|
1369 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
|
|
1370 | if (tmp->type == CONTAINER && QUERY_FLAG (tmp, FLAG_APPLIED) && !strcmp (&tmp->race, type)) |
|
|
1371 | if (object *arrow = find_arrow (tmp, type)) |
|
|
1372 | { |
|
|
1373 | splay (tmp); |
1357 | return op; |
1374 | return arrow; |
|
|
1375 | } |
1358 | |
1376 | |
1359 | return tmp; |
1377 | return 0; |
1360 | } |
1378 | } |
1361 | |
1379 | |
1362 | /* |
1380 | /* |
1363 | * Similar to find_arrow, but looks for (roughly) the best arrow to use |
1381 | * Similar to find_arrow, but looks for (roughly) the best arrow to use |
1364 | * against the target. A full test is not performed, simply a basic test |
1382 | * against the target. A full test is not performed, simply a basic test |
… | |
… | |
1387 | } |
1405 | } |
1388 | } |
1406 | } |
1389 | else if (arrow->type == ARROW && arrow->race == type) |
1407 | else if (arrow->type == ARROW && arrow->race == type) |
1390 | { |
1408 | { |
1391 | /* allways prefer assasination/slaying */ |
1409 | /* allways prefer assasination/slaying */ |
1392 | if (target->race != NULL && arrow->slaying != NULL && strstr (arrow->slaying, target->race)) |
1410 | if (target->race && arrow->slaying && strstr (arrow->slaying, target->race)) |
1393 | { |
1411 | { |
1394 | if (arrow->attacktype & AT_DEATH) |
1412 | if (arrow->attacktype & AT_DEATH) |
1395 | { |
1413 | { |
1396 | *better = 100; |
1414 | *better = 100; |
1397 | return arrow; |
1415 | return arrow; |
… | |
… | |
1585 | arrow->destroy (); |
1603 | arrow->destroy (); |
1586 | return 0; |
1604 | return 0; |
1587 | } |
1605 | } |
1588 | |
1606 | |
1589 | left = arrow; /* these are arrows left to the player */ |
1607 | left = arrow; /* these are arrows left to the player */ |
1590 | arrow = get_split_ob (arrow, 1); |
1608 | arrow = arrow->split (); |
1591 | if (!arrow) |
1609 | if (!arrow) |
1592 | { |
1610 | { |
1593 | new_draw_info_format (NDI_UNIQUE, 0, op, "You have no %s left.", &bow->race); |
1611 | new_draw_info_format (NDI_UNIQUE, 0, op, "You have no %s left.", &bow->race); |
1594 | return 0; |
1612 | return 0; |
1595 | } |
1613 | } |
… | |
… | |
1662 | op->play_sound (sound_find ("fire_arrow")); |
1680 | op->play_sound (sound_find ("fire_arrow")); |
1663 | m->insert (arrow, sx, sy, op); |
1681 | m->insert (arrow, sx, sy, op); |
1664 | |
1682 | |
1665 | if (!arrow->destroyed ()) |
1683 | if (!arrow->destroyed ()) |
1666 | move_arrow (arrow); |
1684 | move_arrow (arrow); |
1667 | |
|
|
1668 | if (op->type == PLAYER) |
|
|
1669 | { |
|
|
1670 | if (left->destroyed ()) |
|
|
1671 | esrv_del_item (op->contr, left->count); |
|
|
1672 | else |
|
|
1673 | esrv_send_item (op, left); |
|
|
1674 | } |
|
|
1675 | |
1685 | |
1676 | return 1; |
1686 | return 1; |
1677 | } |
1687 | } |
1678 | |
1688 | |
1679 | /* Special fire code for players - this takes into |
1689 | /* Special fire code for players - this takes into |
… | |
… | |
1753 | return; |
1763 | return; |
1754 | } |
1764 | } |
1755 | } |
1765 | } |
1756 | else if (item->type == ROD || item->type == HORN) |
1766 | else if (item->type == ROD || item->type == HORN) |
1757 | { |
1767 | { |
1758 | if (item->stats.hp < MAX (item->inv->stats.sp, item->inv->stats.grace)) |
1768 | sint16 spell_sp = MAX (item->inv->stats.sp, item->inv->stats.grace); |
|
|
1769 | |
|
|
1770 | // using the maximum of the rods charge allows at least one spell cast |
|
|
1771 | // for a rod or horn, this fixes some broken rods. |
|
|
1772 | if (item->stats.hp < MIN (spell_sp, item->stats.maxhp)) |
1759 | { |
1773 | { |
1760 | op->contr->play_sound (sound_find ("wand_poof")); |
1774 | op->contr->play_sound (sound_find ("wand_poof")); |
1761 | |
1775 | |
1762 | if (item->type == ROD) |
1776 | if (item->type == ROD) |
1763 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s whines for a while, but nothing happens.", query_base_name (item, 0)); |
1777 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s whines for a while, but nothing happens.", query_base_name (item, 0)); |
… | |
… | |
1782 | CLEAR_FLAG (item, FLAG_ANIMATE); |
1796 | CLEAR_FLAG (item, FLAG_ANIMATE); |
1783 | item->face = item->arch->face; |
1797 | item->face = item->arch->face; |
1784 | item->set_speed (0); |
1798 | item->set_speed (0); |
1785 | } |
1799 | } |
1786 | |
1800 | |
1787 | if ((tmp = item->in_player ())) |
1801 | if (object *pl = item->visible_to ()) |
1788 | esrv_update_item (UPD_ANIM, tmp, item); |
1802 | esrv_update_item (UPD_ANIM, pl, item); |
1789 | } |
1803 | } |
1790 | } |
1804 | } |
1791 | else if (item->type == ROD || item->type == HORN) |
1805 | else if (item->type == ROD || item->type == HORN) |
1792 | drain_rod_charge (item); |
1806 | drain_rod_charge (item); |
1793 | } |
1807 | } |
… | |
… | |
1969 | op->statusmsg (format ("You open the door with the %s", query_short_name (key)), NDI_BROWN); |
1983 | op->statusmsg (format ("You open the door with the %s", query_short_name (key)), NDI_BROWN); |
1970 | remove_door2 (door); /* remove door without violence ;-) */ |
1984 | remove_door2 (door); /* remove door without violence ;-) */ |
1971 | } |
1985 | } |
1972 | |
1986 | |
1973 | /* Do this after we print the message */ |
1987 | /* Do this after we print the message */ |
1974 | decrease_ob (key); /* Use up one of the keys */ |
1988 | key->decrease (); /* Use up one of the keys */ |
1975 | /* Need to update the weight the container the key was in */ |
|
|
1976 | if (container != op) |
|
|
1977 | esrv_update_item (UPD_WEIGHT, op, container); |
|
|
1978 | |
1989 | |
1979 | return 1; /* Nothing more to do below */ |
1990 | return 1; /* Nothing more to do below */ |
1980 | } |
1991 | } |
1981 | else if (door->type == LOCKED_DOOR) |
1992 | else if (door->type == LOCKED_DOOR) |
1982 | { |
1993 | { |
… | |
… | |
2163 | bool |
2174 | bool |
2164 | move_player (object *op, int dir) |
2175 | move_player (object *op, int dir) |
2165 | { |
2176 | { |
2166 | int pick; |
2177 | int pick; |
2167 | |
2178 | |
2168 | if (!op->map || op->map->in_memory != MAP_IN_MEMORY) |
2179 | if (!op->map || op->map->in_memory != MAP_ACTIVE) |
2169 | return 0; |
2180 | return 0; |
2170 | |
2181 | |
2171 | /* Sanity check: make sure dir is valid */ |
2182 | /* Sanity check: make sure dir is valid */ |
2172 | if ((dir < 0) || (dir >= 9)) |
2183 | if ((dir < 0) || (dir >= 9)) |
2173 | { |
2184 | { |
… | |
… | |
2261 | if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE)) |
2272 | if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE)) |
2262 | { |
2273 | { |
2263 | op->play_sound (sound_find ("ob_evaporate")); |
2274 | op->play_sound (sound_find ("ob_evaporate")); |
2264 | new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s vibrates violently, then evaporates.", query_name (tmp)); |
2275 | new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s vibrates violently, then evaporates.", query_name (tmp)); |
2265 | |
2276 | |
2266 | if (op->contr) |
|
|
2267 | esrv_del_item (op->contr, tmp->count); |
|
|
2268 | |
|
|
2269 | tmp->destroy (); |
2277 | tmp->destroy (); |
2270 | CLEAR_FLAG (op, FLAG_LIFESAVE); |
2278 | CLEAR_FLAG (op, FLAG_LIFESAVE); |
2271 | |
2279 | |
2272 | if (op->stats.hp < 0) |
2280 | if (op->stats.hp < 0) |
2273 | op->stats.hp = op->stats.maxhp; |
2281 | op->stats.hp = op->stats.maxhp; |
… | |
… | |
2285 | return 0; |
2293 | return 0; |
2286 | } |
2294 | } |
2287 | |
2295 | |
2288 | /* This goes throws the inventory and removes unpaid objects, and puts them |
2296 | /* This goes throws the inventory and removes unpaid objects, and puts them |
2289 | * back in the map (location and map determined by values of env). This |
2297 | * back in the map (location and map determined by values of env). This |
2290 | * function will descend into containers. op is the object to start the search |
2298 | * function will descend into containers. op is the object to start the search |
2291 | * from. |
2299 | * from. |
2292 | */ |
2300 | */ |
2293 | static void |
2301 | static void |
2294 | drop_unpaid_items (object *op, object *env) |
2302 | drop_unpaid_items (object *op, object *env) |
2295 | { |
2303 | { |
2296 | while (op) |
2304 | while (op) |
2297 | { |
2305 | { |
2298 | object *next = op->below; /* Make sure we have a good value, in case we remove object 'op' */ |
2306 | object *next = op->below; /* Make sure we have a good value, in case we remove object 'op' */ |
2299 | |
2307 | |
2300 | if (QUERY_FLAG (op, FLAG_UNPAID)) |
2308 | if (QUERY_FLAG (op, FLAG_UNPAID)) |
2301 | { |
|
|
2302 | if (env->type == PLAYER) |
|
|
2303 | esrv_del_item (env->contr, op->count); |
|
|
2304 | |
|
|
2305 | op->insert_at (env); |
2309 | op->insert_at (env); |
2306 | } |
|
|
2307 | else if (op->inv) |
2310 | else if (op->inv) |
2308 | drop_unpaid_items (op->inv, env); |
2311 | drop_unpaid_items (op->inv, env); |
2309 | |
2312 | |
2310 | op = next; |
2313 | op = next; |
2311 | } |
2314 | } |
… | |
… | |
2323 | * Moved from apply.c to player.c - player.c is what |
2326 | * Moved from apply.c to player.c - player.c is what |
2324 | * actually uses this function. player.c may not be quite the |
2327 | * actually uses this function. player.c may not be quite the |
2325 | * best, a misc file for object actions is probably better, |
2328 | * best, a misc file for object actions is probably better, |
2326 | * but there isn't one in the server directory. |
2329 | * but there isn't one in the server directory. |
2327 | */ |
2330 | */ |
2328 | char * |
2331 | const char * |
2329 | gravestone_text (object *op) |
2332 | gravestone_text (object *op) |
2330 | { |
2333 | { |
2331 | static char buf2[MAX_BUF]; |
2334 | static dynbuf_text buf; |
2332 | char buf[MAX_BUF]; |
|
|
2333 | time_t now = time (NULL); |
|
|
2334 | |
2335 | |
2335 | strcpy (buf2, " R.I.P.\n\n"); |
2336 | buf << "---- R.I.P. ----\n\n"; |
|
|
2337 | op->name; |
|
|
2338 | |
2336 | if (op->type == PLAYER) |
2339 | if (op->type == PLAYER) |
2337 | sprintf (buf, "%s the %s\n", &op->name, op->contr->title); |
2340 | buf << " the " << op->contr->title; |
2338 | else |
|
|
2339 | sprintf (buf, "%s\n", &op->name); |
|
|
2340 | |
2341 | |
2341 | strncat (buf2, " ", 20 - strlen (buf) / 2); |
2342 | buf << "\n\n"; |
2342 | strcat (buf2, buf); |
2343 | |
|
|
2344 | buf << "who was level "; |
|
|
2345 | buf << (sint32)op->level << "\n\n" // OO breakdown |
|
|
2346 | << " when " << (op->contr ? "killed" : "died") << "\n\n"; |
|
|
2347 | |
2343 | if (op->type == PLAYER) |
2348 | if (op->type == PLAYER) |
2344 | sprintf (buf, "who was in level %d when killed\n", op->level); |
2349 | buf << "by " << op->contr->killer_name () << ".\n\n"; |
2345 | else |
|
|
2346 | sprintf (buf, "who was in level %d when died.\n\n", op->level); |
|
|
2347 | |
2350 | |
2348 | strncat (buf2, " ", 20 - strlen (buf) / 2); |
|
|
2349 | strcat (buf2, buf); |
|
|
2350 | if (op->type == PLAYER) |
|
|
2351 | { |
2351 | { |
2352 | sprintf (buf, "by %s.\n\n", op->contr->killer); |
2352 | static char buf2[128]; |
2353 | strncat (buf2, " ", 21 - strlen (buf) / 2); |
2353 | time_t now = time (NULL); |
2354 | strcat (buf2, buf); |
|
|
2355 | } |
|
|
2356 | |
|
|
2357 | strftime (buf, MAX_BUF, "%b %d %Y\n", localtime (&now)); |
2354 | strftime (buf2, 128, "%b %d %Y\n\n", localtime (&now)); |
2358 | strncat (buf2, " ", 20 - strlen (buf) / 2); |
2355 | buf << buf2; |
2359 | strcat (buf2, buf); |
2356 | } |
2360 | |
2357 | |
2361 | return buf2; |
2358 | return buf; |
2362 | } |
2359 | } |
2363 | |
2360 | |
2364 | void |
2361 | void |
2365 | do_some_living (object *op) |
2362 | do_some_living (object *op) |
2366 | { |
2363 | { |
… | |
… | |
2575 | new_draw_info (NDI_UNIQUE, 0, op, "You blindly grab for a bite of food."); |
2572 | new_draw_info (NDI_UNIQUE, 0, op, "You blindly grab for a bite of food."); |
2576 | manual_apply (op, flesh, 0); |
2573 | manual_apply (op, flesh, 0); |
2577 | } |
2574 | } |
2578 | } |
2575 | } |
2579 | |
2576 | |
2580 | if (op->stats.food < 0) |
2577 | if (op->stats.food < 0 && op->stats.hp >= -op->stats.food) |
2581 | { |
2578 | { |
2582 | op->stats.hp += op->stats.food; |
2579 | op->stats.hp += op->stats.food; |
2583 | op->stats.food = 0; |
2580 | op->stats.food = 0; |
2584 | } |
2581 | } |
2585 | |
2582 | |
… | |
… | |
2640 | { |
2637 | { |
2641 | tmp->name = format ("%s's finger" , &op->name); |
2638 | tmp->name = format ("%s's finger" , &op->name); |
2642 | tmp->name_pl = format ("%s's fingers", &op->name); |
2639 | tmp->name_pl = format ("%s's fingers", &op->name); |
2643 | tmp->msg = format ( |
2640 | tmp->msg = format ( |
2644 | "This finger has been cut off of %s the %s, when he was defeated at level %d by %s.\n", |
2641 | "This finger has been cut off of %s the %s, when he was defeated at level %d by %s.\n", |
2645 | &op->name, op->contr->title, (int) (op->level), op->contr->killer |
2642 | &op->name, op->contr->title, |
|
|
2643 | (int)op->level, |
|
|
2644 | op->contr->killer_name () |
2646 | ); |
2645 | ); |
2647 | tmp->value = 0, tmp->type = 0; |
2646 | tmp->value = 0, tmp->type = 0; |
2648 | tmp->materialname = "organics"; |
2647 | tmp->materialname = "organics"; |
2649 | tmp->insert_at (op, tmp); |
2648 | tmp->insert_at (op, tmp); |
2650 | } |
2649 | } |
… | |
… | |
2658 | INVOKE_PLAYER (DEATH, op->contr); |
2657 | INVOKE_PLAYER (DEATH, op->contr); |
2659 | |
2658 | |
2660 | command_kill_pets (op, 0); |
2659 | command_kill_pets (op, 0); |
2661 | |
2660 | |
2662 | if (op->stats.food < 0) |
2661 | if (op->stats.food < 0) |
2663 | strcpy (op->contr->killer, "starvation"); |
2662 | { |
|
|
2663 | op->contr->killer = archetype::get ("killer_starvation"); |
|
|
2664 | op->contr->killer->destroy (); |
|
|
2665 | } |
2664 | |
2666 | |
2665 | op->contr->play_sound (sound_find ("player_dies")); |
2667 | op->contr->play_sound (sound_find ("player_dies")); |
2666 | |
2668 | |
2667 | /* save the map location for corpse, gravestone */ |
2669 | /* save the map location for corpse, gravestone */ |
2668 | x = op->x; |
2670 | x = op->x; |
… | |
… | |
2801 | tmp = arch_to_object (archetype::find ("gravestone")); |
2803 | tmp = arch_to_object (archetype::find ("gravestone")); |
2802 | sprintf (buf, "%s's gravestone", &op->name); |
2804 | sprintf (buf, "%s's gravestone", &op->name); |
2803 | tmp->name = buf; |
2805 | tmp->name = buf; |
2804 | sprintf (buf, "%s's gravestones", &op->name); |
2806 | sprintf (buf, "%s's gravestones", &op->name); |
2805 | tmp->name_pl = buf; |
2807 | tmp->name_pl = buf; |
2806 | sprintf (buf, "RIP\nHere rests the hero %s the %s,\n" "who was killed\n" "by %s.\n", &op->name, op->contr->title, op->contr->killer); |
2808 | sprintf (buf, "RIP\nHere rests the hero %s the %s,\n" "who was killed\n" "by %s.\n", &op->name, op->contr->title, op->contr->killer_name ()); |
2807 | tmp->msg = buf; |
2809 | tmp->msg = buf; |
2808 | tmp->x = op->x, tmp->y = op->y; |
2810 | tmp->x = op->x, tmp->y = op->y; |
2809 | insert_ob_in_map (tmp, op->map, NULL, 0); |
2811 | insert_ob_in_map (tmp, op->map, NULL, 0); |
2810 | |
2812 | |
2811 | /**************************************/ |
2813 | /**************************************/ |
… | |
… | |
2916 | |
2918 | |
2917 | if (!QUERY_FLAG (tmp, FLAG_UNIQUE) && (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || QUERY_FLAG (tmp, FLAG_NO_DROP) || !(rndm (3)))) |
2919 | if (!QUERY_FLAG (tmp, FLAG_UNIQUE) && (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || QUERY_FLAG (tmp, FLAG_NO_DROP) || !(rndm (3)))) |
2918 | { |
2920 | { |
2919 | if (tmp->nrof > 1) |
2921 | if (tmp->nrof > 1) |
2920 | { |
2922 | { |
2921 | tmp2 = get_split_ob (tmp, 1 + RANDOM () % (tmp->nrof - 1)); |
2923 | tmp->decrease (rndm (1, tmp->nrof - 1)); |
2922 | tmp2->destroy (); |
|
|
2923 | insert_ob_in_map (tmp, op->map, NULL, 0); |
2924 | insert_ob_in_map (tmp, op->map, NULL, 0); |
2924 | } |
2925 | } |
2925 | else |
2926 | else |
2926 | tmp->destroy (); |
2927 | tmp->destroy (); |
2927 | } |
2928 | } |
… | |
… | |
2938 | void |
2939 | void |
2939 | fix_weight (void) |
2940 | fix_weight (void) |
2940 | { |
2941 | { |
2941 | for_all_players (pl) |
2942 | for_all_players (pl) |
2942 | { |
2943 | { |
2943 | int old = pl->ob->carrying, sum = sum_weight (pl->ob); |
2944 | sint32 old = pl->ob->carrying; |
2944 | |
2945 | |
2945 | if (old == sum) |
2946 | pl->ob->update_weight (); |
2946 | continue; |
2947 | |
|
|
2948 | if (old != pl->ob->carrying) |
|
|
2949 | { |
2947 | pl->ob->update_stats (); |
2950 | pl->ob->update_stats (); |
2948 | LOG (llevDebug, "Fixed inventory in %s (%d -> %d)\n", &pl->ob->name, old, sum); |
2951 | LOG (llevDebug, "Fixed inventory in %s (%d -> %d)\n", &pl->ob->name, (int)old, (int)pl->ob->carrying); |
|
|
2952 | } |
2949 | } |
2953 | } |
2950 | } |
2954 | } |
2951 | |
2955 | |
2952 | void |
2956 | void |
2953 | fix_luck (void) |
2957 | fix_luck (void) |
… | |
… | |
3039 | * as bad as carrying a light on a pitch dark map */ |
3043 | * as bad as carrying a light on a pitch dark map */ |
3040 | if (has_carried_lights (ob)) |
3044 | if (has_carried_lights (ob)) |
3041 | level = -(10 + (2 * ob->map->darkness)); |
3045 | level = -(10 + (2 * ob->map->darkness)); |
3042 | |
3046 | |
3043 | /* scan through all nearby squares for terrain to hide in */ |
3047 | /* scan through all nearby squares for terrain to hide in */ |
3044 | for (i = 0, x = ob->x, y = ob->y; i < 9; i++, x = ob->x + freearr_x[i], y = ob->y + freearr_y[i]) |
3048 | for (i = 0, x = ob->x, y = ob->y; |
|
|
3049 | i <= SIZEOFFREE1; |
|
|
3050 | i++, x = ob->x + freearr_x[i], y = ob->y + freearr_y[i]) |
3045 | { |
3051 | { |
3046 | mflag = get_map_flags (ob->map, NULL, x, y, NULL, NULL); |
3052 | mflag = get_map_flags (ob->map, NULL, x, y, NULL, NULL); |
3047 | if (mflag & P_OUT_OF_MAP) |
3053 | if (mflag & P_OUT_OF_MAP) |
3048 | { |
|
|
3049 | continue; |
3054 | continue; |
3050 | } |
3055 | |
3051 | if (mflag & P_BLOCKSVIEW) /* something to hide near! */ |
3056 | if (mflag & P_BLOCKSVIEW) /* something to hide near! */ |
3052 | level += 2; |
3057 | level += 2; |
3053 | else /* open terrain! */ |
3058 | else /* open terrain! */ |
3054 | level -= 1; |
3059 | level -= 1; |
3055 | } |
3060 | } |
… | |
… | |
3066 | * spot (surrounded by clear terrain in broad daylight). -b.t. |
3071 | * spot (surrounded by clear terrain in broad daylight). -b.t. |
3067 | */ |
3072 | */ |
3068 | void |
3073 | void |
3069 | do_hidden_move (object *op) |
3074 | do_hidden_move (object *op) |
3070 | { |
3075 | { |
3071 | int hide = 0, num = random_roll (0, 19, op, PREFER_LOW); |
3076 | int hide = 0; |
3072 | object *skop; |
|
|
3073 | |
3077 | |
3074 | if (!op || !op->map) |
3078 | if (!op || !op->map) |
3075 | return; |
3079 | return; |
3076 | |
3080 | |
3077 | skop = find_obj_by_type_subtype (op, SKILL, SK_HIDING); |
3081 | object *skop = find_obj_by_type_subtype (op, SKILL, SK_HIDING); |
|
|
3082 | int num = random_roll (0, 19, op, PREFER_LOW); |
3078 | |
3083 | |
3079 | /* its *extremely* hard to run and sneak/hide at the same time! */ |
3084 | /* its *extremely* hard to run and sneak/hide at the same time! */ |
3080 | if (op->type == PLAYER && op->contr->run_on) |
3085 | if (op->type == PLAYER && op->contr->run_on) |
3081 | if (!skop || num >= skop->level) |
3086 | if (!skop || num >= skop->level) |
3082 | { |
3087 | { |
… | |
… | |
3092 | num -= hide; |
3097 | num -= hide; |
3093 | |
3098 | |
3094 | if ((op->type == PLAYER && hide < -10) || ((op->invisible -= num) <= 0)) |
3099 | if ((op->type == PLAYER && hide < -10) || ((op->invisible -= num) <= 0)) |
3095 | { |
3100 | { |
3096 | make_visible (op); |
3101 | make_visible (op); |
|
|
3102 | |
3097 | if (op->type == PLAYER) |
3103 | if (op->type == PLAYER) |
3098 | new_draw_info (NDI_UNIQUE, 0, op, "You moved out of hiding! You are visible!"); |
3104 | new_draw_info (NDI_UNIQUE, 0, op, "You moved out of hiding! You are visible!"); |
3099 | } |
3105 | } |
3100 | else if (op->type == PLAYER && skop) |
3106 | else if (op->type == PLAYER && skop) |
3101 | change_exp (op, calc_skill_exp (op, NULL, skop), skop->skill, 0); |
3107 | change_exp (op, calc_skill_exp (op, NULL, skop), skop->skill, 0); |
… | |
… | |
3442 | else |
3448 | else |
3443 | { |
3449 | { |
3444 | /* generate misc. treasure */ |
3450 | /* generate misc. treasure */ |
3445 | tmp = arch_to_object (tr->item); |
3451 | tmp = arch_to_object (tr->item); |
3446 | new_draw_info_format (NDI_UNIQUE | NDI_BLUE, 0, who, "You gained %s", query_short_name (tmp)); |
3452 | new_draw_info_format (NDI_UNIQUE | NDI_BLUE, 0, who, "You gained %s", query_short_name (tmp)); |
3447 | tmp = insert_ob_in_ob (tmp, who); |
3453 | who->insert (tmp); |
3448 | if (who->type == PLAYER) |
|
|
3449 | esrv_send_item (who, tmp); |
|
|
3450 | } |
3454 | } |
3451 | } |
3455 | } |
3452 | |
3456 | |
3453 | /** |
3457 | /** |
3454 | * Unready an object for a player. This function does nothing if the object was |
3458 | * Unready an object for a player. This function does nothing if the object was |