//Leons Petrazickis
//FictAm Events Generator

#include<fstream.h>




ofstream fout("events.txt");


void createunit(char[255],char[255],char[255],char[255],char[255]);
void unitkilled(char[255],char[255],char[255]);
void negotiation(char[255],char[255],char[255],char[255]);
void randomturn(int);
void text(char[32000]);
void beginevents();
void endevents();
void IF();
void THEN();
void ENDIF();
void justonce();
void noschism(char[255]);
void citytaken(char[255],char[255],char[255]);


char civs[8][256] = {
		"Vikings",
		"Irish",
		"Phoenicians",
		"Romans",
		"Chinese",
		"Meso-Americans",
		"Natives",
		"Barbarians"};

void main(){
	char answer = ' ';
	int x=0;
	int number = 5;
	int randfreq = 2;
	int generalinterval = 15;

	cout << "Welcome to the Setup Program for Fictional Americas:\n";
	cout << "\t-Answer in lowercase and follow up with an [Enter]\n";
	cout << "\t-Run it again whenever needed\n";
	cout << "\t-If it summons aliens from Alpha Centauri, it is not my fault\n\n";

	beginevents();

	IF();
	noschism("ANYBODY");
	THEN();
	ENDIF();

	IF();
	negotiation ("Anybody", "humanorcomputer", "Natives", "humanorcomputer");
	THEN();
	ENDIF();

	IF();
	negotiation ("Natives", "humanorcomputer", "Anybody", "humanorcomputer");
	THEN();
	ENDIF();

	cout << "Are Vikings being played by a human? (y or n) ";
	cin >> answer;
	if (answer == 'n'){
		for (x=0; x<number ; x++){
			IF();
			randomturn (randfreq);
			THEN();
			createunit ("Vikings", "Hirdmenn", "No", "NONE", "68,4");
			ENDIF();
		}
		IF();
		randomturn (6);
		THEN();
		createunit ("Vikings", "Settlers", "No", "NONE", "68,4");
		ENDIF();
	}

	cout << "Are Irish being played by a human? (y or n) ";
	cin >> answer;
	if (answer == 'n'){
		for (x=0; x<number ; x++){
			IF();
			randomturn (randfreq);
			THEN();
			createunit ("Irish", "Knight", "No", "NONE", "66,22");
			ENDIF();
		}
		IF();
		randomturn (6);
		THEN();
		createunit ("Irish", "Settlers", "No", "NONE", "66,22");
		ENDIF();
	}
	

	cout << "Are Romans being played by a human? (y or n) ";
	cin >> answer;
	if (answer == 'n'){
		for (x=0; x<number ; x++){
			IF();
			randomturn (randfreq);
			THEN();
			createunit ("Romans", "Legion", "No", "NONE", "56,44");
			ENDIF();
		}
		IF();
		randomturn (6);
		THEN();
		createunit ("Romans", "Settlers", "No", "NONE", "56,44");
		ENDIF();
	}

	cout << "Are Phoenicians being played by a human? (y or n) ";
	cin >> answer;
	if (answer == 'n'){
		for(x=0; x<(number / 2) ;x++){
			IF();
			randomturn (randfreq);
			THEN();
			createunit ("Phoenicians", "War Elephant", "No", "NONE", "79,77");
			ENDIF();
		}
		for(x=0; x<(number / 2) ;x++){
			IF();
			randomturn (randfreq);
			THEN();
			createunit ("Phoenicians", "Eleph. Escort", "No", "NONE", "79,77");
			ENDIF();
		}
		IF();
		randomturn (6);
		THEN();
		createunit ("Phoenicians", "Settlers", "No", "NONE", "79,77");
		ENDIF();
	}

	cout << "Are Chinese being played by a human? (y or n) ";
	cin >> answer;
	if (answer == 'n'){
		for(x=0; x<(number / 2) ;x++){
			IF();
			randomturn (randfreq);
			THEN();
			createunit ("Chinese", "Chu Ko Nu", "No", "NONE", "4,12");
			ENDIF();
		}
		for(x=0; x<(number / 2) ;x++){
			IF();
			randomturn (randfreq);
			THEN();
			createunit ("Chinese", "Feudal Lord", "No", "NONE", "4,12");
			ENDIF();
		}
		IF();
		randomturn (6);
		THEN();
		createunit ("Chinese", "Settlers", "No", "NONE", "4,12");
		ENDIF();
	}


	for(x=0; x<(number/2) ;x++){
		IF();
		randomturn (randfreq);
		THEN();
		createunit ("Natives", "Skirmishers", "No", "NONE", "38,34");
		ENDIF();
	}
	for(x=0; x<(number/2) ;x++){
		IF();
		randomturn (randfreq);
		THEN();
		createunit ("Natives", "Skirmishers", "No", "NONE", "57,19");
		ENDIF();
	}
	for(x=0; x<(number/2) ;x++){
		IF();
		randomturn (randfreq);
		THEN();
		createunit ("Natives", "Skirmishers", "No", "NONE", "23,7");
		ENDIF();
	}
	for(x=0; x<(number/2) ;x++){
		IF();
		randomturn (randfreq);
		THEN();
		createunit ("Natives", "Skirmishers", "No", "NONE", "96,90");
		ENDIF();
	}
	for(x=0; x<(number/2) ;x++){
		IF();
		randomturn (randfreq);
		THEN();
		createunit ("Natives", "Skirmishers", "No", "NONE", "95,119");
		ENDIF();
	}

	//////////////////////////////////////////////

	
	IF();
	unitkilled ("Settlers", "Vikings", "Anybody");
	THEN();
	createunit ("Vikings", "Slaves", "No", "NONE", "68,4");
	ENDIF();
	IF();
	unitkilled ("Slaves", "Vikings", "Anybody");
	THEN();
	createunit ("Vikings", "Slaves", "No", "NONE", "68,4");
	ENDIF();
	IF();
	unitkilled ("Settlers", "Irish", "Anybody");
	THEN();
	createunit ("Irish", "Slaves", "No", "NONE", "66,22");
	ENDIF();
	IF();
	unitkilled ("Slaves", "Irish", "Anybody");
	THEN();
	createunit ("Irish", "Slaves", "No", "NONE", "66,22");
	ENDIF();
	IF();
	unitkilled ("Settlers", "Romans", "Anybody");
	THEN();
	createunit ("Romans", "Slaves", "No", "NONE", "56,44");
	ENDIF();
	IF();
	unitkilled ("Slaves", "Romans", "Anybody");
	THEN();
	createunit ("Romans", "Slaves", "No", "NONE", "56,44");
	ENDIF();
	IF();
	unitkilled ("Settlers", "Phoenicians", "Anybody");
	THEN();
	createunit ("Phoenicians", "Slaves", "No", "NONE", "79,77");
	ENDIF();
	IF();
	unitkilled ("Slaves", "Phoenicians", "Anybody");
	THEN();
	createunit ("Phoenicians", "Slaves", "No", "NONE", "79,77");
	ENDIF();
	IF();
	unitkilled ("Settlers", "Chinese", "Anybody");
	THEN();
	createunit ("Chinese", "Slaves", "No", "NONE", "4,12");
	ENDIF();
	IF();
	unitkilled ("Slaves", "Chinese", "Anybody");
	THEN();
	createunit ("Chinese", "Slaves", "No", "NONE", "4,12");
	ENDIF();
	///////////////////////////////////////////////////////////
	IF();
	randomturn (12);
	THEN();
	createunit ("Vikings", "Slaves", "No", "NONE", "68,4");
	ENDIF();
	IF();
	randomturn (12);
	THEN();
	createunit ("Irish", "Slaves", "No", "NONE", "66,22");
	ENDIF();
	IF();
	randomturn (12);
	THEN();
	createunit ("Romans", "Slaves", "No", "NONE", "56,44");
	ENDIF();
	IF();
	randomturn (12);
	THEN();
	createunit ("Phoenicians", "Slaves", "No", "NONE", "79,77");
	ENDIF();
	IF();
	randomturn (12);
	THEN();
	createunit ("Chinese", "Slaves", "No", "NONE", "4,12");
	ENDIF();
	/////////////////////////////////////////////////////////
	IF();
	unitkilled ("V. Hero", "Anybody", "Anybody");
	THEN();
	text ("A Viking Hero has fallen gloriously on the battlefiled and is on his way to Valhalla..");
	ENDIF();
	IF();
	unitkilled ("I. Crusader", "Anybody", "Anybody");
	THEN();
	text ("An Irish Crusader has died spreading the word of the one true deity.");
	ENDIF();
	IF();
	unitkilled ("R. Centurion", "Anybody", "Anybody");
	THEN();
	text ("A Roman Centurion failed to appease Mars before going into battle and is now no more.");
	ENDIF();
	IF();
	unitkilled ("P. General", "Anybody", "Anybody");
	THEN();
	text ("A Phoenician General has clashed wits with a worthy opponent - he now has an eternity to ponder over his moves.");
	ENDIF();
	IF();
	unitkilled ("C. General", "Anybody", "Anybody");
	THEN();
	text ("A Chinese General has joined his ancestors after fighting a foe Sun Tzu had not anticipated.");
	ENDIF();
	IF();
	unitkilled ("A. General", "Anybody", "Anybody");
	THEN();
	text ("An Aztec General has departed to one of the thirteen heavens - or nine hells.");
	ENDIF();
	IF();
	unitkilled ("M. Priestess", "Anybody", "Anybody");
	THEN();
	text ("A Mayan High Priestess was slain whilst defending a sacred shrine.");
	ENDIF();
	IF();
	unitkilled ("I. General", "Anybody", "Anybody");
	THEN();
	text ("An Incan General is no longer among the living.");
	ENDIF();
	IF();
	unitkilled ("N. Guide", "Anybody", "Anybody");
	THEN();
	text ("A Native Guide shall no longer tread among us, for one cannot outsmart brute force forever.");
	ENDIF();
	////////////////////////////////////////////
	IF();
	randomturn(generalinterval);
	THEN();
	createunit("Vikings","V. Hero","no","NONE","68,4\n72,2\n82,4");
	text("A Viking has proven himself battleworthy and is proclaimed a hero.");
	ENDIF();
	IF();
	randomturn(generalinterval);
	THEN();
	createunit("Irish","I. Crusader","no","NONE","66,22\n68,16\n64,28");
	text("A new Irish Crusader has risen from the ranks.");
	ENDIF();
	IF();
	randomturn(generalinterval);
	THEN();
	createunit("Romans","R. Centurion","no","NONE","56,44\n61,49\n62,56");
	text("A hardened Roman veteran shall now lead troops as Centurion.");
	ENDIF();
	IF();
	randomturn(generalinterval);
	THEN();
	createunit("Phoenicians","P. General","no","NONE","79,77\n75,75\n77,63");
	text("Another son of the Phoenician king has grown old enough to lead troops.");
	ENDIF();
	IF();
	randomturn(generalinterval);
	THEN();
	createunit("Chinese","C. General","no","NONE","4,12\n8,6\n3,3");
	text("The Chinese Emperor has summonned a noble into generalship.");
	ENDIF();
	IF();
	randomturn(generalinterval);
	THEN();
	createunit("Meso-Americans","A. General","no","NONE","26,56\n31,61\n37,63");
	text("The Aztecs gods of war have picked a youth to lead armies in combat.");
	ENDIF();
	IF();
	randomturn(generalinterval);
	THEN();
	createunit("Meso-Americans","I. General","no","NONE","68,90\n73,103\n83,111");
	text("An Incan warrior has been chosen as a General.");
	ENDIF();
	/////////////////////////////////////////////
	IF();
	citytaken("Tenochtitlan","Anybody","Anybody");
	THEN();
	text("Tenochtitlan, the greatest city in the world, lies prostrate before its conquerors.");
	ENDIF();



	endevents();
	fout.close();
}

void createunit(char owner[255],
				char unit[255],
				char veteran[255],
				char homecity[255],
				char loc[255]){
	fout << "CreateUnit\n";
	fout << "owner=" << owner << "\n";
	fout << "unit=" << unit << "\n";
	fout << "veteran=" << veteran << "\n";
	fout << "homecity=" << homecity << "\n";
	fout << "locations\n" << loc << "\nendlocations\n";
}

void unitkilled(char unit[255],
				char attacker[255],
				char defender[255]){
	fout << "UnitKilled\n";
	fout << "unit=" << unit << "\n";
	fout << "attacker=" << attacker << "\n";
	fout << "defender=" << defender << "\n";
}

void randomturn(int denominator){
	fout << "RandomTurn\n";
	fout << "denominator=" << denominator << "\n";
}

void negotiation (char talker[255],
				  char talkertype[255],
				  char listener[255],
				  char listenertype[255]){
    fout << "Negotiation\n";
    fout << "talker=" << talker << "\n";
    fout << "talkertype="<< talkertype << "\n";
    fout << "listener="<< listener << "\n";
    fout << "listenertype="<< listenertype << "\n";
}

void text(char text[32000]){
	fout << "Text\n";
	fout << text << "\n";
	fout << "EndText\n";
}


void beginevents(){
	fout << "@BEGINEVENTS\n";
}

void endevents(){
	fout << "@ENDEVENTS\n";
}

void IF(){
	fout << "@IF\n";
}

void THEN(){
	fout << "@THEN\n";
}

void ENDIF(){
	fout << "@ENDIF\n";
}

void justonce(){
	fout << "JustOnce\n";
}

void noschism(char defender[255]){
	fout << "NoSchism\n";
	fout << "defender=" << defender << "\n";
}

void citytaken(char city[255],char attacker[255],char defender[255]){
	fout << "CityTaken\n";
	fout << "city=" << city << "\n";
	fout << "attacker=" << attacker << "\n";
	fout << "defender=" << defender << "\n";
}