//
// Copyright(C) 1993-1996 Id Software, Inc.
// Copyright(C) 2010 James Haley, Samuel Villareal
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// DESCRIPTION:
//
// [STRIFE] New Module
//
// Strife Hub Saving Code
//

#ifndef M_SAVES_H__
#define M_SAVES_H__

#define CHARACTER_NAME_LEN 32

//
// Strife hub save slot DIRECTORY names.
//
// Vanilla Strife names each slot folder "strfsav<N>.ssg", and slot 6 is the
// temporary/current slot the game actually plays out of.  Note these are
// DIRECTORIES, not files - each one holds "name", "current", "mis_obj",
// "here" and one file per hub map visited.
//
// OpenVMS port: the dot has to go.  See COMPILER_FIXES.TXT section 16.
// On VMS a directory is itself a file, named <DIRNAME>.DIR;1, so a directory
// whose name already contains a dot would have to be spelled
// STRFSAV6.SSG.DIR;1 - two dots in one filespec, which RMS will not parse on
// ODS-2 at all.  The observable symptom was M_MakeDirectory() silently
// failing at startup and then, on the first save/load:
//
//     ClearTmp: Couldn't open dir ./strfsav6.ssg
//
// The dot is replaced with an underscore (legal in an ODS-2 name), giving
// STRFSAV6_SSG.DIR, and "_SSG" is kept so the folders are still recognisable
// and can't collide with anything else in the game directory.  Nothing reads
// these names back or parses them, so the spelling is free: they are produced
// only by M_MakeStrifeSaveDir() below and consumed only by opendir(),
// M_MakeDirectory() and M_SafeFilePath().  This does mean VMS save folders are
// not interchangeable with those of another platform's build, which does not
// matter - the savegames inside are already host-format.
//
#if defined(VMS) || defined(__VMS)
#define STRIFE_SAVEDIR_FMT "strfsav%d_ssg%s"
#else
#define STRIFE_SAVEDIR_FMT "strfsav%d.ssg%s"
#endif

// The slot number of the temporary ("current") save directory.
#define STRIFE_TEMP_SAVESLOT 6

// Number of save directories to create, i.e. slots 0..6 inclusive.
#define STRIFE_NUM_SAVEDIRS  (STRIFE_TEMP_SAVESLOT + 1)

extern char *savepath;
extern char *savepathtemp;
extern char *loadpath;
extern char character_name[CHARACTER_NAME_LEN];

// Strife Savegame Functions
void ClearTmp(void);
void ClearSlot(void);
void FromCurr(void);
void ToCurr(void);
void M_SaveMoveMapToHere(void);
void M_SaveMoveHereToMap(void);

boolean M_SaveMisObj(const char *path);
void    M_ReadMisObj(void);

// Custom Utilities for Filepath Handling
void *M_Calloc(size_t n1, size_t n2);
void  M_NormalizeSlashes(char *str);
int   M_StringAlloc(char **str, int numstrs, size_t extra, const char *str1, ...);
char *M_SafeFilePath(const char *basepath, const char *newcomponent);
char  M_GetFilePath(const char *fn, char *dest, size_t len);
char *M_MakeStrifeSaveDir(int slotnum, const char *extra);
void  M_CreateSaveDirs(const char *savedir);

#endif

// EOF


