1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00
Fixed crash on catapult shot.
This commit is contained in:
Michał W. Urbańczyk 2009-11-29 02:46:30 +00:00
parent dced6ec17c
commit 85f336cbaa
9 changed files with 31 additions and 10 deletions

View File

@ -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

View File

@ -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;
}

View File

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

View File

@ -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;

View File

@ -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

View File

@ -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);
}

View File

@ -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)

View File

@ -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);

View File

@ -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;