EDIT3D.CPP 118 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502
  1. #include <string.h>
  2. #include <stdio.h>
  3. #include "typedefs.h"
  4. #include "engine.h"
  5. #include "debug4g.h"
  6. #include "bstub.h"
  7. #include "misc.h"
  8. #include "gameutil.h"
  9. #include "build.h"
  10. #include "trig.h"
  11. #include "names.h"
  12. #include "db.h"
  13. #include "tile.h"
  14. #include "screen.h"
  15. #include "gui.h"
  16. #include "key.h"
  17. #include "globals.h"
  18. #include "gfx.h"
  19. #include "mouse.h"
  20. #include "sectorfx.h"
  21. typedef void HSECTORFUNC( short nSector );
  22. typedef void HSPRITEFUNC( SPRITE *pSprite );
  23. /*******************************************************************************
  24. Defines
  25. *******************************************************************************/
  26. #define kPlayerRadius 200
  27. #define kMaxVisited 8192 // set to larger of kMaxSectors and kMaxWalls
  28. /*******************************************************************************
  29. Local Variables
  30. *******************************************************************************/
  31. static char buffer[256] = "";
  32. static char *gZModeMsg[3] =
  33. {
  34. "Gravity",
  35. "Locked/Step",
  36. "Locked/Free"
  37. };
  38. static BOOL visited[kMaxVisited];
  39. static int gStep;
  40. static ushort WallShadeFrac[kMaxWalls];
  41. static ushort FloorShadeFrac[kMaxSectors];
  42. static ushort CeilShadeFrac[kMaxSectors];
  43. static int WallArea[kMaxWalls];
  44. static int SectorArea[kMaxSectors];
  45. static int WallNx[kMaxWalls], WallNy[kMaxWalls];
  46. static int FloorNx[kMaxSectors], FloorNy[kMaxSectors], FloorNz[kMaxSectors];
  47. static int CeilNx[kMaxSectors], CeilNy[kMaxSectors], CeilNz[kMaxSectors];
  48. /*******************************************************************************
  49. These are globals that should be referenced in other parts of build.c.
  50. Ken should ADD these to BUILD and make them non-static.
  51. *******************************************************************************/
  52. char tempvisibility = 0;
  53. /***********************************************************************
  54. * SetCeilingZ()
  55. *
  56. * Change the z of a sector ceiling and all sprites on the ceiling
  57. **********************************************************************/
  58. static void SetCeilingZ( int nSector, long z )
  59. {
  60. dassert(nSector >= 0 && nSector < kMaxSectors);
  61. // don't allow to go through the floor
  62. z = ClipHigh(z, sector[nSector].floorz);
  63. for (int i = headspritesect[searchsector]; i != -1; i = nextspritesect[i])
  64. {
  65. int zTop, zBot;
  66. SPRITE *pSprite = &sprite[i];
  67. GetSpriteExtents(pSprite, &zTop, &zBot);
  68. if ( zTop <= getceilzofslope((short)nSector, pSprite->x, pSprite->y) )
  69. pSprite->z += z - sector[nSector].ceilingz;
  70. }
  71. sector[nSector].ceilingz = z;
  72. }
  73. /***********************************************************************
  74. * SetFloorZ()
  75. *
  76. * Change the z of a sector floor and all sprites on the floor
  77. **********************************************************************/
  78. static void SetFloorZ( int nSector, long z )
  79. {
  80. dassert(nSector >= 0 && nSector < kMaxSectors);
  81. // don't allow to go through the ceiling
  82. z = ClipLow(z, sector[nSector].ceilingz);
  83. for (int i = headspritesect[searchsector]; i != -1; i = nextspritesect[i])
  84. {
  85. int zTop, zBot;
  86. SPRITE *pSprite = &sprite[i];
  87. GetSpriteExtents(pSprite, &zTop, &zBot);
  88. if (zBot >= getflorzofslope((short)nSector, pSprite->x, pSprite->y) )
  89. pSprite->z += z - sector[nSector].floorz;
  90. }
  91. sector[nSector].floorz = z;
  92. }
  93. /***********************************************************************
  94. * SetCeilingSlope()
  95. *
  96. * Change the slope of a sector ceiling and all sprites on the ceiling
  97. **********************************************************************/
  98. static void SetCeilingSlope( short nSector, short nSlope )
  99. {
  100. dassert(nSector >= 0 && nSector < kMaxSectors);
  101. sector[nSector].ceilingslope = nSlope;
  102. if ( sector[nSector].ceilingslope == 0 )
  103. sector[nSector].ceilingstat &= ~kSectorSloped;
  104. else
  105. sector[nSector].ceilingstat |= kSectorSloped;
  106. for (int i = headspritesect[searchsector]; i != -1; i = nextspritesect[i])
  107. {
  108. SPRITE *pSprite = &sprite[i];
  109. int zTop, zBot;
  110. GetSpriteExtents(pSprite, &zTop, &zBot);
  111. long z = getceilzofslope(nSector, pSprite->x, pSprite->y);
  112. if ( zTop < z )
  113. sprite[i].z += z - zTop;
  114. }
  115. }
  116. /***********************************************************************
  117. * SetFloorSlope()
  118. *
  119. * Change the slope of a sector floor and all sprites on the floor
  120. **********************************************************************/
  121. static void SetFloorSlope( short nSector, short nSlope )
  122. {
  123. dassert(nSector >= 0 && nSector < kMaxSectors);
  124. sector[nSector].floorslope = nSlope;
  125. if ( sector[nSector].floorslope == 0 )
  126. sector[nSector].floorstat &= ~kSectorSloped;
  127. else
  128. sector[nSector].floorstat |= kSectorSloped;
  129. for (int i = headspritesect[searchsector]; i != -1; i = nextspritesect[i])
  130. {
  131. SPRITE *pSprite = &sprite[i];
  132. int zTop, zBot;
  133. GetSpriteExtents(pSprite, &zTop, &zBot);
  134. long z = getflorzofslope(nSector, pSprite->x, pSprite->y);
  135. if ( zBot > z )
  136. sprite[i].z += z - zBot;
  137. }
  138. }
  139. /***********************************************************************
  140. * IsSectorHighlight()
  141. *
  142. * Determines if a sector is in the sector highlight list
  143. **********************************************************************/
  144. static BOOL IsSectorHighlight( int nSector )
  145. {
  146. dassert(nSector >= 0 && nSector < kMaxSectors);
  147. for (int i = 0; i < highlightsectorcnt; i++)
  148. if (highlightsector[i] == nSector)
  149. return TRUE;
  150. return FALSE;
  151. }
  152. inline int NextCCW( int nWall )
  153. {
  154. dassert( wall[nWall].nextwall >= 0 );
  155. return wall[wall[nWall].nextwall].point2;
  156. }
  157. /*******************************************************************************
  158. FUNCTION: GetWallZPeg()
  159. DESCRIPTION: Calculate the z position that the wall texture is relative
  160. to.
  161. *******************************************************************************/
  162. inline int GetWallZPeg( int nWall )
  163. {
  164. dassert(nWall >= 0 && nWall < kMaxWalls);
  165. int z;
  166. int nSector = sectorofwall((short)nWall);
  167. dassert(nSector >= 0 && nSector < kMaxSectors);
  168. int nNextSector = wall[nWall].nextsector;
  169. if (nNextSector == -1)
  170. {
  171. // one sided wall
  172. if ( wall[nWall].cstat & kWallBottomOrg )
  173. z = sector[nSector].floorz;
  174. else
  175. z = sector[nSector].ceilingz;
  176. }
  177. else
  178. {
  179. // two sided wall
  180. if ( wall[nWall].cstat & kWallOutsideOrg )
  181. z = sector[nSector].ceilingz;
  182. else
  183. {
  184. // top step
  185. if (sector[nNextSector].ceilingz > sector[nSector].ceilingz)
  186. z = sector[nNextSector].ceilingz;
  187. // bottom step
  188. if (sector[nNextSector].floorz < sector[nSector].floorz)
  189. z = sector[nNextSector].floorz;
  190. }
  191. }
  192. return z;
  193. }
  194. static void AlignWalls( int nWall0, int z0, int nWall1, int z1, int nTile )
  195. {
  196. dassert(nWall0 >= 0 && nWall0 < kMaxWalls);
  197. dassert(nWall1 >= 0 && nWall1 < kMaxWalls);
  198. dprintf("¯%d", nWall1);
  199. // do the x alignment
  200. wall[nWall1].cstat &= ~kWallFlipMask; // set to non-flip
  201. wall[nWall1].xpanning = (uchar)((wall[nWall0].xpanning + (wall[nWall0].xrepeat << 3)) % tilesizx[nTile]);
  202. z1 = GetWallZPeg(nWall1);
  203. int n = picsiz[nTile] >> 4;
  204. if ( (1 << n) != tilesizy[nTile] )
  205. n++;
  206. wall[nWall1].yrepeat = wall[nWall0].yrepeat;
  207. wall[nWall1].ypanning = (uchar)(wall[nWall0].ypanning + (((z1 - z0) * wall[nWall0].yrepeat) >> (n + 3)));
  208. }
  209. #define kMaxAlign 64
  210. static void AutoAlignWalls( int nWall0, int ply = 0 )
  211. {
  212. dassert(nWall0 >= 0 && nWall0 < kMaxWalls);
  213. int z0, z1;
  214. int nTile = wall[nWall0].picnum;
  215. int nWall1;
  216. int branch = 0;
  217. if ( ply == kMaxAlign )
  218. {
  219. dprintf("\nAlignment aborted by ply -- possible node problem!\n");
  220. return;
  221. }
  222. if ( ply == 0 )
  223. {
  224. // clear visited bits
  225. memset(visited, FALSE, sizeof(visited));
  226. visited[nWall0] = TRUE;
  227. dprintf("Aligning walls: %d", nWall0);
  228. }
  229. z0 = GetWallZPeg(nWall0);
  230. nWall1 = wall[nWall0].point2;
  231. dassert(nWall1 >= 0 && nWall1 < kMaxWalls);
  232. // loop through walls at this vertex in CCW order
  233. while (1)
  234. {
  235. // break if this wall would connect us in a loop
  236. if ( visited[nWall1] )
  237. break;
  238. visited[nWall1] = TRUE;
  239. // break if reached back of left wall
  240. if ( wall[nWall1].nextwall == nWall0 )
  241. break;
  242. if ( wall[nWall1].picnum == nTile )
  243. {
  244. z1 = GetWallZPeg(nWall1);
  245. BOOL visible = FALSE;
  246. int nNextSector = wall[nWall1].nextsector;
  247. if ( nNextSector < 0 )
  248. visible = TRUE;
  249. else
  250. {
  251. // ignore two sided walls that have no visible face
  252. int nSector = wall[wall[nWall1].nextwall].nextsector;
  253. if ( getceilzofslope((short)nSector, wall[nWall1].x, wall[nWall1].y) <
  254. getceilzofslope((short)nNextSector, wall[nWall1].x, wall[nWall1].y) )
  255. visible = TRUE;
  256. if ( getflorzofslope((short)nSector, wall[nWall1].x, wall[nWall1].y) >
  257. getflorzofslope((short)nNextSector, wall[nWall1].x, wall[nWall1].y) )
  258. visible = TRUE;
  259. }
  260. if ( visible )
  261. {
  262. if ( branch++ )
  263. dprintf(" %d", nWall0);
  264. AlignWalls(nWall0, z0, nWall1, z1, nTile);
  265. int nNextWall = wall[nWall1].nextwall;
  266. // if wall was 1-sided, no need to recurse
  267. if ( nNextWall < 0 )
  268. {
  269. nWall0 = nWall1;
  270. z0 = GetWallZPeg(nWall0);
  271. nWall1 = wall[nWall0].point2;
  272. branch = 0;
  273. continue;
  274. }
  275. else
  276. {
  277. if ( wall[nWall1].cstat & kWallBottomSwap && wall[nNextWall].picnum == nTile )
  278. AlignWalls(nWall0, z0, nNextWall, z1, nTile);
  279. AutoAlignWalls(nWall1, ply + 1);
  280. }
  281. }
  282. }
  283. if (wall[nWall1].nextwall < 0)
  284. break;
  285. nWall1 = wall[wall[nWall1].nextwall].point2;
  286. }
  287. if ( ply == 0 )
  288. dprintf("\n");
  289. }
  290. static void BuildStairsF( int nSector )
  291. {
  292. int i, j;
  293. dassert(nSector >= 0 && nSector < kMaxSectors);
  294. // mark this sector as visited
  295. visited[nSector] = TRUE;
  296. for (i = 0; i < sector[nSector].wallnum; i++)
  297. {
  298. j = wall[sector[nSector].wallptr + i].nextsector;
  299. if (j != -1)
  300. {
  301. if ( IsSectorHighlight(j) && !visited[j] )
  302. {
  303. SetFloorZ(j, sector[nSector].floorz - (gStairHeight << 8));
  304. BuildStairsF(j);
  305. }
  306. }
  307. }
  308. }
  309. static void BuildStairsC( int nSector )
  310. {
  311. int i, j;
  312. dassert(nSector >= 0 && nSector < kMaxSectors);
  313. // mark this sector as visited
  314. visited[nSector] = TRUE;
  315. for (i = 0; i < sector[nSector].wallnum; i++)
  316. {
  317. j = wall[sector[nSector].wallptr + i].nextsector;
  318. if (j != -1)
  319. {
  320. if ( IsSectorHighlight(j) && !visited[j] )
  321. {
  322. SetCeilingZ(j, sector[nSector].ceilingz - (gStairHeight << 8));
  323. BuildStairsC(j);
  324. }
  325. }
  326. }
  327. }
  328. static void ShootRay(int x, int y, int z, short nSector, int dx, int dy, int dz, int nIntensity, int nReflect, int dist)
  329. {
  330. short hitsect = -1, hitwall = -1, hitsprite = -1;
  331. long hitx, hity, hitz;
  332. int x2, y2, z2;
  333. int dotProduct;
  334. int E;
  335. hitscan(x, y, z, nSector, dx, dy, dz << 4, &hitsect, &hitwall, &hitsprite, &hitx, &hity, &hitz);
  336. x2 = qabs(x - hitx) >> 4;
  337. y2 = qabs(y - hity) >> 4;
  338. z2 = qabs(z - hitz) >> 8;
  339. dist += ksqrt(x2 * x2 + y2 * y2 + z2 * z2);
  340. if (hitwall >= 0)
  341. {
  342. E = divscale16(nIntensity, ClipLow(dist + gLBRampDist, 1));
  343. if (E <= 0)
  344. return; // too small to deal with
  345. // distribute over area of wall
  346. E = divscale16(E, ClipLow(WallArea[hitwall], 1));
  347. int n = (wall[hitwall].shade << 16) | WallShadeFrac[hitwall];
  348. n -= E;
  349. wall[hitwall].shade = (schar)ClipLow(n >> 16, gLBMaxBright);
  350. WallShadeFrac[hitwall] = (ushort)(n & 0xFFFF);
  351. if ( nReflect < gLBReflections )
  352. {
  353. int Nx = WallNx[hitwall];
  354. int Ny = WallNy[hitwall];
  355. // dotProduct is cos of angle of intersection
  356. dotProduct = dmulscale16(dx, Nx, dy, Ny);
  357. if (dotProduct < 0)
  358. return; // bogus intersection
  359. // reflect vector
  360. dx -= mulscale16(2 * dotProduct, Nx);
  361. dy -= mulscale16(2 * dotProduct, Ny);
  362. hitx += dx >> 12;
  363. hity += dy >> 12;
  364. hitz += dz >> 8;
  365. nIntensity -= mulscale16(nIntensity, gLBAttenuation);
  366. ShootRay(hitx, hity, hitz, hitsect, dx, dy, dz, nIntensity, nReflect + 1, dist);
  367. }
  368. }
  369. else if (hitsprite >= 0)
  370. {
  371. }
  372. else if (dz > 0) // hit floor
  373. {
  374. E = divscale16(nIntensity, ClipLow(dist + gLBRampDist, 1));
  375. if (E <= 0)
  376. return; // too small to deal with
  377. // distribute over area of floor
  378. E = divscale16(E, ClipLow(SectorArea[hitsect], 1));
  379. int n = (sector[hitsect].floorshade << 16) | FloorShadeFrac[hitsect];
  380. n -= E;
  381. sector[hitsect].floorshade = (schar)ClipLow(n >> 16, gLBMaxBright);
  382. FloorShadeFrac[hitsect] = (ushort)(n & 0xFFFF);
  383. if ( nReflect < gLBReflections )
  384. {
  385. if ( sector[hitsect].floorstat & kSectorSloped )
  386. {
  387. int Nx = FloorNx[hitsect];
  388. int Ny = FloorNy[hitsect];
  389. int Nz = FloorNz[hitsect];
  390. // dotProduct is cos of angle of intersection
  391. dotProduct = tmulscale16(dx, Nx, dy, Ny, dz, Nz);
  392. if (dotProduct < 0)
  393. return; // bogus intersection
  394. dx -= mulscale16(2 * dotProduct, Nx);
  395. dy -= mulscale16(2 * dotProduct, Ny);
  396. dz -= mulscale16(2 * dotProduct, Nz);
  397. }
  398. else
  399. dz = -dz;
  400. nIntensity -= mulscale16(nIntensity, gLBAttenuation);
  401. hitx += dx >> 12;
  402. hity += dy >> 12;
  403. hitz += dz >> 8;
  404. ShootRay(hitx, hity, hitz, hitsect, dx, dy, dz, nIntensity, nReflect + 1, dist);
  405. }
  406. }
  407. else // hit ceiling
  408. {
  409. E = divscale16(nIntensity, ClipLow(dist + gLBRampDist, 1));
  410. if (E <= 0)
  411. return; // too small to deal with
  412. // distribute over area of ceiling
  413. E = divscale16(E, ClipLow(SectorArea[hitsect], 1));
  414. int n = (sector[hitsect].ceilingshade << 16) | CeilShadeFrac[hitsect];
  415. n -= E;
  416. sector[hitsect].ceilingshade = (schar)ClipLow(n >> 16, gLBMaxBright);
  417. CeilShadeFrac[hitsect] = (ushort)(n & 0xFFFF);
  418. if ( nReflect < gLBReflections )
  419. {
  420. // reflect vector
  421. if ( sector[hitsect].ceilingstat & kSectorSloped )
  422. {
  423. int Nx = CeilNx[hitsect];
  424. int Ny = CeilNy[hitsect];
  425. int Nz = CeilNz[hitsect];
  426. // dotProduct is cos of angle of intersection
  427. dotProduct = tmulscale16(dx, Nx, dy, Ny, dz, Nz);
  428. if (dotProduct < 0)
  429. return; // bogus intersection
  430. dx -= mulscale16(2 * dotProduct, Nx);
  431. dy -= mulscale16(2 * dotProduct, Ny);
  432. dz -= mulscale16(2 * dotProduct, Nz);
  433. }
  434. else
  435. dz = -dz;
  436. nIntensity -= mulscale16(nIntensity, gLBAttenuation);
  437. hitx += dx >> 12;
  438. hity += dy >> 12;
  439. hitz += dz >> 8;
  440. ShootRay(hitx, hity, hitz, hitsect, dx, dy, dz, nIntensity, nReflect + 1, dist);
  441. }
  442. }
  443. }
  444. static int AreaOfSector( SECTOR *pSector )
  445. {
  446. int area = 0;
  447. int startwall = pSector->wallptr;
  448. int endwall = startwall + pSector->wallnum;
  449. for (int i = startwall; i < endwall; i++)
  450. {
  451. int x1 = wall[i].x >> 4;
  452. int y1 = wall[i].y >> 4;
  453. int x2 = wall[wall[i].point2].x >> 4;
  454. int y2 = wall[wall[i].point2].y >> 4;
  455. area += (x1+x2) * (y2-y1); // add area of this trapezoid
  456. }
  457. area >>= 1;
  458. return area;
  459. }
  460. static void SetupLightBomb( void )
  461. {
  462. SECTOR *pSector;
  463. WALL *pWall;
  464. int nSector, nWall;
  465. pSector = &sector[0];
  466. for ( nSector = 0; nSector < numsectors; nSector++, pSector++ )
  467. {
  468. FloorShadeFrac[nSector] = 0;
  469. CeilShadeFrac[nSector] = 0;
  470. SectorArea[nSector] = AreaOfSector(pSector);
  471. pWall = &wall[pSector->wallptr];
  472. for (nWall = pSector->wallptr; nWall < pSector->wallptr + pSector->wallnum; nWall++, pWall++)
  473. {
  474. WallShadeFrac[nWall] = 0;
  475. int Nx, Ny;
  476. // calculate normal for wall
  477. Nx = (wall[pWall->point2].y - pWall->y) >> 4;
  478. Ny = -(wall[pWall->point2].x - pWall->x) >> 4;
  479. int length = ksqrt(Nx * Nx + Ny * Ny);
  480. WallNx[nWall] = divscale16(Nx, length);
  481. WallNy[nWall] = divscale16(Ny, length);
  482. long ceilZ, ceilZ1, ceilZ2, floorZ, floorZ1, floorZ2;
  483. getzsofslope((short)nSector, pWall->x, pWall->y, &ceilZ1, &floorZ1);
  484. getzsofslope((short)nSector, wall[pWall->point2].x, wall[pWall->point2].y, &ceilZ2, &floorZ2);
  485. ceilZ = (ceilZ1 + ceilZ2) >> 1;
  486. floorZ = (floorZ1 + floorZ2) >> 1;
  487. // calculate the area of the wall
  488. int height = floorZ - ceilZ;
  489. // red wall?
  490. if ( pWall->nextsector >= 0 )
  491. {
  492. height = 0;
  493. long nextCeilZ, nextCeilZ1, nextCeilZ2, nextFloorZ, nextFloorZ1, nextFloorZ2;
  494. getzsofslope(pWall->nextsector, pWall->x, pWall->y, &nextCeilZ1, &nextFloorZ1);
  495. getzsofslope(pWall->nextsector, wall[pWall->point2].x, wall[pWall->point2].y, &nextCeilZ2, &nextFloorZ2);
  496. nextCeilZ = (nextCeilZ1 + nextCeilZ2) >> 1;
  497. nextFloorZ = (nextFloorZ1 + nextFloorZ2) >> 1;
  498. // floor step up?
  499. if ( nextFloorZ < floorZ)
  500. height += floorZ - nextFloorZ;
  501. // ceiling step down?
  502. if ( nextCeilZ > ceilZ )
  503. height += nextCeilZ - ceilZ;
  504. }
  505. WallArea[nWall] = length * height >> 8;
  506. }
  507. FloorNx[nSector] = 0;
  508. FloorNy[nSector] = 0;
  509. FloorNz[nSector] = -0x10000;
  510. CeilNx[nSector] = 0;
  511. CeilNy[nSector] = 0;
  512. CeilNz[nSector] = 0x10000;
  513. }
  514. }
  515. static void LightBomb( int x, int y, int z, short nSector )
  516. {
  517. int dx, dy, dz;
  518. for (int a = kAngle90 - kAngle60; a <= kAngle90 + kAngle60; a += kAngle15)
  519. {
  520. for (int i = 0; i < kAngle360; i += kAngle360 / 256)
  521. {
  522. dx = mulscale30(Cos(i), Sin(a)) >> 16;
  523. dy = mulscale30(Sin(i), Sin(a)) >> 16;
  524. dz = Cos(a) >> 16;
  525. ShootRay(x, y, z, nSector, dx, dy, dz, gLBIntensity, 0, 0);
  526. }
  527. }
  528. }
  529. static void SetFirstWall( int nSector, int nWall )
  530. {
  531. int start, length, shift;
  532. int i, j, k;
  533. WALL tempWall;
  534. // rotate the walls using the shift copy algorithm
  535. start = sector[nSector].wallptr;
  536. length = sector[nSector].wallnum;
  537. dassert(nWall >= start && nWall < start + length);
  538. shift = nWall - start;
  539. if (shift == 0)
  540. return;
  541. i = k = start;
  542. for (int n = length; n > 0; n--)
  543. {
  544. if (i == k)
  545. tempWall = wall[i];
  546. j = i + shift;
  547. while (j >= start + length)
  548. j -= length;
  549. if (j == k)
  550. {
  551. wall[i] = tempWall;
  552. i = ++k;
  553. continue;
  554. }
  555. wall[i] = wall[j];
  556. i = j;
  557. }
  558. for (i = start; i < start + length; i++)
  559. {
  560. if ( (wall[i].point2 -= shift) < start )
  561. wall[i].point2 += length;
  562. if ( wall[i].nextwall >= 0 )
  563. wall[wall[i].nextwall].nextwall = (short)i;
  564. }
  565. CleanUp();
  566. }
  567. static void TranslateWallToSector( void )
  568. {
  569. short hitsect = -1, hitwall = -1, hitsprite = -1;
  570. long hitx, hity, hitz;
  571. long x, y;
  572. x = 1 << 14;
  573. y = divscale(searchx - xdim / 2, xdim / 2, 14);
  574. RotateVector(&x, &y, ang);
  575. hitscan(posx, posy, posz, cursectnum, //Start position
  576. x, y, (searchy - horiz) * 2000, //vector of 3D ang
  577. &hitsect, &hitwall, &hitsprite, &hitx, &hity, &hitz);
  578. if (hitwall == searchwall) // front of wall?
  579. searchsector = wall[searchwall].nextsector;
  580. else if (hitwall == wall[searchwall].nextwall) // back of 2 texture wall?
  581. searchsector = wall[hitwall].nextsector;
  582. else
  583. {
  584. dprintf("Can't figure out what you are pointing at\n");
  585. return;
  586. }
  587. if (hitz > getflorzofslope(searchsector, hitx, hity))
  588. {
  589. searchstat = SS_FLOOR;
  590. }
  591. else
  592. {
  593. searchstat = SS_CEILING;
  594. }
  595. }
  596. /*******************************************************************************
  597. FUNCTION: InsertMisc()
  598. DESCRIPTION: Displays a tile menu allowing user to insert
  599. a miscellaneous game object.
  600. PARAMETERS:
  601. NOTES: This routine should offer a list box rather than tiles.
  602. *******************************************************************************/
  603. static BOOL InsertMisc( int where, int nSector, long x, long y, long z, int nAngle )
  604. {
  605. static short miscTiles[] =
  606. {
  607. kPicSwitch1Off,
  608. kPicSwitch2Off,
  609. kPicSwitch3Off,
  610. kPicSwitch4Off,
  611. kPicSwitch5Off,
  612. kPicSwitch6Off,
  613. kPicSwitch7Off,
  614. kPicWallCrack,
  615. kPicFluorescent,
  616. kPicGlass,
  617. kPicBlockWeb,
  618. kPicWoodBeam,
  619. // kPicMetalGrate1,
  620. kPicCrateFace,
  621. kPicVase1,
  622. kPicVase2,
  623. kPicStart1,
  624. kPicStart2,
  625. kPicStart3,
  626. kPicStart4,
  627. kPicStart5,
  628. kPicStart6,
  629. kPicStart7,
  630. kPicStart8,
  631. };
  632. short nType;
  633. short nStat = kStatDefault;
  634. tileIndexCount = LENGTH(miscTiles);
  635. for ( int i = 0; i < tileIndexCount; i++ )
  636. tileIndex[i] = miscTiles[i]; // gMiscInfo[i].picnum;
  637. short picnum = tilePick( -1 /*gMiscInfo[0].picnum*/, -1, SS_CUSTOM );
  638. if ( picnum == -1 )
  639. return FALSE;
  640. switch( picnum )
  641. {
  642. case kPicSwitch1Off:
  643. case kPicSwitch2Off:
  644. case kPicSwitch3Off:
  645. case kPicSwitch4Off:
  646. case kPicSwitch5Off:
  647. case kPicSwitch6Off:
  648. case kPicSwitch7Off:
  649. nType = kSwitchToggle;
  650. break;
  651. case kPicWallCrack:
  652. nType = kThingWallCrack;
  653. break;
  654. case kPicFluorescent:
  655. nType = kThingFluorescent;
  656. break;
  657. case kPicGlass:
  658. nType = kThingClearGlass;
  659. break;
  660. case kPicBlockWeb:
  661. nType = kThingWeb;
  662. break;
  663. case kPicWoodBeam:
  664. nType = kThingWoodBeam;
  665. break;
  666. // case kPicMetalGrate1:
  667. // nType = kThingMetalGrate1;
  668. // break;
  669. case kPicCrateFace:
  670. nType = kThingCrateFace;
  671. break;
  672. case kPicVase1:
  673. nType = kThingBlueVase;
  674. break;
  675. case kPicVase2:
  676. nType = kThingBrownVase;
  677. break;
  678. case kPicStart1:
  679. case kPicStart2:
  680. case kPicStart3:
  681. case kPicStart4:
  682. case kPicStart5:
  683. case kPicStart6:
  684. case kPicStart7:
  685. case kPicStart8:
  686. nType = kMarkerPlayerStart;
  687. break;
  688. }
  689. int nSprite = insertsprite( (short)nSector, nStat );
  690. dassert( nSprite >= 0 && nSprite < kMaxSprites );
  691. sprite[nSprite].type = nType;
  692. switch( picnum )
  693. {
  694. case kPicStart1:
  695. case kPicStart2:
  696. case kPicStart3:
  697. case kPicStart4:
  698. case kPicStart5:
  699. case kPicStart6:
  700. case kPicStart7:
  701. case kPicStart8:
  702. {
  703. int nXSprite = GetXSprite( nSprite );
  704. dassert(nXSprite > 0 && nXSprite < kMaxXSprites);
  705. xsprite[nXSprite].data1 = picnum - kPicStart1;
  706. break;
  707. }
  708. }
  709. AutoAdjustSprites();
  710. SPRITE *pSprite = &sprite[nSprite];
  711. pSprite->x = x;
  712. pSprite->y = y;
  713. pSprite->z = z;
  714. pSprite->ang = (short)nAngle;
  715. pSprite->shade = -8;
  716. int zTop, zBot;
  717. GetSpriteExtents(pSprite, &zTop, &zBot);
  718. if ( where == SS_FLOOR)
  719. pSprite->z += getflorzofslope((short)nSector, pSprite->x, pSprite->y) - zBot;
  720. else
  721. pSprite->z += getceilzofslope((short)nSector, pSprite->x, pSprite->y) - zTop;
  722. updatenumsprites();
  723. BeepOkay();
  724. return TRUE;
  725. }
  726. /*******************************************************************************
  727. FUNCTION: InsertHazard()
  728. DESCRIPTION: Displays a tile menu allowing user to insert a hazard.
  729. PARAMETERS:
  730. NOTES: This routine should offer a list box rather than tiles.
  731. *******************************************************************************/
  732. static BOOL InsertHazard( int where, int nSector, long x, long y, long z, int nAngle )
  733. {
  734. static short hazardTiles[] =
  735. {
  736. kAnmCircSaw1,
  737. kAnmTNTProxArmed,
  738. kPicTNTBarrel,
  739. kAnmFloorSpike,
  740. kAnmPendulum,
  741. kPicGuillotine,
  742. kAnmElectrify,
  743. kPicMachineGun,
  744. };
  745. short nType;
  746. short nStat = kStatDefault;
  747. tileIndexCount = LENGTH(hazardTiles);
  748. for ( int i = 0; i < tileIndexCount; i++ )
  749. tileIndex[i] = hazardTiles[i]; // gItemInfo[i].picnum;
  750. short picnum = tilePick( -1 /*gHazardInfo[0].picnum*/, -1, SS_CUSTOM );
  751. if ( picnum == -1 )
  752. return FALSE;
  753. switch( picnum )
  754. {
  755. case kAnmCircSaw1:
  756. nType = kTrapSawBlade;
  757. break;
  758. case kAnmTNTProxArmed:
  759. nType = kThingTNTProxArmed;
  760. nStat = kStatProximity;
  761. break;
  762. case kPicTNTBarrel:
  763. nType = kThingTNTBarrel;
  764. break;
  765. // case kAnmRollBarrel:
  766. // nType = kThingTNTBarrel;
  767. // break;
  768. case kAnmFloorSpike:
  769. nType = kTrapSpiketrap;
  770. break;
  771. case kAnmPendulum:
  772. nType = kTrapPendulum;
  773. break;
  774. case kPicGuillotine:
  775. nType = kTrapGuillotine;
  776. break;
  777. case kAnmElectrify:
  778. nType = kTrapPoweredZap;
  779. break;
  780. case kPicMachineGun:
  781. nType = kThingMachineGun;
  782. break;
  783. default:
  784. scrSetMessage("Invalid hazard tile selected!");
  785. BeepError();
  786. return FALSE;
  787. }
  788. int nSprite = insertsprite( (short)nSector, nStat );
  789. dassert( nSprite >= 0 && nSprite < kMaxSprites );
  790. sprite[nSprite].type = nType;
  791. AutoAdjustSprites();
  792. SPRITE *pSprite = &sprite[nSprite];
  793. pSprite->x = x;
  794. pSprite->y = y;
  795. pSprite->z = z;
  796. pSprite->ang = (short)nAngle;
  797. pSprite->shade = -8;
  798. int zTop, zBot;
  799. GetSpriteExtents(pSprite, &zTop, &zBot);
  800. if ( where == SS_FLOOR)
  801. pSprite->z += getflorzofslope((short)nSector, pSprite->x, pSprite->y) - zBot;
  802. else
  803. pSprite->z += getceilzofslope((short)nSector, pSprite->x, pSprite->y) - zTop;
  804. updatenumsprites();
  805. BeepOkay();
  806. return TRUE;
  807. }
  808. /*******************************************************************************
  809. FUNCTION: InsertItem()
  810. DESCRIPTION: Displays a tile menu allowing user to insert an item
  811. on the floor.
  812. PARAMETERS:
  813. NOTES: This routine should offer a list box rather than tiles.
  814. *******************************************************************************/
  815. static BOOL InsertItem( int where, int nSector, long x, long y, long z, int nAngle )
  816. {
  817. static short itemTiles[] =
  818. {
  819. kPicKey1, //kItemKey1
  820. kPicKey2, //kItemKey2
  821. kPicKey3, //kItemKey3
  822. kPicKey4, //kItemKey4
  823. kPicKey5, //kItemKey5
  824. kPicKey6, //kItemKey6
  825. kPicDocBag, //kItemDoctorBag
  826. kPicMedPouch, //kItemMedPouch
  827. kPicEssence, //kItemLifeEssence
  828. kAnmLifeSeed, //kItemLifeSeed
  829. kPicPotion, //kItemPotion1
  830. kAnmFeather, //kItemFeatherFall
  831. kAnmInviso, //kItemLtdInvisibility
  832. kPicInvulnerable, //kItemInvulnerability
  833. kPicJumpBoots, //kItemJumpBoots
  834. kPicRavenFlight, //kItemRavenFlight
  835. kPicGunsAkimbo, //kItemGunsAkimbo
  836. kPicDivingSuit, //kItemDivingSuit
  837. kPicGasMask, //kItemGasMask
  838. kAnmClone, //kItemClone
  839. kPicCrystalBall, //kItemCrystalBall
  840. kPicDecoy, //kItemDecoy
  841. kAnmDoppleganger, //kItemDoppleganger
  842. kAnmReflectShots, //kItemReflectiveShots
  843. kPicRoseGlasses, //kItemRoseGlasses
  844. kAnmCloakNDagger, //kItemShadowCloak
  845. kPicShroom1, //kItemShroomRage
  846. kPicShroom2, //kItemShroomDelirium
  847. kPicShroom3, //kItemShroomGrow
  848. kPicShroom4, //kItemShroomShrink
  849. kPicDeathMask, //kItemDeathMask
  850. kPicGoblet, //kItemWineGoblet
  851. kPicBottle1, //kItemWineBottle
  852. kPicSkullGrail, //kItemSkullGrail
  853. kPicSilverGrail, //kItemSilverGrail
  854. kPicTome1, //kItemTome
  855. kPicBlackChest, //kItemBlackChest
  856. kPicWoodChest, //kItemWoodenChest
  857. kPicAsbestosSuit, //kItemAsbestosArmor
  858. kPicRandomUp //kItemRandom
  859. };
  860. short nType;
  861. tileIndexCount = LENGTH(itemTiles);
  862. for ( int i = 0; i < tileIndexCount; i++ )
  863. tileIndex[i] = itemTiles[i]; // gItemInfo[i].picnum;
  864. short picnum = tilePick( -1 /*gItemInfo[0].picnum*/, -1, SS_CUSTOM );
  865. if ( picnum == -1 )
  866. return FALSE;
  867. switch( picnum )
  868. {
  869. case kPicKey1:
  870. nType = kItemKey1;
  871. break;
  872. case kPicKey2:
  873. nType = kItemKey2;
  874. break;
  875. case kPicKey3:
  876. nType = kItemKey3;
  877. break;
  878. case kPicKey4:
  879. nType = kItemKey4;
  880. break;
  881. case kPicKey5:
  882. nType = kItemKey5;
  883. break;
  884. case kPicKey6:
  885. nType = kItemKey6;
  886. break;
  887. case kPicDocBag:
  888. nType = kItemDoctorBag;
  889. break;
  890. case kPicMedPouch:
  891. nType = kItemMedPouch;
  892. break;
  893. case kPicEssence:
  894. nType = kItemLifeEssence;
  895. break;
  896. case kAnmLifeSeed:
  897. nType = kItemLifeSeed;
  898. break;
  899. case kPicPotion:
  900. nType = kItemPotion1;
  901. break;
  902. case kAnmFeather:
  903. nType = kItemFeatherFall;
  904. break;
  905. case kAnmInviso:
  906. nType = kItemLtdInvisibility;
  907. break;
  908. case kPicInvulnerable:
  909. nType = kItemInvulnerability;
  910. break;
  911. case kPicJumpBoots:
  912. nType = kItemJumpBoots;
  913. break;
  914. case kPicRavenFlight:
  915. nType = kItemRavenFlight;
  916. break;
  917. case kPicGunsAkimbo:
  918. nType = kItemGunsAkimbo;
  919. break;
  920. case kPicDivingSuit:
  921. nType = kItemDivingSuit;
  922. break;
  923. case kPicGasMask:
  924. nType = kItemGasMask;
  925. break;
  926. case kAnmClone:
  927. nType = kItemClone;
  928. break;
  929. case kPicCrystalBall:
  930. nType = kItemCrystalBall;
  931. break;
  932. case kPicDecoy:
  933. nType = kItemDecoy;
  934. break;
  935. case kAnmDoppleganger:
  936. nType = kItemDoppleganger;
  937. break;
  938. case kAnmReflectShots:
  939. nType = kItemReflectiveShots;
  940. break;
  941. case kPicRoseGlasses:
  942. nType = kItemRoseGlasses;
  943. break;
  944. case kAnmCloakNDagger:
  945. nType = kItemShadowCloak;
  946. break;
  947. case kPicShroom1:
  948. nType = kItemShroomRage;
  949. break;
  950. case kPicShroom2:
  951. nType = kItemShroomDelirium;
  952. break;
  953. case kPicShroom3:
  954. nType = kItemShroomGrow;
  955. break;
  956. case kPicShroom4:
  957. nType = kItemShroomShrink;
  958. break;
  959. case kPicDeathMask:
  960. nType = kItemDeathMask;
  961. break;
  962. case kPicGoblet:
  963. nType = kItemWineGoblet;
  964. break;
  965. case kPicBottle1:
  966. nType = kItemWineBottle;
  967. break;
  968. case kPicSkullGrail:
  969. nType = kItemSkullGrail;
  970. break;
  971. case kPicSilverGrail:
  972. nType = kItemSilverGrail;
  973. break;
  974. case kPicTome1:
  975. nType = kItemTome;
  976. break;
  977. case kPicBlackChest:
  978. nType = kItemBlackChest;
  979. break;
  980. case kPicWoodChest:
  981. nType = kItemWoodenChest;
  982. break;
  983. case kPicAsbestosSuit:
  984. nType = kItemAsbestosArmor;
  985. break;
  986. case kPicRandomUp:
  987. nType = kItemRandom;
  988. break;
  989. default:
  990. scrSetMessage("Invalid item tile selected!");
  991. BeepError();
  992. return FALSE;
  993. }
  994. int nSprite = insertsprite( (short)nSector, kStatItem );
  995. dassert( nSprite >= 0 && nSprite < kMaxSprites );
  996. sprite[nSprite].type = nType;
  997. AutoAdjustSprites();
  998. SPRITE *pSprite = &sprite[nSprite];
  999. pSprite->x = x;
  1000. pSprite->y = y;
  1001. pSprite->z = z;
  1002. pSprite->ang = (short)nAngle;
  1003. pSprite->shade = -8; // gItemInfo[nItemType].shade;
  1004. int zTop, zBot;
  1005. GetSpriteExtents(pSprite, &zTop, &zBot);
  1006. if ( where == SS_FLOOR)
  1007. pSprite->z += getflorzofslope((short)nSector, pSprite->x, pSprite->y) - zBot;
  1008. else
  1009. pSprite->z += getceilzofslope((short)nSector, pSprite->x, pSprite->y) - zTop;
  1010. updatenumsprites();
  1011. BeepOkay();
  1012. return TRUE;
  1013. }
  1014. /*******************************************************************************
  1015. FUNCTION: InsertAmmo()
  1016. DESCRIPTION: Displays a tile menu allowing user to insert an ammo
  1017. object on the floor.
  1018. PARAMETERS:
  1019. NOTES: This routine should offer a list box rather than tiles.
  1020. *******************************************************************************/
  1021. static BOOL InsertAmmo( int where, int nSector, long x, long y, long z, int nAngle )
  1022. {
  1023. static short ammoTiles[] =
  1024. {
  1025. kPicSpear,
  1026. kPicSpears,
  1027. kPicTNTStick,
  1028. kPicTNTPak,
  1029. kPicSprayCan,
  1030. kPicShotShells,
  1031. kPicTNTBox,
  1032. kPicTNTRemote,
  1033. kPicTNTProx,
  1034. kPicShellBox,
  1035. kPicBullets,
  1036. kPicBulletBox,
  1037. kPicBulletBoxAP,
  1038. kPicTommyDrum,
  1039. kPicFlares,
  1040. kPicFlareHE,
  1041. kPicFlareBurst,
  1042. kPicSpearExplode,
  1043. kPicRandomUp
  1044. };
  1045. short nType;
  1046. tileIndexCount = LENGTH(ammoTiles);
  1047. for ( int i = 0; i < tileIndexCount; i++ )
  1048. tileIndex[i] = ammoTiles[i]; // gAmmoInfo[i].picnum;
  1049. short picnum = tilePick( -1 /*gAmmoInfo[0].picnum*/, -1, SS_CUSTOM );
  1050. if ( picnum == -1 )
  1051. return FALSE;
  1052. switch( picnum )
  1053. {
  1054. case kPicSpear:
  1055. nType = kAmmoItemSpear;
  1056. break;
  1057. case kPicSpears:
  1058. nType = kAmmoItemSpearPack;
  1059. break;
  1060. case kPicTNTStick:
  1061. nType = kAmmoItemTNTStick;
  1062. break;
  1063. case kPicTNTPak:
  1064. nType = kAmmoItemTNTBundle;
  1065. break;
  1066. case kPicSprayCan:
  1067. nType = kAmmoItemSprayCan;
  1068. break;
  1069. case kPicShotShells:
  1070. nType = kAmmoItemShells;
  1071. break;
  1072. case kPicTNTBox:
  1073. nType = kAmmoItemTNTCase;
  1074. break;
  1075. case kPicTNTRemote:
  1076. nType = kAmmoItemTNTRemote;
  1077. break;
  1078. case kPicTNTProx:
  1079. nType = kAmmoItemTNTProximity;
  1080. break;
  1081. case kPicShellBox:
  1082. nType = kAmmoItemShellBox;
  1083. break;
  1084. case kPicBullets:
  1085. nType = kAmmoItemBullets;
  1086. break;
  1087. case kPicBulletBox:
  1088. nType = kAmmoItemBulletBox;
  1089. break;
  1090. case kPicBulletBoxAP:
  1091. nType = kAmmoItemAPBullets;
  1092. break;
  1093. case kPicTommyDrum:
  1094. nType = kAmmoItemTommyDrum;
  1095. break;
  1096. case kPicFlareHE:
  1097. nType = kAmmoItemHEFlares;
  1098. break;
  1099. case kPicFlareBurst:
  1100. nType = kAmmoItemStarFlares;
  1101. break;
  1102. case kPicSpearExplode:
  1103. nType = kAmmoItemHESpears;
  1104. break;
  1105. case kPicFlares:
  1106. nType = kAmmoItemFlares;
  1107. break;
  1108. case kPicRandomUp:
  1109. nType = kAmmoItemRandom;
  1110. break;
  1111. default:
  1112. scrSetMessage("Invalid ammo tile selected!");
  1113. BeepError();
  1114. return FALSE;
  1115. }
  1116. int nSprite = insertsprite( (short)nSector, kStatItem );
  1117. dassert( nSprite >= 0 && nSprite < kMaxSprites );
  1118. sprite[nSprite].type = nType;
  1119. AutoAdjustSprites();
  1120. SPRITE *pSprite = &sprite[nSprite];
  1121. pSprite->x = x;
  1122. pSprite->y = y;
  1123. pSprite->z = z;
  1124. pSprite->ang = (short)nAngle;
  1125. pSprite->shade = -8; // gAmmoInfo[nAmmoType].shade;
  1126. int zTop, zBot;
  1127. GetSpriteExtents(pSprite, &zTop, &zBot);
  1128. if ( where == SS_FLOOR)
  1129. pSprite->z += getflorzofslope((short)nSector, pSprite->x, pSprite->y) - zBot;
  1130. else
  1131. pSprite->z += getceilzofslope((short)nSector, pSprite->x, pSprite->y) - zTop;
  1132. updatenumsprites();
  1133. BeepOkay();
  1134. return TRUE;
  1135. }
  1136. /*******************************************************************************
  1137. FUNCTION: InsertWeapon()
  1138. DESCRIPTION: Displays a tile menu allowing user to insert a weapon
  1139. on the floor.
  1140. PARAMETERS:
  1141. NOTES: This routine should offer a list box rather than tiles.
  1142. *******************************************************************************/
  1143. static BOOL InsertWeapon( int where, int nSector, long x, long y, long z, int nAngle )
  1144. {
  1145. static short weaponTiles[] =
  1146. {
  1147. kPicRandomUp, kPicShotgun, kPicTommyGun, kPicFlareGun, kPicVoodooDoll, kPicSpearGun, kPicShadowGun
  1148. };
  1149. short nType;
  1150. tileIndexCount = LENGTH(weaponTiles);
  1151. for ( int i = 0; i < tileIndexCount; i++ )
  1152. tileIndex[i] = weaponTiles[i]; // gWeaponInfo[i].picnum;
  1153. short picnum = tilePick( -1 /*gWeaponInfo[0].picnum*/, -1, SS_CUSTOM );
  1154. if ( picnum == -1 )
  1155. return FALSE;
  1156. switch( picnum )
  1157. {
  1158. case kPicRandomUp:
  1159. nType = kWeaponItemRandom;
  1160. break;
  1161. case kPicShotgun:
  1162. nType = kWeaponItemShotgun;
  1163. break;
  1164. case kPicTommyGun:
  1165. nType = kWeaponItemTommyGun;
  1166. break;
  1167. case kPicFlareGun:
  1168. nType = kWeaponItemFlareGun;
  1169. break;
  1170. case kPicVoodooDoll:
  1171. nType = kWeaponItemVoodooDoll;
  1172. break;
  1173. case kPicSpearGun:
  1174. nType = kWeaponItemSpearGun;
  1175. break;
  1176. case kPicShadowGun:
  1177. nType = kWeaponItemShadowGun;
  1178. break;
  1179. default:
  1180. scrSetMessage("Invalid weapon tile selected!");
  1181. BeepError();
  1182. return FALSE;
  1183. }
  1184. int nSprite = insertsprite( (short)nSector, kStatItem );
  1185. dassert( nSprite >= 0 && nSprite < kMaxSprites );
  1186. sprite[nSprite].type = nType;
  1187. AutoAdjustSprites();
  1188. SPRITE *pSprite = &sprite[nSprite];
  1189. pSprite->x = x;
  1190. pSprite->y = y;
  1191. pSprite->z = z;
  1192. pSprite->ang = (short)nAngle;
  1193. pSprite->shade = -8;
  1194. int zTop, zBot;
  1195. GetSpriteExtents(pSprite, &zTop, &zBot);
  1196. if ( where == SS_FLOOR)
  1197. pSprite->z += getflorzofslope((short)nSector, pSprite->x, pSprite->y) - zBot;
  1198. else
  1199. pSprite->z += getceilzofslope((short)nSector, pSprite->x, pSprite->y) - zTop;
  1200. updatenumsprites();
  1201. BeepOkay();
  1202. return TRUE;
  1203. }
  1204. /*******************************************************************************
  1205. FUNCTION: InsertEnemy()
  1206. DESCRIPTION: Displays a tile menu allowing user to insert an enemy
  1207. on the ceiling or floor.
  1208. PARAMETERS:
  1209. NOTES: This routine should offer a list box rather than tiles.
  1210. At present, only base enemies may be added, but may be
  1211. "extended" in 2D mode to other types in the same class.
  1212. *******************************************************************************/
  1213. static BOOL InsertEnemy( int where, int nSector, long x, long y, long z, int nAngle )
  1214. {
  1215. static short dudeTiles[] =
  1216. {
  1217. kAnmCultistM1, kPicShotgunIdle, kAnmZomb1M1, kPicEarthIdle, kAnmZomb2M1, kAnmGargoyleM1, kAnmGargStatue,
  1218. kAnmPhantasmM1, kAnmHellM2, kAnmHandM1, kAnmSpiderM1, kAnmSpiderM1B, kAnmSpiderM1C, kAnmSpiderM1D,
  1219. kAnmGillM1, kAnmEelM1, kAnmBatM1, kAnmRatM1, kAnmPodM1, kAnmTentacleM1,
  1220. kAnmCerberusM1, kPicRandomUp, kAnmTchernobogM1, kAnmRachelM1,
  1221. };
  1222. short nType;
  1223. tileIndexCount = LENGTH(dudeTiles);
  1224. for ( int i = 0; i < tileIndexCount; i++ )
  1225. tileIndex[i] = dudeTiles[i];
  1226. short picnum = tilePick( -1, -1, SS_CUSTOM );
  1227. if ( picnum == -1 )
  1228. return FALSE;
  1229. switch( picnum )
  1230. {
  1231. case kAnmCultistM1:
  1232. nType = kDudeTommyCultist;
  1233. break;
  1234. case kPicShotgunIdle:
  1235. nType = kDudeShotgunCultist;
  1236. break;
  1237. case kAnmZomb1M1:
  1238. nType = kDudeAxeZombie;
  1239. break;
  1240. case kPicEarthIdle:
  1241. nType = kDudeEarthZombie;
  1242. break;
  1243. case kAnmZomb2M1:
  1244. nType = kDudeFatZombie;
  1245. break;
  1246. case kAnmGargoyleM1:
  1247. nType = kDudeFleshGargoyle;
  1248. break;
  1249. case kAnmGargStatue:
  1250. nType = kDudeFleshStatue;
  1251. break;
  1252. case kAnmPhantasmM1:
  1253. nType = kDudePhantasm;
  1254. break;
  1255. case kAnmHellM2:
  1256. nType = kDudeHound;
  1257. break;
  1258. case kAnmHandM1:
  1259. nType = kDudeHand;
  1260. break;
  1261. case kAnmSpiderM1:
  1262. nType = kDudeBrownSpider;
  1263. break;
  1264. case kAnmSpiderM1B:
  1265. nType = kDudeRedSpider;
  1266. break;
  1267. case kAnmSpiderM1C:
  1268. nType = kDudeBlackSpider;
  1269. break;
  1270. case kAnmSpiderM1D:
  1271. nType = kDudeMotherSpider;
  1272. break;
  1273. case kAnmGillM1:
  1274. nType = kDudeGillBeast;
  1275. break;
  1276. case kAnmEelM1:
  1277. nType = kDudeEel;
  1278. break;
  1279. case kAnmBatM1:
  1280. nType = kDudeBat;
  1281. break;
  1282. case kAnmRatM1:
  1283. nType = kDudeRat;
  1284. break;
  1285. case kAnmPodM1:
  1286. nType = kDudeGreenPod;
  1287. break;
  1288. case kAnmTentacleM1:
  1289. nType = kDudeGreenTentacle;
  1290. break;
  1291. case kAnmCerberusM1:
  1292. nType = kDudeCerberus;
  1293. break;
  1294. case kPicRandomUp:
  1295. nType = kDudeRandom;
  1296. break;
  1297. case kAnmTchernobogM1:
  1298. nType = kDudeTchernobog;
  1299. break;
  1300. case kAnmRachelM1:
  1301. nType = kDudeRachel;
  1302. break;
  1303. default:
  1304. scrSetMessage("Invalid dude tile selected!");
  1305. BeepError();
  1306. return FALSE;
  1307. }
  1308. int nSprite = insertsprite( (short)nSector, kStatDude );
  1309. dassert( nSprite >= 0 && nSprite < kMaxSprites );
  1310. sprite[nSprite].type = nType;
  1311. AutoAdjustSprites();
  1312. SPRITE *pSprite = &sprite[nSprite];
  1313. pSprite->x = x;
  1314. pSprite->y = y;
  1315. pSprite->z = z;
  1316. pSprite->ang = (short)nAngle;
  1317. pSprite->shade = -8;
  1318. int zTop, zBot;
  1319. GetSpriteExtents(pSprite, &zTop, &zBot);
  1320. if ( where == SS_FLOOR)
  1321. pSprite->z += getflorzofslope((short)nSector, pSprite->x, pSprite->y) - zBot;
  1322. else
  1323. pSprite->z += getceilzofslope((short)nSector, pSprite->x, pSprite->y) - zTop;
  1324. updatenumsprites();
  1325. int nXSprite = GetXSprite(nSprite);
  1326. dassert(nXSprite > 0 && nXSprite < kMaxXSprites);
  1327. // handle any special setups here
  1328. switch( nType )
  1329. {
  1330. case kDudeBrownSpider:
  1331. case kDudeRedSpider:
  1332. case kDudeBlackSpider:
  1333. case kDudeMotherSpider:
  1334. if (where == SS_CEILING && !(sector[nSector].ceilingstat & kSectorParallax) )
  1335. pSprite->cstat |= kSpriteFlipY; // invert ceiling spiders
  1336. break;
  1337. case kDudeBat:
  1338. if ( where == SS_CEILING && !(sector[nSector].ceilingstat & kSectorParallax) )
  1339. pSprite->picnum = kAnmBatM2; // make picnum ceiling bat
  1340. else
  1341. xsprite[nXSprite].state = 1; // they must be flying, better turn them on
  1342. break;
  1343. }
  1344. BeepOkay();
  1345. return TRUE;
  1346. }
  1347. // modal results for InsertGameObject
  1348. enum {
  1349. mrEnemy = mrUser,
  1350. mrWeapon,
  1351. mrAmmo,
  1352. mrItem,
  1353. mrHazard,
  1354. mrMisc,
  1355. };
  1356. /*******************************************************************************
  1357. FUNCTION: InsertGameObject()
  1358. DESCRIPTION: Displays a menu allowing user to insert a game-specific
  1359. object. Only ornaments can be placed as wall sprites.
  1360. PARAMETERS:
  1361. NOTES:
  1362. *******************************************************************************/
  1363. static BOOL InsertGameObject( int where, int nSector, long x, long y, long z, int nAngle )
  1364. {
  1365. Window dialog(0, 0, 80, 182, "Insert");
  1366. TextButton *pbEnemy = new TextButton( 4, 4, 60, 20, "&Enemy", (MODAL_RESULT)mrEnemy );
  1367. TextButton *pbWeapon = new TextButton( 4, 26, 60, 20, "&Weapon", (MODAL_RESULT)mrWeapon );
  1368. TextButton *pbAmmo = new TextButton( 4, 48, 60, 20, "&Ammo", (MODAL_RESULT)mrAmmo );
  1369. TextButton *pbItem = new TextButton( 4, 70, 60, 20, "&Item", (MODAL_RESULT)mrItem );
  1370. TextButton *pbHazard = new TextButton( 4, 92, 60, 20, "&Hazard", (MODAL_RESULT)mrHazard );
  1371. TextButton *pbMisc = new TextButton( 4, 114, 60, 20, "&Misc", (MODAL_RESULT)mrMisc );
  1372. TextButton *pbCancel = new TextButton( 4, 136, 60, 20, "&Cancel", (MODAL_RESULT)mrCancel );
  1373. dialog.Insert(pbEnemy);
  1374. dialog.Insert(pbWeapon);
  1375. dialog.Insert(pbAmmo);
  1376. dialog.Insert(pbItem);
  1377. dialog.Insert(pbHazard);
  1378. dialog.Insert(pbMisc);
  1379. dialog.Insert(pbCancel);
  1380. ShowModal(&dialog);
  1381. switch ( dialog.endState )
  1382. {
  1383. case mrEnemy:
  1384. return InsertEnemy( where, nSector, x, y, z, (nAngle + kAngle180) & kAngleMask );
  1385. case mrWeapon:
  1386. return InsertWeapon( where, nSector, x, y, z, 0 );
  1387. case mrAmmo:
  1388. return InsertAmmo( where, nSector, x, y, z, 0 );
  1389. case mrItem:
  1390. return InsertItem( where, nSector, x, y, z, 0);
  1391. case mrHazard:
  1392. return InsertHazard( where, nSector, x, y, z, nAngle );
  1393. case mrMisc:
  1394. return InsertMisc( where, nSector, x, y, z, nAngle );
  1395. case mrCancel:
  1396. // pressed escape
  1397. return FALSE;
  1398. }
  1399. return TRUE;
  1400. }
  1401. static BOOL CompareXSectors( XSECTOR *pXModel, XSECTOR *pXSector )
  1402. {
  1403. return memcmp(pXModel, pXSector, sizeof(XSECTOR)) == 0;
  1404. }
  1405. static BOOL Confirm( char *zMessage )
  1406. {
  1407. // create the dialog
  1408. Window dialog(59, 80, 202, 46, zMessage);
  1409. dialog.Insert(new TextButton(4, 4, 60, 20, "&Yes", mrYes));
  1410. dialog.Insert(new TextButton(68, 4, 60, 20, "&No", mrNo));
  1411. ShowModal(&dialog);
  1412. return (dialog.endState == mrYes) ? TRUE : FALSE;
  1413. }
  1414. /*******************************************************************************
  1415. FUNCTION: OptionsMenu()
  1416. DESCRIPTION:
  1417. PARAMETERS:
  1418. NOTES:
  1419. *******************************************************************************/
  1420. static BOOL OptionsMenu( void )
  1421. {
  1422. Window dialog(0, 0, 80, 182, "Options");
  1423. TextButton *pbClean = new TextButton( 4, 4, 60, 20, "C&lean", (MODAL_RESULT)mrUser );
  1424. TextButton *pbCancel = new TextButton( 4, 136, 60, 20, "&Cancel", (MODAL_RESULT)mrCancel );
  1425. dialog.Insert(pbClean);
  1426. dialog.Insert(pbCancel);
  1427. ShowModal(&dialog);
  1428. switch ( dialog.endState )
  1429. {
  1430. case mrUser:
  1431. {
  1432. XSECTOR model;
  1433. if (somethingintab == SS_FLOOR
  1434. && sector[searchsector].extra >= 0
  1435. && xsector[sector[searchsector].extra].reference == searchsector)
  1436. memcpy(&model, &xsector[sector[searchsector].extra], sizeof(XSECTOR));
  1437. int nCount = 1;
  1438. for (int i = 0; i < kMaxXSectors; i++)
  1439. {
  1440. int nSector = xsector[i].reference;
  1441. // compare with all other valid xsectors except self
  1442. if ((nSector != -1) && sector[nSector].extra == i && nSector != searchsector)
  1443. {
  1444. // fake exceptions in model
  1445. model.reference = xsector[i].reference;
  1446. // compare the xsectors
  1447. if ( CompareXSectors(&model, &xsector[i]) )
  1448. nCount++;
  1449. }
  1450. }
  1451. char message[40];
  1452. sprintf(message, "Clean %i common sectors?", nCount);
  1453. if (Confirm(message))
  1454. {
  1455. for (int i = 0; i < kMaxXSectors; i++)
  1456. {
  1457. int nSector = xsector[i].reference;
  1458. // compare with all other valid xsectors
  1459. if ((nSector != -1) && sector[nSector].extra == i)
  1460. {
  1461. // fake exceptions in model
  1462. model.reference = xsector[i].reference;
  1463. // compare the xsectors
  1464. if ( CompareXSectors(&model, &xsector[i]) )
  1465. dbDeleteXSector( i );
  1466. }
  1467. }
  1468. }
  1469. InitSectorFX();
  1470. break;
  1471. }
  1472. case mrCancel:
  1473. // pressed escape
  1474. return FALSE;
  1475. }
  1476. return TRUE;
  1477. }
  1478. /***********************************************************************
  1479. * SetupSky()
  1480. *
  1481. * Setup the sky based on the width of the first sky tile.
  1482. * Called by ExtCheckKeys, when Alt-1 is pressed.
  1483. *
  1484. * Sky Tile 1024 Tile Engine
  1485. * Width Count Shift Shift pskybits
  1486. * -----------------------------------------
  1487. * 1024 1 10 10 0
  1488. * 512 2 10 9 1
  1489. * 256 4 10 8 2
  1490. * 128 8 10 7 3
  1491. * 64 16 10 6 4
  1492. * 32 32 10 5 5
  1493. * 16 64 10 4 6
  1494. * 8 128 10 3 7
  1495. **********************************************************************/
  1496. static void SetupSky( int nTile )
  1497. {
  1498. dassert(nTile >= 0 && nTile < kMaxTiles);
  1499. pskybits = (short)(10 - (picsiz[nTile] & 0x0F));
  1500. gSkyCount = 1 << pskybits;
  1501. sector[searchsector].ceilingpicnum = (short)nTile;
  1502. dprintf("nTile = %i\n",nTile);
  1503. dprintf("pskybits = %i\n",pskybits);
  1504. dprintf("gSkyCount = %i\n",gSkyCount);
  1505. // setup the sky tile offset table
  1506. for (short i = 0; i < gSkyCount; i++)
  1507. {
  1508. pskyoff[i] = i;
  1509. dprintf("pskyoff[%i] = %i\n",i,pskyoff[i]);
  1510. }
  1511. // reset the base tile for all the parallaxed skies (ceiling & floor!)
  1512. for (i = 0; i < numsectors; i++)
  1513. {
  1514. if ( sector[i].ceilingstat & kSectorParallax )
  1515. sector[i].ceilingpicnum = (short)nTile;
  1516. if ( sector[i].floorstat & kSectorParallax )
  1517. sector[i].floorpicnum = (short)nTile;
  1518. }
  1519. }
  1520. static void PutSpriteOnCeiling( SPRITE *pSprite )
  1521. {
  1522. int zTop, zBot;
  1523. GetSpriteExtents(pSprite, &zTop, &zBot);
  1524. pSprite->z += getceilzofslope(pSprite->sectnum, pSprite->x, pSprite->y) - zTop;
  1525. }
  1526. static void PutSpriteOnFloor( SPRITE *pSprite )
  1527. {
  1528. int zTop, zBot;
  1529. GetSpriteExtents(pSprite, &zTop, &zBot);
  1530. pSprite->z += getflorzofslope(pSprite->sectnum, pSprite->x, pSprite->y) - zBot;
  1531. }
  1532. static void RaiseSprite( SPRITE *pSprite )
  1533. {
  1534. pSprite->z = DecNext(pSprite->z, gStep);
  1535. }
  1536. static void LowerSprite( SPRITE *pSprite )
  1537. {
  1538. pSprite->z = IncNext(pSprite->z, gStep);
  1539. }
  1540. static void ProcessHighlightSprites( HSPRITEFUNC SpriteFunc )
  1541. {
  1542. if ( TestBitString(show2dsprite, searchwall) ) // highlighted?
  1543. {
  1544. for (int i = 0; i < highlightcnt; i++)
  1545. {
  1546. if ( (highlight[i] & 0xC000) == 0x4000 )
  1547. {
  1548. short nSprite = (short)(highlight[i] & 0x3FFF);
  1549. SpriteFunc(&sprite[nSprite]);
  1550. }
  1551. }
  1552. }
  1553. else
  1554. SpriteFunc(&sprite[searchwall]);
  1555. }
  1556. static void RaiseCeiling( short nSector)
  1557. {
  1558. SetCeilingZ(nSector, DecNext(sector[nSector].ceilingz, gStep));
  1559. }
  1560. static void RaiseFloor( short nSector)
  1561. {
  1562. SetFloorZ(nSector, DecNext(sector[nSector].floorz, gStep));
  1563. }
  1564. static void LowerCeiling( short nSector)
  1565. {
  1566. SetCeilingZ(nSector, IncNext(sector[nSector].ceilingz, gStep));
  1567. }
  1568. static void LowerFloor( short nSector)
  1569. {
  1570. SetFloorZ(nSector, IncNext(sector[nSector].floorz, gStep));
  1571. }
  1572. static void ProcessHighlightSectors( HSECTORFUNC FloorFunc )
  1573. {
  1574. if ( IsSectorHighlight(searchsector) )
  1575. {
  1576. for (short i = 0; i < highlightsectorcnt; i++)
  1577. FloorFunc(highlightsector[i]);
  1578. }
  1579. else
  1580. FloorFunc(searchsector);
  1581. }
  1582. /*******************************************************************************
  1583. FUNCTION: ProcessKeys3D()
  1584. DESCRIPTION:
  1585. PARAMETERS:
  1586. NOTES:
  1587. *******************************************************************************/
  1588. void ProcessKeys3D( void )
  1589. {
  1590. int startwall, endwall;
  1591. short nSector;
  1592. long i, j, doubvel, changedir;
  1593. long goalz, xvect, yvect, hiz, loz;
  1594. short hitsect, hitwall, hitsprite;
  1595. long hitx, hity, hitz, hihit, lohit;
  1596. long x, y;
  1597. int nXSector, nXWall, nXSprite;
  1598. BYTE key;
  1599. static short tabang; // tawhat?
  1600. static short temptype;
  1601. int zTop, zBot;
  1602. // these were globals not referenced elsewhere
  1603. static long hvel = 0;
  1604. BYTE shift, ctrl, alt, pad5;
  1605. shift = keystatus[KEY_LSHIFT] | keystatus[KEY_RSHIFT];
  1606. ctrl = keystatus[KEY_LCTRL] | keystatus[KEY_RCTRL];
  1607. alt = keystatus[KEY_LALT] | keystatus[KEY_RALT];
  1608. pad5 = keystatus[KEY_PAD5];
  1609. if (ctrl && pad5)
  1610. horiz = 100;
  1611. if ( angvel )
  1612. {
  1613. doubvel = gFrameTicks;
  1614. if ( shift )
  1615. doubvel += gFrameTicks / 2;
  1616. ang = (short)((ang + (angvel * doubvel >> 4)) & kAngleMask);
  1617. }
  1618. if ( vel | svel )
  1619. {
  1620. doubvel = gFrameTicks;
  1621. if ( shift )
  1622. doubvel += gFrameTicks;
  1623. xvect = 0, yvect = 0;
  1624. if ( vel )
  1625. {
  1626. xvect += mulscale30(vel * doubvel >> 2, Cos(ang));
  1627. yvect += mulscale30(vel * doubvel >> 2, Sin(ang));
  1628. }
  1629. if (svel != 0)
  1630. {
  1631. xvect += mulscale30(svel * doubvel >> 2, Sin(ang));
  1632. yvect -= mulscale30(svel * doubvel >> 2, Cos(ang));
  1633. }
  1634. ClipMove(&posx, &posy, &posz, &cursectnum, xvect, yvect, kPlayerRadius, 4<<8, 4<<8, 0);
  1635. }
  1636. getzrange(posx, posy, posz, cursectnum, &hiz, &hihit, &loz, &lohit, kPlayerRadius, 0);
  1637. // ceiling hit?
  1638. if ( (hihit & kHitTypeMask) == kHitSector && (hihit & kHitIndexMask) == cursectnum)
  1639. {
  1640. if (sector[cursectnum].ceilingstat & kSectorParallax)
  1641. hiz = 0x80000000; // largest negative number
  1642. }
  1643. if ( keystatus[KEY_H] )
  1644. {
  1645. dprintf("kensplayerheight = %i, current height = %i\n", kensplayerheight, loz - posz);
  1646. keystatus[KEY_H] = 0;
  1647. }
  1648. if (zmode == 0)
  1649. {
  1650. goalz = loz - kensplayerheight; // playerheight pixels above floor
  1651. if (goalz < hiz + (16<<8)) //ceiling&floor too close
  1652. goalz = (loz + hiz) / 2;
  1653. if ( keystatus[KEY_A] )
  1654. {
  1655. if ( ctrl )
  1656. {
  1657. if (horiz > 0) horiz -= 4;
  1658. }
  1659. else
  1660. {
  1661. goalz -= (16<<8);
  1662. if ( shift )
  1663. goalz -= (24<<8);
  1664. }
  1665. }
  1666. if (keystatus[KEY_Z]) //Z (stand low)
  1667. {
  1668. if ( ctrl )
  1669. {
  1670. if (horiz < 200) horiz += 4;
  1671. }
  1672. else
  1673. {
  1674. goalz += (12<<8);
  1675. if ( shift )
  1676. goalz += 12 << 8;
  1677. }
  1678. }
  1679. if (goalz != posz)
  1680. {
  1681. if (posz < goalz) hvel += 32;
  1682. if (posz > goalz) hvel = ((goalz-posz)>>3);
  1683. posz += hvel;
  1684. if (posz > loz-(4<<8)) posz = loz-(4<<8), hvel = 0;
  1685. if (posz < hiz+(4<<8)) posz = hiz+(4<<8), hvel = 0;
  1686. }
  1687. }
  1688. else
  1689. {
  1690. goalz = posz;
  1691. if (keystatus[KEY_A])
  1692. {
  1693. if ( keystatus[KEY_LCTRL] )
  1694. {
  1695. if (horiz > 0) horiz -= 4;
  1696. }
  1697. else
  1698. {
  1699. if (zmode != 1)
  1700. goalz -= (8<<8);
  1701. else
  1702. {
  1703. zlock += (4<<8);
  1704. keystatus[KEY_A] = 0;
  1705. }
  1706. }
  1707. }
  1708. if (keystatus[KEY_Z]) //Z (stand low)
  1709. {
  1710. if ( keystatus[KEY_LCTRL] )
  1711. {
  1712. if (horiz < 200) horiz += 4;
  1713. }
  1714. else
  1715. {
  1716. if (zmode != 1)
  1717. goalz += (8<<8);
  1718. else if (zlock > 0)
  1719. {
  1720. zlock -= (4<<8);
  1721. keystatus[KEY_Z] = 0;
  1722. }
  1723. }
  1724. }
  1725. if (goalz < hiz+(4<<8))
  1726. goalz = hiz+(4<<8);
  1727. if (goalz > loz-(4<<8))
  1728. goalz = loz-(4<<8);
  1729. if (zmode == 1)
  1730. goalz = loz-zlock;
  1731. if (goalz < hiz+(4<<8)) //ceiling&floor too close
  1732. goalz = (loz + hiz) / 2;
  1733. if (zmode == 1)
  1734. posz = goalz;
  1735. if (goalz != posz)
  1736. {
  1737. if (posz < goalz) hvel += 32;
  1738. if (posz > goalz) hvel -= 32;
  1739. posz += hvel;
  1740. if (posz > loz-(4<<8)) posz = loz-(4<<8), hvel = 0;
  1741. if (posz < hiz+(4<<8)) posz = hiz+(4<<8), hvel = 0;
  1742. }
  1743. else
  1744. hvel = 0;
  1745. }
  1746. Mouse::Read(gFrameTicks);
  1747. searchx = ClipRange(Mouse::X, 1, xdim - 2);
  1748. searchy = ClipRange(Mouse::Y, 1, ydim - 2);
  1749. searchit = 2;
  1750. // keep search vars if left mouse button pressed
  1751. if (searchstat >= 0 && (Mouse::buttons & 1) )
  1752. searchit = 0;
  1753. // draw mouse
  1754. Video.SetColor(gStdColor[23 + mulscale30(8, Sin(gFrameClock * kAngle360 / kTimerRate))]);
  1755. gfxHLine(searchy, searchx - 6, searchx - 2);
  1756. gfxHLine(searchy, searchx + 2, searchx + 6);
  1757. gfxVLine(searchx, searchy - 5, searchy - 2);
  1758. gfxVLine(searchx, searchy + 2, searchy + 5);
  1759. if (searchstat < 0)
  1760. return;
  1761. key = keyGet();
  1762. switch ( key )
  1763. {
  1764. case KEY_PAGEUP:
  1765. gStep = 0x400;
  1766. if ( shift )
  1767. gStep = 0x100;
  1768. if (( searchstat == SS_WALL ) && (wall[searchwall].nextsector != -1) )
  1769. TranslateWallToSector();
  1770. if ( searchstat == SS_WALL )
  1771. searchstat = SS_CEILING; // adjust ceilings when pointing at white walls
  1772. if (ctrl)
  1773. {
  1774. switch (searchstat)
  1775. {
  1776. case SS_CEILING:
  1777. {
  1778. int nNeighbor = nextsectorneighborz( searchsector, sector[searchsector].ceilingz, -1, -1);
  1779. // if (nNeighbor == -1)
  1780. // nNeighbor = nextsectorneighborz( searchsector, sector[searchsector].ceilingz, -1, 1);
  1781. if (nNeighbor != -1)
  1782. SetCeilingZ( searchsector, sector[nNeighbor].ceilingz );
  1783. sprintf(buffer, "sector[%i].ceilingz: %i", searchsector, sector[searchsector].ceilingz);
  1784. scrSetMessage(buffer);
  1785. }
  1786. break;
  1787. case SS_FLOOR:
  1788. {
  1789. int nNeighbor = nextsectorneighborz( searchsector, sector[searchsector].floorz, 1, -1);
  1790. // if (nNeighbor == -1)
  1791. // nNeighbor = nextsectorneighborz( searchsector, sector[searchsector].floorz, 1, 1);
  1792. if (nNeighbor != -1)
  1793. SetFloorZ( searchsector, sector[nNeighbor].floorz );
  1794. sprintf(buffer, "sector[%i].floorz: %i", searchsector, sector[searchsector].floorz);
  1795. scrSetMessage(buffer);
  1796. }
  1797. break;
  1798. case SS_SPRITE:
  1799. ProcessHighlightSprites(PutSpriteOnCeiling);
  1800. sprintf(buffer, "sprite[%i].z: %i", searchwall, sprite[searchwall].z);
  1801. scrSetMessage(buffer);
  1802. break;
  1803. }
  1804. }
  1805. else if (alt)
  1806. {
  1807. switch (searchstat)
  1808. {
  1809. case SS_CEILING:
  1810. {
  1811. int dzInPixels = (sector[searchsector].floorz - sector[searchsector].ceilingz) / 256;
  1812. gStep = GetNumberBox("height off floor", dzInPixels, dzInPixels) * 256;
  1813. SetCeilingZ(searchsector, sector[searchsector].floorz - gStep);
  1814. sprintf(buffer, "sector[%i].ceilingz: %i", searchsector, sector[searchsector].ceilingz);
  1815. scrSetMessage(buffer);
  1816. break;
  1817. }
  1818. case SS_FLOOR:
  1819. {
  1820. int dzInPixels = (sector[searchsector].floorz - sector[searchsector].ceilingz) / 256;
  1821. gStep = GetNumberBox("height off ceiling", dzInPixels, dzInPixels) * 256;
  1822. SetFloorZ(searchsector, sector[searchsector].ceilingz + gStep);
  1823. sprintf(buffer, "sector[%i].floorz: %i", searchsector, sector[searchsector].floorz);
  1824. scrSetMessage(buffer);
  1825. break;
  1826. }
  1827. }
  1828. }
  1829. else if (shift)
  1830. {
  1831. switch (searchstat)
  1832. {
  1833. case SS_CEILING:
  1834. gStep = GetNumberBox("shift ceiling up", 128, 128) * 256;
  1835. SetCeilingZ(searchsector, sector[searchsector].ceilingz - gStep);
  1836. break;
  1837. case SS_FLOOR:
  1838. gStep = GetNumberBox("shift floor up", 128, 128) * 256;
  1839. SetFloorZ(searchsector, sector[searchsector].floorz - gStep);
  1840. break;
  1841. }
  1842. }
  1843. else
  1844. {
  1845. switch (searchstat)
  1846. {
  1847. case SS_CEILING:
  1848. ProcessHighlightSectors(RaiseCeiling);
  1849. sprintf(buffer, "sector[%i].ceilingz: %i", searchsector, sector[searchsector].ceilingz);
  1850. scrSetMessage(buffer);
  1851. break;
  1852. case SS_FLOOR:
  1853. ProcessHighlightSectors(RaiseFloor);
  1854. sprintf(buffer, "sector[%i].floorz: %i", searchsector, sector[searchsector].floorz);
  1855. scrSetMessage(buffer);
  1856. break;
  1857. case SS_SPRITE:
  1858. ProcessHighlightSprites(RaiseSprite);
  1859. sprintf(buffer, "sprite[%i].z: %i", searchwall, sprite[searchwall].z);
  1860. scrSetMessage(buffer);
  1861. break;
  1862. }
  1863. }
  1864. BeepOkay();
  1865. break;
  1866. case KEY_PAGEDN:
  1867. gStep = 0x400;
  1868. if ( shift )
  1869. gStep = 0x100;
  1870. if (( searchstat == SS_WALL ) && (wall[searchwall].nextsector != -1) )
  1871. TranslateWallToSector();
  1872. if ( searchstat == SS_WALL )
  1873. searchstat = SS_CEILING; // adjust ceilings when pointing at white walls
  1874. if (ctrl)
  1875. {
  1876. switch (searchstat)
  1877. {
  1878. case SS_CEILING:
  1879. {
  1880. int nNeighbor = nextsectorneighborz( searchsector, sector[searchsector].ceilingz, -1, 1);
  1881. // if (nNeighbor == -1)
  1882. // nNeighbor = nextsectorneighborz( searchsector, sector[searchsector].ceilingz, -1, -1);
  1883. if (nNeighbor != -1)
  1884. SetCeilingZ( searchsector, sector[nNeighbor].ceilingz );
  1885. sprintf(buffer, "sector[%i].ceilingz: %i", searchsector, sector[searchsector].ceilingz);
  1886. scrSetMessage(buffer);
  1887. }
  1888. break;
  1889. case SS_FLOOR:
  1890. {
  1891. int nNeighbor = nextsectorneighborz( searchsector, sector[searchsector].floorz, 1, 1);
  1892. // if (nNeighbor == -1)
  1893. // nNeighbor = nextsectorneighborz( searchsector, sector[searchsector].floorz, 1, -1);
  1894. if (nNeighbor != -1)
  1895. SetFloorZ( searchsector, sector[nNeighbor].floorz );
  1896. sprintf(buffer, "sector[%i].floorz: %i", searchsector, sector[searchsector].floorz);
  1897. scrSetMessage(buffer);
  1898. }
  1899. break;
  1900. case SS_SPRITE:
  1901. ProcessHighlightSprites(PutSpriteOnFloor);
  1902. sprintf(buffer, "sprite[%i].z: %i", searchwall, sprite[searchwall].z);
  1903. scrSetMessage(buffer);
  1904. break;
  1905. }
  1906. }
  1907. else if (alt)
  1908. {
  1909. switch (searchstat)
  1910. {
  1911. case SS_CEILING:
  1912. {
  1913. int dzInPixels = (sector[searchsector].floorz - sector[searchsector].ceilingz) / 256;
  1914. gStep = GetNumberBox("height off floor", dzInPixels, dzInPixels) * 256;
  1915. SetCeilingZ(searchsector, sector[searchsector].floorz - gStep);
  1916. sprintf(buffer, "sector[%i].ceilingz: %i", searchsector, sector[searchsector].ceilingz);
  1917. scrSetMessage(buffer);
  1918. break;
  1919. }
  1920. case SS_FLOOR:
  1921. {
  1922. int dzInPixels = (sector[searchsector].floorz - sector[searchsector].ceilingz) / 256;
  1923. gStep = GetNumberBox("height off ceiling", dzInPixels, dzInPixels) * 256;
  1924. SetFloorZ(searchsector, sector[searchsector].ceilingz + gStep);
  1925. sprintf(buffer, "sector[%i].floorz: %i", searchsector, sector[searchsector].floorz);
  1926. scrSetMessage(buffer);
  1927. break;
  1928. }
  1929. }
  1930. }
  1931. else if (shift)
  1932. {
  1933. switch (searchstat)
  1934. {
  1935. case SS_CEILING:
  1936. gStep = GetNumberBox("shift ceiling down", 128, 128) * 256;
  1937. SetCeilingZ(searchsector, sector[searchsector].ceilingz + gStep);
  1938. break;
  1939. case SS_FLOOR:
  1940. gStep = GetNumberBox("shift floor down", 128, 128) * 256;
  1941. SetFloorZ(searchsector, sector[searchsector].floorz + gStep);
  1942. break;
  1943. }
  1944. }
  1945. else
  1946. {
  1947. switch (searchstat)
  1948. {
  1949. case SS_CEILING:
  1950. ProcessHighlightSectors(LowerCeiling);
  1951. sprintf(buffer, "sector[%i].ceilingz: %i", searchsector, sector[searchsector].ceilingz);
  1952. scrSetMessage(buffer);
  1953. break;
  1954. case SS_FLOOR:
  1955. ProcessHighlightSectors(LowerFloor);
  1956. sprintf(buffer, "sector[%i].floorz: %i", searchsector, sector[searchsector].floorz);
  1957. scrSetMessage(buffer);
  1958. break;
  1959. case SS_SPRITE:
  1960. ProcessHighlightSprites(LowerSprite);
  1961. sprintf(buffer, "sprite[%i].z: %i", searchwall, sprite[searchwall].z);
  1962. scrSetMessage(buffer);
  1963. break;
  1964. }
  1965. }
  1966. BeepOkay();
  1967. break;
  1968. case KEY_DELETE:
  1969. if (searchstat == 3)
  1970. {
  1971. deletesprite(searchwall);
  1972. updatenumsprites();
  1973. BeepOkay();
  1974. }
  1975. else
  1976. BeepError();
  1977. break;
  1978. case KEY_TAB:
  1979. switch (searchstat)
  1980. {
  1981. case SS_WALL:
  1982. dprintf("Wall %i copied\n", searchwall);
  1983. temppicnum = wall[searchwall].picnum;
  1984. tempshade = wall[searchwall].shade;
  1985. temppal = wall[searchwall].pal;
  1986. tempxrepeat = wall[searchwall].xrepeat;
  1987. tempyrepeat = wall[searchwall].yrepeat;
  1988. tempcstat = wall[searchwall].cstat;
  1989. tempextra = wall[searchwall].extra;
  1990. temptype = wall[searchwall].type;
  1991. break;
  1992. case SS_CEILING:
  1993. dprintf("Ceiling %i copied\n", searchsector);
  1994. temppicnum = sector[searchsector].ceilingpicnum;
  1995. tempshade = sector[searchsector].ceilingshade;
  1996. temppal = sector[searchsector].ceilingpal;
  1997. tempxrepeat = sector[searchsector].ceilingxpanning;
  1998. tempyrepeat = sector[searchsector].ceilingypanning;
  1999. tempcstat = sector[searchsector].ceilingstat;
  2000. tempextra = sector[searchsector].extra;
  2001. tempvisibility = sector[searchsector].visibility;
  2002. temptype = sector[searchsector].type;
  2003. break;
  2004. case SS_FLOOR:
  2005. dprintf("Floor %i copied\n", searchsector);
  2006. temppicnum = sector[searchsector].floorpicnum;
  2007. tempshade = sector[searchsector].floorshade;
  2008. temppal = sector[searchsector].floorpal;
  2009. tempxrepeat = sector[searchsector].floorxpanning;
  2010. tempyrepeat = sector[searchsector].floorypanning;
  2011. tempcstat = sector[searchsector].floorstat;
  2012. tempextra = sector[searchsector].extra;
  2013. tempvisibility = sector[searchsector].visibility;
  2014. temptype = sector[searchsector].type;
  2015. break;
  2016. case SS_SPRITE:
  2017. dprintf("Sprite %i copied\n", searchwall);
  2018. temppicnum = sprite[searchwall].picnum;
  2019. tempshade = sprite[searchwall].shade;
  2020. temppal = sprite[searchwall].pal;
  2021. tempxrepeat = sprite[searchwall].xrepeat;
  2022. tempyrepeat = sprite[searchwall].yrepeat;
  2023. tempcstat = sprite[searchwall].cstat;
  2024. tempextra = sprite[searchwall].extra;
  2025. tabang = sprite[searchwall].ang;
  2026. temptype = sprite[searchwall].type;
  2027. break;
  2028. case SS_MASKED:
  2029. dprintf("Masked wall %i copied\n", searchwall);
  2030. temppicnum = wall[searchwall].overpicnum;
  2031. tempshade = wall[searchwall].shade;
  2032. temppal = wall[searchwall].pal;
  2033. tempxrepeat = wall[searchwall].xrepeat;
  2034. tempyrepeat = wall[searchwall].yrepeat;
  2035. tempcstat = wall[searchwall].cstat;
  2036. tempextra = wall[searchwall].extra;
  2037. temptype = wall[searchwall].type;
  2038. break;
  2039. }
  2040. somethingintab = (char)searchstat;
  2041. break;
  2042. case KEY_CAPSLOCK:
  2043. zmode = IncRotate(zmode, 3);
  2044. if (zmode == 1)
  2045. zlock = (loz-posz) & ~0x3FF;
  2046. sprintf(buffer, "ZMode = %s", gZModeMsg[zmode]);
  2047. scrSetMessage(buffer);
  2048. break;
  2049. case KEY_ENTER:
  2050. if (somethingintab == 255) // must have something to paste
  2051. {
  2052. BeepError();
  2053. break;
  2054. }
  2055. if ( ctrl )
  2056. {
  2057. switch (searchstat)
  2058. {
  2059. // Paste to every wall in loop
  2060. case SS_WALL:
  2061. case SS_MASKED:
  2062. i = searchwall;
  2063. do
  2064. {
  2065. if ( shift )
  2066. {
  2067. wall[i].shade = tempshade;
  2068. wall[i].pal = temppal;
  2069. }
  2070. else
  2071. {
  2072. wall[i].picnum = temppicnum;
  2073. if (somethingintab == SS_WALL || somethingintab == SS_MASKED)
  2074. {
  2075. wall[i].xrepeat = tempxrepeat;
  2076. wall[i].yrepeat = tempyrepeat;
  2077. wall[i].cstat = tempcstat;
  2078. }
  2079. fixrepeats((short)i);
  2080. }
  2081. i = wall[i].point2;
  2082. }
  2083. while (i != searchwall);
  2084. BeepOkay();
  2085. break;
  2086. // paste to all parallax ceilings
  2087. case SS_CEILING:
  2088. for (i = 0; i < numsectors; i++)
  2089. {
  2090. if ( sector[i].ceilingstat & kSectorParallax )
  2091. {
  2092. sector[i].ceilingpicnum = temppicnum;
  2093. sector[i].ceilingshade = tempshade;
  2094. sector[i].ceilingpal = temppal;
  2095. if (somethingintab == SS_CEILING || somethingintab == SS_FLOOR)
  2096. {
  2097. sector[i].ceilingxpanning = tempxrepeat;
  2098. sector[i].ceilingypanning = tempyrepeat;
  2099. sector[i].ceilingstat = (uchar)(tempcstat | kSectorParallax);
  2100. }
  2101. }
  2102. }
  2103. BeepOkay();
  2104. break;
  2105. // paste to all parallax floors
  2106. case SS_FLOOR:
  2107. for (i = 0; i < numsectors; i++)
  2108. {
  2109. if ( sector[i].floorstat & kSectorParallax )
  2110. {
  2111. sector[i].floorpicnum = temppicnum;
  2112. sector[i].floorshade = tempshade;
  2113. sector[i].floorpal = temppal;
  2114. if (somethingintab == SS_CEILING || somethingintab == SS_FLOOR)
  2115. {
  2116. sector[i].floorxpanning = tempxrepeat;
  2117. sector[i].floorypanning = tempyrepeat;
  2118. sector[i].floorstat = (uchar)(tempcstat | kSectorParallax);
  2119. }
  2120. }
  2121. }
  2122. BeepOkay();
  2123. break;
  2124. default:
  2125. BeepError();
  2126. break;
  2127. }
  2128. break;
  2129. }
  2130. if ( shift ) // paste shade and palette
  2131. {
  2132. switch (searchstat)
  2133. {
  2134. case SS_WALL:
  2135. wall[searchwall].shade = tempshade;
  2136. wall[searchwall].pal = temppal;
  2137. break;
  2138. case SS_CEILING:
  2139. if ( IsSectorHighlight(searchsector) )
  2140. {
  2141. for(i = 0; i < highlightsectorcnt; i++)
  2142. {
  2143. sector[i].ceilingshade = tempshade;
  2144. sector[i].ceilingpal = temppal;
  2145. sector[i].visibility = tempvisibility;
  2146. }
  2147. }
  2148. else
  2149. {
  2150. sector[searchsector].ceilingshade = tempshade;
  2151. sector[searchsector].ceilingpal = temppal;
  2152. sector[searchsector].visibility = tempvisibility;
  2153. // if this sector is a parallaxed sky...
  2154. if ( sector[searchsector].ceilingstat & kSectorParallax )
  2155. {
  2156. // propagate shade data on all parallaxed sky sectors
  2157. for (i = 0; i < numsectors; i++)
  2158. if (sector[i].ceilingstat & kSectorParallax)
  2159. {
  2160. sector[i].ceilingshade = tempshade;
  2161. sector[i].ceilingpal = temppal;
  2162. sector[i].visibility = tempvisibility;
  2163. }
  2164. }
  2165. }
  2166. break;
  2167. case SS_FLOOR:
  2168. if ( IsSectorHighlight(searchsector) )
  2169. {
  2170. for(i = 0; i < highlightsectorcnt; i++)
  2171. {
  2172. sector[i].floorshade = tempshade;
  2173. sector[i].floorpal = temppal;
  2174. sector[i].visibility = tempvisibility;
  2175. }
  2176. }
  2177. else
  2178. {
  2179. sector[searchsector].floorshade = tempshade;
  2180. sector[searchsector].floorpal = temppal;
  2181. sector[searchsector].visibility = tempvisibility;
  2182. }
  2183. break;
  2184. case SS_SPRITE:
  2185. sprite[searchwall].shade = tempshade;
  2186. sprite[searchwall].pal = temppal;
  2187. break;
  2188. case SS_MASKED:
  2189. wall[searchwall].shade = tempshade;
  2190. wall[searchwall].pal = temppal;
  2191. break;
  2192. }
  2193. BeepOkay();
  2194. break;
  2195. }
  2196. if ( alt ) // copy extra structures
  2197. {
  2198. switch (searchstat)
  2199. {
  2200. case SS_WALL:
  2201. case SS_MASKED:
  2202. if (somethingintab == SS_WALL || somethingintab == SS_MASKED)
  2203. {
  2204. wall[searchwall].extra = tempextra;
  2205. wall[searchwall].type = temptype;
  2206. CleanUp();
  2207. BeepOkay();
  2208. }
  2209. else
  2210. BeepError();
  2211. break;
  2212. case SS_CEILING:
  2213. case SS_FLOOR:
  2214. if (somethingintab == SS_CEILING || somethingintab == SS_FLOOR)
  2215. {
  2216. if ( IsSectorHighlight(searchsector) )
  2217. {
  2218. for(i = 0; i < highlightsectorcnt; i++)
  2219. {
  2220. sector[i].extra = tempextra;
  2221. sector[i].type = temptype;
  2222. }
  2223. }
  2224. else
  2225. {
  2226. sector[searchsector].extra = tempextra;
  2227. sector[searchsector].type = temptype;
  2228. }
  2229. CleanUp();
  2230. BeepOkay();
  2231. }
  2232. else
  2233. BeepError();
  2234. break;
  2235. case SS_SPRITE:
  2236. if (somethingintab == SS_SPRITE)
  2237. {
  2238. sprite[searchwall].type = temptype;
  2239. sprite[searchwall].extra = tempextra;
  2240. CleanUp();
  2241. BeepOkay();
  2242. }
  2243. else
  2244. BeepError();
  2245. break;
  2246. }
  2247. break;
  2248. }
  2249. switch (searchstat)
  2250. {
  2251. case SS_WALL:
  2252. wall[searchwall].picnum = temppicnum;
  2253. wall[searchwall].shade = tempshade;
  2254. wall[searchwall].pal = temppal;
  2255. if (somethingintab == SS_WALL)
  2256. {
  2257. wall[searchwall].xrepeat = tempxrepeat;
  2258. wall[searchwall].yrepeat = tempyrepeat;
  2259. wall[searchwall].cstat = tempcstat;
  2260. }
  2261. fixrepeats(searchwall);
  2262. break;
  2263. case SS_CEILING:
  2264. sector[searchsector].ceilingpicnum = temppicnum;
  2265. sector[searchsector].ceilingshade = tempshade;
  2266. sector[searchsector].ceilingpal = temppal;
  2267. if (somethingintab == SS_CEILING || somethingintab == SS_FLOOR)
  2268. {
  2269. sector[searchsector].ceilingxpanning = tempxrepeat;
  2270. sector[searchsector].ceilingypanning = tempyrepeat;
  2271. sector[searchsector].ceilingstat = (uchar)tempcstat;
  2272. sector[searchsector].visibility = tempvisibility;
  2273. }
  2274. break;
  2275. case SS_FLOOR:
  2276. sector[searchsector].floorpicnum = temppicnum;
  2277. sector[searchsector].floorshade = tempshade;
  2278. sector[searchsector].floorpal = temppal;
  2279. if (somethingintab == SS_CEILING || somethingintab == SS_FLOOR)
  2280. {
  2281. sector[searchsector].floorxpanning= tempxrepeat;
  2282. sector[searchsector].floorypanning= tempyrepeat;
  2283. sector[searchsector].floorstat = (uchar)tempcstat;
  2284. sector[searchsector].visibility = tempvisibility;
  2285. }
  2286. break;
  2287. case SS_SPRITE:
  2288. sprite[searchwall].picnum = temppicnum;
  2289. sprite[searchwall].shade = tempshade;
  2290. sprite[searchwall].pal = temppal;
  2291. if (somethingintab == SS_SPRITE)
  2292. {
  2293. sprite[searchwall].xrepeat = tempxrepeat;
  2294. sprite[searchwall].yrepeat = tempyrepeat;
  2295. if (sprite[searchwall].xrepeat < 1) sprite[searchwall].xrepeat = 1;
  2296. if (sprite[searchwall].yrepeat < 1) sprite[searchwall].yrepeat = 1;
  2297. sprite[searchwall].cstat = tempcstat;
  2298. }
  2299. GetSpriteExtents(&sprite[searchwall], &zTop, &zBot);
  2300. if ( !(sector[sprite[searchwall].sectnum].ceilingstat & kSectorParallax) )
  2301. sprite[searchwall].z += ClipLow(sector[sprite[searchwall].sectnum].ceilingz - zTop, 0);
  2302. if ( !(sector[sprite[searchwall].sectnum].floorstat & kSectorParallax) )
  2303. sprite[searchwall].z += ClipHigh(sector[sprite[searchwall].sectnum].floorz - zBot, 0);
  2304. break;
  2305. case SS_MASKED:
  2306. wall[searchwall].overpicnum = temppicnum;
  2307. if (wall[searchwall].nextwall >= 0)
  2308. wall[wall[searchwall].nextwall].overpicnum = temppicnum;
  2309. wall[searchwall].shade = tempshade;
  2310. wall[searchwall].pal = temppal;
  2311. if (somethingintab == SS_MASKED)
  2312. {
  2313. wall[searchwall].xrepeat = tempxrepeat;
  2314. wall[searchwall].yrepeat = tempyrepeat;
  2315. wall[searchwall].cstat = tempcstat;
  2316. }
  2317. fixrepeats(searchwall);
  2318. break;
  2319. }
  2320. BeepOkay();
  2321. break;
  2322. case KEY_LBRACE:
  2323. gStep = 256;
  2324. if ( shift )
  2325. gStep = 32;
  2326. switch (searchstat)
  2327. {
  2328. case SS_CEILING:
  2329. if ( IsSectorHighlight(searchsector) )
  2330. {
  2331. for (i = 0; i < highlightsectorcnt; i++)
  2332. SetCeilingSlope(highlightsector[i], (short)DecNext(sector[highlightsector[i]].ceilingslope, gStep));
  2333. sprintf(buffer, "adjusted %i ceilings by %i", highlightsectorcnt, gStep);
  2334. scrSetMessage(buffer);
  2335. }
  2336. else
  2337. {
  2338. SetCeilingSlope(searchsector, (short)DecNext(sector[searchsector].ceilingslope, gStep));
  2339. sprintf(buffer, "sector[%i].ceilingslope: %i", searchsector, sector[searchsector].ceilingslope);
  2340. scrSetMessage(buffer);
  2341. }
  2342. break;
  2343. case SS_FLOOR:
  2344. if ( IsSectorHighlight(searchsector) )
  2345. {
  2346. for(i = 0; i < highlightsectorcnt; i++)
  2347. SetFloorSlope(highlightsector[i], (short)DecNext(sector[highlightsector[i]].floorslope, gStep));
  2348. sprintf(buffer, "adjusted %i floors by %i", highlightsectorcnt, gStep);
  2349. scrSetMessage(buffer);
  2350. }
  2351. else
  2352. {
  2353. SetFloorSlope(searchsector, (short)DecNext(sector[searchsector].floorslope, gStep));
  2354. sprintf(buffer, "sector[%i].floorslope: %i", searchsector, sector[searchsector].floorslope);
  2355. scrSetMessage(buffer);
  2356. }
  2357. break;
  2358. }
  2359. BeepOkay();
  2360. break;
  2361. case KEY_RBRACE:
  2362. gStep = 256;
  2363. if ( shift )
  2364. gStep = 32;
  2365. switch (searchstat)
  2366. {
  2367. case SS_CEILING:
  2368. if ( IsSectorHighlight(searchsector) )
  2369. {
  2370. for (i = 0; i < highlightsectorcnt; i++)
  2371. SetCeilingSlope(highlightsector[i], (short)IncNext(sector[highlightsector[i]].ceilingslope, gStep));
  2372. sprintf(buffer, "adjusted %i ceilings by %i", highlightsectorcnt, gStep);
  2373. scrSetMessage(buffer);
  2374. }
  2375. else
  2376. {
  2377. SetCeilingSlope(searchsector, (short)IncNext(sector[searchsector].ceilingslope, gStep));
  2378. sprintf(buffer, "sector[%i].ceilingslope: %i", searchsector, sector[searchsector].ceilingslope);
  2379. scrSetMessage(buffer);
  2380. }
  2381. break;
  2382. case SS_FLOOR:
  2383. if ( IsSectorHighlight(searchsector) )
  2384. {
  2385. for(i = 0; i < highlightsectorcnt; i++)
  2386. SetFloorSlope(highlightsector[i], (short)IncNext(sector[highlightsector[i]].floorslope, gStep));
  2387. sprintf(buffer, "adjusted %i floors by %i", highlightsectorcnt, gStep);
  2388. scrSetMessage(buffer);
  2389. }
  2390. else
  2391. {
  2392. SetFloorSlope(searchsector, (short)IncNext(sector[searchsector].floorslope, gStep));
  2393. sprintf(buffer, "sector[%i].floorslope: %i", searchsector, sector[searchsector].floorslope);
  2394. scrSetMessage(buffer);
  2395. }
  2396. break;
  2397. }
  2398. BeepOkay();
  2399. break;
  2400. case KEY_COMMA:
  2401. switch (searchstat)
  2402. {
  2403. // rotate sprite ccw
  2404. case SS_SPRITE:
  2405. gStep = shift ? 16 : 256;
  2406. i = searchwall;
  2407. sprite[i].ang = (short)(IncNext(sprite[i].ang, gStep) & kAngleMask);
  2408. sprintf(buffer, "sprite[%i].ang: %i", searchwall, sprite[searchwall].ang);
  2409. scrSetMessage(buffer);
  2410. BeepOkay();
  2411. break;
  2412. default:
  2413. BeepError();
  2414. }
  2415. break;
  2416. case KEY_PERIOD:
  2417. switch (searchstat)
  2418. {
  2419. // rotate sprite cw
  2420. case SS_SPRITE:
  2421. gStep = shift ? 16 : 256;
  2422. i = searchwall;
  2423. sprite[i].ang = (short)(DecNext(sprite[i].ang, gStep) & kAngleMask);
  2424. sprintf(buffer, "sprite[%i].ang: %i", searchwall, sprite[searchwall].ang);
  2425. scrSetMessage(buffer);
  2426. BeepOkay();
  2427. break;
  2428. // search and fix panning to the right
  2429. case SS_WALL:
  2430. case SS_MASKED:
  2431. AutoAlignWalls(searchwall);
  2432. BeepOkay();
  2433. break;
  2434. default:
  2435. BeepError();
  2436. }
  2437. break;
  2438. case KEY_BACKSLASH: // Reset slope to 0
  2439. switch (searchstat)
  2440. {
  2441. case SS_CEILING:
  2442. sector[searchsector].ceilingslope = 0;
  2443. sector[searchsector].ceilingstat &= ~kSectorSloped;
  2444. sprintf(buffer, "sector[%i] ceiling slope reset", searchsector);
  2445. scrSetMessage(buffer);
  2446. break;
  2447. case SS_FLOOR:
  2448. sector[searchsector].floorslope = 0;
  2449. sector[searchsector].floorstat &= ~kSectorSloped;
  2450. sprintf(buffer, "sector[%i] floor slope reset", searchsector);
  2451. scrSetMessage(buffer);
  2452. break;
  2453. }
  2454. BeepOkay();
  2455. break;
  2456. case KEY_SLASH: // Reset panning, repeat, and flip
  2457. switch (searchstat)
  2458. {
  2459. case SS_WALL:
  2460. case SS_MASKED:
  2461. if ( shift )
  2462. wall[searchwall].xrepeat = wall[searchwall].yrepeat;
  2463. else
  2464. {
  2465. wall[searchwall].xpanning = 0;
  2466. wall[searchwall].ypanning = 0;
  2467. wall[searchwall].xrepeat = 8;
  2468. wall[searchwall].yrepeat = 8;
  2469. wall[searchwall].cstat = 0;
  2470. }
  2471. fixrepeats((short)searchwall);
  2472. sprintf(buffer, "wall[%i] pan/repeat reset", searchwall);
  2473. scrSetMessage(buffer);
  2474. break;
  2475. case SS_CEILING:
  2476. sector[searchsector].ceilingxpanning = 0;
  2477. sector[searchsector].ceilingypanning = 0;
  2478. sector[searchsector].ceilingstat &= ~kSectorFlipMask;
  2479. sprintf(buffer, "sector[%i] ceiling pan reset", searchsector);
  2480. scrSetMessage(buffer);
  2481. break;
  2482. case SS_FLOOR:
  2483. sector[searchsector].floorxpanning = 0;
  2484. sector[searchsector].floorypanning = 0;
  2485. sector[searchsector].floorstat &= ~kSectorFlipMask;
  2486. sprintf(buffer, "sector[%i] floor pan reset", searchsector);
  2487. scrSetMessage(buffer);
  2488. break;
  2489. case SS_SPRITE:
  2490. if ( shift )
  2491. sprite[searchwall].xrepeat = sprite[searchwall].yrepeat;
  2492. else
  2493. sprite[searchwall].xrepeat = sprite[searchwall].yrepeat = 64;
  2494. sprintf(buffer, "sprite[%i].xrepeat: %i yrepeat: %i", searchwall,
  2495. sprite[searchwall].xrepeat, sprite[searchwall].yrepeat );
  2496. scrSetMessage(buffer);
  2497. break;
  2498. }
  2499. BeepOkay();
  2500. break;
  2501. case KEY_MINUS:
  2502. // decrease sector visibility
  2503. if (ctrl && alt)
  2504. {
  2505. if ( IsSectorHighlight(searchsector) )
  2506. {
  2507. for (i = 0; i < highlightsectorcnt; i++)
  2508. {
  2509. // higher numbers are less visibility
  2510. sector[highlightsector[i]].visibility++;
  2511. }
  2512. scrSetMessage("highlighted sectors less visible");
  2513. }
  2514. else
  2515. {
  2516. // higher numbers are less visibility
  2517. sector[searchsector].visibility++;
  2518. sprintf(buffer, "Visibility: %i", sector[searchsector].visibility);
  2519. scrSetMessage(buffer);
  2520. }
  2521. BeepOkay();
  2522. break;
  2523. }
  2524. // decrease lighting effect amplitude
  2525. if ( ctrl )
  2526. {
  2527. nXSector = GetXSector(searchsector);
  2528. xsector[nXSector].amplitude++;
  2529. sprintf(buffer, "Amplitude: %i", xsector[nXSector].amplitude);
  2530. scrSetMessage(buffer);
  2531. BeepOkay();
  2532. break;
  2533. }
  2534. // decrease lighting effect phase
  2535. if ( shift )
  2536. {
  2537. nXSector = GetXSector(searchsector);
  2538. xsector[nXSector].phase -= 6;
  2539. sprintf(buffer, "Phase: %i", xsector[nXSector].phase);
  2540. scrSetMessage(buffer);
  2541. BeepOkay();
  2542. break;
  2543. }
  2544. // adjust gamma level
  2545. if ( keystatus[KEY_G] )
  2546. {
  2547. gGamma = ClipLow(gGamma - 1, 0);
  2548. BloodINI.PutKeyInt("View", "Gamma", gGamma);
  2549. BloodINI.Save();
  2550. sprintf(buffer, "Gamma correction level %i", gGamma);
  2551. scrSetMessage(buffer);
  2552. scrSetGamma(gGamma);
  2553. scrSetDac(0);
  2554. break;
  2555. }
  2556. if ( keystatus[KEY_D] )
  2557. {
  2558. visibility = ClipHigh(visibility + 16, 4096);
  2559. sprintf(buffer, "Depth cueing level %i", visibility);
  2560. scrSetMessage(buffer);
  2561. BeepOkay();
  2562. break;
  2563. }
  2564. break;
  2565. case KEY_PLUS:
  2566. // increase sector visibility
  2567. if ( ctrl && alt )
  2568. {
  2569. if ( IsSectorHighlight(searchsector) )
  2570. {
  2571. for (i = 0; i < highlightsectorcnt; i++)
  2572. {
  2573. sector[highlightsector[i]].visibility--;
  2574. }
  2575. scrSetMessage("highlighted sectors more visible");
  2576. }
  2577. else
  2578. {
  2579. // lower numbers are more visibility
  2580. sector[searchsector].visibility--;
  2581. sprintf(buffer, "Visibility: %i", sector[searchsector].visibility);
  2582. scrSetMessage(buffer);
  2583. }
  2584. BeepOkay();
  2585. break;
  2586. }
  2587. // increase lighting effect amplitude
  2588. if ( ctrl )
  2589. {
  2590. nXSector = GetXSector(searchsector);
  2591. xsector[nXSector].amplitude--;
  2592. sprintf(buffer, "Amplitude: %i", xsector[nXSector].amplitude);
  2593. scrSetMessage(buffer);
  2594. BeepOkay();
  2595. break;
  2596. }
  2597. // increae lighting effect phase
  2598. if ( shift )
  2599. {
  2600. nXSector = GetXSector(searchsector);
  2601. xsector[nXSector].phase += 6;
  2602. sprintf(buffer, "Phase: %i", xsector[nXSector].phase);
  2603. scrSetMessage(buffer);
  2604. BeepOkay();
  2605. break;
  2606. }
  2607. // adjust gamma level
  2608. if ( keystatus[KEY_G] )
  2609. {
  2610. gGamma = ClipHigh(gGamma + 1, gGammaLevels - 1);
  2611. BloodINI.PutKeyInt("View", "Gamma", gGamma);
  2612. BloodINI.Save();
  2613. sprintf(buffer, "Gamma correction level %i", gGamma);
  2614. scrSetMessage(buffer);
  2615. scrSetGamma(gGamma);
  2616. scrSetDac(0);
  2617. break;
  2618. }
  2619. if ( keystatus[KEY_D] )
  2620. {
  2621. visibility = ClipLow(visibility - 16, 128);
  2622. sprintf(buffer, "Depth cueing level %i", visibility);
  2623. scrSetMessage(buffer);
  2624. BeepOkay();
  2625. break;
  2626. }
  2627. break;
  2628. case KEY_B: // B (clip Blocking xor) (3D)
  2629. switch (searchstat)
  2630. {
  2631. case SS_WALL:
  2632. case SS_MASKED:
  2633. if ( TestBitString(show2dwall, searchwall) ) // highlighted?
  2634. {
  2635. for (int i = 0; i < highlightcnt; i++)
  2636. if ( (highlight[i] & 0xC000) == 0 )
  2637. {
  2638. int nWall = highlight[ i ];
  2639. wall[ nWall ].cstat ^= kWallBlocking;
  2640. }
  2641. } else {
  2642. wall[searchwall].cstat ^= kWallBlocking;
  2643. if (wall[searchwall].nextwall >= 0)
  2644. {
  2645. wall[wall[searchwall].nextwall].cstat &= ~kWallBlocking;
  2646. wall[wall[searchwall].nextwall].cstat |= (short)(wall[searchwall].cstat & kWallBlocking);
  2647. }
  2648. }
  2649. sprintf(buffer, "Wall %i blocking flag is %s", searchwall,
  2650. gBoolNames[ wall[searchwall].cstat & kWallBlocking ? 1 : 0 ]);
  2651. scrSetMessage(buffer);
  2652. BeepOkay();
  2653. break;
  2654. case SS_SPRITE:
  2655. sprite[searchwall].cstat ^= kSpriteBlocking;
  2656. sprintf(buffer, "sprite[%i] %s blocking", searchwall,
  2657. (sprite[searchwall].cstat & kSpriteBlocking) ? "is" : "not" );
  2658. scrSetMessage(buffer);
  2659. BeepOkay();
  2660. break;
  2661. default:
  2662. BeepError();
  2663. }
  2664. break;
  2665. case KEY_C:
  2666. if (alt) // change all tiles matching target to tab picnum
  2667. {
  2668. if (somethingintab != searchstat)
  2669. {
  2670. BeepError();
  2671. break;
  2672. }
  2673. switch (searchstat)
  2674. {
  2675. case SS_WALL:
  2676. j = wall[searchwall].picnum;
  2677. if ( TestBitString(show2dwall, searchwall) ) // highlighted?
  2678. {
  2679. for (int i = 0; i < highlightcnt; i++)
  2680. if ( (highlight[i] & 0xC000) == 0 )
  2681. {
  2682. int nWall = highlight[ i ];
  2683. if (wall[nWall].picnum == j)
  2684. {
  2685. if (wall[nWall].picnum != temppicnum)
  2686. wall[nWall].picnum = temppicnum;
  2687. else if (wall[nWall].pal != temppal)
  2688. wall[nWall].pal = temppal;
  2689. }
  2690. }
  2691. } else {
  2692. for ( i = 0; i < numwalls; i++)
  2693. if (wall[i].picnum == j)
  2694. {
  2695. if (wall[i].picnum != temppicnum)
  2696. wall[i].picnum = temppicnum;
  2697. else if (wall[i].pal != temppal)
  2698. wall[i].pal = temppal;
  2699. }
  2700. }
  2701. break;
  2702. case SS_CEILING:
  2703. j = sector[searchsector].ceilingpicnum;
  2704. for (i = 0; i < numsectors; i++)
  2705. if (sector[i].ceilingpicnum == j)
  2706. {
  2707. if (sector[i].ceilingpicnum != temppicnum)
  2708. sector[i].ceilingpicnum = temppicnum;
  2709. else if (sector[i].ceilingpal != temppal)
  2710. sector[i].ceilingpal = temppal;
  2711. }
  2712. break;
  2713. case SS_FLOOR:
  2714. j = sector[searchsector].floorpicnum;
  2715. for (i = 0; i < numsectors; i++)
  2716. if (sector[i].floorpicnum == j)
  2717. {
  2718. if (sector[i].floorpicnum != temppicnum)
  2719. sector[i].floorpicnum = temppicnum;
  2720. else if (sector[i].floorpal != temppal)
  2721. sector[i].floorpal = temppal;
  2722. }
  2723. break;
  2724. case SS_SPRITE:
  2725. j = sprite[searchwall].picnum;
  2726. for (i = 0; i < kMaxSprites; i++)
  2727. if (sprite[i].statnum < kMaxStatus && sprite[i].picnum == j)
  2728. {
  2729. sprite[i].picnum = temppicnum;
  2730. sprite[i].type = temptype;
  2731. }
  2732. break;
  2733. case SS_MASKED:
  2734. j = wall[searchwall].overpicnum;
  2735. for (i = 0; i < numwalls; i++)
  2736. if (wall[i].overpicnum == j)
  2737. {
  2738. wall[i].overpicnum = temppicnum;
  2739. }
  2740. break;
  2741. }
  2742. BeepOkay();
  2743. break;
  2744. }
  2745. /*
  2746. switch (searchstat)
  2747. {
  2748. case SS_SPRITE:
  2749. sprite[searchwall].cstat ^= kSpriteOriginAlign;
  2750. BeepOkay();
  2751. break;
  2752. }
  2753. */
  2754. break;
  2755. case KEY_E: // E (expand)
  2756. switch (searchstat)
  2757. {
  2758. case SS_CEILING:
  2759. sector[searchsector].ceilingstat ^= kSectorExpand;
  2760. sprintf(buffer, "ceiling texture %s expanded",
  2761. (sector[searchsector].ceilingstat & kSectorExpand) ? "is" : "not");
  2762. scrSetMessage(buffer);
  2763. BeepOkay();
  2764. break;
  2765. case SS_FLOOR:
  2766. sector[searchsector].floorstat ^= kSectorExpand;
  2767. sprintf(buffer, "floor texture %s expanded",
  2768. (sector[searchsector].floorstat & kSectorExpand) ? "is" : "not");
  2769. scrSetMessage(buffer);
  2770. BeepOkay();
  2771. break;
  2772. default:
  2773. BeepError();
  2774. }
  2775. break;
  2776. case KEY_F:
  2777. if ( alt )
  2778. {
  2779. switch ( searchstat )
  2780. {
  2781. case SS_WALL:
  2782. case SS_MASKED:
  2783. nSector = sectorofwall(searchwall);
  2784. sector[searchsector].ceilingstat &= ~kSectorFlipMask;
  2785. sector[searchsector].ceilingstat |= kSectorRelAlign;
  2786. SetFirstWall(nSector, searchwall);
  2787. BeepOkay();
  2788. break;
  2789. case SS_CEILING:
  2790. sector[searchsector].ceilingstat &= ~kSectorFlipMask;
  2791. sector[searchsector].ceilingstat |= kSectorRelAlign;
  2792. SetFirstWall(searchsector, sector[searchsector].wallptr + 1);
  2793. BeepOkay();
  2794. break;
  2795. case SS_FLOOR:
  2796. sector[searchsector].floorstat &= ~kSectorFlipMask;
  2797. sector[searchsector].floorstat |= kSectorRelAlign;
  2798. SetFirstWall(searchsector, sector[searchsector].wallptr + 1);
  2799. BeepOkay();
  2800. break;
  2801. default:
  2802. BeepError();
  2803. }
  2804. break;
  2805. }
  2806. switch (searchstat)
  2807. {
  2808. case SS_WALL:
  2809. case SS_MASKED:
  2810. i = wall[searchwall].cstat & kWallFlipMask;
  2811. switch(i)
  2812. {
  2813. case 0: i = kWallFlipX; break;
  2814. case kWallFlipX: i = kWallFlipX | kWallFlipY; break;
  2815. case kWallFlipX | kWallFlipY: i = kWallFlipY; break;
  2816. case kWallFlipY: i = 0; break;
  2817. }
  2818. wall[searchwall].cstat &= ~kWallFlipMask;
  2819. wall[searchwall].cstat |= (short)i;
  2820. sprintf(buffer, "wall[%i]",searchwall);
  2821. if (wall[searchwall].cstat & kWallFlipX)
  2822. strcat(buffer," x-flipped");
  2823. if (wall[searchwall].cstat & kWallFlipY)
  2824. {
  2825. if (wall[searchwall].cstat & kWallFlipX)
  2826. strcat(buffer," and");
  2827. strcat(buffer," y-flipped");
  2828. }
  2829. scrSetMessage(buffer);
  2830. BeepOkay();
  2831. break;
  2832. // 8-way ceiling flipping (bits 2,4,5)
  2833. case SS_CEILING:
  2834. i = sector[searchsector].ceilingstat & kSectorFlipMask;
  2835. switch (i)
  2836. {
  2837. case 0x00: i = 0x10; break;
  2838. case 0x10: i = 0x30; break;
  2839. case 0x30: i = 0x20; break;
  2840. case 0x20: i = 0x04; break;
  2841. case 0x04: i = 0x14; break;
  2842. case 0x14: i = 0x34; break;
  2843. case 0x34: i = 0x24; break;
  2844. case 0x24: i = 0x00; break;
  2845. }
  2846. sector[searchsector].ceilingstat &= ~kSectorFlipMask;
  2847. sector[searchsector].ceilingstat |= (uchar)i;
  2848. break;
  2849. // 8-way floor flipping (bits 2,4,5)
  2850. case SS_FLOOR:
  2851. i = sector[searchsector].floorstat & kSectorFlipMask;
  2852. switch (i)
  2853. {
  2854. case 0x00: i = 0x10; break;
  2855. case 0x10: i = 0x30; break;
  2856. case 0x30: i = 0x20; break;
  2857. case 0x20: i = 0x04; break;
  2858. case 0x04: i = 0x14; break;
  2859. case 0x14: i = 0x34; break;
  2860. case 0x34: i = 0x24; break;
  2861. case 0x24: i = 0x00; break;
  2862. }
  2863. sector[searchsector].floorstat &= ~kSectorFlipMask;
  2864. sector[searchsector].floorstat |= (uchar)i;
  2865. break;
  2866. case SS_SPRITE:
  2867. i = sprite[searchwall].cstat;
  2868. // two-sided floor sprite?
  2869. if ( (i & kSpriteRMask) == kSpriteFloor && !(i & kSpriteOneSided) )
  2870. {
  2871. // what the hell is this supposed to be doing?
  2872. sprite[searchwall].cstat &= ~kSpriteFlipY;
  2873. sprite[searchwall].cstat ^= kSpriteFlipX;
  2874. }
  2875. else
  2876. {
  2877. i = i & 0xC;
  2878. switch(i)
  2879. {
  2880. case 0x0: i = 0x4; break;
  2881. case 0x4: i = 0xC; break;
  2882. case 0xC: i = 0x8; break;
  2883. case 0x8: i = 0x0; break;
  2884. }
  2885. sprite[searchwall].cstat &= ~0xC;
  2886. sprite[searchwall].cstat |= (short)i;
  2887. }
  2888. break;
  2889. }
  2890. BeepOkay();
  2891. break;
  2892. case KEY_G:
  2893. if ( alt )
  2894. {
  2895. // change global palette
  2896. gPalette = IncRotate(gPalette, kMaxPalettes);
  2897. scrSetPalette(gPalette);
  2898. scrSetDac(0); // force update of DAC registers
  2899. switch (gPalette)
  2900. {
  2901. case kPalNormal:
  2902. scrSetMessage("Normal palette");
  2903. break;
  2904. case kPalWater:
  2905. scrSetMessage("Water palette");
  2906. break;
  2907. case kPalBeast:
  2908. scrSetMessage("Beast palette");
  2909. break;
  2910. }
  2911. }
  2912. break;
  2913. case KEY_H: // H (hitscan sensitivity)
  2914. switch (searchstat)
  2915. {
  2916. case SS_WALL:
  2917. case SS_MASKED:
  2918. wall[searchwall].cstat ^= kWallHitscan;
  2919. if (wall[searchwall].nextwall >= 0)
  2920. {
  2921. wall[wall[searchwall].nextwall].cstat &= ~kWallHitscan;
  2922. wall[wall[searchwall].nextwall].cstat |= (short)(wall[searchwall].cstat & kWallHitscan);
  2923. }
  2924. sprintf(buffer, "wall[%i] %s hitscan sensitive", searchwall,
  2925. (wall[searchwall].cstat & kWallHitscan) ? "is" : "not");
  2926. scrSetMessage(buffer);
  2927. BeepOkay();
  2928. break;
  2929. case SS_SPRITE:
  2930. sprite[searchwall].cstat ^= kSpriteHitscan;
  2931. sprintf(buffer, "sprite[%i] %s hitscan sensitive", searchwall,
  2932. (sprite[searchwall].cstat & kSpriteHitscan) ? "is" : "not");
  2933. scrSetMessage(buffer);
  2934. BeepOkay();
  2935. break;
  2936. default:
  2937. BeepError();
  2938. }
  2939. break;
  2940. case KEY_L:
  2941. switch (searchstat)
  2942. {
  2943. case SS_SPRITE:
  2944. {
  2945. GetSpriteExtents(&sprite[searchwall], &zTop, &zBot);
  2946. ushort oldcstat = sprite[searchwall].cstat;
  2947. sprite[searchwall].cstat &= ~kSpriteHitscan;
  2948. SetupLightBomb();
  2949. LightBomb(sprite[searchwall].x, sprite[searchwall].y, zTop,
  2950. sprite[searchwall].sectnum);
  2951. sprite[searchwall].cstat = oldcstat;
  2952. BeepOkay();
  2953. break;
  2954. }
  2955. case SS_FLOOR:
  2956. if (sector[searchsector].ceilingstat & kSectorParallax)
  2957. {
  2958. sector[searchsector].floorstat ^= kSectorFloorShade;
  2959. sprintf(buffer, "Forced floor shading is %s",
  2960. gBoolNames[ sector[searchsector].floorstat & kSectorFloorShade ? 1 : 0 ]);
  2961. scrSetMessage(buffer);
  2962. }
  2963. else
  2964. scrSetMessage("Sky must be parallaxed to force floorshade");
  2965. break;
  2966. default:
  2967. BeepError();
  2968. }
  2969. break;
  2970. case KEY_M: // M (masking walls)
  2971. switch (searchstat)
  2972. {
  2973. case SS_WALL:
  2974. case SS_MASKED:
  2975. case SS_CEILING:
  2976. case SS_FLOOR:
  2977. i = wall[searchwall].nextwall;
  2978. if (i < 0)
  2979. {
  2980. BeepError();
  2981. break;
  2982. }
  2983. wall[searchwall].cstat ^= kWallMasked;
  2984. if (wall[searchwall].cstat & kWallMasked)
  2985. {
  2986. wall[searchwall].cstat &= ~kWallFlipX;
  2987. if ( !shift )
  2988. {
  2989. wall[i].cstat |= kWallFlipX; //auto other-side flip
  2990. wall[i].cstat |= kWallMasked;
  2991. if (wall[searchwall].overpicnum < 0)
  2992. wall[searchwall].overpicnum = 0;
  2993. wall[i].overpicnum = wall[searchwall].overpicnum;
  2994. }
  2995. }
  2996. else
  2997. {
  2998. wall[searchwall].cstat &= ~kWallFlipX;
  2999. if ( !shift )
  3000. {
  3001. wall[i].cstat &= ~kWallFlipX; //auto other-side unflip
  3002. wall[i].cstat &= ~kWallMasked;
  3003. }
  3004. }
  3005. wall[searchwall].cstat &= ~kWallOneWay;
  3006. if ( !shift )
  3007. wall[i].cstat &= ~kWallOneWay;
  3008. sprintf(buffer, "wall[%i] %s masked", searchwall,
  3009. (wall[searchwall].cstat & kWallMasked) ? "is" : "not");
  3010. scrSetMessage(buffer);
  3011. BeepOkay();
  3012. break;
  3013. default:
  3014. BeepError();
  3015. }
  3016. break;
  3017. case KEY_O:
  3018. if (alt)
  3019. {
  3020. asksave = OptionsMenu();
  3021. }
  3022. else
  3023. {
  3024. switch (searchstat)
  3025. {
  3026. // O (top/bottom orientation - for doors)
  3027. case SS_WALL:
  3028. case SS_MASKED:
  3029. wall[searchwall].cstat ^= kWallBottomOrg;
  3030. if ( wall[searchwall].nextwall == -1 )
  3031. sprintf(buffer, "Texture pegged at %s", (wall[searchwall].cstat & kWallBottomOrg) ? "bottom" : "top");
  3032. else
  3033. sprintf(buffer, "Texture pegged at %s", (wall[searchwall].cstat & kWallOutsideOrg) ? "outside" : "inside");
  3034. scrSetMessage(buffer);
  3035. BeepOkay();
  3036. break;
  3037. // O (ornament onto wall)
  3038. case SS_SPRITE:
  3039. {
  3040. if (sprite[searchwall].z > sector[sprite[searchwall].sectnum].floorz)
  3041. {
  3042. scrSetMessage("Sprite z is below floor");
  3043. BeepError();
  3044. break;
  3045. }
  3046. if (sprite[searchwall].z < sector[sprite[searchwall].sectnum].ceilingz)
  3047. {
  3048. scrSetMessage("Sprite z is above ceiling");
  3049. BeepError();
  3050. break;
  3051. }
  3052. HITINFO hitInfo;
  3053. int hitType = HitScan(&sprite[searchwall], sprite[searchwall].z,
  3054. Cos(sprite[searchwall].ang + kAngle180) >> 16,
  3055. Sin(sprite[searchwall].ang + kAngle180) >> 16,
  3056. 0, &hitInfo);
  3057. if ( hitType == SS_WALL || hitType == SS_MASKED )
  3058. {
  3059. int nx, ny;
  3060. GetWallNormal(hitInfo.hitwall, &nx, &ny);
  3061. sprite[searchwall].x = hitInfo.hitx + (nx >> 14);
  3062. sprite[searchwall].y = hitInfo.hity + (ny >> 14);
  3063. sprite[searchwall].z = hitInfo.hitz;
  3064. sprite[searchwall].cstat &= ~kSpriteBlocking;
  3065. sprite[searchwall].cstat |= kSpriteOneSided;
  3066. changespritesect(searchwall, hitInfo.hitsect);
  3067. sprite[searchwall].ang = (short)((GetWallAngle(hitInfo.hitwall) + kAngle90) & kAngleMask);
  3068. dprintf("Sprite ornamented onto wall %d\n", hitInfo.hitwall);
  3069. BeepOkay();
  3070. }
  3071. else
  3072. BeepError();
  3073. break;
  3074. }
  3075. default:
  3076. BeepError();
  3077. }
  3078. }
  3079. break;
  3080. case KEY_P:
  3081. if ( ctrl )
  3082. {
  3083. parallaxtype = (char)IncRotate(parallaxtype, 3);
  3084. sprintf(buffer, "Parallax type: %i", parallaxtype);
  3085. scrSetMessage(buffer);
  3086. BeepOkay();
  3087. break;
  3088. }
  3089. if ( alt )
  3090. {
  3091. switch (searchstat)
  3092. {
  3093. case SS_WALL:
  3094. case SS_MASKED:
  3095. wall[searchwall].pal = (char)GetNumberBox("Wall palookup", wall[searchwall].pal, wall[searchwall].pal);
  3096. break;
  3097. case SS_CEILING:
  3098. sector[searchsector].ceilingpal = (char)GetNumberBox("Ceiling palookup", sector[searchsector].ceilingpal, sector[searchsector].ceilingpal);
  3099. break;
  3100. case SS_FLOOR:
  3101. sector[searchsector].floorpal = (char)GetNumberBox("Floor palookup", sector[searchsector].floorpal, sector[searchsector].floorpal);
  3102. break;
  3103. case SS_SPRITE:
  3104. sprite[searchwall].pal = (char)GetNumberBox("Sprite palookup", sprite[searchwall].pal, sprite[searchwall].pal);
  3105. break;
  3106. }
  3107. BeepOkay();
  3108. break;
  3109. }
  3110. switch (searchstat)
  3111. {
  3112. case SS_CEILING:
  3113. sector[searchsector].ceilingstat ^= kSectorParallax;
  3114. sprintf(buffer, "sector[%i] ceiling %s parallaxed", searchsector,
  3115. (sector[searchsector].ceilingstat & kSectorParallax) ? "is" : "not");
  3116. scrSetMessage(buffer);
  3117. if ( sector[searchsector].ceilingstat & kSectorParallax )
  3118. SetupSky(sector[searchsector].ceilingpicnum);
  3119. else
  3120. sector[searchsector].floorstat &= ~kSectorFloorShade; // clear forced floor shading bit
  3121. BeepOkay();
  3122. break;
  3123. case SS_FLOOR:
  3124. sector[searchsector].floorstat ^= kSectorParallax;
  3125. sprintf(buffer, "sector[%i] floor %s parallaxed", searchsector,
  3126. (sector[searchsector].floorstat & kSectorParallax) ? "is" : "not");
  3127. scrSetMessage(buffer);
  3128. BeepOkay();
  3129. break;
  3130. default:
  3131. BeepError();
  3132. }
  3133. break;
  3134. case KEY_R: // R (relative alignment, rotation)
  3135. switch (searchstat)
  3136. {
  3137. case SS_CEILING:
  3138. sector[searchsector].ceilingstat ^= kSectorRelAlign;
  3139. sprintf(buffer, "sector[%i] ceiling %s relative", searchsector,
  3140. (sector[searchsector].ceilingstat & kSectorRelAlign) ? "is" : "not");
  3141. scrSetMessage(buffer);
  3142. BeepOkay();
  3143. break;
  3144. case SS_FLOOR:
  3145. sector[searchsector].floorstat ^= kSectorRelAlign;
  3146. sprintf(buffer, "sector[%i] floor %s relative", searchsector,
  3147. (sector[searchsector].floorstat & kSectorRelAlign) ? "is" : "not");
  3148. scrSetMessage(buffer);
  3149. BeepOkay();
  3150. break;
  3151. case SS_SPRITE:
  3152. i = sprite[searchwall].cstat & kSpriteRMask;
  3153. switch (i)
  3154. {
  3155. case 0x00:
  3156. i = 0x10;
  3157. sprintf( buffer, "sprite[%i] is wall sprite", searchwall );
  3158. break;
  3159. case 0x10:
  3160. i = 0x20;
  3161. sprintf( buffer, "sprite[%i] is floor sprite", searchwall );
  3162. break;
  3163. case 0x20:
  3164. i = 0x00;
  3165. sprintf( buffer, "sprite[%i] is face sprite", searchwall );
  3166. break;
  3167. default:
  3168. i = 0x00;
  3169. sprintf( buffer, "sprite[%i] is face sprite", searchwall );
  3170. break;
  3171. }
  3172. scrSetMessage(buffer);
  3173. sprite[searchwall].cstat &= ~kSpriteRMask;
  3174. sprite[searchwall].cstat |= (ushort)i;
  3175. BeepOkay();
  3176. break;
  3177. default:
  3178. BeepError();
  3179. }
  3180. break;
  3181. case KEY_S:
  3182. if ( alt && (searchstat == SS_CEILING || searchstat == SS_FLOOR) )
  3183. {
  3184. x = 1 << 14;
  3185. y = divscale(searchx - xdim / 2, xdim / 2, 14);
  3186. RotateVector(&x, &y, ang);
  3187. hitsect = hitwall = hitsprite = -1;
  3188. hitscan(posx, posy, posz, cursectnum, //Start position
  3189. x, y, (searchy-horiz) * 2000, //vector of 3D ang
  3190. &hitsect, &hitwall, &hitsprite, &hitx, &hity, &hitz);
  3191. if (hitsect >= 0)
  3192. {
  3193. x = hitx;
  3194. y = hity;
  3195. if ((gridlock > 0) && (grid > 0))
  3196. {
  3197. x = (x+(1024 >> grid)) & (0xffffffff<<(11-grid));
  3198. y = (y+(1024 >> grid)) & (0xffffffff<<(11-grid));
  3199. }
  3200. asksave = InsertGameObject( searchstat, hitsect, x, y, hitz, ang );
  3201. }
  3202. else
  3203. BeepError();
  3204. break;
  3205. }
  3206. switch (searchstat)
  3207. {
  3208. case SS_WALL:
  3209. case SS_MASKED:
  3210. {
  3211. x = 16384;
  3212. y = divscale(searchx - xdim / 2, xdim / 2, 14);
  3213. RotateVector(&x, &y, ang);
  3214. hitsect = hitwall = hitsprite = -1;
  3215. hitscan(posx, posy, posz, cursectnum, //Start position
  3216. x, y, (searchy - horiz) * 2000, //vector of 3D ang
  3217. &hitsect, &hitwall, &hitsprite, &hitx, &hity, &hitz);
  3218. // NOTE: Unfortunately this case short-circuits masked walls that are not hitscan sensitive.
  3219. if (hitwall != searchwall)
  3220. break;
  3221. int nx, ny;
  3222. short picnum;
  3223. if (somethingintab != SS_SPRITE)
  3224. {
  3225. picnum = tilePick(-1, -1, SS_FLATSPRITE);
  3226. if (picnum == -1)
  3227. break;
  3228. }
  3229. i = insertsprite(searchsector, kStatDefault);
  3230. sprite[i].ang = (short)((GetWallAngle( hitwall ) + kAngle90) & kAngleMask);
  3231. GetWallNormal( hitwall, &nx, &ny );
  3232. sprite[i].x = hitx + (nx >> 14);
  3233. sprite[i].y = hity + (ny >> 14);
  3234. sprite[i].z = hitz;
  3235. if (somethingintab == SS_SPRITE)
  3236. {
  3237. sprite[i].picnum = temppicnum;
  3238. sprite[i].shade = tempshade;
  3239. sprite[i].pal = temppal;
  3240. sprite[i].xrepeat = tempxrepeat;
  3241. sprite[i].yrepeat = tempyrepeat;
  3242. if (sprite[i].xrepeat < 1) sprite[i].xrepeat = 1;
  3243. if (sprite[i].yrepeat < 1) sprite[i].yrepeat = 1;
  3244. sprite[i].cstat = (short)(tempcstat | kSpriteWall | kSpriteOneSided);
  3245. }
  3246. else
  3247. {
  3248. sprite[i].cstat |= kSpriteWall | kSpriteOneSided;
  3249. sprite[i].shade = -8;
  3250. sprite[i].pal = 0;
  3251. sprite[i].picnum = picnum;
  3252. if (tilesizy[sprite[i].picnum] >= 32)
  3253. sprite[i].cstat |= kSpriteBlocking;
  3254. }
  3255. updatenumsprites();
  3256. BeepOkay();
  3257. break;
  3258. }
  3259. case SS_CEILING:
  3260. case SS_FLOOR:
  3261. x = 1 << 14;
  3262. y = divscale(searchx - xdim / 2, xdim / 2, 14);
  3263. RotateVector(&x, &y, ang);
  3264. hitsect = hitwall = hitsprite = -1;
  3265. hitscan(posx, posy, posz, cursectnum, //Start position
  3266. x, y, (searchy-horiz) * 2000, //vector of 3D ang
  3267. &hitsect, &hitwall, &hitsprite, &hitx, &hity, &hitz);
  3268. if (hitsect >= 0)
  3269. {
  3270. x = hitx;
  3271. y = hity;
  3272. if ((gridlock > 0) && (grid > 0))
  3273. {
  3274. x = (x+(1024 >> grid)) & (0xffffffff<<(11-grid));
  3275. y = (y+(1024 >> grid)) & (0xffffffff<<(11-grid));
  3276. }
  3277. short picnum;
  3278. if (somethingintab != SS_SPRITE)
  3279. {
  3280. picnum = tilePick(-1, -1, SS_SPRITE);
  3281. if (picnum == -1)
  3282. break;
  3283. }
  3284. i = insertsprite(hitsect, kStatDefault);
  3285. sprite[i].x = x, sprite[i].y = y;
  3286. if (somethingintab == SS_SPRITE)
  3287. {
  3288. sprite[i].picnum = temppicnum;
  3289. sprite[i].shade = tempshade;
  3290. sprite[i].pal = temppal;
  3291. sprite[i].xrepeat = tempxrepeat;
  3292. sprite[i].yrepeat = tempyrepeat;
  3293. sprite[i].ang = tabang;
  3294. if (sprite[i].xrepeat < 1) sprite[i].xrepeat = 1;
  3295. if (sprite[i].yrepeat < 1) sprite[i].yrepeat = 1;
  3296. sprite[i].cstat = tempcstat;
  3297. }
  3298. else
  3299. {
  3300. sprite[i].shade = -8;
  3301. sprite[i].pal = 0;
  3302. sprite[i].picnum = picnum;
  3303. if (tilesizy[sprite[i].picnum] >= 32)
  3304. sprite[i].cstat |= kSpriteBlocking;
  3305. }
  3306. GetSpriteExtents(&sprite[i], &zTop, &zBot);
  3307. if ( searchstat == SS_FLOOR)
  3308. sprite[i].z += getflorzofslope(hitsect, x, y) - zBot;
  3309. else
  3310. sprite[i].z += getceilzofslope(hitsect, x, y) - zTop;
  3311. // fix sprite type attributes
  3312. AutoAdjustSprites();
  3313. updatenumsprites();
  3314. BeepOkay();
  3315. }
  3316. else
  3317. BeepError();
  3318. break;
  3319. default:
  3320. BeepError();
  3321. }
  3322. break;
  3323. case KEY_T:
  3324. switch (searchstat)
  3325. {
  3326. case SS_MASKED:
  3327. {
  3328. int level = 0;
  3329. if ( wall[searchwall].cstat & kWallTranslucent )
  3330. {
  3331. level = 1;
  3332. if ( wall[searchwall].cstat & kWallTranslucentR )
  3333. level = 2;
  3334. }
  3335. level = IncRotate(level, 3);
  3336. switch ( level )
  3337. {
  3338. case 0:
  3339. wall[searchwall].cstat &= ~kWallTranslucent & ~kWallTranslucentR;
  3340. break;
  3341. case 1:
  3342. wall[searchwall].cstat &= ~kWallTranslucentR;
  3343. wall[searchwall].cstat |= kWallTranslucent;
  3344. break;
  3345. case 2:
  3346. wall[searchwall].cstat |= kWallTranslucent | kWallTranslucentR;
  3347. break;
  3348. }
  3349. if (wall[searchwall].nextwall >= 0)
  3350. {
  3351. wall[wall[searchwall].nextwall].cstat &= ~kWallTranslucent & kWallTranslucentR;
  3352. wall[wall[searchwall].nextwall].cstat |= (short)(wall[searchwall].cstat & (kWallTranslucent | kWallTranslucentR));
  3353. }
  3354. sprintf(buffer, "wall[%i] translucent type %d", searchsector, level);
  3355. scrSetMessage(buffer);
  3356. BeepOkay();
  3357. break;
  3358. }
  3359. case SS_SPRITE:
  3360. {
  3361. int level = 0;
  3362. if ( sprite[searchwall].cstat & kSpriteTranslucent )
  3363. {
  3364. level = 1;
  3365. if ( sprite[searchwall].cstat & kSpriteTranslucentR )
  3366. level = 2;
  3367. }
  3368. level = IncRotate(level, 3);
  3369. switch ( level )
  3370. {
  3371. case 0:
  3372. sprite[searchwall].cstat &= ~kSpriteTranslucent & ~kSpriteTranslucentR;
  3373. break;
  3374. case 1:
  3375. sprite[searchwall].cstat &= ~kSpriteTranslucentR;
  3376. sprite[searchwall].cstat |= kSpriteTranslucent;
  3377. break;
  3378. case 2:
  3379. sprite[searchwall].cstat |= kSpriteTranslucent | kSpriteTranslucentR;
  3380. break;
  3381. }
  3382. sprintf(buffer, "sprite[%i] translucent type %d", searchsector, level);
  3383. scrSetMessage(buffer);
  3384. BeepOkay();
  3385. break;
  3386. }
  3387. default:
  3388. BeepError();
  3389. }
  3390. break;
  3391. case KEY_U:
  3392. for (i = 0; i < numsectors; i++)
  3393. {
  3394. sector[i].visibility = 0;
  3395. }
  3396. scrSetMessage("All sector visibility values set to 0");
  3397. break;
  3398. case KEY_V:
  3399. switch (searchstat)
  3400. {
  3401. case SS_WALL:
  3402. {
  3403. short oldPicnum = wall[searchwall].picnum;
  3404. wall[searchwall].picnum =
  3405. tilePick(wall[searchwall].picnum, wall[searchwall].picnum, SS_WALL);
  3406. vel = svel = angvel = 0;
  3407. if ( wall[searchwall].picnum != oldPicnum )
  3408. BeepOkay();
  3409. break;
  3410. }
  3411. case SS_CEILING:
  3412. {
  3413. short oldPicnum = sector[searchsector].ceilingpicnum;
  3414. sector[searchsector].ceilingpicnum =
  3415. tilePick(sector[searchsector].ceilingpicnum, sector[searchsector].ceilingpicnum, SS_CEILING);
  3416. vel = svel = angvel = 0;
  3417. if (sector[searchsector].ceilingstat & kSectorParallax)
  3418. SetupSky( sector[searchsector].ceilingpicnum );
  3419. else
  3420. sector[searchsector].floorstat &= ~kSectorFloorShade; // clear forced floor shading bit
  3421. if ( sector[searchsector].ceilingpicnum != oldPicnum )
  3422. BeepOkay();
  3423. break;
  3424. }
  3425. case SS_FLOOR:
  3426. {
  3427. short oldPicnum = sector[searchsector].floorpicnum;
  3428. sector[searchsector].floorpicnum =
  3429. tilePick(sector[searchsector].floorpicnum, sector[searchsector].floorpicnum, SS_FLOOR);
  3430. vel = svel = angvel = 0;
  3431. if ( sector[searchsector].floorpicnum != oldPicnum )
  3432. BeepOkay();
  3433. break;
  3434. }
  3435. case SS_SPRITE:
  3436. {
  3437. if ( (sprite[searchwall].cstat & kSpriteRMask) != kSpriteFace )
  3438. searchstat = SS_FLATSPRITE;
  3439. int oldPicnum = sprite[searchwall].picnum;
  3440. sprite[searchwall].picnum =
  3441. tilePick(sprite[searchwall].picnum, sprite[searchwall].picnum, searchstat);
  3442. GetSpriteExtents(&sprite[searchwall], &zTop, &zBot);
  3443. if ( !(sector[sprite[searchwall].sectnum].ceilingstat & kSectorParallax) )
  3444. sprite[searchwall].z += ClipLow(sector[sprite[searchwall].sectnum].ceilingz - zTop, 0);
  3445. if ( !(sector[sprite[searchwall].sectnum].floorstat & kSectorParallax) )
  3446. sprite[searchwall].z += ClipHigh(sector[sprite[searchwall].sectnum].floorz - zBot, 0);
  3447. vel = svel = angvel = 0;
  3448. if ( sprite[searchwall].picnum != oldPicnum )
  3449. BeepOkay();
  3450. break;
  3451. }
  3452. case SS_MASKED:
  3453. {
  3454. dprintf("wall[%d].overpicnum = %d\n",searchwall,wall[searchwall].overpicnum);
  3455. short oldPicnum = wall[searchwall].overpicnum;
  3456. wall[searchwall].overpicnum =
  3457. tilePick(wall[searchwall].overpicnum, wall[searchwall].overpicnum, SS_MASKED);
  3458. vel = svel = angvel = 0;
  3459. if ( wall[searchwall].nextwall >= 0 )
  3460. wall[wall[searchwall].nextwall].overpicnum = wall[searchwall].overpicnum;
  3461. if ( wall[searchwall].overpicnum != oldPicnum )
  3462. BeepOkay();
  3463. break;
  3464. }
  3465. }
  3466. break;
  3467. case KEY_W:
  3468. // change lighting waveform
  3469. nXSector = GetXSector(searchsector);
  3470. do {
  3471. xsector[nXSector].wave = IncRotate(xsector[nXSector].wave, 15);
  3472. } while ( gWaveNames[xsector[nXSector].wave] == NULL );
  3473. scrSetMessage(gWaveNames[xsector[nXSector].wave]);
  3474. break;
  3475. case KEY_PADMINUS:
  3476. gStep = ctrl ? 256 : 1;
  3477. if ( IsSectorHighlight(searchsector) )
  3478. {
  3479. for (i = 0; i < highlightsectorcnt; i++)
  3480. {
  3481. nSector = highlightsector[i];
  3482. sector[nSector].ceilingshade = (schar)ClipHigh(sector[nSector].ceilingshade + gStep, kPalLookups - 1);
  3483. sector[nSector].floorshade = (schar)ClipHigh(sector[nSector].floorshade + gStep, kPalLookups - 1);
  3484. startwall = sector[nSector].wallptr;
  3485. endwall = startwall + sector[nSector].wallnum - 1;
  3486. for (j = startwall; j <= endwall; j++)
  3487. wall[j].shade = (schar)ClipHigh(wall[j].shade + gStep, kPalLookups - 1);
  3488. }
  3489. }
  3490. else
  3491. {
  3492. signed char newshade;
  3493. switch (searchstat)
  3494. {
  3495. case SS_WALL:
  3496. newshade = wall[searchwall].shade = (schar)ClipHigh(wall[searchwall].shade + gStep, kPalLookups - 1);
  3497. break;
  3498. case SS_CEILING:
  3499. newshade = sector[searchsector].ceilingshade = (schar)ClipHigh(sector[searchsector].ceilingshade + gStep, kPalLookups - 1);
  3500. break;
  3501. case SS_FLOOR:
  3502. newshade = sector[searchsector].floorshade = (schar)ClipHigh(sector[searchsector].floorshade + gStep, kPalLookups - 1);
  3503. break;
  3504. case SS_SPRITE:
  3505. newshade = sprite[searchwall].shade = (schar)ClipHigh(sprite[searchwall].shade + gStep, kPalLookups - 1);
  3506. break;
  3507. case SS_MASKED:
  3508. newshade = wall[searchwall].shade = (schar)ClipHigh(wall[searchwall].shade + gStep, kPalLookups - 1);
  3509. break;
  3510. }
  3511. sprintf(buffer, "shade: %i", newshade);
  3512. scrSetMessage(buffer);
  3513. }
  3514. BeepOkay();
  3515. break;
  3516. case KEY_PADPLUS:
  3517. gStep = ctrl ? 256 : 1;
  3518. if ( IsSectorHighlight(searchsector) )
  3519. {
  3520. for( i = 0; i < highlightsectorcnt; i++)
  3521. {
  3522. nSector = highlightsector[i];
  3523. sector[nSector].ceilingshade = (schar)ClipLow(sector[nSector].ceilingshade - gStep, -128);
  3524. sector[nSector].floorshade = (schar)ClipLow(sector[nSector].floorshade - gStep, -128);
  3525. startwall = sector[nSector].wallptr;
  3526. endwall = startwall + sector[nSector].wallnum - 1;
  3527. for(j=startwall;j<=endwall;j++)
  3528. wall[j].shade = (schar)ClipLow(wall[j].shade - 1, -128);
  3529. }
  3530. }
  3531. else
  3532. {
  3533. signed char newshade;
  3534. switch (searchstat)
  3535. {
  3536. case SS_WALL:
  3537. newshade = wall[searchwall].shade = (schar)ClipLow(wall[searchwall].shade - gStep, -128);
  3538. break;
  3539. case SS_CEILING:
  3540. newshade = sector[searchsector].ceilingshade = (schar)ClipLow(sector[searchsector].ceilingshade - gStep, -128);
  3541. break;
  3542. case SS_FLOOR:
  3543. newshade = sector[searchsector].floorshade = (schar)ClipLow(sector[searchsector].floorshade - gStep, -128);
  3544. break;
  3545. case SS_SPRITE:
  3546. newshade = sprite[searchwall].shade = (schar)ClipLow(sprite[searchwall].shade - gStep, -128);
  3547. break;
  3548. case SS_MASKED:
  3549. newshade = wall[searchwall].shade = (schar)ClipLow(wall[searchwall].shade - gStep, -128);
  3550. break;
  3551. }
  3552. sprintf(buffer, "shade: %i", newshade);
  3553. scrSetMessage(buffer);
  3554. }
  3555. BeepOkay();
  3556. break;
  3557. case KEY_PAD0:
  3558. // set the shade of something to 0 brightness
  3559. if ( IsSectorHighlight(searchsector) )
  3560. {
  3561. for( i = 0; i < highlightsectorcnt; i++)
  3562. {
  3563. nSector = highlightsector[i];
  3564. sector[nSector].ceilingshade = 0;
  3565. sector[nSector].floorshade = 0;
  3566. startwall = sector[nSector].wallptr; //wall shade
  3567. endwall = startwall + sector[nSector].wallnum - 1;
  3568. for(j=startwall;j<=endwall;j++)
  3569. wall[j].shade = 0;
  3570. }
  3571. }
  3572. else
  3573. {
  3574. switch (searchstat)
  3575. {
  3576. case SS_WALL:
  3577. wall[searchwall].shade = 0; break;
  3578. case SS_CEILING:
  3579. sector[searchsector].ceilingshade = 0; break;
  3580. case SS_FLOOR:
  3581. sector[searchsector].floorshade = 0; break;
  3582. case SS_SPRITE:
  3583. sprite[searchwall].shade = 0; break;
  3584. case SS_MASKED:
  3585. wall[searchwall].shade = 0; break;
  3586. }
  3587. }
  3588. BeepOkay();
  3589. break;
  3590. case KEY_PADLEFT:
  3591. case KEY_PADRIGHT:
  3592. {
  3593. BOOL bCoarse = gOldKeyMapping ? pad5 : (BOOL)!shift;
  3594. BOOL bPan = gOldKeyMapping ? shift : ctrl;
  3595. changedir = (key == KEY_PADLEFT) ? 1 : -1;
  3596. switch (searchstat)
  3597. {
  3598. case SS_WALL:
  3599. case SS_MASKED:
  3600. if ( bPan )
  3601. {
  3602. wall[searchwall].xpanning = changechar(wall[searchwall].xpanning, changedir, bCoarse, 0);
  3603. sprintf(buffer, "wall %i xpanning: %i ypanning: %i", searchwall,
  3604. wall[searchwall].xpanning, wall[searchwall].ypanning );
  3605. }
  3606. else
  3607. {
  3608. wall[searchwall].xrepeat = changechar(wall[searchwall].xrepeat, changedir, bCoarse, 1);
  3609. sprintf(buffer, "wall %i xrepeat: %i yrepeat: %i", searchwall,
  3610. wall[searchwall].xrepeat, wall[searchwall].yrepeat );
  3611. }
  3612. scrSetMessage(buffer);
  3613. break;
  3614. case SS_CEILING:
  3615. sector[searchsector].ceilingxpanning = changechar(sector[searchsector].ceilingxpanning, changedir, bCoarse, 0);
  3616. break;
  3617. case SS_FLOOR:
  3618. sector[searchsector].floorxpanning = changechar(sector[searchsector].floorxpanning, changedir, bCoarse, 0);
  3619. break;
  3620. case SS_SPRITE:
  3621. if ( bPan )
  3622. {
  3623. sprite[searchwall].xoffset = changechar(sprite[searchwall].xoffset, changedir, bCoarse, 0);
  3624. sprintf(buffer, "sprite %i xoffset: %i yoffset: %i", searchwall,
  3625. sprite[searchwall].xoffset, sprite[searchwall].yoffset);
  3626. }
  3627. else
  3628. {
  3629. sprite[searchwall].xrepeat = (uchar)ClipLow(changechar(sprite[searchwall].xrepeat, -changedir, bCoarse, 1), 4);
  3630. sprintf(buffer, "sprite %i xrepeat: %i yrepeat: %i", searchwall,
  3631. sprite[searchwall].xrepeat, sprite[searchwall].yrepeat);
  3632. }
  3633. scrSetMessage(buffer);
  3634. break;
  3635. }
  3636. BeepOkay();
  3637. break;
  3638. }
  3639. case KEY_PADUP:
  3640. case KEY_PADDOWN:
  3641. {
  3642. BOOL bCoarse = gOldKeyMapping ? pad5 : (BOOL)!shift;
  3643. BOOL bPan = gOldKeyMapping ? shift : ctrl;
  3644. changedir = (key == KEY_PADUP) ? -1 : 1;
  3645. switch (searchstat)
  3646. {
  3647. case SS_WALL:
  3648. case SS_MASKED:
  3649. if ( bPan )
  3650. {
  3651. wall[searchwall].ypanning = changechar(wall[searchwall].ypanning, changedir, bCoarse, 0);
  3652. sprintf(buffer, "wall %i xpanning: %i ypanning: %i", searchwall,
  3653. wall[searchwall].xpanning, wall[searchwall].ypanning );
  3654. }
  3655. else
  3656. {
  3657. wall[searchwall].yrepeat = changechar(wall[searchwall].yrepeat, changedir, bCoarse, 1);
  3658. sprintf(buffer, "wall %i xrepeat: %i yrepeat: %i", searchwall,
  3659. wall[searchwall].xrepeat, wall[searchwall].yrepeat );
  3660. }
  3661. scrSetMessage(buffer);
  3662. break;
  3663. case SS_CEILING:
  3664. sector[searchsector].ceilingypanning = changechar(sector[searchsector].ceilingypanning, changedir, bCoarse, 0);
  3665. break;
  3666. case SS_FLOOR:
  3667. sector[searchsector].floorypanning = changechar(sector[searchsector].floorypanning, changedir, bCoarse, 0);
  3668. break;
  3669. case SS_SPRITE:
  3670. if ( bPan )
  3671. {
  3672. sprite[searchwall].yoffset = changechar(sprite[searchwall].yoffset, changedir, bCoarse, 0);
  3673. sprintf(buffer, "sprite %i xoffset: %i yoffset: %i", searchwall,
  3674. sprite[searchwall].xoffset, sprite[searchwall].yoffset);
  3675. }
  3676. else
  3677. {
  3678. sprite[searchwall].yrepeat = (uchar)ClipLow(changechar(sprite[searchwall].yrepeat, -changedir, bCoarse, 1), 4);
  3679. sprintf(buffer, "sprite %i xrepeat: %i yrepeat: %i", searchwall,
  3680. sprite[searchwall].xrepeat, sprite[searchwall].yrepeat);
  3681. }
  3682. scrSetMessage(buffer);
  3683. break;
  3684. }
  3685. BeepOkay();
  3686. break;
  3687. }
  3688. case KEY_PADENTER:
  3689. overheadeditor();
  3690. clearview(0);
  3691. scrNextPage();
  3692. keyFlushStream();
  3693. CleanUp();
  3694. break;
  3695. case KEY_F2:
  3696. // toggle xstructure state
  3697. switch (searchstat)
  3698. {
  3699. case SS_WALL:
  3700. case SS_MASKED:
  3701. nXWall = wall[searchwall].extra;
  3702. if (nXWall > 0)
  3703. {
  3704. xwall[nXWall].state ^= 1;
  3705. xwall[nXWall].busy = xwall[nXWall].state << 16;
  3706. scrSetMessage(gBoolNames[xwall[nXWall].state]);
  3707. BeepOkay();
  3708. }
  3709. else
  3710. BeepError();
  3711. break;
  3712. case SS_CEILING:
  3713. case SS_FLOOR:
  3714. nXSector = sector[searchsector].extra;
  3715. if (nXSector > 0)
  3716. {
  3717. xsector[nXSector].state ^= 1;
  3718. xsector[nXSector].busy = xsector[nXSector].state << 16;
  3719. scrSetMessage(gBoolNames[xsector[nXSector].state]);
  3720. BeepOkay();
  3721. }
  3722. else
  3723. BeepError();
  3724. break;
  3725. case SS_SPRITE:
  3726. nXSprite = sprite[searchwall].extra;
  3727. if (nXSprite > 0)
  3728. {
  3729. xsprite[nXSprite].state ^= 1;
  3730. xsprite[nXSprite].busy = xsprite[nXSprite].state << 16;
  3731. scrSetMessage(gBoolNames[xsprite[nXSprite].state]);
  3732. BeepOkay();
  3733. }
  3734. else
  3735. BeepError();
  3736. break;
  3737. }
  3738. break;
  3739. case KEY_F3:
  3740. nSector = searchsector;
  3741. if ( alt )
  3742. {
  3743. // capture off positions for sector ceiling and floor height
  3744. switch (searchstat)
  3745. {
  3746. case SS_WALL:
  3747. if (wall[searchwall].nextsector != -1)
  3748. nSector = wall[searchwall].nextsector;
  3749. // fall through to nXSector processing
  3750. case SS_CEILING:
  3751. case SS_FLOOR:
  3752. nXSector = sector[nSector].extra;
  3753. if ( nXSector > 0 )
  3754. {
  3755. xsector[nXSector].offFloorZ = sector[nSector].floorz;
  3756. xsector[nXSector].offCeilZ = sector[nSector].ceilingz;
  3757. sprintf( buffer, "SET offFloorZ= %i offCeilZ= %i",
  3758. xsector[nXSector].offFloorZ, xsector[nXSector].offCeilZ );
  3759. scrSetMessage(buffer);
  3760. BeepOkay();
  3761. asksave = 1;
  3762. } else {
  3763. scrSetMessage("Sector type must first be set in 2D mode.");
  3764. BeepError();
  3765. }
  3766. break;
  3767. }
  3768. break;
  3769. }
  3770. // set sector height to captured off positions
  3771. switch (searchstat)
  3772. {
  3773. case SS_WALL:
  3774. if (wall[searchwall].nextsector != -1)
  3775. nSector = wall[searchwall].nextsector;
  3776. // fall through to nXSector processing
  3777. case SS_CEILING:
  3778. case SS_FLOOR:
  3779. nXSector = sector[nSector].extra;
  3780. if ( nXSector > 0 )
  3781. {
  3782. switch( sector[nSector].type )
  3783. {
  3784. case kSectorZMotion:
  3785. case kSectorZCrusher:
  3786. sector[nSector].floorz = xsector[nXSector].offFloorZ;
  3787. sector[nSector].ceilingz = xsector[nXSector].offCeilZ;
  3788. sprintf( buffer, "SET floorz= %i ceilingz= %i",
  3789. sector[nSector].floorz, sector[nSector].ceilingz );
  3790. scrSetMessage(buffer);
  3791. BeepOkay();
  3792. asksave = 1;
  3793. break;
  3794. }
  3795. } else {
  3796. scrSetMessage("Sector type must first be set in 2D mode.");
  3797. BeepError();
  3798. }
  3799. break;
  3800. }
  3801. break;
  3802. case KEY_F4:
  3803. nSector = searchsector;
  3804. if ( alt )
  3805. {
  3806. // capture on positions for sector ceiling and floor height
  3807. switch (searchstat)
  3808. {
  3809. case SS_WALL:
  3810. if (wall[searchwall].nextsector != -1)
  3811. nSector = wall[searchwall].nextsector;
  3812. // fall through to nXSector processing
  3813. case SS_CEILING:
  3814. case SS_FLOOR:
  3815. nXSector = sector[nSector].extra;
  3816. if ( nXSector > 0 )
  3817. {
  3818. xsector[nXSector].onFloorZ = sector[nSector].floorz;
  3819. xsector[nXSector].onCeilZ = sector[nSector].ceilingz;
  3820. sprintf( buffer, "SET onFloorZ= %i onCeilZ= %i",
  3821. xsector[nXSector].onFloorZ, xsector[nXSector].onCeilZ );
  3822. scrSetMessage(buffer);
  3823. BeepOkay();
  3824. asksave = 1;
  3825. } else {
  3826. scrSetMessage("Sector type must first be set in 2D mode.");
  3827. BeepError();
  3828. }
  3829. break;
  3830. }
  3831. break;
  3832. }
  3833. // set sector height to captured on positions
  3834. switch (searchstat)
  3835. {
  3836. case SS_WALL:
  3837. if (wall[searchwall].nextsector != -1)
  3838. nSector = wall[searchwall].nextsector;
  3839. // fall through to nXSector processing
  3840. case SS_CEILING:
  3841. case SS_FLOOR:
  3842. nXSector = sector[nSector].extra;
  3843. if ( nXSector > 0 )
  3844. {
  3845. switch( sector[nSector].type )
  3846. {
  3847. case kSectorZMotion:
  3848. case kSectorZCrusher:
  3849. sector[nSector].floorz = xsector[nXSector].onFloorZ;
  3850. sector[nSector].ceilingz = xsector[nXSector].onCeilZ;
  3851. sprintf( buffer, "SET floorz= %i ceilingz= %i",
  3852. sector[nSector].floorz, sector[nSector].ceilingz );
  3853. scrSetMessage(buffer);
  3854. BeepOkay();
  3855. asksave = 1;
  3856. break;
  3857. }
  3858. } else {
  3859. scrSetMessage("Sector type must first be set in 2D mode.");
  3860. BeepError();
  3861. }
  3862. break;
  3863. }
  3864. break;
  3865. case KEY_F9:
  3866. // create a set of stairs
  3867. switch (searchstat)
  3868. {
  3869. case SS_FLOOR:
  3870. // clear visited bits
  3871. memset(visited, FALSE, sizeof(visited));
  3872. sector[searchsector].floorstat &= ~0x80;
  3873. gStairHeight = GetNumberBox("Step height", 8, 8);
  3874. BuildStairsF(searchsector);
  3875. break;
  3876. case SS_CEILING:
  3877. // clear visited bits
  3878. memset(visited, FALSE, sizeof(visited));
  3879. sector[searchsector].ceilingstat &= ~0x80;
  3880. gStairHeight = GetNumberBox("Step height", 8, 8);
  3881. BuildStairsC(searchsector);
  3882. break;
  3883. }
  3884. break;
  3885. case KEY_F11:
  3886. gPanning = !gPanning;
  3887. sprintf(buffer, "Global panning is %s", gBoolNames[gPanning]);
  3888. scrSetMessage(buffer);
  3889. BeepOkay();
  3890. break;
  3891. case KEY_F12:
  3892. gBeep = !gBeep;
  3893. sprintf(buffer, "Beeps are %s", gBoolNames[gBeep]);
  3894. scrSetMessage(buffer);
  3895. BeepOkay();
  3896. break;
  3897. case KEY_1:
  3898. switch (searchstat)
  3899. {
  3900. case SS_WALL:
  3901. case SS_MASKED:
  3902. wall[searchwall].cstat ^= kWallOneWay;
  3903. sprintf(buffer, "Wall %i one-way flag is %s", searchwall,
  3904. gBoolNames[wall[searchwall].cstat & kWallOneWay ? 1 : 0 ]);
  3905. scrSetMessage(buffer);
  3906. BeepOkay();
  3907. break;
  3908. case SS_SPRITE:
  3909. sprite[searchwall].cstat ^= kSpriteOneSided;
  3910. i = sprite[searchwall].cstat;
  3911. if ((i & kSpriteRMask) == kSpriteFloor) // floor sprite
  3912. {
  3913. // use y-flip bit to indicate whether its visible from above or below
  3914. sprite[searchwall].cstat &= ~kSpriteFlipY;
  3915. if (i & kSpriteOneSided)
  3916. if (posz > sprite[searchwall].z)
  3917. sprite[searchwall].cstat |= kSpriteFlipY;
  3918. }
  3919. sprintf(buffer, "Sprite %i one-sided flag is %s", searchwall,
  3920. gBoolNames[sprite[searchwall].cstat & kSpriteOneSided ? 1 : 0 ]);
  3921. scrSetMessage(buffer);
  3922. BeepOkay();
  3923. break;
  3924. default:
  3925. BeepError();
  3926. }
  3927. break;
  3928. case KEY_2: // 2 (bottom wall swapping)
  3929. switch (searchstat)
  3930. {
  3931. case SS_WALL:
  3932. case SS_MASKED:
  3933. wall[searchwall].cstat ^= kWallBottomSwap;
  3934. sprintf(buffer, "Wall %i bottom swap flag is %s", searchwall,
  3935. gBoolNames[wall[searchwall].cstat & kWallBottomSwap ? 1 : 0 ]);
  3936. scrSetMessage(buffer);
  3937. BeepOkay();
  3938. break;
  3939. default:
  3940. BeepError();
  3941. }
  3942. break;
  3943. case KEY_PRINTSCREEN:
  3944. screencapture("captxxxx.pcx");
  3945. BeepOkay();
  3946. break;
  3947. }
  3948. // let's see if this fixes the input buffering problem
  3949. if (key != 0)
  3950. keyFlushStream();
  3951. }