瀏覽代碼

* resource bar
* function in CCallback for getting onfo about res
* giving resources at the beginning of game
* moved several txt files to /config subfolder
* minor changes

Michał W. Urbańczyk 18 年之前
父節點
當前提交
7d4aa0c803
共有 17 個文件被更改,包括 119 次插入8 次删除
  1. 47 2
      CAdvmapInterface.cpp
  2. 16 0
      CAdvmapInterface.h
  3. 4 0
      CCallback.cpp
  4. 1 0
      CCallback.h
  5. 26 1
      CMT.cpp
  6. 二進制
      CPreGame.cpp
  7. 1 1
      CPreGame.h
  8. 1 0
      StartInfo.h
  9. 0 0
      config/CREDEFS.TXT
  10. 0 0
      config/minimap.txt
  11. 0 0
      config/portrety.txt
  12. 8 0
      config/startres.txt
  13. 3 0
      global.h
  14. 1 1
      hch/CCreatureHandler.cpp
  15. 1 1
      hch/CHeroHandler.cpp
  16. 8 1
      hch/CTownHandler.cpp
  17. 2 1
      hch/CTownHandler.h

+ 47 - 2
CAdvmapInterface.cpp

@@ -385,7 +385,7 @@ CMinimap::CMinimap(bool draw)
 	pos.y=26;
 	pos.h=pos.w=144;
 	radar = CGI->spriteh->giveDef("RADAR.DEF");
-	std::ifstream is("minimap.txt",std::ifstream::in);
+	std::ifstream is("config/minimap.txt",std::ifstream::in);
 	for (int i=0;i<TERRAIN_TYPES;i++)
 	{
 		std::pair<int,SDL_Color> vinya;
@@ -451,7 +451,10 @@ void CMinimap::clickLeft (tribool down)
 	if (down && (!pressedL))
 		MotionInterested::activate();
 	else if (!down)
-		MotionInterested::deactivate();
+	{
+		if (std::find(LOCPLINT->motioninterested.begin(),LOCPLINT->motioninterested.end(),this)!=LOCPLINT->motioninterested.end())
+			MotionInterested::deactivate();
+	}
 	ClickableL::clickLeft(down);
 	if (!((bool)down))
 		return;
@@ -734,6 +737,46 @@ void CTerrainRect::show()
 	} // if (currentPath)
 }
 
+
+void CResDataBar::clickRight (tribool down)
+{
+}
+void CResDataBar::activate()
+{
+	ClickableR::activate();
+}
+void CResDataBar::deactivate()
+{
+	ClickableR::deactivate();
+}
+CResDataBar::CResDataBar()
+{
+	bg = CGI->bitmaph->loadBitmap("ZRESBAR.bmp");
+	SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255));
+	blueToPlayersAdv(bg,LOCPLINT->playerID);
+	pos = genRect(bg->h,bg->w,3,575);
+
+	txtpos  +=  (std::pair<int,int>(35,577)),(std::pair<int,int>(120,577)),(std::pair<int,int>(205,577)),
+		(std::pair<int,int>(290,577)),(std::pair<int,int>(375,577)),(std::pair<int,int>(460,577)),(std::pair<int,int>(545,577));
+
+}
+CResDataBar::~CResDataBar()
+{
+	SDL_FreeSurface(bg);
+}
+void CResDataBar::draw()
+{
+	blitAt(bg,pos.x,pos.y);
+	char * buf = new char[15];
+	for (int i=0;i<7;i++)
+	{
+		itoa(LOCPLINT->cb->getResourceAmount(i),buf,10);
+		printAt(buf,txtpos[i].first,txtpos[i].second,GEOR13,zwykly);
+	}
+	delete buf;
+	updateRect(&pos,ekran);
+}
+
 CAdvMapInt::CAdvMapInt(int Player)
 :player(Player),
 statusbar(7,556),
@@ -864,6 +907,8 @@ void CAdvMapInt::show()
 	heroList.activate();
 	heroList.draw();
 
+	resdatabar.draw();
+
 	statusbar.show();
 
 	SDL_Flip(ekran);

+ 16 - 0
CAdvmapInterface.h

@@ -159,6 +159,21 @@ public:
 	void keyPressed (SDL_KeyboardEvent & key);
 	void show();
 };
+class CResDataBar
+	:public ClickableR, public virtual CIntObject
+{
+public:
+	SDL_Surface * bg;
+	std::vector<std::pair<int,int> > txtpos;
+
+	void clickRight (tribool down);
+	void activate(); 
+	void deactivate();
+	CResDataBar();
+	~CResDataBar();
+
+	void draw();
+};
 /*****************************/
 class CAdvMapInt //adventure map interface
 {
@@ -198,6 +213,7 @@ public:
 	CTerrainRect terrain; //visible terrain
 
 	CStatusBar statusbar;
+	CResDataBar resdatabar;
 	
 	CHeroList heroList;
 	CTownList townList;

+ 4 - 0
CCallback.cpp

@@ -72,4 +72,8 @@ const CHeroInstance * CCallback::getHeroInfo(int player, int val, bool mode) //m
 		}
 	}
 	return NULL;
+}
+int CCallback::getResourceAmount(int type)
+{
+	return gs->players[gs->currentPlayer].resources[type];
 }

+ 1 - 0
CCallback.h

@@ -22,6 +22,7 @@ public:
 
 	int howManyHeroes(int player);
 	const CHeroInstance * getHeroInfo(int player, int val, bool mode); //mode = 0 -> val = serial; mode = 1 -> val = ID
+	int getResourceAmount(int type);
 };
 
 #endif //CCALLBACK_H

+ 26 - 1
CMT.cpp

@@ -85,7 +85,32 @@ TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM;
 
 void initGameState(CGameInfo * cgi)
 {
-	cgi->state->currentPlayer = 0;
+	/******************RESOURCES****************************************************/
+	//TODO: zeby komputer dostawal inaczej niz gracz
+	std::vector<int> startres;
+	std::ifstream tis("config/startres.txt");
+	int k;
+	for (int j=0;j<cgi->scenarioOps.difficulty;j++)
+	{
+		tis >> k;
+		for (int z=0;z<RESOURCE_QUANTITY;z++)
+			tis>>k;
+	}
+	tis >> k;
+	for (int i=0;i<RESOURCE_QUANTITY;i++)
+	{
+		tis >> k;
+		startres.push_back(k);
+	}
+	tis.close();
+	for (std::map<int,PlayerState>::iterator i = cgi->state->players.begin(); i!=cgi->state->players.end(); i++)
+	{
+		(*i).second.resources.resize(RESOURCE_QUANTITY);
+		for (int x=0;x<RESOURCE_QUANTITY;x++)
+			(*i).second.resources[x] = startres[x];
+
+	}
+
 	/*************************HEROES************************************************/
 	for (int i=0; i<cgi->heroh->heroInstances.size();i++) //heroes instances
 	{

二進制
CPreGame.cpp


+ 1 - 1
CPreGame.h

@@ -258,7 +258,7 @@ public:
 	menuItems * currentItems();
 	void(CPreGame::*handleOther)(SDL_Event&);
 	void scenHandleEv(SDL_Event& sEvent);
-	void begin(){run=false;};
+	void begin(){run=false;ret.difficulty=ourScenSel->selectedDiff;};
 	void quitAskBox();
 	void quit(){exit(0);};  
 	void initScenSel(); 

+ 1 - 0
StartInfo.h

@@ -18,6 +18,7 @@ struct StartInfo
 		int handicap;//0-no, 1-mild, 2-severe
 		std::string name;
 	};
+	int difficulty; //0=easy; 4=impossible
 	std::vector<PlayerSettings> playerInfos;
 	int turnTime; //in minutes, 0=unlimited
 	PlayerSettings & getIthPlayersSettings(int no)

+ 0 - 0
CREDEFS.TXT → config/CREDEFS.TXT


+ 0 - 0
minimap.txt → config/minimap.txt


+ 0 - 0
portrety.txt → config/portrety.txt


+ 8 - 0
config/startres.txt

@@ -0,0 +1,8 @@
+0	30	15	30	15	15	15	30000	0
+1	20	10	20	10	10	10	20000	0
+2	15	7	15	7	7	7	15000	0
+3	10	4	10	4	4	4	10000	0
+4	0	0	0	0	0	0	0	0
+
+Resources on start. Format:
+Difficulty	wood	mercury	ore	sulfur	crystal	gems	gold	mithril

+ 3 - 0
global.h

@@ -37,9 +37,12 @@ const int HEROES_PER_TYPE=8; //amount of heroes of each type
 const int SKILL_QUANTITY=28;
 const int ARTIFACTS_QUANTITY=171;
 const int HEROES_QUANTITY=156;
+const int RESOURCE_QUANTITY=8;
 const int TERRAIN_TYPES=10;
 const int PRIMARY_SKILLS=4;
 
+const int NAMES_PER_TOWN=16;
+
 #define MARK_BLOCKED_POSITIONS false
 #define MARK_VISITABLE_POSITIONS false
 

+ 1 - 1
hch/CCreatureHandler.cpp

@@ -447,7 +447,7 @@ void CCreatureHandler::loadUnitAnimInfo(CCreature & unit, std::string & src, int
 
 void CCreatureHandler::loadUnitAnimations()
 {
-	std::ifstream inp("CREDEFS.TXT", std::ios::in | std::ios::binary); //this file is not in lod
+	std::ifstream inp("config/CREDEFS.TXT", std::ios::in | std::ios::binary); //this file is not in lod
 	inp.seekg(0,std::ios::end); // na koniec
 	int andame = inp.tellg();  // read length
 	inp.seekg(0,std::ios::beg); // wracamy na poczatek

+ 1 - 1
hch/CHeroHandler.cpp

@@ -21,7 +21,7 @@ CHeroHandler::~CHeroHandler()
 }
 void CHeroHandler::loadPortraits()
 {
-	std::ifstream of("portrety.txt");
+	std::ifstream of("config/portrety.txt");
 	for (int j=0;j<heroes.size();j++)
 	{
 		int ID;

+ 8 - 1
hch/CTownHandler.cpp

@@ -14,12 +14,19 @@ CTownHandler::~CTownHandler()
 }
 void CTownHandler::loadNames()
 {
-	std::istringstream ins;
+	std::istringstream ins, names;
 	ins.str(CGI->bitmaph->getTextFile("TOWNTYPE.TXT"));
+	names.str(CGI->bitmaph->getTextFile("TOWNNAME.TXT"));
 	while (!ins.eof())
 	{
 		CTown town;
 		ins >> town.name;
+		char bufname[50];
+		for (int i=0; i<NAMES_PER_TOWN; i++)
+		{
+			names.getline(bufname,50);
+			town.names.push_back(std::string(bufname));
+		}
 		town.bonus=towns.size();
 		if (town.bonus==8) town.bonus=3; 
 		if (town.name.length())

+ 2 - 1
hch/CTownHandler.h

@@ -15,7 +15,8 @@ class CHero;
 class CTown
 {
 public:
-	std::string name;
+	std::string name; //name of type
+	std::vector<std::string> names; //names of the town instances
 	int bonus; //pic number
 };