OGODRES.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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 : OGODRES.CPP
  21. //Description : God resource class
  22. #include <OSYS.h>
  23. #include <OGAMESET.h>
  24. #include <OWORLD.h>
  25. #include <OSPRTRES.h>
  26. #include <ONATION.h>
  27. #include <OUNIT.h>
  28. #include <OUNITRES.h>
  29. #include <OU_GOD.h>
  30. #include <OF_BASE.h>
  31. #include <OGODRES.h>
  32. //---------- #define constant ------------//
  33. #define GOD_DB "GOD"
  34. //------- Begin of function GodRes::GodRes -----------//
  35. GodRes::GodRes()
  36. {
  37. init_flag=0;
  38. }
  39. //--------- End of function GodRes::GodRes -----------//
  40. //---------- Begin of function GodRes::init -----------//
  41. //
  42. // This function must be called after a map is generated.
  43. //
  44. void GodRes::init()
  45. {
  46. deinit();
  47. //------- load database information --------//
  48. load_god_info();
  49. init_flag=1;
  50. }
  51. //---------- End of function GodRes::init -----------//
  52. //---------- Begin of function GodRes::deinit -----------//
  53. void GodRes::deinit()
  54. {
  55. if( init_flag )
  56. {
  57. mem_del(god_info_array);
  58. init_flag=0;
  59. }
  60. }
  61. //---------- End of function GodRes::deinit -----------//
  62. //------- Begin of function GodRes::load_god_info -------//
  63. //
  64. // Read in information of GOD.DBF into memory array
  65. //
  66. void GodRes::load_god_info()
  67. {
  68. GodRec *godRec;
  69. GodInfo *godInfo;
  70. int i;
  71. Database *dbGod = game_set.open_db(GOD_DB);
  72. god_count = (short) dbGod->rec_count();
  73. god_info_array = (GodInfo*) mem_add( sizeof(GodInfo)*god_count );
  74. //------ read in god information array -------//
  75. memset( god_info_array, 0, sizeof(GodInfo) * god_count );
  76. for( i=0 ; i<god_count ; i++ )
  77. {
  78. godRec = (GodRec*) dbGod->read(i+1);
  79. godInfo = god_info_array+i;
  80. godInfo->god_id = i+1;
  81. godInfo->race_id = m.atoi(godRec->race_id, godRec->RACE_ID_LEN);
  82. godInfo->unit_id = m.atoi(godRec->unit_id, godRec->UNIT_ID_LEN);
  83. godInfo->exist_pray_points = m.atoi(godRec->exist_pray_points, godRec->PRAY_POINTS_LEN);
  84. godInfo->power_pray_points = m.atoi(godRec->power_pray_points, godRec->PRAY_POINTS_LEN);
  85. godInfo->can_cast_power = godRec->can_cast_power == '1';
  86. godInfo->cast_power_range = m.atoi(godRec->cast_power_range, godRec->CAST_POWER_RANGE_LEN);
  87. }
  88. }
  89. //--------- End of function GodRes::load_god_info ---------//
  90. //------- Begin of function GodRes::enable_know_all -------//
  91. //
  92. // Make all god creatures known to this nation. (A cheating function)
  93. //
  94. void GodRes::enable_know_all(int nationRecno)
  95. {
  96. for( int i=1 ; i<=god_res.god_count ; i++ )
  97. {
  98. god_res[i]->enable_know(nationRecno);
  99. }
  100. }
  101. //--------- End of function GodRes::enable_know_all ---------//
  102. //------- Begin of function GodRes::init_nation_know -------//
  103. //
  104. // Initialize the god know status of a new nation.
  105. //
  106. void GodRes::init_nation_know(int nationRecno)
  107. {
  108. for( int i=1 ; i<=god_res.god_count ; i++ )
  109. {
  110. god_res[i]->disable_know(nationRecno);
  111. }
  112. }
  113. //--------- End of function GodRes::init_nation_know ---------//
  114. //------- Begin of function GodInfo::enable_know -------//
  115. //
  116. // Make this god known to this nation.
  117. //
  118. void GodInfo::enable_know(int nationRecno)
  119. {
  120. nation_know_array[nationRecno-1] = 1;
  121. nation_array[nationRecno]->know_base_array[race_id-1] = 1; // enable the nation to build the fortress of power
  122. }
  123. //--------- End of function GodInfo::enable_know ---------//
  124. //------- Begin of function GodInfo::disable_know -------//
  125. //
  126. // Make this god known to this nation.
  127. //
  128. void GodInfo::disable_know(int nationRecno)
  129. {
  130. nation_know_array[nationRecno-1] = 0;
  131. nation_array[nationRecno]->know_base_array[race_id-1] = 0; // enable the nation to build the fortress of power
  132. }
  133. //--------- End of function GodInfo::disable_know ---------//
  134. //------- Begin of function GodInfo::invoke -------//
  135. //
  136. // <int> firmRecno - the firm recno of the seat of power which invokes this god.
  137. // <int> xLoc, yLoc - the x and y location of the god
  138. //
  139. // return: <int> the recno of the God unit created.
  140. //
  141. short GodInfo::invoke(int firmRecno, int xLoc, int yLoc)
  142. {
  143. FirmBase* firmBase = (FirmBase*) firm_array[firmRecno];
  144. err_when( firmBase->firm_id != FIRM_BASE );
  145. //------- create the god unit --------//
  146. SpriteInfo* spriteInfo = sprite_res[unit_res[unit_id]->sprite_id];
  147. if( !world.locate_space( xLoc, yLoc, xLoc, yLoc, spriteInfo->loc_width, spriteInfo->loc_height, UNIT_AIR ) )
  148. return 0;
  149. //---------- add the god unit now -----------//
  150. short unitRecno = unit_array.add_unit( unit_id, firmBase->nation_recno,
  151. RANK_SOLDIER, 0, xLoc, yLoc );
  152. //------- set vars of the God unit ----------//
  153. UnitGod* unitGod = (UnitGod*) unit_array[unitRecno];
  154. unitGod->god_id = god_id;
  155. unitGod->base_firm_recno = firmRecno;
  156. unitGod->hit_points = (short) firmBase->pray_points;
  157. return unitRecno;
  158. }
  159. //--------- End of function GodInfo::invoke ---------//
  160. //------- Begin of function GodRes::is_god_unit -------//
  161. //
  162. // Whether the given unit is a god unit or not.
  163. //
  164. int GodRes::is_god_unit(int unitId)
  165. {
  166. for( int i=1 ; i<=god_res.god_count ; i++ )
  167. {
  168. if( god_res[i]->unit_id == unitId )
  169. return 1;
  170. }
  171. return 0;
  172. }
  173. //--------- End of function GodRes::is_god_unit ---------//
  174. //---------- Begin of function GodRes::operator[] -----------//
  175. GodInfo* GodRes::operator[](int godId)
  176. {
  177. err_if( godId<1 || godId>god_count )
  178. err_now( "GodRes::operator[]" );
  179. return god_info_array+godId-1;
  180. }
  181. //------------ End of function GodRes::operator[] -----------//