2 * Copyright (C) 2010 gonzoj
4 * Please check the CREDITS file for further information.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include "d2pointers.h"
28 #define LINE(offsets, x1, y1, x2, y2, i) offsets[i++] = x1; offsets[i++] = y1; offsets[i++] = x2; offsets[i++] = y2;
31 * we have to manually transform our strings because *nix
32 * wchar_t is 4 bytes while windows uses 2 bytes only
36 char_to_ms_wchar(char *str
, ms_wchar_t
*wstr
)
39 for (i
= 0; i
< strlen(str
); i
++)
41 wstr
[i
] = (ms_wchar_t
) (str
[i
] & 0xFF);
43 wstr
[strlen(str
)] = '\0';
47 ms_wchar_to_char(ms_wchar_t
*wstr
, char *str
)
50 for (i
= 0; wstr
[i
] != '\0'; i
++)
52 str
[i
] = (char) (wstr
[i
] & 0xFF);
58 print_ingame(int color
, const char *format
, ...)
61 va_start(args
, format
);
63 vsprintf(msg
, format
, args
);
64 ms_wchar_t wmsg
[strlen(msg
) + 1];
65 char_to_ms_wchar(msg
, wmsg
);
66 D2CLIENT_print_game_string(wmsg
, color
);
70 screen_to_automap(POINT
*p
, int x
, int y
)
72 p
->x
= ((x
- y
) / 2 / (*((int *) p_D2CLIENT_divisor
))) - p_D2CLIENT_offset
->x
74 p
->y
= ((x
+ y
) / 4 / (*((int *) p_D2CLIENT_divisor
))) - p_D2CLIENT_offset
->y
76 if (D2CLIENT_get_automap_size())
84 draw_text(int x
, int y
, int color
, int automap
, int font
, int center
,
88 va_start(args
, format
);
90 vsprintf(text
, format
, args
);
91 ms_wchar_t wtext
[strlen(text
) + 1];
92 char_to_ms_wchar(text
, wtext
);
97 if (!*p_D2CLIENT_automap_on
)
101 screen_to_automap(&p
, x
* 32, y
* 32);
103 DWORD prev_font
= D2WIN_set_text_size(font
);
108 D2WIN_get_text_width_file_no(wtext
, &width
, &file_no
);
109 p
.x
-= (width
>> center
);
111 D2WIN_draw_text(wtext
, p
.x
, p
.y
, color
, -1);
112 D2WIN_set_text_size(prev_font
);
116 draw_rectangle(int x
, int y
, int color
, int automap
)
122 if (!*p_D2CLIENT_automap_on
)
126 screen_to_automap(&p
, x
* 32, y
* 32);
128 D2GFX_draw_line(p
.x
- 3, p
.y
+ 3, p
.x
+ 3, p
.y
+ 3, color
, -1);
129 D2GFX_draw_line(p
.x
- 3, p
.y
+ 3, p
.x
- 3, p
.y
- 3, color
, -1);
130 D2GFX_draw_line(p
.x
- 3, p
.y
- 3, p
.x
+ 3, p
.y
- 3, color
, -1);
131 D2GFX_draw_line(p
.x
+ 3, p
.y
- 3, p
.x
+ 3, p
.y
+ 3, color
, -1);
135 draw_cross(int x
, int y
, int color
, int automap
)
141 if (!*p_D2CLIENT_automap_on
)
145 screen_to_automap(&p
, x
* 32, y
* 32);
149 LINE(lines
, p
.x
, p
.y
- 2, p
.x
+ 4, p
.y
- 4, i
)
150 LINE(lines
, p
.x
+ 4, p
.y
- 4, p
.x
+ 8, p
.y
- 2, i
)
151 LINE(lines
, p
.x
+ 8, p
.y
- 2, p
.x
+ 4, p
.y
, i
)
152 LINE(lines
, p
.x
+ 4, p
.y
, p
.x
+ 8, p
.y
+ 2, i
)
153 LINE(lines
, p
.x
+ 8, p
.y
+ 2, p
.x
+ 4, p
.y
+ 4, i
)
154 LINE(lines
, p
.x
+ 4, p
.y
+ 4, p
.x
, p
.y
+ 2, i
)
155 LINE(lines
, p
.x
, p
.y
+ 2, p
.x
- 4, p
.y
+ 4, i
)
156 LINE(lines
, p
.x
- 4, p
.y
+ 4, p
.x
- 8, p
.y
+ 2, i
)
157 LINE(lines
, p
.x
- 8, p
.y
+ 2, p
.x
- 4, p
.y
, i
)
158 LINE(lines
, p
.x
- 4, p
.y
, p
.x
- 8, p
.y
- 2, i
)
159 LINE(lines
, p
.x
- 8, p
.y
- 2, p
.x
- 4, p
.y
- 4, i
)
160 LINE(lines
, p
.x
- 4, p
.y
- 4, p
.x
, p
.y
- 2, i
)
162 for (j
= 0; j
< i
; j
+= 4)
164 D2GFX_draw_line(lines
[j
], lines
[j
+ 1], lines
[j
+ 2], lines
[j
+ 3],
170 draw_box(int x
, int y
, int width
, int height
, int color
, int automap
, int trans
)
176 if (!*p_D2CLIENT_automap_on
)
180 screen_to_automap(&p
, x
* 32, y
* 32);
182 D2GFX_draw_rectangle(p
.x
, p
.y
, p
.x
+ width
, p
.y
+ height
, color
, trans
);
186 get_level(act_misc
*misc
, DWORD level_no
)
189 for (level
= misc
->level_first
; level
!= NULL
; level
= level
->next
)
191 if (level
->level_no
== level_no
)
196 return D2COMMON_get_level(misc
, level_no
);
200 init_automap_layer(DWORD level_no
)
202 automap_layer2
*layer
= D2COMMON_get_layer(level_no
);
203 return D2CLIENT_init_automap_layer(layer
->layer_no
);
209 unit_any
*hero
= D2CLIENT_get_player_unit();
214 if (hero
->path
->room1
)
215 if (hero
->path
->room1
->room2
)
216 if (hero
->path
->room1
->room2
->level
)
217 if (hero
->path
->room1
->room2
->level
->level_no
)
224 valid_monster(unit_any
*unit
)
226 if ((unit
->mode
== 0) || (unit
->mode
== 12))
230 if (((unit
->txtfile_no
>= 110) && (unit
->txtfile_no
<= 113))
231 || ((unit
->txtfile_no
== 608) && (unit
->mode
== 8)))
235 if ((unit
->txtfile_no
== 68) && (unit
->mode
== 14))
239 if (((unit
->txtfile_no
== 258) || (unit
->txtfile_no
== 261)) && (unit
->mode
244 if (D2COMMON_get_unit_stat(unit
, 172, 0) == 2)
248 DWORD false_positives
[] =
249 { 326, 327, 328, 329, 330, 410, 411, 412, 413, 414, 415, 416, 366, 406,
250 351, 352, 353, 266, 408, 516, 517, 518, 519, 522, 523, 543, 543, 545 };
252 for (i
= 0; i
< 28; i
++)
254 if (unit
->txtfile_no
== false_positives
[i
])
259 ms_wchar_t
*wname
= D2CLIENT_get_unit_name(unit
);
263 ms_wchar_to_char(wname
, name
);
264 if ((strcmp(name
, "an evil force") == 0) || (strcmp(name
, "dummy") == 0))
275 unit_any
*hero
= D2CLIENT_get_player_unit();
276 int level_no
= hero
->path
->room1
->room2
->level
->level_no
;
277 return (level_no
== 1 || level_no
== 40 || level_no
== 75 || level_no
== 103
278 || level_no
== 109) ? 1 : 0;
284 return (int) ((float) (D2COMMON_get_unit_stat(*p_D2CLIENT_player_unit
, 6, 0)
286 / (D2COMMON_get_unit_stat(*p_D2CLIENT_player_unit
, 7, 0) >> 8));