Browse Source

-(linux) Moved all (I hope) files created by VCMI to ~/.vcmi to prevents crash on launch from read-only directory
- minor fixes for #362 #835 #836

Ivan Savenko 14 years ago
parent
commit
0f2e00c780

+ 2 - 2
client/CAnimation.cpp

@@ -1241,7 +1241,7 @@ bool CShowableAnim::set(size_t Group, size_t from, size_t to)
 {
 	size_t max = anim.size(Group);
 
-	if (max>to)
+	if (to < max)
 		max = to;
 
 	if (max < from || max == 0)
@@ -1297,7 +1297,7 @@ void CShowableAnim::show(SDL_Surface *to)
 	if ( ++value == frameDelay )
 	{
 		value = 0;
-		if ( ++frame == last)
+		if ( ++frame >= last)
 			reset();
 	}
 }

+ 33 - 15
client/CCastleInterface.cpp

@@ -505,10 +505,21 @@ CCastleBuildings::~CCastleBuildings()
 
 void CCastleBuildings::checkRules()
 {
+	//if town tonwID have building toCheck
+	//then set animation of building buildID to firstA..lastA
+	//else set to firstB..lastB
+	struct AnimRule
+	{
+		int townID, buildID;
+		int toCheck;
+		size_t firstA, lastA;
+		size_t firstB, lastB;
+	};
+	
 	static const AnimRule animRule[2] = 
 	{
-		{5, 21, 4, 10, -1, 0, 9},//code for Mana Vortex
-		{0,  6, 8,  1, -1, 0, 0},//code for the shipyard in the Castle
+		{5, 21, 4, 10, -1, 0,  10}, //Mana Vortex, Dungeon
+		{0,  6, 8,  1, -1, 0,  1}   //Shipyard, Castle
 	};
 	
 	for (size_t i=0; i<2; i++)
@@ -516,20 +527,27 @@ void CCastleBuildings::checkRules()
 		if ( town->subID != animRule[i].townID ) //wrong town
 			continue;
 		
+		int buildingID = animRule[i].buildID;
+		//check if this building have been upgraded (Ship is upgrade of Shipyard)
 		int groupID = CGI->townh->structures[town->subID][animRule[i].buildID]->group;
-		std::map< int, std::vector<const Structure*> >::const_iterator git= groups.find(groupID);
-		if ( git == groups.end() || git->second.empty() ) //we have no buildings in this group
-			continue;
+		if (groupID != -1)
+		{
+			std::map< int, std::vector<const Structure*> >::const_iterator git= groups.find(groupID);
+			if ( git == groups.end() || git->second.empty() )
+				continue;
+			buildingID  = git->second.back()->ID;
+		}
 
-		int buildID  = git->second.back()->ID;
-		for (std::vector< CBuildingRect* >::const_iterator bit=buildings.begin() ; bit !=buildings.end(); bit++ )
+		BOOST_FOREACH(CBuildingRect* rect, buildings)
 		{
-			if ( (*bit)->str->ID == buildID ) //last building in group
+			if ( rect->str->ID == buildingID )
 			{
 				if (vstd::contains(town->builtBuildings, animRule[i].toCheck))
-					(*bit)->set(0,animRule[i].firstA, animRule[i].lastA);
+					rect->set(0,animRule[i].firstA, animRule[i].lastA);
 				else
-					(*bit)->set(0,animRule[i].firstB, animRule[i].lastB);
+					rect->set(0,animRule[i].firstB, animRule[i].lastB);
+
+				break;
 			}
 		}
 	}
@@ -1358,11 +1376,11 @@ CHallInterface::CHallInterface(const CGTownInstance *Town):
 				int buildingID = boxList[row][col][item];
 				building = CGI->buildh->buildings[town->subID][buildingID];
 
-				//Creature hordes - select unupgraded version if dwelling upgrade was not build yet
-				if (buildingID == 18 && !vstd::contains(town->builtBuildings, town->town->hordeLvl[0]+37))
-					break;
-				if (buildingID == 24 && !vstd::contains(town->builtBuildings, town->town->hordeLvl[1]+37))
-					break;
+				if ( (buildingID == 18 && !vstd::contains(town->builtBuildings, town->town->hordeLvl[0]+37))
+				  || (buildingID == 24 && !vstd::contains(town->builtBuildings, town->town->hordeLvl[1]+37)) )
+					break; // horde present, no upgraded dwelling -> select 18 or 24
+				else
+					continue; //upgraded dwelling, no horde -> select 19 or 25
 
 				if(vstd::contains(town->builtBuildings,buildingID))
 					continue;

+ 0 - 8
client/CCastleInterface.h

@@ -110,14 +110,6 @@ public:
 /// Class for town screen management (town background and structures)
 class CCastleBuildings : public CIntObject
 {
-	struct AnimRule
-	{
-		int townID, buildID;
-		int toCheck;
-		size_t firstA, lastA;
-		size_t firstB, lastB;
-	};
-	
 	CPicture *background;
 	//List of buildings for each group
 	std::map< int, std::vector<const Structure*> > groups;

+ 2 - 2
client/CMT.cpp

@@ -231,7 +231,7 @@ int main(int argc, char** argv)
 
 	timeHandler total, pomtime;
 	std::cout.flags(std::ios::unitbuf);
-	logfile = new std::ofstream("VCMI_Client_log.txt");
+	logfile = new std::ofstream((GVCMIDirs.UserPath + "/VCMI_Client_log.txt").c_str());
 	console = new CConsoleHandler;
 	*console->cb = boost::bind(&processCommand, _1);
 	console->start();
@@ -446,7 +446,7 @@ void processCommand(const std::string &message)
 		
 		BOOST_FOREACH(Entry e, txth->entries)
 			if( e.type == FILE_TEXT )
-				txth->extractFile(std::string(DATA_DIR "/Extracted_txts/")+e.name,e.name);
+				txth->extractFile(std::string(GVCMIDirs.UserPath + "/Extracted_txts/")+e.name, e.name, FILE_TEXT);
 		tlog0<<"\rExtracting done :)\n";
 	}
 	else if(cn=="crash")

+ 3 - 1
client/Client.cpp

@@ -19,6 +19,7 @@
 #include "../lib/Interprocess.h"
 #include "../lib/NetPacks.h"
 #include "../lib/VCMI_Lib.h"
+#include "../lib/VCMIDirs.h"
 #include "../lib/map.h"
 #include "../lib/JsonNode.h"
 #include "mapHandler.h"
@@ -685,7 +686,8 @@ CServerHandler::~CServerHandler()
 void CServerHandler::callServer()
 {
 	setThreadName(-1, "CServerHandler::callServer");
-	std::string comm = std::string(BIN_DIR PATH_SEPARATOR SERVER_NAME " ") + port + " > server_log.txt";
+	std::string logName = GVCMIDirs.UserPath + "/server_log.txt";
+	std::string comm = std::string(BIN_DIR PATH_SEPARATOR SERVER_NAME " ") + port + " > " + logName;
 	std::system(comm.c_str());
 	tlog0 << "Server finished\n";
 }

+ 3 - 2
client/mapHandler.cpp

@@ -171,7 +171,8 @@ void CMapHandler::roadsRiverTerrainInit()
 		for (int j=0-frameH;j<(int)sizes.y+frameH;j++)
 			ttiles[i][j].resize(sizes.z, 0, 0);
 	}
-
+/*
+	//FIXME: unused?
 	// prepare the map
 	for (int i=0; i<sizes.x; i++) //by width
 	{
@@ -182,7 +183,7 @@ void CMapHandler::roadsRiverTerrainInit()
 				TerrainTile2 &pom(ttiles[i][j][k]);
 			}
 		}
-	}
+	}*/
 }
 void CMapHandler::borderAndTerrainBitmapInit()
 {

+ 1 - 1
config/buildings.json

@@ -131,7 +131,7 @@
 				{ "id" : 43, "defname" : "TBCSUP_6.def", "x" : 303, "y" : 0,   "border" : "TOCSANG2.bmp", "area" : "TZCSANG2.bmp" },
 				{ "id" : 20, "defname" : "TBCSBOAT.def", "x" : 478, "y" : 134, "border" : "TOCSDKMN.bmp", "area" : "TZCSDKMN.bmp" }
 			],
-			"blit_order" : [ 1, 2, 3, 10, 11, 12, 13, 5, 22, 30, 37, 16, 6, 20, 18, 19, 34, 41 ],
+			"blit_order" : [ 0, 1, 2, 3, 10, 11, 12, 13, 5, 22, 30, 37, 16, 6, 20, 18, 19, 34, 41 ],
 			"creatures_basic" : [ 0, 2, 4, 6, 8, 10, 12, 150 ],
 			"creatures_upgraded" : [ 1, 3, 5, 7, 9, 11, 13 ],
 			"horde" : [ 2, null ],

+ 4 - 3
lib/CLodHandler.cpp

@@ -195,10 +195,10 @@ DLL_EXPORT int CLodHandler::infs2(unsigned char * in, int size, int realSize, un
 	return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR;
 }
 
-void CLodHandler::extractFile(const std::string FName, const std::string name)
+void CLodHandler::extractFile(const std::string FName, const std::string name, LodFileType type)
 {
 	int len; //length of file to write
-	unsigned char * outp = giveFile(name, FILE_ANY, &len);
+	unsigned char * outp = giveFile(name, type, &len);
 	std::ofstream out;
 	out.open(FName.c_str(), std::ios::binary);
 	if(!out.is_open())
@@ -317,7 +317,8 @@ void CLodHandler::init(const std::string lodFile, const std::string dirName)
 	}
 	else
 	{
-		tlog1<<"Warning: No "+dirName+"/ folder!"<<std::endl;
+		if (!dirName.empty())
+			tlog1<<"Warning: No "+dirName+"/ folder!"<<std::endl;
 	}
 }
 std::string CLodHandler::getTextFile(std::string name, LodFileType type)

+ 1 - 1
lib/CLodHandler.h

@@ -116,7 +116,7 @@ public:
 	unsigned char * giveFile(std::string defName, LodFileType type=FILE_ANY, int * length=NULL); //returns pointer to the decompressed data - it must be deleted when no longer needed!
 	bool haveFile(std::string name, LodFileType type=FILE_ANY);//check if file is present in lod
 	std::string getTextFile(std::string name, LodFileType type=FILE_TEXT); //extracts one file
-	void extractFile(const std::string FName, const std::string name); //extracts a specific file
+	void extractFile(const std::string FName, const std::string name, LodFileType type=FILE_ANY); //extracts a specific file
 
 	static unsigned char * getUnpackedFile(const std::string & path, int * sizeOut); //loads given file, decompresses and returns
 };

+ 11 - 5
lib/CObjectHandler.cpp

@@ -115,11 +115,17 @@ static void readCreatures(const JsonNode &creature, std::vector< std::pair <ui16
 				creInfo.first = cre->idNumber;
 		}
 	}
-	assert(creInfo.first != -1); // ensure we found the creature
-
-	creInfo.second = creature["number"].Float();
+	if (creInfo.first != -1)
+	{
+		creInfo.second = creature["number"].Float();
 
-	storage.push_back(creInfo);
+		storage.push_back(creInfo);
+	}
+	else
+	{
+		//FIXME: localization issues. switch to numeric ID's in bank config?
+		tlog0<<"Unknown creature in bank config: "<<creName<<"\n";
+	}
 }
 
 // Bank helper. Process a bank level.
@@ -3158,7 +3164,7 @@ void CGCreature::joinDecision(const CGHeroInstance *h, int cost, ui32 accept) co
 void CGCreature::fight( const CGHeroInstance *h ) const
 {
 	//split stacks
-	int totalCount; //TODO: multiple creature types in a stack?
+	//TODO: multiple creature types in a stack?
 	int basicType = stacks.begin()->second->type->idNumber;
 	cb->setObjProperty(id, ObjProperty::MONSTER_RESTORE_TYPE, basicType); //store info about creature stack
 

+ 4 - 3
lib/JsonNode.cpp

@@ -317,7 +317,7 @@ JsonParser::JsonParser(const char * inputString, size_t stringSize, JsonNode &ro
 		error("Not all file was parsed!", true);
 
 	//TODO: better way to show errors (like printing file name as well)
-	std::cout<<errors;
+	tlog3<<errors;
 }
 
 bool JsonParser::extractSeparator()
@@ -799,7 +799,8 @@ bool JsonValidator::addMessage(const std::string &message)
 
 JsonValidator::JsonValidator(JsonNode &root)
 {
-	const JsonNode schema = root["schema"];
+	JsonNode schema;
+	schema.swap(root["schema"]);
 
 	if (!schema.isNull())
 	{
@@ -811,5 +812,5 @@ JsonValidator::JsonValidator(JsonNode &root)
 	//	addMessage("Schema not found!", true);
 
 	//TODO: better way to show errors (like printing file name as well)
-	std::cout<<errors;
+	tlog3<<errors;
 }

+ 1 - 1
server/CVCMIServer.cpp

@@ -505,7 +505,7 @@ int _tmain(int argc, _TCHAR* argv[])
 int main(int argc, char** argv)
 #endif
 {
-	logfile = new std::ofstream("VCMI_Server_log.txt");
+	logfile = new std::ofstream((GVCMIDirs.UserPath + "/VCMI_Server_log.txt").c_str());
 	console = new CConsoleHandler;
 	//boost::thread t(boost::bind(&CConsoleHandler::run,::console));
 	if(argc > 1)