SCENARIO.CPP 116 KB

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