mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-12 02:28:11 +02:00
* small refactoring
* Rect intersection by operator&
This commit is contained in:
parent
2a7ad63495
commit
3ea97f7893
@ -5,11 +5,19 @@
|
||||
#include "SDL_framerate.h"
|
||||
#include <map>
|
||||
#include <list>
|
||||
#include <algorithm>
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define sprintf_s snprintf
|
||||
#endif
|
||||
|
||||
#ifdef max
|
||||
#undef max
|
||||
#endif
|
||||
#ifdef min
|
||||
#undef min
|
||||
#endif
|
||||
|
||||
class CDefEssential;
|
||||
class AdventureMapButton;
|
||||
class CHighlightableButtonsGroup;
|
||||
@ -92,37 +100,45 @@ struct Rect : public SDL_Rect
|
||||
y = Y;
|
||||
w = W;
|
||||
h = H;
|
||||
};
|
||||
}
|
||||
Rect(const SDL_Rect & r)
|
||||
{
|
||||
x = r.x;
|
||||
y = r.y;
|
||||
w = r.w;
|
||||
h = r.h;
|
||||
};
|
||||
bool isIn(int qx, int qy)
|
||||
}
|
||||
bool isIn(int qx, int qy) const
|
||||
{
|
||||
if (qx > x && qx<x+w && qy>y && qy<y+h)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
bool isIn(const Point &q)
|
||||
bool isIn(const Point &q) const
|
||||
{
|
||||
return isIn(q.x,q.y);
|
||||
}
|
||||
Point topLeft()
|
||||
Point topLeft() const
|
||||
{
|
||||
return Point(x,y);
|
||||
}
|
||||
Point bottomRight()
|
||||
Point topRight() const
|
||||
{
|
||||
return Point(x+w,y);
|
||||
}
|
||||
Point bottomLeft() const
|
||||
{
|
||||
return Point(x,y+h);
|
||||
}
|
||||
Point bottomRight() const
|
||||
{
|
||||
return Point(x+w,y+h);
|
||||
}
|
||||
Rect operator+(const Rect &p)
|
||||
Rect operator+(const Rect &p) const
|
||||
{
|
||||
return Rect(x+p.x,y+p.y,w,h);
|
||||
}
|
||||
Rect operator+(const Point &p)
|
||||
Rect operator+(const Point &p) const
|
||||
{
|
||||
return Rect(x+p.x,y+p.y,w,h);
|
||||
}
|
||||
@ -132,6 +148,27 @@ struct Rect : public SDL_Rect
|
||||
y += p.y;
|
||||
return *this;
|
||||
}
|
||||
Rect operator&(const Rect &p) const //rect intersection
|
||||
{
|
||||
bool intersect = isIn(p.topLeft()) || isIn(p.bottomRight()) || isIn(p.topRight()) || isIn(p.bottomLeft());
|
||||
|
||||
if(intersect)
|
||||
{
|
||||
Rect ret;
|
||||
ret.x = std::max(this->x, p.x);
|
||||
ret.y = std::max(this->y, p.y);
|
||||
Point bR; //bottomRight point of returned rect
|
||||
bR.x = std::min(this->w+this->x, p.w+p.x);
|
||||
bR.y = std::min(this->h+this->y, p.h+p.y);
|
||||
ret.w = bR.x - ret.x;
|
||||
ret.h = bR.y - ret.y;
|
||||
return ret;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Rect();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class IShowable
|
||||
|
@ -2312,84 +2312,32 @@ void CGameHandler::makeCustomAction( BattleAction &ba )
|
||||
sendAndApply(&bsa);
|
||||
break;
|
||||
}
|
||||
case 27: //shield
|
||||
{
|
||||
SPELL_CAST_TEMPLATE_1(27, h->getPrimSkillLevel(2))
|
||||
break;
|
||||
}
|
||||
case 27: //shield
|
||||
case 28: //air shield
|
||||
{
|
||||
SPELL_CAST_TEMPLATE_1(28, h->getPrimSkillLevel(2))
|
||||
break;
|
||||
}
|
||||
case 41: //bless
|
||||
{
|
||||
SPELL_CAST_TEMPLATE_1(41, h->getPrimSkillLevel(2))
|
||||
break;
|
||||
}
|
||||
case 42: //curse
|
||||
{
|
||||
SPELL_CAST_TEMPLATE_1(42, h->getPrimSkillLevel(2))
|
||||
break;
|
||||
}
|
||||
case 43: //bloodlust
|
||||
{
|
||||
SPELL_CAST_TEMPLATE_1(43, h->getPrimSkillLevel(2))
|
||||
break;
|
||||
}
|
||||
case 45: //weakness
|
||||
{
|
||||
SPELL_CAST_TEMPLATE_1(45, h->getPrimSkillLevel(2))
|
||||
break;
|
||||
}
|
||||
case 46: //stone skin
|
||||
{
|
||||
SPELL_CAST_TEMPLATE_1(46, h->getPrimSkillLevel(2))
|
||||
break;
|
||||
}
|
||||
case 48: //prayer
|
||||
{
|
||||
SPELL_CAST_TEMPLATE_1(48, h->getPrimSkillLevel(2))
|
||||
break;
|
||||
}
|
||||
case 49: //mirth
|
||||
{
|
||||
SPELL_CAST_TEMPLATE_1(49, h->getPrimSkillLevel(2))
|
||||
break;
|
||||
}
|
||||
case 50: //sorrow
|
||||
{
|
||||
SPELL_CAST_TEMPLATE_1(50, h->getPrimSkillLevel(2))
|
||||
break;
|
||||
}
|
||||
case 51: //fortune
|
||||
{
|
||||
SPELL_CAST_TEMPLATE_1(51, h->getPrimSkillLevel(2))
|
||||
break;
|
||||
}
|
||||
case 52: //misfortune
|
||||
{
|
||||
SPELL_CAST_TEMPLATE_1(52, h->getPrimSkillLevel(2))
|
||||
break;
|
||||
}
|
||||
case 53: //haste
|
||||
{
|
||||
SPELL_CAST_TEMPLATE_1(53, h->getPrimSkillLevel(2))
|
||||
break;
|
||||
}
|
||||
case 54: //slow
|
||||
{
|
||||
SPELL_CAST_TEMPLATE_1(54, h->getPrimSkillLevel(2))
|
||||
SPELL_CAST_TEMPLATE_1(ba.additionalInfo, h->getPrimSkillLevel(2))
|
||||
break;
|
||||
}
|
||||
case 56: //frenzy
|
||||
{
|
||||
SPELL_CAST_TEMPLATE_1(56, 1)
|
||||
SPELL_CAST_TEMPLATE_1(ba.additionalInfo, 1)
|
||||
break;
|
||||
}
|
||||
case 61: //forgetfulness
|
||||
{
|
||||
SPELL_CAST_TEMPLATE_1(61, h->getPrimSkillLevel(2))
|
||||
SPELL_CAST_TEMPLATE_1(ba.additionalInfo, h->getPrimSkillLevel(2))
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user