mirror of
https://github.com/1dot13/source.git
synced 2026-07-22 13:40:22 +02:00
Made direction variables more consistent as unsigned chars. Several function prototypes updated for this. Many memory leaks plugged: External options, video overlays, laptop file lists, tactical message queue, strategic pathing, autobandage, merc hiring, detailed placements, crate in Drassen, tactical placement New functions and attributes for soldiers in LUA (still for debugging at best): Soldier.APs (current APs), Soldier.changestance (changes stance, uses game heights) File catalog ignores .SVN directories (game load speedup) Fix CTD in mouse regions JA2 window now refuses to move to negative coords Checks to prevent DirectX-related infinite loops due to minimizing and task switching Invading enemies should now appear on the borders even when reinforcements disabled in .ini Suppression should no longer work on mercs in medium water Infant/Young creatures use restored spit instead of Molotov Creatures begin with their 'guns' (spit) 'locked and loaded' (cartridge in chamber) Further fix to AXP and AlaarDB's weapon ready check: Now 'firing' is always counted as 'ready'. Prevent mercs from falling and flying back through obstacles Check whether battle group is even set before testing its location for battle setup Burst spread locations now limited to 6, the limit within the soldier struct Extra burst spread locations zeroed out so that they aren't used unless necessary Spread code now only shoots at locations in the spread, and will shoot at all 6 Only mercs in the sector where autobandage happens will be made to stand up after it's done Throwing a grenade at the tail of the plane in Drassen should not result in a CTD Reset attack busy count when loading a new sector git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@1347 3b4a5df2-a311-0410-b5c6-a8a6f20db521
101 lines
2.5 KiB
C++
101 lines
2.5 KiB
C++
//
|
|
// Snap: Implementation of the TFileCat class
|
|
//
|
|
#include "FileCat.h"
|
|
#include "readdir.h"
|
|
|
|
|
|
// Remove a slash or backslash (if any) from the end of a string
|
|
void ChompSlash(std::string& s)
|
|
{
|
|
if ( s.empty() ) return;
|
|
|
|
if ( *s.rbegin() == '\\' || *s.rbegin() == '/' ) {
|
|
s.erase( s.length() - 1 );
|
|
}
|
|
}
|
|
|
|
|
|
// Build a new file catalogue by recursively traversing the root directory
|
|
void TFileCat::NewCat(std::string root)
|
|
{
|
|
fRootDir = root;
|
|
ChompSlash(fRootDir);
|
|
|
|
fFileCat.clear();
|
|
|
|
TraverseDir(fRootDir);
|
|
}
|
|
|
|
|
|
// Look for a given file in the catalogue
|
|
// Unless pathIncludesRoot == true, will prepend the root directory to path
|
|
bool TFileCat::FindFile(std::string path, bool pathIncludesRoot) const
|
|
{
|
|
if (pathIncludesRoot) return fFileCat.find(path) != fFileCat.end();
|
|
else return fFileCat.find(fRootDir + '\\' + path) != fFileCat.end();
|
|
}
|
|
|
|
|
|
// Delete a given file from the catalogue
|
|
// Unless pathIncludesRoot == true, will prepend the root directory to path
|
|
size_t TFileCat::RemoveFile(std::string path, bool pathIncludesRoot)
|
|
{
|
|
if (pathIncludesRoot) return fFileCat.erase(path);
|
|
else return fFileCat.erase(fRootDir + '\\' + path);
|
|
}
|
|
|
|
|
|
// Delete all files from a given directory in the catalogue
|
|
// Unless pathIncludesRoot == true, will prepend the root directory to path
|
|
size_t TFileCat::RemoveDir(std::string dir, bool pathIncludesRoot)
|
|
{
|
|
if ( !pathIncludesRoot ) dir = fRootDir + '\\' + dir;
|
|
ChompSlash(dir);
|
|
std::string dirlower = dir + '\\';
|
|
std::string dirupper = dir + char('\\'+1);
|
|
|
|
TCatalogue::iterator upper = fFileCat.upper_bound(dirupper);
|
|
TCatalogue::iterator lower;
|
|
|
|
int deleted = 0;
|
|
|
|
while ( ( lower = fFileCat.lower_bound(dirlower) ) != upper) {
|
|
fFileCat.erase(lower);
|
|
deleted++;
|
|
}
|
|
|
|
return deleted;
|
|
}
|
|
|
|
|
|
// Recursively traverse a directory, adding regular files to the catalogue
|
|
void TFileCat::TraverseDir(std::string dir, int depth)
|
|
{
|
|
using std::string;
|
|
static string dot( ".");
|
|
static string dotdot( "..");
|
|
static string svn( ".svn");
|
|
|
|
if (!dir.empty()) dir += '\\';
|
|
|
|
TReadDir readDir((dir + "*").c_str());
|
|
|
|
char const* fileName;
|
|
unsigned attrib;
|
|
|
|
while ( readDir.NextFile(fileName, attrib) ) {
|
|
if (dot == fileName || dotdot == fileName || svn == fileName) continue;
|
|
|
|
string fullPath = dir + fileName;
|
|
|
|
if (attrib & FILE_ATTRIBUTE_DIRECTORY) {
|
|
if (depth < 0) TraverseDir(fullPath);
|
|
else if (depth > 0) TraverseDir(fullPath, depth-1);
|
|
}
|
|
else {
|
|
fFileCat.insert(fullPath);
|
|
}
|
|
}
|
|
}
|