<?
	$strip = array(chr(13), chr(10), "\'", ";");
	$content=str_replace($strip," ",$content);
	$strip = array("<br>", " III ", " II ", " I ");
	$content=str_replace($strip," ",$content);
	$strip = array("  ", "   ", "    ", "     ", "      ", "       ", "        ", "         ", "          ");
	$content=str_replace($strip," ",$content);
	$content=str_replace(". </b></i><br>"," tag_brrumor ",$content);
	
	if ((strpos($content, "Colyseo")) || (strpos($content, "Productions Aristoļ"))) {
		$source_file="fr";
#		echo "french source file<br>";
	}
	if (strpos($content, "Games")) {
		$source_file="uk";
#		echo "english source file<br>";
	}

	switch ($source_file) {
		case "uk" : $langinside=1; break;
		case "fr" : $langinside=2; break;
	}
	switch ($source_file) {
		case "fr" : $fn=Inc("suppress_fr.csv"); break;
		case "uk" : $fn=Inc("suppress_uk.csv"); break;
	}
	$fp = fopen ($fn, "r");
	$content_replace = fread($fp, filesize($fn));
	fclose($fp);
	Decrunch($content_replace);
	for ($i=1; $i<=$lin; $i++) {
		$word=$cell[$i][1];
		$done=false;
		if (strpos($word, "~")) {
			$wordsplit=explode(" ", $word);
			do {
				$stop=true;
				if (strpos($content, $wordsplit[0])) {
					$pos1=strpos($content, $wordsplit[0]);
					$content1=substr($content, 0, $pos1);
					$contentplus=substr($content, $pos1, strlen($content)-$pos1);
					if (strpos($contentplus, $wordsplit[2])) {
						$pos2=strpos($contentplus, $wordsplit[2]);
						$content2=substr($contentplus, $pos2, strlen($contentplus)-$pos2);
						$content=$content1.$content2;
						$stop=false;
					}
				}
			} while (!$stop);
			$done=true;
		}
		if (strpos($word, "*")) {
			$wordstart=substr($word, 0, strpos($word, "*"));
			$wordlast=substr(strrchr($word, '*'), 1, strlen(strrchr($word, '*'))-1);
			$starcount=substr_count($word, "*");
#			echo "word=$word, wordstart=$wordstart, wordlast=$wordlast, count=$starcount<br>";
			do {
				$stopsearch=true;
				if ((strpos($content, $wordstart)) && (strpos($content, $wordlast))) {
					$stopsearch=false;
				}
				if (!$stopsearch) {
					$plast=strlen($wordlast)-1;
					$p=strpos($content, $wordstart);
					$pstart=$p;
					$p+=strlen($wordstart);
					$starcounted=0;
					$inword=false;
					$beenfound=false;
					do {
						$p++;
						if (($content[$p]==" ") && ($inword)) {
							$inword=false;
							$starcounted++;
							$wordlasted=substr($content, $p, $plast+1);
#							echo "wordlasted=$wordlasted<br>";
							if ($wordlasted==$wordlast) {
								$beenfound=true;
#								echo "<br><b>beenfound !</b><br><br>";
							}
						}
						if (($content[$p]!=" ") && (!$inword)) {
							$inword=true;
						}
					} while (($starcounted<$starcount) && (!$beenfound));
#					echo "p=$p, pstart=$pstart, plast=$plast, starcounted=$starcounted<br>";
					if ($beenfound) {
						$content=substr($content,0,$pstart).substr($content,$p+$plast+1,strlen($content)-$p-$plast-1);
					} else {
						$content=substr($content,0,$pstart).substr($content,$pstart+strlen($wordstart),strlen($content)-$pstart-strlen($wordstart));
					}
#					echo "<table><tr><td bgcolor=#CCFFCC>".$content."</td></tr></table>";
				}
			} while (!$stopsearch);
			$done=true;
		}
		if (!$done) {
			$content=str_replace($word,"",$content);
		}
#		echo "suppressed $word<br>";
	}
#	echo "<table><tr><td bgcolor=#FFAAAA><h2>SUPPRESS DONE</h2><hr>".$content."</td></tr></table>";

	$strip = array("  ", "   ", "    ", "     ", "      ", "       ", "        ", "         ", "          ");
	$content=str_replace($strip," ",$content);
	$content=str_replace("  "," ",$content);

	$fn=Inc("artefacts.csv");
	$fp = fopen ($fn, "r");
	$content2 = fread($fp, filesize($fn));
	fclose($fp);
	Decrunch($content2);
	$artefactloaded=$cell;
	$artlin=$lin;
	$content_replace = "";
	for ($i=1; $i<=$artlin; $i++) {
		$artefacts[$i]=$artefactloaded[$i][$langinside];
		$start=strpos($artefacts[$i], " ");
		$end=strpos($artefacts[$i], "(");
		$artefacts[$i]=substr($artefacts[$i], $start+1, $end-1-$start-1);
		$artefacts[$i]=str_replace("'"," ",$artefacts[$i]);
		$artefactreplace=str_replace(" ","-",$artefacts[$i])." tag_artefact ".$i." ";
		$content_replace .= $artefacts[$i].";".$artefactreplace.";".chr(10);
		$artefacts[$i]=str_replace(" ","-",$artefacts[$i]);
	}

	$fn=Inc("spells.csv");
	$fp = fopen ($fn, "r");
	$content2 = fread($fp, filesize($fn));
	fclose($fp);
	Decrunch($content2);
	$spellloaded=$cell;
	$spelllin=$lin;
	for ($i=1; $i<=$spelllin; $i++) {
		$spells[$i]=$spellloaded[$i][$langinside+1];
		$spells[$i]=str_replace("'"," ",$spells[$i]);
		$spellreplace=str_replace(" ","-",$spells[$i])." tag_spell ".$spellloaded[$i][1]." ";
		$content_replace .= $spellloaded[$i][1]." ".$spells[$i].";".$spellreplace.";".chr(10);
		if (strlen($spells[$i])>=20) {
			$content_replace .= $spellloaded[$i][1]." ".substr($spells[$i],0,15).";".$spellreplace.";".chr(10);
		}
	}

	switch ($source_file) {
		case "fr" : $fn=Inc("spelling_fr.csv"); break;
		case "uk" : $fn=Inc("spelling_uk.csv"); break;
	}
	$fp = fopen ($fn, "r");
	$content_replace .= fread($fp, filesize($fn));
	fclose($fp);
	switch ($source_file) {
		case "fr" : $fn=Inc("replace_troops_fr.csv"); break;
		case "uk" : $fn=Inc("replace_troops_uk.csv"); break;
	}
	$fp = fopen ($fn, "r");
	$content_replace .= fread($fp, filesize($fn));
	fclose($fp);
	switch ($source_file) {
		case "fr" : $fn=Inc("replace_fr.csv"); break;
		case "uk" : $fn=Inc("replace_uk.csv"); break;
	}
	$fp = fopen ($fn, "r");
	$content_replace .= fread($fp, filesize($fn));
	fclose($fp);
	Decrunch($content_replace);
	for ($i=1; $i<=$lin; $i++) {
		$word=$cell[$i][1];
		$done=false;
		if (strpos($word, "~")) {
			$wordsplit=explode(" ", $word);
			do {
				$stop=true;
				if (strpos($content, $wordsplit[0])) {
					$pos1=strpos($content, $wordsplit[0]);
					$content1=substr($content, 0, $pos1);
					$contentplus=substr($content, $pos1, strlen($content)-$pos1);
					if (strpos($contentplus, $wordsplit[2])) {
						$pos2=strpos($contentplus, $wordsplit[2]);
						$content2=substr($contentplus, $pos2, strlen($contentplus)-$pos2);
						$content=$content1.$cell[$i][2].$content2;
						$stop=false;
					}
				}
			} while (!$stop);
			$done=true;
		}
		if (!$done) {
			if ($cell[$i][2]=="") {	$word_replace=str_replace(" ","-",$word); }
			else { $word_replace=$cell[$i][2]; }
			$content=str_replace($word,$word_replace,$content);
		}
#		echo "replaced $word with ".$word_replace."<br>";
	}
#	echo "<table><tr><td bgcolor=#AAAAFF><h2>REPLACE DONE</h2><hr>".$content."</td></tr></table>";

	$fn=Inc("names.csv");
	$fp = fopen ($fn, "r");
	if (filesize($fn)>0) { $content_replace = fread($fp, filesize($fn)); }
	fclose($fp);
	Decrunch($content_replace);
	for ($i=1; $i<=$lin; $i++) {
		$word=$cell[$i][1];
		if ($cell[$i][2]=="") {	$word_replace=str_replace(" ","-",$word); }
		else { $word_replace=$cell[$i][2]; }
		$content=str_replace($word,$word_replace,$content);
	}
			
	$strip = array("  ", "   ", "    ", "     ", "      ", "       ", "        ", "         ", "          ");
	$content=str_replace($strip," ",$content);
	$content=str_replace("  "," ",$content);
#	echo "<table><tr><td bgcolor=#88FF88><h2>REPLACE DONE</h2><hr>".$content."</td></tr></table>";
	
	$fn=Inc("process.csv");
	$fp = fopen ($fn, "r");
	$content2 = fread($fp, filesize($fn));
	fclose($fp);
	Decrunch($content2);

	$peoplenb=0;
	$turnnb=0;
	$checkgame=0;

/*	if ($cg!=$game_check[$game]) {
		echo "<br><center><font class='rougeboldpadd'>".$loc[$loctag[2]+39][$lang]."</font>";
		die();
	}*/

	$nbtowns=0;
	$nbheroes=0;
	$nbarmies=0;
	$relationslist="relations;";
			
	$process_i=0;
	do {
		$process_i++;
		
		$treat=$cell[$process_i][2];
		$start=strpos($content, $cell[$process_i][3]);
		$end=strpos($content, $cell[$process_i][4]);
		$contentcut=substr($content, $start, $end-$start);
		$pieces=explode(" ", $contentcut);
#		echo "<table><tr><td bgcolor=#8888FF><h2>PART=$treat</h2><hr>".$contentcut."</td></tr></table><hr>";
#		echo "<table width=1000><tr><td bgcolor=#8888FF><h2>PART=$treat</h2><hr>"; for ($n=1; $n<=count($pieces); $n++) { echo $pieces[$n].", "; } echo "</td></tr></table><br>";
		
		if ($nbtags>0) { $searchtag = array_fill(0, $nbtags, ""); }
		$nbtags=0;
		for ($i=1; $i<=$lin; $i++) {
			if ($cell[$i][1]==$treat) {
				$nbtags++;
				$searchtag[$nbtags]=$cell[$i][2];
				$action[$nbtags]=$cell[$i][3];
				$value[$nbtags]=$cell[$i][4];
				
#				echo "$nbtags search ".$searchtag[$nbtags]." with action ".$action[$nbtags]." and value ".$value[$nbtags]."<br>";
			}
		}
		
		$i=0;
		do {
			$i++;
			
			if (array_search($pieces[$i], $searchtag)!=false) {
				$tag=array_search($pieces[$i], $searchtag);
				
				switch ($action[$tag]) {
					case "new" :
						switch ($treat) {
							case "town" :
								$nbtowns++;
								$town[$nbtowns] = new Town;
							break;
							case "hero" :
								$nbheroes++;
								$hero[$nbheroes] = new Hero;
							break;
							case "army" :
								$nbarmies++;
								$army[$nbarmies] = new Army;
							break;
						}
					break;
					case "data" :
#						echo "found ".$searchtag[$tag]." is ".$pieces[$i+$value[$tag]]."<br>";
						switch ($treat) {
							case "data" :
								switch ($searchtag[$tag]) {
									case "tag_pickgamenb" : $checkgame=$pieces[$i+$value[$tag]]; break;
									case "tag_pickpeople" : $peoplenb=$pieces[$i+$value[$tag]]; break;
									case "tag_pickturn" : $turnnb=$pieces[$i+$value[$tag]]; break;
								}
							break;
							case "relations" :
								switch ($searchtag[$tag]) {
									case "tag_people" : $relationslist.=$pieces[$i+$value[$tag]].":".$pieces[$i+$value[$tag]+2].";"; break;
								}
							break;
							case "rumors" :
								switch ($searchtag[$tag]) {
									case "tag_getrumors" : break;
								}
							break;
							case "town" :
								switch ($searchtag[$tag]) {
									case "tag_name" : $town[$nbtowns]->name=$pieces[$i+$value[$tag]]; break;
									case "tag_capital" : $town[$nbtowns]->capital=$pieces[$i+$value[$tag]]; break;
									case "tag_hex" : $town[$nbtowns]->hex=$pieces[$i+$value[$tag]]; break;
									case "tag_townclimate" : $town[$nbtowns]->climate=$pieces[$i+$value[$tag]]; break;
									case "tag_size" : $town[$nbtowns]->size=$pieces[$i+$value[$tag]]; break;
									case "tag_fortif" : $town[$nbtowns]->fortif=$pieces[$i+$value[$tag]]; break;
									case "tag_loyalty" : $town[$nbtowns]->loyalty=$pieces[$i+$value[$tag]]; break;
									case "tag_docks" : $town[$nbtowns]->dock=$pieces[$i+$value[$tag]]; break;
									case "tag_hidden" : $town[$nbtowns]->hidden=$pieces[$i+$value[$tag]]; break;
									case "tag_sieged" : $town[$nbtowns]->sieged=$pieces[$i+$value[$tag]]; break;
									case "tag_leat_res" : $town[$nbtowns]->localprod[1]=$pieces[$i+$value[$tag]]; break;
									case "tag_bro_res" : $town[$nbtowns]->localprod[2]=$pieces[$i+$value[$tag]]; break;
									case "tag_ste_res" : $town[$nbtowns]->localprod[3]=$pieces[$i+$value[$tag]]; break;
									case "tag_mith_res" : $town[$nbtowns]->localprod[4]=$pieces[$i+$value[$tag]]; break;
									case "tag_foo_res" : $town[$nbtowns]->localprod[5]=$pieces[$i+$value[$tag]]; break;
									case "tag_woo_res" : $town[$nbtowns]->localprod[6]=$pieces[$i+$value[$tag]]; break;
									case "tag_moun_res" : $town[$nbtowns]->localprod[7]=$pieces[$i+$value[$tag]]; break;
									case "tag_gol_res" : $town[$nbtowns]->localprod[8]=$pieces[$i+$value[$tag]]; break;
								}
							break;
							case "hero" :
								switch ($searchtag[$tag]) {
									case "tag_hero_name" : $hero[$nbheroes]->name=$pieces[$i+$value[$tag]]; break;
									case "tag_hero_hexpos" : $hero[$nbheroes]->hex=$pieces[$i+$value[$tag]]; break;
									case "tag_hero_armyleader" : $hero[$nbheroes]->commander=$pieces[$i+$value[$tag]]; break;
									case "tag_hero_commander" : $hero[$nbheroes]->command=$pieces[$i+$value[$tag]]; break;
									case "tag_hero_agent" : $hero[$nbheroes]->agent=$pieces[$i+$value[$tag]]; break;
									case "tag_hero_emissary" : $hero[$nbheroes]->emissary=$pieces[$i+$value[$tag]]; break;
									case "tag_hero_mage" : $hero[$nbheroes]->mage=$pieces[$i+$value[$tag]]; break;
									case "tag_hero_health" : $hero[$nbheroes]->health=$pieces[$i+$value[$tag]]; break;
									case "tag_hero_stealth" : $hero[$nbheroes]->stealth=$pieces[$i+$value[$tag]]; break;
									case "tag_hero_challenge" : $hero[$nbheroes]->challenge=$pieces[$i+$value[$tag]]; break;
									case "tag_hero_artefacts" : $listas=true; break;
									case "tag_artefact" :
										if ($listas) {
											if ($hero[$nbheroes]->artefactlist!="") { $hero[$nbheroes]->artefactlist.="#"; }
											$hero[$nbheroes]->artefactlist.=$pieces[$i+$value[$tag]];
										}
									break;
									case "tag_spell" :
										if ($listas) {
											if ($hero[$nbheroes]->spelllist!="") { $hero[$nbheroes]->spelllist.="#"; }
											$hero[$nbheroes]->spelllist.=$pieces[$i+$value[$tag]].":".$pieces[$i+$value[$tag]+1];
										}
									break;
									case "tag_hero_endspells" : $listas=false; break;
								}
							break;
							case "army" :
								$armytype=0;
								switch ($searchtag[$tag]) {
									case "tag_name" : $army[$nbarmies]->leader=$pieces[$i+$value[$tag]]; break;
									case "tag_hex" : $army[$nbarmies]->hex=$pieces[$i+$value[$tag]]; break;
									case "tag_army_morale" : $army[$nbarmies]->morale=$pieces[$i+$value[$tag]]; break;
									case "tag_army_climate" : $army[$nbarmies]->climate=$pieces[$i+$value[$tag]]; break;
									case "tag_foo_stock" : $army[$nbarmies]->food=$pieces[$i+$value[$tag]]; break;
									case "tag_army_fleet_ws" : $army[$nbarmies]->fleet_ws=$pieces[$i+$value[$tag]]; break;
									case "tag_army_fleet_tr" : $army[$nbarmies]->fleet_tr=$pieces[$i+$value[$tag]]; break;
									case "tag_army_wm" : $army[$nbarmies]->warm=$pieces[$i+$value[$tag]]; break;
									case "tag_HC" : $armytype=1; break;
									case "tag_LC" : $armytype=2; break;
									case "tag_HI" : $armytype=3; break;
									case "tag_LI" : $armytype=4; break;
									case "tag_ARC" : $armytype=5; break;
									case "tag_ME" : $armytype=6; break;
								}
								if ($armytype!=0) {
									$army[$nbarmies]->units_training[$armytype]=$pieces[$i+2];
									$army[$nbarmies]->units_weapons[$armytype]=$pieces[$i+3];
									$army[$nbarmies]->units_armors[$armytype]=$pieces[$i+4];
									$army[$nbarmies]->unitsnb[$armytype]=$pieces[$i+5];
								}
							break;
							case "market" :
								switch ($searchtag[$tag]) {
									case "tag_market_avail" :
										for ($m=1; $m<=7;$m++) {
											$market[$m]=$pieces[$i+$m];
										}
									break;
									case "tag_buy_avail" :
										for ($m=1; $m<=7;$m++) {
											$market[$m+7]=$pieces[$i+$m];
										}
									break;
									case "tag_sell_avail" :
										for ($m=1; $m<=7;$m++) {
											$market[$m+14]=$pieces[$i+$m];
										}
									break;
								}
							break;
							case "stock" :
								switch ($searchtag[$tag]) {
									case "tag_stock_budgetarmy" : $stock[1]=$pieces[$i+$value[$tag]]; break;
									case "tag_stock_budgettown" : $stock[2]=$pieces[$i+$value[$tag]]; break;
									case "tag_stock_budgethero" : $stock[3]=$pieces[$i+$value[$tag]]; break;
									case "tag_stock_taxes" : $stock[4]=$pieces[$i+$value[$tag]]; break;
									case "tag_stock_gains" : $stock[5]=$pieces[$i+$value[$tag]]; break;
									case "tag_stock_coffer" : $stock[6]=$pieces[$i+$value[$tag]]; break;
									case "tag_leat_stock" : $stock[7]=$pieces[$i+$value[$tag]]; $stock[7+7]=$pieces[$i+$value[$tag]+1]; break;
									case "tag_bro_stock" : $stock[8]=$pieces[$i+$value[$tag]]; $stock[8+7]=$pieces[$i+$value[$tag]+1]; break;
									case "tag_ste_stock" : $stock[9]=$pieces[$i+$value[$tag]]; $stock[9+7]=$pieces[$i+$value[$tag]+1]; break;
									case "tag_mith_stock" : $stock[10]=$pieces[$i+$value[$tag]]; $stock[10+7]=$pieces[$i+$value[$tag]+1]; break;
									case "tag_foo_stock" : $stock[11]=$pieces[$i+$value[$tag]]; $stock[11+7]=$pieces[$i+$value[$tag]+1]; break;
									case "tag_woo_stock" : $stock[12]=$pieces[$i+$value[$tag]]; $stock[12+7]=$pieces[$i+$value[$tag]+1]; break;
									case "tag_moun_stock" : $stock[13]=$pieces[$i+$value[$tag]]; $stock[13+7]=$pieces[$i+$value[$tag]+1]; break;
								}
							break;
							case "battle" :
								switch ($searchtag[$tag]) {
									case "tag_battle_new" : $text="<b>".$loc[$loctag[2]+42][$lang]."</b> : "; $textart=""; $showtext=""; $listb=true; $artinside=false; break;
									case "tag_battle_army_new" : break;
									case "tag_battle_hex" : if ($listb) { $text.=$loc[$loctag[4]+15][$lang]." ".$pieces[$i+$value[$tag]]." "; } break;
									case "tag_battle_climate" : if ($listb) { $text.=" ".$loc[$loctag[7]+26][$lang]." ".$loc[$loctag[7]+$pieces[$i+$value[$tag]]+35][$lang]."<br>"; } break;
									case "tag_battle_armymorale" : if ($listb) { $textc = ", ".$loc[$loctag[7]+27][$lang]." ".$pieces[$i+$value[$tag]]; } break;
									case "tag_battle_leaderarmy" : if ($listb) { $texth ="<b>".$loc[$loctag[7]+30][$lang]."</b> : ".$pieces[$i+$value[$tag]]; } break;
									case "tag_leaderrank" : if ($listb) { $texth.=" (".$loc[$loctag[7]+63][$lang]." ".$pieces[$i+$value[$tag]].")"; } break;
									case "tag_battle_artifact" :
										if ($listb) {
											if (array_search($pieces[$i+$value[$tag]], $artefacts)!=false) {
												$search_artefact=array_search($pieces[$i+$value[$tag]], $artefacts);
												$texta =" ".$loc[$loctag[7]+64][$lang]." ".$artefactloaded[$search_artefact][$langinside];
											} else {
												$texta =" ".$loc[$loctag[7]+64][$lang]." ".$pieces[$i+$value[$tag]]." (".$loc[$loctag[7]+65][$lang].")";
											}
										}
										if ($artinside) {
											$textart.=" ".$loc[$loctag[7]+64][$lang]." '".$pieces[$i+$value[$tag]]."'<br>";
										}
									break;
									case "tag_people" : if ($listb) { $textp = " ".$loc[$loctag[4]+2][$lang]." ".$loc[$loctag[1]+$pieces[$i+$value[$tag]]][$lang]; } break;
									case "tag_battle_enddeschero" : if ($listb) { $text.=$texth.$texta.$textp.$textc."<br>"; $texta=""; } break;
									case "tag_HC" : if ($listb) { $text.=$pieces[$i+$value[$tag]]." ".$loc[$loctag[7]+56][$lang]." "; } break;
									case "tag_LC" : if ($listb) { $text.=$pieces[$i+$value[$tag]]." ".$loc[$loctag[7]+57][$lang]." "; } break;
									case "tag_HI" : if ($listb) { $text.=$pieces[$i+$value[$tag]]." ".$loc[$loctag[7]+58][$lang]." "; } break;
									case "tag_LI" : if ($listb) { $text.=$pieces[$i+$value[$tag]]." ".$loc[$loctag[7]+59][$lang]." "; } break;
									case "tag_ARC" : if ($listb) { $text.=$pieces[$i+$value[$tag]]." ".$loc[$loctag[7]+60][$lang]." "; } break;
									case "tag_ME" : if ($listb) { $text.=$pieces[$i+$value[$tag]]." ".$loc[$loctag[7]+61][$lang]." "; } break;
									case "tag_battle_weapons" : if ($listb) { $text.=" ".$loc[$loctag[7]+19][$lang]." ".$pieces[$i+$value[$tag]]." "; } break;
									case "tag_battle_armors" : if ($listb) { $text.=" ".$loc[$loctag[7]+23][$lang]." ".$pieces[$i+$value[$tag]]." "; } break;
									case "tag_battle_formation" : if ($listb) { $text.=" ".$loc[$loctag[7]+18][$lang]." ".$pieces[$i+$value[$tag]]."<br>"; } break;
									case "tag_battle_enddesc" :
										if ($text!="") { $showtext=$text; }
										$text=""; $listb=false;
									break;
									case "tag_battle_artifactinside" : $artinside=true; $textart=""; break;
									case "tag_battle_heroartifact" : if ($artinside) { $textart.=$pieces[$i+$value[$tag]]; } break;
									case "tag_battle_spell" : if ($artinside) { $textart.=" ".$loc[$loctag[7]+66][$lang]."<br>"; } break;
									case "tag_battle_dragon" : if ($artinside) { $textart.="Dragon ".$pieces[$i+$value[$tag]]."<br>"; } break;
									case "tag_battle_end_battle" :
										if ($showtext!="") { echo "<table><tr><td bgcolor=#88FF88>".$showtext.$textart."</td></tr></table><br>"; }
										$showtext=""; $text=""; $textart=""; $listb=false; $artinside=false;
									break;
								}
							break;
						}
					break;
				}
			}
		} while ($i<=count($pieces));
	} while ($cell[$process_i+1][1]!="endprocess");

	$savefile="people;".$peoplenb.";game;".$checkgame.";turn;".$turnnb.";".chr(10);
	$savefile.=$relationslist.chr(10);
	for ($sf=1; $sf<=$nbtowns; $sf++) {
		$savefile.="town;".$town[$sf]->name.";".$town[$sf]->capital.";".$town[$sf]->hex.";".$town[$sf]->climate.";".$town[$sf]->size.";".$town[$sf]->fortif.";".$town[$sf]->loyalty.";".$town[$sf]->dock.";".$town[$sf]->hidden.";".$town[$sf]->sieged.";";
		for ($sf2=1; $sf2<=8; $sf2++) {
			$savefile.=$town[$sf]->localprod[$sf2].";";
		}
		$savefile.=chr(10);
	}
	for ($sf=1; $sf<=$nbheroes; $sf++) {
		$savefile.="hero;".$hero[$sf]->name.";".$hero[$sf]->commander.";".$hero[$sf]->hex.";".$hero[$sf]->command.";".$hero[$sf]->agent.";".$hero[$sf]->emissary.";".$hero[$sf]->mage.";".$hero[$sf]->health.";".$hero[$sf]->stealth.";".$hero[$sf]->challenge.";".$hero[$sf]->artefactlist.";".$hero[$sf]->spelllist.";".chr(10);
	}
	for ($sf=1; $sf<=$nbarmies; $sf++) {
		for ($sf2=1; $sf2<=$nbheroes; $sf2++) { if ($army[$sf]->leader==$hero[$sf2]->name) { $army[$sf]->leader=$sf2; } }
		
		$savefile.="army;".$army[$sf]->leader.";".$army[$sf]->hex.";".$army[$sf]->morale.";";
		for ($t=1; $t<=7; $t++) { $savefile.=$army[$sf]->unitsnb[$t].";"; }
		$savefile.=$army[$sf]->climate.";";
		for ($t=1; $t<=6; $t++) { $savefile.=$army[$sf]->units_training[$t].";"; }
		for ($t=1; $t<=6; $t++) { $savefile.=$army[$sf]->units_weapons[$t].";"; }
		for ($t=1; $t<=6; $t++) { $savefile.=$army[$sf]->units_armors[$t].";"; }
		$savefile.=$army[$sf]->food.";".$army[$sf]->fleet_ws.";".$army[$sf]->fleet_tr.";".$army[$sf]->warm.";";
		$savefile.=chr(10);
	}
	$savefile.="market;";
	for ($sf=1; $sf<=21; $sf++) {
		$savefile.=$market[$sf].";";
	}
	$savefile.=chr(10);
	$savefile.="stock;";
	for ($sf=1; $sf<=20; $sf++) {
		$savefile.=$stock[$sf].";";
	}
	$savefile.=chr(10);

	$savefn="Game ".$gamenb.'-'.$turnnb.'-'.$peoplenb.".csv";
?>