fixed chicken messages
[snoogans.git] / misc.c
blob19a37f2c7820df9cba377ee86f2532e1d0a2c3b4
1 /*
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/>.
20 #include <stdarg.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
25 #include "d2pointers.h"
26 #include "misc.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
35 void
36 char_to_ms_wchar(char *str, ms_wchar_t *wstr)
38 int i;
39 for (i = 0; i < strlen(str); i++)
41 wstr[i] = (ms_wchar_t) (str[i] & 0xFF);
43 wstr[strlen(str)] = '\0';
46 void
47 ms_wchar_to_char(ms_wchar_t *wstr, char *str)
49 int i;
50 for (i = 0; wstr[i] != '\0'; i++)
52 str[i] = (char) (wstr[i] & 0xFF);
54 str[i] = '\0';
57 void
58 print_ingame(int color, const char *format, ...)
60 va_list args;
61 va_start(args, format);
62 char msg[1024];
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);
69 void
70 screen_to_automap(POINT *p, int x, int y)
72 p->x = ((x - y) / 2 / (*((int *) p_D2CLIENT_divisor))) - p_D2CLIENT_offset->x
73 + 8;
74 p->y = ((x + y) / 4 / (*((int *) p_D2CLIENT_divisor))) - p_D2CLIENT_offset->y
75 - 8;
76 if (D2CLIENT_get_automap_size())
78 --p->x;
79 p->y += 5;
83 void
84 draw_text(int x, int y, int color, int automap, int font, int center,
85 char *format, ...)
87 va_list args;
88 va_start(args, format);
89 char text[1024];
90 vsprintf(text, format, args);
91 ms_wchar_t wtext[strlen(text) + 1];
92 char_to_ms_wchar(text, wtext);
93 POINT p =
94 { x, y, };
95 if (automap)
97 if (!*p_D2CLIENT_automap_on)
99 return;
101 screen_to_automap(&p, x * 32, y * 32);
103 DWORD prev_font = D2WIN_set_text_size(font);
104 if (center >= 0)
106 int width;
107 DWORD file_no;
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);
115 void
116 draw_rectangle(int x, int y, int color, int automap)
118 POINT p =
119 { x, y };
120 if (automap)
122 if (!*p_D2CLIENT_automap_on)
124 return;
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);
134 void
135 draw_cross(int x, int y, int color, int automap)
137 POINT p =
138 { x, y };
139 if (automap)
141 if (!*p_D2CLIENT_automap_on)
143 return;
145 screen_to_automap(&p, x * 32, y * 32);
147 int lines[48];
148 int i = 0;
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)
161 int j;
162 for (j = 0; j < i; j += 4)
164 D2GFX_draw_line(lines[j], lines[j + 1], lines[j + 2], lines[j + 3],
165 color, -1);
169 void
170 draw_box(int x, int y, int width, int height, int color, int automap, int trans)
172 POINT p =
173 { x, y };
174 if (automap)
176 if (!*p_D2CLIENT_automap_on)
178 return;
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);
185 level *
186 get_level(act_misc *misc, DWORD level_no)
188 level *level;
189 for (level = misc->level_first; level != NULL; level = level->next)
191 if (level->level_no == level_no)
193 return level;
196 return D2COMMON_get_level(misc, level_no);
199 automap_layer *
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);
207 ingame()
209 unit_any *hero = D2CLIENT_get_player_unit();
210 if (hero)
211 if (hero->inventory)
212 if (hero->path)
213 if (hero->path->x)
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)
218 if (hero->act)
219 return 1;
220 return 0;
224 valid_monster(unit_any *unit)
226 if ((unit->mode == 0) || (unit->mode == 12))
228 return 0;
230 if (((unit->txtfile_no >= 110) && (unit->txtfile_no <= 113))
231 || ((unit->txtfile_no == 608) && (unit->mode == 8)))
233 return 0;
235 if ((unit->txtfile_no == 68) && (unit->mode == 14))
237 return 0;
239 if (((unit->txtfile_no == 258) || (unit->txtfile_no == 261)) && (unit->mode
240 == 14))
242 return 0;
244 if (D2COMMON_get_unit_stat(unit, 172, 0) == 2)
246 return 0;
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 };
251 int i;
252 for (i = 0; i < 28; i++)
254 if (unit->txtfile_no == false_positives[i])
256 return 0;
259 ms_wchar_t *wname = D2CLIENT_get_unit_name(unit);
260 if (wname)
262 char name[512];
263 ms_wchar_to_char(wname, name);
264 if ((strcmp(name, "an evil force") == 0) || (strcmp(name, "dummy") == 0))
266 return 0;
269 return 1;
273 intown()
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;
282 get_hp_percent()
284 return (int) ((float) (D2COMMON_get_unit_stat(*p_D2CLIENT_player_unit, 6, 0)
285 >> 8) * 100
286 / (D2COMMON_get_unit_stat(*p_D2CLIENT_player_unit, 7, 0) >> 8));