Пример #1
0
bool team::shrouded(const map_location& loc) const
{
	if(!resources::gameboard)
		return shroud_.value(loc.wml_x(),loc.wml_y());

	return shroud_.shared_value(ally_shroud(resources::gameboard->teams()),loc.wml_x(),loc.wml_y());
}
Пример #2
0
bool team::fogged(const map_location& loc) const
{
	if(shrouded(loc)) return true;

	// Check for an override of fog.
	if ( fog_clearer_.count(loc) > 0 )
		return false;

	if(!resources::gameboard)
		return fog_.value(loc.wml_x(),loc.wml_y());

	return fog_.shared_value(ally_fog(resources::gameboard->teams()),loc.wml_x(),loc.wml_y());
}
Пример #3
0
void luaW_pushlocation(lua_State *L, const map_location& ml)
{
	lua_createtable(L, 2, 0);

	lua_pushinteger(L, ml.wml_x());
	lua_rawseti(L, -2, 1);

	lua_pushinteger(L, ml.wml_y());
	lua_rawseti(L, -2, 2);
}
Пример #4
0
void gamemap::overlay_impl(
		// const but changed via set_terrain
		const t_translation::ter_map& m1,
		starting_positions& m1_st,
		const t_translation::ter_map& m2,
		const starting_positions& m2_st,
		std::function<void (const map_location&, const t_translation::terrain_code&, terrain_type_data::merge_mode, bool)> set_terrain,
		map_location loc,
		const std::vector<overlay_rule>& rules,
		bool m_is_odd,
		bool ignore_special_locations)
{
	int xpos = loc.wml_x();
	int ypos = loc.wml_y();

	const int xstart = std::max<int>(0, -xpos);
	const int xend = std::min<int>(m2.w, m1.w -xpos);
	const int xoffset = xpos;

	const int ystart_even = std::max<int>(0, -ypos);
	const int yend_even = std::min<int>(m2.h, m1.h - ypos);
	const int yoffset_even = ypos;

	const int ystart_odd = std::max<int>(0, -ypos +(xpos & 1) -(m_is_odd ? 1 : 0));
	const int yend_odd = std::min<int>(m2.h, m1.h - ypos +(xpos & 1) -(m_is_odd ? 1 : 0));
	const int yoffset_odd = ypos -(xpos & 1) + (m_is_odd ? 1 : 0);

	for(int x1 = xstart; x1 != xend; ++x1) {
		int ystart, yend, yoffset;
		if(x1 & 1) {
			ystart = ystart_odd , yend = yend_odd , yoffset = yoffset_odd;
		}
		else {
			ystart = ystart_even, yend = yend_even, yoffset = yoffset_even;
		}
		for(int y1 = ystart; y1 != yend; ++y1) {
			const int x2 = x1 + xoffset;
			const int y2 = y1 + yoffset;

			const t_translation::terrain_code t = m2.get(x1,y1);
			const t_translation::terrain_code current = m1.get(x2, y2);

			if(t == t_translation::FOGGED || t == t_translation::VOID_TERRAIN) {
				continue;
			}

			// See if there is a matching rule
			const overlay_rule* rule = nullptr;
			for(const overlay_rule& current_rule : rules)
			{
				if(!current_rule.old_.empty() && !t_translation::terrain_matches(current, current_rule.old_)) {
					continue;
				}
				if(!current_rule.new_.empty() && !t_translation::terrain_matches(t, current_rule.new_)) {
					continue;
				}
				rule = &current_rule;
				break;
			}

			if (!rule) {
				set_terrain(map_location(x2, y2, wml_loc()), t, terrain_type_data::BOTH, false);
			}
			else if(!rule->use_old_) {
				set_terrain(map_location(x2, y2, wml_loc()), rule->terrain_ ? *rule->terrain_ : t , rule->mode_, rule->replace_if_failed_);
			}
		}
	}

	if (!ignore_special_locations) {
		for(auto& pair : m2_st.left) {

			int x = pair.second.wml_x();
			int y = pair.second.wml_y();
			if(x & 1) {
				if(x < xstart || x >= xend || y < ystart_odd || y >= yend_odd) {
					continue;
				}
			}
			else {
				if(x < xstart || x >= xend || y < ystart_even || y >= yend_even) {
					continue;
				}
			}
			int x_new = x + xoffset;
			int y_new = y + ((x & 1 ) ? yoffset_odd : yoffset_even);
			map_location pos_new = map_location(x_new, y_new, wml_loc());

			m1_st.left.erase(pair.first);
			m1_st.insert(starting_positions::value_type(pair.first, t_translation::coordinate(pos_new.x, pos_new.y)));
		}
	}
}
Пример #5
0
	bool on_map_noborder(const map_location& loc) const
	{
		return loc.wml_x() > 0 && loc.wml_x() < total_width() - 1 &&  loc.wml_y() > 0 && loc.wml_y() < total_height() - 1;
	}
Пример #6
0
	bool on_map(const map_location& loc) const
	{
		return loc.wml_x() >= 0 && loc.wml_x() < total_width() &&  loc.wml_y() >= 0 && loc.wml_y() < total_height();
	}