OR_NAT.cpp 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098
  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_NAT.CPP
  21. //Description : Nation Report
  22. #include <stdlib.h>
  23. #include <KEY.h>
  24. #include <OCONFIG.h>
  25. #include <OVGA.h>
  26. #include <OFONT.h>
  27. #include <OSTR.h>
  28. #include <OGETA.h>
  29. #include <ODATE.h>
  30. #include <OMOUSE.h>
  31. #include <OIMGRES.h>
  32. #include <OVBROWIF.h>
  33. #include <OBUTTON.h>
  34. #include <OSYS.h>
  35. #include <ONATION.h>
  36. #include <OTALKRES.h>
  37. #include <OINFO.h>
  38. #include <OREMOTE.h>
  39. //------------- Define coordinations -----------//
  40. enum { REPORT_BROWSE_X1 = ZOOM_X1+6,
  41. REPORT_BROWSE_Y1 = ZOOM_Y1+6,
  42. REPORT_BROWSE_X2 = ZOOM_X2-6,
  43. REPORT_BROWSE_Y2 = REPORT_BROWSE_Y1+206,
  44. REPORT_BUTTON_X1 = ZOOM_X1+8,
  45. REPORT_BUTTON_Y1 = REPORT_BROWSE_Y2+6,
  46. REPORT_BUTTON_WIDTH = 135,
  47. REPORT_BUTTON_Y2 = REPORT_BUTTON_Y1+20,
  48. REPORT_BUTTON_X_SPACE = 130,
  49. REPORT_DET_X1 = ZOOM_X1+6,
  50. REPORT_DET_Y1 = REPORT_BUTTON_Y2+4,
  51. REPORT_DET_X2 = ZOOM_X2-6,
  52. REPORT_DET_Y2 = ZOOM_Y2-6,
  53. REPORT_TALK_Y2 = ZOOM_Y2-86, // use a shorter height for the diplomacy menu as it needs to let the player looks at the messages received.
  54. };
  55. //---------- Define report mode strings ---------//
  56. static char* report_mode_str_array[MAX_NATION_REPORT_MODE] =
  57. {
  58. "Information",
  59. "Diplomacy",
  60. "Chat",
  61. "Diplomatic Log",
  62. "Debug",
  63. };
  64. //---------- Define chat receiver str strings ---------//
  65. static char* chat_receiver_str_array[MAX_CHAT_RECEIVER_TYPE] =
  66. {
  67. "Send to the selected kingdom",
  68. "Send to all allied human controlled kingdoms",
  69. "Send to all human controlled kingdoms",
  70. };
  71. //----------- Define static variables ----------//
  72. static VBrowseIF browse_nation, browse_talk_msg;
  73. static ButtonGroup button_allow_attack(2);
  74. static ButtonGroup button_chat_receiver(MAX_CHAT_RECEIVER_TYPE);
  75. static int init_get_chat = 0;
  76. static GetA get_chat;
  77. //----------- Define static functions ----------//
  78. static void put_nation_rec(int recNo, int x, int y, int refreshFlag);
  79. static void put_talk_msg_rec(int recNo, int x, int y, int refreshFlag);
  80. static int nation_filter(int recNo=0);
  81. static void disp_button();
  82. static int detect_button();
  83. static void disp_detail(int refreshFlag);
  84. static void detect_detail();
  85. static void disp_nation_info();
  86. static void detect_nation_info();
  87. static void disp_debug_info();
  88. static void disp_nation_talk();
  89. static void detect_nation_talk();
  90. static void disp_nation_chat(int refreshFlag);
  91. static void detect_nation_chat();
  92. static void disp_talk_msg_sent(int refreshFlag);
  93. static int sort_talk_msg( const void *a, const void *b );
  94. //--------- Begin of function Info::disp_nation ---------//
  95. //
  96. // <int> refreshFlag - INFO_REPAINT - the user has just switched
  97. // to this report.
  98. // INFO_UPDATE - the report is already in this mode,
  99. // just keep displaying and updating.
  100. //
  101. void Info::disp_nation(int refreshFlag)
  102. {
  103. //--------- Create nation income and expenses browsers -------//
  104. int x=REPORT_BROWSE_X1+9, y=REPORT_BROWSE_Y1+4;
  105. vga_back.d3_panel_up(REPORT_BROWSE_X1, REPORT_BROWSE_Y1, REPORT_BROWSE_X2, REPORT_BROWSE_Y1+33 );
  106. font_san.put( x , y+7, "Kingdom" );
  107. font_san.put( x+185, y+7, "Reputation" );
  108. font_san.put( x+275, y+7, "Status" );
  109. #if(defined(SPANISH))
  110. font_san.put( x+335, y , "Allow" );
  111. font_san.put( x+335, y+13, "Attack" );
  112. font_san.put( x+395, y, "Acuerdo" );
  113. font_san.put( x+395, y+13, "Comerc." );
  114. font_san.put( x+468, y , "Cantidad" );
  115. font_san.put( x+468, y+13, "Comerciada" );
  116. #elif(defined(FRENCH))
  117. font_san.put( x+335, y , "Allow" );
  118. font_san.put( x+335, y+13, "Attack" );
  119. font_san.put( x+395, y, "Accord" );
  120. font_san.put( x+395, y+13, "Commercial" );
  121. font_san.put( x+473, y , "Montant" );
  122. font_san.put( x+473, y+13, "Commercial" );
  123. #elif(defined(GERMAN))
  124. font_san.put( x+345, y , "Allow" );
  125. font_san.put( x+343, y+13, "Attack" );
  126. font_san.put( x+405, y , "Handels-" );
  127. font_san.put( x+405, y+13, "Vertrag" );
  128. font_san.put( x+465, y , "Handels-" );
  129. font_san.put( x+465, y+13, "Betrag" );
  130. #else
  131. font_san.put( x+345, y , "Allow" );
  132. font_san.put( x+343, y+13, "Attack" );
  133. font_san.put( x+405, y , "Trade" );
  134. font_san.put( x+405, y+13, "Treaty" );
  135. font_san.put( x+465, y , "Trade" );
  136. font_san.put( x+465, y+13, "Amount" );
  137. #endif
  138. if( refreshFlag == INFO_REPAINT )
  139. {
  140. browse_nation.init( REPORT_BROWSE_X1, REPORT_BROWSE_Y1+35, REPORT_BROWSE_X2, REPORT_BROWSE_Y2,
  141. 0, 20, nation_filter(), put_nation_rec, 1 );
  142. browse_nation.open(browse_nation_recno);
  143. }
  144. else
  145. {
  146. browse_nation.paint();
  147. browse_nation.open(browse_nation_recno, nation_filter());
  148. }
  149. browse_nation_recno = browse_nation.recno();
  150. //------- disp report buttons --------//
  151. disp_button();
  152. //--------- display detail info --------//
  153. if( refreshFlag==INFO_REPAINT )
  154. {
  155. info.last_talk_nation_recno = 0;
  156. browse_talk_msg_recno = 1;
  157. }
  158. disp_detail(refreshFlag);
  159. }
  160. //----------- End of function Info::disp_nation -----------//
  161. //--------- Begin of function Info::detect_nation ---------//
  162. //
  163. void Info::detect_nation()
  164. {
  165. //------- detect nation browser ------//
  166. if( browse_nation.detect() )
  167. {
  168. browse_nation_recno = browse_nation.recno();
  169. return;
  170. }
  171. //------- detect report buttons --------//
  172. if( detect_button() )
  173. return;
  174. //--------- detect detail info -------//
  175. detect_detail();
  176. }
  177. //----------- End of function Info::detect_nation -----------//
  178. //--------- Begin of function Info::init_player_reply ---------//
  179. //
  180. // This function is called by TalkRes::player_reply() when the
  181. // player is going to reply to a diplomatic message from another
  182. // nation.
  183. //
  184. // <int> talkToNationRecno - recno of the nation the player is
  185. // going to talk to.
  186. //
  187. void Info::init_player_reply(int talkToNationRecno)
  188. {
  189. nation_report_mode = NATION_REPORT_TALK;
  190. info.player_reply_mode = 1;
  191. //--- go to the nation in the browser which the player is going to talk to ---//
  192. int nationCount = nation_filter();
  193. int i;
  194. for( i=1 ; i<=nationCount ; i++ )
  195. {
  196. if( nation_filter(i) == talkToNationRecno )
  197. {
  198. browse_nation_recno = i;
  199. break;
  200. }
  201. }
  202. err_when( i>nationCount );
  203. //----- if currently it's in nation report mode -----//
  204. if( sys.view_mode == MODE_NATION )
  205. browse_nation.refresh(browse_nation_recno);
  206. }
  207. //----------- End of function Info::init_player_reply -----------//
  208. //-------- Begin of static function nation_filter --------//
  209. //
  210. // This function has dual purpose :
  211. //
  212. // 1. when <int> recNo is not given :
  213. // - return the total no. of nations of this nation
  214. //
  215. // 2. when <int> recNo is given :
  216. // - return the nation recno in nation_array of the given recno.
  217. //
  218. static int nation_filter(int recNo)
  219. {
  220. int i, nationCount=0;
  221. Nation* viewingNation = nation_array[info.viewing_nation_recno];
  222. for( i=1 ; i<=nation_array.size() ; i++ )
  223. {
  224. if( nation_array.is_deleted(i) )
  225. continue;
  226. if( i==info.viewing_nation_recno ||
  227. viewingNation->get_relation(i)->has_contact )
  228. {
  229. nationCount++;
  230. }
  231. if( recNo && nationCount==recNo )
  232. return i;
  233. }
  234. err_when( recNo ); // the recNo is not found, it is out of range
  235. return nationCount;
  236. }
  237. //----------- End of static function nation_filter -----------//
  238. //-------- Begin of static function put_nation_rec --------//
  239. //
  240. static void put_nation_rec(int recNo, int x, int y, int refreshFlag)
  241. {
  242. int nationRecno = nation_filter(recNo);
  243. Nation* nationPtr = nation_array[nationRecno];
  244. Nation* viewingNation = nation_array[info.viewing_nation_recno];
  245. NationRelation* nationRelation = viewingNation->get_relation(nationRecno);
  246. x+=3;
  247. y+=5;
  248. nationPtr->disp_nation_color(x, y+1);
  249. font_san.put( x+20 , y, nationPtr->nation_name(), 0, x+215 );
  250. font_san.put( x+220, y, m.format((int) nationPtr->reputation) );
  251. //------- display relation parameters --------//
  252. if( nationRecno != info.viewing_nation_recno )
  253. {
  254. font_san.put( x+272, y, nationRelation->status_str() );
  255. font_san.put( x+355, y, nationRelation->should_attack ? (char*)"Yes" : (char*)"No" );
  256. font_san.put( x+412, y, nationRelation->trade_treaty ? (char*)"Yes" : (char*)"No" );
  257. font_san.put( x+465, y, m.format( (int) viewingNation->total_year_trade(nationRecno),2) );
  258. if( config.show_ai_info )
  259. {
  260. font_san.put( x+510, y, m.format(nationPtr->get_relation(info.viewing_nation_recno)->ai_relation_level) );
  261. font_san.put( x+180, y, m.format( (int) nationPtr->get_relation(info.viewing_nation_recno)->good_relation_duration_rating) );
  262. }
  263. }
  264. }
  265. //----------- End of static function put_nation_rec -----------//
  266. //--------- Begin of static function disp_button ---------//
  267. //
  268. static void disp_button()
  269. {
  270. int x=REPORT_BUTTON_X1;
  271. for( int i=1 ; i<=MAX_NATION_REPORT_MODE ; i++ )
  272. {
  273. if( i==NATION_REPORT_DEBUG )
  274. {
  275. if( remote.is_enable() ||
  276. ( !sys.debug_session && !sys.testing_session ) )
  277. {
  278. continue;
  279. }
  280. }
  281. else if( !sys.debug_session && i==NATION_REPORT_CHAT )
  282. {
  283. if( !remote.is_enable() )
  284. continue;
  285. }
  286. //-----------------------------------------//
  287. if( info.nation_report_mode == i )
  288. vga.d3_panel_down( x, REPORT_BUTTON_Y1, x+REPORT_BUTTON_WIDTH-1, REPORT_BUTTON_Y2 );
  289. else
  290. vga.d3_panel_up( x, REPORT_BUTTON_Y1, x+REPORT_BUTTON_WIDTH-1, REPORT_BUTTON_Y2 );
  291. font_san.center_put( x, REPORT_BUTTON_Y1, x+REPORT_BUTTON_WIDTH-1, REPORT_BUTTON_Y2, report_mode_str_array[i-1] );
  292. x+=REPORT_BUTTON_WIDTH;
  293. }
  294. }
  295. //----------- End of static function disp_button -----------//
  296. //--------- Begin of static function detect_button ---------//
  297. //
  298. static int detect_button()
  299. {
  300. int x=REPORT_BUTTON_X1;
  301. for( int i=1 ; i<=MAX_NATION_REPORT_MODE ; i++ )
  302. {
  303. if( i==NATION_REPORT_DEBUG )
  304. {
  305. if( remote.is_enable() ||
  306. ( !sys.debug_session && !sys.testing_session ) )
  307. {
  308. continue;
  309. }
  310. }
  311. else if( !sys.debug_session && i==NATION_REPORT_CHAT )
  312. {
  313. if( !remote.is_enable() )
  314. continue;
  315. }
  316. //-----------------------------------------//
  317. if( mouse.single_click( x, REPORT_BUTTON_Y1, x+REPORT_BUTTON_WIDTH-1, REPORT_BUTTON_Y2 ) )
  318. {
  319. info.nation_report_mode = i;
  320. return 1;
  321. }
  322. x+=REPORT_BUTTON_WIDTH;
  323. }
  324. return 0;
  325. }
  326. //----------- End of static function detect_button -----------//
  327. //--------- Begin of static function disp_detail ---------//
  328. //
  329. static void disp_detail(int refreshFlag)
  330. {
  331. if( browse_nation.recno()==0 ) // no records in the list
  332. return;
  333. switch( info.nation_report_mode )
  334. {
  335. case NATION_REPORT_INFO:
  336. disp_nation_info();
  337. break;
  338. case NATION_REPORT_TALK:
  339. disp_nation_talk();
  340. break;
  341. case NATION_REPORT_CHAT:
  342. disp_nation_chat(refreshFlag);
  343. break;
  344. case NATION_REPORT_TALK_LOG:
  345. disp_talk_msg_sent(refreshFlag);
  346. break;
  347. case NATION_REPORT_DEBUG:
  348. disp_debug_info();
  349. break;
  350. }
  351. }
  352. //----------- End of static function disp_detail -----------//
  353. //--------- Begin of static function detect_detail ---------//
  354. //
  355. static void detect_detail()
  356. {
  357. switch( info.nation_report_mode )
  358. {
  359. case NATION_REPORT_INFO:
  360. detect_nation_info();
  361. break;
  362. case NATION_REPORT_TALK:
  363. detect_nation_talk();
  364. break;
  365. case NATION_REPORT_CHAT:
  366. detect_nation_chat();
  367. break;
  368. case NATION_REPORT_TALK_LOG:
  369. if( browse_talk_msg.detect() )
  370. info.browse_talk_msg_recno = browse_talk_msg.recno();
  371. break;
  372. }
  373. }
  374. //----------- End of static function detect_detail -----------//
  375. //--------- Begin of static function disp_nation_info ---------//
  376. //
  377. static void disp_nation_info()
  378. {
  379. vga.d3_panel_down( REPORT_DET_X1, REPORT_DET_Y1, REPORT_DET_X2, REPORT_DET_Y2 );
  380. //----------- display info ------------//
  381. int nationRecno = nation_filter(browse_nation.recno());
  382. Nation* nationPtr = nation_array[nationRecno];
  383. Nation* viewingNation = nation_array[info.viewing_nation_recno];
  384. NationRelation* nationRelation = viewingNation->get_relation(nationRecno);
  385. int x1=REPORT_DET_X1+6, x2=REPORT_DET_X1+340, x3=REPORT_DET_X2-10;
  386. int y=REPORT_DET_Y1+6;
  387. //-------- display economic data ----------//
  388. String str;
  389. if( nationRecno == info.viewing_nation_recno )
  390. {
  391. font_san.put_field( x1, y, "Your Food", x2, nationPtr->food_str() );
  392. str = "$";
  393. str += nationPtr->cash_str();
  394. font_san.put_field( x1, y+=16, "Your Treasure", x2, str );
  395. font_san.field( x1, y+=16, "Your Continuous Peace Time", x2, nationPtr->peace_duration_str(), x3, INFO_REPAINT, "PEACE" );
  396. }
  397. else
  398. {
  399. str = translate.process("Your Yearly Import from ");
  400. str += nationPtr->nation_name();
  401. font_san.field( x1, y , str, x2, (int) viewingNation->get_relation(nationRecno)->import_365days(IMPORT_TOTAL), 2, x3, INFO_REPAINT, "IMPORT" );
  402. str = translate.process("Your Yearly Export to ");
  403. str += nationPtr->nation_name();
  404. font_san.field( x1, y+=16, str, x2, (int) nationPtr->get_relation(info.viewing_nation_recno)->import_365days(IMPORT_TOTAL), 2, x3, INFO_REPAINT, "EXPORT" );
  405. str = translate.process("Continuous Peace Time of ");
  406. str += nationPtr->nation_name();
  407. font_san.field( x1, y+=16, str, x2, nationPtr->peace_duration_str(), x3, INFO_REPAINT, "PEACE" );
  408. //--------- duration of current status ----------//
  409. #if(defined(SPANISH))
  410. str = "Duración del estado de ";
  411. str += translate.process(nationRelation->status_str());
  412. #elif(defined(FRENCH))
  413. str = "Duration of ";
  414. str += nationRelation->status_str();
  415. str += " Status";
  416. str = translate.process(str);
  417. #else
  418. // GERMAN and US
  419. str = translate.process("Duration of ");
  420. str += translate.process(nationRelation->status_str());
  421. str += " Status";
  422. #endif
  423. font_san.field( x1, y+=16, str, x2, nationRelation->status_duration_str(), x3, INFO_REPAINT, "STATTIME" );
  424. //------- display the allow_attack field --------//
  425. #if(defined(SPANISH))
  426. // str = "Permitir que tus Unidades ataquen al ";
  427. str = "Permitir atacar al ";
  428. str += nationPtr->nation_name();
  429. #elif(defined(FRENCH))
  430. str = "Autoriser attaque contre le ";
  431. str += nationPtr->nation_name();
  432. #elif(defined(GERMAN))
  433. str = "Angriffe auf ";
  434. str += nationPtr->nation_name();
  435. str += " erlauben";
  436. #else
  437. str = "Allow Your Units to Attack ";
  438. str += nationPtr->nation_name();
  439. #endif
  440. font_san.field( x1, y+=16, str, x2, "", x3, INFO_REPAINT, "ALLOWATK" );
  441. button_allow_attack[1].create_text( x2+6 , y, x2+50 , y+15, "Yes" );
  442. button_allow_attack[0].create_text( x2+54, y, x2+100, y+15, "No" );
  443. button_allow_attack.paint( viewingNation->get_relation(nationRecno)->should_attack );
  444. //---- if this nation is our ally, display its cash and food ----//
  445. if( viewingNation->get_relation(nationRecno)->status == NATION_ALLIANCE )
  446. {
  447. #if(defined(SPANISH))
  448. str = "Tesoro del ";
  449. str += nationPtr->nation_name();
  450. #elif(defined(FRENCH))
  451. str = "Trésor du ";
  452. str += nationPtr->nation_name();
  453. #else
  454. // GERMAN and US
  455. str = nationPtr->nation_name();
  456. str += " 's Treasure";
  457. #endif
  458. font_san.field( x1, y+=16, str, x2, nationPtr->cash, 2, x3, INFO_REPAINT );
  459. #if(defined(SPANISH))
  460. str = "Alimentos del ";
  461. str += nationPtr->nation_name();
  462. #elif(defined(FRENCH))
  463. str = "Réserves de nourriture du ";
  464. str += nationPtr->nation_name();
  465. #else
  466. // GERMAN and US
  467. str = nationPtr->nation_name();
  468. str += " 's Food";
  469. #endif
  470. font_san.field( x1, y+=16, str, x2, nationPtr->food, 2, x3, INFO_REPAINT );
  471. }
  472. }
  473. y+=26;
  474. //----- display its relation status with other nations -----//
  475. if( info.viewing_nation_recno != nationRecno )
  476. {
  477. String str;
  478. #if(defined(SPANISH))
  479. str = "Estado Diplomático del ";
  480. str += nationPtr->nation_name();
  481. str += " con otros Reinos:";
  482. #elif(defined(FRENCH))
  483. str = "Relations diplomatiques de ";
  484. str += nationPtr->nation_name();
  485. str += " avec les autres royaumes:";
  486. #else
  487. // GERMAN and US
  488. str = nationPtr->nation_name();
  489. str += "'s ";
  490. str += translate.process( "Diplomatic Status with Other Kingdoms:" );
  491. #endif
  492. nationPtr->disp_nation_color(x1, y+1);
  493. font_san.put(x1+20, y, str);
  494. y+=20;
  495. for( int i=1 ; i<=nation_array.size() ; i++ )
  496. {
  497. if( nation_array.is_deleted(i) ||
  498. i == nationRecno ||
  499. i == info.viewing_nation_recno )
  500. {
  501. continue;
  502. }
  503. nation_array[i]->disp_nation_color(x1, y+1);
  504. font_san.put( x1+20, y, nation_array[i]->nation_name() );
  505. font_san.put( x1+240, y, nationPtr->get_relation(i)->status_str() );
  506. if( nationPtr->get_relation(i)->trade_treaty )
  507. {
  508. font_san.put( x1+330, y, "Trade Treaty" );
  509. #if(defined(FRENCH))
  510. font_san.put( x1+460, y, m.format((int)nationPtr->total_year_trade(i),2) );
  511. #else
  512. // German and US
  513. font_san.put( x1+450, y, m.format((int)nationPtr->total_year_trade(i),2) );
  514. #endif
  515. }
  516. if( config.show_ai_info )
  517. {
  518. font_san.put( x1+500, y, nationPtr->get_relation(i)->ai_relation_level );
  519. font_san.put( x1+530, y, (int) nationPtr->get_relation(i)->good_relation_duration_rating );
  520. }
  521. y+=16;
  522. }
  523. }
  524. }
  525. //----------- End of static function disp_nation_info -----------//
  526. //--------- Begin of static function detect_nation_info ---------//
  527. //
  528. static void detect_nation_info()
  529. {
  530. int nationRecno = nation_filter(browse_nation.recno());
  531. Nation* viewingNation = nation_array[info.viewing_nation_recno];
  532. if( button_allow_attack.detect() >= 0 )
  533. viewingNation->set_relation_should_attack(nationRecno, button_allow_attack.button_pressed, COMMAND_PLAYER);
  534. }
  535. //----------- End of static function detect_nation_info -----------//
  536. //--------- Begin of static function disp_debug_info ---------//
  537. //
  538. static void disp_debug_info()
  539. {
  540. vga.d3_panel_down( REPORT_DET_X1, REPORT_DET_Y1, REPORT_DET_X2, REPORT_DET_Y2 );
  541. //----------- display info ------------//
  542. int nationRecno = nation_filter(browse_nation.recno());
  543. Nation* nationPtr = nation_array[nationRecno];
  544. int x1=REPORT_DET_X1+6, x2=REPORT_DET_X1+160;
  545. int y=REPORT_DET_Y1+6;
  546. int refreshFlag = INFO_REPAINT;
  547. //------------ display AI info ----------//
  548. font_san.put_field( x1, y , "Food ", x2, nationPtr->food_str() );
  549. font_san.put_field( x1, y+=16, "Treasure", x2, nationPtr->cash_str() );
  550. font_san.put_field( x1, y+=16, "ai_capture_enemy_town_recno", x2, nationPtr->ai_capture_enemy_town_recno, 1 );
  551. font_san.put_field( x1, y+=16, "Surplus supply rating", x2, nationPtr->surplus_supply_rating() );
  552. y+=48;
  553. //--------- display AI preference ----------//
  554. x2 += 60;
  555. font_san.put_field( x1, y+=16, "Unit Chase Distance" , x2, nationPtr->pref_unit_chase_distance , 1 );
  556. font_san.put_field( x1, y+=16, "Military Development" , x2, nationPtr->pref_military_development , 1 );
  557. font_san.put_field( x1, y+=16, "Economic Development" , x2, nationPtr->pref_economic_development , 1 );
  558. font_san.put_field( x1, y+=16, "Increase Pop by Capture" , x2, nationPtr->pref_inc_pop_by_capture , 1 );
  559. font_san.put_field( x1, y+=16, "Increase Pop by Growth" , x2, nationPtr->pref_inc_pop_by_growth , 1 );
  560. font_san.put_field( x1, y+=16, "Peacefulness" , x2, nationPtr->pref_peacefulness , 1 );
  561. font_san.put_field( x1, y+=16, "Military Courage" , x2, nationPtr->pref_military_courage , 1 );
  562. font_san.put_field( x1, y+=16, "Territorial Cohesiveness", x2, nationPtr->pref_territorial_cohesiveness, 1 );
  563. font_san.put_field( x1, y+=16, "Trading Tendency" , x2, nationPtr->pref_trading_tendency , 1 );
  564. x1 += (REPORT_DET_X2-REPORT_DET_X1)/2;
  565. x2 += (REPORT_DET_X2-REPORT_DET_X1)/2;
  566. y=REPORT_DET_Y1+6;
  567. font_san.put_field( x1, y , "Allying Tendency" , x2, nationPtr->pref_allying_tendency , 1 );
  568. font_san.put_field( x1, y+=16, "Honesty" , x2, nationPtr->pref_honesty , 1 );
  569. font_san.put_field( x1, y+=16, "Town Harmony" , x2, nationPtr->pref_town_harmony , 1 );
  570. font_san.put_field( x1, y+=16, "Citizen Loyalty Concern" , x2, nationPtr->pref_loyalty_concern , 1 );
  571. font_san.put_field( x1, y+=16, "Forgiveness" , x2, nationPtr->pref_forgiveness , 1 );
  572. font_san.put_field( x1, y+=16, "Collect Tax Tendency" , x2, nationPtr->pref_collect_tax , 1 );
  573. font_san.put_field( x1, y+=16, "Build Inn Tendency" , x2, nationPtr->pref_hire_unit , 1 );
  574. font_san.put_field( x1, y+=16, "Use Weapon Tendency" , x2, nationPtr->pref_use_weapon , 1 );
  575. font_san.put_field( x1, y+=16, "Keep Generals Tendency" , x2, nationPtr->pref_keep_general , 1 );
  576. font_san.put_field( x1, y+=16, "Keep Skilled Units Tendency", x2, nationPtr->pref_keep_skilled_unit , 1 );
  577. font_san.put_field( x1, y+=16, "Attack Monster" , x2, nationPtr->pref_attack_monster , 1 );
  578. font_san.put_field( x1, y+=16, "Use Spies" , x2, nationPtr->pref_spy , 1 );
  579. font_san.put_field( x1, y+=16, "Use Counter Spies" , x2, nationPtr->pref_counter_spy , 1 );
  580. font_san.put_field( x1, y+=16, "Food Reserve" , x2, nationPtr->pref_food_reserve , 1 );
  581. font_san.put_field( x1, y+=16, "Cash Reserve" , x2, nationPtr->pref_cash_reserve , 1 );
  582. font_san.put_field( x1, y+=16, "Use Marine" , x2, nationPtr->pref_use_marine , 1 );
  583. }
  584. //----------- End of static function disp_debug_info -----------//
  585. //--------- Begin of static function disp_nation_talk ---------//
  586. //
  587. static void disp_nation_talk()
  588. {
  589. int nationRecno = nation_filter(info.browse_nation_recno);
  590. //----- if the selected nation is the viewing nation ----//
  591. if( nationRecno != info.viewing_nation_recno &&
  592. info.viewing_nation_recno == nation_array.player_recno )
  593. {
  594. vga.d3_panel_down( REPORT_DET_X1, REPORT_DET_Y1, REPORT_DET_X2, REPORT_TALK_Y2 );
  595. if( info.last_talk_nation_recno != nationRecno && !info.player_reply_mode )
  596. talk_res.init_conversion(nationRecno);
  597. info.player_reply_mode = 0;
  598. info.last_talk_nation_recno = nationRecno;
  599. talk_res.disp_talk();
  600. }
  601. }
  602. //----------- End of static function disp_nation_talk -----------//
  603. //--------- Begin of static function detect_nation_talk ---------//
  604. //
  605. static void detect_nation_talk()
  606. {
  607. int nationRecno = nation_filter(info.browse_nation_recno);
  608. //----- if the selected nation is the viewing nation ----//
  609. if( nationRecno != info.viewing_nation_recno &&
  610. info.viewing_nation_recno == nation_array.player_recno )
  611. {
  612. talk_res.detect_talk();
  613. }
  614. }
  615. //----------- End of static function detect_nation_talk -----------//
  616. //--------- Begin of static function disp_talk_msg_sent ---------//
  617. //
  618. static void disp_talk_msg_sent(int refreshFlag)
  619. {
  620. //--- filter out talk messages sent by this nation and sort them by date ---//
  621. TalkMsg* talkMsg;
  622. TalkMsgDisp talkMsgDisp;
  623. static short lastNationRecno=0;
  624. int nationRecno = nation_filter(info.browse_nation_recno);
  625. if( lastNationRecno != nationRecno )
  626. {
  627. info.browse_talk_msg_recno = 1; // reset the browser recno of the viewing nation has been changed
  628. lastNationRecno = nationRecno;
  629. }
  630. //--------------------------------------------//
  631. info.talk_msg_disp_array.zap();
  632. for( short i=1 ; i<=talk_res.talk_msg_count() ; i++ )
  633. {
  634. if( talk_res.is_talk_msg_deleted(i) )
  635. continue;
  636. talkMsg = talk_res.get_talk_msg(i);
  637. if( !talkMsg->is_valid_to_disp() ) // don't link it out, otherwise it may cause multiplayer sync problem.
  638. continue;
  639. if( talkMsg->from_nation_recno == nationRecno ||
  640. talkMsg->to_nation_recno == nationRecno )
  641. {
  642. if( talkMsg->from_nation_recno == info.viewing_nation_recno ||
  643. talkMsg->to_nation_recno == info.viewing_nation_recno )
  644. {
  645. if( !nation_array.is_deleted(talkMsg->from_nation_recno) &&
  646. !nation_array.is_deleted(talkMsg->to_nation_recno) )
  647. {
  648. talkMsgDisp.recno = i;
  649. talkMsgDisp.date = talkMsg->date;
  650. talkMsgDisp.is_reply = 0;
  651. info.talk_msg_disp_array.linkin(&talkMsgDisp);
  652. if( talkMsg->reply_date )
  653. {
  654. talkMsgDisp.recno = i;
  655. talkMsgDisp.date = talkMsg->reply_date;
  656. talkMsgDisp.is_reply = 1;
  657. info.talk_msg_disp_array.linkin(&talkMsgDisp);
  658. }
  659. }
  660. }
  661. }
  662. }
  663. if( info.talk_msg_disp_array.size() > 0 )
  664. info.talk_msg_disp_array.quick_sort(sort_talk_msg);
  665. //----- display a browser of the talk msg sent -----//
  666. if( refreshFlag == INFO_REPAINT || !browse_talk_msg.init_flag )
  667. {
  668. browse_talk_msg.init( REPORT_DET_X1, REPORT_DET_Y1, REPORT_DET_X2, REPORT_DET_Y2,
  669. 0, 30, info.talk_msg_disp_array.size(), put_talk_msg_rec, 1 );
  670. browse_talk_msg.open(info.browse_talk_msg_recno);
  671. }
  672. else
  673. {
  674. browse_talk_msg.paint();
  675. browse_talk_msg.open(info.browse_talk_msg_recno, info.talk_msg_disp_array.size());
  676. }
  677. info.browse_talk_msg_recno = browse_talk_msg.recno();
  678. }
  679. //----------- End of static function disp_talk_msg_sent -----------//
  680. //------ Begin of function sort_talk_msg ------//
  681. //
  682. static int sort_talk_msg( const void *a, const void *b )
  683. {
  684. if( ((TalkMsgDisp*)b)->recno == ((TalkMsgDisp*)a)->recno )
  685. return ((TalkMsgDisp*)b)->is_reply ? 1 : -1;
  686. return ((TalkMsgDisp*)b)->date - ((TalkMsgDisp*)a)->date;
  687. }
  688. //------- End of function sort_talk_msg ------//
  689. //-------- Begin of static function put_talk_msg_rec --------//
  690. //
  691. static void put_talk_msg_rec(int recNo, int x1, int y, int refreshFlag)
  692. {
  693. TalkMsgDisp* talkMsgDisp = (TalkMsgDisp*) info.talk_msg_disp_array.get(recNo);
  694. TalkMsg* talkMsg = talk_res.get_talk_msg(talkMsgDisp->recno);
  695. int x=x1, isTo;
  696. x+=3;
  697. y+=2;
  698. if( !talkMsgDisp->is_reply ) // if not a replying message
  699. isTo = talkMsg->from_nation_recno == info.viewing_nation_recno; // you send a message to a nation
  700. else
  701. isTo = talkMsg->from_nation_recno != info.viewing_nation_recno;
  702. //---------------------------------------//
  703. char* str1;
  704. if( isTo )
  705. str1 = translate.process("To");
  706. else
  707. str1 = translate.process("From");
  708. font_san.put( x , y, str1 );
  709. x += font_san.text_width(str1)+5;
  710. //---------------------------------------//
  711. if( talkMsg->from_nation_recno == info.viewing_nation_recno )
  712. nation_array[talkMsg->to_nation_recno]->disp_nation_color(x, y+2);
  713. else
  714. nation_array[talkMsg->from_nation_recno]->disp_nation_color(x, y+2);
  715. x+=18;
  716. String str;
  717. str = translate.process("on ");
  718. if( talkMsgDisp->is_reply )
  719. str += date.date_str(talkMsg->reply_date);
  720. else
  721. str += date.date_str(talkMsg->date);
  722. str += " :";
  723. font_san.put( x , y, str );
  724. font_san.put( x1, y+13, talkMsg->msg_str(info.viewing_nation_recno, talkMsgDisp->is_reply), 0, browse_talk_msg.ix2 );
  725. }
  726. //----------- End of static function put_talk_msg_rec -----------//
  727. //--------- Begin of static function disp_nation_chat ---------//
  728. //
  729. static void disp_nation_chat(int refreshFlag)
  730. {
  731. int nationRecno = nation_filter(info.browse_nation_recno);
  732. //----- if the selected nation is the viewing nation ----//
  733. if( !(sys.debug_session || nation_array[nationRecno]->nation_type == NATION_REMOTE &&
  734. info.viewing_nation_recno == nation_array.player_recno ) )
  735. {
  736. return;
  737. }
  738. //-------- display the chat get control -------//
  739. vga.d3_panel_down( REPORT_DET_X1, REPORT_DET_Y1, REPORT_DET_X2, REPORT_TALK_Y2 );
  740. font_san.put( REPORT_DET_X1+10, REPORT_DET_Y1+10,
  741. "Please enter your chat message and press <Enter> to send." );
  742. // ###### begin Gilbert 15/10 #######//
  743. if( !init_get_chat )
  744. {
  745. get_chat.init( REPORT_DET_X1+10, REPORT_DET_Y1+30, REPORT_DET_X2-10,
  746. info.player_chat_str, CHAT_STR_LEN, &font_san, 0, 0 );
  747. get_chat.clear();
  748. init_get_chat = 1;
  749. }
  750. // ###### end Gilbert 15/10 #######//
  751. int vgaUseBack = vga.use_back_buf;
  752. vga.use_back();
  753. get_chat.paint(1); // 1-paint cursor
  754. if( !vgaUseBack )
  755. vga.use_front();
  756. //-------- display receiver type buttons ---------//
  757. int y=REPORT_TALK_Y2-70;
  758. for( int i=1 ; i<=MAX_CHAT_RECEIVER_TYPE ; i++, y+=22 )
  759. {
  760. if( info.chat_receiver_type == i )
  761. vga.d3_panel_down( REPORT_DET_X1+10, y, REPORT_DET_X2-10, y+20 );
  762. else
  763. vga.d3_panel_up( REPORT_DET_X1+10, y, REPORT_DET_X2-10, y+20 );
  764. font_san.center_put( REPORT_DET_X1+10, y, REPORT_DET_X2-10, y+20, chat_receiver_str_array[i-1] );
  765. }
  766. }
  767. //----------- End of static function disp_nation_chat -----------//
  768. //--------- Begin of static function detect_nation_chat ---------//
  769. //
  770. static void detect_nation_chat()
  771. {
  772. int nationRecno = nation_filter(info.browse_nation_recno);
  773. //----- if the selected nation is the viewing nation ----//
  774. if( sys.debug_session || nation_array[nationRecno]->nation_type == NATION_REMOTE &&
  775. info.viewing_nation_recno == nation_array.player_recno )
  776. {
  777. // ###### begin Gilbert 15/10 #######//
  778. if( !init_get_chat )
  779. {
  780. get_chat.init( REPORT_DET_X1+10, REPORT_DET_Y1+30, REPORT_DET_X2-10,
  781. info.player_chat_str, CHAT_STR_LEN, &font_san, 0, 0 );
  782. get_chat.clear();
  783. init_get_chat = 1;
  784. }
  785. // ###### end Gilbert 15/10 #######//
  786. for( int i=0 ; i<5 ; i++ )
  787. {
  788. int keyCode = get_chat.detect();
  789. if( !keyCode )
  790. break;
  791. //---- press <Enter> to send the chat message ----//
  792. if( keyCode == KEY_RETURN && info.player_chat_str[0] != '\0')
  793. {
  794. if( remote.is_enable() )
  795. {
  796. // packet structure : <to nation recno> <from nation recno> <char[CHAT_STR_LEN+1]>
  797. short *shortPtr = (short *)remote.new_send_queue_msg(MSG_CHAT, 2*sizeof(short) + strlen(info.player_chat_str)+1 );
  798. switch( info.chat_receiver_type )
  799. {
  800. case 1: // selected
  801. shortPtr[0] = nationRecno;
  802. break;
  803. case 2: // all allies
  804. shortPtr[0] = -1;
  805. break;
  806. case 3: // all human
  807. shortPtr[0] = 0;
  808. break;
  809. }
  810. shortPtr[1] = info.viewing_nation_recno;
  811. strcpy(2*sizeof(short)+(char *)shortPtr, info.player_chat_str);
  812. }
  813. get_chat.clear();
  814. break;
  815. }
  816. mouse.get_event();
  817. }
  818. }
  819. //-------- detect receiver type buttons ---------//
  820. int y=REPORT_TALK_Y2-70;
  821. for( int i=1 ; i<=MAX_CHAT_RECEIVER_TYPE ; i++, y+=22 )
  822. {
  823. if( mouse.single_click( REPORT_DET_X1+10, y, REPORT_DET_X2-50, y+20 ) )
  824. {
  825. info.chat_receiver_type = i;
  826. return;
  827. }
  828. }
  829. }
  830. //----------- End of static function detect_nation_chat -----------//
  831. //------- Begin of function Info::player_reply_chat --------//
  832. //
  833. // <int> withNationRecno - player reply a chat message to this nation.
  834. //
  835. void Info::player_reply_chat(int withNationRecno)
  836. {
  837. nation_report_mode = NATION_REPORT_CHAT;
  838. //--- go to the nation in the browser which the player is going to talk to ---//
  839. int nationCount = nation_filter();
  840. int i;
  841. for( i=1 ; i<=nationCount ; i++ )
  842. {
  843. if( nation_filter(i) == withNationRecno )
  844. {
  845. browse_nation_recno = i;
  846. break;
  847. }
  848. }
  849. err_when( i>nationCount );
  850. sys.set_view_mode(MODE_NATION);
  851. }
  852. //-------- End of function Info::player_reply_chat ---------//