SCENARIO.CPP 127 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805
  1. //
  2. // Copyright 2020 Electronic Arts Inc.
  3. //
  4. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free
  5. // software: you can redistribute it and/or modify it under the terms of
  6. // the GNU General Public License as published by the Free Software Foundation,
  7. // either version 3 of the License, or (at your option) any later version.
  8. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed
  9. // in the hope that it will be useful, but with permitted additional restrictions
  10. // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
  11. // distributed with this program. You should have received a copy of the
  12. // GNU General Public License along with permitted additional restrictions
  13. // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
  14. //Mono_Printf("%d %s\n",__LINE__,__FILE__);
  15. /* $Header: /CounterStrike/SCENARIO.CPP 15 3/13/97 2:06p Steve_tall $ */
  16. /***********************************************************************************************
  17. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  18. ***********************************************************************************************
  19. * *
  20. * Project Name : Command & Conquer *
  21. * *
  22. * File Name : SCENARIO.CPP *
  23. * *
  24. * Programmer : Joe L. Bostic *
  25. * *
  26. * Start Date : September 10, 1993 *
  27. * *
  28. * Last Update : October 21, 1996 [JLB] *
  29. * *
  30. * This module handles the scenario reading and writing. Scenario related *
  31. * code that is executed between scenario play can also be here. *
  32. * *
  33. *---------------------------------------------------------------------------------------------*
  34. * Functions: *
  35. * Assign_Houses -- Assigns multiplayer houses to various players *
  36. * Clear_Flag_Spots -- Clears flag overlays off the map *
  37. * Clear_Scenario -- Clears all data in preparation for scenario load. *
  38. * Clip_Move -- moves in given direction from given cell; clips to map *
  39. * Clip_Scatter -- randomly scatters from given cell; won't fall off map *
  40. * Create_Units -- Creates infantry & units, for non-base multiplayer *
  41. * Do_Lose -- Display losing comments. *
  42. * Do_Restart -- Handle the restart mission process. *
  43. * Do_Win -- Display winning congratulations. *
  44. * Fill_In_Data -- Recreate all data that is not loaded with scenario. *
  45. * Post_Load_Game -- Fill in an inferred data from the game state. *
  46. * Read_Scenario -- Reads a scenario from disk. *
  47. * Read_Scenario_INI -- Read specified scenario INI file. *
  48. * Remove_AI_Players -- Removes the computer AI houses & their units *
  49. * Restate_Mission -- Handles restating the mission objective. *
  50. * Scan_Place_Object -- places an object >near< the given cell *
  51. * ScenarioClass::ScenarioClass -- Constructor for the scenario control object. *
  52. * ScenarioClass::Set_Global_To -- Set scenario global to value specified. *
  53. * Set_Scenario_Name -- Creates the INI scenario name string. *
  54. * Start_Scenario -- Starts the scenario. *
  55. * Write_Scenario_INI -- Write the scenario INI file. *
  56. * ScenarioClass::Do_BW_Fade -- Cause the palette to temporarily shift to B/W. *
  57. * ScenarioClass::Do_Fade_AI -- Process the palette fading effect. *
  58. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  59. #include "function.h"
  60. #ifdef WIN32
  61. #include "tcpip.h"
  62. #include "ccdde.h"
  63. extern bool SpawnedFromWChat;
  64. #endif
  65. extern int PreserveVQAScreen;
  66. void Display_Briefing_Text_GlyphX();
  67. extern void GlyphX_Assign_Houses(void); //ST - 8/8/2019 12:35PM
  68. extern bool UseGlyphXStartLocations; //ST - 3/31/2020 9:54AM
  69. //#include "WolDebug.h"
  70. #ifdef FIXIT_VERSION_3 // Stalemate games.
  71. #include "WolStrng.h"
  72. #endif
  73. static void Remove_AI_Players(void);
  74. static void Create_Units(bool official);
  75. static CELL Clip_Scatter(CELL cell, int maxdist);
  76. static CELL Clip_Move(CELL cell, FacingType facing, int dist);
  77. // Made this non-static so we can access it from the updated assign players function. ST - 8/9/2019 10:35AM
  78. int _build_tech[11] = {
  79. 2,2, // Tech level 0 and 1 are the same (tech 0 is never used).
  80. 4,
  81. 5,
  82. 7,
  83. 8,
  84. 9,
  85. 10,
  86. 11,
  87. 12,
  88. 13
  89. };
  90. #ifdef FRENCH
  91. #define TXT_HACKHACK "Accomplie"
  92. #endif
  93. #if defined(ENGLISH) || defined(GERMAN)
  94. #define TXT_HACKHACK Text_String(TXT_ACCOMPLISHED)
  95. #endif
  96. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  97. bool Is_Mission_Counterstrike (char *file_name);
  98. bool Is_Mission_Aftermath (char *file_name);
  99. #endif
  100. /***********************************************************************************************
  101. * ScenarioClass::ScenarioClass -- Constructor for the scenario control object. *
  102. * *
  103. * This constructs the default scenario control object. Normally, all the default values *
  104. * are meaningless since the act of starting a scenario will fill in all of the values with *
  105. * settings retrieved from the scenario control file. *
  106. * *
  107. * INPUT: none *
  108. * *
  109. * OUTPUT: none *
  110. * *
  111. * WARNINGS: none *
  112. * *
  113. * HISTORY: *
  114. * 07/03/1996 JLB : Created. *
  115. *=============================================================================================*/
  116. ScenarioClass::ScenarioClass(void) :
  117. Difficulty(DIFF_NORMAL),
  118. CDifficulty(DIFF_NORMAL),
  119. Timer(0),
  120. MissionTimer(0),
  121. ShroudTimer(TICKS_PER_MINUTE * Rule.ShroudRate),
  122. Scenario(1),
  123. Theater(THEATER_TEMPERATE),
  124. IntroMovie(VQ_NONE),
  125. BriefMovie(VQ_NONE),
  126. WinMovie(VQ_NONE),
  127. WinMovie2(VQ_NONE),
  128. WinMovie3(VQ_NONE),
  129. WinMovie4(VQ_NONE),
  130. LoseMovie(VQ_NONE),
  131. ActionMovie(VQ_NONE),
  132. TransitTheme(THEME_NONE),
  133. PlayerHouse(HOUSE_GREECE),
  134. CarryOverPercent(0),
  135. CarryOverMoney(0),
  136. CarryOverCap(0),
  137. Percent(0),
  138. BridgeCount(0),
  139. CarryOverTimer(0),
  140. IsBridgeChanged(false),
  141. IsGlobalChanged(false),
  142. IsToCarryOver(false),
  143. IsToInherit(false),
  144. IsTanyaEvac(false),
  145. IsFadingBW(false),
  146. IsFadingColor(false),
  147. IsEndOfGame(false),
  148. IsInheritTimer(false),
  149. IsNoSpyPlane(false),
  150. IsSkipScore(false),
  151. IsOneTimeOnly(false),
  152. IsNoMapSel(false),
  153. IsTruckCrate(false),
  154. IsMoneyTiberium(false),
  155. #ifdef FIXIT_VERSION_3 // For endgame auto-sonar pulse.
  156. #define AUTOSONAR_PERIOD TICKS_PER_SECOND * 40
  157. AutoSonarTimer( AUTOSONAR_PERIOD ),
  158. #endif
  159. FadeTimer(0)
  160. {
  161. for (int index = 0; index < ARRAY_SIZE(Waypoint); index++) {
  162. Waypoint[index] = -1;
  163. }
  164. strcpy(Description, "");
  165. strcpy(ScenarioName, "");
  166. strcpy(BriefingText, "");
  167. memset(GlobalFlags, '\0', sizeof(GlobalFlags));
  168. memset(Views, '\0', sizeof(Views));
  169. }
  170. /***********************************************************************************************
  171. * ScenarioClass::Do_BW_Fade -- Cause the palette to temporarily shift to B/W. *
  172. * *
  173. * This routine will start the palette to fade to B/W for a brief moment. *
  174. * *
  175. * INPUT: none *
  176. * *
  177. * OUTPUT: none *
  178. * *
  179. * WARNINGS: none *
  180. * *
  181. * HISTORY: *
  182. * 10/21/1996 JLB : Created. *
  183. *=============================================================================================*/
  184. void ScenarioClass::Do_BW_Fade(void)
  185. {
  186. IsFadingBW = true;
  187. IsFadingColor = false;
  188. FadeTimer = GRAYFADETIME;
  189. }
  190. /***********************************************************************************************
  191. * ScenarioClass::Do_Fade_AI -- Process the palette fading effect. *
  192. * *
  193. * This routine will handle the maintenance of the palette fading effect. It should be *
  194. * called once per game frame. *
  195. * *
  196. * INPUT: none *
  197. * *
  198. * OUTPUT: none *
  199. * *
  200. * WARNINGS: none *
  201. * *
  202. * HISTORY: *
  203. * 10/21/1996 JLB : Created. *
  204. *=============================================================================================*/
  205. void ScenarioClass::Do_Fade_AI(void)
  206. {
  207. if (IsFadingColor) {
  208. if (FadeTimer == 0) {
  209. IsFadingColor = false;
  210. }
  211. fixed newsat = Options.Get_Saturation() * fixed(GRAYFADETIME-FadeTimer, GRAYFADETIME);
  212. Options.Adjust_Palette(OriginalPalette, GamePalette, Options.Get_Brightness(), newsat, Options.Get_Tint(), Options.Get_Contrast());
  213. GamePalette.Set();
  214. }
  215. if (IsFadingBW) {
  216. if (FadeTimer == 0) {
  217. IsFadingBW = false;
  218. }
  219. fixed newsat = Options.Get_Saturation() * fixed(FadeTimer, GRAYFADETIME);
  220. Options.Adjust_Palette(OriginalPalette, GamePalette, Options.Get_Brightness(), newsat, Options.Get_Tint(), Options.Get_Contrast());
  221. GamePalette.Set();
  222. if (!IsFadingBW) {
  223. IsFadingColor = true;
  224. FadeTimer = GRAYFADETIME;
  225. }
  226. }
  227. }
  228. /***********************************************************************************************
  229. * ScenarioClass::Set_Global_To -- Set scenario global to value specified. *
  230. * *
  231. * This routine will set the global flag to the falue (true/false) specified. It will *
  232. * also scan for and spring any triggers that are dependant upon that global. *
  233. * *
  234. * INPUT: global -- The global flag to change. *
  235. * *
  236. * value -- The value to change the global flag to. *
  237. * *
  238. * OUTPUT: Returns with the previous value of the flag. *
  239. * *
  240. * WARNINGS: none *
  241. * *
  242. * HISTORY: *
  243. * 07/26/1996 JLB : Created. *
  244. *=============================================================================================*/
  245. bool ScenarioClass::Set_Global_To(int global, bool value)
  246. {
  247. if ((unsigned)global < ARRAY_SIZE(Scen.GlobalFlags)) {
  248. bool previous = GlobalFlags[global];
  249. if (previous != value) {
  250. GlobalFlags[global] = value;
  251. IsGlobalChanged = true;
  252. /*
  253. ** Special case to scan through all triggers and if any are found that depend on this
  254. ** global being set/cleared, then if there is an elapsed time event associated, it
  255. ** will be reset at this time.
  256. */
  257. for (int index = 0; index < Triggers.Count(); index++) {
  258. TriggerClass * tp = Triggers.Ptr(index);
  259. if ((tp->Class->Event1.Event == TEVENT_GLOBAL_SET || tp->Class->Event1.Event == TEVENT_GLOBAL_CLEAR) && tp->Class->Event1.Data.Value == global) {
  260. tp->Class->Event2.Reset(tp->Event1);
  261. }
  262. if ((tp->Class->Event2.Event == TEVENT_GLOBAL_SET || tp->Class->Event2.Event == TEVENT_GLOBAL_CLEAR) && tp->Class->Event2.Data.Value == global) {
  263. tp->Class->Event1.Reset(tp->Event1);
  264. }
  265. }
  266. }
  267. return(previous);
  268. }
  269. return(false);
  270. }
  271. /***********************************************************************************************
  272. * Start_Scenario -- Starts the scenario. *
  273. * *
  274. * This routine will start the scenario. In addition to loading the scenario data, it will *
  275. * play the briefing and action movies. *
  276. * *
  277. * INPUT: root -- Pointer to the filename root for this scenario (e.g., "SCG01EA"). *
  278. * *
  279. * briefing -- Should the briefing be played? Normally this is true except when the *
  280. * scenario is restarting. *
  281. * *
  282. * OUTPUT: Was the scenario started without error? *
  283. * *
  284. * WARNINGS: none *
  285. * *
  286. * HISTORY: *
  287. * 07/04/1995 JLB : Created. *
  288. *=============================================================================================*/
  289. bool Start_Scenario(char * name, bool briefing)
  290. {
  291. //BG Theme.Queue_Song(THEME_QUIET);
  292. Theme.Stop();
  293. IsTanyaDead = SaveTanya;
  294. if (!Read_Scenario(name)) {
  295. return(false);
  296. }
  297. /* Swap Lt. Blue and Blue color remaps in skirmish/multiplayer */
  298. if (Session.Type != GAME_NORMAL) {
  299. RemapControlType temp;
  300. memcpy(&temp, &ColorRemaps[PCOLOR_LTBLUE], sizeof(RemapControlType));
  301. memcpy(&ColorRemaps[PCOLOR_LTBLUE], &ColorRemaps[PCOLOR_BLUE], sizeof(RemapControlType));
  302. memcpy(&ColorRemaps[PCOLOR_BLUE], &temp, sizeof(RemapControlType));
  303. }
  304. /*
  305. ** Play the winning movie and then start the next scenario.
  306. */
  307. RequiredCD = -1;
  308. // if (RequiredCD != -2 && Session.Type == GAME_NORMAL) {
  309. // if (Scen.Scenario == 1)
  310. // RequiredCD = -1;
  311. // else {
  312. // if((Scen.Scenario >= 20 && Scen.ScenarioName[2] == 'G' || Scen.ScenarioName[2] == 'U') || Scen.ScenarioName[2] == 'A'
  313. // || (Scen.ScenarioName[2] == 'M' && Scen.Scenario >= 25))
  314. // RequiredCD = 2;
  315. // else if(Scen.ScenarioName[2] == 'U')
  316. // RequiredCD = 1;
  317. // else if(Scen.ScenarioName[2] == 'G')
  318. // RequiredCD = 0;
  319. // }
  320. //
  321. //#ifdef FIXIT_FORCE_CD
  322. // Forces the CD to be inserted according to the scenario being loaded.
  323. //Hide_Mouse();
  324. //VisiblePage.Clear();
  325. //Show_Mouse();
  326. //GamePalette.Set();
  327. //if (!Force_CD_Available(RequiredCD)) {
  328. // Prog_End();
  329. // exit(EXIT_FAILURE);
  330. //}
  331. //#endif
  332. // }
  333. Theme.Stop();
  334. if (briefing) {
  335. Hide_Mouse();
  336. VisiblePage.Clear();
  337. Show_Mouse();
  338. Play_Movie(Scen.IntroMovie);
  339. Play_Movie(Scen.BriefMovie);
  340. }
  341. /*
  342. ** If there's no briefing movie, restate the mission at the beginning.
  343. */
  344. #if 1 // 12/04/2019 - LLL
  345. if (Session.Type == GAME_NORMAL && Scen.BriefMovie == VQ_NONE) {
  346. Display_Briefing_Text_GlyphX();
  347. }
  348. #else
  349. char buffer[25];
  350. if (Scen.BriefMovie != VQ_NONE) {
  351. sprintf(buffer, "%s.VQA", VQName[Scen.BriefMovie]);
  352. }
  353. if (Session.Type == GAME_NORMAL && Scen.BriefMovie == VQ_NONE || !CCFileClass(buffer).Is_Available()) {
  354. /*
  355. ** Make sure the mouse is visible before showing the restatement.
  356. */
  357. while(Get_Mouse_State()) {
  358. Show_Mouse();
  359. }
  360. Restate_Mission(Scen.ScenarioName, TXT_OK, TXT_NONE);
  361. }
  362. #endif
  363. if (briefing) {
  364. Hide_Mouse();
  365. VisiblePage.Clear();
  366. Show_Mouse();
  367. Play_Movie(Scen.ActionMovie, Scen.TransitTheme);
  368. }
  369. if (Scen.TransitTheme == THEME_NONE) {
  370. Theme.Queue_Song(THEME_FIRST);
  371. }
  372. /*
  373. ** Set the options values, since the palette has been initialized by Read_Scenario
  374. */
  375. Options.Set();
  376. return(true);
  377. }
  378. /***********************************************************************************************
  379. * Set_Scenario_Difficulty -- Sets the difficulty of the scenario. *
  380. * *
  381. * Updates the player's difficulty in single-player mode. *
  382. * *
  383. * INPUT: difficulty -- Scenario difficulty *
  384. * *
  385. * OUTPUT: none *
  386. * *
  387. * WARNINGS: Only works in single-player. *
  388. * Must call Start_Scenario first to initialize the player. *
  389. * *
  390. * HISTORY: *
  391. * 10/02/2019 SKY : Created. *
  392. *=============================================================================================*/
  393. void Set_Scenario_Difficulty(int difficulty)
  394. {
  395. if (Session.Type == GAME_NORMAL) {
  396. switch (difficulty) {
  397. case 0:
  398. PlayerPtr->Assign_Handicap(DIFF_EASY);
  399. break;
  400. case 1:
  401. PlayerPtr->Assign_Handicap(DIFF_NORMAL);
  402. break;
  403. case 2:
  404. PlayerPtr->Assign_Handicap(DIFF_HARD);
  405. break;
  406. default:
  407. break;
  408. }
  409. }
  410. }
  411. /***********************************************************************************************
  412. * Read_Scenario -- Reads a scenario from disk. *
  413. * *
  414. * This will read a scenario from disk. Use this to begin a scenario. *
  415. * It doesn't perform any rendering, it merely sets up the system *
  416. * with the proper data. Setting of the right game state will start *
  417. * the scenario running. *
  418. * *
  419. * INPUT: root -- Scenario root filename *
  420. * *
  421. * OUTPUT: none *
  422. * *
  423. * WARNINGS: You must clear out the system variables before calling *
  424. * this function. Use the Clear_Scenario() function. *
  425. * It is assumed that Scenario is set to the current scenario number. *
  426. * *
  427. * HISTORY: *
  428. * 07/22/1991 : Created. *
  429. * 02/03/1992 JLB : Uses house identification. *
  430. *=============================================================================================*/
  431. bool Read_Scenario(char * name)
  432. {
  433. BStart(BENCH_SCENARIO);
  434. Clear_Scenario();
  435. ScenarioInit++;
  436. if (Read_Scenario_INI(name)) {
  437. #ifdef FIXIT_CSII // ajw - Added runtime check for Aftermath to skirmish mode case.
  438. bool readini = false;
  439. switch(Session.Type) {
  440. case GAME_NORMAL:
  441. readini = false;
  442. break;
  443. case GAME_SKIRMISH:
  444. #ifdef FIXIT_VERSION_3
  445. readini = bAftermathMultiplayer;
  446. #endif
  447. break;
  448. case GAME_INTERNET:
  449. #ifndef FIXIT_VERSION_3 // Loading of Aftermath rules depends on bAftermathMultiplayer now.
  450. if (Is_Mission_Counterstrike(name)) {
  451. readini = false; // Don't allow AM units on a CS map in WChat
  452. break;
  453. }
  454. #endif // ( Note lack of break; )
  455. default:
  456. #ifdef FIXIT_VERSION_3
  457. readini = bAftermathMultiplayer;
  458. #else
  459. if (PlayingAgainstVersion >= VERSION_AFTERMATH_CS) {
  460. readini = true;
  461. }
  462. #endif
  463. break;
  464. }
  465. if(readini) {
  466. /*
  467. ** Find out if the CD in the current drive is the Aftermath disc.
  468. */
  469. #ifdef FIXIT_VERSION_3
  470. int cd_index = Get_CD_Index(CCFileClass::Get_CD_Drive(), 1*60);
  471. if( !( Using_DVD() && cd_index == 5 ) && cd_index != 3 ) {
  472. #else
  473. if(Get_CD_Index(CCFileClass::Get_CD_Drive(), 1*60) != 3) {
  474. #endif
  475. GamePalette.Set(FADE_PALETTE_FAST, Call_Back);
  476. RequiredCD = 3;
  477. if (!Force_CD_Available(RequiredCD)) { // force Aftermath CD in drive.
  478. #ifndef WOLAPI_INTEGRATION
  479. #ifdef WIN32
  480. if(Special.IsFromWChat || SpawnedFromWChat) {
  481. char packet[10] = {"Hello"};
  482. Send_Data_To_DDE_Server (packet, strlen(packet), DDEServerClass::DDE_CONNECTION_FAILED);
  483. }
  484. #endif
  485. #endif
  486. if (!RunningAsDLL) { //PG
  487. Emergency_Exit(EXIT_FAILURE);
  488. }
  489. }
  490. }
  491. CCINIClass ini;
  492. if (ini.Load(CCFileClass("MPLAYER.INI"), false)) {
  493. Rule.General(ini);
  494. Rule.Recharge(ini);
  495. Rule.AI(ini);
  496. Rule.Powerups(ini);
  497. Rule.Land_Types(ini);
  498. Rule.Themes(ini);
  499. Rule.IQ(ini);
  500. Rule.Objects(ini);
  501. Rule.Difficulty(ini);
  502. }
  503. }
  504. #endif
  505. Fill_In_Data();
  506. Map.Set_View_Dimensions(0, 0, Map.MapCellWidth, Map.MapCellHeight);
  507. } else {
  508. #if (1)
  509. char message[200];
  510. if (name) {
  511. sprintf(message, "Failed to load scenario %s", name);
  512. GlyphX_Debug_Print(message);
  513. } else {
  514. GlyphX_Debug_Print("Failed to load scenario");
  515. }
  516. #else
  517. GamePalette.Set(FADE_PALETTE_FAST, Call_Back);
  518. // Fade_Palette_To(GamePalette, FADE_PALETTE_FAST, Call_Back);
  519. Show_Mouse();
  520. WWMessageBox().Process(TXT_UNABLE_READ_SCENARIO);
  521. Hide_Mouse();
  522. #endif
  523. BEnd(BENCH_SCENARIO);
  524. return(false);
  525. }
  526. ScenarioInit--;
  527. BEnd(BENCH_SCENARIO);
  528. return(true);
  529. }
  530. /***********************************************************************************************
  531. * Fill_In_Data -- Recreate all data that is not loaded with scenario. *
  532. * *
  533. * This routine is called after the INI file for the scenario has been processed. It will *
  534. * infer the game state from the scenario INI data. *
  535. * *
  536. * INPUT: none *
  537. * *
  538. * OUTPUT: none *
  539. * *
  540. * WARNINGS: none *
  541. * *
  542. * HISTORY: *
  543. * 10/07/1992 JLB : Created. *
  544. *=============================================================================================*/
  545. void Fill_In_Data(void)
  546. {
  547. /*
  548. ** The basic scenario data load does not contain the full set of
  549. ** game data. We now must fill in the missing pieces.
  550. */
  551. ScenarioInit++;
  552. int index;
  553. for (index = 0; index < Buildings.Count(); index++) {
  554. Buildings.Ptr(index)->Update_Buildables();
  555. }
  556. Map.Flag_To_Redraw(true);
  557. /*
  558. ** Reset the movement zones according to the terrain passability.
  559. */
  560. Map.Zone_Reset(MZONEF_ALL);
  561. #ifdef WIN32
  562. /*
  563. ** Since the sidebar starts up activated, adjust the home start position so that
  564. ** the right edge of the map will still be visible.
  565. */
  566. if (!Debug_Map) {
  567. Map.SidebarClass::Activate(1);
  568. // if (Session.Type == GAME_NORMAL) {
  569. Scen.Views[0] = Scen.Views[1] = Scen.Views[2] = Scen.Views[3] = Scen.Waypoint[WAYPT_HOME];
  570. Map.Set_Tactical_Position(Cell_Coord((Scen.Waypoint[WAYPT_HOME] - (MAP_CELL_W * 4 * RESFACTOR)) - (5*RESFACTOR)));
  571. // }
  572. }
  573. #endif
  574. /*
  575. ** Handle any data resetting that can be safely inferred from the actual
  576. ** data that has been loaded.
  577. */
  578. /*
  579. ** Distribute the trigger pointers to the appropriate working lists.
  580. */
  581. for (index = 0; index < TriggerTypes.Count(); index++) {
  582. TriggerTypeClass * tp = TriggerTypes.Ptr(index);
  583. assert(tp != NULL);
  584. if (tp->Attaches_To() & ATTACH_MAP) {
  585. MapTriggers.Add(Find_Or_Make(tp));
  586. }
  587. if (tp->Attaches_To() & ATTACH_GENERAL) {
  588. LogicTriggers.Add(Find_Or_Make(tp));
  589. }
  590. if (tp->Attaches_To() & ATTACH_HOUSE) {
  591. HouseTriggers[tp->House].Add(Find_Or_Make(tp));
  592. }
  593. }
  594. ScenarioInit--;
  595. /*
  596. ** Now go through and set all the cells ringing the map to be visible, so
  597. ** we won't get the wall of shadow at the edge of the map.
  598. */
  599. int x,y;
  600. for (x = Map.MapCellX-1; x < ((Map.MapCellX + Map.MapCellWidth + 1)); x++) {
  601. Map[XY_Cell(x, Map.MapCellY-1)].IsVisible =
  602. Map[XY_Cell(x, Map.MapCellY-1)].IsMapped = true;
  603. Map[XY_Cell(x, Map.MapCellY+Map.MapCellHeight)].IsVisible =
  604. Map[XY_Cell(x, Map.MapCellY+Map.MapCellHeight)].IsMapped = true;
  605. }
  606. for (y = Map.MapCellY; y < (Map.MapCellY + Map.MapCellHeight); y++) {
  607. Map[XY_Cell(Map.MapCellX-1, y)].IsVisible =
  608. Map[XY_Cell(Map.MapCellX-1, y)].IsMapped = true;
  609. Map[XY_Cell(Map.MapCellX+Map.MapCellWidth, y)].IsVisible =
  610. Map[XY_Cell(Map.MapCellX+Map.MapCellWidth, y)].IsMapped = true;
  611. }
  612. /*
  613. ** If inheriting from a previous scenario was indicated, then create the carry over
  614. ** objects at this time.
  615. */
  616. if (Scen.IsToInherit) {
  617. CarryoverClass * cptr = Carryover;
  618. while (cptr != NULL) {
  619. cptr->Create();
  620. cptr = (CarryoverClass *)cptr->Get_Next();
  621. }
  622. }
  623. /*
  624. ** The "allow win" action is a special case that is handled here. The total number
  625. ** of triggers that have this action must be recorded.
  626. */
  627. for (index = 0; index < TriggerTypes.Count(); index++) {
  628. TriggerTypeClass * tp = TriggerTypes.Ptr(index);
  629. if (tp->Action1.Action == TACTION_ALLOWWIN ||
  630. (tp->ActionControl != MULTI_ONLY && tp->Action2.Action == TACTION_ALLOWWIN)) {
  631. HouseClass::As_Pointer(tp->House)->Blockage++;
  632. }
  633. }
  634. /*
  635. ** Move available money to silos, if the scenario flag so indicates.
  636. */
  637. if (Scen.IsMoneyTiberium) {
  638. for (HousesType house = HOUSE_FIRST; house < HOUSE_COUNT; house++) {
  639. HouseClass * hptr = HouseClass::As_Pointer(house);
  640. if (hptr != NULL) {
  641. int tomove = hptr->Capacity - hptr->Tiberium;
  642. hptr->Credits -= tomove;
  643. hptr->Tiberium += tomove;
  644. }
  645. }
  646. }
  647. /*
  648. ** Count all non-destroyed bridges on the map.
  649. */
  650. Scen.BridgeCount = Map.Intact_Bridge_Count();
  651. Map.All_To_Look(PlayerPtr, true);
  652. }
  653. /***********************************************************************************************
  654. * Post_Load_Game -- Fill in an inferred data from the game state. *
  655. * *
  656. * This routine is typically called after a game has been loaded. Some working data lists *
  657. * can be rebuild from the game state. This working data is rebuilt rather than being *
  658. * stored with the game data file. *
  659. * *
  660. * INPUT: load_multi -- true if we're loading a multiplayer game *
  661. * *
  662. * OUTPUT: none *
  663. * *
  664. * WARNINGS: Although it is safe to call this routine whenever, it is only needed after a *
  665. * game load. *
  666. * *
  667. * HISTORY: *
  668. * 11/30/1995 JLB : Created. *
  669. *=============================================================================================*/
  670. void Post_Load_Game(int load_multi)
  671. {
  672. Map.Set_View_Dimensions(0, 0, Map.MapCellWidth, Map.MapCellHeight);
  673. //
  674. // Do NOT call Overpass if we're loading a multiplayer game; it calls the
  675. // random # generator, which throws the games out of sync if they were
  676. // saved on different frame #'s.
  677. //
  678. if (!load_multi) {
  679. Map.Overpass();
  680. }
  681. Scen.BridgeCount = Map.Intact_Bridge_Count();
  682. Map.Zone_Reset(MZONEF_ALL);
  683. }
  684. /***********************************************************************************************
  685. * Clear_Scenario -- Clears all data in preparation for scenario load. *
  686. * *
  687. * This routine will clear out all data specific to a scenario in *
  688. * preparation for a subsequent scenario data load. This will free *
  689. * all units, animations, and icon maps. *
  690. * *
  691. * INPUT: none *
  692. * *
  693. * OUTPUT: none *
  694. * *
  695. * WARNINGS: none *
  696. * *
  697. * HISTORY: *
  698. * 07/22/1991 : Created. *
  699. * 03/21/1992 JLB : Changed buffer allocations, so changes memset code. *
  700. * 07/13/1995 JLB : End count down moved here. *
  701. *=============================================================================================*/
  702. void Clear_Scenario(void)
  703. {
  704. // TCTCTC -- possibly just use in-place new of scenario object?
  705. Scen.MissionTimer = 0;
  706. Scen.MissionTimer.Stop();
  707. Scen.Timer = 0;
  708. Scen.ShroudTimer = 0;
  709. Scen.IntroMovie = VQ_NONE;
  710. Scen.BriefMovie = VQ_NONE;
  711. Scen.WinMovie = VQ_NONE;
  712. Scen.WinMovie2 = VQ_NONE;
  713. Scen.WinMovie3 = VQ_NONE;
  714. Scen.WinMovie4 = VQ_NONE;
  715. Scen.LoseMovie = VQ_NONE;
  716. Scen.ActionMovie = VQ_NONE;
  717. Scen.IsNoSpyPlane = false;
  718. Scen.IsTanyaEvac = false;
  719. Scen.IsEndOfGame = false;
  720. Scen.IsInheritTimer = false;
  721. Scen.IsToCarryOver = false;
  722. Scen.IsSkipScore = false;
  723. Scen.IsOneTimeOnly = false;
  724. Scen.IsTruckCrate = false;
  725. Scen.IsMoneyTiberium = false;
  726. Scen.IsNoMapSel = false;
  727. Scen.CarryOverCap = 0;
  728. Scen.CarryOverPercent = 0;
  729. Scen.TransitTheme = THEME_NONE;
  730. Scen.Percent = 0;
  731. memset(Scen.GlobalFlags, 0, sizeof(Scen.GlobalFlags));
  732. MapTriggers.Clear();
  733. LogicTriggers.Clear();
  734. for (HousesType house = HOUSE_FIRST; house < HOUSE_COUNT; house++) {
  735. HouseTriggers[house].Clear();
  736. }
  737. /*
  738. ** Call everyone's Init routine, except the Map's; for the Map, only call
  739. ** MapClass::Init, which clears the Cell array. The Display::Init requires
  740. ** a Theater argument, and the theater is not known at this point; also, it
  741. ** would reload MixFiles, which isn't desired. Display::Read_INI calls its
  742. ** own Init, which will Init the entire Map hierarchy.
  743. */
  744. Map.Init_Clear();
  745. Score.Init();
  746. Logic.Init();
  747. HouseClass::Init();
  748. ObjectClass::Init();
  749. TeamTypeClass::Init();
  750. TeamClass::Init();
  751. TriggerClass::Init();
  752. TriggerTypeClass::Init();
  753. AircraftClass::Init();
  754. AnimClass::Init();
  755. BuildingClass::Init();
  756. BulletClass::Init();
  757. InfantryClass::Init();
  758. OverlayClass::Init();
  759. SmudgeClass::Init();
  760. TemplateClass::Init();
  761. TerrainClass::Init();
  762. UnitClass::Init();
  763. VesselClass::Init();
  764. FactoryClass::Init();
  765. Base.Init();
  766. CurrentObject.Clear_All();
  767. for (int index = 0; index < WAYPT_COUNT; index++) {
  768. Scen.Waypoint[index] = -1;
  769. }
  770. #ifdef FIXIT_VERSION_3 // For endgame auto-sonar pulse.
  771. bAutoSonarPulse = false;
  772. #endif
  773. #ifdef FIXIT_VERSION_3 // Stalemate games.
  774. Scen.bLocalProposesDraw = false;
  775. Scen.bOtherProposesDraw = false;
  776. #endif
  777. }
  778. /***********************************************************************************************
  779. * Do_Win -- Display winning congratulations. *
  780. * *
  781. * Perform the win the mission process. This will display any winning movies and the score *
  782. * screen. Followed by the map selection screen and then the load of the new scenario. *
  783. * *
  784. * INPUT: none *
  785. * *
  786. * OUTPUT: none *
  787. * *
  788. * WARNINGS: none *
  789. * *
  790. * HISTORY: *
  791. * 08/05/1992 JLB : Created. *
  792. * 01/01/1995 JLB : Carries money forward into next scenario. *
  793. *=============================================================================================*/
  794. void Do_Win(void)
  795. {
  796. Map.Set_Default_Mouse(MOUSE_NORMAL);
  797. Hide_Mouse();
  798. Theme.Queue_Song(THEME_QUIET);
  799. /*
  800. ** If this is a multiplayer game, clear the game's name so we won't respond
  801. ** to game queries any more (in Call_Back)
  802. */
  803. if (Session.Type != GAME_NORMAL) {
  804. Session.GameName[0] = 0;
  805. }
  806. /*
  807. ** Determine a cosmetic center point for the text.
  808. */
  809. int x = Map.TacPixelX + (Lepton_To_Pixel(Map.TacLeptonWidth)/2);
  810. /*
  811. ** Hack section. If it's allied scenario 10, variation A, then skip the
  812. ** score and map selection, don't increment scenario, and set it to
  813. ** variation B.
  814. */
  815. #ifdef FIXIT_ANTS
  816. if (Session.Type != GAME_NORMAL || !Scen.IsSkipScore || AntsEnabled) {
  817. #else
  818. if (Session.Type != GAME_NORMAL || !Scen.IsSkipScore ) {
  819. #endif //FIXIT_ANTS
  820. /*
  821. ** Announce win to player.
  822. */
  823. Set_Logic_Page(SeenBuff);
  824. Map.Flag_To_Redraw (true);
  825. Map.Render();
  826. #ifdef WIN32
  827. Fancy_Text_Print(TXT_SCENARIO_WON, x, 90*RESFACTOR, &ColorRemaps[PCOLOR_RED], TBLACK, TPF_CENTER|TPF_VCR|TPF_USE_GRAD_PAL|TPF_DROPSHADOW);
  828. #else
  829. Fancy_Text_Print(TXT_MISSION, x, 90*RESFACTOR, &ColorRemaps[PCOLOR_RED], TBLACK, TPF_CENTER|TPF_VCR|TPF_USE_GRAD_PAL|TPF_DROPSHADOW);
  830. Fancy_Text_Print(TXT_HACKHACK, x, 110*RESFACTOR, &ColorRemaps[PCOLOR_RED], TBLACK, TPF_CENTER|TPF_VCR|TPF_USE_GRAD_PAL|TPF_DROPSHADOW);
  831. #endif
  832. CountDownTimer = TIMER_SECOND * 3;
  833. while (Is_Speaking()) {};
  834. Speak(VOX_ACCOMPLISHED);
  835. while (CountDownTimer || Is_Speaking()) {
  836. Call_Back();
  837. }
  838. }
  839. /*
  840. ** Stop here if this is a multiplayer game.
  841. */
  842. if (Session.Type != GAME_NORMAL) {
  843. if (!Session.Play) {
  844. Session.GamesPlayed++;
  845. Multi_Score_Presentation();
  846. Session.CurGame++;
  847. if (Session.CurGame >= MAX_MULTI_GAMES) {
  848. Session.CurGame = MAX_MULTI_GAMES - 1;
  849. }
  850. }
  851. GameActive = 0;
  852. Show_Mouse();
  853. return;
  854. }
  855. Hide_Mouse();
  856. VisiblePage.Clear();
  857. Show_Mouse();
  858. Play_Movie(Scen.WinMovie);
  859. Play_Movie(Scen.WinMovie2);
  860. Play_Movie(Scen.WinMovie3);
  861. Play_Movie(Scen.WinMovie4);
  862. Keyboard->Clear();
  863. SaveTanya = IsTanyaDead;
  864. Scen.CarryOverTimer = Scen.MissionTimer;
  865. // int timer = Scen.MissionTimer;
  866. /*
  867. ** Do the ending screens only if not playing back a recorded game.
  868. */
  869. if (!Session.Play) {
  870. /*
  871. ** If the score presentation should be performed, then do
  872. ** so now.
  873. */
  874. Keyboard->Clear();
  875. if (!Scen.IsSkipScore) {
  876. Score.Presentation();
  877. }
  878. if (Scen.IsOneTimeOnly) {
  879. GameActive = false;
  880. Show_Mouse();
  881. #ifdef FIXIT_ANTS
  882. AntsEnabled = false;
  883. // Mono_Printf("Scenario.cpp one time only antsenabled is false\n");
  884. #endif
  885. return;
  886. }
  887. /*
  888. ** If this scenario is flagged as ending the game then print the credits and exit.
  889. */
  890. #if (0)//PG
  891. if (Scen.IsEndOfGame) {
  892. if (PlayerPtr->ActLike == HOUSE_USSR) {
  893. Play_Movie(VQ_SOVFINAL);
  894. } else {
  895. Play_Movie(VQ_ALLYEND);
  896. }
  897. Show_Who_Was_Responsible();
  898. GameActive = false;
  899. Show_Mouse();
  900. #ifdef FIXIT_ANTS
  901. AntsEnabled = false;
  902. #endif
  903. return;
  904. }
  905. #endif
  906. /*
  907. ** Hack section. If it's allied scenario 10, variation A, then skip the
  908. ** score and map selection, don't increment scenario, and set it to
  909. ** variation B.
  910. */
  911. if (Scen.IsNoMapSel) {
  912. // force it to play the second half of scenario 10
  913. #ifdef FIXIT_ANTS
  914. if (AntsEnabled) {
  915. char scenarioname[24];
  916. strcpy(scenarioname, Scen.ScenarioName);
  917. char buf[10];
  918. Scen.Scenario++;
  919. sprintf(buf, "%02d", Scen.Scenario);
  920. memcpy(&scenarioname[3], buf, 2);
  921. Scen.Set_Scenario_Name(scenarioname);
  922. } else {
  923. Scen.ScenarioName[6] = 'B';
  924. }
  925. #else
  926. Scen.ScenarioName[6] = 'B';
  927. #endif
  928. } else {
  929. Scen.Set_Scenario_Name(Map_Selection());
  930. }
  931. Keyboard->Clear();
  932. }
  933. Scen.CarryOverMoney = PlayerPtr->Credits;
  934. /*
  935. ** If requested, record the scenario's objects in the carry over list
  936. ** for possible use in a future scenario.
  937. */
  938. if (Scen.IsToCarryOver) {
  939. /*
  940. ** First delete any existing carry over list. Any old list will be
  941. ** blasted over by the new list -- there is only one logic carryover
  942. ** list to be maintained.
  943. */
  944. while (Carryover) {
  945. CarryoverClass * cptr = (CarryoverClass *)Carryover->Get_Next();
  946. Carryover->Remove();
  947. delete Carryover;
  948. Carryover = cptr;
  949. }
  950. /*
  951. ** Record all objects, that are to be part of the carry over set, into
  952. ** the carry over list.
  953. */
  954. for (int building_index = 0; building_index < Buildings.Count(); building_index++) {
  955. BuildingClass * building = Buildings.Ptr(building_index);
  956. if (building && !building->IsInLimbo && building->Strength > 0) {
  957. CarryoverClass * cptr = new CarryoverClass(building);
  958. if (cptr) {
  959. if (Carryover) {
  960. cptr->Add_Tail(*Carryover);
  961. } else {
  962. Carryover = cptr;
  963. }
  964. }
  965. }
  966. }
  967. for (int unit_index = 0; unit_index < Units.Count(); unit_index++) {
  968. UnitClass * unit = Units.Ptr(unit_index);
  969. if (unit && !unit->IsInLimbo && unit->Strength > 0) {
  970. CarryoverClass * cptr = new CarryoverClass(unit);
  971. if (cptr) {
  972. if (Carryover) {
  973. cptr->Add_Tail(*Carryover);
  974. } else {
  975. Carryover = cptr;
  976. }
  977. }
  978. }
  979. }
  980. for (int infantry_index = 0; infantry_index < Infantry.Count(); infantry_index++) {
  981. InfantryClass * infantry = Infantry.Ptr(infantry_index);
  982. if (infantry && !infantry->IsInLimbo && infantry->Strength > 0) {
  983. CarryoverClass * cptr = new CarryoverClass(infantry);
  984. if (cptr) {
  985. if (Carryover) {
  986. cptr->Add_Tail(*Carryover);
  987. } else {
  988. Carryover = cptr;
  989. }
  990. }
  991. }
  992. }
  993. for (int vessel_index = 0; vessel_index < Vessels.Count(); vessel_index++) {
  994. VesselClass * vessel = Vessels.Ptr(vessel_index);
  995. if (vessel && !vessel->IsInLimbo && vessel->Strength > 0) {
  996. CarryoverClass * cptr = new CarryoverClass(vessel);
  997. if (cptr) {
  998. if (Carryover) {
  999. cptr->Add_Tail(*Carryover);
  1000. } else {
  1001. Carryover = cptr;
  1002. }
  1003. }
  1004. }
  1005. }
  1006. }
  1007. /*
  1008. ** Generate a new scenario filename
  1009. */
  1010. // Scen.Set_Scenario_Name(Scen.Scenario, Scen.ScenPlayer, Scen.ScenDir, Scen.ScenVar);
  1011. Start_Scenario(Scen.ScenarioName);
  1012. /*
  1013. ** If the mission timer is to be inheriteded from the previous scenario then do it now.
  1014. */
  1015. if (Scen.IsInheritTimer) {
  1016. Scen.MissionTimer = Scen.CarryOverTimer;
  1017. Scen.MissionTimer.Start();
  1018. }
  1019. // PlayerPtr->NukePieces = nukes;
  1020. Map.Render();
  1021. GamePalette.Set(FADE_PALETTE_FAST, Call_Back);
  1022. // Fade_Palette_To(GamePalette, FADE_PALETTE_FAST, Call_Back);
  1023. Show_Mouse();
  1024. }
  1025. /***********************************************************************************************
  1026. * Do_Lose -- Display losing comments. *
  1027. * *
  1028. * Performs the lose mission processing. This will generally display a "would you like *
  1029. * to replay" dialog and then either reload the scenario or set flags such that the main *
  1030. * menu will appear. *
  1031. * *
  1032. * INPUT: none *
  1033. * *
  1034. * OUTPUT: none *
  1035. * *
  1036. * WARNINGS: none *
  1037. * *
  1038. * HISTORY: *
  1039. * 08/05/1992 JLB : Created. *
  1040. *=============================================================================================*/
  1041. void Do_Lose(void)
  1042. {
  1043. Map.Set_Default_Mouse(MOUSE_NORMAL);
  1044. Hide_Mouse();
  1045. Theme.Queue_Song(THEME_QUIET);
  1046. /*
  1047. ** If this is a multiplayer game, clear the game's name so we won't respond
  1048. ** to game queries any more (in Call_Back)
  1049. */
  1050. if (Session.Type != GAME_NORMAL) {
  1051. Session.GameName[0] = 0;
  1052. }
  1053. /*
  1054. ** Determine a cosmetic center point for the text.
  1055. */
  1056. int x = Map.TacPixelX + (Lepton_To_Pixel(Map.TacLeptonWidth)/2);
  1057. /*
  1058. ** Announce win to player.
  1059. */
  1060. Set_Logic_Page(SeenBuff);
  1061. Fancy_Text_Print(TXT_SCENARIO_LOST, x, 90*RESFACTOR, &ColorRemaps[PCOLOR_RED], TBLACK, TPF_CENTER|TPF_VCR|TPF_USE_GRAD_PAL|TPF_DROPSHADOW);
  1062. CountDownTimer = TIMER_SECOND * 3;
  1063. while (Is_Speaking()) {};
  1064. Speak(VOX_FAIL);
  1065. while (CountDownTimer || Is_Speaking()) {
  1066. Call_Back();
  1067. }
  1068. /*
  1069. ** Stop here if this is a multiplayer game.
  1070. */
  1071. if (Session.Type != GAME_NORMAL) {
  1072. if (!Session.Play) {
  1073. Session.GamesPlayed++;
  1074. Multi_Score_Presentation();
  1075. Session.CurGame++;
  1076. if (Session.CurGame >= MAX_MULTI_GAMES) {
  1077. Session.CurGame = MAX_MULTI_GAMES - 1;
  1078. }
  1079. }
  1080. GameActive = 0;
  1081. Show_Mouse();
  1082. return;
  1083. }
  1084. Hide_Mouse();
  1085. VisiblePage.Clear();
  1086. Show_Mouse();
  1087. #ifdef CHEAT_KEYS
  1088. // Mono_Printf("Trying to play lose movie\n");
  1089. #endif //CHEAT_KEYS
  1090. Play_Movie(Scen.LoseMovie);
  1091. /*
  1092. ** Start same scenario again
  1093. */
  1094. GamePalette.Set();
  1095. Show_Mouse();
  1096. if (!Session.Play && !WWMessageBox().Process(TXT_TO_REPLAY, TXT_YES, TXT_NO)) {
  1097. Hide_Mouse();
  1098. Keyboard->Clear();
  1099. Start_Scenario(Scen.ScenarioName, false);
  1100. /*
  1101. ** Start the scenario timer with the carried over value if necessary.
  1102. */
  1103. if (Scen.IsInheritTimer) {
  1104. Scen.MissionTimer = Scen.CarryOverTimer;
  1105. Scen.MissionTimer.Start();
  1106. }
  1107. Map.Render();
  1108. } else {
  1109. Hide_Mouse();
  1110. GameActive = 0;
  1111. }
  1112. GamePalette.Set(FADE_PALETTE_FAST, Call_Back);
  1113. Show_Mouse();
  1114. }
  1115. #ifdef FIXIT_VERSION_3 // Stalemate games.
  1116. /***********************************************************************************************
  1117. * Do_Draw -- Parallels Do_Win and Do_Lose, for multiplayer games that end in a draw.
  1118. *=============================================================================================*/
  1119. void Do_Draw(void)
  1120. {
  1121. Map.Set_Default_Mouse(MOUSE_NORMAL);
  1122. Hide_Mouse();
  1123. Theme.Queue_Song(THEME_QUIET);
  1124. /*
  1125. ** If this is a multiplayer game, clear the game's name so we won't respond
  1126. ** to game queries any more (in Call_Back)
  1127. */
  1128. if (Session.Type != GAME_NORMAL) {
  1129. Session.GameName[0] = 0;
  1130. }
  1131. /*
  1132. ** Determine a cosmetic center point for the text.
  1133. */
  1134. int x = Map.TacPixelX + (Lepton_To_Pixel(Map.TacLeptonWidth)/2);
  1135. /*
  1136. ** Announce win to player.
  1137. */
  1138. Set_Logic_Page(SeenBuff);
  1139. Fancy_Text_Print(TXT_WOL_DRAW, x, 90*RESFACTOR, &ColorRemaps[PCOLOR_RED], TBLACK, TPF_CENTER|TPF_VCR|TPF_USE_GRAD_PAL|TPF_DROPSHADOW);
  1140. CountDownTimer = TIMER_SECOND * 3;
  1141. while (Is_Speaking()) {};
  1142. Speak(VOX_CONTROL_EXIT);
  1143. while (CountDownTimer || Is_Speaking()) {
  1144. Call_Back();
  1145. }
  1146. /*
  1147. ** Stop here if this is a multiplayer game.
  1148. */
  1149. if (!Session.Play) {
  1150. Session.GamesPlayed++;
  1151. Multi_Score_Presentation();
  1152. Session.CurGame++;
  1153. if (Session.CurGame >= MAX_MULTI_GAMES) {
  1154. Session.CurGame = MAX_MULTI_GAMES - 1;
  1155. }
  1156. }
  1157. GameActive = 0;
  1158. Show_Mouse();
  1159. }
  1160. #endif
  1161. /***********************************************************************************************
  1162. * Do_Restart -- Handle the restart mission process. *
  1163. * *
  1164. * This routine is called in the main game loop when the mission must be restarted. This *
  1165. * routine will throw away the current game and reload the appropriate mission. The *
  1166. * game will "resume" at the start of the mission. *
  1167. * *
  1168. * INPUT: none *
  1169. * *
  1170. * OUTPUT: none *
  1171. * *
  1172. * WARNINGS: none *
  1173. * *
  1174. * HISTORY: *
  1175. * 08/24/1995 JLB : Created. *
  1176. *=============================================================================================*/
  1177. void Do_Restart(void)
  1178. {
  1179. /*
  1180. ** Start a timer going, before we restart the scenario
  1181. */
  1182. CDTimerClass<SystemTimerClass> timer;
  1183. timer = TICKS_PER_SECOND * 4;
  1184. Theme.Queue_Song(THEME_QUIET);
  1185. WWMessageBox().Process(TXT_RESTARTING, TXT_NONE);
  1186. Map.Set_Default_Mouse(MOUSE_NORMAL);
  1187. Keyboard->Clear();
  1188. Start_Scenario(Scen.ScenarioName, false);
  1189. /*
  1190. ** Start the scenario timer with the carried over value if necessary.
  1191. */
  1192. if (Scen.IsInheritTimer) {
  1193. Scen.MissionTimer = Scen.CarryOverTimer;
  1194. Scen.MissionTimer.Start();
  1195. }
  1196. /*
  1197. ** Make sure the message stays displayed for at least 1 second
  1198. */
  1199. while (timer > 0) {
  1200. Call_Back();
  1201. }
  1202. Keyboard->Clear();
  1203. Map.Render();
  1204. }
  1205. /***********************************************************************************************
  1206. * Restate_Mission -- Handles restating the mission objective. *
  1207. * *
  1208. * This routine will display the mission objective (as text). It will also give the *
  1209. * option to redisplay the mission briefing video. *
  1210. * *
  1211. * INPUT: name -- The scenario name. This is the unique identifier for the scenario *
  1212. * briefing text as it appears in the "MISSION.INI" file. *
  1213. * *
  1214. * OUTPUT: Returns the response from the dialog. This will either be 1 if the video was *
  1215. * requested, or 0 if the return to game options button was selected. *
  1216. * *
  1217. * WARNINGS: none *
  1218. * *
  1219. * HISTORY: *
  1220. * 06/23/1995 JLB : Created. *
  1221. * 08/06/1995 JLB : Uses preloaded briefing text. *
  1222. *=============================================================================================*/
  1223. bool Restate_Mission(char const * name, int button1, int button2)
  1224. {
  1225. if (name) {
  1226. bool brief = true;
  1227. char buffer[25];
  1228. if (Scen.BriefMovie != VQ_NONE) {
  1229. sprintf(buffer, "%s.VQA", VQName[Scen.BriefMovie]);
  1230. }
  1231. if (Scen.BriefMovie == VQ_NONE || !CCFileClass(buffer).Is_Available()) {
  1232. button2 = TXT_OK;
  1233. button1 = TXT_NONE;
  1234. brief = false;
  1235. }
  1236. /*
  1237. ** If mission object text was found, then display it.
  1238. */
  1239. if (strlen(Scen.BriefingText)) {
  1240. strcpy(_ShapeBuffer, Scen.BriefingText);
  1241. BlackPalette.Set(FADE_PALETTE_MEDIUM, Call_Back);
  1242. if (BGMessageBox(_ShapeBuffer, button2, button1)) {
  1243. return(true);
  1244. }
  1245. if (!brief) return(true);
  1246. return(false);
  1247. }
  1248. }
  1249. return(false);
  1250. }
  1251. #define BUTTON_1 1
  1252. #define BUTTON_2 2
  1253. #define BUTTON_3 3
  1254. #define BUTTON_FLAG 0x8000
  1255. int BGMessageBox(char const * msg, int btn1, int btn2)
  1256. {
  1257. #define BUFFSIZE 511
  1258. char buffer[BUFFSIZE];
  1259. int retval;
  1260. bool process; // loop while true
  1261. KeyNumType input; // user input
  1262. int selection;
  1263. bool pressed;
  1264. int curbutton;
  1265. TextButtonClass * buttons[3];
  1266. BOOL display; // display level
  1267. int realval[5];
  1268. int morebutton = 3; // which button says "more": 2 or 3?
  1269. const char * b1txt = Text_String(btn1);
  1270. const char * b2txt = Text_String(btn2);
  1271. #ifdef FRENCH
  1272. const char * b3txt = "SUITE";
  1273. #else
  1274. #ifdef GERMAN
  1275. const char * b3txt = "MEHR";
  1276. #else
  1277. const char * b3txt = "MORE";
  1278. #endif
  1279. #endif
  1280. const void *briefsnd = MFCD::Retrieve("BRIEFING.AUD");
  1281. GadgetClass::Set_Color_Scheme(&ColorRemaps[PCOLOR_TYPE]);
  1282. /*
  1283. ** If the message won't be needing the 'more' button, get rid of it.
  1284. */
  1285. if (strlen(msg) <= BUFFSIZE-1) {
  1286. b3txt = "";
  1287. }
  1288. #ifdef WIN32
  1289. GraphicBufferClass seen_buff_save(VisiblePage.Get_Width(), VisiblePage.Get_Height(), (void*)NULL);
  1290. #endif
  1291. /*
  1292. ** If there's no text for button one, zero it out.
  1293. */
  1294. if (*b1txt == '\0') {
  1295. b1txt = b2txt;
  1296. b2txt = "";
  1297. if(*b1txt == '\0') {
  1298. b1txt=0;
  1299. }
  1300. }
  1301. /*
  1302. ** If there's no text for button two, zero it out. However, if there
  1303. ** is text for button three, move its text (always "MORE") to button two,
  1304. ** and set the morebutton flag to point to button two. Then, clear out
  1305. ** button 3.
  1306. */
  1307. if (*b2txt == '\0') {
  1308. b2txt = 0;
  1309. if (*b3txt != '\0') {
  1310. b2txt = b3txt;
  1311. b3txt = "";
  1312. morebutton = 1;
  1313. }
  1314. }
  1315. /*
  1316. ** If there's no text for button three, zero it out.
  1317. */
  1318. if (*b3txt == '\0') b3txt = 0;
  1319. Fancy_Text_Print(TXT_NONE, 0, 0, &ColorRemaps[PCOLOR_TYPE], TBLACK, TPF_6PT_GRAD|TPF_USE_GRAD_PAL);
  1320. /*
  1321. ** Examine the optional button parameters. Fetch the width and starting
  1322. ** characters for each.
  1323. */
  1324. char b1char, b2char, b3char; // 1st char of each string
  1325. int bwidth, bheight; // button width and height
  1326. int numbuttons = 0;
  1327. if (b1txt) {
  1328. b1char = toupper(b1txt[0]);
  1329. /*
  1330. ** Build the button list.
  1331. */
  1332. bheight = FontHeight + FontYSpacing + 2;
  1333. bwidth = max((String_Pixel_Width(b1txt) + 8), 80);
  1334. if (b2txt) {
  1335. numbuttons = 2;
  1336. b2char = toupper(b2txt[0]);
  1337. bwidth = max(((int)String_Pixel_Width( b2txt ) + 8), bwidth);
  1338. // b1x = x + 10; // left side
  1339. if (b3txt) {
  1340. numbuttons = 3;
  1341. b3char = toupper(b3txt[0]);
  1342. bwidth = max(((int)String_Pixel_Width( b3txt ) + 8), bwidth);
  1343. }
  1344. } else {
  1345. numbuttons = 1;
  1346. // b1x = x + ((width - bwidth) >> 1); // centered
  1347. }
  1348. }
  1349. /*
  1350. ** Determine the dimensions of the text to be used for the dialog box.
  1351. ** These dimensions will control how the dialog box looks.
  1352. */
  1353. buffer[BUFFSIZE-1] = 0;
  1354. int buffend = BUFFSIZE-1;
  1355. strncpy(buffer, msg, BUFFSIZE-1);
  1356. /*
  1357. ** Scan through the string to see if it got clipped, and if so, we'll
  1358. ** trim it back to the last space so it'll clip on a word.
  1359. */
  1360. if (strlen(buffer) != strlen(msg)) {
  1361. while (buffer[buffend] != ' ') buffend--;
  1362. buffer[buffend]=0;
  1363. }
  1364. Fancy_Text_Print(TXT_NONE, 0, 0, &ColorRemaps[PCOLOR_TYPE], TBLACK, TPF_6PT_GRAD|TPF_USE_GRAD_PAL);
  1365. int width;
  1366. int height;
  1367. Format_Window_String(buffer, 300, width, height);
  1368. height += (numbuttons == 0) ? 30 : 60;
  1369. int x = (SeenBuff.Get_Width() - width) / 2;
  1370. int y = (SeenBuff.Get_Height() - height) / 2;
  1371. /*
  1372. ** Other inits.
  1373. */
  1374. Set_Logic_Page(SeenBuff);
  1375. /*
  1376. ** Initialize the button structures. All are initialized, even though one (or none) may
  1377. ** actually be added to the button list.
  1378. */
  1379. TextButtonClass button1(BUTTON_1, b1txt, TPF_BUTTON,
  1380. x + ((numbuttons == 1) ? ((width - bwidth) >> 1) : 10), y + height - (bheight + 5), bwidth);
  1381. TextButtonClass button2(BUTTON_2, b2txt, TPF_BUTTON,
  1382. x + width - (bwidth + 10), y + height - (bheight + 5), bwidth);
  1383. TextButtonClass button3(BUTTON_3, b3txt, TPF_BUTTON,
  1384. 0, y + height - (bheight + 5));
  1385. button3.X = x + ((width - button3.Width) >> 1);
  1386. TextButtonClass * buttonlist = 0;
  1387. curbutton = 0;
  1388. /*
  1389. ** Add and initialize the buttons to the button list.
  1390. */
  1391. if (numbuttons) {
  1392. buttonlist = &button1;
  1393. buttons[0] = &button1;
  1394. realval[0] = BUTTON_1;
  1395. if (numbuttons > 2) {
  1396. button3.Add(*buttonlist);
  1397. buttons[1] = &button3;
  1398. realval[1] = BUTTON_3;
  1399. button2.Add(*buttonlist);
  1400. buttons[2] = &button2;
  1401. realval[2] = BUTTON_2;
  1402. buttons[curbutton]->Turn_On();
  1403. } else if (numbuttons == 2) {
  1404. button2.Add(*buttonlist);
  1405. buttons[1] = &button2;
  1406. realval[1] = BUTTON_2;
  1407. buttons[curbutton]->Turn_On();
  1408. }
  1409. }
  1410. /*
  1411. ** Draw the dialog.
  1412. */
  1413. Hide_Mouse();
  1414. PaletteClass temp;
  1415. #ifdef WIN32
  1416. char *filename = "SOVPAPER.PCX";
  1417. if (PlayerPtr->Class->House != HOUSE_USSR && PlayerPtr->Class->House != HOUSE_UKRAINE) {
  1418. filename = "ALIPAPER.PCX";
  1419. }
  1420. Load_Title_Screen(filename, &HidPage, (unsigned char*)temp.Get_Data());
  1421. #else
  1422. char *filename = "SOVPAPER.CPS";
  1423. if (PlayerPtr->Class->House != HOUSE_USSR && PlayerPtr->Class->House != HOUSE_UKRAINE) {
  1424. filename = "ALIPAPER.CPS";
  1425. }
  1426. Load_Uncompress(CCFileClass(filename), HidPage, HidPage, temp);
  1427. #endif
  1428. HidPage.Blit(SeenPage);
  1429. #ifdef WIN32
  1430. VisiblePage.Blit(seen_buff_save);
  1431. #endif
  1432. static unsigned char _scorepal[]={0,1,12,13,4,5,6,7,8,9,10,255,252,253,14,248};
  1433. Set_Font_Palette(_scorepal);
  1434. temp.Set(FADE_PALETTE_MEDIUM, Call_Back);
  1435. /*
  1436. ** Main Processing Loop.
  1437. */
  1438. int bufindex = 0;
  1439. Keyboard->Clear();
  1440. Set_Font_Palette(_scorepal);
  1441. int xprint = x + 20;
  1442. int yprint = y + 25;
  1443. do {
  1444. #ifdef WIN32
  1445. /*
  1446. ** If we have just received input focus again after running in the background then
  1447. ** we need to redraw.
  1448. */
  1449. if (AllSurfaces.SurfacesRestored) {
  1450. AllSurfaces.SurfacesRestored = false;
  1451. Hide_Mouse();
  1452. seen_buff_save.Blit(VisiblePage);
  1453. display = true;
  1454. Show_Mouse();
  1455. }
  1456. #endif
  1457. char bufprint[2];
  1458. bufprint[1]=0;
  1459. bufprint[0] = buffer[bufindex];
  1460. if (bufprint[0] == '\r' || bufprint[0] == '@') {
  1461. xprint = x + 20;
  1462. yprint += FontHeight + FontYSpacing;
  1463. } else {
  1464. if (bufprint[0] != 20) {
  1465. SeenPage.Print(bufprint, xprint, yprint, TBLACK, TBLACK);
  1466. #ifdef WIN32
  1467. seen_buff_save.Print(bufprint, xprint, yprint, TBLACK, TBLACK);
  1468. #endif
  1469. xprint += Char_Pixel_Width(bufprint[0]);
  1470. }
  1471. }
  1472. if (bufprint[0] == '\r' || bufprint[0] == '@') {
  1473. #ifdef WIN32
  1474. Play_Sample(briefsnd, 255, Options.Normalize_Volume(135));
  1475. #else
  1476. Play_Sample(briefsnd, 255, Options.Normalize_Volume(45));
  1477. #endif
  1478. CDTimerClass<SystemTimerClass> cd;
  1479. cd = 5;
  1480. do {
  1481. Call_Back();
  1482. } while(!Keyboard->Check() && cd);
  1483. }
  1484. } while (buffer[++bufindex]);
  1485. Show_Mouse();
  1486. Keyboard->Clear();
  1487. if (buttonlist) {
  1488. process = true;
  1489. pressed = false;
  1490. while (process) {
  1491. #ifdef WIN32
  1492. /*
  1493. ** If we have just received input focus again after running in the background then
  1494. ** we need to redraw.
  1495. */
  1496. if (AllSurfaces.SurfacesRestored) {
  1497. AllSurfaces.SurfacesRestored = false;
  1498. Hide_Mouse();
  1499. seen_buff_save.Blit(VisiblePage);
  1500. display = true;
  1501. Show_Mouse();
  1502. }
  1503. #endif
  1504. if (display) {
  1505. display = false;
  1506. Hide_Mouse();
  1507. /*
  1508. ** Redraw the buttons.
  1509. */
  1510. if (buttonlist) {
  1511. buttonlist->Draw_All();
  1512. }
  1513. Show_Mouse();
  1514. }
  1515. /*
  1516. ** Invoke game callback.
  1517. */
  1518. Call_Back();
  1519. /*
  1520. ** Fetch and process input.
  1521. */
  1522. input = buttonlist->Input();
  1523. switch (input) {
  1524. case (BUTTON_1|BUTTON_FLAG):
  1525. selection = realval[0];
  1526. pressed = true;
  1527. break;
  1528. case (KN_ESC):
  1529. if (numbuttons > 2) {
  1530. selection = realval[1];
  1531. pressed = true;
  1532. } else {
  1533. selection = realval[2];
  1534. pressed = true;
  1535. }
  1536. break;
  1537. case (BUTTON_2|BUTTON_FLAG):
  1538. selection = BUTTON_2;
  1539. pressed = true;
  1540. break;
  1541. case (BUTTON_3|BUTTON_FLAG):
  1542. selection = realval[1];
  1543. pressed = true;
  1544. break;
  1545. case (KN_LEFT):
  1546. if (numbuttons > 1) {
  1547. buttons[curbutton]->Turn_Off();
  1548. buttons[curbutton]->Flag_To_Redraw();
  1549. curbutton--;
  1550. if (curbutton < 0) {
  1551. curbutton = numbuttons - 1;
  1552. }
  1553. buttons[curbutton]->Turn_On();
  1554. buttons[curbutton]->Flag_To_Redraw();
  1555. }
  1556. break;
  1557. case (KN_RIGHT):
  1558. if (numbuttons > 1) {
  1559. buttons[curbutton]->Turn_Off();
  1560. buttons[curbutton]->Flag_To_Redraw();
  1561. curbutton++;
  1562. if (curbutton > (numbuttons - 1) ) {
  1563. curbutton = 0;
  1564. }
  1565. buttons[curbutton]->Turn_On();
  1566. buttons[curbutton]->Flag_To_Redraw();
  1567. }
  1568. break;
  1569. case (KN_RETURN):
  1570. selection = curbutton + BUTTON_1;
  1571. pressed = true;
  1572. break;
  1573. /*
  1574. ** Check 'input' to see if it's the 1st char of button text
  1575. */
  1576. default:
  1577. if (b1char == toupper(Keyboard->To_ASCII((KeyNumType)(input & 0xFF)))) {
  1578. selection = BUTTON_1;
  1579. pressed = true;
  1580. } else if (b2txt!=NULL &&
  1581. b2char == toupper(Keyboard->To_ASCII((KeyNumType)(input & 0xFF)))) {
  1582. selection = BUTTON_2;
  1583. pressed = true;
  1584. } else if (b3txt!=NULL &&
  1585. b3char == toupper(Keyboard->To_ASCII((KeyNumType)(input & 0xFF)))) {
  1586. selection = BUTTON_3;
  1587. pressed = true;
  1588. }
  1589. break;
  1590. }
  1591. if (pressed) {
  1592. switch (selection) {
  1593. case (BUTTON_1):
  1594. retval = 1;
  1595. process = false;
  1596. break;
  1597. case (BUTTON_2):
  1598. retval = 0;
  1599. process = false;
  1600. break;
  1601. case BUTTON_3:
  1602. retval = 2;
  1603. process = false;
  1604. break;
  1605. }
  1606. pressed = false;
  1607. }
  1608. }
  1609. } else {
  1610. Keyboard->Clear();
  1611. }
  1612. if (retval == (morebutton-1) && strlen(msg) > BUFFSIZE-1) {
  1613. retval = BGMessageBox(msg + buffend + 1, btn1, btn2);
  1614. }
  1615. /*
  1616. ** Restore the screen.
  1617. */
  1618. Hide_Mouse();
  1619. /*
  1620. ** Now set the palette, depending on if we're going to show the video or
  1621. ** go back to the main menu.
  1622. */
  1623. switch (retval) {
  1624. case 0:
  1625. // BlackPalette.Set(FADE_PALETTE_MEDIUM, Call_Back);
  1626. // SeenPage.Clear();
  1627. //// CCPalette.Set();
  1628. // break;
  1629. case 1:
  1630. BlackPalette.Set(FADE_PALETTE_MEDIUM, Call_Back);
  1631. SeenPage.Clear();
  1632. break;
  1633. default:
  1634. break;
  1635. }
  1636. Show_Mouse();
  1637. GadgetClass::Set_Color_Scheme(&ColorRemaps[PCOLOR_DIALOG_BLUE]);
  1638. return(retval);
  1639. }
  1640. /***********************************************************************************************
  1641. * Set_Scenario_Name -- Creates the INI scenario name string. *
  1642. * *
  1643. * This routine is used by the scenario loading and saving code. It generates the scenario *
  1644. * INI root file name for the specified scenario parameters. *
  1645. * *
  1646. * INPUT: *
  1647. * buf buffer to store filename in; must be long enough for root.ext *
  1648. * scenario scenario number *
  1649. * player player type for this game (GDI, NOD, multi-player, ...) *
  1650. * dir directional parameter for this game (East/West) *
  1651. * var variation of this game (Lose, A/B/C/D, etc) *
  1652. * *
  1653. * OUTPUT: none. *
  1654. * *
  1655. * WARNINGS: none. *
  1656. * *
  1657. * HISTORY: *
  1658. * 05/28/1994 JLB : Created. *
  1659. * 05/01/1995 BRR : 2-player scenarios use same names as multiplayer *
  1660. *=============================================================================================*/
  1661. void ScenarioClass::Set_Scenario_Name(int scenario, ScenarioPlayerType player, ScenarioDirType dir, ScenarioVarType var)
  1662. {
  1663. Scenario = scenario;
  1664. // ScenPlayer = player;
  1665. // ScenDir = dir;
  1666. // ScenVar = var;
  1667. char c_player; // character representing player type
  1668. char c_dir; // character representing direction type
  1669. char c_var; // character representing variation type
  1670. ScenarioVarType i;
  1671. char fname[_MAX_FNAME+_MAX_EXT];
  1672. /*
  1673. ** Set the player-type value.
  1674. */
  1675. switch (player) {
  1676. case SCEN_PLAYER_SPAIN:
  1677. c_player = HouseTypeClass::As_Reference(HOUSE_SPAIN).Prefix;
  1678. break;
  1679. case SCEN_PLAYER_GREECE:
  1680. c_player = HouseTypeClass::As_Reference(HOUSE_GREECE).Prefix;
  1681. break;
  1682. case SCEN_PLAYER_USSR:
  1683. c_player = HouseTypeClass::As_Reference(HOUSE_USSR).Prefix;
  1684. break;
  1685. case SCEN_PLAYER_JP:
  1686. c_player = HouseTypeClass::As_Reference(HOUSE_JP).Prefix;
  1687. break;
  1688. /*
  1689. ** Multi player scenario.
  1690. */
  1691. default:
  1692. c_player = HouseTypeClass::As_Reference(HOUSE_MULTI1).Prefix;
  1693. break;
  1694. }
  1695. /*
  1696. ** Set the directional character value.
  1697. ** If SCEN_DIR_NONE is specified, randomly pick a direction; otherwise, use 'E' or 'W'
  1698. */
  1699. switch (dir) {
  1700. case SCEN_DIR_EAST:
  1701. c_dir = 'E';
  1702. break;
  1703. case SCEN_DIR_WEST:
  1704. c_dir = 'W';
  1705. break;
  1706. default:
  1707. case SCEN_DIR_NONE:
  1708. c_dir = Percent_Chance(50) ? 'W' : 'E';
  1709. break;
  1710. }
  1711. /*
  1712. ** Set the variation value.
  1713. */
  1714. if (var == SCEN_VAR_NONE) {
  1715. /*
  1716. ** Find which variations are available for this scenario
  1717. */
  1718. for (i = SCEN_VAR_FIRST; i < SCEN_VAR_COUNT; i++) {
  1719. sprintf(fname, "SC%c%02d%c%c.INI", c_player, scenario, c_dir, 'A' + i);
  1720. if (!CCFileClass(fname).Is_Available()) {
  1721. break;
  1722. }
  1723. }
  1724. if (i==SCEN_VAR_FIRST) {
  1725. c_var = 'X'; // indicates an error
  1726. } else {
  1727. c_var = 'A' + Random_Pick(0, i-1);
  1728. // ScenVar = (ScenarioVarType)i;
  1729. }
  1730. } else {
  1731. switch (var) {
  1732. case SCEN_VAR_A:
  1733. c_var = 'A';
  1734. break;
  1735. case SCEN_VAR_B:
  1736. c_var = 'B';
  1737. break;
  1738. case SCEN_VAR_C:
  1739. c_var = 'C';
  1740. break;
  1741. case SCEN_VAR_D:
  1742. c_var = 'D';
  1743. break;
  1744. default:
  1745. c_var = 'L';
  1746. break;
  1747. }
  1748. }
  1749. /*
  1750. ** generate the filename
  1751. */
  1752. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  1753. //Mono_Printf("In set_scenario_name, scenario # = %d\n",scenario);Keyboard->Get();Keyboard->Get();
  1754. if (scenario < 100) {
  1755. sprintf(ScenarioName, "SC%c%02d%c%c.INI", c_player, scenario, c_dir, c_var);
  1756. } else {
  1757. char first = (scenario / 36) + 'A';
  1758. char second = scenario % 36;
  1759. if (second < 10) {
  1760. second += '0';
  1761. } else {
  1762. second = (second - 10) + 'A';
  1763. }
  1764. sprintf(ScenarioName, "SC%c%c%c%c%c.INI", c_player, first, second, c_dir, c_var);
  1765. }
  1766. #else
  1767. sprintf(ScenarioName, "SC%c%02d%c%c.INI", c_player, scenario, c_dir, c_var);
  1768. #endif
  1769. }
  1770. void ScenarioClass::Set_Scenario_Name(char const * name)
  1771. {
  1772. if (name != NULL) {
  1773. strncpy(ScenarioName, name, sizeof(ScenarioName));
  1774. ScenarioName[ARRAY_SIZE(ScenarioName)-1] = '\0';
  1775. char buf[3];
  1776. memcpy(buf, &ScenarioName[3], 2);
  1777. buf[2] = '\0';
  1778. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  1779. if (buf[0] > '9' || buf[1] > '9') {
  1780. char first = buf[0];
  1781. char second = buf[1];
  1782. if (first <= '9') {
  1783. first -= '0';
  1784. } else {
  1785. first -= 'A';
  1786. }
  1787. if (second <= '9') {
  1788. second -= '0';
  1789. } else {
  1790. second = (second - 'A') + 10;
  1791. }
  1792. Scenario = (36 * first) + second;
  1793. } else {
  1794. Scenario = atoi(buf);
  1795. }
  1796. #else
  1797. Scenario = atoi(buf);
  1798. #endif
  1799. }
  1800. }
  1801. /***********************************************************************************************
  1802. * Read_Scenario_INI -- Read specified scenario INI file. *
  1803. * *
  1804. * Read in the scenario INI file. This routine only sets the game *
  1805. * globals with that data that is explicitly defined in the INI file. *
  1806. * The remaining necessary interpolated data is generated elsewhere. *
  1807. * *
  1808. * INPUT: *
  1809. * root root filename for scenario file to read *
  1810. * *
  1811. * fresh true = should the current scenario be cleared? *
  1812. * *
  1813. * OUTPUT: bool; Was the scenario read successful? *
  1814. * *
  1815. * WARNINGS: none *
  1816. * *
  1817. * HISTORY: *
  1818. * 10/07/1992 JLB : Created. V.Grippi added CS check 2/5/97 *
  1819. *=============================================================================================*/
  1820. bool Read_Scenario_INI(char * fname, bool )
  1821. {
  1822. // char fname[_MAX_FNAME+_MAX_EXT]; // full INI filename
  1823. ScenarioInit++;
  1824. Clear_Scenario();
  1825. #ifdef OBSOLETE
  1826. /*
  1827. ** If we are not dealing with scenario 1, or a multi player scenario
  1828. ** then make sure the correct disk is in the drive.
  1829. */
  1830. if (RequiredCD != -2) {
  1831. RequiredCD = -1;
  1832. }
  1833. #endif
  1834. /*
  1835. ** Only force a CD check if this is a single player game or if its
  1836. ** a multiplayer game on an official scenario. If its non-official
  1837. ** (a user scenario) then we dont care which CD is in because the
  1838. ** scenario is stored locally on the hard drive. In this case, we
  1839. ** have already verified its existance. ST 3/1/97 4:52PM.
  1840. */
  1841. #ifdef FIXIT_VERSION_3 // Avoid CD check if official scenario was downloaded.
  1842. if( ( Session.Type == GAME_NORMAL || Session.ScenarioIsOfficial ) && _stricmp( Scen.ScenarioName, "download.tmp" ) ){
  1843. #else
  1844. if (Session.Type == GAME_NORMAL || Session.ScenarioIsOfficial){
  1845. #endif
  1846. /*
  1847. ** If this is scenario 1 then it should be on all CDs unless its an ant scenario
  1848. */
  1849. if (Scen.Scenario == 1 && Scen.ScenarioName[2] != 'A') {
  1850. RequiredCD = -1;
  1851. } else {
  1852. // Mono_Printf("Read_SCen_INI scenario is: %s\n", Scen.ScenarioName);
  1853. /*
  1854. ** If this is a multiplayer scenario we need to find out if its a counterstrike
  1855. ** scenario. If so then we need CD 2. The original multiplayer scenarios are on
  1856. ** all CDs.
  1857. */
  1858. if (Session.Type != GAME_NORMAL) {
  1859. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  1860. RequiredCD = -1; // default that any CD will do.
  1861. // If it's a counterstrike mission, require the counterstrike CD, unless the
  1862. // Aftermath CD is already in the drive, in which case, leave it there.
  1863. // Note, this works because this section only tests for multiplayer scenarios.
  1864. if (Is_Mission_Counterstrike(Scen.ScenarioName)) {
  1865. RequiredCD = 2;
  1866. if( Is_Aftermath_Installed() || Get_CD_Index(CCFileClass::Get_CD_Drive(), 1*60) == 3 )
  1867. {
  1868. RequiredCD = 3;
  1869. }
  1870. }
  1871. if(Is_Mission_Aftermath(Scen.ScenarioName)) {
  1872. RequiredCD = 3;
  1873. }
  1874. #else
  1875. if (Scen.Scenario > 24) {
  1876. RequiredCD = 2;
  1877. } else {
  1878. RequiredCD = -1;
  1879. }
  1880. #endif
  1881. } else {
  1882. /*
  1883. ** This is a solo game. If the scenario number is >= 20 or its an ant mission
  1884. ** then we need the counterstrike CD (2)
  1885. */
  1886. if (Scen.Scenario >= 20 || Scen.ScenarioName[2] == 'A') {
  1887. RequiredCD = 2;
  1888. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  1889. if (Scen.Scenario >= 36 && Scen.ScenarioName[2] != 'A') {
  1890. RequiredCD = 3;
  1891. #ifdef BOGUSCD
  1892. RequiredCD = -1;
  1893. #endif
  1894. }
  1895. #endif
  1896. } else {
  1897. /*
  1898. ** This is a solo mission from the original Red Alert. Choose the Soviet or
  1899. ** allied CD depending on the scenario name.
  1900. */
  1901. if (Scen.ScenarioName[2] == 'U') {
  1902. RequiredCD = 1;
  1903. } else {
  1904. if (Scen.ScenarioName[2] == 'G') {
  1905. // Mono_Printf("We are setting REquiredCD to 0");
  1906. RequiredCD = 0;
  1907. }
  1908. }
  1909. }
  1910. }
  1911. }
  1912. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  1913. // If we're asking for a CD swap, check to see if we need to set the palette
  1914. // to avoid a black screen. If this is a normal RA game, and the CD being
  1915. // requested is an RA CD, then don't set the palette, leave the map screen up.
  1916. #ifdef FIXIT_VERSION_3
  1917. int cd_index = Get_CD_Index(CCFileClass::Get_CD_Drive(), 1*60);
  1918. if( !( Using_DVD() && cd_index == 5 ) && cd_index != RequiredCD ) {
  1919. #else
  1920. if (Get_CD_Index(CCFileClass::Get_CD_Drive(), 1*60) != RequiredCD) {
  1921. #endif
  1922. if ((RequiredCD == 0 || RequiredCD == 1) && Session.Type == GAME_NORMAL) {
  1923. SeenPage.Clear();
  1924. }
  1925. GamePalette.Set(FADE_PALETTE_FAST, Call_Back);
  1926. }
  1927. #endif
  1928. if (!Force_CD_Available(RequiredCD)) {
  1929. Prog_End("Read_Scenario_INI Force_CD_Available failed", true);
  1930. if (!RunningAsDLL) { //PG
  1931. Emergency_Exit(EXIT_FAILURE);
  1932. }
  1933. }
  1934. } else {
  1935. /*
  1936. ** This is a user scenario so any old CD will do.
  1937. */
  1938. RequiredCD = -1;
  1939. }
  1940. /*
  1941. ** Create scenario filename and read the file.
  1942. */
  1943. // sprintf(fname, "%s.INI", root);
  1944. CCINIClass ini;
  1945. CCFileClass file(fname);
  1946. // file.Cache();
  1947. int result = ini.Load(file, true);
  1948. if (result == 0) {
  1949. // Mono_Printf("ini.Load failed");
  1950. GlyphX_Debug_Print("Failed to load scenario file");
  1951. GlyphX_Debug_Print(fname);
  1952. return(false);
  1953. }
  1954. GlyphX_Debug_Print("Loaded scenario file");
  1955. GlyphX_Debug_Print(file);
  1956. /*
  1957. ** If the scenario digest is wrong then the return code will be a 2.
  1958. */
  1959. if (result == 2) {
  1960. // if (Session.Type == GAME_NORMAL || Session.ScenarioIsOfficial) {
  1961. /*
  1962. ** Make a special exception so that multiplayer maps from 1 through
  1963. ** 24 will not care if the message digest is in error. All other
  1964. ** maps will abort the scenario load.
  1965. */
  1966. if (Scen.ScenarioName[2] != 'M' || Scen.Scenario >= 25) {
  1967. #if (1)
  1968. GlyphX_Debug_Print("Scenario digest is wrong");
  1969. #else
  1970. GamePalette.Set();
  1971. WWMessageBox().Process(TXT_SCENARIO_ERROR, TXT_OK);
  1972. #endif
  1973. #ifdef RELEASE_VERSION
  1974. return(false);
  1975. #endif
  1976. }
  1977. // }
  1978. }
  1979. /*
  1980. ** Reset the rules values to their initial settings.
  1981. */
  1982. #ifdef FIXIT_NAME_OVERRIDE
  1983. for (int index = 0; index < ARRAY_SIZE(NameOverride); index++) {
  1984. if (NameOverride[index] != NULL) free((void*)NameOverride[index]);
  1985. NameOverride[index] = NULL;
  1986. NameIDOverride[index] = 0;
  1987. }
  1988. if (Session.Type == GAME_NORMAL) {
  1989. Special.IsShadowGrow = false;
  1990. }
  1991. #endif
  1992. #ifdef FIXIT_ANTS
  1993. Session.Messages.Reset();
  1994. // Session.Messages.Add_Message(NULL, 0, NULL, PCOLOR_GREEN, TPF_6PT_GRAD|TPF_USE_GRAD_PAL|TPF_FULLSHADOW, 1);
  1995. // Session.Messages.Add_Message(NULL, 0, NULL, PCOLOR_GREEN, TPF_6PT_GRAD|TPF_USE_GRAD_PAL|TPF_FULLSHADOW, 1);
  1996. // Session.Messages.Add_Message(NULL, 0, NULL, PCOLOR_GREEN, TPF_6PT_GRAD|TPF_USE_GRAD_PAL|TPF_FULLSHADOW, 1);
  1997. // Session.Messages.Add_Message(NULL, 0, NULL, PCOLOR_GREEN, TPF_6PT_GRAD|TPF_USE_GRAD_PAL|TPF_FULLSHADOW, 1);
  1998. // Session.Messages.Add_Message(NULL, 0, NULL, PCOLOR_GREEN, TPF_6PT_GRAD|TPF_USE_GRAD_PAL|TPF_FULLSHADOW, 1);
  1999. // Session.Messages.Add_Message(NULL, 0, NULL, PCOLOR_GREEN, TPF_6PT_GRAD|TPF_USE_GRAD_PAL|TPF_FULLSHADOW, 1);
  2000. WeaponTypeClass::As_Pointer(WEAPON_FLAMER)->Sound = VOC_NONE;
  2001. InfantryTypeClass::As_Reference(INFANTRY_THIEF).IsDoubleOwned = false;
  2002. InfantryTypeClass::As_Reference(INFANTRY_E4).IsDoubleOwned = false;
  2003. InfantryTypeClass::As_Reference(INFANTRY_SPY).PrimaryWeapon = NULL;
  2004. InfantryTypeClass::As_Reference(INFANTRY_SPY).SecondaryWeapon = NULL;
  2005. InfantryTypeClass::As_Reference(INFANTRY_GENERAL).IsBomber = false;
  2006. UnitTypeClass::As_Reference(UNIT_HARVESTER).IsExploding = false;
  2007. UnitTypeClass::As_Reference(UNIT_ANT1).Level = -1;
  2008. UnitTypeClass::As_Reference(UNIT_ANT2).Level = -1;
  2009. UnitTypeClass::As_Reference(UNIT_ANT3).Level = -1;
  2010. BuildingTypeClass::As_Reference(STRUCT_QUEEN).Level = -1;
  2011. BuildingTypeClass::As_Reference(STRUCT_LARVA1).Level = -1;
  2012. BuildingTypeClass::As_Reference(STRUCT_LARVA2).Level = -1;
  2013. #endif
  2014. Rule.General(RuleINI);
  2015. Rule.Recharge(RuleINI);
  2016. Rule.AI(RuleINI);
  2017. Rule.Powerups(RuleINI);
  2018. Rule.Land_Types(RuleINI);
  2019. Rule.Themes(RuleINI);
  2020. Rule.IQ(RuleINI);
  2021. Rule.Objects(RuleINI);
  2022. Rule.Difficulty(RuleINI);
  2023. #ifdef FIXIT_CSII // checked - ajw 9/28/98 - Except does this _change_ any rules, or just add to them? - Just adds.
  2024. Rule.General(AftermathINI);
  2025. Rule.Recharge(AftermathINI);
  2026. Rule.AI(AftermathINI);
  2027. Rule.Powerups(AftermathINI);
  2028. Rule.Land_Types(AftermathINI);
  2029. Rule.Themes(AftermathINI);
  2030. Rule.IQ(AftermathINI);
  2031. Rule.Objects(AftermathINI);
  2032. Rule.Difficulty(AftermathINI);
  2033. #endif
  2034. /*
  2035. ** For civilians, remove the graphics name override from the base rules (can still be overridden in scenario-specific INI).
  2036. */
  2037. for (int iindex = 0; iindex < InfantryTypes.Count(); iindex++) {
  2038. InfantryTypeClass* itype = InfantryTypes.Ptr(iindex);
  2039. if (itype->IsCivilian) {
  2040. itype->GraphicName[0] = '\0';
  2041. }
  2042. }
  2043. /*
  2044. ** Override any rules values specified in this
  2045. ** particular scenario file.
  2046. */
  2047. Rule.General(ini);
  2048. Rule.Recharge(ini);
  2049. Rule.AI(ini);
  2050. Rule.Powerups(ini);
  2051. Rule.Land_Types(ini);
  2052. Rule.Themes(ini);
  2053. Rule.IQ(ini);
  2054. Rule.Objects(ini);
  2055. Rule.Difficulty(ini);
  2056. /*
  2057. ** - Fix a legacy bug with England and France country bonuses.
  2058. ** - Use ore growth and spread values from the special settings.
  2059. */
  2060. if (Session.Type != GAME_NORMAL) {
  2061. HouseTypeClass::As_Reference(HOUSE_ENGLAND).ArmorBias = fixed(9, 10);
  2062. HouseTypeClass::As_Reference(HOUSE_FRANCE).ROFBias = fixed(9, 10);
  2063. Rule.IsTGrowth = Special.IsTGrowth;
  2064. Rule.IsTSpread = Special.IsTSpread;
  2065. }
  2066. /*
  2067. ** Init the Scenario CRC value
  2068. */
  2069. ScenarioCRC = 0;
  2070. #ifdef TOFIX
  2071. len = strlen(buffer);
  2072. for (int i = 0; i < len; i++) {
  2073. val = (unsigned char)buffer[i];
  2074. Add_CRC(&ScenarioCRC, (unsigned long)val);
  2075. }
  2076. #endif
  2077. /*
  2078. ** Fetch the appropriate movie names from the INI file.
  2079. */
  2080. const char * const BASIC = "Basic";
  2081. ini.Get_String(BASIC, "Name", "<none>", Scen.Description, sizeof(Scen.Description));
  2082. Scen.IntroMovie = ini.Get_VQType(BASIC, "Intro", Scen.IntroMovie);
  2083. Scen.BriefMovie = ini.Get_VQType(BASIC, "Brief", Scen.BriefMovie);
  2084. Scen.WinMovie = ini.Get_VQType(BASIC, "Win", Scen.WinMovie);
  2085. Scen.WinMovie2 = ini.Get_VQType(BASIC, "Win2", Scen.WinMovie2);
  2086. Scen.WinMovie3 = ini.Get_VQType(BASIC, "Win3", Scen.WinMovie3);
  2087. Scen.WinMovie4 = ini.Get_VQType(BASIC, "Win4", Scen.WinMovie4);
  2088. Scen.LoseMovie = ini.Get_VQType(BASIC, "Lose", Scen.LoseMovie);
  2089. Scen.ActionMovie = ini.Get_VQType(BASIC, "Action", Scen.ActionMovie);
  2090. Scen.IsToCarryOver = ini.Get_Bool(BASIC, "ToCarryOver", Scen.IsToCarryOver);
  2091. Scen.IsToInherit = ini.Get_Bool(BASIC, "ToInherit", Scen.IsToInherit);
  2092. Scen.IsInheritTimer = ini.Get_Bool(BASIC, "TimerInherit", Scen.IsInheritTimer);
  2093. Scen.IsEndOfGame = ini.Get_Bool(BASIC, "EndOfGame", Scen.IsEndOfGame);
  2094. Scen.IsTanyaEvac = ini.Get_Bool(BASIC, "CivEvac", Scen.IsTanyaEvac);
  2095. Scen.TransitTheme = ini.Get_ThemeType(BASIC, "Theme", THEME_NONE);
  2096. NewINIFormat = ini.Get_Int(BASIC, "NewINIFormat", 0);
  2097. Scen.CarryOverPercent = ini.Get_Fixed(BASIC, "CarryOverMoney", Scen.CarryOverPercent);
  2098. Scen.CarryOverPercent = Saturate(Scen.CarryOverPercent, 1);
  2099. Scen.CarryOverCap = ini.Get_Int(BASIC, "CarryOverCap", Scen.CarryOverCap);
  2100. Scen.IsNoSpyPlane = ini.Get_Bool(BASIC, "NoSpyPlane", Scen.IsNoSpyPlane);
  2101. Scen.IsSkipScore = ini.Get_Bool(BASIC, "SkipScore", Scen.IsSkipScore);
  2102. Scen.IsOneTimeOnly = ini.Get_Bool(BASIC, "OneTimeOnly", Scen.IsOneTimeOnly);
  2103. Scen.IsNoMapSel = ini.Get_Bool(BASIC, "SkipMapSelect", Scen.IsNoMapSel);
  2104. Scen.IsTruckCrate = ini.Get_Bool(BASIC, "TruckCrate", Scen.IsTruckCrate);
  2105. Scen.IsMoneyTiberium = ini.Get_Bool(BASIC, "FillSilos", Scen.IsMoneyTiberium);
  2106. Scen.Percent = ini.Get_Int(BASIC, "Percent", Scen.Percent);
  2107. /*
  2108. ** Read in the specific information for each of the house types. This creates
  2109. ** the houses of different types.
  2110. */
  2111. HouseClass::Read_INI(ini);
  2112. Call_Back();
  2113. /*
  2114. ** Read in the team-type data. The team types must be created before any
  2115. ** triggers can be created.
  2116. */
  2117. TeamTypeClass::Read_INI(ini);
  2118. Call_Back();
  2119. /*
  2120. ** Read in the trigger data. The triggers must be created before any other
  2121. ** objects can be initialized.
  2122. */
  2123. TriggerTypeClass::Read_INI(ini);
  2124. Call_Back();
  2125. /*
  2126. ** Read in the map control values. This includes dimensions
  2127. ** as well as theater information.
  2128. */
  2129. Map.Read_INI(ini);
  2130. Call_Back();
  2131. /*
  2132. ** Assign PlayerPtr by reading the player's house from the INI;
  2133. ** Must be done before any TechnoClass objects are created.
  2134. */
  2135. if (Session.Type == GAME_NORMAL) {
  2136. PlayerPtr = HouseClass::As_Pointer(ini.Get_HousesType(BASIC, "Player", HOUSE_GREECE));
  2137. PlayerPtr->Assign_Handicap(Scen.Difficulty);
  2138. int carryover;
  2139. if (Scen.CarryOverCap != -1) {
  2140. carryover = min(Scen.CarryOverMoney * Scen.CarryOverPercent, Scen.CarryOverCap);
  2141. } else {
  2142. carryover = Scen.CarryOverMoney * Scen.CarryOverPercent;
  2143. }
  2144. PlayerPtr->Credits += carryover;
  2145. PlayerPtr->Control.InitialCredits += carryover;
  2146. } else {
  2147. //Call the new Assign_Houses function. ST - 8/8/2019 12:35PM
  2148. //Assign_Houses();
  2149. GlyphX_Assign_Houses();
  2150. }
  2151. PlayerPtr->IsHuman = true;
  2152. PlayerPtr->IsPlayerControl = true;
  2153. // if (NewINIFormat < 2 || !ini.Is_Present("MapPack")) {
  2154. // Map.Read_Binary(root, &ScenarioCRC);
  2155. // }
  2156. /*
  2157. ** Read in and place the 3D terrain objects.
  2158. */
  2159. TerrainClass::Read_INI(ini);
  2160. Call_Back();
  2161. /*
  2162. ** Read in and place the units (all sides).
  2163. */
  2164. UnitClass::Read_INI(ini);
  2165. Call_Back();
  2166. AircraftClass::Read_INI(ini);
  2167. Call_Back();
  2168. VesselClass::Read_INI(ini);
  2169. Call_Back();
  2170. /*
  2171. ** Read in and place the infantry units (all sides).
  2172. */
  2173. InfantryClass::Read_INI(ini);
  2174. Call_Back();
  2175. /*
  2176. ** Read in and place all the buildings on the map.
  2177. */
  2178. BuildingClass::Read_INI(ini);
  2179. Call_Back();
  2180. /*
  2181. ** Read in the AI's base information.
  2182. */
  2183. Base.Read_INI(ini);
  2184. Call_Back();
  2185. /*
  2186. ** Read in any normal overlay objects.
  2187. */
  2188. OverlayClass::Read_INI(ini);
  2189. Call_Back();
  2190. /*
  2191. ** Read in any smudge overlays.
  2192. */
  2193. SmudgeClass::Read_INI(ini);
  2194. Call_Back();
  2195. /* Moved above ini.Get_TextBlock(...) so Xlat mission.ini could be loaded
  2196. ** If the briefing text could not be found in the INI file, then search
  2197. ** the mission.ini file. VG 10/17/96
  2198. */
  2199. INIClass mini;
  2200. mini.Load(CCFileClass("MISSION.INI"));
  2201. mini.Get_TextBlock(fname, Scen.BriefingText, sizeof(Scen.BriefingText));
  2202. /*
  2203. ** Read in any briefing text.
  2204. */
  2205. if (Scen.BriefingText[0] == '\0') {
  2206. ini.Get_TextBlock("Briefing", Scen.BriefingText, sizeof(Scen.BriefingText));
  2207. }
  2208. /*
  2209. ** Perform a final overpass of the map. This handles smoothing of certain
  2210. ** types of terrain (tiberium).
  2211. */
  2212. Map.Overpass();
  2213. Call_Back();
  2214. /*
  2215. ** Special cases:
  2216. ** Gold Rush multiplayer map cell 9033 - LAND_ROCK
  2217. ** The Lake District multiplayer map cell 8482 - LAND_ROCK
  2218. ** Blue Lakes multiplayer map cell 11937 - LAND_RIVER
  2219. ** USSR mission 13 - fixup trigger action
  2220. ** Allied mission 5B - fail mission if spy re-boards the transport at mission start
  2221. ** Allied mission 8A - Germany is allied with Greece and itself
  2222. ** Allied mission 9A - fail mission if tech center is destroyed before being spied
  2223. ** Aftermath: Brother in Arms - have transports move to separate waypoints
  2224. ** Aftermath: Let's Make a Steal - Make the pillboxes un-capturable
  2225. ** Counterstrike: Soviet Soldier Volkov and Chitzkoi / Deus Ex Machina - Sniper burst fix
  2226. */
  2227. if (_stricmp(Scen.ScenarioName, "scmh8ea.ini") == 0) {
  2228. Map[(CELL)9033].Override_Land_Type(LAND_ROCK);
  2229. }
  2230. if (_stricmp(Scen.ScenarioName, "scm93ea.ini") == 0) {
  2231. Map[(CELL)8482].Override_Land_Type(LAND_ROCK);
  2232. }
  2233. if (_stricmp(Scen.ScenarioName, "scmh4ea.ini") == 0) {
  2234. Map[(CELL)11937].Override_Land_Type(LAND_RIVER);
  2235. }
  2236. if (_stricmp(Scen.ScenarioName, "scu13ea.ini") == 0) {
  2237. TriggerTypeClass* trigger = TriggerTypes.Ptr(11);
  2238. trigger->Action1.Trigger.Set_Raw(39);
  2239. }
  2240. if (_stricmp(Scen.ScenarioName, "scg05eb.ini") == 0) {
  2241. TeamTypeClass* spy1_team = TeamTypeClass::From_Name("spy1");
  2242. assert(spy1_team != NULL);
  2243. spy1_team->MissionList[spy1_team->MissionCount].Mission = TMISSION_SET_GLOBAL;
  2244. spy1_team->MissionList[spy1_team->MissionCount].Data.Value = 16;
  2245. spy1_team->MissionCount++;
  2246. TriggerTypeClass* los3_trigger = new TriggerTypeClass();
  2247. los3_trigger->IsPersistant = TriggerTypeClass::VOLATILE;
  2248. los3_trigger->House = HOUSE_GREECE;
  2249. los3_trigger->EventControl = MULTI_AND;
  2250. los3_trigger->ActionControl = MULTI_AND;
  2251. los3_trigger->Event1.Event = TEVENT_GLOBAL_SET;
  2252. los3_trigger->Event1.Data.Value = 16;
  2253. los3_trigger->Event2.Event = TEVENT_ALL_DESTROYED;
  2254. los3_trigger->Event2.Data.House = HOUSE_GREECE;
  2255. los3_trigger->Action1.Action = TACTION_LOSE;
  2256. los3_trigger->Action1.Data.Value = -255;
  2257. los3_trigger->Action2.Action = TACTION_NONE;
  2258. los3_trigger->Action2.Data.Value = -1;
  2259. TriggerTypeClass* frc1_trigger = TriggerTypeClass::From_Name("frc1");
  2260. assert(frc1_trigger != NULL);
  2261. frc1_trigger->Action1.Trigger = los3_trigger;
  2262. }
  2263. if (_stricmp(Scen.ScenarioName, "scg08ea.ini") == 0) {
  2264. for (int house = HOUSE_FIRST; house < HOUSE_COUNT; ++house) {
  2265. HouseClass* ptr = Houses.Ptr(house);
  2266. if (ptr != NULL && ptr->IsActive) {
  2267. if (ptr->Class->House == HOUSE_GREECE || ptr->Class->House == HOUSE_GERMANY) {
  2268. ptr->Make_Ally(HOUSE_GERMANY);
  2269. }
  2270. }
  2271. }
  2272. }
  2273. if (_stricmp(Scen.ScenarioName, "scg09ea.ini") == 0) {
  2274. TriggerTypeClass* spyd_trigger = TriggerTypeClass::From_Name("Spyd");
  2275. assert(spyd_trigger != NULL);
  2276. TriggerTypeClass* kos_trigger = new TriggerTypeClass();
  2277. kos_trigger->IsPersistant = spyd_trigger->IsPersistant;
  2278. kos_trigger->House = spyd_trigger->House;
  2279. kos_trigger->EventControl = MULTI_LINKED;
  2280. kos_trigger->ActionControl = MULTI_ONLY;
  2281. kos_trigger->Event1.Event = spyd_trigger->Event1.Event;
  2282. kos_trigger->Event1.Data = spyd_trigger->Event1.Data;
  2283. kos_trigger->Event2.Event = TEVENT_DESTROYED;
  2284. kos_trigger->Event2.Data.Value = 0;
  2285. kos_trigger->Action1.Action = TACTION_SET_GLOBAL;
  2286. kos_trigger->Action1.Data.Value = 22;
  2287. kos_trigger->Action2.Action = TACTION_SET_GLOBAL;
  2288. kos_trigger->Action2.Data.Value = 23;
  2289. spyd_trigger->Event1.Event = TEVENT_GLOBAL_SET;
  2290. spyd_trigger->Event1.Data.Value = 22;
  2291. for (int index = 0; index < Buildings.Count(); index++) {
  2292. BuildingClass* building = Buildings.Ptr(index);
  2293. if (building->Trigger.Is_Valid() && (building->Trigger->Class == spyd_trigger)) {
  2294. building->Attach_Trigger(Find_Or_Make(kos_trigger));
  2295. }
  2296. }
  2297. TriggerTypeClass* los3_trigger = new TriggerTypeClass();
  2298. los3_trigger->IsPersistant = spyd_trigger->IsPersistant;
  2299. los3_trigger->House = spyd_trigger->House;
  2300. los3_trigger->EventControl = MULTI_AND;
  2301. los3_trigger->ActionControl = MULTI_AND;
  2302. los3_trigger->Event1.Event = TEVENT_GLOBAL_SET;
  2303. los3_trigger->Event1.Data.Value = 23;
  2304. los3_trigger->Event2.Event = TEVENT_GLOBAL_CLEAR;
  2305. los3_trigger->Event2.Data.Value = 22;
  2306. los3_trigger->Action1.Action = TACTION_LOSE;
  2307. los3_trigger->Action1.Data.Value = -255;
  2308. los3_trigger->Action2.Action = TACTION_TEXT_TRIGGER;
  2309. los3_trigger->Action2.Data.Value = 54;
  2310. }
  2311. if (_stricmp(Scen.ScenarioName, "scu46ea.ini") == 0) {
  2312. Scen.Waypoint[20] = 9915;
  2313. Scen.Waypoint[21] = 9919;
  2314. Map[Scen.Waypoint[20]].IsWaypoint = 1;
  2315. Map[Scen.Waypoint[21]].IsWaypoint = 1;
  2316. TeamTypeClass* rnf1_team = TeamTypeClass::From_Name("rnf1");
  2317. assert(rnf1_team != NULL);
  2318. rnf1_team->MissionList[0].Data.Value = 20;
  2319. TeamTypeClass* rnf2_team = TeamTypeClass::From_Name("rnf2");
  2320. assert(rnf2_team != NULL);
  2321. rnf2_team->MissionList[0].Data.Value = 21;
  2322. }
  2323. if (_stricmp(Scen.ScenarioName, "scu42ea.ini") == 0) {
  2324. BuildingTypeClass::As_Reference(STRUCT_PILLBOX).IsCaptureable = false;
  2325. }
  2326. if ((_stricmp(Scen.ScenarioName, "scu35ea.ini") == 0) || (_stricmp(Scen.ScenarioName, "scu47ea.ini") == 0)) {
  2327. WeaponTypeClass::As_Pointer(Weapon_From_Name("Sniper"))->Burst = 2;
  2328. }
  2329. /*
  2330. ** Multi-player last-minute fixups:
  2331. ** - If computer players are disabled, remove all computer-owned houses
  2332. ** - If bases are disabled, create the scenario dynamically
  2333. ** - Remove any flag spot overlays lying around
  2334. ** - If capture-the-flag is enabled, assign flags to cells.
  2335. */
  2336. if (Session.Type != GAME_NORMAL /*|| Scen.ScenPlayer == SCEN_PLAYER_2PLAYER || Scen.ScenPlayer == SCEN_PLAYER_MPLAYER*/) {
  2337. /*
  2338. ** If Ghosts are disabled and we're not editing, remove computer players
  2339. ** (Must be done after all objects are read in from the INI)
  2340. */
  2341. if ( (Session.Options.AIPlayers + Session.Players.Count() < Rule.MaxPlayers) && !Debug_Map) {
  2342. Remove_AI_Players();
  2343. }
  2344. /*
  2345. ** Units must be created for each house. If bases are ON, this routine
  2346. ** will create an MCV along with the units; otherwise, it will just create
  2347. ** a whole bunch of units. Session.Options.UnitCount is the total # of units
  2348. ** to create.
  2349. */
  2350. if (!Debug_Map) {
  2351. int save_init = ScenarioInit; // turn ScenarioInit off
  2352. ScenarioInit = 0;
  2353. Create_Units(ini.Get_Bool("Basic", "Official", false));
  2354. ScenarioInit = save_init; // turn ScenarioInit back on
  2355. }
  2356. /*
  2357. ** Place crates if random crates are enabled for
  2358. ** this scenario.
  2359. */
  2360. if (Session.Options.Goodies) {
  2361. int count = max(Rule.CrateMinimum, Session.NumPlayers);
  2362. count = min(count, Rule.CrateMaximum);
  2363. for (int index = 0; index < count; index++) {
  2364. Map.Place_Random_Crate();
  2365. }
  2366. }
  2367. }
  2368. Call_Back();
  2369. /*
  2370. ** Return with flag saying that the scenario file was read.
  2371. */
  2372. #ifdef FIXIT_CSII // checked - ajw 9/28/98 - Added runtime check.
  2373. if( Is_Aftermath_Installed() )
  2374. {
  2375. if (Session.Type == GAME_SKIRMISH || Session.Type == GAME_GLYPHX_MULTIPLAYER) {
  2376. bAftermathMultiplayer = NewUnitsEnabled = OverrideNewUnitsEnabled;
  2377. }
  2378. }
  2379. #endif
  2380. ScenarioInit--;
  2381. return(true);
  2382. }
  2383. /***********************************************************************************************
  2384. * Write_Scenario_INI -- Write the scenario INI file. *
  2385. * *
  2386. * INPUT: *
  2387. * root root filename for the scenario *
  2388. * *
  2389. * OUTPUT: *
  2390. * none. *
  2391. * *
  2392. * WARNINGS: *
  2393. * none. *
  2394. * *
  2395. * HISTORY: *
  2396. * 10/07/1992 JLB : Created. *
  2397. * 05/11/1995 JLB : Updates movie data. *
  2398. *=============================================================================================*/
  2399. void Write_Scenario_INI(char * fname)
  2400. {
  2401. #ifndef CHEAT_KEYS
  2402. fname = fname;
  2403. #else
  2404. // CCFileClass file(fname);
  2405. CCINIClass ini;
  2406. /*
  2407. ** Preload the old scenario if it is present because there may
  2408. ** be some fields in the INI that are processed but not written
  2409. ** out. Preloading the scenario will preserve these manually
  2410. ** maintained entries.
  2411. */
  2412. if (CCFileClass(fname).Is_Available()) {
  2413. ini.Load(CCFileClass(fname), true);
  2414. }
  2415. static char const * const BASIC = "Basic";
  2416. ini.Clear(BASIC);
  2417. ini.Put_String(BASIC, "Name", Scen.Description);
  2418. ini.Put_VQType(BASIC, "Intro", Scen.IntroMovie);
  2419. ini.Put_VQType(BASIC, "Brief", Scen.BriefMovie);
  2420. ini.Put_VQType(BASIC, "Win", Scen.WinMovie);
  2421. ini.Put_VQType(BASIC, "Lose", Scen.LoseMovie);
  2422. ini.Put_VQType(BASIC, "Action", Scen.ActionMovie);
  2423. ini.Put_HousesType(BASIC, "Player", PlayerPtr->Class->House);
  2424. ini.Put_ThemeType(BASIC, "Theme", Scen.TransitTheme);
  2425. ini.Put_Fixed(BASIC, "CarryOverMoney", Scen.CarryOverPercent);
  2426. ini.Put_Bool(BASIC, "ToCarryOver", Scen.IsToCarryOver);
  2427. ini.Put_Bool(BASIC, "ToInherit", Scen.IsToInherit);
  2428. ini.Put_Bool(BASIC, "TimerInherit", Scen.IsInheritTimer);
  2429. ini.Put_Bool(BASIC, "CivEvac", Scen.IsTanyaEvac);
  2430. ini.Put_Int(BASIC, "NewINIFormat", 3);
  2431. ini.Put_Int(BASIC, "CarryOverCap", Scen.CarryOverCap/100);
  2432. ini.Put_Bool(BASIC, "EndOfGame", Scen.IsEndOfGame);
  2433. ini.Put_Bool(BASIC, "NoSpyPlane", Scen.IsNoSpyPlane);
  2434. ini.Put_Bool(BASIC, "SkipScore", Scen.IsSkipScore);
  2435. ini.Put_Bool(BASIC, "OneTimeOnly", Scen.IsOneTimeOnly);
  2436. ini.Put_Bool(BASIC, "SkipMapSelect", Scen.IsNoMapSel);
  2437. ini.Put_Bool(BASIC, "Official", true);
  2438. ini.Put_Bool(BASIC, "FillSilos", Scen.IsMoneyTiberium);
  2439. ini.Put_Bool(BASIC, "TruckCrate", Scen.IsTruckCrate);
  2440. ini.Put_Int(BASIC, "Percent", Scen.Percent);
  2441. HouseClass::Write_INI(ini);
  2442. TeamTypeClass::Write_INI(ini);
  2443. TriggerTypeClass::Write_INI(ini);
  2444. Map.Write_INI(ini);
  2445. TerrainClass::Write_INI(ini);
  2446. UnitClass::Write_INI(ini);
  2447. VesselClass::Write_INI(ini);
  2448. InfantryClass::Write_INI(ini);
  2449. BuildingClass::Write_INI(ini);
  2450. Base.Write_INI(ini);
  2451. OverlayClass::Write_INI(ini);
  2452. SmudgeClass::Write_INI(ini);
  2453. if (strlen(Scen.BriefingText)) {
  2454. ini.Put_TextBlock("Briefing", Scen.BriefingText);
  2455. }
  2456. // sprintf(fname, "%s.INI", root);
  2457. RawFileClass rawfile(fname);
  2458. ini.Save(rawfile, true);
  2459. #endif
  2460. }
  2461. /***********************************************************************************************
  2462. * Assign_Houses -- Assigns multiplayer houses to various players *
  2463. * *
  2464. * This routine assigns all players to a multiplayer house slot; it forms network connections *
  2465. * to each player. The Connection ID used is the value for that player's HousesType. *
  2466. * *
  2467. * PlayerPtr is also set here. *
  2468. * *
  2469. * INPUT: *
  2470. * none. *
  2471. * *
  2472. * OUTPUT: *
  2473. * none. *
  2474. * *
  2475. * WARNINGS: *
  2476. * This routine assumes the 'Players' vector has been properly filled in with players' *
  2477. * names, addresses, color, etc. *
  2478. * Also, it's assumed that the HouseClass's have all been created & initialized. *
  2479. * *
  2480. * HISTORY: *
  2481. * 06/09/1995 BRR : Created. *
  2482. * 07/14/1995 JLB : Records name of player in house structure. *
  2483. *=============================================================================================*/
  2484. void Assign_Houses(void)
  2485. {
  2486. int assigned[MAX_PLAYERS];
  2487. int color_used[8];
  2488. int i,j;
  2489. HousesType house;
  2490. HouseClass * housep;
  2491. int lowest_color;
  2492. int index;
  2493. HousesType pref_house;
  2494. int color;
  2495. //------------------------------------------------------------------------
  2496. // Initialize
  2497. //------------------------------------------------------------------------
  2498. for (i = 0; i < MAX_PLAYERS; i++) {
  2499. assigned[i] = 0;
  2500. color_used[i] = 0;
  2501. }
  2502. // debugprint( "Assign_Houses()\n" );
  2503. //------------------------------------------------------------------------
  2504. // Assign each player in 'Players' to a multiplayer house. Players will
  2505. // be sorted by their chosen color value (this value must be unique among
  2506. // all the players).
  2507. //------------------------------------------------------------------------
  2508. for (i = 0; i < Session.Players.Count(); i++) {
  2509. //.....................................................................
  2510. // Find the player with the lowest color index
  2511. //.....................................................................
  2512. index = 0;
  2513. lowest_color = 255;
  2514. for (j = 0; j < Session.Players.Count(); j++) {
  2515. //..................................................................
  2516. // If we've already assigned this house, skip it.
  2517. //..................................................................
  2518. if (assigned[j]) {
  2519. continue;
  2520. }
  2521. if (Session.Players[j]->Player.Color < lowest_color) {
  2522. lowest_color = Session.Players[j]->Player.Color;
  2523. index = j;
  2524. }
  2525. }
  2526. //.....................................................................
  2527. // Mark this player as having been assigned.
  2528. //.....................................................................
  2529. assigned[index] = 1;
  2530. color_used[Session.Players[index]->Player.Color] = 1;
  2531. //.....................................................................
  2532. // Assign the lowest-color'd player to the next available slot in the
  2533. // HouseClass array.
  2534. //.....................................................................
  2535. house = (HousesType)(i + HOUSE_MULTI1);
  2536. housep = HouseClass::As_Pointer(house);
  2537. memset((char *)housep->IniName, 0, MPLAYER_NAME_MAX);
  2538. strncpy((char *)housep->IniName, Session.Players[index]->Name, MPLAYER_NAME_MAX - 1);
  2539. #ifdef WOLAPI_INTEGRATION
  2540. // Make another copy of name, permanent throughout entire game.
  2541. strncpy((char *)housep->InitialName, Session.Players[index]->Name, MPLAYER_NAME_MAX - 1);
  2542. #endif
  2543. housep->IsHuman = true;
  2544. housep->Init_Data((PlayerColorType)(Session.Players[index]->Player.Color),
  2545. Session.Players[index]->Player.House, Session.Options.Credits);
  2546. if (index == 0) {
  2547. PlayerPtr = housep;
  2548. }
  2549. /*
  2550. ** Convert the build level into an actual tech level to assign to the house.
  2551. ** There isn't a one-to-one correspondence.
  2552. */
  2553. housep->Control.TechLevel = _build_tech[BuildLevel];
  2554. housep->Assign_Handicap(Scen.Difficulty);
  2555. //.....................................................................
  2556. // Record where we placed this player
  2557. //.....................................................................
  2558. Session.Players[index]->Player.ID = house;
  2559. // debugprint( "Assigned ID of %i to %s\n", house, Session.Players[index]->Name );
  2560. }
  2561. //------------------------------------------------------------------------
  2562. // Now assign computer players to the remaining houses.
  2563. //------------------------------------------------------------------------
  2564. for (i = Session.Players.Count(); i < Session.Players.Count() + Session.Options.AIPlayers; i++) {
  2565. house = (HousesType)(i + HOUSE_MULTI1);
  2566. housep = HouseClass::As_Pointer(house);
  2567. if (Percent_Chance(50)) {
  2568. pref_house = HOUSE_GREECE;
  2569. } else {
  2570. pref_house = HOUSE_USSR;
  2571. }
  2572. //.....................................................................
  2573. // Pick a color for this house; keep looping until we find one.
  2574. //.....................................................................
  2575. while (1) {
  2576. color = Random_Pick(0, 7);
  2577. if (color_used[color] == false) {
  2578. break;
  2579. }
  2580. }
  2581. color_used[color] = true;
  2582. //.....................................................................
  2583. // Set up the house
  2584. //.....................................................................
  2585. // housep->Control.MaxUnit = 80;
  2586. // housep->Control.MaxInfantry = 60;
  2587. // housep->Control.MaxBuilding = 60;
  2588. // housep->Control.MaxVessel = 60;
  2589. housep->IsHuman = false;
  2590. housep->IsStarted = true;
  2591. strcpy(housep->IniName, Text_String(TXT_COMPUTER));
  2592. if (Session.Type != GAME_NORMAL) {
  2593. housep->IQ = Rule.MaxIQ;
  2594. }
  2595. housep->Init_Data((PlayerColorType)color, pref_house, Session.Options.Credits);
  2596. housep->Control.TechLevel = _build_tech[BuildLevel];
  2597. // housep->Control.TechLevel = BuildLevel;
  2598. DiffType difficulty = Scen.CDifficulty;
  2599. if (Session.Players.Count() > 1 && Rule.IsCompEasyBonus && difficulty > DIFF_EASY) {
  2600. difficulty = (DiffType)(difficulty - 1);
  2601. }
  2602. housep->Assign_Handicap(difficulty);
  2603. }
  2604. for (i = Session.Players.Count()+Session.Options.AIPlayers; i < Rule.MaxPlayers; i++) {
  2605. house = (HousesType)(i + HOUSE_MULTI1);
  2606. housep = HouseClass::As_Pointer(house);
  2607. if (housep != NULL) {
  2608. housep->IsDefeated = true;
  2609. }
  2610. }
  2611. }
  2612. /***********************************************************************************************
  2613. * Remove_AI_Players -- Removes the computer AI houses & their units *
  2614. * *
  2615. * INPUT: *
  2616. * none. *
  2617. * *
  2618. * OUTPUT: *
  2619. * none. *
  2620. * *
  2621. * WARNINGS: *
  2622. * none. *
  2623. * *
  2624. * HISTORY: *
  2625. * 06/09/1995 BRR : Created. *
  2626. *=============================================================================================*/
  2627. static void Remove_AI_Players(void)
  2628. {
  2629. int i;
  2630. int aicount = 0;
  2631. HousesType house;
  2632. HouseClass * housep;
  2633. #if (0)
  2634. for (i = 0; i < MAX_PLAYERS; i++) {
  2635. house = (HousesType)(i + (int)HOUSE_MULTI1);
  2636. housep = HouseClass::As_Pointer (house);
  2637. if (housep->IsHuman == false) {
  2638. aicount++;
  2639. if(aicount > Session.Options.AIPlayers) {
  2640. housep->Clobber_All();
  2641. }
  2642. }
  2643. }
  2644. #else
  2645. /*
  2646. ** AI players are set up like human players now. ST - 8/13/2019 1:32PM
  2647. */
  2648. for (i = 0; i < MAX_PLAYERS; i++) {
  2649. if (i >= Session.Players.Count()) {
  2650. house = (HousesType)(i + (int)HOUSE_MULTI1);
  2651. housep = HouseClass::As_Pointer (house);
  2652. if (housep->IsHuman == false) {
  2653. housep->Clobber_All();
  2654. }
  2655. }
  2656. }
  2657. #endif
  2658. }
  2659. #define USE_GLYPHX_START_LOCATIONS 1
  2660. /***********************************************************************************************
  2661. * Create_Units -- Creates infantry & units, for non-base multiplayer *
  2662. * *
  2663. * This routine uses data tables to determine which units to create for either *
  2664. * a GDI or NOD house, and how many of each. *
  2665. * *
  2666. * It also sets each house's FlagHome & FlagLocation to the Waypoint selected *
  2667. * as that house's "home" cell. *
  2668. * *
  2669. * INPUT: official -- Directs the placement logic to use the full set of waypoints rather *
  2670. * than biasing toward the first four. *
  2671. * *
  2672. * OUTPUT: *
  2673. * none. *
  2674. * *
  2675. * WARNINGS: *
  2676. * none. *
  2677. * *
  2678. * HISTORY: *
  2679. * 06/09/1995 BRR : Created. *
  2680. *=============================================================================================*/
  2681. static int ReserveInfantryIndex = 0;
  2682. static void Reserve_Infantry()
  2683. {
  2684. if (Infantry.Count() == Infantry.Length()) {
  2685. delete Infantry.Ptr(ReserveInfantryIndex);
  2686. ReserveInfantryIndex = (ReserveInfantryIndex + 1) % Infantry.Length();
  2687. }
  2688. }
  2689. static int ReserveUnitIndex = 0;
  2690. static void Reserve_Unit()
  2691. {
  2692. if (Units.Count() == Units.Length()) {
  2693. delete Units.Ptr(ReserveUnitIndex);
  2694. ReserveUnitIndex = (ReserveUnitIndex + 1) % Units.Length();
  2695. }
  2696. }
  2697. static void Create_Units(bool official)
  2698. {
  2699. static struct {
  2700. int MinLevel;
  2701. UnitType AllyType[2];
  2702. UnitType SovietType[2];
  2703. } utable[] = {
  2704. {4, {UNIT_MTANK2, UNIT_LTANK}, {UNIT_MTANK, UNIT_NONE}},
  2705. {5, {UNIT_APC, UNIT_NONE}, {UNIT_V2_LAUNCHER, UNIT_NONE}},
  2706. {8, {UNIT_ARTY, UNIT_JEEP}, {UNIT_MTANK, UNIT_NONE}},
  2707. {10, {UNIT_MTANK2, UNIT_MTANK2}, {UNIT_HTANK, UNIT_NONE}}
  2708. };
  2709. static int num_units[ARRAY_SIZE(utable)]; // # of each type of unit to create
  2710. int tot_units; // total # units to create
  2711. static struct {
  2712. int MinLevel;
  2713. int AllyCount;
  2714. InfantryType AllyType;
  2715. int SovietCount;
  2716. InfantryType SovietType;
  2717. } itable[] = {
  2718. {0, 1,INFANTRY_E1, 1,INFANTRY_E1},
  2719. {2, 1,INFANTRY_E3, 1,INFANTRY_E2},
  2720. {4, 1,INFANTRY_E3, 1,INFANTRY_E4},
  2721. // removed because of bug B478 (inappropriate infantry given in a bases off scenario).
  2722. // {5, 1,INFANTRY_RENOVATOR, 1,INFANTRY_RENOVATOR},
  2723. // {6, 1,INFANTRY_SPY, 1,INFANTRY_DOG},
  2724. // {10, 1,INFANTRY_THIEF, 1,INFANTRY_DOG},
  2725. // {12, 1,INFANTRY_MEDIC, 2,INFANTRY_DOG}
  2726. };
  2727. static int num_infantry[ARRAY_SIZE(itable)];// # of each type of infantry to create
  2728. int tot_infantry; // total # infantry to create
  2729. CELL centroid; // centroid of this house's stuff
  2730. CELL centerpt; // centroid for a category of objects, as a CELL
  2731. int u_limit=0; // last allowable index of units for this BuildLevel
  2732. int i_limit=0; // last allowable index of infantry for this BuildLevel
  2733. TechnoClass * obj; // newly-created object
  2734. int i,j,k; // loop counters
  2735. int scaleval; // value to scale # units or infantry
  2736. ReserveInfantryIndex = ReserveUnitIndex = 0;
  2737. /*
  2738. ** For the current BuildLevel, find the max allowable index into the tables
  2739. */
  2740. for (i = 0; i < ARRAY_SIZE(utable); i++) {
  2741. if (PlayerPtr->Control.TechLevel >= utable[i].MinLevel) {
  2742. u_limit = i+1;
  2743. }
  2744. }
  2745. for (i = 0; i < ARRAY_SIZE(itable); i++) {
  2746. if (PlayerPtr->Control.TechLevel >= itable[i].MinLevel) {
  2747. i_limit = i+1;
  2748. }
  2749. }
  2750. /*
  2751. ** Compute how many of each buildable category to create
  2752. */
  2753. /*
  2754. ** Compute allowed # units
  2755. */
  2756. tot_units = (Session.Options.UnitCount * 2) / 3;
  2757. if (u_limit == 0) tot_units = 0;
  2758. /*
  2759. ** Init # of each category to 0
  2760. */
  2761. for (i = 0; i < u_limit; i++) {
  2762. num_units[i] = 0;
  2763. }
  2764. /*
  2765. ** Increment # of each category, until we've used up all units
  2766. */
  2767. j = 0;
  2768. for (i = 0; i < tot_units; i++) {
  2769. num_units[j]++;
  2770. j++;
  2771. if (j >= u_limit) {
  2772. j = 0;
  2773. }
  2774. }
  2775. /*
  2776. ** Compute allowed # infantry
  2777. */
  2778. tot_infantry = Session.Options.UnitCount - tot_units;
  2779. /*
  2780. ** Init # of each category to 0
  2781. */
  2782. for (i = 0; i < i_limit; i++) {
  2783. num_infantry[i] = 0;
  2784. }
  2785. /*
  2786. ** Increment # of each category, until we've used up all infantry
  2787. */
  2788. j = 0;
  2789. for (i = 0; i < tot_infantry; i++) {
  2790. num_infantry[j]++;
  2791. j++;
  2792. if (j >= i_limit) {
  2793. j = 0;
  2794. }
  2795. }
  2796. /*
  2797. ** Build a list of the valid waypoints. This normally shouldn't be
  2798. ** necessary because the scenario level designer should have assigned
  2799. ** valid locations to the first N waypoints, but just in case, this
  2800. ** loop verifies that.
  2801. */
  2802. const unsigned int MAX_STORED_WAYPOINTS = 26;
  2803. bool taken[MAX_STORED_WAYPOINTS];
  2804. CELL waypts[MAX_STORED_WAYPOINTS];
  2805. assert(Rule.MaxPlayers < ARRAY_SIZE(waypts));
  2806. int num_waypts = 0;
  2807. /*
  2808. ** Calculate the number of waypoints (as a minimum) that will be lifted from the
  2809. ** mission file. Bias this number so that only the first 4 waypoints are used
  2810. ** if there are 4 or fewer players. Unofficial maps will pick from all the
  2811. ** available waypoints.
  2812. */
  2813. #ifndef USE_GLYPHX_START_LOCATIONS
  2814. int look_for = max(4, Session.Players.Count()+Session.Options.AIPlayers);
  2815. if (!official) {
  2816. look_for = 8;
  2817. }
  2818. #else
  2819. /*
  2820. ** We allow the users to choose from all available start positions, even on official maps. ST - 1/15/2020 9:19AM
  2821. */
  2822. int look_for = Session.Players.Count();
  2823. #endif
  2824. for (int waycount = 0; waycount < 26; waycount++) {
  2825. // for (int waycount = 0; waycount < max(4, Session.Players.Count()+Session.Options.AIPlayers); waycount++) {
  2826. if (Scen.Waypoint[waycount] != -1) {
  2827. waypts[num_waypts] = Scen.Waypoint[waycount];
  2828. taken[num_waypts] = false;
  2829. num_waypts++;
  2830. if (num_waypts >= MAX_STORED_WAYPOINTS)
  2831. {
  2832. break;
  2833. }
  2834. }
  2835. }
  2836. /*
  2837. ** If there are insufficient waypoints to account for all players, then randomly assign
  2838. ** starting points until there is enough.
  2839. */
  2840. int deficiency = look_for - num_waypts;
  2841. // int deficiency = (Session.Players.Count() + Session.Options.AIPlayers) - num_waypts;
  2842. if (deficiency > 0) {
  2843. for (int index = 0; index < deficiency; index++) {
  2844. CELL trycell = XY_Cell(Map.MapCellX + Random_Pick(0, Map.MapCellWidth-1), Map.MapCellY + Random_Pick(0, Map.MapCellHeight-1));
  2845. trycell = Map.Nearby_Location(trycell, SPEED_TRACK);
  2846. waypts[num_waypts] = trycell;
  2847. taken[num_waypts] = false;
  2848. num_waypts++;
  2849. }
  2850. }
  2851. /*
  2852. ** Loop through all houses. Computer-controlled houses, with Session.Options.Bases
  2853. ** ON, are treated as though bases are OFF (since we have no base-building
  2854. ** AI logic.)
  2855. */
  2856. int numtaken = 0;
  2857. for (HousesType house = HOUSE_MULTI1; house < (HOUSE_MULTI1 + Session.MaxPlayers); house++) {
  2858. /*
  2859. ** Get a pointer to this house; if there is none, go to the next house
  2860. */
  2861. HouseClass * hptr = HouseClass::As_Pointer(house);
  2862. if (hptr == NULL) {
  2863. continue;
  2864. }
  2865. /*
  2866. ** Pick the starting location for this house. The first house just picks
  2867. ** one of the valid locations at random. The other houses pick the furthest
  2868. ** wapoint from the existing houses.
  2869. */
  2870. if (!UseGlyphXStartLocations) {
  2871. if (numtaken == 0) {
  2872. int pick = Random_Pick(0, num_waypts-1);
  2873. centroid = waypts[pick];
  2874. hptr->StartLocationOverride = pick;
  2875. taken[pick] = true;
  2876. numtaken++;
  2877. } else {
  2878. /*
  2879. ** Set all waypoints to have a score of zero in preparation for giving
  2880. ** a distance score to all waypoints.
  2881. */
  2882. int score[26];
  2883. memset(score, '\0', sizeof(score));
  2884. /*
  2885. ** Scan through all waypoints and give a score as a value of the sum
  2886. ** of the distances from this waypoint to all taken waypoints.
  2887. */
  2888. for (int index = 0; index < num_waypts; index++) {
  2889. /*
  2890. ** If this waypoint has not already been taken, then accumulate the
  2891. ** sum of the distance between this waypoint and all other taken
  2892. ** waypoints.
  2893. */
  2894. if (!taken[index]) {
  2895. for (int trypoint = 0; trypoint < num_waypts; trypoint++) {
  2896. if (taken[trypoint]) {
  2897. score[index] += Distance(Cell_Coord(waypts[index]), Cell_Coord(waypts[trypoint]));
  2898. }
  2899. }
  2900. }
  2901. }
  2902. /*
  2903. ** Now find the waypoint with the largest score. This waypoint is the one
  2904. ** that is furthest from all other taken waypoints.
  2905. */
  2906. int best = 0;
  2907. int bestvalue = 0;
  2908. for (int searchindex = 0; searchindex < num_waypts; searchindex++) {
  2909. if (score[searchindex] > bestvalue || bestvalue == 0) {
  2910. bestvalue = score[searchindex];
  2911. best = searchindex;
  2912. }
  2913. }
  2914. /*
  2915. ** Assign this best position to the house.
  2916. */
  2917. centroid = waypts[best];
  2918. hptr->StartLocationOverride = best;
  2919. taken[best] = true;
  2920. numtaken++;
  2921. }
  2922. } else {
  2923. /*
  2924. ** New code that respects the start locations passed in from GlyphX.
  2925. **
  2926. ** ST - 1/8/2020 3:39PM
  2927. */
  2928. centroid = waypts[hptr->StartLocationOverride];
  2929. }
  2930. /*
  2931. ** Assign the center of this house to the waypoint location.
  2932. */
  2933. hptr->Center = Cell_Coord(centroid);
  2934. /*
  2935. ** If Bases are ON, human & computer houses are treated differently
  2936. */
  2937. if (Session.Options.Bases) {
  2938. /*
  2939. ** - For a human-controlled house:
  2940. ** - Set 'scaleval' to 1
  2941. ** - Create an MCV
  2942. ** - Attach a flag to it for capture-the-flag mode
  2943. */
  2944. scaleval = 1;
  2945. Reserve_Unit();
  2946. obj = new UnitClass (UNIT_MCV, house);
  2947. if (!obj->Unlimbo(Cell_Coord(centroid), DIR_N)) {
  2948. if (!Scan_Place_Object(obj, centroid)) {
  2949. delete obj;
  2950. obj = NULL;
  2951. }
  2952. }
  2953. if (obj != NULL) {
  2954. hptr->FlagHome = 0;
  2955. hptr->FlagLocation = 0;
  2956. if (Special.IsCaptureTheFlag) {
  2957. hptr->Flag_Attach((UnitClass *)obj, true);
  2958. }
  2959. }
  2960. } else {
  2961. /*
  2962. ** If bases are OFF, set 'scaleval' to 1 & create a Mobile HQ for
  2963. ** capture-the-flag mode.
  2964. */
  2965. scaleval = 1;
  2966. #ifdef TOFIX
  2967. if (Special.IsCaptureTheFlag) {
  2968. obj = new UnitClass (UNIT_TRUCK, house);
  2969. obj->Unlimbo(Cell_Coord(centroid), DIR_N);
  2970. hptr->FlagHome = 0; // turn house's flag off
  2971. hptr->FlagLocation = 0;
  2972. }
  2973. #endif
  2974. }
  2975. /*
  2976. ** Create units for this house
  2977. */
  2978. for (i = 0; i < u_limit; i++) {
  2979. /*
  2980. ** Find the center point for this category.
  2981. */
  2982. centerpt = Clip_Scatter(centroid, 4);
  2983. /*
  2984. ** Place objects; loop through all unit in this category
  2985. */
  2986. for (j = 0; j < num_units[i] * scaleval; j++) {
  2987. /*
  2988. ** Create an Ally unit
  2989. */
  2990. if (hptr->ActLike != HOUSE_USSR && hptr->ActLike != HOUSE_UKRAINE) {
  2991. for (k = 0; k < 2; k++) if(utable[i].AllyType[k] != UNIT_NONE) {
  2992. Reserve_Unit();
  2993. obj = new UnitClass (utable[i].AllyType[k], house);
  2994. if (!Scan_Place_Object(obj, centerpt)) {
  2995. delete obj;
  2996. } else {
  2997. if (!hptr->IsHuman) {
  2998. obj->Set_Mission(MISSION_GUARD_AREA);
  2999. } else {
  3000. obj->Set_Mission(MISSION_GUARD);
  3001. }
  3002. }
  3003. }
  3004. } else {
  3005. /*
  3006. ** Create a Soviet unit
  3007. */
  3008. for (k = 0; k < 2; k++) if(utable[i].SovietType[k] != UNIT_NONE) {
  3009. Reserve_Unit();
  3010. obj = new UnitClass (utable[i].SovietType[k], house);
  3011. if (!Scan_Place_Object(obj, centerpt)) {
  3012. delete obj;
  3013. } else {
  3014. if (!hptr->IsHuman) {
  3015. obj->Set_Mission(MISSION_GUARD_AREA);
  3016. } else {
  3017. obj->Set_Mission(MISSION_GUARD);
  3018. }
  3019. }
  3020. }
  3021. }
  3022. }
  3023. }
  3024. /*
  3025. ** Create infantry
  3026. */
  3027. for (i = 0; i < i_limit; i++) {
  3028. /*
  3029. ** Find the center point for this category.
  3030. */
  3031. centerpt = Clip_Scatter(centroid, 4);
  3032. /*
  3033. ** Place objects; loop through all unit in this category
  3034. */
  3035. for (j = 0; j < num_infantry[i] * scaleval; j++) {
  3036. /*
  3037. ** Create Ally infantry (Note: Unlimbo calls Enter_Idle_Mode(), which
  3038. ** assigns the infantry to HUNT; we must use Set_Mission() to override
  3039. ** this state.)
  3040. */
  3041. if (hptr->ActLike != HOUSE_USSR && hptr->ActLike != HOUSE_UKRAINE) {
  3042. for (k = 0; k < itable[i].AllyCount; k++) {
  3043. Reserve_Infantry();
  3044. obj = new InfantryClass (itable[i].AllyType, house);
  3045. if (!Scan_Place_Object(obj, centerpt)) {
  3046. delete obj;
  3047. } else {
  3048. if (!hptr->IsHuman) {
  3049. obj->Set_Mission(MISSION_GUARD_AREA);
  3050. } else {
  3051. obj->Set_Mission(MISSION_GUARD);
  3052. }
  3053. }
  3054. }
  3055. } else {
  3056. /*
  3057. ** Create Soviet infantry
  3058. */
  3059. for (k = 0; k < itable[i].SovietCount; k++) {
  3060. Reserve_Infantry();
  3061. obj = new InfantryClass (itable[i].SovietType, house);
  3062. if (!Scan_Place_Object(obj, centerpt)) {
  3063. delete obj;
  3064. } else {
  3065. if (!hptr->IsHuman) {
  3066. obj->Set_Mission(MISSION_GUARD_AREA);
  3067. } else {
  3068. obj->Set_Mission(MISSION_GUARD);
  3069. }
  3070. }
  3071. }
  3072. }
  3073. }
  3074. }
  3075. }
  3076. }
  3077. /***********************************************************************************************
  3078. * Scan_Place_Object -- places an object >near< the given cell *
  3079. * *
  3080. * INPUT: *
  3081. * obj ptr to object to Unlimbo *
  3082. * cell center of search area *
  3083. * *
  3084. * OUTPUT: *
  3085. * true = object was placed; false = it wasn't *
  3086. * *
  3087. * WARNINGS: *
  3088. * none. *
  3089. * *
  3090. * HISTORY: *
  3091. * 06/09/1995 BRR : Created. *
  3092. *=============================================================================================*/
  3093. int Scan_Place_Object(ObjectClass * obj, CELL cell)
  3094. {
  3095. int dist; // for object placement
  3096. FacingType rot; // for object placement
  3097. FacingType fcounter; // for object placement
  3098. int tryval;
  3099. CELL newcell;
  3100. TechnoClass * techno;
  3101. int skipit;
  3102. /*
  3103. ** First try to unlimbo the object in the given cell.
  3104. */
  3105. if (Map.In_Radar(cell)) {
  3106. techno = Map[cell].Cell_Techno();
  3107. if (!techno || (techno->What_Am_I()==RTTI_INFANTRY &&
  3108. obj->What_Am_I()==RTTI_INFANTRY)) {
  3109. if (obj->Unlimbo(Cell_Coord(cell), DIR_N)) {
  3110. return(true);
  3111. }
  3112. }
  3113. }
  3114. /*
  3115. ** Loop through distances from the given center cell; skip the center cell.
  3116. ** For each distance, try placing the object along each rotational direction;
  3117. ** if none are available, try each direction with a random scatter value.
  3118. ** If that fails, go to the next distance.
  3119. ** This ensures that the closest coordinates are filled first.
  3120. */
  3121. for (dist = 1; dist < 32; dist++) {
  3122. /*
  3123. ** Pick a random starting direction
  3124. */
  3125. rot = Random_Pick(FACING_N, FACING_NW);
  3126. /*
  3127. ** Try all directions twice
  3128. */
  3129. for (tryval = 0 ; tryval < 2; tryval++) {
  3130. /*
  3131. ** Loop through all directions, at this distance.
  3132. */
  3133. for (fcounter = FACING_N; fcounter <= FACING_NW; fcounter++) {
  3134. skipit = false;
  3135. /*
  3136. ** Pick a coordinate along this directional axis
  3137. */
  3138. newcell = Clip_Move(cell, rot, dist);
  3139. /*
  3140. ** If this is our second try at this distance, add a random scatter
  3141. ** to the desired cell, so our units aren't all aligned along spokes.
  3142. */
  3143. if (tryval > 0) {
  3144. newcell = Clip_Scatter (newcell, 1);
  3145. }
  3146. /*
  3147. ** If, by randomly scattering, we've chosen the exact center, skip
  3148. ** it & try another direction.
  3149. */
  3150. if (newcell==cell) {
  3151. skipit = true;
  3152. }
  3153. if (!skipit) {
  3154. /*
  3155. ** Only attempt to Unlimbo the object if:
  3156. ** - there is no techno in the cell
  3157. ** - the techno in the cell & the object are both infantry
  3158. */
  3159. techno = Map[newcell].Cell_Techno();
  3160. if (!techno || (techno->What_Am_I()==RTTI_INFANTRY &&
  3161. obj->What_Am_I()==RTTI_INFANTRY)) {
  3162. if (obj->Unlimbo(Cell_Coord(newcell), DIR_N)) {
  3163. return(true);
  3164. }
  3165. }
  3166. }
  3167. rot++;
  3168. if (rot > FACING_NW) {
  3169. rot = FACING_N;
  3170. }
  3171. }
  3172. }
  3173. }
  3174. return(false);
  3175. }
  3176. /***********************************************************************************************
  3177. * Clip_Scatter -- randomly scatters from given cell; won't fall off map *
  3178. * *
  3179. * INPUT: *
  3180. * cell cell to scatter from *
  3181. * maxdist max distance to scatter *
  3182. * *
  3183. * OUTPUT: *
  3184. * new cell number *
  3185. * *
  3186. * WARNINGS: *
  3187. * none. *
  3188. * *
  3189. * HISTORY: *
  3190. * 07/30/1995 BRR : Created. *
  3191. *=============================================================================================*/
  3192. static CELL Clip_Scatter(CELL cell, int maxdist)
  3193. {
  3194. int x,y;
  3195. int xdist;
  3196. int ydist;
  3197. int xmin,xmax;
  3198. int ymin,ymax;
  3199. /*
  3200. ** Get X & Y coords of given starting cell
  3201. */
  3202. x = Cell_X(cell);
  3203. y = Cell_Y(cell);
  3204. /*
  3205. ** Compute our x & y limits
  3206. */
  3207. xmin = Map.MapCellX;
  3208. xmax = xmin + Map.MapCellWidth - 1;
  3209. ymin = Map.MapCellY;
  3210. ymax = ymin + Map.MapCellHeight - 1;
  3211. /*
  3212. ** Adjust the x-coordinate
  3213. */
  3214. xdist = Random_Pick(0, maxdist);
  3215. if (Percent_Chance(50)) {
  3216. x += xdist;
  3217. if (x > xmax) {
  3218. x = xmax;
  3219. }
  3220. } else {
  3221. x -= xdist;
  3222. if (x < xmin) {
  3223. x = xmin;
  3224. }
  3225. }
  3226. /*
  3227. ** Adjust the y-coordinate
  3228. */
  3229. ydist = Random_Pick(0, maxdist);
  3230. if (Percent_Chance(50)) {
  3231. y += ydist;
  3232. if (y > ymax) {
  3233. y = ymax;
  3234. }
  3235. } else {
  3236. y -= ydist;
  3237. if (y < ymin) {
  3238. y = ymin;
  3239. }
  3240. }
  3241. return (XY_Cell(x, y));
  3242. }
  3243. /***********************************************************************************************
  3244. * Clip_Move -- moves in given direction from given cell; clips to map *
  3245. * *
  3246. * INPUT: *
  3247. * cell cell to start from *
  3248. * facing direction to move *
  3249. * dist distance to move *
  3250. * *
  3251. * OUTPUT: *
  3252. * new cell number *
  3253. * *
  3254. * WARNINGS: *
  3255. * none. *
  3256. * *
  3257. * HISTORY: *
  3258. * 07/30/1995 BRR : Created. *
  3259. *=============================================================================================*/
  3260. static CELL Clip_Move(CELL cell, FacingType facing, int dist)
  3261. {
  3262. int x,y;
  3263. int xmin,xmax;
  3264. int ymin,ymax;
  3265. /*
  3266. ** Get X & Y coords of given starting cell
  3267. */
  3268. x = Cell_X(cell);
  3269. y = Cell_Y(cell);
  3270. /*
  3271. ** Compute our x & y limits
  3272. */
  3273. xmin = Map.MapCellX;
  3274. xmax = xmin + Map.MapCellWidth - 1;
  3275. ymin = Map.MapCellY;
  3276. ymax = ymin + Map.MapCellHeight - 1;
  3277. /*
  3278. ** Adjust the x-coordinate
  3279. */
  3280. switch (facing) {
  3281. case FACING_N:
  3282. y -= dist;
  3283. break;
  3284. case FACING_NE:
  3285. x += dist;
  3286. y -= dist;
  3287. break;
  3288. case FACING_E:
  3289. x += dist;
  3290. break;
  3291. case FACING_SE:
  3292. x += dist;
  3293. y += dist;
  3294. break;
  3295. case FACING_S:
  3296. y += dist;
  3297. break;
  3298. case FACING_SW:
  3299. x -= dist;
  3300. y += dist;
  3301. break;
  3302. case FACING_W:
  3303. x -= dist;
  3304. break;
  3305. case FACING_NW:
  3306. x -= dist;
  3307. y -= dist;
  3308. break;
  3309. }
  3310. /*
  3311. ** Clip to the map
  3312. */
  3313. if (x > xmax)
  3314. x = xmax;
  3315. if (x < xmin)
  3316. x = xmin;
  3317. if (y > ymax)
  3318. y = ymax;
  3319. if (y < ymin)
  3320. y = ymin;
  3321. return (XY_Cell(x, y));
  3322. }
  3323. void Disect_Scenario_Name(char const * name, int & scenario, ScenarioPlayerType & player, ScenarioDirType & dir, ScenarioVarType & var)
  3324. {
  3325. if (name == NULL) return;
  3326. /*
  3327. ** Fetch the scenario number.
  3328. */
  3329. char buf[3];
  3330. memcpy(buf, &name[3], 2);
  3331. buf[2] = '\0';
  3332. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  3333. char first = buf[0];
  3334. char second = buf[1];
  3335. if (first <= '9' && second <= '9') {
  3336. scenario = atoi(buf);
  3337. } else {
  3338. if (first <= '9') {
  3339. first -= '0';
  3340. } else {
  3341. if (first >= 'a' && first <= 'z') {
  3342. first -= 'a';
  3343. } else {
  3344. first -= 'A';
  3345. }
  3346. }
  3347. if (second <= '9') {
  3348. second -= '0';
  3349. } else {
  3350. if (second >= 'a' && second <= 'z') {
  3351. second = (second - 'a') + 10;
  3352. } else {
  3353. second = (second - 'A') + 10;
  3354. }
  3355. }
  3356. scenario = (36 * first) + second;
  3357. }
  3358. #else
  3359. scenario = atoi(buf);
  3360. #endif
  3361. /*
  3362. ** Fetch the scenario player (side).
  3363. */
  3364. player = SCEN_PLAYER_GREECE;
  3365. if (name[2] == HouseTypeClass::As_Reference(HOUSE_SPAIN).Prefix) {
  3366. player = SCEN_PLAYER_SPAIN;
  3367. }
  3368. if (name[2] == HouseTypeClass::As_Reference(HOUSE_GREECE).Prefix) {
  3369. player = SCEN_PLAYER_GREECE;
  3370. }
  3371. if (name[2] == HouseTypeClass::As_Reference(HOUSE_USSR).Prefix) {
  3372. player = SCEN_PLAYER_USSR;
  3373. }
  3374. /*
  3375. ** Fetch the direction.
  3376. */
  3377. dir = SCEN_DIR_EAST;
  3378. if (name[5] == 'E') {
  3379. dir = SCEN_DIR_EAST;
  3380. } else {
  3381. dir = SCEN_DIR_WEST;
  3382. }
  3383. /*
  3384. ** Fetch the variation.
  3385. */
  3386. var = SCEN_VAR_A;
  3387. var = ScenarioVarType((name[6] - 'A') + SCEN_VAR_A);
  3388. }