summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/hiscores.cc
diff options
context:
space:
mode:
authordshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2007-03-15 20:10:20 +0000
committerdshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2007-03-15 20:10:20 +0000
commit621bd9ce58cc45ce9cfcc3cf1f576882b40a426d (patch)
treeadc2b3b4faed06c535b2bec690cf362af40c7fa5 /crawl-ref/source/hiscores.cc
parent83559fff8232481cbc68731b7527dd2154c0bd88 (diff)
downloadcrawl-ref-621bd9ce58cc45ce9cfcc3cf1f576882b40a426d.tar.gz
crawl-ref-621bd9ce58cc45ce9cfcc3cf1f576882b40a426d.zip
Cleaned up ghost and Pandemonium demon handling.
Can now have multiple ghosts or Pandemonium demons on a level. Ghosts and Pan demons can coexist. (D:9 and later are eligible for >1 ghost.) Enabled loading ghosts in Pandemonium. Pandemonium demons can now be created outside Pan. Not that you'd want to do it, but you can. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@1043 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/hiscores.cc')
-rw-r--r--crawl-ref/source/hiscores.cc128
1 files changed, 6 insertions, 122 deletions
diff --git a/crawl-ref/source/hiscores.cc b/crawl-ref/source/hiscores.cc
index 2155e359aa..65db7627a0 100644
--- a/crawl-ref/source/hiscores.cc
+++ b/crawl-ref/source/hiscores.cc
@@ -36,6 +36,7 @@
#include "externs.h"
#include "branch.h"
+#include "files.h"
#include "hiscores.h"
#include "itemname.h"
#include "itemprop.h"
@@ -78,12 +79,6 @@ static int hs_nextint(const char *&inbuf);
static long hs_nextlong(const char *&inbuf);
static time_t parse_time(const std::string &st);
-// file locking stuff
-#ifdef USE_FILE_LOCKING
-static bool lock_file_handle( FILE *handle, int type );
-static bool unlock_file_handle( FILE *handle );
-#endif // USE_FILE_LOCKING
-
std::string score_file_name()
{
if (!SysEnv.scorefile.empty())
@@ -363,129 +358,18 @@ std::string hiscores_format_single_long( const scorefile_entry &se,
// BEGIN private functions
// --------------------------------------------------------------------------
-// first, some file locking stuff for multiuser crawl
-#ifdef USE_FILE_LOCKING
-
-static bool lock_file_handle( FILE *handle, int type )
-{
- struct flock lock;
- int status;
-
- lock.l_whence = SEEK_SET;
- lock.l_start = 0;
- lock.l_len = 0;
- lock.l_type = type;
-
-#ifdef USE_BLOCKING_LOCK
-
- status = fcntl( fileno( handle ), F_SETLKW, &lock );
-
-#else
-
- for (int i = 0; i < 30; i++)
- {
- status = fcntl( fileno( handle ), F_SETLK, &lock );
-
- // success
- if (status == 0)
- break;
-
- // known failure
- if (status == -1 && (errno != EACCES && errno != EAGAIN))
- break;
-
- perror( "Problems locking file... retrying..." );
- delay( 1000 );
- }
-
-#endif
-
- return (status == 0);
-}
-
-static bool unlock_file_handle( FILE *handle )
-{
- struct flock lock;
- int status;
-
- lock.l_whence = SEEK_SET;
- lock.l_start = 0;
- lock.l_len = 0;
- lock.l_type = F_UNLCK;
-
-#ifdef USE_BLOCKING_LOCK
-
- status = fcntl( fileno( handle ), F_SETLKW, &lock );
-
-#else
-
- for (int i = 0; i < 30; i++)
- {
- status = fcntl( fileno( handle ), F_SETLK, &lock );
-
- // success
- if (status == 0)
- break;
-
- // known failure
- if (status == -1 && (errno != EACCES && errno != EAGAIN))
- break;
-
- perror( "Problems unlocking file... retrying..." );
- delay( 1000 );
- }
-
-#endif
-
- return (status == 0);
-}
-
-#endif
-
FILE *hs_open( const char *mode, const std::string &scores )
{
// allow reading from standard input
if ( scores == "-" )
return stdin;
- FILE *handle = fopen(scores.c_str(), mode);
-#ifdef SHARED_FILES_CHMOD_PUBLIC
- chmod(scores.c_str(), SHARED_FILES_CHMOD_PUBLIC);
-#endif
-
-#ifdef USE_FILE_LOCKING
- int locktype = F_RDLCK;
- if (stricmp(mode, "r"))
- locktype = F_WRLCK;
-
- if (handle && !lock_file_handle( handle, locktype ))
- {
- perror( "Could not lock scorefile... " );
- fclose( handle );
- handle = NULL;
- }
-#endif
- return handle;
+ return lk_open( mode, scores );
}
void hs_close( FILE *handle, const char *mode, const std::string &scores )
{
- UNUSED( mode );
-
- if (handle == NULL || handle == stdin)
- return;
-
-#ifdef USE_FILE_LOCKING
- unlock_file_handle( handle );
-#endif
-
- // actually close
- fclose(handle);
-
-#ifdef SHARED_FILES_CHMOD_PUBLIC
- if (stricmp(mode, "w") == 0)
- chmod(scores.c_str(), SHARED_FILES_CHMOD_PUBLIC);
-#endif
+ lk_close(handle, mode, scores);
}
bool hs_read( FILE *scores, scorefile_entry &dest )
@@ -1247,8 +1131,8 @@ void scorefile_entry::init_death_cause(int dam, int dsrc,
}
death_source_name =
- monam( monster->number, monster->type, true, DESC_NOCAP_A,
- monster->inv[MSLOT_WEAPON] );
+ monam( monster, monster->number, monster->type, true,
+ DESC_NOCAP_A, monster->inv[MSLOT_WEAPON] );
}
}
else
@@ -1484,7 +1368,7 @@ const char *scorefile_entry::death_source_desc() const
return (!death_source_name.empty()?
death_source_name.c_str()
- : monam( mon_num, death_source, true, DESC_NOCAP_A ) );
+ : monam( NULL, mon_num, death_source, true, DESC_NOCAP_A ) );
}
std::string scorefile_entry::damage_string(bool terse) const