1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef NUVIE_MISC_U6_MISC_H
24 #define NUVIE_MISC_U6_MISC_H
25 
26 /*
27  *  ultima/nuvie/misc/u6_misc.h
28  *  Nuvie
29  *
30  *  Created by Eric Fry on Sat Jun 14 2003.
31  *  Copyright (c) 2003. All rights reserved.
32  *
33  */
34 #include "ultima/shared/std/string.h"
35 #include "ultima/nuvie/core/nuvie_defs.h"
36 #include "common/rect.h"
37 #include "graphics/managed_surface.h"
38 
39 namespace Ultima {
40 namespace Nuvie {
41 
42 class Configuration;
43 
44 typedef enum {
45 	BLOCKED,
46 	CAN_MOVE,
47 	FORCE_MOVE
48 } MovementStatus;
49 
50 Std::string config_get_game_key(Configuration *config);
51 const char *get_game_tag(int game_type);
52 void config_get_path(Configuration *config, Std::string filename, Std::string &path);
53 uint8 get_game_type(const char *string);
54 nuvie_game_t get_game_type(Configuration *config);
55 void build_path(Std::string path, Std::string filename, Std::string &full_path);
56 bool directory_exists(const char *directory);
57 bool file_exists(const char *path);
58 void print_b(DebugLevelType level, uint8 num);
59 void print_b16(DebugLevelType level, uint16 num);
60 void print_indent(DebugLevelType level, uint8 indent);
61 void print_bool(DebugLevelType level, bool state, const char *yes = "true", const char *no = "false");
62 void print_flags(DebugLevelType level, uint8 num, const char *f[8]);
63 bool subtract_rect(Common::Rect *rect1, Common::Rect *rect2, Common::Rect *sub_rect);
64 uint8 get_nuvie_dir_code(uint8 original_dir_code);
65 sint8 get_original_dir_code(uint8 nuvie_dir_code);
66 uint8 get_direction_code(sint16 rel_x, sint16 rel_y);
67 uint8 get_reverse_direction(uint8 dir);
68 void get_relative_dir(uint8 dir, sint16 *rel_x, sint16 *rel_y);
69 const char *get_direction_name(uint8 dir);
70 const char *get_direction_name(sint16 rel_x, sint16 rel_y);
71 int str_bsearch(const char *str[], int max, const char *value);
72 void stringToLower(Std::string &str);
73 /* Is point x,y within rect?
74  */
point_in_rect(uint16 x,uint16 y,Common::Rect * rect)75 inline bool point_in_rect(uint16 x, uint16 y, Common::Rect *rect) {
76 	return rect->contains(x, y);
77 }
78 
79 
80 /* Does line xy->x2y2 cross rect, to any extent?
81  */
line_in_rect(uint16 x1,uint16 y1,uint16 x2,uint16 y2,Common::Rect * rect)82 inline bool line_in_rect(uint16 x1, uint16 y1, uint16 x2, uint16 y2, Common::Rect *rect) {
83 	uint16 rx2 = rect->right, ry2 = rect->bottom;
84 	return (((y1 >= rect->top && y1 <= ry2 && x1 <= rx2 && x2 >= rect->left)
85 	         || (x1 >= rect->left && x1 <= rx2 && y1 <= ry2 && y2 >= rect->top)));
86 }
87 
88 
89 /* Measure a timeslice for a single function-call. (last_time must be static)
90  * Returns fraction of a second between this_time and last_time.
91  */
92 inline uint32 divide_time(uint32 this_time, uint32 &last_time, uint32 *passed_time = NULL) {
93 	uint32 ms_passed = (this_time - last_time) > 0 ? (this_time - last_time) : 1;
94 	uint32 fraction = 1000 / ms_passed; // % of second
95 	last_time = this_time;
96 	if (passed_time)
97 		*passed_time = ms_passed;
98 	return (fraction);
99 }
100 
101 int mkdir_recursive(Std::string path, int mode);
102 
103 void draw_line_8bit(int sx, int sy, int ex, int ey, uint8 col, uint8 *pixels, uint16 w, uint16 h);
104 
105 bool string_i_compare(const Std::string &s1, const Std::string &s2);
106 
107 void *nuvie_realloc(void *ptr, size_t size);
108 
109 uint32 sdl_getpixel(Graphics::ManagedSurface *surface, int x, int y);
110 
111 void scale_rect_8bit(unsigned char *Source, unsigned char *Target, int SrcWidth, int SrcHeight, int TgtWidth, int TgtHeight);
112 
113 bool has_file_extension(const char *filename, const char *extension);
114 
115 bool has_fmtowns_support(Configuration *config);
116 
117 uint16 wrap_signed_coord(sint16 coord, uint8 level);
118 sint8 get_wrapped_rel_dir(sint16 p1, sint16 p2, uint8 level);
119 
120 Std::string encode_xml_entity(const Std::string &s);
121 
122 } // End of namespace Nuvie
123 } // End of namespace Ultima
124 
125 #endif
126