<commit_before>using UnityEngine;
using UnityEngine.UI;
using System.Collections.Generic;

public class CameraControls : MonoBehaviour {

	RaycastHit2D hit;
	public GameObject hitObject;
	public GameObject selected;
	public GameObject lastSelected;
	public GameObject selectorParticle;
	public GameObject CameraNWEdge;
	public GameObject CameraSEEdge;
	public GameObject player1Base;
	public GameObject player2Base;

	// dynamic UI elements
	public Text moveText;
	public Text actionText;
	public Text healthText;
	public Text attackText;
	public Text playerText;
	public Text oilText;
	public Text goldText;
	public Text oreText;
	public Text lossText;
	public Button endTurn;
	public Button lossButton;
	public Button buildButton;
	public GameObject actionPanel;
	public GameObject lossPanel;

	// red unit prefabs
	public GameObject SettlerBotRedPrefab;
	public GameObject HeavyBotRedPrefab;
	public GameObject MeleeBotRedPrefab;
	public GameObject WorkerBotRedPrefab;
	public GameObject RangedBotRedPrefab;
	public GameObject BaseRedPrefab;

	// blue unit prefabs
	public GameObject SettlerBotBluePrefab;
	public GameObject HeavyBotBluePrefab;
	public GameObject MeleeBotBluePrefab;
	public GameObject WorkerBotBluePrefab;
	public GameObject RangedBotBluePrefab;
	public GameObject BaseBluePrefab;

	// get level init object (for player lists, unit lists)
	public GameObject levelInit;

	// turn bool
	int turn;

	// camera move bool
	bool moveBool;
	int cameraMin;
	int cameraMax;
	float scrollValue;

	// vector for movement target (always lerps here)
	public Vector3 moveCoordinates;

	// mouse location values
	public float mouseX;
	public float mouseY;
	public float mouseZ;

	
	// bool to stop camera movement
	public bool paused;

	// keep track of current player
	public int currentPlayer;

	// When a player buys a unit it is stored here until it is placed.
	public UnitType UnitToPlace { get; set; }
		
	// Use this for initialization
	void Start () {
		UnitToPlace = UnitType.None;
		currentPlayer = 1;
		moveBool = false;
		lastSelected = null;
		paused = false;
		turn = 1;

		cameraMax = 10;
		cameraMin = 1;
		scrollValue = 0F;
	}

	// sets camera focus on end turn for the given player, the camera flies to this object on their turn start
	void SetBase(int playerID, GameObject baseObject) {
		if (playerID == 1) {
			player1Base = baseObject;
		} 
		else if (playerID == 2) {
			player2Base = baseObject;
		}
	}

	// function to grab selector particle (called in init after it is created
	void SetParams() {

		// setup camera params
		selectorParticle = GameObject.FindGameObjectWithTag ("Selector Particle");
		CameraNWEdge = GameObject.FindGameObjectWithTag ("Map NW Corner");
		CameraSEEdge = GameObject.FindGameObjectWithTag ("Map SE Corner");
	}

	// set camera to other player between turns
	public void TakeTurn() {
		if (turn == 1) {

			// do turn bookkeeping
			levelInit.GetComponent<LevelInit> ().player2.TakeTurn ();
			turn = 0;

			// move camera to player 2's base
			MoveTo (player2Base);
			currentPlayer = 2;
			playerText.text = "Player 2";
			UIResourceUpdate();
		} 
		else {

			// do turn bookkeeping
			levelInit.GetComponent<LevelInit>().player1.TakeTurn ();
			turn = 1;

			// move camera to player 1's base
			MoveTo (player1Base);
			currentPlayer = 1;
			playerText.text = "Player 1";
			UIResourceUpdate();
		}
	}

	// function to end game (given player number loses)
	public void PlayerLoss(int playerNumber) {

		// enable loss panel
		lossPanel.SetActive (true);

		// check who lost, set text accordingly
		if (playerNumber == 1) {
			lossText.text = "Player 2 Wins!";
		}
		else {
			lossText.text = "Player 1 Wins!";
		}
	}

	// function to freely move camera to a target
	public void MoveTo(GameObject target) {
		moveCoordinates = new Vector3(target.transform.position.x, target.transform.position.y, -10);
		moveBool = true; 
	}

	// function to set up UI when a pawn is clicked;
	void UIUpdatePawnInfo(GameObject target, int owned) {
		// set color and correct numbers for moves/actions on UI

		// check if we have selected something
		if (target != null) {

			// check if the unit even has a pawn controller
			PawnController targetUnit = target.GetComponent<PawnController>();

			if (owned == 1) {
				// if it is movable, display moves and actions
				if (targetUnit.movable == true) {

					moveText.color = Color.black;
					moveText.text = "Moves Remaining:\t" + targetUnit.currentMoves.ToString ();
				}

				if (targetUnit.canAct == true) {
					buildButton.interactable = true;
				}

				// in all cases, display actions, health, and attack (even if 0)
				actionText.color = Color.black;
				actionText.text = "Actions Remaining:\t" + targetUnit.currentActions.ToString ();

				healthText.color = Color.black;
				healthText.text = "Unit Health:\t\t" + targetUnit.health.ToString ();

				attackText.color = Color.black;
				attackText.text = "Attack Power:\t" + targetUnit.attackDamage.ToString ();

				// activate actionPanel color
				actionPanel.GetComponent<Image>().color = Color.red;

				// Check unit type, build button for unit

			}
			else {
				healthText.color = Color.black;
				healthText.text = "Unit Health:\t\t" + targetUnit.health.ToString ();

				moveText.color = Color.grey;
				moveText.text = "Moves Remaining:";
				
				actionText.color = Color.grey;
				actionText.text = "Actions Remaining:";
				
				attackText.color = Color.grey;
				attackText.text = "Attack Power:";

				actionPanel.GetComponent<Image>().color = Color.black;
			}
		}
	}

	// function to remove UI elements when a pawn is clicked
	void UIDeselectPawn() {
		// assume no pawn is selected now
		moveText.color = Color.grey;
		moveText.text = "Moves Remaining:";
		
		actionText.color = Color.grey;
		actionText.text = "Actions Remaining:";
		
		healthText.color = Color.grey;
		healthText.text = "Unit Health:";
		
		attackText.color = Color.grey;
		attackText.text = "Attack Power:";
		
		// activate actionPanel color
		actionPanel.GetComponent<Image>().color = Color.grey;

		if (lastSelected != null) {
			if (lastSelected.GetComponent<PawnController> ().canAct != true) {
				buildButton.interactable = false;
			}
		}
	}

	// function to update resource UI
	public void UIResourceUpdate() {
		// update all UI text as above on resource panel
		PlayerController player = GetPlayerController ();

		oilText.text = "Oil:\t" + player.oilCount.ToString ();
		goldText.text = "Gold:\t" + player.goldCount.ToString ();
		oreText.text = "Ore:\t" + player.oreCount.ToString ();
	}

	// function to choose the unit to spawn based off of unittype
	public void SpawnSelection (UnitType unit) {

		UnitToPlace = unit;
		GameObject chosenPrefab = null;
		bool resetBase = false;
		PlayerController player = GetPlayerController ();

		// check which player (determines color prefab set)
		if (currentPlayer == 1) {

			switch (UnitToPlace) {
			
			case UnitType.Base: 
				chosenPrefab = BaseRedPrefab;
				resetBase = true;
				break;
			case UnitType.SettlerBot: 
				chosenPrefab = SettlerBotRedPrefab;
				break;
			case UnitType.WorkerBot:
				chosenPrefab = WorkerBotRedPrefab;
				break;
			case UnitType.MeleeBot:
				chosenPrefab = MeleeBotRedPrefab;
				break;
			case UnitType.HeavyBot:
				chosenPrefab = HeavyBotRedPrefab;
				break;
			}
		}
		// player 2 (blue)
		else {

			switch (UnitToPlace) {
				
			case UnitType.Base:
				chosenPrefab = BaseBluePrefab;
				resetBase = true;
				break;
			case UnitType.SettlerBot: 
				chosenPrefab = SettlerBotBluePrefab;
				break;
			case UnitType.WorkerBot:
				chosenPrefab = WorkerBotBluePrefab;
				break;
			case UnitType.MeleeBot:
				chosenPrefab = MeleeBotBluePrefab;
				break;
			case UnitType.HeavyBot:
				chosenPrefab = HeavyBotBluePrefab;
				break;
			default:
				throw new UnityException ("Built a unit with an unsupported UnitType");
				//break;
			}
		}

		if ((player.BuyUnit (chosenPrefab)) == 0) {
			if ((chosenPrefab = (GameObject)(SpawnPawn (chosenPrefab, lastSelected.GetComponent<PawnController>().currentTile, currentPlayer, UnitToPlace))) == null) {
				// show UI panel saying no valid spawn location around building unit
			}
			else {
				if (resetBase) {
					if (currentPlayer == 1) {
						player1Base = chosenPrefab;
					}
					else {
						player2Base = chosenPrefab;
					}
				}
			}
		} 
		else {
			// show UI panel saying the player can't afford it
		}
		
		// The unit has been placed.
		UnitToPlace = UnitType.None;
		UIResourceUpdate ();
	}

	// spawn an arbitrary pawn at spawnTileLocation. Spawns beside tile location (or not at all)
	public GameObject SpawnPawn(GameObject spawnPrefab, GameObject spawnTileLocation, int owningPlayer, UnitType unitType) {

		// check if this tile exists
		if (spawnTileLocation != null) {

			GroundScript spawnTile = spawnTileLocation.GetComponent<GroundScript> ();<commit_msg>Show notification for when the player can't afford a robot.<commit_after>using UnityEngine;
using UnityEngine.UI;
using System.Collections.Generic;

public class CameraControls : MonoBehaviour {

	RaycastHit2D hit;
	public GameObject hitObject;
	public GameObject selected;
	public GameObject lastSelected;
	public GameObject selectorParticle;
	public GameObject CameraNWEdge;
	public GameObject CameraSEEdge;
	public GameObject player1Base;
	public GameObject player2Base;

	// dynamic UI elements
	public Text moveText;
	public Text actionText;
	public Text healthText;
	public Text attackText;
	public Text playerText;
	public Text oilText;
	public Text goldText;
	public Text oreText;
	public Text lossText;
	public Button endTurn;
	public Button lossButton;
	public Button buildButton;
	public GameObject actionPanel;
	public GameObject lossPanel;

	// red unit prefabs
	public GameObject SettlerBotRedPrefab;
	public GameObject HeavyBotRedPrefab;
	public GameObject MeleeBotRedPrefab;
	public GameObject WorkerBotRedPrefab;
	public GameObject RangedBotRedPrefab;
	public GameObject BaseRedPrefab;

	// blue unit prefabs
	public GameObject SettlerBotBluePrefab;
	public GameObject HeavyBotBluePrefab;
	public GameObject MeleeBotBluePrefab;
	public GameObject WorkerBotBluePrefab;
	public GameObject RangedBotBluePrefab;
	public GameObject BaseBluePrefab;

	// get level init object (for player lists, unit lists)
	public GameObject levelInit;

	// turn bool
	int turn;

	// camera move bool
	bool moveBool;
	int cameraMin;
	int cameraMax;
	float scrollValue;

	// vector for movement target (always lerps here)
	public Vector3 moveCoordinates;

	// mouse location values
	public float mouseX;
	public float mouseY;
	public float mouseZ;

	
	// bool to stop camera movement
	public bool paused;

	// keep track of current player
	public int currentPlayer;

	// When a player buys a unit it is stored here until it is placed.
	public UnitType UnitToPlace { get; set; }
		
	// Use this for initialization
	void Start () {
		UnitToPlace = UnitType.None;
		currentPlayer = 1;
		moveBool = false;
		lastSelected = null;
		paused = false;
		turn = 1;

		cameraMax = 10;
		cameraMin = 1;
		scrollValue = 0F;
	}

	// sets camera focus on end turn for the given player, the camera flies to this object on their turn start
	void SetBase(int playerID, GameObject baseObject) {
		if (playerID == 1) {
			player1Base = baseObject;
		} 
		else if (playerID == 2) {
			player2Base = baseObject;
		}
	}

	// function to grab selector particle (called in init after it is created
	void SetParams() {

		// setup camera params
		selectorParticle = GameObject.FindGameObjectWithTag ("Selector Particle");
		CameraNWEdge = GameObject.FindGameObjectWithTag ("Map NW Corner");
		CameraSEEdge = GameObject.FindGameObjectWithTag ("Map SE Corner");
	}

	// set camera to other player between turns
	public void TakeTurn() {
		if (turn == 1) {

			// do turn bookkeeping
			levelInit.GetComponent<LevelInit> ().player2.TakeTurn ();
			turn = 0;

			// move camera to player 2's base
			MoveTo (player2Base);
			currentPlayer = 2;
			playerText.text = "Player 2";
			UIResourceUpdate();
		} 
		else {

			// do turn bookkeeping
			levelInit.GetComponent<LevelInit>().player1.TakeTurn ();
			turn = 1;

			// move camera to player 1's base
			MoveTo (player1Base);
			currentPlayer = 1;
			playerText.text = "Player 1";
			UIResourceUpdate();
		}
	}

	// function to end game (given player number loses)
	public void PlayerLoss(int playerNumber) {

		// enable loss panel
		lossPanel.SetActive (true);

		// check who lost, set text accordingly
		if (playerNumber == 1) {
			lossText.text = "Player 2 Wins!";
		}
		else {
			lossText.text = "Player 1 Wins!";
		}
	}

	// function to freely move camera to a target
	public void MoveTo(GameObject target) {
		moveCoordinates = new Vector3(target.transform.position.x, target.transform.position.y, -10);
		moveBool = true; 
	}

	// function to set up UI when a pawn is clicked;
	void UIUpdatePawnInfo(GameObject target, int owned) {
		// set color and correct numbers for moves/actions on UI

		// check if we have selected something
		if (target != null) {

			// check if the unit even has a pawn controller
			PawnController targetUnit = target.GetComponent<PawnController>();

			if (owned == 1) {
				// if it is movable, display moves and actions
				if (targetUnit.movable == true) {

					moveText.color = Color.black;
					moveText.text = "Moves Remaining:\t" + targetUnit.currentMoves.ToString ();
				}

				if (targetUnit.canAct == true) {
					buildButton.interactable = true;
				}

				// in all cases, display actions, health, and attack (even if 0)
				actionText.color = Color.black;
				actionText.text = "Actions Remaining:\t" + targetUnit.currentActions.ToString ();

				healthText.color = Color.black;
				healthText.text = "Unit Health:\t\t" + targetUnit.health.ToString ();

				attackText.color = Color.black;
				attackText.text = "Attack Power:\t" + targetUnit.attackDamage.ToString ();

				// activate actionPanel color
				actionPanel.GetComponent<Image>().color = Color.red;

				// Check unit type, build button for unit

			}
			else {
				healthText.color = Color.black;
				healthText.text = "Unit Health:\t\t" + targetUnit.health.ToString ();

				moveText.color = Color.grey;
				moveText.text = "Moves Remaining:";
				
				actionText.color = Color.grey;
				actionText.text = "Actions Remaining:";
				
				attackText.color = Color.grey;
				attackText.text = "Attack Power:";

				actionPanel.GetComponent<Image>().color = Color.black;
			}
		}
	}

	// function to remove UI elements when a pawn is clicked
	void UIDeselectPawn() {
		// assume no pawn is selected now
		moveText.color = Color.grey;
		moveText.text = "Moves Remaining:";
		
		actionText.color = Color.grey;
		actionText.text = "Actions Remaining:";
		
		healthText.color = Color.grey;
		healthText.text = "Unit Health:";
		
		attackText.color = Color.grey;
		attackText.text = "Attack Power:";
		
		// activate actionPanel color
		actionPanel.GetComponent<Image>().color = Color.grey;

		if (lastSelected != null) {
			if (lastSelected.GetComponent<PawnController> ().canAct != true) {
				buildButton.interactable = false;
			}
		}
	}

	// function to update resource UI
	public void UIResourceUpdate() {
		// update all UI text as above on resource panel
		PlayerController player = GetPlayerController ();

		oilText.text = "Oil:\t" + player.oilCount.ToString ();
		goldText.text = "Gold:\t" + player.goldCount.ToString ();
		oreText.text = "Ore:\t" + player.oreCount.ToString ();
	}

	// function to choose the unit to spawn based off of unittype
	public void SpawnSelection (UnitType unit) {

		UnitToPlace = unit;
		GameObject chosenPrefab = null;
		bool resetBase = false;
		PlayerController player = GetPlayerController ();

		// check which player (determines color prefab set)
		if (currentPlayer == 1) {

			switch (UnitToPlace) {
			
			case UnitType.Base: 
				chosenPrefab = BaseRedPrefab;
				resetBase = true;
				break;
			case UnitType.SettlerBot: 
				chosenPrefab = SettlerBotRedPrefab;
				break;
			case UnitType.WorkerBot:
				chosenPrefab = WorkerBotRedPrefab;
				break;
			case UnitType.MeleeBot:
				chosenPrefab = MeleeBotRedPrefab;
				break;
			case UnitType.HeavyBot:
				chosenPrefab = HeavyBotRedPrefab;
				break;
			}
		}
		// player 2 (blue)
		else {

			switch (UnitToPlace) {
				
			case UnitType.Base:
				chosenPrefab = BaseBluePrefab;
				resetBase = true;
				break;
			case UnitType.SettlerBot: 
				chosenPrefab = SettlerBotBluePrefab;
				break;
			case UnitType.WorkerBot:
				chosenPrefab = WorkerBotBluePrefab;
				break;
			case UnitType.MeleeBot:
				chosenPrefab = MeleeBotBluePrefab;
				break;
			case UnitType.HeavyBot:
				chosenPrefab = HeavyBotBluePrefab;
				break;
			default:
				throw new UnityException ("Built a unit with an unsupported UnitType");
				//break;
			}
		}

		if ((player.BuyUnit (chosenPrefab)) == 0) {
			if ((chosenPrefab = (GameObject)(SpawnPawn (chosenPrefab, lastSelected.GetComponent<PawnController>().currentTile, currentPlayer, UnitToPlace))) == null) {
				// show UI panel saying no valid spawn location around building unit
			}
			else {
				if (resetBase) {
					if (currentPlayer == 1) {
						player1Base = chosenPrefab;
					}
					else {
						player2Base = chosenPrefab;
					}
				}
			}
		} 
		else {
			// show UI panel saying the player can't afford it
			GetComponent<NotificationController> ().ShowNotification ("You can not afford this robot.");
		}
		
		// The unit has been placed.
		UnitToPlace = UnitType.None;
		UIResourceUpdate ();
	}

	// spawn an arbitrary pawn at spawnTileLocation. Spawns beside tile location (or not at all)
	public GameObject SpawnPawn(GameObject spawnPrefab, GameObject spawnTileLocation, int owningPlayer, UnitType unitType) {

		// check if this tile exists
		if (spawnTileLocation != null) {

			GroundScript spawnTile = spawnTileLocation.GetComponent<GroundScript> ();
{'fraction_non_alphanumeric': 0.09263803680981596, 'fraction_numerical': 0.004573340769659788, 'mean_word_length': 3.4405646359583955, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7368624', 'n_tokens_mistral': 6484, 'n_tokens_neox': 5339, 'n_words': 1659}