14 #include <torchcraft/client.h> 17 #include "debugging.h" 20 #include "unitsinfo.h" 30 inline unsigned int disthelper(
unsigned int dx,
unsigned int dy) {
36 dx = dx - dx / 16u + dy * 3u / 8u - dx / 64u + dy * 3u / 256u;
42 inline unsigned int pxdistance(
int px1,
int py1,
int px2,
int py2) {
43 unsigned int dx = std::abs(px1 - px2);
44 unsigned int dy = std::abs(py1 - py2);
49 inline float distance(
int x1,
int y1,
int x2,
int y2) {
50 unsigned int dx = std::abs(x1 - x2) * unsigned(tc::BW::XYPixelsPerWalktile);
51 unsigned int dy = std::abs(y1 - y2) * unsigned(tc::BW::XYPixelsPerWalktile);
52 return float(
disthelper(dx, dy)) / tc::BW::XYPixelsPerWalktile;
89 }
else if (yminB > ymaxA) {
94 }
else if (xminB > xmaxA) {
97 }
else if (yminB > ymaxA) {
100 return xminB - xmaxA;
102 }
else if (ymaxB < yminA) {
103 return yminA - ymaxB;
104 }
else if (yminB > ymaxA) {
105 return yminB - ymaxA;
124 return float(
pxDistanceBB(a, b)) / tc::BW::XYPixelsPerWalktile;
129 template <
typename T>
143 int(pb.
y * tc::BW::XYPixelsPerWalktile +
145 tc::BW::XYPixelsPerWalktile;
168 auto fdirX = px - ux;
169 auto fdirY = py - uy;
170 if (fdirX == 0 && fdirY == 0) {
174 auto c = std::cos(rad);
175 auto s = std::sin(rad);
176 auto dirX = fdirX * c - fdirY * s;
177 auto dirY = fdirX * s + fdirY * c;
178 if (!exact && dirX * dirX + dirY * dirY < 10) {
181 auto div = std::abs(dirX == 0 ? dirY : dirX);
182 dirX = dirX / div * 10;
183 dirY = dirY / div * 10;
186 utils::clamp(ux + (
int)dirX, 0, mx - 1),
187 utils::clamp(uy + (
int)dirY, 0, my - 1));
190 const State*
const state,
206 const State*
const state,
223 const State*
const state,
226 bool strict =
false) {
227 auto cx = utils::clamp(x, 1, state->
mapWidth() - 1);
228 auto cy = utils::clamp(y, 1, state->
mapHeight() - 1);
229 if (strict && (cx != x || cy != y)) {
236 const State*
const state,
238 bool strict =
false) {
243 auto ut = tc::BW::UnitType::_from_integral_nothrow(unit.
type);
245 return tc::BW::isWorker(*ut);
251 auto ut = tc::BW::UnitType::_from_integral_nothrow(unit.
type);
253 return tc::BW::isBuilding(*ut);
261 static_cast<bool (*)(tc::BW::UnitType)>(&tc::BW::isWorker));
280 if (prereq->isUnit()) {
299 }
else if (prereq->isUpgrade()) {
303 }
else if (prereq->isTech()) {
308 VLOG(2) <<
"Unknown prerequisite " <<
buildTypeString(prereq) <<
" for " Game state.
Definition: state.h:42
bool isWorker(tc::Unit const &unit)
Definition: gamemechanics.h:242
Position predictPosition(Unit const *unit, double frames)
Predict the position of a unit some frames into the future.
Definition: gamemechanics.h:149
std::vector< tc::Unit > getMineralFields(tc::State *state)
Definition: gamemechanics.h:264
int32_t pixel_x
Definition: frame.h:88
int mapHeight() const
Definition: state.h:84
Represents and holds information about buildable types (units, upgrades, techs).
Definition: buildtype.h:36
bool isBuildable(tc::State *state, int x, int y)
Definition: gamemechanics.h:270
int map_size[2]
Definition: state.h:61
bool isBuilding(tc::Unit const &unit)
Definition: gamemechanics.h:250
T y
Definition: basetypes.h:44
double constexpr kDegPerRad
Definition: basetypes.h:28
const BuildType * Zerg_Hive
Definition: buildtype.cpp:346
int32_t pixel_y
Definition: frame.h:88
UnitsInfo & unitsInfo()
Definition: state.h:116
int pxDistanceBB(int xminA, int yminA, int xmaxA, int ymaxA, int xminB, int yminB, int xmaxB, int ymaxB)
Distance between two bounding boxes, in pixels.
Definition: gamemechanics.h:77
std::vector< tc::Unit > getWorkers(tc::State *state)
Definition: gamemechanics.h:258
const BuildType * Zerg_Greater_Spire
Definition: buildtype.cpp:350
int32_t type
Definition: frame.h:87
Position getMovePosHelper(int ux, int uy, int px, int py, int mx, int my, double angle, bool exact)
Definition: gamemechanics.h:159
int dimensionLeft
Definition: buildtype.h:83
Represents a unit in the game.
Definition: unitsinfo.h:35
float distance(int x1, int y1, int x2, int y2)
Walktile distance.
Definition: gamemechanics.h:49
int player_id
Definition: state.h:69
const Units & myCompletedUnitsOfType(const BuildType *type)
Our completed units of a particular type (does not include dead units).
Definition: unitsinfo.cpp:238
int mapWidth() const
Definition: state.h:81
const BuildType * Zerg_Spire
Definition: buildtype.cpp:354
std::string buildTypeString(BuildType const *buildType)
Definition: algorithms.h:176
tc::Unit unit
A copy of the torchcraft unit data.
Definition: unitsinfo.h:81
const BuildType * Zerg_Lair
Definition: buildtype.cpp:345
int dimensionRight
Definition: buildtype.h:85
unsigned int pxdistance(int px1, int py1, int px2, int py2)
Pixel distance.
Definition: gamemechanics.h:42
int dimensionDown
Definition: buildtype.h:86
std::vector< tc::Unit > filterUnitsByType(std::vector< tc::Unit > const &units, tc::BW::UnitType type)
Definition: filter.h:26
Position getMovePos(const State *const state, const Unit *const u, Position p, double angle=0, bool exact=true)
Definition: gamemechanics.h:189
std::vector< const BuildType * > prerequisites
Definition: buildtype.h:43
int dimensionUp
Definition: buildtype.h:84
T x
Definition: basetypes.h:43
Main namespace for bot-related code.
Definition: areainfo.cpp:17
UpgradeLevel getUpgradeLevel(const BuildType *upgrade) const
Get the current level of a given upgrade.
Definition: state.cpp:99
std::vector< uint8_t > buildable_data
Definition: state.h:64
const BuildType * type
Definition: unitsinfo.h:56
bool prerequisitesReady(State *state, const BuildType *buildType)
Definition: gamemechanics.h:277
int x
Definition: unitsinfo.h:37
std::unordered_map< int32_t, std::vector< Unit > > units
Definition: state.h:116
bool hasResearched(const BuildType *tech) const
Check whether a given technology has been researched.
Definition: state.cpp:86
double velocityX
Definition: frame.h:97
int y
Definition: unitsinfo.h:38
int neutral_id
Definition: state.h:70
double velocityY
Definition: frame.h:97
Vec2T< int > Position
Definition: basetypes.h:178
unsigned int disthelper(unsigned int dx, unsigned int dy)
Approximation of Euclidian distance This is the same approximation that StarCraft's engine uses and t...
Definition: gamemechanics.h:30
Position clampPositionToMap(const State *const state, int const x, int const y, bool strict=false)
Definition: gamemechanics.h:222
float distanceBB(Unit const *a, Unit const *b)
Definition: gamemechanics.h:123
const BuildType * Zerg_Hatchery
Definition: buildtype.cpp:344