diff rogue5/rip.c @ 34:655c317b6237

rogue5: add savedir, logfile, bugfixes
author elwin
date Mon, 24 May 2010 20:16:15 +0000
parents f502bf60e6e4
children 24e6beb9e7aa
line wrap: on
line diff
--- a/rogue5/rip.c	Mon May 24 20:10:59 2010 +0000
+++ b/rogue5/rip.c	Mon May 24 20:16:15 2010 +0000
@@ -223,6 +223,62 @@
     }
 }
 
+void writelog(int amount, int flags, int monst)
+{
+#ifdef LOGFILE
+    char logmessage[160], ltemp[80];
+
+    if (logfi == NULL)
+        return;
+#ifdef MASTER
+    if (wizard)
+    {
+        fclose(logfi);
+        return;
+    }
+#endif
+    sprintf(logmessage, "%d %d %.20s %d ", time(NULL), amount, whoami, 
+            pstats.s_lvl);
+    if (flags == 0) /* dead */
+    {
+        sprintf(ltemp, "killed by %s on level %d\n", killname(monst, TRUE),
+                level);
+        strcat(logmessage, ltemp);
+    }
+    else if (flags == 1) /* quit */
+    {
+        if (amulet)
+            sprintf(ltemp, "quit on level %d [max %d] with the Amulet\n",
+                level, max_level);
+        else
+            sprintf(ltemp, "quit on level %d\n", level);
+        strcat(logmessage, ltemp);
+    }
+    else if (flags == 2) /* won */
+    {
+        sprintf(ltemp, "escaped with the Amulet [deepest level: %d]\n",
+                max_level);
+        strcat(logmessage, ltemp);
+    }
+    else if (flags == 3) /* killed with Amulet */
+    {
+        strcat(logmessage, "killed by ");
+        strcat(logmessage, killname(monst, TRUE));
+        sprintf(ltemp, " on level %d [max %d] with the Amulet\n",
+                level, max_level);
+        strcat(logmessage, ltemp);
+    }
+    else
+    {
+        fclose(logfi);
+        return;
+    }
+    fprintf(logfi, "%s", logmessage);
+    fclose(logfi);
+#endif
+    return;
+}
+
 /*
  * death:
  *	Do something really fun when he dies
@@ -271,7 +327,12 @@
     }
     move(LINES - 1, 0);
     refresh();
+    writelog(purse, amulet ? 3 : 0, monst);
     score(purse, amulet ? 3 : 0, monst);
+    /* Make sure the output gets through. */
+    printf("[Press return to exit]\n");
+    fflush(NULL);
+    getchar();
     my_exit(0);
 }
 
@@ -382,6 +443,7 @@
     }
     printw("   %5d  Gold Pieces          ", oldpurse);
     refresh();
+    writelog(purse, 2, ' ');
     score(purse, 2, ' ');
     my_exit(0);
 }