KMINE.C 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. /*
  2. * $Source: f:/miner/source/main/editor/rcs/kmine.c $
  3. * $Revision: 2.0 $
  4. * $Author: john $
  5. * $Date: 1995/02/27 11:34:22 $
  6. *
  7. * Functions to change entire mines.
  8. *
  9. * $Log: kmine.c $
  10. * Revision 2.0 1995/02/27 11:34:22 john
  11. * Version 2.0! No anonymous unions, Watcom 10.0, with no need
  12. * for bitmaps.tbl.
  13. *
  14. * Revision 1.53 1995/02/22 15:04:52 allender
  15. * remove anonymous unions from vecmat stuff
  16. *
  17. * Revision 1.52 1994/11/27 23:17:13 matt
  18. * Made changes for new mprintf calling convention
  19. *
  20. * Revision 1.51 1994/11/17 14:48:05 mike
  21. * validation functions moved from editor to game.
  22. *
  23. * Revision 1.50 1994/11/17 11:38:49 matt
  24. * Ripped out code to load old mines
  25. *
  26. * Revision 1.49 1994/10/08 17:10:22 matt
  27. * Correctly set current_level_num when loading/creating mine in editor
  28. *
  29. * Revision 1.48 1994/10/03 11:30:45 matt
  30. * Fixed problem with permanant player position when creating a new mine
  31. *
  32. * Revision 1.47 1994/09/29 17:42:19 matt
  33. * Cleaned up game_mode a little
  34. *
  35. * Revision 1.46 1994/08/18 10:48:21 john
  36. * Cleaned up game sequencing.
  37. *
  38. * Revision 1.45 1994/08/09 16:05:36 john
  39. * Added the ability to place players. Made old
  40. * Player variable be ConsoleObject.
  41. *
  42. * Revision 1.44 1994/07/22 12:37:06 matt
  43. * Cleaned up editor/game interactions some more.
  44. *
  45. * Revision 1.43 1994/07/21 17:26:50 matt
  46. * When new mine created, the default save filename is now reset
  47. *
  48. * Revision 1.42 1994/06/08 14:29:25 matt
  49. * Took out support for old mine versions
  50. *
  51. * Revision 1.41 1994/06/03 12:28:04 yuan
  52. * Fixed game restore state.
  53. *
  54. * Revision 1.40 1994/05/19 12:10:29 matt
  55. * Use new vecmat macros and globals
  56. *
  57. * Revision 1.39 1994/05/14 17:17:56 matt
  58. * Got rid of externs in source (non-header) files
  59. *
  60. * Revision 1.38 1994/05/12 14:47:47 mike
  61. * New previous mine structure and object structure.
  62. *
  63. * Revision 1.37 1994/05/06 12:52:12 yuan
  64. * Adding some gamesave checks...
  65. *
  66. * Revision 1.36 1994/05/05 20:37:02 yuan
  67. * Added gamesave checks when entering and leaving the game.
  68. *
  69. * Removed Load Game Save Game functions...
  70. * Now there is only Load/Save Mine... (equivalent to old Load/Save Game)
  71. *
  72. * Revision 1.35 1994/04/27 22:57:54 matt
  73. * Made sit mine load from path of sit file
  74. *
  75. * Revision 1.34 1994/04/21 18:29:55 matt
  76. * Don't use same variable for mine filename & sit filename
  77. *
  78. * Revision 1.33 1994/04/21 18:21:43 matt
  79. * Strip path from mine filename in sit file
  80. *
  81. * Revision 1.32 1994/04/18 10:54:35 mike
  82. * Add situation save/load
  83. *
  84. * Revision 1.31 1994/02/16 16:47:54 yuan
  85. * Removed temp.min.
  86. *
  87. * Revision 1.30 1994/02/16 15:22:51 yuan
  88. * Checking in for editor make.
  89. *
  90. * Revision 1.29 1994/02/09 15:04:23 yuan
  91. * brought back save ability
  92. *
  93. * Revision 1.28 1994/02/08 12:42:45 yuan
  94. * fixed log.
  95. *
  96. * Revision 1.27 1994/02/08 12:41:47 yuan
  97. * Crippled save mine function from demo version.
  98. *
  99. * Revision 1.26 1994/01/13 13:26:05 yuan
  100. * Added med_compress_mine when creating new mine or
  101. * when loading mine
  102. *
  103. * Revision 1.25 1994/01/11 12:03:23 yuan
  104. * Fixed so that when old mine implementation not in,
  105. * message is displayed when you try to load an old mine
  106. *
  107. * Revision 1.24 1994/01/11 11:47:57 yuan
  108. * *** empty log message ***
  109. *
  110. * Revision 1.23 1994/01/05 09:59:56 yuan
  111. * Added load old mine funciton
  112. *
  113. * Revision 1.22 1993/12/16 15:58:08 john
  114. * moved texture selection page to texpage.c
  115. * ,
  116. *
  117. * Revision 1.21 1993/12/10 14:48:55 mike
  118. * Kill orthogonal views.
  119. *
  120. * Revision 1.20 1993/12/03 16:44:06 yuan
  121. * Changed some 0.0 return values to 0
  122. *
  123. *
  124. * Revision 1.19 1993/12/02 12:39:34 matt
  125. * Removed extra includes
  126. *
  127. * Revision 1.18 1993/11/17 13:14:48 yuan
  128. * Moved Save Group to group.c
  129. *
  130. * Revision 1.17 1993/11/16 17:25:48 yuan
  131. * Unworking group function added...
  132. *
  133. * Revision 1.16 1993/11/15 14:46:25 john
  134. * Changed Menu to MenuX
  135. *
  136. * Revision 1.15 1993/11/08 19:13:45 yuan
  137. * Added Undo command (not working yet)
  138. *
  139. */
  140. #pragma off (unreferenced)
  141. static char rcsid[] = "$Id: kmine.c 2.0 1995/02/27 11:34:22 john Exp $";
  142. #pragma on (unreferenced)
  143. #include <string.h>
  144. #include <stdio.h>
  145. #include <stdlib.h>
  146. #include "error.h"
  147. #include "inferno.h"
  148. #include "editor.h"
  149. #include "ui.h"
  150. #include "texpage.h" // For texpage_goto_first
  151. #include "segment.h"
  152. #include "mono.h"
  153. #include "kdefs.h"
  154. #include "info.h"
  155. #include "game.h"
  156. #include "gameseq.h"
  157. #include "dcflib.h"
  158. #include "nocfile.h"
  159. #include "object.h"
  160. #define MINESAVE_CRIPPLED 0
  161. char mine_filename[128] = "*.MIN";
  162. char sit_filename[128] = "*.SIT";
  163. #define MAX_NAME_LENGTH 128
  164. // See if filename f contains an extent. If not, add extent ext.
  165. void checkforext( char * f, char *ext )
  166. {
  167. int i;
  168. for (i=1; i<MAX_NAME_LENGTH; i++ ) {
  169. if (f[i]=='.')
  170. return;
  171. if ((f[i] == ' ') || (f[i]==0) ) {
  172. f[i] = '.';
  173. f[i+1] = ext[0];
  174. f[i+2] = ext[1];
  175. f[i+3] = ext[2];
  176. f[i+4] = 0;
  177. return;
  178. }
  179. }
  180. if (i < 123) {
  181. f[i] = '.';
  182. f[i+1] = ext[0];
  183. f[i+2] = ext[1];
  184. f[i+3] = ext[2];
  185. f[i+4] = 0;
  186. return;
  187. }
  188. }
  189. // See if filename f contains an extent. If not, add extent ext.
  190. void set_extension( char * f, char *ext )
  191. {
  192. int i;
  193. for (i=1; i<MAX_NAME_LENGTH-4; i++ ) {
  194. if ((f[i]=='.') || (f[i] == ' ') || (f[i]==0) ) {
  195. f[i] = '.';
  196. f[i+1] = ext[0];
  197. f[i+2] = ext[1];
  198. f[i+3] = ext[2];
  199. f[i+4] = 0;
  200. return;
  201. }
  202. }
  203. }
  204. #if MINESAVE_CRIPPLED
  205. int SaveMine()
  206. {
  207. char ErrorMessage[200];
  208. sprintf( ErrorMessage, "Save Mine not available in demo version.\n");
  209. MessageBox( -2, -2, 1, ErrorMessage, "Ok" );
  210. return 1;
  211. }
  212. #endif
  213. #if !MINESAVE_CRIPPLED
  214. int SaveMine()
  215. {
  216. // Save mine
  217. // med_save_mine("TEMP.MIN");
  218. if (ui_get_filename( mine_filename, "*.MIN", "SAVE MINE" ))
  219. {
  220. checkforext(mine_filename, "MIN");
  221. if (med_save_mine(mine_filename))
  222. return 0;
  223. mine_changed = 0;
  224. }
  225. return 1;
  226. }
  227. #endif
  228. int CreateNewMine()
  229. {
  230. if (SafetyCheck()) {
  231. texpage_goto_first();
  232. create_new_mine();
  233. LargeView.ev_matrix = vmd_identity_matrix; //FrontView.ev_matrix;
  234. set_view_target_from_segment(Cursegp);
  235. vm_vec_make(&Seg_scale,DEFAULT_X_SIZE,DEFAULT_Y_SIZE,DEFAULT_Z_SIZE);
  236. Update_flags = UF_WORLD_CHANGED;
  237. SetPlayerFromCurseg();
  238. SetPlayerPosition(); //say default is permanant position
  239. mine_changed = 0;
  240. N_found_segs = 0;
  241. N_selected_segs = 0;
  242. med_compress_mine();
  243. gamestate_not_restored = 0;
  244. init_info = 1;
  245. ResetFilename();
  246. Game_mode = GM_UNKNOWN;
  247. Current_level_num = 0; //0 means not a real game
  248. }
  249. return 1;
  250. }
  251. int MineMenu()
  252. {
  253. int x;
  254. char * MenuItems[] = { "New mine",
  255. "Load mine",
  256. "Save mine",
  257. "Print mine",
  258. "Redraw mine" };
  259. x = MenuX( -1, -1, 5, MenuItems );
  260. switch( x )
  261. {
  262. case 1: // New
  263. CreateNewMine();
  264. break;
  265. case 2: // Load
  266. //@@LoadMine();
  267. break;
  268. case 3: // Save
  269. SaveMine();
  270. break;
  271. case 4: // Print
  272. break;
  273. case 5: // Redraw
  274. Update_flags = UF_ALL;
  275. break;
  276. }
  277. return 1;
  278. }
  279. // -----------------------------------------------------------------------------
  280. // returns 1 if error, else 0
  281. int med_load_situation(char * filename)
  282. {
  283. if (filename[0] == 97)
  284. Int3();
  285. Int3();
  286. return 1;
  287. //@@ CFILE * LoadFile;
  288. //@@ char mine_name[MAX_NAME_LENGTH];
  289. //@@ char dir_name[_MAX_DIR];
  290. //@@ char mine_path[MAX_NAME_LENGTH];
  291. //@@ vms_vector pos;
  292. //@@ fix mat[9];
  293. //@@
  294. //@@ LoadFile = cfopen( filename, "rt" );
  295. //@@ if (!LoadFile) {
  296. //@@ char ErrorMessage[200];
  297. //@@
  298. //@@ sprintf( ErrorMessage, "ERROR: Unable to open %s\n", filename );
  299. //@@ MessageBox( -2, -2, 1, ErrorMessage, "Ok" );
  300. //@@ return 1;
  301. //@@ }
  302. //@@
  303. //@@ fscanf(LoadFile, "%s", &mine_name);
  304. //@@ mprintf((0, "Mine name = [%s]\n", mine_name));
  305. //@@
  306. //@@ _splitpath(filename,mine_path,dir_name,NULL,NULL);
  307. //@@ strcat(mine_path,dir_name);
  308. //@@ strcat(mine_path,mine_name);
  309. //@@
  310. //@@ mprintf((0, "Mine path = [%s]\n", mine_path));
  311. //@@
  312. //@@ med_load_mine(mine_path);
  313. //@@
  314. //@@ fscanf(LoadFile, "%x %x %x", &pos.x, &pos.y, &pos.z);
  315. //@@ mprintf((0, "Load Position = %8x %8x %8x\n", pos.x, pos.y, pos.z));
  316. //@@ mprintf((0, "\n"));
  317. //@@
  318. //@@ fscanf(LoadFile, "%x %x %x", &mat[0], &mat[1], &mat[2]);
  319. //@@ mprintf((0, "%8x %8x %8x\n", mat[0], mat[1], mat[2]));
  320. //@@
  321. //@@ fscanf(LoadFile, "%x %x %x", &mat[3], &mat[4], &mat[5]);
  322. //@@ mprintf((0, "%8x %8x %8x\n", mat[3], mat[4], mat[5]));
  323. //@@
  324. //@@ fscanf(LoadFile, "%x %x %x", &mat[6], &mat[7], &mat[8]);
  325. //@@ mprintf((0, "%8x %8x %8x\n", mat[6], mat[7], mat[8]));
  326. //@@ mprintf((0, "\n"));
  327. //@@
  328. //@@ fscanf(LoadFile, "%i\n", &ConsoleObject->segnum);
  329. //@@
  330. //@@ cfclose( LoadFile );
  331. //@@
  332. //@@ ConsoleObject->pos = pos;
  333. //@@ ConsoleObject->orient.m1 = mat[0]; ConsoleObject->orient.m2 = mat[1]; ConsoleObject->orient.m3 = mat[2];
  334. //@@ ConsoleObject->orient.m4 = mat[3]; ConsoleObject->orient.m5 = mat[4]; ConsoleObject->orient.m6 = mat[5];
  335. //@@ ConsoleObject->orient.m7 = mat[6]; ConsoleObject->orient.m8 = mat[7]; ConsoleObject->orient.m9 = mat[8];
  336. //@@
  337. //@@ return 0;
  338. }
  339. // -----------------------------------------------------------------------------
  340. int med_save_situation(char * filename)
  341. {
  342. CFILE * SaveFile;
  343. char mine_name[MAX_NAME_LENGTH];
  344. SaveFile = cfopen( filename, "wt" );
  345. if (!SaveFile) {
  346. char ErrorMessage[200];
  347. sprintf( ErrorMessage, "ERROR: Unable to open %s\n", filename );
  348. MessageBox( -2, -2, 1, ErrorMessage, "Ok" );
  349. return 1;
  350. }
  351. // Write mine name.
  352. // strcpy(mine_name, filename);
  353. _splitpath(filename,NULL,NULL,mine_name,NULL);
  354. set_extension(mine_name, "min");
  355. fprintf(SaveFile, "%s\n", mine_name);
  356. // Write player position.
  357. fprintf(SaveFile, "%x %x %x\n", ConsoleObject->pos.x, ConsoleObject->pos.y, ConsoleObject->pos.z);
  358. // Write player orientation.
  359. fprintf(SaveFile, "%x %x %x\n", ConsoleObject->orient.rvec.x, ConsoleObject->orient.rvec.y, ConsoleObject->orient.rvec.z);
  360. fprintf(SaveFile, "%x %x %x\n", ConsoleObject->orient.uvec.x, ConsoleObject->orient.uvec.y, ConsoleObject->orient.uvec.z);
  361. fprintf(SaveFile, "%x %x %x\n", ConsoleObject->orient.fvec.x, ConsoleObject->orient.fvec.y, ConsoleObject->orient.fvec.z);
  362. fprintf(SaveFile, "%i\n", ConsoleObject->segnum);
  363. mprintf((0, "Save Position = %8x %8x %8x\n", ConsoleObject->pos.x, ConsoleObject->pos.y, ConsoleObject->pos.z));
  364. mprintf((0, "\n"));
  365. mprintf((0, "%8x %8x %8x\n", ConsoleObject->orient.rvec.x, ConsoleObject->orient.rvec.y, ConsoleObject->orient.rvec.z));
  366. mprintf((0, "%8x %8x %8x\n", ConsoleObject->orient.uvec.x, ConsoleObject->orient.uvec.y, ConsoleObject->orient.uvec.z));
  367. mprintf((0, "%8x %8x %8x\n", ConsoleObject->orient.fvec.x, ConsoleObject->orient.fvec.y, ConsoleObject->orient.fvec.z));
  368. mprintf((0, "\n"));
  369. cfclose( SaveFile);
  370. return 1;
  371. }
  372. // -----------------------------------------------------------------------------
  373. int SaveSituation(void)
  374. {
  375. if (ui_get_filename( sit_filename, "*.SIT", "Save Situation" )) {
  376. set_extension(sit_filename, "MIN");
  377. if (med_save_mine(sit_filename)) {
  378. mprintf((0, "Unable to save mine in SaveSituation.\n"));
  379. return 0;
  380. }
  381. set_extension(sit_filename, "SIT");
  382. if (med_save_situation(sit_filename))
  383. return 0;
  384. }
  385. return 1;
  386. }
  387. // -----------------------------------------------------------------------------
  388. // Load a situation file which consists of x,y,z, orientation matrix, mine name.
  389. int LoadSituation(void)
  390. {
  391. if (SafetyCheck()) {
  392. if (ui_get_filename( sit_filename, "*.sit", "Load Situation" )) {
  393. checkforext(sit_filename, "SIT");
  394. if (med_load_situation(sit_filename))
  395. return 0;
  396. // set_view_target_from_segment(Cursegp);
  397. Update_flags = UF_WORLD_CHANGED;
  398. // SetPlayerFromCurseg();
  399. med_compress_mine();
  400. init_info = 1;
  401. mine_changed = 0;
  402. }
  403. }
  404. return 1;
  405. }
  406.