Esempio n. 1
0
// Determines whether this AABB intersects another AABB
bool AABB::intersectsAABB(const AABB& box) const {
   const IAPoint &min2 = box.m_min, &max2 = box.m_max;

   // Check if x, y, and z planes are inside of the other AABB's x, y, and z planes
   return ((X_COORD(m_max) > X_COORD(min2)) && (X_COORD(m_min) < X_COORD(max2)) &&
           (Y_COORD(m_max) > Y_COORD(min2)) && (Y_COORD(m_min) < Y_COORD(max2)) &&
           (Z_COORD(m_max) > Z_COORD(min2)) && (Z_COORD(m_min) < Z_COORD(max2)));
}
Esempio n. 2
0
// Find an island entry
struct island_data *closest_island(int x, int y) {
	struct island_data *isle, *best = NULL;
	int b = USE_SIZE;

	for (isle = island_list; isle; isle = isle->next)
		if (compute_distance(X_COORD(isle->loc), Y_COORD(isle->loc), x, y) < b) {
			best = isle;
			b = compute_distance(X_COORD(isle->loc), Y_COORD(isle->loc), x, y);
		}

	return best;
}
Esempio n. 3
0
// overwrites the top and bottom edges of the map with tundra
void add_tundra(void) {
	int iter;
	
	// find edge tiles
	for (iter = 0; iter < USE_SIZE; ++iter) {
		if (Y_COORD(iter) < TUNDRA_HEIGHT + (!number(0, 2) ? 1 : 0)) {
			change_grid(iter, TUNDRA);
		}
		else if (Y_COORD(iter) >= (USE_HEIGHT - TUNDRA_HEIGHT - (!number(0, 2) ? 1 : 0))) {
			change_grid(iter, TUNDRA);
		}
	}
}
Esempio n. 4
0
/**
* Convert terrain from one thing to another near other terrain.
* 
* @param int from Terrain to convert from.
* @param int to Terrain to convert to.
* @param int near Terrain it must be near.
* @param int dist Distance it must be within.
*/
void replace_near(int from, int to, int near, int dist) {
	int x, y, hor, ver, at, loc;
	int found;
	
	for (x = 0; x < USE_WIDTH; ++x) {
		for (y = 0; y < USE_HEIGHT; ++y) {
			at = MAP(x, y);
			
			if (grid[at].type == from) {
				found = 0;
				for (hor = -dist; hor <= dist && !found; ++hor) {
					for (ver = -dist; ver <= dist && !found; ++ver) {
						loc = shift(at, hor, ver);
						
						if (loc != -1 && grid[loc].type == near && compute_distance(X_COORD(at), Y_COORD(at), X_COORD(loc), Y_COORD(loc)) <= dist) {
							change_grid(at, to);
							found = 1;
						}
					}
				}
			}
		}
	}
}
Esempio n. 5
0
// This takes an initial point 'origin' and translates it by x,y
// may return -1 if no valid location
inline int shift(int origin, int x_shift, int y_shift) {
	int loc = origin, y_coord, x_coord;
	
	// sanity
	if (loc < 0 || loc >= USE_SIZE) {
		return -1;
	}
	
	x_coord = X_COORD(loc);
	y_coord = Y_COORD(loc);

	// handle X
	if (x_coord + x_shift < 0) {
		if (USE_WRAP_X) {
			loc += x_shift + USE_WIDTH;
		}
		else {
			// off the left side
			return -1;
		}
	}
	else if (x_coord + x_shift >= USE_WIDTH) {
		if (USE_WRAP_X) {
			loc += x_shift - USE_WIDTH;
		}
		else {
			// off the right side
			return -1;
		}
	}
	else {
		loc += x_shift;
	}
	
	// handle Y
	if (y_coord + y_shift < 0) {
		if (USE_WRAP_Y) {
			loc += (y_shift * USE_WIDTH) + USE_SIZE;
		}
		else {
			// off the bottom
			return -1;
		}
	}
	else if (y_coord + y_shift >= USE_HEIGHT) {
		if (USE_WRAP_Y) {
			loc += (y_shift * USE_WIDTH) - USE_SIZE;
		}
		else {
			// off the top
			return -1;
		}
	}
	else {
		loc += (y_shift * USE_WIDTH);
	}

	// again, we can ONLY return map locations
	if (loc >= 0 && loc < USE_SIZE) {
		return loc;
	}
	else {
		return -1;
	}
}
Esempio n. 6
0
void create_map(void) {
	struct island_data *isle;

	init_grid();
	
	// make a ton of plains islands
	printf("Generating islands with %d total land target...\n", TARGET_LAND_SIZE);
	create_islands();

	printf("Adding mountains and rivers...\n");
	for (isle = island_list; isle; isle = isle->next) {
		// fillings based on location (it's not desert or jungle YET, so we check prcs
		if (IS_IN_Y_PRC_RANGE(Y_COORD(isle->loc), DESERT_START_PRC, DESERT_END_PRC)) {
			// desert
			add_mountains(isle);
			// rare chance of river
			if (!number(0, 2)) {
				add_river(isle);
			}
		}
		else if (IS_IN_Y_PRC_RANGE(Y_COORD(isle->loc), JUNGLE_START_PRC, JUNGLE_END_PRC)) {
			// jungle
			// chance of mountain
			if (!number(0, 1)) {
				add_mountains(isle);
			}
			// always get extra river
			add_river(isle);
			add_river(isle);
		}
		else {
			// not jungle or desert
			add_mountains(isle);
			add_river(isle);
			
			// chance to add additional river
			if (!number(0, 2)) {
				add_river(isle);
			}
		}

		// not currently adding passes
		// add_pass(isle);
	}
	
	// these really need to go in order, as they modify the map in passes
	printf("Adding desert...\n");
	add_latitude_terrain(DESERT, DESERT_START_PRC, DESERT_END_PRC);
	printf("Adding jungle...\n");
	add_latitude_terrain(JUNGLE, JUNGLE_START_PRC, JUNGLE_END_PRC);
	
	printf("Numbering islands and fixing lakes...\n");
	number_islands_and_fix_lakes();
	
	printf("Irrigating from rivers...\n");
	replace_near(DESERT, PLAINS, RIVER, 2);
	replace_near(DESERT, PLAINS, LAKE, 2);
	replace_near(JUNGLE, SWAMP, RIVER, 2);
	replace_near(JUNGLE, SWAMP, LAKE, 2);

	// tundra if no y-wrap
	if (!USE_WRAP_Y && TUNDRA_HEIGHT >= 1) {
		printf("Adding tundra...\n");
		add_tundra();
	}
	
	// center maps if they use only x-wrap
	if (USE_WRAP_X && !USE_WRAP_Y) {
		printf("Centering map horizontally...\r\n");
		center_map();
	}
	
	// finish up the map
	printf("Finishing map...\n");
	complete_map();
	add_start_points();
}
Esempio n. 7
0
// Determines whether this AABB contains the given point
bool AABB::contains(const IAPoint &p) const {
   // Check if x, y, and z coords are inside of the planes defined by my six x, y, and z sides
   return ((X_COORD(m_max) > X_COORD(p)) && (X_COORD(m_min) < X_COORD(p)) &&
           (Y_COORD(m_max) > Y_COORD(p)) && (Y_COORD(m_min) < Y_COORD(p)) &&
           (Z_COORD(m_max) > Z_COORD(p)) && (Z_COORD(m_min) < Z_COORD(p)));
}