ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/player.C
(Generate patch)

Comparing deliantra/server/server/player.C (file contents):
Revision 1.187 by root, Mon Apr 21 07:07:36 2008 UTC vs.
Revision 1.238 by root, Thu Nov 5 16:09:51 2009 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008,2009 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 * Deliantra is free software: you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * it under the terms of the GNU General Public License as published by 9 * the terms of the Affero GNU General Public License as published by the
10 * the Free Software Foundation, either version 3 of the License, or 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * (at your option) any later version. 11 * 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,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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 Affero GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>.
20 * 21 *
21 * The authors can be reached via e-mail to <support@deliantra.net> 22 * The authors can be reached via e-mail to <support@deliantra.net>
22 */ 23 */
24
25//+GPL
23 26
24#include <global.h> 27#include <global.h>
25#include <sproto.h> 28#include <sproto.h>
26#include <sounds.h> 29#include <sounds.h>
27#include <living.h> 30#include <living.h>
32#include <algorithm> 35#include <algorithm>
33#include <functional> 36#include <functional>
34 37
35playervec players; 38playervec players;
36 39
37void
38display_motd (const object *op)
39{
40 char buf[MAX_BUF];
41 char motd[HUGE_BUF];
42 FILE *fp;
43 int comp;
44 int size;
45
46 sprintf (buf, "%s/%s", settings.confdir, settings.motd);
47 if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL)
48 return;
49
50 motd[0] = '\0';
51 size = 0;
52
53 while (fgets (buf, MAX_BUF, fp))
54 {
55 if (*buf == '#')
56 continue;
57
58 strncat (motd + size, buf, HUGE_BUF - size);
59 size += strlen (buf);
60 }
61
62 draw_ext_info (NDI_UNIQUE | NDI_GREEN, 0, op, MSG_TYPE_MOTD, MSG_SUBTYPE_NONE, motd, NULL);
63 close_and_delete (fp, comp);
64}
65
66void
67send_rules (const object *op)
68{
69 char buf[MAX_BUF];
70 char rules[HUGE_BUF];
71 FILE *fp;
72 int comp;
73 int size;
74
75 sprintf (buf, "%s/%s", settings.confdir, settings.rules);
76 if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL)
77 return;
78
79 rules[0] = '\0';
80 size = 0;
81
82 while (fgets (buf, MAX_BUF, fp))
83 {
84 if (*buf == '#')
85 continue;
86
87 if (size + strlen (buf) >= HUGE_BUF)
88 {
89 LOG (llevDebug, "Warning, rules size is > %d bytes.\n", HUGE_BUF);
90 break;
91 }
92
93 strncat (rules + size, buf, HUGE_BUF - size);
94 size += strlen (buf);
95 }
96
97 draw_ext_info (NDI_UNIQUE | NDI_GREEN, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_RULES, rules, NULL);
98 close_and_delete (fp, comp);
99}
100
101void
102send_news (const object *op)
103{
104 char buf[MAX_BUF];
105 char news[HUGE_BUF];
106 char subject[MAX_BUF];
107 FILE *fp;
108 int comp;
109 int size;
110
111 sprintf (buf, "%s/%s", settings.confdir, settings.news);
112 if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL)
113 return;
114
115 news[0] = '\0';
116 subject[0] = '\0';
117 size = 0;
118
119 while (fgets (buf, MAX_BUF, fp))
120 {
121 if (*buf == '#')
122 continue;
123
124 if (*buf == '%')
125 { /* send one news */
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 */
128
129 strcpy (subject, buf + 1);
130 strip_endline (subject);
131 size = 0;
132 news[0] = '\0';
133 }
134 else
135 {
136 if (size + strlen (buf) >= HUGE_BUF)
137 {
138 LOG (llevDebug, "Warning, one news item has size > %d bytes.\n", HUGE_BUF);
139 break;
140 }
141 strncat (news + size, buf, HUGE_BUF - size);
142 size += strlen (buf);
143 }
144 }
145
146 draw_ext_info_format (NDI_UNIQUE | NDI_GREEN, 0, op,
147 MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_NEWS, "INFORMATION: %s\n%s\n", (char *)"%s\n%s", subject, news);
148 close_and_delete (fp, comp);
149}
150
151/* This loads the first map an puts the player on it. */ 40/* This loads the first map an puts the player on it. */
152static void 41static void
153set_first_map (object *op) 42set_first_map (object *op)
154{ 43{
155 op->contr->maplevel = first_map_path; 44 op->contr->maplevel = first_map_path;
207 ob->close_container (); //TODO: client-specific 96 ob->close_container (); //TODO: client-specific
208 97
209 ns->update_look = 0; 98 ns->update_look = 0;
210 ns->look_position = 0; 99 ns->look_position = 0;
211 100
212 clear_los (this); 101 clear_los ();
213 102
214 ns->reset_stats (); 103 ns->reset_stats ();
215 104
216 /* make sure he's a player -- needed because of class change. */ 105 /* make sure he's a player -- needed because of class change. */
217 ob->type = PLAYER; // we are paranoid 106 ob->type = PLAYER; // we are paranoid
218 ob->race = ob->arch->race; 107 ob->race = ob->arch->race;
219 108
220 ob->update_weight (); 109 ob->update_weight ();
221 link_player_skills (ob); 110 link_skills ();
222 111
223 CLEAR_FLAG (ob, FLAG_NO_FIX_PLAYER); 112 CLEAR_FLAG (ob, FLAG_NO_FIX_PLAYER);
224 113
225 assign (title, ob->arch->object::name); 114 assign (title, ob->arch->object::name);
226 115
239 set_dragon_name (ob, abil, skin); 128 set_dragon_name (ob, abil, skin);
240 } 129 }
241 130
242 new_draw_info (NDI_UNIQUE, 0, ob, "Welcome Back!"); 131 new_draw_info (NDI_UNIQUE, 0, ob, "Welcome Back!");
243 132
244 esrv_new_player (this, ob->weight + ob->carrying); 133 esrv_new_player (this);
245 134
246 ob->update_stats (); 135 ob->update_stats ();
247 136
248 ns->floorbox_update (); 137 ns->floorbox_update ();
249 esrv_send_inventory (ob, ob); 138 esrv_send_inventory (ob, ob);
250 esrv_add_spells (this, 0); 139 esrv_add_spells (this, 0);
251 140
252 activate (); 141 activate ();
253 142
254 send_rules (ob);
255 send_news (ob);
256 display_motd (ob);
257
258 INVOKE_PLAYER (CONNECT, this); 143 INVOKE_PLAYER (CONNECT, this);
259 INVOKE_PLAYER (LOGIN, this); 144 INVOKE_PLAYER (LOGIN, this);
260} 145}
261 146
262void 147void
278 ns->reset_stats (); 163 ns->reset_stats ();
279 ns->pl = 0; 164 ns->pl = 0;
280 ns = 0; 165 ns = 0;
281 } 166 }
282 167
283 observe = ob; 168 // this is important for the player scheduler to get the correct refcount
169 // when ns = 0
170 observe = viewpoint = ob;
284 171
285 deactivate (); 172 deactivate ();
286} 173}
174
175//-GPL
287 176
288// the need for this function can be explained 177// the need for this function can be explained
289// by load_object not returning the object 178// by load_object not returning the object
290void 179void
291player::set_object (object *op) 180player::set_object (object *op)
292{ 181{
293 ob = observe = op; 182 ob = observe = viewpoint = op;
294 ob->contr = this; /* this aren't yet in archetype */ 183 ob->contr = this; /* this aren't yet in archetype */
295 184
296 ob->speed = 1.0f; 185 ob->speed = 1.0f;
297 ob->speed_left = 0.5f; 186 ob->speed_left = 0.5f;
298 187
299 ob->direction = 5; /* So player faces south */ 188 ob->direction = 5; /* So player faces south */
300 189
301 ob->flag [FLAG_READY_WEAPON] = false; 190 ob->flag [FLAG_READY_WEAPON] = false;
302 ob->flag [FLAG_READY_SKILL] = false; 191 ob->flag [FLAG_READY_SKILL] = false;
303 ob->flag [FLAG_READY_BOW] = false; 192 ob->flag [FLAG_READY_BOW] = false;
304 193
321 combat_ob = op; 210 combat_ob = op;
322 break; 211 break;
323 } 212 }
324 213
325 ob->change_weapon (combat_ob ? combat_ob : ranged_ob); 214 ob->change_weapon (combat_ob ? combat_ob : ranged_ob);
326 ob->deactivate (); // change_Weapon activates, fix this better 215 ob->deactivate (); // change_weapon activates, fix this better
327} 216}
328 217
329void 218void
330player::set_observe (object *op) 219player::set_observe (object *op)
331{ 220{
332 observe = op ? op : ob; 221 observe = viewpoint = op ? op : ob;
333 do_los = 1; 222 do_los = 1;
334} 223}
224
225void
226player::set_viewpoint (object *op)
227{
228 viewpoint = op ? op : (object *)observe;
229 do_los = 1;
230}
231
232//+GPL
335 233
336player::player () 234player::player ()
337{ 235{
338 /* There are some elements we want initialised to non zero value - 236 /* There are some elements we want initialised to non zero value -
339 * we deal with that below this point. 237 * we deal with that below this point.
345 savebed_map = first_map_path; /* Init. respawn position */ 243 savebed_map = first_map_path; /* Init. respawn position */
346 244
347 gen_sp_armour = 10; 245 gen_sp_armour = 10;
348 bowtype = bow_normal; 246 bowtype = bow_normal;
349 petmode = pet_normal; 247 petmode = pet_normal;
350 listening = 10;
351 usekeys = containers; 248 usekeys = containers;
352 peaceful = 1; /* default peaceful */ 249 peaceful = 1; /* default peaceful */
353 do_los = 1; 250 do_los = 1;
354 251
355 weapon_sp = 1.0f; 252 weapon_sp = 1.0f;
367 { 264 {
368 ob->destroy_inv (false); 265 ob->destroy_inv (false);
369 ob->destroy (); 266 ob->destroy ();
370 } 267 }
371 268
372 ob = observe = 0; 269 ob = observe = viewpoint = 0;
373} 270}
374 271
375player::~player () 272player::~player ()
376{ 273{
377 /* Clear item stack */ 274 /* Clear item stack */
671 op->destroy (); 568 op->destroy ();
672 continue; 569 continue;
673 } 570 }
674 } 571 }
675 572
676 /* This really needs to be better - we should really give 573 /* Here we remove duplicated skills (as duplicated spell objects have
677 * a substitute spellbook. The problem is that we don't really 574 * _very_ confusing effects for players), which could for instance be
678 * have a good idea what to replace it with (need something like 575 * generated by bad treasurelists. - elmex
679 * a first level treasurelist for each skill.)
680 * remove duplicate skills also
681 */ 576 */
682 if (op->type == SPELLBOOK || op->type == SKILL) 577 if (op->type == SKILL)
683 { 578 {
684 object *tmp;
685
686 for (tmp = op->below; tmp; tmp = tmp->below) 579 for (object *tmp = op->below; tmp; tmp = tmp->below)
687 if (tmp->type == op->type && tmp->name == op->name) 580 if (tmp->type == op->type && tmp->name == op->name)
688 break;
689
690 if (tmp)
691 { 581 {
692 op->destroy (); 582 op->destroy ();
583 LOG (llevError,
693 LOG (llevError, "give_initial_items: Removing duplicate object %s\n", &tmp->name); 584 "give_initial_items: Removing duplicate skill %s\n", &tmp->name);
694 continue; 585 break;
695 } 586 }
696 587
697 if (op->nrof > 1) 588 if (op->nrof > 1)
698 op->nrof = 1; 589 op->nrof = 1;
699 } 590 }
700 591
726 else /* lock all 'normal items by default */ 617 else /* lock all 'normal items by default */
727 SET_FLAG (op, FLAG_INV_LOCKED); 618 SET_FLAG (op, FLAG_INV_LOCKED);
728 } /* for loop of objects in player inv */ 619 } /* for loop of objects in player inv */
729 620
730 /* Need to set up the skill pointers */ 621 /* Need to set up the skill pointers */
731 link_player_skills (pl); 622 pl->contr->link_skills ();
732} 623}
733 624
734void 625void
735get_party_password (object *op, partylist *party) 626get_party_password (object *op, partylist *party)
736{ 627{
851 */ 742 */
852void 743void
853player::chargen_race_done () 744player::chargen_race_done ()
854{ 745{
855 /* this must before then initial items are given */ 746 /* this must before then initial items are given */
856 esrv_new_player (ob->contr, ob->weight + ob->carrying); 747 esrv_new_player (ob->contr);
857 748
858 treasurelist *tl = treasurelist::find ("starting_wealth"); 749 treasurelist *tl = treasurelist::find ("starting_wealth");
859 if (tl) 750 if (tl)
860 create_treasure (tl, ob, 0, 0, 0); 751 create_treasure (tl, ob, 0, 0, 0);
861 752
865 ob->contr->ns->state = ST_PLAYING; 756 ob->contr->ns->state = ST_PLAYING;
866 757
867 if (ob->msg) 758 if (ob->msg)
868 ob->msg = 0; 759 ob->msg = 0;
869 760
870 /* We create this now because some of the unique maps will need it
871 * to save here.
872 */
873 {
874 char buf[MAX_BUF];
875 sprintf (buf, "%s/%s/%s", settings.localdir, settings.playerdir, &ob->name);
876 make_path_to_file (buf);
877 }
878
879 start_info (ob); 761 start_info (ob);
880 CLEAR_FLAG (ob, FLAG_WIZ); 762 CLEAR_FLAG (ob, FLAG_WIZ);
881 give_initial_items (ob, ob->randomitems); 763 give_initial_items (ob, ob->randomitems);
882 link_player_skills (ob);
883 esrv_send_inventory (ob, ob); 764 esrv_send_inventory (ob, ob);
884 ob->update_stats (); 765 ob->update_stats ();
885 766
886 /* This moves the player to a different start map, if there 767 /* This moves the player to a different start map, if there
887 * is one for this race 768 * is one for this race
888 */ 769 */
889 if (*first_map_ext_path) 770 if (*first_map_ext_path)
890 { 771 ob->player_goto (format ("%s/%s", &first_map_ext_path, &ob->arch->archname), ob->x, ob->y);
891 object *tmp;
892 char mapname[MAX_BUF];
893
894 snprintf (mapname, MAX_BUF - 1, "%s/%s", &first_map_ext_path, &ob->arch->archname);
895 tmp = object::create ();
896 EXIT_PATH (tmp) = mapname;
897 EXIT_X (tmp) = ob->x;
898 EXIT_Y (tmp) = ob->y;
899 ob->enter_exit (tmp); /* we don't really care if it succeeded;
900 * if the map isn't there, then stay on the
901 * default initial map */
902 tmp->destroy ();
903 }
904 else 772 else
905 LOG (llevDebug, "first_map_ext_path not set\n"); 773 LOG (llevDebug, "first_map_ext_path not set\n");
906} 774}
907 775
908void 776void
952 LOG (llevDebug, "Fleeing player is dead.\n"); 820 LOG (llevDebug, "Fleeing player is dead.\n");
953 CLEAR_FLAG (op, FLAG_SCARED); 821 CLEAR_FLAG (op, FLAG_SCARED);
954 return; 822 return;
955 } 823 }
956 824
957 if (op->enemy == NULL) 825 if (!op->enemy)
958 { 826 {
959 LOG (llevDebug, "Fleeing player had no enemy.\n"); 827 LOG (llevDebug, "Fleeing player had no enemy.\n");
960 CLEAR_FLAG (op, FLAG_SCARED); 828 CLEAR_FLAG (op, FLAG_SCARED);
961 return; 829 return;
962 } 830 }
963 831
964 /* Seen some crashes here. Since we don't store an
965 * op->enemy_count, it is possible that something destroys the
966 * actual enemy, and the object is recycled.
967 */
968 if (op->enemy->map == NULL)
969 {
970 CLEAR_FLAG (op, FLAG_SCARED);
971 op->enemy = NULL;
972 return;
973 }
974
975 if (!(random_roll (0, 4, op, PREFER_LOW)) && did_make_save (op, op->level, 0)) 832 if (!(random_roll (0, 4, op, PREFER_LOW)) && did_make_save (op, op->level, 0))
976 { 833 {
977 op->enemy = NULL; 834 op->enemy = NULL;
978 CLEAR_FLAG (op, FLAG_SCARED); 835 CLEAR_FLAG (op, FLAG_SCARED);
979 return; 836 return;
982 get_rangevector (op, op->enemy, &rv, 0); 839 get_rangevector (op, op->enemy, &rv, 0);
983 840
984 dir = absdir (4 + rv.direction); 841 dir = absdir (4 + rv.direction);
985 for (diff = 0; diff < 3; diff++) 842 for (diff = 0; diff < 3; diff++)
986 { 843 {
987 int m = 1 - (RANDOM () & 2); 844 int m = 1 - rndm (2) * 2;
988 845
989 if (move_ob (op, absdir (dir + diff * m), op) || (diff == 0 && move_ob (op, absdir (dir - diff * m), op))) 846 if (move_ob (op, absdir (dir + diff * m), op) || (diff == 0 && move_ob (op, absdir (dir - diff * m), op)))
990 return; 847 return;
991 } 848 }
992 849
1003check_pick (object *op) 860check_pick (object *op)
1004{ 861{
1005 object *tmp, *next; 862 object *tmp, *next;
1006 int stop = 0; 863 int stop = 0;
1007 int wvratio; 864 int wvratio;
1008 char putstring[128];
1009 865
1010 /* if you're flying, you cna't pick up anything */ 866 /* if you're flying, you cna't pick up anything */
1011 if (op->move_type & MOVE_FLYING) 867 if (op->move_type & MOVE_FLYING)
1012 return 1; 868 return 1;
1013 869
1037 893
1038 if (op->contr->search_str[0] != '\0' && settings.search_items == TRUE) 894 if (op->contr->search_str[0] != '\0' && settings.search_items == TRUE)
1039 { 895 {
1040 if (item_matched_string (op, tmp, op->contr->search_str)) 896 if (item_matched_string (op, tmp, op->contr->search_str))
1041 CHK_PICK_PICKUP; 897 CHK_PICK_PICKUP;
898
1042 continue; 899 continue;
1043 } 900 }
1044 901
1045 /* high not bit set? We're using the old autopickup model */ 902 /* pickup handling */
903 if (op->contr->mode & PU_DEBUG)
904 {
905 /* some debugging code to figure out item information */
906 const char *str = tmp->name
907 ? format ("item name: %s item type: %d weight/value: %d",
908 &tmp->name, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))))
909 : format ("item name: %s item type: %d weight/value: %d",
910 &tmp->arch->archname, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))));
911
912 new_draw_info (NDI_UNIQUE, 0, op, str);
913 }
914
915 if (op->contr->mode & PU_INHIBIT)
916 return 1;
917
918 if (!(op->contr->mode & PU_ENABLE)) // TODO: fix client
919 return 1;
920
921 /* philosophy:
922 * It's easy to grab an item type from a pile, as long as it's
923 * generic. This takes no game-time. For more detailed pickups
924 * and selections, select-items should be used. This is a
925 * grab-as-you-run type mode that's really useful for arrows for
926 * example.
927 * The drawback: right now it has no frontend, so you need to
928 * stick the bits you want into a calculator in hex mode and then
929 * convert to decimal and then 'pickup <#>
930 */
931
932 /* the first two modes are exclusive: if NOTHING we return, if
933 * STOP then we stop. All the rest are applied sequentially,
934 * meaning if any test passes, the item gets picked up. */
935
936 /* if mode is set to pick nothing up, return */
937 if (op->contr->mode == PU_NOTHING)
938 return 1;
939
940 /* if mode is set to stop when encountering objects, return */
941 /* take STOP before INHIBIT since it doesn't actually pick
942 * anything up */
943 if (op->contr->mode & PU_STOP)
944 return 0;
945
946 /* useful for going into stores and not losing your settings... */
947 /* and for battles wher you don't want to get loaded down while
948 * fighting */
949 if (op->contr->mode & PU_INHIBIT)
950 return 1;
951
952 /* prevent us from turning into auto-thieves :) */
953 if (QUERY_FLAG (tmp, FLAG_UNPAID))
954 continue;
955
956 /* ignore known cursed objects */
957 if (QUERY_FLAG (tmp, FLAG_KNOWN_CURSED) && op->contr->mode & PU_NOT_CURSED)
958 continue;
959
960 /* all food and drink if desired */
961 /* question: don't pick up known-poisonous stuff? */
1046 if (!(op->contr->mode & PU_NEWMODE)) 962 if (op->contr->mode & PU_FOOD)
963 if (tmp->type == FOOD)
1047 { 964 {
1048 switch (op->contr->mode) 965 CHK_PICK_PICKUP;
966 continue;
967 }
968
969 if (op->contr->mode & PU_DRINK)
970 if (tmp->type == DRINK || (tmp->type == POISON && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)))
971 {
972 CHK_PICK_PICKUP;
973 continue;
974 }
975
976 if (op->contr->mode & PU_POTION)
977 if (tmp->type == POTION)
978 {
979 CHK_PICK_PICKUP;
980 continue;
981 }
982
983 /* spellbooks, skillscrolls and normal books/scrolls */
984 if (op->contr->mode & PU_SPELLBOOK)
985 if (tmp->type == SPELLBOOK)
986 {
987 CHK_PICK_PICKUP;
988 continue;
989 }
990
991 if (op->contr->mode & PU_SKILLSCROLL)
992 if (tmp->type == SKILLSCROLL)
993 {
994 CHK_PICK_PICKUP;
995 continue;
996 }
997
998 if (op->contr->mode & PU_READABLES)
999 if (tmp->type == BOOK || tmp->type == SCROLL || tmp->type == INSCRIBABLE)
1000 {
1001 CHK_PICK_PICKUP;
1002 continue;
1003 }
1004
1005 /* wands/staves/rods/horns */
1006 if (op->contr->mode & PU_MAGIC_DEVICE)
1007 if (tmp->type == WAND || tmp->type == ROD || tmp->type == HORN)
1008 {
1009 CHK_PICK_PICKUP;
1010 continue;
1011 }
1012
1013 /* pick up all magical items */
1014 if (op->contr->mode & PU_MAGICAL)
1015 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))
1016 {
1017 CHK_PICK_PICKUP;
1018 continue;
1019 }
1020
1021 if (op->contr->mode & PU_VALUABLES)
1022 {
1023 if (tmp->type == MONEY || tmp->type == GEM)
1049 { 1024 {
1050 case 0:
1051 return 1; /* don't pick up */
1052 case 1:
1053 CHK_PICK_PICKUP; 1025 CHK_PICK_PICKUP;
1054 return 1; 1026 continue;
1055 case 2:
1056 CHK_PICK_PICKUP;
1057 return 0;
1058 case 3:
1059 return 0; /* stop before pickup */
1060 case 4:
1061 CHK_PICK_PICKUP;
1062 break;
1063 case 5:
1064 CHK_PICK_PICKUP;
1065 stop = 1;
1066 break;
1067 case 6:
1068 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL)
1069 && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))
1070 CHK_PICK_PICKUP;
1071 break;
1072
1073 case 7:
1074 if (tmp->type == MONEY || tmp->type == GEM)
1075 CHK_PICK_PICKUP;
1076 break;
1077
1078 default:
1079 /* use value density */
1080 if (!QUERY_FLAG (tmp, FLAG_UNPAID)
1081 && (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))) >= op->contr->mode)
1082 CHK_PICK_PICKUP;
1083 } 1027 }
1084 } 1028 }
1085 else 1029
1086 { /* old model */ 1030 /* rings & amulets - talismans seems to be typed AMULET */
1087 /* NEW pickup handling */
1088 if (op->contr->mode & PU_DEBUG) 1031 if (op->contr->mode & PU_JEWELS)
1032 if (tmp->type == RING || tmp->type == AMULET)
1089 { 1033 {
1090 /* some debugging code to figure out item information */ 1034 CHK_PICK_PICKUP;
1091 if (tmp->name != NULL)
1092 sprintf (putstring, "item name: %s item type: %d weight/value: %d",
1093 &tmp->name, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))));
1094 else
1095 sprintf (putstring, "item name: %s item type: %d weight/value: %d",
1096 &tmp->arch->archname, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))));
1097
1098 new_draw_info (NDI_UNIQUE, 0, op, putstring);
1099 }
1100
1101 /* philosophy:
1102 * It's easy to grab an item type from a pile, as long as it's
1103 * generic. This takes no game-time. For more detailed pickups
1104 * and selections, select-items should be used. This is a
1105 * grab-as-you-run type mode that's really useful for arrows for
1106 * example.
1107 * The drawback: right now it has no frontend, so you need to
1108 * stick the bits you want into a calculator in hex mode and then
1109 * convert to decimal and then 'pickup <#>
1110 */
1111
1112 /* the first two modes are exclusive: if NOTHING we return, if
1113 * STOP then we stop. All the rest are applied sequentially,
1114 * meaning if any test passes, the item gets picked up. */
1115
1116 /* if mode is set to pick nothing up, return */
1117
1118 if (op->contr->mode & PU_NOTHING)
1119 return 1;
1120
1121 /* if mode is set to stop when encountering objects, return */
1122 /* take STOP before INHIBIT since it doesn't actually pick
1123 * anything up */
1124
1125 if (op->contr->mode & PU_STOP)
1126 return 0;
1127
1128 /* useful for going into stores and not losing your settings... */
1129 /* and for battles wher you don't want to get loaded down while
1130 * fighting */
1131 if (op->contr->mode & PU_INHIBIT)
1132 return 1;
1133
1134 /* prevent us from turning into auto-thieves :) */
1135 if (QUERY_FLAG (tmp, FLAG_UNPAID))
1136 continue; 1035 continue;
1036 }
1137 1037
1138 /* ignore known cursed objects */ 1038 /* we don't forget dragon food */
1139 if (QUERY_FLAG (tmp, FLAG_KNOWN_CURSED) && op->contr->mode & PU_NOT_CURSED) 1039 if (op->contr->mode & PU_FLESH)
1040 if (tmp->type == FLESH)
1041 {
1042 CHK_PICK_PICKUP;
1140 continue; 1043 continue;
1044 }
1141 1045
1142 /* all food and drink if desired */ 1046 /* bows and arrows. Bows are good for selling! */
1143 /* question: don't pick up known-poisonous stuff? */ 1047 if (op->contr->mode & PU_BOW)
1048 if (tmp->type == BOW)
1049 {
1050 CHK_PICK_PICKUP;
1051 continue;
1052 }
1053
1054 if (op->contr->mode & PU_ARROW)
1055 if (tmp->type == ARROW)
1056 {
1057 CHK_PICK_PICKUP;
1058 continue;
1059 }
1060
1061 /* all kinds of armor etc. */
1062 if (op->contr->mode & PU_ARMOUR)
1063 if (tmp->type == ARMOUR)
1064 {
1065 CHK_PICK_PICKUP;
1066 continue;
1067 }
1068
1069 if (op->contr->mode & PU_HELMET)
1070 if (tmp->type == HELMET)
1071 {
1072 CHK_PICK_PICKUP;
1073 continue;
1074 }
1075
1076 if (op->contr->mode & PU_SHIELD)
1077 if (tmp->type == SHIELD)
1078 {
1079 CHK_PICK_PICKUP;
1080 continue;
1081 }
1082
1144 if (op->contr->mode & PU_FOOD) 1083 if (op->contr->mode & PU_BOOTS)
1145 if (tmp->type == FOOD) 1084 if (tmp->type == BOOTS)
1085 {
1086 CHK_PICK_PICKUP;
1087 continue;
1088 }
1089
1090 if (op->contr->mode & PU_GLOVES)
1091 if (tmp->type == GLOVES)
1092 {
1093 CHK_PICK_PICKUP;
1094 continue;
1095 }
1096
1097 if (op->contr->mode & PU_CLOAK)
1098 if (tmp->type == CLOAK)
1099 {
1100 CHK_PICK_PICKUP;
1101 continue;
1102 }
1103
1104 /* hoping to catch throwing daggers here */
1105 if (op->contr->mode & PU_MISSILEWEAPON)
1106 if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_IS_THROWN))
1107 {
1108 CHK_PICK_PICKUP;
1109 continue;
1110 }
1111
1112 /* careful: chairs and tables are weapons! */
1113 if (op->contr->mode & PU_ALLWEAPON)
1114 {
1115 if (tmp->type == WEAPON)
1116 if (!tmp->arch->archname.contains ("table") && !tmp->arch->archname.contains ("chair"))
1146 { 1117 {
1147 CHK_PICK_PICKUP; 1118 CHK_PICK_PICKUP;
1148 continue; 1119 continue;
1149 } 1120 }
1121 }
1150 1122
1123 /* misc stuff that's useful */
1151 if (op->contr->mode & PU_DRINK) 1124 if (op->contr->mode & PU_KEY)
1152 if (tmp->type == DRINK || (tmp->type == POISON && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))) 1125 if (tmp->type == KEY || tmp->type == SPECIAL_KEY)
1153 { 1126 {
1154 CHK_PICK_PICKUP; 1127 CHK_PICK_PICKUP;
1155 continue; 1128 continue;
1156 } 1129 }
1157 1130
1131 /* any of the last 4 bits set means we use the ratio for value
1132 * pickups */
1158 if (op->contr->mode & PU_POTION) 1133 if (op->contr->mode & PU_RATIO)
1159 if (tmp->type == POTION) 1134 {
1135 /* use value density to decide what else to grab */
1136 /* >=7 was >= op->contr->mode */
1137 /* >=7 is the old standard setting. Now we take the last 4 bits
1160 { 1138 */
1161 CHK_PICK_PICKUP;
1162 continue;
1163 }
1164
1165 /* spellbooks, skillscrolls and normal books/scrolls */
1166 if (op->contr->mode & PU_SPELLBOOK)
1167 if (tmp->type == SPELLBOOK)
1168 {
1169 CHK_PICK_PICKUP;
1170 continue;
1171 }
1172
1173 if (op->contr->mode & PU_SKILLSCROLL)
1174 if (tmp->type == SKILLSCROLL)
1175 {
1176 CHK_PICK_PICKUP;
1177 continue;
1178 }
1179
1180 if (op->contr->mode & PU_READABLES)
1181 if (tmp->type == BOOK || tmp->type == SCROLL || tmp->type == INSCRIBABLE)
1182 {
1183 CHK_PICK_PICKUP;
1184 continue;
1185 }
1186
1187 /* wands/staves/rods/horns */
1188 if (op->contr->mode & PU_MAGIC_DEVICE)
1189 if (tmp->type == WAND || tmp->type == ROD || tmp->type == HORN)
1190 {
1191 CHK_PICK_PICKUP;
1192 continue;
1193 }
1194
1195 /* pick up all magical items */
1196 if (op->contr->mode & PU_MAGICAL) 1139 wvratio = op->contr->mode & PU_RATIO;
1197 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)) 1140 if (1000 * query_cost (tmp, op, F_TRUE) / tmp->total_weight () >= wvratio * 100)
1198 {
1199 CHK_PICK_PICKUP;
1200 continue;
1201 }
1202
1203 if (op->contr->mode & PU_VALUABLES)
1204 { 1141 {
1205 if (tmp->type == MONEY || tmp->type == GEM) 1142#if 0
1143 fprintf (stderr, "HIGH WEIGHT/VALUE [");
1144 if (tmp->name != NULL)
1206 { 1145 {
1207 CHK_PICK_PICKUP; 1146 fprintf (stderr, "%s", tmp->name);
1208 continue;
1209 } 1147 }
1210 }
1211
1212 /* rings & amulets - talismans seems to be typed AMULET */
1213 if (op->contr->mode & PU_JEWELS)
1214 if (tmp->type == RING || tmp->type == AMULET)
1215 {
1216 CHK_PICK_PICKUP;
1217 continue;
1218 }
1219
1220 /* we don't forget dragon food */
1221 if (op->contr->mode & PU_FLESH)
1222 if (tmp->type == FLESH)
1223 {
1224 CHK_PICK_PICKUP;
1225 continue;
1226 }
1227
1228 /* bows and arrows. Bows are good for selling! */
1229 if (op->contr->mode & PU_BOW)
1230 if (tmp->type == BOW)
1231 {
1232 CHK_PICK_PICKUP;
1233 continue;
1234 }
1235
1236 if (op->contr->mode & PU_ARROW)
1237 if (tmp->type == ARROW)
1238 {
1239 CHK_PICK_PICKUP;
1240 continue;
1241 }
1242
1243 /* all kinds of armor etc. */
1244 if (op->contr->mode & PU_ARMOUR)
1245 if (tmp->type == ARMOUR)
1246 {
1247 CHK_PICK_PICKUP;
1248 continue;
1249 }
1250
1251 if (op->contr->mode & PU_HELMET)
1252 if (tmp->type == HELMET)
1253 {
1254 CHK_PICK_PICKUP;
1255 continue;
1256 }
1257
1258 if (op->contr->mode & PU_SHIELD)
1259 if (tmp->type == SHIELD)
1260 {
1261 CHK_PICK_PICKUP;
1262 continue;
1263 }
1264
1265 if (op->contr->mode & PU_BOOTS)
1266 if (tmp->type == BOOTS)
1267 {
1268 CHK_PICK_PICKUP;
1269 continue;
1270 }
1271
1272 if (op->contr->mode & PU_GLOVES)
1273 if (tmp->type == GLOVES)
1274 {
1275 CHK_PICK_PICKUP;
1276 continue;
1277 }
1278
1279 if (op->contr->mode & PU_CLOAK)
1280 if (tmp->type == CLOAK)
1281 {
1282 CHK_PICK_PICKUP;
1283 continue;
1284 }
1285
1286 /* hoping to catch throwing daggers here */
1287 if (op->contr->mode & PU_MISSILEWEAPON)
1288 if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_IS_THROWN))
1289 {
1290 CHK_PICK_PICKUP;
1291 continue;
1292 }
1293
1294 /* careful: chairs and tables are weapons! */
1295 if (op->contr->mode & PU_ALLWEAPON)
1296 {
1297 if (tmp->type == WEAPON && tmp->name != NULL)
1298 {
1299 if (strstr (tmp->name, "table") == NULL && strstr (tmp->arch->archname, "table") == NULL &&
1300 strstr (tmp->name, "chair") && strstr (tmp->arch->archname, "chair") == NULL)
1301 {
1302 CHK_PICK_PICKUP;
1303 continue;
1304 }
1305 }
1306
1307 if (tmp->type == WEAPON && tmp->name == NULL)
1308 {
1309 if (strstr (tmp->arch->archname, "table") == NULL && strstr (tmp->arch->archname, "chair") == NULL)
1310 {
1311 CHK_PICK_PICKUP;
1312 continue;
1313 }
1314 }
1315 }
1316
1317 /* misc stuff that's useful */
1318 if (op->contr->mode & PU_KEY)
1319 if (tmp->type == KEY || tmp->type == SPECIAL_KEY)
1320 {
1321 CHK_PICK_PICKUP;
1322 continue;
1323 }
1324
1325 /* any of the last 4 bits set means we use the ratio for value
1326 * pickups */
1327 if (op->contr->mode & PU_RATIO)
1328 {
1329 /* use value density to decide what else to grab */
1330 /* >=7 was >= op->contr->mode */
1331 /* >=7 is the old standard setting. Now we take the last 4 bits
1332 * and multiply them by 5, giving 0..15*5== 5..75 */
1333 wvratio = (op->contr->mode & PU_RATIO) * 5;
1334 if ((query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))) >= (unsigned int) wvratio)
1335 {
1336 CHK_PICK_PICKUP;
1337#if 0
1338 fprintf (stderr, "HIGH WEIGHT/VALUE [");
1339 if (tmp->name != NULL)
1340 {
1341 fprintf (stderr, "%s", tmp->name);
1342 }
1343 else 1148 else
1344 fprintf (stderr, "%s", tmp->arch->archname); 1149 fprintf (stderr, "%s", tmp->arch->archname);
1345 fprintf (stderr, ",%d] = ", tmp->type); 1150 fprintf (stderr, ",%d] = ", tmp->type);
1346 fprintf (stderr, "%d\n", (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1)))); 1151 fprintf (stderr, "%d\n", (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))));
1347#endif 1152#endif
1153 CHK_PICK_PICKUP;
1348 continue; 1154 continue;
1349 }
1350 } 1155 }
1351 } /* the new pickup model */ 1156 } /* the new pickup model */
1352 } 1157 }
1353 1158
1354 return !stop; 1159 return !stop;
1382 * against the target. A full test is not performed, simply a basic test 1187 * against the target. A full test is not performed, simply a basic test
1383 * of resistances. The archer is making a quick guess at what he sees down 1188 * of resistances. The archer is making a quick guess at what he sees down
1384 * the hall. Failing that it does it's best to pick the highest plus arrow. 1189 * the hall. Failing that it does it's best to pick the highest plus arrow.
1385 */ 1190 */
1386object * 1191object *
1387find_better_arrow (object *op, object *target, const char *type, int *better) 1192find_better_arrow (object *op, object *target, shstr_cmp type, int *better)
1388{ 1193{
1389 object *tmp = NULL, *arrow, *ntmp; 1194 object *tmp = NULL, *arrow, *ntmp;
1390 int attacknum, attacktype, betterby = 0, i; 1195 int attacknum, attacktype, betterby = 0, i;
1391 1196
1392 if (!type) 1197 if (!type)
1396 { 1201 {
1397 if (arrow->type == CONTAINER && arrow->race == type && QUERY_FLAG (arrow, FLAG_APPLIED)) 1202 if (arrow->type == CONTAINER && arrow->race == type && QUERY_FLAG (arrow, FLAG_APPLIED))
1398 { 1203 {
1399 i = 0; 1204 i = 0;
1400 ntmp = find_better_arrow (arrow, target, type, &i); 1205 ntmp = find_better_arrow (arrow, target, type, &i);
1206
1401 if (i > betterby) 1207 if (i > betterby)
1402 { 1208 {
1403 tmp = ntmp; 1209 tmp = ntmp;
1404 betterby = i; 1210 betterby = i;
1405 } 1211 }
1406 } 1212 }
1407 else if (arrow->type == ARROW && arrow->race == type) 1213 else if (arrow->type == ARROW && arrow->race == type)
1408 { 1214 {
1409 /* allways prefer assasination/slaying */ 1215 /* allways prefer assasination/slaying */
1410 if (target->race != NULL && arrow->slaying != NULL && strstr (arrow->slaying, target->race)) 1216 if (target->race && arrow->slaying.contains (target->race))
1411 { 1217 {
1412 if (arrow->attacktype & AT_DEATH) 1218 if (arrow->attacktype & AT_DEATH)
1413 { 1219 {
1414 *better = 100; 1220 *better = 100;
1415 return arrow; 1221 return arrow;
1430 { 1236 {
1431 tmp = arrow; 1237 tmp = arrow;
1432 betterby = (arrow->magic + arrow->stats.dam) * (100 - target->arch->resist[attacknum]) / 100; 1238 betterby = (arrow->magic + arrow->stats.dam) * (100 - target->arch->resist[attacknum]) / 100;
1433 } 1239 }
1434 } 1240 }
1241
1435 if ((2 + arrow->magic + arrow->stats.dam) > betterby) 1242 if ((2 + arrow->magic + arrow->stats.dam) > betterby)
1436 { 1243 {
1437 tmp = arrow; 1244 tmp = arrow;
1438 betterby = 2 + arrow->magic + arrow->stats.dam; 1245 betterby = 2 + arrow->magic + arrow->stats.dam;
1439 } 1246 }
1247
1440 if (arrow->title && (1 + arrow->magic + arrow->stats.dam) > betterby) 1248 if (arrow->title && (1 + arrow->magic + arrow->stats.dam) > betterby)
1441 { 1249 {
1442 tmp = arrow; 1250 tmp = arrow;
1443 betterby = 1 + arrow->magic + arrow->stats.dam; 1251 betterby = 1 + arrow->magic + arrow->stats.dam;
1444 } 1252 }
1445 } 1253 }
1446 } 1254 }
1447 } 1255 }
1256
1448 if (tmp == NULL && arrow == NULL) 1257 if (tmp == NULL && arrow == NULL)
1449 return find_arrow (op, type); 1258 return find_arrow (op, type);
1450 1259
1451 *better = betterby; 1260 *better = betterby;
1452 return tmp; 1261 return tmp;
1457 * op = the shooter 1266 * op = the shooter
1458 * type = bow->race 1267 * type = bow->race
1459 * dir = fire direction 1268 * dir = fire direction
1460 */ 1269 */
1461object * 1270object *
1462pick_arrow_target (object *op, const char *type, int dir) 1271pick_arrow_target (object *op, shstr_cmp type, int dir)
1463{ 1272{
1464 object *tmp = NULL; 1273 object *tmp = NULL;
1465 maptile *m; 1274 maptile *m;
1466 int i, mflags, found, number; 1275 int i, mflags, found, number;
1467 sint16 x, y; 1276 sint16 x, y;
1482 for (i = 0, found = 0; i < 20; i++) 1291 for (i = 0, found = 0; i < 20; i++)
1483 { 1292 {
1484 x += freearr_x[dir]; 1293 x += freearr_x[dir];
1485 y += freearr_y[dir]; 1294 y += freearr_y[dir];
1486 mflags = get_map_flags (m, &m, x, y, &x, &y); 1295 mflags = get_map_flags (m, &m, x, y, &x, &y);
1296
1487 if (mflags & P_OUT_OF_MAP || mflags & P_BLOCKSVIEW) 1297 if (mflags & P_OUT_OF_MAP || mflags & P_BLOCKSVIEW)
1488 { 1298 {
1489 tmp = NULL; 1299 tmp = 0;
1490 break; 1300 break;
1491 } 1301 }
1492 else if (GET_MAP_MOVE_BLOCK (m, x, y) == MOVE_FLY_LOW) 1302 else if (GET_MAP_MOVE_BLOCK (m, x, y) == MOVE_FLY_LOW)
1493 { 1303 {
1494 /* This block presumes arrows and the like are MOVE_FLY_SLOW - 1304 /* This block presumes arrows and the like are MOVE_FLY_SLOW -
1495 * perhaps a bad assumption. 1305 * perhaps a bad assumption.
1496 */ 1306 */
1497 tmp = NULL; 1307 tmp = 0;
1498 break; 1308 break;
1499 } 1309 }
1310
1500 if (mflags & P_IS_ALIVE) 1311 if (mflags & P_IS_ALIVE)
1501 {
1502 for (tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above) 1312 for (tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above)
1503 if (QUERY_FLAG (tmp, FLAG_ALIVE)) 1313 if (QUERY_FLAG (tmp, FLAG_ALIVE))
1504 {
1505 found++;
1506 break;
1507 }
1508 if (found)
1509 break; 1314 break;
1510 }
1511 } 1315 }
1512 if (tmp == NULL) 1316
1317 if (!tmp)
1513 return find_arrow (op, type); 1318 return find_arrow (op, type);
1514 1319
1515 if (tmp->head) 1320 if (tmp->head)
1516 tmp = tmp->head; 1321 tmp = tmp->head;
1517 1322
1557 LOG (llevError, "Range: bow without activated bow (%s).\n", &op->name); 1362 LOG (llevError, "Range: bow without activated bow (%s).\n", &op->name);
1558 return 0; 1363 return 0;
1559 } 1364 }
1560 1365
1561 // optimisation: move object to top so we will find it quickly again 1366 // optimisation: move object to top so we will find it quickly again
1562 if (bow->below) 1367 splay (bow);
1563 {
1564 bow->remove ();
1565 op->insert (bow);
1566 }
1567
1568 } 1368 }
1569 1369
1570 if (!bow->race || !bow->skill) 1370 if (!bow->race || !bow->skill)
1571 { 1371 {
1572 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s is broken.", &bow->name); 1372 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s is broken.", &bow->name);
1598 } 1398 }
1599 1399
1600 /* this should not happen, but sometimes does */ 1400 /* this should not happen, but sometimes does */
1601 if (arrow->nrof == 0) 1401 if (arrow->nrof == 0)
1602 { 1402 {
1403 LOG (llevError | logBacktrace, "arrow (%s) has nrof 0\n", arrow->debug_desc ());
1603 arrow->destroy (); 1404 arrow->destroy ();
1604 return 0; 1405 return 0;
1605 } 1406 }
1606 1407
1607 left = arrow; /* these are arrows left to the player */ 1408 left = arrow; /* these are arrows left to the player */
1617 arrow->direction = dir; 1418 arrow->direction = dir;
1618 1419
1619 arrow->stats.sp = arrow->stats.wc; /* save original wc, dam, attacktype and slaying */ 1420 arrow->stats.sp = arrow->stats.wc; /* save original wc, dam, attacktype and slaying */
1620 arrow->stats.hp = arrow->stats.dam; 1421 arrow->stats.hp = arrow->stats.dam;
1621 arrow->stats.grace = arrow->attacktype; 1422 arrow->stats.grace = arrow->attacktype;
1622 1423 arrow->custom_name = arrow->slaying;
1623 if (arrow->slaying)
1624 arrow->spellarg = strdup (arrow->slaying);
1625 1424
1626#if 0 1425#if 0
1627 if (player *pl = op->contr) 1426 if (player *pl = op->contr)
1628 { 1427 {
1629 float speed = pl->weapon_sp; 1428 float speed = pl->weapon_sp;
1694 * hence the function name. 1493 * hence the function name.
1695 */ 1494 */
1696int 1495int
1697player_fire_bow (object *op, int dir) 1496player_fire_bow (object *op, int dir)
1698{ 1497{
1699 int ret = 0, wcmod = 0; 1498 int ret;
1700 1499
1701 if (op->contr->bowtype == bow_bestarrow) 1500 if (op->contr->bowtype == bow_bestarrow)
1702 { 1501 {
1703 ret = fire_bow (op, op, pick_arrow_target (op, op->contr->ranged_ob->race, dir), dir, 0, op->x, op->y); 1502 ret = fire_bow (op, op, pick_arrow_target (op, op->contr->ranged_ob->race, dir), dir, 0, op->x, op->y);
1704 } 1503 }
1705 else if (op->contr->bowtype >= bow_n && op->contr->bowtype <= bow_nw) 1504 else if (op->contr->bowtype >= bow_n && op->contr->bowtype <= bow_nw)
1706 { 1505 {
1707 if (!similar_direction (dir, op->contr->bowtype - bow_n + 1)) 1506 int wcmod = similar_direction (dir, op->contr->bowtype - bow_n + 1) ? 0 : -1;
1708 wcmod = -1;
1709
1710 ret = fire_bow (op, op, NULL, op->contr->bowtype - bow_n + 1, wcmod, op->x, op->y); 1507 ret = fire_bow (op, op, NULL, op->contr->bowtype - bow_n + 1, wcmod, op->x, op->y);
1711 } 1508 }
1712 else if (op->contr->bowtype == bow_threewide) 1509 else if (op->contr->bowtype == bow_threewide)
1713 { 1510 {
1714 ret = fire_bow (op, op, NULL, dir, 0, op->x, op->y); 1511 ret = fire_bow (op, op, NULL, dir, 0, op->x, op->y);
1715 ret |= fire_bow (op, op, NULL, dir, -5, op->x + freearr_x[absdir (dir + 2)], op->y + freearr_y[absdir (dir + 2)]); 1512 ret |= fire_bow (op, op, NULL, dir, -5, op->x + freearr_x[absdir (dir + 2)], op->y + freearr_y[absdir (dir + 2)]);
1716 ret |= fire_bow (op, op, NULL, dir, -5, op->x + freearr_x[absdir (dir - 2)], op->y + freearr_y[absdir (dir - 2)]); 1513 ret |= fire_bow (op, op, NULL, dir, -5, op->x + freearr_x[absdir (dir - 2)], op->y + freearr_y[absdir (dir - 2)]);
1717 } 1514 }
1718 else if (op->contr->bowtype == bow_spreadshot) 1515 else if (op->contr->bowtype == bow_spreadshot)
1719 { 1516 {
1720 ret |= fire_bow (op, op, NULL, dir, 0, op->x, op->y); 1517 ret = fire_bow (op, op, NULL, dir, 0, op->x, op->y);
1721 ret |= fire_bow (op, op, NULL, absdir (dir - 1), -5, op->x, op->y); 1518 ret |= fire_bow (op, op, NULL, absdir (dir - 1), -5, op->x, op->y);
1722 ret |= fire_bow (op, op, NULL, absdir (dir + 1), -5, op->x, op->y); 1519 ret |= fire_bow (op, op, NULL, absdir (dir + 1), -5, op->x, op->y);
1723 } 1520 }
1724 else 1521 else
1725 { 1522 {
1763 return; 1560 return;
1764 } 1561 }
1765 } 1562 }
1766 else if (item->type == ROD || item->type == HORN) 1563 else if (item->type == ROD || item->type == HORN)
1767 { 1564 {
1768 if (item->stats.hp < MAX (item->inv->stats.sp, item->inv->stats.grace)) 1565 sint16 spell_sp = MAX (item->inv->stats.sp, item->inv->stats.grace);
1566
1567 // using the maximum of the rods charge allows at least one spell cast
1568 // for a rod or horn, this fixes some broken rods.
1569 if (item->stats.hp < MIN (spell_sp, item->stats.maxhp))
1769 { 1570 {
1770 op->contr->play_sound (sound_find ("wand_poof")); 1571 op->contr->play_sound (sound_find ("wand_poof"));
1771 1572
1772 if (item->type == ROD) 1573 if (item->type == ROD)
1773 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s whines for a while, but nothing happens.", query_base_name (item, 0)); 1574 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s whines for a while, but nothing happens.", query_base_name (item, 0));
1778 } 1579 }
1779 } 1580 }
1780 1581
1781 if (cast_spell (op, item, dir, item->inv, NULL)) 1582 if (cast_spell (op, item, dir, item->inv, NULL))
1782 { 1583 {
1783 SET_FLAG (op, FLAG_BEEN_APPLIED); /* You now know something about it */ 1584 item->flag [FLAG_BEEN_APPLIED] = true; /* You now know something about it */
1585
1784 if (item->type == WAND) 1586 if (item->type == WAND)
1785 { 1587 {
1786 if (!(--item->stats.food)) 1588 if (!(--item->stats.food))
1787 { 1589 {
1788 object *tmp; 1590 object *tmp;
1792 CLEAR_FLAG (item, FLAG_ANIMATE); 1594 CLEAR_FLAG (item, FLAG_ANIMATE);
1793 item->face = item->arch->face; 1595 item->face = item->arch->face;
1794 item->set_speed (0); 1596 item->set_speed (0);
1795 } 1597 }
1796 1598
1797 if ((tmp = item->in_player ())) 1599 if (object *pl = item->visible_to ())
1798 esrv_update_item (UPD_ANIM, tmp, item); 1600 esrv_update_item (UPD_ANIM, pl, item);
1799 } 1601 }
1800 } 1602 }
1801 else if (item->type == ROD || item->type == HORN) 1603 else if (item->type == ROD || item->type == HORN)
1802 drain_rod_charge (item); 1604 drain_rod_charge (item);
1803 } 1605 }
1808bool 1610bool
1809fire (object *op, int dir) 1611fire (object *op, int dir)
1810{ 1612{
1811 int spellcost = 0; 1613 int spellcost = 0;
1812 1614
1813 /* check for loss of invisiblity/hide */
1814 if (action_makes_visible (op))
1815 make_visible (op);
1816
1817 player *pl = op->contr; 1615 player *pl = op->contr;
1818 1616
1819 if (pl->golem) 1617 if (pl->golem)
1820 { 1618 {
1821 control_golem (op->contr->golem, dir); 1619 control_golem (op->contr->golem, dir);
1823 } 1621 }
1824 1622
1825 object *ob = pl->ranged_ob; 1623 object *ob = pl->ranged_ob;
1826 1624
1827 if (!ob) 1625 if (!ob)
1828 return false;
1829
1830 if (!op->change_weapon (ob))
1831 return false; 1626 return false;
1832 1627
1833 if (op->speed_left > 0.f) 1628 if (op->speed_left > 0.f)
1834 --op->speed_left; 1629 --op->speed_left;
1835 else 1630 else
1836 return false; 1631 return false;
1837 1632
1633 if (!op->change_weapon (ob))
1634 return false;
1635
1636 /* check for loss of invisiblity/hide */
1637 if (action_makes_visible (op))
1638 make_visible (op);
1639
1838 switch (ob->type) 1640 switch (ob->type)
1839 { 1641 {
1840 case BOW: 1642 case BOW:
1841 player_fire_bow (op, dir); 1643 player_fire_bow (op, dir);
1842 break; 1644 break;
1843 1645
1844 case SPELL: 1646 case SPELL:
1845 spellcost = cast_spell (op, op, dir, ob, pl->spellparam[0] ? pl->spellparam : 0); 1647 spellcost = cast_spell (op, op, dir, ob, *pl->spellparam ? pl->spellparam : 0);
1846 break; 1648 break;
1847 1649
1848 case BUILDER: 1650 case BUILDER:
1849 apply_map_builder (op, dir); 1651 apply_map_builder (op, dir);
1850 break; 1652 break;
1859 } 1661 }
1860 1662
1861 return true; 1663 return true;
1862} 1664}
1863 1665
1864/* find_key 1666static object *
1865 * We try to find a key for the door as passed. If we find a key
1866 * and successfully use it, we return the key, otherwise NULL
1867 * This function merges both normal and locked door, since the logic
1868 * for both is the same - just the specific key is different.
1869 * pl is the player,
1870 * inv is the objects inventory to searched
1871 * door is the door we are trying to match against.
1872 * This function can be called recursively to search containers.
1873 */
1874object *
1875find_key (object *pl, object *container, object *door) 1667find_key_ (object *pl, object *container, object *door)
1876{ 1668{
1877 object *tmp, *key; 1669 object *tmp, *key;
1878 1670
1879 /* Should not happen, but sanity checking is never bad */ 1671 /* Should not happen, but sanity checking is never bad */
1880 if (!container->inv) 1672 if (!container->inv)
1883 /* First, lets try to find a key in the top level inventory */ 1675 /* First, lets try to find a key in the top level inventory */
1884 for (tmp = container->inv; tmp; tmp = tmp->below) 1676 for (tmp = container->inv; tmp; tmp = tmp->below)
1885 { 1677 {
1886 if (door->type == DOOR && tmp->type == KEY) 1678 if (door->type == DOOR && tmp->type == KEY)
1887 break; 1679 break;
1680
1888 /* For sanity, we should really check door type, but other stuff 1681 /* For sanity, we should really check door type, but other stuff
1889 * (like containers) can be locked with special keys 1682 * (like containers) can be locked with special keys
1890 */ 1683 */
1891 if (tmp->slaying && tmp->type == SPECIAL_KEY && tmp->slaying == door->slaying) 1684 if (tmp->slaying && tmp->type == SPECIAL_KEY && tmp->slaying == door->slaying)
1892 break; 1685 break;
1898 * a key, return 1691 * a key, return
1899 */ 1692 */
1900 if (!tmp) 1693 if (!tmp)
1901 { 1694 {
1902 for (tmp = container->inv; tmp; tmp = tmp->below) 1695 for (tmp = container->inv; tmp; tmp = tmp->below)
1903 {
1904 /* No reason to search empty containers */ 1696 /* No reason to search empty containers */
1905 if (tmp->type == CONTAINER && tmp->inv) 1697 if (tmp->type == CONTAINER && tmp->inv)
1906 {
1907 if ((key = find_key (pl, tmp, door))) 1698 if ((key = find_key_ (pl, tmp, door)))
1908 return key; 1699 return key;
1909 }
1910 }
1911 1700
1912 if (!tmp) 1701 if (!tmp)
1913 return NULL; 1702 return 0;
1914 } 1703 }
1915 1704
1916 /* We get down here if we have found a key. Now if its in a container, 1705 /* We get down here if we have found a key. Now if its in a container,
1917 * see if we actually want to use it 1706 * see if we actually want to use it
1918 */ 1707 */
1919 if (pl != container) 1708 if (pl != container)
1920 { 1709 {
1921 /* Only let players use keys in containers */ 1710 /* Only let players use keys in containers */
1922 if (!pl->contr) 1711 if (!pl->contr)
1923 return NULL; 1712 return 0;
1713
1924 /* cases where this fails: 1714 /* cases where this fails:
1925 * If we only search the player inventory, return now since we 1715 * If we only search the player inventory, return now since we
1926 * are not in the players inventory. 1716 * are not in the players inventory.
1927 * If the container is not active, return now since only active 1717 * If the container is not active, return now since only active
1928 * containers can be used. 1718 * containers can be used.
1932 * inv must have been an container and must have been active. 1722 * inv must have been an container and must have been active.
1933 * 1723 *
1934 * Change the color so that the message doesn't disappear with 1724 * Change the color so that the message doesn't disappear with
1935 * all the others. 1725 * all the others.
1936 */ 1726 */
1937 if (pl->contr->usekeys == key_inventory || 1727 if (pl->contr->usekeys == key_inventory
1938 !QUERY_FLAG (container, FLAG_APPLIED) || 1728 || !QUERY_FLAG (container, FLAG_APPLIED)
1939 (pl->contr->usekeys == keyrings && (!container->race || strcmp (container->race, "keys")))) 1729 || (pl->contr->usekeys == keyrings && container->race != shstr_keys))
1940 { 1730 {
1941 new_draw_info_format (NDI_UNIQUE | NDI_BROWN, 0, pl, 1731 new_draw_info_format (NDI_UNIQUE | NDI_BROWN, 0, pl,
1942 "The %s in your %s vibrates as you approach the door", query_name (tmp), query_name (container)); 1732 "The %s in your %s vibrates as you approach the door", query_name (tmp), query_name (container));
1943 return NULL; 1733 return NULL;
1944 } 1734 }
1945 } 1735 }
1946 1736
1947 return tmp; 1737 return tmp;
1738}
1739
1740/* find_key
1741 * We try to find a key for the door as passed. If we find a key
1742 * and successfully use it, we return the key, otherwise NULL
1743 * This function merges both normal and locked door, since the logic
1744 * for both is the same - just the specific key is different.
1745 * pl is the player,
1746 * inv is the objects inventory to searched
1747 * door is the door we are trying to match against.
1748 * This function can be called recursively to search containers.
1749 */
1750object *
1751find_key (object *pl, object *container, object *door)
1752{
1753 if (door->slaying && is_match_expr (door->slaying))
1754 {
1755 // for match expressions, we try to find the key by applying the match
1756 // to the op itself, which is supposed to find the "key", instead
1757 // of searching through containers ourselves.
1758
1759 return match_one (door->slaying, container, door, pl, pl);
1760 }
1761 else
1762 return find_key_ (pl, container, door);
1948} 1763}
1949 1764
1950/* moved door processing out of move_player_attack. 1765/* moved door processing out of move_player_attack.
1951 * returns 1 if player has opened the door with a key 1766 * returns 1 if player has opened the door with a key
1952 * such that the caller should not do anything more, 1767 * such that the caller should not do anything more,
1980 remove_door2 (door); /* remove door without violence ;-) */ 1795 remove_door2 (door); /* remove door without violence ;-) */
1981 } 1796 }
1982 1797
1983 /* Do this after we print the message */ 1798 /* Do this after we print the message */
1984 key->decrease (); /* Use up one of the keys */ 1799 key->decrease (); /* Use up one of the keys */
1985 /* Need to update the weight the container the key was in */
1986 if (container != op)
1987 esrv_update_item (UPD_WEIGHT, op, container);
1988 1800
1989 return 1; /* Nothing more to do below */ 1801 return 1; /* Nothing more to do below */
1990 } 1802 }
1991 else if (door->type == LOCKED_DOOR) 1803 else if (door->type == LOCKED_DOOR)
1992 { 1804 {
2005 * going to try and move (not fire weapons). 1817 * going to try and move (not fire weapons).
2006 */ 1818 */
2007bool 1819bool
2008move_player_attack (object *op, int dir) 1820move_player_attack (object *op, int dir)
2009{ 1821{
1822 if (!op->contr->braced && op->speed_left > 0.f && move_ob (op, dir, op))
1823 {
1824 --op->speed_left;
1825 return true;
1826 }
1827
2010 int on_battleground; 1828 int on_battleground;
2011 1829
2012 sint16 nx = freearr_x[dir] + op->x; 1830 sint16 nx = freearr_x[dir] + op->x;
2013 sint16 ny = freearr_y[dir] + op->y; 1831 sint16 ny = freearr_y[dir] + op->y;
2014 1832
2015 on_battleground = op_on_battleground (op, 0, 0); 1833 on_battleground = op_on_battleground (op, 0, 0);
2016 1834
2017 if (out_of_map (op->map, nx, ny)) 1835 if (out_of_map (op->map, nx, ny))
2018 return false; 1836 return false;
2019
2020 if (!op->contr->braced && op->speed_left > 0.f && move_ob (op, dir, op))
2021 {
2022 --op->speed_left;
2023 return true;
2024 }
2025 1837
2026 /* If braced, or can't move to the square, and it is not out of the 1838 /* If braced, or can't move to the square, and it is not out of the
2027 * map, attack it. Note order of if statement is important - don't 1839 * map, attack it. Note order of if statement is important - don't
2028 * want to be calling move_ob if braced, because move_ob will move the 1840 * want to be calling move_ob if braced, because move_ob will move the
2029 * player. This is a pretty nasty hack, because if we could 1841 * player. This is a pretty nasty hack, because if we could
2089 --op->speed_left; 1901 --op->speed_left;
2090 1902
2091 op->play_sound (sound_find ("push_player")); 1903 op->play_sound (sound_find ("push_player"));
2092 push_ob (mon, dir, op); 1904 push_ob (mon, dir, op);
2093 1905
2094 if (op->contr->tmp_invis || op->hide) 1906 if (action_makes_visible (op))
2095 make_visible (op); 1907 make_visible (op);
2096 1908
2097 return true; 1909 return true;
2098 } 1910 }
2099 else 1911 else
2121 push_ob (mon, dir, op); 1933 push_ob (mon, dir, op);
2122 } 1934 }
2123 else 1935 else
2124 op->statusmsg ("You withhold your attack"); 1936 op->statusmsg ("You withhold your attack");
2125 1937
2126 if (op->contr->tmp_invis || op->hide) 1938 if (op->contr->tmp_invis || op->flag [FLAG_HIDDEN])
2127 make_visible (op); 1939 make_visible (op);
2128 1940
2129 return true; 1941 return true;
2130 } 1942 }
2131 } 1943 }
2189 if (QUERY_FLAG (op, FLAG_CONFUSED) && dir) 2001 if (QUERY_FLAG (op, FLAG_CONFUSED) && dir)
2190 dir = absdir (dir + rndm (3) + rndm (3) - 2); 2002 dir = absdir (dir + rndm (3) + rndm (3) - 2);
2191 2003
2192 op->facing = dir; 2004 op->facing = dir;
2193 2005
2194 if (op->hide) 2006 if (op->flag [FLAG_HIDDEN])
2195 do_hidden_move (op); 2007 do_hidden_move (op);
2196 2008
2197 bool retval; 2009 bool retval;
2198 2010
2199 if (INVOKE_PLAYER (MOVE, op->contr, ARG_INT (dir))) 2011 if (INVOKE_PLAYER (MOVE, op->contr, ARG_INT (dir)))
2271 if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE)) 2083 if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE))
2272 { 2084 {
2273 op->play_sound (sound_find ("ob_evaporate")); 2085 op->play_sound (sound_find ("ob_evaporate"));
2274 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s vibrates violently, then evaporates.", query_name (tmp)); 2086 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s vibrates violently, then evaporates.", query_name (tmp));
2275 2087
2276 if (op->contr)
2277 esrv_del_item (op->contr, tmp->count);
2278
2279 tmp->destroy (); 2088 tmp->destroy ();
2280 CLEAR_FLAG (op, FLAG_LIFESAVE); 2089 CLEAR_FLAG (op, FLAG_LIFESAVE);
2281 2090
2282 if (op->stats.hp < 0) 2091 if (op->stats.hp < 0)
2283 op->stats.hp = op->stats.maxhp; 2092 op->stats.hp = op->stats.maxhp;
2295 return 0; 2104 return 0;
2296} 2105}
2297 2106
2298/* This goes throws the inventory and removes unpaid objects, and puts them 2107/* This goes throws the inventory and removes unpaid objects, and puts them
2299 * back in the map (location and map determined by values of env). This 2108 * back in the map (location and map determined by values of env). This
2300 * function will descend into containers. op is the object to start the search 2109 * function will descend into containers. op is the object to start the search
2301 * from. 2110 * from.
2302 */ 2111 */
2303static void 2112static void
2304drop_unpaid_items (object *op, object *env) 2113drop_unpaid_items (object *op, object *env)
2305{ 2114{
2306 while (op) 2115 while (op)
2307 { 2116 {
2308 object *next = op->below; /* Make sure we have a good value, in case we remove object 'op' */ 2117 object *next = op->below; /* Make sure we have a good value, in case we remove object 'op' */
2309 2118
2310 if (QUERY_FLAG (op, FLAG_UNPAID)) 2119 if (QUERY_FLAG (op, FLAG_UNPAID))
2311 {
2312 if (env->type == PLAYER)
2313 esrv_del_item (env->contr, op->count);
2314
2315 op->insert_at (env); 2120 op->insert_at (env);
2316 }
2317 else if (op->inv) 2121 else if (op->inv)
2318 drop_unpaid_items (op->inv, env); 2122 drop_unpaid_items (op->inv, env);
2319 2123
2320 op = next; 2124 op = next;
2321 } 2125 }
2333 * Moved from apply.c to player.c - player.c is what 2137 * Moved from apply.c to player.c - player.c is what
2334 * actually uses this function. player.c may not be quite the 2138 * actually uses this function. player.c may not be quite the
2335 * best, a misc file for object actions is probably better, 2139 * best, a misc file for object actions is probably better,
2336 * but there isn't one in the server directory. 2140 * but there isn't one in the server directory.
2337 */ 2141 */
2338char * 2142const char *
2339gravestone_text (object *op) 2143gravestone_text (object *op)
2340{ 2144{
2341 static char buf2[MAX_BUF]; 2145 static dynbuf_text buf;
2342 char buf[MAX_BUF];
2343 time_t now = time (NULL);
2344 2146
2345 strcpy (buf2, " R.I.P.\n\n"); 2147 buf << "---- R.I.P. ----\n\n"
2148 << op->name;
2149
2346 if (op->type == PLAYER) 2150 if (op->type == PLAYER)
2347 sprintf (buf, "%s the %s\n", &op->name, op->contr->title); 2151 buf << " the " << op->contr->title;
2348 else
2349 sprintf (buf, "%s\n", &op->name);
2350 2152
2351 strncat (buf2, " ", 20 - strlen (buf) / 2); 2153 buf << "\n\n";
2352 strcat (buf2, buf); 2154
2155 buf << "who was level ";
2156 buf << (sint32)op->level << "\n\n" // OO breakdown
2157 << " when " << (op->contr ? "killed" : "died") << "\n\n";
2158
2353 if (op->type == PLAYER) 2159 if (op->type == PLAYER)
2354 sprintf (buf, "who was in level %d when killed\n", op->level); 2160 buf << "by " << op->contr->killer_name () << ".\n\n";
2355 else
2356 sprintf (buf, "who was in level %d when died.\n\n", op->level);
2357 2161
2358 strncat (buf2, " ", 20 - strlen (buf) / 2);
2359 strcat (buf2, buf);
2360 if (op->type == PLAYER)
2361 { 2162 {
2362 sprintf (buf, "by %s.\n\n", op->contr->killer); 2163 static char buf2[128];
2363 strncat (buf2, " ", 21 - strlen (buf) / 2); 2164 time_t now = time (NULL);
2364 strcat (buf2, buf);
2365 }
2366
2367 strftime (buf, MAX_BUF, "%b %d %Y\n", localtime (&now)); 2165 strftime (buf2, 128, "%b %d %Y\n\n", localtime (&now));
2368 strncat (buf2, " ", 20 - strlen (buf) / 2); 2166 buf << buf2;
2369 strcat (buf2, buf); 2167 }
2370 2168
2371 return buf2; 2169 return buf;
2372} 2170}
2373 2171
2374void 2172void
2375do_some_living (object *op) 2173do_some_living (object *op)
2376{ 2174{
2531 { 2329 {
2532 over_hp = (gen_hp < 20 ? 30 : gen_hp + 10) / rate_hp; 2330 over_hp = (gen_hp < 20 ? 30 : gen_hp + 10) / rate_hp;
2533 2331
2534 if (over_hp > 0) 2332 if (over_hp > 0)
2535 { 2333 {
2536 op->stats.sp += over_hp + (RANDOM () % rate_hp > ((gen_hp < 20 ? 30 : gen_hp + 10) % rate_hp)) ? -1 : 0; 2334 op->stats.sp += over_hp + (rndm (rate_hp) > ((gen_hp < 20 ? 30 : gen_hp + 10) % rate_hp)) ? -1 : 0;
2537 op->last_heal = 0; 2335 op->last_heal = 0;
2538 } 2336 }
2539 else 2337 else
2540 op->last_heal = rate_hp / (gen_hp < 20 ? 30 : gen_hp + 10); 2338 op->last_heal = rate_hp / (gen_hp < 20 ? 30 : gen_hp + 10);
2541 } 2339 }
2557 op->stats.food--; 2355 op->stats.food--;
2558 } 2356 }
2559 2357
2560 if (op->stats.food < 0 && op->stats.hp >= 0) 2358 if (op->stats.food < 0 && op->stats.hp >= 0)
2561 { 2359 {
2562 object *tmp, *flesh = 0; 2360 object *flesh = 0;
2563 2361
2564 for (tmp = op->inv; tmp; tmp = tmp->below) 2362 for_inv_removable (op, tmp)
2565 { 2363 {
2566 if (!QUERY_FLAG (tmp, FLAG_UNPAID)) 2364 if (QUERY_FLAG (tmp, FLAG_UNPAID))
2365 continue;
2366
2367 if (tmp->type == FOOD || tmp->type == DRINK || tmp->type == POISON)
2567 { 2368 {
2568 if (tmp->type == FOOD || tmp->type == DRINK || tmp->type == POISON) 2369 op->statusmsg ("You blindly grab for a bite of food. "
2569 { 2370 "H<To prevent you from starving, you ate some random item from your backpack.>");
2570 new_draw_info (NDI_UNIQUE, 0, op, "You blindly grab for a bite of food.");
2571 manual_apply (op, tmp, 0); 2371 manual_apply (op, tmp, 0);
2372
2572 if (op->stats.food >= 0 || op->stats.hp < 0) 2373 if (op->stats.food >= 0 || op->stats.hp < 0)
2573 break; 2374 break;
2574 } 2375 }
2575 else if (tmp->type == FLESH) 2376 else if (tmp->type == FLESH)
2576 flesh = tmp; 2377 flesh = tmp;
2577 } /* End if paid for object */ 2378 }
2578 } /* end of for loop */
2579 2379
2580 /* If player is still starving, it means they don't have any food, so 2380 /* If player is still starving, it means they don't have any food, so
2581 * eat flesh instead. 2381 * eat flesh instead.
2582 */ 2382 */
2583 if (op->stats.food < 0 && op->stats.hp >= 0 && flesh) 2383 if (op->stats.food < 0 && op->stats.hp >= 0 && flesh)
2584 { 2384 {
2585 new_draw_info (NDI_UNIQUE, 0, op, "You blindly grab for a bite of food."); 2385 op->statusmsg ("You blindly grab for a bite of food. "
2386 "H<To prevent you from starving, you ate some random item from your backpack.>");
2586 manual_apply (op, flesh, 0); 2387 manual_apply (op, flesh, 0);
2587 } 2388 }
2389
2390 // If player is still starving, alert him!
2391 if (op->stats.food < 0)
2392 op->failmsg ("You are starving! "
2393 "H<Eat some food to increase your food and prevent you from an untimely death.>");
2588 } 2394 }
2589 2395
2590 if (op->stats.food < 0) 2396 if (op->stats.food < 0)
2591 { 2397 {
2592 op->stats.hp += op->stats.food; 2398 op->stats.hp += op->stats.food;
2593 op->stats.food = 0; 2399 op->stats.food = 0;
2400
2401 if (op->stats.hp < 0)
2402 {
2403 op->contr->killer = archetype::get ("killer_starvation");
2404 op->contr->killer->destroy ();
2594 } 2405 }
2406 }
2595 2407
2408 /* killer should be set here already */
2596 if (op->stats.hp < 0 && !QUERY_FLAG (op, FLAG_WIZ)) 2409 if (op->stats.hp < 0 && !QUERY_FLAG (op, FLAG_WIZ))
2597 kill_player (op); 2410 kill_player (op);
2598 } 2411 }
2599} 2412}
2600 2413
2605 */ 2418 */
2606void 2419void
2607kill_player (object *op) 2420kill_player (object *op)
2608{ 2421{
2609 int x, y; 2422 int x, y;
2610 char buf[MAX_BUF];
2611 maptile *map; /* this is for resurrection */ 2423 maptile *map; /* this is for resurrection */
2612 int will_kill_again; 2424 int will_kill_again;
2613 archetype *at; 2425 archetype *at;
2614 object *tmp; 2426 object *tmp;
2615 2427
2616 if (save_life (op)) 2428 if (save_life (op))
2617 return; 2429 return;
2430
2431 dynbuf_text deathtab;
2432
2433 /* restore player */
2434 at = archetype::find ("poisoning");
2435 if (object *tmp = present_arch_in_ob (at, op))
2436 {
2437 tmp->destroy ();
2438 deathtab << "Your body feels cleansed...\r";
2439 }
2440
2441 at = archetype::find ("confusion");
2442 if (object *tmp = present_arch_in_ob (at, op))
2443 {
2444 tmp->destroy ();
2445 deathtab << "Your mind feels clearer...\r";
2446 }
2447
2448 cure_disease (op, 0, 0); /* remove any disease */
2449
2450 max_it (op->stats.hp , op->stats.maxhp);
2451 max_it (op->stats.sp , op->stats.maxsp);
2452 max_it (op->stats.grace, op->stats.maxgrace);
2453
2454 if (op->stats.food <= 0)
2455 op->stats.food = 999;
2456
2457 // remove all spell effects that are active
2458 // to avoid long-term effects such as word-of-recall
2459 for (object *item = op->inv; item; )
2460 {
2461 object *next = item->below;
2462
2463 if (item->type == SPELL_EFFECT && item->active)
2464 item->destroy ();
2465
2466 item = next;
2467 }
2618 2468
2619 /* If player dies on BATTLEGROUND, no stat/exp loss! For Combat-Arenas 2469 /* If player dies on BATTLEGROUND, no stat/exp loss! For Combat-Arenas
2620 * in cities ONLY!!! It is very important that this doesn't get abused. 2470 * in cities ONLY!!! It is very important that this doesn't get abused.
2621 * Look at op_on_battleground() for more info --AndreasV 2471 * Look at op_on_battleground() for more info --AndreasV
2622 */ 2472 */
2623 if (op_on_battleground (op, &x, &y)) 2473 if (op_on_battleground (op, &x, &y))
2624 { 2474 {
2625 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, "You have been defeated in combat!"); 2475 deathtab << "You almost died in combat, but local medics have saved your life...\r";
2626 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, "Local medics have saved your life...");
2627
2628 /* restore player */
2629 at = archetype::find ("poisoning");
2630 if (object *tmp = present_arch_in_ob (at, op))
2631 {
2632 tmp->destroy ();
2633 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed");
2634 }
2635
2636 at = archetype::find ("confusion");
2637 if (object *tmp = present_arch_in_ob (at, op))
2638 {
2639 tmp->destroy ();
2640 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer");
2641 }
2642
2643 cure_disease (op, 0, 0); /* remove any disease */
2644 op->stats.hp = op->stats.maxhp;
2645 if (op->stats.food <= 0)
2646 op->stats.food = 999;
2647 2476
2648 /* create a bodypart-trophy to make the winner happy */ 2477 /* create a bodypart-trophy to make the winner happy */
2649 if (object *tmp = arch_to_object (archetype::find ("finger"))) 2478 if (object *tmp = arch_to_object (archetype::find ("finger")))
2650 { 2479 {
2651 tmp->name = format ("%s's finger" , &op->name); 2480 tmp->name = format ("%s's finger" , &op->name);
2652 tmp->name_pl = format ("%s's fingers", &op->name); 2481 tmp->name_pl = format ("%s's fingers", &op->name);
2653 tmp->msg = format ( 2482 tmp->msg = format (
2654 "This finger has been cut off of %s the %s, when he was defeated at level %d by %s.\n", 2483 "This finger has been cut off of %s the %s, when he was defeated at level %d by %s.\n",
2655 &op->name, op->contr->title, (int) (op->level), op->contr->killer 2484 &op->name, op->contr->title,
2485 (int)op->level,
2486 op->contr->killer_name ()
2656 ); 2487 );
2657 tmp->value = 0, tmp->type = 0; 2488 tmp->value = 0, tmp->type = 0;
2658 tmp->materialname = "organics"; 2489 tmp->materialname = "organics";
2659 tmp->insert_at (op, tmp); 2490 tmp->insert_at (op, tmp);
2660 } 2491 }
2661 2492
2662 /* teleport defeated player to new destination */ 2493 /* teleport defeated player to new destination */
2663 transfer_ob (op, x, y, 0, NULL); 2494 transfer_ob (op, x, y, 0, NULL);
2664 op->contr->braced = 0; 2495 op->contr->braced = 0;
2496
2497 op->contr->infobox (MSG_CHANNEL ("death"), deathtab);
2665 return; 2498 return;
2666 } 2499 }
2667 2500
2501 deathtab << "You were killed by " << op->contr->killer_name () << ".\n\n";
2502 deathtab << "T<YOU HAVE DIED>\n\n";
2503
2668 INVOKE_PLAYER (DEATH, op->contr); 2504 INVOKE_PLAYER (DEATH, op->contr);
2669 2505
2670 command_kill_pets (op, 0); 2506 command_kill_pets (op, 0);
2671
2672 if (op->stats.food < 0)
2673 strcpy (op->contr->killer, "starvation");
2674 2507
2675 op->contr->play_sound (sound_find ("player_dies")); 2508 op->contr->play_sound (sound_find ("player_dies"));
2676 2509
2677 /* save the map location for corpse, gravestone */ 2510 /* save the map location for corpse, gravestone */
2678 x = op->x; 2511 x = op->x;
2708 2541
2709 lost_a_stat = 0; 2542 lost_a_stat = 0;
2710 2543
2711 for (z = 0; z < num_stats_lose; z++) 2544 for (z = 0; z < num_stats_lose; z++)
2712 { 2545 {
2713 i = RANDOM () % NUM_STATS; 2546 i = rndm (NUM_STATS);
2714 2547
2715 if (settings.stat_loss_on_death) 2548 if (settings.stat_loss_on_death)
2716 { 2549 {
2717 /* Pick a random stat and take a point off it. Tell the player 2550 /* Pick a random stat and take a point off it. Tell the player
2718 * what he lost. 2551 * what he lost.
2769 } 2602 }
2770 } 2603 }
2771 2604
2772 if (lose_this_stat) 2605 if (lose_this_stat)
2773 { 2606 {
2774 this_stat = get_attr_value (&(dep->stats), i); 2607 this_stat = get_attr_value (&dep->stats, i);
2775 /* We could try to do something clever like find another 2608 /* We could try to do something clever like find another
2776 * stat to reduce if this fails. But chances are, if 2609 * stat to reduce if this fails. But chances are, if
2777 * stats have been depleted to -50, all are pretty low 2610 * stats have been depleted to -50, all are pretty low
2778 * and should be roughly the same, so it shouldn't make a 2611 * and should be roughly the same, so it shouldn't make a
2779 * difference. 2612 * difference.
2787 lost_a_stat = 1; 2620 lost_a_stat = 1;
2788 } 2621 }
2789 } 2622 }
2790 } 2623 }
2791 } 2624 }
2625
2792 /* If no stat lost, tell the player. */ 2626 /* If no stat lost, tell the player. */
2793 if (!lost_a_stat) 2627 if (!lost_a_stat)
2794 { 2628 {
2795 /* determine_god() seems to not work sometimes... why is this? 2629 /* determine_god() seems to not work sometimes... why is this?
2796 Should I be using something else? GD */ 2630 Should I be using something else? GD */
2797 const char *god = determine_god (op); 2631 shstr_tmp god = determine_god (op);
2798 2632
2799 if (god && (strcmp (god, "none"))) 2633 if (god != shstr_none)
2800 new_draw_info_format (NDI_UNIQUE, 0, op, "For a brief moment you feel the holy presence of %s protecting" " you.", god); 2634 deathtab << "For a brief moment you feel the holy presence of " << god << " protecting you.\r";
2801 else 2635 else
2802 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you feel a holy presence protecting you."); 2636 deathtab << "For a brief moment you feel a holy presence protecting you.\r";
2803 } 2637 }
2804#else 2638#else
2805 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you" " feel a holy presence protecting you from losing yourself completely."); 2639 deathtab << "For a brief moment you feel a holy presence protecting you from losing yourself completely.";
2806#endif 2640#endif
2807 2641
2808 /* Put a gravestone up where the character 'almost' died. List the 2642 /* Put a gravestone up where the character 'almost' died. List the
2809 * exp loss on the stone. 2643 * exp loss on the stone.
2810 */ 2644 */
2811 tmp = arch_to_object (archetype::find ("gravestone")); 2645 tmp = arch_to_object (archetype::find ("gravestone"));
2812 sprintf (buf, "%s's gravestone", &op->name); 2646 tmp->name = format ("%s's gravestone", &op->name);
2813 tmp->name = buf; 2647 tmp->name_pl = format ("%s's gravestones", &op->name);
2814 sprintf (buf, "%s's gravestones", &op->name); 2648 tmp->msg = format ("T<RIP>\n\nHere rests the hero %s the %s,\rwho was killed\rby %s.\n",
2815 tmp->name_pl = buf; 2649 &op->name, op->contr->title, op->contr->killer_name ());
2816 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);
2817 tmp->msg = buf;
2818 tmp->x = op->x, tmp->y = op->y; 2650 tmp->x = op->x, tmp->y = op->y;
2819 insert_ob_in_map (tmp, op->map, NULL, 0); 2651 insert_ob_in_map (tmp, op->map, NULL, 0);
2820 2652
2821 /**************************************/ 2653 /**************************************/
2822 /* */ 2654 /* */
2823 /* Subtract the experience points, */ 2655 /* Subtract the experience points, */
2824 /* if we died cause of food, give us */
2825 /* food, and reset HP's... */
2826 /* */ 2656 /* */
2827 /**************************************/ 2657 /**************************************/
2828 2658
2829 /* remove any poisoning and confusion the character may be suffering. */
2830 /* restore player */
2831 at = archetype::find ("poisoning");
2832 tmp = present_arch_in_ob (at, op);
2833
2834 if (tmp)
2835 {
2836 tmp->destroy ();
2837 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed");
2838 }
2839
2840 at = archetype::find ("confusion");
2841 tmp = present_arch_in_ob (at, op);
2842 if (tmp)
2843 {
2844 tmp->destroy ();
2845 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer");
2846 }
2847
2848 cure_disease (op, 0, 0); /* remove any disease */
2849
2850 /*add_exp(op, (op->stats.exp * -0.20)); */ 2659 /*add_exp(op, (op->stats.exp * -0.20)); */
2851 apply_death_exp_penalty (op); 2660 apply_death_exp_penalty (op);
2852 if (op->stats.food < 100)
2853 op->stats.food = 900;
2854 op->stats.hp = op->stats.maxhp;
2855 op->stats.sp = MAX (op->stats.sp, op->stats.maxsp);
2856 op->stats.grace = MAX (op->stats.grace, op->stats.maxgrace);
2857 2661
2858 /* 2662 /*
2859 * Check to see if the player has any unpaid items. If so, remove them 2663 * Check to see if the player has any unpaid items. If so, remove them
2860 * and put them back in the map. 2664 * and put them back in the map.
2861 */ 2665 */
2896 if (will_kill_again & (1 << at)) 2700 if (will_kill_again & (1 << at))
2897 force->resist[at] = 100; 2701 force->resist[at] = 100;
2898 2702
2899 insert_ob_in_ob (force, op); 2703 insert_ob_in_ob (force, op);
2900 op->update_stats (); 2704 op->update_stats ();
2901
2902 } 2705 }
2903 2706
2904 new_draw_info (NDI_UNIQUE, 0, op, "YOU HAVE DIED."); 2707 op->contr->infobox (MSG_CHANNEL ("death"), deathtab);
2905} 2708}
2906 2709
2907void 2710void
2908loot_object (object *op) 2711loot_object (object *op)
2909{ /* Grab and destroy some treasure */ 2712{ /* Grab and destroy some treasure */
3007} 2810}
3008 2811
3009void 2812void
3010make_visible (object *op) 2813make_visible (object *op)
3011{ 2814{
3012 op->hide = 0; 2815 op->flag [FLAG_HIDDEN] = 0;
3013 op->invisible = 0; 2816 op->invisible = 0;
3014 2817
3015 if (op->type == PLAYER) 2818 if (op->type == PLAYER)
3016 { 2819 {
3017 op->contr->tmp_invis = 0; 2820 op->contr->tmp_invis = 0;
3042 2845
3043 if (!ob || !ob->map) 2846 if (!ob || !ob->map)
3044 return 0; 2847 return 0;
3045 2848
3046 /* so, on normal lighted maps, its hard to hide */ 2849 /* so, on normal lighted maps, its hard to hide */
3047 level = ob->map->darkness - 2; 2850 level = ob->map->darklevel () - 2;
3048 2851
3049 /* this also picks up whether the object is glowing. 2852 /* this also picks up whether the object is glowing.
3050 * If you carry a light on a non-dark map, its not 2853 * If you carry a light on a non-dark map, its not
3051 * as bad as carrying a light on a pitch dark map */ 2854 * as bad as carrying a light on a pitch dark map */
3052 if (has_carried_lights (ob)) 2855 if (ob->has_carried_lights ())
3053 level = -(10 + (2 * ob->map->darkness)); 2856 level = -(10 + (2 * ob->map->darklevel ()));
3054 2857
3055 /* scan through all nearby squares for terrain to hide in */ 2858 /* scan through all nearby squares for terrain to hide in */
3056 for (i = 0, x = ob->x, y = ob->y; 2859 for (i = 0, x = ob->x, y = ob->y;
3057 i <= SIZEOFFREE1; 2860 i <= SIZEOFFREE1;
3058 i++, x = ob->x + freearr_x[i], y = ob->y + freearr_y[i]) 2861 i++, x = ob->x + freearr_x[i], y = ob->y + freearr_y[i])
3079 * spot (surrounded by clear terrain in broad daylight). -b.t. 2882 * spot (surrounded by clear terrain in broad daylight). -b.t.
3080 */ 2883 */
3081void 2884void
3082do_hidden_move (object *op) 2885do_hidden_move (object *op)
3083{ 2886{
3084 int hide = 0, num = random_roll (0, 19, op, PREFER_LOW); 2887 int hide = 0;
3085 object *skop;
3086 2888
3087 if (!op || !op->map) 2889 if (!op || !op->map)
3088 return; 2890 return;
3089 2891
3090 skop = find_obj_by_type_subtype (op, SKILL, SK_HIDING); 2892 object *skop = find_obj_by_type_subtype (op, SKILL, SK_HIDING);
2893 int num = random_roll (0, 19, op, PREFER_LOW);
3091 2894
3092 /* its *extremely* hard to run and sneak/hide at the same time! */ 2895 /* its *extremely* hard to run and sneak/hide at the same time! */
3093 if (op->type == PLAYER && op->contr->run_on) 2896 if (op->type == PLAYER && op->contr->run_on)
3094 if (!skop || num >= skop->level) 2897 if (!skop || num >= skop->level)
3095 { 2898 {
3105 num -= hide; 2908 num -= hide;
3106 2909
3107 if ((op->type == PLAYER && hide < -10) || ((op->invisible -= num) <= 0)) 2910 if ((op->type == PLAYER && hide < -10) || ((op->invisible -= num) <= 0))
3108 { 2911 {
3109 make_visible (op); 2912 make_visible (op);
2913
3110 if (op->type == PLAYER) 2914 if (op->type == PLAYER)
3111 new_draw_info (NDI_UNIQUE, 0, op, "You moved out of hiding! You are visible!"); 2915 new_draw_info (NDI_UNIQUE, 0, op, "You moved out of hiding! You are visible!");
3112 } 2916 }
3113 else if (op->type == PLAYER && skop) 2917 else if (op->type == PLAYER && skop)
3114 change_exp (op, calc_skill_exp (op, NULL, skop), skop->skill, 0); 2918 change_exp (op, calc_skill_exp (op, NULL, skop), skop->skill, 0);
3204 while (op) 3008 while (op)
3205 { 3009 {
3206 dx = rv.distance_x + op->arch->x; 3010 dx = rv.distance_x + op->arch->x;
3207 dy = rv.distance_y + op->arch->y; 3011 dy = rv.distance_y + op->arch->y;
3208 3012
3209 /* only the viewable area the player sees is updated by LOS 3013 if (pl->contr->blocked_los (dx, dy) != LOS_BLOCKED)
3210 * code, so we need to restrict ourselves to that range of values
3211 * for any meaningful values.
3212 */
3213 if (abs (dx) <= (pl->contr->ns->mapx / 2) &&
3214 abs (dy) <= (pl->contr->ns->mapy / 2) &&
3215 !pl->contr->blocked_los[dx + (pl->contr->ns->mapx / 2)][dy + (pl->contr->ns->mapy / 2)])
3216 return 1; 3014 return 1;
3217 3015
3218 op = op->more; 3016 op = op->more;
3219 } 3017 }
3220 3018
3221 return 0; 3019 return 0;
3222} 3020}
3223 3021
3224/* routine for both players and monsters. We call this when 3022/* routine for both players and monsters. We call this when
3225 * there is a possibility for our action distrubing our hiding 3023 * there is a possibility for our action distrubing our hiding
3226 * place or invisiblity spell. Artefact invisiblity is not 3024 * place or invisiblity spell. Artefact invisiblity causes
3227 * effected by this. If we arent invisible to begin with, we 3025 * "noise" instead. If we arent invisible to begin with, we
3228 * return 0. 3026 * return 0.
3229 */ 3027 */
3230int 3028int
3231action_makes_visible (object *op) 3029action_makes_visible (object *op)
3232{ 3030{
3233 if (op->invisible && QUERY_FLAG (op, FLAG_ALIVE)) 3031 if (op->invisible && QUERY_FLAG (op, FLAG_ALIVE))
3234 { 3032 {
3235 if (QUERY_FLAG (op, FLAG_MAKE_INVIS)) 3033 if (QUERY_FLAG (op, FLAG_MAKE_INVIS))
3034 {
3035 // artefact invisibility is permanent, but we still make noise
3036 // this is important for game-balance.
3037 if (op->contr)
3038 op->make_noise ();
3039
3236 return 0; 3040 return 0;
3041 }
3237 3042
3238 if (op->contr && op->contr->tmp_invis == 0) 3043 if (op->contr && op->contr->tmp_invis == 0)
3239 return 0; 3044 return 0;
3240 3045
3241 /* If monsters, they should become visible */ 3046 /* If monsters, they should become visible */
3242 if (op->hide || !op->contr || (op->contr && op->contr->tmp_invis)) 3047 if (op->flag [FLAG_HIDDEN] || !op->contr || (op->contr && op->contr->tmp_invis))
3243 { 3048 {
3244 new_draw_info_format (NDI_UNIQUE, 0, op, "You become %s!", op->hide ? "unhidden" : "visible"); 3049 new_draw_info_format (NDI_UNIQUE, 0, op, "You become %s!", op->flag [FLAG_HIDDEN] ? "unhidden" : "visible");
3245 return 1; 3050 return 1;
3246 } 3051 }
3247 } 3052 }
3248 3053
3249 return 0; 3054 return 0;
3455 else 3260 else
3456 { 3261 {
3457 /* generate misc. treasure */ 3262 /* generate misc. treasure */
3458 tmp = arch_to_object (tr->item); 3263 tmp = arch_to_object (tr->item);
3459 new_draw_info_format (NDI_UNIQUE | NDI_BLUE, 0, who, "You gained %s", query_short_name (tmp)); 3264 new_draw_info_format (NDI_UNIQUE | NDI_BLUE, 0, who, "You gained %s", query_short_name (tmp));
3460 tmp = insert_ob_in_ob (tmp, who); 3265 who->insert (tmp);
3461 if (who->type == PLAYER)
3462 esrv_send_item (who, tmp);
3463 } 3266 }
3464} 3267}
3465 3268
3466/** 3269/**
3467 * Unready an object for a player. This function does nothing if the object was 3270 * Unready an object for a player. This function does nothing if the object was
3478 3281
3479 if (pl->ranged_ob == ob) 3282 if (pl->ranged_ob == ob)
3480 pl->ranged_ob = 0; 3283 pl->ranged_ob = 0;
3481} 3284}
3482 3285
3286//-GPL
3287
3483sint8 3288sint8
3484player::visibility_at (maptile *map, int x, int y) const 3289player::darkness_at (maptile *map, int x, int y) const
3485{ 3290{
3486 if (!ns) 3291 if (!ns)
3487 return 0; 3292 return LOS_BLOCKED;
3488 3293
3489 int dx, dy; 3294 int dx, dy;
3490 if (!adjacent_map (map, ns->current_map, &dx, &dy)) 3295 if (!adjacent_map (map, ns->current_map, &dx, &dy))
3491 return 0; 3296 return LOS_BLOCKED;
3492 3297
3493 x += dx - ns->current_x + ns->mapx / 2; 3298 x += dx - ns->current_x;
3494 y += dy - ns->current_y + ns->mapy / 2; 3299 y += dy - ns->current_y;
3495 3300
3496 if (!IN_RANGE_EXC (x, 0, ns->mapx) || !IN_RANGE_EXC (y, 0, ns->mapy))
3497 return 0;
3498
3499 return 100 - blocked_los [x][y]; 3301 return blocked_los (x, y);
3500} 3302}
3501 3303
3502void 3304void
3503player::infobox (const char *title, const char *msg, int color) 3305player::infobox (const char *title, const char *msg, int color)
3504{ 3306{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines