瀏覽代碼

More stuff for selection window.

Michał W. Urbańczyk 18 年之前
父節點
當前提交
01c996591a
共有 8 個文件被更改,包括 141 次插入24 次删除
  1. 1 0
      AI/EmptyAI/CEmptyAI.h
  2. 27 5
      CCallback.cpp
  3. 3 0
      CCallback.h
  4. 1 0
      CGameInterface.h
  5. 74 5
      CLua.cpp
  6. 11 3
      CLua.h
  7. 20 9
      CPlayerInterface.cpp
  8. 4 2
      CPlayerInterface.h

+ 1 - 0
AI/EmptyAI/CEmptyAI.h

@@ -10,6 +10,7 @@ public:
 	void heroCreated(const CHeroInstance *);
 	void heroMoved(const HeroMoveDetails &);
 	void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val) {};
+	void showSelDialog(std::string text, std::vector<SComponent*> & components, int askID){};
 	void tileRevealed(int3 pos){};
 	void tileHidden(int3 pos){};
 };

+ 27 - 5
CCallback.cpp

@@ -204,6 +204,12 @@ bool CCallback::moveHero(int ID, CPath * path, int idtype, int pathType)
 	return true;
 }
 
+void CCallback::selectionMade(int selection, int asker)
+{
+	//todo - jak bedzie multiplayer po sieci, to moze wymagac przerobek zaleznych od obranego modelu
+	IChosen * ask = (IChosen *)asker;
+	ask->chosen(selection);
+}
 
 int CCallback::howManyTowns()
 {
@@ -378,15 +384,23 @@ int3 CScriptCallback::getPos(CGObjectInstance * ob)
 void CScriptCallback::changePrimSkill(int ID, int which, int val)
 {	
 	CGHeroInstance * hero = CGI->state->getHero(ID,0);
-	hero->primSkills[which]+=val;
-	for (int i=0; i<CGI->playerint.size(); i++)
+	if (which<PRIMARY_SKILLS)
 	{
-		if (CGI->playerint[i]->playerID == hero->getOwner())
+		hero->primSkills[which]+=val;
+		for (int i=0; i<CGI->playerint.size(); i++)
 		{
-			CGI->playerint[i]->heroPrimarySkillChanged(hero, which, val);
-			break;
+			if (CGI->playerint[i]->playerID == hero->getOwner())
+			{
+				CGI->playerint[i]->heroPrimarySkillChanged(hero, which, val);
+				break;
+			}
 		}
 	}
+	else if (which==4)
+	{
+		hero->exp+=val;
+		//TODO - powiadomic interfejsy, sprawdzic czy nie ma awansu itp
+	}
 }
 
 int CScriptCallback::getHeroOwner(int heroID)
@@ -413,6 +427,14 @@ void CScriptCallback::showInfoDialog(int player, std::string text, std::vector<S
 		}
 	}
 }
+
+void CScriptCallback::showSelDialog(int player, std::string text, std::vector<SComponent*>*components, IChosen * asker)
+{
+	CGameInterface * temp = CGI->playerint[CGI->state->players[player].serial];
+	if (temp->human)
+		((CPlayerInterface*)(temp))->showSelDialog(text,*components,(int)asker);
+	return;
+}
 int CScriptCallback::getSelectedHero()
 {	
 	int ret;

+ 3 - 0
CCallback.h

@@ -9,6 +9,7 @@ class CTownInstance;
 class CPath;
 class CGObjectInstance;
 class SComponent;
+class IChosen;
 typedef struct lua_State lua_State;
 
 class ICallback
@@ -59,6 +60,7 @@ public:
 //commands
 	bool moveHero(int ID, CPath * path, int idtype, int pathType=0);//idtype: 0 - position in vector of heroes (of that player); 1 - ID of hero 
 															//pathType: 0 - nodes are manifestation pos, 1 - nodes are object pos
+	void selectionMade(int selection, int asker);
 
 //get info
 	bool verifyPath(CPath * path, bool blockSea);
@@ -93,6 +95,7 @@ public:
 	//do sth
 	static void changePrimSkill(int ID, int which, int val);
 	void showInfoDialog(int player, std::string text, std::vector<SComponent*> * components);
+	void showSelDialog(int player, std::string text, std::vector<SComponent*>*components, IChosen * asker);
 	void giveResource(int player, int which, int val);
 	void showCompInfo(int player, SComponent * comp);
 

+ 1 - 0
CGameInterface.h

@@ -24,6 +24,7 @@ public:
 	virtual void tileRevealed(int3 pos)=0{};
 	virtual void tileHidden(int3 pos)=0{};
 	virtual void receivedResource(int type, int val){};
+	virtual void showSelDialog(std::string text, std::vector<SComponent*> & components, int askID)=0{};
 };
 class CAIHandler
 {

+ 74 - 5
CLua.cpp

@@ -202,7 +202,7 @@ void CVisitableOPH::onHeroVisit(CGObjectInstance *os, int heroID)
 };
 void CVisitableOPH::onNAHeroVisit(CGObjectInstance *os, int heroID, bool alreadyVisited)
 {
-	int w=0, ot=0;
+	int w=0, ot=0, vvv=1;
 	switch(os->ID)
 	{
 	case 51:
@@ -221,6 +221,11 @@ void CVisitableOPH::onNAHeroVisit(CGObjectInstance *os, int heroID, bool already
 		w=3;
 		ot=59;
 		break;
+	case 100:
+		w=4;
+		ot=143;
+		vvv=1000;
+		break;
 	}
 	if (!alreadyVisited)
 	{
@@ -231,10 +236,20 @@ void CVisitableOPH::onNAHeroVisit(CGObjectInstance *os, int heroID, bool already
 		case 61:
 		case 32:
 			{
-				cb->changePrimSkill(heroID,w,1);
+				cb->changePrimSkill(heroID,w,vvv);
+				std::vector<SComponent*> weko;
+				weko.push_back(new SComponent(SComponent::primskill,w,vvv)); 
+				cb->showInfoDialog(cb->getHeroOwner(heroID),CGI->objh->advobtxt[ot],&weko); 
+				//for (int ii=0; ii<weko.size();ii++)
+				//	delete weko[ii];
+				break;
+			}
+		case 100:
+			{
+				cb->changePrimSkill(heroID,w,vvv);
 				std::vector<SComponent*> weko;
-				weko.push_back(new SComponent(SComponent::primskill,w,1)); 
-				cb->showInfoDialog(cb->getHeroOwner(heroID),CGI->objh->advobtxt[ot],&weko); //TODO: maybe we have memory leak with these windows
+				weko.push_back(new SComponent(SComponent::experience,0,vvv)); 
+				cb->showInfoDialog(cb->getHeroOwner(heroID),CGI->objh->advobtxt[ot],&weko); 
 				//for (int ii=0; ii<weko.size();ii++)
 				//	delete weko[ii];
 				break;
@@ -250,11 +265,12 @@ void CVisitableOPH::onNAHeroVisit(CGObjectInstance *os, int heroID, bool already
 
 std::vector<int> CVisitableOPH::yourObjects()
 {
-	std::vector<int> ret(4);
+	std::vector<int> ret(5);
 	ret.push_back(51);
 	ret.push_back(23);
 	ret.push_back(61);
 	ret.push_back(32);
+	ret.push_back(100);
 	return ret;
 }
 
@@ -276,6 +292,9 @@ std::string CVisitableOPH::hoverText(CGObjectInstance *os)
 	case 32:
 		pom = 4; 
 		break;
+	case 100:
+		pom = 5; 
+		break;
 	default:
 		throw new std::exception("Unsupported ID in CVisitableOPH::hoverText");
 	}
@@ -479,9 +498,59 @@ void CPickable::onHeroVisit(CGObjectInstance *os, int heroID)
 			cb->showCompInfo(cb->getHeroOwner(heroID),&ccc);
 			break;
 		}
+	case 101:
+		{
+			if (os->subID)
+				break; //not OH3 treasure chest
+			int wyn = rand()%100;
+			if (wyn<32)
+			{
+				tempStore.push_back(new SComponent(SComponent::resource,6,1000));
+				tempStore.push_back(new SComponent(SComponent::experience,0,500));
+			}//1k/0.5k
+			else if(wyn<64)
+			{
+				tempStore.push_back(new SComponent(SComponent::resource,6,1500));
+				tempStore.push_back(new SComponent(SComponent::experience,0,1000));
+			}//1.5k/1k
+			else if(wyn<95)
+			{
+				tempStore.push_back(new SComponent(SComponent::resource,6,2000));
+				tempStore.push_back(new SComponent(SComponent::experience,0,1500));
+			}//2k/1.5k
+			else
+			{
+				if (1/*TODO: backpack is full*/)
+				{
+					tempStore.push_back(new SComponent(SComponent::resource,6,1000));
+					tempStore.push_back(new SComponent(SComponent::experience,0,500));
+				}
+				else
+				{
+					//TODO: give treasure artifact
+					break;
+				}
+			}//random treasure artifact, or (if backapack is full) 1k/0.5k
+			player = cb->getHeroOwner(heroID);
+			cb->showSelDialog(player,"Wybierz prosze co chcesz dostac :)",&tempStore,this);
+			break;
+		}
 	}
 	CGI->mh->removeObject(os);
 }
+void CPickable::chosen(int which)
+{
+	switch(tempStore[which]->type)
+	{
+	case SComponent::resource:
+		cb->giveResource(player,tempStore[which]->subtype,tempStore[which]->val);
+		break;
+	default:
+		throw new std::exception("Unhandled choice");
+		
+	}
+}
+
 std::string CPickable::hoverText(CGObjectInstance *os)
 {
 	switch (os->ID)

+ 11 - 3
CLua.h

@@ -8,6 +8,7 @@ class CGObjectInstance;
 class CGameInfo;
 class CGHeroInstance;
 class CScriptCallback;
+class SComponent;
 enum ESLan{UNDEF=-1,CPP,ERM,LUA};
 class CObjectScript
 {
@@ -43,7 +44,11 @@ public:
 	CScript();
 	virtual ~CScript();
 };
-
+class IChosen
+{
+public:
+	virtual void chosen(int which)=0;
+};
 class CLua :public CScript
 {
 protected:
@@ -130,10 +135,13 @@ class CMines : public CCPPObjectScript  //flaggable, and giving resource at each
 	friend void initGameState(CGameInfo * cgi);
 };
 
-class CPickable : public CCPPObjectScript  //pickable - resources, artifacts, etc
+class CPickable : public CCPPObjectScript, public IChosen  //pickable - resources, artifacts, etc
 {
-	CPickable(CScriptCallback * CB):CCPPObjectScript(CB){};
+	std::vector<SComponent*> tempStore;
+	int player;
 
+	CPickable(CScriptCallback * CB):CCPPObjectScript(CB){};
+	void chosen(int which);
 	void newObject(CGObjectInstance *os);
 	void onHeroVisit(CGObjectInstance *os, int heroID);
 	std::string hoverText(CGObjectInstance *os);

+ 20 - 9
CPlayerInterface.cpp

@@ -47,11 +47,11 @@ void CInfoWindow::close()
 	}
 	components.clear();
 	okb.deactivate();
-	//SDL_FreeSurface(bitmap);
-	//bitmap = NULL;
+	SDL_FreeSurface(bitmap);
+	bitmap = NULL;
 	LOCPLINT->removeObjToBlit(this);
+	//delete this;
 	LOCPLINT->adventureInt->show();
-	delete this;
 }
 CInfoWindow::~CInfoWindow()
 {
@@ -68,10 +68,14 @@ SComponent::SComponent(Etype Type, int Subtype, int Val)
 		break;
 	case resource:
 		description = CGI->generaltexth->allTexts[242];
-		std::ostringstream oss;
 		oss << Val;
 		subtitle = oss.str();
 		break;
+	case experience:
+		description = CGI->generaltexth->allTexts[241];
+		oss << Val ;
+		subtitle = oss.str();
+		break;
 	}
 	type = Type;
 	subtype = Subtype;
@@ -91,6 +95,9 @@ SDL_Surface * SComponent::getImg()
 	case resource:
 		return CGI->heroh->resources->ourImages[subtype].bitmap;
 		break;
+	case experience:
+		return CGI->heroh->pskillsb->ourImages[4].bitmap;
+		break;
 	}
 	return NULL;
 }
@@ -113,10 +120,10 @@ void CSelectableComponent::clickLeft(tribool down)
 	if (down)
 	{
 		select(true);
-
+		owner->selectionChange(this);
 	}
 }
-CSelectableComponent::CSelectableComponent(Etype Type, int Sub, int Val, CSelWindow * Owner=NULL, SDL_Surface * Border)
+CSelectableComponent::CSelectableComponent(Etype Type, int Sub, int Val, CSelWindow * Owner, SDL_Surface * Border)
 :SComponent(Type,Sub,Val),owner(Owner)
 {
 	if (Border) //use custom border
@@ -236,9 +243,9 @@ template <typename T> void CSCButton<T>::clickLeft (tribool down)
 		state=0;
 	}
 	show();
-	pressedL=state;
 	if (delg)
 		(delg->*func)(down);
+	pressedL=state;
 }
 template <typename T> void CSCButton<typename T>::activate()
 {
@@ -1142,7 +1149,7 @@ SDL_Surface * CPlayerInterface::drawPrimarySkill(const CGHeroInstance *curh, SDL
 		itoa(curh->primSkills[i],buf,10);
 		printAtMiddle(buf,84+28*i,68,GEOR13,zwykly,ret);
 	}
-	delete[] buf;
+	delete buf;
 	return ret;
 }
 SDL_Surface * CPlayerInterface::drawHeroInfoWin(const CGHeroInstance * curh)
@@ -1162,7 +1169,7 @@ SDL_Surface * CPlayerInterface::drawHeroInfoWin(const CGHeroInstance * curh)
 	blitAt(curh->type->portraitLarge,11,12,ret);
 	itoa(curh->mana,buf,10);
 	printAtMiddle(buf,166,109,GEORM,zwykly,ret); //mana points
-	delete[] buf;
+	delete buf;
 	blitAt(morale22->ourImages[curh->getCurrentMorale()+3].bitmap,14,84,ret);
 	blitAt(luck22->ourImages[curh->getCurrentLuck()+3].bitmap,14,101,ret);
 	//SDL_SaveBMP(ret,"inf1.bmp");
@@ -1448,6 +1455,10 @@ void CPlayerInterface::receivedResource(int type, int val)
 	adventureInt->resdatabar.draw();
 }
 
+void CPlayerInterface::showSelDialog(std::string text, std::vector<SComponent*> & components, int askID)
+{
+}
+
 void CPlayerInterface::showComp(SComponent comp)
 {
 	adventureInt->infoBar.showComp(&comp,4000);

+ 4 - 2
CPlayerInterface.h

@@ -131,6 +131,7 @@ public:
 };
 class CSelWindow : public CInfoWindow //component selection window
 {
+public:
 	void selectionChange(SComponent * to);
 	void okClicked(tribool down);
 	void close();
@@ -140,7 +141,7 @@ class SComponent : public ClickableR
 public:
 	enum Etype
 	{
-		primskill, secskill, resource, creature, artifact
+		primskill, secskill, resource, creature, artifact, experience
 	} type;
 	int subtype; 
 	int val;
@@ -166,7 +167,7 @@ public:
 
 
 	void clickLeft(tribool down);
-	CSelectableComponent(Etype Type, int Sub, int Val, CSelWindow * Owner, SDL_Surface * Border=NULL);
+	CSelectableComponent(Etype Type, int Sub, int Val, CSelWindow * Owner=NULL, SDL_Surface * Border=NULL);
 	void activate();
 	void deactivate();
 	void select(bool on);
@@ -208,6 +209,7 @@ public:
 	void heroCreated(const CGHeroInstance* hero);
 	void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val);
 	void receivedResource(int type, int val);
+	void showSelDialog(std::string text, std::vector<SComponent*> & components, int askID);
 
 	void showComp(SComponent comp);