diff rogue4/options.c @ 14:e7dc81b41168

rogue4: prevent changing name or save file when using system savedir
author edwarj4
date Sat, 31 Oct 2009 13:20:00 +0000
parents 9535a08ddc39
children 1b73a8641b37
line wrap: on
line diff
--- a/rogue4/options.c	Sat Oct 31 01:51:52 2009 +0000
+++ b/rogue4/options.c	Sat Oct 31 13:20:00 2009 +0000
@@ -34,6 +34,8 @@
 
 typedef struct optstruct	OPTION;
 
+int allowchange(OPTION *opt);
+
 int	put_bool(), get_bool(), put_str(), get_str();
 
 OPTION	optlist[] = {
@@ -72,9 +74,12 @@
      */
     for (op = optlist; op < &optlist[NUM_OPTS]; op++)
     {
-	waddstr(hw, op->o_prompt);
-	(*op->o_putfunc)(op->o_opt);
-	waddch(hw, '\n');
+        if (allowchange(op))
+        {
+	    waddstr(hw, op->o_prompt);
+	    (*op->o_putfunc)(op->o_opt);
+	    waddch(hw, '\n');
+        }
     }
     /*
      * Set values
@@ -82,10 +87,14 @@
     wmove(hw, 0, 0);
     for (op = optlist; op < &optlist[NUM_OPTS]; op++)
     {
+        if (!allowchange(op))
+            continue;
 	waddstr(hw, op->o_prompt);
 	if ((retval = (*op->o_getfunc)(op->o_opt, hw)))
+        {
 	    if (retval == QUIT)
 		break;
+#if 0 /* disable MINUS */
 	    else if (op > optlist) {	/* MINUS */
 		wmove(hw, (op - optlist) - 1, 0);
 		op -= 2;
@@ -96,6 +105,10 @@
 		wmove(hw, 0, 0);
 		op--;
 	    }
+#else
+            break;
+#endif
+        }
     }
     /*
      * Switch back to original screen
@@ -301,6 +314,11 @@
 	 * Look it up and deal with it
 	 */
 	for (op = optlist; op < &optlist[NUM_OPTS]; op++)
+        {
+            /* If using system savefiles, changing your name or the
+               save file is not allowed. */
+            if (!allowchange(op))
+                continue;
 	    if (EQSTR(str, op->o_name, len))
 	    {
 		if (op->o_putfunc == put_bool)	/* if option is a boolean */
@@ -340,6 +358,7 @@
 		*(bool *)op->o_opt = FALSE;
 		break;
 	    }
+        }
 
 	/*
 	 * skip to start of next option name
@@ -368,3 +387,16 @@
     }
     *s1 = '\0';
 }
+
+/* Tells whether the player is allowed to change the option. */
+int allowchange(OPTION *opt)
+{
+    if (!use_savedir)
+        return 1;
+    if (!strcmp(opt->o_name, "name"))
+        return 0;
+    if (!strcmp(opt->o_name, "file"))
+        return 0;
+    return 1;
+}
+