<?php

include_once("internal/tracker.php");
include_once("internal/map_info.php");
include_once("internal/log.php");
include_once("trackers/map_rotator.php");

// --------------------------------------------
class Stage {
	public $map_info = NULL;
	public $change_map_command = "unset change_map";
	public $start_game_command = "unset start_game";

	function __construct() {
		$this->map_info = new MapInfo();
	}
};

// --------------------------------------------

// in this Classic, we define all stages statically here
// - the other choice would be to alter settings dynamically based on logic
//   and outcome from previous matches
$stages = array();

// --------------------------------------------
// let's define a few helpers
// --------------------------------------------
{

	/*
	$all_factions = <<<EOD
  <faction file="green.xml" />
  <faction file="grey.xml" />
EOD;

	$all_items = <<<EOD
	<weapon file="ak47.weapon" />
	<weapon file="apc_hmg.weapon" />
	<weapon file="g36.weapon" />
	<weapon file="m24_a2.weapon" />
	<weapon file="riot_shield.weapon" />
	<weapon file="m72_law.weapon" />
	<weapon file="m240.weapon" />
	<weapon file="mossberg.weapon" />
	<weapon file="mp5sd.weapon" />
	<weapon file="pkm.weapon" />
	<weapon file="famasg1.weapon" />
	<weapon file="m16a4.weapon" />

	<weapon file="f2000.weapon">
		<commonness value="0.0012" in_stock="0" />
	</weapon>
	<weapon file="benelli_m4.weapon">
		<commonness value="0.0012" in_stock="0" />
	</weapon>
	<weapon file="pepperdust.weapon">
		<commonness value="0.0006" in_stock="0" />
	</weapon>

	<weapon file="tank_cannon.weapon" />
	<weapon file="tank_mg.weapon" />

	<weapon file="aks74u.weapon">
		<commonness value="0.0010" in_stock="0" />
	</weapon>
	<weapon file="p90.weapon">
		<commonness value="0.0007" in_stock="0" />
	</weapon>

	<weapon file="dragunov_svd.weapon" />

	<weapon file="medikit.weapon" />

	<weapon file="tow.weapon" />
	<weapon file="vss_vintorez.weapon">
		<commonness value="0.0007" in_stock="0" />
	</weapon>

	<weapon file="ns2000.weapon">
		<commonness value="0.0003" in_stock="0" />
	</weapon>


	<weapon file="spas-12.weapon" /> 
	<weapon file="qcw-05.weapon" />

  <weapon file="cover_resource.weapon" />

  <weapon file="stoner_lmg.weapon">
    <commonness value="0.001" in_stock="0" />
  </weapon>

  <weapon file="humvee_mg.weapon"/>
	<weapon file="psg90.weapon" />        

 <weapon file="rpg-7.weapon" />
 <weapon file="m2_carlgustav.weapon" /> 

    <weapon file="l85a2.weapon" />
	<weapon file="sg552.weapon" />
	<weapon file="imi_negev.weapon"/>
	<weapon file="qbs-09.weapon" />
	<weapon file="scorpion-evo.weapon" />
    <weapon file="m79.weapon" />

	<weapon file="mg_resource.weapon"/>  
	<weapon file="deployable_mg.weapon" />
	<weapon file="tank_trap_resource.weapon"/>
 	<weapon file="patrol_ship_mg.weapon" />
	<weapon file="patrol_ship_cannon.weapon" />   
	<weapon file="patrol_ship_mortar.weapon" />       

  <!-- throwables, no customization for classic needed, yet -->
  <projectile file="all_throwables.xml" />
  <projectile file="at_mine.projectile" />

  <!-- calls -->
	<call file="cover_drop.call" />

  <!-- carry items, none -->
EOD;

	$all_vehicles = <<<EOD
  <vehicle file="jeep.vehicle" />
  <vehicle file="apc.vehicle" />
  <vehicle file="armored_truck.vehicle" />
  <vehicle file="radar_truck.vehicle" />
  <vehicle file="rubber_boat.vehicle" />
  <vehicle file="tank.vehicle" />
  <vehicle file="tow.vehicle" />
  <vehicle file="cover1.vehicle" />
  <vehicle file="deployable_mg.vehicle" />  
  <vehicle file="tank_trap.vehicle" />
  <vehicle file="humvee.vehicle" />
  <vehicle file="transport_truck.vehicle" />
  <vehicle file="deco_vehicles.xml" />    
EOD;
*/

	// --> using non-customized weapons, whatever the map has set up
	// - can be problematic with persistent profiles + different weapon resource setups

	$ai_accuracy = 0.94;
	$player_ai_compensation = 0;
	$xp_multiplier = 1.0;
	$rp_multiplier = 1.0; 
	$initial_xp = 0.4;
	$initial_rp = 200;          
	$friendly_fire = 0;
	$base_capture_system = "none";
	$randomize_respawn_items = 0;

	// ------------------------------------------------------------------------------------------------
	{
		$stage = new Stage();
		$stage->map_info->name = "pvp1";

		/*
		$map_config = 
			"<map_config>\n" .
			$all_factions . "\n" .
			$all_items . "\n" .
			$all_vehicles . "\n" .
			"</map_config>\n";
*/

		$stage->change_map_command = 
			"<command class='change_map'" .
			"	map='media/packages/pvp/maps/pvp1'>" .
			//$map_config .
			"</command>";

		$stage->start_game_command = 
			"<command class='start_game'" .
			"	vehicles='1'" .
			"	max_soldiers='0'" .
			"	player_ai_compensation='" . $player_ai_compensation . "'" .
			"	xp_multiplier='" . $xp_multiplier . "'" .
			"	rp_multiplier='" . $rp_multiplier . "'" .
			"	initial_xp='" . $initial_xp . "'" .       
			"	initial_rp='" . $initial_rp . "'" .       
			"	base_capture_system='" . $base_capture_system . "'" .
			"   randomize_respawn_items='" . $randomize_respawn_items . "'" .
			"	friendly_fire='" . $friendly_fire . "'>\n" .
			"	<faction initial_over_capacity='0' ai_accuracy='" . $ai_accuracy . "' />\n" .
			"	<faction initial_over_capacity='0' ai_accuracy='" . $ai_accuracy . "' />\n" .
			"	<faction initial_over_capacity='0' ai_accuracy='" . $ai_accuracy . "' capacity_multiplier='0' />\n" .
			"</command>\n";

		$stages[] = $stage;
	}

}

// --------------------------------------------
// --------------------------------------------
// --------------------------------------------
// --------------------------------------------
// --------------------------------------------
// --------------------------------------------

class MapRotatorTeamElimination extends MapRotator {

	// --------------------------------------------
	protected function get_stage_count() {
		global $stages;
		return count($stages);
	}

	// --------------------------------------------
	protected function get_map_name($index) {
		global $stages;
		return $stages[$index]->map_info->name;
	}

	// --------------------------------------------
	protected function get_change_map_command($index) {
		global $stages;
		return $stages[$index]->change_map_command;
	}

	// --------------------------------------------
	protected function get_start_game_command($index) {
		global $stages;
		return $stages[$index]->start_game_command;
	}

	// --------------------------------------------
	protected function get_next_stage_index() {
        return pick_random_map_index($this->get_stage_count(), $this->stages_completed);
	}

	// --------------------------------------------
	protected function start_map($index, $begin_only = false) {
		$this->current_stage_index = $index;

		$this->metagame->pre_begin_match();

		if (!$begin_only) {
			// change map 
			$change_map_command = $this->get_change_map_command($index);
			$this->metagame->comms->send($change_map_command);

			// start game 
			$start_game_command = $this->get_start_game_command($index);
			$this->metagame->comms->send($start_game_command);
		}

		// TODO: would be actually better to call match begin once the map has actually loaded and game started
		// but it doesn't matter really
		$this->metagame->post_begin_match();
	}
}


?>