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> |
… | |
… | |
122 | continue; |
122 | continue; |
123 | |
123 | |
124 | if (*buf == '%') |
124 | if (*buf == '%') |
125 | { /* send one news */ |
125 | { /* send one news */ |
126 | if (size > 0) |
126 | if (size > 0) |
127 | draw_ext_info_format (NDI_UNIQUE | NDI_GREEN, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_NEWS, "INFORMATION: %s\n%s", (char *)"%s\n%s", subject, news); /*send previously read news */ |
127 | draw_ext_info_format (NDI_UNIQUE | NDI_GREEN, 0, op, |
|
|
128 | MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_NEWS, |
|
|
129 | "INFORMATION: %s\n%s", (char *)"%s\n%s", |
|
|
130 | subject, news); /*send previously read news */ |
128 | |
131 | |
129 | strcpy (subject, buf + 1); |
132 | strcpy (subject, buf + 1); |
130 | strip_endline (subject); |
133 | strip_endline (subject); |
131 | size = 0; |
134 | size = 0; |
132 | news[0] = '\0'; |
135 | news[0] = '\0'; |
… | |
… | |
183 | |
186 | |
184 | if (ob->map) |
187 | if (ob->map) |
185 | maplevel = ob->map->path; |
188 | maplevel = ob->map->path; |
186 | |
189 | |
187 | ob->remove (); |
190 | ob->remove (); |
|
|
191 | ob->enemy = 0; // sometimes keeps an extra refcount on itself |
188 | ob->map = 0; |
192 | ob->map = 0; |
189 | party = 0; |
193 | party = 0; |
190 | |
194 | |
191 | combat_ob = ranged_ob = 0; //TODO, should be special marker, non-refcounted, not this |
195 | combat_ob = ranged_ob = 0; //TODO, should be special marker, non-refcounted, not this |
192 | |
196 | |
… | |
… | |
214 | |
218 | |
215 | /* make sure he's a player -- needed because of class change. */ |
219 | /* make sure he's a player -- needed because of class change. */ |
216 | ob->type = PLAYER; // we are paranoid |
220 | ob->type = PLAYER; // we are paranoid |
217 | ob->race = ob->arch->race; |
221 | ob->race = ob->arch->race; |
218 | |
222 | |
219 | ob->carrying = sum_weight (ob); |
223 | ob->update_weight (); |
220 | link_player_skills (ob); |
224 | link_skills (); |
221 | |
225 | |
222 | CLEAR_FLAG (ob, FLAG_NO_FIX_PLAYER); |
226 | CLEAR_FLAG (ob, FLAG_NO_FIX_PLAYER); |
223 | |
227 | |
224 | assign (title, ob->arch->object::name); |
228 | assign (title, ob->arch->object::name); |
225 | |
229 | |
… | |
… | |
238 | set_dragon_name (ob, abil, skin); |
242 | set_dragon_name (ob, abil, skin); |
239 | } |
243 | } |
240 | |
244 | |
241 | new_draw_info (NDI_UNIQUE, 0, ob, "Welcome Back!"); |
245 | new_draw_info (NDI_UNIQUE, 0, ob, "Welcome Back!"); |
242 | |
246 | |
243 | esrv_new_player (this, ob->weight + ob->carrying); |
247 | esrv_new_player (this); |
|
|
248 | |
|
|
249 | ob->update_stats (); |
|
|
250 | |
|
|
251 | ns->floorbox_update (); |
|
|
252 | esrv_send_inventory (ob, ob); |
|
|
253 | esrv_add_spells (this, 0); |
|
|
254 | |
|
|
255 | activate (); |
|
|
256 | |
|
|
257 | send_rules (ob); |
|
|
258 | send_news (ob); |
|
|
259 | display_motd (ob); |
|
|
260 | |
|
|
261 | INVOKE_PLAYER (CONNECT, this); |
|
|
262 | INVOKE_PLAYER (LOGIN, this); |
|
|
263 | } |
|
|
264 | |
|
|
265 | void |
|
|
266 | player::disconnect () |
|
|
267 | { |
|
|
268 | if (ob) |
|
|
269 | { |
|
|
270 | ob->close_container (); //TODO: client-specific |
|
|
271 | ob->drop_unpaid_items (); |
|
|
272 | } |
|
|
273 | |
|
|
274 | if (ns) |
|
|
275 | { |
|
|
276 | if (active) |
|
|
277 | INVOKE_PLAYER (LOGOUT, this, ARG_INT (0)); |
|
|
278 | |
|
|
279 | INVOKE_PLAYER (DISCONNECT, this); |
|
|
280 | |
|
|
281 | ns->reset_stats (); |
|
|
282 | ns->pl = 0; |
|
|
283 | ns = 0; |
|
|
284 | } |
|
|
285 | |
|
|
286 | observe = ob; |
|
|
287 | |
|
|
288 | deactivate (); |
|
|
289 | } |
|
|
290 | |
|
|
291 | // the need for this function can be explained |
|
|
292 | // by load_object not returning the object |
|
|
293 | void |
|
|
294 | player::set_object (object *op) |
|
|
295 | { |
|
|
296 | ob = observe = op; |
|
|
297 | ob->contr = this; /* this aren't yet in archetype */ |
|
|
298 | |
|
|
299 | ob->speed = 1.0f; |
|
|
300 | ob->speed_left = 0.5f; |
|
|
301 | |
|
|
302 | ob->direction = 5; /* So player faces south */ |
244 | |
303 | |
245 | ob->flag [FLAG_READY_WEAPON] = false; |
304 | ob->flag [FLAG_READY_WEAPON] = false; |
246 | ob->flag [FLAG_READY_SKILL] = false; |
305 | ob->flag [FLAG_READY_SKILL] = false; |
247 | ob->flag [FLAG_READY_BOW] = false; |
306 | ob->flag [FLAG_READY_BOW] = false; |
248 | |
307 | |
… | |
… | |
265 | combat_ob = op; |
324 | combat_ob = op; |
266 | break; |
325 | break; |
267 | } |
326 | } |
268 | |
327 | |
269 | ob->change_weapon (combat_ob ? combat_ob : ranged_ob); |
328 | ob->change_weapon (combat_ob ? combat_ob : ranged_ob); |
270 | ob->update_stats (); |
329 | ob->deactivate (); // change_weapon activates, fix this better |
271 | |
|
|
272 | ns->floorbox_update (); |
|
|
273 | esrv_send_inventory (ob, ob); |
|
|
274 | esrv_add_spells (this, 0); |
|
|
275 | |
|
|
276 | activate (); |
|
|
277 | |
|
|
278 | send_rules (ob); |
|
|
279 | send_news (ob); |
|
|
280 | display_motd (ob); |
|
|
281 | |
|
|
282 | INVOKE_PLAYER (CONNECT, this); |
|
|
283 | INVOKE_PLAYER (LOGIN, this); |
|
|
284 | } |
|
|
285 | |
|
|
286 | void |
|
|
287 | player::disconnect () |
|
|
288 | { |
|
|
289 | if (ob) |
|
|
290 | { |
|
|
291 | ob->close_container (); //TODO: client-specific |
|
|
292 | ob->drop_unpaid_items (); |
|
|
293 | } |
|
|
294 | |
|
|
295 | if (ns) |
|
|
296 | { |
|
|
297 | if (active) |
|
|
298 | INVOKE_PLAYER (LOGOUT, this, ARG_INT (0)); |
|
|
299 | |
|
|
300 | INVOKE_PLAYER (DISCONNECT, this); |
|
|
301 | |
|
|
302 | ns->reset_stats (); |
|
|
303 | ns->pl = 0; |
|
|
304 | ns = 0; |
|
|
305 | } |
|
|
306 | |
|
|
307 | observe = ob; |
|
|
308 | |
|
|
309 | deactivate (); |
|
|
310 | } |
|
|
311 | |
|
|
312 | // the need for this function can be explained |
|
|
313 | // by load_object not returning the object |
|
|
314 | void |
|
|
315 | player::set_object (object *op) |
|
|
316 | { |
|
|
317 | ob = observe = op; |
|
|
318 | ob->contr = this; /* this aren't yet in archetype */ |
|
|
319 | |
|
|
320 | ob->speed = 1.0f; |
|
|
321 | ob->speed_left = 0.5f; |
|
|
322 | |
|
|
323 | ob->direction = 5; /* So player faces south */ |
|
|
324 | } |
330 | } |
325 | |
331 | |
326 | void |
332 | void |
327 | player::set_observe (object *op) |
333 | player::set_observe (object *op) |
328 | { |
334 | { |
… | |
… | |
342 | savebed_map = first_map_path; /* Init. respawn position */ |
348 | savebed_map = first_map_path; /* Init. respawn position */ |
343 | |
349 | |
344 | gen_sp_armour = 10; |
350 | gen_sp_armour = 10; |
345 | bowtype = bow_normal; |
351 | bowtype = bow_normal; |
346 | petmode = pet_normal; |
352 | petmode = pet_normal; |
347 | listening = 10; |
|
|
348 | usekeys = containers; |
353 | usekeys = containers; |
349 | peaceful = 1; /* default peaceful */ |
354 | peaceful = 1; /* default peaceful */ |
350 | do_los = 1; |
355 | do_los = 1; |
351 | |
356 | |
352 | weapon_sp = 1.0f; |
357 | weapon_sp = 1.0f; |
… | |
… | |
361 | attachable::do_destroy (); |
366 | attachable::do_destroy (); |
362 | |
367 | |
363 | if (ob) |
368 | if (ob) |
364 | { |
369 | { |
365 | ob->destroy_inv (false); |
370 | ob->destroy_inv (false); |
366 | ob->destroy (); |
371 | ob->destroy (true); |
367 | } |
372 | } |
368 | |
373 | |
369 | ob = observe = 0; |
374 | ob = observe = 0; |
370 | } |
375 | } |
371 | |
376 | |
… | |
… | |
401 | * Note: there MUST be at least one player archetype! |
406 | * Note: there MUST be at least one player archetype! |
402 | */ |
407 | */ |
403 | archetype * |
408 | archetype * |
404 | get_player_archetype (archetype *at) |
409 | get_player_archetype (archetype *at) |
405 | { |
410 | { |
|
|
411 | // archetypes could have been reloaded |
|
|
412 | archetype *nat = at ? archetype::find (at->archname) : archetypes [0]; |
|
|
413 | |
|
|
414 | if (!nat) |
|
|
415 | return at; |
|
|
416 | |
406 | archvec::iterator i = at ? archetypes.find (at) : archetypes.begin (); |
417 | archvec::iterator i = archetypes.find (nat); |
407 | |
418 | |
408 | for (;;) |
419 | for (;;) |
409 | { |
420 | { |
410 | if (++i == archetypes.end ()) |
421 | if (++i == archetypes.end ()) |
411 | i = archetypes.begin (); |
422 | i = archetypes.begin (); |
… | |
… | |
629 | |
640 | |
630 | return firstdir; |
641 | return firstdir; |
631 | } |
642 | } |
632 | |
643 | |
633 | void |
644 | void |
634 | give_initial_items (object *pl, treasurelist * items) |
645 | give_initial_items (object *pl, treasurelist *items) |
635 | { |
646 | { |
636 | object *op, *next = NULL; |
|
|
637 | |
|
|
638 | if (pl->randomitems != NULL) |
647 | if (pl->randomitems) |
639 | create_treasure (items, pl, GT_STARTEQUIP | GT_ONLY_GOOD, 1, 0); |
648 | create_treasure (items, pl, GT_STARTEQUIP | GT_ONLY_GOOD, 1, 0); |
640 | |
649 | |
641 | for (op = pl->inv; op; op = next) |
650 | for (object *next, *op = pl->inv; op; op = next) |
642 | { |
651 | { |
643 | next = op->below; |
652 | next = op->below; |
644 | |
653 | |
645 | /* Forces get applied per default, unless they have the |
654 | /* Forces get applied per default, unless they have the |
646 | * flag "neutral" set. Sorry but I can't think of a better way |
655 | * flag "neutral" set. Sorry but I can't think of a better way |
… | |
… | |
651 | /* we never give weapons/armour if these cannot be used |
660 | /* we never give weapons/armour if these cannot be used |
652 | * by this player due to race restrictions |
661 | * by this player due to race restrictions |
653 | */ |
662 | */ |
654 | if (pl->type == PLAYER) |
663 | if (pl->type == PLAYER) |
655 | { |
664 | { |
656 | if ((!QUERY_FLAG (pl, FLAG_USE_ARMOUR) && |
665 | if ((!QUERY_FLAG (pl, FLAG_USE_ARMOUR) |
|
|
666 | && |
657 | (op->type == ARMOUR || op->type == BOOTS || |
667 | (op->type == ARMOUR || op->type == BOOTS |
658 | op->type == CLOAK || op->type == HELMET || |
668 | || op->type == CLOAK || op->type == HELMET |
659 | op->type == SHIELD || op->type == GLOVES || |
669 | || op->type == SHIELD || op->type == GLOVES |
|
|
670 | || op->type == BRACERS || op->type == GIRDLE)) |
660 | op->type == BRACERS || op->type == GIRDLE)) || (!QUERY_FLAG (pl, FLAG_USE_WEAPON) && op->type == WEAPON)) |
671 | || (!QUERY_FLAG (pl, FLAG_USE_WEAPON) && op->type == WEAPON)) |
661 | { |
672 | { |
662 | op->destroy (); |
673 | op->destroy (true); |
663 | continue; |
674 | continue; |
664 | } |
675 | } |
665 | } |
676 | } |
666 | |
677 | |
667 | /* This really needs to be better - we should really give |
678 | /* This really needs to be better - we should really give |
… | |
… | |
678 | if (tmp->type == op->type && tmp->name == op->name) |
689 | if (tmp->type == op->type && tmp->name == op->name) |
679 | break; |
690 | break; |
680 | |
691 | |
681 | if (tmp) |
692 | if (tmp) |
682 | { |
693 | { |
683 | op->destroy (); |
694 | op->destroy (true); |
684 | LOG (llevError, "give_initial_items: Removing duplicate object %s\n", &tmp->name); |
695 | LOG (llevError, "give_initial_items: Removing duplicate object %s\n", &tmp->name); |
685 | continue; |
696 | continue; |
686 | } |
697 | } |
687 | |
698 | |
688 | if (op->nrof > 1) |
699 | if (op->nrof > 1) |
689 | op->nrof = 1; |
700 | op->nrof = 1; |
690 | } |
701 | } |
691 | |
702 | |
692 | if (op->type == SPELLBOOK && op->inv) |
703 | if (op->type == SPELLBOOK && op->inv) |
693 | { |
|
|
694 | CLEAR_FLAG (op->inv, FLAG_STARTEQUIP); |
704 | CLEAR_FLAG (op->inv, FLAG_STARTEQUIP); |
695 | } |
|
|
696 | |
705 | |
697 | /* Give starting characters identified, uncursed, and undamned |
706 | /* Give starting characters identified, uncursed, and undamned |
698 | * items. Just don't identify gold or silver, or it won't be |
707 | * items. Just don't identify gold or silver, or it won't be |
699 | * merged properly. |
708 | * merged properly. |
700 | */ |
709 | */ |
701 | if (need_identify (op)) |
710 | if (need_identify (op)) |
702 | { |
711 | { |
703 | SET_FLAG (op, FLAG_IDENTIFIED); |
712 | SET_FLAG (op, FLAG_IDENTIFIED); |
704 | CLEAR_FLAG (op, FLAG_CURSED); |
713 | CLEAR_FLAG (op, FLAG_CURSED); |
705 | CLEAR_FLAG (op, FLAG_DAMNED); |
714 | CLEAR_FLAG (op, FLAG_DAMNED); |
706 | } |
715 | } |
|
|
716 | |
707 | if (op->type == SPELL) |
717 | if (op->type == SPELL) |
708 | { |
718 | { |
709 | op->destroy (); |
719 | op->destroy (true); |
710 | continue; |
720 | continue; |
711 | } |
721 | } |
712 | else if (op->type == SKILL) |
722 | else if (op->type == SKILL) |
713 | { |
723 | { |
714 | SET_FLAG (op, FLAG_CAN_USE_SKILL); |
724 | SET_FLAG (op, FLAG_CAN_USE_SKILL); |
715 | op->stats.exp = 0; |
725 | op->stats.exp = 0; |
716 | op->level = 1; |
726 | op->level = 1; |
717 | } |
727 | } |
718 | /* lock all 'normal items by default */ |
728 | else /* lock all 'normal items by default */ |
719 | else |
|
|
720 | SET_FLAG (op, FLAG_INV_LOCKED); |
729 | SET_FLAG (op, FLAG_INV_LOCKED); |
721 | } /* for loop of objects in player inv */ |
730 | } /* for loop of objects in player inv */ |
722 | |
731 | |
723 | /* Need to set up the skill pointers */ |
732 | /* Need to set up the skill pointers */ |
724 | link_player_skills (pl); |
733 | pl->contr->link_skills (); |
725 | } |
734 | } |
726 | |
735 | |
727 | void |
736 | void |
728 | get_party_password (object *op, partylist *party) |
737 | get_party_password (object *op, partylist *party) |
729 | { |
738 | { |
… | |
… | |
830 | static void |
839 | static void |
831 | start_info (object *op) |
840 | start_info (object *op) |
832 | { |
841 | { |
833 | char buf[MAX_BUF]; |
842 | char buf[MAX_BUF]; |
834 | |
843 | |
835 | sprintf (buf, "Welcome to Crossfire v%s!", VERSION); |
844 | sprintf (buf, "Welcome to Deliantra v%s!", VERSION); |
836 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
845 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
837 | //new_draw_info (NDI_UNIQUE, 0, op, "Press `?' for help"); |
|
|
838 | //new_draw_info (NDI_UNIQUE, 0, op, " "); |
|
|
839 | } |
846 | } |
840 | |
847 | |
841 | /* This function takes the key that is passed, and does the |
848 | /* This function takes the key that is passed, and does the |
842 | * appropriate action with it (change race, or other things). |
849 | * appropriate action with it (change race, or other things). |
843 | * The function name is for historical reasons - now we have |
850 | * The function name is for historical reasons - now we have |
… | |
… | |
846 | */ |
853 | */ |
847 | void |
854 | void |
848 | player::chargen_race_done () |
855 | player::chargen_race_done () |
849 | { |
856 | { |
850 | /* this must before then initial items are given */ |
857 | /* this must before then initial items are given */ |
851 | esrv_new_player (ob->contr, ob->weight + ob->carrying); |
858 | esrv_new_player (ob->contr); |
852 | |
859 | |
853 | treasurelist *tl = treasurelist::find ("starting_wealth"); |
860 | treasurelist *tl = treasurelist::find ("starting_wealth"); |
854 | if (tl) |
861 | if (tl) |
855 | create_treasure (tl, ob, 0, 0, 0); |
862 | create_treasure (tl, ob, 0, 0, 0); |
856 | |
863 | |
… | |
… | |
860 | ob->contr->ns->state = ST_PLAYING; |
867 | ob->contr->ns->state = ST_PLAYING; |
861 | |
868 | |
862 | if (ob->msg) |
869 | if (ob->msg) |
863 | ob->msg = 0; |
870 | ob->msg = 0; |
864 | |
871 | |
865 | /* We create this now because some of the unique maps will need it |
|
|
866 | * to save here. |
|
|
867 | */ |
|
|
868 | { |
|
|
869 | char buf[MAX_BUF]; |
|
|
870 | sprintf (buf, "%s/%s/%s", settings.localdir, settings.playerdir, &ob->name); |
|
|
871 | make_path_to_file (buf); |
|
|
872 | } |
|
|
873 | |
|
|
874 | start_info (ob); |
872 | start_info (ob); |
875 | CLEAR_FLAG (ob, FLAG_WIZ); |
873 | CLEAR_FLAG (ob, FLAG_WIZ); |
876 | give_initial_items (ob, ob->randomitems); |
874 | give_initial_items (ob, ob->randomitems); |
877 | link_player_skills (ob); |
|
|
878 | esrv_send_inventory (ob, ob); |
875 | esrv_send_inventory (ob, ob); |
879 | ob->update_stats (); |
876 | ob->update_stats (); |
880 | |
877 | |
881 | /* This moves the player to a different start map, if there |
878 | /* This moves the player to a different start map, if there |
882 | * is one for this race |
879 | * is one for this race |
883 | */ |
880 | */ |
884 | if (*first_map_ext_path) |
881 | if (*first_map_ext_path) |
885 | { |
882 | ob->player_goto (format ("%s/%s", &first_map_ext_path, &ob->arch->archname), ob->x, ob->y); |
886 | object *tmp; |
|
|
887 | char mapname[MAX_BUF]; |
|
|
888 | |
|
|
889 | snprintf (mapname, MAX_BUF - 1, "%s/%s", &first_map_ext_path, &ob->arch->archname); |
|
|
890 | tmp = object::create (); |
|
|
891 | EXIT_PATH (tmp) = mapname; |
|
|
892 | EXIT_X (tmp) = ob->x; |
|
|
893 | EXIT_Y (tmp) = ob->y; |
|
|
894 | ob->enter_exit (tmp); /* we don't really care if it succeeded; |
|
|
895 | * if the map isn't there, then stay on the |
|
|
896 | * default initial map */ |
|
|
897 | tmp->destroy (); |
|
|
898 | } |
|
|
899 | else |
883 | else |
900 | LOG (llevDebug, "first_map_ext_path not set\n"); |
884 | LOG (llevDebug, "first_map_ext_path not set\n"); |
901 | } |
885 | } |
902 | |
886 | |
903 | void |
887 | void |
… | |
… | |
1006 | if (op->move_type & MOVE_FLYING) |
990 | if (op->move_type & MOVE_FLYING) |
1007 | return 1; |
991 | return 1; |
1008 | |
992 | |
1009 | next = op->below; |
993 | next = op->below; |
1010 | |
994 | |
|
|
995 | int cnt = MAX_ITEM_PER_DROP; |
|
|
996 | #define CHK_PICK_PICKUP do { pick_up (op, tmp); cnt--; } while (0) |
|
|
997 | |
1011 | /* loop while there are items on the floor that are not marked as |
998 | /* loop while there are items on the floor that are not marked as |
1012 | * destroyed */ |
999 | * destroyed */ |
1013 | while (next && !next->destroyed ()) |
1000 | while (next && !next->destroyed ()) |
1014 | { |
1001 | { |
1015 | tmp = next; |
1002 | tmp = next; |
1016 | next = tmp->below; |
1003 | next = tmp->below; |
1017 | |
1004 | |
|
|
1005 | if (cnt <= 0) |
|
|
1006 | { |
|
|
1007 | op->failmsg ("Couldn't pickup all items at once."); |
|
|
1008 | return 0; |
|
|
1009 | } |
|
|
1010 | |
1018 | if (op->destroyed ()) |
1011 | if (op->destroyed ()) |
1019 | return 0; |
1012 | return 0; |
1020 | |
1013 | |
1021 | if (!can_pick (op, tmp)) |
1014 | if (!can_pick (op, tmp)) |
1022 | continue; |
1015 | continue; |
1023 | |
1016 | |
1024 | if (op->contr->search_str[0] != '\0' && settings.search_items == TRUE) |
1017 | if (op->contr->search_str[0] != '\0' && settings.search_items == TRUE) |
1025 | { |
1018 | { |
1026 | if (item_matched_string (op, tmp, op->contr->search_str)) |
1019 | if (item_matched_string (op, tmp, op->contr->search_str)) |
1027 | pick_up (op, tmp); |
1020 | CHK_PICK_PICKUP; |
1028 | continue; |
1021 | continue; |
1029 | } |
1022 | } |
1030 | |
1023 | |
1031 | /* high not bit set? We're using the old autopickup model */ |
1024 | /* high not bit set? We're using the old autopickup model */ |
1032 | if (!(op->contr->mode & PU_NEWMODE)) |
1025 | if (!(op->contr->mode & PU_NEWMODE)) |
… | |
… | |
1034 | switch (op->contr->mode) |
1027 | switch (op->contr->mode) |
1035 | { |
1028 | { |
1036 | case 0: |
1029 | case 0: |
1037 | return 1; /* don't pick up */ |
1030 | return 1; /* don't pick up */ |
1038 | case 1: |
1031 | case 1: |
1039 | pick_up (op, tmp); |
1032 | CHK_PICK_PICKUP; |
1040 | return 1; |
1033 | return 1; |
1041 | case 2: |
1034 | case 2: |
1042 | pick_up (op, tmp); |
1035 | CHK_PICK_PICKUP; |
1043 | return 0; |
1036 | return 0; |
1044 | case 3: |
1037 | case 3: |
1045 | return 0; /* stop before pickup */ |
1038 | return 0; /* stop before pickup */ |
1046 | case 4: |
1039 | case 4: |
1047 | pick_up (op, tmp); |
1040 | CHK_PICK_PICKUP; |
1048 | break; |
1041 | break; |
1049 | case 5: |
1042 | case 5: |
1050 | pick_up (op, tmp); |
1043 | CHK_PICK_PICKUP; |
1051 | stop = 1; |
1044 | stop = 1; |
1052 | break; |
1045 | break; |
1053 | case 6: |
1046 | case 6: |
1054 | if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)) |
1047 | if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) |
1055 | pick_up (op, tmp); |
1048 | && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)) |
|
|
1049 | CHK_PICK_PICKUP; |
1056 | break; |
1050 | break; |
1057 | |
1051 | |
1058 | case 7: |
1052 | case 7: |
1059 | if (tmp->type == MONEY || tmp->type == GEM) |
1053 | if (tmp->type == MONEY || tmp->type == GEM) |
1060 | pick_up (op, tmp); |
1054 | CHK_PICK_PICKUP; |
1061 | break; |
1055 | break; |
1062 | |
1056 | |
1063 | default: |
1057 | default: |
1064 | /* use value density */ |
1058 | /* use value density */ |
1065 | if (!QUERY_FLAG (tmp, FLAG_UNPAID) |
1059 | if (!QUERY_FLAG (tmp, FLAG_UNPAID) |
1066 | && (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))) >= op->contr->mode) |
1060 | && (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))) >= op->contr->mode) |
1067 | pick_up (op, tmp); |
1061 | CHK_PICK_PICKUP; |
1068 | } |
1062 | } |
1069 | } |
1063 | } |
1070 | else |
1064 | else |
1071 | { /* old model */ |
1065 | { /* old model */ |
1072 | /* NEW pickup handling */ |
1066 | /* NEW pickup handling */ |
… | |
… | |
1127 | /* all food and drink if desired */ |
1121 | /* all food and drink if desired */ |
1128 | /* question: don't pick up known-poisonous stuff? */ |
1122 | /* question: don't pick up known-poisonous stuff? */ |
1129 | if (op->contr->mode & PU_FOOD) |
1123 | if (op->contr->mode & PU_FOOD) |
1130 | if (tmp->type == FOOD) |
1124 | if (tmp->type == FOOD) |
1131 | { |
1125 | { |
1132 | pick_up (op, tmp); |
1126 | CHK_PICK_PICKUP; |
1133 | continue; |
1127 | continue; |
1134 | } |
1128 | } |
1135 | |
1129 | |
1136 | if (op->contr->mode & PU_DRINK) |
1130 | if (op->contr->mode & PU_DRINK) |
1137 | if (tmp->type == DRINK || (tmp->type == POISON && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))) |
1131 | if (tmp->type == DRINK || (tmp->type == POISON && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))) |
1138 | { |
1132 | { |
1139 | pick_up (op, tmp); |
1133 | CHK_PICK_PICKUP; |
1140 | continue; |
1134 | continue; |
1141 | } |
1135 | } |
1142 | |
1136 | |
1143 | if (op->contr->mode & PU_POTION) |
1137 | if (op->contr->mode & PU_POTION) |
1144 | if (tmp->type == POTION) |
1138 | if (tmp->type == POTION) |
1145 | { |
1139 | { |
1146 | pick_up (op, tmp); |
1140 | CHK_PICK_PICKUP; |
1147 | continue; |
1141 | continue; |
1148 | } |
1142 | } |
1149 | |
1143 | |
1150 | /* spellbooks, skillscrolls and normal books/scrolls */ |
1144 | /* spellbooks, skillscrolls and normal books/scrolls */ |
1151 | if (op->contr->mode & PU_SPELLBOOK) |
1145 | if (op->contr->mode & PU_SPELLBOOK) |
1152 | if (tmp->type == SPELLBOOK) |
1146 | if (tmp->type == SPELLBOOK) |
1153 | { |
1147 | { |
1154 | pick_up (op, tmp); |
1148 | CHK_PICK_PICKUP; |
1155 | continue; |
1149 | continue; |
1156 | } |
1150 | } |
1157 | |
1151 | |
1158 | if (op->contr->mode & PU_SKILLSCROLL) |
1152 | if (op->contr->mode & PU_SKILLSCROLL) |
1159 | if (tmp->type == SKILLSCROLL) |
1153 | if (tmp->type == SKILLSCROLL) |
1160 | { |
1154 | { |
1161 | pick_up (op, tmp); |
1155 | CHK_PICK_PICKUP; |
1162 | continue; |
1156 | continue; |
1163 | } |
1157 | } |
1164 | |
1158 | |
1165 | if (op->contr->mode & PU_READABLES) |
1159 | if (op->contr->mode & PU_READABLES) |
1166 | if (tmp->type == BOOK || tmp->type == SCROLL || tmp->type == INSCRIBABLE) |
1160 | if (tmp->type == BOOK || tmp->type == SCROLL || tmp->type == INSCRIBABLE) |
1167 | { |
1161 | { |
1168 | pick_up (op, tmp); |
1162 | CHK_PICK_PICKUP; |
1169 | continue; |
1163 | continue; |
1170 | } |
1164 | } |
1171 | |
1165 | |
1172 | /* wands/staves/rods/horns */ |
1166 | /* wands/staves/rods/horns */ |
1173 | if (op->contr->mode & PU_MAGIC_DEVICE) |
1167 | if (op->contr->mode & PU_MAGIC_DEVICE) |
1174 | if (tmp->type == WAND || tmp->type == ROD || tmp->type == HORN) |
1168 | if (tmp->type == WAND || tmp->type == ROD || tmp->type == HORN) |
1175 | { |
1169 | { |
1176 | pick_up (op, tmp); |
1170 | CHK_PICK_PICKUP; |
1177 | continue; |
1171 | continue; |
1178 | } |
1172 | } |
1179 | |
1173 | |
1180 | /* pick up all magical items */ |
1174 | /* pick up all magical items */ |
1181 | if (op->contr->mode & PU_MAGICAL) |
1175 | if (op->contr->mode & PU_MAGICAL) |
1182 | if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)) |
1176 | if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)) |
1183 | { |
1177 | { |
1184 | pick_up (op, tmp); |
1178 | CHK_PICK_PICKUP; |
1185 | continue; |
1179 | continue; |
1186 | } |
1180 | } |
1187 | |
1181 | |
1188 | if (op->contr->mode & PU_VALUABLES) |
1182 | if (op->contr->mode & PU_VALUABLES) |
1189 | { |
1183 | { |
1190 | if (tmp->type == MONEY || tmp->type == GEM) |
1184 | if (tmp->type == MONEY || tmp->type == GEM) |
1191 | { |
1185 | { |
1192 | pick_up (op, tmp); |
1186 | CHK_PICK_PICKUP; |
1193 | continue; |
1187 | continue; |
1194 | } |
1188 | } |
1195 | } |
1189 | } |
1196 | |
1190 | |
1197 | /* rings & amulets - talismans seems to be typed AMULET */ |
1191 | /* rings & amulets - talismans seems to be typed AMULET */ |
1198 | if (op->contr->mode & PU_JEWELS) |
1192 | if (op->contr->mode & PU_JEWELS) |
1199 | if (tmp->type == RING || tmp->type == AMULET) |
1193 | if (tmp->type == RING || tmp->type == AMULET) |
1200 | { |
1194 | { |
1201 | pick_up (op, tmp); |
1195 | CHK_PICK_PICKUP; |
1202 | continue; |
1196 | continue; |
1203 | } |
1197 | } |
1204 | |
1198 | |
1205 | /* we don't forget dragon food */ |
1199 | /* we don't forget dragon food */ |
1206 | if (op->contr->mode & PU_FLESH) |
1200 | if (op->contr->mode & PU_FLESH) |
1207 | if (tmp->type == FLESH) |
1201 | if (tmp->type == FLESH) |
1208 | { |
1202 | { |
1209 | pick_up (op, tmp); |
1203 | CHK_PICK_PICKUP; |
1210 | continue; |
1204 | continue; |
1211 | } |
1205 | } |
1212 | |
1206 | |
1213 | /* bows and arrows. Bows are good for selling! */ |
1207 | /* bows and arrows. Bows are good for selling! */ |
1214 | if (op->contr->mode & PU_BOW) |
1208 | if (op->contr->mode & PU_BOW) |
1215 | if (tmp->type == BOW) |
1209 | if (tmp->type == BOW) |
1216 | { |
1210 | { |
1217 | pick_up (op, tmp); |
1211 | CHK_PICK_PICKUP; |
1218 | continue; |
1212 | continue; |
1219 | } |
1213 | } |
1220 | |
1214 | |
1221 | if (op->contr->mode & PU_ARROW) |
1215 | if (op->contr->mode & PU_ARROW) |
1222 | if (tmp->type == ARROW) |
1216 | if (tmp->type == ARROW) |
1223 | { |
1217 | { |
1224 | pick_up (op, tmp); |
1218 | CHK_PICK_PICKUP; |
1225 | continue; |
1219 | continue; |
1226 | } |
1220 | } |
1227 | |
1221 | |
1228 | /* all kinds of armor etc. */ |
1222 | /* all kinds of armor etc. */ |
1229 | if (op->contr->mode & PU_ARMOUR) |
1223 | if (op->contr->mode & PU_ARMOUR) |
1230 | if (tmp->type == ARMOUR) |
1224 | if (tmp->type == ARMOUR) |
1231 | { |
1225 | { |
1232 | pick_up (op, tmp); |
1226 | CHK_PICK_PICKUP; |
1233 | continue; |
1227 | continue; |
1234 | } |
1228 | } |
1235 | |
1229 | |
1236 | if (op->contr->mode & PU_HELMET) |
1230 | if (op->contr->mode & PU_HELMET) |
1237 | if (tmp->type == HELMET) |
1231 | if (tmp->type == HELMET) |
1238 | { |
1232 | { |
1239 | pick_up (op, tmp); |
1233 | CHK_PICK_PICKUP; |
1240 | continue; |
1234 | continue; |
1241 | } |
1235 | } |
1242 | |
1236 | |
1243 | if (op->contr->mode & PU_SHIELD) |
1237 | if (op->contr->mode & PU_SHIELD) |
1244 | if (tmp->type == SHIELD) |
1238 | if (tmp->type == SHIELD) |
1245 | { |
1239 | { |
1246 | pick_up (op, tmp); |
1240 | CHK_PICK_PICKUP; |
1247 | continue; |
1241 | continue; |
1248 | } |
1242 | } |
1249 | |
1243 | |
1250 | if (op->contr->mode & PU_BOOTS) |
1244 | if (op->contr->mode & PU_BOOTS) |
1251 | if (tmp->type == BOOTS) |
1245 | if (tmp->type == BOOTS) |
1252 | { |
1246 | { |
1253 | pick_up (op, tmp); |
1247 | CHK_PICK_PICKUP; |
1254 | continue; |
1248 | continue; |
1255 | } |
1249 | } |
1256 | |
1250 | |
1257 | if (op->contr->mode & PU_GLOVES) |
1251 | if (op->contr->mode & PU_GLOVES) |
1258 | if (tmp->type == GLOVES) |
1252 | if (tmp->type == GLOVES) |
1259 | { |
1253 | { |
1260 | pick_up (op, tmp); |
1254 | CHK_PICK_PICKUP; |
1261 | continue; |
1255 | continue; |
1262 | } |
1256 | } |
1263 | |
1257 | |
1264 | if (op->contr->mode & PU_CLOAK) |
1258 | if (op->contr->mode & PU_CLOAK) |
1265 | if (tmp->type == CLOAK) |
1259 | if (tmp->type == CLOAK) |
1266 | { |
1260 | { |
1267 | pick_up (op, tmp); |
1261 | CHK_PICK_PICKUP; |
1268 | continue; |
1262 | continue; |
1269 | } |
1263 | } |
1270 | |
1264 | |
1271 | /* hoping to catch throwing daggers here */ |
1265 | /* hoping to catch throwing daggers here */ |
1272 | if (op->contr->mode & PU_MISSILEWEAPON) |
1266 | if (op->contr->mode & PU_MISSILEWEAPON) |
1273 | if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_IS_THROWN)) |
1267 | if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_IS_THROWN)) |
1274 | { |
1268 | { |
1275 | pick_up (op, tmp); |
1269 | CHK_PICK_PICKUP; |
1276 | continue; |
1270 | continue; |
1277 | } |
1271 | } |
1278 | |
1272 | |
1279 | /* careful: chairs and tables are weapons! */ |
1273 | /* careful: chairs and tables are weapons! */ |
1280 | if (op->contr->mode & PU_ALLWEAPON) |
1274 | if (op->contr->mode & PU_ALLWEAPON) |
… | |
… | |
1282 | if (tmp->type == WEAPON && tmp->name != NULL) |
1276 | if (tmp->type == WEAPON && tmp->name != NULL) |
1283 | { |
1277 | { |
1284 | if (strstr (tmp->name, "table") == NULL && strstr (tmp->arch->archname, "table") == NULL && |
1278 | if (strstr (tmp->name, "table") == NULL && strstr (tmp->arch->archname, "table") == NULL && |
1285 | strstr (tmp->name, "chair") && strstr (tmp->arch->archname, "chair") == NULL) |
1279 | strstr (tmp->name, "chair") && strstr (tmp->arch->archname, "chair") == NULL) |
1286 | { |
1280 | { |
1287 | pick_up (op, tmp); |
1281 | CHK_PICK_PICKUP; |
1288 | continue; |
1282 | continue; |
1289 | } |
1283 | } |
1290 | } |
1284 | } |
1291 | |
1285 | |
1292 | if (tmp->type == WEAPON && tmp->name == NULL) |
1286 | if (tmp->type == WEAPON && tmp->name == NULL) |
1293 | { |
1287 | { |
1294 | if (strstr (tmp->arch->archname, "table") == NULL && strstr (tmp->arch->archname, "chair") == NULL) |
1288 | if (strstr (tmp->arch->archname, "table") == NULL && strstr (tmp->arch->archname, "chair") == NULL) |
1295 | { |
1289 | { |
1296 | pick_up (op, tmp); |
1290 | CHK_PICK_PICKUP; |
1297 | continue; |
1291 | continue; |
1298 | } |
1292 | } |
1299 | } |
1293 | } |
1300 | } |
1294 | } |
1301 | |
1295 | |
1302 | /* misc stuff that's useful */ |
1296 | /* misc stuff that's useful */ |
1303 | if (op->contr->mode & PU_KEY) |
1297 | if (op->contr->mode & PU_KEY) |
1304 | if (tmp->type == KEY || tmp->type == SPECIAL_KEY) |
1298 | if (tmp->type == KEY || tmp->type == SPECIAL_KEY) |
1305 | { |
1299 | { |
1306 | pick_up (op, tmp); |
1300 | CHK_PICK_PICKUP; |
1307 | continue; |
1301 | continue; |
1308 | } |
1302 | } |
1309 | |
1303 | |
1310 | /* any of the last 4 bits set means we use the ratio for value |
1304 | /* any of the last 4 bits set means we use the ratio for value |
1311 | * pickups */ |
1305 | * pickups */ |
1312 | if (op->contr->mode & PU_RATIO) |
1306 | if (op->contr->mode & PU_RATIO) |
1313 | { |
1307 | { |
1314 | /* use value density to decide what else to grab */ |
1308 | /* use value density to decide what else to grab */ |
1315 | /* >=7 was >= op->contr->mode */ |
1309 | /* >=7 was >= op->contr->mode */ |
1316 | /* >=7 is the old standard setting. Now we take the last 4 bits |
1310 | /* >=7 is the old standard setting. Now we take the last 4 bits |
1317 | * and multiply them by 5, giving 0..15*5== 5..75 */ |
1311 | */ |
1318 | wvratio = (op->contr->mode & PU_RATIO) * 5; |
1312 | wvratio = op->contr->mode & PU_RATIO; |
1319 | if ((query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))) >= (unsigned int) wvratio) |
1313 | if (1000 * query_cost (tmp, op, F_TRUE) / tmp->total_weight () >= wvratio * 100) |
1320 | { |
1314 | { |
1321 | pick_up (op, tmp); |
1315 | CHK_PICK_PICKUP; |
1322 | #if 0 |
1316 | #if 0 |
1323 | fprintf (stderr, "HIGH WEIGHT/VALUE ["); |
1317 | fprintf (stderr, "HIGH WEIGHT/VALUE ["); |
1324 | if (tmp->name != NULL) |
1318 | if (tmp->name != NULL) |
1325 | { |
1319 | { |
1326 | fprintf (stderr, "%s", tmp->name); |
1320 | fprintf (stderr, "%s", tmp->name); |
… | |
… | |
1345 | * found object is returned. |
1339 | * found object is returned. |
1346 | */ |
1340 | */ |
1347 | object * |
1341 | object * |
1348 | find_arrow (object *op, const char *type) |
1342 | find_arrow (object *op, const char *type) |
1349 | { |
1343 | { |
1350 | object *tmp = 0; |
|
|
1351 | |
|
|
1352 | for (op = op->inv; op; op = op->below) |
1344 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
1353 | if (!tmp && op->type == CONTAINER && op->race == type && QUERY_FLAG (op, FLAG_APPLIED)) |
|
|
1354 | tmp = find_arrow (op, type); |
|
|
1355 | else if (op->type == ARROW && op->race == type) |
1345 | if (tmp->type == ARROW && !strcmp (&tmp->race, type)) |
|
|
1346 | return splay (tmp); |
|
|
1347 | |
|
|
1348 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
|
|
1349 | if (tmp->type == CONTAINER && QUERY_FLAG (tmp, FLAG_APPLIED) && !strcmp (&tmp->race, type)) |
|
|
1350 | if (object *arrow = find_arrow (tmp, type)) |
|
|
1351 | { |
|
|
1352 | splay (tmp); |
1356 | return op; |
1353 | return arrow; |
|
|
1354 | } |
1357 | |
1355 | |
1358 | return tmp; |
1356 | return 0; |
1359 | } |
1357 | } |
1360 | |
1358 | |
1361 | /* |
1359 | /* |
1362 | * Similar to find_arrow, but looks for (roughly) the best arrow to use |
1360 | * Similar to find_arrow, but looks for (roughly) the best arrow to use |
1363 | * against the target. A full test is not performed, simply a basic test |
1361 | * against the target. A full test is not performed, simply a basic test |
… | |
… | |
1386 | } |
1384 | } |
1387 | } |
1385 | } |
1388 | else if (arrow->type == ARROW && arrow->race == type) |
1386 | else if (arrow->type == ARROW && arrow->race == type) |
1389 | { |
1387 | { |
1390 | /* allways prefer assasination/slaying */ |
1388 | /* allways prefer assasination/slaying */ |
1391 | if (target->race != NULL && arrow->slaying != NULL && strstr (arrow->slaying, target->race)) |
1389 | if (target->race && arrow->slaying && strstr (arrow->slaying, target->race)) |
1392 | { |
1390 | { |
1393 | if (arrow->attacktype & AT_DEATH) |
1391 | if (arrow->attacktype & AT_DEATH) |
1394 | { |
1392 | { |
1395 | *better = 100; |
1393 | *better = 100; |
1396 | return arrow; |
1394 | return arrow; |
… | |
… | |
1424 | betterby = 1 + arrow->magic + arrow->stats.dam; |
1422 | betterby = 1 + arrow->magic + arrow->stats.dam; |
1425 | } |
1423 | } |
1426 | } |
1424 | } |
1427 | } |
1425 | } |
1428 | } |
1426 | } |
|
|
1427 | |
1429 | if (tmp == NULL && arrow == NULL) |
1428 | if (tmp == NULL && arrow == NULL) |
1430 | return find_arrow (op, type); |
1429 | return find_arrow (op, type); |
1431 | |
1430 | |
1432 | *better = betterby; |
1431 | *better = betterby; |
1433 | return tmp; |
1432 | return tmp; |
… | |
… | |
1579 | } |
1578 | } |
1580 | |
1579 | |
1581 | /* this should not happen, but sometimes does */ |
1580 | /* this should not happen, but sometimes does */ |
1582 | if (arrow->nrof == 0) |
1581 | if (arrow->nrof == 0) |
1583 | { |
1582 | { |
|
|
1583 | LOG (llevError | logBacktrace, "arrow (%s) has nrof 0\n", arrow->debug_desc ()); |
1584 | arrow->destroy (); |
1584 | arrow->destroy (true); |
1585 | return 0; |
1585 | return 0; |
1586 | } |
1586 | } |
1587 | |
1587 | |
1588 | left = arrow; /* these are arrows left to the player */ |
1588 | left = arrow; /* these are arrows left to the player */ |
1589 | arrow = get_split_ob (arrow, 1); |
1589 | arrow = arrow->split (); |
1590 | if (!arrow) |
1590 | if (!arrow) |
1591 | { |
1591 | { |
1592 | new_draw_info_format (NDI_UNIQUE, 0, op, "You have no %s left.", &bow->race); |
1592 | new_draw_info_format (NDI_UNIQUE, 0, op, "You have no %s left.", &bow->race); |
1593 | return 0; |
1593 | return 0; |
1594 | } |
1594 | } |
… | |
… | |
1661 | op->play_sound (sound_find ("fire_arrow")); |
1661 | op->play_sound (sound_find ("fire_arrow")); |
1662 | m->insert (arrow, sx, sy, op); |
1662 | m->insert (arrow, sx, sy, op); |
1663 | |
1663 | |
1664 | if (!arrow->destroyed ()) |
1664 | if (!arrow->destroyed ()) |
1665 | move_arrow (arrow); |
1665 | move_arrow (arrow); |
1666 | |
|
|
1667 | if (op->type == PLAYER) |
|
|
1668 | { |
|
|
1669 | if (left->destroyed ()) |
|
|
1670 | esrv_del_item (op->contr, left->count); |
|
|
1671 | else |
|
|
1672 | esrv_send_item (op, left); |
|
|
1673 | } |
|
|
1674 | |
1666 | |
1675 | return 1; |
1667 | return 1; |
1676 | } |
1668 | } |
1677 | |
1669 | |
1678 | /* Special fire code for players - this takes into |
1670 | /* Special fire code for players - this takes into |
… | |
… | |
1752 | return; |
1744 | return; |
1753 | } |
1745 | } |
1754 | } |
1746 | } |
1755 | else if (item->type == ROD || item->type == HORN) |
1747 | else if (item->type == ROD || item->type == HORN) |
1756 | { |
1748 | { |
1757 | if (item->stats.hp < MAX (item->inv->stats.sp, item->inv->stats.grace)) |
1749 | sint16 spell_sp = MAX (item->inv->stats.sp, item->inv->stats.grace); |
|
|
1750 | |
|
|
1751 | // using the maximum of the rods charge allows at least one spell cast |
|
|
1752 | // for a rod or horn, this fixes some broken rods. |
|
|
1753 | if (item->stats.hp < MIN (spell_sp, item->stats.maxhp)) |
1758 | { |
1754 | { |
1759 | op->contr->play_sound (sound_find ("wand_poof")); |
1755 | op->contr->play_sound (sound_find ("wand_poof")); |
1760 | |
1756 | |
1761 | if (item->type == ROD) |
1757 | if (item->type == ROD) |
1762 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s whines for a while, but nothing happens.", query_base_name (item, 0)); |
1758 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s whines for a while, but nothing happens.", query_base_name (item, 0)); |
… | |
… | |
1781 | CLEAR_FLAG (item, FLAG_ANIMATE); |
1777 | CLEAR_FLAG (item, FLAG_ANIMATE); |
1782 | item->face = item->arch->face; |
1778 | item->face = item->arch->face; |
1783 | item->set_speed (0); |
1779 | item->set_speed (0); |
1784 | } |
1780 | } |
1785 | |
1781 | |
1786 | if ((tmp = item->in_player ())) |
1782 | if (object *pl = item->visible_to ()) |
1787 | esrv_update_item (UPD_ANIM, tmp, item); |
1783 | esrv_update_item (UPD_ANIM, pl, item); |
1788 | } |
1784 | } |
1789 | } |
1785 | } |
1790 | else if (item->type == ROD || item->type == HORN) |
1786 | else if (item->type == ROD || item->type == HORN) |
1791 | drain_rod_charge (item); |
1787 | drain_rod_charge (item); |
1792 | } |
1788 | } |
… | |
… | |
1963 | |
1959 | |
1964 | if (door->type == DOOR) |
1960 | if (door->type == DOOR) |
1965 | hit_player (door, 9998, op, AT_PHYSICAL, 1); /* Break through the door */ |
1961 | hit_player (door, 9998, op, AT_PHYSICAL, 1); /* Break through the door */ |
1966 | else if (door->type == LOCKED_DOOR) |
1962 | else if (door->type == LOCKED_DOOR) |
1967 | { |
1963 | { |
1968 | new_draw_info_format (NDI_UNIQUE, NDI_BROWN, op, "You open the door with the %s", query_short_name (key)); |
1964 | op->statusmsg (format ("You open the door with the %s", query_short_name (key)), NDI_BROWN); |
1969 | remove_door2 (door); /* remove door without violence ;-) */ |
1965 | remove_door2 (door); /* remove door without violence ;-) */ |
1970 | } |
1966 | } |
1971 | |
1967 | |
1972 | /* Do this after we print the message */ |
1968 | /* Do this after we print the message */ |
1973 | decrease_ob (key); /* Use up one of the keys */ |
1969 | key->decrease (); /* Use up one of the keys */ |
1974 | /* Need to update the weight the container the key was in */ |
|
|
1975 | if (container != op) |
|
|
1976 | esrv_update_item (UPD_WEIGHT, op, container); |
|
|
1977 | |
1970 | |
1978 | return 1; /* Nothing more to do below */ |
1971 | return 1; /* Nothing more to do below */ |
1979 | } |
1972 | } |
1980 | else if (door->type == LOCKED_DOOR) |
1973 | else if (door->type == LOCKED_DOOR) |
1981 | { |
1974 | { |
1982 | /* Might as well return now - no other way to open this */ |
1975 | /* Might as well return now - no other way to open this */ |
1983 | new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, door->msg); |
1976 | op->failmsg (door->msg ? &door->msg : "Hmm, you miss the certain something to open this door..."); |
1984 | return 1; |
1977 | return 1; |
1985 | } |
1978 | } |
1986 | |
1979 | |
1987 | return 0; |
1980 | return 0; |
1988 | } |
1981 | } |
… | |
… | |
2108 | { |
2101 | { |
2109 | op->play_sound (sound_find ("push_player")); |
2102 | op->play_sound (sound_find ("push_player")); |
2110 | push_ob (mon, dir, op); |
2103 | push_ob (mon, dir, op); |
2111 | } |
2104 | } |
2112 | else |
2105 | else |
2113 | new_draw_info (0, 0, op, "You withhold your attack"); |
2106 | op->statusmsg ("You withhold your attack"); |
2114 | |
2107 | |
2115 | if (op->contr->tmp_invis || op->hide) |
2108 | if (op->contr->tmp_invis || op->hide) |
2116 | make_visible (op); |
2109 | make_visible (op); |
2117 | |
2110 | |
2118 | return true; |
2111 | return true; |
… | |
… | |
2162 | bool |
2155 | bool |
2163 | move_player (object *op, int dir) |
2156 | move_player (object *op, int dir) |
2164 | { |
2157 | { |
2165 | int pick; |
2158 | int pick; |
2166 | |
2159 | |
2167 | if (!op->map || op->map->in_memory != MAP_IN_MEMORY) |
2160 | if (!op->map || op->map->in_memory != MAP_ACTIVE) |
2168 | return 0; |
2161 | return 0; |
2169 | |
2162 | |
2170 | /* Sanity check: make sure dir is valid */ |
2163 | /* Sanity check: make sure dir is valid */ |
2171 | if ((dir < 0) || (dir >= 9)) |
2164 | if ((dir < 0) || (dir >= 9)) |
2172 | { |
2165 | { |
… | |
… | |
2260 | if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE)) |
2253 | if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE)) |
2261 | { |
2254 | { |
2262 | op->play_sound (sound_find ("ob_evaporate")); |
2255 | op->play_sound (sound_find ("ob_evaporate")); |
2263 | new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s vibrates violently, then evaporates.", query_name (tmp)); |
2256 | new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s vibrates violently, then evaporates.", query_name (tmp)); |
2264 | |
2257 | |
2265 | if (op->contr) |
|
|
2266 | esrv_del_item (op->contr, tmp->count); |
|
|
2267 | |
|
|
2268 | tmp->destroy (); |
2258 | tmp->destroy (true); |
2269 | CLEAR_FLAG (op, FLAG_LIFESAVE); |
2259 | CLEAR_FLAG (op, FLAG_LIFESAVE); |
2270 | |
2260 | |
2271 | if (op->stats.hp < 0) |
2261 | if (op->stats.hp < 0) |
2272 | op->stats.hp = op->stats.maxhp; |
2262 | op->stats.hp = op->stats.maxhp; |
2273 | |
2263 | |
… | |
… | |
2284 | return 0; |
2274 | return 0; |
2285 | } |
2275 | } |
2286 | |
2276 | |
2287 | /* This goes throws the inventory and removes unpaid objects, and puts them |
2277 | /* This goes throws the inventory and removes unpaid objects, and puts them |
2288 | * back in the map (location and map determined by values of env). This |
2278 | * back in the map (location and map determined by values of env). This |
2289 | * function will descend into containers. op is the object to start the search |
2279 | * function will descend into containers. op is the object to start the search |
2290 | * from. |
2280 | * from. |
2291 | */ |
2281 | */ |
2292 | static void |
2282 | static void |
2293 | drop_unpaid_items (object *op, object *env) |
2283 | drop_unpaid_items (object *op, object *env) |
2294 | { |
2284 | { |
2295 | while (op) |
2285 | while (op) |
2296 | { |
2286 | { |
2297 | object *next = op->below; /* Make sure we have a good value, in case we remove object 'op' */ |
2287 | object *next = op->below; /* Make sure we have a good value, in case we remove object 'op' */ |
2298 | |
2288 | |
2299 | if (QUERY_FLAG (op, FLAG_UNPAID)) |
2289 | if (QUERY_FLAG (op, FLAG_UNPAID)) |
2300 | { |
|
|
2301 | if (env->type == PLAYER) |
|
|
2302 | esrv_del_item (env->contr, op->count); |
|
|
2303 | |
|
|
2304 | op->insert_at (env); |
2290 | op->insert_at (env); |
2305 | } |
|
|
2306 | else if (op->inv) |
2291 | else if (op->inv) |
2307 | drop_unpaid_items (op->inv, env); |
2292 | drop_unpaid_items (op->inv, env); |
2308 | |
2293 | |
2309 | op = next; |
2294 | op = next; |
2310 | } |
2295 | } |
… | |
… | |
2322 | * Moved from apply.c to player.c - player.c is what |
2307 | * Moved from apply.c to player.c - player.c is what |
2323 | * actually uses this function. player.c may not be quite the |
2308 | * actually uses this function. player.c may not be quite the |
2324 | * best, a misc file for object actions is probably better, |
2309 | * best, a misc file for object actions is probably better, |
2325 | * but there isn't one in the server directory. |
2310 | * but there isn't one in the server directory. |
2326 | */ |
2311 | */ |
2327 | char * |
2312 | const char * |
2328 | gravestone_text (object *op) |
2313 | gravestone_text (object *op) |
2329 | { |
2314 | { |
2330 | static char buf2[MAX_BUF]; |
2315 | static dynbuf_text buf; |
2331 | char buf[MAX_BUF]; |
|
|
2332 | time_t now = time (NULL); |
|
|
2333 | |
2316 | |
2334 | strcpy (buf2, " R.I.P.\n\n"); |
2317 | buf << "---- R.I.P. ----\n\n" |
|
|
2318 | << op->name; |
|
|
2319 | |
2335 | if (op->type == PLAYER) |
2320 | if (op->type == PLAYER) |
2336 | sprintf (buf, "%s the %s\n", &op->name, op->contr->title); |
2321 | buf << " the " << op->contr->title; |
2337 | else |
|
|
2338 | sprintf (buf, "%s\n", &op->name); |
|
|
2339 | |
2322 | |
2340 | strncat (buf2, " ", 20 - strlen (buf) / 2); |
2323 | buf << "\n\n"; |
2341 | strcat (buf2, buf); |
2324 | |
|
|
2325 | buf << "who was level "; |
|
|
2326 | buf << (sint32)op->level << "\n\n" // OO breakdown |
|
|
2327 | << " when " << (op->contr ? "killed" : "died") << "\n\n"; |
|
|
2328 | |
2342 | if (op->type == PLAYER) |
2329 | if (op->type == PLAYER) |
2343 | sprintf (buf, "who was in level %d when killed\n", op->level); |
2330 | buf << "by " << op->contr->killer_name () << ".\n\n"; |
2344 | else |
|
|
2345 | sprintf (buf, "who was in level %d when died.\n\n", op->level); |
|
|
2346 | |
2331 | |
2347 | strncat (buf2, " ", 20 - strlen (buf) / 2); |
|
|
2348 | strcat (buf2, buf); |
|
|
2349 | if (op->type == PLAYER) |
|
|
2350 | { |
2332 | { |
2351 | sprintf (buf, "by %s.\n\n", op->contr->killer); |
2333 | static char buf2[128]; |
2352 | strncat (buf2, " ", 21 - strlen (buf) / 2); |
2334 | time_t now = time (NULL); |
2353 | strcat (buf2, buf); |
|
|
2354 | } |
|
|
2355 | |
|
|
2356 | strftime (buf, MAX_BUF, "%b %d %Y\n", localtime (&now)); |
2335 | strftime (buf2, 128, "%b %d %Y\n\n", localtime (&now)); |
2357 | strncat (buf2, " ", 20 - strlen (buf) / 2); |
2336 | buf << buf2; |
2358 | strcat (buf2, buf); |
2337 | } |
2359 | |
2338 | |
2360 | return buf2; |
2339 | return buf; |
2361 | } |
2340 | } |
2362 | |
2341 | |
2363 | void |
2342 | void |
2364 | do_some_living (object *op) |
2343 | do_some_living (object *op) |
2365 | { |
2344 | { |
… | |
… | |
2546 | op->stats.food--; |
2525 | op->stats.food--; |
2547 | } |
2526 | } |
2548 | |
2527 | |
2549 | if (op->stats.food < 0 && op->stats.hp >= 0) |
2528 | if (op->stats.food < 0 && op->stats.hp >= 0) |
2550 | { |
2529 | { |
2551 | object *tmp, *flesh = 0; |
2530 | object *flesh = 0; |
2552 | |
2531 | |
2553 | for (tmp = op->inv; tmp; tmp = tmp->below) |
2532 | for_inv_removable (op, tmp) |
2554 | { |
2533 | { |
2555 | if (!QUERY_FLAG (tmp, FLAG_UNPAID)) |
2534 | if (QUERY_FLAG (tmp, FLAG_UNPAID)) |
|
|
2535 | continue; |
|
|
2536 | |
|
|
2537 | if (tmp->type == FOOD || tmp->type == DRINK || tmp->type == POISON) |
2556 | { |
2538 | { |
2557 | if (tmp->type == FOOD || tmp->type == DRINK || tmp->type == POISON) |
2539 | op->statusmsg ("You blindly grab for a bite of food. " |
2558 | { |
2540 | "H<To prevent you from starving, you ate some random item from your backpack.>"); |
2559 | new_draw_info (NDI_UNIQUE, 0, op, "You blindly grab for a bite of food."); |
|
|
2560 | manual_apply (op, tmp, 0); |
2541 | manual_apply (op, tmp, 0); |
|
|
2542 | |
2561 | if (op->stats.food >= 0 || op->stats.hp < 0) |
2543 | if (op->stats.food >= 0 || op->stats.hp < 0) |
2562 | break; |
2544 | break; |
2563 | } |
2545 | } |
2564 | else if (tmp->type == FLESH) |
2546 | else if (tmp->type == FLESH) |
2565 | flesh = tmp; |
2547 | flesh = tmp; |
2566 | } /* End if paid for object */ |
2548 | } |
2567 | } /* end of for loop */ |
|
|
2568 | |
2549 | |
2569 | /* If player is still starving, it means they don't have any food, so |
2550 | /* If player is still starving, it means they don't have any food, so |
2570 | * eat flesh instead. |
2551 | * eat flesh instead. |
2571 | */ |
2552 | */ |
2572 | if (op->stats.food < 0 && op->stats.hp >= 0 && flesh) |
2553 | if (op->stats.food < 0 && op->stats.hp >= 0 && flesh) |
2573 | { |
2554 | { |
2574 | new_draw_info (NDI_UNIQUE, 0, op, "You blindly grab for a bite of food."); |
2555 | op->statusmsg ("You blindly grab for a bite of food. " |
|
|
2556 | "H<To prevent you from starving, you ate some random item from your backpack.>"); |
2575 | manual_apply (op, flesh, 0); |
2557 | manual_apply (op, flesh, 0); |
2576 | } |
2558 | } |
|
|
2559 | |
|
|
2560 | // If player is still starving, alert him! |
|
|
2561 | if (op->stats.food < 0) |
|
|
2562 | op->failmsg ("You are starving! " |
|
|
2563 | "H<Eat some food to increase your food and prevent you from an untimely death.>"); |
2577 | } |
2564 | } |
2578 | |
2565 | |
2579 | if (op->stats.food < 0) |
2566 | if (op->stats.food < 0) |
2580 | { |
2567 | { |
2581 | op->stats.hp += op->stats.food; |
2568 | op->stats.hp += op->stats.food; |
2582 | op->stats.food = 0; |
2569 | op->stats.food = 0; |
|
|
2570 | |
|
|
2571 | if (op->stats.hp < 0) |
|
|
2572 | { |
|
|
2573 | op->contr->killer = archetype::get ("killer_starvation"); |
|
|
2574 | op->contr->killer->destroy (true); |
2583 | } |
2575 | } |
|
|
2576 | } |
2584 | |
2577 | |
|
|
2578 | /* killer should be set here already */ |
2585 | if (op->stats.hp < 0 && !QUERY_FLAG (op, FLAG_WIZ)) |
2579 | if (op->stats.hp < 0 && !QUERY_FLAG (op, FLAG_WIZ)) |
2586 | kill_player (op); |
2580 | kill_player (op); |
2587 | } |
2581 | } |
2588 | } |
2582 | } |
2589 | |
2583 | |
… | |
… | |
2593 | * file. |
2587 | * file. |
2594 | */ |
2588 | */ |
2595 | void |
2589 | void |
2596 | kill_player (object *op) |
2590 | kill_player (object *op) |
2597 | { |
2591 | { |
|
|
2592 | int x, y; |
2598 | char buf[MAX_BUF]; |
2593 | char buf[MAX_BUF]; |
2599 | int x, y; |
|
|
2600 | |
|
|
2601 | //int i; |
|
|
2602 | maptile *map; /* this is for resurrection */ |
2594 | maptile *map; /* this is for resurrection */ |
2603 | |
|
|
2604 | /* int z; |
|
|
2605 | int num_stats_lose; |
|
|
2606 | int lost_a_stat; |
|
|
2607 | int lose_this_stat; |
|
|
2608 | int this_stat; */ |
|
|
2609 | int will_kill_again; |
2595 | int will_kill_again; |
2610 | archetype *at; |
2596 | archetype *at; |
2611 | object *tmp; |
2597 | object *tmp; |
2612 | |
2598 | |
2613 | if (save_life (op)) |
2599 | if (save_life (op)) |
… | |
… | |
2624 | |
2610 | |
2625 | /* restore player */ |
2611 | /* restore player */ |
2626 | at = archetype::find ("poisoning"); |
2612 | at = archetype::find ("poisoning"); |
2627 | if (object *tmp = present_arch_in_ob (at, op)) |
2613 | if (object *tmp = present_arch_in_ob (at, op)) |
2628 | { |
2614 | { |
2629 | tmp->destroy (); |
2615 | tmp->destroy (true); |
2630 | new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed"); |
2616 | new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed"); |
2631 | } |
2617 | } |
2632 | |
2618 | |
2633 | at = archetype::find ("confusion"); |
2619 | at = archetype::find ("confusion"); |
2634 | if (object *tmp = present_arch_in_ob (at, op)) |
2620 | if (object *tmp = present_arch_in_ob (at, op)) |
2635 | { |
2621 | { |
2636 | tmp->destroy (); |
2622 | tmp->destroy (true); |
2637 | new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer"); |
2623 | new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer"); |
2638 | } |
2624 | } |
2639 | |
2625 | |
2640 | cure_disease (op, 0); /* remove any disease */ |
2626 | cure_disease (op, 0, 0); /* remove any disease */ |
2641 | op->stats.hp = op->stats.maxhp; |
2627 | op->stats.hp = op->stats.maxhp; |
2642 | if (op->stats.food <= 0) |
2628 | if (op->stats.food <= 0) |
2643 | op->stats.food = 999; |
2629 | op->stats.food = 999; |
2644 | |
2630 | |
2645 | /* create a bodypart-trophy to make the winner happy */ |
2631 | /* create a bodypart-trophy to make the winner happy */ |
2646 | if (object *tmp = arch_to_object (archetype::find ("finger"))) |
2632 | if (object *tmp = arch_to_object (archetype::find ("finger"))) |
2647 | { |
2633 | { |
2648 | sprintf (buf, "%s's finger", &op->name); |
2634 | tmp->name = format ("%s's finger" , &op->name); |
2649 | tmp->name = buf; |
2635 | tmp->name_pl = format ("%s's fingers", &op->name); |
2650 | sprintf (buf, " This finger has been cut off %s\n" |
|
|
2651 | " the %s, when he was defeated at\n level %d by %s.\n", |
|
|
2652 | &op->name, op->contr->title, (int) (op->level), op->contr->killer); |
|
|
2653 | tmp->msg = buf; |
2636 | tmp->msg = format ( |
|
|
2637 | "This finger has been cut off of %s the %s, when he was defeated at level %d by %s.\n", |
|
|
2638 | &op->name, op->contr->title, |
|
|
2639 | (int)op->level, |
|
|
2640 | op->contr->killer_name () |
|
|
2641 | ); |
2654 | tmp->value = 0, tmp->type = 0; |
2642 | tmp->value = 0, tmp->type = 0; |
2655 | tmp->materialname = "organics"; |
2643 | tmp->materialname = "organics"; |
2656 | tmp->insert_at (op, tmp); |
2644 | tmp->insert_at (op, tmp); |
2657 | } |
2645 | } |
2658 | |
2646 | |
… | |
… | |
2663 | } |
2651 | } |
2664 | |
2652 | |
2665 | INVOKE_PLAYER (DEATH, op->contr); |
2653 | INVOKE_PLAYER (DEATH, op->contr); |
2666 | |
2654 | |
2667 | command_kill_pets (op, 0); |
2655 | command_kill_pets (op, 0); |
2668 | |
|
|
2669 | if (op->stats.food < 0) |
|
|
2670 | { |
|
|
2671 | sprintf (buf, "%s starved to death.", &op->name); |
|
|
2672 | strcpy (op->contr->killer, "starvation"); |
|
|
2673 | } |
|
|
2674 | else |
|
|
2675 | sprintf (buf, "%s died.", &op->name); |
|
|
2676 | |
2656 | |
2677 | op->contr->play_sound (sound_find ("player_dies")); |
2657 | op->contr->play_sound (sound_find ("player_dies")); |
2678 | |
2658 | |
2679 | /* save the map location for corpse, gravestone */ |
2659 | /* save the map location for corpse, gravestone */ |
2680 | x = op->x; |
2660 | x = op->x; |
… | |
… | |
2789 | lost_a_stat = 1; |
2769 | lost_a_stat = 1; |
2790 | } |
2770 | } |
2791 | } |
2771 | } |
2792 | } |
2772 | } |
2793 | } |
2773 | } |
|
|
2774 | |
2794 | /* If no stat lost, tell the player. */ |
2775 | /* If no stat lost, tell the player. */ |
2795 | if (!lost_a_stat) |
2776 | if (!lost_a_stat) |
2796 | { |
2777 | { |
2797 | /* determine_god() seems to not work sometimes... why is this? |
2778 | /* determine_god() seems to not work sometimes... why is this? |
2798 | Should I be using something else? GD */ |
2779 | Should I be using something else? GD */ |
… | |
… | |
2802 | new_draw_info_format (NDI_UNIQUE, 0, op, "For a brief moment you feel the holy presence of %s protecting" " you.", god); |
2783 | new_draw_info_format (NDI_UNIQUE, 0, op, "For a brief moment you feel the holy presence of %s protecting" " you.", god); |
2803 | else |
2784 | else |
2804 | new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you feel a holy presence protecting you."); |
2785 | new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you feel a holy presence protecting you."); |
2805 | } |
2786 | } |
2806 | #else |
2787 | #else |
2807 | new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you" " feel a holy presence protecting you from losing yourself completely."); |
2788 | new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you feel a holy presence protecting you from losing yourself completely."); |
2808 | #endif |
2789 | #endif |
2809 | |
2790 | |
2810 | /* Put a gravestone up where the character 'almost' died. List the |
2791 | /* Put a gravestone up where the character 'almost' died. List the |
2811 | * exp loss on the stone. |
2792 | * exp loss on the stone. |
2812 | */ |
2793 | */ |
2813 | tmp = arch_to_object (archetype::find ("gravestone")); |
2794 | tmp = arch_to_object (archetype::find ("gravestone")); |
2814 | sprintf (buf, "%s's gravestone", &op->name); |
2795 | tmp->name = format ("%s's gravestone", &op->name); |
2815 | tmp->name = buf; |
2796 | tmp->name_pl = format ("%s's gravestones", &op->name); |
2816 | sprintf (buf, "%s's gravestones", &op->name); |
2797 | tmp->msg = format ("T<RIP>\n\nHere rests the hero %s the %s,\rwho was killed\rby %s.\n", |
2817 | tmp->name_pl = buf; |
2798 | &op->name, op->contr->title, op->contr->killer_name ()); |
2818 | 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); |
|
|
2819 | tmp->msg = buf; |
|
|
2820 | tmp->x = op->x, tmp->y = op->y; |
2799 | tmp->x = op->x, tmp->y = op->y; |
2821 | insert_ob_in_map (tmp, op->map, NULL, 0); |
2800 | insert_ob_in_map (tmp, op->map, NULL, 0); |
2822 | |
2801 | |
2823 | /**************************************/ |
2802 | /**************************************/ |
2824 | /* */ |
2803 | /* */ |
… | |
… | |
2833 | at = archetype::find ("poisoning"); |
2812 | at = archetype::find ("poisoning"); |
2834 | tmp = present_arch_in_ob (at, op); |
2813 | tmp = present_arch_in_ob (at, op); |
2835 | |
2814 | |
2836 | if (tmp) |
2815 | if (tmp) |
2837 | { |
2816 | { |
2838 | tmp->destroy (); |
2817 | tmp->destroy (true); |
2839 | new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed"); |
2818 | new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed"); |
2840 | } |
2819 | } |
2841 | |
2820 | |
2842 | at = archetype::find ("confusion"); |
2821 | at = archetype::find ("confusion"); |
2843 | tmp = present_arch_in_ob (at, op); |
2822 | tmp = present_arch_in_ob (at, op); |
2844 | if (tmp) |
2823 | if (tmp) |
2845 | { |
2824 | { |
2846 | tmp->destroy (); |
2825 | tmp->destroy (true); |
2847 | new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer"); |
2826 | new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer"); |
2848 | } |
2827 | } |
2849 | |
2828 | |
2850 | cure_disease (op, 0); /* remove any disease */ |
2829 | cure_disease (op, 0, 0); /* remove any disease */ |
|
|
2830 | |
|
|
2831 | // remove all spell effects that are active |
|
|
2832 | // to avoid long-term effects such as word-of-recall |
|
|
2833 | for (object *item = op->inv; item; ) |
|
|
2834 | { |
|
|
2835 | object *next = item->below; |
|
|
2836 | |
|
|
2837 | if (item->type == SPELL_EFFECT && item->active) |
|
|
2838 | item->destroy (true); |
|
|
2839 | |
|
|
2840 | item = next; |
|
|
2841 | } |
2851 | |
2842 | |
2852 | /*add_exp(op, (op->stats.exp * -0.20)); */ |
2843 | /*add_exp(op, (op->stats.exp * -0.20)); */ |
2853 | apply_death_exp_penalty (op); |
2844 | apply_death_exp_penalty (op); |
|
|
2845 | |
2854 | if (op->stats.food < 100) |
2846 | if (op->stats.food < 100) |
2855 | op->stats.food = 900; |
2847 | op->stats.food = 900; |
|
|
2848 | |
2856 | op->stats.hp = op->stats.maxhp; |
2849 | op->stats.hp = op->stats.maxhp; |
2857 | op->stats.sp = MAX (op->stats.sp, op->stats.maxsp); |
2850 | op->stats.sp = MAX (op->stats.sp, op->stats.maxsp); |
2858 | op->stats.grace = MAX (op->stats.grace, op->stats.maxgrace); |
2851 | op->stats.grace = MAX (op->stats.grace, op->stats.maxgrace); |
2859 | |
2852 | |
2860 | /* |
2853 | /* |
… | |
… | |
2898 | if (will_kill_again & (1 << at)) |
2891 | if (will_kill_again & (1 << at)) |
2899 | force->resist[at] = 100; |
2892 | force->resist[at] = 100; |
2900 | |
2893 | |
2901 | insert_ob_in_ob (force, op); |
2894 | insert_ob_in_ob (force, op); |
2902 | op->update_stats (); |
2895 | op->update_stats (); |
2903 | |
|
|
2904 | } |
2896 | } |
2905 | |
2897 | |
2906 | new_draw_info (NDI_UNIQUE, 0, op, "YOU HAVE DIED."); |
2898 | new_draw_info (NDI_UNIQUE, 0, op, "YOU HAVE DIED."); |
2907 | } |
2899 | } |
2908 | |
2900 | |
… | |
… | |
2928 | |
2920 | |
2929 | if (!QUERY_FLAG (tmp, FLAG_UNIQUE) && (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || QUERY_FLAG (tmp, FLAG_NO_DROP) || !(rndm (3)))) |
2921 | if (!QUERY_FLAG (tmp, FLAG_UNIQUE) && (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || QUERY_FLAG (tmp, FLAG_NO_DROP) || !(rndm (3)))) |
2930 | { |
2922 | { |
2931 | if (tmp->nrof > 1) |
2923 | if (tmp->nrof > 1) |
2932 | { |
2924 | { |
2933 | tmp2 = get_split_ob (tmp, 1 + RANDOM () % (tmp->nrof - 1)); |
2925 | tmp->decrease (rndm (1, tmp->nrof - 1)); |
2934 | tmp2->destroy (); |
|
|
2935 | insert_ob_in_map (tmp, op->map, NULL, 0); |
2926 | insert_ob_in_map (tmp, op->map, NULL, 0); |
2936 | } |
2927 | } |
2937 | else |
2928 | else |
2938 | tmp->destroy (); |
2929 | tmp->destroy (true); |
2939 | } |
2930 | } |
2940 | else |
2931 | else |
2941 | insert_ob_in_map (tmp, op->map, NULL, 0); |
2932 | insert_ob_in_map (tmp, op->map, NULL, 0); |
2942 | } |
2933 | } |
2943 | } |
2934 | } |
… | |
… | |
2950 | void |
2941 | void |
2951 | fix_weight (void) |
2942 | fix_weight (void) |
2952 | { |
2943 | { |
2953 | for_all_players (pl) |
2944 | for_all_players (pl) |
2954 | { |
2945 | { |
2955 | int old = pl->ob->carrying, sum = sum_weight (pl->ob); |
2946 | sint32 old = pl->ob->carrying; |
2956 | |
2947 | |
2957 | if (old == sum) |
2948 | pl->ob->update_weight (); |
2958 | continue; |
2949 | |
|
|
2950 | if (old != pl->ob->carrying) |
|
|
2951 | { |
2959 | pl->ob->update_stats (); |
2952 | pl->ob->update_stats (); |
2960 | LOG (llevDebug, "Fixed inventory in %s (%d -> %d)\n", &pl->ob->name, old, sum); |
2953 | LOG (llevDebug, "Fixed inventory in %s (%d -> %d)\n", &pl->ob->name, (int)old, (int)pl->ob->carrying); |
|
|
2954 | } |
2961 | } |
2955 | } |
2962 | } |
2956 | } |
2963 | |
2957 | |
2964 | void |
2958 | void |
2965 | fix_luck (void) |
2959 | fix_luck (void) |
… | |
… | |
3001 | if (op->type == PLAYER) |
2995 | if (op->type == PLAYER) |
3002 | new_draw_info_format (NDI_UNIQUE, 0, op, "You cast %s.", &spob->name); |
2996 | new_draw_info_format (NDI_UNIQUE, 0, op, "You cast %s.", &spob->name); |
3003 | |
2997 | |
3004 | cast_spell (op, throw_ob, dir, spob, NULL); |
2998 | cast_spell (op, throw_ob, dir, spob, NULL); |
3005 | |
2999 | |
3006 | throw_ob->destroy (); |
3000 | throw_ob->destroy (true); |
3007 | } |
3001 | } |
3008 | |
3002 | |
3009 | void |
3003 | void |
3010 | make_visible (object *op) |
3004 | make_visible (object *op) |
3011 | { |
3005 | { |
3012 | op->hide = 0; |
3006 | op->hide = 0; |
3013 | op->invisible = 0; |
3007 | op->invisible = 0; |
|
|
3008 | |
3014 | if (op->type == PLAYER) |
3009 | if (op->type == PLAYER) |
3015 | { |
3010 | { |
3016 | op->contr->tmp_invis = 0; |
3011 | op->contr->tmp_invis = 0; |
3017 | op->contr->invis_race = 0; |
3012 | op->contr->invis_race = 0; |
3018 | } |
3013 | } |
… | |
… | |
3031 | |
3026 | |
3032 | /* look at the surrounding terrain to determine |
3027 | /* look at the surrounding terrain to determine |
3033 | * the hideability of this object. Positive levels |
3028 | * the hideability of this object. Positive levels |
3034 | * indicate greater hideability. |
3029 | * indicate greater hideability. |
3035 | */ |
3030 | */ |
3036 | |
|
|
3037 | int |
3031 | int |
3038 | hideability (object *ob) |
3032 | hideability (object *ob) |
3039 | { |
3033 | { |
3040 | int i, level = 0, mflag; |
3034 | int i, level = 0, mflag; |
3041 | sint16 x, y; |
3035 | sint16 x, y; |
… | |
… | |
3051 | * as bad as carrying a light on a pitch dark map */ |
3045 | * as bad as carrying a light on a pitch dark map */ |
3052 | if (has_carried_lights (ob)) |
3046 | if (has_carried_lights (ob)) |
3053 | level = -(10 + (2 * ob->map->darkness)); |
3047 | level = -(10 + (2 * ob->map->darkness)); |
3054 | |
3048 | |
3055 | /* scan through all nearby squares for terrain to hide in */ |
3049 | /* scan through all nearby squares for terrain to hide in */ |
3056 | for (i = 0, x = ob->x, y = ob->y; i < 9; i++, x = ob->x + freearr_x[i], y = ob->y + freearr_y[i]) |
3050 | for (i = 0, x = ob->x, y = ob->y; |
|
|
3051 | i <= SIZEOFFREE1; |
|
|
3052 | i++, x = ob->x + freearr_x[i], y = ob->y + freearr_y[i]) |
3057 | { |
3053 | { |
3058 | mflag = get_map_flags (ob->map, NULL, x, y, NULL, NULL); |
3054 | mflag = get_map_flags (ob->map, NULL, x, y, NULL, NULL); |
3059 | if (mflag & P_OUT_OF_MAP) |
3055 | if (mflag & P_OUT_OF_MAP) |
3060 | { |
|
|
3061 | continue; |
3056 | continue; |
3062 | } |
3057 | |
3063 | if (mflag & P_BLOCKSVIEW) /* something to hide near! */ |
3058 | if (mflag & P_BLOCKSVIEW) /* something to hide near! */ |
3064 | level += 2; |
3059 | level += 2; |
3065 | else /* open terrain! */ |
3060 | else /* open terrain! */ |
3066 | level -= 1; |
3061 | level -= 1; |
3067 | } |
3062 | } |
… | |
… | |
3078 | * spot (surrounded by clear terrain in broad daylight). -b.t. |
3073 | * spot (surrounded by clear terrain in broad daylight). -b.t. |
3079 | */ |
3074 | */ |
3080 | void |
3075 | void |
3081 | do_hidden_move (object *op) |
3076 | do_hidden_move (object *op) |
3082 | { |
3077 | { |
3083 | int hide = 0, num = random_roll (0, 19, op, PREFER_LOW); |
3078 | int hide = 0; |
3084 | object *skop; |
|
|
3085 | |
3079 | |
3086 | if (!op || !op->map) |
3080 | if (!op || !op->map) |
3087 | return; |
3081 | return; |
3088 | |
3082 | |
3089 | skop = find_obj_by_type_subtype (op, SKILL, SK_HIDING); |
3083 | object *skop = find_obj_by_type_subtype (op, SKILL, SK_HIDING); |
|
|
3084 | int num = random_roll (0, 19, op, PREFER_LOW); |
3090 | |
3085 | |
3091 | /* its *extremely* hard to run and sneak/hide at the same time! */ |
3086 | /* its *extremely* hard to run and sneak/hide at the same time! */ |
3092 | if (op->type == PLAYER && op->contr->run_on) |
3087 | if (op->type == PLAYER && op->contr->run_on) |
3093 | if (!skop || num >= skop->level) |
3088 | if (!skop || num >= skop->level) |
3094 | { |
3089 | { |
… | |
… | |
3104 | num -= hide; |
3099 | num -= hide; |
3105 | |
3100 | |
3106 | if ((op->type == PLAYER && hide < -10) || ((op->invisible -= num) <= 0)) |
3101 | if ((op->type == PLAYER && hide < -10) || ((op->invisible -= num) <= 0)) |
3107 | { |
3102 | { |
3108 | make_visible (op); |
3103 | make_visible (op); |
|
|
3104 | |
3109 | if (op->type == PLAYER) |
3105 | if (op->type == PLAYER) |
3110 | new_draw_info (NDI_UNIQUE, 0, op, "You moved out of hiding! You are visible!"); |
3106 | new_draw_info (NDI_UNIQUE, 0, op, "You moved out of hiding! You are visible!"); |
3111 | } |
3107 | } |
3112 | else if (op->type == PLAYER && skop) |
3108 | else if (op->type == PLAYER && skop) |
3113 | change_exp (op, calc_skill_exp (op, NULL, skop), skop->skill, 0); |
3109 | change_exp (op, calc_skill_exp (op, NULL, skop), skop->skill, 0); |
… | |
… | |
3320 | char buf[MAX_BUF]; /* tmp. string buffer */ |
3316 | char buf[MAX_BUF]; /* tmp. string buffer */ |
3321 | int i = 0, j = 0; |
3317 | int i = 0, j = 0; |
3322 | |
3318 | |
3323 | /* get the appropriate treasurelist */ |
3319 | /* get the appropriate treasurelist */ |
3324 | if (atnr == ATNR_FIRE) |
3320 | if (atnr == ATNR_FIRE) |
3325 | trlist = treasurelist::find ("dragon_ability_fire"); |
3321 | trlist = treasurelist::find (shstr_dragon_ability_fire); |
3326 | else if (atnr == ATNR_COLD) |
3322 | else if (atnr == ATNR_COLD) |
3327 | trlist = treasurelist::find ("dragon_ability_cold"); |
3323 | trlist = treasurelist::find (shstr_dragon_ability_cold); |
3328 | else if (atnr == ATNR_ELECTRICITY) |
3324 | else if (atnr == ATNR_ELECTRICITY) |
3329 | trlist = treasurelist::find ("dragon_ability_elec"); |
3325 | trlist = treasurelist::find (shstr_dragon_ability_elec); |
3330 | else if (atnr == ATNR_POISON) |
3326 | else if (atnr == ATNR_POISON) |
3331 | trlist = treasurelist::find ("dragon_ability_poison"); |
3327 | trlist = treasurelist::find (shstr_dragon_ability_poison); |
3332 | |
3328 | |
3333 | if (trlist == NULL || who->type != PLAYER) |
3329 | if (trlist == NULL || who->type != PLAYER) |
3334 | return; |
3330 | return; |
3335 | |
3331 | |
3336 | for (i = 0, tr = trlist->items; tr != NULL && i < level - 1; tr = tr->next, i++); |
3332 | for (i = 0, tr = trlist->items; tr != NULL && i < level - 1; tr = tr->next, i++); |
… | |
… | |
3454 | else |
3450 | else |
3455 | { |
3451 | { |
3456 | /* generate misc. treasure */ |
3452 | /* generate misc. treasure */ |
3457 | tmp = arch_to_object (tr->item); |
3453 | tmp = arch_to_object (tr->item); |
3458 | new_draw_info_format (NDI_UNIQUE | NDI_BLUE, 0, who, "You gained %s", query_short_name (tmp)); |
3454 | new_draw_info_format (NDI_UNIQUE | NDI_BLUE, 0, who, "You gained %s", query_short_name (tmp)); |
3459 | tmp = insert_ob_in_ob (tmp, who); |
3455 | who->insert (tmp); |
3460 | if (who->type == PLAYER) |
|
|
3461 | esrv_send_item (who, tmp); |
|
|
3462 | } |
3456 | } |
3463 | } |
3457 | } |
3464 | |
3458 | |
3465 | /** |
3459 | /** |
3466 | * Unready an object for a player. This function does nothing if the object was |
3460 | * Unready an object for a player. This function does nothing if the object was |
… | |
… | |
3495 | if (!IN_RANGE_EXC (x, 0, ns->mapx) || !IN_RANGE_EXC (y, 0, ns->mapy)) |
3489 | if (!IN_RANGE_EXC (x, 0, ns->mapx) || !IN_RANGE_EXC (y, 0, ns->mapy)) |
3496 | return 0; |
3490 | return 0; |
3497 | |
3491 | |
3498 | return 100 - blocked_los [x][y]; |
3492 | return 100 - blocked_los [x][y]; |
3499 | } |
3493 | } |
|
|
3494 | |
|
|
3495 | void |
|
|
3496 | player::infobox (const char *title, const char *msg, int color) |
|
|
3497 | { |
|
|
3498 | send_msg (color | NDI_DEF | NDI_REPLY | NDI_CLEAR, title, msg); |
|
|
3499 | } |
|
|
3500 | |
|
|
3501 | void |
|
|
3502 | player::statusmsg (const char *msg, int color) |
|
|
3503 | { |
|
|
3504 | send_msg (color | NDI_REPLY, INFO_CHANNEL, msg); |
|
|
3505 | } |
|
|
3506 | |
|
|
3507 | void |
|
|
3508 | player::failmsg (const char *msg, int color) |
|
|
3509 | { |
|
|
3510 | play_sound (sound_find ("generic_failure")); |
|
|
3511 | statusmsg (msg, color); |
|
|
3512 | } |
|
|
3513 | |