Browse Source

* hints for cregens
* moved battle loop to the activeStack

Michał W. Urbańczyk 17 years ago
parent
commit
17d5d298ca
11 changed files with 72 additions and 14 deletions
  1. 1 1
      CCallback.h
  2. 1 1
      CGameState.cpp
  3. 24 5
      CLua.cpp
  4. 12 0
      CLua.h
  5. 1 0
      CMT.cpp
  6. 14 0
      CPlayerInterface.cpp
  7. 3 1
      config/cregens.txt
  8. 1 1
      hch/CAmbarCendamo.cpp
  9. 4 4
      hch/CLodHandler.cpp
  10. 10 1
      hch/CObjectHandler.cpp
  11. 1 0
      hch/CObjectHandler.h

+ 1 - 1
CCallback.h

@@ -9,7 +9,7 @@ class CGObjectInstance;
 class SComponent;
 class SComponent;
 class IChosen;
 class IChosen;
 class CSelectableComponent;
 class CSelectableComponent;
-class Action;
+struct Action;
 typedef struct lua_State lua_State;
 typedef struct lua_State lua_State;
 
 
 class ICallback
 class ICallback

+ 1 - 1
CGameState.cpp

@@ -92,7 +92,7 @@ void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, C
 
 
 	curB->round++;
 	curB->round++;
 
 
-	SDL_Thread * eventh = SDL_CreateThread(battleEventThread, NULL);
+	//SDL_Thread * eventh = SDL_CreateThread(battleEventThread, NULL);
 
 
 	while(true) //do zwyciestwa jednej ze stron
 	while(true) //do zwyciestwa jednej ze stron
 	{
 	{

+ 24 - 5
CLua.cpp

@@ -647,13 +647,13 @@ void CHeroScript::onHeroVisit(CGObjectInstance *os, int heroID)
 std::vector<int> CHeroScript::yourObjects() //returns IDs of objects which are handled by script
 std::vector<int> CHeroScript::yourObjects() //returns IDs of objects which are handled by script
 {
 {
 	std::vector<int> ret(1);
 	std::vector<int> ret(1);
-	ret.push_back(34); //town
+	ret.push_back(34); //hero
 	return ret;
 	return ret;
 }
 }
 
 
 void CMonsterS::newObject(CGObjectInstance *os)
 void CMonsterS::newObject(CGObjectInstance *os)
 {
 {
-	os->blockVisit = true;
+	//os->blockVisit = true;
 	switch(CGI->creh->creatures[os->subID].level)
 	switch(CGI->creh->creatures[os->subID].level)
 	{
 	{
 	case 1:
 	case 1:
@@ -694,18 +694,37 @@ std::string CMonsterS::hoverText(CGObjectInstance *os)
 {
 {
 	int pom = CCreature::getQuantityID(((CCreatureObjInfo*)os->info)->number);
 	int pom = CCreature::getQuantityID(((CCreatureObjInfo*)os->info)->number);
 	pom = 174 + 3*pom + 1;
 	pom = 174 + 3*pom + 1;
-	return CGI->generaltexth->arraytxt[pom] + CGI->creh->creatures[os->subID].namePl;
+	return CGI->generaltexth->arraytxt[pom] + " " + CGI->creh->creatures[os->subID].namePl;
 }
 }
 void CMonsterS::onHeroVisit(CGObjectInstance *os, int heroID)
 void CMonsterS::onHeroVisit(CGObjectInstance *os, int heroID)
 {
 {
 	CCreatureSet set;
 	CCreatureSet set;
 	//TODO: zrobic secik w sposob wyrafinowany
 	//TODO: zrobic secik w sposob wyrafinowany
 	set.slots[0] = std::pair<CCreature*,int>(&CGI->creh->creatures[os->subID],((CCreatureObjInfo*)os->info)->number);
 	set.slots[0] = std::pair<CCreature*,int>(&CGI->creh->creatures[os->subID],((CCreatureObjInfo*)os->info)->number);
-	//cb->startBattle(heroID,&set,os->pos);
+	cb->startBattle(heroID,&set,os->pos);
 }
 }
 std::vector<int> CMonsterS::yourObjects() //returns IDs of objects which are handled by script
 std::vector<int> CMonsterS::yourObjects() //returns IDs of objects which are handled by script
 {
 {
 	std::vector<int> ret(1);
 	std::vector<int> ret(1);
-	ret.push_back(54); //town
+	ret.push_back(54); //monster
 	return ret;
 	return ret;
 }
 }
+
+
+void CCreatureGen::newObject(CGObjectInstance *os)
+{
+	amount[os] = CGI->creh->creatures[CGI->objh->cregens[os->subID]].growth;
+}
+std::string CCreatureGen::hoverText(CGObjectInstance *os)
+{
+	return CGI->objh->creGens[os->subID];
+}
+void CCreatureGen::onHeroVisit(CGObjectInstance *os, int heroID)
+{
+}
+std::vector<int> CCreatureGen::yourObjects() //returns IDs of objects which are handled by script
+{
+	std::vector<int> ret(1);
+	ret.push_back(17); //cregen1
+	return ret;
+}

+ 12 - 0
CLua.h

@@ -184,5 +184,17 @@ class CMonsterS : public CCPPObjectScript
 	void onHeroVisit(CGObjectInstance *os, int heroID);
 	void onHeroVisit(CGObjectInstance *os, int heroID);
 	std::vector<int> yourObjects(); //returns IDs of objects which are handled by script
 	std::vector<int> yourObjects(); //returns IDs of objects which are handled by script
 
 
+	friend void initGameState(CGameInfo * cgi);
+};
+
+class CCreatureGen : public CCPPObjectScript
+{
+	std::map<CGObjectInstance*, int> amount; //amount of creatures in each dwelling
+	CCreatureGen(CScriptCallback * CB):CCPPObjectScript(CB){};
+	void newObject(CGObjectInstance *os);
+	std::string hoverText(CGObjectInstance *os);
+	void onHeroVisit(CGObjectInstance *os, int heroID);
+	std::vector<int> yourObjects(); //returns IDs of objects which are handled by script
+
 	friend void initGameState(CGameInfo * cgi);
 	friend void initGameState(CGameInfo * cgi);
 };
 };

+ 1 - 0
CMT.cpp

@@ -251,6 +251,7 @@ void initGameState(CGameInfo * cgi)
 	handleCPPObjS(&scripts,new CTownScript(csc));
 	handleCPPObjS(&scripts,new CTownScript(csc));
 	handleCPPObjS(&scripts,new CHeroScript(csc));
 	handleCPPObjS(&scripts,new CHeroScript(csc));
 	handleCPPObjS(&scripts,new CMonsterS(csc));
 	handleCPPObjS(&scripts,new CMonsterS(csc));
+	handleCPPObjS(&scripts,new CCreatureGen(csc));
 	//created map
 	//created map
 
 
 	/****************************LUA OBJECT SCRIPTS************************************************/
 	/****************************LUA OBJECT SCRIPTS************************************************/

+ 14 - 0
CPlayerInterface.cpp

@@ -1873,6 +1873,20 @@ void CPlayerInterface::actionFinished(Action action)//occurs AFTER every action
 
 
 void CPlayerInterface::activeStack(int stackID) //called when it's turn of that stack
 void CPlayerInterface::activeStack(int stackID) //called when it's turn of that stack
 {
 {
+	while(true)
+	{
+		SDL_Event sEvent;
+		while (SDL_PollEvent(&sEvent))  //wait for event...
+		{
+			LOCPLINT->handleEvent(&sEvent);
+		}
+		for(int i=0;i<objsToBlit.size();i++)
+			objsToBlit[i]->show();
+		//SDL_Flip(ekran);
+		CSDL_Ext::update(ekran);
+		SDL_Delay(5); //give time for other apps
+		SDL_framerateDelay(mainFPSmng);
+	}
 }
 }
 
 
 void CPlayerInterface::battleEnd(CCreatureSet * army1, CCreatureSet * army2, CGHeroInstance *hero1, CGHeroInstance *hero2, std::vector<int> capturedArtifacts, int expForWinner, bool winner)
 void CPlayerInterface::battleEnd(CCreatureSet * army1, CCreatureSet * army2, CGHeroInstance *hero1, CGHeroInstance *hero2, std::vector<int> capturedArtifacts, int expForWinner, bool winner)

+ 3 - 1
config/cregens.txt

@@ -90,10 +90,12 @@
 90	170
 90	170
 91	168
 91	168
 92	172
 92	172
+93	164
 94	169
 94	169
 95	173
 95	173
 96	192
 96	192
 97	193
 97	193
 98	194
 98	194
 99	195
 99	195
-100	196
+100	196
+68	24

+ 1 - 1
hch/CAmbarCendamo.cpp

@@ -514,7 +514,7 @@ void CAmbarCendamo::deh3m()
 	THC std::cout<<"\tReading rumors: "<<th.getDif()<<std::endl;
 	THC std::cout<<"\tReading rumors: "<<th.getDif()<<std::endl;
 	switch(map.version)
 	switch(map.version)
 	{
 	{
-	case WoG: case SoD: case AB:
+	case WoG: case SoD:
 		{
 		{
 			for(int z=0;z<HEROES_QUANTITY;z++) //disposed heroes
 			for(int z=0;z<HEROES_QUANTITY;z++) //disposed heroes
 			{
 			{

+ 4 - 4
hch/CLodHandler.cpp

@@ -795,12 +795,12 @@ std::string CLodHandler::getTextFile(std::string name)
 	std::string ret0;
 	std::string ret0;
 	std::transform(name.begin(), name.end(), name.begin(), (int(*)(int))toupper);
 	std::transform(name.begin(), name.end(), name.begin(), (int(*)(int))toupper);
 	Entry *e;
 	Entry *e;
-	for (int i=0;i<totalFiles;i++)
-	{
-		e = entries.znajdz(name);
-	}
+	e = entries.znajdz(name);
 	if(!e)
 	if(!e)
+	{
+		std::cout << "Error: cannot load "<<name<<" from the .lod file!"<<std::endl;
 		return ret0;
 		return ret0;
+	}
 	if(e->offset<0)
 	if(e->offset<0)
 	{
 	{
 		char * outp = new char[e->realSize];
 		char * outp = new char[e->realSize];

+ 10 - 1
hch/CObjectHandler.cpp

@@ -79,7 +79,16 @@ void CObjectHandler::loadObjects()
 		ifs >> dw >> cr;
 		ifs >> dw >> cr;
 		cregens[dw]=cr;
 		cregens[dw]=cr;
 	}
 	}
-	
+	ifs.close();
+	ifs.clear();
+	buf = CGameInfo::mainObj->bitmaph->getTextFile("ZCRGN1.TXT");
+	it=0;
+	while (it<buf.length()-1)
+	{
+		CGeneralTextHandler::loadToIt(temp,buf,it,3);
+		creGens.push_back(temp);
+	}
+
 }
 }
 
 
 bool CGObjectInstance::isHero() const
 bool CGObjectInstance::isHero() const

+ 1 - 0
hch/CObjectHandler.h

@@ -419,6 +419,7 @@ public:
 	std::vector<int> cregens; //type 17. dwelling subid -> creature ID
 	std::vector<int> cregens; //type 17. dwelling subid -> creature ID
 	void loadObjects();
 	void loadObjects();
 
 
+	std::vector<std::string> creGens; //names of creatures' generators
 	std::vector<std::string> advobtxt;
 	std::vector<std::string> advobtxt;
 	std::vector<std::string> xtrainfo;
 	std::vector<std::string> xtrainfo;
 	std::vector<std::string> restypes;
 	std::vector<std::string> restypes;