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.227 by root, Tue Jan 6 19:17:07 2009 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 */
1066 if (op->contr->mode & PU_DEBUG) 1142 if (op->contr->mode & PU_JEWELS)
1143 if (tmp->type == RING || tmp->type == AMULET)
1067 { 1144 {
1068 /* some debugging code to figure out item information */ 1145 CHK_PICK_PICKUP;
1069 if (tmp->name != 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; 1146 continue;
1147 }
1115 1148
1116 /* ignore known cursed objects */ 1149 /* we don't forget dragon food */
1117 if (QUERY_FLAG (tmp, FLAG_KNOWN_CURSED) && op->contr->mode & PU_NOT_CURSED) 1150 if (op->contr->mode & PU_FLESH)
1151 if (tmp->type == FLESH)
1152 {
1153 CHK_PICK_PICKUP;
1118 continue; 1154 continue;
1155 }
1119 1156
1120 /* all food and drink if desired */ 1157 /* bows and arrows. Bows are good for selling! */
1121 /* question: don't pick up known-poisonous stuff? */ 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
1122 if (op->contr->mode & PU_FOOD) 1194 if (op->contr->mode & PU_BOOTS)
1123 if (tmp->type == FOOD) 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)
1227 if (!tmp->arch->archname.contains ("table") && !tmp->arch->archname.contains ("chair"))
1124 { 1228 {
1125 CHK_PICK_PICKUP; 1229 CHK_PICK_PICKUP;
1126 continue; 1230 continue;
1127 } 1231 }
1232 }
1128 1233
1234 /* misc stuff that's useful */
1129 if (op->contr->mode & PU_DRINK) 1235 if (op->contr->mode & PU_KEY)
1130 if (tmp->type == DRINK || (tmp->type == POISON && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))) 1236 if (tmp->type == KEY || tmp->type == SPECIAL_KEY)
1131 { 1237 {
1132 CHK_PICK_PICKUP; 1238 CHK_PICK_PICKUP;
1133 continue; 1239 continue;
1134 } 1240 }
1135 1241
1242 /* any of the last 4 bits set means we use the ratio for value
1243 * pickups */
1136 if (op->contr->mode & PU_POTION) 1244 if (op->contr->mode & PU_RATIO)
1137 if (tmp->type == POTION) 1245 {
1246 /* use value density to decide what else to grab */
1247 /* >=7 was >= op->contr->mode */
1248 /* >=7 is the old standard setting. Now we take the last 4 bits
1138 { 1249 */
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) 1250 wvratio = op->contr->mode & PU_RATIO;
1175 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)) 1251 if (1000 * query_cost (tmp, op, F_TRUE) / tmp->total_weight () >= wvratio * 100)
1176 {
1177 CHK_PICK_PICKUP;
1178 continue;
1179 }
1180
1181 if (op->contr->mode & PU_VALUABLES)
1182 { 1252 {
1183 if (tmp->type == MONEY || tmp->type == GEM) 1253#if 0
1254 fprintf (stderr, "HIGH WEIGHT/VALUE [");
1255 if (tmp->name != NULL)
1184 { 1256 {
1185 CHK_PICK_PICKUP; 1257 fprintf (stderr, "%s", tmp->name);
1186 continue;
1187 } 1258 }
1188 }
1189
1190 /* rings & amulets - talismans seems to be typed AMULET */
1191 if (op->contr->mode & PU_JEWELS)
1192 if (tmp->type == RING || tmp->type == AMULET)
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 {
1275 if (tmp->type == WEAPON && tmp->name != NULL)
1276 {
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;
1281 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 }
1293 }
1294
1295 /* misc stuff that's useful */
1296 if (op->contr->mode & PU_KEY)
1297 if (tmp->type == KEY || tmp->type == SPECIAL_KEY)
1298 {
1299 CHK_PICK_PICKUP;
1300 continue;
1301 }
1302
1303 /* any of the last 4 bits set means we use the ratio for value
1304 * pickups */
1305 if (op->contr->mode & PU_RATIO)
1306 {
1307 /* use value density to decide what else to grab */
1308 /* >=7 was >= op->contr->mode */
1309 /* >=7 is the old standard setting. Now we take the last 4 bits
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 {
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);
1320 }
1321 else 1259 else
1322 fprintf (stderr, "%s", tmp->arch->archname); 1260 fprintf (stderr, "%s", tmp->arch->archname);
1323 fprintf (stderr, ",%d] = ", tmp->type); 1261 fprintf (stderr, ",%d] = ", tmp->type);
1324 fprintf (stderr, "%d\n", (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1)))); 1262 fprintf (stderr, "%d\n", (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))));
1325#endif 1263#endif
1264 CHK_PICK_PICKUP;
1326 continue; 1265 continue;
1327 }
1328 } 1266 }
1329 } /* the new pickup model */ 1267 } /* the new pickup model */
1330 } 1268 }
1331 1269
1332 return !stop; 1270 return !stop;
1360 * against the target. A full test is not performed, simply a basic test 1298 * against the target. A full test is not performed, simply a basic test
1361 * of resistances. The archer is making a quick guess at what he sees down 1299 * of resistances. The archer is making a quick guess at what he sees down
1362 * the hall. Failing that it does it's best to pick the highest plus arrow. 1300 * the hall. Failing that it does it's best to pick the highest plus arrow.
1363 */ 1301 */
1364object * 1302object *
1365find_better_arrow (object *op, object *target, const char *type, int *better) 1303find_better_arrow (object *op, object *target, shstr_cmp type, int *better)
1366{ 1304{
1367 object *tmp = NULL, *arrow, *ntmp; 1305 object *tmp = NULL, *arrow, *ntmp;
1368 int attacknum, attacktype, betterby = 0, i; 1306 int attacknum, attacktype, betterby = 0, i;
1369 1307
1370 if (!type) 1308 if (!type)
1374 { 1312 {
1375 if (arrow->type == CONTAINER && arrow->race == type && QUERY_FLAG (arrow, FLAG_APPLIED)) 1313 if (arrow->type == CONTAINER && arrow->race == type && QUERY_FLAG (arrow, FLAG_APPLIED))
1376 { 1314 {
1377 i = 0; 1315 i = 0;
1378 ntmp = find_better_arrow (arrow, target, type, &i); 1316 ntmp = find_better_arrow (arrow, target, type, &i);
1317
1379 if (i > betterby) 1318 if (i > betterby)
1380 { 1319 {
1381 tmp = ntmp; 1320 tmp = ntmp;
1382 betterby = i; 1321 betterby = i;
1383 } 1322 }
1384 } 1323 }
1385 else if (arrow->type == ARROW && arrow->race == type) 1324 else if (arrow->type == ARROW && arrow->race == type)
1386 { 1325 {
1387 /* allways prefer assasination/slaying */ 1326 /* allways prefer assasination/slaying */
1388 if (target->race && arrow->slaying && strstr (arrow->slaying, target->race)) 1327 if (target->race && arrow->slaying.contains (target->race))
1389 { 1328 {
1390 if (arrow->attacktype & AT_DEATH) 1329 if (arrow->attacktype & AT_DEATH)
1391 { 1330 {
1392 *better = 100; 1331 *better = 100;
1393 return arrow; 1332 return arrow;
1408 { 1347 {
1409 tmp = arrow; 1348 tmp = arrow;
1410 betterby = (arrow->magic + arrow->stats.dam) * (100 - target->arch->resist[attacknum]) / 100; 1349 betterby = (arrow->magic + arrow->stats.dam) * (100 - target->arch->resist[attacknum]) / 100;
1411 } 1350 }
1412 } 1351 }
1352
1413 if ((2 + arrow->magic + arrow->stats.dam) > betterby) 1353 if ((2 + arrow->magic + arrow->stats.dam) > betterby)
1414 { 1354 {
1415 tmp = arrow; 1355 tmp = arrow;
1416 betterby = 2 + arrow->magic + arrow->stats.dam; 1356 betterby = 2 + arrow->magic + arrow->stats.dam;
1417 } 1357 }
1358
1418 if (arrow->title && (1 + arrow->magic + arrow->stats.dam) > betterby) 1359 if (arrow->title && (1 + arrow->magic + arrow->stats.dam) > betterby)
1419 { 1360 {
1420 tmp = arrow; 1361 tmp = arrow;
1421 betterby = 1 + arrow->magic + arrow->stats.dam; 1362 betterby = 1 + arrow->magic + arrow->stats.dam;
1422 } 1363 }
1436 * op = the shooter 1377 * op = the shooter
1437 * type = bow->race 1378 * type = bow->race
1438 * dir = fire direction 1379 * dir = fire direction
1439 */ 1380 */
1440object * 1381object *
1441pick_arrow_target (object *op, const char *type, int dir) 1382pick_arrow_target (object *op, shstr_cmp type, int dir)
1442{ 1383{
1443 object *tmp = NULL; 1384 object *tmp = NULL;
1444 maptile *m; 1385 maptile *m;
1445 int i, mflags, found, number; 1386 int i, mflags, found, number;
1446 sint16 x, y; 1387 sint16 x, y;
1461 for (i = 0, found = 0; i < 20; i++) 1402 for (i = 0, found = 0; i < 20; i++)
1462 { 1403 {
1463 x += freearr_x[dir]; 1404 x += freearr_x[dir];
1464 y += freearr_y[dir]; 1405 y += freearr_y[dir];
1465 mflags = get_map_flags (m, &m, x, y, &x, &y); 1406 mflags = get_map_flags (m, &m, x, y, &x, &y);
1407
1466 if (mflags & P_OUT_OF_MAP || mflags & P_BLOCKSVIEW) 1408 if (mflags & P_OUT_OF_MAP || mflags & P_BLOCKSVIEW)
1467 { 1409 {
1468 tmp = NULL; 1410 tmp = 0;
1469 break; 1411 break;
1470 } 1412 }
1471 else if (GET_MAP_MOVE_BLOCK (m, x, y) == MOVE_FLY_LOW) 1413 else if (GET_MAP_MOVE_BLOCK (m, x, y) == MOVE_FLY_LOW)
1472 { 1414 {
1473 /* This block presumes arrows and the like are MOVE_FLY_SLOW - 1415 /* This block presumes arrows and the like are MOVE_FLY_SLOW -
1474 * perhaps a bad assumption. 1416 * perhaps a bad assumption.
1475 */ 1417 */
1476 tmp = NULL; 1418 tmp = 0;
1477 break; 1419 break;
1478 } 1420 }
1421
1479 if (mflags & P_IS_ALIVE) 1422 if (mflags & P_IS_ALIVE)
1480 {
1481 for (tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above) 1423 for (tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above)
1482 if (QUERY_FLAG (tmp, FLAG_ALIVE)) 1424 if (QUERY_FLAG (tmp, FLAG_ALIVE))
1483 {
1484 found++;
1485 break;
1486 }
1487 if (found)
1488 break; 1425 break;
1489 }
1490 } 1426 }
1491 if (tmp == NULL) 1427
1428 if (!tmp)
1492 return find_arrow (op, type); 1429 return find_arrow (op, type);
1493 1430
1494 if (tmp->head) 1431 if (tmp->head)
1495 tmp = tmp->head; 1432 tmp = tmp->head;
1496 1433
1541 if (bow->below) 1478 if (bow->below)
1542 { 1479 {
1543 bow->remove (); 1480 bow->remove ();
1544 op->insert (bow); 1481 op->insert (bow);
1545 } 1482 }
1546
1547 } 1483 }
1548 1484
1549 if (!bow->race || !bow->skill) 1485 if (!bow->race || !bow->skill)
1550 { 1486 {
1551 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s is broken.", &bow->name); 1487 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s is broken.", &bow->name);
1577 } 1513 }
1578 1514
1579 /* this should not happen, but sometimes does */ 1515 /* this should not happen, but sometimes does */
1580 if (arrow->nrof == 0) 1516 if (arrow->nrof == 0)
1581 { 1517 {
1518 LOG (llevError | logBacktrace, "arrow (%s) has nrof 0\n", arrow->debug_desc ());
1582 arrow->destroy (); 1519 arrow->destroy ();
1583 return 0; 1520 return 0;
1584 } 1521 }
1585 1522
1586 left = arrow; /* these are arrows left to the player */ 1523 left = arrow; /* these are arrows left to the player */
1673 * hence the function name. 1610 * hence the function name.
1674 */ 1611 */
1675int 1612int
1676player_fire_bow (object *op, int dir) 1613player_fire_bow (object *op, int dir)
1677{ 1614{
1678 int ret = 0, wcmod = 0; 1615 int ret;
1679 1616
1680 if (op->contr->bowtype == bow_bestarrow) 1617 if (op->contr->bowtype == bow_bestarrow)
1681 { 1618 {
1682 ret = fire_bow (op, op, pick_arrow_target (op, op->contr->ranged_ob->race, dir), dir, 0, op->x, op->y); 1619 ret = fire_bow (op, op, pick_arrow_target (op, op->contr->ranged_ob->race, dir), dir, 0, op->x, op->y);
1683 } 1620 }
1684 else if (op->contr->bowtype >= bow_n && op->contr->bowtype <= bow_nw) 1621 else if (op->contr->bowtype >= bow_n && op->contr->bowtype <= bow_nw)
1685 { 1622 {
1686 if (!similar_direction (dir, op->contr->bowtype - bow_n + 1)) 1623 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); 1624 ret = fire_bow (op, op, NULL, op->contr->bowtype - bow_n + 1, wcmod, op->x, op->y);
1690 } 1625 }
1691 else if (op->contr->bowtype == bow_threewide) 1626 else if (op->contr->bowtype == bow_threewide)
1692 { 1627 {
1693 ret = fire_bow (op, op, NULL, dir, 0, op->x, op->y); 1628 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)]); 1629 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)]); 1630 ret |= fire_bow (op, op, NULL, dir, -5, op->x + freearr_x[absdir (dir - 2)], op->y + freearr_y[absdir (dir - 2)]);
1696 } 1631 }
1697 else if (op->contr->bowtype == bow_spreadshot) 1632 else if (op->contr->bowtype == bow_spreadshot)
1698 { 1633 {
1699 ret |= fire_bow (op, op, NULL, dir, 0, op->x, op->y); 1634 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); 1635 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); 1636 ret |= fire_bow (op, op, NULL, absdir (dir + 1), -5, op->x, op->y);
1702 } 1637 }
1703 else 1638 else
1704 { 1639 {
1761 } 1696 }
1762 } 1697 }
1763 1698
1764 if (cast_spell (op, item, dir, item->inv, NULL)) 1699 if (cast_spell (op, item, dir, item->inv, NULL))
1765 { 1700 {
1766 SET_FLAG (op, FLAG_BEEN_APPLIED); /* You now know something about it */ 1701 item->flag [FLAG_BEEN_APPLIED] = true; /* You now know something about it */
1702
1767 if (item->type == WAND) 1703 if (item->type == WAND)
1768 { 1704 {
1769 if (!(--item->stats.food)) 1705 if (!(--item->stats.food))
1770 { 1706 {
1771 object *tmp; 1707 object *tmp;
1791bool 1727bool
1792fire (object *op, int dir) 1728fire (object *op, int dir)
1793{ 1729{
1794 int spellcost = 0; 1730 int spellcost = 0;
1795 1731
1796 /* check for loss of invisiblity/hide */
1797 if (action_makes_visible (op))
1798 make_visible (op);
1799
1800 player *pl = op->contr; 1732 player *pl = op->contr;
1801 1733
1802 if (pl->golem) 1734 if (pl->golem)
1803 { 1735 {
1804 control_golem (op->contr->golem, dir); 1736 control_golem (op->contr->golem, dir);
1806 } 1738 }
1807 1739
1808 object *ob = pl->ranged_ob; 1740 object *ob = pl->ranged_ob;
1809 1741
1810 if (!ob) 1742 if (!ob)
1811 return false;
1812
1813 if (!op->change_weapon (ob))
1814 return false; 1743 return false;
1815 1744
1816 if (op->speed_left > 0.f) 1745 if (op->speed_left > 0.f)
1817 --op->speed_left; 1746 --op->speed_left;
1818 else 1747 else
1819 return false; 1748 return false;
1749
1750 if (!op->change_weapon (ob))
1751 return false;
1752
1753 /* check for loss of invisiblity/hide */
1754 if (action_makes_visible (op))
1755 make_visible (op);
1820 1756
1821 switch (ob->type) 1757 switch (ob->type)
1822 { 1758 {
1823 case BOW: 1759 case BOW:
1824 player_fire_bow (op, dir); 1760 player_fire_bow (op, dir);
1917 * Change the color so that the message doesn't disappear with 1853 * Change the color so that the message doesn't disappear with
1918 * all the others. 1854 * all the others.
1919 */ 1855 */
1920 if (pl->contr->usekeys == key_inventory || 1856 if (pl->contr->usekeys == key_inventory ||
1921 !QUERY_FLAG (container, FLAG_APPLIED) || 1857 !QUERY_FLAG (container, FLAG_APPLIED) ||
1922 (pl->contr->usekeys == keyrings && (!container->race || strcmp (container->race, "keys")))) 1858 (pl->contr->usekeys == keyrings && container->race != shstr_keys))
1923 { 1859 {
1924 new_draw_info_format (NDI_UNIQUE | NDI_BROWN, 0, pl, 1860 new_draw_info_format (NDI_UNIQUE | NDI_BROWN, 0, pl,
1925 "The %s in your %s vibrates as you approach the door", query_name (tmp), query_name (container)); 1861 "The %s in your %s vibrates as you approach the door", query_name (tmp), query_name (container));
1926 return NULL; 1862 return NULL;
1927 } 1863 }
2069 --op->speed_left; 2005 --op->speed_left;
2070 2006
2071 op->play_sound (sound_find ("push_player")); 2007 op->play_sound (sound_find ("push_player"));
2072 push_ob (mon, dir, op); 2008 push_ob (mon, dir, op);
2073 2009
2074 if (op->contr->tmp_invis || op->hide) 2010 if (action_makes_visible (op))
2075 make_visible (op); 2011 make_visible (op);
2076 2012
2077 return true; 2013 return true;
2078 } 2014 }
2079 else 2015 else
2101 push_ob (mon, dir, op); 2037 push_ob (mon, dir, op);
2102 } 2038 }
2103 else 2039 else
2104 op->statusmsg ("You withhold your attack"); 2040 op->statusmsg ("You withhold your attack");
2105 2041
2106 if (op->contr->tmp_invis || op->hide) 2042 if (op->contr->tmp_invis || op->flag [FLAG_HIDDEN])
2107 make_visible (op); 2043 make_visible (op);
2108 2044
2109 return true; 2045 return true;
2110 } 2046 }
2111 } 2047 }
2169 if (QUERY_FLAG (op, FLAG_CONFUSED) && dir) 2105 if (QUERY_FLAG (op, FLAG_CONFUSED) && dir)
2170 dir = absdir (dir + rndm (3) + rndm (3) - 2); 2106 dir = absdir (dir + rndm (3) + rndm (3) - 2);
2171 2107
2172 op->facing = dir; 2108 op->facing = dir;
2173 2109
2174 if (op->hide) 2110 if (op->flag [FLAG_HIDDEN])
2175 do_hidden_move (op); 2111 do_hidden_move (op);
2176 2112
2177 bool retval; 2113 bool retval;
2178 2114
2179 if (INVOKE_PLAYER (MOVE, op->contr, ARG_INT (dir))) 2115 if (INVOKE_PLAYER (MOVE, op->contr, ARG_INT (dir)))
2310const char * 2246const char *
2311gravestone_text (object *op) 2247gravestone_text (object *op)
2312{ 2248{
2313 static dynbuf_text buf; 2249 static dynbuf_text buf;
2314 2250
2315 buf << "---- R.I.P. ----\n\n"; 2251 buf << "---- R.I.P. ----\n\n"
2316 op->name; 2252 << op->name;
2317 2253
2318 if (op->type == PLAYER) 2254 if (op->type == PLAYER)
2319 buf << " the " << op->contr->title; 2255 buf << " the " << op->contr->title;
2320 2256
2321 buf << "\n\n"; 2257 buf << "\n\n";
2497 { 2433 {
2498 over_hp = (gen_hp < 20 ? 30 : gen_hp + 10) / rate_hp; 2434 over_hp = (gen_hp < 20 ? 30 : gen_hp + 10) / rate_hp;
2499 2435
2500 if (over_hp > 0) 2436 if (over_hp > 0)
2501 { 2437 {
2502 op->stats.sp += over_hp + (RANDOM () % rate_hp > ((gen_hp < 20 ? 30 : gen_hp + 10) % rate_hp)) ? -1 : 0; 2438 op->stats.sp += over_hp + (rndm (rate_hp) > ((gen_hp < 20 ? 30 : gen_hp + 10) % rate_hp)) ? -1 : 0;
2503 op->last_heal = 0; 2439 op->last_heal = 0;
2504 } 2440 }
2505 else 2441 else
2506 op->last_heal = rate_hp / (gen_hp < 20 ? 30 : gen_hp + 10); 2442 op->last_heal = rate_hp / (gen_hp < 20 ? 30 : gen_hp + 10);
2507 } 2443 }
2563 2499
2564 if (op->stats.food < 0) 2500 if (op->stats.food < 0)
2565 { 2501 {
2566 op->stats.hp += op->stats.food; 2502 op->stats.hp += op->stats.food;
2567 op->stats.food = 0; 2503 op->stats.food = 0;
2504
2505 if (op->stats.hp < 0)
2506 {
2507 op->contr->killer = archetype::get ("killer_starvation");
2508 op->contr->killer->destroy ();
2568 } 2509 }
2510 }
2569 2511
2512 /* killer should be set here already */
2570 if (op->stats.hp < 0 && !QUERY_FLAG (op, FLAG_WIZ)) 2513 if (op->stats.hp < 0 && !QUERY_FLAG (op, FLAG_WIZ))
2571 kill_player (op); 2514 kill_player (op);
2572 } 2515 }
2573} 2516}
2574 2517
2579 */ 2522 */
2580void 2523void
2581kill_player (object *op) 2524kill_player (object *op)
2582{ 2525{
2583 int x, y; 2526 int x, y;
2584 char buf[MAX_BUF];
2585 maptile *map; /* this is for resurrection */ 2527 maptile *map; /* this is for resurrection */
2586 int will_kill_again; 2528 int will_kill_again;
2587 archetype *at; 2529 archetype *at;
2588 object *tmp; 2530 object *tmp;
2589 2531
2590 if (save_life (op)) 2532 if (save_life (op))
2591 return; 2533 return;
2534
2535 dynbuf_text deathtab;
2536
2537 /* restore player */
2538 at = archetype::find ("poisoning");
2539 if (object *tmp = present_arch_in_ob (at, op))
2540 {
2541 tmp->destroy ();
2542 deathtab << "Your body feels cleansed...\r";
2543 }
2544
2545 at = archetype::find ("confusion");
2546 if (object *tmp = present_arch_in_ob (at, op))
2547 {
2548 tmp->destroy ();
2549 deathtab << "Your mind feels clearer...\r";
2550 }
2551
2552 cure_disease (op, 0, 0); /* remove any disease */
2553
2554 max_it (op->stats.hp , op->stats.maxhp);
2555 max_it (op->stats.sp , op->stats.maxsp);
2556 max_it (op->stats.grace, op->stats.maxgrace);
2557
2558 if (op->stats.food <= 0)
2559 op->stats.food = 999;
2560
2561 // remove all spell effects that are active
2562 // to avoid long-term effects such as word-of-recall
2563 for (object *item = op->inv; item; )
2564 {
2565 object *next = item->below;
2566
2567 if (item->type == SPELL_EFFECT && item->active)
2568 item->destroy ();
2569
2570 item = next;
2571 }
2592 2572
2593 /* If player dies on BATTLEGROUND, no stat/exp loss! For Combat-Arenas 2573 /* 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. 2574 * in cities ONLY!!! It is very important that this doesn't get abused.
2595 * Look at op_on_battleground() for more info --AndreasV 2575 * Look at op_on_battleground() for more info --AndreasV
2596 */ 2576 */
2597 if (op_on_battleground (op, &x, &y)) 2577 if (op_on_battleground (op, &x, &y))
2598 { 2578 {
2599 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, "You have been defeated in combat!"); 2579 deathtab << "You almost died in combat, but local medics have saved your life...\r";
2600 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 2580
2622 /* create a bodypart-trophy to make the winner happy */ 2581 /* create a bodypart-trophy to make the winner happy */
2623 if (object *tmp = arch_to_object (archetype::find ("finger"))) 2582 if (object *tmp = arch_to_object (archetype::find ("finger")))
2624 { 2583 {
2625 tmp->name = format ("%s's finger" , &op->name); 2584 tmp->name = format ("%s's finger" , &op->name);
2636 } 2595 }
2637 2596
2638 /* teleport defeated player to new destination */ 2597 /* teleport defeated player to new destination */
2639 transfer_ob (op, x, y, 0, NULL); 2598 transfer_ob (op, x, y, 0, NULL);
2640 op->contr->braced = 0; 2599 op->contr->braced = 0;
2600
2601 op->contr->infobox (MSG_CHANNEL ("death"), deathtab);
2641 return; 2602 return;
2642 } 2603 }
2643 2604
2605 deathtab << "You were killed by " << op->contr->killer_name () << ".\n\n";
2606 deathtab << "T<YOU HAVE DIED>\n\n";
2607
2644 INVOKE_PLAYER (DEATH, op->contr); 2608 INVOKE_PLAYER (DEATH, op->contr);
2645 2609
2646 command_kill_pets (op, 0); 2610 command_kill_pets (op, 0);
2647
2648 if (op->stats.food < 0)
2649 {
2650 op->contr->killer = archetype::get ("killer_starvation");
2651 op->contr->killer->destroy ();
2652 }
2653 2611
2654 op->contr->play_sound (sound_find ("player_dies")); 2612 op->contr->play_sound (sound_find ("player_dies"));
2655 2613
2656 /* save the map location for corpse, gravestone */ 2614 /* save the map location for corpse, gravestone */
2657 x = op->x; 2615 x = op->x;
2687 2645
2688 lost_a_stat = 0; 2646 lost_a_stat = 0;
2689 2647
2690 for (z = 0; z < num_stats_lose; z++) 2648 for (z = 0; z < num_stats_lose; z++)
2691 { 2649 {
2692 i = RANDOM () % NUM_STATS; 2650 i = rndm (NUM_STATS);
2693 2651
2694 if (settings.stat_loss_on_death) 2652 if (settings.stat_loss_on_death)
2695 { 2653 {
2696 /* Pick a random stat and take a point off it. Tell the player 2654 /* Pick a random stat and take a point off it. Tell the player
2697 * what he lost. 2655 * what he lost.
2748 } 2706 }
2749 } 2707 }
2750 2708
2751 if (lose_this_stat) 2709 if (lose_this_stat)
2752 { 2710 {
2753 this_stat = get_attr_value (&(dep->stats), i); 2711 this_stat = get_attr_value (&dep->stats, i);
2754 /* We could try to do something clever like find another 2712 /* We could try to do something clever like find another
2755 * stat to reduce if this fails. But chances are, if 2713 * stat to reduce if this fails. But chances are, if
2756 * stats have been depleted to -50, all are pretty low 2714 * stats have been depleted to -50, all are pretty low
2757 * and should be roughly the same, so it shouldn't make a 2715 * and should be roughly the same, so it shouldn't make a
2758 * difference. 2716 * difference.
2772 /* If no stat lost, tell the player. */ 2730 /* If no stat lost, tell the player. */
2773 if (!lost_a_stat) 2731 if (!lost_a_stat)
2774 { 2732 {
2775 /* determine_god() seems to not work sometimes... why is this? 2733 /* determine_god() seems to not work sometimes... why is this?
2776 Should I be using something else? GD */ 2734 Should I be using something else? GD */
2777 const char *god = determine_god (op); 2735 shstr_tmp god = determine_god (op);
2778 2736
2779 if (god && (strcmp (god, "none"))) 2737 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); 2738 deathtab << "For a brief moment you feel the holy presence of " << god << " protecting you.\r";
2781 else 2739 else
2782 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you feel a holy presence protecting you."); 2740 deathtab << "For a brief moment you feel a holy presence protecting you.\r";
2783 } 2741 }
2784#else 2742#else
2785 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you feel a holy presence protecting you from losing yourself completely."); 2743 deathtab << "For a brief moment you feel a holy presence protecting you from losing yourself completely.";
2786#endif 2744#endif
2787 2745
2788 /* Put a gravestone up where the character 'almost' died. List the 2746 /* Put a gravestone up where the character 'almost' died. List the
2789 * exp loss on the stone. 2747 * exp loss on the stone.
2790 */ 2748 */
2791 tmp = arch_to_object (archetype::find ("gravestone")); 2749 tmp = arch_to_object (archetype::find ("gravestone"));
2792 tmp->name = format ("%s's gravestone", &op->name); 2750 tmp->name = format ("%s's gravestone", &op->name);
2793 tmp->name_pl = format ("%s's gravestones", &op->name); 2751 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 ()); 2752 tmp->msg = format ("T<RIP>\n\nHere rests the hero %s the %s,\rwho was killed\rby %s.\n",
2753 &op->name, op->contr->title, op->contr->killer_name ());
2795 tmp->x = op->x, tmp->y = op->y; 2754 tmp->x = op->x, tmp->y = op->y;
2796 insert_ob_in_map (tmp, op->map, NULL, 0); 2755 insert_ob_in_map (tmp, op->map, NULL, 0);
2797 2756
2798 /**************************************/ 2757 /**************************************/
2799 /* */ 2758 /* */
2800 /* Subtract the experience points, */ 2759 /* Subtract the experience points, */
2801 /* if we died cause of food, give us */
2802 /* food, and reset HP's... */
2803 /* */ 2760 /* */
2804 /**************************************/ 2761 /**************************************/
2805 2762
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)); */ 2763 /*add_exp(op, (op->stats.exp * -0.20)); */
2840 apply_death_exp_penalty (op); 2764 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 2765
2849 /* 2766 /*
2850 * Check to see if the player has any unpaid items. If so, remove them 2767 * Check to see if the player has any unpaid items. If so, remove them
2851 * and put them back in the map. 2768 * and put them back in the map.
2852 */ 2769 */
2887 if (will_kill_again & (1 << at)) 2804 if (will_kill_again & (1 << at))
2888 force->resist[at] = 100; 2805 force->resist[at] = 100;
2889 2806
2890 insert_ob_in_ob (force, op); 2807 insert_ob_in_ob (force, op);
2891 op->update_stats (); 2808 op->update_stats ();
2892
2893 } 2809 }
2894 2810
2895 new_draw_info (NDI_UNIQUE, 0, op, "YOU HAVE DIED."); 2811 op->contr->infobox (MSG_CHANNEL ("death"), deathtab);
2896} 2812}
2897 2813
2898void 2814void
2899loot_object (object *op) 2815loot_object (object *op)
2900{ /* Grab and destroy some treasure */ 2816{ /* Grab and destroy some treasure */
2998} 2914}
2999 2915
3000void 2916void
3001make_visible (object *op) 2917make_visible (object *op)
3002{ 2918{
3003 op->hide = 0; 2919 op->flag [FLAG_HIDDEN] = 0;
3004 op->invisible = 0; 2920 op->invisible = 0;
3005 2921
3006 if (op->type == PLAYER) 2922 if (op->type == PLAYER)
3007 { 2923 {
3008 op->contr->tmp_invis = 0; 2924 op->contr->tmp_invis = 0;
3033 2949
3034 if (!ob || !ob->map) 2950 if (!ob || !ob->map)
3035 return 0; 2951 return 0;
3036 2952
3037 /* so, on normal lighted maps, its hard to hide */ 2953 /* so, on normal lighted maps, its hard to hide */
3038 level = ob->map->darkness - 2; 2954 level = ob->map->darklevel () - 2;
3039 2955
3040 /* this also picks up whether the object is glowing. 2956 /* this also picks up whether the object is glowing.
3041 * If you carry a light on a non-dark map, its not 2957 * If you carry a light on a non-dark map, its not
3042 * as bad as carrying a light on a pitch dark map */ 2958 * as bad as carrying a light on a pitch dark map */
3043 if (has_carried_lights (ob)) 2959 if (ob->has_carried_lights ())
3044 level = -(10 + (2 * ob->map->darkness)); 2960 level = -(10 + (2 * ob->map->darklevel ()));
3045 2961
3046 /* scan through all nearby squares for terrain to hide in */ 2962 /* scan through all nearby squares for terrain to hide in */
3047 for (i = 0, x = ob->x, y = ob->y; 2963 for (i = 0, x = ob->x, y = ob->y;
3048 i <= SIZEOFFREE1; 2964 i <= SIZEOFFREE1;
3049 i++, x = ob->x + freearr_x[i], y = ob->y + freearr_y[i]) 2965 i++, x = ob->x + freearr_x[i], y = ob->y + freearr_y[i])
3196 while (op) 3112 while (op)
3197 { 3113 {
3198 dx = rv.distance_x + op->arch->x; 3114 dx = rv.distance_x + op->arch->x;
3199 dy = rv.distance_y + op->arch->y; 3115 dy = rv.distance_y + op->arch->y;
3200 3116
3201 /* only the viewable area the player sees is updated by LOS 3117 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; 3118 return 1;
3209 3119
3210 op = op->more; 3120 op = op->more;
3211 } 3121 }
3212 3122
3213 return 0; 3123 return 0;
3214} 3124}
3215 3125
3216/* routine for both players and monsters. We call this when 3126/* routine for both players and monsters. We call this when
3217 * there is a possibility for our action distrubing our hiding 3127 * there is a possibility for our action distrubing our hiding
3218 * place or invisiblity spell. Artefact invisiblity is not 3128 * place or invisiblity spell. Artefact invisiblity causes
3219 * effected by this. If we arent invisible to begin with, we 3129 * "noise" instead. If we arent invisible to begin with, we
3220 * return 0. 3130 * return 0.
3221 */ 3131 */
3222int 3132int
3223action_makes_visible (object *op) 3133action_makes_visible (object *op)
3224{ 3134{
3225 if (op->invisible && QUERY_FLAG (op, FLAG_ALIVE)) 3135 if (op->invisible && QUERY_FLAG (op, FLAG_ALIVE))
3226 { 3136 {
3227 if (QUERY_FLAG (op, FLAG_MAKE_INVIS)) 3137 if (QUERY_FLAG (op, FLAG_MAKE_INVIS))
3138 {
3139 // artefact invisibility is permanent, but we still make noise
3140 // this is important for game-balance.
3141 if (op->contr)
3142 op->make_noise ();
3143
3228 return 0; 3144 return 0;
3145 }
3229 3146
3230 if (op->contr && op->contr->tmp_invis == 0) 3147 if (op->contr && op->contr->tmp_invis == 0)
3231 return 0; 3148 return 0;
3232 3149
3233 /* If monsters, they should become visible */ 3150 /* If monsters, they should become visible */
3234 if (op->hide || !op->contr || (op->contr && op->contr->tmp_invis)) 3151 if (op->flag [FLAG_HIDDEN] || !op->contr || (op->contr && op->contr->tmp_invis))
3235 { 3152 {
3236 new_draw_info_format (NDI_UNIQUE, 0, op, "You become %s!", op->hide ? "unhidden" : "visible"); 3153 new_draw_info_format (NDI_UNIQUE, 0, op, "You become %s!", op->flag [FLAG_HIDDEN] ? "unhidden" : "visible");
3237 return 1; 3154 return 1;
3238 } 3155 }
3239 } 3156 }
3240 3157
3241 return 0; 3158 return 0;
3469 if (pl->ranged_ob == ob) 3386 if (pl->ranged_ob == ob)
3470 pl->ranged_ob = 0; 3387 pl->ranged_ob = 0;
3471} 3388}
3472 3389
3473sint8 3390sint8
3474player::visibility_at (maptile *map, int x, int y) const 3391player::darkness_at (maptile *map, int x, int y) const
3475{ 3392{
3476 if (!ns) 3393 if (!ns)
3477 return 0; 3394 return LOS_BLOCKED;
3478 3395
3479 int dx, dy; 3396 int dx, dy;
3480 if (!adjacent_map (map, ns->current_map, &dx, &dy)) 3397 if (!adjacent_map (map, ns->current_map, &dx, &dy))
3481 return 0; 3398 return LOS_BLOCKED;
3482 3399
3483 x += dx - ns->current_x + ns->mapx / 2; 3400 x += dx - ns->current_x;
3484 y += dy - ns->current_y + ns->mapy / 2; 3401 y += dy - ns->current_y;
3485 3402
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]; 3403 return blocked_los (x, y);
3490} 3404}
3491 3405
3492void 3406void
3493player::infobox (const char *title, const char *msg, int color) 3407player::infobox (const char *title, const char *msg, int color)
3494{ 3408{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines