added worldarea -> will be responsible for world map rendering
[dboe.git] / items.c
blobe5f6545b09a29ab5abd71f1ec648ad5d16a431cf
1 #include <windows.h>
3 #include "global.h"
5 #include "graphics.h"
6 #include "text.h"
7 #include "dlogtool.h"
8 #include "items.h"
9 #include "party.h"
10 #include "fields.h"
11 #include "locutils.h"
12 #include "newgraph.h"
13 #include "dlogtool.h"
14 #include "itemdata.h"
15 #include "infodlgs.h"
16 #include "exlsound.h"
17 #include "stdio.h"
18 #include "string.h"
19 #include "graphutl.h"
20 #include "monster.h"
22 extern short stat_window,overall_mode,current_cursor,which_combat_type,current_pc;
23 extern party_record_type far party;
24 extern piles_of_stuff_dumping_type *data_store;
25 extern piles_of_stuff_dumping_type2 *data_store2;
26 extern talking_record_type far talking;
27 extern scenario_data_type far scenario;
29 extern current_town_type far c_town;
30 extern town_item_list far t_i;
31 extern HWND mainPtr;
32 extern Boolean in_startup_mode,boom_anim_active;
33 extern HANDLE store_hInstance;
35 extern pc_record_type far adven[6];
36 extern big_tr_type far t_d;
37 extern location pc_pos[6];
39 extern HCURSOR sword_curs;
40 extern Boolean modeless_exists[18],diff_depth_ok;
41 extern short modeless_key[18];
42 extern HWND modeless_dialogs[18];
43 extern short town_size[3];
44 extern short town_type;
45 extern FARPROC modeless_dlogprocs[18];
46 extern short dialog_answer;
47 extern pascal Boolean cd_event_filter();
48 extern Boolean dialog_not_toast;
49 extern HBITMAP pcs_gworld;
50 extern HDC main_dc,main_dc2,main_dc3;
52 ////
53 Boolean equippable[26] = {FALSE,TRUE,TRUE,FALSE,TRUE, TRUE,TRUE,FALSE,FALSE,FALSE,
54 TRUE,FALSE,TRUE,TRUE,TRUE, TRUE,TRUE,TRUE,TRUE,TRUE,
55 FALSE,FALSE,TRUE,TRUE,TRUE,TRUE};
56 short num_hands_to_use[26] = {0,1,2,0,0, 0,0,0,0,0 ,0,0,1,0,0, 0,1,0,0,0, 0,0,0,0,0, 0};
57 short num_that_can_equip[26] = {0,2,1,0,1, 1,1,0,0,0, 1,0,1,1,1, 1,1,1,2,1, 0,0,1,1,1, 1};
59 // For following, if an item of type n is equipped, no other items of type n can be equipped,
60 // if n > 0
61 short excluding_types[26] = {0,0,0,0,2, 1,1,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,2,1, 2};
63 short selected,item_max = 0;
65 short first_item_shown,store_get_mode,current_getting_pc,store_pcnum,total_items_gettable; // these 5 used for get items dialog
66 short item_array[130]; // NUM_TOWN_ITEMS + a bit
68 short answer_given = 1;
70 char *store_str;
71 short store_dnum;
73 HWND test_dlog3;
74 HWND store_focus;
75 FARPROC dlog_proc1;
77 short being_created;
78 short procinst_exists[18] = {0,0,0,0,0, 0,0,0,0,0 ,0,0,0,0,0, 0,0,0};
80 void sort_pc_items(short pc_num)
82 item_record_type store_item;
83 short item_priority[26] = {20,8,8,20,9, 9,3,2,1,0, 7,20,10,10,10, 10,10,10,5,6, 4,11,12,9,9, 9};
84 Boolean no_swaps = FALSE,store_equip;
85 short i;
87 while (no_swaps == FALSE) {
88 no_swaps = TRUE;
89 for (i = 0; i < 23; i++)
90 if (item_priority[adven[pc_num].items[i + 1].variety] <
91 item_priority[adven[pc_num].items[i].variety]) {
92 no_swaps = FALSE;
93 store_item = adven[pc_num].items[i + 1];
94 adven[pc_num].items[i + 1] = adven[pc_num].items[i];
95 adven[pc_num].items[i] = store_item;
96 store_equip = adven[pc_num].equip[i + 1];
97 adven[pc_num].equip[i + 1] = adven[pc_num].equip[i];
98 adven[pc_num].equip[i] = store_equip;
99 if (adven[pc_num].weap_poisoned == i + 1)
100 adven[pc_num].weap_poisoned--;
101 else if (adven[pc_num].weap_poisoned == i)
102 adven[pc_num].weap_poisoned++;
107 Boolean give_to_pc(short pc_num,item_record_type item,short print_result)
109 short free_space;
110 char announce_string[60];
112 if (item.variety == 0)
113 return TRUE;
114 if (item.variety == 3) {
115 party.gold += item.item_level;
116 ASB("You get some gold.");
117 return TRUE;
119 if (item.variety == 11) {
120 party.food += item.item_level;
121 ASB("You get some food.");
122 return TRUE;
124 if (item_weight(item) >
125 amount_pc_can_carry(pc_num) - pc_carry_weight(pc_num)) {
126 if (print_result == TRUE) {
127 SysBeep(20);
128 ASB("Item too heavy to carry.");
130 return FALSE;
132 if (((free_space = pc_has_space(pc_num)) == 24) || (adven[pc_num].main_status != 1))
133 return FALSE;
134 else {
135 item.item_properties = item.item_properties & 253; // not property
136 item.item_properties = item.item_properties & 247; // not contained
137 adven[pc_num].items[free_space] = item;
139 if (print_result == 1) {
140 if (stat_window == pc_num)
141 put_item_screen(stat_window,0);
143 if (in_startup_mode == FALSE) {
144 if (is_ident(item) == 0)
145 sprintf((char *) announce_string," %s gets %s.",adven[pc_num].name,item.name);
146 else sprintf((char *) announce_string," %s gets %s.",adven[pc_num].name,item.full_name);
147 if (print_result == TRUE)
148 add_string_to_buf((char *)announce_string);
151 combine_things(pc_num);
152 sort_pc_items(pc_num);
153 return TRUE;
155 return FALSE;
158 Boolean give_to_party(item_record_type item,short print_result)
160 short free_space, i = 0;
162 while (i < 6) {
163 if (give_to_pc(i,item,print_result) == TRUE)
164 return TRUE;
165 i++;
167 return FALSE;
170 Boolean forced_give(short item_num,short abil)
171 // if abil > 0, force abil, else ignore
173 short i,j;
174 item_record_type item;
175 char announce_string[60];
177 if ((item_num < 0) || (item_num > 399))
178 return TRUE;
179 item = get_stored_item(item_num);
180 if (abil > 0)
181 item.ability = abil;
182 for (i = 0; i < 6; i++)
183 for (j = 0; j < 24; j++)
184 if ((adven[i].main_status == 1) && (adven[i].items[j].variety == 0)) {
185 adven[i].items[j] = item;
187 if (is_ident(item) == 0)
188 sprintf((char *) announce_string," %s gets %s.",adven[i].name,item.name);
189 else sprintf((char *) announce_string," %s gets %s.",adven[i].name,item.full_name);
190 add_string_to_buf((char *)announce_string);
191 combine_things(i);
192 sort_pc_items(i);
193 return TRUE;
195 return FALSE;
198 Boolean GTP(short item_num)
200 item_record_type item;
202 item = get_stored_item(item_num);
203 return give_to_party(item,TRUE);
205 Boolean silent_GTP(short item_num)
207 item_record_type item;
209 item = get_stored_item(item_num);
210 return give_to_party(item,FALSE);
212 void give_gold(short amount,Boolean print_result)
214 if (amount < 0) return;
215 party.gold = party.gold + amount;
216 if (print_result == TRUE)
217 put_pc_screen();
220 Boolean take_gold(short amount,Boolean print_result)
222 if (party.gold < amount)
223 return FALSE;
224 party.gold = party.gold - amount;
225 if (print_result == TRUE)
226 put_pc_screen();
227 return TRUE;
230 // returnes equipped protection level of specified abil, or -1 if no such abil is equipped
231 short get_prot_level(short pc_num,short abil) ////
233 short i = 0;
235 for (i = 0; i < 24; i++)
236 if ((adven[pc_num].items[i].variety != 0) && (adven[pc_num].items[i].ability == abil)
237 && (adven[pc_num].equip[i] == TRUE))
238 return adven[pc_num].items[i].ability_strength;
239 return -1;
243 short pc_has_abil_equip(short pc_num,short abil)
245 short i = 0;
247 while (((adven[pc_num].items[i].variety == 0) || (adven[pc_num].items[i].ability != abil)
248 || (adven[pc_num].equip[i] == FALSE)) && (i < 24))
249 i++;
250 return i;
254 short pc_has_abil(short pc_num,short abil)
256 short i = 0;
258 while (((adven[pc_num].items[i].variety == 0) || (adven[pc_num].items[i].ability != abil)
259 ) && (i < 24))
260 i++;
261 return i;
264 Boolean party_has_abil(short abil)
266 short i;
268 for (i = 0; i < 6; i++)
269 if (adven[i].main_status == 1)
270 if (pc_has_abil(i,abil) < 24)
271 return TRUE;
272 return FALSE;
275 Boolean party_take_abil(short abil)
277 short i,item;
279 for (i = 0; i < 6; i++)
280 if (adven[i].main_status == 1)
281 if ((item = pc_has_abil(i,abil)) < 24) {
282 if (adven[i].items[item].charges > 1)
283 adven[i].items[item].charges--;
284 else take_item(i,item);
285 return TRUE;
287 return FALSE;
290 short amount_pc_can_carry(short pc_num)
292 return 100 + (15 * min(adven[pc_num].skills[0],20)) + ((adven[pc_num].traits[8] == 0) ? 0 : 30)
293 + ((adven[pc_num].traits[14] == 0) ? 0 : -50);
295 short pc_carry_weight(short pc_num)
297 short i,storage = 0;
298 Boolean airy = FALSE,heavy = FALSE;
300 for (i = 0; i < 24; i++)
301 if (adven[pc_num].items[i].variety > 0) {
302 storage += item_weight(adven[pc_num].items[i]);
303 if (adven[pc_num].items[i].ability == 44)
304 airy = TRUE;
305 if (adven[pc_num].items[i].ability == 45)
306 heavy = TRUE;
308 if (airy == TRUE)
309 storage -= 30;
310 if (heavy == TRUE)
311 storage += 30;
312 if (storage < 0)
313 storage = 0;
314 return storage;
316 short item_weight(item_record_type item)
318 if (item.variety == 0)
319 return 0;
320 if ((item.variety == 5) || (item.variety == 6) || (item.variety == 24) || (item.variety == 7)
321 || ((item.variety == 21) && (item.charges > 0)))
322 return (short) (item.charges) * (short) (item.weight);
323 return (short) (item.weight);
326 void give_food(short amount,Boolean print_result)
328 if (amount < 0) return;
329 party.food = party.food + amount;
330 if (print_result == TRUE)
331 put_pc_screen();
334 short take_food(short amount,Boolean print_result)
336 short diff;
338 diff = amount - party.food;
339 if (diff > 0) {
340 party.food = 0;
341 if (print_result == TRUE)
342 put_pc_screen();
343 return diff;
346 party.food = party.food - amount;
347 if (print_result == TRUE)
348 put_pc_screen();
349 return 0;
352 short pc_has_space(short pc_num)
354 short i = 0;
356 while (i < 24) {
357 if (adven[pc_num].items[i].variety == 0)
358 return i;
359 i++;
361 return 24;
364 // returns 1 if OK, 2 if no room, 3 if not enough cash, 4 if too heavy, 5 if too many of item
365 short pc_ok_to_buy(short pc_num,short cost,item_record_type item)
367 short i;
369 if ((item.variety != 3) && (item.variety != 11)) {
370 for (i = 0; i < 24; i++)
371 if ((adven[pc_num].items[i].variety > 0) && (adven[pc_num].items[i].type_flag == item.type_flag)
372 && (adven[pc_num].items[i].charges > 123))
373 return 5;
375 if (pc_has_space(pc_num) == 24)
376 return 2;
377 if (item_weight(item) >
378 amount_pc_can_carry(pc_num) - pc_carry_weight(pc_num)) {
379 return 4;
382 if (take_gold(cost,FALSE) == FALSE)
383 return 3;
384 return 1;
389 void take_item(short pc_num,short which_item)
390 //short pc_num,which_item; // if which_item > 30, don't update stat win, item is which_item - 30
392 short i;
393 Boolean do_print = TRUE;
395 if (which_item >= 30) {
396 do_print = FALSE;
397 which_item -= 30;
400 if ((adven[pc_num].weap_poisoned == which_item) && (adven[pc_num].status[0] > 0)) {
401 add_string_to_buf(" Poison lost. ");
402 adven[pc_num].status[0] = 0;
404 if ((adven[pc_num].weap_poisoned > which_item) && (adven[pc_num].status[0] > 0))
405 adven[pc_num].weap_poisoned--;
407 for (i = which_item; i < 23; i++) {
408 adven[pc_num].items[i] = adven[pc_num].items[i + 1];
409 adven[pc_num].equip[i] = adven[pc_num].equip[i + 1];
411 adven[pc_num].items[23] = return_dummy_item();
412 adven[pc_num].equip[23] = FALSE;
414 if ((stat_window == pc_num) && (do_print == TRUE))
415 put_item_screen(stat_window,1);
418 void remove_charge(short pc_num,short which_item)
420 if (adven[pc_num].items[which_item].charges > 0) {
421 adven[pc_num].items[which_item].charges--;
422 if (adven[pc_num].items[which_item].charges == 0) {
423 take_item(pc_num,which_item);
427 if (stat_window == pc_num)
428 put_item_screen(stat_window,1);
432 void enchant_weapon(short pc_num,short item_hit,short enchant_type,short new_val)
434 char store_name[60];
436 ////
437 if ((is_magic(adven[pc_num].items[item_hit]) == TRUE) ||
438 (adven[pc_num].items[item_hit].ability != 0))
439 return;
440 adven[pc_num].items[item_hit].item_properties |= 4;
441 switch (enchant_type) {
442 case 0:
443 sprintf((char *)store_name,"%s (+1)",adven[pc_num].items[item_hit].full_name);
444 adven[pc_num].items[item_hit].bonus++;
445 adven[pc_num].items[item_hit].value = new_val;
446 break;
447 case 1:
448 sprintf((char *)store_name,"%s (+2)",adven[pc_num].items[item_hit].full_name);
449 adven[pc_num].items[item_hit].bonus += 2;
450 adven[pc_num].items[item_hit].value = new_val;
451 break;
452 case 2:
453 sprintf((char *)store_name,"%s (+3)",adven[pc_num].items[item_hit].full_name);
454 adven[pc_num].items[item_hit].bonus += 3;
455 adven[pc_num].items[item_hit].value = new_val;
456 break;
457 case 3:
458 sprintf((char *)store_name,"%s (F)",adven[pc_num].items[item_hit].full_name);
459 adven[pc_num].items[item_hit].ability = 110;
460 adven[pc_num].items[item_hit].ability_strength = 5;
461 adven[pc_num].items[item_hit].charges = 8;
462 break;
463 case 4:
464 sprintf((char *)store_name,"%s (F!)",adven[pc_num].items[item_hit].full_name);
465 adven[pc_num].items[item_hit].value = new_val;
466 adven[pc_num].items[item_hit].ability = 1;
467 adven[pc_num].items[item_hit].ability_strength = 5;
468 break;
469 case 5:
470 sprintf((char *)store_name,"%s (+5)",adven[pc_num].items[item_hit].full_name);
471 adven[pc_num].items[item_hit].value = new_val;
472 adven[pc_num].items[item_hit].bonus += 5;
473 break;
474 case 6:
475 sprintf((char *)store_name,"%s (B)",adven[pc_num].items[item_hit].full_name);
476 adven[pc_num].items[item_hit].bonus++;
477 adven[pc_num].items[item_hit].ability = 71;
478 adven[pc_num].items[item_hit].ability_strength = 5;
479 adven[pc_num].items[item_hit].magic_use_type = 0;
480 adven[pc_num].items[item_hit].charges = 8;
481 break;
482 default:
483 strcpy(store_name,adven[pc_num].items[item_hit].full_name);
484 break;
486 if (adven[pc_num].items[item_hit].value > 15000)
487 adven[pc_num].items[item_hit].value = 15000;
488 if (adven[pc_num].items[item_hit].value < 0)
489 adven[pc_num].items[item_hit].value = 15000;
490 strcpy(adven[pc_num].items[item_hit].full_name,store_name);
493 void equip_item(short pc_num,short item_num)
495 short num_equipped_of_this_type = 0;
496 short num_hands_occupied = 0;
497 short i;
498 short equip_item_type = 0;
500 if ((overall_mode == 10) && (adven[pc_num].items[item_num].variety == 11))
501 add_string_to_buf("Equip: Not in combat");
502 else {
504 // unequip
505 if (adven[pc_num].equip[item_num] == TRUE) {
506 if ((adven[pc_num].equip[item_num] == TRUE) &&
507 (is_cursed(adven[pc_num].items[item_num]) == TRUE))
508 add_string_to_buf("Equip: Item is cursed. ");
509 else {
510 adven[pc_num].equip[item_num] = FALSE;
511 add_string_to_buf("Equip: Unequipped");
512 if ((adven[pc_num].weap_poisoned == item_num) && (adven[pc_num].status[0] > 0)) {
513 add_string_to_buf(" Poison lost. ");
514 adven[pc_num].status[0] = 0;
519 else { // equip
520 if (equippable[adven[pc_num].items[item_num].variety] == FALSE)
521 add_string_to_buf("Equip: Can't equip this item.");
522 else {
523 for (i = 0; i < 24; i++)
524 if (adven[pc_num].equip[i] == TRUE) {
525 if (adven[pc_num].items[i].variety == adven[pc_num].items[item_num].variety)
526 num_equipped_of_this_type++;
527 num_hands_occupied = num_hands_occupied + num_hands_to_use[adven[pc_num].items[i].variety];
531 equip_item_type = excluding_types[adven[pc_num].items[item_num].variety];
532 // Now if missile is already equipped, no more missiles
533 if (equip_item_type > 0) {
534 for (i = 0; i < 24; i++)
535 if ((adven[pc_num].equip[i] == TRUE) && (excluding_types[adven[pc_num].items[i].variety] == equip_item_type)) {
536 add_string_to_buf("Equip: You have something of");
537 add_string_to_buf(" this type equipped.");
538 return;
542 if ((is_combat()) && (adven[pc_num].items[item_num].variety == 13))
543 add_string_to_buf("Equip: Not armor in combat");
544 else if ((2 - num_hands_occupied) < num_hands_to_use[adven[pc_num].items[item_num].variety])
545 add_string_to_buf("Equip: Not enough free hands");
546 else if (num_that_can_equip[adven[pc_num].items[item_num].variety] <= num_equipped_of_this_type)
547 add_string_to_buf("Equip: Can't equip another");
548 else {
549 adven[pc_num].equip[item_num] = TRUE;
550 add_string_to_buf("Equip: OK");
556 if (stat_window == pc_num)
557 put_item_screen(stat_window,1);
561 void drop_item(short pc_num,short item_num,location where_drop)
564 short choice,how_many = 0;
565 item_record_type item_store;
566 Boolean take_given_item = TRUE;
567 location loc;
569 item_store = adven[pc_num].items[item_num];
571 if ((adven[pc_num].equip[item_num] == TRUE) &&
572 (is_cursed(adven[pc_num].items[item_num]) == TRUE))
573 add_string_to_buf("Drop: Item is cursed. ");
574 else switch (overall_mode) {
575 case 0:
576 choice = fancy_choice_dialog(1093,0);
577 if (choice == 1)
578 return;
579 add_string_to_buf("Drop: OK");
580 if ((item_store.type_flag > 0) && (item_store.charges > 1)) {
581 how_many = get_num_of_items(item_store.charges);
582 if (how_many == item_store.charges)
583 take_item(pc_num,item_num);
584 else adven[pc_num].items[item_num].charges -= how_many;
586 else take_item(pc_num,item_num);
587 break;
589 case 5: case 15:
590 loc = where_drop;
591 if ((item_store.type_flag > 0) && (item_store.charges > 1)) {
592 how_many = get_num_of_items(item_store.charges);
593 if (how_many <= 0)
594 return;
595 if (how_many < item_store.charges)
596 take_given_item = FALSE;
597 item_store.charges = how_many;
599 if (is_container(loc) == TRUE)
600 item_store.item_properties = item_store.item_properties | 8;
601 if (place_item(item_store,loc,FALSE) == FALSE) {
602 add_string_to_buf("Drop: Too many items on ground");
603 item_store.item_properties = item_store.item_properties & 247; // not contained
605 else {
606 if (is_contained(item_store) == TRUE)
607 add_string_to_buf("Drop: Item put away");
608 else add_string_to_buf("Drop: OK");
609 adven[pc_num].items[item_num].charges -= how_many;
610 if (take_given_item)
611 take_item(pc_num,item_num);
613 break;
617 Boolean place_item(item_record_type item,location where,Boolean forced)
619 short i;
621 for (i = 0; i < NUM_TOWN_ITEMS; i++)
622 if (t_i.items[i].variety == 0) {
623 t_i.items[i] = item;
624 t_i.items[i].item_loc = where;
625 reset_item_max();
626 return TRUE;
628 if (forced == FALSE)
629 return FALSE;
630 destroy_an_item();
631 for (i = 0; i < NUM_TOWN_ITEMS; i++)
632 if (t_i.items[i].variety == 0) {
633 t_i.items[i] = item;
634 t_i.items[i].item_loc = where;
635 reset_item_max();
636 return TRUE;
639 return TRUE;
642 void destroy_an_item()
644 ////
645 short i,j;
646 ASB("Too many items. Some item destroyed.");
647 for (i = 0; i < NUM_TOWN_ITEMS; i++)
648 if (t_i.items[i].type_flag == 15) {
649 t_i.items[i].variety = 0;
650 return;
652 for (i = 0; i < NUM_TOWN_ITEMS; i++)
653 if (t_i.items[i].value < 3) {
654 t_i.items[i].variety = 0;
655 return;
657 for (i = 0; i < NUM_TOWN_ITEMS; i++)
658 if (t_i.items[i].value < 30) {
659 t_i.items[i].variety = 0;
660 return;
662 for (i = 0; i < NUM_TOWN_ITEMS; i++)
663 if (is_magic(t_i.items[i]) == FALSE) {
664 t_i.items[i].variety = 0;
665 return;
667 i = get_ran(1,0,NUM_TOWN_ITEMS);
668 t_i.items[i].variety = 0;
672 void give_thing(short pc_num, short item_num)
674 short who_to,how_many = 0;
675 item_record_type item_store;
676 Boolean take_given_item = TRUE;
678 if ((adven[pc_num].equip[item_num] == TRUE) &&
679 (is_cursed(adven[pc_num].items[item_num]) == TRUE))
680 add_string_to_buf("Give: Item is cursed. ");
681 else {
682 item_store = adven[pc_num].items[item_num];
683 who_to = char_select_pc(1,1,"Give item to who?");
684 if ((overall_mode == 10) && (adjacent(pc_pos[pc_num],pc_pos[who_to]) == FALSE)) {
685 add_string_to_buf("Give: Must be adjacent.");
686 who_to = 6;
689 if ((who_to < 6) && (who_to != pc_num)
690 && ((overall_mode != 10) || (adjacent(pc_pos[pc_num],pc_pos[who_to]) == TRUE))) {
691 if ((item_store.type_flag > 0) && (item_store.charges > 1)) {
692 how_many = get_num_of_items(item_store.charges);
693 if (how_many == 0)
694 return;
695 if (how_many < item_store.charges)
696 take_given_item = FALSE;
697 adven[pc_num].items[item_num].charges -= how_many;
698 item_store.charges = how_many;
700 if (give_to_pc(who_to,item_store,0) == TRUE) {
701 if (take_given_item)
702 take_item(pc_num,item_num);
704 else {
705 if (pc_has_space(who_to) == 24)
706 ASB("Can't give: PC has max. # of items.");
707 else ASB("Can't give: PC carrying too much.");
708 if (how_many > 0)
709 adven[pc_num].items[item_num].charges += how_many;
715 void combine_things(short pc_num)
717 short i,j,test;
719 for (i = 0; i < 24; i++) {
720 if ((adven[pc_num].items[i].variety > 0) &&
721 (adven[pc_num].items[i].type_flag > 0) && (is_ident(adven[pc_num].items[i]))) {
722 for (j = i + 1; j < 24; j++)
723 if ((adven[pc_num].items[j].variety > 0) &&
724 (adven[pc_num].items[j].type_flag == adven[pc_num].items[i].type_flag)
725 && (is_ident(adven[pc_num].items[j]))) {
726 add_string_to_buf("(items combined)");
727 test = (short) (adven[pc_num].items[i].charges) + (short) (adven[pc_num].items[j].charges);
728 if (test > 125) {
729 adven[pc_num].items[i].charges = 125;
730 ASB("(Can have at most 125 of any item.");
732 else adven[pc_num].items[i].charges += adven[pc_num].items[j].charges;
733 if (adven[pc_num].equip[j] == TRUE) {
734 adven[pc_num].equip[i] = TRUE;
735 adven[pc_num].equip[j] = FALSE;
737 take_item(pc_num,30 + j);
740 if ((adven[pc_num].items[i].variety > 0) && (adven[pc_num].items[i].charges < 0))
741 adven[pc_num].items[i].charges = 1;
745 // Procedure only ready for town and outdoor
746 short dist_from_party(location where)
748 short store = 1000, i;
750 if ((overall_mode >= 10) && (overall_mode < 20)) {
751 for (i = 0; i < 6; i++)
752 if (adven[i].main_status == 1)
753 store = min(store,dist(pc_pos[i],where));
755 else store = dist(c_town.p_loc,where);
757 return store;
760 void set_item_flag(item_record_type *item)
762 if ((item->is_special > 0) && (item->is_special < 65)) {
763 item->is_special--;
764 party.item_taken[c_town.town_num][item->is_special / 8] =
765 party.item_taken[c_town.town_num][item->is_special / 8] | s_pow(2,item->is_special % 8);
766 item->is_special = 0;
770 short get_item(location place,short pc_num,Boolean check_container)
771 //short pc_num; // if 6, any
773 short i,taken = 0,who_take,choice;
774 char message[60];
775 Boolean item_near = FALSE,gold_sound = FALSE,food_sound = FALSE;
776 short mass_get = 1;
778 for (i = 0; i < T_M; i++)
779 if ((c_town.monst.dudes[i].active > 0) && (c_town.monst.dudes[i].attitude == 1)
780 && (can_see(place,c_town.monst.dudes[i].m_loc,0) < 5))
781 mass_get = 0;
783 for (i = 0; i < NUM_TOWN_ITEMS; i++)
784 if (t_i.items[i].variety != 0)
785 if (((adjacent(place,t_i.items[i].item_loc) == TRUE) ||
786 ((mass_get == 1) && (check_container == FALSE) &&
787 ((dist(place,t_i.items[i].item_loc) <= 4) || ((is_combat()) && (which_combat_type == 0)))
788 && (can_see(place,t_i.items[i].item_loc,0) < 5)))
789 && ((is_contained(t_i.items[i]) == FALSE) || (check_container == TRUE))) {
790 taken = 1;
792 if (t_i.items[i].value < 2)
793 t_i.items[i].item_properties = t_i.items[i].item_properties | 1;
794 item_near = TRUE;
796 if (item_near == TRUE)
797 if (display_item(place,pc_num,mass_get,check_container) > 0) { // if true, there was a theft
798 for (i = 0; i < T_M; i++)
799 if ((c_town.monst.dudes[i].active > 0) && (c_town.monst.dudes[i].attitude % 2 != 1)
800 && (can_see(place,c_town.monst.dudes[i].m_loc,0) < 5)) {
801 make_town_hostile();
802 i = T_M;
803 add_string_to_buf("Your crime was seen!");
807 if (pc_num != 10) {
808 if (taken == 0)
809 add_string_to_buf("Get: nothing here");
810 else add_string_to_buf("Get: OK");
813 reset_item_max();
815 return taken;
818 void make_town_hostile()
820 short i,num;
821 Boolean fry_party = FALSE;
823 if (which_combat_type == 0)
824 return;
825 give_help(53,0,0);
826 c_town.monst.friendly = 1;
827 ////
828 for (i = 0; i < T_M; i++)
829 if ((c_town.monst.dudes[i].active > 0) && (c_town.monst.dudes[i].summoned == 0)){
830 c_town.monst.dudes[i].attitude = 1;
831 num = c_town.monst.dudes[i].number;
832 c_town.monst.dudes[i].mobile = TRUE;
833 if (scenario.scen_monsters[num].spec_skill == 37) {
834 c_town.monst.dudes[i].active = 2;
836 // If a town, give pwoer boost
837 c_town.monst.dudes[i].m_d.health *= 3;
838 c_town.monst.dudes[i].m_d.status[3] = 8;
839 c_town.monst.dudes[i].m_d.status[1] = 8;
843 // In some towns, doin' this'll getcha' killed.
844 //// wedge in special
846 if (fry_party == TRUE) {
847 for (i = 0; i < 6; i++)
848 if (adven[i].main_status > 0)
849 adven[i].main_status = 0;
850 stat_window = 6;
851 boom_anim_active = FALSE;
856 void put_item_graphics()
858 short i,storage;
859 short item_hit,what_talk_field;
860 item_record_type item;
861 char message[256];
863 // First make sure all arrays for who can get stuff are in order.
864 if ((current_getting_pc < 6) && ((adven[current_getting_pc].main_status != 1)
865 || (pc_has_space(current_getting_pc) == 24))) {
866 current_getting_pc = 6;
869 for (i = 0; i < 6; i++)
870 if ((adven[i].main_status == 1) && (pc_has_space(i) < 24)
871 && ((!is_combat()) || (current_pc == i))) {
872 if (current_getting_pc == 6)
873 current_getting_pc = i;
874 cd_activate_item(987,3 + i,1);
876 else {
877 cd_activate_item(987,3 + i,0);
878 cd_activate_item(987,11 + i,0);
880 for (i = 0; i < 6; i++)
881 if (current_getting_pc == i)
882 cd_add_label(987,3 + i,"* ",1007);
883 else cd_add_label(987,3 + i," ",1007);
885 // darken arrows, as appropriate
886 if (first_item_shown == 0)
887 cd_activate_item(987,9,0);
888 else cd_activate_item(987,9,1);
889 if ((first_item_shown > total_items_gettable - 7) ||
890 (total_items_gettable <= 8) )
891 cd_activate_item(987,10,0);
892 else cd_activate_item(987,10,1);
894 for (i = 0; i < 8; i++) {
895 // first, clear whatever item graphic is there
896 csp(987,20 + i * 4,950);
898 if (item_array[i + first_item_shown] != 200) { // display an item in window
899 item = t_i.items[item_array[i + first_item_shown]];
901 sprintf ((char *) message, "%s",
902 (is_ident(item) == TRUE) ? (char *) item.full_name : (char *) item.name);
903 csit(987,21 + i * 4,(char *) message);
904 if (item.graphic_num >= 150)
905 csp(987,20 + i * 4,3000 + 2000 + item.graphic_num - 150);
906 else csp(987,20 + i * 4,4800 + item.graphic_num);////
907 get_item_interesting_string(item,(char *) message);
908 csit(987,22 + i * 4,(char *) message);
909 storage = item_weight(item);
910 sprintf ((char *) message, "Weight: %d",storage);
911 csit(987,53 + i,(char *) message);
914 else { // erase the spot
915 sprintf ((char *) message, "");
916 csit(987,21 + i * 4,(char *) message);
917 csit(987,22 + i * 4,(char *) message);
918 csit(987,53 + i,(char *) message);
922 if (current_getting_pc < 6) {
923 i = amount_pc_can_carry(current_getting_pc);
924 storage = pc_carry_weight(current_getting_pc);
925 sprintf ((char *) message, "%s is carrying %d out of %d.",adven[current_getting_pc].name,storage,i);
926 csit(987,52,(char *) message);
929 for (i = 0; i < 6; i++)
930 if (adven[i].main_status == 1) {
931 csp(987,11 + i,800 + adven[i].which_graphic);
936 void display_item_event_filter (short item_hit)
938 item_record_type item;
939 short i,store_dlog_ans;
941 switch (item_hit) {
942 case 1:
943 dialog_not_toast = FALSE;
944 break;
945 case 9:
946 if (first_item_shown > 0)
947 first_item_shown -= 8;
948 put_item_graphics();
949 break;
950 case 10:
951 if (first_item_shown < 116)
952 first_item_shown += 8;
953 put_item_graphics();
954 break;
955 case 3: case 4: case 5: case 6:case 7: case 8:
956 current_getting_pc = item_hit - 3;
957 put_item_graphics();
958 break;
959 default:
960 if (current_getting_pc == 6) {
961 break;
963 item_hit = (item_hit - 19) / 4;
964 item_hit += first_item_shown;
965 if (item_array[item_hit] >= NUM_TOWN_ITEMS)
966 break;
967 item = t_i.items[item_array[item_hit]];
968 if (is_property(item) == TRUE) {
969 i = (dialog_answer == 0) ? fancy_choice_dialog(1011,987) : 2;
970 if (i == 1)
971 break;
972 else {
973 dialog_answer = 1;
974 item.item_properties = item.item_properties & 253;
979 if (t_i.items[item_array[item_hit]].variety == 3) {
980 if (t_i.items[item_array[item_hit]].item_level > 3000)
981 t_i.items[item_array[item_hit]].item_level = 3000;
982 set_item_flag(&item);
983 give_gold(t_i.items[item_array[item_hit]].item_level,FALSE);
984 force_play_sound(39);
986 else if (t_i.items[item_array[item_hit]].variety == 11) {
987 give_food(t_i.items[item_array[item_hit]].item_level,FALSE);
988 set_item_flag(&item);
989 set_item_flag(&t_i.items[item_array[item_hit]]);
990 force_play_sound(62);
992 else {
993 if (item_weight(item) >
994 amount_pc_can_carry(current_getting_pc) - pc_carry_weight(current_getting_pc)) {
995 SysBeep(20);
996 csit(987,52,"It's too heavy to carry.");
997 give_help(38,0,987);
998 break;
1001 set_item_flag(&item);
1002 force_play_sound(0);
1003 give_to_pc(current_getting_pc, item, 0);
1005 t_i.items[item_array[item_hit]] = return_dummy_item();
1006 for (i = item_hit; i < 125; i++)
1007 item_array[i] = item_array[i + 1];
1008 total_items_gettable--;
1009 put_item_graphics();
1010 break;
1016 // Returns TRUE is a theft committed
1017 short display_item(location from_loc,short pc_num,short mode, Boolean check_container)
1018 //pc_num; // < 6 - this pc only 6 - any pc
1019 //short mode; // 0 - adjacent 1 - all in sight
1021 short item_hit,i,array_position = 0;
1022 char message[256];
1024 make_cursor_sword();
1026 first_item_shown = 0;
1027 store_get_mode = mode;
1028 current_getting_pc = current_pc;
1029 store_pcnum = pc_num;
1030 dialog_answer = 0;
1032 for (i = 0; i < 130; i++)
1033 item_array[i] = 200;
1035 total_items_gettable = 0;
1036 for (i = 0; i < NUM_TOWN_ITEMS; i++)
1037 if (t_i.items[i].variety != 0) {
1038 if (((adjacent(from_loc,t_i.items[i].item_loc) == TRUE) ||
1039 ((mode == 1) && (check_container == FALSE) &&
1040 ((dist(from_loc,t_i.items[i].item_loc) <= 4) || ((is_combat()) && (which_combat_type == 0)))
1041 && (can_see(from_loc,t_i.items[i].item_loc,0) < 5))) &&
1042 (is_contained(t_i.items[i]) == check_container) &&
1043 ((check_container == FALSE) || (same_point(t_i.items[i].item_loc,from_loc) == TRUE))) {
1044 item_array[array_position] = i;
1045 array_position++;
1046 total_items_gettable++;
1049 if (pcs_gworld == NULL)
1050 pcs_gworld = load_pict(902,main_dc);
1051 cd_create_dialog(987,mainPtr);
1053 if (check_container == TRUE)
1054 csit(987,17,"Looking in container:");
1055 else if (mode == 0)
1056 csit(987,17,"Getting all adjacent items:");
1057 else csit(987,17,"Getting all nearby items:");
1058 cd_set_flag(987,18,1);
1059 cd_set_flag(987,51,0);
1060 cd_set_flag(987,52,0);
1061 for (i = 0; i < 8; i++)
1062 cd_attach_key(987,19 + 4 * i,(char) (97 + i));
1063 put_item_graphics();
1065 if (party.help_received[36] == 0) {
1066 cd_initial_draw(987);
1067 give_help(36,37,987);
1070 while (dialog_not_toast)
1071 ModalDialog();
1073 cd_kill_dialog(987,0);
1075 DisposeGWorld(pcs_gworld);
1076 pcs_gworld = NULL;
1078 put_item_screen(stat_window,0);
1079 put_pc_screen();
1081 return dialog_answer;
1086 short custom_choice_dialog(char *strs,short pic_num,short buttons[3]) ////
1089 short item_hit,i,store_dialog_answer;
1090 char temp_str[256];
1092 store_dialog_answer = dialog_answer;
1093 make_cursor_sword();
1095 cd_create_custom_dialog(mainPtr,strs,pic_num, buttons);
1097 while (dialog_not_toast)
1098 ModalDialog();
1100 cd_kill_dialog(900,0);
1102 if (in_startup_mode == FALSE)
1103 refresh_screen(0);
1104 else draw_startup(0);
1105 i = dialog_answer;
1106 dialog_answer = store_dialog_answer;
1108 return i;
1112 void fancy_choice_dialog_event_filter (short item_hit)
1114 dialog_not_toast = FALSE;
1115 dialog_answer = item_hit;
1118 short fancy_choice_dialog(short which_dlog,short parent)
1119 // ignore parent in Mac version
1121 short item_hit,i,store_dialog_answer;
1122 char temp_str[256];
1124 store_dialog_answer = dialog_answer;
1125 make_cursor_sword();
1127 cd_create_dialog_parent_num(which_dlog,parent);
1129 if (which_dlog == 1062) {
1130 i = get_ran(1,0,12);
1131 get_str(temp_str,11,10 + i);
1132 csit(1062,10,(char *) temp_str);
1134 while (dialog_not_toast)
1135 ModalDialog();
1137 cd_kill_dialog(which_dlog,0);
1139 if (parent < 2) {
1140 if (in_startup_mode == FALSE)
1141 refresh_screen(0);
1142 else draw_startup(0);
1144 i = dialog_answer;
1145 dialog_answer = store_dialog_answer;
1147 return i;
1150 void select_pc_event_filter (short item_hit)
1152 dialog_not_toast = FALSE;
1153 if (item_hit == 16)
1154 dialog_answer = 6;
1155 else dialog_answer = item_hit - 3;
1158 short char_select_pc(short active_only,short free_inv_only,char const *title)
1159 //active_only; // 0 - no 1 - yes 2 - disarm trap
1161 short item_hit,i;
1163 make_cursor_sword();
1165 cd_create_dialog(1018,mainPtr);
1167 if (active_only == 2)
1168 csit(1018,15,"Select PC to disarm trap:");
1169 else csit( 1018,15,title);
1171 for (i = 0; i < 6; i++) {
1172 if ((adven[i].main_status == 0) ||
1173 ((active_only == TRUE) && (adven[i].main_status > 1)) ||
1174 ((free_inv_only == 1) && (pc_has_space(i) == 24)) || (adven[i].main_status == 5)) {
1175 cd_activate_item(1018, 3 + i, 0);
1177 if (adven[i].main_status != 0) {
1178 csit(1018,9 + i,adven[i].name);
1180 else cd_activate_item(1018, 9 + i, 0);
1183 while (dialog_not_toast)
1184 ModalDialog();
1185 cd_kill_dialog(1018,0);
1187 if (in_startup_mode == FALSE)
1188 refresh_screen(0);
1189 else draw_startup(0);
1191 return dialog_answer;
1194 short select_pc(short active_only,short free_inv_only)
1195 //active_only; // 0 - no 1 - yes 2 - disarm trap
1197 if (active_only == 2)
1198 return char_select_pc(active_only,free_inv_only,"Trap! Who will disarm?");
1199 else return char_select_pc(active_only,free_inv_only,"Select a character:");
1202 void get_num_of_items_event_filter (short item_hit)
1204 char get_text[256];
1205 long dummy;
1207 cd_get_text_edit_str(1012,(char *) get_text);
1208 dialog_answer = 0;
1209 sscanf((char *) get_text,"%d",&dialog_answer);
1210 dialog_not_toast = FALSE;
1213 short get_num_of_items(short max_num)
1214 //town_num; // Will be 0 - 200 for town, 200 - 290 for outdoors
1215 //short sign_type; // terrain type
1218 short item_hit;
1219 char sign_text[256];
1220 location view_loc;
1222 make_cursor_sword();
1224 cd_create_dialog(1012,mainPtr);
1226 sprintf((char *) sign_text,"How many? (0-%d) ",max_num);
1227 csit(1012,4,(char *)sign_text);
1228 sprintf((char *) sign_text,"%d",max_num);
1229 cd_set_text_edit_str(1012,(char *) sign_text);
1230 cd_set_edit_focus();
1232 while (dialog_not_toast)
1233 ModalDialog();
1234 cd_kill_dialog(1012,0);
1236 dialog_answer = minmax(0,max_num,dialog_answer);
1238 return dialog_answer;
1241 BOOL FAR PASCAL _export choice_dialog_proc
1242 (HWND hDlg, UINT message, UINT wParam, LONG lParam) {
1243 RECT to_rect = {8,8,44,44};
1244 short i;
1245 Boolean do_stnd = TRUE;
1246 char item_str[256];
1247 RECT r1 = {16,90,44,126},r2 = {16,139,44,175};
1249 test_dlog3 = hDlg;
1251 switch (message) {
1252 case WM_INITDIALOG:
1253 center_window(hDlg);
1255 return TRUE;
1256 case WM_PAINT:
1258 return FALSE;
1260 case WM_COMMAND:
1261 answer_given = (short) wParam;
1262 if (answer_given == 100)
1263 answer_given = 2;
1264 EndDialog(hDlg, 0);
1265 return TRUE;
1267 return FALSE;
1270 short choice_dialog(short pic,short num)
1272 char dlog_name[10];
1274 store_focus = GetFocus();
1275 dlog_proc1 = MakeProcInstance((FARPROC) choice_dialog_proc,store_hInstance);
1276 if (dlog_proc1 == NULL) {
1277 add_string_to_buf("Dialog error, number...");
1278 print_nums(0,0,num);
1279 return 1;
1281 DialogBox(store_hInstance, MAKEINTRESOURCE(num), store_focus, dlog_proc1);
1282 FreeProcInstance(dlog_proc1);
1283 DestroyWindow(test_dlog3);
1284 SetFocus(store_focus);
1285 return answer_given;
1289 BOOL FAR PASCAL _export modeless_dialog_proc
1290 (HWND hDlg, UINT message, UINT wParam, LONG lParam) {
1291 short i,which_d,store_which;
1292 char item_str[256];
1293 Boolean do_stnd = TRUE,id_dlg = TRUE;
1294 RECT to_rect = {6,6,42,42},r1,r2;
1296 for (i = 0; i < 18; i++)
1297 if ((modeless_exists[i] == TRUE) &&
1298 (hDlg == modeless_dialogs[i])) {
1299 which_d = i;
1300 i = 50;
1302 if (i == 18) {
1303 id_dlg = FALSE;
1305 else store_which = modeless_key[which_d];
1307 switch (message) {
1308 case WM_INITDIALOG:
1309 ShowWindow(hDlg,SW_SHOW);
1310 break;
1311 case WM_PAINT:
1312 if (being_created > 0) {
1313 store_which = being_created;
1314 id_dlg = TRUE;
1315 being_created = -1;
1317 if (id_dlg == FALSE)
1318 return 0;
1320 return FALSE;
1322 case WM_COMMAND:
1323 DestroyWindow(hDlg);
1324 return TRUE;
1325 case WM_DESTROY:
1326 if (id_dlg == TRUE)
1327 modeless_exists[which_d] = FALSE;
1328 return 0;
1330 return FALSE;
1333 void create_modeless_dialog(short which_dlog)
1335 short i,which_d;
1336 FARPROC d_proc;
1338 for (i = 0; i < 18; i++)
1339 if (which_dlog == modeless_key[i]) {
1340 which_d = i;
1341 i = 50;
1343 if (i == 18)
1344 return;
1345 if (modeless_exists[which_d] == TRUE) {
1346 SetFocus(modeless_dialogs[which_d]);
1347 return;
1350 being_created = which_dlog;
1352 modeless_exists[which_d] = TRUE;
1353 if (procinst_exists[which_d] == 0) {
1354 procinst_exists[which_d] = 1;
1355 modeless_dlogprocs[which_d] = MakeProcInstance((FARPROC) modeless_dialog_proc,store_hInstance);
1357 modeless_dialogs[which_d] = CreateDialog(store_hInstance,
1358 MAKEINTRESOURCE(which_dlog),mainPtr,modeless_dlogprocs[which_d]);
1361 void make_cursor_watch()
1363 SetCursor(LoadCursor(NULL,IDC_WAIT));
1364 ShowCursor(TRUE);
1368 void place_glands(location where,unsigned char m_type)
1370 short r1;
1371 item_record_type store_i;
1372 monster_record_type monst;
1374 monst = return_monster_template(m_type);
1376 if ((monst.corpse_item >= 0) && (monst.corpse_item < 400) && (get_ran(1,0,100) < monst.corpse_item_chance)) {
1377 store_i = get_stored_item(monst.corpse_item);
1378 place_item(store_i,where,FALSE);
1382 short party_total_level()
1384 short i,j = 0;
1386 for (i = 0; i < 6; i++)
1387 if (adven[i].main_status == 1)
1388 j += adven[i].level;
1389 return j;
1392 void reset_item_max()
1394 short i;
1396 for (i = 0; i < NUM_TOWN_ITEMS; i++)
1397 if (t_i.items[i].variety != 0)
1398 item_max = i + 1;
1401 short item_val(item_record_type item)
1403 if (item.charges == 0)
1404 return item.value;
1405 return item.charges * item.value;
1408 void place_treasure(location where,short level,short loot,short mode)
1409 //short mode; // 0 - normal, 1 - force
1412 item_record_type new_item;
1413 short amt,r1,i,j;
1414 short treas_chart[5][6] = {{0,-1,-1,-1,-1,-1},
1415 {1,-1,-1,-1,-1,-1},
1416 {2,1,1,-1,-1,-1},
1417 {3,2,1,1,-1,-1},
1418 {4,3,2,2,1,1}};
1419 short treas_odds[5][6] = {{10,0,0,0,0,0},
1420 {50,0,0,0,0,0},
1421 {60,50,40,0,0,0},
1422 {100,90,80,70,0,0},
1423 {100,80,80,75,75,75}};
1424 short id_odds[21] = {0,10,15,20,25,30,35,39,43,47,
1425 51,55,59,63,67,71,73,75,77,79,81};
1426 short max_mult[5][10] = {{0,0,0,0,0,0,0,0,0,1},
1427 {0,0,1,1,1,1,2,3,5,20},
1428 {0,0,1,1,2,2,4,6,10,25},
1429 {5,10,10,10,15,20,40,80,100,100},
1430 {25,25,50,50,50,100,100,100,100,100}};
1431 short min_chart[5][10] = {{0,0,0,0,0,0,0,0,0,1},
1432 {0,0,0,0,0,0,0,0,5,20},
1433 {0,0,0,0,1,1,5,10,15,40},
1434 {10,10,15,20,20,30,40,50,75,100},
1435 {50,100,100,100,100,200,200,200,200,200}};
1436 short max,min;
1438 if (loot == 1)
1439 amt = get_ran(2,1,7) + 1;
1440 else amt = loot * (get_ran(1,0,10 + (loot * 6) + (level * 2)) + 5);
1442 if (party_total_level() <= 12)
1443 amt += 1;
1444 if ((party_total_level() <= 60) && (amt > 2))
1445 amt += 2;
1447 if (amt > 3) {
1448 new_item = get_stored_item(0);
1449 new_item.item_level = amt;
1450 r1 = get_ran(1,1,9);
1451 if (((loot > 1) && (r1 < 7)) || ((loot == 1) && (r1 < 5)) || (mode == 1)
1452 || ((r1 < 6) && (party_total_level() < 30)) || (loot > 2) )
1453 place_item(new_item,where,FALSE);
1455 for (j = 0; j < 5; j++) {
1456 r1 = get_ran(1,0,100);
1457 if ((treas_chart[loot][j] >= 0) && (r1 <= treas_odds[loot][j] + luck_total())) {
1458 r1 = get_ran(1,0,9);
1459 min = min_chart[treas_chart[loot][j]][r1];
1460 r1 = get_ran(1,0,9);
1461 max = (min + level + (2 * (loot - 1)) + (luck_total() / 3)) * max_mult[treas_chart[loot][j]][r1];
1462 if (get_ran(1,0,1000) == 500) {
1463 max = 10000;
1464 min = 100;
1467 // reality check
1468 if ((loot == 1) && (max > 100) && (get_ran(1,0,8) < 7))
1469 max = 100;
1470 if ((loot == 2) && (max > 200) && (get_ran(1,0,8) < 6))
1471 max = 200;
1474 new_item = return_treasure(treas_chart[loot][j],level,mode);
1475 if ((item_val(new_item) < min) || (item_val(new_item) > max)) {
1476 new_item = return_treasure(treas_chart[loot][j],level,mode);
1477 if ((item_val(new_item) < min) || (item_val(new_item) > max)) {
1478 new_item = return_treasure(treas_chart[loot][j],level,mode);
1479 if (item_val(new_item) > max)
1480 new_item.variety = 0;
1484 // not many magic items
1485 if (mode == 0) {
1486 if ((is_magic(new_item) == TRUE) && (level < 2) && (get_ran(1,0,5) < 3))
1487 new_item.variety = 0;
1488 if ((is_magic(new_item) == TRUE) && (level == 2) && (get_ran(1,0,5) < 2))
1489 new_item.variety = 0;
1490 if ((is_cursed(new_item) == TRUE) && (get_ran(1,0,5) < 3))
1491 new_item.variety = 0;
1494 // if forced, keep dipping until a treasure comes uo
1495 if ((mode == 1) && (max >= 20)) {
1497 new_item = return_treasure(treas_chart[loot][j],level,mode);
1498 while ((new_item.variety == 0) || (item_val(new_item) > max));
1501 // Not many cursed items
1502 if ((is_cursed(new_item) == TRUE) && (get_ran(1,0,2) == 1))
1503 new_item.variety = 0;
1505 if (new_item.variety != 0) {
1506 for (i = 0; i < 6; i++)
1507 if ((adven[i].main_status == 1)
1508 && (get_ran(1,0,100) < id_odds[adven[i].skills[13]]))
1509 new_item.item_properties = new_item.item_properties | 1;
1510 place_item(new_item,where,FALSE);
1517 short luck_total()
1519 short i = 0;
1521 for (i = 0; i < 6; i++)
1522 if (adven[i].main_status == 1)
1523 i += adven[i].skills[18];
1524 return i;
1527 item_record_type return_treasure(short loot,short level,short mode)
1528 //short mode; // 0 - normal 1 - force
1530 item_record_type treas;
1531 short which_treas_chart[48] = {1,1,1,1,1,2,2,2,2,2,
1532 3,3,3,3,3,2,2,2,4,4,
1533 4,4,5,5,5,6,6,6,7,7,
1534 7,8,8,9,9,10,11,12,12,13,
1535 13,14, 9,10,11,9,10,11};
1536 short r1;
1538 treas.variety = 0;
1539 r1 = get_ran(1,0,41);
1540 if (loot >= 3)
1541 r1 += 3;
1542 if (loot == 4)
1543 r1 += 3;
1544 switch (which_treas_chart[r1]) {
1545 case 1: treas = get_food(); break;
1546 case 2: treas = get_weapon(loot,level); break;
1547 case 3: treas = get_armor(loot,level); break;
1548 case 4: treas = get_shield(loot); break;
1549 case 5: treas = get_helm(loot); break;
1550 case 6: treas = get_missile(loot); break;
1551 case 7: treas = get_potion(loot); break;
1552 case 8: treas = get_scroll(loot); break;
1553 case 9: treas = get_wand(loot); break;
1554 case 10: treas = get_ring(loot); break;
1555 case 11: treas = get_necklace(loot); break;
1556 case 12: treas = get_poison(loot,level); break;
1557 case 13: treas = get_gloves(loot); break;
1558 case 14: treas = get_boots(loot); break;
1560 if (treas.variety == 0)
1561 treas.value = 0;
1562 return treas;
1567 void refresh_store_items()
1569 short i,j;
1570 short loot_index[10] = {1,1,1,1,2,2,2,3,3,4};
1572 for (i = 0; i < 5; i++)
1573 for (j = 0; j < 10; j++) {
1574 party.magic_store_items[i][j] = return_treasure(loot_index[j],7,1);
1575 if ((party.magic_store_items[i][j].variety == 3) ||
1576 (party.magic_store_items[i][j].variety == 11))
1577 party.magic_store_items[i][j] = return_dummy_item();
1578 party.magic_store_items[i][j].item_properties =
1579 party.magic_store_items[i][j].item_properties | 1;
1584 void get_text_response_event_filter (short item_hit)
1586 char get_text[256];
1588 cd_get_text_edit_str(store_dnum,(char *) store_str);
1589 dialog_not_toast = FALSE;
1592 void get_text_response(short dlg,char *str,short parent_num)
1595 short item_hit,i;
1596 char sign_text[256];
1597 location view_loc;
1599 make_cursor_sword();
1601 store_str = (char *) str;
1602 store_dnum = dlg;
1604 cd_create_dialog_parent_num(dlg,parent_num);
1605 cd_set_edit_focus();
1607 while (dialog_not_toast)
1608 ModalDialog();
1609 for (i = 0; i < 15; i++)
1610 if ((str[i] > 64) && (str[i] < 91))
1611 str[i] = str[i] + 32;
1612 //ASB((char *) str);
1613 final_process_dialog(dlg);
1614 //cd_kill_dialog(dlg,0);
1618 // returns true is party has item of given item class
1619 // mode - 0 - take one of them, 1 - don't take
1620 Boolean party_check_class(short item_class,short mode) ////
1622 short i,j;
1624 if (item_class == 0)
1625 return FALSE;
1626 for (i = 0; i < 6; i++)
1627 if (adven[i].main_status == 1)
1628 for (j = 23; j >= 0; j--)
1629 if ((adven[i].items[j].variety > 0) && (adven[i].items[j].special_class == item_class)) {
1630 if (mode == 0) {
1631 if (adven[i].items[j].charges > 1)
1632 adven[i].items[j].charges--;
1633 else take_item(i,j);
1635 return TRUE;
1637 return FALSE;