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.231 by root, Sat Oct 3 18:46:26 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;
671 op->destroy (); 673 op->destroy ();
672 continue; 674 continue;
673 } 675 }
674 } 676 }
675 677
676 /* This really needs to be better - we should really give 678 /* Here we remove duplicated skills (as duplicated spell objects have
677 * a substitute spellbook. The problem is that we don't really 679 * _very_ confusing effects for players), which could for instance be
678 * have a good idea what to replace it with (need something like 680 * generated by bad treasurelists. - elmex
679 * a first level treasurelist for each skill.)
680 * remove duplicate skills also
681 */ 681 */
682 if (op->type == SPELLBOOK || op->type == SKILL) 682 if (op->type == SKILL)
683 { 683 {
684 object *tmp;
685
686 for (tmp = op->below; tmp; tmp = tmp->below) 684 for (object *tmp = op->below; tmp; tmp = tmp->below)
687 if (tmp->type == op->type && tmp->name == op->name) 685 if (tmp->type == op->type && tmp->name == op->name)
688 break;
689
690 if (tmp)
691 { 686 {
692 op->destroy (); 687 op->destroy ();
688 LOG (llevError,
693 LOG (llevError, "give_initial_items: Removing duplicate object %s\n", &tmp->name); 689 "give_initial_items: Removing duplicate skill %s\n", &tmp->name);
694 continue; 690 break;
695 } 691 }
696 692
697 if (op->nrof > 1) 693 if (op->nrof > 1)
698 op->nrof = 1; 694 op->nrof = 1;
699 } 695 }
700 696
726 else /* lock all 'normal items by default */ 722 else /* lock all 'normal items by default */
727 SET_FLAG (op, FLAG_INV_LOCKED); 723 SET_FLAG (op, FLAG_INV_LOCKED);
728 } /* for loop of objects in player inv */ 724 } /* for loop of objects in player inv */
729 725
730 /* Need to set up the skill pointers */ 726 /* Need to set up the skill pointers */
731 link_player_skills (pl); 727 pl->contr->link_skills ();
732} 728}
733 729
734void 730void
735get_party_password (object *op, partylist *party) 731get_party_password (object *op, partylist *party)
736{ 732{
868 ob->msg = 0; 864 ob->msg = 0;
869 865
870 start_info (ob); 866 start_info (ob);
871 CLEAR_FLAG (ob, FLAG_WIZ); 867 CLEAR_FLAG (ob, FLAG_WIZ);
872 give_initial_items (ob, ob->randomitems); 868 give_initial_items (ob, ob->randomitems);
873 link_player_skills (ob);
874 esrv_send_inventory (ob, ob); 869 esrv_send_inventory (ob, ob);
875 ob->update_stats (); 870 ob->update_stats ();
876 871
877 /* This moves the player to a different start map, if there 872 /* This moves the player to a different start map, if there
878 * is one for this race 873 * is one for this race
930 LOG (llevDebug, "Fleeing player is dead.\n"); 925 LOG (llevDebug, "Fleeing player is dead.\n");
931 CLEAR_FLAG (op, FLAG_SCARED); 926 CLEAR_FLAG (op, FLAG_SCARED);
932 return; 927 return;
933 } 928 }
934 929
935 if (op->enemy == NULL) 930 if (!op->enemy)
936 { 931 {
937 LOG (llevDebug, "Fleeing player had no enemy.\n"); 932 LOG (llevDebug, "Fleeing player had no enemy.\n");
938 CLEAR_FLAG (op, FLAG_SCARED); 933 CLEAR_FLAG (op, FLAG_SCARED);
939 return; 934 return;
940 } 935 }
941 936
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)) 937 if (!(random_roll (0, 4, op, PREFER_LOW)) && did_make_save (op, op->level, 0))
954 { 938 {
955 op->enemy = NULL; 939 op->enemy = NULL;
956 CLEAR_FLAG (op, FLAG_SCARED); 940 CLEAR_FLAG (op, FLAG_SCARED);
957 return; 941 return;
960 get_rangevector (op, op->enemy, &rv, 0); 944 get_rangevector (op, op->enemy, &rv, 0);
961 945
962 dir = absdir (4 + rv.direction); 946 dir = absdir (4 + rv.direction);
963 for (diff = 0; diff < 3; diff++) 947 for (diff = 0; diff < 3; diff++)
964 { 948 {
965 int m = 1 - (RANDOM () & 2); 949 int m = 1 - rndm (2) * 2;
966 950
967 if (move_ob (op, absdir (dir + diff * m), op) || (diff == 0 && move_ob (op, absdir (dir - diff * m), op))) 951 if (move_ob (op, absdir (dir + diff * m), op) || (diff == 0 && move_ob (op, absdir (dir - diff * m), op)))
968 return; 952 return;
969 } 953 }
970 954
981check_pick (object *op) 965check_pick (object *op)
982{ 966{
983 object *tmp, *next; 967 object *tmp, *next;
984 int stop = 0; 968 int stop = 0;
985 int wvratio; 969 int wvratio;
986 char putstring[128];
987 970
988 /* if you're flying, you cna't pick up anything */ 971 /* if you're flying, you cna't pick up anything */
989 if (op->move_type & MOVE_FLYING) 972 if (op->move_type & MOVE_FLYING)
990 return 1; 973 return 1;
991 974
1015 998
1016 if (op->contr->search_str[0] != '\0' && settings.search_items == TRUE) 999 if (op->contr->search_str[0] != '\0' && settings.search_items == TRUE)
1017 { 1000 {
1018 if (item_matched_string (op, tmp, op->contr->search_str)) 1001 if (item_matched_string (op, tmp, op->contr->search_str))
1019 CHK_PICK_PICKUP; 1002 CHK_PICK_PICKUP;
1003
1020 continue; 1004 continue;
1021 } 1005 }
1022 1006
1023 /* high not bit set? We're using the old autopickup model */ 1007 /* pickup handling */
1008 if (op->contr->mode & PU_DEBUG)
1009 {
1010 /* some debugging code to figure out item information */
1011 const char *str = tmp->name
1012 ? format ("item name: %s item type: %d weight/value: %d",
1013 &tmp->name, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))))
1014 : format ("item name: %s item type: %d weight/value: %d",
1015 &tmp->arch->archname, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))));
1016
1017 new_draw_info (NDI_UNIQUE, 0, op, str);
1018 }
1019
1020 if (op->contr->mode & PU_INHIBIT)
1021 return 1;
1022
1023 if (!(op->contr->mode & PU_ENABLE)) // TODO: fix client
1024 return 1;
1025
1026 /* philosophy:
1027 * It's easy to grab an item type from a pile, as long as it's
1028 * generic. This takes no game-time. For more detailed pickups
1029 * and selections, select-items should be used. This is a
1030 * grab-as-you-run type mode that's really useful for arrows for
1031 * example.
1032 * The drawback: right now it has no frontend, so you need to
1033 * stick the bits you want into a calculator in hex mode and then
1034 * convert to decimal and then 'pickup <#>
1035 */
1036
1037 /* the first two modes are exclusive: if NOTHING we return, if
1038 * STOP then we stop. All the rest are applied sequentially,
1039 * meaning if any test passes, the item gets picked up. */
1040
1041 /* if mode is set to pick nothing up, return */
1042 if (op->contr->mode == PU_NOTHING)
1043 return 1;
1044
1045 /* if mode is set to stop when encountering objects, return */
1046 /* take STOP before INHIBIT since it doesn't actually pick
1047 * anything up */
1048 if (op->contr->mode & PU_STOP)
1049 return 0;
1050
1051 /* useful for going into stores and not losing your settings... */
1052 /* and for battles wher you don't want to get loaded down while
1053 * fighting */
1054 if (op->contr->mode & PU_INHIBIT)
1055 return 1;
1056
1057 /* prevent us from turning into auto-thieves :) */
1058 if (QUERY_FLAG (tmp, FLAG_UNPAID))
1059 continue;
1060
1061 /* ignore known cursed objects */
1062 if (QUERY_FLAG (tmp, FLAG_KNOWN_CURSED) && op->contr->mode & PU_NOT_CURSED)
1063 continue;
1064
1065 /* all food and drink if desired */
1066 /* question: don't pick up known-poisonous stuff? */
1024 if (!(op->contr->mode & PU_NEWMODE)) 1067 if (op->contr->mode & PU_FOOD)
1068 if (tmp->type == FOOD)
1025 { 1069 {
1026 switch (op->contr->mode) 1070 CHK_PICK_PICKUP;
1071 continue;
1072 }
1073
1074 if (op->contr->mode & PU_DRINK)
1075 if (tmp->type == DRINK || (tmp->type == POISON && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)))
1076 {
1077 CHK_PICK_PICKUP;
1078 continue;
1079 }
1080
1081 if (op->contr->mode & PU_POTION)
1082 if (tmp->type == POTION)
1083 {
1084 CHK_PICK_PICKUP;
1085 continue;
1086 }
1087
1088 /* spellbooks, skillscrolls and normal books/scrolls */
1089 if (op->contr->mode & PU_SPELLBOOK)
1090 if (tmp->type == SPELLBOOK)
1091 {
1092 CHK_PICK_PICKUP;
1093 continue;
1094 }
1095
1096 if (op->contr->mode & PU_SKILLSCROLL)
1097 if (tmp->type == SKILLSCROLL)
1098 {
1099 CHK_PICK_PICKUP;
1100 continue;
1101 }
1102
1103 if (op->contr->mode & PU_READABLES)
1104 if (tmp->type == BOOK || tmp->type == SCROLL || tmp->type == INSCRIBABLE)
1105 {
1106 CHK_PICK_PICKUP;
1107 continue;
1108 }
1109
1110 /* wands/staves/rods/horns */
1111 if (op->contr->mode & PU_MAGIC_DEVICE)
1112 if (tmp->type == WAND || tmp->type == ROD || tmp->type == HORN)
1113 {
1114 CHK_PICK_PICKUP;
1115 continue;
1116 }
1117
1118 /* pick up all magical items */
1119 if (op->contr->mode & PU_MAGICAL)
1120 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))
1121 {
1122 CHK_PICK_PICKUP;
1123 continue;
1124 }
1125
1126 if (op->contr->mode & PU_VALUABLES)
1127 {
1128 if (tmp->type == MONEY || tmp->type == GEM)
1027 { 1129 {
1028 case 0:
1029 return 1; /* don't pick up */
1030 case 1:
1031 CHK_PICK_PICKUP; 1130 CHK_PICK_PICKUP;
1032 return 1; 1131 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 } 1132 }
1062 } 1133 }
1063 else 1134
1064 { /* old model */ 1135 /* rings & amulets - talismans seems to be typed AMULET */
1065 /* NEW pickup handling */
1066 if (op->contr->mode & PU_DEBUG) 1136 if (op->contr->mode & PU_JEWELS)
1137 if (tmp->type == RING || tmp->type == AMULET)
1067 { 1138 {
1068 /* some debugging code to figure out item information */ 1139 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; 1140 continue;
1141 }
1115 1142
1116 /* ignore known cursed objects */ 1143 /* we don't forget dragon food */
1117 if (QUERY_FLAG (tmp, FLAG_KNOWN_CURSED) && op->contr->mode & PU_NOT_CURSED) 1144 if (op->contr->mode & PU_FLESH)
1145 if (tmp->type == FLESH)
1146 {
1147 CHK_PICK_PICKUP;
1118 continue; 1148 continue;
1149 }
1119 1150
1120 /* all food and drink if desired */ 1151 /* bows and arrows. Bows are good for selling! */
1121 /* question: don't pick up known-poisonous stuff? */ 1152 if (op->contr->mode & PU_BOW)
1153 if (tmp->type == BOW)
1154 {
1155 CHK_PICK_PICKUP;
1156 continue;
1157 }
1158
1159 if (op->contr->mode & PU_ARROW)
1160 if (tmp->type == ARROW)
1161 {
1162 CHK_PICK_PICKUP;
1163 continue;
1164 }
1165
1166 /* all kinds of armor etc. */
1167 if (op->contr->mode & PU_ARMOUR)
1168 if (tmp->type == ARMOUR)
1169 {
1170 CHK_PICK_PICKUP;
1171 continue;
1172 }
1173
1174 if (op->contr->mode & PU_HELMET)
1175 if (tmp->type == HELMET)
1176 {
1177 CHK_PICK_PICKUP;
1178 continue;
1179 }
1180
1181 if (op->contr->mode & PU_SHIELD)
1182 if (tmp->type == SHIELD)
1183 {
1184 CHK_PICK_PICKUP;
1185 continue;
1186 }
1187
1122 if (op->contr->mode & PU_FOOD) 1188 if (op->contr->mode & PU_BOOTS)
1123 if (tmp->type == FOOD) 1189 if (tmp->type == BOOTS)
1190 {
1191 CHK_PICK_PICKUP;
1192 continue;
1193 }
1194
1195 if (op->contr->mode & PU_GLOVES)
1196 if (tmp->type == GLOVES)
1197 {
1198 CHK_PICK_PICKUP;
1199 continue;
1200 }
1201
1202 if (op->contr->mode & PU_CLOAK)
1203 if (tmp->type == CLOAK)
1204 {
1205 CHK_PICK_PICKUP;
1206 continue;
1207 }
1208
1209 /* hoping to catch throwing daggers here */
1210 if (op->contr->mode & PU_MISSILEWEAPON)
1211 if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_IS_THROWN))
1212 {
1213 CHK_PICK_PICKUP;
1214 continue;
1215 }
1216
1217 /* careful: chairs and tables are weapons! */
1218 if (op->contr->mode & PU_ALLWEAPON)
1219 {
1220 if (tmp->type == WEAPON)
1221 if (!tmp->arch->archname.contains ("table") && !tmp->arch->archname.contains ("chair"))
1124 { 1222 {
1125 CHK_PICK_PICKUP; 1223 CHK_PICK_PICKUP;
1126 continue; 1224 continue;
1127 } 1225 }
1226 }
1128 1227
1228 /* misc stuff that's useful */
1129 if (op->contr->mode & PU_DRINK) 1229 if (op->contr->mode & PU_KEY)
1130 if (tmp->type == DRINK || (tmp->type == POISON && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))) 1230 if (tmp->type == KEY || tmp->type == SPECIAL_KEY)
1131 { 1231 {
1132 CHK_PICK_PICKUP; 1232 CHK_PICK_PICKUP;
1133 continue; 1233 continue;
1134 } 1234 }
1135 1235
1236 /* any of the last 4 bits set means we use the ratio for value
1237 * pickups */
1136 if (op->contr->mode & PU_POTION) 1238 if (op->contr->mode & PU_RATIO)
1137 if (tmp->type == POTION) 1239 {
1240 /* use value density to decide what else to grab */
1241 /* >=7 was >= op->contr->mode */
1242 /* >=7 is the old standard setting. Now we take the last 4 bits
1138 { 1243 */
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) 1244 wvratio = op->contr->mode & PU_RATIO;
1175 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)) 1245 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 { 1246 {
1183 if (tmp->type == MONEY || tmp->type == GEM) 1247#if 0
1248 fprintf (stderr, "HIGH WEIGHT/VALUE [");
1249 if (tmp->name != NULL)
1184 { 1250 {
1185 CHK_PICK_PICKUP; 1251 fprintf (stderr, "%s", tmp->name);
1186 continue;
1187 } 1252 }
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 1253 else
1322 fprintf (stderr, "%s", tmp->arch->archname); 1254 fprintf (stderr, "%s", tmp->arch->archname);
1323 fprintf (stderr, ",%d] = ", tmp->type); 1255 fprintf (stderr, ",%d] = ", tmp->type);
1324 fprintf (stderr, "%d\n", (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1)))); 1256 fprintf (stderr, "%d\n", (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))));
1325#endif 1257#endif
1258 CHK_PICK_PICKUP;
1326 continue; 1259 continue;
1327 }
1328 } 1260 }
1329 } /* the new pickup model */ 1261 } /* the new pickup model */
1330 } 1262 }
1331 1263
1332 return !stop; 1264 return !stop;
1360 * against the target. A full test is not performed, simply a basic test 1292 * 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 1293 * 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. 1294 * the hall. Failing that it does it's best to pick the highest plus arrow.
1363 */ 1295 */
1364object * 1296object *
1365find_better_arrow (object *op, object *target, const char *type, int *better) 1297find_better_arrow (object *op, object *target, shstr_cmp type, int *better)
1366{ 1298{
1367 object *tmp = NULL, *arrow, *ntmp; 1299 object *tmp = NULL, *arrow, *ntmp;
1368 int attacknum, attacktype, betterby = 0, i; 1300 int attacknum, attacktype, betterby = 0, i;
1369 1301
1370 if (!type) 1302 if (!type)
1374 { 1306 {
1375 if (arrow->type == CONTAINER && arrow->race == type && QUERY_FLAG (arrow, FLAG_APPLIED)) 1307 if (arrow->type == CONTAINER && arrow->race == type && QUERY_FLAG (arrow, FLAG_APPLIED))
1376 { 1308 {
1377 i = 0; 1309 i = 0;
1378 ntmp = find_better_arrow (arrow, target, type, &i); 1310 ntmp = find_better_arrow (arrow, target, type, &i);
1311
1379 if (i > betterby) 1312 if (i > betterby)
1380 { 1313 {
1381 tmp = ntmp; 1314 tmp = ntmp;
1382 betterby = i; 1315 betterby = i;
1383 } 1316 }
1384 } 1317 }
1385 else if (arrow->type == ARROW && arrow->race == type) 1318 else if (arrow->type == ARROW && arrow->race == type)
1386 { 1319 {
1387 /* allways prefer assasination/slaying */ 1320 /* allways prefer assasination/slaying */
1388 if (target->race && arrow->slaying && strstr (arrow->slaying, target->race)) 1321 if (target->race && arrow->slaying.contains (target->race))
1389 { 1322 {
1390 if (arrow->attacktype & AT_DEATH) 1323 if (arrow->attacktype & AT_DEATH)
1391 { 1324 {
1392 *better = 100; 1325 *better = 100;
1393 return arrow; 1326 return arrow;
1408 { 1341 {
1409 tmp = arrow; 1342 tmp = arrow;
1410 betterby = (arrow->magic + arrow->stats.dam) * (100 - target->arch->resist[attacknum]) / 100; 1343 betterby = (arrow->magic + arrow->stats.dam) * (100 - target->arch->resist[attacknum]) / 100;
1411 } 1344 }
1412 } 1345 }
1346
1413 if ((2 + arrow->magic + arrow->stats.dam) > betterby) 1347 if ((2 + arrow->magic + arrow->stats.dam) > betterby)
1414 { 1348 {
1415 tmp = arrow; 1349 tmp = arrow;
1416 betterby = 2 + arrow->magic + arrow->stats.dam; 1350 betterby = 2 + arrow->magic + arrow->stats.dam;
1417 } 1351 }
1352
1418 if (arrow->title && (1 + arrow->magic + arrow->stats.dam) > betterby) 1353 if (arrow->title && (1 + arrow->magic + arrow->stats.dam) > betterby)
1419 { 1354 {
1420 tmp = arrow; 1355 tmp = arrow;
1421 betterby = 1 + arrow->magic + arrow->stats.dam; 1356 betterby = 1 + arrow->magic + arrow->stats.dam;
1422 } 1357 }
1436 * op = the shooter 1371 * op = the shooter
1437 * type = bow->race 1372 * type = bow->race
1438 * dir = fire direction 1373 * dir = fire direction
1439 */ 1374 */
1440object * 1375object *
1441pick_arrow_target (object *op, const char *type, int dir) 1376pick_arrow_target (object *op, shstr_cmp type, int dir)
1442{ 1377{
1443 object *tmp = NULL; 1378 object *tmp = NULL;
1444 maptile *m; 1379 maptile *m;
1445 int i, mflags, found, number; 1380 int i, mflags, found, number;
1446 sint16 x, y; 1381 sint16 x, y;
1461 for (i = 0, found = 0; i < 20; i++) 1396 for (i = 0, found = 0; i < 20; i++)
1462 { 1397 {
1463 x += freearr_x[dir]; 1398 x += freearr_x[dir];
1464 y += freearr_y[dir]; 1399 y += freearr_y[dir];
1465 mflags = get_map_flags (m, &m, x, y, &x, &y); 1400 mflags = get_map_flags (m, &m, x, y, &x, &y);
1401
1466 if (mflags & P_OUT_OF_MAP || mflags & P_BLOCKSVIEW) 1402 if (mflags & P_OUT_OF_MAP || mflags & P_BLOCKSVIEW)
1467 { 1403 {
1468 tmp = NULL; 1404 tmp = 0;
1469 break; 1405 break;
1470 } 1406 }
1471 else if (GET_MAP_MOVE_BLOCK (m, x, y) == MOVE_FLY_LOW) 1407 else if (GET_MAP_MOVE_BLOCK (m, x, y) == MOVE_FLY_LOW)
1472 { 1408 {
1473 /* This block presumes arrows and the like are MOVE_FLY_SLOW - 1409 /* This block presumes arrows and the like are MOVE_FLY_SLOW -
1474 * perhaps a bad assumption. 1410 * perhaps a bad assumption.
1475 */ 1411 */
1476 tmp = NULL; 1412 tmp = 0;
1477 break; 1413 break;
1478 } 1414 }
1415
1479 if (mflags & P_IS_ALIVE) 1416 if (mflags & P_IS_ALIVE)
1480 {
1481 for (tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above) 1417 for (tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above)
1482 if (QUERY_FLAG (tmp, FLAG_ALIVE)) 1418 if (QUERY_FLAG (tmp, FLAG_ALIVE))
1483 {
1484 found++;
1485 break;
1486 }
1487 if (found)
1488 break; 1419 break;
1489 }
1490 } 1420 }
1491 if (tmp == NULL) 1421
1422 if (!tmp)
1492 return find_arrow (op, type); 1423 return find_arrow (op, type);
1493 1424
1494 if (tmp->head) 1425 if (tmp->head)
1495 tmp = tmp->head; 1426 tmp = tmp->head;
1496 1427
1536 LOG (llevError, "Range: bow without activated bow (%s).\n", &op->name); 1467 LOG (llevError, "Range: bow without activated bow (%s).\n", &op->name);
1537 return 0; 1468 return 0;
1538 } 1469 }
1539 1470
1540 // optimisation: move object to top so we will find it quickly again 1471 // optimisation: move object to top so we will find it quickly again
1541 if (bow->below) 1472 splay (bow);
1542 {
1543 bow->remove ();
1544 op->insert (bow);
1545 }
1546
1547 } 1473 }
1548 1474
1549 if (!bow->race || !bow->skill) 1475 if (!bow->race || !bow->skill)
1550 { 1476 {
1551 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s is broken.", &bow->name); 1477 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s is broken.", &bow->name);
1577 } 1503 }
1578 1504
1579 /* this should not happen, but sometimes does */ 1505 /* this should not happen, but sometimes does */
1580 if (arrow->nrof == 0) 1506 if (arrow->nrof == 0)
1581 { 1507 {
1508 LOG (llevError | logBacktrace, "arrow (%s) has nrof 0\n", arrow->debug_desc ());
1582 arrow->destroy (); 1509 arrow->destroy ();
1583 return 0; 1510 return 0;
1584 } 1511 }
1585 1512
1586 left = arrow; /* these are arrows left to the player */ 1513 left = arrow; /* these are arrows left to the player */
1596 arrow->direction = dir; 1523 arrow->direction = dir;
1597 1524
1598 arrow->stats.sp = arrow->stats.wc; /* save original wc, dam, attacktype and slaying */ 1525 arrow->stats.sp = arrow->stats.wc; /* save original wc, dam, attacktype and slaying */
1599 arrow->stats.hp = arrow->stats.dam; 1526 arrow->stats.hp = arrow->stats.dam;
1600 arrow->stats.grace = arrow->attacktype; 1527 arrow->stats.grace = arrow->attacktype;
1601 1528 arrow->custom_name = arrow->slaying;
1602 if (arrow->slaying)
1603 arrow->spellarg = strdup (arrow->slaying);
1604 1529
1605#if 0 1530#if 0
1606 if (player *pl = op->contr) 1531 if (player *pl = op->contr)
1607 { 1532 {
1608 float speed = pl->weapon_sp; 1533 float speed = pl->weapon_sp;
1673 * hence the function name. 1598 * hence the function name.
1674 */ 1599 */
1675int 1600int
1676player_fire_bow (object *op, int dir) 1601player_fire_bow (object *op, int dir)
1677{ 1602{
1678 int ret = 0, wcmod = 0; 1603 int ret;
1679 1604
1680 if (op->contr->bowtype == bow_bestarrow) 1605 if (op->contr->bowtype == bow_bestarrow)
1681 { 1606 {
1682 ret = fire_bow (op, op, pick_arrow_target (op, op->contr->ranged_ob->race, dir), dir, 0, op->x, op->y); 1607 ret = fire_bow (op, op, pick_arrow_target (op, op->contr->ranged_ob->race, dir), dir, 0, op->x, op->y);
1683 } 1608 }
1684 else if (op->contr->bowtype >= bow_n && op->contr->bowtype <= bow_nw) 1609 else if (op->contr->bowtype >= bow_n && op->contr->bowtype <= bow_nw)
1685 { 1610 {
1686 if (!similar_direction (dir, op->contr->bowtype - bow_n + 1)) 1611 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); 1612 ret = fire_bow (op, op, NULL, op->contr->bowtype - bow_n + 1, wcmod, op->x, op->y);
1690 } 1613 }
1691 else if (op->contr->bowtype == bow_threewide) 1614 else if (op->contr->bowtype == bow_threewide)
1692 { 1615 {
1693 ret = fire_bow (op, op, NULL, dir, 0, op->x, op->y); 1616 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)]); 1617 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)]); 1618 ret |= fire_bow (op, op, NULL, dir, -5, op->x + freearr_x[absdir (dir - 2)], op->y + freearr_y[absdir (dir - 2)]);
1696 } 1619 }
1697 else if (op->contr->bowtype == bow_spreadshot) 1620 else if (op->contr->bowtype == bow_spreadshot)
1698 { 1621 {
1699 ret |= fire_bow (op, op, NULL, dir, 0, op->x, op->y); 1622 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); 1623 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); 1624 ret |= fire_bow (op, op, NULL, absdir (dir + 1), -5, op->x, op->y);
1702 } 1625 }
1703 else 1626 else
1704 { 1627 {
1761 } 1684 }
1762 } 1685 }
1763 1686
1764 if (cast_spell (op, item, dir, item->inv, NULL)) 1687 if (cast_spell (op, item, dir, item->inv, NULL))
1765 { 1688 {
1766 SET_FLAG (op, FLAG_BEEN_APPLIED); /* You now know something about it */ 1689 item->flag [FLAG_BEEN_APPLIED] = true; /* You now know something about it */
1690
1767 if (item->type == WAND) 1691 if (item->type == WAND)
1768 { 1692 {
1769 if (!(--item->stats.food)) 1693 if (!(--item->stats.food))
1770 { 1694 {
1771 object *tmp; 1695 object *tmp;
1791bool 1715bool
1792fire (object *op, int dir) 1716fire (object *op, int dir)
1793{ 1717{
1794 int spellcost = 0; 1718 int spellcost = 0;
1795 1719
1796 /* check for loss of invisiblity/hide */
1797 if (action_makes_visible (op))
1798 make_visible (op);
1799
1800 player *pl = op->contr; 1720 player *pl = op->contr;
1801 1721
1802 if (pl->golem) 1722 if (pl->golem)
1803 { 1723 {
1804 control_golem (op->contr->golem, dir); 1724 control_golem (op->contr->golem, dir);
1806 } 1726 }
1807 1727
1808 object *ob = pl->ranged_ob; 1728 object *ob = pl->ranged_ob;
1809 1729
1810 if (!ob) 1730 if (!ob)
1811 return false;
1812
1813 if (!op->change_weapon (ob))
1814 return false; 1731 return false;
1815 1732
1816 if (op->speed_left > 0.f) 1733 if (op->speed_left > 0.f)
1817 --op->speed_left; 1734 --op->speed_left;
1818 else 1735 else
1819 return false; 1736 return false;
1820 1737
1738 if (!op->change_weapon (ob))
1739 return false;
1740
1741 /* check for loss of invisiblity/hide */
1742 if (action_makes_visible (op))
1743 make_visible (op);
1744
1821 switch (ob->type) 1745 switch (ob->type)
1822 { 1746 {
1823 case BOW: 1747 case BOW:
1824 player_fire_bow (op, dir); 1748 player_fire_bow (op, dir);
1825 break; 1749 break;
1826 1750
1827 case SPELL: 1751 case SPELL:
1828 spellcost = cast_spell (op, op, dir, ob, pl->spellparam[0] ? pl->spellparam : 0); 1752 spellcost = cast_spell (op, op, dir, ob, *pl->spellparam ? pl->spellparam : 0);
1829 break; 1753 break;
1830 1754
1831 case BUILDER: 1755 case BUILDER:
1832 apply_map_builder (op, dir); 1756 apply_map_builder (op, dir);
1833 break; 1757 break;
1917 * Change the color so that the message doesn't disappear with 1841 * Change the color so that the message doesn't disappear with
1918 * all the others. 1842 * all the others.
1919 */ 1843 */
1920 if (pl->contr->usekeys == key_inventory || 1844 if (pl->contr->usekeys == key_inventory ||
1921 !QUERY_FLAG (container, FLAG_APPLIED) || 1845 !QUERY_FLAG (container, FLAG_APPLIED) ||
1922 (pl->contr->usekeys == keyrings && (!container->race || strcmp (container->race, "keys")))) 1846 (pl->contr->usekeys == keyrings && container->race != shstr_keys))
1923 { 1847 {
1924 new_draw_info_format (NDI_UNIQUE | NDI_BROWN, 0, pl, 1848 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)); 1849 "The %s in your %s vibrates as you approach the door", query_name (tmp), query_name (container));
1926 return NULL; 1850 return NULL;
1927 } 1851 }
2069 --op->speed_left; 1993 --op->speed_left;
2070 1994
2071 op->play_sound (sound_find ("push_player")); 1995 op->play_sound (sound_find ("push_player"));
2072 push_ob (mon, dir, op); 1996 push_ob (mon, dir, op);
2073 1997
2074 if (op->contr->tmp_invis || op->hide) 1998 if (action_makes_visible (op))
2075 make_visible (op); 1999 make_visible (op);
2076 2000
2077 return true; 2001 return true;
2078 } 2002 }
2079 else 2003 else
2101 push_ob (mon, dir, op); 2025 push_ob (mon, dir, op);
2102 } 2026 }
2103 else 2027 else
2104 op->statusmsg ("You withhold your attack"); 2028 op->statusmsg ("You withhold your attack");
2105 2029
2106 if (op->contr->tmp_invis || op->hide) 2030 if (op->contr->tmp_invis || op->flag [FLAG_HIDDEN])
2107 make_visible (op); 2031 make_visible (op);
2108 2032
2109 return true; 2033 return true;
2110 } 2034 }
2111 } 2035 }
2169 if (QUERY_FLAG (op, FLAG_CONFUSED) && dir) 2093 if (QUERY_FLAG (op, FLAG_CONFUSED) && dir)
2170 dir = absdir (dir + rndm (3) + rndm (3) - 2); 2094 dir = absdir (dir + rndm (3) + rndm (3) - 2);
2171 2095
2172 op->facing = dir; 2096 op->facing = dir;
2173 2097
2174 if (op->hide) 2098 if (op->flag [FLAG_HIDDEN])
2175 do_hidden_move (op); 2099 do_hidden_move (op);
2176 2100
2177 bool retval; 2101 bool retval;
2178 2102
2179 if (INVOKE_PLAYER (MOVE, op->contr, ARG_INT (dir))) 2103 if (INVOKE_PLAYER (MOVE, op->contr, ARG_INT (dir)))
2310const char * 2234const char *
2311gravestone_text (object *op) 2235gravestone_text (object *op)
2312{ 2236{
2313 static dynbuf_text buf; 2237 static dynbuf_text buf;
2314 2238
2315 buf << "---- R.I.P. ----\n\n"; 2239 buf << "---- R.I.P. ----\n\n"
2316 op->name; 2240 << op->name;
2317 2241
2318 if (op->type == PLAYER) 2242 if (op->type == PLAYER)
2319 buf << " the " << op->contr->title; 2243 buf << " the " << op->contr->title;
2320 2244
2321 buf << "\n\n"; 2245 buf << "\n\n";
2497 { 2421 {
2498 over_hp = (gen_hp < 20 ? 30 : gen_hp + 10) / rate_hp; 2422 over_hp = (gen_hp < 20 ? 30 : gen_hp + 10) / rate_hp;
2499 2423
2500 if (over_hp > 0) 2424 if (over_hp > 0)
2501 { 2425 {
2502 op->stats.sp += over_hp + (RANDOM () % rate_hp > ((gen_hp < 20 ? 30 : gen_hp + 10) % rate_hp)) ? -1 : 0; 2426 op->stats.sp += over_hp + (rndm (rate_hp) > ((gen_hp < 20 ? 30 : gen_hp + 10) % rate_hp)) ? -1 : 0;
2503 op->last_heal = 0; 2427 op->last_heal = 0;
2504 } 2428 }
2505 else 2429 else
2506 op->last_heal = rate_hp / (gen_hp < 20 ? 30 : gen_hp + 10); 2430 op->last_heal = rate_hp / (gen_hp < 20 ? 30 : gen_hp + 10);
2507 } 2431 }
2563 2487
2564 if (op->stats.food < 0) 2488 if (op->stats.food < 0)
2565 { 2489 {
2566 op->stats.hp += op->stats.food; 2490 op->stats.hp += op->stats.food;
2567 op->stats.food = 0; 2491 op->stats.food = 0;
2492
2493 if (op->stats.hp < 0)
2494 {
2495 op->contr->killer = archetype::get ("killer_starvation");
2496 op->contr->killer->destroy ();
2568 } 2497 }
2498 }
2569 2499
2500 /* killer should be set here already */
2570 if (op->stats.hp < 0 && !QUERY_FLAG (op, FLAG_WIZ)) 2501 if (op->stats.hp < 0 && !QUERY_FLAG (op, FLAG_WIZ))
2571 kill_player (op); 2502 kill_player (op);
2572 } 2503 }
2573} 2504}
2574 2505
2579 */ 2510 */
2580void 2511void
2581kill_player (object *op) 2512kill_player (object *op)
2582{ 2513{
2583 int x, y; 2514 int x, y;
2584 char buf[MAX_BUF];
2585 maptile *map; /* this is for resurrection */ 2515 maptile *map; /* this is for resurrection */
2586 int will_kill_again; 2516 int will_kill_again;
2587 archetype *at; 2517 archetype *at;
2588 object *tmp; 2518 object *tmp;
2589 2519
2590 if (save_life (op)) 2520 if (save_life (op))
2591 return; 2521 return;
2522
2523 dynbuf_text deathtab;
2524
2525 /* restore player */
2526 at = archetype::find ("poisoning");
2527 if (object *tmp = present_arch_in_ob (at, op))
2528 {
2529 tmp->destroy ();
2530 deathtab << "Your body feels cleansed...\r";
2531 }
2532
2533 at = archetype::find ("confusion");
2534 if (object *tmp = present_arch_in_ob (at, op))
2535 {
2536 tmp->destroy ();
2537 deathtab << "Your mind feels clearer...\r";
2538 }
2539
2540 cure_disease (op, 0, 0); /* remove any disease */
2541
2542 max_it (op->stats.hp , op->stats.maxhp);
2543 max_it (op->stats.sp , op->stats.maxsp);
2544 max_it (op->stats.grace, op->stats.maxgrace);
2545
2546 if (op->stats.food <= 0)
2547 op->stats.food = 999;
2548
2549 // remove all spell effects that are active
2550 // to avoid long-term effects such as word-of-recall
2551 for (object *item = op->inv; item; )
2552 {
2553 object *next = item->below;
2554
2555 if (item->type == SPELL_EFFECT && item->active)
2556 item->destroy ();
2557
2558 item = next;
2559 }
2592 2560
2593 /* If player dies on BATTLEGROUND, no stat/exp loss! For Combat-Arenas 2561 /* 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. 2562 * in cities ONLY!!! It is very important that this doesn't get abused.
2595 * Look at op_on_battleground() for more info --AndreasV 2563 * Look at op_on_battleground() for more info --AndreasV
2596 */ 2564 */
2597 if (op_on_battleground (op, &x, &y)) 2565 if (op_on_battleground (op, &x, &y))
2598 { 2566 {
2599 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, "You have been defeated in combat!"); 2567 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 2568
2622 /* create a bodypart-trophy to make the winner happy */ 2569 /* create a bodypart-trophy to make the winner happy */
2623 if (object *tmp = arch_to_object (archetype::find ("finger"))) 2570 if (object *tmp = arch_to_object (archetype::find ("finger")))
2624 { 2571 {
2625 tmp->name = format ("%s's finger" , &op->name); 2572 tmp->name = format ("%s's finger" , &op->name);
2636 } 2583 }
2637 2584
2638 /* teleport defeated player to new destination */ 2585 /* teleport defeated player to new destination */
2639 transfer_ob (op, x, y, 0, NULL); 2586 transfer_ob (op, x, y, 0, NULL);
2640 op->contr->braced = 0; 2587 op->contr->braced = 0;
2588
2589 op->contr->infobox (MSG_CHANNEL ("death"), deathtab);
2641 return; 2590 return;
2642 } 2591 }
2643 2592
2593 deathtab << "You were killed by " << op->contr->killer_name () << ".\n\n";
2594 deathtab << "T<YOU HAVE DIED>\n\n";
2595
2644 INVOKE_PLAYER (DEATH, op->contr); 2596 INVOKE_PLAYER (DEATH, op->contr);
2645 2597
2646 command_kill_pets (op, 0); 2598 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 2599
2654 op->contr->play_sound (sound_find ("player_dies")); 2600 op->contr->play_sound (sound_find ("player_dies"));
2655 2601
2656 /* save the map location for corpse, gravestone */ 2602 /* save the map location for corpse, gravestone */
2657 x = op->x; 2603 x = op->x;
2687 2633
2688 lost_a_stat = 0; 2634 lost_a_stat = 0;
2689 2635
2690 for (z = 0; z < num_stats_lose; z++) 2636 for (z = 0; z < num_stats_lose; z++)
2691 { 2637 {
2692 i = RANDOM () % NUM_STATS; 2638 i = rndm (NUM_STATS);
2693 2639
2694 if (settings.stat_loss_on_death) 2640 if (settings.stat_loss_on_death)
2695 { 2641 {
2696 /* Pick a random stat and take a point off it. Tell the player 2642 /* Pick a random stat and take a point off it. Tell the player
2697 * what he lost. 2643 * what he lost.
2748 } 2694 }
2749 } 2695 }
2750 2696
2751 if (lose_this_stat) 2697 if (lose_this_stat)
2752 { 2698 {
2753 this_stat = get_attr_value (&(dep->stats), i); 2699 this_stat = get_attr_value (&dep->stats, i);
2754 /* We could try to do something clever like find another 2700 /* We could try to do something clever like find another
2755 * stat to reduce if this fails. But chances are, if 2701 * stat to reduce if this fails. But chances are, if
2756 * stats have been depleted to -50, all are pretty low 2702 * stats have been depleted to -50, all are pretty low
2757 * and should be roughly the same, so it shouldn't make a 2703 * and should be roughly the same, so it shouldn't make a
2758 * difference. 2704 * difference.
2772 /* If no stat lost, tell the player. */ 2718 /* If no stat lost, tell the player. */
2773 if (!lost_a_stat) 2719 if (!lost_a_stat)
2774 { 2720 {
2775 /* determine_god() seems to not work sometimes... why is this? 2721 /* determine_god() seems to not work sometimes... why is this?
2776 Should I be using something else? GD */ 2722 Should I be using something else? GD */
2777 const char *god = determine_god (op); 2723 shstr_tmp god = determine_god (op);
2778 2724
2779 if (god && (strcmp (god, "none"))) 2725 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); 2726 deathtab << "For a brief moment you feel the holy presence of " << god << " protecting you.\r";
2781 else 2727 else
2782 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you feel a holy presence protecting you."); 2728 deathtab << "For a brief moment you feel a holy presence protecting you.\r";
2783 } 2729 }
2784#else 2730#else
2785 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you feel a holy presence protecting you from losing yourself completely."); 2731 deathtab << "For a brief moment you feel a holy presence protecting you from losing yourself completely.";
2786#endif 2732#endif
2787 2733
2788 /* Put a gravestone up where the character 'almost' died. List the 2734 /* Put a gravestone up where the character 'almost' died. List the
2789 * exp loss on the stone. 2735 * exp loss on the stone.
2790 */ 2736 */
2791 tmp = arch_to_object (archetype::find ("gravestone")); 2737 tmp = arch_to_object (archetype::find ("gravestone"));
2792 tmp->name = format ("%s's gravestone", &op->name); 2738 tmp->name = format ("%s's gravestone", &op->name);
2793 tmp->name_pl = format ("%s's gravestones", &op->name); 2739 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 ()); 2740 tmp->msg = format ("T<RIP>\n\nHere rests the hero %s the %s,\rwho was killed\rby %s.\n",
2741 &op->name, op->contr->title, op->contr->killer_name ());
2795 tmp->x = op->x, tmp->y = op->y; 2742 tmp->x = op->x, tmp->y = op->y;
2796 insert_ob_in_map (tmp, op->map, NULL, 0); 2743 insert_ob_in_map (tmp, op->map, NULL, 0);
2797 2744
2798 /**************************************/ 2745 /**************************************/
2799 /* */ 2746 /* */
2800 /* Subtract the experience points, */ 2747 /* Subtract the experience points, */
2801 /* if we died cause of food, give us */
2802 /* food, and reset HP's... */
2803 /* */ 2748 /* */
2804 /**************************************/ 2749 /**************************************/
2805 2750
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)); */ 2751 /*add_exp(op, (op->stats.exp * -0.20)); */
2840 apply_death_exp_penalty (op); 2752 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 2753
2849 /* 2754 /*
2850 * Check to see if the player has any unpaid items. If so, remove them 2755 * Check to see if the player has any unpaid items. If so, remove them
2851 * and put them back in the map. 2756 * and put them back in the map.
2852 */ 2757 */
2887 if (will_kill_again & (1 << at)) 2792 if (will_kill_again & (1 << at))
2888 force->resist[at] = 100; 2793 force->resist[at] = 100;
2889 2794
2890 insert_ob_in_ob (force, op); 2795 insert_ob_in_ob (force, op);
2891 op->update_stats (); 2796 op->update_stats ();
2892
2893 } 2797 }
2894 2798
2895 new_draw_info (NDI_UNIQUE, 0, op, "YOU HAVE DIED."); 2799 op->contr->infobox (MSG_CHANNEL ("death"), deathtab);
2896} 2800}
2897 2801
2898void 2802void
2899loot_object (object *op) 2803loot_object (object *op)
2900{ /* Grab and destroy some treasure */ 2804{ /* Grab and destroy some treasure */
2998} 2902}
2999 2903
3000void 2904void
3001make_visible (object *op) 2905make_visible (object *op)
3002{ 2906{
3003 op->hide = 0; 2907 op->flag [FLAG_HIDDEN] = 0;
3004 op->invisible = 0; 2908 op->invisible = 0;
3005 2909
3006 if (op->type == PLAYER) 2910 if (op->type == PLAYER)
3007 { 2911 {
3008 op->contr->tmp_invis = 0; 2912 op->contr->tmp_invis = 0;
3033 2937
3034 if (!ob || !ob->map) 2938 if (!ob || !ob->map)
3035 return 0; 2939 return 0;
3036 2940
3037 /* so, on normal lighted maps, its hard to hide */ 2941 /* so, on normal lighted maps, its hard to hide */
3038 level = ob->map->darkness - 2; 2942 level = ob->map->darklevel () - 2;
3039 2943
3040 /* this also picks up whether the object is glowing. 2944 /* this also picks up whether the object is glowing.
3041 * If you carry a light on a non-dark map, its not 2945 * If you carry a light on a non-dark map, its not
3042 * as bad as carrying a light on a pitch dark map */ 2946 * as bad as carrying a light on a pitch dark map */
3043 if (has_carried_lights (ob)) 2947 if (ob->has_carried_lights ())
3044 level = -(10 + (2 * ob->map->darkness)); 2948 level = -(10 + (2 * ob->map->darklevel ()));
3045 2949
3046 /* scan through all nearby squares for terrain to hide in */ 2950 /* scan through all nearby squares for terrain to hide in */
3047 for (i = 0, x = ob->x, y = ob->y; 2951 for (i = 0, x = ob->x, y = ob->y;
3048 i <= SIZEOFFREE1; 2952 i <= SIZEOFFREE1;
3049 i++, x = ob->x + freearr_x[i], y = ob->y + freearr_y[i]) 2953 i++, x = ob->x + freearr_x[i], y = ob->y + freearr_y[i])
3196 while (op) 3100 while (op)
3197 { 3101 {
3198 dx = rv.distance_x + op->arch->x; 3102 dx = rv.distance_x + op->arch->x;
3199 dy = rv.distance_y + op->arch->y; 3103 dy = rv.distance_y + op->arch->y;
3200 3104
3201 /* only the viewable area the player sees is updated by LOS 3105 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; 3106 return 1;
3209 3107
3210 op = op->more; 3108 op = op->more;
3211 } 3109 }
3212 3110
3213 return 0; 3111 return 0;
3214} 3112}
3215 3113
3216/* routine for both players and monsters. We call this when 3114/* routine for both players and monsters. We call this when
3217 * there is a possibility for our action distrubing our hiding 3115 * there is a possibility for our action distrubing our hiding
3218 * place or invisiblity spell. Artefact invisiblity is not 3116 * place or invisiblity spell. Artefact invisiblity causes
3219 * effected by this. If we arent invisible to begin with, we 3117 * "noise" instead. If we arent invisible to begin with, we
3220 * return 0. 3118 * return 0.
3221 */ 3119 */
3222int 3120int
3223action_makes_visible (object *op) 3121action_makes_visible (object *op)
3224{ 3122{
3225 if (op->invisible && QUERY_FLAG (op, FLAG_ALIVE)) 3123 if (op->invisible && QUERY_FLAG (op, FLAG_ALIVE))
3226 { 3124 {
3227 if (QUERY_FLAG (op, FLAG_MAKE_INVIS)) 3125 if (QUERY_FLAG (op, FLAG_MAKE_INVIS))
3126 {
3127 // artefact invisibility is permanent, but we still make noise
3128 // this is important for game-balance.
3129 if (op->contr)
3130 op->make_noise ();
3131
3228 return 0; 3132 return 0;
3133 }
3229 3134
3230 if (op->contr && op->contr->tmp_invis == 0) 3135 if (op->contr && op->contr->tmp_invis == 0)
3231 return 0; 3136 return 0;
3232 3137
3233 /* If monsters, they should become visible */ 3138 /* If monsters, they should become visible */
3234 if (op->hide || !op->contr || (op->contr && op->contr->tmp_invis)) 3139 if (op->flag [FLAG_HIDDEN] || !op->contr || (op->contr && op->contr->tmp_invis))
3235 { 3140 {
3236 new_draw_info_format (NDI_UNIQUE, 0, op, "You become %s!", op->hide ? "unhidden" : "visible"); 3141 new_draw_info_format (NDI_UNIQUE, 0, op, "You become %s!", op->flag [FLAG_HIDDEN] ? "unhidden" : "visible");
3237 return 1; 3142 return 1;
3238 } 3143 }
3239 } 3144 }
3240 3145
3241 return 0; 3146 return 0;
3469 if (pl->ranged_ob == ob) 3374 if (pl->ranged_ob == ob)
3470 pl->ranged_ob = 0; 3375 pl->ranged_ob = 0;
3471} 3376}
3472 3377
3473sint8 3378sint8
3474player::visibility_at (maptile *map, int x, int y) const 3379player::darkness_at (maptile *map, int x, int y) const
3475{ 3380{
3476 if (!ns) 3381 if (!ns)
3477 return 0; 3382 return LOS_BLOCKED;
3478 3383
3479 int dx, dy; 3384 int dx, dy;
3480 if (!adjacent_map (map, ns->current_map, &dx, &dy)) 3385 if (!adjacent_map (map, ns->current_map, &dx, &dy))
3481 return 0; 3386 return LOS_BLOCKED;
3482 3387
3483 x += dx - ns->current_x + ns->mapx / 2; 3388 x += dx - ns->current_x;
3484 y += dy - ns->current_y + ns->mapy / 2; 3389 y += dy - ns->current_y;
3485 3390
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]; 3391 return blocked_los (x, y);
3490} 3392}
3491 3393
3492void 3394void
3493player::infobox (const char *title, const char *msg, int color) 3395player::infobox (const char *title, const char *msg, int color)
3494{ 3396{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines