Skip to content

Commit

Permalink
Some safety measures for the pathfinding code
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrettin committed Jan 13, 2016
1 parent 28d3d52 commit 67e1923
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/include/unit_find.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@ class CUnitTypeFinder
bool operator()(const CUnit *const unit) const
{
const CUnitType &type = *unit->Type;
//Wyrmgus start
if (!&type) {
fprintf(stderr, "CUnitTypeFinder Error: Unit's type is NULL.\n");
return false;
}
//Wyrmgus end
if (type.BoolFlag[VANISHES_INDEX].value || (unitTypeType != static_cast<UnitTypeType>(-1) && type.UnitType != unitTypeType)) {
return false;
}
Expand Down
12 changes: 11 additions & 1 deletion src/pathfinder/astar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,12 @@ static int CostMoveToCallBack_Default(unsigned int index, const CUnit &unit)
*/
static inline int CostMoveTo(unsigned int index, const CUnit &unit)
{
//Wyrmgus start
if (!&unit) {
fprintf(stderr, "Error in CostMoveTo(unsigned int index, const CUnit &unit): Unit is NULL.\n");
return -1;
}
//Wyrmgus end
int *c = &CostMoveToCache[index];
if (*c != CacheNotSet) {
return *c;
Expand Down Expand Up @@ -1040,7 +1046,11 @@ int AStarFindPath(const Vec2i &startPos, const Vec2i &goalPos, int gw, int gh,

// Outside the map or can't be entered.
if (endPos.x < 0 || endPos.x + tilesizex - 1 >= AStarMapWidth
|| endPos.y < 0 || endPos.y + tilesizey - 1 >= AStarMapHeight) {
//Wyrmgus start
// || endPos.y < 0 || endPos.y + tilesizey - 1 >= AStarMapHeight) {
|| endPos.y < 0 || endPos.y + tilesizey - 1 >= AStarMapHeight
|| !Map.Info.IsPointOnMap(endPos)) {
//Wyrmgus end
continue;
}

Expand Down

0 comments on commit 67e1923

Please sign in to comment.