Browse Source

* wczytywanie tekstów wyświetlanych przy znalezieniu artefaktu (wymaga ARTEVENT.TXT)
* wczytywanie niektórych informacji o bohaterach (wymaga HOTRAITS.TXT)
* załatanie większości wycieków pamięci (były wycieki rzędu 3MB na przesunięcie mapy...)
* zmniejszenie czasu na inne aplikacje do 30 ms (lepiej się przesuwa)

mateuszb 18 years ago
parent
commit
0abb0c8279
7 changed files with 181 additions and 6 deletions
  1. 1 0
      CAmbarCendamo.cpp
  2. 35 3
      CArtHandler.cpp
  3. 2 0
      CArtHandler.h
  4. 103 0
      CHeroHandler.cpp
  5. 32 0
      CHeroHandler.h
  6. 7 2
      CMT.cpp
  7. 1 1
      mapHandler.cpp

+ 1 - 0
CAmbarCendamo.cpp

@@ -12,6 +12,7 @@ CAmbarCendamo::CAmbarCendamo (const char * tie)
 	is->seekg(0,std::ios::beg); // wracamy na poczatek
 	bufor = new unsigned char[andame]; // allocate memory 
 	is->read((char*)bufor, andame); // read map file to buffer
+	delete is;
 }
 CAmbarCendamo::~CAmbarCendamo () 
 {// free memory

+ 35 - 3
CArtHandler.cpp

@@ -1,6 +1,5 @@
 #include "CArtHandler.h"
 #include <fstream>
-#include <iostream>
 
 void CArtHandler::loadArtifacts()
 {
@@ -15,13 +14,17 @@ void CArtHandler::loadArtifacts()
 	while(!inp.eof())
 	{
 		CArtifact nart;
-		nart.number=numberlet++;
+		nart.number = numberlet++;
 		char * read = new char[10000]; //here we'll have currently read character
 		inp.getline(read, 10000);
 		int eol=0; //end of looking
 		std::string ss = std::string(read);
 		if(ss==std::string("") && inp.eof())
+		{
+			delete [10000] read;
+			loadArtEvents();
 			return;
+		}
 		for(int i=0; i<200; ++i)
 		{
 			if(ss[i]=='\t')
@@ -31,6 +34,8 @@ void CArtHandler::loadArtifacts()
 				break;
 			}
 		}
+		if(nart.name==std::string("-1") || nart.name==std::string("-2"))
+			continue;
 		for(int i=eol; i<eol+200; ++i)
 		{
 			if(ss[i]=='\t')
@@ -191,6 +196,33 @@ void CArtHandler::loadArtifacts()
 			nart.desc2 += ss;
 		}
 		while(nart.desc2[nart.desc2.size()-1]!='"' || (nart.name==std::string("£uk Penetracji") && bowCounter<4) ); //do - while end
+		//if(nart.name!=std::string("-1") && nart.name!=std::string("-2"))
 		this->artifacts.push_back(nart);
+		delete[10000] read;
+	}
+	loadArtEvents();
+}
+
+bool CArtHandler::loadArtEvents()
+{
+	std::ifstream inp("ARTEVENT.TXT", std::ios::in);
+	if(!inp.is_open())
+	{
+		return false;
+	}
+	for(int i=0; i<this->artifacts.size(); ++i)
+	{
+		char * tab = new char[1000];
+		inp.getline(tab, 1000);
+		std::string spo = std::string("\42-1\42");
+		if(std::string(tab).substr(0, std::string(tab).size()-1)==std::string("\42-1\42")
+			|| std::string(tab).substr(0, std::string(tab).size()-1)==std::string("\"-2\""))
+		{
+			--i;
+			continue;
+		}
+		artifacts[i].eventText = std::string(tab).substr(0, std::string(tab).size()-1);
+		delete[1000] tab;
 	}
-}
+	return true;
+}

+ 2 - 0
CArtHandler.h

@@ -12,6 +12,7 @@ public:
 	std::string name;
 	std::string description;
 	std::string desc2;
+	std::string eventText;
 	unsigned int price;
 	bool spellBook, warMachine1, warMachine2, warMachine3, warMachine4, misc1, misc2, misc3, misc4, misc5, feet, lRing, rRing, torso, lHand, rHand, neck, shoulders, head;
 	EartClass aClass;
@@ -23,6 +24,7 @@ class CArtHandler //handles artifacts
 public:
 	std::vector<CArtifact> artifacts;
 	void loadArtifacts();
+	bool loadArtEvents();
 };
 
 #endif // CARTHANDLER_H

+ 103 - 0
CHeroHandler.cpp

@@ -0,0 +1,103 @@
+#include <fstream>
+#include "CHeroHandler.h"
+
+void CHeroHandler::loadHeroes()
+{
+	std::ifstream inp("HOTRAITS.TXT", std::ios::in);
+	std::string dump;
+	for(int i=0; i<25; ++i)
+	{
+		inp>>dump;
+	}
+	inp.ignore();
+	while(!inp.eof())
+	{
+		CHero nher;
+		std::string base;
+		char * tab = new char[500];
+		int iit = 0;
+		inp.getline(tab, 500);
+		base = std::string(tab);
+		if(base.size()<2) //ended, but some rubbish could still stay end we have something useless
+		{
+			return;
+		}
+		while(base[iit]!='\t')
+		{
+			++iit;
+		}
+		nher.name = base.substr(0, iit);
+		++iit;
+		for(int i=iit; i<iit+100; ++i)
+		{
+			if(base[i]==(char)(10) || base[i]==(char)(9))
+			{
+				nher.low1stack = atoi(base.substr(iit, i).c_str());
+				iit=i+1;
+				break;
+			}
+		}
+		for(int i=iit; i<iit+100; ++i)
+		{
+			if(base[i]==(char)(10) || base[i]==(char)(9))
+			{
+				nher.high1stack = atoi(base.substr(iit, i).c_str());
+				iit=i+1;
+				break;
+			}
+		}
+		int ipom=iit;
+		while(base[ipom]!='\t')
+		{
+			++ipom;
+		}
+		nher.refType1stack = base.substr(iit, ipom-iit);
+		iit=ipom+1;
+		for(int i=iit; i<iit+100; ++i)
+		{
+			if(base[i]==(char)(10) || base[i]==(char)(9))
+			{
+				nher.low2stack = atoi(base.substr(iit, i-iit).c_str());
+				iit=i+1;
+				break;
+			}
+		}
+		for(int i=iit; i<iit+100; ++i)
+		{
+			if(base[i]==(char)(10) || base[i]==(char)(9))
+			{
+				nher.high2stack = atoi(base.substr(iit, i-iit).c_str());
+				iit=i+1;
+				break;
+			}
+		}
+		ipom=iit;
+		while(base[ipom]!='\t')
+		{
+			++ipom;
+		}
+		nher.refType2stack = base.substr(iit, ipom-iit);
+		iit=ipom+1;
+		for(int i=iit; i<iit+100; ++i)
+		{
+			if(base[i]==(char)(10) || base[i]==(char)(9))
+			{
+				nher.low3stack = atoi(base.substr(iit, i-iit).c_str());
+				iit=i+1;
+				break;
+			}
+		}
+		for(int i=iit; i<iit+100; ++i)
+		{
+			if(base[i]==(char)(10) || base[i]==(char)(9))
+			{
+				nher.high3stack = atoi(base.substr(iit, i-iit).c_str());
+				iit=i+1;
+				break;
+			}
+		}
+		nher.refType3stack = base.substr(iit, base.size()-iit);
+		heroes.push_back(nher);
+		delete[500] tab;
+	}
+}

+ 32 - 0
CHeroHandler.h

@@ -0,0 +1,32 @@
+#ifndef CHEROHANDLER_H
+#define CHEROHANDLER_H
+
+#include <string>
+#include <vector>
+
+class CHero
+{
+public:
+	std::string name;
+	int low1stack, high1stack, low2stack, high2stack, low3stack, high3stack; //amount of units; described below
+	std::string refType1stack, refType2stack, refType3stack; //reference names of units appearing in hero's army if he is recruited in tavern
+};
+
+class CHeroInstance
+{
+public:
+	CHero type;
+	int x, y; //position
+	bool under; //is underground?
+	//TODO: armia, artefakty, itd.
+};
+
+class CHeroHandler
+{
+public:
+	std::vector<CHero> heroes;
+	void loadHeroes();
+};
+
+
+#endif //CHEROHANDLER_H

+ 7 - 2
CMT.cpp

@@ -12,6 +12,7 @@
 #include <cmath>
 #include <ctime>
 #include "CArthandler.h"
+#include "CHeroHandler.h"
 
 #if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
 #  include <fcntl.h>
@@ -224,6 +225,8 @@ int _tmain(int argc, _TCHAR* argv[])
 		THC timeHandler tmh;
 		CArtHandler * arth = new CArtHandler;
 		arth->loadArtifacts();
+		CHeroHandler * heroh = new CHeroHandler;
+		heroh->loadHeroes();
 		CAmbarCendamo * ac = new CAmbarCendamo("4gryf");
 		THC std::cout<<"Wczytywanie pliku: "<<tmh.getDif()<<std::endl;
 		ac->deh3m();
@@ -289,7 +292,9 @@ int _tmain(int argc, _TCHAR* argv[])
 							}
 						}
 						SDL_FillRect(ekran, NULL, SDL_MapRGB(ekran->format, 0, 0, 0));
-						SDL_BlitSurface(mh->terrainRect(xx,yy,32,24),NULL,ekran,NULL);
+						SDL_Surface * help = mh->terrainRect(xx,yy,32,24);
+						SDL_BlitSurface(help,NULL,ekran,NULL);
+						SDL_FreeSurface(help);
 						SDL_Flip(ekran);
 					}
 				}
@@ -297,7 +302,7 @@ int _tmain(int argc, _TCHAR* argv[])
 			catch(...)
 			{ continue; }
 
-			SDL_Delay(50); //give time for other apps
+			SDL_Delay(30); //give time for other apps
 		}
 		return 0;
 	}

+ 1 - 1
mapHandler.cpp

@@ -83,7 +83,7 @@ SDL_Surface * mapHandler::terrainRect(int x, int y, int dx, int dy)
 			sr->h=sr->w=32;
 			
 			SDL_BlitSurface(terrainBitmap[bx+x][by+y],NULL,su,sr);
-
+			delete sr;
 			//SDL_BlitSurface(su,NULL,ekran,NULL);SDL_Flip(ekran);
 		}
 	}