← Back to team overview

widelands-dev team mailing list archive

Re: [Merge] lp:~widelands-dev/widelands/bug-1810062-territorial-calculations into lp:widelands

 


Diff comments:

> 
> === modified file 'src/logic/map.cc'
> --- src/logic/map.cc	2019-02-12 17:27:04 +0000
> +++ src/logic/map.cc	2019-02-21 09:14:58 +0000
> @@ -255,6 +257,77 @@
>  		}
>  }
>  
> +
> +std::set<FCoords> Map::calculate_valuable_fields() const {
> +	std::set<FCoords> result;
> +	std::set<FCoords> check;
> +
> +	ScopedTimer timer("Calculating valuable fields took %ums");
> +
> +	// Add all land coordinates starting from the given field for the given radius
> +	const auto add_starting_coords = [this, &result, &check](const Coords& coords, int radius) {
> +		MapRegion<Area<FCoords>> mr(*this, Area<FCoords>(get_fcoords(coords), radius));
> +		do {
> +			if (!(mr.location().field->maxcaps() & MOVECAPS_SWIM)) {
> +				result.insert(mr.location());
> +				check.insert(mr.location());
> +			}
> +		} while (mr.advance(*this));
> +	};
> +
> +	// Initialize the fields table and the check area with the regions around the starting field of each player
> +	for (const Coords& coords : starting_pos_) {
> +		add_starting_coords(coords, 9);
> +	}
> +
> +	// Add port spaces to the starting check area
> +	if (allows_seafaring()) {
> +		for (const Coords& coords : get_port_spaces()) {
> +			add_starting_coords(coords, 5);
> +		}
> +	}
> +
> +	// Walk the map
> +	while (!check.empty()) {
> +		std::set<FCoords> new_fields;
> +		// Checking the check region for buildcaps and add fields that can be conquered
> +		for (const FCoords& fcoords : check) {
> +			int radius = 0;
> +			int inner_radius = 1;
> +			Field* field = fcoords.field;
> +			if ((field->maxcaps() & BUILDCAPS_BIG) == BUILDCAPS_BIG) {

I don't understand this line. Wouldn't this be sufficient?

if ((field->maxcaps() & BUILDCAPS_BIG) {

I don't see any difference when using this. The calculated number of fields are equal.

> +				radius = 9;
> +				inner_radius = 7;
> +			} else if (field->maxcaps() & BUILDCAPS_MEDIUM) {
> +				radius = 7;
> +				inner_radius = 5;
> +			} else if (field->maxcaps() & BUILDCAPS_SMALL) {
> +				radius = 5;
> +			}
> +			if (radius > 0) {
> +				Widelands::HollowArea<> hollow_area(Widelands::Area<>(fcoords, radius), inner_radius);
> +				Widelands::MapHollowRegion<> mr(*this, hollow_area);
> +				do {
> +					const FCoords& candidate = get_fcoords(mr.location());
> +					if ((check.count(candidate) == 0)
> +						&& (result.count(candidate) == 0)
> +						&& (candidate.field->maxcaps() & MOVECAPS_WALK)) {
> +						result.insert(candidate);
> +						new_fields.insert(candidate);
> +					}
> +
> +				} while (mr.advance(*this));
> +			}
> +		}
> +		check.clear();
> +		check = new_fields;
> +	}
> +
> +	log("Found %" PRIuS " valuable fields\n", result.size());
> +
> +	return result;
> +}
> +
>  /*
>  ===============
>  remove your world, remove your data


-- 
https://code.launchpad.net/~widelands-dev/widelands/bug-1810062-territorial-calculations/+merge/361366
Your team Widelands Developers is subscribed to branch lp:~widelands-dev/widelands/bug-1810062-territorial-calculations.


References