(svn r2069) - Feature: [ 1168743 ] save command for console (pkirchhofer)
authorDarkvater
Fri, 25 Mar 2005 18:26:49 +0000
changeset 1565 925f94da4077
parent 1564 679a7bcfe95a
child 1566 6b37067ea47e
(svn r2069) - Feature: [ 1168743 ] save command for console (pkirchhofer)
console_cmds.c
--- a/console_cmds.c	Fri Mar 25 18:11:24 2005 +0000
+++ b/console_cmds.c	Fri Mar 25 18:26:49 2005 +0000
@@ -145,6 +145,35 @@
 extern void BuildFileList(void);
 extern void SetFiosType(const byte fiostype);
 
+/* Save the map to current dir */
+static void SaveMap(const char *filename)
+{
+	char buf[200];
+
+	snprintf(buf, sizeof(buf), "%s%s%s.sav", _path.save_dir, PATHSEP, filename);
+	IConsolePrint(_iconsole_color_default, "Saving map...");
+
+	if (SaveOrLoad(buf, SL_SAVE) != SL_OK) {
+		IConsolePrint(_iconsole_color_error, "SaveMap failed");
+	} else
+		IConsolePrintF(_iconsole_color_default, "Map sucessfully saved to %s", buf);
+}
+
+/* Save the map to a file */
+DEF_CONSOLE_CMD(ConSave)
+{
+	/* We need 1 argument */
+	if (argc == 2) {
+		/* Save the map */
+		SaveMap(argv[1]);
+		return NULL;
+	}
+
+	/* Give usage */
+	IConsolePrint(_iconsole_color_default, "Unknown usage. Usage: save <filename>");
+	return NULL;
+}
+
 /* Load a file-number from current dir */
 static void LoadMap(uint no)
 {
@@ -1240,6 +1269,7 @@
 	IConsoleCmdRegister("set",			ConSet);
 	IConsoleCmdRegister("alias",		ConAlias);
 	IConsoleCmdRegister("load",			ConLoad);
+	IConsoleCmdRegister("save",			ConSave);
 	IConsoleCmdRegister("list_files", ConListFiles);
 	IConsoleCmdRegister("scan_files", ConScanFiles);
 	IConsoleCmdRegister("goto_dir", ConGotoDir);