OpenGTA/util/map_helper.cpp

69 lines
1.6 KiB
C++
Raw Normal View History

2015-12-03 00:37:37 +00:00
#include "map_helper.h"
#include "log.h"
2018-09-23 05:57:34 +00:00
#include <cstdlib>
#include <iostream>
#include <ctime>
2015-12-03 00:37:37 +00:00
namespace Util {
2018-09-23 05:57:34 +00:00
SpriteCreationArea::SpriteCreationArea()
{
std::srand(unsigned(std::time(0)));
}
2015-12-03 00:37:37 +00:00
void SpriteCreationArea::setRects(const SDL_Rect & allowed, const SDL_Rect & denied) {
2018-09-14 15:42:44 +00:00
validRects = std::make_pair(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() {
2018-09-23 05:57:34 +00:00
uint32_t x = std::rand() % validRects.first.w + validRects.first.x;
uint32_t y = std::rand() % validRects.first.h + validRects.first.y;
2018-09-14 15:42:44 +00:00
return std::make_pair(x, y);
2015-12-03 00:37:37 +00:00
}
2015-12-03 00:38:22 +00:00
int item_count(MapOfPair2Int & m, int a, int b) {
2018-09-14 15:42:44 +00:00
const auto& j = m.find({a, b});
2015-12-03 00:38:22 +00:00
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>(
2018-09-14 15:42:44 +00:00
std::make_pair(a, b),
2015-12-03 00:38:22 +00:00
1)
);
}
void register_item(MapOfPair2Int & m, int a, int b) {
2018-09-14 15:42:44 +00:00
Pair2Int _p(std::make_pair(a, b));
2015-12-03 00:38:22 +00:00
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
}