← Back to team overview

widelands-dev team mailing list archive

Re: [Merge] lp:~widelands-dev/widelands/bridges into lp:widelands

 


Diff comments:

> === modified file 'src/economy/roadbase.cc'
> --- src/economy/roadbase.cc	2019-03-12 12:11:23 +0000
> +++ src/economy/roadbase.cc	2019-03-12 12:11:50 +0000
> @@ -69,6 +71,68 @@
>  	return *flags_[FlagStart];
>  }
>  
> +// This returns true if and only if this is a road that covers the specified edge and
> +// both triangles adjacent to that edge are unwalkable
> +bool RoadBase::is_bridge(const EditorGameBase& egbase, const FCoords& field, uint8_t dir) const {

OK, let's leave it as it is then :)

> +	if (descr().type() != MapObjectType::ROAD) {
> +		// waterways can't be bridges...
> +		return false;
> +	}
> +
> +	const Map& map = egbase.map();
> +
> +	FCoords iterate = map.get_fcoords(path_.get_start());
> +	const Path::StepVector::size_type nr_steps = path_.get_nsteps();
> +	bool found = false;
> +	for (Path::StepVector::size_type i = 0; i <= nr_steps; ++i) {
> +		if (iterate == field) {
> +			if ((i < nr_steps && path_[i] == dir) || (i > 0 && path_[i - 1] == get_reverse_dir(dir))) {
> +				found = true;
> +				break;
> +			}
> +			return false;
> +		}
> +		if (i < nr_steps) {
> +			map.get_neighbour(iterate, path_[i], &iterate);
> +		}
> +	}
> +	if (!found) {
> +		return false;
> +	}
> +
> +	FCoords fr, fd;
> +	switch (dir) {
> +		case WALK_SW:
> +			fd = field;
> +			map.get_ln(field, &fr);
> +			break;
> +		case WALK_SE:
> +			fd = field;
> +			fr = field;
> +			break;
> +		case WALK_NW:
> +			map.get_tln(field, &fd);
> +			fr = fd;
> +			break;
> +		case WALK_NE:
> +			map.get_trn(field, &fd);
> +			map.get_tln(field, &fr);
> +			break;
> +		case WALK_W:
> +			map.get_tln(field, &fd);
> +			map.get_ln(field, &fr);
> +			break;
> +		case WALK_E:
> +			map.get_trn(field, &fd);
> +			fr = field;
> +			break;
> +		default:
> +			NEVER_HERE();
> +	}
> +	return (egbase.world().terrain_descr(fd.field->terrain_d()).get_is() & TerrainDescription::Is::kUnwalkable) &&
> +			(egbase.world().terrain_descr(fr.field->terrain_r()).get_is() & TerrainDescription::Is::kUnwalkable);
> +}
> +
>  /**
>   * Return the cost of getting from fromflag to the other flag.
>   */
> @@ -107,15 +171,25 @@
>  		// mark the road that leads up to this field
>  		if (steps > 0) {
>  			const Direction dir = get_reverse_dir(path_[steps - 1]);
> -			if (dir == WALK_SW || dir == WALK_SE || dir == WALK_E)
> -				egbase.set_road(curf, dir, type_);
> +			if (dir == WALK_SW || dir == WALK_SE || dir == WALK_E) {
> +				uint8_t type = type_;
> +				if (is_bridge(egbase, curf, dir)) {
> +					type += RoadType::kBridgeNormal - RoadType::kNormal;

OK :)

> +				}
> +				egbase.set_road(curf, dir, type);
> +			}
>  		}
>  
>  		// mark the road that leads away from this field
>  		if (steps < path_.get_nsteps()) {
>  			const Direction dir = path_[steps];
> -			if (dir == WALK_SW || dir == WALK_SE || dir == WALK_E)
> -				egbase.set_road(curf, dir, type_);
> +			if (dir == WALK_SW || dir == WALK_SE || dir == WALK_E) {
> +				uint8_t type = type_;
> +				if (is_bridge(egbase, curf, dir)) {
> +					type += RoadType::kBridgeNormal - RoadType::kNormal;
> +				}
> +				egbase.set_road(curf, dir, type);
> +			}
>  
>  			map.get_neighbour(curf, dir, &curf);
>  		}


-- 
https://code.launchpad.net/~widelands-dev/widelands/bridges/+merge/364318
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bridges into lp:widelands.


References