Browse Source

Working mines and minor improvements.

Michał W. Urbańczyk 18 years ago
parent
commit
845d99a908
9 changed files with 111 additions and 17 deletions
  1. 2 3
      CCallback.cpp
  2. 5 1
      CGameState.h
  3. 56 10
      CLua.cpp
  4. 15 0
      CLua.h
  5. 2 0
      CMT.cpp
  6. 11 1
      CPlayerInterface.cpp
  7. 1 1
      global.h
  8. 18 1
      hch/CObjectHandler.cpp
  9. 1 0
      hch/CObjectHandler.h

+ 2 - 3
CCallback.cpp

@@ -38,10 +38,9 @@ void CCallback::newTurn()
 {
 {
 	//std::map<int, PlayerState>::iterator i = gs->players.begin() ;
 	//std::map<int, PlayerState>::iterator i = gs->players.begin() ;
 	gs->day++;
 	gs->day++;
-	for (int i=0;i<CGI->objh->objInstances.size();i++)
+	for (std::set<CCPPObjectScript *>::iterator i=gs->cppscripts.begin();i!=gs->cppscripts.end();i++)
 	{
 	{
-		if (CGI->objh->objInstances[i]->state)
-			CGI->objh->objInstances[i]->state->newTurn();
+		(*i)->newTurn();
 	}
 	}
 	for ( std::map<int, PlayerState>::iterator i=gs->players.begin() ; i!=gs->players.end();i++)
 	for ( std::map<int, PlayerState>::iterator i=gs->players.begin() ; i!=gs->players.end();i++)
 	{
 	{

+ 5 - 1
CGameState.h

@@ -1,11 +1,13 @@
 #ifndef CGAMESTATE_H
 #ifndef CGAMESTATE_H
 #define CGAMESTATE_H
 #define CGAMESTATE_H
 #include "mapHandler.h"
 #include "mapHandler.h"
+#include <set>
 class CScriptCallback;
 class CScriptCallback;
 class CHeroInstance;
 class CHeroInstance;
 class CTownInstance;
 class CTownInstance;
 class CCallback;
 class CCallback;
 class CLuaCallback;
 class CLuaCallback;
+class CCPPObjectScript;
 struct PlayerState
 struct PlayerState
 {
 {
 public:
 public:
@@ -24,7 +26,8 @@ private:
 	int currentPlayer;
 	int currentPlayer;
 	int day; //total number of days in game
 	int day; //total number of days in game
 	std::map<int,PlayerState> players; //color <-> playerstate
 	std::map<int,PlayerState> players; //color <-> playerstate
-	std::map<int, std::map<std::string, CObjectScript*> > objscr; //custom user scripts
+	std::set<CCPPObjectScript *> cppscripts;
+	std::map<int, std::map<std::string, CObjectScript*> > objscr; //custom user scripts (as for now only Lua)
 	
 	
 
 
 	bool checkFunc(int obid, std::string name)
 	bool checkFunc(int obid, std::string name)
@@ -58,6 +61,7 @@ public:
 	friend int _tmain(int argc, _TCHAR* argv[]);
 	friend int _tmain(int argc, _TCHAR* argv[]);
 	friend void initGameState(CGameInfo * cgi);
 	friend void initGameState(CGameInfo * cgi);
 	friend CScriptCallback;
 	friend CScriptCallback;
+	friend void handleCPPObjS(std::map<int,CCPPObjectScript*> * mapa, CCPPObjectScript * script);
 	//CCallback * cb; //for communication between PlayerInterface/AI and GameState
 	//CCallback * cb; //for communication between PlayerInterface/AI and GameState
 
 
 	friend SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level, unsigned char anim, PseudoV< PseudoV< PseudoV<unsigned char> > > & visibilityMap); //todo: wywalic koniecznie, tylko do flag obecnie!!!!
 	friend SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level, unsigned char anim, PseudoV< PseudoV< PseudoV<unsigned char> > > & visibilityMap); //todo: wywalic koniecznie, tylko do flag obecnie!!!!

+ 56 - 10
CLua.cpp

@@ -389,13 +389,59 @@ std::string CVisitableOPW::hoverText(CGObjectInstance *os)
 	return CGI->objh->objects[os->defInfo->id].name + " " + ( (visited[os]) ? (CGI->generaltexth->allTexts[352]) : (CGI->generaltexth->allTexts[353]))  ;
 	return CGI->objh->objects[os->defInfo->id].name + " " + ( (visited[os]) ? (CGI->generaltexth->allTexts[352]) : (CGI->generaltexth->allTexts[353]))  ;
 }
 }
 
 
-//std::string SComponent::getSubtitle()
-//{
-//	std::string ret;
-//
-//
-//	return ret;
-//}
-//void SComponent::getDescription(Etype Type, int Subtype)
-//{
-//}
+void CMines::newObject(CGObjectInstance *os)
+{
+	ourObjs.push_back(os);
+	os->tempOwner = NEUTRAL_PLAYER;
+}
+void CMines::onHeroVisit(CGObjectInstance *os, int heroID)
+{
+	int vv = 1;
+	if (os->subID==0 || os->subID==2)
+		vv++;
+	else if (os->subID==6)
+		vv = 1000;
+	if (os->tempOwner == cb->getHeroOwner(heroID))
+	{
+		//TODO: garrison
+	}
+	else
+	{
+		if (os->subID==7)
+			return; //TODO: support for abandoned mine
+		os->tempOwner = cb->getHeroOwner(heroID);
+		SComponent * com = new SComponent(SComponent::Etype::resource,os->subID,vv);
+		com->subtitle+=CGI->generaltexth->allTexts[3].substr(2,CGI->generaltexth->allTexts[3].length()-2);
+		std::vector<SComponent*> weko;
+		weko.push_back(com);
+		cb->showInfoDialog(cb->getHeroOwner(heroID),CGI->objh->mines[os->subID].second,&weko);
+	}
+}
+std::vector<int> CMines::yourObjects()
+{
+	std::vector<int> ret(1);
+	ret.push_back(53);
+	return ret;
+}
+std::string CMines::hoverText(CGObjectInstance *os)
+{
+	if (os->tempOwner == NEUTRAL_PLAYER)
+		return CGI->objh->mines[os->subID].first;
+	else
+		return CGI->objh->mines[os->subID].first + " " + CGI->generaltexth->arraytxt[23+os->tempOwner];
+
+}
+void CMines::newTurn ()
+{
+	for (int i=0;i<ourObjs.size();i++)
+	{
+		if (ourObjs[i]->tempOwner == NEUTRAL_PLAYER)
+			continue;
+		int vv = 1;
+		if (ourObjs[i]->subID==0 || ourObjs[i]->subID==2)
+			vv++;
+		else if (ourObjs[i]->subID==6)
+			vv = 1000;
+		cb->giveResource(ourObjs[i]->tempOwner,ourObjs[i]->subID,vv);
+	}
+}

+ 15 - 0
CLua.h

@@ -112,5 +112,20 @@ class CVisitableOPW : public CCPPObjectScript  //once per week
 	std::string hoverText(CGObjectInstance *os);
 	std::string hoverText(CGObjectInstance *os);
 	void newTurn (); 
 	void newTurn (); 
 
 
+	friend void initGameState(CGameInfo * cgi);
+};
+
+class CMines : public CCPPObjectScript  //flaggable, and giving resource at each day
+{
+	CMines(CScriptCallback * CB):CCPPObjectScript(CB){};
+
+	std::vector<CGObjectInstance*> ourObjs;
+
+	void newObject(CGObjectInstance *os);
+	void onHeroVisit(CGObjectInstance *os, int heroID);
+	std::vector<int> yourObjects(); //returns IDs of objects which are handled by script
+	std::string hoverText(CGObjectInstance *os);
+	void newTurn (); 
+
 	friend void initGameState(CGameInfo * cgi);
 	friend void initGameState(CGameInfo * cgi);
 };
 };

+ 2 - 0
CMT.cpp

@@ -66,6 +66,7 @@ void handleCPPObjS(std::map<int,CCPPObjectScript*> * mapa, CCPPObjectScript * sc
 	{
 	{
 		(*mapa)[tempv[i]]=script;
 		(*mapa)[tempv[i]]=script;
 	}
 	}
+	CGI->state->cppscripts.insert(script);
 }
 }
 void initGameState(CGameInfo * cgi)
 void initGameState(CGameInfo * cgi)
 {
 {
@@ -221,6 +222,7 @@ void initGameState(CGameInfo * cgi)
 	csc->gs = cgi->state;
 	csc->gs = cgi->state;
 	handleCPPObjS(&scripts,new CVisitableOPH(csc));
 	handleCPPObjS(&scripts,new CVisitableOPH(csc));
 	handleCPPObjS(&scripts,new CVisitableOPW(csc));
 	handleCPPObjS(&scripts,new CVisitableOPW(csc));
+	handleCPPObjS(&scripts,new CMines(csc));
 	//created map
 	//created map
 
 
 
 

+ 11 - 1
CPlayerInterface.cpp

@@ -41,7 +41,11 @@ void CInfoWindow::okClicked(tribool down)
 void CInfoWindow::close()
 void CInfoWindow::close()
 {
 {
 	for (int i=0;i<components.size();i++)
 	for (int i=0;i<components.size();i++)
+	{
+		components[i]->deactivate();
 		delete components[i];
 		delete components[i];
+	}
+	components.clear();
 	okb.deactivate();
 	okb.deactivate();
 	SDL_FreeSurface(bitmap);
 	SDL_FreeSurface(bitmap);
 	bitmap = NULL;
 	bitmap = NULL;
@@ -1195,7 +1199,7 @@ void CPlayerInterface::heroPrimarySkillChanged(const CGHeroInstance * hero, int
 }
 }
 void CPlayerInterface::showInfoDialog(std::string text, std::vector<SComponent*> & components)
 void CPlayerInterface::showInfoDialog(std::string text, std::vector<SComponent*> & components)
 {
 {
-	adventureInt->hide();
+	adventureInt->hide(); //dezaktywacja starego interfejsu
 	CInfoWindow * temp = CMessage::genIWindow(text,LOCPLINT->playerID,32,components);
 	CInfoWindow * temp = CMessage::genIWindow(text,LOCPLINT->playerID,32,components);
 	LOCPLINT->objsToBlit.push_back(temp);
 	LOCPLINT->objsToBlit.push_back(temp);
 	temp->pos.x=300-(temp->pos.w/2);
 	temp->pos.x=300-(temp->pos.w/2);
@@ -1203,6 +1207,12 @@ void CPlayerInterface::showInfoDialog(std::string text, std::vector<SComponent*>
 	temp->okb.pos.x = temp->okb.posr.x + temp->pos.x;
 	temp->okb.pos.x = temp->okb.posr.x + temp->pos.x;
 	temp->okb.pos.y = temp->okb.posr.y + temp->pos.y;
 	temp->okb.pos.y = temp->okb.posr.y + temp->pos.y;
 	temp->okb.activate();
 	temp->okb.activate();
+	for (int i=0;i<temp->components.size();i++)
+	{
+		temp->components[i]->activate();
+		temp->components[i]->pos.x += temp->pos.x;
+		temp->components[i]->pos.y += temp->pos.y;
+	}
 }
 }
 void CPlayerInterface::removeObjToBlit(CSimpleWindow* obj)
 void CPlayerInterface::removeObjToBlit(CSimpleWindow* obj)
 {
 {

+ 1 - 1
global.h

@@ -41,7 +41,7 @@ const int HEROES_QUANTITY=156;
 const int RESOURCE_QUANTITY=8;
 const int RESOURCE_QUANTITY=8;
 const int TERRAIN_TYPES=10;
 const int TERRAIN_TYPES=10;
 const int PRIMARY_SKILLS=4;
 const int PRIMARY_SKILLS=4;
-
+const int NEUTRAL_PLAYER=255;
 const int NAMES_PER_TOWN=16;
 const int NAMES_PER_TOWN=16;
 
 
 #define MARK_BLOCKED_POSITIONS false
 #define MARK_BLOCKED_POSITIONS false

+ 18 - 1
hch/CObjectHandler.cpp

@@ -36,12 +36,29 @@ void CObjectHandler::loadObjects()
 
 
 	buf = CGameInfo::mainObj->bitmaph->getTextFile("XTRAINFO.TXT");
 	buf = CGameInfo::mainObj->bitmaph->getTextFile("XTRAINFO.TXT");
 	it=0;
 	it=0;
-	temp;
 	while (it<buf.length()-1)
 	while (it<buf.length()-1)
 	{
 	{
 		CGeneralTextHandler::loadToIt(temp,buf,it,3);
 		CGeneralTextHandler::loadToIt(temp,buf,it,3);
 		xtrainfo.push_back(temp);
 		xtrainfo.push_back(temp);
 	}
 	}
+
+	buf = CGameInfo::mainObj->bitmaph->getTextFile("MINENAME.TXT");
+	it=0;
+	while (it<buf.length()-1)
+	{
+		CGeneralTextHandler::loadToIt(temp,buf,it,3);
+		mines.push_back(std::pair<std::string,std::string>(temp,""));
+	}
+
+	buf = CGameInfo::mainObj->bitmaph->getTextFile("MINEEVNT.TXT");
+	it=0;
+	int i=0;
+	while (it<buf.length()-1)
+	{
+		CGeneralTextHandler::loadToIt(temp,buf,it,3);
+		temp = temp.substr(1,temp.length()-2);
+		mines[i++].second = temp;
+	}
 	
 	
 }
 }
 
 

+ 1 - 0
hch/CObjectHandler.h

@@ -450,6 +450,7 @@ public:
 
 
 	std::vector<std::string> advobtxt;
 	std::vector<std::string> advobtxt;
 	std::vector<std::string> xtrainfo;
 	std::vector<std::string> xtrainfo;
+	std::vector<std::pair<std::string,std::string> > mines; //first - name; second - event
 };
 };