Example #1
0
    //ユニット作成(リスト追加は外部で実施すること)
    public static UnitObj Create(String _name, Unit _type, Vector2Int _pos, PlayerCtl _player)
    {
        UnitObj newObj = Instantiate(_player.utltList.FirstOrDefault(u => u.units == _type));
        //対象のシェーダー情報を取得
        Shader sh = _player.utltList.FirstOrDefault(u => u.units == _type).transform.GetComponent <SpriteRenderer>().material.shader;    //Find("Texture").
        //取得したシェーダーを元に新しいマテリアルを作成
        Material mat = new Material(sh);

        newObj.transform.GetComponent <SpriteRenderer>().material = mat; //Find("Texture").

        newObj.name    = _name;
        newObj.pos     = _pos;
        newObj.old_pos = _pos;
        newObj.hp      = newObj.hpMax;
        newObj.fuel    = newObj.fuelMax;
        newObj.gameObject.SetActive(true); //表示
        newObj.lock_max = UnityEngine.Random.Range(10, 100);
        newObj.player   = _player;
        newObj.gameObject.SetActive(true);
        newObj.GetComponent <SpriteRenderer>().color = _player.pColor;
        newObj.chgWorkType(WorkType.Newing);
        newObj.gameObject.name = "Obj_" + _player.pnum + "_" + _type.ToString();
        _player.vMap.moveAdd(_pos, 3);
        if (newObj.type != uType.Building)
        {
            StageCtl.UnitList[newObj.player.pnum].Insert(0, newObj);      //先頭
        }
        else
        {
            StageCtl.UnitList[newObj.player.pnum].Add(newObj);      //末尾
        }
        newObj.transform.position = map.GetComponent <Grid>().GetCellCenterWorld(new Vector3Int(MapCtl.offset_stg2tile_x(_pos.x), MapCtl.offset_stg2tile_y(_pos.y), 0)) - new Vector3(0f, 0f, 1f);
        return(newObj);
    }
Example #2
0
 // 帰還チェック(帰還必要時は帰還処理含む)
 void chkReturn(UnitObj units)
 {
     if (((float)units.fuel / (float)units.fuelMax < 0.25f) &&
         ((units.works != WorkType.Returning) && (units.works != WorkType.Repairing)))
     {
         units.doReturn();
     }
 }
Example #3
0
    public void Init(IGetUnitInfo info)
    {
        Info = info;
        UnitType unitType = info.GetUnitType();

        Instantiate(UnitTable.Instance.GetUnitModel(unitType).Model, modelRoot);

        //Movement
        GetComponent <Movement>().Init(new Vector3(info.GetXPos(), info.GetYPos(), info.GetZPos()), info.GetRotation());

        //Animation
        IGetAnimInfo animInfo = info as IGetAnimInfo;

        if (animInfo != null)
        {
            GetComponent <Animation>().Init(animInfo.GetAnimType(), animInfo.GetSpeedRate(), animInfo.GetPlayTime());
        }

        //HealthBar
        if (UnitType.Core <= unitType && unitType <= UnitType.Tower)
        {
            BuildingObj obj = info as BuildingObj;

            healthBarInstance = Instantiate(generalHealthBar, GameObject.Find("HealthBars").transform);
            healthBarInstance.GetComponent <GeneralHealthBar>().SetData(new Vector3(transform.position.x, 2.6f, transform.position.z), obj.MaxHP, obj.CurHP, obj.Team);
        }
        else if (UnitType.TowerBullet <= unitType && unitType <= UnitType.PressurisedSteam)
        {
            ActorObj obj = info as ActorObj;
        }
        else if (UnitType.Minion <= unitType && unitType <= UnitType.UltraMonster)
        {
            UnitObj obj = info as UnitObj;

            healthBarInstance = Instantiate(generalHealthBar, GameObject.Find("HealthBars").transform);
            healthBarInstance.GetComponent <GeneralHealthBar>().SetData(new Vector3(transform.position.x, 2.0f, transform.position.z), obj.MaxHP, obj.CurHP, obj.Team);
        }
        else
        {
            ChampionObj obj = info as ChampionObj;

            healthBarInstance = Instantiate(championHealthBar, GameObject.Find("HealthBars").transform);
            SetChampionHealthBarData(obj);
        }

        //Minimap
        if (unitType < UnitType.HatsuneMiku)
        {
            dotInstance = Instantiate(generalDot, GameObject.Find("MinimapUI").transform);
            dotInstance.GetComponent <GeneralDot>().SetData(info.GetTeam(), new Vector2(info.GetXPos(), info.GetZPos()));
        }
        else
        {
            dotInstance = Instantiate(championDot, GameObject.Find("MinimapUI").transform);
            dotInstance.GetComponent <ChampionDot>().SetData(info.GetUnitType(), info.GetTeam(), new Vector2(info.GetXPos(), info.GetZPos()));
        }
    }
Example #4
0
    //ユニットオブジェクトのテンプレート作成
    static UnitObj addObjTlt(String _image, uType _type, Unit _units, int _cost, int _hpMax, int _fuelMax, int _fuelEfc, float _speedMax, float _yawMax)
    {
        UnitObj newObj = Instantiate(instance);

        newObj.unitImage        = newObj.transform.GetComponent <SpriteRenderer>(); //newObj.transform.Find("Texture").GetComponent<SpriteRenderer>()
        newObj.unitImage.sprite = Resources.Load <Sprite>("UnitImg/" + _image);
        newObj.units            = _units;
        newObj.type             = _type;
        newObj.hpMax            = _hpMax;
        newObj.fuelMax          = _fuelMax;
        newObj.fuelEfc          = _fuelEfc;
        newObj.speedMax         = _speedMax;
        newObj.yawMax           = _yawMax;
        newObj.yawrate          = _yawMax;
        newObj.gameObject.SetActive(false); //非表示
        newObj.gameObject.name = "Tlt_" + _units.ToString();

        //switch (newObj.type){
        //    case uType.Infantry:  /* 歩兵   */
        //		newObj.gameObject.layer = LayerMask.NameToLayer("Infantry");
        //		break;
        //    case uType.Vehicle:   /* 車両   */
        //		newObj.gameObject.layer = LayerMask.NameToLayer("Vehicle");
        //		break;
        //    case uType.Aircraft:  /* 航空機 */
        //		newObj.gameObject.layer = LayerMask.NameToLayer("Aircraft");
        //		break;
        //    case uType.Warship:   /* 戦艦   */
        //		newObj.gameObject.layer = LayerMask.NameToLayer("Warship");
        //		break;
        //    case uType.Submarine: /* 潜水艦 */
        //		newObj.gameObject.layer = LayerMask.NameToLayer("Submarine");
        //		break;
        //    case uType.Building:
        //		newObj.gameObject.layer = LayerMask.NameToLayer("Building");
        //		break;
        //	default:              /* その他 */
        //		break;
        //
        //}
        newObj.gameObject.layer = LayerMask.NameToLayer(newObj.type.ToString());

        //建物の場合は、位置と向きを固定
        if (_type == uType.Building)
        {
            var rb = newObj.GetComponent <Rigidbody2D>();
            rb.constraints = RigidbodyConstraints2D.FreezeAll;
            newObj.GetComponent <CircleCollider2D>().isTrigger = true;    //コライダーを無効化
        }

        return(newObj);
    }
Example #5
0
    public void UpdateData(IGetUnitInfo info)
    {
        Info = info;
        UnitType unitType = info.GetUnitType();

        //Movement
        GetComponent <Movement>().SetPosition(new Vector3(info.GetXPos(), info.GetYPos(), info.GetZPos()), info.GetRotation(), info.GetWarped());

        //Animation
        IGetAnimInfo animInfo = info as IGetAnimInfo;

        if (animInfo != null)
        {
            GetComponent <Animation>().SetAnime(animInfo.GetAnimType(), animInfo.GetSpeedRate(), animInfo.GetPlayTime());
        }

        if (UnitType.Core <= unitType && unitType <= UnitType.Tower)
        {
            BuildingObj obj = info as BuildingObj;
            healthBarInstance.GetComponent <GeneralHealthBar>().SetData(new Vector3(transform.position.x, 2.6f, transform.position.z), obj.MaxHP, obj.CurHP, obj.Team);
        }
        else if (UnitType.TowerBullet <= unitType && unitType <= UnitType.PressurisedSteam)
        {
            ActorObj obj = info as ActorObj;
        }
        else if (UnitType.Minion <= unitType && unitType <= UnitType.UltraMonster)
        {
            UnitObj obj = info as UnitObj;
            healthBarInstance.GetComponent <GeneralHealthBar>().SetData(new Vector3(transform.position.x, 2.0f, transform.position.z), obj.MaxHP, obj.CurHP, obj.Team);
        }
        else
        {
            ChampionObj obj = info as ChampionObj;
            SetChampionHealthBarData(obj);
        }

        //Minimap
        if (unitType < UnitType.HatsuneMiku)
        {
            dotInstance.GetComponent <GeneralDot>().SetData(info.GetTeam(), new Vector2(info.GetXPos(), info.GetZPos()));
        }
        else
        {
            dotInstance.GetComponent <ChampionDot>().SetData(info.GetUnitType(), info.GetTeam(), new Vector2(info.GetXPos(), info.GetZPos()));
        }

        //Victory
        if (unitType == UnitType.Core && info.GetCurHP() <= 0)
        {
            GameObject.Find("VictoryUI").GetComponent <VictoryUI>().SetVictory(info.GetTeam());
        }
    }
Example #6
0
    // ユニットを作成 (false:失敗)
    public bool doBuildUnit(Unit _type)
    {
        Vector2Int?buildPos;

        if ((uCost.canCreate(player.pnum, _type, fuel, 0, this.units)) && (works == WorkType.None))
        {
            //港の場合はどこか開いている場所にする
            if (this.units == Unit.NavalPort)
            {
                buildPos = map.tileRing(pos, 1).FirstOrDefault(tll => ((map.tileMap[tll.x, tll.y].getGroup() == TileGroup.Sea) && (StageCtl.UnitList[player.pnum].Any(u => (u.pos == tll) && ((u.type == uType.Warship) || (u.type == uType.Submarine))) == false)));
                if (buildPos == null)
                {
                    return(false);
                }
            }
            else
            {
                buildPos = pos;
            }

            //ユニット上に人・車がある場合はfalse
            if (StageCtl.UnitList[player.pnum].Any(u => (u.pos == buildPos) && ((u.type == uType.Infantry) || (u.type == uType.Vehicle))) == true)
            {
                Debug.Log("ERR!! " + _type);
                return(false);
            }

            chgWorkType(WorkType.Building);
            fuel -= uCost.fuel(player.pnum, _type);

            //対象を作成
            UnitObj newObj2 = Create("BBB", _type, (Vector2Int)buildPos, player);

            //親が存在
            var _parents = uCost.chkParent(player.pnum, _type);
            if (_parents != null)
            {
                UnitObj newObj = Create("BBB", (Unit)_parents, (Vector2Int)buildPos, player);
                newObj.transform.parent = transform;
                newObj2.chgWorkType(WorkType.Loading);
                newObj.transform.parent.GetComponent <UnitObj>().loadUnits.Add(newObj2);
                newObj2.transform.parent = newObj.transform;
            }
            else
            {
                newObj2.transform.parent = transform;
            }

            return(true);
        }
        return(false);
    }
Example #7
0
 void moveWithShip(cpuUnit cUnit, UnitObj minObj, List <Vector2Int> mvList, int dist)
 {
     if (mvList.Count() > 0)
     {
         minObj.doMove(mvList[mvList.Count() - 1]);
     }
     else
     {
         minObj.doMove(cUnit.tgtUnit.pos);
     }
     cUnit.tgtUnit.doMove(minObj.pos);
     cUnit.cWorkType = CpuWorkType.None;
 }
Example #8
0
 // ユニットに乗る (false: 失敗)
 public bool doLoad(UnitObj dst)
 {
     if (map.MapDist(pos, dst.pos) > 1)
     {
         return(false);
     }
     Debug.Log(string.Format("Load!!"));
     destList.Clear();
     destList.Add(new Vector2(map.GetComponent <Grid>().CellToLocal(new Vector3Int(MapCtl.offset_stg2tile_x(dst.pos.x), MapCtl.offset_stg2tile_y(dst.pos.y), 0)).x,
                              map.GetComponent <Grid>().CellToLocal(new Vector3Int(MapCtl.offset_stg2tile_x(dst.pos.x), MapCtl.offset_stg2tile_y(dst.pos.y), 0)).y));                                                                           //dst.pos);
     chgWorkType(WorkType.Loading);
     transform.parent = dst.transform;
     //dst.chgWorkType(WorkType.Loading);
     return(true);
 }
Example #9
0
    private void _endBattle()
    {
        Debug.Log("ENDING BATTLE");
        for (int i = TEAM_GOOD_GUYS; i < this.CombatantsByTeam.Length; i++)
        {
            foreach (GameObject UnitObj in this.CombatantsByTeam[i])
            {
                Unit SurvivingUnit = UnitObj.GetComponent <Unit>();
                SurvivingUnit.setBattle(null);
            }
        }

        Destroy(this);
        Destroy(this.gameObject);
    }
Example #10
0
    public PlayerCtl(string name, int type, int team, Color _pColor)
    {
        this.pnum   = num++;
        this.pname  = name;
        this.ptype  = type;
        this.pteam  = team;
        this.pColor = _pColor;
        GameObject pObj = new GameObject("Player_" + this.pnum);

        utltList = UnitObj.initUnitTlt(this);
        if (type > 0)
        {
            //指定した番号のCPUコンポーネントをロードする
            pObj.AddComponent(Type.GetType(cpulist[ptype]));
        }
        //vMap = new ViewMap();
    }
Example #11
0
    //ユニット情報を登録(type 1:歩兵/2:車両/3:飛行機/4:船舶)
    public UnitObj AddUnit(String name, Vector2Int point, PlayerCtl player, Unit type)
    {
        //UnitObj unit = Instantiate(baseUnit);
        //unit.Initialize(name, type, point, player, moveAmount, hp, fuel, atkmin, atkmax, atk, image);
        UnitObj unit = UnitObj.Create(name, type, point, player);

        //unit.gameObject.SetActive(true);
        //if (player.pnum == 0){
        //    unit.GetComponent<SpriteRenderer>().color = new Color(0.75f, 0.0f, 0.0f, 1.0f); //red transform.Find("Texture").
        //} else {
        //    unit.transform.GetComponent<SpriteRenderer>().color = new Color(0.0f, 0.0f, 0.75f, 1.0f); //blue
        //}
        //unit.transform.position = map.GetComponent<Grid>().GetCellCenterWorld( new Vector3Int( MapCtl.offset_stg2tile_x(point.x), MapCtl.offset_stg2tile_y(point.y), 0 ) ) - new Vector3(0f, 0f, 1f);
        //if (unit.type != uType.Building){
        //	UnitList[player.pnum].Insert(0, unit);  //先頭
        //} else {
        //	UnitList[player.pnum].Add(unit);  //末尾
        //}
        return(unit);
    }
Example #12
0
 //ユニットに乗れる (false 乗れない)
 public UnitObj canLoad(UnitObj tgtObj = null)
 {
     if (tgtObj != null)
     {
         if (map.MapDist(pos, tgtObj.pos) < 2)
         {
             return(tgtObj);
         }
     }
     else
     {
         //if (works == WorkType.None) {
         //	//Debug.Log (string.Format ("MapDist: ({0})", player.utltList.Count));
         //	UnitObj unt = StageCtl.UnitList[player.pnum].FirstOrDefault(u => (u.units == Unit.TransportShip || u.units == Unit.LargeTransportShip) && u.works == WorkType.None && (map.MapDist(pos, u.pos) < 2));//).Min(u => map.MapDist(pos, u.pos)); //
         //	if (unt != null) Debug.Log (string.Format ("MapDist: ({0})", map.MapDist(pos, unt.pos)));
         //	return unt;
         //}
     }
     return(null);
 }
Example #13
0
    private void _doRoundForTeam(int teamNumber)
    {
        int targetTeam = TEAM_MONSTERS;

        if (teamNumber == TEAM_MONSTERS)
        {
            targetTeam = TEAM_GOOD_GUYS;
        }

        //Now go through the units in the team
        ArrayList TargetTeam = this.CombatantsByTeam[targetTeam];

        foreach (GameObject UnitObj in this.CombatantsByTeam[teamNumber])
        {
            Unit AttackingUnit = UnitObj.GetComponent <Unit>();

            //Attack a rando on the other team
            //Debug.Log ("Target team size: " + TargetTeam.Count);
            int targetIndex = Random.Range(0, TargetTeam.Count - 1);

            //Debug.Log("ATTACKING");
            GameObject TargetUnitObj = TargetTeam[targetIndex] as GameObject;

            AttackingUnit.attack(TargetUnitObj);

            Unit TargetUnit = TargetUnitObj.GetComponent <Unit>();
            //Debug.Log(TargetUnit.health);
            if (TargetUnit.health <= 0.0f)
            {
                TargetTeam.RemoveAt(targetIndex);
                TargetUnit.die();

                if (TargetTeam.Count <= 0)                   //The other team is dead oh neos!
                {
                    this._endBattle();
                    return;
                }
            }
        }        //end foreach
    }
Example #14
0
 // ユニットから降りる (false: 失敗 dst 降りる先)
 public bool doUnload(UnitObj tgtObj, Vector2Int?dst = null)
 {
     Debug.Log(string.Format("Unload!!"));
     //
     if (dst != null)
     {
         //降りる候補を選定
     }
     else
     {
         Vector2Int?dsts = map.tileRing(pos, 1).FirstOrDefault(tll => (map.tileMap[tll.x, tll.y].getGroup() == TileGroup.Ground));
         if (dsts != null)
         {
             //候補がある場合
             tgtObj.gameObject.SetActive(true);
             tgtObj.destList.Clear();
             tgtObj.destList.Add(new Vector2(map.GetComponent <Grid>().CellToLocal(new Vector3Int(MapCtl.offset_stg2tile_x((int)dsts?.x), MapCtl.offset_stg2tile_y((int)dsts?.y), 0)).x,
                                             map.GetComponent <Grid>().CellToLocal(new Vector3Int(MapCtl.offset_stg2tile_x((int)dsts?.x), MapCtl.offset_stg2tile_y((int)dsts?.y), 0)).y));
             tgtObj.transform.parent = null;
             loadUnits.Remove(tgtObj);
             tgtObj.chgWorkType(WorkType.Unloading);
             //tgtObj.pos = (Vector2Int)dsts;
         }
         else
         {
             //候補がない場合
             return(false);
         }
     }
     //if (map.MapDist(pos, dst.pos) > 1) return false;
     //destList.Clear();
     //destList.Add(new Vector2(map.GetComponent<Grid>().CellToLocal(new Vector3Int(MapCtl.offset_stg2tile_x(dst.pos.x),MapCtl.offset_stg2tile_y(dst.pos.y), 0)).x,
     //	                                                                               map.GetComponent<Grid>().CellToLocal(new Vector3Int(MapCtl.offset_stg2tile_x(dst.pos.x), MapCtl.offset_stg2tile_y(dst.pos.y), 0)).y));  //dst.pos);
     //chgWorkType(WorkType.Loading);
     //
     return(true);
 }
Example #15
0
 void Awake()
 {
     instance = this;
     map      = GameObject.Find("Grid").GetComponent <MapCtl>();
 }
Example #16
0
        public UnitObj tgtUnit;        //その油田を担当する油井

        public visOil(Vector2Int _pos)
        {
            pos     = _pos;
            tgtUnit = null;
        }
Example #17
0
    // Update is called once per frame
    void Update()
    {
        timeleft -= Time.deltaTime;
        //5秒おき
        if (timeleft <= 0.0)
        {
            timeleft = 5.0f;
            //新しいユニットが生成されたかチェック
            foreach (var units in StageCtl.UnitList[0])
            {
                if (cpuUnitList.Any(u => u.tgtUnit == units) == false)
                {
                    cpuUnit newUnit = new cpuUnit();
                    newUnit.tgtUnit = units;
                    cpuUnitList.Add(newUnit);
                }
            }
        }


        //Debug.Log("[cpuUnit="+ cpuUnitList.Count +"]");

        //ユニットごとの処理
        //foreach(var cUnit in cpuUnitList){
        for (int i = cpuUnitList.Count() - 1; i >= 0; i--)
        {
            if (cpuUnitList[i].tgtUnit == null)
            {
                cpuUnitList.RemoveAt(i);
                continue;
            }
            UnitObj units = cpuUnitList[i].tgtUnit;
            switch (units.units)
            {
            case Unit.LargeTransport:                                                   /* 大型輸送車 */
                if ((units.works == WorkType.None) && (units.transform.parent == null)) //★要改善!
                /* ユニットが搭載されている */
                {
                    if (units.loadUnits.Count > 0)
                    {
                        switch (units.loadUnits[0].units)
                        {
                        case Unit.OilWell:                                 /* 油井 */
                            /* 油田上に居る場合 */
                            if (map.tileMap[units.pos.x, units.pos.y].getType() == TileType.OilField)
                            {
                                units.doDeployUnit();
                            }
                            else
                            {
                                var u = units.canLoad(cpuUnitList[i].hopeRideShip);
                                if (u != null)
                                {
                                    units.doLoad(u);
                                    units.LastDest              = MapCtl.offset_stg2vec(cpuUnitList[i].cpuTgtPos);
                                    cpuUnitList[i].cWorkType    = CpuWorkType.None;
                                    cpuUnitList[i].hopeRideShip = null;
                                }
                                else
                                {
                                    //
                                    if (cpuUnitList[i].hopeRideShip == null)
                                    {
                                        /* 移動先油田未設定 */
                                        //Debug.Log("cpuUnit["+ i +"].cpuTgtPos = " + cpuUnitList[i].cpuTgtPos +"]");
                                        if (cpuUnitList[i].cpuTgtPos.x == -1)
                                        {
                                            visOil OilObj = visOilList.Where(uu => uu.tgtUnit == null).ToList().Find(s => map.MapDist(cpuUnitList[i].tgtUnit.pos, s.pos) == visOilList.Where(uu => uu.tgtUnit == null).ToList().Min(p => map.MapDist(cpuUnitList[i].tgtUnit.pos, p.pos)));
                                            //if (OilObj){
                                            cpuUnitList[i].cpuTgtPos = OilObj.pos;
                                            OilObj.tgtUnit           = cpuUnitList[i].tgtUnit.loadUnits[0];
                                            //Debug.Log("cpuUnit["+ i +"].cpuTgtPos = " + cpuUnitList[i].cpuTgtPos +"]");
                                            //}
                                        }
                                        /* 開いている最短の油田へ経路探索 */
                                        if ((cpuUnitList[i].cWorkType == CpuWorkType.None) && (cpuUnitList[i].cpuTgtPos.x > -1))
                                        {
                                            srcOil(cpuUnitList[i]);
                                            cpuUnitList[i].hopeRideShip = null;
                                            Debug.Log("srcOil cpuUnit[" + i + "].cpuTgtPos = " + units.pos + " ->" + cpuUnitList[i].cpuTgtPos + "]");
                                            //units.doMove(map.getSpcTilePos(new Vector2Int(0,0), new Vector2Int (StageCtl.TileLenX, StageCtl.TileLenY), TileType.OilField, TileType.None)[0]);
                                        }
                                    }
                                    else
                                    {
                                        units.doMove(cpuUnitList[i].hopeRideShip.pos);
                                    }
                                }
                            }
                            break;

                        case Unit.NavalPort:                                 /* 軍港 */
                            if (units.doDeployUnit() == false)
                            {
                                List <Vector2Int> clist = map.getSpcTilePos(new Vector2Int(0, 0), new Vector2Int(StageCtl.TileLenX, StageCtl.TileLenY), TileType.Meadow, TileType.ShallowSea);
                                units.doMove(clist[0]);
                            }
                            break;

                        case Unit.Airfield:                                 /* 飛行場 */
                            if (units.doDeployUnit() == false)
                            {
                                List <Vector2Int> clist = map.getSpcTilePos(new Vector2Int(0, 0), new Vector2Int(StageCtl.TileLenX, StageCtl.TileLenY), TileType.Meadow, TileType.Meadow);
                                units.doMove(clist[0]);
                            }
                            break;

                        case Unit.Factory:                                 /* 工場 */
                            if (units.doDeployUnit() == false)
                            {
                                List <Vector2Int> clist = map.getSpcTilePos(new Vector2Int(0, 0), new Vector2Int(StageCtl.TileLenX, StageCtl.TileLenY), TileType.Meadow, TileType.ShallowSea);
                                units.doMove(clist[0]);
                            }
                            break;

                        case Unit.Refinery:                                 /* 製油所 */
                            if (units.doDeployUnit() == false)
                            {
                                List <Vector2Int> clist = map.getSpcTilePos(new Vector2Int(0, 0), new Vector2Int(StageCtl.TileLenX, StageCtl.TileLenY), TileType.Meadow, TileType.ShallowSea);
                                units.doMove(clist[0]);
                            }
                            break;

                        case Unit.Camp:                                 /* 野営地 */
                            if (units.doDeployUnit() == false)
                            {
                                List <Vector2Int> clist = map.getSpcTilePos(new Vector2Int(0, 0), new Vector2Int(StageCtl.TileLenX, StageCtl.TileLenY), TileType.Meadow, TileType.ShallowSea);
                                units.doMove(clist[0]);
                            }
                            break;

                        case Unit.Base:                                 /* 基地 */
                            if (units.doDeployUnit() == false)
                            {
                                List <Vector2Int> clist = map.getSpcTilePos(new Vector2Int(0, 0), new Vector2Int(StageCtl.TileLenX, StageCtl.TileLenY), TileType.Meadow, TileType.ShallowSea);
                                units.doMove(clist[0]);
                            }
                            break;

                        case Unit.Fortress:                                 /* 要塞 */
                            if (units.doDeployUnit() == false)
                            {
                                List <Vector2Int> clist = map.getSpcTilePos(new Vector2Int(0, 0), new Vector2Int(StageCtl.TileLenX, StageCtl.TileLenY), TileType.Meadow, TileType.ShallowSea);
                                units.doMove(clist[0]);
                            }
                            break;

                        default:                                 /* その他 */
                            break;
                        }
                        /* ユニットが未搭載 */
                    }
                    else
                    {
                    }
                }
                break;

            case Unit.TransportShip:             /* 輸送艦 */
                if (units.works == WorkType.None)
                {
                    /* ユニットが搭載されている */
                    if (units.loadUnits.Count > 0)
                    {
                        if (units.loadUnits[0].works == WorkType.Loading)
                        {
                            //搭載ユニットの最終移動先へ
                            units.doMove(MapCtl.offset_vec2stg(units.loadUnits[0].LastDest));
                            units.loadUnits[0].works = WorkType.None;
                        }
                        else
                        {
                            if (map.tileRing(units.pos, 1).Exists(tll => (((map.tileMap[tll.x, tll.y].getGroup() == TileGroup.Ground)))))
                            {
                                units.doUnload(units.loadUnits[0]);
                                cpuUnitList[i].hopeRideShip = null;
                            }
                            else
                            {
                                units.doMove(MapCtl.offset_vec2stg(units.loadUnits[0].LastDest));
                            }
                        }
                        /* ユニットが非搭載 */
                    }
                    else
                    {
                        //陸地に隣接している場合
                        if (map.tileRing(units.pos, 1).Exists(tll => (((map.tileMap[tll.x, tll.y].getGroup() == TileGroup.Ground)))))
                        {
                            /* 待機 */
                        }
                        else
                        {
                            //ランダムな首都を目指す(デバッグ用)
                            //units.doMove(UnitList.Where(u => u.units == Unit.Capital ).OrderBy(j => System.Guid.NewGuid()).ToList()[0].pos);
                            //ランダムな支配下領域を目指す
                            //units.doMove(map.getSpcTilePos(new Vector2Int(0,0), new Vector2Int (StageCtl.TileLenX, StageCtl.TileLenY), TileType.Meadow, TileType.None).FirstOrDefault(t=>cpuTileMap[t.x, t.y].domain>0));
                        }
                    }
                }
                break;

            case Unit.Surveillance:             /* 偵察機 */
                if (units.works == WorkType.None)
                {
                    units.doMove(new Vector2Int(3, 3));
                    units.addMove(new Vector2Int(15, 15));
                }

                /* 帰還チェック */
                chkReturn(units);

                break;

            case Unit.LandFighter:             /* 陸上戦闘機 */
                if (units.works == WorkType.None)
                {
                    units.doMove(new Vector2Int(3, 3));
                    units.addMove(new Vector2Int(15, 15));
                }

                /* 帰還チェック */
                chkReturn(units);

                break;

            case Unit.Fighter:             /* 戦闘機 */
                if (units.works == WorkType.None)
                {
                    units.doMove(new Vector2Int(3, 3));
                    units.addMove(new Vector2Int(15, 15));
                }

                /* 帰還チェック */
                chkReturn(units);

                break;

            case Unit.Capital:             /* 首都 */
                if (units.works == WorkType.None)
                {
                    //if (UnitList.Where( u => u.units == Unit.NavalPort ).ToList().Count < 1) {
                    //	//units.bldNavalPort();
                    //	units.doBuildUnit(Unit.NavalPort);
                    //} else if (UnitList.Where( u => u.units == Unit.OilWell ).ToList().Count < 5){
                    //	//units.bldOilWell();
                    //	units.doBuildUnit(Unit.OilWell);
                    //} else
                    if (UnitList.Where(u => u.units == Unit.Airfield).ToList().Count < 1)
                    {
                        units.doBuildUnit(Unit.Airfield);
                    }
                }
                break;

            case Unit.Factory:             /* 工場 */
                break;

            case Unit.NavalPort:             /* 軍港 */

                //Debug.Log("NavalPort!! "+ units.works);
                if (units.works == WorkType.None)
                {
                    if (UnitList.Where(u => u.units == Unit.TransportShip).ToList().Count < 3)
                    {
                        units.doBuildUnit(Unit.TransportShip);
                    }
                    else if (UnitList.Where(u => u.units == Unit.LargeTanker).ToList().Count < 5)
                    {
                        units.doBuildUnit(Unit.LargeTanker);
                    }
                }
                break;

            case Unit.Airfield:             /* 飛行場 */
                if (units.works == WorkType.None)
                {
                    if (UnitList.Where(u => u.units == Unit.Surveillance).ToList().Count < 2)                         /* 偵察機 */
                    {
                        units.doBuildUnit(Unit.Surveillance);
                    }
                    else if (UnitList.Where(u => u.units == Unit.LandFighter).ToList().Count < 5)                          /* 陸上戦闘機 */
                    {
                        units.doBuildUnit(Unit.LandFighter);
                    }
                }
                break;

            case Unit.Camp:             /* 工場 */
                break;

            case Unit.Base:             /* 軍港 */
                break;

            default:             /* 資源・その他 */
                //units.bldOilWell();
                break;
            }

            //
        }
    }
Example #18
0
 // Start is called before the first frame update
 void Start()
 {
     parentUnit = transform.parent.GetComponent <UnitObj>();
 }