edit.cpp 103 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405
  1. /* $Id$
  2. * MegaZeux
  3. *
  4. * Copyright (C) 1996 Greg Janson
  5. * Copyright (C) 1998 Matthew D. Williams - dbwilli@scsn.net
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21. //Took out SMZX -Koji
  22. //Editing the world!
  23. #include "helpsys.h"
  24. #include "runrobot.h"
  25. #include "scrdisp.h"
  26. #include "scrdump.h"
  27. #include "sfx.h"
  28. #include "sfx_edit.h"
  29. #include "counter.h"
  30. #include "game.h"
  31. #include "fill.h"
  32. #include "meter.h"
  33. #include "password.h"
  34. #include "egacode.h"
  35. #include "block.h"
  36. #include "pal_ed.h"
  37. #include "char_ed.h"
  38. #include "edit_di.h"
  39. #include "beep.h"
  40. #include "boardmem.h"
  41. #include "intake.h"
  42. #include "mod.h"
  43. #include "param.h"
  44. #include "error.h"
  45. #include "idarray.h"
  46. #include "ems.h"
  47. #include "meminter.h"
  48. #include "cursor.h"
  49. #include "retrace.h"
  50. #include "string.h"
  51. #include "edit.h"
  52. #include "ezboard.h"
  53. #include "data.h"
  54. #include "const.h"
  55. #include "graphics.h"
  56. #include "window.h"
  57. #include "getkey.h"
  58. #include "palette.h"
  59. #include "idput.h"
  60. #include "hexchar.h"
  61. #include <dos.h>
  62. #include "roballoc.h"
  63. #include "saveload.h"
  64. #include <stdio.h>
  65. #include "blink.h"
  66. #include "cursor.h"
  67. /* Edit menu- (w/box ends on sides) Current menu name is highlighted. The
  68. bottom section zooms to show a list of options for the current menu,
  69. although all keys are available at all times. PGUP/PGDN changes menu.
  70. The menus are shown in listed order. [draw] can be [text]. (in which case
  71. there is the words "Type to place text" after the ->) [draw] can also be
  72. [place] or [block]. The options DRAW, TEXT, DEBUG, BLOCK, MOD, and DEF.
  73. COLORS are highlighted white (instead of green) when active. Debug mode
  74. pops up a small window in the lower left corner, which rushes to the right
  75. side and back when the cursor reaches 3/4 of the way towards it,
  76. horizontally. The menu itself is 15 lines wide and 7 lines high. The
  77. board display, w/o the debug menu, is 19 lines high and 80 lines wide.
  78. Note: SAVE is highlighted white if the world has changed since last load
  79. or save.
  80. The commands with ! instead of : have not been implemented yet.
  81. The menu line turns to "Overlay editing-" and the lower portion shows
  82. overlay commands on overlay mode.
  83. ÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
  84. X/Y: 99/99³
  85. Board: 000³
  86. Mem: 0000k³
  87. EMS: 0000k³
  88. Robot memory-³
  89. 64.0/64k 100%³
  90. ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
  91. WORLD BOARD THING CURSOR SHOW MISC Drawing:_!_ (_#_ PushableRobot p00)
  92. ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
  93. L:Load S:Save G:Global Info Alt+R:Restart Alt+T:Test *:Protection
  94. Alt+S:Status Info Alt+C:Char Edit Alt+E:Palette Alt+F:Sound Effects
  95. Alt+Z:Clear X:Exits Alt+P:Size/Pos I:Info A:Add D:Delete V:View
  96. Alt+I:Import Alt+X:Export B:Select Board Alt+O:Edit Overlay
  97. F3:Terrain F4:Item F5:Creature F6:Puzzle F7:Transport F8:Element
  98. F9:Misc F10:Objects P:Parameter C:Color
  99. :Move Space:Place Enter:Modify+Grab Alt+M:Modify Ins:Grab Del:Delete
  100. F:Fill Tab:Draw F2:Text Alt+B:Block Alt+:Move 10
  101. Shift+F1:Show InvisWalls Shift+F2:Show Robots Shift+F3:Show Fakes
  102. Shift+F4:Show Spaces
  103. F1!Help R:Redraw Screen Alt+A:Select Char Set Alt+D:Default Colors
  104. ESC:Exit Alt+L:Test SAM Alt+Y:Debug Mode Alt+N:Music
  105. ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄPgup/Pgdn:MenuÄ
  106. ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
  107. OVERLAY EDITING- (Alt+O to end) Current:_!_ (_#_ Character p00)
  108. ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
  109. :Move Space:Place Ins:Grab Enter:Character Del:Delete F:Fill
  110. C:Color Alt+B:Block Tab:Draw Alt+:Move 10 Alt+S:Show level F2:Text
  111. ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
  112. Undocumented keys:
  113. End: LR corner
  114. Home: UL corner
  115. ESC: Cancel mode/overlay mode if active (otherwise exit)
  116. Backspace: Delete (move left one in text)
  117. Alt+W: redraw screen
  118. */
  119. /* Editing data */
  120. int draw_mode=0;//1 for on, 2 for text, 3 for block, 4 for block place.
  121. //+128 for overlay.
  122. int curr_color=7,curr_thing=0,curr_param=0;//Current. Param 0 for robot/etc
  123. //is temp. storage to be deleted
  124. //or realigned upon first
  125. //placement. Other params mean
  126. //to copy on placement.
  127. char curr_menu=0;//Current menu, 0 thru 5.
  128. char def_color_mode=1;//If default colors are on.
  129. char debug_mode=0,debug_x=0;//If debug mode is on, and X position of box.
  130. int x_pos=0,y_pos=0;//Current screen cursor position.
  131. int x_top_pos=0,y_top_pos=0;//Current x/y position in array of screen
  132. #define ARRAY_X (x_pos+x_top_pos)
  133. #define ARRAY_Y (y_pos+y_top_pos)
  134. #define ARRAY_OFFS (ARRAY_X+ARRAY_Y*max_bxsiz)
  135. char changed=0;//Whether world has changed since a load or save.
  136. //Whether to update menu and/or view, whether to fade in
  137. char update_menu=1,fade_in=1,update_view=1;
  138. //Remembers one corner of a block cmd or the starting position for a text cmd
  139. int save_x,save_y;
  140. int save_x2,save_y2;
  141. char blk_cmd;
  142. //Whether to show non-overlay when editing overlay
  143. char show_level=1;
  144. /* Menu data */
  145. #define NUM_MENUS 6
  146. char far menu_names[NUM_MENUS][9]={
  147. " WORLD "," BOARD "," THING "," CURSOR "," SHOW "," MISC " };
  148. char far draw_names[6][10]={ " Current:"," Drawing:"," Text:"," Block:",
  149. " Block:"," Import:" };
  150. char far text_help[19]="Type to place text";
  151. char far block_help[28]="Press ENTER on other corner";
  152. char far block_help2[27]="Press ENTER to place block";
  153. char far block_help3[26]="Press ENTER to place ANSi";
  154. char far menu_help[15]="Pgup/Pgdn:Menu";
  155. char far *menu_lines[NUM_MENUS][2]={ {
  156. " L:LoadS:Save G:Global Info Alt+R:Restart Alt+T:Test *:Protection",
  157. " Alt+S:Status Info Alt+C:Char Edit Alt+E:Palette Alt+F:Sound Effects"
  158. } , {
  159. " Alt+Z:Clear X:Exits Alt+P:Size/Pos I:Info A:Add D:Delete V:View",
  160. " Alt+I:Import Alt+X:Export B:Select Board Alt+O:Edit Overlay"
  161. } , {
  162. " F3:Terrain F4:Item F5:Creature F6:Puzzle F7:Transport F8:Element",
  163. " F9:MiscF10:Objects P:Parameter C:Color"
  164. } , {
  165. " :Move Space:Place Enter:Modify+Grab Alt+M:Modify Ins:Grab Del:Delete",
  166. " F:Fill Tab:DrawF2:Text Alt+B:Block Alt+:Move 10"
  167. } , {
  168. " Shift+F1:Show InvisWalls Shift+F2:Show Robots Shift+F3:Show Fakes",
  169. " Shift+F4:Show Spaces"
  170. } , {
  171. " F1:Help R:Redraw Screen Alt+A:Select Char Set Alt+D:Default Colors",
  172. " ESC:Exit Alt+L:Test SAM Alt+Y:Debug Mode Alt+N:Music Alt+8:Mod *"
  173. } };
  174. int far menu_keys[NUM_MENUS+1][2][28]={ {
  175. { 6,'L',5,0,6,'S',2,0,13,'G',4,0,13,-19,2,0,10,-20,2,0,12,'*',2,0 },
  176. { 17,-31,2,0,15,-46,2,0,13,-18,2,0,19,-33,7,0 }
  177. },{
  178. { 11,-44,3,0,7,'X',7,0,14,-25,2,0,6,'I',2,0,5,'A',2,0,8,'D',2,0,6,'V',2,0 },
  179. { 12,-23,2,0,12,-45,2,0,14,'B',2,0,18,-24,2,0 }
  180. },{
  181. { 10,-61,2,0,7,-62,6,0,11,-63,2,0,9,-64,2,0,12,-65,2,0,10,-66,4,0 },
  182. { 7,-67,5,0,11,-68,2,0,11,'P',2,0,7,'C',32,0 }
  183. },{
  184. { 9,0,11,' ',2,0,17,13,2,0,12,-50,2,0,8,-82,2,0,10,-83,2,0 },
  185. { 6,'F',3,0,8,9,5,0,7,-60,12,0,11,-48,22,0 }
  186. },{
  187. { 24,-84,2,0,20,-85,2,0,19,-86,10,0 },
  188. { 20,-87,57,0 }
  189. },{
  190. { 7,-59,4,0,15,'R',2,0,21,-30,2,0,20,-32,6,0 },
  191. { 8,27,3,0,14,-38,3,0,16,-21,7,0,11,-49,15,0 }
  192. },{
  193. { 9,0,11,' ',2,0,8,-82,2,0,15,13,2,0,10,-83,8,0,6,'F',4,0 },
  194. { 7,'C',2,0,11,-48,2,0,8,9,19,0,16,-31,2,0,7,-60,3,0 } } };
  195. char far *overlay_menu_lines[4]={
  196. " OVERLAY EDITING- (Alt+O to end)",
  197. " :Move Space:Place Ins:Grab Enter:Character Del:Delete F:Fill",
  198. " C:Color Alt+B:Block Tab:Draw Alt+:Move 10 Alt+S:Show level F2:Text",
  199. "Character" };
  200. void add_ext(char far *str,char far *ext) {
  201. int t1,t2=str_len(str);
  202. //check for existing ext.
  203. for(t1=0;t1<t2;t1++)
  204. if(str[t1]=='.') break;
  205. if(t1<t2) return;
  206. str[8]=0;//Limit main filename section to 8 chars
  207. str_cat(str,ext);
  208. }
  209. void edit_world(void) {
  210. int t1,t2,t3,t4,t5,t6,t7,t8,t9,t0;
  211. int key;
  212. char temp[20];
  213. char ansi[15];
  214. long tlong1,tlong2;
  215. char r,g,b;
  216. FILE *fp;
  217. set_context(80);
  218. error_mode=0;
  219. //Clear world on entrance
  220. clear_world();
  221. clear_zero_objects();
  222. scroll_color=15;
  223. scroll_base_color=143;
  224. scroll_corner_color=135;
  225. scroll_pointer_color=128;
  226. scroll_title_color=143;
  227. scroll_arrow_color=142;
  228. //Setup most variables
  229. draw_mode=curr_thing=curr_param=curr_menu=x_pos=y_pos=changed=
  230. x_top_pos=y_top_pos=0;
  231. curr_color=update_menu=fade_in=7;
  232. show_level=1;
  233. debug_x=65;
  234. //Set page
  235. current_page=0;
  236. current_pg_seg=VIDEO_SEG;
  237. //Clear screen
  238. clear_screen(1824,current_pg_seg);
  239. m_show();
  240. //Normally cursor is moved right after key interpretation.
  241. move_cursor(x_pos,y_pos);
  242. cursor_solid();
  243. do {
  244. //If NOTHING was changed, do NOT page flip
  245. if(!(update_view|update_menu|fade_in)) {
  246. m_hide();
  247. goto no_pflip;
  248. }
  249. //Pre-page flip
  250. current_pg_seg=VIDEO_NUM2SEG(!current_page);
  251. //Draw view OR copy view from old page
  252. if(update_view) {
  253. //Fill area to blot out overflow
  254. fill_line(1520,0,0,EC_NA_FILL*256+177,current_pg_seg);
  255. if(draw_mode<128) {
  256. overlay_mode|=128;
  257. draw_edit_window(x_top_pos,y_top_pos,current_pg_seg);
  258. overlay_mode&=~128;
  259. }
  260. else {
  261. //ALWAYS shown as a normal overlay.
  262. t1=overlay_mode;
  263. overlay_mode=1;
  264. if(!show_level) overlay_mode|=64;
  265. draw_edit_window(x_top_pos,y_top_pos,current_pg_seg);
  266. overlay_mode=t1;
  267. }
  268. //Highlight block, if any
  269. if((draw_mode&127)==3) {
  270. //From t1/t2 to t3/t4
  271. t1=save_x;
  272. t2=save_y;
  273. t3=ARRAY_X;
  274. t4=ARRAY_Y;
  275. if(t3<t1) {
  276. t5=t1;
  277. t1=t3;
  278. t3=t5;
  279. }
  280. if(t4<t2) {
  281. t5=t2;
  282. t2=t4;
  283. t4=t5;
  284. }
  285. //Offset by xy_top_pos
  286. t1-=x_top_pos;
  287. t2-=y_top_pos;
  288. t3-=x_top_pos;
  289. t4-=y_top_pos;
  290. //Clip to screen
  291. if(t1<0) t1=0;
  292. if(t2<0) t2=0;
  293. if(t3>79) t3=79;
  294. if(t4>18) t4=18;
  295. //t3 becomes WIDTH
  296. t3=t3-t1+1;
  297. //Highlight block
  298. for(;t2<=t4;t2++)
  299. color_line(t3,t1,t2,159,current_pg_seg);
  300. }
  301. }
  302. else {
  303. //Copy 19 lines of 80 chars of 2 bytes each.
  304. m_hide();
  305. mem_cpy((char far *)MK_FP(current_pg_seg,0),
  306. (char far *)MK_FP(VIDEO_NUM2SEG(current_page),0),3040);
  307. m_show();
  308. }
  309. //Draw menu (draw debug if view updated)
  310. if(update_menu|update_view) {
  311. if(debug_mode) {
  312. draw_debug_box();
  313. update_view=0;
  314. }
  315. //Draw box
  316. if(update_menu) {
  317. draw_window_box(0,19,79,24,current_pg_seg,EC_MAIN_BOX,
  318. EC_MAIN_BOX_DARK,EC_MAIN_BOX_CORNER,0);
  319. draw_window_box(0,21,79,24,current_pg_seg,EC_MAIN_BOX,
  320. EC_MAIN_BOX_DARK,EC_MAIN_BOX_CORNER,0);
  321. draw_char(196,EC_MAIN_BOX_CORNER,78,21,current_pg_seg);
  322. draw_char(217,EC_MAIN_BOX_DARK,79,21,current_pg_seg);
  323. //Write menu names
  324. if(draw_mode<128) {
  325. t3=1;//X position
  326. for(t1=0;t1<NUM_MENUS;t1++) {
  327. t2=EC_MENU_NAME;//Pick the color
  328. if(t1==curr_menu) t2=EC_CURR_MENU_NAME;
  329. //Write it
  330. write_string(menu_names[t1],t3,20,t2,current_pg_seg);
  331. //Add to x
  332. t3+=str_len(menu_names[t1]);
  333. }
  334. }
  335. else {
  336. write_string(overlay_menu_lines[0],1,20,EC_MENU_NAME,
  337. current_pg_seg);
  338. t3=42;
  339. }
  340. //Write mode string
  341. write_string(draw_names[draw_mode&127],t3,20,EC_MODE_STR,current_pg_seg);
  342. t3+=str_len(draw_names[draw_mode&127]);
  343. //Write help or current thing
  344. if((draw_mode&127)==2) write_string(text_help,t3,20,EC_MODE_HELP,
  345. current_pg_seg);
  346. else if((draw_mode&127)==3) write_string(block_help,t3,20,EC_MODE_HELP,
  347. current_pg_seg);
  348. else if((draw_mode&127)==4) write_string(block_help2,t3,20,EC_MODE_HELP,
  349. current_pg_seg);
  350. else if((draw_mode&127)==5) write_string(block_help3,t3,20,EC_MODE_HELP,
  351. current_pg_seg);
  352. else {
  353. //Current thing
  354. draw_char(' ',7,t3,20,current_pg_seg);
  355. draw_char(' ',7,t3+2,20,current_pg_seg);
  356. //Use id_put
  357. if(draw_mode<128) {
  358. t1=level_id[0];
  359. t2=level_color[0];
  360. t4=level_param[0];
  361. t5=level_under_color[0];
  362. level_id[0]=curr_thing;
  363. level_color[0]=curr_color;
  364. level_param[0]=curr_param;
  365. level_under_color[0]=0;
  366. overlay_mode|=128;
  367. id_put(t3+1,20,0,0,0,0,current_pg_seg);
  368. overlay_mode&=~128;
  369. level_id[0]=t1;
  370. level_color[0]=t2;
  371. level_param[0]=t4;
  372. level_under_color[0]=t5;
  373. }
  374. else draw_char(curr_param,curr_color,t3+1,20,current_pg_seg);
  375. //Space and '('
  376. t3+=4;
  377. draw_char('(',EC_CURR_THING,t3++,20,current_pg_seg);
  378. //Color symbol
  379. draw_color_box(curr_color,0,t3,20,current_pg_seg);
  380. //Name of thing
  381. if(draw_mode&128) {
  382. write_string(overlay_menu_lines[3],t3+4,20,EC_CURR_THING,
  383. current_pg_seg);
  384. t3+=str_len(overlay_menu_lines[3])+5;
  385. }
  386. else {
  387. write_string(thing_names[curr_thing],t3+4,20,EC_CURR_THING,
  388. current_pg_seg);
  389. t3+=str_len(thing_names[curr_thing])+5;
  390. }
  391. //Parameter (DON'T SHOW for robots/etc unless RPARAM def'd)
  392. #ifndef RPARAM
  393. if(curr_thing<122) {
  394. #endif
  395. draw_char('p',EC_CURR_PARAM,t3++,20,current_pg_seg);
  396. write_hex_byte(curr_param,EC_CURR_PARAM,t3,20,current_pg_seg);
  397. t3+=2;
  398. #ifndef RPARAM
  399. }
  400. else t3--;
  401. #endif
  402. //')'
  403. draw_char(')',EC_CURR_THING,t3,20,current_pg_seg);
  404. //Done
  405. }
  406. //Draw current menu
  407. if(draw_mode&128) {
  408. write_string(overlay_menu_lines[1],1,22,EC_OPTION,current_pg_seg);
  409. write_string(overlay_menu_lines[2],1,23,EC_OPTION,current_pg_seg);
  410. }
  411. else {
  412. write_string(menu_lines[curr_menu][0],1,22,EC_OPTION,current_pg_seg);
  413. write_string(menu_lines[curr_menu][1],1,23,EC_OPTION,current_pg_seg);
  414. }
  415. //Highlight any current options
  416. if(draw_mode&128) {
  417. if(show_level)
  418. color_line(16,51,23,EC_HIGHLIGHTED_OPTION,current_pg_seg);
  419. if(draw_mode==129)
  420. color_line(8,24,23,EC_HIGHLIGHTED_OPTION,current_pg_seg);
  421. else if(draw_mode==130)
  422. color_line(7,69,23,EC_HIGHLIGHTED_OPTION,current_pg_seg);
  423. else if((draw_mode==131)||(draw_mode==132))
  424. color_line(11,11,23,EC_HIGHLIGHTED_OPTION,current_pg_seg);
  425. }
  426. else if(curr_menu==0) {
  427. if(changed)
  428. color_line(6,13,22,EC_HIGHLIGHTED_OPTION,current_pg_seg);
  429. }
  430. else if(curr_menu==3) {
  431. if(draw_mode==1)
  432. color_line(8,11,23,EC_HIGHLIGHTED_OPTION,current_pg_seg);
  433. else if(draw_mode==2)
  434. color_line(7,24,23,EC_HIGHLIGHTED_OPTION,current_pg_seg);
  435. else if((draw_mode==3)||(draw_mode==4))
  436. color_line(11,43,23,EC_HIGHLIGHTED_OPTION,current_pg_seg);
  437. }
  438. else if(curr_menu==5) {
  439. if(def_color_mode)
  440. color_line(20,53,22,EC_HIGHLIGHTED_OPTION,current_pg_seg);
  441. if(mod_playing[0]!=0)
  442. color_line(11,53,23,EC_HIGHLIGHTED_OPTION,current_pg_seg);
  443. if(debug_mode)
  444. color_line(16,30,23,EC_HIGHLIGHTED_OPTION,current_pg_seg);
  445. }
  446. //Write menu help string
  447. if(draw_mode<128)
  448. write_string(menu_help,64,24,EC_CURR_PARAM,current_pg_seg);
  449. //Done!
  450. }
  451. else {//Otherwise copy menu
  452. m_hide();
  453. mem_cpy((char far *)MK_FP(current_pg_seg,3040),
  454. (char far *)MK_FP(VIDEO_NUM2SEG(current_page),3040),960);
  455. m_show();
  456. }
  457. //Menu is updated
  458. update_menu=0;
  459. }
  460. else {//Otherwise copy menu
  461. m_hide();
  462. mem_cpy((char far *)MK_FP(current_pg_seg,3040),
  463. (char far *)MK_FP(VIDEO_NUM2SEG(current_page),3040),960);
  464. m_show();
  465. }
  466. //Page flip
  467. current_page=1-current_page;
  468. //Page flip automatically doesn't occur until NEXT retrace.
  469. //But we wait until then so we don't start writing on the
  470. //visible page!
  471. m_hide();
  472. page_flip(current_page);
  473. move_cursor(x_pos,y_pos);
  474. cursor_solid();
  475. m_vidseg(current_pg_seg);
  476. wait_retrace();
  477. //Fade in (used upon entrance)
  478. if(fade_in) {
  479. vquick_fadein();
  480. fade_in=0;
  481. //Turn cursor on
  482. cursor_solid();
  483. }
  484. no_pflip:
  485. //Move cursor done at end of loop
  486. if(debug_mode) {
  487. write_number(ARRAY_X,EC_DEBUG_NUMBER,debug_x+7,13,current_pg_seg,3);
  488. write_number(ARRAY_Y,EC_DEBUG_NUMBER,debug_x+11,13,current_pg_seg,3);
  489. }
  490. //Highlight cursor - Save old color/char and fiddle with it
  491. t1=t2=*(unsigned char far *)MK_FP(current_pg_seg,((x_pos+y_pos*80)<<1)+1);
  492. //If same fg/bk, flip the bk brightness
  493. if((t1&15)==((t1&240)>>4)) t1^=128;
  494. *(unsigned char far *)MK_FP(current_pg_seg,((x_pos+y_pos*80)<<1)+1)=t1;
  495. //Check character- if it is a 219, change to a space.
  496. //If it is a ², make it a °.
  497. t1=t3=*(unsigned char far *)MK_FP(current_pg_seg,(x_pos+y_pos*80)<<1);
  498. if(t1==219) t1=32;
  499. if(t1==178) t1=176;
  500. *(unsigned char far *)MK_FP(current_pg_seg,(x_pos+y_pos*80)<<1)=t1;
  501. //Get key
  502. m_show();
  503. key=getkey();
  504. m_hide();
  505. //Fix cursor
  506. *(unsigned char far *)MK_FP(current_pg_seg,((x_pos+y_pos*80)<<1)+1)=t2;
  507. *(unsigned char far *)MK_FP(current_pg_seg,(x_pos+y_pos*80)<<1)=t3;
  508. m_show();
  509. //Act upon key
  510. cursor_off();
  511. //Check for text mode...
  512. if(((draw_mode&127)==2)&&((key>=32)&&(key<=255))) {
  513. //Place a character.
  514. changed=1;
  515. if(!(draw_mode&128)) {
  516. if(level_id[ARRAY_OFFS]==127) goto move_right;//No overwriting player
  517. //If top thing at position is a robot/etc, deallocate it. If it
  518. //is the CURRENT thing, copy to #0 first
  519. t1=level_id[ARRAY_OFFS];
  520. if(t1==122) {//(sensor)
  521. if((level_param[ARRAY_OFFS]==curr_param)&&(curr_thing==122))
  522. copy_sensor(0,curr_param);
  523. clear_sensor(level_param[ARRAY_OFFS]);
  524. curr_param=0;
  525. }
  526. else if((t1==123)||(t1==124)) {//(robot)
  527. if((level_param[ARRAY_OFFS]==curr_param)&&
  528. ((curr_thing==123)||(curr_thing==124)))
  529. copy_robot(0,curr_param);//No mem. = too bad
  530. clear_robot(level_param[ARRAY_OFFS]);
  531. curr_param=0;
  532. }
  533. else if((t1==125)||(t1==126)) {//(scroll)
  534. if((level_param[ARRAY_OFFS]==curr_param)&&
  535. ((curr_thing==125)||(curr_thing==126)))
  536. copy_scroll(0,curr_param);//No mem. = too bad
  537. clear_scroll(level_param[ARRAY_OFFS]);
  538. curr_param=0;
  539. }
  540. //Place.
  541. id_place(ARRAY_X,ARRAY_Y,77,curr_color,key);
  542. }
  543. else {
  544. //Overlay mode
  545. overlay[ARRAY_OFFS]=key;
  546. overlay_color[ARRAY_OFFS]=curr_color;
  547. }
  548. update_view=1;
  549. //Increase x position if possible
  550. goto move_right;
  551. }
  552. //Ensure uppercase
  553. if((key>='a')&&(key<='z')) key-=32;
  554. //Fix for block mode
  555. if(((draw_mode&127)==3)||((draw_mode&127)==4)||((draw_mode&127)==5))
  556. if((key==' ')||(key==13)) key=-48;
  557. re_evaul_key:
  558. switch(key) {
  559. case ']'://Screen .PCX dump
  560. dump_screen();
  561. break;
  562. case MOUSE_EVENT://Mouse click
  563. //Possibilities-
  564. //
  565. //1) Mouse is in upper menu area.
  566. // a) Mouse will change current menu/exit overlay mode (left)
  567. // b) Mouse will change current color (right)
  568. //2) Mouse is in lower menu area.
  569. // a) Mouse will choose menu command.
  570. // b) Mouse will change current menu. (Pgup/Pgdn)
  571. //3) Mouse is in level area- move cursor and place.
  572. //4) Mouse is anywhere else- do nothing.
  573. if(mouse_event.cy==20) {//#1
  574. if(mouse_event.cx<42) {//#1a
  575. if(draw_mode&128) goto overlay_off;
  576. //Determine menu to switch to.
  577. t1=1;
  578. for(t2=0;t2<NUM_MENUS;t2++) {
  579. t1+=str_len(menu_names[t2]);
  580. if(mouse_event.cx<t1) break;
  581. }
  582. if(t2>=NUM_MENUS) t2=NUM_MENUS-1;
  583. curr_menu=t2;
  584. update_menu=1;
  585. break;
  586. }
  587. else goto change_color;//#1b
  588. }
  589. else if(mouse_event.cy>21) {//#2
  590. if(mouse_event.cy<24) {//#2a
  591. if((mouse_event.cx<2)||(mouse_event.cx==79)) break;
  592. if(draw_mode&128) t1=NUM_MENUS;
  593. else t1=curr_menu;
  594. t2=mouse_event.cy-22;
  595. t3=mouse_event.cx-2;
  596. t4=0;
  597. do {
  598. t3-=menu_keys[t1][t2][t4];
  599. if(t3<0) break;
  600. t4+=2;
  601. } while(1);
  602. key=menu_keys[t1][t2][t4+1];
  603. goto re_evaul_key;
  604. }
  605. else {//#2b
  606. if(mouse_event.cx<68) goto prev_menu;
  607. else goto next_menu;
  608. }
  609. }
  610. //#3 or #4?
  611. if(mouse_event.cy>18) break;
  612. if(mouse_event.cx>=board_xsiz) break;
  613. if(mouse_event.cy>=board_ysiz) break;
  614. //#3- Move cursor and place.
  615. x_pos=mouse_event.cx;
  616. y_pos=mouse_event.cy;
  617. //Move debug window?
  618. if((debug_x==65)&&(x_pos>59)) {
  619. debug_x=0;
  620. update_view=1;
  621. }
  622. if((debug_x==0)&&(x_pos<20)) {
  623. debug_x=65;
  624. update_view=1;
  625. }
  626. goto place;
  627. case -20://Alt+T
  628. //Test
  629. if(protection_method!=NO_PROTECTION) {
  630. error("Can't test password-protected world",0,24,
  631. current_pg_seg,0x2001);
  632. break;
  633. }
  634. if((curr_thing==122)&&(curr_param==0)) {
  635. clear_sensor(0);
  636. curr_thing=0;
  637. }
  638. else if(((curr_thing==123)||(curr_thing==124))&&(curr_param==0)) {
  639. clear_robot(0);
  640. curr_thing=0;
  641. }
  642. else if(((curr_thing==125)||(curr_thing==126))&&(curr_param==0)) {
  643. clear_scroll(0);
  644. curr_thing=0;
  645. }
  646. //Temporary save
  647. str_cpy(temp,curr_file);
  648. t1=curr_board;
  649. store_current();
  650. save_world("test_$$$.mzx");
  651. select_current(t1);
  652. //Turn cheats on and fade out
  653. cheats_active+=5;
  654. vquick_fadeout();
  655. //Play
  656. clear_game_params();
  657. set_counter("TIME",time_limit);
  658. send_robot_def(0,11);
  659. send_robot_def(0,10);
  660. m_hide();
  661. player_restart_x=player_x;
  662. player_restart_y=player_y;
  663. play_game(1);
  664. cheats_active-=5;
  665. //Clear screen
  666. clear_screen(1824,current_pg_seg);
  667. //Palette
  668. default_palette();
  669. for(t2=0;t2<16;t2++)
  670. set_color_intensity(t2,100);
  671. insta_fadein();
  672. m_show();
  673. //Reload
  674. clear_world();
  675. if(load_world("test_$$$.mzx",2)) {
  676. clear_world();
  677. select_current(0);
  678. update_view=update_menu=1;
  679. curr_file[0]=0;
  680. break;
  681. }
  682. select_current(t1);
  683. unlink("test_$$$.mzx");
  684. insta_fadeout();
  685. fade_in=1;
  686. update_view=update_menu=1;
  687. str_cpy(curr_file,temp);
  688. break;
  689. case -33://AltF
  690. //Edit SFX
  691. sfx_edit();
  692. changed=1;
  693. break;
  694. case -17://AltW
  695. //Re-init screen
  696. vga_16p_mode();
  697. ega_14p_mode();
  698. cursor_off();
  699. blink_off();
  700. ec_update_set();
  701. update_palette(0);
  702. changed=1;
  703. update_menu=1;
  704. break;
  705. case 'F'://F
  706. //Fill
  707. //Just, well, fill! Fill function takes care of all
  708. //robot copying/deleting/etc, filling something over
  709. //itself, (same OR different param) and filling with/over
  710. //the player. (not allowed) Only precaution- copy current
  711. //robot to #0 first.
  712. if(draw_mode&128)
  713. fill_overlay(ARRAY_X,ARRAY_Y,curr_param,curr_color);
  714. else {
  715. if((curr_thing==122)&&(curr_param)) {
  716. copy_sensor(0,curr_param);
  717. sensors[0].used=1;
  718. curr_param=0;
  719. }
  720. else if(((curr_thing==123)||(curr_thing==124))&&(curr_param)) {
  721. copy_robot(0,curr_param);
  722. robots[0].used=1;
  723. curr_param=0;
  724. }
  725. else if(((curr_thing==125)||(curr_thing==126))&&(curr_param)) {
  726. copy_scroll(0,curr_param);
  727. scrolls[0].used=1;
  728. curr_param=0;
  729. }
  730. fill_area(ARRAY_X,ARRAY_Y,curr_thing,curr_color,curr_param);
  731. }
  732. //Was our current object overwritten?
  733. if((curr_thing==122)&&(!sensors[curr_param].used))
  734. curr_thing=0;
  735. else if(((curr_thing==123)||(curr_thing==124))&&
  736. (!robots[curr_param].used))
  737. curr_thing=0;
  738. else if(((curr_thing==125)||(curr_thing==126))&&
  739. (!scrolls[curr_param].used))
  740. curr_thing=0;
  741. changed=1;
  742. update_view=update_menu=1;
  743. break;
  744. case 'V'://V
  745. //View
  746. if(draw_mode&128) break;
  747. scroll_x=scroll_y=0;
  748. do {
  749. //Select OTHER page for seg
  750. current_pg_seg=VIDEO_NUM2SEG(!current_page);
  751. //Draw border
  752. draw_viewport();
  753. //Figure out x/y of top
  754. calculate_xytop(t1,t2);
  755. //Draw screen
  756. draw_game_window(t1,t2,current_pg_seg);
  757. //Page flip
  758. current_page=1-current_page;
  759. page_flip(current_page);
  760. m_vidseg(current_pg_seg);
  761. //Retrace
  762. wait_retrace();
  763. //Movement
  764. if(keywaiting()) {
  765. key=getkey();
  766. switch(key) {
  767. case -72://Up
  768. scroll_y--;
  769. break;
  770. case -80://Down
  771. scroll_y++;
  772. break;
  773. case -75://Left
  774. scroll_x--;
  775. break;
  776. case -77://Right
  777. scroll_x++;
  778. break;
  779. case -71://Home
  780. case -79://End
  781. scroll_x=scroll_y=0;
  782. break;
  783. }
  784. }
  785. } while(key!=27);
  786. scroll_x=scroll_y=0;
  787. update_view=update_menu=key=1;
  788. break;
  789. case -23://AltI
  790. //Import
  791. if(draw_mode&128) break;
  792. //Choose import mode
  793. t1=import_type();
  794. if(t1==-1) break;
  795. //Import as...
  796. switch(t1) {
  797. case 0:
  798. //...board file.
  799. if(choose_file("*.MZB",temp,"Choose board to import")) break;
  800. //Open file.
  801. fp=fopen(temp,"rb");
  802. if(fp==NULL) {
  803. error("Error importing board",1,24,current_pg_seg,0x1501);
  804. break;
  805. }
  806. //Verify header
  807. fread(temp,1,3,fp);
  808. temp[3]=0;
  809. if(str_cmp(temp,"\xFFMB")) {
  810. //Either a ver 1.0? file or corrupted
  811. error("Error importing board",1,24,current_pg_seg,0x1502);
  812. break;
  813. }
  814. //Get file ver.
  815. t1=fgetc(fp);
  816. if(t1!='2') {
  817. //Not a ver 2.00 file
  818. error("Board is from a more recent version of MegaZeux",
  819. 0,24,current_pg_seg,0x1601);
  820. break;
  821. }
  822. //Read board- Store current...
  823. //If current object is a robot/etc of not #0, copy to #0.
  824. if((curr_thing==122)&&(curr_param!=0)) {
  825. copy_sensor(0,curr_param);
  826. curr_param=0;
  827. }
  828. if(((curr_thing==123)||(curr_thing==124))&&(curr_param!=0))
  829. //No room = forget it!
  830. if(!copy_robot(0,curr_param)) curr_param=0;
  831. if(((curr_thing==125)||(curr_thing==126))&&(curr_param!=0))
  832. //No room = forget it!
  833. if(!copy_scroll(0,curr_param)) curr_param=0;
  834. //Clear current
  835. clear_current();
  836. //Get size of board
  837. tlong1=ftell(fp);
  838. fseek(fp,-BOARD_NAME_SIZE,SEEK_END);
  839. tlong2=ftell(fp);
  840. fseek(fp,tlong1,SEEK_SET);
  841. tlong2-=tlong1;
  842. //tlong2=board size
  843. //no space allocated to current
  844. //allocate space and set vars
  845. if(allocate_board_space(tlong2,curr_board))//Exit only
  846. error("Out of memory and/or disk space",2,4,
  847. current_pg_seg,0x0205);
  848. //allocated, set vars
  849. board_sizes[curr_board]=tlong2;
  850. //Read board
  851. disk_board(curr_board,fp,1,0);
  852. //Load into current
  853. select_current(curr_board);
  854. //Load board name from file
  855. fread(&board_list[curr_board*BOARD_NAME_SIZE],1,
  856. BOARD_NAME_SIZE,fp);
  857. //Done.
  858. fclose(fp);
  859. break;
  860. case 1:
  861. //Character set
  862. if(choose_file("*.CHR",temp,"Choose character set")) break;
  863. //Open file.
  864. if(ec_load_set(temp))
  865. error("Error importing char. set",1,24,current_pg_seg,0x1801);
  866. break;
  867. case 2:
  868. case 6:
  869. //Ansi file
  870. if(choose_file("*.ANS",ansi,"Choose ANSi file")) break;
  871. //Get type of import
  872. t2=import_ansi_obj_type();
  873. if(t2==-1) break;
  874. //Check if overlay
  875. if(t2==3) {
  876. if(overlay_mode==0) {
  877. error("Overlay mode is not on (see Board Info)",0,24,
  878. current_pg_seg,0x1103);
  879. break;
  880. }
  881. }
  882. //Import
  883. if(t2==0) t2=5;
  884. else if(t2==1) t2=17;
  885. else if(t2==2) t2=77;
  886. else t2=0;
  887. if(t1==2) import_ansi(ansi,t2,curr_thing,curr_param);
  888. else {
  889. blk_cmd=t2;
  890. draw_mode=(draw_mode&128)+5;
  891. update_view=update_menu=1;
  892. }
  893. break;
  894. case 3:
  895. //Import world
  896. if(choose_file("*.MZX",temp,"Choose world to import")) break;
  897. //Open file
  898. fp=fopen(temp,"rb");
  899. if(fp==NULL) {
  900. error("Error importing world",1,24,current_pg_seg,0x1A01);
  901. break;
  902. }
  903. //Check for password protection and world type
  904. fseek(fp,25,SEEK_SET);
  905. if(fgetc(fp)!=0) {
  906. error("Cannot import password protected world",0,
  907. 24,current_pg_seg,0x1B01);
  908. fclose(fp);
  909. break;
  910. }
  911. if(fgetc(fp)!='M') {
  912. error("Error importing world",1,24,current_pg_seg,0x1A02);
  913. fclose(fp);
  914. break;
  915. }
  916. t1=fgetc(fp);
  917. if(t1=='X') {
  918. error("World is from version 1- Use conversion program",
  919. 0,24,current_pg_seg,0x1C01);
  920. fclose(fp);
  921. break;
  922. }
  923. //Version and pw okay
  924. fseek(fp,4234,SEEK_SET);
  925. t1=fgetc(fp);//Number of boards
  926. if(t1==0) {
  927. //SFX- Skip
  928. fread(&t1,1,2,fp);
  929. fseek(fp,t1,SEEK_CUR);
  930. t9=3+t1;
  931. t1=fgetc(fp);
  932. }
  933. else t9=0;//Size of SFX section
  934. //Count OUR empty boards
  935. t2=0;
  936. for(t3=0;t3<NUM_BOARDS;t3++)
  937. if(board_where[t3]==W_NOWHERE) t2++;
  938. //Compare
  939. if(t1>t2) {
  940. //Too many-
  941. if(t2==0) {
  942. error("No available boards",1,24,current_pg_seg,0x0B02);
  943. fclose(fp);
  944. break;
  945. }
  946. if(error("Too many boards- only partial import will be done",
  947. 0,25,current_pg_seg,0x1D01)==1) {
  948. fclose(fp);
  949. break;//Fail
  950. }
  951. //They chose OK, so import as many as possible.
  952. }
  953. //Import t1 boards- Mark as importable by setting
  954. //type to W_IMPORT, offset to file area, and size
  955. //properly. Also sets title.
  956. t3=0;//Current board to change (out of NUM_BOARDS)
  957. t4=0;//Current board within MZX file (out of t1)
  958. do {
  959. //Find next empty board
  960. do {
  961. t3++;
  962. if(t3>=NUM_BOARDS) break;
  963. } while(board_where[t3]!=W_NOWHERE);
  964. if(t3>=NUM_BOARDS) break;//Done
  965. //Import to board t3- get title
  966. fread(&board_list[BOARD_NAME_SIZE*t3],1,
  967. BOARD_NAME_SIZE,fp);
  968. //Jump to board size/offset, saving curr. position
  969. tlong1=ftell(fp);
  970. //Tlong2=Position of size/offsets
  971. tlong2=4235+t9+(t1*BOARD_NAME_SIZE);
  972. //Increase to position of size/offset for current board
  973. tlong2+=t4*8;
  974. //Jump
  975. fseek(fp,tlong2,SEEK_SET);
  976. //Read size and offset
  977. fread(&board_sizes[t3],4,1,fp);
  978. fread(&board_offsets[t3].offset,4,1,fp);
  979. //Set where
  980. board_where[t3]=W_IMPORT;
  981. //Return to names
  982. fseek(fp,tlong1,SEEK_SET);
  983. //Next board...
  984. } while((++t4)<t1);
  985. //Now actually IMPORT each board- % meter used
  986. save_screen(current_pg_seg);
  987. t2=0;//Keeps track of number of boards imported
  988. //t4=Max number of boards we'll import
  989. meter("Importing world...",current_pg_seg,t2,t4);
  990. for(t1=0;t1<NUM_BOARDS;t1++) {
  991. //Import this board?
  992. if(board_where[t1]!=W_IMPORT) continue;
  993. //Save file offset
  994. tlong1=board_offsets[t1].offset;
  995. //Allocate space...
  996. board_where[t1]=W_NOWHERE;
  997. if(allocate_board_space(board_sizes[t1],t1)) {
  998. fclose(fp);
  999. restore_screen(current_pg_seg);
  1000. error("Out of memory and/or disk space",2,4,
  1001. current_pg_seg,0x0206);
  1002. }
  1003. //Read in board.
  1004. fseek(fp,tlong1,SEEK_SET);
  1005. disk_board(t1,fp,1,0);
  1006. //Next!
  1007. meter_interior(current_pg_seg,++t2,t4);
  1008. }
  1009. //Done!
  1010. fclose(fp);
  1011. restore_screen(current_pg_seg);
  1012. break;
  1013. case 4:
  1014. //Palette file
  1015. if(choose_file("*.PAL",temp,"Choose palette file")) break;
  1016. //Open file.
  1017. fp=fopen(temp,"rb");
  1018. if(fp==NULL) {
  1019. error("Error importing palette",1,24,current_pg_seg,0x2401);
  1020. break;
  1021. }
  1022. for(t1=0;t1<16;t1++) {
  1023. r=fgetc(fp);
  1024. g=fgetc(fp);
  1025. b=fgetc(fp);
  1026. set_rgb(t1,r,g,b);
  1027. }
  1028. update_palette();
  1029. //Done.
  1030. fclose(fp);
  1031. break;
  1032. case 5:
  1033. //SFX file
  1034. if(choose_file("*.SFX",temp,"Choose SFX file")) break;
  1035. //Open file.
  1036. fp=fopen(temp,"rb");
  1037. if(fp==NULL) {
  1038. error("Error importing .SFX file",1,24,current_pg_seg,0x3001);
  1039. break;
  1040. }
  1041. custom_sfx_on=1;
  1042. for(t1=0;t1<NUM_SFX;t1++)
  1043. fread(&custom_sfx[69*t1],1,69,fp);
  1044. //Done.
  1045. fclose(fp);
  1046. break;
  1047. }
  1048. changed=1;
  1049. update_view=update_menu=1;
  1050. break;
  1051. case -45://AltX
  1052. //Export
  1053. if(draw_mode&128) break;
  1054. //Confirm pw
  1055. if(check_pw()) break;
  1056. //Choose export mode
  1057. t1=export_type();
  1058. if(t1==-1) break;
  1059. //Get file name
  1060. temp[0]=0;
  1061. if(save_file_dialog("Export","Save as: ",temp)) break;
  1062. //Export as...
  1063. switch(t1) {
  1064. case 0:
  1065. //...board file.
  1066. add_ext(temp,".MZB");
  1067. //Open file.
  1068. fp=fopen(temp,"wb");
  1069. if(fp==NULL) {
  1070. error("Error exporting board",1,24,current_pg_seg,0x1201);
  1071. break;
  1072. }
  1073. //Save header.
  1074. fwrite("\xFFMB2",1,4,fp);
  1075. //Write board- Store it...
  1076. //If current object is a robot/etc of not #0, copy to #0.
  1077. if((curr_thing==122)&&(curr_param!=0)) {
  1078. copy_sensor(0,curr_param);
  1079. curr_param=0;
  1080. }
  1081. if(((curr_thing==123)||(curr_thing==124))&&(curr_param!=0))
  1082. //No room = forget it!
  1083. if(!copy_robot(0,curr_param)) curr_param=0;
  1084. if(((curr_thing==125)||(curr_thing==126))&&(curr_param!=0))
  1085. //No room = forget it!
  1086. if(!copy_scroll(0,curr_param)) curr_param=0;
  1087. //Store current
  1088. store_current();
  1089. //Save board
  1090. disk_board(curr_board,fp,0,0);
  1091. //Reload current
  1092. select_current(curr_board);
  1093. update_view=update_menu=1;
  1094. //Save board name to file
  1095. fwrite(&board_list[curr_board*BOARD_NAME_SIZE],1,
  1096. BOARD_NAME_SIZE,fp);
  1097. //Done.
  1098. fclose(fp);
  1099. break;
  1100. case 1:
  1101. //Character set
  1102. add_ext(temp,".CHR");
  1103. //Open file.
  1104. if(ec_save_set(temp))
  1105. error("Error exporting char. set",1,24,current_pg_seg,0x1301);
  1106. break;
  1107. case 2:
  1108. //Ansi file
  1109. add_ext(temp,".ANS");
  1110. case 3:
  1111. //Text file
  1112. if(t1==3) add_ext(temp,".TXT");
  1113. //Overlays as they normally would be.
  1114. //Save. (auto clips)
  1115. export_ansi(temp,0,0,board_xsiz,board_ysiz,t1-2);
  1116. //Done.
  1117. break;
  1118. case 4:
  1119. //Palette file
  1120. add_ext(temp,".PAL");
  1121. fp=fopen(temp,"wb");
  1122. if(fp==NULL) {
  1123. error("Error exporting palette",1,24,current_pg_seg,0x2E01);
  1124. break;
  1125. }
  1126. for(t1=0;t1<16;t1++) {
  1127. get_rgb(t1,r,g,b);
  1128. fputc(r,fp);
  1129. fputc(g,fp);
  1130. fputc(b,fp);
  1131. }
  1132. fclose(fp);
  1133. break;
  1134. case 5:
  1135. //SFX file
  1136. add_ext(temp,".SFX");
  1137. fp=fopen(temp,"wb");
  1138. if(fp==NULL) {
  1139. error("Error exporting .SFX file",1,24,current_pg_seg,0x2F01);
  1140. break;
  1141. }
  1142. for(t1=0;t1<NUM_SFX;t1++) {
  1143. if(custom_sfx_on)
  1144. fwrite(&custom_sfx[69*t1],1,69,fp);
  1145. else fwrite(sfx_strs[t1],1,69,fp);
  1146. }
  1147. fclose(fp);
  1148. break;
  1149. }
  1150. break;
  1151. case '*'://*
  1152. //Password
  1153. if(draw_mode&128) break;
  1154. password_dialog();
  1155. changed=1;
  1156. break;
  1157. case -30://AltA
  1158. //Select char set
  1159. if(draw_mode&128) break;
  1160. t1=choose_char_set();
  1161. if(t1==-1) break;
  1162. switch(t1) {
  1163. case 0:
  1164. //Megazeux default
  1165. ec_load_mzx();
  1166. break;
  1167. case 1:
  1168. //Blank
  1169. ec_load_mzx();
  1170. //Characters to leave alone-
  1171. //32 through 126 (text)
  1172. //0 (already blank)
  1173. //16-18, 24-27, 29-31 (arrows)
  1174. //176-223 (lines/blocks)
  1175. //254 (square)
  1176. //249-250 (dots)
  1177. //251 (check mark)
  1178. //7 (circle)
  1179. //
  1180. //Blanken all others.
  1181. //
  1182. //Series to blanken-
  1183. //1-6, 8-15, 19-23, 28, 127-175, 224-248, 252-253
  1184. for(t1=1;t1<=6;t1++)
  1185. for(t2=0;t2<14;t2++)
  1186. ec_change_byte_nou(t1,t2,0);
  1187. for(t1=8;t1<=15;t1++)
  1188. for(t2=0;t2<14;t2++)
  1189. ec_change_byte_nou(t1,t2,0);
  1190. for(t1=19;t1<=23;t1++)
  1191. for(t2=0;t2<14;t2++)
  1192. ec_change_byte_nou(t1,t2,0);
  1193. for(t1=127;t1<=175;t1++)
  1194. for(t2=0;t2<14;t2++)
  1195. ec_change_byte_nou(t1,t2,0);
  1196. for(t1=224;t1<=248;t1++)
  1197. for(t2=0;t2<14;t2++)
  1198. ec_change_byte_nou(t1,t2,0);
  1199. for(t2=0;t2<14;t2++) {
  1200. ec_change_byte_nou(28,t2,0);
  1201. ec_change_byte_nou(252,t2,0);
  1202. ec_change_byte_nou(253,t2,0);
  1203. ec_change_byte_nou(255,t2,0);
  1204. }
  1205. ec_update_set();
  1206. break;
  1207. }
  1208. changed=1;
  1209. break;
  1210. case -48://AltB
  1211. //Block mode
  1212. if((draw_mode&127)==0) {
  1213. //Turn ON.
  1214. draw_mode=3+(draw_mode&128);
  1215. save_x=ARRAY_X;
  1216. save_y=ARRAY_Y;
  1217. update_view=update_menu=1;
  1218. break;
  1219. }
  1220. else if(((draw_mode&127)!=3)&&((draw_mode&127)!=4)) {
  1221. if((draw_mode&127)==5)//Place ANSi
  1222. import_ansi(ansi,blk_cmd,curr_thing,curr_param,ARRAY_X,ARRAY_Y);
  1223. //Turn other mode OFF.
  1224. draw_mode&=128;
  1225. update_view=update_menu=1;
  1226. break;
  1227. }
  1228. else if((draw_mode&127)==4) {
  1229. //Block destination chosen.
  1230. t1=ARRAY_X;
  1231. t2=ARRAY_Y;
  1232. if(((save_x2-save_x)+t1)>=board_xsiz)
  1233. save_x2=save_x+board_xsiz-t1-1;
  1234. if(((save_y2-save_y)+t2)>=board_ysiz)
  1235. save_y2=save_y+board_ysiz-t2-1;
  1236. switch(blk_cmd) {
  1237. case 0://Copy
  1238. //Do ULeft->LRight or LRight->ULeft?
  1239. if((t1==save_x)&&(t2==save_y)) break;//Done
  1240. if((t1<save_x)||((t1==save_x)&&(t2<save_y))) {
  1241. //Copy starting at UL, going by columns.
  1242. for(t3=save_x;t3<=save_x2;t3++) {
  1243. for(t4=save_y;t4<=save_y2;t4++) {
  1244. t5=t3+t4*max_bxsiz;
  1245. t6=((t3-save_x)+t1)+((t4-save_y)+t2)*max_bxsiz;
  1246. //Copy from t5 to t6
  1247. if(draw_mode&128) {
  1248. //Overlay-
  1249. overlay[t6]=overlay[t5];
  1250. overlay_color[t6]=overlay_color[t5];
  1251. continue;
  1252. }
  1253. //Clear anything there...
  1254. t7=level_id[t6];
  1255. if(t7==127) continue;//No copy over player
  1256. if(t7==122) {//(sensor)
  1257. //Clear, copying to 0 first if param==curr
  1258. if((level_param[t6]==curr_param)&&
  1259. (curr_thing==122)) {
  1260. copy_sensor(0,curr_param);
  1261. curr_param=0;
  1262. }
  1263. clear_sensor(level_param[t6]);
  1264. }
  1265. else if((t7==123)||(t7==124)) {//(robot)
  1266. //Clear, copying to 0 first if param==curr
  1267. if((level_param[t6]==curr_param)&&
  1268. ((curr_thing==123)||(curr_thing==124))) {
  1269. copy_robot(0,curr_param);
  1270. curr_param=0;
  1271. }
  1272. clear_robot(level_param[t6]);
  1273. }
  1274. else if((t7==125)||(t7==126)) {//(scroll)
  1275. //Clear, copying to 0 first if param==curr
  1276. if((level_param[t6]==curr_param)&&
  1277. ((curr_thing==125)||(curr_thing==126))) {
  1278. copy_scroll(0,curr_param);
  1279. curr_param=0;
  1280. }
  1281. clear_scroll(level_param[t6]);
  1282. }
  1283. //Copy any robot/scroll at t5
  1284. t7=level_id[t5];
  1285. t8=level_param[t5];
  1286. if(t7==122) {//(sensor)
  1287. //...make a copy...
  1288. if(!(t9=find_sensor())) {
  1289. error("No available sensors",1,24,current_pg_seg,0x0801);
  1290. break;
  1291. }
  1292. copy_sensor(t9,t8);
  1293. t8=t9;
  1294. }
  1295. if((t7==123)||(t7==124)) {//(robot)
  1296. //...make a copy...
  1297. if(!(t9=find_robot())) {
  1298. error("No available robots",1,24,current_pg_seg,0x0901);
  1299. break;
  1300. }
  1301. if(copy_robot(t9,t8)) {
  1302. robots[t9].used=0;
  1303. error("Out of robot memory",1,21,current_pg_seg,0x0502);
  1304. break;
  1305. }
  1306. //...and deallocate original if it was number 0.
  1307. t8=t9;
  1308. }
  1309. if((t7==125)||(t7==126)) {//(scroll)
  1310. //...make a copy...
  1311. if(!(t9=find_scroll())) {
  1312. error("No available scrolls",1,24,current_pg_seg,0x0A01);
  1313. break;
  1314. }
  1315. if(copy_scroll(t9,t8)) {
  1316. robots[t9].used=0;
  1317. error("Out of robot memory",1,21,current_pg_seg,0x0503);
  1318. break;
  1319. }
  1320. t8=t9;
  1321. }
  1322. //Player?
  1323. if(t7==127) {
  1324. level_id[t6]=level_param[t6]=
  1325. level_under_id[t6]=level_under_param[t6]=0;
  1326. level_color[t6]=level_under_color[t6]=7;
  1327. }
  1328. else {
  1329. //Place
  1330. level_id[t6]=t7;
  1331. level_param[t6]=t8;
  1332. level_color[t6]=level_color[t5];
  1333. level_under_id[t6]=level_under_id[t5];
  1334. level_under_color[t6]=level_under_color[t5];
  1335. level_under_param[t6]=level_under_param[t5];
  1336. }
  1337. //Loop. (whew!)
  1338. }
  1339. }
  1340. //Done (UL -> LR)
  1341. }
  1342. else {
  1343. //Copy starting at LR, going left by columns.
  1344. for(t3=save_x2;t3>=save_x;t3--) {
  1345. for(t4=save_y2;t4>=save_y;t4--) {
  1346. t5=t3+t4*max_bxsiz;
  1347. t6=((t3-save_x)+t1)+((t4-save_y)+t2)*max_bxsiz;
  1348. //Copy from t5 to t6
  1349. if(draw_mode&128) {
  1350. //Overlay-
  1351. overlay[t6]=overlay[t5];
  1352. overlay_color[t6]=overlay_color[t5];
  1353. continue;
  1354. }
  1355. //Clear anything there...
  1356. t7=level_id[t6];
  1357. if(t7==127) continue;//No copy over player
  1358. if(t7==122) {//(sensor)
  1359. //Clear, copying to 0 first if param==curr
  1360. if((level_param[t6]==curr_param)&&
  1361. (curr_thing==122)) {
  1362. copy_sensor(0,curr_param);
  1363. curr_param=0;
  1364. }
  1365. clear_sensor(level_param[t6]);
  1366. }
  1367. else if((t7==123)||(t7==124)) {//(robot)
  1368. //Clear, copying to 0 first if param==curr
  1369. if((level_param[t6]==curr_param)&&
  1370. ((curr_thing==123)||(curr_thing==124))) {
  1371. copy_robot(0,curr_param);
  1372. curr_param=0;
  1373. }
  1374. clear_robot(level_param[t6]);
  1375. }
  1376. else if((t7==125)||(t7==126)) {//(scroll)
  1377. //Clear, copying to 0 first if param==curr
  1378. if((level_param[t6]==curr_param)&&
  1379. ((curr_thing==125)||(curr_thing==126))) {
  1380. copy_scroll(0,curr_param);
  1381. curr_param=0;
  1382. }
  1383. clear_scroll(level_param[t6]);
  1384. }
  1385. //Copy any robot/scroll at t5
  1386. t7=level_id[t5];
  1387. t8=level_param[t5];
  1388. if(t7==122) {//(sensor)
  1389. //...make a copy...
  1390. if(!(t9=find_sensor())) {
  1391. error("No available sensors",1,24,current_pg_seg,0x0801);
  1392. break;
  1393. }
  1394. copy_sensor(t9,t8);
  1395. t8=t9;
  1396. }
  1397. if((t7==123)||(t7==124)) {//(robot)
  1398. //...make a copy...
  1399. if(!(t9=find_robot())) {
  1400. error("No available robots",1,24,current_pg_seg,0x0901);
  1401. break;
  1402. }
  1403. if(copy_robot(t9,t8)) {
  1404. robots[t9].used=0;
  1405. error("Out of robot memory",1,21,current_pg_seg,0x0502);
  1406. break;
  1407. }
  1408. //...and deallocate original if it was number 0.
  1409. t8=t9;
  1410. }
  1411. if((t7==125)||(t7==126)) {//(scroll)
  1412. //...make a copy...
  1413. if(!(t9=find_scroll())) {
  1414. error("No available scrolls",1,24,current_pg_seg,0x0A01);
  1415. break;
  1416. }
  1417. if(copy_scroll(t9,t8)) {
  1418. robots[t9].used=0;
  1419. error("Out of robot memory",1,21,current_pg_seg,0x0503);
  1420. break;
  1421. }
  1422. t8=t9;
  1423. }
  1424. //Player?
  1425. if(t7==127) {
  1426. level_id[t6]=level_param[t6]=
  1427. level_under_id[t6]=level_under_param[t6]=0;
  1428. level_color[t6]=level_under_color[t6]=7;
  1429. }
  1430. else {
  1431. //Place
  1432. level_id[t6]=t7;
  1433. level_param[t6]=t8;
  1434. level_color[t6]=level_color[t5];
  1435. level_under_id[t6]=level_under_id[t5];
  1436. level_under_color[t6]=level_under_color[t5];
  1437. level_under_param[t6]=level_under_param[t5];
  1438. }
  1439. //Loop. (whew!)
  1440. }
  1441. }
  1442. //Done (UL -> LR)
  1443. }
  1444. break;
  1445. case 6://Copy (to/from overlay)
  1446. //If from overlay to main, ask if we want it to become
  1447. //CustomFloor, CustomBlock, or Text.
  1448. if(draw_mode<128) {
  1449. t9=rtoo_obj_type();
  1450. if(t9==-1) break;
  1451. if(t9==0) t9=5;
  1452. else if(t9==1) t9=17;
  1453. else t9=77;
  1454. }
  1455. //Copy starting at UL, going by columns.
  1456. for(t3=save_x;t3<=save_x2;t3++) {
  1457. for(t4=save_y;t4<=save_y2;t4++) {
  1458. t5=t3+t4*max_bxsiz;
  1459. t6=((t3-save_x)+t1)+((t4-save_y)+t2)*max_bxsiz;
  1460. //Copy from t5 to t6
  1461. if(draw_mode&128) {
  1462. //TO Overlay- Use magic id draw function
  1463. overlay_mode|=128;//DON'T do overlay
  1464. id_put(0,0,t3,t4,0,0,current_pg_seg);
  1465. overlay_mode&=~128;
  1466. //Use color/char at 0/0
  1467. overlay[t6]=*(char far *)MK_FP(current_pg_seg,0);
  1468. overlay_color[t6]=*(char far *)MK_FP(current_pg_seg,1);
  1469. continue;
  1470. }
  1471. //FROM overlay...
  1472. //Clear anything there...
  1473. t7=level_id[t6];
  1474. if(t7==127) continue;//No copy over player
  1475. if(t7==122) {//(sensor)
  1476. //Clear, copying to 0 first if param==curr
  1477. if((level_param[t6]==curr_param)&&
  1478. (curr_thing==122)) {
  1479. copy_sensor(0,curr_param);
  1480. curr_param=0;
  1481. }
  1482. clear_sensor(level_param[t6]);
  1483. }
  1484. else if((t7==123)||(t7==124)) {//(robot)
  1485. //Clear, copying to 0 first if param==curr
  1486. if((level_param[t6]==curr_param)&&
  1487. ((curr_thing==123)||(curr_thing==124))) {
  1488. copy_robot(0,curr_param);
  1489. curr_param=0;
  1490. }
  1491. clear_robot(level_param[t6]);
  1492. }
  1493. else if((t7==125)||(t7==126)) {//(scroll)
  1494. //Clear, copying to 0 first if param==curr
  1495. if((level_param[t6]==curr_param)&&
  1496. ((curr_thing==125)||(curr_thing==126))) {
  1497. copy_scroll(0,curr_param);
  1498. curr_param=0;
  1499. }
  1500. clear_scroll(level_param[t6]);
  1501. }
  1502. //Copy as ID type t9 UNLESS it's a space
  1503. if(overlay[t5]==32) {
  1504. level_id[t6]=level_param[t6]=0;
  1505. level_color[t6]=7;
  1506. }
  1507. else {
  1508. level_id[t6]=t9;
  1509. level_param[t6]=overlay[t5];
  1510. level_color[t6]=overlay_color[t5];
  1511. }
  1512. level_under_id[t6]=level_under_param[t6]=0;
  1513. level_under_color[t6]=7;
  1514. //Loop.
  1515. }
  1516. }
  1517. //Done
  1518. break;
  1519. case 1://Move
  1520. //Do ULeft->LRight or LRight->ULeft?
  1521. if((t1==save_x)&&(t2==save_y)) break;//Done
  1522. if((t1<save_x)||((t1==save_x)&&(t2<save_y))) {
  1523. //Move starting at UL, going by columns.
  1524. for(t3=save_x;t3<=save_x2;t3++) {
  1525. for(t4=save_y;t4<=save_y2;t4++) {
  1526. t5=t3+t4*max_bxsiz;
  1527. t6=((t3-save_x)+t1)+((t4-save_y)+t2)*max_bxsiz;
  1528. //Move from t5 to t6
  1529. if(draw_mode&128) {
  1530. //Overlay-
  1531. overlay[t6]=overlay[t5];
  1532. overlay_color[t6]=overlay_color[t5];
  1533. overlay[t5]=32;
  1534. overlay_color[t5]=7;
  1535. continue;
  1536. }
  1537. //Clear anything there...
  1538. t7=level_id[t6];
  1539. if(t7==127) continue;//No copy over player
  1540. if(t7==122) {//(sensor)
  1541. //Clear, copying to 0 first if param==curr
  1542. if((level_param[t6]==curr_param)&&
  1543. (curr_thing==122)) {
  1544. copy_sensor(0,curr_param);
  1545. curr_param=0;
  1546. }
  1547. clear_sensor(level_param[t6]);
  1548. }
  1549. else if((t7==123)||(t7==124)) {//(robot)
  1550. //Clear, copying to 0 first if param==curr
  1551. if((level_param[t6]==curr_param)&&
  1552. ((curr_thing==123)||(curr_thing==124))) {
  1553. copy_robot(0,curr_param);
  1554. curr_param=0;
  1555. }
  1556. clear_robot(level_param[t6]);
  1557. }
  1558. else if((t7==125)||(t7==126)) {//(scroll)
  1559. //Clear, copying to 0 first if param==curr
  1560. if((level_param[t6]==curr_param)&&
  1561. ((curr_thing==125)||(curr_thing==126))) {
  1562. copy_scroll(0,curr_param);
  1563. curr_param=0;
  1564. }
  1565. clear_scroll(level_param[t6]);
  1566. }
  1567. //move
  1568. level_id[t6]=level_id[t5];
  1569. level_param[t6]=level_param[t5];
  1570. level_color[t6]=level_color[t5];
  1571. level_under_id[t6]=level_under_id[t5];
  1572. level_under_color[t6]=level_under_color[t5];
  1573. level_under_param[t6]=level_under_param[t5];
  1574. id_clear(t3,t4);
  1575. //Loop.
  1576. }
  1577. }
  1578. //Done (UL -> LR)
  1579. }
  1580. else {
  1581. //Move starting at LR, going left by columns.
  1582. for(t3=save_x2;t3>=save_x;t3--) {
  1583. for(t4=save_y2;t4>=save_y;t4--) {
  1584. t5=t3+t4*max_bxsiz;
  1585. t6=((t3-save_x)+t1)+((t4-save_y)+t2)*max_bxsiz;
  1586. //Move from t5 to t6
  1587. if(draw_mode&128) {
  1588. //Overlay-
  1589. overlay[t6]=overlay[t5];
  1590. overlay_color[t6]=overlay_color[t5];
  1591. overlay[t5]=32;
  1592. overlay_color[t5]=7;
  1593. continue;
  1594. }
  1595. //Clear anything there...
  1596. t7=level_id[t6];
  1597. if(t7==127) continue;//No copy over player
  1598. if(t7==122) {//(sensor)
  1599. //Clear, copying to 0 first if param==curr
  1600. if((level_param[t6]==curr_param)&&
  1601. (curr_thing==122)) {
  1602. copy_sensor(0,curr_param);
  1603. curr_param=0;
  1604. }
  1605. clear_sensor(level_param[t6]);
  1606. }
  1607. else if((t7==123)||(t7==124)) {//(robot)
  1608. //Clear, copying to 0 first if param==curr
  1609. if((level_param[t6]==curr_param)&&
  1610. ((curr_thing==123)||(curr_thing==124))) {
  1611. copy_robot(0,curr_param);
  1612. curr_param=0;
  1613. }
  1614. clear_robot(level_param[t6]);
  1615. }
  1616. else if((t7==125)||(t7==126)) {//(scroll)
  1617. //Clear, copying to 0 first if param==curr
  1618. if((level_param[t6]==curr_param)&&
  1619. ((curr_thing==125)||(curr_thing==126))) {
  1620. copy_scroll(0,curr_param);
  1621. curr_param=0;
  1622. }
  1623. clear_scroll(level_param[t6]);
  1624. }
  1625. //Move
  1626. level_id[t6]=level_id[t5];
  1627. level_param[t6]=level_param[t5];
  1628. level_color[t6]=level_color[t5];
  1629. level_under_id[t6]=level_under_id[t5];
  1630. level_under_color[t6]=level_under_color[t5];
  1631. level_under_param[t6]=level_under_param[t5];
  1632. id_clear(t3,t4);
  1633. //Loop.
  1634. }
  1635. }
  1636. //Done (UL -> LR)
  1637. }
  1638. break;
  1639. }
  1640. draw_mode&=128;
  1641. changed=1;
  1642. update_view=update_menu=1;
  1643. break;
  1644. }
  1645. //Finish block
  1646. draw_mode&=128;
  1647. save_x2=ARRAY_X;
  1648. save_y2=ARRAY_Y;
  1649. if(save_x>save_x2) {
  1650. t1=save_x;
  1651. save_x=save_x2;
  1652. save_x2=t1;
  1653. }
  1654. if(save_y>save_y2) {
  1655. t1=save_y;
  1656. save_y=save_y2;
  1657. save_y2=t1;
  1658. }
  1659. //Redraw
  1660. update_view=update_menu=1;
  1661. //Ask function
  1662. t1=block_cmd();
  1663. if(t1==-1) break;
  1664. //Do function t1
  1665. switch(t1) {
  1666. case 0:
  1667. //Copy
  1668. blk_cmd=t1;
  1669. draw_mode+=4;
  1670. break;
  1671. case 1:
  1672. //Move
  1673. blk_cmd=t1;
  1674. draw_mode+=4;
  1675. break;
  1676. case 2:
  1677. //Clear
  1678. for(t1=save_x;t1<=save_x2;t1++) {
  1679. for(t2=save_y;t2<=save_y2;t2++) {
  1680. if(draw_mode<128) {
  1681. t3=level_id[t1+t2*max_bxsiz];
  1682. if(t3==127) continue;//Player
  1683. if(t3==122) {//(sensor)
  1684. //Clear, copying to 0 first if param==curr
  1685. if((level_param[t1+t2*max_bxsiz]==curr_param)&&
  1686. (curr_thing==122)) {
  1687. copy_sensor(0,curr_param);
  1688. curr_param=0;
  1689. }
  1690. clear_sensor(level_param[t1+t2*max_bxsiz]);
  1691. }
  1692. else if((t3==123)||(t3==124)) {//(robot)
  1693. //Clear, copying to 0 first if param==curr
  1694. if((level_param[t1+t2*max_bxsiz]==curr_param)&&
  1695. ((curr_thing==123)||(curr_thing==124))) {
  1696. copy_robot(0,curr_param);
  1697. curr_param=0;
  1698. }
  1699. clear_robot(level_param[t1+t2*max_bxsiz]);
  1700. }
  1701. else if((t3==125)||(t3==126)) {//(scroll)
  1702. //Clear, copying to 0 first if param==curr
  1703. if((level_param[t1+t2*max_bxsiz]==curr_param)&&
  1704. ((curr_thing==125)||(curr_thing==126))) {
  1705. copy_scroll(0,curr_param);
  1706. curr_param=0;
  1707. }
  1708. clear_scroll(level_param[t1+t2*max_bxsiz]);
  1709. }
  1710. //Clear
  1711. id_clear(t1,t2);
  1712. }
  1713. else {
  1714. overlay[t1+t2*max_bxsiz]=32;
  1715. overlay_color[t1+t2*max_bxsiz]=7;
  1716. }
  1717. }
  1718. }
  1719. changed=1;
  1720. break;
  1721. case 3:
  1722. //Flip
  1723. if(draw_mode<128) {
  1724. t4=((save_y2-save_y)>>1)+save_y;
  1725. for(t1=save_x;t1<=save_x2;t1++) {
  1726. for(t2=save_y,t3=save_y2;t2<=t4;t2++,t3--) {
  1727. t5=level_id[t1+t2*max_bxsiz];
  1728. level_id[t1+t2*max_bxsiz]=level_id[t1+t3*max_bxsiz];
  1729. level_id[t1+t3*max_bxsiz]=t5;
  1730. t5=level_color[t1+t2*max_bxsiz];
  1731. level_color[t1+t2*max_bxsiz]=level_color[t1+t3*max_bxsiz];
  1732. level_color[t1+t3*max_bxsiz]=t5;
  1733. t5=level_param[t1+t2*max_bxsiz];
  1734. level_param[t1+t2*max_bxsiz]=level_param[t1+t3*max_bxsiz];
  1735. level_param[t1+t3*max_bxsiz]=t5;
  1736. t5=level_under_id[t1+t2*max_bxsiz];
  1737. level_under_id[t1+t2*max_bxsiz]=level_under_id[t1+t3*max_bxsiz];
  1738. level_under_id[t1+t3*max_bxsiz]=t5;
  1739. t5=level_under_color[t1+t2*max_bxsiz];
  1740. level_under_color[t1+t2*max_bxsiz]=level_under_color[t1+t3*max_bxsiz];
  1741. level_under_color[t1+t3*max_bxsiz]=t5;
  1742. t5=level_under_param[t1+t2*max_bxsiz];
  1743. level_under_param[t1+t2*max_bxsiz]=level_under_param[t1+t3*max_bxsiz];
  1744. level_under_param[t1+t3*max_bxsiz]=t5;
  1745. }
  1746. }
  1747. }
  1748. else {
  1749. t4=((save_y2-save_y)>>1)+save_y;
  1750. for(t1=save_x;t1<=save_x2;t1++) {
  1751. for(t2=save_y,t3=save_y2;t2<=t4;t2++,t3--) {
  1752. t5=overlay[t1+t2*max_bxsiz];
  1753. overlay[t1+t2*max_bxsiz]=overlay[t1+t3*max_bxsiz];
  1754. overlay[t1+t3*max_bxsiz]=t5;
  1755. t5=overlay_color[t1+t2*max_bxsiz];
  1756. overlay_color[t1+t2*max_bxsiz]=overlay_color[t1+t3*max_bxsiz];
  1757. overlay_color[t1+t3*max_bxsiz]=t5;
  1758. }
  1759. }
  1760. }
  1761. changed=1;
  1762. break;
  1763. case 4:
  1764. //Mirror
  1765. if(draw_mode<128) {
  1766. t4=((save_x2-save_x)>>1)+save_x;
  1767. for(t1=save_x,t3=save_x2;t1<=t4;t1++,t3--) {
  1768. for(t2=save_y;t2<=save_y2;t2++) {
  1769. t5=level_id[t1+t2*max_bxsiz];
  1770. level_id[t1+t2*max_bxsiz]=level_id[t3+t2*max_bxsiz];
  1771. level_id[t3+t2*max_bxsiz]=t5;
  1772. t5=level_color[t1+t2*max_bxsiz];
  1773. level_color[t1+t2*max_bxsiz]=level_color[t3+t2*max_bxsiz];
  1774. level_color[t3+t2*max_bxsiz]=t5;
  1775. t5=level_param[t1+t2*max_bxsiz];
  1776. level_param[t1+t2*max_bxsiz]=level_param[t3+t2*max_bxsiz];
  1777. level_param[t3+t2*max_bxsiz]=t5;
  1778. t5=level_under_id[t1+t2*max_bxsiz];
  1779. level_under_id[t1+t2*max_bxsiz]=level_under_id[t3+t2*max_bxsiz];
  1780. level_under_id[t3+t2*max_bxsiz]=t5;
  1781. t5=level_under_color[t1+t2*max_bxsiz];
  1782. level_under_color[t1+t2*max_bxsiz]=level_under_color[t3+t2*max_bxsiz];
  1783. level_under_color[t3+t2*max_bxsiz]=t5;
  1784. t5=level_under_param[t1+t2*max_bxsiz];
  1785. level_under_param[t1+t2*max_bxsiz]=level_under_param[t3+t2*max_bxsiz];
  1786. level_under_param[t3+t2*max_bxsiz]=t5;
  1787. }
  1788. }
  1789. }
  1790. else {
  1791. t4=((save_x2-save_x)>>1)+save_x;
  1792. for(t1=save_x,t3=save_x2;t1<=t4;t1++,t3--) {
  1793. for(t2=save_y;t2<=save_y2;t2++) {
  1794. t5=overlay[t1+t2*max_bxsiz];
  1795. overlay[t1+t2*max_bxsiz]=overlay[t3+t2*max_bxsiz];
  1796. overlay[t3+t2*max_bxsiz]=t5;
  1797. t5=overlay_color[t1+t2*max_bxsiz];
  1798. overlay_color[t1+t2*max_bxsiz]=overlay_color[t3+t2*max_bxsiz];
  1799. overlay_color[t3+t2*max_bxsiz]=t5;
  1800. }
  1801. }
  1802. }
  1803. changed=1;
  1804. break;
  1805. case 5:
  1806. //Paint
  1807. if(draw_mode<128) {
  1808. for(t1=save_x;t1<=save_x2;t1++)
  1809. for(t2=save_y;t2<=save_y2;t2++)
  1810. level_color[t1+t2*max_bxsiz]=curr_color;
  1811. }
  1812. else {
  1813. for(t1=save_x;t1<=save_x2;t1++)
  1814. for(t2=save_y;t2<=save_y2;t2++)
  1815. overlay_color[t1+t2*max_bxsiz]=curr_color;
  1816. }
  1817. changed=1;
  1818. break;
  1819. case 6:
  1820. //Main <-> overlay
  1821. if(overlay_mode==0) {
  1822. error("Overlay mode is not on (see Board Info)",0,24,
  1823. current_pg_seg,0x1102);
  1824. break;
  1825. }
  1826. blk_cmd=t1;
  1827. if(draw_mode<128) {
  1828. //Clear current object...
  1829. if((curr_thing==122)&&(curr_param==0))
  1830. clear_sensor(0);
  1831. else if(((curr_thing==123)||(curr_thing==124))&&(curr_param==0))
  1832. clear_robot(0);
  1833. else if(((curr_thing==125)||(curr_thing==126))&&(curr_param==0))
  1834. clear_scroll(0);
  1835. curr_thing=0;
  1836. curr_color=7;
  1837. curr_param=32;
  1838. //Draw mode fix
  1839. draw_mode=132;
  1840. //Update
  1841. update_menu=update_view=1;
  1842. //Done
  1843. break;
  1844. }
  1845. //Turn off-
  1846. curr_thing=0;
  1847. curr_color=7;
  1848. curr_param=0;
  1849. //Draw mode fix
  1850. draw_mode=4;
  1851. //Update
  1852. update_menu=update_view=1;
  1853. break;
  1854. case 7:
  1855. //Pw check
  1856. if(protection_method==NO_SAVING)
  1857. if(check_pw()) break;
  1858. //Save as ANSi
  1859. temp[0]=0;
  1860. if(save_file_dialog("Block ANSi Save","Save block as: ",temp))
  1861. break;
  1862. add_ext(temp,".ANS");
  1863. t1=overlay_mode;
  1864. if(draw_mode&128) overlay_mode=1|(64*(show_level==0));
  1865. else overlay_mode=128;
  1866. export_ansi(temp,save_x,save_y,save_x2,save_y2,0);
  1867. overlay_mode=t1;
  1868. break;
  1869. }
  1870. break;
  1871. case -24://AltO
  1872. //Overlay mode
  1873. //Turn on-
  1874. if(draw_mode<128) {
  1875. //Is overlay mode ON !?
  1876. if(overlay_mode==0) {
  1877. error("Overlay mode is not on (see Board Info)",0,24,
  1878. current_pg_seg,0x1101);
  1879. break;
  1880. }
  1881. //Clear current object...
  1882. if((curr_thing==122)&&(curr_param==0))
  1883. clear_sensor(0);
  1884. else if(((curr_thing==123)||(curr_thing==124))&&(curr_param==0))
  1885. clear_robot(0);
  1886. else if(((curr_thing==125)||(curr_thing==126))&&(curr_param==0))
  1887. clear_scroll(0);
  1888. curr_thing=0;
  1889. curr_color=7;
  1890. curr_param=32;
  1891. //Draw mode fix
  1892. draw_mode=128;
  1893. //Update
  1894. update_menu=update_view=1;
  1895. //Done
  1896. context=81;
  1897. break;
  1898. }
  1899. overlay_off:
  1900. context=80;
  1901. //Turn off-
  1902. curr_thing=0;
  1903. curr_color=7;
  1904. curr_param=0;
  1905. //Draw mode fix
  1906. draw_mode=0;
  1907. //Update
  1908. update_menu=update_view=1;
  1909. break;
  1910. case -46://AltC
  1911. if(draw_mode&128) break;
  1912. //Edit char set
  1913. char_editor();
  1914. changed=1;
  1915. break;
  1916. case -18://AltE
  1917. if(draw_mode&128) break;
  1918. //Edit palette
  1919. palette_editor();
  1920. changed=1;
  1921. break;
  1922. case 'G'://G
  1923. if(draw_mode&128) break;
  1924. //Global info
  1925. global_info();
  1926. changed=1;
  1927. update_menu=update_view=1;
  1928. break;
  1929. case -84://ShF1
  1930. if(draw_mode&128) break;
  1931. //Show invisible walls
  1932. //Loop, fiddling with global chars and showing.
  1933. t1=id_chars[71];
  1934. overlay_mode|=128;
  1935. do {
  1936. id_chars[71]=178;
  1937. draw_edit_window(x_top_pos,y_top_pos,current_pg_seg);
  1938. id_chars[71]=176;
  1939. draw_edit_window(x_top_pos,y_top_pos,current_pg_seg);
  1940. } while(!keywaiting());
  1941. overlay_mode&=~128;
  1942. getkey();
  1943. id_chars[71]=t1;
  1944. update_view=1;
  1945. break;
  1946. case -85://ShF2
  1947. if(draw_mode&128) break;
  1948. //Show robots
  1949. //Loop, fiddling with global chars and showing.
  1950. overlay_mode|=128;
  1951. do {
  1952. id_chars[123]='!';
  1953. id_chars[124]='!';
  1954. draw_edit_window(x_top_pos,y_top_pos,current_pg_seg);
  1955. id_chars[123]=0;
  1956. id_chars[124]=0;
  1957. draw_edit_window(x_top_pos,y_top_pos,current_pg_seg);
  1958. } while(!keywaiting());
  1959. overlay_mode&=~128;
  1960. getkey();
  1961. update_menu=1;//Redraw debug menu if needed
  1962. break;
  1963. case -86://ShF3
  1964. if(draw_mode&128) break;
  1965. //Show fakes
  1966. //Loop, fiddling with global chars and showing.
  1967. t1=id_chars[13];
  1968. t2=id_chars[14];
  1969. t3=id_chars[15];
  1970. t4=id_chars[16];
  1971. overlay_mode|=128;
  1972. do {
  1973. for(t5=13;t5<20;t5++) id_chars[t5]='#';
  1974. draw_edit_window(x_top_pos,y_top_pos,current_pg_seg);
  1975. for(t5=13;t5<20;t5++) id_chars[t5]=177;
  1976. draw_edit_window(x_top_pos,y_top_pos,current_pg_seg);
  1977. } while(!keywaiting());
  1978. overlay_mode&=~128;
  1979. getkey();
  1980. id_chars[13]=t1;
  1981. id_chars[14]=t2;
  1982. id_chars[15]=t3;
  1983. id_chars[16]=t4;
  1984. id_chars[17]=255;
  1985. id_chars[18]=0;
  1986. id_chars[19]=0;
  1987. update_view=1;
  1988. break;
  1989. case -87://ShF4
  1990. if(draw_mode&128) break;
  1991. //Show spaces
  1992. //Loop, fiddling with global chars and showing.
  1993. t1=id_chars[0];
  1994. overlay_mode|=128;
  1995. do {
  1996. id_chars[0]='O';
  1997. draw_edit_window(x_top_pos,y_top_pos,current_pg_seg);
  1998. id_chars[0]='*';
  1999. draw_edit_window(x_top_pos,y_top_pos,current_pg_seg);
  2000. } while(!keywaiting());
  2001. overlay_mode&=~128;
  2002. getkey();
  2003. id_chars[0]=t1;
  2004. update_view=1;
  2005. break;/*
  2006. case -90://ShF7
  2007. set_counter("SMZX_MODE",smzx_mode + 1, 0);
  2008. update_view=update_menu=1;
  2009. break; */
  2010. case 'I'://I
  2011. if(draw_mode&128) break;
  2012. //Board info
  2013. board_info();
  2014. changed=1;
  2015. break;
  2016. case -25://AltP
  2017. if(draw_mode&128) break;
  2018. t1=board_xsiz;
  2019. t2=board_ysiz;
  2020. t3=max_bxsiz;
  2021. t4=max_bysiz;
  2022. //Size/pos
  2023. size_pos();
  2024. //Fix x/y
  2025. if(ARRAY_X>=board_xsiz) x_pos=x_top_pos=0;
  2026. if(ARRAY_Y>=board_ysiz) y_pos=y_top_pos=0;
  2027. if((x_top_pos+80)>board_xsiz) x_top_pos=0;
  2028. if((y_top_pos+19)>board_ysiz) x_top_pos=0;
  2029. //Board size change?
  2030. if((t1!=board_xsiz)||(t2!=board_ysiz)||(t3!=max_bxsiz)||
  2031. (t4!=max_bysiz)) {
  2032. //Yep. save board to file, using old sizes.
  2033. fp=fopen("~EDITRSZ.TMP","wb+");
  2034. if(fp==NULL) {
  2035. error("Error accessing temp file, ~EDITRSZ.TMP",1,24,
  2036. current_pg_seg,0x3601);
  2037. break;
  2038. }
  2039. for(t5=0;t5<t1;t5++) {
  2040. for(t6=0;t6<t2;t6++) {
  2041. fputc(level_id[t5+t6*t3],fp);
  2042. fputc(level_color[t5+t6*t3],fp);
  2043. fputc(level_param[t5+t6*t3],fp);
  2044. fputc(level_under_id[t5+t6*t3],fp);
  2045. fputc(level_under_color[t5+t6*t3],fp);
  2046. fputc(level_under_param[t5+t6*t3],fp);
  2047. fputc(overlay[t5+t6*t3],fp);
  2048. fputc(overlay_color[t5+t6*t3],fp);
  2049. }
  2050. }
  2051. fseek(fp,0,SEEK_SET);
  2052. //Now clear board...
  2053. for(t5=0;t5<10000;t5++) {
  2054. level_id[t5]=level_under_id[t5]=0;
  2055. level_param[t5]=level_under_param[t5]=0;
  2056. level_color[t5]=level_under_color[t5]=overlay_color[t5]=7;
  2057. overlay[t5]=32;
  2058. }
  2059. t0=0;//We didn't clear the player yet
  2060. //And reload
  2061. for(t5=0;t5<t1;t5++) {
  2062. for(t6=0;t6<t2;t6++) {
  2063. if((t5>=board_xsiz)||(t6>=board_ysiz)) {
  2064. //Not being placed. If a robot/scroll, delete
  2065. t7=fgetc(fp);
  2066. t8=fgetc(fp);//color
  2067. t9=fgetc(fp);//param
  2068. if(t7==127) t0=1;//player
  2069. else if(t7==122) {//(sensor)
  2070. //Clear, copying to 0 first if param==curr
  2071. if((t9==curr_param)&&
  2072. (curr_thing==122)) {
  2073. copy_sensor(0,curr_param);
  2074. curr_param=0;
  2075. }
  2076. clear_sensor(t9);
  2077. }
  2078. else if((t7==123)||(t7==124)) {//(robot)
  2079. //Clear, copying to 0 first if param==curr
  2080. if((t9==curr_param)&&
  2081. ((curr_thing==123)||(curr_thing==124))) {
  2082. copy_robot(0,curr_param);
  2083. curr_param=0;
  2084. }
  2085. clear_robot(t9);
  2086. }
  2087. else if((t7==125)||(t7==126)) {//(scroll)
  2088. //Clear, copying to 0 first if param==curr
  2089. if((t9==curr_param)&&
  2090. ((curr_thing==125)||(curr_thing==126))) {
  2091. copy_scroll(0,curr_param);
  2092. curr_param=0;
  2093. }
  2094. clear_scroll(t9);
  2095. }
  2096. //Under...
  2097. t7=fgetc(fp);
  2098. t8=fgetc(fp);
  2099. t9=fgetc(fp);
  2100. if(t7==122) {//(sensor)
  2101. //Clear, copying to 0 first if param==curr
  2102. if((t9==curr_param)&&
  2103. (curr_thing==122)) {
  2104. copy_sensor(0,curr_param);
  2105. curr_param=0;
  2106. }
  2107. clear_sensor(t9);
  2108. }
  2109. //Overlay...
  2110. fgetc(fp);
  2111. fgetc(fp);
  2112. }
  2113. else {
  2114. //Place into new board
  2115. t7=t5+t6*max_bxsiz;
  2116. level_id[t7]=fgetc(fp);
  2117. level_color[t7]=fgetc(fp);
  2118. level_param[t7]=fgetc(fp);
  2119. level_under_id[t7]=fgetc(fp);
  2120. level_under_color[t7]=fgetc(fp);
  2121. level_under_param[t7]=fgetc(fp);
  2122. overlay[t7]=fgetc(fp);
  2123. overlay_color[t7]=fgetc(fp);
  2124. }
  2125. }
  2126. }
  2127. if(t0) {
  2128. //Place player at first empty space
  2129. t4=0;
  2130. for(t1=0;t1<board_xsiz;t1++) {
  2131. for(t2=0;t2<board_ysiz;t2++) {
  2132. t3=level_id[t1+t2*max_bxsiz];
  2133. if(t3<120) t4=t1+t2*max_bxsiz;
  2134. if(level_id[t1+t2*max_bxsiz]) continue;
  2135. id_place(t1,t2,127,0,0);
  2136. goto donneth;
  2137. }
  2138. }
  2139. //Put at first non-robot/scroll/sign/sensor
  2140. offs_place_id(t4,0,127,0,0);
  2141. }
  2142. fclose(fp);
  2143. unlink("~EDITRSZ.TMP");
  2144. }
  2145. donneth:
  2146. changed=1;
  2147. update_menu=update_view=1;
  2148. break;
  2149. case 'X'://X
  2150. if(draw_mode&128) break;
  2151. //Exits
  2152. board_exits();
  2153. changed=1;
  2154. break;
  2155. case -31://AltS
  2156. if(draw_mode&128) {
  2157. //Whether to show level in overlay mode
  2158. update_view=update_menu=1;
  2159. show_level^=1;
  2160. break;
  2161. }
  2162. //Status counter info
  2163. status_counter_info();
  2164. changed=1;
  2165. break;
  2166. case -19://AltR
  2167. if(draw_mode&128) break;
  2168. //Restart
  2169. if(!confirm("Clear ALL- Are you sure?")) {
  2170. //If current object is a robot/etc of not #0, copy to #0.
  2171. if((curr_thing==122)&&(curr_param!=0)) {
  2172. copy_sensor(0,curr_param);
  2173. curr_param=0;
  2174. }
  2175. if(((curr_thing==123)||(curr_thing==124))&&(curr_param!=0))
  2176. //No room = forget it!
  2177. if(!copy_robot(0,curr_param)) curr_param=0;
  2178. if(((curr_thing==125)||(curr_thing==126))&&(curr_param!=0))
  2179. //No room = forget it!
  2180. if(!copy_scroll(0,curr_param)) curr_param=0;
  2181. //If pw-protection is NO_SAVING, clear curr_objects
  2182. if(protection_method==NO_SAVING) {
  2183. clear_zero_objects();
  2184. curr_thing=curr_param=0;
  2185. curr_color=7;
  2186. }
  2187. clear_world();
  2188. changed=0;
  2189. update_menu=update_view=1;
  2190. draw_mode=0;
  2191. }
  2192. break;
  2193. case 'L'://L
  2194. if(draw_mode&128) break;
  2195. //Changed?
  2196. if(changed)
  2197. if(confirm("Load: World has not been saved, are you sure?")) break;
  2198. //Load world
  2199. if(!choose_file("*.MZX",temp,"Choose world to load",1)) {
  2200. //If current object is a robot/etc of not #0, copy to #0.
  2201. if((curr_thing==122)&&(curr_param!=0)) {
  2202. copy_sensor(0,curr_param);
  2203. curr_param=0;
  2204. }
  2205. if(((curr_thing==123)||(curr_thing==124))&&(curr_param!=0))
  2206. //No room = forget it!
  2207. if(!copy_robot(0,curr_param)) curr_param=0;
  2208. if(((curr_thing==125)||(curr_thing==126))&&(curr_param!=0))
  2209. //No room = forget it!
  2210. if(!copy_scroll(0,curr_param)) curr_param=0;
  2211. //If pw-protection is NO_SAVING, clear curr_objects
  2212. if(protection_method==NO_SAVING) {
  2213. clear_zero_objects();
  2214. curr_thing=curr_param=0;
  2215. curr_color=7;
  2216. }
  2217. //Swap out current board...
  2218. store_current();
  2219. clear_current();
  2220. //Load game
  2221. if(load_world(temp,1)) {
  2222. select_current(curr_board);
  2223. break;
  2224. }
  2225. //Swap in starting board
  2226. if(board_where[first_board]!=W_NOWHERE)
  2227. select_current(first_board);
  2228. else select_current(0);
  2229. changed=0;
  2230. update_menu=update_view=1;
  2231. x_pos=x_top_pos=y_pos=y_top_pos=draw_mode=0;
  2232. //Copy filename
  2233. str_cpy(curr_file,temp);
  2234. }
  2235. break;
  2236. case 'S'://S
  2237. if(draw_mode&128) break;
  2238. //Pw check
  2239. if(protection_method==NO_SAVING)
  2240. if(check_pw()) break;
  2241. //Save world
  2242. if(!save_world_dialog()) {
  2243. //Name in curr_file...
  2244. if(curr_file[0]==0) break;
  2245. add_ext(curr_file,".MZX");
  2246. //Check for an overwrite
  2247. if((fp=fopen(curr_file,"rb"))!=NULL) {
  2248. fclose(fp);
  2249. if(confirm("File exists- Overwrite?")) break;
  2250. }
  2251. //If current object is a robot/etc of not #0, copy to #0.
  2252. if((curr_thing==122)&&(curr_param!=0)) {
  2253. copy_sensor(0,curr_param);
  2254. curr_param=0;
  2255. }
  2256. if(((curr_thing==123)||(curr_thing==124))&&(curr_param!=0))
  2257. //No room = forget it!
  2258. if(!copy_robot(0,curr_param)) curr_param=0;
  2259. if(((curr_thing==125)||(curr_thing==126))&&(curr_param!=0))
  2260. //No room = forget it!
  2261. if(!copy_scroll(0,curr_param)) curr_param=0;
  2262. //Store current
  2263. store_current();
  2264. //Save entire game
  2265. save_world(curr_file);
  2266. //Reload current
  2267. select_current(curr_board);
  2268. changed=0;
  2269. update_view=update_menu=1;
  2270. }
  2271. break;
  2272. case 'D'://D
  2273. if(draw_mode&128) break;
  2274. //Delete board
  2275. //Choose which one...
  2276. t1=choose_board(curr_board,"Delete board:",current_pg_seg);
  2277. if(t1>0) {
  2278. if(confirm("DELETE BOARD- Are you sure?")) break;
  2279. //Deleting board t1. Current?
  2280. if(curr_board==t1) {
  2281. //Fix objects and swap to 0
  2282. //If current object is a robot/etc of not #0, copy to #0.
  2283. if((curr_thing==122)&&(curr_param!=0)) {
  2284. copy_sensor(0,curr_param);
  2285. curr_param=0;
  2286. }
  2287. if(((curr_thing==123)||(curr_thing==124))&&(curr_param!=0))
  2288. //No room = forget it!
  2289. if(!copy_robot(0,curr_param)) curr_param=0;
  2290. if(((curr_thing==125)||(curr_thing==126))&&(curr_param!=0))
  2291. //No room = forget it!
  2292. if(!copy_scroll(0,curr_param)) curr_param=0;
  2293. swap_with(0);
  2294. //Update x/y
  2295. if(ARRAY_X>=board_xsiz) x_pos=x_top_pos=0;
  2296. if(ARRAY_Y>=board_ysiz) y_pos=y_top_pos=0;
  2297. if((x_top_pos+80)>board_xsiz) x_top_pos=0;
  2298. if((y_top_pos+19)>board_ysiz) x_top_pos=0;
  2299. }
  2300. //Delete it if it isn't already
  2301. if(board_where[t1]!=W_NOWHERE) delete_board(t1);
  2302. //Fix starting board if neccessary
  2303. if(t1==first_board) first_board=0;
  2304. changed=1;
  2305. }
  2306. update_view=update_menu=1;
  2307. break;
  2308. case 'B'://B
  2309. if(draw_mode&128) break;
  2310. //Select board
  2311. //If current object is a robot/etc of not #0, copy to #0.
  2312. if((curr_thing==122)&&(curr_param!=0)) {
  2313. copy_sensor(0,curr_param);
  2314. curr_param=0;
  2315. }
  2316. if(((curr_thing==123)||(curr_thing==124))&&(curr_param!=0))
  2317. //No room = forget it!
  2318. if(!copy_robot(0,curr_param)) curr_param=0;
  2319. if(((curr_thing==125)||(curr_thing==126))&&(curr_param!=0))
  2320. //No room = forget it!
  2321. if(!copy_scroll(0,curr_param)) curr_param=0;
  2322. //Choose...
  2323. t1=choose_board(curr_board,"Select current board:",current_pg_seg);
  2324. if(t1>=0) swap_with(t1);
  2325. draw_mode=0;
  2326. update_view=update_menu=1;
  2327. //Update x/y
  2328. if(ARRAY_X>=board_xsiz) x_pos=x_top_pos=0;
  2329. if(ARRAY_Y>=board_ysiz) y_pos=y_top_pos=0;
  2330. if((x_top_pos+80)>board_xsiz) x_top_pos=0;
  2331. if((y_top_pos+19)>board_ysiz) y_top_pos=0;
  2332. break;
  2333. case 'A'://A
  2334. if(draw_mode&128) break;
  2335. //Add board
  2336. //Search for empty...
  2337. for(t1=0;t1<NUM_BOARDS;t1++)
  2338. if(board_where[t1]==W_NOWHERE) break;
  2339. if(t1>=NUM_BOARDS) {
  2340. error("No available boards",1,24,current_pg_seg,0x0B01);
  2341. break;
  2342. }
  2343. //Input a name
  2344. m_hide();
  2345. save_screen(current_pg_seg);
  2346. draw_window_box(16,12,64,14,current_pg_seg,EC_DEBUG_BOX,
  2347. EC_DEBUG_BOX_DARK,EC_DEBUG_BOX_CORNER);
  2348. write_string("Name for new board:",18,13,EC_DEBUG_LABEL,
  2349. current_pg_seg);
  2350. update_menu=update_view=1;
  2351. board_list[t1*BOARD_NAME_SIZE]=0;
  2352. m_show();
  2353. if(intake(&board_list[t1*BOARD_NAME_SIZE],BOARD_NAME_SIZE-1,
  2354. 38,13,current_pg_seg,15,1,0)==27) {
  2355. restore_screen(current_pg_seg);
  2356. break;
  2357. }
  2358. restore_screen(current_pg_seg);
  2359. //If current object is a robot/etc of not #0, copy to #0.
  2360. if((curr_thing==122)&&(curr_param!=0)) {
  2361. copy_sensor(0,curr_param);
  2362. curr_param=0;
  2363. }
  2364. if(((curr_thing==123)||(curr_thing==124))&&(curr_param!=0))
  2365. //No room = forget it!
  2366. if(!copy_robot(0,curr_param)) curr_param=0;
  2367. if(((curr_thing==125)||(curr_thing==126))&&(curr_param!=0))
  2368. //No room = forget it!
  2369. if(!copy_scroll(0,curr_param)) curr_param=0;
  2370. //Store current
  2371. store_current();
  2372. //Add at number t1
  2373. clear_current_and_select(t1);
  2374. board_where[curr_board=t1]=W_CURRENT;
  2375. board_sizes[t1]=0;
  2376. changed=1;
  2377. //No need to fix x/y position since sizing info is taken
  2378. //from current board.
  2379. break;
  2380. case 27://ESC
  2381. //ESC cancels draw mode if any, instead of exiting
  2382. if((draw_mode&127)>0) {
  2383. draw_mode&=128;
  2384. update_view=update_menu=1;
  2385. key=0;
  2386. }
  2387. //If none, tries to cancel overlay mode
  2388. else if(draw_mode&128) {
  2389. key=0;
  2390. goto overlay_off;
  2391. }
  2392. //Else we will exit-
  2393. else if(changed)
  2394. if(confirm("Exit: World has not been saved, are you sure?")) {
  2395. key=0;
  2396. break;
  2397. }
  2398. break;
  2399. case -81://Pgdn
  2400. next_menu:
  2401. if(draw_mode&128) break;
  2402. if(curr_menu<(NUM_MENUS-1)) curr_menu++;
  2403. else curr_menu=0;
  2404. update_menu=1;
  2405. break;
  2406. case -73://Pgup
  2407. prev_menu:
  2408. if(draw_mode&128) break;
  2409. if(curr_menu>0) curr_menu--;
  2410. else curr_menu=NUM_MENUS-1;
  2411. update_menu=1;
  2412. break;
  2413. case -71://Home
  2414. x_pos=y_pos=x_top_pos=y_top_pos=0;
  2415. update_view=1;
  2416. debug_x=65;
  2417. break;
  2418. case -79://End
  2419. if(board_xsiz<80) {
  2420. x_top_pos=0;
  2421. x_pos=board_xsiz-1;
  2422. }
  2423. else {
  2424. x_pos=79;
  2425. x_top_pos=board_xsiz-x_pos-1;
  2426. }
  2427. if(board_ysiz<19) {
  2428. y_top_pos=0;
  2429. y_pos=board_ysiz-1;
  2430. }
  2431. else {
  2432. y_pos=18;
  2433. y_top_pos=board_ysiz-y_pos-1;
  2434. }
  2435. update_view=1;
  2436. debug_x=0;
  2437. break;
  2438. case -77://Right
  2439. case -157://AltRight
  2440. move_right:
  2441. if(key==-157) t1=10;
  2442. else t1=1;
  2443. for(;t1>0;t1--) {//By amount
  2444. //At edge?
  2445. if(ARRAY_X<(board_xsiz-1)) {
  2446. //Nope- Do a little incrementing.
  2447. //If x position < 74, move right one.
  2448. //Else scroll right one, unless can't, then
  2449. //move right one.
  2450. if(x_pos<74) x_pos++;
  2451. else {
  2452. if((x_top_pos+80)<board_xsiz) {
  2453. x_top_pos++;
  2454. update_view=1;
  2455. }
  2456. else x_pos++;
  2457. }
  2458. //Move debug window?
  2459. if((debug_x==65)&&(x_pos>59)) {
  2460. debug_x=0;
  2461. update_view=1;
  2462. }
  2463. //Draw? (only if not last movement)
  2464. if((t1)&&((draw_mode&127)==1)) {
  2465. if(draw_mode&128) {
  2466. overlay[ARRAY_OFFS]=curr_param;
  2467. overlay_color[ARRAY_OFFS]=curr_color;
  2468. update_view=1;
  2469. }
  2470. else if(level_id[ARRAY_OFFS]!=127) {//No overwriting player
  2471. //If a robot/scroll/sensor...
  2472. if(curr_thing==122) {//(sensor)
  2473. //...make a copy...
  2474. if(!(t2=find_sensor())) {
  2475. error("No available sensors",1,24,current_pg_seg,0x0801);
  2476. break;
  2477. }
  2478. copy_sensor(t2,curr_param);
  2479. //...and deallocate original if it was number 0.
  2480. if(curr_param==0) clear_sensor(0);
  2481. curr_param=t2;
  2482. }
  2483. if((curr_thing==123)||(curr_thing==124)) {//(robot)
  2484. //...make a copy...
  2485. if(!(t2=find_robot())) {
  2486. error("No available robots",1,24,current_pg_seg,0x0901);
  2487. break;
  2488. }
  2489. if(copy_robot(t2,curr_param)) {
  2490. robots[t2].used=0;
  2491. error("Out of robot memory",1,21,current_pg_seg,0x0502);
  2492. break;
  2493. }
  2494. //...and deallocate original if it was number 0.
  2495. if(curr_param==0) clear_robot(0);
  2496. curr_param=t2;
  2497. }
  2498. if((curr_thing==125)||(curr_thing==126)) {//(scroll)
  2499. //...make a copy...
  2500. if(!(t2=find_scroll())) {
  2501. error("No available scrolls",1,24,current_pg_seg,0x0A01);
  2502. break;
  2503. }
  2504. if(copy_scroll(t2,curr_param)) {
  2505. robots[t2].used=0;
  2506. error("Out of robot memory",1,21,current_pg_seg,0x0503);
  2507. break;
  2508. }
  2509. //...and deallocate original if it was number 0.
  2510. if(curr_param==0) clear_scroll(0);
  2511. curr_param=t2;
  2512. }
  2513. //Search and erase old players if placing a player.
  2514. if(curr_thing==127)
  2515. for(t2=0;t2<board_xsiz;t2++)
  2516. for(t3=0;t3<board_ysiz;t3++)
  2517. if(level_id[t2+t3*max_bxsiz]==127)
  2518. id_remove_top(t2,t3);
  2519. //If top thing at position is a robot/etc, deallocate it.
  2520. t2=level_id[ARRAY_OFFS];
  2521. if((t2==122)&&(curr_thing!=127)) //(sensor)
  2522. clear_sensor(level_param[ARRAY_OFFS]);
  2523. else if((t2==123)||(t2==124)) //(robot)
  2524. clear_robot(level_param[ARRAY_OFFS]);
  2525. else if((t2==125)||(t2==126)) //(scroll)
  2526. clear_scroll(level_param[ARRAY_OFFS]);
  2527. //Place.
  2528. id_place(ARRAY_X,ARRAY_Y,curr_thing,curr_color,curr_param);
  2529. }
  2530. }
  2531. }
  2532. }
  2533. if((draw_mode&127)==1) goto place;
  2534. if((draw_mode&127)==3) update_view=1;
  2535. break;
  2536. case -75://Left
  2537. case -155://AltLeft
  2538. if(key==-155) t1=10;
  2539. else t1=1;
  2540. for(;t1>0;t1--) {//By amount
  2541. //At edge?
  2542. if(ARRAY_X>0) {
  2543. //Nope- Do a little decrementing.
  2544. //If x position > 5, move left one.
  2545. //Else scroll left one, unless can't, then
  2546. //move left one.
  2547. if(x_pos>5) x_pos--;
  2548. else {
  2549. if(x_top_pos>0) {
  2550. x_top_pos--;
  2551. update_view=1;
  2552. }
  2553. else x_pos--;
  2554. }
  2555. //Move debug window?
  2556. if((debug_x==0)&&(x_pos<20)) {
  2557. debug_x=65;
  2558. update_view=1;
  2559. }
  2560. //Draw? (only if not last movement)
  2561. if((t1)&&((draw_mode&127)==1)) {
  2562. if(draw_mode&128) {
  2563. overlay[ARRAY_OFFS]=curr_param;
  2564. overlay_color[ARRAY_OFFS]=curr_color;
  2565. update_view=1;
  2566. }
  2567. else if(level_id[ARRAY_OFFS]!=127) {//No overwriting player
  2568. //If a robot/scroll/sensor...
  2569. if(curr_thing==122) {//(sensor)
  2570. //...make a copy...
  2571. if(!(t2=find_sensor())) {
  2572. error("No available sensors",1,24,current_pg_seg,0x0801);
  2573. break;
  2574. }
  2575. copy_sensor(t2,curr_param);
  2576. //...and deallocate original if it was number 0.
  2577. if(curr_param==0) clear_sensor(0);
  2578. curr_param=t2;
  2579. }
  2580. if((curr_thing==123)||(curr_thing==124)) {//(robot)
  2581. //...make a copy...
  2582. if(!(t2=find_robot())) {
  2583. error("No available robots",1,24,current_pg_seg,0x0901);
  2584. break;
  2585. }
  2586. if(copy_robot(t2,curr_param)) {
  2587. robots[t2].used=0;
  2588. error("Out of robot memory",1,21,current_pg_seg,0x0502);
  2589. break;
  2590. }
  2591. //...and deallocate original if it was number 0.
  2592. if(curr_param==0) clear_robot(0);
  2593. curr_param=t2;
  2594. }
  2595. if((curr_thing==125)||(curr_thing==126)) {//(scroll)
  2596. //...make a copy...
  2597. if(!(t2=find_scroll())) {
  2598. error("No available scrolls",1,24,current_pg_seg,0x0A01);
  2599. break;
  2600. }
  2601. if(copy_scroll(t2,curr_param)) {
  2602. robots[t2].used=0;
  2603. error("Out of robot memory",1,21,current_pg_seg,0x0503);
  2604. break;
  2605. }
  2606. //...and deallocate original if it was number 0.
  2607. if(curr_param==0) clear_scroll(0);
  2608. curr_param=t2;
  2609. }
  2610. //Search and erase old players if placing a player.
  2611. if(curr_thing==127)
  2612. for(t2=0;t2<board_xsiz;t2++)
  2613. for(t3=0;t3<board_ysiz;t3++)
  2614. if(level_id[t2+t3*max_bxsiz]==127)
  2615. id_remove_top(t2,t3);
  2616. //If top thing at position is a robot/etc, deallocate it.
  2617. t2=level_id[ARRAY_OFFS];
  2618. if((t2==122)&&(curr_thing!=127)) //(sensor)
  2619. clear_sensor(level_param[ARRAY_OFFS]);
  2620. else if((t2==123)||(t2==124)) //(robot)
  2621. clear_robot(level_param[ARRAY_OFFS]);
  2622. else if((t2==125)||(t2==126)) //(scroll)
  2623. clear_scroll(level_param[ARRAY_OFFS]);
  2624. //Place.
  2625. id_place(ARRAY_X,ARRAY_Y,curr_thing,curr_color,curr_param);
  2626. }
  2627. }
  2628. }
  2629. }
  2630. if((draw_mode&127)==1) goto place;
  2631. if((draw_mode&127)==3) update_view=1;
  2632. break;
  2633. case 8://Backspace
  2634. //Delete to the left...first move left in text mode
  2635. //At edge?
  2636. if((ARRAY_X>0)&&((draw_mode&127)==2)) {
  2637. //Nope- Do a little decrementing.
  2638. //If x position > 5, move left one.
  2639. //Else scroll left one, unless can't, then
  2640. //move left one.
  2641. if(x_pos>5) x_pos--;
  2642. else {
  2643. if(x_top_pos>0) x_top_pos--;
  2644. else x_pos--;
  2645. }
  2646. //Move debug window?
  2647. if((debug_x==0)&&(x_pos<20)) debug_x=65;
  2648. }
  2649. //Jump to delete
  2650. goto erase;
  2651. case -80://Down
  2652. case -160://AltDown
  2653. move_down:
  2654. if(key==-160) t1=10;
  2655. else t1=1;
  2656. for(;t1>0;t1--) {//By amount
  2657. //At edge?
  2658. if(ARRAY_Y<(board_ysiz-1)) {
  2659. //Nope- Do a little incrementing.
  2660. //If y position < 14, move down one.
  2661. //Else scroll down one, unless can't, then
  2662. //move down one.
  2663. if(y_pos<14) y_pos++;
  2664. else {
  2665. if((y_top_pos+19)<board_ysiz) {
  2666. y_top_pos++;
  2667. update_view=1;
  2668. }
  2669. else y_pos++;
  2670. }
  2671. //Draw? (only if not last movement)
  2672. if((t1)&&((draw_mode&127)==1)) {
  2673. if(draw_mode&128) {
  2674. overlay[ARRAY_OFFS]=curr_param;
  2675. overlay_color[ARRAY_OFFS]=curr_color;
  2676. update_view=1;
  2677. }
  2678. else if(level_id[ARRAY_OFFS]!=127) {//No overwriting player
  2679. //If a robot/scroll/sensor...
  2680. if(curr_thing==122) {//(sensor)
  2681. //...make a copy...
  2682. if(!(t2=find_sensor())) {
  2683. error("No available sensors",1,24,current_pg_seg,0x0801);
  2684. break;
  2685. }
  2686. copy_sensor(t2,curr_param);
  2687. //...and deallocate original if it was number 0.
  2688. if(curr_param==0) clear_sensor(0);
  2689. curr_param=t2;
  2690. }
  2691. if((curr_thing==123)||(curr_thing==124)) {//(robot)
  2692. //...make a copy...
  2693. if(!(t2=find_robot())) {
  2694. error("No available robots",1,24,current_pg_seg,0x0901);
  2695. break;
  2696. }
  2697. if(copy_robot(t2,curr_param)) {
  2698. robots[t2].used=0;
  2699. error("Out of robot memory",1,21,current_pg_seg,0x0502);
  2700. break;
  2701. }
  2702. //...and deallocate original if it was number 0.
  2703. if(curr_param==0) clear_robot(0);
  2704. curr_param=t2;
  2705. }
  2706. if((curr_thing==125)||(curr_thing==126)) {//(scroll)
  2707. //...make a copy...
  2708. if(!(t2=find_scroll())) {
  2709. error("No available scrolls",1,24,current_pg_seg,0x0A01);
  2710. break;
  2711. }
  2712. if(copy_scroll(t2,curr_param)) {
  2713. robots[t2].used=0;
  2714. error("Out of robot memory",1,21,current_pg_seg,0x0503);
  2715. break;
  2716. }
  2717. //...and deallocate original if it was number 0.
  2718. if(curr_param==0) clear_scroll(0);
  2719. curr_param=t2;
  2720. }
  2721. //Search and erase old players if placing a player.
  2722. if(curr_thing==127)
  2723. for(t2=0;t2<board_xsiz;t2++)
  2724. for(t3=0;t3<board_ysiz;t3++)
  2725. if(level_id[t2+t3*max_bxsiz]==127)
  2726. id_remove_top(t2,t3);
  2727. //If top thing at position is a robot/etc, deallocate it.
  2728. t2=level_id[ARRAY_OFFS];
  2729. if((t2==122)&&(curr_thing!=127)) //(sensor)
  2730. clear_sensor(level_param[ARRAY_OFFS]);
  2731. else if((t2==123)||(t2==124)) //(robot)
  2732. clear_robot(level_param[ARRAY_OFFS]);
  2733. else if((t2==125)||(t2==126)) //(scroll)
  2734. clear_scroll(level_param[ARRAY_OFFS]);
  2735. //Place.
  2736. id_place(ARRAY_X,ARRAY_Y,curr_thing,curr_color,curr_param);
  2737. }
  2738. }
  2739. }
  2740. }
  2741. if((draw_mode&127)==1) goto place;
  2742. if((draw_mode&127)==3) update_view=1;
  2743. break;
  2744. case -72://Up
  2745. case -152://AltUp
  2746. if(key==-152) t1=10;
  2747. else t1=1;
  2748. for(;t1>0;t1--) {//By amount
  2749. //At edge?
  2750. if(ARRAY_Y>0) {
  2751. //Nope- Do a little decrementing.
  2752. //If y position > 4, move up one.
  2753. //Else scroll up one, unless can't, then
  2754. //move up one.
  2755. if(y_pos>4) y_pos--;
  2756. else {
  2757. if(y_top_pos>0) {
  2758. y_top_pos--;
  2759. update_view=1;
  2760. }
  2761. else y_pos--;
  2762. }
  2763. //Draw? (only if not last movement)
  2764. if((t1)&&((draw_mode&127)==1)) {
  2765. if(draw_mode&128) {
  2766. overlay[ARRAY_OFFS]=curr_param;
  2767. overlay_color[ARRAY_OFFS]=curr_color;
  2768. update_view=1;
  2769. }
  2770. else if(level_id[ARRAY_OFFS]!=127) {//No overwriting player
  2771. //If a robot/scroll/sensor...
  2772. if(curr_thing==122) {//(sensor)
  2773. //...make a copy...
  2774. if(!(t2=find_sensor())) {
  2775. error("No available sensors",1,24,current_pg_seg,0x0801);
  2776. break;
  2777. }
  2778. copy_sensor(t2,curr_param);
  2779. //...and deallocate original if it was number 0.
  2780. if(curr_param==0) clear_sensor(0);
  2781. curr_param=t2;
  2782. }
  2783. if((curr_thing==123)||(curr_thing==124)) {//(robot)
  2784. //...make a copy...
  2785. if(!(t2=find_robot())) {
  2786. error("No available robots",1,24,current_pg_seg,0x0901);
  2787. break;
  2788. }
  2789. if(copy_robot(t2,curr_param)) {
  2790. robots[t2].used=0;
  2791. error("Out of robot memory",1,21,current_pg_seg,0x0502);
  2792. break;
  2793. }
  2794. //...and deallocate original if it was number 0.
  2795. if(curr_param==0) clear_robot(0);
  2796. curr_param=t2;
  2797. }
  2798. if((curr_thing==125)||(curr_thing==126)) {//(scroll)
  2799. //...make a copy...
  2800. if(!(t2=find_scroll())) {
  2801. error("No available scrolls",1,24,current_pg_seg,0x0A01);
  2802. break;
  2803. }
  2804. if(copy_scroll(t2,curr_param)) {
  2805. robots[t2].used=0;
  2806. error("Out of robot memory",1,21,current_pg_seg,0x0503);
  2807. break;
  2808. }
  2809. //...and deallocate original if it was number 0.
  2810. if(curr_param==0) clear_scroll(0);
  2811. curr_param=t2;
  2812. }
  2813. //Search and erase old players if placing a player.
  2814. if(curr_thing==127)
  2815. for(t2=0;t2<board_xsiz;t2++)
  2816. for(t3=0;t3<board_ysiz;t3++)
  2817. if(level_id[t2+t3*max_bxsiz]==127)
  2818. id_remove_top(t2,t3);
  2819. //If top thing at position is a robot/etc, deallocate it.
  2820. t2=level_id[ARRAY_OFFS];
  2821. if((t2==122)&&(curr_thing!=127)) //(sensor)
  2822. clear_sensor(level_param[ARRAY_OFFS]);
  2823. else if((t2==123)||(t2==124)) //(robot)
  2824. clear_robot(level_param[ARRAY_OFFS]);
  2825. else if((t2==125)||(t2==126)) //(scroll)
  2826. clear_scroll(level_param[ARRAY_OFFS]);
  2827. //Place.
  2828. id_place(ARRAY_X,ARRAY_Y,curr_thing,curr_color,curr_param);
  2829. }
  2830. }
  2831. }
  2832. }
  2833. if((draw_mode&127)==1) goto place;
  2834. if((draw_mode&127)==3) update_view=1;
  2835. break;
  2836. case -21://AltY
  2837. //Toggle debug
  2838. debug_mode=!debug_mode;
  2839. update_view=update_menu=1;
  2840. break;
  2841. case -32://AltD
  2842. if(draw_mode&128) break;
  2843. //Toggle default colors
  2844. def_color_mode=!def_color_mode;
  2845. update_menu=1;
  2846. break;
  2847. case 32://Space
  2848. //Place, making copies properly for robots/scrolls/sensors,
  2849. //not deleting the player, and moving the player from it's
  2850. //original position if placed.
  2851. //If same id/color, erase
  2852. if(draw_mode&128) {
  2853. if((overlay[ARRAY_OFFS]==curr_param)&&
  2854. (overlay_color[ARRAY_OFFS]==curr_color)) goto erase;
  2855. }
  2856. else {
  2857. if((level_id[ARRAY_OFFS]==curr_thing)&&
  2858. (level_color[ARRAY_OFFS]==curr_color)) goto erase;
  2859. }
  2860. place:
  2861. changed=1;
  2862. //(place: label here since drawing and new things should
  2863. //ALWAYS work)
  2864. if(draw_mode&128) {
  2865. overlay[ARRAY_OFFS]=curr_param;
  2866. overlay_color[ARRAY_OFFS]=curr_color;
  2867. update_view=1;
  2868. break;
  2869. }
  2870. if(level_id[ARRAY_OFFS]==127) break;//No overwriting player
  2871. //If a robot/scroll/sensor...
  2872. if(curr_thing==122) {//(sensor)
  2873. //...make a copy...
  2874. if(!(t1=find_sensor())) {
  2875. error("No available sensors",1,24,current_pg_seg,0x0801);
  2876. break;
  2877. }
  2878. copy_sensor(t1,curr_param);
  2879. //...and deallocate original if it was number 0.
  2880. if(curr_param==0) clear_sensor(0);
  2881. curr_param=t1;
  2882. }
  2883. if((curr_thing==123)||(curr_thing==124)) {//(robot)
  2884. //...make a copy...
  2885. if(!(t1=find_robot())) {
  2886. error("No available robots",1,24,current_pg_seg,0x0901);
  2887. break;
  2888. }
  2889. if(copy_robot(t1,curr_param)) {
  2890. robots[t1].used=0;
  2891. error("Out of robot memory",1,21,current_pg_seg,0x0502);
  2892. break;
  2893. }
  2894. //...and deallocate original if it was number 0.
  2895. if(curr_param==0) clear_robot(0);
  2896. curr_param=t1;
  2897. }
  2898. if((curr_thing==125)||(curr_thing==126)) {//(scroll)
  2899. //...make a copy...
  2900. if(!(t1=find_scroll())) {
  2901. error("No available scrolls",1,24,current_pg_seg,0x0A01);
  2902. break;
  2903. }
  2904. if(copy_scroll(t1,curr_param)) {
  2905. robots[t1].used=0;
  2906. error("Out of robot memory",1,21,current_pg_seg,0x0503);
  2907. break;
  2908. }
  2909. //...and deallocate original if it was number 0.
  2910. if(curr_param==0) clear_scroll(0);
  2911. curr_param=t1;
  2912. }
  2913. //Search and erase old players if placing a player.
  2914. if(curr_thing==127)
  2915. for(t1=0;t1<board_xsiz;t1++)
  2916. for(t2=0;t2<board_ysiz;t2++)
  2917. if(level_id[t1+t2*max_bxsiz]==127)
  2918. id_remove_top(t1,t2);
  2919. //If top thing at position is a robot/etc, deallocate it.
  2920. t1=level_id[ARRAY_OFFS];
  2921. if((t1==122)&&(curr_thing!=127)) //(sensor)
  2922. clear_sensor(level_param[ARRAY_OFFS]);
  2923. else if((t1==123)||(t1==124)) //(robot)
  2924. clear_robot(level_param[ARRAY_OFFS]);
  2925. else if((t1==125)||(t1==126)) //(scroll)
  2926. clear_scroll(level_param[ARRAY_OFFS]);
  2927. //Place.
  2928. id_place(ARRAY_X,ARRAY_Y,curr_thing,curr_color,curr_param);
  2929. update_view=1;
  2930. break;
  2931. case -83://Del
  2932. erase:
  2933. changed=1;
  2934. //Erase
  2935. if(draw_mode&128) {
  2936. overlay[ARRAY_OFFS]=32;
  2937. overlay_color[ARRAY_OFFS]=7;
  2938. update_view=1;
  2939. break;
  2940. }
  2941. //Special for robots/scrolls/sensors
  2942. t1=level_id[ARRAY_OFFS];
  2943. if(t1==122) {//(sensor)
  2944. //Clear, copying to 0 first if param==curr
  2945. if((level_param[ARRAY_OFFS]==curr_param)&&
  2946. (curr_thing==122)) {
  2947. copy_sensor(0,curr_param);
  2948. curr_param=0;
  2949. }
  2950. clear_sensor(level_param[ARRAY_OFFS]);
  2951. }
  2952. else if((t1==123)||(t1==124)) {//(robot)
  2953. //Clear, copying to 0 first if param==curr
  2954. if((level_param[ARRAY_OFFS]==curr_param)&&
  2955. ((curr_thing==123)||(curr_thing==124))) {
  2956. copy_robot(0,curr_param);
  2957. curr_param=0;
  2958. }
  2959. clear_robot(level_param[ARRAY_OFFS]);
  2960. }
  2961. else if((t1==125)||(t1==126)) {//(scroll)
  2962. //Clear, copying to 0 first if param==curr
  2963. if((level_param[ARRAY_OFFS]==curr_param)&&
  2964. ((curr_thing==125)||(curr_thing==126))) {
  2965. copy_scroll(0,curr_param);
  2966. curr_param=0;
  2967. }
  2968. clear_scroll(level_param[ARRAY_OFFS]);
  2969. }
  2970. else if(t1==127) break;//No kill player
  2971. //Clear
  2972. id_clear(ARRAY_X,ARRAY_Y);
  2973. update_view=1;
  2974. break;
  2975. case 'C'://C
  2976. change_color:
  2977. //Change color
  2978. t1=color_selection(curr_color,current_pg_seg);
  2979. if(t1>-1) {
  2980. curr_color=t1;
  2981. update_menu=1;
  2982. }
  2983. break;
  2984. case -61://F3
  2985. case -62://F4
  2986. case -63://F5
  2987. case -64://F6
  2988. case -65://F7
  2989. case -66://F8
  2990. case -67://F9
  2991. case -68://F10
  2992. if(draw_mode&128) break;
  2993. //Over player?
  2994. if(level_id[ARRAY_OFFS]==127) {//No overwriting player
  2995. error("Cannot overwrite player- move him first",0,24,
  2996. current_pg_seg,0x3E01);
  2997. break;
  2998. }
  2999. //Unselecting #0?
  3000. if((curr_thing==122)&&(curr_param==0)) {
  3001. clear_sensor(0);
  3002. curr_thing=0;
  3003. }
  3004. else if(((curr_thing==123)||(curr_thing==124))&&(curr_param==0)) {
  3005. clear_robot(0);
  3006. curr_thing=0;
  3007. }
  3008. else if(((curr_thing==125)||(curr_thing==126))&&(curr_param==0)) {
  3009. clear_scroll(0);
  3010. curr_thing=0;
  3011. }
  3012. //Thing menus
  3013. t1=(-key)-61;//Menu # from 0 to 7
  3014. t2=list_menu(thing_menus[t1],20,tmenu_titles[t1],0,
  3015. tmenu_num_choices[t1],current_pg_seg);
  3016. if(t2>-1) {
  3017. t1=tmenu_thing_ids[t1][t2];
  3018. //Set param
  3019. t2=edit_param(t1,-1);
  3020. if(t2<0) break;//ESC
  3021. curr_thing=t1;//Thing
  3022. curr_param=t2;//Param
  3023. if(def_color_mode)//Set color
  3024. if(def_colors[curr_thing])
  3025. curr_color=def_colors[curr_thing];
  3026. update_menu=1;
  3027. goto place;//Now PLACE it!
  3028. }
  3029. break;
  3030. case -82://Insert
  3031. if(draw_mode&128) {
  3032. curr_param=overlay[ARRAY_OFFS];
  3033. curr_color=overlay_color[ARRAY_OFFS];
  3034. update_menu=1;
  3035. break;
  3036. }
  3037. //Grab. Only special case is if current is a sensor/etc. with
  3038. //param 0, then must free mem.
  3039. if((curr_thing==122)&&(curr_param==0))
  3040. clear_sensor(0);
  3041. else if(((curr_thing==123)||(curr_thing==124))&&(curr_param==0))
  3042. clear_robot(0);
  3043. else if(((curr_thing==125)||(curr_thing==126))&&(curr_param==0))
  3044. clear_scroll(0);
  3045. //Grab (gets objects properly, as a reference to copy from)
  3046. curr_thing=level_id[ARRAY_OFFS];
  3047. curr_param=level_param[ARRAY_OFFS];
  3048. curr_color=level_color[ARRAY_OFFS];
  3049. update_menu=1;
  3050. break;
  3051. case -50://AltM
  3052. if(draw_mode&128) break;
  3053. //Modify- Edit parameter of thing UNDER cursor. If it is our
  3054. //current object, we first copy ourselves to #0.
  3055. if((level_id[ARRAY_OFFS]==curr_thing)&&
  3056. (level_param[ARRAY_OFFS]==curr_param)) {
  3057. if(curr_thing==122) {
  3058. copy_sensor(0,curr_param);
  3059. curr_param=0;
  3060. }
  3061. else if((curr_thing==123)||(curr_thing==124)) {
  3062. //If out of mem, just don't copy!
  3063. if(!copy_robot(0,curr_param)) curr_param=0;
  3064. }
  3065. else if((curr_thing==125)||(curr_thing==126)) {
  3066. //If out of mem, just don't copy!
  3067. if(!copy_scroll(0,curr_param)) curr_param=0;
  3068. }
  3069. }
  3070. t2=edit_param(level_id[ARRAY_OFFS],level_param[ARRAY_OFFS]);
  3071. if(t2>-1) {
  3072. changed=1;
  3073. level_param[ARRAY_OFFS]=t2;
  3074. }
  3075. break;
  3076. case 13://Enter
  3077. update_view=1;
  3078. //(special for text mode)
  3079. if((draw_mode&127)==2) {
  3080. x_top_pos=save_x-5;
  3081. x_pos=5;
  3082. if(save_x<5) {
  3083. x_top_pos=0;
  3084. x_pos=save_x;
  3085. }
  3086. else if((save_x+75)>board_xsiz) {
  3087. x_top_pos=board_xsiz-80;
  3088. x_pos=save_x-x_top_pos;
  3089. if(x_top_pos<0) {
  3090. x_top_pos=0;
  3091. x_pos=save_x;
  3092. }
  3093. if(x_pos<0) x_pos=0;
  3094. }
  3095. goto move_down;
  3096. }
  3097. if(draw_mode&128) {
  3098. t1=char_selection(curr_param,current_pg_seg);
  3099. if(t1>=0) curr_param=t1;
  3100. update_menu=1;
  3101. break;
  3102. }
  3103. //Modify at cursor and grab. Only special case is if current
  3104. //is an object param #0. Grabbing objects works because our
  3105. //copy is supposed to be an exact duplicate, and we make copies
  3106. //during placement.
  3107. if((curr_thing==122)&&(curr_param==0))
  3108. clear_sensor(0);
  3109. else if(((curr_thing==123)||(curr_thing==124))&&(curr_param==0))
  3110. clear_robot(0);
  3111. else if(((curr_thing==125)||(curr_thing==126))&&(curr_param==0))
  3112. clear_scroll(0);
  3113. //Grab
  3114. curr_thing=level_id[ARRAY_OFFS];
  3115. curr_param=level_param[ARRAY_OFFS];
  3116. curr_color=level_color[ARRAY_OFFS];
  3117. //Modify
  3118. t2=edit_param(curr_thing,curr_param);
  3119. if(t2>-1) {
  3120. curr_param=t2;
  3121. changed=1;
  3122. }
  3123. //Save
  3124. level_param[ARRAY_OFFS]=curr_param;
  3125. update_menu=1;
  3126. break;
  3127. case 'P'://P
  3128. if(draw_mode&128) break;
  3129. //Edit parameter of current thing.
  3130. t2=edit_param(curr_thing,curr_param);
  3131. if(t2>-1) curr_param=t2;
  3132. update_menu=1;
  3133. break;
  3134. case 'R'://R
  3135. //Redraw screen
  3136. update_view=update_menu=1;
  3137. break;
  3138. case 9://Tab
  3139. //Toggle draw
  3140. if((draw_mode&127)==0) draw_mode=1+(draw_mode&128);
  3141. else draw_mode&=128;
  3142. update_menu=update_view=1;
  3143. if(draw_mode&127) goto place;
  3144. break;
  3145. case -44://AltZ
  3146. if(draw_mode&128) break;
  3147. //Clear board
  3148. if(!confirm("Clear board- Are you sure?")) {
  3149. //Save current objects
  3150. if((curr_thing==122)&&(curr_param!=0)) {
  3151. copy_sensor(0,curr_param);
  3152. curr_param=0;
  3153. }
  3154. if(((curr_thing==123)||(curr_thing==124))&&(curr_param!=0))
  3155. //No room- forget it!
  3156. if(!copy_robot(0,curr_param)) curr_param=0;
  3157. if(((curr_thing==125)||(curr_thing==126))&&(curr_param!=0))
  3158. //No room- forget it!
  3159. if(!copy_scroll(0,curr_param)) curr_param=0;
  3160. //No need to fix x/y position since board size remains
  3161. clear_current();
  3162. changed=1;
  3163. update_view=update_menu=1;
  3164. draw_mode=0;
  3165. }
  3166. break;
  3167. case -49://AltN
  3168. if(draw_mode&128) break;
  3169. //Mod
  3170. update_menu=1;
  3171. //Turn off module if one present...
  3172. if(mod_playing[0]!=0) end_mod();
  3173. //...else new module
  3174. else {
  3175. if(choose_file(NULL,temp,"Choose a module file")) break;
  3176. load_mod(temp);
  3177. }
  3178. changed=1;
  3179. break;
  3180. case -127://Alt8
  3181. if(draw_mode&128) break;
  3182. //Mod
  3183. update_menu=1;
  3184. //Turn off module if one present...
  3185. if(mod_playing[0]!=0) end_mod();
  3186. //...else new module
  3187. str_cpy(mod_playing,"*");
  3188. changed=1;
  3189. break;
  3190. case -38://AltL
  3191. if(draw_mode&128) break;
  3192. //Sample
  3193. update_menu=1;
  3194. //Choose and play sample
  3195. if(choose_file("*.SAM",temp,"Choose a .SAM file")) break;
  3196. play_sample(428,temp);
  3197. break;
  3198. case -60://F2
  3199. //Text
  3200. update_menu=1;
  3201. if((draw_mode&127)==0) {
  3202. draw_mode=2+(draw_mode&128);//Text mode
  3203. save_x=ARRAY_X;//Remember our position for ENTER.
  3204. }
  3205. else draw_mode&=128;
  3206. break;
  3207. }
  3208. move_cursor(x_pos,y_pos);
  3209. cursor_solid();
  3210. //Loop if not exiting
  3211. } while(key!=27);
  3212. cursor_off();
  3213. vquick_fadeout();
  3214. clear_sfx_queue();
  3215. //Exit with mouse on
  3216. error_mode=2;
  3217. pop_context();
  3218. }
  3219. //Arrays for 'thing' menus
  3220. char tmenu_num_choices[8]={ 17,14,18,8,6,11,12,10 };
  3221. char far *tmenu_titles[8]={ "Terrains","Items","Creatures","Puzzle Pieces",
  3222. "Transport","Elements","Miscellaneous","Objects" };
  3223. char far *thing_menus[8]={//Each 'item' is 20 char long, including '\0'.
  3224. //Terrain (F3)
  3225. "Space ~1 \0\
  3226. Normal ~E²\0\
  3227. Solid ~DÛ\0\
  3228. Tree ~A\0\
  3229. Line ~BÍ\0\
  3230. Custom Block ~F?\0\
  3231. Breakaway ~C±\0\
  3232. Custom Break ~F?\0\
  3233. Fake ~9²\0\
  3234. Carpet ~4±\0\
  3235. Floor ~6°\0\
  3236. Tiles ~0þ\0\
  3237. Custom Floor ~F?\0\
  3238. Web ~7Å\0\
  3239. Thick Web ~7Î\0\
  3240. Forest ~2²\0\
  3241. Invis. Wall ~1 ",
  3242. //Item (F4)
  3243. "Gem ~A\0\
  3244. Magic Gem ~E\0\
  3245. Health ~C\0\
  3246. Ring ~E\x9\0\
  3247. Potion ~B–\0\
  3248. Energizer ~D\0\
  3249. Ammo ~3¤\0\
  3250. Bomb ~8 \0\
  3251. Key ~F \0\
  3252. Lock ~F\xA\0\
  3253. Coin ~E\0\
  3254. Life ~B›\0\
  3255. Pouch ~7Ÿ\0\
  3256. Chest ~6 ",
  3257. //Creature (F5)
  3258. "Snake ~2ë\0\
  3259. Eye ~Fì\0\
  3260. Thief ~C\0\
  3261. Slime Blob ~A*\0\
  3262. Runner ~4\0\
  3263. Ghost ~7ê\0\
  3264. Dragon ~4\0\
  3265. Fish ~Eà\0\
  3266. Shark ~7\0\
  3267. Spider ~7•\0\
  3268. Goblin ~D\0\
  3269. Spitting Tiger ~Bã\0\
  3270. Bear ~6¬\0\
  3271. Bear Cub ~6­\0\
  3272. Lazer Gun ~4Î\0\
  3273. Bullet Gun ~F\0\
  3274. Spinning Gun ~F\0\
  3275. Missile Gun ~8",
  3276. //Puzzle (F6)
  3277. "Boulder ~7é\0\
  3278. Crate ~6þ\0\
  3279. Custom Push ~F?\0\
  3280. Box ~Eþ\0\
  3281. Custom Box ~F?\0\
  3282. Pusher ~D\0\
  3283. Slider NS ~D\0\
  3284. Slider EW ~D",
  3285. //Tranport (F7)
  3286. "Stairs ~A¢\0\
  3287. Cave ~6¡\0\
  3288. Transport ~E<\0\
  3289. Whirlpool ~B—\0\
  3290. CWRotate ~9/\0\
  3291. CCWRotate ~9\\",
  3292. //Element (F8)
  3293. "Still Water ~9°\0\
  3294. N Water ~9\x18\0\
  3295. S Water ~9\x19\0\
  3296. E Water ~9\x1A\0\
  3297. W Water ~9\x1B\0\
  3298. Ice ~Bý\0\
  3299. Lava ~C²\0\
  3300. Fire ~E±\0\
  3301. Goop ~8°\0\
  3302. Lit Bomb ~8«\0\
  3303. Explosion ~E±",
  3304. //Misc (F9)
  3305. "Door ~6Ä\0\
  3306. Gate ~8\0\
  3307. Ricochet Panel ~9/\0\
  3308. Ricochet ~A*\0\
  3309. Mine ~C�\0\
  3310. Spike ~8\0\
  3311. Custom Hurt ~F?\0\
  3312. Text ~F?\0\
  3313. N Moving Wall ~F?\0\
  3314. S Moving Wall ~F?\0\
  3315. E Moving Wall ~F?\0\
  3316. W Moving Wall ~F?",
  3317. //Objects (F10)
  3318. "Robot ~F?\0\
  3319. Pushable Robot ~F?\0\
  3320. Player ~B\0\
  3321. Scroll ~Fè\0\
  3322. Sign ~6â\0\
  3323. Sensor ~F?\0\
  3324. Bullet ~Fù\0\
  3325. Missile ~8\0\
  3326. Seeker ~A/\0\
  3327. Shooting Fire ~E" };
  3328. char tmenu_thing_ids[8][18]={
  3329. //Terrain (F3)
  3330. { 0,1,2,3,4,5,6,7,13,14,15,16,17,18,19,65,71 },
  3331. //Item (F4)
  3332. { 28,29,30,31,32,33,35,36,39,40,50,66,55,27 },
  3333. //Creature (F5)
  3334. { 80,81,82,83,84,85,86,87,88,89,90,91,94,95,60,92,93,97 },
  3335. //Puzzle (F6)
  3336. { 8,9,10,11,12,56,57,58 },
  3337. //Tranport (F7)
  3338. { 43,44,49,67,45,46 },
  3339. //Element (F8)
  3340. { 20,21,22,23,24,25,26,63,34,37,38 },
  3341. //Misc (F9)
  3342. { 41,47,72,73,74,75,76,77,51,52,53,54 },
  3343. //Objects (F10)
  3344. { 124,123,127,126,125,122,61,62,79,78 } };
  3345. //Default colors
  3346. unsigned char def_colors[128]={
  3347. 7,0,0,10,0,0,0,0,7,6,0,0,0,0,0,0,0,0,7,7,25,25,25,25,25,59,76,6,0,0,12,14,//0-31
  3348. 11,15,24,3,8,8,239,0,0,0,0,0,0,0,0,8,8,0,14,0,0,0,0,7,0,0,0,0,4,15,8,12,//32-63
  3349. 0,2,11,31,31,31,31,0,9,10,12,8,0,0,14,10,2,15,12,10,4,7,4,14,7,7,2,11,15,15,6,6,//64-95
  3350. 0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,15,27 };//96-127
  3351. void draw_debug_box(char ypos) {
  3352. int t1;
  3353. draw_window_box(debug_x,ypos,debug_x+14,24,current_pg_seg,
  3354. EC_DEBUG_BOX,EC_DEBUG_BOX_DARK,EC_DEBUG_BOX_CORNER,0);
  3355. write_string("X/Y: /\nBoard:\nMem: k\nEMS: k\nRobot memory-\n . /61k %",
  3356. debug_x+1,ypos+1,EC_DEBUG_LABEL,current_pg_seg);
  3357. write_number(curr_board,EC_DEBUG_NUMBER,debug_x+13,ypos+2,
  3358. current_pg_seg,0,1);
  3359. write_number((int)(farcoreleft()>>10),EC_DEBUG_NUMBER,
  3360. debug_x+12,ypos+3,current_pg_seg,0,1);
  3361. write_number(free_mem_EMS()<<4,EC_DEBUG_NUMBER,debug_x+12,ypos+4,
  3362. current_pg_seg,0,1);
  3363. t1=robot_free_mem/102;
  3364. write_number(t1/10,EC_DEBUG_NUMBER,debug_x+2,ypos+6,current_pg_seg,
  3365. 0,1);
  3366. write_number(t1%10,EC_DEBUG_NUMBER,debug_x+4,ypos+6,current_pg_seg,1);
  3367. t1=(unsigned int)(robot_free_mem*100L/62464L);
  3368. write_number(t1,EC_DEBUG_NUMBER,debug_x+12,ypos+6,current_pg_seg,0,1);
  3369. }