Example #1
0
bool VehicleInstance::dirWalkable(PathNode *p, int x, int y, int z) {

    if(!(walkable(x,y,z)))
        return false;

    uint32 dirStart = tileDir(p->tileX(),p->tileY(),p->tileZ());
    uint32 dirEnd = tileDir(x,y,z);
    if (dirStart == 0xFFFFFFFF || dirEnd == 0xFFFFFFFF)
        return true;

    if (((dirStart & 0xFF000000) != 0xFF000000)
        || ((dirEnd & 0xFF000000) != 0xFF000000))
        if ((dirStart & 0xFF000000) == (dirEnd & 0xFF000000))
                return true;
    if (((dirStart & 0x00FF0000) != 0x00FF0000)
        || ((dirEnd & 0x00FF0000) != 0x00FF0000))
        if ((dirStart & 0x00FF0000) == (dirEnd & 0x00FF0000))
                return true;
    if (((dirStart & 0x0000FF00) != 0x0000FF00)
        || ((dirEnd & 0x0000FF00) != 0x0000FF00))
        if ((dirStart & 0x0000FF00) == (dirEnd & 0x0000FF00))
                return true;
    if (((dirStart & 0x000000FF) != 0x000000FF)
        || ((dirEnd & 0x000000FF) != 0x000000FF))
        if ((dirStart & 0x000000FF) == (dirEnd & 0x000000FF))
                return true;

    return false;
}
Example #2
0
void JavaFrameAnchor::make_walkable(JavaThread* thread) {
  if (walkable()) return;
  // Eventually make an assert
  guarantee(Thread::current() == (Thread*)thread, "only current thread can flush its registers");
  // We always flush in case the profiler wants it but we won't mark
  // the windows as flushed unless we have a last_Java_frame
  intptr_t* sp = StubRoutines::Sparc::flush_callers_register_windows_func()();
  if (last_Java_sp() != NULL ) {
    capture_last_Java_pc(sp);
  }
}
Example #3
0
int wall_near(int i, int j)
{
	if(!walkable(i,j)) return 1;
	if(!walkable(i,j+1)) return 1;
	if(!walkable(i+1,j+1)) return 1;
	if(!walkable(i+1,j)) return 1;

	if(!walkable(i,j-1)) return 1;
	if(!walkable(i+1,j-1)) return 1;
	if(!walkable(i-1,j-1)) return 1;
	if(!walkable(i-1,j+1)) return 1;
	
	return 0;
}
Example #4
0
list *update(list *ol, elem e, location t, elem *np, int n)
{
	elem *nextElem = neighbours(e, np, n);
	for(int i = 0; i < n; i++)
	{
		//printPos(nextElem[i]);
		//nextElem[i].h = abs(nextElem[i].l.x - t.x) + abs(nextElem[i].l.y - t.y);	// Manhattan Distance
		nextElem[i].h = sqrt(pow((nextElem[i].l.x - t.x),2)+pow(nextElem[i].l.y - t.y,2));  //euclidean distance
		nextElem[i].g += np->g;
		if(walkable(nextElem[i].l))
			ol = append(ol, nextElem[i]);
	}
	
	return ol;
}
Example #5
0
void VehicleInstance::setDestinationV(Mission *m, int x, int y, int z, int ox,
                                       int oy, int new_speed)
{
    std::set < PathNode > open, closed;
    std::map < PathNode, PathNode > parent;

    m->adjXYZ(x, y, z);
    z = tile_z_;

    dest_path_.clear();
    setSpeed(0);

    if (map_ == -1 || health_ <= 0 || !(walkable(x, y, z)))
        return;

    if (!walkable(tile_x_, tile_y_, tile_z_)) {
        float dBest = 100000, dCur;
        int xBest,yBest;
        // we got somewhere we shouldn't, we need to find somewhere that is walkable
        for (int j = 0; j < 5; j++)
            for (int i = 0; i < 5; i++)
                if (walkable(tile_x_ + i, tile_y_ + j, tile_z_)) {
                    dCur = sqrt((float)(i*i + j*j));
                    if(dCur < dBest) {
                        xBest = tile_x_ + i;
                        yBest = tile_y_ + j;
                        dBest = dCur;
                    }
                }
        for (int j = 0; j < 5; j++)
            for (int i = 0; i > -5; --i)
                if (walkable(tile_x_ + i, tile_y_ + j, tile_z_)) {
                    dCur = sqrt((float)(i*i + j*j));
                    if(dCur < dBest) {
                        xBest = tile_x_ + i;
                        yBest = tile_y_ + j;
                        dBest = dCur;
                    }
                }
        for (int j = 0; j > -5; --j)
            for (int i = 0; i > -5; --i)
                if (walkable(tile_x_ + i, tile_y_ + j, tile_z_)) {
                    dCur = sqrt((float)(i*i + j*j));
                    if(dCur < dBest) {
                        xBest = tile_x_ + i;
                        yBest = tile_y_ + j;
                    }
                }
        for (int j = 0; j > -5; --j)
            for (int i = 0; i < 5; i++)
                if (walkable(tile_x_ + i, tile_y_ + j, tile_z_)) {
                    dCur = sqrt((float)(i*i + j*j));
                    if(dCur < dBest) {
                        xBest = tile_x_ + i;
                        yBest = tile_y_ + j;
                        dBest = dCur;
                    }
                }
        if(dBest == 100000)
            return;
        else {
            tile_x_ = xBest;
            tile_y_ = yBest;
        }
    }

    PathNode closest;
    float closest_dist = 100000;

    open.insert(PathNode(tile_x_, tile_y_, tile_z_, off_x_, off_y_));
    int watchDog = 1000;
    while (!open.empty()) {
        watchDog--;
        float dist = 100000;
        PathNode p;
        std::set < PathNode >::iterator pit;
        for (std::set < PathNode >::iterator it = open.begin();
             it != open.end(); it++) {
            float d =
                sqrt((float) (x - it->tileX()) * (x - it->tileX()) +
                     (y - it->tileY()) * (y - it->tileY()));
            if (d < dist) {
                dist = d;
                p = *it;
                pit = it;       // it cannot be const_iterator because of this assign
            }
        }
        if (dist < closest_dist) {
            closest = p;
            closest_dist = dist;
        }
        //printf("found best dist %f in %i nodes\n", dist, open.size());
        open.erase(pit);
        closed.insert(p);

        if ((p.tileX() == x && p.tileY() == y && p.tileZ() == z)
            || watchDog < 0) {
            if (watchDog < 0) {
                p = closest;
                dest_path_.
                    push_front(PathNode
                               (p.tileX(), p.tileY(), p.tileZ(), ox, oy));
            } else
                dest_path_.push_front(PathNode(x, y, z, ox, oy));
            while (parent.find(p) != parent.end()) {
                p = parent[p];
                if (p.tileX() == tile_x_ && p.tileY() == tile_y_
                    && p.tileZ() == tile_z_)
                    break;
                dest_path_.push_front(p);
            }
            break;
        }

        std::list < PathNode > neighbours;
        uint32 goodDir = tileDir(p.tileX(), p.tileY(), p.tileZ());

        if (p.tileX() > 0) {
            if (dirWalkable(&p,p.tileX() - 1, p.tileY(), p.tileZ())
                && ((goodDir & 0xFF000000) == 0x06000000 || goodDir == 0xFFFFFFFF))
                neighbours.
                    push_back(PathNode(p.tileX() - 1, p.tileY(), p.tileZ()));
        }

        if (p.tileX() < g_App.maps().map(map())->maxX()) {
            if (dirWalkable(&p,p.tileX() + 1, p.tileY(), p.tileZ())
                && ((goodDir & 0x0000FF00) == 0x00000200 || goodDir == 0xFFFFFFFF))
                neighbours.
                    push_back(PathNode(p.tileX() + 1, p.tileY(), p.tileZ()));
        }

        if (p.tileY() > 0)
            if (dirWalkable(&p,p.tileX(), p.tileY() - 1, p.tileZ())
                && ((goodDir & 0x00FF0000) == 0x00040000 || goodDir == 0xFFFFFFFF))
                neighbours.
                    push_back(PathNode(p.tileX(), p.tileY() - 1, p.tileZ()));

        if (p.tileY() < g_App.maps().map(map())->maxY())
            if (dirWalkable(&p,p.tileX(), p.tileY() + 1, p.tileZ())
                && ((goodDir & 0x000000FF) == 0x0 || goodDir == 0xFFFFFFFF))
                neighbours.
                    push_back(PathNode(p.tileX(), p.tileY() + 1, p.tileZ()));

        for (std::list < PathNode >::iterator it = neighbours.begin();
             it != neighbours.end(); it++)
            if (dirWalkable(&p,it->tileX(), it->tileY(), it->tileZ())
                && open.find(*it) == open.end()
                && closed.find(*it) == closed.end()) {
                parent[*it] = p;
                open.insert(*it);
            }
    }

    if(!dest_path_.empty()) {
        // Adjusting offsets for correct positioning
        speed_ = new_speed;
        for(std::list < PathNode >::iterator it = dest_path_.begin();
            it != dest_path_.end(); it++) {

            // TODO : requires testing for correct offsets per
            // every direction, because in some part of game
            // vehicle position on start of game can create incorrect
            // visual representation
            // maybe offsets depend on type or tileZ?
            switch(tileDir(it->tileX(), it->tileY(), it->tileZ())) {
                case 0xFFFFFF00:
                case 0xFFFF0200:
                    it->setOffX(200);
                    it->setOffY(32);
                    break;
                case 0xFF04FFFF:
                    it->setOffX(32);
                    it->setOffY(200);
                    break;
                case 0xFFFF02FF:
                case 0xFF0402FF:
                    it->setOffX(32);
                    it->setOffY(32);
                    break;
                case 0x06FFFFFF:
                case 0x0604FFFF:
                    it->setOffX(32);
                    it->setOffY(200);
                    break;
                case 0x06FFFF00:
                    it->setOffX(200);
                    it->setOffY(200);
                    break;
                default:
                    printf("hmm tileDir %X\n", (unsigned int)tileDir(it->tileX(), it->tileY(), it->tileZ()));
                    break;
            }

        }
    }
}