mirror of
https://github.com/1dot13/source.git
synced 2026-08-05 14:00:23 +02:00
Space Viking's many mercs changes plus numerous generic bug fixes
git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@2498 3b4a5df2-a311-0410-b5c6-a8a6f20db521
This commit is contained in:
+72
-27
@@ -1,11 +1,17 @@
|
||||
#include "builddefines.h"
|
||||
#include "IniReader.h"
|
||||
#include "FileMan.h"
|
||||
#include "debug.h"
|
||||
#include "Font Control.h"
|
||||
#include "message.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sstream>
|
||||
|
||||
// Kaiden: INI reading function definitions:
|
||||
|
||||
std::stack<std::string> iniErrorMessages;
|
||||
|
||||
|
||||
CIniReader::CIniReader(const STR8 szFileName)
|
||||
{
|
||||
@@ -26,41 +32,80 @@ int CIniReader::ReadInteger(const STR8 szSection, const STR8 szKey, int iDefault
|
||||
}
|
||||
|
||||
|
||||
int CIniReader::ReadInteger(const STR8 szSection, const STR8 szKey, int iDefaultValue, int iMinValue, int iMaxValue)
|
||||
int CIniReader::ReadInteger(const STR8 szSection, const STR8 szKey, int defaultValue, int minValue, int maxValue)
|
||||
{
|
||||
int i = GetPrivateProfileInt(szSection, szKey, iDefaultValue, m_szFileName);
|
||||
if (i < iMinValue)
|
||||
return iMinValue;
|
||||
else if (i > iMaxValue)
|
||||
return iMaxValue;
|
||||
return i;
|
||||
}
|
||||
|
||||
int ReadInteger(const STR8 szSection, const STR8 szKey, int iDefaultValue, int iMinValue, int iMaxValue);
|
||||
|
||||
|
||||
|
||||
float CIniReader::ReadFloat(const STR8 szSection, const STR8 szKey, float fltDefaultValue)
|
||||
{
|
||||
char szResult[255];
|
||||
char szDefault[255];
|
||||
float fltResult;
|
||||
sprintf(szDefault, "%f",fltDefaultValue);
|
||||
GetPrivateProfileString(szSection, szKey, szDefault, szResult, 255, m_szFileName);
|
||||
fltResult = (float) atof(szResult);
|
||||
return fltResult;
|
||||
int iniValueReadFromFile = GetPrivateProfileInt(szSection, szKey, defaultValue, m_szFileName);
|
||||
//AssertGE(iniValueReadFromFile, minValue);
|
||||
//AssertLE(iniValueReadFromFile, maxValue);
|
||||
if (iniValueReadFromFile < minValue) {
|
||||
std::stringstream errMessage;
|
||||
errMessage << "The value of the .ini setting " << szKey << "(" << iniValueReadFromFile
|
||||
<< ") is outsize the valid range of " << minValue << " to " << maxValue
|
||||
<< ". " << minValue << " will be used.";
|
||||
iniErrorMessages.push(errMessage.str());
|
||||
return minValue;
|
||||
} else if (iniValueReadFromFile > maxValue) {
|
||||
std::stringstream errMessage;
|
||||
errMessage << "The value of the .ini setting " << szKey << "(" << iniValueReadFromFile
|
||||
<< ") is outsize the valid range of " << minValue << " to " << maxValue
|
||||
<< ". " << maxValue << " will be used.";
|
||||
iniErrorMessages.push(errMessage.str());
|
||||
return maxValue;
|
||||
}
|
||||
return iniValueReadFromFile;
|
||||
}
|
||||
|
||||
|
||||
bool CIniReader::ReadBoolean(const STR8 szSection, const STR8 szKey, bool bolDefaultValue)
|
||||
|
||||
//float CIniReader::ReadDouble(const STR8 szSection, const STR8 szKey, float fltDefaultValue)
|
||||
//{
|
||||
// char szResult[255];
|
||||
// char szDefault[255];
|
||||
// float fltResult;
|
||||
// sprintf(szDefault, "%f",fltDefaultValue);
|
||||
// GetPrivateProfileString(szSection, szKey, szDefault, szResult, 255, m_szFileName);
|
||||
// fltResult = (float) atof(szResult);
|
||||
// return fltResult;
|
||||
//}
|
||||
|
||||
double CIniReader::ReadDouble(const STR8 szSection, const STR8 szKey, double defaultValue, double minValue, double maxValue)
|
||||
{
|
||||
char szResult[255];
|
||||
char szDefault[255];
|
||||
double iniValueReadFromFile;
|
||||
sprintf(szDefault, "%f", defaultValue);
|
||||
GetPrivateProfileString(szSection, szKey, szDefault, szResult, 255, m_szFileName);
|
||||
iniValueReadFromFile = (float) atof(szResult);
|
||||
//AssertGE(iniValueReadFromFile, minValue);
|
||||
//AssertLE(iniValueReadFromFile, maxValue);
|
||||
if (iniValueReadFromFile < minValue) {
|
||||
std::stringstream errMessage;
|
||||
errMessage << "The value of the .ini setting " << szKey << "(" << iniValueReadFromFile
|
||||
<< ") is outsize the valid range of " << minValue << " to " << maxValue
|
||||
<< ". " << minValue << " will be used.";
|
||||
iniErrorMessages.push(errMessage.str());
|
||||
return minValue;
|
||||
} else if (iniValueReadFromFile > maxValue) {
|
||||
std::stringstream errMessage;
|
||||
errMessage << "The value of the .ini setting " << szKey << "(" << iniValueReadFromFile
|
||||
<< ") is outsize the valid range of " << minValue << " to " << maxValue
|
||||
<< ". " << maxValue << " will be used.";
|
||||
iniErrorMessages.push(errMessage.str());
|
||||
return maxValue;
|
||||
}
|
||||
return iniValueReadFromFile;
|
||||
}
|
||||
|
||||
|
||||
bool CIniReader::ReadBoolean(const STR8 szSection, const STR8 szKey, bool defaultValue)
|
||||
{
|
||||
char szResult[255];
|
||||
char szDefault[255];
|
||||
bool bolResult;
|
||||
sprintf(szDefault, "%s", bolDefaultValue? "TRUE" : "FALSE");
|
||||
bool boolResult;
|
||||
sprintf(szDefault, "%s", defaultValue? "TRUE" : "FALSE");
|
||||
GetPrivateProfileString(szSection, szKey, szDefault, szResult, 255, m_szFileName);
|
||||
bolResult = (strcmp(szResult, "TRUE") == 0 || strcmp(szResult, "TRUE") == 0) ? true : false;
|
||||
return bolResult;
|
||||
boolResult = (strcmp(szResult, "TRUE") == 0 || strcmp(szResult, "TRUE") == 0) ? true : false;
|
||||
return boolResult;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user