Exemplo n.º 1
0
void destroy_map()
{
	int i;
#ifdef EXTRA_DEBUG
	ERR();
#endif

	have_a_map = 0;

	clear_bbox_tree(main_bbox_tree);
	//kill the tile and height map
	if(tile_map)
	{
		free (tile_map);
		tile_map = NULL;
	}
	memset(tile_list,0,sizeof(tile_list));
	tile_map_size_x = tile_map_size_y = 0;

	if(height_map)
	{
		free (height_map);
		height_map = NULL;
	}

#ifndef MAP_EDITOR2
	///kill the pathfinding tile map
	if(pf_tile_map)
	{
		free(pf_tile_map);
		pf_tile_map = NULL;

		if (pf_follow_path)
			pf_destroy_path();
	}
#endif

	//kill the 3d objects links
	destroy_all_3d_objects();

	//kill the 2d objects links
	destroy_all_2d_objects();

	//kill the lights links
	for(i=0;i<MAX_LIGHTS;i++)
		{
			if(lights_list[i])
				{
					free(lights_list[i]);
					lights_list[i]= NULL;	//kill any refference to it
				}
		}
	num_lights= 0;

#ifdef CLUSTER_INSIDES
	destroy_clusters_array ();
#endif
}
Exemplo n.º 2
0
int pf_find_path(int x, int y)
{
	actor *me;
	int i;
	int attempts= 0;

	pf_destroy_path();

	me = get_our_actor();
	if (!me)
		return -1;

	pf_src_tile = pf_get_tile(me->x_tile_pos, me->y_tile_pos);
	pf_dst_tile = pf_get_tile(x, y);

	if (!pf_dst_tile || pf_dst_tile->z == 0)
		return 0;

	for (i = 0; i < tile_map_size_x*tile_map_size_y*6*6; i++)
	{
		pf_tile_map[i].state = PF_STATE_NONE;
		pf_tile_map[i].parent = NULL;
	}

	pf_open.tiles = calloc(tile_map_size_x*tile_map_size_y*6*6, sizeof(PF_TILE*));
	pf_open.count = 0;

	pf_add_tile_to_open_list(NULL, pf_src_tile);

	while ((pf_cur_tile = pf_get_next_open_tile()) && attempts++ < MAX_PATHFINDER_ATTEMPTS)
	{
		if (pf_cur_tile == pf_dst_tile)
		{
			pf_follow_path = 1;

			pf_movement_timer_callback(0, NULL);
			pf_movement_timer = SDL_AddTimer(me->step_duration * 10,
				pf_movement_timer_callback, NULL);
			break;
		}

		pf_add_tile_to_open_list(pf_cur_tile, pf_get_tile(pf_cur_tile->x,   pf_cur_tile->y+1));
		pf_add_tile_to_open_list(pf_cur_tile, pf_get_tile(pf_cur_tile->x+1, pf_cur_tile->y+1));
		pf_add_tile_to_open_list(pf_cur_tile, pf_get_tile(pf_cur_tile->x+1, pf_cur_tile->y));
		pf_add_tile_to_open_list(pf_cur_tile, pf_get_tile(pf_cur_tile->x+1, pf_cur_tile->y-1));
		pf_add_tile_to_open_list(pf_cur_tile, pf_get_tile(pf_cur_tile->x,   pf_cur_tile->y-1));
		pf_add_tile_to_open_list(pf_cur_tile, pf_get_tile(pf_cur_tile->x-1, pf_cur_tile->y-1));
		pf_add_tile_to_open_list(pf_cur_tile, pf_get_tile(pf_cur_tile->x-1, pf_cur_tile->y));
		pf_add_tile_to_open_list(pf_cur_tile, pf_get_tile(pf_cur_tile->x-1, pf_cur_tile->y+1));
	}

	free(pf_open.tiles);

	return pf_follow_path;
}
Exemplo n.º 3
0
void pf_move()
{
	int x, y;
	actor *me;

	if (!pf_follow_path || !(me = get_our_actor())) {
		return;
	}

	x = me->x_tile_pos;
	y = me->y_tile_pos;

	if (PF_DIFF(x, pf_dst_tile->x) < 2 && PF_DIFF(y, pf_dst_tile->y) < 2) {
		pf_destroy_path();
	} else {
		PF_TILE *t = pf_get_tile(x, y);
		int i = 0, j = 0;

		for (pf_cur_tile = pf_dst_tile; pf_cur_tile; pf_cur_tile = pf_cur_tile->parent) {
			if (pf_cur_tile == t) {
				break;
			}
			i++;
		}

		if (pf_cur_tile == t) {
#ifdef	FUZZY_PATHS
			int	limit= i-(10+rand()%3);
#else	//FUZZY_PATHS
			int	limit= i-12;
#endif	//FUZZY_PATHS
			for (pf_cur_tile = pf_dst_tile; pf_cur_tile; pf_cur_tile = pf_cur_tile->parent) {
				if (j++ == limit) {
					break;
				}
			}
			if (pf_cur_tile) {
				Uint8 str[5];

				str[0] = MOVE_TO;
				*((short *)(str+1)) = SDL_SwapLE16((short)pf_cur_tile->x);
				*((short *)(str+3)) = SDL_SwapLE16((short)pf_cur_tile->y);
				my_tcp_send(my_socket, str, 5);

				return;
			}
		}

		for (pf_cur_tile = pf_dst_tile; pf_cur_tile; pf_cur_tile = pf_cur_tile->parent) {
			if (PF_DIFF(x, pf_cur_tile->x) <= 12 && PF_DIFF(y, pf_cur_tile->y) <= 12
			&& !pf_is_tile_occupied(pf_cur_tile->x, pf_cur_tile->y)) {
				Uint8 str[5];

				str[0] = MOVE_TO;
				*((short *)(str+1)) = SDL_SwapLE16((short)pf_cur_tile->x);
				*((short *)(str+3)) = SDL_SwapLE16((short)pf_cur_tile->y);
				my_tcp_send(my_socket, str, 5);
				break;
			}
		}
	}
}
Exemplo n.º 4
0
void move_self_forward()
{
	int i,x,y,rot,tx,ty;
	Uint8 str[10];

	for(i=0;i<max_actors;i++)
		{
			if(actors_list[i] && actors_list[i]->actor_id==yourself)
				{
					lock_actors_lists();
					x=actors_list[i]->x_tile_pos;
					y=actors_list[i]->y_tile_pos;
					rot=actors_list[i]->z_rot;
					rot=unwindAngle_Degrees(rot);
					switch(rot) {
					case 0:
						tx=x;
						ty=y+1;
						break;
					case 45:
						tx=x+1;
						ty=y+1;
						break;
					case 90:
						tx=x+1;
						ty=y;
						break;
					case 135:
						tx=x+1;
						ty=y-1;
						break;
					case 180:
						tx=x;
						ty=y-1;
						break;
					case 225:
						tx=x-1;
						ty=y-1;
						break;
					case 270:
						tx=x-1;
						ty=y;
						break;
					case 315:
						tx=x-1;
						ty=y+1;
						break;
					default:
						tx=x;
						ty=y;
					}

					//check to see if the coordinates are OUTSIDE the map
					if(ty<0 || tx<0 || tx>=tile_map_size_x*6 || ty>=tile_map_size_y*6)return;

					if (pf_follow_path) {
						pf_destroy_path();
					}

					str[0]=MOVE_TO;
					*((short *)(str+1))=tx;
					*((short *)(str+3))=ty;

					my_tcp_send(my_socket,str,5);
					unlock_actors_lists();
					return;
				}
		}
}