OU_MARIS.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. #include <OU_MARI.h>
  21. #include <OF_MINE.h>
  22. #include <OF_FACT.h>
  23. #include <OF_MARK.h>
  24. //--------- Begin of function ShipStop::update_pick_up ---------//
  25. // enableFlag - represent which button will be displayed
  26. //
  27. int ShipStop::update_pick_up(char *enableFlag)
  28. {
  29. #ifdef DBEUG
  30. if(pick_up_type == AUTO_PICK_UP || pick_up_type == NO_PICK_UP)
  31. {
  32. for(int di=0; di<MAX_PICK_UP_GOODS; ++di)
  33. err_when(pick_up_array[di]);
  34. }
  35. #endif
  36. static char dummyBuffer[MAX_GOODS_SELECT_BUTTON];
  37. if(enableFlag==NULL)
  38. enableFlag = dummyBuffer;
  39. memset(enableFlag, 0, sizeof(char)*MAX_GOODS_SELECT_BUTTON);
  40. Firm *harborPtr = firm_array[firm_recno];
  41. Firm *firmPtr;
  42. MarketGoods *marketGoodsPtr;
  43. int selectiveMode = (pick_up_type!=AUTO_PICK_UP && pick_up_type!=NO_PICK_UP);
  44. int goodsNum=0; // represent the number of cargo displayed in the menu for this stop
  45. int firstGoodsId = 0;
  46. int id, i, j;
  47. for(i=harborPtr->linked_firm_count-1; i>=0; --i)
  48. {
  49. err_when(firm_array.is_deleted(harborPtr->linked_firm_array[i]));
  50. firmPtr = firm_array[harborPtr->linked_firm_array[i]];
  51. switch(firmPtr->firm_id)
  52. {
  53. case FIRM_MINE:
  54. if((id = ((FirmMine*)firmPtr)->raw_id)) // 1-3
  55. {
  56. goodsNum++;
  57. enableFlag[id] = 1;
  58. if(firstGoodsId==0)
  59. firstGoodsId = id;
  60. }
  61. break;
  62. case FIRM_FACTORY:
  63. if((id = ((FirmFactory*)firmPtr)->product_raw_id)) // 1-3
  64. {
  65. id += MAX_RAW; // 4-6
  66. goodsNum++;
  67. enableFlag[id] = 1;
  68. if(firstGoodsId==0)
  69. firstGoodsId = id;
  70. }
  71. break;
  72. case FIRM_MARKET:
  73. marketGoodsPtr = ((FirmMarket*) firmPtr)->market_goods_array;
  74. for(j=1; j<=MAX_MARKET_GOODS; j++, marketGoodsPtr++)
  75. {
  76. if((id = marketGoodsPtr->raw_id)) // 1-3
  77. {
  78. goodsNum++;
  79. enableFlag[id] = 1;
  80. if(firstGoodsId==0)
  81. firstGoodsId = id;
  82. }
  83. else if((id = marketGoodsPtr->product_raw_id)) // 1-3
  84. {
  85. id += MAX_RAW; // 4-6
  86. goodsNum++;
  87. enableFlag[id] = 1;
  88. if(firstGoodsId==0)
  89. firstGoodsId = id;
  90. }
  91. }
  92. break;
  93. default: err_here();
  94. break;
  95. }
  96. }
  97. for(i=0; i<MAX_PICK_UP_GOODS; ++i)
  98. {
  99. if(pick_up_array[i])
  100. {
  101. if(enableFlag[i+1]==0)
  102. pick_up_array[i] = 0;
  103. }
  104. }
  105. if(goodsNum==0 && pick_up_type!=NO_PICK_UP)
  106. pick_up_set_none();
  107. if(goodsNum==1 && pick_up_type==AUTO_PICK_UP)
  108. {
  109. pick_up_type = firstGoodsId; // change to selective
  110. pick_up_array[pick_up_type-1] = 1;
  111. }
  112. err_when(pick_up_type==AUTO_PICK_UP && goodsNum==0);
  113. #ifdef DEBUG
  114. int debugCount = 0;
  115. if(pick_up_type!=AUTO_PICK_UP && pick_up_type!=NO_PICK_UP)
  116. {
  117. for(int di=1; di<=MAX_PICK_UP_GOODS; ++di)
  118. {
  119. if(enableFlag[di])
  120. debugCount++;
  121. }
  122. err_when(debugCount==0);
  123. }
  124. #endif
  125. return goodsNum;
  126. }
  127. //----------- End of function ShipStop::update_pick_up -----------//
  128. //--------- Begin of function ShipStop::mp_pick_up_toggle ---------//
  129. void ShipStop::mp_pick_up_toggle(int pos)
  130. {
  131. err_when(firm_array.is_deleted(firm_recno));
  132. //------------------------------------------------------------//
  133. // verify for cargo button
  134. // if not exist then return else call pick_up_toggle(int pos)
  135. //------------------------------------------------------------//
  136. Firm *harborPtr = firm_array[firm_recno];
  137. Firm *firmPtr;
  138. MarketGoods *marketGoodsPtr;
  139. int cargoExist = 0;
  140. int i, j, id;
  141. for(i=harborPtr->linked_firm_count-1; i>=0; --i)
  142. {
  143. err_when(firm_array.is_deleted(harborPtr->linked_firm_array[i]));
  144. firmPtr = firm_array[harborPtr->linked_firm_array[i]];
  145. switch(firmPtr->firm_id)
  146. {
  147. case FIRM_MINE:
  148. id = ((FirmMine*)firmPtr)->raw_id+PICK_UP_RAW_FIRST-1;
  149. if(id==pos)
  150. cargoExist = 1;
  151. break;
  152. case FIRM_FACTORY:
  153. id = ((FirmFactory*)firmPtr)->product_raw_id+PICK_UP_PRODUCT_FIRST-1;
  154. if(id==pos)
  155. cargoExist = 1;
  156. break;
  157. case FIRM_MARKET:
  158. marketGoodsPtr = ((FirmMarket*) firmPtr)->market_goods_array;
  159. for(j=1; j<=MAX_MARKET_GOODS; j++, marketGoodsPtr++)
  160. {
  161. if((id = marketGoodsPtr->raw_id)) // 1-3
  162. {
  163. if(id==pos)
  164. cargoExist = 1;
  165. break;
  166. }
  167. else if((id = marketGoodsPtr->product_raw_id)) // 1-3
  168. {
  169. id += MAX_PRODUCT; // 4-6
  170. if(id==pos)
  171. cargoExist = 1;
  172. break;
  173. }
  174. }
  175. break;
  176. default: err_here();
  177. break;
  178. }
  179. if(cargoExist)
  180. {
  181. pick_up_toggle(pos);
  182. break;
  183. }
  184. }
  185. }
  186. //----------- End of function ShipStop::mp_pick_up_toggle -----------//