ONEWS2.cpp 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195
  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 : ONEWS2.CPP
  21. //Description : News adding functions
  22. #include <OTOWN.h>
  23. #include <ONATION.h>
  24. #include <OMONSRES.h>
  25. #include <OTALKRES.h>
  26. #include <OFIRM.h>
  27. #include <OSPY.h>
  28. #include <OUNIT.h>
  29. #include <ONEWS.h>
  30. //------ Begin of function NewsArray::diplomacy -----//
  31. //
  32. // <int> talkMsgRecno = the recno of the TalkMsg in talk_res.talk_msg_array
  33. //
  34. // short_para1 = the recno of the TalkMsg in talk_res.talk_msg_array
  35. //
  36. void NewsArray::diplomacy(int talkMsgRecno)
  37. {
  38. //----------- add news --------------//
  39. err_when( talk_res.is_talk_msg_deleted(talkMsgRecno) );
  40. TalkMsg* talkMsgPtr = talk_res.get_talk_msg(talkMsgRecno);
  41. News* newsPtr = add_news( NEWS_DIPLOMACY, NEWS_NORMAL, talkMsgPtr->from_nation_recno, talkMsgPtr->to_nation_recno );
  42. if( !newsPtr ) // only news of nations that have contact with the player are added
  43. return;
  44. newsPtr->short_para1 = talkMsgRecno;
  45. }
  46. //------- End of function NewsArray::diplomacy -----//
  47. //------ Begin of function NewsArray::town_rebel -----//
  48. //
  49. // <int> townRecno = the recno of the town where people there rebel
  50. // <int> rebelCount = no. of rebels
  51. //
  52. // short_para1 = the town name id.
  53. // short_para2 = no. of rebels
  54. //
  55. void NewsArray::town_rebel(int townRecno, int rebelCount)
  56. {
  57. Town* townPtr = town_array[townRecno];
  58. //----------- add news --------------//
  59. News* newsPtr = add_news( NEWS_TOWN_REBEL, NEWS_NORMAL, townPtr->nation_recno );
  60. if( !newsPtr ) // only news of nations that have contact with the player are added
  61. return;
  62. newsPtr->short_para1 = townPtr->town_name_id;
  63. newsPtr->short_para2 = rebelCount;
  64. //-------- set location ----------//
  65. newsPtr->set_loc( townPtr->center_x, townPtr->center_y, NEWS_LOC_TOWN, townRecno );
  66. }
  67. //------- End of function NewsArray::town_rebel -----//
  68. //------ Begin of function NewsArray::migrate -----//
  69. //
  70. // <int> srcTownRecno = the town that the worker migrates from
  71. // <int> desTownRecno = the town that the worker migrates to
  72. // <int> raceId = race id. of the migrated worker/peasant
  73. // <int> migratedCount= no. of people migrated.
  74. // [int] firmRecno = if firm worker migrates,
  75. // >this is the firm id. that the worker works for
  76. // if town peasant migrates
  77. // >this is 0
  78. //
  79. // short_para1 = the town name id. that the worker migrates from
  80. // short_para2 = the town name id. that the worker migrates to
  81. // short_para3 = race id. of the migrated worker/peasant
  82. // short_para4 = no. of people migrated
  83. // short_para5 = the firm id. that the worker works for
  84. //
  85. void NewsArray::migrate(int srcTownRecno, int desTownRecno, int raceId, int migratedCount, int firmRecno)
  86. {
  87. err_when( srcTownRecno==0 || desTownRecno==0 || raceId==0 || migratedCount==0 );
  88. Town* srcTown = town_array[srcTownRecno];
  89. Town* desTown = town_array[desTownRecno];
  90. //----------- add news --------------//
  91. News* newsPtr = add_news( NEWS_MIGRATE, NEWS_NORMAL, srcTown->nation_recno, desTown->nation_recno );
  92. if( !newsPtr ) // only news of nations that have contact with the player are added
  93. return;
  94. newsPtr->short_para1 = srcTown->town_name_id;
  95. newsPtr->short_para2 = desTown->town_name_id;
  96. newsPtr->short_para3 = raceId;
  97. newsPtr->short_para4 = migratedCount;
  98. if( firmRecno )
  99. newsPtr->short_para5 = firm_array[firmRecno]->firm_id;
  100. else
  101. newsPtr->short_para5 = 0;
  102. //-------- set location ----------//
  103. newsPtr->set_loc( desTown->center_x, desTown->center_y, NEWS_LOC_TOWN, desTownRecno );
  104. }
  105. //------- End of function NewsArray::migrate -----//
  106. //------ Begin of function NewsArray::new_nation -----//
  107. //
  108. // <int> nationRecno - recno of the new nation.
  109. //
  110. // king_name1() - name of the king of the new kingdom.
  111. //
  112. void NewsArray::new_nation(int nationRecno)
  113. {
  114. News* newsPtr = add_news( NEWS_NEW_NATION, NEWS_NORMAL, nationRecno );
  115. if( !newsPtr )
  116. return;
  117. //---- set the news location to one of its town ----//
  118. for( int i=town_array.size() ; i>0 ; i-- )
  119. {
  120. if( town_array.is_deleted(i) )
  121. continue;
  122. Town* townPtr = town_array[i];
  123. if( townPtr->nation_recno == nationRecno )
  124. {
  125. newsPtr->set_loc( townPtr->center_x, townPtr->center_y,
  126. NEWS_LOC_TOWN, i );
  127. break;
  128. }
  129. }
  130. }
  131. //------- End of function NewsArray::new_nation -----//
  132. //------ Begin of function NewsArray::nation_destroyed -----//
  133. //
  134. // <int> nationRecno - recno of the nation that has been destroyed
  135. //
  136. // nation_name1() - the nation that has been destroyed.
  137. //
  138. void NewsArray::nation_destroyed(int nationRecno)
  139. {
  140. add_news( NEWS_NATION_DESTROYED, NEWS_NORMAL, nationRecno );
  141. }
  142. //------- End of function NewsArray::nation_destroyed -----//
  143. //------ Begin of function NewsArray::nation_surrender -----//
  144. //
  145. // <int> nationRecno - recno of the surrendering nation.
  146. // <int> toNationRecno - recno of the nation to surrender.
  147. //
  148. void NewsArray::nation_surrender(int nationRecno, int toNationRecno)
  149. {
  150. add_news( NEWS_NATION_SURRENDER, NEWS_NORMAL, nationRecno, toNationRecno );
  151. }
  152. //------- End of function NewsArray::nation_surrender -----//
  153. //------ Begin of function NewsArray::king_die -----//
  154. //
  155. // <int> nationRecno - recno of the nation with its king died.
  156. //
  157. // king_name1() - the nation whose king has died.
  158. //
  159. void NewsArray::king_die(int nationRecno)
  160. {
  161. add_news( NEWS_KING_DIE, NEWS_NORMAL, nationRecno );
  162. }
  163. //------- End of function NewsArray::king_die -----//
  164. //------ Begin of function NewsArray::new_king -----//
  165. //
  166. // <int> nationRecno - recno of the nation
  167. // <int> kingUnitRecno - unit recno of the new king.
  168. //
  169. // This function should be called before set_king() has been called.
  170. //
  171. // nation_name1() - name of the nation where there is a new king.
  172. //
  173. // short_para1 - race id. of the new king.
  174. // short_para2 - name id. of the new king.
  175. //
  176. void NewsArray::new_king(int nationRecno, int kingUnitRecno)
  177. {
  178. News* newsPtr = add_news( NEWS_NEW_KING, NEWS_NORMAL, nationRecno );
  179. if( !newsPtr )
  180. return;
  181. Unit* unitPtr = unit_array[kingUnitRecno];
  182. newsPtr->short_para1 = unitPtr->race_id;
  183. newsPtr->short_para2 = unitPtr->name_id;
  184. }
  185. //------- End of function NewsArray::new_king -----//
  186. //------ Begin of function NewsArray::firm_destroyed -----//
  187. //
  188. // <int> firmRecno - recno of the firm destroyed.
  189. // <Unit*> attackUnit - recno to the attacking unit.
  190. //
  191. // short_para1 - id. of the firm destroyed.
  192. // short_para2 - name id of the town where the firm is located.
  193. // short_para3 - destroyer type: 1 - a nation, 2 - rebels, 3 - Fryhtans.
  194. //
  195. void NewsArray::firm_destroyed(int firmRecno, Unit* attackUnit)
  196. {
  197. Firm* firmPtr = firm_array[firmRecno];
  198. err_when( firmPtr->nation_recno != nation_array.player_recno );
  199. int destroyerNationRecno=0;
  200. if( attackUnit )
  201. destroyerNationRecno = attackUnit->nation_recno;
  202. News* newsPtr = add_news( NEWS_FIRM_DESTROYED, NEWS_NORMAL, firmPtr->nation_recno, destroyerNationRecno );
  203. if( !newsPtr ) // only news of nations that have contact with the player are added
  204. return;
  205. newsPtr->short_para1 = firmPtr->firm_id;
  206. if( firmPtr->closest_town_name_id )
  207. newsPtr->short_para2 = firmPtr->closest_town_name_id;
  208. else
  209. newsPtr->short_para2 = firmPtr->get_closest_town_name_id();
  210. //-------- set destroyer type ------//
  211. newsPtr->short_para3 = DESTROYER_UNKNOWN;
  212. if( attackUnit )
  213. {
  214. if( attackUnit->unit_mode == UNIT_MODE_REBEL )
  215. newsPtr->short_para3 = DESTROYER_REBEL;
  216. else if( unit_res[attackUnit->unit_id]->unit_class == UNIT_CLASS_MONSTER )
  217. newsPtr->short_para3 = DESTROYER_MONSTER;
  218. else if( attackUnit->nation_recno )
  219. newsPtr->short_para3 = DESTROYER_NATION;
  220. }
  221. //--------- set location ---------//
  222. newsPtr->set_loc( firmPtr->center_x, firmPtr->center_y, NEWS_LOC_ANY );
  223. }
  224. //------- End of function NewsArray::firm_destroyed -----//
  225. //------ Begin of function NewsArray::firm_captured -----//
  226. //
  227. // <int> firmRecno - recno of the firm destroyed.
  228. // <int> takeoverNationRecno - recno of nation that has taken over the firm.
  229. // <int> spyTakeover - whether the capturer of the firm is a spy.
  230. //
  231. // short_para1 - id. of the firm destroyed.
  232. // short_para2 - name id of the town where the firm is located.
  233. // short_para3 - whether the capturer of the firm is a spy.
  234. //
  235. void NewsArray::firm_captured(int firmRecno, int takeoverNationRecno, int spyTakeover)
  236. {
  237. Firm* firmPtr = firm_array[firmRecno];
  238. err_when( firmPtr->nation_recno != nation_array.player_recno );
  239. News* newsPtr = add_news( NEWS_FIRM_CAPTURED, NEWS_NORMAL, firmPtr->nation_recno, takeoverNationRecno );
  240. if( !newsPtr ) // only news of nations that have contact with the player are added
  241. return;
  242. newsPtr->short_para1 = firmPtr->firm_id;
  243. if( firmPtr->closest_town_name_id )
  244. newsPtr->short_para2 = firmPtr->closest_town_name_id;
  245. else
  246. newsPtr->short_para2 = firmPtr->get_closest_town_name_id();
  247. newsPtr->short_para3 = spyTakeover;
  248. //--------- set location ---------//
  249. newsPtr->set_loc( firmPtr->center_x, firmPtr->center_y, NEWS_LOC_FIRM, firmRecno );
  250. }
  251. //------- End of function NewsArray::firm_captured -----//
  252. //------ Begin of function NewsArray::town_destroyed -----//
  253. //
  254. // <int> townNameId - name id. of the town destroyed.
  255. // <int> xLoc, yLoc - location of the town
  256. // <Unit*> attackUnit - recno to the attacking unit.
  257. //
  258. // short_para1 - name id. of the town destroyed.
  259. // short_para2 - destroyer type: 1 - a nation, 2 - rebels, 3 - Fryhtans.
  260. //
  261. void NewsArray::town_destroyed(int townNameId, int xLoc, int yLoc, Unit* attackUnit)
  262. {
  263. int destroyerNationRecno=0;
  264. if( attackUnit )
  265. destroyerNationRecno = attackUnit->nation_recno;
  266. News* newsPtr = add_news( NEWS_TOWN_DESTROYED, NEWS_NORMAL, nation_array.player_recno, destroyerNationRecno );
  267. if( !newsPtr ) // only news of nations that have contact with the player are added
  268. return;
  269. newsPtr->short_para1 = townNameId;
  270. //-------- set destroyer type ------//
  271. newsPtr->short_para2 = DESTROYER_UNKNOWN;
  272. if( attackUnit )
  273. {
  274. if( attackUnit->unit_mode == UNIT_MODE_REBEL )
  275. newsPtr->short_para2 = DESTROYER_REBEL;
  276. else if( unit_res[attackUnit->unit_id]->unit_class == UNIT_CLASS_MONSTER )
  277. newsPtr->short_para2 = DESTROYER_MONSTER;
  278. else if( attackUnit->nation_recno )
  279. newsPtr->short_para2 = DESTROYER_NATION;
  280. }
  281. //-------- set location ----------//
  282. newsPtr->set_loc( xLoc, yLoc, NEWS_LOC_ANY );
  283. }
  284. //------- End of function NewsArray::town_destroyed -----//
  285. //------ Begin of function NewsArray::town_abandoned -----//
  286. //
  287. // <int> townRecno - recno of the town destroyed.
  288. //
  289. // short_para1 - name id. of the town destroyed.
  290. //
  291. void NewsArray::town_abandoned(int townRecno)
  292. {
  293. Town* townPtr = town_array[townRecno];
  294. err_when( townPtr->nation_recno != nation_array.player_recno );
  295. News* newsPtr = add_news( NEWS_TOWN_ABANDONED, NEWS_NORMAL, townPtr->nation_recno );
  296. if( !newsPtr ) // only news of nations that have contact with the player are added
  297. return;
  298. newsPtr->short_para1 = townPtr->town_name_id;
  299. //-------- set location ----------//
  300. newsPtr->set_loc( townPtr->center_x, townPtr->center_y, NEWS_LOC_ANY );
  301. }
  302. //------- End of function NewsArray::town_abandoned -----//
  303. //------ Begin of function NewsArray::town_surrendered -----//
  304. //
  305. // <int> townRecno - recno of the town
  306. // <int> toNationRecno - recno of the nation this town surrenders to
  307. //
  308. // short_para1 - name id. of the surrendering town.
  309. //
  310. // nation_name1() - name of the nation the town surrenders to.
  311. // nation_name2() - name of the nation of the surrendering town.
  312. //
  313. // This function should be called before the town surrenders.
  314. //
  315. void NewsArray::town_surrendered(int townRecno, int toNationRecno)
  316. {
  317. Town* townPtr = town_array[townRecno];
  318. err_when( townPtr->nation_recno != nation_array.player_recno &&
  319. toNationRecno != nation_array.player_recno );
  320. News* newsPtr = add_news( NEWS_TOWN_SURRENDERED, NEWS_NORMAL, toNationRecno, townPtr->nation_recno );
  321. if( !newsPtr ) // only news of nations that have contact with the player are added
  322. return;
  323. newsPtr->short_para1 = townPtr->town_name_id;
  324. //-------- set location ----------//
  325. newsPtr->set_loc( townPtr->center_x, townPtr->center_y, NEWS_LOC_TOWN, townRecno );
  326. }
  327. //------- End of function NewsArray::town_surrendered -----//
  328. //------ Begin of function NewsArray::monster_king_killed -----//
  329. //
  330. // <int> monsterId - monster id. of the monster king.
  331. //
  332. // short_para1 - monster id.
  333. //
  334. void NewsArray::monster_king_killed(int monsterId, int xLoc, int yLoc)
  335. {
  336. err_when( monsterId < 1 || monsterId > monster_res.monster_count );
  337. News* newsPtr = add_news( NEWS_MONSTER_KING_KILLED, NEWS_NORMAL );
  338. if( !newsPtr ) // only news of nations that have contact with the player are added
  339. return;
  340. newsPtr->short_para1 = monsterId;
  341. //-------- set location ----------//
  342. newsPtr->set_loc( xLoc, yLoc, NEWS_LOC_ANY );
  343. }
  344. //------- End of function NewsArray::monster_king_killed -----//
  345. //------ Begin of function NewsArray::monster_firm_destroyed -----//
  346. //
  347. // <int> monsterId - monster id. of the monster king.
  348. //
  349. // short_para1 - monster id.
  350. //
  351. void NewsArray::monster_firm_destroyed(int monsterId, int xLoc, int yLoc)
  352. {
  353. err_when( monsterId < 1 || monsterId > monster_res.monster_count );
  354. News* newsPtr = add_news( NEWS_MONSTER_FIRM_DESTROYED, NEWS_NORMAL );
  355. if( !newsPtr ) // only news of nations that have contact with the player are added
  356. return;
  357. newsPtr->short_para1 = monsterId;
  358. //-------- set location ----------//
  359. newsPtr->set_loc( xLoc, yLoc, NEWS_LOC_ANY );
  360. }
  361. //------- End of function NewsArray::monster_firm_destroyed -----//
  362. //------ Begin of function NewsArray::scroll_acquired -----//
  363. //
  364. // <int> acquireNationRecno - recno of the nation that has acquired the scroll
  365. // <int> scrollRaceId - race of the scroll
  366. //
  367. // nation_name1() - the nation that has acquired the scroll.
  368. //
  369. // short_para1 = the race id. of the scroll.
  370. //
  371. void NewsArray::scroll_acquired(int acquireNationRecno, int scrollRaceId)
  372. {
  373. News* newsPtr = add_news( NEWS_SCROLL_ACQUIRED, NEWS_NORMAL, acquireNationRecno );
  374. if( !newsPtr ) // only news of nations that have contact with the player are added
  375. return;
  376. newsPtr->short_para1 = scrollRaceId;
  377. }
  378. //------- End of function NewsArray::scroll_acquired -----//
  379. //------ Begin of function NewsArray::monster_gold_acquired -----//
  380. //
  381. // When the player recovered treasures from monsters.
  382. //
  383. // <int> goldAmt - the amount of treasure recovered.
  384. //
  385. // short_para1 = amount of gold.
  386. //
  387. void NewsArray::monster_gold_acquired(int goldAmt)
  388. {
  389. News* newsPtr = add_news( NEWS_MONSTER_GOLD_ACQUIRED, NEWS_NORMAL, nation_array.player_recno );
  390. if( !newsPtr )
  391. return;
  392. newsPtr->short_para1 = goldAmt;
  393. }
  394. //------- End of function NewsArray::monster_gold_acquired -----//
  395. //------ Begin of function NewsArray::spy_killed -----//
  396. //
  397. // <int> spyRecno - recno of the spy.
  398. //
  399. // nation_name1() - your nation.
  400. // nation_name2() - the nation that killed your spy.
  401. //
  402. // short_para1 - firm id. if it's a firm
  403. // 0 if it's a town
  404. // short_para2 - the town id.
  405. // short_para3 - spy place
  406. //
  407. // This function should be called just right before the spy is killed.
  408. //
  409. void NewsArray::spy_killed(int spyRecno)
  410. {
  411. Spy* spyPtr = spy_array[spyRecno];
  412. News* newsPtr;
  413. //---------- your spy is killed in an enemy nation ---------//
  414. if( spyPtr->true_nation_recno == nation_array.player_recno )
  415. {
  416. newsPtr = add_news( NEWS_YOUR_SPY_KILLED, NEWS_NORMAL,
  417. nation_array.player_recno, spyPtr->cloaked_nation_recno );
  418. }
  419. else //----- an enemy spy in your nation is uncovered and executed ----//
  420. {
  421. err_when( spyPtr->cloaked_nation_recno != nation_array.player_recno );
  422. newsPtr = add_news( NEWS_ENEMY_SPY_KILLED, NEWS_NORMAL,
  423. nation_array.player_recno, spyPtr->true_nation_recno );
  424. }
  425. if( !newsPtr ) // only news of nations that have contact with the player are added
  426. return;
  427. //-------------------------------------------//
  428. newsPtr->short_para3 = spyPtr->spy_place;
  429. if( spyPtr->spy_place == SPY_FIRM )
  430. {
  431. Firm* firmPtr = firm_array[spyPtr->spy_place_para];
  432. newsPtr->short_para1 = firmPtr->firm_id;
  433. newsPtr->short_para2 = firmPtr->get_closest_town_name_id();
  434. newsPtr->set_loc( firmPtr->center_x, firmPtr->center_y, NEWS_LOC_FIRM, firmPtr->firm_recno );
  435. }
  436. else if( spyPtr->spy_place == SPY_TOWN )
  437. {
  438. Town* townPtr = town_array[spyPtr->spy_place_para];
  439. newsPtr->short_para1 = 0;
  440. newsPtr->short_para2 = townPtr->town_name_id;
  441. newsPtr->set_loc( townPtr->center_x, townPtr->center_y, NEWS_LOC_TOWN, townPtr->town_recno );
  442. }
  443. else if( spyPtr->spy_place == SPY_MOBILE )
  444. {
  445. Unit* unitPtr = unit_array[spyPtr->spy_place_para];
  446. newsPtr->short_para1 = unitPtr->race_id;
  447. newsPtr->short_para2 = unitPtr->name_id;
  448. }
  449. }
  450. //------- End of function NewsArray::spy_killed -----//
  451. //------ Begin of function NewsArray::unit_betray -----//
  452. //
  453. // <int> unitRecno - recno of the unit.
  454. // <int> betrayToNationRecno - the nation which the unit betray towards
  455. //
  456. // nation_name1() - the nation that the unit originally belongs to.
  457. // nation_name2() - the nation that the unit has turned towards.
  458. //
  459. // short_para1 - race id. of the unit
  460. // short_para2 - name id. of the unit
  461. // short_para3 - rank id. of the unit
  462. //
  463. // This function should be called before the unit betray.
  464. //
  465. void NewsArray::unit_betray(int unitRecno, int betrayToNationRecno)
  466. {
  467. Unit* unitPtr = unit_array[unitRecno];
  468. err_when( unitPtr->nation_recno != nation_array.player_recno &&
  469. betrayToNationRecno != nation_array.player_recno );
  470. News* newsPtr = add_news( NEWS_UNIT_BETRAY, NEWS_NORMAL, unitPtr->nation_recno, betrayToNationRecno );
  471. if( !newsPtr ) // only news of nations that have contact with the player are added
  472. return;
  473. newsPtr->short_para1 = unitPtr->race_id;
  474. newsPtr->short_para2 = unitPtr->name_id;
  475. newsPtr->short_para3 = unitPtr->rank_id;
  476. //------- set location --------//
  477. if( betrayToNationRecno == nation_array.player_recno )
  478. newsPtr->set_loc( unitPtr->next_x_loc(), unitPtr->next_y_loc(), NEWS_LOC_UNIT, unitRecno, unitPtr->name_id );
  479. else
  480. newsPtr->set_loc( unitPtr->next_x_loc(), unitPtr->next_y_loc(), NEWS_LOC_ANY );
  481. }
  482. //------- End of function NewsArray::unit_betray -----//
  483. //------ Begin of function NewsArray::unit_assassinated -----//
  484. //
  485. // <int> unitRecno - recno of the unit that has been assassinated.
  486. // <int> spyKilled - whether the enemy spy has been killed during his assissination mission.
  487. //
  488. // short_para1 - race id. of the assassinated unit
  489. // short_para2 - name id. of the assassinated unit
  490. // short_para3 - rank id. of the assassinated unit
  491. // short_para4 - whether the enemy spy has been killed or not.
  492. //
  493. void NewsArray::unit_assassinated(int unitRecno, int spyKilled)
  494. {
  495. Unit* unitPtr = unit_array[unitRecno];
  496. err_when( unitPtr->nation_recno != nation_array.player_recno );
  497. News* newsPtr = add_news( NEWS_UNIT_ASSASSINATED, NEWS_NORMAL, unitPtr->nation_recno );
  498. if( !newsPtr ) // only news of nations that have contact with the player are added
  499. return;
  500. newsPtr->short_para1 = unitPtr->race_id;
  501. newsPtr->short_para2 = unitPtr->name_id;
  502. newsPtr->short_para3 = unitPtr->rank_id;
  503. newsPtr->short_para4 = spyKilled;
  504. //------- set location --------//
  505. short xLoc, yLoc;
  506. unitPtr->get_cur_loc(xLoc, yLoc);
  507. newsPtr->set_loc( xLoc, yLoc, NEWS_LOC_ANY );
  508. }
  509. //------- End of function NewsArray::unit_assassinated -----//
  510. //------ Begin of function NewsArray::assassinator_caught -----//
  511. //
  512. // <int> spyRecno - spy recno of the assassinator.
  513. // <int> targetRankId - the rank id. of the assassinating target
  514. //
  515. // short_para1 - rank id. of the assassinating target.
  516. //
  517. void NewsArray::assassinator_caught(int spyRecno, int targetRankId)
  518. {
  519. News* newsPtr = add_news( NEWS_ASSASSINATOR_CAUGHT, NEWS_NORMAL );
  520. if( !newsPtr ) // only news of nations that have contact with the player are added
  521. return;
  522. newsPtr->short_para1 = targetRankId;
  523. //------- set location --------//
  524. int xLoc, yLoc;
  525. spy_array[spyRecno]->get_loc(xLoc, yLoc);
  526. newsPtr->set_loc( xLoc, yLoc, NEWS_LOC_ANY );
  527. }
  528. //------- End of function NewsArray::assassinator_caught -----//
  529. //------ Begin of function NewsArray::general_die -----//
  530. //
  531. // <int> unitRecno - recno of the unit.
  532. //
  533. // short_para1 - race id. of your general
  534. // short_para2 - name id. of your general
  535. //
  536. void NewsArray::general_die(int unitRecno)
  537. {
  538. Unit* unitPtr = unit_array[unitRecno];
  539. err_when( unitPtr->nation_recno != nation_array.player_recno );
  540. News* newsPtr = add_news( NEWS_GENERAL_DIE, NEWS_NORMAL, unitPtr->nation_recno );
  541. if( !newsPtr ) // only news of nations that have contact with the player are added
  542. return;
  543. newsPtr->short_para1 = unitPtr->race_id;
  544. newsPtr->short_para2 = unitPtr->name_id;
  545. //------- set location --------//
  546. newsPtr->set_loc( unitPtr->next_x_loc(), unitPtr->next_y_loc(), NEWS_LOC_ANY );
  547. }
  548. //------- End of function NewsArray::general_die -----//
  549. //------ Begin of function NewsArray::raw_exhaust -----//
  550. //
  551. // short_para1 - raw id.
  552. //
  553. void NewsArray::raw_exhaust(int rawId, int xLoc, int yLoc)
  554. {
  555. News* newsPtr = add_news( NEWS_RAW_EXHAUST, NEWS_NORMAL );
  556. if( !newsPtr ) // only news of nations that have contact with the player are added
  557. return;
  558. newsPtr->short_para1 = rawId;
  559. //------- set location --------//
  560. newsPtr->set_loc( xLoc, yLoc, NEWS_LOC_ANY );
  561. }
  562. //------- End of function NewsArray::raw_exhaust -----//
  563. //------ Begin of function NewsArray::tech_researched -----//
  564. //
  565. // short_para1 - tech id.
  566. // short_para2 - tech version.
  567. //
  568. void NewsArray::tech_researched(int techId, int techVersion)
  569. {
  570. News* newsPtr = add_news( NEWS_TECH_RESEARCHED, NEWS_NORMAL, nation_array.player_recno );
  571. if( !newsPtr ) // only news of nations that have contact with the player are added
  572. return;
  573. newsPtr->short_para1 = techId;
  574. newsPtr->short_para2 = techVersion;
  575. }
  576. //------- End of function NewsArray::tech_researched -----//
  577. //------ Begin of function NewsArray::lightning_damage -----//
  578. //
  579. void NewsArray::lightning_damage(int xLoc, int yLoc, int objectId, int recno, int objectDie)
  580. {
  581. News* newsPtr = add_news( NEWS_LIGHTNING_DAMAGE, NEWS_NORMAL );
  582. if( !newsPtr )
  583. return;
  584. newsPtr->set_loc( xLoc, yLoc, objectId, recno);
  585. newsPtr->short_para1 = objectId;
  586. newsPtr->short_para2 = 0;
  587. newsPtr->short_para3 = 0;
  588. newsPtr->short_para4 = 0;
  589. switch( objectId )
  590. {
  591. case NEWS_LOC_UNIT:
  592. newsPtr->short_para4 = unit_array[recno]->rank_id;
  593. if( (newsPtr->short_para2 = unit_array[recno]->race_id) > 0)
  594. newsPtr->short_para3 = (short) unit_array[recno]->name_id;
  595. else
  596. newsPtr->short_para3 = unit_array[recno]->unit_id;
  597. break;
  598. case NEWS_LOC_FIRM:
  599. newsPtr->short_para2 = firm_array[recno]->firm_id;
  600. newsPtr->short_para3 = firm_array[recno]->closest_town_name_id;
  601. break;
  602. case NEWS_LOC_TOWN:
  603. newsPtr->short_para3 = town_array[recno]->town_name_id;
  604. break;
  605. default:
  606. err_here();
  607. }
  608. newsPtr->short_para5 = objectDie;
  609. }
  610. //------- End of function NewsArray::lightning_damage -----//
  611. //------ Begin of function NewsArray::earthquake_damage -----//
  612. //
  613. void NewsArray::earthquake_damage(int unitDamage, int unitDie, int townDamage, int firmDamage, int firmDie)
  614. {
  615. News* newsPtr;
  616. // ######## begin Gilbert 12/9 #######//
  617. if( unitDamage > 0 || unitDie > 0)
  618. {
  619. newsPtr = add_news( NEWS_EARTHQUAKE_DAMAGE, NEWS_NORMAL );
  620. if( newsPtr )
  621. {
  622. newsPtr->short_para1 = 1;
  623. newsPtr->short_para2 = unitDamage;
  624. newsPtr->short_para3 = unitDie;
  625. }
  626. }
  627. if( townDamage > 0)
  628. {
  629. newsPtr = add_news( NEWS_EARTHQUAKE_DAMAGE, NEWS_NORMAL );
  630. if( newsPtr )
  631. {
  632. newsPtr->short_para1 = 2;
  633. newsPtr->short_para2 = townDamage;
  634. }
  635. }
  636. if( firmDamage > 0 || firmDie > 0)
  637. {
  638. newsPtr = add_news( NEWS_EARTHQUAKE_DAMAGE, NEWS_NORMAL );
  639. if( newsPtr )
  640. {
  641. newsPtr->short_para1 = 3;
  642. newsPtr->short_para2 = firmDamage;
  643. newsPtr->short_para3 = firmDie;
  644. }
  645. }
  646. // ######## end Gilbert 12/9 #######//
  647. }
  648. //------- End of function NewsArray::earthquake_damage -----//
  649. //------ Begin of function NewsArray::goal_deadline -----//
  650. //
  651. // Display a warning message as the deadline of the goals approaches.
  652. //
  653. // short_para1 - years left before the deadline.
  654. // short_para2 - months left before the deadline.
  655. //
  656. void NewsArray::goal_deadline(int yearLeft, int monthLeft)
  657. {
  658. News* newsPtr = add_news( NEWS_GOAL_DEADLINE, NEWS_NORMAL, nation_array.player_recno );
  659. if( !newsPtr ) // only news of nations that have contact with the player are added
  660. return;
  661. newsPtr->short_para1 = yearLeft;
  662. newsPtr->short_para2 = monthLeft;
  663. }
  664. //------- End of function NewsArray::goal_deadline -----//
  665. //------ Begin of function NewsArray::weapon_ship_worn_out -----//
  666. //
  667. // Your weapon worn out and destroyed due to lack of money for
  668. // maintenance.
  669. //
  670. // short_para1 - unit id. of the weapon
  671. // short_para2 - level of the weapon
  672. //
  673. void NewsArray::weapon_ship_worn_out(int unitId, int weaponLevel)
  674. {
  675. err_when( unit_res[unitId]->unit_class != UNIT_CLASS_WEAPON &&
  676. unit_res[unitId]->unit_class != UNIT_CLASS_SHIP );
  677. News* newsPtr = add_news( NEWS_WEAPON_SHIP_WORN_OUT, NEWS_NORMAL, nation_array.player_recno );
  678. if( !newsPtr ) // only news of nations that have contact with the player are added
  679. return;
  680. newsPtr->short_para1 = unitId;
  681. newsPtr->short_para2 = weaponLevel;
  682. }
  683. //------- End of function NewsArray::weapon_ship_worn_out -----//
  684. //------ Begin of function NewsArray::firm_worn_out -----//
  685. //
  686. // <int> firmRecno - recno of the firm destroyed.
  687. //
  688. // short_para1 - id. of the firm destroyed.
  689. // short_para2 - name id of the town where the firm is located.
  690. //
  691. void NewsArray::firm_worn_out(int firmRecno)
  692. {
  693. Firm* firmPtr = firm_array[firmRecno];
  694. err_when( firmPtr->nation_recno != nation_array.player_recno );
  695. News* newsPtr = add_news( NEWS_FIRM_WORN_OUT, NEWS_NORMAL, firmPtr->nation_recno);
  696. if( !newsPtr ) // only news of nations that have contact with the player are added
  697. return;
  698. newsPtr->short_para1 = firmPtr->firm_id;
  699. if( firmPtr->closest_town_name_id )
  700. newsPtr->short_para2 = firmPtr->closest_town_name_id;
  701. else
  702. newsPtr->short_para2 = firmPtr->get_closest_town_name_id();
  703. }
  704. //------- End of function NewsArray::firm_worn_out -----//
  705. //------ Begin of function NewsArray::chat_msg -----//
  706. //
  707. // <int> fromNationRecno - recno of the nation from which this chat message is sent.
  708. // <char*> chatStr - pointer to the chat string.
  709. //
  710. // short_para1 - id. of the chat msg in Info::remote_chat_str_array[]
  711. //
  712. // nation_name1() - the nation from which this chat message is sent.
  713. //
  714. void NewsArray::chat_msg(int fromNationRecno, char* chatStr)
  715. {
  716. //---- add the chat string into Info::remote_chat_str_array[] ----//
  717. int useChatId=0;
  718. int minDate=info.game_date+1;
  719. for( int i=0; i<MAX_REMOTE_CHAT_STR ; i++ )
  720. {
  721. if( info.remote_chat_array[i].received_date < minDate ) // replace the oldest one
  722. {
  723. minDate = info.remote_chat_array[i].received_date;
  724. useChatId = i+1;
  725. }
  726. }
  727. if( useChatId )
  728. {
  729. ChatInfo* chatInfo = info.remote_chat_array+useChatId-1;
  730. chatInfo->received_date = info.game_date;
  731. chatInfo->from_nation_recno = fromNationRecno;
  732. strncpy( chatInfo->chat_str, chatStr, CHAT_STR_LEN );
  733. chatInfo->chat_str[CHAT_STR_LEN] = NULL;
  734. }
  735. //----------------------------------------------//
  736. News* newsPtr = add_news( NEWS_CHAT_MSG, NEWS_NORMAL, fromNationRecno);
  737. if( !newsPtr ) // only news of nations that have contact with the player are added
  738. return;
  739. newsPtr->short_para1 = useChatId;
  740. }
  741. //------- End of function NewsArray::chat_msg -----//
  742. //------ Begin of function NewsArray::multi_retire -----//
  743. //
  744. // This function is called when a human player retires.
  745. //
  746. void NewsArray::multi_retire(int nationRecno)
  747. {
  748. add_news( NEWS_MULTI_RETIRE, NEWS_NORMAL, nationRecno, nation_array.player_recno, 1 ); // add player recno as the 2nd parameter so this message is always displayed even if the player doesn't yet have contact with this nation
  749. }
  750. //------- End of function NewsArray::multi_retire -----//
  751. //------ Begin of function NewsArray::multi_quit_game -----//
  752. //
  753. // This function is called when a human player quits the game.
  754. //
  755. void NewsArray::multi_quit_game(int nationRecno)
  756. {
  757. add_news( NEWS_MULTI_QUIT_GAME, NEWS_NORMAL, nationRecno, nation_array.player_recno, 1 ); // add player recno as the 2nd parameter so this message is always displayed even if the player doesn't yet have contact with this nation
  758. }
  759. //------- End of function NewsArray::multi_quit_game -----//
  760. //------ Begin of function NewsArray::multi_save_game -----//
  761. //
  762. // This function is called when a human player calls for saving the game.
  763. //
  764. void NewsArray::multi_save_game()
  765. {
  766. add_news( NEWS_MULTI_SAVE_GAME, NEWS_NORMAL );
  767. }
  768. //------- End of function NewsArray::multi_save_game -----//
  769. //------ Begin of function NewsArray::multi_connection_lost -----//
  770. //
  771. // This function is called when a human player's connection has been lost.
  772. //
  773. void NewsArray::multi_connection_lost(int nationRecno)
  774. {
  775. add_news( NEWS_MULTI_CONNECTION_LOST, NEWS_NORMAL, nationRecno, nation_array.player_recno, 1 ); // add player recno as the 2nd parameter so this message is always displayed even if the player doesn't yet have contact with this nation
  776. }
  777. //------- End of function NewsArray::multi_connection_lost -----//
  778. //------ Begin of function NewsArray::add_news -----//
  779. //
  780. // Called by news processing function to set news parameters
  781. //
  782. // <int> newsId = the id. of the news
  783. // <int> newsType = news type
  784. // [int] nationRecno = nation recno of the news
  785. // [int] nationRecno2 = recno of the 2nd nation related to the news
  786. // [int] forceAdd = add this news anyway, regardless of whether
  787. // the nation has contact with the player or not
  788. // (default: 0)
  789. //
  790. // return : <News*> return the pointer of the News
  791. // NULL - the nation of the news does not have contact with the player
  792. //
  793. News* NewsArray::add_news(int newsId, int newsType, int nationRecno, int nationRecno2, int forceAdd)
  794. {
  795. if( nation_array.player_recno==0 ) // if the player has lost
  796. return NULL;
  797. //----- only news of nations that have contact with the player are added ----//
  798. if( nation_array.player_recno && !forceAdd )
  799. {
  800. Nation* playerNation = ~nation_array;
  801. if( nationRecno && nationRecno != nation_array.player_recno )
  802. {
  803. if( !playerNation->get_relation(nationRecno)->has_contact )
  804. return NULL;
  805. }
  806. if( nationRecno2 && nationRecno2 != nation_array.player_recno )
  807. {
  808. if( !playerNation->get_relation(nationRecno2)->has_contact )
  809. return NULL;
  810. }
  811. }
  812. //----------------------------------------------//
  813. static News news;
  814. news.id = newsId;
  815. news.type = newsType;
  816. news.news_date = info.game_date;
  817. news.loc_type = 0;
  818. Nation* nationPtr;
  819. if( nationRecno )
  820. {
  821. nationPtr = nation_array[nationRecno];
  822. news.nation_name_id1 = nationPtr->nation_name_id;
  823. news.nation_race_id1 = (char) nationPtr->race_id;
  824. news.nation_color1 = nationPtr->color_scheme_id;
  825. err_when( !news.nation_name_id1 || !news.nation_race_id1 );
  826. }
  827. else
  828. {
  829. news.nation_name_id1 = 0;
  830. news.nation_color1 = -1;
  831. }
  832. if( nationRecno2 )
  833. {
  834. nationPtr = nation_array[nationRecno2];
  835. news.nation_name_id2 = nationPtr->nation_name_id;
  836. news.nation_race_id2 = (char) nationPtr->race_id;
  837. news.nation_color2 = nationPtr->color_scheme_id;
  838. }
  839. else
  840. {
  841. news.nation_name_id2 = 0;
  842. news.nation_color2 = -1;
  843. }
  844. //--- if the news adding flag is turned off, don't add the news ---//
  845. if( news_add_flag )
  846. {
  847. //--- if no. of news reaches max., delete the oldest one ---//
  848. if( size() >= MAX_NEWS )
  849. {
  850. start();
  851. linkout();
  852. if( last_clear_recno > 1 )
  853. last_clear_recno--;
  854. }
  855. //--------- link in a new news ---------//
  856. linkin(&news);
  857. return (News*) get();
  858. }
  859. else
  860. {
  861. return &news;
  862. }
  863. }
  864. //------- End of function NewsArray::add_news -----//
  865. //------ Begin of function News::set_loc ------//
  866. //
  867. void News::set_loc(int xLoc, int yLoc, int locType, int locTypePara, int locTypePara2)
  868. {
  869. loc_type = locType;
  870. loc_type_para = locTypePara;
  871. loc_type_para2 = locTypePara2;
  872. err_when( loc_type_para < 0 );
  873. err_when( loc_type_para2 < 0 );
  874. loc_x = xLoc;
  875. loc_y = yLoc;
  876. }
  877. //------- End of function News::set_loc -------//
  878. //------ Begin of function News::is_loc_valid ------//
  879. //
  880. // Whether the location of this news is still valid.
  881. //
  882. int News::is_loc_valid()
  883. {
  884. if( !loc_type )
  885. return 0;
  886. int rc=0;
  887. if( loc_type == NEWS_LOC_TOWN )
  888. {
  889. if( !town_array.is_deleted(loc_type_para) )
  890. {
  891. Town* townPtr = town_array[loc_type_para];
  892. rc = townPtr->center_x == loc_x &&
  893. townPtr->center_y == loc_y;
  894. }
  895. }
  896. else if( loc_type == NEWS_LOC_FIRM )
  897. {
  898. if( !firm_array.is_deleted(loc_type_para) )
  899. {
  900. Firm* firmPtr = firm_array[loc_type_para];
  901. rc = firmPtr->center_x == loc_x &&
  902. firmPtr->center_y == loc_y;
  903. }
  904. }
  905. else if( loc_type == NEWS_LOC_UNIT )
  906. {
  907. if( !unit_array.is_deleted(loc_type_para) )
  908. {
  909. Unit* unitPtr = unit_array[loc_type_para];
  910. if( unitPtr->name_id == loc_type_para2 )
  911. {
  912. //--- if the unit is no longer belong to our nation ----//
  913. //--- only keep track of the unit for one month --------//
  914. if( unitPtr->nation_recno == nation_array.player_recno ||
  915. info.game_date < news_date + 30 )
  916. {
  917. if( unitPtr->get_cur_loc(loc_x, loc_y) )
  918. {
  919. Location* locPtr = world.get_loc(loc_x, loc_y);
  920. rc = locPtr->visit_level > 0;
  921. }
  922. }
  923. }
  924. }
  925. }
  926. else if( loc_type == NEWS_LOC_ANY )
  927. {
  928. rc = 1;
  929. }
  930. if( !rc )
  931. loc_type = 0;
  932. return rc;
  933. }
  934. //------- End of function News::is_loc_valid -------//