OMISC.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * Seven Kingdoms: Ancient Adversaries
  3. *
  4. * Copyright 1997,1998 Enlight Software Ltd.
  5. *
  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 2 of the License, or
  9. * (at your option) any later version.
  10. *
  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.
  15. *
  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/>.
  18. *
  19. */
  20. //Filename : MISC.H
  21. //Description : Header file for MISC function object
  22. #ifndef __MISC_H
  23. #define __MISC_H
  24. //-------- Define macro constant ---------//
  25. #define LINE_FEED 0xA // Line feed ascii code
  26. #define RETURN 0xD
  27. //-----------------------------------------//
  28. class Misc
  29. {
  30. public:
  31. enum { STR_BUF_LEN = 120 };
  32. char str_buf[STR_BUF_LEN+1];
  33. char freeze_seed;
  34. long random_seed;
  35. public:
  36. Misc();
  37. int str_cut(char*,char*,int,int=-1);
  38. int str_chr(char*,char,int=1,int=-1);
  39. int str_str(char*,char*,int=1,int=-1);
  40. int str_cmp(char*,char*);
  41. int str_cmpx(char*,char*);
  42. int str_icmpx(char*,char*);
  43. void str_shorten(char*,char*,int);
  44. int upper(int);
  45. int lower(int);
  46. int rtrim_len(char*,int=1,int=-1);
  47. int ltrim_len(char*,int=1,int=-1);
  48. void rtrim(char*,char*);
  49. void ltrim(char*,char*);
  50. void alltrim(char*,char*);
  51. char* rtrim(char*);
  52. char* ltrim(char*);
  53. char* alltrim(char*);
  54. char* nullify(char*,int);
  55. void rtrim_fld(char*,char*,int);
  56. int atoi(char*,int);
  57. void empty(char*,int);
  58. int is_empty(char*,int=0);
  59. int valid_char(char);
  60. void fix_str(char*,int,char=0);
  61. int check_sum(char*,int=-1);
  62. char* format(double,int=1);
  63. char* format_percent(double);
  64. char* format(int,int=1);
  65. char* format(short a,int b=1) { return format((int)a, b); }
  66. char* format(long a,int b=1) { return format((int)a, b); }
  67. char* num_th(int);
  68. char* num_to_str(int);
  69. char* roman_number(int);
  70. int get_key();
  71. int key_pressed();
  72. int is_touch(int,int,int,int,int,int,int,int);
  73. int sqrt(long);
  74. int diagonal_distance(int,int,int,int);
  75. int points_distance(int,int,int,int);
  76. float round(float,int,int=0);
  77. float round_dec(float);
  78. void delay(float wait);
  79. unsigned long get_time();
  80. void randomize();
  81. void set_random_seed(long);
  82. long get_random_seed();
  83. int rand();
  84. int random(int);
  85. int is_file_exist(char*);
  86. void change_file_ext(char*,char*,char*);
  87. void extract_file_name(char*, char*);
  88. void put_text_scr(char*);
  89. void del_array_rec(void* arrayBody, int arraySize, int recSize, int delRecno);
  90. void cal_move_around_a_point(short num, short width, short height, int& xShift, int& yShift);
  91. void cal_move_around_a_point_v2(short num, short width, short height, int& xShift, int& yShift);
  92. void set_surround_bit(long int& flag, int bitNo);
  93. void lock_seed();
  94. void unlock_seed();
  95. int is_seed_locked();
  96. private:
  97. void construct_move_around_table();
  98. };
  99. extern Misc m, m2; // two instance for separate random_seed
  100. //---------- End of define class ---------------//
  101. //--------- Begin of inline function Misc::is_touch ------------//
  102. //
  103. // Check if the given two area touch each other
  104. //
  105. // Return : 1 or 0
  106. //
  107. inline int Misc::is_touch(int x1, int y1, int x2, int y2, int a1, int b1, int a2, int b2 )
  108. {
  109. return (( b1 <= y1 && b2 >= y1 ) ||
  110. ( y1 <= b1 && y2 >= b1 )) &&
  111. (( a1 <= x1 && a2 >= x1 ) ||
  112. ( x1 <= a1 && x2 >= a1 ));
  113. }
  114. //--------- End of inline function Misc::is_touch -----------//
  115. #endif