- attempt to fix pizza's crash

- safer use of random # in unit updater (not backward compatible with other builds)
This commit is contained in:
Mark Vejvoda
2012-07-20 23:07:44 +00:00
parent ed6961195f
commit ed9ae076c5
4 changed files with 24 additions and 22 deletions

View File

@@ -919,11 +919,11 @@ void Game::init(bool initForPreviewOnly) {
world.init(this, gameSettings.getDefaultUnits()); world.init(this, gameSettings.getDefaultUnits());
} }
catch(const exception &ex) { catch(const exception &ex) {
char szBuf[8096]=""; char szErrBuf[8096]="";
sprintf(szBuf,"In [%s::%s Line: %d]\nError [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what()); sprintf(szErrBuf,"In [%s::%s %d]",__FILE__,__FUNCTION__,__LINE__);
string sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n");
SystemFlags::OutputDebug(SystemFlags::debugError,szBuf); SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str());
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,szBuf); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str());
if(errorMessageBox.getEnabled() == false) { if(errorMessageBox.getEnabled() == false) {
ErrorDisplayMessage(ex.what(),true); ErrorDisplayMessage(ex.what(),true);
@@ -1527,8 +1527,8 @@ void Game::update() {
world.init(this, gameSettings.getDefaultUnits(),false); world.init(this, gameSettings.getDefaultUnits(),false);
} }
catch(const exception &ex) { catch(const exception &ex) {
char szBuf[4096]=""; char szBuf[8096]="";
sprintf(szBuf,"In [%s::%s Line: %d] Error [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what()); sprintf(szBuf,"In [%s::%s Line: %d]\nError [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what());
SystemFlags::OutputDebug(SystemFlags::debugError,szBuf); SystemFlags::OutputDebug(SystemFlags::debugError,szBuf);
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,szBuf); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,szBuf);

View File

@@ -2068,7 +2068,8 @@ void UnitUpdater::damage(Unit *attacker, const AttackSkillType* ast, Unit *attac
float damageMultiplier = world->getTechTree()->getDamageMultiplier(ast->getAttackType(), attacked->getType()->getArmorType()); float damageMultiplier = world->getTechTree()->getDamageMultiplier(ast->getAttackType(), attacked->getType()->getArmorType());
//compute damage //compute damage
damage += random.randRange(-var, var); //damage += random.randRange(-var, var);
damage += attacker->getRandom()->randRange(-var, var);
damage /= distance+1; damage /= distance+1;
damage -= armor; damage -= armor;
damage *= damageMultiplier; damage *= damageMultiplier;
@@ -2625,7 +2626,7 @@ void UnitUpdater::saveGame(XmlNode *rootNode) {
// RoutePlanner *routePlanner; // RoutePlanner *routePlanner;
// Game *game; // Game *game;
// RandomGen random; // RandomGen random;
unitupdaterNode->addAttribute("random",intToStr(random.getLastNumber()), mapTagReplacements); //unitupdaterNode->addAttribute("random",intToStr(random.getLastNumber()), mapTagReplacements);
// float attackWarnRange; // float attackWarnRange;
unitupdaterNode->addAttribute("attackWarnRange",floatToStr(attackWarnRange), mapTagReplacements); unitupdaterNode->addAttribute("attackWarnRange",floatToStr(attackWarnRange), mapTagReplacements);
// AttackWarnings attackWarnings; // AttackWarnings attackWarnings;
@@ -2638,7 +2639,7 @@ void UnitUpdater::loadGame(const XmlNode *rootNode) {
const XmlNode *unitupdaterNode = rootNode->getChild("UnitUpdater"); const XmlNode *unitupdaterNode = rootNode->getChild("UnitUpdater");
pathFinder->loadGame(unitupdaterNode); pathFinder->loadGame(unitupdaterNode);
random.setLastNumber(unitupdaterNode->getAttribute("random")->getIntValue()); //random.setLastNumber(unitupdaterNode->getAttribute("random")->getIntValue());
// float attackWarnRange; // float attackWarnRange;
attackWarnRange = unitupdaterNode->getAttribute("attackWarnRange")->getFloatValue(); attackWarnRange = unitupdaterNode->getAttribute("attackWarnRange")->getFloatValue();
} }

View File

@@ -81,7 +81,7 @@ private:
PathFinder *pathFinder; PathFinder *pathFinder;
RoutePlanner *routePlanner; RoutePlanner *routePlanner;
Game *game; Game *game;
RandomGen random; //RandomGen random;
float attackWarnRange; float attackWarnRange;
AttackWarnings attackWarnings; AttackWarnings attackWarnings;

View File

@@ -259,7 +259,7 @@ void World::init(Game *game, bool createUnits, bool initFactions){
initMinimap(); initMinimap();
bool gotError = false; bool gotError = false;
char szErrBuf[8096]=""; string sErrBuf = "";
try { try {
if(createUnits) { if(createUnits) {
@@ -267,12 +267,11 @@ void World::init(Game *game, bool createUnits, bool initFactions){
} }
} }
catch(const std::exception &ex) { catch(const std::exception &ex) {
//printf("***A\n");
gotError = true; gotError = true;
sprintf(szErrBuf,"In [%s::%s %d]\nerror [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); char szErrBuf[8096]="";
SystemFlags::OutputDebug(SystemFlags::debugError,szErrBuf); sprintf(szErrBuf,"In [%s::%s %d]",__FILE__,__FUNCTION__,__LINE__);
sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n");
//printf("***B\n"); SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str());
} }
if(loadWorldNode != NULL) { if(loadWorldNode != NULL) {
@@ -284,7 +283,7 @@ void World::init(Game *game, bool createUnits, bool initFactions){
computeFow(); computeFow();
if(gotError == true) { if(gotError == true) {
throw megaglest_runtime_error(szErrBuf); throw megaglest_runtime_error(sErrBuf);
} }
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
@@ -1641,7 +1640,7 @@ void World::initUnits() {
Logger::getInstance().add(Lang::getInstance().get("LogScreenGameLoadingGenerateGameElements","",true), true); Logger::getInstance().add(Lang::getInstance().get("LogScreenGameLoadingGenerateGameElements","",true), true);
bool gotError = false; bool gotError = false;
char szErrBuf[8096]=""; string sErrBuf="";
try { try {
//put starting units //put starting units
if(loadWorldNode == NULL) { if(loadWorldNode == NULL) {
@@ -1679,15 +1678,17 @@ void World::initUnits() {
} }
catch(const std::exception &ex) { catch(const std::exception &ex) {
gotError = true; gotError = true;
sprintf(szErrBuf,"In [%s::%s %d]\nerror [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); char szErrBuf[8096]="";
SystemFlags::OutputDebug(SystemFlags::debugError,szErrBuf); sprintf(szErrBuf,"In [%s::%s %d]",__FILE__,__FUNCTION__,__LINE__);
sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n");
SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str());
} }
map.computeNormals(); map.computeNormals();
map.computeInterpolatedHeights(); map.computeInterpolatedHeights();
if(gotError == true) { if(gotError == true) {
throw megaglest_runtime_error(szErrBuf); throw megaglest_runtime_error(sErrBuf);
} }
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
} }