-
Notifications
You must be signed in to change notification settings - Fork 0
/
vendor.cpp
320 lines (285 loc) · 11 KB
/
vendor.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
#include <windows.h>
#include "resource.h"
#include "common.h"
#include "wizard.h"
static unsigned item_prices[4] = { 0, 1250, 1500, 2000 } ;
// static char dbg[128] ;
// ilI1| 0Oo
//****************************************************************************
static void vendor_show_value(HWND hDlg, int vid, unsigned value)
{
char stext[20] ;
HWND hwndTemp = GetDlgItem(hDlg, vid) ;
wsprintf(stext, " %u ", value) ;
SetWindowText(hwndTemp, stext) ;
}
//****************************************************************************
static void update_equip_avail(HWND hDlg)
{
unsigned j, idx, tval ;
// update armour/weapon entries based on available cash
for (j=IDC_VANONE, tval=IDC_VWNONE, idx=0; idx <= 3; j++, tval++, idx++) {
unsigned apoints = idx * 7 ;
HWND hwndArmour = GetDlgItem(hDlg, j) ;
HWND hwndWeapon = GetDlgItem(hDlg, tval) ;
// debug
if (item_prices[idx] <= (unsigned) player.gold) {
if (idx == 0 || apoints > player.armour_points)
EnableWindow(hwndArmour, TRUE) ;
else
EnableWindow(hwndArmour, FALSE) ;
if (idx == 0 || idx > (unsigned) player.weapon)
EnableWindow(hwndWeapon, TRUE) ;
else
EnableWindow(hwndWeapon, FALSE) ;
} else {
EnableWindow(hwndArmour, FALSE) ;
EnableWindow(hwndWeapon, FALSE) ;
}
// syslog("idx%u: apoints=%u\n", idx, apoints) ;
}
}
//****************************************************************************
static BOOL CALLBACK VendorDlgProc (
HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
HWND hwndChk ;
// HWND hwndArmour, hwndWeapon ;
int iTemp ;
static int str_changed ;
static int gem_stati[8] ;
static int weap_stati[4] ;
static int armor_stati[4] ;
static unsigned treasure_prices[8] ;
static unsigned stat_prices[3] ; // how many attr/1000GP
static unsigned stat_value[3] ; // temp stat value
static unsigned stat_edits[3] ; // how many times has attr been selected
unsigned j, idx, tval ;
static int iArmour, iWeapon ;
switch (message) {
case WM_INITDIALOG:
ZeroMemory((char *) &gem_stati[0], sizeof(gem_stati)) ;
ZeroMemory((char *) &weap_stati[0], sizeof(weap_stati)) ;
ZeroMemory((char *) &armor_stati[0], sizeof(armor_stati)) ;
ZeroMemory((char *) &stat_edits[0], sizeof(stat_edits)) ;
str_changed = 0 ;
// show current available gold
vendor_show_value(hDlg, IDC_VGOLD, player.gold) ;
// set up gem-sales display
for (j=IDC_GEM1, tval=IDC_TGEM1, idx=0; j<=IDC_GEM8; j++, tval++, idx++) {
hwndChk = GetDlgItem(hDlg, j) ;
if (player.treasures[idx] == 0) {
EnableWindow(hwndChk, FALSE) ;
treasure_prices[idx] = 0 ;
} else {
EnableWindow(hwndChk, TRUE) ;
treasure_prices[idx] = random(1500 * (idx+1)) ;
}
vendor_show_value(hDlg, tval, treasure_prices[idx]) ;
}
// debug
// wsprintf(dbg, "va=%u, hgt=%u, clhgt=%u, go_top=%u\n",
// VARMOR_TOP, CR_HEIGHT, CL_HEIGHT, GO_TOP) ;
// OutputDebugString(dbg) ;
// mark initial armour/weapon selections
iArmour = IDC_VANONE ;
CheckRadioButton (hDlg, IDC_VANONE, IDC_VAPLATE, iArmour) ;
iWeapon = IDC_VWNONE ;
CheckRadioButton (hDlg, IDC_VWNONE, IDC_VWSWORD, iWeapon) ;
// syslog("player gold=%u, armour=%u/%u, weapon=%u\n",
// player.gold, player.armour,
// player.armour_points,
// player.weapon) ;
update_equip_avail(hDlg) ;
stat_prices[0] = 1+random(6) ;
stat_value[0] = player.str ;
vendor_show_value(hDlg, IDC_VSTRCOST, stat_prices[0]) ;
vendor_show_value(hDlg, IDC_VSTRDATA, stat_value[0]) ;
stat_prices[1] = 1+random(6) ;
stat_value[1] = player.dex ;
vendor_show_value(hDlg, IDC_VDEXCOST, stat_prices[1]) ;
vendor_show_value(hDlg, IDC_VDEXDATA, stat_value[1]) ;
stat_prices[2] = 1+random(6) ;
stat_value[2] = player.iq ;
vendor_show_value(hDlg, IDC_VINTCOST, stat_prices[2]) ;
vendor_show_value(hDlg, IDC_VINTDATA, stat_value[2]) ;
// move focus to exit button
iTemp = IDVOK ;
SetFocus (GetDlgItem (hDlg, iTemp)) ;
break;
case WM_COMMAND:
switch (LOWORD (wParam)) {
case IDVOK:
if (iWeapon != IDC_VWNONE && player.gold >= item_prices[iWeapon - IDC_VWNONE]) {
player.weapon = iWeapon - IDC_VWNONE ;
player.gold -= item_prices[player.weapon] ;
}
if (iArmour != IDC_VANONE && player.gold >= item_prices[iArmour - IDC_VANONE]) {
player.armour = iArmour - IDC_VANONE ;
player.armour_points = 7 * player.armour ;
player.gold -= item_prices[player.armour] ;
}
if (stat_edits[0] > 0)
player.str = min(stat_value[0], 18) ;
if (str_changed)
adjust_hit_points() ;
if (stat_edits[1] > 0)
player.dex = min(stat_value[1], 18) ;
if (stat_edits[2] > 0)
player.iq = min(stat_value[2], 18) ;
// iCurrentColor = iRace ;
// iCurrentFigure = iFigure ;
EndDialog (hDlg, TRUE) ;
return TRUE ;
case IDC_SELLGEMS:
for (idx=0; idx<8; idx++) {
if (gem_stati[idx] != 0) {
j = idx + IDC_GEM1 ;
hwndChk = GetDlgItem(hDlg, j) ;
SendMessage(hwndChk, BM_SETCHECK, 0, 0) ;
player.gold += treasure_prices[idx] ;
player.treasures[idx] = 0 ;
player.treasure_count-- ;
}
}
SendMessage(hDlg, WM_INITDIALOG, 0, 0) ;
return TRUE ;
case IDC_GEM1:
case IDC_GEM2:
case IDC_GEM3:
case IDC_GEM4:
case IDC_GEM5:
case IDC_GEM6:
case IDC_GEM7:
case IDC_GEM8:
j = LOWORD (wParam) ;
idx = j - IDC_GEM1 ;
if (gem_stati[idx] == 0) {
SendMessage((HWND) lParam, BM_SETCHECK, 1, 0) ;
gem_stati[idx] = 1 ;
} else {
SendMessage((HWND) lParam, BM_SETCHECK, 0, 0) ;
gem_stati[idx] = 0 ;
}
return TRUE ;
case IDC_VANONE:
case IDC_VALEATH:
case IDC_VACHAIN:
case IDC_VAPLATE:
iArmour = LOWORD (wParam) ;
CheckRadioButton (hDlg, IDC_VANONE, IDC_VAPLATE, iArmour) ;
return TRUE ;
case IDC_VWNONE:
case IDC_VWDAGGER:
case IDC_VWMACE:
case IDC_VWSWORD:
iWeapon = LOWORD (wParam) ;
CheckRadioButton (hDlg, IDC_VWNONE, IDC_VWSWORD, iWeapon) ;
return TRUE ;
case IDC_VSTRMORE:
str_changed++ ;
if (stat_value[0] < 18 && player.gold >= 1000) {
stat_edits[0]++ ;
stat_value[0] += stat_prices[0] ;
// don't wrap stat here, do it at checkout time.
// This way undo is easier.
// if (stat_value[0] > 18)
// stat_value[0] = 18 ;
player.gold -= 1000 ;
vendor_show_value(hDlg, IDC_VSTRDATA, min(stat_value[0], 18)) ;
vendor_show_value(hDlg, IDC_VGOLD, player.gold) ;
update_equip_avail(hDlg) ;
}
return TRUE ;
case IDC_VSTRLESS:
if (str_changed > 0)
str_changed-- ;
if (stat_edits[0] > 0) {
stat_edits[0]-- ;
stat_value[0] -= stat_prices[0] ; // this doesn't undo wrap correctly
player.gold += 1000 ;
vendor_show_value(hDlg, IDC_VSTRDATA, min(stat_value[0], 18)) ;
vendor_show_value(hDlg, IDC_VGOLD, player.gold) ;
update_equip_avail(hDlg) ;
}
return TRUE ;
case IDC_VDEXMORE:
if (stat_value[1] < 18 && player.gold >= 1000) {
stat_edits[1]++ ;
stat_value[1] += stat_prices[1] ;
// don't wrap stat here, do it at checkout time.
// This way undo is easier.
// if (stat_value[0] > 18)
// stat_value[0] = 18 ;
player.gold -= 1000 ;
vendor_show_value(hDlg, IDC_VDEXDATA, min(stat_value[1], 18)) ;
vendor_show_value(hDlg, IDC_VGOLD, player.gold) ;
update_equip_avail(hDlg) ;
}
return TRUE ;
case IDC_VDEXLESS:
if (stat_edits[1] > 0) {
stat_edits[1]-- ;
stat_value[1] -= stat_prices[1] ; // this doesn't undo wrap correctly
player.gold += 1000 ;
vendor_show_value(hDlg, IDC_VDEXDATA, min(stat_value[1], 18)) ;
vendor_show_value(hDlg, IDC_VGOLD, player.gold) ;
update_equip_avail(hDlg) ;
}
return TRUE ;
case IDC_VINTMORE:
if (stat_value[2] < 18 && player.gold >= 1000) {
stat_edits[2]++ ;
stat_value[2] += stat_prices[2] ;
// don't wrap stat here, do it at checkout time.
// This way undo is easier.
// if (stat_value[0] > 18)
// stat_value[0] = 18 ;
player.gold -= 1000 ;
vendor_show_value(hDlg, IDC_VINTDATA, min(stat_value[2], 18)) ;
vendor_show_value(hDlg, IDC_VGOLD, player.gold) ;
update_equip_avail(hDlg) ;
}
return TRUE ;
case IDC_VINTLESS:
if (stat_edits[2] > 0) {
stat_edits[2]-- ;
stat_value[2] -= stat_prices[2] ; // this doesn't undo wrap correctly
player.gold += 1000 ;
vendor_show_value(hDlg, IDC_VINTDATA, min(stat_value[2], 18)) ;
vendor_show_value(hDlg, IDC_VGOLD, player.gold) ;
update_equip_avail(hDlg) ;
}
return TRUE ;
} //lint !e744 switch on target checkbox
break;
//********************************************************************
// application shutdown handlers
//********************************************************************
case WM_CLOSE:
DestroyWindow(hDlg);
return TRUE ;
case WM_DESTROY:
// if (main_timer_id != 0) {
// KillTimer(hwnd, main_timer_id) ;
// main_timer_id = 0 ;
// }
// release_led_images() ;
set_default_keymap();
update_status();
// PostQuitMessage(0);
return TRUE ;
default:
break;
} //lint !e744
return FALSE ;
}
//****************************************************************************
int trade_with_vendor(HWND hwnd)
{
int result = DialogBox (g_hinst, MAKEINTRESOURCE(IDD_VENDORBOX), hwnd, VendorDlgProc);
if (result < 0) {
syslog("Vendor: DialogBox: %s\n", get_system_message()) ;
}
return result;
}