// when the player captures a city it will add upgrade points to their daily pool
// by default the player will start off with 1 town already controled

function CaptureCity()
{
   %list = sg.PickPoint(player.GetPosition());
   
   %count = getWordCount(%list);
   
   for(%i=0;%i<%count;%i++)
   {
      %obj = getWord(%list, %i);
      
      if(%obj.city !$= "")
         %cityname = %obj.city;   
      if(%obj.silo !$= "")
         %silo = true;
   }
   
   if(%silo $= true)
      return;
   
   if(%cityname $= "")
   {
      alxPlay(buzzer);
      return;      
   }
   
   if($CityList[%cityname] $= "" || $CityList[%cityname] $= 0)
   {
      alxPlay(buzzer);
      Infowindow.Visible = true;
      InfoYesbutton.Visible = false;
      InfoNobutton.Visible = false;
      Infocontinuebutton.Visible = true;
      Infocontinuebutton.command = "Infowindow.Visible = false;";   

      Infotext.setText("Your gang already has control of this city.");
      return;
   }
   
   echo("CITY CAPTURE CLICK");
   alxPlay(click);
   
   UpdateTime();
   
   AutoSave();
   
   $CitySoldierList = $CityList[%cityname];
   $citycapturename = %cityname;

   StartPeopleBattle();   
}

function ShowCityBattleReport()
{  
   InfoWindow.Visible = true;
   InfoNobutton.Visible = false;
   InfoYesbutton.Visible = false;   
   Infocontinuebutton.Visible = true;
   
   // if they have taken over the town

   $CityList[$citycapturename] = 0;

   InfoText.SetText("You have taken over the city!");
   $CapturedCities++;
   $UpgradePoints++;
   
   for(%i=1;%i<=150;%i++)
   {
      if($CapturedCities[%i] $= "")
      {
         $CapturedCities[%i] = $citycapturename;
         break;
      }
   }
   
   IncreaseMorale();

   // change command of continue button to close window
   
   InfoContinuebutton.Command = "GetSuppliesAfterCityCombat();";      
   
   $citycapturename = "";
   $CitySoldierList = "";
}

function GetSuppliesAfterCityCombat()
{
   $SearchIndex = 1;
   $foodFound = "";
   $gunsFound = "";
   $ammoFound = "";
   $medicineFound = "";
   $tiresFound = "";
   $sparepartsFound = "";   
   $fuelFound = "";

   $gunsFound = $EnemyInfantry;
      
   $ammoFound = getRandom(5, 125);
   
   %spare = GetTotalSupplyCapacity() - GetCurrentSupplyCount();
   
   %ammo = %ammo / 10;
   %count = %ammo+$gunsFound;
   
   if(%count <= %spare)         
      SearchReturn();  
   else
      Infowindow.Visible = false;   
}

// this will be called once a day

function AddUpgradePoints()
{
   $UpgradePoints = $UpgradePoints+$CapturedCities;
   
   if($UpgradePoints > 999)
      $UpgradePoints = 999;
         
   UpdateStatsBar();
}

// this only gets called once at the start of the game to randomly put a controlling gang population in

function BuildCityPopulation()
{
   %rand = getRandom(15, 30);
   $CityList[NewYork] = %rand;
   %rand = getRandom(15, 30);
   $CityList[LosAngeles] = %rand;
   %rand = getRandom(15, 30);
   $CityList[Chicago] = %rand;
   %rand = getRandom(15, 30);
   $CityList[Houston] = %rand;
   %rand = getRandom(15, 30);
   $CityList[Phoenix] = %rand;
   %rand = getRandom(15, 30);
   $CityList[Philadelphia] = %rand;
   %rand = getRandom(15, 30);
   $CityList[SanAntonio] = %rand;
   %rand = getRandom(15, 30);
   $CityList[Dallas] = %rand;
   %rand = getRandom(15, 30);
   $CityList[SanDiego] = %rand;
   %rand = getRandom(15, 30);
   $CityList[Detroit] = %rand;
   %rand = getRandom(15, 30);
   $CityList[SanFrancisco] = %rand;
   %rand = getRandom(15, 30);
   $CityList[Jacksonville] = %rand;
   %rand = getRandom(15, 30);
   $CityList[Austin] = %rand;
   %rand = getRandom(15, 30);
   $CityList[Columbus] = %rand;
   %rand = getRandom(15, 30);
   $CityList[Charlotte] = %rand;
   %rand = getRandom(15, 30);
   $CityList[Memphis] = %rand;
   %rand = getRandom(15, 30);
   $CityList[Baltimore] = %rand;
   %rand = getRandom(15, 30);
   $CityList[ElPaso] = %rand;
   %rand = getRandom(15, 30);
   $CityList[Boston] = %rand;
   %rand = getRandom(15, 30);
   $CityList[Denver] = %rand;
   %rand = getRandom(15, 30);
   $CityList[Seattle] = %rand;
   %rand = getRandom(15, 30);
   $CityList[Nashville] = %rand;
   %rand = getRandom(15, 30);
   $CityList[Washington] = %rand;
   %rand = getRandom(15, 30);
   $CityList[LasVegas] = %rand;
   %rand = getRandom(15, 30);
   $CityList[Portland] = %rand;
   %rand = getRandom(15, 30);
   $CityList[Louisville] = %rand;
   %rand = getRandom(15, 30);
   $CityList[Tucson] = %rand;
   %rand = getRandom(15, 30);
   $CityList[Atlanta] = %rand;
   %rand = getRandom(15, 30);
   $CityList[Albuqurque] = %rand;
   %rand = getRandom(15, 30);
   $CityList[Fresno] = %rand;
   %rand = getRandom(15, 30);
   $CityList[Sacramento] = %rand;
   %rand = getRandom(15, 30);
   $CityList[KansasCity] = %rand;
   %rand = getRandom(15, 30);
   $CityList[Omaha] = %rand;
   %rand = getRandom(15, 30);
   $CityList[Cleveland] = %rand;
   %rand = getRandom(15, 30);
   $CityList[Miami] = %rand;
   %rand = getRandom(15, 30);
   $CityList[Raleigh] = %rand;
   %rand = getRandom(15, 30);
   $CityList[Tulsa] = %rand;
   %rand = getRandom(15, 30);
   $CityList[Minneapolis] = %rand;
   %rand = getRandom(15, 30);
   $CityList[ColoradoSprings] = %rand;
   %rand = getRandom(15, 30);
   $CityList[Wichita] = %rand;
   %rand = getRandom(15, 30);
   $CityList[StLouis] = %rand;
   %rand = getRandom(15, 30);
   $CityList[Tampa] = %rand;
   %rand = getRandom(15, 30);
   $CityList[Bakersfield] = %rand;
   %rand = getRandom(15, 30);
   $CityList[NewOrleans] = %rand;
   %rand = getRandom(15, 30);
   $CityList[Pittsburgh] = %rand;
   %rand = getRandom(15, 30);
   $CityList[Riverside] = %rand;
   %rand = getRandom(15, 30);
   $CityList[Stockton] = %rand;
   %rand = getRandom(15, 30);
   $CityList[CorpusChristi] = %rand;
   %rand = getRandom(15, 30);
   $CityList[Buffalo] = %rand;
   %rand = getRandom(15, 30);
   $CityList[JerseyCity] = %rand;
   %rand = getRandom(15, 30);
   $CityList[Norfolk] = %rand;
   %rand = getRandom(15, 30);
   $CityList[Orlando] = %rand;
   %rand = getRandom(15, 30);
   $CityList[Birmingham] = %rand;
   %rand = getRandom(15, 30);
   $CityList[Reno] = %rand;
   %rand = getRandom(15, 30);
   $CityList[SaltLakeCity] = %rand;   
   %rand = getRandom(15, 30);
   $CityList[Spokane] = %rand;   
}

function DisplayCity(%cityname)
{
   switch$ (%cityname)
   {
      case "NewYork":
         return "New York";
      case "LosAngeles":
         return "Los Angeles";
      case "SanAntonio":
         return "San Antonio";
      case "SanDiego":
         return "San Diego";
      case "SanFrancisco":
         return "San Francisco";
      case "FortWorth":
         return "Fort Worth";
      case "ElPaso":
         return "El Paso";
      case "LasVegas":
         return "Las Vegas";
      case "LongBeach":
         return "Long Beach";
      case "KansasCity":
         return "Kansas City";
      case "ColoradoSprings":
         return "Colorado Springs";
      case "NewOrleans":
         return "New Orleans";
      case "CorpusChristi":
         return "Corpus Christi";
      case "JerseyCity":
         return "Jersey City";
      case "SaltLakeCity":   
         return "Salt Lake City";
      case "StLouis":   
         return "St. Louis";
   }
}
   