コード例 #1
0
        public void InitAI(IAICallback aicallback, int team)
        {
            this.aicallback = aicallback;
            this.team       = team;
            aicallback.SendTextMsg("Hello from Mono AbicWrappers", 0);
            aicallback.SendTextMsg("The map name is: " + aicallback.GetMapName(), 0);
            aicallback.SendTextMsg("Our ally team is: " + aicallback.GetMyTeam(), 0);

            //int features[10000 + 1];
            //int numfeatures = IAICallback_GetFeatures( aicallback, features, 10000 );
            //sprintf( buffer, "Num features is: %i", numfeatures );
            //IAICallback_SendTextMsg( aicallback, buffer, 0 );

            //const FeatureDef *featuredef = IAICallback_GetFeatureDef( aicallback, features[0] );
            //sprintf( buffer, "First feature: %s", FeatureDef_get_myName( featuredef ) );
            //IAICallback_SendTextMsg( aicallback, buffer, 0 );

            IUnitDef unitdef = aicallback.GetUnitDefByTypeId(34);

            aicallback.SendTextMsg("gotunitdef", 0);
            aicallback.SendTextMsg("type id 34 is " + unitdef.name, 0);
            aicallback.SendTextMsg("human name: " + unitdef.humanName, 0);
            aicallback.SendTextMsg("id: " + unitdef.id, 0);

            IMoveData movedata = unitdef.movedata;

            //IAICallback_SendTextMsg( aicallback, "movedata is null? " + ( movedata == 0 );
            //IAICallback_SendTextMsg( aicallback, buffer, 0 );

            //IAICallback_SendTextMsg( aicallback, "movetype: %i" + MoveData_get_movetype( movedata ) );
            //IAICallback_SendTextMsg( aicallback, buffer, 0 );

            aicallback.SendTextMsg("maxslope: " + movedata.maxSlope, 0);
        }
コード例 #2
0
        void GenerateBuildTable(string modname)
        {
            logfile.WriteLine("Generating indexes mod " + modname);

            foreach (IUnitDef unitdef in availableunittypes)
            {
                string    logline  = unitdef.id + " " + unitdef.name + " " + unitdef.humanName + " size: " + unitdef.xsize + "," + unitdef.ysize;
                IMoveData movedata = unitdef.movedata;
                if (movedata != null)
                {
                    logline += " maxSlope: " + movedata.maxSlope + " depth " + movedata.depth + " slopeMod " + movedata.slopeMod +
                               " depthMod: " + movedata.depthMod + " movefamily: " + movedata.moveFamily;
                }
                logfile.WriteLine(logline);

                if (!UnitDefByName.ContainsKey(unitdef.name.ToLower()))
                {
                    UnitDefByName.Add(unitdef.name.ToLower(), unitdef);
                    UnitDefById.Add(unitdef.id, unitdef);
                }
                else
                {
                    logfile.WriteLine("Warning: duplicate name: " + unitdef.name.ToLower());
                }
            }
        }
コード例 #3
0
 public async UniTask OnPlayerMove(IMoveData moveData, History.Mode mode)
 {
     if (TurnManager.instance.IsGameOver())
     {
         buttonSave.interactable = false;
     }
 }
コード例 #4
0
    public void SetUp(IMoveData data)
    {
        _moveData = data;
        _rb       = GetRigidBody2D();


        alpha            = Utils.angle360(_moveData.targetObj.transform.position, this.transform.position);
        _isClockWiseMove = Utils.IsClockwiseMoveOrNot(_moveData.targetObj.transform, this.transform);
    }
コード例 #5
0
    private void Awake()
    {
        if (instance == null)
        {
            instance = this;
        }

        _moveData = new MoveData();
    }
コード例 #6
0
 public History(History history) : this()
 {
     recentMoves.AddRange(history.recentMoves);
     undoneMoves.AddRange(history.undoneMoves);
     for (int i = 0; i < undoneMoves.Count; ++i)
     {
         var moves = undoneMoves[i];
         Array.Copy(moves, undoneMoves[i] = new IMoveData[moves.Length], moves.Length);
     }
 }
コード例 #7
0
 public void Play(IMoveData data)
 {
     undoneMoves.Clear();
     if (recentMoves.Count == CAPACITY)
     {
         recentMoves.RemoveAt(0);
     }
     recentMoves.Add(data);
     execute(data, Mode.Play);
 }
コード例 #8
0
        public async UniTask OnPlayerMove(IMoveData moveData, History.Mode mode)
        {
            var data = moveData as Core.MoveData;

            core.Move(data, mode);

            if (mode != History.Mode.Undo)
            {
                #region DO
                var piece = mailBox[data.from.x][data.from.y];
                mailBox[data.from.x][data.from.y] = null;
                piece.IncreaseSortOrder();

                // Nếu là AI hoặc Remote thì tô màu đích đến trước khi di chuyển quân cờ
                if (!TurnManager.instance.CurrentPlayerIsLocalHuman())
                {
                    moveTarget.position = data.to.ToVector3();
                }

                await piece.transform.Move(data.to.ToVector3(), pieceMoveSpeed);

                piece.DecreaseSortOrder();

                var opponent = mailBox[data.to.x][data.to.y];
                if (opponent)
                {
                    opponent.gameObject.SetActive(false);
                }
                (mailBox[data.to.x][data.to.y] = piece).hidden = false;
                moveTarget.position = data.to.ToVector3();
                #endregion
            }
            else
            {
                #region UNDO
                var piece = mailBox[data.to.x][data.to.y];
                if (data.capturedPiece != null)
                {
                    var opponent = data.capturedPiece.Value;
                    (mailBox[data.to.x][data.to.y] = pieces[opponent.color][opponent.name].Show(data.to.ToVector3()))
                    .hidden = opponent.hidden;
                }
                else
                {
                    mailBox[data.to.x][data.to.y] = null;
                }

                await piece.transform.Move(data.from.ToVector3(), pieceMoveSpeed);

                (mailBox[data.from.x][data.from.y] = piece).hidden = core[data.from.x, data.from.y].Value.hidden;
                moveTarget.position = data.from.ToVector3();
                #endregion
            }
        }
コード例 #9
0
    public IMoveData DeepCopy(IMoveData data)
    {
        IMoveData copyData = new MoveData();

        copyData.movingSpeed   = data.movingSpeed;
        copyData.rotationSpeed = data.rotationSpeed;
        copyData.torque        = data.torque;
        copyData.direction     = data.direction;
        copyData.targetObj     = data.targetObj;

        return(copyData);
    }
コード例 #10
0
        public async override UniTask OnPlayerMove(IMoveData moveData, History.Mode mode)
        {
            var data = moveData as Core.MoveData;

            if (mode == History.Mode.Undo)
            {
                emptyCells.Add(data.index);
            }
            else
            {
                emptyCells.Remove(data.index);
            }
        }
コード例 #11
0
        public void UnitCreated(int unit)
        {
            aicallback.SendTextMsg("Unit created: " + unit, 0);

            IUnitDef unitdef = aicallback.GetUnitDef(unit);

            aicallback.SendTextMsg("Unit created: " + unitdef.name, 0);

            IMoveData movedata = unitdef.movedata;

            if (movedata != null)
            {
                aicallback.SendTextMsg("Max Slope: " + movedata.maxSlope, 0);
            }

            if (unitdef.isCommander)
            {
                int    numbuildoptions    = unitdef.GetNumBuildOptions();
                string buildoptionsstring = "Build options: ";
                for (int i = 0; i < numbuildoptions; i++)
                {
                    buildoptionsstring += unitdef.GetBuildOption(i);
                }
                aicallback.SendTextMsg(buildoptionsstring, 0);

                Float3 commanderpos = aicallback.GetUnitPos(unit);
                aicallback.SendTextMsg("Commanderpos: " + commanderpos.ToString(), 0);

                int numunitdefs = aicallback.GetNumUnitDefs();
                aicallback.SendTextMsg("Num unit defs: " + numunitdefs, 0);

                for (int i = 1; i <= numunitdefs; i++)
                {
                    IUnitDef thisunitdef = aicallback.GetUnitDefByTypeId(i);
                    if (thisunitdef.name == "ARMSOLAR")
                    {
                        aicallback.SendTextMsg("Found solar collector def: " + thisunitdef.id, 0);

                        Float3 nearestbuildpos = aicallback.ClosestBuildSite(thisunitdef, commanderpos, 1400, 2);
                        aicallback.SendTextMsg("Closest build site: " + nearestbuildpos.ToString(), 0);

                        aicallback.DrawUnit("ARMSOLAR", nearestbuildpos, 0,
                                            200, aicallback.GetMyAllyTeam(), true, true);

                        aicallback.GiveOrder(unit, new Command(-thisunitdef.id, nearestbuildpos.ToDoubleArray()));
                    }
                }
            }
        }
コード例 #12
0
 public void InnerCircleCollided(IMoveData playerAttractData)
 {
     if (_isAutoLaunch == true)
     {
         playerAttractData.movingSpeed = _launchSpeed;
         playerMovement.SetData(playerAttractData);
         playerMovement.DockInLauncher();
         playerMovement.SetMoveState(PlayerMovement.movingState.MoveTowardsAdirection);
     }
     else
     {
         playerAttractData.movingSpeed = 0.0f;
         playerMovement.SetData(playerAttractData);
         playerMovement.SetMoveState(PlayerMovement.movingState.DockedInLauncher);
     }
 }
コード例 #13
0
        public async UniTask OnPlayerMove(IMoveData moveData, History.Mode mode)
        {
            var data = moveData as Core.MoveData;

            core.Move(data, mode);

            if (mode != History.Mode.Undo)
            {
                flag.position = data.index.ToVector3();
            }
            else
            {
                var t = TurnManager.instance;
                flag.position = t.moveCount != 0 ? (t[t.moveCount - 1] as Core.MoveData).index.ToVector3() : new Vector3(-1, -1);
            }
        }
コード例 #14
0
        public async UniTask OnPlayerMove(IMoveData moveData, History.Mode mode)
        {
            var data = moveData as Core.MoveData;

            core.Move(data, mode);

            if (mode != History.Mode.Undo)
            {
                pieceMap.SetTile(data.index.ToVector3Int(), pieces[(Symbol)data.playerID]);
                flag.position = data.index.ToVector3();
            }
            else
            {
                pieceMap.SetTile(data.index.ToVector3Int(), null);
                var t = TurnManager.instance;
                flag.position = t.moveCount != 0 ? (t[t.moveCount - 1] as Core.MoveData).index.ToVector3() : new Vector3(-1, -1);
            }
        }
コード例 #15
0
 private void SetPlanetData()
 {
     _playerAttractData = new MoveData();
 }
コード例 #16
0
    public void SetUp(IMoveData data)
    {
        _moveData = data;
        _rb       = GetRigidBody2D();
//        Debug.Log("Rmov speed ... " + _moveData.movingSpeed + "  center obj is : " + _moveData.targetObj);
    }
コード例 #17
0
 public void SetData(IMoveData moveData)
 {
     _moveData = moveData.DeepCopy(moveData);
 }
コード例 #18
0
 public abstract UniTask OnPlayerMove(IMoveData data, History.Mode mode);
コード例 #19
0
 /// <summary>
 /// Đi 1 nước, nếu không có <paramref name="data"/> thì bỏ lượt, đồng thời có thể kết thúc lượt ngay sau khi đi<para/>
 /// Chú ý: Đảm bảo bắt đầu tuần tự các <see cref="ITurnListener.OnPlayerMove(IMoveData, History.Mode)"/> sau đó đợi tất cả quá trình <see langword="async"/> kết thúc<br/>
 /// Ví dụ: ... <see langword="await"/> <see cref="UniTask.WhenAll(IEnumerable{UniTask})"/>  ...
 /// </summary>
 /// <param name="data">Nếu <see langword="null"/> thì bỏ lượt</param>
 /// <param name="endTurn">Nếu <see langword="true"/> thì kết thúc lượt ngay sau khi đi</param>
 public abstract UniTask Play(IMoveData data, bool endTurn);
コード例 #20
0
 public async UniTask OnPlayerMove(IMoveData moveData, History.Mode mode)
 {
 }
コード例 #21
0
ファイル: Board.cs プロジェクト: HyVong007/BoardGame
        public async UniTask OnPlayerMove(IMoveData moveData, History.Mode mode)
        {
            var data = moveData as Core.MoveData;

            core.Move(data, mode);

            var from = data.from.ToMailBoxIndex();
            var to   = data.to.ToMailBoxIndex();

            if (mode != History.Mode.Undo)
            {
                #region DO
                var piece = mailBox[from.x][from.y];
                mailBox[from.x][from.y] = null;

                // Nếu là AI hoặc Remote thì tô màu đích đến trước khi di chuyển quân cờ
                if (!TurnManager.instance.CurrentPlayerIsLocalHuman())
                {
                    moveTarget.position = to.ToVector3();
                }

                await piece.transform.Move(to.ToVector3(), pieceMoveSpeed);

                #region Đặt quân vào ô vị trí {to}
                if (data.promotedName != null)
                {
                    pieces[piece.color][piece.name].Recycle(piece);
                    piece = pieces[(Color)data.playerID][data.promotedName.Value].Get(to.ToVector3());
                }

                var opponent = mailBox[to.x][to.y];
                if (opponent)
                {
                    pieces[opponent.color][opponent.name].Recycle(opponent);
                }
                mailBox[to.x][to.y] = piece;
                moveTarget.position = to.ToVector3();
                #endregion

                #region Xử lý nếu có bắt quân đối phương
                if (data.capturedName != null)
                {
                    if (data.enpassantCapturedIndex != null)
                    {
                        var index = data.enpassantCapturedIndex.Value.ToMailBoxIndex();
                        opponent = mailBox[index.x][index.y];
                        mailBox[index.x][index.y] = null;
                        pieces[opponent.color][opponent.name].Recycle(opponent);
                    }
                }
                #endregion

                if (data.castling != Core.MoveData.Castling.None)
                {
                    var r    = Core.CASTLING_ROOK_MOVEMENTS[(Color)data.playerID][data.castling];
                    var rook = mailBox[r.m_from.x][r.m_from.y];
                    mailBox[r.m_from.x][r.m_from.y] = null;
                    await rook.transform.Move(r.m_to.ToVector3(), pieceMoveSpeed);

                    mailBox[r.m_to.x][r.m_to.y] = rook;
                }
                #endregion
            }
            else
            {
                #region UNDO
                var piece = mailBox[to.x][to.y];

                #region Lấy quân {data.name} hoặc {data.promotedName} ra khỏi ô vị trí {to}
                if (data.promotedName != null)
                {
                    pieces[piece.color][piece.name].Recycle(piece);
                    piece = pieces[(Color)data.playerID][data.name].Get(new Vector3(to.x, to.y));
                }
                #endregion

                #region Khôi phục lại quân đối phương bị bắt nếu có
                if (data.capturedName != null)
                {
                    if (data.enpassantCapturedIndex != null)
                    {
                        mailBox[to.x][to.y] = null;
                        var index = data.enpassantCapturedIndex.Value.ToMailBoxIndex();
                        mailBox[index.x][index.y] = pieces[(Color)(1 - data.playerID)][PieceName.Pawn].Get(index.ToVector3());
                    }
                    else
                    {
                        mailBox[to.x][to.y] = pieces[(Color)(1 - data.playerID)][data.capturedName.Value].Get(to.ToVector3());
                    }
                }
                else
                {
                    mailBox[to.x][to.y] = null;
                }
                #endregion

                // Nếu là AI hoặc Remote thì tô màu đích đến trước khi di chuyển quân cờ
                if (!TurnManager.instance.CurrentPlayerIsLocalHuman())
                {
                    moveTarget.position = from.ToVector3();
                }
                await piece.transform.Move(from.ToVector3(), pieceMoveSpeed);

                mailBox[from.x][from.y] = piece;

                if (data.castling != Core.MoveData.Castling.None)
                {
                    var r    = Core.CASTLING_ROOK_MOVEMENTS[(Color)data.playerID][data.castling];
                    var rook = mailBox[r.m_to.x][r.m_to.y];
                    mailBox[r.m_to.x][r.m_to.y] = null;
                    await rook.transform.Move(from.ToVector3(), pieceMoveSpeed);

                    mailBox[r.m_from.x][r.m_from.y] = rook;
                }
                #endregion
            }
        }
コード例 #22
0
        void GenerateBuildTable(string modname)
        {
            logfile.WriteLine("Generating indexes mod " + modname);

            foreach (IUnitDef unitdef in availableunittypes)
            {
                if (unitdef != null)
                {
                    string    logline  = unitdef.id + " " + unitdef.name + " " + unitdef.humanName + " size: " + unitdef.xsize + "," + unitdef.ysize;
                    IMoveData movedata = unitdef.movedata;
                    if (movedata != null)
                    {
                        logline += " maxSlope: " + movedata.maxSlope + " depth " + movedata.depth + " slopeMod " + movedata.slopeMod +
                                   " depthMod: " + movedata.depthMod + " movefamily: " + movedata.moveFamily;
                    }
                    logfile.WriteLine(logline);

                    if (unitdef.extractsMetal > 0)
                    {
                        MetalExtractors.Add(unitdef);
                    }
                    if (unitdef.energyMake > 0 || unitdef.windGenerator > 0 || unitdef.tidalGenerator > 0)
                    {
                        EnergyProducers.Add(unitdef);
                    }
                    if (unitdef.builder && unitdef.speed >= 1)
                    {
                        Constructors.Add(unitdef);
                    }
                    if (unitdef.builder && unitdef.speed < 1)
                    {
                        Factories.Add(unitdef);
                    }
                    if (unitdef.canAttack && unitdef.canmove && unitdef.minWaterDepth < 0)
                    {
                        GroundAttack.Add(unitdef);
                    }
                    if (unitdef.canAttack && unitdef.canmove && unitdef.canfly)
                    {
                        AirAttack.Add(unitdef);
                    }
                    if (!UnitDefByName.ContainsKey(unitdef.name.ToLower()))
                    {
                        UnitDefByName.Add(unitdef.name.ToLower(), unitdef);
                    }
                    else
                    {
                        logfile.WriteLine("Warning: duplicate name: " + unitdef.name.ToLower());
                    }
                }
            }
            logfile.WriteLine("=======================================================");
            logfile.WriteLine("Metal Extractors");
            logfile.WriteLine(MetalExtractors.ToString());
            logfile.WriteLine("=======================================================");
            logfile.WriteLine("EnergyProducers");
            logfile.WriteLine(EnergyProducers.ToString());
            logfile.WriteLine("=======================================================");
            logfile.WriteLine("Constructors");
            logfile.WriteLine(Constructors.ToString());
            logfile.WriteLine("=======================================================");
            logfile.WriteLine("GroundAttack");
            logfile.WriteLine(GroundAttack.ToString());
            logfile.WriteLine("=======================================================");
            logfile.WriteLine("Factories");
            logfile.WriteLine(Factories.ToString());

            IUnitDef constuctionvehicle = UnitDefByName[BuildTable.ArmConstructionVehicle] as IUnitDef;
            //int
            //BuildOption[] buildoptions = constuctionvehicle.GetNumBuildOptions;
            //string buildoptionsstring = "Constructionvehicle build options: ";
            //foreach( BuildOption buildoption in buildoptions )
            //{
            //buildoptionsstring += "( " + buildoption.TablePosition.ToString() + ", " + buildoption.UnitTypeName + " ) ";
            //}
            //logfile.WriteLine( buildoptionsstring );
        }
コード例 #23
0
 public void OuterCircleCollided(IMoveData playerAttractData)
 {
     playerMovement.SetData(playerAttractData);
     playerMovement.SetMoveState(PlayerMovement.movingState.TowardAPosition);
 }
コード例 #24
0
		private Task CheckPlayerMove(IMoveData data) => throw new NotImplementedException();
コード例 #25
0
 public void InnerCircleCollided(IMoveData playerAttractData)
 {
     playerMovement.SetData(playerAttractData);
     playerMovement.SetMoveState(PlayerMovement.movingState.RotateAround);
 }
コード例 #26
0
 public void SetUp(IMoveData data)
 {
     _moveData = data;
     _rb       = GetRigidBody2D();
 }