#define PERIOD_EARLY_EXPLORERS			0
#define PERIOD_THE_SPANISH_MAIN			1
#define PERIOD_GOLDEN_AGE_OF_PIRACY		2
#define PERIOD_COLONIAL_POWERS			3
#define PERIOD_REVOLUTIONS				4
#define PERIOD_THE_CORSICAN				5

#define MAX_PERIODS						6

object Periods[MAX_PERIODS];

int PeriodsQuantity = 0;

void InitPeriods()
{
	ref period;
	int n = 0;

	for (n = 0; n < MAX_PERIODS; n++) {
		makeref(period, Periods[n]);
		DeleteAttribute(period, "");
		period.id = "Period" + n;
		period.name = "";
		period.date.start = "";
		period.date.end = "";
	}

	n = 0;

	makeref(period, Periods[n]);
	period.name = "Early Explorers";
	period.date.start = "1500";
	period.date.end = "1599";
	n++;

	makeref(period, Periods[n]);
	period.name = "The Spanish Main";
	period.date.start = "1600";
	period.date.end = "1679";
	n++;

	makeref(period, Periods[n]);
	period.name = "Golden Age of Piracy";
	period.date.start = "1680";
	period.date.end = "1739";
	n++;

	makeref(period, Periods[n]);
	period.name = "Colonial Powers";
	period.date.start = "1740";
	period.date.end = "1769";
	n++;

	makeref(period, Periods[n]);
	period.name = "Revolutions";
	period.date.start = "1770";
	period.date.end = "1789";
	n++;

	makeref(period, Periods[n]);
	period.name = "The Corsican";
	period.date.start = "1790";
	period.date.end = "1820";
	n++;

	PeriodsQuantity = n;
}

string GetPeriodName(int idx)
{
	if (idx < 0 || idx >= PeriodsQuantity) return "";
	ref period; makeref(period, Periods[idx]);
	if (!CheckAttribute(period, "name")) return "";
	return period.name;
}

int GetPeriodFromYear(int year)
{
	ref period;
	for (int i = 0; i < PeriodsQuantity; i++) {
		makeref(period, Periods[i]);
		if(sti(period.date.start) <= year && sti(period.date.end) >= year) return i;
	}
	return -1;
}

int GetCurrentPeriod()
{
	ref period; makeref(period, Periods[0]);
	if(!CheckAttribute(period, "current")) return PERIOD_GOLDEN_AGE_OF_PIRACY;
	return sti(period.current);
}

void SetCurrentPeriod(int cperiod)
{
	ref period; makeref(period, Periods[0]);
	if(cperiod < 0 || cperiod >= MAX_PERIODS) period.current = PERIOD_GOLDEN_AGE_OF_PIRACY;
	else period.current = cperiod;
}
