#!/bin/sh

# Europa	50	X

gawk -v S=$1 '
@include "scripts/getcls.awk"

$1 == S {
	data[$2] = $3
	indices[++i] = $2
}

END {
	asort(indices)
	for (i = 1; i <= length(indices); i++) {
		x = i % 4
		if (x == 1)
			printf "trX {"

		printf "td .%s colspan=\"X\" {-€%d}", getcls(data[indices[i]]), indices[i]

		if (x == 0) {
			print "}"
			ends++
		}
	}

	if ((length(data) / 4) > ends)
		print "}"

	print "__MARKER__"
}
' data/world/notes.ez \
| scripts/colspan.sed \
| scripts/last-of-design.sed