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.171 by root, Sat Sep 8 07:06:51 2007 UTC vs.
Revision 1.178 by root, Sat Jan 5 06:11:28 2008 UTC

1/* 1/*
2 * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team 4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * Crossfire TRT is free software: you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or 10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version. 11 * (at your option) any later version.
12 * 12 *
13 * This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * 20 *
21 * The authors can be reached via e-mail to <crossfire@schmorp.de> 21 * The authors can be reached via e-mail to <support@deliantra.net>
22 */ 22 */
23 23
24#include <global.h> 24#include <global.h>
25#include <sproto.h> 25#include <sproto.h>
26#include <sounds.h> 26#include <sounds.h>
241 241
242 new_draw_info (NDI_UNIQUE, 0, ob, "Welcome Back!"); 242 new_draw_info (NDI_UNIQUE, 0, ob, "Welcome Back!");
243 243
244 esrv_new_player (this, ob->weight + ob->carrying); 244 esrv_new_player (this, ob->weight + ob->carrying);
245 245
246 ob->update_stats ();
247
248 ns->floorbox_update ();
249 esrv_send_inventory (ob, ob);
250 esrv_add_spells (this, 0);
251
252 activate ();
253
254 send_rules (ob);
255 send_news (ob);
256 display_motd (ob);
257
258 INVOKE_PLAYER (CONNECT, this);
259 INVOKE_PLAYER (LOGIN, this);
260}
261
262void
263player::disconnect ()
264{
265 if (ob)
266 {
267 ob->close_container (); //TODO: client-specific
268 ob->drop_unpaid_items ();
269 }
270
271 if (ns)
272 {
273 if (active)
274 INVOKE_PLAYER (LOGOUT, this, ARG_INT (0));
275
276 INVOKE_PLAYER (DISCONNECT, this);
277
278 ns->reset_stats ();
279 ns->pl = 0;
280 ns = 0;
281 }
282
283 observe = ob;
284
285 deactivate ();
286}
287
288// the need for this function can be explained
289// by load_object not returning the object
290void
291player::set_object (object *op)
292{
293 ob = observe = op;
294 ob->contr = this; /* this aren't yet in archetype */
295
296 ob->speed = 1.0f;
297 ob->speed_left = 0.5f;
298
299 ob->direction = 5; /* So player faces south */
300
246 ob->flag [FLAG_READY_WEAPON] = false; 301 ob->flag [FLAG_READY_WEAPON] = false;
247 ob->flag [FLAG_READY_SKILL] = false; 302 ob->flag [FLAG_READY_SKILL] = false;
248 ob->flag [FLAG_READY_BOW] = false; 303 ob->flag [FLAG_READY_BOW] = false;
249 304
250 for (object *op = ob->inv; op; op = op->below) 305 for (object *op = ob->inv; op; op = op->below)
266 combat_ob = op; 321 combat_ob = op;
267 break; 322 break;
268 } 323 }
269 324
270 ob->change_weapon (combat_ob ? combat_ob : ranged_ob); 325 ob->change_weapon (combat_ob ? combat_ob : ranged_ob);
271 ob->update_stats ();
272
273 ns->floorbox_update ();
274 esrv_send_inventory (ob, ob);
275 esrv_add_spells (this, 0);
276
277 activate ();
278
279 send_rules (ob);
280 send_news (ob);
281 display_motd (ob);
282
283 INVOKE_PLAYER (CONNECT, this);
284 INVOKE_PLAYER (LOGIN, this);
285}
286
287void
288player::disconnect ()
289{
290 if (ob)
291 {
292 ob->close_container (); //TODO: client-specific
293 ob->drop_unpaid_items ();
294 }
295
296 if (ns)
297 {
298 if (active)
299 INVOKE_PLAYER (LOGOUT, this, ARG_INT (0));
300
301 INVOKE_PLAYER (DISCONNECT, this);
302
303 ns->reset_stats ();
304 ns->pl = 0;
305 ns = 0;
306 }
307
308 observe = ob;
309
310 deactivate ();
311}
312
313// the need for this function can be explained
314// by load_object not returning the object
315void
316player::set_object (object *op)
317{
318 ob = observe = op;
319 ob->contr = this; /* this aren't yet in archetype */
320
321 ob->speed = 1.0f;
322 ob->speed_left = 0.5f;
323
324 ob->direction = 5; /* So player faces south */
325} 326}
326 327
327void 328void
328player::set_observe (object *op) 329player::set_observe (object *op)
329{ 330{
632} 633}
633 634
634void 635void
635give_initial_items (object *pl, treasurelist * items) 636give_initial_items (object *pl, treasurelist * items)
636{ 637{
637 object *op, *next = NULL;
638
639 if (pl->randomitems != NULL) 638 if (pl->randomitems)
640 create_treasure (items, pl, GT_STARTEQUIP | GT_ONLY_GOOD, 1, 0); 639 create_treasure (items, pl, GT_STARTEQUIP | GT_ONLY_GOOD, 1, 0);
641 640
642 for (op = pl->inv; op; op = next) 641 for (object *next, *op = pl->inv; op; op = next)
643 { 642 {
644 next = op->below; 643 next = op->below;
645 644
646 /* Forces get applied per default, unless they have the 645 /* Forces get applied per default, unless they have the
647 * flag "neutral" set. Sorry but I can't think of a better way 646 * flag "neutral" set. Sorry but I can't think of a better way
689 if (op->nrof > 1) 688 if (op->nrof > 1)
690 op->nrof = 1; 689 op->nrof = 1;
691 } 690 }
692 691
693 if (op->type == SPELLBOOK && op->inv) 692 if (op->type == SPELLBOOK && op->inv)
694 {
695 CLEAR_FLAG (op->inv, FLAG_STARTEQUIP); 693 CLEAR_FLAG (op->inv, FLAG_STARTEQUIP);
696 }
697 694
698 /* Give starting characters identified, uncursed, and undamned 695 /* Give starting characters identified, uncursed, and undamned
699 * items. Just don't identify gold or silver, or it won't be 696 * items. Just don't identify gold or silver, or it won't be
700 * merged properly. 697 * merged properly.
701 */ 698 */
831static void 828static void
832start_info (object *op) 829start_info (object *op)
833{ 830{
834 char buf[MAX_BUF]; 831 char buf[MAX_BUF];
835 832
836 sprintf (buf, "Welcome to Crossfire v%s!", VERSION); 833 sprintf (buf, "Welcome to Deliantra v%s!", VERSION);
837 new_draw_info (NDI_UNIQUE, 0, op, buf); 834 new_draw_info (NDI_UNIQUE, 0, op, buf);
838 //new_draw_info (NDI_UNIQUE, 0, op, "Press `?' for help");
839 //new_draw_info (NDI_UNIQUE, 0, op, " ");
840} 835}
841 836
842/* This function takes the key that is passed, and does the 837/* This function takes the key that is passed, and does the
843 * appropriate action with it (change race, or other things). 838 * appropriate action with it (change race, or other things).
844 * The function name is for historical reasons - now we have 839 * The function name is for historical reasons - now we have
1007 if (op->move_type & MOVE_FLYING) 1002 if (op->move_type & MOVE_FLYING)
1008 return 1; 1003 return 1;
1009 1004
1010 next = op->below; 1005 next = op->below;
1011 1006
1007 int cnt = MAX_ITEM_PER_DROP;
1008#define CHK_PICK_PICKUP do { pick_up (op, tmp); cnt--; } while (0)
1009
1012 /* loop while there are items on the floor that are not marked as 1010 /* loop while there are items on the floor that are not marked as
1013 * destroyed */ 1011 * destroyed */
1014 while (next && !next->destroyed ()) 1012 while (next && !next->destroyed ())
1015 { 1013 {
1016 tmp = next; 1014 tmp = next;
1017 next = tmp->below; 1015 next = tmp->below;
1018 1016
1017 if (cnt <= 0)
1018 {
1019 op->failmsg ("Couldn't pickup all items at once.");
1020 return 0;
1021 }
1022
1019 if (op->destroyed ()) 1023 if (op->destroyed ())
1020 return 0; 1024 return 0;
1021 1025
1022 if (!can_pick (op, tmp)) 1026 if (!can_pick (op, tmp))
1023 continue; 1027 continue;
1024 1028
1025 if (op->contr->search_str[0] != '\0' && settings.search_items == TRUE) 1029 if (op->contr->search_str[0] != '\0' && settings.search_items == TRUE)
1026 { 1030 {
1027 if (item_matched_string (op, tmp, op->contr->search_str)) 1031 if (item_matched_string (op, tmp, op->contr->search_str))
1028 pick_up (op, tmp); 1032 CHK_PICK_PICKUP;
1029 continue; 1033 continue;
1030 } 1034 }
1031 1035
1032 /* high not bit set? We're using the old autopickup model */ 1036 /* high not bit set? We're using the old autopickup model */
1033 if (!(op->contr->mode & PU_NEWMODE)) 1037 if (!(op->contr->mode & PU_NEWMODE))
1035 switch (op->contr->mode) 1039 switch (op->contr->mode)
1036 { 1040 {
1037 case 0: 1041 case 0:
1038 return 1; /* don't pick up */ 1042 return 1; /* don't pick up */
1039 case 1: 1043 case 1:
1040 pick_up (op, tmp); 1044 CHK_PICK_PICKUP;
1041 return 1; 1045 return 1;
1042 case 2: 1046 case 2:
1043 pick_up (op, tmp); 1047 CHK_PICK_PICKUP;
1044 return 0; 1048 return 0;
1045 case 3: 1049 case 3:
1046 return 0; /* stop before pickup */ 1050 return 0; /* stop before pickup */
1047 case 4: 1051 case 4:
1048 pick_up (op, tmp); 1052 CHK_PICK_PICKUP;
1049 break; 1053 break;
1050 case 5: 1054 case 5:
1051 pick_up (op, tmp); 1055 CHK_PICK_PICKUP;
1052 stop = 1; 1056 stop = 1;
1053 break; 1057 break;
1054 case 6: 1058 case 6:
1055 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)) 1059 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL)
1056 pick_up (op, tmp); 1060 && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))
1061 CHK_PICK_PICKUP;
1057 break; 1062 break;
1058 1063
1059 case 7: 1064 case 7:
1060 if (tmp->type == MONEY || tmp->type == GEM) 1065 if (tmp->type == MONEY || tmp->type == GEM)
1061 pick_up (op, tmp); 1066 CHK_PICK_PICKUP;
1062 break; 1067 break;
1063 1068
1064 default: 1069 default:
1065 /* use value density */ 1070 /* use value density */
1066 if (!QUERY_FLAG (tmp, FLAG_UNPAID) 1071 if (!QUERY_FLAG (tmp, FLAG_UNPAID)
1067 && (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))) >= op->contr->mode) 1072 && (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))) >= op->contr->mode)
1068 pick_up (op, tmp); 1073 CHK_PICK_PICKUP;
1069 } 1074 }
1070 } 1075 }
1071 else 1076 else
1072 { /* old model */ 1077 { /* old model */
1073 /* NEW pickup handling */ 1078 /* NEW pickup handling */
1128 /* all food and drink if desired */ 1133 /* all food and drink if desired */
1129 /* question: don't pick up known-poisonous stuff? */ 1134 /* question: don't pick up known-poisonous stuff? */
1130 if (op->contr->mode & PU_FOOD) 1135 if (op->contr->mode & PU_FOOD)
1131 if (tmp->type == FOOD) 1136 if (tmp->type == FOOD)
1132 { 1137 {
1133 pick_up (op, tmp); 1138 CHK_PICK_PICKUP;
1134 continue; 1139 continue;
1135 } 1140 }
1136 1141
1137 if (op->contr->mode & PU_DRINK) 1142 if (op->contr->mode & PU_DRINK)
1138 if (tmp->type == DRINK || (tmp->type == POISON && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))) 1143 if (tmp->type == DRINK || (tmp->type == POISON && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)))
1139 { 1144 {
1140 pick_up (op, tmp); 1145 CHK_PICK_PICKUP;
1141 continue; 1146 continue;
1142 } 1147 }
1143 1148
1144 if (op->contr->mode & PU_POTION) 1149 if (op->contr->mode & PU_POTION)
1145 if (tmp->type == POTION) 1150 if (tmp->type == POTION)
1146 { 1151 {
1147 pick_up (op, tmp); 1152 CHK_PICK_PICKUP;
1148 continue; 1153 continue;
1149 } 1154 }
1150 1155
1151 /* spellbooks, skillscrolls and normal books/scrolls */ 1156 /* spellbooks, skillscrolls and normal books/scrolls */
1152 if (op->contr->mode & PU_SPELLBOOK) 1157 if (op->contr->mode & PU_SPELLBOOK)
1153 if (tmp->type == SPELLBOOK) 1158 if (tmp->type == SPELLBOOK)
1154 { 1159 {
1155 pick_up (op, tmp); 1160 CHK_PICK_PICKUP;
1156 continue; 1161 continue;
1157 } 1162 }
1158 1163
1159 if (op->contr->mode & PU_SKILLSCROLL) 1164 if (op->contr->mode & PU_SKILLSCROLL)
1160 if (tmp->type == SKILLSCROLL) 1165 if (tmp->type == SKILLSCROLL)
1161 { 1166 {
1162 pick_up (op, tmp); 1167 CHK_PICK_PICKUP;
1163 continue; 1168 continue;
1164 } 1169 }
1165 1170
1166 if (op->contr->mode & PU_READABLES) 1171 if (op->contr->mode & PU_READABLES)
1167 if (tmp->type == BOOK || tmp->type == SCROLL || tmp->type == INSCRIBABLE) 1172 if (tmp->type == BOOK || tmp->type == SCROLL || tmp->type == INSCRIBABLE)
1168 { 1173 {
1169 pick_up (op, tmp); 1174 CHK_PICK_PICKUP;
1170 continue; 1175 continue;
1171 } 1176 }
1172 1177
1173 /* wands/staves/rods/horns */ 1178 /* wands/staves/rods/horns */
1174 if (op->contr->mode & PU_MAGIC_DEVICE) 1179 if (op->contr->mode & PU_MAGIC_DEVICE)
1175 if (tmp->type == WAND || tmp->type == ROD || tmp->type == HORN) 1180 if (tmp->type == WAND || tmp->type == ROD || tmp->type == HORN)
1176 { 1181 {
1177 pick_up (op, tmp); 1182 CHK_PICK_PICKUP;
1178 continue; 1183 continue;
1179 } 1184 }
1180 1185
1181 /* pick up all magical items */ 1186 /* pick up all magical items */
1182 if (op->contr->mode & PU_MAGICAL) 1187 if (op->contr->mode & PU_MAGICAL)
1183 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)) 1188 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))
1184 { 1189 {
1185 pick_up (op, tmp); 1190 CHK_PICK_PICKUP;
1186 continue; 1191 continue;
1187 } 1192 }
1188 1193
1189 if (op->contr->mode & PU_VALUABLES) 1194 if (op->contr->mode & PU_VALUABLES)
1190 { 1195 {
1191 if (tmp->type == MONEY || tmp->type == GEM) 1196 if (tmp->type == MONEY || tmp->type == GEM)
1192 { 1197 {
1193 pick_up (op, tmp); 1198 CHK_PICK_PICKUP;
1194 continue; 1199 continue;
1195 } 1200 }
1196 } 1201 }
1197 1202
1198 /* rings & amulets - talismans seems to be typed AMULET */ 1203 /* rings & amulets - talismans seems to be typed AMULET */
1199 if (op->contr->mode & PU_JEWELS) 1204 if (op->contr->mode & PU_JEWELS)
1200 if (tmp->type == RING || tmp->type == AMULET) 1205 if (tmp->type == RING || tmp->type == AMULET)
1201 { 1206 {
1202 pick_up (op, tmp); 1207 CHK_PICK_PICKUP;
1203 continue; 1208 continue;
1204 } 1209 }
1205 1210
1206 /* we don't forget dragon food */ 1211 /* we don't forget dragon food */
1207 if (op->contr->mode & PU_FLESH) 1212 if (op->contr->mode & PU_FLESH)
1208 if (tmp->type == FLESH) 1213 if (tmp->type == FLESH)
1209 { 1214 {
1210 pick_up (op, tmp); 1215 CHK_PICK_PICKUP;
1211 continue; 1216 continue;
1212 } 1217 }
1213 1218
1214 /* bows and arrows. Bows are good for selling! */ 1219 /* bows and arrows. Bows are good for selling! */
1215 if (op->contr->mode & PU_BOW) 1220 if (op->contr->mode & PU_BOW)
1216 if (tmp->type == BOW) 1221 if (tmp->type == BOW)
1217 { 1222 {
1218 pick_up (op, tmp); 1223 CHK_PICK_PICKUP;
1219 continue; 1224 continue;
1220 } 1225 }
1221 1226
1222 if (op->contr->mode & PU_ARROW) 1227 if (op->contr->mode & PU_ARROW)
1223 if (tmp->type == ARROW) 1228 if (tmp->type == ARROW)
1224 { 1229 {
1225 pick_up (op, tmp); 1230 CHK_PICK_PICKUP;
1226 continue; 1231 continue;
1227 } 1232 }
1228 1233
1229 /* all kinds of armor etc. */ 1234 /* all kinds of armor etc. */
1230 if (op->contr->mode & PU_ARMOUR) 1235 if (op->contr->mode & PU_ARMOUR)
1231 if (tmp->type == ARMOUR) 1236 if (tmp->type == ARMOUR)
1232 { 1237 {
1233 pick_up (op, tmp); 1238 CHK_PICK_PICKUP;
1234 continue; 1239 continue;
1235 } 1240 }
1236 1241
1237 if (op->contr->mode & PU_HELMET) 1242 if (op->contr->mode & PU_HELMET)
1238 if (tmp->type == HELMET) 1243 if (tmp->type == HELMET)
1239 { 1244 {
1240 pick_up (op, tmp); 1245 CHK_PICK_PICKUP;
1241 continue; 1246 continue;
1242 } 1247 }
1243 1248
1244 if (op->contr->mode & PU_SHIELD) 1249 if (op->contr->mode & PU_SHIELD)
1245 if (tmp->type == SHIELD) 1250 if (tmp->type == SHIELD)
1246 { 1251 {
1247 pick_up (op, tmp); 1252 CHK_PICK_PICKUP;
1248 continue; 1253 continue;
1249 } 1254 }
1250 1255
1251 if (op->contr->mode & PU_BOOTS) 1256 if (op->contr->mode & PU_BOOTS)
1252 if (tmp->type == BOOTS) 1257 if (tmp->type == BOOTS)
1253 { 1258 {
1254 pick_up (op, tmp); 1259 CHK_PICK_PICKUP;
1255 continue; 1260 continue;
1256 } 1261 }
1257 1262
1258 if (op->contr->mode & PU_GLOVES) 1263 if (op->contr->mode & PU_GLOVES)
1259 if (tmp->type == GLOVES) 1264 if (tmp->type == GLOVES)
1260 { 1265 {
1261 pick_up (op, tmp); 1266 CHK_PICK_PICKUP;
1262 continue; 1267 continue;
1263 } 1268 }
1264 1269
1265 if (op->contr->mode & PU_CLOAK) 1270 if (op->contr->mode & PU_CLOAK)
1266 if (tmp->type == CLOAK) 1271 if (tmp->type == CLOAK)
1267 { 1272 {
1268 pick_up (op, tmp); 1273 CHK_PICK_PICKUP;
1269 continue; 1274 continue;
1270 } 1275 }
1271 1276
1272 /* hoping to catch throwing daggers here */ 1277 /* hoping to catch throwing daggers here */
1273 if (op->contr->mode & PU_MISSILEWEAPON) 1278 if (op->contr->mode & PU_MISSILEWEAPON)
1274 if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_IS_THROWN)) 1279 if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_IS_THROWN))
1275 { 1280 {
1276 pick_up (op, tmp); 1281 CHK_PICK_PICKUP;
1277 continue; 1282 continue;
1278 } 1283 }
1279 1284
1280 /* careful: chairs and tables are weapons! */ 1285 /* careful: chairs and tables are weapons! */
1281 if (op->contr->mode & PU_ALLWEAPON) 1286 if (op->contr->mode & PU_ALLWEAPON)
1283 if (tmp->type == WEAPON && tmp->name != NULL) 1288 if (tmp->type == WEAPON && tmp->name != NULL)
1284 { 1289 {
1285 if (strstr (tmp->name, "table") == NULL && strstr (tmp->arch->archname, "table") == NULL && 1290 if (strstr (tmp->name, "table") == NULL && strstr (tmp->arch->archname, "table") == NULL &&
1286 strstr (tmp->name, "chair") && strstr (tmp->arch->archname, "chair") == NULL) 1291 strstr (tmp->name, "chair") && strstr (tmp->arch->archname, "chair") == NULL)
1287 { 1292 {
1288 pick_up (op, tmp); 1293 CHK_PICK_PICKUP;
1289 continue; 1294 continue;
1290 } 1295 }
1291 } 1296 }
1292 1297
1293 if (tmp->type == WEAPON && tmp->name == NULL) 1298 if (tmp->type == WEAPON && tmp->name == NULL)
1294 { 1299 {
1295 if (strstr (tmp->arch->archname, "table") == NULL && strstr (tmp->arch->archname, "chair") == NULL) 1300 if (strstr (tmp->arch->archname, "table") == NULL && strstr (tmp->arch->archname, "chair") == NULL)
1296 { 1301 {
1297 pick_up (op, tmp); 1302 CHK_PICK_PICKUP;
1298 continue; 1303 continue;
1299 } 1304 }
1300 } 1305 }
1301 } 1306 }
1302 1307
1303 /* misc stuff that's useful */ 1308 /* misc stuff that's useful */
1304 if (op->contr->mode & PU_KEY) 1309 if (op->contr->mode & PU_KEY)
1305 if (tmp->type == KEY || tmp->type == SPECIAL_KEY) 1310 if (tmp->type == KEY || tmp->type == SPECIAL_KEY)
1306 { 1311 {
1307 pick_up (op, tmp); 1312 CHK_PICK_PICKUP;
1308 continue; 1313 continue;
1309 } 1314 }
1310 1315
1311 /* any of the last 4 bits set means we use the ratio for value 1316 /* any of the last 4 bits set means we use the ratio for value
1312 * pickups */ 1317 * pickups */
1317 /* >=7 is the old standard setting. Now we take the last 4 bits 1322 /* >=7 is the old standard setting. Now we take the last 4 bits
1318 * and multiply them by 5, giving 0..15*5== 5..75 */ 1323 * and multiply them by 5, giving 0..15*5== 5..75 */
1319 wvratio = (op->contr->mode & PU_RATIO) * 5; 1324 wvratio = (op->contr->mode & PU_RATIO) * 5;
1320 if ((query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))) >= (unsigned int) wvratio) 1325 if ((query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))) >= (unsigned int) wvratio)
1321 { 1326 {
1322 pick_up (op, tmp); 1327 CHK_PICK_PICKUP;
1323#if 0 1328#if 0
1324 fprintf (stderr, "HIGH WEIGHT/VALUE ["); 1329 fprintf (stderr, "HIGH WEIGHT/VALUE [");
1325 if (tmp->name != NULL) 1330 if (tmp->name != NULL)
1326 { 1331 {
1327 fprintf (stderr, "%s", tmp->name); 1332 fprintf (stderr, "%s", tmp->name);
1346 * found object is returned. 1351 * found object is returned.
1347 */ 1352 */
1348object * 1353object *
1349find_arrow (object *op, const char *type) 1354find_arrow (object *op, const char *type)
1350{ 1355{
1351 object *tmp = 0;
1352
1353 for (op = op->inv; op; op = op->below) 1356 for (object *tmp = op->inv; tmp; tmp = tmp->below)
1354 if (!tmp && op->type == CONTAINER && op->race == type && QUERY_FLAG (op, FLAG_APPLIED))
1355 tmp = find_arrow (op, type);
1356 else if (op->type == ARROW && op->race == type) 1357 if (tmp->type == ARROW && !strcmp (tmp->race, type))
1358 return splay (tmp);
1359
1360 for (object *tmp = op->inv; tmp; tmp = tmp->below)
1361 if (tmp->type == CONTAINER && QUERY_FLAG (tmp, FLAG_APPLIED) && !strcmp (tmp->race, type))
1362 if (object *arrow = find_arrow (tmp, type))
1363 {
1364 splay (tmp);
1357 return op; 1365 return arrow;
1366 }
1358 1367
1359 return tmp; 1368 return 0;
1360} 1369}
1361 1370
1362/* 1371/*
1363 * Similar to find_arrow, but looks for (roughly) the best arrow to use 1372 * Similar to find_arrow, but looks for (roughly) the best arrow to use
1364 * against the target. A full test is not performed, simply a basic test 1373 * against the target. A full test is not performed, simply a basic test

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines