NULLDLG.CPP 253 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835
  1. //
  2. // Copyright 2020 Electronic Arts Inc.
  3. //
  4. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free
  5. // software: you can redistribute it and/or modify it under the terms of
  6. // the GNU General Public License as published by the Free Software Foundation,
  7. // either version 3 of the License, or (at your option) any later version.
  8. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed
  9. // in the hope that it will be useful, but with permitted additional restrictions
  10. // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
  11. // distributed with this program. You should have received a copy of the
  12. // GNU General Public License along with permitted additional restrictions
  13. // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
  14. /* $Header: /counterstrike/NULLDLG.CPP 14 3/17/97 1:05a Steve_tall $ */
  15. /***************************************************************************
  16. ** 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 **
  17. ***************************************************************************
  18. * *
  19. * Project Name : Command & Conquer *
  20. * *
  21. * File Name : NULLDLG.CPP *
  22. * *
  23. * Programmer : Bill R. Randolph *
  24. * *
  25. * Start Date : 04/29/95 *
  26. * *
  27. * Last Update : Jan. 21, 1997 [V.Grippi] *
  28. * *
  29. *-------------------------------------------------------------------------*
  30. * Functions: *
  31. * Build_InitString_Listbox -- [re]builds the initstring entry listbox *
  32. * Build_Phone_Listbox -- [re]builds the phone entry listbox *
  33. * Com_Scenario_Dialog -- Serial game scenario selection dialog *
  34. * Com_Settings_Dialog -- Lets user select serial port settings *
  35. * Destroy_Null_Connection -- destroys the given connection *
  36. * Edit_Phone_Dialog -- lets user edit a phone book entry *
  37. * Init_Null_Modem -- Initializes Null Modem communications *
  38. * Init_String_Compare -- for qsort *
  39. * Phone_Compare -- for qsort *
  40. * Phone_Dialog -- Lets user edit phone directory & dial *
  41. * Reconnect_Null_Modem -- allows user to reconnect *
  42. * Select_Serial_Dialog -- Serial Communications menu dialog *
  43. * Shutdown_Modem -- Shuts down modem/null-modem communications *
  44. * Test_Null_Modem -- Null-Modem test routine *
  45. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  46. #include "function.h"
  47. //PG
  48. GameType Select_Serial_Dialog(void) { return GAME_NORMAL; }
  49. #if (0)//PG
  50. #ifdef FIXIT_RANDOM_GAME
  51. #include "time.h"
  52. #endif
  53. #ifdef WIN32
  54. #include "wincomm.h"
  55. #include "modemreg.h"
  56. ModemRegistryEntryClass *ModemRegistry = NULL; //Ptr to modem registry data
  57. #endif //WIN32
  58. #include "COORDA.h"
  59. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  60. extern bool Is_Mission_126x126 (char *file_name);
  61. extern bool Is_Mission_Counterstrike (char *file_name);
  62. extern bool Is_Mission_Aftermath( char* file_name );
  63. #endif
  64. //#include "WolDebug.h"
  65. //
  66. // how much time (ticks) to go by before thinking other system
  67. // is not responding.
  68. //
  69. #define PACKET_SENDING_TIMEOUT 1800
  70. #define PACKET_CANCEL_TIMEOUT 900
  71. //extern char const *ForMisStr[];
  72. extern char const *EngMisStr[];
  73. //
  74. // how much time (ticks) to go by before sending another packet
  75. // of game options or serial connect.
  76. //
  77. #define PACKET_RETRANS_TIME 30
  78. #define PACKET_REDRAW_TIME 60
  79. static int Reconnect_Null_Modem( void );
  80. static int Com_Settings_Dialog( SerialSettingsType *settings );
  81. static int Phone_Dialog (void);
  82. static void Build_Init_String_Listbox (ListClass *list, EditClass *edit, char *buf, int *index);
  83. static int Init_String_Compare (const void *p1, const void *p2);
  84. static void Build_Phone_Listbox (ListClass *list, EditClass *edit, char *buf);
  85. static int Phone_Compare (const void *p1, const void *p2);
  86. static int Edit_Phone_Dialog (PhoneEntryClass *phone);
  87. static bool Dial_Modem( SerialSettingsType *settings, bool reconnect );
  88. static bool Answer_Modem( SerialSettingsType *settings, bool reconnect );
  89. static void Modem_Echo( char c );
  90. void Smart_Printf( char *format, ... );
  91. void Hex_Dump_Data( char *buffer, int length );
  92. void itoh( int i, char *s);
  93. static SerialPacketType SendPacket;
  94. static SerialPacketType ReceivePacket;
  95. char TheirName[MPLAYER_NAME_MAX];
  96. PlayerColorType TheirColor;
  97. HousesType TheirHouse;
  98. static char DialString[ CWAITSTRBUF_MAX + PhoneEntryClass::PHONE_MAX_NUM - 1 ];
  99. static SerialSettingsType *DialSettings;
  100. #ifdef FIXIT_VERSION_3
  101. bool Force_Scenario_Available( const char* szName );
  102. bool bSpecialAftermathScenario( const char* szScenarioDescription );
  103. #endif
  104. #define PCOLOR_BROWN PCOLOR_GREY
  105. #define SHOW_MONO 0
  106. /***************************************************************************
  107. * Init_Null_Modem -- Initializes Null Modem communications *
  108. * *
  109. * INPUT: *
  110. * none. *
  111. * *
  112. * OUTPUT: *
  113. * true = OK, false = error *
  114. * *
  115. * WARNINGS: *
  116. * none. *
  117. * *
  118. * HISTORY: *
  119. * 04/29/1995 BRR : Created. *
  120. * 8/2/96 ST : Win32 support added *
  121. *=========================================================================*/
  122. int Init_Null_Modem( SerialSettingsType *settings )
  123. {
  124. #ifdef WIN32
  125. if ( NullModem.Init( settings->Port, settings->IRQ,
  126. settings->ModemName,
  127. settings->Baud, 0, 8, 1,
  128. settings->HardwareFlowControl ) ) {
  129. return (true);
  130. } else {
  131. return (false);
  132. }
  133. #else //WIN32
  134. if ( NullModem.Init( settings->Port, settings->IRQ,
  135. settings->ModemName,
  136. settings->Baud, 'N', 8, 1,
  137. settings->HardwareFlowControl) ) {
  138. NullModem.Change_IRQ_Priority( settings->IRQ );
  139. return(true);
  140. } else {
  141. return(false);
  142. }
  143. #endif //WIN32
  144. }
  145. /***************************************************************************
  146. * Shutdown_Modem -- Shuts down modem/null-modem communications *
  147. * *
  148. * INPUT: *
  149. * none. *
  150. * *
  151. * OUTPUT: *
  152. * none. *
  153. * *
  154. * WARNINGS: *
  155. * none. *
  156. * *
  157. * HISTORY: *
  158. * 04/29/1995 BRR : Created. *
  159. *=========================================================================*/
  160. void Shutdown_Modem( void )
  161. {
  162. if (!Session.Play) {
  163. if (Session.Type == GAME_MODEM) {
  164. NullModem.Hangup_Modem();
  165. }
  166. }
  167. NullModem.Change_IRQ_Priority( 0 ); // reset priority of interrupts
  168. //
  169. // close port
  170. //
  171. NullModem.Shutdown();
  172. }
  173. /***************************************************************************
  174. * Modem_Signoff -- sends EXIT event *
  175. * *
  176. * INPUT: *
  177. * none. *
  178. * *
  179. * OUTPUT: *
  180. * none. *
  181. * *
  182. * WARNINGS: *
  183. * none. *
  184. * *
  185. * HISTORY: *
  186. * 08/03/1995 DRD : Created. *
  187. *=========================================================================*/
  188. void Modem_Signoff( void )
  189. {
  190. unsigned long starttime;
  191. EventClass event;
  192. if (!Session.Play) {
  193. /*
  194. ** Send a sign-off packet
  195. */
  196. memset (&event, 0, sizeof(EventClass));
  197. event.Type = EventClass::EXIT;
  198. NullModem.Send_Message (&event,sizeof(EventClass),0);
  199. NullModem.Send_Message (&event,sizeof(EventClass),0);
  200. starttime = TickCount;
  201. while ( (TickCount - starttime) < 30) {
  202. NullModem.Service();
  203. }
  204. }
  205. }
  206. /***************************************************************************
  207. * Test_Null_Modem -- Null-Modem test routine *
  208. * *
  209. * INPUT: *
  210. * none. *
  211. * *
  212. * OUTPUT: *
  213. * 0 = failure to connect; 1 = I'm the game owner, 2 = I'm not *
  214. * *
  215. * WARNINGS: *
  216. * none. *
  217. * *
  218. * HISTORY: *
  219. * 04/29/1995 BRR : Created. *
  220. * 8/2/96 ST : Win32 support added *
  221. *=========================================================================*/
  222. int Test_Null_Modem( void )
  223. {
  224. /*
  225. ** Get the resolution factor
  226. */
  227. // int factor = (SeenBuff.Get_Width() == 320) ? 1 : 2;
  228. /*
  229. ** Button Enumerations
  230. */
  231. enum {
  232. BUTTON_CANCEL = 100,
  233. };
  234. /*
  235. ** Dialog variables
  236. */
  237. bool process = true; // process while true
  238. int retval;
  239. unsigned long starttime;
  240. int packetlen;
  241. int x,y,width,height; // dialog dimensions
  242. char buffer[80*3];
  243. RemapControlType * scheme = GadgetClass::Get_Color_Scheme();
  244. /*
  245. ** Buttons
  246. */
  247. GadgetClass *commands; // button list
  248. /*
  249. ** Determine the dimensions of the text to be used for the dialog box.
  250. ** These dimensions will control how the dialog box looks.
  251. */
  252. strcpy( buffer, Text_String( TXT_WAITING_CONNECT ) );
  253. Fancy_Text_Print(TXT_NONE,0,0,TBLACK,TBLACK,TPF_6PT_GRAD | TPF_NOSHADOW);
  254. Format_Window_String(buffer, SeenBuff.Get_Height(), width, height);
  255. width = max(width, 50 * RESFACTOR);
  256. width += 40 * RESFACTOR;
  257. height += 60 * RESFACTOR;
  258. x = (SeenBuff.Get_Width() - width) / 2;
  259. y = (SeenBuff.Get_Height() - height) / 2;
  260. TextButtonClass cancelbtn(BUTTON_CANCEL, TXT_CANCEL, TPF_BUTTON,
  261. x + ((width - (String_Pixel_Width( Text_String( TXT_CANCEL ) ) + 8 * RESFACTOR)) >> 1),
  262. y + height - (FontHeight + FontYSpacing + 2 * RESFACTOR) - 10 * RESFACTOR);
  263. /*
  264. ** Initialize
  265. */
  266. Set_Logic_Page(SeenBuff);
  267. process = true;
  268. /*
  269. ** Create the list
  270. */
  271. commands = &cancelbtn;
  272. commands->Flag_List_To_Redraw();
  273. /*
  274. ** Draw the dialog
  275. */
  276. Hide_Mouse();
  277. Load_Title_Page(true);
  278. Dialog_Box(x, y, width, height);
  279. Draw_Caption(TXT_NONE, x, y, width);
  280. Fancy_Text_Print(buffer, x + 20 * RESFACTOR, y + 25 * RESFACTOR, scheme, TBLACK, TPF_TEXT);
  281. commands->Draw_All();
  282. while (Get_Mouse_State() > 0) Show_Mouse();
  283. #ifdef WIN32
  284. /*
  285. ** This is supposed to be a direct connection so hang up any modem on this port
  286. ** just to annoy British Telecom
  287. */
  288. /*
  289. ** Go into break mode
  290. */
  291. SetCommBreak(SerialPort->Get_Port_Handle());
  292. /*
  293. ** Send hangup command
  294. */
  295. SerialPort->Write_To_Serial_Port ((unsigned char*)"ATH\r", strlen("ATH\r"));
  296. CountDownTimerClass time;
  297. time.Set(2*60);
  298. while (time.Time()) {}
  299. /*
  300. ** Back out of break mode
  301. */
  302. ClearCommBreak(SerialPort->Get_Port_Handle());
  303. /*
  304. ** Drop DTR as well - just in case the modem still hasnt got the message
  305. */
  306. EscapeCommFunction(SerialPort->Get_Port_Handle(), CLRDTR);
  307. #endif //WIN32
  308. /*
  309. ** Check for a packet. If we detect one, the other system has already been
  310. ** started. Wait 1/2 sec for him to receive my ACK, then exit with success.
  311. ** Note: The initial time must be a little longer than the resend delay.
  312. ** Just in case we just missed the packet.
  313. */
  314. starttime = TickCount;
  315. while ( TickCount - starttime < 80) {
  316. NullModem.Service();
  317. if ( NullModem.Get_Message( &ReceivePacket, &packetlen ) > 0) {
  318. if (ReceivePacket.Command == SERIAL_CONNECT) {
  319. starttime = TickCount;
  320. while (TickCount - starttime < 30)
  321. NullModem.Service();
  322. process = false;
  323. retval = 2;
  324. break;
  325. }
  326. }
  327. }
  328. /*
  329. ** Send a packet across. As long as Num_Send() is non-zero, the other system
  330. ** hasn't received it yet.
  331. */
  332. if (process) {
  333. memset (&SendPacket, 0, sizeof(SerialPacketType));
  334. SendPacket.Command = SERIAL_CONNECT;
  335. //
  336. // put time from start of game for determining the host in case of tie.
  337. //
  338. SendPacket.ScenarioInfo.Seed = TickCount;
  339. SendPacket.ID = (int) buffer; // address of buffer for more uniqueness.
  340. NullModem.Send_Message (&SendPacket, sizeof(SendPacket), 1);
  341. starttime = TickCount;
  342. while (TickCount - starttime < 80) {
  343. NullModem.Service();
  344. if (NullModem.Get_Message (&ReceivePacket, &packetlen) > 0) {
  345. if (ReceivePacket.Command == SERIAL_CONNECT) {
  346. starttime = TickCount;
  347. while (TickCount - starttime < 30)
  348. NullModem.Service();
  349. //
  350. // whoever has the highest time is the host
  351. //
  352. if (ReceivePacket.ScenarioInfo.Seed > SendPacket.ScenarioInfo.Seed) {
  353. process = false;
  354. retval = 2;
  355. } else if (ReceivePacket.ScenarioInfo.Seed == SendPacket.ScenarioInfo.Seed) {
  356. if (ReceivePacket.ID > SendPacket.ID) {
  357. process = false;
  358. retval = 2;
  359. //
  360. // if they are equal then it's a loopback cable or a modem
  361. //
  362. } else if (ReceivePacket.ID == SendPacket.ID) {
  363. process = false;
  364. retval = 3;
  365. }
  366. }
  367. break;
  368. }
  369. }
  370. }
  371. }
  372. starttime = TickCount;
  373. /*
  374. ** Main Processing Loop
  375. */
  376. while (process) {
  377. #ifdef WIN32
  378. /*
  379. ** If we have just received input focus again after running in the background then
  380. ** we need to redraw.
  381. */
  382. if (AllSurfaces.SurfacesRestored) {
  383. AllSurfaces.SurfacesRestored=FALSE;
  384. commands->Draw_All();
  385. }
  386. #endif //WIN32
  387. /*
  388. ** Invoke game callback
  389. */
  390. Call_Back();
  391. /*
  392. ** Get user input
  393. */
  394. KeyNumType input = commands->Input();
  395. /*
  396. ** Process input
  397. */
  398. switch (input) {
  399. case (KN_ESC):
  400. case (BUTTON_CANCEL | KN_BUTTON):
  401. retval = 0;
  402. process = false;
  403. break;
  404. default:
  405. break;
  406. }
  407. /*
  408. ** Service the connection.
  409. */
  410. NullModem.Service();
  411. if (NullModem.Num_Send() == 0) {
  412. if (NullModem.Get_Message (&ReceivePacket, &packetlen) > 0) {
  413. if (ReceivePacket.Command == SERIAL_CONNECT) {
  414. starttime = TickCount;
  415. while (TickCount - starttime < 30)
  416. NullModem.Service();
  417. //
  418. // whoever has the highest time is the host
  419. //
  420. if (ReceivePacket.ScenarioInfo.Seed > SendPacket.ScenarioInfo.Seed) {
  421. process = false;
  422. retval = 2;
  423. } else if (ReceivePacket.ScenarioInfo.Seed == SendPacket.ScenarioInfo.Seed) {
  424. if (ReceivePacket.ID > SendPacket.ID) {
  425. process = false;
  426. retval = 2;
  427. //
  428. // if they are equal then it's a loopback cable or a modem
  429. //
  430. } else if (ReceivePacket.ID == SendPacket.ID) {
  431. process = false;
  432. retval = 3;
  433. }
  434. }
  435. } else {
  436. retval = 0;
  437. process = false;
  438. }
  439. } else {
  440. retval = 1;
  441. process = false;
  442. }
  443. }
  444. if (TickCount - starttime > 3600) { // only wait 1 minute
  445. retval = 0;
  446. process = false;
  447. }
  448. } /* end of while */
  449. return( retval );
  450. }
  451. /***************************************************************************
  452. * Reconnect_Modem -- allows user to reconnect *
  453. * *
  454. * INPUT: *
  455. * none. *
  456. * *
  457. * OUTPUT: *
  458. * 0 = failure to connect; 1 = connect OK *
  459. * *
  460. * WARNINGS: *
  461. * none. *
  462. * *
  463. * HISTORY: *
  464. * 04/29/1995 BRR : Created. *
  465. *=========================================================================*/
  466. int Reconnect_Modem( void )
  467. {
  468. int status;
  469. int modemstatus;
  470. switch (Session.ModemType) {
  471. case (MODEM_NULL_HOST):
  472. case (MODEM_NULL_JOIN):
  473. status = Reconnect_Null_Modem();
  474. break;
  475. case (MODEM_DIALER):
  476. modemstatus = NullModem.Get_Modem_Status();
  477. if ( (modemstatus & CD_SET) ) {
  478. status = Reconnect_Null_Modem();
  479. } else {
  480. status = Dial_Modem( DialSettings, true );
  481. }
  482. break;
  483. case (MODEM_ANSWERER):
  484. modemstatus = NullModem.Get_Modem_Status();
  485. if ( (modemstatus & CD_SET) ) {
  486. status = Reconnect_Null_Modem();
  487. } else {
  488. status = Answer_Modem( DialSettings, true );
  489. }
  490. break;
  491. }
  492. return( status );
  493. }
  494. /***************************************************************************
  495. * Reconnect_Null_Modem -- allows user to reconnect *
  496. * *
  497. * INPUT: *
  498. * none. *
  499. * *
  500. * OUTPUT: *
  501. * 0 = failure to connect; 1 = connect OK *
  502. * *
  503. * WARNINGS: *
  504. * none. *
  505. * *
  506. * HISTORY: *
  507. * 04/29/1995 BRR : Created. *
  508. *=========================================================================*/
  509. static int Reconnect_Null_Modem( void )
  510. {
  511. /*
  512. ** Button Enumerations
  513. */
  514. enum {
  515. BUTTON_CANCEL = 100,
  516. };
  517. /*
  518. ** Dialog variables
  519. */
  520. bool process = true; // process while true
  521. KeyNumType input;
  522. int retval;
  523. unsigned long starttime;
  524. unsigned long lastmsgtime;
  525. int packetlen;
  526. RemapControlType * scheme = GadgetClass::Get_Color_Scheme();
  527. int x,y,width,height; // dialog dimensions
  528. char buffer[80*3];
  529. /*
  530. ** Buttons
  531. */
  532. GadgetClass *commands; // button list
  533. /*
  534. ** Determine the dimensions of the text to be used for the dialog box.
  535. ** These dimensions will control how the dialog box looks.
  536. */
  537. strcpy( buffer, Text_String( TXT_NULL_CONNERR_CHECK_CABLES ) );
  538. Fancy_Text_Print(TXT_NONE,0,0,TBLACK,TBLACK,TPF_6PT_GRAD | TPF_NOSHADOW);
  539. Format_Window_String(buffer, SeenBuff.Get_Height(), width, height);
  540. width = max(width, 50 * RESFACTOR);
  541. width += 40 * RESFACTOR;
  542. height += 60 * RESFACTOR;
  543. x = (SeenBuff.Get_Width() - width) / 2;
  544. y = (SeenBuff.Get_Height() - height) / 2;
  545. TextButtonClass cancelbtn(BUTTON_CANCEL, TXT_CANCEL, TPF_BUTTON,
  546. x + ((width - (String_Pixel_Width( Text_String( TXT_CANCEL ) ) + 8 * RESFACTOR)) >> 1),
  547. y + height - (FontHeight + FontYSpacing + 2*RESFACTOR) - 10 * RESFACTOR);
  548. /*
  549. ** Initialize
  550. */
  551. Set_Logic_Page(SeenBuff);
  552. process = true;
  553. /*
  554. ** Create the list
  555. */
  556. commands = &cancelbtn;
  557. commands->Flag_List_To_Redraw();
  558. /*
  559. ** Draw the dialog
  560. */
  561. Hide_Mouse();
  562. Dialog_Box(x, y, width, height);
  563. Draw_Caption(TXT_NONE, x, y, width);
  564. Fancy_Text_Print(buffer, x + 20*RESFACTOR, y + 25*RESFACTOR, scheme, TBLACK, TPF_TEXT);
  565. commands->Draw_All();
  566. Show_Mouse();
  567. /*
  568. ** Main Processing Loop
  569. */
  570. starttime = lastmsgtime = TickCount;
  571. while (process) {
  572. #ifdef WIN32
  573. /*
  574. ** If we have just received input focus again after running in the background then
  575. ** we need to redraw.
  576. */
  577. if (AllSurfaces.SurfacesRestored) {
  578. AllSurfaces.SurfacesRestored=FALSE;
  579. commands->Draw_All();
  580. }
  581. #endif //WIN32
  582. /*
  583. ** Invoke game callback
  584. */
  585. Call_Back();
  586. /*
  587. ** Get user input
  588. */
  589. input = commands->Input();
  590. /*
  591. ** Process input
  592. */
  593. switch (input) {
  594. case (KN_ESC):
  595. case (BUTTON_CANCEL | KN_BUTTON):
  596. retval = false;
  597. process = false;
  598. break;
  599. default:
  600. break;
  601. }
  602. /*
  603. ** Service the connection.
  604. */
  605. NullModem.Service();
  606. /*
  607. ** Resend our message if it's time
  608. */
  609. if (TickCount - starttime > PACKET_RETRANS_TIME) {
  610. starttime = TickCount;
  611. memset (&SendPacket, 0, sizeof(SerialPacketType));
  612. SendPacket.Command = SERIAL_CONNECT;
  613. SendPacket.ID = Session.ColorIdx;
  614. NullModem.Send_Message (&SendPacket, sizeof(SendPacket), 0);
  615. }
  616. /*
  617. ** Check for an incoming message
  618. */
  619. if (NullModem.Get_Message (&ReceivePacket, &packetlen) > 0) {
  620. lastmsgtime = TickCount;
  621. if (ReceivePacket.Command == SERIAL_CONNECT) {
  622. // are we getting our own packets back??
  623. if (ReceivePacket.ID == Session.ColorIdx) {
  624. WWMessageBox().Process (TXT_SYSTEM_NOT_RESPONDING);
  625. retval = false;
  626. process = false;
  627. break;
  628. }
  629. /*
  630. ** OK, we got our message; now we have to make certain the other
  631. ** guy gets his, so send him one with an ACK required.
  632. */
  633. memset (&SendPacket, 0, sizeof(SerialPacketType));
  634. SendPacket.Command = SERIAL_CONNECT;
  635. SendPacket.ID = Session.ColorIdx;
  636. NullModem.Send_Message (&SendPacket, sizeof(SendPacket), 1);
  637. starttime = TickCount;
  638. while (TickCount - starttime < 60)
  639. NullModem.Service();
  640. retval = true;
  641. process = false;
  642. }
  643. }
  644. //
  645. // timeout if we do not get any packets
  646. //
  647. if (TickCount - lastmsgtime > PACKET_CANCEL_TIMEOUT) {
  648. retval = false;
  649. process = false;
  650. }
  651. } /* end of while */
  652. return( retval );
  653. }
  654. /***********************************************************************************************
  655. * Destroy_Null_Connection -- destroys the given connection *
  656. * *
  657. * Call this routine when a connection goes bad, or another player signs off. *
  658. * *
  659. * INPUT: *
  660. * id connection ID to destroy; this should be the HousesType of the player being *
  661. * "destroyed". *
  662. * error 0 = user signed off; 1 = connection error *
  663. * *
  664. * OUTPUT: *
  665. * none. *
  666. * *
  667. * WARNINGS: *
  668. * none. *
  669. * *
  670. * HISTORY: *
  671. * 07/31/1995 DRD : Created. *
  672. *=============================================================================================*/
  673. void Destroy_Null_Connection(int id, int error)
  674. {
  675. int i;
  676. HouseClass *housep;
  677. char txt[80];
  678. if ( Session.NumPlayers == 1 ) {
  679. return;
  680. }
  681. /*
  682. ** Do nothing if the house isn't human.
  683. */
  684. housep = HouseClass::As_Pointer((HousesType)id);
  685. if (!housep || !housep->IsHuman)
  686. return;
  687. /*
  688. ** Create a message to display to the user
  689. */
  690. txt[0] = '\0';
  691. switch (error) {
  692. case 1:
  693. sprintf(txt,Text_String(TXT_CONNECTION_LOST), housep->IniName);
  694. break;
  695. case 0:
  696. sprintf(txt,Text_String(TXT_LEFT_GAME), housep->IniName);
  697. break;
  698. case -1:
  699. NullModem.Delete_Connection();
  700. break;
  701. }
  702. if (strlen(txt)) {
  703. Session.Messages.Add_Message (NULL, 0, txt,
  704. (housep->RemapColor == PCOLOR_DIALOG_BLUE) ? PCOLOR_REALLY_BLUE : housep->RemapColor,
  705. TPF_TEXT, Rule.MessageDelay * TICKS_PER_MINUTE);
  706. Map.Flag_To_Redraw(false);
  707. }
  708. /*
  709. ** Remove this player from the Players vector
  710. */
  711. for (i = 0; i < Session.Players.Count(); i++) {
  712. if (!stricmp(Session.Players[i]->Name,housep->IniName)) {
  713. delete Session.Players[i];
  714. Session.Players.Delete(Session.Players[i]);
  715. break;
  716. }
  717. }
  718. /*
  719. ** Turn the player's house over to the computer's AI
  720. */
  721. housep->IsHuman = false;
  722. // housep->Smartness = IQ_MENSA;
  723. housep->IQ = Rule.MaxIQ;
  724. strcpy (housep->IniName,Text_String(TXT_COMPUTER));
  725. Session.NumPlayers--;
  726. /*
  727. ** If we're the last player left, tell the user.
  728. */
  729. if (Session.NumPlayers == 1) {
  730. sprintf(txt,"%s",Text_String(TXT_JUST_YOU_AND_ME));
  731. Session.Messages.Add_Message (NULL, 0, txt,
  732. (housep->RemapColor == PCOLOR_DIALOG_BLUE) ? PCOLOR_REALLY_BLUE : housep->RemapColor,
  733. TPF_TEXT, Rule.MessageDelay * TICKS_PER_MINUTE);
  734. Map.Flag_To_Redraw(false);
  735. }
  736. }
  737. /***************************************************************************
  738. * Select_Serial_Dialog -- Serial Communications menu dialog *
  739. * *
  740. * INPUT: *
  741. * none. *
  742. * *
  743. * OUTPUT: *
  744. * GAME_MODEM user wants to play a modem game *
  745. * GAME_NULL_MODEM user wants to play a null-modem game *
  746. * GAME_NORMAL user hit Cancel *
  747. * *
  748. * WARNINGS: *
  749. * none. *
  750. * *
  751. * HISTORY: *
  752. * 04/29/1995 BRR : Created. *
  753. *=========================================================================*/
  754. GameType Select_Serial_Dialog( void )
  755. {
  756. int rc;
  757. // int value, i;
  758. int com = -1, baud = -1;
  759. int error = 0;
  760. /*
  761. ** Dialog & button dimensions
  762. */
  763. int d_dialog_w = 160 * RESFACTOR; // dialog width
  764. int d_dialog_h = 94 * RESFACTOR; // dialog height
  765. int d_dialog_x = ((320 * RESFACTOR - d_dialog_w) / 2); // dialog x-coord
  766. int d_dialog_y = 80*RESFACTOR;
  767. // int d_dialog_y = ((136 * RESFACTOR - d_dialog_h) / 2); // dialog y-coord
  768. int d_dialog_cx = d_dialog_x + (d_dialog_w / 2); // center x-coord
  769. int d_txt6_h = 7 * RESFACTOR; // ht of 6-pt text
  770. int d_margin = 7 * RESFACTOR; // margin width/height
  771. int d_dial_w = 90 * RESFACTOR;
  772. int d_dial_h = 9 * RESFACTOR;
  773. int d_dial_x = d_dialog_cx - d_dial_w / 2;
  774. int d_dial_y = d_dialog_y + d_margin + d_txt6_h + d_margin;
  775. int d_answer_w = 90 * RESFACTOR;
  776. int d_answer_h = 9 * RESFACTOR;
  777. int d_answer_x = d_dialog_cx - d_answer_w / 2;
  778. int d_answer_y = d_dial_y + d_dial_h + 2;
  779. int d_nullmodem_w = 90 * RESFACTOR;
  780. int d_nullmodem_h = 9 * RESFACTOR;
  781. int d_nullmodem_x = d_dialog_cx - d_nullmodem_w / 2;
  782. int d_nullmodem_y = d_answer_y + d_answer_h + 2;
  783. int d_settings_w = 90 * RESFACTOR;
  784. int d_settings_h = 9 * RESFACTOR;
  785. int d_settings_x = d_dialog_cx - d_settings_w / 2;
  786. int d_settings_y = d_nullmodem_y + d_nullmodem_h + 2;
  787. int d_cancel_w = 50 * RESFACTOR;
  788. int d_cancel_h = 9 * RESFACTOR;
  789. int d_cancel_x = d_dialog_cx - d_cancel_w / 2;
  790. int d_cancel_y = d_settings_y + d_settings_h + d_margin;
  791. /*
  792. ** Button Enumerations
  793. */
  794. enum {
  795. BUTTON_DIAL = 100,
  796. BUTTON_ANSWER,
  797. BUTTON_NULLMODEM,
  798. BUTTON_SETTINGS,
  799. BUTTON_CANCEL,
  800. NUM_OF_BUTTONS = 5,
  801. };
  802. /*
  803. ** Redraw values: in order from "top" to "bottom" layer of the dialog
  804. */
  805. typedef enum {
  806. REDRAW_NONE = 0,
  807. REDRAW_BUTTONS,
  808. REDRAW_BACKGROUND,
  809. REDRAW_ALL = REDRAW_BACKGROUND
  810. } RedrawType;
  811. /*
  812. ** Dialog variables
  813. */
  814. RedrawType display = REDRAW_ALL; // redraw level
  815. bool process = true; // process while true
  816. KeyNumType input;
  817. char namebuf[MPLAYER_NAME_MAX] = {0}; // buffer for player's name
  818. int tabs[] = {77*RESFACTOR}; // tabs for player list box
  819. GameType retval; // return value
  820. int selection;
  821. bool pressed;
  822. int curbutton;
  823. TextButtonClass *buttons[NUM_OF_BUTTONS];
  824. SerialSettingsType *settings;
  825. bool selectsettings = false;
  826. RemapControlType * scheme = GadgetClass::Get_Color_Scheme();
  827. /*
  828. ** Buttons
  829. */
  830. GadgetClass *commands; // button list
  831. TextButtonClass dialbtn(BUTTON_DIAL, TXT_DIAL_MODEM, TPF_BUTTON, d_dial_x, d_dial_y, d_dial_w, d_dial_h);
  832. TextButtonClass answerbtn(BUTTON_ANSWER, TXT_ANSWER_MODEM, TPF_BUTTON, d_answer_x, d_answer_y, d_answer_w, d_answer_h);
  833. TextButtonClass nullmodembtn(BUTTON_NULLMODEM, TXT_NULL_MODEM, TPF_BUTTON, d_nullmodem_x, d_nullmodem_y, d_nullmodem_w, d_nullmodem_h);
  834. TextButtonClass settingsbtn(BUTTON_SETTINGS, TXT_SETTINGS, TPF_BUTTON, d_settings_x, d_settings_y, d_settings_w, d_settings_h);
  835. TextButtonClass cancelbtn(BUTTON_CANCEL, TXT_CANCEL, TPF_BUTTON, d_cancel_x, d_cancel_y, d_cancel_w, d_cancel_h);
  836. /*
  837. ** Initialize
  838. */
  839. Set_Logic_Page(SeenBuff);
  840. if (Session.SerialDefaults.Port == 0 ||
  841. Session.SerialDefaults.IRQ == -1 ||
  842. Session.SerialDefaults.Baud == -1) {
  843. selectsettings = true;
  844. } else if ( NullModem.Detect_Port( &Session.SerialDefaults ) != PORT_VALID ) {
  845. selectsettings = true;
  846. }
  847. /*
  848. ** Create the list
  849. */
  850. commands = &dialbtn;
  851. answerbtn.Add_Tail(*commands);
  852. nullmodembtn.Add_Tail(*commands);
  853. settingsbtn.Add_Tail(*commands);
  854. cancelbtn.Add_Tail(*commands);
  855. /*
  856. ** Fill array of button ptrs
  857. */
  858. curbutton = 0;
  859. buttons[0] = &dialbtn;
  860. buttons[1] = &answerbtn;
  861. buttons[2] = &nullmodembtn;
  862. buttons[3] = &settingsbtn;
  863. buttons[4] = &cancelbtn;
  864. buttons[curbutton]->Turn_On();
  865. Keyboard->Clear();
  866. Fancy_Text_Print(TXT_NONE, 0, 0, scheme, TBLACK, TPF_CENTER | TPF_TEXT);
  867. /*
  868. ** Main Processing Loop
  869. */
  870. display = REDRAW_ALL;
  871. process = true;
  872. pressed = false;
  873. while (process) {
  874. /*
  875. ** Invoke game callback
  876. */
  877. Call_Back();
  878. /*
  879. ** Refresh display if needed
  880. */
  881. #ifdef WIN32
  882. /*
  883. ** If we have just received input focus again after running in the background then
  884. ** we need to redraw.
  885. */
  886. if (AllSurfaces.SurfacesRestored) {
  887. AllSurfaces.SurfacesRestored=FALSE;
  888. display = REDRAW_ALL;
  889. }
  890. #endif
  891. if (display) {
  892. Hide_Mouse();
  893. if (display >= REDRAW_BACKGROUND) {
  894. /*
  895. ** Refresh the backdrop
  896. */
  897. Load_Title_Page(true);
  898. /*
  899. ** Draw the background
  900. */
  901. Dialog_Box(d_dialog_x, d_dialog_y, d_dialog_w, d_dialog_h);
  902. /*
  903. ** Draw the labels
  904. */
  905. Draw_Caption (TXT_SELECT_SERIAL_GAME, d_dialog_x, d_dialog_y, d_dialog_w);
  906. }
  907. commands->Draw_All();
  908. Show_Mouse();
  909. display = REDRAW_NONE;
  910. }
  911. /*
  912. ** Get user input
  913. */
  914. input = commands->Input();
  915. /*
  916. ** Process input
  917. */
  918. switch (input) {
  919. case (BUTTON_DIAL | KN_BUTTON):
  920. selection = BUTTON_DIAL;
  921. pressed = true;
  922. break;
  923. case (BUTTON_ANSWER | KN_BUTTON):
  924. selection = BUTTON_ANSWER;
  925. pressed = true;
  926. break;
  927. case (BUTTON_NULLMODEM | KN_BUTTON):
  928. selection = BUTTON_NULLMODEM;
  929. pressed = true;
  930. break;
  931. case (BUTTON_SETTINGS | KN_BUTTON):
  932. selection = BUTTON_SETTINGS;
  933. pressed = true;
  934. break;
  935. case (KN_ESC):
  936. case (BUTTON_CANCEL | KN_BUTTON):
  937. selection = BUTTON_CANCEL;
  938. pressed = true;
  939. break;
  940. case (KN_UP):
  941. buttons[curbutton]->Turn_Off();
  942. buttons[curbutton]->Flag_To_Redraw();
  943. curbutton--;
  944. if (curbutton < 0)
  945. curbutton = (NUM_OF_BUTTONS - 1);
  946. buttons[curbutton]->Turn_On();
  947. buttons[curbutton]->Flag_To_Redraw();
  948. break;
  949. case (KN_DOWN):
  950. buttons[curbutton]->Turn_Off();
  951. buttons[curbutton]->Flag_To_Redraw();
  952. curbutton++;
  953. if (curbutton > (NUM_OF_BUTTONS - 1) )
  954. curbutton = 0;
  955. buttons[curbutton]->Turn_On();
  956. buttons[curbutton]->Flag_To_Redraw();
  957. break;
  958. case (KN_RETURN):
  959. selection = curbutton + BUTTON_DIAL;
  960. pressed = true;
  961. break;
  962. default:
  963. break;
  964. }
  965. if (pressed) {
  966. //
  967. // to make sure the selection is correct in case they used the mouse
  968. //
  969. buttons[curbutton]->Turn_Off();
  970. buttons[curbutton]->Flag_To_Redraw();
  971. curbutton = selection - BUTTON_DIAL;
  972. buttons[curbutton]->Turn_On();
  973. buttons[curbutton]->IsPressed = true;
  974. buttons[curbutton]->Draw_Me(true);
  975. switch (selection) {
  976. case (BUTTON_DIAL):
  977. if (selectsettings) {
  978. WWMessageBox().Process(TXT_SELECT_SETTINGS);
  979. /*
  980. ** Remote-connect
  981. */
  982. } else if ( Phone_Dialog() ) {
  983. if (Session.PhoneBook[Session.CurPhoneIdx]->Settings.Port == 0) {
  984. settings = &Session.SerialDefaults;
  985. } else {
  986. settings = &(Session.PhoneBook[Session.CurPhoneIdx]->Settings);
  987. }
  988. #ifdef WIN32
  989. if (SerialPort) {
  990. delete SerialPort;
  991. }
  992. SerialPort = new WinModemClass;
  993. #endif //WIN32
  994. if ( Init_Null_Modem( settings ) ) {
  995. if (settings->CallWaitStringIndex == CALL_WAIT_CUSTOM) {
  996. strcpy( DialString, settings->CallWaitString );
  997. } else {
  998. strcpy( DialString,
  999. Session.CallWaitStrings[ settings->CallWaitStringIndex ] );
  1000. }
  1001. strcat( DialString, Session.PhoneBook[ Session.CurPhoneIdx ]->Number );
  1002. if ( Dial_Modem( settings, false ) ) {
  1003. Session.ModemType = MODEM_DIALER;
  1004. if ( Com_Scenario_Dialog() ) {
  1005. retval = GAME_MODEM;
  1006. process = false;
  1007. }
  1008. }
  1009. if (process) { // restore to default
  1010. NullModem.Change_IRQ_Priority( 0 );
  1011. }
  1012. } else {
  1013. WWMessageBox().Process(TXT_SELECT_SETTINGS);
  1014. }
  1015. }
  1016. if (process) {
  1017. buttons[curbutton]->IsPressed = false;
  1018. buttons[curbutton]->Flag_To_Redraw();
  1019. }
  1020. display = REDRAW_ALL;
  1021. break;
  1022. case (BUTTON_ANSWER):
  1023. if (selectsettings) {
  1024. WWMessageBox().Process(TXT_SELECT_SETTINGS);
  1025. } else {
  1026. /*
  1027. ** Remote-connect
  1028. */
  1029. settings = &Session.SerialDefaults;
  1030. #ifdef WIN32
  1031. if (SerialPort) {
  1032. delete SerialPort;
  1033. }
  1034. SerialPort = new WinModemClass;
  1035. #endif //WIN32
  1036. if ( Init_Null_Modem( settings ) ) {
  1037. if ( Answer_Modem( settings, false ) ) {
  1038. Session.ModemType = MODEM_ANSWERER;
  1039. if ( Com_Show_Scenario_Dialog() ) {
  1040. retval = GAME_MODEM;
  1041. process = false;
  1042. }
  1043. }
  1044. if (process) { // restore to default
  1045. NullModem.Change_IRQ_Priority( 0 );
  1046. }
  1047. } else {
  1048. WWMessageBox().Process(TXT_SELECT_SETTINGS);
  1049. }
  1050. }
  1051. if (process) {
  1052. buttons[curbutton]->IsPressed = false;
  1053. buttons[curbutton]->Flag_To_Redraw();
  1054. }
  1055. display = REDRAW_ALL;
  1056. break;
  1057. case (BUTTON_NULLMODEM):
  1058. if (selectsettings) {
  1059. WWMessageBox().Process(TXT_SELECT_SETTINGS);
  1060. /*
  1061. ** Otherwise, remote-connect; save values if we're recording
  1062. */
  1063. } else if ( Init_Null_Modem( &Session.SerialDefaults ) ) {
  1064. rc = Test_Null_Modem();
  1065. switch (rc) {
  1066. case (1):
  1067. Session.ModemType = MODEM_NULL_HOST;
  1068. if ( Com_Scenario_Dialog() ) {
  1069. retval = GAME_NULL_MODEM;
  1070. process = false;
  1071. }
  1072. break;
  1073. case (2):
  1074. Session.ModemType = MODEM_NULL_JOIN;
  1075. if ( Com_Show_Scenario_Dialog() ) {
  1076. retval = GAME_NULL_MODEM;
  1077. process = false;
  1078. }
  1079. break;
  1080. case (3):
  1081. WWMessageBox().Process( TXT_MODEM_OR_LOOPBACK );
  1082. break;
  1083. }
  1084. if (process) { // restore to default
  1085. NullModem.Change_IRQ_Priority( 0 );
  1086. }
  1087. } else {
  1088. WWMessageBox().Process(TXT_SELECT_SETTINGS);
  1089. }
  1090. if (process) {
  1091. buttons[curbutton]->IsPressed = false;
  1092. buttons[curbutton]->Flag_To_Redraw();
  1093. }
  1094. display = REDRAW_ALL;
  1095. break;
  1096. case (BUTTON_SETTINGS):
  1097. if ( Com_Settings_Dialog( &Session.SerialDefaults ) ) {
  1098. Session.Write_MultiPlayer_Settings ();
  1099. selectsettings = true;
  1100. if (Session.SerialDefaults.Port != 0 &&
  1101. Session.SerialDefaults.IRQ != -1 &&
  1102. Session.SerialDefaults.Baud != -1) {
  1103. if ( NullModem.Detect_Port( &Session.SerialDefaults ) == PORT_VALID) {
  1104. selectsettings = false;
  1105. }
  1106. }
  1107. }
  1108. buttons[curbutton]->IsPressed = false;
  1109. buttons[curbutton]->Flag_To_Redraw();
  1110. display = REDRAW_ALL;
  1111. break;
  1112. case (BUTTON_CANCEL):
  1113. retval = GAME_NORMAL;
  1114. process = false;
  1115. break;
  1116. }
  1117. pressed = false;
  1118. }
  1119. } /* end of while */
  1120. return( retval );
  1121. }
  1122. #ifdef WIN32
  1123. /***********************************************************************************************
  1124. * Advanced_Modem_Settings -- Allows to user to set additional modem settings *
  1125. * *
  1126. * *
  1127. * *
  1128. * INPUT: current settings *
  1129. * *
  1130. * OUTPUT: modified settings *
  1131. * *
  1132. * WARNINGS: None *
  1133. * *
  1134. * HISTORY: *
  1135. * 12/16/96 2:29PM ST : Created *
  1136. *=============================================================================================*/
  1137. Advanced_Modem_Settings (SerialSettingsType *settings)
  1138. {
  1139. /*........................................................................
  1140. Dialog & button dimensions
  1141. ........................................................................*/
  1142. #if (FRENCH | GERMAN)
  1143. int d_dialog_w = 440; // dialog width
  1144. #else
  1145. int d_dialog_w = 340; // dialog width
  1146. #endif
  1147. int d_dialog_h = 200; // dialog height
  1148. int d_dialog_x = 320 - d_dialog_w/2; // dialog x-coord
  1149. int d_dialog_y = 200 - d_dialog_h/ 4; // dialog y-coord
  1150. int d_compression_w = 50;
  1151. int d_compression_h = 18;
  1152. int d_compression_x = d_dialog_x + d_dialog_w/2 +40;
  1153. int d_compression_y = d_dialog_y + 40;
  1154. int d_errorcorrection_w = 50;
  1155. int d_errorcorrection_h = 18;
  1156. int d_errorcorrection_x = d_dialog_x + d_dialog_w/2 +40;
  1157. int d_errorcorrection_y = d_dialog_y + 65;
  1158. int d_hardwareflowcontrol_w = 50;
  1159. int d_hardwareflowcontrol_h = 18;
  1160. int d_hardwareflowcontrol_x = d_dialog_x + d_dialog_w/2 +40;
  1161. int d_hardwareflowcontrol_y = d_dialog_y + 90;
  1162. int d_default_w = 100;
  1163. int d_default_h = 18;
  1164. int d_default_x = d_dialog_x + d_dialog_w / 2 - d_default_w / 2;
  1165. int d_default_y = d_dialog_y + d_dialog_h - 70;
  1166. int d_ok_w = 100;
  1167. int d_ok_h = 18;
  1168. int d_ok_x = d_dialog_x + d_dialog_w/2 - d_ok_w / 2;
  1169. int d_ok_y = d_dialog_y + d_dialog_h - 40;
  1170. enum {
  1171. BUTTON_COMPRESSION = 100,
  1172. BUTTON_ERROR_CORRECTION,
  1173. BUTTON_HARDWARE_FLOW_CONTROL,
  1174. BUTTON_DEFAULT,
  1175. BUTTON_OK,
  1176. };
  1177. typedef enum {
  1178. REDRAW_NONE = 0,
  1179. REDRAW_BUTTONS,
  1180. REDRAW_BACKGROUND,
  1181. REDRAW_ALL = REDRAW_BACKGROUND,
  1182. } RedrawType;
  1183. /*
  1184. ** Yes/No strings
  1185. */
  1186. char compress_text [16];
  1187. char correction_text [16];
  1188. char flowcontrol_text[16];
  1189. RemapControlType * scheme = GadgetClass::Get_Color_Scheme();
  1190. /*
  1191. ** Initialise the button text
  1192. */
  1193. strcpy (compress_text, settings->Compression ? Text_String (TXT_ON) : Text_String (TXT_OFF) );
  1194. strcpy (correction_text, settings->ErrorCorrection ?
  1195. Text_String (TXT_ON) : Text_String (TXT_OFF) );
  1196. strcpy (flowcontrol_text, settings->HardwareFlowControl ?
  1197. Text_String (TXT_ON) : Text_String (TXT_OFF) );
  1198. /*
  1199. ** Create the buttons
  1200. */
  1201. TextButtonClass compressionbutton(BUTTON_COMPRESSION, compress_text,
  1202. TPF_CENTER | TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW,
  1203. d_compression_x, d_compression_y, d_compression_w, d_compression_h);
  1204. TextButtonClass errorcorrectionbutton(BUTTON_ERROR_CORRECTION, correction_text,
  1205. TPF_CENTER | TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW,
  1206. d_errorcorrection_x, d_errorcorrection_y, d_errorcorrection_w, d_errorcorrection_h);
  1207. TextButtonClass hardwareflowcontrolbutton(BUTTON_HARDWARE_FLOW_CONTROL, flowcontrol_text,
  1208. TPF_CENTER | TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW,
  1209. d_hardwareflowcontrol_x, d_hardwareflowcontrol_y, d_hardwareflowcontrol_w, d_hardwareflowcontrol_h);
  1210. TextButtonClass defaultbutton(BUTTON_DEFAULT, TXT_DEFAULT,
  1211. TPF_CENTER | TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW,
  1212. d_default_x, d_default_y, d_default_w, d_default_h);
  1213. TextButtonClass okbutton(BUTTON_OK, TXT_OK,
  1214. TPF_CENTER | TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW,
  1215. d_ok_x, d_ok_y, d_ok_w, d_ok_h);
  1216. /*
  1217. ** Misc. variables.
  1218. */
  1219. RedrawType display = REDRAW_ALL; // redraw level
  1220. BOOL process = true; // process while true
  1221. KeyNumType input;
  1222. GadgetClass *commands; // button list
  1223. commands = &okbutton;
  1224. defaultbutton.Add_Tail(*commands);
  1225. compressionbutton.Add_Tail(*commands);
  1226. errorcorrectionbutton.Add_Tail(*commands);
  1227. hardwareflowcontrolbutton.Add_Tail(*commands);
  1228. /*
  1229. ** Main process loop
  1230. */
  1231. while (process) {
  1232. /*
  1233. ** If we have just received input focus again after running in the background then
  1234. ** we need to redraw.
  1235. */
  1236. if (AllSurfaces.SurfacesRestored){
  1237. AllSurfaces.SurfacesRestored=FALSE;
  1238. display=REDRAW_ALL;
  1239. }
  1240. /*
  1241. ........................ Invoke game callback .........................
  1242. */
  1243. Call_Back();
  1244. /*
  1245. ...................... Refresh display if needed ......................
  1246. */
  1247. if (display) {
  1248. Hide_Mouse();
  1249. /*
  1250. .................. Redraw backgound & dialog box ...................
  1251. */
  1252. if (display >= REDRAW_BACKGROUND) {
  1253. Load_Title_Page(true);
  1254. CCPalette.Set();
  1255. Dialog_Box(d_dialog_x, d_dialog_y, d_dialog_w, d_dialog_h);
  1256. // init font variables
  1257. Fancy_Text_Print(TXT_NONE, 0, 0, scheme, TBLACK, TPF_TEXT);
  1258. /*...............................................................
  1259. Dialog & Field labels
  1260. ...............................................................*/
  1261. Draw_Caption (TXT_MODEM_INITIALISATION, d_dialog_x, d_dialog_y, d_dialog_w);
  1262. Fancy_Text_Print( TXT_DATA_COMPRESSION,
  1263. d_compression_x - 26, d_compression_y + 2,
  1264. scheme, TBLACK, TPF_TEXT | TPF_RIGHT);
  1265. Fancy_Text_Print( TXT_ERROR_CORRECTION,
  1266. d_errorcorrection_x - 26, d_errorcorrection_y +2,
  1267. scheme, TBLACK, TPF_TEXT | TPF_RIGHT);
  1268. Fancy_Text_Print( TXT_HARDWARE_FLOW_CONTROL,
  1269. d_hardwareflowcontrol_x -26, d_hardwareflowcontrol_y +2,
  1270. scheme, TBLACK, TPF_TEXT | TPF_RIGHT);
  1271. }
  1272. /*
  1273. .......................... Redraw buttons ..........................
  1274. */
  1275. if (display >= REDRAW_BUTTONS) {
  1276. compressionbutton.Flag_To_Redraw();
  1277. errorcorrectionbutton.Flag_To_Redraw();
  1278. hardwareflowcontrolbutton.Flag_To_Redraw();
  1279. }
  1280. Show_Mouse();
  1281. display = REDRAW_NONE;
  1282. }
  1283. /*
  1284. ........................... Get user input ............................
  1285. */
  1286. input = commands->Input();
  1287. /*
  1288. ---------------------------- Process input ----------------------------
  1289. */
  1290. switch (input) {
  1291. case (BUTTON_COMPRESSION | KN_BUTTON):
  1292. settings->Compression = settings->Compression ^ 1;
  1293. strcpy (compress_text, settings->Compression ?
  1294. Text_String (TXT_ON) : Text_String (TXT_OFF) );
  1295. if (display < REDRAW_BUTTONS) display = REDRAW_BUTTONS;
  1296. break;
  1297. case (BUTTON_ERROR_CORRECTION | KN_BUTTON):
  1298. settings->ErrorCorrection = settings->ErrorCorrection ^ 1;
  1299. strcpy (correction_text, settings->ErrorCorrection ?
  1300. Text_String (TXT_ON) : Text_String (TXT_OFF) );
  1301. if (display < REDRAW_BUTTONS) display = REDRAW_BUTTONS;
  1302. break;
  1303. case (BUTTON_HARDWARE_FLOW_CONTROL | KN_BUTTON):
  1304. settings->HardwareFlowControl = settings->HardwareFlowControl ^ 1;
  1305. strcpy (flowcontrol_text, settings->HardwareFlowControl ?
  1306. Text_String (TXT_ON) : Text_String (TXT_OFF) );
  1307. if (display < REDRAW_BUTTONS) display = REDRAW_BUTTONS;
  1308. break;
  1309. case (BUTTON_DEFAULT | KN_BUTTON):
  1310. settings->Compression = false;
  1311. settings->ErrorCorrection = false;
  1312. settings->HardwareFlowControl = true;
  1313. strcpy (compress_text, settings->Compression ?
  1314. Text_String (TXT_ON) : Text_String (TXT_OFF) );
  1315. strcpy (correction_text, settings->ErrorCorrection ?
  1316. Text_String (TXT_ON) : Text_String (TXT_OFF) );
  1317. strcpy (flowcontrol_text, settings->HardwareFlowControl ?
  1318. Text_String (TXT_ON) : Text_String (TXT_OFF) );
  1319. if (display < REDRAW_BUTTONS) display = REDRAW_BUTTONS;
  1320. break;
  1321. case (BUTTON_OK | KN_BUTTON):
  1322. process = false;
  1323. break;
  1324. }
  1325. }
  1326. }
  1327. #endif //WIN32
  1328. /***************************************************************************
  1329. * Com_Settings_Dialog -- Lets user select serial port settings *
  1330. * *
  1331. * ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ *
  1332. * ³ Settings ³ *
  1333. * ³ ³ *
  1334. * ³ Port:____ IRQ:__ Baud:______ ³ *
  1335. * ³ ÚÄÄÄÄÄÄÄÄÄÄÄÄ¿ ÚÄÄÄÄÄÄÄÄÄÄÄÄ¿ ÚÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ *
  1336. * ³ ³ ³ ³ ³ ³ ³ ³ *
  1337. * ³ ³ ³ ³ ³ ³ ³ ³ *
  1338. * ³ ³ ³ ³ ³ ³ ³ ³ *
  1339. * ³ ³ ³ ³ ³ ³ ³ ³ *
  1340. * ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÙ ÀÄÄÄÄÄÄÄÄÄÄÄÄÙ ÀÄÄÄÄÄÄÄÄÄÄÄÄÙ ³ *
  1341. * ³ ³ *
  1342. * ³ Initialization: [Add] [Delete] ³ *
  1343. * ³ _____________________________ ³ *
  1344. * ³ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ *
  1345. * ³ ³ ³ ³ *
  1346. * ³ ³ ³ ³ *
  1347. * ³ ³ ³ ³ *
  1348. * ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ³ *
  1349. * ³ ³ *
  1350. * ³ Call Waiting: ³ *
  1351. * ³ _______________ ³ *
  1352. * ³ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ [Tone Dialing] ³ *
  1353. * ³ ³ ³ ³ *
  1354. * ³ ³ ³ [Pulse Dialing] ³ *
  1355. * ³ ³ ³ ³ *
  1356. * ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ³ *
  1357. * ³ ³ *
  1358. * ³ [OK] [Cancel] ³ *
  1359. * ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ *
  1360. * *
  1361. * INPUT: *
  1362. * settings ptr to SerialSettingsType structure *
  1363. * *
  1364. * OUTPUT: *
  1365. * true = OK, false = Cancel *
  1366. * *
  1367. * WARNINGS: *
  1368. * none. *
  1369. * *
  1370. * HISTORY: *
  1371. * 04/29/1995 BRR : Created. *
  1372. *=========================================================================*/
  1373. static int Com_Settings_Dialog( SerialSettingsType *settings )
  1374. {
  1375. /*
  1376. ** Dialog & button dimensions
  1377. */
  1378. int d_dialog_w = 320 * RESFACTOR; // dialog width
  1379. int d_dialog_h = 200 * RESFACTOR; // dialog height
  1380. int d_dialog_x = ((320 * RESFACTOR - d_dialog_w) / 2); // dialog x-coord
  1381. int d_dialog_y = ((200 * RESFACTOR - d_dialog_h) / 2); // dialog y-coord
  1382. int d_dialog_cx = d_dialog_x + (d_dialog_w / 2); // center x-coord
  1383. int d_txt6_h = 7 * RESFACTOR; // ht of 6-pt text
  1384. int d_margin = 5 * RESFACTOR; // margin width/height
  1385. int d_portlist_w = 80 * RESFACTOR + 80*(RESFACTOR-1); //Port list wider in hires
  1386. int d_portlist_h = 33 * RESFACTOR;
  1387. int d_portlist_x = d_dialog_x + (d_dialog_w / 6) - (d_portlist_w / 2);
  1388. #ifdef WIN32
  1389. d_portlist_x = 0x45;
  1390. #endif
  1391. int d_portlist_y = d_dialog_y + ((d_margin + d_txt6_h) * 2) + d_margin + 10 * RESFACTOR;
  1392. #ifdef WIN32
  1393. int d_port_w = d_portlist_w;
  1394. int d_port_x = 0x45;
  1395. #else
  1396. int d_port_w = (5 * 6 * RESFACTOR) + 3 * RESFACTOR;
  1397. // int d_port_x = d_portlist_x + 29 * RESFACTOR;
  1398. #ifdef FRENCH //VG2
  1399. int d_port_x = (d_portlist_x + 29 * RESFACTOR) + 5;
  1400. #else
  1401. int d_port_x = d_portlist_x + 29 * RESFACTOR;
  1402. #endif
  1403. #endif //WIN32
  1404. int d_port_h = 9 * RESFACTOR;
  1405. int d_port_y = d_portlist_y - d_margin - d_txt6_h;
  1406. int d_irqlist_w = 80 * RESFACTOR;
  1407. int d_irqlist_h = 33 * RESFACTOR;
  1408. int d_irqlist_x = d_dialog_x + (d_dialog_w / 2) - (d_irqlist_w / 2);
  1409. int d_irqlist_y = d_portlist_y;
  1410. int d_irq_w = ((IRQBUF_MAX - 1) * 6 * RESFACTOR) + 3 * RESFACTOR;
  1411. int d_irq_h = 9 * RESFACTOR;
  1412. int d_irq_x = d_irqlist_x + 25 * RESFACTOR;
  1413. int d_irq_y = d_irqlist_y - d_margin - d_txt6_h;
  1414. int d_baudlist_w = 80 * RESFACTOR;
  1415. int d_baudlist_h = 33 * RESFACTOR;
  1416. int d_baudlist_x = d_dialog_x + ((d_dialog_w * 5) / 6) - (d_baudlist_w / 2);
  1417. #ifdef WIN32
  1418. d_baudlist_x -= 32;
  1419. #endif
  1420. int d_baudlist_y = d_irqlist_y;
  1421. int d_baud_w = ((BAUDBUF_MAX - 1) * 6 * RESFACTOR) + 3 * RESFACTOR;
  1422. int d_baud_h = 9 * RESFACTOR;
  1423. int d_baud_x = d_baudlist_x + 29 * RESFACTOR;
  1424. int d_baud_y = d_baudlist_y - d_margin - d_txt6_h;
  1425. int d_initstrlist_w = ((INITSTRBUF_MAX - 1) * 6 * RESFACTOR) + 8 * RESFACTOR + 3 * RESFACTOR;
  1426. int d_initstrlist_h = 21 * RESFACTOR;
  1427. int d_initstrlist_x = d_dialog_cx - (d_initstrlist_w / 2);
  1428. int d_initstrlist_y = d_portlist_y + d_portlist_h + ((d_margin + d_txt6_h) * 2) + d_margin + 4;
  1429. int d_initstr_w = ((INITSTRBUF_MAX - 1) * 6 * RESFACTOR) + 3 * RESFACTOR;
  1430. int d_initstr_h = 9 * RESFACTOR;
  1431. int d_initstr_x = d_initstrlist_x;
  1432. int d_initstr_y = d_initstrlist_y - d_margin - d_txt6_h;
  1433. int d_add_w = 45 * RESFACTOR;
  1434. #ifdef FRENCH
  1435. int d_add_x = d_dialog_cx - (d_add_w / 2);
  1436. #else
  1437. int d_add_x = (d_dialog_cx - (d_add_w / 2)) + 30;
  1438. #endif
  1439. int d_add_h = 9 * RESFACTOR;
  1440. int d_add_y = d_initstr_y - d_add_h - 3 * RESFACTOR;
  1441. int d_delete_w = 45 * RESFACTOR;
  1442. #ifdef FRENCH
  1443. int d_delete_x = (d_dialog_x + ((d_dialog_w * 3) / 4) - (d_delete_w / 2)) + 10;
  1444. #else
  1445. int d_delete_x = d_dialog_x + ((d_dialog_w * 3) / 4) - (d_delete_w / 2);
  1446. #endif
  1447. int d_delete_h = 9 * RESFACTOR;
  1448. int d_delete_y = d_initstr_y - d_add_h - 3 * RESFACTOR;
  1449. int d_cwaitstrlist_w = (((CWAITSTRBUF_MAX - 1) + 9) * 6) * RESFACTOR + 3 * RESFACTOR;
  1450. int d_cwaitstrlist_h = 27 * RESFACTOR;
  1451. int d_cwaitstrlist_x = d_initstrlist_x;
  1452. int d_cwaitstrlist_y = d_initstrlist_y + d_initstrlist_h + ((d_margin + d_txt6_h) * 2) + 2;
  1453. int d_cwaitstr_w = ((CWAITSTRBUF_MAX - 1) * 6) * RESFACTOR + 3 * RESFACTOR;
  1454. int d_cwaitstr_h = 9 * RESFACTOR;
  1455. int d_cwaitstr_x = d_cwaitstrlist_x;
  1456. int d_cwaitstr_y = d_cwaitstrlist_y - d_margin - d_txt6_h;
  1457. int d_tone_w = 80 * RESFACTOR;
  1458. int d_tone_h = 9 * RESFACTOR;
  1459. int d_tone_x = d_dialog_x + ((d_dialog_w * 3) / 4) - (d_tone_w / 2);
  1460. int d_tone_y = d_cwaitstrlist_y;
  1461. int d_pulse_w = 80 * RESFACTOR;
  1462. int d_pulse_h = 9 * RESFACTOR;
  1463. int d_pulse_x = d_dialog_x + ((d_dialog_w * 3) / 4) - (d_pulse_w / 2);
  1464. int d_pulse_y = d_tone_y + d_tone_h + d_margin;
  1465. #ifdef FRENCH
  1466. int d_save_w = 80 * RESFACTOR;
  1467. #else
  1468. int d_save_w = 40 * RESFACTOR;
  1469. #endif
  1470. int d_save_h = 9 * RESFACTOR;
  1471. int d_save_x = d_dialog_x + (d_dialog_w / 5) - (d_save_w / 2);
  1472. int d_save_y = d_dialog_y + d_dialog_h - d_save_h - d_margin - 4*RESFACTOR;
  1473. int d_cancel_w = 50 * RESFACTOR;
  1474. int d_cancel_h = 9 * RESFACTOR;
  1475. int d_cancel_x = d_dialog_x + ((d_dialog_w * 4) / 5) - (d_cancel_w / 2);
  1476. int d_cancel_y = d_dialog_y + d_dialog_h - d_cancel_h - d_margin - 4*RESFACTOR;
  1477. #if (GERMAN | FRENCH)
  1478. int d_advanced_w = 50*RESFACTOR;
  1479. #else
  1480. int d_advanced_w = 40*RESFACTOR;
  1481. #endif
  1482. int d_advanced_h = 9*RESFACTOR;
  1483. int d_advanced_x = d_dialog_x + ((d_dialog_w) / 2) - (d_advanced_w / 2);
  1484. int d_advanced_y = d_dialog_y + d_dialog_h - d_advanced_h - d_margin - 4 *RESFACTOR;
  1485. /*
  1486. ** Button Enumerations
  1487. */
  1488. enum {
  1489. BUTTON_PORT = 100,
  1490. BUTTON_PORTLIST,
  1491. BUTTON_IRQ,
  1492. BUTTON_IRQLIST,
  1493. BUTTON_BAUD,
  1494. BUTTON_BAUDLIST,
  1495. BUTTON_INITSTR,
  1496. BUTTON_INITSTRLIST,
  1497. BUTTON_ADD,
  1498. BUTTON_DELETE,
  1499. BUTTON_CWAITSTR,
  1500. BUTTON_CWAITSTRLIST,
  1501. BUTTON_TONE,
  1502. BUTTON_PULSE,
  1503. BUTTON_SAVE,
  1504. BUTTON_ADVANCED,
  1505. BUTTON_CANCEL,
  1506. };
  1507. /*
  1508. ** Redraw values: in order from "top" to "bottom" layer of the dialog
  1509. */
  1510. typedef enum {
  1511. REDRAW_NONE = 0,
  1512. REDRAW_BUTTONS,
  1513. REDRAW_BACKGROUND,
  1514. REDRAW_ALL = REDRAW_BACKGROUND
  1515. } RedrawType;
  1516. static char *portname[4] = {
  1517. "COM1 - 3F8",
  1518. "COM2 - 2F8",
  1519. "COM3 - 3E8",
  1520. "COM4 - 2E8",
  1521. };
  1522. static char custom_port[10 + MODEM_NAME_MAX] = {"CUSTOM - ????"};
  1523. #ifndef WIN32 // No IRQ dialog in Win version
  1524. static char *irqname[5] = {
  1525. "2 / 9",
  1526. "3 - [COM2 & 4]",
  1527. "4 - [COM1 & 3]",
  1528. "5",
  1529. "CUSTOM - ??"
  1530. };
  1531. static int _irqidx[4] = {
  1532. 2,
  1533. 1,
  1534. 2,
  1535. 1
  1536. };
  1537. #endif //WIN32
  1538. #ifdef WIN32
  1539. static char *baudname[5] = {
  1540. "14400",
  1541. "19200",
  1542. "28800",
  1543. "38400",
  1544. "57600",
  1545. };
  1546. static char modemnames[10][MODEM_NAME_MAX];
  1547. #else //WIN32
  1548. static char *baudname[5] = {
  1549. "9600",
  1550. "14400",
  1551. "19200",
  1552. "28800",
  1553. "38400"
  1554. };
  1555. #endif //WIN32
  1556. /*
  1557. ** Dialog variables
  1558. */
  1559. RedrawType display = REDRAW_ALL; // redraw level
  1560. bool process = true; // process while true
  1561. KeyNumType input;
  1562. char * item; // general-purpose string
  1563. char * temp; // general-purpose string
  1564. RemapControlType * scheme = GadgetClass::Get_Color_Scheme();
  1565. char portbuf[ PORTBUF_MAX ] = {0}; // buffer for port
  1566. char irqbuf[ IRQBUF_MAX ] = {0}; // buffer for irq
  1567. char baudbuf[ BAUDBUF_MAX ] = {0}; // buffer for baud
  1568. char initstrbuf[ INITSTRBUF_MAX ] = {0}; // buffer for init string
  1569. char cwaitstrbuf[ CWAITSTRBUF_MAX ] = {0}; // buffer for call waiting string
  1570. int port_index = 1; // index of currently-selected port (default = com2)
  1571. int port_custom_index = 4; //index of custom entry in port list
  1572. int irq_index = 1; // index of currently-selected irq (default = 3)
  1573. int baud_index = 1; // index of currently-selected baud (default = 19200)
  1574. int initstr_index = 0; // index of currently-selected modem init (default = "ATZ")
  1575. int cwaitstr_index = CALL_WAIT_CUSTOM; // index of currently-selected call waiting (default = "")
  1576. int rc = 0; // -1 = user cancelled, 1 = New
  1577. int i; // loop counter
  1578. int pos;
  1579. int len;
  1580. bool firsttime = true;
  1581. SerialSettingsType tempsettings;
  1582. DetectPortType dpstatus;
  1583. /*
  1584. ** Buttons
  1585. */
  1586. GadgetClass *commands; // button list
  1587. EditClass port_edt (BUTTON_PORT, portbuf, PORTBUF_MAX,
  1588. TPF_TEXT, d_port_x, d_port_y, d_port_w, d_port_h, EditClass::ALPHANUMERIC);
  1589. ListClass portlist(BUTTON_PORTLIST, d_portlist_x, d_portlist_y, d_portlist_w, d_portlist_h,
  1590. TPF_TEXT, MFCD::Retrieve("BTN-UP.SHP"), MFCD::Retrieve("BTN-DN.SHP"));
  1591. #ifndef WIN32
  1592. EditClass irq_edt (BUTTON_IRQ, irqbuf, IRQBUF_MAX, TPF_TEXT, d_irq_x, d_irq_y, d_irq_w, d_irq_h, EditClass::NUMERIC);
  1593. ListClass irqlist(BUTTON_IRQLIST, d_irqlist_x, d_irqlist_y, d_irqlist_w, d_irqlist_h, TPF_TEXT, MFCD::Retrieve("BTN-UP.SHP"), MFCD::Retrieve("BTN-DN.SHP"));
  1594. #endif //WIN32
  1595. EditClass baud_edt (BUTTON_BAUD, baudbuf, BAUDBUF_MAX, TPF_TEXT, d_baud_x, d_baud_y, d_baud_w, d_baud_h, EditClass::NUMERIC);
  1596. ListClass baudlist(BUTTON_BAUDLIST, d_baudlist_x, d_baudlist_y, d_baudlist_w, d_baudlist_h, TPF_TEXT, MFCD::Retrieve("BTN-UP.SHP"), MFCD::Retrieve("BTN-DN.SHP"));
  1597. EditClass initstr_edt (BUTTON_INITSTR, initstrbuf, INITSTRBUF_MAX, TPF_TEXT, d_initstr_x, d_initstr_y, d_initstr_w, d_initstr_h, EditClass::ALPHANUMERIC);
  1598. ListClass initstrlist(BUTTON_INITSTRLIST, d_initstrlist_x, d_initstrlist_y, d_initstrlist_w, d_initstrlist_h, TPF_TEXT, MFCD::Retrieve("BTN-UP.SHP"), MFCD::Retrieve("BTN-DN.SHP"));
  1599. TextButtonClass addbtn(BUTTON_ADD, TXT_ADD, TPF_BUTTON, d_add_x, d_add_y, d_add_w, d_add_h);
  1600. TextButtonClass deletebtn(BUTTON_DELETE, TXT_DELETE_BUTTON, TPF_BUTTON, d_delete_x, d_delete_y, d_delete_w, d_delete_h);
  1601. EditClass cwaitstr_edt (BUTTON_CWAITSTR, cwaitstrbuf, CWAITSTRBUF_MAX, TPF_TEXT, d_cwaitstr_x, d_cwaitstr_y, d_cwaitstr_w, d_cwaitstr_h, EditClass::ALPHANUMERIC);
  1602. ListClass cwaitstrlist(BUTTON_CWAITSTRLIST, d_cwaitstrlist_x, d_cwaitstrlist_y, d_cwaitstrlist_w, d_cwaitstrlist_h, TPF_TEXT, MFCD::Retrieve("BTN-UP.SHP"), MFCD::Retrieve("BTN-DN.SHP"));
  1603. TextButtonClass tonebtn(BUTTON_TONE, TXT_TONE_BUTTON, TPF_BUTTON, d_tone_x, d_tone_y, d_tone_w, d_tone_h);
  1604. TextButtonClass pulsebtn(BUTTON_PULSE, TXT_PULSE_BUTTON, TPF_BUTTON, d_pulse_x, d_pulse_y, d_pulse_w, d_pulse_h);
  1605. TextButtonClass savebtn(BUTTON_SAVE, TXT_SAVE_BUTTON, TPF_BUTTON, d_save_x, d_save_y, d_save_w, d_save_h);
  1606. TextButtonClass cancelbtn(BUTTON_CANCEL, TXT_CANCEL, TPF_BUTTON, d_cancel_x, d_cancel_y, d_cancel_w, d_cancel_h);
  1607. #ifdef WIN32
  1608. TextButtonClass advancedbutton(BUTTON_ADVANCED, TXT_ADVANCED, TPF_BUTTON, d_advanced_x, d_advanced_y, d_advanced_w, d_advanced_h);
  1609. #endif //WIN32
  1610. /*
  1611. ** Various Inits
  1612. */
  1613. memcpy( &tempsettings, settings, sizeof(SerialSettingsType) );
  1614. if (tempsettings.Port == 0) {
  1615. tempsettings.Port = 0x2f8;
  1616. }
  1617. if (tempsettings.IRQ == -1) {
  1618. tempsettings.IRQ = 3;
  1619. }
  1620. if (tempsettings.Baud == -1) {
  1621. #ifdef WIN32
  1622. tempsettings.Baud = 19200;
  1623. #else //WIN32
  1624. tempsettings.Baud = 9600;
  1625. #endif //WIN32
  1626. }
  1627. /*
  1628. ** Set the current indices
  1629. */
  1630. #ifndef WIN32
  1631. switch ( tempsettings.IRQ ) {
  1632. case ( 2 ):
  1633. irq_index = 0;
  1634. strcpy (irqbuf, "2");
  1635. break;
  1636. case ( 3 ):
  1637. irq_index = 1;
  1638. strcpy (irqbuf, "3");
  1639. break;
  1640. case ( 4 ):
  1641. irq_index = 2;
  1642. strcpy (irqbuf, "4");
  1643. break;
  1644. case ( 5 ):
  1645. irq_index = 3;
  1646. strcpy (irqbuf, "5");
  1647. break;
  1648. default:
  1649. irq_index = 4;
  1650. sprintf (irqbuf, "%d", tempsettings.IRQ);
  1651. temp = strchr( irqname[4], '-' );
  1652. if ( temp ) {
  1653. pos = (int)(temp - irqname[4]) + 2;
  1654. len = strlen( irqbuf );
  1655. strncpy( irqname[4] + pos, irqbuf, len );
  1656. *(irqname[4] + pos + len) = 0;
  1657. }
  1658. break;
  1659. }
  1660. #endif //WIN32
  1661. #ifdef WIN32
  1662. if (tempsettings.Baud == 14400) {
  1663. baud_index = 0;
  1664. } else if (tempsettings.Baud == 19200) {
  1665. baud_index = 1;
  1666. } else if (tempsettings.Baud == 28800) {
  1667. baud_index = 2;
  1668. } else if (tempsettings.Baud == 38400) {
  1669. baud_index = 3;
  1670. } else {
  1671. baud_index = 4;
  1672. }
  1673. #else //WIN32
  1674. if (tempsettings.Baud == 9600) {
  1675. baud_index = 0;
  1676. } else if (tempsettings.Baud == 14400) {
  1677. baud_index = 1;
  1678. } else if (tempsettings.Baud == 19200) {
  1679. baud_index = 2;
  1680. } else if (tempsettings.Baud == 28800) {
  1681. baud_index = 3;
  1682. } else {
  1683. baud_index = 4;
  1684. }
  1685. #endif //WIN32
  1686. sprintf (baudbuf, "%d", tempsettings.Baud);
  1687. /*
  1688. ** Set up the port list box & edit box
  1689. */
  1690. for (i = 0; i < 4; i++) {
  1691. portlist.Add_Item( portname[ i ] );
  1692. }
  1693. #ifdef WIN32
  1694. /*
  1695. ** Loop through the first 10 possible modem entries in the registry. Frankly, its just
  1696. ** tough luck if the user has more than 10 modems attached!
  1697. */
  1698. if (ModemRegistry) {
  1699. delete ModemRegistry;
  1700. }
  1701. int modems_found = 0;
  1702. for (i=0 ; i<10 ; i++) {
  1703. ModemRegistry = new ModemRegistryEntryClass (i);
  1704. if (ModemRegistry->Get_Modem_Name()) {
  1705. strncpy (modemnames[modems_found], ModemRegistry->Get_Modem_Name(), MODEM_NAME_MAX);
  1706. portlist.Add_Item( modemnames [modems_found++] );
  1707. port_custom_index ++;
  1708. }
  1709. delete ModemRegistry;
  1710. }
  1711. ModemRegistry = NULL;
  1712. #endif //WIN32
  1713. portlist.Add_Item ( custom_port );
  1714. /*
  1715. ** Work out the current port index
  1716. */
  1717. port_index = -1;
  1718. #ifdef WIN32
  1719. if (tempsettings.ModemName[0]) {
  1720. for ( i=0 ; i<port_custom_index ; i++) {
  1721. if (!stricmp (portlist.Get_Item(i), tempsettings.ModemName)) {
  1722. port_index = i;
  1723. strcpy (portbuf, tempsettings.ModemName);
  1724. break;
  1725. }
  1726. }
  1727. /*
  1728. ** The modem name specified wasnt in the registry so add it as a custom entry
  1729. */
  1730. if (port_index == -1) {
  1731. temp = strchr( custom_port, '-' );
  1732. if ( temp ) {
  1733. pos = (int)(temp - custom_port) + 2;
  1734. len = strlen( tempsettings.ModemName );
  1735. strncpy( custom_port + pos, tempsettings.ModemName, len );
  1736. *(custom_port + pos + len) = 0;
  1737. strcpy (portbuf, tempsettings.ModemName);
  1738. port_index = port_custom_index;
  1739. }
  1740. }
  1741. }
  1742. #endif //WIN32
  1743. if (port_index == -1) {
  1744. switch ( tempsettings.Port ) {
  1745. case ( 0x3f8 ):
  1746. port_index = 0;
  1747. strcpy (portbuf, "COM1");
  1748. break;
  1749. case ( 0x2f8 ):
  1750. port_index = 1;
  1751. strcpy (portbuf, "COM2");
  1752. break;
  1753. case ( 0x3e8 ):
  1754. port_index = 2;
  1755. strcpy (portbuf, "COM3");
  1756. break;
  1757. case ( 0x2e8 ):
  1758. port_index = 3;
  1759. strcpy (portbuf, "COM4");
  1760. break;
  1761. default:
  1762. port_index = port_custom_index;
  1763. sprintf (portbuf, "%x", tempsettings.Port);
  1764. temp = strchr( custom_port, '-' );
  1765. if ( temp ) {
  1766. pos = (int)(temp - custom_port) + 2;
  1767. len = strlen( portbuf );
  1768. strncpy( custom_port + pos, portbuf, len );
  1769. *(custom_port + pos + len) = 0;
  1770. }
  1771. break;
  1772. }
  1773. }
  1774. portlist.Set_Selected_Index( port_index );
  1775. /*
  1776. ** Set up the port edit box
  1777. */
  1778. port_edt.Set_Text( portbuf, PORTBUF_MAX );
  1779. #ifndef WIN32
  1780. /*
  1781. ** Set up the IRQ list box & edit box
  1782. */
  1783. for (i = 0; i < 5; i++) {
  1784. irqlist.Add_Item( irqname[ i ] );
  1785. }
  1786. irqlist.Set_Selected_Index( irq_index );
  1787. irq_edt.Set_Text( irqbuf, IRQBUF_MAX );
  1788. #endif //WIN32
  1789. /*
  1790. ** Set up the baud rate list box & edit box
  1791. */
  1792. for (i = 0; i < 5; i++) {
  1793. baudlist.Add_Item( baudname[ i ] );
  1794. }
  1795. baudlist.Set_Selected_Index( baud_index );
  1796. baud_edt.Set_Text( baudbuf, BAUDBUF_MAX );
  1797. initstr_index = tempsettings.InitStringIndex;
  1798. Build_Init_String_Listbox(&initstrlist, &initstr_edt, initstrbuf, &initstr_index);
  1799. /*
  1800. ** Set up the cwait rate list box & edit box
  1801. */
  1802. cwaitstr_index = tempsettings.CallWaitStringIndex;
  1803. for (i = 0; i < CALL_WAIT_STRINGS_NUM; i++) {
  1804. if ( i == CALL_WAIT_CUSTOM ) {
  1805. item = Session.CallWaitStrings[ i ];
  1806. temp = strchr( item, '-' );
  1807. if ( temp ) {
  1808. pos = (int)(temp - item) + 2;
  1809. len = strlen( tempsettings.CallWaitString );
  1810. strncpy( item + pos, tempsettings.CallWaitString, len );
  1811. *(item + pos + len) = 0;
  1812. if (i == cwaitstr_index) {
  1813. strncpy( cwaitstrbuf, item + pos, CWAITSTRBUF_MAX );
  1814. }
  1815. }
  1816. } else if (i == cwaitstr_index) {
  1817. strncpy( cwaitstrbuf, Session.CallWaitStrings[ i ], CWAITSTRBUF_MAX );
  1818. }
  1819. cwaitstrlist.Add_Item( Session.CallWaitStrings[ i ] );
  1820. }
  1821. cwaitstrlist.Set_Selected_Index( cwaitstr_index );
  1822. cwaitstr_edt.Set_Text( cwaitstrbuf, CWAITSTRBUF_MAX );
  1823. /*
  1824. ** Build the button list
  1825. */
  1826. commands = &cancelbtn;
  1827. port_edt.Add_Tail(*commands);
  1828. portlist.Add_Tail(*commands);
  1829. #ifndef WIN32
  1830. irq_edt.Add_Tail(*commands);
  1831. irqlist.Add_Tail(*commands);
  1832. #endif //WIN32
  1833. baud_edt.Add_Tail(*commands);
  1834. baudlist.Add_Tail(*commands);
  1835. initstr_edt.Add_Tail(*commands);
  1836. initstrlist.Add_Tail(*commands);
  1837. addbtn.Add_Tail(*commands);
  1838. deletebtn.Add_Tail(*commands);
  1839. cwaitstr_edt.Add_Tail(*commands);
  1840. cwaitstrlist.Add_Tail(*commands);
  1841. tonebtn.Add_Tail(*commands);
  1842. pulsebtn.Add_Tail(*commands);
  1843. savebtn.Add_Tail(*commands);
  1844. #ifdef WIN32
  1845. advancedbutton.Add_Tail(*commands);
  1846. #endif //WIN32
  1847. if (tempsettings.DialMethod == DIAL_TOUCH_TONE) {
  1848. tonebtn.Turn_On();
  1849. } else {
  1850. pulsebtn.Turn_On();
  1851. }
  1852. /*
  1853. ** Processing loop
  1854. */
  1855. while (process) {
  1856. /*
  1857. ** Invoke game callback
  1858. */
  1859. Call_Back();
  1860. /*
  1861. ** Dont allow editing of non-custom ports to fix the problem of the cursor appearing
  1862. ** outside the edit box.
  1863. */
  1864. if (port_index == port_custom_index) {
  1865. port_edt.Set_Read_Only(false);
  1866. }else{
  1867. port_edt.Set_Read_Only(true);
  1868. }
  1869. #ifdef WIN32
  1870. /*
  1871. ** If we have just received input focus again after running in the background then
  1872. ** we need to redraw.
  1873. */
  1874. if (AllSurfaces.SurfacesRestored) {
  1875. AllSurfaces.SurfacesRestored=FALSE;
  1876. display = REDRAW_ALL;
  1877. }
  1878. #endif
  1879. /*
  1880. ** Refresh display if needed
  1881. */
  1882. if (display) {
  1883. Hide_Mouse();
  1884. /*
  1885. ** Redraw backgound & dialog box
  1886. */
  1887. if (display >= REDRAW_BACKGROUND) {
  1888. Load_Title_Page(true);
  1889. CCPalette.Set();
  1890. Dialog_Box(d_dialog_x, d_dialog_y, d_dialog_w, d_dialog_h);
  1891. // init font variables
  1892. Fancy_Text_Print(TXT_NONE, 0, 0, TBLACK, TBLACK, TPF_CENTER | TPF_TEXT);
  1893. /*
  1894. ** Dialog & Field labels
  1895. */
  1896. Draw_Caption(TXT_SETTINGS, d_dialog_x, d_dialog_y, d_dialog_w);
  1897. Fancy_Text_Print(TXT_PORT_COLON, d_port_x - 3 * RESFACTOR, d_port_y + 1 * RESFACTOR, scheme, TBLACK, TPF_RIGHT | TPF_TEXT);
  1898. #ifndef WIN32
  1899. Fancy_Text_Print(TXT_IRQ_COLON, d_irq_x - 3 * RESFACTOR, d_irq_y + 1 * RESFACTOR, scheme, TBLACK, TPF_RIGHT | TPF_TEXT);
  1900. #endif //WIN32
  1901. Fancy_Text_Print(TXT_BAUD_COLON, d_baud_x - 3 * RESFACTOR, d_baud_y + 1 * RESFACTOR, scheme, TBLACK, TPF_RIGHT | TPF_TEXT);
  1902. Fancy_Text_Print(TXT_INIT_STRING, d_initstr_x, d_initstr_y - d_txt6_h - 3 * RESFACTOR, scheme, TBLACK, TPF_TEXT);
  1903. Fancy_Text_Print(TXT_CWAIT_STRING, d_cwaitstr_x, d_cwaitstr_y - d_txt6_h - 3 * RESFACTOR, scheme, TBLACK, TPF_TEXT);
  1904. }
  1905. /*
  1906. ** Redraw buttons
  1907. */
  1908. if (display >= REDRAW_BUTTONS) {
  1909. cancelbtn.Flag_To_Redraw();
  1910. port_edt.Flag_To_Redraw();
  1911. portlist.Flag_To_Redraw();
  1912. #ifndef WIN32
  1913. irq_edt.Flag_To_Redraw();
  1914. irqlist.Flag_To_Redraw();
  1915. #endif //WIN32
  1916. baud_edt.Flag_To_Redraw();
  1917. baudlist.Flag_To_Redraw();
  1918. #ifdef WIN32
  1919. advancedbutton.Flag_To_Redraw();
  1920. #endif //WIN32
  1921. initstr_edt.Flag_To_Redraw();
  1922. initstrlist.Flag_To_Redraw();
  1923. addbtn.Flag_To_Redraw();
  1924. deletebtn.Flag_To_Redraw();
  1925. cwaitstr_edt.Flag_To_Redraw();
  1926. cwaitstrlist.Flag_To_Redraw();
  1927. tonebtn.Flag_To_Redraw();
  1928. pulsebtn.Flag_To_Redraw();
  1929. savebtn.Flag_To_Redraw();
  1930. }
  1931. Show_Mouse();
  1932. display = REDRAW_NONE;
  1933. }
  1934. /*
  1935. ** Get user input
  1936. */
  1937. input = commands->Input();
  1938. if ( firsttime ) {
  1939. // port_edt.Set_Focus();
  1940. port_edt.Flag_To_Redraw();
  1941. input = commands->Input();
  1942. firsttime = false;
  1943. }
  1944. /*
  1945. ** Process input
  1946. */
  1947. switch (input) {
  1948. #ifdef WIN32
  1949. case (BUTTON_ADVANCED | KN_BUTTON):
  1950. Advanced_Modem_Settings (&tempsettings);
  1951. display = REDRAW_ALL;
  1952. break;
  1953. #endif //WIN32
  1954. case (BUTTON_PORT | KN_BUTTON):
  1955. item = (char *)portlist.Current_Item();
  1956. if (port_index < 4) {
  1957. temp = strchr( item, ' ' );
  1958. if ( !temp ) {
  1959. strncpy( portbuf, item, PORTBUF_MAX );
  1960. } else {
  1961. pos = (int)(temp - item);
  1962. strncpy( portbuf, item, pos );
  1963. portbuf[pos] = 0;
  1964. }
  1965. port_edt.Set_Text( portbuf, PORTBUF_MAX );
  1966. port_edt.Flag_To_Redraw();
  1967. #ifndef WIN32
  1968. irq_edt.Set_Focus();
  1969. irq_edt.Flag_To_Redraw();
  1970. #endif //WIN32
  1971. } else {
  1972. strupr( portbuf );
  1973. if ( stricmp(portbuf, "3F8") == 0 ) {
  1974. port_index = 0;
  1975. portlist.Set_Selected_Index( port_index );
  1976. strcpy (portbuf, "COM1");
  1977. display = REDRAW_BUTTONS;
  1978. } else if ( stricmp(portbuf, "2F8") == 0 ) {
  1979. port_index = 1;
  1980. portlist.Set_Selected_Index( port_index );
  1981. strcpy (portbuf, "COM2");
  1982. display = REDRAW_BUTTONS;
  1983. } else if ( stricmp(portbuf, "3E8") == 0 ) {
  1984. port_index = 2;
  1985. portlist.Set_Selected_Index( port_index );
  1986. strcpy (portbuf, "COM3");
  1987. display = REDRAW_BUTTONS;
  1988. } else if ( stricmp(portbuf, "2E8") == 0 ) {
  1989. port_index = 3;
  1990. portlist.Set_Selected_Index( port_index );
  1991. strcpy (portbuf, "COM4");
  1992. display = REDRAW_BUTTONS;
  1993. } else if ( strncmp(portbuf, "COM", 3) == 0 ) {
  1994. display = REDRAW_BUTTONS;
  1995. switch ( (portbuf[3] - '0') ) {
  1996. case 1:
  1997. port_index = 0;
  1998. break;
  1999. case 2:
  2000. port_index = 1;
  2001. break;
  2002. case 3:
  2003. port_index = 2;
  2004. break;
  2005. case 4:
  2006. port_index = 3;
  2007. break;
  2008. default:
  2009. #ifdef WIN32
  2010. if (portbuf[3] <= '9' && portbuf[3] >'0') {
  2011. portbuf[4] = 0;
  2012. port_index = port_custom_index;
  2013. temp = strchr( item, '-' );
  2014. if ( temp ) {
  2015. pos = (int)(temp - item) + 2;
  2016. len = strlen( portbuf );
  2017. strncpy( item + pos, portbuf, len );
  2018. *(item + pos + len) = 0;
  2019. display = REDRAW_BUTTONS;
  2020. }
  2021. break;
  2022. }
  2023. #endif //WIN32
  2024. WWMessageBox().Process( TXT_INVALID_PORT_ADDRESS );
  2025. port_edt.Set_Focus();
  2026. display = REDRAW_ALL;
  2027. break;
  2028. }
  2029. portlist.Set_Selected_Index( port_index );
  2030. } else {
  2031. temp = strchr( item, '-' );
  2032. if ( temp ) {
  2033. pos = (int)(temp - item) + 2;
  2034. len = strlen( portbuf );
  2035. strncpy( item + pos, portbuf, len );
  2036. *(item + pos + len) = 0;
  2037. display = REDRAW_BUTTONS;
  2038. }
  2039. }
  2040. #ifndef WIN32
  2041. if (display == REDRAW_BUTTONS) {
  2042. irq_edt.Set_Focus();
  2043. irq_edt.Flag_To_Redraw();
  2044. }
  2045. #endif //WIN32
  2046. }
  2047. break;
  2048. case (BUTTON_PORTLIST | KN_BUTTON):
  2049. if (portlist.Current_Index() != port_index) {
  2050. port_index = portlist.Current_Index();
  2051. item = (char *)portlist.Current_Item();
  2052. if (port_index < 4) {
  2053. temp = strchr( item, ' ' );
  2054. pos = (int)(temp - item);
  2055. strncpy( portbuf, item, pos );
  2056. portbuf[pos] = 0;
  2057. port_edt.Clear_Focus();
  2058. // auto select the irq for port
  2059. #ifndef WIN32
  2060. irq_index = _irqidx[ port_index ];
  2061. irqlist.Set_Selected_Index( irq_index );
  2062. item = (char *)irqlist.Current_Item();
  2063. temp = strchr( item, ' ' );
  2064. if ( !temp ) {
  2065. strncpy( irqbuf, item, 2 );
  2066. } else {
  2067. pos = (int)(temp - item);
  2068. strncpy( irqbuf, item, pos );
  2069. irqbuf[pos] = 0;
  2070. }
  2071. irq_edt.Clear_Focus();
  2072. #endif //WIN32
  2073. } else {
  2074. if (port_index == port_custom_index) {
  2075. /*
  2076. ** This is the custom entry
  2077. */
  2078. temp = strchr( item, '-' );
  2079. if ( temp ) {
  2080. pos = (int)(temp - item) + 2;
  2081. if ( *(item + pos) == '?' ) {
  2082. portbuf[0] = 0;
  2083. } else {
  2084. strncpy( portbuf, item + pos, PORTBUF_MAX );
  2085. }
  2086. }
  2087. port_edt.Set_Focus();
  2088. } else {
  2089. /*
  2090. ** Must be a modem name entry so just copy iy
  2091. */
  2092. strncpy (portbuf, item, PORTBUF_MAX);
  2093. }
  2094. }
  2095. port_edt.Set_Text( portbuf, PORTBUF_MAX );
  2096. } else if (port_index < port_custom_index) {
  2097. port_edt.Clear_Focus();
  2098. } else {
  2099. port_edt.Set_Focus();
  2100. }
  2101. display = REDRAW_BUTTONS;
  2102. break;
  2103. #ifndef WIN32
  2104. case (BUTTON_IRQ | KN_BUTTON):
  2105. item = (char *)irqlist.Current_Item();
  2106. if (irq_index < 4) {
  2107. temp = strchr( item, ' ' );
  2108. if ( !temp ) {
  2109. strncpy( irqbuf, item, IRQBUF_MAX );
  2110. } else {
  2111. pos = (int)(temp - item);
  2112. strncpy( irqbuf, item, pos );
  2113. irqbuf[pos] = 0;
  2114. }
  2115. irq_edt.Set_Text( irqbuf, IRQBUF_MAX );
  2116. irq_edt.Flag_To_Redraw();
  2117. } else {
  2118. temp = strchr( item, '-' );
  2119. if ( temp ) {
  2120. pos = (int)(temp - item) + 2;
  2121. len = strlen( irqbuf );
  2122. strncpy( item + pos, irqbuf, len );
  2123. *(item + pos + len) = 0;
  2124. display = REDRAW_BUTTONS;
  2125. }
  2126. }
  2127. baud_edt.Set_Focus();
  2128. baud_edt.Flag_To_Redraw();
  2129. break;
  2130. case (BUTTON_IRQLIST | KN_BUTTON):
  2131. if (irqlist.Current_Index() != irq_index) {
  2132. irq_index = irqlist.Current_Index();
  2133. item = (char *)irqlist.Current_Item();
  2134. if (irq_index < 4) {
  2135. temp = strchr( item, ' ' );
  2136. if ( !temp ) {
  2137. strncpy( irqbuf, item, IRQBUF_MAX );
  2138. } else {
  2139. pos = (int)(temp - item);
  2140. strncpy( irqbuf, item, pos );
  2141. irqbuf[pos] = 0;
  2142. }
  2143. irq_edt.Clear_Focus();
  2144. } else {
  2145. temp = strchr( item, '-' );
  2146. if ( temp ) {
  2147. pos = (int)(temp - item) + 2;
  2148. if ( *(item + pos) == '?' ) {
  2149. irqbuf[0] = 0;
  2150. } else {
  2151. strncpy( irqbuf, item + pos, IRQBUF_MAX );
  2152. }
  2153. }
  2154. irq_edt.Set_Focus();
  2155. }
  2156. irq_edt.Set_Text( irqbuf, IRQBUF_MAX );
  2157. } else if (irq_index < 4) {
  2158. irq_edt.Clear_Focus();
  2159. } else {
  2160. irq_edt.Set_Focus();
  2161. }
  2162. display = REDRAW_BUTTONS;
  2163. break;
  2164. #endif //WIN32
  2165. case (BUTTON_BAUD | KN_BUTTON):
  2166. item = (char *)baudlist.Current_Item();
  2167. strncpy( baudbuf, item, BAUDBUF_MAX );
  2168. baud_edt.Set_Text( baudbuf, BAUDBUF_MAX );
  2169. initstr_edt.Set_Focus();
  2170. initstr_edt.Flag_To_Redraw();
  2171. display = REDRAW_BUTTONS;
  2172. break;
  2173. case (BUTTON_BAUDLIST | KN_BUTTON):
  2174. if (baudlist.Current_Index() != baud_index) {
  2175. baud_index = baudlist.Current_Index();
  2176. item = (char *)baudlist.Current_Item();
  2177. strncpy( baudbuf, item, BAUDBUF_MAX );
  2178. baud_edt.Set_Text( baudbuf, BAUDBUF_MAX );
  2179. baud_edt.Clear_Focus();
  2180. display = REDRAW_BUTTONS;
  2181. }
  2182. break;
  2183. #if 0
  2184. case (BUTTON_INITSTR | KN_BUTTON):
  2185. strupr( initstrbuf );
  2186. strncpy( Session.InitStrings[ initstr_index ], initstrbuf, INITSTRBUF_MAX );
  2187. Build_Init_String_Listbox(&initstrlist, &initstr_edt, initstrbuf,
  2188. &initstr_index);
  2189. cwaitstr_edt.Set_Focus();
  2190. cwaitstr_edt.Flag_To_Redraw();
  2191. display = REDRAW_BUTTONS;
  2192. break;
  2193. #endif
  2194. case (BUTTON_INITSTRLIST | KN_BUTTON):
  2195. if (initstrlist.Current_Index() != initstr_index) {
  2196. initstr_index = initstrlist.Current_Index();
  2197. item = (char *)initstrlist.Current_Item();
  2198. strncpy( initstrbuf, item, INITSTRBUF_MAX );
  2199. initstr_edt.Set_Text( initstrbuf, INITSTRBUF_MAX );
  2200. }
  2201. initstr_edt.Set_Focus();
  2202. initstr_edt.Flag_To_Redraw();
  2203. display = REDRAW_BUTTONS;
  2204. break;
  2205. /*
  2206. ** Add a new InitString entry
  2207. */
  2208. case (BUTTON_ADD | KN_BUTTON):
  2209. item = new char[ INITSTRBUF_MAX ];
  2210. memset (item, 0, INITSTRBUF_MAX);
  2211. strupr ( initstrbuf );
  2212. strncpy ( item, initstrbuf, INITSTRBUF_MAX-1 );
  2213. Session.InitStrings.Add ( item );
  2214. Build_Init_String_Listbox (&initstrlist, &initstr_edt, initstrbuf,
  2215. &initstr_index);
  2216. /*............................................................
  2217. Set the current listbox index to the newly-added item.
  2218. ............................................................*/
  2219. for (i = 0; i < Session.InitStrings.Count(); i++) {
  2220. if (item == Session.InitStrings[i]) {
  2221. initstr_index = i;
  2222. strcpy( initstrbuf, Session.InitStrings[ initstr_index ] );
  2223. initstr_edt.Set_Text( initstrbuf, INITSTRBUF_MAX );
  2224. initstrlist.Set_Selected_Index( initstr_index );
  2225. }
  2226. }
  2227. initstr_edt.Set_Focus();
  2228. initstr_edt.Flag_To_Redraw();
  2229. display = REDRAW_BUTTONS;
  2230. break;
  2231. /*------------------------------------------------------------------
  2232. Delete the current InitString entry
  2233. ------------------------------------------------------------------*/
  2234. case (BUTTON_DELETE | KN_BUTTON):
  2235. if ( Session.InitStrings.Count() && initstr_index != -1) {
  2236. Session.InitStrings.Delete( initstr_index );
  2237. Build_Init_String_Listbox(&initstrlist, &initstr_edt, initstrbuf,
  2238. &initstr_index);
  2239. }
  2240. break;
  2241. case (BUTTON_CWAITSTR | KN_BUTTON):
  2242. item = (char *)cwaitstrlist.Current_Item();
  2243. if (cwaitstr_index < 3) {
  2244. } else {
  2245. temp = strchr( item, '-' );
  2246. if ( temp ) {
  2247. pos = (int)(temp - item) + 2;
  2248. len = strlen( cwaitstrbuf );
  2249. strncpy( item + pos, cwaitstrbuf, len );
  2250. *(item + pos + len) = 0;
  2251. display = REDRAW_BUTTONS;
  2252. }
  2253. }
  2254. break;
  2255. case (BUTTON_CWAITSTRLIST | KN_BUTTON):
  2256. if (cwaitstrlist.Current_Index() != cwaitstr_index) {
  2257. cwaitstr_index = cwaitstrlist.Current_Index();
  2258. item = (char *)cwaitstrlist.Current_Item();
  2259. if (cwaitstr_index < 3) {
  2260. strncpy( cwaitstrbuf, item, CWAITSTRBUF_MAX );
  2261. cwaitstr_edt.Clear_Focus();
  2262. } else {
  2263. temp = strchr( item, '-' );
  2264. if ( temp ) {
  2265. pos = (int)(temp - item) + 2;
  2266. strncpy( cwaitstrbuf, item + pos, CWAITSTRBUF_MAX );
  2267. }
  2268. cwaitstr_edt.Set_Focus();
  2269. }
  2270. cwaitstr_edt.Set_Text( cwaitstrbuf, CWAITSTRBUF_MAX );
  2271. } else if (cwaitstr_index < 3) {
  2272. cwaitstr_edt.Clear_Focus();
  2273. } else {
  2274. cwaitstr_edt.Set_Focus();
  2275. }
  2276. display = REDRAW_BUTTONS;
  2277. break;
  2278. case (BUTTON_TONE | KN_BUTTON):
  2279. tempsettings.DialMethod = DIAL_TOUCH_TONE;
  2280. tonebtn.Turn_On();
  2281. pulsebtn.Turn_Off();
  2282. break;
  2283. case (BUTTON_PULSE | KN_BUTTON):
  2284. tempsettings.DialMethod = DIAL_PULSE;
  2285. tonebtn.Turn_Off();
  2286. pulsebtn.Turn_On();
  2287. break;
  2288. /*------------------------------------------------------------------
  2289. SAVE: save the com settings
  2290. ------------------------------------------------------------------*/
  2291. case (KN_RETURN):
  2292. case (BUTTON_SAVE | KN_BUTTON):
  2293. switch (port_index) {
  2294. case ( 0 ):
  2295. tempsettings.Port = 0x3f8;
  2296. tempsettings.ModemName[0] = 0;
  2297. break;
  2298. case ( 1 ):
  2299. tempsettings.Port = 0x2f8;
  2300. tempsettings.ModemName[0] = 0;
  2301. break;
  2302. case ( 2 ):
  2303. tempsettings.Port = 0x3e8;
  2304. tempsettings.ModemName[0] = 0;
  2305. break;
  2306. case ( 3 ):
  2307. tempsettings.Port = 0x2e8;
  2308. tempsettings.ModemName[0] = 0;
  2309. break;
  2310. default:
  2311. if (port_index == port_custom_index) {
  2312. #ifdef WIN32
  2313. strncpy ( tempsettings.ModemName, portbuf, MODEM_NAME_MAX );
  2314. tempsettings.Port = 1;
  2315. #else //WIN32
  2316. sscanf( portbuf, "%x", &tempsettings.Port );
  2317. tempsettings.ModemName[0] = 0;
  2318. #endif //WIN32
  2319. } else {
  2320. /*
  2321. ** Must be a modem name index
  2322. */
  2323. strcpy (tempsettings.ModemName, portlist.Current_Item());
  2324. tempsettings.Port = 1;
  2325. }
  2326. break;
  2327. }
  2328. #ifndef WIN32
  2329. switch (irq_index) {
  2330. case ( 0 ):
  2331. tempsettings.IRQ = 2;
  2332. break;
  2333. case ( 1 ):
  2334. tempsettings.IRQ = 3;
  2335. break;
  2336. case ( 2 ):
  2337. tempsettings.IRQ = 4;
  2338. break;
  2339. case ( 3 ):
  2340. tempsettings.IRQ = 5;
  2341. break;
  2342. default:
  2343. sscanf( irqbuf, "%d", &tempsettings.IRQ );
  2344. break;
  2345. }
  2346. #endif //WIN32
  2347. sscanf( baudbuf, "%d", &tempsettings.Baud );
  2348. tempsettings.InitStringIndex = initstr_index;
  2349. tempsettings.CallWaitStringIndex = cwaitstr_index;
  2350. item = Session.CallWaitStrings[ CALL_WAIT_CUSTOM ];
  2351. temp = strchr( item, '-' );
  2352. if ( temp ) {
  2353. pos = (int)(temp - item) + 2;
  2354. strncpy( cwaitstrbuf, item + pos, CWAITSTRBUF_MAX );
  2355. } else {
  2356. cwaitstrbuf[ 0 ] = 0;
  2357. }
  2358. strncpy( tempsettings.CallWaitString, cwaitstrbuf, CWAITSTRBUF_MAX );
  2359. dpstatus = NullModem.Detect_Port( &tempsettings );
  2360. if (dpstatus == PORT_VALID) {
  2361. process = false;
  2362. rc = true;
  2363. } else if (dpstatus == PORT_INVALID) {
  2364. #ifdef WIN32
  2365. WWMessageBox().Process( TXT_UNABLE_TO_OPEN_PORT );
  2366. #else //WIN32
  2367. WWMessageBox().Process( TXT_INVALID_SETTINGS );
  2368. #endif //WIN32
  2369. firsttime = true;
  2370. display = REDRAW_ALL;
  2371. } else if (dpstatus == PORT_IRQ_INUSE) {
  2372. WWMessageBox().Process( TXT_IRQ_ALREADY_IN_USE );
  2373. firsttime = true;
  2374. display = REDRAW_ALL;
  2375. }
  2376. break;
  2377. /*------------------------------------------------------------------
  2378. CANCEL: send a SIGN_OFF, bail out with error code
  2379. ------------------------------------------------------------------*/
  2380. case (KN_ESC):
  2381. case (BUTTON_CANCEL | KN_BUTTON):
  2382. process = false;
  2383. rc = false;
  2384. break;
  2385. }
  2386. } /* end of while */
  2387. /*------------------------------------------------------------------------
  2388. Restore screen
  2389. ------------------------------------------------------------------------*/
  2390. Hide_Mouse();
  2391. Load_Title_Page(true);
  2392. Show_Mouse();
  2393. /*------------------------------------------------------------------------
  2394. Save values into the Settings structure
  2395. ------------------------------------------------------------------------*/
  2396. if (rc) {
  2397. memcpy( settings, &tempsettings, sizeof(SerialSettingsType) );
  2398. }
  2399. return(rc);
  2400. } /* end of Com_Settings_Dialog */
  2401. /***************************************************************************
  2402. * Build_Init_String_Listbox -- [re]builds the initstring listbox *
  2403. * *
  2404. * This routine rebuilds the initstring list box from scratch; it also *
  2405. * updates the contents of the initstring edit field. *
  2406. * *
  2407. * INPUT: *
  2408. * list ptr to list box *
  2409. * edit ptr to edit box *
  2410. * buf ptr to buffer for initstring *
  2411. * *
  2412. * OUTPUT: *
  2413. * none. *
  2414. * *
  2415. * WARNINGS: *
  2416. * none. *
  2417. * *
  2418. * HISTORY: *
  2419. * 06/08/1995 DRD : Created. *
  2420. *=========================================================================*/
  2421. static void Build_Init_String_Listbox (ListClass *list, EditClass *edit, char *buf, int *index)
  2422. {
  2423. int i, curidx;
  2424. char *item;
  2425. curidx = *index;
  2426. /*........................................................................
  2427. Clear the list
  2428. ........................................................................*/
  2429. while (list->Count()) {
  2430. item = (char *)(list->Get_Item(0));
  2431. list->Remove_Item(item);
  2432. delete [] item;
  2433. }
  2434. /*
  2435. ** Now sort the init string list by name then number
  2436. */
  2437. qsort ((void *)(&Session.InitStrings[0]), Session.InitStrings.Count(), sizeof(char *), Init_String_Compare);
  2438. /*........................................................................
  2439. Build the list
  2440. ........................................................................*/
  2441. for (i = 0; i < Session.InitStrings.Count(); i++) {
  2442. item = new char[ INITSTRBUF_MAX ];
  2443. strcpy( item, Session.InitStrings[i] );
  2444. list->Add_Item(item);
  2445. }
  2446. list->Flag_To_Redraw();
  2447. /*........................................................................
  2448. Init the current phone book index
  2449. ........................................................................*/
  2450. if (list->Count() == 0 || curidx < -1) {
  2451. curidx = -1;
  2452. } else if (curidx >= list->Count() ) {
  2453. curidx = 0;
  2454. }
  2455. /*........................................................................
  2456. Fill in initstring edit buffer
  2457. ........................................................................*/
  2458. if (curidx > -1) {
  2459. strcpy (buf, Session.InitStrings[ curidx ]);
  2460. edit->Set_Text (buf, INITSTRBUF_MAX );
  2461. list->Set_Selected_Index( curidx );
  2462. }
  2463. *index = curidx;
  2464. }
  2465. /***************************************************************************
  2466. * Init_String_Compare -- for qsort *
  2467. * *
  2468. * INPUT: *
  2469. * p1,p2 ptrs to elements to compare *
  2470. * *
  2471. * OUTPUT: *
  2472. * 0 = same, -1 = (*p1) goes BEFORE (*p2), 1 = (*p1) goes AFTER (*p2) *
  2473. * *
  2474. * WARNINGS: *
  2475. * none. *
  2476. * *
  2477. * HISTORY: *
  2478. * 06/08/1995 DRD : Created. *
  2479. *=========================================================================*/
  2480. static int Init_String_Compare (const void *p1, const void *p2)
  2481. {
  2482. return( strcmp( *((char **)p1), *((char **)p2) ) );
  2483. }
  2484. /***********************************************************************************************
  2485. * Com_Scenario_Dialog -- Serial game scenario selection dialog *
  2486. * *
  2487. * *
  2488. * INPUT: *
  2489. * none. *
  2490. * *
  2491. * OUTPUT: *
  2492. * true = success, false = cancel *
  2493. * *
  2494. * WARNINGS: *
  2495. * none. *
  2496. * *
  2497. * HISTORY: *
  2498. * 02/14/1995 BR : Created.
  2499. * 01/21/97 V.Grippi added check for CS before sending scenario file *
  2500. *=============================================================================================*/
  2501. int Com_Scenario_Dialog(bool skirmish)
  2502. {
  2503. /*........................................................................
  2504. Dialog & button dimensions
  2505. ........................................................................*/
  2506. int d_dialog_w = 320 * RESFACTOR; // dialog width
  2507. int d_dialog_h = 200 * RESFACTOR; // dialog height
  2508. int d_dialog_x = ((320 * RESFACTOR - d_dialog_w) / 2); // dialog x-coord
  2509. int d_dialog_y = ((200 * RESFACTOR - d_dialog_h) / 2); // dialog y-coord
  2510. int d_dialog_cx = d_dialog_x + (d_dialog_w / 2); // center x-coord
  2511. int d_txt6_h = 6 * RESFACTOR+1; // ht of 6-pt text
  2512. int d_margin1 = 5 * RESFACTOR; // margin width/height
  2513. int d_margin2 = 7 * RESFACTOR; // margin width/height
  2514. int d_name_w = 70 * RESFACTOR;
  2515. int d_name_h = 9 * RESFACTOR;
  2516. int d_name_x = d_dialog_x + (d_dialog_w / 4) - (d_name_w / 2);
  2517. int d_name_y = d_dialog_y + d_margin2 + d_txt6_h + 1 * RESFACTOR;
  2518. #ifdef OLDWAY
  2519. int d_gdi_w = 40 * RESFACTOR;
  2520. int d_gdi_h = 9 * RESFACTOR;
  2521. int d_gdi_x = d_dialog_cx - d_gdi_w;
  2522. int d_gdi_y = d_name_y;
  2523. int d_nod_w = 40 * RESFACTOR;
  2524. int d_nod_h = 9 * RESFACTOR;
  2525. int d_nod_x = d_dialog_cx;
  2526. int d_nod_y = d_name_y;
  2527. #else
  2528. int d_house_w = 60 *RESFACTOR;
  2529. int d_house_h = (8 * 5 *RESFACTOR);
  2530. int d_house_x = d_dialog_cx - (d_house_w / 2);
  2531. int d_house_y = d_name_y;
  2532. #endif
  2533. int d_color_w = 10 * RESFACTOR;
  2534. int d_color_h = 9 * RESFACTOR;
  2535. int d_color_y = d_name_y;
  2536. int d_color_x = d_dialog_x + ((d_dialog_w / 4) * 3) - (d_color_w * 3);
  2537. int d_playerlist_w = 118 * RESFACTOR;
  2538. int d_playerlist_h = (6 * 6 * RESFACTOR) + 3 * RESFACTOR; // 6 rows high
  2539. int d_playerlist_x = d_dialog_x + d_margin1 + d_margin1 + 5*RESFACTOR;
  2540. int d_playerlist_y = d_color_y + d_color_h + d_margin2 + 2*RESFACTOR/*KO + d_txt6_h*/;
  2541. int d_scenariolist_w = 162 * RESFACTOR;
  2542. int d_scenariolist_h = (6 * 6 * RESFACTOR) + 3 * RESFACTOR; // 6 rows high
  2543. if (skirmish) {
  2544. d_scenariolist_h *= 2;
  2545. }
  2546. int d_scenariolist_x = d_dialog_x + d_dialog_w - d_margin1 - d_margin1 - d_scenariolist_w - 5*RESFACTOR;
  2547. int d_scenariolist_y = d_color_y + d_color_h + d_margin2 + 2*RESFACTOR;
  2548. if (skirmish) {
  2549. d_scenariolist_x = d_dialog_x + (d_dialog_w-d_scenariolist_w)/2;
  2550. }
  2551. int d_count_w = 25 * RESFACTOR;
  2552. int d_count_h = d_txt6_h;
  2553. int d_count_x = d_playerlist_x + (d_playerlist_w / 2) + 20 * RESFACTOR; // (fudged)
  2554. int d_count_y = d_playerlist_y + d_playerlist_h + (d_margin1 * 2) - 2 * RESFACTOR;
  2555. if (skirmish) {
  2556. d_count_y = d_scenariolist_y + d_scenariolist_h + d_margin1 - 2*RESFACTOR;
  2557. }
  2558. int d_level_w = 25 * RESFACTOR;
  2559. int d_level_h = d_txt6_h;
  2560. int d_level_x = d_playerlist_x + (d_playerlist_w / 2) + 20 * RESFACTOR; // (fudged)
  2561. int d_level_y = d_count_y + d_count_h;
  2562. int d_credits_w = 25 * RESFACTOR;
  2563. int d_credits_h = d_txt6_h;
  2564. int d_credits_x = d_playerlist_x + (d_playerlist_w / 2) + 20 * RESFACTOR; // (fudged)
  2565. int d_credits_y = d_level_y + d_level_h;
  2566. int d_aiplayers_w = 25*RESFACTOR;
  2567. int d_aiplayers_h = d_txt6_h;
  2568. int d_aiplayers_x = d_playerlist_x + (d_playerlist_w / 2) + 20*RESFACTOR; // (fudged)
  2569. int d_aiplayers_y = d_credits_y + d_credits_h;
  2570. int d_options_w = 106 * RESFACTOR;
  2571. int d_options_h = (5 * 6* RESFACTOR) + 4*RESFACTOR;
  2572. int d_options_x = d_dialog_x + d_dialog_w - 149 * RESFACTOR;
  2573. int d_options_y = d_scenariolist_y + d_scenariolist_h + d_margin1 - 2*RESFACTOR;
  2574. int d_message_w = d_dialog_w - (d_margin1 * 2) - 20*RESFACTOR;
  2575. int d_message_h = (8 * d_txt6_h) + 3 * RESFACTOR; // 4 rows high
  2576. int d_message_x = d_dialog_x + d_margin1 + 10*RESFACTOR;
  2577. int d_message_y = d_options_y + d_options_h + 2*RESFACTOR;
  2578. int d_send_w = d_dialog_w - (d_margin1 * 2) - 20*RESFACTOR;
  2579. int d_send_h = 9 * RESFACTOR;
  2580. int d_send_x = d_dialog_x + d_margin1 + 10*RESFACTOR;
  2581. int d_send_y = d_message_y + d_message_h;
  2582. int d_ok_w = 45 * RESFACTOR;
  2583. int d_ok_h = 9 * RESFACTOR;
  2584. int d_ok_x = d_dialog_x + (d_dialog_w / 6) - (d_ok_w / 2);
  2585. int d_ok_y = d_dialog_y + d_dialog_h - d_ok_h - d_margin1 - RESFACTOR*6;
  2586. int d_cancel_w = 45 * RESFACTOR;
  2587. int d_cancel_h = 9 * RESFACTOR;
  2588. int d_cancel_x = d_dialog_cx - (d_cancel_w / 2);
  2589. int d_cancel_y = d_dialog_y + d_dialog_h - d_cancel_h - d_margin1 - RESFACTOR*6;
  2590. int d_load_w = 45 * RESFACTOR;
  2591. int d_load_h = 9 * RESFACTOR;
  2592. int d_load_x = d_dialog_x + ((d_dialog_w * 5) / 6) - (d_load_w / 2);
  2593. int d_load_y = d_dialog_y + d_dialog_h - d_load_h - d_margin1 - RESFACTOR*6;
  2594. /*........................................................................
  2595. Button Enumerations
  2596. ........................................................................*/
  2597. enum {
  2598. BUTTON_NAME = 100,
  2599. #ifdef OLDWAY
  2600. BUTTON_GDI,
  2601. BUTTON_NOD,
  2602. #else
  2603. BUTTON_HOUSE,
  2604. #endif
  2605. BUTTON_CREDITS,
  2606. BUTTON_AIPLAYERS,
  2607. BUTTON_OPTIONS,
  2608. BUTTON_PLAYERLIST,
  2609. BUTTON_SCENARIOLIST,
  2610. BUTTON_COUNT,
  2611. BUTTON_LEVEL,
  2612. BUTTON_OK,
  2613. BUTTON_LOAD,
  2614. BUTTON_CANCEL,
  2615. BUTTON_DIFFICULTY,
  2616. };
  2617. /*........................................................................
  2618. Redraw values: in order from "top" to "bottom" layer of the dialog
  2619. ........................................................................*/
  2620. typedef enum {
  2621. REDRAW_NONE = 0,
  2622. REDRAW_PARMS,
  2623. REDRAW_MESSAGE,
  2624. REDRAW_COLORS,
  2625. REDRAW_BUTTONS,
  2626. REDRAW_BACKGROUND,
  2627. REDRAW_ALL = REDRAW_BACKGROUND
  2628. } RedrawType;
  2629. /*........................................................................
  2630. Dialog variables
  2631. ........................................................................*/
  2632. RedrawType display = REDRAW_ALL; // redraw level
  2633. bool process = true; // process while true
  2634. KeyNumType input;
  2635. int playertabs[] = {77*RESFACTOR}; // tabs for player list box
  2636. int optiontabs[] = {8}; // tabs for player list box
  2637. char namebuf[MPLAYER_NAME_MAX] = {0}; // buffer for player's name
  2638. bool transmit; // 1 = re-transmit new game options
  2639. int cbox_x[] = {
  2640. d_color_x,
  2641. d_color_x + d_color_w,
  2642. d_color_x + (d_color_w * 2),
  2643. d_color_x + (d_color_w * 3),
  2644. d_color_x + (d_color_w * 4),
  2645. d_color_x + (d_color_w * 5),
  2646. d_color_x + (d_color_w * 6),
  2647. d_color_x + (d_color_w * 7)
  2648. };
  2649. bool parms_received = false; // 1 = game options received
  2650. bool changed = false; // 1 = user has changed an option
  2651. int rc;
  2652. int recsignedoff = false;
  2653. int i;
  2654. unsigned long version;
  2655. unsigned long starttime;
  2656. unsigned long timingtime;
  2657. unsigned long lastmsgtime;
  2658. unsigned long lastredrawtime;
  2659. unsigned long transmittime = 0;
  2660. unsigned long theirresponsetime;
  2661. int packetlen;
  2662. static bool first_time = true;
  2663. bool oppscorescreen = false;
  2664. bool gameoptions = Session.Type == GAME_SKIRMISH;
  2665. EventClass *event; // event ptr
  2666. unsigned long msg_timeout = 1200; // init to 20 seconds
  2667. CCFileClass loadfile ("SAVEGAME.NET");
  2668. bool load_game = false; // 1 = load a saved game
  2669. NodeNameType *who; // node to add to Players
  2670. char *item; // for filling in lists
  2671. RemapControlType * scheme = GadgetClass::Get_Color_Scheme();
  2672. bool messages_have_focus = true; // Gadget focus starts on the message system
  2673. Set_Logic_Page(SeenBuff);
  2674. CDTimerClass<SystemTimerClass> kludge_timer; // Timer to allow a wait after client joins
  2675. // game before game can start
  2676. bool ok_button_added = false;
  2677. /*........................................................................
  2678. Buttons
  2679. ........................................................................*/
  2680. GadgetClass * commands; // button list
  2681. EditClass name_edt(BUTTON_NAME, namebuf, MPLAYER_NAME_MAX, TPF_TEXT, d_name_x, d_name_y, d_name_w, d_name_h, EditClass::ALPHANUMERIC);
  2682. #ifdef OLDWAY
  2683. TextButtonClass gdibtn(BUTTON_GDI, TXT_ALLIES, TPF_BUTTON, d_gdi_x, d_gdi_y, d_gdi_w, d_gdi_h);
  2684. TextButtonClass nodbtn(BUTTON_NOD, TXT_SOVIET, TPF_BUTTON, d_nod_x, d_nod_y, d_nod_w, d_nod_h);
  2685. #else
  2686. char housetext[25] = "";
  2687. Fancy_Text_Print("", 0, 0, 0, 0, TPF_TEXT);
  2688. DropListClass housebtn(BUTTON_HOUSE, housetext, sizeof(housetext),
  2689. TPF_TEXT,
  2690. d_house_x, d_house_y, d_house_w, d_house_h,
  2691. MFCD::Retrieve("BTN-UP.SHP"),
  2692. MFCD::Retrieve("BTN-DN.SHP"));
  2693. #endif
  2694. ColorListClass playerlist(BUTTON_PLAYERLIST, d_playerlist_x, d_playerlist_y, d_playerlist_w, d_playerlist_h, TPF_TEXT, MFCD::Retrieve("BTN-UP.SHP"), MFCD::Retrieve("BTN-DN.SHP"));
  2695. ListClass scenariolist(BUTTON_SCENARIOLIST, d_scenariolist_x, d_scenariolist_y, d_scenariolist_w, d_scenariolist_h, TPF_TEXT, MFCD::Retrieve("BTN-UP.SHP"), MFCD::Retrieve("BTN-DN.SHP"));
  2696. GaugeClass countgauge(BUTTON_COUNT, d_count_x, d_count_y, d_count_w, d_count_h);
  2697. char staticcountbuff[35];
  2698. StaticButtonClass staticcount(0, " ", TPF_TEXT, d_count_x+d_count_w+3*RESFACTOR, d_count_y);
  2699. GaugeClass levelgauge(BUTTON_LEVEL, d_level_x, d_level_y, d_level_w, d_level_h);
  2700. char staticlevelbuff[35];
  2701. StaticButtonClass staticlevel(0, " ", TPF_TEXT, d_level_x+d_level_w+3*RESFACTOR, d_level_y);
  2702. GaugeClass creditsgauge(BUTTON_CREDITS, d_credits_x, d_credits_y, d_credits_w, d_credits_h);
  2703. char staticcreditsbuff[35];
  2704. StaticButtonClass staticcredits(0, " ", TPF_TEXT, d_credits_x+d_credits_w+3*RESFACTOR, d_credits_y);
  2705. GaugeClass aiplayersgauge(BUTTON_AIPLAYERS, d_aiplayers_x, d_aiplayers_y, d_aiplayers_w, d_aiplayers_h);
  2706. char staticaibuff[35];
  2707. StaticButtonClass staticai(0, " ", TPF_TEXT, d_aiplayers_x+d_aiplayers_w+3*RESFACTOR, d_aiplayers_y);
  2708. CheckListClass optionlist(BUTTON_OPTIONS, d_options_x, d_options_y, d_options_w, d_options_h, TPF_TEXT, MFCD::Retrieve("BTN-UP.SHP"), MFCD::Retrieve("BTN-DN.SHP"));
  2709. TextButtonClass okbtn(BUTTON_OK, TXT_OK, TPF_BUTTON, d_ok_x, d_ok_y, d_ok_w, d_ok_h);
  2710. TextButtonClass loadbtn(BUTTON_LOAD, TXT_LOAD_BUTTON, TPF_BUTTON, d_load_x, d_load_y, d_load_w, d_load_h);
  2711. TextButtonClass cancelbtn(BUTTON_CANCEL, TXT_CANCEL, TPF_BUTTON, d_cancel_x, d_cancel_y, d_cancel_w, d_cancel_h);
  2712. SliderClass difficulty(BUTTON_DIFFICULTY, d_name_x, optionlist.Y + optionlist.Height + d_margin1 + d_margin1, d_dialog_w - (d_name_x-d_dialog_x)*2, 8*RESFACTOR, true);
  2713. if (Rule.IsFineDifficulty) {
  2714. difficulty.Set_Maximum(5);
  2715. difficulty.Set_Value(2);
  2716. } else {
  2717. difficulty.Set_Maximum(3);
  2718. difficulty.Set_Value(1);
  2719. }
  2720. /*
  2721. ------------------------- Build the button list --------------------------
  2722. */
  2723. commands = &name_edt;
  2724. staticcount.Add_Tail(*commands);
  2725. staticcredits.Add_Tail(*commands);
  2726. staticai.Add_Tail(*commands);
  2727. staticlevel.Add_Tail(*commands);
  2728. if (!skirmish) {
  2729. playerlist.Add_Tail(*commands);
  2730. } else {
  2731. difficulty.Add_Tail(*commands);
  2732. }
  2733. scenariolist.Add_Tail(*commands);
  2734. countgauge.Add_Tail(*commands);
  2735. levelgauge.Add_Tail(*commands);
  2736. creditsgauge.Add_Tail(*commands);
  2737. aiplayersgauge.Add_Tail(*commands);
  2738. optionlist.Add_Tail(*commands);
  2739. if (Session.Type == GAME_SKIRMISH){
  2740. okbtn.Add_Tail(*commands);
  2741. }
  2742. cancelbtn.Add_Tail(*commands);
  2743. if (!skirmish && loadfile.Is_Available()) {
  2744. #ifdef FIXIT_MULTI_SAVE
  2745. //Load button added only when other player has arrived
  2746. //loadbtn.Add_Tail(*commands);
  2747. #endif
  2748. } else {
  2749. cancelbtn.X = loadbtn.X;
  2750. }
  2751. #ifdef OLDWAY
  2752. gdibtn.Add_Tail(*commands);
  2753. nodbtn.Add_Tail(*commands);
  2754. #else
  2755. housebtn.Add_Tail(*commands);
  2756. #endif
  2757. /*
  2758. ----------------------------- Various Inits ------------------------------
  2759. */
  2760. /*........................................................................
  2761. Init player name & house
  2762. ........................................................................*/
  2763. Session.ColorIdx = Session.PrefColor; // init my preferred color
  2764. strcpy (namebuf, Session.Handle); // set my name
  2765. name_edt.Set_Text(namebuf,MPLAYER_NAME_MAX);
  2766. name_edt.Set_Color(&ColorRemaps[(Session.ColorIdx == PCOLOR_DIALOG_BLUE) ? PCOLOR_REALLY_BLUE : Session.ColorIdx]);
  2767. #ifdef OLDWAY
  2768. if (Session.House==HOUSE_GOOD) {
  2769. gdibtn.Turn_On();
  2770. } else {
  2771. nodbtn.Turn_On();
  2772. }
  2773. #else
  2774. for (HousesType house = HOUSE_USSR; house <= HOUSE_FRANCE; house++) {
  2775. housebtn.Add_Item(Text_String(HouseTypeClass::As_Reference(house).Full_Name()));
  2776. }
  2777. housebtn.Set_Selected_Index(Session.House - HOUSE_USSR);
  2778. housebtn.Set_Read_Only (true);
  2779. #endif
  2780. /*........................................................................
  2781. Init scenario values, only the first time through
  2782. ........................................................................*/
  2783. Special.IsCaptureTheFlag = Rule.IsMPCaptureTheFlag;
  2784. if (first_time) {
  2785. Session.Options.Credits = Rule.MPDefaultMoney; // init credits & credit buffer
  2786. Session.Options.Bases = Rule.IsMPBasesOn; // init scenario parameters
  2787. Session.Options.Tiberium = Rule.IsMPTiberiumGrow;
  2788. Session.Options.Goodies = Rule.IsMPCrates;
  2789. Session.Options.AIPlayers = 0;
  2790. Special.IsShadowGrow = Rule.IsMPShadowGrow;
  2791. Session.Options.UnitCount = (SessionClass::CountMax[Session.Options.Bases] + SessionClass::CountMin[Session.Options.Bases]) / 2;
  2792. first_time = false;
  2793. }
  2794. /*........................................................................
  2795. Init button states
  2796. ........................................................................*/
  2797. playerlist.Set_Tabs(playertabs);
  2798. playerlist.Set_Selected_Style(ColorListClass::SELECT_NORMAL);
  2799. optionlist.Set_Tabs(optiontabs);
  2800. optionlist.Set_Read_Only(0);
  2801. optionlist.Add_Item(Text_String(TXT_BASES));
  2802. optionlist.Add_Item(Text_String(TXT_ORE_SPREADS));
  2803. optionlist.Add_Item(Text_String(TXT_CRATES));
  2804. optionlist.Add_Item(Text_String(TXT_SHADOW_REGROWS));
  2805. if (!skirmish) {
  2806. optionlist.Add_Item(Text_String(TXT_CAPTURE_THE_FLAG));
  2807. }
  2808. optionlist.Check_Item(0, Session.Options.Bases);
  2809. optionlist.Check_Item(1, Session.Options.Tiberium);
  2810. optionlist.Check_Item(2, Session.Options.Goodies);
  2811. optionlist.Check_Item(3, Special.IsShadowGrow);
  2812. if (!skirmish) {
  2813. optionlist.Check_Item(4, Special.IsCaptureTheFlag);
  2814. }
  2815. countgauge.Set_Maximum(SessionClass::CountMax[Session.Options.Bases] - SessionClass::CountMin[Session.Options.Bases]);
  2816. countgauge.Set_Value(Session.Options.UnitCount - SessionClass::CountMin[Session.Options.Bases]);
  2817. levelgauge.Set_Maximum(MPLAYER_BUILD_LEVEL_MAX - 1);
  2818. levelgauge.Set_Value(BuildLevel - 1);
  2819. creditsgauge.Set_Maximum(Rule.MPMaxMoney);
  2820. creditsgauge.Set_Value(Session.Options.Credits);
  2821. int maxp = Rule.MaxPlayers - 2;
  2822. // int maxp = Rule.MaxPlayers - (skirmish ? 1 : 2);
  2823. aiplayersgauge.Set_Maximum(maxp);
  2824. if (skirmish) {
  2825. if ( Session.Options.AIPlayers > 7 ) {
  2826. Session.Options.AIPlayers = 7;
  2827. }
  2828. Session.Options.AIPlayers = max(Session.Options.AIPlayers, 1);
  2829. }else{
  2830. if ( Session.Options.AIPlayers > 6 ) {
  2831. Session.Options.AIPlayers = 6;
  2832. }
  2833. }
  2834. aiplayersgauge.Set_Value(Session.Options.AIPlayers - (skirmish ? 1 : 0));
  2835. /*........................................................................
  2836. Init other scenario parameters
  2837. ........................................................................*/
  2838. Special.IsTGrowth = //Session.Options.Tiberium;
  2839. Rule.IsTGrowth = //Session.Options.Tiberium;
  2840. Special.IsTSpread = //Session.Options.Tiberium;
  2841. Rule.IsTSpread = Session.Options.Tiberium;
  2842. transmit = true;
  2843. /*........................................................................
  2844. Clear the Players vector
  2845. ........................................................................*/
  2846. Clear_Vector(&Session.Players);
  2847. /*........................................................................
  2848. Init scenario description list box
  2849. ........................................................................*/
  2850. for (i = 0; i < Session.Scenarios.Count(); i++) {
  2851. for (int j = 0; EngMisStr[j] != NULL; j++) {
  2852. if (!strcmp(Session.Scenarios[i]->Description(), EngMisStr[j])) {
  2853. #ifdef FIXIT_CSII // ajw Added Aftermath installed checks (before, it was assumed).
  2854. // Add mission if it's available to us.
  2855. if( !( ( Is_Mission_Counterstrike((char *)(Session.Scenarios[i]->Get_Filename())) && !Is_Counterstrike_Installed() ) ||
  2856. ( Is_Mission_Aftermath((char *)(Session.Scenarios[i]->Get_Filename())) && !Is_Aftermath_Installed() ) ) )
  2857. #endif
  2858. #if defined(GERMAN) || defined(FRENCH)
  2859. scenariolist.Add_Item(EngMisStr[j+1]);
  2860. #else
  2861. scenariolist.Add_Item(EngMisStr[j]);
  2862. #endif
  2863. break;
  2864. }
  2865. }
  2866. if (EngMisStr[j] == NULL) {
  2867. #ifdef FIXIT_CSII // ajw Added Aftermath installed checks (before, it was assumed). Added officialness check.
  2868. // Add mission if it's available to us.
  2869. if( !Session.Scenarios[i]->Get_Official() ||
  2870. !( ( Is_Mission_Counterstrike((char *)(Session.Scenarios[i]->Get_Filename())) && !Is_Counterstrike_Installed() ) ||
  2871. ( Is_Mission_Aftermath((char *)(Session.Scenarios[i]->Get_Filename())) && !Is_Aftermath_Installed() ) ) )
  2872. #endif
  2873. scenariolist.Add_Item(Session.Scenarios[i]->Description());
  2874. }
  2875. }
  2876. Session.Options.ScenarioIndex = 0; // 1st scenario is selected
  2877. /*........................................................................
  2878. Init random-number generator, & create a seed to be used for all random
  2879. numbers from here on out
  2880. ........................................................................*/
  2881. #ifdef FIXIT_RANDOM_GAME
  2882. srand(time(NULL));
  2883. Seed = rand();
  2884. #else
  2885. // randomize();
  2886. // Seed = rand();
  2887. #endif
  2888. /*........................................................................
  2889. Init the message display system
  2890. ........................................................................*/
  2891. if (!skirmish) {
  2892. Session.Messages.Init (d_message_x + 1, d_message_y + 1, 8,
  2893. MAX_MESSAGE_LENGTH, d_txt6_h, d_send_x + 1, d_send_y + 1, 1,
  2894. 20, MAX_MESSAGE_LENGTH - 5, d_message_w);
  2895. Session.Messages.Add_Edit ((Session.ColorIdx == PCOLOR_DIALOG_BLUE) ? PCOLOR_REALLY_BLUE : Session.ColorIdx,
  2896. TPF_TEXT, NULL, '_', d_message_w);
  2897. }
  2898. /*........................................................................
  2899. Init version number clipping system
  2900. ........................................................................*/
  2901. VerNum.Init_Clipping();
  2902. Load_Title_Page(true);
  2903. CCPalette.Set();
  2904. extern char ModemRXString[];
  2905. if (strlen(ModemRXString) > 36)
  2906. ModemRXString[36] = 0;
  2907. if (strlen(ModemRXString) > 0)
  2908. Session.Messages.Add_Message (NULL, 0, ModemRXString, PCOLOR_BROWN,
  2909. TPF_TEXT, -1);
  2910. ModemRXString[0] = '\0';
  2911. /*
  2912. ---------------------------- Init Mono Output ----------------------------
  2913. */
  2914. #if(SHOW_MONO)
  2915. if (!skirmish) {
  2916. NullModem.Configure_Debug(sizeof (CommHeaderType),sizeof (SerialCommandType),
  2917. SerialPacketNames, 100, 8);
  2918. NullModem.Mono_Debug_Print(1);
  2919. }
  2920. #endif
  2921. /*
  2922. ---------------------------- Processing loop -----------------------------
  2923. */
  2924. if (!skirmish) {
  2925. NullModem.Reset_Response_Time(); // clear response time
  2926. }
  2927. theirresponsetime = 10000; // initialize to an invalid value
  2928. timingtime = lastmsgtime = lastredrawtime = TickCount;
  2929. /*
  2930. ** Those easily offended should avert their eyes from the following line. And whatever
  2931. ** you do, dont search for 'goto'.
  2932. */
  2933. oh_dear_its_a_label:
  2934. while (process) {
  2935. #if(SHOW_MONO)
  2936. if (!skirmish) {
  2937. NullModem.Mono_Debug_Print(0);
  2938. }
  2939. #endif
  2940. if (!skirmish){
  2941. if (!ok_button_added && gameoptions && kludge_timer == 0){
  2942. okbtn.Add_Tail(*commands);
  2943. ok_button_added = true;
  2944. #ifdef FIXIT_VERSION_3
  2945. if( loadfile.Is_Available() )
  2946. {
  2947. loadbtn.Add_Tail( *commands );
  2948. }
  2949. #else
  2950. #ifdef FIXIT_MULTI_SAVE
  2951. if ( loadfile.Is_Available() && PlayingAgainstVersion > VERSION_RED_ALERT_104 ) {
  2952. loadbtn.Add_Tail ( *commands );
  2953. }
  2954. #endif
  2955. #endif
  2956. if (display < REDRAW_BUTTONS) display = REDRAW_BUTTONS;
  2957. }
  2958. }
  2959. /*
  2960. ** Kludge to make sure we redraw the message input line when it loses focus.
  2961. ** If we dont do this then the cursor doesnt disappear.
  2962. */
  2963. if (!skirmish) {
  2964. if (messages_have_focus) {
  2965. if (name_edt.Has_Focus()) {
  2966. if (display < REDRAW_MESSAGE) display = REDRAW_MESSAGE;
  2967. messages_have_focus = false;
  2968. }
  2969. } else {
  2970. if (!name_edt.Has_Focus()) {
  2971. messages_have_focus = true;
  2972. if (display < REDRAW_MESSAGE) display = REDRAW_MESSAGE;
  2973. Session.Messages.Set_Edit_Focus();
  2974. }
  2975. }
  2976. }
  2977. /*
  2978. ........................ Invoke game callback .........................
  2979. */
  2980. Call_Back();
  2981. #ifdef WIN32
  2982. /*
  2983. ** If we have just received input focus again after running in the background then
  2984. ** we need to redraw.
  2985. */
  2986. if (AllSurfaces.SurfacesRestored) {
  2987. AllSurfaces.SurfacesRestored=FALSE;
  2988. display = REDRAW_ALL;
  2989. }
  2990. #endif
  2991. /*
  2992. ...................... Refresh display if needed ......................
  2993. */
  2994. if (display) {
  2995. if (housebtn.IsDropped) {
  2996. housebtn.Collapse();
  2997. display = REDRAW_BACKGROUND;
  2998. }
  2999. Hide_Mouse();
  3000. /*
  3001. .................. Redraw backgound & dialog box ...................
  3002. */
  3003. if (display >= REDRAW_BACKGROUND) {
  3004. Dialog_Box(d_dialog_x, d_dialog_y, d_dialog_w, d_dialog_h);
  3005. // init font variables
  3006. Fancy_Text_Print(TXT_NONE, 0, 0, TBLACK, TBLACK, TPF_CENTER | TPF_TEXT);
  3007. /*...............................................................
  3008. Dialog & Field labels
  3009. ...............................................................*/
  3010. Fancy_Text_Print(TXT_YOUR_NAME, d_name_x + (d_name_w / 2), d_name_y - d_txt6_h, scheme, TBLACK, TPF_CENTER | TPF_TEXT);
  3011. #ifdef OLDWAY
  3012. Fancy_Text_Print(TXT_SIDE_COLON, d_gdi_x + d_gdi_w, d_gdi_y - d_txt6_h, scheme, TBLACK, TPF_CENTER | TPF_TEXT);
  3013. #else
  3014. Fancy_Text_Print(TXT_SIDE_COLON, d_house_x + (d_house_w / 2), d_house_y - d_txt6_h, scheme, TBLACK, TPF_CENTER | TPF_TEXT);
  3015. #endif
  3016. Fancy_Text_Print(TXT_COLOR_COLON, d_dialog_x + ((d_dialog_w / 4) * 3), d_color_y - d_txt6_h, scheme, TBLACK, TPF_CENTER | TPF_TEXT);
  3017. if (!skirmish) {
  3018. Fancy_Text_Print(TXT_PLAYERS, d_playerlist_x + (d_playerlist_w / 2), d_playerlist_y - d_txt6_h, scheme, TBLACK, TPF_CENTER | TPF_TEXT);
  3019. } else {
  3020. Fancy_Text_Print(TXT_EASY, difficulty.X, difficulty.Y-8*RESFACTOR, scheme, TBLACK, TPF_TEXT);
  3021. Fancy_Text_Print(TXT_HARD, difficulty.X + difficulty.Width, difficulty.Y-8*RESFACTOR, scheme, TBLACK, TPF_RIGHT|TPF_TEXT);
  3022. Fancy_Text_Print(TXT_NORMAL, difficulty.X + difficulty.Width/2, difficulty.Y-8*RESFACTOR, scheme, TBLACK, TPF_CENTER|TPF_TEXT);
  3023. }
  3024. Fancy_Text_Print(TXT_SCENARIOS, d_scenariolist_x + (d_scenariolist_w / 2), d_scenariolist_y - d_txt6_h, scheme, TBLACK, TPF_CENTER | TPF_TEXT);
  3025. Fancy_Text_Print(TXT_COUNT, d_count_x - 2, d_count_y, scheme, TBLACK, TPF_TEXT | TPF_RIGHT);
  3026. Fancy_Text_Print(TXT_LEVEL, d_level_x - 2, d_level_y, scheme, TBLACK, TPF_TEXT | TPF_RIGHT);
  3027. Fancy_Text_Print(TXT_CREDITS_COLON, d_credits_x - 2, d_credits_y, scheme, TBLACK, TPF_TEXT | TPF_RIGHT);
  3028. Fancy_Text_Print(TXT_AI_PLAYERS_COLON, d_aiplayers_x - 2*RESFACTOR, d_aiplayers_y, scheme, TBLACK, TPF_TEXT | TPF_RIGHT);
  3029. }
  3030. /*..................................................................
  3031. Draw the color boxes
  3032. ..................................................................*/
  3033. if (display >= REDRAW_COLORS) {
  3034. for (i = 0; i < MAX_MPLAYER_COLORS; i++) {
  3035. LogicPage->Fill_Rect (cbox_x[i] + 1, d_color_y + 1,
  3036. cbox_x[i] + 1 + d_color_w - 2, d_color_y + 1 + d_color_h - 2,
  3037. ColorRemaps[i].Box);
  3038. // (i == PCOLOR_DIALOG_BLUE) ? ColorRemaps[PCOLOR_REALLY_BLUE].Box : ColorRemaps[i].Box);
  3039. if (i == Session.ColorIdx) {
  3040. Draw_Box(cbox_x[i], d_color_y, d_color_w, d_color_h, BOXSTYLE_DOWN, false);
  3041. } else {
  3042. Draw_Box(cbox_x[i], d_color_y, d_color_w, d_color_h, BOXSTYLE_RAISED, false);
  3043. }
  3044. }
  3045. }
  3046. /*..................................................................
  3047. Draw the message system; erase old messages first
  3048. ..................................................................*/
  3049. if (display >= REDRAW_MESSAGE && !skirmish) {
  3050. Draw_Box(d_message_x, d_message_y, d_message_w, d_message_h, BOXSTYLE_BOX, true);
  3051. Draw_Box(d_send_x, d_send_y, d_send_w, d_send_h, BOXSTYLE_BOX, true);
  3052. Session.Messages.Draw();
  3053. }
  3054. //..................................................................
  3055. // Update game parameter labels
  3056. //..................................................................
  3057. if (display >= REDRAW_PARMS) {
  3058. // LogicPage->Fill_Rect(d_count_x + d_count_w + 2, d_count_y, d_count_x + d_count_w + 35 * RESFACTOR, d_aiplayers_y + d_aiplayers_h+RESFACTOR, BLACK);
  3059. sprintf(staticcountbuff, "%d", Session.Options.UnitCount);
  3060. staticcount.Set_Text(staticcountbuff);
  3061. staticcount.Draw_Me();
  3062. // Fancy_Text_Print("%d ", d_count_x + d_count_w + 3 * RESFACTOR, d_count_y, scheme, BLACK, TPF_TEXT, Session.Options.UnitCount);
  3063. if (BuildLevel <= MPLAYER_BUILD_LEVEL_MAX) {
  3064. sprintf(staticlevelbuff, "%d ", BuildLevel);
  3065. } else {
  3066. sprintf(staticlevelbuff, "**");
  3067. }
  3068. staticlevel.Set_Text(staticlevelbuff);
  3069. staticlevel.Draw_Me();
  3070. // Fancy_Text_Print(txt, d_level_x + d_level_w + 3 * RESFACTOR, d_level_y, scheme, BLACK, TPF_TEXT);
  3071. sprintf(staticcreditsbuff, "%d", Session.Options.Credits);
  3072. staticcredits.Set_Text(staticcreditsbuff);
  3073. staticcredits.Draw_Me();
  3074. // Fancy_Text_Print("%d", d_credits_x + d_credits_w + 2 * RESFACTOR, d_credits_y, scheme, BLACK, TPF_TEXT, Session.Options.Credits);
  3075. sprintf(staticaibuff, "%d", Session.Options.AIPlayers);
  3076. staticai.Set_Text(staticaibuff);
  3077. staticai.Draw_Me();
  3078. // Fancy_Text_Print("%d", d_aiplayers_x + d_aiplayers_w + 2*RESFACTOR, d_aiplayers_y, scheme, BLACK, TPF_TEXT, Session.Options.AIPlayers);
  3079. }
  3080. /*
  3081. .......................... Redraw buttons ..........................
  3082. */
  3083. if (display >= REDRAW_BUTTONS) {
  3084. commands->Flag_List_To_Redraw();
  3085. commands->Draw_All();
  3086. }
  3087. Show_Mouse();
  3088. display = REDRAW_NONE;
  3089. }
  3090. /*
  3091. ........................... Get user input ............................
  3092. */
  3093. messages_have_focus = Session.Messages.Has_Edit_Focus();
  3094. bool droplist_is_dropped = housebtn.IsDropped;
  3095. input = commands->Input();
  3096. /*
  3097. ** Sort out the input focus between the name edit box and the message system
  3098. */
  3099. if (!skirmish) {
  3100. if (messages_have_focus) {
  3101. if (!name_edt.Has_Focus()) {
  3102. Session.Messages.Set_Edit_Focus();
  3103. } else {
  3104. messages_have_focus = false;
  3105. display = REDRAW_MESSAGE;
  3106. }
  3107. }
  3108. }
  3109. /*
  3110. ** Redraw everything if the droplist collapsed
  3111. */
  3112. if (droplist_is_dropped && !housebtn.IsDropped) {
  3113. display = REDRAW_BACKGROUND;
  3114. }
  3115. if (input & KN_BUTTON) {
  3116. if (housebtn.IsDropped) {
  3117. housebtn.Collapse();
  3118. display = REDRAW_BACKGROUND;
  3119. }
  3120. }
  3121. /*
  3122. ---------------------------- Process input ----------------------------
  3123. */
  3124. switch (input) {
  3125. /*------------------------------------------------------------------
  3126. User clicks on a color button
  3127. ------------------------------------------------------------------*/
  3128. case KN_LMOUSE:
  3129. if (Keyboard->MouseQX > cbox_x[0] &&
  3130. Keyboard->MouseQX < (cbox_x[MAX_MPLAYER_COLORS - 1] + d_color_w) &&
  3131. Keyboard->MouseQY > d_color_y &&
  3132. Keyboard->MouseQY < (d_color_y + d_color_h)) {
  3133. Session.PrefColor = (PlayerColorType)((Keyboard->MouseQX - cbox_x[0]) / d_color_w);
  3134. Session.ColorIdx = Session.PrefColor;
  3135. if (display < REDRAW_COLORS) display = REDRAW_COLORS;
  3136. name_edt.Set_Color (&ColorRemaps[(Session.ColorIdx == PCOLOR_DIALOG_BLUE) ? PCOLOR_REALLY_BLUE : Session.ColorIdx]);
  3137. name_edt.Flag_To_Redraw();
  3138. Session.Messages.Set_Edit_Color((Session.ColorIdx == PCOLOR_DIALOG_BLUE) ? PCOLOR_REALLY_BLUE : Session.ColorIdx);
  3139. strcpy (Session.Handle, namebuf);
  3140. transmit = true;
  3141. changed = true;
  3142. if (housebtn.IsDropped) {
  3143. housebtn.Collapse();
  3144. display = REDRAW_BACKGROUND;
  3145. }
  3146. }
  3147. break;
  3148. /*------------------------------------------------------------------
  3149. User edits the name field; retransmit new game options
  3150. ------------------------------------------------------------------*/
  3151. case (BUTTON_NAME | KN_BUTTON):
  3152. if (housebtn.IsDropped) {
  3153. housebtn.Collapse();
  3154. display = REDRAW_BACKGROUND;
  3155. }
  3156. strcpy (Session.Handle, namebuf);
  3157. transmit = true;
  3158. changed = true;
  3159. break;
  3160. #ifdef OLDWAY
  3161. /*------------------------------------------------------------------
  3162. House Buttons: set the player's desired House
  3163. ------------------------------------------------------------------*/
  3164. case (BUTTON_GDI | KN_BUTTON):
  3165. Session.House = HOUSE_GOOD;
  3166. gdibtn.Turn_On();
  3167. nodbtn.Turn_Off();
  3168. strcpy (Session.Handle, namebuf);
  3169. transmit = true;
  3170. break;
  3171. case (BUTTON_NOD | KN_BUTTON):
  3172. Session.House = HOUSE_BAD;
  3173. gdibtn.Turn_Off();
  3174. nodbtn.Turn_On();
  3175. strcpy (Session.Handle, namebuf);
  3176. transmit = true;
  3177. break;
  3178. #else
  3179. case (BUTTON_HOUSE | KN_BUTTON):
  3180. Session.House = HousesType(housebtn.Current_Index()+HOUSE_USSR);
  3181. strcpy (Session.Handle, namebuf);
  3182. display = REDRAW_BACKGROUND;
  3183. transmit = true;
  3184. break;
  3185. #endif
  3186. /*------------------------------------------------------------------
  3187. New Scenario selected.
  3188. ------------------------------------------------------------------*/
  3189. #ifdef FIXIT_VERSION_3 // All scenarios now allowable as downloads. ajw
  3190. case (BUTTON_SCENARIOLIST | KN_BUTTON):
  3191. if (housebtn.IsDropped) {
  3192. housebtn.Collapse();
  3193. display = REDRAW_BACKGROUND;
  3194. }
  3195. if (scenariolist.Current_Index() != Session.Options.ScenarioIndex)
  3196. {
  3197. Session.Options.ScenarioIndex = scenariolist.Current_Index();
  3198. strcpy (Session.Handle, namebuf);
  3199. transmit = true;
  3200. }
  3201. break;
  3202. #else // FIXIT_VERSION_3 Whoever duplicated Netdlg into Nulldlg should be shot. Wasn't it enough?
  3203. Abandon all hope ye who hit enter here.
  3204. case (BUTTON_SCENARIOLIST | KN_BUTTON):
  3205. if (housebtn.IsDropped) {
  3206. housebtn.Collapse();
  3207. display = REDRAW_BACKGROUND;
  3208. }
  3209. if (scenariolist.Current_Index() != Session.Options.ScenarioIndex) {
  3210. #ifdef FIXIT_CSII // checked - ajw
  3211. if ( !skirmish && (PlayingAgainstVersion != VERSION_RED_ALERT_107 && PlayingAgainstVersion != VERSION_RED_ALERT_108 && PlayingAgainstVersion < VERSION_AFTERMATH_CS) &&
  3212. #else
  3213. if ( !skirmish && PlayingAgainstVersion < VERSION_RED_ALERT_107 &&
  3214. #endif
  3215. Session.Scenarios[scenariolist.Current_Index()]->Get_Expansion()){
  3216. scenariolist.Set_Selected_Index (Session.Options.ScenarioIndex);
  3217. Session.Messages.Add_Message(NULL, 0,
  3218. (char *)Text_String(TXT_NO_CS_SCENARIOS), PCOLOR_BROWN, TPF_TEXT, 1200);
  3219. Sound_Effect(VOC_SYS_ERROR);
  3220. if (display < REDRAW_MESSAGE) display = REDRAW_MESSAGE;
  3221. #ifdef FIXIT_CSII // checked - ajw
  3222. } else
  3223. if ( !skirmish && PlayingAgainstVersion < VERSION_AFTERMATH_CS &&
  3224. Is_Mission_126x126((char *)Session.Scenarios[scenariolist.Current_Index()]->Get_Filename() ) ){
  3225. scenariolist.Set_Selected_Index (Session.Options.ScenarioIndex);
  3226. Session.Messages.Add_Message(NULL, 0,
  3227. (char *)Text_String(TXT_NO_CS_SCENARIOS), PCOLOR_BROWN, TPF_TEXT, 1200);
  3228. Sound_Effect(VOC_SYS_ERROR);
  3229. if (display < REDRAW_MESSAGE) display = REDRAW_MESSAGE;
  3230. #endif
  3231. }else{
  3232. Session.Options.ScenarioIndex = scenariolist.Current_Index();
  3233. transmit = 1;
  3234. }
  3235. strcpy (Session.Handle, namebuf);
  3236. transmit = true;
  3237. }
  3238. break;
  3239. #endif
  3240. /*------------------------------------------------------------------
  3241. User adjusts max # units
  3242. ------------------------------------------------------------------*/
  3243. case (BUTTON_COUNT | KN_BUTTON):
  3244. Session.Options.UnitCount = countgauge.Get_Value() + SessionClass::CountMin[Session.Options.Bases];
  3245. if (display < REDRAW_PARMS) display = REDRAW_PARMS;
  3246. if (housebtn.IsDropped) {
  3247. housebtn.Collapse();
  3248. display = REDRAW_BACKGROUND;
  3249. }
  3250. transmit = true;
  3251. break;
  3252. /*------------------------------------------------------------------
  3253. User adjusts build level
  3254. ------------------------------------------------------------------*/
  3255. case (BUTTON_LEVEL | KN_BUTTON):
  3256. BuildLevel = levelgauge.Get_Value() + 1;
  3257. if (BuildLevel > MPLAYER_BUILD_LEVEL_MAX) // if it's pegged, max it out
  3258. BuildLevel = MPLAYER_BUILD_LEVEL_MAX;
  3259. if (display < REDRAW_PARMS) display = REDRAW_PARMS;
  3260. if (housebtn.IsDropped) {
  3261. housebtn.Collapse();
  3262. display = REDRAW_BACKGROUND;
  3263. }
  3264. transmit = true;
  3265. break;
  3266. /*------------------------------------------------------------------
  3267. User adjusts max # units
  3268. ------------------------------------------------------------------*/
  3269. case (BUTTON_CREDITS | KN_BUTTON):
  3270. Session.Options.Credits = creditsgauge.Get_Value();
  3271. Session.Options.Credits = ((Session.Options.Credits + 250) / 500) * 500;
  3272. if (display < REDRAW_PARMS) display = REDRAW_PARMS;
  3273. if (housebtn.IsDropped) {
  3274. housebtn.Collapse();
  3275. display = REDRAW_BACKGROUND;
  3276. }
  3277. transmit = true;
  3278. break;
  3279. //..................................................................
  3280. // User adjusts # of AI players
  3281. //..................................................................
  3282. case (BUTTON_AIPLAYERS | KN_BUTTON):
  3283. {
  3284. Session.Options.AIPlayers = aiplayersgauge.Get_Value();
  3285. int humans = 2; // Two humans.
  3286. if (skirmish) {
  3287. Session.Options.AIPlayers += 1; // Always one forced AI player.
  3288. humans = 1; // One human.
  3289. // if (Session.Options.AIPlayers == 0) {
  3290. // Session.Options.AIPlayers = 1;
  3291. // aiplayersgauge.Set_Value(0);
  3292. // }
  3293. }
  3294. if (Session.Options.AIPlayers+humans >= Rule.MaxPlayers) { // if it's pegged, max it out
  3295. Session.Options.AIPlayers = Rule.MaxPlayers - humans;
  3296. aiplayersgauge.Set_Value(Session.Options.AIPlayers - (skirmish ? 1 : 0));
  3297. }
  3298. transmit = true;
  3299. if (display < REDRAW_PARMS) display = REDRAW_PARMS;
  3300. if (housebtn.IsDropped) {
  3301. housebtn.Collapse();
  3302. display = REDRAW_BACKGROUND;
  3303. }
  3304. break;
  3305. }
  3306. //------------------------------------------------------------------
  3307. // Toggle-able options:
  3308. // If 'Bases' gets toggled, we have to change the range of the
  3309. // UnitCount slider.
  3310. // Also, if Tiberium gets toggled, we have to set the flags
  3311. // in SpecialClass.
  3312. //------------------------------------------------------------------
  3313. case (BUTTON_OPTIONS | KN_BUTTON):
  3314. if (!skirmish && Special.IsCaptureTheFlag != optionlist.Is_Checked(4) && !Special.IsCaptureTheFlag) {
  3315. optionlist.Check_Item(0, true);
  3316. }
  3317. if (Session.Options.Bases != optionlist.Is_Checked(0)) {
  3318. Session.Options.Bases = optionlist.Is_Checked(0);
  3319. if (Session.Options.Bases) {
  3320. Session.Options.UnitCount = Fixed_To_Cardinal (
  3321. SessionClass::CountMax[1] -
  3322. SessionClass::CountMin[1],
  3323. Cardinal_To_Fixed(
  3324. SessionClass::CountMax[0]-SessionClass::CountMin[0],
  3325. Session.Options.UnitCount-SessionClass::CountMin[0])) +
  3326. SessionClass::CountMin[1];
  3327. } else {
  3328. if (!skirmish) optionlist.Check_Item(4, false);
  3329. Session.Options.UnitCount = Fixed_To_Cardinal (
  3330. SessionClass::CountMax[0] -
  3331. SessionClass::CountMin[0],
  3332. Cardinal_To_Fixed(
  3333. SessionClass::CountMax[1]-SessionClass::CountMin[1],
  3334. Session.Options.UnitCount - SessionClass::CountMin[1])) +
  3335. SessionClass::CountMin[0];
  3336. }
  3337. countgauge.Set_Maximum(
  3338. SessionClass::CountMax[Session.Options.Bases] -
  3339. SessionClass::CountMin[Session.Options.Bases]);
  3340. countgauge.Set_Value(Session.Options.UnitCount -
  3341. SessionClass::CountMin[Session.Options.Bases]);
  3342. }
  3343. Session.Options.Tiberium = optionlist.Is_Checked(1);
  3344. Special.IsTGrowth = Session.Options.Tiberium;
  3345. Rule.IsTGrowth = Session.Options.Tiberium;
  3346. Special.IsTSpread = Session.Options.Tiberium;
  3347. Rule.IsTSpread = Session.Options.Tiberium;
  3348. Session.Options.Goodies = optionlist.Is_Checked(2);
  3349. Special.IsShadowGrow = optionlist.Is_Checked(3);
  3350. if (!skirmish) {
  3351. Special.IsCaptureTheFlag = optionlist.Is_Checked(4);
  3352. }
  3353. transmit = true;
  3354. if (display < REDRAW_PARMS) display = REDRAW_PARMS;
  3355. if (housebtn.IsDropped) {
  3356. housebtn.Collapse();
  3357. display = REDRAW_BACKGROUND;
  3358. }
  3359. break;
  3360. /*------------------------------------------------------------------
  3361. OK: exit loop with true status
  3362. ------------------------------------------------------------------*/
  3363. case (BUTTON_LOAD | KN_BUTTON):
  3364. case (BUTTON_OK | KN_BUTTON):
  3365. if (housebtn.IsDropped) {
  3366. housebtn.Collapse();
  3367. display = REDRAW_BACKGROUND;
  3368. }
  3369. //
  3370. // make sure we got a game options packet from the other player
  3371. //
  3372. if (gameoptions) {
  3373. rc = true;
  3374. process = false;
  3375. // force transmitting of game options packet one last time
  3376. transmit = true;
  3377. transmittime = 0;
  3378. } else {
  3379. WWMessageBox().Process (TXT_ONLY_ONE,TXT_OOPS,NULL);
  3380. display = REDRAW_ALL;
  3381. }
  3382. if (input==(BUTTON_LOAD | KN_BUTTON))
  3383. load_game = true;
  3384. break;
  3385. /*------------------------------------------------------------------
  3386. CANCEL: send a SIGN_OFF, bail out with error code
  3387. ------------------------------------------------------------------*/
  3388. case (KN_ESC):
  3389. case (BUTTON_CANCEL | KN_BUTTON):
  3390. if (housebtn.IsDropped) {
  3391. housebtn.Collapse();
  3392. display = REDRAW_BACKGROUND;
  3393. }
  3394. process = false;
  3395. rc = false;
  3396. break;
  3397. /*------------------------------------------------------------------
  3398. Default: manage the inter-player messages
  3399. ------------------------------------------------------------------*/
  3400. default:
  3401. if (!skirmish) {
  3402. if (Session.Messages.Manage()) {
  3403. if (display < REDRAW_MESSAGE) display = REDRAW_MESSAGE;
  3404. }
  3405. /*...............................................................
  3406. Service keyboard input for any message being edited.
  3407. ...............................................................*/
  3408. i = Session.Messages.Input(input);
  3409. /*...............................................................
  3410. If 'Input' returned 1, it means refresh the message display.
  3411. (We have to redraw the edit line, to erase the cursor.)
  3412. ...............................................................*/
  3413. if (i==1) {
  3414. Hide_Mouse();
  3415. Draw_Box(d_send_x, d_send_y, d_send_w, d_send_h,
  3416. BOXSTYLE_BOX, true);
  3417. Session.Messages.Draw();
  3418. Show_Mouse();
  3419. } else if (i==2) {
  3420. /*...............................................................
  3421. If 'Input' returned 2, it means redraw the message display.
  3422. Rather than setting 'display', which would redraw all msgs,
  3423. we only need to erase & redraw the edit box here.
  3424. ...............................................................*/
  3425. Hide_Mouse();
  3426. Draw_Box(d_send_x, d_send_y, d_send_w, d_send_h, BOXSTYLE_BOX, true);
  3427. Session.Messages.Draw();
  3428. Show_Mouse();
  3429. } else if (i==3 || i==4) {
  3430. /*...............................................................
  3431. If 'input' returned 3, it means send the current message.
  3432. ...............................................................*/
  3433. memset (&SendPacket, 0, sizeof(SerialPacketType));
  3434. SendPacket.Command = SERIAL_MESSAGE;
  3435. strcpy (SendPacket.Name, namebuf);
  3436. SendPacket.ID = Session.ColorIdx;
  3437. if (i==3) {
  3438. strcpy (SendPacket.Message.Message, Session.Messages.Get_Edit_Buf());
  3439. } else {
  3440. strcpy (SendPacket.Message.Message, Session.Messages.Get_Overflow_Buf());
  3441. Session.Messages.Clear_Overflow_Buf();
  3442. }
  3443. /*..................................................................
  3444. Send the message
  3445. ..................................................................*/
  3446. if (!skirmish) {
  3447. NullModem.Send_Message (&SendPacket, sizeof(SendPacket), 1);
  3448. NullModem.Service();
  3449. }
  3450. /*..................................................................
  3451. Add the message to our own screen
  3452. ..................................................................*/
  3453. Session.Messages.Add_Message (SendPacket.Name, SendPacket.ID,
  3454. SendPacket.Message.Message,
  3455. (Session.ColorIdx == PCOLOR_DIALOG_BLUE) ? PCOLOR_REALLY_BLUE : Session.ColorIdx,
  3456. TPF_TEXT, -1);
  3457. Session.Messages.Add_Edit((Session.ColorIdx == PCOLOR_DIALOG_BLUE) ?
  3458. PCOLOR_REALLY_BLUE : Session.ColorIdx,
  3459. TPF_TEXT, NULL, '_', d_message_w);
  3460. if (display < REDRAW_MESSAGE) display = REDRAW_MESSAGE;
  3461. } /* end of send message */
  3462. }
  3463. break;
  3464. }
  3465. /*---------------------------------------------------------------------
  3466. Detect editing of the name buffer, transmit new values to players
  3467. ---------------------------------------------------------------------*/
  3468. if (strcmp (namebuf, Session.Handle)) {
  3469. strcpy (Session.Handle, namebuf);
  3470. transmit = true;
  3471. changed = true;
  3472. }
  3473. /*---------------------------------------------------------------------
  3474. If our Transmit flag is set, we need to send out a game option packet.
  3475. This message requires an ACK. The first time through the loop, transmit
  3476. should be set, so we send out our default options; we'll then send
  3477. any changes we make to the defaults.
  3478. ---------------------------------------------------------------------*/
  3479. if (skirmish) {
  3480. transmit = false;
  3481. }
  3482. if (transmit && (TickCount - transmittime) > PACKET_RETRANS_TIME) {
  3483. memset (&SendPacket, 0, sizeof(SerialPacketType));
  3484. SendPacket.Command = SERIAL_GAME_OPTIONS;
  3485. strcpy (SendPacket.Name, namebuf);
  3486. SendPacket.ScenarioInfo.CheatCheck = RuleINI.Get_Unique_ID();
  3487. SendPacket.ScenarioInfo.MinVersion = VerNum.Min_Version();
  3488. SendPacket.ScenarioInfo.MaxVersion = VerNum.Max_Version();
  3489. SendPacket.ScenarioInfo.House = Session.House;
  3490. SendPacket.ScenarioInfo.Color = Session.ColorIdx;
  3491. SendPacket.ScenarioInfo.Credits = Session.Options.Credits;
  3492. SendPacket.ScenarioInfo.IsBases = Session.Options.Bases;
  3493. SendPacket.ScenarioInfo.IsTiberium = Session.Options.Tiberium;
  3494. SendPacket.ScenarioInfo.IsGoodies = Session.Options.Goodies;
  3495. SendPacket.ScenarioInfo.AIPlayers = Session.Options.AIPlayers;
  3496. SendPacket.ScenarioInfo.BuildLevel = BuildLevel;
  3497. SendPacket.ScenarioInfo.UnitCount = Session.Options.UnitCount;
  3498. SendPacket.ScenarioInfo.Seed = Seed;
  3499. SendPacket.ScenarioInfo.Special = Special;
  3500. SendPacket.ScenarioInfo.GameSpeed = Options.GameSpeed;
  3501. SendPacket.ID = Session.ModemType;
  3502. /*
  3503. ** Set up the scenario info so the remote player can match the scenario on his machine
  3504. ** or request a download if it doesnt exist
  3505. */
  3506. strcpy (SendPacket.ScenarioInfo.Scenario, Session.Scenarios[Session.Options.ScenarioIndex]->Description());
  3507. CCFileClass file (Session.Scenarios[Session.Options.ScenarioIndex]->Get_Filename());
  3508. SendPacket.ScenarioInfo.FileLength = file.Size();
  3509. #ifdef WOLAPI_INTEGRATION
  3510. strcpy( SendPacket.ScenarioInfo.ShortFileName, Session.Scenarios[Session.Options.ScenarioIndex]->Get_Filename() );
  3511. #else
  3512. strncpy (SendPacket.ScenarioInfo.ShortFileName, Session.Scenarios[Session.Options.ScenarioIndex]->Get_Filename(), sizeof(SendPacket.ScenarioInfo.ShortFileName));
  3513. #endif
  3514. strncpy ((char*)SendPacket.ScenarioInfo.FileDigest, Session.Scenarios[Session.Options.ScenarioIndex]->Get_Digest(), sizeof SendPacket.ScenarioInfo.FileDigest);
  3515. SendPacket.ScenarioInfo.OfficialScenario = Session.Scenarios[Session.Options.ScenarioIndex]->Get_Official();
  3516. NullModem.Send_Message (&SendPacket, sizeof(SendPacket), 1);
  3517. transmittime = TickCount;
  3518. transmit = false;
  3519. //..................................................................
  3520. // Keep the player list up to date
  3521. //..................................................................
  3522. if (playerlist.Count()) {
  3523. item = (char *)playerlist.Get_Item(0);
  3524. #ifdef OLDWAY
  3525. if (Session.House==HOUSE_GOOD) {
  3526. sprintf(item,"%s\t%s",namebuf,
  3527. Text_String(TXT_ALLIES));
  3528. } else {
  3529. sprintf(item,"%s\t%s",namebuf,
  3530. Text_String(TXT_SOVIET));
  3531. }
  3532. #else //OLDWAY
  3533. sprintf (item, "%s\t%s", namebuf, Text_String(HouseTypeClass::As_Reference(Session.House).Full_Name()));
  3534. #endif //OLDWAY
  3535. playerlist.Colors[0] = &ColorRemaps[(Session.ColorIdx == PCOLOR_DIALOG_BLUE) ?
  3536. PCOLOR_REALLY_BLUE : Session.ColorIdx];
  3537. playerlist.Flag_To_Redraw();
  3538. }
  3539. //..................................................................
  3540. // Play a little sound effect
  3541. //..................................................................
  3542. Sound_Effect(VOC_OPTIONS_CHANGED);
  3543. }
  3544. //
  3545. // send a timing packet if enough time has gone by.
  3546. //
  3547. if (!skirmish && (TickCount - timingtime) > PACKET_TIMING_TIMEOUT) {
  3548. memset (&SendPacket, 0, sizeof(SerialPacketType));
  3549. SendPacket.Command = SERIAL_TIMING;
  3550. SendPacket.ScenarioInfo.ResponseTime = NullModem.Response_Time();
  3551. SendPacket.ID = Session.ModemType;
  3552. NullModem.Send_Message (&SendPacket, sizeof(SendPacket), 0);
  3553. timingtime = TickCount;
  3554. }
  3555. /*---------------------------------------------------------------------
  3556. Check for an incoming message
  3557. ---------------------------------------------------------------------*/
  3558. if (!skirmish && NullModem.Get_Message (&ReceivePacket, &packetlen) > 0) {
  3559. lastmsgtime = TickCount;
  3560. msg_timeout = 600; // reset timeout value to 10 seconds
  3561. // (only the 1st time through is 20 seconds)
  3562. // are we getting our own packets back??
  3563. if (ReceivePacket.Command >= SERIAL_CONNECT &&
  3564. ReceivePacket.Command < SERIAL_LAST_COMMAND &&
  3565. ReceivePacket.Command != SERIAL_MESSAGE &&
  3566. ReceivePacket.ID == Session.ModemType) {
  3567. WWMessageBox().Process (TXT_SYSTEM_NOT_RESPONDING);
  3568. // to skip the other system not responding msg
  3569. lastmsgtime = TickCount;
  3570. process = false;
  3571. rc = false;
  3572. // say we did receive sign off to keep from sending one
  3573. recsignedoff = true;
  3574. break;
  3575. }
  3576. event = (EventClass *)&ReceivePacket;
  3577. if (event->Type <= EventClass::FRAMEINFO) {
  3578. if ( (TickCount - lastredrawtime) > PACKET_REDRAW_TIME) {
  3579. lastredrawtime = TickCount;
  3580. oppscorescreen = true;
  3581. if (display < REDRAW_MESSAGE) display = REDRAW_MESSAGE;
  3582. parms_received = true;
  3583. }
  3584. } else {
  3585. switch ( ReceivePacket.Command ) {
  3586. /*..................................................................
  3587. Sign-off: Give the other machine time to receive my ACK, display a
  3588. message, and exit.
  3589. ..................................................................*/
  3590. case (SERIAL_SIGN_OFF):
  3591. starttime = TickCount;
  3592. while (TickCount - starttime < 60)
  3593. NullModem.Service();
  3594. WWMessageBox().Process(TXT_USER_SIGNED_OFF);
  3595. // to skip the other system not responding msg
  3596. lastmsgtime = TickCount;
  3597. process = false;
  3598. rc = false;
  3599. recsignedoff = true;
  3600. break;
  3601. /*..................................................................
  3602. Game Options: Store the other machine's name, color & house;
  3603. If they've picked the same color as myself, re-transmit my settings
  3604. to force him to choose a different color. (Com_Show_Scenario_Dialog
  3605. is responsible for ensuring the colors are different.)
  3606. ..................................................................*/
  3607. case (SERIAL_GAME_OPTIONS):
  3608. oppscorescreen = false;
  3609. gameoptions = true;
  3610. kludge_timer = 2*60;
  3611. strcpy (TheirName, ReceivePacket.Name);
  3612. TheirColor = ReceivePacket.ScenarioInfo.Color;
  3613. TheirHouse = ReceivePacket.ScenarioInfo.House;
  3614. transmit = true;
  3615. parms_received = true;
  3616. if (display < REDRAW_MESSAGE) display = REDRAW_MESSAGE;
  3617. //.........................................................
  3618. // "Clip" the other system's version range to our own
  3619. // ........................................................
  3620. version = VerNum.Clip_Version(ReceivePacket.ScenarioInfo.MinVersion,
  3621. ReceivePacket.ScenarioInfo.MaxVersion);
  3622. // ........................................................
  3623. // If the greatest-common-version comes back 0, the other
  3624. // system's range is too low for ours
  3625. // ........................................................
  3626. if (version == 0) {
  3627. WWMessageBox().Process (TXT_DESTGAME_OUTDATED);
  3628. // to skip the other system not responding msg
  3629. lastmsgtime = TickCount;
  3630. process = false;
  3631. rc = false;
  3632. } else if (version == 0xffffffff) {
  3633. // ........................................................
  3634. // If the greatest-common-version comes back 0xffffffff,
  3635. // the other system's range is too high for ours
  3636. // ........................................................
  3637. WWMessageBox().Process (TXT_YOURGAME_OUTDATED);
  3638. // to skip the other system not responding msg
  3639. lastmsgtime = TickCount;
  3640. process = false;
  3641. rc = false;
  3642. } else {
  3643. if (ReceivePacket.ScenarioInfo.CheatCheck != RuleINI.Get_Unique_ID()) {
  3644. WWMessageBox().Process (TXT_MISMATCH);
  3645. // to skip the other system not responding msg
  3646. lastmsgtime = TickCount;
  3647. process = false;
  3648. rc = false;
  3649. } else {
  3650. // ........................................................
  3651. // Otherwise, 'version' is the highest version we have in
  3652. // common; look up the protocol that goes with this version.
  3653. // ........................................................
  3654. Session.CommProtocol = VerNum.Version_Protocol(version);
  3655. #ifndef FIXIT_VERSION_3
  3656. PlayingAgainstVersion = version;
  3657. #endif
  3658. }
  3659. }
  3660. /*.........................................................
  3661. If this is the first game-options packet we've received,
  3662. init the game & player lists
  3663. .........................................................*/
  3664. if (playerlist.Count()==0) {
  3665. //......................................................
  3666. // Add two strings to the player list
  3667. //......................................................
  3668. item = new char [MPLAYER_NAME_MAX + 64]; //Need room to display country name
  3669. playerlist.Add_Item(item,
  3670. &ColorRemaps[Session.ColorIdx]);
  3671. item = new char [MPLAYER_NAME_MAX + 64]; //Need room to display country name
  3672. playerlist.Add_Item(item,
  3673. &ColorRemaps[TheirColor]);
  3674. }
  3675. //.........................................................
  3676. // Ensure the player list has the latest, greatest copy of
  3677. // our names & colors. Do this every time we receive an
  3678. // options packet.
  3679. //.........................................................
  3680. item = (char *)playerlist.Get_Item(0);
  3681. #ifdef OLDWAY
  3682. if (Session.House==HOUSE_GOOD) {
  3683. sprintf(item,"%s\t%s",namebuf,
  3684. Text_String(TXT_ALLIES));
  3685. } else {
  3686. sprintf(item,"%s\t%s",namebuf,
  3687. Text_String(TXT_SOVIET));
  3688. }
  3689. #else //OLDWAY
  3690. sprintf (item, "%s\t%s", namebuf, Text_String(HouseTypeClass::As_Reference(Session.House).Full_Name()));
  3691. #endif //OLDWAY
  3692. playerlist.Colors[0] = &ColorRemaps[(Session.ColorIdx == PCOLOR_DIALOG_BLUE) ?
  3693. PCOLOR_REALLY_BLUE : Session.ColorIdx];
  3694. item = (char *)playerlist.Get_Item(1);
  3695. #ifdef OLDWAY
  3696. if (TheirHouse==HOUSE_GOOD) {
  3697. sprintf(item,"%s\t%s",TheirName,
  3698. Text_String(TXT_ALLIES));
  3699. } else {
  3700. sprintf(item,"%s\t%s",TheirName,
  3701. Text_String(TXT_SOVIET));
  3702. }
  3703. #else //OLDWAY
  3704. sprintf (item, "%s\t%s", TheirName, Text_String(HouseTypeClass::As_Reference(TheirHouse).Full_Name()));
  3705. #endif //OLDWAY
  3706. playerlist.Colors[1] = &ColorRemaps[(TheirColor == PCOLOR_DIALOG_BLUE) ?
  3707. PCOLOR_REALLY_BLUE : TheirColor];
  3708. playerlist.Flag_To_Redraw();
  3709. //.........................................................
  3710. // Play a little sound effect
  3711. //.........................................................
  3712. Sound_Effect(VOC_OPTIONS_CHANGED);
  3713. break;
  3714. /*..................................................................
  3715. Incoming message: add to our list
  3716. ..................................................................*/
  3717. case (SERIAL_MESSAGE):
  3718. oppscorescreen = false;
  3719. Session.Messages.Add_Message (ReceivePacket.Name,
  3720. ((PlayerColorType)ReceivePacket.ID == PCOLOR_DIALOG_BLUE) ?
  3721. PCOLOR_REALLY_BLUE : (PlayerColorType)ReceivePacket.ID,
  3722. ReceivePacket.Message.Message,
  3723. ((PlayerColorType)ReceivePacket.ID == PCOLOR_DIALOG_BLUE) ?
  3724. PCOLOR_REALLY_BLUE : (PlayerColorType)ReceivePacket.ID,
  3725. TPF_TEXT, -1);
  3726. Sound_Effect(VOC_INCOMING_MESSAGE);
  3727. if (display < REDRAW_MESSAGE) display = REDRAW_MESSAGE;
  3728. break;
  3729. //
  3730. // get their response time
  3731. //
  3732. case (SERIAL_TIMING):
  3733. oppscorescreen = false;
  3734. theirresponsetime = ReceivePacket.ScenarioInfo.ResponseTime;
  3735. if ( !gameoptions ) {
  3736. // retransmit of game options packet again
  3737. transmit = true;
  3738. }
  3739. break;
  3740. //
  3741. // print msg waiting for opponent
  3742. //
  3743. case (SERIAL_SCORE_SCREEN):
  3744. oppscorescreen = true;
  3745. if (display < REDRAW_MESSAGE) display = REDRAW_MESSAGE;
  3746. parms_received = true;
  3747. break;
  3748. default:
  3749. break;
  3750. }
  3751. }
  3752. }
  3753. // if we haven't received a msg for 10 seconds exit
  3754. if (!skirmish && (TickCount - lastmsgtime) > msg_timeout) {
  3755. WWMessageBox().Process (TXT_SYSTEM_NOT_RESPONDING);
  3756. process = false;
  3757. rc = false;
  3758. // say we did receive sign off to keep from sending one
  3759. recsignedoff = true;
  3760. }
  3761. /*---------------------------------------------------------------------
  3762. Service the connection
  3763. ---------------------------------------------------------------------*/
  3764. if (!skirmish) {
  3765. NullModem.Service();
  3766. }
  3767. }
  3768. /*------------------------------------------------------------------------
  3769. Prepare to load the scenario
  3770. ------------------------------------------------------------------------*/
  3771. if (rc) {
  3772. Session.NumPlayers = skirmish ? 1 : 2;
  3773. Scen.Scenario = Session.Options.ScenarioIndex;
  3774. strcpy (Scen.ScenarioName, Session.Scenarios[Session.Options.ScenarioIndex]->Get_Filename());
  3775. /*.....................................................................
  3776. Add both players to the Players vector; the local system is always
  3777. index 0.
  3778. .....................................................................*/
  3779. who = new NodeNameType;
  3780. strcpy(who->Name, namebuf);
  3781. who->Player.House = Session.House;
  3782. who->Player.Color = Session.ColorIdx;
  3783. who->Player.ProcessTime = -1;
  3784. Session.Players.Add (who);
  3785. /*
  3786. ** Fetch the difficulty setting when in skirmish mode.
  3787. */
  3788. if (skirmish) {
  3789. int diff = difficulty.Get_Value() * (Rule.IsFineDifficulty ? 1 : 2);
  3790. switch (diff) {
  3791. case 0:
  3792. Scen.CDifficulty = DIFF_HARD;
  3793. Scen.Difficulty = DIFF_EASY;
  3794. break;
  3795. case 1:
  3796. Scen.CDifficulty = DIFF_HARD;
  3797. Scen.Difficulty = DIFF_NORMAL;
  3798. break;
  3799. case 2:
  3800. Scen.CDifficulty = DIFF_NORMAL;
  3801. Scen.Difficulty = DIFF_NORMAL;
  3802. break;
  3803. case 3:
  3804. Scen.CDifficulty = DIFF_EASY;
  3805. Scen.Difficulty = DIFF_NORMAL;
  3806. break;
  3807. case 4:
  3808. Scen.CDifficulty = DIFF_EASY;
  3809. Scen.Difficulty = DIFF_HARD;
  3810. break;
  3811. }
  3812. } else {
  3813. Scen.CDifficulty = DIFF_NORMAL;
  3814. Scen.Difficulty = DIFF_NORMAL;
  3815. }
  3816. if (!skirmish) {
  3817. who = new NodeNameType;
  3818. #ifdef FIXIT_MODEM_LOAD_CRASH
  3819. /* If the names of the players are the same then we MUST force them
  3820. * be be unique. This is necessary to prevent a crash after loading
  3821. * a modem save game.
  3822. */
  3823. if (strcmp(TheirName, namebuf) == 0)
  3824. {
  3825. if (strlen(TheirName) == (MPLAYER_NAME_MAX - 1))
  3826. {
  3827. TheirName[MPLAYER_NAME_MAX - 1] = '\0';
  3828. }
  3829. else
  3830. {
  3831. strcat(TheirName, "2");
  3832. }
  3833. }
  3834. #endif
  3835. strcpy(who->Name, TheirName);
  3836. who->Player.House = TheirHouse;
  3837. who->Player.Color = TheirColor;
  3838. who->Player.ProcessTime = -1;
  3839. Session.Players.Add (who);
  3840. }
  3841. /*.....................................................................
  3842. Send all players a GO packet.
  3843. .....................................................................*/
  3844. memset (&SendPacket, 0, sizeof(SerialPacketType));
  3845. if (load_game) {
  3846. SendPacket.Command = SERIAL_LOADGAME;
  3847. } else {
  3848. SendPacket.Command = SERIAL_GO;
  3849. }
  3850. if (!skirmish) {
  3851. SendPacket.ScenarioInfo.ResponseTime = NullModem.Response_Time();
  3852. if ( theirresponsetime == 10000 ) {
  3853. ;
  3854. } else if (SendPacket.ScenarioInfo.ResponseTime < theirresponsetime) {
  3855. SendPacket.ScenarioInfo.ResponseTime = theirresponsetime;
  3856. }
  3857. }
  3858. //
  3859. // calculated one way delay for a packet and overall delay to execute
  3860. // a packet
  3861. //
  3862. if (!skirmish) {
  3863. if (Session.CommProtocol == COMM_PROTOCOL_MULTI_E_COMP) {
  3864. Session.MaxAhead = max( ((((SendPacket.ScenarioInfo.ResponseTime / 8) +
  3865. (Session.FrameSendRate - 1)) / Session.FrameSendRate) *
  3866. Session.FrameSendRate), (Session.FrameSendRate * 2)
  3867. );
  3868. } else {
  3869. Session.MaxAhead = max( (SendPacket.ScenarioInfo.ResponseTime / 8),
  3870. MODEM_MIN_MAX_AHEAD );
  3871. }
  3872. }
  3873. SendPacket.ID = Session.ModemType;
  3874. if (!skirmish) {
  3875. NullModem.Send_Message (&SendPacket, sizeof(SendPacket), 1);
  3876. starttime = TickCount;
  3877. while ( ( NullModem.Num_Send()
  3878. && ((TickCount - starttime) < PACKET_SENDING_TIMEOUT) )
  3879. || ((TickCount - starttime) < 60) ) {
  3880. #if(SHOW_MONO)
  3881. NullModem.Mono_Debug_Print(0);
  3882. #endif
  3883. NullModem.Service();
  3884. }
  3885. /*
  3886. ** Wait for the go response. This will be either a 'GO' reply, a
  3887. ** request for the scenario to be sent or a reply to say that the scenario
  3888. ** cant be played.
  3889. */
  3890. #ifdef WIN32
  3891. WWDebugString ("RA95 - About to wait for 'GO' response.\n");
  3892. #endif
  3893. do {
  3894. NullModem.Service();
  3895. if (NullModem.Get_Message (&ReceivePacket, &packetlen) > 0) {
  3896. #ifdef FIXIT_VERSION_3
  3897. if (ReceivePacket.Command == SERIAL_READY_TO_GO)
  3898. {
  3899. if( Session.Scenarios[Session.Options.ScenarioIndex]->Get_Official() )
  3900. {
  3901. if( !Force_Scenario_Available( Scen.ScenarioName ) )
  3902. Emergency_Exit(EXIT_FAILURE);
  3903. }
  3904. break;
  3905. }
  3906. #else
  3907. if (ReceivePacket.Command == SERIAL_READY_TO_GO) break;
  3908. #endif
  3909. if (ReceivePacket.Command == SERIAL_NO_SCENARIO) {
  3910. WWMessageBox().Process(TXT_NO_EXPANSION_SCENARIO, TXT_CANCEL);
  3911. /*
  3912. ** We have to recover from this somehow so....
  3913. */
  3914. process = true;
  3915. display = REDRAW_ALL;
  3916. lastmsgtime = TickCount;
  3917. goto oh_dear_its_a_label;
  3918. }
  3919. if (ReceivePacket.Command == SERIAL_REQ_SCENARIO) {
  3920. #ifdef WIN32
  3921. WWDebugString ("RA95 - About to call 'Send_Remote_File'.\n");
  3922. #endif
  3923. #ifdef FIXIT_VERSION_3
  3924. if( Session.Scenarios[Session.Options.ScenarioIndex]->Get_Official() )
  3925. {
  3926. if( !Force_Scenario_Available( Scen.ScenarioName ) )
  3927. Emergency_Exit(EXIT_FAILURE);
  3928. }
  3929. #endif
  3930. Send_Remote_File (Scen.ScenarioName, 0);
  3931. break;
  3932. }
  3933. }
  3934. } while ( !Keyboard->Check() );
  3935. // clear queue to keep from doing any resends
  3936. NullModem.Init_Send_Queue();
  3937. }
  3938. } else {
  3939. if ( !recsignedoff ) {
  3940. /*.....................................................................
  3941. Broadcast my sign-off over my network
  3942. .....................................................................*/
  3943. if (!skirmish) {
  3944. memset (&SendPacket, 0, sizeof(SerialPacketType));
  3945. SendPacket.Command = SERIAL_SIGN_OFF;
  3946. SendPacket.ScenarioInfo.Color = Session.ColorIdx; // use Color for ID
  3947. SendPacket.ID = Session.ModemType;
  3948. NullModem.Send_Message (&SendPacket, sizeof(SendPacket), 1);
  3949. starttime = TickCount;
  3950. while ( (NullModem.Num_Send()
  3951. && ((TickCount - starttime) < PACKET_CANCEL_TIMEOUT) )
  3952. || ((TickCount - starttime) < 60) ) {
  3953. #if(SHOW_MONO)
  3954. NullModem.Mono_Debug_Print(0);
  3955. #endif
  3956. if ( NullModem.Get_Message( &ReceivePacket, &packetlen ) > 0) {
  3957. // are we getting our own packets back??
  3958. if (ReceivePacket.Command == SERIAL_SIGN_OFF
  3959. && ReceivePacket.ID == Session.ModemType) {
  3960. // exit while
  3961. break;
  3962. }
  3963. }
  3964. NullModem.Service();
  3965. }
  3966. }
  3967. }
  3968. if (!skirmish) Shutdown_Modem();
  3969. }
  3970. /*------------------------------------------------------------------------
  3971. Clear all lists
  3972. ------------------------------------------------------------------------*/
  3973. while (scenariolist.Count()) {
  3974. scenariolist.Remove_Item(scenariolist.Get_Item(0));
  3975. }
  3976. /*------------------------------------------------------------------------
  3977. Clean up the list boxes
  3978. ------------------------------------------------------------------------*/
  3979. while (playerlist.Count()>0) {
  3980. item = (char *)playerlist.Get_Item(0);
  3981. delete [] item;
  3982. playerlist.Remove_Item(item);
  3983. }
  3984. /*------------------------------------------------------------------------
  3985. Remove the chat edit box
  3986. ------------------------------------------------------------------------*/
  3987. Session.Messages.Remove_Edit();
  3988. /*------------------------------------------------------------------------
  3989. Restore screen
  3990. ------------------------------------------------------------------------*/
  3991. Hide_Mouse();
  3992. Load_Title_Page(true);
  3993. Show_Mouse();
  3994. /*------------------------------------------------------------------------
  3995. Save any changes made to our options
  3996. ------------------------------------------------------------------------*/
  3997. if (changed) {
  3998. Session.Write_MultiPlayer_Settings();
  3999. }
  4000. if (load_game && !skirmish) {
  4001. if (!Load_Game (-1)) {
  4002. WWMessageBox().Process (TXT_ERROR_LOADING_GAME);
  4003. rc = false;
  4004. }
  4005. Frame++;
  4006. }
  4007. return(rc);
  4008. }
  4009. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  4010. extern bool Is_Mission_Aftermath (char *file_name);
  4011. #endif
  4012. /***********************************************************************************************
  4013. * Find_Local_Scenario -- finds the file name of the scenario with matching attributes *
  4014. * *
  4015. * *
  4016. * *
  4017. * INPUT: ptr to Scenario description *
  4018. * ptr to Scenario filename to fix up *
  4019. * length of file for trivial rejection of scenario files *
  4020. * ptr to digest. Digests must match. *
  4021. * *
  4022. * *
  4023. * OUTPUT: true if scenario is available locally *
  4024. * *
  4025. * WARNINGS: We need to reject files that don't match exactly because scenarios with the same *
  4026. * description can exist on both machines but have different contents. For example *
  4027. * there will be lots of scenarios called 'my map' and 'aaaaaa'. *
  4028. * *
  4029. * HISTORY: *
  4030. * 8/23/96 12:36PM ST : Created *
  4031. *=============================================================================================*/
  4032. bool Find_Local_Scenario (char *description, char *filename, unsigned int length, char *digest, bool official)
  4033. {
  4034. //FILE *fp;
  4035. //fp = fopen("findscen.txt","wt");
  4036. //debugprint("looking for local scenario: description = %s, name=%s, length=%d, digest=%s, official=%d\n", description, filename, length, digest, official);
  4037. char digest_buffer[32];
  4038. /*
  4039. ** Scan through the scenario list looking for scenarios with matching descriptions.
  4040. */
  4041. for (int index = 0; index < Session.Scenarios.Count(); index++) {
  4042. //debugprint( "Checking against scenario: %s\n", Session.Scenarios[index]->Description());
  4043. if (!strcmp (Session.Scenarios[index]->Description(), description)) {
  4044. //debugprint("found matching description.\n");
  4045. CCFileClass file (Session.Scenarios[index]->Get_Filename());
  4046. /*
  4047. ** Possible rejection on the basis of availability.
  4048. */
  4049. if (file.Is_Available()) {
  4050. //debugprint("file is available.\n");
  4051. /*
  4052. ** Possible rejection on the basis of size.
  4053. */
  4054. if (file.Size() == length) {
  4055. //debugprint("length matches.\n");
  4056. /*
  4057. ** We don't know the digest for 'official' scenarios so assume its correct
  4058. */
  4059. if (!official) {
  4060. //debugprint("!official.\n");
  4061. /*
  4062. ** Possible rejection on the basis of digest
  4063. */
  4064. INIClass ini;
  4065. ini.Load(file);
  4066. ini.Get_String ("Digest", "1", "No digest here mate. Nope.", digest_buffer, sizeof (digest_buffer) );
  4067. }
  4068. //debugprint("digest = %s, digest_buffer = %s.\n", digest, digest_buffer);
  4069. #ifdef FIXIT_CSII // checked - ajw 9/28/98. But don't know why this happens. Because of autodownload?
  4070. /*
  4071. ** If this is an aftermath scenario then ignore the digest and return success.
  4072. */
  4073. if ( Is_Mission_Aftermath ((char*)Session.Scenarios[index]->Get_Filename()) ) {
  4074. //debugprint("a 1match!\n");
  4075. strcpy (filename, Session.Scenarios[index]->Get_Filename());
  4076. return (true);
  4077. }
  4078. #endif
  4079. /*
  4080. ** This must be the same scenario. Copy the name and return true.
  4081. */
  4082. if (official || !strcmp (digest, digest_buffer)) {
  4083. //debugprint("a match!\n");
  4084. strcpy (filename, Session.Scenarios[index]->Get_Filename());
  4085. return (true);
  4086. }
  4087. }
  4088. }
  4089. // else
  4090. // debugprint("file not available '%s'.\n", Session.Scenarios[index]->Get_Filename());
  4091. }
  4092. }
  4093. //debugprint("failed match.\n");
  4094. /*
  4095. ** Couldnt find the scenario locally. Return failure.
  4096. */
  4097. return (false);
  4098. }
  4099. /***********************************************************************************************
  4100. * Com_Show_Scenario_Dialog -- Serial game scenario selection dialog *
  4101. * *
  4102. * The 'Players' vector is filled in by this routine, when the game starts; this *
  4103. * is for the Assign_Houses routine, which expects this vector to contain all *
  4104. * players' names & houses & colors. Other than that, the Players vector, Games *
  4105. * vector, and Chat vector aren't used at all by this routine. The Game & Players *
  4106. * list boxes are filled in manually in the processing loop. *
  4107. * *
  4108. * ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ *
  4109. * ³ Serial Game ³ *
  4110. * ³ ³ *
  4111. * ³ Your Name: __________ ³ *
  4112. * ³ House: [GDI] [NOD] ³ *
  4113. * ³ Desired Color: [ ][ ][ ][ ] ³ *
  4114. * ³ ³ *
  4115. * ³ Opponent: Name ³ *
  4116. * ³ Scenario: Description ³ *
  4117. * ³ Credits: xxxx ³ *
  4118. * ³ Bases: ON ³ *
  4119. * ³ Crates: ON ³ *
  4120. * ³ Tiberium: ON ³ *
  4121. * ³ Ghosts: ON ³ *
  4122. * ³ ³ *
  4123. * ³ [Cancel] ³ *
  4124. * ³ ³ *
  4125. * ³ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ *
  4126. * ³ ³ ³ ³ *
  4127. * ³ ³ ³ ³ *
  4128. * ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ³ *
  4129. * ³ [Send Message] ³ *
  4130. * ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ *
  4131. * *
  4132. * INPUT: *
  4133. * none. *
  4134. * *
  4135. * OUTPUT: *
  4136. * true = success, false = cancel *
  4137. * *
  4138. * WARNINGS: *
  4139. * none. *
  4140. * *
  4141. * HISTORY: *
  4142. * 02/14/1995 BR : Created. *
  4143. *=============================================================================================*/
  4144. int Com_Show_Scenario_Dialog(void)
  4145. {
  4146. /*........................................................................
  4147. Dialog & button dimensions
  4148. ........................................................................*/
  4149. int d_dialog_w = 320 * RESFACTOR; // dialog width
  4150. int d_dialog_h = 200 * RESFACTOR; // dialog height
  4151. int d_dialog_x = ((320 * RESFACTOR - d_dialog_w) / 2); // dialog x-coord
  4152. int d_dialog_y = ((200 * RESFACTOR - d_dialog_h) / 2); // dialog y-coord
  4153. int d_dialog_cx = d_dialog_x + (d_dialog_w / 2); // center x-coord
  4154. int d_txt6_h = 6 * RESFACTOR+1; // ht of 6-pt text
  4155. int d_margin1 = 5 * RESFACTOR; // margin width/height
  4156. int d_margin2 = 2 * RESFACTOR; // margin width/height
  4157. int d_name_w = 70 * RESFACTOR;
  4158. int d_name_h = 9 * RESFACTOR;
  4159. int d_name_x = d_dialog_x + (d_dialog_w / 4) - (d_name_w / 2);
  4160. int d_name_y = d_dialog_y + d_margin1 + d_margin2 + d_txt6_h + 1*RESFACTOR;
  4161. #ifdef OLDWAY
  4162. int d_gdi_w = 40 * RESFACTOR;
  4163. int d_gdi_h = 9 * RESFACTOR;
  4164. int d_gdi_x = d_dialog_cx - d_gdi_w;
  4165. int d_gdi_y = d_name_y;
  4166. int d_nod_w = 40 * RESFACTOR;
  4167. int d_nod_h = 9 * RESFACTOR;
  4168. int d_nod_x = d_dialog_cx;
  4169. int d_nod_y = d_name_y;
  4170. #else //OLDWAY
  4171. int d_house_w = 60 *RESFACTOR;
  4172. int d_house_h = (8 * 5 *RESFACTOR);
  4173. int d_house_x = d_dialog_cx - (d_house_w / 2);
  4174. int d_house_y = d_name_y;
  4175. #endif //OLDWAY
  4176. int d_color_w = 10 * RESFACTOR;
  4177. int d_color_h = 9 * RESFACTOR;
  4178. int d_color_x = d_dialog_x + ((d_dialog_w / 4) * 3) - (d_color_w * 3);
  4179. int d_color_y = d_name_y;
  4180. int d_scenario_y = d_name_y + d_name_h + d_margin2;
  4181. int d_gamelist_w = 160 * RESFACTOR;
  4182. int d_gamelist_h = (6 * 6 * RESFACTOR) + 3 * RESFACTOR; // 6 rows high
  4183. int d_gamelist_x = d_dialog_x + d_margin1 + 10*RESFACTOR;
  4184. int d_gamelist_y = d_scenario_y + d_txt6_h + d_margin2 + d_txt6_h + d_margin2;
  4185. //BG int d_playerlist_w = 112 * RESFACTOR;
  4186. int d_playerlist_w = 118 * RESFACTOR;
  4187. int d_playerlist_h = (6 * 6 * RESFACTOR) + 3 * RESFACTOR; // 6 rows high
  4188. int d_playerlist_x = d_dialog_x + d_dialog_w - d_margin1 - d_margin1 - d_playerlist_w - 5*RESFACTOR;
  4189. int d_playerlist_y = d_gamelist_y;
  4190. int d_count_w = 25 * RESFACTOR;
  4191. int d_count_h = d_txt6_h;
  4192. int d_count_x = d_gamelist_x + (d_gamelist_w / 2);
  4193. int d_count_y = d_gamelist_y + d_gamelist_h + (d_margin1 * 2) - d_margin2;
  4194. int d_level_w = 25 * RESFACTOR;
  4195. int d_level_h = d_txt6_h;
  4196. int d_level_x = d_gamelist_x + (d_gamelist_w / 2);
  4197. int d_level_y = d_count_y + d_count_h;
  4198. int d_credits_w = 25 * RESFACTOR;
  4199. int d_credits_h = d_txt6_h;
  4200. int d_credits_x = d_gamelist_x + (d_gamelist_w / 2);
  4201. int d_credits_y = d_level_y + d_level_h;
  4202. int d_aiplayers_w = 25 * RESFACTOR;
  4203. int d_aiplayers_h = d_txt6_h;
  4204. int d_aiplayers_x = d_gamelist_x + (d_gamelist_w / 2);
  4205. int d_aiplayers_y = d_credits_y + d_credits_h;
  4206. int d_options_w = 112 * RESFACTOR;
  4207. int d_options_h = (5 * 6* RESFACTOR) + 4*RESFACTOR;
  4208. int d_options_x = d_playerlist_x;
  4209. int d_options_y = d_playerlist_y + d_playerlist_h + d_margin1 - d_margin2;
  4210. int d_message_w = d_dialog_w - (d_margin1 * 2) - 20*RESFACTOR;
  4211. int d_message_h = (7 * d_txt6_h) + 3 * RESFACTOR; // 7 rows high
  4212. int d_message_x = d_gamelist_x;//d_dialog_x + d_margin1 + 10*RESFACTOR;
  4213. int d_message_y = d_options_y + d_options_h + d_margin2/*KO + d_margin1*/;
  4214. int d_send_w = d_message_w;
  4215. int d_send_h = 9 * RESFACTOR;
  4216. int d_send_x = d_message_x;
  4217. int d_send_y = d_message_y + d_message_h;
  4218. int d_cancel_w = 45 * RESFACTOR;
  4219. int d_cancel_h = 9 * RESFACTOR;
  4220. int d_cancel_x = d_dialog_cx - (d_cancel_w / 2);
  4221. int d_cancel_y = d_send_y + d_send_h/*KO + d_margin2*/;
  4222. /*........................................................................
  4223. Button Enumerations
  4224. ........................................................................*/
  4225. enum {
  4226. BUTTON_NAME = 100,
  4227. #ifdef OLDWAY
  4228. BUTTON_GDI,
  4229. BUTTON_NOD,
  4230. #else //OLDWAY
  4231. BUTTON_HOUSE,
  4232. #endif //OLDWAY
  4233. BUTTON_GAMELIST,
  4234. BUTTON_PLAYERLIST,
  4235. BUTTON_CANCEL,
  4236. BUTTON_COUNT,
  4237. BUTTON_LEVEL,
  4238. BUTTON_CREDITS,
  4239. BUTTON_AI_PLAYERS,
  4240. BUTTON_OPTIONS,
  4241. };
  4242. /*........................................................................
  4243. Redraw values: in order from "top" to "bottom" layer of the dialog
  4244. ........................................................................*/
  4245. typedef enum {
  4246. REDRAW_NONE = 0,
  4247. REDRAW_PARMS,
  4248. REDRAW_MESSAGE,
  4249. REDRAW_COLORS,
  4250. REDRAW_BUTTONS,
  4251. REDRAW_BACKGROUND,
  4252. REDRAW_ALL = REDRAW_BACKGROUND
  4253. } RedrawType;
  4254. /*........................................................................
  4255. Dialog variables
  4256. ........................................................................*/
  4257. RedrawType display = REDRAW_ALL; // redraw level
  4258. int cbox_x[] = {
  4259. d_color_x,
  4260. d_color_x + d_color_w,
  4261. d_color_x + (d_color_w * 2),
  4262. d_color_x + (d_color_w * 3),
  4263. d_color_x + (d_color_w * 4),
  4264. d_color_x + (d_color_w * 5),
  4265. d_color_x + (d_color_w * 6),
  4266. d_color_x + (d_color_w * 7)
  4267. };
  4268. char namebuf[MPLAYER_NAME_MAX] = {0}; // buffer for player's name
  4269. //BG int playertabs[] = {77}; // tabs for player list box
  4270. int playertabs[] = {71*RESFACTOR}; // tabs for player list box
  4271. int optiontabs[] = {8}; // tabs for options list box
  4272. bool transmit; // 1 = re-transmit new game options
  4273. bool first; // 1 = no packets received yet
  4274. bool parms_received = false; // 1 = game options received
  4275. bool changed = false; // 1 = user has changed an option
  4276. int rc;
  4277. int recsignedoff = 0;
  4278. int i;
  4279. unsigned long version;
  4280. char txt[80];
  4281. unsigned long starttime;
  4282. unsigned long timingtime;
  4283. unsigned long lastmsgtime;
  4284. unsigned long lastredrawtime;
  4285. unsigned long transmittime = 0;
  4286. int packetlen;
  4287. bool oppscorescreen = false;
  4288. bool gameoptions = false;
  4289. EventClass *event; // event ptr
  4290. unsigned long msg_timeout = 1200; // init to 20 seconds
  4291. bool load_game = false; // 1 = load saved game
  4292. NodeNameType *who; // node to add to Players
  4293. char *item; // for filling in lists
  4294. char *p;
  4295. RemapControlType * scheme = GadgetClass::Get_Color_Scheme();
  4296. Session.Options.ScenarioDescription[0] = 0; //Flag that we dont know the scenario name yet
  4297. bool messages_have_focus = true;
  4298. bool ready_packet_was_sent = false;
  4299. /*........................................................................
  4300. Buttons
  4301. ........................................................................*/
  4302. GadgetClass *commands; // button list
  4303. EditClass name_edt(BUTTON_NAME, namebuf, MPLAYER_NAME_MAX, TPF_TEXT, d_name_x, d_name_y, d_name_w, d_name_h, EditClass::ALPHANUMERIC);
  4304. #ifdef OLDWAY
  4305. TextButtonClass gdibtn(BUTTON_GDI, TXT_ALLIES, TPF_BUTTON, d_gdi_x, d_gdi_y, d_gdi_w, d_gdi_h);
  4306. TextButtonClass nodbtn(BUTTON_NOD, TXT_SOVIET, TPF_BUTTON, d_nod_x, d_nod_y, d_nod_w, d_nod_h);
  4307. #else //OLDWAY
  4308. char housetext[25] = "";
  4309. Fancy_Text_Print("", 0, 0, 0, 0, TPF_TEXT);
  4310. DropListClass housebtn(BUTTON_HOUSE, housetext, sizeof(housetext),
  4311. TPF_TEXT,
  4312. d_house_x, d_house_y, d_house_w, d_house_h,
  4313. MFCD::Retrieve("BTN-UP.SHP"),
  4314. MFCD::Retrieve("BTN-DN.SHP"));
  4315. #endif //OLDWAY
  4316. TextButtonClass cancelbtn(BUTTON_CANCEL, TXT_CANCEL, TPF_BUTTON, d_cancel_x, d_cancel_y, d_cancel_w);
  4317. ListClass gamelist(BUTTON_GAMELIST, d_gamelist_x, d_gamelist_y, d_gamelist_w, d_gamelist_h, TPF_TEXT, MFCD::Retrieve("BTN-UP.SHP"), MFCD::Retrieve("BTN-DN.SHP"));
  4318. ColorListClass playerlist(BUTTON_PLAYERLIST, d_playerlist_x, d_playerlist_y, d_playerlist_w, d_playerlist_h, TPF_TEXT, MFCD::Retrieve("BTN-UP.SHP"), MFCD::Retrieve("BTN-DN.SHP"));
  4319. GaugeClass countgauge(BUTTON_COUNT, d_count_x, d_count_y, d_count_w, d_count_h);
  4320. char staticcountbuff[35];
  4321. StaticButtonClass staticcount(0, " ", TPF_TEXT, d_count_x+d_count_w+3*RESFACTOR, d_count_y);
  4322. GaugeClass levelgauge(BUTTON_LEVEL, d_level_x, d_level_y, d_level_w, d_level_h);
  4323. char staticlevelbuff[35];
  4324. StaticButtonClass staticlevel(0, " ", TPF_TEXT, d_level_x+d_level_w+3*RESFACTOR, d_level_y);
  4325. GaugeClass creditsgauge(BUTTON_CREDITS, d_credits_x, d_credits_y, d_credits_w, d_credits_h);
  4326. char staticcreditsbuff[35];
  4327. StaticButtonClass staticcredits(0, " ", TPF_TEXT, d_credits_x+d_credits_w+3*RESFACTOR, d_credits_y);
  4328. GaugeClass aiplayersgauge(BUTTON_AI_PLAYERS, d_aiplayers_x, d_aiplayers_y, d_aiplayers_w, d_aiplayers_h);
  4329. char staticaibuff[35];
  4330. StaticButtonClass staticai(0, " ", TPF_TEXT, d_aiplayers_x+d_aiplayers_w+3*RESFACTOR, d_aiplayers_y);
  4331. CheckListClass optionlist(BUTTON_OPTIONS, d_options_x, d_options_y, d_options_w, d_options_h, TPF_TEXT, MFCD::Retrieve("BTN-UP.SHP"), MFCD::Retrieve("BTN-DN.SHP"));
  4332. /*
  4333. ------------------------- Build the button list --------------------------
  4334. */
  4335. commands = &name_edt;
  4336. staticcount.Add_Tail(*commands);
  4337. staticcredits.Add_Tail(*commands);
  4338. staticai.Add_Tail(*commands);
  4339. staticlevel.Add_Tail(*commands);
  4340. cancelbtn.Add_Tail(*commands);
  4341. gamelist.Add_Tail(*commands);
  4342. playerlist.Add_Tail(*commands);
  4343. countgauge.Add_Tail(*commands);
  4344. levelgauge.Add_Tail(*commands);
  4345. creditsgauge.Add_Tail(*commands);
  4346. aiplayersgauge.Add_Tail(*commands);
  4347. optionlist.Add_Tail(*commands);
  4348. #ifdef OLDWAY
  4349. gdibtn.Add_Tail(*commands);
  4350. nodbtn.Add_Tail(*commands);
  4351. #else //OLDWAY
  4352. housebtn.Add_Tail(*commands);
  4353. #endif //OLDWAY
  4354. //------------------------------------------------------------------------
  4355. // Init the button states
  4356. //------------------------------------------------------------------------
  4357. //........................................................................
  4358. // Name & Color
  4359. //........................................................................
  4360. Session.ColorIdx = Session.PrefColor; // init my preferred color
  4361. strcpy (namebuf, Session.Handle); // set my name
  4362. name_edt.Set_Text(namebuf,MPLAYER_NAME_MAX);
  4363. name_edt.Set_Color(&ColorRemaps[(Session.ColorIdx == PCOLOR_DIALOG_BLUE) ? PCOLOR_REALLY_BLUE : Session.ColorIdx]);
  4364. //........................................................................
  4365. // List boxes
  4366. //........................................................................
  4367. playerlist.Set_Tabs(playertabs);
  4368. playerlist.Set_Selected_Style(ColorListClass::SELECT_NORMAL);
  4369. optionlist.Set_Tabs(optiontabs);
  4370. optionlist.Set_Read_Only(1);
  4371. optionlist.Add_Item(Text_String(TXT_BASES));
  4372. optionlist.Add_Item(Text_String(TXT_ORE_SPREADS));
  4373. optionlist.Add_Item(Text_String(TXT_CRATES));
  4374. optionlist.Add_Item(Text_String(TXT_CAPTURE_THE_FLAG));
  4375. optionlist.Add_Item(Text_String(TXT_SHADOW_REGROWS));
  4376. optionlist.Check_Item(0, Session.Options.Bases);
  4377. optionlist.Check_Item(1, Session.Options.Tiberium);
  4378. optionlist.Check_Item(2, Session.Options.Goodies);
  4379. optionlist.Check_Item(3, Special.IsCaptureTheFlag);
  4380. optionlist.Check_Item(4, Special.IsShadowGrow);
  4381. //........................................................................
  4382. // House buttons
  4383. //........................................................................
  4384. #ifdef OLDWAY
  4385. if (Session.House==HOUSE_GOOD) {
  4386. gdibtn.Turn_On();
  4387. } else {
  4388. nodbtn.Turn_On();
  4389. }
  4390. #else //OLDWAY
  4391. for (HousesType house = HOUSE_USSR; house <= HOUSE_FRANCE; house++) {
  4392. housebtn.Add_Item(Text_String(HouseTypeClass::As_Reference(house).Full_Name()));
  4393. }
  4394. housebtn.Set_Selected_Index(Session.House - HOUSE_USSR);
  4395. housebtn.Set_Read_Only (true);
  4396. #endif //OLDWAY
  4397. //........................................................................
  4398. // Option gauges
  4399. //........................................................................
  4400. countgauge.Use_Thumb(0);
  4401. countgauge.Set_Maximum(SessionClass::CountMax[Session.Options.Bases] - SessionClass::CountMin[Session.Options.Bases]);
  4402. countgauge.Set_Value(Session.Options.UnitCount - SessionClass::CountMin[Session.Options.Bases]);
  4403. levelgauge.Use_Thumb(0);
  4404. levelgauge.Set_Maximum(MPLAYER_BUILD_LEVEL_MAX - 1);
  4405. levelgauge.Set_Value(BuildLevel - 1);
  4406. creditsgauge.Use_Thumb(0);
  4407. creditsgauge.Set_Maximum(Rule.MPMaxMoney);
  4408. creditsgauge.Set_Value(Session.Options.Credits);
  4409. aiplayersgauge.Use_Thumb(0);
  4410. aiplayersgauge.Set_Maximum(Rule.MaxPlayers-2);
  4411. aiplayersgauge.Set_Value(Session.Options.AIPlayers);
  4412. Fancy_Text_Print("", 0, 0, scheme, TBLACK, TPF_CENTER | TPF_TEXT);
  4413. transmit = true;
  4414. first = true;
  4415. /*........................................................................
  4416. Clear the Players vector
  4417. ........................................................................*/
  4418. Clear_Vector(&Session.Players);
  4419. /*........................................................................
  4420. Init the message display system
  4421. ........................................................................*/
  4422. Session.Messages.Init (d_message_x + 1, d_message_y + 1, 7,
  4423. MAX_MESSAGE_LENGTH, d_txt6_h, d_send_x + 1 * RESFACTOR, d_send_y + 1 * RESFACTOR, 1,
  4424. 20, MAX_MESSAGE_LENGTH - 5, d_message_w);
  4425. Session.Messages.Add_Edit ((Session.ColorIdx == PCOLOR_DIALOG_BLUE) ? PCOLOR_REALLY_BLUE : Session.ColorIdx,
  4426. TPF_TEXT, NULL, '_', d_message_w);
  4427. Session.WWChat = 0;
  4428. /*........................................................................
  4429. Init version number clipping system
  4430. ........................................................................*/
  4431. VerNum.Init_Clipping();
  4432. Load_Title_Page(true);
  4433. CCPalette.Set();
  4434. extern char ModemRXString[];
  4435. if (strlen(ModemRXString) > 36)
  4436. ModemRXString[36] = 0;
  4437. if (strlen(ModemRXString) > 0)
  4438. Session.Messages.Add_Message (NULL, 0, ModemRXString, PCOLOR_BROWN,
  4439. TPF_TEXT, -1);
  4440. ModemRXString[0] = '\0';
  4441. /*
  4442. ---------------------------- Init Mono Output ----------------------------
  4443. */
  4444. #if(SHOW_MONO)
  4445. NullModem.Configure_Debug(sizeof (CommHeaderType),sizeof (SerialCommandType),
  4446. SerialPacketNames, 100, 8);
  4447. NullModem.Mono_Debug_Print(1);
  4448. #endif
  4449. /*
  4450. ---------------------------- Processing loop -----------------------------
  4451. */
  4452. NullModem.Reset_Response_Time(); // clear response time
  4453. timingtime = lastmsgtime = lastredrawtime = TickCount;
  4454. bool process = true; // process while true
  4455. while (process) {
  4456. #if(SHOW_MONO)
  4457. NullModem.Mono_Debug_Print(0);
  4458. #endif
  4459. /*
  4460. ** Kludge to make sure we redraw the message input line when it loses focus.
  4461. ** If we dont do this then the cursor doesnt disappear.
  4462. */
  4463. if (messages_have_focus) {
  4464. if (name_edt.Has_Focus()) {
  4465. if (display < REDRAW_MESSAGE) display = REDRAW_MESSAGE;
  4466. messages_have_focus = false;
  4467. }
  4468. } else {
  4469. if (!name_edt.Has_Focus()) {
  4470. messages_have_focus = true;
  4471. if (display < REDRAW_MESSAGE) display = REDRAW_MESSAGE;
  4472. Session.Messages.Set_Edit_Focus();
  4473. }
  4474. }
  4475. /*
  4476. ........................ Invoke game callback .........................
  4477. */
  4478. Call_Back();
  4479. #ifdef WIN32
  4480. /*
  4481. ** If we have just received input focus again after running in the background then
  4482. ** we need to redraw.
  4483. */
  4484. if (AllSurfaces.SurfacesRestored) {
  4485. AllSurfaces.SurfacesRestored=FALSE;
  4486. display = REDRAW_ALL;
  4487. }
  4488. #endif
  4489. /*
  4490. ...................... Refresh display if needed ......................
  4491. */
  4492. if (display) {
  4493. if (housebtn.IsDropped) {
  4494. housebtn.Collapse();
  4495. display = REDRAW_BACKGROUND;
  4496. }
  4497. Hide_Mouse();
  4498. /*
  4499. .................. Redraw backgound & dialog box ...................
  4500. */
  4501. if (display >= REDRAW_BACKGROUND) {
  4502. Dialog_Box(d_dialog_x, d_dialog_y, d_dialog_w, d_dialog_h);
  4503. /*...............................................................
  4504. Dialog & Field labels
  4505. ...............................................................*/
  4506. Fancy_Text_Print(TXT_CHANNEL_GAMES, d_gamelist_x + (d_gamelist_w / 2), d_gamelist_y - d_txt6_h, scheme, TBLACK, TPF_CENTER | TPF_TEXT);
  4507. Fancy_Text_Print(TXT_PLAYERS, d_playerlist_x + (d_playerlist_w / 2), d_playerlist_y - d_txt6_h, scheme, TBLACK, TPF_CENTER | TPF_TEXT);
  4508. Fancy_Text_Print(TXT_YOUR_NAME, d_name_x + (d_name_w / 2), d_name_y - d_txt6_h, scheme, TBLACK, TPF_CENTER | TPF_TEXT);
  4509. #ifdef OLDWAY
  4510. Fancy_Text_Print(TXT_SIDE_COLON, d_gdi_x + d_gdi_w, d_gdi_y - d_txt6_h, scheme, TBLACK, TPF_CENTER | TPF_TEXT);
  4511. #else
  4512. Fancy_Text_Print(TXT_SIDE_COLON, d_house_x + (d_house_w / 2), d_house_y - d_txt6_h, scheme, TBLACK, TPF_CENTER | TPF_TEXT);
  4513. #endif
  4514. Fancy_Text_Print(TXT_COLOR_COLON, d_dialog_x + ((d_dialog_w / 4) * 3), d_color_y - d_txt6_h, scheme, TBLACK, TPF_CENTER | TPF_TEXT);
  4515. Fancy_Text_Print (TXT_COUNT, d_count_x - 2 * RESFACTOR, d_count_y, scheme, TBLACK, TPF_TEXT | TPF_RIGHT);
  4516. Fancy_Text_Print (TXT_LEVEL, d_level_x - 2 * RESFACTOR, d_level_y, scheme, TBLACK, TPF_TEXT | TPF_RIGHT);
  4517. Fancy_Text_Print (TXT_CREDITS_COLON, d_credits_x - 2 * RESFACTOR, d_credits_y, scheme, TBLACK, TPF_TEXT | TPF_RIGHT);
  4518. Fancy_Text_Print (TXT_AI_PLAYERS_COLON, d_aiplayers_x - 2 * RESFACTOR, d_aiplayers_y, scheme, TBLACK, TPF_TEXT | TPF_RIGHT);
  4519. }
  4520. /*..................................................................
  4521. Draw the color boxes
  4522. ..................................................................*/
  4523. if (display >= REDRAW_COLORS) {
  4524. for (i = 0; i < MAX_MPLAYER_COLORS; i++) {
  4525. LogicPage->Fill_Rect (cbox_x[i] + 1 * RESFACTOR, d_color_y + 1 * RESFACTOR,
  4526. cbox_x[i] + 1 * RESFACTOR + d_color_w - 2 * RESFACTOR, d_color_y + 1 * RESFACTOR + d_color_h - 2 * RESFACTOR,
  4527. ColorRemaps[i].Box);
  4528. // (i == PCOLOR_DIALOG_BLUE) ? ColorRemaps[PCOLOR_REALLY_BLUE].Box : ColorRemaps[i].Box);
  4529. if (i == Session.ColorIdx) {
  4530. Draw_Box(cbox_x[i], d_color_y, d_color_w, d_color_h,
  4531. BOXSTYLE_DOWN, false);
  4532. } else {
  4533. Draw_Box(cbox_x[i], d_color_y, d_color_w, d_color_h,
  4534. BOXSTYLE_RAISED, false);
  4535. }
  4536. }
  4537. }
  4538. /*..................................................................
  4539. Draw the message system; erase old messages first
  4540. ..................................................................*/
  4541. if (display >= REDRAW_MESSAGE) {
  4542. Draw_Box(d_message_x, d_message_y, d_message_w, d_message_h,
  4543. BOXSTYLE_BOX, true);
  4544. Draw_Box(d_send_x, d_send_y, d_send_w, d_send_h,
  4545. BOXSTYLE_BOX, true);
  4546. Session.Messages.Draw();
  4547. //..................................................................
  4548. // Redraw the game options
  4549. //..................................................................
  4550. if (display >= REDRAW_PARMS && parms_received) {
  4551. if (oppscorescreen) {
  4552. sprintf(txt,"%s",Text_String(TXT_WAITING_FOR_OPPONENT));
  4553. int txtwidth = String_Pixel_Width( txt );
  4554. Fancy_Text_Print(txt, d_dialog_cx, d_scenario_y, scheme, TBLACK, TPF_CENTER | TPF_TEXT);
  4555. } else {
  4556. /*............................................................
  4557. Scenario description
  4558. ............................................................*/
  4559. //LogicPage->Fill_Rect(d_dialog_x + 16*RESFACTOR, d_scenario_y,
  4560. // d_dialog_x + d_dialog_w - 16*RESFACTOR, d_scenario_y + d_txt6_h, BLACK);
  4561. p = (char *)Text_String(TXT_SCENARIO_COLON);
  4562. if (Session.Options.ScenarioDescription[0]) {
  4563. // sprintf(txt,"%s %s",p, Session.Options.ScenarioDescription);
  4564. // Fancy_Text_Print (txt, d_dialog_cx, d_scenario_y, scheme, TBLACK, TPF_TEXT | TPF_CENTER);
  4565. // EW - Scenario language translation goes here!!!!!!!! VG
  4566. for (i = 0; EngMisStr[i] != NULL; i++) {
  4567. if (!strcmp(Session.Options.ScenarioDescription, EngMisStr[i])) {
  4568. #if defined(GERMAN) || defined(FRENCH)
  4569. sprintf(txt, "%s %s", p, EngMisStr[i+1]);
  4570. #else
  4571. sprintf(txt, "%s %s", p, Session.Options.ScenarioDescription);
  4572. #endif
  4573. break;
  4574. }
  4575. }
  4576. if (EngMisStr[i] == NULL) {
  4577. sprintf(txt, "%s %s", p, Session.Options.ScenarioDescription);
  4578. }
  4579. Fancy_Text_Print (txt, d_dialog_cx, d_scenario_y, scheme, TBLACK, TPF_TEXT | TPF_CENTER);
  4580. } else {
  4581. sprintf(txt,"%s %s",p,Text_String(TXT_NOT_FOUND));
  4582. Fancy_Text_Print (txt, d_dialog_cx, d_scenario_y, &ColorRemaps[PCOLOR_RED], TBLACK, TPF_TEXT | TPF_CENTER);
  4583. }
  4584. //.........................................................
  4585. // Unit count, tech level, credits
  4586. //.........................................................
  4587. //LogicPage->Fill_Rect(d_count_x + d_count_w + 2 * RESFACTOR, d_count_y,
  4588. // d_count_x + d_count_w + 35 * RESFACTOR, d_aiplayers_y + d_aiplayers_h+RESFACTOR,
  4589. // BLACK);
  4590. sprintf(staticcountbuff, "%d", Session.Options.UnitCount);
  4591. staticcount.Set_Text(staticcountbuff);
  4592. staticcount.Draw_Me();
  4593. if (BuildLevel <= MPLAYER_BUILD_LEVEL_MAX) {
  4594. sprintf(staticlevelbuff, "%d ", BuildLevel);
  4595. } else {
  4596. sprintf(staticlevelbuff, "**");
  4597. }
  4598. staticlevel.Set_Text(staticlevelbuff);
  4599. staticlevel.Draw_Me();
  4600. sprintf(staticcreditsbuff, "%d", Session.Options.Credits);
  4601. staticcredits.Set_Text(staticcreditsbuff);
  4602. staticcredits.Draw_Me();
  4603. sprintf(staticaibuff, "%d", Session.Options.AIPlayers);
  4604. staticai.Set_Text(staticaibuff);
  4605. staticai.Draw_Me();
  4606. }
  4607. }
  4608. }
  4609. /*
  4610. .......................... Redraw buttons ..........................
  4611. */
  4612. if (display >= REDRAW_BUTTONS) {
  4613. commands->Flag_List_To_Redraw();
  4614. }
  4615. Show_Mouse();
  4616. display = REDRAW_NONE;
  4617. }
  4618. /*
  4619. ........................... Get user input ............................
  4620. */
  4621. messages_have_focus = Session.Messages.Has_Edit_Focus();
  4622. bool droplist_is_dropped = housebtn.IsDropped;
  4623. KeyNumType input = commands->Input();
  4624. /*
  4625. ** Sort out the input focus between the name edit box and the message system
  4626. */
  4627. if (messages_have_focus) {
  4628. if (!name_edt.Has_Focus()) {
  4629. Session.Messages.Set_Edit_Focus();
  4630. } else {
  4631. messages_have_focus = false;
  4632. if (display < REDRAW_MESSAGE) display = REDRAW_MESSAGE;
  4633. }
  4634. }
  4635. /*
  4636. ** Redraw everything if the droplist collapsed
  4637. */
  4638. if (droplist_is_dropped && !housebtn.IsDropped) {
  4639. display = REDRAW_BACKGROUND;
  4640. }
  4641. /*
  4642. ---------------------------- Process input ----------------------------
  4643. */
  4644. switch (input) {
  4645. /*------------------------------------------------------------------
  4646. User clicks on a color button
  4647. ------------------------------------------------------------------*/
  4648. case KN_LMOUSE:
  4649. if (Keyboard->MouseQX > cbox_x[0] &&
  4650. Keyboard->MouseQX < (cbox_x[MAX_MPLAYER_COLORS - 1] + d_color_w) &&
  4651. Keyboard->MouseQY > d_color_y &&
  4652. Keyboard->MouseQY < (d_color_y + d_color_h)) {
  4653. /*.........................................................
  4654. Compute my preferred color as the one I clicked on.
  4655. .........................................................*/
  4656. Session.PrefColor = (PlayerColorType)
  4657. ((Keyboard->MouseQX - cbox_x[0]) / d_color_w);
  4658. changed = true;
  4659. /*.........................................................
  4660. If 'TheirColor' is set to the other player's color, make
  4661. sure we can't pick that color.
  4662. .........................................................*/
  4663. if (parms_received) {
  4664. if (Session.PrefColor == TheirColor)
  4665. break;
  4666. }
  4667. Session.ColorIdx = Session.PrefColor;
  4668. name_edt.Set_Color(&ColorRemaps[(Session.ColorIdx == PCOLOR_DIALOG_BLUE) ?
  4669. PCOLOR_REALLY_BLUE : Session.ColorIdx]);
  4670. name_edt.Flag_To_Redraw();
  4671. Session.Messages.Set_Edit_Color((Session.ColorIdx == PCOLOR_DIALOG_BLUE) ?
  4672. PCOLOR_REALLY_BLUE : Session.ColorIdx);
  4673. if (display < REDRAW_COLORS) display = REDRAW_COLORS;
  4674. strcpy (Session.Handle, namebuf);
  4675. transmit = true;
  4676. if (housebtn.IsDropped) {
  4677. housebtn.Collapse();
  4678. display = REDRAW_BACKGROUND;
  4679. }
  4680. } else if ( (Get_Mouse_X() >= d_count_x &&
  4681. Get_Mouse_X() <= d_count_x + d_count_w &&
  4682. Get_Mouse_Y() >= d_count_y &&
  4683. Get_Mouse_Y() <= d_aiplayers_y + d_aiplayers_h) ||
  4684. (Get_Mouse_X() >= d_options_x &&
  4685. Get_Mouse_X() <= d_options_x + d_options_w &&
  4686. Get_Mouse_Y() >= d_options_y &&
  4687. Get_Mouse_Y() <= d_options_y + d_options_h) ) {
  4688. Session.Messages.Add_Message(NULL, 0, (char *)Text_String(TXT_ONLY_HOST_CAN_MODIFY), PCOLOR_BROWN, TPF_TEXT, 1200);
  4689. Sound_Effect(VOC_SYS_ERROR);
  4690. if (display < REDRAW_MESSAGE) display = REDRAW_MESSAGE;
  4691. if (housebtn.IsDropped) {
  4692. housebtn.Collapse();
  4693. display = REDRAW_BACKGROUND;
  4694. }
  4695. }
  4696. break;
  4697. #ifdef OLDWAY
  4698. /*------------------------------------------------------------------
  4699. House Buttons: set the player's desired House
  4700. ------------------------------------------------------------------*/
  4701. case (BUTTON_GDI | KN_BUTTON):
  4702. Session.House = HOUSE_GOOD;
  4703. gdibtn.Turn_On();
  4704. nodbtn.Turn_Off();
  4705. strcpy (Session.Handle, namebuf);
  4706. transmit = true;
  4707. break;
  4708. case (BUTTON_NOD | KN_BUTTON):
  4709. Session.House = HOUSE_BAD;
  4710. gdibtn.Turn_Off();
  4711. nodbtn.Turn_On();
  4712. strcpy (Session.Handle, namebuf);
  4713. transmit = true;
  4714. break;
  4715. #else //OLDWAY
  4716. case (BUTTON_HOUSE | KN_BUTTON):
  4717. Session.House = HousesType(housebtn.Current_Index()+HOUSE_USSR);
  4718. strcpy (Session.Handle, namebuf);
  4719. transmit = true;
  4720. //display = REDRAW_BACKGROUND;
  4721. break;
  4722. #endif //OLDWAY
  4723. /*------------------------------------------------------------------
  4724. User edits the name value; retransmit
  4725. ------------------------------------------------------------------*/
  4726. case (BUTTON_NAME | KN_BUTTON):
  4727. if (housebtn.IsDropped) {
  4728. housebtn.Collapse();
  4729. display = REDRAW_BACKGROUND;
  4730. }
  4731. strcpy (Session.Handle, namebuf);
  4732. transmit = true;
  4733. changed = true;
  4734. break;
  4735. /*------------------------------------------------------------------
  4736. CANCEL: send a SIGN_OFF, bail out with error code
  4737. ------------------------------------------------------------------*/
  4738. case (KN_ESC):
  4739. case (BUTTON_CANCEL | KN_BUTTON):
  4740. process = false;
  4741. rc = false;
  4742. break;
  4743. /*------------------------------------------------------------------
  4744. Default: manage the inter-player messages
  4745. ------------------------------------------------------------------*/
  4746. default:
  4747. if (Session.Messages.Manage()) {
  4748. if (display < REDRAW_MESSAGE) display = REDRAW_MESSAGE;
  4749. }
  4750. /*...............................................................
  4751. Service keyboard input for any message being edited.
  4752. ...............................................................*/
  4753. i = Session.Messages.Input(input);
  4754. /*...............................................................
  4755. If 'Input' returned 1, it means refresh the message display.
  4756. (We have to redraw the edit line, to erase the cursor.)
  4757. ...............................................................*/
  4758. if (i==1) {
  4759. Hide_Mouse();
  4760. Draw_Box(d_send_x, d_send_y, d_send_w, d_send_h,
  4761. BOXSTYLE_BOX, true);
  4762. Session.Messages.Draw();
  4763. Show_Mouse();
  4764. } else if (i==2) {
  4765. /*...............................................................
  4766. If 'Input' returned 2, it means redraw the message display.
  4767. Rather than setting 'display', which would redraw all msgs,
  4768. we only need to erase & redraw the edit box here.
  4769. ...............................................................*/
  4770. Hide_Mouse();
  4771. Draw_Box(d_send_x, d_send_y, d_send_w, d_send_h,
  4772. BOXSTYLE_BOX, true);
  4773. Session.Messages.Draw();
  4774. Show_Mouse();
  4775. } else if (i==3 || i==4) {
  4776. /*...............................................................
  4777. If 'input' returned 3, it means send the current message.
  4778. ...............................................................*/
  4779. memset (&SendPacket, 0, sizeof(SerialPacketType));
  4780. SendPacket.Command = SERIAL_MESSAGE;
  4781. strcpy (SendPacket.Name, namebuf);
  4782. SendPacket.ID = Session.ColorIdx;
  4783. if (i==3) {
  4784. strcpy (SendPacket.Message.Message, Session.Messages.Get_Edit_Buf());
  4785. } else {
  4786. strcpy (SendPacket.Message.Message, Session.Messages.Get_Overflow_Buf());
  4787. Session.Messages.Clear_Overflow_Buf();
  4788. }
  4789. /*..................................................................
  4790. Send the message
  4791. ..................................................................*/
  4792. NullModem.Send_Message (&SendPacket, sizeof(SendPacket), 1);
  4793. NullModem.Service();
  4794. /*..................................................................
  4795. Add the message to our own screen
  4796. ..................................................................*/
  4797. Session.Messages.Add_Message (SendPacket.Name, SendPacket.ID,
  4798. SendPacket.Message.Message,
  4799. (Session.ColorIdx == PCOLOR_DIALOG_BLUE) ? PCOLOR_REALLY_BLUE : Session.ColorIdx,
  4800. TPF_TEXT, -1);
  4801. Session.Messages.Add_Edit((Session.ColorIdx == PCOLOR_DIALOG_BLUE) ?
  4802. PCOLOR_REALLY_BLUE : Session.ColorIdx,
  4803. TPF_TEXT, NULL, '_', d_message_w);
  4804. if (display < REDRAW_MESSAGE) display = REDRAW_MESSAGE;
  4805. }
  4806. break;
  4807. }
  4808. /*---------------------------------------------------------------------
  4809. Detect editing of the name buffer, transmit new values to players
  4810. ---------------------------------------------------------------------*/
  4811. if (strcmp (namebuf, Session.Handle)) {
  4812. strcpy (Session.Handle, namebuf);
  4813. transmit = true;
  4814. changed = true;
  4815. }
  4816. /*---------------------------------------------------------------------
  4817. If our Transmit flag is set, we need to send out a game option packet
  4818. ---------------------------------------------------------------------*/
  4819. if (transmit && (TickCount - transmittime) > PACKET_RETRANS_TIME) {
  4820. memset (&SendPacket, 0, sizeof(SerialPacketType));
  4821. SendPacket.Command = SERIAL_GAME_OPTIONS;
  4822. strcpy (SendPacket.Name, namebuf);
  4823. SendPacket.ScenarioInfo.CheatCheck = RuleINI.Get_Unique_ID();
  4824. SendPacket.ScenarioInfo.MinVersion = VerNum.Min_Version();
  4825. SendPacket.ScenarioInfo.MaxVersion = VerNum.Max_Version();
  4826. SendPacket.ScenarioInfo.House = Session.House;
  4827. SendPacket.ScenarioInfo.Color = Session.ColorIdx;
  4828. SendPacket.ID = Session.ModemType;
  4829. NullModem.Send_Message (&SendPacket, sizeof(SendPacket), 1);
  4830. transmittime = TickCount;
  4831. transmit = false;
  4832. //..................................................................
  4833. // Keep the player list up to date
  4834. //..................................................................
  4835. if (playerlist.Count()) {
  4836. item = (char *)playerlist.Get_Item(0);
  4837. #ifdef OLDWAY
  4838. if (Session.House==HOUSE_GOOD) {
  4839. sprintf(item,"%s\t%s",namebuf,
  4840. Text_String(TXT_ALLIES));
  4841. } else {
  4842. sprintf(item,"%s\t%s",namebuf,
  4843. Text_String(TXT_SOVIET));
  4844. }
  4845. #else //OLDWAY
  4846. sprintf (item, "%s\t%s", namebuf, Text_String(HouseTypeClass::As_Reference(Session.House).Full_Name()));
  4847. #endif //OLDWAY
  4848. playerlist.Colors[0] = &ColorRemaps[(Session.ColorIdx == PCOLOR_DIALOG_BLUE) ?
  4849. PCOLOR_REALLY_BLUE : Session.ColorIdx];
  4850. playerlist.Flag_To_Redraw();
  4851. }
  4852. //..................................................................
  4853. // Play a little sound effect
  4854. //..................................................................
  4855. Sound_Effect(VOC_OPTIONS_CHANGED);
  4856. }
  4857. //
  4858. // send a timing packet if enough time has gone by.
  4859. //
  4860. if ((TickCount - timingtime) > PACKET_TIMING_TIMEOUT) {
  4861. memset (&SendPacket, 0, sizeof(SerialPacketType));
  4862. SendPacket.Command = SERIAL_TIMING;
  4863. SendPacket.ScenarioInfo.ResponseTime = NullModem.Response_Time();
  4864. SendPacket.ID = Session.ModemType;
  4865. NullModem.Send_Message (&SendPacket, sizeof(SendPacket), 0);
  4866. timingtime = TickCount;
  4867. }
  4868. /*---------------------------------------------------------------------
  4869. Check for an incoming message
  4870. ---------------------------------------------------------------------*/
  4871. if (NullModem.Get_Message(&ReceivePacket, &packetlen) > 0) {
  4872. lastmsgtime = TickCount;
  4873. msg_timeout = 600;
  4874. // are we getting our own packets back??
  4875. if (ReceivePacket.Command >= SERIAL_CONNECT &&
  4876. ReceivePacket.Command < SERIAL_LAST_COMMAND &&
  4877. ReceivePacket.Command != SERIAL_MESSAGE &&
  4878. ReceivePacket.ID == Session.ModemType) {
  4879. WWMessageBox().Process (TXT_SYSTEM_NOT_RESPONDING);
  4880. // to skip the other system not responding msg
  4881. lastmsgtime = TickCount;
  4882. process = false;
  4883. rc = false;
  4884. // say we did receive sign off to keep from sending one
  4885. recsignedoff = true;
  4886. break;
  4887. }
  4888. event = (EventClass *)&ReceivePacket;
  4889. if (event->Type <= EventClass::FRAMEINFO) {
  4890. if ( (TickCount - lastredrawtime) > PACKET_REDRAW_TIME) {
  4891. lastredrawtime = TickCount;
  4892. oppscorescreen = true;
  4893. if (display < REDRAW_MESSAGE) display = REDRAW_MESSAGE;
  4894. parms_received = true;
  4895. }
  4896. } else {
  4897. switch ( ReceivePacket.Command ) {
  4898. /*..................................................................
  4899. Other system signs off: Give it time to receive my ACK, then show
  4900. a message.
  4901. ..................................................................*/
  4902. case (SERIAL_SIGN_OFF):
  4903. starttime = TickCount;
  4904. while ( (TickCount - starttime) < 60)
  4905. NullModem.Service();
  4906. WWMessageBox().Process(TXT_USER_SIGNED_OFF);
  4907. // to skip the other system not responding msg
  4908. lastmsgtime = TickCount;
  4909. process = false;
  4910. rc = false;
  4911. recsignedoff = true;
  4912. break;
  4913. /*..................................................................
  4914. Game Options: Store all options; check my color & game version.
  4915. ..................................................................*/
  4916. case (SERIAL_GAME_OPTIONS):
  4917. oppscorescreen = false;
  4918. gameoptions = true;
  4919. if (display < REDRAW_MESSAGE) display = REDRAW_MESSAGE;
  4920. parms_received = true;
  4921. strcpy (TheirName, ReceivePacket.Name);
  4922. TheirColor = ReceivePacket.ScenarioInfo.Color;
  4923. TheirHouse = ReceivePacket.ScenarioInfo.House;
  4924. /*...............................................................
  4925. Make sure I don't have the same color as the other guy.
  4926. ...............................................................*/
  4927. if (Session.ColorIdx == TheirColor) {
  4928. // force transmitting of game options packet
  4929. transmit = true;
  4930. transmittime = 0;
  4931. Session.ColorIdx = (PlayerColorType)(TheirColor + 1);
  4932. if (Session.ColorIdx >= 6) {
  4933. Session.ColorIdx = PCOLOR_FIRST;
  4934. }
  4935. name_edt.Set_Color(&ColorRemaps[(Session.ColorIdx == PCOLOR_DIALOG_BLUE) ? PCOLOR_REALLY_BLUE : Session.ColorIdx]);
  4936. name_edt.Flag_To_Redraw();
  4937. if (display < REDRAW_COLORS) display = REDRAW_COLORS;
  4938. if (housebtn.IsDropped) {
  4939. housebtn.Collapse();
  4940. display = REDRAW_BACKGROUND;
  4941. }
  4942. }
  4943. /*...............................................................
  4944. Save scenario settings.
  4945. ...............................................................*/
  4946. Session.Options.Credits = ReceivePacket.ScenarioInfo.Credits;
  4947. Session.Options.Bases = ReceivePacket.ScenarioInfo.IsBases;
  4948. Session.Options.Tiberium = ReceivePacket.ScenarioInfo.IsTiberium;
  4949. Session.Options.Goodies = ReceivePacket.ScenarioInfo.IsGoodies;
  4950. Session.Options.AIPlayers = ReceivePacket.ScenarioInfo.AIPlayers;
  4951. BuildLevel = ReceivePacket.ScenarioInfo.BuildLevel;
  4952. Session.Options.UnitCount = ReceivePacket.ScenarioInfo.UnitCount;
  4953. Seed = ReceivePacket.ScenarioInfo.Seed;
  4954. Special = ReceivePacket.ScenarioInfo.Special;
  4955. Options.GameSpeed = ReceivePacket.ScenarioInfo.GameSpeed;
  4956. if (Session.Options.Tiberium) {
  4957. Special.IsTGrowth = true;
  4958. Rule.IsTGrowth = true;
  4959. Special.IsTSpread = true;
  4960. Rule.IsTSpread = true;
  4961. } else {
  4962. Special.IsTGrowth = false;
  4963. Rule.IsTGrowth = false;
  4964. Special.IsTSpread = false;
  4965. Rule.IsTSpread = false;
  4966. }
  4967. //.........................................................
  4968. // Adjust the gauges
  4969. //.........................................................
  4970. countgauge.Set_Maximum(
  4971. SessionClass::CountMax[Session.Options.Bases] -
  4972. SessionClass::CountMin[Session.Options.Bases]);
  4973. countgauge.Set_Value(Session.Options.UnitCount -
  4974. SessionClass::CountMin[Session.Options.Bases]);
  4975. levelgauge.Set_Value(BuildLevel - 1);
  4976. creditsgauge.Set_Value(Session.Options.Credits);
  4977. aiplayersgauge.Set_Value(Session.Options.AIPlayers);
  4978. //.........................................................
  4979. // Update the options list box
  4980. //.........................................................
  4981. optionlist.Check_Item(0, Session.Options.Bases);
  4982. optionlist.Check_Item(1, Session.Options.Tiberium);
  4983. optionlist.Check_Item(2, Session.Options.Goodies);
  4984. optionlist.Check_Item(3, Special.IsCaptureTheFlag);
  4985. optionlist.Check_Item(4, Special.IsShadowGrow);
  4986. optionlist.Flag_To_Redraw();
  4987. /*
  4988. ** If the scenario name changed then we need to redraw the whole lot.
  4989. */
  4990. if (strcmp (Session.Options.ScenarioDescription, ReceivePacket.ScenarioInfo.Scenario)) {
  4991. if (display < REDRAW_BACKGROUND) display = REDRAW_BACKGROUND;
  4992. }
  4993. /*...............................................................
  4994. Copy the information about the scenario that the host wants to
  4995. play so ee can request this scenario from the host if we don't
  4996. have it locally.
  4997. ...............................................................*/
  4998. strcpy (Session.Options.ScenarioDescription, ReceivePacket.ScenarioInfo.Scenario);
  4999. strcpy (Session.ScenarioFileName, ReceivePacket.ScenarioInfo.ShortFileName);
  5000. #ifdef WOLAPI_INTEGRATION
  5001. strncpy (Session.ScenarioDigest, (char*)ReceivePacket.ScenarioInfo.FileDigest, sizeof( ReceivePacket.ScenarioInfo.FileDigest ));
  5002. #else
  5003. strcpy (Session.ScenarioDigest, (char*)ReceivePacket.ScenarioInfo.FileDigest);
  5004. #endif
  5005. Session.ScenarioIsOfficial = ReceivePacket.ScenarioInfo.OfficialScenario;
  5006. Session.ScenarioFileLength = ReceivePacket.ScenarioInfo.FileLength;
  5007. //.........................................................
  5008. // "Clip" the other system's version range to our own
  5009. // ........................................................
  5010. version = VerNum.Clip_Version(ReceivePacket.ScenarioInfo.MinVersion,
  5011. ReceivePacket.ScenarioInfo.MaxVersion);
  5012. // ........................................................
  5013. // If the greatest-common-version comes back 0, the other
  5014. // system's range is too low for ours
  5015. // ........................................................
  5016. if (version == 0) {
  5017. WWMessageBox().Process (TXT_DESTGAME_OUTDATED);
  5018. // to skip the other system not responding msg
  5019. lastmsgtime = TickCount;
  5020. process = false;
  5021. rc = false;
  5022. } else if (version == 0xffffffff) {
  5023. // ........................................................
  5024. // If the greatest-common-version comes back 0xffffffff,
  5025. // the other system's range is too high for ours
  5026. // ........................................................
  5027. WWMessageBox().Process (TXT_YOURGAME_OUTDATED);
  5028. // to skip the other system not responding msg
  5029. lastmsgtime = TickCount;
  5030. process = false;
  5031. rc = false;
  5032. }
  5033. // ........................................................
  5034. // Otherwise, 'version' is the highest version we have in
  5035. // common; look up the protocol that goes with this version.
  5036. // ........................................................
  5037. else {
  5038. if (ReceivePacket.ScenarioInfo.CheatCheck != RuleINI.Get_Unique_ID()) {
  5039. WWMessageBox().Process(TXT_MISMATCH);
  5040. // to skip the other system not responding msg
  5041. lastmsgtime = TickCount;
  5042. process = false;
  5043. rc = false;
  5044. } else {
  5045. Session.CommProtocol = VerNum.Version_Protocol(version);
  5046. #ifndef FIXIT_VERSION_3
  5047. PlayingAgainstVersion = version;
  5048. #endif
  5049. }
  5050. }
  5051. /*.........................................................
  5052. If this is the first game-options packet we've received,
  5053. init the game & player lists, then transmit our options
  5054. to him.
  5055. .........................................................*/
  5056. if (first) {
  5057. //......................................................
  5058. // Add a string to the game list, and two to the player
  5059. // list
  5060. //......................................................
  5061. item = new char [MPLAYER_NAME_MAX + 64];
  5062. gamelist.Add_Item(item);
  5063. item = new char [MPLAYER_NAME_MAX + 64]; //Need room to display country name
  5064. playerlist.Add_Item(item,
  5065. &ColorRemaps[(Session.ColorIdx == PCOLOR_DIALOG_BLUE) ?
  5066. PCOLOR_REALLY_BLUE : Session.ColorIdx]);
  5067. item = new char [MPLAYER_NAME_MAX + 64]; //Need room to display country name
  5068. playerlist.Add_Item(item,
  5069. &ColorRemaps[(TheirColor == PCOLOR_DIALOG_BLUE) ? PCOLOR_REALLY_BLUE : TheirColor]);
  5070. first = false;
  5071. transmit = true;
  5072. transmittime = 0;
  5073. }
  5074. //.........................................................
  5075. // Ensure the game list & player list have the latest,
  5076. // greatest copy of our names & colors. Do this every time
  5077. // we receive an options packet.
  5078. //.........................................................
  5079. item = (char *)gamelist.Get_Item(0);
  5080. sprintf(item,Text_String(TXT_THATGUYS_GAME),
  5081. TheirName);
  5082. item = (char *)playerlist.Get_Item(0);
  5083. #ifdef OLDWAY
  5084. if (Session.House==HOUSE_GOOD) {
  5085. sprintf(item,"%s\t%s",namebuf,
  5086. Text_String(TXT_ALLIES));
  5087. } else {
  5088. sprintf(item,"%s\t%s",namebuf,
  5089. Text_String(TXT_SOVIET));
  5090. }
  5091. #else //OLDWAY
  5092. sprintf (item, "%s\t%s", namebuf, Text_String(HouseTypeClass::As_Reference(Session.House).Full_Name()));
  5093. #endif //OLDWAY
  5094. playerlist.Colors[0] = &ColorRemaps[(Session.ColorIdx == PCOLOR_DIALOG_BLUE) ?
  5095. PCOLOR_REALLY_BLUE : Session.ColorIdx];
  5096. item = (char *)playerlist.Get_Item(1);
  5097. #ifdef OLDWAY
  5098. if (TheirHouse==HOUSE_GOOD) {
  5099. sprintf(item,"%s\t%s",TheirName,
  5100. Text_String(TXT_ALLIES));
  5101. } else {
  5102. sprintf(item,"%s\t%s",TheirName,
  5103. Text_String(TXT_SOVIET));
  5104. }
  5105. #else //OLDWAY
  5106. sprintf (item, "%s\t%s", TheirName, Text_String(HouseTypeClass::As_Reference(TheirHouse).Full_Name()));
  5107. #endif //OLDWAY
  5108. playerlist.Colors[1] = &ColorRemaps[(TheirColor == PCOLOR_DIALOG_BLUE) ? PCOLOR_REALLY_BLUE : TheirColor];
  5109. gamelist.Flag_To_Redraw();
  5110. playerlist.Flag_To_Redraw();
  5111. //.........................................................
  5112. // Play a little sound effect
  5113. //.........................................................
  5114. Sound_Effect(VOC_OPTIONS_CHANGED);
  5115. break;
  5116. /*..................................................................
  5117. GO: Exit this routine with a success code.
  5118. ..................................................................*/
  5119. case (SERIAL_LOADGAME):
  5120. load_game = true;
  5121. case (SERIAL_GO):
  5122. ready_packet_was_sent = false;
  5123. if (!load_game){
  5124. /*
  5125. ** Special new kludge for counterstrike.
  5126. **
  5127. ** Find local scenario will fail to match a counterstrike mission
  5128. ** unless the CS CD is in the drive. So....
  5129. **
  5130. ** If Counterstrike is installed and this is an official map and
  5131. ** the file name matches a counterstrike map then tell the host
  5132. ** that I have the scenario so he can continue while we make
  5133. ** sure the local user has the Counterstrike CD in the drive.
  5134. **
  5135. */
  5136. // This is duplicated for Aftermath scenarios. ajw
  5137. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  5138. if (Session.ScenarioIsOfficial &&
  5139. ( (Expansion_CS_Present() && Is_Mission_Counterstrike(Session.ScenarioFileName)) ||
  5140. (Expansion_AM_Present() && Is_Mission_Aftermath(Session.ScenarioFileName)) ) ) {
  5141. #else
  5142. if ( Expansion_CS_Present() && Session.ScenarioIsOfficial ) {
  5143. #endif
  5144. CCFileClass check_file ( Session.ScenarioFileName );
  5145. if ( !check_file.Is_Available() ) {
  5146. int current_drive = CCFileClass::Get_CD_Drive();
  5147. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  5148. int index = Get_CD_Index(current_drive, 1*60);
  5149. bool needcd = false;
  5150. if (Is_Mission_Counterstrike(Session.ScenarioFileName)) {
  5151. if (index != 2 && index != 3) {
  5152. RequiredCD = 2;
  5153. needcd = true;
  5154. }
  5155. }
  5156. if (Is_Mission_Aftermath(Session.ScenarioFileName)) {
  5157. if (index != 3) {
  5158. RequiredCD = 3;
  5159. needcd = true;
  5160. }
  5161. }
  5162. if (needcd) {
  5163. #else
  5164. if ( Get_CD_Index(current_drive, 1*60) != 2 ){
  5165. RequiredCD = 2;
  5166. #endif
  5167. #ifdef WIN32
  5168. WWDebugString ("RA95 - Counterstrike CD is not in drive\n");
  5169. #endif
  5170. /*
  5171. ** We should have the scenario but the wrong disk is in.
  5172. ** Tell the host that I am ready to go anyway.
  5173. */
  5174. memset ((void*)&SendPacket, 0, sizeof (SendPacket));
  5175. SendPacket.Command = SERIAL_READY_TO_GO;
  5176. NullModem.Send_Message (&SendPacket, sizeof (SendPacket), 1);
  5177. starttime = TickCount;
  5178. while ( ( NullModem.Num_Send()
  5179. && ((TickCount - starttime) < PACKET_SENDING_TIMEOUT) )
  5180. || ((TickCount - starttime) < 60) ) {
  5181. NullModem.Service();
  5182. }
  5183. ready_packet_was_sent = true;
  5184. if (!Force_CD_Available (RequiredCD)){
  5185. Emergency_Exit(EXIT_FAILURE);
  5186. }
  5187. /*
  5188. ** Update the internal list of scenarios to include the counterstrike
  5189. ** list.
  5190. */
  5191. Session.Read_Scenario_Descriptions();
  5192. /*
  5193. ** Make sure we dont time out because of the disk swap
  5194. */
  5195. lastmsgtime = TickCount;
  5196. }
  5197. }
  5198. }
  5199. /*
  5200. ** If the scenario that the host wants to play doesnt exist locally then we
  5201. ** need to request that it is sent. If we can identify the scenario locally then
  5202. ** we need to fix up the file name so we load the right one.
  5203. */
  5204. if (Find_Local_Scenario (Session.Options.ScenarioDescription,
  5205. Session.ScenarioFileName,
  5206. Session.ScenarioFileLength,
  5207. Session.ScenarioDigest,
  5208. Session.ScenarioIsOfficial)) {
  5209. /*
  5210. ** We have the scenario. Tell the host that I am ready to go.
  5211. */
  5212. if (!ready_packet_was_sent) {
  5213. memset ((void*)&SendPacket, 0, sizeof (SendPacket));
  5214. SendPacket.Command = SERIAL_READY_TO_GO;
  5215. NullModem.Send_Message (&SendPacket, sizeof (SendPacket), 1);
  5216. starttime = TickCount;
  5217. while ( ( NullModem.Num_Send()
  5218. && ((TickCount - starttime) < PACKET_SENDING_TIMEOUT) )
  5219. || ((TickCount - starttime) < 60) ) {
  5220. NullModem.Service();
  5221. }
  5222. }
  5223. } else {
  5224. #ifndef FIXIT_VERSION_3 // Removed restriction on downloading official maps.
  5225. /*
  5226. ** Oh dear. Thats a scenario I dont have. Request that the host sends the
  5227. ** scenario to me provided it isnt an official Westwood scenario.
  5228. **
  5229. ** If the file is received OK then we will get a true return value and the
  5230. ** actual file name to load will be in Session.ScenarioFileName
  5231. */
  5232. if (Session.ScenarioIsOfficial) {
  5233. /*
  5234. ** We dont have the scenario and we dont want to request that it gets
  5235. ** sent because its an official one.
  5236. ** Print up a message saying we cant play this scenario and reply to the
  5237. ** host, telling him to select another.
  5238. */
  5239. memset ((void*)&SendPacket, 0, sizeof (SendPacket));
  5240. SendPacket.Command = SERIAL_NO_SCENARIO;
  5241. NullModem.Send_Message (&SendPacket, sizeof (SendPacket), 1);
  5242. NullModem.Service();
  5243. WWMessageBox().Process (TXT_UNABLE_PLAY_WAAUGH);
  5244. display = REDRAW_ALL;
  5245. lastmsgtime = TickCount;
  5246. break;
  5247. } else {
  5248. #endif
  5249. #ifdef FIXIT_VERSION_3
  5250. if( bSpecialAftermathScenario( Session.Options.ScenarioDescription ) )
  5251. break;
  5252. #endif
  5253. if (!Get_Scenario_File_From_Host(Session.ScenarioFileName, 0)) {
  5254. rc = false;
  5255. break;
  5256. } else {
  5257. /*
  5258. ** Make sure we dont time-out because of the download
  5259. */
  5260. lastmsgtime = TickCount;
  5261. }
  5262. #ifndef FIXIT_VERSION_3
  5263. }
  5264. #endif
  5265. }
  5266. }else{
  5267. /*
  5268. ** Make sure we respond to the host in a load game
  5269. */
  5270. memset ((void*)&SendPacket, 0, sizeof (SendPacket));
  5271. SendPacket.Command = SERIAL_READY_TO_GO;
  5272. NullModem.Send_Message (&SendPacket, sizeof (SendPacket), 1);
  5273. starttime = TickCount;
  5274. while ( ( NullModem.Num_Send()
  5275. && ((TickCount - starttime) < PACKET_SENDING_TIMEOUT) )
  5276. || ((TickCount - starttime) < 60) ) {
  5277. NullModem.Service();
  5278. }
  5279. }
  5280. /*
  5281. ** Fall through here...
  5282. */
  5283. strcpy (Scen.ScenarioName, Session.ScenarioFileName);
  5284. //
  5285. // calculated one way delay for a packet and overall delay
  5286. // to execute a packet
  5287. //
  5288. if (Session.CommProtocol == COMM_PROTOCOL_MULTI_E_COMP) {
  5289. Session.MaxAhead = max( ((((ReceivePacket.ScenarioInfo.ResponseTime / 8) +
  5290. (Session.FrameSendRate - 1)) / Session.FrameSendRate) *
  5291. Session.FrameSendRate), (Session.FrameSendRate * 2) );
  5292. } else {
  5293. Session.MaxAhead = max( (ReceivePacket.ScenarioInfo.ResponseTime / 8),
  5294. MODEM_MIN_MAX_AHEAD );
  5295. }
  5296. process = false;
  5297. rc = true;
  5298. if (ReceivePacket.Command == SERIAL_LOADGAME)
  5299. load_game = true;
  5300. break;
  5301. /*..................................................................
  5302. Incoming message: add to our list
  5303. ..................................................................*/
  5304. case (SERIAL_MESSAGE):
  5305. oppscorescreen = false;
  5306. Session.Messages.Add_Message (ReceivePacket.Name,
  5307. ((PlayerColorType)ReceivePacket.ID == PCOLOR_DIALOG_BLUE) ?
  5308. PCOLOR_REALLY_BLUE : (PlayerColorType)ReceivePacket.ID,
  5309. ReceivePacket.Message.Message,
  5310. ((PlayerColorType)ReceivePacket.ID == PCOLOR_DIALOG_BLUE) ?
  5311. PCOLOR_REALLY_BLUE : (PlayerColorType)ReceivePacket.ID,
  5312. TPF_TEXT, -1);
  5313. Sound_Effect(VOC_INCOMING_MESSAGE);
  5314. if (display < REDRAW_MESSAGE) display = REDRAW_MESSAGE;
  5315. break;
  5316. //
  5317. // throw away timing packet
  5318. //
  5319. case (SERIAL_TIMING):
  5320. oppscorescreen = false;
  5321. break;
  5322. //
  5323. // print msg waiting for opponent
  5324. //
  5325. case (SERIAL_SCORE_SCREEN):
  5326. oppscorescreen = true;
  5327. if (display < REDRAW_MESSAGE) display = REDRAW_MESSAGE;
  5328. parms_received = true;
  5329. break;
  5330. default:
  5331. break;
  5332. }
  5333. }
  5334. }
  5335. // if we haven't received a msg for 10 seconds exit
  5336. if ((TickCount - lastmsgtime) > msg_timeout) {
  5337. WWMessageBox().Process (TXT_SYSTEM_NOT_RESPONDING);
  5338. process = false;
  5339. rc = false;
  5340. // say we did receive sign off to keep from sending one
  5341. recsignedoff = true;
  5342. }
  5343. /*---------------------------------------------------------------------
  5344. Service the connection
  5345. ---------------------------------------------------------------------*/
  5346. NullModem.Service();
  5347. }
  5348. /*------------------------------------------------------------------------
  5349. Prepare to load the scenario
  5350. ------------------------------------------------------------------------*/
  5351. if (rc) {
  5352. Session.NumPlayers = 2;
  5353. /*.....................................................................
  5354. Add both players to the Players vector; the local system is always
  5355. index 0.
  5356. .....................................................................*/
  5357. who = new NodeNameType;
  5358. #ifdef FIXIT_MODEM_LOAD_CRASH
  5359. /* If the names of the players are the same then we MUST force them
  5360. * be be unique. This is necessary to prevent a crash after loading
  5361. * a modem save game.
  5362. */
  5363. if (strcmp(TheirName, namebuf) == 0)
  5364. {
  5365. if (strlen(TheirName) == (MPLAYER_NAME_MAX - 1))
  5366. {
  5367. namebuf[MPLAYER_NAME_MAX - 1] = '\0';
  5368. }
  5369. else
  5370. {
  5371. strcat(namebuf, "2");
  5372. }
  5373. }
  5374. #endif
  5375. strcpy(who->Name, namebuf);
  5376. who->Player.House = Session.House;
  5377. who->Player.Color = Session.ColorIdx;
  5378. who->Player.ProcessTime = -1;
  5379. Session.Players.Add (who);
  5380. who = new NodeNameType;
  5381. strcpy(who->Name, TheirName);
  5382. who->Player.House = TheirHouse;
  5383. who->Player.Color = TheirColor;
  5384. who->Player.ProcessTime = -1;
  5385. Session.Players.Add (who);
  5386. starttime = TickCount;
  5387. while ( ( NullModem.Num_Send()
  5388. && ((TickCount - starttime) < PACKET_SENDING_TIMEOUT) )
  5389. || ((TickCount - starttime) < 60) ) {
  5390. #if(SHOW_MONO)
  5391. NullModem.Mono_Debug_Print(0);
  5392. #endif
  5393. NullModem.Service();
  5394. }
  5395. // clear queue to keep from doing any resends
  5396. NullModem.Init_Send_Queue();
  5397. } else {
  5398. if ( !recsignedoff ) {
  5399. /*.....................................................................
  5400. Broadcast my sign-off over my network
  5401. .....................................................................*/
  5402. memset (&SendPacket, 0, sizeof(SerialPacketType));
  5403. SendPacket.Command = SERIAL_SIGN_OFF;
  5404. SendPacket.ScenarioInfo.Color = Session.ColorIdx; // use Color for ID
  5405. SendPacket.ID = Session.ModemType;
  5406. NullModem.Send_Message (&SendPacket, sizeof(SendPacket), 1);
  5407. starttime = TickCount;
  5408. while ( (NullModem.Num_Send()
  5409. && ((TickCount - starttime) < PACKET_CANCEL_TIMEOUT) )
  5410. || ((TickCount - starttime) < 60) ) {
  5411. #if(SHOW_MONO)
  5412. NullModem.Mono_Debug_Print(0);
  5413. #endif
  5414. if ( NullModem.Get_Message( &ReceivePacket, &packetlen ) > 0) {
  5415. // are we getting our own packets back??
  5416. if (ReceivePacket.Command == SERIAL_SIGN_OFF
  5417. && ReceivePacket.ID == Session.ModemType) {
  5418. // exit while
  5419. break;
  5420. }
  5421. }
  5422. NullModem.Service();
  5423. }
  5424. }
  5425. Shutdown_Modem();
  5426. }
  5427. /*------------------------------------------------------------------------
  5428. Clean up the list boxes
  5429. ------------------------------------------------------------------------*/
  5430. // while (optionlist.Count()>0) {
  5431. // item = (char *)optionlist.Get_Item(0);
  5432. // delete [] item;
  5433. // optionlist.Remove_Item(item);
  5434. // }
  5435. while (gamelist.Count()>0) {
  5436. item = (char *)gamelist.Get_Item(0);
  5437. delete [] item;
  5438. gamelist.Remove_Item(item);
  5439. }
  5440. while (playerlist.Count()>0) {
  5441. item = (char *)playerlist.Get_Item(0);
  5442. delete [] item;
  5443. playerlist.Remove_Item(item);
  5444. }
  5445. /*------------------------------------------------------------------------
  5446. Remove the chat edit box
  5447. ------------------------------------------------------------------------*/
  5448. Session.Messages.Remove_Edit();
  5449. /*------------------------------------------------------------------------
  5450. Restore screen
  5451. ------------------------------------------------------------------------*/
  5452. Hide_Mouse();
  5453. Load_Title_Page(true);
  5454. //#ifdef WIN32
  5455. // Load_Uncompress(CCFileClass("TITLE.CPS"), SysMemPage, SysMemPage, CCPalette);
  5456. // SysMemPage.Scale(SeenPage);
  5457. //#else
  5458. // Load_Uncompress(CCFileClass("TITLE.CPS"), HidPage, HidPage, CCPalette);
  5459. // HidPage.Blit(SeenPage);
  5460. //#endif
  5461. Show_Mouse();
  5462. /*------------------------------------------------------------------------
  5463. Save any changes made to our options
  5464. ------------------------------------------------------------------------*/
  5465. if (changed) {
  5466. Session.Write_MultiPlayer_Settings ();
  5467. }
  5468. if (load_game) {
  5469. if (!Load_Game (-1)) {
  5470. WWMessageBox().Process (TXT_ERROR_LOADING_GAME);
  5471. rc = false;
  5472. }
  5473. Frame++;
  5474. }
  5475. return(rc);
  5476. } /* end of Com_Show_Scenario_Dialog */
  5477. /***************************************************************************
  5478. * Phone_Dialog -- Lets user edit phone directory & dial *
  5479. * *
  5480. * INPUT: *
  5481. * none. *
  5482. * *
  5483. * OUTPUT: *
  5484. * true = dial the current phone book entry, false = cancel. *
  5485. * *
  5486. * WARNINGS: *
  5487. * Serial options must have been read from CC.INI. *
  5488. * *
  5489. * HISTORY: *
  5490. * 04/29/1995 BRR : Created. *
  5491. *=========================================================================*/
  5492. static int Phone_Dialog (void)
  5493. {
  5494. /*........................................................................
  5495. Dialog & button dimensions
  5496. ........................................................................*/
  5497. int d_dialog_w = 280 * RESFACTOR; // dialog width
  5498. int d_dialog_h = 160 * RESFACTOR; // dialog height
  5499. int d_dialog_x = ((320 * RESFACTOR - d_dialog_w) / 2); // dialog x-coord
  5500. int d_dialog_y = ((200 * RESFACTOR - d_dialog_h) / 2); // dialog y-coord
  5501. int d_dialog_cx = d_dialog_x + (d_dialog_w / 2); // center x-coord
  5502. int d_txt6_h = 7 * RESFACTOR; // ht of 6-pt text
  5503. int d_margin = 7 * RESFACTOR; // margin width/height
  5504. int d_phonelist_w = 248 * RESFACTOR;
  5505. int d_phonelist_h = 87 * RESFACTOR;
  5506. int d_phonelist_x = d_dialog_cx - (d_phonelist_w / 2);
  5507. int d_phonelist_y = d_dialog_y + d_margin + d_txt6_h + 11 * RESFACTOR;
  5508. int d_add_w = 45 * RESFACTOR;
  5509. int d_add_h = 9 * RESFACTOR;
  5510. int d_add_x = d_dialog_cx - (d_add_w / 2) - d_margin - d_add_w;
  5511. int d_add_y = d_phonelist_y + d_phonelist_h + d_margin;
  5512. int d_edit_w = 45 * RESFACTOR;
  5513. int d_edit_h = 9 * RESFACTOR;
  5514. int d_edit_x = d_dialog_cx - (d_edit_w / 2);
  5515. int d_edit_y = d_phonelist_y + d_phonelist_h + d_margin;
  5516. int d_delete_w = 45 * RESFACTOR;
  5517. int d_delete_h = 9 * RESFACTOR;
  5518. int d_delete_x = d_dialog_cx + (d_delete_w / 2) + d_margin;
  5519. int d_delete_y = d_phonelist_y + d_phonelist_h + d_margin;
  5520. int d_numedit_w = ( (PhoneEntryClass::PHONE_MAX_NUM - 1) * 6) * RESFACTOR + 3 * RESFACTOR;
  5521. int d_numedit_h = 9 * RESFACTOR;
  5522. int d_numedit_x = d_dialog_cx - (d_numedit_w / 2);
  5523. int d_numedit_y = d_add_y + d_add_h + d_margin;
  5524. int d_dial_w = 45 * RESFACTOR;
  5525. int d_dial_h = 9 * RESFACTOR;
  5526. int d_dial_x = d_dialog_cx - (d_numedit_w / 2) - d_margin - d_dial_w;
  5527. int d_dial_y = d_add_y + d_add_h + d_margin;
  5528. int d_cancel_w = 45 * RESFACTOR;
  5529. int d_cancel_h = 9 * RESFACTOR;
  5530. int d_cancel_x = d_dialog_cx + (d_numedit_w / 2) + d_margin;
  5531. int d_cancel_y = d_add_y + d_add_h + d_margin;
  5532. /*........................................................................
  5533. Button Enumerations
  5534. ........................................................................*/
  5535. enum {
  5536. BUTTON_PHONELIST = 100,
  5537. BUTTON_ADD,
  5538. BUTTON_EDIT,
  5539. BUTTON_DELETE,
  5540. BUTTON_DIAL,
  5541. BUTTON_CANCEL,
  5542. BUTTON_NUMEDIT,
  5543. };
  5544. /*........................................................................
  5545. Redraw values: in order from "top" to "bottom" layer of the dialog
  5546. ........................................................................*/
  5547. typedef enum {
  5548. REDRAW_NONE = 0,
  5549. REDRAW_BUTTONS,
  5550. REDRAW_BACKGROUND,
  5551. REDRAW_ALL = REDRAW_BACKGROUND
  5552. } RedrawType;
  5553. /*........................................................................
  5554. Dialog variables
  5555. ........................................................................*/
  5556. RedrawType display = REDRAW_ALL; // redraw level
  5557. bool process = true; // process while true
  5558. KeyNumType input;
  5559. char phone_num[ PhoneEntryClass::PHONE_MAX_NUM ] = { 0 }; // buffer for editing phone #
  5560. int rc;
  5561. int i;
  5562. int tabs[] = {123*RESFACTOR, 207*RESFACTOR}; // tabs for list box
  5563. char *item; // for removing items from list box
  5564. PhoneEntryClass *p_entry; // for creating / editing phonebook entries
  5565. bool changed = false; // 1 = save changes to INI file
  5566. bool firsttime = false;
  5567. /*........................................................................
  5568. Buttons
  5569. ........................................................................*/
  5570. GadgetClass *commands; // button list
  5571. ListClass phonelist(BUTTON_PHONELIST, d_phonelist_x, d_phonelist_y, d_phonelist_w, d_phonelist_h, TPF_TEXT, MFCD::Retrieve("BTN-UP.SHP"), MFCD::Retrieve("BTN-DN.SHP"));
  5572. TextButtonClass addbtn(BUTTON_ADD, TXT_ADD, TPF_BUTTON, d_add_x, d_add_y, d_add_w, d_add_h);
  5573. TextButtonClass editbtn(BUTTON_EDIT, TXT_EDIT, TPF_BUTTON, d_edit_x, d_edit_y, d_edit_w, d_edit_h);
  5574. TextButtonClass deletebtn(BUTTON_DELETE, TXT_DELETE_BUTTON, TPF_BUTTON, d_delete_x, d_delete_y, d_delete_w, d_delete_h);
  5575. TextButtonClass dialbtn(BUTTON_DIAL, TXT_DIAL, TPF_BUTTON, d_dial_x, d_dial_y, d_dial_w, d_dial_h);
  5576. TextButtonClass cancelbtn(BUTTON_CANCEL, TXT_CANCEL, TPF_BUTTON, d_cancel_x, d_cancel_y, d_cancel_w, d_cancel_h);
  5577. EditClass numedit (BUTTON_NUMEDIT, phone_num, PhoneEntryClass::PHONE_MAX_NUM, TPF_TEXT, d_numedit_x, d_numedit_y, d_numedit_w, d_numedit_h, EditClass::ALPHANUMERIC);
  5578. /*
  5579. ------------------------- Build the button list --------------------------
  5580. */
  5581. commands = &phonelist;
  5582. addbtn.Add_Tail(*commands);
  5583. editbtn.Add_Tail(*commands);
  5584. deletebtn.Add_Tail(*commands);
  5585. dialbtn.Add_Tail(*commands);
  5586. cancelbtn.Add_Tail(*commands);
  5587. numedit.Add_Tail(*commands);
  5588. dialbtn.Turn_On();
  5589. /*
  5590. ----------------------------- Various Inits ------------------------------
  5591. */
  5592. /*........................................................................
  5593. Fill in the phone directory list box
  5594. ........................................................................*/
  5595. phonelist.Set_Tabs(tabs);
  5596. Build_Phone_Listbox(&phonelist, &numedit, phone_num);
  5597. if (Session.CurPhoneIdx == -1) {
  5598. firsttime = true;
  5599. }
  5600. /*
  5601. ---------------------------- Processing loop -----------------------------
  5602. */
  5603. while (process) {
  5604. /*
  5605. ........................ Invoke game callback .........................
  5606. */
  5607. Call_Back();
  5608. #ifdef WIN32
  5609. /*
  5610. ** If we have just received input focus again after running in the background then
  5611. ** we need to redraw.
  5612. */
  5613. if (AllSurfaces.SurfacesRestored) {
  5614. AllSurfaces.SurfacesRestored=FALSE;
  5615. display = REDRAW_ALL;
  5616. }
  5617. #endif
  5618. /*
  5619. ...................... Refresh display if needed ......................
  5620. */
  5621. if (display) {
  5622. Hide_Mouse();
  5623. /*
  5624. .................. Redraw backgound & dialog box ...................
  5625. */
  5626. if (display >= REDRAW_BACKGROUND) {
  5627. Load_Title_Page(true);
  5628. CCPalette.Set();
  5629. Dialog_Box(d_dialog_x, d_dialog_y, d_dialog_w, d_dialog_h);
  5630. // init font variables
  5631. Fancy_Text_Print(TXT_NONE, 0, 0, TBLACK, TBLACK, TPF_CENTER | TPF_TEXT);
  5632. /*...............................................................
  5633. Dialog & Field labels
  5634. ...............................................................*/
  5635. Draw_Caption (TXT_PHONE_LIST, d_dialog_x, d_dialog_y, d_dialog_w);
  5636. phonelist.Draw_Me (true);
  5637. }
  5638. /*
  5639. .......................... Redraw buttons ..........................
  5640. */
  5641. if (display >= REDRAW_BUTTONS) {
  5642. addbtn.Flag_To_Redraw();
  5643. editbtn.Flag_To_Redraw();
  5644. deletebtn.Flag_To_Redraw();
  5645. dialbtn.Flag_To_Redraw();
  5646. cancelbtn.Flag_To_Redraw();
  5647. numedit.Flag_To_Redraw();
  5648. }
  5649. Show_Mouse();
  5650. display = REDRAW_NONE;
  5651. }
  5652. /*
  5653. ........................... Get user input ............................
  5654. */
  5655. input = commands->Input();
  5656. if ( firsttime ) {
  5657. numedit.Set_Focus();
  5658. numedit.Flag_To_Redraw();
  5659. input = commands->Input();
  5660. firsttime = false;
  5661. }
  5662. /*
  5663. ---------------------------- Process input ----------------------------
  5664. */
  5665. switch (input) {
  5666. /*------------------------------------------------------------------
  5667. New phone listing selected.
  5668. ------------------------------------------------------------------*/
  5669. case (BUTTON_PHONELIST | KN_BUTTON):
  5670. /*...............................................................
  5671. Detect a change in the selected item; update CurPhoneIdx, and
  5672. the edit box buffer.
  5673. ...............................................................*/
  5674. #ifdef FIXIT_PHONELIST_CRASH
  5675. if (Session.CurPhoneIdx != -1) {
  5676. #endif
  5677. if (phonelist.Current_Index() != Session.CurPhoneIdx) {
  5678. Session.CurPhoneIdx = phonelist.Current_Index();
  5679. strcpy (phone_num, Session.PhoneBook[Session.CurPhoneIdx]->Number);
  5680. numedit.Set_Text (phone_num, PhoneEntryClass::PHONE_MAX_NUM );
  5681. changed = true;
  5682. }
  5683. #ifdef FIXIT_PHONELIST_CRASH
  5684. }
  5685. #endif
  5686. break;
  5687. /*------------------------------------------------------------------
  5688. Add a new entry
  5689. ------------------------------------------------------------------*/
  5690. case (BUTTON_ADD | KN_BUTTON):
  5691. /*...............................................................
  5692. Allocate a new phone book entry
  5693. ...............................................................*/
  5694. p_entry = new PhoneEntryClass();
  5695. p_entry->Name[0] = 0;
  5696. p_entry->Number[0] = 0;
  5697. p_entry->Settings.Port = 0;
  5698. p_entry->Settings.IRQ = -1;
  5699. p_entry->Settings.Baud = -1;
  5700. p_entry->Settings.DialMethod = DIAL_TOUCH_TONE;
  5701. p_entry->Settings.InitStringIndex = 0;
  5702. p_entry->Settings.CallWaitStringIndex = CALL_WAIT_CUSTOM;
  5703. p_entry->Settings.CallWaitString[0] = 0;
  5704. /*...............................................................
  5705. Invoke the entry editor; if user clicks Save, add the new entry
  5706. to the list, and rebuild the list box.
  5707. ...............................................................*/
  5708. if ( Edit_Phone_Dialog( p_entry ) ) {
  5709. Session.PhoneBook.Add (p_entry);
  5710. Build_Phone_Listbox( &phonelist, &numedit, phone_num );
  5711. /*............................................................
  5712. Set the current listbox index to the newly-added item.
  5713. ............................................................*/
  5714. for (i = 0; i < Session.PhoneBook.Count(); i++) {
  5715. if (p_entry == Session.PhoneBook[i]) {
  5716. Session.CurPhoneIdx = i;
  5717. strcpy (phone_num, Session.PhoneBook[Session.CurPhoneIdx]->Number);
  5718. numedit.Set_Text (phone_num, PhoneEntryClass::PHONE_MAX_NUM );
  5719. phonelist.Set_Selected_Index( Session.CurPhoneIdx );
  5720. }
  5721. }
  5722. changed = true;
  5723. } else {
  5724. /*...............................................................
  5725. If the user clicked Cancel, delete the entry & keep looping.
  5726. ...............................................................*/
  5727. delete p_entry;
  5728. }
  5729. display = REDRAW_ALL;
  5730. break;
  5731. /*------------------------------------------------------------------
  5732. Edit the current entry
  5733. ------------------------------------------------------------------*/
  5734. case (BUTTON_EDIT | KN_BUTTON):
  5735. /*...............................................................
  5736. Do nothing if no entry is selected.
  5737. ...............................................................*/
  5738. if (Session.CurPhoneIdx==-1)
  5739. break;
  5740. /*...............................................................
  5741. Allocate a new entry & copy the currently-selected entry into it
  5742. ...............................................................*/
  5743. p_entry = new PhoneEntryClass();
  5744. (*p_entry) = (*Session.PhoneBook[Session.CurPhoneIdx]);
  5745. /*...............................................................
  5746. Pass the new entry to the entry editor; if the user selects OK,
  5747. copy the data back into our phone book. Rebuild the list so
  5748. the changes show up in the list box.
  5749. ...............................................................*/
  5750. if ( Edit_Phone_Dialog( p_entry ) ) {
  5751. (*Session.PhoneBook[Session.CurPhoneIdx]) = (*p_entry);
  5752. Build_Phone_Listbox(&phonelist, &numedit, phone_num);
  5753. /*............................................................
  5754. Set the current listbox index to the newly-added item.
  5755. ............................................................*/
  5756. for (i = 0; i < Session.PhoneBook.Count(); i++) {
  5757. if (Session.PhoneBook[Session.CurPhoneIdx] == Session.PhoneBook[i]) {
  5758. Session.CurPhoneIdx = i;
  5759. strcpy (phone_num, Session.PhoneBook[Session.CurPhoneIdx]->Number);
  5760. numedit.Set_Text (phone_num, PhoneEntryClass::PHONE_MAX_NUM );
  5761. phonelist.Set_Selected_Index( Session.CurPhoneIdx );
  5762. }
  5763. }
  5764. changed = true;
  5765. }
  5766. delete p_entry;
  5767. display = REDRAW_ALL;
  5768. break;
  5769. /*------------------------------------------------------------------
  5770. Delete the current entry
  5771. ------------------------------------------------------------------*/
  5772. case (BUTTON_DELETE | KN_BUTTON):
  5773. /*...............................................................
  5774. Do nothing if no entry is selected.
  5775. ...............................................................*/
  5776. if (Session.CurPhoneIdx == -1)
  5777. break;
  5778. /*...............................................................
  5779. Delete the current item & rebuild the phone listbox
  5780. ...............................................................*/
  5781. Session.PhoneBook.Delete (Session.CurPhoneIdx);
  5782. Build_Phone_Listbox(&phonelist, &numedit, phone_num);
  5783. if (Session.CurPhoneIdx == -1) {
  5784. *phone_num = 0;
  5785. numedit.Set_Text (phone_num, PhoneEntryClass::PHONE_MAX_NUM );
  5786. }
  5787. changed = true;
  5788. break;
  5789. /*------------------------------------------------------------------
  5790. Dial the current number
  5791. ------------------------------------------------------------------*/
  5792. case (KN_RETURN):
  5793. dialbtn.IsPressed = true;
  5794. dialbtn.Draw_Me(true);
  5795. // fall thru
  5796. case (BUTTON_DIAL | KN_BUTTON):
  5797. /*...............................................................
  5798. If no item is selected, just dial the number in the phone #
  5799. edit box:
  5800. - Create a new phone entry
  5801. - Copy the phone number into it
  5802. - Set settings to defaults
  5803. ...............................................................*/
  5804. if (Session.CurPhoneIdx == -1 ||
  5805. strcmp( Session.PhoneBook[Session.CurPhoneIdx]->Number, phone_num) ) {
  5806. if ( strlen(phone_num) == 0) { // do not dial
  5807. dialbtn.IsPressed = true;
  5808. dialbtn.Flag_To_Redraw();
  5809. break;
  5810. }
  5811. p_entry = new PhoneEntryClass();
  5812. strcpy( p_entry->Name, "NONAME" );
  5813. strcpy( p_entry->Number, phone_num);
  5814. p_entry->Settings.Port = 0;
  5815. p_entry->Settings.IRQ = -1;
  5816. p_entry->Settings.Baud = -1;
  5817. p_entry->Settings.DialMethod = DIAL_TOUCH_TONE;
  5818. p_entry->Settings.InitStringIndex = 0;
  5819. p_entry->Settings.CallWaitStringIndex = CALL_WAIT_CUSTOM;
  5820. p_entry->Settings.CallWaitString[0] = 0;
  5821. Session.PhoneBook.Add (p_entry);
  5822. Build_Phone_Listbox(&phonelist, &numedit, phone_num);
  5823. /*............................................................
  5824. Set the current listbox index to the newly-added item.
  5825. ............................................................*/
  5826. for (i = 0; i < Session.PhoneBook.Count(); i++) {
  5827. if (p_entry == Session.PhoneBook[i]) {
  5828. Session.CurPhoneIdx = i;
  5829. }
  5830. }
  5831. changed = true;
  5832. }
  5833. process = false;
  5834. rc = true;
  5835. break;
  5836. /*------------------------------------------------------------------
  5837. CANCEL: bail out
  5838. ------------------------------------------------------------------*/
  5839. case (KN_ESC):
  5840. case (BUTTON_CANCEL | KN_BUTTON):
  5841. process = false;
  5842. rc = false;
  5843. break;
  5844. }
  5845. } /* end of while */
  5846. /*------------------------------------------------------------------------
  5847. Save any changes we've made to the phone list or settings
  5848. ------------------------------------------------------------------------*/
  5849. if (changed) {
  5850. Session.Write_MultiPlayer_Settings ();
  5851. }
  5852. /*------------------------------------------------------------------------
  5853. Clear the list box
  5854. ------------------------------------------------------------------------*/
  5855. while (phonelist.Count()) {
  5856. item = (char *)phonelist.Get_Item(0);
  5857. phonelist.Remove_Item(item);
  5858. delete [] item;
  5859. }
  5860. return(rc);
  5861. } /* end of Phone_Dialog */
  5862. /***************************************************************************
  5863. * Build_Phone_Listbox -- [re]builds the phone entry listbox *
  5864. * *
  5865. * This routine rebuilds the phone list box from scratch; it also updates *
  5866. * the contents of the phone # edit field. *
  5867. * *
  5868. * INPUT: *
  5869. * list ptr to list box *
  5870. * edit ptr to edit box *
  5871. * buf ptr to buffer for phone # *
  5872. * *
  5873. * OUTPUT: *
  5874. * none. *
  5875. * *
  5876. * WARNINGS: *
  5877. * none. *
  5878. * *
  5879. * HISTORY: *
  5880. * 04/29/1995 BRR : Created. *
  5881. *=========================================================================*/
  5882. static void Build_Phone_Listbox (ListClass *list, EditClass *edit, char *buf)
  5883. {
  5884. int i;
  5885. char *item;
  5886. char phonename[21];
  5887. char phonenum[15];
  5888. /*........................................................................
  5889. Clear the list
  5890. ........................................................................*/
  5891. while (list->Count()) {
  5892. item = (char *)(list->Get_Item(0));
  5893. list->Remove_Item(item);
  5894. delete [] item;
  5895. }
  5896. /*
  5897. ** Now sort the phone list by name then number
  5898. */
  5899. qsort ((void *)(&Session.PhoneBook[0]), Session.PhoneBook.Count(), sizeof(class PhoneEntryClass *), Phone_Compare);
  5900. /*........................................................................
  5901. Build the list
  5902. ........................................................................*/
  5903. for (i = 0; i < Session.PhoneBook.Count(); i++) {
  5904. item = new char[80];
  5905. if ( !(strlen( Session.PhoneBook[i]->Name )) ) {
  5906. strcpy( phonename, " " );
  5907. } else {
  5908. strncpy( phonename, Session.PhoneBook[i]->Name, 20 );
  5909. phonename[21] = 0;
  5910. }
  5911. if ( !(strlen( Session.PhoneBook[i]->Number )) ) {
  5912. strcpy( phonenum, " " );
  5913. } else {
  5914. if ( strlen( Session.PhoneBook[i]->Number ) < 14) {
  5915. strcpy( phonenum, Session.PhoneBook[i]->Number );
  5916. } else {
  5917. strncpy( phonenum, Session.PhoneBook[i]->Number, 12 );
  5918. phonenum[12] = 0;
  5919. strcat( phonenum, "..." );
  5920. }
  5921. }
  5922. if (Session.PhoneBook[i]->Settings.Baud != -1) {
  5923. sprintf(item,"%s\t%s\t%d", phonename, phonenum,
  5924. Session.PhoneBook[i]->Settings.Baud);
  5925. } else {
  5926. sprintf(item,"%s\t%s\t[%s]", phonename, phonenum,
  5927. Text_String(TXT_DEFAULT));
  5928. }
  5929. list->Add_Item(item);
  5930. }
  5931. list->Flag_To_Redraw();
  5932. /*........................................................................
  5933. Init the current phone book index
  5934. ........................................................................*/
  5935. if (list->Count() == 0 || Session.CurPhoneIdx < -1) {
  5936. Session.CurPhoneIdx = -1;
  5937. } else {
  5938. if (Session.CurPhoneIdx >= list->Count() ) {
  5939. Session.CurPhoneIdx = 0;
  5940. }
  5941. }
  5942. /*........................................................................
  5943. Fill in phone number edit buffer
  5944. ........................................................................*/
  5945. if (Session.CurPhoneIdx > -1) {
  5946. strcpy (buf, Session.PhoneBook[Session.CurPhoneIdx]->Number);
  5947. edit->Set_Text (buf, PhoneEntryClass::PHONE_MAX_NUM );
  5948. list->Set_Selected_Index( Session.CurPhoneIdx );
  5949. }
  5950. }
  5951. /***************************************************************************
  5952. * Phone_Compare -- for qsort *
  5953. * *
  5954. * INPUT: *
  5955. * p1,p2 ptrs to elements to compare *
  5956. * *
  5957. * OUTPUT: *
  5958. * 0 = same, -1 = (*p1) goes BEFORE (*p2), 1 = (*p1) goes AFTER (*p2) *
  5959. * *
  5960. * WARNINGS: *
  5961. * none. *
  5962. * *
  5963. * HISTORY: *
  5964. * 02/14/1995 BR : Created. *
  5965. *=========================================================================*/
  5966. static int Phone_Compare (const void *p1, const void *p2)
  5967. {
  5968. class PhoneEntryClass *pe1,*pe2;
  5969. int result;
  5970. pe1 = *((class PhoneEntryClass **)p1);
  5971. pe2 = *((class PhoneEntryClass **)p2);
  5972. result = strcmp( pe1->Name, pe2->Name );
  5973. // if strings are equal then check the phone number
  5974. if ( !result ) {
  5975. result = strcmp( pe1->Number, pe2->Number );
  5976. }
  5977. return(result);
  5978. }
  5979. /***************************************************************************
  5980. * Edit_Phone_Dialog -- lets user edit a phone book entry *
  5981. * *
  5982. * INPUT: *
  5983. * phone entry to edit *
  5984. * *
  5985. * OUTPUT: *
  5986. * true = OK, false = cancel *
  5987. * *
  5988. * WARNINGS: *
  5989. * none. *
  5990. * *
  5991. * HISTORY: *
  5992. * 04/29/1995 BRR : Created. *
  5993. *=========================================================================*/
  5994. static int Edit_Phone_Dialog (PhoneEntryClass *phone)
  5995. {
  5996. /*........................................................................
  5997. Dialog & button dimensions
  5998. ........................................................................*/
  5999. int d_dialog_w = 230 * RESFACTOR; // dialog width
  6000. int d_dialog_h = 110 * RESFACTOR; // dialog height
  6001. int d_dialog_x = ((320 * RESFACTOR - d_dialog_w) / 2); // dialog x-coord
  6002. int d_dialog_y = ((136 * RESFACTOR - d_dialog_h) / 2); // dialog y-coord
  6003. int d_dialog_cx = d_dialog_x + (d_dialog_w / 2); // center x-coord
  6004. int d_txt6_h = 7 * RESFACTOR; // ht of 6-pt text
  6005. int d_margin = 7 * RESFACTOR; // margin width/height
  6006. int d_name_w = ( (PhoneEntryClass::PHONE_MAX_NAME - 1) * 6) * RESFACTOR + 3 * RESFACTOR;
  6007. int d_name_h = 9 * RESFACTOR;
  6008. int d_name_x = d_dialog_x + (((d_dialog_w - d_name_w) * 3) / 4) - 5 * RESFACTOR;
  6009. int d_name_y = d_dialog_y + 25 * RESFACTOR;
  6010. int d_number_w = ( (PhoneEntryClass::PHONE_MAX_NUM - 1) * 6) * RESFACTOR + 3 * RESFACTOR;
  6011. int d_number_h = 9 * RESFACTOR;
  6012. int d_number_x = d_dialog_x + (((d_dialog_w - d_number_w) * 3) / 4) - 5 * RESFACTOR;
  6013. int d_number_y = d_name_y + d_name_h + d_margin;
  6014. int d_default_w = 130 * RESFACTOR;
  6015. int d_default_h = 9 * RESFACTOR;
  6016. int d_default_x = d_dialog_cx - (d_default_w / 2);
  6017. int d_default_y = d_number_y + d_number_h + d_margin;
  6018. int d_custom_w = 130 * RESFACTOR;
  6019. int d_custom_h = 9 * RESFACTOR;
  6020. int d_custom_x = d_dialog_cx - (d_default_w / 2);
  6021. int d_custom_y = d_default_y + d_default_h + d_margin;
  6022. int d_save_w = 55 * RESFACTOR;
  6023. int d_save_h = 9 * RESFACTOR;
  6024. int d_save_x = d_dialog_cx - d_margin - d_save_w;
  6025. int d_save_y = d_dialog_y + d_dialog_h - d_margin - d_save_h - 5*RESFACTOR;
  6026. int d_cancel_w = 55 * RESFACTOR;
  6027. int d_cancel_h = 9 * RESFACTOR;
  6028. int d_cancel_x = d_dialog_cx + d_margin;
  6029. int d_cancel_y = d_dialog_y + d_dialog_h - d_margin - d_cancel_h - 5*RESFACTOR;
  6030. /*........................................................................
  6031. Button Enumerations
  6032. ........................................................................*/
  6033. enum {
  6034. BUTTON_NAME = 100,
  6035. BUTTON_NUMBER,
  6036. BUTTON_DEFAULT,
  6037. BUTTON_CUSTOM,
  6038. BUTTON_SAVE,
  6039. BUTTON_CANCEL,
  6040. };
  6041. /*........................................................................
  6042. Redraw values: in order from "top" to "bottom" layer of the dialog
  6043. ........................................................................*/
  6044. typedef enum {
  6045. REDRAW_NONE = 0,
  6046. REDRAW_BUTTONS,
  6047. REDRAW_BACKGROUND,
  6048. REDRAW_ALL = REDRAW_BACKGROUND
  6049. } RedrawType;
  6050. /*........................................................................
  6051. Dialog variables
  6052. ........................................................................*/
  6053. RedrawType display = REDRAW_ALL; // redraw level
  6054. char namebuf[PhoneEntryClass::PHONE_MAX_NAME] = { 0 }; // buffer for editing name
  6055. char numbuf[PhoneEntryClass::PHONE_MAX_NUM] = { 0 }; // buffer for editing phone #
  6056. int rc;
  6057. SerialSettingsType settings;
  6058. bool custom = false;
  6059. bool firsttime = true;
  6060. RemapControlType * scheme = GadgetClass::Get_Color_Scheme();
  6061. /*........................................................................
  6062. Buttons
  6063. ........................................................................*/
  6064. GadgetClass *commands; // button list
  6065. EditClass nameedit(BUTTON_NAME, namebuf, PhoneEntryClass::PHONE_MAX_NAME, TPF_TEXT, d_name_x, d_name_y, d_name_w, d_name_h, EditClass::ALPHANUMERIC);
  6066. EditClass numedit(BUTTON_NUMBER, numbuf, PhoneEntryClass::PHONE_MAX_NUM, TPF_TEXT, d_number_x, d_number_y, d_number_w, d_number_h, EditClass::ALPHANUMERIC);
  6067. TextButtonClass defaultbtn(BUTTON_DEFAULT, TXT_DEFAULT_SETTINGS, TPF_BUTTON, d_default_x, d_default_y, d_default_w, d_default_h);
  6068. TextButtonClass custombtn(BUTTON_CUSTOM, TXT_CUSTOM_SETTINGS, TPF_BUTTON, d_custom_x, d_custom_y, d_custom_w, d_custom_h);
  6069. TextButtonClass savebtn(BUTTON_SAVE, TXT_SAVE_BUTTON, TPF_BUTTON, d_save_x, d_save_y, d_save_w, d_save_h);
  6070. TextButtonClass cancelbtn(BUTTON_CANCEL, TXT_CANCEL, TPF_BUTTON, d_cancel_x, d_cancel_y, d_cancel_w, d_cancel_h);
  6071. /*
  6072. ------------------------- Build the button list --------------------------
  6073. */
  6074. commands = &nameedit;
  6075. numedit.Add_Tail(*commands);
  6076. defaultbtn.Add_Tail(*commands);
  6077. custombtn.Add_Tail(*commands);
  6078. savebtn.Add_Tail(*commands);
  6079. cancelbtn.Add_Tail(*commands);
  6080. /*
  6081. ----------------------------- Various Inits ------------------------------
  6082. */
  6083. /*........................................................................
  6084. Init the settings; if the phone entry is set to use defaults, init our
  6085. settings to sensible values (in case we invoke the setting editor);
  6086. otherwise, copy the entry's settings.
  6087. ........................................................................*/
  6088. if (phone->Settings.Port == 0 || phone->Settings.IRQ == -1 ||
  6089. phone->Settings.Baud == -1) {
  6090. settings = Session.SerialDefaults;
  6091. defaultbtn.Turn_On();
  6092. custom = false;
  6093. } else {
  6094. settings = phone->Settings;
  6095. custombtn.Turn_On();
  6096. custom = true;
  6097. }
  6098. strcpy (namebuf, phone->Name);
  6099. nameedit.Set_Text (namebuf, PhoneEntryClass::PHONE_MAX_NAME);
  6100. strcpy (numbuf, phone->Number);
  6101. numedit.Set_Text (numbuf, PhoneEntryClass::PHONE_MAX_NUM);
  6102. /*
  6103. ---------------------------- Processing loop -----------------------------
  6104. */
  6105. bool process = true; // process while true
  6106. while (process) {
  6107. /*
  6108. ........................ Invoke game callback .........................
  6109. */
  6110. Call_Back();
  6111. #ifdef WIN32
  6112. /*
  6113. ** If we have just received input focus again after running in the background then
  6114. ** we need to redraw.
  6115. */
  6116. if (AllSurfaces.SurfacesRestored) {
  6117. AllSurfaces.SurfacesRestored=FALSE;
  6118. display = REDRAW_ALL;
  6119. }
  6120. #endif
  6121. /*
  6122. ...................... Refresh display if needed ......................
  6123. */
  6124. if (display) {
  6125. Hide_Mouse();
  6126. /*
  6127. .................. Redraw backgound & dialog box ...................
  6128. */
  6129. if (display >= REDRAW_BACKGROUND) {
  6130. Load_Title_Page(true);
  6131. CCPalette.Set();
  6132. Dialog_Box(d_dialog_x, d_dialog_y, d_dialog_w, d_dialog_h);
  6133. Draw_Caption (TXT_PHONE_LISTING, d_dialog_x, d_dialog_y, d_dialog_w);
  6134. /*...............................................................
  6135. Dialog & Field labels
  6136. ...............................................................*/
  6137. Fancy_Text_Print (TXT_NAME_COLON, d_name_x - 5 * RESFACTOR, d_name_y + 1 * RESFACTOR, scheme, TBLACK, TPF_RIGHT | TPF_TEXT);
  6138. Fancy_Text_Print (TXT_NUMBER_COLON, d_number_x - 5 * RESFACTOR, d_number_y + 1 * RESFACTOR, scheme, TBLACK, TPF_RIGHT | TPF_TEXT);
  6139. }
  6140. /*
  6141. .......................... Redraw buttons ..........................
  6142. */
  6143. if (display >= REDRAW_BUTTONS) {
  6144. commands->Flag_List_To_Redraw();
  6145. }
  6146. Show_Mouse();
  6147. display = REDRAW_NONE;
  6148. }
  6149. /*
  6150. ........................... Get user input ............................
  6151. */
  6152. KeyNumType input = commands->Input();
  6153. if ( firsttime ) {
  6154. nameedit.Set_Focus();
  6155. nameedit.Flag_To_Redraw();
  6156. input = commands->Input();
  6157. firsttime = false;
  6158. }
  6159. /*
  6160. ---------------------------- Process input ----------------------------
  6161. */
  6162. switch (input) {
  6163. case (BUTTON_NAME | KN_BUTTON):
  6164. numedit.Set_Focus();
  6165. numedit.Flag_To_Redraw();
  6166. break;
  6167. // case (BUTTON_NUMBER | KN_BUTTON):
  6168. // nameedit.Clear_Focus();
  6169. // nameedit.Flag_To_Redraw();
  6170. // break;
  6171. /*------------------------------------------------------------------
  6172. Use Default Serial Settings
  6173. ------------------------------------------------------------------*/
  6174. case (BUTTON_DEFAULT | KN_BUTTON):
  6175. custombtn.Turn_Off();
  6176. defaultbtn.Turn_On();
  6177. custom = false;
  6178. break;
  6179. /*------------------------------------------------------------------
  6180. Use Custom Serial Settings
  6181. ------------------------------------------------------------------*/
  6182. case (BUTTON_CUSTOM | KN_BUTTON):
  6183. if (Com_Settings_Dialog (&settings)) {
  6184. custombtn.Turn_On();
  6185. defaultbtn.Turn_Off();
  6186. }
  6187. custom = true;
  6188. display = REDRAW_ALL;
  6189. break;
  6190. /*------------------------------------------------------------------
  6191. CANCEL: bail out
  6192. ------------------------------------------------------------------*/
  6193. case (KN_ESC):
  6194. case (BUTTON_CANCEL | KN_BUTTON):
  6195. process = false;
  6196. rc = false;
  6197. break;
  6198. /*------------------------------------------------------------------
  6199. Save: save changes
  6200. ------------------------------------------------------------------*/
  6201. case (KN_RETURN):
  6202. case (BUTTON_SAVE | KN_BUTTON):
  6203. process = false;
  6204. rc = true;
  6205. break;
  6206. }
  6207. } /* end of while */
  6208. /*------------------------------------------------------------------------
  6209. If 'Save', save all current settings
  6210. ------------------------------------------------------------------------*/
  6211. if (rc) {
  6212. strcpy( phone->Name, strupr( namebuf ) );
  6213. // if nothing was entered then make if NONAME
  6214. if ( !(phone->Name[0]) ) {
  6215. strcpy( phone->Name, "NONAME" );
  6216. }
  6217. strcpy( phone->Number, strupr( numbuf ) );
  6218. if (custom) {
  6219. phone->Settings = settings;
  6220. } else {
  6221. phone->Settings.Port = 0;
  6222. phone->Settings.IRQ = -1;
  6223. phone->Settings.Baud = -1;
  6224. phone->Settings.DialMethod = DIAL_TOUCH_TONE;
  6225. phone->Settings.InitStringIndex = 0;
  6226. phone->Settings.CallWaitStringIndex = CALL_WAIT_CUSTOM;
  6227. phone->Settings.CallWaitString[0] = 0;
  6228. }
  6229. }
  6230. return(rc);
  6231. } /* end of Edit_Phone_Dialog */
  6232. static bool Dial_Modem( SerialSettingsType *settings, bool reconnect )
  6233. {
  6234. bool connected = false;
  6235. DialStatusType dialstatus;
  6236. int modemstatus;
  6237. /*
  6238. ** Turn modem servicing off in the callback routine.
  6239. */
  6240. Session.ModemService = false;
  6241. // save for later to reconnect
  6242. DialSettings = settings;
  6243. modemstatus = NullModem.Get_Modem_Status();
  6244. if (reconnect) {
  6245. if ( (modemstatus & CD_SET) ) {
  6246. connected = true;
  6247. Session.ModemService = true;
  6248. return( connected );
  6249. }
  6250. } else if ( (modemstatus & CD_SET) ) {
  6251. NullModem.Hangup_Modem();
  6252. Session.ModemService = false;
  6253. }
  6254. NullModem.Setup_Modem_Echo( Modem_Echo );
  6255. modemstatus = NullModem.Detect_Modem( settings, reconnect );
  6256. if ( !modemstatus ) {
  6257. NullModem.Remove_Modem_Echo();
  6258. NullModem.Print_EchoBuf();
  6259. NullModem.Reset_EchoBuf();
  6260. //#ifndef WIN32
  6261. /*
  6262. ** If our first attempt to detect the modem failed, and we're at
  6263. ** 14400 or 28800, bump up to the next baud rate & try again.
  6264. */
  6265. switch (settings->Baud) {
  6266. case 14400:
  6267. settings->Baud = 19200;
  6268. Shutdown_Modem();
  6269. Init_Null_Modem(settings);
  6270. NullModem.Setup_Modem_Echo( Modem_Echo );
  6271. modemstatus = NullModem.Detect_Modem( settings, reconnect );
  6272. if ( !modemstatus ) {
  6273. NullModem.Remove_Modem_Echo();
  6274. NullModem.Print_EchoBuf();
  6275. NullModem.Reset_EchoBuf();
  6276. WWMessageBox().Process( TXT_UNABLE_FIND_MODEM );
  6277. Session.ModemService = true;
  6278. return( connected );
  6279. }
  6280. break;
  6281. case 28800:
  6282. settings->Baud = 38400;
  6283. Shutdown_Modem();
  6284. Init_Null_Modem(settings);
  6285. NullModem.Setup_Modem_Echo( Modem_Echo );
  6286. modemstatus = NullModem.Detect_Modem( settings, reconnect );
  6287. if ( !modemstatus ) {
  6288. NullModem.Remove_Modem_Echo();
  6289. NullModem.Print_EchoBuf();
  6290. NullModem.Reset_EchoBuf();
  6291. WWMessageBox().Process( TXT_UNABLE_FIND_MODEM );
  6292. Session.ModemService = true;
  6293. return( connected );
  6294. }
  6295. break;
  6296. default:
  6297. WWMessageBox().Process( TXT_UNABLE_FIND_MODEM );
  6298. Session.ModemService = true;
  6299. return( connected );
  6300. }
  6301. //#else //WIN32
  6302. // Session.ModemService = true;
  6303. // return( connected );
  6304. //#endif //WIN32
  6305. } else if ( modemstatus == -1 ) {
  6306. NullModem.Remove_Modem_Echo();
  6307. NullModem.Print_EchoBuf();
  6308. NullModem.Reset_EchoBuf();
  6309. WWMessageBox().Process( TXT_ERROR_IN_INITSTRING );
  6310. // WWMessageBox().Process( "Error in the InitString." );
  6311. Session.ModemService = true;
  6312. return( connected );
  6313. }
  6314. #ifdef WIN32
  6315. #ifdef FIXIT_APTIVA_MODEM
  6316. /*
  6317. ** Completely disable audio. This is required for MWave devices like those
  6318. ** found in the IBM Aptiva.
  6319. */
  6320. ThemeType old_theme = THEME_NONE;
  6321. if (SoundOn){
  6322. old_theme = Theme.What_Is_Playing();
  6323. Theme.Stop();
  6324. CountDownTimerClass wait;
  6325. Call_Back();
  6326. wait.Set (60,true);
  6327. while ( wait.Time() ) {
  6328. Call_Back();
  6329. }
  6330. Sound_End();
  6331. Call_Back();
  6332. wait.Set (60,true);
  6333. while ( wait.Time() ) {
  6334. Call_Back();
  6335. }
  6336. SoundOn = 0;
  6337. }
  6338. #endif //FIXIT_APTIVA_MODEM
  6339. #endif //WIN32
  6340. dialstatus = NullModem.Dial_Modem( DialString, settings->DialMethod, reconnect );
  6341. if (reconnect) {
  6342. /*
  6343. --------------------------- Redraw the display ---------------------------
  6344. */
  6345. HidPage.Clear();
  6346. Map.Flag_To_Redraw(true);
  6347. Map.Render();
  6348. }
  6349. switch ( dialstatus ) {
  6350. case DIAL_CONNECTED:
  6351. connected = true;
  6352. break;
  6353. case DIAL_NO_CARRIER:
  6354. WWMessageBox().Process(TXT_NO_CARRIER);
  6355. connected = false;
  6356. break;
  6357. case DIAL_BUSY:
  6358. WWMessageBox().Process(TXT_LINE_BUSY);
  6359. connected = false;
  6360. break;
  6361. case DIAL_ERROR:
  6362. WWMessageBox().Process(TXT_NUMBER_INVALID);
  6363. connected = false;
  6364. break;
  6365. case DIAL_NO_DIAL_TONE:
  6366. WWMessageBox().Process(TXT_NO_DIAL_TONE);
  6367. connected = false;
  6368. break;
  6369. case DIAL_CANCELED:
  6370. NullModem.Hangup_Modem();
  6371. Session.ModemService = false;
  6372. WWMessageBox().Process(TXT_DIALING_CANCELED);
  6373. connected = false;
  6374. break;
  6375. }
  6376. NullModem.Remove_Modem_Echo();
  6377. NullModem.Print_EchoBuf();
  6378. NullModem.Reset_EchoBuf();
  6379. #ifdef WIN32
  6380. #ifdef FIXIT_APTIVA_MODEM
  6381. /*
  6382. ** Restore audio capability
  6383. */
  6384. SoundOn = Audio_Init ( MainWindow , 16 , false , 11025*2 , 0 );
  6385. if (SoundOn){
  6386. Theme.Play_Song (old_theme);
  6387. }
  6388. #endif //FIXIT_APTIVA_MODEM
  6389. #endif //WIN32
  6390. Session.ModemService = true;
  6391. return( connected );
  6392. } /* end of Dial_Modem */
  6393. static bool Answer_Modem( SerialSettingsType *settings, bool reconnect )
  6394. {
  6395. bool connected = false;
  6396. DialStatusType dialstatus;
  6397. int modemstatus;
  6398. /*
  6399. ** Turn modem servicing off in the callback routine.
  6400. */
  6401. Session.ModemService = false;
  6402. // save for later to reconnect
  6403. DialSettings = settings;
  6404. modemstatus = NullModem.Get_Modem_Status();
  6405. if (reconnect) {
  6406. if ( (modemstatus & CD_SET) ) {
  6407. connected = true;
  6408. Session.ModemService = true;
  6409. return( connected );
  6410. }
  6411. } else if ( (modemstatus & CD_SET) ) {
  6412. NullModem.Hangup_Modem();
  6413. Session.ModemService = false;
  6414. }
  6415. NullModem.Setup_Modem_Echo( Modem_Echo );
  6416. modemstatus = NullModem.Detect_Modem( settings, reconnect );
  6417. if ( !modemstatus ) {
  6418. NullModem.Remove_Modem_Echo();
  6419. NullModem.Print_EchoBuf();
  6420. NullModem.Reset_EchoBuf();
  6421. //#ifndef WIN32
  6422. /*
  6423. ** If our first attempt to detect the modem failed, and we're at
  6424. ** 14400 or 28800, bump up to the next baud rate & try again.
  6425. */
  6426. switch (settings->Baud) {
  6427. case 14400:
  6428. settings->Baud = 19200;
  6429. Shutdown_Modem();
  6430. Init_Null_Modem(settings);
  6431. NullModem.Setup_Modem_Echo( Modem_Echo );
  6432. modemstatus = NullModem.Detect_Modem( settings, reconnect );
  6433. if ( !modemstatus ) {
  6434. NullModem.Remove_Modem_Echo();
  6435. NullModem.Print_EchoBuf();
  6436. NullModem.Reset_EchoBuf();
  6437. WWMessageBox().Process( TXT_UNABLE_FIND_MODEM );
  6438. Session.ModemService = true;
  6439. return( connected );
  6440. }
  6441. break;
  6442. case 28800:
  6443. settings->Baud = 38400;
  6444. Shutdown_Modem();
  6445. Init_Null_Modem(settings);
  6446. NullModem.Setup_Modem_Echo( Modem_Echo );
  6447. modemstatus = NullModem.Detect_Modem( settings, reconnect );
  6448. if ( !modemstatus ) {
  6449. NullModem.Remove_Modem_Echo();
  6450. NullModem.Print_EchoBuf();
  6451. NullModem.Reset_EchoBuf();
  6452. WWMessageBox().Process( TXT_UNABLE_FIND_MODEM );
  6453. Session.ModemService = true;
  6454. return( connected );
  6455. }
  6456. break;
  6457. default:
  6458. WWMessageBox().Process( TXT_UNABLE_FIND_MODEM );
  6459. Session.ModemService = true;
  6460. return( connected );
  6461. }
  6462. //#else //WIN32
  6463. // Session.ModemService = true;
  6464. // return( connected );
  6465. //#endif //WIN32
  6466. } else if ( modemstatus == -1 ) {
  6467. NullModem.Remove_Modem_Echo();
  6468. NullModem.Print_EchoBuf();
  6469. NullModem.Reset_EchoBuf();
  6470. WWMessageBox().Process( TXT_ERROR_IN_INITSTRING );
  6471. Session.ModemService = true;
  6472. return( connected );
  6473. }
  6474. #ifdef WIN32
  6475. #ifdef FIXIT_APTIVA_MODEM
  6476. /*
  6477. ** Completely disable audio. This is required for some MWave devices like those
  6478. ** found in the IBM Aptiva.
  6479. */
  6480. ThemeType old_theme = THEME_NONE;
  6481. if (SoundOn){
  6482. old_theme = Theme.What_Is_Playing();
  6483. Theme.Stop();
  6484. CountDownTimerClass wait;
  6485. Call_Back();
  6486. wait.Set (60,true);
  6487. while ( wait.Time() ) {
  6488. Call_Back();
  6489. }
  6490. Sound_End();
  6491. Call_Back();
  6492. wait.Set (60,true);
  6493. while ( wait.Time() ) {
  6494. Call_Back();
  6495. }
  6496. SoundOn = 0;
  6497. }
  6498. #endif //FIXIT_APTIVA_MODEM
  6499. #endif //WIN32
  6500. dialstatus = NullModem.Answer_Modem( reconnect );
  6501. switch ( dialstatus ) {
  6502. case DIAL_CONNECTED:
  6503. connected = true;
  6504. break;
  6505. case DIAL_NO_CARRIER:
  6506. WWMessageBox().Process(TXT_NO_CARRIER);
  6507. connected = false;
  6508. break;
  6509. // case DIAL_BUSY:
  6510. // WWMessageBox().Process(TXT_LINE_BUSY);
  6511. // connected = false;
  6512. // break;
  6513. case DIAL_ERROR:
  6514. WWMessageBox().Process(TXT_NUMBER_INVALID);
  6515. connected = false;
  6516. break;
  6517. case DIAL_CANCELED:
  6518. WWMessageBox().Process(TXT_ANSWERING_CANCELED);
  6519. connected = false;
  6520. break;
  6521. }
  6522. NullModem.Remove_Modem_Echo();
  6523. NullModem.Print_EchoBuf();
  6524. NullModem.Reset_EchoBuf();
  6525. #ifdef WIN32
  6526. #ifdef FIXIT_APTIVA_MODEM
  6527. /*
  6528. ** Restore audio capability
  6529. */
  6530. SoundOn = Audio_Init ( MainWindow , 16 , false , 11025*2 , 0 );
  6531. if (SoundOn){
  6532. Theme.Play_Song (old_theme);
  6533. }
  6534. #endif //FIXIT_APTIVA_MODEM
  6535. #endif //WIN32
  6536. Session.ModemService = true;
  6537. return( connected );
  6538. } /* end of Answer_Modem */
  6539. static void Modem_Echo( char c )
  6540. {
  6541. if (NullModem.EchoCount < (NullModem.EchoSize - 1) ) {
  6542. *(NullModem.EchoBuf + NullModem.EchoCount) = c;
  6543. *(NullModem.EchoBuf + NullModem.EchoCount + 1) = 0;
  6544. NullModem.EchoCount++;
  6545. }
  6546. } /* end of Modem_Echo */
  6547. void Smart_Printf( char *format, ... )
  6548. {
  6549. va_list arglist;
  6550. char buf[501];
  6551. va_start(arglist,format);
  6552. vsprintf(buf,format,arglist);
  6553. va_end(arglist);
  6554. if (Debug_Smart_Print) {
  6555. if (MonoClass::Is_Enabled()) {
  6556. Mono_Printf("%s",buf);
  6557. } else {
  6558. printf("%s",buf);
  6559. }
  6560. } else {
  6561. if (Debug_Heap_Dump) {
  6562. printf("%s",buf);
  6563. }
  6564. if (Debug_Modem_Dump) {
  6565. printf("%s",buf);
  6566. }
  6567. }
  6568. }
  6569. void Hex_Dump_Data( char *buffer, int length )
  6570. {
  6571. int i;
  6572. int offset = 0;
  6573. char buff[10];
  6574. char ptr[16];
  6575. char c;
  6576. while (length >= 16) {
  6577. memcpy( ptr, (buffer + offset), 16);
  6578. Smart_Printf("%05lX ", offset);
  6579. for (i = 0; i < 16; i++) {
  6580. c = ptr[i];
  6581. itoh(c, buff);
  6582. if (!(i & 0x3) && i) {
  6583. Smart_Printf("³ ");
  6584. }
  6585. Smart_Printf("%s ", buff);
  6586. }
  6587. Smart_Printf(" ");
  6588. for (i = 0; i < 16; i++) {
  6589. c = ptr[i];
  6590. if (c && ((c < 7) || (c > 11)) && (c != 13)) {
  6591. Smart_Printf("%c", c);
  6592. } else {
  6593. Smart_Printf(".");
  6594. }
  6595. }
  6596. Smart_Printf("\n");
  6597. offset += 16;
  6598. length -= 16;
  6599. }
  6600. if (length) {
  6601. memcpy( ptr, (buffer + offset), 16);
  6602. Smart_Printf("%05lX ", offset);
  6603. for (i = 0; i < 16; i++) {
  6604. if (i < length) {
  6605. c = ptr[i];
  6606. itoh(c, buff);
  6607. if (!(i & 0x3) && i) {
  6608. Smart_Printf("³ ");
  6609. }
  6610. Smart_Printf("%s ", buff);
  6611. } else {
  6612. if (!(i & 0x3) && i) {
  6613. Smart_Printf(" ");
  6614. }
  6615. Smart_Printf(" ");
  6616. }
  6617. }
  6618. Smart_Printf(" ");
  6619. for (i = 0; i < length; i++) {
  6620. c = ptr[i];
  6621. if (c && ((c < 7) || (c > 11)) && (c != 13)) {
  6622. Smart_Printf("%c", c);
  6623. } else {
  6624. Smart_Printf(".");
  6625. }
  6626. }
  6627. Smart_Printf("\n");
  6628. }
  6629. } /* end of Hex_Dump_Data */
  6630. void itoh( int i, char *s)
  6631. {
  6632. int nibble, loop;
  6633. // *s++ = '0';
  6634. // *s++ = 'x';
  6635. if (i == 0) {
  6636. *s++ = '0';
  6637. *s++ = '0';
  6638. } else {
  6639. for (loop = 1; loop >= 0; loop--) {
  6640. nibble = (i >> (loop << 2)) & 0x000F;
  6641. /* decimal range */
  6642. if (nibble < 10) {
  6643. *s++ = '0' + nibble;
  6644. } else {
  6645. *s++ = 'A' + (nibble - 10);
  6646. }
  6647. }
  6648. }
  6649. *s = 0; /* null terminate it */
  6650. }
  6651. void Log_Start_Time( char *string )
  6652. {
  6653. // LogDump_Print = true;
  6654. LogLevel = 0;
  6655. LogLevelTime[ LogLevel ] = LogLastTime = TickCount;
  6656. Smart_Printf( "start tick=%d, %s \n", LogLastTime, string );
  6657. }
  6658. void Log_End_Time( char *string )
  6659. {
  6660. int i;
  6661. unsigned long currtime;
  6662. unsigned long ticks;
  6663. currtime = TickCount;
  6664. while (LogLevel >= 0) {
  6665. if (LogLevel < MAX_LOG_LEVEL) {
  6666. //
  6667. // put one space for each level as indenting
  6668. //
  6669. i = 0;
  6670. while (i++ < LogLevel) {
  6671. Smart_Printf( " " );
  6672. }
  6673. } else {
  6674. Smart_Printf( "LogLevel %d too large!-! \n", LogLevel);
  6675. LogLevel = MAX_LOG_LEVEL - 1;
  6676. }
  6677. ticks = currtime - LogLevelTime[ LogLevel-- ];
  6678. Smart_Printf( "end tick=%d, ticks=%d, tsecs=%d, %s \n",
  6679. currtime, ticks, ((ticks * 10) / 60), string );
  6680. }
  6681. LogDump_Print = false;
  6682. }
  6683. void Log_Time( char *string )
  6684. {
  6685. int i;
  6686. unsigned long currtime;
  6687. unsigned long ticks;
  6688. currtime = TickCount;
  6689. if (LogLevel < MAX_LOG_LEVEL) {
  6690. //
  6691. // put one space for each level as indenting
  6692. //
  6693. i = 0;
  6694. while (i++ < LogLevel) {
  6695. Smart_Printf( " " );
  6696. }
  6697. } else {
  6698. Smart_Printf( "LogLevel %d too large!-! \n", LogLevel);
  6699. LogLevel = MAX_LOG_LEVEL - 1;
  6700. }
  6701. ticks = currtime - LogLastTime;
  6702. Smart_Printf( "tick=%d, ticks=%d, tsecs=%d, %s \n",
  6703. currtime, ticks, ((ticks * 10) / 60), string );
  6704. LogLastTime = currtime;
  6705. }
  6706. void Log_Start_Nest_Time( char *string )
  6707. {
  6708. int i;
  6709. unsigned long currtime;
  6710. unsigned long ticks;
  6711. currtime = TickCount;
  6712. if (LogLevel < MAX_LOG_LEVEL) {
  6713. //
  6714. // put one space for each level as indenting
  6715. //
  6716. i = 0;
  6717. while (i++ < LogLevel) {
  6718. Smart_Printf( " " );
  6719. }
  6720. } else {
  6721. Smart_Printf( "LogLevel %d too large!-! \n", LogLevel);
  6722. LogLevel = MAX_LOG_LEVEL - 1;
  6723. }
  6724. ticks = currtime - LogLastTime;
  6725. Smart_Printf( "start ntick=%d, ticks=%d, tsecs=%d, %s \n",
  6726. currtime, ticks, ((ticks * 10) / 60), string );
  6727. if (LogLevel >= (MAX_LOG_LEVEL - 1) ) {
  6728. Smart_Printf( "Could not start another nesting Maxed at %d,%d!-! \n",
  6729. LogLevel, (MAX_LOG_LEVEL - 1) );
  6730. } else {
  6731. LogLevelTime[ ++LogLevel ] = currtime;
  6732. }
  6733. LogLastTime = currtime;
  6734. }
  6735. void Log_End_Nest_Time( char *string )
  6736. {
  6737. int i;
  6738. unsigned long currtime;
  6739. unsigned long ticks;
  6740. currtime = TickCount;
  6741. if (LogLevel <= 0) {
  6742. Smart_Printf( "Could not end another nesting Mined at %d,%d!-! \n",
  6743. LogLevel, 0 );
  6744. LogLevel = 0;
  6745. }
  6746. if (LogLevel < MAX_LOG_LEVEL) {
  6747. //
  6748. // put one space for each level as indenting
  6749. //
  6750. i = 0;
  6751. while (i++ < LogLevel) {
  6752. Smart_Printf( " " );
  6753. }
  6754. } else {
  6755. Smart_Printf( "LogLevel %d too large!-! \n", LogLevel);
  6756. LogLevel = MAX_LOG_LEVEL - 1;
  6757. }
  6758. ticks = currtime - LogLevelTime[ LogLevel ];
  6759. Smart_Printf( "end ntick=%d, ticks=%d, secs=%d, %s \n",
  6760. currtime, ticks, ((ticks * 10) / 60), string );
  6761. if (LogLevel) {
  6762. LogLevel--;
  6763. }
  6764. LogLastTime = currtime;
  6765. }
  6766. #endif