OTALKRES.cpp 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390
  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 : OTALKRES.CPP
  21. //Description : Object Talk
  22. #include <OMOUSE.h>
  23. #include <OSYS.h>
  24. #include <OVGA.h>
  25. #include <OINFO.h>
  26. #include <OFONT.h>
  27. #include <OTECHRES.h>
  28. #include <OGAMESET.h>
  29. #include <ONEWS.h>
  30. #include <ONATION.h>
  31. #include <OTALKRES.h>
  32. #include <OREMOTE.h>
  33. // #### begin Gilbert 9/10 ######//
  34. #include <OSE.h>
  35. // #### end Gilbert 9/10 ######//
  36. //---------- the subtitle area ----------//
  37. enum { TALK_X1 = ZOOM_X1+16,
  38. TALK_Y1 = ZOOM_Y1+252,
  39. TALK_X2 = ZOOM_X2-16,
  40. TALK_Y2 = ZOOM_Y2-86,
  41. };
  42. enum { TALK_LINE_HEIGHT = 18 };
  43. //------- define constant --------//
  44. #define MESSAGE_SENT_STR "The message has been sent."
  45. //------- define static vars -------//
  46. static String nation_name_str_array[MAX_NATION];
  47. //---------- Begin of function TalkRes::TalkRes -----------//
  48. //
  49. TalkRes::TalkRes() : talk_msg_array( sizeof(TalkMsg), 100 )
  50. {
  51. }
  52. //---------- End of function TalkRes::TalkRes -----------//
  53. //---------- Begin of function TalkRes::init -----------//
  54. //
  55. void TalkRes::init()
  56. {
  57. memset( this, 0, sizeof(TalkRes) - sizeof(talk_msg_array) );
  58. talk_msg_array.zap();
  59. }
  60. //---------- End of function TalkRes::init -----------//
  61. //---------- Begin of function TalkRes::deinit -----------//
  62. //
  63. void TalkRes::deinit()
  64. {
  65. }
  66. //---------- End of function TalkRes::deinit -----------//
  67. //------- Begin of function TalkRes::init_conversion --------//
  68. //
  69. // <int> toNationRecno - recno of the nation which the player
  70. // is going to talk to.
  71. //
  72. void TalkRes::init_conversion(int toNationRecno)
  73. {
  74. memset( &cur_talk_msg, 0, sizeof(TalkMsg) );
  75. cur_talk_msg.from_nation_recno = (char) nation_array.player_recno;
  76. cur_talk_msg.to_nation_recno = toNationRecno;
  77. reply_talk_msg_recno = 0;
  78. set_talk_choices();
  79. }
  80. //-------- End of function TalkRes::init_conversion ---------//
  81. //---- Begin of function TalkRes::set_talk_choices ------//
  82. //
  83. // Set the choices of the next talk.
  84. //
  85. // return : <int> 1 - choices are set
  86. // 0 - if there is no additional talk segment for this talk
  87. //
  88. int TalkRes::set_talk_choices()
  89. {
  90. //------------------------------------//
  91. Nation* playerNation = ~nation_array;
  92. talk_choice_count = 0;
  93. choice_question = NULL;
  94. choice_question_second_line = NULL;
  95. cur_choice_id = 0;
  96. //------------------------------------//
  97. int rc=0;
  98. memset( available_talk_id_array, 0, sizeof(available_talk_id_array) );
  99. switch( cur_talk_msg.talk_id )
  100. {
  101. //--- add the main option choices ---//
  102. case 0:
  103. add_main_choices();
  104. return 1;
  105. case TALK_PROPOSE_TRADE_TREATY:
  106. case TALK_PROPOSE_FRIENDLY_TREATY:
  107. case TALK_PROPOSE_ALLIANCE_TREATY:
  108. case TALK_END_TRADE_TREATY:
  109. case TALK_END_FRIENDLY_TREATY:
  110. case TALK_END_ALLIANCE_TREATY:
  111. case TALK_REQUEST_CEASE_WAR:
  112. case TALK_DECLARE_WAR:
  113. case TALK_REQUEST_MILITARY_AID:
  114. return 0;
  115. case TALK_REQUEST_TRADE_EMBARGO:
  116. rc = add_trade_embargo_choices();
  117. break;
  118. case TALK_REQUEST_DECLARE_WAR:
  119. rc = add_declare_war_choices();
  120. break;
  121. case TALK_REQUEST_BUY_FOOD:
  122. rc = add_buy_food_choices();
  123. break;
  124. case TALK_GIVE_TRIBUTE:
  125. case TALK_DEMAND_TRIBUTE:
  126. rc = add_tribute_choices();
  127. if( rc )
  128. choice_question = "How much tribute?"; // add the choice question here because we use the same function for both tribute and aid
  129. break;
  130. case TALK_GIVE_AID:
  131. case TALK_DEMAND_AID:
  132. rc = add_tribute_choices();
  133. if( rc )
  134. choice_question = "How much aid?";
  135. break;
  136. case TALK_GIVE_TECH:
  137. case TALK_DEMAND_TECH:
  138. rc = add_give_tech_choices();
  139. break;
  140. case TALK_REQUEST_SURRENDER:
  141. rc = add_request_surrender_choices();
  142. break;
  143. case TALK_SURRENDER:
  144. rc = add_surrender_choices();
  145. break;
  146. default:
  147. err_here();
  148. }
  149. if( rc )
  150. add_talk_choice( "Cancel.", 0 );
  151. return rc;
  152. }
  153. //----- End of function TalkRes::set_talk_choices -------//
  154. //---- Begin of function TalkRes::add_main_choices ------//
  155. //
  156. void TalkRes::add_main_choices()
  157. {
  158. static char* talkMsgArray[] =
  159. {
  160. "Propose a trade treaty.",
  161. "Propose a friendly treaty.",
  162. "Propose an alliance treaty.",
  163. "Terminate our trade treaty.",
  164. "Terminate our friendly treaty.",
  165. "Terminate our alliance treaty.",
  166. "Request immediate military aid.",
  167. "Request a trade embargo.",
  168. "Request a cease-fire.",
  169. "Request a declaration of war against a foe.",
  170. "Request to purchase food.",
  171. "Declare war.",
  172. "Offer to pay tribute.",
  173. "Demand tribute.",
  174. "Offer aid.",
  175. "Request aid.",
  176. "Offer to transfer technology.",
  177. "Request technology.",
  178. "Offer to purchase throne and unite kingdoms.",
  179. "Surrender.",
  180. };
  181. //-----------------------------------------//
  182. int rc;
  183. int relationStatus = (~nation_array)->get_relation_status(cur_talk_msg.to_nation_recno);
  184. for( int i=1 ; i<=MAX_TALK_TYPE ; i++ )
  185. {
  186. if( !can_send_msg(cur_talk_msg.to_nation_recno, nation_array.player_recno, i) )
  187. continue;
  188. rc=0;
  189. if( !rc )
  190. add_talk_choice( talkMsgArray[i-1], i );
  191. available_talk_id_array[i-1] = 1;
  192. }
  193. }
  194. //----- End of function TalkRes::add_main_choices -------//
  195. //---- Begin of function TalkRes::add_trade_embargo_choices ------//
  196. //
  197. int TalkRes::add_trade_embargo_choices()
  198. {
  199. if( cur_talk_msg.talk_para1 )
  200. return 0;
  201. choice_question = "Request an embargo on trade with which kingdom?";
  202. Nation* fromNation = nation_array[cur_talk_msg.from_nation_recno];
  203. Nation* toNation = nation_array[cur_talk_msg.to_nation_recno];
  204. for( int i=1 ; i<=nation_array.size() ; i++ )
  205. {
  206. if( nation_array.is_deleted(i) )
  207. continue;
  208. if( i==cur_talk_msg.from_nation_recno ||
  209. i==cur_talk_msg.to_nation_recno )
  210. {
  211. continue;
  212. }
  213. if( fromNation->get_relation(i)->trade_treaty==0 &&
  214. toNation->get_relation(i)->trade_treaty==1 )
  215. {
  216. //------ add color bar -------//
  217. char colorCodeStr[] = "0 ";
  218. colorCodeStr[0] = FIRST_NATION_COLOR_CODE_IN_TEXT + nation_array[i]->color_scheme_id;
  219. nation_name_str_array[i-1] = colorCodeStr;
  220. //------ add natino name ------//
  221. nation_name_str_array[i-1] += nation_array[i]->nation_name();
  222. //---- add talk choice string ------//
  223. add_talk_choice( nation_name_str_array[i-1], i );
  224. }
  225. }
  226. return 1;
  227. }
  228. //----- End of function TalkRes::add_trade_embargo_choices -------//
  229. //---- Begin of function TalkRes::add_declare_war_choices ------//
  230. //
  231. int TalkRes::add_declare_war_choices()
  232. {
  233. if( cur_talk_msg.talk_para1 )
  234. return 0;
  235. choice_question = "Declare war on which kingdom?";
  236. Nation* fromNation = nation_array[cur_talk_msg.from_nation_recno];
  237. Nation* toNation = nation_array[cur_talk_msg.to_nation_recno];
  238. for( int i=1 ; i<=nation_array.size() ; i++ )
  239. {
  240. if( nation_array.is_deleted(i) )
  241. continue;
  242. //--- can only ask another nation to declare war with a nation that is currently at war with our nation ---//
  243. if( fromNation->get_relation_status(i) == NATION_HOSTILE &&
  244. toNation->get_relation_status(i) != NATION_HOSTILE )
  245. {
  246. //------ add color bar -------//
  247. char colorCodeStr[] = "0 ";
  248. colorCodeStr[0] = FIRST_NATION_COLOR_CODE_IN_TEXT + nation_array[i]->color_scheme_id;
  249. nation_name_str_array[i-1] = colorCodeStr;
  250. //------ add natino name ------//
  251. nation_name_str_array[i-1] += nation_array[i]->nation_name();
  252. //---- add talk choice string ------//
  253. add_talk_choice( nation_name_str_array[i-1], i );
  254. }
  255. }
  256. return 1;
  257. }
  258. //----- End of function TalkRes::add_declare_war_choices -------//
  259. //---- Begin of function TalkRes::add_buy_food_choices ------//
  260. //
  261. int TalkRes::add_buy_food_choices()
  262. {
  263. #define MIN_FOOD_PURCHASE_PRICE 5
  264. if( !cur_talk_msg.talk_para1 )
  265. {
  266. choice_question = "How much food do you want to purchase?";
  267. static char* qtyStrArray[] = { "500.", "1000.", "2000.", "4000." };
  268. static short qtyArray[] = { 500, 1000, 2000, 4000 };
  269. for( int i=0 ; i<4 ; i++ )
  270. {
  271. if( (~nation_array)->cash >= qtyArray[i] * MIN_FOOD_PURCHASE_PRICE / 10 )
  272. add_talk_choice( qtyStrArray[i], qtyArray[i] );
  273. }
  274. return 1;
  275. }
  276. else if( !cur_talk_msg.talk_para2 )
  277. {
  278. choice_question = "How much do you offer for 10 units of food?";
  279. static char* priceStrArray[] = { "$5.", "$10.", "$15.", "$20." };
  280. static short priceArray[] = { 5, 10, 15, 20 };
  281. for( int i=0 ; i<4 ; i++ )
  282. {
  283. if( i==0 || (~nation_array)->cash >= cur_talk_msg.talk_para1 * priceArray[i] / 10 ) // i==0 to at least add one option
  284. add_talk_choice( priceStrArray[i], priceArray[i] );
  285. }
  286. return 1;
  287. }
  288. else
  289. return 0;
  290. }
  291. //----- End of function TalkRes::add_buy_food_choices -------//
  292. //---- Begin of function TalkRes::add_tribute_choices ------//
  293. //
  294. int TalkRes::add_tribute_choices()
  295. {
  296. if( cur_talk_msg.talk_para1 )
  297. return 0;
  298. static char* tributeStrArray[] = { "$500.", "$1000.", "$2000.", "$3000.", "$4000." };
  299. static short tributeAmtArray[] = { 500, 1000, 2000, 3000, 4000 };
  300. for( int i=0 ; i<5 ; i++ )
  301. {
  302. if( cur_talk_msg.talk_id == TALK_DEMAND_TRIBUTE || // when demand tribute, the amount can be sent to any
  303. cur_talk_msg.talk_id == TALK_DEMAND_AID ||
  304. (~nation_array)->cash >= tributeAmtArray[i] )
  305. {
  306. add_talk_choice( tributeStrArray[i], tributeAmtArray[i] );
  307. }
  308. }
  309. return 1;
  310. }
  311. //----- End of function TalkRes::add_tribute_choices -------//
  312. //---- Begin of function TalkRes::add_give_tech_choices ------//
  313. //
  314. int TalkRes::add_give_tech_choices()
  315. {
  316. int i, techNationRecno;
  317. if( cur_talk_msg.talk_id == TALK_GIVE_TECH )
  318. techNationRecno = cur_talk_msg.from_nation_recno;
  319. else // demand tech
  320. techNationRecno = cur_talk_msg.to_nation_recno;
  321. if( !cur_talk_msg.talk_para1 )
  322. {
  323. choice_question = "Which technology?";
  324. for( i=1 ; i<=tech_res.tech_count ; i++ )
  325. {
  326. if( tech_res[i]->get_nation_tech_level(techNationRecno) > 0 )
  327. {
  328. add_talk_choice( tech_res[i]->tech_des(), i );
  329. }
  330. }
  331. return 1;
  332. }
  333. else if( !cur_talk_msg.talk_para2 && cur_talk_msg.talk_id == TALK_GIVE_TECH )
  334. {
  335. TechInfo* techInfo = tech_res[cur_talk_msg.talk_para1];
  336. if( techInfo->max_tech_level==1 ) // this tech only has one level
  337. return 0;
  338. choice_question = "Which version?";
  339. int nationLevel = techInfo->get_nation_tech_level(techNationRecno);
  340. err_when( nationLevel<1 || nationLevel>3 );
  341. static char* verStrArray[] = { "Mark I", "Mark II", "Mark III" };
  342. for( i=1 ; i<=min(3, nationLevel) ; i++ )
  343. add_talk_choice( verStrArray[i-1], i );
  344. return 1;
  345. }
  346. else
  347. return 0;
  348. }
  349. //----- End of function TalkRes::add_give_tech_choices -------//
  350. //---- Begin of function TalkRes::add_request_surrender_choices ------//
  351. //
  352. int TalkRes::add_request_surrender_choices()
  353. {
  354. if( cur_talk_msg.talk_para1 )
  355. return 0;
  356. choice_question = "How much do you offer?";
  357. static char* strArray[] = { "$5000.", "$7500.", "$10000.",
  358. "$15000.", "$20000.", "$30000.", "$40000.", "$50000." };
  359. static int amtArray[] = { 5000, 7500, 10000, 15000, 20000, 30000, 40000, 50000 };
  360. for( int i=0 ; i<8 ; i++ )
  361. {
  362. if( (~nation_array)->cash >= amtArray[i] )
  363. {
  364. add_talk_choice( strArray[i], amtArray[i]/10 ); // divided by 10 to cope with the limit of <short>
  365. }
  366. }
  367. return 1;
  368. }
  369. //----- End of function TalkRes::add_request_surrender_choices -------//
  370. //---- Begin of function TalkRes::add_surrender_choices ------//
  371. //
  372. int TalkRes::add_surrender_choices()
  373. {
  374. if( cur_talk_msg.talk_para1 )
  375. return 0;
  376. static String str;
  377. #if(defined(GERMAN))
  378. str = "Wollen Sie wirklich vor ";
  379. str += nation_array[cur_talk_msg.to_nation_recno]->nation_name();
  380. str += " kapitulieren?";
  381. #else
  382. // SPANISH, FRENCH and US
  383. str = translate.process("Do you really want to Surrender to ");
  384. str += nation_array[cur_talk_msg.to_nation_recno]->nation_name();
  385. str += "?";
  386. #endif
  387. choice_question = str;
  388. add_talk_choice( "Confirm.", 1 );
  389. return 1;
  390. }
  391. //----- End of function TalkRes::add_surrender_choices -------//
  392. //------- Begin of function TalkRes::can_send_any_msg --------//
  393. //
  394. int TalkRes::can_send_any_msg(int toNationRecno, int fromNationRecno)
  395. {
  396. return wait_msg_count(toNationRecno, fromNationRecno) < MAX_WAIT_MSG_PER_NATION;
  397. }
  398. //-------- End of function TalkRes::can_send_any_msg ---------//
  399. //------- Begin of function TalkRes::can_send_msg --------//
  400. //
  401. // return whether one specific nation can send a specific message
  402. // to another specific nation.
  403. //
  404. int TalkRes::can_send_msg(int toNationRecno, int fromNationRecno, int talkId)
  405. {
  406. Nation* fromNation = nation_array[fromNationRecno];
  407. Nation* toNation = nation_array[toNationRecno];
  408. NationRelation *nationRelation = fromNation->get_relation(toNationRecno);
  409. int relationStatus = nationRelation->status;
  410. switch( talkId )
  411. {
  412. case TALK_PROPOSE_TRADE_TREATY:
  413. return relationStatus !=NATION_ALLIANCE && // allied nations are oblied to trade with each other
  414. relationStatus !=NATION_HOSTILE &&
  415. !toNation->get_relation(fromNationRecno)->trade_treaty;
  416. case TALK_PROPOSE_FRIENDLY_TREATY:
  417. return relationStatus==NATION_TENSE ||
  418. relationStatus==NATION_NEUTRAL;
  419. case TALK_PROPOSE_ALLIANCE_TREATY:
  420. return relationStatus==NATION_FRIENDLY ||
  421. relationStatus==NATION_NEUTRAL;
  422. case TALK_END_TRADE_TREATY:
  423. return relationStatus !=NATION_ALLIANCE && // allied nations are oblied to trade with each other
  424. toNation->get_relation(fromNationRecno)->trade_treaty;
  425. case TALK_END_FRIENDLY_TREATY:
  426. return relationStatus==NATION_FRIENDLY;
  427. case TALK_END_ALLIANCE_TREATY:
  428. return relationStatus==NATION_ALLIANCE;
  429. case TALK_REQUEST_MILITARY_AID:
  430. return fromNation->is_at_war() &&
  431. (relationStatus==NATION_FRIENDLY ||
  432. relationStatus==NATION_ALLIANCE);
  433. case TALK_REQUEST_TRADE_EMBARGO:
  434. return relationStatus==NATION_FRIENDLY ||
  435. relationStatus==NATION_ALLIANCE;
  436. case TALK_REQUEST_CEASE_WAR:
  437. return relationStatus==NATION_HOSTILE;
  438. case TALK_REQUEST_DECLARE_WAR: // can only request an allied nation to declare war with another nation
  439. {
  440. if( relationStatus != NATION_ALLIANCE )
  441. return 0;
  442. //--- see if this nation has an enemy right now ---//
  443. for( int i=nation_array.size() ; i>0 ; i-- )
  444. {
  445. if( nation_array.is_deleted(i) )
  446. continue;
  447. if( fromNation->get_relation(i)->status == NATION_HOSTILE )
  448. return 1;
  449. }
  450. return 0;
  451. }
  452. case TALK_REQUEST_BUY_FOOD:
  453. return relationStatus != NATION_HOSTILE;
  454. case TALK_DECLARE_WAR:
  455. return relationStatus != NATION_ALLIANCE &&
  456. relationStatus != NATION_FRIENDLY &&
  457. relationStatus != NATION_HOSTILE;
  458. case TALK_GIVE_TRIBUTE:
  459. case TALK_DEMAND_TRIBUTE:
  460. return relationStatus <= NATION_NEUTRAL;
  461. case TALK_GIVE_AID:
  462. case TALK_DEMAND_AID:
  463. return relationStatus >= NATION_FRIENDLY;
  464. case TALK_GIVE_TECH:
  465. return fromNation->total_tech_level() > 0;
  466. case TALK_DEMAND_TECH:
  467. return toNation->total_tech_level() > 0;
  468. case TALK_REQUEST_SURRENDER:
  469. return 1;
  470. case TALK_SURRENDER:
  471. return 1;
  472. }
  473. return 0;
  474. }
  475. //-------- End of function TalkRes::can_send_msg ---------//
  476. //------- Begin of function TalkRes::add_talk_choice --------//
  477. //
  478. void TalkRes::add_talk_choice(char* talkStr, int talkPara)
  479. {
  480. err_when( talk_choice_count >= MAX_TALK_CHOICE );
  481. talk_choice_count++;
  482. talk_choice_array[talk_choice_count-1].str = talkStr;
  483. talk_choice_array[talk_choice_count-1].para = talkPara;
  484. }
  485. //-------- End of function TalkRes::add_talk_choice ---------//
  486. //------- Begin of function TalkRes::ai_send_talk_msg --------//
  487. //
  488. // <int> toNationRecno - the nation which this message is being sent to
  489. // <int> fromNationRecno - the nation which this message is from
  490. // <int> talkId - id. of the talk
  491. // [int] talkPara1 - talk para 1
  492. // [int] talkPara2 - talk para 2
  493. // [int] forceSend - if 1, then should_diplomacy_retry() won't
  494. // be checked. (default: 0)
  495. //
  496. int TalkRes::ai_send_talk_msg(int toNationRecno, int fromNationRecno, int talkId, int talkPara1, int talkPara2, int forceSend)
  497. {
  498. Nation* fromNation = nation_array[fromNationRecno];
  499. if( !fromNation->is_ai() )
  500. return 0;
  501. //--- first check again if the nation should send the message now ---//
  502. if( !forceSend )
  503. {
  504. if( !fromNation->should_diplomacy_retry(talkId, toNationRecno) )
  505. return 0;
  506. }
  507. //-------- avoid send opposite message too soon ----//
  508. int oppTalkId=0;
  509. switch( talkId )
  510. {
  511. case TALK_PROPOSE_ALLIANCE_TREATY:
  512. oppTalkId = TALK_END_FRIENDLY_TREATY;
  513. break;
  514. case TALK_GIVE_TRIBUTE:
  515. oppTalkId = TALK_DEMAND_TRIBUTE;
  516. break;
  517. case TALK_DEMAND_TRIBUTE:
  518. oppTalkId = TALK_GIVE_TRIBUTE;
  519. break;
  520. case TALK_GIVE_AID:
  521. oppTalkId = TALK_DEMAND_AID;
  522. break;
  523. case TALK_DEMAND_AID:
  524. oppTalkId = TALK_GIVE_AID;
  525. break;
  526. case TALK_GIVE_TECH:
  527. oppTalkId = TALK_DEMAND_TECH;
  528. break;
  529. case TALK_DEMAND_TECH:
  530. oppTalkId = TALK_GIVE_TECH;
  531. break;
  532. }
  533. if( oppTalkId )
  534. {
  535. fromNation->get_relation(toNationRecno)->
  536. last_talk_reject_date_array[oppTalkId-1] = info.game_date;
  537. }
  538. //------------------------------------------//
  539. TalkMsg talkMsg;
  540. memset(&talkMsg, 0, sizeof(TalkMsg));
  541. talkMsg.to_nation_recno = toNationRecno;
  542. talkMsg.from_nation_recno = fromNationRecno;
  543. talkMsg.talk_id = talkId;
  544. talkMsg.talk_para1 = talkPara1;
  545. talkMsg.talk_para2 = talkPara2;
  546. err_when( !nation_array[fromNationRecno]->is_ai() );
  547. send_talk_msg( &talkMsg, COMMAND_AI );
  548. return 1;
  549. }
  550. //-------- End of function TalkRes::ai_send_talk_msg ---------//
  551. //------- Begin of function TalkRes::send_talk_msg --------//
  552. //
  553. // Now records in talk_msg_array cannot be deleted as
  554. // news_array.diplomacy() use recno to refer to talk_msg_array.
  555. //
  556. void TalkRes::send_talk_msg(TalkMsg* talkMsgPtr, char remoteAction)
  557. {
  558. //-------- send multiplayer -----------//
  559. if( !remoteAction && remote.is_enable() )
  560. {
  561. // packet strcture : <TalkMsg>
  562. char* dataPtr = remote.new_send_queue_msg(MSG_SEND_TALK_MSG, sizeof(TalkMsg) );
  563. memcpy( dataPtr, talkMsgPtr, sizeof(TalkMsg) );
  564. return;
  565. }
  566. //------ the TalkMsg::reply_type ------//
  567. if( talkMsgPtr->is_reply_needed() )
  568. talkMsgPtr->reply_type = REPLY_WAITING;
  569. else
  570. talkMsgPtr->reply_type = REPLY_NOT_NEEDED;
  571. //-- If this is an AI message check if this message has already been sent --//
  572. if( nation_array[talkMsgPtr->from_nation_recno]->nation_type == NATION_AI )
  573. {
  574. if( talkMsgPtr->reply_type == REPLY_WAITING ) // for messages that do not need a reply, duplication in the message log is allowed.
  575. {
  576. if( is_talk_msg_exist(talkMsgPtr, 0) ) // 0-don't check talk_para1 & talk_para2
  577. return;
  578. }
  579. }
  580. //--- in a multiplayer game, when the msg comes back from the network, can_send_msg might be different, so we have to check it again ---//
  581. if( !can_send_msg( talkMsgPtr->to_nation_recno, talkMsgPtr->from_nation_recno, talkMsgPtr->talk_id ) )
  582. return;
  583. //-------- send the message now ---------//
  584. send_talk_msg_now(talkMsgPtr);
  585. //---- if it's a notification message ----//
  586. if( talkMsgPtr->reply_type == REPLY_NOT_NEEDED )
  587. talkMsgPtr->process_accepted_reply();
  588. }
  589. //-------- End of function TalkRes::send_talk_msg ---------//
  590. //------- Begin of function TalkRes::send_talk_msg_now --------//
  591. //
  592. void TalkRes::send_talk_msg_now(TalkMsg* talkMsgPtr)
  593. {
  594. //--------- add the message ------------//
  595. Nation* toNation = nation_array[talkMsgPtr->to_nation_recno];
  596. talkMsgPtr->date = info.game_date;
  597. talkMsgPtr->relation_status = toNation->get_relation_status(talkMsgPtr->from_nation_recno);
  598. talk_msg_array.linkin( talkMsgPtr );
  599. err_when( nation_array.is_deleted(talkMsgPtr->from_nation_recno) );
  600. err_when( nation_array.is_deleted(talkMsgPtr->to_nation_recno) );
  601. //--------------------------------------//
  602. switch(toNation->nation_type)
  603. {
  604. case NATION_OWN: // can be from both AI or a remote player
  605. news_array.diplomacy( talk_msg_array.recno() );
  606. // ###### begin Gilbert 9/10 ########//
  607. // sound effect
  608. se_ctrl.immediate_sound(talkMsgPtr->talk_id==TALK_DECLARE_WAR ? (char*)"DECL_WAR":(char*)"GONG");
  609. // ###### end Gilbert 9/10 ########//
  610. break;
  611. case NATION_AI:
  612. if( talkMsgPtr->reply_type == REPLY_WAITING )
  613. {
  614. //-- put the message in the receiver's actin queue --//
  615. toNation->add_action( 0, 0, 0, 0, ACTION_AI_PROCESS_TALK_MSG, talk_msg_array.recno() );
  616. }
  617. else if( talkMsgPtr->reply_type == REPLY_NOT_NEEDED )
  618. {
  619. //--- notify the receiver immediately ---//
  620. toNation->notify_talk_msg( talkMsgPtr );
  621. }
  622. else
  623. err_here();
  624. break;
  625. case NATION_REMOTE: // do nothing here as NATION_OWN handle both msg from AI and a remote player
  626. break;
  627. }
  628. }
  629. //-------- End of function TalkRes::send_talk_msg_now ---------//
  630. //------- Begin of function TalkRes::reply_talk_msg --------//
  631. //
  632. // If the nation which receives this message decides to accept
  633. // the offer of this message, this function is called.
  634. //
  635. // <int> talkMsgRecno - the recno of the TalkMsg
  636. // <char> replyType - reply type, either REPLY_ACCEPT or REPLY_REJECT
  637. // <char> remoteAction - remote action type
  638. //
  639. void TalkRes::reply_talk_msg(int talkMsgRecno, char replyType, char remoteAction)
  640. {
  641. //-------- send multiplayer -----------//
  642. if( !remoteAction && remote.is_enable() )
  643. {
  644. // packet structure : <talkRecno:int> <reply type:char> <padding:char>
  645. char* charPtr = remote.new_send_queue_msg( MSG_REPLY_TALK_MSG, sizeof(int)+2*sizeof(char) );
  646. *(int *)charPtr = talkMsgRecno;
  647. charPtr[sizeof(int)] = replyType;
  648. charPtr[sizeof(int)+sizeof(char)] = 0;
  649. return;
  650. }
  651. //-------------------------------------//
  652. err_when( is_talk_msg_deleted(talkMsgRecno) );
  653. TalkMsg* talkMsgPtr = get_talk_msg(talkMsgRecno);
  654. Nation* fromNation = nation_array[talkMsgPtr->from_nation_recno];
  655. err_when( talkMsgPtr->reply_type == REPLY_NOT_NEEDED );
  656. err_when( replyType != REPLY_ACCEPT && replyType != REPLY_REJECT );
  657. talkMsgPtr->reply_type = replyType;
  658. talkMsgPtr->reply_date = info.game_date;
  659. switch( fromNation->nation_type )
  660. {
  661. case NATION_OWN:
  662. news_array.diplomacy( talkMsgRecno );
  663. // ###### begin Gilbert 9/10 ########//
  664. // sound effect
  665. se_ctrl.immediate_sound("GONG");
  666. // ###### end Gilbert 9/10 ########//
  667. break;
  668. case NATION_AI:
  669. fromNation->ai_notify_reply( talkMsgRecno ); // notify the AI nation about this reply.
  670. break;
  671. case NATION_REMOTE:
  672. break;
  673. }
  674. //------- if the offer is accepted -------//
  675. if( talkMsgPtr->reply_type == REPLY_ACCEPT )
  676. talkMsgPtr->process_accepted_reply();
  677. //--- if the player has replyed the message, remove it from the news display ---//
  678. if( talkMsgPtr->to_nation_recno == nation_array.player_recno )
  679. news_array.remove(NEWS_DIPLOMACY, talkMsgRecno);
  680. }
  681. //-------- End of function TalkRes::reply_talk_msg ---------//
  682. //------- Begin of function TalkRes::disp_talk --------//
  683. void TalkRes::disp_talk()
  684. {
  685. //----- if the player can send no more message to the nation ---//
  686. if( !info.player_reply_mode &&
  687. !can_send_any_msg(cur_talk_msg.to_nation_recno, nation_array.player_recno) )
  688. {
  689. if( !( choice_question && strcmp(choice_question, MESSAGE_SENT_STR)==0 ) ) // if it's currently displaying the has sent notification, display that message
  690. {
  691. char* msgStr = "You've sent too many messages to this kingdom. "
  692. "You cannot send any new messages until the existing ones are processed.";
  693. font_san.put_paragraph( TALK_X1, TALK_Y1, TALK_X2, TALK_Y2, msgStr, 4 );
  694. return;
  695. }
  696. }
  697. //--- return whether the talk choices should be refreshed. ---//
  698. if( !reply_talk_msg_recno && !cur_talk_msg.talk_id ) // not replying and haven't selected a message type yet.
  699. {
  700. for( int i=0 ; i<MAX_TALK_TYPE ; i++ )
  701. {
  702. if( available_talk_id_array[i] != can_send_msg(cur_talk_msg.to_nation_recno, cur_talk_msg.from_nation_recno, i+1) )
  703. {
  704. set_talk_choices();
  705. break;
  706. }
  707. }
  708. }
  709. //------ repaint the area for displaying the sub-title ------//
  710. int y=TALK_Y1;
  711. String str;
  712. //----- if there is a question on the choices ------//
  713. if( choice_question )
  714. {
  715. font_san.put( TALK_X1+3, y, choice_question );
  716. y+=TALK_LINE_HEIGHT;
  717. }
  718. if( choice_question_second_line ) // second line message
  719. {
  720. font_san.put( TALK_X1+3, y, choice_question_second_line );
  721. y+=TALK_LINE_HEIGHT;
  722. }
  723. //--------- display talk choices ---------//
  724. for( int i=0 ; i<talk_choice_count ; i++, y+=TALK_LINE_HEIGHT )
  725. {
  726. if( i+1 == cur_choice_id ) // this is the one the mouse cursor is currently on
  727. vga_back.adjust_brightness( TALK_X1, y, TALK_X2, y+TALK_LINE_HEIGHT-1, -3 );
  728. if( choice_question )
  729. {
  730. str = "- "; // display bullets in front of the text strings
  731. str += translate.process( talk_choice_array[i].str );
  732. }
  733. else
  734. str = talk_choice_array[i].str;
  735. font_san.put_paragraph( TALK_X1+3, y+2, TALK_X2-3, y+font_san.height()+1, str );
  736. }
  737. }
  738. //-------- End of function TalkRes::disp_talk ---------//
  739. //------- Begin of function TalkRes::detect_talk_choices --------//
  740. //
  741. int TalkRes::detect_talk_choices()
  742. {
  743. int i, y=TALK_Y1;
  744. int newChoiceId=0;
  745. if( choice_question )
  746. y+=TALK_LINE_HEIGHT;
  747. if( choice_question_second_line )
  748. y+=TALK_LINE_HEIGHT;
  749. for( i=0 ; i<talk_choice_count ; i++, y+=TALK_LINE_HEIGHT )
  750. {
  751. if( mouse.in_area(TALK_X1, y, TALK_X2, y+TALK_LINE_HEIGHT-1) )
  752. {
  753. newChoiceId = i+1;
  754. break;
  755. }
  756. }
  757. //-------- refresh talk display -------//
  758. if( newChoiceId != cur_choice_id )
  759. {
  760. cur_choice_id = newChoiceId;
  761. disp_talk();
  762. }
  763. //------ if pressed on one of the talks ------//
  764. if( newChoiceId && mouse.single_click(TALK_X1, y, TALK_X2, y+TALK_LINE_HEIGHT-1) )
  765. return newChoiceId;
  766. return 0;
  767. }
  768. //-------- End of function TalkRes::detect_talk_choices ---------//
  769. //------- Begin of function TalkRes::detect_talk --------//
  770. //
  771. int TalkRes::detect_talk()
  772. {
  773. //----- if the message which player is reply is deleted (this can only happen when the player stays on the reply message screen for almost 1 year without doing anything and then the message is automatically deleted after having being kept for 1 year ---//
  774. if( reply_talk_msg_recno &&
  775. is_talk_msg_deleted(reply_talk_msg_recno) ) // the message may become invalid during the replying period
  776. {
  777. sys.set_view_mode(save_view_mode);
  778. if( save_view_mode == MODE_NATION )
  779. {
  780. cur_talk_msg.talk_id = 0;
  781. init_conversion(cur_talk_msg.to_nation_recno);
  782. }
  783. return 0;
  784. }
  785. //------------------------------------------//
  786. int choiceId = detect_talk_choices();
  787. if( !choiceId )
  788. return 0;
  789. int choicePara = talk_choice_array[choiceId-1].para;
  790. //---- if the player is replying message from other nation ----//
  791. if( reply_talk_msg_recno )
  792. {
  793. if( !is_talk_msg_deleted(reply_talk_msg_recno) ) // the message may become invalid during the replying period
  794. {
  795. if( choicePara==1 )
  796. reply_talk_msg(reply_talk_msg_recno, REPLY_ACCEPT, COMMAND_PLAYER);
  797. else
  798. reply_talk_msg(reply_talk_msg_recno, REPLY_REJECT, COMMAND_PLAYER);
  799. }
  800. sys.set_view_mode(save_view_mode);
  801. if( save_view_mode == MODE_NATION )
  802. {
  803. cur_talk_msg.talk_id = 0;
  804. init_conversion(cur_talk_msg.to_nation_recno);
  805. }
  806. return 1;
  807. }
  808. //---------------------------------------//
  809. if( strcmp( talk_choice_array[choiceId-1].str, "Cancel." ) == 0 ||
  810. (choice_question && strcmp( choice_question, MESSAGE_SENT_STR )==0) )
  811. {
  812. cur_talk_msg.talk_id = 0;
  813. init_conversion(cur_talk_msg.to_nation_recno);
  814. return 1;
  815. }
  816. //------ set the current choice to cur_talk_msg -------//
  817. if( cur_talk_msg.talk_id == 0 )
  818. cur_talk_msg.talk_id = choicePara;
  819. else if( cur_talk_msg.talk_para1 == 0 )
  820. cur_talk_msg.talk_para1 = choicePara;
  821. else if( cur_talk_msg.talk_para2 == 0 )
  822. cur_talk_msg.talk_para2 = choicePara;
  823. else
  824. err_here();
  825. //------ prepare the next available choices ------//
  826. if( !set_talk_choices() ) // the talk is complete
  827. {
  828. send_talk_msg( &cur_talk_msg, COMMAND_PLAYER );
  829. //--- the message has been sent, display notification message ---//
  830. choice_question = MESSAGE_SENT_STR;
  831. choice_question_second_line = NULL;
  832. talk_choice_count = 0;
  833. add_talk_choice( "Continue", 0 );
  834. }
  835. return 1;
  836. }
  837. //-------- End of function TalkRes::detect_talk ---------//
  838. //------- Begin of function TalkRes::get_talk_msg --------//
  839. TalkMsg* TalkRes::get_talk_msg(int recNo)
  840. {
  841. err_when( recNo < 1 || recNo > talk_msg_array.size() );
  842. TalkMsg* talkMsg = (TalkMsg*) talk_msg_array.get(recNo);
  843. if( !talkMsg->talk_id )
  844. err.run( "get_talk_msg() error, the TalkMsg is deleted." );
  845. return talkMsg;
  846. }
  847. //-------- End of function TalkRes::get_talk_msg ---------//
  848. //------- Begin of function TalkRes::is_talk_msg_deleted --------//
  849. int TalkRes::is_talk_msg_deleted(int recNo)
  850. {
  851. if( recNo < 1 || recNo > talk_msg_array.size() )
  852. return 1;
  853. TalkMsg* talkMsg = (TalkMsg*) talk_msg_array.get(recNo);
  854. return talkMsg->talk_id==0;
  855. }
  856. //-------- End of function TalkRes::is_talk_msg_deleted ---------//
  857. //------- Begin of function TalkRes::next_day --------//
  858. void TalkRes::next_day()
  859. {
  860. if( info.game_date%7 == 0 )
  861. process_talk_msg();
  862. }
  863. //-------- End of function TalkRes::next_day ---------//
  864. //------ Begin of function TalkRes::process_talk_msg ------//
  865. //
  866. void TalkRes::process_talk_msg()
  867. {
  868. int i;
  869. TalkMsg* talkMsg;
  870. for( i=talk_msg_count() ; i>0 ; i-- )
  871. {
  872. if( is_talk_msg_deleted(i) )
  873. continue;
  874. talkMsg = get_talk_msg(i);
  875. //--------------------------------------------------------//
  876. // If this is an AI message and there is no response from
  877. // the player after one month the message has been sent,
  878. // it presumes that the message has been rejected.
  879. //--------------------------------------------------------//
  880. if( nation_array[talkMsg->from_nation_recno]->nation_type == NATION_AI &&
  881. talkMsg->reply_type == REPLY_WAITING &&
  882. info.game_date > talkMsg->date + DISP_NEWS_DAYS )
  883. {
  884. talkMsg->reply_type = REPLY_REJECT;
  885. nation_array[talkMsg->from_nation_recno]->ai_notify_reply(i);
  886. }
  887. //--- delete the talk message after 2 months ---//
  888. if( info.game_date > talkMsg->date + TALK_MSG_KEEP_DAYS )
  889. del_talk_msg(i);
  890. }
  891. }
  892. //-------- End of function TalkRes::process_talk_msg ---------//
  893. //------ Begin of function TalkRes::del_talk_msg ------//
  894. //
  895. void TalkRes::del_talk_msg(int talkMsgRecno)
  896. {
  897. err_when( is_talk_msg_deleted(talkMsgRecno) );
  898. TalkMsg* talkMsg = get_talk_msg(talkMsgRecno);
  899. //--- if this message is sent to an AI nation ---//
  900. Nation* nationPtr = nation_array[talkMsg->to_nation_recno];
  901. if( nationPtr->nation_type == NATION_AI &&
  902. (talkMsg->reply_type == REPLY_NOT_NEEDED || // even if a reply is not needed, the message will still be sent to the AI for notification.
  903. talkMsg->reply_type == REPLY_WAITING) )
  904. {
  905. //--- it may still have the message in its action queue ---//
  906. ActionNode* actionNode;
  907. for( int i=nationPtr->action_count() ; i>0 ; i-- )
  908. {
  909. actionNode = nationPtr->get_action(i);
  910. if( actionNode->action_mode == ACTION_AI_PROCESS_TALK_MSG &&
  911. actionNode->action_para == talkMsgRecno )
  912. {
  913. nationPtr->del_action(i);
  914. break;
  915. }
  916. }
  917. }
  918. //----- delete the message from the news array -----//
  919. if( talkMsg->to_nation_recno == nation_array.player_recno ||
  920. talkMsg->from_nation_recno == nation_array.player_recno )
  921. {
  922. news_array.remove( NEWS_DIPLOMACY, talkMsgRecno );
  923. }
  924. //----- link it out from talk_msg_array -----//
  925. talk_msg_array.linkout(talkMsgRecno);
  926. }
  927. //-------- End of function TalkRes::del_talk_msg ---------//
  928. //------- Begin of function TalkRes::is_talk_msg_exist --------//
  929. //
  930. // <int> checkPara - whether check talk_para1 and talk_para2
  931. // in comparing TalkMsg.
  932. //
  933. // return : <int> >0 - the recno of the talk msg that already exists
  934. // ==0 - not found
  935. //
  936. int TalkRes::is_talk_msg_exist(TalkMsg* thisTalkMsg, int checkPara)
  937. {
  938. int i;
  939. TalkMsg* talkMsg;
  940. for( i=talk_msg_count() ; i>0 ; i-- )
  941. {
  942. if( is_talk_msg_deleted(i) )
  943. continue;
  944. talkMsg = get_talk_msg(i);
  945. if( talkMsg->reply_type == REPLY_WAITING ||
  946. talkMsg->reply_type == REPLY_NOT_NEEDED )
  947. {
  948. if( talkMsg->talk_id == thisTalkMsg->talk_id &&
  949. talkMsg->from_nation_recno == thisTalkMsg->from_nation_recno &&
  950. talkMsg->to_nation_recno == thisTalkMsg->to_nation_recno )
  951. {
  952. if( checkPara )
  953. {
  954. if( talkMsg->talk_para1 == thisTalkMsg->talk_para1 &&
  955. talkMsg->talk_para2 == thisTalkMsg->talk_para2 )
  956. {
  957. return i;
  958. }
  959. }
  960. else
  961. return i;
  962. }
  963. }
  964. }
  965. return 0;
  966. }
  967. //-------- End of function TalkRes::is_talk_msg_exist ---------//
  968. //------- Begin of function TalkRes::wait_msg_count --------//
  969. //
  970. // Return the number of messages sent to the nation waiting
  971. // for its reply.
  972. //
  973. int TalkRes::wait_msg_count(int toNationRecno, int fromNationRecno)
  974. {
  975. int i, waitMsgCount=0;
  976. TalkMsg* talkMsg;
  977. for( i=talk_msg_count() ; i>0 ; i-- )
  978. {
  979. if( is_talk_msg_deleted(i) )
  980. continue;
  981. talkMsg = get_talk_msg(i);
  982. if( talkMsg->reply_type == REPLY_WAITING &&
  983. talkMsg->to_nation_recno == toNationRecno &&
  984. talkMsg->from_nation_recno == fromNationRecno &&
  985. info.game_date < talkMsg->date + 30 ) // only count message in a month
  986. {
  987. waitMsgCount++;
  988. }
  989. }
  990. return waitMsgCount;
  991. }
  992. //-------- End of function TalkRes::wait_msg_count ---------//
  993. //------- Begin of function TalkRes::player_reply --------//
  994. void TalkRes::player_reply(int talkMsgRecno)
  995. {
  996. //------- set the reply choices --------//
  997. err_when( is_talk_msg_deleted(talkMsgRecno) );
  998. TalkMsg* talkMsg = get_talk_msg(talkMsgRecno);
  999. if( nation_array.is_deleted(talkMsg->from_nation_recno) )
  1000. return;
  1001. init_conversion(talkMsg->from_nation_recno);
  1002. talk_choice_count = 0;
  1003. cur_choice_id = 0;
  1004. reply_talk_msg_recno = talkMsgRecno;
  1005. //--------- add talk choices ---------//
  1006. static String msgStr, msgStr2;
  1007. msgStr = talkMsg->msg_str(nation_array.player_recno); // make a static copy of it.
  1008. choice_question = msgStr;
  1009. //---- see if this message has a second line -----//
  1010. msgStr2 = talkMsg->msg_str(nation_array.player_recno, 0, 1); // 1-display the second line of the question
  1011. if( msgStr!=msgStr2 )
  1012. choice_question_second_line = msgStr2;
  1013. else
  1014. choice_question_second_line = NULL;
  1015. //--------- add choices to the question ---------//
  1016. if( talkMsg->can_accept() ) // whether the replier can accept the request or demand of the message
  1017. add_talk_choice( "Accept.", 1 );
  1018. add_talk_choice( "Reject.", 0 );
  1019. //--- switch to the nation report mode and go to the diplomacy mode ---//
  1020. info.init_player_reply( talkMsg->from_nation_recno );
  1021. save_view_mode = sys.view_mode;
  1022. sys.set_view_mode(MODE_NATION);
  1023. }
  1024. //-------- End of function TalkRes::player_reply ---------//
  1025. //------- Begin of function TalkRes::del_all_nation_msg --------//
  1026. //
  1027. // Delete all messages related to this nation.
  1028. //
  1029. void TalkRes::del_all_nation_msg(int nationRecno)
  1030. {
  1031. int i;
  1032. TalkMsg* talkMsg;
  1033. for( i=talk_msg_count() ; i>0 ; i-- )
  1034. {
  1035. if( is_talk_msg_deleted(i) )
  1036. continue;
  1037. talkMsg = get_talk_msg(i);
  1038. if( talkMsg->from_nation_recno == nationRecno ||
  1039. talkMsg->to_nation_recno == nationRecno ||
  1040. !talkMsg->is_valid_to_disp() ) // if the nation is the talk_para1 (e.g. TRADE_EMBARGO), is_valid_to_disp() will return 0 and the talk message should than be deleted
  1041. {
  1042. del_talk_msg(i);
  1043. }
  1044. }
  1045. }
  1046. //-------- End of function TalkRes::del_all_nation_msg ---------//