added worldarea -> will be responsible for world map rendering
[dboe.git] / actions.c
blob6d02a68b66af9c637fbe5e1ac7f9cdbde86e35b2
1 //#include <Windows.h>
2 #include <stdio.h>
4 #include "global.h"
5 #include "actions.h"
6 #include "gutils.h"
7 #include "graphics.h"
8 #include "townspec.h"
9 #include "fileio.h"
10 #include "dlgutils.h"
11 #include "locutils.h"
12 #include "fields.h"
13 #include "town.h"
14 #include "math.h"
15 #include "text.h"
16 #include "party.h"
17 #include "monster.h"
18 #include "specials.h"
19 #include "newgraph.h"
20 #include "combat.h"
21 #include "items.h"
22 #include "exlsound.h"
23 #include "infodlgs.h"
24 #include "itemdata.h"
25 #include "dlogtool.h"
26 #include "graphutl.h"
28 RECT bottom_buttons[7];
29 RECT town_buttons[10];
30 RECT combat_buttons[9];
31 RECT world_screen = {23, 23, 274,346};
32 RECT item_screen_button_rects[9] = {{11,126,28,140},{40,126,57,140},{69,126,86,140},{98,126,115,140},
33 {127,126,144,140},{156,126,173,140},{176,126,211,141},{213,126,248,141},{251,127,267,139}};
35 RECT border_rect[4] = {{5, 5, 283, 15}, {5, 5, 15, 355},
36 {5, 345, 283, 355}, {273, 5, 283, 355}};
37 RECT medium_buttons[4] = {{190, 383,225,401}, {190, 402, 225, 420},
38 {227, 383, 263, 401}, {227, 402, 263,420}}; ;
40 RECT item_buttons[8][6];
41 // name, use, give, drip, info, sell/id
42 RECT pc_buttons[6][5];
43 // name, hp, sp, info, trade
44 short num_chirps_played = 0;
45 RECT startup_top;
46 short special_queue[20];
47 Boolean end_scenario = FALSE;
49 extern RECT startup_button[6];
51 // For menu spell casting, some info needs to be stored up here.
52 short refer_mage[62] = {0,2,1,1,2,2,0,2,2,0, 2,2,2,2,1,2,2,2,2,2, 0,1,2,0,2,2,3,3,2,1,
53 2,2,1,0,2,2,3,2, 0,1,2,0,2,3,2,3, 2,1,2,3,2,2,2,0, 1,1,1,0,3,2,2,3};
54 short refer_priest[62] = {1,0,0,2,0,0,0,0,0,2, 1,0,2,0,2,2,0,2,3,0, 0,0,2,0,0,0,2,0,0,3,
55 0,1,2,0,3,0,0,0, 1,0,0,2,0,3,0,2, 0,0,0,0,2,1,1,1, 0,2,0,2,1,2,0,0};
56 // 0 - refer 1 - do in combat immed. 2 - need targeting 3 - need fancy targeting
57 short mage_need_select[62] = {0,0,1,1,0,0,0,0,0,0, 0,0,0,0,1,0,0,0,0,0, 0,1,0,0,0,0,0,0,0,1,
58 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,1,0,0,0,0};
59 short priest_need_select[62] = {1,1,1,0,0,1,1,0,0,0, 1,1,0,0,0,0,0,0,0,1, 1,0,0,0,1,0,0,1,1,0,
60 0,0,0,1,0,1,1,0, 0,1,2,0,0,0,0,0, 0,1,0,2,0,0,0,0, 0,0,2,0,0,0,0,0};
61 // 0 - no select 1 - active only 2 - any existing
63 word_rect_type preset_words[9] = {{"Look",{4,366,54,389}},{"Name",{70,366,130,389}},{"Job",{136,366,186,389}},
64 {"Buy",{4,389,54,412}},{"Sell",{70,389,120,412}},{"Record",{121,389,186,412}},
65 {"Done",{210,389,270,412}},{"Go Back",{190,366,270,389}},
66 {"Ask About...",{4,343,134,366}}};
68 Boolean item_area_button_active[8][6];
69 Boolean pc_area_button_active[6][5];
70 short item_bottom_button_active[9] = {0,0,0,0,0, 0,1,1,1};
72 RECT pc_help_button,pc_area_rect,item_area_rect;
74 short current_terrain_type = 0,num_out_moves = 0;
75 short door_pc,store_drop_item;
76 short current_switch = 6;
77 out_wandering_type store_wandering_special;
78 long dummy;
79 short store_shop_type;
81 short debug_ok = 0;
82 short store_selling_values[8] = {0,0,0,0,0,0,0,0};
84 extern short cen_x, cen_y, overall_mode, stat_window,give_delays,pc_moves[6];
85 extern POINT to_create;
86 extern Boolean in_startup_mode,All_Done,play_sounds,frills_on,spell_forced,save_maps,monsters_going;
87 extern Boolean debug_on,registered,cartoon_happening,in_scen_debug,party_in_memory;
89 // game info globals
91 extern HWND mainPtr;
92 extern party_record_type party;
93 extern piles_of_stuff_dumping_type *data_store;
94 extern piles_of_stuff_dumping_type2 *data_store2;
95 extern talking_record_type talking;
96 extern scenario_data_type scenario;
98 extern pc_record_type adven[6];
99 extern outdoor_record_type outdoors[2][2];
100 extern current_town_type c_town;
101 extern big_tr_type t_d;
102 extern unsigned char out[96][96];
103 extern unsigned char out_e[96][96];
104 extern short which_item_page[6],current_ground;
105 extern short town_size[3],store_spell_target,pc_last_cast[2][6],pc_casting,store_mage,store_priest;
106 extern town_item_list t_i; // shouldn't be here
107 extern unsigned char misc_i[64][64];
108 extern short spec_item_array[60];
109 extern stored_town_maps_type town_maps,town_maps2;
111 // combat globals
114 extern short which_combat_type,num_targets_left;
115 extern unsigned char combat_terrain[64][64];
116 extern location center;
117 extern location pc_pos[6];
118 extern short current_pc,town_type;
119 extern short combat_active_pc,stat_screen_mode;
121 extern Boolean modeless_exists[18],diff_depth_ok;
122 extern short modeless_key[18];
123 extern HWND modeless_dialogs[18];
125 extern stored_items_list_type stored_items[3];
126 extern stored_outdoor_maps_type o_maps;
127 extern short ulx,uly;
128 extern HWND text_sbar,item_sbar,shop_sbar;
129 extern short shop_identify_cost;
130 extern Boolean fry_startup;
133 char const *dir_string[] = {"North", "NorthEast", "East", "SouthEast", "South", "SouthWest", "West", "NorthWest"};
134 char get_new_terrain();
135 creature_start_type save_monster_type;
137 short wand_loc_count = 0;
138 short monst_place_count = 0; // 1 - standard place 2 - place last
139 Boolean unreg_party_in_scen_not_check = FALSE;
141 item_record_type start_items[6] =
143 {1,4, 0,1,0,0,1,0, 45,0,0,0,0,0, 2, 7,0, {0,0},"Bronze Knife","Knife",0,1,0,0},
144 {12,1,1,0,0,0,0,0, 65,0,0,0,0,0, 2, 20,0, {0,0},"Crude Buckler","Buckler",0,1,0,0},
145 {4,0,0,0,0,0,0,0, 10,0,0,0,0,0, 15, 20,0, {0,0},"Cavewood Bow","Bow",0,1,0,0},
146 {5,12,0,0,0,12,0,0, 47,0,0,0,0,0, 1, 1,0, {0,0},"Arrows","Arrows",0,1,0,0},
147 {2,9,0,0,0,0,3,0, 4,0,0,0,0,0, 10, 30,0, {0,0},"Stone Spear","Spear",0,1,0,0},
148 {14,1,0,0,0,0,0,0, 66,0,0,0,0,0, 6, 15,0, {0,0},"Leather Helm","Helm",0,1,0,0}
151 // 0 - whole area, 1 - active area 2 - graphic 3 - item name
152 // 4 - item cost 5 - item extra str 6 - item help button
153 RECT shopping_rects[8][7];
155 void init_screen_locs()
157 short i,j,k,l;
158 RECT bottom_base = {0,0,18,15},startup_base = {5,279,306,327};
159 RECT shop_base = {12,63,267,99}; /**/
161 for (i = 0; i < 7; i++)
162 shopping_rects[0][i] = shop_base;
163 shopping_rects[0][1].right -= 35;
164 shopping_rects[0][2].right = shopping_rects[0][2].left + 28;
165 shopping_rects[0][3].top += 4;
166 shopping_rects[0][3].left += 28;
167 shopping_rects[0][4].top += 20;
168 shopping_rects[0][4].left += 154;
169 shopping_rects[0][5].top += 20;
170 shopping_rects[0][5].left += 34;
171 shopping_rects[0][6].top += 3;
172 shopping_rects[0][6].bottom -= 21;
173 shopping_rects[0][6].right -= 19;
174 shopping_rects[0][6].left = shopping_rects[0][6].right - 14;
175 for (i = 1; i < 8; i++)
176 for (j = 0; j < 7; j++) {
177 shopping_rects[i][j] = shopping_rects[0][j];
178 OffsetRect(&shopping_rects[i][j],0,i * 36);
182 for (i = 0; i < 6; i++) {
183 startup_button[i] = startup_base;
184 OffsetRect(&startup_button[i],301 * (i / 3) - 0,48 * (i % 3));
186 startup_top.top = 5;
187 startup_top.bottom = startup_button[0].top;
188 startup_top.left = 5;
189 startup_top.right = startup_button[3].right;
191 for (i = 0; i < 100; i++)
192 for (j = 0; j < 8; j++)
193 for (k = 0; k < 64; k++)////
194 town_maps.town_maps[i][j][k] = 0;
195 for (i = 0; i < 100; i++)
196 for (j = 0; j < 8; j++)
197 for (k = 0; k < 64; k++)////
198 town_maps2.town_maps[i][j][k] = 0;
200 for (i = 0; i < 100; i++)
201 for (k = 0; k < 6; k++)
202 for (l = 0; l < 48; l++)
203 o_maps.outdoor_maps[i][k][l] = 0;
205 for (i = 0; i < 7; i++) {
206 bottom_buttons[i].top = 383;
207 bottom_buttons[i].bottom = 420;
208 bottom_buttons[i].left = 5 + (i * 37);
209 bottom_buttons[i].right = bottom_buttons[i].left + 36;
210 town_buttons[i] = bottom_buttons[i];
212 //FrameRect (&bottom_buttons[i]);
215 for (i = 0; i < 5; i++) {
216 combat_buttons[i] = bottom_buttons[i];
218 town_buttons[7] = bottom_buttons[6];
219 town_buttons[5] = medium_buttons[0];
220 town_buttons[6] = medium_buttons[1];
221 for (i = 5; i < 9; i++) {
222 combat_buttons[i] = medium_buttons[i - 5];
225 // name, use, give, drip, info, sell/id each one 13 down
226 item_buttons[0][0].top = 17;
227 item_buttons[0][0].bottom = item_buttons[0][0].top + 12;
228 item_buttons[0][0].left = 3;
229 item_buttons[0][0].right = item_buttons[0][0].left + 185;
230 OffsetRect(&item_buttons[0][0],0,1);
231 item_buttons[0][1] = item_buttons[0][0];
232 item_buttons[0][1].left = 196;
233 item_buttons[0][1].right = 210;
234 item_buttons[0][2] = item_buttons[0][0];
235 item_buttons[0][2].left = 210;
236 item_buttons[0][2].right = 224;
237 item_buttons[0][3] = item_buttons[0][0];
238 item_buttons[0][3].left = 224;
239 item_buttons[0][3].right = 238;
240 item_buttons[0][4] = item_buttons[0][0];
241 item_buttons[0][4].left = 238;
242 item_buttons[0][4].right = 252;
243 item_buttons[0][5] = item_buttons[0][0];
244 item_buttons[0][5].left = 173;
245 item_buttons[0][5].right = 232;
246 for (i = 1; i < 8; i++)
247 for (j = 0; j < 6; j++) {
248 item_buttons[i][j] = item_buttons[0][j];
249 OffsetRect(&item_buttons[i][j],0,13 * i);
252 /* for (i = 0; i < 8; i++) {
253 item_screen_button_rects[i] = bottom_base;
254 OffsetRect(&item_screen_button_rects[i],10 + i * 29,126);
256 item_screen_button_rects[6].left = 176;
257 item_screen_button_rects[6].right = 211;
258 item_screen_button_rects[7].left = 213;
259 item_screen_button_rects[7].right = 248;
260 item_screen_button_rects[8].top = 127;
261 item_screen_button_rects[8].bottom = 140;
262 item_screen_button_rects[8].left = 251;
263 item_screen_button_rects[8].right = 267; */
265 // name, hp, sp, info, trade
266 pc_buttons[0][0].top = 18;
267 pc_buttons[0][0].bottom = pc_buttons[0][0].top + 12;
268 pc_buttons[0][0].left = 3;
269 pc_buttons[0][0].right = pc_buttons[0][0].left + 177;
270 pc_buttons[0][1] = pc_buttons[0][0];
271 pc_buttons[0][1].left = 184;
272 pc_buttons[0][1].right = 214;
273 pc_buttons[0][2] = pc_buttons[0][0];
274 pc_buttons[0][2].left = 214;
275 pc_buttons[0][2].right = 237;
276 pc_buttons[0][3] = pc_buttons[0][0];
277 pc_buttons[0][3].left = 241;
278 pc_buttons[0][3].right = 253;
279 pc_buttons[0][4] = pc_buttons[0][0];
280 pc_buttons[0][4].left = 253;
281 pc_buttons[0][4].right = 262;
282 for (i = 1; i < 6; i++)
283 for (j = 0; j < 5; j++) {
284 pc_buttons[i][j] = pc_buttons[0][j];
285 OffsetRect(&pc_buttons[i][j],0,13 * i);
287 pc_help_button.top = 101;
288 pc_help_button.bottom = 114;
289 pc_help_button.left = 251;
290 pc_help_button.right = 267;
292 pc_area_rect.top = PC_WIN_UL_Y;
293 pc_area_rect.left = PC_WIN_UL_X;
294 pc_area_rect.bottom = PC_WIN_UL_Y + 116;
295 pc_area_rect.right = PC_WIN_UL_X + 271;
296 item_area_rect.top = ITEM_WIN_UL_Y;
297 item_area_rect.left = ITEM_WIN_UL_X;
298 item_area_rect.bottom = ITEM_WIN_UL_Y + 143;
299 item_area_rect.right = ITEM_WIN_UL_X + 271;
303 Boolean prime_time()
305 if ((overall_mode < 2) || (overall_mode == 10))
306 return TRUE;
307 return FALSE;
310 Boolean handle_action(POINT the_point, UINT wparam, LONG lparam )
312 short i,j,k, store_dest,i_num,item_hit,which_t,s1,s2,s3;
313 Boolean are_done = FALSE;
314 RECT targ_rect;
315 Boolean need_redraw = FALSE, did_something = FALSE, need_reprint = FALSE;
316 Boolean town_move_done = FALSE,pc_delayed = FALSE;
317 location destination,cur_loc,sector = {0,0},loc_in_sec,cur_direction = {0,0};
318 char *store_str;
319 unsigned char storage;
320 short find_direction_from,ter_looked_at,button_hit = 12,store_cur_pc;
321 long dummy;
322 short store_sp[6];
324 char str[60];
325 POINT point_in_area;
326 Boolean right_button = FALSE;
327 Boolean ctrl_key = FALSE;
328 unsigned char ter;
330 if (lparam != -1) {
331 the_point.x -= ulx;
332 the_point.y -= uly;
334 if (lparam == -2)
335 right_button = TRUE;
336 if (MK_CONTROL & wparam)
337 ctrl_key = TRUE;
339 for (i = 0; i < 20; i++)
340 special_queue[i] = -1;
341 end_scenario = FALSE;
343 if (unreg_party_in_scen_not_check == TRUE) {
344 if (enter_password() == FALSE) {
345 end_scenario = TRUE;
347 else {
348 in_scen_debug = TRUE;
349 ASB("Debug mode ON.");
351 unreg_party_in_scen_not_check = FALSE;
354 // Now split off the extra stuff, like talking and shopping.
355 if (overall_mode == 20) {
356 handle_talk_event(the_point,right_button);
357 if (overall_mode != 20)
358 return FALSE;
360 if (overall_mode == 21) {
361 handle_shop_event(the_point,right_button);
362 if (overall_mode != 21)
363 return FALSE;
366 num_chirps_played = 0;
368 // First, figure out where party is
369 switch (overall_mode) {
370 case 0: case 35:
371 cur_loc = party.p_loc;
372 for (i = 0; i < 7; i++)
373 if (PtInRect ( &bottom_buttons[i], the_point) == TRUE) {
374 button_hit = i;
375 if (spell_forced == FALSE)
376 main_button_click(overall_mode,bottom_buttons[i]);
378 break;
380 case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 36:
381 // cur_loc = c_town.p_loc;
382 cur_loc = center;
383 for (i = 0; i < 8; i++)
384 if (PtInRect (&town_buttons[i], the_point) == TRUE) {
385 button_hit = i;
386 if (spell_forced == FALSE)
387 main_button_click(overall_mode,town_buttons[i]);
389 break;
391 case 20: case 21: break;
393 default:
394 cur_loc = (overall_mode > 10) ? center : pc_pos[current_pc];
395 for (i = 0; i < 9; i++)
396 if (PtInRect (&combat_buttons[i], the_point) == TRUE) {
397 button_hit = i;
398 if (spell_forced == FALSE)
399 main_button_click(overall_mode,combat_buttons[i]);
401 break;
404 // Then, handle a button being hit.
405 if (button_hit != 12)
406 switch(button_hit)
408 case 0: case 1:
409 if (someone_awake() == FALSE) {
410 ASB("Everyone's asleep/paralyzed.");
411 need_reprint = TRUE;
412 need_redraw = TRUE;
414 if (overall_mode == 0) {
415 cast_spell(button_hit,0);
416 spell_forced = FALSE;
417 need_reprint = TRUE;
418 need_redraw = TRUE;
420 else if (overall_mode == 1) {
421 for (i = 0; i < 6; i++)
422 store_sp[i] = adven[i].cur_sp;
423 cast_spell(button_hit,1);
424 spell_forced = FALSE;
425 need_reprint = TRUE;
426 need_redraw = TRUE;
427 for (i = 0; i < 6; i++)
428 if (store_sp[i] != adven[i].cur_sp)
429 did_something = TRUE;
431 else if (overall_mode == 3) {
432 add_string_to_buf(" Cancelled. ");
433 overall_mode = 1;
435 else if (overall_mode == 10) {
436 if ((overall_mode == 10) && (button_hit == 0)) {
437 did_something = combat_cast_mage_spell();
438 need_reprint = TRUE;
440 if ((overall_mode == 10) && (button_hit == 1)) {
441 did_something = combat_cast_priest_spell();
442 need_reprint = TRUE;
444 if ((overall_mode != 11) && (overall_mode != 14)) {
445 need_redraw = TRUE;
447 else did_something = FALSE;
448 spell_forced = FALSE;
449 redraw_terrain();
451 else if ((overall_mode == 11) || (overall_mode == 14)) {
452 add_string_to_buf(" Cancelled. ");
453 overall_mode = 10;
454 center = pc_pos[current_pc];
455 pause(10);
456 need_redraw = TRUE;
458 put_pc_screen();
459 put_item_screen(stat_window,0);
460 break;
462 case 2:
463 if (overall_mode == 0) {
464 overall_mode = 35;
465 add_string_to_buf("Look: Select a space. You can also ");
466 add_string_to_buf(" right click to look.");
467 need_redraw = TRUE;
469 if (overall_mode == 1) {
470 overall_mode = 36;
471 add_string_to_buf("Look: Select a space. You can also ");
472 add_string_to_buf(" right click to look.");
473 need_redraw = TRUE;
475 if (overall_mode == 10) {
476 overall_mode = 37;
477 add_string_to_buf("Look: Select a space. You can also ");
478 add_string_to_buf(" right click to look.");
479 need_redraw = TRUE;
481 break;
483 case 3:
484 if (overall_mode == 10) {
485 add_string_to_buf("Parry. ");
486 char_parry();
487 did_something = TRUE;
488 need_reprint = TRUE;
489 need_redraw = TRUE;
491 if (overall_mode == 1) {
492 overall_mode = 2;
493 add_string_to_buf("Talk: Select someone ");
494 need_reprint = TRUE;
496 if (overall_mode == 0) { // Resting
497 i = 0;
498 ter = out[party.p_loc.x][party.p_loc.y];
499 if (party.in_boat >= 0)
500 add_string_to_buf("Rest: Not in boat. ");
501 else if (someone_poisoned() == TRUE)
502 add_string_to_buf("Rest: Someone poisoned. ");
503 else if (party.food <= 12)
504 add_string_to_buf("Rest: Not enough food. ");
505 else if (nearest_monster() <= 3)
506 add_string_to_buf("Rest: Monster too close. ");
507 else if ((scenario.ter_types[ter].special >= 2) && (scenario.ter_types[ter].special <= 6))
508 add_string_to_buf("Rest: It's dangerous here.");////
509 else if (flying() == TRUE)
510 add_string_to_buf("Rest: Not while flying. ");
511 else {
512 add_string_to_buf("Resting... ");
513 print_buf();
514 play_sound(20);
515 draw_rest_screen();
516 pause(25);
517 party.food -= 6;
518 while (i < 50) {
519 increase_age();
520 j = get_ran(1,1,2);
521 if (j == 2)
522 do_monsters();
523 j = get_ran(1,1,70);
524 if (j == 10)
525 create_wand_monst();
526 if (nearest_monster() <= 3) {
527 i = 200;
528 add_string_to_buf(" Monsters nearby.");
530 else i++;
532 put_pc_screen();
534 if (i == 50) {
535 party.age += 1200;////
536 add_string_to_buf(" Rest successful. ");
537 heal_party(get_ran(5,1,10));
538 restore_sp_party(50);
539 put_pc_screen();
541 need_reprint = TRUE;
542 need_redraw = TRUE;
544 break;
546 case 4:
547 if (overall_mode == 0) {
548 give_help(62,0,0);
549 display_map();
550 make_cursor_sword();
551 SetFocus(mainPtr);
553 if ((overall_mode == 1) || (overall_mode == 10)) {
554 if (party.in_boat >= 0) {
555 j = 0;
556 add_string_to_buf("Get: Not while in boat. ");
558 if (overall_mode == 1)
559 j = get_item(c_town.p_loc,6,FALSE);
560 else {
561 j = get_item(pc_pos[current_pc],current_pc,FALSE);
562 take_ap(4);
564 if (j > 0) {
565 put_item_screen(stat_window, 0);
566 put_pc_screen();
567 need_redraw = TRUE;
568 did_something = TRUE;
570 need_reprint = TRUE;
572 break;
574 case 5:
575 if (overall_mode == 0) {
576 save_file(0);
577 need_redraw = TRUE;
578 current_switch = 6;
579 break;
581 if (overall_mode == 1) {
582 add_string_to_buf("Use: Select a space or item.");
583 add_string_to_buf(" (Hit button again to cancel.)");
584 need_reprint = TRUE;
585 overall_mode = 4;
587 else if (overall_mode == 4) {
588 overall_mode = 1;
589 need_reprint = TRUE;
590 add_string_to_buf(" Cancelled.");
592 if (overall_mode == 10) {
593 need_reprint = TRUE;
594 need_redraw = TRUE;
595 pc_delayed = TRUE;
598 break;
600 case 6:
601 if (overall_mode == 0) {
602 do_load();
603 break;
605 if (overall_mode == 1) {
606 give_help(62,0,0);
607 display_map();
608 make_cursor_sword();
609 SetFocus(mainPtr);
611 if (overall_mode == 10) {
612 load_missile();
613 need_reprint = TRUE;
614 redraw_terrain();
616 else if ((overall_mode == 12) || (overall_mode == 13)) {
617 add_string_to_buf(" Cancelled. ");
618 center = pc_pos[current_pc];
619 pause(10);
620 need_redraw = TRUE;
621 overall_mode = 10;
623 break;
625 case 7:
626 if (overall_mode == 1) {
627 if (party.in_boat >= 0) {
628 need_reprint = TRUE;
629 add_string_to_buf("Combat: Not while in boat. ");
631 else if (party.in_horse >= 0) {
632 need_reprint = TRUE;
633 add_string_to_buf("Combat: Not while on horseback. ");
635 else {
636 add_string_to_buf("Combat! ");
637 play_sound(18);
638 need_reprint = TRUE;
639 //print_nums(999,current_pc,party.direction);
640 start_town_combat(party.direction);
641 //MessageBox(mainPtr,"Started town combat","Debug note",MB_OK | MB_ICONEXCLAMATION);
642 need_redraw = TRUE;
643 current_pc = 6;
644 did_something = TRUE;
645 put_pc_screen();
646 //MessageBox(mainPtr,"PC screen up","Debug note",MB_OK | MB_ICONEXCLAMATION);
649 else if (overall_mode == 10) {
650 if (which_combat_type == 0) {
651 if (hit_end_c_button() == TRUE) {
652 end_town_mode(0,c_town.p_loc);
653 play_sound(93);
654 add_string_to_buf("End combat. ");
655 handle_wandering_specials(0,1);
656 menu_activate(1);
657 put_pc_screen();
658 set_stat_window(current_pc);
660 else add_string_to_buf("Can't end combat yet. ");
662 else {
663 party.direction = end_town_combat();
664 center = c_town.p_loc;
665 //put_pc_screen();
666 set_stat_window(current_pc);
667 redraw_screen(0);
668 play_sound(93);
669 need_reprint = TRUE;
670 need_redraw = TRUE;
671 did_something = TRUE;
672 menu_activate(1);
674 need_redraw = TRUE;
676 break;
678 case 8:
680 if (overall_mode == 10) {
681 if (combat_active_pc == 6) {
682 add_string_to_buf("This PC now active. ");
683 combat_active_pc = current_pc;
685 else {
686 add_string_to_buf("All PC's now active. ");
687 current_pc = combat_active_pc;
688 combat_active_pc = 6;
690 need_reprint = TRUE;
692 break;
698 /* if (overall_mode == 30) /// I don't know what this is for.
699 if (PtInRect(the_point, &text_panel_rect)) {
700 through_sending();
701 restore_mode();
702 print_buf();
703 } */
705 // Begin : click in terrain
706 if ((PtInRect ( &world_screen,the_point)) && ((is_out()) || (is_town()) || (is_combat())) ){
707 i = (the_point.x - 23) / 28;
708 j = (the_point.y - 23) / 36;
710 destination = cur_loc;
712 if ((overall_mode == 0) || (overall_mode == 1) || (overall_mode == 10))
713 if ((i == 4) && (j == 4) && (right_button == FALSE)) { // Pausing
714 if (overall_mode == 10) {
715 char_stand_ready();
716 add_string_to_buf("Stand ready. ");
717 if (adven[current_pc].status[6] > 0) {
718 add_string_to_buf("You clean webs. ");
719 adven[current_pc].status[6] = move_to_zero(adven[current_pc].status[6]);
720 adven[current_pc].status[6] = move_to_zero(adven[current_pc].status[6]);
721 put_pc_screen();
723 check_fields(pc_pos[current_pc],2,current_pc);
725 else {
726 add_string_to_buf("Pause.");
727 for (k = 0; k < 6; k++)
728 if ((adven[k].main_status == 1) && (adven[k].status[6] > 0)) {
729 sprintf((char *) str,"%s cleans webs.",adven[k].name);
730 add_string_to_buf((char *) str);
731 adven[k].status[6] = move_to_zero(adven[k].status[6]);
732 adven[k].status[6] = move_to_zero(adven[k].status[6]);
734 if (party.in_horse >= 0) {
735 if (overall_mode == 0) {
736 party.horses[party.in_horse].which_town = 200;
737 party.horses[party.in_horse].horse_loc_in_sec = global_to_local(party.p_loc);
738 party.horses[party.in_horse].horse_loc = party.p_loc;
739 party.horses[party.in_horse].horse_sector.x = party.outdoor_corner.x + party.i_w_c.x;
740 party.horses[party.in_horse].horse_sector.y = party.outdoor_corner.y + party.i_w_c.y;
741 party.in_horse = -1;
743 else if (overall_mode == 1){
744 party.horses[party.in_horse].horse_loc = c_town.p_loc;
745 party.horses[party.in_horse].which_town = c_town.town_num;
746 party.in_horse = -1;
749 put_pc_screen();
750 check_fields(c_town.p_loc,1,0);
753 did_something = TRUE;
754 need_redraw = TRUE;
756 else if (right_button == FALSE) {
757 cur_direction = get_cur_direction(the_point);
758 destination.x += cur_direction.x;
759 destination.y += cur_direction.y;
763 // Begin: Moving
764 if ((right_button == FALSE) && (overall_mode == 10)) {
765 if (pc_combat_move(destination) == TRUE) {
766 center = pc_pos[current_pc];
767 did_something = TRUE;
768 update_explored(destination);
770 need_redraw = TRUE;
771 menu_activate(1);
773 if ((right_button == FALSE) && (overall_mode == 1)) {
774 if (someone_awake() == FALSE) {
775 ASB("Everyone's asleep/paralyzed.");
776 need_reprint = TRUE;
777 need_redraw = TRUE;
779 else {
780 need_redraw = TRUE;
781 if (town_move_party(destination,0) == TRUE) {
782 did_something = TRUE;
783 center = c_town.p_loc;
784 update_explored(destination);
786 if (loc_off_act_area(c_town.p_loc) == TRUE) {
788 destination = end_town_mode(0,destination);
791 town_move_done = TRUE;
792 FlushEvents(2);
795 else need_reprint = TRUE;
796 menu_activate(1);
799 if ((right_button == FALSE) && (overall_mode == 0)) {
800 if (outd_move_party(destination,town_move_done) == TRUE) {
801 center = destination;
802 need_redraw = TRUE;
803 did_something = TRUE;
804 update_explored(party.p_loc);
806 menu_activate(1);
808 else need_redraw = TRUE;
810 storage = out[party.p_loc.x][party.p_loc.y];
811 if (scenario.ter_types[storage].special == 21) {//// town entry
813 if (party.direction == 0) find_direction_from = 2;
814 else if (party.direction == 4) find_direction_from = 0;
815 else if (party.direction < 4) find_direction_from = 3;
816 else find_direction_from = 1;
818 for (i = 0; i < 8; i++)
819 if (same_point(party.loc_in_sec,outdoors[party.i_w_c.x][party.i_w_c.y].exit_locs[i]) == TRUE) {
820 which_t = outdoors[party.i_w_c.x][party.i_w_c.y].exit_dests[i];
821 if (which_t >= 0)
822 start_town_mode(outdoors[party.i_w_c.x][party.i_w_c.y].exit_dests[i], find_direction_from);
823 if (is_town() == TRUE) {
824 need_redraw = FALSE;
825 i = 8;
826 if (party.in_boat >= 0)
827 party.boats[party.in_boat].which_town = c_town.town_num;
828 if (party.in_horse >= 0)
829 party.horses[party.in_horse].which_town = c_town.town_num;
833 } // End if(overall_mode == 0)
836 // End: Moving
838 // Begin: Looking at something
839 if ((right_button == TRUE) || (overall_mode == 35) || (overall_mode == 36) || (overall_mode == 37)) {
840 destination.x = destination.x + i - 4;
841 destination.y = destination.y + j - 4;
843 need_reprint = TRUE;
845 // if ((can_see(cur_loc,destination) >= 4) || ((overall_mode != 35) && (loc_off_world(destination) == TRUE)))
846 if ((is_combat() == FALSE) && (party_can_see(destination) == 6))
847 add_string_to_buf(" Can't see space. ");
848 else if ((is_combat() == TRUE) && (can_see(pc_pos[current_pc],destination,0) >= 4))
849 add_string_to_buf(" Can't see space. ");
850 else {
851 add_string_to_buf("You see... ");
852 ter_looked_at = do_look(destination);
853 if ((is_town()) || (is_combat()))
854 if (adjacent(c_town.p_loc,destination) == TRUE)
855 if (adj_town_look(destination) == TRUE)
856 need_redraw = TRUE;
857 if (is_sign(ter_looked_at)) {
858 print_buf();
859 need_reprint = FALSE;
860 k = 0;
861 if (is_town()) {
862 while (k < 15) {
863 if (same_point (destination, c_town.town.sign_locs[k]) == TRUE) {
864 need_reprint = TRUE;
865 if (adjacent(c_town.town.sign_locs[k],c_town.p_loc)==TRUE)
866 do_sign(c_town.town_num,k,(short) ter_looked_at,destination);
867 else add_string_to_buf(" Too far away to read sign. ");
869 k++;
872 if (is_out()) {
873 loc_in_sec = party.loc_in_sec;
874 loc_in_sec.x += i - 4;
875 loc_in_sec.y += j - 4;
876 while (k < 8) {
877 if (same_point (loc_in_sec,
878 outdoors[party.i_w_c.x][party.i_w_c.y].sign_locs[k]) == TRUE) {
879 need_reprint = TRUE;
880 if (adjacent(outdoors[party.i_w_c.x][party.i_w_c.y].sign_locs[k],party.loc_in_sec)==TRUE)
881 do_sign((short) (200 + get_outdoor_num()),k,(short) ter_looked_at,destination);
882 else add_string_to_buf(" Too far away to read sign. ");
884 k++;
890 // sprintf(store_str," Mod: %d",event.modifiers);
891 // add_string_to_buf(store_str);
893 // If option not pressed, looking done, so restore center
894 if ((ctrl_key == FALSE) && (right_button == FALSE)) {
895 if (overall_mode == 37) {
896 overall_mode = 10;
897 center = pc_pos[current_pc];
898 pause(5);
899 need_redraw = TRUE;
901 else if (overall_mode == 36) {
902 overall_mode = 1;
903 center = c_town.p_loc;
904 need_redraw = TRUE;
906 else if (overall_mode == 35)
907 overall_mode = 0;
912 // End: looking at something
913 if (get_ran(1,0,100) == 50)
914 if (load_blades_data() == FALSE)
915 registered = FALSE;
917 // Begin : talking to someone
918 if (overall_mode == 2) {
919 destination.x = destination.x + i - 4;
920 destination.y = destination.y + j - 4;
922 if ((can_see(cur_loc,destination,0) >= 4) || (loc_off_world(destination) == TRUE)) {
923 add_string_to_buf(" Can't see space ");
924 need_reprint = TRUE;
926 else {
928 for (i = 0; i < T_M; i++) {
929 if (monst_on_space(destination,i) == TRUE) {
930 did_something = TRUE;
931 need_redraw = TRUE;
932 if (c_town.monst.dudes[i].attitude % 2 == 1) {
933 add_string_to_buf(" Creature is hostile. ");
935 else if ((c_town.monst.dudes[i].summoned > 0)////
936 || (c_town.monst.dudes[i].monst_start.personality < 0))
937 add_string_to_buf("Talk: No response. ");
938 else switch (c_town.monst.dudes[i].monst_start.personality) {
939 default:
940 start_talk_mode(i,c_town.monst.dudes[i].monst_start.personality,c_town.monst.dudes[i].number,
941 c_town.monst.dudes[i].monst_start.facial_pic); did_something = FALSE;
942 need_redraw = FALSE;
943 break;
947 if ((did_something == FALSE) && (overall_mode != 20)){
948 add_string_to_buf(" Nobody there");
949 need_reprint = TRUE;
951 if (overall_mode != 20)
952 overall_mode = 1;
954 if (overall_mode != 20)
955 need_redraw = TRUE;
957 // End : talking to someone
959 // Begin : Targeting a space
960 if ((overall_mode == 11) || (overall_mode == 12) || (overall_mode == 13) ||
961 (overall_mode == 14) || (overall_mode == 15)) {
962 destination.x = destination.x + i - 4;
963 destination.y = destination.y + j - 4;
964 if (overall_mode == 11)
965 do_combat_cast(destination);
966 if ((overall_mode == 13) || (overall_mode == 12))
967 fire_missile(destination);
968 if (overall_mode == 14) {
969 place_target(destination);
970 need_reprint = TRUE;
972 if (overall_mode != 14) {
973 did_something = TRUE;
974 center = pc_pos[current_pc];
976 if (overall_mode == 15) { // dropping
977 if (adjacent(pc_pos[current_pc],destination) == FALSE)
978 add_string_to_buf("Drop: must be adjacent.");
979 else {
980 drop_item(current_pc,store_drop_item,destination);
981 take_ap(1);
984 pause(6);
985 need_redraw = TRUE;
986 if ((overall_mode >= 10) && (overall_mode < 20) && (overall_mode != 14))
987 overall_mode = 10;
988 put_pc_screen();
989 put_item_screen(stat_window,0);
991 if ((overall_mode > 2) && (overall_mode < 6)) {
992 destination.x = destination.x + i - 4;
993 destination.y = destination.y + j - 4;
994 switch (overall_mode) {
995 case 3:
996 cast_town_spell(destination);
997 did_something = TRUE;
998 break;
999 case 4:
1000 if (adjacent(destination,c_town.p_loc) == FALSE)
1001 add_string_to_buf(" Must be adjacent. ");
1002 else {
1003 did_something = use_space(destination);
1005 break;
1006 case 5:
1007 if (adjacent(c_town.p_loc,destination) == FALSE)
1008 add_string_to_buf("Drop: must be adjacent.");
1009 else if (get_obscurity(destination.x,destination.y) == 5)
1010 ASB("Drop: Space is blocked.");
1011 else drop_item(current_pc,store_drop_item,destination);
1012 break;
1014 overall_mode = 1;
1015 need_redraw = TRUE;
1016 put_pc_screen();
1017 put_item_screen(stat_window,0);
1019 // End : Targeting a space
1022 //End: click in terrain
1023 if (get_ran(1,0,100) == 50)
1024 if (load_blades_data() == FALSE)
1025 registered = FALSE;
1027 // Begin: Screen shift
1028 if ((overall_mode == 11) || (overall_mode == 12) || (overall_mode == 13) || (overall_mode == 14)
1029 || (overall_mode == 37) || (overall_mode == 36)) {
1030 if ((PtInRect ( &border_rect[0],the_point)) && (center.y > c_town.town.in_town_rect.top)
1031 && (center.y > 4)) {
1032 center.y--;
1033 need_redraw = TRUE;
1035 if ((PtInRect ( &border_rect[1],the_point)) && (center.x > c_town.town.in_town_rect.left)
1036 && (center.x > 4)) {
1037 center.x--;
1038 need_redraw = TRUE;
1040 if ((PtInRect ( &border_rect[2],the_point)) && (center.y < c_town.town.in_town_rect.bottom)
1041 && (center.y < town_size[town_type] - 5)) {
1042 center.y++;
1043 need_redraw = TRUE;
1045 if ((PtInRect (&border_rect[3],the_point)) && (center.x < c_town.town.in_town_rect.right)
1046 && (center.x < town_size[town_type] - 5)) {
1047 center.x++;
1048 need_redraw = TRUE;
1051 // End: Screen shift
1054 // Process clicks in PC stats area
1055 if (PtInRect (&pc_area_rect,the_point)) {
1056 point_in_area = the_point;
1057 point_in_area.x -= PC_WIN_UL_X;
1058 point_in_area.y -= PC_WIN_UL_Y;
1059 if (PtInRect (&pc_help_button,point_in_area)) {
1060 OffsetRect(&pc_help_button,PC_WIN_UL_X,PC_WIN_UL_Y);
1061 arrow_button_click(pc_help_button);
1062 OffsetRect(&pc_help_button,-1 * PC_WIN_UL_X,-1 * PC_WIN_UL_Y);
1063 FCD(1082,0);
1065 for (i = 0; i < 6; i++)
1066 for (j = 0; j < 5; j++)
1067 if ((pc_area_button_active[i][j] > 0) && (PtInRect (&pc_buttons[i][j],point_in_area))) {
1068 OffsetRect(&pc_buttons[i][j],PC_WIN_UL_X,PC_WIN_UL_Y);
1069 arrow_button_click(pc_buttons[i][j]);
1070 OffsetRect(&pc_buttons[i][j],-1 * PC_WIN_UL_X,-1 * PC_WIN_UL_Y);
1071 switch (j) {
1072 case 0:
1073 if ((prime_time() == FALSE) && (overall_mode != 21)&& (overall_mode != 20))
1074 add_string_to_buf("Set active: Finish what you're doing first.");
1075 else if (is_combat())
1076 add_string_to_buf("Set active: Can't set this in combat.");
1077 else if ((adven[i].main_status != 1) &&
1078 ((overall_mode != 21) || (store_shop_type != 3)))
1079 add_string_to_buf("Set active: PC must be here & active.");
1080 else {
1081 current_pc = i;
1082 set_stat_window (i);
1083 if (overall_mode == 21)
1084 sprintf((char *) str,"Now shopping: %s",adven[i].name);
1085 else sprintf((char *) str,"Now active: %s",adven[i].name);
1086 add_string_to_buf((char *)str);
1087 adjust_spell_menus();
1089 break;
1090 case 1:
1091 sprintf((char *) str,"%s has %d health out of %d.",adven[i].name,
1092 adven[i].cur_health,adven[i].max_health);
1093 add_string_to_buf((char *)str);
1094 break;
1095 case 2:
1096 sprintf((char *) str,"%s has %d spell pts. out of %d.",adven[i].name,
1097 adven[i].cur_sp,adven[i].max_sp);
1098 add_string_to_buf((char *)str);
1099 break;
1100 case 3: // pc info
1101 give_pc_info(i);
1102 break;
1103 case 4: // trade places
1104 if (prime_time() == FALSE)
1105 add_string_to_buf("Trade places: Finish what you're doing first.");
1106 else if (is_combat())
1107 add_string_to_buf("Trade places: Can't do this in combat.");
1108 else {
1109 switch_pc(i);
1111 break;
1114 need_reprint = TRUE;
1115 put_pc_screen();
1116 put_item_screen(stat_window,0);
1117 if (overall_mode == 21) {
1118 set_up_shop_array();
1119 draw_shop_graphics(0,pc_buttons[0][0]);
1124 if (get_ran(1,0,1000) == 50)
1125 if (load_blades_data() == FALSE)
1126 registered = FALSE;
1127 // Process clicks in item stats area
1128 if (PtInRect (&item_area_rect,the_point)) {
1129 point_in_area = the_point;
1130 point_in_area.x -= ITEM_WIN_UL_X;
1131 point_in_area.y -= ITEM_WIN_UL_Y;
1133 for (i = 0; i < 9; i++)
1134 if ((item_bottom_button_active[i] > 0) && (PtInRect (&item_screen_button_rects[i],point_in_area))) {
1135 OffsetRect(&item_screen_button_rects[i],ITEM_WIN_UL_X,ITEM_WIN_UL_Y);
1136 arrow_button_click(item_screen_button_rects[i]);
1137 OffsetRect(&item_screen_button_rects[i],-1 * ITEM_WIN_UL_X,-1 * ITEM_WIN_UL_Y);
1138 switch (i) {
1139 case 0: case 1: case 2: case 3: case 4: case 5:
1140 if ((prime_time() == FALSE) && (overall_mode != 20) && (overall_mode != 21))
1141 add_string_to_buf("Set active: Finish what you're doing first.");
1142 else {
1143 if (!(is_combat())) {
1144 if ((adven[i].main_status != 1) &&
1145 ((overall_mode != 21) || (store_shop_type != 12)))
1146 add_string_to_buf("Set active: PC must be here & active.");
1147 else {
1148 current_pc = i;
1149 sprintf((char *) str,"Now active: %s",adven[i].name);
1150 add_string_to_buf((char *)str);
1151 adjust_spell_menus();
1154 set_stat_window(i);
1155 if (overall_mode == 21) {
1156 set_up_shop_array();
1157 draw_shop_graphics(0,item_screen_button_rects[i]); // rect is dummy
1160 break;
1161 case 6: // special screen
1162 give_help(50,0,0);
1163 set_stat_window(6);
1164 break;
1165 case 7: // jobs
1166 give_help(50,0,0);
1167 set_stat_window(7);
1168 break;
1169 case 8: // help
1170 FCD(1090,0);
1171 break;
1174 if (stat_window < 7) {
1175 for (i = 0; i < 8; i++)
1176 for (j = 0; j < 6; j++)
1177 if ((item_area_button_active[i][j] > 0) && (PtInRect (&item_buttons[i][j],point_in_area))) {
1178 OffsetRect(&item_buttons[i][j],ITEM_WIN_UL_X,ITEM_WIN_UL_Y);
1179 if ((j > 0) || (stat_screen_mode < 2))
1180 arrow_button_click(item_buttons[i][j]);
1181 OffsetRect(&item_buttons[i][j],-1 * ITEM_WIN_UL_X,-1 * ITEM_WIN_UL_Y);
1183 item_hit = GetScrollPos(item_sbar,SB_CTL) + i;
1184 if ((prime_time() == FALSE) && (j < 4)
1185 && ((j > 0) || (stat_screen_mode < 2)))
1186 add_string_to_buf("Item action: Finish what you're doing first.");
1187 else switch (j) {
1188 case 0: // equip
1189 if (overall_mode == 4) {
1190 add_string_to_buf("Note: Clicking 'U' button by item");
1191 add_string_to_buf(" uses the item.");
1192 use_item(stat_window, item_hit);
1193 overall_mode = 1;
1194 take_ap(3);
1196 else if (prime_time() == TRUE) {
1197 equip_item(stat_window, item_hit);
1198 take_ap(1);
1200 break;
1201 case 1: // use
1202 use_item(stat_window, item_hit);
1203 if ((overall_mode != 3) && (overall_mode != 11))
1204 did_something = TRUE;
1205 take_ap(3);
1206 break;
1207 case 2: // give
1208 give_thing(stat_window, item_hit);
1209 did_something = TRUE;
1210 need_redraw = TRUE;
1211 take_ap(1);
1212 break;
1213 case 3: // drop
1214 if (stat_window == 6){
1215 use_spec_item(spec_item_array[item_hit]);
1216 need_redraw = TRUE;////
1218 else if (is_out())
1219 drop_item(stat_window,item_hit,party.p_loc);
1220 else {
1221 add_string_to_buf("Drop item: Click where to drop item.");
1222 store_drop_item = item_hit;
1223 overall_mode = (is_town()) ? 5 : 15;
1225 break;
1226 case 4: // info
1227 if (stat_window == 6)
1228 put_spec_item_info(spec_item_array[item_hit]);
1229 else display_pc_item(stat_window, item_hit,adven[stat_window].items[item_hit],0);
1230 break;
1231 case 5: // sell? That this codes was reached indicates that the item was sellable
1232 switch (stat_screen_mode) {
1233 case 2: // identify item
1234 if (take_gold(shop_identify_cost,FALSE) == FALSE)
1235 ASB("Identify: You don't have the gold.");
1236 else {
1237 play_sound(68);
1238 ASB("Your item is identified.");
1239 adven[stat_window].items[item_hit].item_properties =
1240 adven[stat_window].items[item_hit].item_properties | 1;
1242 break;
1243 case 3: case 4: case 5: // various selling
1244 play_sound(39);
1245 party.gold += store_selling_values[i];
1246 ASB("You sell your item.");
1247 take_item(stat_window,item_hit);
1248 break;
1249 case 6: // enchant item
1250 if (take_gold(store_selling_values[i],FALSE) == FALSE)
1251 ASB("Enchant: You don't have the gold.");
1252 else {
1253 play_sound(51);
1254 ASB("Your item is now enchanted.");
1255 enchant_weapon(stat_window,item_hit,shop_identify_cost,store_selling_values[i]);
1257 break;
1260 break;
1264 put_pc_screen();
1265 put_item_screen(stat_window,0);
1266 need_reprint = TRUE;
1270 // Alchemy
1271 if (the_point.x == 1000) {
1272 need_reprint = TRUE;
1273 need_redraw = TRUE;
1274 if (overall_mode == 1) {
1275 do_alchemy();
1277 else add_string_to_buf("Alchemy: Only in town.");
1282 // Wait 40 spaces (town only)
1283 if (the_point.x == 1001) {
1284 need_reprint = TRUE;
1285 need_redraw = TRUE;
1287 if (party_sees_a_monst() == TRUE)
1288 add_string_to_buf("Long wait: Monster in sight.");
1289 else {
1290 add_string_to_buf("Long wait... ");
1291 print_buf();
1292 play_sound(-20);
1293 draw_rest_screen();
1294 pause(10);
1295 for (i = 0; i < 6; i++){
1296 store_sp[i] = adven[i].cur_health;
1297 adven[i].status[6] = 0;
1300 i = 0;
1302 while ((i < 80) && (party_sees_a_monst() == FALSE)){
1303 increase_age();
1304 do_monsters();
1305 do_monster_turn();
1306 j = get_ran(1,1,160 - c_town.difficulty);
1307 if (j == 10)
1308 create_wand_monst();
1309 for (j = 0; j < 6; j++)
1310 if (adven[j].cur_health < store_sp[j]) {
1311 i = 200;
1312 j = 6;
1313 add_string_to_buf(" Waiting interrupted.");
1315 if (party_sees_a_monst() == TRUE) {
1316 i = 200;
1317 add_string_to_buf(" Monster sighted! ");
1319 else i++;
1321 put_pc_screen();
1324 // If in combat and pc delayed, jump forward a step
1325 if (pc_delayed == TRUE) {
1326 initiate_redraw();
1327 //pause(2);
1328 current_pc++;
1329 combat_next_step();
1330 set_stat_window(current_pc);
1331 put_pc_screen();
1334 // At this point, see if any specials have been queued up, and deal with them
1335 for (i = 0; i < 20; i++)
1336 if (special_queue[i] >= 0) {
1337 s3 = 0;
1338 switch (i) {
1339 case 0:
1340 run_special(5,2,special_queue[0],c_town.p_loc,&s1,&s2,&s3);
1341 break;
1342 case 1:
1343 run_special(6,2,special_queue[1],party.p_loc,&s1,&s2,&s3);
1344 break;
1346 if (s3 > 0)
1347 initiate_redraw();
1350 // Handle non-PC stuff (like monsters) if the party actually did something
1351 if (did_something == TRUE) {
1352 draw_map(modeless_dialogs[5],5);
1354 if ((overall_mode >= 10) && (overall_mode < 20)) {
1355 if (no_pcs_left() == TRUE) {
1356 end_combat();
1357 if (which_combat_type == 0) {
1358 end_town_mode(0,party.p_loc);
1359 add_string_to_buf("Fled the combat. ");
1360 handle_wandering_specials(0,2);
1363 else {
1365 if (need_redraw == TRUE) {
1366 initiate_redraw();
1367 if ((combat_active_pc == 6) || (pc_moves[combat_active_pc] > 0))
1368 need_redraw = FALSE;
1370 //pause(2);
1371 store_cur_pc = current_pc;
1372 if (combat_next_step() == TRUE)
1373 need_redraw = TRUE;
1374 /* if ((store_cur_pc != current_pc) && (combat_active_pc == 6)) {
1375 // need_reprint = TRUE;
1376 need_redraw = TRUE;
1377 } */
1381 else {
1382 increase_age();
1383 if (!(is_out()) || ((is_out()) && (party.age % 10 == 0))) // no monst move is party outdoors and on horse
1384 do_monsters();
1385 if (overall_mode != 0)
1386 do_monster_turn();
1387 // Wand monsts
1388 if ((overall_mode == 0) && (party_toast() == FALSE) && (party.age % 10 == 0)) {
1390 i = get_ran(1,1,70 + PSD[306][8] * 200);
1391 if (i == 10)
1392 create_wand_monst();
1393 for (i = 0; i < 10; i++)
1394 if (party.out_c[i].exists == TRUE)
1395 if (((adjacent(party.p_loc,party.out_c[i].m_loc) == TRUE) ||
1396 (party.out_c[i].what_monst.cant_flee >= 10))
1397 && (party.in_boat < 0) && (flying() == FALSE)) {
1398 store_wandering_special = party.out_c[i].what_monst;
1400 if (handle_wandering_specials(0,0) == TRUE)
1401 initiate_outdoor_combat(i);
1402 party.out_c[i].exists = FALSE;
1404 // Get rid of excess keyclicks
1405 FlushEvents(2);
1407 need_reprint = FALSE;
1408 i = 20;
1411 if (overall_mode == 1) {
1412 i = get_ran(1,1,160 - c_town.difficulty + PSD[306][8] * 200);
1413 if (i == 2)
1414 create_wand_monst();
1423 if (need_redraw == TRUE) {
1424 initiate_redraw();
1428 if ((need_reprint == TRUE) || (need_redraw == TRUE)) {
1429 print_buf();
1432 if (end_scenario == TRUE) {
1433 reload_startup();
1434 in_startup_mode = TRUE;
1435 draw_startup(0);
1436 menu_activate(1);
1437 if (FCD(901,0) == 2)
1438 save_file(1);
1440 if (party_toast() == TRUE) {
1441 for (i = 0; i < 6; i++)
1442 if (adven[i].main_status == 5) {
1443 adven[i].main_status = 1;
1444 if (is_combat()) {
1445 end_town_mode(0,c_town.p_loc);
1446 add_string_to_buf("End combat. ");
1447 handle_wandering_specials(0,2);
1450 if (party.stuff_done[304][0] > 0) {
1451 end_split(0);
1452 if (is_combat()) {
1453 overall_mode = 1;
1455 else if (is_town()) {
1458 center = c_town.p_loc;
1460 menu_activate(1);
1461 initiate_redraw();
1462 put_pc_screen();
1463 put_item_screen(stat_window,0);
1464 if (party_toast() == TRUE) {
1465 play_sound(13);
1466 handle_death();
1467 if (All_Done == TRUE)
1468 return TRUE;
1471 //if (is_combat())
1472 // MessageBox(mainPtr,"At end","Debug note",MB_OK | MB_ICONEXCLAMATION);
1473 are_done = All_Done;
1474 return are_done;
1477 Boolean someone_awake()
1479 short i;
1481 for (i = 0; i < 6; i++)
1482 if ((adven[i].main_status == 1) && (adven[i].status[11] <= 0) && (adven[i].status[12] <= 0))
1483 return TRUE;
1484 return FALSE;
1487 void check_cd_event(HWND hwnd,UINT message,UINT wparam,LONG lparam)
1489 POINT press;
1490 Boolean action_done = FALSE;
1491 short wind_hit = -1,item_hit = -1;
1493 switch (message) {
1494 case WM_COMMAND:
1495 // pare out command messages sent from text box
1496 if (wparam == 150)
1497 break;
1498 cd_find_dlog(hwnd,&wind_hit,&item_hit); // item_hit is dummy
1499 item_hit = (short) wparam;
1500 break;
1501 case WM_KEYDOWN:
1502 wind_hit = cd_process_syskeystroke(hwnd, wparam, lparam,&item_hit);
1503 break;
1505 case WM_CHAR:
1506 wind_hit = cd_process_keystroke(hwnd, wparam, lparam,&item_hit);
1507 break;
1509 case WM_LBUTTONDOWN:
1510 press = MAKEPOINT(lparam);
1511 wind_hit = cd_process_click(hwnd,press, wparam, lparam,&item_hit);
1512 break;
1513 case WM_RBUTTONDOWN:
1514 press = MAKEPOINT(lparam);
1515 wparam = wparam | MK_CONTROL;
1516 wind_hit = cd_process_click(hwnd,press, wparam, lparam,&item_hit);
1517 break;
1519 case WM_PAINT:
1520 cd_redraw(hwnd);
1521 break;
1523 if (wind_hit < 0)
1524 return;
1525 switch (wind_hit) {
1526 case -1: break;
1527 case 823: give_password_filter(item_hit); break;
1528 case 869: pick_prefab_scen_event_filter(item_hit); break;
1529 case 947: pick_a_scen_event_filter(item_hit); break;
1530 case 958: tip_of_day_event_filter(item_hit); break;
1531 case 960: talk_notes_event_filter(item_hit); break;
1532 case 961: adventure_notes_event_filter(item_hit); break;
1533 case 970: case 971: case 972: case 973: display_strings_event_filter(item_hit); break;
1534 case 987: display_item_event_filter(item_hit); break;
1535 case 988: pick_trapped_monst_event_filter(item_hit); break;
1536 case 989: edit_party_event_filter(item_hit); break;
1537 case 991: display_pc_event_filter(item_hit); break;
1538 case 996: display_alchemy_event_filter(item_hit); break;
1539 case 997: display_help_event_filter(item_hit); break;
1540 case 998: display_pc_item_event_filter(item_hit); break;
1541 case 999: display_monst_event_filter(item_hit); break;
1542 case 1010: spend_xp_event_filter (item_hit); break;
1543 case 1012: get_num_of_items_event_filter (item_hit); break;
1544 case 1013: pick_race_abil_event_filter (item_hit); break;
1545 case 1014: sign_event_filter (item_hit); break;
1546 case 1017: case 873: get_text_response_event_filter (item_hit); break;
1547 case 1018: select_pc_event_filter (item_hit); break;
1548 case 1019: give_pc_info_event_filter(item_hit); break;
1549 case 1047: alch_choice_event_filter(item_hit); break;
1550 case 1050: pc_graphic_event_filter(item_hit); break;
1551 case 1051: pc_name_event_filter(item_hit); break;
1552 case 1073: give_reg_info_event_filter (item_hit); break;
1553 case 1075: do_registration_event_filter (item_hit); break;
1554 case 1096: display_spells_event_filter (item_hit); break;
1555 case 1097: display_skills_event_filter (item_hit); break;
1556 case 1098: pick_spell_event_filter (item_hit); break;
1557 case 1099: prefs_event_filter (item_hit); break;
1558 default: fancy_choice_dialog_event_filter (item_hit); break;
1563 void flash_rect(RECT to_flash)
1565 int i;
1566 long dummy;
1567 HDC hdc;
1569 hdc = GetDC(mainPtr);
1570 SetViewportOrg( hdc,ulx,uly);
1571 InvertRect (hdc,&to_flash);
1572 play_sound(37);
1573 Delay(5,&dummy);
1574 InvertRect (hdc,&to_flash);
1575 fry_dc(mainPtr,hdc);
1579 void button_flash_rect(RECT to_flash)
1581 int i;
1582 long dummy;
1583 HDC hdc;
1585 hdc = GetDC(mainPtr);
1586 InvertRect (hdc,&to_flash);
1587 if (play_sounds == TRUE)
1588 play_sound(34);
1589 else Delay(5,&dummy);
1590 InvertRect (hdc,&to_flash);
1591 fry_dc(mainPtr,hdc);
1595 void flash_round_rect(RECT to_flash,short radius)
1597 int i;
1598 long dummy;
1599 HDC hdc;
1601 hdc = GetDC(mainPtr);
1602 SetViewportOrg( hdc,ulx,uly);
1603 InvertRect (hdc,&to_flash);
1604 play_sound(37);
1605 Delay(5,&dummy);
1606 InvertRect (hdc,&to_flash);
1607 fry_dc(mainPtr,hdc);
1612 void handle_menu_spell(short spell_picked,short spell_type)
1614 POINT pass_point;
1616 spell_forced = TRUE;
1617 pc_casting = current_pc;
1618 pc_last_cast[spell_type][current_pc] = spell_picked;
1619 if (spell_type == 0)
1620 store_mage = spell_picked;
1621 else store_priest = spell_picked;
1622 if ((spell_type == 0) && (mage_need_select[spell_picked] > 0)) {
1623 if ((store_spell_target = char_select_pc(2 - mage_need_select[spell_picked],0,"Cast spell on who?")) == 6)
1624 return;
1626 else {
1627 if ((spell_type == 1) && (priest_need_select[spell_picked] > 0))
1628 if ((store_spell_target = char_select_pc(2 - priest_need_select[spell_picked],0,"Cast spell on who?")) == 6)
1629 return;
1632 pass_point.x = bottom_buttons[spell_type].left + 5;
1633 pass_point.y = bottom_buttons[spell_type].top + 5;
1634 handle_action(pass_point,0,-1);
1637 void initiate_outdoor_combat(short i)
1639 long dummy;
1640 short m,n,store_lev;
1641 location to_place;
1643 initiate_redraw();
1645 // Is combat too easy?
1646 if ((party_total_level() > ((out_enc_lev_tot(i) * 5) / 3) ) && (out_enc_lev_tot(i) < 200)
1647 && (party.out_c[i].what_monst.cant_flee % 10 != 1)) {
1648 add_string_to_buf("Combat: Monsters fled! ");
1649 party.out_c[i].exists = FALSE;
1650 return;
1653 // Delay((long) 100,&dummy);
1655 start_outdoor_combat(party.out_c[i], out[party.p_loc.x][party.p_loc.y],count_walls(party.p_loc));
1657 party.out_c[i].exists = FALSE;
1659 for (m = 0; m < 6; m++)
1660 if (adven[m].main_status == 1)
1661 to_place = pc_pos[m];
1662 for (m = 0; m < 6; m++)
1663 for (n = 0; n < 24; n++)
1664 if ((adven[m].main_status != 1) && (adven[m].items[n].variety != 0)) {
1665 place_item(adven[m].items[n],to_place,TRUE);
1666 adven[m].items[n].variety = 0;
1669 overall_mode = 10;
1670 center = pc_pos[current_pc];
1671 initiate_redraw();
1674 void initiate_redraw()
1675 // Draw changes in terrain, but only if terrain is onscreen
1677 /*if (is_combat()) {
1678 print_nums(0,0,current_pc);
1679 print_buf();
1680 MessageBox(mainPtr,"In redraw proc now","Debug note",MB_OK | MB_ICONEXCLAMATION);
1681 } */
1682 if ((overall_mode < 20) || (overall_mode >= 30))
1683 draw_terrain(0);
1686 Boolean handle_syskeystroke(UINT wParam,LONG lParam,short *handled)
1688 UINT kp[10] = {VK_NUMPAD0,VK_NUMPAD1, VK_NUMPAD2, VK_NUMPAD3, VK_NUMPAD4,
1689 VK_NUMPAD5, VK_NUMPAD6, VK_NUMPAD7, VK_NUMPAD8, VK_NUMPAD9};
1690 POINT terrain_click[10] = {{150,185},{120,215},{150,215},{180,215},
1691 {120,185},{150,185},{180,185},
1692 {120,155},{150,155},{180,135}};
1693 POINT pass_point;
1694 Boolean are_done = FALSE;
1695 short i;
1697 if (in_startup_mode == TRUE)
1698 return FALSE;
1700 for (i = 0; i < 10; i++)
1701 if (wParam == kp[i]) {
1702 if (i == 0) {
1703 *handled = 1;
1704 return handle_keystroke((UINT) 'z',-1);
1706 else {
1707 //*handled = 1;
1708 pass_point.x = terrain_click[i].x;
1709 pass_point.y = terrain_click[i].y;
1710 wParam = 0;
1711 FlushEvents(0);
1712 are_done = handle_action(pass_point,wParam,-1);
1713 return are_done;
1717 if (overall_mode == 20) {
1718 if (wParam == VK_ESCAPE) {
1719 pass_point.x = preset_words[6].word_rect.left + 9;
1720 pass_point.y = preset_words[6].word_rect.top + 9;
1721 are_done = handle_action(pass_point,wParam,-1);
1722 return are_done;
1725 else if (overall_mode == 21) { // shopping keystrokes
1726 if (wParam == VK_ESCAPE) {
1727 pass_point.x = 222;
1728 pass_point.y = 398;
1729 are_done = handle_action(pass_point,wParam,-1);
1730 return are_done;
1734 if ((wParam == VK_LEFT) || (wParam == VK_RIGHT)) {
1735 *handled = 1;
1736 pass_point.x = (wParam == VK_LEFT) ? 120 : 180;
1737 pass_point.y = 185;
1738 are_done = handle_action(pass_point,wParam,-1);
1739 return are_done;
1741 if ((wParam == VK_UP) || (wParam == VK_DOWN)) {
1742 *handled = 1;
1743 pass_point.x = 150;
1744 pass_point.y = (wParam == VK_UP) ? 155 : 215;
1745 are_done = handle_action(pass_point,wParam,-1);
1746 return are_done;
1748 return are_done;
1752 Boolean handle_keystroke(UINT wParam,LONG lParam)
1754 Boolean are_done = FALSE;
1755 POINT pass_point;
1756 short i,j,k,l,dum;
1757 long i2,j2,k2,l2,dum2;
1758 long dummy;
1759 short the_type;
1760 DWORD s1;
1761 UINT s2,s3;
1763 char keypad[10] = {82,83,84,85,86,87,88,89,91,92};
1764 POINT terrain_click[10] = {{150,185},{120,215},{150,215},{180,215},
1765 {120,185},{150,185},{180,185},
1766 {120,155},{150,155},{180,135}};
1767 char talk_chars[9] = {'l','n','j','b','s','r','d','g','a'};
1768 Boolean dialog_grabbed_key = FALSE;
1769 char chr;
1771 if (in_startup_mode == TRUE)
1772 return FALSE;
1774 chr = (char) wParam;
1776 if (overall_mode == 20) {
1777 if (chr == ' ')
1778 chr = 'g';
1779 for (i = 0; i < 9; i++)
1780 if (chr == talk_chars[i]) {
1781 pass_point.x = preset_words[i].word_rect.left + 9;
1782 pass_point.y = preset_words[i].word_rect.top + 9;
1783 are_done = handle_action(pass_point,wParam,-1);
1784 return are_done;
1787 else if (overall_mode == 21) { // shopping keystrokes
1788 for (i = 0; i < 8; i++)
1789 if (chr == 97 + i) {
1790 pass_point.x = shopping_rects[i][1].left + 9;
1791 pass_point.y = shopping_rects[i][1].top + 9;
1792 are_done = handle_action(pass_point,wParam,-1);
1793 return are_done;
1797 if ((overall_mode != 20) && (overall_mode != 21)) {
1799 for (k = 0; k < (short) LOWORD(lParam); k++)
1800 switch(chr)
1803 case 'D':
1804 if (in_scen_debug == TRUE) {
1805 if (registered == FALSE) {
1806 ASB("Until your copy is registered,");
1807 ASB("you can't turn debug mode off.");
1808 break;
1810 in_scen_debug = FALSE;
1811 ASB("Debug mode OFF.");
1813 else if (enter_password() == FALSE)
1814 ASB("Password incorrect.");
1815 else {
1816 in_scen_debug = TRUE;
1817 ASB("Debug mode ON.");
1819 print_buf();
1820 break;
1822 case 'E':
1823 add_string_to_buf("Memory check:");
1824 ASB("Num 1: Free memory div by 1000");
1825 ASB("Num 2: % of user resources left");
1826 ASB("Num 3: % of graphics resources left");
1827 s1 = GetFreeSpace(0);
1828 s2 = GetFreeSystemResources(GFSR_USERRESOURCES);
1829 i = (short) (s1 / 1000);
1830 j = (short) s2;
1831 s2 = GetFreeSystemResources(GFSR_GDIRESOURCES);
1832 k = (short) s2;
1833 print_nums(i,j,k);
1835 print_buf();
1837 return FALSE;
1838 case '&':
1839 add_string_to_buf("If Valorim ...");
1840 print_buf();
1841 break;
1842 case '*':
1843 add_string_to_buf("You want to save ...");
1844 print_buf();
1845 break;
1846 case '(':
1847 add_string_to_buf("Back up your save files ...");
1848 print_buf();
1849 break;
1850 case ')':
1851 add_string_to_buf("Burma Shave.");
1852 print_buf();
1853 break;
1855 case '?':
1856 if (is_out()) FCD(1079,0);
1857 if (is_town()) FCD(1080,0);
1858 if (is_combat()) FCD(1081,0);
1859 if (overall_mode == 21) {
1860 party.help_received[26] = 0;
1861 give_help(226,27,0);
1863 if (overall_mode == 21) {
1864 party.help_received[26] = 0;
1865 give_help(226,27,0);
1867 if (overall_mode == 20) {
1868 party.help_received[5] = 0;
1869 give_help(205,6,0);
1871 break;
1873 case '1': case '2': case '3': case '4': case '5': case '6':
1874 pass_point.x = pc_buttons[((short) chr) - 49][0].left + 1 + PC_WIN_UL_X;
1875 pass_point.y = pc_buttons[((short) chr) - 49][0].top + PC_WIN_UL_Y;
1876 are_done = handle_action(pass_point,wParam,-1);
1877 return are_done;
1878 break;
1880 case '9':
1881 pass_point.x = item_screen_button_rects[6].left + ITEM_WIN_UL_X;
1882 pass_point.y = item_screen_button_rects[6].top + ITEM_WIN_UL_Y;
1883 are_done = handle_action(pass_point,wParam,-1);
1884 return are_done;
1885 break;
1887 case ' ':
1888 if (overall_mode == 14) { // cast multi-target spell, set # targets to 0 so that
1889 // space clicked doesn't matter
1890 num_targets_left = 0;
1891 pass_point = terrain_click[5];
1892 are_done = handle_action(pass_point,wParam,-1);
1893 return are_done;
1895 if (overall_mode == 11)
1896 spell_cast_hit_return();
1897 break;
1900 case 'z':
1901 if (((overall_mode >= 10) && (overall_mode < 20)) || (overall_mode == 37)) {
1902 set_stat_window(current_pc);
1903 put_item_screen(stat_window,0);
1905 else {
1906 set_stat_window(0);
1907 put_item_screen(stat_window,0);
1909 break;
1911 case '=':
1912 if (debug_on == FALSE) {
1913 for (i = 0; i < 6; i++)
1914 adven[i].exp_adj = 100;
1915 break;
1917 party.gold += 100;
1918 party.food += 100;
1919 for (i = 0; i < 6; i++) {
1920 adven[i].main_status = 1;
1921 adven[i].cur_health = 100;
1922 adven[i].cur_sp = 100;
1924 award_party_xp(25);
1925 refresh_store_items();
1926 for (i = 0; i < 6; i++)
1927 for (j = 0; j < 62; j++) {
1928 adven[i].mage_spells[j] = TRUE;
1929 adven[i].priest_spells[j] = TRUE;
1930 adven[i].skills[9] = 7;
1931 adven[i].skills[10] = 7;
1934 add_string_to_buf("Debug: Add stuff and heal. ");
1935 print_buf();
1936 put_pc_screen();
1937 break;
1939 case 'K':
1940 if (debug_on) {
1941 for (i = 0; i < T_M; i++) {
1942 if ((is_combat()) && (c_town.monst.dudes[i].active > 0) && (c_town.monst.dudes[i].attitude % 2 == 1))
1943 c_town.monst.dudes[i].active = 0;
1945 if ((c_town.monst.dudes[i].active > 0) && (c_town.monst.dudes[i].attitude % 2 == 1)
1946 && (dist(c_town.monst.dudes[i].m_loc,c_town.p_loc) <= 10) )
1947 damage_monst(i, 7,1000,0, 4);
1949 // kill_monst(&c_town.monst.dudes[i],6);
1950 initiate_redraw();
1951 add_string_to_buf("Debug: Kill things. ");
1952 print_buf();
1955 break;
1959 case 'W':
1960 refresh_store_items();
1961 add_string_to_buf("Debug: Refreshed jobs/shops. ");
1962 print_buf();
1963 break;
1965 // case 'R':
1966 // current_switch = 6;
1967 // start_new_game(0);
1968 // break;
1969 case '`':
1970 break;
1971 //dump_gworld();
1972 break;
1973 case '[':
1974 break;
1975 debug_ok = 1;
1976 return FALSE;
1977 break;
1978 case '+':
1979 break;
1980 if (debug_on == TRUE) {
1981 print_nums(-999,-999,-999);
1982 debug_on = FALSE;
1984 if (debug_ok == 1) {
1985 print_nums(999,999,999);
1986 debug_on = TRUE;
1988 break;
1989 case '/':
1990 if (debug_on == TRUE) {
1991 ASB("Debug: Increase age.");
1992 print_buf();
1993 party.age += 5000;
1994 put_pc_screen();
1996 break;
1997 case '>':
1998 ASB("DEBUG: Towns have short memory.");
1999 ASB("Your deeds have been forgotten.");
2000 print_buf();
2001 for (i = 0; i < 4; i++)
2002 party.creature_save[i].which_town = 200;
2003 break;
2004 case 'a':
2005 if (overall_mode < 2) {
2006 pass_point.x = (overall_mode == 0) ? 170 : 221;
2007 pass_point.y = 405;
2008 are_done = handle_action(pass_point,wParam,-1);
2009 return are_done;
2012 break;
2014 case 'b': case 'u': case 'L':
2015 if (overall_mode == 1) {
2016 pass_point.x = (chr == 'u') ? 220 : 205;
2017 pass_point.y = (chr == 'L') ? 405 : 388;
2018 are_done = handle_action(pass_point,wParam,-1);
2019 return are_done;
2021 break;
2023 case 's': case 'x': case 'e':
2024 if ((overall_mode == 10) ||
2025 ((overall_mode == 12) && (chr == 's')) ||
2026 ((overall_mode == 13) && (chr == 's')) ) {
2027 pass_point.x = (chr == 's') ? 205 : 240;
2028 pass_point.y = (chr == 'e') ? 390 : 406;
2029 are_done = handle_action(pass_point,wParam,-1);
2030 return are_done;
2032 break;
2035 case 'm': case 'p': case 'l': case 'r': case 'w': case 't': case 'd': case 'g': case 'f':
2036 case 'M': case 'P': case 'A':
2037 j = 50;
2038 if ((chr == 'm') && ((overall_mode == 11) || (overall_mode == 14))) // cancel spell
2039 j = 0;
2040 if ((chr == 'p') && ((overall_mode == 11) || (overall_mode == 14))) // cancel spell
2041 j = 1;
2042 if ((overall_mode == 0) || (overall_mode == 1) || (overall_mode == 10)) {
2043 switch (chr) {
2044 case 'M': spell_forced = TRUE; j = 0; break;
2045 case 'm': j = 0; break;
2046 case 'P': spell_forced = TRUE; j = 1; break;
2047 case 'p': j = 1; break;
2048 case 'l': j = 2; break;
2049 case 'r': if (overall_mode != 0) return FALSE;
2050 j = 3;
2051 break;
2052 case 't': if (overall_mode == 1)
2053 j = 3;
2054 else return FALSE;
2055 break;
2056 case 'A':if (overall_mode == 1) {
2057 pass_point.x = 1000;
2058 are_done = handle_action(pass_point,wParam,-1);
2060 else {
2061 add_string_to_buf("Alchemy: In town only.");
2062 print_buf();
2063 return FALSE;
2065 break;
2066 case 'w':if (overall_mode == 10)
2067 j = 5;
2068 else if (overall_mode == 1) {
2069 pass_point.x = 1001;
2070 are_done = handle_action(pass_point,wParam,-1);
2072 else {
2073 add_string_to_buf("Wait: In town only.");
2074 print_buf();
2075 return FALSE;
2077 break;
2078 case 'd': if (overall_mode != 10) return FALSE;
2079 j = 3;
2080 break;
2081 case 'g': if (overall_mode == 0) return FALSE;
2082 j = 4;
2083 break;
2084 case 'f': if (overall_mode != 1) return FALSE;
2085 j = 6;
2086 break;
2089 if (j < 50) {
2090 pass_point.x = bottom_buttons[j].left + 5;
2091 pass_point.y = bottom_buttons[j].top + 5;
2092 are_done = handle_action(pass_point,wParam,-1);
2093 return are_done;
2095 break;
2099 debug_ok = 0;
2101 spell_forced = FALSE;
2102 return are_done;
2106 void menu_activate( short type)
2107 // type; // 0 - save off alter off 1 - not all off
2109 HMENU menu;
2110 short i;
2112 menu = GetMenu(mainPtr);
2114 if (in_startup_mode == TRUE) {
2115 EnableMenuItem(menu,2,MF_GRAYED | MF_BYCOMMAND);
2116 EnableMenuItem(menu,3,MF_GRAYED | MF_BYCOMMAND);
2117 EnableMenuItem(menu,21,MF_GRAYED | MF_BYCOMMAND);
2118 EnableMenuItem(menu,22,MF_GRAYED | MF_BYCOMMAND);
2119 EnableMenuItem(menu,23,MF_GRAYED | MF_BYCOMMAND);
2120 EnableMenuItem(menu,24,MF_GRAYED | MF_BYCOMMAND);
2121 EnableMenuItem(menu,26,MF_GRAYED | MF_BYCOMMAND);
2122 EnableMenuItem(menu,27,MF_GRAYED | MF_BYCOMMAND);
2123 EnableMenuItem(menu,28,MF_GRAYED | MF_BYCOMMAND);
2124 EnableMenuItem(menu,29,MF_GRAYED | MF_BYCOMMAND);
2125 EnableMenuItem(menu,81,MF_GRAYED | MF_BYCOMMAND);
2126 EnableMenuItem(menu,82,MF_GRAYED | MF_BYCOMMAND);
2127 EnableMenuItem(menu,84,MF_GRAYED | MF_BYCOMMAND);
2128 //EnableMenuItem(menu,,MF_GRAYED | MF_BYCOMMAND);
2130 DrawMenuBar(mainPtr);
2131 return;
2134 EnableMenuItem(menu,3,MF_ENABLED | MF_BYCOMMAND);
2135 EnableMenuItem(menu,2,MF_ENABLED | MF_BYCOMMAND);
2136 EnableMenuItem(menu,21,MF_ENABLED | MF_BYCOMMAND);
2137 EnableMenuItem(menu,22,MF_ENABLED | MF_BYCOMMAND);
2138 EnableMenuItem(menu,23,MF_ENABLED | MF_BYCOMMAND);
2139 EnableMenuItem(menu,24,MF_ENABLED | MF_BYCOMMAND);
2140 EnableMenuItem(menu,26,MF_ENABLED | MF_BYCOMMAND);
2141 EnableMenuItem(menu,27,MF_ENABLED | MF_BYCOMMAND);
2142 EnableMenuItem(menu,28,MF_ENABLED | MF_BYCOMMAND);
2143 EnableMenuItem(menu,29,MF_ENABLED | MF_BYCOMMAND);
2144 EnableMenuItem(menu,81,MF_ENABLED | MF_BYCOMMAND);
2145 EnableMenuItem(menu,82,MF_ENABLED | MF_BYCOMMAND);
2146 EnableMenuItem(menu,84,MF_ENABLED | MF_BYCOMMAND);
2147 DrawMenuBar(mainPtr);
2148 /* cur_menu = GetMHandle(600);
2149 EnableItem(cur_menu,0);
2150 cur_menu = GetMHandle(700);
2151 EnableItem(cur_menu,0);
2152 cur_menu = GetMHandle(800);
2153 EnableItem(cur_menu,0);
2154 cur_menu = GetMHandle(900);
2155 EnableItem(cur_menu,0);
2156 cur_menu = GetMHandle(950);
2157 EnableItem(cur_menu,0);
2159 cur_menu = GetMHandle(550);
2160 EnableItem(cur_menu,2);
2161 EnableItem(cur_menu,3);
2165 void do_load()
2167 load_file();
2168 if (in_startup_mode == FALSE)
2169 post_load();
2170 menu_activate(1);
2173 void post_load()
2175 current_switch = 6;
2177 reset_item_max();
2179 if (overall_mode == 0)
2180 update_explored(party.p_loc);
2181 if (overall_mode == 1) {
2182 make_town_trim(0);
2184 make_out_trim();
2186 create_clip_region();
2187 redraw_screen(0);
2190 stat_window = first_active_pc();
2191 set_stat_window(0);
2193 //put_pc_screen();
2194 //initiate_redraw();
2196 //beep(); beep();beep();beep();beep();
2197 //draw_buttons(0);
2198 //draw_text_bar(1);
2200 //print_buf();
2202 clear_map();
2203 adjust_spell_menus();
2204 adjust_monst_menu();
2206 cartoon_happening = FALSE;
2209 void do_save(short mode)
2210 //mode; // 0 - normal 1 - save as
2212 // SelectWindow(mainPtr);
2213 if (overall_mode > 1) {
2214 add_string_to_buf("Save: Only while outdoors, or in ");
2215 add_string_to_buf(" town and not looking/casting. ");
2216 print_buf();
2217 return;
2219 save_file(mode);
2220 pause(6);
2221 initiate_redraw();
2222 put_pc_screen();
2223 put_item_screen(stat_window,0);
2224 print_buf();
2227 void increase_age()
2229 short i,j,k,item,how_many_short = 0,r1,store_day;
2230 Boolean update_stat = FALSE;
2233 // Increase age, adjust light level & stealth
2234 store_day = calc_day();
2235 if (is_out()) {
2236 if (party.in_horse < 0)
2237 party.age -= party.age % 10;
2238 else party.age -= party.age % 5;
2239 party.age += 5;
2240 if (party.in_horse < 0)
2241 party.age += 5;
2244 else party.age++;
2245 if (calc_day() != store_day) { // Day changed, so check for interesting stuff.
2246 update_stat = TRUE;
2249 party.light_level = move_to_zero(party.light_level);
2251 // if (party.stuff_done[128][9] == 1)
2252 // clear_map();
2254 // decrease monster present counter
2255 party.stuff_done[305][9] = move_to_zero(party.stuff_done[305][9]);
2257 // Party spell effects
2258 if (party.stuff_done[305][0] == 1) {reset_text_bar();
2259 add_string_to_buf("Your footsteps grow louder. "); }
2260 party.stuff_done[305][0] = move_to_zero(party.stuff_done[305][0]);
2261 if (party.stuff_done[305][2] == 1) {reset_text_bar();
2262 add_string_to_buf("You stop detecting monsters. ");}
2263 party.stuff_done[305][2] = move_to_zero(party.stuff_done[305][2]);
2264 if (party.stuff_done[305][3] == 1) {reset_text_bar();
2265 add_string_to_buf("Your feet stop glowing. ");}
2266 party.stuff_done[305][3] = move_to_zero(party.stuff_done[305][3]);
2268 if (party.stuff_done[305][1] == 2)
2269 add_string_to_buf("You are starting to descend.");
2270 if (party.stuff_done[305][1] == 1) {
2271 if (scenario.ter_types[out[party.p_loc.x][party.p_loc.y]].blockage > 2) {
2272 add_string_to_buf(" You plummet to your deaths. ");
2273 slay_party(2);
2274 print_buf();
2275 pause(150);
2277 else add_string_to_buf(" You land safely. ");
2278 reset_text_bar();
2281 party.stuff_done[305][1] = move_to_zero(party.stuff_done[305][1]);
2283 if ((overall_mode > 0) && (c_town.town.lighting == 2))
2284 party.light_level = max (0,party.light_level - 9);
2285 if (c_town.town.lighting == 3) {
2286 if (party.light_level > 0)
2287 ASB("Your light is drained.");
2288 party.light_level = 0;
2292 // Specials countdowns
2293 if ((party.age % 500 == 0) && (get_ran(1,0,5) == 3) && (party_has_abil(52) == TRUE)) {
2294 update_stat = TRUE;
2295 display_enc_string(52,39,3);
2296 for (i = 0; i < 6; i++)
2297 disease_pc(i,2);
2301 // Plants and magic shops
2302 if (party.age % 4000 == 0) {
2303 //SysBeep(2);
2304 //ASB("DEBUG: Stuff replaced.");
2305 refresh_store_items();
2306 //for (i = 0; i < 10; i++)
2307 // party.stuff_done[302][i] = 0;
2308 //for (i = 0; i < 10; i++)
2309 // party.stuff_done[301][i] = 0;
2310 //for (i = 0; i < 10; i++)
2311 //// party.stuff_done[300][i] = 0;
2314 // Protection, etc.
2315 for (i = 0; i < 6; i++) { // Process some status things, and check if stats updated
2317 if ((adven[i].status[4] == 1) || (adven[i].status[5] == 1) || (adven[i].status[8] == 1)
2318 || (adven[i].status[11] == 1)|| (adven[i].status[12] == 1))
2319 update_stat = TRUE;
2320 adven[i].status[4] = move_to_zero(adven[i].status[4]);
2321 adven[i].status[5] = move_to_zero(adven[i].status[5]);
2322 adven[i].status[8] = move_to_zero(adven[i].status[8]);
2323 adven[i].status[10] = move_to_zero(adven[i].status[10]);
2324 adven[i].status[11] = move_to_zero(adven[i].status[11]);
2325 adven[i].status[12] = move_to_zero(adven[i].status[12]);
2326 if ((party.age % 40 == 0) && (adven[i].status[0] > 0)) {
2327 update_stat = TRUE;
2328 adven[i].status[0] = move_to_zero(adven[i].status[0]);
2333 // Food
2334 if ((party.age % 1000 == 0) && (overall_mode < 10)) {
2335 for (i = 0; i < 6; i++)
2336 if (adven[i].main_status == 1)
2337 how_many_short++;
2338 how_many_short = take_food (how_many_short,FALSE);
2339 if (how_many_short > 0) {
2340 add_string_to_buf("Starving! ");
2341 play_sound(66);
2342 r1 = get_ran(3,1,6);
2343 hit_party(r1,4);
2344 update_stat = TRUE;
2345 if (overall_mode < 10)
2346 boom_space(party.p_loc,overall_mode,0,r1,0);
2348 else {
2349 play_sound(6);
2350 add_string_to_buf("You eat. ");
2352 update_stat = TRUE;
2355 // Poison, acid, disease damage
2356 for (i = 0; i < 6; i++) // Poison
2357 if (adven[i].status[2] > 0) {
2358 i = 6;
2359 if (((overall_mode == 0) && (party.age % 50 == 0)) || ((overall_mode == 1) && (party.age % 20 == 0))) {
2360 update_stat = TRUE;
2361 do_poison();
2364 for (i = 0; i < 6; i++) // Disease
2365 if (adven[i].status[7] > 0) {
2366 i = 6;
2367 if (((overall_mode == 0) && (party.age % 100 == 0)) || ((overall_mode == 1) && (party.age % 25 == 0))) {
2368 update_stat = TRUE;
2369 handle_disease();
2372 for (i = 0; i < 6; i++) // Acid
2373 if (adven[i].status[13] > 0) {
2374 i = 6;
2375 update_stat = TRUE;
2376 handle_acid();
2379 // Healing and restoration of spell pts.
2380 if (is_out()) {
2381 if (party.age % 100 == 0) {
2382 for (i = 0; i < 6; i++)
2383 if ((adven[i].main_status == 1) && (adven[i].cur_health < adven[i].max_health))
2384 update_stat = TRUE;
2385 heal_party(2);
2388 else {
2389 if (party.age % 50 == 0) {
2390 for (i = 0; i < 6; i++)
2391 if ((adven[i].main_status == 1) && (adven[i].cur_health < adven[i].max_health))
2392 update_stat = TRUE;
2393 heal_party(1);
2396 if (is_out()) {
2397 if (party.age % 80 == 0) {
2398 for (i = 0; i < 6; i++)
2399 if ((adven[i].main_status == 1) && (adven[i].cur_sp < adven[i].max_sp))
2400 update_stat = TRUE;
2401 restore_sp_party(2);
2404 else {
2405 if (party.age % 40 == 0) {
2406 for (i = 0; i < 6; i++)
2407 if ((adven[i].main_status == 1) && (adven[i].cur_sp < adven[i].max_sp))
2408 update_stat = TRUE;
2409 restore_sp_party(1);
2413 // Recuperation and chronic disease disads
2414 for (i = 0; i < 6; i++)
2415 if (adven[i].main_status == 1) {
2416 if ((adven[i].traits[9] > 0) && (get_ran(1,0,10) == 1) && (adven[i].cur_health < adven[i].max_health)) {
2417 heal_pc(i,2);
2418 update_stat = TRUE;
2420 if ((adven[i].traits[13] > 0) && (get_ran(1,0,110) == 1)) {
2421 disease_pc(i,4);
2422 update_stat = TRUE;
2428 // Blessing, slowed,etc.
2429 if (party.age % 4 == 0)
2430 for (i = 0; i < 6; i++) {
2431 if ((adven[i].status[1] != 0) || (adven[i].status[3] != 0))
2432 update_stat = TRUE;
2433 adven[i].status[1] = move_to_zero(adven[i].status[1]);
2434 adven[i].status[3] = move_to_zero(adven[i].status[3]);
2435 if (((item = pc_has_abil_equip(i,50)) < 24)
2436 && (adven[i].cur_health < adven[i].max_health)
2437 && ((overall_mode > 0) || (get_ran(1,0,10) == 5))){
2438 j = get_ran(1,0,adven[i].items[item].ability_strength / 3);
2439 if (adven[i].items[item].ability_strength / 3 == 0)
2440 j = get_ran(1,0,1);
2441 if (is_out()) j = j * 4;
2442 heal_pc(i,j);
2443 update_stat = TRUE;
2447 dump_gold(1);
2449 special_increase_age();
2450 //if (debug_on == FALSE)
2451 push_things();
2453 if (is_town()) {
2454 process_fields();
2459 // Cancel switching PC order
2460 current_switch = 6;
2462 // If a change, draw stat screen
2463 if (update_stat == TRUE)
2464 put_pc_screen();
2465 adjust_spell_menus();
2468 void handle_cave_lore()
2470 char str[60];
2471 short i,pic;
2472 unsigned char ter;
2474 if (!is_out())
2475 return;
2477 ter = out[party.p_loc.x][party.p_loc.y];
2478 pic = scenario.ter_types[ter].picture;
2479 for (i = 0; i < 6; i++)
2480 if ((adven[i].main_status == 1) && (adven[i].traits[4] > 0) && (get_ran(1,0,12) == 5)
2481 && (((pic >= 0) && (pic <= 1)) || ((pic >= 70) && (pic <= 76))) ) {
2482 sprintf((char *)str,"%s hunts.",adven[i].name);
2483 party.food += get_ran(2,1,6);
2484 add_string_to_buf((char *)str);
2485 put_pc_screen();
2487 for (i = 0; i < 6; i++)
2488 if (
2489 (adven[i].main_status == 1) && (adven[i].traits[5] > 0) && (get_ran(1,0,12) == 5)
2490 && (((pic >= 2) && (pic <= 4)) || ((pic >= 79) && (pic <= 84)))) {
2491 sprintf((char *)str,"%s hunts.",adven[i].name);
2492 party.food += get_ran(2,1,6);
2493 add_string_to_buf((char *)str);
2494 put_pc_screen();
2500 void switch_pc(short which)
2502 pc_record_type store_pc;
2504 if (current_switch < 6) {
2505 if (current_switch != which) {
2506 add_string_to_buf("Switch: OK.");
2507 store_pc = adven[which];
2508 adven[which] = adven[current_switch];
2509 adven[current_switch] = store_pc;
2510 if (current_pc == current_switch)
2511 current_pc = which;
2512 else if (current_pc == which)
2513 current_pc = current_switch;
2514 set_stat_window(current_pc);
2515 update_pc_graphics();
2516 current_switch = 6;
2518 else {
2519 ASB("Switch: Not with self.");
2520 current_switch = 6;
2523 else {
2524 add_string_to_buf("Switch: Switch with who? ");
2525 current_switch = which;
2529 void drop_pc(short which)
2531 short choice,i;
2533 choice = fancy_choice_dialog(1053,0);
2534 if (choice == 1) {
2535 add_string_to_buf("Delete PC: Cancelled. ");
2536 return;
2538 add_string_to_buf("Delete PC: OK. ");
2539 kill_pc(which,0);
2540 for (i = which; i < 5; i++)
2541 adven[i] = adven[i + 1];
2542 adven[5].main_status = 0;
2543 set_stat_window(0);
2544 put_pc_screen();
2547 void handle_death()
2549 short choice;
2551 in_startup_mode = TRUE;
2553 while (in_startup_mode == TRUE) {
2554 // Use death (or leave Exile) dialog
2555 in_startup_mode = FALSE;
2556 choice = FCD(1069,0); //// FCD hates it when it gets called in startup mode
2557 // and startup graphiocs aren't loaded.
2558 in_startup_mode = TRUE;
2560 if (choice == 3) {
2561 in_startup_mode = FALSE;
2562 All_Done = TRUE;
2564 if (choice == 1) {
2565 in_startup_mode = FALSE;
2566 load_file();
2567 if (party_toast() == FALSE) {
2568 if (in_startup_mode == FALSE)
2569 post_load();
2570 else return;
2572 else in_startup_mode = TRUE;
2574 if (choice == 2) {
2575 start_new_game();
2581 void start_new_game()
2583 short which,i,r1; // 0 - make party 1 - sample party
2584 short num_pcs = 0,choice;
2585 Boolean creation_done = FALSE;
2586 location in_town_loc = {59,6};
2588 choice = FCD(1065,0);
2589 if (choice == 2)
2590 return;
2592 //which = choice - 1;
2594 // display_intro();
2595 init_party(0);
2597 //while (creation_done == FALSE) {
2598 edit_party(1,0);
2599 /* if ((i > 0) || (in_startup_mode == FALSE))
2600 creation_done = TRUE;
2601 if ((i == 0) && (in_startup_mode == FALSE))
2602 return;
2603 } */
2605 // if no PCs left, forget it
2606 for (i = 0 ; i < 6; i++)
2607 if (adven[i].main_status == 1)
2608 i = 100;
2609 if (i == 6)
2610 return;
2613 // everyone gets a weapon
2614 for (i = 0; i < 6; i++)
2615 if (adven[i].main_status == 1) {
2616 adven[i].items[0] = start_items[adven[i].race * 2];
2617 adven[i].equip[0] = TRUE;
2618 adven[i].items[1] = start_items[adven[i].race * 2 + 1];
2619 adven[i].equip[1] = TRUE;
2621 // PCs get adjustments
2622 for (i = 0; i < 6; i++)
2623 if (adven[i].main_status == 1) {
2624 // Do stat adjs for selected race.
2625 if (adven[i].race == 1) {
2626 if (adven[i].skills[1] < 18)
2627 adven[i].skills[1] += 2;
2629 if (adven[i].race == 2) {
2630 if (adven[i].skills[0] < 18)
2631 adven[i].skills[0] += 2;
2632 if (adven[i].skills[2] < 19)
2633 adven[i].skills[2] += 1;
2635 adven[i].max_sp += adven[i].skills[9] * 3 + adven[i].skills[10] * 3;
2636 adven[i].cur_sp = adven[i].max_sp;
2638 save_file(1);
2639 party_in_memory = TRUE;
2643 location get_cur_direction(POINT the_point)
2645 location store_dir = {0,0};
2647 // This is a kludgy adjustment to adjust for the screen shifting between Exile I & II
2648 the_point.y += 5;
2649 the_point.x += 5;
2651 if ((the_point.x < 135) & (the_point.y >= ((the_point.x * 34) / 10) - 293)
2652 & (the_point.y <= (-1 * ((the_point.x * 34) / 10) + 663)))
2653 store_dir.x--;
2654 if ((the_point.x > 163) & (the_point.y <= ((the_point.x * 34) / 10) - 350)
2655 & (the_point.y >= (-1 * ((the_point.x * 34) / 10) + 721)))
2656 store_dir.x++;
2658 if ((the_point.y < 167) & (the_point.y <= (the_point.x / 2) + 102)
2659 & (the_point.y <= (-1 * (the_point.x / 2) + 249)))
2660 store_dir.y--;
2661 if ((the_point.y > 203) & (the_point.y >= (the_point.x / 2) + 123)
2662 & (the_point.y >= (-1 * (the_point.x / 2) + 268)))
2663 store_dir.y++;
2665 return store_dir;
2668 Boolean outd_move_party(location destination,Boolean forced)
2670 char create_line[60];
2671 short i,boat_num,horse_num,spec_num;
2672 location real_dest, sector_p_in;
2673 Boolean keep_going = TRUE,check_f;
2674 location store_corner,store_iwc;
2675 unsigned char ter;
2677 keep_going = check_special_terrain(destination,0,0,&spec_num,&check_f);
2678 if (check_f == TRUE)
2679 forced = TRUE;
2680 if (debug_on == TRUE)
2681 forced = TRUE;
2682 if (spec_num == 50)
2683 forced = TRUE;
2685 // If not blocked and not put in town by a special, process move
2686 if ((keep_going == TRUE) && (overall_mode == 0)) {
2688 real_dest.x = destination.x - party.p_loc.x;
2689 real_dest.y = destination.y - party.p_loc.y;
2691 sector_p_in.x = party.outdoor_corner.x + party.i_w_c.x;
2692 sector_p_in.y = party.outdoor_corner.y + party.i_w_c.y;
2694 store_corner = party.outdoor_corner;
2695 store_iwc = party.i_w_c;
2697 // Check if party moves into new sector
2698 if ((destination.x < 6) && (party.outdoor_corner.x > 0))
2699 shift_universe_left();
2700 if ((destination.x > 90) && (party.outdoor_corner.x < scenario.out_width - 1))
2701 shift_universe_right();
2702 if ((destination.y < 6) && (party.outdoor_corner.y > 0)) {
2703 shift_universe_up();
2705 else if ((destination.y > 90) && (party.outdoor_corner.y < scenario.out_height - 1))
2706 shift_universe_down();
2707 // Now stop from going off the world's edge
2708 real_dest.x = party.p_loc.x + real_dest.x;
2709 real_dest.y = party.p_loc.y + real_dest.y;
2710 if ((real_dest.x < 4) && (party.outdoor_corner.x <= 0)) {
2711 ASB("You've reached the world's edge.");
2712 return FALSE;
2714 if (((real_dest.x > 92) && (party.outdoor_corner.x >= scenario.out_width - 2)) ||
2715 ((real_dest.x > 44) && (party.outdoor_corner.x >= scenario.out_width - 1))) {
2716 ASB("You've reached the world's edge.");
2717 return FALSE;
2719 if ((real_dest.y < 4) && (party.outdoor_corner.y <= 0)) {
2720 ASB("You've reached the world's edge.");
2721 return FALSE;
2723 else if (((real_dest.y > 92) && (party.outdoor_corner.y >= scenario.out_height - 2)) ||
2724 ((real_dest.y > 44) && (party.outdoor_corner.y >= scenario.out_height - 1))) {
2725 ASB("You've reached the world's edge.");
2726 return FALSE;
2729 // if ((store_corner.x != party.outdoor_corner.x) || (store_corner.y != party.outdoor_corner.y) ||
2730 // (store_iwc.x != party.i_w_c.x) || (store_iwc.y != party.i_w_c.y))
2731 // clear_map();
2735 //if (forced == TRUE)
2736 // for (i = 0; i < 10; i++)
2737 // if (same_point(destination,party.out_c[i].m_loc) == TRUE)
2738 // party.out_c[i].exists = FALSE;
2740 ter = out[real_dest.x][real_dest.y];
2741 if (party.in_boat >= 0) {
2742 if ((outd_is_blocked(real_dest) == FALSE) //&& (outd_is_special(real_dest) == FALSE)
2743 // not in towns
2744 && ((scenario.ter_types[ter].boat_over == FALSE)
2745 || ((real_dest.x != party.p_loc.x) && (real_dest.y != party.p_loc.y)))
2746 && (scenario.ter_types[ter].special != 21)) {
2747 add_string_to_buf("You leave the boat.");
2748 party.in_boat = -1;
2750 else if (((real_dest.x != party.p_loc.x) && (real_dest.y != party.p_loc.y))
2751 || ((forced == FALSE) && (out_boat_there(destination) < 30)))
2752 return FALSE;
2753 else if ((outd_is_blocked(real_dest) == FALSE)
2754 && (scenario.ter_types[ter].boat_over == TRUE)
2755 && (scenario.ter_types[ter].special != 21)) {
2756 if ((fancy_choice_dialog(1086,0)) == 1)
2757 forced = TRUE;
2758 else {
2759 add_string_to_buf("You leave the boat. ");
2760 party.in_boat = -1;
2763 else if (scenario.ter_types[ter].boat_over == TRUE)
2764 forced = TRUE;
2767 if (((boat_num = out_boat_there(real_dest)) < 30) && (party.in_boat < 0) && (party.in_horse < 0)) {
2768 if (flying() == TRUE) {
2769 add_string_to_buf("You land first. ");
2770 party.stuff_done[305][1] = 0;
2772 give_help(61,0,0);
2773 add_string_to_buf("Move: You board the boat. ");
2774 party.in_boat = boat_num;
2775 party.direction = set_direction(party.p_loc, destination);
2777 party.p_loc = real_dest;
2778 party.i_w_c.x = (party.p_loc.x > 48) ? 1 : 0;
2779 party.i_w_c.y = (party.p_loc.y > 48) ? 1 : 0;
2780 party.loc_in_sec = global_to_local(party.p_loc);
2782 if ((store_corner.x != party.outdoor_corner.x) || (store_corner.y != party.outdoor_corner.y) ||
2783 (store_iwc.x != party.i_w_c.x) || (store_iwc.y != party.i_w_c.y))
2784 clear_map();
2786 return TRUE;
2788 else if (((horse_num = out_horse_there(real_dest)) < 30) && (party.in_boat < 0) && (party.in_horse < 0)) {
2789 if (flying() == TRUE) {
2790 add_string_to_buf("Land before mounting horses.");
2791 return FALSE;
2793 if ((scenario.ter_types[ter].special >= 2) && (scenario.ter_types[ter].special <= 4)) {
2794 ASB("Your horses quite sensibly refuse.");
2795 return FALSE;
2798 give_help(60,0,0);
2799 add_string_to_buf("Move: You mount the horses. ");
2800 play_sound(84);
2801 party.in_horse = horse_num;
2802 party.direction = set_direction(party.p_loc, destination);
2804 party.p_loc = real_dest;
2805 party.i_w_c.x = (party.p_loc.x > 48) ? 1 : 0;
2806 party.i_w_c.y = (party.p_loc.y > 48) ? 1 : 0;
2807 party.loc_in_sec = global_to_local(party.p_loc);
2809 if ((store_corner.x != party.outdoor_corner.x) || (store_corner.y != party.outdoor_corner.y) ||
2810 (store_iwc.x != party.i_w_c.x) || (store_iwc.y != party.i_w_c.y))
2811 clear_map();
2813 return TRUE;
2815 else if ((outd_is_blocked(real_dest) == FALSE) || (forced == TRUE)
2816 // Check if can fly over
2817 || ((flying() == TRUE) &&
2818 (scenario.ter_types[ter].fly_over == TRUE)) ) {
2819 party.direction = set_direction(party.p_loc, destination);
2821 if ((flying() == TRUE) && (scenario.ter_types[ter].special == 21)) {
2822 add_string_to_buf("Moved: You have to land first. ");
2823 return FALSE;
2827 party.p_loc = real_dest;
2828 party.i_w_c.x = (party.p_loc.x > 47) ? 1 : 0;
2829 party.i_w_c.y = (party.p_loc.y > 47) ? 1 : 0;
2830 party.loc_in_sec = global_to_local(party.p_loc);
2831 //sprintf ((char *) create_line, "Moved: %s",dir_string[party.direction]);//, party.p_loc.x, party.p_loc.y, party.loc_in_sec.x, party.loc_in_sec.y);
2832 //add_string_to_buf((char *) create_line);
2833 move_sound(out[real_dest.x][real_dest.y],num_out_moves);
2834 num_out_moves++;
2836 if (party.in_boat >= 0) {
2837 // Waterfall!!!
2838 while (scenario.ter_types[out[party.p_loc.x][party.p_loc.y + 1]].special == 15) {
2839 add_string_to_buf(" Waterfall! ");
2840 party.p_loc.y += 2;
2841 party.loc_in_sec.y += 2;
2842 update_explored(party.p_loc);
2843 initiate_redraw();
2844 print_buf();
2845 if ((cave_lore_present() > 0) && (get_ran(1,0,1) == 0))
2846 add_string_to_buf(" (No supplies lost.)");
2847 else if (party.food > 1800)
2848 party.food -= 50;
2849 else party.food = (party.food * 19) / 20;
2850 put_pc_screen();
2851 play_sound(28);
2852 pause(8);
2854 party.boats[party.in_boat].which_town = 200;
2855 party.boats[party.in_boat].boat_loc_in_sec = party.loc_in_sec;
2856 party.boats[party.in_boat].boat_loc = party.p_loc;
2857 party.boats[party.in_boat].boat_sector.x = party.outdoor_corner.x + party.i_w_c.x;
2858 party.boats[party.in_boat].boat_sector.y = party.outdoor_corner.y + party.i_w_c.y;
2861 if (party.in_horse >= 0) {
2862 party.horses[party.in_horse].which_town = 200;
2863 party.horses[party.in_horse].horse_loc_in_sec = party.loc_in_sec;
2864 party.horses[party.in_horse].horse_loc = party.p_loc;
2865 party.horses[party.in_horse].horse_sector.x = party.outdoor_corner.x + party.i_w_c.x;
2866 party.horses[party.in_horse].horse_sector.y = party.outdoor_corner.y + party.i_w_c.y;
2870 if ((store_corner.x != party.outdoor_corner.x) || (store_corner.y != party.outdoor_corner.y) ||
2871 (store_iwc.x != party.i_w_c.x) || (store_iwc.y != party.i_w_c.y))
2872 clear_map();
2874 return TRUE;
2876 else {
2877 sprintf ((char *) create_line, "Blocked: %s",dir_string[set_direction(party.p_loc, destination)]);
2878 add_string_to_buf((char *) create_line);
2879 return FALSE;
2882 return FALSE;
2887 Boolean town_move_party(location destination,short forced)
2889 char create_line[60],keep_going = TRUE;
2890 short boat_there,horse_there,spec_num,i;
2891 unsigned char ter;
2892 Boolean check_f = FALSE;
2894 if (debug_on == TRUE)
2895 forced = TRUE;
2897 // remove if not registered
2899 if ((scenario.out_width != 3) || (scenario.out_height != 3) ||
2900 (scenario.num_towns != 21) || (scenario.town_size[3] != 1) || (scenario.town_size[9] != 0)) {
2901 ASB("Blades of Exile must be registered");
2902 ASB("before you can play scenarios besides");
2903 ASB("the unmodified Valley of Dying things.");
2904 print_buf();
2905 return FALSE;
2909 if (monst_there(destination) > T_M)
2910 keep_going = check_special_terrain(destination,1,0,&spec_num,&check_f);
2911 if (check_f == TRUE)
2912 forced = TRUE;
2914 if (spec_num == 50)
2915 forced = TRUE;
2916 ter = t_d.terrain[destination.x][destination.y];
2918 if (keep_going == TRUE) {
2919 if (party.in_boat >= 0) {
2920 if ((is_blocked(destination) == FALSE) && (is_special(destination) == FALSE)
2921 // If to bridge, exit if heading diagonal, keep going is head horiz or vert
2922 && ( (scenario.ter_types[ter].boat_over == FALSE)
2923 || ((destination.x != c_town.p_loc.x) && (destination.y != c_town.p_loc.y)))) {
2924 add_string_to_buf("You leave the boat. ");
2925 party.in_boat = -1;
2927 else if ((destination.x != c_town.p_loc.x) && (destination.y != c_town.p_loc.y))
2928 return FALSE;
2929 // Crossing bridge: land or go through
2930 else if ((is_blocked(destination) == FALSE) && (scenario.ter_types[ter].boat_over == TRUE)) {
2931 if ((fancy_choice_dialog(1086,0)) == 1)
2932 forced = TRUE;
2933 else if (is_blocked(destination) == FALSE) {
2934 add_string_to_buf("You leave the boat. ");
2935 party.in_boat = -1;
2938 // boat in destination
2939 else if (town_boat_there(destination) < 30) {
2940 add_string_to_buf(" Boat there already. ");
2941 return FALSE;
2943 // water or lava
2944 else if (scenario.ter_types[ter].boat_over == TRUE)
2945 forced = TRUE;
2948 if (((boat_there = town_boat_there(destination)) < 30) && (party.in_boat < 0)) {
2949 if (party.boats[boat_there].property == TRUE) {
2950 add_string_to_buf(" Not your boat. ");
2951 return FALSE;
2953 give_help(61,0,0);
2954 add_string_to_buf("Move: You board the boat. ");
2955 party.in_boat = boat_there;
2956 party.direction = set_direction(c_town.p_loc, destination);
2958 c_town.p_loc = destination;
2959 center = c_town.p_loc;
2961 return TRUE;
2963 else if (((horse_there = town_horse_there(destination)) < 30) && (party.in_horse < 0)) {
2964 if (party.horses[horse_there].property == TRUE) {
2965 add_string_to_buf(" Not your horses. ");
2966 return FALSE;
2968 give_help(60,0,0);
2969 add_string_to_buf("Move: You mount the horses. ");
2970 play_sound(84);
2971 party.in_horse = horse_there;
2972 party.direction = set_direction(c_town.p_loc, destination);
2974 c_town.p_loc = destination;
2975 center = c_town.p_loc;
2977 return TRUE;
2979 else if ((is_blocked(destination) == FALSE) || (forced == 1)) {
2980 if (party.in_horse >= 0) {
2981 if ((scenario.ter_types[ter].special >= 2) && (scenario.ter_types[ter].special <= 4)) {
2982 ASB("Your horses quite sensibly refuse.");
2983 return FALSE;
2985 if (scenario.ter_types[ter].block_horse == TRUE) {
2986 ASB("You can't take horses there!");
2987 return FALSE;
2989 if ((c_town.town.lighting > 0) && (get_ran(1,0,1) == 0)) {
2990 ASB("The darkness spooks your horses.");
2991 return FALSE;
2995 party.direction = set_direction(c_town.p_loc, destination);
2996 c_town.p_loc = destination;
2997 //sprintf ((char *) create_line, "Moved: %s",dir_string[party.direction]);
2998 //add_string_to_buf((char *) create_line);
2999 // place_treasure(destination,5,3);
3001 move_sound(t_d.terrain[destination.x][destination.y],(short) party.age);
3003 if (party.in_boat >= 0) {
3004 party.boats[party.in_boat].boat_loc = c_town.p_loc;
3005 party.boats[party.in_boat].which_town = c_town.town_num;
3007 if (party.in_horse >= 0) {
3008 party.horses[party.in_horse].horse_loc = c_town.p_loc;
3009 party.horses[party.in_horse].which_town = c_town.town_num;
3011 center = c_town.p_loc;
3012 return TRUE;
3014 else {
3015 if (is_door(destination) == TRUE)
3016 sprintf ((char *) create_line, "Door locked: %s ",dir_string[set_direction(c_town.p_loc, destination)]);
3017 else sprintf ((char *) create_line, "Blocked: %s ",dir_string[set_direction(c_town.p_loc, destination)]);
3018 add_string_to_buf((char *) create_line);
3019 return FALSE;
3022 return FALSE;
3027 Boolean someone_poisoned()
3029 short i;
3031 for (i = 0; i < 6; i++)
3032 if ((adven[i].main_status == 1) && (adven[i].status[2] > 0))
3033 return TRUE;
3034 return FALSE;
3037 short nearest_monster()
3039 short i = 100,j,s;
3040 char debug[60];
3042 for (j = 0; j < 10; j++)
3043 if (party.out_c[j].exists == TRUE) {
3044 s = dist(party.p_loc,party.out_c[j].m_loc);
3045 i = min(i,s);
3047 return i;
3050 void setup_outdoors(location where)
3052 update_explored(where);
3055 short get_outdoor_num()
3057 return (scenario.out_width * (party.outdoor_corner.y + party.i_w_c.y) + party.outdoor_corner.x + party.i_w_c.x);
3060 short count_walls(location loc)
3062 unsigned char walls[31] = {5,6,7,8,9, 10,11,12,13,14, 15,16,17,18,19, 20,21,22,23,24,
3063 25,26,27,28,29, 30,31,32,33,34, 35};
3064 short answer = 0;
3065 short k = 0;
3067 for (k = 0; k < 31 ; k++) {
3068 if (out[loc.x + 1][loc.y] == walls[k])
3069 answer++;
3070 if (out[loc.x - 1][loc.y] == walls[k])
3071 answer++;
3072 if (out[loc.x][loc.y + 1] == walls[k])
3073 answer++;
3074 if (out[loc.x][loc.y - 1] == walls[k])
3075 answer++;
3077 return answer;
3080 Boolean is_sign(unsigned char ter)
3082 unsigned char signs[6] = {110,127,142,213,214,252};
3083 short i;
3085 if (scenario.ter_types[ter].special == 11)
3086 return TRUE;
3087 return FALSE;