OGAMEMP.cpp 141 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890
  1. /*
  2. * Seven Kingdoms: Ancient Adversaries
  3. *
  4. * Copyright 1997,1998 Enlight Software Ltd.
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. */
  20. //Filename : OGAMEMP.CPP
  21. //Description : Main Game Object - Multiplayer Game (using Imagic multiplayer SDK)
  22. #include <OSYS.h>
  23. #include <OMOUSE.h>
  24. #include <OMOUSECR.h>
  25. #include <OBOX.h>
  26. #include <OVGA.h>
  27. #include <OFONT.h>
  28. #include <OBUTT3D.h>
  29. #include <ONATION.h>
  30. #include <ORACERES.h>
  31. #include <OREMOTE.h>
  32. #include <OBATTLE.h>
  33. #include <OGAME.h>
  34. #include <ODPLAY.h>
  35. #include <OIMMPLAY.h>
  36. #include <OERRCTRL.h>
  37. #include <OGFILE.h>
  38. #include <OCONFIG.h>
  39. #include <OIMGRES.h>
  40. #include <OGET.h>
  41. #include <KEY.h>
  42. #include <OMUSIC.h>
  43. #include <OBUTTCUS.h>
  44. #include <OCOLTBL.h>
  45. #include <OGETA.h>
  46. #include <OSLIDCUS.h>
  47. #include <OBLOB.h>
  48. // --------- Define constant --------//
  49. #define PLAYER_RATIO_CDROM 3
  50. #define PLAYER_RATIO_NOCD -1
  51. #define PLAYER_RATIO_STRING "four"
  52. #define FORCE_MAX_FRAME_DELAY 5
  53. enum { OPTION_BASIC,
  54. OPTION_ADVANCED,
  55. OPTION_ADVANCE2,
  56. OPTION_GOAL,
  57. };
  58. enum { BASIC_OPTION_X_SPACE = 78,
  59. BASIC_OPTION_HEIGHT = 32 };
  60. enum { COLOR_OPTION_X_SPACE = 35,
  61. COLOR_OPTION_HEIGHT = 32 };
  62. enum { SERVICE_OPTION_X_SPACE = 180,
  63. SERVICE_OPTION_HEIGHT = 139 };
  64. static char race_table[MAX_RACE] = // race translation table
  65. #if(MAX_RACE == 10)
  66. {
  67. RACE_CHINESE, RACE_EGYPTIAN, RACE_GREEK, RACE_JAPANESE, RACE_MAYA,
  68. RACE_INDIAN, RACE_NORMAN, RACE_PERSIAN, RACE_VIKING, RACE_ZULU
  69. };
  70. #else
  71. {
  72. RACE_CHINESE, RACE_GREEK, RACE_JAPANESE, RACE_MAYA,
  73. RACE_PERSIAN, RACE_NORMAN, RACE_VIKING
  74. };
  75. #endif
  76. static char reverse_race_table[MAX_RACE] = // race translation table
  77. #if(MAX_RACE == 10)
  78. {
  79. 6, 4, 2, 8, 7, 0, 3, 1, 5, 9
  80. };
  81. #else
  82. {
  83. 5, 3, 1, 6, 4, 0, 2
  84. };
  85. #endif
  86. static char sub_game_mode; // 0 = new multiplayer game, 1 = load multiplayer game
  87. static void disp_virtual_button(ButtonCustom *, int);
  88. static void disp_virtual_tick(ButtonCustom *, int);
  89. static void disp_scroll_bar_func(SlideVBar *scroll, int);
  90. enum
  91. {
  92. MPMSG_START_GAME = 0x1f5a0001,
  93. MPMSG_ABORT_GAME,
  94. MPMSG_RANDOM_SEED, // see MpStructSeed
  95. MPMSG_RANDOM_SEED_STR,
  96. MPMSG_DECLARE_NATION, // see MpStructNation
  97. MPMSG_END_SETTING,
  98. MPMSG_START_LOAD_GAME,
  99. MPMSG_ACCEPT_DECLARE_NATION, // used in loading multiplayer game
  100. MPMSG_REFUSE_DECLARE_NATION,
  101. MPMSG_SEND_CONFIG,
  102. MPMSG_NEW_PLAYER,
  103. MPMSG_ACCEPT_NEW_PLAYER,
  104. MPMSG_REFUSE_NEW_PLAYER,
  105. MPMSG_ACQUIRE_COLOR,
  106. MPMSG_ACCEPT_COLOR,
  107. MPMSG_REFUSE_COLOR,
  108. MPMSG_ACQUIRE_RACE,
  109. MPMSG_ACCEPT_RACE,
  110. MPMSG_REFUSE_RACE,
  111. MPMSG_PLAYER_READY,
  112. MPMSG_PLAYER_UNREADY,
  113. MPMSG_LOAD_GAME_NEW_PLAYER,
  114. MPMSG_SEND_CHAT_MSG,
  115. // ### patch begin Gilbert 22/1 ######//
  116. // introduced since version 111
  117. MPMSG_SEND_SYNC_TEST_LEVEL,
  118. // ### patch begin Gilbert 22/1 ######//
  119. MPMSG_TEST_LATENCY_SEND,
  120. MPMSG_TEST_LATENCY_ECHO,
  121. MPMSG_SET_PROCESS_FRAME_DELAY,
  122. };
  123. struct MpStructBase
  124. {
  125. DWORD msg_id;
  126. MpStructBase(DWORD msgId) : msg_id(msgId) {}
  127. };
  128. struct MpStructSeed : public MpStructBase
  129. {
  130. long seed;
  131. MpStructSeed(long s) : MpStructBase(MPMSG_RANDOM_SEED), seed(s) {}
  132. };
  133. struct MpStructSeedStr : public MpStructBase
  134. {
  135. enum { RANDOM_SEED_MAX_LEN = 11 };
  136. char seed_str[RANDOM_SEED_MAX_LEN+1];
  137. MpStructSeedStr(char *s) : MpStructBase(MPMSG_RANDOM_SEED_STR)
  138. {
  139. if(s)
  140. strcpy(seed_str, s);
  141. else
  142. seed_str[0] = '\0';
  143. }
  144. MpStructSeedStr(long l) : MpStructBase(MPMSG_RANDOM_SEED_STR)
  145. {
  146. ltoa(l, seed_str, 10);
  147. }
  148. };
  149. struct MpStructNation : public MpStructBase
  150. {
  151. short nation_recno;
  152. DWORD dp_player_id;
  153. short color_scheme;
  154. short race_id;
  155. char player_name[NationArray::HUMAN_NAME_LEN+1];
  156. MpStructNation() : MpStructBase(MPMSG_DECLARE_NATION) {}
  157. MpStructNation(short n, DWORD playerId, short scheme, short race,
  158. char *playerName):
  159. MpStructBase(MPMSG_DECLARE_NATION), nation_recno(n),
  160. dp_player_id(playerId), color_scheme(scheme), race_id(race)
  161. {
  162. strcpy(player_name, playerName);
  163. }
  164. void init(short n, DWORD playerId, short scheme, short race,
  165. char *playerName)
  166. {
  167. msg_id = MPMSG_DECLARE_NATION;
  168. nation_recno = n;
  169. dp_player_id = playerId;
  170. color_scheme = scheme;
  171. race_id = race;
  172. strcpy(player_name, playerName);
  173. }
  174. };
  175. struct MpStructConfig : public MpStructBase
  176. {
  177. Config game_config;
  178. MpStructConfig(Config &c) : MpStructBase(MPMSG_SEND_CONFIG), game_config(c) {}
  179. };
  180. struct MpStructNewPlayer : public MpStructBase
  181. {
  182. PID_TYPE player_id;
  183. short player_balance; // 2 for CD-ROM version, -1 for non CD-ROM version
  184. MpStructNewPlayer(PID_TYPE p, short bal) : MpStructBase(MPMSG_NEW_PLAYER), player_id(p),
  185. player_balance(bal) {}
  186. };
  187. struct MpStructAcceptNewPlayer : public MpStructBase
  188. {
  189. PID_TYPE player_id;
  190. MpStructAcceptNewPlayer(PID_TYPE p) : MpStructBase(MPMSG_ACCEPT_NEW_PLAYER), player_id(p) {}
  191. };
  192. struct MpStructRefuseNewPlayer : public MpStructBase
  193. {
  194. PID_TYPE player_id;
  195. MpStructRefuseNewPlayer(PID_TYPE p) : MpStructBase(MPMSG_REFUSE_NEW_PLAYER), player_id(p) {}
  196. };
  197. struct MpStructAcquireColor : public MpStructBase
  198. {
  199. short color_scheme_id;
  200. MpStructAcquireColor(short c) : MpStructBase(MPMSG_ACQUIRE_COLOR), color_scheme_id(c) {}
  201. };
  202. struct MpStructAcceptColor : public MpStructBase
  203. {
  204. PID_TYPE request_player_id;
  205. short color_scheme_id;
  206. MpStructAcceptColor(PID_TYPE p,short c) : MpStructBase(MPMSG_ACCEPT_COLOR),
  207. request_player_id(p), color_scheme_id(c) {}
  208. };
  209. struct MpStructRefuseColor : public MpStructBase
  210. {
  211. PID_TYPE request_player_id;
  212. short color_scheme_id;
  213. MpStructRefuseColor(PID_TYPE p, short c) : MpStructBase(MPMSG_REFUSE_COLOR),
  214. request_player_id(p), color_scheme_id(c) {}
  215. };
  216. struct MpStructAcquireRace : public MpStructBase
  217. {
  218. short race_id;
  219. MpStructAcquireRace(short raceId) : MpStructBase(MPMSG_ACQUIRE_RACE), race_id(raceId) {}
  220. };
  221. struct MpStructAcceptRace : public MpStructBase
  222. {
  223. PID_TYPE request_player_id;
  224. short race_id;
  225. MpStructAcceptRace(PID_TYPE p,short raceId) : MpStructBase(MPMSG_ACCEPT_RACE),
  226. request_player_id(p), race_id(raceId) {}
  227. };
  228. struct MpStructRefuseRace : public MpStructBase
  229. {
  230. PID_TYPE request_player_id;
  231. short race_id;
  232. MpStructRefuseRace(PID_TYPE p, short raceId) : MpStructBase(MPMSG_REFUSE_RACE),
  233. request_player_id(p), race_id(raceId) {}
  234. };
  235. struct MpStructPlayerReady : public MpStructBase
  236. {
  237. PID_TYPE player_id;
  238. MpStructPlayerReady(PID_TYPE p) : MpStructBase(MPMSG_PLAYER_READY), player_id(p) {}
  239. };
  240. struct MpStructPlayerUnready : public MpStructBase
  241. {
  242. PID_TYPE player_id;
  243. MpStructPlayerUnready(PID_TYPE p) : MpStructBase(MPMSG_PLAYER_UNREADY), player_id(p) {}
  244. };
  245. struct MpStructLoadGameNewPlayer : public MpStructBase
  246. {
  247. PID_TYPE player_id;
  248. short nation_recno;
  249. short color_scheme_id;
  250. short race_id;
  251. DWORD frame_count; // detail to test save game from the same game
  252. long random_seed;
  253. short player_balance;
  254. MpStructLoadGameNewPlayer(PID_TYPE p, Nation *n, DWORD frame, long seed, short bal) :
  255. MpStructBase(MPMSG_LOAD_GAME_NEW_PLAYER), player_id(p),
  256. nation_recno(n->nation_recno), color_scheme_id(n->color_scheme_id),
  257. race_id(n->race_id), frame_count(frame), random_seed(seed), player_balance(bal)
  258. {
  259. }
  260. };
  261. struct MpStructChatMsg : public MpStructBase
  262. {
  263. enum { MSG_LENGTH = 60 };
  264. char sender[MP_FRIENDLY_NAME_LEN+1];
  265. char content[MSG_LENGTH+1];
  266. MpStructChatMsg(char *fromName, char *message) : MpStructBase(MPMSG_SEND_CHAT_MSG)
  267. {
  268. if( fromName )
  269. strcpy(sender, fromName);
  270. else
  271. sender[0] = '\0';
  272. if( message )
  273. strcpy(content, message);
  274. else
  275. content[0] = '\0';
  276. }
  277. };
  278. struct MpStructSyncLevel : public MpStructBase
  279. {
  280. char sync_test_level;
  281. MpStructSyncLevel(char syncLevel) : MpStructBase(MPMSG_SEND_SYNC_TEST_LEVEL), sync_test_level(syncLevel)
  282. {
  283. }
  284. };
  285. struct MpStructLatencySend : public MpStructBase
  286. {
  287. int test_id;
  288. DWORD send_time;
  289. MpStructLatencySend(int testId, DWORD sendTime) : MpStructBase(MPMSG_TEST_LATENCY_SEND),
  290. test_id(testId), send_time(sendTime)
  291. {
  292. }
  293. };
  294. struct MpStructLatencyReturn : public MpStructLatencySend
  295. {
  296. MpStructLatencyReturn(const MpStructLatencySend &ls) : MpStructLatencySend(ls)
  297. {
  298. msg_id = MPMSG_TEST_LATENCY_ECHO;
  299. }
  300. };
  301. struct MpStructProcessFrameDelay : public MpStructBase
  302. {
  303. int common_process_frame_delay;
  304. MpStructProcessFrameDelay(int newFrameDelay) : MpStructBase(MPMSG_SET_PROCESS_FRAME_DELAY),
  305. common_process_frame_delay(newFrameDelay)
  306. {
  307. }
  308. };
  309. //--------- Define static functions ------------//
  310. static void pregame_disconnect_handler(DWORD playerId);
  311. static void ingame_disconnect_handler(DWORD playerId);
  312. /*
  313. //--------- Begin of function Game::mp_disp_player ---------//
  314. void Game::mp_disp_players()
  315. {
  316. enum { BUTTON_WIDTH=80, BUTTON_HEIGHT=22, BUTTON_Y_SPACE=26 };
  317. enum { BUTTON_NUM=8, BUTTON_TOP_X=620, BUTTON_TOP_Y=10 };
  318. //--------- display buttons -------//
  319. int x=BUTTON_TOP_X;
  320. int y=BUTTON_TOP_Y;
  321. Button buttonArray[BUTTON_NUM];
  322. mp_obj.poll_players();
  323. for( int i=0 ; i<BUTTON_NUM && mp_obj.get_player(i+1); i++, y+=BUTTON_Y_SPACE )
  324. {
  325. buttonArray[i].paint_text(x, y, x+BUTTON_WIDTH-1, y+BUTTON_HEIGHT-1, mp_obj.get_player(i+1)->friendly_name );
  326. }
  327. }
  328. //--------- End of function Game::mp_disp_players ---------//
  329. */
  330. //-------- Begin of function Game::mp_broadcast_setting --------//
  331. //
  332. // Broadcast the latest game settings from the host to all clients.
  333. // This function should be called by the host only
  334. //
  335. // see also to RemoteMsg::update_game_setting
  336. //
  337. void Game::mp_broadcast_setting()
  338. {
  339. // send (long) random seed
  340. // send (short) no. of nations
  341. // for each nation, send :
  342. // (short) nation recno
  343. // (DWORD) directPlay player id
  344. // (short) color scheme
  345. // (short) race id
  346. //
  347. short i;
  348. int msgSize = sizeof(long) +sizeof(short) +
  349. nation_array.size()*(3*sizeof(short)+sizeof(PID_TYPE));
  350. RemoteMsg *remoteMsg = remote.new_msg( MSG_UPDATE_GAME_SETTING, msgSize );
  351. char* dataPtr = remoteMsg->data_buf;
  352. *(long*)dataPtr = m.get_random_seed();
  353. dataPtr += sizeof(long);
  354. *(short*)dataPtr = nation_array.size();
  355. dataPtr += sizeof(short);
  356. for( i=1 ; i<=nation_array.size() ; i++)
  357. {
  358. *(short *)dataPtr = i;
  359. dataPtr += sizeof(short);
  360. *(PID_TYPE *)dataPtr = nation_array[i]->player_id;
  361. dataPtr += sizeof(PID_TYPE);
  362. *(short *)dataPtr = nation_array[i]->color_scheme_id;
  363. dataPtr += sizeof(short);
  364. *(short *)dataPtr = nation_array[i]->race_id;
  365. dataPtr += sizeof(short);
  366. }
  367. err_when(dataPtr - remoteMsg->data_buf > msgSize);
  368. remote.send_free_msg(remoteMsg); // send out the message and free it after finishing sending
  369. }
  370. //--------- End of function Game::mp_broadcast_setting ---------//
  371. //-------- Begin of function pregame_disconnect_handler --------//
  372. //
  373. // Host disconnection handler, called by Remote when one of the players
  374. // disconnects from the game when it's still in multiplayer game setting
  375. // menu.
  376. //
  377. static void pregame_disconnect_handler(DWORD playerId)
  378. {
  379. int i;
  380. for( i=1 ; i<=nation_array.size() ; i++ )
  381. {
  382. if( nation_array[i]->player_id == playerId )
  383. {
  384. ((DynArray*)&nation_array)->linkout(i);
  385. break;
  386. }
  387. }
  388. }
  389. //--------- End of function pregame_disconnect_handler ---------//
  390. //-------- Begin of function ingame_disconnect_handler --------//
  391. //
  392. // Host disconnection handler, called by Remote when one of the players
  393. // disconnects from the game after the game has started.
  394. //
  395. static void ingame_disconnect_handler(DWORD playerId)
  396. {
  397. int i;
  398. for( i=1 ; i<=nation_array.size() ; i++ )
  399. {
  400. if( nation_array.is_deleted(i) )
  401. continue;
  402. if( nation_array[i]->player_id == playerId )
  403. {
  404. nation_array[i]->nation_type = NATION_AI; //**BUGHERE, should have a function to set all units, structures of this nation to AI
  405. nation_array.ai_nation_count++;
  406. }
  407. }
  408. }
  409. //--------- End of function ingame_disconnect_handler ---------//
  410. // --------- Begin of static function multi_player_game ----------//
  411. // avoid creating local variable in this function
  412. // ###### begin Gilbert 13/2 #######//
  413. void Game::multi_player_game(char *cmdLine)
  414. // ###### end Gilbert 13/2 #######//
  415. {
  416. sub_game_mode = 0;
  417. info.init_random_seed(0); // initialize the random seed
  418. int choice, p;
  419. mp_obj.pre_init();
  420. // ###### begin Gilbert 13/2 #######//
  421. if( !cmdLine || (mp_obj.init_lobbied(MAX_NATION, cmdLine), !mp_obj.init_flag) )
  422. { // not launched from lobby
  423. // ###### end Gilbert 13/2 #######//
  424. mp_obj.poll_service_providers();
  425. choice = mp_select_service();
  426. if( !choice )
  427. {
  428. mp_obj.deinit();
  429. return;
  430. }
  431. #ifdef IMAGICMP
  432. mp_obj.init(mp_obj.get_service_provider(choice)->service_id());
  433. #else
  434. switch(choice)
  435. {
  436. case 1: // IPX
  437. for(p = 1; mp_obj.get_service_provider(p); ++p)
  438. {
  439. if( m.str_str(mp_obj.get_service_provider(p)->description, "IPX") ||
  440. mp_obj.get_service_provider(p)->service_id() == DPSPGUID_IPX )
  441. {
  442. mp_obj.init(mp_obj.get_service_provider(p)->service_id());
  443. break;
  444. }
  445. }
  446. break;
  447. case 2: // TCP/IP
  448. for(p = 1; mp_obj.get_service_provider(p); ++p)
  449. {
  450. if( m.str_str(mp_obj.get_service_provider(p)->description, "TCP/IP") ||
  451. mp_obj.get_service_provider(p)->service_id() == DPSPGUID_TCPIP )
  452. {
  453. mp_obj.init(mp_obj.get_service_provider(p)->service_id());
  454. break;
  455. }
  456. }
  457. break;
  458. case 3: // Modem
  459. for(p = 1; mp_obj.get_service_provider(p); ++p)
  460. {
  461. if( m.str_str(mp_obj.get_service_provider(p)->description, "Modem") ||
  462. mp_obj.get_service_provider(p)->service_id() == DPSPGUID_MODEM )
  463. {
  464. mp_obj.init(mp_obj.get_service_provider(p)->service_id());
  465. break;
  466. }
  467. }
  468. break;
  469. case 4: // Serial
  470. for(p = 1; mp_obj.get_service_provider(p); ++p)
  471. {
  472. if( m.str_str(mp_obj.get_service_provider(p)->description, "Serial") ||
  473. mp_obj.get_service_provider(p)->service_id() == DPSPGUID_SERIAL )
  474. {
  475. mp_obj.init(mp_obj.get_service_provider(p)->service_id());
  476. break;
  477. }
  478. }
  479. break;
  480. }
  481. #endif
  482. // ####### begin Gilbert 13/2 ########//
  483. }
  484. // ####### end Gilbert 13/2 ########//
  485. // do not call remote.init here, or sys.yield will call remote.poll_msg
  486. if(!mp_obj.init_flag)
  487. {
  488. // BUGHERE : display error message
  489. box.msg("Cannot initialize DirectPlay.");
  490. mp_obj.deinit();
  491. return;
  492. }
  493. // create game or join game
  494. switch( mp_select_mode(NULL) )
  495. {
  496. case 1: // create game
  497. // BUGHERE : enter session name here and player name here
  498. if( mp_obj.create_session(config.player_name, MAX_NATION)
  499. && mp_obj.create_player(config.player_name, config.player_name) )
  500. {
  501. remote.init(&mp_obj);
  502. remote.create_game();
  503. }
  504. else
  505. {
  506. mp_obj.deinit();
  507. return;
  508. }
  509. break;
  510. case 2: // join game
  511. if( (choice = mp_select_session()) )
  512. {
  513. if( mp_obj.join_session(choice)
  514. && mp_obj.create_player(config.player_name, config.player_name) )
  515. {
  516. remote.init(&mp_obj);
  517. remote.connect_game();
  518. }
  519. else
  520. {
  521. // can't join session
  522. // BUGHERE : display error message here
  523. mp_obj.deinit();
  524. return;
  525. }
  526. }
  527. else
  528. {
  529. mp_obj.deinit();
  530. return;
  531. }
  532. break;
  533. default: // cancel
  534. mp_obj.deinit();
  535. return;
  536. }
  537. // config game session ...
  538. NewNationPara *nationPara = (NewNationPara *)mem_add(sizeof(NewNationPara)*MAX_NATION);
  539. int mpPlayerCount = 0;
  540. if( !mp_select_option(nationPara, &mpPlayerCount) )
  541. {
  542. mem_del(nationPara);
  543. if( remote.is_host )
  544. mp_obj.close_session();
  545. remote.deinit();
  546. mp_obj.deinit();
  547. return;
  548. }
  549. // assign nation is done is mp_select_option
  550. // ---------- initialize ec_remote --------- //
  551. // find itself
  552. for( p = 0; p < mpPlayerCount; ++p )
  553. {
  554. if( nationPara[p].dp_player_id == mp_obj.my_player_id )
  555. {
  556. ec_remote.init( &mp_obj, char(p+1) );
  557. break;
  558. }
  559. }
  560. err_when( p >= mpPlayerCount );
  561. for( p = 0; p < mpPlayerCount; ++p )
  562. {
  563. if( nationPara[p].dp_player_id != mp_obj.my_player_id )
  564. {
  565. ec_remote.set_dp_id(char(p+1), nationPara[p].dp_player_id );
  566. }
  567. }
  568. //---------- start game now ----------//
  569. // vga_front.bar(0,0,VGA_WIDTH-1,VGA_HEIGHT-1,V_LIGHT_BLUE);
  570. // sys.blt_virtual_buf();
  571. remote.init_start_mp();
  572. // suppose inital sys.frame_count is 1
  573. // find nation_array.player_recno from nationPara
  574. for( p = 0; p < mpPlayerCount; ++p )
  575. {
  576. if( nationPara[p].dp_player_id == mp_obj.my_player_id )
  577. {
  578. // remote.init_send_queue(1, nation_array.player_recno); // but nation_array.player_recno is not set
  579. remote.init_send_queue(1, nationPara[p].nation_recno); // initialize the send queue for later sending
  580. break;
  581. }
  582. }
  583. err_when( p >= mpPlayerCount );
  584. remote.init_receive_queue(1);
  585. init();
  586. remote.handle_vga_lock = 0; // disable lock handling
  587. battle.run(nationPara, mpPlayerCount);
  588. mem_del(nationPara);
  589. remote.deinit();
  590. mp_obj.deinit();
  591. deinit();
  592. }
  593. // --------- End of static function multi_player_game ----------//
  594. // --------- Begin of static function load_mp_game ----------//
  595. // avoid creating local variable in this function
  596. void Game::load_mp_game(char *fileName, char *cmdLine)
  597. {
  598. sub_game_mode = 1;
  599. int nationRecno;
  600. int choice, p;
  601. mp_obj.pre_init();
  602. // ###### begin Gilbert 13/2 #######//
  603. if( !cmdLine || (mp_obj.init_lobbied(MAX_NATION, cmdLine), !mp_obj.init_flag) )
  604. { // not launched from lobby
  605. // ###### end Gilbert 13/2 #######//
  606. mp_obj.poll_service_providers();
  607. choice = mp_select_service();
  608. if( !choice )
  609. {
  610. mp_obj.deinit();
  611. return;
  612. }
  613. #ifdef IMAGICMP
  614. mp_obj.init(mp_obj.get_service_provider(choice)->service_id());
  615. #else
  616. switch(choice)
  617. {
  618. case 1: // IPX
  619. for(p = 1; mp_obj.get_service_provider(p); ++p)
  620. {
  621. if( m.str_str(mp_obj.get_service_provider(p)->description, "IPX") ||
  622. mp_obj.get_service_provider(p)->service_id() == DPSPGUID_IPX )
  623. {
  624. mp_obj.init(mp_obj.get_service_provider(p)->service_id());
  625. break;
  626. }
  627. }
  628. break;
  629. case 2: // TCP/IP
  630. for(p = 1; mp_obj.get_service_provider(p); ++p)
  631. {
  632. if( m.str_str(mp_obj.get_service_provider(p)->description, "TCP/IP") ||
  633. mp_obj.get_service_provider(p)->service_id() == DPSPGUID_TCPIP )
  634. {
  635. mp_obj.init(mp_obj.get_service_provider(p)->service_id());
  636. break;
  637. }
  638. }
  639. break;
  640. case 3: // Modem
  641. for(p = 1; mp_obj.get_service_provider(p); ++p)
  642. {
  643. if( m.str_str(mp_obj.get_service_provider(p)->description, "Modem") ||
  644. mp_obj.get_service_provider(p)->service_id() == DPSPGUID_MODEM )
  645. {
  646. mp_obj.init(mp_obj.get_service_provider(p)->service_id());
  647. break;
  648. }
  649. }
  650. break;
  651. case 4: // Serial
  652. for(p = 1; mp_obj.get_service_provider(p); ++p)
  653. {
  654. if( m.str_str(mp_obj.get_service_provider(p)->description, "Serial") ||
  655. mp_obj.get_service_provider(p)->service_id() == DPSPGUID_SERIAL )
  656. {
  657. mp_obj.init(mp_obj.get_service_provider(p)->service_id());
  658. break;
  659. }
  660. }
  661. break;
  662. }
  663. #endif
  664. // ####### begin Gilbert 13/2 ########//
  665. }
  666. // ####### end Gilbert 13/2 ########//
  667. // do not call remote.init here, or sys.yield will call remote.poll_msg
  668. if(!mp_obj.init_flag)
  669. {
  670. // BUGHERE : display error message
  671. box.msg("Cannot initialize DirectPlay.");
  672. mp_obj.deinit();
  673. return;
  674. }
  675. // load game
  676. //if( !game_file.load_game(fileName) )
  677. //{
  678. // mp_obj.deinit();
  679. // return;
  680. //}
  681. // count required player
  682. int gamePlayerCount = 0;
  683. for(nationRecno = 1; nationRecno <= nation_array.size(); ++nationRecno)
  684. if( !nation_array.is_deleted(nationRecno) &&
  685. (nation_array[nationRecno]->is_own() || nation_array[nationRecno]->is_remote()) )
  686. ++gamePlayerCount;
  687. // create game or join game
  688. switch( mp_select_mode(fileName) )
  689. {
  690. case 1: // create game
  691. // BUGHERE : enter session name here and player name here
  692. if( mp_obj.create_session(config.player_name, gamePlayerCount) // player name as session name
  693. && mp_obj.create_player(config.player_name, config.player_name) )
  694. {
  695. remote.init(&mp_obj);
  696. remote.create_game();
  697. }
  698. else
  699. {
  700. mp_obj.deinit();
  701. return;
  702. }
  703. break;
  704. case 2: // join game
  705. if( (choice = mp_select_session()) )
  706. {
  707. // BUGHERE : enter session name here and player name here
  708. if( mp_obj.join_session(choice) && mp_obj.create_player(config.player_name, config.player_name) )
  709. {
  710. // count required player
  711. gamePlayerCount = 0;
  712. for(nationRecno = 1; nationRecno <= nation_array.size(); ++nationRecno)
  713. if( !nation_array.is_deleted(nationRecno) && !nation_array[nationRecno]->is_ai() )
  714. ++gamePlayerCount;
  715. remote.init(&mp_obj);
  716. remote.connect_game();
  717. }
  718. else
  719. {
  720. // can't join session
  721. // BUGHERE : display error message here
  722. mp_obj.deinit();
  723. return;
  724. }
  725. }
  726. else
  727. {
  728. mp_obj.deinit();
  729. return;
  730. }
  731. break;
  732. default: // cancel
  733. mp_obj.deinit();
  734. return;
  735. }
  736. // config game session ...
  737. if( !mp_select_load_option(fileName) )
  738. {
  739. if( remote.is_host )
  740. mp_obj.close_session();
  741. remote.deinit();
  742. mp_obj.deinit();
  743. return;
  744. }
  745. // assign nation is done is mp_select_load_option
  746. // ---------- initialize ec_remote --------- //
  747. // find itself
  748. ec_remote.init( &mp_obj, (char) (~nation_array)->nation_recno );
  749. for( p = 1; p <= nation_array.size(); ++p )
  750. {
  751. if( !nation_array.is_deleted(p) )
  752. {
  753. Nation *nationPtr = nation_array[p];
  754. if( nationPtr->is_remote() )
  755. {
  756. ec_remote.set_dp_id((char) p, nationPtr->player_id );
  757. }
  758. }
  759. }
  760. //---------- start game now ----------//
  761. // vga_front.bar(0,0,VGA_WIDTH-1,VGA_HEIGHT-1,V_LIGHT_BLUE);
  762. // sys.blt_virtual_buf();
  763. remote.init_start_mp();
  764. remote.init_send_queue(sys.frame_count, nation_array.player_recno); // initialize the send queue for later sending
  765. remote.init_receive_queue(sys.frame_count);
  766. // init();
  767. remote.handle_vga_lock = 0; // disable lock handling
  768. battle.run_loaded(); // 1-multiplayer game
  769. remote.deinit();
  770. mp_obj.deinit();
  771. deinit();
  772. }
  773. // --------- End of static function load_mp_game ----------//
  774. //-------- Begin of function Game::mp_select_service --------//
  775. //
  776. // Select multiplayer mode. Create a new game or connect
  777. // to an existing game ?
  778. //
  779. // return : <int> service selected, starting from 1
  780. //
  781. int Game::mp_select_service()
  782. {
  783. #ifdef IMAGICMP
  784. enum { BUTTON_NUM = 5 };
  785. static short buttonX[BUTTON_NUM] = { 171, 171, 171, 171, 171 };
  786. static short buttonY[BUTTON_NUM] = { 57, 125, 193, 261, 329 };
  787. #define SERVICE_BUTTON_WIDTH 459
  788. #define SERVICE_BUTTON_HEIGHT 67
  789. enum { DESC_MARGIN = 10, DESC_TOP_MARGIN = 6 };
  790. #else
  791. enum { BUTTON_NUM = 4 };
  792. static short buttonX[BUTTON_NUM] = { 206, 412, 206, 412 };
  793. static short buttonY[BUTTON_NUM] = { 94, 94, 254, 254 };
  794. #define SERVICE_BUTTON_WIDTH SERVICE_OPTION_X_SPACE
  795. #define SERVICE_BUTTON_HEIGHT SERVICE_OPTION_HEIGHT
  796. #endif
  797. #define SVOPTION_PAGE 0x00000001
  798. #define SVOPTION_ALL 0x0fffffff
  799. int refreshFlag = SVOPTION_ALL;
  800. // -------- display button ---------//
  801. Button3D returnButton;
  802. returnButton.create(520, 538, "CANCEL-U", "CANCEL-D", 1, 0);
  803. ButtonCustom serviceButton[BUTTON_NUM];
  804. int b;
  805. for( b = 0; b < BUTTON_NUM && mp_obj.get_service_provider(b+1); ++b )
  806. {
  807. serviceButton[b].create(buttonX[b], buttonY[b],
  808. buttonX[b]+SERVICE_BUTTON_WIDTH-1, buttonY[b]+SERVICE_BUTTON_HEIGHT-1,
  809. disp_virtual_button, ButtonCustomPara(NULL,0) );
  810. }
  811. int buttonCount = b;
  812. int choice = 0;
  813. vga_front.unlock_buf();
  814. //-------- detect buttons ---------//
  815. while(1)
  816. {
  817. MSG msg;
  818. if (PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE))
  819. {
  820. if (!GetMessage( &msg, NULL, 0, 0))
  821. {
  822. sys.signal_exit_flag = 1;
  823. // BUGHERE : vga_front is unlocked
  824. return 0;
  825. }
  826. TranslateMessage(&msg);
  827. DispatchMessage(&msg);
  828. continue;
  829. }
  830. else if( sys.paused_flag || !sys.active_flag )
  831. {
  832. WaitMessage();
  833. continue;
  834. }
  835. if( sys.need_redraw_flag )
  836. {
  837. refreshFlag = SVOPTION_ALL;
  838. sys.need_redraw_flag = 0;
  839. }
  840. vga_front.lock_buf();
  841. sys.yield();
  842. mouse.get_event();
  843. if( refreshFlag )
  844. {
  845. if( refreshFlag & SVOPTION_PAGE )
  846. {
  847. //--------- display interface screen -------//
  848. image_menu.put_to_buf( &vga_back, "MPG-PG1" );
  849. #ifdef IMAGICMP
  850. // protection : image_menu.put_to_buf( &vga_back, "MPG-PG1");
  851. // ensure the user has the release version (I_MENU.RES)
  852. // image_menu2.put_to_buf( &vga_back, "MPG-PG1") get the real one
  853. image_menu2.put_to_buf( &vga_back, "MPG-PG1");
  854. #endif
  855. image_menu.put_back( 234, 15,
  856. sub_game_mode == 0 ? (char*)"TOP-NMPG" : (char*)"TOP-LMPG" );
  857. vga.blt_buf(0, 0, vga_back.buf_width()-1, vga_back.buf_height()-1, 0);
  858. returnButton.paint();
  859. for( b = 0; b < buttonCount; ++b )
  860. {
  861. #ifdef IMAGICMP
  862. int y = buttonY[b]+DESC_TOP_MARGIN;
  863. // write service name to back buffer
  864. char useBack = vga.use_back_buf;
  865. vga.use_back();
  866. font_bible.center_put(buttonX[b], y,
  867. buttonX[b]+SERVICE_BUTTON_WIDTH-1, y+font_bible.max_font_height-1,
  868. mp_obj.get_service_provider(b+1)->name_str());
  869. y += font_bible.max_font_height;
  870. if( mp_obj.get_service_provider(b+1)->name_str_long() )
  871. {
  872. font_san.put_paragraph(buttonX[b]+DESC_MARGIN, y,
  873. buttonX[b]+SERVICE_BUTTON_WIDTH-DESC_MARGIN-1, buttonY[b]+SERVICE_BUTTON_HEIGHT-1,
  874. mp_obj.get_service_provider(b+1)->name_str_long());
  875. }
  876. if( !useBack )
  877. vga.use_front();
  878. #endif
  879. serviceButton[b].paint();
  880. }
  881. }
  882. refreshFlag = 0;
  883. }
  884. sys.blt_virtual_buf(); // blt the virtual front buffer to the screen
  885. if( config.music_flag )
  886. {
  887. if( !music.is_playing() )
  888. music.play(1, sys.cdrom_drive ? MUSIC_CD_THEN_WAV : 0 );
  889. }
  890. else
  891. music.stop();
  892. // ------- detect next button -------//
  893. if( returnButton.detect() )
  894. {
  895. choice = 0;
  896. break;
  897. }
  898. // ------- detect protocol button ---------//
  899. for( b = 0; b < buttonCount; ++b )
  900. {
  901. if( serviceButton[b].detect())
  902. {
  903. // let the button look pushed
  904. serviceButton[b].paint(1);
  905. choice = b+1;
  906. break;
  907. }
  908. }
  909. if( choice)
  910. break;
  911. vga_front.unlock_buf();
  912. }
  913. if( !vga_front.buf_locked )
  914. vga_front.lock_buf();
  915. return choice;
  916. }
  917. //--------- End of function Game::mp_select_service ---------//
  918. //-------- Begin of function Game::mp_select_mode --------//
  919. // return 0 = cancel, 1 = create, 2 = join
  920. int Game::mp_select_mode(char *defSaveFileName)
  921. {
  922. #ifdef IMAGICMP
  923. enum { BUTTON_NUM = 5 };
  924. static short buttonX[BUTTON_NUM] = { 171, 171, 171, 171, 171 };
  925. static short buttonY[BUTTON_NUM] = { 57, 125, 193, 261, 329 };
  926. #define SERVICE_BUTTON_WIDTH 459
  927. #define SERVICE_BUTTON_HEIGHT 67
  928. enum { DESC_MARGIN = 10, DESC_TOP_MARGIN = 6 };
  929. #else
  930. enum { BUTTON_NUM = 4 };
  931. static short buttonX[BUTTON_NUM] = { 206, 412, 206, 412 };
  932. static short buttonY[BUTTON_NUM] = { 94, 94, 254, 254 };
  933. #define SERVICE_BUTTON_WIDTH SERVICE_OPTION_X_SPACE
  934. #define SERVICE_BUTTON_HEIGHT SERVICE_OPTION_HEIGHT
  935. #endif
  936. #define SMOPTION_GETA(n) (1 << n)
  937. #define SMOPTION_GETA_ALL 0x0000000f
  938. #define SMOPTION_PAGE 0x08000000
  939. #define SMOPTION_ALL 0x0fffffff
  940. int refreshFlag = SMOPTION_ALL;
  941. Button3D createButton, joinButton, returnButton;
  942. // ####### begin Gilbert 13/2 ##########//
  943. if( mp_obj.get_lobbied_name() )
  944. {
  945. strncpy(config.player_name, mp_obj.get_lobbied_name(), Config::PLAYER_NAME_LEN );
  946. config.player_name[Config::PLAYER_NAME_LEN] = '\0';
  947. }
  948. createButton.create(120, 538, "CREATE-U", "CREATE-D", 1, 0);
  949. if( mp_obj.is_lobbied() == 2 ) // join only
  950. createButton.enable_flag = 0; // avoid paint();
  951. joinButton.create(320, 538, "JOIN-U", "JOIN-D", 1, 0);
  952. if( mp_obj.is_lobbied() == 1 ) // join only
  953. joinButton.enable_flag = 0; // avoid paint();
  954. // ####### end Gilbert 13/2 ##########//
  955. returnButton.create(520, 538, "CANCEL-U", "CANCEL-D", 1, 0);
  956. //Get get_name;
  957. //get_name.field( 374, 470, config.player_name, Config::PLAYER_NAME_LEN, 574 );
  958. char saveFileName[8+1]; // save game name without path or extension
  959. if( defSaveFileName )
  960. {
  961. int newLen = m.str_str(defSaveFileName, "." );
  962. if( newLen > 1)
  963. m.str_cut(saveFileName, defSaveFileName, 1, newLen-1);
  964. else
  965. err_here();
  966. if( m.str_icmpx(saveFileName, "AUTO") || m.str_icmpx(saveFileName, "AUTO2") )
  967. {
  968. strcpy(saveFileName, "MULTI");
  969. }
  970. }
  971. else
  972. {
  973. strcpy(saveFileName, "MULTI");
  974. }
  975. //GetA getName, getSaveFile;
  976. //getName.init( 319, 423, 582, config.player_name, Config::PLAYER_NAME_LEN, &font_san, 0);
  977. //getName.enable_flag = !sub_game_mode; // disable the first input, all input
  978. //getName.paint();
  979. //getSaveFile.init( 394, 447, 582, saveFileName, 8, &font_san, 0);
  980. //getSaveFile.enable_flag = 0;
  981. //getSaveFile.paint();
  982. GetAGroup keyInField(2);
  983. GetA &getName = keyInField[0];
  984. GetA &getSaveFile = keyInField[1];
  985. getName.init( 319, 423, 582, config.player_name, Config::PLAYER_NAME_LEN, &font_san, 0 ,1);
  986. getSaveFile.init( 394, 447, 582, saveFileName, 8, &font_san, 0, 1);
  987. keyInField.set_focus(0, 0); // 0 in 2nd parameter - don't display
  988. int rc = 0;
  989. vga_front.unlock_buf();
  990. while(1)
  991. {
  992. MSG msg;
  993. if (PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE))
  994. {
  995. if (!GetMessage( &msg, NULL, 0, 0))
  996. {
  997. sys.signal_exit_flag = 1;
  998. // BUGHERE : vga_front is unlocked
  999. return 0;
  1000. }
  1001. TranslateMessage(&msg);
  1002. DispatchMessage(&msg);
  1003. continue;
  1004. }
  1005. else if( sys.paused_flag || !sys.active_flag )
  1006. {
  1007. WaitMessage();
  1008. continue;
  1009. }
  1010. if( sys.need_redraw_flag )
  1011. {
  1012. refreshFlag = SMOPTION_ALL;
  1013. sys.need_redraw_flag = 0;
  1014. }
  1015. vga_front.lock_buf();
  1016. sys.yield();
  1017. mouse.get_event();
  1018. if( refreshFlag )
  1019. {
  1020. if( refreshFlag & SMOPTION_PAGE )
  1021. {
  1022. //--------- display interface screen -------//
  1023. image_menu.put_to_buf( &vga_back, "MPG-PG1" );
  1024. #ifdef IMAGICMP
  1025. // protection : image_menu.put_to_buf( &vga_back, "MPG-PG1");
  1026. // ensure the user has the release version (I_MENU.RES)
  1027. // image_menu2.put_to_buf( &vga_back, "MPG-PG1") get the real one
  1028. image_menu2.put_to_buf( &vga_back, "MPG-PG1");
  1029. #endif
  1030. image_menu.put_back( 234, 15,
  1031. sub_game_mode == 0 ? (char*)"TOP-NMPG" : (char*)"TOP-LMPG" );
  1032. #ifdef IMAGICMP
  1033. int b = 0;
  1034. for( b = 0; mp_obj.get_service_provider(b+1); ++b )
  1035. {
  1036. int y = buttonY[b]+DESC_TOP_MARGIN;
  1037. // write service name to back buffer
  1038. char useBack = vga.use_back_buf;
  1039. vga.use_back();
  1040. font_bible.center_put(buttonX[b], y,
  1041. buttonX[b]+SERVICE_BUTTON_WIDTH-1, y+font_bible.max_font_height-1,
  1042. mp_obj.get_service_provider(b+1)->name_str());
  1043. y += font_bible.max_font_height;
  1044. if( mp_obj.get_service_provider(b+1)->name_str_long() )
  1045. {
  1046. font_san.put_paragraph(buttonX[b]+DESC_MARGIN, y,
  1047. buttonX[b]+SERVICE_BUTTON_WIDTH-DESC_MARGIN-1, buttonY[b]+SERVICE_BUTTON_HEIGHT-1,
  1048. mp_obj.get_service_provider(b+1)->name_str_long());
  1049. }
  1050. if( !useBack )
  1051. vga.use_front();
  1052. }
  1053. #endif
  1054. vga.blt_buf(0, 0, vga_back.buf_width()-1, vga_back.buf_height()-1, 0);
  1055. if( createButton.enable_flag )
  1056. createButton.paint();
  1057. if( joinButton.enable_flag )
  1058. joinButton.paint();
  1059. returnButton.paint();
  1060. }
  1061. if( refreshFlag & SMOPTION_GETA_ALL )
  1062. {
  1063. keyInField.paint();
  1064. }
  1065. refreshFlag = 0;
  1066. }
  1067. sys.blt_virtual_buf(); // blt the virtual front buffer to the screen
  1068. if( config.music_flag )
  1069. {
  1070. if( !music.is_playing() )
  1071. music.play(1, sys.cdrom_drive ? MUSIC_CD_THEN_WAV : 0 );
  1072. }
  1073. else
  1074. music.stop();
  1075. if( keyInField.detect() )
  1076. {
  1077. // refreshFlag |= SMOPTION_GETA_ALL;
  1078. }
  1079. else if( returnButton.detect() )
  1080. {
  1081. rc = 0;
  1082. break;
  1083. }
  1084. else if( createButton.detect() )
  1085. {
  1086. rc = 1;
  1087. }
  1088. else if( joinButton.detect() )
  1089. {
  1090. rc = 2;
  1091. }
  1092. if( rc )
  1093. {
  1094. // check saveFileName is AUTO*
  1095. if( m.str_icmpx(getSaveFile.input_field, "AUTO") ||
  1096. m.str_icmpx(getSaveFile.input_field, "AUTO2") )
  1097. {
  1098. if( !box.ask("It is not recommended to use this save game file name, do you wish to continue?") )
  1099. {
  1100. rc = 0;
  1101. }
  1102. }
  1103. }
  1104. if( rc )
  1105. {
  1106. // correct saveFileName
  1107. int newLen;
  1108. if( (newLen = m.str_str(getSaveFile.input_field, ".")) > 0 )
  1109. {
  1110. m.str_cut(getSaveFile.input_field, getSaveFile.input_field, 1, newLen-1);
  1111. }
  1112. if( strlen(getSaveFile.input_field) == 0 )
  1113. {
  1114. // empty, set back to default save game name
  1115. strcpy( getSaveFile.input_field, "MULTI" );
  1116. }
  1117. strcpy(remote.save_file_name, saveFileName);
  1118. strcat(remote.save_file_name, ".SVM");
  1119. break;
  1120. }
  1121. vga_front.unlock_buf();
  1122. }
  1123. if( !vga_front.buf_locked )
  1124. vga_front.lock_buf();
  1125. return rc;
  1126. }
  1127. //-------- End of function Game::mp_select_mode --------//
  1128. //-------- Begin of function Game::mp_select_session --------//
  1129. int Game::mp_select_session()
  1130. {
  1131. #define SSOPTION_PAGE 0x00000010
  1132. #define SSOPTION_POLL_SESSION 0x00000001
  1133. #define SSOPTION_DISP_SESSION 0x00000002
  1134. #ifdef AMPLUS
  1135. #define SSOPTION_SCROLL_BAR 0x00000004
  1136. #endif
  1137. #define SSOPTION_ALL 0x7fffffff
  1138. enum { JOIN_BUTTON_X = 320, JOIN_BUTTON_Y = 538 };
  1139. enum { CANCEL_BUTTON_X = 520, CANCEL_BUTTON_Y = 538 };
  1140. #ifdef AMPLUS
  1141. enum { SESSION_BUTTON_X1 = 30, SESSION_BUTTON_Y1 = 160 };
  1142. enum { SESSION_BUTTON_Y_SPACING = 44, MAX_BUTTON = 8 };
  1143. enum { SESSION_BUTTON_X2 = 754,
  1144. SESSION_DESC_Y1 = SESSION_BUTTON_Y1+14,
  1145. SESSION_DESC_X1 = SESSION_BUTTON_X1 + 14, SESSION_DESC_X2 = SESSION_BUTTON_X2,
  1146. SESSION_BUTTON_Y2 = SESSION_BUTTON_Y1 + MAX_BUTTON * SESSION_BUTTON_Y_SPACING-1};
  1147. enum { SCROLL_X1=757, SCROLL_Y1 = 176, SCROLL_X2 = 770, SCROLL_Y2 = 493 };
  1148. #else
  1149. enum { SESSION_BUTTON_X1 = 108, SESSION_BUTTON_Y1 = 125 };
  1150. enum { SESSION_BUTTON_Y_SPACING = BASIC_OPTION_HEIGHT, MAX_BUTTON = 6 };
  1151. enum { SESSION_BUTTON_X2 = SESSION_BUTTON_X1 + BASIC_OPTION_X_SPACE-1,
  1152. SESSION_DESC_Y1 = SESSION_BUTTON_Y1+10,
  1153. SESSION_DESC_X1 = SESSION_BUTTON_X2 + 8, SESSION_DESC_X2 = 600,
  1154. SESSION_BUTTON_Y2 = SESSION_BUTTON_Y1 + MAX_BUTTON * SESSION_BUTTON_Y_SPACING-1};
  1155. #endif
  1156. // ####### begin Gilbert 13/2 ########//
  1157. if( mp_obj.is_lobbied() == 2 ) // join session, but selected in lobby
  1158. {
  1159. return 1;
  1160. }
  1161. // ####### end Gilbert 13/2 ########//
  1162. unsigned long refreshTime;
  1163. int refreshFlag = SSOPTION_ALL;
  1164. int choice = 0;
  1165. SessionIdType sessionGuid;
  1166. memset(&sessionGuid, 0, sizeof(sessionGuid));
  1167. // ------- initialized button -----------//
  1168. Button3D joinButton;
  1169. joinButton.create(JOIN_BUTTON_X, JOIN_BUTTON_Y, "JOIN-U", "JOIN-D", 1, 0);
  1170. joinButton.disable();
  1171. Button3D cancelButton;
  1172. cancelButton.create(CANCEL_BUTTON_X, CANCEL_BUTTON_Y, "CANCEL-U", "CANCEL-D", 1, 0);
  1173. #ifdef AMPLUS
  1174. SlideVBar scrollBar;
  1175. scrollBar.init_scroll(SCROLL_X1, SCROLL_Y1, SCROLL_X2, SCROLL_Y2,
  1176. MAX_BUTTON, disp_scroll_bar_func);
  1177. scrollBar.set(1, 1, 1); // assume it has one record
  1178. Button3D scrollUp;
  1179. scrollUp.create(SCROLL_X1,SCROLL_Y1-17, "SV-UP-U", "SV-UP-D", 1, 0);
  1180. Button3D scrollDown;
  1181. scrollDown.create(SCROLL_X1,SCROLL_Y2+1, "SV-DW-U", "SV-DW-D", 1, 0);
  1182. Blob browseArea[MAX_BUTTON];
  1183. #define BASE_SESSION scrollBar.view_recno
  1184. #else
  1185. #define BASE_SESSION 1
  1186. #endif
  1187. unsigned long pollTime = 1000;
  1188. vga_front.unlock_buf();
  1189. while(1)
  1190. {
  1191. int s;
  1192. int b;
  1193. MSG msg;
  1194. if (PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE))
  1195. {
  1196. if (!GetMessage( &msg, NULL, 0, 0))
  1197. {
  1198. sys.signal_exit_flag = 1;
  1199. // BUGHERE : vga_front is unlocked
  1200. return 0;
  1201. }
  1202. TranslateMessage(&msg);
  1203. DispatchMessage(&msg);
  1204. continue;
  1205. }
  1206. else if( sys.paused_flag || !sys.active_flag )
  1207. {
  1208. WaitMessage();
  1209. continue;
  1210. }
  1211. if( sys.need_redraw_flag )
  1212. {
  1213. refreshFlag = SSOPTION_ALL;
  1214. sys.need_redraw_flag = 0;
  1215. }
  1216. vga_front.lock_buf();
  1217. sys.yield();
  1218. mouse.get_event();
  1219. if( refreshFlag )
  1220. {
  1221. if( refreshFlag & SSOPTION_PAGE )
  1222. {
  1223. // --------- display interface screen -------//
  1224. image_menu.put_to_buf( &vga_back, "MPG-PG2" );
  1225. #ifdef AMPLUS
  1226. image_menu2.put_to_buf( &vga_back, "MPG-PG2" );
  1227. #endif
  1228. image_menu.put_back( 234, 15,
  1229. sub_game_mode == 0 ? (char*)"TOP-NMPG" : (char*)"TOP-LMPG" );
  1230. vga.blt_buf(0, 0, vga_back.buf_width()-1, vga_back.buf_height()-1, 0);
  1231. #ifdef AMPLUS
  1232. scrollBar.paint();
  1233. scrollUp.paint();
  1234. scrollDown.paint();
  1235. // capture into browseArea, scrollArea, textArea
  1236. for( b = 0; b < MAX_BUTTON; ++b)
  1237. {
  1238. browseArea[b].resize(2*sizeof(short) + (SESSION_BUTTON_X2-SESSION_BUTTON_X1+1)*SESSION_BUTTON_Y_SPACING);
  1239. vga_front.read_bitmap(
  1240. SESSION_BUTTON_X1, b*SESSION_BUTTON_Y_SPACING+SESSION_BUTTON_Y1,
  1241. SESSION_BUTTON_X2, (b+1)*SESSION_BUTTON_Y_SPACING+SESSION_BUTTON_Y1-1,
  1242. browseArea[b].ptr);
  1243. }
  1244. #endif
  1245. joinButton.paint();
  1246. cancelButton.paint();
  1247. }
  1248. if( refreshFlag & SSOPTION_POLL_SESSION )
  1249. {
  1250. pollTime = m.get_time();
  1251. if( !mp_obj.poll_sessions() )
  1252. {
  1253. // return fail if poll_sessions fails or cancel the dialogue box
  1254. choice = 0;
  1255. break;
  1256. }
  1257. // limit the pollTime between 1 sec to 10 sec
  1258. pollTime = m.get_time() - pollTime + 1000;
  1259. if( pollTime > 10000 )
  1260. pollTime = 10000;
  1261. refreshTime = m.get_time();
  1262. #ifdef AMPLUS
  1263. // ------- sort by name ---------//
  1264. mp_obj.sort_sessions(2); // sort by session name
  1265. #endif
  1266. // ------- update choice ---------- //
  1267. choice = 0;
  1268. for( s = 1; mp_obj.get_session(s); ++s )
  1269. {
  1270. if( sessionGuid == mp_obj.get_session(s)->session_id() )
  1271. choice = s;
  1272. }
  1273. if( choice > 0)
  1274. joinButton.enable();
  1275. else
  1276. joinButton.disable();
  1277. //------- update scroll bar --------//
  1278. // BUGHERE : error if empty
  1279. #ifdef AMPLUS
  1280. scrollBar.set(1, s-1, scrollBar.view_recno);
  1281. refreshFlag |= SSOPTION_SCROLL_BAR;
  1282. #endif
  1283. refreshFlag |= SSOPTION_DISP_SESSION;
  1284. }
  1285. if( refreshFlag & SSOPTION_DISP_SESSION )
  1286. {
  1287. #ifndef AMPLUS
  1288. vga.blt_buf(SESSION_BUTTON_X1, SESSION_BUTTON_Y1, SESSION_DESC_X2, SESSION_BUTTON_Y2, 0);
  1289. #endif
  1290. for( b = 0, s = BASE_SESSION; b < MAX_BUTTON; ++b, ++s )
  1291. {
  1292. #ifdef AMPLUS
  1293. vga_back.put_bitmap(
  1294. SESSION_BUTTON_X1, b*SESSION_BUTTON_Y_SPACING+SESSION_BUTTON_Y1,
  1295. browseArea[(s-1)%MAX_BUTTON].ptr);
  1296. vga.blt_buf(
  1297. SESSION_BUTTON_X1, b*SESSION_BUTTON_Y_SPACING+SESSION_BUTTON_Y1,
  1298. SESSION_BUTTON_X2, (b+1)*SESSION_BUTTON_Y_SPACING+SESSION_BUTTON_Y1-1, 0);
  1299. #endif
  1300. if( mp_obj.get_session(s) )
  1301. {
  1302. // display session description
  1303. font_san.put( SESSION_DESC_X1, SESSION_DESC_Y1 + b*SESSION_BUTTON_Y_SPACING,
  1304. mp_obj.get_session(s)->name_str(), 0, SESSION_DESC_X2 );
  1305. // display cursor
  1306. if( s == choice )
  1307. {
  1308. vga_front.adjust_brightness( SESSION_BUTTON_X1, SESSION_BUTTON_Y1 + b*SESSION_BUTTON_Y_SPACING,
  1309. SESSION_BUTTON_X2, SESSION_BUTTON_Y1 + (b+1)*SESSION_BUTTON_Y_SPACING-1, -2);
  1310. #ifndef AMPLUS
  1311. image_interface.put_front(SESSION_BUTTON_X1, SESSION_BUTTON_Y1 + b*SESSION_BUTTON_Y_SPACING, "BAS_DOWN" );
  1312. #endif
  1313. }
  1314. }
  1315. }
  1316. }
  1317. #ifdef AMPLUS
  1318. if( refreshFlag & SSOPTION_SCROLL_BAR )
  1319. {
  1320. scrollBar.paint();
  1321. }
  1322. #endif
  1323. refreshFlag = 0;
  1324. }
  1325. sys.blt_virtual_buf(); // blt the virtual front buffer to the screen
  1326. if( config.music_flag )
  1327. {
  1328. if( !music.is_playing() )
  1329. music.play(1, sys.cdrom_drive ? MUSIC_CD_THEN_WAV : 0 );
  1330. }
  1331. else
  1332. music.stop();
  1333. #ifdef AMPLUS
  1334. int scrollRc = scrollBar.detect();
  1335. if( scrollRc )
  1336. {
  1337. // refreshFlag |= SSOPTION_SCROLL_BAR;
  1338. // dragging scroll bar, don't poll session
  1339. refreshFlag &= ~SSOPTION_POLL_SESSION;
  1340. // suspend the refreshTime, so session list won't update immediate after release dragging
  1341. refreshTime = m.get_time();
  1342. if( scrollRc == 1)
  1343. refreshFlag |= SSOPTION_DISP_SESSION;
  1344. }
  1345. else
  1346. #endif
  1347. {
  1348. for( b = 0, s = BASE_SESSION; b < MAX_BUTTON && mp_obj.get_session(s) ; ++b, ++s )
  1349. {
  1350. if( mouse.single_click( SESSION_BUTTON_X1, SESSION_BUTTON_Y1 + (b)*SESSION_BUTTON_Y_SPACING,
  1351. SESSION_DESC_X2, SESSION_BUTTON_Y1 + (b+1)*SESSION_BUTTON_Y_SPACING -1 ) )
  1352. {
  1353. choice = s;
  1354. sessionGuid = mp_obj.get_session(s)->session_id();
  1355. refreshFlag |= SSOPTION_DISP_SESSION;
  1356. joinButton.enable();
  1357. // suspend the refreshTime, so session list won't update immediate after release dragging
  1358. refreshTime = m.get_time();
  1359. }
  1360. }
  1361. #ifdef AMPLUS
  1362. if( scrollUp.detect() )
  1363. {
  1364. int oldValue = scrollBar.view_recno;
  1365. if( oldValue != scrollBar.set_view_recno(oldValue-1) )
  1366. refreshFlag |= SSOPTION_DISP_SESSION | SSOPTION_SCROLL_BAR;
  1367. }
  1368. if( scrollDown.detect() )
  1369. {
  1370. int oldValue = scrollBar.view_recno;
  1371. if( oldValue != scrollBar.set_view_recno(oldValue+1) )
  1372. refreshFlag |= SSOPTION_DISP_SESSION | SSOPTION_SCROLL_BAR;
  1373. }
  1374. #endif
  1375. if( choice > 0 && joinButton.detect() )
  1376. break;
  1377. if( cancelButton.detect() )
  1378. {
  1379. choice = 0;
  1380. break;
  1381. }
  1382. if( !(mouse.skey_state & SHIFT_KEY_MASK) && m.get_time() - refreshTime > pollTime )
  1383. refreshFlag |= SSOPTION_POLL_SESSION | SSOPTION_DISP_SESSION;
  1384. }
  1385. vga_front.unlock_buf();
  1386. }
  1387. if( !vga_front.buf_locked )
  1388. vga_front.lock_buf();
  1389. return choice;
  1390. }
  1391. //-------- End of function Game::mp_select_session --------//
  1392. // define bit flag for refreshFlag
  1393. #define SGOPTION_PAGE 0x40000000
  1394. #define SGOPTION_RACE 0x00000001
  1395. #define SGOPTION_COLOR 0x00000002
  1396. #define SGOPTION_AI_NATION 0x00000004
  1397. #define SGOPTION_DIFFICULTY 0x00000008
  1398. #define SGOPTION_TERRAIN 0x00000010
  1399. #define SGOPTION_LAND_MASS 0x00000020
  1400. // #### begin Gilbert 25/10 #######//
  1401. // #define SGOPTION_NAME_FIELD 0x00000040
  1402. #define SGOPTION_MAP_ID 0x00000080
  1403. // #### end Gilbert 25/10 #######//
  1404. #define SGOPTION_EXPLORED 0x00000100
  1405. #define SGOPTION_FOG 0x00000200
  1406. #define SGOPTION_TREASURE 0x00000400
  1407. #define SGOPTION_AI_TREASURE 0x00000800
  1408. #define SGOPTION_AI_AGGRESSIVE 0x00001000
  1409. #define SGOPTION_FRYHTANS 0x00002000
  1410. #define SGOPTION_RANDOM_STARTUP 0x00004000
  1411. #define SGOPTION_RAW 0x00010000
  1412. #define SGOPTION_NEAR_RAW 0x00020000
  1413. #define SGOPTION_START_TOWN 0x00040000
  1414. #define SGOPTION_TOWN_STRENGTH 0x00080000
  1415. #define SGOPTION_TOWN_EMERGE 0x00100000
  1416. #define SGOPTION_KINGDOM_EMERGE 0x00200000
  1417. #define SGOPTION_RANDOM_EVENT 0x00400000
  1418. #define SGOPTION_CLEAR_ENEMY 0x01000000
  1419. #define SGOPTION_CLEAR_MONSTER 0x02000000
  1420. #define SGOPTION_ENOUGH_PEOPLE 0x04000000
  1421. #define SGOPTION_ENOUGH_INCOME 0x08000000
  1422. // ##### begin Gilbert 25/10 #######//
  1423. #define SGOPTION_ENOUGH_SCORE 0x10000000
  1424. #define SGOPTION_TIME_LIMIT 0x20000000
  1425. // ##### end Gilbert 25/10 #######//
  1426. #define SGOPTION_ALL 0x7fffffff
  1427. #define SGOPTION_ALL_OPTIONS (SGOPTION_ALL & ~SGOPTION_PAGE & ~SGOPTION_MAP_ID)
  1428. #define MGOPTION_PLAYERS 0x00000001
  1429. #define MGOPTION_IN_MESSAGE 0x00000002
  1430. #define MGOPTION_OUT_MESSAGE 0x00000004
  1431. #define MGOPTION_ALL 0x7fffffff
  1432. //-------- Begin of function Game::mp_select_option -----------//
  1433. // return 0 = cancel, 1 = ok
  1434. int Game::mp_select_option(NewNationPara *nationPara, int *mpPlayerCount)
  1435. {
  1436. const int offsetY = 212;
  1437. char optionMode = OPTION_BASIC;
  1438. char menuTitleBitmap[] = "TOP-NMPG";
  1439. Config tempConfig = config;
  1440. tempConfig.reset_cheat_setting();
  1441. // some setting may be modified in the last game
  1442. if( tempConfig.difficulty_level != OPTION_CUSTOM )
  1443. tempConfig.change_difficulty(tempConfig.difficulty_level);
  1444. PID_TYPE from, to;
  1445. DWORD recvLen;
  1446. int sysMsgCount;
  1447. char *recvPtr;
  1448. char raceAssigned[MAX_RACE]; // master copy belongs to host's
  1449. char colorAssigned[MAX_COLOR_SCHEME]; // master copy belongs to host's
  1450. //static short raceX[MAX_RACE] = {390, 313, 236, 467, 390, 236, 313};
  1451. //static short raceY[MAX_RACE] = {276, 276, 276, 276, 243, 243, 243};
  1452. //const raceWidth = 77;
  1453. //const raceHeight = 33;
  1454. //static short colorX[MAX_COLOR_SCHEME] = {545, 581, 581, 617, 617, 545, 653};
  1455. //static short colorY[MAX_COLOR_SCHEME] = {243, 276, 243, 276, 243, 276, 276};
  1456. //const colorWidth = 36;
  1457. //const colorHeight = 33;
  1458. static short tickX[MAX_NATION] = { 103, 254, 405, 556, 103, 254, 405 };
  1459. static short tickY[MAX_NATION] = { 53, 53, 53, 53, 73, 73, 73 };
  1460. const int nameOffsetX = 23;
  1461. const int nameOffsetY = 3;
  1462. DynArray messageList(sizeof(MpStructChatMsg));
  1463. MpStructChatMsg typingMsg(tempConfig.player_name, NULL);
  1464. memset( raceAssigned, 0, sizeof(raceAssigned) );
  1465. memset( colorAssigned, 0, sizeof(colorAssigned) );
  1466. PID_TYPE hostPlayerId = 0;
  1467. PID_TYPE regPlayerId[MAX_NATION];
  1468. memset( regPlayerId, 0, sizeof(regPlayerId) );
  1469. char playerReadyFlag[MAX_NATION];
  1470. memset( playerReadyFlag, 0, sizeof(playerReadyFlag) );
  1471. short playerRace[MAX_NATION]; // host only
  1472. memset( playerRace, 0, sizeof(playerRace) );
  1473. short playerColor[MAX_NATION]; // host only
  1474. memset( playerColor, 0, sizeof(playerColor) );
  1475. short playerBalance[MAX_NATION];
  1476. memset( playerBalance, 0, sizeof(playerBalance) );
  1477. int regPlayerCount = 0;
  1478. int selfReadyFlag = 0;
  1479. int shareRace = 1; // host only, 0= exclusive race of each player
  1480. mp_obj.poll_players();
  1481. int p;
  1482. for( p = 1; p <= MAX_NATION && mp_obj.get_player(p); ++p )
  1483. {
  1484. // host only identify himself
  1485. if( !remote.is_host || mp_obj.get_player(p)->pid() == mp_obj.my_player_id )
  1486. {
  1487. regPlayerId[regPlayerCount] = mp_obj.get_player(p)->pid();
  1488. playerReadyFlag[regPlayerCount] = 0;
  1489. playerColor[regPlayerCount] = 0;
  1490. playerRace[regPlayerCount] = 0;
  1491. playerBalance[regPlayerCount] = 0;
  1492. ++regPlayerCount;
  1493. }
  1494. }
  1495. int i;
  1496. long refreshFlag = SGOPTION_ALL;
  1497. // ####### begin Gilbert 25/10 #####//
  1498. long mRefreshFlag = MGOPTION_ALL;
  1499. // ####### end Gilbert 25/10 #####//
  1500. int retFlag = 0;
  1501. // randomly select a race
  1502. if( remote.is_host )
  1503. {
  1504. tempConfig.race_id = char(mp_obj.my_player_id % MAX_RACE + 1);
  1505. raceAssigned[tempConfig.race_id-1] = 1;
  1506. tempConfig.player_nation_color = 1;
  1507. colorAssigned[tempConfig.player_nation_color-1] = 1;
  1508. for( p = 0; p < regPlayerCount && regPlayerId[p] != mp_obj.my_player_id; ++p );
  1509. if( p < regPlayerCount )
  1510. {
  1511. playerRace[p] = tempConfig.race_id;
  1512. playerColor[p] = tempConfig.player_nation_color;
  1513. playerBalance[p] = sys.cdrom_drive ? PLAYER_RATIO_CDROM : PLAYER_RATIO_NOCD;
  1514. }
  1515. }
  1516. else
  1517. {
  1518. tempConfig.race_id = 0;
  1519. tempConfig.player_nation_color = 0;
  1520. // ask host for a race and color code
  1521. MpStructNewPlayer msgNewPlayer( mp_obj.my_player_id,
  1522. sys.cdrom_drive ? PLAYER_RATIO_CDROM : PLAYER_RATIO_NOCD );
  1523. mp_obj.send_stream(BROADCAST_PID, &msgNewPlayer, sizeof(msgNewPlayer) );
  1524. }
  1525. // --------- initialize race button group ---------- //
  1526. ButtonCustomGroup raceGroup(MAX_RACE);
  1527. for( i = 0; i < MAX_RACE; ++i )
  1528. {
  1529. #if(MAX_RACE == 10)
  1530. raceGroup[i].create(220+(i%5)*BASIC_OPTION_X_SPACE, (i/5)*BASIC_OPTION_HEIGHT+offsetY+70,
  1531. 220+(i%5+1)*BASIC_OPTION_X_SPACE-1, (i/5+1)*BASIC_OPTION_HEIGHT+offsetY+70-1,
  1532. disp_virtual_button, ButtonCustomPara(&raceGroup, race_table[i]), 0, 0);
  1533. #define Y_SHIFT_FLAG 1
  1534. #else
  1535. raceGroup[i].create(118+i*BASIC_OPTION_X_SPACE, offsetY+93,
  1536. 118+(i+1)*BASIC_OPTION_X_SPACE-1, offsetY+93+BASIC_OPTION_HEIGHT-1,
  1537. disp_virtual_button, ButtonCustomPara(&raceGroup, race_table[i]), 0, 0);
  1538. #define Y_SHIFT_FLAG 0
  1539. #endif
  1540. }
  1541. // --------- initialize color button group ---------- //
  1542. ButtonCustomGroup colorGroup(MAX_COLOR_SCHEME);
  1543. for( i = 0; i < MAX_COLOR_SCHEME; ++i )
  1544. {
  1545. #if(Y_SHIFT_FLAG)
  1546. #define Y_SHIFT 13
  1547. #else
  1548. #define Y_SHIFT 0
  1549. #endif
  1550. colorGroup[i].create(195+i*COLOR_OPTION_X_SPACE, offsetY+139+Y_SHIFT,
  1551. 195+(i+1)*COLOR_OPTION_X_SPACE-1, offsetY+139+Y_SHIFT+COLOR_OPTION_HEIGHT-1,
  1552. disp_virtual_button, ButtonCustomPara(&colorGroup, i+1), 0, 0);
  1553. #undef Y_SHIFT
  1554. }
  1555. // ---------- initialize ai_nation_count buttons --------//
  1556. ButtonCustom aiNationInc, aiNationDec;
  1557. {
  1558. #if(Y_SHIFT_FLAG)
  1559. #define Y_SHIFT 13
  1560. #else
  1561. #define Y_SHIFT 0
  1562. #endif
  1563. aiNationInc.create(595, offsetY+139+Y_SHIFT,
  1564. 595+COLOR_OPTION_X_SPACE-1, offsetY+139+Y_SHIFT+COLOR_OPTION_HEIGHT-1,
  1565. disp_virtual_button, ButtonCustomPara(NULL, +1) );
  1566. aiNationDec.create(630, offsetY+139+Y_SHIFT,
  1567. 630+COLOR_OPTION_X_SPACE-1, offsetY+139+Y_SHIFT+COLOR_OPTION_HEIGHT-1,
  1568. disp_virtual_button, ButtonCustomPara(NULL, -1) );
  1569. #undef Y_SHIFT
  1570. }
  1571. // ---------- initialize difficulty_level button group -------//
  1572. ButtonCustomGroup diffGroup(6);
  1573. for( i = 0; i < 6; ++i )
  1574. {
  1575. #if(Y_SHIFT_FLAG)
  1576. #define Y_SHIFT 16
  1577. #else
  1578. #define Y_SHIFT 0
  1579. #endif
  1580. diffGroup[i].create( 205+i*BASIC_OPTION_X_SPACE, offsetY+184+Y_SHIFT,
  1581. 205+(i+1)*BASIC_OPTION_X_SPACE-1, offsetY+184+Y_SHIFT+BASIC_OPTION_HEIGHT-1,
  1582. disp_virtual_button, ButtonCustomPara(&diffGroup, i), 0, 0);
  1583. #undef Y_SHIFT
  1584. }
  1585. // --------- initialize terrain_set button group -------//
  1586. // ##### begin Gilbert 25/10 #######//
  1587. ButtonCustomGroup terrainGroup(3);
  1588. for( i = 0; i < 3; ++i )
  1589. {
  1590. #if(Y_SHIFT_FLAG)
  1591. #define Y_SHIFT 16
  1592. #else
  1593. #define Y_SHIFT 0
  1594. #endif
  1595. #ifdef AMPLUS
  1596. terrainGroup[i].create(166+i*BASIC_OPTION_X_SPACE, offsetY+248+Y_SHIFT,
  1597. 166+(i+1)*BASIC_OPTION_X_SPACE-1, offsetY+248+Y_SHIFT+BASIC_OPTION_HEIGHT-1,
  1598. disp_virtual_button, ButtonCustomPara(&terrainGroup, i+1), 0, 0);
  1599. #else
  1600. int k = i;
  1601. switch(i)
  1602. {
  1603. case 1: k = 2; break;
  1604. case 2: k = 1; break;
  1605. }
  1606. terrainGroup[i].create(205+k*BASIC_OPTION_X_SPACE, offsetY+248+Y_SHIFT,
  1607. 205+(k+1)*BASIC_OPTION_X_SPACE-1, offsetY+248+Y_SHIFT+BASIC_OPTION_HEIGHT-1,
  1608. disp_virtual_button, ButtonCustomPara(&terrainGroup, i+1), 0, 0);
  1609. if( i == 1 )
  1610. terrainGroup[i].enable_flag = 0;
  1611. #endif
  1612. #undef Y_SHIFT
  1613. }
  1614. // ##### end Gilbert 25/10 #######//
  1615. // --------- initialize land_mass button group -------//
  1616. ButtonCustomGroup landGroup(3);
  1617. for( i = 0; i < 3; ++i )
  1618. {
  1619. #if(Y_SHIFT_FLAG)
  1620. #define Y_SHIFT 16
  1621. #else
  1622. #define Y_SHIFT 0
  1623. #endif
  1624. landGroup[i].create(439+i*BASIC_OPTION_X_SPACE, offsetY+248+Y_SHIFT,
  1625. 439+(i+1)*BASIC_OPTION_X_SPACE-1, offsetY+248+Y_SHIFT+BASIC_OPTION_HEIGHT-1,
  1626. disp_virtual_button, ButtonCustomPara(&landGroup, i+1), 0, 0);
  1627. #undef Y_SHIFT
  1628. }
  1629. GetA messageField;
  1630. messageField.init( 190, 116, 700, typingMsg.content,
  1631. MpStructChatMsg::MSG_LENGTH, &font_san, 0, 1);
  1632. // ###### begin Gilbert 25/10 #######//
  1633. // --------- initialize info.random_seed field ----------//
  1634. MpStructSeedStr msgSeedStr(info.random_seed);
  1635. GetA mapIdField;
  1636. #if(defined(SPANISH))
  1637. #define MAPID_X1 588
  1638. #elif(defined(FRENCH))
  1639. #define MAPID_X1 578
  1640. #else
  1641. #define MAPID_X1 564
  1642. #endif
  1643. mapIdField.init( MAPID_X1, offsetY+83, 700, msgSeedStr.seed_str, msgSeedStr.RANDOM_SEED_MAX_LEN, &font_san, 0, 1);
  1644. #undef MAPID_X1
  1645. // ###### end Gilbert 25/10 #######//
  1646. // --------- initialize explore_whole_map button group -------//
  1647. ButtonCustomGroup exploreGroup(2);
  1648. for( i = 0; i < 2; ++i )
  1649. {
  1650. exploreGroup[i].create(335+i*BASIC_OPTION_X_SPACE, offsetY+74,
  1651. 335+(i+1)*BASIC_OPTION_X_SPACE-1, offsetY+74+BASIC_OPTION_HEIGHT-1,
  1652. disp_virtual_button, ButtonCustomPara(&exploreGroup, 1-i), 0, 0);
  1653. }
  1654. // --------- initialize fog_of_war button group -------//
  1655. ButtonCustomGroup fogGroup(2);
  1656. for( i = 0; i < 2; ++i )
  1657. {
  1658. fogGroup[i].create(335+i*BASIC_OPTION_X_SPACE, offsetY+106,
  1659. 335+(i+1)*BASIC_OPTION_X_SPACE-1, offsetY+106+BASIC_OPTION_HEIGHT-1,
  1660. disp_virtual_button, ButtonCustomPara(&fogGroup, 1-i), 0, 0);
  1661. }
  1662. // --------- initialize start_up_cash/start_up_food button group -------//
  1663. ButtonCustomGroup treasureGroup(4);
  1664. for( i = 0; i < 4; ++i )
  1665. {
  1666. treasureGroup[i].create(335+i*BASIC_OPTION_X_SPACE, offsetY+138,
  1667. 335+(i+1)*BASIC_OPTION_X_SPACE-1, offsetY+138+BASIC_OPTION_HEIGHT-1,
  1668. disp_virtual_button, ButtonCustomPara(&treasureGroup, i+1), 0, 0);
  1669. }
  1670. // --------- initialize ai_start_up_cash/food button group -------//
  1671. ButtonCustomGroup aiTreasureGroup(4);
  1672. for( i = 0; i < 4; ++i )
  1673. {
  1674. aiTreasureGroup[i].create(335+i*BASIC_OPTION_X_SPACE, offsetY+170,
  1675. 335+(i+1)*BASIC_OPTION_X_SPACE-1, offsetY+170+BASIC_OPTION_HEIGHT-1,
  1676. disp_virtual_button, ButtonCustomPara(&aiTreasureGroup, i+1), 0, 0);
  1677. }
  1678. // --------- initialize ai_aggressiveness -------//
  1679. ButtonCustomGroup aiAggressiveGroup(4);
  1680. for( i = 0; i < 4; ++i )
  1681. {
  1682. aiAggressiveGroup[i].create(335+i*BASIC_OPTION_X_SPACE, offsetY+202,
  1683. 335+(i+1)*BASIC_OPTION_X_SPACE-1, offsetY+202+BASIC_OPTION_HEIGHT-1,
  1684. disp_virtual_button, ButtonCustomPara(&aiAggressiveGroup, i+1), 0, 0);
  1685. }
  1686. // --------- initialize monster_type -------//
  1687. ButtonCustomGroup monsterGroup(3);
  1688. for( i = 0; i < 3; ++i )
  1689. {
  1690. monsterGroup[i].create(335+i*BASIC_OPTION_X_SPACE, offsetY+234,
  1691. 335+(i+1)*BASIC_OPTION_X_SPACE-1, offsetY+234+BASIC_OPTION_HEIGHT-1,
  1692. disp_virtual_button, ButtonCustomPara(&monsterGroup, i), 0, 0);
  1693. }
  1694. // --------- initialize random startup button group -------//
  1695. ButtonCustomGroup randomStartUpGroup(2);
  1696. for( i = 0; i < 2; ++i )
  1697. {
  1698. randomStartUpGroup[i].create(335+i*BASIC_OPTION_X_SPACE, offsetY+266,
  1699. 335+(i+1)*BASIC_OPTION_X_SPACE-1, offsetY+266+BASIC_OPTION_HEIGHT-1,
  1700. disp_virtual_button, ButtonCustomPara(&randomStartUpGroup, 1-i), 0, 0);
  1701. }
  1702. // -------- initialize start_up_raw_site buttons --------- //
  1703. ButtonCustom rawSiteInc, rawSiteDec;
  1704. rawSiteInc.create( 358, offsetY+72,
  1705. 358+COLOR_OPTION_X_SPACE-1, offsetY+72+COLOR_OPTION_HEIGHT-1,
  1706. disp_virtual_button, ButtonCustomPara(NULL,0));
  1707. rawSiteDec.create( 393, offsetY+72,
  1708. 393+COLOR_OPTION_X_SPACE-1, offsetY+72+COLOR_OPTION_HEIGHT-1,
  1709. disp_virtual_button, ButtonCustomPara(NULL,0));
  1710. // --------- initialize start_up_has_mine_nearby button group --------//
  1711. ButtonCustomGroup nearRawGroup(2);
  1712. for( i = 0; i < 2; ++i )
  1713. {
  1714. nearRawGroup[i].create(322+i*BASIC_OPTION_X_SPACE, offsetY+104,
  1715. 322+(i+1)*BASIC_OPTION_X_SPACE-1, offsetY+104+BASIC_OPTION_HEIGHT-1,
  1716. disp_virtual_button, ButtonCustomPara(&nearRawGroup, 1-i), 0, 0);
  1717. }
  1718. // --------- initialize start_up_independent_town button group --------//
  1719. static short startTownArray[3] = { 7, 15, 30 };
  1720. ButtonCustomGroup townStartGroup(3);
  1721. for( i = 0; i < 3; ++i )
  1722. {
  1723. townStartGroup[i].create(322+i*BASIC_OPTION_X_SPACE, offsetY+136,
  1724. 322+(i+1)*BASIC_OPTION_X_SPACE-1, offsetY+136+BASIC_OPTION_HEIGHT-1,
  1725. disp_virtual_button, ButtonCustomPara(&townStartGroup, startTownArray[i]), 0, 0);
  1726. }
  1727. // --------- initialize independent_town_resistance button group --------//
  1728. ButtonCustomGroup townResistGroup(3);
  1729. for( i = 0; i < 3; ++i )
  1730. {
  1731. townResistGroup[i].create(322+i*BASIC_OPTION_X_SPACE, offsetY+168,
  1732. 322+(i+1)*BASIC_OPTION_X_SPACE-1, offsetY+168+BASIC_OPTION_HEIGHT-1,
  1733. disp_virtual_button, ButtonCustomPara(&townResistGroup, i+1), 0, 0);
  1734. }
  1735. // --------- initialize new_independent_town_emerge button group --------//
  1736. ButtonCustomGroup townEmergeGroup(2);
  1737. for( i = 0; i < 2; ++i )
  1738. {
  1739. townEmergeGroup[i].create(322+i*BASIC_OPTION_X_SPACE, offsetY+200,
  1740. 322+(i+1)*BASIC_OPTION_X_SPACE-1, offsetY+200+BASIC_OPTION_HEIGHT-1,
  1741. disp_virtual_button, ButtonCustomPara(&townEmergeGroup, 1-i), 0, 0);
  1742. }
  1743. // --------- initialize new_nation_emerge button group --------//
  1744. ButtonCustomGroup nationEmergeGroup(2);
  1745. for( i = 0; i < 2; ++i )
  1746. {
  1747. nationEmergeGroup[i].create(322+i*BASIC_OPTION_X_SPACE, offsetY+232,
  1748. 322+(i+1)*BASIC_OPTION_X_SPACE-1, offsetY+232+BASIC_OPTION_HEIGHT-1,
  1749. disp_virtual_button, ButtonCustomPara(&nationEmergeGroup, 1-i), 0, 0);
  1750. }
  1751. // --------- initialize random_event_frequency button group --------//
  1752. ButtonCustomGroup randomEventGroup(4);
  1753. for( i = 0; i < 4; ++i )
  1754. {
  1755. randomEventGroup[i].create(322+i*BASIC_OPTION_X_SPACE, offsetY+264,
  1756. 322+(i+1)*BASIC_OPTION_X_SPACE-1, offsetY+264+BASIC_OPTION_HEIGHT-1,
  1757. disp_virtual_button, ButtonCustomPara(&randomEventGroup, i), 0, 0);
  1758. }
  1759. // ---------- initialize goal buttons ----------//
  1760. // ##### begin Gilbert 25/10 #######//
  1761. ButtonCustom clearEnemyButton, clearMonsterButton, enoughPeopleButton, enoughIncomeButton, enoughScoreButton, timeLimitButton;
  1762. ButtonCustom peopleInc, peopleDec, incomeInc, incomeDec, scoreInc, scoreDec, yearInc, yearDec;
  1763. clearEnemyButton.create( 209, offsetY+109, 209+19, offsetY+109+19, // -3
  1764. disp_virtual_tick, ButtonCustomPara(NULL, 0), 0, 1);
  1765. clearEnemyButton.enable_flag = 0;;
  1766. clearMonsterButton.create( 209, offsetY+142, 209+19, offsetY+142+19,
  1767. disp_virtual_tick, ButtonCustomPara(NULL, 0), 0,
  1768. tempConfig.goal_destroy_monster);
  1769. enoughPeopleButton.create( 209, offsetY+175, 209+19, offsetY+175+19,
  1770. disp_virtual_tick, ButtonCustomPara(NULL, 0), 0,
  1771. tempConfig.goal_population_flag);
  1772. enoughIncomeButton.create( 209, offsetY+208, 209+19, offsetY+208+19,
  1773. disp_virtual_tick, ButtonCustomPara(NULL, 0), 0,
  1774. tempConfig.goal_economic_score_flag);
  1775. enoughScoreButton.create( 209, offsetY+241, 209+19, offsetY+241+19,
  1776. disp_virtual_tick, ButtonCustomPara(NULL, 0), 0,
  1777. tempConfig.goal_total_score_flag);
  1778. timeLimitButton.create( 209, offsetY+273, 209+19, offsetY+273+19, // +29
  1779. disp_virtual_tick, ButtonCustomPara(NULL, 0), 0,
  1780. tempConfig.goal_year_limit_flag);
  1781. peopleInc.create( 524, offsetY+170,
  1782. 524+COLOR_OPTION_X_SPACE-1, offsetY+170+COLOR_OPTION_HEIGHT-1,
  1783. disp_virtual_button, ButtonCustomPara(NULL, 0) );
  1784. peopleDec.create( 559, offsetY+170,
  1785. 559+COLOR_OPTION_X_SPACE-1, offsetY+170+COLOR_OPTION_HEIGHT-1,
  1786. disp_virtual_button, ButtonCustomPara(NULL, 0) );
  1787. incomeInc.create( 524, offsetY+202,
  1788. 524+COLOR_OPTION_X_SPACE-1, offsetY+202+COLOR_OPTION_HEIGHT-1,
  1789. disp_virtual_button, ButtonCustomPara(NULL, 0) );
  1790. incomeDec.create( 559, offsetY+202,
  1791. 559+COLOR_OPTION_X_SPACE-1, offsetY+202+COLOR_OPTION_HEIGHT-1,
  1792. disp_virtual_button, ButtonCustomPara(NULL, 0) );
  1793. scoreInc.create( 524, offsetY+234,
  1794. 524+COLOR_OPTION_X_SPACE-1, offsetY+234+COLOR_OPTION_HEIGHT-1,
  1795. disp_virtual_button, ButtonCustomPara(NULL, 0) );
  1796. scoreDec.create( 559, offsetY+234,
  1797. 559+COLOR_OPTION_X_SPACE-1, offsetY+234+COLOR_OPTION_HEIGHT-1,
  1798. disp_virtual_button, ButtonCustomPara(NULL, 0) );
  1799. yearInc.create( 524, offsetY+266,
  1800. 524+COLOR_OPTION_X_SPACE-1, offsetY+266+COLOR_OPTION_HEIGHT-1,
  1801. disp_virtual_button, ButtonCustomPara(NULL, 0) );
  1802. yearDec.create( 559, offsetY+266,
  1803. 559+COLOR_OPTION_X_SPACE-1, offsetY+266+COLOR_OPTION_HEIGHT-1,
  1804. disp_virtual_button, ButtonCustomPara(NULL, 0) );
  1805. // ##### end Gilbert 25/10 #######//
  1806. Button3D startButton, readyButton, returnButton;
  1807. readyButton.create(120, 538, "READY-U", "READY-D", 1, 0);
  1808. startButton.create(320, 538, "START-U", "START-D", 1, 0);
  1809. returnButton.create(520, 538, "CANCEL-U", "CANCEL-D", 1, 0);
  1810. // ###### begin Gilbert 24/10 #######//
  1811. vga_front.unlock_buf();
  1812. // ###### end Gilbert 24/10 #######//
  1813. while(1)
  1814. {
  1815. // ####### begin Gilbert 23/10 #######//
  1816. MSG msg;
  1817. if (PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE))
  1818. {
  1819. if (!GetMessage( &msg, NULL, 0, 0))
  1820. {
  1821. sys.signal_exit_flag = 1;
  1822. // BUGHERE : vga_front is unlocked
  1823. return 0;
  1824. }
  1825. TranslateMessage(&msg);
  1826. DispatchMessage(&msg);
  1827. continue;
  1828. }
  1829. else if( sys.paused_flag || !sys.active_flag )
  1830. {
  1831. WaitMessage();
  1832. continue;
  1833. }
  1834. if( sys.need_redraw_flag )
  1835. {
  1836. refreshFlag = SGOPTION_ALL;
  1837. mRefreshFlag = MGOPTION_ALL;
  1838. sys.need_redraw_flag = 0;
  1839. }
  1840. vga_front.lock_buf();
  1841. // ####### end Gilbert 23/10 #######//
  1842. sys.yield();
  1843. mouse.get_event();
  1844. // -------- display ----------//
  1845. // ##### begin Gilbert 25/10 #####//
  1846. if( refreshFlag || mRefreshFlag )
  1847. // ##### end Gilbert 25/10 #####//
  1848. {
  1849. // ------- display basic option ---------//
  1850. if( optionMode == OPTION_BASIC )
  1851. {
  1852. if( refreshFlag & SGOPTION_PAGE )
  1853. {
  1854. image_menu.put_to_buf( &vga_back, "MPG-BSC");
  1855. #if(MAX_RACE == 10)
  1856. // protection : image_menu.put_to_buf( &vga_back, "MPG-BSC");
  1857. // ensure the user has the release version (I_MENU.RES)
  1858. // image_menu2.put_to_buf( &vga_back, "MPG-BSC") get the real one
  1859. image_menu2.put_to_buf( &vga_back, "MPG-BSC");
  1860. #endif
  1861. image_menu.put_back( 234, 15, menuTitleBitmap);
  1862. vga.blt_buf(0,0,VGA_WIDTH-1,VGA_HEIGHT-1,0);
  1863. }
  1864. if( refreshFlag & SGOPTION_RACE )
  1865. raceGroup.paint( reverse_race_table[tempConfig.race_id-1] );
  1866. if( refreshFlag & SGOPTION_COLOR )
  1867. colorGroup.paint( tempConfig.player_nation_color-1 );
  1868. if( refreshFlag & SGOPTION_AI_NATION )
  1869. {
  1870. #if(Y_SHIFT_FLAG)
  1871. #define Y_SHIFT 13
  1872. #else
  1873. #define Y_SHIFT 0
  1874. #endif
  1875. font_san.center_put(564, offsetY+144+Y_SHIFT, 564+25, offsetY+144+Y_SHIFT+21,
  1876. m.format(tempConfig.ai_nation_count), 1);
  1877. aiNationInc.paint();
  1878. aiNationDec.paint();
  1879. #undef Y_SHIFT
  1880. }
  1881. if( refreshFlag & SGOPTION_DIFFICULTY )
  1882. diffGroup.paint(tempConfig.difficulty_level);
  1883. if( refreshFlag & SGOPTION_TERRAIN )
  1884. terrainGroup.paint(tempConfig.terrain_set-1);
  1885. if( refreshFlag & SGOPTION_LAND_MASS )
  1886. landGroup.paint(tempConfig.land_mass-1);
  1887. }
  1888. // ------- display advanced option ---------//
  1889. if( optionMode == OPTION_ADVANCED )
  1890. {
  1891. if( refreshFlag & SGOPTION_PAGE )
  1892. {
  1893. image_menu.put_to_buf( &vga_back, "MPG-O1");
  1894. image_menu.put_back( 234, 15, menuTitleBitmap);
  1895. vga.blt_buf(0,0,VGA_WIDTH-1,VGA_HEIGHT-1,0);
  1896. }
  1897. // ###### begin Gilbert 25/10 #######//
  1898. if( refreshFlag & SGOPTION_MAP_ID )
  1899. mapIdField.paint();
  1900. // ###### end Gilbert 25/10 #######//
  1901. if( refreshFlag & SGOPTION_EXPLORED )
  1902. exploreGroup.paint(1-tempConfig.explore_whole_map);
  1903. if( refreshFlag & SGOPTION_FOG )
  1904. fogGroup.paint(1-tempConfig.fog_of_war);
  1905. if( refreshFlag & SGOPTION_TREASURE )
  1906. treasureGroup.paint( tempConfig.start_up_cash-1 );
  1907. if( refreshFlag & SGOPTION_AI_TREASURE )
  1908. aiTreasureGroup.paint( tempConfig.ai_start_up_cash-1 );
  1909. if( refreshFlag & SGOPTION_AI_AGGRESSIVE )
  1910. aiAggressiveGroup.paint(tempConfig.ai_aggressiveness-1);
  1911. if( refreshFlag & SGOPTION_FRYHTANS )
  1912. monsterGroup.paint(tempConfig.monster_type);
  1913. if( refreshFlag & SGOPTION_RANDOM_STARTUP )
  1914. randomStartUpGroup.paint(1-tempConfig.random_start_up);
  1915. }
  1916. // ------- display advanced option ---------//
  1917. if( optionMode == OPTION_ADVANCE2 )
  1918. {
  1919. if( refreshFlag & SGOPTION_PAGE )
  1920. {
  1921. image_menu.put_to_buf( &vga_back, "MPG-O2");
  1922. image_menu.put_back( 234, 15, menuTitleBitmap);
  1923. vga.blt_buf(0,0,VGA_WIDTH-1,VGA_HEIGHT-1,0);
  1924. }
  1925. if( refreshFlag & SGOPTION_RAW )
  1926. {
  1927. font_san.center_put(327, offsetY+77, 327+25, offsetY+77+21,
  1928. m.format(tempConfig.start_up_raw_site), 1);
  1929. rawSiteInc.paint();
  1930. rawSiteDec.paint();
  1931. }
  1932. if( refreshFlag & SGOPTION_NEAR_RAW )
  1933. nearRawGroup.paint(1-tempConfig.start_up_has_mine_nearby);
  1934. if( refreshFlag & SGOPTION_START_TOWN )
  1935. townStartGroup.paint(
  1936. tempConfig.start_up_independent_town >= 30 ? 2 :
  1937. tempConfig.start_up_independent_town <= 7 ? 0 :
  1938. 1
  1939. );
  1940. if( refreshFlag & SGOPTION_TOWN_STRENGTH )
  1941. townResistGroup.paint(tempConfig.independent_town_resistance-1);
  1942. if( refreshFlag & SGOPTION_TOWN_EMERGE )
  1943. townEmergeGroup.paint(1-tempConfig.new_independent_town_emerge);
  1944. if( refreshFlag & SGOPTION_KINGDOM_EMERGE )
  1945. nationEmergeGroup.paint(1-tempConfig.new_nation_emerge);
  1946. if( refreshFlag & SGOPTION_RANDOM_EVENT )
  1947. randomEventGroup.paint(tempConfig.random_event_frequency);
  1948. }
  1949. // ------- display goal option ---------//
  1950. if( optionMode == OPTION_GOAL )
  1951. {
  1952. if( refreshFlag & SGOPTION_PAGE )
  1953. {
  1954. image_menu.put_to_buf( &vga_back, "MPG-GOAL");
  1955. image_menu.put_back( 234, 15, menuTitleBitmap);
  1956. vga.blt_buf(0,0,VGA_WIDTH-1,VGA_HEIGHT-1,0);
  1957. }
  1958. if( refreshFlag & SGOPTION_CLEAR_ENEMY )
  1959. clearEnemyButton.paint();
  1960. if( refreshFlag & SGOPTION_CLEAR_MONSTER )
  1961. clearMonsterButton.paint(tempConfig.goal_destroy_monster);
  1962. // ####### begin Gilbert 25/10 ########//
  1963. if( refreshFlag & SGOPTION_ENOUGH_PEOPLE )
  1964. {
  1965. enoughPeopleButton.paint(tempConfig.goal_population_flag);
  1966. font_san.center_put( 446, offsetY+176, 446+67, offsetY+176+21,
  1967. m.format(tempConfig.goal_population), 1);
  1968. peopleInc.paint();
  1969. peopleDec.paint();
  1970. }
  1971. if( refreshFlag & SGOPTION_ENOUGH_INCOME )
  1972. {
  1973. enoughIncomeButton.paint(tempConfig.goal_economic_score_flag);
  1974. font_san.center_put( 446, offsetY+207, 446+67, offsetY+207+21,
  1975. m.format(tempConfig.goal_economic_score), 1);
  1976. incomeInc.paint();
  1977. incomeDec.paint();
  1978. }
  1979. if( refreshFlag & SGOPTION_ENOUGH_SCORE )
  1980. {
  1981. enoughScoreButton.paint(tempConfig.goal_total_score_flag);
  1982. font_san.center_put( 446, offsetY+239, 446+67, offsetY+239+21,
  1983. m.format(tempConfig.goal_total_score), 1);
  1984. scoreInc.paint();
  1985. scoreDec.paint();
  1986. }
  1987. if( refreshFlag & SGOPTION_TIME_LIMIT )
  1988. {
  1989. timeLimitButton.paint(tempConfig.goal_year_limit_flag);
  1990. font_san.center_put( 446, offsetY+271, 446+33, offsetY+271+21,
  1991. m.format(tempConfig.goal_year_limit), 1);
  1992. yearInc.paint();
  1993. yearDec.paint();
  1994. }
  1995. // ####### end Gilbert 25/10 ########//
  1996. }
  1997. // -------- refresh players in the session --------//
  1998. if( mRefreshFlag & MGOPTION_PLAYERS )
  1999. {
  2000. vga.blt_buf( 96, 46, 702, 100, 0 );
  2001. for( p = 0; p < regPlayerCount; ++p)
  2002. {
  2003. if( playerReadyFlag[p] )
  2004. {
  2005. image_menu.put_front( tickX[p]+3, tickY[p]+3, "NMPG-RCH" );
  2006. }
  2007. PlayerDesc *dispPlayer = mp_obj.search_player(regPlayerId[p]);
  2008. font_san.put( tickX[p]+nameOffsetX, tickY[p]+nameOffsetY, dispPlayer?dispPlayer->friendly_name_str():(char*)"?anonymous?" );
  2009. }
  2010. }
  2011. // ------------ display chat message --------//
  2012. if( mRefreshFlag & MGOPTION_OUT_MESSAGE )
  2013. {
  2014. messageField.paint();
  2015. }
  2016. // ------------- display incoming chat message --------//
  2017. if( mRefreshFlag & MGOPTION_IN_MESSAGE )
  2018. {
  2019. vga.blt_buf( 101, 135, 700, 202, 0 );
  2020. for( p = 1; p <= 4 && p <= messageList.size() ; ++p)
  2021. {
  2022. int ny = 136+(p-1)*16;
  2023. int nx = font_san.put( 102, ny, ((MpStructChatMsg *)messageList.get(p))->sender );
  2024. nx = font_san.put( nx, ny, " : ");
  2025. nx = font_san.put( nx, ny, ((MpStructChatMsg *)messageList.get(p))->content, 0, 700);
  2026. }
  2027. }
  2028. // ------- display difficulty -------//
  2029. if( (refreshFlag & SGOPTION_DIFFICULTY) || (mRefreshFlag & MGOPTION_PLAYERS) )
  2030. {
  2031. font_san.center_put( 718, offsetY+74, 780, offsetY+108,
  2032. m.format(tempConfig.multi_player_difficulty(regPlayerCount-1)), 1 );
  2033. }
  2034. // -------- repaint button -------//
  2035. if( refreshFlag & SGOPTION_PAGE )
  2036. {
  2037. if( remote.is_host )
  2038. startButton.paint();
  2039. readyButton.paint();
  2040. returnButton.paint();
  2041. }
  2042. refreshFlag = 0;
  2043. mRefreshFlag = 0;
  2044. }
  2045. sys.blt_virtual_buf();
  2046. if( config.music_flag )
  2047. {
  2048. if( !music.is_playing() )
  2049. music.play(1, sys.cdrom_drive ? MUSIC_CD_THEN_WAV : 0 );
  2050. }
  2051. else
  2052. music.stop();
  2053. // --------- detect remote message -------//
  2054. mp_obj.before_receive();
  2055. recvPtr = mp_obj.receive(&from, &to, &recvLen, &sysMsgCount);
  2056. mp_obj.after_send();
  2057. if( sysMsgCount )
  2058. {
  2059. // see any player disconnect
  2060. for(int q = 0; q < regPlayerCount; ++q)
  2061. {
  2062. if( !mp_obj.is_player_connecting(regPlayerId[q]) )
  2063. {
  2064. mRefreshFlag |= MGOPTION_PLAYERS;
  2065. memmove( regPlayerId+q, regPlayerId+q+1, (MAX_NATION-1-q)*sizeof(regPlayerId[0]) );
  2066. regPlayerId[MAX_NATION-1] = 0;
  2067. memmove( playerReadyFlag+q, playerReadyFlag+q+1, (MAX_NATION-1-q)*sizeof(playerReadyFlag[0]) );
  2068. playerReadyFlag[MAX_NATION-1] = 0;
  2069. short freeColor = playerColor[q];
  2070. memmove( playerColor+q, playerColor+q+1, (MAX_NATION-1-q)*sizeof(playerColor[0]) );
  2071. playerColor[MAX_NATION-1] = 0;
  2072. if(freeColor > 0 && freeColor <= MAX_COLOR_SCHEME)
  2073. colorAssigned[freeColor-1] = 0;
  2074. short freeRace = playerRace[q];
  2075. memmove( playerRace+q, playerRace+q+1, (MAX_NATION-1-q)*sizeof(playerRace[0]) );
  2076. playerRace[MAX_NATION-1] = 0;
  2077. if(freeRace > 0 && freeRace <= MAX_RACE)
  2078. raceAssigned[freeRace-1]--;
  2079. memmove( playerBalance+q, playerBalance+q+1, (MAX_NATION-1-q)*sizeof(playerBalance[0]) );
  2080. playerBalance[MAX_NATION-1] = 0;
  2081. --regPlayerCount;
  2082. --q;
  2083. }
  2084. }
  2085. }
  2086. if( recvPtr )
  2087. {
  2088. if( ((MpStructBase *)recvPtr)->msg_id == MPMSG_START_GAME )
  2089. {
  2090. retFlag = 1;
  2091. break; // break while(1) loop
  2092. }
  2093. else
  2094. {
  2095. switch( ((MpStructBase *)recvPtr)->msg_id )
  2096. {
  2097. case MPMSG_ABORT_GAME:
  2098. return 0;
  2099. case MPMSG_SEND_CONFIG:
  2100. tempConfig.change_game_setting( ((MpStructConfig *)recvPtr)->game_config );
  2101. refreshFlag |= SGOPTION_ALL_OPTIONS;
  2102. break;
  2103. case MPMSG_RANDOM_SEED:
  2104. info.init_random_seed( ((MpStructSeed *)recvPtr)->seed );
  2105. break;
  2106. // ####### begin Gilbert 25/10 #######//
  2107. case MPMSG_RANDOM_SEED_STR:
  2108. msgSeedStr = *(MpStructSeedStr *)recvPtr;
  2109. mapIdField.select_whole();
  2110. refreshFlag |= SGOPTION_MAP_ID;
  2111. break;
  2112. // ####### end Gilbert 25/10 #######//
  2113. case MPMSG_NEW_PLAYER:
  2114. mp_obj.poll_players();
  2115. if( remote.is_host )
  2116. {
  2117. if( regPlayerCount < MAX_NATION )
  2118. {
  2119. MpStructNewPlayer *newPlayerMsg = (MpStructNewPlayer *)recvPtr;
  2120. regPlayerId[regPlayerCount] = newPlayerMsg->player_id;
  2121. playerReadyFlag[regPlayerCount] = 0;
  2122. // send accept new player to all player
  2123. MpStructAcceptNewPlayer msgAccept(from);
  2124. mp_obj.send_stream( BROADCAST_PID, &msgAccept, sizeof(msgAccept) );
  2125. // assign initial race
  2126. int c = m.get_time() % MAX_RACE;
  2127. int t;
  2128. for( t = 0; t < MAX_RACE; ++t, ++c )
  2129. {
  2130. c %= MAX_RACE;
  2131. if( raceAssigned[c] == 0 )
  2132. {
  2133. raceAssigned[c]++;
  2134. playerRace[regPlayerCount] = c+1;
  2135. MpStructAcceptRace msgAcceptRace(from, c+1);
  2136. mp_obj.send_stream( from, &msgAcceptRace, sizeof(msgAcceptRace) );
  2137. break;
  2138. }
  2139. }
  2140. err_when( t >= MAX_RACE ); // not found
  2141. // assign initial color
  2142. c = m.get_time() % MAX_COLOR_SCHEME;
  2143. for( t = 0; t < MAX_COLOR_SCHEME; ++t, ++c )
  2144. {
  2145. c %= MAX_COLOR_SCHEME;
  2146. if( !colorAssigned[c] )
  2147. {
  2148. colorAssigned[c]=1;
  2149. playerColor[regPlayerCount] = c+1;
  2150. MpStructAcceptColor msgAcceptColor(from, c+1);
  2151. mp_obj.send_stream( from, &msgAcceptColor, sizeof(msgAcceptColor) );
  2152. break;
  2153. }
  2154. }
  2155. err_when( t >= MAX_COLOR_SCHEME ); // not found
  2156. // send random seed
  2157. // ###### begin Gilbert 25/10 #######//
  2158. // MpStructSeed msgRandomSeed(m.get_random_seed());
  2159. // mp_obj.send_stream( from, &msgRandomSeed, sizeof(msgRandomSeed) );
  2160. mp_obj.send_stream( from, &msgSeedStr, sizeof(msgSeedStr) );
  2161. // ###### end Gilbert 25/10 #######//
  2162. // send config
  2163. MpStructConfig msgConfig( tempConfig );
  2164. mp_obj.send_stream( from, &msgConfig, sizeof(msgConfig) );
  2165. // send ready flag
  2166. for( c = 0; c < regPlayerCount; ++c)
  2167. {
  2168. if( playerReadyFlag[c] )
  2169. {
  2170. MpStructPlayerReady msgReady(regPlayerId[c]);
  2171. mp_obj.send_stream(from, &msgReady, sizeof(msgReady));
  2172. }
  2173. }
  2174. // ###### patch begin Gilbert 22/1 ######//
  2175. // send remote.sync_test_level
  2176. MpStructSyncLevel msgSyncTest(remote.sync_test_level);
  2177. mp_obj.send_stream( from, &msgSyncTest, sizeof(msgSyncTest) );
  2178. // ###### patch end Gilbert 22/1 ######//
  2179. // update balance
  2180. playerBalance[regPlayerCount] = newPlayerMsg->player_balance;
  2181. regPlayerCount++;
  2182. mRefreshFlag |= MGOPTION_PLAYERS;
  2183. }
  2184. else
  2185. {
  2186. // reply refuse new player
  2187. MpStructRefuseNewPlayer msgRefuse(from);
  2188. mp_obj.send_stream( BROADCAST_PID, &msgRefuse, sizeof(msgRefuse) );
  2189. }
  2190. }
  2191. break;
  2192. case MPMSG_LOAD_GAME_NEW_PLAYER:
  2193. {
  2194. // incorrect message, reject
  2195. MpStructRefuseNewPlayer msgRefuse(from);
  2196. mp_obj.send_stream(BROADCAST_PID, &msgRefuse, sizeof(msgRefuse) );
  2197. }
  2198. break;
  2199. case MPMSG_ACCEPT_NEW_PLAYER:
  2200. hostPlayerId = from;
  2201. if( regPlayerCount < MAX_NATION && ((MpStructAcceptNewPlayer *)recvPtr)->player_id != mp_obj.my_player_id )
  2202. {
  2203. // search if this player has existed
  2204. for( p=0; p < regPlayerCount && regPlayerId[p] != ((MpStructAcceptNewPlayer *)recvPtr)->player_id; ++p );
  2205. regPlayerId[p] = ((MpStructAcceptNewPlayer *)recvPtr)->player_id;
  2206. playerReadyFlag[p] = 0;
  2207. if( p >= regPlayerCount )
  2208. {
  2209. regPlayerCount++; // now regPlayerCount == p
  2210. err_when( p != regPlayerCount );
  2211. }
  2212. mRefreshFlag |= MGOPTION_PLAYERS;
  2213. }
  2214. break;
  2215. case MPMSG_ACQUIRE_RACE:
  2216. if( remote.is_host )
  2217. {
  2218. short cl = ((MpStructAcquireRace *)recvPtr)->race_id;
  2219. if( !cl )
  2220. {
  2221. for( cl = 1; cl <= MAX_RACE; ++cl)
  2222. {
  2223. if( raceAssigned[cl-1] == 0 )
  2224. break;
  2225. }
  2226. }
  2227. int p;
  2228. for( p = 0; p < regPlayerCount && regPlayerId[p] != from; ++p );
  2229. if( cl <= MAX_RACE && p < regPlayerCount &&
  2230. (shareRace || raceAssigned[cl-1] == 0 ) ) // more than one player can use the same race
  2231. {
  2232. // unassign current race
  2233. if( playerRace[p] > 0)
  2234. raceAssigned[playerRace[p]-1]--;
  2235. // mark race assigned
  2236. raceAssigned[cl-1]++;
  2237. playerRace[p] = cl;
  2238. // reply accept race
  2239. MpStructAcceptRace msgAcceptRace(from, cl );
  2240. mp_obj.send_stream( from, &msgAcceptRace, sizeof(msgAcceptRace) );
  2241. }
  2242. else
  2243. {
  2244. // reply refuse race
  2245. MpStructRefuseRace msgRefuseRace(from, ((MpStructAcquireRace *)recvPtr)->race_id );
  2246. mp_obj.send_stream( from, &msgRefuseRace, sizeof(msgRefuseRace) );
  2247. }
  2248. }
  2249. break;
  2250. case MPMSG_ACCEPT_RACE:
  2251. if( ((MpStructAcceptRace *)recvPtr)->request_player_id == mp_obj.my_player_id )
  2252. {
  2253. tempConfig.race_id = char(((MpStructAcceptRace *)recvPtr)->race_id);
  2254. refreshFlag |= SGOPTION_RACE;
  2255. }
  2256. break;
  2257. case MPMSG_REFUSE_RACE:
  2258. if( ((MpStructRefuseRace *)recvPtr)->request_player_id == mp_obj.my_player_id )
  2259. {
  2260. refreshFlag |= SGOPTION_RACE;
  2261. // sound effect here
  2262. }
  2263. break;
  2264. case MPMSG_ACQUIRE_COLOR:
  2265. if( remote.is_host )
  2266. {
  2267. short cl = ((MpStructAcquireColor *)recvPtr)->color_scheme_id;
  2268. if( !cl )
  2269. {
  2270. for( cl = 1; cl <= MAX_COLOR_SCHEME && colorAssigned[cl-1]; ++cl);
  2271. }
  2272. int p;
  2273. for( p = 0; p < regPlayerCount && regPlayerId[p] != from; ++p );
  2274. if( cl <= MAX_COLOR_SCHEME && !colorAssigned[cl-1] && p < regPlayerCount )
  2275. {
  2276. if( playerColor[p] > 0 )
  2277. colorAssigned[playerColor[p]-1] = 0;
  2278. // mark color assigned
  2279. colorAssigned[cl-1] = 1;
  2280. playerColor[p] = cl;
  2281. // reply accept color
  2282. MpStructAcceptColor msgAcceptColor(from, cl );
  2283. mp_obj.send_stream( from, &msgAcceptColor, sizeof(msgAcceptColor) );
  2284. }
  2285. else
  2286. {
  2287. // reply refuse color
  2288. MpStructRefuseColor msgRefuseColor(from, ((MpStructAcquireColor *)recvPtr)->color_scheme_id );
  2289. mp_obj.send_stream( from, &msgRefuseColor, sizeof(msgRefuseColor) );
  2290. }
  2291. }
  2292. break;
  2293. case MPMSG_ACCEPT_COLOR:
  2294. if( ((MpStructAcceptColor *)recvPtr)->request_player_id == mp_obj.my_player_id )
  2295. {
  2296. tempConfig.player_nation_color = char(((MpStructAcceptColor *)recvPtr)->color_scheme_id);
  2297. refreshFlag |= SGOPTION_COLOR;
  2298. }
  2299. break;
  2300. case MPMSG_REFUSE_COLOR:
  2301. if( ((MpStructRefuseColor *)recvPtr)->request_player_id == mp_obj.my_player_id )
  2302. {
  2303. refreshFlag |= SGOPTION_COLOR;
  2304. // sound effect here
  2305. }
  2306. break;
  2307. case MPMSG_PLAYER_READY:
  2308. {
  2309. for( int p = 0; p < regPlayerCount; ++p)
  2310. {
  2311. if( regPlayerId[p] == ((MpStructPlayerReady *)recvPtr)->player_id )
  2312. {
  2313. playerReadyFlag[p] = 1;
  2314. mRefreshFlag |= MGOPTION_PLAYERS;
  2315. }
  2316. }
  2317. }
  2318. break;
  2319. case MPMSG_PLAYER_UNREADY:
  2320. {
  2321. for( int p = 0; p < regPlayerCount; ++p)
  2322. {
  2323. if( regPlayerId[p] == ((MpStructPlayerUnready *)recvPtr)->player_id )
  2324. {
  2325. playerReadyFlag[p] = 0;
  2326. mRefreshFlag |= MGOPTION_PLAYERS;
  2327. }
  2328. }
  2329. }
  2330. break;
  2331. case MPMSG_SEND_CHAT_MSG:
  2332. while( messageList.size() >= 4 )
  2333. messageList.linkout(1);
  2334. messageList.linkin(recvPtr);
  2335. mRefreshFlag |= MGOPTION_IN_MESSAGE;
  2336. break;
  2337. // ###### patch begin Gilbert 22/1 ######//
  2338. case MPMSG_SEND_SYNC_TEST_LEVEL:
  2339. remote.sync_test_level = ((MpStructSyncLevel *)recvPtr)->sync_test_level;
  2340. break;
  2341. // ###### patch end Gilbert 22/1 ######//
  2342. case MPMSG_REFUSE_NEW_PLAYER:
  2343. if( ((MpStructRefuseNewPlayer *)recvPtr)->player_id == mp_obj.my_player_id )
  2344. {
  2345. box.msg("You cannot join the game because the multiplayer saved game you selected is different from those of other human players.");
  2346. return 0;
  2347. }
  2348. break;
  2349. default: // if the game is started, any other thing is received
  2350. return 0;
  2351. }
  2352. }
  2353. }
  2354. // --------- detect basic option -------- //
  2355. if( optionMode == OPTION_BASIC )
  2356. {
  2357. if( !selfReadyFlag )
  2358. {
  2359. if( raceGroup.detect() >= 0)
  2360. {
  2361. int r = tempConfig.race_id = raceGroup[raceGroup()].custom_para.value;
  2362. if( remote.is_host )
  2363. {
  2364. int p;
  2365. for( p = 0; p < regPlayerCount && regPlayerId[p] != mp_obj.my_player_id ; ++p );
  2366. if( r <= MAX_RACE && p < regPlayerCount &&
  2367. (shareRace || raceAssigned[r-1] == 0 ) ) // more than one player can use the same race
  2368. {
  2369. // unassign current race
  2370. if( playerRace[p] > 0)
  2371. raceAssigned[playerRace[p]-1]--;
  2372. // mark race assigned
  2373. raceAssigned[r-1]++;
  2374. playerRace[p] = r;
  2375. tempConfig.race_id = r;
  2376. }
  2377. refreshFlag |= SGOPTION_RACE;
  2378. }
  2379. else
  2380. {
  2381. MpStructAcquireRace msgAcquire(r);
  2382. mp_obj.send_stream(hostPlayerId, &msgAcquire, sizeof( msgAcquire) );
  2383. }
  2384. //refreshFlag |= SGOPTION_RACE;
  2385. }
  2386. else if( colorGroup.detect() >= 0)
  2387. {
  2388. int r = colorGroup[colorGroup()].custom_para.value;
  2389. if( remote.is_host )
  2390. {
  2391. if( !colorAssigned[r-1] )
  2392. {
  2393. int p;
  2394. for( p = 0; p < regPlayerCount && regPlayerId[p] != mp_obj.my_player_id; ++p );
  2395. if( r <= MAX_COLOR_SCHEME && !colorAssigned[r-1] && p < regPlayerCount )
  2396. {
  2397. // unmark current color
  2398. if( playerColor[p] > 0 )
  2399. colorAssigned[playerColor[p]-1] = 0;
  2400. // mark color assigned
  2401. colorAssigned[r-1] = 1;
  2402. playerColor[p] = r;
  2403. tempConfig.player_nation_color = r;
  2404. }
  2405. }
  2406. refreshFlag |= SGOPTION_COLOR;
  2407. }
  2408. else
  2409. {
  2410. MpStructAcquireColor msgAcquire(r);
  2411. mp_obj.send_stream(hostPlayerId, &msgAcquire, sizeof( msgAcquire) );
  2412. }
  2413. //refreshFlag |= SGOPTION_COLOR;
  2414. }
  2415. }
  2416. }
  2417. // -------- detect other option, only host can change ---------//
  2418. unsigned keyCode = 0;
  2419. if( remote.is_host && !selfReadyFlag)
  2420. {
  2421. int configChange = 0;
  2422. // ------- detect basic option ---------//
  2423. if( optionMode == OPTION_BASIC )
  2424. {
  2425. if( aiNationInc.detect() )
  2426. {
  2427. tempConfig.ai_nation_count++;
  2428. if( tempConfig.ai_nation_count >= MAX_NATION )
  2429. tempConfig.ai_nation_count = MAX_NATION-1;
  2430. tempConfig.difficulty_level = OPTION_CUSTOM;
  2431. configChange = 1;
  2432. refreshFlag |= SGOPTION_AI_NATION | SGOPTION_DIFFICULTY;
  2433. }
  2434. else if( aiNationDec.detect() )
  2435. {
  2436. tempConfig.ai_nation_count--;
  2437. if( tempConfig.ai_nation_count < 0 )
  2438. tempConfig.ai_nation_count = 0;
  2439. tempConfig.difficulty_level = OPTION_CUSTOM;
  2440. configChange = 1;
  2441. refreshFlag |= SGOPTION_AI_NATION | SGOPTION_DIFFICULTY;
  2442. }
  2443. else if( diffGroup.detect() >= 0)
  2444. {
  2445. if( diffGroup[diffGroup()].custom_para.value != OPTION_CUSTOM )
  2446. {
  2447. tempConfig.change_difficulty(diffGroup[diffGroup()].custom_para.value);
  2448. configChange = 1;
  2449. // all but SGOPTION_PAGE;
  2450. refreshFlag |= SGOPTION_ALL & ~SGOPTION_PAGE;
  2451. }
  2452. }
  2453. else if( terrainGroup.detect() >= 0)
  2454. {
  2455. tempConfig.terrain_set = terrainGroup[terrainGroup()].custom_para.value;
  2456. static short latitudeArray[3] = { 45, 70, 20 };
  2457. err_when( tempConfig.terrain_set <= 0 || tempConfig.terrain_set > 3 );
  2458. tempConfig.latitude = latitudeArray[tempConfig.terrain_set-1];
  2459. configChange = 1;
  2460. //refreshFlag |= SGOPTION_TERRAIN;
  2461. }
  2462. else if( landGroup.detect() >= 0)
  2463. {
  2464. tempConfig.land_mass = landGroup[landGroup()].custom_para.value;
  2465. configChange = 1;
  2466. //refreshFlag |= SGOPTION_LAND_MASS;
  2467. }
  2468. }
  2469. // ------- detect advanced option ---------//
  2470. else if( optionMode == OPTION_ADVANCED )
  2471. {
  2472. // ###### begin Gilbert 24/10 ######//
  2473. MpStructSeedStr oldMapStr(msgSeedStr);
  2474. if( keyCode = mapIdField.detect() )
  2475. {
  2476. if( strcmp(oldMapStr.seed_str, msgSeedStr.seed_str) )
  2477. mp_obj.send_stream( BROADCAST_PID, &msgSeedStr, sizeof(msgSeedStr) );
  2478. refreshFlag |= SGOPTION_MAP_ID;
  2479. }
  2480. else
  2481. // ###### end Gilbert 24/10 ######//
  2482. if( exploreGroup.detect() >= 0 )
  2483. {
  2484. tempConfig.explore_whole_map = exploreGroup[exploreGroup()].custom_para.value;
  2485. tempConfig.difficulty_level = OPTION_CUSTOM;
  2486. configChange = 1;
  2487. // refreshFlag |= SGOPTION_EXPLORED;
  2488. refreshFlag |= SGOPTION_DIFFICULTY;
  2489. }
  2490. else if( fogGroup.detect() >= 0 )
  2491. {
  2492. tempConfig.fog_of_war = fogGroup[fogGroup()].custom_para.value;
  2493. tempConfig.difficulty_level = OPTION_CUSTOM;
  2494. configChange = 1;
  2495. // refreshFlag |= SGOPTION_FOG
  2496. refreshFlag |= SGOPTION_DIFFICULTY;
  2497. }
  2498. else if( treasureGroup.detect() >= 0 )
  2499. {
  2500. tempConfig.start_up_cash = treasureGroup[treasureGroup()].custom_para.value;
  2501. tempConfig.difficulty_level = OPTION_CUSTOM;
  2502. configChange = 1;
  2503. // refreshFlag |= SGOPTION_TREASURE;
  2504. refreshFlag |= SGOPTION_DIFFICULTY;
  2505. }
  2506. else if( aiTreasureGroup.detect() >= 0 )
  2507. {
  2508. tempConfig.ai_start_up_cash = aiTreasureGroup[aiTreasureGroup()].custom_para.value;
  2509. tempConfig.difficulty_level = OPTION_CUSTOM;
  2510. configChange = 1;
  2511. // refreshFlag |= SGOPTION_AI_TREASURE;
  2512. refreshFlag |= SGOPTION_DIFFICULTY;
  2513. }
  2514. else if( aiAggressiveGroup.detect() >= 0 )
  2515. {
  2516. tempConfig.ai_aggressiveness =
  2517. aiAggressiveGroup[aiAggressiveGroup()].custom_para.value;
  2518. tempConfig.difficulty_level = OPTION_CUSTOM;
  2519. configChange = 1;
  2520. // refreshFlag |= SGOPTION_AI_AGGRESSIVE;
  2521. refreshFlag |= SGOPTION_DIFFICULTY;
  2522. }
  2523. else if( monsterGroup.detect() >= 0 )
  2524. {
  2525. tempConfig.monster_type = monsterGroup[monsterGroup()].custom_para.value;
  2526. tempConfig.difficulty_level = OPTION_CUSTOM;
  2527. configChange = 1;
  2528. // refreshFlag |= SGOPTION_FRYHTANS;
  2529. refreshFlag |= SGOPTION_DIFFICULTY;
  2530. }
  2531. else if( randomStartUpGroup.detect() >= 0)
  2532. {
  2533. tempConfig.random_start_up = randomStartUpGroup[randomStartUpGroup()].custom_para.value;
  2534. tempConfig.difficulty_level = OPTION_CUSTOM;
  2535. configChange = 1;
  2536. // refreshFlag |= SGOPTION_RANDOM_STARTUP;
  2537. refreshFlag |= SGOPTION_DIFFICULTY;
  2538. }
  2539. }
  2540. // -------- detect advanced option ---------//
  2541. else if( optionMode == OPTION_ADVANCE2 )
  2542. {
  2543. if( rawSiteInc.detect() )
  2544. {
  2545. if( ++tempConfig.start_up_raw_site > 7 )
  2546. tempConfig.start_up_raw_site = 7;
  2547. tempConfig.difficulty_level = OPTION_CUSTOM;
  2548. configChange = 1;
  2549. refreshFlag |= SGOPTION_RAW | SGOPTION_DIFFICULTY;
  2550. }
  2551. else if( rawSiteDec.detect() )
  2552. {
  2553. if( --tempConfig.start_up_raw_site < 1 )
  2554. tempConfig.start_up_raw_site = 1;
  2555. tempConfig.difficulty_level = OPTION_CUSTOM;
  2556. configChange = 1;
  2557. refreshFlag |= SGOPTION_RAW | SGOPTION_DIFFICULTY;
  2558. }
  2559. else if( nearRawGroup.detect() >= 0)
  2560. {
  2561. tempConfig.start_up_has_mine_nearby = nearRawGroup[nearRawGroup()].custom_para.value;
  2562. tempConfig.difficulty_level = OPTION_CUSTOM;
  2563. configChange = 1;
  2564. // refreshFlag |= SGOPTION_NEAR_RAW;
  2565. refreshFlag |= SGOPTION_DIFFICULTY;
  2566. }
  2567. else if( townStartGroup.detect() >= 0)
  2568. {
  2569. tempConfig.start_up_independent_town = townStartGroup[townStartGroup()].custom_para.value;
  2570. tempConfig.difficulty_level = OPTION_CUSTOM;
  2571. configChange = 1;
  2572. // resfreshFlag |= SGOPTION_START_TOWN;
  2573. refreshFlag |= SGOPTION_DIFFICULTY;
  2574. }
  2575. else if( townResistGroup.detect() >= 0)
  2576. {
  2577. tempConfig.independent_town_resistance = townResistGroup[townResistGroup()].custom_para.value;
  2578. tempConfig.difficulty_level = OPTION_CUSTOM;
  2579. configChange = 1;
  2580. // resfreshFlag |= SGOPTION_TOWN_RESIST;
  2581. refreshFlag |= SGOPTION_DIFFICULTY;
  2582. }
  2583. else if( townEmergeGroup.detect() >= 0)
  2584. {
  2585. tempConfig.new_independent_town_emerge = townEmergeGroup[townEmergeGroup()].custom_para.value;
  2586. tempConfig.difficulty_level = OPTION_CUSTOM;
  2587. configChange = 1;
  2588. // refreshFlag |= SGOPTION_TOWN_EMERGE;
  2589. refreshFlag |= SGOPTION_DIFFICULTY;
  2590. }
  2591. else if( nationEmergeGroup.detect() >= 0)
  2592. {
  2593. tempConfig.new_nation_emerge = nationEmergeGroup[nationEmergeGroup()].custom_para.value;
  2594. tempConfig.difficulty_level = OPTION_CUSTOM;
  2595. configChange = 1;
  2596. // refreshFlag |= SGOPTION_NATION_EMERGE;
  2597. refreshFlag |= SGOPTION_DIFFICULTY;
  2598. }
  2599. else if( randomEventGroup.detect() >= 0)
  2600. {
  2601. tempConfig.random_event_frequency = randomEventGroup[randomEventGroup()].custom_para.value;
  2602. tempConfig.difficulty_level = OPTION_CUSTOM;
  2603. configChange = 1;
  2604. // refreshFlag |= SGOPTION_RANDOM_EVENT;
  2605. refreshFlag |= SGOPTION_DIFFICULTY;
  2606. }
  2607. }
  2608. // -------- detect goal option ----------//
  2609. else if( optionMode == OPTION_GOAL )
  2610. {
  2611. if( clearEnemyButton.detect() )
  2612. {
  2613. }
  2614. else if( clearMonsterButton.detect() )
  2615. {
  2616. tempConfig.goal_destroy_monster = clearMonsterButton.pushed_flag;
  2617. configChange = 1;
  2618. }
  2619. else if( enoughPeopleButton.detect() )
  2620. {
  2621. tempConfig.goal_population_flag = enoughPeopleButton.pushed_flag;
  2622. configChange = 1;
  2623. }
  2624. else if( enoughIncomeButton.detect() )
  2625. {
  2626. tempConfig.goal_economic_score_flag = enoughIncomeButton.pushed_flag;
  2627. configChange = 1;
  2628. }
  2629. // ##### begin Gilbert 24/10 #######//
  2630. else if( enoughScoreButton.detect() )
  2631. {
  2632. tempConfig.goal_total_score_flag = enoughScoreButton.pushed_flag;
  2633. configChange = 1;
  2634. }
  2635. // ##### end Gilbert 24/10 #######//
  2636. else if( timeLimitButton.detect() )
  2637. {
  2638. tempConfig.goal_year_limit_flag = timeLimitButton.pushed_flag;
  2639. configChange = 1;
  2640. }
  2641. else if( peopleInc.detect() )
  2642. {
  2643. tempConfig.goal_population += 100;
  2644. if( tempConfig.goal_population > 5000 )
  2645. tempConfig.goal_population = 5000;
  2646. configChange = 1;
  2647. refreshFlag |= SGOPTION_ENOUGH_PEOPLE;
  2648. }
  2649. else if( peopleDec.detect() )
  2650. {
  2651. tempConfig.goal_population -= 100;
  2652. if( tempConfig.goal_population < 100 )
  2653. tempConfig.goal_population = 100;
  2654. configChange = 1;
  2655. refreshFlag |= SGOPTION_ENOUGH_PEOPLE;
  2656. }
  2657. // ###### begin Gilbert 24/10 #######//
  2658. else if( incomeInc.detect() )
  2659. {
  2660. tempConfig.goal_economic_score += 100;
  2661. if( tempConfig.goal_economic_score > 5000 )
  2662. {
  2663. tempConfig.goal_economic_score = 5000;
  2664. }
  2665. configChange = 1;
  2666. refreshFlag |= SGOPTION_ENOUGH_INCOME;
  2667. }
  2668. else if( incomeDec.detect() )
  2669. {
  2670. tempConfig.goal_economic_score -= 100;
  2671. if( tempConfig.goal_economic_score < 100 )
  2672. {
  2673. tempConfig.goal_economic_score = 100;
  2674. }
  2675. configChange = 1;
  2676. refreshFlag |= SGOPTION_ENOUGH_INCOME;
  2677. }
  2678. else if( scoreInc.detect() )
  2679. {
  2680. if( tempConfig.goal_total_score >= 2000 )
  2681. tempConfig.goal_total_score += 500;
  2682. else
  2683. tempConfig.goal_total_score += 100;
  2684. if( tempConfig.goal_total_score > 10000 )
  2685. tempConfig.goal_total_score = 10000;
  2686. configChange = 1;
  2687. refreshFlag |= SGOPTION_ENOUGH_SCORE;
  2688. }
  2689. else if( scoreDec.detect() )
  2690. {
  2691. if( tempConfig.goal_total_score > 2000 )
  2692. tempConfig.goal_total_score -= 500;
  2693. else
  2694. tempConfig.goal_total_score -= 100;
  2695. if( tempConfig.goal_total_score < 100 )
  2696. tempConfig.goal_total_score = 100;
  2697. configChange = 1;
  2698. refreshFlag |= SGOPTION_ENOUGH_SCORE;
  2699. }
  2700. // ###### end Gilbert 24/10 #######//
  2701. else if( yearInc.detect() )
  2702. {
  2703. if( tempConfig.goal_year_limit >= 20 )
  2704. tempConfig.goal_year_limit += 5;
  2705. else
  2706. tempConfig.goal_year_limit++;
  2707. if( tempConfig.goal_year_limit > 100 )
  2708. {
  2709. tempConfig.goal_year_limit = 100;
  2710. }
  2711. configChange = 1;
  2712. refreshFlag |= SGOPTION_TIME_LIMIT;
  2713. }
  2714. else if( yearDec.detect() )
  2715. {
  2716. if( tempConfig.goal_year_limit > 20 )
  2717. tempConfig.goal_year_limit -= 5;
  2718. else
  2719. tempConfig.goal_year_limit--;
  2720. if( tempConfig.goal_year_limit < 1 )
  2721. {
  2722. tempConfig.goal_year_limit = 1;
  2723. }
  2724. configChange = 1;
  2725. refreshFlag |= SGOPTION_TIME_LIMIT;
  2726. }
  2727. }
  2728. if( configChange )
  2729. {
  2730. MpStructConfig msgConfig(tempConfig);
  2731. mp_obj.send_stream( BROADCAST_PID, &msgConfig, sizeof(msgConfig) );
  2732. }
  2733. }
  2734. // --------- detect switch option button ------//
  2735. if( mouse.single_click(96, offsetY+12, 218, offsetY+54) )
  2736. {
  2737. if( optionMode != OPTION_BASIC )
  2738. {
  2739. optionMode = OPTION_BASIC;
  2740. refreshFlag = SGOPTION_ALL;
  2741. mRefreshFlag = MGOPTION_ALL;
  2742. }
  2743. }
  2744. else if( mouse.single_click(236, offsetY+12, 363, offsetY+54) )
  2745. {
  2746. if( optionMode != OPTION_ADVANCED )
  2747. {
  2748. optionMode = OPTION_ADVANCED;
  2749. refreshFlag = SGOPTION_ALL;
  2750. mRefreshFlag = MGOPTION_ALL;
  2751. }
  2752. }
  2753. else if( mouse.single_click(380, offsetY+12, 506, offsetY+54) )
  2754. {
  2755. if( optionMode != OPTION_ADVANCE2 )
  2756. {
  2757. optionMode = OPTION_ADVANCE2;
  2758. refreshFlag = SGOPTION_ALL;
  2759. mRefreshFlag = MGOPTION_ALL;
  2760. }
  2761. }
  2762. else if( mouse.single_click(523, offsetY+12, 649, offsetY+54) )
  2763. {
  2764. if( optionMode != OPTION_GOAL )
  2765. {
  2766. optionMode = OPTION_GOAL;
  2767. refreshFlag = SGOPTION_ALL;
  2768. mRefreshFlag = MGOPTION_ALL;
  2769. }
  2770. }
  2771. // --------- detect ready button button --------//
  2772. if( readyButton.detect() )
  2773. {
  2774. mRefreshFlag |= MGOPTION_PLAYERS;
  2775. for(p = 0; p < regPlayerCount && regPlayerId[p] != mp_obj.my_player_id; ++p);
  2776. if( p < regPlayerCount )
  2777. {
  2778. if( !selfReadyFlag )
  2779. {
  2780. playerReadyFlag[p] = selfReadyFlag = 1;
  2781. MpStructPlayerReady msgReady(mp_obj.my_player_id);
  2782. mp_obj.send_stream(BROADCAST_PID, &msgReady, sizeof(msgReady));
  2783. }
  2784. else
  2785. {
  2786. // else un-ready this player
  2787. playerReadyFlag[p] = selfReadyFlag = 0;
  2788. MpStructPlayerUnready msgUnready(mp_obj.my_player_id);
  2789. mp_obj.send_stream(BROADCAST_PID, &msgUnready, sizeof(msgUnready));
  2790. }
  2791. }
  2792. }
  2793. if( remote.is_host && startButton.detect() && regPlayerCount >= 2 )
  2794. {
  2795. // see if all player is ready
  2796. short sumBalance = 0;
  2797. int q;
  2798. for( q = 0; q < regPlayerCount && playerReadyFlag[q]; ++q)
  2799. {
  2800. err_when( playerBalance[q] == 0 );
  2801. sumBalance += playerBalance[q];
  2802. }
  2803. if( q >= regPlayerCount ) // not all playerReadyFlag[p] = 1;
  2804. {
  2805. #ifdef DEBUG
  2806. sumBalance = 0;
  2807. #endif
  2808. #ifdef BETA
  2809. sumBalance = 0;
  2810. #endif
  2811. if( sumBalance >= 0 )
  2812. {
  2813. // MpStructBase msgStart(MPMSG_START_GAME);
  2814. // mp_obj.send_stream(BROADCAST_PID, &msgStart, sizeof(msgStart));
  2815. retFlag = 1;
  2816. break; // break while(1)
  2817. }
  2818. else
  2819. {
  2820. // too many non-CD version
  2821. box.msg("There are not enough Seven Kingdoms CDROMs to start the game. Each CDROM supports "PLAYER_RATIO_STRING" players.");
  2822. }
  2823. }
  2824. }
  2825. else if( returnButton.detect() )
  2826. {
  2827. if( remote.is_host )
  2828. {
  2829. MpStructBase msgAbort(MPMSG_ABORT_GAME);
  2830. mp_obj.send_stream(BROADCAST_PID, &msgAbort, sizeof(msgAbort) );
  2831. }
  2832. retFlag = 0;
  2833. break; // break while(1)
  2834. }
  2835. else if( !keyCode && (keyCode = messageField.detect()) != 0) // keyCode may be non-zero if after mapIdField.detect()
  2836. {
  2837. mRefreshFlag |= MGOPTION_OUT_MESSAGE;
  2838. if(keyCode == KEY_RETURN && strlen(typingMsg.content) > 0)
  2839. {
  2840. // send message
  2841. mp_obj.send_stream(BROADCAST_PID, &typingMsg, sizeof(typingMsg) );
  2842. // clear the string
  2843. messageField.clear();
  2844. }
  2845. else if( keyCode == KEY_ESC )
  2846. {
  2847. messageField.clear();
  2848. }
  2849. }
  2850. mp_obj.after_send();
  2851. // ####### begin Gilbert 24/10 #######//
  2852. vga_front.unlock_buf();
  2853. // ####### end Gilbert 24/10 #######//
  2854. }
  2855. // ###### begin Gilbert 24/10 #######//
  2856. if( !vga_front.buf_locked )
  2857. vga_front.lock_buf();
  2858. // ###### end Gilbert 24/10 #######//
  2859. mp_obj.after_send();
  2860. // ---------- final setup to start multiplayer game --------//
  2861. if( retFlag )
  2862. {
  2863. retFlag = 0;
  2864. if( remote.is_host )
  2865. mp_obj.disable_join_session();
  2866. // mp_obj.poll_players();
  2867. nation_array.init();
  2868. nation_array.zap();
  2869. int trial;
  2870. unsigned long startTime;
  2871. int playerCount = 0;
  2872. if( remote.is_host )
  2873. {
  2874. VLenQueue setupString;
  2875. // ------- put start game string -------//
  2876. {
  2877. MpStructBase msgStart(MPMSG_START_GAME);
  2878. memcpy( setupString.reserve(sizeof(msgStart)), &msgStart, sizeof(msgStart) );
  2879. }
  2880. // -------- put random seed -------- //
  2881. do
  2882. {
  2883. info.init_random_seed( atol(msgSeedStr.seed_str) );
  2884. } while (m.get_random_seed() == 0L);
  2885. {
  2886. MpStructSeed msgSeed(m.get_random_seed());
  2887. memcpy( setupString.reserve(sizeof(msgSeed)), &msgSeed, sizeof(msgSeed) );
  2888. }
  2889. // -------- send config ------------//
  2890. {
  2891. MpStructConfig msgConfig(tempConfig);
  2892. memcpy( setupString.reserve(sizeof(msgConfig)), &msgConfig, sizeof(msgConfig) );
  2893. }
  2894. // BUGHERE : terrain_set 2 is not available
  2895. #ifndef AMPLUS
  2896. if( tempConfig.terrain_set == 2)
  2897. tempConfig.terrain_set = 1;
  2898. #endif
  2899. config = tempConfig; // nation_array.new_nation reads setting from config
  2900. // -------- setup nation now ------------ //
  2901. info.init();
  2902. playerCount = 0;
  2903. for( p = 0; p < regPlayerCount; ++p )
  2904. {
  2905. // ensure it is a valid player
  2906. PID_TYPE playerId = regPlayerId[p];
  2907. PlayerDesc *player = mp_obj.search_player(playerId);
  2908. if( !playerId || !player || !player->connecting )
  2909. continue;
  2910. nationPara[playerCount].init(playerCount+1, playerId, playerColor[p], playerRace[p], player->friendly_name_str());
  2911. ((MpStructNation *)setupString.reserve(sizeof(MpStructNation)))->init(
  2912. playerCount+1, playerId, playerColor[p], playerRace[p], player->friendly_name_str());
  2913. playerCount++;
  2914. }
  2915. *mpPlayerCount = playerCount;
  2916. config.difficulty_rating = config.multi_player_difficulty(playerCount-1);
  2917. // ---- force set to the lowest frame delay -------//
  2918. #ifdef AMPLUS
  2919. remote.set_process_frame_delay(FORCE_MAX_FRAME_DELAY);
  2920. {
  2921. MpStructProcessFrameDelay msgFrameDelay(remote.get_process_frame_delay());
  2922. memcpy( setupString.reserve(sizeof(msgFrameDelay)), &msgFrameDelay, sizeof(msgFrameDelay));
  2923. }
  2924. #endif
  2925. // -------- send sync test level ----------//
  2926. {
  2927. MpStructSyncLevel msgSyncTest(remote.sync_test_level);
  2928. memcpy( setupString.reserve(sizeof(msgSyncTest)), &msgSyncTest, sizeof(msgSyncTest));
  2929. }
  2930. mp_obj.send_stream(BROADCAST_PID, setupString.queue_buf, setupString.length() );
  2931. mp_obj.after_send();
  2932. }
  2933. else
  2934. {
  2935. // use the message recving MPMSG_START_GAME
  2936. err_when( !recvPtr);
  2937. DWORD offset = 0;
  2938. int recvStartMsg = 0;
  2939. int recvSeed = 0;
  2940. int recvConfig = 0;
  2941. int ownPlayerFound = 0;
  2942. playerCount = 0;
  2943. char *oriRecvPtr = recvPtr;
  2944. int recvSetFrameDelay = 0;
  2945. int recvSyncTestLevel = 0;
  2946. // process the string received
  2947. while( offset < recvLen )
  2948. {
  2949. DWORD oldOffset = offset;
  2950. recvPtr = oriRecvPtr + offset;
  2951. switch( ((MpStructBase *)(recvPtr))->msg_id )
  2952. {
  2953. case MPMSG_START_GAME:
  2954. recvStartMsg = 1;
  2955. offset += sizeof( MpStructBase );
  2956. break;
  2957. case MPMSG_RANDOM_SEED:
  2958. err_when( ((MpStructSeed *) recvPtr)->seed == 0L);
  2959. info.init_random_seed( ((MpStructSeed *) recvPtr)->seed );
  2960. offset += sizeof( MpStructSeed );
  2961. ++recvSeed;
  2962. break;
  2963. case MPMSG_SEND_CONFIG:
  2964. tempConfig.change_game_setting( ((MpStructConfig *) recvPtr)->game_config );
  2965. offset += sizeof( MpStructConfig );
  2966. ++recvConfig;
  2967. #ifndef AMPLUS
  2968. if( tempConfig.terrain_set == 2)
  2969. tempConfig.terrain_set = 1;
  2970. #endif
  2971. config = tempConfig; // nation_array.new_nation reads setting from config
  2972. break;
  2973. case MPMSG_DECLARE_NATION:
  2974. {
  2975. if( playerCount == 0 )
  2976. info.init(); // info.init for the first time
  2977. MpStructNation *msgNation = (MpStructNation *)recvPtr;
  2978. nationPara[playerCount].init( msgNation->nation_recno,
  2979. msgNation->dp_player_id, msgNation->color_scheme,
  2980. msgNation->race_id, msgNation->player_name);
  2981. if( msgNation->dp_player_id == mp_obj.my_player_id )
  2982. ownPlayerFound++;
  2983. *mpPlayerCount = ++playerCount;
  2984. offset += sizeof( MpStructNation );
  2985. config.difficulty_rating = config.multi_player_difficulty(playerCount-1);
  2986. }
  2987. break;
  2988. case MPMSG_SET_PROCESS_FRAME_DELAY:
  2989. remote.set_process_frame_delay(((MpStructProcessFrameDelay *)recvPtr)->common_process_frame_delay);
  2990. ++recvSetFrameDelay;
  2991. offset += sizeof( MpStructProcessFrameDelay );
  2992. break;
  2993. case MPMSG_SEND_SYNC_TEST_LEVEL:
  2994. remote.sync_test_level = ((MpStructSyncLevel *)recvPtr)->sync_test_level;
  2995. ++recvSyncTestLevel;
  2996. offset += sizeof( MpStructSyncLevel );
  2997. break;
  2998. } // end switch
  2999. if( !recvStartMsg || offset <= oldOffset )
  3000. {
  3001. err_here();
  3002. box.msg( "Connection string from host is corrupted" );
  3003. return 0;
  3004. }
  3005. } // end while
  3006. if( !recvSeed )
  3007. {
  3008. box.msg( "Cannot get random seeds from the host." );
  3009. return 0;
  3010. }
  3011. err_when( recvSeed > 1 );
  3012. if( !recvConfig )
  3013. {
  3014. box.msg( "Cannot get game configuration info from the host." );
  3015. return 0;
  3016. }
  3017. err_when( recvConfig > 1 );
  3018. if( playerCount == 0 )
  3019. {
  3020. box.msg( "Cannot get kingdom information from the host." );
  3021. return 0;
  3022. }
  3023. err_when( playerCount > MAX_NATION );
  3024. if( !ownPlayerFound )
  3025. {
  3026. box.msg( "The host cannot recognize your machine." );
  3027. return 0;
  3028. }
  3029. err_when( ownPlayerFound > 1 );
  3030. if( !recvSetFrameDelay || !recvSyncTestLevel )
  3031. {
  3032. box.msg("Cannot receive important information from the host");
  3033. return 0;
  3034. }
  3035. err_when( recvSetFrameDelay > 1 );
  3036. err_when( recvSyncTestLevel > 1 );
  3037. }
  3038. if( remote.sync_test_level == 0)
  3039. {
  3040. remote.set_alternating_send(playerCount > 4 ? 4 : playerCount); // automatic setting
  3041. }
  3042. {
  3043. // ------- broadcast end setting string ------- //
  3044. MpStructBase mpEndSetting(MPMSG_END_SETTING);
  3045. mp_obj.send_stream( BROADCAST_PID, &mpEndSetting, sizeof(mpEndSetting) );
  3046. mp_obj.after_send();
  3047. // ------ wait for MPMSG_END_SETTING ----------//
  3048. // ---- to filter other all message until MP_MSG_END_SETTING ---//
  3049. trial = 5000;
  3050. startTime = m.get_time();
  3051. int recvEndSetting = 0;
  3052. while( --trial > 0 || m.get_time() - startTime < 10000 )
  3053. {
  3054. if( recvEndSetting >= playerCount-1)
  3055. break;
  3056. mp_obj.before_receive();
  3057. recvPtr = mp_obj.receive( &from, &to, &recvLen);
  3058. mp_obj.after_send();
  3059. if( recvPtr )
  3060. {
  3061. trial = max(trial, 1000);
  3062. startTime = m.get_time();
  3063. if( ((MpStructBase *)recvPtr)->msg_id == MPMSG_END_SETTING )
  3064. {
  3065. recvEndSetting++;
  3066. }
  3067. }
  3068. }
  3069. if( recvEndSetting < playerCount-1 )
  3070. {
  3071. box.msg("Some player(s) encountered errors when initializing the game.");
  3072. // but continue
  3073. }
  3074. }
  3075. retFlag = 1;
  3076. } // end if(retFlag)
  3077. return retFlag;
  3078. }
  3079. #ifdef Y_SHIFT
  3080. #error
  3081. #endif
  3082. #undef Y_SHIFT_FLAG
  3083. //-------- End of function Game::mp_select_option -----------//
  3084. //-------- Begin of function Game::mp_select_load_option -----------//
  3085. // return 0 = cancel, 1 = ok
  3086. int Game::mp_select_load_option(char *fileName)
  3087. {
  3088. const int offsetY = 212;
  3089. char optionMode = OPTION_BASIC;
  3090. char menuTitleBitmap[] = "TOP-LMPG";
  3091. Config &tempConfig = config;
  3092. PID_TYPE from, to;
  3093. DWORD recvLen;
  3094. int sysMsgCount;
  3095. char *recvPtr;
  3096. char raceAssigned[MAX_RACE]; // master copy belongs to host's
  3097. char colorAssigned[MAX_COLOR_SCHEME]; // master copy belongs to host's
  3098. //static short raceX[MAX_RACE] = {390, 313, 236, 467, 390, 236, 313};
  3099. //static short raceY[MAX_RACE] = {276, 276, 276, 276, 243, 243, 243};
  3100. //const raceWidth = 77;
  3101. //const raceHeight = 33;
  3102. //static short colorX[MAX_COLOR_SCHEME] = {545, 581, 581, 617, 617, 545, 653};
  3103. //static short colorY[MAX_COLOR_SCHEME] = {243, 276, 243, 276, 243, 276, 276};
  3104. //const colorWidth = 36;
  3105. //const colorHeight = 33;
  3106. static short tickX[MAX_NATION] = { 103, 254, 405, 556, 103, 254, 405 };
  3107. static short tickY[MAX_NATION] = { 53, 53, 53, 53, 73, 73, 73 };
  3108. const int nameOffsetX = 23;
  3109. const int nameOffsetY = 3;
  3110. DynArray messageList(sizeof(MpStructChatMsg));
  3111. MpStructChatMsg typingMsg(tempConfig.player_name, NULL);
  3112. memset( raceAssigned, 0, sizeof(raceAssigned) );
  3113. memset( colorAssigned, 0, sizeof(colorAssigned) );
  3114. PID_TYPE hostPlayerId = 0;
  3115. PID_TYPE regPlayerId[MAX_NATION];
  3116. memset( regPlayerId, 0, sizeof(regPlayerId) );
  3117. char playerReadyFlag[MAX_NATION];
  3118. memset( playerReadyFlag, 0, sizeof(playerReadyFlag) );
  3119. short playerRace[MAX_NATION]; // host only
  3120. memset( playerRace, 0, sizeof(playerRace) );
  3121. short playerColor[MAX_NATION]; // host only
  3122. memset( playerColor, 0, sizeof(playerColor) );
  3123. short playerBalance[MAX_NATION];
  3124. memset( playerBalance, 0, sizeof(playerBalance) );
  3125. int regPlayerCount = 0;
  3126. int selfReadyFlag = 0;
  3127. int maxPlayer;
  3128. int shareRace = 1; // host only, 0= exclusive race of each player
  3129. mp_obj.poll_players();
  3130. int p;
  3131. for( p = 1; p <= MAX_NATION && mp_obj.get_player(p); ++p )
  3132. {
  3133. // host only identify himself
  3134. if( !remote.is_host || mp_obj.get_player(p)->pid() == mp_obj.my_player_id )
  3135. {
  3136. regPlayerId[regPlayerCount] = mp_obj.get_player(p)->pid();
  3137. playerReadyFlag[regPlayerCount] = 0;
  3138. playerColor[regPlayerCount] = 0;
  3139. playerRace[regPlayerCount] = 0;
  3140. playerBalance[regPlayerCount] = 0;
  3141. ++regPlayerCount;
  3142. }
  3143. }
  3144. err_when( tempConfig.race_id != (~nation_array)->race_id );
  3145. err_when( tempConfig.player_nation_color != (~nation_array)->color_scheme_id );
  3146. int i;
  3147. long refreshFlag = SGOPTION_ALL;
  3148. long mRefreshFlag = MGOPTION_ALL;
  3149. int retFlag = 0;
  3150. if( remote.is_host )
  3151. {
  3152. colorAssigned[tempConfig.player_nation_color-1] = 1;
  3153. for( p = 0; p < regPlayerCount && regPlayerId[p] != mp_obj.my_player_id; ++p );
  3154. if( p < regPlayerCount )
  3155. {
  3156. playerColor[p] = tempConfig.player_nation_color;
  3157. playerBalance[p] = sys.cdrom_drive ? PLAYER_RATIO_CDROM : PLAYER_RATIO_NOCD;
  3158. }
  3159. // initialize other colorAssigned, only free for those of the remote players
  3160. maxPlayer = 1; // host
  3161. for( p = 1; p <= nation_array.size(); ++p )
  3162. {
  3163. if( !nation_array.is_deleted(p) && nation_array[p]->is_remote() )
  3164. {
  3165. colorAssigned[nation_array[p]->color_scheme_id-1] = 0;
  3166. maxPlayer++;
  3167. }
  3168. }
  3169. err_when( maxPlayer > MAX_NATION );
  3170. }
  3171. else
  3172. {
  3173. memset( colorAssigned, 0, sizeof(colorAssigned) ); // assume all color are unassigned
  3174. MpStructLoadGameNewPlayer msgNewPlayer( mp_obj.my_player_id, ~nation_array, sys.frame_count,
  3175. m.get_random_seed(), sys.cdrom_drive ? PLAYER_RATIO_CDROM : PLAYER_RATIO_NOCD );
  3176. mp_obj.send_stream(BROADCAST_PID, &msgNewPlayer, sizeof(msgNewPlayer) );
  3177. }
  3178. // --------- initialize race button group ---------- //
  3179. ButtonCustomGroup raceGroup(MAX_RACE);
  3180. for( i = 0; i < MAX_RACE; ++i )
  3181. {
  3182. #if(MAX_RACE == 10)
  3183. raceGroup[i].create(220+(i%5)*BASIC_OPTION_X_SPACE, (i/5)*BASIC_OPTION_HEIGHT+offsetY+70,
  3184. 220+(i%5+1)*BASIC_OPTION_X_SPACE-1, (i/5+1)*BASIC_OPTION_HEIGHT+offsetY+70-1,
  3185. disp_virtual_button, ButtonCustomPara(&raceGroup, race_table[i]), 0, 0);
  3186. #define Y_SHIFT_FLAG 1
  3187. #else
  3188. raceGroup[i].create(118+i*BASIC_OPTION_X_SPACE, offsetY+93,
  3189. 118+(i+1)*BASIC_OPTION_X_SPACE-1, offsetY+93+BASIC_OPTION_HEIGHT-1,
  3190. disp_virtual_button, ButtonCustomPara(&raceGroup, race_table[i]), 0, 0);
  3191. #define Y_SHIFT_FLAG 0
  3192. #endif
  3193. }
  3194. // --------- initialize color button group ---------- //
  3195. ButtonCustomGroup colorGroup(MAX_COLOR_SCHEME);
  3196. for( i = 0; i < MAX_COLOR_SCHEME; ++i )
  3197. {
  3198. #if(Y_SHIFT_FLAG)
  3199. #define Y_SHIFT 13
  3200. #else
  3201. #define Y_SHIFT 0
  3202. #endif
  3203. colorGroup[i].create(195+i*COLOR_OPTION_X_SPACE, offsetY+139+Y_SHIFT,
  3204. 195+(i+1)*COLOR_OPTION_X_SPACE-1, offsetY+139+Y_SHIFT+COLOR_OPTION_HEIGHT-1,
  3205. disp_virtual_button, ButtonCustomPara(&colorGroup, i+1), 0, 0);
  3206. #undef Y_SHIFT
  3207. }
  3208. // ---------- initialize ai_nation_count buttons --------//
  3209. ButtonCustom aiNationInc, aiNationDec;
  3210. {
  3211. #if(Y_SHIFT_FLAG)
  3212. #define Y_SHIFT 13
  3213. #else
  3214. #define Y_SHIFT 0
  3215. #endif
  3216. aiNationInc.create(595, offsetY+139+Y_SHIFT,
  3217. 595+COLOR_OPTION_X_SPACE-1, offsetY+139+Y_SHIFT+COLOR_OPTION_HEIGHT-1,
  3218. disp_virtual_button, ButtonCustomPara(NULL, +1) );
  3219. aiNationDec.create(630, offsetY+139+Y_SHIFT,
  3220. 630+COLOR_OPTION_X_SPACE-1, offsetY+139+Y_SHIFT+COLOR_OPTION_HEIGHT-1,
  3221. disp_virtual_button, ButtonCustomPara(NULL, -1) );
  3222. #undef Y_SHIFT
  3223. }
  3224. // ---------- initialize difficulty_level button group -------//
  3225. ButtonCustomGroup diffGroup(6);
  3226. for( i = 0; i < 6; ++i )
  3227. {
  3228. #if(Y_SHIFT_FLAG)
  3229. #define Y_SHIFT 16
  3230. #else
  3231. #define Y_SHIFT 0
  3232. #endif
  3233. diffGroup[i].create( 205+i*BASIC_OPTION_X_SPACE, offsetY+184+Y_SHIFT,
  3234. 205+(i+1)*BASIC_OPTION_X_SPACE-1, offsetY+184+Y_SHIFT+BASIC_OPTION_HEIGHT-1,
  3235. disp_virtual_button, ButtonCustomPara(&diffGroup, i), 0, 0);
  3236. #undef Y_SHIFT
  3237. }
  3238. // --------- initialize terrain_set button group -------//
  3239. // ####### begin Gilbert 25/10 #######//
  3240. ButtonCustomGroup terrainGroup(3);
  3241. for( i = 0; i < 3; ++i )
  3242. {
  3243. #if(Y_SHIFT_FLAG)
  3244. #define Y_SHIFT 16
  3245. #else
  3246. #define Y_SHIFT 0
  3247. #endif
  3248. #ifdef AMPLUS
  3249. terrainGroup[i].create(166+i*BASIC_OPTION_X_SPACE, offsetY+248+Y_SHIFT,
  3250. 166+(i+1)*BASIC_OPTION_X_SPACE-1, offsetY+248+Y_SHIFT+BASIC_OPTION_HEIGHT-1,
  3251. disp_virtual_button, ButtonCustomPara(&terrainGroup, i+1), 0, 0);
  3252. #else
  3253. int k = i;
  3254. switch(i)
  3255. {
  3256. case 1: k = 2; break;
  3257. case 2: k = 1; break;
  3258. }
  3259. terrainGroup[i].create(205+k*BASIC_OPTION_X_SPACE, offsetY+248+Y_SHIFT,
  3260. 205+(k+1)*BASIC_OPTION_X_SPACE-1, offsetY+248+Y_SHIFT+BASIC_OPTION_HEIGHT-1,
  3261. disp_virtual_button, ButtonCustomPara(&terrainGroup, i+1), 0, 0);
  3262. if( i == 1 )
  3263. terrainGroup[i].enable_flag = 0;
  3264. #endif
  3265. #undef Y_SHIFT
  3266. }
  3267. // ####### end Gilbert 25/10 #######//
  3268. // --------- initialize land_mass button group -------//
  3269. ButtonCustomGroup landGroup(3);
  3270. for( i = 0; i < 3; ++i )
  3271. {
  3272. #if(Y_SHIFT_FLAG)
  3273. #define Y_SHIFT 16
  3274. #else
  3275. #define Y_SHIFT 0
  3276. #endif
  3277. landGroup[i].create(439+i*BASIC_OPTION_X_SPACE, offsetY+248+Y_SHIFT,
  3278. 439+(i+1)*BASIC_OPTION_X_SPACE-1, offsetY+248+Y_SHIFT+BASIC_OPTION_HEIGHT-1,
  3279. disp_virtual_button, ButtonCustomPara(&landGroup, i+1), 0, 0);
  3280. #undef Y_SHIFT
  3281. }
  3282. GetA messageField;
  3283. messageField.init( 190, 116, 700, typingMsg.content,
  3284. MpStructChatMsg::MSG_LENGTH, &font_san, 0, 1);
  3285. // ###### begin Gilbert 25/10 #######//
  3286. // --------- initialize info.random_seed field ----------//
  3287. MpStructSeedStr msgSeedStr(info.random_seed);
  3288. GetA mapIdField;
  3289. #if(defined(SPANISH))
  3290. #define MAPID_X1 588
  3291. #elif(defined(FRENCH))
  3292. #define MAPID_X1 578
  3293. #else
  3294. #define MAPID_X1 564
  3295. #endif
  3296. mapIdField.init( MAPID_X1, offsetY+83, 700, msgSeedStr.seed_str, msgSeedStr.RANDOM_SEED_MAX_LEN, &font_san, 0, 1);
  3297. #undef MAPID_X1
  3298. // ###### end Gilbert 25/10 #######//
  3299. // --------- initialize explore_whole_map button group -------//
  3300. ButtonCustomGroup exploreGroup(2);
  3301. for( i = 0; i < 2; ++i )
  3302. {
  3303. exploreGroup[i].create(335+i*BASIC_OPTION_X_SPACE, offsetY+74,
  3304. 335+(i+1)*BASIC_OPTION_X_SPACE-1, offsetY+74+BASIC_OPTION_HEIGHT-1,
  3305. disp_virtual_button, ButtonCustomPara(&exploreGroup, 1-i), 0, 0);
  3306. }
  3307. // --------- initialize fog_of_war button group -------//
  3308. ButtonCustomGroup fogGroup(2);
  3309. for( i = 0; i < 2; ++i )
  3310. {
  3311. fogGroup[i].create(335+i*BASIC_OPTION_X_SPACE, offsetY+106,
  3312. 335+(i+1)*BASIC_OPTION_X_SPACE-1, offsetY+106+BASIC_OPTION_HEIGHT-1,
  3313. disp_virtual_button, ButtonCustomPara(&fogGroup, 1-i), 0, 0);
  3314. }
  3315. // --------- initialize start_up_cash/start_up_food button group -------//
  3316. ButtonCustomGroup treasureGroup(4);
  3317. for( i = 0; i < 4; ++i )
  3318. {
  3319. treasureGroup[i].create(335+i*BASIC_OPTION_X_SPACE, offsetY+138,
  3320. 335+(i+1)*BASIC_OPTION_X_SPACE-1, offsetY+138+BASIC_OPTION_HEIGHT-1,
  3321. disp_virtual_button, ButtonCustomPara(&treasureGroup, i+1), 0, 0);
  3322. }
  3323. // --------- initialize ai_start_up_cash/food button group -------//
  3324. ButtonCustomGroup aiTreasureGroup(4);
  3325. for( i = 0; i < 4; ++i )
  3326. {
  3327. aiTreasureGroup[i].create(335+i*BASIC_OPTION_X_SPACE, offsetY+170,
  3328. 335+(i+1)*BASIC_OPTION_X_SPACE-1, offsetY+170+BASIC_OPTION_HEIGHT-1,
  3329. disp_virtual_button, ButtonCustomPara(&aiTreasureGroup, i+1), 0, 0);
  3330. }
  3331. // --------- initialize ai_aggressiveness -------//
  3332. ButtonCustomGroup aiAggressiveGroup(4);
  3333. for( i = 0; i < 4; ++i )
  3334. {
  3335. aiAggressiveGroup[i].create(335+i*BASIC_OPTION_X_SPACE, offsetY+202,
  3336. 335+(i+1)*BASIC_OPTION_X_SPACE-1, offsetY+202+BASIC_OPTION_HEIGHT-1,
  3337. disp_virtual_button, ButtonCustomPara(&aiAggressiveGroup, i+1), 0, 0);
  3338. }
  3339. // --------- initialize monster_type -------//
  3340. ButtonCustomGroup monsterGroup(3);
  3341. for( i = 0; i < 3; ++i )
  3342. {
  3343. monsterGroup[i].create(335+i*BASIC_OPTION_X_SPACE, offsetY+234,
  3344. 335+(i+1)*BASIC_OPTION_X_SPACE-1, offsetY+234+BASIC_OPTION_HEIGHT-1,
  3345. disp_virtual_button, ButtonCustomPara(&monsterGroup, i), 0, 0);
  3346. }
  3347. // --------- initialize random startup button group -------//
  3348. ButtonCustomGroup randomStartUpGroup(2);
  3349. for( i = 0; i < 2; ++i )
  3350. {
  3351. randomStartUpGroup[i].create(335+i*BASIC_OPTION_X_SPACE, offsetY+266,
  3352. 335+(i+1)*BASIC_OPTION_X_SPACE-1, offsetY+266+BASIC_OPTION_HEIGHT-1,
  3353. disp_virtual_button, ButtonCustomPara(&randomStartUpGroup, 1-i), 0, 0);
  3354. }
  3355. // -------- initialize start_up_raw_site buttons --------- //
  3356. ButtonCustom rawSiteInc, rawSiteDec;
  3357. rawSiteInc.create( 358, offsetY+72,
  3358. 358+COLOR_OPTION_X_SPACE-1, offsetY+72+COLOR_OPTION_HEIGHT-1,
  3359. disp_virtual_button, ButtonCustomPara(NULL,0));
  3360. rawSiteDec.create( 393, offsetY+72,
  3361. 393+COLOR_OPTION_X_SPACE-1, offsetY+72+COLOR_OPTION_HEIGHT-1,
  3362. disp_virtual_button, ButtonCustomPara(NULL,0));
  3363. // --------- initialize start_up_has_mine_nearby button group --------//
  3364. ButtonCustomGroup nearRawGroup(2);
  3365. for( i = 0; i < 2; ++i )
  3366. {
  3367. nearRawGroup[i].create(322+i*BASIC_OPTION_X_SPACE, offsetY+104,
  3368. 322+(i+1)*BASIC_OPTION_X_SPACE-1, offsetY+104+BASIC_OPTION_HEIGHT-1,
  3369. disp_virtual_button, ButtonCustomPara(&nearRawGroup, 1-i), 0, 0);
  3370. }
  3371. // --------- initialize start_up_independent_town button group --------//
  3372. static short startTownArray[3] = { 7, 15, 30 };
  3373. ButtonCustomGroup townStartGroup(3);
  3374. for( i = 0; i < 3; ++i )
  3375. {
  3376. townStartGroup[i].create(322+i*BASIC_OPTION_X_SPACE, offsetY+136,
  3377. 322+(i+1)*BASIC_OPTION_X_SPACE-1, offsetY+136+BASIC_OPTION_HEIGHT-1,
  3378. disp_virtual_button, ButtonCustomPara(&townStartGroup, startTownArray[i]), 0, 0);
  3379. }
  3380. // --------- initialize independent_town_resistance button group --------//
  3381. ButtonCustomGroup townResistGroup(3);
  3382. for( i = 0; i < 3; ++i )
  3383. {
  3384. townResistGroup[i].create(322+i*BASIC_OPTION_X_SPACE, offsetY+168,
  3385. 322+(i+1)*BASIC_OPTION_X_SPACE-1, offsetY+168+BASIC_OPTION_HEIGHT-1,
  3386. disp_virtual_button, ButtonCustomPara(&townResistGroup, i+1), 0, 0);
  3387. }
  3388. // --------- initialize new_independent_town_emerge button group --------//
  3389. ButtonCustomGroup townEmergeGroup(2);
  3390. for( i = 0; i < 2; ++i )
  3391. {
  3392. townEmergeGroup[i].create(322+i*BASIC_OPTION_X_SPACE, offsetY+200,
  3393. 322+(i+1)*BASIC_OPTION_X_SPACE-1, offsetY+200+BASIC_OPTION_HEIGHT-1,
  3394. disp_virtual_button, ButtonCustomPara(&townEmergeGroup, 1-i), 0, 0);
  3395. }
  3396. // --------- initialize new_nation_emerge button group --------//
  3397. ButtonCustomGroup nationEmergeGroup(2);
  3398. for( i = 0; i < 2; ++i )
  3399. {
  3400. nationEmergeGroup[i].create(322+i*BASIC_OPTION_X_SPACE, offsetY+232,
  3401. 322+(i+1)*BASIC_OPTION_X_SPACE-1, offsetY+232+BASIC_OPTION_HEIGHT-1,
  3402. disp_virtual_button, ButtonCustomPara(&nationEmergeGroup, 1-i), 0, 0);
  3403. }
  3404. // --------- initialize random_event_frequency button group --------//
  3405. ButtonCustomGroup randomEventGroup(4);
  3406. for( i = 0; i < 4; ++i )
  3407. {
  3408. randomEventGroup[i].create(322+i*BASIC_OPTION_X_SPACE, offsetY+264,
  3409. 322+(i+1)*BASIC_OPTION_X_SPACE-1, offsetY+264+BASIC_OPTION_HEIGHT-1,
  3410. disp_virtual_button, ButtonCustomPara(&randomEventGroup, i), 0, 0);
  3411. }
  3412. // ---------- initialize goal buttons ----------//
  3413. // ##### begin Gilbert 25/10 #######//
  3414. ButtonCustom clearEnemyButton, clearMonsterButton, enoughPeopleButton, enoughIncomeButton, enoughScoreButton, timeLimitButton;
  3415. ButtonCustom peopleInc, peopleDec, incomeInc, incomeDec, scoreInc, scoreDec, yearInc, yearDec;
  3416. clearEnemyButton.create( 209, offsetY+109, 209+19, offsetY+109+19, // -3
  3417. disp_virtual_tick, ButtonCustomPara(NULL, 0), 0, 1);
  3418. clearEnemyButton.enable_flag = 0;;
  3419. clearMonsterButton.create( 209, offsetY+142, 209+19, offsetY+142+19,
  3420. disp_virtual_tick, ButtonCustomPara(NULL, 0), 0,
  3421. tempConfig.goal_destroy_monster);
  3422. enoughPeopleButton.create( 209, offsetY+175, 209+19, offsetY+175+19,
  3423. disp_virtual_tick, ButtonCustomPara(NULL, 0), 0,
  3424. tempConfig.goal_population_flag);
  3425. enoughIncomeButton.create( 209, offsetY+208, 209+19, offsetY+208+19,
  3426. disp_virtual_tick, ButtonCustomPara(NULL, 0), 0,
  3427. tempConfig.goal_economic_score_flag);
  3428. enoughScoreButton.create( 209, offsetY+241, 209+19, offsetY+241+19,
  3429. disp_virtual_tick, ButtonCustomPara(NULL, 0), 0,
  3430. tempConfig.goal_total_score_flag);
  3431. timeLimitButton.create( 209, offsetY+273, 209+19, offsetY+273+19, // +29
  3432. disp_virtual_tick, ButtonCustomPara(NULL, 0), 0,
  3433. tempConfig.goal_year_limit_flag);
  3434. peopleInc.create( 524, offsetY+170,
  3435. 524+COLOR_OPTION_X_SPACE-1, offsetY+170+COLOR_OPTION_HEIGHT-1,
  3436. disp_virtual_button, ButtonCustomPara(NULL, 0) );
  3437. peopleDec.create( 559, offsetY+170,
  3438. 559+COLOR_OPTION_X_SPACE-1, offsetY+170+COLOR_OPTION_HEIGHT-1,
  3439. disp_virtual_button, ButtonCustomPara(NULL, 0) );
  3440. incomeInc.create( 524, offsetY+202,
  3441. 524+COLOR_OPTION_X_SPACE-1, offsetY+202+COLOR_OPTION_HEIGHT-1,
  3442. disp_virtual_button, ButtonCustomPara(NULL, 0) );
  3443. incomeDec.create( 559, offsetY+202,
  3444. 559+COLOR_OPTION_X_SPACE-1, offsetY+202+COLOR_OPTION_HEIGHT-1,
  3445. disp_virtual_button, ButtonCustomPara(NULL, 0) );
  3446. scoreInc.create( 524, offsetY+234,
  3447. 524+COLOR_OPTION_X_SPACE-1, offsetY+234+COLOR_OPTION_HEIGHT-1,
  3448. disp_virtual_button, ButtonCustomPara(NULL, 0) );
  3449. scoreDec.create( 559, offsetY+234,
  3450. 559+COLOR_OPTION_X_SPACE-1, offsetY+234+COLOR_OPTION_HEIGHT-1,
  3451. disp_virtual_button, ButtonCustomPara(NULL, 0) );
  3452. yearInc.create( 524, offsetY+266,
  3453. 524+COLOR_OPTION_X_SPACE-1, offsetY+266+COLOR_OPTION_HEIGHT-1,
  3454. disp_virtual_button, ButtonCustomPara(NULL, 0) );
  3455. yearDec.create( 559, offsetY+266,
  3456. 559+COLOR_OPTION_X_SPACE-1, offsetY+266+COLOR_OPTION_HEIGHT-1,
  3457. disp_virtual_button, ButtonCustomPara(NULL, 0) );
  3458. // ##### end Gilbert 25/10 #######//
  3459. Button3D startButton, readyButton, returnButton;
  3460. readyButton.create(120, 538, "READY-U", "READY-D", 1, 0);
  3461. startButton.create(320, 538, "START-U", "START-D", 1, 0);
  3462. returnButton.create(520, 538, "CANCEL-U", "CANCEL-D", 1, 0);
  3463. // ###### begin Gilbert 24/10 #######//
  3464. vga_front.unlock_buf();
  3465. // ###### end Gilbert 24/10 #######//
  3466. while(1)
  3467. {
  3468. // ####### begin Gilbert 23/10 #######//
  3469. MSG msg;
  3470. if (PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE))
  3471. {
  3472. if (!GetMessage( &msg, NULL, 0, 0))
  3473. {
  3474. sys.signal_exit_flag = 1;
  3475. // BUGHERE : vga_front is unlocked
  3476. return 0;
  3477. }
  3478. TranslateMessage(&msg);
  3479. DispatchMessage(&msg);
  3480. continue;
  3481. }
  3482. else if( sys.paused_flag || !sys.active_flag )
  3483. {
  3484. WaitMessage();
  3485. continue;
  3486. }
  3487. if( sys.need_redraw_flag )
  3488. {
  3489. refreshFlag = SGOPTION_ALL;
  3490. mRefreshFlag = MGOPTION_ALL;
  3491. sys.need_redraw_flag = 0;
  3492. }
  3493. vga_front.lock_buf();
  3494. // ####### begin Gilbert 24/10 ########//
  3495. sys.yield();
  3496. mouse.get_event();
  3497. // -------- display ----------//
  3498. if( refreshFlag || mRefreshFlag )
  3499. {
  3500. // ------- display basic option ---------//
  3501. if( optionMode == OPTION_BASIC )
  3502. {
  3503. if( refreshFlag & SGOPTION_PAGE )
  3504. {
  3505. image_menu.put_to_buf( &vga_back, "MPG-BSC");
  3506. #if(MAX_RACE == 10)
  3507. // protection : image_menu.put_to_buf( &vga_back, "MPG-BSC");
  3508. // ensure the user has the release version (I_MENU.RES)
  3509. // image_menu2.put_to_buf( &vga_back, "MPG-BSC") get the real one
  3510. image_menu2.put_to_buf( &vga_back, "MPG-BSC");
  3511. #endif
  3512. image_menu.put_back( 234, 15, menuTitleBitmap);
  3513. vga.blt_buf(0,0,VGA_WIDTH-1,VGA_HEIGHT-1,0);
  3514. }
  3515. if( refreshFlag & SGOPTION_RACE )
  3516. raceGroup.paint( reverse_race_table[tempConfig.race_id-1] );
  3517. if( refreshFlag & SGOPTION_COLOR )
  3518. colorGroup.paint( tempConfig.player_nation_color-1 );
  3519. if( refreshFlag & SGOPTION_AI_NATION )
  3520. {
  3521. #if(Y_SHIFT_FLAG)
  3522. #define Y_SHIFT 13
  3523. #else
  3524. #define Y_SHIFT 0
  3525. #endif
  3526. font_san.center_put(564, offsetY+144+Y_SHIFT, 564+25, offsetY+144+Y_SHIFT+21,
  3527. m.format(tempConfig.ai_nation_count), 1);
  3528. aiNationInc.paint();
  3529. aiNationDec.paint();
  3530. #undef Y_SHIFT
  3531. }
  3532. if( refreshFlag & SGOPTION_DIFFICULTY )
  3533. diffGroup.paint(tempConfig.difficulty_level);
  3534. if( refreshFlag & SGOPTION_TERRAIN )
  3535. terrainGroup.paint(tempConfig.terrain_set-1);
  3536. if( refreshFlag & SGOPTION_LAND_MASS )
  3537. landGroup.paint(tempConfig.land_mass-1);
  3538. }
  3539. // ------- display advanced option ---------//
  3540. if( optionMode == OPTION_ADVANCED )
  3541. {
  3542. if( refreshFlag & SGOPTION_PAGE )
  3543. {
  3544. image_menu.put_to_buf( &vga_back, "MPG-O1");
  3545. image_menu.put_back( 234, 15, menuTitleBitmap);
  3546. vga.blt_buf(0,0,VGA_WIDTH-1,VGA_HEIGHT-1,0);
  3547. }
  3548. // ###### begin Gilbert 24/10 #######//
  3549. if( refreshFlag & SGOPTION_MAP_ID )
  3550. mapIdField.paint();
  3551. // ###### end Gilbert 24/10 #######//
  3552. if( refreshFlag & SGOPTION_EXPLORED )
  3553. exploreGroup.paint(1-tempConfig.explore_whole_map);
  3554. if( refreshFlag & SGOPTION_FOG )
  3555. fogGroup.paint(1-tempConfig.fog_of_war);
  3556. if( refreshFlag & SGOPTION_TREASURE )
  3557. treasureGroup.paint( tempConfig.start_up_cash-1 );
  3558. if( refreshFlag & SGOPTION_AI_TREASURE )
  3559. aiTreasureGroup.paint( tempConfig.ai_start_up_cash-1 );
  3560. if( refreshFlag & SGOPTION_AI_AGGRESSIVE )
  3561. aiAggressiveGroup.paint(tempConfig.ai_aggressiveness-1);
  3562. if( refreshFlag & SGOPTION_FRYHTANS )
  3563. monsterGroup.paint(tempConfig.monster_type);
  3564. if( refreshFlag & SGOPTION_RANDOM_STARTUP )
  3565. randomStartUpGroup.paint(1-tempConfig.random_start_up);
  3566. }
  3567. // ------- display advanced option ---------//
  3568. if( optionMode == OPTION_ADVANCE2 )
  3569. {
  3570. if( refreshFlag & SGOPTION_PAGE )
  3571. {
  3572. image_menu.put_to_buf( &vga_back, "MPG-O2");
  3573. image_menu.put_back( 234, 15, menuTitleBitmap);
  3574. vga.blt_buf(0,0,VGA_WIDTH-1,VGA_HEIGHT-1,0);
  3575. }
  3576. if( refreshFlag & SGOPTION_RAW )
  3577. {
  3578. font_san.center_put(327, offsetY+77, 327+25, offsetY+77+21,
  3579. m.format(tempConfig.start_up_raw_site), 1);
  3580. rawSiteInc.paint();
  3581. rawSiteDec.paint();
  3582. }
  3583. if( refreshFlag & SGOPTION_NEAR_RAW )
  3584. nearRawGroup.paint(1-tempConfig.start_up_has_mine_nearby);
  3585. if( refreshFlag & SGOPTION_START_TOWN )
  3586. townStartGroup.paint(
  3587. tempConfig.start_up_independent_town >= 30 ? 2 :
  3588. tempConfig.start_up_independent_town <= 7 ? 0 :
  3589. 1
  3590. );
  3591. if( refreshFlag & SGOPTION_TOWN_STRENGTH )
  3592. townResistGroup.paint(tempConfig.independent_town_resistance-1);
  3593. if( refreshFlag & SGOPTION_TOWN_EMERGE )
  3594. townEmergeGroup.paint(1-tempConfig.new_independent_town_emerge);
  3595. if( refreshFlag & SGOPTION_KINGDOM_EMERGE )
  3596. nationEmergeGroup.paint(1-tempConfig.new_nation_emerge);
  3597. if( refreshFlag & SGOPTION_RANDOM_EVENT )
  3598. randomEventGroup.paint(tempConfig.random_event_frequency);
  3599. }
  3600. // ------- display goal option ---------//
  3601. if( optionMode == OPTION_GOAL )
  3602. {
  3603. if( refreshFlag & SGOPTION_PAGE )
  3604. {
  3605. image_menu.put_to_buf( &vga_back, "MPG-GOAL");
  3606. image_menu.put_back( 234, 15, menuTitleBitmap);
  3607. vga.blt_buf(0,0,VGA_WIDTH-1,VGA_HEIGHT-1,0);
  3608. }
  3609. if( refreshFlag & SGOPTION_CLEAR_ENEMY )
  3610. clearEnemyButton.paint();
  3611. if( refreshFlag & SGOPTION_CLEAR_MONSTER )
  3612. clearMonsterButton.paint(tempConfig.goal_destroy_monster);
  3613. // ####### begin Gilbert 25/10 ########//
  3614. if( refreshFlag & SGOPTION_ENOUGH_PEOPLE )
  3615. {
  3616. enoughPeopleButton.paint(tempConfig.goal_population_flag);
  3617. font_san.center_put( 446, offsetY+176, 446+67, offsetY+176+21,
  3618. m.format(tempConfig.goal_population), 1);
  3619. peopleInc.paint();
  3620. peopleDec.paint();
  3621. }
  3622. if( refreshFlag & SGOPTION_ENOUGH_INCOME )
  3623. {
  3624. enoughIncomeButton.paint(tempConfig.goal_economic_score_flag);
  3625. font_san.center_put( 446, offsetY+207, 446+67, offsetY+207+21,
  3626. m.format(tempConfig.goal_economic_score), 1);
  3627. incomeInc.paint();
  3628. incomeDec.paint();
  3629. }
  3630. if( refreshFlag & SGOPTION_ENOUGH_SCORE )
  3631. {
  3632. enoughScoreButton.paint(tempConfig.goal_total_score_flag);
  3633. font_san.center_put( 446, offsetY+239, 446+67, offsetY+239+21,
  3634. m.format(tempConfig.goal_total_score), 1);
  3635. scoreInc.paint();
  3636. scoreDec.paint();
  3637. }
  3638. if( refreshFlag & SGOPTION_TIME_LIMIT )
  3639. {
  3640. timeLimitButton.paint(tempConfig.goal_year_limit_flag);
  3641. font_san.center_put( 446, offsetY+271, 446+33, offsetY+271+21,
  3642. m.format(tempConfig.goal_year_limit), 1);
  3643. yearInc.paint();
  3644. yearDec.paint();
  3645. }
  3646. // ####### end Gilbert 25/10 ########//
  3647. }
  3648. // -------- refresh players in the session --------//
  3649. if( mRefreshFlag & MGOPTION_PLAYERS )
  3650. {
  3651. vga.blt_buf( 96, 46, 702, 100, 0 );
  3652. for( p = 0; p < regPlayerCount; ++p)
  3653. {
  3654. if( playerReadyFlag[p] )
  3655. {
  3656. image_menu.put_front( tickX[p]+3, tickY[p]+3, "NMPG-RCH" );
  3657. }
  3658. PlayerDesc *dispPlayer = mp_obj.search_player(regPlayerId[p]);
  3659. font_san.put( tickX[p]+nameOffsetX, tickY[p]+nameOffsetY, dispPlayer?dispPlayer->friendly_name_str():(char*)"?anonymous?" );
  3660. }
  3661. }
  3662. // ------------ display chat message --------//
  3663. if( mRefreshFlag & MGOPTION_OUT_MESSAGE )
  3664. {
  3665. messageField.paint();
  3666. }
  3667. // ------------- display incoming chat message --------//
  3668. if( mRefreshFlag & MGOPTION_IN_MESSAGE )
  3669. {
  3670. vga.blt_buf( 101, 135, 700, 202, 0 );
  3671. for( p = 1; p <= 4 && p <= messageList.size() ; ++p)
  3672. {
  3673. int ny = 136+(p-1)*16;
  3674. int nx = font_san.put( 102, ny, ((MpStructChatMsg *)messageList.get(p))->sender );
  3675. nx = font_san.put( nx, ny, " : ");
  3676. nx = font_san.put( nx, ny, ((MpStructChatMsg *)messageList.get(p))->content, 0, 700);
  3677. }
  3678. }
  3679. // ------- display difficulty -------//
  3680. if( (refreshFlag & SGOPTION_DIFFICULTY) || (mRefreshFlag & MGOPTION_PLAYERS) )
  3681. {
  3682. font_san.center_put( 718, offsetY+84, 774, offsetY+108,
  3683. m.format(tempConfig.difficulty_rating), 1 );
  3684. }
  3685. // -------- repaint button -------//
  3686. if( refreshFlag & SGOPTION_PAGE )
  3687. {
  3688. if( remote.is_host )
  3689. startButton.paint();
  3690. readyButton.paint();
  3691. returnButton.paint();
  3692. }
  3693. refreshFlag = 0;
  3694. mRefreshFlag = 0;
  3695. }
  3696. sys.blt_virtual_buf();
  3697. if( config.music_flag )
  3698. {
  3699. if( !music.is_playing() )
  3700. music.play(1, sys.cdrom_drive ? MUSIC_CD_THEN_WAV : 0 );
  3701. }
  3702. else
  3703. music.stop();
  3704. // --------- detect remote message -------//
  3705. mp_obj.before_receive();
  3706. recvPtr = mp_obj.receive(&from, &to, &recvLen, &sysMsgCount);
  3707. mp_obj.after_send();
  3708. if( sysMsgCount )
  3709. {
  3710. // see any player disconnect
  3711. for(int q = 0; q < regPlayerCount; ++q)
  3712. {
  3713. if( !mp_obj.is_player_connecting(regPlayerId[q]) )
  3714. {
  3715. mRefreshFlag |= MGOPTION_PLAYERS;
  3716. memmove( regPlayerId+q, regPlayerId+q+1, (MAX_NATION-1-q)*sizeof(regPlayerId[0]) );
  3717. regPlayerId[MAX_NATION-1] = 0;
  3718. memmove( playerReadyFlag+q, playerReadyFlag+q+1, (MAX_NATION-1-q)*sizeof(playerReadyFlag[0]) );
  3719. playerReadyFlag[MAX_NATION-1] = 0;
  3720. short freeColor = playerColor[q];
  3721. memmove( playerColor+q, playerColor+q+1, (MAX_NATION-1-q)*sizeof(playerColor[0]) );
  3722. playerColor[MAX_NATION-1] = 0;
  3723. if(freeColor > 0 && freeColor <= MAX_COLOR_SCHEME)
  3724. colorAssigned[freeColor-1] = 0;
  3725. short freeRace = playerRace[q];
  3726. memmove( playerRace+q, playerRace+q+1, (MAX_NATION-1-q)*sizeof(playerRace[0]) );
  3727. playerRace[MAX_NATION-1] = 0;
  3728. if(freeRace > 0 && freeRace <= MAX_RACE)
  3729. raceAssigned[freeRace-1]--;
  3730. memmove( playerBalance+q, playerBalance+q+1, (MAX_NATION-1-q)*sizeof(playerBalance[0]) );
  3731. playerBalance[MAX_NATION-1] = 0;
  3732. --regPlayerCount;
  3733. --q;
  3734. }
  3735. }
  3736. }
  3737. if( recvPtr )
  3738. {
  3739. if( ((MpStructBase *)recvPtr)->msg_id == MPMSG_START_GAME )
  3740. {
  3741. retFlag = 1;
  3742. break; // break while(1) loop
  3743. }
  3744. else
  3745. {
  3746. switch( ((MpStructBase *)recvPtr)->msg_id )
  3747. {
  3748. case MPMSG_ABORT_GAME:
  3749. return 0;
  3750. case MPMSG_SEND_CONFIG:
  3751. tempConfig.change_game_setting( ((MpStructConfig *)recvPtr)->game_config );
  3752. refreshFlag |= SGOPTION_ALL_OPTIONS;
  3753. break;
  3754. case MPMSG_RANDOM_SEED:
  3755. info.init_random_seed( ((MpStructSeed *)recvPtr)->seed );
  3756. break;
  3757. // ####### begin Gilbert 25/10 #######//
  3758. case MPMSG_RANDOM_SEED_STR:
  3759. msgSeedStr = *(MpStructSeedStr *)recvPtr;
  3760. mapIdField.select_whole();
  3761. refreshFlag |= SGOPTION_MAP_ID;
  3762. break;
  3763. // ####### end Gilbert 25/10 #######//
  3764. case MPMSG_NEW_PLAYER:
  3765. {
  3766. // incorrect message, reject
  3767. MpStructRefuseNewPlayer msgRefuse(from);
  3768. mp_obj.send_stream(BROADCAST_PID, &msgRefuse, sizeof(msgRefuse) );
  3769. }
  3770. break;
  3771. case MPMSG_LOAD_GAME_NEW_PLAYER:
  3772. mp_obj.poll_players();
  3773. if( remote.is_host )
  3774. {
  3775. MpStructLoadGameNewPlayer *newPlayerMsg = (MpStructLoadGameNewPlayer *)recvPtr;
  3776. if( regPlayerCount < MAX_NATION
  3777. && !nation_array.is_deleted(newPlayerMsg->nation_recno)
  3778. && nation_array[newPlayerMsg->nation_recno]->color_scheme_id == newPlayerMsg->color_scheme_id
  3779. && nation_array[newPlayerMsg->nation_recno]->race_id == newPlayerMsg->race_id
  3780. && !colorAssigned[newPlayerMsg->color_scheme_id-1]
  3781. && newPlayerMsg->frame_count == sys.frame_count
  3782. && newPlayerMsg->random_seed == m.get_random_seed() )
  3783. {
  3784. regPlayerId[regPlayerCount] = newPlayerMsg->player_id;
  3785. playerReadyFlag[regPlayerCount] = 0;
  3786. raceAssigned[newPlayerMsg->race_id]++;
  3787. playerRace[regPlayerCount] = newPlayerMsg->race_id;
  3788. colorAssigned[newPlayerMsg->color_scheme_id-1]=1;
  3789. playerColor[regPlayerCount] = newPlayerMsg->color_scheme_id;
  3790. // send accept new player to all player
  3791. MpStructAcceptNewPlayer msgAccept(from);
  3792. mp_obj.send_stream( BROADCAST_PID, &msgAccept, sizeof(msgAccept) );
  3793. // send ready flag
  3794. for( int c = 0; c < regPlayerCount; ++c)
  3795. {
  3796. if( playerReadyFlag[c] )
  3797. {
  3798. MpStructPlayerReady msgReady(regPlayerId[c]);
  3799. mp_obj.send_stream(from, &msgReady, sizeof(msgReady));
  3800. }
  3801. }
  3802. // ###### patch begin Gilbert 22/1 ######//
  3803. // send remote.sync_test_level
  3804. MpStructSyncLevel msgSyncTest(remote.sync_test_level);
  3805. mp_obj.send_stream( from, &msgSyncTest, sizeof(msgSyncTest) );
  3806. // ###### patch end Gilbert 22/1 ######//
  3807. // update balance
  3808. playerBalance[regPlayerCount] = newPlayerMsg->player_balance;
  3809. regPlayerCount++;
  3810. mRefreshFlag |= MGOPTION_PLAYERS;
  3811. }
  3812. else
  3813. {
  3814. // reply refuse new player
  3815. MpStructRefuseNewPlayer msgRefuse(from);
  3816. mp_obj.send_stream( BROADCAST_PID, &msgRefuse, sizeof(msgRefuse) );
  3817. }
  3818. }
  3819. break;
  3820. case MPMSG_ACCEPT_NEW_PLAYER:
  3821. hostPlayerId = from;
  3822. if( regPlayerCount < MAX_NATION && ((MpStructAcceptNewPlayer *)recvPtr)->player_id != mp_obj.my_player_id )
  3823. {
  3824. // search if this player has existed
  3825. for( p=0; p < regPlayerCount && regPlayerId[p] != ((MpStructAcceptNewPlayer *)recvPtr)->player_id; ++p );
  3826. regPlayerId[p] = ((MpStructAcceptNewPlayer *)recvPtr)->player_id;
  3827. playerReadyFlag[p] = 0;
  3828. if( p >= regPlayerCount )
  3829. {
  3830. regPlayerCount++; // now regPlayerCount == p
  3831. err_when( p != regPlayerCount );
  3832. }
  3833. mRefreshFlag |= MGOPTION_PLAYERS;
  3834. }
  3835. break;
  3836. case MPMSG_PLAYER_READY:
  3837. {
  3838. for( int p = 0; p < regPlayerCount; ++p)
  3839. {
  3840. if( regPlayerId[p] == ((MpStructPlayerReady *)recvPtr)->player_id )
  3841. {
  3842. playerReadyFlag[p] = 1;
  3843. mRefreshFlag |= MGOPTION_PLAYERS;
  3844. }
  3845. }
  3846. }
  3847. break;
  3848. case MPMSG_PLAYER_UNREADY:
  3849. {
  3850. for( int p = 0; p < regPlayerCount; ++p)
  3851. {
  3852. if( regPlayerId[p] == ((MpStructPlayerUnready *)recvPtr)->player_id )
  3853. {
  3854. playerReadyFlag[p] = 0;
  3855. mRefreshFlag |= MGOPTION_PLAYERS;
  3856. }
  3857. }
  3858. }
  3859. break;
  3860. case MPMSG_SEND_CHAT_MSG:
  3861. while( messageList.size() >= 4 )
  3862. messageList.linkout(1);
  3863. messageList.linkin(recvPtr);
  3864. mRefreshFlag |= MGOPTION_IN_MESSAGE;
  3865. break;
  3866. // ###### patch begin Gilbert 22/1 ######//
  3867. case MPMSG_SEND_SYNC_TEST_LEVEL:
  3868. remote.sync_test_level = ((MpStructSyncLevel *)recvPtr)->sync_test_level;
  3869. break;
  3870. // ###### patch end Gilbert 22/1 ######//
  3871. case MPMSG_REFUSE_NEW_PLAYER:
  3872. if( ((MpStructRefuseNewPlayer *)recvPtr)->player_id == mp_obj.my_player_id )
  3873. {
  3874. box.msg("You cannot join the game because the multiplayer saved game you selected is different from those of other human players.");
  3875. return 0;
  3876. }
  3877. break;
  3878. default: // if the game is started, any other thing is received
  3879. return 0;
  3880. }
  3881. }
  3882. }
  3883. // --------- detect switch option button ------//
  3884. if( mouse.single_click(96, offsetY+12, 218, offsetY+54) )
  3885. {
  3886. if( optionMode != OPTION_BASIC )
  3887. {
  3888. optionMode = OPTION_BASIC;
  3889. refreshFlag = SGOPTION_ALL;
  3890. mRefreshFlag = MGOPTION_ALL;
  3891. }
  3892. }
  3893. else if( mouse.single_click(236, offsetY+12, 363, offsetY+54) )
  3894. {
  3895. if( optionMode != OPTION_ADVANCED )
  3896. {
  3897. optionMode = OPTION_ADVANCED;
  3898. refreshFlag = SGOPTION_ALL;
  3899. mRefreshFlag = MGOPTION_ALL;
  3900. }
  3901. }
  3902. else if( mouse.single_click(380, offsetY+12, 506, offsetY+54) )
  3903. {
  3904. if( optionMode != OPTION_ADVANCE2 )
  3905. {
  3906. optionMode = OPTION_ADVANCE2;
  3907. refreshFlag = SGOPTION_ALL;
  3908. mRefreshFlag = MGOPTION_ALL;
  3909. }
  3910. }
  3911. else if( mouse.single_click(523, offsetY+12, 649, offsetY+54) )
  3912. {
  3913. if( optionMode != OPTION_GOAL )
  3914. {
  3915. optionMode = OPTION_GOAL;
  3916. refreshFlag = SGOPTION_ALL;
  3917. mRefreshFlag = MGOPTION_ALL;
  3918. }
  3919. }
  3920. // --------- detect ready button button --------//
  3921. unsigned keyCode;
  3922. if( readyButton.detect() )
  3923. {
  3924. mRefreshFlag |= MGOPTION_PLAYERS;
  3925. for(p = 0; p < regPlayerCount && regPlayerId[p] != mp_obj.my_player_id; ++p);
  3926. if( p < regPlayerCount )
  3927. {
  3928. if( !selfReadyFlag )
  3929. {
  3930. playerReadyFlag[p] = selfReadyFlag = 1;
  3931. MpStructPlayerReady msgReady(mp_obj.my_player_id);
  3932. mp_obj.send_stream(BROADCAST_PID, &msgReady, sizeof(msgReady));
  3933. }
  3934. else
  3935. {
  3936. // else un-ready this player
  3937. playerReadyFlag[p] = selfReadyFlag = 0;
  3938. MpStructPlayerUnready msgUnready(mp_obj.my_player_id);
  3939. mp_obj.send_stream(BROADCAST_PID, &msgUnready, sizeof(msgUnready));
  3940. }
  3941. }
  3942. }
  3943. if( remote.is_host && startButton.detect() )
  3944. {
  3945. // see if all player is ready
  3946. short sumBalance = 0;
  3947. int q;
  3948. for( q = 0; q < regPlayerCount && playerReadyFlag[q]; ++q)
  3949. {
  3950. err_when( playerBalance[q] == 0 );
  3951. sumBalance += playerBalance[q];
  3952. }
  3953. if( q >= regPlayerCount ) // not all playerReadyFlag[p] = 1;
  3954. {
  3955. #ifdef DEBUG
  3956. sumBalance = 0;
  3957. #endif
  3958. #ifdef BETA
  3959. sumBalance = 0;
  3960. #endif
  3961. if( regPlayerCount != maxPlayer )
  3962. {
  3963. String str;
  3964. str = "This multiplayer saved game needs ";
  3965. str += maxPlayer;
  3966. str += " human players while now there ";
  3967. if( regPlayerCount > 1 )
  3968. str += " are";
  3969. else
  3970. str += " is";
  3971. str += " only ";
  3972. str += regPlayerCount;
  3973. if( regPlayerCount > 1 )
  3974. str += " human players.";
  3975. else
  3976. str += " human player.";
  3977. str += " The game cannot start.";
  3978. box.msg(str);
  3979. }
  3980. else if( sumBalance < 0 )
  3981. {
  3982. // too many non-CD version
  3983. box.msg("There are not enough Seven Kingdoms CDROMs to start the game. Each CDROM supports "PLAYER_RATIO_STRING" players.");
  3984. }
  3985. else
  3986. {
  3987. // MpStructBase msgStart(MPMSG_START_GAME);
  3988. // mp_obj.send_stream(BROADCAST_PID, &msgStart, sizeof(msgStart));
  3989. retFlag = 1;
  3990. break; // break while(1)
  3991. }
  3992. }
  3993. }
  3994. else if( returnButton.detect() )
  3995. {
  3996. if( remote.is_host )
  3997. {
  3998. MpStructBase msgAbort(MPMSG_ABORT_GAME);
  3999. mp_obj.send_stream(BROADCAST_PID, &msgAbort, sizeof(msgAbort) );
  4000. }
  4001. retFlag = 0;
  4002. break; // break while(1)
  4003. }
  4004. else if( (keyCode = messageField.detect()) != 0 )
  4005. {
  4006. mRefreshFlag |= MGOPTION_OUT_MESSAGE;
  4007. if(keyCode == KEY_RETURN && strlen(typingMsg.content) > 0)
  4008. {
  4009. // send message
  4010. mp_obj.send_stream(BROADCAST_PID, &typingMsg, sizeof(typingMsg) );
  4011. // clear the string
  4012. messageField.clear();
  4013. }
  4014. else if( keyCode == KEY_ESC )
  4015. {
  4016. messageField.clear();
  4017. }
  4018. }
  4019. mp_obj.after_send();
  4020. // ####### begin Gilbert 24/10 #######//
  4021. vga_front.unlock_buf();
  4022. // ####### end Gilbert 24/10 #######//
  4023. }
  4024. // ###### begin Gilbert 24/10 #######//
  4025. if( !vga_front.buf_locked )
  4026. vga_front.lock_buf();
  4027. // ###### end Gilbert 24/10 #######//
  4028. mp_obj.after_send();
  4029. // ---------- final setup to start multiplayer game --------//
  4030. if( retFlag )
  4031. {
  4032. retFlag = 0;
  4033. if( remote.is_host )
  4034. mp_obj.disable_join_session();
  4035. // mp_obj.poll_players();
  4036. int trial;
  4037. unsigned long startTime;
  4038. int playerCount = 0;
  4039. if( &config != &tempConfig )
  4040. config = tempConfig;
  4041. if( remote.is_host )
  4042. {
  4043. // setup nation now
  4044. VLenQueue setupString;
  4045. // ------- put start game string -------//
  4046. {
  4047. MpStructBase msgStart(MPMSG_START_GAME);
  4048. memcpy( setupString.reserve(sizeof(msgStart)), &msgStart, sizeof(msgStart) );
  4049. }
  4050. // ------- put nations -------//
  4051. playerCount = 0;
  4052. for( p = 0; p < regPlayerCount; ++p )
  4053. {
  4054. PID_TYPE playerId = regPlayerId[p];
  4055. PlayerDesc *player = mp_obj.search_player(playerId);
  4056. if( !playerId || !player || !player->connecting )
  4057. continue;
  4058. // match nation color
  4059. for( short nationRecno = 1; nationRecno <= nation_array.size(); ++nationRecno)
  4060. {
  4061. Nation *nationPtr;
  4062. if( !nation_array.is_deleted(nationRecno) && (nationPtr = nation_array[nationRecno])
  4063. && (nationPtr->is_own() || nationPtr->is_remote())
  4064. && playerColor[p] == nation_array[nationRecno]->color_scheme_id )
  4065. {
  4066. nationPtr->player_id = playerId;
  4067. nationPtr->next_frame_ready = 0;
  4068. ((MpStructNation *)setupString.reserve(sizeof(MpStructNation)))->init(
  4069. nationRecno, nationPtr->player_id,
  4070. nationPtr->color_scheme_id, nationPtr->race_id, player->friendly_name_str());
  4071. playerCount++;
  4072. break;
  4073. }
  4074. }
  4075. }
  4076. /*
  4077. for( int d = 1; playerCount<MAX_NATION && mp_obj.get_player(d); ++d)
  4078. {
  4079. // ensure it is a valid player
  4080. PlayerDesc *player = mp_obj.get_player(d);
  4081. PID_TYPE playerId = player ? player->pid() : 0;
  4082. if( !playerId || !player->connecting )
  4083. continue;
  4084. for( p = 0; p < regPlayerCount && regPlayerId[p] != playerId; ++p);
  4085. if( p >= regPlayerCount ) // not found
  4086. continue;
  4087. // match nation color
  4088. for( short nationRecno = 1; nationRecno <= nation_array.size(); ++nationRecno)
  4089. {
  4090. Nation *nationPtr;
  4091. if( !nation_array.is_deleted(nationRecno) && (nationPtr = nation_array[nationRecno])
  4092. && (nationPtr->is_own() || nationPtr->is_remote())
  4093. && playerColor[p] == nation_array[nationRecno]->color_scheme_id )
  4094. {
  4095. nationPtr->player_id = playerId;
  4096. nationPtr->next_frame_ready = 0;
  4097. ((MpStructNation *)setupString.reserve(sizeof(MpStructNation)))->init(
  4098. nationRecno, nationPtr->player_id,
  4099. nationPtr->color_scheme_id, nationPtr->race_id, player->friendly_name_str());
  4100. playerCount++;
  4101. break;
  4102. }
  4103. }
  4104. }
  4105. */
  4106. //--- if the current number of players < original number of players ---//
  4107. if( playerCount < maxPlayer )
  4108. {
  4109. String str;
  4110. str = "This multiplayer saved game needs ";
  4111. str += maxPlayer;
  4112. str += " human players while now there ";
  4113. if( playerCount > 1 )
  4114. str += " are";
  4115. else
  4116. str += " is";
  4117. str += " only ";
  4118. str += playerCount;
  4119. if( playerCount > 1 )
  4120. str += " human players.";
  4121. else
  4122. str += " human player.";
  4123. str += " The game cannot start.";
  4124. box.msg(str);
  4125. return 0;
  4126. }
  4127. //--- if the current number of players > original number of players ---//
  4128. if( playerCount > maxPlayer )
  4129. {
  4130. String str;
  4131. str = "This multiplayer saved game can only support ";
  4132. str += maxPlayer;
  4133. str += " human players while now there are ";
  4134. str += playerCount;
  4135. str += " human players. The game cannot start.";
  4136. box.msg(str);
  4137. return 0;
  4138. }
  4139. // ---- force set to the lowest frame delay -------//
  4140. #ifdef AMPLUS
  4141. remote.set_process_frame_delay(FORCE_MAX_FRAME_DELAY);
  4142. {
  4143. MpStructProcessFrameDelay msgFrameDelay(remote.get_process_frame_delay());
  4144. memcpy( setupString.reserve(sizeof(msgFrameDelay)), &msgFrameDelay, sizeof(msgFrameDelay));
  4145. }
  4146. #endif
  4147. // -------- send sync test level ----------//
  4148. {
  4149. MpStructSyncLevel msgSyncTest(remote.sync_test_level);
  4150. memcpy( setupString.reserve(sizeof(msgSyncTest)), &msgSyncTest, sizeof(msgSyncTest));
  4151. }
  4152. mp_obj.send_stream( BROADCAST_PID, setupString.queue_buf, setupString.length() );
  4153. mp_obj.after_send();
  4154. }
  4155. else
  4156. {
  4157. // use the message recving MPMSG_START_GAME
  4158. err_when( !recvPtr );
  4159. DWORD offset = 0;
  4160. int recvStartMsg = 0;
  4161. int ownPlayerFound = 0;
  4162. playerCount = 0;
  4163. char *oriRecvPtr = recvPtr;
  4164. int recvSetFrameDelay = 0;
  4165. int recvSyncTestLevel = 0;
  4166. // process the string received
  4167. while( offset < recvLen )
  4168. {
  4169. DWORD oldOffset = offset;
  4170. recvPtr = oriRecvPtr + offset;
  4171. switch( ((MpStructBase *)(recvPtr))->msg_id )
  4172. {
  4173. case MPMSG_START_GAME:
  4174. recvStartMsg = 1;
  4175. offset += sizeof( MpStructBase );
  4176. break;
  4177. case MPMSG_DECLARE_NATION:
  4178. {
  4179. MpStructNation *msgNation = (MpStructNation *)recvPtr;
  4180. short nationRecno = msgNation->nation_recno;
  4181. Nation *nationPtr;
  4182. if( nation_array.is_deleted(nationRecno) ||
  4183. !(nationPtr = nation_array[nationRecno]) ||
  4184. !nationPtr->is_own() && !nationPtr->is_remote() ||
  4185. nationPtr->color_scheme_id != msgNation->color_scheme )
  4186. {
  4187. box.msg( "Incorrect kingdom information received from the host." );
  4188. return 0;
  4189. }
  4190. nationPtr->player_id = msgNation->dp_player_id;
  4191. if( nationPtr->is_own() && msgNation->dp_player_id == mp_obj.my_player_id)
  4192. {
  4193. ownPlayerFound = 1;
  4194. }
  4195. nationPtr->next_frame_ready = 0;
  4196. nation_array.set_human_name(nationRecno, msgNation->player_name);
  4197. ++playerCount;
  4198. offset += sizeof( MpStructNation );
  4199. }
  4200. break;
  4201. case MPMSG_SET_PROCESS_FRAME_DELAY:
  4202. remote.set_process_frame_delay(((MpStructProcessFrameDelay *)recvPtr)->common_process_frame_delay);
  4203. ++recvSetFrameDelay;
  4204. offset += sizeof( MpStructProcessFrameDelay );
  4205. break;
  4206. case MPMSG_SEND_SYNC_TEST_LEVEL:
  4207. remote.sync_test_level = ((MpStructSyncLevel *)recvPtr)->sync_test_level;
  4208. ++recvSyncTestLevel;
  4209. offset += sizeof( MpStructSyncLevel );
  4210. break;
  4211. } // end switch
  4212. if( !recvStartMsg || offset <= oldOffset )
  4213. {
  4214. err_here();
  4215. box.msg( "Connection string from host is corrupted" );
  4216. return 0;
  4217. }
  4218. } // end while
  4219. if( playerCount == 0 )
  4220. {
  4221. box.msg( "Cannot get kingdom information from the host." );
  4222. return 0;
  4223. }
  4224. err_when( playerCount > MAX_NATION );
  4225. if( !ownPlayerFound )
  4226. {
  4227. box.msg( "The host cannot recognize your machine." );
  4228. return 0;
  4229. }
  4230. err_when( ownPlayerFound > 1 );
  4231. if( !recvSetFrameDelay || !recvSyncTestLevel )
  4232. {
  4233. box.msg("Cannot receive important information from the host");
  4234. return 0;
  4235. }
  4236. err_when( recvSetFrameDelay > 1 );
  4237. err_when( recvSyncTestLevel > 1 );
  4238. // ------- send end setting string ------- //
  4239. MpStructBase mpEndSetting(MPMSG_END_SETTING);
  4240. mp_obj.send_stream( from, &mpEndSetting, sizeof(mpEndSetting) );
  4241. mp_obj.after_send();
  4242. }
  4243. if( remote.sync_test_level == 0)
  4244. {
  4245. remote.set_alternating_send(playerCount > 4 ? 4 : playerCount); // automatic setting
  4246. }
  4247. {
  4248. // ------- broadcast end setting string ------- //
  4249. MpStructBase mpEndSetting(MPMSG_END_SETTING);
  4250. mp_obj.send_stream( BROADCAST_PID, &mpEndSetting, sizeof(mpEndSetting) );
  4251. mp_obj.after_send();
  4252. // ------ wait for MPMSG_END_SETTING ----------//
  4253. // ---- to filter other all message until MP_MSG_END_SETTING ---//
  4254. trial = 5000;
  4255. startTime = m.get_time();
  4256. int recvEndSetting = 0;
  4257. while( --trial > 0 || m.get_time() - startTime < 10000 )
  4258. {
  4259. if( recvEndSetting >= playerCount-1)
  4260. break;
  4261. mp_obj.before_receive();
  4262. recvPtr = mp_obj.receive( &from, &to, &recvLen);
  4263. mp_obj.after_send();
  4264. if( recvPtr )
  4265. {
  4266. trial = max(trial, 1000);
  4267. startTime = m.get_time();
  4268. if( ((MpStructBase *)recvPtr)->msg_id == MPMSG_END_SETTING )
  4269. {
  4270. recvEndSetting++;
  4271. }
  4272. }
  4273. }
  4274. if( recvEndSetting < playerCount-1 )
  4275. {
  4276. box.msg("Some player(s) encountered errors when initializing the game.");
  4277. // but continue
  4278. }
  4279. }
  4280. retFlag = 1;
  4281. }
  4282. return retFlag;
  4283. }
  4284. #ifdef Y_SHIFT
  4285. #error
  4286. #endif
  4287. #undef Y_SHIFT_FLAG
  4288. // --------- End of function Game::mp_select_load_option --------- //
  4289. static void disp_virtual_button(ButtonCustom *button, int)
  4290. {
  4291. mouse.hide_area(button->x1, button->y1, button->x2, button->y2);
  4292. if( !button->pushed_flag )
  4293. {
  4294. // copy from back buffer to front buffer
  4295. IMGcopy(vga_front.buf_ptr(), vga_front.buf_pitch(),
  4296. vga_back.buf_ptr(), vga_back.buf_pitch(),
  4297. button->x1, button->y1, button->x2, button->y2 );
  4298. }
  4299. else
  4300. {
  4301. // copy from back buffer to front buffer, but the area is
  4302. // darkened by 2 scale
  4303. IMGcopyRemap(vga_front.buf_ptr(), vga_front.buf_pitch(),
  4304. vga_back.buf_ptr(), vga_back.buf_pitch(),
  4305. button->x1, button->y1, button->x2, button->y2,
  4306. vga.vga_color_table->get_table(-2) );
  4307. // draw black frame
  4308. if( button->x2-button->x1+1 == BASIC_OPTION_X_SPACE &&
  4309. button->y2-button->y1+1 == BASIC_OPTION_HEIGHT )
  4310. {
  4311. image_interface.put_front(button->x1, button->y1, "BAS_DOWN");
  4312. }
  4313. else if( button->x2-button->x1+1 == COLOR_OPTION_X_SPACE &&
  4314. button->y2-button->y1+1 == COLOR_OPTION_HEIGHT )
  4315. {
  4316. image_interface.put_front(button->x1, button->y1, "COL_DOWN");
  4317. }
  4318. else if( button->x2-button->x1+1 == SERVICE_OPTION_X_SPACE &&
  4319. button->y2-button->y1+1 == SERVICE_OPTION_HEIGHT )
  4320. {
  4321. image_menu.put_front(button->x1, button->y1, "NMPG-1BD");
  4322. }
  4323. }
  4324. mouse.show_area();
  4325. }
  4326. static void disp_virtual_tick(ButtonCustom *button, int )
  4327. {
  4328. mouse.hide_area(button->x1, button->y1, button->x2, button->y2);
  4329. // copy from back buffer to front buffer
  4330. IMGcopy(vga_front.buf_ptr(), vga_front.buf_pitch(),
  4331. vga_back.buf_ptr(), vga_back.buf_pitch(),
  4332. button->x1, button->y1, button->x2, button->y2 );
  4333. if( button->pushed_flag )
  4334. image_menu.put_front( button->x1+3, button->y1+3, "NMPG-RCH" );
  4335. mouse.show_area();
  4336. }
  4337. static void disp_scroll_bar_func(SlideVBar *scroll, int)
  4338. {
  4339. short rectTop = scroll->rect_top();
  4340. short rectBottom = scroll->rect_bottom();
  4341. vga.blt_buf(scroll->scrn_x1, scroll->scrn_y1, scroll->scrn_x2, scroll->scrn_y2, 0);
  4342. vga_front.bar( scroll->scrn_x1, rectTop, scroll->scrn_x2, rectBottom, VGA_YELLOW+1);
  4343. if( rectBottom - rectTop > 6 )
  4344. {
  4345. vga_front.d3_panel_up(scroll->scrn_x1, rectTop, scroll->scrn_x2, rectBottom,2,0);
  4346. }
  4347. }