1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-26 03:52:01 +02:00

* small refactoring

* Rect intersection by operator&
This commit is contained in:
mateuszb 2009-03-21 17:22:16 +00:00
parent 2a7ad63495
commit 3ea97f7893
2 changed files with 49 additions and 64 deletions

View File

@ -5,11 +5,19 @@
#include "SDL_framerate.h" #include "SDL_framerate.h"
#include <map> #include <map>
#include <list> #include <list>
#include <algorithm>
#ifdef __GNUC__ #ifdef __GNUC__
#define sprintf_s snprintf #define sprintf_s snprintf
#endif #endif
#ifdef max
#undef max
#endif
#ifdef min
#undef min
#endif
class CDefEssential; class CDefEssential;
class AdventureMapButton; class AdventureMapButton;
class CHighlightableButtonsGroup; class CHighlightableButtonsGroup;
@ -92,37 +100,45 @@ struct Rect : public SDL_Rect
y = Y; y = Y;
w = W; w = W;
h = H; h = H;
}; }
Rect(const SDL_Rect & r) Rect(const SDL_Rect & r)
{ {
x = r.x; x = r.x;
y = r.y; y = r.y;
w = r.w; w = r.w;
h = r.h; 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) if (qx > x && qx<x+w && qy>y && qy<y+h)
return true; return true;
return false; return false;
} }
bool isIn(const Point &q) bool isIn(const Point &q) const
{ {
return isIn(q.x,q.y); return isIn(q.x,q.y);
} }
Point topLeft() Point topLeft() const
{ {
return Point(x,y); 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); 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); 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); return Rect(x+p.x,y+p.y,w,h);
} }
@ -132,6 +148,27 @@ struct Rect : public SDL_Rect
y += p.y; y += p.y;
return *this; 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 class IShowable

View File

@ -2312,84 +2312,32 @@ void CGameHandler::makeCustomAction( BattleAction &ba )
sendAndApply(&bsa); sendAndApply(&bsa);
break; break;
} }
case 27: //shield case 27: //shield
{
SPELL_CAST_TEMPLATE_1(27, h->getPrimSkillLevel(2))
break;
}
case 28: //air shield case 28: //air shield
{
SPELL_CAST_TEMPLATE_1(28, h->getPrimSkillLevel(2))
break;
}
case 41: //bless case 41: //bless
{
SPELL_CAST_TEMPLATE_1(41, h->getPrimSkillLevel(2))
break;
}
case 42: //curse case 42: //curse
{
SPELL_CAST_TEMPLATE_1(42, h->getPrimSkillLevel(2))
break;
}
case 43: //bloodlust case 43: //bloodlust
{
SPELL_CAST_TEMPLATE_1(43, h->getPrimSkillLevel(2))
break;
}
case 45: //weakness case 45: //weakness
{
SPELL_CAST_TEMPLATE_1(45, h->getPrimSkillLevel(2))
break;
}
case 46: //stone skin case 46: //stone skin
{
SPELL_CAST_TEMPLATE_1(46, h->getPrimSkillLevel(2))
break;
}
case 48: //prayer case 48: //prayer
{
SPELL_CAST_TEMPLATE_1(48, h->getPrimSkillLevel(2))
break;
}
case 49: //mirth case 49: //mirth
{
SPELL_CAST_TEMPLATE_1(49, h->getPrimSkillLevel(2))
break;
}
case 50: //sorrow case 50: //sorrow
{
SPELL_CAST_TEMPLATE_1(50, h->getPrimSkillLevel(2))
break;
}
case 51: //fortune case 51: //fortune
{
SPELL_CAST_TEMPLATE_1(51, h->getPrimSkillLevel(2))
break;
}
case 52: //misfortune case 52: //misfortune
{
SPELL_CAST_TEMPLATE_1(52, h->getPrimSkillLevel(2))
break;
}
case 53: //haste case 53: //haste
{
SPELL_CAST_TEMPLATE_1(53, h->getPrimSkillLevel(2))
break;
}
case 54: //slow case 54: //slow
{ {
SPELL_CAST_TEMPLATE_1(54, h->getPrimSkillLevel(2)) SPELL_CAST_TEMPLATE_1(ba.additionalInfo, h->getPrimSkillLevel(2))
break; break;
} }
case 56: //frenzy case 56: //frenzy
{ {
SPELL_CAST_TEMPLATE_1(56, 1) SPELL_CAST_TEMPLATE_1(ba.additionalInfo, 1)
break; break;
} }
case 61: //forgetfulness case 61: //forgetfulness
{ {
SPELL_CAST_TEMPLATE_1(61, h->getPrimSkillLevel(2)) SPELL_CAST_TEMPLATE_1(ba.additionalInfo, h->getPrimSkillLevel(2))
break; break;
} }
} }