edit.cpp 107 KB

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