MED.C 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586
  1. /*
  2. * $Source: f:/miner/source/main/editor/rcs/med.c $
  3. * $Revision: 2.3 $
  4. * $Author: john $
  5. * $Date: 1995/03/06 18:23:52 $
  6. *
  7. * Editor loop for Inferno
  8. *
  9. * $Log: med.c $
  10. * Revision 2.3 1995/03/06 18:23:52 john
  11. * Fixed bug with font screwing up.
  12. *
  13. * Revision 2.2 1995/03/06 16:34:55 john
  14. * Fixed bug with previous.
  15. *
  16. * Revision 2.1 1995/03/06 15:20:57 john
  17. * New screen mode method.
  18. *
  19. * Revision 2.0 1995/02/27 11:35:54 john
  20. * Version 2.0! No anonymous unions, Watcom 10.0, with no need
  21. * for bitmaps.tbl.
  22. *
  23. * Revision 1.192 1994/11/30 12:33:55 mike
  24. * set window clearing mode for editor.
  25. *
  26. * Revision 1.191 1994/11/27 23:17:02 matt
  27. * Made changes for new mprintf calling convention
  28. *
  29. * Revision 1.190 1994/11/19 00:04:33 john
  30. * Changed some shorts to ints.
  31. *
  32. * Revision 1.189 1994/11/17 14:47:57 mike
  33. * validation functions moved from editor to game.
  34. *
  35. * Revision 1.188 1994/11/14 11:41:38 john
  36. * Fixed bug with editor/game sequencing.
  37. *
  38. * Revision 1.187 1994/11/13 15:36:44 john
  39. * Changed game sequencing with editor.
  40. *
  41. * Revision 1.186 1994/11/10 16:49:12 matt
  42. * Don't sort seg list if no segs in list
  43. *
  44. * Revision 1.185 1994/11/08 09:28:39 mike
  45. * reset ai paths on going to game.
  46. *
  47. * Revision 1.184 1994/10/30 14:13:05 mike
  48. * rip out repair center stuff.
  49. *
  50. * Revision 1.183 1994/10/27 10:07:06 mike
  51. * adapt to no inverse table.
  52. *
  53. * Revision 1.182 1994/10/20 12:48:03 matt
  54. * Replaced old save files (MIN/SAV/HOT) with new LVL files
  55. *
  56. * Revision 1.181 1994/10/13 11:39:22 john
  57. * Took out network stuff/.
  58. *
  59. * Revision 1.180 1994/10/07 22:21:38 mike
  60. * Stop Delete-{whatever} from hanging you!
  61. *
  62. * Revision 1.179 1994/10/03 23:39:37 mike
  63. * Adapt to newer, better, fuelcen_activate function.
  64. *
  65. * Revision 1.178 1994/09/30 00:38:05 mike
  66. * Shorten diagnostic message erase -- was erasing outside canvas.
  67. *
  68. * Revision 1.177 1994/09/28 17:31:37 mike
  69. * Add call to check_wall_validity();
  70. *
  71. * Revision 1.176 1994/08/19 10:57:42 mike
  72. * Fix status message erase bug.
  73. *
  74. * Revision 1.175 1994/08/18 10:48:12 john
  75. * Cleaned up game sequencing.
  76. *
  77. * Revision 1.174 1994/08/16 18:11:04 yuan
  78. * Maded C place you in the center of a segment.
  79. *
  80. * Revision 1.173 1994/08/10 19:55:05 john
  81. * Changed font stuff.
  82. *
  83. * Revision 1.172 1994/08/09 16:06:06 john
  84. * Added the ability to place players. Made old
  85. * Player variable be ConsoleObject.
  86. *
  87. * Revision 1.171 1994/08/04 09:14:11 matt
  88. * Fixed problem I said I fixed last time
  89. *
  90. * Revision 1.170 1994/08/04 00:27:57 matt
  91. * When viewing a wall, update the objects segnum if moved out of the segment
  92. *
  93. * Revision 1.169 1994/08/02 14:18:12 mike
  94. * Clean up dialog boxes.
  95. *
  96. * Revision 1.168 1994/07/29 15:34:35 mike
  97. * Kill some mprintfs.
  98. *
  99. * Revision 1.167 1994/07/29 14:56:46 yuan
  100. * Close centers window, when you go into game.
  101. *
  102. * Revision 1.166 1994/07/28 17:16:20 john
  103. * MAde editor use Network stuff.
  104. *
  105. * Revision 1.165 1994/07/28 16:59:10 mike
  106. * objects containing objects.
  107. *
  108. * Revision 1.164 1994/07/22 12:37:07 matt
  109. * Cleaned up editor/game interactions some more.
  110. *
  111. * Revision 1.163 1994/07/21 19:35:11 yuan
  112. * Fixed #include problem
  113. *
  114. * Revision 1.162 1994/07/21 18:02:09 matt
  115. * Don't re-init player stats when going from editor -> game
  116. *
  117. * Revision 1.161 1994/07/21 12:47:53 mike
  118. * Add tilde key functionality for object movement.
  119. *
  120. * Revision 1.160 1994/07/18 10:44:55 mike
  121. * One-click access to keypads.
  122. *
  123. * Revision 1.159 1994/07/01 18:05:54 john
  124. * *** empty log message ***
  125. *
  126. * Revision 1.158 1994/07/01 17:57:06 john
  127. * First version of not-working hostage system
  128. *
  129. *
  130. * Revision 1.157 1994/07/01 11:32:29 john
  131. * *** empty log message ***
  132. *
  133. * Revision 1.156 1994/06/24 17:04:36 john
  134. * *** empty log message ***
  135. *
  136. * Revision 1.155 1994/06/23 15:53:47 matt
  137. * Finished hacking in 3d rendering in big window
  138. *
  139. * Revision 1.154 1994/06/21 16:17:54 yuan
  140. * Init stats when you go to game from editor
  141. *
  142. * Revision 1.153 1994/06/21 12:57:14 yuan
  143. * Remove center from segment function added to menu.
  144. *
  145. */
  146. //#define DEMO 1
  147. #define DIAGNOSTIC_MESSAGE_MAX 90
  148. #define EDITOR_STATUS_MESSAGE_DURATION 4 // Shows for 3+..4 seconds
  149. #pragma off (unreferenced)
  150. static char rcsid[] = "$Id: med.c 2.3 1995/03/06 18:23:52 john Exp $";
  151. #pragma on (unreferenced)
  152. #include <stdio.h>
  153. #include <stdlib.h>
  154. #include <stdarg.h>
  155. #include <string.h>
  156. #include <process.h>
  157. #include <time.h>
  158. //#define INCLUDE_XLISP
  159. #include "inferno.h"
  160. #include "segment.h"
  161. #include "gr.h"
  162. #include "ui.h"
  163. #include "editor.h"
  164. //#include "gamemine.h"
  165. #include "gamesave.h"
  166. #include "gameseg.h"
  167. #include "key.h"
  168. #include "mono.h"
  169. #include "error.h"
  170. #include "kfuncs.h"
  171. #include "macro.h"
  172. #ifdef INCLUDE_XLISP
  173. #include "medlisp.h"
  174. #endif
  175. #include "mem.h"
  176. #include "render.h"
  177. #include "game.h"
  178. #include "slew.h"
  179. #include "kdefs.h"
  180. #include "func.h"
  181. #include "textures.h"
  182. #include "screens.h"
  183. #include "texmap.h"
  184. #include "object.h"
  185. #include "cflib.h"
  186. #include "effects.h"
  187. #include "wall.h"
  188. #include "info.h"
  189. #include "ai.h"
  190. #include "texpage.h" // Textue selection paging stuff
  191. #include "objpage.h" // Object selection paging stuff
  192. #include "medmisc.h"
  193. #include "meddraw.h"
  194. #include "medsel.h"
  195. #include "medrobot.h"
  196. #include "medwall.h"
  197. #include "eswitch.h"
  198. #include "ehostage.h"
  199. #include "centers.h"
  200. #include "fuelcen.h"
  201. #include "gameseq.h"
  202. #include "newmenu.h"
  203. //#define _MARK_ON 1
  204. //#include <wsample.h> //should come after inferno.h to get mark setting
  205. #define COMPRESS_INTERVAL 5 // seconds
  206. //char *undo_status[128];
  207. int initializing;
  208. //these are instances of canvases, pointed to by variables below
  209. grs_canvas _canv_editor_game; //the game on the editor screen
  210. //these are pointers to our canvases
  211. grs_canvas *Canv_editor; //the editor screen
  212. grs_canvas *Canv_editor_game=&_canv_editor_game; //the game on the editor screen
  213. grs_canvas *canv_offscreen; //for off-screen rendering
  214. grs_canvas *Pad_text_canvas; // Keypad text
  215. grs_font *editor_font=NULL;
  216. //where the editor is looking
  217. vms_vector Ed_view_target={0,0,0};
  218. int gamestate_not_restored = 0;
  219. UI_WINDOW * EditorWindow;
  220. int Large_view_index = -1;
  221. UI_GADGET_USERBOX * GameViewBox;
  222. UI_GADGET_USERBOX * LargeViewBox;
  223. UI_GADGET_USERBOX * GroupViewBox;
  224. #if ORTHO_VIEWS
  225. UI_GADGET_USERBOX * TopViewBox;
  226. UI_GADGET_USERBOX * FrontViewBox;
  227. UI_GADGET_USERBOX * RightViewBox;
  228. #endif
  229. UI_GADGET_ICON * ViewIcon;
  230. UI_GADGET_ICON * AllIcon;
  231. UI_GADGET_ICON * AxesIcon;
  232. UI_GADGET_ICON * ChaseIcon;
  233. UI_GADGET_ICON * OutlineIcon;
  234. UI_GADGET_ICON * LockIcon;
  235. //-NOLIGHTICON- UI_GADGET_ICON * LightIcon;
  236. UI_EVENT * DemoBuffer = NULL;
  237. //grs_canvas * BigCanvas[2];
  238. //int CurrentBigCanvas = 0;
  239. //int BigCanvasFirstTime = 1;
  240. int Found_seg_index=0; // Index in Found_segs corresponding to Cursegp
  241. void print_status_bar( char message[DIAGNOSTIC_MESSAGE_MAX] ) {
  242. int w,h,aw;
  243. gr_set_current_canvas( NULL );
  244. gr_set_curfont(editor_font);
  245. gr_set_fontcolor( CBLACK, CGREY );
  246. gr_get_string_size( message, &w, &h, &aw );
  247. gr_string( 4, 583, message );
  248. gr_set_fontcolor( CBLACK, CWHITE );
  249. gr_setcolor( CGREY );
  250. gr_rect( 4+w, 583, 799, 599 );
  251. }
  252. void print_diagnostic( char message[DIAGNOSTIC_MESSAGE_MAX] ) {
  253. int w,h,aw;
  254. gr_set_current_canvas( NULL );
  255. gr_set_curfont(editor_font);
  256. gr_set_fontcolor( CBLACK, CGREY );
  257. gr_get_string_size( message, &w, &h, &aw );
  258. gr_string( 4, 583, message );
  259. gr_set_fontcolor( CBLACK, CWHITE );
  260. gr_setcolor( CGREY );
  261. gr_rect( 4+w, 583, 799, 599 );
  262. }
  263. static char status_line[DIAGNOSTIC_MESSAGE_MAX];
  264. struct tm Editor_status_last_time;
  265. void editor_status( const char *format, ... )
  266. {
  267. va_list ap;
  268. va_start(ap, format);
  269. vsprintf(status_line, format, ap);
  270. va_end(ap);
  271. print_status_bar(status_line);
  272. Editor_status_last_time = Editor_time_of_day;
  273. }
  274. // int tm_sec; /* seconds after the minute -- [0,61] */
  275. // int tm_min; /* minutes after the hour -- [0,59] */
  276. // int tm_hour; /* hours after midnight -- [0,23] */
  277. // int tm_mday; /* day of the month -- [1,31] */
  278. // int tm_mon; /* months since January -- [0,11] */
  279. // int tm_year; /* years since 1900 */
  280. // int tm_wday; /* days since Sunday -- [0,6] */
  281. // int tm_yday; /* days since January 1 -- [0,365]*/
  282. // int tm_isdst; /* Daylight Savings Time flag */
  283. void clear_editor_status(void)
  284. {
  285. int cur_time = Editor_time_of_day.tm_hour * 3600 + Editor_time_of_day.tm_min*60 + Editor_time_of_day.tm_sec;
  286. int erase_time = Editor_status_last_time.tm_hour * 3600 + Editor_status_last_time.tm_min*60 + Editor_status_last_time.tm_sec + EDITOR_STATUS_MESSAGE_DURATION;
  287. if (cur_time > erase_time) {
  288. int i;
  289. char message[DIAGNOSTIC_MESSAGE_MAX];
  290. for (i=0; i<DIAGNOSTIC_MESSAGE_MAX-1; i++)
  291. message[i] = ' ';
  292. message[i] = 0;
  293. print_status_bar(message);
  294. Editor_status_last_time.tm_hour = 99;
  295. }
  296. }
  297. void diagnostic_message( char *format, ... )
  298. {
  299. char diag_line[DIAGNOSTIC_MESSAGE_MAX];
  300. va_list ap;
  301. va_start(ap, format);
  302. vsprintf(diag_line, format, ap);
  303. va_end(ap);
  304. editor_status(diag_line);
  305. }
  306. static char sub_status_line[DIAGNOSTIC_MESSAGE_MAX];
  307. void editor_sub_status( const char *format, ... )
  308. {
  309. int w,h,aw;
  310. va_list ap;
  311. va_start(ap, format);
  312. vsprintf(sub_status_line, format, ap);
  313. va_end(ap);
  314. gr_set_current_canvas( NULL );
  315. gr_set_curfont(editor_font);
  316. gr_set_fontcolor( BM_XRGB(0,0,31), CGREY );
  317. gr_get_string_size( sub_status_line, &w, &h, &aw );
  318. gr_string( 500, 583, sub_status_line );
  319. gr_set_fontcolor( CBLACK, CWHITE );
  320. gr_setcolor( CGREY );
  321. gr_rect( 500+w, 583, 799, 599 );
  322. }
  323. int DropIntoDebugger()
  324. {
  325. Int3();
  326. return 1;
  327. }
  328. #ifdef INCLUDE_XLISP
  329. int CallLisp()
  330. {
  331. medlisp_go();
  332. return 1;
  333. }
  334. #endif
  335. int ExitEditor()
  336. {
  337. if (SafetyCheck()) {
  338. ModeFlag = 1;
  339. }
  340. return 1;
  341. }
  342. int GotoGameCommon(int mode) {
  343. stop_time();
  344. //@@ init_player_stats();
  345. //@@
  346. //@@ Player_init.pos = Player->pos;
  347. //@@ Player_init.orient = Player->orient;
  348. //@@ Player_init.segnum = Player->segnum;
  349. // -- must always save gamesave.sav because the restore-objects code relies on it
  350. // -- that code could be made smarter and use the original file, if appropriate.
  351. // if (mine_changed)
  352. if (gamestate_not_restored == 0) {
  353. gamestate_not_restored = 1;
  354. save_level("GAMESAVE.LVL");
  355. editor_status("Gamestate saved.\n");
  356. mprintf((0, "Gamestate saved.\n"));
  357. }
  358. ai_reset_all_paths();
  359. start_time();
  360. ModeFlag = mode;
  361. return 1;
  362. }
  363. int GotoGameScreen()
  364. {
  365. return GotoGameCommon(3);
  366. }
  367. int GotoGame()
  368. {
  369. return GotoGameCommon(2);
  370. }
  371. void ReadLispMacro( FILE * file, char * buffer )
  372. {
  373. // char c;
  374. // int size=0;
  375. // int pcount = 0;
  376. // char text[100];
  377. // int i=0;
  378. fscanf( file, " { %s } ", buffer );
  379. /*
  380. while (1)
  381. {
  382. c = text[i++];
  383. if (pcount > 0 )
  384. buffer[size++] = c;
  385. if ( c == '(' ) pcount++;
  386. if ( c == ')' ) break;
  387. }
  388. buffer[size++] = 0;
  389. */
  390. return;
  391. }
  392. static int (*KeyFunction[2048])();
  393. void medkey_init()
  394. {
  395. FILE * keyfile;
  396. char keypress[100];
  397. int key;
  398. int i; //, size;
  399. int np;
  400. char * LispCommand;
  401. //MALLOC( LispCommand, char, DIAGNOSTIC_MESSAGE_MAX );//KRB hack
  402. LispCommand = (char *)malloc(DIAGNOSTIC_MESSAGE_MAX*sizeof(char));
  403. for (i=0; i<2048; i++ )
  404. KeyFunction[i] = NULL;
  405. keyfile = fopen( "GLOBAL.KEY", "rt" );
  406. if (keyfile)
  407. {
  408. while (fscanf( keyfile, " %s %s ", keypress, LispCommand ) != EOF )
  409. {
  410. //ReadLispMacro( keyfile, LispCommand );
  411. if ( (key=DecodeKeyText( keypress ))!= -1 )
  412. {
  413. Assert( key < 2048);
  414. KeyFunction[key] = func_get( LispCommand, &np );
  415. } else {
  416. Error( "Bad key %s in GLOBAL.KEY!", keypress );
  417. }
  418. }
  419. fclose(keyfile);
  420. }
  421. free( LispCommand );
  422. }
  423. void init_editor()
  424. {
  425. minit();
  426. ui_init();
  427. init_med_functions(); // Must be called before medlisp_init
  428. ui_pad_read( 0, "segmove.pad" );
  429. ui_pad_read( 1, "segsize.pad" );
  430. ui_pad_read( 2, "curve.pad" );
  431. ui_pad_read( 3, "texture.pad" );
  432. ui_pad_read( 4, "object.pad" );
  433. ui_pad_read( 5, "objmov.pad" );
  434. ui_pad_read( 6, "group.pad" );
  435. ui_pad_read( 7, "lighting.pad" );
  436. ui_pad_read( 8, "test.pad" );
  437. medkey_init();
  438. editor_font = gr_init_font( "pc8x16.fnt" );
  439. menubar_init( "MED.MNU" );
  440. canv_offscreen = gr_create_canvas(LVIEW_W,LVIEW_H);
  441. Draw_all_segments = 1; // Say draw all segments, not just connected ones
  442. init_autosave();
  443. // atexit(close_editor);
  444. Clear_window = 1; // do full window clear.
  445. }
  446. int ShowAbout()
  447. {
  448. MessageBox( -2, -2, 1, "INFERNO Mine Editor\n\n" \
  449. "Copyright (c) 1993 Parallax Software Corp.",
  450. "OK");
  451. return 0;
  452. }
  453. void move_player_2_segment(segment *seg,int side);
  454. int SetPlayerFromCurseg()
  455. {
  456. move_player_2_segment(Cursegp,Curside);
  457. Update_flags |= UF_ED_STATE_CHANGED | UF_GAME_VIEW_CHANGED;
  458. return 1;
  459. }
  460. int fuelcen_create_from_curseg()
  461. {
  462. Cursegp->special = SEGMENT_IS_FUELCEN;
  463. fuelcen_activate( Cursegp, Cursegp->special);
  464. return 1;
  465. }
  466. int repaircen_create_from_curseg()
  467. {
  468. Int3(); // -- no longer supported!
  469. // Cursegp->special = SEGMENT_IS_REPAIRCEN;
  470. // fuelcen_activate( Cursegp, Cursegp->special);
  471. return 1;
  472. }
  473. int controlcen_create_from_curseg()
  474. {
  475. Cursegp->special = SEGMENT_IS_CONTROLCEN;
  476. fuelcen_activate( Cursegp, Cursegp->special);
  477. return 1;
  478. }
  479. int robotmaker_create_from_curseg()
  480. {
  481. Cursegp->special = SEGMENT_IS_ROBOTMAKER;
  482. fuelcen_activate( Cursegp, Cursegp->special);
  483. return 1;
  484. }
  485. int fuelcen_reset_all() {
  486. fuelcen_reset();
  487. return 1;
  488. }
  489. int fuelcen_delete_from_curseg() {
  490. fuelcen_delete( Cursegp );
  491. return 1;
  492. }
  493. //@@//this routine places the viewer in the center of the side opposite to curside,
  494. //@@//with the view toward the center of curside
  495. //@@int SetPlayerFromCursegMinusOne()
  496. //@@{
  497. //@@ vms_vector vp;
  498. //@@
  499. //@@// int newseg,newside;
  500. //@@// get_previous_segment(SEG_PTR_2_NUM(Cursegp),Curside,&newseg,&newside);
  501. //@@// move_player_2_segment(&Segments[newseg],newside);
  502. //@@
  503. //@@ med_compute_center_point_on_side(&Player->obj_position,Cursegp,Side_opposite[Curside]);
  504. //@@ med_compute_center_point_on_side(&vp,Cursegp,Curside);
  505. //@@ vm_vec_sub2(&vp,&Player->position);
  506. //@@ vm_vector_2_matrix(&Player->orient,&vp,NULL,NULL);
  507. //@@
  508. //@@ Player->seg = SEG_PTR_2_NUM(Cursegp);
  509. //@@
  510. //@@ Update_flags |= UF_GAME_VIEW_CHANGED;
  511. //@@ return 1;
  512. //@@}
  513. //this constant determines how much of the window will be occupied by the
  514. //viewed side when SetPlayerFromCursegMinusOne() is called. It actually
  515. //determine how from from the center of the window the farthest point will be
  516. #define SIDE_VIEW_FRAC (f1_0*8/10) //80%
  517. void move_player_2_segment_and_rotate(segment *seg,int side)
  518. {
  519. vms_vector vp;
  520. vms_vector upvec;
  521. static edgenum=0;
  522. compute_segment_center(&ConsoleObject->pos,seg);
  523. compute_center_point_on_side(&vp,seg,side);
  524. vm_vec_sub2(&vp,&ConsoleObject->pos);
  525. vm_vec_sub(&upvec, &Vertices[Cursegp->verts[Side_to_verts[Curside][edgenum%4]]], &Vertices[Cursegp->verts[Side_to_verts[Curside][(edgenum+3)%4]]]);
  526. edgenum++;
  527. vm_vector_2_matrix(&ConsoleObject->orient,&vp,&upvec,NULL);
  528. // vm_vector_2_matrix(&ConsoleObject->orient,&vp,NULL,NULL);
  529. obj_relink( ConsoleObject-Objects, SEG_PTR_2_NUM(seg) );
  530. }
  531. int SetPlayerFromCursegAndRotate()
  532. {
  533. move_player_2_segment_and_rotate(Cursegp,Curside);
  534. Update_flags |= UF_ED_STATE_CHANGED | UF_GAME_VIEW_CHANGED;
  535. return 1;
  536. }
  537. //sets the player facing curseg/curside, normal to face0 of curside, and
  538. //far enough away to see all of curside
  539. int SetPlayerFromCursegMinusOne()
  540. {
  541. vms_vector view_vec,view_vec2,side_center;
  542. vms_vector corner_v[4];
  543. vms_vector upvec;
  544. g3s_point corner_p[4];
  545. int i;
  546. fix max,view_dist=f1_0*10;
  547. static edgenum=0;
  548. int newseg;
  549. view_vec = Cursegp->sides[Curside].normals[0];
  550. vm_vec_negate(&view_vec);
  551. compute_center_point_on_side(&side_center,Cursegp,Curside);
  552. vm_vec_copy_scale(&view_vec2,&view_vec,view_dist);
  553. vm_vec_sub(&ConsoleObject->pos,&side_center,&view_vec2);
  554. vm_vec_sub(&upvec, &Vertices[Cursegp->verts[Side_to_verts[Curside][edgenum%4]]], &Vertices[Cursegp->verts[Side_to_verts[Curside][(edgenum+3)%4]]]);
  555. edgenum++;
  556. vm_vector_2_matrix(&ConsoleObject->orient,&view_vec,&upvec,NULL);
  557. gr_set_current_canvas(Canv_editor_game);
  558. g3_start_frame();
  559. g3_set_view_matrix(&ConsoleObject->pos,&ConsoleObject->orient,Render_zoom);
  560. for (i=max=0;i<4;i++) {
  561. corner_v[i] = Vertices[Cursegp->verts[Side_to_verts[Curside][i]]];
  562. g3_rotate_point(&corner_p[i],&corner_v[i]);
  563. if (labs(corner_p[i].x) > max) max = labs(corner_p[i].x);
  564. if (labs(corner_p[i].y) > max) max = labs(corner_p[i].y);
  565. }
  566. view_dist = fixmul(view_dist,fixdiv(fixdiv(max,SIDE_VIEW_FRAC),corner_p[0].z));
  567. vm_vec_copy_scale(&view_vec2,&view_vec,view_dist);
  568. vm_vec_sub(&ConsoleObject->pos,&side_center,&view_vec2);
  569. //obj_relink(ConsoleObject-Objects, SEG_PTR_2_NUM(Cursegp) );
  570. //update_object_seg(ConsoleObject); //might have backed right out of curseg
  571. newseg = find_point_seg(&ConsoleObject->pos,SEG_PTR_2_NUM(Cursegp) );
  572. if (newseg != -1)
  573. obj_relink(ConsoleObject-Objects,newseg);
  574. Update_flags |= UF_ED_STATE_CHANGED | UF_GAME_VIEW_CHANGED;
  575. return 1;
  576. }
  577. int ToggleLighting(void)
  578. {
  579. char outstr[80] = "[shift-L] ";
  580. int chindex;
  581. Lighting_on++;
  582. if (Lighting_on >= 2)
  583. Lighting_on = 0;
  584. Update_flags |= UF_GAME_VIEW_CHANGED;
  585. if (last_keypress == KEY_L + KEY_SHIFTED)
  586. chindex = 0;
  587. else
  588. chindex = 10;
  589. switch (Lighting_on) {
  590. case 0:
  591. strcpy(&outstr[chindex],"Lighting off.");
  592. break;
  593. case 1:
  594. strcpy(&outstr[chindex],"Static lighting.");
  595. break;
  596. case 2:
  597. strcpy(&outstr[chindex],"Ship lighting.");
  598. break;
  599. case 3:
  600. strcpy(&outstr[chindex],"Ship and static lighting.");
  601. break;
  602. }
  603. diagnostic_message(outstr);
  604. return Lighting_on;
  605. }
  606. void find_concave_segs();
  607. int FindConcaveSegs()
  608. {
  609. find_concave_segs();
  610. Update_flags |= UF_ED_STATE_CHANGED; //list may have changed
  611. return 1;
  612. }
  613. int DosShell()
  614. {
  615. int ok, w, h;
  616. grs_bitmap * save_bitmap;
  617. // Save the current graphics state.
  618. w = grd_curscreen->sc_canvas.cv_bitmap.bm_w;
  619. h = grd_curscreen->sc_canvas.cv_bitmap.bm_h;
  620. save_bitmap = gr_create_bitmap( w, h );
  621. gr_bm_ubitblt(w, h, 0, 0, 0, 0, &(grd_curscreen->sc_canvas.cv_bitmap), save_bitmap );
  622. gr_restore_mode();
  623. printf( "\n\nType EXIT to return to Inferno" );
  624. fflush(stdout);
  625. key_close();
  626. ok = spawnl(P_WAIT,getenv("COMSPEC"), NULL );
  627. key_init();
  628. gr_set_mode(grd_curscreen->sc_mode);
  629. gr_bm_ubitblt(w, h, 0, 0, 0, 0, save_bitmap, &(grd_curscreen->sc_canvas.cv_bitmap));
  630. gr_free_bitmap( save_bitmap );
  631. //gr_pal_setblock( 0, 256, grd_curscreen->pal );
  632. //gr_use_palette_table();
  633. return 1;
  634. }
  635. int ToggleOutlineMode()
  636. { int mode;
  637. mode=toggle_outline_mode();
  638. if (mode)
  639. if (last_keypress != KEY_O)
  640. diagnostic_message("[O] Outline Mode ON.");
  641. else
  642. diagnostic_message("Outline Mode ON.");
  643. else
  644. if (last_keypress != KEY_O)
  645. diagnostic_message("[O] Outline Mode OFF.");
  646. else
  647. diagnostic_message("Outline Mode OFF.");
  648. Update_flags |= UF_GAME_VIEW_CHANGED;
  649. return mode;
  650. }
  651. //@@int do_reset_orient()
  652. //@@{
  653. //@@ slew_reset_orient(SlewObj);
  654. //@@
  655. //@@ Update_flags |= UF_GAME_VIEW_CHANGED;
  656. //@@
  657. //@@ * (ubyte *) 0x417 &= ~0x20;
  658. //@@
  659. //@@ return 1;
  660. //@@}
  661. int GameZoomOut()
  662. {
  663. Render_zoom = fixmul(Render_zoom,68985);
  664. Update_flags |= UF_GAME_VIEW_CHANGED;
  665. return 1;
  666. }
  667. int GameZoomIn()
  668. {
  669. Render_zoom = fixmul(Render_zoom,62259);
  670. Update_flags |= UF_GAME_VIEW_CHANGED;
  671. return 1;
  672. }
  673. int med_keypad_goto_0() { ui_pad_goto(0); return 0; }
  674. int med_keypad_goto_1() { ui_pad_goto(1); return 0; }
  675. int med_keypad_goto_2() { ui_pad_goto(2); return 0; }
  676. int med_keypad_goto_3() { ui_pad_goto(3); return 0; }
  677. int med_keypad_goto_4() { ui_pad_goto(4); return 0; }
  678. int med_keypad_goto_5() { ui_pad_goto(5); return 0; }
  679. int med_keypad_goto_6() { ui_pad_goto(6); return 0; }
  680. int med_keypad_goto_7() { ui_pad_goto(7); return 0; }
  681. int med_keypad_goto_8() { ui_pad_goto(8); return 0; }
  682. #define PAD_WIDTH 30
  683. #define PAD_WIDTH1 (PAD_WIDTH + 7)
  684. int editor_screen_open = 0;
  685. //setup the editors windows, canvases, gadgets, etc.
  686. //called whenever the editor screen is selected
  687. void init_editor_screen()
  688. {
  689. // grs_bitmap * bmp;
  690. if (editor_screen_open) return;
  691. grd_curscreen->sc_canvas.cv_font = editor_font;
  692. //create canvas for game on the editor screen
  693. initializing = 1;
  694. gr_set_current_canvas(Canv_editor);
  695. Canv_editor->cv_font = editor_font;
  696. gr_init_sub_canvas(Canv_editor_game,Canv_editor,GAMEVIEW_X,GAMEVIEW_Y,GAMEVIEW_W,GAMEVIEW_H);
  697. //Editor renders into full (320x200) game screen
  698. init_info = 1;
  699. //do other editor screen setup
  700. // Since the palette might have changed, find some good colors...
  701. CBLACK = gr_find_closest_color( 1, 1, 1 );
  702. CGREY = gr_find_closest_color( 28, 28, 28 );
  703. CWHITE = gr_find_closest_color( 38, 38, 38 );
  704. CBRIGHT = gr_find_closest_color( 60, 60, 60 );
  705. CRED = gr_find_closest_color( 63, 0, 0 );
  706. gr_set_curfont(editor_font);
  707. gr_set_fontcolor( CBLACK, CWHITE );
  708. EditorWindow = ui_open_window( 0 , 0, ED_SCREEN_W, ED_SCREEN_H, WIN_FILLED );
  709. LargeViewBox = ui_add_gadget_userbox( EditorWindow,LVIEW_X,LVIEW_Y,LVIEW_W,LVIEW_H);
  710. #if ORTHO_VIEWS
  711. TopViewBox = ui_add_gadget_userbox( EditorWindow,TVIEW_X,TVIEW_Y,TVIEW_W,TVIEW_H);
  712. FrontViewBox = ui_add_gadget_userbox( EditorWindow,FVIEW_X,FVIEW_Y,FVIEW_W,FVIEW_H);
  713. RightViewBox = ui_add_gadget_userbox( EditorWindow,RVIEW_X,RVIEW_Y,RVIEW_W,RVIEW_H);
  714. #endif
  715. ui_gadget_calc_keys(EditorWindow); //make tab work for all windows
  716. GameViewBox = ui_add_gadget_userbox( EditorWindow, GAMEVIEW_X, GAMEVIEW_Y, GAMEVIEW_W, GAMEVIEW_H );
  717. // GroupViewBox = ui_add_gadget_userbox( EditorWindow,GVIEW_X,GVIEW_Y,GVIEW_W,GVIEW_H);
  718. // GameViewBox->when_tab = GameViewBox->when_btab = (UI_GADGET *) LargeViewBox;
  719. // LargeViewBox->when_tab = LargeViewBox->when_btab = (UI_GADGET *) GameViewBox;
  720. // ui_gadget_calc_keys(EditorWindow); //make tab work for all windows
  721. ViewIcon = ui_add_gadget_icon( EditorWindow, "Lock\nview", 455,25+530, 40, 22, KEY_V+KEY_CTRLED, ToggleLockViewToCursegp );
  722. AllIcon = ui_add_gadget_icon( EditorWindow, "Draw\nall", 500,25+530, 40, 22, KEY_A+KEY_CTRLED, ToggleDrawAllSegments );
  723. AxesIcon = ui_add_gadget_icon( EditorWindow, "Coord\naxes",545,25+530, 40, 22, KEY_D+KEY_CTRLED, ToggleCoordAxes );
  724. //-NOLIGHTICON- LightIcon = ui_add_gadget_icon( EditorWindow, "Light\ning", 590,25+530, 40, 22, KEY_L+KEY_SHIFTED,ToggleLighting );
  725. ChaseIcon = ui_add_gadget_icon( EditorWindow, "Chase\nmode",635,25+530, 40, 22, -1, ToggleChaseMode );
  726. OutlineIcon = ui_add_gadget_icon( EditorWindow, "Out\nline", 680,25+530, 40, 22, KEY_O, ToggleOutlineMode );
  727. LockIcon = ui_add_gadget_icon( EditorWindow, "Lock\nstep", 725,25+530, 40, 22, KEY_L, ToggleLockstep );
  728. meddraw_init_views(LargeViewBox->canvas);
  729. //ui_add_gadget_button( EditorWindow, 460, 510, 50, 25, "Quit", ExitEditor );
  730. //ui_add_gadget_button( EditorWindow, 520, 510, 50, 25, "Lisp", CallLisp );
  731. //ui_add_gadget_button( EditorWindow, 580, 510, 50, 25, "Mine", MineMenu );
  732. //ui_add_gadget_button( EditorWindow, 640, 510, 50, 25, "Help", DoHelp );
  733. //ui_add_gadget_button( EditorWindow, 460, 540, 50, 25, "Macro", MacroMenu );
  734. //ui_add_gadget_button( EditorWindow, 520, 540, 50, 25, "About", ShowAbout );
  735. //ui_add_gadget_button( EditorWindow, 640, 540, 50, 25, "Shell", DosShell );
  736. ui_pad_activate( EditorWindow, PAD_X, PAD_Y );
  737. Pad_text_canvas = gr_create_sub_canvas(Canv_editor, PAD_X + 250, PAD_Y + 8, 180, 160);
  738. ui_add_gadget_button( EditorWindow, PAD_X+6, PAD_Y+(30*5)+22, PAD_WIDTH, 20, "<<", med_keypad_goto_prev );
  739. ui_add_gadget_button( EditorWindow, PAD_X+PAD_WIDTH1+6, PAD_Y+(30*5)+22, PAD_WIDTH, 20, ">>", med_keypad_goto_next );
  740. { int i;
  741. i = 0; ui_add_gadget_button( EditorWindow, PAD_X+16+(i+2)*PAD_WIDTH1, PAD_Y+(30*5)+22, PAD_WIDTH, 20, "SR", med_keypad_goto_0 );
  742. i++; ui_add_gadget_button( EditorWindow, PAD_X+16+(i+2)*PAD_WIDTH1, PAD_Y+(30*5)+22, PAD_WIDTH, 20, "SS", med_keypad_goto_1 );
  743. i++; ui_add_gadget_button( EditorWindow, PAD_X+16+(i+2)*PAD_WIDTH1, PAD_Y+(30*5)+22, PAD_WIDTH, 20, "CF", med_keypad_goto_2 );
  744. i++; ui_add_gadget_button( EditorWindow, PAD_X+16+(i+2)*PAD_WIDTH1, PAD_Y+(30*5)+22, PAD_WIDTH, 20, "TM", med_keypad_goto_3 );
  745. i++; ui_add_gadget_button( EditorWindow, PAD_X+16+(i+2)*PAD_WIDTH1, PAD_Y+(30*5)+22, PAD_WIDTH, 20, "OP", med_keypad_goto_4 );
  746. i++; ui_add_gadget_button( EditorWindow, PAD_X+16+(i+2)*PAD_WIDTH1, PAD_Y+(30*5)+22, PAD_WIDTH, 20, "OR", med_keypad_goto_5 );
  747. i++; ui_add_gadget_button( EditorWindow, PAD_X+16+(i+2)*PAD_WIDTH1, PAD_Y+(30*5)+22, PAD_WIDTH, 20, "GE", med_keypad_goto_6 );
  748. i++; ui_add_gadget_button( EditorWindow, PAD_X+16+(i+2)*PAD_WIDTH1, PAD_Y+(30*5)+22, PAD_WIDTH, 20, "LI", med_keypad_goto_7 );
  749. i++; ui_add_gadget_button( EditorWindow, PAD_X+16+(i+2)*PAD_WIDTH1, PAD_Y+(30*5)+22, PAD_WIDTH, 20, "TT", med_keypad_goto_8 );
  750. }
  751. gr_set_curfont(editor_font);
  752. menubar_show();
  753. // INIT TEXTURE STUFF
  754. texpage_init( EditorWindow );
  755. objpage_init( EditorWindow );
  756. EditorWindow->keyboard_focus_gadget = (UI_GADGET *)LargeViewBox;
  757. canv_offscreen->cv_font = grd_curscreen->sc_canvas.cv_font;
  758. // BigCanvas[0]->cv_font = grd_curscreen->sc_canvas.cv_font;
  759. // BigCanvas[1]->cv_font = grd_curscreen->sc_canvas.cv_font;
  760. // BigCanvasFirstTime = 1;
  761. // Draw status box
  762. gr_set_current_canvas( NULL );
  763. gr_setcolor( CGREY );
  764. gr_rect(STATUS_X,STATUS_Y,STATUS_X+STATUS_W-1,STATUS_Y+STATUS_H-1); //0, 582, 799, 599 );
  765. // Draw icon box
  766. // gr_set_current_canvas( NULL );
  767. // gr_setcolor( CBRIGHT );
  768. // gr_rect( 528, 2, 798, 22);
  769. // gr_setcolor( CGREY);
  770. // gr_rect( 530, 2, 799, 20);
  771. Update_flags = UF_ALL;
  772. initializing = 0;
  773. editor_screen_open = 1;
  774. }
  775. //shutdown ui on the editor screen
  776. close_editor_screen()
  777. {
  778. if (!editor_screen_open) return;
  779. editor_screen_open = 0;
  780. ui_pad_deactivate();
  781. gr_free_sub_canvas(Pad_text_canvas);
  782. ui_close_window(EditorWindow);
  783. close_all_windows();
  784. // CLOSE TEXTURE STUFF
  785. texpage_close();
  786. objpage_close();
  787. menubar_hide();
  788. }
  789. med_show_warning(char *s)
  790. {
  791. grs_canvas *save_canv=grd_curcanv;
  792. //gr_pal_fade_in(grd_curscreen->pal); //in case palette is blacked
  793. MessageBox(-2,-2,1,s,"OK");
  794. gr_set_current_canvas(save_canv);
  795. }
  796. // Returns 1 if OK to trash current mine.
  797. int SafetyCheck()
  798. {
  799. int x;
  800. if (mine_changed) {
  801. stop_time();
  802. x = nm_messagebox( "Warning!", 2, "Cancel", "OK", "You are about to lose work." );
  803. if (x<1) {
  804. start_time();
  805. return 0;
  806. }
  807. start_time();
  808. }
  809. return 1;
  810. }
  811. //called at the end of the program
  812. void close_editor() {
  813. close_autosave();
  814. menubar_close();
  815. gr_close_font(editor_font);
  816. gr_free_canvas(canv_offscreen); canv_offscreen = NULL;
  817. return;
  818. }
  819. //variables for find segments process
  820. // ---------------------------------------------------------------------------------------------------
  821. // Subtract all elements in Found_segs from selected list.
  822. void subtract_found_segments_from_selected_list(void)
  823. {
  824. int s,f;
  825. for (f=0; f<N_found_segs; f++) {
  826. int foundnum = Found_segs[f];
  827. for (s=0; s<N_selected_segs; s++) {
  828. if (Selected_segs[s] == foundnum) {
  829. Selected_segs[s] = Selected_segs[N_selected_segs-1];
  830. N_selected_segs--;
  831. break;
  832. }
  833. }
  834. }
  835. }
  836. // ---------------------------------------------------------------------------------------------------
  837. // Add all elements in Found_segs to selected list.
  838. void add_found_segments_to_selected_list(void) {
  839. int s,f;
  840. for (f=0; f<N_found_segs; f++) {
  841. int foundnum = Found_segs[f];
  842. for (s=0; s<N_selected_segs; s++)
  843. if (Selected_segs[s] == foundnum)
  844. break;
  845. if (s == N_selected_segs)
  846. Selected_segs[N_selected_segs++] = foundnum;
  847. }
  848. }
  849. void gamestate_restore_check() {
  850. char Message[DIAGNOSTIC_MESSAGE_MAX];
  851. obj_position Save_position;
  852. if (gamestate_not_restored) {
  853. sprintf( Message, "Do you wish to restore game state?\n");
  854. if (MessageBox( -2, -2, 2, Message, "Yes", "No" )==1) {
  855. // Save current position
  856. Save_position.pos = ConsoleObject->pos;
  857. Save_position.orient = ConsoleObject->orient;
  858. Save_position.segnum = ConsoleObject->segnum;
  859. load_level("GAMESAVE.LVL");
  860. // Restore current position
  861. if (Save_position.segnum <= Highest_segment_index) {
  862. ConsoleObject->pos = Save_position.pos;
  863. ConsoleObject->orient = Save_position.orient;
  864. obj_relink(ConsoleObject-Objects,Save_position.segnum);
  865. }
  866. gamestate_not_restored = 0;
  867. Update_flags |= UF_WORLD_CHANGED;
  868. }
  869. else
  870. gamestate_not_restored = 1;
  871. }
  872. }
  873. void RestoreGameState() {
  874. load_level("GAMESAVE.LVL");
  875. gamestate_not_restored = 0;
  876. mprintf((0, "Gamestate restored.\n"));
  877. editor_status("Gamestate restored.\n");
  878. Update_flags |= UF_WORLD_CHANGED;
  879. }
  880. extern void check_wall_validity(void);
  881. // ---------------------------------------------------------------------------------------------------
  882. //this function is the editor. called when editor mode selected. runs until
  883. //game mode or exit selected
  884. void editor(void)
  885. {
  886. int w,h;
  887. grs_bitmap * savedbitmap;
  888. editor_view *new_cv;
  889. static padnum=0;
  890. vms_matrix MouseRotMat,tempm;
  891. //@@short camera_objnum; //a camera for viewing
  892. init_editor();
  893. InitCurve();
  894. restore_effect_bitmap_icons();
  895. if (!set_screen_mode(SCREEN_EDITOR)) {
  896. set_screen_mode(SCREEN_GAME);
  897. Function_mode=FMODE_GAME; //force back into game
  898. return;
  899. }
  900. gr_set_current_canvas( NULL );
  901. gr_set_curfont(editor_font);
  902. //Editor renders into full (320x200) game screen
  903. set_warn_func(med_show_warning);
  904. keyd_repeat = 1; // Allow repeat in editor
  905. //_MARK_("start of editor");//Nuked to compile -KRB
  906. ui_mouse_hide();
  907. ui_reset_idle_seconds();
  908. //@@ //create a camera for viewing in the editor. copy position from ConsoleObject
  909. //@@ camera_objnum = obj_create(OBJ_CAMERA,0,ConsoleObject->segnum,&ConsoleObject->pos,&ConsoleObject->orient,0);
  910. //@@ Viewer = &Objects[camera_objnum];
  911. //@@ slew_init(Viewer); //camera is slewing
  912. Viewer = ConsoleObject;
  913. slew_init(ConsoleObject);
  914. Update_flags = UF_ALL;
  915. medlisp_update_screen();
  916. //set the wire-frame window to be the current view
  917. current_view = &LargeView;
  918. if (faded_in==0)
  919. {
  920. faded_in = 1;
  921. //gr_pal_fade_in( grd_curscreen->pal );
  922. }
  923. w = GameViewBox->canvas->cv_bitmap.bm_w;
  924. h = GameViewBox->canvas->cv_bitmap.bm_h;
  925. savedbitmap = gr_create_bitmap(w, h );
  926. gr_bm_ubitblt( w, h, 0, 0, 0, 0, &GameViewBox->canvas->cv_bitmap, savedbitmap );
  927. gr_set_current_canvas( GameViewBox->canvas );
  928. gr_set_curfont(editor_font);
  929. //gr_setcolor( CBLACK );
  930. //gr_deaccent_canvas();
  931. //gr_grey_canvas();
  932. ui_mouse_show();
  933. gr_set_curfont(editor_font);
  934. ui_pad_goto(padnum);
  935. gamestate_restore_check();
  936. while (Function_mode == FMODE_EDITOR) {
  937. gr_set_curfont(editor_font);
  938. info_display_all(EditorWindow);
  939. ModeFlag = 0;
  940. // Update the windows
  941. // Only update if there is no key waiting and we're not in
  942. // fast play mode.
  943. if (!key_peekkey()) //-- && (MacroStatus != UI_STATUS_FASTPLAY))
  944. medlisp_update_screen();
  945. //do editor stuff
  946. gr_set_curfont(editor_font);
  947. ui_mega_process();
  948. last_keypress &= ~KEY_DEBUGGED; // mask off delete key bit which has no function in editor.
  949. ui_window_do_gadgets(EditorWindow);
  950. do_robot_window();
  951. do_object_window();
  952. do_wall_window();
  953. do_trigger_window();
  954. do_hostage_window();
  955. do_centers_window();
  956. check_wall_validity();
  957. Assert(Num_walls>=0);
  958. if (Gameview_lockstep) {
  959. static segment *old_cursegp=NULL;
  960. static int old_curside=-1;
  961. if (old_cursegp!=Cursegp || old_curside!=Curside) {
  962. SetPlayerFromCursegMinusOne();
  963. old_cursegp = Cursegp;
  964. old_curside = Curside;
  965. }
  966. }
  967. // mprintf((0, "%d ", ui_get_idle_seconds() ));
  968. if ( ui_get_idle_seconds() > COMPRESS_INTERVAL )
  969. {
  970. med_compress_mine();
  971. ui_reset_idle_seconds();
  972. }
  973. // Commented out because it occupies about 25% of time in twirling the mine.
  974. // Removes some Asserts....
  975. // med_check_all_vertices();
  976. clear_editor_status(); // if enough time elapsed, clear editor status message
  977. TimedAutosave(mine_filename);
  978. set_editor_time_of_day();
  979. gr_set_current_canvas( GameViewBox->canvas );
  980. // Remove keys used for slew
  981. switch(last_keypress)
  982. {
  983. case KEY_PAD9:
  984. case KEY_PAD7:
  985. case KEY_PADPLUS:
  986. case KEY_PADMINUS:
  987. case KEY_PAD8:
  988. case KEY_PAD2:
  989. case KEY_LBRACKET:
  990. case KEY_RBRACKET:
  991. case KEY_PAD1:
  992. case KEY_PAD3:
  993. case KEY_PAD6:
  994. case KEY_PAD4:
  995. last_keypress = 0;
  996. }
  997. if ((last_keypress&0xff)==KEY_LSHIFT) last_keypress=0;
  998. if ((last_keypress&0xff)==KEY_RSHIFT) last_keypress=0;
  999. if ((last_keypress&0xff)==KEY_LCTRL) last_keypress=0;
  1000. if ((last_keypress&0xff)==KEY_RCTRL) last_keypress=0;
  1001. // if ((last_keypress&0xff)==KEY_LALT) last_keypress=0;
  1002. // if ((last_keypress&0xff)==KEY_RALT) last_keypress=0;
  1003. gr_set_curfont(editor_font);
  1004. menubar_do( last_keypress );
  1005. //=================== DO FUNCTIONS ====================
  1006. if ( KeyFunction[ last_keypress ] != NULL ) {
  1007. KeyFunction[last_keypress]();
  1008. last_keypress = 0;
  1009. }
  1010. switch (last_keypress)
  1011. {
  1012. case 0:
  1013. case KEY_Z:
  1014. case KEY_G:
  1015. case KEY_LALT:
  1016. case KEY_RALT:
  1017. case KEY_LCTRL:
  1018. case KEY_RCTRL:
  1019. case KEY_LSHIFT:
  1020. case KEY_RSHIFT:
  1021. case KEY_LAPOSTRO:
  1022. break;
  1023. case KEY_SHIFTED + KEY_L:
  1024. ToggleLighting();
  1025. break;
  1026. case KEY_F1:
  1027. render_3d_in_big_window = !render_3d_in_big_window;
  1028. Update_flags |= UF_ALL;
  1029. break;
  1030. default:
  1031. {
  1032. char kdesc[100];
  1033. GetKeyDescription( kdesc, last_keypress );
  1034. editor_status("Error: %s isn't bound to anything.", kdesc );
  1035. }
  1036. }
  1037. //================================================================
  1038. if (ModeFlag==1)
  1039. {
  1040. close_editor_screen();
  1041. Function_mode=FMODE_EXIT;
  1042. gr_free_bitmap( savedbitmap );
  1043. break;
  1044. }
  1045. if (ModeFlag==2) //-- && MacroStatus==UI_STATUS_NORMAL )
  1046. {
  1047. ui_mouse_hide();
  1048. Function_mode = FMODE_GAME;
  1049. gr_bm_ubitblt( w, h, 0, 0, 0, 0, savedbitmap, &GameViewBox->canvas->cv_bitmap);
  1050. gr_free_bitmap( savedbitmap );
  1051. break;
  1052. }
  1053. if (ModeFlag==3) //-- && MacroStatus==UI_STATUS_NORMAL )
  1054. {
  1055. // med_compress_mine(); //will be called anyways before game.
  1056. close_editor_screen();
  1057. Function_mode=FMODE_GAME; //force back into game
  1058. set_screen_mode(SCREEN_GAME); //put up game screen
  1059. gr_free_bitmap( savedbitmap );
  1060. break;
  1061. }
  1062. // if (CurWindow->keyboard_focus_gadget == (UI_GADGET *)GameViewBox) current_view=NULL;
  1063. // if (CurWindow->keyboard_focus_gadget == (UI_GADGET *)GroupViewBox) current_view=NULL;
  1064. new_cv = current_view ;
  1065. #if ORTHO_VIEWS
  1066. if (CurWindow->keyboard_focus_gadget == (UI_GADGET *)LargeViewBox) new_cv=&LargeView;
  1067. if (CurWindow->keyboard_focus_gadget == (UI_GADGET *)TopViewBox) new_cv=&TopView;
  1068. if (CurWindow->keyboard_focus_gadget == (UI_GADGET *)FrontViewBox) new_cv=&FrontView;
  1069. if (CurWindow->keyboard_focus_gadget == (UI_GADGET *)RightViewBox) new_cv=&RightView;
  1070. #endif
  1071. if (new_cv != current_view ) {
  1072. current_view->ev_changed = 1;
  1073. new_cv->ev_changed = 1;
  1074. current_view = new_cv;
  1075. }
  1076. calc_frame_time();
  1077. if (slew_frame(0))
  1078. { //do movement and check keys
  1079. Update_flags |= UF_GAME_VIEW_CHANGED;
  1080. if (Gameview_lockstep) {
  1081. Cursegp = &Segments[ConsoleObject->segnum];
  1082. med_create_new_segment_from_cursegp();
  1083. Update_flags |= UF_ED_STATE_CHANGED;
  1084. }
  1085. }
  1086. // DO TEXTURE STUFF
  1087. texpage_do();
  1088. objpage_do();
  1089. // Process selection of Cursegp using mouse.
  1090. if (LargeViewBox->mouse_onme && LargeViewBox->b1_clicked && !render_3d_in_big_window)
  1091. {
  1092. int xcrd,ycrd;
  1093. xcrd = LargeViewBox->b1_drag_x1;
  1094. ycrd = LargeViewBox->b1_drag_y1;
  1095. find_segments(xcrd,ycrd,LargeViewBox->canvas,&LargeView,Cursegp,Big_depth); // Sets globals N_found_segs, Found_segs
  1096. // If shift is down, then add segment to found list
  1097. if (keyd_pressed[ KEY_LSHIFT ] || keyd_pressed[ KEY_RSHIFT ])
  1098. subtract_found_segments_from_selected_list();
  1099. else
  1100. add_found_segments_to_selected_list();
  1101. Found_seg_index = 0;
  1102. if (N_found_segs > 0) {
  1103. sort_seg_list(N_found_segs,Found_segs,&ConsoleObject->pos);
  1104. Cursegp = &Segments[Found_segs[0]];
  1105. med_create_new_segment_from_cursegp();
  1106. if (Lock_view_to_cursegp)
  1107. set_view_target_from_segment(Cursegp);
  1108. }
  1109. Update_flags |= UF_ED_STATE_CHANGED | UF_VIEWPOINT_MOVED;
  1110. }
  1111. if (GameViewBox->mouse_onme && GameViewBox->b1_dragging) {
  1112. int x, y;
  1113. x = GameViewBox->b1_drag_x2;
  1114. y = GameViewBox->b1_drag_y2;
  1115. ui_mouse_hide();
  1116. gr_set_current_canvas( GameViewBox->canvas );
  1117. gr_setcolor( 15 );
  1118. gr_rect( x-1, y-1, x+1, y+1 );
  1119. ui_mouse_show();
  1120. }
  1121. // Set current segment and side by clicking on a polygon in game window.
  1122. // If ctrl pressed, also assign current texture map to that side.
  1123. //if (GameViewBox->mouse_onme && (GameViewBox->b1_done_dragging || GameViewBox->b1_clicked)) {
  1124. if ((GameViewBox->mouse_onme && GameViewBox->b1_clicked && !render_3d_in_big_window) ||
  1125. (LargeViewBox->mouse_onme && LargeViewBox->b1_clicked && render_3d_in_big_window)) {
  1126. int xcrd,ycrd;
  1127. int seg,side,face,poly,tmap;
  1128. if (render_3d_in_big_window) {
  1129. xcrd = LargeViewBox->b1_drag_x1;
  1130. ycrd = LargeViewBox->b1_drag_y1;
  1131. }
  1132. else {
  1133. xcrd = GameViewBox->b1_drag_x1;
  1134. ycrd = GameViewBox->b1_drag_y1;
  1135. }
  1136. //Int3();
  1137. if (find_seg_side_face(xcrd,ycrd,&seg,&side,&face,&poly)) {
  1138. if (seg<0) { //found an object
  1139. Cur_object_index = -seg-1;
  1140. editor_status("Object %d selected.",Cur_object_index);
  1141. Update_flags |= UF_ED_STATE_CHANGED;
  1142. }
  1143. else {
  1144. // See if either shift key is down and, if so, assign texture map
  1145. if (keyd_pressed[KEY_LSHIFT] || keyd_pressed[KEY_RSHIFT]) {
  1146. Cursegp = &Segments[seg];
  1147. Curside = side;
  1148. AssignTexture();
  1149. med_create_new_segment_from_cursegp();
  1150. editor_status("Texture assigned");
  1151. } else if (keyd_pressed[KEY_G]) {
  1152. tmap = Segments[seg].sides[side].tmap_num;
  1153. texpage_grab_current(tmap);
  1154. editor_status( "Texture grabbed." );
  1155. } else if (keyd_pressed[ KEY_LAPOSTRO] ) {
  1156. ui_mouse_hide();
  1157. move_object_to_mouse_click();
  1158. } else {
  1159. Cursegp = &Segments[seg];
  1160. Curside = side;
  1161. med_create_new_segment_from_cursegp();
  1162. editor_status("Curseg and curside selected");
  1163. }
  1164. }
  1165. Update_flags |= UF_ED_STATE_CHANGED;
  1166. }
  1167. else
  1168. editor_status("Click on non-texture ingored");
  1169. }
  1170. // Allow specification of LargeView using mouse
  1171. if (keyd_pressed[ KEY_LCTRL ] || keyd_pressed[ KEY_RCTRL ]) {
  1172. ui_mouse_hide();
  1173. if ( (Mouse.dx!=0) && (Mouse.dy!=0) ) {
  1174. GetMouseRotation( Mouse.dx, Mouse.dy, &MouseRotMat );
  1175. vm_matrix_x_matrix(&tempm,&LargeView.ev_matrix,&MouseRotMat);
  1176. LargeView.ev_matrix = tempm;
  1177. LargeView.ev_changed = 1;
  1178. Large_view_index = -1; // say not one of the orthogonal views
  1179. }
  1180. } else {
  1181. ui_mouse_show();
  1182. }
  1183. if ( keyd_pressed[ KEY_Z ] ) {
  1184. ui_mouse_hide();
  1185. if ( Mouse.dy!=0 ) {
  1186. current_view->ev_dist += Mouse.dy*10000;
  1187. current_view->ev_changed = 1;
  1188. }
  1189. } else {
  1190. ui_mouse_show();
  1191. }
  1192. }
  1193. // _MARK_("end of editor");//Nuked to compile -KRB
  1194. clear_warn_func(med_show_warning);
  1195. //kill our camera object
  1196. Viewer = ConsoleObject; //reset viewer
  1197. //@@obj_delete(camera_objnum);
  1198. padnum = ui_pad_get_current();
  1199. close_editor();
  1200. ui_close();
  1201. }
  1202. void test_fade(void)
  1203. {
  1204. int i,c;
  1205. for (c=0; c<256; c++) {
  1206. printf("%4i: {%3i %3i %3i} ",c,gr_palette[3*c],gr_palette[3*c+1],gr_palette[3*c+2]);
  1207. for (i=0; i<16; i++) {
  1208. int col = gr_fade_table[256*i+c];
  1209. printf("[%3i %3i %3i] ",gr_palette[3*col],gr_palette[3*col+1],gr_palette[3*col+2]);
  1210. }
  1211. if ( (c%16) == 15)
  1212. printf("\n");
  1213. printf("\n");
  1214. }
  1215. }
  1216. void dump_stuff(void)
  1217. {
  1218. int i,j,prev_color;
  1219. printf("Palette:\n");
  1220. for (i=0; i<256; i++)
  1221. printf("%3i: %2i %2i %2i\n",i,gr_palette[3*i],gr_palette[3*i+1],gr_palette[3*i+2]);
  1222. for (i=0; i<16; i++) {
  1223. printf("\nFade table #%i\n",i);
  1224. for (j=0; j<256; j++) {
  1225. int c = gr_fade_table[i*256 + j];
  1226. printf("[%3i %2i %2i %2i] ",c, gr_palette[3*c], gr_palette[3*c+1], gr_palette[3*c+2]);
  1227. if ((j % 8) == 7)
  1228. printf("\n");
  1229. }
  1230. }
  1231. printf("Colors indexed by intensity:\n");
  1232. printf(". = change from previous, * = no change\n");
  1233. for (j=0; j<256; j++) {
  1234. printf("%3i: ",j);
  1235. prev_color = -1;
  1236. for (i=0; i<16; i++) {
  1237. int c = gr_fade_table[i*256 + j];
  1238. if (c == prev_color)
  1239. printf("*");
  1240. else
  1241. printf(".");
  1242. prev_color = c;
  1243. }
  1244. printf(" ");
  1245. for (i=0; i<16; i++) {
  1246. int c = gr_fade_table[i*256 + j];
  1247. printf("[%3i %2i %2i %2i] ", c, gr_palette[3*c], gr_palette[3*c+1], gr_palette[3*c+2]);
  1248. }
  1249. printf("\n");
  1250. }
  1251. }
  1252. int MarkStart(void)
  1253. {
  1254. char mystr[30];
  1255. sprintf(mystr,"mark %i start",Mark_count);
  1256. // _MARK_(mystr);//Nuked to compile -KRB
  1257. return 1;
  1258. }
  1259. int MarkEnd(void)
  1260. {
  1261. char mystr[30];
  1262. sprintf(mystr,"mark %i end",Mark_count);
  1263. Mark_count++;
  1264. // _MARK_(mystr);//Nuked to compile -KRB
  1265. return 1;
  1266. }
  1267.