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.222 by root, Thu Jan 1 11:41:17 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 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
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
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';
207 ob->close_container (); //TODO: client-specific 210 ob->close_container (); //TODO: client-specific
208 211
209 ns->update_look = 0; 212 ns->update_look = 0;
210 ns->look_position = 0; 213 ns->look_position = 0;
211 214
212 clear_los (this); 215 clear_los ();
213 216
214 ns->reset_stats (); 217 ns->reset_stats ();
215 218
216 /* make sure he's a player -- needed because of class change. */ 219 /* make sure he's a player -- needed because of class change. */
217 ob->type = PLAYER; // we are paranoid 220 ob->type = PLAYER; // we are paranoid
218 ob->race = ob->arch->race; 221 ob->race = ob->arch->race;
219 222
220 ob->update_weight (); 223 ob->update_weight ();
221 link_player_skills (ob); 224 link_skills ();
222 225
223 CLEAR_FLAG (ob, FLAG_NO_FIX_PLAYER); 226 CLEAR_FLAG (ob, FLAG_NO_FIX_PLAYER);
224 227
225 assign (title, ob->arch->object::name); 228 assign (title, ob->arch->object::name);
226 229
239 set_dragon_name (ob, abil, skin); 242 set_dragon_name (ob, abil, skin);
240 } 243 }
241 244
242 new_draw_info (NDI_UNIQUE, 0, ob, "Welcome Back!"); 245 new_draw_info (NDI_UNIQUE, 0, ob, "Welcome Back!");
243 246
244 esrv_new_player (this, ob->weight + ob->carrying); 247 esrv_new_player (this);
245 248
246 ob->update_stats (); 249 ob->update_stats ();
247 250
248 ns->floorbox_update (); 251 ns->floorbox_update ();
249 esrv_send_inventory (ob, ob); 252 esrv_send_inventory (ob, ob);
291player::set_object (object *op) 294player::set_object (object *op)
292{ 295{
293 ob = observe = op; 296 ob = observe = op;
294 ob->contr = this; /* this aren't yet in archetype */ 297 ob->contr = this; /* this aren't yet in archetype */
295 298
296 ob->speed = 1.0f; 299 ob->speed = 1.0f;
297 ob->speed_left = 0.5f; 300 ob->speed_left = 0.5f;
298 301
299 ob->direction = 5; /* So player faces south */ 302 ob->direction = 5; /* So player faces south */
300 303
301 ob->flag [FLAG_READY_WEAPON] = false; 304 ob->flag [FLAG_READY_WEAPON] = false;
302 ob->flag [FLAG_READY_SKILL] = false; 305 ob->flag [FLAG_READY_SKILL] = false;
303 ob->flag [FLAG_READY_BOW] = false; 306 ob->flag [FLAG_READY_BOW] = false;
304 307
321 combat_ob = op; 324 combat_ob = op;
322 break; 325 break;
323 } 326 }
324 327
325 ob->change_weapon (combat_ob ? combat_ob : ranged_ob); 328 ob->change_weapon (combat_ob ? combat_ob : ranged_ob);
326 ob->deactivate (); // change_Weapon activates, fix this better 329 ob->deactivate (); // change_weapon activates, fix this better
327} 330}
328 331
329void 332void
330player::set_observe (object *op) 333player::set_observe (object *op)
331{ 334{
345 savebed_map = first_map_path; /* Init. respawn position */ 348 savebed_map = first_map_path; /* Init. respawn position */
346 349
347 gen_sp_armour = 10; 350 gen_sp_armour = 10;
348 bowtype = bow_normal; 351 bowtype = bow_normal;
349 petmode = pet_normal; 352 petmode = pet_normal;
350 listening = 10;
351 usekeys = containers; 353 usekeys = containers;
352 peaceful = 1; /* default peaceful */ 354 peaceful = 1; /* default peaceful */
353 do_los = 1; 355 do_los = 1;
354 356
355 weapon_sp = 1.0f; 357 weapon_sp = 1.0f;
726 else /* lock all 'normal items by default */ 728 else /* lock all 'normal items by default */
727 SET_FLAG (op, FLAG_INV_LOCKED); 729 SET_FLAG (op, FLAG_INV_LOCKED);
728 } /* for loop of objects in player inv */ 730 } /* for loop of objects in player inv */
729 731
730 /* Need to set up the skill pointers */ 732 /* Need to set up the skill pointers */
731 link_player_skills (pl); 733 pl->contr->link_skills ();
732} 734}
733 735
734void 736void
735get_party_password (object *op, partylist *party) 737get_party_password (object *op, partylist *party)
736{ 738{
851 */ 853 */
852void 854void
853player::chargen_race_done () 855player::chargen_race_done ()
854{ 856{
855 /* this must before then initial items are given */ 857 /* this must before then initial items are given */
856 esrv_new_player (ob->contr, ob->weight + ob->carrying); 858 esrv_new_player (ob->contr);
857 859
858 treasurelist *tl = treasurelist::find ("starting_wealth"); 860 treasurelist *tl = treasurelist::find ("starting_wealth");
859 if (tl) 861 if (tl)
860 create_treasure (tl, ob, 0, 0, 0); 862 create_treasure (tl, ob, 0, 0, 0);
861 863
865 ob->contr->ns->state = ST_PLAYING; 867 ob->contr->ns->state = ST_PLAYING;
866 868
867 if (ob->msg) 869 if (ob->msg)
868 ob->msg = 0; 870 ob->msg = 0;
869 871
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); 872 start_info (ob);
880 CLEAR_FLAG (ob, FLAG_WIZ); 873 CLEAR_FLAG (ob, FLAG_WIZ);
881 give_initial_items (ob, ob->randomitems); 874 give_initial_items (ob, ob->randomitems);
882 link_player_skills (ob);
883 esrv_send_inventory (ob, ob); 875 esrv_send_inventory (ob, ob);
884 ob->update_stats (); 876 ob->update_stats ();
885 877
886 /* This moves the player to a different start map, if there 878 /* This moves the player to a different start map, if there
887 * is one for this race 879 * is one for this race
888 */ 880 */
889 if (*first_map_ext_path) 881 if (*first_map_ext_path)
890 { 882 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 883 else
905 LOG (llevDebug, "first_map_ext_path not set\n"); 884 LOG (llevDebug, "first_map_ext_path not set\n");
906} 885}
907 886
908void 887void
952 LOG (llevDebug, "Fleeing player is dead.\n"); 931 LOG (llevDebug, "Fleeing player is dead.\n");
953 CLEAR_FLAG (op, FLAG_SCARED); 932 CLEAR_FLAG (op, FLAG_SCARED);
954 return; 933 return;
955 } 934 }
956 935
957 if (op->enemy == NULL) 936 if (!op->enemy)
958 { 937 {
959 LOG (llevDebug, "Fleeing player had no enemy.\n"); 938 LOG (llevDebug, "Fleeing player had no enemy.\n");
960 CLEAR_FLAG (op, FLAG_SCARED); 939 CLEAR_FLAG (op, FLAG_SCARED);
961 return; 940 return;
962 } 941 }
963 942
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)) 943 if (!(random_roll (0, 4, op, PREFER_LOW)) && did_make_save (op, op->level, 0))
976 { 944 {
977 op->enemy = NULL; 945 op->enemy = NULL;
978 CLEAR_FLAG (op, FLAG_SCARED); 946 CLEAR_FLAG (op, FLAG_SCARED);
979 return; 947 return;
982 get_rangevector (op, op->enemy, &rv, 0); 950 get_rangevector (op, op->enemy, &rv, 0);
983 951
984 dir = absdir (4 + rv.direction); 952 dir = absdir (4 + rv.direction);
985 for (diff = 0; diff < 3; diff++) 953 for (diff = 0; diff < 3; diff++)
986 { 954 {
987 int m = 1 - (RANDOM () & 2); 955 int m = 1 - rndm (2) * 2;
988 956
989 if (move_ob (op, absdir (dir + diff * m), op) || (diff == 0 && move_ob (op, absdir (dir - diff * m), op))) 957 if (move_ob (op, absdir (dir + diff * m), op) || (diff == 0 && move_ob (op, absdir (dir - diff * m), op)))
990 return; 958 return;
991 } 959 }
992 960
1003check_pick (object *op) 971check_pick (object *op)
1004{ 972{
1005 object *tmp, *next; 973 object *tmp, *next;
1006 int stop = 0; 974 int stop = 0;
1007 int wvratio; 975 int wvratio;
1008 char putstring[128];
1009 976
1010 /* if you're flying, you cna't pick up anything */ 977 /* if you're flying, you cna't pick up anything */
1011 if (op->move_type & MOVE_FLYING) 978 if (op->move_type & MOVE_FLYING)
1012 return 1; 979 return 1;
1013 980
1037 1004
1038 if (op->contr->search_str[0] != '\0' && settings.search_items == TRUE) 1005 if (op->contr->search_str[0] != '\0' && settings.search_items == TRUE)
1039 { 1006 {
1040 if (item_matched_string (op, tmp, op->contr->search_str)) 1007 if (item_matched_string (op, tmp, op->contr->search_str))
1041 CHK_PICK_PICKUP; 1008 CHK_PICK_PICKUP;
1009
1042 continue; 1010 continue;
1043 } 1011 }
1044 1012
1045 /* high not bit set? We're using the old autopickup model */ 1013 /* pickup handling */
1014 if (op->contr->mode & PU_DEBUG)
1015 {
1016 /* some debugging code to figure out item information */
1017 const char *str = tmp->name
1018 ? format ("item name: %s item type: %d weight/value: %d",
1019 &tmp->name, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))))
1020 : format ("item name: %s item type: %d weight/value: %d",
1021 &tmp->arch->archname, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))));
1022
1023 new_draw_info (NDI_UNIQUE, 0, op, str);
1024 }
1025
1026 if (op->contr->mode & PU_INHIBIT)
1027 return 1;
1028
1029 if (!(op->contr->mode & PU_ENABLE)) // TODO: fix client
1030 return 1;
1031
1032 /* philosophy:
1033 * It's easy to grab an item type from a pile, as long as it's
1034 * generic. This takes no game-time. For more detailed pickups
1035 * and selections, select-items should be used. This is a
1036 * grab-as-you-run type mode that's really useful for arrows for
1037 * example.
1038 * The drawback: right now it has no frontend, so you need to
1039 * stick the bits you want into a calculator in hex mode and then
1040 * convert to decimal and then 'pickup <#>
1041 */
1042
1043 /* the first two modes are exclusive: if NOTHING we return, if
1044 * STOP then we stop. All the rest are applied sequentially,
1045 * meaning if any test passes, the item gets picked up. */
1046
1047 /* if mode is set to pick nothing up, return */
1048 if (op->contr->mode == PU_NOTHING)
1049 return 1;
1050
1051 /* if mode is set to stop when encountering objects, return */
1052 /* take STOP before INHIBIT since it doesn't actually pick
1053 * anything up */
1054 if (op->contr->mode & PU_STOP)
1055 return 0;
1056
1057 /* useful for going into stores and not losing your settings... */
1058 /* and for battles wher you don't want to get loaded down while
1059 * fighting */
1060 if (op->contr->mode & PU_INHIBIT)
1061 return 1;
1062
1063 /* prevent us from turning into auto-thieves :) */
1064 if (QUERY_FLAG (tmp, FLAG_UNPAID))
1065 continue;
1066
1067 /* ignore known cursed objects */
1068 if (QUERY_FLAG (tmp, FLAG_KNOWN_CURSED) && op->contr->mode & PU_NOT_CURSED)
1069 continue;
1070
1071 /* all food and drink if desired */
1072 /* question: don't pick up known-poisonous stuff? */
1046 if (!(op->contr->mode & PU_NEWMODE)) 1073 if (op->contr->mode & PU_FOOD)
1074 if (tmp->type == FOOD)
1047 { 1075 {
1048 switch (op->contr->mode) 1076 CHK_PICK_PICKUP;
1077 continue;
1078 }
1079
1080 if (op->contr->mode & PU_DRINK)
1081 if (tmp->type == DRINK || (tmp->type == POISON && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)))
1082 {
1083 CHK_PICK_PICKUP;
1084 continue;
1085 }
1086
1087 if (op->contr->mode & PU_POTION)
1088 if (tmp->type == POTION)
1089 {
1090 CHK_PICK_PICKUP;
1091 continue;
1092 }
1093
1094 /* spellbooks, skillscrolls and normal books/scrolls */
1095 if (op->contr->mode & PU_SPELLBOOK)
1096 if (tmp->type == SPELLBOOK)
1097 {
1098 CHK_PICK_PICKUP;
1099 continue;
1100 }
1101
1102 if (op->contr->mode & PU_SKILLSCROLL)
1103 if (tmp->type == SKILLSCROLL)
1104 {
1105 CHK_PICK_PICKUP;
1106 continue;
1107 }
1108
1109 if (op->contr->mode & PU_READABLES)
1110 if (tmp->type == BOOK || tmp->type == SCROLL || tmp->type == INSCRIBABLE)
1111 {
1112 CHK_PICK_PICKUP;
1113 continue;
1114 }
1115
1116 /* wands/staves/rods/horns */
1117 if (op->contr->mode & PU_MAGIC_DEVICE)
1118 if (tmp->type == WAND || tmp->type == ROD || tmp->type == HORN)
1119 {
1120 CHK_PICK_PICKUP;
1121 continue;
1122 }
1123
1124 /* pick up all magical items */
1125 if (op->contr->mode & PU_MAGICAL)
1126 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))
1127 {
1128 CHK_PICK_PICKUP;
1129 continue;
1130 }
1131
1132 if (op->contr->mode & PU_VALUABLES)
1133 {
1134 if (tmp->type == MONEY || tmp->type == GEM)
1049 { 1135 {
1050 case 0:
1051 return 1; /* don't pick up */
1052 case 1:
1053 CHK_PICK_PICKUP; 1136 CHK_PICK_PICKUP;
1054 return 1; 1137 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 } 1138 }
1084 } 1139 }
1085 else 1140
1086 { /* old model */ 1141 /* rings & amulets - talismans seems to be typed AMULET */
1087 /* NEW pickup handling */ 1142 if (op->contr->mode & PU_JEWELS)
1143 if (tmp->type == RING || tmp->type == AMULET)
1144 {
1145 CHK_PICK_PICKUP;
1146 continue;
1147 }
1148
1149 /* we don't forget dragon food */
1150 if (op->contr->mode & PU_FLESH)
1151 if (tmp->type == FLESH)
1152 {
1153 CHK_PICK_PICKUP;
1154 continue;
1155 }
1156
1157 /* bows and arrows. Bows are good for selling! */
1088 if (op->contr->mode & PU_DEBUG) 1158 if (op->contr->mode & PU_BOW)
1159 if (tmp->type == BOW)
1160 {
1161 CHK_PICK_PICKUP;
1162 continue;
1163 }
1164
1165 if (op->contr->mode & PU_ARROW)
1166 if (tmp->type == ARROW)
1167 {
1168 CHK_PICK_PICKUP;
1169 continue;
1170 }
1171
1172 /* all kinds of armor etc. */
1173 if (op->contr->mode & PU_ARMOUR)
1174 if (tmp->type == ARMOUR)
1175 {
1176 CHK_PICK_PICKUP;
1177 continue;
1178 }
1179
1180 if (op->contr->mode & PU_HELMET)
1181 if (tmp->type == HELMET)
1182 {
1183 CHK_PICK_PICKUP;
1184 continue;
1185 }
1186
1187 if (op->contr->mode & PU_SHIELD)
1188 if (tmp->type == SHIELD)
1189 {
1190 CHK_PICK_PICKUP;
1191 continue;
1192 }
1193
1194 if (op->contr->mode & PU_BOOTS)
1195 if (tmp->type == BOOTS)
1196 {
1197 CHK_PICK_PICKUP;
1198 continue;
1199 }
1200
1201 if (op->contr->mode & PU_GLOVES)
1202 if (tmp->type == GLOVES)
1203 {
1204 CHK_PICK_PICKUP;
1205 continue;
1206 }
1207
1208 if (op->contr->mode & PU_CLOAK)
1209 if (tmp->type == CLOAK)
1210 {
1211 CHK_PICK_PICKUP;
1212 continue;
1213 }
1214
1215 /* hoping to catch throwing daggers here */
1216 if (op->contr->mode & PU_MISSILEWEAPON)
1217 if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_IS_THROWN))
1218 {
1219 CHK_PICK_PICKUP;
1220 continue;
1221 }
1222
1223 /* careful: chairs and tables are weapons! */
1224 if (op->contr->mode & PU_ALLWEAPON)
1225 {
1226 if (tmp->type == WEAPON && !tmp->name)
1089 { 1227 {
1090 /* some debugging code to figure out item information */ 1228 if (strstr (tmp->name, "table") == NULL && strstr (tmp->arch->archname, "table") == NULL &&
1091 if (tmp->name != NULL) 1229 strstr (tmp->name, "chair") && strstr (tmp->arch->archname, "chair") == 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;
1137
1138 /* ignore known cursed objects */
1139 if (QUERY_FLAG (tmp, FLAG_KNOWN_CURSED) && op->contr->mode & PU_NOT_CURSED)
1140 continue;
1141
1142 /* all food and drink if desired */
1143 /* question: don't pick up known-poisonous stuff? */
1144 if (op->contr->mode & PU_FOOD)
1145 if (tmp->type == FOOD)
1146 {
1147 CHK_PICK_PICKUP;
1148 continue;
1149 }
1150
1151 if (op->contr->mode & PU_DRINK)
1152 if (tmp->type == DRINK || (tmp->type == POISON && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)))
1153 {
1154 CHK_PICK_PICKUP;
1155 continue;
1156 }
1157
1158 if (op->contr->mode & PU_POTION)
1159 if (tmp->type == POTION)
1160 {
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)
1197 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))
1198 {
1199 CHK_PICK_PICKUP;
1200 continue;
1201 }
1202
1203 if (op->contr->mode & PU_VALUABLES)
1204 {
1205 if (tmp->type == MONEY || tmp->type == GEM)
1206 { 1230 {
1207 CHK_PICK_PICKUP; 1231 CHK_PICK_PICKUP;
1208 continue; 1232 continue;
1209 } 1233 }
1210 } 1234 }
1211 1235
1212 /* rings & amulets - talismans seems to be typed AMULET */ 1236 if (tmp->type == WEAPON && !tmp->name)
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 { 1237 {
1297 if (tmp->type == WEAPON && tmp->name != NULL) 1238 if (strstr (tmp->arch->archname, "table") == NULL && strstr (tmp->arch->archname, "chair") == NULL)
1298 { 1239 {
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; 1240 CHK_PICK_PICKUP;
1303 continue; 1241 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 } 1242 }
1315 } 1243 }
1244 }
1316 1245
1317 /* misc stuff that's useful */ 1246 /* misc stuff that's useful */
1318 if (op->contr->mode & PU_KEY) 1247 if (op->contr->mode & PU_KEY)
1319 if (tmp->type == KEY || tmp->type == SPECIAL_KEY) 1248 if (tmp->type == KEY || tmp->type == SPECIAL_KEY)
1320 { 1249 {
1321 CHK_PICK_PICKUP; 1250 CHK_PICK_PICKUP;
1322 continue; 1251 continue;
1323 } 1252 }
1324 1253
1325 /* any of the last 4 bits set means we use the ratio for value 1254 /* any of the last 4 bits set means we use the ratio for value
1326 * pickups */ 1255 * pickups */
1327 if (op->contr->mode & PU_RATIO) 1256 if (op->contr->mode & PU_RATIO)
1257 {
1258 /* use value density to decide what else to grab */
1259 /* >=7 was >= op->contr->mode */
1260 /* >=7 is the old standard setting. Now we take the last 4 bits
1261 */
1262 wvratio = op->contr->mode & PU_RATIO;
1263 if (1000 * query_cost (tmp, op, F_TRUE) / tmp->total_weight () >= wvratio * 100)
1328 { 1264 {
1329 /* use value density to decide what else to grab */ 1265#if 0
1330 /* >=7 was >= op->contr->mode */ 1266 fprintf (stderr, "HIGH WEIGHT/VALUE [");
1331 /* >=7 is the old standard setting. Now we take the last 4 bits 1267 if (tmp->name != NULL)
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 { 1268 {
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); 1269 fprintf (stderr, "%s", tmp->name);
1342 } 1270 }
1343 else 1271 else
1344 fprintf (stderr, "%s", tmp->arch->archname); 1272 fprintf (stderr, "%s", tmp->arch->archname);
1345 fprintf (stderr, ",%d] = ", tmp->type); 1273 fprintf (stderr, ",%d] = ", tmp->type);
1346 fprintf (stderr, "%d\n", (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1)))); 1274 fprintf (stderr, "%d\n", (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))));
1347#endif 1275#endif
1276 CHK_PICK_PICKUP;
1348 continue; 1277 continue;
1349 }
1350 } 1278 }
1351 } /* the new pickup model */ 1279 } /* the new pickup model */
1352 } 1280 }
1353 1281
1354 return !stop; 1282 return !stop;
1382 * against the target. A full test is not performed, simply a basic test 1310 * 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 1311 * 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. 1312 * the hall. Failing that it does it's best to pick the highest plus arrow.
1385 */ 1313 */
1386object * 1314object *
1387find_better_arrow (object *op, object *target, const char *type, int *better) 1315find_better_arrow (object *op, object *target, shstr_cmp type, int *better)
1388{ 1316{
1389 object *tmp = NULL, *arrow, *ntmp; 1317 object *tmp = NULL, *arrow, *ntmp;
1390 int attacknum, attacktype, betterby = 0, i; 1318 int attacknum, attacktype, betterby = 0, i;
1391 1319
1392 if (!type) 1320 if (!type)
1396 { 1324 {
1397 if (arrow->type == CONTAINER && arrow->race == type && QUERY_FLAG (arrow, FLAG_APPLIED)) 1325 if (arrow->type == CONTAINER && arrow->race == type && QUERY_FLAG (arrow, FLAG_APPLIED))
1398 { 1326 {
1399 i = 0; 1327 i = 0;
1400 ntmp = find_better_arrow (arrow, target, type, &i); 1328 ntmp = find_better_arrow (arrow, target, type, &i);
1329
1401 if (i > betterby) 1330 if (i > betterby)
1402 { 1331 {
1403 tmp = ntmp; 1332 tmp = ntmp;
1404 betterby = i; 1333 betterby = i;
1405 } 1334 }
1406 } 1335 }
1407 else if (arrow->type == ARROW && arrow->race == type) 1336 else if (arrow->type == ARROW && arrow->race == type)
1408 { 1337 {
1409 /* allways prefer assasination/slaying */ 1338 /* allways prefer assasination/slaying */
1410 if (target->race != NULL && arrow->slaying != NULL && strstr (arrow->slaying, target->race)) 1339 if (target->race && arrow->slaying && strstr (arrow->slaying, target->race))
1411 { 1340 {
1412 if (arrow->attacktype & AT_DEATH) 1341 if (arrow->attacktype & AT_DEATH)
1413 { 1342 {
1414 *better = 100; 1343 *better = 100;
1415 return arrow; 1344 return arrow;
1430 { 1359 {
1431 tmp = arrow; 1360 tmp = arrow;
1432 betterby = (arrow->magic + arrow->stats.dam) * (100 - target->arch->resist[attacknum]) / 100; 1361 betterby = (arrow->magic + arrow->stats.dam) * (100 - target->arch->resist[attacknum]) / 100;
1433 } 1362 }
1434 } 1363 }
1364
1435 if ((2 + arrow->magic + arrow->stats.dam) > betterby) 1365 if ((2 + arrow->magic + arrow->stats.dam) > betterby)
1436 { 1366 {
1437 tmp = arrow; 1367 tmp = arrow;
1438 betterby = 2 + arrow->magic + arrow->stats.dam; 1368 betterby = 2 + arrow->magic + arrow->stats.dam;
1439 } 1369 }
1370
1440 if (arrow->title && (1 + arrow->magic + arrow->stats.dam) > betterby) 1371 if (arrow->title && (1 + arrow->magic + arrow->stats.dam) > betterby)
1441 { 1372 {
1442 tmp = arrow; 1373 tmp = arrow;
1443 betterby = 1 + arrow->magic + arrow->stats.dam; 1374 betterby = 1 + arrow->magic + arrow->stats.dam;
1444 } 1375 }
1445 } 1376 }
1446 } 1377 }
1447 } 1378 }
1379
1448 if (tmp == NULL && arrow == NULL) 1380 if (tmp == NULL && arrow == NULL)
1449 return find_arrow (op, type); 1381 return find_arrow (op, type);
1450 1382
1451 *better = betterby; 1383 *better = betterby;
1452 return tmp; 1384 return tmp;
1457 * op = the shooter 1389 * op = the shooter
1458 * type = bow->race 1390 * type = bow->race
1459 * dir = fire direction 1391 * dir = fire direction
1460 */ 1392 */
1461object * 1393object *
1462pick_arrow_target (object *op, const char *type, int dir) 1394pick_arrow_target (object *op, shstr_cmp type, int dir)
1463{ 1395{
1464 object *tmp = NULL; 1396 object *tmp = NULL;
1465 maptile *m; 1397 maptile *m;
1466 int i, mflags, found, number; 1398 int i, mflags, found, number;
1467 sint16 x, y; 1399 sint16 x, y;
1482 for (i = 0, found = 0; i < 20; i++) 1414 for (i = 0, found = 0; i < 20; i++)
1483 { 1415 {
1484 x += freearr_x[dir]; 1416 x += freearr_x[dir];
1485 y += freearr_y[dir]; 1417 y += freearr_y[dir];
1486 mflags = get_map_flags (m, &m, x, y, &x, &y); 1418 mflags = get_map_flags (m, &m, x, y, &x, &y);
1419
1487 if (mflags & P_OUT_OF_MAP || mflags & P_BLOCKSVIEW) 1420 if (mflags & P_OUT_OF_MAP || mflags & P_BLOCKSVIEW)
1488 { 1421 {
1489 tmp = NULL; 1422 tmp = 0;
1490 break; 1423 break;
1491 } 1424 }
1492 else if (GET_MAP_MOVE_BLOCK (m, x, y) == MOVE_FLY_LOW) 1425 else if (GET_MAP_MOVE_BLOCK (m, x, y) == MOVE_FLY_LOW)
1493 { 1426 {
1494 /* This block presumes arrows and the like are MOVE_FLY_SLOW - 1427 /* This block presumes arrows and the like are MOVE_FLY_SLOW -
1495 * perhaps a bad assumption. 1428 * perhaps a bad assumption.
1496 */ 1429 */
1497 tmp = NULL; 1430 tmp = 0;
1498 break; 1431 break;
1499 } 1432 }
1433
1500 if (mflags & P_IS_ALIVE) 1434 if (mflags & P_IS_ALIVE)
1501 {
1502 for (tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above) 1435 for (tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above)
1503 if (QUERY_FLAG (tmp, FLAG_ALIVE)) 1436 if (QUERY_FLAG (tmp, FLAG_ALIVE))
1504 {
1505 found++;
1506 break;
1507 }
1508 if (found)
1509 break; 1437 break;
1510 }
1511 } 1438 }
1512 if (tmp == NULL) 1439
1440 if (!tmp)
1513 return find_arrow (op, type); 1441 return find_arrow (op, type);
1514 1442
1515 if (tmp->head) 1443 if (tmp->head)
1516 tmp = tmp->head; 1444 tmp = tmp->head;
1517 1445
1562 if (bow->below) 1490 if (bow->below)
1563 { 1491 {
1564 bow->remove (); 1492 bow->remove ();
1565 op->insert (bow); 1493 op->insert (bow);
1566 } 1494 }
1567
1568 } 1495 }
1569 1496
1570 if (!bow->race || !bow->skill) 1497 if (!bow->race || !bow->skill)
1571 { 1498 {
1572 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s is broken.", &bow->name); 1499 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s is broken.", &bow->name);
1598 } 1525 }
1599 1526
1600 /* this should not happen, but sometimes does */ 1527 /* this should not happen, but sometimes does */
1601 if (arrow->nrof == 0) 1528 if (arrow->nrof == 0)
1602 { 1529 {
1530 LOG (llevError | logBacktrace, "arrow (%s) has nrof 0\n", arrow->debug_desc ());
1603 arrow->destroy (); 1531 arrow->destroy ();
1604 return 0; 1532 return 0;
1605 } 1533 }
1606 1534
1607 left = arrow; /* these are arrows left to the player */ 1535 left = arrow; /* these are arrows left to the player */
1694 * hence the function name. 1622 * hence the function name.
1695 */ 1623 */
1696int 1624int
1697player_fire_bow (object *op, int dir) 1625player_fire_bow (object *op, int dir)
1698{ 1626{
1699 int ret = 0, wcmod = 0; 1627 int ret;
1700 1628
1701 if (op->contr->bowtype == bow_bestarrow) 1629 if (op->contr->bowtype == bow_bestarrow)
1702 { 1630 {
1703 ret = fire_bow (op, op, pick_arrow_target (op, op->contr->ranged_ob->race, dir), dir, 0, op->x, op->y); 1631 ret = fire_bow (op, op, pick_arrow_target (op, op->contr->ranged_ob->race, dir), dir, 0, op->x, op->y);
1704 } 1632 }
1705 else if (op->contr->bowtype >= bow_n && op->contr->bowtype <= bow_nw) 1633 else if (op->contr->bowtype >= bow_n && op->contr->bowtype <= bow_nw)
1706 { 1634 {
1707 if (!similar_direction (dir, op->contr->bowtype - bow_n + 1)) 1635 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); 1636 ret = fire_bow (op, op, NULL, op->contr->bowtype - bow_n + 1, wcmod, op->x, op->y);
1711 } 1637 }
1712 else if (op->contr->bowtype == bow_threewide) 1638 else if (op->contr->bowtype == bow_threewide)
1713 { 1639 {
1714 ret = fire_bow (op, op, NULL, dir, 0, op->x, op->y); 1640 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)]); 1641 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)]); 1642 ret |= fire_bow (op, op, NULL, dir, -5, op->x + freearr_x[absdir (dir - 2)], op->y + freearr_y[absdir (dir - 2)]);
1717 } 1643 }
1718 else if (op->contr->bowtype == bow_spreadshot) 1644 else if (op->contr->bowtype == bow_spreadshot)
1719 { 1645 {
1720 ret |= fire_bow (op, op, NULL, dir, 0, op->x, op->y); 1646 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); 1647 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); 1648 ret |= fire_bow (op, op, NULL, absdir (dir + 1), -5, op->x, op->y);
1723 } 1649 }
1724 else 1650 else
1725 { 1651 {
1763 return; 1689 return;
1764 } 1690 }
1765 } 1691 }
1766 else if (item->type == ROD || item->type == HORN) 1692 else if (item->type == ROD || item->type == HORN)
1767 { 1693 {
1768 if (item->stats.hp < MAX (item->inv->stats.sp, item->inv->stats.grace)) 1694 sint16 spell_sp = MAX (item->inv->stats.sp, item->inv->stats.grace);
1695
1696 // using the maximum of the rods charge allows at least one spell cast
1697 // for a rod or horn, this fixes some broken rods.
1698 if (item->stats.hp < MIN (spell_sp, item->stats.maxhp))
1769 { 1699 {
1770 op->contr->play_sound (sound_find ("wand_poof")); 1700 op->contr->play_sound (sound_find ("wand_poof"));
1771 1701
1772 if (item->type == ROD) 1702 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)); 1703 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s whines for a while, but nothing happens.", query_base_name (item, 0));
1778 } 1708 }
1779 } 1709 }
1780 1710
1781 if (cast_spell (op, item, dir, item->inv, NULL)) 1711 if (cast_spell (op, item, dir, item->inv, NULL))
1782 { 1712 {
1783 SET_FLAG (op, FLAG_BEEN_APPLIED); /* You now know something about it */ 1713 item->flag [FLAG_BEEN_APPLIED] = true; /* You now know something about it */
1714
1784 if (item->type == WAND) 1715 if (item->type == WAND)
1785 { 1716 {
1786 if (!(--item->stats.food)) 1717 if (!(--item->stats.food))
1787 { 1718 {
1788 object *tmp; 1719 object *tmp;
1792 CLEAR_FLAG (item, FLAG_ANIMATE); 1723 CLEAR_FLAG (item, FLAG_ANIMATE);
1793 item->face = item->arch->face; 1724 item->face = item->arch->face;
1794 item->set_speed (0); 1725 item->set_speed (0);
1795 } 1726 }
1796 1727
1797 if ((tmp = item->in_player ())) 1728 if (object *pl = item->visible_to ())
1798 esrv_update_item (UPD_ANIM, tmp, item); 1729 esrv_update_item (UPD_ANIM, pl, item);
1799 } 1730 }
1800 } 1731 }
1801 else if (item->type == ROD || item->type == HORN) 1732 else if (item->type == ROD || item->type == HORN)
1802 drain_rod_charge (item); 1733 drain_rod_charge (item);
1803 } 1734 }
1808bool 1739bool
1809fire (object *op, int dir) 1740fire (object *op, int dir)
1810{ 1741{
1811 int spellcost = 0; 1742 int spellcost = 0;
1812 1743
1813 /* check for loss of invisiblity/hide */
1814 if (action_makes_visible (op))
1815 make_visible (op);
1816
1817 player *pl = op->contr; 1744 player *pl = op->contr;
1818 1745
1819 if (pl->golem) 1746 if (pl->golem)
1820 { 1747 {
1821 control_golem (op->contr->golem, dir); 1748 control_golem (op->contr->golem, dir);
1823 } 1750 }
1824 1751
1825 object *ob = pl->ranged_ob; 1752 object *ob = pl->ranged_ob;
1826 1753
1827 if (!ob) 1754 if (!ob)
1828 return false;
1829
1830 if (!op->change_weapon (ob))
1831 return false; 1755 return false;
1832 1756
1833 if (op->speed_left > 0.f) 1757 if (op->speed_left > 0.f)
1834 --op->speed_left; 1758 --op->speed_left;
1835 else 1759 else
1836 return false; 1760 return false;
1761
1762 if (!op->change_weapon (ob))
1763 return false;
1764
1765 /* check for loss of invisiblity/hide */
1766 if (action_makes_visible (op))
1767 make_visible (op);
1837 1768
1838 switch (ob->type) 1769 switch (ob->type)
1839 { 1770 {
1840 case BOW: 1771 case BOW:
1841 player_fire_bow (op, dir); 1772 player_fire_bow (op, dir);
1980 remove_door2 (door); /* remove door without violence ;-) */ 1911 remove_door2 (door); /* remove door without violence ;-) */
1981 } 1912 }
1982 1913
1983 /* Do this after we print the message */ 1914 /* Do this after we print the message */
1984 key->decrease (); /* Use up one of the keys */ 1915 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 1916
1989 return 1; /* Nothing more to do below */ 1917 return 1; /* Nothing more to do below */
1990 } 1918 }
1991 else if (door->type == LOCKED_DOOR) 1919 else if (door->type == LOCKED_DOOR)
1992 { 1920 {
2089 --op->speed_left; 2017 --op->speed_left;
2090 2018
2091 op->play_sound (sound_find ("push_player")); 2019 op->play_sound (sound_find ("push_player"));
2092 push_ob (mon, dir, op); 2020 push_ob (mon, dir, op);
2093 2021
2094 if (op->contr->tmp_invis || op->hide) 2022 if (action_makes_visible (op))
2095 make_visible (op); 2023 make_visible (op);
2096 2024
2097 return true; 2025 return true;
2098 } 2026 }
2099 else 2027 else
2121 push_ob (mon, dir, op); 2049 push_ob (mon, dir, op);
2122 } 2050 }
2123 else 2051 else
2124 op->statusmsg ("You withhold your attack"); 2052 op->statusmsg ("You withhold your attack");
2125 2053
2126 if (op->contr->tmp_invis || op->hide) 2054 if (op->contr->tmp_invis || op->flag [FLAG_HIDDEN])
2127 make_visible (op); 2055 make_visible (op);
2128 2056
2129 return true; 2057 return true;
2130 } 2058 }
2131 } 2059 }
2189 if (QUERY_FLAG (op, FLAG_CONFUSED) && dir) 2117 if (QUERY_FLAG (op, FLAG_CONFUSED) && dir)
2190 dir = absdir (dir + rndm (3) + rndm (3) - 2); 2118 dir = absdir (dir + rndm (3) + rndm (3) - 2);
2191 2119
2192 op->facing = dir; 2120 op->facing = dir;
2193 2121
2194 if (op->hide) 2122 if (op->flag [FLAG_HIDDEN])
2195 do_hidden_move (op); 2123 do_hidden_move (op);
2196 2124
2197 bool retval; 2125 bool retval;
2198 2126
2199 if (INVOKE_PLAYER (MOVE, op->contr, ARG_INT (dir))) 2127 if (INVOKE_PLAYER (MOVE, op->contr, ARG_INT (dir)))
2271 if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE)) 2199 if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE))
2272 { 2200 {
2273 op->play_sound (sound_find ("ob_evaporate")); 2201 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)); 2202 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s vibrates violently, then evaporates.", query_name (tmp));
2275 2203
2276 if (op->contr)
2277 esrv_del_item (op->contr, tmp->count);
2278
2279 tmp->destroy (); 2204 tmp->destroy ();
2280 CLEAR_FLAG (op, FLAG_LIFESAVE); 2205 CLEAR_FLAG (op, FLAG_LIFESAVE);
2281 2206
2282 if (op->stats.hp < 0) 2207 if (op->stats.hp < 0)
2283 op->stats.hp = op->stats.maxhp; 2208 op->stats.hp = op->stats.maxhp;
2295 return 0; 2220 return 0;
2296} 2221}
2297 2222
2298/* This goes throws the inventory and removes unpaid objects, and puts them 2223/* 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 2224 * 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 2225 * function will descend into containers. op is the object to start the search
2301 * from. 2226 * from.
2302 */ 2227 */
2303static void 2228static void
2304drop_unpaid_items (object *op, object *env) 2229drop_unpaid_items (object *op, object *env)
2305{ 2230{
2306 while (op) 2231 while (op)
2307 { 2232 {
2308 object *next = op->below; /* Make sure we have a good value, in case we remove object 'op' */ 2233 object *next = op->below; /* Make sure we have a good value, in case we remove object 'op' */
2309 2234
2310 if (QUERY_FLAG (op, FLAG_UNPAID)) 2235 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); 2236 op->insert_at (env);
2316 }
2317 else if (op->inv) 2237 else if (op->inv)
2318 drop_unpaid_items (op->inv, env); 2238 drop_unpaid_items (op->inv, env);
2319 2239
2320 op = next; 2240 op = next;
2321 } 2241 }
2333 * Moved from apply.c to player.c - player.c is what 2253 * Moved from apply.c to player.c - player.c is what
2334 * actually uses this function. player.c may not be quite the 2254 * actually uses this function. player.c may not be quite the
2335 * best, a misc file for object actions is probably better, 2255 * best, a misc file for object actions is probably better,
2336 * but there isn't one in the server directory. 2256 * but there isn't one in the server directory.
2337 */ 2257 */
2338char * 2258const char *
2339gravestone_text (object *op) 2259gravestone_text (object *op)
2340{ 2260{
2341 static char buf2[MAX_BUF]; 2261 static dynbuf_text buf;
2342 char buf[MAX_BUF];
2343 time_t now = time (NULL);
2344 2262
2345 strcpy (buf2, " R.I.P.\n\n"); 2263 buf << "---- R.I.P. ----\n\n"
2264 << op->name;
2265
2346 if (op->type == PLAYER) 2266 if (op->type == PLAYER)
2347 sprintf (buf, "%s the %s\n", &op->name, op->contr->title); 2267 buf << " the " << op->contr->title;
2348 else
2349 sprintf (buf, "%s\n", &op->name);
2350 2268
2351 strncat (buf2, " ", 20 - strlen (buf) / 2); 2269 buf << "\n\n";
2352 strcat (buf2, buf); 2270
2271 buf << "who was level ";
2272 buf << (sint32)op->level << "\n\n" // OO breakdown
2273 << " when " << (op->contr ? "killed" : "died") << "\n\n";
2274
2353 if (op->type == PLAYER) 2275 if (op->type == PLAYER)
2354 sprintf (buf, "who was in level %d when killed\n", op->level); 2276 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 2277
2358 strncat (buf2, " ", 20 - strlen (buf) / 2);
2359 strcat (buf2, buf);
2360 if (op->type == PLAYER)
2361 { 2278 {
2362 sprintf (buf, "by %s.\n\n", op->contr->killer); 2279 static char buf2[128];
2363 strncat (buf2, " ", 21 - strlen (buf) / 2); 2280 time_t now = time (NULL);
2364 strcat (buf2, buf);
2365 }
2366
2367 strftime (buf, MAX_BUF, "%b %d %Y\n", localtime (&now)); 2281 strftime (buf2, 128, "%b %d %Y\n\n", localtime (&now));
2368 strncat (buf2, " ", 20 - strlen (buf) / 2); 2282 buf << buf2;
2369 strcat (buf2, buf); 2283 }
2370 2284
2371 return buf2; 2285 return buf;
2372} 2286}
2373 2287
2374void 2288void
2375do_some_living (object *op) 2289do_some_living (object *op)
2376{ 2290{
2531 { 2445 {
2532 over_hp = (gen_hp < 20 ? 30 : gen_hp + 10) / rate_hp; 2446 over_hp = (gen_hp < 20 ? 30 : gen_hp + 10) / rate_hp;
2533 2447
2534 if (over_hp > 0) 2448 if (over_hp > 0)
2535 { 2449 {
2536 op->stats.sp += over_hp + (RANDOM () % rate_hp > ((gen_hp < 20 ? 30 : gen_hp + 10) % rate_hp)) ? -1 : 0; 2450 op->stats.sp += over_hp + (rndm (rate_hp) > ((gen_hp < 20 ? 30 : gen_hp + 10) % rate_hp)) ? -1 : 0;
2537 op->last_heal = 0; 2451 op->last_heal = 0;
2538 } 2452 }
2539 else 2453 else
2540 op->last_heal = rate_hp / (gen_hp < 20 ? 30 : gen_hp + 10); 2454 op->last_heal = rate_hp / (gen_hp < 20 ? 30 : gen_hp + 10);
2541 } 2455 }
2557 op->stats.food--; 2471 op->stats.food--;
2558 } 2472 }
2559 2473
2560 if (op->stats.food < 0 && op->stats.hp >= 0) 2474 if (op->stats.food < 0 && op->stats.hp >= 0)
2561 { 2475 {
2562 object *tmp, *flesh = 0; 2476 object *flesh = 0;
2563 2477
2564 for (tmp = op->inv; tmp; tmp = tmp->below) 2478 for_inv_removable (op, tmp)
2565 { 2479 {
2566 if (!QUERY_FLAG (tmp, FLAG_UNPAID)) 2480 if (QUERY_FLAG (tmp, FLAG_UNPAID))
2481 continue;
2482
2483 if (tmp->type == FOOD || tmp->type == DRINK || tmp->type == POISON)
2567 { 2484 {
2568 if (tmp->type == FOOD || tmp->type == DRINK || tmp->type == POISON) 2485 op->statusmsg ("You blindly grab for a bite of food. "
2569 { 2486 "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); 2487 manual_apply (op, tmp, 0);
2488
2572 if (op->stats.food >= 0 || op->stats.hp < 0) 2489 if (op->stats.food >= 0 || op->stats.hp < 0)
2573 break; 2490 break;
2574 } 2491 }
2575 else if (tmp->type == FLESH) 2492 else if (tmp->type == FLESH)
2576 flesh = tmp; 2493 flesh = tmp;
2577 } /* End if paid for object */ 2494 }
2578 } /* end of for loop */
2579 2495
2580 /* If player is still starving, it means they don't have any food, so 2496 /* If player is still starving, it means they don't have any food, so
2581 * eat flesh instead. 2497 * eat flesh instead.
2582 */ 2498 */
2583 if (op->stats.food < 0 && op->stats.hp >= 0 && flesh) 2499 if (op->stats.food < 0 && op->stats.hp >= 0 && flesh)
2584 { 2500 {
2585 new_draw_info (NDI_UNIQUE, 0, op, "You blindly grab for a bite of food."); 2501 op->statusmsg ("You blindly grab for a bite of food. "
2502 "H<To prevent you from starving, you ate some random item from your backpack.>");
2586 manual_apply (op, flesh, 0); 2503 manual_apply (op, flesh, 0);
2587 } 2504 }
2505
2506 // If player is still starving, alert him!
2507 if (op->stats.food < 0)
2508 op->failmsg ("You are starving! "
2509 "H<Eat some food to increase your food and prevent you from an untimely death.>");
2588 } 2510 }
2589 2511
2590 if (op->stats.food < 0) 2512 if (op->stats.food < 0)
2591 { 2513 {
2592 op->stats.hp += op->stats.food; 2514 op->stats.hp += op->stats.food;
2593 op->stats.food = 0; 2515 op->stats.food = 0;
2516
2517 if (op->stats.hp < 0)
2518 {
2519 op->contr->killer = archetype::get ("killer_starvation");
2520 op->contr->killer->destroy ();
2594 } 2521 }
2522 }
2595 2523
2524 /* killer should be set here already */
2596 if (op->stats.hp < 0 && !QUERY_FLAG (op, FLAG_WIZ)) 2525 if (op->stats.hp < 0 && !QUERY_FLAG (op, FLAG_WIZ))
2597 kill_player (op); 2526 kill_player (op);
2598 } 2527 }
2599} 2528}
2600 2529
2614 object *tmp; 2543 object *tmp;
2615 2544
2616 if (save_life (op)) 2545 if (save_life (op))
2617 return; 2546 return;
2618 2547
2548 /* restore player */
2549 at = archetype::find ("poisoning");
2550 if (object *tmp = present_arch_in_ob (at, op))
2551 {
2552 tmp->destroy ();
2553 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed");
2554 }
2555
2556 at = archetype::find ("confusion");
2557 if (object *tmp = present_arch_in_ob (at, op))
2558 {
2559 tmp->destroy ();
2560 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer");
2561 }
2562
2563 cure_disease (op, 0, 0); /* remove any disease */
2564
2565 max_it (op->stats.hp , op->stats.maxhp);
2566 max_it (op->stats.sp , op->stats.maxsp);
2567 max_it (op->stats.grace, op->stats.maxgrace);
2568
2569 if (op->stats.food <= 0)
2570 op->stats.food = 999;
2571
2572 // remove all spell effects that are active
2573 // to avoid long-term effects such as word-of-recall
2574 for (object *item = op->inv; item; )
2575 {
2576 object *next = item->below;
2577
2578 if (item->type == SPELL_EFFECT && item->active)
2579 item->destroy ();
2580
2581 item = next;
2582 }
2583
2619 /* If player dies on BATTLEGROUND, no stat/exp loss! For Combat-Arenas 2584 /* 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. 2585 * in cities ONLY!!! It is very important that this doesn't get abused.
2621 * Look at op_on_battleground() for more info --AndreasV 2586 * Look at op_on_battleground() for more info --AndreasV
2622 */ 2587 */
2623 if (op_on_battleground (op, &x, &y)) 2588 if (op_on_battleground (op, &x, &y))
2624 { 2589 {
2625 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, "You have been defeated in combat!"); 2590 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, "You have been defeated in combat!");
2626 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, "Local medics have saved your life..."); 2591 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, "Local medics have saved your life...");
2627 2592
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
2648 /* create a bodypart-trophy to make the winner happy */ 2593 /* create a bodypart-trophy to make the winner happy */
2649 if (object *tmp = arch_to_object (archetype::find ("finger"))) 2594 if (object *tmp = arch_to_object (archetype::find ("finger")))
2650 { 2595 {
2651 tmp->name = format ("%s's finger" , &op->name); 2596 tmp->name = format ("%s's finger" , &op->name);
2652 tmp->name_pl = format ("%s's fingers", &op->name); 2597 tmp->name_pl = format ("%s's fingers", &op->name);
2653 tmp->msg = format ( 2598 tmp->msg = format (
2654 "This finger has been cut off of %s the %s, when he was defeated at level %d by %s.\n", 2599 "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 2600 &op->name, op->contr->title,
2601 (int)op->level,
2602 op->contr->killer_name ()
2656 ); 2603 );
2657 tmp->value = 0, tmp->type = 0; 2604 tmp->value = 0, tmp->type = 0;
2658 tmp->materialname = "organics"; 2605 tmp->materialname = "organics";
2659 tmp->insert_at (op, tmp); 2606 tmp->insert_at (op, tmp);
2660 } 2607 }
2666 } 2613 }
2667 2614
2668 INVOKE_PLAYER (DEATH, op->contr); 2615 INVOKE_PLAYER (DEATH, op->contr);
2669 2616
2670 command_kill_pets (op, 0); 2617 command_kill_pets (op, 0);
2671
2672 if (op->stats.food < 0)
2673 strcpy (op->contr->killer, "starvation");
2674 2618
2675 op->contr->play_sound (sound_find ("player_dies")); 2619 op->contr->play_sound (sound_find ("player_dies"));
2676 2620
2677 /* save the map location for corpse, gravestone */ 2621 /* save the map location for corpse, gravestone */
2678 x = op->x; 2622 x = op->x;
2708 2652
2709 lost_a_stat = 0; 2653 lost_a_stat = 0;
2710 2654
2711 for (z = 0; z < num_stats_lose; z++) 2655 for (z = 0; z < num_stats_lose; z++)
2712 { 2656 {
2713 i = RANDOM () % NUM_STATS; 2657 i = rndm (NUM_STATS);
2714 2658
2715 if (settings.stat_loss_on_death) 2659 if (settings.stat_loss_on_death)
2716 { 2660 {
2717 /* Pick a random stat and take a point off it. Tell the player 2661 /* Pick a random stat and take a point off it. Tell the player
2718 * what he lost. 2662 * what he lost.
2769 } 2713 }
2770 } 2714 }
2771 2715
2772 if (lose_this_stat) 2716 if (lose_this_stat)
2773 { 2717 {
2774 this_stat = get_attr_value (&(dep->stats), i); 2718 this_stat = get_attr_value (&dep->stats, i);
2775 /* We could try to do something clever like find another 2719 /* We could try to do something clever like find another
2776 * stat to reduce if this fails. But chances are, if 2720 * stat to reduce if this fails. But chances are, if
2777 * stats have been depleted to -50, all are pretty low 2721 * stats have been depleted to -50, all are pretty low
2778 * and should be roughly the same, so it shouldn't make a 2722 * and should be roughly the same, so it shouldn't make a
2779 * difference. 2723 * difference.
2787 lost_a_stat = 1; 2731 lost_a_stat = 1;
2788 } 2732 }
2789 } 2733 }
2790 } 2734 }
2791 } 2735 }
2736
2792 /* If no stat lost, tell the player. */ 2737 /* If no stat lost, tell the player. */
2793 if (!lost_a_stat) 2738 if (!lost_a_stat)
2794 { 2739 {
2795 /* determine_god() seems to not work sometimes... why is this? 2740 /* determine_god() seems to not work sometimes... why is this?
2796 Should I be using something else? GD */ 2741 Should I be using something else? GD */
2797 const char *god = determine_god (op); 2742 shstr_tmp god = determine_god (op);
2798 2743
2799 if (god && (strcmp (god, "none"))) 2744 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); 2745 new_draw_info_format (NDI_UNIQUE, 0, op, "For a brief moment you feel the holy presence of %s protecting" " you.", &god);
2801 else 2746 else
2802 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you feel a holy presence protecting you."); 2747 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you feel a holy presence protecting you.");
2803 } 2748 }
2804#else 2749#else
2805 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you" " feel a holy presence protecting you from losing yourself completely."); 2750 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you feel a holy presence protecting you from losing yourself completely.");
2806#endif 2751#endif
2807 2752
2808 /* Put a gravestone up where the character 'almost' died. List the 2753 /* Put a gravestone up where the character 'almost' died. List the
2809 * exp loss on the stone. 2754 * exp loss on the stone.
2810 */ 2755 */
2811 tmp = arch_to_object (archetype::find ("gravestone")); 2756 tmp = arch_to_object (archetype::find ("gravestone"));
2812 sprintf (buf, "%s's gravestone", &op->name); 2757 tmp->name = format ("%s's gravestone", &op->name);
2813 tmp->name = buf; 2758 tmp->name_pl = format ("%s's gravestones", &op->name);
2814 sprintf (buf, "%s's gravestones", &op->name); 2759 tmp->msg = format ("T<RIP>\n\nHere rests the hero %s the %s,\rwho was killed\rby %s.\n",
2815 tmp->name_pl = buf; 2760 &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; 2761 tmp->x = op->x, tmp->y = op->y;
2819 insert_ob_in_map (tmp, op->map, NULL, 0); 2762 insert_ob_in_map (tmp, op->map, NULL, 0);
2820 2763
2821 /**************************************/ 2764 /**************************************/
2822 /* */ 2765 /* */
2823 /* Subtract the experience points, */ 2766 /* Subtract the experience points, */
2824 /* if we died cause of food, give us */
2825 /* food, and reset HP's... */
2826 /* */ 2767 /* */
2827 /**************************************/ 2768 /**************************************/
2828 2769
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)); */ 2770 /*add_exp(op, (op->stats.exp * -0.20)); */
2851 apply_death_exp_penalty (op); 2771 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 2772
2858 /* 2773 /*
2859 * Check to see if the player has any unpaid items. If so, remove them 2774 * Check to see if the player has any unpaid items. If so, remove them
2860 * and put them back in the map. 2775 * and put them back in the map.
2861 */ 2776 */
2896 if (will_kill_again & (1 << at)) 2811 if (will_kill_again & (1 << at))
2897 force->resist[at] = 100; 2812 force->resist[at] = 100;
2898 2813
2899 insert_ob_in_ob (force, op); 2814 insert_ob_in_ob (force, op);
2900 op->update_stats (); 2815 op->update_stats ();
2901
2902 } 2816 }
2903 2817
2904 new_draw_info (NDI_UNIQUE, 0, op, "YOU HAVE DIED."); 2818 new_draw_info (NDI_UNIQUE, 0, op, "YOU HAVE DIED.");
2905} 2819}
2906 2820
3007} 2921}
3008 2922
3009void 2923void
3010make_visible (object *op) 2924make_visible (object *op)
3011{ 2925{
3012 op->hide = 0; 2926 op->flag [FLAG_HIDDEN] = 0;
3013 op->invisible = 0; 2927 op->invisible = 0;
3014 2928
3015 if (op->type == PLAYER) 2929 if (op->type == PLAYER)
3016 { 2930 {
3017 op->contr->tmp_invis = 0; 2931 op->contr->tmp_invis = 0;
3042 2956
3043 if (!ob || !ob->map) 2957 if (!ob || !ob->map)
3044 return 0; 2958 return 0;
3045 2959
3046 /* so, on normal lighted maps, its hard to hide */ 2960 /* so, on normal lighted maps, its hard to hide */
3047 level = ob->map->darkness - 2; 2961 level = ob->map->darklevel () - 2;
3048 2962
3049 /* this also picks up whether the object is glowing. 2963 /* this also picks up whether the object is glowing.
3050 * If you carry a light on a non-dark map, its not 2964 * If you carry a light on a non-dark map, its not
3051 * as bad as carrying a light on a pitch dark map */ 2965 * as bad as carrying a light on a pitch dark map */
3052 if (has_carried_lights (ob)) 2966 if (has_carried_lights (ob))
3053 level = -(10 + (2 * ob->map->darkness)); 2967 level = -(10 + (2 * ob->map->darklevel ()));
3054 2968
3055 /* scan through all nearby squares for terrain to hide in */ 2969 /* scan through all nearby squares for terrain to hide in */
3056 for (i = 0, x = ob->x, y = ob->y; 2970 for (i = 0, x = ob->x, y = ob->y;
3057 i <= SIZEOFFREE1; 2971 i <= SIZEOFFREE1;
3058 i++, x = ob->x + freearr_x[i], y = ob->y + freearr_y[i]) 2972 i++, x = ob->x + freearr_x[i], y = ob->y + freearr_y[i])
3079 * spot (surrounded by clear terrain in broad daylight). -b.t. 2993 * spot (surrounded by clear terrain in broad daylight). -b.t.
3080 */ 2994 */
3081void 2995void
3082do_hidden_move (object *op) 2996do_hidden_move (object *op)
3083{ 2997{
3084 int hide = 0, num = random_roll (0, 19, op, PREFER_LOW); 2998 int hide = 0;
3085 object *skop;
3086 2999
3087 if (!op || !op->map) 3000 if (!op || !op->map)
3088 return; 3001 return;
3089 3002
3090 skop = find_obj_by_type_subtype (op, SKILL, SK_HIDING); 3003 object *skop = find_obj_by_type_subtype (op, SKILL, SK_HIDING);
3004 int num = random_roll (0, 19, op, PREFER_LOW);
3091 3005
3092 /* its *extremely* hard to run and sneak/hide at the same time! */ 3006 /* its *extremely* hard to run and sneak/hide at the same time! */
3093 if (op->type == PLAYER && op->contr->run_on) 3007 if (op->type == PLAYER && op->contr->run_on)
3094 if (!skop || num >= skop->level) 3008 if (!skop || num >= skop->level)
3095 { 3009 {
3105 num -= hide; 3019 num -= hide;
3106 3020
3107 if ((op->type == PLAYER && hide < -10) || ((op->invisible -= num) <= 0)) 3021 if ((op->type == PLAYER && hide < -10) || ((op->invisible -= num) <= 0))
3108 { 3022 {
3109 make_visible (op); 3023 make_visible (op);
3024
3110 if (op->type == PLAYER) 3025 if (op->type == PLAYER)
3111 new_draw_info (NDI_UNIQUE, 0, op, "You moved out of hiding! You are visible!"); 3026 new_draw_info (NDI_UNIQUE, 0, op, "You moved out of hiding! You are visible!");
3112 } 3027 }
3113 else if (op->type == PLAYER && skop) 3028 else if (op->type == PLAYER && skop)
3114 change_exp (op, calc_skill_exp (op, NULL, skop), skop->skill, 0); 3029 change_exp (op, calc_skill_exp (op, NULL, skop), skop->skill, 0);
3204 while (op) 3119 while (op)
3205 { 3120 {
3206 dx = rv.distance_x + op->arch->x; 3121 dx = rv.distance_x + op->arch->x;
3207 dy = rv.distance_y + op->arch->y; 3122 dy = rv.distance_y + op->arch->y;
3208 3123
3209 /* only the viewable area the player sees is updated by LOS 3124 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; 3125 return 1;
3217 3126
3218 op = op->more; 3127 op = op->more;
3219 } 3128 }
3220 3129
3221 return 0; 3130 return 0;
3222} 3131}
3223 3132
3224/* routine for both players and monsters. We call this when 3133/* routine for both players and monsters. We call this when
3225 * there is a possibility for our action distrubing our hiding 3134 * there is a possibility for our action distrubing our hiding
3226 * place or invisiblity spell. Artefact invisiblity is not 3135 * place or invisiblity spell. Artefact invisiblity causes
3227 * effected by this. If we arent invisible to begin with, we 3136 * "noise" instead. If we arent invisible to begin with, we
3228 * return 0. 3137 * return 0.
3229 */ 3138 */
3230int 3139int
3231action_makes_visible (object *op) 3140action_makes_visible (object *op)
3232{ 3141{
3233 if (op->invisible && QUERY_FLAG (op, FLAG_ALIVE)) 3142 if (op->invisible && QUERY_FLAG (op, FLAG_ALIVE))
3234 { 3143 {
3235 if (QUERY_FLAG (op, FLAG_MAKE_INVIS)) 3144 if (QUERY_FLAG (op, FLAG_MAKE_INVIS))
3145 {
3146 // artefact invisibility is permanent, but we still make noise
3147 // this is important for game-balance.
3148 if (op->contr)
3149 op->make_noise ();
3150
3236 return 0; 3151 return 0;
3152 }
3237 3153
3238 if (op->contr && op->contr->tmp_invis == 0) 3154 if (op->contr && op->contr->tmp_invis == 0)
3239 return 0; 3155 return 0;
3240 3156
3241 /* If monsters, they should become visible */ 3157 /* If monsters, they should become visible */
3242 if (op->hide || !op->contr || (op->contr && op->contr->tmp_invis)) 3158 if (op->flag [FLAG_HIDDEN] || !op->contr || (op->contr && op->contr->tmp_invis))
3243 { 3159 {
3244 new_draw_info_format (NDI_UNIQUE, 0, op, "You become %s!", op->hide ? "unhidden" : "visible"); 3160 new_draw_info_format (NDI_UNIQUE, 0, op, "You become %s!", op->flag [FLAG_HIDDEN] ? "unhidden" : "visible");
3245 return 1; 3161 return 1;
3246 } 3162 }
3247 } 3163 }
3248 3164
3249 return 0; 3165 return 0;
3455 else 3371 else
3456 { 3372 {
3457 /* generate misc. treasure */ 3373 /* generate misc. treasure */
3458 tmp = arch_to_object (tr->item); 3374 tmp = arch_to_object (tr->item);
3459 new_draw_info_format (NDI_UNIQUE | NDI_BLUE, 0, who, "You gained %s", query_short_name (tmp)); 3375 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); 3376 who->insert (tmp);
3461 if (who->type == PLAYER)
3462 esrv_send_item (who, tmp);
3463 } 3377 }
3464} 3378}
3465 3379
3466/** 3380/**
3467 * Unready an object for a player. This function does nothing if the object was 3381 * Unready an object for a player. This function does nothing if the object was
3479 if (pl->ranged_ob == ob) 3393 if (pl->ranged_ob == ob)
3480 pl->ranged_ob = 0; 3394 pl->ranged_ob = 0;
3481} 3395}
3482 3396
3483sint8 3397sint8
3484player::visibility_at (maptile *map, int x, int y) const 3398player::darkness_at (maptile *map, int x, int y) const
3485{ 3399{
3486 if (!ns) 3400 if (!ns)
3487 return 0; 3401 return LOS_BLOCKED;
3488 3402
3489 int dx, dy; 3403 int dx, dy;
3490 if (!adjacent_map (map, ns->current_map, &dx, &dy)) 3404 if (!adjacent_map (map, ns->current_map, &dx, &dy))
3491 return 0; 3405 return LOS_BLOCKED;
3492 3406
3493 x += dx - ns->current_x + ns->mapx / 2; 3407 x += dx - ns->current_x;
3494 y += dy - ns->current_y + ns->mapy / 2; 3408 y += dy - ns->current_y;
3495 3409
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]; 3410 return blocked_los (x, y);
3500} 3411}
3501 3412
3502void 3413void
3503player::infobox (const char *title, const char *msg, int color) 3414player::infobox (const char *title, const char *msg, int color)
3504{ 3415{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines