Ejemplo n.º 1
0
int walkActor(character *actor, int dx, int dy) {
	int currentDx = -1, currentDy = -1;
	
	if (!isPositionWalkable(dx, dy)) {
		printf("Invalid pathing destination: %i, %i\n", dx, dy);
		
		return 0;
	}
	
	if (TCOD_path_size(actor->path)) {
		TCOD_path_get_destination(actor->path, &currentDx, &currentDy);
		
		if (dx == currentDx && dy == currentDy) {
			return 1;
		}
	}
	
	if (!TCOD_path_compute(actor->path, actor->x, actor->y, dx, dy)) {
		//printf("Invalid path!\n");

		return 0;
	}

	return 1;
}
Ejemplo n.º 2
0
TCOD_path_t map_computepath(point *origin, point *dest)
{
	//printf("origin %f, %f\n", origin->x, origin->y);
	//printf("dest %f, %f\n", dest->x, dest->y);
	// diagonal cost is sqrt(2)
	TCOD_path_t path = TCOD_path_new_using_map(tcod_map, 1.41f);
	TCOD_path_compute(path, origin->x, origin->y, dest->x, dest->y);

	/*
	bool is_possible = TCOD_path_compute(path, origin->x, origin->y, dest->x, dest->y);
	printf("is_possible: %d\n", is_possible);
	printf("path steps: %d\n", TCOD_path_size(path));
	for (int i = 0; i < TCOD_path_size(path); ++i) {
		int x, y;
		TCOD_path_get(path, i, &x, &y);
		printf("step %d: %d, %d\n", i + 1, x, y);
	}
	*/
	return path;
}
Ejemplo n.º 3
0
bool TCOD_path_walk(TCOD_path_t p, int *x, int *y, bool recalculate_when_needed) {
	int newx,newy;
	float can_walk;
	int d;
	TCOD_path_data_t *path=(TCOD_path_data_t *)p;
	TCOD_IFNOT(p != NULL) return false;
	if ( TCOD_path_is_empty(path) ) return false;
	d=(int)(uintptr)TCOD_list_pop(path->path);
	newx=path->ox + dirx[d];
	newy=path->oy + diry[d];
	/* check if the path is still valid */
	can_walk = TCOD_path_walk_cost(path,path->ox,path->oy,newx,newy);
	if ( can_walk == 0.0f ) {
		if (! recalculate_when_needed ) return false; /* don't walk */
		/* calculate a new path */
		if (! TCOD_path_compute(path, path->ox,path->oy, path->dx,path->dy) ) return false ; /* cannot find a new path */
		return TCOD_path_walk(p,x,y,true); /* walk along the new path */
	}
	if ( x ) *x=newx;
	if ( y ) *y=newy;
	path->ox=newx;
	path->oy=newy;
	return true;
}
Ejemplo n.º 4
0
bool TCODPath::compute(int ox, int oy, int dx, int dy) {
	return TCOD_path_compute(data,ox,oy,dx,dy) != 0;
}