浏览代码

deleting objects, a bit of hero randomizing

mateuszb 18 年之前
父节点
当前提交
b226540775
共有 2 个文件被更改,包括 68 次插入35 次删除
  1. 67 35
      mapHandler.cpp
  2. 1 0
      mapHandler.h

+ 67 - 35
mapHandler.cpp

@@ -11,7 +11,9 @@
 #include "CGameState.h"
 #include "CLua.h"
 #include "hch\CCastleHandler.h"
-#include "hch/CHeroHandler.h"
+#include "hch\CHeroHandler.h"
+#include <iomanip>
+#include <sstream>
 extern SDL_Surface * ekran;
 
 class OCM_HLP
@@ -26,47 +28,60 @@ public:
 void CMapHandler::init()
 {
 	///////////////randomizing objects on map///////////////////////////
-
-	for(int no=0; no<CGI->objh->objInstances.size(); ++no)
+	for(int gh=0; gh<2; ++gh) //some objects can be initialized not before initializing some other
 	{
-		std::string nname = getRandomizedDefName(CGI->objh->objInstances[no]->defInfo, CGI->objh->objInstances[no]);
-		if(nname.size()>0) //change def
+		for(int no=0; no<CGI->objh->objInstances.size(); ++no)
 		{
-			int f=-1;
-			for(f=0; f<CGI->dobjinfo->objs.size(); ++f)
+			std::string nname = getRandomizedDefName(CGI->objh->objInstances[no]->defInfo, CGI->objh->objInstances[no]);
+			if(nname.size()>0) //change def
 			{
-				if(CGI->dobjinfo->objs[f].defName==nname)
+				int f=-1;
+				for(f=0; f<CGI->dobjinfo->objs.size(); ++f)
 				{
-					break;
+					if(CGI->dobjinfo->objs[f].defName==nname)
+					{
+						break;
+					}
 				}
-			}
-			CGI->objh->objInstances[no]->defInfo->name = nname;
-			if(loadedDefs.find(nname)!=loadedDefs.end())
-			{
-				CGI->objh->objInstances[no]->defInfo->handler = loadedDefs.find(nname)->second;
-			}
-			else
-			{
-				CGI->objh->objInstances[no]->defInfo->handler = CGI->spriteh->giveDef(nname);
-				for(int dd=0; dd<CGI->objh->objInstances[no]->defInfo->handler->ourImages.size(); ++dd)
+				CGI->objh->objInstances[no]->defInfo->name = nname;
+				if(CGI->objh->objInstances[no]->ID==70) //random hero - init here
 				{
-					CSDL_Ext::fullAlphaTransform(CGI->objh->objInstances[no]->defInfo->handler->ourImages[dd].bitmap);
+					CHeroObjInfo* curc = ((CHeroObjInfo*)CGI->objh->objInstances[no]->info);
+					curc->type = CGI->heroh->heroes[rand()%CGI->heroh->heroes.size()];
+					curc->sex = rand()%2; //TODO: what to do with that?
+					curc->name = curc->type->name;
+					curc->attack = curc->type->heroClass->initialAttack;
+					curc->defence = curc->type->heroClass->initialDefence;
+					curc->knowledge = curc->type->heroClass->initialKnowledge;
+					curc->power = curc->type->heroClass->initialPower;
+				}
+				if(loadedDefs.find(nname)!=loadedDefs.end())
+				{
+					CGI->objh->objInstances[no]->defInfo->handler = loadedDefs.find(nname)->second;
+				}
+				else
+				{
+					CGI->objh->objInstances[no]->defInfo->handler = CGI->spriteh->giveDef(nname);
+					for(int dd=0; dd<CGI->objh->objInstances[no]->defInfo->handler->ourImages.size(); ++dd)
+					{
+						CSDL_Ext::fullAlphaTransform(CGI->objh->objInstances[no]->defInfo->handler->ourImages[dd].bitmap);
+					}
+					loadedDefs.insert(std::pair<std::string, CDefHandler*>(nname, CGI->objh->objInstances[no]->defInfo->handler));
+				}
+				CGI->objh->objInstances[no]->defObjInfoNumber = f;
+				if(f!=-1)
+				{
+					CGI->objh->objInstances[no]->defInfo->isOnDefList = true;
+					CGI->objh->objInstances[no]->ID = CGI->dobjinfo->objs[f].type;
+					CGI->objh->objInstances[no]->subID = CGI->dobjinfo->objs[f].subtype;
+					CGI->objh->objInstances[no]->defInfo->id = CGI->dobjinfo->objs[f].type;
+					CGI->objh->objInstances[no]->defInfo->subid = CGI->dobjinfo->objs[f].subtype;
+					CGI->objh->objInstances[no]->defInfo->printPriority = CGI->dobjinfo->objs[f].priority;
+				}
+				else
+				{
+					CGI->objh->objInstances[no]->defInfo->isOnDefList = false;
 				}
-				loadedDefs.insert(std::pair<std::string, CDefHandler*>(nname, CGI->objh->objInstances[no]->defInfo->handler));
-			}
-			CGI->objh->objInstances[no]->defObjInfoNumber = f;
-			if(f!=-1)
-			{
-				CGI->objh->objInstances[no]->defInfo->isOnDefList = true;
-				CGI->objh->objInstances[no]->ID = CGI->dobjinfo->objs[f].type;
-				CGI->objh->objInstances[no]->subID = CGI->dobjinfo->objs[f].subtype;
-				CGI->objh->objInstances[no]->defInfo->id = CGI->dobjinfo->objs[f].type;
-				CGI->objh->objInstances[no]->defInfo->subid = CGI->dobjinfo->objs[f].subtype;
-				CGI->objh->objInstances[no]->defInfo->printPriority = CGI->dobjinfo->objs[f].priority;
-			}
-			else
-			{
-				CGI->objh->objInstances[no]->defInfo->isOnDefList = false;
 			}
 		}
 	}
@@ -1766,6 +1781,23 @@ std::string CMapHandler::getRandomizedDefName(CGDefInfo *di, CGObjectInstance *
 			}
 		}
 	}
+	else if(di->id==70) //random hero
+	{
+		std::stringstream nm;
+		nm<<"AH";
+		nm<<std::setw(2);
+		nm<<std::setfill('0');
+		nm<<rand()%18; //HARDCODED VALUE! TODO: REMOVE IN FUTURE
+		nm<<"_.DEF";
+		return nm.str();
+	}
 
 	return std::string();
 }
+
+bool CMapHandler::removeObject(CGObjectInstance *obj)
+{
+	hideObject(obj);
+	CGI->objh->objInstances.erase(std::find(CGI->objh->objInstances.begin(), CGI->objh->objInstances.end(), obj));
+	return true;
+}

+ 1 - 0
mapHandler.h

@@ -86,6 +86,7 @@ public:
 	std::string getDefName(int id, int subid); //returns name of def for object with given id and subid
 	bool printObject(CGObjectInstance * obj); //puts appropriate things to ttiles, so obj will be visible on map
 	bool hideObject(CGObjectInstance * obj); //removes appropriate things from ttiles, so obj will be no longer visible on map (but still will exist)
+	bool removeObject(CGObjectInstance * obj); //removes object from each place in VCMI (I hope)
 	void init();
 	SDL_Surface * terrainRect(int x, int y, int dx, int dy, int level=0, unsigned char anim=0, PseudoV< PseudoV< PseudoV<unsigned char> > > & visibilityMap = CGI->mh->visibility);
 	SDL_Surface * terrBitmap(int x, int y);