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.198 by root, Sat May 17 00:17:02 2008 UTC vs.
Revision 1.221 by root, Wed Dec 31 17:35:38 2008 UTC

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
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{
868 ob->msg = 0; 870 ob->msg = 0;
869 871
870 start_info (ob); 872 start_info (ob);
871 CLEAR_FLAG (ob, FLAG_WIZ); 873 CLEAR_FLAG (ob, FLAG_WIZ);
872 give_initial_items (ob, ob->randomitems); 874 give_initial_items (ob, ob->randomitems);
873 link_player_skills (ob);
874 esrv_send_inventory (ob, ob); 875 esrv_send_inventory (ob, ob);
875 ob->update_stats (); 876 ob->update_stats ();
876 877
877 /* This moves the player to a different start map, if there 878 /* This moves the player to a different start map, if there
878 * is one for this race 879 * is one for this race
930 LOG (llevDebug, "Fleeing player is dead.\n"); 931 LOG (llevDebug, "Fleeing player is dead.\n");
931 CLEAR_FLAG (op, FLAG_SCARED); 932 CLEAR_FLAG (op, FLAG_SCARED);
932 return; 933 return;
933 } 934 }
934 935
935 if (op->enemy == NULL) 936 if (!op->enemy)
936 { 937 {
937 LOG (llevDebug, "Fleeing player had no enemy.\n"); 938 LOG (llevDebug, "Fleeing player had no enemy.\n");
938 CLEAR_FLAG (op, FLAG_SCARED); 939 CLEAR_FLAG (op, FLAG_SCARED);
939 return; 940 return;
940 } 941 }
941 942
942 /* Seen some crashes here. Since we don't store an
943 * op->enemy_count, it is possible that something destroys the
944 * actual enemy, and the object is recycled.
945 */
946 if (op->enemy->map == NULL)
947 {
948 CLEAR_FLAG (op, FLAG_SCARED);
949 op->enemy = NULL;
950 return;
951 }
952
953 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))
954 { 944 {
955 op->enemy = NULL; 945 op->enemy = NULL;
956 CLEAR_FLAG (op, FLAG_SCARED); 946 CLEAR_FLAG (op, FLAG_SCARED);
957 return; 947 return;
960 get_rangevector (op, op->enemy, &rv, 0); 950 get_rangevector (op, op->enemy, &rv, 0);
961 951
962 dir = absdir (4 + rv.direction); 952 dir = absdir (4 + rv.direction);
963 for (diff = 0; diff < 3; diff++) 953 for (diff = 0; diff < 3; diff++)
964 { 954 {
965 int m = 1 - (RANDOM () & 2); 955 int m = 1 - rndm (2) * 2;
966 956
967 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)))
968 return; 958 return;
969 } 959 }
970 960
981check_pick (object *op) 971check_pick (object *op)
982{ 972{
983 object *tmp, *next; 973 object *tmp, *next;
984 int stop = 0; 974 int stop = 0;
985 int wvratio; 975 int wvratio;
986 char putstring[128];
987 976
988 /* if you're flying, you cna't pick up anything */ 977 /* if you're flying, you cna't pick up anything */
989 if (op->move_type & MOVE_FLYING) 978 if (op->move_type & MOVE_FLYING)
990 return 1; 979 return 1;
991 980
1015 1004
1016 if (op->contr->search_str[0] != '\0' && settings.search_items == TRUE) 1005 if (op->contr->search_str[0] != '\0' && settings.search_items == TRUE)
1017 { 1006 {
1018 if (item_matched_string (op, tmp, op->contr->search_str)) 1007 if (item_matched_string (op, tmp, op->contr->search_str))
1019 CHK_PICK_PICKUP; 1008 CHK_PICK_PICKUP;
1009
1020 continue; 1010 continue;
1021 } 1011 }
1022 1012
1023 /* 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? */
1024 if (!(op->contr->mode & PU_NEWMODE)) 1073 if (op->contr->mode & PU_FOOD)
1074 if (tmp->type == FOOD)
1025 { 1075 {
1026 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)
1027 { 1135 {
1028 case 0:
1029 return 1; /* don't pick up */
1030 case 1:
1031 CHK_PICK_PICKUP; 1136 CHK_PICK_PICKUP;
1032 return 1; 1137 continue;
1033 case 2:
1034 CHK_PICK_PICKUP;
1035 return 0;
1036 case 3:
1037 return 0; /* stop before pickup */
1038 case 4:
1039 CHK_PICK_PICKUP;
1040 break;
1041 case 5:
1042 CHK_PICK_PICKUP;
1043 stop = 1;
1044 break;
1045 case 6:
1046 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL)
1047 && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))
1048 CHK_PICK_PICKUP;
1049 break;
1050
1051 case 7:
1052 if (tmp->type == MONEY || tmp->type == GEM)
1053 CHK_PICK_PICKUP;
1054 break;
1055
1056 default:
1057 /* use value density */
1058 if (!QUERY_FLAG (tmp, FLAG_UNPAID)
1059 && (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))) >= op->contr->mode)
1060 CHK_PICK_PICKUP;
1061 } 1138 }
1062 } 1139 }
1063 else 1140
1064 { /* old model */ 1141 /* rings & amulets - talismans seems to be typed AMULET */
1065 /* 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! */
1066 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 != NULL)
1067 { 1227 {
1068 /* some debugging code to figure out item information */ 1228 if (strstr (tmp->name, "table") == NULL && strstr (tmp->arch->archname, "table") == NULL &&
1069 if (tmp->name != NULL) 1229 strstr (tmp->name, "chair") && strstr (tmp->arch->archname, "chair") == NULL)
1070 sprintf (putstring, "item name: %s item type: %d weight/value: %d",
1071 &tmp->name, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))));
1072 else
1073 sprintf (putstring, "item name: %s item type: %d weight/value: %d",
1074 &tmp->arch->archname, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))));
1075
1076 new_draw_info (NDI_UNIQUE, 0, op, putstring);
1077 }
1078
1079 /* philosophy:
1080 * It's easy to grab an item type from a pile, as long as it's
1081 * generic. This takes no game-time. For more detailed pickups
1082 * and selections, select-items should be used. This is a
1083 * grab-as-you-run type mode that's really useful for arrows for
1084 * example.
1085 * The drawback: right now it has no frontend, so you need to
1086 * stick the bits you want into a calculator in hex mode and then
1087 * convert to decimal and then 'pickup <#>
1088 */
1089
1090 /* the first two modes are exclusive: if NOTHING we return, if
1091 * STOP then we stop. All the rest are applied sequentially,
1092 * meaning if any test passes, the item gets picked up. */
1093
1094 /* if mode is set to pick nothing up, return */
1095
1096 if (op->contr->mode & PU_NOTHING)
1097 return 1;
1098
1099 /* if mode is set to stop when encountering objects, return */
1100 /* take STOP before INHIBIT since it doesn't actually pick
1101 * anything up */
1102
1103 if (op->contr->mode & PU_STOP)
1104 return 0;
1105
1106 /* useful for going into stores and not losing your settings... */
1107 /* and for battles wher you don't want to get loaded down while
1108 * fighting */
1109 if (op->contr->mode & PU_INHIBIT)
1110 return 1;
1111
1112 /* prevent us from turning into auto-thieves :) */
1113 if (QUERY_FLAG (tmp, FLAG_UNPAID))
1114 continue;
1115
1116 /* ignore known cursed objects */
1117 if (QUERY_FLAG (tmp, FLAG_KNOWN_CURSED) && op->contr->mode & PU_NOT_CURSED)
1118 continue;
1119
1120 /* all food and drink if desired */
1121 /* question: don't pick up known-poisonous stuff? */
1122 if (op->contr->mode & PU_FOOD)
1123 if (tmp->type == FOOD)
1124 {
1125 CHK_PICK_PICKUP;
1126 continue;
1127 }
1128
1129 if (op->contr->mode & PU_DRINK)
1130 if (tmp->type == DRINK || (tmp->type == POISON && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)))
1131 {
1132 CHK_PICK_PICKUP;
1133 continue;
1134 }
1135
1136 if (op->contr->mode & PU_POTION)
1137 if (tmp->type == POTION)
1138 {
1139 CHK_PICK_PICKUP;
1140 continue;
1141 }
1142
1143 /* spellbooks, skillscrolls and normal books/scrolls */
1144 if (op->contr->mode & PU_SPELLBOOK)
1145 if (tmp->type == SPELLBOOK)
1146 {
1147 CHK_PICK_PICKUP;
1148 continue;
1149 }
1150
1151 if (op->contr->mode & PU_SKILLSCROLL)
1152 if (tmp->type == SKILLSCROLL)
1153 {
1154 CHK_PICK_PICKUP;
1155 continue;
1156 }
1157
1158 if (op->contr->mode & PU_READABLES)
1159 if (tmp->type == BOOK || tmp->type == SCROLL || tmp->type == INSCRIBABLE)
1160 {
1161 CHK_PICK_PICKUP;
1162 continue;
1163 }
1164
1165 /* wands/staves/rods/horns */
1166 if (op->contr->mode & PU_MAGIC_DEVICE)
1167 if (tmp->type == WAND || tmp->type == ROD || tmp->type == HORN)
1168 {
1169 CHK_PICK_PICKUP;
1170 continue;
1171 }
1172
1173 /* pick up all magical items */
1174 if (op->contr->mode & PU_MAGICAL)
1175 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))
1176 {
1177 CHK_PICK_PICKUP;
1178 continue;
1179 }
1180
1181 if (op->contr->mode & PU_VALUABLES)
1182 {
1183 if (tmp->type == MONEY || tmp->type == GEM)
1184 { 1230 {
1185 CHK_PICK_PICKUP; 1231 CHK_PICK_PICKUP;
1186 continue; 1232 continue;
1187 } 1233 }
1188 } 1234 }
1189 1235
1190 /* rings & amulets - talismans seems to be typed AMULET */
1191 if (op->contr->mode & PU_JEWELS)
1192 if (tmp->type == RING || tmp->type == AMULET) 1236 if (tmp->type == WEAPON && tmp->name == NULL)
1193 {
1194 CHK_PICK_PICKUP;
1195 continue;
1196 }
1197
1198 /* we don't forget dragon food */
1199 if (op->contr->mode & PU_FLESH)
1200 if (tmp->type == FLESH)
1201 {
1202 CHK_PICK_PICKUP;
1203 continue;
1204 }
1205
1206 /* bows and arrows. Bows are good for selling! */
1207 if (op->contr->mode & PU_BOW)
1208 if (tmp->type == BOW)
1209 {
1210 CHK_PICK_PICKUP;
1211 continue;
1212 }
1213
1214 if (op->contr->mode & PU_ARROW)
1215 if (tmp->type == ARROW)
1216 {
1217 CHK_PICK_PICKUP;
1218 continue;
1219 }
1220
1221 /* all kinds of armor etc. */
1222 if (op->contr->mode & PU_ARMOUR)
1223 if (tmp->type == ARMOUR)
1224 {
1225 CHK_PICK_PICKUP;
1226 continue;
1227 }
1228
1229 if (op->contr->mode & PU_HELMET)
1230 if (tmp->type == HELMET)
1231 {
1232 CHK_PICK_PICKUP;
1233 continue;
1234 }
1235
1236 if (op->contr->mode & PU_SHIELD)
1237 if (tmp->type == SHIELD)
1238 {
1239 CHK_PICK_PICKUP;
1240 continue;
1241 }
1242
1243 if (op->contr->mode & PU_BOOTS)
1244 if (tmp->type == BOOTS)
1245 {
1246 CHK_PICK_PICKUP;
1247 continue;
1248 }
1249
1250 if (op->contr->mode & PU_GLOVES)
1251 if (tmp->type == GLOVES)
1252 {
1253 CHK_PICK_PICKUP;
1254 continue;
1255 }
1256
1257 if (op->contr->mode & PU_CLOAK)
1258 if (tmp->type == CLOAK)
1259 {
1260 CHK_PICK_PICKUP;
1261 continue;
1262 }
1263
1264 /* hoping to catch throwing daggers here */
1265 if (op->contr->mode & PU_MISSILEWEAPON)
1266 if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_IS_THROWN))
1267 {
1268 CHK_PICK_PICKUP;
1269 continue;
1270 }
1271
1272 /* careful: chairs and tables are weapons! */
1273 if (op->contr->mode & PU_ALLWEAPON)
1274 { 1237 {
1275 if (tmp->type == WEAPON && tmp->name != NULL) 1238 if (strstr (tmp->arch->archname, "table") == NULL && strstr (tmp->arch->archname, "chair") == NULL)
1276 { 1239 {
1277 if (strstr (tmp->name, "table") == NULL && strstr (tmp->arch->archname, "table") == NULL &&
1278 strstr (tmp->name, "chair") && strstr (tmp->arch->archname, "chair") == NULL)
1279 {
1280 CHK_PICK_PICKUP; 1240 CHK_PICK_PICKUP;
1281 continue; 1241 continue;
1282 }
1283 }
1284
1285 if (tmp->type == WEAPON && tmp->name == NULL)
1286 {
1287 if (strstr (tmp->arch->archname, "table") == NULL && strstr (tmp->arch->archname, "chair") == NULL)
1288 {
1289 CHK_PICK_PICKUP;
1290 continue;
1291 }
1292 } 1242 }
1293 } 1243 }
1244 }
1294 1245
1295 /* misc stuff that's useful */ 1246 /* misc stuff that's useful */
1296 if (op->contr->mode & PU_KEY) 1247 if (op->contr->mode & PU_KEY)
1297 if (tmp->type == KEY || tmp->type == SPECIAL_KEY) 1248 if (tmp->type == KEY || tmp->type == SPECIAL_KEY)
1298 { 1249 {
1299 CHK_PICK_PICKUP; 1250 CHK_PICK_PICKUP;
1300 continue; 1251 continue;
1301 } 1252 }
1302 1253
1303 /* 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
1304 * pickups */ 1255 * pickups */
1305 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)
1306 { 1264 {
1307 /* use value density to decide what else to grab */ 1265#if 0
1308 /* >=7 was >= op->contr->mode */ 1266 fprintf (stderr, "HIGH WEIGHT/VALUE [");
1309 /* >=7 is the old standard setting. Now we take the last 4 bits 1267 if (tmp->name != NULL)
1310 * and multiply them by 5, giving 0..15*5== 5..75 */
1311 wvratio = (op->contr->mode & PU_RATIO) * 5;
1312 if ((query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))) >= (unsigned int) wvratio)
1313 { 1268 {
1314 CHK_PICK_PICKUP;
1315#if 0
1316 fprintf (stderr, "HIGH WEIGHT/VALUE [");
1317 if (tmp->name != NULL)
1318 {
1319 fprintf (stderr, "%s", tmp->name); 1269 fprintf (stderr, "%s", tmp->name);
1320 } 1270 }
1321 else 1271 else
1322 fprintf (stderr, "%s", tmp->arch->archname); 1272 fprintf (stderr, "%s", tmp->arch->archname);
1323 fprintf (stderr, ",%d] = ", tmp->type); 1273 fprintf (stderr, ",%d] = ", tmp->type);
1324 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))));
1325#endif 1275#endif
1276 CHK_PICK_PICKUP;
1326 continue; 1277 continue;
1327 }
1328 } 1278 }
1329 } /* the new pickup model */ 1279 } /* the new pickup model */
1330 } 1280 }
1331 1281
1332 return !stop; 1282 return !stop;
1461 for (i = 0, found = 0; i < 20; i++) 1411 for (i = 0, found = 0; i < 20; i++)
1462 { 1412 {
1463 x += freearr_x[dir]; 1413 x += freearr_x[dir];
1464 y += freearr_y[dir]; 1414 y += freearr_y[dir];
1465 mflags = get_map_flags (m, &m, x, y, &x, &y); 1415 mflags = get_map_flags (m, &m, x, y, &x, &y);
1416
1466 if (mflags & P_OUT_OF_MAP || mflags & P_BLOCKSVIEW) 1417 if (mflags & P_OUT_OF_MAP || mflags & P_BLOCKSVIEW)
1467 { 1418 {
1468 tmp = NULL; 1419 tmp = 0;
1469 break; 1420 break;
1470 } 1421 }
1471 else if (GET_MAP_MOVE_BLOCK (m, x, y) == MOVE_FLY_LOW) 1422 else if (GET_MAP_MOVE_BLOCK (m, x, y) == MOVE_FLY_LOW)
1472 { 1423 {
1473 /* This block presumes arrows and the like are MOVE_FLY_SLOW - 1424 /* This block presumes arrows and the like are MOVE_FLY_SLOW -
1474 * perhaps a bad assumption. 1425 * perhaps a bad assumption.
1475 */ 1426 */
1476 tmp = NULL; 1427 tmp = 0;
1477 break; 1428 break;
1478 } 1429 }
1430
1479 if (mflags & P_IS_ALIVE) 1431 if (mflags & P_IS_ALIVE)
1480 {
1481 for (tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above) 1432 for (tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above)
1482 if (QUERY_FLAG (tmp, FLAG_ALIVE)) 1433 if (QUERY_FLAG (tmp, FLAG_ALIVE))
1483 {
1484 found++;
1485 break;
1486 }
1487 if (found)
1488 break; 1434 break;
1489 }
1490 } 1435 }
1491 if (tmp == NULL) 1436
1437 if (!tmp)
1492 return find_arrow (op, type); 1438 return find_arrow (op, type);
1493 1439
1494 if (tmp->head) 1440 if (tmp->head)
1495 tmp = tmp->head; 1441 tmp = tmp->head;
1496 1442
1541 if (bow->below) 1487 if (bow->below)
1542 { 1488 {
1543 bow->remove (); 1489 bow->remove ();
1544 op->insert (bow); 1490 op->insert (bow);
1545 } 1491 }
1546
1547 } 1492 }
1548 1493
1549 if (!bow->race || !bow->skill) 1494 if (!bow->race || !bow->skill)
1550 { 1495 {
1551 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s is broken.", &bow->name); 1496 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s is broken.", &bow->name);
1577 } 1522 }
1578 1523
1579 /* this should not happen, but sometimes does */ 1524 /* this should not happen, but sometimes does */
1580 if (arrow->nrof == 0) 1525 if (arrow->nrof == 0)
1581 { 1526 {
1527 LOG (llevError | logBacktrace, "arrow (%s) has nrof 0\n", arrow->debug_desc ());
1582 arrow->destroy (); 1528 arrow->destroy ();
1583 return 0; 1529 return 0;
1584 } 1530 }
1585 1531
1586 left = arrow; /* these are arrows left to the player */ 1532 left = arrow; /* these are arrows left to the player */
1673 * hence the function name. 1619 * hence the function name.
1674 */ 1620 */
1675int 1621int
1676player_fire_bow (object *op, int dir) 1622player_fire_bow (object *op, int dir)
1677{ 1623{
1678 int ret = 0, wcmod = 0; 1624 int ret;
1679 1625
1680 if (op->contr->bowtype == bow_bestarrow) 1626 if (op->contr->bowtype == bow_bestarrow)
1681 { 1627 {
1682 ret = fire_bow (op, op, pick_arrow_target (op, op->contr->ranged_ob->race, dir), dir, 0, op->x, op->y); 1628 ret = fire_bow (op, op, pick_arrow_target (op, op->contr->ranged_ob->race, dir), dir, 0, op->x, op->y);
1683 } 1629 }
1684 else if (op->contr->bowtype >= bow_n && op->contr->bowtype <= bow_nw) 1630 else if (op->contr->bowtype >= bow_n && op->contr->bowtype <= bow_nw)
1685 { 1631 {
1686 if (!similar_direction (dir, op->contr->bowtype - bow_n + 1)) 1632 int wcmod = similar_direction (dir, op->contr->bowtype - bow_n + 1) ? 0 : -1;
1687 wcmod = -1;
1688
1689 ret = fire_bow (op, op, NULL, op->contr->bowtype - bow_n + 1, wcmod, op->x, op->y); 1633 ret = fire_bow (op, op, NULL, op->contr->bowtype - bow_n + 1, wcmod, op->x, op->y);
1690 } 1634 }
1691 else if (op->contr->bowtype == bow_threewide) 1635 else if (op->contr->bowtype == bow_threewide)
1692 { 1636 {
1693 ret = fire_bow (op, op, NULL, dir, 0, op->x, op->y); 1637 ret = fire_bow (op, op, NULL, dir, 0, op->x, op->y);
1694 ret |= fire_bow (op, op, NULL, dir, -5, op->x + freearr_x[absdir (dir + 2)], op->y + freearr_y[absdir (dir + 2)]); 1638 ret |= fire_bow (op, op, NULL, dir, -5, op->x + freearr_x[absdir (dir + 2)], op->y + freearr_y[absdir (dir + 2)]);
1695 ret |= fire_bow (op, op, NULL, dir, -5, op->x + freearr_x[absdir (dir - 2)], op->y + freearr_y[absdir (dir - 2)]); 1639 ret |= fire_bow (op, op, NULL, dir, -5, op->x + freearr_x[absdir (dir - 2)], op->y + freearr_y[absdir (dir - 2)]);
1696 } 1640 }
1697 else if (op->contr->bowtype == bow_spreadshot) 1641 else if (op->contr->bowtype == bow_spreadshot)
1698 { 1642 {
1699 ret |= fire_bow (op, op, NULL, dir, 0, op->x, op->y); 1643 ret = fire_bow (op, op, NULL, dir, 0, op->x, op->y);
1700 ret |= fire_bow (op, op, NULL, absdir (dir - 1), -5, op->x, op->y); 1644 ret |= fire_bow (op, op, NULL, absdir (dir - 1), -5, op->x, op->y);
1701 ret |= fire_bow (op, op, NULL, absdir (dir + 1), -5, op->x, op->y); 1645 ret |= fire_bow (op, op, NULL, absdir (dir + 1), -5, op->x, op->y);
1702 } 1646 }
1703 else 1647 else
1704 { 1648 {
1761 } 1705 }
1762 } 1706 }
1763 1707
1764 if (cast_spell (op, item, dir, item->inv, NULL)) 1708 if (cast_spell (op, item, dir, item->inv, NULL))
1765 { 1709 {
1766 SET_FLAG (op, FLAG_BEEN_APPLIED); /* You now know something about it */ 1710 item->flag [FLAG_BEEN_APPLIED] = true; /* You now know something about it */
1711
1767 if (item->type == WAND) 1712 if (item->type == WAND)
1768 { 1713 {
1769 if (!(--item->stats.food)) 1714 if (!(--item->stats.food))
1770 { 1715 {
1771 object *tmp; 1716 object *tmp;
1791bool 1736bool
1792fire (object *op, int dir) 1737fire (object *op, int dir)
1793{ 1738{
1794 int spellcost = 0; 1739 int spellcost = 0;
1795 1740
1796 /* check for loss of invisiblity/hide */
1797 if (action_makes_visible (op))
1798 make_visible (op);
1799
1800 player *pl = op->contr; 1741 player *pl = op->contr;
1801 1742
1802 if (pl->golem) 1743 if (pl->golem)
1803 { 1744 {
1804 control_golem (op->contr->golem, dir); 1745 control_golem (op->contr->golem, dir);
1806 } 1747 }
1807 1748
1808 object *ob = pl->ranged_ob; 1749 object *ob = pl->ranged_ob;
1809 1750
1810 if (!ob) 1751 if (!ob)
1811 return false;
1812
1813 if (!op->change_weapon (ob))
1814 return false; 1752 return false;
1815 1753
1816 if (op->speed_left > 0.f) 1754 if (op->speed_left > 0.f)
1817 --op->speed_left; 1755 --op->speed_left;
1818 else 1756 else
1819 return false; 1757 return false;
1758
1759 if (!op->change_weapon (ob))
1760 return false;
1761
1762 /* check for loss of invisiblity/hide */
1763 if (action_makes_visible (op))
1764 make_visible (op);
1820 1765
1821 switch (ob->type) 1766 switch (ob->type)
1822 { 1767 {
1823 case BOW: 1768 case BOW:
1824 player_fire_bow (op, dir); 1769 player_fire_bow (op, dir);
2069 --op->speed_left; 2014 --op->speed_left;
2070 2015
2071 op->play_sound (sound_find ("push_player")); 2016 op->play_sound (sound_find ("push_player"));
2072 push_ob (mon, dir, op); 2017 push_ob (mon, dir, op);
2073 2018
2074 if (op->contr->tmp_invis || op->hide) 2019 if (action_makes_visible (op))
2075 make_visible (op); 2020 make_visible (op);
2076 2021
2077 return true; 2022 return true;
2078 } 2023 }
2079 else 2024 else
2101 push_ob (mon, dir, op); 2046 push_ob (mon, dir, op);
2102 } 2047 }
2103 else 2048 else
2104 op->statusmsg ("You withhold your attack"); 2049 op->statusmsg ("You withhold your attack");
2105 2050
2106 if (op->contr->tmp_invis || op->hide) 2051 if (op->contr->tmp_invis || op->flag [FLAG_HIDDEN])
2107 make_visible (op); 2052 make_visible (op);
2108 2053
2109 return true; 2054 return true;
2110 } 2055 }
2111 } 2056 }
2169 if (QUERY_FLAG (op, FLAG_CONFUSED) && dir) 2114 if (QUERY_FLAG (op, FLAG_CONFUSED) && dir)
2170 dir = absdir (dir + rndm (3) + rndm (3) - 2); 2115 dir = absdir (dir + rndm (3) + rndm (3) - 2);
2171 2116
2172 op->facing = dir; 2117 op->facing = dir;
2173 2118
2174 if (op->hide) 2119 if (op->flag [FLAG_HIDDEN])
2175 do_hidden_move (op); 2120 do_hidden_move (op);
2176 2121
2177 bool retval; 2122 bool retval;
2178 2123
2179 if (INVOKE_PLAYER (MOVE, op->contr, ARG_INT (dir))) 2124 if (INVOKE_PLAYER (MOVE, op->contr, ARG_INT (dir)))
2310const char * 2255const char *
2311gravestone_text (object *op) 2256gravestone_text (object *op)
2312{ 2257{
2313 static dynbuf_text buf; 2258 static dynbuf_text buf;
2314 2259
2315 buf << "---- R.I.P. ----\n\n"; 2260 buf << "---- R.I.P. ----\n\n"
2316 op->name; 2261 << op->name;
2317 2262
2318 if (op->type == PLAYER) 2263 if (op->type == PLAYER)
2319 buf << " the " << op->contr->title; 2264 buf << " the " << op->contr->title;
2320 2265
2321 buf << "\n\n"; 2266 buf << "\n\n";
2497 { 2442 {
2498 over_hp = (gen_hp < 20 ? 30 : gen_hp + 10) / rate_hp; 2443 over_hp = (gen_hp < 20 ? 30 : gen_hp + 10) / rate_hp;
2499 2444
2500 if (over_hp > 0) 2445 if (over_hp > 0)
2501 { 2446 {
2502 op->stats.sp += over_hp + (RANDOM () % rate_hp > ((gen_hp < 20 ? 30 : gen_hp + 10) % rate_hp)) ? -1 : 0; 2447 op->stats.sp += over_hp + (rndm (rate_hp) > ((gen_hp < 20 ? 30 : gen_hp + 10) % rate_hp)) ? -1 : 0;
2503 op->last_heal = 0; 2448 op->last_heal = 0;
2504 } 2449 }
2505 else 2450 else
2506 op->last_heal = rate_hp / (gen_hp < 20 ? 30 : gen_hp + 10); 2451 op->last_heal = rate_hp / (gen_hp < 20 ? 30 : gen_hp + 10);
2507 } 2452 }
2563 2508
2564 if (op->stats.food < 0) 2509 if (op->stats.food < 0)
2565 { 2510 {
2566 op->stats.hp += op->stats.food; 2511 op->stats.hp += op->stats.food;
2567 op->stats.food = 0; 2512 op->stats.food = 0;
2513
2514 if (op->stats.hp < 0)
2515 {
2516 op->contr->killer = archetype::get ("killer_starvation");
2517 op->contr->killer->destroy ();
2568 } 2518 }
2519 }
2569 2520
2521 /* killer should be set here already */
2570 if (op->stats.hp < 0 && !QUERY_FLAG (op, FLAG_WIZ)) 2522 if (op->stats.hp < 0 && !QUERY_FLAG (op, FLAG_WIZ))
2571 kill_player (op); 2523 kill_player (op);
2572 } 2524 }
2573} 2525}
2574 2526
2588 object *tmp; 2540 object *tmp;
2589 2541
2590 if (save_life (op)) 2542 if (save_life (op))
2591 return; 2543 return;
2592 2544
2545 /* restore player */
2546 at = archetype::find ("poisoning");
2547 if (object *tmp = present_arch_in_ob (at, op))
2548 {
2549 tmp->destroy ();
2550 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed");
2551 }
2552
2553 at = archetype::find ("confusion");
2554 if (object *tmp = present_arch_in_ob (at, op))
2555 {
2556 tmp->destroy ();
2557 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer");
2558 }
2559
2560 cure_disease (op, 0, 0); /* remove any disease */
2561
2562 max_it (op->stats.hp , op->stats.maxhp);
2563 max_it (op->stats.sp , op->stats.maxsp);
2564 max_it (op->stats.grace, op->stats.maxgrace);
2565
2566 if (op->stats.food <= 0)
2567 op->stats.food = 999;
2568
2569 // remove all spell effects that are active
2570 // to avoid long-term effects such as word-of-recall
2571 for (object *item = op->inv; item; )
2572 {
2573 object *next = item->below;
2574
2575 if (item->type == SPELL_EFFECT && item->active)
2576 item->destroy ();
2577
2578 item = next;
2579 }
2580
2593 /* If player dies on BATTLEGROUND, no stat/exp loss! For Combat-Arenas 2581 /* If player dies on BATTLEGROUND, no stat/exp loss! For Combat-Arenas
2594 * in cities ONLY!!! It is very important that this doesn't get abused. 2582 * in cities ONLY!!! It is very important that this doesn't get abused.
2595 * Look at op_on_battleground() for more info --AndreasV 2583 * Look at op_on_battleground() for more info --AndreasV
2596 */ 2584 */
2597 if (op_on_battleground (op, &x, &y)) 2585 if (op_on_battleground (op, &x, &y))
2598 { 2586 {
2599 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, "You have been defeated in combat!"); 2587 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, "You have been defeated in combat!");
2600 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, "Local medics have saved your life..."); 2588 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, "Local medics have saved your life...");
2601
2602 /* restore player */
2603 at = archetype::find ("poisoning");
2604 if (object *tmp = present_arch_in_ob (at, op))
2605 {
2606 tmp->destroy ();
2607 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed");
2608 }
2609
2610 at = archetype::find ("confusion");
2611 if (object *tmp = present_arch_in_ob (at, op))
2612 {
2613 tmp->destroy ();
2614 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer");
2615 }
2616
2617 cure_disease (op, 0, 0); /* remove any disease */
2618 op->stats.hp = op->stats.maxhp;
2619 if (op->stats.food <= 0)
2620 op->stats.food = 999;
2621 2589
2622 /* create a bodypart-trophy to make the winner happy */ 2590 /* create a bodypart-trophy to make the winner happy */
2623 if (object *tmp = arch_to_object (archetype::find ("finger"))) 2591 if (object *tmp = arch_to_object (archetype::find ("finger")))
2624 { 2592 {
2625 tmp->name = format ("%s's finger" , &op->name); 2593 tmp->name = format ("%s's finger" , &op->name);
2643 2611
2644 INVOKE_PLAYER (DEATH, op->contr); 2612 INVOKE_PLAYER (DEATH, op->contr);
2645 2613
2646 command_kill_pets (op, 0); 2614 command_kill_pets (op, 0);
2647 2615
2648 if (op->stats.food < 0)
2649 {
2650 op->contr->killer = archetype::get ("killer_starvation");
2651 op->contr->killer->destroy ();
2652 }
2653
2654 op->contr->play_sound (sound_find ("player_dies")); 2616 op->contr->play_sound (sound_find ("player_dies"));
2655 2617
2656 /* save the map location for corpse, gravestone */ 2618 /* save the map location for corpse, gravestone */
2657 x = op->x; 2619 x = op->x;
2658 y = op->y; 2620 y = op->y;
2687 2649
2688 lost_a_stat = 0; 2650 lost_a_stat = 0;
2689 2651
2690 for (z = 0; z < num_stats_lose; z++) 2652 for (z = 0; z < num_stats_lose; z++)
2691 { 2653 {
2692 i = RANDOM () % NUM_STATS; 2654 i = rndm (NUM_STATS);
2693 2655
2694 if (settings.stat_loss_on_death) 2656 if (settings.stat_loss_on_death)
2695 { 2657 {
2696 /* Pick a random stat and take a point off it. Tell the player 2658 /* Pick a random stat and take a point off it. Tell the player
2697 * what he lost. 2659 * what he lost.
2748 } 2710 }
2749 } 2711 }
2750 2712
2751 if (lose_this_stat) 2713 if (lose_this_stat)
2752 { 2714 {
2753 this_stat = get_attr_value (&(dep->stats), i); 2715 this_stat = get_attr_value (&dep->stats, i);
2754 /* We could try to do something clever like find another 2716 /* We could try to do something clever like find another
2755 * stat to reduce if this fails. But chances are, if 2717 * stat to reduce if this fails. But chances are, if
2756 * stats have been depleted to -50, all are pretty low 2718 * stats have been depleted to -50, all are pretty low
2757 * and should be roughly the same, so it shouldn't make a 2719 * and should be roughly the same, so it shouldn't make a
2758 * difference. 2720 * difference.
2772 /* If no stat lost, tell the player. */ 2734 /* If no stat lost, tell the player. */
2773 if (!lost_a_stat) 2735 if (!lost_a_stat)
2774 { 2736 {
2775 /* determine_god() seems to not work sometimes... why is this? 2737 /* determine_god() seems to not work sometimes... why is this?
2776 Should I be using something else? GD */ 2738 Should I be using something else? GD */
2777 const char *god = determine_god (op); 2739 shstr_tmp god = determine_god (op);
2778 2740
2779 if (god && (strcmp (god, "none"))) 2741 if (god != shstr_none)
2780 new_draw_info_format (NDI_UNIQUE, 0, op, "For a brief moment you feel the holy presence of %s protecting" " you.", god); 2742 new_draw_info_format (NDI_UNIQUE, 0, op, "For a brief moment you feel the holy presence of %s protecting" " you.", &god);
2781 else 2743 else
2782 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you feel a holy presence protecting you."); 2744 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you feel a holy presence protecting you.");
2783 } 2745 }
2784#else 2746#else
2785 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you feel a holy presence protecting you from losing yourself completely."); 2747 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you feel a holy presence protecting you from losing yourself completely.");
2789 * exp loss on the stone. 2751 * exp loss on the stone.
2790 */ 2752 */
2791 tmp = arch_to_object (archetype::find ("gravestone")); 2753 tmp = arch_to_object (archetype::find ("gravestone"));
2792 tmp->name = format ("%s's gravestone", &op->name); 2754 tmp->name = format ("%s's gravestone", &op->name);
2793 tmp->name_pl = format ("%s's gravestones", &op->name); 2755 tmp->name_pl = format ("%s's gravestones", &op->name);
2794 tmp->msg = format ("RIP\nHere rests the hero %s the %s,\nwho was killed\nby %s.\n", &op->name, op->contr->title, op->contr->killer_name ()); 2756 tmp->msg = format ("T<RIP>\n\nHere rests the hero %s the %s,\rwho was killed\rby %s.\n",
2757 &op->name, op->contr->title, op->contr->killer_name ());
2795 tmp->x = op->x, tmp->y = op->y; 2758 tmp->x = op->x, tmp->y = op->y;
2796 insert_ob_in_map (tmp, op->map, NULL, 0); 2759 insert_ob_in_map (tmp, op->map, NULL, 0);
2797 2760
2798 /**************************************/ 2761 /**************************************/
2799 /* */ 2762 /* */
2800 /* Subtract the experience points, */ 2763 /* Subtract the experience points, */
2801 /* if we died cause of food, give us */
2802 /* food, and reset HP's... */
2803 /* */ 2764 /* */
2804 /**************************************/ 2765 /**************************************/
2805 2766
2806 /* remove any poisoning and confusion the character may be suffering. */
2807 /* restore player */
2808 at = archetype::find ("poisoning");
2809 tmp = present_arch_in_ob (at, op);
2810
2811 if (tmp)
2812 {
2813 tmp->destroy ();
2814 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed");
2815 }
2816
2817 at = archetype::find ("confusion");
2818 tmp = present_arch_in_ob (at, op);
2819 if (tmp)
2820 {
2821 tmp->destroy ();
2822 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer");
2823 }
2824
2825 cure_disease (op, 0, 0); /* remove any disease */
2826
2827 // remove all spell effects that are active
2828 // to avoid long-term effects such as word-of-recall
2829 for (object *item = op->inv; item; )
2830 {
2831 object *next = item->below;
2832
2833 if (item->type == SPELL_EFFECT && item->active)
2834 item->destroy ();
2835
2836 item = next;
2837 }
2838
2839 /*add_exp(op, (op->stats.exp * -0.20)); */ 2767 /*add_exp(op, (op->stats.exp * -0.20)); */
2840 apply_death_exp_penalty (op); 2768 apply_death_exp_penalty (op);
2841
2842 if (op->stats.food < 100)
2843 op->stats.food = 900;
2844
2845 op->stats.hp = op->stats.maxhp;
2846 op->stats.sp = MAX (op->stats.sp, op->stats.maxsp);
2847 op->stats.grace = MAX (op->stats.grace, op->stats.maxgrace);
2848 2769
2849 /* 2770 /*
2850 * Check to see if the player has any unpaid items. If so, remove them 2771 * Check to see if the player has any unpaid items. If so, remove them
2851 * and put them back in the map. 2772 * and put them back in the map.
2852 */ 2773 */
2887 if (will_kill_again & (1 << at)) 2808 if (will_kill_again & (1 << at))
2888 force->resist[at] = 100; 2809 force->resist[at] = 100;
2889 2810
2890 insert_ob_in_ob (force, op); 2811 insert_ob_in_ob (force, op);
2891 op->update_stats (); 2812 op->update_stats ();
2892
2893 } 2813 }
2894 2814
2895 new_draw_info (NDI_UNIQUE, 0, op, "YOU HAVE DIED."); 2815 new_draw_info (NDI_UNIQUE, 0, op, "YOU HAVE DIED.");
2896} 2816}
2897 2817
2998} 2918}
2999 2919
3000void 2920void
3001make_visible (object *op) 2921make_visible (object *op)
3002{ 2922{
3003 op->hide = 0; 2923 op->flag [FLAG_HIDDEN] = 0;
3004 op->invisible = 0; 2924 op->invisible = 0;
3005 2925
3006 if (op->type == PLAYER) 2926 if (op->type == PLAYER)
3007 { 2927 {
3008 op->contr->tmp_invis = 0; 2928 op->contr->tmp_invis = 0;
3033 2953
3034 if (!ob || !ob->map) 2954 if (!ob || !ob->map)
3035 return 0; 2955 return 0;
3036 2956
3037 /* so, on normal lighted maps, its hard to hide */ 2957 /* so, on normal lighted maps, its hard to hide */
3038 level = ob->map->darkness - 2; 2958 level = ob->map->darklevel () - 2;
3039 2959
3040 /* this also picks up whether the object is glowing. 2960 /* this also picks up whether the object is glowing.
3041 * If you carry a light on a non-dark map, its not 2961 * If you carry a light on a non-dark map, its not
3042 * as bad as carrying a light on a pitch dark map */ 2962 * as bad as carrying a light on a pitch dark map */
3043 if (has_carried_lights (ob)) 2963 if (has_carried_lights (ob))
3044 level = -(10 + (2 * ob->map->darkness)); 2964 level = -(10 + (2 * ob->map->darklevel ()));
3045 2965
3046 /* scan through all nearby squares for terrain to hide in */ 2966 /* scan through all nearby squares for terrain to hide in */
3047 for (i = 0, x = ob->x, y = ob->y; 2967 for (i = 0, x = ob->x, y = ob->y;
3048 i <= SIZEOFFREE1; 2968 i <= SIZEOFFREE1;
3049 i++, x = ob->x + freearr_x[i], y = ob->y + freearr_y[i]) 2969 i++, x = ob->x + freearr_x[i], y = ob->y + freearr_y[i])
3196 while (op) 3116 while (op)
3197 { 3117 {
3198 dx = rv.distance_x + op->arch->x; 3118 dx = rv.distance_x + op->arch->x;
3199 dy = rv.distance_y + op->arch->y; 3119 dy = rv.distance_y + op->arch->y;
3200 3120
3201 /* only the viewable area the player sees is updated by LOS 3121 if (pl->contr->blocked_los (dx, dy) != LOS_BLOCKED)
3202 * code, so we need to restrict ourselves to that range of values
3203 * for any meaningful values.
3204 */
3205 if (abs (dx) <= (pl->contr->ns->mapx / 2) &&
3206 abs (dy) <= (pl->contr->ns->mapy / 2) &&
3207 !pl->contr->blocked_los[dx + (pl->contr->ns->mapx / 2)][dy + (pl->contr->ns->mapy / 2)])
3208 return 1; 3122 return 1;
3209 3123
3210 op = op->more; 3124 op = op->more;
3211 } 3125 }
3212 3126
3213 return 0; 3127 return 0;
3214} 3128}
3215 3129
3216/* routine for both players and monsters. We call this when 3130/* routine for both players and monsters. We call this when
3217 * there is a possibility for our action distrubing our hiding 3131 * there is a possibility for our action distrubing our hiding
3218 * place or invisiblity spell. Artefact invisiblity is not 3132 * place or invisiblity spell. Artefact invisiblity causes
3219 * effected by this. If we arent invisible to begin with, we 3133 * "noise" instead. If we arent invisible to begin with, we
3220 * return 0. 3134 * return 0.
3221 */ 3135 */
3222int 3136int
3223action_makes_visible (object *op) 3137action_makes_visible (object *op)
3224{ 3138{
3225 if (op->invisible && QUERY_FLAG (op, FLAG_ALIVE)) 3139 if (op->invisible && QUERY_FLAG (op, FLAG_ALIVE))
3226 { 3140 {
3227 if (QUERY_FLAG (op, FLAG_MAKE_INVIS)) 3141 if (QUERY_FLAG (op, FLAG_MAKE_INVIS))
3142 {
3143 // artefact invisibility is permanent, but we still make noise
3144 // this is important for game-balance.
3145 if (op->contr)
3146 op->make_noise ();
3147
3228 return 0; 3148 return 0;
3149 }
3229 3150
3230 if (op->contr && op->contr->tmp_invis == 0) 3151 if (op->contr && op->contr->tmp_invis == 0)
3231 return 0; 3152 return 0;
3232 3153
3233 /* If monsters, they should become visible */ 3154 /* If monsters, they should become visible */
3234 if (op->hide || !op->contr || (op->contr && op->contr->tmp_invis)) 3155 if (op->flag [FLAG_HIDDEN] || !op->contr || (op->contr && op->contr->tmp_invis))
3235 { 3156 {
3236 new_draw_info_format (NDI_UNIQUE, 0, op, "You become %s!", op->hide ? "unhidden" : "visible"); 3157 new_draw_info_format (NDI_UNIQUE, 0, op, "You become %s!", op->flag [FLAG_HIDDEN] ? "unhidden" : "visible");
3237 return 1; 3158 return 1;
3238 } 3159 }
3239 } 3160 }
3240 3161
3241 return 0; 3162 return 0;
3469 if (pl->ranged_ob == ob) 3390 if (pl->ranged_ob == ob)
3470 pl->ranged_ob = 0; 3391 pl->ranged_ob = 0;
3471} 3392}
3472 3393
3473sint8 3394sint8
3474player::visibility_at (maptile *map, int x, int y) const 3395player::darkness_at (maptile *map, int x, int y) const
3475{ 3396{
3476 if (!ns) 3397 if (!ns)
3477 return 0; 3398 return LOS_BLOCKED;
3478 3399
3479 int dx, dy; 3400 int dx, dy;
3480 if (!adjacent_map (map, ns->current_map, &dx, &dy)) 3401 if (!adjacent_map (map, ns->current_map, &dx, &dy))
3481 return 0; 3402 return LOS_BLOCKED;
3482 3403
3483 x += dx - ns->current_x + ns->mapx / 2; 3404 x += dx - ns->current_x;
3484 y += dy - ns->current_y + ns->mapy / 2; 3405 y += dy - ns->current_y;
3485 3406
3486 if (!IN_RANGE_EXC (x, 0, ns->mapx) || !IN_RANGE_EXC (y, 0, ns->mapy))
3487 return 0;
3488
3489 return 100 - blocked_los [x][y]; 3407 return blocked_los (x, y);
3490} 3408}
3491 3409
3492void 3410void
3493player::infobox (const char *title, const char *msg, int color) 3411player::infobox (const char *title, const char *msg, int color)
3494{ 3412{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines