| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835 |
- //
- // Copyright 2020 Electronic Arts Inc.
- //
- // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free
- // software: you can redistribute it and/or modify it under the terms of
- // the GNU General Public License as published by the Free Software Foundation,
- // either version 3 of the License, or (at your option) any later version.
- // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed
- // in the hope that it will be useful, but with permitted additional restrictions
- // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
- // distributed with this program. You should have received a copy of the
- // GNU General Public License along with permitted additional restrictions
- // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
- /* $Header: /counterstrike/NULLDLG.CPP 14 3/17/97 1:05a Steve_tall $ */
- /***************************************************************************
- ** 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 **
- ***************************************************************************
- * *
- * Project Name : Command & Conquer *
- * *
- * File Name : NULLDLG.CPP *
- * *
- * Programmer : Bill R. Randolph *
- * *
- * Start Date : 04/29/95 *
- * *
- * Last Update : Jan. 21, 1997 [V.Grippi] *
- * *
- *-------------------------------------------------------------------------*
- * Functions: *
- * Build_InitString_Listbox -- [re]builds the initstring entry listbox *
- * Build_Phone_Listbox -- [re]builds the phone entry listbox *
- * Com_Scenario_Dialog -- Serial game scenario selection dialog *
- * Com_Settings_Dialog -- Lets user select serial port settings *
- * Destroy_Null_Connection -- destroys the given connection *
- * Edit_Phone_Dialog -- lets user edit a phone book entry *
- * Init_Null_Modem -- Initializes Null Modem communications *
- * Init_String_Compare -- for qsort *
- * Phone_Compare -- for qsort *
- * Phone_Dialog -- Lets user edit phone directory & dial *
- * Reconnect_Null_Modem -- allows user to reconnect *
- * Select_Serial_Dialog -- Serial Communications menu dialog *
- * Shutdown_Modem -- Shuts down modem/null-modem communications *
- * Test_Null_Modem -- Null-Modem test routine *
- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
- #include "function.h"
- //PG
- GameType Select_Serial_Dialog(void) { return GAME_NORMAL; }
- #if (0)//PG
- #ifdef FIXIT_RANDOM_GAME
- #include "time.h"
- #endif
- #ifdef WIN32
- #include "wincomm.h"
- #include "modemreg.h"
- ModemRegistryEntryClass *ModemRegistry = NULL; //Ptr to modem registry data
- #endif //WIN32
- #include "COORDA.h"
- #ifdef FIXIT_CSII // checked - ajw 9/28/98
- extern bool Is_Mission_126x126 (char *file_name);
- extern bool Is_Mission_Counterstrike (char *file_name);
- extern bool Is_Mission_Aftermath( char* file_name );
- #endif
- //#include "WolDebug.h"
- //
- // how much time (ticks) to go by before thinking other system
- // is not responding.
- //
- #define PACKET_SENDING_TIMEOUT 1800
- #define PACKET_CANCEL_TIMEOUT 900
- //extern char const *ForMisStr[];
- extern char const *EngMisStr[];
- //
- // how much time (ticks) to go by before sending another packet
- // of game options or serial connect.
- //
- #define PACKET_RETRANS_TIME 30
- #define PACKET_REDRAW_TIME 60
- static int Reconnect_Null_Modem( void );
- static int Com_Settings_Dialog( SerialSettingsType *settings );
- static int Phone_Dialog (void);
- static void Build_Init_String_Listbox (ListClass *list, EditClass *edit, char *buf, int *index);
- static int Init_String_Compare (const void *p1, const void *p2);
- static void Build_Phone_Listbox (ListClass *list, EditClass *edit, char *buf);
- static int Phone_Compare (const void *p1, const void *p2);
- static int Edit_Phone_Dialog (PhoneEntryClass *phone);
- static bool Dial_Modem( SerialSettingsType *settings, bool reconnect );
- static bool Answer_Modem( SerialSettingsType *settings, bool reconnect );
- static void Modem_Echo( char c );
- void Smart_Printf( char *format, ... );
- void Hex_Dump_Data( char *buffer, int length );
- void itoh( int i, char *s);
- static SerialPacketType SendPacket;
- static SerialPacketType ReceivePacket;
- char TheirName[MPLAYER_NAME_MAX];
- PlayerColorType TheirColor;
- HousesType TheirHouse;
- static char DialString[ CWAITSTRBUF_MAX + PhoneEntryClass::PHONE_MAX_NUM - 1 ];
- static SerialSettingsType *DialSettings;
- #ifdef FIXIT_VERSION_3
- bool Force_Scenario_Available( const char* szName );
- bool bSpecialAftermathScenario( const char* szScenarioDescription );
- #endif
- #define PCOLOR_BROWN PCOLOR_GREY
- #define SHOW_MONO 0
- /***************************************************************************
- * Init_Null_Modem -- Initializes Null Modem communications *
- * *
- * INPUT: *
- * none. *
- * *
- * OUTPUT: *
- * true = OK, false = error *
- * *
- * WARNINGS: *
- * none. *
- * *
- * HISTORY: *
- * 04/29/1995 BRR : Created. *
- * 8/2/96 ST : Win32 support added *
- *=========================================================================*/
- int Init_Null_Modem( SerialSettingsType *settings )
- {
- #ifdef WIN32
- if ( NullModem.Init( settings->Port, settings->IRQ,
- settings->ModemName,
- settings->Baud, 0, 8, 1,
- settings->HardwareFlowControl ) ) {
- return (true);
- } else {
- return (false);
- }
- #else //WIN32
- if ( NullModem.Init( settings->Port, settings->IRQ,
- settings->ModemName,
- settings->Baud, 'N', 8, 1,
- settings->HardwareFlowControl) ) {
- NullModem.Change_IRQ_Priority( settings->IRQ );
- return(true);
- } else {
- return(false);
- }
- #endif //WIN32
- }
- /***************************************************************************
- * Shutdown_Modem -- Shuts down modem/null-modem communications *
- * *
- * INPUT: *
- * none. *
- * *
- * OUTPUT: *
- * none. *
- * *
- * WARNINGS: *
- * none. *
- * *
- * HISTORY: *
- * 04/29/1995 BRR : Created. *
- *=========================================================================*/
- void Shutdown_Modem( void )
- {
- if (!Session.Play) {
- if (Session.Type == GAME_MODEM) {
- NullModem.Hangup_Modem();
- }
- }
- NullModem.Change_IRQ_Priority( 0 ); // reset priority of interrupts
- //
- // close port
- //
- NullModem.Shutdown();
- }
- /***************************************************************************
- * Modem_Signoff -- sends EXIT event *
- * *
- * INPUT: *
- * none. *
- * *
- * OUTPUT: *
- * none. *
- * *
- * WARNINGS: *
- * none. *
- * *
- * HISTORY: *
- * 08/03/1995 DRD : Created. *
- *=========================================================================*/
- void Modem_Signoff( void )
- {
- unsigned long starttime;
- EventClass event;
- if (!Session.Play) {
- /*
- ** Send a sign-off packet
- */
- memset (&event, 0, sizeof(EventClass));
- event.Type = EventClass::EXIT;
- NullModem.Send_Message (&event,sizeof(EventClass),0);
- NullModem.Send_Message (&event,sizeof(EventClass),0);
- starttime = TickCount;
- while ( (TickCount - starttime) < 30) {
- NullModem.Service();
- }
- }
- }
- /***************************************************************************
- * Test_Null_Modem -- Null-Modem test routine *
- * *
- * INPUT: *
- * none. *
- * *
- * OUTPUT: *
- * 0 = failure to connect; 1 = I'm the game owner, 2 = I'm not *
- * *
- * WARNINGS: *
- * none. *
- * *
- * HISTORY: *
- * 04/29/1995 BRR : Created. *
- * 8/2/96 ST : Win32 support added *
- *=========================================================================*/
- int Test_Null_Modem( void )
- {
- /*
- ** Get the resolution factor
- */
- // int factor = (SeenBuff.Get_Width() == 320) ? 1 : 2;
- /*
- ** Button Enumerations
- */
- enum {
- BUTTON_CANCEL = 100,
- };
- /*
- ** Dialog variables
- */
- bool process = true; // process while true
- int retval;
- unsigned long starttime;
- int packetlen;
- int x,y,width,height; // dialog dimensions
- char buffer[80*3];
- RemapControlType * scheme = GadgetClass::Get_Color_Scheme();
- /*
- ** Buttons
- */
- GadgetClass *commands; // button list
- /*
- ** Determine the dimensions of the text to be used for the dialog box.
- ** These dimensions will control how the dialog box looks.
- */
- strcpy( buffer, Text_String( TXT_WAITING_CONNECT ) );
- Fancy_Text_Print(TXT_NONE,0,0,TBLACK,TBLACK,TPF_6PT_GRAD | TPF_NOSHADOW);
- Format_Window_String(buffer, SeenBuff.Get_Height(), width, height);
- width = max(width, 50 * RESFACTOR);
- width += 40 * RESFACTOR;
- height += 60 * RESFACTOR;
- x = (SeenBuff.Get_Width() - width) / 2;
- y = (SeenBuff.Get_Height() - height) / 2;
- TextButtonClass cancelbtn(BUTTON_CANCEL, TXT_CANCEL, TPF_BUTTON,
- x + ((width - (String_Pixel_Width( Text_String( TXT_CANCEL ) ) + 8 * RESFACTOR)) >> 1),
- y + height - (FontHeight + FontYSpacing + 2 * RESFACTOR) - 10 * RESFACTOR);
- /*
- ** Initialize
- */
- Set_Logic_Page(SeenBuff);
- process = true;
- /*
- ** Create the list
- */
- commands = &cancelbtn;
- commands->Flag_List_To_Redraw();
- /*
- ** Draw the dialog
- */
- Hide_Mouse();
- Load_Title_Page(true);
- Dialog_Box(x, y, width, height);
- Draw_Caption(TXT_NONE, x, y, width);
- Fancy_Text_Print(buffer, x + 20 * RESFACTOR, y + 25 * RESFACTOR, scheme, TBLACK, TPF_TEXT);
- commands->Draw_All();
- while (Get_Mouse_State() > 0) Show_Mouse();
- #ifdef WIN32
- /*
- ** This is supposed to be a direct connection so hang up any modem on this port
- ** just to annoy British Telecom
- */
- /*
- ** Go into break mode
- */
- SetCommBreak(SerialPort->Get_Port_Handle());
- /*
- ** Send hangup command
- */
- SerialPort->Write_To_Serial_Port ((unsigned char*)"ATH\r", strlen("ATH\r"));
- CountDownTimerClass time;
- time.Set(2*60);
- while (time.Time()) {}
- /*
- ** Back out of break mode
- */
- ClearCommBreak(SerialPort->Get_Port_Handle());
- /*
- ** Drop DTR as well - just in case the modem still hasnt got the message
- */
- EscapeCommFunction(SerialPort->Get_Port_Handle(), CLRDTR);
- #endif //WIN32
- /*
- ** Check for a packet. If we detect one, the other system has already been
- ** started. Wait 1/2 sec for him to receive my ACK, then exit with success.
- ** Note: The initial time must be a little longer than the resend delay.
- ** Just in case we just missed the packet.
- */
- starttime = TickCount;
- while ( TickCount - starttime < 80) {
- NullModem.Service();
- if ( NullModem.Get_Message( &ReceivePacket, &packetlen ) > 0) {
- if (ReceivePacket.Command == SERIAL_CONNECT) {
- starttime = TickCount;
- while (TickCount - starttime < 30)
- NullModem.Service();
- process = false;
- retval = 2;
- break;
- }
- }
- }
- /*
- ** Send a packet across. As long as Num_Send() is non-zero, the other system
- ** hasn't received it yet.
- */
- if (process) {
- memset (&SendPacket, 0, sizeof(SerialPacketType));
- SendPacket.Command = SERIAL_CONNECT;
- //
- // put time from start of game for determining the host in case of tie.
- //
- SendPacket.ScenarioInfo.Seed = TickCount;
- SendPacket.ID = (int) buffer; // address of buffer for more uniqueness.
- NullModem.Send_Message (&SendPacket, sizeof(SendPacket), 1);
- starttime = TickCount;
- while (TickCount - starttime < 80) {
- NullModem.Service();
- if (NullModem.Get_Message (&ReceivePacket, &packetlen) > 0) {
- if (ReceivePacket.Command == SERIAL_CONNECT) {
- starttime = TickCount;
- while (TickCount - starttime < 30)
- NullModem.Service();
- //
- // whoever has the highest time is the host
- //
- if (ReceivePacket.ScenarioInfo.Seed > SendPacket.ScenarioInfo.Seed) {
- process = false;
- retval = 2;
- } else if (ReceivePacket.ScenarioInfo.Seed == SendPacket.ScenarioInfo.Seed) {
- if (ReceivePacket.ID > SendPacket.ID) {
- process = false;
- retval = 2;
- //
- // if they are equal then it's a loopback cable or a modem
- //
- } else if (ReceivePacket.ID == SendPacket.ID) {
- process = false;
- retval = 3;
- }
- }
- break;
- }
- }
- }
- }
- starttime = TickCount;
- /*
- ** Main Processing Loop
- */
- while (process) {
- #ifdef WIN32
- /*
- ** If we have just received input focus again after running in the background then
- ** we need to redraw.
- */
- if (AllSurfaces.SurfacesRestored) {
- AllSurfaces.SurfacesRestored=FALSE;
- commands->Draw_All();
- }
- #endif //WIN32
- /*
- ** Invoke game callback
- */
- Call_Back();
- /*
- ** Get user input
- */
- KeyNumType input = commands->Input();
- /*
- ** Process input
- */
- switch (input) {
- case (KN_ESC):
- case (BUTTON_CANCEL | KN_BUTTON):
- retval = 0;
- process = false;
- break;
- default:
- break;
- }
- /*
- ** Service the connection.
- */
- NullModem.Service();
- if (NullModem.Num_Send() == 0) {
- if (NullModem.Get_Message (&ReceivePacket, &packetlen) > 0) {
- if (ReceivePacket.Command == SERIAL_CONNECT) {
- starttime = TickCount;
- while (TickCount - starttime < 30)
- NullModem.Service();
- //
- // whoever has the highest time is the host
- //
- if (ReceivePacket.ScenarioInfo.Seed > SendPacket.ScenarioInfo.Seed) {
- process = false;
- retval = 2;
- } else if (ReceivePacket.ScenarioInfo.Seed == SendPacket.ScenarioInfo.Seed) {
- if (ReceivePacket.ID > SendPacket.ID) {
- process = false;
- retval = 2;
- //
- // if they are equal then it's a loopback cable or a modem
- //
- } else if (ReceivePacket.ID == SendPacket.ID) {
- process = false;
- retval = 3;
- }
- }
- } else {
- retval = 0;
- process = false;
- }
- } else {
- retval = 1;
- process = false;
- }
- }
- if (TickCount - starttime > 3600) { // only wait 1 minute
- retval = 0;
- process = false;
- }
- } /* end of while */
- return( retval );
- }
- /***************************************************************************
- * Reconnect_Modem -- allows user to reconnect *
- * *
- * INPUT: *
- * none. *
- * *
- * OUTPUT: *
- * 0 = failure to connect; 1 = connect OK *
- * *
- * WARNINGS: *
- * none. *
- * *
- * HISTORY: *
- * 04/29/1995 BRR : Created. *
- *=========================================================================*/
- int Reconnect_Modem( void )
- {
- int status;
- int modemstatus;
- switch (Session.ModemType) {
- case (MODEM_NULL_HOST):
- case (MODEM_NULL_JOIN):
- status = Reconnect_Null_Modem();
- break;
- case (MODEM_DIALER):
- modemstatus = NullModem.Get_Modem_Status();
- if ( (modemstatus & CD_SET) ) {
- status = Reconnect_Null_Modem();
- } else {
- status = Dial_Modem( DialSettings, true );
- }
- break;
- case (MODEM_ANSWERER):
- modemstatus = NullModem.Get_Modem_Status();
- if ( (modemstatus & CD_SET) ) {
- status = Reconnect_Null_Modem();
- } else {
- status = Answer_Modem( DialSettings, true );
- }
- break;
- }
- return( status );
- }
- /***************************************************************************
- * Reconnect_Null_Modem -- allows user to reconnect *
- * *
- * INPUT: *
- * none. *
- * *
- * OUTPUT: *
- * 0 = failure to connect; 1 = connect OK *
- * *
- * WARNINGS: *
- * none. *
- * *
- * HISTORY: *
- * 04/29/1995 BRR : Created. *
- *=========================================================================*/
- static int Reconnect_Null_Modem( void )
- {
- /*
- ** Button Enumerations
- */
- enum {
- BUTTON_CANCEL = 100,
- };
- /*
- ** Dialog variables
- */
- bool process = true; // process while true
- KeyNumType input;
- int retval;
- unsigned long starttime;
- unsigned long lastmsgtime;
- int packetlen;
- RemapControlType * scheme = GadgetClass::Get_Color_Scheme();
- int x,y,width,height; // dialog dimensions
- char buffer[80*3];
- /*
- ** Buttons
- */
- GadgetClass *commands; // button list
- /*
- ** Determine the dimensions of the text to be used for the dialog box.
- ** These dimensions will control how the dialog box looks.
- */
- strcpy( buffer, Text_String( TXT_NULL_CONNERR_CHECK_CABLES ) );
- Fancy_Text_Print(TXT_NONE,0,0,TBLACK,TBLACK,TPF_6PT_GRAD | TPF_NOSHADOW);
- Format_Window_String(buffer, SeenBuff.Get_Height(), width, height);
- width = max(width, 50 * RESFACTOR);
- width += 40 * RESFACTOR;
- height += 60 * RESFACTOR;
- x = (SeenBuff.Get_Width() - width) / 2;
- y = (SeenBuff.Get_Height() - height) / 2;
- TextButtonClass cancelbtn(BUTTON_CANCEL, TXT_CANCEL, TPF_BUTTON,
- x + ((width - (String_Pixel_Width( Text_String( TXT_CANCEL ) ) + 8 * RESFACTOR)) >> 1),
- y + height - (FontHeight + FontYSpacing + 2*RESFACTOR) - 10 * RESFACTOR);
- /*
- ** Initialize
- */
- Set_Logic_Page(SeenBuff);
- process = true;
- /*
- ** Create the list
- */
- commands = &cancelbtn;
- commands->Flag_List_To_Redraw();
- /*
- ** Draw the dialog
- */
- Hide_Mouse();
- Dialog_Box(x, y, width, height);
- Draw_Caption(TXT_NONE, x, y, width);
- Fancy_Text_Print(buffer, x + 20*RESFACTOR, y + 25*RESFACTOR, scheme, TBLACK, TPF_TEXT);
- commands->Draw_All();
- Show_Mouse();
- /*
- ** Main Processing Loop
- */
- starttime = lastmsgtime = TickCount;
- while (process) {
- #ifdef WIN32
- /*
- ** If we have just received input focus again after running in the background then
- ** we need to redraw.
- */
- if (AllSurfaces.SurfacesRestored) {
- AllSurfaces.SurfacesRestored=FALSE;
- commands->Draw_All();
- }
- #endif //WIN32
- /*
- ** Invoke game callback
- */
- Call_Back();
- /*
- ** Get user input
- */
- input = commands->Input();
- /*
- ** Process input
- */
- switch (input) {
- case (KN_ESC):
- case (BUTTON_CANCEL | KN_BUTTON):
- retval = false;
- process = false;
- break;
- default:
- break;
- }
- /*
- ** Service the connection.
- */
- NullModem.Service();
- /*
- ** Resend our message if it's time
- */
- if (TickCount - starttime > PACKET_RETRANS_TIME) {
- starttime = TickCount;
- memset (&SendPacket, 0, sizeof(SerialPacketType));
- SendPacket.Command = SERIAL_CONNECT;
- SendPacket.ID = Session.ColorIdx;
- NullModem.Send_Message (&SendPacket, sizeof(SendPacket), 0);
- }
- /*
- ** Check for an incoming message
- */
- if (NullModem.Get_Message (&ReceivePacket, &packetlen) > 0) {
- lastmsgtime = TickCount;
- if (ReceivePacket.Command == SERIAL_CONNECT) {
- // are we getting our own packets back??
- if (ReceivePacket.ID == Session.ColorIdx) {
- WWMessageBox().Process (TXT_SYSTEM_NOT_RESPONDING);
- retval = false;
- process = false;
- break;
- }
- /*
- ** OK, we got our message; now we have to make certain the other
- ** guy gets his, so send him one with an ACK required.
- */
- memset (&SendPacket, 0, sizeof(SerialPacketType));
- SendPacket.Command = SERIAL_CONNECT;
- SendPacket.ID = Session.ColorIdx;
- NullModem.Send_Message (&SendPacket, sizeof(SendPacket), 1);
- starttime = TickCount;
- while (TickCount - starttime < 60)
- NullModem.Service();
- retval = true;
- process = false;
- }
- }
- //
- // timeout if we do not get any packets
- //
- if (TickCount - lastmsgtime > PACKET_CANCEL_TIMEOUT) {
- retval = false;
- process = false;
- }
- } /* end of while */
- return( retval );
- }
- /***********************************************************************************************
- * Destroy_Null_Connection -- destroys the given connection *
- * *
- * Call this routine when a connection goes bad, or another player signs off. *
- * *
- * INPUT: *
- * id connection ID to destroy; this should be the HousesType of the player being *
- * "destroyed". *
- * error 0 = user signed off; 1 = connection error *
- * *
- * OUTPUT: *
- * none. *
- * *
- * WARNINGS: *
- * none. *
- * *
- * HISTORY: *
- * 07/31/1995 DRD : Created. *
- *=============================================================================================*/
- void Destroy_Null_Connection(int id, int error)
- {
- int i;
- HouseClass *housep;
- char txt[80];
- if ( Session.NumPlayers == 1 ) {
- return;
- }
- /*
- ** Do nothing if the house isn't human.
- */
- housep = HouseClass::As_Pointer((HousesType)id);
- if (!housep || !housep->IsHuman)
- return;
- /*
- ** Create a message to display to the user
- */
- txt[0] = '\0';
- switch (error) {
- case 1:
- sprintf(txt,Text_String(TXT_CONNECTION_LOST), housep->IniName);
- break;
- case 0:
- sprintf(txt,Text_String(TXT_LEFT_GAME), housep->IniName);
- break;
- case -1:
- NullModem.Delete_Connection();
- break;
- }
- if (strlen(txt)) {
- Session.Messages.Add_Message (NULL, 0, txt,
- (housep->RemapColor == PCOLOR_DIALOG_BLUE) ? PCOLOR_REALLY_BLUE : housep->RemapColor,
- TPF_TEXT, Rule.MessageDelay * TICKS_PER_MINUTE);
- Map.Flag_To_Redraw(false);
- }
- /*
- ** Remove this player from the Players vector
- */
- for (i = 0; i < Session.Players.Count(); i++) {
- if (!stricmp(Session.Players[i]->Name,housep->IniName)) {
- delete Session.Players[i];
- Session.Players.Delete(Session.Players[i]);
- break;
- }
- }
- /*
- ** Turn the player's house over to the computer's AI
- */
- housep->IsHuman = false;
- // housep->Smartness = IQ_MENSA;
- housep->IQ = Rule.MaxIQ;
- strcpy (housep->IniName,Text_String(TXT_COMPUTER));
- Session.NumPlayers--;
- /*
- ** If we're the last player left, tell the user.
- */
- if (Session.NumPlayers == 1) {
- sprintf(txt,"%s",Text_String(TXT_JUST_YOU_AND_ME));
- Session.Messages.Add_Message (NULL, 0, txt,
- (housep->RemapColor == PCOLOR_DIALOG_BLUE) ? PCOLOR_REALLY_BLUE : housep->RemapColor,
- TPF_TEXT, Rule.MessageDelay * TICKS_PER_MINUTE);
- Map.Flag_To_Redraw(false);
- }
- }
- /***************************************************************************
- * Select_Serial_Dialog -- Serial Communications menu dialog *
- * *
- * INPUT: *
- * none. *
- * *
- * OUTPUT: *
- * GAME_MODEM user wants to play a modem game *
- * GAME_NULL_MODEM user wants to play a null-modem game *
- * GAME_NORMAL user hit Cancel *
- * *
- * WARNINGS: *
- * none. *
- * *
- * HISTORY: *
- * 04/29/1995 BRR : Created. *
- *=========================================================================*/
- GameType Select_Serial_Dialog( void )
- {
- int rc;
- // int value, i;
- int com = -1, baud = -1;
- int error = 0;
- /*
- ** Dialog & button dimensions
- */
- int d_dialog_w = 160 * RESFACTOR; // dialog width
- int d_dialog_h = 94 * RESFACTOR; // dialog height
- int d_dialog_x = ((320 * RESFACTOR - d_dialog_w) / 2); // dialog x-coord
- int d_dialog_y = 80*RESFACTOR;
- // int d_dialog_y = ((136 * RESFACTOR - d_dialog_h) / 2); // dialog y-coord
- int d_dialog_cx = d_dialog_x + (d_dialog_w / 2); // center x-coord
- int d_txt6_h = 7 * RESFACTOR; // ht of 6-pt text
- int d_margin = 7 * RESFACTOR; // margin width/height
- int d_dial_w = 90 * RESFACTOR;
- int d_dial_h = 9 * RESFACTOR;
- int d_dial_x = d_dialog_cx - d_dial_w / 2;
- int d_dial_y = d_dialog_y + d_margin + d_txt6_h + d_margin;
- int d_answer_w = 90 * RESFACTOR;
- int d_answer_h = 9 * RESFACTOR;
- int d_answer_x = d_dialog_cx - d_answer_w / 2;
- int d_answer_y = d_dial_y + d_dial_h + 2;
- int d_nullmodem_w = 90 * RESFACTOR;
- int d_nullmodem_h = 9 * RESFACTOR;
- int d_nullmodem_x = d_dialog_cx - d_nullmodem_w / 2;
- int d_nullmodem_y = d_answer_y + d_answer_h + 2;
- int d_settings_w = 90 * RESFACTOR;
- int d_settings_h = 9 * RESFACTOR;
- int d_settings_x = d_dialog_cx - d_settings_w / 2;
- int d_settings_y = d_nullmodem_y + d_nullmodem_h + 2;
- int d_cancel_w = 50 * RESFACTOR;
- int d_cancel_h = 9 * RESFACTOR;
- int d_cancel_x = d_dialog_cx - d_cancel_w / 2;
- int d_cancel_y = d_settings_y + d_settings_h + d_margin;
- /*
- ** Button Enumerations
- */
- enum {
- BUTTON_DIAL = 100,
- BUTTON_ANSWER,
- BUTTON_NULLMODEM,
- BUTTON_SETTINGS,
- BUTTON_CANCEL,
- NUM_OF_BUTTONS = 5,
- };
- /*
- ** Redraw values: in order from "top" to "bottom" layer of the dialog
- */
- typedef enum {
- REDRAW_NONE = 0,
- REDRAW_BUTTONS,
- REDRAW_BACKGROUND,
- REDRAW_ALL = REDRAW_BACKGROUND
- } RedrawType;
- /*
- ** Dialog variables
- */
- RedrawType display = REDRAW_ALL; // redraw level
- bool process = true; // process while true
- KeyNumType input;
- char namebuf[MPLAYER_NAME_MAX] = {0}; // buffer for player's name
- int tabs[] = {77*RESFACTOR}; // tabs for player list box
- GameType retval; // return value
- int selection;
- bool pressed;
- int curbutton;
- TextButtonClass *buttons[NUM_OF_BUTTONS];
- SerialSettingsType *settings;
- bool selectsettings = false;
- RemapControlType * scheme = GadgetClass::Get_Color_Scheme();
- /*
- ** Buttons
- */
- GadgetClass *commands; // button list
- TextButtonClass dialbtn(BUTTON_DIAL, TXT_DIAL_MODEM, TPF_BUTTON, d_dial_x, d_dial_y, d_dial_w, d_dial_h);
- TextButtonClass answerbtn(BUTTON_ANSWER, TXT_ANSWER_MODEM, TPF_BUTTON, d_answer_x, d_answer_y, d_answer_w, d_answer_h);
- TextButtonClass nullmodembtn(BUTTON_NULLMODEM, TXT_NULL_MODEM, TPF_BUTTON, d_nullmodem_x, d_nullmodem_y, d_nullmodem_w, d_nullmodem_h);
- TextButtonClass settingsbtn(BUTTON_SETTINGS, TXT_SETTINGS, TPF_BUTTON, d_settings_x, d_settings_y, d_settings_w, d_settings_h);
- TextButtonClass cancelbtn(BUTTON_CANCEL, TXT_CANCEL, TPF_BUTTON, d_cancel_x, d_cancel_y, d_cancel_w, d_cancel_h);
- /*
- ** Initialize
- */
- Set_Logic_Page(SeenBuff);
- if (Session.SerialDefaults.Port == 0 ||
- Session.SerialDefaults.IRQ == -1 ||
- Session.SerialDefaults.Baud == -1) {
- selectsettings = true;
- } else if ( NullModem.Detect_Port( &Session.SerialDefaults ) != PORT_VALID ) {
- selectsettings = true;
- }
- /*
- ** Create the list
- */
- commands = &dialbtn;
- answerbtn.Add_Tail(*commands);
- nullmodembtn.Add_Tail(*commands);
- settingsbtn.Add_Tail(*commands);
- cancelbtn.Add_Tail(*commands);
- /*
- ** Fill array of button ptrs
- */
- curbutton = 0;
- buttons[0] = &dialbtn;
- buttons[1] = &answerbtn;
- buttons[2] = &nullmodembtn;
- buttons[3] = &settingsbtn;
- buttons[4] = &cancelbtn;
- buttons[curbutton]->Turn_On();
- Keyboard->Clear();
- Fancy_Text_Print(TXT_NONE, 0, 0, scheme, TBLACK, TPF_CENTER | TPF_TEXT);
- /*
- ** Main Processing Loop
- */
- display = REDRAW_ALL;
- process = true;
- pressed = false;
- while (process) {
- /*
- ** Invoke game callback
- */
- Call_Back();
- /*
- ** Refresh display if needed
- */
- #ifdef WIN32
- /*
- ** If we have just received input focus again after running in the background then
- ** we need to redraw.
- */
- if (AllSurfaces.SurfacesRestored) {
- AllSurfaces.SurfacesRestored=FALSE;
- display = REDRAW_ALL;
- }
- #endif
- if (display) {
- Hide_Mouse();
- if (display >= REDRAW_BACKGROUND) {
- /*
- ** Refresh the backdrop
- */
- Load_Title_Page(true);
- /*
- ** Draw the background
- */
- Dialog_Box(d_dialog_x, d_dialog_y, d_dialog_w, d_dialog_h);
- /*
- ** Draw the labels
- */
- Draw_Caption (TXT_SELECT_SERIAL_GAME, d_dialog_x, d_dialog_y, d_dialog_w);
- }
- commands->Draw_All();
- Show_Mouse();
- display = REDRAW_NONE;
- }
- /*
- ** Get user input
- */
- input = commands->Input();
- /*
- ** Process input
- */
- switch (input) {
- case (BUTTON_DIAL | KN_BUTTON):
- selection = BUTTON_DIAL;
- pressed = true;
- break;
- case (BUTTON_ANSWER | KN_BUTTON):
- selection = BUTTON_ANSWER;
- pressed = true;
- break;
- case (BUTTON_NULLMODEM | KN_BUTTON):
- selection = BUTTON_NULLMODEM;
- pressed = true;
- break;
- case (BUTTON_SETTINGS | KN_BUTTON):
- selection = BUTTON_SETTINGS;
- pressed = true;
- break;
- case (KN_ESC):
- case (BUTTON_CANCEL | KN_BUTTON):
- selection = BUTTON_CANCEL;
- pressed = true;
- break;
- case (KN_UP):
- buttons[curbutton]->Turn_Off();
- buttons[curbutton]->Flag_To_Redraw();
- curbutton--;
- if (curbutton < 0)
- curbutton = (NUM_OF_BUTTONS - 1);
- buttons[curbutton]->Turn_On();
- buttons[curbutton]->Flag_To_Redraw();
- break;
- case (KN_DOWN):
- buttons[curbutton]->Turn_Off();
- buttons[curbutton]->Flag_To_Redraw();
- curbutton++;
- if (curbutton > (NUM_OF_BUTTONS - 1) )
- curbutton = 0;
- buttons[curbutton]->Turn_On();
- buttons[curbutton]->Flag_To_Redraw();
- break;
- case (KN_RETURN):
- selection = curbutton + BUTTON_DIAL;
- pressed = true;
- break;
- default:
- break;
- }
- if (pressed) {
- //
- // to make sure the selection is correct in case they used the mouse
- //
- buttons[curbutton]->Turn_Off();
- buttons[curbutton]->Flag_To_Redraw();
- curbutton = selection - BUTTON_DIAL;
- buttons[curbutton]->Turn_On();
- buttons[curbutton]->IsPressed = true;
- buttons[curbutton]->Draw_Me(true);
- switch (selection) {
- case (BUTTON_DIAL):
- if (selectsettings) {
- WWMessageBox().Process(TXT_SELECT_SETTINGS);
- /*
- ** Remote-connect
- */
- } else if ( Phone_Dialog() ) {
- if (Session.PhoneBook[Session.CurPhoneIdx]->Settings.Port == 0) {
- settings = &Session.SerialDefaults;
- } else {
- settings = &(Session.PhoneBook[Session.CurPhoneIdx]->Settings);
- }
- #ifdef WIN32
- if (SerialPort) {
- delete SerialPort;
- }
- SerialPort = new WinModemClass;
- #endif //WIN32
- if ( Init_Null_Modem( settings ) ) {
- if (settings->CallWaitStringIndex == CALL_WAIT_CUSTOM) {
- strcpy( DialString, settings->CallWaitString );
- } else {
- strcpy( DialString,
- Session.CallWaitStrings[ settings->CallWaitStringIndex ] );
- }
- strcat( DialString, Session.PhoneBook[ Session.CurPhoneIdx ]->Number );
- if ( Dial_Modem( settings, false ) ) {
- Session.ModemType = MODEM_DIALER;
- if ( Com_Scenario_Dialog() ) {
- retval = GAME_MODEM;
- process = false;
- }
- }
- if (process) { // restore to default
- NullModem.Change_IRQ_Priority( 0 );
- }
- } else {
- WWMessageBox().Process(TXT_SELECT_SETTINGS);
- }
- }
- if (process) {
- buttons[curbutton]->IsPressed = false;
- buttons[curbutton]->Flag_To_Redraw();
- }
- display = REDRAW_ALL;
- break;
- case (BUTTON_ANSWER):
- if (selectsettings) {
- WWMessageBox().Process(TXT_SELECT_SETTINGS);
- } else {
- /*
- ** Remote-connect
- */
- settings = &Session.SerialDefaults;
- #ifdef WIN32
- if (SerialPort) {
- delete SerialPort;
- }
- SerialPort = new WinModemClass;
- #endif //WIN32
- if ( Init_Null_Modem( settings ) ) {
- if ( Answer_Modem( settings, false ) ) {
- Session.ModemType = MODEM_ANSWERER;
- if ( Com_Show_Scenario_Dialog() ) {
- retval = GAME_MODEM;
- process = false;
- }
- }
- if (process) { // restore to default
- NullModem.Change_IRQ_Priority( 0 );
- }
- } else {
- WWMessageBox().Process(TXT_SELECT_SETTINGS);
- }
- }
- if (process) {
- buttons[curbutton]->IsPressed = false;
- buttons[curbutton]->Flag_To_Redraw();
- }
- display = REDRAW_ALL;
- break;
- case (BUTTON_NULLMODEM):
- if (selectsettings) {
- WWMessageBox().Process(TXT_SELECT_SETTINGS);
- /*
- ** Otherwise, remote-connect; save values if we're recording
- */
- } else if ( Init_Null_Modem( &Session.SerialDefaults ) ) {
- rc = Test_Null_Modem();
- switch (rc) {
- case (1):
- Session.ModemType = MODEM_NULL_HOST;
- if ( Com_Scenario_Dialog() ) {
- retval = GAME_NULL_MODEM;
- process = false;
- }
- break;
- case (2):
- Session.ModemType = MODEM_NULL_JOIN;
- if ( Com_Show_Scenario_Dialog() ) {
- retval = GAME_NULL_MODEM;
- process = false;
- }
- break;
- case (3):
- WWMessageBox().Process( TXT_MODEM_OR_LOOPBACK );
- break;
- }
- if (process) { // restore to default
- NullModem.Change_IRQ_Priority( 0 );
- }
- } else {
- WWMessageBox().Process(TXT_SELECT_SETTINGS);
- }
- if (process) {
- buttons[curbutton]->IsPressed = false;
- buttons[curbutton]->Flag_To_Redraw();
- }
- display = REDRAW_ALL;
- break;
- case (BUTTON_SETTINGS):
- if ( Com_Settings_Dialog( &Session.SerialDefaults ) ) {
- Session.Write_MultiPlayer_Settings ();
- selectsettings = true;
- if (Session.SerialDefaults.Port != 0 &&
- Session.SerialDefaults.IRQ != -1 &&
- Session.SerialDefaults.Baud != -1) {
- if ( NullModem.Detect_Port( &Session.SerialDefaults ) == PORT_VALID) {
- selectsettings = false;
- }
- }
- }
- buttons[curbutton]->IsPressed = false;
- buttons[curbutton]->Flag_To_Redraw();
- display = REDRAW_ALL;
- break;
- case (BUTTON_CANCEL):
- retval = GAME_NORMAL;
- process = false;
- break;
- }
- pressed = false;
- }
- } /* end of while */
- return( retval );
- }
- #ifdef WIN32
- /***********************************************************************************************
- * Advanced_Modem_Settings -- Allows to user to set additional modem settings *
- * *
- * *
- * *
- * INPUT: current settings *
- * *
- * OUTPUT: modified settings *
- * *
- * WARNINGS: None *
- * *
- * HISTORY: *
- * 12/16/96 2:29PM ST : Created *
- *=============================================================================================*/
- Advanced_Modem_Settings (SerialSettingsType *settings)
- {
- /*........................................................................
- Dialog & button dimensions
- ........................................................................*/
- #if (FRENCH | GERMAN)
- int d_dialog_w = 440; // dialog width
- #else
- int d_dialog_w = 340; // dialog width
- #endif
- int d_dialog_h = 200; // dialog height
- int d_dialog_x = 320 - d_dialog_w/2; // dialog x-coord
- int d_dialog_y = 200 - d_dialog_h/ 4; // dialog y-coord
- int d_compression_w = 50;
- int d_compression_h = 18;
- int d_compression_x = d_dialog_x + d_dialog_w/2 +40;
- int d_compression_y = d_dialog_y + 40;
- int d_errorcorrection_w = 50;
- int d_errorcorrection_h = 18;
- int d_errorcorrection_x = d_dialog_x + d_dialog_w/2 +40;
- int d_errorcorrection_y = d_dialog_y + 65;
- int d_hardwareflowcontrol_w = 50;
- int d_hardwareflowcontrol_h = 18;
- int d_hardwareflowcontrol_x = d_dialog_x + d_dialog_w/2 +40;
- int d_hardwareflowcontrol_y = d_dialog_y + 90;
- int d_default_w = 100;
- int d_default_h = 18;
- int d_default_x = d_dialog_x + d_dialog_w / 2 - d_default_w / 2;
- int d_default_y = d_dialog_y + d_dialog_h - 70;
- int d_ok_w = 100;
- int d_ok_h = 18;
- int d_ok_x = d_dialog_x + d_dialog_w/2 - d_ok_w / 2;
- int d_ok_y = d_dialog_y + d_dialog_h - 40;
- enum {
- BUTTON_COMPRESSION = 100,
- BUTTON_ERROR_CORRECTION,
- BUTTON_HARDWARE_FLOW_CONTROL,
- BUTTON_DEFAULT,
- BUTTON_OK,
- };
- typedef enum {
- REDRAW_NONE = 0,
- REDRAW_BUTTONS,
- REDRAW_BACKGROUND,
- REDRAW_ALL = REDRAW_BACKGROUND,
- } RedrawType;
- /*
- ** Yes/No strings
- */
- char compress_text [16];
- char correction_text [16];
- char flowcontrol_text[16];
- RemapControlType * scheme = GadgetClass::Get_Color_Scheme();
- /*
- ** Initialise the button text
- */
- strcpy (compress_text, settings->Compression ? Text_String (TXT_ON) : Text_String (TXT_OFF) );
- strcpy (correction_text, settings->ErrorCorrection ?
- Text_String (TXT_ON) : Text_String (TXT_OFF) );
- strcpy (flowcontrol_text, settings->HardwareFlowControl ?
- Text_String (TXT_ON) : Text_String (TXT_OFF) );
- /*
- ** Create the buttons
- */
- TextButtonClass compressionbutton(BUTTON_COMPRESSION, compress_text,
- TPF_CENTER | TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW,
- d_compression_x, d_compression_y, d_compression_w, d_compression_h);
- TextButtonClass errorcorrectionbutton(BUTTON_ERROR_CORRECTION, correction_text,
- TPF_CENTER | TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW,
- d_errorcorrection_x, d_errorcorrection_y, d_errorcorrection_w, d_errorcorrection_h);
- TextButtonClass hardwareflowcontrolbutton(BUTTON_HARDWARE_FLOW_CONTROL, flowcontrol_text,
- TPF_CENTER | TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW,
- d_hardwareflowcontrol_x, d_hardwareflowcontrol_y, d_hardwareflowcontrol_w, d_hardwareflowcontrol_h);
- TextButtonClass defaultbutton(BUTTON_DEFAULT, TXT_DEFAULT,
- TPF_CENTER | TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW,
- d_default_x, d_default_y, d_default_w, d_default_h);
- TextButtonClass okbutton(BUTTON_OK, TXT_OK,
- TPF_CENTER | TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW,
- d_ok_x, d_ok_y, d_ok_w, d_ok_h);
- /*
- ** Misc. variables.
- */
- RedrawType display = REDRAW_ALL; // redraw level
- BOOL process = true; // process while true
- KeyNumType input;
- GadgetClass *commands; // button list
- commands = &okbutton;
- defaultbutton.Add_Tail(*commands);
- compressionbutton.Add_Tail(*commands);
- errorcorrectionbutton.Add_Tail(*commands);
- hardwareflowcontrolbutton.Add_Tail(*commands);
- /*
- ** Main process loop
- */
- while (process) {
- /*
- ** If we have just received input focus again after running in the background then
- ** we need to redraw.
- */
- if (AllSurfaces.SurfacesRestored){
- AllSurfaces.SurfacesRestored=FALSE;
- display=REDRAW_ALL;
- }
- /*
- ........................ Invoke game callback .........................
- */
- Call_Back();
- /*
- ...................... Refresh display if needed ......................
- */
- if (display) {
- Hide_Mouse();
- /*
- .................. Redraw backgound & dialog box ...................
- */
- if (display >= REDRAW_BACKGROUND) {
- Load_Title_Page(true);
- CCPalette.Set();
- Dialog_Box(d_dialog_x, d_dialog_y, d_dialog_w, d_dialog_h);
- // init font variables
- Fancy_Text_Print(TXT_NONE, 0, 0, scheme, TBLACK, TPF_TEXT);
- /*...............................................................
- Dialog & Field labels
- ...............................................................*/
- Draw_Caption (TXT_MODEM_INITIALISATION, d_dialog_x, d_dialog_y, d_dialog_w);
- Fancy_Text_Print( TXT_DATA_COMPRESSION,
- d_compression_x - 26, d_compression_y + 2,
- scheme, TBLACK, TPF_TEXT | TPF_RIGHT);
- Fancy_Text_Print( TXT_ERROR_CORRECTION,
- d_errorcorrection_x - 26, d_errorcorrection_y +2,
- scheme, TBLACK, TPF_TEXT | TPF_RIGHT);
- Fancy_Text_Print( TXT_HARDWARE_FLOW_CONTROL,
- d_hardwareflowcontrol_x -26, d_hardwareflowcontrol_y +2,
- scheme, TBLACK, TPF_TEXT | TPF_RIGHT);
- }
- /*
- .......................... Redraw buttons ..........................
- */
- if (display >= REDRAW_BUTTONS) {
- compressionbutton.Flag_To_Redraw();
- errorcorrectionbutton.Flag_To_Redraw();
- hardwareflowcontrolbutton.Flag_To_Redraw();
- }
- Show_Mouse();
- display = REDRAW_NONE;
- }
- /*
- ........................... Get user input ............................
- */
- input = commands->Input();
- /*
- ---------------------------- Process input ----------------------------
- */
- switch (input) {
- case (BUTTON_COMPRESSION | KN_BUTTON):
- settings->Compression = settings->Compression ^ 1;
- strcpy (compress_text, settings->Compression ?
- Text_String (TXT_ON) : Text_String (TXT_OFF) );
- if (display < REDRAW_BUTTONS) display = REDRAW_BUTTONS;
- break;
- case (BUTTON_ERROR_CORRECTION | KN_BUTTON):
- settings->ErrorCorrection = settings->ErrorCorrection ^ 1;
- strcpy (correction_text, settings->ErrorCorrection ?
- Text_String (TXT_ON) : Text_String (TXT_OFF) );
- if (display < REDRAW_BUTTONS) display = REDRAW_BUTTONS;
- break;
- case (BUTTON_HARDWARE_FLOW_CONTROL | KN_BUTTON):
- settings->HardwareFlowControl = settings->HardwareFlowControl ^ 1;
- strcpy (flowcontrol_text, settings->HardwareFlowControl ?
- Text_String (TXT_ON) : Text_String (TXT_OFF) );
- if (display < REDRAW_BUTTONS) display = REDRAW_BUTTONS;
- break;
- case (BUTTON_DEFAULT | KN_BUTTON):
- settings->Compression = false;
- settings->ErrorCorrection = false;
- settings->HardwareFlowControl = true;
- strcpy (compress_text, settings->Compression ?
- Text_String (TXT_ON) : Text_String (TXT_OFF) );
- strcpy (correction_text, settings->ErrorCorrection ?
- Text_String (TXT_ON) : Text_String (TXT_OFF) );
- strcpy (flowcontrol_text, settings->HardwareFlowControl ?
- Text_String (TXT_ON) : Text_String (TXT_OFF) );
- if (display < REDRAW_BUTTONS) display = REDRAW_BUTTONS;
- break;
- case (BUTTON_OK | KN_BUTTON):
- process = false;
- break;
- }
- }
- }
- #endif //WIN32
- /***************************************************************************
- * Com_Settings_Dialog -- Lets user select serial port settings *
- * *
- * ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ *
- * ³ Settings ³ *
- * ³ ³ *
- * ³ Port:____ IRQ:__ Baud:______ ³ *
- * ³ ÚÄÄÄÄÄÄÄÄÄÄÄÄ¿ ÚÄÄÄÄÄÄÄÄÄÄÄÄ¿ ÚÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ *
- * ³ ³ ³ ³ ³ ³ ³ ³ *
- * ³ ³ ³ ³ ³ ³ ³ ³ *
- * ³ ³ ³ ³ ³ ³ ³ ³ *
- * ³ ³ ³ ³ ³ ³ ³ ³ *
- * ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÙ ÀÄÄÄÄÄÄÄÄÄÄÄÄÙ ÀÄÄÄÄÄÄÄÄÄÄÄÄÙ ³ *
- * ³ ³ *
- * ³ Initialization: [Add] [Delete] ³ *
- * ³ _____________________________ ³ *
- * ³ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ *
- * ³ ³ ³ ³ *
- * ³ ³ ³ ³ *
- * ³ ³ ³ ³ *
- * ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ³ *
- * ³ ³ *
- * ³ Call Waiting: ³ *
- * ³ _______________ ³ *
- * ³ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ [Tone Dialing] ³ *
- * ³ ³ ³ ³ *
- * ³ ³ ³ [Pulse Dialing] ³ *
- * ³ ³ ³ ³ *
- * ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ³ *
- * ³ ³ *
- * ³ [OK] [Cancel] ³ *
- * ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ *
- * *
- * INPUT: *
- * settings ptr to SerialSettingsType structure *
- * *
- * OUTPUT: *
- * true = OK, false = Cancel *
- * *
- * WARNINGS: *
- * none. *
- * *
- * HISTORY: *
- * 04/29/1995 BRR : Created. *
- *=========================================================================*/
- static int Com_Settings_Dialog( SerialSettingsType *settings )
- {
- /*
- ** Dialog & button dimensions
- */
- int d_dialog_w = 320 * RESFACTOR; // dialog width
- int d_dialog_h = 200 * RESFACTOR; // dialog height
- int d_dialog_x = ((320 * RESFACTOR - d_dialog_w) / 2); // dialog x-coord
- int d_dialog_y = ((200 * RESFACTOR - d_dialog_h) / 2); // dialog y-coord
- int d_dialog_cx = d_dialog_x + (d_dialog_w / 2); // center x-coord
- int d_txt6_h = 7 * RESFACTOR; // ht of 6-pt text
- int d_margin = 5 * RESFACTOR; // margin width/height
- int d_portlist_w = 80 * RESFACTOR + 80*(RESFACTOR-1); //Port list wider in hires
- int d_portlist_h = 33 * RESFACTOR;
- int d_portlist_x = d_dialog_x + (d_dialog_w / 6) - (d_portlist_w / 2);
- #ifdef WIN32
- d_portlist_x = 0x45;
- #endif
- int d_portlist_y = d_dialog_y + ((d_margin + d_txt6_h) * 2) + d_margin + 10 * RESFACTOR;
- #ifdef WIN32
- int d_port_w = d_portlist_w;
- int d_port_x = 0x45;
- #else
- int d_port_w = (5 * 6 * RESFACTOR) + 3 * RESFACTOR;
- // int d_port_x = d_portlist_x + 29 * RESFACTOR;
- #ifdef FRENCH //VG2
- int d_port_x = (d_portlist_x + 29 * RESFACTOR) + 5;
- #else
- int d_port_x = d_portlist_x + 29 * RESFACTOR;
- #endif
- #endif //WIN32
- int d_port_h = 9 * RESFACTOR;
- int d_port_y = d_portlist_y - d_margin - d_txt6_h;
- int d_irqlist_w = 80 * RESFACTOR;
- int d_irqlist_h = 33 * RESFACTOR;
- int d_irqlist_x = d_dialog_x + (d_dialog_w / 2) - (d_irqlist_w / 2);
- int d_irqlist_y = d_portlist_y;
- int d_irq_w = ((IRQBUF_MAX - 1) * 6 * RESFACTOR) + 3 * RESFACTOR;
- int d_irq_h = 9 * RESFACTOR;
- int d_irq_x = d_irqlist_x + 25 * RESFACTOR;
- int d_irq_y = d_irqlist_y - d_margin - d_txt6_h;
- int d_baudlist_w = 80 * RESFACTOR;
- int d_baudlist_h = 33 * RESFACTOR;
- int d_baudlist_x = d_dialog_x + ((d_dialog_w * 5) / 6) - (d_baudlist_w / 2);
- #ifdef WIN32
- d_baudlist_x -= 32;
- #endif
- int d_baudlist_y = d_irqlist_y;
- int d_baud_w = ((BAUDBUF_MAX - 1) * 6 * RESFACTOR) + 3 * RESFACTOR;
- int d_baud_h = 9 * RESFACTOR;
- int d_baud_x = d_baudlist_x + 29 * RESFACTOR;
- int d_baud_y = d_baudlist_y - d_margin - d_txt6_h;
- int d_initstrlist_w = ((INITSTRBUF_MAX - 1) * 6 * RESFACTOR) + 8 * RESFACTOR + 3 * RESFACTOR;
- int d_initstrlist_h = 21 * RESFACTOR;
- int d_initstrlist_x = d_dialog_cx - (d_initstrlist_w / 2);
- int d_initstrlist_y = d_portlist_y + d_portlist_h + ((d_margin + d_txt6_h) * 2) + d_margin + 4;
- int d_initstr_w = ((INITSTRBUF_MAX - 1) * 6 * RESFACTOR) + 3 * RESFACTOR;
- int d_initstr_h = 9 * RESFACTOR;
- int d_initstr_x = d_initstrlist_x;
- int d_initstr_y = d_initstrlist_y - d_margin - d_txt6_h;
- int d_add_w = 45 * RESFACTOR;
- #ifdef FRENCH
- int d_add_x = d_dialog_cx - (d_add_w / 2);
- #else
- int d_add_x = (d_dialog_cx - (d_add_w / 2)) + 30;
- #endif
- int d_add_h = 9 * RESFACTOR;
- int d_add_y = d_initstr_y - d_add_h - 3 * RESFACTOR;
- int d_delete_w = 45 * RESFACTOR;
- #ifdef FRENCH
- int d_delete_x = (d_dialog_x + ((d_dialog_w * 3) / 4) - (d_delete_w / 2)) + 10;
- #else
- int d_delete_x = d_dialog_x + ((d_dialog_w * 3) / 4) - (d_delete_w / 2);
- #endif
- int d_delete_h = 9 * RESFACTOR;
- int d_delete_y = d_initstr_y - d_add_h - 3 * RESFACTOR;
- int d_cwaitstrlist_w = (((CWAITSTRBUF_MAX - 1) + 9) * 6) * RESFACTOR + 3 * RESFACTOR;
- int d_cwaitstrlist_h = 27 * RESFACTOR;
- int d_cwaitstrlist_x = d_initstrlist_x;
- int d_cwaitstrlist_y = d_initstrlist_y + d_initstrlist_h + ((d_margin + d_txt6_h) * 2) + 2;
- int d_cwaitstr_w = ((CWAITSTRBUF_MAX - 1) * 6) * RESFACTOR + 3 * RESFACTOR;
- int d_cwaitstr_h = 9 * RESFACTOR;
- int d_cwaitstr_x = d_cwaitstrlist_x;
- int d_cwaitstr_y = d_cwaitstrlist_y - d_margin - d_txt6_h;
- int d_tone_w = 80 * RESFACTOR;
- int d_tone_h = 9 * RESFACTOR;
- int d_tone_x = d_dialog_x + ((d_dialog_w * 3) / 4) - (d_tone_w / 2);
- int d_tone_y = d_cwaitstrlist_y;
- int d_pulse_w = 80 * RESFACTOR;
- int d_pulse_h = 9 * RESFACTOR;
- int d_pulse_x = d_dialog_x + ((d_dialog_w * 3) / 4) - (d_pulse_w / 2);
- int d_pulse_y = d_tone_y + d_tone_h + d_margin;
- #ifdef FRENCH
- int d_save_w = 80 * RESFACTOR;
- #else
- int d_save_w = 40 * RESFACTOR;
- #endif
- int d_save_h = 9 * RESFACTOR;
- int d_save_x = d_dialog_x + (d_dialog_w / 5) - (d_save_w / 2);
- int d_save_y = d_dialog_y + d_dialog_h - d_save_h - d_margin - 4*RESFACTOR;
- int d_cancel_w = 50 * RESFACTOR;
- int d_cancel_h = 9 * RESFACTOR;
- int d_cancel_x = d_dialog_x + ((d_dialog_w * 4) / 5) - (d_cancel_w / 2);
- int d_cancel_y = d_dialog_y + d_dialog_h - d_cancel_h - d_margin - 4*RESFACTOR;
- #if (GERMAN | FRENCH)
- int d_advanced_w = 50*RESFACTOR;
- #else
- int d_advanced_w = 40*RESFACTOR;
- #endif
- int d_advanced_h = 9*RESFACTOR;
- int d_advanced_x = d_dialog_x + ((d_dialog_w) / 2) - (d_advanced_w / 2);
- int d_advanced_y = d_dialog_y + d_dialog_h - d_advanced_h - d_margin - 4 *RESFACTOR;
- /*
- ** Button Enumerations
- */
- enum {
- BUTTON_PORT = 100,
- BUTTON_PORTLIST,
- BUTTON_IRQ,
- BUTTON_IRQLIST,
- BUTTON_BAUD,
- BUTTON_BAUDLIST,
- BUTTON_INITSTR,
- BUTTON_INITSTRLIST,
- BUTTON_ADD,
- BUTTON_DELETE,
- BUTTON_CWAITSTR,
- BUTTON_CWAITSTRLIST,
- BUTTON_TONE,
- BUTTON_PULSE,
- BUTTON_SAVE,
- BUTTON_ADVANCED,
- BUTTON_CANCEL,
- };
- /*
- ** Redraw values: in order from "top" to "bottom" layer of the dialog
- */
- typedef enum {
- REDRAW_NONE = 0,
- REDRAW_BUTTONS,
- REDRAW_BACKGROUND,
- REDRAW_ALL = REDRAW_BACKGROUND
- } RedrawType;
- static char *portname[4] = {
- "COM1 - 3F8",
- "COM2 - 2F8",
- "COM3 - 3E8",
- "COM4 - 2E8",
- };
- static char custom_port[10 + MODEM_NAME_MAX] = {"CUSTOM - ????"};
- #ifndef WIN32 // No IRQ dialog in Win version
- static char *irqname[5] = {
- "2 / 9",
- "3 - [COM2 & 4]",
- "4 - [COM1 & 3]",
- "5",
- "CUSTOM - ??"
- };
- static int _irqidx[4] = {
- 2,
- 1,
- 2,
- 1
- };
- #endif //WIN32
- #ifdef WIN32
- static char *baudname[5] = {
- "14400",
- "19200",
- "28800",
- "38400",
- "57600",
- };
- static char modemnames[10][MODEM_NAME_MAX];
- #else //WIN32
- static char *baudname[5] = {
- "9600",
- "14400",
- "19200",
- "28800",
- "38400"
- };
- #endif //WIN32
- /*
- ** Dialog variables
- */
- RedrawType display = REDRAW_ALL; // redraw level
- bool process = true; // process while true
- KeyNumType input;
- char * item; // general-purpose string
- char * temp; // general-purpose string
- RemapControlType * scheme = GadgetClass::Get_Color_Scheme();
- char portbuf[ PORTBUF_MAX ] = {0}; // buffer for port
- char irqbuf[ IRQBUF_MAX ] = {0}; // buffer for irq
- char baudbuf[ BAUDBUF_MAX ] = {0}; // buffer for baud
- char initstrbuf[ INITSTRBUF_MAX ] = {0}; // buffer for init string
- char cwaitstrbuf[ CWAITSTRBUF_MAX ] = {0}; // buffer for call waiting string
- int port_index = 1; // index of currently-selected port (default = com2)
- int port_custom_index = 4; //index of custom entry in port list
- int irq_index = 1; // index of currently-selected irq (default = 3)
- int baud_index = 1; // index of currently-selected baud (default = 19200)
- int initstr_index = 0; // index of currently-selected modem init (default = "ATZ")
- int cwaitstr_index = CALL_WAIT_CUSTOM; // index of currently-selected call waiting (default = "")
- int rc = 0; // -1 = user cancelled, 1 = New
- int i; // loop counter
- int pos;
- int len;
- bool firsttime = true;
- SerialSettingsType tempsettings;
- DetectPortType dpstatus;
- /*
- ** Buttons
- */
- GadgetClass *commands; // button list
- EditClass port_edt (BUTTON_PORT, portbuf, PORTBUF_MAX,
- TPF_TEXT, d_port_x, d_port_y, d_port_w, d_port_h, EditClass::ALPHANUMERIC);
- ListClass portlist(BUTTON_PORTLIST, d_portlist_x, d_portlist_y, d_portlist_w, d_portlist_h,
- TPF_TEXT, MFCD::Retrieve("BTN-UP.SHP"), MFCD::Retrieve("BTN-DN.SHP"));
- #ifndef WIN32
- EditClass irq_edt (BUTTON_IRQ, irqbuf, IRQBUF_MAX, TPF_TEXT, d_irq_x, d_irq_y, d_irq_w, d_irq_h, EditClass::NUMERIC);
- 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"));
- #endif //WIN32
- EditClass baud_edt (BUTTON_BAUD, baudbuf, BAUDBUF_MAX, TPF_TEXT, d_baud_x, d_baud_y, d_baud_w, d_baud_h, EditClass::NUMERIC);
- 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"));
- EditClass initstr_edt (BUTTON_INITSTR, initstrbuf, INITSTRBUF_MAX, TPF_TEXT, d_initstr_x, d_initstr_y, d_initstr_w, d_initstr_h, EditClass::ALPHANUMERIC);
- 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"));
- TextButtonClass addbtn(BUTTON_ADD, TXT_ADD, TPF_BUTTON, d_add_x, d_add_y, d_add_w, d_add_h);
- TextButtonClass deletebtn(BUTTON_DELETE, TXT_DELETE_BUTTON, TPF_BUTTON, d_delete_x, d_delete_y, d_delete_w, d_delete_h);
- EditClass cwaitstr_edt (BUTTON_CWAITSTR, cwaitstrbuf, CWAITSTRBUF_MAX, TPF_TEXT, d_cwaitstr_x, d_cwaitstr_y, d_cwaitstr_w, d_cwaitstr_h, EditClass::ALPHANUMERIC);
- 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"));
- TextButtonClass tonebtn(BUTTON_TONE, TXT_TONE_BUTTON, TPF_BUTTON, d_tone_x, d_tone_y, d_tone_w, d_tone_h);
- TextButtonClass pulsebtn(BUTTON_PULSE, TXT_PULSE_BUTTON, TPF_BUTTON, d_pulse_x, d_pulse_y, d_pulse_w, d_pulse_h);
- TextButtonClass savebtn(BUTTON_SAVE, TXT_SAVE_BUTTON, TPF_BUTTON, d_save_x, d_save_y, d_save_w, d_save_h);
- TextButtonClass cancelbtn(BUTTON_CANCEL, TXT_CANCEL, TPF_BUTTON, d_cancel_x, d_cancel_y, d_cancel_w, d_cancel_h);
- #ifdef WIN32
- TextButtonClass advancedbutton(BUTTON_ADVANCED, TXT_ADVANCED, TPF_BUTTON, d_advanced_x, d_advanced_y, d_advanced_w, d_advanced_h);
- #endif //WIN32
- /*
- ** Various Inits
- */
- memcpy( &tempsettings, settings, sizeof(SerialSettingsType) );
- if (tempsettings.Port == 0) {
- tempsettings.Port = 0x2f8;
- }
- if (tempsettings.IRQ == -1) {
- tempsettings.IRQ = 3;
- }
- if (tempsettings.Baud == -1) {
- #ifdef WIN32
- tempsettings.Baud = 19200;
- #else //WIN32
- tempsettings.Baud = 9600;
- #endif //WIN32
- }
- /*
- ** Set the current indices
- */
- #ifndef WIN32
- switch ( tempsettings.IRQ ) {
- case ( 2 ):
- irq_index = 0;
- strcpy (irqbuf, "2");
- break;
- case ( 3 ):
- irq_index = 1;
- strcpy (irqbuf, "3");
- break;
- case ( 4 ):
- irq_index = 2;
- strcpy (irqbuf, "4");
- break;
- case ( 5 ):
- irq_index = 3;
- strcpy (irqbuf, "5");
- break;
- default:
- irq_index = 4;
- sprintf (irqbuf, "%d", tempsettings.IRQ);
- temp = strchr( irqname[4], '-' );
- if ( temp ) {
- pos = (int)(temp - irqname[4]) + 2;
- len = strlen( irqbuf );
- strncpy( irqname[4] + pos, irqbuf, len );
- *(irqname[4] + pos + len) = 0;
- }
- break;
- }
- #endif //WIN32
- #ifdef WIN32
- if (tempsettings.Baud == 14400) {
- baud_index = 0;
- } else if (tempsettings.Baud == 19200) {
- baud_index = 1;
- } else if (tempsettings.Baud == 28800) {
- baud_index = 2;
- } else if (tempsettings.Baud == 38400) {
- baud_index = 3;
- } else {
- baud_index = 4;
- }
- #else //WIN32
- if (tempsettings.Baud == 9600) {
- baud_index = 0;
- } else if (tempsettings.Baud == 14400) {
- baud_index = 1;
- } else if (tempsettings.Baud == 19200) {
- baud_index = 2;
- } else if (tempsettings.Baud == 28800) {
- baud_index = 3;
- } else {
- baud_index = 4;
- }
- #endif //WIN32
- sprintf (baudbuf, "%d", tempsettings.Baud);
- /*
- ** Set up the port list box & edit box
- */
- for (i = 0; i < 4; i++) {
- portlist.Add_Item( portname[ i ] );
- }
- #ifdef WIN32
- /*
- ** Loop through the first 10 possible modem entries in the registry. Frankly, its just
- ** tough luck if the user has more than 10 modems attached!
- */
- if (ModemRegistry) {
- delete ModemRegistry;
- }
- int modems_found = 0;
- for (i=0 ; i<10 ; i++) {
- ModemRegistry = new ModemRegistryEntryClass (i);
- if (ModemRegistry->Get_Modem_Name()) {
- strncpy (modemnames[modems_found], ModemRegistry->Get_Modem_Name(), MODEM_NAME_MAX);
- portlist.Add_Item( modemnames [modems_found++] );
- port_custom_index ++;
- }
- delete ModemRegistry;
- }
- ModemRegistry = NULL;
- #endif //WIN32
- portlist.Add_Item ( custom_port );
- /*
- ** Work out the current port index
- */
- port_index = -1;
- #ifdef WIN32
- if (tempsettings.ModemName[0]) {
- for ( i=0 ; i<port_custom_index ; i++) {
- if (!stricmp (portlist.Get_Item(i), tempsettings.ModemName)) {
- port_index = i;
- strcpy (portbuf, tempsettings.ModemName);
- break;
- }
- }
- /*
- ** The modem name specified wasnt in the registry so add it as a custom entry
- */
- if (port_index == -1) {
- temp = strchr( custom_port, '-' );
- if ( temp ) {
- pos = (int)(temp - custom_port) + 2;
- len = strlen( tempsettings.ModemName );
- strncpy( custom_port + pos, tempsettings.ModemName, len );
- *(custom_port + pos + len) = 0;
- strcpy (portbuf, tempsettings.ModemName);
- port_index = port_custom_index;
- }
- }
- }
- #endif //WIN32
- if (port_index == -1) {
- switch ( tempsettings.Port ) {
- case ( 0x3f8 ):
- port_index = 0;
- strcpy (portbuf, "COM1");
- break;
- case ( 0x2f8 ):
- port_index = 1;
- strcpy (portbuf, "COM2");
- break;
- case ( 0x3e8 ):
- port_index = 2;
- strcpy (portbuf, "COM3");
- break;
- case ( 0x2e8 ):
- port_index = 3;
- strcpy (portbuf, "COM4");
- break;
- default:
- port_index = port_custom_index;
- sprintf (portbuf, "%x", tempsettings.Port);
- temp = strchr( custom_port, '-' );
- if ( temp ) {
- pos = (int)(temp - custom_port) + 2;
- len = strlen( portbuf );
- strncpy( custom_port + pos, portbuf, len );
- *(custom_port + pos + len) = 0;
- }
- break;
- }
- }
- portlist.Set_Selected_Index( port_index );
- /*
- ** Set up the port edit box
- */
- port_edt.Set_Text( portbuf, PORTBUF_MAX );
- #ifndef WIN32
- /*
- ** Set up the IRQ list box & edit box
- */
- for (i = 0; i < 5; i++) {
- irqlist.Add_Item( irqname[ i ] );
- }
- irqlist.Set_Selected_Index( irq_index );
- irq_edt.Set_Text( irqbuf, IRQBUF_MAX );
- #endif //WIN32
- /*
- ** Set up the baud rate list box & edit box
- */
- for (i = 0; i < 5; i++) {
- baudlist.Add_Item( baudname[ i ] );
- }
- baudlist.Set_Selected_Index( baud_index );
- baud_edt.Set_Text( baudbuf, BAUDBUF_MAX );
- initstr_index = tempsettings.InitStringIndex;
- Build_Init_String_Listbox(&initstrlist, &initstr_edt, initstrbuf, &initstr_index);
- /*
- ** Set up the cwait rate list box & edit box
- */
- cwaitstr_index = tempsettings.CallWaitStringIndex;
- for (i = 0; i < CALL_WAIT_STRINGS_NUM; i++) {
- if ( i == CALL_WAIT_CUSTOM ) {
- item = Session.CallWaitStrings[ i ];
- temp = strchr( item, '-' );
- if ( temp ) {
- pos = (int)(temp - item) + 2;
- len = strlen( tempsettings.CallWaitString );
- strncpy( item + pos, tempsettings.CallWaitString, len );
- *(item + pos + len) = 0;
- if (i == cwaitstr_index) {
- strncpy( cwaitstrbuf, item + pos, CWAITSTRBUF_MAX );
- }
- }
- } else if (i == cwaitstr_index) {
- strncpy( cwaitstrbuf, Session.CallWaitStrings[ i ], CWAITSTRBUF_MAX );
- }
- cwaitstrlist.Add_Item( Session.CallWaitStrings[ i ] );
- }
- cwaitstrlist.Set_Selected_Index( cwaitstr_index );
- cwaitstr_edt.Set_Text( cwaitstrbuf, CWAITSTRBUF_MAX );
- /*
- ** Build the button list
- */
- commands = &cancelbtn;
- port_edt.Add_Tail(*commands);
- portlist.Add_Tail(*commands);
- #ifndef WIN32
- irq_edt.Add_Tail(*commands);
- irqlist.Add_Tail(*commands);
- #endif //WIN32
- baud_edt.Add_Tail(*commands);
- baudlist.Add_Tail(*commands);
- initstr_edt.Add_Tail(*commands);
- initstrlist.Add_Tail(*commands);
- addbtn.Add_Tail(*commands);
- deletebtn.Add_Tail(*commands);
- cwaitstr_edt.Add_Tail(*commands);
- cwaitstrlist.Add_Tail(*commands);
- tonebtn.Add_Tail(*commands);
- pulsebtn.Add_Tail(*commands);
- savebtn.Add_Tail(*commands);
- #ifdef WIN32
- advancedbutton.Add_Tail(*commands);
- #endif //WIN32
- if (tempsettings.DialMethod == DIAL_TOUCH_TONE) {
- tonebtn.Turn_On();
- } else {
- pulsebtn.Turn_On();
- }
- /*
- ** Processing loop
- */
- while (process) {
- /*
- ** Invoke game callback
- */
- Call_Back();
- /*
- ** Dont allow editing of non-custom ports to fix the problem of the cursor appearing
- ** outside the edit box.
- */
- if (port_index == port_custom_index) {
- port_edt.Set_Read_Only(false);
- }else{
- port_edt.Set_Read_Only(true);
- }
- #ifdef WIN32
- /*
- ** If we have just received input focus again after running in the background then
- ** we need to redraw.
- */
- if (AllSurfaces.SurfacesRestored) {
- AllSurfaces.SurfacesRestored=FALSE;
- display = REDRAW_ALL;
- }
- #endif
- /*
- ** Refresh display if needed
- */
- if (display) {
- Hide_Mouse();
- /*
- ** Redraw backgound & dialog box
- */
- if (display >= REDRAW_BACKGROUND) {
- Load_Title_Page(true);
- CCPalette.Set();
- Dialog_Box(d_dialog_x, d_dialog_y, d_dialog_w, d_dialog_h);
- // init font variables
- Fancy_Text_Print(TXT_NONE, 0, 0, TBLACK, TBLACK, TPF_CENTER | TPF_TEXT);
- /*
- ** Dialog & Field labels
- */
- Draw_Caption(TXT_SETTINGS, d_dialog_x, d_dialog_y, d_dialog_w);
- Fancy_Text_Print(TXT_PORT_COLON, d_port_x - 3 * RESFACTOR, d_port_y + 1 * RESFACTOR, scheme, TBLACK, TPF_RIGHT | TPF_TEXT);
- #ifndef WIN32
- Fancy_Text_Print(TXT_IRQ_COLON, d_irq_x - 3 * RESFACTOR, d_irq_y + 1 * RESFACTOR, scheme, TBLACK, TPF_RIGHT | TPF_TEXT);
- #endif //WIN32
- Fancy_Text_Print(TXT_BAUD_COLON, d_baud_x - 3 * RESFACTOR, d_baud_y + 1 * RESFACTOR, scheme, TBLACK, TPF_RIGHT | TPF_TEXT);
- Fancy_Text_Print(TXT_INIT_STRING, d_initstr_x, d_initstr_y - d_txt6_h - 3 * RESFACTOR, scheme, TBLACK, TPF_TEXT);
- Fancy_Text_Print(TXT_CWAIT_STRING, d_cwaitstr_x, d_cwaitstr_y - d_txt6_h - 3 * RESFACTOR, scheme, TBLACK, TPF_TEXT);
- }
- /*
- ** Redraw buttons
- */
- if (display >= REDRAW_BUTTONS) {
- cancelbtn.Flag_To_Redraw();
- port_edt.Flag_To_Redraw();
- portlist.Flag_To_Redraw();
- #ifndef WIN32
- irq_edt.Flag_To_Redraw();
- irqlist.Flag_To_Redraw();
- #endif //WIN32
- baud_edt.Flag_To_Redraw();
- baudlist.Flag_To_Redraw();
- #ifdef WIN32
- advancedbutton.Flag_To_Redraw();
- #endif //WIN32
- initstr_edt.Flag_To_Redraw();
- initstrlist.Flag_To_Redraw();
- addbtn.Flag_To_Redraw();
- deletebtn.Flag_To_Redraw();
- cwaitstr_edt.Flag_To_Redraw();
- cwaitstrlist.Flag_To_Redraw();
- tonebtn.Flag_To_Redraw();
- pulsebtn.Flag_To_Redraw();
- savebtn.Flag_To_Redraw();
- }
- Show_Mouse();
- display = REDRAW_NONE;
- }
- /*
- ** Get user input
- */
- input = commands->Input();
- if ( firsttime ) {
- // port_edt.Set_Focus();
- port_edt.Flag_To_Redraw();
- input = commands->Input();
- firsttime = false;
- }
- /*
- ** Process input
- */
- switch (input) {
- #ifdef WIN32
- case (BUTTON_ADVANCED | KN_BUTTON):
- Advanced_Modem_Settings (&tempsettings);
- display = REDRAW_ALL;
- break;
- #endif //WIN32
- case (BUTTON_PORT | KN_BUTTON):
- item = (char *)portlist.Current_Item();
- if (port_index < 4) {
- temp = strchr( item, ' ' );
- if ( !temp ) {
- strncpy( portbuf, item, PORTBUF_MAX );
- } else {
- pos = (int)(temp - item);
- strncpy( portbuf, item, pos );
- portbuf[pos] = 0;
- }
- port_edt.Set_Text( portbuf, PORTBUF_MAX );
- port_edt.Flag_To_Redraw();
- #ifndef WIN32
- irq_edt.Set_Focus();
- irq_edt.Flag_To_Redraw();
- #endif //WIN32
- } else {
- strupr( portbuf );
- if ( stricmp(portbuf, "3F8") == 0 ) {
- port_index = 0;
- portlist.Set_Selected_Index( port_index );
- strcpy (portbuf, "COM1");
- display = REDRAW_BUTTONS;
- } else if ( stricmp(portbuf, "2F8") == 0 ) {
- port_index = 1;
- portlist.Set_Selected_Index( port_index );
- strcpy (portbuf, "COM2");
- display = REDRAW_BUTTONS;
- } else if ( stricmp(portbuf, "3E8") == 0 ) {
- port_index = 2;
- portlist.Set_Selected_Index( port_index );
- strcpy (portbuf, "COM3");
- display = REDRAW_BUTTONS;
- } else if ( stricmp(portbuf, "2E8") == 0 ) {
- port_index = 3;
- portlist.Set_Selected_Index( port_index );
- strcpy (portbuf, "COM4");
- display = REDRAW_BUTTONS;
- } else if ( strncmp(portbuf, "COM", 3) == 0 ) {
- display = REDRAW_BUTTONS;
- switch ( (portbuf[3] - '0') ) {
- case 1:
- port_index = 0;
- break;
- case 2:
- port_index = 1;
- break;
- case 3:
- port_index = 2;
- break;
- case 4:
- port_index = 3;
- break;
- default:
- #ifdef WIN32
- if (portbuf[3] <= '9' && portbuf[3] >'0') {
- portbuf[4] = 0;
- port_index = port_custom_index;
- temp = strchr( item, '-' );
- if ( temp ) {
- pos = (int)(temp - item) + 2;
- len = strlen( portbuf );
- strncpy( item + pos, portbuf, len );
- *(item + pos + len) = 0;
- display = REDRAW_BUTTONS;
- }
- break;
- }
- #endif //WIN32
- WWMessageBox().Process( TXT_INVALID_PORT_ADDRESS );
- port_edt.Set_Focus();
- display = REDRAW_ALL;
- break;
- }
- portlist.Set_Selected_Index( port_index );
- } else {
- temp = strchr( item, '-' );
- if ( temp ) {
- pos = (int)(temp - item) + 2;
- len = strlen( portbuf );
- strncpy( item + pos, portbuf, len );
- *(item + pos + len) = 0;
- display = REDRAW_BUTTONS;
- }
- }
- #ifndef WIN32
- if (display == REDRAW_BUTTONS) {
- irq_edt.Set_Focus();
- irq_edt.Flag_To_Redraw();
- }
- #endif //WIN32
- }
- break;
- case (BUTTON_PORTLIST | KN_BUTTON):
- if (portlist.Current_Index() != port_index) {
- port_index = portlist.Current_Index();
- item = (char *)portlist.Current_Item();
- if (port_index < 4) {
- temp = strchr( item, ' ' );
- pos = (int)(temp - item);
- strncpy( portbuf, item, pos );
- portbuf[pos] = 0;
- port_edt.Clear_Focus();
- // auto select the irq for port
- #ifndef WIN32
- irq_index = _irqidx[ port_index ];
- irqlist.Set_Selected_Index( irq_index );
- item = (char *)irqlist.Current_Item();
- temp = strchr( item, ' ' );
- if ( !temp ) {
- strncpy( irqbuf, item, 2 );
- } else {
- pos = (int)(temp - item);
- strncpy( irqbuf, item, pos );
- irqbuf[pos] = 0;
- }
- irq_edt.Clear_Focus();
- #endif //WIN32
- } else {
- if (port_index == port_custom_index) {
- /*
- ** This is the custom entry
- */
- temp = strchr( item, '-' );
- if ( temp ) {
- pos = (int)(temp - item) + 2;
- if ( *(item + pos) == '?' ) {
- portbuf[0] = 0;
- } else {
- strncpy( portbuf, item + pos, PORTBUF_MAX );
- }
- }
- port_edt.Set_Focus();
- } else {
- /*
- ** Must be a modem name entry so just copy iy
- */
- strncpy (portbuf, item, PORTBUF_MAX);
- }
- }
- port_edt.Set_Text( portbuf, PORTBUF_MAX );
- } else if (port_index < port_custom_index) {
- port_edt.Clear_Focus();
- } else {
- port_edt.Set_Focus();
- }
- display = REDRAW_BUTTONS;
- break;
- #ifndef WIN32
- case (BUTTON_IRQ | KN_BUTTON):
- item = (char *)irqlist.Current_Item();
- if (irq_index < 4) {
- temp = strchr( item, ' ' );
- if ( !temp ) {
- strncpy( irqbuf, item, IRQBUF_MAX );
- } else {
- pos = (int)(temp - item);
- strncpy( irqbuf, item, pos );
- irqbuf[pos] = 0;
- }
- irq_edt.Set_Text( irqbuf, IRQBUF_MAX );
- irq_edt.Flag_To_Redraw();
- } else {
- temp = strchr( item, '-' );
- if ( temp ) {
- pos = (int)(temp - item) + 2;
- len = strlen( irqbuf );
- strncpy( item + pos, irqbuf, len );
- *(item + pos + len) = 0;
- display = REDRAW_BUTTONS;
- }
- }
- baud_edt.Set_Focus();
- baud_edt.Flag_To_Redraw();
- break;
- case (BUTTON_IRQLIST | KN_BUTTON):
- if (irqlist.Current_Index() != irq_index) {
- irq_index = irqlist.Current_Index();
- item = (char *)irqlist.Current_Item();
- if (irq_index < 4) {
- temp = strchr( item, ' ' );
- if ( !temp ) {
- strncpy( irqbuf, item, IRQBUF_MAX );
- } else {
- pos = (int)(temp - item);
- strncpy( irqbuf, item, pos );
- irqbuf[pos] = 0;
- }
- irq_edt.Clear_Focus();
- } else {
- temp = strchr( item, '-' );
- if ( temp ) {
- pos = (int)(temp - item) + 2;
- if ( *(item + pos) == '?' ) {
- irqbuf[0] = 0;
- } else {
- strncpy( irqbuf, item + pos, IRQBUF_MAX );
- }
- }
- irq_edt.Set_Focus();
- }
- irq_edt.Set_Text( irqbuf, IRQBUF_MAX );
- } else if (irq_index < 4) {
- irq_edt.Clear_Focus();
- } else {
- irq_edt.Set_Focus();
- }
- display = REDRAW_BUTTONS;
- break;
- #endif //WIN32
- case (BUTTON_BAUD | KN_BUTTON):
- item = (char *)baudlist.Current_Item();
- strncpy( baudbuf, item, BAUDBUF_MAX );
- baud_edt.Set_Text( baudbuf, BAUDBUF_MAX );
- initstr_edt.Set_Focus();
- initstr_edt.Flag_To_Redraw();
- display = REDRAW_BUTTONS;
- break;
- case (BUTTON_BAUDLIST | KN_BUTTON):
- if (baudlist.Current_Index() != baud_index) {
- baud_index = baudlist.Current_Index();
- item = (char *)baudlist.Current_Item();
- strncpy( baudbuf, item, BAUDBUF_MAX );
- baud_edt.Set_Text( baudbuf, BAUDBUF_MAX );
- baud_edt.Clear_Focus();
- display = REDRAW_BUTTONS;
- }
- break;
- #if 0
- case (BUTTON_INITSTR | KN_BUTTON):
- strupr( initstrbuf );
- strncpy( Session.InitStrings[ initstr_index ], initstrbuf, INITSTRBUF_MAX );
- Build_Init_String_Listbox(&initstrlist, &initstr_edt, initstrbuf,
- &initstr_index);
- cwaitstr_edt.Set_Focus();
- cwaitstr_edt.Flag_To_Redraw();
- display = REDRAW_BUTTONS;
- break;
- #endif
- case (BUTTON_INITSTRLIST | KN_BUTTON):
- if (initstrlist.Current_Index() != initstr_index) {
- initstr_index = initstrlist.Current_Index();
- item = (char *)initstrlist.Current_Item();
- strncpy( initstrbuf, item, INITSTRBUF_MAX );
- initstr_edt.Set_Text( initstrbuf, INITSTRBUF_MAX );
- }
- initstr_edt.Set_Focus();
- initstr_edt.Flag_To_Redraw();
- display = REDRAW_BUTTONS;
- break;
- /*
- ** Add a new InitString entry
- */
- case (BUTTON_ADD | KN_BUTTON):
- item = new char[ INITSTRBUF_MAX ];
- memset (item, 0, INITSTRBUF_MAX);
- strupr ( initstrbuf );
- strncpy ( item, initstrbuf, INITSTRBUF_MAX-1 );
- Session.InitStrings.Add ( item );
- Build_Init_String_Listbox (&initstrlist, &initstr_edt, initstrbuf,
- &initstr_index);
- /*............................................................
- Set the current listbox index to the newly-added item.
- ............................................................*/
- for (i = 0; i < Session.InitStrings.Count(); i++) {
- if (item == Session.InitStrings[i]) {
- initstr_index = i;
- strcpy( initstrbuf, Session.InitStrings[ initstr_index ] );
- initstr_edt.Set_Text( initstrbuf, INITSTRBUF_MAX );
- initstrlist.Set_Selected_Index( initstr_index );
- }
- }
- initstr_edt.Set_Focus();
- initstr_edt.Flag_To_Redraw();
- display = REDRAW_BUTTONS;
- break;
- /*------------------------------------------------------------------
- Delete the current InitString entry
- ------------------------------------------------------------------*/
- case (BUTTON_DELETE | KN_BUTTON):
- if ( Session.InitStrings.Count() && initstr_index != -1) {
- Session.InitStrings.Delete( initstr_index );
- Build_Init_String_Listbox(&initstrlist, &initstr_edt, initstrbuf,
- &initstr_index);
- }
- break;
- case (BUTTON_CWAITSTR | KN_BUTTON):
- item = (char *)cwaitstrlist.Current_Item();
- if (cwaitstr_index < 3) {
- } else {
- temp = strchr( item, '-' );
- if ( temp ) {
- pos = (int)(temp - item) + 2;
- len = strlen( cwaitstrbuf );
- strncpy( item + pos, cwaitstrbuf, len );
- *(item + pos + len) = 0;
- display = REDRAW_BUTTONS;
- }
- }
- break;
- case (BUTTON_CWAITSTRLIST | KN_BUTTON):
- if (cwaitstrlist.Current_Index() != cwaitstr_index) {
- cwaitstr_index = cwaitstrlist.Current_Index();
- item = (char *)cwaitstrlist.Current_Item();
- if (cwaitstr_index < 3) {
- strncpy( cwaitstrbuf, item, CWAITSTRBUF_MAX );
- cwaitstr_edt.Clear_Focus();
- } else {
- temp = strchr( item, '-' );
- if ( temp ) {
- pos = (int)(temp - item) + 2;
- strncpy( cwaitstrbuf, item + pos, CWAITSTRBUF_MAX );
- }
- cwaitstr_edt.Set_Focus();
- }
- cwaitstr_edt.Set_Text( cwaitstrbuf, CWAITSTRBUF_MAX );
- } else if (cwaitstr_index < 3) {
- cwaitstr_edt.Clear_Focus();
- } else {
- cwaitstr_edt.Set_Focus();
- }
- display = REDRAW_BUTTONS;
- break;
- case (BUTTON_TONE | KN_BUTTON):
- tempsettings.DialMethod = DIAL_TOUCH_TONE;
- tonebtn.Turn_On();
- pulsebtn.Turn_Off();
- break;
- case (BUTTON_PULSE | KN_BUTTON):
- tempsettings.DialMethod = DIAL_PULSE;
- tonebtn.Turn_Off();
- pulsebtn.Turn_On();
- break;
- /*------------------------------------------------------------------
- SAVE: save the com settings
- ------------------------------------------------------------------*/
- case (KN_RETURN):
- case (BUTTON_SAVE | KN_BUTTON):
- switch (port_index) {
- case ( 0 ):
- tempsettings.Port = 0x3f8;
- tempsettings.ModemName[0] = 0;
- break;
- case ( 1 ):
- tempsettings.Port = 0x2f8;
- tempsettings.ModemName[0] = 0;
- break;
- case ( 2 ):
- tempsettings.Port = 0x3e8;
- tempsettings.ModemName[0] = 0;
- break;
- case ( 3 ):
- tempsettings.Port = 0x2e8;
- tempsettings.ModemName[0] = 0;
- break;
- default:
- if (port_index == port_custom_index) {
- #ifdef WIN32
- strncpy ( tempsettings.ModemName, portbuf, MODEM_NAME_MAX );
- tempsettings.Port = 1;
- #else //WIN32
- sscanf( portbuf, "%x", &tempsettings.Port );
- tempsettings.ModemName[0] = 0;
- #endif //WIN32
- } else {
- /*
- ** Must be a modem name index
- */
- strcpy (tempsettings.ModemName, portlist.Current_Item());
- tempsettings.Port = 1;
- }
- break;
- }
- #ifndef WIN32
- switch (irq_index) {
- case ( 0 ):
- tempsettings.IRQ = 2;
- break;
- case ( 1 ):
- tempsettings.IRQ = 3;
- break;
- case ( 2 ):
- tempsettings.IRQ = 4;
- break;
- case ( 3 ):
- tempsettings.IRQ = 5;
- break;
- default:
- sscanf( irqbuf, "%d", &tempsettings.IRQ );
- break;
- }
- #endif //WIN32
- sscanf( baudbuf, "%d", &tempsettings.Baud );
- tempsettings.InitStringIndex = initstr_index;
- tempsettings.CallWaitStringIndex = cwaitstr_index;
- item = Session.CallWaitStrings[ CALL_WAIT_CUSTOM ];
- temp = strchr( item, '-' );
- if ( temp ) {
- pos = (int)(temp - item) + 2;
- strncpy( cwaitstrbuf, item + pos, CWAITSTRBUF_MAX );
- } else {
- cwaitstrbuf[ 0 ] = 0;
- }
- strncpy( tempsettings.CallWaitString, cwaitstrbuf, CWAITSTRBUF_MAX );
- dpstatus = NullModem.Detect_Port( &tempsettings );
- if (dpstatus == PORT_VALID) {
- process = false;
- rc = true;
- } else if (dpstatus == PORT_INVALID) {
- #ifdef WIN32
- WWMessageBox().Process( TXT_UNABLE_TO_OPEN_PORT );
- #else //WIN32
- WWMessageBox().Process( TXT_INVALID_SETTINGS );
- #endif //WIN32
- firsttime = true;
- display = REDRAW_ALL;
- } else if (dpstatus == PORT_IRQ_INUSE) {
- WWMessageBox().Process( TXT_IRQ_ALREADY_IN_USE );
- firsttime = true;
- display = REDRAW_ALL;
- }
- break;
- /*------------------------------------------------------------------
- CANCEL: send a SIGN_OFF, bail out with error code
- ------------------------------------------------------------------*/
- case (KN_ESC):
- case (BUTTON_CANCEL | KN_BUTTON):
- process = false;
- rc = false;
- break;
- }
- } /* end of while */
- /*------------------------------------------------------------------------
- Restore screen
- ------------------------------------------------------------------------*/
- Hide_Mouse();
- Load_Title_Page(true);
- Show_Mouse();
- /*------------------------------------------------------------------------
- Save values into the Settings structure
- ------------------------------------------------------------------------*/
- if (rc) {
- memcpy( settings, &tempsettings, sizeof(SerialSettingsType) );
- }
- return(rc);
- } /* end of Com_Settings_Dialog */
- /***************************************************************************
- * Build_Init_String_Listbox -- [re]builds the initstring listbox *
- * *
- * This routine rebuilds the initstring list box from scratch; it also *
- * updates the contents of the initstring edit field. *
- * *
- * INPUT: *
- * list ptr to list box *
- * edit ptr to edit box *
- * buf ptr to buffer for initstring *
- * *
- * OUTPUT: *
- * none. *
- * *
- * WARNINGS: *
- * none. *
- * *
- * HISTORY: *
- * 06/08/1995 DRD : Created. *
- *=========================================================================*/
- static void Build_Init_String_Listbox (ListClass *list, EditClass *edit, char *buf, int *index)
- {
- int i, curidx;
- char *item;
- curidx = *index;
- /*........................................................................
- Clear the list
- ........................................................................*/
- while (list->Count()) {
- item = (char *)(list->Get_Item(0));
- list->Remove_Item(item);
- delete [] item;
- }
- /*
- ** Now sort the init string list by name then number
- */
- qsort ((void *)(&Session.InitStrings[0]), Session.InitStrings.Count(), sizeof(char *), Init_String_Compare);
- /*........................................................................
- Build the list
- ........................................................................*/
- for (i = 0; i < Session.InitStrings.Count(); i++) {
- item = new char[ INITSTRBUF_MAX ];
- strcpy( item, Session.InitStrings[i] );
- list->Add_Item(item);
- }
- list->Flag_To_Redraw();
- /*........................................................................
- Init the current phone book index
- ........................................................................*/
- if (list->Count() == 0 || curidx < -1) {
- curidx = -1;
- } else if (curidx >= list->Count() ) {
- curidx = 0;
- }
- /*........................................................................
- Fill in initstring edit buffer
- ........................................................................*/
- if (curidx > -1) {
- strcpy (buf, Session.InitStrings[ curidx ]);
- edit->Set_Text (buf, INITSTRBUF_MAX );
- list->Set_Selected_Index( curidx );
- }
- *index = curidx;
- }
- /***************************************************************************
- * Init_String_Compare -- for qsort *
- * *
- * INPUT: *
- * p1,p2 ptrs to elements to compare *
- * *
- * OUTPUT: *
- * 0 = same, -1 = (*p1) goes BEFORE (*p2), 1 = (*p1) goes AFTER (*p2) *
- * *
- * WARNINGS: *
- * none. *
- * *
- * HISTORY: *
- * 06/08/1995 DRD : Created. *
- *=========================================================================*/
- static int Init_String_Compare (const void *p1, const void *p2)
- {
- return( strcmp( *((char **)p1), *((char **)p2) ) );
- }
- /***********************************************************************************************
- * Com_Scenario_Dialog -- Serial game scenario selection dialog *
- * *
- * *
- * INPUT: *
- * none. *
- * *
- * OUTPUT: *
- * true = success, false = cancel *
- * *
- * WARNINGS: *
- * none. *
- * *
- * HISTORY: *
- * 02/14/1995 BR : Created.
- * 01/21/97 V.Grippi added check for CS before sending scenario file *
- *=============================================================================================*/
- int Com_Scenario_Dialog(bool skirmish)
- {
- /*........................................................................
- Dialog & button dimensions
- ........................................................................*/
- int d_dialog_w = 320 * RESFACTOR; // dialog width
- int d_dialog_h = 200 * RESFACTOR; // dialog height
- int d_dialog_x = ((320 * RESFACTOR - d_dialog_w) / 2); // dialog x-coord
- int d_dialog_y = ((200 * RESFACTOR - d_dialog_h) / 2); // dialog y-coord
- int d_dialog_cx = d_dialog_x + (d_dialog_w / 2); // center x-coord
- int d_txt6_h = 6 * RESFACTOR+1; // ht of 6-pt text
- int d_margin1 = 5 * RESFACTOR; // margin width/height
- int d_margin2 = 7 * RESFACTOR; // margin width/height
- int d_name_w = 70 * RESFACTOR;
- int d_name_h = 9 * RESFACTOR;
- int d_name_x = d_dialog_x + (d_dialog_w / 4) - (d_name_w / 2);
- int d_name_y = d_dialog_y + d_margin2 + d_txt6_h + 1 * RESFACTOR;
- #ifdef OLDWAY
- int d_gdi_w = 40 * RESFACTOR;
- int d_gdi_h = 9 * RESFACTOR;
- int d_gdi_x = d_dialog_cx - d_gdi_w;
- int d_gdi_y = d_name_y;
- int d_nod_w = 40 * RESFACTOR;
- int d_nod_h = 9 * RESFACTOR;
- int d_nod_x = d_dialog_cx;
- int d_nod_y = d_name_y;
- #else
- int d_house_w = 60 *RESFACTOR;
- int d_house_h = (8 * 5 *RESFACTOR);
- int d_house_x = d_dialog_cx - (d_house_w / 2);
- int d_house_y = d_name_y;
- #endif
- int d_color_w = 10 * RESFACTOR;
- int d_color_h = 9 * RESFACTOR;
- int d_color_y = d_name_y;
- int d_color_x = d_dialog_x + ((d_dialog_w / 4) * 3) - (d_color_w * 3);
- int d_playerlist_w = 118 * RESFACTOR;
- int d_playerlist_h = (6 * 6 * RESFACTOR) + 3 * RESFACTOR; // 6 rows high
- int d_playerlist_x = d_dialog_x + d_margin1 + d_margin1 + 5*RESFACTOR;
- int d_playerlist_y = d_color_y + d_color_h + d_margin2 + 2*RESFACTOR/*KO + d_txt6_h*/;
- int d_scenariolist_w = 162 * RESFACTOR;
- int d_scenariolist_h = (6 * 6 * RESFACTOR) + 3 * RESFACTOR; // 6 rows high
- if (skirmish) {
- d_scenariolist_h *= 2;
- }
- int d_scenariolist_x = d_dialog_x + d_dialog_w - d_margin1 - d_margin1 - d_scenariolist_w - 5*RESFACTOR;
- int d_scenariolist_y = d_color_y + d_color_h + d_margin2 + 2*RESFACTOR;
- if (skirmish) {
- d_scenariolist_x = d_dialog_x + (d_dialog_w-d_scenariolist_w)/2;
- }
- int d_count_w = 25 * RESFACTOR;
- int d_count_h = d_txt6_h;
- int d_count_x = d_playerlist_x + (d_playerlist_w / 2) + 20 * RESFACTOR; // (fudged)
- int d_count_y = d_playerlist_y + d_playerlist_h + (d_margin1 * 2) - 2 * RESFACTOR;
- if (skirmish) {
- d_count_y = d_scenariolist_y + d_scenariolist_h + d_margin1 - 2*RESFACTOR;
- }
- int d_level_w = 25 * RESFACTOR;
- int d_level_h = d_txt6_h;
- int d_level_x = d_playerlist_x + (d_playerlist_w / 2) + 20 * RESFACTOR; // (fudged)
- int d_level_y = d_count_y + d_count_h;
- int d_credits_w = 25 * RESFACTOR;
- int d_credits_h = d_txt6_h;
- int d_credits_x = d_playerlist_x + (d_playerlist_w / 2) + 20 * RESFACTOR; // (fudged)
- int d_credits_y = d_level_y + d_level_h;
- int d_aiplayers_w = 25*RESFACTOR;
- int d_aiplayers_h = d_txt6_h;
- int d_aiplayers_x = d_playerlist_x + (d_playerlist_w / 2) + 20*RESFACTOR; // (fudged)
- int d_aiplayers_y = d_credits_y + d_credits_h;
- int d_options_w = 106 * RESFACTOR;
- int d_options_h = (5 * 6* RESFACTOR) + 4*RESFACTOR;
- int d_options_x = d_dialog_x + d_dialog_w - 149 * RESFACTOR;
- int d_options_y = d_scenariolist_y + d_scenariolist_h + d_margin1 - 2*RESFACTOR;
- int d_message_w = d_dialog_w - (d_margin1 * 2) - 20*RESFACTOR;
- int d_message_h = (8 * d_txt6_h) + 3 * RESFACTOR; // 4 rows high
- int d_message_x = d_dialog_x + d_margin1 + 10*RESFACTOR;
- int d_message_y = d_options_y + d_options_h + 2*RESFACTOR;
- int d_send_w = d_dialog_w - (d_margin1 * 2) - 20*RESFACTOR;
- int d_send_h = 9 * RESFACTOR;
- int d_send_x = d_dialog_x + d_margin1 + 10*RESFACTOR;
- int d_send_y = d_message_y + d_message_h;
- int d_ok_w = 45 * RESFACTOR;
- int d_ok_h = 9 * RESFACTOR;
- int d_ok_x = d_dialog_x + (d_dialog_w / 6) - (d_ok_w / 2);
- int d_ok_y = d_dialog_y + d_dialog_h - d_ok_h - d_margin1 - RESFACTOR*6;
- int d_cancel_w = 45 * RESFACTOR;
- int d_cancel_h = 9 * RESFACTOR;
- int d_cancel_x = d_dialog_cx - (d_cancel_w / 2);
- int d_cancel_y = d_dialog_y + d_dialog_h - d_cancel_h - d_margin1 - RESFACTOR*6;
- int d_load_w = 45 * RESFACTOR;
- int d_load_h = 9 * RESFACTOR;
- int d_load_x = d_dialog_x + ((d_dialog_w * 5) / 6) - (d_load_w / 2);
- int d_load_y = d_dialog_y + d_dialog_h - d_load_h - d_margin1 - RESFACTOR*6;
- /*........................................................................
- Button Enumerations
- ........................................................................*/
- enum {
- BUTTON_NAME = 100,
- #ifdef OLDWAY
- BUTTON_GDI,
- BUTTON_NOD,
- #else
- BUTTON_HOUSE,
- #endif
- BUTTON_CREDITS,
- BUTTON_AIPLAYERS,
- BUTTON_OPTIONS,
- BUTTON_PLAYERLIST,
- BUTTON_SCENARIOLIST,
- BUTTON_COUNT,
- BUTTON_LEVEL,
- BUTTON_OK,
- BUTTON_LOAD,
- BUTTON_CANCEL,
- BUTTON_DIFFICULTY,
- };
- /*........................................................................
- Redraw values: in order from "top" to "bottom" layer of the dialog
- ........................................................................*/
- typedef enum {
- REDRAW_NONE = 0,
- REDRAW_PARMS,
- REDRAW_MESSAGE,
- REDRAW_COLORS,
- REDRAW_BUTTONS,
- REDRAW_BACKGROUND,
- REDRAW_ALL = REDRAW_BACKGROUND
- } RedrawType;
- /*........................................................................
- Dialog variables
- ........................................................................*/
- RedrawType display = REDRAW_ALL; // redraw level
- bool process = true; // process while true
- KeyNumType input;
- int playertabs[] = {77*RESFACTOR}; // tabs for player list box
- int optiontabs[] = {8}; // tabs for player list box
- char namebuf[MPLAYER_NAME_MAX] = {0}; // buffer for player's name
- bool transmit; // 1 = re-transmit new game options
- int cbox_x[] = {
- d_color_x,
- d_color_x + d_color_w,
- d_color_x + (d_color_w * 2),
- d_color_x + (d_color_w * 3),
- d_color_x + (d_color_w * 4),
- d_color_x + (d_color_w * 5),
- d_color_x + (d_color_w * 6),
- d_color_x + (d_color_w * 7)
- };
- bool parms_received = false; // 1 = game options received
- bool changed = false; // 1 = user has changed an option
- int rc;
- int recsignedoff = false;
- int i;
- unsigned long version;
- unsigned long starttime;
- unsigned long timingtime;
- unsigned long lastmsgtime;
- unsigned long lastredrawtime;
- unsigned long transmittime = 0;
- unsigned long theirresponsetime;
- int packetlen;
- static bool first_time = true;
- bool oppscorescreen = false;
- bool gameoptions = Session.Type == GAME_SKIRMISH;
- EventClass *event; // event ptr
- unsigned long msg_timeout = 1200; // init to 20 seconds
- CCFileClass loadfile ("SAVEGAME.NET");
- bool load_game = false; // 1 = load a saved game
- NodeNameType *who; // node to add to Players
- char *item; // for filling in lists
- RemapControlType * scheme = GadgetClass::Get_Color_Scheme();
- bool messages_have_focus = true; // Gadget focus starts on the message system
- Set_Logic_Page(SeenBuff);
- CDTimerClass<SystemTimerClass> kludge_timer; // Timer to allow a wait after client joins
- // game before game can start
- bool ok_button_added = false;
- /*........................................................................
- Buttons
- ........................................................................*/
- GadgetClass * commands; // button list
- 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);
- #ifdef OLDWAY
- TextButtonClass gdibtn(BUTTON_GDI, TXT_ALLIES, TPF_BUTTON, d_gdi_x, d_gdi_y, d_gdi_w, d_gdi_h);
- TextButtonClass nodbtn(BUTTON_NOD, TXT_SOVIET, TPF_BUTTON, d_nod_x, d_nod_y, d_nod_w, d_nod_h);
- #else
- char housetext[25] = "";
- Fancy_Text_Print("", 0, 0, 0, 0, TPF_TEXT);
- DropListClass housebtn(BUTTON_HOUSE, housetext, sizeof(housetext),
- TPF_TEXT,
- d_house_x, d_house_y, d_house_w, d_house_h,
- MFCD::Retrieve("BTN-UP.SHP"),
- MFCD::Retrieve("BTN-DN.SHP"));
- #endif
- 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"));
- 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"));
- GaugeClass countgauge(BUTTON_COUNT, d_count_x, d_count_y, d_count_w, d_count_h);
- char staticcountbuff[35];
- StaticButtonClass staticcount(0, " ", TPF_TEXT, d_count_x+d_count_w+3*RESFACTOR, d_count_y);
- GaugeClass levelgauge(BUTTON_LEVEL, d_level_x, d_level_y, d_level_w, d_level_h);
- char staticlevelbuff[35];
- StaticButtonClass staticlevel(0, " ", TPF_TEXT, d_level_x+d_level_w+3*RESFACTOR, d_level_y);
- GaugeClass creditsgauge(BUTTON_CREDITS, d_credits_x, d_credits_y, d_credits_w, d_credits_h);
- char staticcreditsbuff[35];
- StaticButtonClass staticcredits(0, " ", TPF_TEXT, d_credits_x+d_credits_w+3*RESFACTOR, d_credits_y);
- GaugeClass aiplayersgauge(BUTTON_AIPLAYERS, d_aiplayers_x, d_aiplayers_y, d_aiplayers_w, d_aiplayers_h);
- char staticaibuff[35];
- StaticButtonClass staticai(0, " ", TPF_TEXT, d_aiplayers_x+d_aiplayers_w+3*RESFACTOR, d_aiplayers_y);
- 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"));
- TextButtonClass okbtn(BUTTON_OK, TXT_OK, TPF_BUTTON, d_ok_x, d_ok_y, d_ok_w, d_ok_h);
- TextButtonClass loadbtn(BUTTON_LOAD, TXT_LOAD_BUTTON, TPF_BUTTON, d_load_x, d_load_y, d_load_w, d_load_h);
- TextButtonClass cancelbtn(BUTTON_CANCEL, TXT_CANCEL, TPF_BUTTON, d_cancel_x, d_cancel_y, d_cancel_w, d_cancel_h);
- 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);
- if (Rule.IsFineDifficulty) {
- difficulty.Set_Maximum(5);
- difficulty.Set_Value(2);
- } else {
- difficulty.Set_Maximum(3);
- difficulty.Set_Value(1);
- }
- /*
- ------------------------- Build the button list --------------------------
- */
- commands = &name_edt;
- staticcount.Add_Tail(*commands);
- staticcredits.Add_Tail(*commands);
- staticai.Add_Tail(*commands);
- staticlevel.Add_Tail(*commands);
- if (!skirmish) {
- playerlist.Add_Tail(*commands);
- } else {
- difficulty.Add_Tail(*commands);
- }
- scenariolist.Add_Tail(*commands);
- countgauge.Add_Tail(*commands);
- levelgauge.Add_Tail(*commands);
- creditsgauge.Add_Tail(*commands);
- aiplayersgauge.Add_Tail(*commands);
- optionlist.Add_Tail(*commands);
- if (Session.Type == GAME_SKIRMISH){
- okbtn.Add_Tail(*commands);
- }
- cancelbtn.Add_Tail(*commands);
- if (!skirmish && loadfile.Is_Available()) {
- #ifdef FIXIT_MULTI_SAVE
- //Load button added only when other player has arrived
- //loadbtn.Add_Tail(*commands);
- #endif
- } else {
- cancelbtn.X = loadbtn.X;
- }
- #ifdef OLDWAY
- gdibtn.Add_Tail(*commands);
- nodbtn.Add_Tail(*commands);
- #else
- housebtn.Add_Tail(*commands);
- #endif
- /*
- ----------------------------- Various Inits ------------------------------
- */
- /*........................................................................
- Init player name & house
- ........................................................................*/
- Session.ColorIdx = Session.PrefColor; // init my preferred color
- strcpy (namebuf, Session.Handle); // set my name
- name_edt.Set_Text(namebuf,MPLAYER_NAME_MAX);
- name_edt.Set_Color(&ColorRemaps[(Session.ColorIdx == PCOLOR_DIALOG_BLUE) ? PCOLOR_REALLY_BLUE : Session.ColorIdx]);
- #ifdef OLDWAY
- if (Session.House==HOUSE_GOOD) {
- gdibtn.Turn_On();
- } else {
- nodbtn.Turn_On();
- }
- #else
- for (HousesType house = HOUSE_USSR; house <= HOUSE_FRANCE; house++) {
- housebtn.Add_Item(Text_String(HouseTypeClass::As_Reference(house).Full_Name()));
- }
- housebtn.Set_Selected_Index(Session.House - HOUSE_USSR);
- housebtn.Set_Read_Only (true);
- #endif
- /*........................................................................
- Init scenario values, only the first time through
- ........................................................................*/
- Special.IsCaptureTheFlag = Rule.IsMPCaptureTheFlag;
- if (first_time) {
- Session.Options.Credits = Rule.MPDefaultMoney; // init credits & credit buffer
- Session.Options.Bases = Rule.IsMPBasesOn; // init scenario parameters
- Session.Options.Tiberium = Rule.IsMPTiberiumGrow;
- Session.Options.Goodies = Rule.IsMPCrates;
- Session.Options.AIPlayers = 0;
- Special.IsShadowGrow = Rule.IsMPShadowGrow;
- Session.Options.UnitCount = (SessionClass::CountMax[Session.Options.Bases] + SessionClass::CountMin[Session.Options.Bases]) / 2;
- first_time = false;
- }
- /*........................................................................
- Init button states
- ........................................................................*/
- playerlist.Set_Tabs(playertabs);
- playerlist.Set_Selected_Style(ColorListClass::SELECT_NORMAL);
- optionlist.Set_Tabs(optiontabs);
- optionlist.Set_Read_Only(0);
- optionlist.Add_Item(Text_String(TXT_BASES));
- optionlist.Add_Item(Text_String(TXT_ORE_SPREADS));
- optionlist.Add_Item(Text_String(TXT_CRATES));
- optionlist.Add_Item(Text_String(TXT_SHADOW_REGROWS));
- if (!skirmish) {
- optionlist.Add_Item(Text_String(TXT_CAPTURE_THE_FLAG));
- }
- optionlist.Check_Item(0, Session.Options.Bases);
- optionlist.Check_Item(1, Session.Options.Tiberium);
- optionlist.Check_Item(2, Session.Options.Goodies);
- optionlist.Check_Item(3, Special.IsShadowGrow);
- if (!skirmish) {
- optionlist.Check_Item(4, Special.IsCaptureTheFlag);
- }
- countgauge.Set_Maximum(SessionClass::CountMax[Session.Options.Bases] - SessionClass::CountMin[Session.Options.Bases]);
- countgauge.Set_Value(Session.Options.UnitCount - SessionClass::CountMin[Session.Options.Bases]);
- levelgauge.Set_Maximum(MPLAYER_BUILD_LEVEL_MAX - 1);
- levelgauge.Set_Value(BuildLevel - 1);
- creditsgauge.Set_Maximum(Rule.MPMaxMoney);
- creditsgauge.Set_Value(Session.Options.Credits);
- int maxp = Rule.MaxPlayers - 2;
- // int maxp = Rule.MaxPlayers - (skirmish ? 1 : 2);
- aiplayersgauge.Set_Maximum(maxp);
- if (skirmish) {
- if ( Session.Options.AIPlayers > 7 ) {
- Session.Options.AIPlayers = 7;
- }
- Session.Options.AIPlayers = max(Session.Options.AIPlayers, 1);
- }else{
- if ( Session.Options.AIPlayers > 6 ) {
- Session.Options.AIPlayers = 6;
- }
- }
- aiplayersgauge.Set_Value(Session.Options.AIPlayers - (skirmish ? 1 : 0));
- /*........................................................................
- Init other scenario parameters
- ........................................................................*/
- Special.IsTGrowth = //Session.Options.Tiberium;
- Rule.IsTGrowth = //Session.Options.Tiberium;
- Special.IsTSpread = //Session.Options.Tiberium;
- Rule.IsTSpread = Session.Options.Tiberium;
- transmit = true;
- /*........................................................................
- Clear the Players vector
- ........................................................................*/
- Clear_Vector(&Session.Players);
- /*........................................................................
- Init scenario description list box
- ........................................................................*/
- for (i = 0; i < Session.Scenarios.Count(); i++) {
- for (int j = 0; EngMisStr[j] != NULL; j++) {
- if (!strcmp(Session.Scenarios[i]->Description(), EngMisStr[j])) {
- #ifdef FIXIT_CSII // ajw Added Aftermath installed checks (before, it was assumed).
- // Add mission if it's available to us.
- if( !( ( Is_Mission_Counterstrike((char *)(Session.Scenarios[i]->Get_Filename())) && !Is_Counterstrike_Installed() ) ||
- ( Is_Mission_Aftermath((char *)(Session.Scenarios[i]->Get_Filename())) && !Is_Aftermath_Installed() ) ) )
- #endif
- #if defined(GERMAN) || defined(FRENCH)
- scenariolist.Add_Item(EngMisStr[j+1]);
- #else
- scenariolist.Add_Item(EngMisStr[j]);
- #endif
- break;
- }
- }
- if (EngMisStr[j] == NULL) {
- #ifdef FIXIT_CSII // ajw Added Aftermath installed checks (before, it was assumed). Added officialness check.
- // Add mission if it's available to us.
- if( !Session.Scenarios[i]->Get_Official() ||
- !( ( Is_Mission_Counterstrike((char *)(Session.Scenarios[i]->Get_Filename())) && !Is_Counterstrike_Installed() ) ||
- ( Is_Mission_Aftermath((char *)(Session.Scenarios[i]->Get_Filename())) && !Is_Aftermath_Installed() ) ) )
- #endif
- scenariolist.Add_Item(Session.Scenarios[i]->Description());
- }
- }
- Session.Options.ScenarioIndex = 0; // 1st scenario is selected
- /*........................................................................
- Init random-number generator, & create a seed to be used for all random
- numbers from here on out
- ........................................................................*/
- #ifdef FIXIT_RANDOM_GAME
- srand(time(NULL));
- Seed = rand();
- #else
- // randomize();
- // Seed = rand();
- #endif
- /*........................................................................
- Init the message display system
- ........................................................................*/
- if (!skirmish) {
- Session.Messages.Init (d_message_x + 1, d_message_y + 1, 8,
- MAX_MESSAGE_LENGTH, d_txt6_h, d_send_x + 1, d_send_y + 1, 1,
- 20, MAX_MESSAGE_LENGTH - 5, d_message_w);
- Session.Messages.Add_Edit ((Session.ColorIdx == PCOLOR_DIALOG_BLUE) ? PCOLOR_REALLY_BLUE : Session.ColorIdx,
- TPF_TEXT, NULL, '_', d_message_w);
- }
- /*........................................................................
- Init version number clipping system
- ........................................................................*/
- VerNum.Init_Clipping();
- Load_Title_Page(true);
- CCPalette.Set();
- extern char ModemRXString[];
- if (strlen(ModemRXString) > 36)
- ModemRXString[36] = 0;
- if (strlen(ModemRXString) > 0)
- Session.Messages.Add_Message (NULL, 0, ModemRXString, PCOLOR_BROWN,
- TPF_TEXT, -1);
- ModemRXString[0] = '\0';
- /*
- ---------------------------- Init Mono Output ----------------------------
- */
- #if(SHOW_MONO)
- if (!skirmish) {
- NullModem.Configure_Debug(sizeof (CommHeaderType),sizeof (SerialCommandType),
- SerialPacketNames, 100, 8);
- NullModem.Mono_Debug_Print(1);
- }
- #endif
- /*
- ---------------------------- Processing loop -----------------------------
- */
- if (!skirmish) {
- NullModem.Reset_Response_Time(); // clear response time
- }
- theirresponsetime = 10000; // initialize to an invalid value
- timingtime = lastmsgtime = lastredrawtime = TickCount;
- /*
- ** Those easily offended should avert their eyes from the following line. And whatever
- ** you do, dont search for 'goto'.
- */
- oh_dear_its_a_label:
- while (process) {
- #if(SHOW_MONO)
- if (!skirmish) {
- NullModem.Mono_Debug_Print(0);
- }
- #endif
- if (!skirmish){
- if (!ok_button_added && gameoptions && kludge_timer == 0){
- okbtn.Add_Tail(*commands);
- ok_button_added = true;
- #ifdef FIXIT_VERSION_3
- if( loadfile.Is_Available() )
- {
- loadbtn.Add_Tail( *commands );
- }
- #else
- #ifdef FIXIT_MULTI_SAVE
- if ( loadfile.Is_Available() && PlayingAgainstVersion > VERSION_RED_ALERT_104 ) {
- loadbtn.Add_Tail ( *commands );
- }
- #endif
- #endif
- if (display < REDRAW_BUTTONS) display = REDRAW_BUTTONS;
- }
- }
- /*
- ** Kludge to make sure we redraw the message input line when it loses focus.
- ** If we dont do this then the cursor doesnt disappear.
- */
- if (!skirmish) {
- if (messages_have_focus) {
- if (name_edt.Has_Focus()) {
- if (display < REDRAW_MESSAGE) display = REDRAW_MESSAGE;
- messages_have_focus = false;
- }
- } else {
- if (!name_edt.Has_Focus()) {
- messages_have_focus = true;
- if (display < REDRAW_MESSAGE) display = REDRAW_MESSAGE;
- Session.Messages.Set_Edit_Focus();
- }
- }
- }
- /*
- ........................ Invoke game callback .........................
- */
- Call_Back();
- #ifdef WIN32
- /*
- ** If we have just received input focus again after running in the background then
- ** we need to redraw.
- */
- if (AllSurfaces.SurfacesRestored) {
- AllSurfaces.SurfacesRestored=FALSE;
- display = REDRAW_ALL;
- }
- #endif
- /*
- ...................... Refresh display if needed ......................
- */
- if (display) {
- if (housebtn.IsDropped) {
- housebtn.Collapse();
- display = REDRAW_BACKGROUND;
- }
- Hide_Mouse();
- /*
- .................. Redraw backgound & dialog box ...................
- */
- if (display >= REDRAW_BACKGROUND) {
- Dialog_Box(d_dialog_x, d_dialog_y, d_dialog_w, d_dialog_h);
- // init font variables
- Fancy_Text_Print(TXT_NONE, 0, 0, TBLACK, TBLACK, TPF_CENTER | TPF_TEXT);
- /*...............................................................
- Dialog & Field labels
- ...............................................................*/
- 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);
- #ifdef OLDWAY
- Fancy_Text_Print(TXT_SIDE_COLON, d_gdi_x + d_gdi_w, d_gdi_y - d_txt6_h, scheme, TBLACK, TPF_CENTER | TPF_TEXT);
- #else
- 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);
- #endif
- 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);
- if (!skirmish) {
- Fancy_Text_Print(TXT_PLAYERS, d_playerlist_x + (d_playerlist_w / 2), d_playerlist_y - d_txt6_h, scheme, TBLACK, TPF_CENTER | TPF_TEXT);
- } else {
- Fancy_Text_Print(TXT_EASY, difficulty.X, difficulty.Y-8*RESFACTOR, scheme, TBLACK, TPF_TEXT);
- Fancy_Text_Print(TXT_HARD, difficulty.X + difficulty.Width, difficulty.Y-8*RESFACTOR, scheme, TBLACK, TPF_RIGHT|TPF_TEXT);
- Fancy_Text_Print(TXT_NORMAL, difficulty.X + difficulty.Width/2, difficulty.Y-8*RESFACTOR, scheme, TBLACK, TPF_CENTER|TPF_TEXT);
- }
- Fancy_Text_Print(TXT_SCENARIOS, d_scenariolist_x + (d_scenariolist_w / 2), d_scenariolist_y - d_txt6_h, scheme, TBLACK, TPF_CENTER | TPF_TEXT);
- Fancy_Text_Print(TXT_COUNT, d_count_x - 2, d_count_y, scheme, TBLACK, TPF_TEXT | TPF_RIGHT);
- Fancy_Text_Print(TXT_LEVEL, d_level_x - 2, d_level_y, scheme, TBLACK, TPF_TEXT | TPF_RIGHT);
- Fancy_Text_Print(TXT_CREDITS_COLON, d_credits_x - 2, d_credits_y, scheme, TBLACK, TPF_TEXT | TPF_RIGHT);
- Fancy_Text_Print(TXT_AI_PLAYERS_COLON, d_aiplayers_x - 2*RESFACTOR, d_aiplayers_y, scheme, TBLACK, TPF_TEXT | TPF_RIGHT);
- }
- /*..................................................................
- Draw the color boxes
- ..................................................................*/
- if (display >= REDRAW_COLORS) {
- for (i = 0; i < MAX_MPLAYER_COLORS; i++) {
- LogicPage->Fill_Rect (cbox_x[i] + 1, d_color_y + 1,
- cbox_x[i] + 1 + d_color_w - 2, d_color_y + 1 + d_color_h - 2,
- ColorRemaps[i].Box);
- // (i == PCOLOR_DIALOG_BLUE) ? ColorRemaps[PCOLOR_REALLY_BLUE].Box : ColorRemaps[i].Box);
- if (i == Session.ColorIdx) {
- Draw_Box(cbox_x[i], d_color_y, d_color_w, d_color_h, BOXSTYLE_DOWN, false);
- } else {
- Draw_Box(cbox_x[i], d_color_y, d_color_w, d_color_h, BOXSTYLE_RAISED, false);
- }
- }
- }
- /*..................................................................
- Draw the message system; erase old messages first
- ..................................................................*/
- if (display >= REDRAW_MESSAGE && !skirmish) {
- Draw_Box(d_message_x, d_message_y, d_message_w, d_message_h, BOXSTYLE_BOX, true);
- Draw_Box(d_send_x, d_send_y, d_send_w, d_send_h, BOXSTYLE_BOX, true);
- Session.Messages.Draw();
- }
- //..................................................................
- // Update game parameter labels
- //..................................................................
- if (display >= REDRAW_PARMS) {
- // 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);
- sprintf(staticcountbuff, "%d", Session.Options.UnitCount);
- staticcount.Set_Text(staticcountbuff);
- staticcount.Draw_Me();
- // Fancy_Text_Print("%d ", d_count_x + d_count_w + 3 * RESFACTOR, d_count_y, scheme, BLACK, TPF_TEXT, Session.Options.UnitCount);
- if (BuildLevel <= MPLAYER_BUILD_LEVEL_MAX) {
- sprintf(staticlevelbuff, "%d ", BuildLevel);
- } else {
- sprintf(staticlevelbuff, "**");
- }
- staticlevel.Set_Text(staticlevelbuff);
- staticlevel.Draw_Me();
- // Fancy_Text_Print(txt, d_level_x + d_level_w + 3 * RESFACTOR, d_level_y, scheme, BLACK, TPF_TEXT);
- sprintf(staticcreditsbuff, "%d", Session.Options.Credits);
- staticcredits.Set_Text(staticcreditsbuff);
- staticcredits.Draw_Me();
- // Fancy_Text_Print("%d", d_credits_x + d_credits_w + 2 * RESFACTOR, d_credits_y, scheme, BLACK, TPF_TEXT, Session.Options.Credits);
- sprintf(staticaibuff, "%d", Session.Options.AIPlayers);
- staticai.Set_Text(staticaibuff);
- staticai.Draw_Me();
- // Fancy_Text_Print("%d", d_aiplayers_x + d_aiplayers_w + 2*RESFACTOR, d_aiplayers_y, scheme, BLACK, TPF_TEXT, Session.Options.AIPlayers);
- }
- /*
- .......................... Redraw buttons ..........................
- */
- if (display >= REDRAW_BUTTONS) {
- commands->Flag_List_To_Redraw();
- commands->Draw_All();
- }
- Show_Mouse();
- display = REDRAW_NONE;
- }
- /*
- ........................... Get user input ............................
- */
- messages_have_focus = Session.Messages.Has_Edit_Focus();
- bool droplist_is_dropped = housebtn.IsDropped;
- input = commands->Input();
- /*
- ** Sort out the input focus between the name edit box and the message system
- */
- if (!skirmish) {
- if (messages_have_focus) {
- if (!name_edt.Has_Focus()) {
- Session.Messages.Set_Edit_Focus();
- } else {
- messages_have_focus = false;
- display = REDRAW_MESSAGE;
- }
- }
- }
- /*
- ** Redraw everything if the droplist collapsed
- */
- if (droplist_is_dropped && !housebtn.IsDropped) {
- display = REDRAW_BACKGROUND;
- }
- if (input & KN_BUTTON) {
- if (housebtn.IsDropped) {
- housebtn.Collapse();
- display = REDRAW_BACKGROUND;
- }
- }
- /*
- ---------------------------- Process input ----------------------------
- */
- switch (input) {
- /*------------------------------------------------------------------
- User clicks on a color button
- ------------------------------------------------------------------*/
- case KN_LMOUSE:
- if (Keyboard->MouseQX > cbox_x[0] &&
- Keyboard->MouseQX < (cbox_x[MAX_MPLAYER_COLORS - 1] + d_color_w) &&
- Keyboard->MouseQY > d_color_y &&
- Keyboard->MouseQY < (d_color_y + d_color_h)) {
- Session.PrefColor = (PlayerColorType)((Keyboard->MouseQX - cbox_x[0]) / d_color_w);
- Session.ColorIdx = Session.PrefColor;
- if (display < REDRAW_COLORS) display = REDRAW_COLORS;
- name_edt.Set_Color (&ColorRemaps[(Session.ColorIdx == PCOLOR_DIALOG_BLUE) ? PCOLOR_REALLY_BLUE : Session.ColorIdx]);
- name_edt.Flag_To_Redraw();
- Session.Messages.Set_Edit_Color((Session.ColorIdx == PCOLOR_DIALOG_BLUE) ? PCOLOR_REALLY_BLUE : Session.ColorIdx);
- strcpy (Session.Handle, namebuf);
- transmit = true;
- changed = true;
- if (housebtn.IsDropped) {
- housebtn.Collapse();
- display = REDRAW_BACKGROUND;
- }
- }
- break;
- /*------------------------------------------------------------------
- User edits the name field; retransmit new game options
- ------------------------------------------------------------------*/
- case (BUTTON_NAME | KN_BUTTON):
- if (housebtn.IsDropped) {
- housebtn.Collapse();
- display = REDRAW_BACKGROUND;
- }
- strcpy (Session.Handle, namebuf);
- transmit = true;
- changed = true;
- break;
- #ifdef OLDWAY
- /*------------------------------------------------------------------
- House Buttons: set the player's desired House
- ------------------------------------------------------------------*/
- case (BUTTON_GDI | KN_BUTTON):
- Session.House = HOUSE_GOOD;
- gdibtn.Turn_On();
- nodbtn.Turn_Off();
- strcpy (Session.Handle, namebuf);
- transmit = true;
- break;
- case (BUTTON_NOD | KN_BUTTON):
- Session.House = HOUSE_BAD;
- gdibtn.Turn_Off();
- nodbtn.Turn_On();
- strcpy (Session.Handle, namebuf);
- transmit = true;
- break;
- #else
- case (BUTTON_HOUSE | KN_BUTTON):
- Session.House = HousesType(housebtn.Current_Index()+HOUSE_USSR);
- strcpy (Session.Handle, namebuf);
- display = REDRAW_BACKGROUND;
- transmit = true;
- break;
- #endif
- /*------------------------------------------------------------------
- New Scenario selected.
- ------------------------------------------------------------------*/
- #ifdef FIXIT_VERSION_3 // All scenarios now allowable as downloads. ajw
- case (BUTTON_SCENARIOLIST | KN_BUTTON):
- if (housebtn.IsDropped) {
- housebtn.Collapse();
- display = REDRAW_BACKGROUND;
- }
- if (scenariolist.Current_Index() != Session.Options.ScenarioIndex)
- {
- Session.Options.ScenarioIndex = scenariolist.Current_Index();
- strcpy (Session.Handle, namebuf);
- transmit = true;
- }
- break;
- #else // FIXIT_VERSION_3 Whoever duplicated Netdlg into Nulldlg should be shot. Wasn't it enough?
- Abandon all hope ye who hit enter here.
- case (BUTTON_SCENARIOLIST | KN_BUTTON):
- if (housebtn.IsDropped) {
- housebtn.Collapse();
- display = REDRAW_BACKGROUND;
- }
- if (scenariolist.Current_Index() != Session.Options.ScenarioIndex) {
- #ifdef FIXIT_CSII // checked - ajw
- if ( !skirmish && (PlayingAgainstVersion != VERSION_RED_ALERT_107 && PlayingAgainstVersion != VERSION_RED_ALERT_108 && PlayingAgainstVersion < VERSION_AFTERMATH_CS) &&
- #else
- if ( !skirmish && PlayingAgainstVersion < VERSION_RED_ALERT_107 &&
- #endif
- Session.Scenarios[scenariolist.Current_Index()]->Get_Expansion()){
- scenariolist.Set_Selected_Index (Session.Options.ScenarioIndex);
- Session.Messages.Add_Message(NULL, 0,
- (char *)Text_String(TXT_NO_CS_SCENARIOS), PCOLOR_BROWN, TPF_TEXT, 1200);
- Sound_Effect(VOC_SYS_ERROR);
- if (display < REDRAW_MESSAGE) display = REDRAW_MESSAGE;
- #ifdef FIXIT_CSII // checked - ajw
- } else
- if ( !skirmish && PlayingAgainstVersion < VERSION_AFTERMATH_CS &&
- Is_Mission_126x126((char *)Session.Scenarios[scenariolist.Current_Index()]->Get_Filename() ) ){
- scenariolist.Set_Selected_Index (Session.Options.ScenarioIndex);
- Session.Messages.Add_Message(NULL, 0,
- (char *)Text_String(TXT_NO_CS_SCENARIOS), PCOLOR_BROWN, TPF_TEXT, 1200);
- Sound_Effect(VOC_SYS_ERROR);
- if (display < REDRAW_MESSAGE) display = REDRAW_MESSAGE;
- #endif
- }else{
- Session.Options.ScenarioIndex = scenariolist.Current_Index();
- transmit = 1;
- }
- strcpy (Session.Handle, namebuf);
- transmit = true;
- }
- break;
- #endif
- /*------------------------------------------------------------------
- User adjusts max # units
- ------------------------------------------------------------------*/
- case (BUTTON_COUNT | KN_BUTTON):
- Session.Options.UnitCount = countgauge.Get_Value() + SessionClass::CountMin[Session.Options.Bases];
- if (display < REDRAW_PARMS) display = REDRAW_PARMS;
- if (housebtn.IsDropped) {
- housebtn.Collapse();
- display = REDRAW_BACKGROUND;
- }
- transmit = true;
- break;
- /*------------------------------------------------------------------
- User adjusts build level
- ------------------------------------------------------------------*/
- case (BUTTON_LEVEL | KN_BUTTON):
- BuildLevel = levelgauge.Get_Value() + 1;
- if (BuildLevel > MPLAYER_BUILD_LEVEL_MAX) // if it's pegged, max it out
- BuildLevel = MPLAYER_BUILD_LEVEL_MAX;
- if (display < REDRAW_PARMS) display = REDRAW_PARMS;
- if (housebtn.IsDropped) {
- housebtn.Collapse();
- display = REDRAW_BACKGROUND;
- }
- transmit = true;
- break;
- /*------------------------------------------------------------------
- User adjusts max # units
- ------------------------------------------------------------------*/
- case (BUTTON_CREDITS | KN_BUTTON):
- Session.Options.Credits = creditsgauge.Get_Value();
- Session.Options.Credits = ((Session.Options.Credits + 250) / 500) * 500;
- if (display < REDRAW_PARMS) display = REDRAW_PARMS;
- if (housebtn.IsDropped) {
- housebtn.Collapse();
- display = REDRAW_BACKGROUND;
- }
- transmit = true;
- break;
- //..................................................................
- // User adjusts # of AI players
- //..................................................................
- case (BUTTON_AIPLAYERS | KN_BUTTON):
- {
- Session.Options.AIPlayers = aiplayersgauge.Get_Value();
- int humans = 2; // Two humans.
- if (skirmish) {
- Session.Options.AIPlayers += 1; // Always one forced AI player.
- humans = 1; // One human.
- // if (Session.Options.AIPlayers == 0) {
- // Session.Options.AIPlayers = 1;
- // aiplayersgauge.Set_Value(0);
- // }
- }
- if (Session.Options.AIPlayers+humans >= Rule.MaxPlayers) { // if it's pegged, max it out
- Session.Options.AIPlayers = Rule.MaxPlayers - humans;
- aiplayersgauge.Set_Value(Session.Options.AIPlayers - (skirmish ? 1 : 0));
- }
- transmit = true;
- if (display < REDRAW_PARMS) display = REDRAW_PARMS;
- if (housebtn.IsDropped) {
- housebtn.Collapse();
- display = REDRAW_BACKGROUND;
- }
- break;
- }
- //------------------------------------------------------------------
- // Toggle-able options:
- // If 'Bases' gets toggled, we have to change the range of the
- // UnitCount slider.
- // Also, if Tiberium gets toggled, we have to set the flags
- // in SpecialClass.
- //------------------------------------------------------------------
- case (BUTTON_OPTIONS | KN_BUTTON):
- if (!skirmish && Special.IsCaptureTheFlag != optionlist.Is_Checked(4) && !Special.IsCaptureTheFlag) {
- optionlist.Check_Item(0, true);
- }
- if (Session.Options.Bases != optionlist.Is_Checked(0)) {
- Session.Options.Bases = optionlist.Is_Checked(0);
- if (Session.Options.Bases) {
- Session.Options.UnitCount = Fixed_To_Cardinal (
- SessionClass::CountMax[1] -
- SessionClass::CountMin[1],
- Cardinal_To_Fixed(
- SessionClass::CountMax[0]-SessionClass::CountMin[0],
- Session.Options.UnitCount-SessionClass::CountMin[0])) +
- SessionClass::CountMin[1];
- } else {
- if (!skirmish) optionlist.Check_Item(4, false);
- Session.Options.UnitCount = Fixed_To_Cardinal (
- SessionClass::CountMax[0] -
- SessionClass::CountMin[0],
- Cardinal_To_Fixed(
- SessionClass::CountMax[1]-SessionClass::CountMin[1],
- Session.Options.UnitCount - SessionClass::CountMin[1])) +
- SessionClass::CountMin[0];
- }
- countgauge.Set_Maximum(
- SessionClass::CountMax[Session.Options.Bases] -
- SessionClass::CountMin[Session.Options.Bases]);
- countgauge.Set_Value(Session.Options.UnitCount -
- SessionClass::CountMin[Session.Options.Bases]);
- }
- Session.Options.Tiberium = optionlist.Is_Checked(1);
- Special.IsTGrowth = Session.Options.Tiberium;
- Rule.IsTGrowth = Session.Options.Tiberium;
- Special.IsTSpread = Session.Options.Tiberium;
- Rule.IsTSpread = Session.Options.Tiberium;
- Session.Options.Goodies = optionlist.Is_Checked(2);
- Special.IsShadowGrow = optionlist.Is_Checked(3);
- if (!skirmish) {
- Special.IsCaptureTheFlag = optionlist.Is_Checked(4);
- }
- transmit = true;
- if (display < REDRAW_PARMS) display = REDRAW_PARMS;
- if (housebtn.IsDropped) {
- housebtn.Collapse();
- display = REDRAW_BACKGROUND;
- }
- break;
- /*------------------------------------------------------------------
- OK: exit loop with true status
- ------------------------------------------------------------------*/
- case (BUTTON_LOAD | KN_BUTTON):
- case (BUTTON_OK | KN_BUTTON):
- if (housebtn.IsDropped) {
- housebtn.Collapse();
- display = REDRAW_BACKGROUND;
- }
- //
- // make sure we got a game options packet from the other player
- //
- if (gameoptions) {
- rc = true;
- process = false;
- // force transmitting of game options packet one last time
- transmit = true;
- transmittime = 0;
- } else {
- WWMessageBox().Process (TXT_ONLY_ONE,TXT_OOPS,NULL);
- display = REDRAW_ALL;
- }
- if (input==(BUTTON_LOAD | KN_BUTTON))
- load_game = true;
- break;
- /*------------------------------------------------------------------
- CANCEL: send a SIGN_OFF, bail out with error code
- ------------------------------------------------------------------*/
- case (KN_ESC):
- case (BUTTON_CANCEL | KN_BUTTON):
- if (housebtn.IsDropped) {
- housebtn.Collapse();
- display = REDRAW_BACKGROUND;
- }
- process = false;
- rc = false;
- break;
- /*------------------------------------------------------------------
- Default: manage the inter-player messages
- ------------------------------------------------------------------*/
- default:
- if (!skirmish) {
- if (Session.Messages.Manage()) {
- if (display < REDRAW_MESSAGE) display = REDRAW_MESSAGE;
- }
- /*...............................................................
- Service keyboard input for any message being edited.
- ...............................................................*/
- i = Session.Messages.Input(input);
- /*...............................................................
- If 'Input' returned 1, it means refresh the message display.
- (We have to redraw the edit line, to erase the cursor.)
- ...............................................................*/
- if (i==1) {
- Hide_Mouse();
- Draw_Box(d_send_x, d_send_y, d_send_w, d_send_h,
- BOXSTYLE_BOX, true);
- Session.Messages.Draw();
- Show_Mouse();
- } else if (i==2) {
- /*...............................................................
- If 'Input' returned 2, it means redraw the message display.
- Rather than setting 'display', which would redraw all msgs,
- we only need to erase & redraw the edit box here.
- ...............................................................*/
- Hide_Mouse();
- Draw_Box(d_send_x, d_send_y, d_send_w, d_send_h, BOXSTYLE_BOX, true);
- Session.Messages.Draw();
- Show_Mouse();
- } else if (i==3 || i==4) {
- /*...............................................................
- If 'input' returned 3, it means send the current message.
- ...............................................................*/
- memset (&SendPacket, 0, sizeof(SerialPacketType));
- SendPacket.Command = SERIAL_MESSAGE;
- strcpy (SendPacket.Name, namebuf);
- SendPacket.ID = Session.ColorIdx;
- if (i==3) {
- strcpy (SendPacket.Message.Message, Session.Messages.Get_Edit_Buf());
- } else {
- strcpy (SendPacket.Message.Message, Session.Messages.Get_Overflow_Buf());
- Session.Messages.Clear_Overflow_Buf();
- }
- /*..................................................................
- Send the message
- ..................................................................*/
- if (!skirmish) {
- NullModem.Send_Message (&SendPacket, sizeof(SendPacket), 1);
- NullModem.Service();
- }
- /*..................................................................
- Add the message to our own screen
- ..................................................................*/
- Session.Messages.Add_Message (SendPacket.Name, SendPacket.ID,
- SendPacket.Message.Message,
- (Session.ColorIdx == PCOLOR_DIALOG_BLUE) ? PCOLOR_REALLY_BLUE : Session.ColorIdx,
- TPF_TEXT, -1);
- Session.Messages.Add_Edit((Session.ColorIdx == PCOLOR_DIALOG_BLUE) ?
- PCOLOR_REALLY_BLUE : Session.ColorIdx,
- TPF_TEXT, NULL, '_', d_message_w);
- if (display < REDRAW_MESSAGE) display = REDRAW_MESSAGE;
- } /* end of send message */
- }
- break;
- }
- /*---------------------------------------------------------------------
- Detect editing of the name buffer, transmit new values to players
- ---------------------------------------------------------------------*/
- if (strcmp (namebuf, Session.Handle)) {
- strcpy (Session.Handle, namebuf);
- transmit = true;
- changed = true;
- }
- /*---------------------------------------------------------------------
- If our Transmit flag is set, we need to send out a game option packet.
- This message requires an ACK. The first time through the loop, transmit
- should be set, so we send out our default options; we'll then send
- any changes we make to the defaults.
- ---------------------------------------------------------------------*/
- if (skirmish) {
- transmit = false;
- }
- if (transmit && (TickCount - transmittime) > PACKET_RETRANS_TIME) {
- memset (&SendPacket, 0, sizeof(SerialPacketType));
- SendPacket.Command = SERIAL_GAME_OPTIONS;
- strcpy (SendPacket.Name, namebuf);
- SendPacket.ScenarioInfo.CheatCheck = RuleINI.Get_Unique_ID();
- SendPacket.ScenarioInfo.MinVersion = VerNum.Min_Version();
- SendPacket.ScenarioInfo.MaxVersion = VerNum.Max_Version();
- SendPacket.ScenarioInfo.House = Session.House;
- SendPacket.ScenarioInfo.Color = Session.ColorIdx;
- SendPacket.ScenarioInfo.Credits = Session.Options.Credits;
- SendPacket.ScenarioInfo.IsBases = Session.Options.Bases;
- SendPacket.ScenarioInfo.IsTiberium = Session.Options.Tiberium;
- SendPacket.ScenarioInfo.IsGoodies = Session.Options.Goodies;
- SendPacket.ScenarioInfo.AIPlayers = Session.Options.AIPlayers;
- SendPacket.ScenarioInfo.BuildLevel = BuildLevel;
- SendPacket.ScenarioInfo.UnitCount = Session.Options.UnitCount;
- SendPacket.ScenarioInfo.Seed = Seed;
- SendPacket.ScenarioInfo.Special = Special;
- SendPacket.ScenarioInfo.GameSpeed = Options.GameSpeed;
- SendPacket.ID = Session.ModemType;
- /*
- ** Set up the scenario info so the remote player can match the scenario on his machine
- ** or request a download if it doesnt exist
- */
- strcpy (SendPacket.ScenarioInfo.Scenario, Session.Scenarios[Session.Options.ScenarioIndex]->Description());
- CCFileClass file (Session.Scenarios[Session.Options.ScenarioIndex]->Get_Filename());
- SendPacket.ScenarioInfo.FileLength = file.Size();
- #ifdef WOLAPI_INTEGRATION
- strcpy( SendPacket.ScenarioInfo.ShortFileName, Session.Scenarios[Session.Options.ScenarioIndex]->Get_Filename() );
- #else
- strncpy (SendPacket.ScenarioInfo.ShortFileName, Session.Scenarios[Session.Options.ScenarioIndex]->Get_Filename(), sizeof(SendPacket.ScenarioInfo.ShortFileName));
- #endif
- strncpy ((char*)SendPacket.ScenarioInfo.FileDigest, Session.Scenarios[Session.Options.ScenarioIndex]->Get_Digest(), sizeof SendPacket.ScenarioInfo.FileDigest);
- SendPacket.ScenarioInfo.OfficialScenario = Session.Scenarios[Session.Options.ScenarioIndex]->Get_Official();
- NullModem.Send_Message (&SendPacket, sizeof(SendPacket), 1);
- transmittime = TickCount;
- transmit = false;
- //..................................................................
- // Keep the player list up to date
- //..................................................................
- if (playerlist.Count()) {
- item = (char *)playerlist.Get_Item(0);
- #ifdef OLDWAY
- if (Session.House==HOUSE_GOOD) {
- sprintf(item,"%s\t%s",namebuf,
- Text_String(TXT_ALLIES));
- } else {
- sprintf(item,"%s\t%s",namebuf,
- Text_String(TXT_SOVIET));
- }
- #else //OLDWAY
- sprintf (item, "%s\t%s", namebuf, Text_String(HouseTypeClass::As_Reference(Session.House).Full_Name()));
- #endif //OLDWAY
- playerlist.Colors[0] = &ColorRemaps[(Session.ColorIdx == PCOLOR_DIALOG_BLUE) ?
- PCOLOR_REALLY_BLUE : Session.ColorIdx];
- playerlist.Flag_To_Redraw();
- }
- //..................................................................
- // Play a little sound effect
- //..................................................................
- Sound_Effect(VOC_OPTIONS_CHANGED);
- }
- //
- // send a timing packet if enough time has gone by.
- //
- if (!skirmish && (TickCount - timingtime) > PACKET_TIMING_TIMEOUT) {
- memset (&SendPacket, 0, sizeof(SerialPacketType));
- SendPacket.Command = SERIAL_TIMING;
- SendPacket.ScenarioInfo.ResponseTime = NullModem.Response_Time();
- SendPacket.ID = Session.ModemType;
- NullModem.Send_Message (&SendPacket, sizeof(SendPacket), 0);
- timingtime = TickCount;
- }
- /*---------------------------------------------------------------------
- Check for an incoming message
- ---------------------------------------------------------------------*/
- if (!skirmish && NullModem.Get_Message (&ReceivePacket, &packetlen) > 0) {
- lastmsgtime = TickCount;
- msg_timeout = 600; // reset timeout value to 10 seconds
- // (only the 1st time through is 20 seconds)
- // are we getting our own packets back??
- if (ReceivePacket.Command >= SERIAL_CONNECT &&
- ReceivePacket.Command < SERIAL_LAST_COMMAND &&
- ReceivePacket.Command != SERIAL_MESSAGE &&
- ReceivePacket.ID == Session.ModemType) {
- WWMessageBox().Process (TXT_SYSTEM_NOT_RESPONDING);
- // to skip the other system not responding msg
- lastmsgtime = TickCount;
- process = false;
- rc = false;
- // say we did receive sign off to keep from sending one
- recsignedoff = true;
- break;
- }
- event = (EventClass *)&ReceivePacket;
- if (event->Type <= EventClass::FRAMEINFO) {
- if ( (TickCount - lastredrawtime) > PACKET_REDRAW_TIME) {
- lastredrawtime = TickCount;
- oppscorescreen = true;
- if (display < REDRAW_MESSAGE) display = REDRAW_MESSAGE;
- parms_received = true;
- }
- } else {
- switch ( ReceivePacket.Command ) {
- /*..................................................................
- Sign-off: Give the other machine time to receive my ACK, display a
- message, and exit.
- ..................................................................*/
- case (SERIAL_SIGN_OFF):
- starttime = TickCount;
- while (TickCount - starttime < 60)
- NullModem.Service();
- WWMessageBox().Process(TXT_USER_SIGNED_OFF);
- // to skip the other system not responding msg
- lastmsgtime = TickCount;
- process = false;
- rc = false;
- recsignedoff = true;
- break;
- /*..................................................................
- Game Options: Store the other machine's name, color & house;
- If they've picked the same color as myself, re-transmit my settings
- to force him to choose a different color. (Com_Show_Scenario_Dialog
- is responsible for ensuring the colors are different.)
- ..................................................................*/
- case (SERIAL_GAME_OPTIONS):
- oppscorescreen = false;
- gameoptions = true;
- kludge_timer = 2*60;
- strcpy (TheirName, ReceivePacket.Name);
- TheirColor = ReceivePacket.ScenarioInfo.Color;
- TheirHouse = ReceivePacket.ScenarioInfo.House;
- transmit = true;
- parms_received = true;
- if (display < REDRAW_MESSAGE) display = REDRAW_MESSAGE;
- //.........................................................
- // "Clip" the other system's version range to our own
- // ........................................................
- version = VerNum.Clip_Version(ReceivePacket.ScenarioInfo.MinVersion,
- ReceivePacket.ScenarioInfo.MaxVersion);
- // ........................................................
- // If the greatest-common-version comes back 0, the other
- // system's range is too low for ours
- // ........................................................
- if (version == 0) {
- WWMessageBox().Process (TXT_DESTGAME_OUTDATED);
- // to skip the other system not responding msg
- lastmsgtime = TickCount;
- process = false;
- rc = false;
- } else if (version == 0xffffffff) {
- // ........................................................
- // If the greatest-common-version comes back 0xffffffff,
- // the other system's range is too high for ours
- // ........................................................
- WWMessageBox().Process (TXT_YOURGAME_OUTDATED);
- // to skip the other system not responding msg
- lastmsgtime = TickCount;
- process = false;
- rc = false;
- } else {
- if (ReceivePacket.ScenarioInfo.CheatCheck != RuleINI.Get_Unique_ID()) {
- WWMessageBox().Process (TXT_MISMATCH);
- // to skip the other system not responding msg
- lastmsgtime = TickCount;
- process = false;
- rc = false;
- } else {
- // ........................................................
- // Otherwise, 'version' is the highest version we have in
- // common; look up the protocol that goes with this version.
- // ........................................................
- Session.CommProtocol = VerNum.Version_Protocol(version);
- #ifndef FIXIT_VERSION_3
- PlayingAgainstVersion = version;
- #endif
- }
- }
- /*.........................................................
- If this is the first game-options packet we've received,
- init the game & player lists
- .........................................................*/
- if (playerlist.Count()==0) {
- //......................................................
- // Add two strings to the player list
- //......................................................
- item = new char [MPLAYER_NAME_MAX + 64]; //Need room to display country name
- playerlist.Add_Item(item,
- &ColorRemaps[Session.ColorIdx]);
- item = new char [MPLAYER_NAME_MAX + 64]; //Need room to display country name
- playerlist.Add_Item(item,
- &ColorRemaps[TheirColor]);
- }
- //.........................................................
- // Ensure the player list has the latest, greatest copy of
- // our names & colors. Do this every time we receive an
- // options packet.
- //.........................................................
- item = (char *)playerlist.Get_Item(0);
- #ifdef OLDWAY
- if (Session.House==HOUSE_GOOD) {
- sprintf(item,"%s\t%s",namebuf,
- Text_String(TXT_ALLIES));
- } else {
- sprintf(item,"%s\t%s",namebuf,
- Text_String(TXT_SOVIET));
- }
- #else //OLDWAY
- sprintf (item, "%s\t%s", namebuf, Text_String(HouseTypeClass::As_Reference(Session.House).Full_Name()));
- #endif //OLDWAY
- playerlist.Colors[0] = &ColorRemaps[(Session.ColorIdx == PCOLOR_DIALOG_BLUE) ?
- PCOLOR_REALLY_BLUE : Session.ColorIdx];
- item = (char *)playerlist.Get_Item(1);
- #ifdef OLDWAY
- if (TheirHouse==HOUSE_GOOD) {
- sprintf(item,"%s\t%s",TheirName,
- Text_String(TXT_ALLIES));
- } else {
- sprintf(item,"%s\t%s",TheirName,
- Text_String(TXT_SOVIET));
- }
- #else //OLDWAY
- sprintf (item, "%s\t%s", TheirName, Text_String(HouseTypeClass::As_Reference(TheirHouse).Full_Name()));
- #endif //OLDWAY
- playerlist.Colors[1] = &ColorRemaps[(TheirColor == PCOLOR_DIALOG_BLUE) ?
- PCOLOR_REALLY_BLUE : TheirColor];
- playerlist.Flag_To_Redraw();
- //.........................................................
- // Play a little sound effect
- //.........................................................
- Sound_Effect(VOC_OPTIONS_CHANGED);
- break;
- /*..................................................................
- Incoming message: add to our list
- ..................................................................*/
- case (SERIAL_MESSAGE):
- oppscorescreen = false;
- Session.Messages.Add_Message (ReceivePacket.Name,
- ((PlayerColorType)ReceivePacket.ID == PCOLOR_DIALOG_BLUE) ?
- PCOLOR_REALLY_BLUE : (PlayerColorType)ReceivePacket.ID,
- ReceivePacket.Message.Message,
- ((PlayerColorType)ReceivePacket.ID == PCOLOR_DIALOG_BLUE) ?
- PCOLOR_REALLY_BLUE : (PlayerColorType)ReceivePacket.ID,
- TPF_TEXT, -1);
- Sound_Effect(VOC_INCOMING_MESSAGE);
- if (display < REDRAW_MESSAGE) display = REDRAW_MESSAGE;
- break;
- //
- // get their response time
- //
- case (SERIAL_TIMING):
- oppscorescreen = false;
- theirresponsetime = ReceivePacket.ScenarioInfo.ResponseTime;
- if ( !gameoptions ) {
- // retransmit of game options packet again
- transmit = true;
- }
- break;
- //
- // print msg waiting for opponent
- //
- case (SERIAL_SCORE_SCREEN):
- oppscorescreen = true;
- if (display < REDRAW_MESSAGE) display = REDRAW_MESSAGE;
- parms_received = true;
- break;
- default:
- break;
- }
- }
- }
- // if we haven't received a msg for 10 seconds exit
- if (!skirmish && (TickCount - lastmsgtime) > msg_timeout) {
- WWMessageBox().Process (TXT_SYSTEM_NOT_RESPONDING);
- process = false;
- rc = false;
- // say we did receive sign off to keep from sending one
- recsignedoff = true;
- }
- /*---------------------------------------------------------------------
- Service the connection
- ---------------------------------------------------------------------*/
- if (!skirmish) {
- NullModem.Service();
- }
- }
- /*------------------------------------------------------------------------
- Prepare to load the scenario
- ------------------------------------------------------------------------*/
- if (rc) {
- Session.NumPlayers = skirmish ? 1 : 2;
- Scen.Scenario = Session.Options.ScenarioIndex;
- strcpy (Scen.ScenarioName, Session.Scenarios[Session.Options.ScenarioIndex]->Get_Filename());
- /*.....................................................................
- Add both players to the Players vector; the local system is always
- index 0.
- .....................................................................*/
- who = new NodeNameType;
- strcpy(who->Name, namebuf);
- who->Player.House = Session.House;
- who->Player.Color = Session.ColorIdx;
- who->Player.ProcessTime = -1;
- Session.Players.Add (who);
- /*
- ** Fetch the difficulty setting when in skirmish mode.
- */
- if (skirmish) {
- int diff = difficulty.Get_Value() * (Rule.IsFineDifficulty ? 1 : 2);
- switch (diff) {
- case 0:
- Scen.CDifficulty = DIFF_HARD;
- Scen.Difficulty = DIFF_EASY;
- break;
- case 1:
- Scen.CDifficulty = DIFF_HARD;
- Scen.Difficulty = DIFF_NORMAL;
- break;
- case 2:
- Scen.CDifficulty = DIFF_NORMAL;
- Scen.Difficulty = DIFF_NORMAL;
- break;
- case 3:
- Scen.CDifficulty = DIFF_EASY;
- Scen.Difficulty = DIFF_NORMAL;
- break;
- case 4:
- Scen.CDifficulty = DIFF_EASY;
- Scen.Difficulty = DIFF_HARD;
- break;
- }
- } else {
- Scen.CDifficulty = DIFF_NORMAL;
- Scen.Difficulty = DIFF_NORMAL;
- }
- if (!skirmish) {
- who = new NodeNameType;
- #ifdef FIXIT_MODEM_LOAD_CRASH
- /* If the names of the players are the same then we MUST force them
- * be be unique. This is necessary to prevent a crash after loading
- * a modem save game.
- */
- if (strcmp(TheirName, namebuf) == 0)
- {
- if (strlen(TheirName) == (MPLAYER_NAME_MAX - 1))
- {
- TheirName[MPLAYER_NAME_MAX - 1] = '\0';
- }
- else
- {
- strcat(TheirName, "2");
- }
- }
- #endif
- strcpy(who->Name, TheirName);
- who->Player.House = TheirHouse;
- who->Player.Color = TheirColor;
- who->Player.ProcessTime = -1;
- Session.Players.Add (who);
- }
- /*.....................................................................
- Send all players a GO packet.
- .....................................................................*/
- memset (&SendPacket, 0, sizeof(SerialPacketType));
- if (load_game) {
- SendPacket.Command = SERIAL_LOADGAME;
- } else {
- SendPacket.Command = SERIAL_GO;
- }
- if (!skirmish) {
- SendPacket.ScenarioInfo.ResponseTime = NullModem.Response_Time();
- if ( theirresponsetime == 10000 ) {
- ;
- } else if (SendPacket.ScenarioInfo.ResponseTime < theirresponsetime) {
- SendPacket.ScenarioInfo.ResponseTime = theirresponsetime;
- }
- }
- //
- // calculated one way delay for a packet and overall delay to execute
- // a packet
- //
- if (!skirmish) {
- if (Session.CommProtocol == COMM_PROTOCOL_MULTI_E_COMP) {
- Session.MaxAhead = max( ((((SendPacket.ScenarioInfo.ResponseTime / 8) +
- (Session.FrameSendRate - 1)) / Session.FrameSendRate) *
- Session.FrameSendRate), (Session.FrameSendRate * 2)
- );
- } else {
- Session.MaxAhead = max( (SendPacket.ScenarioInfo.ResponseTime / 8),
- MODEM_MIN_MAX_AHEAD );
- }
- }
- SendPacket.ID = Session.ModemType;
- if (!skirmish) {
- NullModem.Send_Message (&SendPacket, sizeof(SendPacket), 1);
- starttime = TickCount;
- while ( ( NullModem.Num_Send()
- && ((TickCount - starttime) < PACKET_SENDING_TIMEOUT) )
- || ((TickCount - starttime) < 60) ) {
- #if(SHOW_MONO)
- NullModem.Mono_Debug_Print(0);
- #endif
- NullModem.Service();
- }
- /*
- ** Wait for the go response. This will be either a 'GO' reply, a
- ** request for the scenario to be sent or a reply to say that the scenario
- ** cant be played.
- */
- #ifdef WIN32
- WWDebugString ("RA95 - About to wait for 'GO' response.\n");
- #endif
- do {
- NullModem.Service();
- if (NullModem.Get_Message (&ReceivePacket, &packetlen) > 0) {
- #ifdef FIXIT_VERSION_3
- if (ReceivePacket.Command == SERIAL_READY_TO_GO)
- {
- if( Session.Scenarios[Session.Options.ScenarioIndex]->Get_Official() )
- {
- if( !Force_Scenario_Available( Scen.ScenarioName ) )
- Emergency_Exit(EXIT_FAILURE);
- }
- break;
- }
- #else
- if (ReceivePacket.Command == SERIAL_READY_TO_GO) break;
- #endif
- if (ReceivePacket.Command == SERIAL_NO_SCENARIO) {
- WWMessageBox().Process(TXT_NO_EXPANSION_SCENARIO, TXT_CANCEL);
- /*
- ** We have to recover from this somehow so....
- */
- process = true;
- display = REDRAW_ALL;
- lastmsgtime = TickCount;
- goto oh_dear_its_a_label;
- }
- if (ReceivePacket.Command == SERIAL_REQ_SCENARIO) {
- #ifdef WIN32
- WWDebugString ("RA95 - About to call 'Send_Remote_File'.\n");
- #endif
- #ifdef FIXIT_VERSION_3
- if( Session.Scenarios[Session.Options.ScenarioIndex]->Get_Official() )
- {
- if( !Force_Scenario_Available( Scen.ScenarioName ) )
- Emergency_Exit(EXIT_FAILURE);
- }
- #endif
- Send_Remote_File (Scen.ScenarioName, 0);
- break;
- }
- }
- } while ( !Keyboard->Check() );
- // clear queue to keep from doing any resends
- NullModem.Init_Send_Queue();
- }
- } else {
- if ( !recsignedoff ) {
- /*.....................................................................
- Broadcast my sign-off over my network
- .....................................................................*/
- if (!skirmish) {
- memset (&SendPacket, 0, sizeof(SerialPacketType));
- SendPacket.Command = SERIAL_SIGN_OFF;
- SendPacket.ScenarioInfo.Color = Session.ColorIdx; // use Color for ID
- SendPacket.ID = Session.ModemType;
- NullModem.Send_Message (&SendPacket, sizeof(SendPacket), 1);
- starttime = TickCount;
- while ( (NullModem.Num_Send()
- && ((TickCount - starttime) < PACKET_CANCEL_TIMEOUT) )
- || ((TickCount - starttime) < 60) ) {
- #if(SHOW_MONO)
- NullModem.Mono_Debug_Print(0);
- #endif
- if ( NullModem.Get_Message( &ReceivePacket, &packetlen ) > 0) {
- // are we getting our own packets back??
- if (ReceivePacket.Command == SERIAL_SIGN_OFF
- && ReceivePacket.ID == Session.ModemType) {
- // exit while
- break;
- }
- }
- NullModem.Service();
- }
- }
- }
- if (!skirmish) Shutdown_Modem();
- }
- /*------------------------------------------------------------------------
- Clear all lists
- ------------------------------------------------------------------------*/
- while (scenariolist.Count()) {
- scenariolist.Remove_Item(scenariolist.Get_Item(0));
- }
- /*------------------------------------------------------------------------
- Clean up the list boxes
- ------------------------------------------------------------------------*/
- while (playerlist.Count()>0) {
- item = (char *)playerlist.Get_Item(0);
- delete [] item;
- playerlist.Remove_Item(item);
- }
- /*------------------------------------------------------------------------
- Remove the chat edit box
- ------------------------------------------------------------------------*/
- Session.Messages.Remove_Edit();
- /*------------------------------------------------------------------------
- Restore screen
- ------------------------------------------------------------------------*/
- Hide_Mouse();
- Load_Title_Page(true);
- Show_Mouse();
- /*------------------------------------------------------------------------
- Save any changes made to our options
- ------------------------------------------------------------------------*/
- if (changed) {
- Session.Write_MultiPlayer_Settings();
- }
- if (load_game && !skirmish) {
- if (!Load_Game (-1)) {
- WWMessageBox().Process (TXT_ERROR_LOADING_GAME);
- rc = false;
- }
- Frame++;
- }
- return(rc);
- }
- #ifdef FIXIT_CSII // checked - ajw 9/28/98
- extern bool Is_Mission_Aftermath (char *file_name);
- #endif
- /***********************************************************************************************
- * Find_Local_Scenario -- finds the file name of the scenario with matching attributes *
- * *
- * *
- * *
- * INPUT: ptr to Scenario description *
- * ptr to Scenario filename to fix up *
- * length of file for trivial rejection of scenario files *
- * ptr to digest. Digests must match. *
- * *
- * *
- * OUTPUT: true if scenario is available locally *
- * *
- * WARNINGS: We need to reject files that don't match exactly because scenarios with the same *
- * description can exist on both machines but have different contents. For example *
- * there will be lots of scenarios called 'my map' and 'aaaaaa'. *
- * *
- * HISTORY: *
- * 8/23/96 12:36PM ST : Created *
- *=============================================================================================*/
- bool Find_Local_Scenario (char *description, char *filename, unsigned int length, char *digest, bool official)
- {
- //FILE *fp;
- //fp = fopen("findscen.txt","wt");
- //debugprint("looking for local scenario: description = %s, name=%s, length=%d, digest=%s, official=%d\n", description, filename, length, digest, official);
- char digest_buffer[32];
- /*
- ** Scan through the scenario list looking for scenarios with matching descriptions.
- */
- for (int index = 0; index < Session.Scenarios.Count(); index++) {
- //debugprint( "Checking against scenario: %s\n", Session.Scenarios[index]->Description());
- if (!strcmp (Session.Scenarios[index]->Description(), description)) {
- //debugprint("found matching description.\n");
- CCFileClass file (Session.Scenarios[index]->Get_Filename());
- /*
- ** Possible rejection on the basis of availability.
- */
- if (file.Is_Available()) {
- //debugprint("file is available.\n");
- /*
- ** Possible rejection on the basis of size.
- */
- if (file.Size() == length) {
- //debugprint("length matches.\n");
- /*
- ** We don't know the digest for 'official' scenarios so assume its correct
- */
- if (!official) {
- //debugprint("!official.\n");
- /*
- ** Possible rejection on the basis of digest
- */
- INIClass ini;
- ini.Load(file);
- ini.Get_String ("Digest", "1", "No digest here mate. Nope.", digest_buffer, sizeof (digest_buffer) );
- }
- //debugprint("digest = %s, digest_buffer = %s.\n", digest, digest_buffer);
- #ifdef FIXIT_CSII // checked - ajw 9/28/98. But don't know why this happens. Because of autodownload?
- /*
- ** If this is an aftermath scenario then ignore the digest and return success.
- */
- if ( Is_Mission_Aftermath ((char*)Session.Scenarios[index]->Get_Filename()) ) {
- //debugprint("a 1match!\n");
- strcpy (filename, Session.Scenarios[index]->Get_Filename());
- return (true);
- }
- #endif
- /*
- ** This must be the same scenario. Copy the name and return true.
- */
- if (official || !strcmp (digest, digest_buffer)) {
- //debugprint("a match!\n");
- strcpy (filename, Session.Scenarios[index]->Get_Filename());
- return (true);
- }
- }
- }
- // else
- // debugprint("file not available '%s'.\n", Session.Scenarios[index]->Get_Filename());
- }
- }
- //debugprint("failed match.\n");
- /*
- ** Couldnt find the scenario locally. Return failure.
- */
- return (false);
- }
- /***********************************************************************************************
- * Com_Show_Scenario_Dialog -- Serial game scenario selection dialog *
- * *
- * The 'Players' vector is filled in by this routine, when the game starts; this *
- * is for the Assign_Houses routine, which expects this vector to contain all *
- * players' names & houses & colors. Other than that, the Players vector, Games *
- * vector, and Chat vector aren't used at all by this routine. The Game & Players *
- * list boxes are filled in manually in the processing loop. *
- * *
- * ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ *
- * ³ Serial Game ³ *
- * ³ ³ *
- * ³ Your Name: __________ ³ *
- * ³ House: [GDI] [NOD] ³ *
- * ³ Desired Color: [ ][ ][ ][ ] ³ *
- * ³ ³ *
- * ³ Opponent: Name ³ *
- * ³ Scenario: Description ³ *
- * ³ Credits: xxxx ³ *
- * ³ Bases: ON ³ *
- * ³ Crates: ON ³ *
- * ³ Tiberium: ON ³ *
- * ³ Ghosts: ON ³ *
- * ³ ³ *
- * ³ [Cancel] ³ *
- * ³ ³ *
- * ³ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ *
- * ³ ³ ³ ³ *
- * ³ ³ ³ ³ *
- * ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ³ *
- * ³ [Send Message] ³ *
- * ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ *
- * *
- * INPUT: *
- * none. *
- * *
- * OUTPUT: *
- * true = success, false = cancel *
- * *
- * WARNINGS: *
- * none. *
- * *
- * HISTORY: *
- * 02/14/1995 BR : Created. *
- *=============================================================================================*/
- int Com_Show_Scenario_Dialog(void)
- {
- /*........................................................................
- Dialog & button dimensions
- ........................................................................*/
- int d_dialog_w = 320 * RESFACTOR; // dialog width
- int d_dialog_h = 200 * RESFACTOR; // dialog height
- int d_dialog_x = ((320 * RESFACTOR - d_dialog_w) / 2); // dialog x-coord
- int d_dialog_y = ((200 * RESFACTOR - d_dialog_h) / 2); // dialog y-coord
- int d_dialog_cx = d_dialog_x + (d_dialog_w / 2); // center x-coord
- int d_txt6_h = 6 * RESFACTOR+1; // ht of 6-pt text
- int d_margin1 = 5 * RESFACTOR; // margin width/height
- int d_margin2 = 2 * RESFACTOR; // margin width/height
- int d_name_w = 70 * RESFACTOR;
- int d_name_h = 9 * RESFACTOR;
- int d_name_x = d_dialog_x + (d_dialog_w / 4) - (d_name_w / 2);
- int d_name_y = d_dialog_y + d_margin1 + d_margin2 + d_txt6_h + 1*RESFACTOR;
- #ifdef OLDWAY
- int d_gdi_w = 40 * RESFACTOR;
- int d_gdi_h = 9 * RESFACTOR;
- int d_gdi_x = d_dialog_cx - d_gdi_w;
- int d_gdi_y = d_name_y;
- int d_nod_w = 40 * RESFACTOR;
- int d_nod_h = 9 * RESFACTOR;
- int d_nod_x = d_dialog_cx;
- int d_nod_y = d_name_y;
- #else //OLDWAY
- int d_house_w = 60 *RESFACTOR;
- int d_house_h = (8 * 5 *RESFACTOR);
- int d_house_x = d_dialog_cx - (d_house_w / 2);
- int d_house_y = d_name_y;
- #endif //OLDWAY
- int d_color_w = 10 * RESFACTOR;
- int d_color_h = 9 * RESFACTOR;
- int d_color_x = d_dialog_x + ((d_dialog_w / 4) * 3) - (d_color_w * 3);
- int d_color_y = d_name_y;
- int d_scenario_y = d_name_y + d_name_h + d_margin2;
- int d_gamelist_w = 160 * RESFACTOR;
- int d_gamelist_h = (6 * 6 * RESFACTOR) + 3 * RESFACTOR; // 6 rows high
- int d_gamelist_x = d_dialog_x + d_margin1 + 10*RESFACTOR;
- int d_gamelist_y = d_scenario_y + d_txt6_h + d_margin2 + d_txt6_h + d_margin2;
- //BG int d_playerlist_w = 112 * RESFACTOR;
- int d_playerlist_w = 118 * RESFACTOR;
- int d_playerlist_h = (6 * 6 * RESFACTOR) + 3 * RESFACTOR; // 6 rows high
- int d_playerlist_x = d_dialog_x + d_dialog_w - d_margin1 - d_margin1 - d_playerlist_w - 5*RESFACTOR;
- int d_playerlist_y = d_gamelist_y;
- int d_count_w = 25 * RESFACTOR;
- int d_count_h = d_txt6_h;
- int d_count_x = d_gamelist_x + (d_gamelist_w / 2);
- int d_count_y = d_gamelist_y + d_gamelist_h + (d_margin1 * 2) - d_margin2;
- int d_level_w = 25 * RESFACTOR;
- int d_level_h = d_txt6_h;
- int d_level_x = d_gamelist_x + (d_gamelist_w / 2);
- int d_level_y = d_count_y + d_count_h;
- int d_credits_w = 25 * RESFACTOR;
- int d_credits_h = d_txt6_h;
- int d_credits_x = d_gamelist_x + (d_gamelist_w / 2);
- int d_credits_y = d_level_y + d_level_h;
- int d_aiplayers_w = 25 * RESFACTOR;
- int d_aiplayers_h = d_txt6_h;
- int d_aiplayers_x = d_gamelist_x + (d_gamelist_w / 2);
- int d_aiplayers_y = d_credits_y + d_credits_h;
- int d_options_w = 112 * RESFACTOR;
- int d_options_h = (5 * 6* RESFACTOR) + 4*RESFACTOR;
- int d_options_x = d_playerlist_x;
- int d_options_y = d_playerlist_y + d_playerlist_h + d_margin1 - d_margin2;
- int d_message_w = d_dialog_w - (d_margin1 * 2) - 20*RESFACTOR;
- int d_message_h = (7 * d_txt6_h) + 3 * RESFACTOR; // 7 rows high
- int d_message_x = d_gamelist_x;//d_dialog_x + d_margin1 + 10*RESFACTOR;
- int d_message_y = d_options_y + d_options_h + d_margin2/*KO + d_margin1*/;
- int d_send_w = d_message_w;
- int d_send_h = 9 * RESFACTOR;
- int d_send_x = d_message_x;
- int d_send_y = d_message_y + d_message_h;
- int d_cancel_w = 45 * RESFACTOR;
- int d_cancel_h = 9 * RESFACTOR;
- int d_cancel_x = d_dialog_cx - (d_cancel_w / 2);
- int d_cancel_y = d_send_y + d_send_h/*KO + d_margin2*/;
- /*........................................................................
- Button Enumerations
- ........................................................................*/
- enum {
- BUTTON_NAME = 100,
- #ifdef OLDWAY
- BUTTON_GDI,
- BUTTON_NOD,
- #else //OLDWAY
- BUTTON_HOUSE,
- #endif //OLDWAY
- BUTTON_GAMELIST,
- BUTTON_PLAYERLIST,
- BUTTON_CANCEL,
- BUTTON_COUNT,
- BUTTON_LEVEL,
- BUTTON_CREDITS,
- BUTTON_AI_PLAYERS,
- BUTTON_OPTIONS,
- };
- /*........................................................................
- Redraw values: in order from "top" to "bottom" layer of the dialog
- ........................................................................*/
- typedef enum {
- REDRAW_NONE = 0,
- REDRAW_PARMS,
- REDRAW_MESSAGE,
- REDRAW_COLORS,
- REDRAW_BUTTONS,
- REDRAW_BACKGROUND,
- REDRAW_ALL = REDRAW_BACKGROUND
- } RedrawType;
- /*........................................................................
- Dialog variables
- ........................................................................*/
- RedrawType display = REDRAW_ALL; // redraw level
- int cbox_x[] = {
- d_color_x,
- d_color_x + d_color_w,
- d_color_x + (d_color_w * 2),
- d_color_x + (d_color_w * 3),
- d_color_x + (d_color_w * 4),
- d_color_x + (d_color_w * 5),
- d_color_x + (d_color_w * 6),
- d_color_x + (d_color_w * 7)
- };
- char namebuf[MPLAYER_NAME_MAX] = {0}; // buffer for player's name
- //BG int playertabs[] = {77}; // tabs for player list box
- int playertabs[] = {71*RESFACTOR}; // tabs for player list box
- int optiontabs[] = {8}; // tabs for options list box
- bool transmit; // 1 = re-transmit new game options
- bool first; // 1 = no packets received yet
- bool parms_received = false; // 1 = game options received
- bool changed = false; // 1 = user has changed an option
- int rc;
- int recsignedoff = 0;
- int i;
- unsigned long version;
- char txt[80];
- unsigned long starttime;
- unsigned long timingtime;
- unsigned long lastmsgtime;
- unsigned long lastredrawtime;
- unsigned long transmittime = 0;
- int packetlen;
- bool oppscorescreen = false;
- bool gameoptions = false;
- EventClass *event; // event ptr
- unsigned long msg_timeout = 1200; // init to 20 seconds
- bool load_game = false; // 1 = load saved game
- NodeNameType *who; // node to add to Players
- char *item; // for filling in lists
- char *p;
- RemapControlType * scheme = GadgetClass::Get_Color_Scheme();
- Session.Options.ScenarioDescription[0] = 0; //Flag that we dont know the scenario name yet
- bool messages_have_focus = true;
- bool ready_packet_was_sent = false;
- /*........................................................................
- Buttons
- ........................................................................*/
- GadgetClass *commands; // button list
- 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);
- #ifdef OLDWAY
- TextButtonClass gdibtn(BUTTON_GDI, TXT_ALLIES, TPF_BUTTON, d_gdi_x, d_gdi_y, d_gdi_w, d_gdi_h);
- TextButtonClass nodbtn(BUTTON_NOD, TXT_SOVIET, TPF_BUTTON, d_nod_x, d_nod_y, d_nod_w, d_nod_h);
- #else //OLDWAY
- char housetext[25] = "";
- Fancy_Text_Print("", 0, 0, 0, 0, TPF_TEXT);
- DropListClass housebtn(BUTTON_HOUSE, housetext, sizeof(housetext),
- TPF_TEXT,
- d_house_x, d_house_y, d_house_w, d_house_h,
- MFCD::Retrieve("BTN-UP.SHP"),
- MFCD::Retrieve("BTN-DN.SHP"));
- #endif //OLDWAY
- TextButtonClass cancelbtn(BUTTON_CANCEL, TXT_CANCEL, TPF_BUTTON, d_cancel_x, d_cancel_y, d_cancel_w);
- 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"));
- 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"));
- GaugeClass countgauge(BUTTON_COUNT, d_count_x, d_count_y, d_count_w, d_count_h);
- char staticcountbuff[35];
- StaticButtonClass staticcount(0, " ", TPF_TEXT, d_count_x+d_count_w+3*RESFACTOR, d_count_y);
- GaugeClass levelgauge(BUTTON_LEVEL, d_level_x, d_level_y, d_level_w, d_level_h);
- char staticlevelbuff[35];
- StaticButtonClass staticlevel(0, " ", TPF_TEXT, d_level_x+d_level_w+3*RESFACTOR, d_level_y);
- GaugeClass creditsgauge(BUTTON_CREDITS, d_credits_x, d_credits_y, d_credits_w, d_credits_h);
- char staticcreditsbuff[35];
- StaticButtonClass staticcredits(0, " ", TPF_TEXT, d_credits_x+d_credits_w+3*RESFACTOR, d_credits_y);
- GaugeClass aiplayersgauge(BUTTON_AI_PLAYERS, d_aiplayers_x, d_aiplayers_y, d_aiplayers_w, d_aiplayers_h);
- char staticaibuff[35];
- StaticButtonClass staticai(0, " ", TPF_TEXT, d_aiplayers_x+d_aiplayers_w+3*RESFACTOR, d_aiplayers_y);
- 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"));
- /*
- ------------------------- Build the button list --------------------------
- */
- commands = &name_edt;
- staticcount.Add_Tail(*commands);
- staticcredits.Add_Tail(*commands);
- staticai.Add_Tail(*commands);
- staticlevel.Add_Tail(*commands);
- cancelbtn.Add_Tail(*commands);
- gamelist.Add_Tail(*commands);
- playerlist.Add_Tail(*commands);
- countgauge.Add_Tail(*commands);
- levelgauge.Add_Tail(*commands);
- creditsgauge.Add_Tail(*commands);
- aiplayersgauge.Add_Tail(*commands);
- optionlist.Add_Tail(*commands);
- #ifdef OLDWAY
- gdibtn.Add_Tail(*commands);
- nodbtn.Add_Tail(*commands);
- #else //OLDWAY
- housebtn.Add_Tail(*commands);
- #endif //OLDWAY
- //------------------------------------------------------------------------
- // Init the button states
- //------------------------------------------------------------------------
- //........................................................................
- // Name & Color
- //........................................................................
- Session.ColorIdx = Session.PrefColor; // init my preferred color
- strcpy (namebuf, Session.Handle); // set my name
- name_edt.Set_Text(namebuf,MPLAYER_NAME_MAX);
- name_edt.Set_Color(&ColorRemaps[(Session.ColorIdx == PCOLOR_DIALOG_BLUE) ? PCOLOR_REALLY_BLUE : Session.ColorIdx]);
- //........................................................................
- // List boxes
- //........................................................................
- playerlist.Set_Tabs(playertabs);
- playerlist.Set_Selected_Style(ColorListClass::SELECT_NORMAL);
- optionlist.Set_Tabs(optiontabs);
- optionlist.Set_Read_Only(1);
- optionlist.Add_Item(Text_String(TXT_BASES));
- optionlist.Add_Item(Text_String(TXT_ORE_SPREADS));
- optionlist.Add_Item(Text_String(TXT_CRATES));
- optionlist.Add_Item(Text_String(TXT_CAPTURE_THE_FLAG));
- optionlist.Add_Item(Text_String(TXT_SHADOW_REGROWS));
- optionlist.Check_Item(0, Session.Options.Bases);
- optionlist.Check_Item(1, Session.Options.Tiberium);
- optionlist.Check_Item(2, Session.Options.Goodies);
- optionlist.Check_Item(3, Special.IsCaptureTheFlag);
- optionlist.Check_Item(4, Special.IsShadowGrow);
- //........................................................................
- // House buttons
- //........................................................................
- #ifdef OLDWAY
- if (Session.House==HOUSE_GOOD) {
- gdibtn.Turn_On();
- } else {
- nodbtn.Turn_On();
- }
- #else //OLDWAY
- for (HousesType house = HOUSE_USSR; house <= HOUSE_FRANCE; house++) {
- housebtn.Add_Item(Text_String(HouseTypeClass::As_Reference(house).Full_Name()));
- }
- housebtn.Set_Selected_Index(Session.House - HOUSE_USSR);
- housebtn.Set_Read_Only (true);
- #endif //OLDWAY
- //........................................................................
- // Option gauges
- //........................................................................
- countgauge.Use_Thumb(0);
- countgauge.Set_Maximum(SessionClass::CountMax[Session.Options.Bases] - SessionClass::CountMin[Session.Options.Bases]);
- countgauge.Set_Value(Session.Options.UnitCount - SessionClass::CountMin[Session.Options.Bases]);
- levelgauge.Use_Thumb(0);
- levelgauge.Set_Maximum(MPLAYER_BUILD_LEVEL_MAX - 1);
- levelgauge.Set_Value(BuildLevel - 1);
- creditsgauge.Use_Thumb(0);
- creditsgauge.Set_Maximum(Rule.MPMaxMoney);
- creditsgauge.Set_Value(Session.Options.Credits);
- aiplayersgauge.Use_Thumb(0);
- aiplayersgauge.Set_Maximum(Rule.MaxPlayers-2);
- aiplayersgauge.Set_Value(Session.Options.AIPlayers);
- Fancy_Text_Print("", 0, 0, scheme, TBLACK, TPF_CENTER | TPF_TEXT);
- transmit = true;
- first = true;
- /*........................................................................
- Clear the Players vector
- ........................................................................*/
- Clear_Vector(&Session.Players);
- /*........................................................................
- Init the message display system
- ........................................................................*/
- Session.Messages.Init (d_message_x + 1, d_message_y + 1, 7,
- MAX_MESSAGE_LENGTH, d_txt6_h, d_send_x + 1 * RESFACTOR, d_send_y + 1 * RESFACTOR, 1,
- 20, MAX_MESSAGE_LENGTH - 5, d_message_w);
- Session.Messages.Add_Edit ((Session.ColorIdx == PCOLOR_DIALOG_BLUE) ? PCOLOR_REALLY_BLUE : Session.ColorIdx,
- TPF_TEXT, NULL, '_', d_message_w);
- Session.WWChat = 0;
- /*........................................................................
- Init version number clipping system
- ........................................................................*/
- VerNum.Init_Clipping();
- Load_Title_Page(true);
- CCPalette.Set();
- extern char ModemRXString[];
- if (strlen(ModemRXString) > 36)
- ModemRXString[36] = 0;
- if (strlen(ModemRXString) > 0)
- Session.Messages.Add_Message (NULL, 0, ModemRXString, PCOLOR_BROWN,
- TPF_TEXT, -1);
- ModemRXString[0] = '\0';
- /*
- ---------------------------- Init Mono Output ----------------------------
- */
- #if(SHOW_MONO)
- NullModem.Configure_Debug(sizeof (CommHeaderType),sizeof (SerialCommandType),
- SerialPacketNames, 100, 8);
- NullModem.Mono_Debug_Print(1);
- #endif
- /*
- ---------------------------- Processing loop -----------------------------
- */
- NullModem.Reset_Response_Time(); // clear response time
- timingtime = lastmsgtime = lastredrawtime = TickCount;
- bool process = true; // process while true
- while (process) {
- #if(SHOW_MONO)
- NullModem.Mono_Debug_Print(0);
- #endif
- /*
- ** Kludge to make sure we redraw the message input line when it loses focus.
- ** If we dont do this then the cursor doesnt disappear.
- */
- if (messages_have_focus) {
- if (name_edt.Has_Focus()) {
- if (display < REDRAW_MESSAGE) display = REDRAW_MESSAGE;
- messages_have_focus = false;
- }
- } else {
- if (!name_edt.Has_Focus()) {
- messages_have_focus = true;
- if (display < REDRAW_MESSAGE) display = REDRAW_MESSAGE;
- Session.Messages.Set_Edit_Focus();
- }
- }
- /*
- ........................ Invoke game callback .........................
- */
- Call_Back();
- #ifdef WIN32
- /*
- ** If we have just received input focus again after running in the background then
- ** we need to redraw.
- */
- if (AllSurfaces.SurfacesRestored) {
- AllSurfaces.SurfacesRestored=FALSE;
- display = REDRAW_ALL;
- }
- #endif
- /*
- ...................... Refresh display if needed ......................
- */
- if (display) {
- if (housebtn.IsDropped) {
- housebtn.Collapse();
- display = REDRAW_BACKGROUND;
- }
- Hide_Mouse();
- /*
- .................. Redraw backgound & dialog box ...................
- */
- if (display >= REDRAW_BACKGROUND) {
- Dialog_Box(d_dialog_x, d_dialog_y, d_dialog_w, d_dialog_h);
- /*...............................................................
- Dialog & Field labels
- ...............................................................*/
- 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);
- Fancy_Text_Print(TXT_PLAYERS, d_playerlist_x + (d_playerlist_w / 2), d_playerlist_y - d_txt6_h, scheme, TBLACK, TPF_CENTER | TPF_TEXT);
- 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);
- #ifdef OLDWAY
- Fancy_Text_Print(TXT_SIDE_COLON, d_gdi_x + d_gdi_w, d_gdi_y - d_txt6_h, scheme, TBLACK, TPF_CENTER | TPF_TEXT);
- #else
- 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);
- #endif
- 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);
- Fancy_Text_Print (TXT_COUNT, d_count_x - 2 * RESFACTOR, d_count_y, scheme, TBLACK, TPF_TEXT | TPF_RIGHT);
- Fancy_Text_Print (TXT_LEVEL, d_level_x - 2 * RESFACTOR, d_level_y, scheme, TBLACK, TPF_TEXT | TPF_RIGHT);
- Fancy_Text_Print (TXT_CREDITS_COLON, d_credits_x - 2 * RESFACTOR, d_credits_y, scheme, TBLACK, TPF_TEXT | TPF_RIGHT);
- Fancy_Text_Print (TXT_AI_PLAYERS_COLON, d_aiplayers_x - 2 * RESFACTOR, d_aiplayers_y, scheme, TBLACK, TPF_TEXT | TPF_RIGHT);
- }
- /*..................................................................
- Draw the color boxes
- ..................................................................*/
- if (display >= REDRAW_COLORS) {
- for (i = 0; i < MAX_MPLAYER_COLORS; i++) {
- LogicPage->Fill_Rect (cbox_x[i] + 1 * RESFACTOR, d_color_y + 1 * RESFACTOR,
- cbox_x[i] + 1 * RESFACTOR + d_color_w - 2 * RESFACTOR, d_color_y + 1 * RESFACTOR + d_color_h - 2 * RESFACTOR,
- ColorRemaps[i].Box);
- // (i == PCOLOR_DIALOG_BLUE) ? ColorRemaps[PCOLOR_REALLY_BLUE].Box : ColorRemaps[i].Box);
- if (i == Session.ColorIdx) {
- Draw_Box(cbox_x[i], d_color_y, d_color_w, d_color_h,
- BOXSTYLE_DOWN, false);
- } else {
- Draw_Box(cbox_x[i], d_color_y, d_color_w, d_color_h,
- BOXSTYLE_RAISED, false);
- }
- }
- }
- /*..................................................................
- Draw the message system; erase old messages first
- ..................................................................*/
- if (display >= REDRAW_MESSAGE) {
- Draw_Box(d_message_x, d_message_y, d_message_w, d_message_h,
- BOXSTYLE_BOX, true);
- Draw_Box(d_send_x, d_send_y, d_send_w, d_send_h,
- BOXSTYLE_BOX, true);
- Session.Messages.Draw();
- //..................................................................
- // Redraw the game options
- //..................................................................
- if (display >= REDRAW_PARMS && parms_received) {
- if (oppscorescreen) {
- sprintf(txt,"%s",Text_String(TXT_WAITING_FOR_OPPONENT));
- int txtwidth = String_Pixel_Width( txt );
- Fancy_Text_Print(txt, d_dialog_cx, d_scenario_y, scheme, TBLACK, TPF_CENTER | TPF_TEXT);
- } else {
- /*............................................................
- Scenario description
- ............................................................*/
- //LogicPage->Fill_Rect(d_dialog_x + 16*RESFACTOR, d_scenario_y,
- // d_dialog_x + d_dialog_w - 16*RESFACTOR, d_scenario_y + d_txt6_h, BLACK);
- p = (char *)Text_String(TXT_SCENARIO_COLON);
- if (Session.Options.ScenarioDescription[0]) {
- // sprintf(txt,"%s %s",p, Session.Options.ScenarioDescription);
- // Fancy_Text_Print (txt, d_dialog_cx, d_scenario_y, scheme, TBLACK, TPF_TEXT | TPF_CENTER);
- // EW - Scenario language translation goes here!!!!!!!! VG
- for (i = 0; EngMisStr[i] != NULL; i++) {
- if (!strcmp(Session.Options.ScenarioDescription, EngMisStr[i])) {
- #if defined(GERMAN) || defined(FRENCH)
- sprintf(txt, "%s %s", p, EngMisStr[i+1]);
- #else
- sprintf(txt, "%s %s", p, Session.Options.ScenarioDescription);
- #endif
- break;
- }
- }
- if (EngMisStr[i] == NULL) {
- sprintf(txt, "%s %s", p, Session.Options.ScenarioDescription);
- }
- Fancy_Text_Print (txt, d_dialog_cx, d_scenario_y, scheme, TBLACK, TPF_TEXT | TPF_CENTER);
- } else {
- sprintf(txt,"%s %s",p,Text_String(TXT_NOT_FOUND));
- Fancy_Text_Print (txt, d_dialog_cx, d_scenario_y, &ColorRemaps[PCOLOR_RED], TBLACK, TPF_TEXT | TPF_CENTER);
- }
- //.........................................................
- // Unit count, tech level, credits
- //.........................................................
- //LogicPage->Fill_Rect(d_count_x + d_count_w + 2 * RESFACTOR, d_count_y,
- // d_count_x + d_count_w + 35 * RESFACTOR, d_aiplayers_y + d_aiplayers_h+RESFACTOR,
- // BLACK);
- sprintf(staticcountbuff, "%d", Session.Options.UnitCount);
- staticcount.Set_Text(staticcountbuff);
- staticcount.Draw_Me();
- if (BuildLevel <= MPLAYER_BUILD_LEVEL_MAX) {
- sprintf(staticlevelbuff, "%d ", BuildLevel);
- } else {
- sprintf(staticlevelbuff, "**");
- }
- staticlevel.Set_Text(staticlevelbuff);
- staticlevel.Draw_Me();
- sprintf(staticcreditsbuff, "%d", Session.Options.Credits);
- staticcredits.Set_Text(staticcreditsbuff);
- staticcredits.Draw_Me();
- sprintf(staticaibuff, "%d", Session.Options.AIPlayers);
- staticai.Set_Text(staticaibuff);
- staticai.Draw_Me();
- }
- }
- }
- /*
- .......................... Redraw buttons ..........................
- */
- if (display >= REDRAW_BUTTONS) {
- commands->Flag_List_To_Redraw();
- }
- Show_Mouse();
- display = REDRAW_NONE;
- }
- /*
- ........................... Get user input ............................
- */
- messages_have_focus = Session.Messages.Has_Edit_Focus();
- bool droplist_is_dropped = housebtn.IsDropped;
- KeyNumType input = commands->Input();
- /*
- ** Sort out the input focus between the name edit box and the message system
- */
- if (messages_have_focus) {
- if (!name_edt.Has_Focus()) {
- Session.Messages.Set_Edit_Focus();
- } else {
- messages_have_focus = false;
- if (display < REDRAW_MESSAGE) display = REDRAW_MESSAGE;
- }
- }
- /*
- ** Redraw everything if the droplist collapsed
- */
- if (droplist_is_dropped && !housebtn.IsDropped) {
- display = REDRAW_BACKGROUND;
- }
- /*
- ---------------------------- Process input ----------------------------
- */
- switch (input) {
- /*------------------------------------------------------------------
- User clicks on a color button
- ------------------------------------------------------------------*/
- case KN_LMOUSE:
- if (Keyboard->MouseQX > cbox_x[0] &&
- Keyboard->MouseQX < (cbox_x[MAX_MPLAYER_COLORS - 1] + d_color_w) &&
- Keyboard->MouseQY > d_color_y &&
- Keyboard->MouseQY < (d_color_y + d_color_h)) {
- /*.........................................................
- Compute my preferred color as the one I clicked on.
- .........................................................*/
- Session.PrefColor = (PlayerColorType)
- ((Keyboard->MouseQX - cbox_x[0]) / d_color_w);
- changed = true;
- /*.........................................................
- If 'TheirColor' is set to the other player's color, make
- sure we can't pick that color.
- .........................................................*/
- if (parms_received) {
- if (Session.PrefColor == TheirColor)
- break;
- }
- Session.ColorIdx = Session.PrefColor;
- name_edt.Set_Color(&ColorRemaps[(Session.ColorIdx == PCOLOR_DIALOG_BLUE) ?
- PCOLOR_REALLY_BLUE : Session.ColorIdx]);
- name_edt.Flag_To_Redraw();
- Session.Messages.Set_Edit_Color((Session.ColorIdx == PCOLOR_DIALOG_BLUE) ?
- PCOLOR_REALLY_BLUE : Session.ColorIdx);
- if (display < REDRAW_COLORS) display = REDRAW_COLORS;
- strcpy (Session.Handle, namebuf);
- transmit = true;
- if (housebtn.IsDropped) {
- housebtn.Collapse();
- display = REDRAW_BACKGROUND;
- }
- } else if ( (Get_Mouse_X() >= d_count_x &&
- Get_Mouse_X() <= d_count_x + d_count_w &&
- Get_Mouse_Y() >= d_count_y &&
- Get_Mouse_Y() <= d_aiplayers_y + d_aiplayers_h) ||
- (Get_Mouse_X() >= d_options_x &&
- Get_Mouse_X() <= d_options_x + d_options_w &&
- Get_Mouse_Y() >= d_options_y &&
- Get_Mouse_Y() <= d_options_y + d_options_h) ) {
- Session.Messages.Add_Message(NULL, 0, (char *)Text_String(TXT_ONLY_HOST_CAN_MODIFY), PCOLOR_BROWN, TPF_TEXT, 1200);
- Sound_Effect(VOC_SYS_ERROR);
- if (display < REDRAW_MESSAGE) display = REDRAW_MESSAGE;
- if (housebtn.IsDropped) {
- housebtn.Collapse();
- display = REDRAW_BACKGROUND;
- }
- }
- break;
- #ifdef OLDWAY
- /*------------------------------------------------------------------
- House Buttons: set the player's desired House
- ------------------------------------------------------------------*/
- case (BUTTON_GDI | KN_BUTTON):
- Session.House = HOUSE_GOOD;
- gdibtn.Turn_On();
- nodbtn.Turn_Off();
- strcpy (Session.Handle, namebuf);
- transmit = true;
- break;
- case (BUTTON_NOD | KN_BUTTON):
- Session.House = HOUSE_BAD;
- gdibtn.Turn_Off();
- nodbtn.Turn_On();
- strcpy (Session.Handle, namebuf);
- transmit = true;
- break;
- #else //OLDWAY
- case (BUTTON_HOUSE | KN_BUTTON):
- Session.House = HousesType(housebtn.Current_Index()+HOUSE_USSR);
- strcpy (Session.Handle, namebuf);
- transmit = true;
- //display = REDRAW_BACKGROUND;
- break;
- #endif //OLDWAY
- /*------------------------------------------------------------------
- User edits the name value; retransmit
- ------------------------------------------------------------------*/
- case (BUTTON_NAME | KN_BUTTON):
- if (housebtn.IsDropped) {
- housebtn.Collapse();
- display = REDRAW_BACKGROUND;
- }
- strcpy (Session.Handle, namebuf);
- transmit = true;
- changed = true;
- break;
- /*------------------------------------------------------------------
- CANCEL: send a SIGN_OFF, bail out with error code
- ------------------------------------------------------------------*/
- case (KN_ESC):
- case (BUTTON_CANCEL | KN_BUTTON):
- process = false;
- rc = false;
- break;
- /*------------------------------------------------------------------
- Default: manage the inter-player messages
- ------------------------------------------------------------------*/
- default:
- if (Session.Messages.Manage()) {
- if (display < REDRAW_MESSAGE) display = REDRAW_MESSAGE;
- }
- /*...............................................................
- Service keyboard input for any message being edited.
- ...............................................................*/
- i = Session.Messages.Input(input);
- /*...............................................................
- If 'Input' returned 1, it means refresh the message display.
- (We have to redraw the edit line, to erase the cursor.)
- ...............................................................*/
- if (i==1) {
- Hide_Mouse();
- Draw_Box(d_send_x, d_send_y, d_send_w, d_send_h,
- BOXSTYLE_BOX, true);
- Session.Messages.Draw();
- Show_Mouse();
- } else if (i==2) {
- /*...............................................................
- If 'Input' returned 2, it means redraw the message display.
- Rather than setting 'display', which would redraw all msgs,
- we only need to erase & redraw the edit box here.
- ...............................................................*/
- Hide_Mouse();
- Draw_Box(d_send_x, d_send_y, d_send_w, d_send_h,
- BOXSTYLE_BOX, true);
- Session.Messages.Draw();
- Show_Mouse();
- } else if (i==3 || i==4) {
- /*...............................................................
- If 'input' returned 3, it means send the current message.
- ...............................................................*/
- memset (&SendPacket, 0, sizeof(SerialPacketType));
- SendPacket.Command = SERIAL_MESSAGE;
- strcpy (SendPacket.Name, namebuf);
- SendPacket.ID = Session.ColorIdx;
- if (i==3) {
- strcpy (SendPacket.Message.Message, Session.Messages.Get_Edit_Buf());
- } else {
- strcpy (SendPacket.Message.Message, Session.Messages.Get_Overflow_Buf());
- Session.Messages.Clear_Overflow_Buf();
- }
- /*..................................................................
- Send the message
- ..................................................................*/
- NullModem.Send_Message (&SendPacket, sizeof(SendPacket), 1);
- NullModem.Service();
- /*..................................................................
- Add the message to our own screen
- ..................................................................*/
- Session.Messages.Add_Message (SendPacket.Name, SendPacket.ID,
- SendPacket.Message.Message,
- (Session.ColorIdx == PCOLOR_DIALOG_BLUE) ? PCOLOR_REALLY_BLUE : Session.ColorIdx,
- TPF_TEXT, -1);
- Session.Messages.Add_Edit((Session.ColorIdx == PCOLOR_DIALOG_BLUE) ?
- PCOLOR_REALLY_BLUE : Session.ColorIdx,
- TPF_TEXT, NULL, '_', d_message_w);
- if (display < REDRAW_MESSAGE) display = REDRAW_MESSAGE;
- }
- break;
- }
- /*---------------------------------------------------------------------
- Detect editing of the name buffer, transmit new values to players
- ---------------------------------------------------------------------*/
- if (strcmp (namebuf, Session.Handle)) {
- strcpy (Session.Handle, namebuf);
- transmit = true;
- changed = true;
- }
- /*---------------------------------------------------------------------
- If our Transmit flag is set, we need to send out a game option packet
- ---------------------------------------------------------------------*/
- if (transmit && (TickCount - transmittime) > PACKET_RETRANS_TIME) {
- memset (&SendPacket, 0, sizeof(SerialPacketType));
- SendPacket.Command = SERIAL_GAME_OPTIONS;
- strcpy (SendPacket.Name, namebuf);
- SendPacket.ScenarioInfo.CheatCheck = RuleINI.Get_Unique_ID();
- SendPacket.ScenarioInfo.MinVersion = VerNum.Min_Version();
- SendPacket.ScenarioInfo.MaxVersion = VerNum.Max_Version();
- SendPacket.ScenarioInfo.House = Session.House;
- SendPacket.ScenarioInfo.Color = Session.ColorIdx;
- SendPacket.ID = Session.ModemType;
- NullModem.Send_Message (&SendPacket, sizeof(SendPacket), 1);
- transmittime = TickCount;
- transmit = false;
- //..................................................................
- // Keep the player list up to date
- //..................................................................
- if (playerlist.Count()) {
- item = (char *)playerlist.Get_Item(0);
- #ifdef OLDWAY
- if (Session.House==HOUSE_GOOD) {
- sprintf(item,"%s\t%s",namebuf,
- Text_String(TXT_ALLIES));
- } else {
- sprintf(item,"%s\t%s",namebuf,
- Text_String(TXT_SOVIET));
- }
- #else //OLDWAY
- sprintf (item, "%s\t%s", namebuf, Text_String(HouseTypeClass::As_Reference(Session.House).Full_Name()));
- #endif //OLDWAY
- playerlist.Colors[0] = &ColorRemaps[(Session.ColorIdx == PCOLOR_DIALOG_BLUE) ?
- PCOLOR_REALLY_BLUE : Session.ColorIdx];
- playerlist.Flag_To_Redraw();
- }
- //..................................................................
- // Play a little sound effect
- //..................................................................
- Sound_Effect(VOC_OPTIONS_CHANGED);
- }
- //
- // send a timing packet if enough time has gone by.
- //
- if ((TickCount - timingtime) > PACKET_TIMING_TIMEOUT) {
- memset (&SendPacket, 0, sizeof(SerialPacketType));
- SendPacket.Command = SERIAL_TIMING;
- SendPacket.ScenarioInfo.ResponseTime = NullModem.Response_Time();
- SendPacket.ID = Session.ModemType;
- NullModem.Send_Message (&SendPacket, sizeof(SendPacket), 0);
- timingtime = TickCount;
- }
- /*---------------------------------------------------------------------
- Check for an incoming message
- ---------------------------------------------------------------------*/
- if (NullModem.Get_Message(&ReceivePacket, &packetlen) > 0) {
- lastmsgtime = TickCount;
- msg_timeout = 600;
- // are we getting our own packets back??
- if (ReceivePacket.Command >= SERIAL_CONNECT &&
- ReceivePacket.Command < SERIAL_LAST_COMMAND &&
- ReceivePacket.Command != SERIAL_MESSAGE &&
- ReceivePacket.ID == Session.ModemType) {
- WWMessageBox().Process (TXT_SYSTEM_NOT_RESPONDING);
- // to skip the other system not responding msg
- lastmsgtime = TickCount;
- process = false;
- rc = false;
- // say we did receive sign off to keep from sending one
- recsignedoff = true;
- break;
- }
- event = (EventClass *)&ReceivePacket;
- if (event->Type <= EventClass::FRAMEINFO) {
- if ( (TickCount - lastredrawtime) > PACKET_REDRAW_TIME) {
- lastredrawtime = TickCount;
- oppscorescreen = true;
- if (display < REDRAW_MESSAGE) display = REDRAW_MESSAGE;
- parms_received = true;
- }
- } else {
- switch ( ReceivePacket.Command ) {
- /*..................................................................
- Other system signs off: Give it time to receive my ACK, then show
- a message.
- ..................................................................*/
- case (SERIAL_SIGN_OFF):
- starttime = TickCount;
- while ( (TickCount - starttime) < 60)
- NullModem.Service();
- WWMessageBox().Process(TXT_USER_SIGNED_OFF);
- // to skip the other system not responding msg
- lastmsgtime = TickCount;
- process = false;
- rc = false;
- recsignedoff = true;
- break;
- /*..................................................................
- Game Options: Store all options; check my color & game version.
- ..................................................................*/
- case (SERIAL_GAME_OPTIONS):
- oppscorescreen = false;
- gameoptions = true;
- if (display < REDRAW_MESSAGE) display = REDRAW_MESSAGE;
- parms_received = true;
- strcpy (TheirName, ReceivePacket.Name);
- TheirColor = ReceivePacket.ScenarioInfo.Color;
- TheirHouse = ReceivePacket.ScenarioInfo.House;
- /*...............................................................
- Make sure I don't have the same color as the other guy.
- ...............................................................*/
- if (Session.ColorIdx == TheirColor) {
- // force transmitting of game options packet
- transmit = true;
- transmittime = 0;
- Session.ColorIdx = (PlayerColorType)(TheirColor + 1);
- if (Session.ColorIdx >= 6) {
- Session.ColorIdx = PCOLOR_FIRST;
- }
- name_edt.Set_Color(&ColorRemaps[(Session.ColorIdx == PCOLOR_DIALOG_BLUE) ? PCOLOR_REALLY_BLUE : Session.ColorIdx]);
- name_edt.Flag_To_Redraw();
- if (display < REDRAW_COLORS) display = REDRAW_COLORS;
- if (housebtn.IsDropped) {
- housebtn.Collapse();
- display = REDRAW_BACKGROUND;
- }
- }
- /*...............................................................
- Save scenario settings.
- ...............................................................*/
- Session.Options.Credits = ReceivePacket.ScenarioInfo.Credits;
- Session.Options.Bases = ReceivePacket.ScenarioInfo.IsBases;
- Session.Options.Tiberium = ReceivePacket.ScenarioInfo.IsTiberium;
- Session.Options.Goodies = ReceivePacket.ScenarioInfo.IsGoodies;
- Session.Options.AIPlayers = ReceivePacket.ScenarioInfo.AIPlayers;
- BuildLevel = ReceivePacket.ScenarioInfo.BuildLevel;
- Session.Options.UnitCount = ReceivePacket.ScenarioInfo.UnitCount;
- Seed = ReceivePacket.ScenarioInfo.Seed;
- Special = ReceivePacket.ScenarioInfo.Special;
- Options.GameSpeed = ReceivePacket.ScenarioInfo.GameSpeed;
- if (Session.Options.Tiberium) {
- Special.IsTGrowth = true;
- Rule.IsTGrowth = true;
- Special.IsTSpread = true;
- Rule.IsTSpread = true;
- } else {
- Special.IsTGrowth = false;
- Rule.IsTGrowth = false;
- Special.IsTSpread = false;
- Rule.IsTSpread = false;
- }
- //.........................................................
- // Adjust the gauges
- //.........................................................
- countgauge.Set_Maximum(
- SessionClass::CountMax[Session.Options.Bases] -
- SessionClass::CountMin[Session.Options.Bases]);
- countgauge.Set_Value(Session.Options.UnitCount -
- SessionClass::CountMin[Session.Options.Bases]);
- levelgauge.Set_Value(BuildLevel - 1);
- creditsgauge.Set_Value(Session.Options.Credits);
- aiplayersgauge.Set_Value(Session.Options.AIPlayers);
- //.........................................................
- // Update the options list box
- //.........................................................
- optionlist.Check_Item(0, Session.Options.Bases);
- optionlist.Check_Item(1, Session.Options.Tiberium);
- optionlist.Check_Item(2, Session.Options.Goodies);
- optionlist.Check_Item(3, Special.IsCaptureTheFlag);
- optionlist.Check_Item(4, Special.IsShadowGrow);
- optionlist.Flag_To_Redraw();
- /*
- ** If the scenario name changed then we need to redraw the whole lot.
- */
- if (strcmp (Session.Options.ScenarioDescription, ReceivePacket.ScenarioInfo.Scenario)) {
- if (display < REDRAW_BACKGROUND) display = REDRAW_BACKGROUND;
- }
- /*...............................................................
- Copy the information about the scenario that the host wants to
- play so ee can request this scenario from the host if we don't
- have it locally.
- ...............................................................*/
- strcpy (Session.Options.ScenarioDescription, ReceivePacket.ScenarioInfo.Scenario);
- strcpy (Session.ScenarioFileName, ReceivePacket.ScenarioInfo.ShortFileName);
- #ifdef WOLAPI_INTEGRATION
- strncpy (Session.ScenarioDigest, (char*)ReceivePacket.ScenarioInfo.FileDigest, sizeof( ReceivePacket.ScenarioInfo.FileDigest ));
- #else
- strcpy (Session.ScenarioDigest, (char*)ReceivePacket.ScenarioInfo.FileDigest);
- #endif
- Session.ScenarioIsOfficial = ReceivePacket.ScenarioInfo.OfficialScenario;
- Session.ScenarioFileLength = ReceivePacket.ScenarioInfo.FileLength;
- //.........................................................
- // "Clip" the other system's version range to our own
- // ........................................................
- version = VerNum.Clip_Version(ReceivePacket.ScenarioInfo.MinVersion,
- ReceivePacket.ScenarioInfo.MaxVersion);
- // ........................................................
- // If the greatest-common-version comes back 0, the other
- // system's range is too low for ours
- // ........................................................
- if (version == 0) {
- WWMessageBox().Process (TXT_DESTGAME_OUTDATED);
- // to skip the other system not responding msg
- lastmsgtime = TickCount;
- process = false;
- rc = false;
- } else if (version == 0xffffffff) {
- // ........................................................
- // If the greatest-common-version comes back 0xffffffff,
- // the other system's range is too high for ours
- // ........................................................
- WWMessageBox().Process (TXT_YOURGAME_OUTDATED);
- // to skip the other system not responding msg
- lastmsgtime = TickCount;
- process = false;
- rc = false;
- }
- // ........................................................
- // Otherwise, 'version' is the highest version we have in
- // common; look up the protocol that goes with this version.
- // ........................................................
- else {
- if (ReceivePacket.ScenarioInfo.CheatCheck != RuleINI.Get_Unique_ID()) {
- WWMessageBox().Process(TXT_MISMATCH);
- // to skip the other system not responding msg
- lastmsgtime = TickCount;
- process = false;
- rc = false;
- } else {
- Session.CommProtocol = VerNum.Version_Protocol(version);
- #ifndef FIXIT_VERSION_3
- PlayingAgainstVersion = version;
- #endif
- }
- }
- /*.........................................................
- If this is the first game-options packet we've received,
- init the game & player lists, then transmit our options
- to him.
- .........................................................*/
- if (first) {
- //......................................................
- // Add a string to the game list, and two to the player
- // list
- //......................................................
- item = new char [MPLAYER_NAME_MAX + 64];
- gamelist.Add_Item(item);
- item = new char [MPLAYER_NAME_MAX + 64]; //Need room to display country name
- playerlist.Add_Item(item,
- &ColorRemaps[(Session.ColorIdx == PCOLOR_DIALOG_BLUE) ?
- PCOLOR_REALLY_BLUE : Session.ColorIdx]);
- item = new char [MPLAYER_NAME_MAX + 64]; //Need room to display country name
- playerlist.Add_Item(item,
- &ColorRemaps[(TheirColor == PCOLOR_DIALOG_BLUE) ? PCOLOR_REALLY_BLUE : TheirColor]);
- first = false;
- transmit = true;
- transmittime = 0;
- }
- //.........................................................
- // Ensure the game list & player list have the latest,
- // greatest copy of our names & colors. Do this every time
- // we receive an options packet.
- //.........................................................
- item = (char *)gamelist.Get_Item(0);
- sprintf(item,Text_String(TXT_THATGUYS_GAME),
- TheirName);
- item = (char *)playerlist.Get_Item(0);
- #ifdef OLDWAY
- if (Session.House==HOUSE_GOOD) {
- sprintf(item,"%s\t%s",namebuf,
- Text_String(TXT_ALLIES));
- } else {
- sprintf(item,"%s\t%s",namebuf,
- Text_String(TXT_SOVIET));
- }
- #else //OLDWAY
- sprintf (item, "%s\t%s", namebuf, Text_String(HouseTypeClass::As_Reference(Session.House).Full_Name()));
- #endif //OLDWAY
- playerlist.Colors[0] = &ColorRemaps[(Session.ColorIdx == PCOLOR_DIALOG_BLUE) ?
- PCOLOR_REALLY_BLUE : Session.ColorIdx];
- item = (char *)playerlist.Get_Item(1);
- #ifdef OLDWAY
- if (TheirHouse==HOUSE_GOOD) {
- sprintf(item,"%s\t%s",TheirName,
- Text_String(TXT_ALLIES));
- } else {
- sprintf(item,"%s\t%s",TheirName,
- Text_String(TXT_SOVIET));
- }
- #else //OLDWAY
- sprintf (item, "%s\t%s", TheirName, Text_String(HouseTypeClass::As_Reference(TheirHouse).Full_Name()));
- #endif //OLDWAY
- playerlist.Colors[1] = &ColorRemaps[(TheirColor == PCOLOR_DIALOG_BLUE) ? PCOLOR_REALLY_BLUE : TheirColor];
- gamelist.Flag_To_Redraw();
- playerlist.Flag_To_Redraw();
- //.........................................................
- // Play a little sound effect
- //.........................................................
- Sound_Effect(VOC_OPTIONS_CHANGED);
- break;
- /*..................................................................
- GO: Exit this routine with a success code.
- ..................................................................*/
- case (SERIAL_LOADGAME):
- load_game = true;
- case (SERIAL_GO):
- ready_packet_was_sent = false;
- if (!load_game){
- /*
- ** Special new kludge for counterstrike.
- **
- ** Find local scenario will fail to match a counterstrike mission
- ** unless the CS CD is in the drive. So....
- **
- ** If Counterstrike is installed and this is an official map and
- ** the file name matches a counterstrike map then tell the host
- ** that I have the scenario so he can continue while we make
- ** sure the local user has the Counterstrike CD in the drive.
- **
- */
- // This is duplicated for Aftermath scenarios. ajw
- #ifdef FIXIT_CSII // checked - ajw 9/28/98
- if (Session.ScenarioIsOfficial &&
- ( (Expansion_CS_Present() && Is_Mission_Counterstrike(Session.ScenarioFileName)) ||
- (Expansion_AM_Present() && Is_Mission_Aftermath(Session.ScenarioFileName)) ) ) {
- #else
- if ( Expansion_CS_Present() && Session.ScenarioIsOfficial ) {
- #endif
- CCFileClass check_file ( Session.ScenarioFileName );
- if ( !check_file.Is_Available() ) {
- int current_drive = CCFileClass::Get_CD_Drive();
- #ifdef FIXIT_CSII // checked - ajw 9/28/98
- int index = Get_CD_Index(current_drive, 1*60);
- bool needcd = false;
- if (Is_Mission_Counterstrike(Session.ScenarioFileName)) {
- if (index != 2 && index != 3) {
- RequiredCD = 2;
- needcd = true;
- }
- }
- if (Is_Mission_Aftermath(Session.ScenarioFileName)) {
- if (index != 3) {
- RequiredCD = 3;
- needcd = true;
- }
- }
- if (needcd) {
- #else
- if ( Get_CD_Index(current_drive, 1*60) != 2 ){
- RequiredCD = 2;
- #endif
- #ifdef WIN32
- WWDebugString ("RA95 - Counterstrike CD is not in drive\n");
- #endif
- /*
- ** We should have the scenario but the wrong disk is in.
- ** Tell the host that I am ready to go anyway.
- */
- memset ((void*)&SendPacket, 0, sizeof (SendPacket));
- SendPacket.Command = SERIAL_READY_TO_GO;
- NullModem.Send_Message (&SendPacket, sizeof (SendPacket), 1);
- starttime = TickCount;
- while ( ( NullModem.Num_Send()
- && ((TickCount - starttime) < PACKET_SENDING_TIMEOUT) )
- || ((TickCount - starttime) < 60) ) {
- NullModem.Service();
- }
- ready_packet_was_sent = true;
- if (!Force_CD_Available (RequiredCD)){
- Emergency_Exit(EXIT_FAILURE);
- }
- /*
- ** Update the internal list of scenarios to include the counterstrike
- ** list.
- */
- Session.Read_Scenario_Descriptions();
- /*
- ** Make sure we dont time out because of the disk swap
- */
- lastmsgtime = TickCount;
- }
- }
- }
- /*
- ** If the scenario that the host wants to play doesnt exist locally then we
- ** need to request that it is sent. If we can identify the scenario locally then
- ** we need to fix up the file name so we load the right one.
- */
- if (Find_Local_Scenario (Session.Options.ScenarioDescription,
- Session.ScenarioFileName,
- Session.ScenarioFileLength,
- Session.ScenarioDigest,
- Session.ScenarioIsOfficial)) {
- /*
- ** We have the scenario. Tell the host that I am ready to go.
- */
- if (!ready_packet_was_sent) {
- memset ((void*)&SendPacket, 0, sizeof (SendPacket));
- SendPacket.Command = SERIAL_READY_TO_GO;
- NullModem.Send_Message (&SendPacket, sizeof (SendPacket), 1);
- starttime = TickCount;
- while ( ( NullModem.Num_Send()
- && ((TickCount - starttime) < PACKET_SENDING_TIMEOUT) )
- || ((TickCount - starttime) < 60) ) {
- NullModem.Service();
- }
- }
- } else {
- #ifndef FIXIT_VERSION_3 // Removed restriction on downloading official maps.
- /*
- ** Oh dear. Thats a scenario I dont have. Request that the host sends the
- ** scenario to me provided it isnt an official Westwood scenario.
- **
- ** If the file is received OK then we will get a true return value and the
- ** actual file name to load will be in Session.ScenarioFileName
- */
- if (Session.ScenarioIsOfficial) {
- /*
- ** We dont have the scenario and we dont want to request that it gets
- ** sent because its an official one.
- ** Print up a message saying we cant play this scenario and reply to the
- ** host, telling him to select another.
- */
- memset ((void*)&SendPacket, 0, sizeof (SendPacket));
- SendPacket.Command = SERIAL_NO_SCENARIO;
- NullModem.Send_Message (&SendPacket, sizeof (SendPacket), 1);
- NullModem.Service();
- WWMessageBox().Process (TXT_UNABLE_PLAY_WAAUGH);
- display = REDRAW_ALL;
- lastmsgtime = TickCount;
- break;
- } else {
- #endif
- #ifdef FIXIT_VERSION_3
- if( bSpecialAftermathScenario( Session.Options.ScenarioDescription ) )
- break;
- #endif
- if (!Get_Scenario_File_From_Host(Session.ScenarioFileName, 0)) {
- rc = false;
- break;
- } else {
- /*
- ** Make sure we dont time-out because of the download
- */
- lastmsgtime = TickCount;
- }
- #ifndef FIXIT_VERSION_3
- }
- #endif
- }
- }else{
- /*
- ** Make sure we respond to the host in a load game
- */
- memset ((void*)&SendPacket, 0, sizeof (SendPacket));
- SendPacket.Command = SERIAL_READY_TO_GO;
- NullModem.Send_Message (&SendPacket, sizeof (SendPacket), 1);
- starttime = TickCount;
- while ( ( NullModem.Num_Send()
- && ((TickCount - starttime) < PACKET_SENDING_TIMEOUT) )
- || ((TickCount - starttime) < 60) ) {
- NullModem.Service();
- }
- }
- /*
- ** Fall through here...
- */
- strcpy (Scen.ScenarioName, Session.ScenarioFileName);
- //
- // calculated one way delay for a packet and overall delay
- // to execute a packet
- //
- if (Session.CommProtocol == COMM_PROTOCOL_MULTI_E_COMP) {
- Session.MaxAhead = max( ((((ReceivePacket.ScenarioInfo.ResponseTime / 8) +
- (Session.FrameSendRate - 1)) / Session.FrameSendRate) *
- Session.FrameSendRate), (Session.FrameSendRate * 2) );
- } else {
- Session.MaxAhead = max( (ReceivePacket.ScenarioInfo.ResponseTime / 8),
- MODEM_MIN_MAX_AHEAD );
- }
- process = false;
- rc = true;
- if (ReceivePacket.Command == SERIAL_LOADGAME)
- load_game = true;
- break;
- /*..................................................................
- Incoming message: add to our list
- ..................................................................*/
- case (SERIAL_MESSAGE):
- oppscorescreen = false;
- Session.Messages.Add_Message (ReceivePacket.Name,
- ((PlayerColorType)ReceivePacket.ID == PCOLOR_DIALOG_BLUE) ?
- PCOLOR_REALLY_BLUE : (PlayerColorType)ReceivePacket.ID,
- ReceivePacket.Message.Message,
- ((PlayerColorType)ReceivePacket.ID == PCOLOR_DIALOG_BLUE) ?
- PCOLOR_REALLY_BLUE : (PlayerColorType)ReceivePacket.ID,
- TPF_TEXT, -1);
- Sound_Effect(VOC_INCOMING_MESSAGE);
- if (display < REDRAW_MESSAGE) display = REDRAW_MESSAGE;
- break;
- //
- // throw away timing packet
- //
- case (SERIAL_TIMING):
- oppscorescreen = false;
- break;
- //
- // print msg waiting for opponent
- //
- case (SERIAL_SCORE_SCREEN):
- oppscorescreen = true;
- if (display < REDRAW_MESSAGE) display = REDRAW_MESSAGE;
- parms_received = true;
- break;
- default:
- break;
- }
- }
- }
- // if we haven't received a msg for 10 seconds exit
- if ((TickCount - lastmsgtime) > msg_timeout) {
- WWMessageBox().Process (TXT_SYSTEM_NOT_RESPONDING);
- process = false;
- rc = false;
- // say we did receive sign off to keep from sending one
- recsignedoff = true;
- }
- /*---------------------------------------------------------------------
- Service the connection
- ---------------------------------------------------------------------*/
- NullModem.Service();
- }
- /*------------------------------------------------------------------------
- Prepare to load the scenario
- ------------------------------------------------------------------------*/
- if (rc) {
- Session.NumPlayers = 2;
- /*.....................................................................
- Add both players to the Players vector; the local system is always
- index 0.
- .....................................................................*/
- who = new NodeNameType;
- #ifdef FIXIT_MODEM_LOAD_CRASH
- /* If the names of the players are the same then we MUST force them
- * be be unique. This is necessary to prevent a crash after loading
- * a modem save game.
- */
- if (strcmp(TheirName, namebuf) == 0)
- {
- if (strlen(TheirName) == (MPLAYER_NAME_MAX - 1))
- {
- namebuf[MPLAYER_NAME_MAX - 1] = '\0';
- }
- else
- {
- strcat(namebuf, "2");
- }
- }
- #endif
- strcpy(who->Name, namebuf);
- who->Player.House = Session.House;
- who->Player.Color = Session.ColorIdx;
- who->Player.ProcessTime = -1;
- Session.Players.Add (who);
- who = new NodeNameType;
- strcpy(who->Name, TheirName);
- who->Player.House = TheirHouse;
- who->Player.Color = TheirColor;
- who->Player.ProcessTime = -1;
- Session.Players.Add (who);
- starttime = TickCount;
- while ( ( NullModem.Num_Send()
- && ((TickCount - starttime) < PACKET_SENDING_TIMEOUT) )
- || ((TickCount - starttime) < 60) ) {
- #if(SHOW_MONO)
- NullModem.Mono_Debug_Print(0);
- #endif
- NullModem.Service();
- }
- // clear queue to keep from doing any resends
- NullModem.Init_Send_Queue();
- } else {
- if ( !recsignedoff ) {
- /*.....................................................................
- Broadcast my sign-off over my network
- .....................................................................*/
- memset (&SendPacket, 0, sizeof(SerialPacketType));
- SendPacket.Command = SERIAL_SIGN_OFF;
- SendPacket.ScenarioInfo.Color = Session.ColorIdx; // use Color for ID
- SendPacket.ID = Session.ModemType;
- NullModem.Send_Message (&SendPacket, sizeof(SendPacket), 1);
- starttime = TickCount;
- while ( (NullModem.Num_Send()
- && ((TickCount - starttime) < PACKET_CANCEL_TIMEOUT) )
- || ((TickCount - starttime) < 60) ) {
- #if(SHOW_MONO)
- NullModem.Mono_Debug_Print(0);
- #endif
- if ( NullModem.Get_Message( &ReceivePacket, &packetlen ) > 0) {
- // are we getting our own packets back??
- if (ReceivePacket.Command == SERIAL_SIGN_OFF
- && ReceivePacket.ID == Session.ModemType) {
- // exit while
- break;
- }
- }
- NullModem.Service();
- }
- }
- Shutdown_Modem();
- }
- /*------------------------------------------------------------------------
- Clean up the list boxes
- ------------------------------------------------------------------------*/
- // while (optionlist.Count()>0) {
- // item = (char *)optionlist.Get_Item(0);
- // delete [] item;
- // optionlist.Remove_Item(item);
- // }
- while (gamelist.Count()>0) {
- item = (char *)gamelist.Get_Item(0);
- delete [] item;
- gamelist.Remove_Item(item);
- }
- while (playerlist.Count()>0) {
- item = (char *)playerlist.Get_Item(0);
- delete [] item;
- playerlist.Remove_Item(item);
- }
- /*------------------------------------------------------------------------
- Remove the chat edit box
- ------------------------------------------------------------------------*/
- Session.Messages.Remove_Edit();
- /*------------------------------------------------------------------------
- Restore screen
- ------------------------------------------------------------------------*/
- Hide_Mouse();
- Load_Title_Page(true);
- //#ifdef WIN32
- // Load_Uncompress(CCFileClass("TITLE.CPS"), SysMemPage, SysMemPage, CCPalette);
- // SysMemPage.Scale(SeenPage);
- //#else
- // Load_Uncompress(CCFileClass("TITLE.CPS"), HidPage, HidPage, CCPalette);
- // HidPage.Blit(SeenPage);
- //#endif
- Show_Mouse();
- /*------------------------------------------------------------------------
- Save any changes made to our options
- ------------------------------------------------------------------------*/
- if (changed) {
- Session.Write_MultiPlayer_Settings ();
- }
- if (load_game) {
- if (!Load_Game (-1)) {
- WWMessageBox().Process (TXT_ERROR_LOADING_GAME);
- rc = false;
- }
- Frame++;
- }
- return(rc);
- } /* end of Com_Show_Scenario_Dialog */
- /***************************************************************************
- * Phone_Dialog -- Lets user edit phone directory & dial *
- * *
- * INPUT: *
- * none. *
- * *
- * OUTPUT: *
- * true = dial the current phone book entry, false = cancel. *
- * *
- * WARNINGS: *
- * Serial options must have been read from CC.INI. *
- * *
- * HISTORY: *
- * 04/29/1995 BRR : Created. *
- *=========================================================================*/
- static int Phone_Dialog (void)
- {
- /*........................................................................
- Dialog & button dimensions
- ........................................................................*/
- int d_dialog_w = 280 * RESFACTOR; // dialog width
- int d_dialog_h = 160 * RESFACTOR; // dialog height
- int d_dialog_x = ((320 * RESFACTOR - d_dialog_w) / 2); // dialog x-coord
- int d_dialog_y = ((200 * RESFACTOR - d_dialog_h) / 2); // dialog y-coord
- int d_dialog_cx = d_dialog_x + (d_dialog_w / 2); // center x-coord
- int d_txt6_h = 7 * RESFACTOR; // ht of 6-pt text
- int d_margin = 7 * RESFACTOR; // margin width/height
- int d_phonelist_w = 248 * RESFACTOR;
- int d_phonelist_h = 87 * RESFACTOR;
- int d_phonelist_x = d_dialog_cx - (d_phonelist_w / 2);
- int d_phonelist_y = d_dialog_y + d_margin + d_txt6_h + 11 * RESFACTOR;
- int d_add_w = 45 * RESFACTOR;
- int d_add_h = 9 * RESFACTOR;
- int d_add_x = d_dialog_cx - (d_add_w / 2) - d_margin - d_add_w;
- int d_add_y = d_phonelist_y + d_phonelist_h + d_margin;
- int d_edit_w = 45 * RESFACTOR;
- int d_edit_h = 9 * RESFACTOR;
- int d_edit_x = d_dialog_cx - (d_edit_w / 2);
- int d_edit_y = d_phonelist_y + d_phonelist_h + d_margin;
- int d_delete_w = 45 * RESFACTOR;
- int d_delete_h = 9 * RESFACTOR;
- int d_delete_x = d_dialog_cx + (d_delete_w / 2) + d_margin;
- int d_delete_y = d_phonelist_y + d_phonelist_h + d_margin;
- int d_numedit_w = ( (PhoneEntryClass::PHONE_MAX_NUM - 1) * 6) * RESFACTOR + 3 * RESFACTOR;
- int d_numedit_h = 9 * RESFACTOR;
- int d_numedit_x = d_dialog_cx - (d_numedit_w / 2);
- int d_numedit_y = d_add_y + d_add_h + d_margin;
- int d_dial_w = 45 * RESFACTOR;
- int d_dial_h = 9 * RESFACTOR;
- int d_dial_x = d_dialog_cx - (d_numedit_w / 2) - d_margin - d_dial_w;
- int d_dial_y = d_add_y + d_add_h + d_margin;
- int d_cancel_w = 45 * RESFACTOR;
- int d_cancel_h = 9 * RESFACTOR;
- int d_cancel_x = d_dialog_cx + (d_numedit_w / 2) + d_margin;
- int d_cancel_y = d_add_y + d_add_h + d_margin;
- /*........................................................................
- Button Enumerations
- ........................................................................*/
- enum {
- BUTTON_PHONELIST = 100,
- BUTTON_ADD,
- BUTTON_EDIT,
- BUTTON_DELETE,
- BUTTON_DIAL,
- BUTTON_CANCEL,
- BUTTON_NUMEDIT,
- };
- /*........................................................................
- Redraw values: in order from "top" to "bottom" layer of the dialog
- ........................................................................*/
- typedef enum {
- REDRAW_NONE = 0,
- REDRAW_BUTTONS,
- REDRAW_BACKGROUND,
- REDRAW_ALL = REDRAW_BACKGROUND
- } RedrawType;
- /*........................................................................
- Dialog variables
- ........................................................................*/
- RedrawType display = REDRAW_ALL; // redraw level
- bool process = true; // process while true
- KeyNumType input;
- char phone_num[ PhoneEntryClass::PHONE_MAX_NUM ] = { 0 }; // buffer for editing phone #
- int rc;
- int i;
- int tabs[] = {123*RESFACTOR, 207*RESFACTOR}; // tabs for list box
- char *item; // for removing items from list box
- PhoneEntryClass *p_entry; // for creating / editing phonebook entries
- bool changed = false; // 1 = save changes to INI file
- bool firsttime = false;
- /*........................................................................
- Buttons
- ........................................................................*/
- GadgetClass *commands; // button list
- 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"));
- TextButtonClass addbtn(BUTTON_ADD, TXT_ADD, TPF_BUTTON, d_add_x, d_add_y, d_add_w, d_add_h);
- TextButtonClass editbtn(BUTTON_EDIT, TXT_EDIT, TPF_BUTTON, d_edit_x, d_edit_y, d_edit_w, d_edit_h);
- TextButtonClass deletebtn(BUTTON_DELETE, TXT_DELETE_BUTTON, TPF_BUTTON, d_delete_x, d_delete_y, d_delete_w, d_delete_h);
- TextButtonClass dialbtn(BUTTON_DIAL, TXT_DIAL, TPF_BUTTON, d_dial_x, d_dial_y, d_dial_w, d_dial_h);
- TextButtonClass cancelbtn(BUTTON_CANCEL, TXT_CANCEL, TPF_BUTTON, d_cancel_x, d_cancel_y, d_cancel_w, d_cancel_h);
- 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);
- /*
- ------------------------- Build the button list --------------------------
- */
- commands = &phonelist;
- addbtn.Add_Tail(*commands);
- editbtn.Add_Tail(*commands);
- deletebtn.Add_Tail(*commands);
- dialbtn.Add_Tail(*commands);
- cancelbtn.Add_Tail(*commands);
- numedit.Add_Tail(*commands);
- dialbtn.Turn_On();
- /*
- ----------------------------- Various Inits ------------------------------
- */
- /*........................................................................
- Fill in the phone directory list box
- ........................................................................*/
- phonelist.Set_Tabs(tabs);
- Build_Phone_Listbox(&phonelist, &numedit, phone_num);
- if (Session.CurPhoneIdx == -1) {
- firsttime = true;
- }
- /*
- ---------------------------- Processing loop -----------------------------
- */
- while (process) {
- /*
- ........................ Invoke game callback .........................
- */
- Call_Back();
- #ifdef WIN32
- /*
- ** If we have just received input focus again after running in the background then
- ** we need to redraw.
- */
- if (AllSurfaces.SurfacesRestored) {
- AllSurfaces.SurfacesRestored=FALSE;
- display = REDRAW_ALL;
- }
- #endif
- /*
- ...................... Refresh display if needed ......................
- */
- if (display) {
- Hide_Mouse();
- /*
- .................. Redraw backgound & dialog box ...................
- */
- if (display >= REDRAW_BACKGROUND) {
- Load_Title_Page(true);
- CCPalette.Set();
- Dialog_Box(d_dialog_x, d_dialog_y, d_dialog_w, d_dialog_h);
- // init font variables
- Fancy_Text_Print(TXT_NONE, 0, 0, TBLACK, TBLACK, TPF_CENTER | TPF_TEXT);
- /*...............................................................
- Dialog & Field labels
- ...............................................................*/
- Draw_Caption (TXT_PHONE_LIST, d_dialog_x, d_dialog_y, d_dialog_w);
- phonelist.Draw_Me (true);
- }
- /*
- .......................... Redraw buttons ..........................
- */
- if (display >= REDRAW_BUTTONS) {
- addbtn.Flag_To_Redraw();
- editbtn.Flag_To_Redraw();
- deletebtn.Flag_To_Redraw();
- dialbtn.Flag_To_Redraw();
- cancelbtn.Flag_To_Redraw();
- numedit.Flag_To_Redraw();
- }
- Show_Mouse();
- display = REDRAW_NONE;
- }
- /*
- ........................... Get user input ............................
- */
- input = commands->Input();
- if ( firsttime ) {
- numedit.Set_Focus();
- numedit.Flag_To_Redraw();
- input = commands->Input();
- firsttime = false;
- }
- /*
- ---------------------------- Process input ----------------------------
- */
- switch (input) {
- /*------------------------------------------------------------------
- New phone listing selected.
- ------------------------------------------------------------------*/
- case (BUTTON_PHONELIST | KN_BUTTON):
- /*...............................................................
- Detect a change in the selected item; update CurPhoneIdx, and
- the edit box buffer.
- ...............................................................*/
- #ifdef FIXIT_PHONELIST_CRASH
- if (Session.CurPhoneIdx != -1) {
- #endif
- if (phonelist.Current_Index() != Session.CurPhoneIdx) {
- Session.CurPhoneIdx = phonelist.Current_Index();
- strcpy (phone_num, Session.PhoneBook[Session.CurPhoneIdx]->Number);
- numedit.Set_Text (phone_num, PhoneEntryClass::PHONE_MAX_NUM );
- changed = true;
- }
- #ifdef FIXIT_PHONELIST_CRASH
- }
- #endif
- break;
- /*------------------------------------------------------------------
- Add a new entry
- ------------------------------------------------------------------*/
- case (BUTTON_ADD | KN_BUTTON):
- /*...............................................................
- Allocate a new phone book entry
- ...............................................................*/
- p_entry = new PhoneEntryClass();
- p_entry->Name[0] = 0;
- p_entry->Number[0] = 0;
- p_entry->Settings.Port = 0;
- p_entry->Settings.IRQ = -1;
- p_entry->Settings.Baud = -1;
- p_entry->Settings.DialMethod = DIAL_TOUCH_TONE;
- p_entry->Settings.InitStringIndex = 0;
- p_entry->Settings.CallWaitStringIndex = CALL_WAIT_CUSTOM;
- p_entry->Settings.CallWaitString[0] = 0;
- /*...............................................................
- Invoke the entry editor; if user clicks Save, add the new entry
- to the list, and rebuild the list box.
- ...............................................................*/
- if ( Edit_Phone_Dialog( p_entry ) ) {
- Session.PhoneBook.Add (p_entry);
- Build_Phone_Listbox( &phonelist, &numedit, phone_num );
- /*............................................................
- Set the current listbox index to the newly-added item.
- ............................................................*/
- for (i = 0; i < Session.PhoneBook.Count(); i++) {
- if (p_entry == Session.PhoneBook[i]) {
- Session.CurPhoneIdx = i;
- strcpy (phone_num, Session.PhoneBook[Session.CurPhoneIdx]->Number);
- numedit.Set_Text (phone_num, PhoneEntryClass::PHONE_MAX_NUM );
- phonelist.Set_Selected_Index( Session.CurPhoneIdx );
- }
- }
- changed = true;
- } else {
- /*...............................................................
- If the user clicked Cancel, delete the entry & keep looping.
- ...............................................................*/
- delete p_entry;
- }
- display = REDRAW_ALL;
- break;
- /*------------------------------------------------------------------
- Edit the current entry
- ------------------------------------------------------------------*/
- case (BUTTON_EDIT | KN_BUTTON):
- /*...............................................................
- Do nothing if no entry is selected.
- ...............................................................*/
- if (Session.CurPhoneIdx==-1)
- break;
- /*...............................................................
- Allocate a new entry & copy the currently-selected entry into it
- ...............................................................*/
- p_entry = new PhoneEntryClass();
- (*p_entry) = (*Session.PhoneBook[Session.CurPhoneIdx]);
- /*...............................................................
- Pass the new entry to the entry editor; if the user selects OK,
- copy the data back into our phone book. Rebuild the list so
- the changes show up in the list box.
- ...............................................................*/
- if ( Edit_Phone_Dialog( p_entry ) ) {
- (*Session.PhoneBook[Session.CurPhoneIdx]) = (*p_entry);
- Build_Phone_Listbox(&phonelist, &numedit, phone_num);
- /*............................................................
- Set the current listbox index to the newly-added item.
- ............................................................*/
- for (i = 0; i < Session.PhoneBook.Count(); i++) {
- if (Session.PhoneBook[Session.CurPhoneIdx] == Session.PhoneBook[i]) {
- Session.CurPhoneIdx = i;
- strcpy (phone_num, Session.PhoneBook[Session.CurPhoneIdx]->Number);
- numedit.Set_Text (phone_num, PhoneEntryClass::PHONE_MAX_NUM );
- phonelist.Set_Selected_Index( Session.CurPhoneIdx );
- }
- }
- changed = true;
- }
- delete p_entry;
- display = REDRAW_ALL;
- break;
- /*------------------------------------------------------------------
- Delete the current entry
- ------------------------------------------------------------------*/
- case (BUTTON_DELETE | KN_BUTTON):
- /*...............................................................
- Do nothing if no entry is selected.
- ...............................................................*/
- if (Session.CurPhoneIdx == -1)
- break;
- /*...............................................................
- Delete the current item & rebuild the phone listbox
- ...............................................................*/
- Session.PhoneBook.Delete (Session.CurPhoneIdx);
- Build_Phone_Listbox(&phonelist, &numedit, phone_num);
- if (Session.CurPhoneIdx == -1) {
- *phone_num = 0;
- numedit.Set_Text (phone_num, PhoneEntryClass::PHONE_MAX_NUM );
- }
- changed = true;
- break;
- /*------------------------------------------------------------------
- Dial the current number
- ------------------------------------------------------------------*/
- case (KN_RETURN):
- dialbtn.IsPressed = true;
- dialbtn.Draw_Me(true);
- // fall thru
- case (BUTTON_DIAL | KN_BUTTON):
- /*...............................................................
- If no item is selected, just dial the number in the phone #
- edit box:
- - Create a new phone entry
- - Copy the phone number into it
- - Set settings to defaults
- ...............................................................*/
- if (Session.CurPhoneIdx == -1 ||
- strcmp( Session.PhoneBook[Session.CurPhoneIdx]->Number, phone_num) ) {
- if ( strlen(phone_num) == 0) { // do not dial
- dialbtn.IsPressed = true;
- dialbtn.Flag_To_Redraw();
- break;
- }
- p_entry = new PhoneEntryClass();
- strcpy( p_entry->Name, "NONAME" );
- strcpy( p_entry->Number, phone_num);
- p_entry->Settings.Port = 0;
- p_entry->Settings.IRQ = -1;
- p_entry->Settings.Baud = -1;
- p_entry->Settings.DialMethod = DIAL_TOUCH_TONE;
- p_entry->Settings.InitStringIndex = 0;
- p_entry->Settings.CallWaitStringIndex = CALL_WAIT_CUSTOM;
- p_entry->Settings.CallWaitString[0] = 0;
- Session.PhoneBook.Add (p_entry);
- Build_Phone_Listbox(&phonelist, &numedit, phone_num);
- /*............................................................
- Set the current listbox index to the newly-added item.
- ............................................................*/
- for (i = 0; i < Session.PhoneBook.Count(); i++) {
- if (p_entry == Session.PhoneBook[i]) {
- Session.CurPhoneIdx = i;
- }
- }
- changed = true;
- }
- process = false;
- rc = true;
- break;
- /*------------------------------------------------------------------
- CANCEL: bail out
- ------------------------------------------------------------------*/
- case (KN_ESC):
- case (BUTTON_CANCEL | KN_BUTTON):
- process = false;
- rc = false;
- break;
- }
- } /* end of while */
- /*------------------------------------------------------------------------
- Save any changes we've made to the phone list or settings
- ------------------------------------------------------------------------*/
- if (changed) {
- Session.Write_MultiPlayer_Settings ();
- }
- /*------------------------------------------------------------------------
- Clear the list box
- ------------------------------------------------------------------------*/
- while (phonelist.Count()) {
- item = (char *)phonelist.Get_Item(0);
- phonelist.Remove_Item(item);
- delete [] item;
- }
- return(rc);
- } /* end of Phone_Dialog */
- /***************************************************************************
- * Build_Phone_Listbox -- [re]builds the phone entry listbox *
- * *
- * This routine rebuilds the phone list box from scratch; it also updates *
- * the contents of the phone # edit field. *
- * *
- * INPUT: *
- * list ptr to list box *
- * edit ptr to edit box *
- * buf ptr to buffer for phone # *
- * *
- * OUTPUT: *
- * none. *
- * *
- * WARNINGS: *
- * none. *
- * *
- * HISTORY: *
- * 04/29/1995 BRR : Created. *
- *=========================================================================*/
- static void Build_Phone_Listbox (ListClass *list, EditClass *edit, char *buf)
- {
- int i;
- char *item;
- char phonename[21];
- char phonenum[15];
- /*........................................................................
- Clear the list
- ........................................................................*/
- while (list->Count()) {
- item = (char *)(list->Get_Item(0));
- list->Remove_Item(item);
- delete [] item;
- }
- /*
- ** Now sort the phone list by name then number
- */
- qsort ((void *)(&Session.PhoneBook[0]), Session.PhoneBook.Count(), sizeof(class PhoneEntryClass *), Phone_Compare);
- /*........................................................................
- Build the list
- ........................................................................*/
- for (i = 0; i < Session.PhoneBook.Count(); i++) {
- item = new char[80];
- if ( !(strlen( Session.PhoneBook[i]->Name )) ) {
- strcpy( phonename, " " );
- } else {
- strncpy( phonename, Session.PhoneBook[i]->Name, 20 );
- phonename[21] = 0;
- }
- if ( !(strlen( Session.PhoneBook[i]->Number )) ) {
- strcpy( phonenum, " " );
- } else {
- if ( strlen( Session.PhoneBook[i]->Number ) < 14) {
- strcpy( phonenum, Session.PhoneBook[i]->Number );
- } else {
- strncpy( phonenum, Session.PhoneBook[i]->Number, 12 );
- phonenum[12] = 0;
- strcat( phonenum, "..." );
- }
- }
- if (Session.PhoneBook[i]->Settings.Baud != -1) {
- sprintf(item,"%s\t%s\t%d", phonename, phonenum,
- Session.PhoneBook[i]->Settings.Baud);
- } else {
- sprintf(item,"%s\t%s\t[%s]", phonename, phonenum,
- Text_String(TXT_DEFAULT));
- }
- list->Add_Item(item);
- }
- list->Flag_To_Redraw();
- /*........................................................................
- Init the current phone book index
- ........................................................................*/
- if (list->Count() == 0 || Session.CurPhoneIdx < -1) {
- Session.CurPhoneIdx = -1;
- } else {
- if (Session.CurPhoneIdx >= list->Count() ) {
- Session.CurPhoneIdx = 0;
- }
- }
- /*........................................................................
- Fill in phone number edit buffer
- ........................................................................*/
- if (Session.CurPhoneIdx > -1) {
- strcpy (buf, Session.PhoneBook[Session.CurPhoneIdx]->Number);
- edit->Set_Text (buf, PhoneEntryClass::PHONE_MAX_NUM );
- list->Set_Selected_Index( Session.CurPhoneIdx );
- }
- }
- /***************************************************************************
- * Phone_Compare -- for qsort *
- * *
- * INPUT: *
- * p1,p2 ptrs to elements to compare *
- * *
- * OUTPUT: *
- * 0 = same, -1 = (*p1) goes BEFORE (*p2), 1 = (*p1) goes AFTER (*p2) *
- * *
- * WARNINGS: *
- * none. *
- * *
- * HISTORY: *
- * 02/14/1995 BR : Created. *
- *=========================================================================*/
- static int Phone_Compare (const void *p1, const void *p2)
- {
- class PhoneEntryClass *pe1,*pe2;
- int result;
- pe1 = *((class PhoneEntryClass **)p1);
- pe2 = *((class PhoneEntryClass **)p2);
- result = strcmp( pe1->Name, pe2->Name );
- // if strings are equal then check the phone number
- if ( !result ) {
- result = strcmp( pe1->Number, pe2->Number );
- }
- return(result);
- }
- /***************************************************************************
- * Edit_Phone_Dialog -- lets user edit a phone book entry *
- * *
- * INPUT: *
- * phone entry to edit *
- * *
- * OUTPUT: *
- * true = OK, false = cancel *
- * *
- * WARNINGS: *
- * none. *
- * *
- * HISTORY: *
- * 04/29/1995 BRR : Created. *
- *=========================================================================*/
- static int Edit_Phone_Dialog (PhoneEntryClass *phone)
- {
- /*........................................................................
- Dialog & button dimensions
- ........................................................................*/
- int d_dialog_w = 230 * RESFACTOR; // dialog width
- int d_dialog_h = 110 * RESFACTOR; // dialog height
- int d_dialog_x = ((320 * RESFACTOR - d_dialog_w) / 2); // dialog x-coord
- int d_dialog_y = ((136 * RESFACTOR - d_dialog_h) / 2); // dialog y-coord
- int d_dialog_cx = d_dialog_x + (d_dialog_w / 2); // center x-coord
- int d_txt6_h = 7 * RESFACTOR; // ht of 6-pt text
- int d_margin = 7 * RESFACTOR; // margin width/height
- int d_name_w = ( (PhoneEntryClass::PHONE_MAX_NAME - 1) * 6) * RESFACTOR + 3 * RESFACTOR;
- int d_name_h = 9 * RESFACTOR;
- int d_name_x = d_dialog_x + (((d_dialog_w - d_name_w) * 3) / 4) - 5 * RESFACTOR;
- int d_name_y = d_dialog_y + 25 * RESFACTOR;
- int d_number_w = ( (PhoneEntryClass::PHONE_MAX_NUM - 1) * 6) * RESFACTOR + 3 * RESFACTOR;
- int d_number_h = 9 * RESFACTOR;
- int d_number_x = d_dialog_x + (((d_dialog_w - d_number_w) * 3) / 4) - 5 * RESFACTOR;
- int d_number_y = d_name_y + d_name_h + d_margin;
- int d_default_w = 130 * RESFACTOR;
- int d_default_h = 9 * RESFACTOR;
- int d_default_x = d_dialog_cx - (d_default_w / 2);
- int d_default_y = d_number_y + d_number_h + d_margin;
- int d_custom_w = 130 * RESFACTOR;
- int d_custom_h = 9 * RESFACTOR;
- int d_custom_x = d_dialog_cx - (d_default_w / 2);
- int d_custom_y = d_default_y + d_default_h + d_margin;
- int d_save_w = 55 * RESFACTOR;
- int d_save_h = 9 * RESFACTOR;
- int d_save_x = d_dialog_cx - d_margin - d_save_w;
- int d_save_y = d_dialog_y + d_dialog_h - d_margin - d_save_h - 5*RESFACTOR;
- int d_cancel_w = 55 * RESFACTOR;
- int d_cancel_h = 9 * RESFACTOR;
- int d_cancel_x = d_dialog_cx + d_margin;
- int d_cancel_y = d_dialog_y + d_dialog_h - d_margin - d_cancel_h - 5*RESFACTOR;
- /*........................................................................
- Button Enumerations
- ........................................................................*/
- enum {
- BUTTON_NAME = 100,
- BUTTON_NUMBER,
- BUTTON_DEFAULT,
- BUTTON_CUSTOM,
- BUTTON_SAVE,
- BUTTON_CANCEL,
- };
- /*........................................................................
- Redraw values: in order from "top" to "bottom" layer of the dialog
- ........................................................................*/
- typedef enum {
- REDRAW_NONE = 0,
- REDRAW_BUTTONS,
- REDRAW_BACKGROUND,
- REDRAW_ALL = REDRAW_BACKGROUND
- } RedrawType;
- /*........................................................................
- Dialog variables
- ........................................................................*/
- RedrawType display = REDRAW_ALL; // redraw level
- char namebuf[PhoneEntryClass::PHONE_MAX_NAME] = { 0 }; // buffer for editing name
- char numbuf[PhoneEntryClass::PHONE_MAX_NUM] = { 0 }; // buffer for editing phone #
- int rc;
- SerialSettingsType settings;
- bool custom = false;
- bool firsttime = true;
- RemapControlType * scheme = GadgetClass::Get_Color_Scheme();
- /*........................................................................
- Buttons
- ........................................................................*/
- GadgetClass *commands; // button list
- 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);
- 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);
- TextButtonClass defaultbtn(BUTTON_DEFAULT, TXT_DEFAULT_SETTINGS, TPF_BUTTON, d_default_x, d_default_y, d_default_w, d_default_h);
- TextButtonClass custombtn(BUTTON_CUSTOM, TXT_CUSTOM_SETTINGS, TPF_BUTTON, d_custom_x, d_custom_y, d_custom_w, d_custom_h);
- TextButtonClass savebtn(BUTTON_SAVE, TXT_SAVE_BUTTON, TPF_BUTTON, d_save_x, d_save_y, d_save_w, d_save_h);
- TextButtonClass cancelbtn(BUTTON_CANCEL, TXT_CANCEL, TPF_BUTTON, d_cancel_x, d_cancel_y, d_cancel_w, d_cancel_h);
- /*
- ------------------------- Build the button list --------------------------
- */
- commands = &nameedit;
- numedit.Add_Tail(*commands);
- defaultbtn.Add_Tail(*commands);
- custombtn.Add_Tail(*commands);
- savebtn.Add_Tail(*commands);
- cancelbtn.Add_Tail(*commands);
- /*
- ----------------------------- Various Inits ------------------------------
- */
- /*........................................................................
- Init the settings; if the phone entry is set to use defaults, init our
- settings to sensible values (in case we invoke the setting editor);
- otherwise, copy the entry's settings.
- ........................................................................*/
- if (phone->Settings.Port == 0 || phone->Settings.IRQ == -1 ||
- phone->Settings.Baud == -1) {
- settings = Session.SerialDefaults;
- defaultbtn.Turn_On();
- custom = false;
- } else {
- settings = phone->Settings;
- custombtn.Turn_On();
- custom = true;
- }
- strcpy (namebuf, phone->Name);
- nameedit.Set_Text (namebuf, PhoneEntryClass::PHONE_MAX_NAME);
- strcpy (numbuf, phone->Number);
- numedit.Set_Text (numbuf, PhoneEntryClass::PHONE_MAX_NUM);
- /*
- ---------------------------- Processing loop -----------------------------
- */
- bool process = true; // process while true
- while (process) {
- /*
- ........................ Invoke game callback .........................
- */
- Call_Back();
- #ifdef WIN32
- /*
- ** If we have just received input focus again after running in the background then
- ** we need to redraw.
- */
- if (AllSurfaces.SurfacesRestored) {
- AllSurfaces.SurfacesRestored=FALSE;
- display = REDRAW_ALL;
- }
- #endif
- /*
- ...................... Refresh display if needed ......................
- */
- if (display) {
- Hide_Mouse();
- /*
- .................. Redraw backgound & dialog box ...................
- */
- if (display >= REDRAW_BACKGROUND) {
- Load_Title_Page(true);
- CCPalette.Set();
- Dialog_Box(d_dialog_x, d_dialog_y, d_dialog_w, d_dialog_h);
- Draw_Caption (TXT_PHONE_LISTING, d_dialog_x, d_dialog_y, d_dialog_w);
- /*...............................................................
- Dialog & Field labels
- ...............................................................*/
- Fancy_Text_Print (TXT_NAME_COLON, d_name_x - 5 * RESFACTOR, d_name_y + 1 * RESFACTOR, scheme, TBLACK, TPF_RIGHT | TPF_TEXT);
- Fancy_Text_Print (TXT_NUMBER_COLON, d_number_x - 5 * RESFACTOR, d_number_y + 1 * RESFACTOR, scheme, TBLACK, TPF_RIGHT | TPF_TEXT);
- }
- /*
- .......................... Redraw buttons ..........................
- */
- if (display >= REDRAW_BUTTONS) {
- commands->Flag_List_To_Redraw();
- }
- Show_Mouse();
- display = REDRAW_NONE;
- }
- /*
- ........................... Get user input ............................
- */
- KeyNumType input = commands->Input();
- if ( firsttime ) {
- nameedit.Set_Focus();
- nameedit.Flag_To_Redraw();
- input = commands->Input();
- firsttime = false;
- }
- /*
- ---------------------------- Process input ----------------------------
- */
- switch (input) {
- case (BUTTON_NAME | KN_BUTTON):
- numedit.Set_Focus();
- numedit.Flag_To_Redraw();
- break;
- // case (BUTTON_NUMBER | KN_BUTTON):
- // nameedit.Clear_Focus();
- // nameedit.Flag_To_Redraw();
- // break;
- /*------------------------------------------------------------------
- Use Default Serial Settings
- ------------------------------------------------------------------*/
- case (BUTTON_DEFAULT | KN_BUTTON):
- custombtn.Turn_Off();
- defaultbtn.Turn_On();
- custom = false;
- break;
- /*------------------------------------------------------------------
- Use Custom Serial Settings
- ------------------------------------------------------------------*/
- case (BUTTON_CUSTOM | KN_BUTTON):
- if (Com_Settings_Dialog (&settings)) {
- custombtn.Turn_On();
- defaultbtn.Turn_Off();
- }
- custom = true;
- display = REDRAW_ALL;
- break;
- /*------------------------------------------------------------------
- CANCEL: bail out
- ------------------------------------------------------------------*/
- case (KN_ESC):
- case (BUTTON_CANCEL | KN_BUTTON):
- process = false;
- rc = false;
- break;
- /*------------------------------------------------------------------
- Save: save changes
- ------------------------------------------------------------------*/
- case (KN_RETURN):
- case (BUTTON_SAVE | KN_BUTTON):
- process = false;
- rc = true;
- break;
- }
- } /* end of while */
- /*------------------------------------------------------------------------
- If 'Save', save all current settings
- ------------------------------------------------------------------------*/
- if (rc) {
- strcpy( phone->Name, strupr( namebuf ) );
- // if nothing was entered then make if NONAME
- if ( !(phone->Name[0]) ) {
- strcpy( phone->Name, "NONAME" );
- }
- strcpy( phone->Number, strupr( numbuf ) );
- if (custom) {
- phone->Settings = settings;
- } else {
- phone->Settings.Port = 0;
- phone->Settings.IRQ = -1;
- phone->Settings.Baud = -1;
- phone->Settings.DialMethod = DIAL_TOUCH_TONE;
- phone->Settings.InitStringIndex = 0;
- phone->Settings.CallWaitStringIndex = CALL_WAIT_CUSTOM;
- phone->Settings.CallWaitString[0] = 0;
- }
- }
- return(rc);
- } /* end of Edit_Phone_Dialog */
- static bool Dial_Modem( SerialSettingsType *settings, bool reconnect )
- {
- bool connected = false;
- DialStatusType dialstatus;
- int modemstatus;
- /*
- ** Turn modem servicing off in the callback routine.
- */
- Session.ModemService = false;
- // save for later to reconnect
- DialSettings = settings;
- modemstatus = NullModem.Get_Modem_Status();
- if (reconnect) {
- if ( (modemstatus & CD_SET) ) {
- connected = true;
- Session.ModemService = true;
- return( connected );
- }
- } else if ( (modemstatus & CD_SET) ) {
- NullModem.Hangup_Modem();
- Session.ModemService = false;
- }
- NullModem.Setup_Modem_Echo( Modem_Echo );
- modemstatus = NullModem.Detect_Modem( settings, reconnect );
- if ( !modemstatus ) {
- NullModem.Remove_Modem_Echo();
- NullModem.Print_EchoBuf();
- NullModem.Reset_EchoBuf();
- //#ifndef WIN32
- /*
- ** If our first attempt to detect the modem failed, and we're at
- ** 14400 or 28800, bump up to the next baud rate & try again.
- */
- switch (settings->Baud) {
- case 14400:
- settings->Baud = 19200;
- Shutdown_Modem();
- Init_Null_Modem(settings);
- NullModem.Setup_Modem_Echo( Modem_Echo );
- modemstatus = NullModem.Detect_Modem( settings, reconnect );
- if ( !modemstatus ) {
- NullModem.Remove_Modem_Echo();
- NullModem.Print_EchoBuf();
- NullModem.Reset_EchoBuf();
- WWMessageBox().Process( TXT_UNABLE_FIND_MODEM );
- Session.ModemService = true;
- return( connected );
- }
- break;
- case 28800:
- settings->Baud = 38400;
- Shutdown_Modem();
- Init_Null_Modem(settings);
- NullModem.Setup_Modem_Echo( Modem_Echo );
- modemstatus = NullModem.Detect_Modem( settings, reconnect );
- if ( !modemstatus ) {
- NullModem.Remove_Modem_Echo();
- NullModem.Print_EchoBuf();
- NullModem.Reset_EchoBuf();
- WWMessageBox().Process( TXT_UNABLE_FIND_MODEM );
- Session.ModemService = true;
- return( connected );
- }
- break;
- default:
- WWMessageBox().Process( TXT_UNABLE_FIND_MODEM );
- Session.ModemService = true;
- return( connected );
- }
- //#else //WIN32
- // Session.ModemService = true;
- // return( connected );
- //#endif //WIN32
- } else if ( modemstatus == -1 ) {
- NullModem.Remove_Modem_Echo();
- NullModem.Print_EchoBuf();
- NullModem.Reset_EchoBuf();
- WWMessageBox().Process( TXT_ERROR_IN_INITSTRING );
- // WWMessageBox().Process( "Error in the InitString." );
- Session.ModemService = true;
- return( connected );
- }
- #ifdef WIN32
- #ifdef FIXIT_APTIVA_MODEM
- /*
- ** Completely disable audio. This is required for MWave devices like those
- ** found in the IBM Aptiva.
- */
- ThemeType old_theme = THEME_NONE;
- if (SoundOn){
- old_theme = Theme.What_Is_Playing();
- Theme.Stop();
- CountDownTimerClass wait;
- Call_Back();
- wait.Set (60,true);
- while ( wait.Time() ) {
- Call_Back();
- }
- Sound_End();
- Call_Back();
- wait.Set (60,true);
- while ( wait.Time() ) {
- Call_Back();
- }
- SoundOn = 0;
- }
- #endif //FIXIT_APTIVA_MODEM
- #endif //WIN32
- dialstatus = NullModem.Dial_Modem( DialString, settings->DialMethod, reconnect );
- if (reconnect) {
- /*
- --------------------------- Redraw the display ---------------------------
- */
- HidPage.Clear();
- Map.Flag_To_Redraw(true);
- Map.Render();
- }
- switch ( dialstatus ) {
- case DIAL_CONNECTED:
- connected = true;
- break;
- case DIAL_NO_CARRIER:
- WWMessageBox().Process(TXT_NO_CARRIER);
- connected = false;
- break;
- case DIAL_BUSY:
- WWMessageBox().Process(TXT_LINE_BUSY);
- connected = false;
- break;
- case DIAL_ERROR:
- WWMessageBox().Process(TXT_NUMBER_INVALID);
- connected = false;
- break;
- case DIAL_NO_DIAL_TONE:
- WWMessageBox().Process(TXT_NO_DIAL_TONE);
- connected = false;
- break;
- case DIAL_CANCELED:
- NullModem.Hangup_Modem();
- Session.ModemService = false;
- WWMessageBox().Process(TXT_DIALING_CANCELED);
- connected = false;
- break;
- }
- NullModem.Remove_Modem_Echo();
- NullModem.Print_EchoBuf();
- NullModem.Reset_EchoBuf();
- #ifdef WIN32
- #ifdef FIXIT_APTIVA_MODEM
- /*
- ** Restore audio capability
- */
- SoundOn = Audio_Init ( MainWindow , 16 , false , 11025*2 , 0 );
- if (SoundOn){
- Theme.Play_Song (old_theme);
- }
- #endif //FIXIT_APTIVA_MODEM
- #endif //WIN32
- Session.ModemService = true;
- return( connected );
- } /* end of Dial_Modem */
- static bool Answer_Modem( SerialSettingsType *settings, bool reconnect )
- {
- bool connected = false;
- DialStatusType dialstatus;
- int modemstatus;
- /*
- ** Turn modem servicing off in the callback routine.
- */
- Session.ModemService = false;
- // save for later to reconnect
- DialSettings = settings;
- modemstatus = NullModem.Get_Modem_Status();
- if (reconnect) {
- if ( (modemstatus & CD_SET) ) {
- connected = true;
- Session.ModemService = true;
- return( connected );
- }
- } else if ( (modemstatus & CD_SET) ) {
- NullModem.Hangup_Modem();
- Session.ModemService = false;
- }
- NullModem.Setup_Modem_Echo( Modem_Echo );
- modemstatus = NullModem.Detect_Modem( settings, reconnect );
- if ( !modemstatus ) {
- NullModem.Remove_Modem_Echo();
- NullModem.Print_EchoBuf();
- NullModem.Reset_EchoBuf();
- //#ifndef WIN32
- /*
- ** If our first attempt to detect the modem failed, and we're at
- ** 14400 or 28800, bump up to the next baud rate & try again.
- */
- switch (settings->Baud) {
- case 14400:
- settings->Baud = 19200;
- Shutdown_Modem();
- Init_Null_Modem(settings);
- NullModem.Setup_Modem_Echo( Modem_Echo );
- modemstatus = NullModem.Detect_Modem( settings, reconnect );
- if ( !modemstatus ) {
- NullModem.Remove_Modem_Echo();
- NullModem.Print_EchoBuf();
- NullModem.Reset_EchoBuf();
- WWMessageBox().Process( TXT_UNABLE_FIND_MODEM );
- Session.ModemService = true;
- return( connected );
- }
- break;
- case 28800:
- settings->Baud = 38400;
- Shutdown_Modem();
- Init_Null_Modem(settings);
- NullModem.Setup_Modem_Echo( Modem_Echo );
- modemstatus = NullModem.Detect_Modem( settings, reconnect );
- if ( !modemstatus ) {
- NullModem.Remove_Modem_Echo();
- NullModem.Print_EchoBuf();
- NullModem.Reset_EchoBuf();
- WWMessageBox().Process( TXT_UNABLE_FIND_MODEM );
- Session.ModemService = true;
- return( connected );
- }
- break;
- default:
- WWMessageBox().Process( TXT_UNABLE_FIND_MODEM );
- Session.ModemService = true;
- return( connected );
- }
- //#else //WIN32
- // Session.ModemService = true;
- // return( connected );
- //#endif //WIN32
- } else if ( modemstatus == -1 ) {
- NullModem.Remove_Modem_Echo();
- NullModem.Print_EchoBuf();
- NullModem.Reset_EchoBuf();
- WWMessageBox().Process( TXT_ERROR_IN_INITSTRING );
- Session.ModemService = true;
- return( connected );
- }
- #ifdef WIN32
- #ifdef FIXIT_APTIVA_MODEM
- /*
- ** Completely disable audio. This is required for some MWave devices like those
- ** found in the IBM Aptiva.
- */
- ThemeType old_theme = THEME_NONE;
- if (SoundOn){
- old_theme = Theme.What_Is_Playing();
- Theme.Stop();
- CountDownTimerClass wait;
- Call_Back();
- wait.Set (60,true);
- while ( wait.Time() ) {
- Call_Back();
- }
- Sound_End();
- Call_Back();
- wait.Set (60,true);
- while ( wait.Time() ) {
- Call_Back();
- }
- SoundOn = 0;
- }
- #endif //FIXIT_APTIVA_MODEM
- #endif //WIN32
- dialstatus = NullModem.Answer_Modem( reconnect );
- switch ( dialstatus ) {
- case DIAL_CONNECTED:
- connected = true;
- break;
- case DIAL_NO_CARRIER:
- WWMessageBox().Process(TXT_NO_CARRIER);
- connected = false;
- break;
- // case DIAL_BUSY:
- // WWMessageBox().Process(TXT_LINE_BUSY);
- // connected = false;
- // break;
- case DIAL_ERROR:
- WWMessageBox().Process(TXT_NUMBER_INVALID);
- connected = false;
- break;
- case DIAL_CANCELED:
- WWMessageBox().Process(TXT_ANSWERING_CANCELED);
- connected = false;
- break;
- }
- NullModem.Remove_Modem_Echo();
- NullModem.Print_EchoBuf();
- NullModem.Reset_EchoBuf();
- #ifdef WIN32
- #ifdef FIXIT_APTIVA_MODEM
- /*
- ** Restore audio capability
- */
- SoundOn = Audio_Init ( MainWindow , 16 , false , 11025*2 , 0 );
- if (SoundOn){
- Theme.Play_Song (old_theme);
- }
- #endif //FIXIT_APTIVA_MODEM
- #endif //WIN32
- Session.ModemService = true;
- return( connected );
- } /* end of Answer_Modem */
- static void Modem_Echo( char c )
- {
- if (NullModem.EchoCount < (NullModem.EchoSize - 1) ) {
- *(NullModem.EchoBuf + NullModem.EchoCount) = c;
- *(NullModem.EchoBuf + NullModem.EchoCount + 1) = 0;
- NullModem.EchoCount++;
- }
- } /* end of Modem_Echo */
- void Smart_Printf( char *format, ... )
- {
- va_list arglist;
- char buf[501];
- va_start(arglist,format);
- vsprintf(buf,format,arglist);
- va_end(arglist);
- if (Debug_Smart_Print) {
- if (MonoClass::Is_Enabled()) {
- Mono_Printf("%s",buf);
- } else {
- printf("%s",buf);
- }
- } else {
- if (Debug_Heap_Dump) {
- printf("%s",buf);
- }
- if (Debug_Modem_Dump) {
- printf("%s",buf);
- }
- }
- }
- void Hex_Dump_Data( char *buffer, int length )
- {
- int i;
- int offset = 0;
- char buff[10];
- char ptr[16];
- char c;
- while (length >= 16) {
- memcpy( ptr, (buffer + offset), 16);
- Smart_Printf("%05lX ", offset);
- for (i = 0; i < 16; i++) {
- c = ptr[i];
- itoh(c, buff);
- if (!(i & 0x3) && i) {
- Smart_Printf("³ ");
- }
- Smart_Printf("%s ", buff);
- }
- Smart_Printf(" ");
- for (i = 0; i < 16; i++) {
- c = ptr[i];
- if (c && ((c < 7) || (c > 11)) && (c != 13)) {
- Smart_Printf("%c", c);
- } else {
- Smart_Printf(".");
- }
- }
- Smart_Printf("\n");
- offset += 16;
- length -= 16;
- }
- if (length) {
- memcpy( ptr, (buffer + offset), 16);
- Smart_Printf("%05lX ", offset);
- for (i = 0; i < 16; i++) {
- if (i < length) {
- c = ptr[i];
- itoh(c, buff);
- if (!(i & 0x3) && i) {
- Smart_Printf("³ ");
- }
- Smart_Printf("%s ", buff);
- } else {
- if (!(i & 0x3) && i) {
- Smart_Printf(" ");
- }
- Smart_Printf(" ");
- }
- }
- Smart_Printf(" ");
- for (i = 0; i < length; i++) {
- c = ptr[i];
- if (c && ((c < 7) || (c > 11)) && (c != 13)) {
- Smart_Printf("%c", c);
- } else {
- Smart_Printf(".");
- }
- }
- Smart_Printf("\n");
- }
- } /* end of Hex_Dump_Data */
- void itoh( int i, char *s)
- {
- int nibble, loop;
- // *s++ = '0';
- // *s++ = 'x';
- if (i == 0) {
- *s++ = '0';
- *s++ = '0';
- } else {
- for (loop = 1; loop >= 0; loop--) {
- nibble = (i >> (loop << 2)) & 0x000F;
- /* decimal range */
- if (nibble < 10) {
- *s++ = '0' + nibble;
- } else {
- *s++ = 'A' + (nibble - 10);
- }
- }
- }
- *s = 0; /* null terminate it */
- }
- void Log_Start_Time( char *string )
- {
- // LogDump_Print = true;
- LogLevel = 0;
- LogLevelTime[ LogLevel ] = LogLastTime = TickCount;
- Smart_Printf( "start tick=%d, %s \n", LogLastTime, string );
- }
- void Log_End_Time( char *string )
- {
- int i;
- unsigned long currtime;
- unsigned long ticks;
- currtime = TickCount;
- while (LogLevel >= 0) {
- if (LogLevel < MAX_LOG_LEVEL) {
- //
- // put one space for each level as indenting
- //
- i = 0;
- while (i++ < LogLevel) {
- Smart_Printf( " " );
- }
- } else {
- Smart_Printf( "LogLevel %d too large!-! \n", LogLevel);
- LogLevel = MAX_LOG_LEVEL - 1;
- }
- ticks = currtime - LogLevelTime[ LogLevel-- ];
- Smart_Printf( "end tick=%d, ticks=%d, tsecs=%d, %s \n",
- currtime, ticks, ((ticks * 10) / 60), string );
- }
- LogDump_Print = false;
- }
- void Log_Time( char *string )
- {
- int i;
- unsigned long currtime;
- unsigned long ticks;
- currtime = TickCount;
- if (LogLevel < MAX_LOG_LEVEL) {
- //
- // put one space for each level as indenting
- //
- i = 0;
- while (i++ < LogLevel) {
- Smart_Printf( " " );
- }
- } else {
- Smart_Printf( "LogLevel %d too large!-! \n", LogLevel);
- LogLevel = MAX_LOG_LEVEL - 1;
- }
- ticks = currtime - LogLastTime;
- Smart_Printf( "tick=%d, ticks=%d, tsecs=%d, %s \n",
- currtime, ticks, ((ticks * 10) / 60), string );
- LogLastTime = currtime;
- }
- void Log_Start_Nest_Time( char *string )
- {
- int i;
- unsigned long currtime;
- unsigned long ticks;
- currtime = TickCount;
- if (LogLevel < MAX_LOG_LEVEL) {
- //
- // put one space for each level as indenting
- //
- i = 0;
- while (i++ < LogLevel) {
- Smart_Printf( " " );
- }
- } else {
- Smart_Printf( "LogLevel %d too large!-! \n", LogLevel);
- LogLevel = MAX_LOG_LEVEL - 1;
- }
- ticks = currtime - LogLastTime;
- Smart_Printf( "start ntick=%d, ticks=%d, tsecs=%d, %s \n",
- currtime, ticks, ((ticks * 10) / 60), string );
- if (LogLevel >= (MAX_LOG_LEVEL - 1) ) {
- Smart_Printf( "Could not start another nesting Maxed at %d,%d!-! \n",
- LogLevel, (MAX_LOG_LEVEL - 1) );
- } else {
- LogLevelTime[ ++LogLevel ] = currtime;
- }
- LogLastTime = currtime;
- }
- void Log_End_Nest_Time( char *string )
- {
- int i;
- unsigned long currtime;
- unsigned long ticks;
- currtime = TickCount;
- if (LogLevel <= 0) {
- Smart_Printf( "Could not end another nesting Mined at %d,%d!-! \n",
- LogLevel, 0 );
- LogLevel = 0;
- }
- if (LogLevel < MAX_LOG_LEVEL) {
- //
- // put one space for each level as indenting
- //
- i = 0;
- while (i++ < LogLevel) {
- Smart_Printf( " " );
- }
- } else {
- Smart_Printf( "LogLevel %d too large!-! \n", LogLevel);
- LogLevel = MAX_LOG_LEVEL - 1;
- }
- ticks = currtime - LogLevelTime[ LogLevel ];
- Smart_Printf( "end ntick=%d, ticks=%d, secs=%d, %s \n",
- currtime, ticks, ((ticks * 10) / 60), string );
- if (LogLevel) {
- LogLevel--;
- }
- LogLastTime = currtime;
- }
- #endif
|