private TurnOptions CalculateMoveOptions(TurnOptionCalculatorArgs args)
        {
            TurnOptions finalOptions = new TurnOptions();

            finalOptions.options = new List <TurnAction>();
            Piece          piece = board.Pieces[args.pieceIndex];
            PiecePrototype proto = db.PiecePrototypes[piece.PrototypeID];

            scripts.AddGlobal("actionHelper", luaHelper);
            DynValue ret = scripts.CallFunction(proto.MovementFunction, args.luaState);

            scripts.RemoveGlobal("actionHelper");
            try {
                Table optionList = SafeGetTable(ret, string.Format("Piece {0} action function error: Expected table to be returned", proto.LuaTag));
                int   numOptions = optionList.Length;
                for (int i = 1; i <= numOptions; i++)
                {
                    Table actionList = SafeGetTable(optionList.Get(i),
                                                    string.Format("Piece {0} action function error: Expected table at position {1} in returned list", proto.LuaTag, i));
                    TurnAction action = TranslateActionTable(args.pieceIndex, actionList, i);
                    finalOptions.options.Add(action);
                }
            } catch (BadActionException ex) {
                scripts.WriteToAuthorLog(ex.Message);
                finalOptions.options.Clear();
            }

            return(finalOptions);
        }
Ejemplo n.º 2
0
        public static Mods.Lua.Piece GetPiece(int pieceIndex, Board gameBoard, GameDatabase db)
        {
            Piece          gamePiece  = gameBoard.Pieces[pieceIndex];
            PiecePrototype behavior   = db.PiecePrototypes[gamePiece.PrototypeID];
            bool           isCaptured = gamePiece.IsCaptured;

            return(new Mods.Lua.Piece()
            {
                Index = pieceIndex + 1,
                IsCaptured = isCaptured,
                Owner = GetPlayerTag(gamePiece.OwnerPlayer),
                PieceName = behavior.LuaTag,
                PositionX = isCaptured ? 0 : gamePiece.BoardPosition.x + 1,
                PositionY = isCaptured ? 0 : gamePiece.BoardPosition.y + 1,
                NumberOfMoves = gamePiece.NumberOfMoves,
            });
        }