ORAWRES.cpp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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 : ORAWRES.CPP
  21. //Description : Raw material resource object
  22. #include <OINFO.h>
  23. #include <OVGA.h>
  24. #include <OHELP.h>
  25. #include <OFONT.h>
  26. #include <OSYS.h>
  27. #include <OGAMESET.h>
  28. #include <OF_FACT.h>
  29. #include <OF_MINE.h>
  30. #include <OF_MARK.h>
  31. #include <ORAWRES.h>
  32. //---------- #define constant ------------//
  33. #define RAW_DB "RAW"
  34. //------- Begin of function RawRes::RawRes -----------//
  35. RawRes::RawRes()
  36. {
  37. init_flag=0;
  38. }
  39. //--------- End of function RawRes::RawRes -----------//
  40. //---------- Begin of function RawRes::init -----------//
  41. //
  42. // This function must be called after a map is generated.
  43. //
  44. void RawRes::init()
  45. {
  46. deinit();
  47. //----- open unit bitmap resource file -------//
  48. String str;
  49. str = DIR_RES;
  50. str += "I_RAW.RES";
  51. res_icon.init(str, 1); // 1-read all into buffer
  52. //------- load database information --------//
  53. load_all_info();
  54. init_flag=1;
  55. }
  56. //---------- End of function RawRes::init -----------//
  57. //---------- Begin of function RawRes::deinit -----------//
  58. void RawRes::deinit()
  59. {
  60. if( init_flag )
  61. {
  62. delete [] raw_info_array;
  63. init_flag=0;
  64. }
  65. }
  66. //---------- End of function RawRes::deinit -----------//
  67. //------- Begin of function RawRes::load_all_info -------//
  68. //
  69. // Read in information of RAW.DBF into memory array
  70. //
  71. void RawRes::load_all_info()
  72. {
  73. RawRec *rawRec;
  74. RawInfo *rawInfo;
  75. int i;
  76. Database *dbRaw = game_set.open_db(RAW_DB);
  77. raw_count = (short) dbRaw->rec_count();
  78. raw_info_array = new RawInfo[raw_count];
  79. //------ read in raw information array -------//
  80. for( i=0 ; i<raw_count ; i++ )
  81. {
  82. rawRec = (RawRec*) dbRaw->read(i+1);
  83. rawInfo = raw_info_array+i;
  84. m.rtrim_fld( rawInfo->name, rawRec->name, rawRec->NAME_LEN );
  85. #if(defined(GERMAN) || defined(FRENCH) || defined(SPANISH))
  86. translate.multi_to_win(rawInfo->name, rawInfo->NAME_LEN);
  87. #endif
  88. rawInfo->raw_id = i+1;
  89. rawInfo->tera_type = m.atoi( rawRec->tera_type, rawRec->TERA_TYPE_LEN );
  90. }
  91. }
  92. //--------- End of function RawRes::load_all_info ---------//
  93. //---------- Begin of function RawRes::next_day -----------//
  94. void RawRes::next_day()
  95. {
  96. if( info.game_date%15==0 )
  97. update_supply_firm();
  98. }
  99. //---------- End of function RawRes::next_day -----------//
  100. //------- Begin of function RawRes::update_supply_firm -------//
  101. void RawRes::update_supply_firm()
  102. {
  103. //----- reset the supply array of each raw and product ----//
  104. for( int i=0 ; i<MAX_RAW ; i++ )
  105. {
  106. raw_info_array[i].raw_supply_firm_array.zap();
  107. raw_info_array[i].product_supply_firm_array.zap();
  108. }
  109. //---- locate for suppliers that supply the products needed ----//
  110. Firm* firmPtr;
  111. FirmMine* firmMine;
  112. FirmFactory* firmFactory;
  113. FirmMarket* firmMarket;
  114. for( short firmRecno=firm_array.size() ; firmRecno>0 ; firmRecno-- )
  115. {
  116. if( firm_array.is_deleted(firmRecno) )
  117. continue;
  118. firmPtr = (Firm*) firm_array[firmRecno];
  119. //-------- factory as a potential supplier ------//
  120. if( firmPtr->firm_id == FIRM_FACTORY )
  121. {
  122. firmFactory = (FirmFactory*) firmPtr;
  123. if( firmFactory->product_raw_id &&
  124. firmFactory->stock_qty > firmFactory->max_stock_qty / 5 )
  125. {
  126. raw_res[firmFactory->product_raw_id]->add_product_supply_firm(firmRecno);
  127. }
  128. }
  129. //-------- mine as a potential supplier ------//
  130. if( firmPtr->firm_id == FIRM_MINE )
  131. {
  132. firmMine = (FirmMine*) firmPtr;
  133. if( firmMine->raw_id &&
  134. firmMine->stock_qty > firmMine->max_stock_qty / 5 )
  135. {
  136. raw_res[firmMine->raw_id]->add_raw_supply_firm(firmRecno);
  137. }
  138. }
  139. //-------- market place as a potential supplier ------//
  140. else if( firmPtr->firm_id == FIRM_MARKET )
  141. {
  142. firmMarket = (FirmMarket*) firmPtr;
  143. MarketGoods* marketGoods = firmMarket->market_goods_array;
  144. for( int i=0 ; i<MAX_MARKET_GOODS ; i++, marketGoods++ )
  145. {
  146. if( marketGoods->stock_qty > MAX_MARKET_STOCK / 5 )
  147. {
  148. if( marketGoods->product_raw_id )
  149. raw_res[marketGoods->product_raw_id]->add_product_supply_firm(firmRecno);
  150. else if( marketGoods->raw_id )
  151. raw_res[marketGoods->raw_id]->add_raw_supply_firm(firmRecno);
  152. }
  153. }
  154. }
  155. }
  156. }
  157. //-------- End of function RawRes::update_supply_firm --------//
  158. //------- Begin of function RawInfo::RawInfo -----------//
  159. RawInfo::RawInfo() : raw_supply_firm_array(sizeof(short), 70), product_supply_firm_array(sizeof(short), 70)
  160. {
  161. }
  162. //--------- End of function RawInfo::RawInfo -----------//
  163. //------- Begin of function RawInfo::add_raw_supply_firm -----------//
  164. void RawInfo::add_raw_supply_firm(short firmRecno)
  165. {
  166. err_when( firm_array.is_deleted(firmRecno) );
  167. raw_supply_firm_array.linkin(&firmRecno);
  168. }
  169. //--------- End of function RawInfo::add_raw_supply_firm --------//
  170. //------- Begin of function RawInfo::add_product_supply_firm -----------//
  171. void RawInfo::add_product_supply_firm(short firmRecno)
  172. {
  173. err_when( firm_array.is_deleted(firmRecno) );
  174. product_supply_firm_array.linkin(&firmRecno);
  175. }
  176. //--------- End of function RawInfo::add_product_supply_firm --------//
  177. //---------- Begin of function RawRes::operator[] -----------//
  178. RawInfo* RawRes::operator[](int rawId)
  179. {
  180. err_if( rawId<1 || rawId>raw_count )
  181. err_now( "RawRes::operator[]" );
  182. return raw_info_array+rawId-1;
  183. }
  184. //------------ End of function RawRes::operator[] -----------//
  185. //---------- Begin of function RawRes::put_small_raw_icon -----------//
  186. void RawRes::put_small_raw_icon(int x, int y, int rawId)
  187. {
  188. char* bitmapPtr = res_icon.read(MAX_RAW*3+rawId);
  189. Vga::active_buf->put_bitmap_trans(x, y, bitmapPtr);
  190. help.set_custom_help( x, y, x+RAW_SMALL_ICON_WIDTH-1, y+RAW_SMALL_ICON_HEIGHT-1,
  191. raw_res[rawId]->name );
  192. }
  193. //---------- End of function RawRes::put_small_raw_icon -----------//
  194. //---------- Begin of function RawRes::put_small_product_icon -----------//
  195. void RawRes::put_small_product_icon(int x, int y, int rawId)
  196. {
  197. char* bitmapPtr = res_icon.read(MAX_RAW+rawId);
  198. Vga::active_buf->put_bitmap_trans(x, y, bitmapPtr);
  199. String str;
  200. #if(defined(FRENCH))
  201. char productName[20];
  202. strcpy(productName, raw_res[rawId]->name);
  203. strcat(productName, " Products");
  204. str = translate.process(productName);
  205. #else
  206. str = raw_res[rawId]->name;
  207. str += translate.process(" Products");
  208. #endif
  209. help.set_custom_help( x, y, x+RAW_SMALL_ICON_WIDTH-1, y+RAW_SMALL_ICON_HEIGHT-1, str );
  210. }
  211. //---------- End of function RawRes::put_small_product_icon -----------//