Selaa lähdekoodia

Fixed #158, #236, #243, #248.
Fixed crash on catapult shot.

Michał W. Urbańczyk 16 vuotta sitten
vanhempi
sitoutus
85f336cbaa

+ 3 - 4
client/CAdvmapInterface.cpp

@@ -1607,7 +1607,7 @@ void CAdvMapInt::fadventureOPtions()
 
 void CAdvMapInt::fsystemOptions()
 {
-	CSystemOptionsWindow * sysopWindow = new CSystemOptionsWindow(center(genRect(487, 481, 0, 0)), LOCPLINT);
+	CSystemOptionsWindow * sysopWindow = new CSystemOptionsWindow(Rect::createCentered(487, 481), LOCPLINT);
 	GH.pushInt(sysopWindow);
 }
 
@@ -1883,7 +1883,7 @@ void CAdvMapInt::keyPressed(const SDL_KeyboardEvent & key)
 				k = arrowToNum(SDLKey(k));
 			}
 
-			if(!active)
+			if(!active || LOCPLINT->ctrlPressed())//ctrl makes arrow move screen, not hero
 				break;
 
 			k -= SDLK_KP0 + 1;
@@ -1920,8 +1920,7 @@ void CAdvMapInt::keyPressed(const SDL_KeyboardEvent & key)
 		return;
 	}
 	if(Dir && key.state == SDL_PRESSED //arrow is pressed
-		&& (SDL_GetKeyState(NULL)[SDLK_LCTRL] 
-			|| SDL_GetKeyState(NULL)[SDLK_RCTRL])
+		&& LOCPLINT->ctrlPressed()
 	)
 		scrollingDir |= Dir;
 	else

+ 8 - 2
client/CBattleInterface.cpp

@@ -792,9 +792,15 @@ CBattleAttack::CBattleAttack(CBattleInterface * _owner, int _stackID, int _dest)
 	attackedStack = LOCPLINT->cb->battleGetStackByPos(_dest, false);
 	attackingStack = LOCPLINT->cb->battleGetStackByID(_stackID, false);
 
-	assert(attackedStack && "attackedStack is NULL in CBattleAttack::CBattleAttack !\n");
 	assert(attackingStack && "attackingStack is NULL in CBattleAttack::CBattleAttack !\n");
-
+	if(attackingStack->creature->idNumber != 145) //catapult is allowed to attack not-creature
+	{
+		assert(attackedStack && "attackedStack is NULL in CBattleAttack::CBattleAttack !\n");
+	}
+	else //catapult can attack walls only
+	{
+		assert(LOCPLINT->cb->battleGetWallUnderHex(_dest) >= 0);
+	}
 	attackingStackPosBeforeReturn = attackingStack->position;
 }
 

+ 1 - 1
client/CHeroWindow.cpp

@@ -25,7 +25,7 @@
 #include <sstream>
 #include <boost/lexical_cast.hpp>
 
-#undef min;
+#undef min
 
 /*
  * CHeroWindow.cpp, part of VCMI engine

+ 9 - 0
client/CPlayerInterface.cpp

@@ -252,7 +252,11 @@ void CPlayerInterface::heroMoved(const TryMoveHero & details)
 	adventureInt->heroList.draw(screen2);
 
 	if(details.result == TryMoveHero::TELEPORTATION	||  details.start == details.end)
+	{
+		adventureInt->paths.erase(ho); //if hero goes through teleport / gate his path will be erased
+		adventureInt->terrain.currentPath = NULL;
 		return;
+	}
 
 	int3 hp = details.start;
 
@@ -1544,6 +1548,11 @@ void CPlayerInterface::objectRemoved( const CGObjectInstance *obj )
 	}
 }
 
+bool CPlayerInterface::ctrlPressed() const
+{
+	return SDL_GetKeyState(NULL)[SDLK_LCTRL]  ||  SDL_GetKeyState(NULL)[SDLK_RCTRL];
+}
+
 void SystemOptions::setMusicVolume( int newVolume )
 {
 	musicVolume = newVolume;

+ 1 - 0
client/CPlayerInterface.h

@@ -190,6 +190,7 @@ public:
 	void heroKilled(const CGHeroInstance* hero);
 	void waitWhileDialog();
 	bool shiftPressed() const; //determines if shift key is pressed (left or right or both)
+	bool ctrlPressed() const; //determines if ctrl key is pressed (left or right or both)
 	void redrawHeroWin(const CGHeroInstance * hero);
 	void updateWater();
 	void showComp(SComponent comp); //TODO: comment me

+ 5 - 0
client/GUIBase.cpp

@@ -776,3 +776,8 @@ bool isArrowKey( SDLKey key )
 {
 	return key >= SDLK_UP && key <= SDLK_LEFT;
 }
+
+Rect Rect::createCentered( int w, int h )
+{
+	return Rect(screen->w/2 - w/2, screen->h/2 - h/2, w, h);
+}

+ 1 - 0
client/GUIBase.h

@@ -132,6 +132,7 @@ struct Rect : public SDL_Rect
 		w = r.w;
 		h = r.h;
 	}
+	static Rect createCentered(int w, int h);
 	bool isIn(int qx, int qy) const //determines if given point lies inside rect
 	{
 		if (qx > x   &&   qx<x+w   &&   qy>y   &&   qy<y+h)

+ 2 - 2
client/GUIClasses.cpp

@@ -2428,7 +2428,7 @@ void CLevelWindow::close()
 CLevelWindow::CLevelWindow(const CGHeroInstance *hero, int pskill, std::vector<ui16> &skills, boost::function<void(ui32)> &callback)
 {
 	LOCPLINT->showingDialog->setn(true);
-	heroType = hero->subID;
+	heroPortrait = hero->portrait;
 	cb = callback;
 	for(int i=0;i<skills.size();i++)
 	{
@@ -2515,7 +2515,7 @@ void CLevelWindow::deactivate()
 void CLevelWindow::show(SDL_Surface * to)
 {
 	blitAt(bitmap,pos.x,pos.y,to);
-	blitAt(graphics->portraitLarge[heroType],170+pos.x,66+pos.y,to);
+	blitAt(graphics->portraitLarge[heroPortrait],170+pos.x,66+pos.y,to);
 	ok->show(to);
 	for(int i=0;i<comps.size();i++)
 		comps[i]->show(to);

+ 1 - 1
client/GUIClasses.h

@@ -435,7 +435,7 @@ public:
 class CLevelWindow : public CIntObject
 {
 public:
-	int heroType;
+	int heroPortrait;
 	SDL_Surface *bitmap; //background
 	std::vector<CSelectableComponent *> comps; //skills to select
 	AdventureMapButton *ok;