Example #1
0
/*!
\author Luxor
*/
void cChar::follow( pChar pc )
{
	if ( isFrozen() ) {
		if ( hasPath() )
			safedelete( path );
		return;
	}
	if ( dist( getBody()->getPosition(), pc->getBody()->getPosition() ) <= 1.0 ) { // Target reached
		if ( hasPath() )
			safedelete( path );
		facexy( pc->getBody()->getPosition().x, pc->getBody()->getPosition().y );
		return;
	}
	if ( !hasPath() || path->targetReached() ) { // We haven't got a right path, call the pathfinding.
		pathFind( pc->getBody()->getPosition(), true );
		walkNextStep();
		return;
	}

	double distance = dist( path->getFinalPos(), pc->getBody()->getPosition() );
	if ( distance <= 3.0 ) { // Path finalPos is pretty near... let's not overhead the processor
		walkNextStep();
	} else { // Path finalPos is too far, call the pathfinding.
		pathFind( pc->getBody()->getPosition(), true );
		walkNextStep();
	}
}
Example #2
0
bool RenderSVGShape::isEmpty() const
{
    // This function should never be called before assigning a new Path to m_path.
    // But this bug can happen if this renderer was created and its layout was not
    // done before painting. Assert this did not happen but do not crash.
    ASSERT(hasPath());
    return !hasPath() || path().isEmpty();
}
Example #3
0
 bool hasPath(TreeNode *root, int sum) {
     if (root) {
         sum -= root->val;
         if (!root->left && !root->right && sum == 0) {
             return true;
         } else if (!root->left && !root->right && sum != 0) {
             return false;
         }
         return hasPath(root->left, sum) || hasPath(root->right, sum);
     }
     return false;
 }
Example #4
0
/**
 * @brief Returns the path from the path key
 * 
 * @param pathKey The key of the path to be found
 * @return Path from the path key
 */
string PathManager::getPath(string pathKey){
	if(hasPath(pathKey)){
		return this->m_paths[pathKey];
	} else {
		throw KeyNotFoundException(pathKey);
	}
}
Example #5
0
std::string URL::path() const
{
    if (hasPath())
        return _buf.substr(_parser.field_data[UF_PATH].off,
                           _parser.field_data[UF_PATH].len);
    return std::string();
}
Example #6
0
/*!
\author Luxor
*/
void cChar::walkNextStep()
{
	if ( isFrozen() )
		return;
	if ( !hasPath() )
		return;
	if ( !path->pathFound() )
		path->exec();

	sLocation pos = path->getNextPos();

	if ( pos == getPosition() )
		return;

	if ( isWalkable( pos, WALKFLAG_DYNAMIC|WALKFLAG_CHARS, this ) == illegal_z ) {
                safedelete( path );
		return;
	}


	pCreatureInfo creature = creatures.getCreature( getId() );
	if( creature!=NULL ) {
		if( creature->canFly() && ( fly_steps>0 ) )
			if ( chance( 20 ) )
				playAction( 0x13 ); // Flying animation
	}

	uint8_t dirXY = getDirFromXY(pos);
	dir = dirXY & 0x07;
	MoveTo( pos );
	sendToPlayers( this, dirXY );
	setNpcMoveTime();
}
Example #7
0
int env(int argc, char **argv) {
  char epath[PATH_MAX + 1];
  char *oldpath = getenv("PATH");

  assert(oldpath);

  if (!getExecutablePath(epath, sizeof(epath)))
    exit(EXIT_FAILURE);

  if (argc <= 1) {
    const std::string &pname = getParentProcessName();

    if (pname == "csh" || pname == "tcsh") {
      std::cerr << std::endl << "you are invoking this program from a C shell, "
                << std::endl << "please use " << std::endl << std::endl
                << "setenv PATH `" << epath << "/osxcross-env -v=PATH`"
                << std::endl << std::endl << "instead." << std::endl
                << std::endl;
    }
  }

  std::vector<std::string> path;
  std::map<std::string, std::string> vars;

  splitPath(oldpath, path);

  if (!hasPath(path, epath))
    path.push_back(epath);

  vars["PATH"] = joinPath(path);

  auto printVariable = [&](const std::string & var)->bool {
    auto it = vars.find(var);
    if (it == vars.end()) {
      std::cerr << "unknown variable '" << var << "'" << std::endl;
      return false;
    }
    std::cout << it->second << std::endl;
    return true;
  };

  if (argc <= 1) {
    std::cout << std::endl;
    for (auto &v : vars) {
      std::cout << "export " << v.first << "=";
      if (!printVariable(v.first))
        return 1;
      std::cout << std::endl;
    }
  } else {
    if (strncmp(argv[1], "-v=", 3))
      return 1;

    const char *var = argv[1] + 3;
    return static_cast<int>(printVariable(var));
  }

  return 0;
}
Example #8
0
void URL::updatePath(const std::string& path)
{
    if (!hasPath())
        throw std::runtime_error("Cannot update invalid URL");        

    std::string tmp(str());
    util::replaceInPlace(tmp, this->path(), path);
    parse(tmp);
}
Example #9
0
int main()
{
	int n, m, from, to;
	std::vector<std::vector<int> > c;
	std::vector<std::vector<int> > f;
	std::vector<int> p;

	scanf("%d %d", &n, &m);
	scanf("%d %d", &from, &to);

	from--;
	to--;

	c.resize(n, std::vector<int>(n, 0));
	f.resize(n, std::vector<int>(n, 0));
	p.resize(n, -1);

	for (int i = 0; i < m; i++)
	{
		int start, end, cost;

		scanf("%d %d %d", &start, &end, &cost);

		start--;
		end--;

		c[start][end] = cost;
	}

	int path;

	while ((path = hasPath(c, f, p, from, to)) > 0)
	{
		int cur = to;
		int prev = p[to];

		while (prev != -1)
		{
			f[prev][cur] += path;
			f[cur][prev] = -f[prev][cur];
			cur = prev;
			prev = p[cur];
		}

		p.assign(n, -1);
	}

	int sum = 0;

	for (int i = 0; i < n; i++)
		sum += f[from][i];

	printf("%d\n", sum);

	return 0;
}
Example #10
0
File: BFS.cpp Project: dylqt/huawei
vector<int> BreadthFirstSearch::pathTo(int v) {
	vector<int> links;
	if (hasPath(v)) {
		for (int tmp = v; tmp != s; tmp = edgeTo[tmp]) {
			links.push_back(tmp);
		}
		links.push_back(s);
	}
	reverse(links.begin(), links.end());
	return links;
}
Example #11
0
bool RenderSVGRect::shapeDependentStrokeContains(const FloatPoint& point)
{
    // The optimized contains code below does not support non-smooth strokes so we need
    // to fall back to RenderSVGShape::shapeDependentStrokeContains in these cases.
    if (m_usePathFallback || !hasSmoothStroke()) {
        if (!hasPath())
            RenderSVGShape::updateShapeFromElement();
        return RenderSVGShape::shapeDependentStrokeContains(point);
    }

    return m_outerStrokeRect.contains(point, FloatRect::InsideOrOnStroke) && !m_innerStrokeRect.contains(point, FloatRect::InsideButNotOnStroke);
}
Example #12
0
    void LocationModel::toJson(Json::Value &node)
    {
        if(mSources.size() > 0)
            node[LocationModel::SOURCE_ATTRIBUTE] = JsonUtils::toJson(mSources);

        if(mDestinations.size() > 0)
            node[LocationModel::DESTINATION_ATTRIBUTE] = JsonUtils::toJson(mDestinations);

        if(INVALID_ID != mAttachedAgent)
            node[LocationModel::ATTACHED_AGENT_ATTRIBUTE] = JsonUtils::toJson(mAttachedAgent);

        if(hasPath())
            node[LocationModel::PATH_ATTRIBUTE] = JsonUtils::toJson(mPath);

        serializeTags(node);
    }
bool LayoutSVGEllipse::shapeDependentStrokeContains(const FloatPoint& point)
{
    // The optimized check below for circles does not support non-scaling or
    // discontinuous strokes.
    if (m_usePathFallback
        || !hasContinuousStroke()
        || m_radii.width() != m_radii.height()) {
        if (!hasPath())
            createPath();
        return LayoutSVGShape::shapeDependentStrokeContains(point);
    }

    const FloatPoint center = FloatPoint(m_center.x() - point.x(), m_center.y() - point.y());
    const float halfStrokeWidth = strokeWidth() / 2;
    const float r = m_radii.width();
    return std::abs(center.length() - r) <= halfStrokeWidth;
}
bool LayoutSVGRect::shapeDependentStrokeContains(const FloatPoint& point)
{
    // The optimized code below does not support non-simple strokes so we need
    // to fall back to LayoutSVGShape::shapeDependentStrokeContains in these cases.
    if (m_usePathFallback || !definitelyHasSimpleStroke()) {
        if (!hasPath())
            LayoutSVGShape::updateShapeFromElement();
        return LayoutSVGShape::shapeDependentStrokeContains(point);
    }

    const float halfStrokeWidth = strokeWidth() / 2;
    const float halfWidth = m_fillBoundingBox.width() / 2;
    const float halfHeight = m_fillBoundingBox.height() / 2;

    const FloatPoint fillBoundingBoxCenter = FloatPoint(m_fillBoundingBox.x() + halfWidth, m_fillBoundingBox.y() + halfHeight);
    const float absDeltaX = std::abs(point.x() - fillBoundingBoxCenter.x());
    const float absDeltaY = std::abs(point.y() - fillBoundingBoxCenter.y());

    if (!(absDeltaX <= halfWidth + halfStrokeWidth && absDeltaY <= halfHeight + halfStrokeWidth))
        return false;

    return (halfWidth - halfStrokeWidth <= absDeltaX)
           || (halfHeight - halfStrokeWidth <= absDeltaY);
}
Example #15
0
bool RenderSVGEllipse::shapeDependentStrokeContains(const FloatPoint& point)
{
    // The optimized contains code below does not support non-smooth strokes so we need
    // to fall back to RenderSVGShape::shapeDependentStrokeContains in these cases.
    if (m_usePathFallback || !hasSmoothStroke()) {
        if (!hasPath())
            RenderSVGShape::updateShapeFromElement();
        return RenderSVGShape::shapeDependentStrokeContains(point);
    }

    float halfStrokeWidth = strokeWidth() / 2;
    FloatPoint center = FloatPoint(m_center.x() - point.x(), m_center.y() - point.y());

    // This works by checking if the point satisfies the ellipse equation,
    // (x/rX)^2 + (y/rY)^2 <= 1, for the outer but not the inner stroke.
    float xrXOuter = center.x() / (m_radii.width() + halfStrokeWidth);
    float yrYOuter = center.y() / (m_radii.height() + halfStrokeWidth);
    if (xrXOuter * xrXOuter + yrYOuter * yrYOuter > 1.0)
        return false;

    float xrXInner = center.x() / (m_radii.width() - halfStrokeWidth);
    float yrYInner = center.y() / (m_radii.height() - halfStrokeWidth);
    return xrXInner * xrXInner + yrYInner * yrYInner >= 1.0;
}
Example #16
0
/*!
\author Luxor
\brief Calls the pathfinding algorithm and creates a new path
*/
void cChar::pathFind( sLocation pos, bool bOverrideCurrentPath )
{
	if ( hasPath() ) {
		if ( bOverrideCurrentPath )
			safedelete( path );
		else
			return;
	}

        bool bOk = true;
	sLocation loc = pos;
	if ( isWalkable( pos, WALKFLAG_ALL, this ) == illegal_z ) { // If it isn't walkable, we can only reach the nearest tile
		bOk = false;
		for ( uint32_t i = 1; i < 4; i++ ) {
                        // East
			loc = sLocation( pos.x + i, pos.y, pos.z );
			if ( isWalkable( loc, WALKFLAG_ALL, this ) != illegal_z ) {
				bOk = true;
				break;
			}

			// West
			loc = sLocation( pos.x - i, pos.y, pos.z );
			if ( isWalkable( loc, WALKFLAG_ALL, this ) != illegal_z ) {
				bOk = true;
				break;
			}

			// South
			loc = sLocation( pos.x, pos.y + i, pos.z );
			if ( isWalkable( loc, WALKFLAG_ALL, this ) != illegal_z ) {
				bOk = true;
				break;
			}

			// North
			loc = sLocation( pos.x, pos.y - i, pos.z );
			if ( isWalkable( loc, WALKFLAG_ALL, this ) != illegal_z ) {
				bOk = true;
				break;
			}

			// North-East
			loc = sLocation( pos.x + i, pos.y - i, pos.z );
			if ( isWalkable( loc, WALKFLAG_ALL, this ) != illegal_z ) {
				bOk = true;
				break;
			}

			// North-West
			loc = sLocation( pos.x - i, pos.y - i, pos.z );
			if ( isWalkable( loc, WALKFLAG_ALL, this ) != illegal_z ) {
				bOk = true;
				break;
			}

			// South-East
			loc = sLocation( pos.x + i, pos.y + i, pos.z );
			if ( isWalkable( loc, WALKFLAG_ALL, this ) != illegal_z ) {
				bOk = true;
				break;
			}

			// South-West
			loc = sLocation( pos.x - i, pos.y + i, pos.z );
			if ( isWalkable( loc, WALKFLAG_ALL, this ) != illegal_z ) {
				bOk = true;
				break;
			}
		}
	}

        if ( bOk )
		path = new cPath( getPosition(), loc, this );
}
Example #17
0
std::string UrlObject::path() const {
  if (hasPath())
    return _buf.substr(_handle.field_data[UF_PATH].off, _handle.field_data[UF_PATH].len);
  return std::string("/");
}
Example #18
0
 bool hasPathSum(TreeNode *root, int sum) {
     if (root) {
         return hasPath(root, sum);
     }
     return false;
 }
Example #19
0
char *wb_nrep::nameName(const char *n, int ntype, char *res)
{
  static char result[512];
  int colon_added = 0;

  if ( !res)
    res = result;
  if ( ntype & cdh_mName_volume && ntype & cdh_mName_object)
    ntype |= cdh_mName_path;
  if ( ntype & cdh_mName_path && ntype & cdh_mName_attribute)
    ntype |= cdh_mName_object;
  if ( ntype & cdh_mName_volume && ntype & cdh_mName_attribute)
    ntype = ntype | cdh_mName_path | cdh_mName_object;
  strcpy( res, "");

  if ( ntype & cdh_mName_idString) {
#if 0
    if ( ntype & cdh_mName_volume) printf( "wname: volume\n");
    if ( ntype & cdh_mName_object) printf( "wname: object\n");
    if ( ntype & cdh_mName_attribute) printf( "wname: attribute\n");
#endif
    if ( !(ntype & cdh_mName_attribute)) {
      if ( ntype & cdh_mName_volume && !(ntype & cdh_mName_object))
        strcat( res, "_V");
      else if ( !(ntype & cdh_mName_volume))
        strcat( res, "_X");
      else
        strcat( res, "_O");
    }
    else
      strcat( res, "_A");
  }
  if ( ntype & cdh_mName_volume)
    volumeName( n, res + strlen(res));
  else if ( ntype & cdh_mName_ref)
    volumeName( n, res + strlen(res));
  if ( ntype & cdh_mName_path) {
    if ( ntype & cdh_mName_volume && hasVolume()) {
      strcat( res, ":");
      colon_added = 1;
    }
    pathName( n, res + strlen(res));
  }
  if ( ntype & cdh_mName_object) {
    if ( ntype & cdh_mName_path && hasPath())
      strcat( res, "-");
    else if ( ntype & cdh_mName_volume && !hasPath() && hasVolume() && !colon_added)
      strcat( res, ":");
    objectName( n, res + strlen(res));
  }
  if ( ntype & cdh_mName_attribute && hasAttribute()) {
    if ( !m_hasSuper || m_shadowed || ntype & cdh_mName_trueAttr) {
      strcat( res, ".");
      strcat( res, n + attr[0].offs);
    }
    else {
      for ( int i = 0; i < num_attr; i++) {
	if ( !attr[i].isSuper) {
	  strcat( res, ".");
	  int l = strlen(res);
	  strncat( res, n + attr[i].offs, attr[i].len);
	  if ( attr[i].index != -1)
	    sprintf( &res[ l + attr[i].len], "[%d]", attr[i].index);
	  else
	  res[ l + attr[i].len] = 0;
	}
      }
    }
  }
  return res;
}
Example #20
0
void EntityCreature::updatePlayerActionState() 
{
        hasAttacked = getCanWalk();
        float f = 16;
        if(playerToAttack == null)
        {
            playerToAttack = findPlayerToAttack();
            if(playerToAttack != null)
            {
                pathToEntity = worldObj.getPathToEntity(this, playerToAttack, f);
            }
        } else
        if(!playerToAttack.isEntityAlive())
        {
            playerToAttack = null;
        } else
        {
            float f1 = playerToAttack.getDistanceToEntity(this);
            if(canEntityBeSeen(playerToAttack))
            {
                attackEntity(playerToAttack, f1);
            }
        }
        if(!hasAttacked && playerToAttack != null && (pathToEntity == null || rand.nextInt(20) == 0))
        {
            pathToEntity = worldObj.getPathToEntity(this, playerToAttack, f);
        } else
        if(!hasAttacked && (pathToEntity == null && rand.nextInt(80) == 0 || rand.nextInt(80) == 0))
        {
            boolean flag = false;
            int j = -1;
            int k = -1;
            int l = -1;
            float f2 = -99999;
            for(int i1 = 0; i1 < 10; i1++)
            {
                int j1 = MathHelper.floor_double((posX + (double)rand.nextInt(13)) - 6);
                int k1 = MathHelper.floor_double((posY + (double)rand.nextInt(7)) - 3);
                int l1 = MathHelper.floor_double((posZ + (double)rand.nextInt(13)) - 6);
                float f3 = getBlockPathWeight(j1, k1, l1);
                if(f3 > f2)
                {
                    f2 = f3;
                    j = j1;
                    k = k1;
                    l = l1;
                    flag = true;
                }
            }

            if(flag)
            {
                pathToEntity = worldObj.getEntityPathToXYZ(this, j, k, l, 10);
            }
        }
        int i = MathHelper.floor_double(boundingBox.minY + 0.5);
        boolean flag1 = func_27013_ag();
        boolean flag2 = handleLavaMovement();
        rotationPitch = 0.0F;
        if(pathToEntity == null || rand.nextInt(100) == 0)
        {
            super.updatePlayerActionState();
            pathToEntity = null;
            return;
        }
        Vec3 vec3d = pathToEntity.getPosition(this);
        for(double d = width * 2.0F; vec3d != null && vec3d.squareDistanceTo(posX, vec3d.yCoord, posZ) < d * d;)
        {
            pathToEntity.incrementPathIndex();
            if(pathToEntity.isFinished())
            {
                vec3d = null;
                pathToEntity = null;
            } else
            {
                vec3d = pathToEntity.getPosition(this);
            }
        }

        isJumping = false;
        if(vec3d != null)
        {
            double d1 = vec3d.xCoord - posX;
            double d2 = vec3d.zCoord - posZ;
            double d3 = vec3d.yCoord - (double)i;
            float f4 = (float)((Math.atan2(d2, d1) * 180) / 3.1415927410125732) - 90;
            float f5 = f4 - rotationYaw;
            moveForward = moveSpeed;
            for(; f5 < -180; f5 += 360) { }
            for(; f5 >= 180; f5 -= 360) { }
            if(f5 > 30)
            {
                f5 = 30;
            }
            if(f5 < -30)
            {
                f5 = -30;
            }
            rotationYaw += f5;
            if(hasAttacked && playerToAttack != null)
            {
                double d4 = playerToAttack.posX - posX;
                double d5 = playerToAttack.posZ - posZ;
                float f7 = rotationYaw;
                rotationYaw = (float)((Math.atan2(d5, d4) * 180) / 3.1415927410125732) - 90;
                float f6 = (((f7 - rotationYaw) + 90) * 3.141593) / 180;
                moveStrafing = -MathHelper.sin(f6) * moveForward * 1.0F;
                moveForward = MathHelper.cos(f6) * moveForward * 1.0F;
            }
            if(d3 > 0.0D)
            {
                isJumping = true;
            }
        }
        if(playerToAttack != null)
        {
            faceEntity(playerToAttack, 30, 30);
        }
        if(isCollidedHorizontally && !hasPath())
        {
            isJumping = true;
        }
        if(rand.nextFloat() < 0.8 && (flag1 || flag2))
        {
            isJumping = true;
        }
}