OR_TECH.cpp 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  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 : OR_TECH.CPP
  21. //Description : Technology Report
  22. #include <OVGA.h>
  23. #include <OFONT.h>
  24. #include <OIMGRES.h>
  25. #include <OVBROWIF.h>
  26. #include <OBUTTON.h>
  27. #include <OTECHRES.h>
  28. #include <OGODRES.h>
  29. #include <ORACERES.h>
  30. #include <ONATION.h>
  31. #include <OU_GOD.h>
  32. #include <OINFO.h>
  33. //------------- Define coordinations -----------//
  34. enum { TECH_BROWSE_X1 = ZOOM_X1+6,
  35. TECH_BROWSE_Y1 = ZOOM_Y1+6,
  36. TECH_BROWSE_X2 = ZOOM_X2-6,
  37. TECH_BROWSE_Y2 = TECH_BROWSE_Y1+220
  38. };
  39. enum { SCROLL_X1 = ZOOM_X1+6,
  40. SCROLL_Y1 = TECH_BROWSE_Y2+6,
  41. SCROLL_X2 = ZOOM_X2-6,
  42. SCROLL_Y2 = SCROLL_Y1+80
  43. };
  44. enum { GOD_BROWSE_X1 = ZOOM_X1+6,
  45. GOD_BROWSE_Y1 = SCROLL_Y2+6,
  46. GOD_BROWSE_X2 = ZOOM_X2-6,
  47. GOD_BROWSE_Y2 = ZOOM_Y2-6
  48. };
  49. //----------- Define static variables ----------//
  50. static VBrowseIF browse_tech, browse_god;
  51. //----------- Define static functions ----------//
  52. static int tech_filter(int recNo=0);
  53. static int god_filter(int recNo=0);
  54. static void put_tech_rec(int recNo, int x, int y, int refreshFlag);
  55. static void put_god_rec(int recNo, int x, int y, int refreshFlag);
  56. static void disp_owned_scroll();
  57. static void disp_scroll(int x, int y, int raceId);
  58. //--------- Begin of function Info::disp_tech ---------//
  59. //
  60. void Info::disp_tech(int refreshFlag)
  61. {
  62. //-------- display the technology browser ---------//
  63. int x=TECH_BROWSE_X1+9;
  64. int y=TECH_BROWSE_Y1+4;
  65. vga_back.d3_panel_up(TECH_BROWSE_X1, TECH_BROWSE_Y1, TECH_BROWSE_X2, TECH_BROWSE_Y1+32 );
  66. font_san.put( x , y+7, "Technology" );
  67. #if(defined(SPANISH))
  68. font_san.put( x+160, y , "Version" );
  69. font_san.put( x+160, y+13, "Present");
  70. font_san.put( x+245, y , "Version" );
  71. font_san.put( x+230, y+13, "Researching");
  72. font_san.put( x+320, y+7, "Research Progress" );
  73. font_san.put( x+460, y , "Tower of" );
  74. font_san.put( x+468, y+13, "Science" );
  75. #elif(defined(FRENCH))
  76. font_san.put( x+160, y , "Catégorie" );
  77. font_san.put( x+160, y+13, "Actuelle" );
  78. font_san.put( x+230, y , "Catégorie" );
  79. font_san.put( x+230, y+13, "Recherchée" );
  80. font_san.put( x+320, y, "Etat de la" );
  81. font_san.put( x+320, y+13, "Recherche");
  82. font_san.put( x+460, y , "Tour du" );
  83. font_san.put( x+462, y+13, "Savoir" );
  84. #else
  85. // German and US
  86. font_san.put( x+160, y , "Present" );
  87. font_san.put( x+160, y+13, "Version" );
  88. font_san.put( x+230, y , "Researching" );
  89. font_san.put( x+245, y+13, "Version" );
  90. font_san.put( x+320, y+7, "Research Progress" );
  91. font_san.put( x+460, y , "Tower of" );
  92. font_san.put( x+462, y+13, "Science" );
  93. #endif
  94. if( refreshFlag == INFO_REPAINT )
  95. {
  96. browse_tech.init( TECH_BROWSE_X1, TECH_BROWSE_Y1+34, TECH_BROWSE_X2, TECH_BROWSE_Y2,
  97. 0, 22, tech_filter(), put_tech_rec, 1 );
  98. browse_tech.open(browse_tech_recno);
  99. }
  100. else
  101. {
  102. browse_tech.paint();
  103. browse_tech.open(browse_tech_recno, tech_filter());
  104. }
  105. //----- display the list of acquired scrolls of power ----//
  106. disp_owned_scroll();
  107. //-------- display the god unit browser ---------//
  108. x=GOD_BROWSE_X1+9;
  109. y=GOD_BROWSE_Y1+4;
  110. vga_back.d3_panel_up(GOD_BROWSE_X1, GOD_BROWSE_Y1, GOD_BROWSE_X2, GOD_BROWSE_Y1+20 );
  111. font_san.put( x , y, "Greater Being" );
  112. font_san.put( x+300, y, "Hit Points" );
  113. if( refreshFlag == INFO_REPAINT )
  114. {
  115. browse_god.init( GOD_BROWSE_X1, GOD_BROWSE_Y1+22, GOD_BROWSE_X2, GOD_BROWSE_Y2,
  116. 0, 22, god_filter(), put_god_rec, 1 );
  117. browse_god.open(browse_god_recno);
  118. }
  119. else
  120. {
  121. browse_god.paint();
  122. browse_god.open(browse_god_recno, god_filter());
  123. }
  124. }
  125. //----------- End of function Info::disp_tech -----------//
  126. //--------- Begin of function Info::detect_tech ---------//
  127. //
  128. void Info::detect_tech()
  129. {
  130. if( browse_tech.detect() )
  131. browse_tech_recno = browse_tech.recno();
  132. if( browse_god.detect() )
  133. {
  134. browse_god_recno = browse_god.recno();
  135. if( browse_god.double_click )
  136. {
  137. Unit* unitPtr = unit_array[ god_filter(browse_god.recno()) ];
  138. world.go_loc( unitPtr->next_x_loc(), unitPtr->next_y_loc(), 1 );
  139. }
  140. }
  141. }
  142. //----------- End of function Info::detect_tech -----------//
  143. //-------- Begin of static function tech_filter --------//
  144. //
  145. // This function has dual purpose :
  146. //
  147. // 1. when <int> recNo is not given :
  148. // - return the total no. of firms of this nation
  149. //
  150. // 2. when <int> recNo is given :
  151. // - return the firm recno in firm_array of the given recno.
  152. //
  153. static int tech_filter(int recNo)
  154. {
  155. int techCount=0;
  156. TechInfo* techInfo;
  157. for( int techId=tech_res.tech_count ; techId>0 ; techId-- )
  158. {
  159. techInfo = tech_res[techId];
  160. if( techInfo->is_nation_researching(info.viewing_nation_recno) ||
  161. techInfo->get_nation_tech_level(info.viewing_nation_recno) > 0 )
  162. {
  163. techCount++;
  164. }
  165. if( recNo && techCount==recNo )
  166. return techId;
  167. }
  168. err_when( recNo ); // the recNo is not found, it is out of range
  169. return techCount;
  170. }
  171. //----------- End of static function tech_filter -----------//
  172. //-------- Begin of static function god_filter --------//
  173. //
  174. // This function has dual purpose :
  175. //
  176. // 1. when <int> recNo is not given :
  177. // - return the total no. of firms of this nation
  178. //
  179. // 2. when <int> recNo is given :
  180. // - return the firm recno in firm_array of the given recno.
  181. //
  182. static int god_filter(int recNo)
  183. {
  184. int godCount=0, totalUnit=unit_array.size();
  185. Unit* unitPtr;
  186. for( int i=1 ; i<=totalUnit ; i++ )
  187. {
  188. if( unit_array.is_deleted(i) )
  189. continue;
  190. unitPtr = unit_array[i];
  191. if( unitPtr->nation_recno == info.viewing_nation_recno &&
  192. unit_res[ unitPtr->unit_id ]->unit_class == UNIT_CLASS_GOD )
  193. {
  194. godCount++;
  195. }
  196. if( recNo && godCount==recNo )
  197. return i;
  198. }
  199. err_when( recNo ); // the recNo is not found, it is out of range
  200. return godCount;
  201. }
  202. //----------- End of static function god_filter -----------//
  203. //-------- Begin of static function put_tech_rec --------//
  204. //
  205. static void put_tech_rec(int recNo, int x, int y, int refreshFlag)
  206. {
  207. int techId = tech_filter(recNo);
  208. TechInfo* techInfo = tech_res[techId];
  209. //---------- display bitmap ----------//
  210. x+=3;
  211. y+=3;
  212. vga_back.put_bitmap( x, y-2, techInfo->tech_small_icon() );
  213. //----------- display info ----------//
  214. y+=2;
  215. int curLevel = techInfo->get_nation_tech_level(info.viewing_nation_recno);
  216. font_san.put( x+28 , y, techInfo->tech_des() );
  217. if( curLevel > 0 )
  218. font_san.put( x+180, y, m.roman_number(curLevel) );
  219. //----- if the nation is researching this technology -----//
  220. int isResearching = techInfo->is_nation_researching(info.viewing_nation_recno);
  221. if( isResearching )
  222. {
  223. err_when( curLevel >= techInfo->max_tech_level );
  224. font_san.put( x+260, y, m.roman_number(curLevel+1) );
  225. font_san.put( x+480, y, isResearching ); //isResearching tells the no. of towers of science researching this technology
  226. //----- display the research progress bar -----//
  227. vga.d3_panel_down( x+320, y-2, x+440, y+14 );
  228. vga_back.indicator( x+321, y-1, x+439, y+13, techInfo->get_progress(info.viewing_nation_recno), (float)100, VGA_GRAY );
  229. }
  230. }
  231. //----------- End of static function put_tech_rec -----------//
  232. //-------- Begin of static function put_god_rec --------//
  233. //
  234. static void put_god_rec(int recNo, int x, int y, int refreshFlag)
  235. {
  236. UnitGod* unitGod = (UnitGod*) unit_array[ god_filter(recNo) ];
  237. err_when( unit_res[unitGod->unit_id]->unit_class != UNIT_CLASS_GOD );
  238. //----------- display info ----------//
  239. x+=3;
  240. y+=5;
  241. font_san.put( x, y, unit_res[unitGod->unit_id]->name );
  242. //--------- display hit points -----------//
  243. String str;
  244. str = (int) unitGod->hit_points;
  245. str += "/";
  246. str += unitGod->max_hit_points;
  247. font_san.put( x+300, y, str );
  248. }
  249. //----------- End of static function put_god_rec -----------//
  250. //-------- Begin of static function disp_scroll --------//
  251. //
  252. static void disp_scroll(int x, int y, int raceId)
  253. {
  254. char iconName[]="SCROLL-0";
  255. iconName[7] = race_res[raceId]->code[0];
  256. image_spict.put_back( x, y, iconName );
  257. }
  258. //----------- End of static function disp_scroll -----------//
  259. //-------- Begin of static function disp_owned_scroll --------//
  260. //
  261. static void disp_owned_scroll()
  262. {
  263. vga.d3_panel_down( SCROLL_X1, SCROLL_Y1, SCROLL_X2, SCROLL_Y2 );
  264. //------ count the number of acquired scrolls ------//
  265. Nation* nationPtr = nation_array[info.viewing_nation_recno];
  266. int scrollCount=0;
  267. int i;
  268. for( i=0 ; i<MAX_RACE ; i++ )
  269. {
  270. if( nationPtr->know_base_array[i] )
  271. scrollCount++;
  272. }
  273. //------- display words -------//
  274. if( scrollCount > 1 )
  275. font_san.put( SCROLL_X1+6, SCROLL_Y1+5, "Acquired Scrolls:" );
  276. else
  277. font_san.put( SCROLL_X1+6, SCROLL_Y1+5, "Acquired Scroll:" );
  278. //------- display scrolls ----------//
  279. int x=SCROLL_X1+6, y=SCROLL_Y1+18;
  280. for( i=0 ; i<MAX_RACE ; i++ )
  281. {
  282. if( !nationPtr->know_base_array[i] )
  283. continue;
  284. disp_scroll(x, y, i+1 );
  285. font_san.put( x+36, y+6, race_res[i+1]->name );
  286. x+=105;
  287. if( x+95 > SCROLL_X2 )
  288. {
  289. x = SCROLL_X1+6;
  290. y += 30;
  291. }
  292. }
  293. }
  294. //----------- End of static function disp_owned_scroll -----------//