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:
SpaceViking
2009-01-15 01:26:13 +00:00
parent f64f58fbf8
commit f26095d86f
138 changed files with 3493 additions and 3265 deletions
+72 -27
View File
@@ -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;
}