mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	* new spell: implosion
* optimizations in def handling * small refactoring
This commit is contained in:
		| @@ -1117,7 +1117,7 @@ bool CBattleInterface::isTileAttackable(const int & number) const | ||||
|  | ||||
| void CBattleInterface::hexLclicked(int whichOne) | ||||
| { | ||||
| 	if((whichOne%17)!=0 && (whichOne%17)!=16) //if player is trying to attack enemey unit or move creature stack | ||||
| 	if((whichOne%BFIELD_WIDTH)!=0 && (whichOne%BFIELD_WIDTH)!=(BFIELD_WIDTH-1)) //if player is trying to attack enemey unit or move creature stack | ||||
| 	{ | ||||
| 		if(!myTurn) | ||||
| 			return; //we are not permit to do anything | ||||
| @@ -1351,6 +1351,11 @@ void CBattleInterface::spellCasted(SpellCasted * sc) | ||||
| 			displayEffect(1, sc->tile); | ||||
| 			break; | ||||
| 		} | ||||
| 	case 18: //implosion | ||||
| 		{ | ||||
| 			displayEffect(10, sc->tile); | ||||
| 			break; | ||||
| 		} | ||||
| 	case 53: //haste | ||||
| 		{ | ||||
| 			displayEffect(31, sc->tile); | ||||
|   | ||||
| @@ -127,7 +127,7 @@ vector<Coordinate>* CPathfinder::CalcPath() | ||||
|  * Determines if the given node exists in the closed list, returns true if it does.  This is | ||||
|  * used to ensure you dont check the same node twice. | ||||
| */ | ||||
| bool CPathfinder::ExistsInClosed(Coordinate node) | ||||
| bool CPathfinder::ExistsInClosed(const Coordinate & node) const | ||||
| { | ||||
| 	for(int i = 0; i < Closed.size(); i++) | ||||
| 	{ | ||||
| @@ -386,11 +386,11 @@ void CPathfinder::convertPath(CPath * path, unsigned int mode) //mode=0 -> from | ||||
| 	} | ||||
| } | ||||
|  | ||||
| int3 CPath::startPos() | ||||
| int3 CPath::startPos() const | ||||
| { | ||||
| 	return int3(nodes[nodes.size()-1].coord.x,nodes[nodes.size()-1].coord.y,nodes[nodes.size()-1].coord.z); | ||||
| } | ||||
| int3 CPath::endPos() | ||||
| int3 CPath::endPos() const | ||||
| { | ||||
| 	return int3(nodes[0].coord.x,nodes[0].coord.y,nodes[0].coord.z); | ||||
| } | ||||
|   | ||||
| @@ -47,8 +47,8 @@ struct CPath | ||||
| { | ||||
| 	std::vector<CPathNode> nodes; //just get node by node | ||||
|  | ||||
| 	int3 startPos(); // start point | ||||
| 	int3 endPos(); //destination point | ||||
| 	int3 startPos() const; // start point | ||||
| 	int3 endPos() const; //destination point | ||||
| }; | ||||
|  | ||||
| class CPathfinder | ||||
| @@ -65,7 +65,7 @@ private: | ||||
|  	 * Determines if the given node exists in the closed list, returns true if it does.  This is | ||||
| 	 * used to ensure you dont check the same node twice. | ||||
| 	 */ | ||||
| 	bool ExistsInClosed(Coordinate node); | ||||
| 	bool ExistsInClosed(const Coordinate & node) const; | ||||
|  | ||||
| 	/* | ||||
| 	 * Adds the neighbors of the current node to the open cue so they can be considered in the | ||||
|   | ||||
| @@ -2362,17 +2362,17 @@ CHeroList::CHeroList(int Size) | ||||
| 	selection = BitmapHandler::loadBitmap("HPSYYY.bmp"); | ||||
| 	SDL_SetColorKey(selection,SDL_SRCCOLORKEY,SDL_MapRGB(selection->format,0,255,255)); | ||||
|  | ||||
| 	pos = genRect(32*SIZE+arrup->h+arrdo->h,std::max(arrup->w,arrdo->w),conf.go()->ac.hlistX,conf.go()->ac.hlistY); | ||||
| 	pos = genRect(32*SIZE+arrup->height+arrdo->height, std::max(arrup->width,arrdo->width), conf.go()->ac.hlistX, conf.go()->ac.hlistY); | ||||
|  | ||||
| 	arrupp = genRect(arrup->h,arrup->w,pos.x,pos.y); | ||||
| 	arrdop = genRect(arrdo->h,arrdo->w,pos.x,pos.y+32*SIZE+arrup->h); | ||||
| 	arrupp = genRect(arrup->height, arrup->width, pos.x, pos.y); | ||||
| 	arrdop = genRect(arrdo->height, arrdo->width, pos.x, pos.y+32*SIZE+arrup->height); | ||||
|  //32px per hero | ||||
| 	posmobx = pos.x+1; | ||||
| 	posmoby = pos.y+arrup->h+1; | ||||
| 	posporx = pos.x+mobile->w+2; | ||||
| 	pospory = pos.y+arrup->h; | ||||
| 	posmanx = pos.x+1+50+mobile->w; | ||||
| 	posmany = pos.y+arrup->h+1; | ||||
| 	posmoby = pos.y+arrup->height+1; | ||||
| 	posporx = pos.x+mobile->width+2; | ||||
| 	pospory = pos.y+arrup->height; | ||||
| 	posmanx = pos.x+1+50+mobile->width; | ||||
| 	posmany = pos.y+arrup->height+1; | ||||
|  | ||||
| 	from = 0; | ||||
| 	pressed = indeterminate; | ||||
| @@ -2633,16 +2633,16 @@ CTownList::CTownList(int Size, int x, int y, std::string arrupg, std::string arr | ||||
| 	arrdo = CDefHandler::giveDef(arrdog); | ||||
| 	pos.x = x; | ||||
| 	pos.y = y; | ||||
| 	pos.w = std::max(arrdo->w,arrup->h); | ||||
| 	pos.w = std::max(arrdo->width, arrup->height); | ||||
|  | ||||
| 	arrupp.x=x; | ||||
| 	arrupp.y=y; | ||||
| 	arrupp.w=arrup->w; | ||||
| 	arrupp.h=arrup->h; | ||||
| 	arrupp.w=arrup->width; | ||||
| 	arrupp.h=arrup->height; | ||||
| 	arrdop.x=x; | ||||
| 	arrdop.y=y+arrup->h+32*SIZE; | ||||
| 	arrdop.w=arrdo->w; | ||||
| 	arrdop.h=arrdo->h; | ||||
| 	arrdop.y=y+arrup->height+32*SIZE; | ||||
| 	arrdop.w=arrdo->width; | ||||
| 	arrdop.h=arrdo->height; | ||||
| 	posporx = arrdop.x; | ||||
| 	pospory = arrupp.y + arrupp.h; | ||||
|  | ||||
|   | ||||
| @@ -33,7 +33,7 @@ void CCreatureAnimation::setType(int type) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| CCreatureAnimation::CCreatureAnimation(std::string name) : RLEntries(NULL), RWEntries(NULL) | ||||
| CCreatureAnimation::CCreatureAnimation(std::string name) : RLEntries(NULL) | ||||
| { | ||||
| 	FDef = CDefHandler::Spriteh->giveFile(name); //load main file | ||||
|  | ||||
| @@ -98,7 +98,7 @@ CCreatureAnimation::CCreatureAnimation(std::string name) : RLEntries(NULL), RWEn | ||||
| 	RLEntries = new int[fullHeight]; | ||||
| } | ||||
|  | ||||
| int CCreatureAnimation::readNormalNr (int pos, int bytCon, unsigned char * str, bool cyclic) | ||||
| int CCreatureAnimation::readNormalNr (int pos, int bytCon, unsigned char * str) const | ||||
| { | ||||
| 	int ret=0; | ||||
| 	int amp=1; | ||||
| @@ -107,7 +107,7 @@ int CCreatureAnimation::readNormalNr (int pos, int bytCon, unsigned char * str, | ||||
| 		for (int i=0; i<bytCon; i++) | ||||
| 		{ | ||||
| 			ret+=str[pos+i]*amp; | ||||
| 			amp*=256; | ||||
| 			amp<<=8; //amp*=256; | ||||
| 		} | ||||
| 	} | ||||
| 	else  | ||||
| @@ -115,13 +115,9 @@ int CCreatureAnimation::readNormalNr (int pos, int bytCon, unsigned char * str, | ||||
| 		for (int i=0; i<bytCon; i++) | ||||
| 		{ | ||||
| 			ret+=FDef[pos+i]*amp; | ||||
| 			amp*=256; | ||||
| 			amp<<=8; //amp*=256; | ||||
| 		} | ||||
| 	} | ||||
| 	if(cyclic && bytCon<4 && ret>=amp/2) | ||||
| 	{ | ||||
| 		ret = ret-amp; | ||||
| 	} | ||||
| 	return ret; | ||||
| } | ||||
| int CCreatureAnimation::nextFrameMiddle(SDL_Surface *dest, int x, int y, bool attacker, bool incrementFrame, bool yellowBorder, SDL_Rect * destRect) | ||||
| @@ -198,15 +194,10 @@ int CCreatureAnimation::nextFrame(SDL_Surface *dest, int x, int y, bool attacker | ||||
| 	{ | ||||
| 		if (TopMargin>0) | ||||
| 		{ | ||||
| 			for (int i=0;i<TopMargin;i++) | ||||
| 			{ | ||||
| 				ftcp+=FullWidth; | ||||
| 			} | ||||
| 		} | ||||
| 		for (int i=0;i<SpriteHeight;i++) | ||||
| 		{ | ||||
| 			RLEntries[i]=readNormalNr(BaseOffset,4,FDef);BaseOffset+=4; | ||||
| 			ftcp+=FullWidth * TopMargin; | ||||
| 		} | ||||
| 		memcpy(RLEntries, FDef+BaseOffset, SpriteHeight*sizeof(int)); | ||||
| 		BaseOffset += sizeof(int) * SpriteHeight; | ||||
| 		for (int i=0;i<SpriteHeight;i++) | ||||
| 		{ | ||||
| 			BaseOffset=BaseOffsetor+RLEntries[i]; | ||||
| @@ -281,8 +272,6 @@ int CCreatureAnimation::framesInGroup(int group) const | ||||
| CCreatureAnimation::~CCreatureAnimation() | ||||
| { | ||||
| 	delete [] FDef; | ||||
| 	if (RWEntries) | ||||
| 		delete [] RWEntries; | ||||
| 	if (RLEntries) | ||||
| 		delete [] RLEntries; | ||||
| } | ||||
|   | ||||
| @@ -7,10 +7,8 @@ class CCreatureAnimation : public CIntObject | ||||
| { | ||||
| private: | ||||
| 	int totalEntries, DEFType, totalBlocks; | ||||
| 	bool allowRepaint; | ||||
| 	int length; | ||||
| 	BMPPalette palette[256]; | ||||
| 	unsigned int * RWEntries; | ||||
| 	int * RLEntries; | ||||
| 	struct SEntry | ||||
| 	{ | ||||
| @@ -19,10 +17,9 @@ private: | ||||
| 		int group; | ||||
| 	} ; | ||||
| 	std::vector<SEntry> SEntries ; | ||||
| 	char id[2]; | ||||
| 	std::string defName, curDir; | ||||
| 	int readNormalNr (int pos, int bytCon, unsigned char * str=NULL, bool cyclic=false); | ||||
| 	void putPixel(SDL_Surface * dest, const int & ftcp, const BMPPalette & color, const unsigned char & palc, const bool & yellowBorder) const; | ||||
| 	int readNormalNr (int pos, int bytCon, unsigned char * str=NULL) const; | ||||
| 	void inline putPixel(SDL_Surface * dest, const int & ftcp, const BMPPalette & color, const unsigned char & palc, const bool & yellowBorder) const; | ||||
|  | ||||
| 	//////////// | ||||
|  | ||||
|   | ||||
| @@ -9,7 +9,7 @@ | ||||
| 7 1 C04SPA0.DEF | ||||
| 8 1 C04SPE0.DEF | ||||
| 9 1 C04SPF0.DEF | ||||
| 10 0 | ||||
| 10 1 C05SPE0.DEF | ||||
| 11 1 C05SPF0.DEF | ||||
| 12 1 C06SPF0.DEF | ||||
| 13 1 C07SPA0.DEF | ||||
|   | ||||
| @@ -59,8 +59,8 @@ void CDefHandler::openDef(std::string name) | ||||
| 	delete is; | ||||
| 	i = 0; | ||||
| 	DEFType = readNormalNr(i,4,FDef); i+=4; | ||||
| 	w = readNormalNr(i,4,FDef); i+=4; | ||||
| 	h = readNormalNr(i,4,FDef); i+=4; | ||||
| 	width = readNormalNr(i,4,FDef); i+=4; | ||||
| 	height = readNormalNr(i,4,FDef); i+=4; | ||||
| 	i=0xc; | ||||
| 	totalBlocks = readNormalNr(i,4,FDef); i+=4; | ||||
|  | ||||
| @@ -123,8 +123,8 @@ void CDefHandler::openFromMemory(unsigned char *table, std::string name) | ||||
| 	defName=name; | ||||
| 	i = 0; | ||||
| 	DEFType = readNormalNr(i,4,table); i+=4; | ||||
| 	w = readNormalNr(i,4,table); i+=4; | ||||
| 	h = readNormalNr(i,4,table); i+=4; | ||||
| 	width = readNormalNr(i,4,table); i+=4; | ||||
| 	height = readNormalNr(i,4,table); i+=4; | ||||
| 	i=0xc; | ||||
| 	totalBlocks = readNormalNr(i,4,table); i+=4; | ||||
|  | ||||
| @@ -168,7 +168,7 @@ void CDefHandler::openFromMemory(unsigned char *table, std::string name) | ||||
| 	{ | ||||
| 		SEntries[j].name = SEntries[j].name.substr(0, SEntries[j].name.find('.')+4); | ||||
| 	} | ||||
| 	RWEntries = new unsigned int[h]; | ||||
| 	RWEntries = new unsigned int[height]; | ||||
| 	for(int i=0; i<SEntries.size(); ++i) | ||||
| 	{ | ||||
| 		Cimage nimg; | ||||
| @@ -337,10 +337,8 @@ SDL_Surface * CDefHandler::getSprite (int SIndex, unsigned char * FDef, BMPPalet | ||||
| 					((char*)(ret->pixels))[ftcp++]='\0'; | ||||
| 			} | ||||
| 		} | ||||
| 		for (int i=0;i<SpriteHeight;i++) | ||||
| 		{ | ||||
| 			RWEntries[i]=readNormalNr(BaseOffset,4,FDef);BaseOffset+=4; | ||||
| 		} | ||||
| 		memcpy(RWEntries, FDef+BaseOffset, SpriteHeight*sizeof(int)); | ||||
| 		BaseOffset += sizeof(int) * SpriteHeight; | ||||
| 		for (int i=0;i<SpriteHeight;i++) | ||||
| 		{ | ||||
| 			BaseOffset=BaseOffsetor+RWEntries[i]; | ||||
|   | ||||
| @@ -28,7 +28,7 @@ private: | ||||
| 	std::vector<SEntry> SEntries ; | ||||
|  | ||||
| public: | ||||
| 	int w, h; //width and height | ||||
| 	int width, height; //width and height | ||||
| 	static CLodHandler * Spriteh; | ||||
| 	std::string defName, curDir; | ||||
| 	std::vector<Cimage> ourImages; | ||||
|   | ||||
							
								
								
									
										12
									
								
								int3.h
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								int3.h
									
									
									
									
									
								
							| @@ -32,16 +32,18 @@ public: | ||||
| 	si32 x,y,z; | ||||
| 	inline int3():x(0),y(0),z(0){}; //c-tor, x/y/z initialized to 0 | ||||
| 	inline int3(const si32 & X, const si32 & Y, const si32 & Z):x(X),y(Y),z(Z){}; //c-tor | ||||
| 	inline int3(const int3 & val) : x(val.x), y(val.y), z(val.z){} //copy c-tor | ||||
| 	inline int3 operator=(const int3 & val) {x = val.x; y = val.y; z = val.z; return *this;} //assignemt operator | ||||
| 	inline ~int3(){} // d-tor - does nothing | ||||
| 	inline int3 operator+(const int3 & i) const | ||||
| 	inline int3 operator+(const int3 & i) const //returns int3 with coordinates increased by corresponding coordinate of given int3 | ||||
| 		{return int3(x+i.x,y+i.y,z+i.z);} | ||||
| 	inline int3 operator+(const si32 i) const //increases all components by si32 | ||||
| 	inline int3 operator+(const si32 i) const //returns int3 with coordinates increased by given numer | ||||
| 		{return int3(x+i,y+i,z+i);} | ||||
| 	inline int3 operator-(const int3 & i) const | ||||
| 	inline int3 operator-(const int3 & i) const //returns int3 with coordinates decreased by corresponding coordinate of given int3 | ||||
| 		{return int3(x-i.x,y-i.y,z-i.z);} | ||||
| 	inline int3 operator-(const si32 i) const | ||||
| 	inline int3 operator-(const si32 i) const //returns int3 with coordinates decreased by given numer | ||||
| 		{return int3(x-i,y-i,z-i);} | ||||
| 	inline int3 operator-() const //increases all components by si32 | ||||
| 	inline int3 operator-() const //returns opposite position | ||||
| 		{return int3(-x,-y,-z);} | ||||
| 	inline double dist2d(const int3 other) const //distance (z coord is not used) | ||||
| 		{return std::sqrt((double)(x-other.x)*(x-other.x) + (y-other.y)*(y-other.y));} | ||||
|   | ||||
| @@ -1230,7 +1230,7 @@ upgend: | ||||
| 							sendAndApply(&sc); | ||||
| 							switch(ba.additionalInfo) //spell id | ||||
| 							{ | ||||
| 							case 15://magic arrow | ||||
| 							case 15: //magic arrow | ||||
| 								{ | ||||
| 									CStack * attacked = gs->curB->getStackT(ba.destinationTile); | ||||
| 									if(!attacked) break; | ||||
| @@ -1243,7 +1243,7 @@ upgend: | ||||
| 									sendAndApply(&bsa); | ||||
| 									break; | ||||
| 								} | ||||
| 							case 16://ice bolt | ||||
| 							case 16: //ice bolt | ||||
| 								{ | ||||
| 									CStack * attacked = gs->curB->getStackT(ba.destinationTile); | ||||
| 									if(!attacked) break; | ||||
| @@ -1256,7 +1256,7 @@ upgend: | ||||
| 									sendAndApply(&bsa); | ||||
| 									break; | ||||
| 								} | ||||
| 							case 17://lightning bolt | ||||
| 							case 17: //lightning bolt | ||||
| 								{ | ||||
| 									CStack * attacked = gs->curB->getStackT(ba.destinationTile); | ||||
| 									if(!attacked) break; | ||||
| @@ -1269,6 +1269,19 @@ upgend: | ||||
| 									sendAndApply(&bsa); | ||||
| 									break; | ||||
| 								} | ||||
| 							case 18: //implosion | ||||
| 								{ | ||||
| 									CStack * attacked = gs->curB->getStackT(ba.destinationTile); | ||||
| 									if(!attacked) break; | ||||
| 									BattleStackAttacked bsa; | ||||
| 									bsa.flags |= 2; | ||||
| 									bsa.effect = 10; | ||||
| 									bsa.damageAmount = h->getPrimSkillLevel(2) * 75  +  s->powers[getSchoolLevel(h,s)];  | ||||
| 									bsa.stackAttacked = attacked->ID; | ||||
| 									prepareAttacked(bsa,attacked); | ||||
| 									sendAndApply(&bsa); | ||||
| 									break; | ||||
| 								} | ||||
| 							case 53: //haste | ||||
| 								{ | ||||
| 									SetStackEffect sse; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user