34 #include "MissionSave.h"
36 #include "Management.h"
38 #include "FredRender.h"
40 #include "EventEditor.h"
42 #include "MessageEditorDlg.h"
53 static char THIS_FILE[] = __FILE__;
60 #ifndef __FOLDERDLG_H__
61 #include "FolderDlg.h"
67 IMPLEMENT_DYNCREATE(
CFREDDoc, CDocument)
69 BEGIN_MESSAGE_MAP(
CFREDDoc, CDocument)
73 ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
74 ON_COMMAND(ID_EDIT_CUT, OnEditCut)
77 ON_COMMAND(ID_EDIT_PASTE, OnEditPaste)
78 ON_COMMAND(ID_EDIT_UNDO, OnEditUndo)
104 confirm_deleting =
TRUE;
105 show_capital_ships =
TRUE;
106 show_elevations =
TRUE;
107 show_fighters =
TRUE;
109 show_misc_objects =
TRUE;
111 show_waypoints =
TRUE;
112 show_starfield =
TRUE;
115 undo_desc[i].Empty();
124 if (!CDocument::OnNewDocument())
156 if (name[len - 4] ==
'.')
162 if ((name[i] ==
'\\') || (name[i] ==
':'))
191 len = strlen(pathname);
193 if (name[len - 4] ==
'.')
198 if ((name[len] ==
'\\') || (name[len] ==
':'))
209 Fred_main_wnd->MessageBox(
"Event editor dialog is still open, so changes there won't be saved");
212 Fred_main_wnd->MessageBox(
"Message editor dialog is still open, so changes there won't be saved");
214 fp = fopen(pathname,
"r");
217 attrib = GetFileAttributes(pathname);
218 if (attrib & FILE_ATTRIBUTE_READONLY) {
219 Fred_main_wnd->MessageBox(
"File is read-only. You need to check it out before saving to it");
229 SetModifiedFlag(
FALSE);
231 Error(
LOCATION,
"Failed attempting to reload mission after saving. Report this bug now!");
255 fp = fopen(name,
"r");
296 char name[256], backup_name[256];
305 fp = fopen(name,
"r");
317 len = strlen(backup_name);
322 sprintf(backup_name + len,
".%.3d", i + 1);
323 sprintf(name + len,
".%.3d", i);
339 char name[512], *old_name;
356 sprintf(name,
"Unable to import the file \"%s\".", pathname);
361 sprintf(name,
"Unable to load the file \"%s\".", pathname);
373 sprintf(msg,
"Fred encountered unknown ship/weapon classes when importing \"%s\" (path \"%s\"). You will have to manually edit the converted mission to correct this.",
The_mission.
name, pathname);
378 Fred_view_wnd->MessageBox(
"Fred encountered unknown ship/weapon classes when parsing the mission file. This may be due to mission disk data you do not have.");
427 if ( (!strlen(
Team_data[i].weaponry_pool_variable[j])) && (!strlen(
Team_data[i].weaponry_amount_variable[j])) ) {
430 if (
Team_data[i].weaponry_count[j] < 0) {
440 if (used_pool[j] != 0) {
533 void CFREDDoc::AssertValid()
const
535 CDocument::AssertValid();
538 void CFREDDoc::Dump(CDumpContext& dc)
const
611 if (dlg.DoModal() == IDOK)
631 SetModifiedFlag(
FALSE);
878 if ((ch =
stristr(fs1_mission_path,
"FreeSpace2")) != NULL)
880 strcpy(ch,
"FreeSpace\\Data\\Missions");
884 strcat_s(fs2_mission_path,
"\\Data\\Missions");
893 CFileDialog dlgFile(
TRUE,
"fsm", NULL, OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_ALLOWMULTISELECT,
"FreeSpace Missions (*.fsm)|*.fsm|All files (*.*)|*.*||");
894 dlgFile.m_ofn.lpstrTitle =
"Select one or more missions to import";
895 dlgFile.m_ofn.lpstrInitialDir = fs1_mission_path;
898 if (dlgFile.DoModal() != IDOK)
901 memset( dest_directory, 0,
sizeof(dest_directory) );
904 #if ( _MFC_VER >= 0x0700 )
910 bi.hwndOwner =
theApp.GetMainWnd()->GetSafeHwnd();
913 bi.pszDisplayName = dest_directory;
914 bi.lpszTitle =
"Select a location to save in";
920 LPCITEMIDLIST ret_val = SHBrowseForFolder(&bi);
925 SHGetPathFromIDList(ret_val, dest_directory);
927 CFolderDialog dlgFolder(_T(
"Select a location to save in"), fs2_mission_path, NULL);
928 if(dlgFolder.
DoModal() != IDOK)
941 POSITION
pos(dlgFile.GetStartPosition());
949 CString fs1_path_mfc(dlgFile.GetNextPathName(
pos));
961 if (!strlen(fs1_path_mfc))
979 ch = strrchr(filename,
'.');
989 strcpy_s(dest_path, dest_directory);
994 fp = fopen(dest_path,
"r");
998 attrib = GetFileAttributes(dest_path);
999 if (attrib & FILE_ATTRIBUTE_READONLY)
1004 if (save.save_mission_file(dest_path))
1012 MessageBox(NULL,
"Import complete. Please check the destination folder to verify all missions were imported successfully.",
"Status",
MB_OK);
1016 void CFREDDoc::recreate_dialogs()
1024 SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE);
1034 SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE);
void wing_bash_ship_name(char *ship_name, const char *wing_name, int index)
int Num_unknown_ship_classes
int cf_delete(const char *filename, int path_type)
Delete the specified file.
void generate_weaponry_usage_list(int *arr, int wing)
CMessageEditorDlg * Message_editor_dlg
weapon_info Weapon_info[MAX_WEAPON_TYPES]
afx_msg void OnEditCopy()
afx_msg void OnEditHold()
virtual BOOL OnOpenDocument(LPCTSTR lpszPathName)
void mission_parse_lookup_callsign_index(int index, char *out)
void mission_parse_lookup_alt_index(int index, char *out)
afx_msg void OnEditDelete()
void _cdecl void void _cdecl void _cdecl Warning(char *filename, int line, SCP_FORMAT_STRING const char *format,...) SCP_FORMAT_STRING_ARGS(3
CString undo_desc[BACKUP_DEPTH+1]
char Fred_alt_names[MAX_SHIPS][NAME_LENGTH+1]
#define DIR_SEPARATOR_CHAR
virtual void OnEditClearAll()
void update_sexp_references(const char *old_name, const char *new_name, int format, int node)
#define END_OF_LIST(head)
CMainFrame * Fred_main_wnd
void obj_merge_created_list(void)
int cf_create_default_path_string(char *path, uint path_max, int pathtype, const char *filename, bool localize)
AFX_INLINE LPCTSTR GetFolderPath(VOID) const
bg_bitmap_dlg * Bg_bitmap_dialog
int Num_unknown_loadout_classes
afx_msg void OnEditFetch()
void create_new_mission()
reinforcements Reinforcements[MAX_REINFORCEMENTS]
virtual void Serialize(CArchive &ar)
GLdouble GLdouble GLdouble r
afx_msg void OnEditUndo()
void stars_post_level_init()
event_editor * Event_editor_dlg
afx_msg void OnFilePreferences()
char * stristr(char *str, const char *substr)
sprintf(buf,"(%f,%f,%f)", v3->xyz.x, v3->xyz.y, v3->xyz.z)
int Num_unknown_weapon_classes
int weaponry_pool[MAX_WEAPON_TYPES]
int autosave_mission_file(char *pathname)
afx_msg void OnDuplicate()
int cf_rename(const char *old_name, const char *name, int dir_type)
virtual INT DoModal(VOID)
int wing_objects[MAX_WINGS][MAX_SHIPS_PER_WING]
static void UpdateStatus(int flags=US_WORLD_CHANGED)
virtual void DeleteContents()
char Mission_filename[80]
void ai_update_goal_references(ai_goal *goals, int type, const char *old_name, const char *new_name)
CFREDView * Fred_view_wnd
#define ID_FILE_PREFERENCES
afx_msg void OnFileImportFSM()
object Objects[MAX_OBJECTS]
void _cdecl void void _cdecl Error(const char *filename, int line, SCP_FORMAT_STRING const char *format,...) SCP_FORMAT_STRING_ARGS(3
#define ID_FILE_IMPORT_FSM
int load_mission(char *pathname, int flags=0)
void set_modified(BOOL arg)
GLuint const GLchar * name
int weaponry_count[MAX_WEAPON_TYPES]
#define MB_ICONEXCLAMATION
virtual BOOL OnSaveDocument(LPCTSTR lpszPathName)
char mission_pathname[256]
int save_mission_file(char *pathname)
#define MISSION_BACKUP_NAME
afx_msg void OnEditPaste()
int parse_main(const char *mission_name, int flags)
void update_data(int update=1)
int MessageBox(HWND h, const char *s1, const char *s2, int i)
afx_msg void editor_init_mission()
void icon_select(int num)
virtual BOOL OnNewDocument()
matrix Parse_viewer_orient
team_data Team_data[MAX_TVT_TEAMS]
int ship_index[MAX_SHIPS_PER_WING]
briefing_editor_dlg * Briefing_dialog
char Fred_callsigns[MAX_SHIPS][NAME_LENGTH+1]
void update_texture_replacements(const char *old_name, const char *new_name)
char ship_name[NAME_LENGTH]
void restore_editor_state()
#define MISSION_FLAG_SUBSPACE
void palette_load_table(const char *filename)