Subversion Repositories Games.Descent

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Portions of this file are copyright Rebirth contributors and licensed as
  3.  * described in COPYING.txt.
  4.  * Portions of this file are copyright Parallax Software and licensed
  5.  * according to the Parallax license below.
  6.  * See COPYING.txt for license details.
  7.  
  8. THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  9. SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
  10. END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  11. ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  12. IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  13. SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  14. FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  15. CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
  16. AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
  17. COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
  18. */
  19.  
  20. /*
  21.  *
  22.  * Functions to change entire mines.
  23.  *
  24.  */
  25.  
  26. #include <string.h>
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29. #include "dxxerror.h"
  30. #include "strutil.h"
  31. #include "inferno.h"
  32. #include "editor.h"
  33. #include "editor/esegment.h"
  34. #include "editor/medmisc.h"
  35. #include "ui.h"
  36. #include "texpage.h"            // For texpage_goto_first
  37. #include "segment.h"
  38. #include "kdefs.h"
  39. #include "info.h"
  40. #include "game.h"
  41. #include "physfsx.h"
  42. #include "gameseq.h"
  43. #include "object.h"
  44.  
  45. char mine_filename[PATH_MAX] = "*.MIN";
  46. static char sit_filename[PATH_MAX] = "*.SIT";
  47.  
  48. #define MAX_NAME_LENGTH PATH_MAX
  49.  
  50. //      See if filename f contains an extent.  If not, add extent ext.
  51. static void checkforext( char * f, const char *ext )
  52. {
  53.         int i;
  54.  
  55.         for (i=1; i<MAX_NAME_LENGTH; i++ ) {
  56.                 if (f[i]=='.')
  57.                         return;
  58.  
  59.                 if ((f[i] == ' ') || (f[i]==0) ) {
  60.                         f[i] = '.';
  61.                         f[i+1] = ext[0];
  62.                         f[i+2] = ext[1];
  63.                         f[i+3] = ext[2];
  64.                         f[i+4] = 0;
  65.                         return;
  66.                 }
  67.         }
  68.  
  69.         if (i < 123) {
  70.                 f[i] = '.';
  71.                 f[i+1] = ext[0];
  72.                 f[i+2] = ext[1];
  73.                 f[i+3] = ext[2];
  74.                 f[i+4] = 0;
  75.                 return;
  76.         }
  77. }
  78.  
  79. //      See if filename f contains an extent.  If not, add extent ext.
  80. static void set_extension( char * f, const char *ext )
  81. {
  82.         int i;
  83.  
  84.         for (i=1; i<MAX_NAME_LENGTH-4; i++ ) {
  85.                 if ((f[i]=='.') || (f[i] == ' ') || (f[i]==0) ) {
  86.                         f[i] = '.';
  87.                         f[i+1] = ext[0];
  88.                         f[i+2] = ext[1];
  89.                         f[i+3] = ext[2];
  90.                         f[i+4] = 0;
  91.                         return;
  92.                 }
  93.         }
  94. }
  95.  
  96. int SaveMine()
  97. {
  98.         // Save mine
  99. //      med_save_mine("TEMP.MIN");
  100.     if (ui_get_filename( mine_filename, "*.MIN", "SAVE MINE" ))
  101.         {
  102.         checkforext(mine_filename, "MIN");
  103.         if (med_save_mine(mine_filename))
  104.                         return 0;
  105.                 mine_changed = 0;
  106.         }
  107.        
  108.         return 1;
  109. }
  110.  
  111. int CreateNewMine()
  112. {
  113.         auto &LevelSharedVertexState = LevelSharedSegmentState.get_vertex_state();
  114.         auto &Vertices = LevelSharedVertexState.get_vertices();
  115.         if (SafetyCheck())  {
  116.                 texpage_goto_first();
  117.                 create_new_mine();
  118.                 LargeView.ev_matrix = vmd_identity_matrix;      //FrontView.ev_matrix;
  119.                 auto &vcvertptr = Vertices.vcptr;
  120.                 set_view_target_from_segment(vcvertptr, Cursegp);
  121.                 Update_flags = UF_WORLD_CHANGED;
  122.                 SetPlayerFromCurseg();
  123.                 SetPlayerPosition();            //say default is permanant position
  124.                 mine_changed = 0;
  125.                 Found_segs.clear();
  126.                 Selected_segs.clear();
  127.                 med_compress_mine();
  128.                 gamestate = editor_gamestate::none;
  129.                 init_info = 1;
  130.                 ResetFilename();
  131.                 Game_mode = GM_UNKNOWN;
  132.                 Current_level_num = 1;          // make level 1
  133.         }
  134.         return 1;
  135. }
  136.  
  137. int MineMenu()
  138. {
  139.         int x;
  140.         static const char *const MenuItems[] = { "New mine",
  141.                                            "Load mine",
  142.                                            "Save mine",
  143.                                            "Print mine",
  144.                                            "Redraw mine" };
  145.  
  146.         x = MenuX( -1, -1, 5, MenuItems );
  147.  
  148.         switch( x )
  149.         {
  150.         case 1:     // New
  151.                 CreateNewMine();
  152.                 break;
  153.         case 2:     // Load
  154.                 //@@LoadMine();
  155.                 break;
  156.         case 3:     // Save
  157.                 SaveMine();
  158.                 break;
  159.         case 4:     // Print
  160.                 break;
  161.         case 5:     // Redraw
  162.                 Update_flags = UF_ALL;
  163.                 break;
  164.         }
  165.         return 1;
  166. }
  167.  
  168. // -----------------------------------------------------------------------------
  169. // returns 1 if error, else 0
  170. static int med_load_situation(char * filename)
  171. {
  172.         if (filename[0] == 97)
  173.                 Int3();
  174.         Int3();
  175.  
  176.         return 1;
  177. }
  178.  
  179. //      -----------------------------------------------------------------------------
  180. static int med_save_situation(char * filename)
  181. {
  182.         auto SaveFile = PHYSFSX_openWriteBuffered(filename);
  183.         if (!SaveFile)  {
  184.                 char  ErrorMessage[512];
  185.  
  186.                 snprintf(ErrorMessage, sizeof(ErrorMessage), "ERROR: Unable to open %.480s", filename);
  187.                 ui_messagebox( -2, -2, 1, ErrorMessage, "Ok" );
  188.                 return 1;
  189.         }
  190.  
  191.         //      Write mine name.
  192.         struct splitpath_t path;
  193.         d_splitpath(filename, &path);
  194.         PHYSFSX_printf(SaveFile, "%.*s.min\n", DXX_ptrdiff_cast_int(path.base_end - path.base_start), path.base_start);
  195.  
  196.         //      Write player position.
  197.         PHYSFSX_printf(SaveFile, "%x %x %x\n",static_cast<unsigned>(ConsoleObject->pos.x),static_cast<unsigned>(ConsoleObject->pos.y),static_cast<unsigned>(ConsoleObject->pos.z));
  198.  
  199.         //      Write player orientation.
  200.         PHYSFSX_printf(SaveFile, "%8x %8x %8x\n",static_cast<unsigned>(ConsoleObject->orient.rvec.x),static_cast<unsigned>(ConsoleObject->orient.rvec.y),static_cast<unsigned>(ConsoleObject->orient.rvec.z));
  201.         PHYSFSX_printf(SaveFile, "%8x %8x %8x\n",static_cast<unsigned>(ConsoleObject->orient.uvec.x),static_cast<unsigned>(ConsoleObject->orient.uvec.y),static_cast<unsigned>(ConsoleObject->orient.uvec.z));
  202.         PHYSFSX_printf(SaveFile, "%8x %8x %8x\n",static_cast<unsigned>(ConsoleObject->orient.fvec.x),static_cast<unsigned>(ConsoleObject->orient.fvec.y),static_cast<unsigned>(ConsoleObject->orient.fvec.z));
  203.         PHYSFSX_printf(SaveFile, "%i\n", ConsoleObject->segnum);
  204.         return 1;
  205. }
  206.  
  207. //      -----------------------------------------------------------------------------
  208. int SaveSituation(void)
  209. {
  210.         if (ui_get_filename( sit_filename, "*.SIT", "Save Situation" )) {
  211.                 set_extension(sit_filename, "MIN");
  212.                 if (med_save_mine(sit_filename)) {
  213.                         return 0;
  214.                 }
  215.  
  216.                 set_extension(sit_filename, "SIT");
  217.                 if (med_save_situation(sit_filename))
  218.                         return 0;
  219.         }
  220.        
  221.         return 1;
  222. }
  223.  
  224. //      -----------------------------------------------------------------------------
  225. //      Load a situation file which consists of x,y,z, orientation matrix, mine name.
  226. int LoadSituation(void)
  227. {
  228.         if (SafetyCheck())  {
  229.                 if (ui_get_filename( sit_filename, "*.sit", "Load Situation" )) {
  230.          checkforext(sit_filename, "SIT");
  231.          if (med_load_situation(sit_filename))
  232.                                 return 0;
  233.                         // set_view_target_from_segment(Cursegp);
  234.                         Update_flags = UF_WORLD_CHANGED;
  235.                         // SetPlayerFromCurseg();
  236.                         med_compress_mine();
  237.                         init_info = 1;
  238.                         mine_changed = 0;
  239.                 }
  240.         }
  241.  
  242.         return 1;
  243. }
  244.  
  245.