mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	* new files: CGameState.h and int3.h
* creature set now uses std::set * int3 class - may be used for locations * fixes crashbug in cpregame (state in HughButton not initialized) * started making CTownInstance
This commit is contained in:
		| @@ -1836,96 +1836,76 @@ EDefType CAmbarCendamo::getDefType(DefInfo &a) | ||||
| CCreatureSet CAmbarCendamo::readCreatureSet(int pos, int number) | ||||
| { | ||||
| 	CCreatureSet ret; | ||||
| 	std::pair<CCreature *, int> ins; | ||||
| 	if(number>0 && readNormalNr(pos, 2)!=0xffff) | ||||
| 	{ | ||||
| 		int rettt = readNormalNr(pos, 2); | ||||
| 		if(rettt>32768) | ||||
| 			rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16; | ||||
| 		ret.slot1 = &(CGameInfo::mainObj->creh->creatures[rettt]); | ||||
| 		ret.s1 = readNormalNr(pos+2, 2); | ||||
| 	} | ||||
| 	else | ||||
| 	{ | ||||
| 		ret.slot1 = NULL; | ||||
| 		ret.s1 = 0; | ||||
| 		ins.first = &(CGameInfo::mainObj->creh->creatures[rettt]); | ||||
| 		ins.second = readNormalNr(pos+2, 2); | ||||
| 		std::pair<int,std::pair<CCreature *, int> > tt(0,ins); | ||||
| 		ret.slots.insert(tt); | ||||
| 	} | ||||
| 	if(number>1 && readNormalNr(pos+4, 2)!=0xffff) | ||||
| 	{ | ||||
| 		int rettt = readNormalNr(pos+4, 2); | ||||
| 		if(rettt>32768) | ||||
| 			rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16; | ||||
| 		ret.slot2 = &(CGameInfo::mainObj->creh->creatures[rettt]); | ||||
| 		ret.s2 = readNormalNr(pos+6, 2); | ||||
| 	} | ||||
| 	else | ||||
| 	{ | ||||
| 		ret.slot2 = NULL; | ||||
| 		ret.s2 = 0; | ||||
| 		ins.first  = &(CGameInfo::mainObj->creh->creatures[rettt]); | ||||
| 		ins.second = readNormalNr(pos+6, 2); | ||||
| 		std::pair<int,std::pair<CCreature *, int> > tt(1,ins); | ||||
| 		ret.slots.insert(tt); | ||||
| 	} | ||||
| 	if(number>2 && readNormalNr(pos+8, 2)!=0xffff) | ||||
| 	{ | ||||
| 		int rettt = readNormalNr(pos+8, 2); | ||||
| 		if(rettt>32768) | ||||
| 			rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16; | ||||
| 		ret.slot3 = &(CGameInfo::mainObj->creh->creatures[rettt]); | ||||
| 		ret.s3 = readNormalNr(pos+10, 2); | ||||
| 	} | ||||
| 	else | ||||
| 	{ | ||||
| 		ret.slot3 = NULL; | ||||
| 		ret.s3 = 0; | ||||
| 		ins.first  = &(CGameInfo::mainObj->creh->creatures[rettt]); | ||||
| 		ins.second = readNormalNr(pos+10, 2); | ||||
| 		std::pair<int,std::pair<CCreature *, int> > tt(2,ins); | ||||
| 		ret.slots.insert(tt); | ||||
| 	} | ||||
| 	if(number>3 && readNormalNr(pos+12, 2)!=0xffff) | ||||
| 	{ | ||||
| 		int rettt = readNormalNr(pos+12, 2); | ||||
| 		if(rettt>32768) | ||||
| 			rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16; | ||||
| 		ret.slot4 = &(CGameInfo::mainObj->creh->creatures[rettt]); | ||||
| 		ret.s4 = readNormalNr(pos+14, 2); | ||||
| 	} | ||||
| 	else | ||||
| 	{ | ||||
| 		ret.slot4 = NULL; | ||||
| 		ret.s4 = 0; | ||||
| 		ins.first  = &(CGameInfo::mainObj->creh->creatures[rettt]); | ||||
| 		ins.second = readNormalNr(pos+14, 2); | ||||
| 		std::pair<int,std::pair<CCreature *, int> > tt(3,ins); | ||||
| 		ret.slots.insert(tt); | ||||
| 	} | ||||
| 	if(number>4 && readNormalNr(pos+16, 2)!=0xffff) | ||||
| 	{ | ||||
| 		int rettt = readNormalNr(pos+16, 2); | ||||
| 		if(rettt>32768) | ||||
| 			rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16; | ||||
| 		ret.slot5 = &(CGameInfo::mainObj->creh->creatures[rettt]); | ||||
| 		ret.s5 = readNormalNr(pos+18, 2); | ||||
| 	} | ||||
| 	else | ||||
| 	{ | ||||
| 		ret.slot5 = NULL; | ||||
| 		ret.s5 = 0; | ||||
| 		ins.first  = &(CGameInfo::mainObj->creh->creatures[rettt]); | ||||
| 		ins.second = readNormalNr(pos+18, 2); | ||||
| 		std::pair<int,std::pair<CCreature *, int> > tt(4,ins); | ||||
| 		ret.slots.insert(tt); | ||||
| 	} | ||||
| 	if(number>5 && readNormalNr(pos+20, 2)!=0xffff) | ||||
| 	{ | ||||
| 		int rettt = readNormalNr(pos+20, 2); | ||||
| 		if(rettt>32768) | ||||
| 			rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16; | ||||
| 		ret.slot6 = &(CGameInfo::mainObj->creh->creatures[rettt]); | ||||
| 		ret.s6 = readNormalNr(pos+22, 2); | ||||
| 	} | ||||
| 	else | ||||
| 	{ | ||||
| 		ret.slot6 = NULL; | ||||
| 		ret.s6 = 0; | ||||
| 		ins.first  = &(CGameInfo::mainObj->creh->creatures[rettt]); | ||||
| 		ins.second = readNormalNr(pos+22, 2); | ||||
| 		std::pair<int,std::pair<CCreature *, int> > tt(5,ins); | ||||
| 		ret.slots.insert(tt); | ||||
| 	} | ||||
| 	if(number>6 && readNormalNr(pos+24, 2)!=0xffff) | ||||
| 	{ | ||||
| 		int rettt = readNormalNr(pos+24, 2); | ||||
| 		if(rettt>32768) | ||||
| 			rettt = 65536-rettt+CGameInfo::mainObj->creh->creatures.size()-16; | ||||
| 		ret.slot7 = &(CGameInfo::mainObj->creh->creatures[rettt]); | ||||
| 		ret.s7 = readNormalNr(pos+26, 2); | ||||
| 	} | ||||
| 	else | ||||
| 	{ | ||||
| 		ret.slot7 = NULL; | ||||
| 		ret.s7 = 0; | ||||
| 		ins.first  = &(CGameInfo::mainObj->creh->creatures[rettt]); | ||||
| 		ins.second = readNormalNr(pos+26, 2); | ||||
| 		std::pair<int,std::pair<CCreature *, int> > tt(6,ins); | ||||
| 		ret.slots.insert(tt); | ||||
| 	} | ||||
| 	return ret; | ||||
| } | ||||
|   | ||||
| @@ -3,6 +3,7 @@ | ||||
|  | ||||
| #include <string> | ||||
| #include <vector> | ||||
| #include <map> | ||||
| #include "CDefHandler.h" | ||||
|  | ||||
| class CCreature | ||||
| @@ -34,8 +35,9 @@ public: | ||||
| class CCreatureSet //seven combined creatures | ||||
| { | ||||
| public: | ||||
| 	CCreature * slot1, * slot2, * slot3, * slot4, * slot5, * slot6, * slot7; //types of creatures on each slot | ||||
| 	unsigned int s1, s2, s3, s4, s5, s6, s7; //amounts of units in slots | ||||
| 	std::map<int,std::pair<CCreature*,int> > slots; | ||||
| 	//CCreature * slot1, * slot2, * slot3, * slot4, * slot5, * slot6, * slot7; //types of creatures on each slot | ||||
| 	//unsigned int s1, s2, s3, s4, s5, s6, s7; //amounts of units in slots | ||||
| 	bool formation; //false - wide, true - tight | ||||
| }; | ||||
|  | ||||
|   | ||||
							
								
								
									
										32
									
								
								CGameState.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								CGameState.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,32 @@ | ||||
| #ifndef CGAMESTATE_H | ||||
| #define CGAMESTATE_H | ||||
|  | ||||
| #include "CSpellHandler.h" | ||||
| #include "CAbilityHandler.h" | ||||
| #include "CCreaturehandler.h" | ||||
| #include "CArtHandler.h" | ||||
| #include "CHeroHandler.h" | ||||
| #include "CAmbarCendamo.h" | ||||
| #include "CBuildingHandler.h" | ||||
| #include "CObjectHandler.h" | ||||
| #include "CMusicHandler.h" | ||||
| #include "CSemiLodHandler.h" | ||||
| #include "CDefObjInfoHandler.h" | ||||
| #include "CLodHandler.h" | ||||
| #include "CTownHandler.h" | ||||
|  | ||||
| struct PlayerState | ||||
| { | ||||
| 	int color; | ||||
| 	vector<vector<bool> > fogOfWarMap; | ||||
| 	std::vector<int> resources; | ||||
| 	std::vector<CHeroInstance> heroes; | ||||
| 	std::vector<CTownInstance> heroes; | ||||
| } | ||||
|  | ||||
| class CGameState | ||||
| { | ||||
|  | ||||
| } | ||||
|  | ||||
| #endif //CGAMESTATE_H | ||||
| @@ -5,6 +5,7 @@ | ||||
| #include <vector> | ||||
| #include "CCreatureHandler.h" | ||||
| #include "SDL.h" | ||||
| #include "int3.h" | ||||
|  | ||||
| class CHeroClass; | ||||
|  | ||||
| @@ -44,7 +45,7 @@ class CHeroInstance | ||||
| { | ||||
| public: | ||||
| 	CHero type; | ||||
| 	int x, y, z; //position | ||||
| 	int3 pos; | ||||
| 	CCreatureSet army; //army | ||||
| 	//TODO: armia, artefakty, itd. | ||||
| }; | ||||
|   | ||||
| @@ -25,7 +25,7 @@ struct HighButton | ||||
| 	int state; | ||||
| 	HighButton( SDL_Rect Pos, CDefHandler* Imgs, bool Sel=false, int id=-1) | ||||
| 		{type=0;imgs=Imgs;selectable=Sel;selected=false;state=0;pos=Pos;ID=id;highlightable=false;}; | ||||
| 	HighButton(){} | ||||
| 	HighButton(){state=0;} | ||||
| 	bool selectable, selected; | ||||
| 	bool highlightable, highlighted; | ||||
| 	virtual void show(); | ||||
|   | ||||
| @@ -20,5 +20,10 @@ public: | ||||
| 	void loadNames(); | ||||
| 	SDL_Surface * getPic(int ID, bool fort=true, bool builded=false); //ID=-1 - blank; -2 - border; -3 - random | ||||
| }; | ||||
| class CTownInstance | ||||
| { | ||||
| 	int type; | ||||
| 	std::string name; | ||||
|  | ||||
| }; | ||||
| #endif //CTOWNHANDLER_H | ||||
							
								
								
									
										2
									
								
								global.h
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								global.h
									
									
									
									
									
								
							| @@ -21,5 +21,7 @@ const int F_NUMBER = 9; //factions quantity | ||||
| const int PLAYER_LIMIT = 8; //player limit per map | ||||
| const int HEROES_PER_TYPE=8; //amount of heroes of each type | ||||
|  | ||||
|  | ||||
|  | ||||
| #define DEFBYPASS | ||||
| #endif //GLOBAL_H | ||||
							
								
								
									
										61
									
								
								int3.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										61
									
								
								int3.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,61 @@ | ||||
| class int3 | ||||
| { | ||||
| 	int x,y,z; | ||||
| 	inline int3():x(0),y(0),z(0){}; //c-tor, x/y/z initialized to 0 | ||||
| 	inline int3(const int X, const int Y, const int Z):x(X),y(Y),z(Z){}; //c-tor | ||||
| 	inline ~int3(){} // d-tor - does nothing | ||||
| 	inline int3 operator+(const int3 & i) | ||||
| 		{return int3(x+i.x,y+i.y,z+i.z);} | ||||
| 	inline int3 operator+(const int i) //increases all components by int | ||||
| 		{return int3(x+i,y+i,z+i);} | ||||
| 	inline int3 operator-(const int3 & i) | ||||
| 		{return int3(x-i.x,y-i.y,z-i.z);} | ||||
| 	inline int3 operator-(const int i) | ||||
| 		{return int3(x-i,y-i,z-i);} | ||||
| 	inline int3 operator-() //increases all components by int | ||||
| 		{return int3(-x,-y,-z);} | ||||
| 	inline void operator+=(const int3 & i) | ||||
| 	{ | ||||
| 		x+=i.x; | ||||
| 		y+=i.y; | ||||
| 		z+=i.z; | ||||
| 	}	 | ||||
| 	inline void operator+=(const int i) | ||||
| 	{ | ||||
| 		x+=i; | ||||
| 		y+=i; | ||||
| 		z+=i; | ||||
| 	} | ||||
| 	inline void operator-=(const int3 & i) | ||||
| 	{ | ||||
| 		x-=i.x; | ||||
| 		y-=i.y; | ||||
| 		z-=i.z; | ||||
| 	}	 | ||||
| 	inline void operator-=(const int i) | ||||
| 	{ | ||||
| 		x+=i; | ||||
| 		y+=i; | ||||
| 		z+=i; | ||||
| 	}	 | ||||
| 	inline bool operator==(const int3 & i) | ||||
| 		{return (x==i.x) && (y==i.y) && (z==i.z);}	 | ||||
| 	inline bool operator!=(const int3 & i) | ||||
| 		{return !(*this==i);} | ||||
| 	inline bool operator<(const int3 & i) | ||||
| 	{ | ||||
| 		if (z<i.z) | ||||
| 			return true; | ||||
| 		if (z>i.z) | ||||
| 			return false; | ||||
| 		if (y<i.y) | ||||
| 			return true; | ||||
| 		if (y>i.y) | ||||
| 			return false; | ||||
| 		if (x<i.x) | ||||
| 			return true; | ||||
| 		if (x>i.x) | ||||
| 			return false; | ||||
| 		return false; | ||||
| 	} | ||||
| }; | ||||
		Reference in New Issue
	
	Block a user