added worldarea -> will be responsible for world map rendering
[dboe.git] / townspec.c
blob0c994970e1f0b87378d8bd77a31eea262796be45
2 //#include <Windows.h>
4 #include "global.h"
5 #include "party.h"
6 #include "town.h"
7 #include "items.h"
8 #include "combat.h"
9 #include "monster.h"
10 #include "infodlgs.h"
11 #include "locutils.h"
12 #include "fields.h"
13 #include "text.h"
14 #include "itemdata.h"
15 #include "townspec.h"
16 #include "exlsound.h"
17 //#include "small.h"
18 //#include "medium.h"
19 //#include "large.h"
21 extern short overall_mode;
22 extern party_record_type party;
23 extern piles_of_stuff_dumping_type *data_store;
24 extern piles_of_stuff_dumping_type2 *data_store2;
25 extern talking_record_type talking;
26 extern scenario_data_type scenario;
28 extern current_town_type c_town;
29 extern unsigned char out[96][96];
30 extern unsigned char out_e[96][96];
31 extern unsigned char combat_terrain[64][64];
32 extern short current_pc,stat_window;
33 extern outdoor_record_type outdoors[2][2];
34 extern location pc_pos[6],center;
35 extern town_item_list t_i;
36 extern pc_record_type adven[6];
37 extern big_tr_type t_d;
38 extern Boolean registered;
39 extern HWND mainPtr;
41 item_record_type null_thing = {0,0, 0,0,0,0,0,0, 0,0,0,0,0,0, 0, 0,0, {0,0},"", "",0,0,0,0};
42 char answer[256];
46 void activate_monster_enc(short enc_num,short str1,short str2,short strsnd,short *flip_bit)
48 if (*flip_bit == 0) {
49 display_enc_string(str1,str2,strsnd);
50 activate_monsters(enc_num,1);
51 *flip_bit = 20;
56 // OTS = One Time Strings
57 void OTS(short str1b,short str2b,short str12a,short sound,unsigned char *flip_bit)
59 if (*flip_bit > 0)
60 return;
61 else *flip_bit = 20;
62 if (str2b == 0)
63 D2ES(str12a,str1b,0,0,sound);
64 else D2ES(str12a,str1b,str12a,str2b,sound);
67 // GFI go for it ... do simple dialog check
68 Boolean GFI(short dialog_num)
70 if (FCD(dialog_num,0) > 1)
71 return true;
72 else return false;
75 //DSG = Do Special Give
76 void DSG(short item_num,unsigned char *flip_bit,short dialog_num,short what_spec,short amt_gold,short amt_food)
77 //short special; // 0 - nah 3** - Set spec item 1000 + * give food 2000 + * give cash
79 short choice;
80 Boolean did_give;
81 item_record_type item;
83 item = get_stored_item(item_num);
84 if (item_num == 0)
85 item.variety = 0;
86 if (*flip_bit == 0) {
87 choice = fancy_choice_dialog(dialog_num,0);
88 if (choice == 1)
89 return;
91 if (item.variety == 0)
92 did_give = true;
93 else did_give = give_to_party(item,0);
94 if (did_give == true) {
95 party.food += amt_food;
96 party.gold += amt_gold;
97 if (what_spec >= 0) {
98 if (party.spec_items[what_spec] > 0) {
99 ASB("You already have this special item.");
100 return;
102 party.spec_items[what_spec] += 1;
103 put_item_screen(stat_window,0);
105 *flip_bit = 20;
106 put_pc_screen();
108 else choice = fancy_choice_dialog(1049,0);
113 Boolean run_trap(short pc_num,short trap_type,short trap_level,short diff)
114 //short pc_num; // 6 - BOOM! 7 - pick here
115 //short trap_type; // 0 - random 1 - blade 2 - dart 3 - gas 4 - boom 5,6 - no
116 // 7 - level drain 8 - alert 9 - big flames 10 - dumbfound 11 - town hostile
117 // 20 + * - trap *, but nasty
119 short r1,skill,i,num_hits = 1,i_level;
120 short trap_odds[30] = {5,30,35,42,48, 55,63,69,75,77,
121 78,80,82,84,86, 88,90,92,94,96,98,99,99,99,99,99,99,99,99,99};
123 if (pc_num > 7) { // Debug
124 SysBeep(50);
125 ASB("TRAP ERROR! REPORT!");
126 return true;
129 if (pc_num == 7) {
130 pc_num = select_pc(1,0);
131 if (pc_num == 6)
132 return false;
136 num_hits += trap_level;
138 if (trap_type == 0)
139 trap_type = get_ran(1,1,4);
140 if ((trap_type == 5) || (trap_type == 6))
141 return true;
143 if (pc_num < 6) {
144 i = stat_adj(pc_num,1);
145 if ((i_level = get_prot_level(pc_num,42)) > 0)
146 i = i + i_level / 2;
147 skill = minmax(0,20,adven[pc_num].skills[14] +
148 + adven[pc_num].skills[18] / 2 + 1 - c_town.difficulty + 2 * i);
150 r1 = get_ran(1,0,100) + diff;
151 // Nimble?
152 if (adven[pc_num].traits[3] == false)
153 r1 -= 6;
156 if (r1 < trap_odds[skill]) {
157 add_string_to_buf(" Trap disarmed. ");
158 return true;
160 else add_string_to_buf(" Disarm failed. ");
163 switch (trap_type) {
164 case 1:
165 for (i = 0; i < num_hits; i++) {
166 add_string_to_buf(" A knife flies out! ");
167 r1 = get_ran(2 + c_town.difficulty / 14,1,10);
168 damage_pc(pc_num,r1,0,-1);
170 break;
172 case 2:
173 add_string_to_buf(" A dart flies out. ");
174 r1 = 3 + c_town.difficulty / 14;
175 r1 = r1 + trap_level * 2;
176 poison_pc(pc_num,r1);
177 break;
179 case 3:
180 add_string_to_buf(" Poison gas pours out. ");
181 r1 = 2 + c_town.difficulty / 14;
182 r1 = r1 + trap_level * 2;
183 for(i = 0; i < 6; i++)
184 poison_pc(i,r1);
185 break;
187 case 4:
188 for (i = 0; i < num_hits; i++) {
189 add_string_to_buf(" There is an explosion. ");
190 r1 = get_ran(3 + c_town.difficulty / 13,1,8);
191 hit_party(r1,1);
193 break;
195 case 5:
196 add_string_to_buf(" A purple ray flies out. ");
197 r1 = 200 + c_town.difficulty * 100;
198 r1 = r1 + trap_level * 400;
199 sleep_pc(pc_num,r1,12,50);
200 break;
201 case 7:
202 add_string_to_buf(" You feel weak. ");
203 r1 = 40;
204 r1 = r1 + trap_level * 30;
205 adven[pc_num].experience = max (0,adven[pc_num].experience - r1);
206 break;
208 case 8:
209 add_string_to_buf(" An alarm goes off!!! ");
210 make_town_hostile();
211 break;
213 case 9:
214 add_string_to_buf(" Flames shoot from the walls. ");
215 r1 = get_ran(10 + trap_level * 5,1,8);
216 hit_party(r1,1);
217 break;
218 case 10:
219 add_string_to_buf(" You feel disoriented. ");
220 for(i = 0; i < 6; i++)
221 dumbfound_pc(i,2 + trap_level * 2);
222 break;
224 case 11:
225 add_string_to_buf(" You prick your finger. ");
226 r1 = 3 + c_town.difficulty / 14;
227 r1 = r1 + trap_level * 2;
228 disease_pc(pc_num,r1);
229 break;
231 case 12:
232 add_string_to_buf(" A foul substance sprays out.");
233 r1 = 2 + c_town.difficulty / 14;
234 r1 = r1 + trap_level * 2;
235 for(i = 0; i < 6; i++)
236 disease_pc(i,r1);
237 break;
239 put_pc_screen();
240 put_item_screen(stat_window,0);
241 return true;
244 location get_spec_loc(short which)
246 location where = {0,0};
247 short i;
249 for (i = 0; i < 50; i++)
250 if (c_town.town.spec_id[i] == which)
251 return c_town.town.special_locs[i];
252 return where;
256 void start_split(short a,short b,short noise)
258 short i;
260 party.stuff_done[304][0] = 1;
261 party.stuff_done[304][1] = c_town.p_loc.x;
262 party.stuff_done[304][2] = c_town.p_loc.y;
263 c_town.p_loc.x = a;
264 c_town.p_loc.y = b;
265 for (i = 0; i < 6; i++)
266 if (i != party.stuff_done[304][3])
267 adven[i].main_status += 10;
268 current_pc = party.stuff_done[304][3];
269 update_explored(c_town.p_loc);
270 center = c_town.p_loc;
271 if (noise > 0)
272 play_sound(10);
275 void end_split(short noise)
277 short i;
279 if (party.stuff_done[304][0] == 0) {
280 ASB("Party already together!");
281 return;
283 c_town.p_loc.x = party.stuff_done[304][1];
284 c_town.p_loc.y = party.stuff_done[304][2];
285 party.stuff_done[304][0] = 0;
286 for (i = 0; i < 6; i++)
287 if (adven[i].main_status >= 10)
288 adven[i].main_status -= 10;
289 update_explored(c_town.p_loc);
290 center = c_town.p_loc;
291 if (noise > 0)
292 play_sound(10);
293 add_string_to_buf("You are reunited.");
296 // 0 if no pull.
297 // 1 if in right position now.
298 // 2 if in left position
299 // levers should always start to left.
300 short handle_lever(location w)
302 if (FCD(1020,0) == 1)
303 return 0;
304 play_sound(94);
305 switch_lever(w);
306 return 1;
309 void switch_lever(location w)
311 alter_space(w.x,w.y,scenario.ter_types[t_d.terrain[w.x][w.y]].trans_to_what);