/** ** Find new path. ** ** The destination could be a unit or a field. ** Range gives how far we must reach the goal. ** ** @note The destination could become negative coordinates! ** ** @param unit Path for this unit. ** ** @return >0 remaining path length, 0 wait for path, -1 ** reached goal, -2 can't reach the goal. */ static int NewPath(PathFinderInput &input, PathFinderOutput &output) { char *path = output.Path; int i = AStarFindPath(input.GetUnitPos(), input.GetGoalPos(), input.GetGoalSize().x, input.GetGoalSize().y, input.GetUnitSize().x, input.GetUnitSize().y, input.GetMinRange(), input.GetMaxRange(), path, PathFinderOutput::MAX_PATH_LENGTH, *input.GetUnit()); input.PathRacalculated(); if (i == PF_FAILED) { i = PF_UNREACHABLE; } // Update path if it was requested. Otherwise we may only want // to know if there exists a path. if (path != NULL) { output.Length = std::min<int>(i, PathFinderOutput::MAX_PATH_LENGTH); if (output.Length == 0) { ++output.Length; } } return i; }
/* virtual */ void COrder_Build::UpdatePathFinderData(PathFinderInput &input) { input.SetMinRange(this->Type->BoolFlag[BUILDEROUTSIDE_INDEX].value ? 1 : 0); input.SetMaxRange(this->Range); const Vec2i tileSize(this->Type->TileWidth, this->Type->TileHeight); input.SetGoal(this->goalPos, tileSize); }
/* virtual */ void COrder_Move::UpdatePathFinderData(PathFinderInput &input) { input.SetMinRange(0); input.SetMaxRange(this->Range); const Vec2i tileSize(0, 0); input.SetGoal(this->goalPos, tileSize); }
/* virtual */ void COrder_Build::UpdatePathFinderData(PathFinderInput &input) { input.SetMinRange(this->Type->BuilderOutside ? 1 : 0); input.SetMaxRange(this->Range); const Vec2i tileSize(this->Type->TileWidth, this->Type->TileHeight); input.SetGoal(this->goalPos, tileSize); }
/* virtual */ void COrder_Move::UpdatePathFinderData(PathFinderInput &input) { const Vec2i tileSize(0, 0); input.SetGoal(this->goalPos, tileSize); int distance = this->Range; if (GameSettings.Inside) { CheckObstaclesBetweenTiles(input.GetUnitPos(), this->HasGoal() ? this->GetGoal()->tilePos : this->goalPos, MapFieldRocks | MapFieldForest, &distance); } input.SetMaxRange(distance); input.SetMinRange(0); }
/* virtual */ void COrder_Board::UpdatePathFinderData(PathFinderInput &input) { input.SetMinRange(0); input.SetMaxRange(this->Range); Vec2i tileSize; if (this->HasGoal()) { CUnit *goal = this->GetGoal(); tileSize.x = goal->Type->TileWidth; tileSize.y = goal->Type->TileHeight; input.SetGoal(goal->tilePos, tileSize); } else { tileSize.x = 0; tileSize.y = 0; input.SetGoal(this->goalPos, tileSize); } }
/* virtual */ void COrder_Repair::UpdatePathFinderData(PathFinderInput &input) { const CUnit &unit = *input.GetUnit(); input.SetMinRange(0); input.SetMaxRange(ReparableTarget != NULL ? unit.Type->RepairRange : 0); Vec2i tileSize; if (ReparableTarget != NULL) { tileSize.x = ReparableTarget->Type->TileWidth; tileSize.y = ReparableTarget->Type->TileHeight; input.SetGoal(ReparableTarget->tilePos, tileSize); } else { tileSize.x = 0; tileSize.y = 0; input.SetGoal(this->goalPos, tileSize); } }
/* virtual */ void COrder_Follow::UpdatePathFinderData(PathFinderInput &input) { input.SetMinRange(0); input.SetMaxRange(this->Range); Vec2i tileSize; if (this->HasGoal()) { CUnit *goal = this->GetGoal(); tileSize.x = goal->Type->TileWidth; tileSize.y = goal->Type->TileHeight; //Wyrmgus start // input.SetGoal(goal->tilePos, tileSize); input.SetGoal(goal->tilePos, tileSize, goal->MapLayer); //Wyrmgus end } else { tileSize.x = 0; tileSize.y = 0; //Wyrmgus start // input.SetGoal(this->goalPos, tileSize); input.SetGoal(this->goalPos, tileSize, this->MapLayer); //Wyrmgus end } }