Ejemplo n.º 1
0
    // Start is called before the first frame update
    void Start()
    {
        GameObject parent = transform.parent.gameObject;

        if (parent.GetComponent <Master>() != null)
        {
            typ = Typ.master; master = parent.GetComponent <Master>();
        }
        else if (parent.GetComponent <ToolShop>() != null)
        {
            typ = Typ.toolshop; toolShop = parent.GetComponent <ToolShop>();
        }
        else if (parent.GetComponent <IronPile>() != null)
        {
            typ = Typ.ironpile; ironPile = parent.GetComponent <IronPile>();
        }
        else if (parent.GetComponent <BuildSite>() != null)
        {
            typ = Typ.buildsite; buildSite = parent.GetComponent <BuildSite>();
        }
        else if (parent.GetComponent <Farm>() != null)
        {
            typ = Typ.farm; farm = parent.GetComponent <Farm>();
        }
        else
        {
            throw new System.NotImplementedException("typ not available yet for go: " + parent);
        }
    }
Ejemplo n.º 2
0
    public void SpawnUnitFromNetwork(int unitType, int unitIndex, int factionIndexMod)
    {
        UnitType  type = (UnitType)(unitType - 1);
        BuildSite site = null;

        foreach (Unit b in GameObject.Find("CellGrid").GetComponent <CellGrid>().Units)
        {
            if (b is BuildSite && (b as BuildSite).unitIndex == unitIndex)
            {
                site = b as BuildSite;
                break;
            }
        }

        if (site == null)
        {
            return;
        }
        GameObject newUnit = CreateNewUnit(factionIndexMod, site, type);

        site.spawnUnit = true;

        if (!site.Cell.IsTaken && site.spawnUnit && site.CanSpawnUnit(newUnit.GetComponent <Unit>()))
        {
            site.hasAlreadySpawned = true;
            site.SpawnUnit(newUnit.GetComponent <Unit>());
        }
        else
        {
            Destroy(newUnit.gameObject);
            newUnit = null;
        }
        site.spawnUnit = false;
    }
Ejemplo n.º 3
0
    public void SpawnAStarFromNetwork(int unitType, int unitIndex)
    {
        UnitType  type = (UnitType)unitType;
        BuildSite site = null;

        foreach (Unit b in GameObject.Find("CellGrid").GetComponent <CellGrid>().Units)
        {
            if (b is BuildSite && (b as BuildSite).unitIndex == unitIndex)
            {
                site = b as BuildSite;
                break;
            }
        }

        if (site == null)
        {
            return;
        }

        GameObject newUnit = Instantiate(aStarUnits[unitType - aStarIndexMod], site.transform.position, Quaternion.identity);

        site.spawnUnit = true;

        if (!site.Cell.IsTaken && site.spawnUnit && site.CanSpawnUnit(newUnit.GetComponent <Unit>()))
        {
            site.hasAlreadySpawned = true;
            site.SpawnUnit(newUnit.GetComponent <Unit>());
        }
        else
        {
            Destroy(newUnit.gameObject);
            newUnit = null;
        }
        site.spawnUnit = false;
    }
Ejemplo n.º 4
0
    private void Update()
    {
        var        cameraRay = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hitInfo;

        if (placeableInstance != null)
        {
            if (Input.GetKeyDown(KeyCode.R))
            {
                placeableInstance.transform.Rotate(new Vector3(0, 90, 0), Space.World);
            }

            if (Input.GetKeyDown(KeyCode.Escape))
            {
                ClearPlaceable();
                return;
            }

            if (CanPlace())
            {
                placeableInstance.GetComponent <Selectable>().ChangeColor(Color.green);
            }
            else
            {
                placeableInstance.GetComponent <Selectable>().ChangeColor(Color.red);
            }

            var selectionManager = SelectionManager.GetInstance();
            if (Physics.Raycast(cameraRay, out hitInfo, float.MaxValue, LayerMask.GetMask("Ground")))
            {
                placeableInstance.transform.position = hitInfo.point;
                if (CanPlace() && Input.GetMouseButtonUp(0) && !EventSystem.current.IsPointerOverGameObject())
                {
                    if (ResourceManager.GetInstance().OffsetAll(-placeableInstance.GetWoodCost(), -placeableInstance.GetStoneCost(), -placeableInstance.GetMetalCost(), 0))
                    {
                        var buildSite = BuildSite.Instantiate(placeableInstance).GetComponent <Assignable>();
                        foreach (var worker in selectionManager.GetSelected().Where(s => s.GetComponent <Worker>() != null).Select(s => s.GetComponent <Worker>()).OrderBy(s => s.IsAssigned()))
                        {
                            if (!buildSite.AddWorker(worker))
                            {
                                break;
                            }
                        }
                        placeableInstance.GetComponent <Selectable>().ChangeColor(Color.clear);
                        placeableInstance = null;
                        selectionManager.DeselectAll();
                        selectionManager.Enable();
                    }
                }
                else if (Input.GetMouseButtonUp(1))
                {
                    ClearPlaceable();
                    return;
                }
            }
        }
    }
Ejemplo n.º 5
0
        // Select the choke point for either the start location or the natural expansions location.
        private bool SelectChoke(bool startChoke)
        {
            // get the distance between start and natural
            BuildSite    site        = Interface().currentBuildSite;
            TilePosition start       = Interface().baseLocations[(int)BuildSite.StartingLocation];
            TilePosition targetChoke = null;
            Chokepoint   chokepoint  = null;

            if (!startChoke)
            {
                targetChoke = Interface().baseLocations[2];
                double distance = start.getDistance(targetChoke);

                // find some kind of measure to determine if the the closest choke to natural is not the once between choke and start but after the natural
                IEnumerable <Chokepoint> chokes = bwta.getChokepoints().Where(ck => bwta.getGroundDistance(new TilePosition(ck.getCenter()), start) > 0).OrderBy(choke => choke.getCenter().getDistance(new Position(targetChoke)));
                if (chokes == null)
                {
                    return(false);
                }
                foreach (Chokepoint ck in chokes)
                {
                    if (bwta.getGroundDistance(new TilePosition(ck.getCenter()), targetChoke) < bwta.getGroundDistance(new TilePosition(ck.getCenter()), start))
                    {
                        chokepoint = ck;
                        break;
                    }
                }
            }
            else
            {
                targetChoke = start;
                chokepoint  = bwta.getChokepoints().Where(ck => bwta.getGroundDistance(new TilePosition(ck.getCenter()), start) > 0).OrderBy(choke => choke.getCenter().getDistance(new Position(start))).First();
            }



            if (chokepoint == null)
            {
                return(false);
            }

            //picking the right side of the choke to position forces
            Interface().forcePoints[ForceLocations.NaturalChoke] = (targetChoke.getDistance(new TilePosition(chokepoint.getSides().first)) < targetChoke.getDistance(new TilePosition(chokepoint.getSides().second))) ? new TilePosition(chokepoint.getSides().first) : new TilePosition(chokepoint.getSides().second);
            Interface().currentForcePoint = ForceLocations.NaturalChoke;

            if (!Interface().baseLocations.ContainsKey((int)BuildSite.Choke))
            {
                Interface().baseLocations.Add(4, Interface().forcePoints[ForceLocations.NaturalChoke]);
            }

            return(true);
        }
Ejemplo n.º 6
0
        void IStarcraftBot.onStart()
        {
            bwapi.Broodwar.setLocalSpeed(0);
            bwapi.Broodwar.setFrameSkip(200);
            System.Console.WriteLine("Starting Match!");
            bwapi.Broodwar.sendText("This is HellBot a poshSHARP based planning agent!");
            mapDim         = new int[2];
            ActivePlayers  = new Dictionary <string, Player>();
            UnitDiscovered = new Dictionary <long, Unit>();
            UnitEvade      = new Dictionary <long, Unit>();
            UnitShow       = new Dictionary <long, Unit>();
            UnitHide       = new Dictionary <long, Unit>();

            UnitCreated   = new Dictionary <long, Unit>();
            UnitDestroyed = new Dictionary <long, Unit>();
            UnitMorphed   = new Dictionary <long, Unit>();
            UnitTrained   = new Dictionary <long, Unit>();
            UnitRenegade  = new Dictionary <long, Unit>();

            baseLocations    = new Dictionary <int, TilePosition>();
            currentBuildSite = BuildSite.StartingLocation;

            foreach (Player pl in bwapi.Broodwar.getPlayers())
            {
                ActivePlayers.Add(pl.getName(), pl);
            }
            if (ActivePlayers.ContainsKey(Self().getName()))
            {
                ActivePlayers.Remove(Self().getName());
            }

            forces      = new Dictionary <ForceLocations, List <UnitAgent> >();
            forcePoints = new Dictionary <ForceLocations, TilePosition>();

            // initiating the starting location
            if (Self().getStartLocation() is TilePosition)
            {
                baseLocations[(int)BuildSite.StartingLocation] = Self().getStartLocation();
                forcePoints[ForceLocations.OwnStart]           = Self().getStartLocation();
            }

            // Get all base locations to be used for scouting and attacking
            basePositions = bwta.getBaseLocations().Where(baseLoc => bwta.getGroundDistance(Self().getStartLocation(), baseLoc.getTilePosition()) > 0).OrderBy(baseLoc => bwta.getGroundDistance(Self().getStartLocation(), baseLoc.getTilePosition()));
            basePositions.Reverse();

            currentForcePoint = ForceLocations.OwnStart;
            currentBuildSite  = BuildSite.StartingLocation;
        }
Ejemplo n.º 7
0
        public void Execute(ServiceObject service)
        {
            BuildTemplate.CreateProxyClass(service);

            var projectPath = String.Format("{0}/{1}.csproj", service.Path, service.Name);

            BuildTemplate.Restore(@"\Modules\Build\Resource\nuget.exe", projectPath);

            BuildTemplate.Build(projectPath, service.MsBuildPath);

            BuildSite.Create(service.Name, service.Port, service.IISPath);

            var binWebSitePath = String.Format("{0}/{1}", service.IISPath, service.Name);

            BuildTemplate.MoveBin(service.Path, binWebSitePath);
        }
Ejemplo n.º 8
0
    public void SpawnUnitWithButton(int unitType, int factionIndexMod)
    {
        UnitType  type = (UnitType)(unitType);
        BuildSite site = null;

        foreach (Unit b in GameObject.Find("CellGrid").GetComponent <CellGrid>().Units)
        {
            if (b is BuildSite && (b as BuildSite).selected)
            {
                site = b as BuildSite;
                break;
            }
        }

        if (site == null)
        {
            return;
        }

        Debug.Log(unitType.ToString() + " + " + factionIndexMod.ToString());
        GameObject newUnit = CreateNewUnit(factionIndexMod, site, type);

        //GameObject newUnit = Instantiate(aStarUnits[unitType - factionIndexMod], site.transform.position, Quaternion.identity);
        type           = (UnitType)(unitType + factionIndexMod);
        site.spawnUnit = true;

        if (!site.Cell.IsTaken && site.spawnUnit && site.selected && site.CanSpawnUnit(newUnit.GetComponent <Unit>()))
        {
            site.hasAlreadySpawned = true;
            site.SpawnUnit(newUnit.GetComponent <Unit>());
            UnitUpdate update = new UnitUpdate();
            update.newLocationX = site.transform.position.x;
            update.newLocationY = site.transform.position.y;
            update.command      = UnitUpdateCommand.SPAWN;
            update.moving       = site.unitIndex;
            update.type         = type;
            NetManager.SendData(TagIndex.Controller, TagIndex.PlayerUpdate, update);
        }
        else
        {
            Destroy(newUnit.gameObject);
            newUnit = null;
        }
        site.spawnUnit = false;
    }
Ejemplo n.º 9
0
    GameObject CreateNewUnit(int factionIndex, BuildSite site, UnitType type)
    {
        int index = (int)type + (factionIndex);

        if (factionIndex >= usbIndexMod)
        {
            return(Instantiate(usbFactionUnits[index - usbIndexMod], site.transform.position, Quaternion.identity));
        }
        else if (factionIndex >= iFactIndexMod)
        {
            return(Instantiate(iFactionUnits[index - iFactIndexMod], site.transform.position, Quaternion.identity));
        }
        else if (factionIndex >= aStarIndexMod)
        {
            return(Instantiate(aStarUnits[index - aStarIndexMod], site.transform.position, Quaternion.identity));
        }
        return(null);
    }
Ejemplo n.º 10
0
    public void SpawniFactionWithButton(int unitType)
    {
        UnitType  type = (UnitType)unitType;
        BuildSite site = null;

        foreach (Unit b in GameObject.Find("CellGrid").GetComponent <CellGrid>().Units)
        {
            if (b is BuildSite && (b as BuildSite).selected)
            {
                site = b as BuildSite;
                break;
            }
        }

        if (site == null)
        {
            return;
        }

        GameObject newUnit = Instantiate(iFactionUnits[unitType - iFactIndexMod], site.transform.position, Quaternion.identity);

        site.spawnUnit             = true;
        newUnit.transform.position = new Vector3(newUnit.transform.position.x, newUnit.transform.position.y, -1.0f);

        if (!site.Cell.IsTaken && site.spawnUnit && site.selected && site.CanSpawnUnit(newUnit.GetComponent <Unit>()))
        {
            site.hasAlreadySpawned = true;
            site.SpawnUnit(newUnit.GetComponent <Unit>());
            UnitUpdate update = new UnitUpdate();
            update.newLocationX = site.transform.position.x;
            update.newLocationY = site.transform.position.y;
            update.command      = UnitUpdateCommand.SPAWN;
            update.moving       = site.unitIndex;
            update.type         = type;
            NetManager.SendData(TagIndex.Controller, TagIndex.PlayerUpdate, update);
        }
        else
        {
            Destroy(newUnit.gameObject);
            newUnit = null;
        }
        site.spawnUnit = false;
    }
        void IStarcraftBot.onStart()
        {
            System.Console.WriteLine("Starting Match!");
            bwapi.Broodwar.sendText("Hello world! This is POSH!");
            mapDim         = new int[2];
            ActivePlayers  = new Dictionary <string, Player>();
            UnitDiscovered = new Dictionary <long, Unit>();
            UnitEvade      = new Dictionary <long, Unit>();
            UnitShow       = new Dictionary <long, Unit>();
            UnitHide       = new Dictionary <long, Unit>();

            UnitCreated   = new Dictionary <long, Unit>();
            UnitDestroyed = new Dictionary <long, Unit>();
            UnitMorphed   = new Dictionary <long, Unit>();
            UnitTrained   = new Dictionary <long, Unit>();
            UnitRenegade  = new Dictionary <long, Unit>();

            baseLocations    = new Dictionary <int, TilePosition>();
            currentBuildSite = BuildSite.StartingLocation;

            foreach (Player pl in bwapi.Broodwar.getPlayers())
            {
                ActivePlayers.Add(pl.getName(), pl);
            }
            if (ActivePlayers.ContainsKey(Self().getName()))
            {
                ActivePlayers.Remove(Self().getName());
            }

            forces      = new Dictionary <ForceLocations, List <UnitAgent> >();
            forcePoints = new Dictionary <ForceLocations, TilePosition>();

            // initiating the starting location
            if (Self().getStartLocation() is TilePosition)
            {
                baseLocations[(int)BuildSite.StartingLocation] = Self().getStartLocation();
                forcePoints[ForceLocations.OwnStart]           = Self().getStartLocation();
            }

            currentForcePoint = ForceLocations.OwnStart;
            currentBuildSite  = BuildSite.StartingLocation;
        }
Ejemplo n.º 12
0
    public void HandleBuildAction(int index)
    {
        BuildSite site = null;

        foreach (Unit b in GameObject.Find("CellGrid").GetComponent <CellGrid>().Units)
        {
            if (b is BuildSite && (b as BuildSite).selected)
            {
                site = b as BuildSite;
                break;
            }
        }

        if (site == null)
        {
            return;
        }

        //handle cost
        if ((DarkRift.DarkRiftAPI.isConnected && !site.CanAffordToBuild(NetManager.buildCosts[index - 1])))
        {
            return;
        }

        site.grid.Players[site.PlayerNumber].Money -= NetManager.buildCosts[index - 1];
        PlayerController.currTurnMoney              = site.grid.Players[site.PlayerNumber].Money;
        SetAvailableFundsText(GameObject.Find("Canvas").GetComponentsInChildren <Text>(), site);
        //GameObject.Find("Canvas").GetComponentsInChildren<Text>()[site.PlayerNumber].text = PlayerController.currTurnMoney.ToString() + "G" + "(+" + site.grid.Players[site.PlayerNumber].income.ToString() + "G)";

        site.buildingType = (MatIndex)index;
        site.GetComponent <ChangeMaterial>().SetNewMaterial((MatIndex)index);

        UnitUpdate update = new UnitUpdate();

        update.command      = UnitUpdateCommand.BUILDSITE;
        update.moving       = site.unitIndex;
        update.buildingType = (MatIndex)index;
        NetManager.SendData(TagIndex.Controller, TagIndex.PlayerUpdate, update);

        site.OnUnitDeselected();
    }
Ejemplo n.º 13
0
    public void IncreaseMoneyGenIfAble()
    {
        BuildSite rax = null;

        foreach (Unit b in GameObject.Find("CellGrid").GetComponent <CellGrid>().Units)
        {
            if ((b as BuildSite && (b as BuildSite).selected))
            {
                rax = b as BuildSite;
                break;
            }
        }
        if (rax == null)
        {
            return;
        }

        if (rax.ActionPoints > 0)
        {
            rax.SelfIncreaseMoneyGenIfAble();
            rax.SendIncreaseMoneyCommand();
        }
    }
Ejemplo n.º 14
0
 public bool Build(uint vsopts, XmlElement config, IVsOutputWindowPane output, bool fCleanBuild, BuildSite site){
   this.BuildSite = site;
   try{
     return Build(vsopts, config, output, fCleanBuild);
   }finally{
     this.BuildSite = null;
   }
 }
Ejemplo n.º 15
0
 public BuildSiteAdaptor(BuildSite buildSite)
 {
     this.buildSite = buildSite;
 }
Ejemplo n.º 16
0
 public void SetAvailableFundsText(Text[] t, BuildSite site)
 {
     t[site.PlayerNumber].text = PlayerController.currTurnMoney.ToString() + "G" + "(+" + site.grid.Players[site.PlayerNumber].income.ToString() + "G)";
 }
Ejemplo n.º 17
0
    void ReceiveData(ushort senderID, byte tag, ushort subject, object data)
    {
        bool ignoreMessage = false;

        if (ignoreMessage)
        {
            return;
        }

        if (tag == TagIndex.Controller)
        {
            if (subject == TagIndex.ControllerSubjects.JoinMessage)
            {
                networkConnected = true;
                DarkRiftAPI.SendMessageToID(senderID, TagIndex.Controller, TagIndex.ControllerSubjects.SpawnPlayer, null);
                SendData(TagIndex.Controller, TagIndex.PlayerUpdate, factions[DarkRiftAPI.id - 1]);
                if (senderID == 1)
                {
                    playerNumber = 2;
                }
                if (senderID > playerCount)
                {
                    playerCount = senderID;
                }
                //GameObject.Find("Name1").GetComponent<UnityEngine.UI.InputField>().readOnly = true;
                //GameObject.Find("Name2").GetComponent<UnityEngine.UI.InputField>().readOnly = false;

                //Handle Connect message
            }

            if (subject == TagIndex.ControllerSubjects.SpawnPlayer)
            {
                networkConnected = true;
                //Handle spawning the player into our game
            }

            if (subject == TagIndex.PlayerUpdate)
            {
                if (data is string && (data as string) == "ERROR")
                {
                    possibleDesyncOccurred = true;
                    RetrySendData();
                }
                if (data is string[])
                {
                    string[] name = data as string[];
                    if (name[0] == "name")
                    {
                        GameObject go = GameObject.Find("Name" + (senderID).ToString());
                        go.GetComponent <UnityEngine.UI.InputField>().text = name[1];
                    }
                    else if (name[0] == "StartGame")
                    {
                        DontDestroyOnLoad(transform.gameObject);
                        DontDestroyOnLoad(GameObject.Find("GameInitiator"));
                        //if (NetManager.playerCount >= 2)
                        //{
                        //    GameInit.mapName = GameInit.mapNames[NetManager.playerCount - 2];
                        //}
                        //string mapDropDownText = GameObject.Find("mapDropDown").GetComponent<Dropdown>().itemText.text;
                        //GameInit.mapName = mapDropDownText.Split(' ')[1];
                        GameInit.mapName = name[1];
                        SceneManager.LoadScene(GameInit.mapName);
                        //SceneManager.LoadScene("Main");
                    }
                    else if (name[0] == "charUpdate")
                    {
                        GameObject.Find(name[1]).GetComponent <UnityEngine.UI.Dropdown>().value = int.Parse(name[2]);
                    }
                }
                if (data is UnitUpdate /*&& messageIndex + 1 == (data as UnitUpdate).index*/)
                {
                    UnitUpdate update      = data as UnitUpdate;
                    GameObject unitsParent = GameObject.Find("Units Parent");
                    Unit[]     units       = unitsParent.GetComponentsInChildren <Unit>();
                    CellGrid   grid        = GameObject.Find("CellGrid").GetComponent <CellGrid>();
                    messageIndex = update.index;
                    if (IsEndTurnCommand(update))
                    {
                        grid.EndTurn();
                        //end turn
                    }
                    else if (IsMoveUnitCommand(update))
                    {
                        foreach (Unit u in units)
                        {
                            if (u.unitIndex == update.moving)
                            {
                                //CellGrid grid = GameObject.Find("CellGrid").GetComponent<CellGrid>();
                                foreach (Cell c in grid.Cells)
                                {
                                    if (c.transform.position.x == update.newLocationX &&
                                        c.transform.position.y == update.newLocationY)
                                    {
                                        u.AdjustCellMovementCosts();
                                        var path = u.FindPath(grid.Cells, c);
                                        u.ResetMovementPoints();
                                        u.Move(c, path);
                                        u.ResetMovementPoints();
                                        break;
                                    }
                                }
                                break;
                            }
                        }
                    }
                    else if (IsAttackCommand(update))
                    {
                        Unit attacker = null;
                        Unit defender = null;
                        foreach (Unit u in units)
                        {
                            if (u.unitIndex == update.moving)
                            {
                                attacker = u;
                                //CellGrid grid = GameObject.Find("CellGrid").GetComponent<CellGrid>();
                            }
                            if (u.unitIndex == update.target)
                            {
                                defender = u;
                            }
                            if (attacker != null && defender != null)
                            {
                                attacker.DealDamage(defender, true);
                                //attack

                                break;
                            }
                        }
                    }
                    else if (IsSpawnUnitCommand(update))
                    {
                        foreach (Unit c in grid.Units)
                        {
                            if (c.transform.position.x == update.newLocationX && c.transform.position.y == update.newLocationY)
                            {
                                if (c is BarracksUnit)
                                {
                                    (c as BarracksUnit).InstantiateUnit(update.type);
                                }
                                else if (c is BuildSite)
                                {
                                    if (update.type >= UnitType.INFANTRY && update.type <= UnitType.ANTIAIR)
                                    {
                                        //TODO 1
                                        //guiCamRef.GetComponent<NewBarracks>().SpawnAStarFromNetwork((int)update.type, (int)update.moving);
                                        guiCamRef.GetComponent <NewBarracks>().SpawnUnitFromNetwork((int)update.type, (int)update.moving, 1);
                                        //GameObject.Find("GUICamera").GetComponent<NewBarracks>().SpawnAStarFromNetwork((int)update.type, (int)update.index);
                                    }
                                    else if (update.type >= UnitType.ANDROID && update.type <= UnitType.TURRET)
                                    {
                                        guiCamRef.GetComponent <NewBarracks>().SpawniFactionFromNetwork((int)update.type, (int)update.moving);
                                    }
                                    else if (update.type >= UnitType.ADVERSARY && update.type <= UnitType.STASISGUN)
                                    {
                                        guiCamRef.GetComponent <NewBarracks>().SpawnusbFromNetwork((int)update.type, (int)update.moving);
                                    }
                                    //(c as BuildSite).InstantiateUnit(update.type);
                                }
                                break;
                            }
                        }
                        foreach (Unit c in grid.Units)
                        {
                            if (c.transform.position.x == update.newLocationX && c.transform.position.y == update.newLocationY)
                            {
                                if (c is Airport)
                                {
                                    (c as Airport).InstantiateUnit(update.type);
                                }
                                else if (c is BuildSite)
                                {
                                    if (update.type >= UnitType.FIGHTER && update.type <= UnitType.COPTER)
                                    {
                                        guiCamRef.GetComponent <NewAirport>().SpawnAStarFromNetwork((int)update.type, (int)update.moving);
                                    }
                                    else if (update.type >= UnitType.CAPCOPTER && update.type <= UnitType.BOMB)
                                    {
                                        guiCamRef.GetComponent <NewAirport>().SpawniFactionFromNetwork((int)update.type, (int)update.moving);
                                    }
                                    else if (update.type >= UnitType.ORBITALSTRIKER && update.type <= UnitType.NULLSTAR)
                                    {
                                        guiCamRef.GetComponent <NewAirport>().SpawniFactionFromNetwork((int)update.type, (int)update.moving);
                                    }
                                    //(c as BuildSite).InstantiateUnit(update.type);
                                }
                                break;
                            }
                        }
                        //CellGrid grid = GameObject.Find("CellGrid").GetComponent<CellGrid>()
                    }
                    else if (IsCaptureCommand(update))
                    {
                    }
                    else if (IsIncreaseMoneGenCommand(update))
                    {
                        foreach (Unit c in grid.Units)
                        {
                            if (c.unitIndex == update.moving)
                            {
                                if (c is City)
                                {
                                    (c as City).SelfIncreaseMoneyGenIfAble();
                                }
                                else if (c is BuildSite)
                                {
                                    (c as BuildSite).SelfIncreaseMoneyGenIfAble();
                                }
                            }
                        }
                    }
                    else if (IsUpgradeBuildSiteCommand(update))
                    {
                        BuildSite site = null;

                        foreach (Unit b in GameObject.Find("CellGrid").GetComponent <CellGrid>().Units)
                        {
                            if (b is BuildSite && b.unitIndex == update.moving)
                            {
                                site = b as BuildSite;
                                break;
                            }
                        }

                        if (site == null)
                        {
                            return;
                        }

                        //handle cost
                        Debug.Log("Site == null: " + (site == null).ToString());
                        Debug.Log("update == null: " + (update == null).ToString());
                        Debug.Log(NetManager.buildCosts[(int)update.buildingType - 1]);

                        if (!site.CanAffordToBuild(NetManager.buildCosts[(int)update.buildingType - 1]))
                        {
                            return;
                        }

                        site.grid.Players[site.PlayerNumber].Money -= NetManager.buildCosts[(int)update.buildingType - 1];
                        PlayerController.currTurnMoney              = site.grid.Players[site.PlayerNumber].Money;
                        GameObject.Find("Canvas").GetComponentsInChildren <Text>()[site.PlayerNumber].text = PlayerController.currTurnMoney.ToString() + "G" + "(+" + site.grid.Players[site.PlayerNumber].income.ToString() + "G)";

                        site.buildingType = update.buildingType;
                        site.GetComponent <ChangeMaterial>().SetNewMaterial(update.buildingType);
                    }

                    else if (data is UnitUpdate && messageIndex + 1 != (data as UnitUpdate).index)
                    {
                        possibleDesyncOccurred = true;
                        SendData(TagIndex.Controller, TagIndex.PlayerUpdate, "ERROR");
                        //send error message
                    }
                }
                else if (data is Unit.Faction)
                {
                    factions[senderID - 1] = (Unit.Faction)data;
                }
            }
        }
    }