瀏覽代碼

Merged changes from trunk.

Michał W. Urbańczyk 14 年之前
父節點
當前提交
f52d4f7cd6

+ 2 - 0
AI/EmptyAI/CEmptyAI.h

@@ -1,6 +1,8 @@
 #include "../../AI_Base.h"
 #include "../../CCallback.h"
 
+struct HeroMoveDetails;
+
 class CEmptyAI : public CGlobalAI
 {
 	ICallback * cb;

+ 7 - 8
CConsoleHandler.cpp

@@ -19,12 +19,13 @@
 	typedef std::string TColor;
 	#define	_kill_thread(a) pthread_cancel(a)
 	typedef pthread_t ThreadHandle;
-	#define CONSOLE_GREEN "\x1b[1;40;32m"
-	#define CONSOLE_RED "\x1b[1;40;32m"
-	#define CONSOLE_MAGENTA "\x1b[1;40;35m"
-	#define CONSOLE_YELLOW "\x1b[1;40;32m"
-	#define CONSOLE_WHITE "\x1b[1;40;39m"
-	#define CONSOLE_GRAY "\x1b[0;40;39m"
+	#define CONSOLE_GREEN "\x1b[1;32m"
+	#define CONSOLE_RED "\x1b[1;32m"
+	#define CONSOLE_MAGENTA "\x1b[1;35m"
+	#define CONSOLE_YELLOW "\x1b[1;32m"
+	#define CONSOLE_WHITE "\x1b[1;39m"
+	#define CONSOLE_GRAY "\x1b[1;30m"
+	#define CONSOLE_TEAL "\x1b[1;36m"
 #else
 	#define WIN32_LEAN_AND_MEAN //excludes rarely used stuff from windows headers - delete this line if something is missing
 	#include <windows.h>
@@ -231,7 +232,5 @@ void CConsoleHandler::end()
 
 void CConsoleHandler::start()
 {
-#ifdef _WIN32
 	thread = new boost::thread(boost::bind(&CConsoleHandler::run,console));
-#endif
 }

+ 10 - 8
client/CAnimation.cpp

@@ -298,14 +298,16 @@ BMPPalette * CDefFile::getPalette()
 
 CDefFile::CDefFile(std::string Name):data(NULL),colors(NULL)
 {
-	static SDL_Color H3Palette[8] = {{  0,   0,   0, 255},
-	                                 {  0,   0,   0, 192},
-	/* 5 shadow colors */            {  0,   0,   0, 128},
-	                                 {  0,   0,   0,  64},
-	                                 {  0,   0,   0,  32},
-	                                 {255, 255,   0, 255},
-	/* 3 selection highlight color */{255, 255,   0, 255},
-	                                 {255, 255,   0, 255}};
+	//First 8 colors in def palette used for transparency
+	static SDL_Color H3Palette[8] = {
+	{  0,   0,   0, 255},// 100% - transparency
+	{  0,   0,   0, 192},//  75% - shadow border, 
+	{  0,   0,   0, 128},// TODO: find exact value
+	{  0,   0,   0, 128},// TODO: for transparency
+	{  0,   0,   0, 128},//  50% - shadow body
+	{  0,   0,   0, 255},// 100% - selection highlight
+	{  0,   0,   0, 128},//  50% - shadow body   below selection
+	{  0,   0,   0, 192}};// 75% - shadow border below selection
 	
 	data = spriteh->giveFile(Name, FILE_ANIMATION, &datasize);
 	if (!data)

+ 15 - 16
client/CAnimation.h

@@ -42,17 +42,16 @@ private:
 		ui32 TopMargin;
 	};
 
-	unsigned int type;
-	unsigned char * data;
-	int datasize;
-	BMPPalette * colors;
-
 	//offset[group][frame] - offset of frame data in file
 	std::vector< std::vector <size_t> > offset;
 
 	//sorted list of offsets used to determine size
 	std::set <size_t> offList;
 
+	unsigned char * data;
+	BMPPalette * colors;
+	int datasize;
+	unsigned int type;
 
 public:
 	CDefFile(std::string Name);
@@ -88,33 +87,33 @@ private:
 		//surface for this entry
 		SDL_Surface * surf;
 
-		//bitfield, location of image data: 1 - def, 2 - file#9.*, 4 - file#9#2.*
-		unsigned char source;
+		//data for CompressedAnim
+		unsigned char * data;
 
 		//reference count, changed by loadFrame \ unloadFrame
 		size_t refCount;
 
-		//data for CompressedAnim
-		unsigned char * data;
-
 		//size of compressed data, unused for def files
 		size_t dataSize;
 
+		//bitfield, location of image data: 1 - def, 2 - file#9.*, 4 - file#9#2.*
+		unsigned char source;
+
 		AnimEntry();
 	};
 
-	//animation file name
-	std::string name;
-
-	//if true all frames will be stored in compressed state
-	const bool compressed;
-
 	//palette from def file, used only for compressed anim
 	BMPPalette * defPalette;
 
 	//entries[group][position], store all info regarding frames
 	std::vector< std::vector <AnimEntry> > entries;
 
+	//animation file name
+	std::string name;
+
+	//if true all frames will be stored in compressed state
+	const bool compressed;
+
 	//loader, will be called by load(), require opened def file for loading from it. Returns true if image is loaded
 	bool loadFrame(CDefFile * file, size_t frame, size_t group);
 

+ 2 - 0
client/CCastleInterface.cpp

@@ -803,6 +803,8 @@ void CCastleInterface::townChange()
 {
 	const CGTownInstance * nt = LOCPLINT->towns[townlist->selected];
 	int tpos = townlist->selected - townlist->from;
+	if ( nt == town )
+		return;
 	GH.popIntTotally(this);
 	GH.pushInt(new CCastleInterface(nt, tpos));
 }

+ 9 - 30
client/CCreatureAnimation.cpp

@@ -308,54 +308,33 @@ inline void CCreatureAnimation::putPixel(
 	const unsigned char & animCount
 ) const
 {	
-    if(palc!=0)
+	if(palc!=0)
 	{
 		Uint8 * p = (Uint8*)dest->pixels + ftcp*dest->format->BytesPerPixel;
 		if(palc > 7) //normal color
 		{
 			ColorPutter<bpp, 0>::PutColor(p, color.R, color.G, color.B);
 		}
-		else if((yellowBorder || blueBorder) && (palc == 6 || palc == 7)) //dark yellow border
+		else if((yellowBorder || blueBorder) && (palc == 6 || palc == 7)) //selection highlight
 		{
 			if(blueBorder)
 				ColorPutter<bpp, 0>::PutColor(p, 0, 0x0f + animCount, 0x0f + animCount);
 			else
 				ColorPutter<bpp, 0>::PutColor(p, 0x0f + animCount, 0x0f + animCount, 0);
 		}
-		else if((yellowBorder || blueBorder) && (palc == 5)) //yellow border
+		else if (palc == 5) //selection highlight or transparent
 		{
 			if(blueBorder)
 				ColorPutter<bpp, 0>::PutColor(p, color.B, color.G - 0xf0 + animCount, color.R - 0xf0 + animCount); //shouldnt it be reversed? its bgr instead of rgb
-			else
+			else if (yellowBorder)
 				ColorPutter<bpp, 0>::PutColor(p, color.R - 0xf0 + animCount, color.G - 0xf0 + animCount, color.B);
 		}
-		else if(palc < 5) //shadow
-		{ 
+		else //shadow
+		{
+			//determining transparency value, 255 or 0 should be already filtered
 			Uint16 alpha;
-			switch(color.G)
-			{
-			case 0:
-				alpha = 128;
-				break;
-			case 50:
-				alpha = 50+32;
-				break;
-			case 100:
-				alpha = 100+64;
-				break;
-			case 125:
-				alpha = 125+64;
-				break;
-			case 128:
-				alpha = 128+64;
-				break;
-			case 150:
-				alpha = 150+64;
-				break;
-			default:
-				alpha = 255;
-				break;
-			}
+			static Uint16 colToAlpha[8] = {255,192,128,128,128,255,128,192};
+			alpha = colToAlpha[palc];
 
 			if(bpp != 3 && bpp != 4)
 			{

+ 10 - 10
client/CKingdomInterface.cpp

@@ -733,7 +733,7 @@ CKingdomInterface::CHeroItem::CHeroItem(int num, CKingdomInterface * Owner)
 	{
 		secondarySkills.push_back(new LRClickableAreaWTextComp(genRect(32, 32, pos.x+410+i*37, pos.y+5), SComponent::secskill));
 	}
-
+/*
 	for (int i=0; i<18;i++)
 	{
 		artifacts.push_back(new CArtPlace(this, genRect(44, 44, pos.x+268+(i%9)*48, pos.y+66)));
@@ -742,7 +742,7 @@ CKingdomInterface::CHeroItem::CHeroItem(int num, CKingdomInterface * Owner)
 	for (int i=0; i<8;i++)
 	{
 		backpack.push_back(new CArtPlace(this, genRect(44, 44, pos.x+293+(i%9)*48, pos.y+66)));
-	}
+	}*/
 }
 
 CKingdomInterface::CHeroItem::~CHeroItem()
@@ -899,21 +899,21 @@ void CKingdomInterface::CHeroItem::showAll(SDL_Surface * to)
 	{//arts
 		case 1:iter = 9;//misc. arts, spellbook, war machines
 		case 0://equipped arts
-			for (int i = iter ; i<iter+9;i++)
+			/*for (int i = iter ; i<iter+9;i++)
 			{
 				int artID = hero->getArtTypeId(i);
 				if (artID>=0)
 					blitAt(graphics->artDefs->ourImages[artID].bitmap,pos.x+268+48*(i%9),pos.y+66,to);
-			}
+			}*/
 			break;
 		case 2:
 			artLeft->show(to);
 			artRight->show(to);
 			int max = hero->artifacts.size();
 			iter = std::min(8, max);
-			for (size_t it = 0 ; it<iter;it++)
+			/*for (size_t it = 0 ; it<iter;it++)
 				blitAt(graphics->artDefs->ourImages[hero->artifacts[(it+backpackPos)%max]->id].bitmap,pos.x+293+48*it,pos.y+66,to);
-			break;
+			*/break;
 	}
 	show(to);
 }
@@ -934,7 +934,7 @@ void CKingdomInterface::CHeroItem::activate()
 	if (!hero)
 		return;
 	artButtons->activate();
-	garr->activate();
+	garr->activate();/*
 	if ( artGroup == 2 )
 	{
 		artLeft->activate();
@@ -946,7 +946,7 @@ void CKingdomInterface::CHeroItem::activate()
 	{
 		for (size_t i=artGroup*9; i<9+artGroup*9;i++)
 			artifacts[i]->activate();
-	}
+	}*/
 	portrait->activate();
 	experience->activate();
 	morale->activate();
@@ -966,7 +966,7 @@ void CKingdomInterface::CHeroItem::deactivate()
 	if (!hero)
 		return;
 	artButtons->deactivate();
-	garr->deactivate();
+	garr->deactivate();/*
 	if ( artGroup == 2 )
 	{
 		artLeft->deactivate();
@@ -978,7 +978,7 @@ void CKingdomInterface::CHeroItem::deactivate()
 	{
 		for (size_t i=artGroup*9; i<9+artGroup*9;i++)
 			artifacts[i]->deactivate();
-	}
+	}*/
 
 	portrait->deactivate();
 	experience->deactivate();

+ 2 - 2
client/CKingdomInterface.h

@@ -81,8 +81,8 @@ class CKingdomInterface : public CGarrisonHolder
 		LRClickableAreaWText * speciality;
 		std::vector<LRClickableAreaWTextComp *> primarySkills;
 		std::vector<LRClickableAreaWTextComp *> secondarySkills;
-		std::vector<LRClickableAreaWTextComp *> artifacts;
-		std::vector<LRClickableAreaWTextComp *> backpack;
+		std::vector<CArtPlace *> artifacts;
+		std::vector<CArtPlace *> backpack;
 		CHighlightableButtonsGroup * artButtons;
 		void setHero(const CGHeroInstance * newHero);//change hero and update info
 		void scrollArts(int move);//moving backpack, receiving distance

+ 48 - 36
client/CMessage.cpp

@@ -102,11 +102,13 @@ SDL_Surface * CMessage::drawBox1(int w, int h, int playerColor) //draws box for
 {
 	//prepare surface
 	SDL_Surface * ret = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, screen->format->BitsPerPixel, screen->format->Rmask, screen->format->Gmask, screen->format->Bmask, screen->format->Amask);
-	for (int i=0; i<h; i+=background->h)//background
+	for (int i=0; i<w; i+=background->w)//background
 	{
-		for (int j=0; j<w; j+=background->w)
+		for (int j=0; j<h; j+=background->h)
 		{
-			CSDL_Ext::blitSurface(background,&genRect(background->h,background->w,0,0),ret,&genRect(h,w,j,i)); //FIXME taking address of temporary
+			Rect srcR(0,0,background->w, background->h);
+			Rect dstR(i,j,w,h);
+			CSDL_Ext::blitSurface(background, &srcR, ret, &dstR);
 		}
 	}
 	drawBorder(playerColor, ret, w, h);
@@ -486,31 +488,41 @@ void CMessage::drawIWindow(CInfoWindow * ret, std::string text, int player)
 
 void CMessage::drawBorder(int playerColor, SDL_Surface * ret, int w, int h, int x, int y)
 {	
+	std::vector<SDL_Surface *> &box = piecesOfBox[playerColor];
 	//obwodka I-szego rzedu pozioma //border of 1st series, horizontal
-	for (int i=0; i<w-piecesOfBox[playerColor][6]->w; i+=piecesOfBox[playerColor][6]->w)
+	for (int i=0; i<w-box[6]->w; i+=box[6]->w)
 	{
-		CSDL_Ext::blitSurface
-			(piecesOfBox[playerColor][6],NULL,ret,&genRect(piecesOfBox[playerColor][6]->h,piecesOfBox[playerColor][6]->w,x+i,y+0));
-		CSDL_Ext::blitSurface
-			(piecesOfBox[playerColor][7],NULL,ret,&genRect(piecesOfBox[playerColor][7]->h,piecesOfBox[playerColor][7]->w,x+i,y+h-piecesOfBox[playerColor][7]->h+1));
+		Rect dstR(x+i, y, box[6]->w, box[6]->h);
+		CSDL_Ext::blitSurface(box[6], NULL, ret, &dstR);
+		
+		int currY = y+h-box[7]->h+1;
+		dstR=Rect(x+i, currY, box[7]->w, box[7]->h);
+
+		CSDL_Ext::blitSurface(box[7], NULL, ret, &dstR);
 	}
 	//obwodka I-szego rzedu pionowa  //border of 1st series, vertical
-	for (int i=0; i<h-piecesOfBox[playerColor][4]->h; i+=piecesOfBox[playerColor][4]->h)
+	for (int i=0; i<h-box[4]->h; i+=box[4]->h)
 	{
-		CSDL_Ext::blitSurface
-			(piecesOfBox[playerColor][4],NULL,ret,&genRect(piecesOfBox[playerColor][4]->h,piecesOfBox[playerColor][4]->w,x+0,y+i));
-		CSDL_Ext::blitSurface
-			(piecesOfBox[playerColor][5],NULL,ret,&genRect(piecesOfBox[playerColor][5]->h,piecesOfBox[playerColor][5]->w,x+w-piecesOfBox[playerColor][5]->w,y+i));
+		Rect dstR(x, y+i, box[4]->w, box[4]->h);
+		CSDL_Ext::blitSurface(box[4], NULL, ret, &dstR);
+		
+		int currX = x+w-box[5]->w;
+		dstR=Rect(currX, y+i, box[5]->w, box[5]->h);
+
+		CSDL_Ext::blitSurface(box[5], NULL, ret, &dstR);
 	}
 	//corners
-	CSDL_Ext::blitSurface
-		(piecesOfBox[playerColor][0],NULL,ret,&genRect(piecesOfBox[playerColor][0]->h,piecesOfBox[playerColor][0]->w,x+0,y+0));
-	CSDL_Ext::blitSurface
-		(piecesOfBox[playerColor][1],NULL,ret,&genRect(piecesOfBox[playerColor][1]->h,piecesOfBox[playerColor][1]->w,x+w-piecesOfBox[playerColor][1]->w,y+0));
-	CSDL_Ext::blitSurface
-		(piecesOfBox[playerColor][2],NULL,ret,&genRect(piecesOfBox[playerColor][2]->h,piecesOfBox[playerColor][2]->w,x+0,y+h-piecesOfBox[playerColor][2]->h+1));
-	CSDL_Ext::blitSurface
-		(piecesOfBox[playerColor][3],NULL,ret,&genRect(piecesOfBox[playerColor][3]->h,piecesOfBox[playerColor][3]->w,x+w-piecesOfBox[playerColor][3]->w,y+h-piecesOfBox[playerColor][3]->h+1));
+	Rect dstR(x, y, box[0]->w, box[0]->h);
+	CSDL_Ext::blitSurface(box[0], NULL, ret, &dstR);
+
+	dstR=Rect(x+w-box[1]->w, y,   box[1]->w, box[1]->h);
+	CSDL_Ext::blitSurface(box[1], NULL, ret, &dstR);
+
+	dstR=Rect(x, y+h-box[2]->h+1, box[2]->w, box[2]->h);
+	CSDL_Ext::blitSurface(box[2], NULL, ret, &dstR);
+
+	dstR=Rect(x+w-box[3]->w, y+h-box[3]->h+1, box[3]->w, box[3]->h);
+	CSDL_Ext::blitSurface(box[3], NULL, ret, &dstR);
 }
 
 ComponentResolved::ComponentResolved()
@@ -526,7 +538,7 @@ ComponentResolved::ComponentResolved( SComponent *Comp )
 	comp = Comp;
 	img = comp->getImg();
 	std::vector<std::string> brtext = CMessage::breakText(comp->subtitle,13); //text 
-	txt = CMessage::drawText(&brtext,txtFontHeight,FONT_MEDIUM);
+	txt = CMessage::drawText(&brtext,txtFontHeight,FONT_SMALL);
 
 	//calculate dimensions
 	std::pair<int,int> textSize = CMessage::getMaxSizes(txt, txtFontHeight);
@@ -610,26 +622,25 @@ void ComponentsToBlit::blitCompsOnSur( SDL_Surface * _or, int inter, int &curh,
 		{
 			totalw += (inter) * ((comps)[i].size() - 1);
 		}
-
-		curh+=maxh/2;
-		int compX, compY;
-
+		
+		int middleh = curh + maxh/2;//axis for image aligment
 		int curw = (ret->w/2)-(totalw/2);
+
 		for(size_t j=0;j<(comps)[i].size();j++)
 		{
 			ComponentResolved *cur = (comps)[i][j];
 
 			//blit img
-			compX = curw + ( cur->comp->pos.w - cur->comp->getImg()->w ) / 2;
-			compY = curh - cur->comp->getImg()->h / 2;
-			blitAt(cur->img, compX, compY, ret);
-			cur->comp->pos.x = compX;
-			cur->comp->pos.y = compY;
+			int imgX = curw + ( cur->comp->pos.w - cur->comp->getImg()->w ) / 2;
+			int imgY = middleh - cur->comp->getImg()->h / 2;
+			blitAt(cur->img, imgX, imgY, ret);
+			cur->comp->pos.x = imgX;
+			cur->comp->pos.y = imgY;
 
 			//blit subtitle
-			compX += cur->comp->getImg()->w/2;
-			compY  = curh + maxh / 2 + COMPONENT_TO_SUBTITLE;
-			CMessage::blitTextOnSur(cur->txt, cur->txtFontHeight, compY, ret, compX );
+			int textX = imgX + cur->comp->getImg()->w/2;
+			int textY = middleh + cur->comp->getImg()->h /2 + COMPONENT_TO_SUBTITLE;
+			CMessage::blitTextOnSur(cur->txt, cur->txtFontHeight, textY, ret, textX );
 
 			//if there is subsequent component blit "or"
 			curw += cur->comp->pos.w;
@@ -638,12 +649,13 @@ void ComponentsToBlit::blitCompsOnSur( SDL_Surface * _or, int inter, int &curh,
 				if(_or)
 				{
 					curw+=inter;
-					blitAt(_or,curw,curh-(_or->h/2),ret);
+					blitAt(_or,curw,middleh-(_or->h/2),ret);
 					curw+=_or->w;
 				}
 				curw+=inter;
 			}
+			amax(curh, textY);
 		}
-		curh = compY+BETWEEN_COMPS_ROWS;
+		curh += BETWEEN_COMPS_ROWS;
 	}
 }

+ 9 - 0
client/CVideoHandler.cpp

@@ -555,6 +555,13 @@ bool CVideoPlayer::playVideo(int x, int y, SDL_Surface *dst, bool stopOnKey)
 
 #else
 
+//Workaround for compile error in ffmpeg (UINT_64C was not declared)
+#define __STDC_CONSTANT_MACROS
+#ifdef _STDINT_H
+#undef _STDINT_H
+#endif
+#include <stdint.h>
+
 #include <../client/SDL_framerate.h>
 
 extern "C" {
@@ -934,3 +941,5 @@ CVideoPlayer::~CVideoPlayer()
 }
 
 #endif
+
+ 	  	 

+ 4 - 1
client/GUIClasses.cpp

@@ -3520,7 +3520,7 @@ CAltarWindow::CAltarWindow(const IMarket *Market, const CGHeroInstance *Hero /*=
 
 		{
 			BLOCK_CAPTURING;
-			arts = new CArtifactsOfHero(Point(-267,-10));
+			arts = new CArtifactsOfHero(Point(pos.x-363, pos.y-12));
 			arts->commonInfo = new CArtifactsOfHero::SCommonPart;
 			arts->commonInfo->participants.insert(arts);
 			arts->setHero(Hero);
@@ -5983,7 +5983,10 @@ void CUniversityWindow::CItem::showAll(SDL_Surface * to)
 		        break;
 		case 2: bar = parent->green;
 		        break;
+		default:bar = NULL;
+		        break;
 	}
+	assert(bar);
 	
 	blitAtLoc(bar->bg, -28, -22, to);
 	blitAtLoc(bar->bg, -28,  48, to);

+ 1 - 1
config/AC_desc.txt

@@ -73,7 +73,7 @@
 71 1 SP01_.DEF
 72 1 SP04_.DEF
 73 1 SP03_.DEF
-74 1 SP06_.DEF
+74 1 SP12_.DEF
 75 1 SP07_A.DEF
 76 1 SP07_B.DEF
 77 1 SP08_.DEF

+ 2 - 2
config/buildings.txt

@@ -116,8 +116,8 @@
 2 43 TBTWUP_6.def 75 91
 2 8 TBTWCAS2.def 301 0
 3 16 TBINBLAK.def 684 253
-3 9 TBINCAS3.def 223 18
-3 7 TBINCSTL.def 223 44
+3 9 TBINCAS3.def 222 18
+3 7 TBINCSTL.def 222 44
 3 30 TBINDW_0.def 614 256
 3 31 TBINDW_1.def 187 248
 3 32 TBINDW_2.def 9 325

+ 3 - 3
config/cr_shots.txt

@@ -26,12 +26,12 @@
 123 PICEE.DEF 0
 127 CPRGTIX.DEF 0
 136 SMBALX.DEF 0
-137 PLCBOWX.DEF 0
+137 PELFX.DEF 0
 138 PHALF.DEF 1
 145 SMCATX.DEF 1
 146 SMBALX.DEF 0
-152 SMBALX.DEF 0
-169 SMBALX.DEF 0
+152 CPRGTIX.DEF 0
+169 CPRZEAX.DEF 0
 170 PLCBOWX.DEF 0
 171 PLCBOWX.DEF 0
 173 CPRGRE.DEF 1

+ 4 - 0
lib/map.h

@@ -215,6 +215,10 @@ public:
 	{
 		return firstOccurence < b.firstOccurence;
 	}
+	bool operator<=(const CMapEvent &b) const
+	{
+		return firstOccurence <= b.firstOccurence;
+	}
 };
 
 class DLL_EXPORT CCastleEvent: public CMapEvent

+ 13 - 3
server/CGameHandler.cpp

@@ -3808,8 +3808,13 @@ void CGameHandler::handleTimeEvents()
 
 		if(ev->nextOccurence)
 		{
+			gs->map->events.pop_front();
+
 			ev->firstOccurence += ev->nextOccurence;
-			gs->map->events.sort(evntCmp);
+			std::list<CMapEvent*>::iterator it = gs->map->events.begin();
+			while ( it !=gs->map->events.end() && **it <= *ev )
+				it++;
+			gs->map->events.insert(it, ev);
 		}
 		else
 		{
@@ -3869,9 +3874,14 @@ void CGameHandler::handleTownEvents(CGTownInstance * town, NewTurn &n, std::map<
 		}
 
 		if(ev->nextOccurence)
-		{
+		{
+			town->events.pop_front();
+
 			ev->firstOccurence += ev->nextOccurence;
-			town->events.sort(evntCmp);
+			std::list<CCastleEvent*>::iterator it = town->events.begin();
+			while ( it !=town->events.end() &&  **it <= *ev )
+				it++;
+			town->events.insert(it, ev);
 		}
 		else
 		{