summaryrefslogtreecommitdiff
path: root/csrc/drawing.c
blob: e20447e8f372a5614bd7bc924ff75c4378c48c29 (plain)
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
#include <windows.h>
#include "player_info.h"
#include "data_struct.h"

struct st st_46caec;

int fcn_455c52(uint32_t a0, uint32_t a1, uint16_t *a2, struct st * a3, int a4, int a5, int a6)
{
	a4 -= (int16_t)a3->f4;
	a5 -= (int16_t)a3->f6;
	if (a6 != 1) {
		if (a4 >= a0 ||
				a4 + (uint16_t)a3->f0 <= 0 ||
				a5 >= a1 ||
				a5 + (uint16_t)a3->f2 <= 0)
			return 1;

		[ebp-4] = 0;
		[ebp-8] = 0;
		[ebp-12] = (uint16_t)a3->f0;
		[ebp-16] = (uint16_t)a3->f2;

		if (a4 < 0) {
			[ebp-4] -= a4;
			[ebp-12] += a4;
			a4 = 0;
		} else {
			eax = [ebp-12] + a4 - a0;
			if (eax > 0) {
				[ebp-12] -= eax;
			}
		}

		if (a5 < 0) {
			[ebp-8] -= a5;
			[ebp-16] += a5;
			a5 = 0;
		} else {
			eax = [ebp-16] + a5 - a1;
			if (eax > 0) {
				[ebp-16] -= eax;
			}
		}
	} else {
		if (a4 >= dw_4861c0
				|| a4 + (uint16_t)a3->f0 <= dw_4861b8
				|| a5 >= dw_4861c4
				|| a5 + (uint16_t)a3->f2 <= dw_4861bc)
			return 1;

		[ebp - 4] = 0;
		[ebp - 8] = 0;
		[ebp - 12] = (uint16_t)a3->f0;
		[ebp - 16] = (uint16_t)a3->f2;

		if (a4 < dw_4861b8) {
			eax = dw_4861b8 - a4;
			a4 = dw_4861b8;
			[ebp - 4] += eax;
			[ebp - 12] -= eax;
		} else {
			eax = [ebp - 12] + a4 - dw_4861c0;
			if (eax > 0) {
				[ebp - 12] -= eax;
			}
		}

		if (a5 < dw_4861bc) {
			eax = dw_4861bc - a5;
			a5 = dw_4861bc;
			[ebp - 8] += eax;
			[ebp - 16] -= eax;
		} else {
			eax = [ebp  - 16] + a5 - dw_4861c4;
			if (eax > 0) {
				[ebp - 16] -= eax;
			}
		}

	}

	eax = (uint16_t)a3->f0 * [ebp-8] + [ebp-4];
	esi = &a3->f8[eax];
	[ebp - 4] = ((uint16_t)a3->f0 - [ebp - 12]) * 2;
	[ebp - 8] = (a0 - [ebp-12]) * 2;
	edi = (a5 * a0 + a4) * 2 + a2;

	edx = [ebp - 12];
	ebx = [ebp - 16];
	do {
		ecx = edx;
		do {
			ax = [esi];
			(uint16_t*)esi ++;
			if (ax != 0) {
				*edi = ax;
			}
			(uint16_t*)edi ++;
		} while (--ecx);

		esi += [ebp - 4];
		edi += [ebp - 8];
	} while (--ebx);

	return 0;
}

void fcn_4562a5(struct st * a0, struct st * a1, int a2, int a3)
{
	fcn_455c52((uint16_t)a0->f0, (uint16_t)a0->f2, a0->f8, a1, a2, a3, 0);
}

void fcn_417191(int a0)
{
	RECT r0;
	r0.left = dw_48bdec;
	r0.top = dw_48bde8;
	r0.right = r0.left + dw_48bdd8;
	r0.bottom = r0.top + dw_48bddc;

	GetCursorPos_35d(&r0); /* fcn_4021f8.c */

	if (dw_48bdec != dw_475284 || dw_48bde8 != dw_475288) {
		dw_48bdec = dw_475284;
		dw_48bde8 = dw_475288;
		IDirectDrawSurface_BltFast(pddrawsf1, r0.left, r0.top, pddrawsf2, &r0, 0x10);
	}

	if (a0 == 0) {
		if (b_46cafd != 0)
			return;

		GetCursorPos_250(&r0);
		return;
	}

	ebx = 0;
	if (players[current_player].days_stopping != 0)
		ebx = 2;
	if (players[current_player].days_tortoise_walking != 0)
		ebx = 4;

	IDirectDrawSurface_Lock(pddrawsf1, 0, &sfdesc1, 1, 0);
	st_46caec.f0 = sfdesc1.DUMMYUNIONNAME1.lPitch / 2;
	dw_46caf4 = sfdesc1.lpSurface;

	edx = dw_48bdd4 + ebx;
	edx = edx * 12 + dw_48be04 + 12;

	fcn_4562a5(&st_46caec, edx, dw_475284, dw_475288);

	eax = players[current_player].traffic_method & 3;
	switch (eax) {
		case 0:
			eax = dw_475288 + 0x1a;
			if (players[current_player].days_stopping == 0) {
				fcn_4562a5(&st_46caec, dw_48be04+0x60, dw_475284+7, eax);
			} else {
				fcn_4562a5(&st_46caec, dw_48be04+0x54, dw_475284+8, eax);
			}
			break;
		case 1:
			for (ebx = 0; ebx < 2; ebx++) {
				edx = players[current_player].ndices - 1;
				if (ebx <= edx && players[current_player].days_stopping == 0) {
					eax_1 = ebx * 19 + dw_475288 + 0x10;
					edx = (ebx * 2 + 7) * 12;
					eax_2 = dw_48be04 + 0xc + edx;
					fcn_4562a5(&st_46caec, eax_2, dw_475284 + 7, eax_1);
				} else {
					eax_1 = ebx*19 + dw_475288 + 0x10;
					eax_2 = (ebx * 2 + 6) * 12 + dw_48be04 + 0xc;
					fcn_4562a5(&st_46caec, eax_2, dw_475284 + 8, eax_1);
				}
			}
			break;
		case 2:
			for (ebx = 0; ebx < 3; ebx++) {
				edx = players[current_player].ndices - 1;
				if (ebx <= edx && players[current_player].days_stopping == 0) {
					a4 = ebx * 16 + dw_475288 + 9;
					a3 = dw_475284 + 7;
					a2 = (ebx * 2 + 7) * 12 + dw_48be04 + 0xc;
					fcn_4562a5(&st_46caec, a2, a3, a4);
				} else {
					a4 = ebx * 16 + dw_475288 + 9;
					a3 = dw_475284 + 8;
					a2 = (ebx * 2 + 6) * 12 + dw_48be04 + 0xc;
					fcn_4562a5(&st_46caec, a2, a3, a4);
				}
			}
			break;
		default:
			break;
	}
	IDirectDrawSurface_Unlock(pddrawsf1, NULL);
	GetCursorPos_250(&r0);
	st_46caec.f0 = 640;
}

void IntersectRect_4cd(RECT *r0)
{
	RECT result_rect;
	RECT o_rect;
	if (b_46cafd == 0)
		return;

	o_rect.left = dw_475284;
	o_rect.top = dw_475288;
	o_rect.right = o_rect.left + dw_48bdd8;
	o_rect.bottom = o_rect.top + dw_48bddc;

	int ret = IntersectRect(&result_rect, &o_rect, r0);
	if (ret == 0) // do not intersect
		return;

	fcn_417191(1);
}