OREGION.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 : OREGION.H
  21. // Description : Header file of RegionArray
  22. // Owner : Gilbert
  23. #ifndef __OREGION_H
  24. #define __OREGION_H
  25. #ifndef DEBUG
  26. #include <OREGIONS.h>
  27. #endif
  28. #ifndef __ALL_H
  29. #include <ALL.h>
  30. #endif
  31. //---------- define constant ---------//
  32. #define MAX_REGION 255
  33. //------- Define enum RegionType -------//
  34. enum RegionType
  35. {
  36. REGION_INPASSABLE,
  37. REGION_LAND,
  38. REGION_SEA,
  39. };
  40. //------- Define struct RegionInfo ----------//
  41. #pragma pack(1)
  42. struct RegionInfo
  43. {
  44. BYTE region_id;
  45. BYTE region_stat_id;
  46. RegionType region_type;
  47. int adj_offset_bit;
  48. int region_size;
  49. short center_x, center_y; // the center locatino of the region
  50. };
  51. #pragma pack()
  52. //------- Define class RegionArray ----------//
  53. class RegionStat;
  54. #pragma pack(1)
  55. class RegionArray
  56. {
  57. public:
  58. int init_flag;
  59. RegionInfo* region_info_array;
  60. int region_info_count;
  61. RegionStat* region_stat_array;
  62. int region_stat_count;
  63. unsigned char *connect_bits;
  64. BYTE region_sorted_array[MAX_REGION]; // an array of region id. sorted by the region size
  65. public:
  66. RegionArray();
  67. ~RegionArray();
  68. void init(int maxRegion);
  69. void deinit();
  70. void next_day();
  71. void inc_size(int reg);
  72. void set_region(int reg, RegionType);
  73. void set_adjacent(int reg1, int reg2);
  74. int is_adjacent(int reg1, int reg2);
  75. void sort_region();
  76. void init_region_stat();
  77. void update_region_stat();
  78. int get_sea_path_region_id(int regionId1, int regionId2);
  79. int nation_has_base_town(int regionId, int nationRecno);
  80. int write_file(File* filePtr);
  81. int read_file(File* filePtr);
  82. //--------------------------------------//
  83. #ifdef DEBUG
  84. RegionStat* get_region_stat(int regionId);
  85. RegionStat* get_region_stat2(int regionStatId);
  86. RegionInfo* get_sorted_region(int recNo);
  87. RegionType region_type(int region);
  88. RegionInfo *operator[](int region);
  89. #else
  90. RegionInfo *operator[](int region)
  91. { return region_info_array+region-1; }
  92. RegionStat* get_region_stat(int regionId)
  93. { return region_stat_array + region_info_array[regionId-1].region_stat_id - 1; }
  94. RegionStat* get_region_stat2(int regionStatId)
  95. { return region_stat_array+regionStatId-1; }
  96. RegionType region_type(int region)
  97. { return region_info_array[region-1].region_type; }
  98. RegionInfo* get_sorted_region(int recNo)
  99. { return operator[]( region_sorted_array[recNo-1] ); }
  100. #endif
  101. };
  102. #pragma pack()
  103. extern RegionArray region_array;
  104. //------------------------------------------//
  105. #endif