Пример #1
0
int is_abs_walkable(Entity** entities, int x, int y) {
    int walkable = is_walkable(entities[DIV(x)][DIV(y)]);
    if(MOD(x) != 0 && MOD(y) != 0)
        walkable = walkable && is_walkable(entities[DIV(x) + 1][DIV(y) + 1]);
    if(MOD(x) != 0)
        walkable = walkable && is_walkable(entities[DIV(x) + 1][DIV(y)]);
    if(MOD(y) != 0)
        walkable = walkable && is_walkable(entities[DIV(x)][DIV(y) + 1]);
    return walkable;
}
Пример #2
0
int neighbors(node &n)
{
	int nr = 0;
	node next;
	int i;
	for(i=0; i<4; ++i)
	{
		next.x = n.x + dirx[i];
		next.y = n.y + diry[i];
		if(is_walkable(1, &next))
			++nr;
	}
	return 0;
}
Пример #3
0
void playAggresive(bool &place, int32_t& movedir)
{
	place = 0;
	movedir = -1;

	int i, j;
	for(i=0; i<n; ++i)
		for(j=0; j<m; ++j)
			tempweights[i][j] = -100;
	queue<node> q;
	node current, next;

	current.x = enemyx;
	current.y = enemyy;
	current.weight = tempweights[current.x][current.y] = 0;
	q.push(current);

	while(!q.empty())
	{
		current = q.front();
		q.pop();

		for(i=0; i<4; ++i)
		{
			next.x = current.x + dirx[i];
			next.y = current.y + diry[i];
			next.weight = current.weight + 1; //use weights as distances mmmkay
			if(next.weight < 7 &&
			   is_walkable(current.weight, &next) && tempweights[next.x][next.y] == -100)
			{
				tempweights[next.x][next.y] = current.weight + 1;
				if(next.x == currentx && next.y == currenty)
				{
					break;
				}
				else {
					q.push(next);
				}
			}
		}
		if (i != 4)
			break;
	}

	for(i=0; i<4; ++i)
		if(tempweights[currentx + dirx[i]][currenty + diry[i]] == tempweights[currentx][currenty] - 1)
			movedir = i;

	++movedir;
}
Пример #4
0
/* Some generic air critter animation */
static void animate_aircritter(struct Critter *critter) {
    animate_flyer(&critter->flyer,critter->ship?1:0,&ship_list);
    if(critter->physics.hitground && is_walkable(Round(critter->physics.x),Round(critter->physics.y) + (critter->flyer.bat?1:-1))==0) {
        /* Flying critter is perched */
        critter->frame = critter->frames-1;
    } else {
        critter->frame++;
        if(critter->bidir) {
            if(critter->physics.vel.x>0) {
                if(critter->frame>=(critter->frames-1)/2)
                    critter->frame=0;
            } else {
                if(critter->frame>=critter->frames-1)
                    critter->frame=(critter->frames-1)/2;
            }
        } else {
            if(critter->frame>=critter->frames-1)
                critter->frame=0;
        }
    }
}
Пример #5
0
/* Find a random starting position. If ground=-+1, coordinates
 * will be at the interface of walkable terrain and the medium.
 * x and y will be set to the discovered coordinates.
 * Returns nonzero if no suitable coordinates were found.
 */
static int random_coords(Uint8 medium, int ground,float *xcoord,float *ycoord) {
    unsigned int loops=0;
    while(loops++<1000) {
        int x = rand()%lev_level.width;
        int y = rand()%lev_level.height;
        if(lev_level.solid[x][y]==medium) {
            if(ground) {
                int r=0;
                for(r=0;r<200;r++,y+=ground) {
                    if(y<0 || y>=lev_level.height ||
                            lev_level.solid[x][y]!=medium) break;
                }
                if(is_walkable(x,y)==0) continue;
            }
            *xcoord = x;
            *ycoord = y;
            return 0;
        }
    }
    return 1;
}
Пример #6
0
void constructRoutes(node* currentNode, node* parent, int &maxweight, int32_t &dir, int recursionlevel, int &depth)
{
	int weight = -120, i=-1, k;
	if(rootNode == NULL || rootNode->kids.empty())
	{
		initializeRoutes();
		return;
	}

	currentNode->parent = parent;
	tempweights[currentNode->x][currentNode->y] = 0;

	for(k=0; k<currentNode->kids.size(); ++k)
	{
		if(is_walkable(recursionlevel+1, currentNode->kids[k]) &&
		   currentNode->kids[k] != currentNode->parent&&
		   tempweights[currentNode->kids[k]->x][currentNode->kids[k]->y] == -100)
		{
			int32_t aux = (int32_t)i;
			constructRoutes(currentNode->kids[k], currentNode, weight, aux, recursionlevel+1, depth);

			weight += currentNode->weight;
			if(flameTimer[currentNode->x][currentNode->y])
				weight += BOMBRANGE;
			if(currentNode->x == enemyx && currentNode->y == enemyy)
				weight += ENEMYVALUE;
			tempweights[currentNode->x][currentNode->y] = weight;

			if(weight > maxweight)
			{
				maxweight = weight;
				dir = i;
				depth = recursionlevel + 1;
			}
		}
	}
}
Пример #7
0
void playNormal(bool &place, int32_t &movedir)
{
	int length, weight,i,j;
	movedir = -1;

	for(i=0; i<n; ++i)
		for(j=0; j<m; ++j)
			tempweights[i][j] = -100;
	constructRoutes(rootNode, NULL, weight, movedir, 1, length);
	printf("%d",length);
	if(length > 3)
	{
		place = length<=6;
		++movedir;
		return;
	}

	int maxweight = -1;
	j = movedir;
	node tempNode, currNode;
	place = 0;
	weight = 0;
	// euristica, n-as paria ca si mere dar fie...

	for(i=0; i<4; ++i)
	{
		currNode.x = rootNode->x + dirx[i];
		currNode.y = rootNode->y + diry[i];
		if(i!=j && is_walkable(1, &currNode) && tempweights[currNode.x][currNode.y] > maxweight)
		{
			maxweight = tempweights[currNode.x][currNode.y];
			movedir = i;
		}
	}
	++movedir;
}
Пример #8
0
Файл: game.c Проект: jdp/psionrl
/* Attempts to move, processes a turn */
void attempt_move(map_t* m, int newx, int newy) {
	if (is_walkable(m, newx, newy)) {
		move_player(newx, newy);
	}
}