2015-12-03 00:37:37 +00:00
|
|
|
#include "map_helper.h"
|
|
|
|
#include "log.h"
|
|
|
|
|
|
|
|
namespace Util {
|
|
|
|
void SpriteCreationArea::setRects(const SDL_Rect & allowed, const SDL_Rect & denied) {
|
|
|
|
validRects = std::make_pair<SDL_Rect, SDL_Rect>(allowed, denied);
|
2015-12-03 00:38:22 +00:00
|
|
|
onScreen = denied;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SpriteCreationArea::isOnScreen(const Vector3D & p) {
|
|
|
|
/* INFO << p.x << " " << p.y << " " << p.z << std::endl;
|
|
|
|
INFO << onScreen.x <<", " << onScreen.y << " -> " <<
|
|
|
|
onScreen.x + onScreen.w << ", " << onScreen.y + onScreen.h << std::endl;
|
|
|
|
*/
|
|
|
|
if ((p.x >= onScreen.x) && (p.x <= onScreen.x + onScreen.w) &&
|
|
|
|
(p.z >= onScreen.y) && (p.z <= onScreen.y + onScreen.h))
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SpriteCreationArea::isOffScreen(const Vector3D & p) {
|
|
|
|
return false;
|
2015-12-03 00:37:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TupleOfUint8 SpriteCreationArea::getValidCoord() {
|
|
|
|
uint32_t x = rnd.nextUint(validRects.first.w) + validRects.first.x;
|
|
|
|
uint32_t y = rnd.nextUint(validRects.first.h) + validRects.first.y;
|
|
|
|
return std::make_pair<uint8_t, uint8_t>(x, y);
|
|
|
|
}
|
2015-12-03 00:38:22 +00:00
|
|
|
|
|
|
|
int item_count(MapOfPair2Int & m, int a, int b) {
|
|
|
|
MapOfPair2Int::iterator j = m.find( std::make_pair<int, int>(a, b) );
|
|
|
|
if (j == m.end())
|
|
|
|
return 0;
|
|
|
|
return j->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
void register_item1(MapOfPair2Int & m, int a, int b) {
|
|
|
|
m.insert( std::make_pair< Pair2Int, int>(
|
|
|
|
std::make_pair<int, int>(a, b),
|
|
|
|
1)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void register_item(MapOfPair2Int & m, int a, int b) {
|
|
|
|
Pair2Int _p(std::make_pair<int, int>(a, b));
|
|
|
|
MapOfPair2Int::iterator j = m.find(_p);
|
|
|
|
if (j == m.end())
|
|
|
|
register_item1(m, a, b);
|
|
|
|
else
|
|
|
|
j->second++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-03 00:37:37 +00:00
|
|
|
}
|