• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Feb 22nd, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1.
2. #ifndef __INC_METIN_II_UTILS_H__
3. #define __INC_METIN_II_UTILS_H__
4.
5. #include <math.h>
6.
7. #define IS_SET(flag, bit)       ((flag) & (bit))
8. #define SET_BIT(var, bit)       ((var) |= (bit))
9. #define REMOVE_BIT(var, bit)    ((var) &= ~(bit))
10. #define TOGGLE_BIT(var, bit)    ((var) = (var) ^ (bit))
11.
12. inline float DISTANCE_SQRT(long dx, long dy)
13. {
14.     return ::sqrt((float)dx * dx + (float)dy * dy);
15. }
16.
17. inline int DISTANCE_APPROX(int dx, int dy)
18. {
19.     int min, max;
20.
21.     if (dx < 0)
22.         dx = -dx;
23.
24.     if (dy < 0)
25.         dy = -dy;
26.
27.     if (dx < dy)
28.     {
29.         min = dx;
30.         max = dy;
31.     }
32.     else
33.     {
34.         min = dy;
35.         max = dx;
36.     }
37.
38.     // coefficients equivalent to ( 123/128 * max ) and ( 51/128 * min )
39.     return ((( max << 8 ) + ( max << 3 ) - ( max << 4 ) - ( max << 1 ) +
40.         ( min << 7 ) - ( min << 5 ) + ( min << 3 ) - ( min << 1 )) >> 8 );
41. }
42.
43. #ifndef __WIN32__
44. inline WORD MAKEWORD(BYTE a, BYTE b)
45. {
46.     return static_cast<WORD>(a) | (static_cast<WORD>(b) << 8);
47. }
48. #endif
49.
50. extern void set_global_time(time_t t);
51. extern time_t get_global_time();
52.
53. extern int  dice(int number, int size);
54. extern size_t str_lower(const char * src, char * dest, size_t dest_size);
55.
56. extern void skip_spaces(char **string);
57.
58. extern const char * one_argument(const char *argument, char *first_arg, size_t first_size);
59. extern const char * two_arguments(const char *argument, char *first_arg, size_t first_size, char *second_arg, size_t second_size);
60. extern const char * three_arguments(const char * argument, char * first_arg, size_t first_size, char * second_arg, size_t second_size, char * third_flag, size_t third_size);
61. extern const char * first_cmd(const char *argument, char *first_arg, size_t first_arg_size, size_t *first_arg_len_result);
62. extern void split_argument(const char *argument, std::vector<std::string> & vecArgs);
63.
64. extern int CalculateDuration(int iSpd, int iDur);
65.
66. extern float gauss_random(float avg = 0, float sigma = 1);
67.
68. extern int parse_time_str(const char* str);
69.
70. extern bool WildCaseCmp(const char *w, const char *s);
71.
72. #endif /* __INC_METIN_II_UTILS_H__ */
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top