OR_ECO.cpp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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 : OINFOECO.CPP
  21. //Description : Economy information screen
  22. #include <OVGA.h>
  23. #include <OSYS.h>
  24. #include <OFONT.h>
  25. #include <OIMGRES.h>
  26. #include <OVBROWIF.h>
  27. #include <OBUTTON.h>
  28. #include <OFIRM.h>
  29. #include <OFIRMRES.h>
  30. #include <ORACERES.h>
  31. #include <ONATION.h>
  32. #include <OUNIT.h>
  33. #include <OINFO.h>
  34. //------------- Define coordinations -----------//
  35. enum { INCOME_BROWSE_X1 = ZOOM_X1+6,
  36. INCOME_BROWSE_Y1 = ZOOM_Y1+6,
  37. INCOME_BROWSE_X2 = ZOOM_X2-6,
  38. INCOME_BROWSE_Y2 = INCOME_BROWSE_Y1+186
  39. };
  40. enum { EXPENSE_BROWSE_X1 = ZOOM_X1+6,
  41. EXPENSE_BROWSE_Y1 = INCOME_BROWSE_Y2+6,
  42. EXPENSE_BROWSE_X2 = ZOOM_X2-6,
  43. EXPENSE_BROWSE_Y2 = ZOOM_Y2-30,
  44. };
  45. //----------- Define static variables ----------//
  46. static VBrowseIF browse_income, browse_expense;
  47. //----------- Define static functions ----------//
  48. static void put_income_rec(int recNo, int x, int y, int refreshFlag);
  49. static void put_expense_rec(int recNo, int x, int y, int refreshFlag);
  50. static void disp_total();
  51. //--------- Begin of function Info::disp_economy ---------//
  52. //
  53. void Info::disp_economy(int refreshFlag)
  54. {
  55. //------- display the income report -------//
  56. int x=INCOME_BROWSE_X1+9;
  57. int y=INCOME_BROWSE_Y1+4;
  58. vga_back.d3_panel_up(INCOME_BROWSE_X1, INCOME_BROWSE_Y1, INCOME_BROWSE_X2, INCOME_BROWSE_Y1+20 );
  59. font_san.put( x , y, "Income Item" );
  60. font_san.put( x+350, y, "Yearly Income" );
  61. int incomeCount; // only display the cheat income if it amount is > 0
  62. if( nation_array[info.viewing_nation_recno]->income_365days(INCOME_CHEAT) > 0 &&
  63. (sys.testing_session || info.viewing_nation_recno == nation_array.player_recno) ) // only display cheat amount in debug mode or cheat amount of the player's kingdom, do not display cheat amount on AI kingdoms
  64. {
  65. incomeCount = INCOME_TYPE_COUNT;
  66. }
  67. else
  68. incomeCount = INCOME_TYPE_COUNT-1;
  69. if( refreshFlag == INFO_REPAINT )
  70. {
  71. browse_income.init( INCOME_BROWSE_X1, INCOME_BROWSE_Y1+22, INCOME_BROWSE_X2, INCOME_BROWSE_Y2-20,
  72. 0, 16, incomeCount, put_income_rec, 1 );
  73. browse_income.open(browse_income_recno); // if refreshFlag is INFO_UPDATE, keep the original top_rec_no of the browser
  74. }
  75. else
  76. {
  77. browse_income.paint();
  78. browse_income.open(browse_income_recno, incomeCount);
  79. }
  80. //------- display the expense report -------//
  81. x=EXPENSE_BROWSE_X1+9;
  82. y=EXPENSE_BROWSE_Y1+4;
  83. vga_back.d3_panel_up(EXPENSE_BROWSE_X1, EXPENSE_BROWSE_Y1, EXPENSE_BROWSE_X2, EXPENSE_BROWSE_Y1+20 );
  84. font_san.put( x , y, "Expense Item" );
  85. font_san.put( x+350, y, "Yearly Expense" );
  86. if( refreshFlag == INFO_REPAINT )
  87. {
  88. browse_expense.init( EXPENSE_BROWSE_X1, EXPENSE_BROWSE_Y1+22, EXPENSE_BROWSE_X2, EXPENSE_BROWSE_Y2-20,
  89. 0, 16, EXPENSE_TYPE_COUNT, put_expense_rec, 1 );
  90. browse_expense.open(browse_expense_recno); // if refreshFlag is INFO_UPDATE, keep the original top_rec_no of the browser
  91. }
  92. else
  93. {
  94. browse_expense.paint();
  95. browse_expense.open(browse_expense_recno, EXPENSE_TYPE_COUNT); // if refreshFlag is INFO_UPDATE, keep the original top_rec_no of the browser
  96. }
  97. //--------- display total ----------//
  98. disp_total();
  99. }
  100. //----------- End of function Info::disp_economy -----------//
  101. //--------- Begin of function Info::detect_economy ---------//
  102. //
  103. void Info::detect_economy()
  104. {
  105. if( browse_income.detect() )
  106. browse_income_recno = browse_income.recno();
  107. if( browse_expense.detect() )
  108. browse_expense_recno = browse_expense.recno();
  109. }
  110. //----------- End of function Info::detect_economy -----------//
  111. //--------- Begin of static function disp_total ---------//
  112. //
  113. static void disp_total()
  114. {
  115. //--- calculate the total income and expense ----//
  116. float totalIncome = (float) 0;
  117. float totalExpense = (float) 0;
  118. Nation* nationPtr = nation_array[info.viewing_nation_recno];
  119. int i;
  120. for( i=0 ; i<INCOME_TYPE_COUNT ; i++ )
  121. totalIncome += nationPtr->income_365days(i);
  122. for( i=0 ; i<EXPENSE_TYPE_COUNT ; i++ )
  123. totalExpense += nationPtr->expense_365days(i);
  124. //---------- display total income ----------//
  125. vga_back.d3_panel_up(INCOME_BROWSE_X1, INCOME_BROWSE_Y2-18, INCOME_BROWSE_X2, INCOME_BROWSE_Y2 );
  126. int x=INCOME_BROWSE_X1+9;
  127. int y=INCOME_BROWSE_Y2-16;
  128. font_san.put( x, y, "Total Yearly Income" );
  129. font_san.put( x+370, y, m.format( (int) totalIncome, 2 ) );
  130. //---------- display total expense ----------//
  131. vga_back.d3_panel_up(EXPENSE_BROWSE_X1, EXPENSE_BROWSE_Y2-18, EXPENSE_BROWSE_X2, EXPENSE_BROWSE_Y2 );
  132. x=EXPENSE_BROWSE_X1+9;
  133. y=EXPENSE_BROWSE_Y2-16;
  134. font_san.put( x, y, "Total Yearly Expenses" );
  135. font_san.put( x+370, y, m.format( (int) totalExpense, 2 ) );
  136. //----------- display the balance --------//
  137. y=EXPENSE_BROWSE_Y2+7;
  138. vga_back.d3_panel_up(EXPENSE_BROWSE_X1, EXPENSE_BROWSE_Y2+4, EXPENSE_BROWSE_X2, ZOOM_Y2-6 );
  139. font_san.put( x, y, "Yearly Balance" );
  140. font_san.put( x+370, y, m.format( (int)(totalIncome-totalExpense), 2 ) );
  141. }
  142. //----------- End of static function disp_total -----------//
  143. //-------- Begin of static function put_income_rec --------//
  144. //
  145. static void put_income_rec(int recNo, int x, int y, int refreshFlag)
  146. {
  147. //----- define income descriptions ------//
  148. static char* income_des_array[INCOME_TYPE_COUNT] =
  149. {
  150. "Sale of Goods",
  151. "Exports",
  152. "Taxes",
  153. "Recovered Treasure",
  154. "Worker Income",
  155. "Sale of Buildings",
  156. "Aid/Tribute from Other Kingdoms",
  157. "Cheating",
  158. };
  159. //---------------------------------//
  160. x+=3;
  161. y+=3;
  162. Nation* nationPtr = nation_array[info.viewing_nation_recno];
  163. font_san.put( x , y, income_des_array[recNo-1] );
  164. font_san.put( x+370, y, m.format( (int) nationPtr->income_365days(recNo-1), 2 ) );
  165. }
  166. //----------- End of static function put_income_rec -----------//
  167. //-------- Begin of static function put_expense_rec --------//
  168. //
  169. static void put_expense_rec(int recNo, int x, int y, int refreshFlag)
  170. {
  171. //----- define expense descriptions -------//
  172. static char* expense_des_array[EXPENSE_TYPE_COUNT] =
  173. {
  174. "General Costs",
  175. "Spy Costs",
  176. "Other Mobile Human Unit Costs",
  177. "Caravan Costs",
  178. "Weapons Costs",
  179. "Ship Costs",
  180. "Buildings Costs",
  181. "Training Units",
  182. "Hiring Units",
  183. "Honoring Units",
  184. "Foreign Worker Salaries",
  185. "Grants to Your Villagers",
  186. "Grants to Other Villagers",
  187. "Imports",
  188. "Aid/Tribute to Other Kingdoms",
  189. "Bribes",
  190. };
  191. //---------------------------------//
  192. x+=3;
  193. y+=3;
  194. Nation* nationPtr = nation_array[info.viewing_nation_recno];
  195. font_san.put( x , y, expense_des_array[recNo-1] );
  196. font_san.put( x+370, y, m.format( (int) nationPtr->expense_365days(recNo-1), 2 ) );
  197. }
  198. //----------- End of static function put_expense_rec -----------//