예제 #1
0
	//called when the current selected player unit has used up all available move
	public static void SwitchToNextUnitInTurn(){
		GridManager.Deselect();
		
		_TurnMode turnMode=GameControlTB.GetTurnMode();
		
		//select next unit for this round,  if all unit has been moved, start new round
		if(turnMode==_TurnMode.SingleUnitPerTurn){
			currentUnitTurnID+=1;
			if(currentUnitTurnID>=instance.allUnits.Count){
				currentUnitTurnID=-1;
				//if all unit has been moved, issue a new round,
				GameControlTB.OnNewRound();
			}
			else{
				//Unit with the highest turnPriority move first
				//all unit has been arrange in order using function ArrangeAllUnitToTurnPriority() at every new round, check OnNewRound
				//so we simply select next unit based on currentUnitTurnID
				selectedUnit=instance.allUnits[currentUnitTurnID];
				selectedUnit.occupiedTile.Select();
				
				GameControlTB.turnID=selectedUnit.factionID;
				
				if(!GameControlTB.IsPlayerFaction(selectedUnit.factionID)) AIManager.MoveUnit(selectedUnit);
				//if(selectedUnit.factionID!=GameControlTB.GetPlayerFactionID()) AIManager.MoveUnit(selectedUnit);
			}
		}
		else if(turnMode==_TurnMode.SingleUnitRealTime || turnMode==_TurnMode.SingleUnitRealTimeNoRound){
			
			if(turnMode==_TurnMode.SingleUnitRealTime){
				if(instance.allUnitsMoved.Count==instance.allUnits.Count){
					GameControlTB.OnNewRound();
					instance.allUnitsMoved=new List<UnitTB>();
					return;
				}
			}
			
			float lowest=100000;
			instance.holdWaitedTime=false;
			UnitTB currentSelected=null;
			
			for(int i=0; i<instance.allUnits.Count; i++){
				UnitTB unit=instance.allUnits[i];
				if(unit.waitedTime<=0){
					if(unit.waitedTime==lowest) {
						instance.holdWaitedTime=true;
					}
					if(unit.waitedTime<lowest){
						lowest=unit.waitedTime;
						currentSelected=unit;
					}
				}
			}
			
			if(currentSelected==null){
				instance.OnNextTurn();
				return;
			}
			
			selectedUnit=currentSelected;
			selectedUnit.waitedTime=selectedUnit.waitingTime;
			selectedUnit.OnNewRound(0);
			selectedUnit.occupiedTile.Select();
			if(!instance.allUnitsMoved.Contains(selectedUnit)) instance.allUnitsMoved.Add(selectedUnit);
			
			GameControlTB.turnID=selectedUnit.factionID;
			
			if(!GameControlTB.IsPlayerFaction(selectedUnit.factionID)) AIManager.MoveUnit(selectedUnit);
			//if(selectedUnit.factionID!=GameControlTB.GetPlayerFactionID()) AIManager.MoveUnit(selectedUnit);
		}
		else{
			if(turnMode==_TurnMode.FactionAllUnitPerTurn){
				//when in FactionAllUnitPerTurn
				//this section is only called when the faction in turn belongs to player
				//otherwise AIROutine is called to move all AI's units
				if(!GameControlTB.IsPlayerTurn()) return;
			}
			
			//get the faction in turn and make sure a unit has been selected successfully
			Faction faction=instance.allFactionList[GameControlTB.turnID];
			if(!instance.SelectNexUnit(faction)) return;
			
			if(turnMode!=_TurnMode.FactionAllUnitPerTurn){
				//if the selecte unit doesnt belong to player, call AI to move the unit
				if(!GameControlTB.IsPlayerFaction(selectedUnit.factionID)){
					AIManager.MoveUnit(selectedUnit);
				}
				else{
					//Debug.Log("UC unit switched, player's turn");
				}
				//if(selectedUnit.factionID!=GameControlTB.GetPlayerFactionID()) AIManager.MoveUnit(selectedUnit);
			}
		}
	}